@poveste/plugin-vue 0.2.1 → 0.3.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.
@@ -1,55 +1,46 @@
1
- import { defineComponent as i, h as l, ref as m, watch as a, onMounted as s, onUnmounted as c } from "@poveste/vendors/vue";
2
- import { reactive as y } from "vue";
3
- import { createPreviewHost as d } from "./host.js";
4
- const v = i({
5
- name: "MountStory",
6
- props: {
7
- story: {
8
- type: Object,
9
- required: !0
10
- }
11
- },
12
- setup(e) {
13
- const n = m(), u = y({
14
- mode: "mount",
15
- slotName: "default",
16
- currentVariant: null,
17
- externalState: null,
18
- nextVariantIndex: {
19
- value: 0
20
- }
21
- });
22
- let t;
23
- async function o() {
24
- t = d({
25
- name: "MountStorySubApp",
26
- el: n.value,
27
- getStory: () => e.story,
28
- getVariant: () => null,
29
- renderContext: u
30
- }), await t.mount();
31
- }
32
- function r() {
33
- t?.unmount(), t = null;
34
- }
35
- return a(() => e.story.id, async () => {
36
- r(), await o();
37
- }), s(async () => {
38
- await o();
39
- }), a(() => e.story.variants, () => {
40
- t?.forceUpdate();
41
- }), c(() => {
42
- r();
43
- }), {
44
- el: n
45
- };
46
- },
47
- render() {
48
- return l("div", {
49
- ref: "el"
50
- });
51
- }
1
+ import { createPreviewHost as e } from "./host.js";
2
+ import { defineComponent as t, h as n, onMounted as r, onUnmounted as i, ref as a, watch as o } from "@poveste/vendors/vue";
3
+ import { reactive as s } from "vue";
4
+ //#region src/client/app/MountStory.ts
5
+ var c = t({
6
+ name: "MountStory",
7
+ props: { story: {
8
+ type: Object,
9
+ required: !0
10
+ } },
11
+ setup(t) {
12
+ let n = a(), c = s({
13
+ mode: "mount",
14
+ slotName: "default",
15
+ currentVariant: null,
16
+ externalState: null,
17
+ nextVariantIndex: { value: 0 }
18
+ }), l;
19
+ async function u() {
20
+ l = e({
21
+ name: "MountStorySubApp",
22
+ el: n.value,
23
+ getStory: () => t.story,
24
+ getVariant: () => null,
25
+ renderContext: c
26
+ }), await l.mount();
27
+ }
28
+ function d() {
29
+ l?.unmount(), l = null;
30
+ }
31
+ return o(() => t.story.id, async () => {
32
+ d(), await u();
33
+ }), r(async () => {
34
+ await u();
35
+ }), o(() => t.story.variants, () => {
36
+ l?.forceUpdate();
37
+ }), i(() => {
38
+ d();
39
+ }), { el: n };
40
+ },
41
+ render() {
42
+ return n("div", { ref: "el" });
43
+ }
52
44
  });
53
- export {
54
- v as default
55
- };
45
+ //#endregion
46
+ export { c as default };
@@ -1,74 +1,67 @@
1
- import { defineComponent as v, h as S, ref as x, onMounted as V, watch as c, onBeforeUnmount as g } from "@poveste/vendors/vue";
2
- import { reactive as m } from "vue";
3
- import { createPreviewHost as N } from "./host.js";
4
- import { syncStateBundledAndExternal as l } from "./util.js";
5
- const j = v({
6
- name: "RenderStory",
7
- props: {
8
- variant: {
9
- type: Object,
10
- required: !0
11
- },
12
- story: {
13
- type: Object,
14
- required: !0
15
- },
16
- slotName: {
17
- type: String,
18
- default: "default"
19
- }
20
- },
21
- emits: {
22
- ready: () => !0
23
- },
24
- setup(t, { emit: f }) {
25
- const o = x();
26
- let e, n = !1;
27
- const r = m({});
28
- let i = l(t.variant.state, r);
29
- const a = m({
30
- mode: "render",
31
- slotName: t.slotName,
32
- currentVariant: t.variant,
33
- externalState: r,
34
- nextVariantIndex: {
35
- value: 0
36
- }
37
- });
38
- function u() {
39
- e?.unmount(), e = null;
40
- }
41
- function s() {
42
- i?.stop(), i = l(t.variant.state, r);
43
- }
44
- async function d() {
45
- n || (n = !0, u(), a.currentVariant = t.variant, a.slotName = t.slotName, e = N({
46
- name: "RenderStorySubApp",
47
- el: o.value,
48
- getStory: () => t.story,
49
- getVariant: () => t.variant,
50
- renderContext: a,
51
- wrapInDiv: !0
52
- }), await e.mount(), n = !1, f("ready"));
53
- }
54
- return V(async () => {
55
- t.variant.configReady && await d();
56
- }), c(() => t.variant, () => {
57
- a.currentVariant = t.variant, s();
58
- }), c(() => [t.story.id, t.slotName, t.variant.id, t.variant.configReady], async ([, y]) => {
59
- a.currentVariant = t.variant, a.slotName = y, t.variant.configReady && !n && (e ? e.forceUpdate() : await d());
60
- }), g(() => {
61
- i?.stop(), u();
62
- }), {
63
- sandbox: o
64
- };
65
- },
66
- render() {
67
- return S("div", {
68
- ref: "sandbox"
69
- });
70
- }
1
+ import { syncStateBundledAndExternal as e } from "./util.js";
2
+ import { createPreviewHost as t } from "./host.js";
3
+ import { defineComponent as n, h as r, onBeforeUnmount as i, onMounted as a, ref as o, watch as s } from "@poveste/vendors/vue";
4
+ import { reactive as c } from "vue";
5
+ //#region src/client/app/RenderStory.ts
6
+ var l = n({
7
+ name: "RenderStory",
8
+ props: {
9
+ variant: {
10
+ type: Object,
11
+ required: !0
12
+ },
13
+ story: {
14
+ type: Object,
15
+ required: !0
16
+ },
17
+ slotName: {
18
+ type: String,
19
+ default: "default"
20
+ }
21
+ },
22
+ emits: { ready: () => !0 },
23
+ setup(n, { emit: r }) {
24
+ let l = o(), u, d = !1, f = c({}), p = e(n.variant.state, f), m = c({
25
+ mode: "render",
26
+ slotName: n.slotName,
27
+ currentVariant: n.variant,
28
+ externalState: f,
29
+ nextVariantIndex: { value: 0 }
30
+ });
31
+ function h() {
32
+ u?.unmount(), u = null;
33
+ }
34
+ function g() {
35
+ p?.stop(), p = e(n.variant.state, f);
36
+ }
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"));
46
+ }
47
+ return a(async () => {
48
+ n.variant.configReady && await _();
49
+ }), s(() => n.variant, () => {
50
+ m.currentVariant = n.variant, g();
51
+ }), s(() => [
52
+ n.story.id,
53
+ n.slotName,
54
+ n.variant.id,
55
+ n.variant.configReady
56
+ ], async ([, e]) => {
57
+ m.currentVariant = n.variant, m.slotName = e, n.variant.configReady && !d && (u ? u.forceUpdate() : await _());
58
+ }), i(() => {
59
+ p?.stop(), h();
60
+ }), { sandbox: l };
61
+ },
62
+ render() {
63
+ return r("div", { ref: "sandbox" });
64
+ }
71
65
  });
72
- export {
73
- j as default
74
- };
66
+ //#endregion
67
+ export { l as default };
@@ -1,40 +1,39 @@
1
- import { defineComponent as r, computed as e, h as a } from "vue";
2
- const s = {
3
- path: "/",
4
- name: void 0,
5
- redirectedFrom: void 0,
6
- params: {},
7
- query: {},
8
- hash: "",
9
- fullPath: "/",
10
- matched: [],
11
- meta: {},
12
- href: "/"
13
- }, n = r({
14
- name: "RouterLinkStub",
15
- compatConfig: { MODE: 3 },
16
- props: {
17
- to: {
18
- type: [String, Object],
19
- required: !0
20
- },
21
- custom: {
22
- type: Boolean,
23
- default: !1
24
- }
25
- },
26
- render() {
27
- const t = e(() => s), o = this.$slots?.default?.({
28
- route: t,
29
- href: e(() => t.value.href),
30
- isActive: e(() => !1),
31
- isExactActive: e(() => !1),
32
- navigate: async () => {
33
- }
34
- });
35
- return this.custom ? o : a("a", void 0, o);
36
- }
1
+ import { computed as e, defineComponent as t, h as n } from "vue";
2
+ //#region src/client/app/RouterLinkStub.ts
3
+ var r = {
4
+ path: "/",
5
+ name: void 0,
6
+ redirectedFrom: void 0,
7
+ params: {},
8
+ query: {},
9
+ hash: "",
10
+ fullPath: "/",
11
+ matched: [],
12
+ meta: {},
13
+ href: "/"
14
+ }, i = t({
15
+ name: "RouterLinkStub",
16
+ compatConfig: { MODE: 3 },
17
+ props: {
18
+ to: {
19
+ type: [String, Object],
20
+ required: !0
21
+ },
22
+ custom: {
23
+ type: Boolean,
24
+ default: !1
25
+ }
26
+ },
27
+ render() {
28
+ let t = e(() => r), i = this.$slots?.default?.({
29
+ route: t,
30
+ href: e(() => t.value.href),
31
+ isActive: e(() => !1),
32
+ isExactActive: e(() => !1),
33
+ navigate: async () => {}
34
+ });
35
+ return this.custom ? i : n("a", void 0, i);
36
+ }
37
37
  });
38
- export {
39
- n as RouterLinkStub
40
- };
38
+ //#endregion
39
+ export { i as RouterLinkStub };
@@ -1,112 +1,99 @@
1
- import { omitInheritStoryProps as g } from "@poveste/shared";
2
- import { defineComponent as j, h as $, getCurrentInstance as C, useAttrs as O, computed as P, provide as S, reactive as _, isRef as h, cloneVNode as A } from "vue";
3
- import { useRenderContext as I } from "./render-context.js";
4
- import R from "./Variant.js";
5
- const F = j({
6
- name: "Story",
7
- __povesteType: "story",
8
- inheritAttrs: !1,
9
- props: {
10
- initState: {
11
- type: Function,
12
- default: void 0
13
- },
14
- meta: {
15
- type: Object,
16
- default: void 0
17
- }
18
- },
19
- setup(p) {
20
- const a = C(), n = O(), f = I(), y = P(() => n.story);
21
- S("story", y);
22
- const s = a.parent, d = _({});
23
- Object.defineProperty(d, "$data", {
24
- enumerable: !0,
25
- configurable: !0,
26
- get: () => s.data,
27
- set: (t) => {
28
- Object.assign(s.data, t);
29
- }
30
- });
31
- function l(t, o) {
32
- const c = t[o];
33
- typeof c == "function" || c?.__file || typeof c?.render == "function" || typeof c?.setup == "function" || Object.defineProperty(d, o, {
34
- enumerable: !0,
35
- configurable: !0,
36
- get: () => {
37
- const r = t[o];
38
- return h(r) ? r.value : r;
39
- },
40
- set: (r) => {
41
- const e = t[o];
42
- h(e) ? e.value = r : e && typeof e == "object" && r && typeof r == "object" ? Object.assign(e, r) : t[o] = r;
43
- }
44
- });
45
- }
46
- for (const t in s.exposed)
47
- l(s.exposed, t);
48
- for (const t in s.devtoolsRawSetupState)
49
- l(s.devtoolsRawSetupState, t);
50
- for (const t in s.data)
51
- l(s.data, t);
52
- S("implicitState", () => d);
53
- function v() {
54
- p.meta && (n.story.meta || (n.story.meta = {}), Object.assign(n.story.meta, p.meta)), Object.assign(n.story, {
55
- slots: () => a.proxy.$slots
56
- });
57
- }
58
- return {
59
- renderContext: f,
60
- story: y,
61
- renderMountStory: x,
62
- renderPreviewStory: b,
63
- updateStory: v
64
- };
65
- function x() {
66
- let t = 0;
67
- const o = (c) => {
68
- const r = [];
69
- for (const e of c) {
70
- if (e.type?.__povesteType === "variant") {
71
- const m = n.story.variants[t];
72
- if (t++, !m)
73
- continue;
74
- const u = {
75
- variant: m
76
- };
77
- !e.props?.initState && !e.props?.["init-state"] && (u.initState = p.initState);
78
- for (const i in a.proxy.$attrs)
79
- typeof e.props?.[i] > "u" && (u[i] = a.proxy.$attrs[i]);
80
- for (const i in n.story)
81
- !g.includes(i) && typeof e.props?.[i] > "u" && (u[i] = n.story[i]);
82
- r.push(A(e, u));
83
- continue;
84
- }
85
- Array.isArray(e.children) && (e.children = o(e.children)), r.push(e);
86
- }
87
- return r;
88
- };
89
- return o(a.proxy.$slots.default?.() ?? []);
90
- }
91
- function b() {
92
- f.nextVariantIndex.value = 0;
93
- const t = {
94
- state: f.externalState
95
- }, o = [];
96
- return f.slotName === "controls" && o.push(...a.proxy.$slots.controls?.(t) ?? []), (f.slotName === "default" || n.story.meta?.hasVariantChildComponents) && o.push(...a.proxy.$slots.default?.(t) ?? []), o;
97
- }
98
- },
99
- render() {
100
- this.updateStory();
101
- const [p] = this.story.variants;
102
- return p?.id === "_default" ? $(R, {
103
- variant: p,
104
- initState: this.initState,
105
- implicit: !0,
106
- ...this.$attrs
107
- }, this.$slots) : this.renderContext?.mode === "render" ? this.renderPreviewStory() : this.renderMountStory();
108
- }
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";
5
+ //#region src/client/app/Story.ts
6
+ var f = i({
7
+ name: "Story",
8
+ __povesteType: "story",
9
+ inheritAttrs: !1,
10
+ props: {
11
+ initState: {
12
+ type: Function,
13
+ default: void 0
14
+ },
15
+ meta: {
16
+ type: Object,
17
+ default: void 0
18
+ }
19
+ },
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", {
25
+ enumerable: !0,
26
+ configurable: !0,
27
+ get: () => m.data,
28
+ set: (e) => {
29
+ Object.assign(m.data, e);
30
+ }
31
+ });
32
+ function g(e, t) {
33
+ let n = e[t];
34
+ typeof n == "function" || n?.__file || typeof n?.render == "function" || typeof n?.setup == "function" || Object.defineProperty(h, t, {
35
+ enumerable: !0,
36
+ configurable: !0,
37
+ get: () => {
38
+ let n = e[t];
39
+ return s(n) ? n.value : n;
40
+ },
41
+ set: (n) => {
42
+ 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;
44
+ }
45
+ });
46
+ }
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 });
53
+ }
54
+ return {
55
+ renderContext: f,
56
+ story: p,
57
+ renderMountStory: v,
58
+ renderPreviewStory: y,
59
+ updateStory: _
60
+ };
61
+ function v() {
62
+ let e = 0, r = (a) => {
63
+ let s = [];
64
+ for (let c of a) {
65
+ if (c.type?.__povesteType === "variant") {
66
+ let r = o.story.variants[e];
67
+ if (e++, !r) continue;
68
+ let a = { variant: r };
69
+ !c.props?.initState && !c.props?.["init-state"] && (a.initState = t.initState);
70
+ for (let e in i.proxy.$attrs) c.props?.[e] === void 0 && (a[e] = i.proxy.$attrs[e]);
71
+ for (let e in o.story) !d.includes(e) && c.props?.[e] === void 0 && (a[e] = o.story[e]);
72
+ s.push(n(c, a));
73
+ continue;
74
+ }
75
+ Array.isArray(c.children) && (c.children = r(c.children)), s.push(c);
76
+ }
77
+ return s;
78
+ };
79
+ return r(i.proxy.$slots.default?.() ?? []);
80
+ }
81
+ function y() {
82
+ f.nextVariantIndex.value = 0;
83
+ let e = { state: f.externalState }, t = [];
84
+ return f.slotName === "controls" && t.push(...i.proxy.$slots.controls?.(e) ?? []), (f.slotName === "default" || o.story.meta?.hasVariantChildComponents) && t.push(...i.proxy.$slots.default?.(e) ?? []), t;
85
+ }
86
+ },
87
+ render() {
88
+ this.updateStory();
89
+ let [e] = this.story.variants;
90
+ return e?.id === "_default" ? o(t, {
91
+ variant: e,
92
+ initState: this.initState,
93
+ implicit: !0,
94
+ ...this.$attrs
95
+ }, this.$slots) : this.renderContext?.mode === "render" ? this.renderPreviewStory() : this.renderMountStory();
96
+ }
109
97
  });
110
- export {
111
- F as default
112
- };
98
+ //#endregion
99
+ export { f as default };