@poveste/plugin-vue 0.15.0 → 0.16.1

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 (36) hide show
  1. package/README.md +1 -1
  2. package/components.d.ts +4 -0
  3. package/dist/bundled/client/app/MountStory.js +5 -0
  4. package/dist/bundled/client/app/Story.js +58 -57
  5. package/dist/bundled/client/app/Variant.js +42 -41
  6. package/dist/bundled/client/app/context.js +5 -0
  7. package/dist/bundled/client/app/global-components.js +1 -1
  8. package/dist/bundled/client/app/render-context.js +7 -7
  9. package/dist/bundled/client/app/util.js +32 -27
  10. package/dist/bundled/client/context.js +20 -0
  11. package/dist/bundled/client/server/Story.js +28 -27
  12. package/dist/bundled/client/server/Variant.js +13 -17
  13. package/dist/bundled/client/server/context.js +5 -0
  14. package/dist/bundled/client/server/run.js +27 -27
  15. package/dist/client/app/MountStory.d.ts +9 -0
  16. package/dist/client/app/context.d.ts +9 -0
  17. package/dist/client/app/render-context.d.ts +15 -0
  18. package/dist/client/app/util.d.ts +32 -0
  19. package/dist/client/context.d.ts +40 -0
  20. package/dist/client/server/context.d.ts +7 -0
  21. package/package.json +13 -13
  22. package/src/client/__tests__/context.spec.ts +50 -0
  23. package/src/client/app/MountStory.ts +6 -0
  24. package/src/client/app/Story.ts +9 -4
  25. package/src/client/app/Variant.ts +10 -5
  26. package/src/client/app/__tests__/state-sync.spec.ts +113 -2
  27. package/src/client/app/__tests__/writable-binding.spec.ts +39 -0
  28. package/src/client/app/context.ts +17 -0
  29. package/src/client/app/render-context.ts +25 -5
  30. package/src/client/app/util.ts +88 -3
  31. package/src/client/context.ts +66 -0
  32. package/src/client/server/Story.ts +7 -7
  33. package/src/client/server/Variant.ts +13 -17
  34. package/src/client/server/__tests__/nesting-errors.spec.ts +48 -0
  35. package/src/client/server/context.ts +18 -0
  36. package/src/client/server/run.ts +7 -4
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
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,6 +24,7 @@ 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
30
  }), l = null;
@@ -1,10 +1,11 @@
1
- import { useRenderContext as e } from "./render-context.js";
2
- import { useInstance as t } from "./util.js";
3
- import n from "./Variant.js";
4
- import { cloneVNode as r, computed as i, defineComponent as a, h as o, isRef as s, provide as c, reactive as l, useAttrs as u } from "vue";
5
- 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";
6
7
  //#region src/client/app/Story.ts
