@storybook/vue3 11.0.0-alpha.6 → 11.0.0-alpha.8

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,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_o98lcndpw1r from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_o98lcndpw1r from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_o98lcndpw1r from "node:module";
1
+ import CJS_COMPAT_NODE_URL_6baiaphk7nk from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_6baiaphk7nk from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_6baiaphk7nk from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_o98lcndpw1r.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_o98lcndpw1r.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_o98lcndpw1r.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_6baiaphk7nk.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_6baiaphk7nk.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_6baiaphk7nk.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -136,7 +136,7 @@ async function applyVueDocgenApiTempFixes(filename, componentsMeta, exportNames)
136
136
  let parsedComponentDocs = await parseMulti(filename), parsedByExportName = new Map(parsedComponentDocs.map((doc) => [doc.exportName, doc]));
137
137
  componentsMeta.forEach((meta, index) => {
138
138
  let parsed = parsedByExportName.get(exportNames[index]);
139
- parsed && ((hasEvents || needsEventRestore) && mergeEventDescriptions(meta, parsed.events), needsEventRestore && restoreMissingRuntimeEvents(meta, parsed.events), needsSlots && mergeTemplateSlots(meta, parsed.slots));
139
+ parsed && ((hasEvents || needsEventRestore) && mergeEventDescriptions(meta, parsed.events), needsEventRestore && restoreMissingRuntimeEvents(meta, parsed.events), needsSlots && mergeTemplateSlots(meta, parsed.slots, source));
140
140
  });
141
141
  } catch {
142
142
  }
@@ -185,16 +185,36 @@ function hasTemplateSlotGap(filename, componentsMeta, source) {
185
185
  (meta) => meta.slots.length === 0 || meta.slots.some((slot) => !slot.description)
186
186
  ) ? !1 : /<slot[\s/>]/.test(source ?? "");
187
187
  }
