histoire 0.7.1 → 0.7.4

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.
Files changed (118) hide show
  1. package/client.d.ts +1 -1
  2. package/dist/bundled/MobileOverlay.js +2 -2
  3. package/dist/bundled/StoryView.js +22 -19
  4. package/dist/bundled/dark.js +4 -0
  5. package/dist/bundled/index.js +0 -1
  6. package/dist/bundled/index2.js +6 -6
  7. package/dist/bundled/mapping.js +78 -0
  8. package/dist/bundled/sandbox.js +7 -6
  9. package/dist/bundled/state.js +13 -44
  10. package/dist/bundled/style.css +17 -17
  11. package/dist/client/app/App.vue +2 -2
  12. package/dist/client/app/components/base/BaseSplitPane.vue +6 -6
  13. package/dist/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
  14. package/dist/client/app/components/panel/ControlsComponentProps.vue +2 -1
  15. package/dist/client/app/components/panel/StatePresets.vue +2 -1
  16. package/dist/client/app/components/panel/StoryControls.vue +1 -1
  17. package/dist/client/app/components/panel/StorySourceCode.vue +2 -2
  18. package/dist/client/app/components/story/StoryVariantGridItem.vue +1 -1
  19. package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
  20. package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
  21. package/dist/client/app/components/story/StoryVariantSingleView.vue +1 -1
  22. package/dist/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
  23. package/dist/client/app/components/tree/StoryGroup.vue +1 -1
  24. package/dist/client/app/index.js +0 -2
  25. package/dist/client/app/sandbox.js +4 -5
  26. package/dist/client/app/style/main.pcss +3 -3
  27. package/dist/client/app/style/sandbox.css +1 -1
  28. package/dist/client/app/types.d.ts +1 -52
  29. package/dist/client/app/util/mapping.d.ts +1 -1
  30. package/dist/client/app/util/mapping.js +50 -36
  31. package/dist/client/app/{components/sandbox/lib.d.ts → util/sandbox.d.ts} +1 -1
  32. package/dist/client/app/{components/sandbox/lib.js → util/sandbox.js} +1 -1
  33. package/dist/client/app/util/state.d.ts +1 -5
  34. package/dist/client/app/util/state.js +12 -44
  35. package/dist/node/collect/index.d.ts +2 -2
  36. package/dist/node/collect/index.js +3 -0
  37. package/dist/node/collect/run.d.ts +2 -0
  38. package/dist/{client/server/index.js → node/collect/run.js} +1 -1
  39. package/dist/node/collect/worker.d.ts +3 -3
  40. package/dist/node/collect/worker.js +4 -1
  41. package/dist/node/config.d.ts +3 -3
  42. package/dist/node/context.d.ts +2 -2
  43. package/dist/node/plugin.d.ts +3 -3
  44. package/dist/node/stories.d.ts +4 -4
  45. package/dist/node/tree.d.ts +3 -22
  46. package/dist/style.css +80 -4
  47. package/package.json +4 -2
  48. package/src/client/app/App.vue +2 -2
  49. package/src/client/app/components/base/BaseSplitPane.vue +6 -6
  50. package/src/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
  51. package/src/client/app/components/panel/ControlsComponentProps.vue +2 -1
  52. package/src/client/app/components/panel/StatePresets.vue +2 -1
  53. package/src/client/app/components/panel/StoryControls.vue +1 -1
  54. package/src/client/app/components/panel/StorySourceCode.vue +2 -2
  55. package/src/client/app/components/story/StoryVariantGridItem.vue +1 -1
  56. package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
  57. package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
  58. package/src/client/app/components/story/StoryVariantSingleView.vue +1 -1
  59. package/src/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
  60. package/src/client/app/components/tree/StoryGroup.vue +1 -1
  61. package/src/client/app/index.ts +0 -2
  62. package/src/client/app/sandbox.ts +4 -5
  63. package/src/client/app/style/main.pcss +3 -3
  64. package/src/client/app/style/sandbox.css +1 -1
  65. package/src/client/app/types.ts +6 -57
  66. package/src/client/app/util/mapping.ts +47 -34
  67. package/src/client/app/{components/sandbox/lib.ts → util/sandbox.ts} +2 -2
  68. package/src/client/app/util/state.ts +15 -44
  69. package/src/node/collect/index.ts +5 -2
  70. package/src/node/collect/run.ts +13 -0
  71. package/src/node/collect/worker.ts +8 -6
  72. package/src/node/config.ts +3 -3
  73. package/src/node/context.ts +2 -2
  74. package/src/node/plugin.ts +2 -2
  75. package/src/node/server.ts +2 -2
  76. package/src/node/stories.ts +4 -4
  77. package/src/node/tree.ts +7 -31
  78. package/tailwind.config.cjs +1 -1
  79. package/vite.config.ts +12 -7
  80. package/dist/bundled/SandboxVue3.js +0 -706
  81. package/dist/bundled/global-components.js +0 -213
  82. package/dist/client/app/codegen/const.d.ts +0 -1
  83. package/dist/client/app/codegen/const.js +0 -3
  84. package/dist/client/app/codegen/serialize-js.d.ts +0 -1
  85. package/dist/client/app/codegen/serialize-js.js +0 -113
  86. package/dist/client/app/codegen/util.d.ts +0 -10
  87. package/dist/client/app/codegen/util.js +0 -70
  88. package/dist/client/app/codegen/vue3.d.ts +0 -4
  89. package/dist/client/app/codegen/vue3.js +0 -357
  90. package/dist/client/app/components/exposed/Story.vue +0 -106
  91. package/dist/client/app/components/exposed/Variant.vue +0 -78
  92. package/dist/client/app/components/sandbox/RouterLinkStub.d.ts +0 -21
  93. package/dist/client/app/components/sandbox/RouterLinkStub.js +0 -43
  94. package/dist/client/app/components/sandbox/SandboxVue3.vue +0 -185
  95. package/dist/client/app/global-components.d.ts +0 -2
  96. package/dist/client/app/global-components.js +0 -10
  97. package/dist/client/server/index.d.ts +0 -7
  98. package/dist/client/server/vue3/Story.vue +0 -120
  99. package/dist/client/server/vue3/Variant.vue +0 -52
  100. package/dist/client/server/vue3/run.d.ts +0 -2
  101. package/dist/client/server/vue3/run.js +0 -45
  102. package/dist/node/types.d.ts +0 -50
  103. package/dist/node/types.js +0 -1
  104. package/src/client/app/codegen/const.ts +0 -3
  105. package/src/client/app/codegen/serialize-js.ts +0 -119
  106. package/src/client/app/codegen/util.ts +0 -79
  107. package/src/client/app/codegen/vue3.ts +0 -361
  108. package/src/client/app/components/exposed/Story.vue +0 -106
  109. package/src/client/app/components/exposed/Variant.vue +0 -78
  110. package/src/client/app/components/sandbox/RouterLinkStub.ts +0 -49
  111. package/src/client/app/components/sandbox/SandboxVue3.vue +0 -185
  112. package/src/client/app/global-components.ts +0 -13
  113. package/src/client/server/index.ts +0 -19
  114. package/src/client/server/vue3/Story.vue +0 -120
  115. package/src/client/server/vue3/Variant.vue +0 -52
  116. package/src/client/server/vue3/run.ts +0 -55
  117. package/src/components.d.ts +0 -143
  118. package/src/node/types.ts +0 -53
