UNPKG

2.82 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.componentWrapperDecorator = exports.applicationConfig = exports.moduleMetadata = void 0;
4const ComputesTemplateFromComponent_1 = require("./angular-beta/ComputesTemplateFromComponent");
5const 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.
8const 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};
26exports.moduleMetadata = moduleMetadata;
27/**
28 * Decorator to set the config options which are available during the application bootstrap operation
29 */
30function applicationConfig(
31/**
32 * Set of config options available during the application bootstrap operation.
33 */
34config) {
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}
50exports.applicationConfig = applicationConfig;
51const 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};
70exports.componentWrapperDecorator = componentWrapperDecorator;