@poveste/plugin-vue 0.1.3 → 0.2.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,10 +1,11 @@
1
- import * as a from "virtual:$poveste-generated-global-setup";
2
- import * as i from "virtual:$poveste-setup";
3
- import { defineComponent as l, h as o, createApp as y, Suspense as v } from "vue";
1
+ import { getSetupHook as i } from "@poveste/shared";
2
+ import * as d from "virtual:$poveste-generated-global-setup";
3
+ import * as l from "virtual:$poveste-setup";
4
+ import { defineComponent as y, h as o, createApp as v, Suspense as g } from "vue";
4
5
  import { registerGlobalComponents as w } from "./global-components.js";
5
- import { provideRenderContext as C } from "./render-context.js";
6
- import { RouterLinkStub as g } from "./RouterLinkStub.js";
7
- const x = l({
6
+ import { provideRenderContext as S } from "./render-context.js";
7
+ import { RouterLinkStub as C } from "./RouterLinkStub.js";
8
+ const x = y({
8
9
  name: "PreviewHostRoot",
9
10
  props: {
10
11
  story: {
@@ -17,33 +18,33 @@ const x = l({
17
18
  }
18
19
  },
19
20
  setup(e) {
20
- return C(e.renderContext), () => o(e.story.file.component, {
21
+ return S(e.renderContext), () => o(e.story.file.component, {
21
22
  story: e.story
22
23
  });
23
24
  }
24
25
  });
25
- function H(e) {
26
+ function F(e) {
26
27
  let t = null, r = null;
27
- async function p() {
28
+ async function a() {
28
29
  const u = [];
29
- r = document.createElement("div"), e.el.appendChild(r), t = y({
30
+ r = document.createElement("div"), e.el.appendChild(r), t = v({
30
31
  name: e.name,
31
32
  render: () => {
32
33
  let n = o(x, {
33
34
  story: e.getStory(),
34
35
  renderContext: e.renderContext
35
36
  });
36
- for (const m of u) {
37
- const d = n;
38
- n = o(m, {
37
+ for (const s of u) {
38
+ const f = n;
39
+ n = o(s, {
39
40
  story: e.getStory(),
40
41
  variant: e.getVariant()
41
- }, () => d);
42
+ }, () => f);
42
43
  }
43
- return e.wrapInDiv && (n = o("div", n)), o(v, {}, n);
44
+ return e.wrapInDiv && (n = o("div", n)), o(g, {}, n);
44
45
  }
45
- }), w(t), t.component("RouterLink", g);
46
- const f = {
46
+ }), w(t), t.component("RouterLink", C);
47
+ const m = {
47
48
  app: t,
48
49
  story: e.getStory(),
49
50
  variant: e.getVariant(),
@@ -51,34 +52,29 @@ function H(e) {
51
52
  u.unshift(n);
52
53
  }
53
54
  };
54
- await S(f), t.mount(r);
55
+ await h(m), t.mount(r);
55
56
  }
56
- function c() {
57
+ function p() {
57
58
  t?.unmount(), t = null, r && (r.parentNode?.removeChild(r), r = null);
58
59
  }
59
- function s() {
60
+ function c() {
60
61
  t?._instance?.proxy?.$forceUpdate();
61
62
  }
62
63
  return {
63
- mount: p,
64
- unmount: c,
65
- forceUpdate: s
64
+ mount: a,
65
+ unmount: p,
66
+ forceUpdate: c
66
67
  };
67
68
  }
68
- async function S(e) {
69
- if (typeof a?.setupVue3 == "function") {
70
- const t = a.setupVue3;
71
- await t(e);
72
- }
73
- if (typeof i?.setupVue3 == "function") {
74
- const t = i.setupVue3;
75
- await t(e);
76
- }
77
- if (typeof e.variant?.setupApp == "function") {
78
- const t = e.variant.setupApp;
79
- await t(e);
69
+ async function h(e) {
70
+ const t = i(d, "setupVue3");
71
+ t && await t(e);
72
+ const r = i(l, "setupVue3");
73
+ if (r && await r(e), typeof e.variant?.setupApp == "function") {
74
+ const a = e.variant.setupApp;
75
+ await a(e);
80
76
  }
81
77
  }
82
78
  export {
83
- H as createPreviewHost
79
+ F as createPreviewHost
84
80
  };
@@ -1,6 +1,6 @@
1
- import { defineComponent as i, useAttrs as n, inject as d, provide as r, onMounted as l } from "vue";
2
- import { autoStubComponents as u } from "./stub.js";
3
- const c = i({
1
+ import { defineComponent as a, inject as r, provide as i, onMounted as d } from "vue";
2
+ import { autoStubComponents as l } from "./stub.js";
3
+ const f = a({
4
4
  name: "PovesteStory",
5
5
  inheritAttrs: !1,
6
6
  props: {
@@ -38,9 +38,9 @@ const c = i({
38
38
  }
39
39
  },
40
40
  setup(t) {
41
- const e = n(), o = {
42
- id: t.id ?? e.data.id,
43
- title: t.title ?? e.data.fileName,
41
+ const e = r("hstStoryFile"), o = {
42
+ id: t.id ?? e?.id,
43
+ title: t.title ?? e?.fileName,
44
44
  group: t.group,
45
45
  layout: t.layout,
46
46
  icon: t.icon,
@@ -49,9 +49,9 @@ const c = i({
49
49
  meta: t.meta,
50
50
  variants: []
51
51
  };
52
- return d("addStory", null)?.(o), r("story", o), r("addVariant", (a) => {
53
- o.variants.push(a);
54
- }), l(() => {
52
+ return r("addStory", null)?.(o), i("story", o), i("addVariant", (n) => {
53
+ o.variants.push(n);
54
+ }), d(() => {
55
55
  o.variants.length || o.variants.push({
56
56
  id: "_default",
57
57
  title: "default"
@@ -68,12 +68,12 @@ const c = i({
68
68
  return t = !0, {};
69
69
  }
70
70
  });
71
- return Array.isArray(e) && u(e), e;
71
+ return Array.isArray(e) && l(e), e;
72
72
  } catch (e) {
73
73
  return t || console.error(e), null;
74
74
  }
75
75
  }
76
76
  });
77
77
  export {
78
- c as default
78
+ f as default
79
79
  };
@@ -1,51 +1,44 @@
1
- import * as u from "virtual:$poveste-generated-global-setup";
2
- import * as a from "virtual:$poveste-setup";
3
- import { createApp as m, h as d } from "vue";
4
- import f from "./Story.js";
5
- import l from "./Variant.js";
6
- async function S({ file: n, storyData: r, el: c }) {
1
+ import { getSetupHook as i } from "@poveste/shared";
2
+ import * as d from "virtual:$poveste-generated-global-setup";
3
+ import * as f from "virtual:$poveste-setup";
4
+ import { createApp as l, h as S } from "vue";
5
+ import y from "./Story.js";
6
+ import h from "./Variant.js";
7
+ async function w({ file: n, storyData: r, el: m }) {
7
8
  const { default: e } = await import(/* @vite-ignore */
8
9
  /* @vite-ignore */
9
10
  n.moduleId
10
- ), o = m({
11
+ ), t = l({
11
12
  provide: {
12
- addStory(t) {
13
- r.push(t);
14
- }
13
+ addStory(o) {
14
+ r.push(o);
15
+ },
16
+ hstStoryFile: n
15
17
  },
16
18
  render() {
17
- return d(e, {
18
- ref: "comp",
19
- data: n
20
- });
19
+ return S(e);
21
20
  }
22
21
  });
23
- o.component("Story", f), o.component("Variant", l);
22
+ t.component("Story", y), t.component("Variant", h);
24
23
  const p = {
25
- app: o,
24
+ app: t,
26
25
  story: null,
27
26
  variant: null,
28
27
  addWrapper: () => {
29
28
  }
30
- };
31
- if (typeof u?.setupVue3 == "function") {
32
- const t = u.setupVue3;
33
- await t(p);
34
- }
35
- if (typeof a?.setupVue3 == "function") {
36
- const t = a.setupVue3;
37
- await t(p);
38
- }
39
- if (o.mount(c), e.doc) {
40
- const t = document.createElement("div");
41
- t.innerHTML = e.doc;
42
- const i = t.textContent;
43
- r.forEach((s) => {
44
- s.docsText = i;
29
+ }, a = i(d, "setupVue3");
30
+ a && await a(p);
31
+ const u = i(f, "setupVue3");
32
+ if (u && await u(p), t.mount(m), e.doc) {
33
+ const o = document.createElement("div");
34
+ o.innerHTML = e.doc;
35
+ const s = o.textContent;
36
+ r.forEach((c) => {
37
+ c.docsText = s;
45
38
  });
46
39
  }
47
- o.unmount();
40
+ t.unmount();
48
41
  }
49
42
  export {
50
- S as run
43
+ w as run
51
44
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@poveste/plugin-vue",
3
3
  "type": "module",
4
- "version": "0.1.3",
4
+ "version": "0.2.1",
5
5
  "description": "Poveste plugin for Vue.js support",
6
6
  "author": {
7
7
  "name": "Sorin Gitlan"
@@ -44,16 +44,16 @@
44
44
  "types": "dist/index.node.d.ts",
45
45
  "peerDependencies": {
46
46
  "vue": "^3.5.26",
47
- "poveste": "^0.1.3"
47
+ "poveste": "^0.2.1"
48
48
  },
49
49
  "dependencies": {
50
50
  "change-case": "^5.4.4",
51
51
  "globby": "^14.0.2",
52
52
  "launch-editor": "^2.9.1",
53
53
  "pathe": "^1.1.2",
54
- "@poveste/controls": "^0.1.3",
55
- "@poveste/shared": "^0.1.3",
56
- "@poveste/vendors": "^0.1.3"
54
+ "@poveste/controls": "^0.2.1",
55
+ "@poveste/vendors": "^0.2.1",
56
+ "@poveste/shared": "^0.2.1"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/node": "^22.10.1",
@@ -61,7 +61,7 @@
61
61
  "typescript": "5.6.3",
62
62
  "vite": "^7.3.0",
63
63
  "vue": "^3.5.26",
64
- "poveste": "0.1.3"
64
+ "poveste": "0.2.1"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "rimraf dist && vite build && tsc -d -P tsconfig.build.json && pnpm run build:types",
@@ -1,6 +1,7 @@
1
1
  import type { Story, Variant } from '@poveste/shared'
2
2
  import type { App, Component, PropType, VNode } from 'vue'
3
3
  import type { Vue3StorySetupApi, Vue3StorySetupHandler } from '../../helpers.js'
4
+ import { getSetupHook } from '@poveste/shared'
4
5
  // @ts-expect-error virtual module id
5
6
  import * as generatedSetup from 'virtual:$poveste-generated-global-setup'
6
7
  // @ts-expect-error virtual module id
@@ -122,18 +123,18 @@ export function createPreviewHost(options: PreviewHostOptions) {
122
123
  }
123
124
 
124
125
  async function runSetupHooks(setupApi: Vue3StorySetupApi) {
125
- if (typeof generatedSetup?.setupVue3 === 'function') {
126
- const setupFn = generatedSetup.setupVue3 as Vue3StorySetupHandler
127
- await setupFn(setupApi)
126
+ const generatedSetupFn = getSetupHook<Vue3StorySetupHandler>(generatedSetup, 'setupVue3')
127
+ if (generatedSetupFn) {
128
+ await generatedSetupFn(setupApi)
128
129
  }
129
130
 
130
- if (typeof setup?.setupVue3 === 'function') {
131
- const setupFn = setup.setupVue3 as Vue3StorySetupHandler
131
+ const setupFn = getSetupHook<Vue3StorySetupHandler>(setup, 'setupVue3')
132
+ if (setupFn) {
132
133
  await setupFn(setupApi)
133
134
  }
134
135
 
135
136
  if (typeof setupApi.variant?.setupApp === 'function') {
136
- const setupFn = setupApi.variant.setupApp as Vue3StorySetupHandler
137
- await setupFn(setupApi)
137
+ const variantSetupFn = setupApi.variant.setupApp as Vue3StorySetupHandler
138
+ await variantSetupFn(setupApi)
138
139
  }
139
140
  }
@@ -1,6 +1,6 @@
1
1
  import type { ServerStory, ServerStoryFile, ServerVariant } from '@poveste/shared'
2
2
  import type { PropType } from 'vue'
3
- import { defineComponent, inject, onMounted, provide, useAttrs } from 'vue'
3
+ import { defineComponent, inject, onMounted, provide } from 'vue'
4
4
  import { autoStubComponents } from './stub'
5
5
 
6
6
  export default defineComponent({
@@ -51,15 +51,13 @@ export default defineComponent({
51
51
  },
52
52
 
53
53
  setup(props) {
54
- const attrs = useAttrs() as {
55
- data: ServerStoryFile
56
- }
54
+ const file = inject<ServerStoryFile>('hstStoryFile')
57
55
 
58
56
  // Story
59
57
 
60
58
  const story: ServerStory = {
61
- id: props.id ?? attrs.data.id,
62
- title: props.title ?? attrs.data.fileName,
59
+ id: props.id ?? file?.id,
60
+ title: props.title ?? file?.fileName,
63
61
  group: props.group,
64
62
  layout: props.layout,
65
63
  icon: props.icon,
@@ -1,5 +1,6 @@
1
1
  import type { ServerRunPayload } from '@poveste/shared'
2
2
  import type { Vue3StorySetupApi, Vue3StorySetupHandler } from '../../helpers.js'
3
+ import { getSetupHook } from '@poveste/shared'
3
4
  // @ts-expect-error virtual module id
4
5
  import * as generatedSetup from 'virtual:$poveste-generated-global-setup'
5
6
  // @ts-expect-error virtual module id
@@ -16,12 +17,10 @@ export async function run({ file, storyData, el }: ServerRunPayload) {
16
17
  addStory(data) {
17
18
  storyData.push(data)
18
19
  },
20
+ hstStoryFile: file,
19
21
  },
20
22
  render() {
21
- return h(Comp, {
22
- ref: 'comp',
23
- data: file,
24
- })
23
+ return h(Comp)
25
24
  },
26
25
  })
27
26
 
@@ -38,13 +37,13 @@ export async function run({ file, storyData, el }: ServerRunPayload) {
38
37
  addWrapper: () => { /* noop */ },
39
38
  }
40
39
 
41
- if (typeof generatedSetup?.setupVue3 === 'function') {
42
- const setupFn = generatedSetup.setupVue3 as Vue3StorySetupHandler
43
- await setupFn(setupApi)
40
+ const generatedSetupFn = getSetupHook<Vue3StorySetupHandler>(generatedSetup, 'setupVue3')
41
+ if (generatedSetupFn) {
42
+ await generatedSetupFn(setupApi)
44
43
  }
45
44
 
46
- if (typeof setup?.setupVue3 === 'function') {
47
- const setupFn = setup.setupVue3 as Vue3StorySetupHandler
45
+ const setupFn = getSetupHook<Vue3StorySetupHandler>(setup, 'setupVue3')
46
+ if (setupFn) {
48
47
  await setupFn(setupApi)
49
48
  }
50
49