histoire 0.7.2 → 0.7.5
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 +13 -44
- 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 +1 -5
- package/dist/client/app/util/state.js +12 -44
- 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/dist/node/vite.js +1 -0
- package/dist/style.css +76 -0
- 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 +15 -44
- 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/src/node/vite.ts +1 -0
- package/vite.config.ts +12 -7
- package/dist/bundled/SandboxVue3.js +0 -706
- 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 -113
- 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 -119
- 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
|
<script lang="ts" setup>
|
|
2
2
|
import { PropType } from 'vue'
|
|
3
3
|
import { Icon } from '@iconify/vue'
|
|
4
|
+
import { SandboxVue3 } from '@histoire/plugin-vue/client'
|
|
4
5
|
import type { Story, Variant } from '../../types'
|
|
5
|
-
import SandboxVue3 from '../sandbox/SandboxVue3.vue'
|
|
6
6
|
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
7
7
|
import StatePresets from './StatePresets.vue'
|
|
8
8
|
import ControlsComponentProps from './ControlsComponentProps.vue'
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { computed, onMounted, PropType, ref, shallowRef, watch } from 'vue'
|
|
3
3
|
import { getHighlighter, Highlighter, setCDN } from 'shiki'
|
|
4
4
|
import { HstCopyIcon } from '@histoire/controls'
|
|
5
|
-
import {
|
|
5
|
+
import { unindent } from '@histoire/shared'
|
|
6
|
+
import { generateSourceCode } from '@histoire/plugin-vue/client'
|
|
6
7
|
import type { Variant } from '../../types'
|
|
7
8
|
import { isDark } from '../../util/dark'
|
|
8
|
-
import { unindent } from '../../codegen/util'
|
|
9
9
|
|
|
10
10
|
const props = defineProps({
|
|
11
11
|
variant: {
|
|
@@ -3,9 +3,9 @@ import { PropType, ref, toRefs } from 'vue'
|
|
|
3
3
|
import { Icon } from '@iconify/vue'
|
|
4
4
|
import { useRouter } from 'vue-router'
|
|
5
5
|
import { useResizeObserver } from '@vueuse/core'
|
|
6
|
+
import { SandboxVue3 } from '@histoire/plugin-vue/client'
|
|
6
7
|
import { useCurrentVariantRoute } from '../../util/variant'
|
|
7
8
|
import type { Story, Variant } from '../../types'
|
|
8
|
-
import SandboxVue3 from '../sandbox/SandboxVue3.vue'
|
|
9
9
|
import { useScrollOnActive } from '../../util/scroll'
|
|
10
10
|
|
|
11
11
|
const props = defineProps({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
+
import { SandboxVue3 } from '@histoire/plugin-vue/client'
|
|
2
3
|
import type { Story, Variant } from '../../types'
|
|
3
|
-
import SandboxVue3 from '../sandbox/SandboxVue3.vue'
|
|
4
4
|
import StoryResponsivePreview from './StoryResponsivePreview.vue'
|
|
5
5
|
|
|
6
6
|
const props = defineProps<{
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
import { computed, onUnmounted, Ref, ref, toRaw, watch } from 'vue'
|
|
3
3
|
import { useEventListener } from '@vueuse/core'
|
|
4
4
|
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { applyStateToVariant } from '@histoire/shared'
|
|
5
6
|
import { STATE_SYNC, PREVIEW_SETTINGS_SYNC, SANDBOX_READY, EVENT_SEND } from '../../util/const'
|
|
6
7
|
import type { Story, Variant } from '../../types'
|
|
7
8
|
import HatchedPattern from '../misc/HatchedPattern.vue'
|
|
8
9
|
import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
|
|
9
|
-
import { getSandboxUrl } from '
|
|
10
|
+
import { getSandboxUrl } from '../../util/sandbox'
|
|
10
11
|
import { usePreviewSettingsStore } from '../../stores/preview-settings'
|
|
11
12
|
import { HstEvent, useEventsStore } from '../../stores/events'
|
|
12
13
|
import StoryResponsivePreview from './StoryResponsivePreview.vue'
|
|
13
|
-
import {
|
|
14
|
+
import { toRawDeep } from '../../util/state'
|
|
14
15
|
|
|
15
16
|
const props = defineProps<{
|
|
16
17
|
story: Story
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Icon } from '@iconify/vue'
|
|
3
3
|
import type { Story, Variant } from '../../types'
|
|
4
4
|
import { computed } from 'vue'
|
|
5
|
-
import { getSandboxUrl } from '
|
|
5
|
+
import { getSandboxUrl } from '../../util/sandbox'
|
|
6
6
|
|
|
7
7
|
const props = defineProps<{
|
|
8
8
|
variant: Variant
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import type { Story, TreeGroup
|
|
2
|
+
import type { Story, TreeGroup } from '../../types'
|
|
3
3
|
import StoryListItem from './StoryListItem.vue'
|
|
4
4
|
import StoryListFolder from './StoryListFolder.vue'
|
|
5
5
|
import { Icon } from '@iconify/vue'
|
package/src/client/app/index.ts
CHANGED
|
@@ -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 {
|
|
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,61 +1,32 @@
|
|
|
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
|
-
export function toRawDeep (val) {
|
|
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
|
+
|
|
12
|
+
if (seen.has(unwrappedValue)) {
|
|
13
|
+
return Array.isArray(unwrappedValue) ? [] : {}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
seen.add(unwrappedValue)
|
|
17
|
+
|
|
9
18
|
if (!isObject(unwrappedValue)) {
|
|
10
19
|
return unwrappedValue
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
if (Array.isArray(unwrappedValue)) {
|
|
14
|
-
return unwrappedValue.map(toRawDeep)
|
|
23
|
+
return unwrappedValue.map(value => toRawDeep(value, seen))
|
|
15
24
|
}
|
|
16
25
|
|
|
17
|
-
return toRawObject(unwrappedValue)
|
|
26
|
+
return toRawObject(unwrappedValue, seen)
|
|
18
27
|
}
|
|
19
28
|
|
|
20
|
-
const toRawObject = (obj: Record<any, any
|
|
21
|
-
raw[key] = toRawDeep(obj[key])
|
|
29
|
+
const toRawObject = (obj: Record<any, any>, seen = new Set()) => Object.keys(obj).reduce((raw, key) => {
|
|
30
|
+
raw[key] = toRawDeep(obj[key], seen)
|
|
22
31
|
return raw
|
|
23
32
|
}, {})
|
|
24
|
-
|
|
25
|
-
export function clone (data) {
|
|
26
|
-
try {
|
|
27
|
-
return structuredClone(data)
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.warn(e, `Fallback to JSON cloning`)
|
|
30
|
-
try {
|
|
31
|
-
return JSON.parse(JSON.stringify(data))
|
|
32
|
-
} catch (e) {
|
|
33
|
-
console.error(e)
|
|
34
|
-
}
|
|
35
|
-
return data
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function omit (data, keys: string[]) {
|
|
40
|
-
const copy = {}
|
|
41
|
-
for (const key in data) {
|
|
42
|
-
if (!keys.includes(key)) {
|
|
43
|
-
copy[key] = data[key]
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return copy
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function applyStateToVariant (variant: Variant, state: any) {
|
|
50
|
-
if (variant.state) {
|
|
51
|
-
for (const key in state) {
|
|
52
|
-
if (variant.state[key] && !key.startsWith('_h') && typeof variant.state[key] === 'object' && !Array.isArray(variant.state[key])) {
|
|
53
|
-
Object.assign(variant.state[key], state[key])
|
|
54
|
-
} else {
|
|
55
|
-
variant.state[key] = state[key]
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
variant.state = state
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -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,
|