@storybook/angular 9.1.0-alpha.0 → 9.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-schema.json +199 -0
- package/builders.json +14 -0
- package/dist/builders/build-storybook/index.js +31 -80
- package/dist/builders/start-storybook/index.js +31 -101
- package/dist/chunk-CUDJAP6K.mjs +3 -0
- package/dist/chunk-KMSSK3DZ.mjs +6 -0
- package/dist/chunk-LXSTVAFF.mjs +40 -0
- package/dist/client/config.d.ts +20 -6
- package/dist/client/config.js +49 -20
- package/dist/client/config.mjs +10 -13
- package/dist/client/docs/config.d.ts +6 -3
- package/dist/client/docs/config.js +18 -14
- package/dist/client/docs/config.mjs +6 -10
- package/dist/client/index.d.ts +144 -6
- package/dist/client/index.js +47 -30
- package/dist/client/index.mjs +3 -9
- package/dist/client/preview-prod.d.ts +2 -1
- package/dist/client/preview-prod.js +5 -4
- package/dist/client/preview-prod.mjs +1 -0
- package/dist/index.d.ts +59 -2
- package/dist/index.js +47 -29
- package/dist/index.mjs +3 -13
- package/dist/preset.js +8 -38
- package/dist/server/framework-preset-angular-cli.js +20 -83
- package/dist/server/framework-preset-angular-ivy.js +6 -59
- package/dist/{client/types.d.ts → types-3b0b7107.d.ts} +9 -9
- package/package.json +71 -24
- package/start-schema.json +234 -0
- package/dist/builders/build-storybook/index.d.ts +0 -25
- package/dist/builders/build-storybook/index.mjs +0 -78
- package/dist/builders/build-storybook/index.spec.d.ts +0 -1
- package/dist/builders/build-storybook/index.spec.js +0 -222
- package/dist/builders/build-storybook/index.spec.mjs +0 -187
- package/dist/builders/build-storybook/schema.json +0 -199
- package/dist/builders/builders.json +0 -14
- package/dist/builders/start-storybook/index.d.ts +0 -21
- package/dist/builders/start-storybook/index.mjs +0 -99
- package/dist/builders/start-storybook/index.spec.d.ts +0 -1
- package/dist/builders/start-storybook/index.spec.js +0 -188
- package/dist/builders/start-storybook/index.spec.mjs +0 -186
- package/dist/builders/start-storybook/schema.json +0 -234
- package/dist/builders/utils/error-handler.d.ts +0 -2
- package/dist/builders/utils/error-handler.js +0 -38
- package/dist/builders/utils/error-handler.mjs +0 -33
- package/dist/builders/utils/run-compodoc.d.ts +0 -6
- package/dist/builders/utils/run-compodoc.js +0 -35
- package/dist/builders/utils/run-compodoc.mjs +0 -31
- package/dist/builders/utils/run-compodoc.spec.d.ts +0 -1
- package/dist/builders/utils/run-compodoc.spec.js +0 -76
- package/dist/builders/utils/run-compodoc.spec.mjs +0 -74
- package/dist/builders/utils/standalone-options.d.ts +0 -18
- package/dist/builders/utils/standalone-options.js +0 -2
- package/dist/builders/utils/standalone-options.mjs +0 -1
- package/dist/client/angular-beta/AbstractRenderer.d.ts +0 -75
- package/dist/client/angular-beta/AbstractRenderer.js +0 -201
- package/dist/client/angular-beta/AbstractRenderer.mjs +0 -164
- package/dist/client/angular-beta/CanvasRenderer.d.ts +0 -12
- package/dist/client/angular-beta/CanvasRenderer.js +0 -13
- package/dist/client/angular-beta/CanvasRenderer.mjs +0 -9
- package/dist/client/angular-beta/ComputesTemplateFromComponent.d.ts +0 -24
- package/dist/client/angular-beta/ComputesTemplateFromComponent.js +0 -160
- package/dist/client/angular-beta/ComputesTemplateFromComponent.mjs +0 -154
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.d.ts +0 -1
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.js +0 -730
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.mjs +0 -728
- package/dist/client/angular-beta/DocsRenderer.d.ts +0 -13
- package/dist/client/angular-beta/DocsRenderer.js +0 -39
- package/dist/client/angular-beta/DocsRenderer.mjs +0 -35
- package/dist/client/angular-beta/RendererFactory.d.ts +0 -11
- package/dist/client/angular-beta/RendererFactory.js +0 -56
- package/dist/client/angular-beta/RendererFactory.mjs +0 -50
- package/dist/client/angular-beta/RendererFactory.test.d.ts +0 -1
- package/dist/client/angular-beta/RendererFactory.test.js +0 -235
- package/dist/client/angular-beta/RendererFactory.test.mjs +0 -233
- package/dist/client/angular-beta/StorybookModule.d.ts +0 -8
- package/dist/client/angular-beta/StorybookModule.js +0 -27
- package/dist/client/angular-beta/StorybookModule.mjs +0 -23
- package/dist/client/angular-beta/StorybookModule.test.d.ts +0 -1
- package/dist/client/angular-beta/StorybookModule.test.js +0 -321
- package/dist/client/angular-beta/StorybookModule.test.mjs +0 -319
- package/dist/client/angular-beta/StorybookProvider.d.ts +0 -5
- package/dist/client/angular-beta/StorybookProvider.js +0 -26
- package/dist/client/angular-beta/StorybookProvider.mjs +0 -22
- package/dist/client/angular-beta/StorybookWrapperComponent.d.ts +0 -13
- package/dist/client/angular-beta/StorybookWrapperComponent.js +0 -127
- package/dist/client/angular-beta/StorybookWrapperComponent.mjs +0 -123
- package/dist/client/angular-beta/__testfixtures__/input.component.d.ts +0 -29
- package/dist/client/angular-beta/__testfixtures__/input.component.js +0 -76
- package/dist/client/angular-beta/__testfixtures__/input.component.mjs +0 -73
- package/dist/client/angular-beta/__testfixtures__/test.module.d.ts +0 -2
- package/dist/client/angular-beta/__testfixtures__/test.module.js +0 -20
- package/dist/client/angular-beta/__testfixtures__/test.module.mjs +0 -17
- package/dist/client/angular-beta/utils/BootstrapQueue.d.ts +0 -12
- package/dist/client/angular-beta/utils/BootstrapQueue.js +0 -86
- package/dist/client/angular-beta/utils/BootstrapQueue.mjs +0 -49
- package/dist/client/angular-beta/utils/BootstrapQueue.test.d.ts +0 -1
- package/dist/client/angular-beta/utils/BootstrapQueue.test.js +0 -164
- package/dist/client/angular-beta/utils/BootstrapQueue.test.mjs +0 -162
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.d.ts +0 -22
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.js +0 -93
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.mjs +0 -84
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.d.ts +0 -1
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.js +0 -388
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.mjs +0 -386
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.d.ts +0 -6
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.js +0 -41
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.mjs +0 -37
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.d.ts +0 -1
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.js +0 -24
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.mjs +0 -22
- package/dist/client/angular-beta/utils/PropertyExtractor.d.ts +0 -30
- package/dist/client/angular-beta/utils/PropertyExtractor.js +0 -196
- package/dist/client/angular-beta/utils/PropertyExtractor.mjs +0 -158
- package/dist/client/angular-beta/utils/PropertyExtractor.test.d.ts +0 -1
- package/dist/client/angular-beta/utils/PropertyExtractor.test.js +0 -177
- package/dist/client/angular-beta/utils/PropertyExtractor.test.mjs +0 -175
- package/dist/client/angular-beta/utils/StoryUID.d.ts +0 -22
- package/dist/client/angular-beta/utils/StoryUID.js +0 -43
- package/dist/client/angular-beta/utils/StoryUID.mjs +0 -38
- package/dist/client/argsToTemplate.d.ts +0 -56
- package/dist/client/argsToTemplate.js +0 -58
- package/dist/client/argsToTemplate.mjs +0 -55
- package/dist/client/argsToTemplate.test.d.ts +0 -1
- package/dist/client/argsToTemplate.test.js +0 -102
- package/dist/client/argsToTemplate.test.mjs +0 -100
- package/dist/client/compodoc-types.d.ts +0 -102
- package/dist/client/compodoc-types.js +0 -2
- package/dist/client/compodoc-types.mjs +0 -1
- package/dist/client/compodoc.d.ts +0 -12
- package/dist/client/compodoc.js +0 -261
- package/dist/client/compodoc.mjs +0 -248
- package/dist/client/compodoc.test.d.ts +0 -1
- package/dist/client/compodoc.test.js +0 -132
- package/dist/client/compodoc.test.mjs +0 -130
- package/dist/client/decorateStory.d.ts +0 -4
- package/dist/client/decorateStory.js +0 -48
- package/dist/client/decorateStory.mjs +0 -45
- package/dist/client/decorateStory.test.d.ts +0 -1
- package/dist/client/decorateStory.test.js +0 -306
- package/dist/client/decorateStory.test.mjs +0 -301
- package/dist/client/decorators.d.ts +0 -13
- package/dist/client/decorators.js +0 -69
- package/dist/client/decorators.mjs +0 -63
- package/dist/client/decorators.test.d.ts +0 -1
- package/dist/client/decorators.test.js +0 -159
- package/dist/client/decorators.test.mjs +0 -157
- package/dist/client/docs/__testfixtures__/doc-button/input.d.ts +0 -110
- package/dist/client/docs/__testfixtures__/doc-button/input.js +0 -204
- package/dist/client/docs/__testfixtures__/doc-button/input.mjs +0 -201
- package/dist/client/docs/__testfixtures__/doc-button/tsconfig.json +0 -7
- package/dist/client/docs/angular-properties.test.d.ts +0 -1
- package/dist/client/docs/angular-properties.test.js +0 -36
- package/dist/client/docs/angular-properties.test.mjs +0 -34
- package/dist/client/docs/sourceDecorator.d.ts +0 -10
- package/dist/client/docs/sourceDecorator.js +0 -53
- package/dist/client/docs/sourceDecorator.mjs +0 -48
- package/dist/client/globals.d.ts +0 -1
- package/dist/client/globals.js +0 -33
- package/dist/client/globals.mjs +0 -31
- package/dist/client/portable-stories.d.ts +0 -23
- package/dist/client/portable-stories.js +0 -62
- package/dist/client/portable-stories.mjs +0 -26
- package/dist/client/public-types.d.ts +0 -54
- package/dist/client/public-types.js +0 -2
- package/dist/client/public-types.mjs +0 -1
- package/dist/client/render.d.ts +0 -7
- package/dist/client/render.js +0 -19
- package/dist/client/render.mjs +0 -14
- package/dist/client/types.js +0 -2
- package/dist/client/types.mjs +0 -1
- package/dist/node/index.d.ts +0 -2
- package/dist/node/index.js +0 -6
- package/dist/node/index.mjs +0 -3
- package/dist/preset.d.ts +0 -5
- package/dist/preset.mjs +0 -34
- package/dist/renderer.d.ts +0 -6
- package/dist/renderer.js +0 -15
- package/dist/renderer.mjs +0 -6
- package/dist/server/__mocks-ng-workspace__/empty-projects-entry/angular.json +0 -4
- package/dist/server/__mocks-ng-workspace__/minimal-config/angular.json +0 -18
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/main.d.ts +0 -1
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/main.js +0 -5
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/main.mjs +0 -2
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/tsconfig.app.json +0 -9
- package/dist/server/__mocks-ng-workspace__/minimal-config/tsconfig.json +0 -13
- package/dist/server/__mocks-ng-workspace__/some-config/angular.json +0 -19
- package/dist/server/__mocks-ng-workspace__/some-config/src/main.d.ts +0 -1
- package/dist/server/__mocks-ng-workspace__/some-config/src/main.js +0 -5
- package/dist/server/__mocks-ng-workspace__/some-config/src/main.mjs +0 -2
- package/dist/server/__mocks-ng-workspace__/some-config/src/tsconfig.app.json +0 -9
- package/dist/server/__mocks-ng-workspace__/some-config/tsconfig.json +0 -13
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/angular.json +0 -64
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/main.d.ts +0 -1
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/main.js +0 -5
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/main.mjs +0 -2
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/tsconfig.app.json +0 -9
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/tsconfig.json +0 -13
- package/dist/server/__mocks-ng-workspace__/with-lib/angular.json +0 -28
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/src/main.d.ts +0 -1
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/src/main.js +0 -5
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/src/main.mjs +0 -2
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/tsconfig.lib.json +0 -20
- package/dist/server/__mocks-ng-workspace__/with-lib/tsconfig.json +0 -13
- package/dist/server/__mocks-ng-workspace__/with-nx/angular.json +0 -18
- package/dist/server/__mocks-ng-workspace__/with-nx/nx.json +0 -3
- package/dist/server/__mocks-ng-workspace__/with-nx/src/main.d.ts +0 -1
- package/dist/server/__mocks-ng-workspace__/with-nx/src/main.js +0 -5
- package/dist/server/__mocks-ng-workspace__/with-nx/src/main.mjs +0 -2
- package/dist/server/__mocks-ng-workspace__/with-nx/src/tsconfig.app.json +0 -8
- package/dist/server/__mocks-ng-workspace__/with-nx/tsconfig.json +0 -14
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/nx.json +0 -3
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/main.d.ts +0 -1
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/main.js +0 -5
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/main.mjs +0 -2
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/tsconfig.app.json +0 -8
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/tsconfig.json +0 -14
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/workspace.json +0 -18
- package/dist/server/__mocks-ng-workspace__/with-options-styles/angular.json +0 -18
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/main.d.ts +0 -1
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/main.js +0 -5
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/main.mjs +0 -2
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/tsconfig.app.json +0 -9
- package/dist/server/__mocks-ng-workspace__/with-options-styles/tsconfig.json +0 -13
- package/dist/server/__mocks-ng-workspace__/without-architect-build/angular.json +0 -5
- package/dist/server/__mocks-ng-workspace__/without-architect-build-options/angular.json +0 -11
- package/dist/server/__mocks-ng-workspace__/without-compatible-projects/angular.json +0 -7
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/angular.json +0 -3
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/src/main.d.ts +0 -1
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/src/main.js +0 -5
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/src/main.mjs +0 -2
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/tsconfig.lib.json +0 -20
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/tsconfig.json +0 -13
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/angular.json +0 -16
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/main.d.ts +0 -1
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/main.js +0 -5
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/main.mjs +0 -2
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/tsconfig.app.json +0 -9
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/tsconfig.json +0 -13
- package/dist/server/__tests__/angular.json +0 -96
- package/dist/server/angular-cli-webpack.d.ts +0 -1
- package/dist/server/angular-cli-webpack.js +0 -80
- package/dist/server/angular-cli-webpack.mjs +0 -80
- package/dist/server/framework-preset-angular-cli.d.ts +0 -3
- package/dist/server/framework-preset-angular-cli.mjs +0 -81
- package/dist/server/framework-preset-angular-ivy.d.ts +0 -10
- package/dist/server/framework-preset-angular-ivy.mjs +0 -56
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.d.ts +0 -12
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.js +0 -55
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.mjs +0 -52
- package/dist/server/preset-options.d.ts +0 -9
- package/dist/server/preset-options.js +0 -2
- package/dist/server/preset-options.mjs +0 -1
- package/dist/server/utils/filter-out-styling-rules.d.ts +0 -2
- package/dist/server/utils/filter-out-styling-rules.js +0 -17
- package/dist/server/utils/filter-out-styling-rules.mjs +0 -13
- package/dist/server/utils/module-is-available.d.ts +0 -1
- package/dist/server/utils/module-is-available.js +0 -13
- package/dist/server/utils/module-is-available.mjs +0 -9
- package/dist/test-setup.d.ts +0 -1
- package/dist/test-setup.js +0 -6
- package/dist/test-setup.mjs +0 -4
- package/dist/types.d.ts +0 -27
- package/dist/types.js +0 -2
- package/dist/types.mjs +0 -1
- package/scripts/postbuild.js +0 -17
- package/template/cli/.eslintrc.json +0 -5
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
// @vitest-environment happy-dom
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|
12
|
-
import { describe, expect, it } from 'vitest';
|
|
13
|
-
import { TestBed } from '@angular/core/testing';
|
|
14
|
-
import { BehaviorSubject } from 'rxjs';
|
|
15
|
-
import { getApplication } from './StorybookModule';
|
|
16
|
-
import { storyPropsProvider } from './StorybookProvider';
|
|
17
|
-
import { PropertyExtractor } from './utils/PropertyExtractor';
|
|
18
|
-
describe('StorybookModule', () => {
|
|
19
|
-
describe('getStorybookModuleMetadata', () => {
|
|
20
|
-
describe('with simple component', () => {
|
|
21
|
-
let FooComponent = class FooComponent {
|
|
22
|
-
constructor() {
|
|
23
|
-
this.output = new EventEmitter();
|
|
24
|
-
this.localOutput = new EventEmitter();
|
|
25
|
-
this.localFunction = () => '';
|
|
26
|
-
this.setterCallNb = 0;
|
|
27
|
-
}
|
|
28
|
-
set setter(value) {
|
|
29
|
-
this.setterCallNb += 1;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
__decorate([
|
|
33
|
-
Input(),
|
|
34
|
-
__metadata("design:type", String)
|
|
35
|
-
], FooComponent.prototype, "input", void 0);
|
|
36
|
-
__decorate([
|
|
37
|
-
Input('inputBindingPropertyName'),
|
|
38
|
-
__metadata("design:type", String)
|
|
39
|
-
], FooComponent.prototype, "localPropertyName", void 0);
|
|
40
|
-
__decorate([
|
|
41
|
-
Input(),
|
|
42
|
-
__metadata("design:type", String),
|
|
43
|
-
__metadata("design:paramtypes", [String])
|
|
44
|
-
], FooComponent.prototype, "setter", null);
|
|
45
|
-
__decorate([
|
|
46
|
-
Output(),
|
|
47
|
-
__metadata("design:type", Object)
|
|
48
|
-
], FooComponent.prototype, "output", void 0);
|
|
49
|
-
__decorate([
|
|
50
|
-
Output('outputBindingPropertyName'),
|
|
51
|
-
__metadata("design:type", Object)
|
|
52
|
-
], FooComponent.prototype, "localOutput", void 0);
|
|
53
|
-
FooComponent = __decorate([
|
|
54
|
-
Component({
|
|
55
|
-
selector: 'foo',
|
|
56
|
-
template: `
|
|
57
|
-
<p id="input">{{ input }}</p>
|
|
58
|
-
<p id="inputBindingPropertyName">{{ localPropertyName }}</p>
|
|
59
|
-
<p id="setterCallNb">{{ setterCallNb }}</p>
|
|
60
|
-
<p id="localProperty">{{ localProperty }}</p>
|
|
61
|
-
<p id="localFunction">{{ localFunction() }}</p>
|
|
62
|
-
<p id="output" (click)="output.emit('outputEmitted')"></p>
|
|
63
|
-
<p id="outputBindingPropertyName" (click)="localOutput.emit('outputEmitted')"></p>
|
|
64
|
-
`,
|
|
65
|
-
})
|
|
66
|
-
], FooComponent);
|
|
67
|
-
it('should initialize inputs', async () => {
|
|
68
|
-
const props = {
|
|
69
|
-
input: 'input',
|
|
70
|
-
inputBindingPropertyName: 'inputBindingPropertyName',
|
|
71
|
-
localProperty: 'localProperty',
|
|
72
|
-
localFunction: () => 'localFunction',
|
|
73
|
-
};
|
|
74
|
-
const analyzedMetadata = new PropertyExtractor({}, FooComponent);
|
|
75
|
-
await analyzedMetadata.init();
|
|
76
|
-
const application = getApplication({
|
|
77
|
-
storyFnAngular: { props },
|
|
78
|
-
component: FooComponent,
|
|
79
|
-
targetSelector: 'my-selector',
|
|
80
|
-
analyzedMetadata,
|
|
81
|
-
});
|
|
82
|
-
const { fixture } = await configureTestingModule({
|
|
83
|
-
imports: [application],
|
|
84
|
-
providers: [storyPropsProvider(new BehaviorSubject(props))],
|
|
85
|
-
});
|
|
86
|
-
fixture.detectChanges();
|
|
87
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(props.input);
|
|
88
|
-
expect(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual(props.inputBindingPropertyName);
|
|
89
|
-
expect(fixture.nativeElement.querySelector('p#localProperty').innerHTML).toEqual(props.localProperty);
|
|
90
|
-
expect(fixture.nativeElement.querySelector('p#localFunction').innerHTML).toEqual(props.localFunction());
|
|
91
|
-
});
|
|
92
|
-
it('should initialize outputs', async () => {
|
|
93
|
-
let expectedOutputValue;
|
|
94
|
-
let expectedOutputBindingValue;
|
|
95
|
-
const props = {
|
|
96
|
-
output: (value) => {
|
|
97
|
-
expectedOutputValue = value;
|
|
98
|
-
},
|
|
99
|
-
outputBindingPropertyName: (value) => {
|
|
100
|
-
expectedOutputBindingValue = value;
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
const analyzedMetadata = new PropertyExtractor({}, FooComponent);
|
|
104
|
-
await analyzedMetadata.init();
|
|
105
|
-
const application = getApplication({
|
|
106
|
-
storyFnAngular: { props },
|
|
107
|
-
component: FooComponent,
|
|
108
|
-
targetSelector: 'my-selector',
|
|
109
|
-
analyzedMetadata,
|
|
110
|
-
});
|
|
111
|
-
const { fixture } = await configureTestingModule({
|
|
112
|
-
imports: [application],
|
|
113
|
-
providers: [storyPropsProvider(new BehaviorSubject(props))],
|
|
114
|
-
});
|
|
115
|
-
fixture.detectChanges();
|
|
116
|
-
fixture.nativeElement.querySelector('p#output').click();
|
|
117
|
-
fixture.nativeElement.querySelector('p#outputBindingPropertyName').click();
|
|
118
|
-
expect(expectedOutputValue).toEqual('outputEmitted');
|
|
119
|
-
expect(expectedOutputBindingValue).toEqual('outputEmitted');
|
|
120
|
-
});
|
|
121
|
-
it('should change inputs if storyProps$ Subject emit', async () => {
|
|
122
|
-
const initialProps = {
|
|
123
|
-
input: 'input',
|
|
124
|
-
inputBindingPropertyName: '',
|
|
125
|
-
};
|
|
126
|
-
const storyProps$ = new BehaviorSubject(initialProps);
|
|
127
|
-
const analyzedMetadata = new PropertyExtractor({}, FooComponent);
|
|
128
|
-
await analyzedMetadata.init();
|
|
129
|
-
const application = getApplication({
|
|
130
|
-
storyFnAngular: { props: initialProps },
|
|
131
|
-
component: FooComponent,
|
|
132
|
-
targetSelector: 'my-selector',
|
|
133
|
-
analyzedMetadata,
|
|
134
|
-
});
|
|
135
|
-
const { fixture } = await configureTestingModule({
|
|
136
|
-
imports: [application],
|
|
137
|
-
providers: [storyPropsProvider(storyProps$)],
|
|
138
|
-
});
|
|
139
|
-
fixture.detectChanges();
|
|
140
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(initialProps.input);
|
|
141
|
-
expect(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual('');
|
|
142
|
-
const newProps = {
|
|
143
|
-
input: 'new input',
|
|
144
|
-
inputBindingPropertyName: 'new inputBindingPropertyName',
|
|
145
|
-
localProperty: 'new localProperty',
|
|
146
|
-
localFunction: () => 'new localFunction',
|
|
147
|
-
};
|
|
148
|
-
storyProps$.next(newProps);
|
|
149
|
-
fixture.detectChanges();
|
|
150
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(newProps.input);
|
|
151
|
-
expect(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual(newProps.inputBindingPropertyName);
|
|
152
|
-
expect(fixture.nativeElement.querySelector('p#localProperty').innerHTML).toEqual(newProps.localProperty);
|
|
153
|
-
expect(fixture.nativeElement.querySelector('p#localFunction').innerHTML).toEqual(newProps.localFunction());
|
|
154
|
-
});
|
|
155
|
-
it('should override outputs if storyProps$ Subject emit', async () => {
|
|
156
|
-
let expectedOutputValue;
|
|
157
|
-
let expectedOutputBindingValue;
|
|
158
|
-
const initialProps = {
|
|
159
|
-
input: '',
|
|
160
|
-
output: (value) => {
|
|
161
|
-
expectedOutputValue = value;
|
|
162
|
-
},
|
|
163
|
-
outputBindingPropertyName: (value) => {
|
|
164
|
-
expectedOutputBindingValue = value;
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
const storyProps$ = new BehaviorSubject(initialProps);
|
|
168
|
-
const analyzedMetadata = new PropertyExtractor({}, FooComponent);
|
|
169
|
-
await analyzedMetadata.init();
|
|
170
|
-
const application = getApplication({
|
|
171
|
-
storyFnAngular: { props: initialProps },
|
|
172
|
-
component: FooComponent,
|
|
173
|
-
targetSelector: 'my-selector',
|
|
174
|
-
analyzedMetadata,
|
|
175
|
-
});
|
|
176
|
-
const { fixture } = await configureTestingModule({
|
|
177
|
-
imports: [application],
|
|
178
|
-
providers: [storyPropsProvider(storyProps$)],
|
|
179
|
-
});
|
|
180
|
-
fixture.detectChanges();
|
|
181
|
-
const newProps = {
|
|
182
|
-
input: 'new input',
|
|
183
|
-
output: () => {
|
|
184
|
-
expectedOutputValue = 'should be called';
|
|
185
|
-
},
|
|
186
|
-
outputBindingPropertyName: () => {
|
|
187
|
-
expectedOutputBindingValue = 'should be called';
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
storyProps$.next(newProps);
|
|
191
|
-
fixture.detectChanges();
|
|
192
|
-
fixture.nativeElement.querySelector('p#output').click();
|
|
193
|
-
fixture.nativeElement.querySelector('p#outputBindingPropertyName').click();
|
|
194
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(newProps.input);
|
|
195
|
-
expect(expectedOutputValue).toEqual('should be called');
|
|
196
|
-
expect(expectedOutputBindingValue).toEqual('should be called');
|
|
197
|
-
});
|
|
198
|
-
it('should change template inputs if storyProps$ Subject emit', async () => {
|
|
199
|
-
const initialProps = {
|
|
200
|
-
color: 'red',
|
|
201
|
-
input: 'input',
|
|
202
|
-
};
|
|
203
|
-
const storyProps$ = new BehaviorSubject(initialProps);
|
|
204
|
-
const analyzedMetadata = new PropertyExtractor({}, FooComponent);
|
|
205
|
-
await analyzedMetadata.init();
|
|
206
|
-
const application = getApplication({
|
|
207
|
-
storyFnAngular: {
|
|
208
|
-
props: initialProps,
|
|
209
|
-
template: '<p [style.color]="color"><foo [input]="input"></foo></p>',
|
|
210
|
-
},
|
|
211
|
-
component: FooComponent,
|
|
212
|
-
targetSelector: 'my-selector',
|
|
213
|
-
analyzedMetadata,
|
|
214
|
-
});
|
|
215
|
-
const { fixture } = await configureTestingModule({
|
|
216
|
-
imports: [application],
|
|
217
|
-
providers: [storyPropsProvider(storyProps$)],
|
|
218
|
-
});
|
|
219
|
-
fixture.detectChanges();
|
|
220
|
-
expect(fixture.nativeElement.querySelector('p').style.color).toEqual('red');
|
|
221
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(initialProps.input);
|
|
222
|
-
const newProps = {
|
|
223
|
-
color: 'black',
|
|
224
|
-
input: 'new input',
|
|
225
|
-
};
|
|
226
|
-
storyProps$.next(newProps);
|
|
227
|
-
fixture.detectChanges();
|
|
228
|
-
expect(fixture.nativeElement.querySelector('p').style.color).toEqual('black');
|
|
229
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(newProps.input);
|
|
230
|
-
});
|
|
231
|
-
it('should call the Input() setter the right number of times', async () => {
|
|
232
|
-
const initialProps = {
|
|
233
|
-
setter: 'init',
|
|
234
|
-
};
|
|
235
|
-
const storyProps$ = new BehaviorSubject(initialProps);
|
|
236
|
-
const analyzedMetadata = new PropertyExtractor({}, FooComponent);
|
|
237
|
-
await analyzedMetadata.init();
|
|
238
|
-
const application = getApplication({
|
|
239
|
-
storyFnAngular: { props: initialProps },
|
|
240
|
-
component: FooComponent,
|
|
241
|
-
targetSelector: 'my-selector',
|
|
242
|
-
analyzedMetadata,
|
|
243
|
-
});
|
|
244
|
-
const { fixture } = await configureTestingModule({
|
|
245
|
-
imports: [application],
|
|
246
|
-
providers: [storyPropsProvider(storyProps$)],
|
|
247
|
-
});
|
|
248
|
-
fixture.detectChanges();
|
|
249
|
-
expect(fixture.nativeElement.querySelector('p#setterCallNb').innerHTML).toEqual('1');
|
|
250
|
-
const newProps = {
|
|
251
|
-
setter: 'new setter value',
|
|
252
|
-
};
|
|
253
|
-
storyProps$.next(newProps);
|
|
254
|
-
fixture.detectChanges();
|
|
255
|
-
expect(fixture.nativeElement.querySelector('p#setterCallNb').innerHTML).toEqual('2');
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
describe('with component without selector', () => {
|
|
259
|
-
let WithoutSelectorComponent = class WithoutSelectorComponent {
|
|
260
|
-
};
|
|
261
|
-
WithoutSelectorComponent = __decorate([
|
|
262
|
-
Component({
|
|
263
|
-
template: `The content`,
|
|
264
|
-
})
|
|
265
|
-
], WithoutSelectorComponent);
|
|
266
|
-
it('should display the component', async () => {
|
|
267
|
-
const props = {};
|
|
268
|
-
const analyzedMetadata = new PropertyExtractor({ entryComponents: [WithoutSelectorComponent] }, WithoutSelectorComponent);
|
|
269
|
-
await analyzedMetadata.init();
|
|
270
|
-
const application = getApplication({
|
|
271
|
-
storyFnAngular: {
|
|
272
|
-
props,
|
|
273
|
-
moduleMetadata: { entryComponents: [WithoutSelectorComponent] },
|
|
274
|
-
},
|
|
275
|
-
component: WithoutSelectorComponent,
|
|
276
|
-
targetSelector: 'my-selector',
|
|
277
|
-
analyzedMetadata,
|
|
278
|
-
});
|
|
279
|
-
const { fixture } = await configureTestingModule({
|
|
280
|
-
imports: [application],
|
|
281
|
-
providers: [storyPropsProvider(new BehaviorSubject(props))],
|
|
282
|
-
});
|
|
283
|
-
fixture.detectChanges();
|
|
284
|
-
expect(fixture.nativeElement.innerHTML).toContain('The content');
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
it('should keep template with an empty value', async () => {
|
|
288
|
-
let FooComponent = class FooComponent {
|
|
289
|
-
};
|
|
290
|
-
FooComponent = __decorate([
|
|
291
|
-
Component({
|
|
292
|
-
selector: 'foo',
|
|
293
|
-
template: `Should not be displayed`,
|
|
294
|
-
})
|
|
295
|
-
], FooComponent);
|
|
296
|
-
const analyzedMetadata = new PropertyExtractor({}, FooComponent);
|
|
297
|
-
await analyzedMetadata.init();
|
|
298
|
-
const application = getApplication({
|
|
299
|
-
storyFnAngular: { template: '' },
|
|
300
|
-
component: FooComponent,
|
|
301
|
-
targetSelector: 'my-selector',
|
|
302
|
-
analyzedMetadata,
|
|
303
|
-
});
|
|
304
|
-
const { fixture } = await configureTestingModule({
|
|
305
|
-
imports: [application],
|
|
306
|
-
providers: [storyPropsProvider(new BehaviorSubject({}))],
|
|
307
|
-
});
|
|
308
|
-
fixture.detectChanges();
|
|
309
|
-
expect(fixture.nativeElement.innerHTML).toEqual('');
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
async function configureTestingModule(ngModule) {
|
|
313
|
-
await TestBed.configureTestingModule(ngModule).compileComponents();
|
|
314
|
-
const fixture = TestBed.createComponent(ngModule.imports[0]);
|
|
315
|
-
return {
|
|
316
|
-
fixture,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { InjectionToken, Provider } from '@angular/core';
|
|
2
|
-
import { Subject } from 'rxjs';
|
|
3
|
-
import { ICollection } from '../types';
|
|
4
|
-
export declare const STORY_PROPS: InjectionToken<Subject<ICollection | undefined>>;
|
|
5
|
-
export declare const storyPropsProvider: (storyProps$: Subject<ICollection | undefined>) => Provider;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.storyPropsProvider = exports.STORY_PROPS = void 0;
|
|
4
|
-
const core_1 = require("@angular/core");
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
6
|
-
exports.STORY_PROPS = new core_1.InjectionToken('STORY_PROPS');
|
|
7
|
-
const storyPropsProvider = (storyProps$) => ({
|
|
8
|
-
provide: exports.STORY_PROPS,
|
|
9
|
-
useFactory: storyDataFactory(storyProps$.asObservable()),
|
|
10
|
-
deps: [core_1.NgZone],
|
|
11
|
-
});
|
|
12
|
-
exports.storyPropsProvider = storyPropsProvider;
|
|
13
|
-
function storyDataFactory(data) {
|
|
14
|
-
return (ngZone) => new rxjs_1.Observable((subscriber) => {
|
|
15
|
-
const sub = data.subscribe((v) => {
|
|
16
|
-
ngZone.run(() => subscriber.next(v));
|
|
17
|
-
}, (err) => {
|
|
18
|
-
ngZone.run(() => subscriber.error(err));
|
|
19
|
-
}, () => {
|
|
20
|
-
ngZone.run(() => subscriber.complete());
|
|
21
|
-
});
|
|
22
|
-
return () => {
|
|
23
|
-
sub.unsubscribe();
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { InjectionToken, NgZone } from '@angular/core';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
export const STORY_PROPS = new InjectionToken('STORY_PROPS');
|
|
4
|
-
export const storyPropsProvider = (storyProps$) => ({
|
|
5
|
-
provide: STORY_PROPS,
|
|
6
|
-
useFactory: storyDataFactory(storyProps$.asObservable()),
|
|
7
|
-
deps: [NgZone],
|
|
8
|
-
});
|
|
9
|
-
function storyDataFactory(data) {
|
|
10
|
-
return (ngZone) => new Observable((subscriber) => {
|
|
11
|
-
const sub = data.subscribe((v) => {
|
|
12
|
-
ngZone.run(() => subscriber.next(v));
|
|
13
|
-
}, (err) => {
|
|
14
|
-
ngZone.run(() => subscriber.error(err));
|
|
15
|
-
}, () => {
|
|
16
|
-
ngZone.run(() => subscriber.complete());
|
|
17
|
-
});
|
|
18
|
-
return () => {
|
|
19
|
-
sub.unsubscribe();
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Type } from '@angular/core';
|
|
2
|
-
import { ICollection, NgModuleMetadata } from '../types';
|
|
3
|
-
import { PropertyExtractor } from './utils/PropertyExtractor';
|
|
4
|
-
/** Wraps the story template into a component */
|
|
5
|
-
export declare const createStorybookWrapperComponent: ({ selector, template, storyComponent, styles, moduleMetadata, initialProps, analyzedMetadata, }: {
|
|
6
|
-
selector: string;
|
|
7
|
-
template: string;
|
|
8
|
-
storyComponent: Type<unknown> | undefined;
|
|
9
|
-
styles: string[];
|
|
10
|
-
moduleMetadata: NgModuleMetadata;
|
|
11
|
-
initialProps?: ICollection;
|
|
12
|
-
analyzedMetadata: PropertyExtractor;
|
|
13
|
-
}) => Type<any>;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.createStorybookWrapperComponent = void 0;
|
|
16
|
-
const core_1 = require("@angular/core");
|
|
17
|
-
const rxjs_1 = require("rxjs");
|
|
18
|
-
const operators_1 = require("rxjs/operators");
|
|
19
|
-
const StorybookProvider_1 = require("./StorybookProvider");
|
|
20
|
-
const NgComponentAnalyzer_1 = require("./utils/NgComponentAnalyzer");
|
|
21
|
-
const PropertyExtractor_1 = require("./utils/PropertyExtractor");
|
|
22
|
-
const getNonInputsOutputsProps = (ngComponentInputsOutputs, props = {}) => {
|
|
23
|
-
const inputs = ngComponentInputsOutputs.inputs
|
|
24
|
-
.filter((i) => i.templateName in props)
|
|
25
|
-
.map((i) => i.templateName);
|
|
26
|
-
const outputs = ngComponentInputsOutputs.outputs
|
|
27
|
-
.filter((o) => o.templateName in props)
|
|
28
|
-
.map((o) => o.templateName);
|
|
29
|
-
return Object.keys(props).filter((k) => ![...inputs, ...outputs].includes(k));
|
|
30
|
-
};
|
|
31
|
-
/** Wraps the story template into a component */
|
|
32
|
-
const createStorybookWrapperComponent = ({ selector, template, storyComponent, styles, moduleMetadata, initialProps, analyzedMetadata, }) => {
|
|
33
|
-
// In ivy, a '' selector is not allowed, therefore we need to just set it to anything if
|
|
34
|
-
// storyComponent was not provided.
|
|
35
|
-
const viewChildSelector = storyComponent ?? '__storybook-noop';
|
|
36
|
-
const { imports, declarations, providers } = analyzedMetadata;
|
|
37
|
-
let StorybookComponentModule = class StorybookComponentModule {
|
|
38
|
-
};
|
|
39
|
-
StorybookComponentModule = __decorate([
|
|
40
|
-
(0, core_1.NgModule)({
|
|
41
|
-
declarations,
|
|
42
|
-
imports,
|
|
43
|
-
exports: [...declarations, ...imports],
|
|
44
|
-
})
|
|
45
|
-
], StorybookComponentModule);
|
|
46
|
-
PropertyExtractor_1.PropertyExtractor.warnImportsModuleWithProviders(analyzedMetadata);
|
|
47
|
-
let StorybookWrapperComponent = class StorybookWrapperComponent {
|
|
48
|
-
constructor(storyProps$, changeDetectorRef) {
|
|
49
|
-
this.storyProps$ = storyProps$;
|
|
50
|
-
this.changeDetectorRef = changeDetectorRef;
|
|
51
|
-
// Used in case of a component without selector
|
|
52
|
-
this.storyComponent = storyComponent ?? '';
|
|
53
|
-
}
|
|
54
|
-
ngOnInit() {
|
|
55
|
-
// Subscribes to the observable storyProps$ to keep these properties up to date
|
|
56
|
-
this.storyWrapperPropsSubscription = this.storyProps$.subscribe((storyProps = {}) => {
|
|
57
|
-
// All props are added as component properties
|
|
58
|
-
Object.assign(this, storyProps);
|
|
59
|
-
this.changeDetectorRef.detectChanges();
|
|
60
|
-
this.changeDetectorRef.markForCheck();
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
ngAfterViewInit() {
|
|
64
|
-
// Bind properties to component, if the story have component
|
|
65
|
-
if (this.storyComponentElementRef) {
|
|
66
|
-
const ngComponentInputsOutputs = (0, NgComponentAnalyzer_1.getComponentInputsOutputs)(storyComponent);
|
|
67
|
-
const initialOtherProps = getNonInputsOutputsProps(ngComponentInputsOutputs, initialProps);
|
|
68
|
-
// Initializes properties that are not Inputs | Outputs
|
|
69
|
-
// Allows story props to override local component properties
|
|
70
|
-
initialOtherProps.forEach((p) => {
|
|
71
|
-
this.storyComponentElementRef[p] = initialProps[p];
|
|
72
|
-
});
|
|
73
|
-
// `markForCheck` the component in case this uses changeDetection: OnPush
|
|
74
|
-
// And then forces the `detectChanges`
|
|
75
|
-
this.storyComponentViewContainerRef.injector.get(core_1.ChangeDetectorRef).markForCheck();
|
|
76
|
-
this.changeDetectorRef.detectChanges();
|
|
77
|
-
// Once target component has been initialized, the storyProps$ observable keeps target component properties than are not Input|Output up to date
|
|
78
|
-
this.storyComponentPropsSubscription = this.storyProps$
|
|
79
|
-
.pipe((0, operators_1.skip)(1), (0, operators_1.map)((props) => {
|
|
80
|
-
const propsKeyToKeep = getNonInputsOutputsProps(ngComponentInputsOutputs, props);
|
|
81
|
-
return propsKeyToKeep.reduce((acc, p) => ({ ...acc, [p]: props[p] }), {});
|
|
82
|
-
}))
|
|
83
|
-
.subscribe((props) => {
|
|
84
|
-
// Replace inputs with new ones from props
|
|
85
|
-
Object.assign(this.storyComponentElementRef, props);
|
|
86
|
-
// `markForCheck` the component in case this uses changeDetection: OnPush
|
|
87
|
-
// And then forces the `detectChanges`
|
|
88
|
-
this.storyComponentViewContainerRef.injector.get(core_1.ChangeDetectorRef).markForCheck();
|
|
89
|
-
this.changeDetectorRef.detectChanges();
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
ngOnDestroy() {
|
|
94
|
-
if (this.storyComponentPropsSubscription != null) {
|
|
95
|
-
this.storyComponentPropsSubscription.unsubscribe();
|
|
96
|
-
}
|
|
97
|
-
if (this.storyWrapperPropsSubscription != null) {
|
|
98
|
-
this.storyWrapperPropsSubscription.unsubscribe();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
__decorate([
|
|
103
|
-
(0, core_1.ViewChild)(viewChildSelector, { static: true }),
|
|
104
|
-
__metadata("design:type", core_1.ElementRef)
|
|
105
|
-
], StorybookWrapperComponent.prototype, "storyComponentElementRef", void 0);
|
|
106
|
-
__decorate([
|
|
107
|
-
(0, core_1.ViewChild)(viewChildSelector, { read: core_1.ViewContainerRef, static: true }),
|
|
108
|
-
__metadata("design:type", core_1.ViewContainerRef)
|
|
109
|
-
], StorybookWrapperComponent.prototype, "storyComponentViewContainerRef", void 0);
|
|
110
|
-
StorybookWrapperComponent = __decorate([
|
|
111
|
-
(0, core_1.Component)({
|
|
112
|
-
selector,
|
|
113
|
-
template,
|
|
114
|
-
standalone: true,
|
|
115
|
-
imports: [StorybookComponentModule],
|
|
116
|
-
providers,
|
|
117
|
-
styles,
|
|
118
|
-
schemas: moduleMetadata.schemas,
|
|
119
|
-
}),
|
|
120
|
-
__param(0, (0, core_1.Inject)(StorybookProvider_1.STORY_PROPS)),
|
|
121
|
-
__param(1, (0, core_1.Inject)(core_1.ChangeDetectorRef)),
|
|
122
|
-
__metadata("design:paramtypes", [rxjs_1.Subject,
|
|
123
|
-
core_1.ChangeDetectorRef])
|
|
124
|
-
], StorybookWrapperComponent);
|
|
125
|
-
return StorybookWrapperComponent;
|
|
126
|
-
};
|
|
127
|
-
exports.createStorybookWrapperComponent = createStorybookWrapperComponent;
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { ChangeDetectorRef, Component, ElementRef, Inject, NgModule, ViewChild, ViewContainerRef, } from '@angular/core';
|
|
14
|
-
import { Subject } from 'rxjs';
|
|
15
|
-
import { map, skip } from 'rxjs/operators';
|
|
16
|
-
import { STORY_PROPS } from './StorybookProvider';
|
|
17
|
-
import { getComponentInputsOutputs } from './utils/NgComponentAnalyzer';
|
|
18
|
-
import { PropertyExtractor } from './utils/PropertyExtractor';
|
|
19
|
-
const getNonInputsOutputsProps = (ngComponentInputsOutputs, props = {}) => {
|
|
20
|
-
const inputs = ngComponentInputsOutputs.inputs
|
|
21
|
-
.filter((i) => i.templateName in props)
|
|
22
|
-
.map((i) => i.templateName);
|
|
23
|
-
const outputs = ngComponentInputsOutputs.outputs
|
|
24
|
-
.filter((o) => o.templateName in props)
|
|
25
|
-
.map((o) => o.templateName);
|
|
26
|
-
return Object.keys(props).filter((k) => ![...inputs, ...outputs].includes(k));
|
|
27
|
-
};
|
|
28
|
-
/** Wraps the story template into a component */
|
|
29
|
-
export const createStorybookWrapperComponent = ({ selector, template, storyComponent, styles, moduleMetadata, initialProps, analyzedMetadata, }) => {
|
|
30
|
-
// In ivy, a '' selector is not allowed, therefore we need to just set it to anything if
|
|
31
|
-
// storyComponent was not provided.
|
|
32
|
-
const viewChildSelector = storyComponent ?? '__storybook-noop';
|
|
33
|
-
const { imports, declarations, providers } = analyzedMetadata;
|
|
34
|
-
let StorybookComponentModule = class StorybookComponentModule {
|
|
35
|
-
};
|
|
36
|
-
StorybookComponentModule = __decorate([
|
|
37
|
-
NgModule({
|
|
38
|
-
declarations,
|
|
39
|
-
imports,
|
|
40
|
-
exports: [...declarations, ...imports],
|
|
41
|
-
})
|
|
42
|
-
], StorybookComponentModule);
|
|
43
|
-
PropertyExtractor.warnImportsModuleWithProviders(analyzedMetadata);
|
|
44
|
-
let StorybookWrapperComponent = class StorybookWrapperComponent {
|
|
45
|
-
constructor(storyProps$, changeDetectorRef) {
|
|
46
|
-
this.storyProps$ = storyProps$;
|
|
47
|
-
this.changeDetectorRef = changeDetectorRef;
|
|
48
|
-
// Used in case of a component without selector
|
|
49
|
-
this.storyComponent = storyComponent ?? '';
|
|
50
|
-
}
|
|
51
|
-
ngOnInit() {
|
|
52
|
-
// Subscribes to the observable storyProps$ to keep these properties up to date
|
|
53
|
-
this.storyWrapperPropsSubscription = this.storyProps$.subscribe((storyProps = {}) => {
|
|
54
|
-
// All props are added as component properties
|
|
55
|
-
Object.assign(this, storyProps);
|
|
56
|
-
this.changeDetectorRef.detectChanges();
|
|
57
|
-
this.changeDetectorRef.markForCheck();
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
ngAfterViewInit() {
|
|
61
|
-
// Bind properties to component, if the story have component
|
|
62
|
-
if (this.storyComponentElementRef) {
|
|
63
|
-
const ngComponentInputsOutputs = getComponentInputsOutputs(storyComponent);
|
|
64
|
-
const initialOtherProps = getNonInputsOutputsProps(ngComponentInputsOutputs, initialProps);
|
|
65
|
-
// Initializes properties that are not Inputs | Outputs
|
|
66
|
-
// Allows story props to override local component properties
|
|
67
|
-
initialOtherProps.forEach((p) => {
|
|
68
|
-
this.storyComponentElementRef[p] = initialProps[p];
|
|
69
|
-
});
|
|
70
|
-
// `markForCheck` the component in case this uses changeDetection: OnPush
|
|
71
|
-
// And then forces the `detectChanges`
|
|
72
|
-
this.storyComponentViewContainerRef.injector.get(ChangeDetectorRef).markForCheck();
|
|
73
|
-
this.changeDetectorRef.detectChanges();
|
|
74
|
-
// Once target component has been initialized, the storyProps$ observable keeps target component properties than are not Input|Output up to date
|
|
75
|
-
this.storyComponentPropsSubscription = this.storyProps$
|
|
76
|
-
.pipe(skip(1), map((props) => {
|
|
77
|
-
const propsKeyToKeep = getNonInputsOutputsProps(ngComponentInputsOutputs, props);
|
|
78
|
-
return propsKeyToKeep.reduce((acc, p) => ({ ...acc, [p]: props[p] }), {});
|
|
79
|
-
}))
|
|
80
|
-
.subscribe((props) => {
|
|
81
|
-
// Replace inputs with new ones from props
|
|
82
|
-
Object.assign(this.storyComponentElementRef, props);
|
|
83
|
-
// `markForCheck` the component in case this uses changeDetection: OnPush
|
|
84
|
-
// And then forces the `detectChanges`
|
|
85
|
-
this.storyComponentViewContainerRef.injector.get(ChangeDetectorRef).markForCheck();
|
|
86
|
-
this.changeDetectorRef.detectChanges();
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
ngOnDestroy() {
|
|
91
|
-
if (this.storyComponentPropsSubscription != null) {
|
|
92
|
-
this.storyComponentPropsSubscription.unsubscribe();
|
|
93
|
-
}
|
|
94
|
-
if (this.storyWrapperPropsSubscription != null) {
|
|
95
|
-
this.storyWrapperPropsSubscription.unsubscribe();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
__decorate([
|
|
100
|
-
ViewChild(viewChildSelector, { static: true }),
|
|
101
|
-
__metadata("design:type", ElementRef)
|
|
102
|
-
], StorybookWrapperComponent.prototype, "storyComponentElementRef", void 0);
|
|
103
|
-
__decorate([
|
|
104
|
-
ViewChild(viewChildSelector, { read: ViewContainerRef, static: true }),
|
|
105
|
-
__metadata("design:type", ViewContainerRef)
|
|
106
|
-
], StorybookWrapperComponent.prototype, "storyComponentViewContainerRef", void 0);
|
|
107
|
-
StorybookWrapperComponent = __decorate([
|
|
108
|
-
Component({
|
|
109
|
-
selector,
|
|
110
|
-
template,
|
|
111
|
-
standalone: true,
|
|
112
|
-
imports: [StorybookComponentModule],
|
|
113
|
-
providers,
|
|
114
|
-
styles,
|
|
115
|
-
schemas: moduleMetadata.schemas,
|
|
116
|
-
}),
|
|
117
|
-
__param(0, Inject(STORY_PROPS)),
|
|
118
|
-
__param(1, Inject(ChangeDetectorRef)),
|
|
119
|
-
__metadata("design:paramtypes", [Subject,
|
|
120
|
-
ChangeDetectorRef])
|
|
121
|
-
], StorybookWrapperComponent);
|
|
122
|
-
return StorybookWrapperComponent;
|
|
123
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from '@angular/core';
|
|
2
|
-
export declare const exportedConstant = "An exported constant";
|
|
3
|
-
export declare enum ButtonAccent {
|
|
4
|
-
'Normal' = "Normal",
|
|
5
|
-
'High' = "High"
|
|
6
|
-
}
|
|
7
|
-
export interface ISomeInterface {
|
|
8
|
-
one: string;
|
|
9
|
-
two: boolean;
|
|
10
|
-
three: any[];
|
|
11
|
-
ref?: ISomeInterface;
|
|
12
|
-
}
|
|
13
|
-
export declare class InputComponent<T> {
|
|
14
|
-
/** Appearance style of the button. */
|
|
15
|
-
appearance: 'primary' | 'secondary';
|
|
16
|
-
counter: number;
|
|
17
|
-
/** Specify the accent-type of the button */
|
|
18
|
-
accent: ButtonAccent;
|
|
19
|
-
/** To test source-generation with overridden propertyname */
|
|
20
|
-
foregroundColor: string;
|
|
21
|
-
/** Sets the button to a disabled state. */
|
|
22
|
-
isDisabled: boolean;
|
|
23
|
-
label: string;
|
|
24
|
-
ariaLabel: string;
|
|
25
|
-
/** Specifies some arbitrary object */
|
|
26
|
-
someDataObject: ISomeInterface;
|
|
27
|
-
onClick: EventEmitter<Event>;
|
|
28
|
-
dashOut: EventEmitter<any>;
|
|
29
|
-
}
|