Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/components/global/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,30 @@ export default function Playground({

if (hasUsageTargetOptions) {
editorOptions.files = Object.keys(codeSnippets[usageTarget])
.map((fileName) => ({
[fileName]: hostRef.current!.querySelector<HTMLElement>(`#${getCodeSnippetId(usageTarget, fileName)} code`)
.outerText,
}))
.map((fileName) => {
const codeBlock = hostRef.current!.querySelector<HTMLElement>(
`#${getCodeSnippetId(usageTarget, fileName)} code`
);
let code = codeBlock.outerText;

if (code.trim().length === 0) {
/**
* Safari has an issue where accessing the `outerText` on a non-visible
* DOM element results in a string with only whitespace. To work around this,
* we create a clone of the element, not attached to the DOM, and parse
* the outerText from that.
*
* Only in Safari does this persist whitespace & line breaks, so we
* explicitly check for when the code is empty to use this workaround.
*/
const el = document.createElement('div');
el.innerHTML = codeBlock.innerHTML;
code = el.outerText;
}
return {
[fileName]: code,
};
})
.reduce((acc, curr) => ({ ...acc, ...curr }), {});
editorOptions.dependencies = (code[usageTarget] as UsageTargetOptions).dependencies;
}
Expand Down
2 changes: 1 addition & 1 deletion static/usage/v6/tabs/router/angular/app_module_ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ExampleComponent } from './example.component';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
imports: [BrowserModule, FormsModule, AppRoutingModule, IonicModule.forRoot()],
imports: [BrowserModule, FormsModule, AppRoutingModule, IonicModule.forRoot({})],
declarations: [AppComponent, ExampleComponent],
bootstrap: [AppComponent],
})
Expand Down
2 changes: 1 addition & 1 deletion static/usage/v7/tabs/router/angular/app_module_ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ExampleComponent } from './example.component';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
imports: [BrowserModule, FormsModule, AppRoutingModule, IonicModule.forRoot()],
imports: [BrowserModule, FormsModule, AppRoutingModule, IonicModule.forRoot({})],
declarations: [AppComponent, ExampleComponent],
bootstrap: [AppComponent],
})
Expand Down