histoire 0.7.3 → 0.7.6

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 (111) hide show
  1. package/client.d.ts +1 -1
  2. package/dist/bundled/StoryView.js +22 -19
  3. package/dist/bundled/dark.js +4 -0
  4. package/dist/bundled/index.js +0 -1
  5. package/dist/bundled/index2.js +6 -6
  6. package/dist/bundled/mapping.js +78 -0
  7. package/dist/bundled/sandbox.js +7 -6
  8. package/dist/bundled/state.js +7 -42
  9. package/dist/bundled/style.css +3 -3
  10. package/dist/client/app/App.vue +2 -2
  11. package/dist/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
  12. package/dist/client/app/components/panel/ControlsComponentProps.vue +2 -1
  13. package/dist/client/app/components/panel/StatePresets.vue +2 -1
  14. package/dist/client/app/components/panel/StoryControls.vue +1 -1
  15. package/dist/client/app/components/panel/StorySourceCode.vue +2 -2
  16. package/dist/client/app/components/story/StoryVariantGridItem.vue +1 -1
  17. package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
  18. package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
  19. package/dist/client/app/components/story/StoryVariantSingleView.vue +1 -1
  20. package/dist/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
  21. package/dist/client/app/components/tree/StoryGroup.vue +1 -1
  22. package/dist/client/app/index.js +0 -2
  23. package/dist/client/app/sandbox.js +4 -5
  24. package/dist/client/app/types.d.ts +1 -52
  25. package/dist/client/app/util/mapping.d.ts +1 -1
  26. package/dist/client/app/util/mapping.js +50 -36
  27. package/dist/client/app/{components/sandbox/lib.d.ts → util/sandbox.d.ts} +1 -1
  28. package/dist/client/app/{components/sandbox/lib.js → util/sandbox.js} +1 -1
  29. package/dist/client/app/util/state.d.ts +0 -4
  30. package/dist/client/app/util/state.js +6 -42
  31. package/dist/node/collect/index.d.ts +2 -2
  32. package/dist/node/collect/index.js +3 -0
  33. package/dist/node/collect/run.d.ts +2 -0
  34. package/dist/{client/server/index.js → node/collect/run.js} +1 -1
  35. package/dist/node/collect/worker.d.ts +3 -3
  36. package/dist/node/collect/worker.js +4 -1
  37. package/dist/node/config.d.ts +3 -3
  38. package/dist/node/context.d.ts +2 -2
  39. package/dist/node/plugin.d.ts +3 -3
  40. package/dist/node/stories.d.ts +4 -4
  41. package/dist/node/tree.d.ts +3 -22
  42. package/dist/node/vite.js +6 -0
  43. package/package.json +4 -2
  44. package/src/client/app/App.vue +2 -2
  45. package/src/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
  46. package/src/client/app/components/panel/ControlsComponentProps.vue +2 -1
  47. package/src/client/app/components/panel/StatePresets.vue +2 -1
  48. package/src/client/app/components/panel/StoryControls.vue +1 -1
  49. package/src/client/app/components/panel/StorySourceCode.vue +2 -2
  50. package/src/client/app/components/story/StoryVariantGridItem.vue +1 -1
  51. package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
  52. package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
  53. package/src/client/app/components/story/StoryVariantSingleView.vue +1 -1
  54. package/src/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
  55. package/src/client/app/components/tree/StoryGroup.vue +1 -1
  56. package/src/client/app/index.ts +0 -2
  57. package/src/client/app/sandbox.ts +4 -5
  58. package/src/client/app/types.ts +6 -57
  59. package/src/client/app/util/mapping.ts +47 -34
  60. package/src/client/app/{components/sandbox/lib.ts → util/sandbox.ts} +2 -2
  61. package/src/client/app/util/state.ts +8 -43
  62. package/src/node/collect/index.ts +5 -2
  63. package/src/node/collect/run.ts +13 -0
  64. package/src/node/collect/worker.ts +8 -6
  65. package/src/node/config.ts +3 -3
  66. package/src/node/context.ts +2 -2
  67. package/src/node/plugin.ts +2 -2
  68. package/src/node/server.ts +2 -2
  69. package/src/node/stories.ts +4 -4
  70. package/src/node/tree.ts +7 -31
  71. package/src/node/vite.ts +6 -0
  72. package/vite.config.ts +12 -7
  73. package/dist/bundled/SandboxVue3.js +0 -717
  74. package/dist/bundled/global-components.js +0 -213
  75. package/dist/client/app/codegen/const.d.ts +0 -1
  76. package/dist/client/app/codegen/const.js +0 -3
  77. package/dist/client/app/codegen/serialize-js.d.ts +0 -1
  78. package/dist/client/app/codegen/serialize-js.js +0 -126
  79. package/dist/client/app/codegen/util.d.ts +0 -10
  80. package/dist/client/app/codegen/util.js +0 -70
  81. package/dist/client/app/codegen/vue3.d.ts +0 -4
  82. package/dist/client/app/codegen/vue3.js +0 -357
  83. package/dist/client/app/components/exposed/Story.vue +0 -106
  84. package/dist/client/app/components/exposed/Variant.vue +0 -78
  85. package/dist/client/app/components/sandbox/RouterLinkStub.d.ts +0 -21
  86. package/dist/client/app/components/sandbox/RouterLinkStub.js +0 -43
  87. package/dist/client/app/components/sandbox/SandboxVue3.vue +0 -185
  88. package/dist/client/app/global-components.d.ts +0 -2
  89. package/dist/client/app/global-components.js +0 -10
  90. package/dist/client/server/index.d.ts +0 -7
  91. package/dist/client/server/vue3/Story.vue +0 -120
  92. package/dist/client/server/vue3/Variant.vue +0 -52
  93. package/dist/client/server/vue3/run.d.ts +0 -2
  94. package/dist/client/server/vue3/run.js +0 -45
  95. package/dist/node/types.d.ts +0 -50
  96. package/dist/node/types.js +0 -1
  97. package/src/client/app/codegen/const.ts +0 -3
  98. package/src/client/app/codegen/serialize-js.ts +0 -133
  99. package/src/client/app/codegen/util.ts +0 -79
  100. package/src/client/app/codegen/vue3.ts +0 -361
  101. package/src/client/app/components/exposed/Story.vue +0 -106
  102. package/src/client/app/components/exposed/Variant.vue +0 -78
  103. package/src/client/app/components/sandbox/RouterLinkStub.ts +0 -49
  104. package/src/client/app/components/sandbox/SandboxVue3.vue +0 -185
  105. package/src/client/app/global-components.ts +0 -13
  106. package/src/client/server/index.ts +0 -19
  107. package/src/client/server/vue3/Story.vue +0 -120
  108. package/src/client/server/vue3/Variant.vue +0 -52
  109. package/src/client/server/vue3/run.ts +0 -55
  110. package/src/components.d.ts +0 -143
  111. package/src/node/types.ts +0 -53
