histoire 0.3.0 → 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.
@@ -3,7 +3,7 @@ import type { Story, Variant } from './app/types.js';
3
3
  export { hstEvent } from './app/util/events';
4
4
  export declare type Vue3StorySetupHandler = (payload: {
5
5
  app: App;
6
- story: Story;
7
- variant: Variant;
6
+ story?: Story;
7
+ variant?: Variant;
8
8
  }) => Promise<void> | void;
9
9
  export declare function defineSetupVue3(handler: Vue3StorySetupHandler): Vue3StorySetupHandler;
@@ -1,2 +1,7 @@
1
- import type { StoryFile } from '../../node/types';
2
- export declare function run(file: StoryFile, storyData: any, el: any): Promise<void>;
1
+ import type { StoryFile, Story } from '../../node/types';
2
+ export interface ServerRunPayload {
3
+ file: StoryFile;
4
+ storyData: Story[];
5
+ el: HTMLElement;
6
+ }
7
+ export declare function run(payload: ServerRunPayload): Promise<any>;
@@ -1,27 +1,9 @@
1
- import { createApp, h } from 'vue';
2
- import { registerVueComponents } from '@histoire/controls';
3
- import Story from './Story.server.vue';
4
- import Variant from './Variant.server.vue';
5
- export async function run(file, storyData, el) {
6
- const { default: Comp } = await import(file.moduleId);
7
- const app = createApp({
8
- provide: {
9
- addStory(data) {
10
- storyData.push(data);
11
- },
12
- },
13
- render() {
14
- return h(Comp, {
15
- ref: 'comp',
16
- data: file,
17
- });
18
- },
19
- });
20
- // eslint-disable-next-line vue/multi-word-component-names
21
- app.component('Story', Story);
22
- // eslint-disable-next-line vue/multi-word-component-names
23
- app.component('Variant', Variant);
24
- registerVueComponents(app);
25
- app.mount(el);
26
- app.unmount();
1
+ export async function run(payload) {
2
+ let result;
3
+ // @TODO if (vue3)
4
+ {
5
+ const { run } = await import('./vue3/run.js');
6
+ result = await run(payload);
7
+ }
8
+ return result;
27
9
  }
@@ -0,0 +1,2 @@
1
+ import type { ServerRunPayload } from '../index.js';
2
+ export declare function run({ file, storyData, el }: ServerRunPayload): Promise<void>;
@@ -0,0 +1,32 @@
1
+ import { createApp, h } from 'vue';
2
+ import { registerVueComponents } from '@histoire/controls';
3
+ import Story from './Story.vue';
4
+ import Variant from './Variant.vue';
5
+ // @ts-expect-error virtual module id
6
+ import * as setup from '$histoire-setup';
7
+ export async function run({ file, storyData, el }) {
8
+ const { default: Comp } = await import(file.moduleId);
9
+ const app = createApp({
10
+ provide: {
11
+ addStory(data) {
12
+ storyData.push(data);
13
+ },
14
+ },
15
+ render() {
16
+ return h(Comp, {
17
+ ref: 'comp',
18
+ data: file,
19
+ });
20
+ },
21
+ });
22
+ if (typeof setup?.setupVue3 === 'function') {
23
+ await setup.setupVue3({ app });
24
+ }
25
+ // eslint-disable-next-line vue/multi-word-component-names
26
+ app.component('Story', Story);
27
+ // eslint-disable-next-line vue/multi-word-component-names
28
+ app.component('Variant', Variant);
29
+ registerVueComponents(app);
30
+ app.mount(el);
31
+ app.unmount();
32
+ }
@@ -26,9 +26,13 @@ export default async (payload) => {
26
26
  const { destroy: destroyDomEnv } = createDomEnv();
27
27
  const el = window.document.createElement('div');
28
28
  // Mount app to collect stories/variants
29
- const { run } = await runner.executeFile(resolve(__dirname, '../../client/server/index.js'));
29
+ const { run } = (await runner.executeFile(resolve(__dirname, '../../client/server/index.js')));
30
30
  const storyData = [];
31
- await run(payload.storyFile, storyData, el);
31
+ await run({
32
+ file: payload.storyFile,
33
+ storyData,
34
+ el,
35
+ });
32
36
  destroyDomEnv();
33
37
  return {
34
38
  storyData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,7 +33,7 @@
33
33
  "histoire": "./bin.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@histoire/controls": "^0.3.0",
36
+ "@histoire/controls": "^0.3.1",
37
37
  "@iconify/vue": "^3.2.1",
38
38
  "@vitejs/plugin-vue": "^2.3.1",
39
39
  "@vueuse/core": "^8.2.5",
@@ -87,9 +87,8 @@
87
87
  "scripts": {
88
88
  "build": "rimraf dist && tsc -d && pnpm run build:css && node ./scripts/copy.mjs",
89
89
  "build:css": "tailwindcss -i src/client/app/style/main.pcss -o ./dist/style.css -c tailwind.config.cjs --postcss postcss.config.cjs",
90
- "watch": "concurrently \"tsc -d -w --sourceMap\" \"pnpm run build:css -- --watch\" \"node ./scripts/watchAndCopy.mjs\"",
90
+ "watch": "concurrently \"tsc -d -w --sourceMap\" \"pnpm run build:css --watch\" \"node ./scripts/watchAndCopy.mjs\"",
91
91
  "test:open": "peeky open",
92
92
  "test": "peeky run"
93
- },
94
- "readme": "# Histoire\n\n> Fast and beautiful interactive component playgrounds\n\n[Learn more](https://github.com/Akryum/histoire)\n\n```\npnpm add histoire -D\npnpm exec histoire dev\npnpm exec histoire build\n```\n"
93
+ }
95
94
  }
@@ -4,8 +4,8 @@ export { hstEvent } from './app/util/events'
4
4
 
5
5
  export type Vue3StorySetupHandler = (payload: {
6
6
  app: App
7
- story: Story
8
- variant: Variant
7
+ story?: Story
8
+ variant?: Variant
9
9
  }) => Promise<void> | void
10
10
 
11
11
  export function defineSetupVue3 (handler: Vue3StorySetupHandler): Vue3StorySetupHandler {
@@ -1,32 +1,19 @@
1
- import { createApp, h } from 'vue'
2
- import { registerVueComponents } from '@histoire/controls'
3
- import type { StoryFile } from '../../node/types'
4
- import Story from './Story.server.vue'
5
- import Variant from './Variant.server.vue'
1
+ import type { StoryFile, Story } from '../../node/types'
6
2
 
7
- export async function run (file: StoryFile, storyData, el) {
8
- const { default: Comp } = await import(file.moduleId)
9
- const app = createApp({
10
- provide: {
11
- addStory (data) {
12
- storyData.push(data)
13
- },
14
- },
15
- render () {
16
- return h(Comp, {
17
- ref: 'comp',
18
- data: file,
19
- })
20
- },
21
- })
3
+ export interface ServerRunPayload {
4
+ file: StoryFile
5
+ storyData: Story[]
6
+ el: HTMLElement
7
+ }
22
8
 
23
- // eslint-disable-next-line vue/multi-word-component-names
24
- app.component('Story', Story)
25
- // eslint-disable-next-line vue/multi-word-component-names
26
- app.component('Variant', Variant)
9
+ export async function run (payload: ServerRunPayload) {
10
+ let result: any
27
11
 
28
- registerVueComponents(app)
12
+ // @TODO if (vue3)
13
+ {
14
+ const { run } = await import('./vue3/run.js')
15
+ result = await run(payload)
16
+ }
29
17
 
30
- app.mount(el)
31
- app.unmount()
18
+ return result
32
19
  }
@@ -0,0 +1,38 @@
1
+ import { createApp, h } from 'vue'
2
+ import { registerVueComponents } from '@histoire/controls'
3
+ import type { ServerRunPayload } from '../index.js'
4
+ import Story from './Story.vue'
5
+ import Variant from './Variant.vue'
6
+ // @ts-expect-error virtual module id
7
+ import * as setup from '$histoire-setup'
8
+
9
+ export async function run ({ file, storyData, el }: ServerRunPayload) {
10
+ const { default: Comp } = await import(file.moduleId)
11
+ const app = createApp({
12
+ provide: {
13
+ addStory (data) {
14
+ storyData.push(data)
15
+ },
16
+ },
17
+ render () {
18
+ return h(Comp, {
19
+ ref: 'comp',
20
+ data: file,
21
+ })
22
+ },
23
+ })
24
+
25
+ if (typeof setup?.setupVue3 === 'function') {
26
+ await setup.setupVue3({ app })
27
+ }
28
+
29
+ // eslint-disable-next-line vue/multi-word-component-names
30
+ app.component('Story', Story)
31
+ // eslint-disable-next-line vue/multi-word-component-names
32
+ app.component('Variant', Variant)
33
+
34
+ registerVueComponents(app)
35
+
36
+ app.mount(el)
37
+ app.unmount()
38
+ }
@@ -6,6 +6,7 @@ import type { FetchFunction, ResolveIdFunction } from 'vite-node'
6
6
  import { dirname, resolve } from 'pathe'
7
7
  import { createDomEnv } from '../dom/env.js'
8
8
  import type { StoryFile, Story } from '../types.js'
9
+ import type { ServerRunPayload } from '../../client/server/index.js'
9
10
 
10
11
  const __dirname = dirname(fileURLToPath(import.meta.url))
11
12
 
@@ -49,9 +50,13 @@ export default async (payload: Payload): Promise<ReturnData> => {
49
50
  const el = window.document.createElement('div')
50
51
 
51
52
  // Mount app to collect stories/variants
52
- const { run } = await runner.executeFile(resolve(__dirname, '../../client/server/index.js'))
53
+ const { run } = (await runner.executeFile(resolve(__dirname, '../../client/server/index.js'))) as { run: (payload: ServerRunPayload) => Promise<any> }
53
54
  const storyData: Story[] = []
54
- await run(payload.storyFile, storyData, el)
55
+ await run({
56
+ file: payload.storyFile,
57
+ storyData,
58
+ el,
59
+ })
55
60
 
56
61
  destroyDomEnv()
57
62