@poveste/plugin-vue 0.14.0 → 0.16.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.
Files changed (68) hide show
  1. package/README.md +2 -2
  2. package/components.d.ts +4 -0
  3. package/dist/bundled/client/app/MountStory.js +8 -3
  4. package/dist/bundled/client/app/RenderStory.js +15 -9
  5. package/dist/bundled/client/app/Story.js +76 -62
  6. package/dist/bundled/client/app/Variant.js +48 -42
  7. package/dist/bundled/client/app/context.js +5 -0
  8. package/dist/bundled/client/app/global-components.js +11 -10
  9. package/dist/bundled/client/app/host.js +2 -2
  10. package/dist/bundled/client/app/render-context.js +7 -7
  11. package/dist/bundled/client/app/util.js +36 -26
  12. package/dist/bundled/client/client.js +4 -4
  13. package/dist/bundled/client/codegen.js +79 -60
  14. package/dist/bundled/client/context.js +20 -0
  15. package/dist/bundled/client/server/Story.js +28 -25
  16. package/dist/bundled/client/server/Variant.js +13 -16
  17. package/dist/bundled/client/server/context.js +5 -0
  18. package/dist/bundled/client/server/run.js +29 -29
  19. package/dist/client/app/MountStory.d.ts +12 -3
  20. package/dist/client/app/RenderStory.d.ts +1 -1
  21. package/dist/client/app/Story.d.ts +10 -7
  22. package/dist/client/app/Variant.d.ts +14 -13
  23. package/dist/client/app/context.d.ts +9 -0
  24. package/dist/client/app/render-context.d.ts +16 -1
  25. package/dist/client/app/util.d.ts +38 -3
  26. package/dist/client/codegen.d.ts +29 -0
  27. package/dist/client/context.d.ts +40 -0
  28. package/dist/client/server/Story.d.ts +17 -17
  29. package/dist/client/server/Variant.d.ts +10 -10
  30. package/dist/client/server/context.d.ts +7 -0
  31. package/dist/commands/generate-story.client.js +4 -4
  32. package/dist/commands/generate-story.server.js +2 -2
  33. package/dist/helpers.d.ts +2 -2
  34. package/dist/index.node.js +2 -0
  35. package/dist/util/list-components.d.ts +1 -1
  36. package/dist/util/list-components.js +63 -6
  37. package/dist/util/list-components.spec.d.ts +1 -0
  38. package/dist/util/list-components.spec.js +46 -0
  39. package/package.json +17 -16
  40. package/src/client/__tests__/codegen-attrs.spec.ts +149 -0
  41. package/src/client/__tests__/context.spec.ts +50 -0
  42. package/src/client/app/MountStory.ts +11 -1
  43. package/src/client/app/RenderStory.ts +6 -1
  44. package/src/client/app/RouterLinkStub.ts +1 -1
  45. package/src/client/app/Story.ts +85 -39
  46. package/src/client/app/Variant.ts +35 -27
  47. package/src/client/app/__tests__/preview-variants.spec.ts +76 -0
  48. package/src/client/app/__tests__/state-sync.spec.ts +113 -2
  49. package/src/client/app/__tests__/writable-binding.spec.ts +39 -0
  50. package/src/client/app/auto-props.ts +2 -2
  51. package/src/client/app/context.ts +17 -0
  52. package/src/client/app/global-components.ts +20 -14
  53. package/src/client/app/host.ts +9 -6
  54. package/src/client/app/render-context.ts +25 -5
  55. package/src/client/app/util.ts +104 -9
  56. package/src/client/codegen.ts +81 -29
  57. package/src/client/context.ts +66 -0
  58. package/src/client/server/Story.ts +16 -10
  59. package/src/client/server/Variant.ts +13 -14
  60. package/src/client/server/__tests__/nesting-errors.spec.ts +48 -0
  61. package/src/client/server/context.ts +18 -0
  62. package/src/client/server/run.ts +11 -7
  63. package/src/commands/generate-story.client.ts +4 -4
  64. package/src/commands/generate-story.server.ts +2 -2
  65. package/src/helpers.ts +2 -2
  66. package/src/index.node.ts +2 -0
  67. package/src/util/list-components.spec.ts +54 -0
  68. package/src/util/list-components.ts +68 -6
