@poveste/plugin-vue 0.3.3 → 0.4.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.
@@ -1,12 +1,13 @@
1
- import { provideRenderContext as e } from "./render-context.js";
2
- import { registerGlobalComponents as t } from "./global-components.js";
3
- import { RouterLinkStub as n } from "./RouterLinkStub.js";
4
- import { Suspense as r, createApp as i, defineComponent as a, h as o } from "vue";
5
- import { getSetupHook as s } from "@poveste/shared";
6
- import * as c from "virtual:$poveste-generated-global-setup";
7
- import * as l from "virtual:$poveste-setup";
1
+ import { VUE_SETUP_HOOK_NAMES as e } from "../../setup-hooks.js";
2
+ import { provideRenderContext as t } from "./render-context.js";
3
+ import { registerGlobalComponents as n } from "./global-components.js";
4
+ import { RouterLinkStub as r } from "./RouterLinkStub.js";
5
+ import { Suspense as i, createApp as a, defineComponent as o, h as s } from "vue";
6
+ import { getSetupHook as c } from "@poveste/shared";
7
+ import * as l from "virtual:$poveste-generated-global-setup";
8
+ import * as u from "virtual:$poveste-setup";
8
9
  //#region src/client/app/host.ts
9
- var u = a({
10
+ var d = o({
10
11
  name: "PreviewHostRoot",
11
12
  props: {
12
13
  story: {
@@ -18,59 +19,59 @@ var u = a({
18
19
  required: !0
19
20
  }
20
21
  },
21
- setup(t) {
22
- return e(t.renderContext), () => o(t.story.file.component, { story: t.story });
22
+ setup(e) {
23
+ return t(e.renderContext), () => s(e.story.file.component, { story: e.story });
23
24
  }
24
25
  });
25
- function d(e) {
26
- let a = null, s = null;
26
+ function f(e) {
27
+ let t = null, o = null;
27
28
  async function c() {
28
29
  let c = [];
29
- s = document.createElement("div"), e.el.appendChild(s), a = i({
30
+ o = document.createElement("div"), e.el.appendChild(o), t = a({
30
31
  name: e.name,
31
32
  render: () => {
32
- let t = o(u, {
33
+ let t = s(d, {
33
34
  story: e.getStory(),
34
35
  renderContext: e.renderContext
35
36
  });
36
37
  for (let n of c) {
37
38
  let r = t;
38
- t = o(n, {
39
+ t = s(n, {
39
40
  story: e.getStory(),
40
41
  variant: e.getVariant()
41
42
  }, () => r);
42
43
  }
43
- return e.wrapInDiv && (t = o("div", t)), o(r, {}, t);
44
+ return e.wrapInDiv && (t = s("div", t)), s(i, {}, t);
44
45
  }
45
- }), t(a), a.component("RouterLink", n), await f({
46
- app: a,
46
+ }), n(t), t.component("RouterLink", r), await p({
47
+ app: t,
47
48
  story: e.getStory(),
48
49
  variant: e.getVariant(),
49
50
  addWrapper: (e) => {
50
51
  c.unshift(e);
51
52
  }
52
- }), a.mount(s);
53
+ }), t.mount(o);
53
54
  }
54
55
  function l() {
55
- a?.unmount(), a = null, s &&= (s.parentNode?.removeChild(s), null);
56
+ t?.unmount(), t = null, o &&= (o.parentNode?.removeChild(o), null);
56
57
  }
57
- function d() {
58
- a?._instance?.proxy?.$forceUpdate();
58
+ function u() {
59
+ t?._instance?.proxy?.$forceUpdate();
59
60
  }
60
61
  return {
61
62
  mount: c,
62
63
  unmount: l,
63
- forceUpdate: d
64
+ forceUpdate: u
64
65
  };
65
66
  }
66
- async function f(e) {
67
- let t = s(c, "setupVue3");
68
- t && await t(e);
69
- let n = s(l, "setupVue3");
70
- if (n && await n(e), typeof e.variant?.setupApp == "function") {
71
- let t = e.variant.setupApp;
72
- await t(e);
67
+ async function p(t) {
68
+ let n = c(l, e);
69
+ n && await n(t);
70
+ let r = c(u, e);
71
+ if (r && await r(t), typeof t.variant?.setupApp == "function") {
72
+ let e = t.variant.setupApp;
73
+ await e(t);
73
74
  }
74
75
  }
75
76
  //#endregion
76
- export { d as createPreviewHost };
77
+ export { f as createPreviewHost };
@@ -1,43 +1,44 @@
1
- import e from "./Story.js";
2
- import t from "./Variant.js";
3
- import { createApp as n, h as r } from "vue";
4
- import { getSetupHook as i } from "@poveste/shared";
5
- import * as a from "virtual:$poveste-generated-global-setup";
6
- import * as o from "virtual:$poveste-setup";
1
+ import { VUE_SETUP_HOOK_NAMES as e } from "../../setup-hooks.js";
2
+ import t from "./Story.js";
3
+ import n from "./Variant.js";
4
+ import { createApp as r, h as i } from "vue";
5
+ import { getSetupHook as a } from "@poveste/shared";
6
+ import * as o from "virtual:$poveste-generated-global-setup";
7
+ import * as s from "virtual:$poveste-setup";
7
8
  //#region src/client/server/run.ts
8
- async function s({ file: s, storyData: c, el: l }) {
9
- let { default: u } = await import(/* @vite-ignore */
9
+ async function c({ file: c, storyData: l, el: u }) {
10
+ let { default: d } = await import(/* @vite-ignore */
10
11
  /* @vite-ignore */
11
- s.moduleId
12
- ), d = n({
12
+ c.moduleId
13
+ ), f = r({
13
14
  provide: {
14
15
  addStory(e) {
15
- c.push(e);
16
+ l.push(e);
16
17
  },
17
- hstStoryFile: s
18
+ hstStoryFile: c
18
19
  },
19
20
  render() {
20
- return r(u);
21
+ return i(d);
21
22
  }
22
23
  });
23
- d.component("Story", e), d.component("Variant", t);
24
- let f = {
25
- app: d,
24
+ f.component("Story", t), f.component("Variant", n);
25
+ let p = {
26
+ app: f,
26
27
  story: null,
27
28
  variant: null,
28
29
  addWrapper: () => {}
29
- }, p = i(a, "setupVue3");
30
- p && await p(f);
31
- let m = i(o, "setupVue3");
32
- if (m && await m(f), d.mount(l), u.doc) {
30
+ }, m = a(o, e);
31
+ m && await m(p);
32
+ let h = a(s, e);
33
+ if (h && await h(p), f.mount(u), d.doc) {
33
34
  let e = document.createElement("div");
34
- e.innerHTML = u.doc;
35
+ e.innerHTML = d.doc;
35
36
  let t = e.textContent;
36
- c.forEach((e) => {
37
+ l.forEach((e) => {
37
38
  e.docsText = t;
38
39
  });
39
40
  }
40
- d.unmount();
41
+ f.unmount();
41
42
  }
42
43
  //#endregion
43
- export { s as run };
44
+ export { c as run };
@@ -0,0 +1,4 @@
1
+ //#region src/setup-hooks.ts
2
+ var e = ["setupVue3", "setupVue"];
3
+ //#endregion
4
+ export { e as VUE_SETUP_HOOK_NAMES };
package/dist/helpers.d.ts CHANGED
@@ -7,4 +7,11 @@ export interface Vue3StorySetupApi {
7
7
  addWrapper: (wrapper: Component) => void;
8
8
  }
9
9
  export type Vue3StorySetupHandler = (api: Vue3StorySetupApi) => Promise<void> | void;
10
- export declare function defineSetupVue3(handler: Vue3StorySetupHandler): Vue3StorySetupHandler;
10
+ export declare function defineSetupVue(handler: Vue3StorySetupHandler): Vue3StorySetupHandler;
11
+ /**
12
+ * @deprecated Renamed to {@link defineSetupVue}, and rename the exported hook
13
+ * from `setupVue3` to `setupVue` at the same time. Both spellings work for the
14
+ * whole of 0.x; the numbered pair is a candidate for removal at 1.0, which is
15
+ * the only release allowed to drop them (#135).
16
+ */
17
+ export declare const defineSetupVue3: typeof defineSetupVue;
package/dist/helpers.js CHANGED
@@ -1,3 +1,10 @@
1
- export function defineSetupVue3(handler) {
1
+ export function defineSetupVue(handler) {
2
2
  return handler;
3
3
  }
4
+ /**
5
+ * @deprecated Renamed to {@link defineSetupVue}, and rename the exported hook
6
+ * from `setupVue3` to `setupVue` at the same time. Both spellings work for the
7
+ * whole of 0.x; the numbered pair is a candidate for removal at 1.0, which is
8
+ * the only release allowed to drop them (#135).
9
+ */
10
+ export const defineSetupVue3 = defineSetupVue;
@@ -1,4 +1,5 @@
1
1
  import generateStoryCommand from './commands/generate-story.server.js';
2
+ import { VUE_SETUP_HOOK_NAMES } from './setup-hooks.js';
2
3
  import { listComponentFiles } from './util/list-components.js';
3
4
  export function HstVue() {
4
5
  return {
@@ -35,7 +36,7 @@ export function HstVue() {
35
36
  supportPlugin: {
36
37
  id: 'vue3',
37
38
  moduleName: '@poveste/plugin-vue',
38
- setupFn: 'setupVue3',
39
+ setupFn: VUE_SETUP_HOOK_NAMES,
39
40
  importStoriesPrepend: `import { defineAsyncComponent as defineAsyncComponentVue3 } from 'vue'`,
40
41
  importStoryComponent: (file, index) => `const Comp${index} = defineAsyncComponentVue3(() => import(${JSON.stringify(file.moduleId)}))`,
41
42
  },
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The names a Vue setup file may export, most established first.
3
+ *
4
+ * `setupVue3` is what users have written in `poveste.setup.ts` since histoire,
5
+ * so it can never be removed without a major. `setupVue` is the unnumbered name
6
+ * new docs use — added as an alias rather than a rename, which is the only way
7
+ * to introduce it without breaking every existing setup file (#135).
8
+ *
9
+ * Order is load-bearing: `getSetupHook` runs the first one present, so a file
10
+ * that already exports `setupVue3` behaves exactly as before.
11
+ */
12
+ export declare const VUE_SETUP_HOOK_NAMES: string[];
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The names a Vue setup file may export, most established first.
3
+ *
4
+ * `setupVue3` is what users have written in `poveste.setup.ts` since histoire,
5
+ * so it can never be removed without a major. `setupVue` is the unnumbered name
6
+ * new docs use — added as an alias rather than a rename, which is the only way
7
+ * to introduce it without breaking every existing setup file (#135).
8
+ *
9
+ * Order is load-bearing: `getSetupHook` runs the first one present, so a file
10
+ * that already exports `setupVue3` behaves exactly as before.
11
+ */
12
+ export const VUE_SETUP_HOOK_NAMES = ['setupVue3', 'setupVue'];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@poveste/plugin-vue",
3
3
  "type": "module",
4
- "version": "0.3.3",
4
+ "version": "0.4.0",
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.3.3"
47
+ "poveste": "^0.4.0"
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.3.3",
55
- "@poveste/shared": "^0.3.3",
56
- "@poveste/vendors": "^0.3.3"
54
+ "@poveste/controls": "^0.4.0",
55
+ "@poveste/vendors": "^0.4.0",
56
+ "@poveste/shared": "^0.4.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/node": "^22.10.1",
@@ -62,7 +62,7 @@
62
62
  "vite": "^8.2.0",
63
63
  "vitest": "^4.1.10",
64
64
  "vue": "^3.5.26",
65
- "poveste": "0.3.3"
65
+ "poveste": "0.4.0"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "rimraf dist && vite build && tsc -d -P tsconfig.build.json && pnpm run build:types",
@@ -13,6 +13,7 @@ import {
13
13
  h,
14
14
  Suspense,
15
15
  } from 'vue'
16
+ import { VUE_SETUP_HOOK_NAMES } from '../../setup-hooks.js'
16
17
  import { registerGlobalComponents } from './global-components.js'
17
18
  import { provideRenderContext } from './render-context.js'
18
19
  import { RouterLinkStub } from './RouterLinkStub'
@@ -124,12 +125,12 @@ export function createPreviewHost(options: PreviewHostOptions) {
124
125
  }
125
126
 
126
127
  async function runSetupHooks(setupApi: Vue3StorySetupApi) {
127
- const generatedSetupFn = getSetupHook<Vue3StorySetupHandler>(generatedSetup, 'setupVue3')
128
+ const generatedSetupFn = getSetupHook<Vue3StorySetupHandler>(generatedSetup, VUE_SETUP_HOOK_NAMES)
128
129
  if (generatedSetupFn) {
129
130
  await generatedSetupFn(setupApi)
130
131
  }
131
132
 
132
- const setupFn = getSetupHook<Vue3StorySetupHandler>(setup, 'setupVue3')
133
+ const setupFn = getSetupHook<Vue3StorySetupHandler>(setup, VUE_SETUP_HOOK_NAMES)
133
134
  if (setupFn) {
134
135
  await setupFn(setupApi)
135
136
  }
@@ -6,6 +6,7 @@ import * as generatedSetup from 'virtual:$poveste-generated-global-setup'
6
6
  // @ts-expect-error virtual module id
7
7
  import * as setup from 'virtual:$poveste-setup'
8
8
  import { createApp, h } from 'vue'
9
+ import { VUE_SETUP_HOOK_NAMES } from '../../setup-hooks.js'
9
10
  import Story from './Story'
10
11
  import Variant from './Variant'
11
12
 
@@ -37,12 +38,12 @@ export async function run({ file, storyData, el }: ServerRunPayload) {
37
38
  addWrapper: () => { /* noop */ },
38
39
  }
39
40
 
40
- const generatedSetupFn = getSetupHook<Vue3StorySetupHandler>(generatedSetup, 'setupVue3')
41
+ const generatedSetupFn = getSetupHook<Vue3StorySetupHandler>(generatedSetup, VUE_SETUP_HOOK_NAMES)
41
42
  if (generatedSetupFn) {
42
43
  await generatedSetupFn(setupApi)
43
44
  }
44
45
 
45
- const setupFn = getSetupHook<Vue3StorySetupHandler>(setup, 'setupVue3')
46
+ const setupFn = getSetupHook<Vue3StorySetupHandler>(setup, VUE_SETUP_HOOK_NAMES)
46
47
  if (setupFn) {
47
48
  await setupFn(setupApi)
48
49
  }
package/src/helpers.ts CHANGED
@@ -10,6 +10,14 @@ export interface Vue3StorySetupApi {
10
10
 
11
11
  export type Vue3StorySetupHandler = (api: Vue3StorySetupApi) => Promise<void> | void
12
12
 
13
- export function defineSetupVue3(handler: Vue3StorySetupHandler): Vue3StorySetupHandler {
13
+ export function defineSetupVue(handler: Vue3StorySetupHandler): Vue3StorySetupHandler {
14
14
  return handler
15
15
  }
16
+
17
+ /**
18
+ * @deprecated Renamed to {@link defineSetupVue}, and rename the exported hook
19
+ * from `setupVue3` to `setupVue` at the same time. Both spellings work for the
20
+ * whole of 0.x; the numbered pair is a candidate for removal at 1.0, which is
21
+ * the only release allowed to drop them (#135).
22
+ */
23
+ export const defineSetupVue3 = defineSetupVue
package/src/index.node.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Plugin } from 'poveste'
2
2
 
3
3
  import generateStoryCommand from './commands/generate-story.server.js'
4
+ import { VUE_SETUP_HOOK_NAMES } from './setup-hooks.js'
4
5
  import { listComponentFiles } from './util/list-components.js'
5
6
 
6
7
  export function HstVue(): Plugin {
@@ -41,7 +42,7 @@ export function HstVue(): Plugin {
41
42
  supportPlugin: {
42
43
  id: 'vue3',
43
44
  moduleName: '@poveste/plugin-vue',
44
- setupFn: 'setupVue3',
45
+ setupFn: VUE_SETUP_HOOK_NAMES,
45
46
  importStoriesPrepend: `import { defineAsyncComponent as defineAsyncComponentVue3 } from 'vue'`,
46
47
  importStoryComponent: (file, index) => `const Comp${index} = defineAsyncComponentVue3(() => import(${JSON.stringify(file.moduleId)}))`,
47
48
  },
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The names a Vue setup file may export, most established first.
3
+ *
4
+ * `setupVue3` is what users have written in `poveste.setup.ts` since histoire,
5
+ * so it can never be removed without a major. `setupVue` is the unnumbered name
6
+ * new docs use — added as an alias rather than a rename, which is the only way
7
+ * to introduce it without breaking every existing setup file (#135).
8
+ *
9
+ * Order is load-bearing: `getSetupHook` runs the first one present, so a file
10
+ * that already exports `setupVue3` behaves exactly as before.
11
+ */
12
+ export const VUE_SETUP_HOOK_NAMES = ['setupVue3', 'setupVue']