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 |
|
7 |
|
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 |
|
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;
|