Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 6b5d0bb

Browse files
committed
fix(stack-blitz): add more configuration files to the template
allow the exported/downloaded project from StackBlitz to be functional - move files into /src and /src/app to match a normal configuration rename Stackblitz to StackBlitz use StackBlitz logo to launch examples use a relative URL for downloading `versions.json` update Ivy fix for VersionPicker log errors during app bootstrap in StackBlitz switch StackBlitz examples to SCSS fix lint warnings in deploy script add ignores for Firebase Fixes #623. Fixes #629. Relates to #642.
1 parent d8939ac commit 6b5d0bb

29 files changed

+535
-112
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ speed-measure-plugin*.json
4040
npm-debug.log
4141
yarn-error.log
4242
testem.log
43+
firebase-debug.log
44+
.firebase/
4345
/typings
4446

4547
#System Files

src/app/app-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {ComponentHeaderModule} from './pages/component-page-header/component-pag
2020
import {StyleManager} from './shared/style-manager';
2121
import {SvgViewerModule} from './shared/svg-viewer/svg-viewer';
2222
import {ThemePickerModule} from './shared/theme-picker';
23-
import {StackblitzButtonModule} from './shared/stackblitz';
23+
import {StackBlitzButtonModule} from './shared/stack-blitz';
2424
import {NavBarModule} from './shared/navbar';
2525
import {ThemeStorage} from './shared/theme-picker/theme-storage/theme-storage';
2626
import {GuideItems} from './shared/guide-items/guide-items';
@@ -58,7 +58,7 @@ import {GaService} from './shared/ga/ga';
5858
GuideViewerModule,
5959
HomepageModule,
6060
NavBarModule,
61-
StackblitzButtonModule,
61+
StackBlitzButtonModule,
6262
SvgViewerModule,
6363
ThemePickerModule,
6464
],

src/app/shared/doc-viewer/doc-viewer-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {DocViewer} from './doc-viewer';
22
import {ExampleViewer} from '../example-viewer/example-viewer';
3-
import {StackblitzButtonModule} from '../stackblitz/stackblitz-button';
3+
import {StackBlitzButtonModule} from '../stack-blitz/stack-blitz-button';
44
import {MatButtonModule} from '@angular/material/button';
55
import {MatIconModule} from '@angular/material/icon';
66
import {MatSnackBarModule} from '@angular/material/snack-bar';
@@ -23,7 +23,7 @@ import {CopierService} from '../copier/copier.service';
2323
MatTabsModule,
2424
CommonModule,
2525
PortalModule,
26-
StackblitzButtonModule
26+
StackBlitzButtonModule
2727
],
2828
providers: [CopierService],
2929
declarations: [DocViewer, ExampleViewer, HeaderLink],

src/app/shared/example-viewer/example-viewer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</mat-icon>
1313
</button>
1414

15-
<stackblitz-button [example]="example"></stackblitz-button>
15+
<stack-blitz-button [example]="example"></stack-blitz-button>
1616
</div>
1717

1818
<div class="docs-example-viewer-source" *ngIf="showSource">

src/app/shared/stack-blitz/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './stack-blitz-button';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<div [matTooltip]="isDisabled ? 'Building StackBlitz example...' : 'Edit in StackBlitz'">
2+
<button mat-icon-button type="button"
3+
(click)="openStackBlitz()"
4+
[disabled]="isDisabled">
5+
<mat-icon>
6+
<svg width='24px' height='24px' viewBox='0 -3 23 40' version='1.1'
7+
xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>
8+
<title>StackBlitz Logo</title>
9+
<desc>Created with Sketch.</desc>
10+
<g id='Symbols' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'>
11+
<g fill='#1389FD' fill-rule='nonzero'>
12+
<polygon id='Path'
13+
points='0 19.9187087 9.87007874 19.9187087 4.12007874 34 23 13.9612393 13.0846457 13.9612393 18.7893701 0'>
14+
</polygon>
15+
</g>
16+
</g>
17+
</svg>
18+
</mat-icon>
19+
</button>
20+
</div>
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
11
import {Component, Input, NgModule} from '@angular/core';
2-
import {StackblitzWriter} from './stackblitz-writer';
32
import {ExampleData} from '@angular/material-examples';
43
import {MatButtonModule} from '@angular/material/button';
54
import {MatIconModule} from '@angular/material/icon';
65
import {MatTooltipModule} from '@angular/material/tooltip';
6+
import {StackBlitzWriter} from './stack-blitz-writer';
77

