@storybook/vue3 11.0.0-alpha.1 → 11.0.0-alpha.2
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/dist/_browser-chunks/{chunk-X42PMG4S.js → chunk-SKDBAXQY.js} +7 -12
- package/dist/_browser-chunks/{chunk-RVWTWVC7.js → chunk-T4D6SHGG.js} +1 -1
- package/dist/_node-chunks/chunk-5YXAOXC5.js +332 -0
- package/dist/_node-chunks/{chunk-CBUQSMLV.js → chunk-HMJ7OQCR.js} +9 -9
- package/dist/_node-chunks/{chunk-ZVM3PFP6.js → chunk-KTX22GYQ.js} +7 -7
- package/dist/_node-chunks/chunk-N4SWLWYK.js +1417 -0
- package/dist/_node-chunks/{component-meta-BNWGJCPR.js → component-meta-VD2ERN35.js} +7 -7
- package/dist/_node-chunks/{parsers-IND63D3J.js → parsers-4SAZHL3Y.js} +6 -6
- package/dist/_node-chunks/vue-docgen-api-JTFQSS7Y.js +17 -0
- package/dist/chunk-Dka2iJUy.d.ts +44 -0
- package/dist/chunk-PVetFykd.d.ts +65 -0
- package/dist/docgen/docgen-worker.js +23 -267
- package/dist/docgen/index.d.ts +58 -0
- package/dist/docgen/index.js +254 -0
- package/dist/entry-preview-docs.js +1 -1
- package/dist/entry-preview.js +1 -1
- package/dist/index.d.ts +22 -88
- package/dist/index.js +2 -2
- package/dist/preset.d.ts +27 -57
- package/dist/preset.js +48 -1421
- package/package.json +9 -3
- package/dist/_node-chunks/vue-docgen-api-2FOKDIT5.js +0 -17
|
@@ -14,13 +14,9 @@ __export(entry_preview_exports, {
|
|
|
14
14
|
});
|
|
15
15
|
import { enhanceArgTypes, extractComponentDescription } from "storybook/internal/docs-tools";
|
|
16
16
|
|
|
17
|
-
// src/extractArgTypes.ts
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
extractComponentProps,
|
|
21
|
-
hasDocgen
|
|
22
|
-
} from "storybook/internal/docs-tools";
|
|
23
|
-
var ARG_TYPE_SECTIONS = ["props", "events", "slots", "exposed", "expose"], extractArgTypes = (component) => {
|
|
17
|
+
// src/docgen/component-docgen/arg-types/extractArgTypes.ts
|
|
18
|
+
import { convert, extractComponentProps, hasDocgen } from "storybook/internal/docs-tools";
|
|
19
|
+
var ARG_TYPE_SECTIONS = ["props", "events", "slots", "exposed", "expose"], extractArgTypes = (component, resolveNamedTypeDetail) => {
|
|
24
20
|
if (!hasDocgen(component))
|
|
25
21
|
return null;
|
|
26
22
|
let usedDocgenPlugin = "exposed" in component.__docgenInfo ? "vue-component-meta" : "vue-docgen-api", argTypes = {};
|
|
@@ -32,7 +28,7 @@ var ARG_TYPE_SECTIONS = ["props", "events", "slots", "exposed", "expose"], extra
|
|
|
32
28
|
argType = extractFromVueDocgenApi(docgenInfo, section, extractedProp);
|
|
33
29
|
} else {
|
|
34
30
|
let docgenInfo = extractedProp.docgenInfo;
|
|
35
|
-
argType = extractFromVueComponentMeta(docgenInfo, section);
|
|
31
|
+
argType = extractFromVueComponentMeta(docgenInfo, section, resolveNamedTypeDetail);
|
|
36
32
|
}
|
|
37
33
|
if (!argType || argTypes[argType.name])
|
|
38
34
|
return;
|
|
@@ -64,23 +60,22 @@ var ARG_TYPE_SECTIONS = ["props", "events", "slots", "exposed", "expose"], extra
|
|
|
64
60
|
category: section
|
|
65
61
|
}
|
|
66
62
|
};
|
|
67
|
-
}, extractFromVueComponentMeta = (docgenInfo, section) => {
|
|
63
|
+
}, extractFromVueComponentMeta = (docgenInfo, section, resolveNamedTypeDetail) => {
|
|
68
64
|
if ("global" in docgenInfo && docgenInfo.global)
|
|
69
65
|
return;
|
|
70
66
|
let tableType = { summary: docgenInfo.type.replace(" | undefined", "") };
|
|
71
67
|
if (section === "props") {
|
|
72
|
-
let propInfo = docgenInfo, defaultValue = propInfo.default ? { summary: propInfo.default } : void 0, type = convertVueComponentMetaProp(propInfo), enumLabels = getEnumMemberLabels(propInfo.schema);
|
|
68
|
+
let propInfo = docgenInfo, defaultValue = propInfo.default ? { summary: propInfo.default } : void 0, type = convertVueComponentMetaProp(propInfo), enumLabels = getEnumMemberLabels(propInfo.schema), detail = resolveNamedTypeDetail?.(tableType.summary);
|
|
73
69
|
return {
|
|
74
70
|
name: propInfo.name,
|
|
75
71
|
description: formatDescriptionWithTags(propInfo.description, propInfo.tags),
|
|
76
|
-
defaultValue,
|
|
77
72
|
type,
|
|
78
73
|
// A TS enum member is selected by its runtime value, so the qualified name it is written
|
|
79
74
|
// as can only be a label. "control.type" is left to inferControls, which picks radio or
|
|
80
75
|
// select by option count just like it does for a plain literal union.
|
|
81
76
|
...enumLabels && type.name === "enum" ? { options: type.value, control: { labels: enumLabels } } : {},
|
|
82
77
|
table: {
|
|
83
|
-
type: tableType,
|
|
78
|
+
type: detail ? { ...tableType, detail } : tableType,
|
|
84
79
|
defaultValue,
|
|
85
80
|
category: section
|
|
86
81
|
}
|
|
@@ -8,7 +8,7 @@ __export(entry_preview_docs_exports, {
|
|
|
8
8
|
decorators: () => decorators
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
// src/docs/sourceDecorator.ts
|
|
11
|
+
// src/docgen/story-docs/source-decorator/sourceDecorator.ts
|
|
12
12
|
import { SourceType } from "storybook/internal/docs-tools";
|
|
13
13
|
import { emitTransformCode, useEffect } from "storybook/preview-api";
|
|
14
14
|
import { isVNode } from "vue";
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import CJS_COMPAT_NODE_URL_98nuqxz95u6 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_98nuqxz95u6 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_98nuqxz95u6 from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_98nuqxz95u6.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_98nuqxz95u6.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_98nuqxz95u6.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import {
|
|
13
|
+
indent
|
|
14
|
+
} from "./chunk-HMJ7OQCR.js";
|
|
15
|
+
|
|
16
|
+
// src/docgen/component-docgen/arg-types/extractArgTypes.ts
|
|
17
|
+
import { convert, extractComponentProps, hasDocgen } from "storybook/internal/docs-tools";
|
|
18
|
+
var ARG_TYPE_SECTIONS = ["props", "events", "slots", "exposed", "expose"], extractArgTypes = (component, resolveNamedTypeDetail) => {
|
|
19
|
+
if (!hasDocgen(component))
|
|
20
|
+
return null;
|
|
21
|
+
let usedDocgenPlugin = "exposed" in component.__docgenInfo ? "vue-component-meta" : "vue-docgen-api", argTypes = {};
|
|
22
|
+
return ARG_TYPE_SECTIONS.forEach((section2) => {
|
|
23
|
+
extractComponentProps(component, section2).forEach((extractedProp) => {
|
|
24
|
+
let argType;
|
|
25
|
+
if (usedDocgenPlugin === "vue-docgen-api") {
|
|
26
|
+
let docgenInfo = extractedProp.docgenInfo;
|
|
27
|
+
argType = extractFromVueDocgenApi(docgenInfo, section2, extractedProp);
|
|
28
|
+
} else {
|
|
29
|
+
let docgenInfo = extractedProp.docgenInfo;
|
|
30
|
+
argType = extractFromVueComponentMeta(docgenInfo, section2, resolveNamedTypeDetail);
|
|
31
|
+
}
|
|
32
|
+
if (!argType || argTypes[argType.name])
|
|
33
|
+
return;
|
|
34
|
+
["events", "expose", "exposed"].includes(section2) && (argType.control = { disable: !0 }), argTypes[argType.name] = argType;
|
|
35
|
+
});
|
|
36
|
+
}), argTypes;
|
|
37
|
+
}, extractFromVueDocgenApi = (docgenInfo, section2, extractedProp) => {
|
|
38
|
+
let type, sbType;
|
|
39
|
+
if (section2 === "events" && (type = docgenInfo.type?.names.join(), sbType = { name: "other", value: type ?? "", required: !1 }), section2 === "slots") {
|
|
40
|
+
let slotBindings = docgenInfo.bindings?.filter((binding) => !!binding.name).map((binding) => `${binding.name}: ${binding.type?.name ?? "unknown"}`).join("; ");
|
|
41
|
+
type = slotBindings ? `{ ${slotBindings} }` : void 0, sbType = { name: "other", value: type ?? "", required: !1 };
|
|
42
|
+
}
|
|
43
|
+
if (section2 === "props") {
|
|
44
|
+
let propInfo = docgenInfo;
|
|
45
|
+
if (type = propInfo.type?.name, sbType = extractedProp ? convert(extractedProp.docgenInfo) : { name: "other", value: type }, propInfo.type && "elements" in propInfo.type && Array.isArray(propInfo.type.elements) && propInfo.type.elements.length > 0) {
|
|
46
|
+
let elements = propInfo.type.elements.map((i) => i.name);
|
|
47
|
+
type === "Array" && (type = `${elements.length === 1 ? elements[0] : `(${elements.join(" | ")})`}[]`), type === "union" ? type = elements.join(" | ") : type === "intersection" && (type = elements.join(" & "));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
let required = "required" in docgenInfo ? docgenInfo.required ?? !1 : !1;
|
|
51
|
+
return {
|
|
52
|
+
name: docgenInfo.name,
|
|
53
|
+
description: docgenInfo.description,
|
|
54
|
+
type: sbType ? { ...sbType, required } : { name: "other", value: type ?? "" },
|
|
55
|
+
table: {
|
|
56
|
+
type: type ? { summary: type } : void 0,
|
|
57
|
+
defaultValue: extractedProp?.propDef.defaultValue ?? void 0,
|
|
58
|
+
jsDocTags: extractedProp?.propDef.jsDocTags,
|
|
59
|
+
category: section2
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}, extractFromVueComponentMeta = (docgenInfo, section2, resolveNamedTypeDetail) => {
|
|
63
|
+
if ("global" in docgenInfo && docgenInfo.global)
|
|
64
|
+
return;
|
|
65
|
+
let tableType = { summary: docgenInfo.type.replace(" | undefined", "") };
|
|
66
|
+
if (section2 === "props") {
|
|
67
|
+
let propInfo = docgenInfo, defaultValue = propInfo.default ? { summary: propInfo.default } : void 0, type = convertVueComponentMetaProp(propInfo), enumLabels = getEnumMemberLabels(propInfo.schema), detail = resolveNamedTypeDetail?.(tableType.summary);
|
|
68
|
+
return {
|
|
69
|
+
name: propInfo.name,
|
|
70
|
+
description: formatDescriptionWithTags(propInfo.description, propInfo.tags),
|
|
71
|
+
type,
|
|
72
|
+
// A TS enum member is selected by its runtime value, so the qualified name it is written
|
|
73
|
+
// as can only be a label. "control.type" is left to inferControls, which picks radio or
|
|
74
|
+
// select by option count just like it does for a plain literal union.
|
|
75
|
+
...enumLabels && type.name === "enum" ? { options: type.value, control: { labels: enumLabels } } : {},
|
|
76
|
+
table: {
|
|
77
|
+
type: detail ? { ...tableType, detail } : tableType,
|
|
78
|
+
defaultValue,
|
|
79
|
+
category: section2
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
} else
|
|
83
|
+
return {
|
|
84
|
+
name: docgenInfo.name,
|
|
85
|
+
description: "description" in docgenInfo ? docgenInfo.description : "",
|
|
86
|
+
type: { name: "other", value: docgenInfo.type },
|
|
87
|
+
table: { type: tableType, category: section2 }
|
|
88
|
+
};
|
|
89
|
+
}, convertVueComponentMetaProp = (propInfo) => {
|
|
90
|
+
let schema = propInfo.schema, required = propInfo.required, fallbackSbType = { name: "other", value: propInfo.type, required }, KNOWN_SCHEMAS = ["string", "number", "function", "boolean", "symbol"];
|
|
91
|
+
if (typeof schema == "string")
|
|
92
|
+
return KNOWN_SCHEMAS.includes(schema) ? { name: schema, required } : fallbackSbType;
|
|
93
|
+
switch (schema.kind) {
|
|
94
|
+
case "enum": {
|
|
95
|
+
let definedSchemas = schema.schema?.filter((item) => item !== "undefined") ?? [];
|
|
96
|
+
return isBooleanSchema(definedSchemas) ? { name: "boolean", required } : isSelectableUnionSchema(definedSchemas) ? { name: "enum", value: definedSchemas.map(selectableValue), required } : isEnumSchema(definedSchemas) ? fallbackSbType : definedSchemas.length === 1 ? convertVueComponentMetaProp({
|
|
97
|
+
schema: definedSchemas[0],
|
|
98
|
+
type: propInfo.type,
|
|
99
|
+
required
|
|
100
|
+
}) : (definedSchemas.length > 2 && definedSchemas.includes("true") && definedSchemas.includes("false") && (definedSchemas = definedSchemas.filter((i) => i !== "true" && i !== "false"), definedSchemas.push("boolean")), {
|
|
101
|
+
name: "union",
|
|
102
|
+
value: definedSchemas.map((i) => convertVueComponentMetaProp(typeof i == "object" ? {
|
|
103
|
+
schema: i,
|
|
104
|
+
type: i.type,
|
|
105
|
+
required: !1
|
|
106
|
+
} : { schema: i, type: i, required: !1 })),
|
|
107
|
+
required
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
case "array": {
|
|
111
|
+
let definedSchemas = schema.schema?.filter((item) => item !== "undefined") ?? [];
|
|
112
|
+
return definedSchemas.length === 0 ? fallbackSbType : definedSchemas.length === 1 ? {
|
|
113
|
+
name: "array",
|
|
114
|
+
value: convertVueComponentMetaProp({
|
|
115
|
+
schema: definedSchemas[0],
|
|
116
|
+
type: propInfo.type,
|
|
117
|
+
required: !1
|
|
118
|
+
}),
|
|
119
|
+
required
|
|
120
|
+
} : {
|
|
121
|
+
name: "union",
|
|
122
|
+
value: definedSchemas.map((i) => convertVueComponentMetaProp(typeof i == "object" ? {
|
|
123
|
+
schema: i,
|
|
124
|
+
type: i.type,
|
|
125
|
+
required: !1
|
|
126
|
+
} : { schema: i, type: i, required: !1 })),
|
|
127
|
+
required
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
case "object":
|
|
131
|
+
return {
|
|
132
|
+
name: "object",
|
|
133
|
+
// while Storybook generates simple JSON object controls, nested schemas don't have specialized controls
|
|
134
|
+
// so we don't need to recursively map the object schema here
|
|
135
|
+
value: {},
|
|
136
|
+
required
|
|
137
|
+
};
|
|
138
|
+
default:
|
|
139
|
+
return fallbackSbType;
|
|
140
|
+
}
|
|
141
|
+
}, formatDescriptionWithTags = (description, tags) => !tags?.length || !description ? description ?? "" : `${tags.map((tag) => `@${tag.name}: ${tag.text}`).join("<br>")}<br><br>${description}`, isLiteralSchema = (schema) => typeof schema == "object" && schema.kind === "literal", isQuotedLiteral = (schema) => typeof schema == "string" && schema.startsWith('"') && schema.endsWith('"'), isSelectableUnionSchema = (schemas) => schemas.every((schema) => isQuotedLiteral(schema) || isLiteralSchema(schema)), selectableValue = (schema) => isLiteralSchema(schema) ? JSON.parse(schema.value) : schema.replace(/"/g, ""), getEnumMemberLabels = (schema) => {
|
|
142
|
+
if (typeof schema != "object" || schema.kind !== "enum")
|
|
143
|
+
return;
|
|
144
|
+
let members = (schema.schema ?? []).filter(isLiteralSchema);
|
|
145
|
+
return members.length ? Object.fromEntries(members.map((member) => [selectableValue(member), member.type])) : void 0;
|
|
146
|
+
}, isEnumSchema = (schemas) => schemas.every((schema) => typeof schema == "string" && schema.includes(".")), isBooleanSchema = (schemas) => schemas.length === 2 && schemas.includes("true") && schemas.includes("false");
|
|
147
|
+
|
|
148
|
+
// src/docgen/component-docgen/api-description/api-description.ts
|
|
149
|
+
var IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
150
|
+
function buildApiDescription(meta) {
|
|
151
|
+
let { slots, exposed } = meta, bindableProps = meta.props.filter((prop) => !prop.global), eventsByName = new Map(meta.events.map((event) => [event.name, event])), models = bindableProps.filter((prop) => eventsByName.has(`update:${prop.name}`)), modelNames = new Set(models.map((model) => model.name)), props = bindableProps.filter((prop) => !modelNames.has(prop.name)), events = meta.events.filter(
|
|
152
|
+
(event) => !(event.name.startsWith("update:") && modelNames.has(event.name.slice(6)))
|
|
153
|
+
);
|
|
154
|
+
if (!models.length && !props.length && !events.length && !slots.length && !exposed.length)
|
|
155
|
+
return;
|
|
156
|
+
let sanitizedDisplayName = meta.displayName.replace(/\W+/g, ""), typePrefix = /^[A-Za-z_$]/.test(sanitizedDisplayName) ? sanitizedDisplayName : `Component${sanitizedDisplayName}`;
|
|
157
|
+
function memberKey2(name) {
|
|
158
|
+
return IDENTIFIER.test(name) ? name : JSON.stringify(name);
|
|
159
|
+
}
|
|
160
|
+
let parts = [];
|
|
161
|
+
return models.length > 0 && parts.push(
|
|
162
|
+
...section(
|
|
163
|
+
"Models",
|
|
164
|
+
`${typePrefix}Models`,
|
|
165
|
+
meta.typeParams,
|
|
166
|
+
models.flatMap((model) => {
|
|
167
|
+
let event = eventsByName.get(`update:${model.name}`), description = model.description?.trim() ? model.description : event?.description;
|
|
168
|
+
return propLine(
|
|
169
|
+
{ ...model, description: description ?? "" },
|
|
170
|
+
` // ${modelBinding(model.name)}="..."`
|
|
171
|
+
);
|
|
172
|
+
}),
|
|
173
|
+
"Two-way bindings. Bind each one with the `v-model` syntax shown next to it \u2014 do not pass the prop and listen to its `update:` event separately."
|
|
174
|
+
)
|
|
175
|
+
), props.length > 0 && parts.push(
|
|
176
|
+
...section(
|
|
177
|
+
"Props",
|
|
178
|
+
`${typePrefix}Props`,
|
|
179
|
+
meta.typeParams,
|
|
180
|
+
props.flatMap((prop) => propLine(prop))
|
|
181
|
+
)
|
|
182
|
+
), events.length > 0 && parts.push(
|
|
183
|
+
...section(
|
|
184
|
+
"Events",
|
|
185
|
+
`${typePrefix}Events`,
|
|
186
|
+
meta.typeParams,
|
|
187
|
+
events.flatMap((event) => [
|
|
188
|
+
...docComment(event),
|
|
189
|
+
`${memberKey2(event.name)}: ${event.type};`
|
|
190
|
+
])
|
|
191
|
+
)
|
|
192
|
+
), slots.length > 0 && parts.push(
|
|
193
|
+
...section(
|
|
194
|
+
"Slots",
|
|
195
|
+
`${typePrefix}Slots`,
|
|
196
|
+
meta.typeParams,
|
|
197
|
+
slots.flatMap((slot) => [...docComment(slot), `${memberKey2(slot.name)}: ${slot.type};`]),
|
|
198
|
+
"Each slot is typed with the props it passes to its content."
|
|
199
|
+
)
|
|
200
|
+
), exposed.length > 0 && parts.push(
|
|
201
|
+
...section(
|
|
202
|
+
"Exposed",
|
|
203
|
+
`${typePrefix}Exposed`,
|
|
204
|
+
meta.typeParams,
|
|
205
|
+
exposed.flatMap((member) => [
|
|
206
|
+
...docComment(member),
|
|
207
|
+
`${memberKey2(member.name)}: ${member.type};`
|
|
208
|
+
]),
|
|
209
|
+
"Available on the component instance through a template ref."
|
|
210
|
+
)
|
|
211
|
+
), parts.join(`
|
|
212
|
+
`).trim();
|
|
213
|
+
}
|
|
214
|
+
function memberKey(name) {
|
|
215
|
+
return IDENTIFIER.test(name) ? name : `'${name}'`;
|
|
216
|
+
}
|
|
217
|
+
function modelBinding(propName) {
|
|
218
|
+
return propName === "modelValue" ? "v-model" : `v-model:${propName}`;
|
|
219
|
+
}
|
|
220
|
+
function docComment(member, defaultValue) {
|
|
221
|
+
let description = member.description?.trim() ?? "", tags = member.tags ?? [], tagLines = tags.map((tag) => `@${tag.name}${tag.text ? ` ${tag.text}` : ""}`);
|
|
222
|
+
if (defaultValue !== void 0 && !tags.some((tag) => tag.name === "default") && tagLines.push(`@default ${defaultValue}`), !description && tagLines.length === 0)
|
|
223
|
+
return [];
|
|
224
|
+
if (!description && tagLines.length === 1)
|
|
225
|
+
return [`/** ${tagLines[0]} */`];
|
|
226
|
+
if (!description.includes(`
|
|
227
|
+
`) && tagLines.length === 0)
|
|
228
|
+
return [`/** ${description} */`];
|
|
229
|
+
let body = description.split(`
|
|
230
|
+
`).map((line) => line.trim() ? ` * ${line}` : " *");
|
|
231
|
+
return [
|
|
232
|
+
"/**",
|
|
233
|
+
...description ? body : [],
|
|
234
|
+
...tagLines.length ? [...description ? [" *"] : [], ...tagLines.map((tag) => ` * ${tag}`)] : [],
|
|
235
|
+
" */"
|
|
236
|
+
];
|
|
237
|
+
}
|
|
238
|
+
function propLine(prop, marker = "") {
|
|
239
|
+
let optional = prop.required ? "" : "?", type = prop.type.replace(" | undefined", "");
|
|
240
|
+
return [
|
|
241
|
+
...docComment(prop, prop.default),
|
|
242
|
+
`${memberKey(prop.name)}${optional}: ${type};${marker}`
|
|
243
|
+
];
|
|
244
|
+
}
|
|
245
|
+
function section(heading, typeName, typeParams, lines, intro) {
|
|
246
|
+
let aliasTypeParams = typeParams ? `<${typeParams}>` : "";
|
|
247
|
+
return [
|
|
248
|
+
`## ${heading}`,
|
|
249
|
+
"",
|
|
250
|
+
...intro ? [intro, ""] : [],
|
|
251
|
+
"```",
|
|
252
|
+
`export type ${typeName}${aliasTypeParams} = {`,
|
|
253
|
+
...indent(lines.join(`
|
|
254
|
+
`)).split(`
|
|
255
|
+
`),
|
|
256
|
+
"}",
|
|
257
|
+
"```",
|
|
258
|
+
""
|
|
259
|
+
];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/docgen/component-docgen/arg-types/named-type-detail.ts
|
|
263
|
+
import { slash } from "storybook/internal/common";
|
|
264
|
+
var MAX_DETAIL_LINES = 20, TYPE_NAME_PATTERN = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/, isExternalFile = (file) => file.isDeclarationFile || file.fileName.includes("node_modules");
|
|
265
|
+
function createNamedTypeDetailResolver({
|
|
266
|
+
checker,
|
|
267
|
+
typescript,
|
|
268
|
+
componentPath
|
|
269
|
+
}) {
|
|
270
|
+
let program = checker.getProgram(), location = program?.getSourceFile(slash(componentPath));
|
|
271
|
+
if (!program || !location)
|
|
272
|
+
return () => {
|
|
273
|
+
};
|
|
274
|
+
let typeChecker = program.getTypeChecker(), unwrapAlias = (symbol) => symbol.flags & typescript.SymbolFlags.Alias ? typeChecker.getAliasedSymbol(symbol) : symbol, resolveQualifiedName = (name) => {
|
|
275
|
+
let [head, ...rest] = name.split("."), symbol = typeChecker.resolveName(
|
|
276
|
+
head,
|
|
277
|
+
location,
|
|
278
|
+
typescript.SymbolFlags.Type | typescript.SymbolFlags.Namespace,
|
|
279
|
+
!1
|
|
280
|
+
);
|
|
281
|
+
for (let segment of rest) {
|
|
282
|
+
if (!symbol)
|
|
283
|
+
return;
|
|
284
|
+
symbol = unwrapAlias(symbol).exports?.get(segment);
|
|
285
|
+
}
|
|
286
|
+
return symbol;
|
|
287
|
+
}, capLines = (lines) => lines.length <= MAX_DETAIL_LINES ? lines : [...lines.slice(0, MAX_DETAIL_LINES), `\u2026 ${lines.length - MAX_DETAIL_LINES} more`], renderMembers = (name, lines) => lines.length > 0 ? [`${name} {`, ...capLines(lines), "}"].join(`
|
|
288
|
+
`) : void 0, renderObject = (name, type) => renderMembers(
|
|
289
|
+
name,
|
|
290
|
+
type.getProperties().map((property) => {
|
|
291
|
+
let isOptional = !!(property.flags & typescript.SymbolFlags.Optional), rawTypeText = typeChecker.typeToString(typeChecker.getTypeOfSymbol(property)), strippedTypeText = rawTypeText.replace(/\s*\|\s*undefined$/, ""), typeText = isOptional && strippedTypeText || rawTypeText, description = typescript.displayPartsToString(property.getDocumentationComment(typeChecker)).replace(/\s+/g, " ").trim();
|
|
292
|
+
return ` ${property.getName()}${isOptional ? "?" : ""}: ${typeText}${description ? ` \u2014 ${description}` : ""}`;
|
|
293
|
+
})
|
|
294
|
+
), renderEnum = (name, declaration) => renderMembers(
|
|
295
|
+
name,
|
|
296
|
+
declaration.members.map((member) => {
|
|
297
|
+
let memberName = member.name.getText(), constantValue = typeChecker.getConstantValue(member);
|
|
298
|
+
if (typeof constantValue == "string")
|
|
299
|
+
return ` ${memberName} = '${constantValue.replace(/'/g, "\\'")}'`;
|
|
300
|
+
if (typeof constantValue == "number")
|
|
301
|
+
return ` ${memberName} = ${constantValue}`;
|
|
302
|
+
let initializer = member.initializer?.getText();
|
|
303
|
+
return initializer ? ` ${memberName} = ${initializer}` : ` ${memberName}`;
|
|
304
|
+
})
|
|
305
|
+
);
|
|
306
|
+
return (typeName) => {
|
|
307
|
+
if (!TYPE_NAME_PATTERN.test(typeName))
|
|
308
|
+
return;
|
|
309
|
+
let symbol = resolveQualifiedName(typeName);
|
|
310
|
+
if (!symbol)
|
|
311
|
+
return;
|
|
312
|
+
let realSymbol = unwrapAlias(symbol), declaration = realSymbol.declarations?.[0];
|
|
313
|
+
if (declaration && !realSymbol.declarations?.some((d) => isExternalFile(d.getSourceFile()))) {
|
|
314
|
+
if (typescript.isEnumDeclaration(declaration))
|
|
315
|
+
return renderEnum(typeName, declaration);
|
|
316
|
+
if (typescript.isInterfaceDeclaration(declaration))
|
|
317
|
+
return renderObject(typeName, typeChecker.getDeclaredTypeOfSymbol(realSymbol));
|
|
318
|
+
if (typescript.isTypeAliasDeclaration(declaration)) {
|
|
319
|
+
let resolved = typeChecker.getTypeAtLocation(declaration.type);
|
|
320
|
+
return !(resolved.flags & typescript.TypeFlags.Object) || typeChecker.getPropertiesOfType(resolved).every(
|
|
321
|
+
(member) => member.declarations?.some((d) => isExternalFile(d.getSourceFile())) ?? !0
|
|
322
|
+
) ? void 0 : renderObject(typeName, resolved);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export {
|
|
329
|
+
extractArgTypes,
|
|
330
|
+
buildApiDescription,
|
|
331
|
+
createNamedTypeDetailResolver
|
|
332
|
+
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_98nuqxz95u6 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_98nuqxz95u6 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_98nuqxz95u6 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_98nuqxz95u6.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_98nuqxz95u6.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_98nuqxz95u6.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
|
|
13
|
-
// src/
|
|
13
|
+
// src/docgen/shared/render-primitives.ts
|
|
14
14
|
import { types as t } from "storybook/internal/babel";
|
|
15
15
|
import {
|
|
16
16
|
buildImportStatements,
|
|
17
17
|
unwrapExpression as unwrapExpression2
|
|
18
18
|
} from "storybook/internal/csf-tools";
|
|
19
19
|
|
|
20
|
-
// src/
|
|
20
|
+
// src/docgen/shared/classify-value.ts
|
|
21
21
|
import { recast } from "storybook/internal/babel";
|
|
22
22
|
import { unwrapExpression } from "storybook/internal/csf-tools";
|
|
23
23
|
var RESOLVABLE_GLOBALS = /* @__PURE__ */ new Set([
|
|
@@ -159,7 +159,7 @@ function isResolvable(node, locals = NO_LOCALS) {
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
// src/
|
|
162
|
+
// src/docgen/shared/render-primitives.ts
|
|
163
163
|
var VUE_PACKAGE = "vue";
|
|
164
164
|
function partitionArgsByRole(args) {
|
|
165
165
|
return {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_98nuqxz95u6 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_98nuqxz95u6 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_98nuqxz95u6 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_98nuqxz95u6.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_98nuqxz95u6.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_98nuqxz95u6.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
|
|
13
|
-
// src/docgen/component-meta.ts
|
|
13
|
+
// src/docgen/component-docgen/component-meta/component-meta.ts
|
|
14
14
|
import { readFile, stat } from "node:fs/promises";
|
|
15
15
|
import { join, parse } from "node:path";
|
|
16
16
|
import { getProjectRoot } from "storybook/internal/common";
|