@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
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Poveste + Vue 3
2
2
 
3
- Requires `vue@^3.5.26`.
3
+ Requires `vue@^3.5.43`.
4
4
 
5
5
  ```bash
6
6
  pnpm add -D poveste @poveste/plugin-vue
@@ -40,5 +40,5 @@ import MyButton from './MyButton.vue'
40
40
  Coming from histoire? The Vue API is unchanged: swap the dependency and your existing
41
41
  `.story.vue` files keep working.
42
42
 
43
- [Vue guide](https://poveste.dev/guide/vue/getting-started.html) ·
43
+ [Vue guide](https://poveste.dev/guide/vue/getting-started) ·
44
44
  [Documentation](https://poveste.dev)
package/components.d.ts CHANGED
@@ -18,6 +18,8 @@ import type {
18
18
  HstTextarea,
19
19
  HstSelect,
20
20
  HstRadio,
21
+ HstColor,
22
+ HstDate,
21
23
  HstJson,
22
24
  HstColorShades,
23
25
  HstTokenList,
@@ -229,6 +231,8 @@ declare module 'vue' {
229
231
  HstTextarea: typeof HstTextarea
230
232
  HstSelect: typeof HstSelect
231
233
  HstRadio: typeof HstRadio
234
+ HstColor: typeof HstColor
235
+ HstDate: typeof HstDate
232
236
  HstJson: typeof HstJson
233
237
  HstColorShades: typeof HstColorShades
234
238
  HstTokenList: typeof HstTokenList
@@ -12,6 +12,10 @@ var c = t({
12
12
  targetVariantId: {
13
13
  type: String,
14
14
  default: null
15
+ },
16
+ syncState: {
17
+ type: Boolean,
18
+ default: !0
15
19
  }
16
20
  },
17
21
  setup(t) {
@@ -20,17 +24,18 @@ var c = t({
20
24
  slotName: "default",
21
25
  currentVariant: null,
22
26
  targetVariantId: t.targetVariantId,
27
+ syncState: t.syncState,
23
28
  externalState: null,
24
29
  nextVariantIndex: { value: 0 }
25
- }), l;
30
+ }), l = null;
26
31
  async function u() {
27
- l = e({
32
+ n.value && (l = e({
28
33
  name: "MountStorySubApp",
29
34
  el: n.value,
30
35
  getStory: () => t.story,
31
36
  getVariant: () => null,
32
37
  renderContext: c
33
- }), await l.mount();
38
+ }), await l.mount());
34
39
  }
35
40
  function d() {
36
41
  l?.unmount(), l = null;
@@ -21,7 +21,7 @@ var l = n({
21
21
  },
22
22
  emits: { ready: () => !0 },
23
23
  setup(n, { emit: r }) {
24
- let l = o(), u, d = !1, f = c({}), p = e(n.variant.state, f), m = c({
24
+ let l = o(), u = null, d = !1, f = c({}), p = e(n.variant.state, f), m = c({
25
25
  mode: "render",
26
26
  slotName: n.slotName,
27
27
  currentVariant: n.variant,
@@ -35,14 +35,20 @@ var l = n({
35
35
  p?.stop(), p = e(n.variant.state, f);
36
36
  }
37
37
  async function _() {
38
- d || (d = !0, h(), m.currentVariant = n.variant, m.slotName = n.slotName, u = t({
39
- name: "RenderStorySubApp",
40
- el: l.value,
41
- getStory: () => n.story,
42
- getVariant: () => n.variant,
43
- renderContext: m,
44
- wrapInDiv: !0
45
- }), await u.mount(), d = !1, r("ready"));
38
+ if (!d) {
39
+ if (d = !0, h(), m.currentVariant = n.variant, m.slotName = n.slotName, !l.value) {
40
+ d = !1;
41
+ return;
42
+ }
43
+ u = t({
44
+ name: "RenderStorySubApp",
45
+ el: l.value,
46
+ getStory: () => n.story,
47
+ getVariant: () => n.variant,
48
+ renderContext: m,
49
+ wrapInDiv: !0
50
+ }), await u.mount(), d = !1, r("ready");
51
+ }
46
52
  }
47
53
  return a(async () => {
48
54
  n.variant.configReady && await _();
@@ -1,9 +1,11 @@
1
- import { useRenderContext as e } from "./render-context.js";
2
- import t from "./Variant.js";
3
- import { cloneVNode as n, computed as r, defineComponent as i, getCurrentInstance as a, h as o, isRef as s, provide as c, reactive as l, useAttrs as u } from "vue";
4
- import { omitInheritStoryProps as d } from "@poveste/shared";
1
+ import { implicitStateContext as e, storyContext as t } from "./context.js";
2
+ import { useRenderContext as n } from "./render-context.js";
3
+ import { isWritableBinding as r, useInstance as i } from "./util.js";
4
+ import a from "./Variant.js";
5
+ import { cloneVNode as o, computed as s, defineComponent as c, h as l, isRef as u, reactive as d, useAttrs as f } from "vue";
6
+ import { omitInheritStoryProps as p } from "@poveste/shared";
5
7
  //#region src/client/app/Story.ts
6
- var f = i({
8
+ var m = c({
7
9
  name: "Story",
8
10
  __povesteType: "story",
9
11
  inheritAttrs: !1,
@@ -17,100 +19,112 @@ var f = i({
17
19
  default: void 0
18
20
  }
19
21
  },
20
- setup(t) {
21
- let i = a(), o = u(), f = e(), p = r(() => o.story);
22
- c("story", p);
23
- let m = i.parent, h = l({});
24
- Object.defineProperty(h, "$data", {
22
+ setup(a) {
23
+ let c = i("Story"), l = f(), m = n(), h = s(() => l.story);
24
+ t.provide(h);
25
+ let g = c.parent, _ = d({});
26
+ Object.defineProperty(_, "$data", {
25
27
  enumerable: !0,
26
28
  configurable: !0,
27
- get: () => m.data,
29
+ get: () => g.data,
28
30
  set: (e) => {
29
- Object.assign(m.data, e);
31
+ Object.assign(g.data, e);
30
32
  }
31
33
  });
32
- function g(e, t) {
34
+ function v(e, t) {
33
35
  let n = e[t];
34
- typeof n == "function" || n?.__file || typeof n?.render == "function" || typeof n?.setup == "function" || Object.defineProperty(h, t, {
36
+ typeof n == "function" || n?.__file || typeof n?.render == "function" || typeof n?.setup == "function" || r(n) && Object.defineProperty(_, t, {
35
37
  enumerable: !0,
36
38
  configurable: !0,
37
39
  get: () => {
38
40
  let n = e[t];
39
- return s(n) ? n.value : n;
41
+ return u(n) ? n.value : n;
40
42
  },
41
43
  set: (n) => {
42
44
  let r = e[t];
43
- s(r) ? r.value = n : r && typeof r == "object" && n && typeof n == "object" ? Object.assign(r, n) : e[t] = n;
45
+ u(r) ? r.value = n : r && typeof r == "object" && n && typeof n == "object" ? Object.assign(r, n) : e[t] = n;
44
46
  }
45
47
  });
46
48
  }
47
- for (let e in m.exposed) g(m.exposed, e);
48
- for (let e in m.devtoolsRawSetupState) g(m.devtoolsRawSetupState, e);
49
- for (let e in m.data) g(m.data, e);
50
- c("implicitState", () => h);
51
- function _() {
52
- t.meta && (o.story.meta || (o.story.meta = {}), Object.assign(o.story.meta, t.meta)), Object.assign(o.story, { slots: () => i.proxy.$slots });
49
+ for (let e in g.exposed) v(g.exposed, e);
50
+ for (let e in g.devtoolsRawSetupState) v(g.devtoolsRawSetupState, e);
51
+ for (let e in g.data) v(g.data, e);
52
+ e.provide(() => _);
53
+ function y() {
54
+ a.meta && (l.story.meta || (l.story.meta = {}), Object.assign(l.story.meta, a.meta)), Object.assign(l.story, { slots: () => c.slots });
53
55
  }
54
56
  return {
55
- renderContext: f,
56
- story: p,
57
- renderMountStory: v,
58
- renderPreviewStory: y,
59
- updateStory: _
57
+ renderContext: m,
58
+ story: h,
59
+ renderMountStory: x,
60
+ renderPreviewStory: C,
61
+ updateStory: y
60
62
  };
61
- function v() {
62
- let e = 0, r = f?.targetVariantId ? o.story.variants.findIndex((e) => e.id === f.targetVariantId) : -1, a = (s) => {
63
- let c = [];
64
- for (let l of s) {
65
- if (l.type?.__povesteType === "variant") {
66
- let a = o.story.variants[e];
67
- if (e++, !a || r !== -1 && e - 1 !== r) continue;
68
- let s = { variant: a };
69
- l.key ?? (s.key = a.id), !l.props?.initState && !l.props?.["init-state"] && (s.initState = t.initState);
70
- for (let e in i.proxy.$attrs) l.props?.[e] === void 0 && (s[e] = i.proxy.$attrs[e]);
71
- for (let e in o.story) !d.includes(e) && l.props?.[e] === void 0 && (s[e] = o.story[e]);
72
- c.push(n(l, s));
63
+ function b(e) {
64
+ let t = {};
65
+ for (let n in c.attrs) e.props?.[n] === void 0 && (t[n] = c.attrs[n]);
66
+ for (let n in l.story) !p.includes(n) && e.props?.[n] === void 0 && (t[n] = Reflect.get(l.story, n));
67
+ return t;
68
+ }
69
+ function x() {
70
+ let e = 0, t = m?.targetVariantId, n = t ? l.story.variants.findIndex((e) => e.id === t) : -1, r = (t) => {
71
+ let i = [];
72
+ for (let s of t) {
73
+ if (s.type?.__povesteType === "variant") {
74
+ let t = l.story.variants[e];
75
+ if (e++, !t || n !== -1 && e - 1 !== n) continue;
76
+ let r = { variant: t };
77
+ s.key ?? (r.key = t.id), !s.props?.initState && !s.props?.["init-state"] && (r.initState = a.initState), Object.assign(r, b(s)), i.push(o(s, r));
73
78
  continue;
74
79
  }
75
- Array.isArray(l.children) && (l.children = a(l.children)), c.push(l);
80
+ Array.isArray(s.children) && (s.children = r(s.children)), i.push(s);
76
81
  }
77
- return c;
82
+ return i;
78
83
  };
79
- return a(i.proxy.$slots.default?.() ?? []);
84
+ return r(c.slots.default?.() ?? []);
80
85
  }
81
- function y() {
82
- f.nextVariantIndex.value = 0;
83
- let e = { state: f.externalState }, t = [];
84
- if (f.slotName === "controls" && t.push(...i.proxy.$slots.controls?.(e) ?? []), (f.slotName === "default" || o.story.meta?.hasVariantChildComponents) && t.push(...i.proxy.$slots.default?.(e) ?? []), f.slotName === "default" && f.currentVariant && !o.story.meta?.hasVariantChildComponents) {
85
- let e = o.story.variants.findIndex((e) => e.id === f.currentVariant.id);
86
- if (e !== -1) {
87
- let n = 0, r = !1, i = (t) => {
88
- let a = [];
89
- for (let o of t) {
90
- if (o?.type?.__povesteType === "variant") {
91
- n === e && (a.push(o), r = !0), n++;
86
+ function S(e) {
87
+ let t = 0;
88
+ for (let n of e) n?.type?.__povesteType === "variant" ? t++ : Array.isArray(n?.children) && (t += S(n.children));
89
+ return t;
90
+ }
91
+ function C(e) {
92
+ e.nextVariantIndex.value = 0;
93
+ let t = { state: e.externalState }, n = [];
94
+ e.slotName === "controls" && n.push(...c.slots.controls?.(t) ?? []), (e.slotName === "default" || l.story.meta?.hasVariantChildComponents) && n.push(...c.slots.default?.(t) ?? []);
95
+ let r = e.currentVariant;
96
+ if (e.slotName === "default" && r && S(n) === l.story.variants.length) {
97
+ let t = l.story.variants.findIndex((e) => e.id === r.id);
98
+ if (t !== -1) {
99
+ let r = 0, i = !1, a = (e) => {
100
+ let n = [];
101
+ for (let s of e) {
102
+ if (s?.type?.__povesteType === "variant") {
103
+ r === t && (n.push(o(s, b(s))), i = !0), r++;
92
104
  continue;
93
105
  }
94
- Array.isArray(o?.children) && o.children.length && (o.children = i(o.children)), a.push(o);
106
+ Array.isArray(s?.children) && s.children.length && (s.children = a(s.children)), n.push(s);
95
107
  }
96
- return a;
97
- }, a = i(t);
98
- if (r) return f.nextVariantIndex.value = e, a;
108
+ return n;
109
+ }, s = a(n);
110
+ if (i) return e.nextVariantIndex.value = t, s;
99
111
  }
100
112
  }
101
- return t;
113
+ return n;
102
114
  }
103
115
  },
104
116
  render() {
105
117
  this.updateStory();
106
118
  let [e] = this.story.variants;
107
- return e?.id === "_default" ? o(t, {
119
+ if (e?.id === "_default") return l(a, {
108
120
  variant: e,
109
- initState: this.initState,
121
+ ...this.initState ? { initState: this.initState } : {},
110
122
  implicit: !0,
111
123
  ...this.$attrs
112
- }, this.$slots) : this.renderContext?.mode === "render" ? this.renderPreviewStory() : this.renderMountStory();
124
+ }, this.$slots);
125
+ let t = this.renderContext;
126
+ return t?.mode === "render" ? this.renderPreviewStory(t) : this.renderMountStory();
113
127
  }
114
128
  });
115
129
  //#endregion
116
- export { f as default };
130
+ export { m as default };
@@ -1,10 +1,11 @@
1
- import { useRenderContext as e } from "./render-context.js";
2
- import { syncVariantAutoProps as t } from "./auto-props.js";
3
- import { syncStateBundledAndExternal as n, toRawDeep as r } from "./util.js";
4
- import { computed as i, defineComponent as a, getCurrentInstance as o, inject as s, onBeforeUnmount as c, useAttrs as l } from "vue";
5
- import { applyState as u, autoPropsStateKeys as d } from "@poveste/shared";
1
+ import { implicitStateContext as e, storyContext as t } from "./context.js";
2
+ import { useRenderContext as n } from "./render-context.js";
3
+ import { syncStateBundledAndExternal as r, toRawDeep as i, useInstance as a } from "./util.js";
4
+ import { syncVariantAutoProps as o } from "./auto-props.js";
5
+ import { computed as s, defineComponent as c, onBeforeUnmount as l, useAttrs as u } from "vue";
6
+ import { applyState as d, autoPropsStateKeys as f } from "@poveste/shared";
6
7
  //#region src/client/app/Variant.ts
7
- var f = a({
8
+ var p = c({
8
9
  name: "Variant",
9
10
  __povesteType: "variant",
10
11
  props: {
@@ -37,54 +38,59 @@ var f = a({
37
38
  default: !1
38
39
  }
39
40
  },
40
- async setup(a) {
41
- let f = l(), p = o(), m = s("story"), h = s("implicitState"), g = e(), _, v, y, b;
42
- c(() => {
43
- y?.stop(), b?.stop();
41
+ async setup(c) {
42
+ let p = u(), m = a("Variant"), h = t.injectOptional(), g = e.injectOptional(), _ = n(), v, y, b = null, x;
43
+ l(() => {
44
+ b?.stop(), x?.stop();
44
45
  });
45
- let x = i(() => f.variant);
46
- if (g?.mode !== "render" && typeof a.initState == "function" && x.value) {
47
- let e = await a.initState();
48
- u(x.value.state, r(e));
46
+ let S = s(() => p.variant);
47
+ if (_?.mode !== "render" && typeof c.initState == "function" && S.value) {
48
+ let e = await c.initState();
49
+ d(S.value.state, i(e));
49
50
  }
50
- g?.mode !== "render" && x.value && h && (b = n(x.value.state, h(), d));
51
- function S(e) {
51
+ _?.mode !== "render" && _?.syncState !== !1 && S.value && g && (x = r(S.value.state, g(), f));
52
+ function C(e) {
52
53
  Object.assign(e, {
53
- slots: () => p.proxy.$slots,
54
- source: a.source,
55
- responsiveDisabled: a.responsiveDisabled,
56
- autoPropsDisabled: a.autoPropsDisabled,
57
- setupApp: a.setupApp,
58
- meta: a.meta,
54
+ slots: () => m.slots,
55
+ source: c.source,
56
+ responsiveDisabled: c.responsiveDisabled,
57
+ autoPropsDisabled: c.autoPropsDisabled,
58
+ setupApp: c.setupApp,
59
+ meta: c.meta,
59
60
  configReady: !0
60
- }), !a.implicit && !m.value?.meta?.hasVariantChildComponents && (m.value.meta || (m.value.meta = {}), Object.assign(m.value.meta, { hasVariantChildComponents: !0 }));
61
+ });
62
+ let t = h?.value;
63
+ t && !c.implicit && !t.meta?.hasVariantChildComponents && (t.meta ||= {}, Object.assign(t.meta, { hasVariantChildComponents: !0 }));
61
64
  }
62
- function C() {
63
- return f.variant ? f.variant : g?.mode === "render" ? (v || (v = m.value?.variants[g.nextVariantIndex.value], g.nextVariantIndex.value++), v) : null;
65
+ function w() {
66
+ return p.variant ? p.variant : _?.mode === "render" ? (y || (y = h?.value?.variants[_.nextVariantIndex.value], _.nextVariantIndex.value++), y) : null;
64
67
  }
65
- function w(e) {
66
- if (g.slotName === "controls") return p.proxy.$slots.controls?.({ state: g.externalState }) ?? null;
67
- if (g.slotName !== "default") return null;
68
- let n = p.proxy.$slots.default?.({ state: g.externalState }) ?? null;
69
- return n && !e.autoPropsDisabled && (_ = t(e, n, g.externalState, _)), n;
68
+ function T(e, t) {
69
+ if (t.slotName === "controls") return m.slots.controls?.({ state: t.externalState }) ?? null;
70
+ if (t.slotName !== "default") return null;
71
+ let n = m.slots.default?.({ state: t.externalState }) ?? null;
72
+ return n && !e.autoPropsDisabled && (v = o(e, n, t.externalState, v)), n;
70
73
  }
71
- function T(e) {
72
- if (!h) return;
73
- let t = g?.mode === "render" && g.currentVariant?.id === e.id;
74
- t && !y ? y = n(e.state, h(), d) : !t && y && (y.stop(), y = null);
74
+ function E(e) {
75
+ if (!g) return;
76
+ let t = _?.mode === "render" && _.currentVariant?.id === e.id;
77
+ t && !b ? b = r(e.state, g(), f) : !t && b && (b.stop(), b = null);
75
78
  }
76
- return x.value && S(x.value), {
77
- renderContext: g,
78
- renderVariantSlot: w,
79
- resolveVariant: C,
80
- syncRenderVariantState: T,
81
- updateVariant: S
79
+ return S.value && C(S.value), {
80
+ renderContext: _,
81
+ renderVariantSlot: T,
82
+ resolveVariant: w,
83
+ syncRenderVariantState: E,
84
+ updateVariant: C
82
85
  };
83
86
  },
84
87
  render() {
85
88
  let e = this.resolveVariant();
86
- return !e || (this.updateVariant(e), this.syncRenderVariantState(e), this.renderContext?.mode !== "render") || this.renderContext.currentVariant?.id !== e.id ? null : this.renderVariantSlot(e);
89
+ if (!e) return null;
90
+ this.updateVariant(e), this.syncRenderVariantState(e);
91
+ let t = this.renderContext;
92
+ return t?.mode !== "render" || t.currentVariant?.id !== e.id ? null : this.renderVariantSlot(e, t);
87
93
  }
88
94
  });
89
95
  //#endregion
90
- export { f as default };
96
+ export { p as default };
@@ -0,0 +1,5 @@
1
+ import { createContext as e } from "../context.js";
2
+ //#region src/client/app/context.ts
3
+ var t = e("poveste-app-story", "<Story>"), n = e("poveste-app-implicit-state", "<Story>");
4
+ //#endregion
5
+ export { n as implicitStateContext, t as storyContext };
@@ -6,13 +6,14 @@ import { components as f } from "@poveste/controls";
6
6
  //#region src/client/app/global-components.ts
7
7
  function p(n) {
8
8
  n.component("Story", t), n.component("Variant", e);
9
- for (let e in f) n.component(e, m(f[e]));
9
+ for (let [e, t] of Object.entries(f)) n.component(e, m(t));
10
10
  }
11
11
  function m(e) {
12
+ let t = e;
12
13
  return a({
13
- name: e.name,
14
+ ...e.name ? { name: e.name } : {},
14
15
  inheritAttrs: !1,
15
- setup(t, { attrs: a }) {
16
+ setup(e, { attrs: a }) {
16
17
  let o = d(), f = d(), p = i({});
17
18
  function m(e) {
18
19
  Object.assign(p, e);
@@ -23,11 +24,11 @@ function m(e) {
23
24
  let h = [], g = d([]);
24
25
  function _() {
25
26
  g.value.forEach((e, t) => {
26
- let n = f.value.querySelector(`[renderslotid="${t}"]`);
27
- if (!n) return;
28
- let r = o.value.querySelector(`[slotid="${t}"]`);
29
- for (; r.firstChild;) r.removeChild(r.lastChild);
30
- r.appendChild(n);
27
+ let n = f.value?.querySelector(`[renderslotid="${t}"]`), r = o.value?.querySelector(`[slotid="${t}"]`);
28
+ if (n && r) {
29
+ for (; r.lastChild;) r.removeChild(r.lastChild);
30
+ r.appendChild(n);
31
+ }
31
32
  });
32
33
  }
33
34
  let v;
@@ -40,7 +41,7 @@ function m(e) {
40
41
  g.value = h, h = [];
41
42
  },
42
43
  render() {
43
- return r(e, {
44
+ return r(t, {
44
45
  ...p,
45
46
  key: "component"
46
47
  }, { default: (e) => (h.push(e), r("div", { slotId: h.length - 1 })) });
@@ -57,7 +58,7 @@ function m(e) {
57
58
  };
58
59
  },
59
60
  render() {
60
- return [o("div", { ref: "el" }), o("div", { ref: "slotEl" }, this.slotCalls.map((e, t) => o("div", { renderSlotId: t }, this.$slots.default(e))))];
61
+ return [o("div", { ref: "el" }), o("div", { ref: "slotEl" }, this.slotCalls.map((e, t) => o("div", { renderSlotId: t }, this.$slots.default?.(e))))];
61
62
  }
62
63
  });
63
64
  }
@@ -20,7 +20,7 @@ var f = o({
20
20
  }
21
21
  },
22
22
  setup(e) {
23
- return t(e.renderContext), () => s(e.story.file.component, { story: e.story });
23
+ return t(e.renderContext), () => e.story.file ? s(e.story.file.component, { story: e.story }) : null;
24
24
  }
25
25
  });
26
26
  function p(e) {
@@ -51,7 +51,7 @@ function p(e) {
51
51
  }, n(t), t.component("RouterLink", r), await m({
52
52
  app: t,
53
53
  story: e.getStory(),
54
- variant: e.getVariant(),
54
+ variant: e.getVariant() ?? void 0,
55
55
  addWrapper: (e) => {
56
56
  c.unshift(e);
57
57
  }
@@ -1,11 +1,11 @@
1
- import { inject as e, provide as t } from "vue";
1
+ import { createContext as e } from "../context.js";
2
2
  //#region src/client/app/render-context.ts
3
- var n = Symbol("poveste-preview-render-context");
4
- function r(e) {
5
- t(n, e);
3
+ var t = e("poveste-preview-render-context", "<Story>");
4
+ function n(e) {
5
+ t.provide(e);
6
6
  }
7
- function i() {
8
- return e(n, null);
7
+ function r() {
8
+ return t.injectOptional();
9
9
  }
10
10
  //#endregion
11
- export { r as provideRenderContext, i as useRenderContext };
11
+ export { n as provideRenderContext, r as useRenderContext };
@@ -1,71 +1,81 @@
1
1
  import { isRef as e, unref as t, watch as n } from "@poveste/vendors/vue";
2
- import { isRef as r, unref as i, watch as a } from "vue";
3
- import { applyState as o, createStateBaseline as s } from "@poveste/shared";
2
+ import { getCurrentInstance as r, isReadonly as i, isRef as a, markRaw as o, unref as s, watch as c } from "vue";
3
+ import { applyState as l, createStateBaseline as u, isMarkedRaw as d, isPlainObject as f } from "@poveste/shared";
4
4
  //#region src/client/app/util.ts
5
- var c = (e) => typeof e == "object" && !!e;
6
- function l(e, t = /* @__PURE__ */ new WeakMap()) {
7
- let n = r(e) ? i(e) : e;
5
+ var p = (e) => typeof e == "object" && !!e;
6
+ function m(e, t = /* @__PURE__ */ new WeakMap()) {
7
+ let n = a(e) ? s(e) : e;
8
8
  if (typeof n == "symbol") return n.toString();
9
- if (!c(n)) return n;
9
+ if (!p(n) || d(n)) return n;
10
10
  if (t.has(n)) return t.get(n);
11
+ if (!Array.isArray(n) && !f(n)) return o(n);
11
12
  if (Array.isArray(n)) {
12
13
  let e = [];
13
- return t.set(n, e), e.push(...n.map((e) => l(e, t))), e;
14
+ return t.set(n, e), e.push(...n.map((e) => m(e, t))), e;
14
15
  }
15
16
  {
16
17
  let e = {};
17
- return t.set(n, e), u(n, e, t), e;
18
+ return t.set(n, e), h(n, e, t), e;
18
19
  }
19
20
  }
20
- function u(e, t, n = /* @__PURE__ */ new WeakMap()) {
21
+ function h(e, t, n = /* @__PURE__ */ new WeakMap()) {
21
22
  Object.keys(e).forEach((r) => {
22
- t[r] = l(e[r], n);
23
+ t[r] = m(e[r], n);
23
24
  });
24
25
  }
25
- function d(n, r = /* @__PURE__ */ new WeakMap()) {
26
+ function g(n, r = /* @__PURE__ */ new WeakMap()) {
26
27
  let i = e(n) ? t(n) : n;
27
28
  if (typeof i == "symbol") return i.toString();
28
- if (!c(i)) return i;
29
+ if (!p(i) || d(i)) return i;
29
30
  if (r.has(i)) return r.get(i);
31
+ if (!Array.isArray(i) && !f(i)) return o(i);
30
32
  if (Array.isArray(i)) {
31
33
  let e = [];
32
- return r.set(i, e), e.push(...i.map((e) => d(e, r))), e;
34
+ return r.set(i, e), e.push(...i.map((e) => g(e, r))), e;
33
35
  }
34
36
  {
35
37
  let e = {};
36
- return r.set(i, e), f(i, e, r), e;
38
+ return r.set(i, e), _(i, e, r), e;
37
39
  }
38
40
  }
39
- function f(e, t, n = /* @__PURE__ */ new WeakMap()) {
41
+ function _(e, t, n = /* @__PURE__ */ new WeakMap()) {
40
42
  Object.keys(e).forEach((r) => {
41
- t[r] = l(e[r], n);
43
+ t[r] = g(e[r], n);
42
44
  });
43
45
  }
44
- function p(e, t) {
46
+ function v(e, t) {
45
47
  if (!t.length) return e;
46
48
  let n = { ...e };
47
49
  for (let e of t) delete n[e];
48
50
  return n;
49
51
  }
50
- function m(e, t, r = []) {
51
- let i = s(), c = n(() => e, (e) => {
52
+ function y(e, t, r = []) {
53
+ let i = u(), a = n(() => e, (e) => {
52
54
  if (e == null) return;
53
- let n = i.take(p(d(e), r));
54
- n && o(t, n);
55
+ let n = i.take(v(g(e), r));
56
+ n && l(t, n);
55
57
  }, {
56
58
  deep: !0,
57
59
  immediate: !0
58
- }), u = a(() => t, (t) => {
60
+ }), o = c(() => t, (t) => {
59
61
  if (t == null) return;
60
- let n = i.take(p(l(t), r));
61
- n && o(e, n);
62
+ let n = i.take(v(m(t), r));
63
+ n && l(e, n);
62
64
  }, {
63
65
  deep: !0,
64
66
  immediate: !0
65
67
  });
66
68
  return { stop() {
67
- c(), u();
69
+ a(), o();
68
70
  } };
69
71
  }
72
+ function b(e) {
73
+ return !(a(e) && i(e));
74
+ }
75
+ function x(e) {
76
+ let t = r();
77
+ if (!t) throw Error(`[poveste] <${e}> can only be set up inside a component`);
78
+ return t;
79
+ }
70
80
  //#endregion
71
- export { d as _toRawDeep, m as syncStateBundledAndExternal, l as toRawDeep };
81
+ export { g as _toRawDeep, b as isWritableBinding, y as syncStateBundledAndExternal, m as toRawDeep, x as useInstance };
@@ -1,5 +1,5 @@
1
- import { generateSourceCode as e, getTagName as t } from "./codegen.js";
2
- import n from "./app/MountStory.js";
3
- import r from "./app/RenderStory.js";
1
+ import { delimitAttr as e, generateSourceCode as t, getTagName as n } from "./codegen.js";
2
+ import r from "./app/MountStory.js";
3
+ import i from "./app/RenderStory.js";
4
4
  import "./app/index.js";
5
- export { n as MountStory, r as RenderStory, e as generateSourceCode, t as getTagName };
5
+ export { r as MountStory, i as RenderStory, e as delimitAttr, t as generateSourceCode, n as getTagName };