88
@Component({
9-
selector: 'stackblitz-button',
10-
templateUrl: './stackblitz-button.html',
11-
providers: [StackblitzWriter],
9+
selector: 'stack-blitz-button',
10+
templateUrl: './stack-blitz-button.html',
11+
providers: [StackBlitzWriter],
1212
host: {
13-
'(mouseover)': 'isDisabled = !stackblitzForm'
13+
'(mouseover)': 'isDisabled = !stackBlitzForm'
1414
}
1515
})
16-
export class StackblitzButton {
16+
export class StackBlitzButton {
1717
/**
18-
* The button becomes disabled if the user hovers over the button before the stackblitz form
18+
* The button becomes disabled if the user hovers over the button before the StackBlitz form
1919
* is created. After the form is created, the button becomes enabled again.
2020
* The form creation usually happens extremely quickly, but we handle the case of the
21-
* stackblitz not yet being ready for people with poor network connections or slow devices.
21+
* StackBlitz not yet being ready for people with poor network connections or slow devices.
2222
*/
2323
isDisabled = false;
24-
stackblitzForm: HTMLFormElement;
24+
stackBlitzForm: HTMLFormElement;
2525

2626
@Input()
2727
set example(example: string) {
2828
const exampleData = new ExampleData(example);
2929

3030
if (example) {
31-
this.stackblitzWriter.constructStackblitzForm(exampleData).then(stackblitzForm => {
32-
this.stackblitzForm = stackblitzForm;
31+
this.stackBlitzWriter.constructStackBlitzForm(exampleData)
32+
.then((stackBlitzForm: HTMLFormElement) => {
33+
this.stackBlitzForm = stackBlitzForm;
3334
this.isDisabled = false;
3435
});
3536
} else {
3637
this.isDisabled = true;
3738
}
3839
}
3940

40-
constructor(private stackblitzWriter: StackblitzWriter) {}
41+
constructor(private stackBlitzWriter: StackBlitzWriter) {}
4142

42-
openStackblitz(): void {
43+
openStackBlitz(): void {
4344
// When the form is submitted, it must be in the document body. The standard of forms is not
4445
// to submit if it is detached from the document. See the following chromium commit for
4546
// more details:
4647
// https://chromium.googlesource.com/chromium/src/+/962c2a22ddc474255c776aefc7abeba00edc7470%5E!
47-
document.body.appendChild(this.stackblitzForm);
48-
this.stackblitzForm.submit();
49-
document.body.removeChild(this.stackblitzForm);
48+
document.body.appendChild(this.stackBlitzForm);
49+
this.stackBlitzForm.submit();
50+
document.body.removeChild(this.stackBlitzForm);
5051
}
5152
}
5253

5354
@NgModule({
5455
imports: [MatTooltipModule, MatButtonModule, MatIconModule],
55-
exports: [StackblitzButton],
56-
declarations: [StackblitzButton],
57-
providers: [StackblitzWriter],
56+
exports: [StackBlitzButton],
57+
declarations: [StackBlitzButton],
58+
providers: [StackBlitzWriter],
5859
})
59-
export class StackblitzButtonModule {}
60+
export class StackBlitzButtonModule {}

src/app/shared/stackblitz/stackblitz-writer.spec.ts renamed to src/app/shared/stack-blitz/stack-blitz-writer.spec.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
22
import {async, fakeAsync, flushMicrotasks, inject, TestBed} from '@angular/core/testing';
33
import {ExampleData} from '@angular/material-examples';
4-
import {StackblitzWriter} from './stackblitz-writer';
4+
import {StackBlitzWriter} from './stack-blitz-writer';
55

66

7-
describe('StackblitzWriter', () => {
8-
let stackblitzWriter: StackblitzWriter;
7+
describe('StackBlitzWriter', () => {
8+
let stackBlitzWriter: StackBlitzWriter;
99
let data: ExampleData;
1010
let http: HttpTestingController;
1111

@@ -14,7 +14,7 @@ describe('StackblitzWriter', () => {
1414
imports: [HttpClientTestingModule],
1515
declarations: [],
1616
providers: [
17-
StackblitzWriter,
17+
StackBlitzWriter,
1818
]
1919
}).compileComponents();
2020
}));
@@ -24,19 +24,19 @@ describe('StackblitzWriter', () => {
2424
}));
2525

2626
beforeEach(() => {
27-
stackblitzWriter = TestBed.get(StackblitzWriter);
27+
stackBlitzWriter = TestBed.get(StackBlitzWriter);
2828
data = new ExampleData('');
2929
data.exampleFiles = ['test.ts', 'test.html', 'src/detail.ts'];
3030
});
3131

3232
it('should append correct copyright', () => {
33-
expect(stackblitzWriter._appendCopyright('test.ts', 'NoContent')).toBe(`NoContent
33+
expect(stackBlitzWriter._appendCopyright('test.ts', 'NoContent')).toBe(`NoContent
3434
3535
/** Copyright 2019 Google LLC. All Rights Reserved.
3636
Use of this source code is governed by an MIT-style license that
3737
can be found in the LICENSE file at http://angular.io/license */`);
3838

39-
expect(stackblitzWriter._appendCopyright('test.html', 'NoContent')).toBe(`NoContent
39+
expect(stackBlitzWriter._appendCopyright('test.html', 'NoContent')).toBe(`NoContent
4040
4141
<!-- Copyright 2019 Google LLC. All Rights Reserved.
4242
Use of this source code is governed by an MIT-style license that
@@ -45,27 +45,27 @@ describe('StackblitzWriter', () => {
4545
});
4646

4747
it('should create form element', () => {
48-
expect(stackblitzWriter._createFormElement('index.ts').outerHTML).toBe(
48+
expect(stackBlitzWriter._createFormElement('index.ts').outerHTML).toBe(
4949
`<form action="https://run.stackblitz.com/api/angular/v1?file=index.ts" ` +
5050
`method="post" target="_blank"></form>`);
5151
});
5252

5353
it('should add files to form input', () => {
54-
let form = stackblitzWriter._createFormElement('index.ts');
54+
let form = stackBlitzWriter._createFormElement('index.ts');
5555

56-
stackblitzWriter._addFileToForm(form, data, 'NoContent', 'test.ts', 'path/to/file');
57-
stackblitzWriter._addFileToForm(form, data, 'Test', 'test.html', 'path/to/file');
58-
stackblitzWriter._addFileToForm(form, data, 'Detail', 'src/detail.ts', 'path/to/file');
56+
stackBlitzWriter._addFileToForm(form, data, 'NoContent', 'test.ts', 'path/to/file');
57+
stackBlitzWriter._addFileToForm(form, data, 'Test', 'test.html', 'path/to/file');
58+
stackBlitzWriter._addFileToForm(form, data, 'Detail', 'src/detail.ts', 'path/to/file');
5959

6060
expect(form.elements.length).toBe(3);
61-
expect(form.elements[0].getAttribute('name')).toBe('files[app/test.ts]');
62-
expect(form.elements[1].getAttribute('name')).toBe('files[app/test.html]');
63-
expect(form.elements[2].getAttribute('name')).toBe('files[app/src/detail.ts]');
61+
expect(form.elements[0].getAttribute('name')).toBe('files[src/app/test.ts]');
62+
expect(form.elements[1].getAttribute('name')).toBe('files[src/app/test.html]');
63+
expect(form.elements[2].getAttribute('name')).toBe('files[src/app/src/detail.ts]');
6464
});
6565

6666
it('should open a new window with stackblitz url', fakeAsync(() => {
6767
let form: HTMLFormElement;
68-
stackblitzWriter.constructStackblitzForm(data).then((result: HTMLFormElement) => {
68+
stackBlitzWriter.constructStackBlitzForm(data).then((result: HTMLFormElement) => {
6969
form = result;
7070
flushMicrotasks();
7171

@@ -91,14 +91,14 @@ describe('StackblitzWriter', () => {
9191
expect(form.elements[5].getAttribute('name')).toBe('dependencies');
9292

9393
// Should have files needed for example.
94-
expect(form.elements[6].getAttribute('name')).toBe('files[index.html]');
95-
expect(form.elements[7].getAttribute('name')).toBe('files[styles.css]');
96-
expect(form.elements[8].getAttribute('name')).toBe('files[polyfills.ts]');
97-
expect(form.elements[9].getAttribute('name')).toBe('files[main.ts]');
98-
expect(form.elements[10].getAttribute('name')).toBe('files[material-module.ts]');
99-
expect(form.elements[11].getAttribute('name')).toBe('files[app/test.ts]');
100-
expect(form.elements[12].getAttribute('name')).toBe('files[app/test.html]');
101-
expect(form.elements[13].getAttribute('name')).toBe('files[app/src/detail.ts]');
94+
expect(form.elements[6].getAttribute('name')).toBe('files[src/index.html]');
95+
expect(form.elements[7].getAttribute('name')).toBe('files[src/styles.scss]');
96+
expect(form.elements[8].getAttribute('name')).toBe('files[src/polyfills.ts]');
97+
expect(form.elements[9].getAttribute('name')).toBe('files[src/main.ts]');
98+
expect(form.elements[10].getAttribute('name')).toBe('files[src/app/material-module.ts]');
99+
expect(form.elements[11].getAttribute('name')).toBe('files[src/app/test.ts]');
100+
expect(form.elements[12].getAttribute('name')).toBe('files[src/app/test.html]');
101+
expect(form.elements[13].getAttribute('name')).toBe('files[src/app/src/detail.ts]');
102102
});
103103
}));
104104
});
@@ -110,11 +110,11 @@ const FAKE_DOCS: {[key: string]: string} = {
110110
};
111111

112112
const TEST_URLS = [
113-
'/assets/stackblitz/index.html',
114-
'/assets/stackblitz/styles.css',
115-
'/assets/stackblitz/polyfills.ts',
116-
'/assets/stackblitz/main.ts',
117-
'/assets/stackblitz/material-module.ts',
113+
'/assets/stack-blitz/src/index.html',
114+
'/assets/stack-blitz/src/styles.scss',
115+
'/assets/stack-blitz/src/polyfills.ts',
116+
'/assets/stack-blitz/src/main.ts',
117+
'/assets/stack-blitz/src/app/material-module.ts',
118118
'/docs-content/examples-source/test.ts',
119119
'/docs-content/examples-source/test.html',
120120
'/docs-content/examples-source/src/detail.ts',

0 commit comments

Comments
 (0)