@poveste/plugin-vue 0.1.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 (81) hide show
  1. package/LICENSE +22 -0
  2. package/client.d.ts +2 -0
  3. package/collect.d.ts +2 -0
  4. package/components.d.ts +239 -0
  5. package/dist/bundled/client/app/MountStory.js +55 -0
  6. package/dist/bundled/client/app/RenderStory.js +74 -0
  7. package/dist/bundled/client/app/RouterLinkStub.js +40 -0
  8. package/dist/bundled/client/app/Story.js +112 -0
  9. package/dist/bundled/client/app/Variant.js +104 -0
  10. package/dist/bundled/client/app/auto-props.js +66 -0
  11. package/dist/bundled/client/app/global-components.js +81 -0
  12. package/dist/bundled/client/app/host.js +84 -0
  13. package/dist/bundled/client/app/index.js +6 -0
  14. package/dist/bundled/client/app/render-context.js +12 -0
  15. package/dist/bundled/client/app/util.js +70 -0
  16. package/dist/bundled/client/client.js +10 -0
  17. package/dist/bundled/client/codegen.js +196 -0
  18. package/dist/bundled/client/server/Story.js +79 -0
  19. package/dist/bundled/client/server/Variant.js +46 -0
  20. package/dist/bundled/client/server/run.js +51 -0
  21. package/dist/bundled/client/server/stub.js +8 -0
  22. package/dist/bundled/client/server.js +4 -0
  23. package/dist/bundled/node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.js +118 -0
  24. package/dist/client/app/MountStory.d.ts +16 -0
  25. package/dist/client/app/RenderStory.d.ts +38 -0
  26. package/dist/client/app/RouterLinkStub.d.ts +21 -0
  27. package/dist/client/app/Story.d.ts +33 -0
  28. package/dist/client/app/Variant.d.ts +78 -0
  29. package/dist/client/app/auto-props.d.ts +2 -0
  30. package/dist/client/app/global-components.d.ts +2 -0
  31. package/dist/client/app/host.d.ts +16 -0
  32. package/dist/client/app/index.d.ts +2 -0
  33. package/dist/client/app/render-context.d.ts +12 -0
  34. package/dist/client/app/util.d.ts +16 -0
  35. package/dist/client/client.d.ts +7 -0
  36. package/dist/client/codegen.d.ts +4 -0
  37. package/dist/client/server/Story.d.ts +81 -0
  38. package/dist/client/server/Variant.d.ts +52 -0
  39. package/dist/client/server/run.d.ts +2 -0
  40. package/dist/client/server/stub.d.ts +1 -0
  41. package/dist/client/server.d.ts +1 -0
  42. package/dist/commands/generate-story.client.d.ts +3 -0
  43. package/dist/commands/generate-story.client.js +27 -0
  44. package/dist/commands/generate-story.server.d.ts +3 -0
  45. package/dist/commands/generate-story.server.js +45 -0
  46. package/dist/helpers.d.ts +10 -0
  47. package/dist/helpers.js +3 -0
  48. package/dist/index.d.ts +1 -0
  49. package/dist/index.js +1 -0
  50. package/dist/index.node.d.ts +3 -0
  51. package/dist/index.node.js +54 -0
  52. package/dist/util/list-components.d.ts +1 -0
  53. package/dist/util/list-components.js +15 -0
  54. package/package.json +71 -0
  55. package/src/client/app/MountStory.ts +83 -0
  56. package/src/client/app/RenderStory.ts +131 -0
  57. package/src/client/app/RouterLinkStub.ts +48 -0
  58. package/src/client/app/Story.ts +209 -0
  59. package/src/client/app/Variant.ts +196 -0
  60. package/src/client/app/auto-props.ts +135 -0
  61. package/src/client/app/global-components.ts +131 -0
  62. package/src/client/app/host.ts +139 -0
  63. package/src/client/app/index.ts +2 -0
  64. package/src/client/app/render-context.ts +23 -0
  65. package/src/client/app/util.ts +129 -0
  66. package/src/client/client.ts +8 -0
  67. package/src/client/codegen.ts +400 -0
  68. package/src/client/server/Story.ts +121 -0
  69. package/src/client/server/Variant.ts +56 -0
  70. package/src/client/server/run.ts +63 -0
  71. package/src/client/server/stub.ts +12 -0
  72. package/src/client/server.ts +1 -0
  73. package/src/commands/generate-story.client.ts +29 -0
  74. package/src/commands/generate-story.server.ts +55 -0
  75. package/src/helpers.ts +15 -0
  76. package/src/index.node.ts +63 -0
  77. package/src/index.ts +1 -0
  78. package/src/util/list-components.ts +16 -0
  79. package/tsconfig.build.json +6 -0
  80. package/tsconfig.json +40 -0
  81. package/vite.config.ts +70 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Guillaume Chau (original "histoire" project)
