histoire 0.7.3 → 0.7.4
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.
- package/client.d.ts +1 -1
- package/dist/bundled/StoryView.js +22 -19
- package/dist/bundled/dark.js +4 -0
- package/dist/bundled/index.js +0 -1
- package/dist/bundled/index2.js +6 -6
- package/dist/bundled/mapping.js +78 -0
- package/dist/bundled/sandbox.js +7 -6
- package/dist/bundled/state.js +4 -39
- package/dist/bundled/style.css +3 -3
- package/dist/client/app/App.vue +2 -2
- package/dist/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
- package/dist/client/app/components/panel/ControlsComponentProps.vue +2 -1
- package/dist/client/app/components/panel/StatePresets.vue +2 -1
- package/dist/client/app/components/panel/StoryControls.vue +1 -1
- package/dist/client/app/components/panel/StorySourceCode.vue +2 -2
- package/dist/client/app/components/story/StoryVariantGridItem.vue +1 -1
- package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
- package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
- package/dist/client/app/components/story/StoryVariantSingleView.vue +1 -1
- package/dist/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
- package/dist/client/app/components/tree/StoryGroup.vue +1 -1
- package/dist/client/app/index.js +0 -2
- package/dist/client/app/sandbox.js +4 -5
- package/dist/client/app/types.d.ts +1 -52
- package/dist/client/app/util/mapping.d.ts +1 -1
- package/dist/client/app/util/mapping.js +50 -36
- package/dist/client/app/{components/sandbox/lib.d.ts → util/sandbox.d.ts} +1 -1
- package/dist/client/app/{components/sandbox/lib.js → util/sandbox.js} +1 -1
- package/dist/client/app/util/state.d.ts +0 -4
- package/dist/client/app/util/state.js +3 -39
- package/dist/node/collect/index.d.ts +2 -2
- package/dist/node/collect/index.js +3 -0
- package/dist/node/collect/run.d.ts +2 -0
- package/dist/{client/server/index.js → node/collect/run.js} +1 -1
- package/dist/node/collect/worker.d.ts +3 -3
- package/dist/node/collect/worker.js +4 -1
- package/dist/node/config.d.ts +3 -3
- package/dist/node/context.d.ts +2 -2
- package/dist/node/plugin.d.ts +3 -3
- package/dist/node/stories.d.ts +4 -4
- package/dist/node/tree.d.ts +3 -22
- package/package.json +4 -2
- package/src/client/app/App.vue +2 -2
- package/src/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
- package/src/client/app/components/panel/ControlsComponentProps.vue +2 -1
- package/src/client/app/components/panel/StatePresets.vue +2 -1
- package/src/client/app/components/panel/StoryControls.vue +1 -1
- package/src/client/app/components/panel/StorySourceCode.vue +2 -2
- package/src/client/app/components/story/StoryVariantGridItem.vue +1 -1
- package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
- package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
- package/src/client/app/components/story/StoryVariantSingleView.vue +1 -1
- package/src/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
- package/src/client/app/components/tree/StoryGroup.vue +1 -1
- package/src/client/app/index.ts +0 -2
- package/src/client/app/sandbox.ts +4 -5
- package/src/client/app/types.ts +6 -57
- package/src/client/app/util/mapping.ts +47 -34
- package/src/client/app/{components/sandbox/lib.ts → util/sandbox.ts} +2 -2
- package/src/client/app/util/state.ts +4 -39
- package/src/node/collect/index.ts +5 -2
- package/src/node/collect/run.ts +13 -0
- package/src/node/collect/worker.ts +8 -6
- package/src/node/config.ts +3 -3
- package/src/node/context.ts +2 -2
- package/src/node/plugin.ts +2 -2
- package/src/node/server.ts +2 -2
- package/src/node/stories.ts +4 -4
- package/src/node/tree.ts +7 -31
- package/vite.config.ts +12 -7
- package/dist/bundled/SandboxVue3.js +0 -717
- package/dist/bundled/global-components.js +0 -213
- package/dist/client/app/codegen/const.d.ts +0 -1
- package/dist/client/app/codegen/const.js +0 -3
- package/dist/client/app/codegen/serialize-js.d.ts +0 -1
- package/dist/client/app/codegen/serialize-js.js +0 -126
- package/dist/client/app/codegen/util.d.ts +0 -10
- package/dist/client/app/codegen/util.js +0 -70
- package/dist/client/app/codegen/vue3.d.ts +0 -4
- package/dist/client/app/codegen/vue3.js +0 -357
- package/dist/client/app/components/exposed/Story.vue +0 -106
- package/dist/client/app/components/exposed/Variant.vue +0 -78
- package/dist/client/app/components/sandbox/RouterLinkStub.d.ts +0 -21
- package/dist/client/app/components/sandbox/RouterLinkStub.js +0 -43
- package/dist/client/app/components/sandbox/SandboxVue3.vue +0 -185
- package/dist/client/app/global-components.d.ts +0 -2
- package/dist/client/app/global-components.js +0 -10
- package/dist/client/server/index.d.ts +0 -7
- package/dist/client/server/vue3/Story.vue +0 -120
- package/dist/client/server/vue3/Variant.vue +0 -52
- package/dist/client/server/vue3/run.d.ts +0 -2
- package/dist/client/server/vue3/run.js +0 -45
- package/dist/node/types.d.ts +0 -50
- package/dist/node/types.js +0 -1
- package/src/client/app/codegen/const.ts +0 -3
- package/src/client/app/codegen/serialize-js.ts +0 -133
- package/src/client/app/codegen/util.ts +0 -79
- package/src/client/app/codegen/vue3.ts +0 -361
- package/src/client/app/components/exposed/Story.vue +0 -106
- package/src/client/app/components/exposed/Variant.vue +0 -78
- package/src/client/app/components/sandbox/RouterLinkStub.ts +0 -49
- package/src/client/app/components/sandbox/SandboxVue3.vue +0 -185
- package/src/client/app/global-components.ts +0 -13
- package/src/client/server/index.ts +0 -19
- package/src/client/server/vue3/Story.vue +0 -120
- package/src/client/server/vue3/Variant.vue +0 -52
- package/src/client/server/vue3/run.ts +0 -55
- package/src/components.d.ts +0 -143
- package/src/node/types.ts +0 -53
|
@@ -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 {
|
|
5
|
-
import SandboxVue3 from '
|
|
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 {
|
|
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(
|
|
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 => {
|
package/src/client/app/types.ts
CHANGED
|
@@ -1,49 +1,11 @@
|
|
|
1
1
|
import type { RouteLocationRaw } from 'vue-router'
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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 '
|
|
3
|
-
import { Story, Variant } from '
|
|
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,11 +1,14 @@
|
|
|
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
|
|
|
8
|
+
if (typeof unwrappedValue === 'symbol') {
|
|
9
|
+
return unwrappedValue.toString()
|
|
10
|
+
}
|
|
11
|
+
|
|
9
12
|
if (seen.has(unwrappedValue)) {
|
|
10
13
|
return Array.isArray(unwrappedValue) ? [] : {}
|
|
11
14
|
}
|
|
@@ -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 {
|
|
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:
|
|
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:
|
|
16
|
+
storyFile: ServerStoryFile
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
export interface ReturnData {
|
|
21
|
-
storyData:
|
|
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, '
|
|
50
|
-
const storyData:
|
|
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,
|
package/src/node/config.ts
CHANGED
|
@@ -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 {
|
|
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:
|
|
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:
|
|
64
|
+
file?: 'title' | 'path' | ((file: ServerTreeFile) => string[])
|
|
65
65
|
order?: 'asc' | ((a: string, b: string) => number)
|
|
66
66
|
groups?: TreeGroupConfig[]
|
|
67
67
|
}
|
package/src/node/context.ts
CHANGED
|
@@ -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:
|
|
9
|
+
storyFiles: ServerStoryFile[]
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface CreateContextOptions {
|
package/src/node/plugin.ts
CHANGED
|
@@ -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:
|
|
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[] = []
|
package/src/node/server.ts
CHANGED
|
@@ -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:
|
|
49
|
+
let queuedFiles: ServerStoryFile[] = []
|
|
50
50
|
let queuedAll = false
|
|
51
51
|
let didAllStoriesYet = false
|
|
52
52
|
|
package/src/node/stories.ts
CHANGED
|
@@ -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?:
|
|
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?:
|
|
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:
|
|
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
|
|
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:
|
|
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:
|
|
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:
|
|
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):
|
|
146
|
-
const 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/vite.config.ts
CHANGED
|
@@ -17,15 +17,19 @@ export default defineConfig({
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
closeBundle () {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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),
|