Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(demo): add external stackblitz playground #9084

Merged
merged 1 commit into from
Sep 24, 2024
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
2 changes: 2 additions & 0 deletions projects/demo/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const environment = {
production: true,
ym: 87890624,
playground:
'https://stackblitz.com/~/github.com/taiga-family/taiga-playground?file=src/app/app.component.html',
};
2 changes: 2 additions & 0 deletions projects/demo/src/modules/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Component, DestroyRef, inject, ViewEncapsulation} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {NavigationEnd, Router} from '@angular/router';
import {changeDetection} from '@demo/emulate/change-detection';
import {environment} from '@demo/environments/environment';
import {DemoRoute} from '@demo/routes';
import {TuiDemo} from '@demo/utils';
import {WA_LOCAL_STORAGE} from '@ng-web-apis/common';
Expand Down Expand Up @@ -61,6 +62,7 @@ export class App extends AbstractDemo implements OnInit {
protected readonly router = inject(Router);
protected readonly storage = inject(WA_LOCAL_STORAGE);
protected readonly routes = DemoRoute;
protected readonly playground = environment.playground;

protected readonly isLanding$ = this.router.events.pipe(
filter((event) => event instanceof NavigationEnd),
Expand Down
4 changes: 3 additions & 1 deletion projects/demo/src/modules/app/app.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@
<a
appearance="icon"
iconStart="assets/icons/stackblitz.svg"
rel="noreferrer"
target="_blank"
splincode marked this conversation as resolved.
Show resolved Hide resolved
title="Taiga UI StackBlitz Starter"
tuiLink
class="app-link"
[routerLink]="routes.StackblitzStarter"
[href]="playground"
></a>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type {TuiCodeEditor} from '@taiga-ui/addon-doc';
import {PolymorpheusComponent} from '@taiga-ui/polymorpheus';

import {TsFileComponentParser} from '../classes';
import {StackblitzEditButton} from './edit';
import {StackblitzDepsService} from './stackblitz-deps.service';
import {AbstractTuiStackblitzResourcesLoader} from './stackblitz-resources-loader';
import {StackblitzEditButton} from './starter/stackblitz-edit';
import {appPrefix, getSupportFiles, prepareLess, prepareSupportFiles} from './utils';

const APP_COMP_META = {
Expand Down

This file was deleted.

This file was deleted.

53 changes: 7 additions & 46 deletions projects/demo/src/modules/app/stackblitz/starter/index.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,17 @@
import {isPlatformBrowser} from '@angular/common';
import type {OnInit} from '@angular/core';
import {ChangeDetectionStrategy, Component, inject, PLATFORM_ID} from '@angular/core';
import {TuiDemo} from '@demo/utils';
import {tuiRawLoad, tuiTryParseMarkdownCodeBlock} from '@taiga-ui/addon-doc';
import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import {environment} from '@demo/environments/environment';
import {WA_WINDOW} from '@ng-web-apis/common';
import {TuiLoader} from '@taiga-ui/core';

import {TuiStackblitzService} from '../stackblitz.service';
import {appPrefix} from '../utils';

@Component({
standalone: true,
imports: [TuiDemo, TuiLoader],
imports: [TuiLoader],
templateUrl: './index.html',
styleUrls: ['./index.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [TuiStackblitzService],
})
export default class Page implements OnInit {
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
private readonly stackblitz = inject(TuiStackblitzService);

public async ngOnInit(): Promise<void> {
if (this.isBrowser) {
await this.openStackblitz();
}
}

protected async openStackblitz(): Promise<void> {
const [appTemplate, appComponent] = await Promise.all(
[
import('./files/app.template.html.md?raw'),
import('./files/app.component.ts.md?raw'),
].map(tuiRawLoad),
).then((markdowns) => markdowns.map((md) => tuiTryParseMarkdownCodeBlock(md)[0]));

return this.stackblitz.openStarter(
{
title: 'Taiga UI Starter',
description:
'A starter with Taiga UI library\nDocumentation: https://taiga-ui.dev',
files: {
[appPrefix`app.template.html`]: appTemplate ?? '',
[appPrefix`app.component.ts`]: appComponent ?? '',
[appPrefix`app.style.less`]:
"@import '@taiga-ui/core/styles/taiga-ui-local.less';",
},
},
{
newWindow: false,
openFile: appPrefix`app.template.html`,
hideExplorer: true,
},
);
export default class Page {
constructor() {
splincode marked this conversation as resolved.
Show resolved Hide resolved
inject(WA_WINDOW).location.replace(environment.playground);
}
}
Loading