188
- function mergeTemplateSlots(meta, slots) {
188
+ var NAME_DIRECTIVE = /(?:^|\s)(?::|v-bind:)name\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
189
+ function isDynamicSlotName(slot, source) {
190
+ if (!(slot.bindings?.some((binding) => binding.name === "name") ?? !1) || !source)
191
+ return !1;
192
+ let expression = slot.name.trim();
193
+ for (let match of source.matchAll(NAME_DIRECTIVE))
194
+ if ((match[1] ?? match[2] ?? "").trim() === expression)
195
+ return !0;
196
+ return !1;
197
+ }
198
+ var FOLDABLE_SLOT_NAME = /^\s*[\w$][\w$.]*\s*\?\?\s*(?:'([^']+)'|"([^"]+)")\s*$/;
199
+ function resolveTemplateSlotName(slot, isDynamic) {
200
+ if (!isDynamic)
201
+ return slot.name;
202
+ let fallback = slot.name.match(FOLDABLE_SLOT_NAME);
203
+ return fallback?.[1] || fallback?.[2];
204
+ }
205
+ function mergeTemplateSlots(meta, slots, source) {
189
206
  for (let slot of slots ?? []) {
190
- let existing = meta.slots.find((candidate) => candidate.name === slot.name);
207
+ let isDynamic = isDynamicSlotName(slot, source), slotName = resolveTemplateSlotName(slot, isDynamic);
208
+ if (!slotName)
209
+ continue;
210
+ let existing = meta.slots.find((candidate) => candidate.name === slotName);
191
211
  if (existing) {
192
212
  !existing.description && slot.description && (existing.description = slot.description);
193
213
  continue;
194
214
  }
195
- let bindings = (slot.bindings ?? []).filter((binding) => binding.name).map((binding) => `${binding.name}: ${binding.type?.name ?? "unknown"}`), type = bindings.length > 0 ? `{ ${bindings.join("; ")} }` : "{}";
215
+ let bindings = (slot.bindings ?? []).filter((binding) => binding.name && (!isDynamic || binding.name !== "name")).map((binding) => `${binding.name}: ${binding.type?.name ?? "unknown"}`), type = bindings.length > 0 ? `{ ${bindings.join("; ")} }` : "{}";
196
216
  meta.slots.push({
197
- name: slot.name,
217
+ name: slotName,
198
218
  description: slot.description ?? "",
199
219
  type,
200
220
  schema: type,
@@ -1,25 +1,29 @@
1
- import CJS_COMPAT_NODE_URL_o98lcndpw1r from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_o98lcndpw1r from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_o98lcndpw1r from "node:module";
1
+ import CJS_COMPAT_NODE_URL_6baiaphk7nk from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_6baiaphk7nk from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_6baiaphk7nk from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_o98lcndpw1r.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_o98lcndpw1r.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_o98lcndpw1r.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_6baiaphk7nk.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_6baiaphk7nk.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_6baiaphk7nk.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
13
  // src/docgen/shared/render-primitives.ts
14
- import { types as t } from "storybook/internal/babel";
15
14
  import {
16
15
  buildImportStatements,
16
+ isStringLiteral as isStringLiteral2,
17
17
  unwrapExpression as unwrapExpression2
18
18
  } from "storybook/internal/csf-tools";
19
19
 
20
20
  // src/docgen/shared/classify-value.ts
21
- import { recast } from "storybook/internal/babel";
22
- import { unwrapExpression } from "storybook/internal/csf-tools";
21
+ import {
22
+ textOf,
23
+ isStringLiteral,
24
+ unwrapExpression,
25
+ walk
26
+ } from "storybook/internal/csf-tools";
23
27
  var RESOLVABLE_GLOBALS = /* @__PURE__ */ new Set([
24
28
  "Array",
25
29
  "BigInt",
@@ -59,7 +63,27 @@ function classifyValue(node) {
59
63
  return isUndefinedIdentifier(value) ? { kind: "unset" } : isFunctionExpression(value) || isEmptyString(value) ? { kind: "omit" } : isInlineLiteral(value) ? { kind: "inline" } : isResolvable(value) ? { kind: "hoist" } : { kind: "unrepresentable" };
60
64
  }
61
65
  function printValue(node) {
62
- return recast.print(node, { tabWidth: 2 }).code;
66
+ let source = textOf(node), lines = source.split(`
67
+ `);
68
+ if (lines.length === 1)
69
+ return source;
70
+ let { start } = node, quasis = [];
71
+ walk(node, (child) => {
72
+ if (child.type === "TemplateElement") {
73
+ let span = child;
74
+ quasis.push([span.start - start, span.end - start]);
75
+ }
76
+ });
77
+ let offset = 0, dedentable = lines.map((line, index) => {
78
+ let lineStart = offset;
79
+ return offset += line.length + 1, index > 0 && !quasis.some(([from, to]) => from < lineStart && lineStart <= to);
80
+ }), depth = Math.min(
81
+ ...lines.filter((line, index) => dedentable[index] && line.trim() !== "").map((line) => line.search(/\S/))
82
+ );
83
+ return Number.isFinite(depth) && depth > 0 ? lines.map(
84
+ (line, index) => dedentable[index] ? line.slice(Math.min(depth, line.search(/\S|$/))) : line
85
+ ).join(`
86
+ `) : source;
63
87
  }
64
88
  function isFunctionExpression(node) {
65
89
  let unwrapped = unwrapExpression(node);
@@ -74,7 +98,7 @@ function isSelfContainedFunction(node) {
74
98
  if (fn.type !== "ArrowFunctionExpression" && fn.type !== "FunctionExpression")
75
99
  return !1;
76
100
  let locals = /* @__PURE__ */ new Set();
77
- return fn.params.every((param) => collectPatternNames(param, locals)) ? fn.body.type !== "BlockStatement" ? isResolvable(fn.body, locals) : fn.body.body.every((statement) => statementIsResolvable(statement, locals)) : !1;
101
+ return !fn.params.every((param) => collectPatternNames(param, locals)) || !fn.body ? !1 : fn.body.type !== "BlockStatement" ? isResolvable(fn.body, locals) : fn.body.body.every((statement) => statementIsResolvable(statement, locals));
78
102
  }
79
103
  function statementIsResolvable(statement, locals) {
80
104
  switch (statement.type) {
@@ -110,17 +134,13 @@ function collectPatternNames(pattern, into) {
110
134
  }
111
135
  function isEmptyString(node) {
112
136
  let value = unwrapExpression(node);
113
- return value.type === "StringLiteral" && value.value === "";
137
+ return isStringLiteral(value) && value.value === "";
114
138
  }
115
139
  function isInlineLiteral(node) {
116
140
  let value = unwrapExpression(node);
117
141
  switch (value.type) {
118
- case "StringLiteral":
119
- case "NumericLiteral":
120
- case "BooleanLiteral":
121
- case "NullLiteral":
122
- case "BigIntLiteral":
123
- return !0;
142
+ case "Literal":
143
+ return !("regex" in value && value.regex);
124
144
  case "UnaryExpression":
125
145
  return value.operator === "-" && isInlineLiteral(value.argument);
126
146
  default:
@@ -130,12 +150,7 @@ function isInlineLiteral(node) {
130
150
  function isResolvable(node, locals = NO_LOCALS) {
131
151
  let value = unwrapExpression(node), resolves = (child) => isResolvable(child, locals);
132
152
  switch (value.type) {
133
- case "StringLiteral":
134
- case "NumericLiteral":
135
- case "BooleanLiteral":
136
- case "NullLiteral":
137
- case "BigIntLiteral":
138
- case "RegExpLiteral":
153
+ case "Literal":
139
154
  return !0;
140
155
  case "Identifier":
141
156
  return locals.has(value.name) || RESOLVABLE_GLOBALS.has(value.name);
@@ -144,7 +159,7 @@ function isResolvable(node, locals = NO_LOCALS) {
144
159
  case "ArrayExpression":
145
160
  return value.elements.every((element) => !element || resolves(element));
146
161
  case "ObjectExpression":
147
- return value.properties.every((property) => property.type !== "ObjectProperty" ? !1 : (!property.computed || resolves(property.key)) && resolves(property.value));
162
+ return value.properties.every((property) => property.type !== "Property" || property.method || property.kind !== "init" ? !1 : (!property.computed || resolves(property.key)) && resolves(property.value));
148
163
  case "CallExpression":
149
164
  case "NewExpression":
150
165
  return resolves(value.callee) && value.arguments.every(resolves);
@@ -198,7 +213,7 @@ function renderPropArg(arg, ctx) {
198
213
  }
199
214
  function renderPropValue(input, ctx) {
200
215
  let value = unwrapExpression2(input.value);
201
- return input.plan.kind === "hoist" ? hoistedProp(input, ctx, printValue(value)) : value.type === "BooleanLiteral" ? value.value ? { attrName: input.attributeName } : { attrName: `:${input.attributeName}`, value: "false" } : value.type === "StringLiteral" ? quoteAttributeValue(value.value) === void 0 ? hoistedProp(input, ctx, printValue(value)) : { attrName: input.attributeName, value: value.value } : { attrName: `:${input.attributeName}`, value: printValue(value) };
216
+ return input.plan.kind === "hoist" ? hoistedProp(input, ctx, printValue(value)) : value.type === "Literal" && typeof value.value == "boolean" ? value.value ? { attrName: input.attributeName } : { attrName: `:${input.attributeName}`, value: "false" } : isStringLiteral2(value) ? quoteAttributeValue(value.value) === void 0 ? hoistedProp(input, ctx, printValue(value)) : { attrName: input.attributeName, value: value.value } : { attrName: `:${input.attributeName}`, value: printValue(value) };
202
217
  }
203
218
  function hoistedProp(input, ctx, source) {
204
219
  let existing = ctx.hoistedArgs.get(input.variableName);
@@ -229,15 +244,8 @@ function renderSlotContent(arg, plan, ctx) {
229
244
  }
230
245
  function inlinePrimitiveSource(node) {
231
246
  let value = unwrapExpression2(node);
232
- switch (value.type) {
233
- case "StringLiteral":
234
- return value.value;
235
- case "NumericLiteral":
236
- case "BooleanLiteral":
237
- return String(value.value);
238
- default:
239
- return;
240
- }
247
+ if (value.type === "Literal")
248
+ return typeof value.value == "string" ? value.value : typeof value.value == "number" || typeof value.value == "boolean" ? String(value.value) : void 0;
241
249
  }
242
250
  function escapeTextContent(text) {
243
251
  return text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("{{", "&#123;&#123;");
@@ -256,11 +264,18 @@ ${sections.join(`
256
264
  </script>`;
257
265
  }
258
266
  function allocateBindingName(name, ctx) {
259
- let baseName = t.toIdentifier(name), bindingName = baseName, suffix = 2;
267
+ let baseName = toIdentifier(name), bindingName = baseName, suffix = 2;
260
268
  for (; ctx.bindings.has(bindingName); )
261
269
  bindingName = `${baseName}${suffix}`, suffix += 1;
262
270
  return ctx.bindings.add(bindingName), bindingName;
263
271
  }
272
+ var RESERVED_WORDS = new Set(
273
+ "break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with implements interface let package private protected public static yield await arguments eval".split(" ")
274
+ );
275
+ function toIdentifier(input) {
276
+ let name = [...input].map((char) => /[\p{ID_Continue}$\u200C\u200D]/u.test(char) ? char : "-").join("").replace(/^[-0-9]+/, "").replace(/[-\s]+(.)?/g, (_, next) => next ? next.toUpperCase() : "");
277
+ return name && !RESERVED_WORDS.has(name) ? name : `_${name}`;
278
+ }
264
279
  function quoteAttributeValue(value) {
265
280
  if (!value.includes("&")) {
266
281
  if (!value.includes('"'))
@@ -1,17 +1,17 @@
1
- import CJS_COMPAT_NODE_URL_o98lcndpw1r from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_o98lcndpw1r from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_o98lcndpw1r from "node:module";
1
+ import CJS_COMPAT_NODE_URL_6baiaphk7nk from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_6baiaphk7nk from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_6baiaphk7nk from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_o98lcndpw1r.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_o98lcndpw1r.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_o98lcndpw1r.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_6baiaphk7nk.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_6baiaphk7nk.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_6baiaphk7nk.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
  import {
13
13
  indent
14
- } from "./chunk-MD3CZS6R.js";
14
+ } from "./chunk-KQTNCEDF.js";
15
15
 
16
16
  // src/docgen/component-docgen/arg-types/extractArgTypes.ts
17
17
  import { convert, extractComponentProps, hasDocgen } from "storybook/internal/docs-tools";