Skip to content

Commit

Permalink
Merge pull request #14240 from primefaces/stackblitz-dependency
Browse files Browse the repository at this point in the history
Stackblitz dependency
  • Loading branch information
cetincakiroglu authored Nov 29, 2023
2 parents c18d2e1 + 8d3a8fe commit f88ef21
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 12 deletions.
95 changes: 95 additions & 0 deletions src/app/showcase/layout/doc/code/app.code.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { CommonModule } from '@angular/common';
import { Component, ElementRef, Input, NgModule, ViewChild } from '@angular/core';
import { ButtonModule } from 'primeng/button';
import { TooltipModule } from 'primeng/tooltip';
import { Code, ExtFile, RouteFile } from 'src/app/showcase/domain/code';
import { useCodeSandbox, useStackBlitz } from '../codeeditor';

@Component({
selector: 'app-code',
templateUrl: './app.code.component.html'
})
export class AppCodeComponent {
@Input() code!: Code;

@Input() service!: any;

@Input() selector!: string;

@Input() extFiles: ExtFile[] = [];

@Input() routeFiles: RouteFile[] = [];

@Input() hideToggleCode: boolean = false;

@Input() hideCodeSandbox: boolean = false;

@Input() hideStackBlitz: boolean = false;

@ViewChild('codeElement') codeElement: ElementRef;

fullCodeVisible: boolean = false;

lang!: string;

ngAfterViewChecked() {
if (typeof window !== undefined && window['Prism'] && this.codeElement && !this.codeElement.nativeElement.classList.contains('prism')) {
window['Prism'].highlightElement(this.codeElement.nativeElement);
this.codeElement.nativeElement.classList.add('prism');
this.codeElement.nativeElement.parentElement.setAttribute('tabindex', '-1');
}
}

ngOnInit() {
this.lang = this.getInitialLang();
}

changeLang(lang: string) {
this.lang = lang;
}

getInitialLang(): string {
if (this.code) {
return Object.keys(this.code)[0];
}
}

async copyCode() {
await navigator.clipboard.writeText(this.code[this.lang]);
}

getCode(lang: string = 'basic') {
if (this.code) {
if (this.fullCodeVisible || this.hideToggleCode) {
return this.code[lang];
} else {
return this.code['basic'];
}
}
}

toggleCode() {
this.fullCodeVisible = !this.fullCodeVisible;
this.fullCodeVisible && (this.lang = 'html');
!this.fullCodeVisible && (this.lang = 'basic');
}

openStackBlitz() {
if (this.code) {
useStackBlitz({ code: this.code, selector: this.selector, extFiles: this.extFiles, routeFiles: this.routeFiles });
}
}

openCodeSandbox() {
if (this.code) {
useCodeSandbox({ code: this.code, selector: this.selector, extFiles: this.extFiles, routeFiles: this.routeFiles });
}
}
}

@NgModule({
imports: [CommonModule, ButtonModule, TooltipModule],
exports: [AppCodeComponent],
declarations: [AppCodeComponent]
})
export class AppCodeModule {}
50 changes: 38 additions & 12 deletions src/app/showcase/layout/doc/codeeditor/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,43 @@ const PrimeNG = {
'PrimeNG is an open source UI library for Angular featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock, which has 370+ ready to use UI blocks to build spectacular applications in no time.'
};

const demoDependencies = [
"@angular-devkit/build-angular",
"@angular/animations",
"@angular/cdk",
"@angular/cli",
"@angular/common",
"@angular/compiler",
"@angular/compiler-cli",
"@angular/core",
"@angular/forms",
"@angular/material",
"@angular/material-moment-adapter",
"@angular/platform-browser",
"@angular/platform-browser-dynamic",
"@angular/platform-server",
"@angular/router",
"@nguniversal/builders",
"@nguniversal/common",
"@nguniversal/express-engine",
"quill",
"primeflex",
"chart.js",
"primeicons",
"rxjs",
"tslib",
"zone.js"
];

const getAppDependencies = () => {
const dependencies = {};
for (const key in app_dependencies) {
if (checkDependency(key)) {
dependencies[key] = app_dependencies[key];
}
}
const dependencies = {};
for (const key in app_dependencies) {
if (demoDependencies.includes(key)) {
dependencies[key] = app_dependencies[key];
}
}

return dependencies;
return dependencies;
};

const getDependencies = () => {
Expand All @@ -42,10 +70,6 @@ const getDependencies = () => {
return dependencies;
};

const checkDependency = (dep: string) => {
return !(dep.startsWith('jasmine') || dep.startsWith('del') || dep.startsWith('gulp') || dep.startsWith('jspdf') || dep.startsWith('prism') || dep.startsWith('del') || dep.startsWith('@stackblitz'));
};

const getServiceImports = (service: string[]) => {
return service.map((s) => `import { ${s} } from 'src/service/${s.toLowerCase()}';`).join('');
};
Expand Down Expand Up @@ -455,6 +479,8 @@ Firefox ESR
not ios_saf 15.2-15.3
not safari 15.2-15.3`;



const getAngularApp = (props: Props = {}) => {
const { code, extFiles, routeFiles, selector } = props;
const dependencies = getDependencies();
Expand Down Expand Up @@ -704,7 +730,7 @@ export class AppModule {}`;
'src/index.html': { content: index_html },
'src/karma.conf.js': { content: karma_conf_js },
'src/styles.scss': { content: staticStyles.global },
'src/flags.css': { content: staticStyles.flags }
'src/flags.css': { content: staticStyles.flags },
};

const files = {
Expand Down

0 comments on commit f88ef21

Please sign in to comment.