@@ -3,7 +3,7 @@ import { createAutoBuildingObject as o, indent as s, serializeJs as c, voidEleme
3
3
  import { camelCase as u, pascalCase as d } from "change-case";
4
4
  //#region src/client/codegen.ts
5
5
  async function f(e) {
6
- let t = e.slots().default?.({ state: e.state ?? {} }) ?? [], n = Array.isArray(t) ? t : [t], r = [];
6
+ let t = e.slots?.().default?.({ state: e.state ?? {} }) ?? [], n = Array.isArray(t) ? t : [t], r = [];
7
7
  for (let t in n) {
8
8
  let i = n[t];
9
9
  r.push(...(await p(i, e.state?._hPropState?.[t])).lines);
@@ -18,24 +18,24 @@ async function p(c, d = null) {
18
18
  let f = [];
19
19
  if (typeof c.type == "object" || typeof c.type == "string") {
20
20
  c.type?.__asyncLoader && !c.type.__asyncResolved && await c.type.__asyncLoader();
21
- let e = [], h = !1, v = ["key"];
22
- function y(t, n, r = null) {
21
+ let e = [], g = !1, y = ["key"];
22
+ function b(t, n, r = null) {
23
23
  let i = "";
24
24
  for (let e in n.modifiers) n.modifiers[e] && (i += `.${e}`);
25
25
  let a = "";
26
26
  n.arg && (a = `:${n.arg}`), r &&= r.replace(/^\$(?:setup|props|data)\./g, "");
27
- let o = r ? [r] : g(n.value), s = [], c = `v-${t}${a}${i}="`;
28
- o.length > 1 ? (s.push(`${c}${o[0]}`), s.push(...o.slice(1, o.length - 1)), s.push(`${o[o.length - 1]}"`), h = !0) : s.push(`${c}${o[0] ?? ""}"`), e.push(s);
27
+ let o = r ? [r] : _(n.value), s = [], c = `v-${t}${a}${i}="`;
28
+ o.length > 1 ? (s.push(`${c}${o[0]}`), s.push(...o.slice(1, o.length - 1)), s.push(`${o[o.length - 1]}"`), g = !0) : s.push(`${c}${o[0] ?? ""}"`), e.push(s);
29
29
  }
30
30
  if (c.dirs) {
31
31
  for (let e of c.dirs) if (e.dir === a || e.dir === i || e.dir === r || e.dir === t || e.dir === n) {
32
- let t = [`onUpdate:${e.arg ?? "modelValue"}`, `onUpdate:${u(e.arg ?? "modelValue")}`].find((e) => c.props[e]), n = c.props[t], r = null;
33
- if (n) {
34
- v.push(t);
32
+ let t = [`onUpdate:${e.arg ?? "modelValue"}`, `onUpdate:${u(e.arg ?? "modelValue")}`].find((e) => c.props?.[e]), n = t ? c.props?.[t] : void 0, r = null;
33
+ if (t && n) {
34
+ y.push(t);
35
35
  let e = n.toString(), i = /\(\$event\) => (.*?) = \$event/.exec(e);
36
- i && (r = i[1]);
36
+ i && (r = i[1] ?? null);
37
37
  }
38
- y("model", e, r);
38
+ b("model", e, r);
39
39
  } else if (e.instance._ || e.instance.$) {
40
40
  let t = e.instance.$ ?? e.instance._, n;
41
41
  for (let r of [t.directives, t.appContext.directives]) {
@@ -51,99 +51,118 @@ async function p(c, d = null) {
51
51
  break;
52
52
  }
53
53
  }
54
- n && y(n, e);
54
+ n && b(n, e);
55
55
  }
56
56
  }
57
- function b(t, n) {
57
+ function x(t, n) {
58
58
  if (typeof n != "string" || c.dynamicProps?.includes(t)) {
59
59
  let r = ":";
60
60
  t.startsWith("on") && (r = "@");
61
- let i = r === "@" ? `${t[2].toLowerCase()}${t.slice(3)}` : t, a = [`onUpdate:${t}`, `onUpdate:${u(t)}`].find((e) => c.dynamicProps?.includes(e) || c.props && e in c.props);
61
+ let i = r === "@" ? `${t.charAt(2).toLowerCase()}${t.slice(3)}` : t, a = [`onUpdate:${t}`, `onUpdate:${u(t)}`].find((e) => c.dynamicProps?.includes(e) || c.props && e in c.props);
62
62
  if (r === ":" && a) {
63
- v.push(a);
64
- let e = c.props[a].toString(), r, i = /\(\$event\) => (.*?) = \$event/.exec(e);
65
- i && (r = i[1]);
66
- let o = `${t === "modelValue" ? "model" : t}Modifiers`, s = c.props[o] ?? {};
67
- v.push(o), y("model", {
63
+ y.push(a);
64
+ let e = c.props?.[a], r = String(e), i = null, o = /\(\$event\) => (.*?) = \$event/.exec(r);
65
+ o && (i = o[1] ?? null);
66
+ let s = `${t === "modelValue" ? "model" : t}Modifiers`, l = c.props?.[s] ?? {};
67
+ y.push(s), b("model", {
68
68
  arg: t === "modelValue" ? null : t,
69
- modifiers: s,
69
+ modifiers: l,
70
70
  value: n
71
- }, r);
71
+ }, i);
72
72
  return;
73
73
  }
74
74
  if (n === void 0) return;
75
75
  let o;
76
- if (typeof n == "string" && n.startsWith("{{") && n.endsWith("}}")) o = _(n.substring(2, n.length - 2).trim()).split("\n");
76
+ if (typeof n == "string" && n.startsWith("{{") && n.endsWith("}}")) o = v(n.substring(2, n.length - 2).trim()).split("\n");
77
77
  else if (typeof n == "function") {
78
- let e = _(n.toString().replace(/'/g, "\\'").replace(/"/g, "'")), t = /function (\S+)\(/.exec(e);
79
- t ? o = [t[1]] : (e.startsWith("($event) => ") && (e = e.substring(12)), o = e.split("\n"));
80
- } else o = g(n);
81
- if (o.length > 1) {
82
- h = !0;
83
- let t = [`${r}${i}="${o[0]}`];
84
- t.push(...o.slice(1, o.length - 1)), t.push(`${o[o.length - 1]}"`), e.push(t);
85
- } else e.push([`${r}${i}="${o[0]}"`]);
86
- } else c.type?.props?.[t]?.type === Boolean ? e.push([t]) : e.push([`${t}="${n}"`]);
78
+ let e = v(n.toString()), t = /function (\S+)\(/.exec(e)?.[1];
79
+ t ? o = [t] : (e.startsWith("($event) => ") && (e = e.substring(12)), o = e.split("\n"));
80
+ } else o = _(n);
81
+ let { quote: s, lines: l } = m(o);
82
+ if (l.length > 1) {
83
+ g = !0;
84
+ let t = [`${r}${i}=${s}${l[0]}`];
85
+ t.push(...l.slice(1, l.length - 1)), t.push(`${l[l.length - 1]}${s}`), e.push(t);
86
+ } else e.push([`${r}${i}=${s}${l[0]}${s}`]);
87
+ } else if (c.type?.props?.[t]?.type === Boolean) e.push([t]);
88
+ else {
89
+ let r = m([String(n)]);
90
+ e.push([`${t}=${r.quote}${r.lines[0]}${r.quote}`]);
91
+ }
87
92
  }
88
93
  for (let e in c.props) {
89
- if (v.includes(e) || d && e in d) continue;
94
+ if (y.includes(e) || d && e in d) continue;
90
95
  let t = c.props[e];
91
- b(e, t);
96
+ x(e, t);
92
97
  }
93
- if (d) for (let e in d) b(e, d[e]);
94
- e.length > 1 && (h = !0);
95
- let x = m(c), S = !1, C = [];
96
- if (typeof c.children == "string") x === "pre" ? C.push(c.children) : C.push(...c.children.split("\n")), S = !0;
98
+ if (d) for (let e in d) x(e, d[e]);
99
+ e.length > 1 && (g = !0);
100
+ let S = h(c), C = !1, w = [];
101
+ if (typeof c.children == "string") S === "pre" ? w.push(c.children) : w.push(...c.children.split("\n")), C = !0;
97
102
  else if (Array.isArray(c.children)) {
98
103
  let e;
99
104
  for (let t of c.children) {
100
105
  let n = await p(t);
101
106
  if (n.isText) {
102
107
  e === void 0 && (e = !0);
103
- let t = n.lines[0];
104
- !C.length || /^\s/.test(t) ? C.push(t.trim()) : C[C.length - 1] += t;
105
- } else e === void 0 && (e = !1), C.push(...n.lines);
108
+ let t = n.lines[0] ?? "";
109
+ !w.length || /^\s/.test(t) ? w.push(t.trim()) : w[w.length - 1] += t;
110
+ } else e === void 0 && (e = !1), w.push(...n.lines);
106
111
  }
107
- e !== void 0 && (S = e);
112
+ e !== void 0 && (C = e);
108
113
  }
109
114
  if (c.children && typeof c.children == "object" && !Array.isArray(c.children)) {
110
115
  for (let e in c.children) if (typeof c.children[e] == "function") {
111
- let t = o((e) => `{{ ${e} }}`, (e, t) => {
112
- if (t === "__v_isRef") return () => !1;
113
- }), n = c.children[e](t.proxy), r = [];
116
+ let t = o((e) => `{{ ${e} }}`, (e, t) => t === "__v_isRef" ? () => !1 : null), n = c.children[e](t.proxy), r = [];
114
117
  for (let e of n) r.push(...(await p(e)).lines);
115
118
  let i = Object.keys(t.cache);
116
- i.length ? (C.push(`<template #${e}="{ ${i.join(", ")} }">`), C.push(...s(r)), C.push("</template>")) : e === "default" ? C.push(...r) : (C.push(`<template #${e}>`), C.push(...s(r)), C.push("</template>"));
119
+ i.length ? (w.push(`<template #${e}="{ ${i.join(", ")} }">`), w.push(...s(r)), w.push("</template>")) : e === "default" ? w.push(...r) : (w.push(`<template #${e}>`), w.push(...s(r)), w.push("</template>"));
117
120
  }
118
121
  }
119
- let w = [`<${x}`];
120
- if (h) {
121
- for (let t of e) w.push(...s(t));
122
- C.length > 0 && w.push(">");
123
- } else e.length === 1 && (w[0] += ` ${e[0]}`), C.length > 0 && (w[0] += ">");
124
- let T = l.includes(x.toLowerCase());
125
- C.length > 0 ? C.length === 1 && w.length === 1 && !e.length && S ? f.push(`${w[0]}${C[0]}</${x}>`) : (f.push(...w), f.push(...s(C)), f.push(`</${x}>`)) : w.length > 1 ? (f.push(...w), f.push(T ? ">" : "/>")) : f.push(`${w[0]}${T ? "" : " /"}>`);
122
+ let T = [`<${S}`];
123
+ if (g) {
124
+ for (let t of e) T.push(...s(t));
125
+ w.length > 0 && T.push(">");
126
+ } else e.length === 1 && (T[0] += ` ${e[0]}`), w.length > 0 && (T[0] += ">");
127
+ let E = l.includes(S.toLowerCase());
128
+ w.length > 0 ? w.length === 1 && T.length === 1 && !e.length && C ? f.push(`${T[0]}${w[0]}</${S}>`) : (f.push(...T), f.push(...s(w)), f.push(`</${S}>`)) : T.length > 1 ? (f.push(...T), f.push(E ? ">" : "/>")) : f.push(`${T[0]}${E ? "" : " /"}>`);
126
129
  } else if (c?.shapeFlag & 16) for (let e of c.children) f.push(...(await p(e)).lines);
127
130
  return { lines: f };
128
131
  }
129
132
  function m(e) {
133
+ let t = e.join("\n"), n = (t.match(/"/g) ?? []).length, r = (t.match(/'/g) ?? []).length;
134
+ return n === 0 ? {
135
+ quote: "\"",
136
+ lines: e
137
+ } : r === 0 ? {
138
+ quote: "'",
139
+ lines: e
140
+ } : r <= n ? {
141
+ quote: "'",
142
+ lines: e.map((e) => e.replace(/'/g, "&#39;"))
143
+ } : {
144
+ quote: "\"",
145
+ lines: e.map((e) => e.replace(/"/g, "&quot;"))
146
+ };
147
+ }
148
+ function h(e) {
130
149
  if (typeof e.type == "string") return e.type;
131
150
  if (e.type?.__asyncResolved) {
132
151
  let t = e.type?.__asyncResolved;
133
- return t.name ?? h(t.__file);
152
+ return t.name ?? g(t.__file);
134
153
  }
135
- return e.type?.name ? e.type.name : e.type?.__file ? h(e.type.__file) : "Anonymous";
136
- }
137
- function h(e) {
138
- let t = /([^/]+)\.vue$/.exec(e);
139
- return t ? d(t[1]) : "Anonymous";
154
+ return e.type?.name ? e.type.name : e.type?.__file ? g(e.type.__file) : "Anonymous";
140
155
  }
141
156
  function g(e) {
142
- let t = !!e?.__autoBuildingObject, n = c(e);
143
- return t ? [_(n.__autoBuildingObjectGetKey)] : _(n).split("\n");
157
+ let t = /([^/]+)\.vue$/.exec(e)?.[1];
158
+ return t ? d(t) : "Anonymous";
144
159
  }
145
160
  function _(e) {
161
+ let t = !!e?.__autoBuildingObject, n = c(e);
162
+ return t ? [v(n.__autoBuildingObjectGetKey)] : v(n).split("\n");
163
+ }
164
+ function v(e) {
146
165
  return e.replace(/\$setup\./g, "");
147
166
  }
148
167
  //#endregion
149
- export { f as generateSourceCode, m as getTagName };
168
+ export { m as delimitAttr, f as generateSourceCode, h as getTagName };
@@ -0,0 +1,20 @@
1
+ import { inject as e, provide as t } from "vue";
2
+ //#region src/client/context.ts
3
+ function n(n, r) {
4
+ let i = Symbol.for(n);
5
+ return {
6
+ provide(e) {
7
+ t(i, e);
8
+ },
9
+ inject(t) {
10
+ let n = e(i, null);
11
+ if (n === null) throw Error(`[poveste] a ${t} has to be inside a ${r}`);
12
+ return n;
13
+ },
14
+ injectOptional() {
15
+ return e(i, null);
16
+ }
17
+ };
18
+ }
19
+ //#endregion
20
+ export { n as createContext };
@@ -1,7 +1,8 @@
1
- import { autoStubComponents as e } from "./stub.js";
2
- import { defineComponent as t, inject as n, onMounted as r, provide as i } from "vue";
1
+ import { addStoryContext as e, addVariantContext as t, serverStoryContext as n, storyFileContext as r } from "./context.js";
2
+ import { autoStubComponents as i } from "./stub.js";
3
+ import { defineComponent as a, onMounted as o } from "vue";
3
4
  //#region src/client/server/Story.ts
4
- var a = t({
5
+ var s = a({
5
6
  name: "PovesteStory",
6
7
  inheritAttrs: !1,
7
8
  props: {
@@ -38,38 +39,40 @@ var a = t({
38
39
  default: void 0
39
40
  }
40
41
  },
41
- setup(e) {
42
- let t = n("hstStoryFile"), a = {
43
- id: e.id ?? t?.id,
44
- title: e.title ?? t?.fileName,
45
- group: e.group,
46
- layout: e.layout,
47
- icon: e.icon,
48
- iconColor: e.iconColor,
49
- docsOnly: e.docsOnly,
50
- meta: e.meta,
42
+ setup(i) {
43
+ let a = r.injectOptional(), s = i.id ?? a?.id, c = i.title ?? a?.fileName;
44
+ if (!s || c === void 0) throw Error("[poveste] a <Story> collected outside a story file needs an `id` and a `title`");
45
+ let l = {
46
+ id: s,
47
+ title: c,
48
+ group: i.group,
49
+ layout: i.layout,
50
+ icon: i.icon,
51
+ iconColor: i.iconColor,
52
+ docsOnly: i.docsOnly,
53
+ meta: i.meta,
51
54
  variants: []
52
55
  };
53
- return n("addStory", null)?.(a), i("story", a), i("addVariant", (e) => {
54
- a.variants.push(e);
55
- }), r(() => {
56
- a.variants.length || a.variants.push({
56
+ return e.injectOptional()?.(l), n.provide(l), t.provide((e) => {
57
+ l.variants.push(e);
58
+ }), o(() => {
59
+ l.variants.length || l.variants.push({
57
60
  id: "_default",
58
61
  title: "default"
59
62
  });
60
- }), { story: a };
63
+ }), { story: l };
61
64
  },
62
65
  render() {
63
- let t = !1;
66
+ let e = !1;
64
67
  try {
65
- let n = this.$slots.default?.({ get state() {
66
- return t = !0, {};
68
+ let t = this.$slots.default?.({ get state() {
69
+ return e = !0, {};
67
70
  } });
68
- return Array.isArray(n) && e(n), n;
69
- } catch (e) {
70
- return t || console.error(e), null;
71
+ return Array.isArray(t) && i(t), t;
72
+ } catch (t) {
73
+ return e || console.error(t), null;
71
74
  }
72
75
  }
73
76
  });
74
77
  //#endregion
75
- export { a as default };
78
+ export { s as default };
@@ -1,6 +1,7 @@
1
- import { defineComponent as e, inject as t } from "vue";
1
+ import { addVariantContext as e, serverStoryContext as t } from "./context.js";
2
+ import { defineComponent as n } from "vue";
2
3
  //#region src/client/server/Variant.ts
3
- var n = e({
4
+ var r = n({
4
5
  name: "PovesteVariant",
5
6
  props: {
6
7
  title: {
@@ -24,23 +25,19 @@ var n = e({
24
25
  default: void 0
25
26
  }
26
27
  },
27
- setup(e) {
28
- let n = t("story");
29
- function r() {
30
- return `${n.id}-${n.variants.length}`;
31
- }
32
- let i = {
33
- id: e.id ?? r(),
34
- title: e.title,
35
- icon: e.icon,
36
- iconColor: e.iconColor,
37
- meta: e.meta
38
- };
39
- t("addVariant")(i);
28
+ setup(n) {
29
+ let r = t.inject("<Variant>");
30
+ e.inject("<Variant>")({
31
+ id: n.id ?? `${r.id}-${r.variants.length}`,
32
+ title: n.title,
33
+ icon: n.icon,
34
+ iconColor: n.iconColor,
35
+ meta: n.meta
36
+ });
40
37
  },
41
38
  render() {
42
39
  return null;
43
40
  }
44
41
  });
45
42
  //#endregion
46
- export { n as default };
43
+ export { r as default };
@@ -0,0 +1,5 @@
1
+ import { createContext as e } from "../context.js";
2
+ //#region src/client/server/context.ts
3
+ var t = e("poveste-server-story-file", "story file"), n = e("poveste-server-add-story", "story file"), r = e("poveste-server-story", "<Story>"), i = e("poveste-server-add-variant", "<Story>");
4
+ //#endregion
5
+ export { n as addStoryContext, i as addVariantContext, r as serverStoryContext, t as storyFileContext };
@@ -1,44 +1,44 @@
1
1
  import { VUE_SETUP_HOOK_NAMES as e } from "../../setup-hooks.js";
2
- import t from "./Story.js";
3
- import n from "./Variant.js";
4
- import { createApp as r, h as i } from "vue";
5
- import { getSetupHook as a } from "@poveste/shared";
6
- import * as o from "virtual:$poveste-generated-global-setup";
7
- import * as s from "virtual:$poveste-setup";
2
+ import { addStoryContext as t, storyFileContext as n } from "./context.js";
3
+ import r from "./Story.js";
4
+ import i from "./Variant.js";
5
+ import { createApp as a, h as o } from "vue";
6
+ import { getSetupHook as s } from "@poveste/shared";
7
+ import * as c from "virtual:$poveste-generated-global-setup";
8
+ import * as l from "virtual:$poveste-setup";
8
9
  //#region src/client/server/run.ts
9
- async function c({ file: c, storyData: l, el: u }) {
10
- let { default: d } = await import(/* @vite-ignore */
10
+ async function u({ file: u, storyData: d, el: f }) {
11
+ let { default: p } = await import(/* @vite-ignore */
11
12
  /* @vite-ignore */
12
- c.moduleId
13
- ), f = r({
14
- provide: {
15
- addStory(e) {
16
- l.push(e);
17
- },
18
- hstStoryFile: c
13
+ u.moduleId
14
+ ), m = a({
15
+ setup() {
16
+ t.provide((e) => {
17
+ d.push(e);
18
+ }), n.provide(u);
19
19
  },
20
20
  render() {
21
- return i(d);
21
+ return o(p);
22
22
  }
23
23
  });
24
- f.component("Story", t), f.component("Variant", n);
25
- let p = {
26
- app: f,
27
- story: null,
28
- variant: null,
24
+ m.component("Story", r), m.component("Variant", i);
25
+ let h = {
26
+ app: m,
27
+ story: void 0,
28
+ variant: void 0,
29
29
  addWrapper: () => {}
30
- }, m = a(o, e);
31
- m && await m(p);
32
- let h = a(s, e);
33
- if (h && await h(p), f.mount(u), d.doc) {
30
+ }, g = s(c, e);
31
+ g && await g(h);
32
+ let _ = s(l, e);
33
+ if (_ && await _(h), m.mount(f), p.doc) {
34
34
  let e = document.createElement("div");
35
- e.innerHTML = d.doc;
35
+ e.innerHTML = p.doc;
36
36
  let t = e.textContent;
37
- l.forEach((e) => {
37
+ d.forEach((e) => {
38
38
  e.docsText = t;
39
39
  });
40
40
  }
41
- f.unmount();
41
+ m.unmount();
42
42
  }
43
43
  //#endregion
44
- export { c as run };
44
+ export { u as run };
@@ -7,10 +7,14 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
7
7
  };
8
8
  targetVariantId: {
9
9
  type: StringConstructor;
10
- default: any;
10
+ default: null;
11
+ };
12
+ syncState: {
13
+ type: BooleanConstructor;
14
+ default: boolean;
11
15
  };
12
16
  }>, {
13
- el: import("vue").Ref<HTMLDivElement, HTMLDivElement>;
17
+ el: import("vue").Ref<HTMLDivElement | undefined, HTMLDivElement | undefined>;
14
18
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
15
19
  story: {
16
20
  type: _PropType<Story>;
@@ -18,9 +22,14 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
18
22
  };
19
23
  targetVariantId: {
20
24
  type: StringConstructor;
21
- default: any;
25
+ default: null;
26
+ };
27
+ syncState: {
28
+ type: BooleanConstructor;
29
+ default: boolean;
22
30
  };
23
31
  }>> & Readonly<{}>, {
32
+ syncState: boolean;
24
33
  targetVariantId: string;
25
34
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
26
35
  export default _default;
@@ -14,7 +14,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
14
14
  default: string;
15
15
  };
16
16
  }>, {
17
- sandbox: import("vue").Ref<HTMLDivElement, HTMLDivElement>;
17
+ sandbox: import("vue").Ref<HTMLDivElement | undefined, HTMLDivElement | undefined>;
18
18
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
19
19
  ready: () => true;
20
20
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
@@ -1,33 +1,36 @@
1
1
  import type { Story } from '@poveste/shared';
2
2
  import type { PropType, VNode } from 'vue';
3
+ import type { PreviewRenderContext } from './render-context.js';
3
4
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
5
  initState: {
5
6
  type: PropType<() => any | Promise<any>>;
6
- default: any;
7
+ default: undefined;
7
8
  };
8
9
  meta: {
9
10
  type: PropType<Story["meta"]>;
10
- default: any;
11
+ default: undefined;
11
12
  };
12
13
  }>, {
13
- renderContext: import("./render-context.js").PreviewRenderContext;
14
+ renderContext: PreviewRenderContext | null;
14
15
  story: import("vue").ComputedRef<Story>;
15
16
  renderMountStory: () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
16
17
  [key: string]: any;
17
18
  }>[];
18
- renderPreviewStory: () => any[];
19
+ renderPreviewStory: (context: PreviewRenderContext) => VNode<import("vue").RendererNode, import("vue").RendererElement, {
20
+ [key: string]: any;
21
+ }>[];
19
22
  updateStory: () => void;
20
23
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
21
24
  initState: {
22
25
  type: PropType<() => any | Promise<any>>;
23
- default: any;
26
+ default: undefined;
24
27
  };
25
28
  meta: {
26
29
  type: PropType<Story["meta"]>;
27
- default: any;
30
+ default: undefined;
28
31
  };
29
32
  }>> & Readonly<{}>, {
30
- meta: import("poveste").StoryMeta;
33
+ meta: import("poveste").StoryMeta | undefined;
31
34
  initState: () => any | Promise<any>;
32
35
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
33
36
  export default _default;
@@ -1,13 +1,14 @@
1
1
  import type { Variant } from '@poveste/shared';
2
2
  import type { PropType } from 'vue';
3
+ import type { PreviewRenderContext } from './render-context.js';
3
4
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
5
  initState: {
5
6
  type: PropType<() => any | Promise<any>>;
6
- default: any;
7
+ default: undefined;
7
8
  };
8
9
  source: {
9
10
  type: StringConstructor;
10
- default: any;
11
+ default: undefined;
11
12
  };
12
13
  responsiveDisabled: {
13
14
  type: BooleanConstructor;
@@ -19,32 +20,32 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
19
20
  };
20
21
  setupApp: {
21
22
  type: FunctionConstructor;
22
- default: any;
23
+ default: undefined;
23
24
  };
24
25
  meta: {
25
26
  type: PropType<Variant["meta"]>;
26
- default: any;
27
+ default: undefined;
27
28
  };
28
29
  implicit: {
29
30
  type: BooleanConstructor;
30
31
  default: boolean;
31
32
  };
32
33
  }>, {
33
- renderContext: import("./render-context.js").PreviewRenderContext;
34
- renderVariantSlot: (variant: Variant) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
34
+ renderContext: PreviewRenderContext | null;
35
+ renderVariantSlot: (variant: Variant, context: PreviewRenderContext) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
35
36
  [key: string]: any;
36
- }>[];
37
- resolveVariant: () => Variant;
37
+ }>[] | null;
38
+ resolveVariant: () => Variant | null | undefined;
38
39
  syncRenderVariantState: (variant: Variant) => void;
39
40
  updateVariant: (variant: Variant) => void;
40
41
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
41
42
  initState: {
42
43
  type: PropType<() => any | Promise<any>>;
43
- default: any;
44
+ default: undefined;
44
45
  };
45
46
  source: {
46
47
  type: StringConstructor;
47
- default: any;
48
+ default: undefined;
48
49
  };
49
50
  responsiveDisabled: {
50
51
  type: BooleanConstructor;
@@ -56,18 +57,18 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
56
57
  };
57
58
  setupApp: {
58
59
  type: FunctionConstructor;
59
- default: any;
60
+ default: undefined;
60
61
  };
61
62
  meta: {
62
63
  type: PropType<Variant["meta"]>;
63
- default: any;
64
+ default: undefined;
64
65
  };
65
66
  implicit: {
66
67
  type: BooleanConstructor;
67
68
  default: boolean;
68
69
  };
69
70
  }>> & Readonly<{}>, {
70
- meta: any;
71
+ meta: import("poveste").VariantMeta | undefined;
71
72
  initState: () => any | Promise<any>;
72
73
  source: string;
73
74
  responsiveDisabled: boolean;
@@ -0,0 +1,9 @@
1
+ import type { ComputedRef } from 'vue';
2
+ /** The story a variant belongs to. Read with `?.` throughout. */
3
+ export declare const storyContext: import("../context.js").Context<ComputedRef<any>>;
4
+ /**
5
+ * The story's implicit state, absent when the story has none. A variant skips
6
+ * its state sync rather than failing, which is behaviour rather than an
7
+ * oversight — this is the type saying so.
8
+ */
9
+ export declare const implicitStateContext: import("../context.js").Context<() => any>;
@@ -9,10 +9,25 @@ export interface PreviewRenderContext {
9
9
  * app realm, where the story view needs all of them mounted.
10
10
  */
11
11
  targetVariantId?: string | null;
12
+ /**
13
+ * Whether this mount pass owns the live state sync for its variants.
14
+ *
15
+ * False in a sandbox realm, where the render tree beside it already syncs the
16
+ * same `variant.state` against the same story's bindings. Two syncs over one
17
+ * state is two deep watchers walking the whole graph on every edit, and a
18
+ * story holding a large one pays for both: #964 measured the sandbox running
19
+ * three syncs where the app realm runs one.
20
+ *
21
+ * The app realm keeps it. Its mount pass is the only thing that fills
22
+ * `variant.state` there — with no controls slot nothing renders, so nothing
23
+ * else would — and that is what the controls panel builds from.
24
+ */
25
+ syncState?: boolean;
12
26
  externalState: Variant['state'] | null;
13
27
  nextVariantIndex: {
14
28
  value: number;
15
29
  };
16
30
  }
17
31
  export declare function provideRenderContext(value: PreviewRenderContext): void;
18
- export declare function useRenderContext(): PreviewRenderContext;
32
+ /** Null outside a preview, which several call sites read with `?.`. */
33
+ export declare function useRenderContext(): PreviewRenderContext | null;