@poveste/plugin-vue 0.2.1 → 0.3.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.
- package/dist/bundled/client/app/MountStory.js +45 -54
- package/dist/bundled/client/app/RenderStory.js +66 -73
- package/dist/bundled/client/app/RouterLinkStub.js +38 -39
- package/dist/bundled/client/app/Story.js +98 -111
- package/dist/bundled/client/app/Variant.js +89 -103
- package/dist/bundled/client/app/auto-props.js +46 -62
- package/dist/bundled/client/app/global-components.js +63 -79
- package/dist/bundled/client/app/host.js +72 -76
- package/dist/bundled/client/app/index.js +3 -6
- package/dist/bundled/client/app/render-context.js +9 -10
- package/dist/bundled/client/app/util.js +68 -65
- package/dist/bundled/client/client.js +4 -9
- package/dist/bundled/client/codegen.js +143 -190
- package/dist/bundled/client/server/Story.js +74 -78
- package/dist/bundled/client/server/Variant.js +45 -45
- package/dist/bundled/client/server/run.js +41 -42
- package/dist/bundled/client/server/stub.js +9 -7
- package/dist/bundled/client/server.js +1 -3
- package/dist/client/app/Story.d.ts +1 -1
- package/dist/client/app/host.d.ts +1 -1
- package/dist/client/server/Story.d.ts +2 -2
- package/dist/client/server/Variant.d.ts +1 -1
- package/package.json +11 -8
- package/src/client/app/Variant.ts +15 -5
- package/src/client/app/__tests__/state-sync.spec.ts +154 -0
- package/src/client/app/host.ts +2 -1
- package/src/client/app/util.ts +24 -10
- package/src/client/codegen.ts +1 -1
- package/src/client/server/Variant.ts +2 -1
- package/tsconfig.json +1 -1
- package/vitest.config.ts +13 -0
|
@@ -1,55 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { c as default };
|
|
@@ -1,74 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { l as default };
|
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { i as RouterLinkStub };
|
|
@@ -1,112 +1,99 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
};
|
|
98
|
+
//#endregion
|
|
99
|
+
export { f as default };
|