4
+ Copyright (c) 2026 Sorin Gitlan (poveste fork)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/client.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ // https://github.com/microsoft/TypeScript/issues/33079
2
+ export * from './dist/client/client'
package/collect.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ // https://github.com/microsoft/TypeScript/issues/33079
2
+ export * from './dist/client/server'
@@ -0,0 +1,239 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+
3
+ import type {
4
+ StoryLayout,
5
+ Story,
6
+ Variant,
7
+ StoryMeta,
8
+ VariantMeta,
9
+ } from '@poveste/shared'
10
+ import type {
11
+ HstButton,
12
+ HstButtonGroup,
13
+ HstCheckbox,
14
+ HstCheckboxList,
15
+ HstText,
16
+ HstNumber,
17
+ HstSlider,
18
+ HstTextarea,
19
+ HstSelect,
20
+ HstRadio,
21
+ HstJson,
22
+ HstColorShades,
23
+ HstTokenList,
24
+ HstTokenGrid,
25
+ HstCopyIcon,
26
+ HstColorSelect,
27
+ } from '@poveste/controls'
28
+
29
+ // Utils
30
+
31
+ declare type NonUndefinedable<T> = T extends undefined ? never : T
32
+ declare type TypePropsToRuntimeProps<T> = {
33
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
34
+ type: import('vue').PropType<NonUndefinedable<T[K]>>
35
+ } : {
36
+ type: import('vue').PropType<T[K]>
37
+ required: true
38
+ }
39
+ }
40
+
41
+ // <Story>
42
+
43
+ interface VueStoryProps {
44
+ /**
45
+ * Title of the story.
46
+ */
47
+ title?: string
48
+ /**
49
+ * Id of the story used in the URL. By default, the id is automatically generated from the file path. Setting an id manually will ensure the URL parameter doesn't change with the order of the variants in the story.
50
+ */
51
+ id?: string
52
+ /**
53
+ * Layout of the story.
54
+ */
55
+ layout?: StoryLayout
56
+ /**
57
+ * A function to configure the Vue application. This will be the default for the variants in the story.
58
+ */
59
+ setupApp?: (payload: { app: import('vue').App, story: Story, variant: Variant }) => void | Promise<void>
60
+ /**
61
+ * The id of a group to include the story in.
62
+ */
63
+ group?: string
64
+ /**
65
+ * An Iconify id to customize the story icon in the tree.
66
+ * https://icones.js.org/
67
+ */
68
+ icon?: string
69
+ /**
70
+ * The icon color.
71
+ * Example: `#8B5CF6`
72
+ */
73
+ iconColor?: string
74
+ /**
75
+ * This story will only render a documentation page.
76
+ */
77
+ docsOnly?: boolean
78
+ /**
79
+ * The copyable source code of the story.
80
+ */
81
+ source?: string
82
+ /**
83
+ * Disables the responsive menu, preview resize handles and makes the preview laways fit the available space.
84
+ */
85
+ responsiveDisabled?: boolean
86
+ /**
87
+ * Free form meta data.
88
+ *
89
+ * You can type it with:
90
+ *
91
+ * ```ts
92
+ * declare module 'poveste' {
93
+ * // For both Story and Variant
94
+ * interface CommonMeta {
95
+ * myMeta: string
96
+ * }
97
+ *
98
+ * // Only for Story
99
+ * interface StoryMeta {
100
+ * myMeta: string
101
+ * }
102
+ * }
103
+ * ```
104
+ */
105
+ meta?: StoryMeta
106
+ }
107
+
108
+ type VueStoryComponent = import('vue').DefineComponent<
109
+ TypePropsToRuntimeProps<VueStoryProps>, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, Readonly<import('vue').ExtractPropTypes<TypePropsToRuntimeProps<VueStoryProps>>> & {}, import('vue').ExtractDefaultPropTypes<TypePropsToRuntimeProps<VueStoryProps>>, import('vue').SlotsType
110
+ >
111
+
112
+ interface VueStoryPropsGeneric<S extends Record<string, any>> {
113
+ initState?: () => S
114
+ }
115
+
116
+ interface VueStoryInternalPropsGeneric<S extends Record<string, any>> {
117
+ readonly $props: {
118
+ /**
119
+ * Function that returns the intial state. Will be used as default value for variants.
120
+ */
121
+ initState?: () => S
122
+ }
123
+ readonly $slots: {
124
+ default: import('vue').Slot<{ state: S }>
125
+ controls: import('vue').Slot<{ state: S }>
126
+ }
127
+ }
128
+
129
+ type VueStoryComponentGeneric = new <S extends Record<string, any> = Record<string, any>>(props: VueStoryPropsGeneric<S>) => VueStoryInternalPropsGeneric<S>;
130
+
131
+ declare const VueStoryComponent: VueStoryComponent & VueStoryComponentGeneric
132
+
133
+ declare const MeowVueStoryComponent: import('vue').Component<TypePropsToRuntimeProps<VueStoryProps>>
134
+
135
+ // <Variant>
136
+
137
+ interface VueVariantProps {
138
+ /**
139
+ * Title of the variant.
140
+ */
141
+ title?: string
142
+ /**
143
+ * Id of the variant used in the URL. By default, the id is automatically generated with the index of the variant in the list. Setting an id manually will ensure the URL parameter doesn't change with the order of the variants in the story.
144
+ */
145
+ id?: string
146
+ /**
147
+ * A function to configure the Vue application.
148
+ */
149
+ setupApp?: (payload: { app: import('vue').App, story: Story, variant: Variant }) => void | Promise<void>
150
+ /**
151
+ * An Iconify id to customize the variant icon in the UI.
152
+ * https://icones.js.org/
153
+ */
154
+ icon?: string
155
+ /**
156
+ * The icon color.
157
+ * Example: `#8B5CF6`
158
+ */
159
+ iconColor?: string
160
+ /**
161
+ * The copyable source code of the variant.
162
+ */
163
+ source?: string
164
+ /**
165
+ * Disables the responsive menu, preview resize handles and makes the preview laways fit the available space.
166
+ */
167
+ responsiveDisabled?: boolean
168
+ /**
169
+ * Free form meta data.
170
+ *
171
+ * You can type it with:
172
+ *
173
+ * ```ts
174
+ * declare module 'poveste' {
175
+ * // For both Story and Variant
176
+ * interface CommonMeta {
177
+ * myMeta: string
178
+ * }
179
+ *
180
+ * // Only for Variant
181
+ * interface VariantMeta {
182
+ * myMeta: string
183
+ * }
184
+ * }
185
+ * ```
186
+ */
187
+ variant?: VariantMeta
188
+ }
189
+
190
+ type VueVariantComponent = import('vue').DefineComponent<
191
+ TypePropsToRuntimeProps<VueVariantProps>, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, Readonly<import('vue').ExtractPropTypes<TypePropsToRuntimeProps<VueVariantProps>>> & {}, import('vue').ExtractDefaultPropTypes<TypePropsToRuntimeProps<VueStoryProps>>, import('vue').SlotsType
192
+ >
193
+
194
+ interface VueVariantPropsGeneric<S extends Record<string, any>> {
195
+ initState?: () => S
196
+ }
197
+
198
+ interface VueVariantInternalPropsGeneric<S extends Record<string, any>> {
199
+ readonly $props: {
200
+ /**
201
+ * Function that returns the intial state.
202
+ */
203
+ initState?: () => S
204
+ }
205
+ readonly $slots: {
206
+ default: import('vue').Slot<{ state: S }>
207
+ controls: import('vue').Slot<{ state: S }>
208
+ }
209
+ }
210
+
211
+ type VueVariantComponentGeneric = new <S extends Record<string, any> = Record<string, any>>(props: VueVariantPropsGeneric<S>) => VueVariantInternalPropsGeneric<S>;
212
+
213
+ declare const VueVariantComponent: VueVariantComponent & VueVariantComponentGeneric
214
+
215
+ // Register global components
216
+
217
+ declare module 'vue' {
218
+ export interface GlobalComponents {
219
+ Story: typeof VueStoryComponent
220
+ Variant: typeof VueVariantComponent
221
+ // Controls
222
+ HstButton: typeof HstButton
223
+ HstButtonGroup: typeof HstButtonGroup
224
+ HstCheckbox: typeof HstCheckbox
225
+ HstCheckboxList: typeof HstCheckboxList
226
+ HstText: typeof HstText
227
+ HstNumber: typeof HstNumber
228
+ HstSlider: typeof HstSlider
229
+ HstTextarea: typeof HstTextarea
230
+ HstSelect: typeof HstSelect
231
+ HstRadio: typeof HstRadio
232
+ HstJson: typeof HstJson
233
+ HstColorShades: typeof HstColorShades
234
+ HstTokenList: typeof HstTokenList
235
+ HstTokenGrid: typeof HstTokenGrid
236
+ HstCopyIcon: typeof HstCopyIcon
237
+ HstColorSelect: typeof HstColorSelect
238
+ }
239
+ }
@@ -0,0 +1,55 @@
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
+ }
52
+ });
53
+ export {
54
+ v as default
55
+ };
@@ -0,0 +1,74 @@
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
+ }
71
+ });
72
+ export {
73
+ j as default
74
+ };
@@ -0,0 +1,40 @@
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
+ }
37
+ });
38
+ export {
39
+ n as RouterLinkStub
40
+ };
@@ -0,0 +1,112 @@
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 h, reactive as _, isRef as S, 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
+ __histoireType: "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(c) {
20
+ const a = C(), n = O(), p = I(), y = P(() => n.story);
21
+ h("story", y);
22
+ const i = a.parent, d = _({});
23
+ Object.defineProperty(d, "$data", {
24
+ enumerable: !0,
25
+ configurable: !0,
26
+ get: () => i.data,
27
+ set: (t) => {
28
+ Object.assign(i.data, t);
29
+ }
30
+ });
31
+ function l(t, o) {
32
+ const f = t[o];
33
+ typeof f == "function" || f?.__file || typeof f?.render == "function" || typeof f?.setup == "function" || Object.defineProperty(d, o, {
34
+ enumerable: !0,
35
+ configurable: !0,
36
+ get: () => {
37
+ const r = t[o];
38
+ return S(r) ? r.value : r;
39
+ },
40
+ set: (r) => {
41
+ const e = t[o];
42
+ S(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 i.exposed)
47
+ l(i.exposed, t);
48
+ for (const t in i.devtoolsRawSetupState)
49
+ l(i.devtoolsRawSetupState, t);
50
+ for (const t in i.data)
51
+ l(i.data, t);
52
+ h("implicitState", () => d);
53
+ function v() {
54
+ c.meta && (n.story.meta || (n.story.meta = {}), Object.assign(n.story.meta, c.meta)), Object.assign(n.story, {
55
+ slots: () => a.proxy.$slots
56
+ });
57
+ }
58
+ return {
59
+ renderContext: p,
60
+ story: y,
61
+ renderMountStory: x,
62
+ renderPreviewStory: b,
63
+ updateStory: v
64
+ };
65
+ function x() {
66
+ let t = 0;
67
+ const o = (f) => {
68
+ const r = [];
69
+ for (const e of f) {
70
+ if (e.type?.__histoireType === "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 = c.initState);
78
+ for (const s in a.proxy.$attrs)
79
+ typeof e.props?.[s] > "u" && (u[s] = a.proxy.$attrs[s]);
80
+ for (const s in n.story)
81
+ !g.includes(s) && typeof e.props?.[s] > "u" && (u[s] = n.story[s]);
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
+ p.nextVariantIndex.value = 0;
93
+ const t = {
94
+ state: p.externalState
95
+ }, o = [];
96
+ return p.slotName === "controls" && o.push(...a.proxy.$slots.controls?.(t) ?? []), (p.slotName === "default" || n.story.meta?.hasVariantChildComponents) && o.push(...a.proxy.$slots.default?.(t) ?? []), o;
97
+ }
98
+ },
99
+ render() {
100
+ this.updateStory();
101
+ const [c] = this.story.variants;
102
+ return c?.id === "_default" ? $(R, {
103
+ variant: c,
104
+ initState: this.initState,
105
+ implicit: !0,
106
+ ...this.$attrs
107
+ }, this.$slots) : this.renderContext?.mode === "render" ? this.renderPreviewStory() : this.renderMountStory();
108
+ }
109
+ });
110
+ export {
111
+ F as default
112
+ };
@@ -0,0 +1,104 @@
1
+ import { applyState as V } from "@poveste/shared";
2
+ import { defineComponent as x, useAttrs as h, getCurrentInstance as b, inject as p, computed as C, onBeforeUnmount as D } from "vue";
3
+ import { syncVariantAutoProps as A } from "./auto-props.js";
4
+ import { useRenderContext as P } from "./render-context.js";
5
+ import { toRawDeep as g, syncStateBundledAndExternal as m } from "./util.js";
6
+ const $ = x({
7
+ name: "Variant",
8
+ __histoireType: "variant",
9
+ props: {
10
+ initState: {
11
+ type: Function,
12
+ default: void 0
13
+ },
14
+ source: {
15
+ type: String,
16
+ default: void 0
17
+ },
18
+ responsiveDisabled: {
19
+ type: Boolean,
20
+ default: !1
21
+ },
22
+ autoPropsDisabled: {
23
+ type: Boolean,
24
+ default: !1
25
+ },
26
+ setupApp: {
27
+ type: Function,
28
+ default: void 0
29
+ },
30
+ meta: {
31
+ type: Object,
32
+ default: void 0
33
+ },
34
+ implicit: {
35
+ type: Boolean,
36
+ default: !1
37
+ }
38
+ },
39
+ async setup(t) {
40
+ const l = h(), u = b(), o = p("story"), s = p("implicitState"), e = P();
41
+ let c, d, a;
42
+ const r = C(() => l.variant);
43
+ if (e?.mode !== "render" && typeof t.initState == "function" && r.value) {
44
+ const n = await t.initState();
45
+ V(r.value.state, g(n));
46
+ }
47
+ e?.mode !== "render" && r.value && s && m(r.value.state, s());
48
+ function f(n) {
49
+ Object.assign(n, {
50
+ slots: () => u.proxy.$slots,
51
+ source: t.source,
52
+ responsiveDisabled: t.responsiveDisabled,
53
+ autoPropsDisabled: t.autoPropsDisabled,
54
+ setupApp: t.setupApp,
55
+ meta: t.meta,
56
+ configReady: !0
57
+ }), !t.implicit && !o.value?.meta?.hasVariantChildComponents && (o.value.meta || (o.value.meta = {}), Object.assign(o.value.meta, {
58
+ hasVariantChildComponents: !0
59
+ }));
60
+ }
61
+ function v() {
62
+ return l.variant ? l.variant : e?.mode !== "render" ? null : (d || (d = o.value?.variants[e.nextVariantIndex.value], e.nextVariantIndex.value++), d);
63
+ }
64
+ function y(n) {
65
+ if (e.slotName === "controls")
66
+ return u.proxy.$slots.controls?.({
67
+ state: e.externalState
68
+ }) ?? null;
69
+ if (e.slotName !== "default")
70
+ return null;
71
+ const i = u.proxy.$slots.default?.({
72
+ state: e.externalState
73
+ }) ?? null;
74
+ return i && !n.autoPropsDisabled && (c = A(
75
+ n,
76
+ i,
77
+ e.externalState,
78
+ c
79
+ )), i;
80
+ }
81
+ function S(n) {
82
+ if (!s)
83
+ return;
84
+ const i = e?.mode === "render" && e.currentVariant?.id === n.id;
85
+ i && !a ? a = m(n.state, s()) : !i && a && (a.stop(), a = null);
86
+ }
87
+ return r.value && f(r.value), D(() => {
88
+ a?.stop();
89
+ }), {
90
+ renderContext: e,
91
+ renderVariantSlot: y,
92
+ resolveVariant: v,
93
+ syncRenderVariantState: S,
94
+ updateVariant: f
95
+ };
96
+ },
97
+ render() {
98
+ const t = this.resolveVariant();
99
+ return !t || (this.updateVariant(t), this.syncRenderVariantState(t), this.renderContext?.mode !== "render") || this.renderContext.currentVariant?.id !== t.id ? null : this.renderVariantSlot(t);
100
+ }
101
+ });
102
+ export {
103
+ $ as default
104
+ };