@storybook/vue3 10.1.0-alpha.10 → 10.1.0-alpha.12
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-4BE7D4DS.js +9 -0
- package/dist/_browser-chunks/chunk-YJYABENR.js +263 -0
- package/dist/entry-preview-docs.js +147 -289
- package/dist/entry-preview.js +2 -2
- package/dist/index.js +12 -23
- package/dist/playwright.js +1 -1
- package/dist/preset.js +10 -13
- package/package.json +3 -3
- package/template/cli/ts/Button.stories.ts +1 -5
- package/dist/_browser-chunks/chunk-GZHEVVQL.js +0 -427
- package/dist/_browser-chunks/chunk-JFJ5UJ7Q.js +0 -11
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-4BE7D4DS.js";
|
|
4
|
+
|
|
5
|
+
// src/entry-preview.ts
|
|
6
|
+
var entry_preview_exports = {};
|
|
7
|
+
__export(entry_preview_exports, {
|
|
8
|
+
applyDecorators: () => decorateStory,
|
|
9
|
+
argTypesEnhancers: () => argTypesEnhancers,
|
|
10
|
+
mount: () => mount,
|
|
11
|
+
parameters: () => parameters,
|
|
12
|
+
render: () => render,
|
|
13
|
+
renderToCanvas: () => renderToCanvas
|
|
14
|
+
});
|
|
15
|
+
import { enhanceArgTypes, extractComponentDescription } from "storybook/internal/docs-tools";
|
|
16
|
+
|
|
17
|
+
// src/extractArgTypes.ts
|
|
18
|
+
import {
|
|
19
|
+
convert,
|
|
20
|
+
extractComponentProps,
|
|
21
|
+
hasDocgen
|
|
22
|
+
} from "storybook/internal/docs-tools";
|
|
23
|
+
var ARG_TYPE_SECTIONS = ["props", "events", "slots", "exposed", "expose"], extractArgTypes = (component) => {
|
|
24
|
+
if (!hasDocgen(component))
|
|
25
|
+
return null;
|
|
26
|
+
let usedDocgenPlugin = "exposed" in component.__docgenInfo ? "vue-component-meta" : "vue-docgen-api", argTypes = {};
|
|
27
|
+
return ARG_TYPE_SECTIONS.forEach((section) => {
|
|
28
|
+
extractComponentProps(component, section).forEach((extractedProp) => {
|
|
29
|
+
let argType;
|
|
30
|
+
if (usedDocgenPlugin === "vue-docgen-api") {
|
|
31
|
+
let docgenInfo = extractedProp.docgenInfo;
|
|
32
|
+
argType = extractFromVueDocgenApi(docgenInfo, section, extractedProp);
|
|
33
|
+
} else {
|
|
34
|
+
let docgenInfo = extractedProp.docgenInfo;
|
|
35
|
+
argType = extractFromVueComponentMeta(docgenInfo, section);
|
|
36
|
+
}
|
|
37
|
+
if (!argType || argTypes[argType.name])
|
|
38
|
+
return;
|
|
39
|
+
["events", "expose", "exposed"].includes(section) && (argType.control = { disable: !0 }), argTypes[argType.name] = argType;
|
|
40
|
+
});
|
|
41
|
+
}), argTypes;
|
|
42
|
+
}, extractFromVueDocgenApi = (docgenInfo, section, extractedProp) => {
|
|
43
|
+
let type, sbType;
|
|
44
|
+
if (section === "events" && (type = docgenInfo.type?.names.join(), sbType = { name: "other", value: type ?? "", required: !1 }), section === "slots") {
|
|
45
|
+
let slotBindings = docgenInfo.bindings?.filter((binding) => !!binding.name).map((binding) => `${binding.name}: ${binding.type?.name ?? "unknown"}`).join("; ");
|
|
46
|
+
type = slotBindings ? `{ ${slotBindings} }` : void 0, sbType = { name: "other", value: type ?? "", required: !1 };
|
|
47
|
+
}
|
|
48
|
+
if (section === "props") {
|
|
49
|
+
let propInfo = docgenInfo;
|
|
50
|
+
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) {
|
|
51
|
+
let elements = propInfo.type.elements.map((i) => i.name);
|
|
52
|
+
type === "Array" && (type = `${elements.length === 1 ? elements[0] : `(${elements.join(" | ")})`}[]`), type === "union" ? type = elements.join(" | ") : type === "intersection" && (type = elements.join(" & "));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
let required = "required" in docgenInfo ? docgenInfo.required ?? !1 : !1;
|
|
56
|
+
return {
|
|
57
|
+
name: docgenInfo.name,
|
|
58
|
+
description: docgenInfo.description,
|
|
59
|
+
type: sbType ? { ...sbType, required } : { name: "other", value: type ?? "" },
|
|
60
|
+
table: {
|
|
61
|
+
type: type ? { summary: type } : void 0,
|
|
62
|
+
defaultValue: extractedProp?.propDef.defaultValue ?? void 0,
|
|
63
|
+
jsDocTags: extractedProp?.propDef.jsDocTags,
|
|
64
|
+
category: section
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}, extractFromVueComponentMeta = (docgenInfo, section) => {
|
|
68
|
+
if ("global" in docgenInfo && docgenInfo.global)
|
|
69
|
+
return;
|
|
70
|
+
let tableType = { summary: docgenInfo.type.replace(" | undefined", "") };
|
|
71
|
+
if (section === "props") {
|
|
72
|
+
let propInfo = docgenInfo, defaultValue = propInfo.default ? { summary: propInfo.default } : void 0;
|
|
73
|
+
return {
|
|
74
|
+
name: propInfo.name,
|
|
75
|
+
description: formatDescriptionWithTags(propInfo.description, propInfo.tags),
|
|
76
|
+
defaultValue,
|
|
77
|
+
type: convertVueComponentMetaProp(propInfo),
|
|
78
|
+
table: {
|
|
79
|
+
type: tableType,
|
|
80
|
+
defaultValue,
|
|
81
|
+
category: section
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
} else
|
|
85
|
+
return {
|
|
86
|
+
name: docgenInfo.name,
|
|
87
|
+
description: "description" in docgenInfo ? docgenInfo.description : "",
|
|
88
|
+
type: { name: "other", value: docgenInfo.type },
|
|
89
|
+
table: { type: tableType, category: section }
|
|
90
|
+
};
|
|
91
|
+
}, convertVueComponentMetaProp = (propInfo) => {
|
|
92
|
+
let schema = propInfo.schema, required = propInfo.required, fallbackSbType = { name: "other", value: propInfo.type, required }, KNOWN_SCHEMAS = ["string", "number", "function", "boolean", "symbol"];
|
|
93
|
+
if (typeof schema == "string")
|
|
94
|
+
return KNOWN_SCHEMAS.includes(schema) ? { name: schema, required } : fallbackSbType;
|
|
95
|
+
switch (schema.kind) {
|
|
96
|
+
case "enum": {
|
|
97
|
+
let definedSchemas = schema.schema?.filter((item) => item !== "undefined") ?? [];
|
|
98
|
+
return isBooleanSchema(definedSchemas) ? { name: "boolean", required } : isLiteralUnionSchema(definedSchemas) || isEnumSchema(definedSchemas) ? { name: "enum", value: definedSchemas.map((literal) => literal.replace(/"/g, "")), required } : definedSchemas.length === 1 ? convertVueComponentMetaProp({
|
|
99
|
+
schema: definedSchemas[0],
|
|
100
|
+
type: propInfo.type,
|
|
101
|
+
required
|
|
102
|
+
}) : (definedSchemas.length > 2 && definedSchemas.includes("true") && definedSchemas.includes("false") && (definedSchemas = definedSchemas.filter((i) => i !== "true" && i !== "false"), definedSchemas.push("boolean")), {
|
|
103
|
+
name: "union",
|
|
104
|
+
value: definedSchemas.map((i) => convertVueComponentMetaProp(typeof i == "object" ? {
|
|
105
|
+
schema: i,
|
|
106
|
+
type: i.type,
|
|
107
|
+
required: !1
|
|
108
|
+
} : { schema: i, type: i, required: !1 })),
|
|
109
|
+
required
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
case "array": {
|
|
113
|
+
let definedSchemas = schema.schema?.filter((item) => item !== "undefined") ?? [];
|
|
114
|
+
return definedSchemas.length === 0 ? fallbackSbType : definedSchemas.length === 1 ? {
|
|
115
|
+
name: "array",
|
|
116
|
+
value: convertVueComponentMetaProp({
|
|
117
|
+
schema: definedSchemas[0],
|
|
118
|
+
type: propInfo.type,
|
|
119
|
+
required: !1
|
|
120
|
+
}),
|
|
121
|
+
required
|
|
122
|
+
} : {
|
|
123
|
+
name: "union",
|
|
124
|
+
value: definedSchemas.map((i) => convertVueComponentMetaProp(typeof i == "object" ? {
|
|
125
|
+
schema: i,
|
|
126
|
+
type: i.type,
|
|
127
|
+
required: !1
|
|
128
|
+
} : { schema: i, type: i, required: !1 })),
|
|
129
|
+
required
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
case "object":
|
|
133
|
+
return {
|
|
134
|
+
name: "object",
|
|
135
|
+
// while Storybook generates simple JSON object controls, nested schemas don't have specialized controls
|
|
136
|
+
// so we don't need to recursively map the object schema here
|
|
137
|
+
value: {},
|
|
138
|
+
required
|
|
139
|
+
};
|
|
140
|
+
default:
|
|
141
|
+
return fallbackSbType;
|
|
142
|
+
}
|
|
143
|
+
}, formatDescriptionWithTags = (description, tags) => !tags?.length || !description ? description ?? "" : `${tags.map((tag) => `@${tag.name}: ${tag.text}`).join("<br>")}<br><br>${description}`, isLiteralUnionSchema = (schemas) => schemas.every(
|
|
144
|
+
(schema) => typeof schema == "string" && schema.startsWith('"') && schema.endsWith('"')
|
|
145
|
+
), isEnumSchema = (schemas) => schemas.every((schema) => typeof schema == "string" && schema.includes(".")), isBooleanSchema = (schemas) => schemas.length === 2 && schemas.includes("true") && schemas.includes("false");
|
|
146
|
+
|
|
147
|
+
// src/render.ts
|
|
148
|
+
import { createApp, h, isReactive, isVNode, reactive } from "vue";
|
|
149
|
+
var render = (props, context) => {
|
|
150
|
+
let { id, component: Component } = context;
|
|
151
|
+
if (!Component)
|
|
152
|
+
throw new Error(
|
|
153
|
+
`Unable to render story ${id} as the component annotation is missing from the default export`
|
|
154
|
+
);
|
|
155
|
+
return () => h(Component, props, getSlots(props, context));
|
|
156
|
+
}, setup = (fn) => {
|
|
157
|
+
globalThis.PLUGINS_SETUP_FUNCTIONS ??= /* @__PURE__ */ new Set(), globalThis.PLUGINS_SETUP_FUNCTIONS.add(fn);
|
|
158
|
+
}, runSetupFunctions = async (app, storyContext) => {
|
|
159
|
+
globalThis && globalThis.PLUGINS_SETUP_FUNCTIONS && await Promise.all([...globalThis.PLUGINS_SETUP_FUNCTIONS].map((fn) => fn(app, storyContext)));
|
|
160
|
+
}, map = /* @__PURE__ */ new Map();
|
|
161
|
+
async function renderToCanvas({ storyFn, forceRemount, showMain, showException, storyContext, id }, canvasElement) {
|
|
162
|
+
let existingApp = map.get(canvasElement);
|
|
163
|
+
if (existingApp && !forceRemount) {
|
|
164
|
+
let element = storyFn(), args = getArgs(element, storyContext);
|
|
165
|
+
return updateArgs(existingApp.reactiveArgs, args), () => {
|
|
166
|
+
teardown(existingApp.vueApp, canvasElement);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
existingApp && forceRemount && teardown(existingApp.vueApp, canvasElement);
|
|
170
|
+
let vueApp = createApp({
|
|
171
|
+
setup() {
|
|
172
|
+
storyContext.args = reactive(storyContext.args);
|
|
173
|
+
let rootElement = storyFn(), args = getArgs(rootElement, storyContext), appState = {
|
|
174
|
+
vueApp,
|
|
175
|
+
reactiveArgs: reactive(args)
|
|
176
|
+
};
|
|
177
|
+
return map.set(canvasElement, appState), () => h(rootElement);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
return vueApp.config.errorHandler = (e, instance, info) => {
|
|
181
|
+
window.__STORYBOOK_PREVIEW__?.storyRenders.some(
|
|
182
|
+
(renderer) => renderer.id === id && renderer.phase === "playing"
|
|
183
|
+
) ? setTimeout(() => {
|
|
184
|
+
throw e;
|
|
185
|
+
}, 0) : showException(e);
|
|
186
|
+
}, await runSetupFunctions(vueApp, storyContext), vueApp.mount(canvasElement), showMain(), () => {
|
|
187
|
+
teardown(vueApp, canvasElement);
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function getSlots(props, context) {
|
|
191
|
+
let { argTypes } = context, slots = Object.entries(props).filter(([key]) => argTypes[key]?.table?.category === "slots").map(([key, value]) => [key, typeof value == "function" ? value : () => value]);
|
|
192
|
+
return Object.fromEntries(slots);
|
|
193
|
+
}
|
|
194
|
+
function getArgs(element, storyContext) {
|
|
195
|
+
return element.props && isVNode(element) ? element.props : storyContext.args;
|
|
196
|
+
}
|
|
197
|
+
function updateArgs(reactiveArgs, nextArgs) {
|
|
198
|
+
if (Object.keys(nextArgs).length === 0)
|
|
199
|
+
return;
|
|
200
|
+
let currentArgs = isReactive(reactiveArgs) ? reactiveArgs : reactive(reactiveArgs);
|
|
201
|
+
Object.keys(currentArgs).forEach((key) => {
|
|
202
|
+
key in nextArgs || delete currentArgs[key];
|
|
203
|
+
}), Object.assign(currentArgs, nextArgs);
|
|
204
|
+
}
|
|
205
|
+
function teardown(storybookApp, canvasElement) {
|
|
206
|
+
storybookApp?.unmount(), map.has(canvasElement) && map.delete(canvasElement);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/decorateStory.ts
|
|
210
|
+
import { sanitizeStoryContextUpdate } from "storybook/preview-api";
|
|
211
|
+
import { h as h2 } from "vue";
|
|
212
|
+
function normalizeFunctionalComponent(options) {
|
|
213
|
+
return typeof options == "function" ? { render: options, name: options.name } : options;
|
|
214
|
+
}
|
|
215
|
+
function prepare(rawStory, innerStory) {
|
|
216
|
+
let story = rawStory;
|
|
217
|
+
return story === null ? null : typeof story == "function" ? story : innerStory ? {
|
|
218
|
+
// Normalize so we can always spread an object
|
|
219
|
+
...normalizeFunctionalComponent(story),
|
|
220
|
+
components: { ...story.components || {}, story: innerStory }
|
|
221
|
+
} : {
|
|
222
|
+
render() {
|
|
223
|
+
return h2(story);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function decorateStory(storyFn, decorators) {
|
|
228
|
+
return decorators.reduce(
|
|
229
|
+
(decorated, decorator) => (context) => {
|
|
230
|
+
let story, decoratedStory = decorator((update) => {
|
|
231
|
+
let sanitizedUpdate = sanitizeStoryContextUpdate(update);
|
|
232
|
+
return update && (sanitizedUpdate.args = Object.assign(context.args, sanitizedUpdate.args)), story = decorated({ ...context, ...sanitizedUpdate }), story;
|
|
233
|
+
}, context);
|
|
234
|
+
return story || (story = decorated(context)), decoratedStory === story ? story : prepare(decoratedStory, () => h2(story));
|
|
235
|
+
},
|
|
236
|
+
(context) => prepare(storyFn(context))
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/mount.ts
|
|
241
|
+
import { h as h3 } from "vue";
|
|
242
|
+
var mount = (context) => async (Component, options) => (Component && (context.originalStoryFn = () => () => h3(Component, options?.props, options?.slots)), await context.renderToCanvas(), context.canvas);
|
|
243
|
+
|
|
244
|
+
// src/entry-preview.ts
|
|
245
|
+
var parameters = {
|
|
246
|
+
renderer: "vue3",
|
|
247
|
+
docs: {
|
|
248
|
+
story: { inline: !0 },
|
|
249
|
+
extractArgTypes,
|
|
250
|
+
extractComponentDescription
|
|
251
|
+
}
|
|
252
|
+
}, argTypesEnhancers = [enhanceArgTypes];
|
|
253
|
+
|
|
254
|
+
export {
|
|
255
|
+
render,
|
|
256
|
+
setup,
|
|
257
|
+
renderToCanvas,
|
|
258
|
+
decorateStory,
|
|
259
|
+
mount,
|
|
260
|
+
parameters,
|
|
261
|
+
argTypesEnhancers,
|
|
262
|
+
entry_preview_exports
|
|
263
|
+
};
|