@@ -1,706 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- import { Text, vModelText, vModelSelect, vModelRadio, vModelCheckbox, vModelDynamic, defineComponent, computed, h, ref, createApp, onMounted, watch, onUnmounted, openBlock, createElementBlock } from "vue";
18
- import { pascal } from "case";
19
- import { a as applyStateToVariant } from "./state.js";
20
- import * as setup from "$histoire-setup";
21
- import * as generatedSetup from "$histoire-generated-global-setup";
22
- function indent(lines, count = 1) {
23
- return lines.map((line) => `${" ".repeat(count)}${line}`);
24
- }
25
- function unindent(code) {
26
- const lines = code.split("\n");
27
- let indentLevel = -1;
28
- let indentText;
29
- const linesToAnalyze = lines.filter((line) => line.trim().length > 0);
30
- for (const line of linesToAnalyze) {
31
- const match = /^\s*/.exec(line);
32
- if (match && (indentLevel === -1 || indentLevel > match[0].length)) {
33
- indentLevel = match[0].length;
34
- indentText = match[0];
35
- }
36
- }
37
- const result = [];
38
- for (const line of lines) {
39
- result.push(line.replace(indentText, ""));
40
- }
41
- return result.join("\n").trim();
42
- }
43
- function createAutoBuildingObject(format, specialKeysHandler, key = "", depth = 0) {
44
- const cache = {};
45
- if (depth > 32)
46
- return { key, cache, target: {}, proxy: () => key };
47
- const target = () => {
48
- const k = key + "()";
49
- return format ? format(k) : k;
50
- };
51
- const proxy = new Proxy(target, {
52
- get(_, p) {
53
- if (p === "__autoBuildingObject") {
54
- return true;
55
- }
56
- if (p === "__autoBuildingObjectGetKey") {
57
- return key;
58
- }
59
- if (specialKeysHandler) {
60
- const fn = specialKeysHandler(target, p);
61
- if (fn) {
62
- return fn();
63
- }
64
- }
65
- if (p === "toString") {
66
- const k = key + ".toString()";
67
- return () => format ? format(k) : k;
68
- }
69
- if (p === Symbol.toPrimitive) {
70
- return () => format ? format(key) : key;
71
- }
72
- if (!cache[p]) {
73
- const childKey = key ? `${key}.${p.toString()}` : p.toString();
74
- const child = createAutoBuildingObject(format, specialKeysHandler, childKey, depth + 1);
75
- cache[p] = __spreadValues({ key: childKey }, child);
76
- }
77
- return cache[p].proxy;
78
- },
79
- apply(_, thisArg, args) {
80
- const k = `${key}(${args.join(", ")})`;
81
- return format ? format(k) : k;
82
- }
83
- });
84
- return {
85
- key,
86
- cache,
87
- target,
88
- proxy
89
- };
90
- }
91
- const KEY_ESCAPE_REG = /[\s-.:|#@$£*%]/;
92
- const MAX_SINGLE_LINE_ARRAY_LENGTH = 3;
93
- function serializeJs(value) {
94
- if (value === void 0) {
95
- return "undefined";
96
- }
97
- if (value === null) {
98
- return "null";
99
- }
100
- if (typeof value === "string") {
101
- return `'${value}'`;
102
- }
103
- if (typeof value === "boolean") {
104
- return value ? "true" : "false";
105
- }
106
- if (Array.isArray(value)) {
107
- return printLines(arrayToSourceLines(value));
108
- }
109
- if (typeof value === "object") {
110
- return printLines(objectToSourceLines(value));
111
- }
112
- if (value == null ? void 0 : value.__autoBuildingObject) {
113
- return value;
114
- }
115
- if (typeof value === "function" && value.name) {
116
- return value.name;
117
- }
118
- return value.toString();
119
- }
120
- function printLines(lines) {
121
- return lines.map((line) => " ".repeat(line.spaces) + line.line).join("\n");
122
- }
123
- function objectToSourceLines(object, indentCount = 0) {
124
- return createLines(indentCount, (lines) => {
125
- lines.push("{");
126
- lines.push(...createLines(1, (lines2) => {
127
- for (const key in object) {
128
- const value = object[key];
129
- let printedKey = key;
130
- if (KEY_ESCAPE_REG.test(key)) {
131
- printedKey = `'${printedKey}'`;
132
- }
133
- addLinesFromValue(lines2, value, `${printedKey}: `, ",");
134
- }
135
- }));
136
- lines.push("}");
137
- });
138
- }
139
- function arrayToSourceLines(array, indentCount = 0) {
140
- return createLines(indentCount, (lines) => {
141
- const contentLines = createLines(1, (lines2) => {
142
- for (const value of array) {
143
- addLinesFromValue(lines2, value, "", ",");
144
- }
145
- });
146
- if (contentLines.length === 0) {
147
- lines.push("[]");
148
- } else if (contentLines.length <= MAX_SINGLE_LINE_ARRAY_LENGTH && !contentLines.some((line) => line.spaces > 1)) {
149
- const [first] = contentLines;
150
- first.line = contentLines.map(({ line }) => line.substring(0, line.length - 1)).join(", ");
151
- first.line = `[${first.line}]`;
152
- first.spaces--;
153
- lines.push(first);
154
- } else {
155
- lines.push("[", ...contentLines, "]");
156
- }
157
- });
158
- }
159
- function createLines(indentCount, handler) {
160
- const lines = [];
161
- handler(lines);
162
- return lines.map((line) => {
163
- if (line.spaces != null) {
164
- line.spaces += indentCount;
165
- return line;
166
- }
167
- return { spaces: indentCount, line };
168
- });
169
- }
170
- function addLinesFromValue(lines, value, before, after) {
171
- let result;
172
- if (Array.isArray(value)) {
173
- lines.push(...wrap(arrayToSourceLines(value), before, after));
174
- return;
175
- } else if (value && typeof value === "object") {
176
- lines.push(...wrap(objectToSourceLines(value), before, after));
177
- return;
178
- } else if (typeof value === "string") {
179
- result = value.includes("'") ? `\`${value}\`` : `'${value}'`;
180
- } else if (typeof value === "undefined") {
181
- result = "undefined";
182
- } else if (value === null) {
183
- result = "null";
184
- } else if (typeof value === "boolean") {
185
- result = value ? "true" : "false";
186
- } else {
187
- result = value;
188
- }
189
- lines.push(before + result + after);
190
- }
191
- function wrap(lines, before, after) {
192
- lines[0].line = before + lines[0].line;
193
- lines[lines.length - 1].line += after;
194
- return lines;
195
- }
196
- const voidElements = [
197
- "area",
198
- "base",
199
- "br",
200
- "col",
201
- "embed",
202
- "hr",
203
- "img",
204
- "input",
205
- "keygen",
206
- "link",
207
- "meta",
208
- "param",
209
- "source",
210
- "track",
211
- "wbr"
212
- ];
213
- async function generateSourceCode(variant) {
214
- var _a, _b, _c, _d, _e, _f;
215
- const vnode = (_d = (_c = (_b = variant.slots()).default) == null ? void 0 : _c.call(_b, { state: (_a = variant.state) != null ? _a : {} })) != null ? _d : [];
216
- const list = Array.isArray(vnode) ? vnode : [vnode];
217
- const lines = [];
218
- for (const n in list) {
219
- const vnode2 = list[n];
220
- lines.push(...(await printVNode(vnode2, (_f = (_e = variant.state) == null ? void 0 : _e._hPropState) == null ? void 0 : _f[n])).lines);
221
- }
222
- return lines.join("\n");
223
- }
224
- async function printVNode(vnode, propsOverrides = null) {
225
- var _a, _b, _c;
226
- if (vnode.type === Text) {
227
- return {
228
- lines: [vnode.children],
229
- isText: true
230
- };
231
- }
232
- const lines = [];
233
- if (typeof vnode.type === "object" || typeof vnode.type === "string") {
234
- let genDirective = function(dirName, dir, valueCode = null) {
235
- var _a2;
236
- let modifiers = "";
237
- for (const key in dir.modifiers) {
238
- if (dir.modifiers[key]) {
239
- modifiers += `.${key}`;
240
- }
241
- }
242
- let arg = "";
243
- if (dir.arg) {
244
- arg = `:${dir.arg}`;
245
- }
246
- if (valueCode) {
247
- valueCode = valueCode.replace(/^\$(setup|props|data)\./g, "");
248
- }
249
- const valueLines = valueCode ? [valueCode] : serializeAndCleanJs(dir.value);
250
- const attr = [];
251
- const dirAttr = `v-${dirName}${arg}${modifiers}="`;
252
- if (valueLines.length > 1) {
253
- attr.push(`${dirAttr}${valueLines[0]}`);
254
- attr.push(...valueLines.slice(1, valueLines.length - 1));
255
- attr.push(`${valueLines[valueLines.length - 1]}"`);
256
- multilineAttrs = true;
257
- } else {
258
- attr.push(`${dirAttr}${(_a2 = valueLines[0]) != null ? _a2 : ""}"`);
259
- }
260
- attrs.push(attr);
261
- }, addAttr = function(prop, value) {
262
- var _a2, _b2, _c2;
263
- if (typeof value !== "string" || ((_a2 = vnode.dynamicProps) == null ? void 0 : _a2.includes(prop))) {
264
- let directive = ":";
265
- if (prop.startsWith("on")) {
266
- directive = "@";
267
- }
268
- const arg = directive === "@" ? `${prop[2].toLowerCase()}${prop.slice(3)}` : prop;
269
- const vmodelListener = `onUpdate:${prop}`;
270
- if (directive === ":" && ((_b2 = vnode.dynamicProps) == null ? void 0 : _b2.includes(vmodelListener))) {
271
- skipProps.push(vmodelListener);
272
- const listener = vnode.props[vmodelListener];
273
- const listenerSource = listener.toString();
274
- let valueCode;
275
- const result = /\(\$event\) => (.*?) = \$event/.exec(listenerSource);
276
- if (result) {
277
- valueCode = result[1];
278
- }
279
- const modifiersKey = `${prop === "modelValue" ? "model" : prop}Modifiers`;
280
- const modifiers = (_c2 = vnode.props[modifiersKey]) != null ? _c2 : {};
281
- skipProps.push(modifiersKey);
282
- genDirective("model", {
283
- arg: prop === "modelValue" ? null : prop,
284
- modifiers,
285
- value
286
- }, valueCode);
287
- return;
288
- }
289
- let serialized;
290
- if (typeof value === "string" && value.startsWith("{{") && value.endsWith("}}")) {
291
- serialized = cleanupExpression(value.substring(2, value.length - 2).trim()).split("\n");
292
- } else if (typeof value === "function") {
293
- let code = cleanupExpression(value.toString().replace(/'/g, "\\'").replace(/"/g, "'"));
294
- const testResult = /function ([^\s]+)\(/.exec(code);
295
- if (testResult) {
296
- serialized = [testResult[1]];
297
- } else {
298
- if (code.startsWith("($event) => ")) {
299
- code = code.substring("($event) => ".length);
300
- }
301
- serialized = code.split("\n");
302
- }
303
- } else {
304
- serialized = serializeAndCleanJs(value);
305
- }
306
- if (serialized.length > 1) {
307
- multilineAttrs = true;
308
- const indented = [`${directive}${arg}="${serialized[0]}`];
309
- indented.push(...serialized.slice(1, serialized.length - 1));
310
- indented.push(`${serialized[serialized.length - 1]}"`);
311
- attrs.push(indented);
312
- } else {
313
- attrs.push([`${directive}${arg}="${serialized[0]}"`]);
314
- }
315
- } else {
316
- attrs.push([`${prop}="${value}"`]);
317
- }
318
- };
319
- if (((_a = vnode.type) == null ? void 0 : _a.__asyncLoader) && !vnode.type.__asyncResolved) {
320
- await vnode.type.__asyncLoader();
321
- }
322
- const attrs = [];
323
- let multilineAttrs = false;
324
- const skipProps = [
325
- "key"
326
- ];
327
- if (vnode.dirs) {
328
- for (const dir of vnode.dirs) {
329
- if (dir.dir === vModelText || dir.dir === vModelSelect || dir.dir === vModelRadio || dir.dir === vModelCheckbox || dir.dir === vModelDynamic) {
330
- const listenerKey = `onUpdate:${(_b = dir.arg) != null ? _b : "modelValue"}`;
331
- const listener = vnode.props[listenerKey];
332
- let valueCode = null;
333
- if (listener) {
334
- skipProps.push(listenerKey);
335
- const listenerSource = listener.toString();
336
- const result = /\(\$event\) => (.*?) = \$event/.exec(listenerSource);
337
- if (result) {
338
- valueCode = result[1];
339
- }
340
- }
341
- genDirective("model", dir, valueCode);
342
- } else if (dir.instance._ || dir.instance.$) {
343
- const target = (_c = dir.instance.$) != null ? _c : dir.instance._;
344
- let dirName;
345
- for (const directives of [target.directives, target.appContext.directives]) {
346
- for (const key in directives) {
347
- if (target.directives[key] === dir.dir) {
348
- dirName = key;
349
- break;
350
- }
351
- }
352
- if (dirName)
353
- break;
354
- }
355
- if (dirName) {
356
- genDirective(dirName, dir);
357
- }
358
- }
359
- }
360
- }
361
- for (const prop in vnode.props) {
362
- if (skipProps.includes(prop) || propsOverrides && prop in propsOverrides) {
363
- continue;
364
- }
365
- const value = vnode.props[prop];
366
- addAttr(prop, value);
367
- }
368
- if (propsOverrides) {
369
- for (const prop in propsOverrides) {
370
- addAttr(prop, propsOverrides[prop]);
371
- }
372
- }
373
- if (attrs.length > 1) {
374
- multilineAttrs = true;
375
- }
376
- const tagName = getTagName(vnode);
377
- let isChildText = false;
378
- const childLines = [];
379
- if (typeof vnode.children === "string") {
380
- if (tagName === "pre") {
381
- childLines.push(vnode.children);
382
- } else {
383
- childLines.push(...vnode.children.split("\n"));
384
- }
385
- isChildText = true;
386
- } else if (Array.isArray(vnode.children)) {
387
- let isAllChildText;
388
- for (const child of vnode.children) {
389
- const result = await printVNode(child);
390
- if (result.isText) {
391
- if (isAllChildText === void 0) {
392
- isAllChildText = true;
393
- }
394
- const text = result.lines[0];
395
- if (!childLines.length || /^\s/.test(text)) {
396
- childLines.push(text.trim());
397
- } else {
398
- childLines[childLines.length - 1] += text;
399
- }
400
- } else {
401
- if (isAllChildText === void 0) {
402
- isAllChildText = false;
403
- }
404
- childLines.push(...result.lines);
405
- }
406
- }
407
- if (isAllChildText !== void 0) {
408
- isChildText = isAllChildText;
409
- }
410
- }
411
- if (vnode.children && typeof vnode.children === "object" && !Array.isArray(vnode.children)) {
412
- for (const key in vnode.children) {
413
- if (typeof vnode.children[key] === "function") {
414
- const autoObject = createAutoBuildingObject((key2) => `{{ ${key2} }}`, (target, p) => {
415
- if (p === "__v_isRef") {
416
- return () => false;
417
- }
418
- });
419
- const children = vnode.children[key](autoObject.proxy);
420
- const slotLines = [];
421
- for (const child of children) {
422
- slotLines.push(...(await printVNode(child)).lines);
423
- }
424
- const slotProps = Object.keys(autoObject.cache);
425
- if (slotProps.length) {
426
- childLines.push(`<template #${key}="{ ${slotProps.join(", ")} }">`);
427
- childLines.push(...indent(slotLines));
428
- childLines.push("</template>");
429
- } else if (key === "default") {
430
- childLines.push(...slotLines);
431
- } else {
432
- childLines.push(`<template #${key}>`);
433
- childLines.push(...indent(slotLines));
434
- childLines.push(`</template>`);
435
- }
436
- }
437
- }
438
- }
439
- const tag = [`<${tagName}`];
440
- if (multilineAttrs) {
441
- for (const attrLines of attrs) {
442
- tag.push(...indent(attrLines));
443
- }
444
- if (childLines.length > 0) {
445
- tag.push(">");
446
- }
447
- } else {
448
- if (attrs.length === 1) {
449
- tag[0] += ` ${attrs[0]}`;
450
- }
451
- if (childLines.length > 0) {
452
- tag[0] += ">";
453
- }
454
- }
455
- const isVoid = voidElements.includes(tagName.toLowerCase());
456
- if (childLines.length > 0) {
457
- if (childLines.length === 1 && tag.length === 1 && !attrs.length && isChildText) {
458
- lines.push(`${tag[0]}${childLines[0]}</${tagName}>`);
459
- } else {
460
- lines.push(...tag);
461
- lines.push(...indent(childLines));
462
- lines.push(`</${tagName}>`);
463
- }
464
- } else if (tag.length > 1) {
465
- lines.push(...tag);
466
- lines.push(isVoid ? ">" : "/>");
467
- } else {
468
- lines.push(`${tag[0]}${isVoid ? "" : " /"}>`);
469
- }
470
- } else if ((vnode == null ? void 0 : vnode.shapeFlag) & 1 << 4) {
471
- for (const child of vnode.children) {
472
- lines.push(...(await printVNode(child)).lines);
473
- }
474
- }
475
- return {
476
- lines
477
- };
478
- }
479
- function getTagName(vnode) {
480
- var _a, _b, _c, _d, _e;
481
- if (typeof vnode.type === "string") {
482
- return vnode.type;
483
- } else if ((_a = vnode.type) == null ? void 0 : _a.__asyncResolved) {
484
- const asyncComp = (_b = vnode.type) == null ? void 0 : _b.__asyncResolved;
485
- return (_c = asyncComp.name) != null ? _c : getNameFromFile(asyncComp.__file);
486
- } else if ((_d = vnode.type) == null ? void 0 : _d.name) {
487
- return vnode.type.name;
488
- } else if ((_e = vnode.type) == null ? void 0 : _e.__file) {
489
- return getNameFromFile(vnode.type.__file);
490
- }
491
- return "Anonymous";
492
- }
493
- function getNameFromFile(file) {
494
- const parts = /([^/]+)\.vue$/.exec(file);
495
- if (parts) {
496
- return pascal(parts[1]);
497
- }
498
- return "Anonymous";
499
- }
500
- function serializeAndCleanJs(value) {
501
- const isAutoBuildingObject = !!(value == null ? void 0 : value.__autoBuildingObject);
502
- const result = serializeJs(value);
503
- if (isAutoBuildingObject) {
504
- return [cleanupExpression(result.__autoBuildingObjectGetKey)];
505
- } else {
506
- return cleanupExpression(result).split("\n");
507
- }
508
- }
509
- function cleanupExpression(expr) {
510
- return expr.replace(/\$setup\./g, "");
511
- }
512
- const defaultRoute = {
513
- path: "/",
514
- name: void 0,
515
- redirectedFrom: void 0,
516
- params: {},
517
- query: {},
518
- hash: "",
519
- fullPath: "/",
520
- matched: [],
521
- meta: {},
522
- href: "/"
523
- };
524
- const RouterLinkStub = defineComponent({
525
- name: "RouterLinkStub",
526
- compatConfig: { MODE: 3 },
527
- props: {
528
- to: {
529
- type: [String, Object],
530
- required: true
531
- },
532
- custom: {
533
- type: Boolean,
534
- default: false
535
- }
536
- },
537
- render() {
538
- var _a, _b;
539
- const route = computed(() => defaultRoute);
540
- const children = (_b = (_a = this.$slots) == null ? void 0 : _a.default) == null ? void 0 : _b.call(_a, {
541
- route,
542
- href: computed(() => route.value.href),
543
- isActive: computed(() => false),
544
- isExactActive: computed(() => false),
545
- navigate: async () => {
546
- }
547
- });
548
- return this.custom ? children : h("a", void 0, children);
549
- }
550
- });
551
- const _sfc_main = /* @__PURE__ */ defineComponent({
552
- name: "SandboxVue3",
553
- props: {
554
- variant: {
555
- type: Object,
556
- required: true
557
- },
558
- story: {
559
- type: Object,
560
- required: true
561
- },
562
- slotName: {
563
- type: String,
564
- default: "default"
565
- }
566
- },
567
- emits: {
568
- ready: () => true
569
- },
570
- setup(__props, { emit }) {
571
- const props = __props;
572
- const sandbox = ref();
573
- let app;
574
- let mounting = false;
575
- async function mountVariant() {
576
- mounting = true;
577
- await props.variant.initState();
578
- let lastPropsTypesSnapshot;
579
- app = createApp({
580
- name: "SandboxVue3",
581
- render: () => {
582
- var _a, _b, _c, _d, _e, _f, _g;
583
- const vnodes = (_g = (_c = (_a = props.variant.slots()) == null ? void 0 : _a[props.slotName]) == null ? void 0 : _c.call(_a, {
584
- state: (_b = props.variant.state) != null ? _b : {}
585
- })) != null ? _g : (_f = (_d = props.story.slots()) == null ? void 0 : _d[props.slotName]) == null ? void 0 : _f.call(_d, {
586
- state: (_e = props.variant.state) != null ? _e : {}
587
- });
588
- if (props.slotName === "default") {
589
- const propsTypes = vnodes.filter((vnode) => typeof vnode.type === "object").map((vnode, index) => {
590
- var _a2, _b2, _c2;
591
- const propDefs = [];
592
- for (const key in vnode.type.props) {
593
- const prop = vnode.type.props[key];
594
- let types;
595
- let defaultValue;
596
- if (prop) {
597
- const rawTypes = Array.isArray(prop.type) ? prop.type : [prop.type];
598
- types = rawTypes.map((t) => {
599
- switch (t) {
600
- case String:
601
- return "string";
602
- case Number:
603
- return "number";
604
- case Boolean:
605
- return "boolean";
606
- case Object:
607
- return "object";
608
- case Array:
609
- return "array";
610
- default:
611
- return "unknown";
612
- }
613
- });
614
- defaultValue = typeof prop.default === "function" ? prop.default.toString() : prop.default;
615
- }
616
- propDefs.push({
617
- name: key,
618
- types,
619
- required: prop == null ? void 0 : prop.required,
620
- default: defaultValue
621
- });
622
- if ((_c2 = (_b2 = (_a2 = props.variant.state) == null ? void 0 : _a2._hPropState) == null ? void 0 : _b2[index]) == null ? void 0 : _c2[key]) {
623
- if (!vnode.props) {
624
- vnode.props = {};
625
- }
626
- vnode.props[key] = props.variant.state._hPropState[index][key];
627
- if (!vnode.dynamicProps) {
628
- vnode.dynamicProps = [];
629
- }
630
- if (!vnode.dynamicProps.includes(key)) {
631
- vnode.dynamicProps.push(key);
632
- }
633
- }
634
- }
635
- return {
636
- name: getTagName(vnode),
637
- index,
638
- props: propDefs
639
- };
640
- }).filter((def) => def.props.length);
641
- const snapshot = JSON.stringify(propsTypes);
642
- if (!lastPropsTypesSnapshot || lastPropsTypesSnapshot !== snapshot) {
643
- applyStateToVariant(props.variant, {
644
- _hPropDefs: propsTypes
645
- });
646
- if (!props.variant.state._hPropState) {
647
- applyStateToVariant(props.variant, {
648
- _hPropState: {}
649
- });
650
- }
651
- lastPropsTypesSnapshot = snapshot;
652
- }
653
- }
654
- return vnodes;
655
- }
656
- });
657
- app.component("RouterLink", RouterLinkStub);
658
- if (typeof (generatedSetup == null ? void 0 : generatedSetup.setupVue3) === "function") {
659
- await generatedSetup.setupVue3({
660
- app,
661
- story: props.story,
662
- variant: props.variant
663
- });
664
- }
665
- if (typeof (setup == null ? void 0 : setup.setupVue3) === "function") {
666
- await setup.setupVue3({
667
- app,
668
- story: props.story,
669
- variant: props.variant
670
- });
671
- }
672
- if (typeof props.variant.setupApp === "function") {
673
- await props.variant.setupApp({
674
- app,
675
- story: props.story,
676
- variant: props.variant
677
- });
678
- }
679
- const target = document.createElement("div");
680
- sandbox.value.appendChild(target);
681
- app.mount(target);
682
- emit("ready");
683
- }
684
- onMounted(async () => {
685
- if (props.variant.initState) {
686
- await mountVariant();
687
- }
688
- });
689
- watch(() => props.variant.initState, (value) => {
690
- if (value && !mounting) {
691
- mountVariant();
692
- }
693
- });
694
- onUnmounted(() => {
695
- app == null ? void 0 : app.unmount();
696
- });
697
- return (_ctx, _cache) => {
698
- return openBlock(), createElementBlock("div", {
699
- ref_key: "sandbox",
700
- ref: sandbox,
701
- class: "__histoire-sandbox htw-overflow-auto"
702
- }, null, 512);
703
- };
704
- }
705
- });
706
- export { _sfc_main as _, generateSourceCode as g, unindent as u };