Skip to content

Commit

Permalink
ng-mdx-remote update
Browse files Browse the repository at this point in the history
  • Loading branch information
thisiseddy-ab committed Aug 28, 2024
1 parent 961ea2b commit 027000f
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions projects/ng-mdx-remote/src/lib/ng-mdx-remote.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,15 @@ export class NgMdxRemoteComponent implements AfterViewInit, OnChanges, OnDestroy
async ngAfterViewInit() {
if (this.source) {
this.reactRoot = ReactDOM.createRoot(this.elementRef.nativeElement);


if(this.nested_code){
this.createNestedCode_Comp()
}

if (this.ngComponents) {
if(this.nested_code){
this.ngComponents = {
...this.ngComponents,
...{"ng-mdx-nested-code" : NgMDXNestedCodeComponent}
}
}
this.mdxService.convertNGComponents_FromObject(this.ngComponents);
}

await this.mdxService.renderMdx(this.source, this.sourceType, this.reactRoot, this.elementRef, this.viewContainerRef, this.options , this.createRenderOptions(), this.reactComponents);
}
}
Expand All @@ -249,16 +248,28 @@ export class NgMdxRemoteComponent implements AfterViewInit, OnChanges, OnDestroy
return;
}

if (changes['source'] || changes['options'] || changes['reactComponents']) {
if (changes['source'] || changes['options'] || changes['reactComponents'] || changes['nested_code']) {
try {

if(this.nested_code){
this.createNestedCode_Comp()
this.mdxService.convertNGComponents_FromObject(this.ngComponents);
}

await this.mdxService.renderMdx(this.source, this.sourceType, this.reactRoot, this.elementRef, this.viewContainerRef, this.options , this.createRenderOptions(), this.reactComponents);
} catch (error) {
console.error('Error rendering MDX:', error);
}
} else if (changes['ngComponents']) {
try {
this.mdxService.convertNGComponents_FromObject(this.ngComponents);
await this.mdxService.renderMdx(this.source, this.sourceType, this.reactRoot, this.elementRef, this.viewContainerRef, this.options , this.createRenderOptions(), this.reactComponents);

if(this.nested_code){
this.createNestedCode_Comp()
}

this.mdxService.convertNGComponents_FromObject(this.ngComponents);

await this.mdxService.renderMdx(this.source, this.sourceType, this.reactRoot, this.elementRef, this.viewContainerRef, this.options , this.createRenderOptions(), this.reactComponents);
} catch (error) {
console.error('Error converting NG components or rendering MDX:', error);
}
Expand All @@ -275,6 +286,15 @@ export class NgMdxRemoteComponent implements AfterViewInit, OnChanges, OnDestroy
return value != null && `${String(value)}` !== 'false';
}

private createNestedCode_Comp() : void {
if(this.nested_code){
this.ngComponents = {
...this.ngComponents,
...{"ng-mdx-nested-code" : NgMDXNestedCodeComponent}
}
}
}

private createRenderOptions(): Render_Options {
return {
clipboard : this.clipboard,
Expand Down

0 comments on commit 027000f

Please sign in to comment.