@@ -7,7 +7,6 @@ import { createApp } from 'vue'
7
7
  import { createPinia } from 'pinia'
8
8
  import FloatingVue from 'floating-vue'
9
9
  import App from './App.vue'
10
- import { registerGlobalComponents } from './global-components.js'
11
10
  import { router } from './router'
12
11
 
13
12
  export function mountMainApp () {
@@ -27,7 +26,6 @@ export function mountMainApp () {
27
26
  },
28
27
  })
29
28
  app.use(router)
30
- registerGlobalComponents(app)
31
29
  app.mount('#app')
32
30
 
33
31
  if (import.meta.hot) {
@@ -1,8 +1,8 @@
1
1
  import { parseQuery } from 'vue-router'
2
2
  import { computed, createApp, h, onMounted, ref, watch } from 'vue'
3
3
  import { createPinia } from 'pinia'
4
- import { registerGlobalComponents } from './global-components'
5
- import SandboxVue3 from './components/sandbox/SandboxVue3.vue'
4
+ import { applyStateToVariant } from '@histoire/shared'
5
+ import { SandboxVue3, MountStoryVue3 } from '@histoire/plugin-vue/client'
6
6
  import type { StoryFile } from './types'
7
7
  import { mapFile } from './util/mapping'
8
8
  // @ts-expect-error virtual module
@@ -11,7 +11,7 @@ import { PREVIEW_SETTINGS_SYNC, STATE_SYNC, SANDBOX_READY } from './util/const.j
11
11
  import { applyPreviewSettings } from './util/preview-settings.js'
12
12
  import { isDark } from './util/dark.js'
13
13
  import { histoireConfig } from './util/config.js'
14
- import { applyStateToVariant, toRawDeep } from './util/state'
14
+ import { toRawDeep } from './util/state.js'
15
15
 
16
16
  const query = parseQuery(window.location.search)
17
17
  const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
@@ -62,7 +62,7 @@ const app = createApp({
62
62
  render () {
63
63
  return [
64
64
  h('div', { class: 'htw-sandbox-hidden' }, [
65
- h(file.value.component, {
65
+ h(MountStoryVue3, {
66
66
  story: file.value.story,
67
67
  }),
68
68
  ]),
@@ -81,7 +81,6 @@ const app = createApp({
81
81
  },
82
82
  })
83
83
  app.use(createPinia())
84
- registerGlobalComponents(app)
85
84
  app.mount('#app')
86
85
 
87
86
  watch(isDark, value => {
@@ -1,49 +1,11 @@
1
1
  import type { RouteLocationRaw } from 'vue-router'
2
2
 
3
- export interface StoryFile {
4
- id: string
5
- framework: string
6
- component: any
7
- story: Story
8
- path: string[]
9
- }
10
-
11
- export type StoryLayout = {
12
- type: 'single'
13
- iframe?: boolean
14
- } | {
15
- type: 'grid'
16
- width?: number | string
17
- }
18
-
19
- export interface Story {
20
- id: string
21
- title: string
22
- group?: string
23
- variants: Variant[]
24
- layout?: StoryLayout
25
- icon?: string
26
- iconColor?: string
27
- docsOnly?: boolean
28
- file?: StoryFile
29
- lastSelectedVariant?: Variant
30
- slots?: () => Readonly<any>
31
- }
32
-
33
- export interface Variant {
34
- id: string
35
- title: string
36
- icon?: string
37
- iconColor?: string
38
- initState?: () => any
39
- setupApp?: (payload: any) => unknown
40
- slots?: () => Readonly<any>
41
- state?: any
42
- source?: string
43
- responsiveDisabled?: boolean
44
- configReady?: boolean
45
- previewReady?: boolean
46
- }
3
+ export type {
4
+ StoryFile,
5
+ StoryLayout,
6
+ Story,
7
+ Variant,
8
+ } from '@histoire/shared'
47
9
 
48
10
  export type TreeLeaf = {
49
11
  title: string
@@ -82,16 +44,3 @@ export interface PreviewSettings {
82
44
  backgroundColor: string
83
45
  checkerboard: boolean
84
46
  }
85
-
86
- export interface PropDefinition {
87
- name: string
88
- types?: string[]
89
- required?: boolean
90
- default?: any
91
- }
92
-
93
- export interface AutoPropComponentDefinition {
94
- name: string
95
- index: number
96
- props: PropDefinition[]
97
- }
@@ -13,49 +13,62 @@ const copiedFromExistingVariant = [
13
13
  ]
14
14
 
15
15
  export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
16
- const result: StoryFile = {
17
- ...file,
18
- component: markRaw(file.component),
19
- story: {
20
- ...file.story,
21
- title: file.story.title,
22
- file: markRaw(file),
23
- variants: file.story.variants.map(v => mapVariant(v)),
24
- slots: () => ({}),
25
- },
26
- }
16
+ let result: StoryFile
27
17
 
28
18
  if (existingFile) {
29
- for (const index in result.story.variants) {
30
- const variant = result.story.variants[index]
31
- const existingVariant = existingFile.story.variants[index]
32
- if (existingVariant) {
33
- for (const key of copiedFromExistingVariant) {
34
- if (typeof existingVariant[key] !== 'undefined') {
35
- if (key === 'state') {
36
- variant.state = existingVariant.state
37
- continue
38
- }
39
- variant[key] = existingVariant[key]
40
- }
41
- }
19
+ // Update
20
+ result = existingFile
21
+ for (const key in file) {
22
+ if (key === 'story') {
23
+ Object.assign(result.story, {
24
+ ...file.story,
25
+ file: markRaw(result),
26
+ variants: file.story.variants.map(v => mapVariant(v, existingFile.story.variants.find(item => item.id === v.id))),
27
+ })
28
+ } else if (key !== 'component') {
29
+ result[key] = file[key]
42
30
  }
43
31
  }
44
- if (existingFile.story.lastSelectedVariant) {
45
- result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id)
32
+ } else {
33
+ // Create
34
+ result = {
35
+ ...file,
36
+ component: markRaw(file.component),
37
+ story: {
38
+ ...file.story,
39
+ title: file.story.title,
40
+ file: markRaw(file),
41
+ variants: file.story.variants.map(v => mapVariant(v)),
42
+ slots: () => ({}),
43
+ },
46
44
  }
47
45
  }
48
46
 
49
47
  return result
50
48
  }
51
49
 
52
- export function mapVariant (variant: Variant): Variant {
53
- return {
54
- ...variant,
55
- state: null,
56
- initState: null,
57
- setupApp: null,
58
- slots: () => ({}),
59
- previewReady: false,
50
+ export function mapVariant (variant: Variant, existingVariant?: Variant): Variant {
51
+ let result: Variant
52
+
53
+ if (existingVariant) {
54
+ // Update
55
+ result = existingVariant
56
+ for (const key in variant) {
57
+ if (!copiedFromExistingVariant.includes(key)) {
58
+ result[key] = variant[key]
59
+ }
60
+ }
61
+ } else {
62
+ // Create
63
+ result = {
64
+ ...variant,
65
+ state: null,
66
+ initState: null,
67
+ setupApp: null,
68
+ slots: () => ({}),
69
+ previewReady: false,
70
+ }
60
71
  }
72
+
73
+ return result
61
74
  }
@@ -1,6 +1,6 @@
1
1
 
2
- import { base } from '../../router'
3
- import { Story, Variant } from '../../types'
2
+ import { base } from '../router'
3
+ import { Story, Variant } from '../types'
4
4
 
5
5
  export function getSandboxUrl (story: Story, variant: Variant) {
6
6
  const url = new URLSearchParams()
@@ -1,21 +1,24 @@
1
1
  import { unref, isRef } from 'vue'
2
- import type { Variant } from '../types'
3
2
 
4
3
  const isObject = (val) => val !== null && typeof val === 'object'
5
4
 
6
5
  export function toRawDeep (val, seen = new Set()) {
7
6
  const unwrappedValue = isRef(val) ? unref(val) : val
8
7
 
9
- if (seen.has(unwrappedValue)) {
10
- return Array.isArray(unwrappedValue) ? [] : {}
8
+ if (typeof unwrappedValue === 'symbol') {
9
+ return unwrappedValue.toString()
11
10
  }
12
11
 
13
- seen.add(unwrappedValue)
14
-
15
12
  if (!isObject(unwrappedValue)) {
16
13
  return unwrappedValue
17
14
  }
18
15
 
16
+ if (seen.has(unwrappedValue)) {
17
+ return Array.isArray(unwrappedValue) ? [] : {}
18
+ }
19
+
20
+ seen.add(unwrappedValue)
21
+
19
22
  if (Array.isArray(unwrappedValue)) {
20
23
  return unwrappedValue.map(value => toRawDeep(value, seen))
21
24
  }
@@ -27,41 +30,3 @@ const toRawObject = (obj: Record<any, any>, seen = new Set()) => Object.keys(obj
27
30
  raw[key] = toRawDeep(obj[key], seen)
28
31
  return raw
29
32
  }, {})
30
-
31
- export function clone (data) {
32
- try {
33
- return structuredClone(data)
34
- } catch (e) {
35
- console.warn(e, `Fallback to JSON cloning`)
36
- try {
37
- return JSON.parse(JSON.stringify(data))
38
- } catch (e) {
39
- console.error(e)
40
- }
41
- return data
42
- }
43
- }
44
-
45
- export function omit (data, keys: string[]) {
46
- const copy = {}
47
- for (const key in data) {
48
- if (!keys.includes(key)) {
49
- copy[key] = data[key]
50
- }
51
- }
52
- return copy
53
- }
54
-
55
- export function applyStateToVariant (variant: Variant, state: any) {
56
- if (variant.state) {
57
- for (const key in state) {
58
- if (variant.state[key] && !key.startsWith('_h') && typeof variant.state[key] === 'object' && !Array.isArray(variant.state[key])) {
59
- Object.assign(variant.state[key], state[key])
60
- } else {
61
- variant.state[key] = state[key]
62
- }
63
- }
64
- } else {
65
- variant.state = state
66
- }
67
- }
@@ -7,7 +7,7 @@ import pc from 'picocolors'
7
7
  import Tinypool from 'tinypool'
8
8
  import { createBirpc } from 'birpc'
9
9
  import { cpus } from 'os'
10
- import type { StoryFile } from '../types.js'
10
+ import type { ServerStoryFile } from '@histoire/shared'
11
11
  import { createPath } from '../tree.js'
12
12
  import type { Context } from '../context.js'
13
13
  import type { Payload, ReturnData } from './worker.js'
@@ -24,7 +24,10 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
24
24
  deps: {
25
25
  inline: [
26
26
  /histoire\/dist/,
27
+ /@histoire\/[\w\d-]+\/dist/,
28
+ /histoire-[\w\d-]+\/dist/,
27
29
  /@vue\/devtools-api/,
30
+ /vuetify/,
28
31
  ...ctx.config.viteNodeInlineDeps ?? [],
29
32
  ],
30
33
  },
@@ -70,7 +73,7 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
70
73
  }
71
74
  }
72
75
 
73
- async function executeStoryFile (storyFile: StoryFile) {
76
+ async function executeStoryFile (storyFile: ServerStoryFile) {
74
77
  try {
75
78
  const { workerPort } = createChannel()
76
79
  const { storyData } = await threadPool.run({
@@ -0,0 +1,13 @@
1
+ import type { ServerRunPayload } from '@histoire/shared'
2
+
3
+ export async function run (payload: ServerRunPayload) {
4
+ let result: any
5
+
6
+ // @TODO if (vue3)
7
+ {
8
+ const { run } = await import('@histoire/plugin-vue/collect')
9
+ result = await run(payload)
10
+ }
11
+
12
+ return result
13
+ }
@@ -4,9 +4,8 @@ import { ViteNodeRunner } from 'vite-node/client'
4
4
  import { createBirpc } from 'birpc'
5
5
  import type { FetchFunction, ResolveIdFunction } from 'vite-node'
6
6
  import { dirname, resolve } from 'pathe'
7
+ import type { ServerStoryFile, ServerStory, ServerRunPayload } from '@histoire/shared'
7
8
  import { createDomEnv } from '../dom/env.js'
8
- import type { StoryFile, Story } from '../types.js'
9
- import type { ServerRunPayload } from '../../client/server/index.js'
10
9
 
11
10
  const __dirname = dirname(fileURLToPath(import.meta.url))
12
11
 
@@ -14,11 +13,11 @@ export interface Payload {
14
13
  root: string
15
14
  base: string
16
15
  port: MessagePort
17
- storyFile: StoryFile
16
+ storyFile: ServerStoryFile
18
17
  }
19
18
 
20
19
  export interface ReturnData {
21
- storyData: Story[]
20
+ storyData: ServerStory[]
22
21
  }
23
22
 
24
23
  export default async (payload: Payload): Promise<ReturnData> => {
@@ -42,12 +41,15 @@ export default async (payload: Payload): Promise<ReturnData> => {
42
41
  })
43
42
 
44
43
  const { destroy: destroyDomEnv } = createDomEnv()
44
+ if (!global.CSS.supports) {
45
+ global.CSS.supports = () => false
46
+ }
45
47
 
46
48
  const el = window.document.createElement('div')
47
49
 
48
50
  // Mount app to collect stories/variants
49
- const { run } = (await runner.executeFile(resolve(__dirname, '../../client/server/index.js'))) as { run: (payload: ServerRunPayload) => Promise<any> }
50
- const storyData: Story[] = []
51
+ const { run } = (await runner.executeFile(resolve(__dirname, './run.js'))) as { run: (payload: ServerRunPayload) => Promise<any> }
52
+ const storyData: ServerStory[] = []
51
53
  await run({
52
54
  file: payload.storyFile,
53
55
  storyData,
@@ -11,7 +11,7 @@ import { ViteNodeServer } from 'vite-node/server'
11
11
  import { ViteNodeRunner } from 'vite-node/client'
12
12
  import pc from 'picocolors'
13
13
  import type MarkdownIt from 'markdown-it'
14
- import { TreeFile } from './tree.js'
14
+ import type { ServerTreeFile } from '@histoire/shared'
15
15
  import { defaultColors } from './colors.js'
16
16
  import { Plugin } from './plugin.js'
17
17
  import { findUp } from './util/find-up.js'
@@ -35,7 +35,7 @@ export interface BackgroundPreset {
35
35
  export interface TreeGroupConfig {
36
36
  title: string
37
37
  id?: string
38
- include?: (file: TreeFile) => boolean
38
+ include?: (file: ServerTreeFile) => boolean
39
39
  }
40
40
 
41
41
  export interface HistoireConfig {
@@ -61,7 +61,7 @@ export interface HistoireConfig {
61
61
  *
62
62
  * Use `'path'` use the real folder structure on your computer.
63
63
  */
64
- file?: 'title' | 'path' | ((file: TreeFile) => string[])
64
+ file?: 'title' | 'path' | ((file: ServerTreeFile) => string[])
65
65
  order?: 'asc' | ((a: string, b: string) => number)
66
66
  groups?: TreeGroupConfig[]
67
67
  }
@@ -1,12 +1,12 @@
1
1
  import { resolveConfig as resolveViteConfig } from 'vite'
2
+ import type { ServerStoryFile } from '@histoire/shared'
2
3
  import { resolveConfig, HistoireConfig, ConfigMode } from './config.js'
3
- import type { StoryFile } from './types.js'
4
4
 
5
5
  export interface Context {
6
6
  root: string
7
7
  config: HistoireConfig
8
8
  mode: ConfigMode
9
- storyFiles: StoryFile[]
9
+ storyFiles: ServerStoryFile[]
10
10
  }
11
11
 
12
12
  export interface CreateContextOptions {
@@ -2,12 +2,12 @@ import chokidar from 'chokidar'
2
2
  import path from 'pathe'
3
3
  import fs from 'fs-extra'
4
4
  import pc from 'picocolors'
5
+ import type { ServerStory, ServerVariant } from '@histoire/shared'
5
6
  import { TEMP_PATH } from './alias.js'
6
7
  import type { ConfigMode, HistoireConfig } from './config.js'
7
8
  import type { Context } from './context.js'
8
9
  import type { ModuleLoader } from './load.js'
9
10
  import { addStory, removeStory } from './stories.js'
10
- import type { Story, Variant } from './types.js'
11
11
 
12
12
  export interface Plugin {
13
13
  /**
@@ -77,7 +77,7 @@ export class DevPluginApi extends BasePluginApi {
77
77
  }
78
78
 
79
79
  export type BuildEndCallback = () => Promise<void> | void
80
- export type PreviewStoryCallback = (payload: { file: string, story: Story, variant: Variant, url: string }) => Promise<void> | void
80
+ export type PreviewStoryCallback = (payload: { file: string, story: ServerStory, variant: ServerVariant, url: string }) => Promise<void> | void
81
81
 
82
82
  export class BuildPluginApi extends BasePluginApi {
83
83
  buildEndCallbacks: BuildEndCallback[] = []
@@ -1,9 +1,9 @@
1
1
  import { createServer as createViteServer } from 'vite'
2
+ import type { ServerStoryFile } from '@histoire/shared'
2
3
  import { Context } from './context.js'
3
4
  import { getViteConfigWithPlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js'
4
5
  import { onStoryChange, watchStories } from './stories.js'
5
6
  import { useCollectStories } from './collect/index.js'
6
- import type { StoryFile } from './types.js'
7
7
  import { DevPluginApi } from './plugin.js'
8
8
  import { useModuleLoader } from './load.js'
9
9
 
@@ -46,7 +46,7 @@ export async function createServer (ctx: Context, port: number) {
46
46
  let queue: Promise<void>
47
47
  let queueResolve: () => void
48
48
  let queued = false
49
- let queuedFiles: StoryFile[] = []
49
+ let queuedFiles: ServerStoryFile[] = []
50
50
  let queuedAll = false
51
51
  let didAllStoriesYet = false
52
52
 
@@ -2,10 +2,10 @@ import chokidar from 'chokidar'
2
2
  import { globby } from 'globby'
3
3
  import Case from 'case'
4
4
  import { resolve, basename } from 'pathe'
5
+ import type { ServerStoryFile } from '@histoire/shared'
5
6
  import { Context } from './context.js'
6
- import type { StoryFile } from './types.js'
7
7
 
8
- type StoryChangeHandler = (file?: StoryFile) => unknown
8
+ type StoryChangeHandler = (file?: ServerStoryFile) => unknown
9
9
  const handlers: StoryChangeHandler[] = []
10
10
 
11
11
  let context: Context
@@ -34,7 +34,7 @@ export async function watchStories (newContext: Context) {
34
34
  return watcher
35
35
  }
36
36
 
37
- export function notifyStoryChange (file?: StoryFile) {
37
+ export function notifyStoryChange (file?: ServerStoryFile) {
38
38
  for (const handler of handlers) {
39
39
  handler(file)
40
40
  }
@@ -52,7 +52,7 @@ export function addStory (relativeFilePath: string) {
52
52
  fileName = fileName.substring(0, fileName.indexOf('.'))
53
53
  }
54
54
 
55
- const file: StoryFile = {
55
+ const file: ServerStoryFile = {
56
56
  id: fileId, // The file id will be changed by the story id after it is collected
57
57
  path: absoluteFilePath,
58
58
  fileName,
package/src/node/tree.ts CHANGED
@@ -1,32 +1,8 @@
1
1
  import pc from 'picocolors'
2
+ import type { ServerStoryFile, ServerTree, ServerTreeFile } from '@histoire/shared'
2
3
  import type { HistoireConfig, TreeGroupConfig } from './config.js'
3
- import type { StoryFile } from './types.js'
4
4
 
5
- export interface TreeFile {
6
- title: string
7
- path: string
8
- }
9
-
10
- export interface TreeLeaf {
11
- title: string
12
- index: number
13
- }
14
-
15
- export interface TreeFolder {
16
- title: string
17
- children: (TreeFolder | TreeLeaf)[]
18
- }
19
-
20
- export interface TreeGroup {
21
- group: true
22
- id: string
23
- title: string
24
- children: (TreeFolder | TreeLeaf)[]
25
- }
26
-
27
- export type Tree = (TreeGroup | TreeFolder | TreeLeaf)[]
28
-
29
- export function createPath (config: HistoireConfig, file: TreeFile) {
5
+ export function createPath (config: HistoireConfig, file: ServerTreeFile) {
30
6
  if (config.tree.file === 'title') {
31
7
  return file.title.split('/')
32
8
  }
@@ -41,7 +17,7 @@ export function createPath (config: HistoireConfig, file: TreeFile) {
41
17
  return config.tree.file(file)
42
18
  }
43
19
 
44
- export function makeTree (config: HistoireConfig, files: StoryFile[]) {
20
+ export function makeTree (config: HistoireConfig, files: ServerStoryFile[]) {
45
21
  interface ITreeObject {
46
22
  [index: string]: number | ITreeObject
47
23
  }
@@ -71,7 +47,7 @@ export function makeTree (config: HistoireConfig, files: StoryFile[]) {
71
47
  sortingFunction = config.tree.order
72
48
  }
73
49
 
74
- const result: Tree = []
50
+ const result: ServerTree = []
75
51
 
76
52
  for (const group of groups) {
77
53
  if (group === defaultGroup) {
@@ -88,7 +64,7 @@ export function makeTree (config: HistoireConfig, files: StoryFile[]) {
88
64
 
89
65
  return result
90
66
 
91
- function getGroup (file: StoryFile): ITreeGroup {
67
+ function getGroup (file: ServerStoryFile): ITreeGroup {
92
68
  if (file.story?.group) {
93
69
  const group = groups.find(g => g.groupConfig?.id === file.story.group)
94
70
  if (group) {
@@ -142,8 +118,8 @@ export function makeTree (config: HistoireConfig, files: StoryFile[]) {
142
118
  }
143
119
  }
144
120
 
145
- function buildTree (treeObject: ITreeObject): Tree {
146
- const tree: Tree = []
121
+ function buildTree (treeObject: ITreeObject): ServerTree {
122
+ const tree: ServerTree = []
147
123
 
148
124
  for (const [key, element] of Object.entries(treeObject)) {
149
125
  if (Number.isInteger(element)) {
package/src/node/vite.ts CHANGED
@@ -70,6 +70,11 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
70
70
 
71
71
  config () {
72
72
  return {
73
+ resolve: {
74
+ dedupe: [
75
+ 'vue',
76
+ ],
77
+ },
73
78
  optimizeDeps: {
74
79
  disabled: server,
75
80
  entries: [
@@ -87,6 +92,7 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
87
92
  ],
88
93
  exclude: [
89
94
  'histoire',
95
+ '@histoire',
90
96
  ],
91
97
  },
92
98
  server: {
package/vite.config.ts CHANGED
@@ -17,15 +17,19 @@ export default defineConfig({
17
17
  }
18
18
  },
19
19
  closeBundle () {
20
- const files = fs.readdirSync('./dist/bundled')
21
- for (const file of files) {
22
- if (file.endsWith('.js')) {
23
- const filePath = path.join('./dist/bundled', file)
24
- const content = fs.readFileSync(filePath, 'utf-8')
25
- if (content.includes('import__meta')) {
26
- fs.writeFileSync(filePath, content.replace(/import__meta/g, 'import.meta'), 'utf-8')
20
+ try {
21
+ const files = fs.readdirSync('./dist/bundled')
22
+ for (const file of files) {
23
+ if (file.endsWith('.js')) {
24
+ const filePath = path.join('./dist/bundled', file)
25
+ const content = fs.readFileSync(filePath, 'utf-8')
26
+ if (content.includes('import__meta')) {
27
+ fs.writeFileSync(filePath, content.replace(/import__meta/g, 'import.meta'), 'utf-8')
28
+ }
27
29
  }
28
30
  }
31
+ } catch (e) {
32
+ console.error(e)
29
33
  }
30
34
  },
31
35
  },
@@ -41,6 +45,7 @@ export default defineConfig({
41
45
  rollupOptions: {
42
46
  external: [
43
47
  /\$histoire/,
48
+ /@histoire/,
44
49
  /@vue\/*/,
45
50
  // eslint-disable-next-line @typescript-eslint/no-var-requires
46
51
  ...Object.keys(require('./package.json').dependencies),