@storybook/vue3 9.2.0-alpha.2 → 10.0.0-beta.0
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/README.md +4 -0
- package/dist/_browser-chunks/chunk-GZHEVVQL.js +427 -0
- package/dist/_browser-chunks/chunk-JFJ5UJ7Q.js +11 -0
- package/dist/entry-preview-docs.js +367 -11
- package/dist/entry-preview.js +17 -1
- package/dist/index.d.ts +50 -9
- package/dist/index.js +70 -1
- package/dist/playwright.js +7 -1
- package/dist/preset.js +26 -1
- package/package.json +17 -40
- package/preset.js +1 -1
- package/dist/chunk-CEH6MNVV.mjs +0 -3
- package/dist/chunk-DYBVISFM.mjs +0 -8
- package/dist/entry-preview-docs.d.ts +0 -10
- package/dist/entry-preview-docs.mjs +0 -23
- package/dist/entry-preview.d.ts +0 -24
- package/dist/entry-preview.mjs +0 -2
- package/dist/index.mjs +0 -10
- package/dist/playwright.mjs +0 -2
- package/dist/preset.d.ts +0 -5
- package/dist/public-types-e4ebb831.d.ts +0 -40
- package/dist/render-0377a2e9.d.ts +0 -9
- package/dist/types-1ede6954.d.ts +0 -14
package/README.md
CHANGED
@@ -0,0 +1,427 @@
|
|
1
|
+
import {
|
2
|
+
__export,
|
3
|
+
__name
|
4
|
+
} from "./chunk-JFJ5UJ7Q.js";
|
5
|
+
|
6
|
+
// src/entry-preview.ts
|
7
|
+
var entry_preview_exports = {};
|
8
|
+
__export(entry_preview_exports, {
|
9
|
+
applyDecorators: () => decorateStory,
|
10
|
+
argTypesEnhancers: () => argTypesEnhancers,
|
11
|
+
mount: () => mount,
|
12
|
+
parameters: () => parameters,
|
13
|
+
render: () => render,
|
14
|
+
renderToCanvas: () => renderToCanvas
|
15
|
+
});
|
16
|
+
import { enhanceArgTypes, extractComponentDescription } from "storybook/internal/docs-tools";
|
17
|
+
|
18
|
+
// src/extractArgTypes.ts
|
19
|
+
import {
|
20
|
+
convert,
|
21
|
+
extractComponentProps,
|
22
|
+
hasDocgen
|
23
|
+
} from "storybook/internal/docs-tools";
|
24
|
+
var ARG_TYPE_SECTIONS = ["props", "events", "slots", "exposed", "expose"];
|
25
|
+
var extractArgTypes = /* @__PURE__ */ __name((component) => {
|
26
|
+
if (!hasDocgen(component)) {
|
27
|
+
return null;
|
28
|
+
}
|
29
|
+
const usedDocgenPlugin = "exposed" in component.__docgenInfo ? "vue-component-meta" : "vue-docgen-api";
|
30
|
+
const argTypes = {};
|
31
|
+
ARG_TYPE_SECTIONS.forEach((section) => {
|
32
|
+
const props = extractComponentProps(component, section);
|
33
|
+
props.forEach((extractedProp) => {
|
34
|
+
let argType;
|
35
|
+
if (usedDocgenPlugin === "vue-docgen-api") {
|
36
|
+
const docgenInfo = extractedProp.docgenInfo;
|
37
|
+
argType = extractFromVueDocgenApi(docgenInfo, section, extractedProp);
|
38
|
+
} else {
|
39
|
+
const docgenInfo = extractedProp.docgenInfo;
|
40
|
+
argType = extractFromVueComponentMeta(docgenInfo, section);
|
41
|
+
}
|
42
|
+
if (!argType || argTypes[argType.name]) {
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
const sectionsToDisableControls = ["events", "expose", "exposed"];
|
46
|
+
if (sectionsToDisableControls.includes(section)) {
|
47
|
+
argType.control = { disable: true };
|
48
|
+
}
|
49
|
+
argTypes[argType.name] = argType;
|
50
|
+
});
|
51
|
+
});
|
52
|
+
return argTypes;
|
53
|
+
}, "extractArgTypes");
|
54
|
+
var extractFromVueDocgenApi = /* @__PURE__ */ __name((docgenInfo, section, extractedProp) => {
|
55
|
+
let type;
|
56
|
+
let sbType;
|
57
|
+
if (section === "events") {
|
58
|
+
const eventInfo = docgenInfo;
|
59
|
+
type = eventInfo.type?.names.join();
|
60
|
+
sbType = { name: "other", value: type ?? "", required: false };
|
61
|
+
}
|
62
|
+
if (section === "slots") {
|
63
|
+
const slotInfo = docgenInfo;
|
64
|
+
const slotBindings = slotInfo.bindings?.filter((binding) => !!binding.name).map((binding) => {
|
65
|
+
return `${binding.name}: ${binding.type?.name ?? "unknown"}`;
|
66
|
+
}).join("; ");
|
67
|
+
type = slotBindings ? `{ ${slotBindings} }` : void 0;
|
68
|
+
sbType = { name: "other", value: type ?? "", required: false };
|
69
|
+
}
|
70
|
+
if (section === "props") {
|
71
|
+
const propInfo = docgenInfo;
|
72
|
+
type = propInfo.type?.name;
|
73
|
+
sbType = extractedProp ? convert(extractedProp.docgenInfo) : { name: "other", value: type };
|
74
|
+
if (propInfo.type && "elements" in propInfo.type && Array.isArray(propInfo.type.elements) && propInfo.type.elements.length > 0) {
|
75
|
+
const elements = propInfo.type.elements.map((i) => i.name);
|
76
|
+
if (type === "Array") {
|
77
|
+
const arrayElements = elements.length === 1 ? elements[0] : `(${elements.join(" | ")})`;
|
78
|
+
type = `${arrayElements}[]`;
|
79
|
+
}
|
80
|
+
if (type === "union") {
|
81
|
+
type = elements.join(" | ");
|
82
|
+
} else if (type === "intersection") {
|
83
|
+
type = elements.join(" & ");
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
const required = "required" in docgenInfo ? docgenInfo.required ?? false : false;
|
88
|
+
return {
|
89
|
+
name: docgenInfo.name,
|
90
|
+
description: docgenInfo.description,
|
91
|
+
type: sbType ? { ...sbType, required } : { name: "other", value: type ?? "" },
|
92
|
+
table: {
|
93
|
+
type: type ? { summary: type } : void 0,
|
94
|
+
defaultValue: extractedProp?.propDef.defaultValue ?? void 0,
|
95
|
+
jsDocTags: extractedProp?.propDef.jsDocTags,
|
96
|
+
category: section
|
97
|
+
}
|
98
|
+
};
|
99
|
+
}, "extractFromVueDocgenApi");
|
100
|
+
var extractFromVueComponentMeta = /* @__PURE__ */ __name((docgenInfo, section) => {
|
101
|
+
if ("global" in docgenInfo && docgenInfo.global) {
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
const tableType = { summary: docgenInfo.type.replace(" | undefined", "") };
|
105
|
+
if (section === "props") {
|
106
|
+
const propInfo = docgenInfo;
|
107
|
+
const defaultValue = propInfo.default ? { summary: propInfo.default } : void 0;
|
108
|
+
return {
|
109
|
+
name: propInfo.name,
|
110
|
+
description: formatDescriptionWithTags(propInfo.description, propInfo.tags),
|
111
|
+
defaultValue,
|
112
|
+
type: convertVueComponentMetaProp(propInfo),
|
113
|
+
table: {
|
114
|
+
type: tableType,
|
115
|
+
defaultValue,
|
116
|
+
category: section
|
117
|
+
}
|
118
|
+
};
|
119
|
+
} else {
|
120
|
+
return {
|
121
|
+
name: docgenInfo.name,
|
122
|
+
description: "description" in docgenInfo ? docgenInfo.description : "",
|
123
|
+
type: { name: "other", value: docgenInfo.type },
|
124
|
+
table: { type: tableType, category: section }
|
125
|
+
};
|
126
|
+
}
|
127
|
+
}, "extractFromVueComponentMeta");
|
128
|
+
var convertVueComponentMetaProp = /* @__PURE__ */ __name((propInfo) => {
|
129
|
+
const schema = propInfo.schema;
|
130
|
+
const required = propInfo.required;
|
131
|
+
const fallbackSbType = { name: "other", value: propInfo.type, required };
|
132
|
+
const KNOWN_SCHEMAS = ["string", "number", "function", "boolean", "symbol"];
|
133
|
+
if (typeof schema === "string") {
|
134
|
+
if (KNOWN_SCHEMAS.includes(schema)) {
|
135
|
+
return { name: schema, required };
|
136
|
+
}
|
137
|
+
return fallbackSbType;
|
138
|
+
}
|
139
|
+
switch (schema.kind) {
|
140
|
+
case "enum": {
|
141
|
+
let definedSchemas = schema.schema?.filter((item) => item !== "undefined") ?? [];
|
142
|
+
if (isBooleanSchema(definedSchemas)) {
|
143
|
+
return { name: "boolean", required };
|
144
|
+
}
|
145
|
+
if (isLiteralUnionSchema(definedSchemas) || isEnumSchema(definedSchemas)) {
|
146
|
+
const literals = definedSchemas.map((literal) => literal.replace(/"/g, ""));
|
147
|
+
return { name: "enum", value: literals, required };
|
148
|
+
}
|
149
|
+
if (definedSchemas.length === 1) {
|
150
|
+
return convertVueComponentMetaProp({
|
151
|
+
schema: definedSchemas[0],
|
152
|
+
type: propInfo.type,
|
153
|
+
required
|
154
|
+
});
|
155
|
+
}
|
156
|
+
if (definedSchemas.length > 2 && definedSchemas.includes("true") && definedSchemas.includes("false")) {
|
157
|
+
definedSchemas = definedSchemas.filter((i) => i !== "true" && i !== "false");
|
158
|
+
definedSchemas.push("boolean");
|
159
|
+
}
|
160
|
+
return {
|
161
|
+
name: "union",
|
162
|
+
value: definedSchemas.map((i) => {
|
163
|
+
if (typeof i === "object") {
|
164
|
+
return convertVueComponentMetaProp({
|
165
|
+
schema: i,
|
166
|
+
type: i.type,
|
167
|
+
required: false
|
168
|
+
});
|
169
|
+
} else {
|
170
|
+
return convertVueComponentMetaProp({ schema: i, type: i, required: false });
|
171
|
+
}
|
172
|
+
}),
|
173
|
+
required
|
174
|
+
};
|
175
|
+
}
|
176
|
+
case "array": {
|
177
|
+
const definedSchemas = schema.schema?.filter((item) => item !== "undefined") ?? [];
|
178
|
+
if (definedSchemas.length === 0) {
|
179
|
+
return fallbackSbType;
|
180
|
+
}
|
181
|
+
if (definedSchemas.length === 1) {
|
182
|
+
return {
|
183
|
+
name: "array",
|
184
|
+
value: convertVueComponentMetaProp({
|
185
|
+
schema: definedSchemas[0],
|
186
|
+
type: propInfo.type,
|
187
|
+
required: false
|
188
|
+
}),
|
189
|
+
required
|
190
|
+
};
|
191
|
+
}
|
192
|
+
return {
|
193
|
+
name: "union",
|
194
|
+
value: definedSchemas.map((i) => {
|
195
|
+
if (typeof i === "object") {
|
196
|
+
return convertVueComponentMetaProp({
|
197
|
+
schema: i,
|
198
|
+
type: i.type,
|
199
|
+
required: false
|
200
|
+
});
|
201
|
+
} else {
|
202
|
+
return convertVueComponentMetaProp({ schema: i, type: i, required: false });
|
203
|
+
}
|
204
|
+
}),
|
205
|
+
required
|
206
|
+
};
|
207
|
+
}
|
208
|
+
case "object":
|
209
|
+
return {
|
210
|
+
name: "object",
|
211
|
+
// while Storybook generates simple JSON object controls, nested schemas don't have specialized controls
|
212
|
+
// so we don't need to recursively map the object schema here
|
213
|
+
value: {},
|
214
|
+
required
|
215
|
+
};
|
216
|
+
default:
|
217
|
+
return fallbackSbType;
|
218
|
+
}
|
219
|
+
}, "convertVueComponentMetaProp");
|
220
|
+
var formatDescriptionWithTags = /* @__PURE__ */ __name((description, tags) => {
|
221
|
+
if (!tags?.length || !description) {
|
222
|
+
return description ?? "";
|
223
|
+
}
|
224
|
+
const tagDescriptions = tags.map((tag) => `@${tag.name}: ${tag.text}`).join("<br>");
|
225
|
+
return `${tagDescriptions}<br><br>${description}`;
|
226
|
+
}, "formatDescriptionWithTags");
|
227
|
+
var isLiteralUnionSchema = /* @__PURE__ */ __name((schemas) => {
|
228
|
+
return schemas.every(
|
229
|
+
(schema) => typeof schema === "string" && schema.startsWith('"') && schema.endsWith('"')
|
230
|
+
);
|
231
|
+
}, "isLiteralUnionSchema");
|
232
|
+
var isEnumSchema = /* @__PURE__ */ __name((schemas) => {
|
233
|
+
return schemas.every((schema) => typeof schema === "string" && schema.includes("."));
|
234
|
+
}, "isEnumSchema");
|
235
|
+
var isBooleanSchema = /* @__PURE__ */ __name((schemas) => {
|
236
|
+
return schemas.length === 2 && schemas.includes("true") && schemas.includes("false");
|
237
|
+
}, "isBooleanSchema");
|
238
|
+
|
239
|
+
// src/render.ts
|
240
|
+
import { createApp, h, isReactive, isVNode, reactive } from "vue";
|
241
|
+
var render = /* @__PURE__ */ __name((props, context) => {
|
242
|
+
const { id, component: Component } = context;
|
243
|
+
if (!Component) {
|
244
|
+
throw new Error(
|
245
|
+
`Unable to render story ${id} as the component annotation is missing from the default export`
|
246
|
+
);
|
247
|
+
}
|
248
|
+
return () => h(Component, props, getSlots(props, context));
|
249
|
+
}, "render");
|
250
|
+
var setup = /* @__PURE__ */ __name((fn) => {
|
251
|
+
globalThis.PLUGINS_SETUP_FUNCTIONS ??= /* @__PURE__ */ new Set();
|
252
|
+
globalThis.PLUGINS_SETUP_FUNCTIONS.add(fn);
|
253
|
+
}, "setup");
|
254
|
+
var runSetupFunctions = /* @__PURE__ */ __name(async (app, storyContext) => {
|
255
|
+
if (globalThis && globalThis.PLUGINS_SETUP_FUNCTIONS) {
|
256
|
+
await Promise.all([...globalThis.PLUGINS_SETUP_FUNCTIONS].map((fn) => fn(app, storyContext)));
|
257
|
+
}
|
258
|
+
}, "runSetupFunctions");
|
259
|
+
var map = /* @__PURE__ */ new Map();
|
260
|
+
async function renderToCanvas({ storyFn, forceRemount, showMain, showException, storyContext, id }, canvasElement) {
|
261
|
+
const existingApp = map.get(canvasElement);
|
262
|
+
if (existingApp && !forceRemount) {
|
263
|
+
const element = storyFn();
|
264
|
+
const args = getArgs(element, storyContext);
|
265
|
+
updateArgs(existingApp.reactiveArgs, args);
|
266
|
+
return () => {
|
267
|
+
teardown(existingApp.vueApp, canvasElement);
|
268
|
+
};
|
269
|
+
}
|
270
|
+
if (existingApp && forceRemount) {
|
271
|
+
teardown(existingApp.vueApp, canvasElement);
|
272
|
+
}
|
273
|
+
const vueApp = createApp({
|
274
|
+
setup() {
|
275
|
+
storyContext.args = reactive(storyContext.args);
|
276
|
+
const rootElement = storyFn();
|
277
|
+
const args = getArgs(rootElement, storyContext);
|
278
|
+
const appState = {
|
279
|
+
vueApp,
|
280
|
+
reactiveArgs: reactive(args)
|
281
|
+
};
|
282
|
+
map.set(canvasElement, appState);
|
283
|
+
return () => {
|
284
|
+
return h(rootElement);
|
285
|
+
};
|
286
|
+
}
|
287
|
+
});
|
288
|
+
vueApp.config.errorHandler = (e, instance, info) => {
|
289
|
+
const preview = window.__STORYBOOK_PREVIEW__;
|
290
|
+
const isPlaying = preview?.storyRenders.some(
|
291
|
+
(renderer) => renderer.id === id && renderer.phase === "playing"
|
292
|
+
);
|
293
|
+
if (isPlaying) {
|
294
|
+
setTimeout(() => {
|
295
|
+
throw e;
|
296
|
+
}, 0);
|
297
|
+
} else {
|
298
|
+
showException(e);
|
299
|
+
}
|
300
|
+
};
|
301
|
+
await runSetupFunctions(vueApp, storyContext);
|
302
|
+
vueApp.mount(canvasElement);
|
303
|
+
showMain();
|
304
|
+
return () => {
|
305
|
+
teardown(vueApp, canvasElement);
|
306
|
+
};
|
307
|
+
}
|
308
|
+
__name(renderToCanvas, "renderToCanvas");
|
309
|
+
function getSlots(props, context) {
|
310
|
+
const { argTypes } = context;
|
311
|
+
const slots = Object.entries(props).filter(([key]) => argTypes[key]?.table?.category === "slots").map(([key, value]) => [key, typeof value === "function" ? value : () => value]);
|
312
|
+
return Object.fromEntries(slots);
|
313
|
+
}
|
314
|
+
__name(getSlots, "getSlots");
|
315
|
+
function getArgs(element, storyContext) {
|
316
|
+
return element.props && isVNode(element) ? element.props : storyContext.args;
|
317
|
+
}
|
318
|
+
__name(getArgs, "getArgs");
|
319
|
+
function updateArgs(reactiveArgs, nextArgs) {
|
320
|
+
if (Object.keys(nextArgs).length === 0) {
|
321
|
+
return;
|
322
|
+
}
|
323
|
+
const currentArgs = isReactive(reactiveArgs) ? reactiveArgs : reactive(reactiveArgs);
|
324
|
+
Object.keys(currentArgs).forEach((key) => {
|
325
|
+
if (!(key in nextArgs)) {
|
326
|
+
delete currentArgs[key];
|
327
|
+
}
|
328
|
+
});
|
329
|
+
Object.assign(currentArgs, nextArgs);
|
330
|
+
}
|
331
|
+
__name(updateArgs, "updateArgs");
|
332
|
+
function teardown(storybookApp, canvasElement) {
|
333
|
+
storybookApp?.unmount();
|
334
|
+
if (map.has(canvasElement)) {
|
335
|
+
map.delete(canvasElement);
|
336
|
+
}
|
337
|
+
}
|
338
|
+
__name(teardown, "teardown");
|
339
|
+
|
340
|
+
// src/decorateStory.ts
|
341
|
+
import { sanitizeStoryContextUpdate } from "storybook/preview-api";
|
342
|
+
import { h as h2 } from "vue";
|
343
|
+
function normalizeFunctionalComponent(options) {
|
344
|
+
return typeof options === "function" ? { render: options, name: options.name } : options;
|
345
|
+
}
|
346
|
+
__name(normalizeFunctionalComponent, "normalizeFunctionalComponent");
|
347
|
+
function prepare(rawStory, innerStory) {
|
348
|
+
const story = rawStory;
|
349
|
+
if (story === null) {
|
350
|
+
return null;
|
351
|
+
}
|
352
|
+
if (typeof story === "function") {
|
353
|
+
return story;
|
354
|
+
}
|
355
|
+
if (innerStory) {
|
356
|
+
return {
|
357
|
+
// Normalize so we can always spread an object
|
358
|
+
...normalizeFunctionalComponent(story),
|
359
|
+
components: { ...story.components || {}, story: innerStory }
|
360
|
+
};
|
361
|
+
}
|
362
|
+
return {
|
363
|
+
render() {
|
364
|
+
return h2(story);
|
365
|
+
}
|
366
|
+
};
|
367
|
+
}
|
368
|
+
__name(prepare, "prepare");
|
369
|
+
function decorateStory(storyFn, decorators) {
|
370
|
+
return decorators.reduce(
|
371
|
+
(decorated, decorator) => (context) => {
|
372
|
+
let story;
|
373
|
+
const decoratedStory = decorator((update) => {
|
374
|
+
const sanitizedUpdate = sanitizeStoryContextUpdate(update);
|
375
|
+
if (update) {
|
376
|
+
sanitizedUpdate.args = Object.assign(context.args, sanitizedUpdate.args);
|
377
|
+
}
|
378
|
+
story = decorated({ ...context, ...sanitizedUpdate });
|
379
|
+
return story;
|
380
|
+
}, context);
|
381
|
+
if (!story) {
|
382
|
+
story = decorated(context);
|
383
|
+
}
|
384
|
+
if (decoratedStory === story) {
|
385
|
+
return story;
|
386
|
+
}
|
387
|
+
const innerStory = /* @__PURE__ */ __name(() => h2(story), "innerStory");
|
388
|
+
return prepare(decoratedStory, innerStory);
|
389
|
+
},
|
390
|
+
(context) => prepare(storyFn(context))
|
391
|
+
);
|
392
|
+
}
|
393
|
+
__name(decorateStory, "decorateStory");
|
394
|
+
|
395
|
+
// src/mount.ts
|
396
|
+
import { h as h3 } from "vue";
|
397
|
+
var mount = /* @__PURE__ */ __name((context) => {
|
398
|
+
return async (Component, options) => {
|
399
|
+
if (Component) {
|
400
|
+
context.originalStoryFn = () => () => h3(Component, options?.props, options?.slots);
|
401
|
+
}
|
402
|
+
await context.renderToCanvas();
|
403
|
+
return context.canvas;
|
404
|
+
};
|
405
|
+
}, "mount");
|
406
|
+
|
407
|
+
// src/entry-preview.ts
|
408
|
+
var parameters = {
|
409
|
+
renderer: "vue3",
|
410
|
+
docs: {
|
411
|
+
story: { inline: true },
|
412
|
+
extractArgTypes,
|
413
|
+
extractComponentDescription
|
414
|
+
}
|
415
|
+
};
|
416
|
+
var argTypesEnhancers = [enhanceArgTypes];
|
417
|
+
|
418
|
+
export {
|
419
|
+
render,
|
420
|
+
setup,
|
421
|
+
renderToCanvas,
|
422
|
+
decorateStory,
|
423
|
+
mount,
|
424
|
+
parameters,
|
425
|
+
argTypesEnhancers,
|
426
|
+
entry_preview_exports
|
427
|
+
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
3
|
+
var __export = (target, all) => {
|
4
|
+
for (var name in all)
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
6
|
+
};
|
7
|
+
|
8
|
+
export {
|
9
|
+
__name,
|
10
|
+
__export
|
11
|
+
};
|