Skip to content

Commit

Permalink
docs: fix stackblitz
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikarin committed Jun 9, 2024
1 parent 9ede45c commit 9964538
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 220 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/app/docs/components/example/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
</xui-tab>

@for (file of content$ | async; track file.name) {
@for (file of content(); track file.name) {
<xui-tab [title]="file.name">
<pre><code lineNumbers="true" [language]="getFileType(file)" [highlight]="file.content"></code></pre>
</xui-tab>
Expand Down
42 changes: 19 additions & 23 deletions apps/web/src/app/docs/components/example/example.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ChangeDetectionStrategy, Component, Inject, input, Input, OnInit } from '@angular/core';
import {ChangeDetectionStrategy, Component, Inject, input, OnInit, signal} from '@angular/core';
import { convertToBoolean, XuiCardModule, XuiIcon, XuiTabModule, XuiTooltipModule } from '@xui/components';
import sdk, { Project, ProjectFiles } from '@stackblitz/sdk';
import { HttpClient } from '@angular/common/http';
import { BehaviorSubject, lastValueFrom } from 'rxjs';
import { BooleanInput } from '@angular/cdk/coercion';
import { lastValueFrom } from 'rxjs';
import { CommonModule, DOCUMENT } from '@angular/common';
import { angularProject } from '../../../../templates/angular';
import { HighlightModule } from 'ngx-highlightjs';
Expand All @@ -28,18 +27,17 @@ import { HighlightLineNumbers } from 'ngx-highlightjs/line-numbers';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class Example implements OnInit {
static ngAcceptInputType_todo: BooleanInput;
content$ = new BehaviorSubject<File[]>([]);
content = signal<File[]>([]);

@Input() files: { [name: string]: FileType } = {};
files = input<Files>();
todo = input(false, { transform: (v: string | boolean) => convertToBoolean(v) });

get project(): Project {
return <Project>{
...angularProject,
files: {
...this.injectedAngularFiles(this.content$.value),
...this.content$.value.reduce(
...this.injectedAngularFiles(this.content()),
...this.content().reduce(
(obj, val) => {
obj[val.path] = val.content;
return obj;
Expand All @@ -50,21 +48,18 @@ export class Example implements OnInit {
};
}

constructor(
private http: HttpClient,
@Inject(DOCUMENT) private document: Document
) {}
constructor(private http: HttpClient, @Inject(DOCUMENT) private document: Document) {}

async ngOnInit() {
this.content$.next(await this.fetchFiles());
this.content.set(await this.fetchFiles());
}

async fetchFiles() {
const files: File[] = [];

// TODO: finish this
for (const file of Object.keys(this.files)) {
if (this.files[file] === FileType.Component) {
for (const file of Object.keys(this.files()!)) {
if (this.files()![file] === FileType.Component) {
const ts = await this.fetchFile(file, 'component.ts');
const scss = await this.fetchFile(file, 'component.scss');
const html = await this.fetchFile(file, 'component.html');
Expand All @@ -88,7 +83,7 @@ export class Example implements OnInit {

for (const file of files) {
if (file.className) {
const path = file.path.replace('src/app/', '').replace('.ts', '');
const path = file.path.replace('src/', '').replace('.ts', '');
imports.push(`import { ${file.className} } from './${path}';`);
}

Expand All @@ -101,16 +96,13 @@ export class Example implements OnInit {
.filter(x => x.className)
.map(x => x.className)
.join(', ');

const ret = angularProject.files;
ret['src/app/app.module.ts'] = ret['src/app/app.module.ts']
ret['src/main.ts'] = ret['src/main.ts']
.replace('{{SELECTORS}}', selectors.join('\n'))
.replace('{{IMPORTS}}', imports.join('\n'))
.replace('{{DECLARATIONS}}', declarations);

ret['src/app/app.component.html'] = ret['src/app/app.component.html'].replace(
'{{SELECTORS}}',
selectors.join('\n')
);

return ret;
}

Expand All @@ -137,7 +129,7 @@ export class Example implements OnInit {
openProject() {
sdk.openProject(this.project, {
newWindow: true,
openFile: this.content$.value.map(x => x.path).join(',')
openFile: this.content().map(x => x.path).join(',')
});
}

Expand Down Expand Up @@ -187,3 +179,7 @@ export enum FileType {
Source,
Component
}

interface Files {
[name: string]: FileType
}
Loading

0 comments on commit 9964538

Please sign in to comment.