7
- var f = a({
8
+ var m = c({
8
9
  name: "Story",
9
10
  __povesteType: "story",
10
11
  inheritAttrs: !1,
@@ -18,95 +19,95 @@ var f = a({
18
19
  default: void 0
19
20
  }
20
21
  },
21
- setup(n) {
22
- let a = t("Story"), o = u(), f = e(), p = i(() => o.story);
23
- c("story", p);
24
- let m = a.parent, h = l({});
25
- 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", {
26
27
  enumerable: !0,
27
28
  configurable: !0,
28
- get: () => m.data,
29
+ get: () => g.data,
29
30
  set: (e) => {
30
- Object.assign(m.data, e);
31
+ Object.assign(g.data, e);
31
32
  }
32
33
  });
33
- function g(e, t) {
34
+ function v(e, t) {
34
35
  let n = e[t];
35
- 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, {
36
37
  enumerable: !0,
37
38
  configurable: !0,
38
39
  get: () => {
39
40
  let n = e[t];
40
- return s(n) ? n.value : n;
41
+ return u(n) ? n.value : n;
41
42
  },
42
43
  set: (n) => {
43
44
  let r = e[t];
44
- 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;
45
46
  }
46
47
  });
47
48
  }
48
- for (let e in m.exposed) g(m.exposed, e);
49
- for (let e in m.devtoolsRawSetupState) g(m.devtoolsRawSetupState, e);
50
- for (let e in m.data) g(m.data, e);
51
- c("implicitState", () => h);
52
- function _() {
53
- n.meta && (o.story.meta || (o.story.meta = {}), Object.assign(o.story.meta, n.meta)), Object.assign(o.story, { slots: () => a.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 });
54
55
  }
55
56
  return {
56
- renderContext: f,
57
- story: p,
58
- renderMountStory: y,
59
- renderPreviewStory: x,
60
- updateStory: _
57
+ renderContext: m,
58
+ story: h,
59
+ renderMountStory: x,
60
+ renderPreviewStory: C,
61
+ updateStory: y
61
62
  };
62
- function v(e) {
63
+ function b(e) {
63
64
  let t = {};
64
- for (let n in a.attrs) e.props?.[n] === void 0 && (t[n] = a.attrs[n]);
65
- for (let n in o.story) !d.includes(n) && e.props?.[n] === void 0 && (t[n] = Reflect.get(o.story, n));
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));
66
67
  return t;
67
68
  }
68
- function y() {
69
- let e = 0, t = f?.targetVariantId, i = t ? o.story.variants.findIndex((e) => e.id === t) : -1, s = (t) => {
70
- let a = [];
71
- for (let c of t) {
72
- if (c.type?.__povesteType === "variant") {
73
- let t = o.story.variants[e];
74
- if (e++, !t || i !== -1 && e - 1 !== i) continue;
75
- let s = { variant: t };
76
- c.key ?? (s.key = t.id), !c.props?.initState && !c.props?.["init-state"] && (s.initState = n.initState), Object.assign(s, v(c)), a.push(r(c, s));
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));
77
78
  continue;
78
79
  }
79
- Array.isArray(c.children) && (c.children = s(c.children)), a.push(c);
80
+ Array.isArray(s.children) && (s.children = r(s.children)), i.push(s);
80
81
  }
81
- return a;
82
+ return i;
82
83
  };
83
- return s(a.slots.default?.() ?? []);
84
+ return r(c.slots.default?.() ?? []);
84
85
  }
