@storybook/angular 10.6.0-alpha.4 → 10.6.0-alpha.6

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.
@@ -1,246 +0,0 @@
1
- import {
2
- __export,
3
- computesTemplateFromComponent,
4
- render,
5
- renderToCanvas
6
- } from "./chunk-FPQDYJYM.js";
7
-
8
- // src/client/config.ts
9
- var config_exports = {};
10
- __export(config_exports, {
11
- applyDecorators: () => decorateStory,
12
- argTypesEnhancers: () => argTypesEnhancers,
13
- parameters: () => parameters,
14
- render: () => render,
15
- renderToCanvas: () => renderToCanvas
16
- });
17
-
18
- // src/client/globals.ts
19
- import { global } from "@storybook/global";
20
- global.STORYBOOK_ENV = "angular";
21
-
22
- // src/client/decorateStory.ts
23
- import { sanitizeStoryContextUpdate } from "storybook/preview-api";
24
- function decorateStory(mainStoryFn, decorators) {
25
- return [cleanArgsDecorator, ...decorators].reduce(
26
- (previousStoryFn, decorator) => (context) => decorator((update) => previousStoryFn({
27
- ...context,
28
- ...sanitizeStoryContextUpdate(update)
29
- }), context),
30
- (context) => prepareMain(mainStoryFn(context), context)
31
- );
32
- }
33
- var prepareMain = (story, context) => {
34
- let { template } = story, { component } = context, userDefinedTemplate = !hasNoTemplate(template);
35
- return !userDefinedTemplate && component && (template = computesTemplateFromComponent(component, story.props, "")), {
36
- ...story,
37
- ...template ? { template, userDefinedTemplate } : {}
38
- };
39
- };
40
- function hasNoTemplate(template) {
41
- return template == null;
42
- }
43
- var cleanArgsDecorator = (storyFn, context) => {
44
- if (!context.argTypes || !context.args)
45
- return storyFn();
46
- let argsToClean = context.args;
47
- return context.args = Object.entries(argsToClean).reduce((obj, [key, arg]) => {
48
- let argType = context.argTypes[key];
49
- return argType?.action || argType?.control ? { ...obj, [key]: arg } : obj;
50
- }, {}), storyFn();
51
- };
52
-
53
- // src/client/config.ts
54
- import { enhanceArgTypes } from "storybook/internal/docs-tools";
55
-
56
- // src/client/compodoc.ts
57
- import { logger } from "storybook/internal/client-logger";
58
- import { global as global2 } from "@storybook/global";
59
- var { FEATURES } = global2, isMethod = (methodOrProp) => methodOrProp.args !== void 0;
60
- var getCompodocJson = () => global2.__STORYBOOK_COMPODOC_JSON__, checkValidComponentOrDirective = (component) => {
61
- if (!component.name)
62
- throw new Error(`Invalid component ${JSON.stringify(component)}`);
63
- }, checkValidCompodocJson = (compodocJson) => {
64
- if (!compodocJson || !compodocJson.components)
65
- throw new Error("Invalid compodoc JSON");
66
- }, hasDecorator = (item, decoratorName) => item.decorators && item.decorators.find((x) => x.name === decoratorName), mapPropertyToSection = (item) => hasDecorator(item, "ViewChild") ? "view child" : hasDecorator(item, "ViewChildren") ? "view children" : hasDecorator(item, "ContentChild") ? "content child" : hasDecorator(item, "ContentChildren") ? "content children" : "properties", mapItemToSection = (key, item) => {
67
- switch (key) {
68
- case "methods":
69
- case "methodsClass":
70
- return "methods";
71
- case "inputsClass":
72
- return "inputs";
73
- case "outputsClass":
74
- return "outputs";
75
- case "properties":
76
- case "propertiesClass":
77
- if (isMethod(item))
78
- throw new Error("Cannot be of type Method if key === 'propertiesClass'");
79
- return mapPropertyToSection(item);
80
- default:
81
- throw new Error(`Unknown key: ${key}`);
82
- }
83
- }, findComponentByName = (name, compodocJson) => compodocJson.components.find((c) => c.name === name) || compodocJson.directives.find((c) => c.name === name) || compodocJson.pipes.find((c) => c.name === name) || compodocJson.injectables.find((c) => c.name === name) || compodocJson.classes.find((c) => c.name === name), getComponentData = (component) => {
84
- if (!component)
85
- return null;
86
- checkValidComponentOrDirective(component);
87
- let compodocJson = getCompodocJson();
88
- if (!compodocJson)
89
- return null;
90
- checkValidCompodocJson(compodocJson);
91
- let { name } = component, metadata = findComponentByName(name, compodocJson);
92
- return metadata || logger.warn(`Component not found in compodoc JSON: '${name}'`), metadata;
93
- }, displaySignature = (item) => `(${item.args.map(
94
- (arg) => `${arg.name}${arg.optional ? "?" : ""}: ${arg.type}`
95
- ).join(", ")}) => ${item.returnType}`, extractTypeFromValue = (defaultValue) => {
96
- let valueType = typeof defaultValue;
97
- return defaultValue || valueType === "number" || valueType === "boolean" || valueType === "string" ? valueType : null;
98
- }, extractEnumValues = (compodocType) => {
99
- let enumType = getCompodocJson()?.miscellaneous?.enumerations?.find((x) => x.name === compodocType);
100
- if (enumType?.childs.every((x) => x.value))
101
- return enumType.childs.map((x) => x.value);
102
- if (typeof compodocType != "string" || compodocType.indexOf("|") === -1)
103
- return null;
104
- try {
105
- return compodocType.split("|").map((value) => JSON.parse(value));
106
- } catch {
107
- return null;
108
- }
109
- }, extractType = (property, defaultValue) => {
110
- let compodocType = property.type || extractTypeFromValue(defaultValue);
111
- switch (compodocType) {
112
- case "string":
113
- case "boolean":
114
- case "number":
115
- return { name: compodocType };
116
- case void 0:
117
- case null:
118
- return { name: "other", value: "void" };
119
- default: {
120
- let resolvedType = resolveTypealias(compodocType), enumValues = extractEnumValues(resolvedType);
121
- return enumValues ? { name: "enum", value: enumValues } : { name: "other", value: "empty-enum" };
122
- }
123
- }
124
- }, castDefaultValue = (property, defaultValue) => {
125
- let compodocType = property.type;
126
- if (["boolean", "number", "string", "EventEmitter"].includes(compodocType))
127
- switch (compodocType) {
128
- case "boolean":
129
- return defaultValue === "true";
130
- case "number":
131
- return Number(defaultValue);
132
- case "EventEmitter":
133
- return;
134
- default:
135
- return defaultValue;
136
- }
137
- else
138
- switch (defaultValue) {
139
- case "true":
140
- return !0;
141
- case "false":
142
- return !1;
143
- case "null":
144
- return null;
145
- case "undefined":
146
- return;
147
- default:
148
- return defaultValue;
149
- }
150
- }, extractDefaultValueFromComments = (property, value) => {
151
- let commentValue = value;
152
- return property.jsdoctags.forEach((tag) => {
153
- ["default", "defaultvalue"].includes(tag.tagName.escapedText) && (commentValue = new global2.DOMParser().parseFromString(tag.comment, "text/html").body.textContent);
154
- }), commentValue;
155
- }, extractDefaultValue = (property) => {
156
- try {
157
- let value = property.defaultValue?.replace(/^'(.*)'$/, "$1");
158
- return value = castDefaultValue(property, value), value == null && property.jsdoctags?.length > 0 && (value = extractDefaultValueFromComments(property, value)), value;
159
- } catch {
160
- logger.debug(`Error extracting ${property.name}: ${property.defaultValue}`);
161
- return;
162
- }
163
- }, resolveTypealias = (compodocType) => {
164
- let typeAlias = getCompodocJson()?.miscellaneous?.typealiases?.find((x) => x.name === compodocType);
165
- return typeAlias ? resolveTypealias(typeAlias.rawtype) : compodocType;
166
- }, extractArgTypesFromData = (componentData) => {
167
- let sectionToItems = {}, componentClasses = FEATURES.angularFilterNonInputControls ? ["inputsClass"] : ["propertiesClass", "methodsClass", "inputsClass", "outputsClass"], compodocClasses = ["component", "directive"].includes(componentData.type) ? componentClasses : ["properties", "methods"], inputClassNames = new Set(
168
- (componentData.inputsClass || []).map((item) => item.name)
169
- ), modelProperties = (componentData.outputsClass || []).filter((item) => inputClassNames.has(item.name)), modelPropertyNames = new Set(modelProperties.map((item) => item.name));
170
- compodocClasses.forEach((key) => {
171
- (componentData[key] || []).forEach((item) => {
172
- let section = mapItemToSection(key, item);
173
- if (key === "outputsClass" && !isMethod(item) && modelPropertyNames.has(item.name))
174
- return;
175
- let defaultValue = isMethod(item) ? void 0 : extractDefaultValue(item), type = isMethod(item) || section !== "inputs" && section !== "properties" ? { name: "other", value: "void" } : extractType(item, defaultValue), action = section === "outputs" ? { action: item.name } : {}, argType = {
176
- name: item.name,
177
- description: item.rawdescription || item.description,
178
- type,
179
- ...action,
180
- table: {
181
- category: section,
182
- type: {
183
- summary: isMethod(item) ? displaySignature(item) : item.type,
184
- required: isMethod(item) ? !1 : !item.optional
185
- },
186
- defaultValue: { summary: defaultValue }
187
- }
188
- };
189
- sectionToItems[section] || (sectionToItems[section] = []), sectionToItems[section].push(argType);
190
- });
191
- }), modelProperties.forEach((item) => {
192
- let changeName = `${item.name}Change`, argType = {
193
- name: changeName,
194
- description: item.rawdescription || item.description,
195
- type: { name: "other", value: "void" },
196
- action: changeName,
197
- table: {
198
- category: "outputs",
199
- type: {
200
- summary: `(e: ${item.type}) => void`,
201
- required: !item.optional
202
- }
203
- }
204
- };
205
- sectionToItems.outputs || (sectionToItems.outputs = []), sectionToItems.outputs.push(argType);
206
- });
207
- let SECTIONS = [
208
- "properties",
209
- "inputs",
210
- "outputs",
211
- "methods",
212
- "view child",
213
- "view children",
214
- "content child",
215
- "content children"
216
- ], argTypes = {};
217
- return SECTIONS.forEach((section) => {
218
- let items = sectionToItems[section];
219
- items && items.forEach((argType) => {
220
- argTypes[argType.name] = argType;
221
- });
222
- }), argTypes;
223
- }, extractArgTypes = (component) => {
224
- let componentData = getComponentData(component);
225
- return componentData && extractArgTypesFromData(componentData);
226
- }, extractComponentDescription = (component) => {
227
- let componentData = getComponentData(component);
228
- return componentData && (componentData.rawdescription || componentData.description);
229
- };
230
-
231
- // src/client/config.ts
232
- var parameters = {
233
- renderer: "angular",
234
- docs: {
235
- story: { inline: !0 },
236
- extractArgTypes,
237
- extractComponentDescription
238
- }
239
- }, argTypesEnhancers = [enhanceArgTypes];
240
-
241
- export {
242
- decorateStory,
243
- parameters,
244
- argTypesEnhancers,
245
- config_exports
246
- };