Skip to content

Commit

Permalink
chore(demo): update stackblitz starter
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed May 8, 2024
1 parent b2e44b0 commit 72dcf1c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 77 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class StackblitzDepsService {
'@tinkoff/ng-polymorpheus': `latest`,
'@tinkoff/ng-dompurify': `latest`,
dompurify: `latest`,
punycode: `latest`,
typescript: `5.3.x`,
'@tinkoff/tui-editor': `1.x.x`,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {tuiRawLoad, tuiTryParseMarkdownCodeBlock} from '@taiga-ui/addon-doc';

interface TuiProjectFiles {
angularJson: string;
appModuleTs: string;
indexHtml: string;
mainTs: string;
polyfills: string;
Expand All @@ -18,15 +17,13 @@ export abstract class AbstractTuiStackblitzResourcesLoader {
indexHtmlContent,
polyfillsContent,
stylesContent,
appModuleTsContent,
]: string[] = await Promise.all(
[
import(`./project-files/configs.md?raw`),
import(`./project-files/src/main.ts.md?raw`),
import(`./project-files/src/index.html.md?raw`),
import(`./project-files/src/polyfills.ts.md?raw`),
import(`./project-files/src/styles.less.md?raw`),
import(`./project-files/src/app/app.module.ts.md?raw`),
].map(tuiRawLoad),
);

Expand All @@ -35,8 +32,7 @@ export abstract class AbstractTuiStackblitzResourcesLoader {
const [indexHtml] = tuiTryParseMarkdownCodeBlock(indexHtmlContent);
const [polyfills] = tuiTryParseMarkdownCodeBlock(polyfillsContent);
const [styles] = tuiTryParseMarkdownCodeBlock(stylesContent);
const [appModuleTs] = tuiTryParseMarkdownCodeBlock(appModuleTsContent);

return {angularJson, tsconfig, mainTs, indexHtml, polyfills, appModuleTs, styles};
return {angularJson, tsconfig, mainTs, indexHtml, polyfills, styles};
}
}
34 changes: 3 additions & 31 deletions projects/demo/src/app/pages/stackblitz/stackblitz.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ import stackblitz, {OpenOptions, Project} from '@stackblitz/sdk';
import {TuiCodeEditor} from '@taiga-ui/addon-doc';
import {PolymorpheusComponent} from '@tinkoff/ng-polymorpheus';

import {TsFileComponentParser, TsFileModuleParser} from './classes';
import {TsFileComponentParser} from './classes';
import {StackblitzDepsService} from './stackblitz-deps.service';
import {AbstractTuiStackblitzResourcesLoader} from './stackblitz-resources-loader';
import {StackblitzEditButtonComponent} from './starter/stackblitz-edit-button.component';
import {
appPrefix,
getComponentsClassNames,
getSupportFiles,
getSupportModules,
prepareLess,
prepareSupportFiles,
} from './utils';
import {appPrefix, getSupportFiles, prepareLess, prepareSupportFiles} from './utils';

const APP_COMP_META = {
SELECTOR: `my-app`,
Expand Down Expand Up @@ -42,29 +35,10 @@ export class TuiStackblitzService implements TuiCodeEditor {
return;
}

const {appModuleTs} =
await AbstractTuiStackblitzResourcesLoader.getProjectFiles();

const appModule = new TsFileModuleParser(appModuleTs);
const appCompTs = new TsFileComponentParser(content.TypeScript);
const supportFilesTuples = getSupportFiles(content);
const supportModulesTuples = getSupportModules(supportFilesTuples);
const supportCompClassNames = getComponentsClassNames(supportFilesTuples);
const modifiedSupportFiles = prepareSupportFiles(supportFilesTuples);

supportCompClassNames.forEach(([fileName, className]) => {
const insideAnotherModule = supportModulesTuples.some(([_, module]) =>
module.hasDeclarationEntity(className),
);

if (insideAnotherModule) {
return;
}

appModule.addImport(className, `./${fileName}`);
appModule.addDeclaration(className);
});

appCompTs.selector = APP_COMP_META.SELECTOR;
appCompTs.templateUrl = APP_COMP_META.TEMPLATE_URL;
appCompTs.styleUrls = APP_COMP_META.STYLE_URLS;
Expand All @@ -77,7 +51,6 @@ export class TuiStackblitzService implements TuiCodeEditor {
files: {
...(await this.getBaseAngularProjectFiles()),
...modifiedSupportFiles,
[appPrefix`app.module.ts`]: appModule.toString(),
[appPrefix`app.component.ts`]: appCompTs.toString(),
[appPrefix`app.component.html`]: `<tui-root>\n\n${content.HTML}\n</tui-root>`,
[appPrefix`app.component.less`]: prepareLess(content.LESS || ``),
Expand All @@ -104,7 +77,7 @@ export class TuiStackblitzService implements TuiCodeEditor {
}

private async getBaseAngularProjectFiles(): Promise<Project['files']> {
const {tsconfig, angularJson, mainTs, polyfills, indexHtml, styles, appModuleTs} =
const {tsconfig, angularJson, mainTs, polyfills, indexHtml, styles} =
await AbstractTuiStackblitzResourcesLoader.getProjectFiles();

return {
Expand All @@ -114,7 +87,6 @@ export class TuiStackblitzService implements TuiCodeEditor {
'src/polyfills.ts': polyfills,
'src/index.html': indexHtml,
'src/styles.less': styles,
[appPrefix`app.module.ts`]: appModuleTs.toString(),
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
```ts
import {ChangeDetectionStrategy, Component} from '@angular/core';
import {ChangeDetectionStrategy, Component, Injector, INJECTOR} from '@angular/core';
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
import {TuiRootModule} from '@taiga-ui/core';
import {
defaultEditorExtensions,
defaultEditorTools,
TUI_EDITOR_DEFAULT_EDITOR_TOOLS,
TUI_EDITOR_DEFAULT_EXTENSIONS,
TUI_EDITOR_EXTENSIONS,
TuiEditorModule,
TuiEditorSocketModule,
Expand All @@ -21,13 +21,19 @@ import {
providers: [
{
provide: TUI_EDITOR_EXTENSIONS,
useValue: defaultEditorExtensions,
deps: [INJECTOR],
useFactory: (injector: Injector) => [
...TUI_EDITOR_DEFAULT_EXTENSIONS,
import('@tinkoff/tui-editor/extensions/image-editor').then(({tuiCreateImageEditorExtension}) =>
tuiCreateImageEditorExtension({injector}),
),
],
},
],
})
export class AppComponent {
readonly control = new FormControl();

readonly tools: TuiEditorTool[] = defaultEditorTools;
readonly tools: TuiEditorTool[] = TUI_EDITOR_DEFAULT_EDITOR_TOOLS;
}
```

0 comments on commit 72dcf1c

Please sign in to comment.