85
- function b(e) {
86
+ function S(e) {
86
87
  let t = 0;
87
- for (let n of e) n?.type?.__povesteType === "variant" ? t++ : Array.isArray(n?.children) && (t += b(n.children));
88
+ for (let n of e) n?.type?.__povesteType === "variant" ? t++ : Array.isArray(n?.children) && (t += S(n.children));
88
89
  return t;
89
90
  }
90
- function x(e) {
91
+ function C(e) {
91
92
  e.nextVariantIndex.value = 0;
92
93
  let t = { state: e.externalState }, n = [];
93
- e.slotName === "controls" && n.push(...a.slots.controls?.(t) ?? []), (e.slotName === "default" || o.story.meta?.hasVariantChildComponents) && n.push(...a.slots.default?.(t) ?? []);
94
- let i = e.currentVariant;
95
- if (e.slotName === "default" && i && b(n) === o.story.variants.length) {
96
- let t = o.story.variants.findIndex((e) => e.id === i.id);
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);
97
98
  if (t !== -1) {
98
- let i = 0, a = !1, o = (e) => {
99
+ let r = 0, i = !1, a = (e) => {
99
100
  let n = [];
100
101
  for (let s of e) {
101
102
  if (s?.type?.__povesteType === "variant") {
102
- i === t && (n.push(r(s, v(s))), a = !0), i++;
103
+ r === t && (n.push(o(s, b(s))), i = !0), r++;
103
104
  continue;
104
105
  }
105
- Array.isArray(s?.children) && s.children.length && (s.children = o(s.children)), n.push(s);
106
+ Array.isArray(s?.children) && s.children.length && (s.children = a(s.children)), n.push(s);
106
107
  }
107
108
  return n;
108
- }, s = o(n);
109
- if (a) return e.nextVariantIndex.value = t, s;
109
+ }, s = a(n);
110
+ if (i) return e.nextVariantIndex.value = t, s;
110
111
  }
111
112
  }
112
113
  return n;
@@ -115,7 +116,7 @@ var f = a({
115
116
  render() {
116
117
  this.updateStory();
117
118
  let [e] = this.story.variants;
118
- if (e?.id === "_default") return o(n, {
119
+ if (e?.id === "_default") return l(a, {
119
120
  variant: e,
120
121
  ...this.initState ? { initState: this.initState } : {},
121
122
  implicit: !0,
@@ -126,4 +127,4 @@ var f = a({
126
127
  }
127
128
  });
128
129
  //#endregion
129
- export { f as default };
130
+ export { m as default };
@@ -1,10 +1,11 @@
1
- import { useRenderContext as e } from "./render-context.js";
2
- import { syncStateBundledAndExternal as t, toRawDeep as n, useInstance as r } from "./util.js";
3
- import { syncVariantAutoProps as i } from "./auto-props.js";
4
- import { computed as a, defineComponent 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 = o({
8
+ var p = c({
8
9
  name: "Variant",
9
10
  __povesteType: "variant",
10
11
  props: {
@@ -37,50 +38,50 @@ var f = o({
37
38
  default: !1
38
39
  }
39
40
  },
40
- async setup(o) {
41
- let f = l(), p = r("Variant"), m = s("story"), h = s("implicitState"), g = e(), _, v, y = null, 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 = a(() => f.variant);
46
- if (g?.mode !== "render" && typeof o.initState == "function" && x.value) {
47
- let e = await o.initState();
48
- u(x.value.state, n(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 = t(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.slots,
54
- source: o.source,
55
- responsiveDisabled: o.responsiveDisabled,
56
- autoPropsDisabled: o.autoPropsDisabled,
57
- setupApp: o.setupApp,
58
- meta: o.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
61
  });
61
- let t = m?.value;
62
- t && !o.implicit && !t.meta?.hasVariantChildComponents && (t.meta ||= {}, Object.assign(t.meta, { hasVariantChildComponents: !0 }));
62
+ let t = h?.value;
63
+ t && !c.implicit && !t.meta?.hasVariantChildComponents && (t.meta ||= {}, Object.assign(t.meta, { hasVariantChildComponents: !0 }));
63
64
  }
64
- function C() {
65
- 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;
66
67
  }
67
- function w(e, t) {
68
- if (t.slotName === "controls") return p.slots.controls?.({ state: t.externalState }) ?? null;
68
+ function T(e, t) {
69
+ if (t.slotName === "controls") return m.slots.controls?.({ state: t.externalState }) ?? null;
69
70
  if (t.slotName !== "default") return null;
70
- let n = p.slots.default?.({ state: t.externalState }) ?? null;
71
- return n && !e.autoPropsDisabled && (_ = i(e, n, t.externalState, _)), n;
71
+ let n = m.slots.default?.({ state: t.externalState }) ?? null;
72
+ return n && !e.autoPropsDisabled && (v = o(e, n, t.externalState, v)), n;
72
73
  }
73
- function T(e) {
74
- if (!h) return;
75
- let n = g?.mode === "render" && g.currentVariant?.id === e.id;
76
- n && !y ? y = t(e.state, h(), d) : !n && 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);
77
78
  }
78
- return x.value && S(x.value), {
79
- renderContext: g,
80
- renderVariantSlot: w,
81
- resolveVariant: C,
82
- syncRenderVariantState: T,
83
- updateVariant: S
79
+ return S.value && C(S.value), {
80
+ renderContext: _,
81
+ renderVariantSlot: T,
82
+ resolveVariant: w,
83
+ syncRenderVariantState: E,
84
+ updateVariant: C
84
85
  };
85
86
  },
86
87
  render() {
@@ -92,4 +93,4 @@ var f = o({
92
93
  }
93
94
  });
94
95
  //#endregion
95
- 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 };
@@ -25,7 +25,7 @@ function m(e) {
25
25
  function _() {
26
26
  g.value.forEach((e, t) => {
27
27
  let n = f.value?.querySelector(`[renderslotid="${t}"]`), r = o.value?.querySelector(`[slotid="${t}"]`);
28
- if (!(!n || !r)) {
28
+ if (n && r) {
29
29
  for (; r.lastChild;) r.removeChild(r.lastChild);
30
30
  r.appendChild(n);
31
31
  }
@@ -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,76 +1,81 @@
1
1
  import { isRef as e, unref as t, watch as n } from "@poveste/vendors/vue";
2
- import { getCurrentInstance as r, isRef as i, unref as a, watch as o } from "vue";
3
- import { applyState as s, createStateBaseline as c } 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 l = (e) => typeof e == "object" && !!e;
6
- function u(e, t = /* @__PURE__ */ new WeakMap()) {
7
- let n = i(e) ? a(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 (!l(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) => u(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), d(n, e, t), e;
18
+ return t.set(n, e), h(n, e, t), e;
18
19
  }
19
20
  }
20
- function d(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] = u(e[r], n);
23
+ t[r] = m(e[r], n);
23
24
  });
24
25
  }
25
- function f(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 (!l(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) => f(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), p(i, e, r), e;
38
+ return r.set(i, e), _(i, e, r), e;
37
39
  }
38
40
  }
39
- function p(e, t, n = /* @__PURE__ */ new WeakMap()) {
41
+ function _(e, t, n = /* @__PURE__ */ new WeakMap()) {
40
42
  Object.keys(e).forEach((r) => {
41
- t[r] = u(e[r], n);
43
+ t[r] = g(e[r], n);
42
44
  });
43
45
  }
44
- function m(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 h(e, t, r = []) {
51
- let i = c(), a = 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(m(f(e), r));
54
- n && s(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
- }), l = o(() => t, (t) => {
60
+ }), o = c(() => t, (t) => {
59
61
  if (t == null) return;
60
- let n = i.take(m(u(t), r));
61
- n && s(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
- a(), l();
69
+ a(), o();
68
70
  } };
69
71
  }
70
- function g(e) {
72
+ function b(e) {
73
+ return !(a(e) && i(e));
74
+ }
75
+ function x(e) {
71
76
  let t = r();
72
77
  if (!t) throw Error(`[poveste] <${e}> can only be set up inside a component`);
73
78
  return t;
74
79
  }
75
80
  //#endregion
76
- export { f as _toRawDeep, h as syncStateBundledAndExternal, u as toRawDeep, g as useInstance };
81
+ export { g as _toRawDeep, b as isWritableBinding, y as syncStateBundledAndExternal, m as toRawDeep, x as useInstance };
@@ -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,40 +39,40 @@ var a = t({
38
39
  default: void 0
39
40
  }
40
41
  },
41
- setup(e) {
42
- let t = n("hstStoryFile"), a = e.id ?? t?.id, o = e.title ?? t?.fileName;
43
- if (!a || o === void 0) throw Error("[poveste] a <Story> collected outside a story file needs an `id` and a `title`");
44
- let s = {
45
- id: a,
46
- title: o,
47
- group: e.group,
48
- layout: e.layout,
49
- icon: e.icon,
50
- iconColor: e.iconColor,
51
- docsOnly: e.docsOnly,
52
- 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,
53
54
  variants: []
54
55
  };
55
- return n("addStory", null)?.(s), i("story", s), i("addVariant", (e) => {
56
- s.variants.push(e);
57
- }), r(() => {
58
- s.variants.length || s.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({
59
60
  id: "_default",
60
61
  title: "default"
61
62
  });
62
- }), { story: s };
63
+ }), { story: l };
63
64
  },
64
65
  render() {
65
- let t = !1;
66
+ let e = !1;
66
67
  try {
67
- let n = this.$slots.default?.({ get state() {
68
- return t = !0, {};
68
+ let t = this.$slots.default?.({ get state() {
69
+ return e = !0, {};
69
70
  } });
70
- return Array.isArray(n) && e(n), n;
71
- } catch (e) {
72
- return t || console.error(e), null;
71
+ return Array.isArray(t) && i(t), t;
72
+ } catch (t) {
73
+ return e || console.error(t), null;
73
74
  }
74
75
  }
75
76
  });
76
77
  //#endregion
77
- 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,24 +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
- if (!n) throw Error("[poveste] a <Variant> with no `id` has to be inside a <Story>");
31
- return `${n.id}-${n.variants.length}`;
32
- }
33
- let i = {
34
- id: e.id ?? r(),
35
- title: e.title,
36
- icon: e.icon,
37
- iconColor: e.iconColor,
38
- meta: e.meta
39
- };
40
- 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
+ });
41
37
  },
42
38
  render() {
43
39
  return null;
44
40
  }
45
41
  });
46
42
  //#endregion
47
- 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 };