@storybook/angular 0.0.0-pr-23609-sha-f47ef339
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/.eslintrc.js +8 -0
- package/README.md +322 -0
- package/dist/builders/build-storybook/index.js +72 -0
- package/dist/builders/build-storybook/index.spec.d.ts +1 -0
- package/dist/builders/build-storybook/index.spec.js +216 -0
- package/dist/builders/build-storybook/schema.json +167 -0
- package/dist/builders/builders.json +14 -0
- package/dist/builders/start-storybook/index.js +93 -0
- package/dist/builders/start-storybook/index.spec.d.ts +1 -0
- package/dist/builders/start-storybook/index.spec.js +215 -0
- package/dist/builders/start-storybook/schema.json +198 -0
- package/dist/builders/utils/error-handler.d.ts +2 -0
- package/dist/builders/utils/error-handler.js +38 -0
- package/dist/builders/utils/run-compodoc.d.ts +6 -0
- package/dist/builders/utils/run-compodoc.js +58 -0
- package/dist/builders/utils/run-compodoc.spec.d.ts +1 -0
- package/dist/builders/utils/run-compodoc.spec.js +86 -0
- package/dist/builders/utils/standalone-options.d.ts +15 -0
- package/dist/builders/utils/standalone-options.js +2 -0
- package/dist/client/angular-beta/AbstractRenderer.d.ts +53 -0
- package/dist/client/angular-beta/AbstractRenderer.js +180 -0
- package/dist/client/angular-beta/CanvasRenderer.d.ts +13 -0
- package/dist/client/angular-beta/CanvasRenderer.js +16 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.d.ts +17 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.js +132 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.d.ts +1 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.js +403 -0
- package/dist/client/angular-beta/DocsRenderer.d.ts +13 -0
- package/dist/client/angular-beta/DocsRenderer.js +40 -0
- package/dist/client/angular-beta/RendererFactory.d.ts +11 -0
- package/dist/client/angular-beta/RendererFactory.js +56 -0
- package/dist/client/angular-beta/RendererFactory.test.d.ts +1 -0
- package/dist/client/angular-beta/RendererFactory.test.js +164 -0
- package/dist/client/angular-beta/StorybookModule.d.ts +8 -0
- package/dist/client/angular-beta/StorybookModule.js +29 -0
- package/dist/client/angular-beta/StorybookModule.test.d.ts +1 -0
- package/dist/client/angular-beta/StorybookModule.test.js +311 -0
- package/dist/client/angular-beta/StorybookProvider.d.ts +5 -0
- package/dist/client/angular-beta/StorybookProvider.js +26 -0
- package/dist/client/angular-beta/StorybookWrapperComponent.d.ts +16 -0
- package/dist/client/angular-beta/StorybookWrapperComponent.js +140 -0
- package/dist/client/angular-beta/__testfixtures__/input.component.d.ts +26 -0
- package/dist/client/angular-beta/__testfixtures__/input.component.js +67 -0
- package/dist/client/angular-beta/__testfixtures__/test.module.d.ts +2 -0
- package/dist/client/angular-beta/__testfixtures__/test.module.js +20 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.d.ts +29 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.js +100 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.d.ts +1 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.js +374 -0
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.d.ts +6 -0
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.js +41 -0
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.d.ts +1 -0
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.js +23 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.d.ts +32 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.js +162 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.test.d.ts +1 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.test.js +142 -0
- package/dist/client/config.d.ts +6 -0
- package/dist/client/config.js +10 -0
- package/dist/client/decorateStory.d.ts +4 -0
- package/dist/client/decorateStory.js +49 -0
- package/dist/client/decorateStory.test.d.ts +1 -0
- package/dist/client/decorateStory.test.js +304 -0
- package/dist/client/decorators.d.ts +14 -0
- package/dist/client/decorators.js +70 -0
- package/dist/client/decorators.test.d.ts +1 -0
- package/dist/client/decorators.test.js +146 -0
- package/dist/client/docs/__testfixtures__/doc-button/input.d.ts +111 -0
- package/dist/client/docs/__testfixtures__/doc-button/input.js +207 -0
- package/dist/client/docs/__testfixtures__/doc-button/tsconfig.json +7 -0
- package/dist/client/docs/angular-properties.test.d.ts +1 -0
- package/dist/client/docs/angular-properties.test.js +62 -0
- package/dist/client/docs/compodoc.d.ts +12 -0
- package/dist/client/docs/compodoc.js +258 -0
- package/dist/client/docs/compodoc.test.d.ts +1 -0
- package/dist/client/docs/compodoc.test.js +131 -0
- package/dist/client/docs/config.d.ts +4 -0
- package/dist/client/docs/config.js +19 -0
- package/dist/client/docs/index.d.ts +1 -0
- package/dist/client/docs/index.js +17 -0
- package/dist/client/docs/sourceDecorator.d.ts +9 -0
- package/dist/client/docs/sourceDecorator.js +51 -0
- package/dist/client/docs/types.d.ts +102 -0
- package/dist/client/docs/types.js +2 -0
- package/dist/client/globals.d.ts +23 -0
- package/dist/client/globals.js +40 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +30 -0
- package/dist/client/preview-prod.d.ts +1 -0
- package/dist/client/preview-prod.js +4 -0
- package/dist/client/public-api.d.ts +15 -0
- package/dist/client/public-api.js +36 -0
- package/dist/client/public-types.d.ts +37 -0
- package/dist/client/public-types.js +2 -0
- package/dist/client/render.d.ts +7 -0
- package/dist/client/render.js +19 -0
- package/dist/client/types.d.ts +46 -0
- package/dist/client/types.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +29 -0
- package/dist/index.mjs +13 -0
- package/dist/preset.d.ts +6 -0
- package/dist/preset.js +36 -0
- package/dist/preset.mjs +30 -0
- package/dist/renderer.d.ts +6 -0
- package/dist/renderer.js +15 -0
- package/dist/renderer.mjs +6 -0
- package/dist/server/__mocks-ng-workspace__/empty-projects-entry/angular.json +4 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/angular.json +18 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/tsconfig.app.json +9 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/some-config/angular.json +19 -0
- package/dist/server/__mocks-ng-workspace__/some-config/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/some-config/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/some-config/src/tsconfig.app.json +9 -0
- package/dist/server/__mocks-ng-workspace__/some-config/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/angular.json +64 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/tsconfig.app.json +9 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/angular.json +28 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/tsconfig.lib.json +20 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/angular.json +18 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/nx.json +3 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/src/tsconfig.app.json +8 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/tsconfig.json +14 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/nx.json +3 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/tsconfig.app.json +8 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/tsconfig.json +14 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/workspace.json +18 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/angular.json +18 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/tsconfig.app.json +9 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/without-architect-build/angular.json +5 -0
- package/dist/server/__mocks-ng-workspace__/without-architect-build-options/angular.json +11 -0
- package/dist/server/__mocks-ng-workspace__/without-compatible-projects/angular.json +7 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/angular.json +3 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/tsconfig.lib.json +20 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/angular.json +16 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/tsconfig.app.json +9 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/tsconfig.json +13 -0
- package/dist/server/__tests__/angular.json +96 -0
- package/dist/server/angular-cli-webpack.d.ts +1 -0
- package/dist/server/angular-cli-webpack.js +99 -0
- package/dist/server/framework-preset-angular-cli.d.ts +4 -0
- package/dist/server/framework-preset-angular-cli.js +85 -0
- package/dist/server/framework-preset-angular-docs.d.ts +2 -0
- package/dist/server/framework-preset-angular-docs.js +10 -0
- package/dist/server/framework-preset-angular-ivy.d.ts +10 -0
- package/dist/server/framework-preset-angular-ivy.js +103 -0
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.d.ts +25 -0
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.js +48 -0
- package/dist/server/preset-options.d.ts +13 -0
- package/dist/server/preset-options.js +2 -0
- package/dist/server/utils/filter-out-styling-rules.d.ts +2 -0
- package/dist/server/utils/filter-out-styling-rules.js +17 -0
- package/dist/server/utils/module-is-available.d.ts +1 -0
- package/dist/server/utils/module-is-available.js +13 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.js +2 -0
- package/dist/types.mjs +1 -0
- package/jest.config.js +31 -0
- package/package.json +126 -0
- package/preset.js +1 -0
- package/renderer.d.ts +1 -0
- package/renderer.js +1 -0
- package/src/server/angular-cli-webpack.d.ts +7 -0
- package/src/server/angular-cli-webpack.js +127 -0
- package/src/server/plugins/storybook-normalize-angular-entry-plugin.js +54 -0
- package/src/typings.d.ts +21 -0
- package/template/cli/.eslintrc.json +5 -0
- package/template/cli/Button.stories.ts +51 -0
- package/template/cli/Header.stories.ts +37 -0
- package/template/cli/Page.stories.ts +46 -0
- package/template/cli/User.ts +2 -0
- package/template/cli/button.component.ts +55 -0
- package/template/cli/header.component.ts +75 -0
- package/template/cli/page.component.ts +77 -0
- package/template/components/button.component.ts +54 -0
- package/template/components/button.css +30 -0
- package/template/components/form.component.ts +37 -0
- package/template/components/html.component.ts +22 -0
- package/template/components/index.js +8 -0
- package/template/components/pre.component.ts +29 -0
- package/template/stories/angular-mdx.stories.mdx +25 -0
- package/template/stories/argTypes/doc-button/doc-button.component.html +7 -0
- package/template/stories/argTypes/doc-button/doc-button.component.scss +3 -0
- package/template/stories/argTypes/doc-button/doc-button.component.ts +232 -0
- package/template/stories/argTypes/doc-button/doc-button.stories.ts +24 -0
- package/template/stories/argTypes/doc-directive/doc-directive.directive.ts +24 -0
- package/template/stories/argTypes/doc-directive/doc-directive.stories.ts +14 -0
- package/template/stories/argTypes/doc-injectable/doc-injectable.service.ts +27 -0
- package/template/stories/argTypes/doc-injectable/doc-injectable.stories.ts +17 -0
- package/template/stories/argTypes/doc-pipe/doc-pipe.pipe.ts +18 -0
- package/template/stories/argTypes/doc-pipe/doc-pipe.stories.ts +17 -0
- package/template/stories/basics/README.stories.mdx +7 -0
- package/template/stories/basics/angular-forms/customControlValueAccessor/custom-cva-component.stories.ts +27 -0
- package/template/stories/basics/angular-forms/customControlValueAccessor/custom-cva.component.ts +57 -0
- package/template/stories/basics/component-with-complex-selectors/attribute-selector.component.ts +19 -0
- package/template/stories/basics/component-with-complex-selectors/attribute-selectors.component.stories.ts +8 -0
- package/template/stories/basics/component-with-complex-selectors/class-selector.component.stories.ts +8 -0
- package/template/stories/basics/component-with-complex-selectors/class-selector.component.ts +19 -0
- package/template/stories/basics/component-with-complex-selectors/multiple-class-selector.component.stories.ts +8 -0
- package/template/stories/basics/component-with-complex-selectors/multiple-selector.component.stories.ts +8 -0
- package/template/stories/basics/component-with-complex-selectors/multiple-selector.component.ts +37 -0
- package/template/stories/basics/component-with-enums/enums.component.html +8 -0
- package/template/stories/basics/component-with-enums/enums.component.stories.ts +24 -0
- package/template/stories/basics/component-with-enums/enums.component.ts +53 -0
- package/template/stories/basics/component-with-inheritance/base-button.component.ts +10 -0
- package/template/stories/basics/component-with-inheritance/base-button.stories.ts +12 -0
- package/template/stories/basics/component-with-inheritance/icon-button.component.ts +11 -0
- package/template/stories/basics/component-with-inheritance/icon-button.stories.ts +13 -0
- package/template/stories/basics/component-with-ng-content/ng-content-about-parent.stories.ts +58 -0
- package/template/stories/basics/component-with-ng-content/ng-content-simple.stories.ts +29 -0
- package/template/stories/basics/component-with-ng-on-destroy/component-with-on-destroy.stories.ts +40 -0
- package/template/stories/basics/component-with-on-push/on-push-box.component.ts +21 -0
- package/template/stories/basics/component-with-on-push/on-push.stories.ts +21 -0
- package/template/stories/basics/component-with-pipe/custom-pipes.stories.ts +31 -0
- package/template/stories/basics/component-with-pipe/custom.pipe.ts +10 -0
- package/template/stories/basics/component-with-pipe/with-pipe.component.ts +10 -0
- package/template/stories/basics/component-with-provider/di.component.html +7 -0
- package/template/stories/basics/component-with-provider/di.component.stories.ts +26 -0
- package/template/stories/basics/component-with-provider/di.component.ts +28 -0
- package/template/stories/basics/component-with-style/styled.component.css +3 -0
- package/template/stories/basics/component-with-style/styled.component.html +5 -0
- package/template/stories/basics/component-with-style/styled.component.scss +5 -0
- package/template/stories/basics/component-with-style/styled.component.stories.ts +10 -0
- package/template/stories/basics/component-with-style/styled.component.ts +8 -0
- package/template/stories/basics/component-without-selector/without-selector-ng-component-outlet.stories.ts +73 -0
- package/template/stories/basics/component-without-selector/without-selector-ng-factory-resolver.stories.ts +71 -0
- package/template/stories/basics/component-without-selector/without-selector.component.ts +30 -0
- package/template/stories/basics/component-without-selector/without-selector.stories.ts +30 -0
- package/template/stories/basics/ng-module/angular-src/chip-color.token.ts +3 -0
- package/template/stories/basics/ng-module/angular-src/chip-text.pipe.ts +29 -0
- package/template/stories/basics/ng-module/angular-src/chip.component.ts +60 -0
- package/template/stories/basics/ng-module/angular-src/chips-group.component.ts +49 -0
- package/template/stories/basics/ng-module/angular-src/chips.module.ts +31 -0
- package/template/stories/basics/ng-module/import-module-chip.stories.ts +23 -0
- package/template/stories/basics/ng-module/import-module-for-root.stories.ts +50 -0
- package/template/stories/basics/ng-module/import-module.stories.ts +35 -0
- package/template/stories/button.component.ts +26 -0
- package/template/stories/core/README.stories.mdx +7 -0
- package/template/stories/core/applicationConfig/with-browser-animations.stories.ts +40 -0
- package/template/stories/core/applicationConfig/with-noop-browser-animations.stories.ts +35 -0
- package/template/stories/core/decorators/componentWrapperDecorator/child.component.ts +20 -0
- package/template/stories/core/decorators/componentWrapperDecorator/decorators.stories.ts +99 -0
- package/template/stories/core/decorators/componentWrapperDecorator/parent.component.ts +18 -0
- package/template/stories/core/decorators/theme-decorator/decorators.stories.ts +20 -0
- package/template/stories/core/moduleMetadata/angular-src/custom.pipe.ts +10 -0
- package/template/stories/core/moduleMetadata/angular-src/dummy.service.ts +14 -0
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.css +13 -0
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.html +7 -0
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.ts +39 -0
- package/template/stories/core/moduleMetadata/angular-src/service.component.ts +24 -0
- package/template/stories/core/moduleMetadata/angular-src/token.component.ts +31 -0
- package/template/stories/core/moduleMetadata/in-export-default.stories.ts +38 -0
- package/template/stories/core/moduleMetadata/in-stories.stories.ts +46 -0
- package/template/stories/core/moduleMetadata/merge-default-and-story.stories.ts +35 -0
- package/template/stories/core/parameters/bootstrap-options.stories.ts +18 -0
- package/template/stories/core/styles/story-styles.stories.ts +50 -0
- package/template/stories/others/app-initializer-use-factory/app-initializer-use-factory.stories.ts +34 -0
- package/template/stories/others/issues/12009-unknown-component.stories.ts +14 -0
- package/template/stories/others/ngx-translate/README.stories.mdx +65 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("@angular/common");
|
|
4
|
+
const core_1 = require("@angular/core");
|
|
5
|
+
const platform_browser_1 = require("@angular/platform-browser");
|
|
6
|
+
const animations_1 = require("@angular/platform-browser/animations");
|
|
7
|
+
const PropertyExtractor_1 = require("./PropertyExtractor");
|
|
8
|
+
const test_module_1 = require("../__testfixtures__/test.module");
|
|
9
|
+
const TEST_TOKEN = new core_1.InjectionToken('testToken');
|
|
10
|
+
const TestTokenProvider = { provide: TEST_TOKEN, useValue: 123 };
|
|
11
|
+
const TestService = (0, core_1.Injectable)()(class {
|
|
12
|
+
});
|
|
13
|
+
const TestComponent1 = (0, core_1.Component)({})(class {
|
|
14
|
+
});
|
|
15
|
+
const TestComponent2 = (0, core_1.Component)({})(class {
|
|
16
|
+
});
|
|
17
|
+
const StandaloneTestComponent = (0, core_1.Component)({ standalone: true })(class {
|
|
18
|
+
});
|
|
19
|
+
const TestDirective = (0, core_1.Directive)({})(class {
|
|
20
|
+
});
|
|
21
|
+
const TestModuleWithDeclarations = (0, core_1.NgModule)({ declarations: [TestComponent1] })(class {
|
|
22
|
+
});
|
|
23
|
+
const TestModuleWithImportsAndProviders = (0, core_1.NgModule)({
|
|
24
|
+
imports: [TestModuleWithDeclarations],
|
|
25
|
+
providers: [TestTokenProvider],
|
|
26
|
+
})(class {
|
|
27
|
+
});
|
|
28
|
+
const analyzeMetadata = (metadata, component) => {
|
|
29
|
+
return new PropertyExtractor_1.PropertyExtractor(metadata, component);
|
|
30
|
+
};
|
|
31
|
+
const extractImports = (metadata, component) => {
|
|
32
|
+
const { imports } = new PropertyExtractor_1.PropertyExtractor(metadata, component);
|
|
33
|
+
return imports;
|
|
34
|
+
};
|
|
35
|
+
const extractDeclarations = (metadata, component) => {
|
|
36
|
+
const { declarations } = new PropertyExtractor_1.PropertyExtractor(metadata, component);
|
|
37
|
+
return declarations;
|
|
38
|
+
};
|
|
39
|
+
const extractProviders = (metadata, component) => {
|
|
40
|
+
const { providers } = new PropertyExtractor_1.PropertyExtractor(metadata, component);
|
|
41
|
+
return providers;
|
|
42
|
+
};
|
|
43
|
+
const extractApplicationProviders = (metadata, component) => {
|
|
44
|
+
const { applicationProviders } = new PropertyExtractor_1.PropertyExtractor(metadata, component);
|
|
45
|
+
return applicationProviders;
|
|
46
|
+
};
|
|
47
|
+
describe('PropertyExtractor', () => {
|
|
48
|
+
jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
49
|
+
describe('analyzeMetadata', () => {
|
|
50
|
+
it('should remove BrowserModule', () => {
|
|
51
|
+
const metadata = {
|
|
52
|
+
imports: [platform_browser_1.BrowserModule],
|
|
53
|
+
};
|
|
54
|
+
const { imports, providers, applicationProviders } = analyzeMetadata(metadata);
|
|
55
|
+
expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule]);
|
|
56
|
+
expect(providers.flat(Number.MAX_VALUE)).toEqual([]);
|
|
57
|
+
expect(applicationProviders.flat(Number.MAX_VALUE)).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
it('should remove BrowserAnimationsModule and use its providers instead', () => {
|
|
60
|
+
const metadata = {
|
|
61
|
+
imports: [animations_1.BrowserAnimationsModule],
|
|
62
|
+
};
|
|
63
|
+
const { imports, providers, applicationProviders } = analyzeMetadata(metadata);
|
|
64
|
+
expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule]);
|
|
65
|
+
expect(providers.flat(Number.MAX_VALUE)).toEqual([]);
|
|
66
|
+
expect(applicationProviders.flat(Number.MAX_VALUE)).toEqual((0, animations_1.provideAnimations)());
|
|
67
|
+
});
|
|
68
|
+
it('should remove NoopAnimationsModule and use its providers instead', () => {
|
|
69
|
+
const metadata = {
|
|
70
|
+
imports: [animations_1.NoopAnimationsModule],
|
|
71
|
+
};
|
|
72
|
+
const { imports, providers, applicationProviders } = analyzeMetadata(metadata);
|
|
73
|
+
expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule]);
|
|
74
|
+
expect(providers.flat(Number.MAX_VALUE)).toEqual([]);
|
|
75
|
+
expect(applicationProviders.flat(Number.MAX_VALUE)).toEqual((0, animations_1.provideNoopAnimations)());
|
|
76
|
+
});
|
|
77
|
+
it('should remove Browser/Animations modules recursively', () => {
|
|
78
|
+
const metadata = {
|
|
79
|
+
imports: [animations_1.BrowserAnimationsModule, platform_browser_1.BrowserModule],
|
|
80
|
+
};
|
|
81
|
+
const { imports, providers, applicationProviders } = analyzeMetadata(metadata);
|
|
82
|
+
expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule]);
|
|
83
|
+
expect(providers.flat(Number.MAX_VALUE)).toEqual([]);
|
|
84
|
+
expect(applicationProviders.flat(Number.MAX_VALUE)).toEqual((0, animations_1.provideAnimations)());
|
|
85
|
+
});
|
|
86
|
+
it('should not destructure Angular official module', () => {
|
|
87
|
+
const metadata = {
|
|
88
|
+
imports: [test_module_1.WithOfficialModule],
|
|
89
|
+
};
|
|
90
|
+
const { imports, providers, applicationProviders } = analyzeMetadata(metadata);
|
|
91
|
+
expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule, test_module_1.WithOfficialModule]);
|
|
92
|
+
expect(providers.flat(Number.MAX_VALUE)).toEqual([]);
|
|
93
|
+
expect(applicationProviders.flat(Number.MAX_VALUE)).toEqual([]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('extractImports', () => {
|
|
97
|
+
it('should return Angular official modules', () => {
|
|
98
|
+
const imports = extractImports({ imports: [TestModuleWithImportsAndProviders] });
|
|
99
|
+
expect(imports).toEqual([common_1.CommonModule, TestModuleWithImportsAndProviders]);
|
|
100
|
+
});
|
|
101
|
+
it('should return standalone components', () => {
|
|
102
|
+
const imports = extractImports({
|
|
103
|
+
imports: [TestModuleWithImportsAndProviders],
|
|
104
|
+
}, StandaloneTestComponent);
|
|
105
|
+
expect(imports).toEqual([
|
|
106
|
+
common_1.CommonModule,
|
|
107
|
+
TestModuleWithImportsAndProviders,
|
|
108
|
+
StandaloneTestComponent,
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('extractDeclarations', () => {
|
|
113
|
+
it('should return an array of declarations that contains `storyComponent`', () => {
|
|
114
|
+
const declarations = extractDeclarations({ declarations: [TestComponent1] }, TestComponent2);
|
|
115
|
+
expect(declarations).toEqual([TestComponent1, TestComponent2]);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe('analyzeDecorators', () => {
|
|
119
|
+
it('isStandalone should be false', () => {
|
|
120
|
+
const { isStandalone } = PropertyExtractor_1.PropertyExtractor.analyzeDecorators(TestComponent1);
|
|
121
|
+
expect(isStandalone).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
it('isStandalone should be true', () => {
|
|
124
|
+
const { isStandalone } = PropertyExtractor_1.PropertyExtractor.analyzeDecorators(StandaloneTestComponent);
|
|
125
|
+
expect(isStandalone).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('extractProviders', () => {
|
|
129
|
+
it('should return an array of providers', () => {
|
|
130
|
+
const providers = extractProviders({
|
|
131
|
+
providers: [TestService],
|
|
132
|
+
});
|
|
133
|
+
expect(providers).toEqual([TestService]);
|
|
134
|
+
});
|
|
135
|
+
it('should return an array of singletons extracted', () => {
|
|
136
|
+
const singeltons = extractApplicationProviders({
|
|
137
|
+
imports: [animations_1.BrowserAnimationsModule],
|
|
138
|
+
});
|
|
139
|
+
expect(singeltons).toEqual((0, animations_1.provideAnimations)());
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parameters = exports.applyDecorators = exports.renderToCanvas = exports.render = void 0;
|
|
4
|
+
require("./globals");
|
|
5
|
+
var render_1 = require("./render");
|
|
6
|
+
Object.defineProperty(exports, "render", { enumerable: true, get: function () { return render_1.render; } });
|
|
7
|
+
Object.defineProperty(exports, "renderToCanvas", { enumerable: true, get: function () { return render_1.renderToCanvas; } });
|
|
8
|
+
var decorateStory_1 = require("./decorateStory");
|
|
9
|
+
Object.defineProperty(exports, "applyDecorators", { enumerable: true, get: function () { return decorateStory_1.decorateStory; } });
|
|
10
|
+
exports.parameters = { renderer: 'angular' };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DecoratorFunction, LegacyStoryFn } from '@storybook/types';
|
|
2
|
+
import { AngularRenderer } from './types';
|
|
3
|
+
export default function decorateStory(mainStoryFn: LegacyStoryFn<AngularRenderer>, decorators: DecoratorFunction<AngularRenderer>[]): LegacyStoryFn<AngularRenderer>;
|
|
4
|
+
export { decorateStory };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorateStory = void 0;
|
|
4
|
+
const preview_api_1 = require("@storybook/preview-api");
|
|
5
|
+
const ComputesTemplateFromComponent_1 = require("./angular-beta/ComputesTemplateFromComponent");
|
|
6
|
+
function decorateStory(mainStoryFn, decorators) {
|
|
7
|
+
const returnDecorators = [cleanArgsDecorator, ...decorators].reduce((previousStoryFn, decorator) => (context) => {
|
|
8
|
+
const decoratedStory = decorator((update) => {
|
|
9
|
+
return previousStoryFn({
|
|
10
|
+
...context,
|
|
11
|
+
...(0, preview_api_1.sanitizeStoryContextUpdate)(update),
|
|
12
|
+
});
|
|
13
|
+
}, context);
|
|
14
|
+
return decoratedStory;
|
|
15
|
+
}, (context) => prepareMain(mainStoryFn(context), context));
|
|
16
|
+
return returnDecorators;
|
|
17
|
+
}
|
|
18
|
+
exports.default = decorateStory;
|
|
19
|
+
exports.decorateStory = decorateStory;
|
|
20
|
+
const prepareMain = (story, context) => {
|
|
21
|
+
let { template } = story;
|
|
22
|
+
const { component } = context;
|
|
23
|
+
const userDefinedTemplate = !hasNoTemplate(template);
|
|
24
|
+
if (!userDefinedTemplate && component) {
|
|
25
|
+
template = (0, ComputesTemplateFromComponent_1.computesTemplateFromComponent)(component, story.props, '');
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
...story,
|
|
29
|
+
...(template ? { template, userDefinedTemplate } : {}),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
function hasNoTemplate(template) {
|
|
33
|
+
return template === null || template === undefined;
|
|
34
|
+
}
|
|
35
|
+
const cleanArgsDecorator = (storyFn, context) => {
|
|
36
|
+
if (!context.argTypes || !context.args) {
|
|
37
|
+
return storyFn();
|
|
38
|
+
}
|
|
39
|
+
const argsToClean = context.args;
|
|
40
|
+
context.args = Object.entries(argsToClean).reduce((obj, [key, arg]) => {
|
|
41
|
+
const argType = context.argTypes[key];
|
|
42
|
+
// Only keeps args with a control or an action in argTypes
|
|
43
|
+
if (argType?.action || argType?.control) {
|
|
44
|
+
return { ...obj, [key]: arg };
|
|
45
|
+
}
|
|
46
|
+
return obj;
|
|
47
|
+
}, {});
|
|
48
|
+
return storyFn();
|
|
49
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,304 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const core_1 = require("@angular/core");
|
|
16
|
+
const decorators_1 = require("./decorators");
|
|
17
|
+
const decorateStory_1 = __importDefault(require("./decorateStory"));
|
|
18
|
+
describe('decorateStory', () => {
|
|
19
|
+
describe('angular behavior', () => {
|
|
20
|
+
it('should use componentWrapperDecorator with args', () => {
|
|
21
|
+
const decorators = [
|
|
22
|
+
(0, decorators_1.componentWrapperDecorator)(ParentComponent, ({ args }) => args),
|
|
23
|
+
(0, decorators_1.componentWrapperDecorator)((story) => `<grandparent [grandparentInput]="grandparentInput">${story}</grandparent>`, ({ args }) => args),
|
|
24
|
+
(0, decorators_1.componentWrapperDecorator)((story) => `<great-grandparent>${story}</great-grandparent>`),
|
|
25
|
+
];
|
|
26
|
+
const decorated = (0, decorateStory_1.default)(() => ({ template: '</child>' }), decorators);
|
|
27
|
+
expect(decorated(makeContext({
|
|
28
|
+
component: FooComponent,
|
|
29
|
+
args: {
|
|
30
|
+
parentInput: 'Parent input',
|
|
31
|
+
grandparentInput: 'grandparent input',
|
|
32
|
+
parentOutput: () => { },
|
|
33
|
+
},
|
|
34
|
+
}))).toEqual({
|
|
35
|
+
props: {
|
|
36
|
+
parentInput: 'Parent input',
|
|
37
|
+
grandparentInput: 'grandparent input',
|
|
38
|
+
parentOutput: expect.any(Function),
|
|
39
|
+
},
|
|
40
|
+
template: '<great-grandparent><grandparent [grandparentInput]="grandparentInput"><parent [parentInput]="parentInput" (parentOutput)="parentOutput($event)"></child></parent></grandparent></great-grandparent>',
|
|
41
|
+
userDefinedTemplate: true,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it('should use componentWrapperDecorator with input / output', () => {
|
|
45
|
+
const decorators = [
|
|
46
|
+
(0, decorators_1.componentWrapperDecorator)(ParentComponent, {
|
|
47
|
+
parentInput: 'Parent input',
|
|
48
|
+
parentOutput: () => { },
|
|
49
|
+
}),
|
|
50
|
+
(0, decorators_1.componentWrapperDecorator)((story) => `<grandparent [grandparentInput]="grandparentInput">${story}</grandparent>`, {
|
|
51
|
+
grandparentInput: 'Grandparent input',
|
|
52
|
+
sameInput: 'Should be override by story props',
|
|
53
|
+
}),
|
|
54
|
+
(0, decorators_1.componentWrapperDecorator)((story) => `<great-grandparent>${story}</great-grandparent>`),
|
|
55
|
+
];
|
|
56
|
+
const decorated = (0, decorateStory_1.default)(() => ({ template: '</child>', props: { sameInput: 'Story input' } }), decorators);
|
|
57
|
+
expect(decorated(makeContext({
|
|
58
|
+
component: FooComponent,
|
|
59
|
+
}))).toEqual({
|
|
60
|
+
props: {
|
|
61
|
+
parentInput: 'Parent input',
|
|
62
|
+
parentOutput: expect.any(Function),
|
|
63
|
+
grandparentInput: 'Grandparent input',
|
|
64
|
+
sameInput: 'Story input',
|
|
65
|
+
},
|
|
66
|
+
template: '<great-grandparent><grandparent [grandparentInput]="grandparentInput"><parent [parentInput]="parentInput" (parentOutput)="parentOutput($event)"></child></parent></grandparent></great-grandparent>',
|
|
67
|
+
userDefinedTemplate: true,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
it('should use componentWrapperDecorator', () => {
|
|
71
|
+
const decorators = [
|
|
72
|
+
(0, decorators_1.componentWrapperDecorator)(ParentComponent),
|
|
73
|
+
(0, decorators_1.componentWrapperDecorator)((story) => `<grandparent>${story}</grandparent>`),
|
|
74
|
+
(0, decorators_1.componentWrapperDecorator)((story) => `<great-grandparent>${story}</great-grandparent>`),
|
|
75
|
+
];
|
|
76
|
+
const decorated = (0, decorateStory_1.default)(() => ({ template: '</child>' }), decorators);
|
|
77
|
+
expect(decorated(makeContext({ component: FooComponent }))).toEqual({
|
|
78
|
+
template: '<great-grandparent><grandparent><parent></child></parent></grandparent></great-grandparent>',
|
|
79
|
+
userDefinedTemplate: true,
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
it('should use template in preference to component parameters', () => {
|
|
83
|
+
const decorators = [
|
|
84
|
+
(s) => {
|
|
85
|
+
const story = s();
|
|
86
|
+
return {
|
|
87
|
+
...story,
|
|
88
|
+
template: `<parent>${story.template}</parent>`,
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
(s) => {
|
|
92
|
+
const story = s();
|
|
93
|
+
return {
|
|
94
|
+
...story,
|
|
95
|
+
template: `<grandparent>${story.template}</grandparent>`,
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
(s) => {
|
|
99
|
+
const story = s();
|
|
100
|
+
return {
|
|
101
|
+
...story,
|
|
102
|
+
template: `<great-grandparent>${story.template}</great-grandparent>`,
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
const decorated = (0, decorateStory_1.default)(() => ({ template: '</child>' }), decorators);
|
|
107
|
+
expect(decorated(makeContext({ component: FooComponent }))).toEqual({
|
|
108
|
+
template: '<great-grandparent><grandparent><parent></child></parent></grandparent></great-grandparent>',
|
|
109
|
+
userDefinedTemplate: true,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
it('should include story templates in decorators', () => {
|
|
113
|
+
const decorators = [
|
|
114
|
+
(s) => {
|
|
115
|
+
const story = s();
|
|
116
|
+
return {
|
|
117
|
+
...story,
|
|
118
|
+
template: `<parent>${story.template}</parent>`,
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
(s) => {
|
|
122
|
+
const story = s();
|
|
123
|
+
return {
|
|
124
|
+
...story,
|
|
125
|
+
template: `<grandparent>${story.template}</grandparent>`,
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
(s) => {
|
|
129
|
+
const story = s();
|
|
130
|
+
return {
|
|
131
|
+
...story,
|
|
132
|
+
template: `<great-grandparent>${story.template}</great-grandparent>`,
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
const decorated = (0, decorateStory_1.default)(() => ({ template: '</child>' }), decorators);
|
|
137
|
+
expect(decorated(makeContext({}))).toEqual({
|
|
138
|
+
template: '<great-grandparent><grandparent><parent></child></parent></grandparent></great-grandparent>',
|
|
139
|
+
userDefinedTemplate: true,
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
it('should include story components in decorators', () => {
|
|
143
|
+
const decorators = [
|
|
144
|
+
(s) => {
|
|
145
|
+
const story = s();
|
|
146
|
+
return {
|
|
147
|
+
...story,
|
|
148
|
+
template: `<parent>${story.template}</parent>`,
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
(s) => {
|
|
152
|
+
const story = s();
|
|
153
|
+
return {
|
|
154
|
+
...story,
|
|
155
|
+
template: `<grandparent>${story.template}</grandparent>`,
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
(s) => {
|
|
159
|
+
const story = s();
|
|
160
|
+
return {
|
|
161
|
+
...story,
|
|
162
|
+
template: `<great-grandparent>${story.template}</great-grandparent>`,
|
|
163
|
+
};
|
|
164
|
+
},
|
|
165
|
+
];
|
|
166
|
+
const decorated = (0, decorateStory_1.default)(() => ({}), decorators);
|
|
167
|
+
expect(decorated(makeContext({ component: FooComponent }))).toEqual({
|
|
168
|
+
template: '<great-grandparent><grandparent><parent><foo></foo></parent></grandparent></great-grandparent>',
|
|
169
|
+
userDefinedTemplate: false,
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
it('should keep template with an empty value', () => {
|
|
173
|
+
const decorators = [
|
|
174
|
+
(0, decorators_1.componentWrapperDecorator)(ParentComponent),
|
|
175
|
+
];
|
|
176
|
+
const decorated = (0, decorateStory_1.default)(() => ({ template: '' }), decorators);
|
|
177
|
+
expect(decorated(makeContext({ component: FooComponent }))).toEqual({
|
|
178
|
+
template: '<parent></parent>',
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
it('should only keeps args with a control or an action in argTypes', () => {
|
|
182
|
+
const decorated = (0, decorateStory_1.default)((context) => ({
|
|
183
|
+
template: `Args available in the story : ${Object.keys(context.args).join()}`,
|
|
184
|
+
}), []);
|
|
185
|
+
expect(decorated(makeContext({
|
|
186
|
+
component: FooComponent,
|
|
187
|
+
argTypes: {
|
|
188
|
+
withControl: { control: { type: 'object' }, name: 'withControl' },
|
|
189
|
+
withAction: { action: 'onClick', name: 'withAction' },
|
|
190
|
+
toRemove: { name: 'toRemove' },
|
|
191
|
+
},
|
|
192
|
+
args: {
|
|
193
|
+
withControl: 'withControl',
|
|
194
|
+
withAction: () => ({}),
|
|
195
|
+
toRemove: 'toRemove',
|
|
196
|
+
},
|
|
197
|
+
}))).toEqual({
|
|
198
|
+
template: 'Args available in the story : withControl,withAction',
|
|
199
|
+
userDefinedTemplate: true,
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
describe('default behavior', () => {
|
|
204
|
+
it('calls decorators in out to in order', () => {
|
|
205
|
+
const decorators = [
|
|
206
|
+
(s) => {
|
|
207
|
+
const story = s();
|
|
208
|
+
return { ...story, props: { a: [...story.props.a, 1] } };
|
|
209
|
+
},
|
|
210
|
+
(s) => {
|
|
211
|
+
const story = s();
|
|
212
|
+
return { ...story, props: { a: [...story.props.a, 2] } };
|
|
213
|
+
},
|
|
214
|
+
(s) => {
|
|
215
|
+
const story = s();
|
|
216
|
+
return { ...story, props: { a: [...story.props.a, 3] } };
|
|
217
|
+
},
|
|
218
|
+
];
|
|
219
|
+
const decorated = (0, decorateStory_1.default)(() => ({ props: { a: [0] } }), decorators);
|
|
220
|
+
expect(decorated(makeContext({}))).toEqual({ props: { a: [0, 1, 2, 3] } });
|
|
221
|
+
});
|
|
222
|
+
it('passes context through to sub decorators', () => {
|
|
223
|
+
const decorators = [
|
|
224
|
+
(s, c) => {
|
|
225
|
+
const story = s({ ...c, k: 1 });
|
|
226
|
+
return { ...story, props: { a: [...story.props.a, c.k] } };
|
|
227
|
+
},
|
|
228
|
+
(s, c) => {
|
|
229
|
+
const story = s({ ...c, k: 2 });
|
|
230
|
+
return { ...story, props: { a: [...story.props.a, c.k] } };
|
|
231
|
+
},
|
|
232
|
+
(s, c) => {
|
|
233
|
+
const story = s({ ...c, k: 3 });
|
|
234
|
+
return { ...story, props: { a: [...story.props.a, c.k] } };
|
|
235
|
+
},
|
|
236
|
+
];
|
|
237
|
+
const decorated = (0, decorateStory_1.default)((c) => ({ props: { a: [c.k] } }), decorators);
|
|
238
|
+
expect(decorated(makeContext({ k: 0 }))).toEqual({ props: { a: [1, 2, 3, 0] } });
|
|
239
|
+
});
|
|
240
|
+
it('DOES NOT merge parameter or pass through parameters key in context', () => {
|
|
241
|
+
const decorators = [
|
|
242
|
+
(s, c) => {
|
|
243
|
+
const story = s({ ...c, k: 1, parameters: { p: 1 } });
|
|
244
|
+
return {
|
|
245
|
+
...story,
|
|
246
|
+
props: { a: [...story.props.a, c.k], p: [...story.props.p, c.parameters.p] },
|
|
247
|
+
};
|
|
248
|
+
},
|
|
249
|
+
(s, c) => {
|
|
250
|
+
const story = s({ ...c, k: 2, parameters: { p: 2 } });
|
|
251
|
+
return {
|
|
252
|
+
...story,
|
|
253
|
+
props: { a: [...story.props.a, c.k], p: [...story.props.p, c.parameters.p] },
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
(s, c) => {
|
|
257
|
+
const story = s({ ...c, k: 3, parameters: { p: 3 } });
|
|
258
|
+
return {
|
|
259
|
+
...story,
|
|
260
|
+
props: { a: [...story.props.a, c.k], p: [...story.props.p, c.parameters.p] },
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
];
|
|
264
|
+
const decorated = (0, decorateStory_1.default)((c) => ({ props: { a: [c.k], p: [c.parameters.p] } }), decorators);
|
|
265
|
+
expect(decorated(makeContext({ k: 0, parameters: { p: 0 } }))).toEqual({
|
|
266
|
+
props: { a: [1, 2, 3, 0], p: [0, 0, 0, 0] },
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
function makeContext(input) {
|
|
272
|
+
return {
|
|
273
|
+
id: 'id',
|
|
274
|
+
kind: 'kind',
|
|
275
|
+
name: 'name',
|
|
276
|
+
viewMode: 'story',
|
|
277
|
+
parameters: {},
|
|
278
|
+
...input,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
let FooComponent = class FooComponent {
|
|
282
|
+
};
|
|
283
|
+
FooComponent = __decorate([
|
|
284
|
+
(0, core_1.Component)({
|
|
285
|
+
selector: 'foo',
|
|
286
|
+
template: `foo`,
|
|
287
|
+
})
|
|
288
|
+
], FooComponent);
|
|
289
|
+
let ParentComponent = class ParentComponent {
|
|
290
|
+
};
|
|
291
|
+
__decorate([
|
|
292
|
+
(0, core_1.Input)(),
|
|
293
|
+
__metadata("design:type", String)
|
|
294
|
+
], ParentComponent.prototype, "parentInput", void 0);
|
|
295
|
+
__decorate([
|
|
296
|
+
(0, core_1.Output)(),
|
|
297
|
+
__metadata("design:type", Object)
|
|
298
|
+
], ParentComponent.prototype, "parentOutput", void 0);
|
|
299
|
+
ParentComponent = __decorate([
|
|
300
|
+
(0, core_1.Component)({
|
|
301
|
+
selector: 'parent',
|
|
302
|
+
template: `<ng-content></ng-content>`,
|
|
303
|
+
})
|
|
304
|
+
], ParentComponent);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Type } from '@angular/core';
|
|
2
|
+
import { ApplicationConfig } from '@angular/platform-browser';
|
|
3
|
+
import { DecoratorFunction, StoryContext } from '@storybook/types';
|
|
4
|
+
import { ICollection, NgModuleMetadata, AngularRenderer } from './types';
|
|
5
|
+
export declare const moduleMetadata: <TArgs = any>(metadata: Partial<NgModuleMetadata>) => DecoratorFunction<AngularRenderer, TArgs>;
|
|
6
|
+
/**
|
|
7
|
+
* Decorator to set the config options which are available during the application bootstrap operation
|
|
8
|
+
*/
|
|
9
|
+
export declare function applicationConfig<TArgs = any>(
|
|
10
|
+
/**
|
|
11
|
+
* Set of config options available during the application bootstrap operation.
|
|
12
|
+
*/
|
|
13
|
+
config: ApplicationConfig): DecoratorFunction<AngularRenderer, TArgs>;
|
|
14
|
+
export declare const componentWrapperDecorator: <TArgs = any>(element: Type<unknown> | ((story: string) => string), props?: ICollection | ((storyContext: StoryContext<AngularRenderer, TArgs>) => ICollection) | undefined) => DecoratorFunction<AngularRenderer, TArgs>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.componentWrapperDecorator = exports.applicationConfig = exports.moduleMetadata = void 0;
|
|
4
|
+
const ComputesTemplateFromComponent_1 = require("./angular-beta/ComputesTemplateFromComponent");
|
|
5
|
+
const NgComponentAnalyzer_1 = require("./angular-beta/utils/NgComponentAnalyzer");
|
|
6
|
+
// We use `any` here as the default type rather than `Args` because we need something that is
|
|
7
|
+
// castable to any component-specific args type when the user is being careful.
|
|
8
|
+
const moduleMetadata = (metadata) => (storyFn) => {
|
|
9
|
+
const story = storyFn();
|
|
10
|
+
const storyMetadata = story.moduleMetadata || {};
|
|
11
|
+
metadata = metadata || {};
|
|
12
|
+
return {
|
|
13
|
+
...story,
|
|
14
|
+
moduleMetadata: {
|
|
15
|
+
declarations: [...(metadata.declarations || []), ...(storyMetadata.declarations || [])],
|
|
16
|
+
entryComponents: [
|
|
17
|
+
...(metadata.entryComponents || []),
|
|
18
|
+
...(storyMetadata.entryComponents || []),
|
|
19
|
+
],
|
|
20
|
+
imports: [...(metadata.imports || []), ...(storyMetadata.imports || [])],
|
|
21
|
+
schemas: [...(metadata.schemas || []), ...(storyMetadata.schemas || [])],
|
|
22
|
+
providers: [...(metadata.providers || []), ...(storyMetadata.providers || [])],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.moduleMetadata = moduleMetadata;
|
|
27
|
+
/**
|
|
28
|
+
* Decorator to set the config options which are available during the application bootstrap operation
|
|
29
|
+
*/
|
|
30
|
+
function applicationConfig(
|
|
31
|
+
/**
|
|
32
|
+
* Set of config options available during the application bootstrap operation.
|
|
33
|
+
*/
|
|
34
|
+
config) {
|
|
35
|
+
return (storyFn) => {
|
|
36
|
+
const story = storyFn();
|
|
37
|
+
const storyConfig = story.applicationConfig;
|
|
38
|
+
return {
|
|
39
|
+
...story,
|
|
40
|
+
applicationConfig: storyConfig || config
|
|
41
|
+
? {
|
|
42
|
+
...config,
|
|
43
|
+
...storyConfig,
|
|
44
|
+
providers: [...(config?.providers || []), ...(storyConfig?.providers || [])],
|
|
45
|
+
}
|
|
46
|
+
: undefined,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.applicationConfig = applicationConfig;
|
|
51
|
+
const componentWrapperDecorator = (element, props) => (storyFn, storyContext) => {
|
|
52
|
+
const story = storyFn();
|
|
53
|
+
const currentProps = typeof props === 'function' ? props(storyContext) : props;
|
|
54
|
+
const template = (0, NgComponentAnalyzer_1.isComponent)(element)
|
|
55
|
+
? (0, ComputesTemplateFromComponent_1.computesTemplateFromComponent)(element, currentProps ?? {}, story.template)
|
|
56
|
+
: element(story.template);
|
|
57
|
+
return {
|
|
58
|
+
...story,
|
|
59
|
+
template,
|
|
60
|
+
...(currentProps || story.props
|
|
61
|
+
? {
|
|
62
|
+
props: {
|
|
63
|
+
...currentProps,
|
|
64
|
+
...story.props,
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
: {}),
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
exports.componentWrapperDecorator = componentWrapperDecorator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|