histoire 0.3.0 → 0.3.3
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/dist/client/app/components/base/BaseEmpty.vue +1 -1
- package/dist/client/app/components/base/BaseOverflowMenu.vue +118 -0
- package/dist/client/app/components/base/BaseOverflowTab.vue +46 -0
- package/dist/client/app/components/exposed/Story.vue +12 -1
- package/dist/client/app/components/exposed/Variant.vue +6 -0
- package/dist/client/app/components/panel/PaneTabs.vue +64 -0
- package/dist/client/app/components/{story → panel}/StoryControls.vue +1 -1
- package/dist/client/app/components/{story → panel}/StoryDocs.vue +0 -0
- package/{src/client/app/components/story → dist/client/app/components/panel}/StoryEvent.vue +1 -0
- package/dist/client/app/components/{story → panel}/StoryEvents.vue +0 -0
- package/dist/client/app/components/{story → panel}/StorySidePanel.vue +3 -31
- package/dist/client/app/components/{story → panel}/StorySourceCode.vue +0 -0
- package/dist/client/app/components/sandbox/SandboxVue3.vue +10 -0
- package/dist/client/app/components/search/SearchPane.vue +19 -11
- package/dist/client/app/components/search/search-data.d.ts +9 -2
- package/dist/client/app/components/story/StoryResponsivePreview.vue +9 -131
- package/dist/client/app/components/story/StoryVariantSingle.vue +109 -0
- package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +39 -0
- package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
- package/dist/client/app/components/story/StoryVariantSingleView.vue +13 -6
- package/dist/client/app/components/story/StoryView.vue +2 -2
- package/dist/client/app/components/story/StoryViewer.vue +2 -92
- package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantBackground.vue +3 -3
- package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantNewTab.vue +2 -2
- package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantResponsiveSize.vue +3 -3
- package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
- package/dist/client/app/stores/events.js +1 -1
- package/dist/client/app/stores/story.d.ts +27 -0
- package/dist/client/app/style/transitions.pcss +13 -0
- package/dist/client/app/types.d.ts +3 -0
- package/dist/client/app/util/mapping.js +2 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/server/index.d.ts +7 -2
- package/dist/client/server/index.js +8 -26
- package/{src/client/server/Story.server.vue → dist/client/server/vue3/Story.vue} +1 -1
- package/dist/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
- package/dist/client/server/vue3/run.d.ts +2 -0
- package/dist/client/server/vue3/run.js +32 -0
- package/dist/node/collect/worker.js +6 -2
- package/dist/node/search.d.ts +7 -1
- package/dist/node/search.js +21 -12
- package/dist/node/vite.js +3 -0
- package/dist/style.css +93 -69
- package/package.json +5 -6
- package/src/client/app/components/base/BaseEmpty.vue +1 -1
- package/src/client/app/components/base/BaseOverflowMenu.vue +118 -0
- package/src/client/app/components/base/BaseOverflowTab.vue +46 -0
- package/src/client/app/components/exposed/Story.vue +12 -1
- package/src/client/app/components/exposed/Variant.vue +6 -0
- package/src/client/app/components/panel/PaneTabs.vue +64 -0
- package/src/client/app/components/{story → panel}/StoryControls.vue +1 -1
- package/src/client/app/components/{story → panel}/StoryDocs.vue +0 -0
- package/{dist/client/app/components/story → src/client/app/components/panel}/StoryEvent.vue +1 -0
- package/src/client/app/components/{story → panel}/StoryEvents.vue +0 -0
- package/src/client/app/components/{story → panel}/StorySidePanel.vue +3 -31
- package/src/client/app/components/{story → panel}/StorySourceCode.vue +0 -0
- package/src/client/app/components/sandbox/SandboxVue3.vue +10 -0
- package/src/client/app/components/search/SearchPane.vue +19 -11
- package/src/client/app/components/search/search-data.ts +7 -2
- package/src/client/app/components/story/StoryResponsivePreview.vue +9 -131
- package/src/client/app/components/story/StoryVariantSingle.vue +109 -0
- package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +39 -0
- package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
- package/src/client/app/components/story/StoryVariantSingleView.vue +13 -6
- package/src/client/app/components/story/StoryView.vue +2 -2
- package/src/client/app/components/story/StoryViewer.vue +2 -92
- package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantBackground.vue +3 -3
- package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantNewTab.vue +2 -2
- package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantResponsiveSize.vue +3 -3
- package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
- package/src/client/app/sandbox.ts +1 -1
- package/src/client/app/stores/events.ts +1 -1
- package/src/client/app/style/transitions.pcss +13 -0
- package/src/client/app/types.ts +4 -0
- package/src/client/app/util/mapping.ts +2 -0
- package/src/client/index.ts +2 -2
- package/src/client/server/index.ts +14 -27
- package/{dist/client/server/Story.server.vue → src/client/server/vue3/Story.vue} +1 -1
- package/src/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
- package/src/client/server/vue3/run.ts +38 -0
- package/src/node/collect/worker.ts +7 -2
- package/src/node/search.ts +23 -12
- package/src/node/vite.ts +3 -0
|
@@ -8,8 +8,8 @@ import BaseSplitPane from '../base/BaseSplitPane.vue'
|
|
|
8
8
|
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
9
9
|
import { isMobile } from '../../util/responsive'
|
|
10
10
|
import StoryViewer from './StoryViewer.vue'
|
|
11
|
-
import StorySidePanel from '
|
|
12
|
-
import StoryDocs from '
|
|
11
|
+
import StorySidePanel from '../panel/StorySidePanel.vue'
|
|
12
|
+
import StoryDocs from '../panel/StoryDocs.vue'
|
|
13
13
|
|
|
14
14
|
const storyStore = useStoryStore()
|
|
15
15
|
|
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed, ref, watch } from 'vue'
|
|
3
3
|
import { useStoryStore } from '../../stores/story'
|
|
4
|
-
import { Icon } from '@iconify/vue'
|
|
5
|
-
import { isMobile } from '../../util/responsive'
|
|
6
|
-
import BaseSplitPane from '../base/BaseSplitPane.vue'
|
|
7
4
|
import StoryVariantListItem from './StoryVariantListItem.vue'
|
|
8
|
-
import StoryVariantSingleView from './StoryVariantSingleView.vue'
|
|
9
5
|
import MobileOverlay from '../app/MobileOverlay.vue'
|
|
10
6
|
import StoryVariantGrid from './StoryVariantGrid.vue'
|
|
7
|
+
import StoryVariantSingle from './StoryVariantSingle.vue'
|
|
11
8
|
|
|
12
9
|
const storyStore = useStoryStore()
|
|
13
10
|
|
|
14
|
-
const hasSingleVariant = computed(() => (storyStore.currentStory?.variants.length === 1))
|
|
15
|
-
|
|
16
11
|
const variant = computed(() => storyStore.currentVariant)
|
|
17
12
|
|
|
18
13
|
const isMenuOpened = ref(false)
|
|
19
14
|
|
|
20
|
-
function openMenu () {
|
|
21
|
-
isMenuOpened.value = true
|
|
22
|
-
}
|
|
23
|
-
|
|
24
15
|
function closeMenu () {
|
|
25
16
|
isMenuOpened.value = false
|
|
26
17
|
}
|
|
@@ -36,88 +27,7 @@ watch(variant, () => {
|
|
|
36
27
|
<StoryVariantGrid
|
|
37
28
|
v-if="storyStore.currentStory.layout.type === 'grid'"
|
|
38
29
|
/>
|
|
39
|
-
|
|
40
|
-
<template v-else-if="storyStore.currentStory.layout.type === 'single'">
|
|
41
|
-
<div
|
|
42
|
-
v-if="hasSingleVariant && storyStore.currentVariant"
|
|
43
|
-
class="htw-p-2 htw-h-full"
|
|
44
|
-
>
|
|
45
|
-
<StoryVariantSingleView
|
|
46
|
-
v-if="storyStore.currentVariant.configReady"
|
|
47
|
-
:variant="storyStore.currentVariant"
|
|
48
|
-
:story="storyStore.currentStory"
|
|
49
|
-
/>
|
|
50
|
-
</div>
|
|
51
|
-
<template v-else>
|
|
52
|
-
<div
|
|
53
|
-
v-if="isMobile"
|
|
54
|
-
class="htw-divide-y htw-divide-gray-100 dark:htw-divide-gray-800 htw-h-full htw-flex htw-flex-col"
|
|
55
|
-
>
|
|
56
|
-
<a
|
|
57
|
-
class="htw-px-6 htw-h-12 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer htw-flex htw-gap-2 htw-flex-wrap htw-w-full htw-items-center"
|
|
58
|
-
@click="openMenu"
|
|
59
|
-
>
|
|
60
|
-
<template v-if="variant">
|
|
61
|
-
<Icon
|
|
62
|
-
:icon="variant.icon ?? 'carbon:cube'"
|
|
63
|
-
class="base-list-item-link-icon htw-w-5 htw-h-5 htw-flex-none"
|
|
64
|
-
:class="{
|
|
65
|
-
'htw-text-gray-500': !variant.iconColor,
|
|
66
|
-
'bind-icon-color': variant.iconColor,
|
|
67
|
-
}"
|
|
68
|
-
/>
|
|
69
|
-
{{ variant.title }}
|
|
70
|
-
</template>
|
|
71
|
-
<template v-else>
|
|
72
|
-
Select a variant...
|
|
73
|
-
</template>
|
|
74
|
-
|
|
75
|
-
<Icon
|
|
76
|
-
icon="carbon:chevron-sort"
|
|
77
|
-
class="htw-w-5 htw-h-5 htw-shrink-0 htw-ml-auto"
|
|
78
|
-
/>
|
|
79
|
-
</a>
|
|
80
|
-
<div
|
|
81
|
-
v-if="storyStore.currentVariant"
|
|
82
|
-
class="htw-p-2 htw-h-full"
|
|
83
|
-
>
|
|
84
|
-
<StoryVariantSingleView
|
|
85
|
-
v-if="storyStore.currentVariant.configReady"
|
|
86
|
-
:variant="storyStore.currentVariant"
|
|
87
|
-
:story="storyStore.currentStory"
|
|
88
|
-
/>
|
|
89
|
-
</div>
|
|
90
|
-
</div>
|
|
91
|
-
<BaseSplitPane
|
|
92
|
-
v-else
|
|
93
|
-
save-id="story-single-main-split"
|
|
94
|
-
:min="5"
|
|
95
|
-
:max="40"
|
|
96
|
-
:default-split="17"
|
|
97
|
-
>
|
|
98
|
-
<template #first>
|
|
99
|
-
<div class="htw-h-full htw-overflow-y-auto">
|
|
100
|
-
<StoryVariantListItem
|
|
101
|
-
v-for="(variant, index) of storyStore.currentStory.variants"
|
|
102
|
-
:key="index"
|
|
103
|
-
:variant="variant"
|
|
104
|
-
/>
|
|
105
|
-
</div>
|
|
106
|
-
</template>
|
|
107
|
-
<template #last>
|
|
108
|
-
<div
|
|
109
|
-
v-if="storyStore.currentVariant"
|
|
110
|
-
class="htw-p-2 htw-h-full"
|
|
111
|
-
>
|
|
112
|
-
<StoryVariantSingleView
|
|
113
|
-
:variant="storyStore.currentVariant"
|
|
114
|
-
:story="storyStore.currentStory"
|
|
115
|
-
/>
|
|
116
|
-
</div>
|
|
117
|
-
</template>
|
|
118
|
-
</BaseSplitPane>
|
|
119
|
-
</template>
|
|
120
|
-
</template>
|
|
30
|
+
<StoryVariantSingle v-else-if="storyStore.currentStory.layout.type === 'single'" />
|
|
121
31
|
</div>
|
|
122
32
|
|
|
123
33
|
<MobileOverlay
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { Icon } from '@iconify/vue'
|
|
3
|
-
import { usePreviewSettingsStore } from '
|
|
4
|
-
import { histoireConfig } from '
|
|
5
|
-
import BaseCheckbox from '
|
|
3
|
+
import { usePreviewSettingsStore } from '../../stores/preview-settings'
|
|
4
|
+
import { histoireConfig } from '../../util/config'
|
|
5
|
+
import BaseCheckbox from '../base/BaseCheckbox.vue'
|
|
6
6
|
|
|
7
7
|
const settings = usePreviewSettingsStore().currentSettings
|
|
8
8
|
</script>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { Icon } from '@iconify/vue'
|
|
3
|
-
import type { Story, Variant } from '
|
|
3
|
+
import type { Story, Variant } from '../../types'
|
|
4
4
|
import { computed } from 'vue'
|
|
5
|
-
import { getSandboxUrl } from '
|
|
5
|
+
import { getSandboxUrl } from '../sandbox/lib'
|
|
6
6
|
|
|
7
7
|
const props = defineProps<{
|
|
8
8
|
variant: Variant
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { Icon } from '@iconify/vue'
|
|
3
|
-
import { usePreviewSettingsStore } from '
|
|
4
|
-
import { histoireConfig } from '
|
|
5
|
-
import BaseCheckbox from '
|
|
3
|
+
import { usePreviewSettingsStore } from '../../stores/preview-settings'
|
|
4
|
+
import { histoireConfig } from '../../util/config'
|
|
5
|
+
import BaseCheckbox from '../base/BaseCheckbox.vue'
|
|
6
6
|
|
|
7
7
|
const settings = usePreviewSettingsStore().currentSettings
|
|
8
8
|
</script>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './style/sandbox.css'
|
|
2
2
|
import { parseQuery } from 'vue-router'
|
|
3
|
-
import { computed, createApp, h, onMounted, ref, watch
|
|
3
|
+
import { computed, createApp, h, onMounted, ref, watch } from 'vue'
|
|
4
4
|
import { createPinia } from 'pinia'
|
|
5
5
|
import { registerGlobalComponents } from './global-components'
|
|
6
6
|
import SandboxVue3 from './components/sandbox/SandboxVue3.vue'
|
|
@@ -11,6 +11,19 @@
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
.__histoire-scale-y {
|
|
15
|
+
&-enter-active,
|
|
16
|
+
&-leave-active {
|
|
17
|
+
transition: transform .15s, opacity .15s;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&-enter-from,
|
|
21
|
+
&-leave-to {
|
|
22
|
+
transform: scaleY(0);
|
|
23
|
+
opacity: 0;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
.__histoire-fade {
|
|
15
28
|
&-enter-active,
|
|
16
29
|
&-leave-active {
|
package/src/client/app/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { App } from 'vue'
|
|
1
2
|
import type { RouteLocationRaw } from 'vue-router'
|
|
2
3
|
|
|
3
4
|
export interface StoryFile {
|
|
@@ -15,6 +16,7 @@ export interface Story {
|
|
|
15
16
|
variants: Variant[]
|
|
16
17
|
layout?: {
|
|
17
18
|
type: 'single'
|
|
19
|
+
iframe?: boolean
|
|
18
20
|
} | {
|
|
19
21
|
type: 'grid'
|
|
20
22
|
width?: number | string
|
|
@@ -24,6 +26,7 @@ export interface Story {
|
|
|
24
26
|
docsOnly?: boolean
|
|
25
27
|
file?: StoryFile
|
|
26
28
|
lastSelectedVariant?: Variant
|
|
29
|
+
slots?: () => Readonly<any>
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
export interface Variant {
|
|
@@ -32,6 +35,7 @@ export interface Variant {
|
|
|
32
35
|
icon?: string
|
|
33
36
|
iconColor?: string
|
|
34
37
|
initState?: () => any
|
|
38
|
+
setupApp?: (payload: any) => unknown
|
|
35
39
|
slots?: () => Readonly<any>
|
|
36
40
|
state?: any
|
|
37
41
|
source?: string
|
|
@@ -10,6 +10,7 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
|
|
|
10
10
|
title: file.story.title,
|
|
11
11
|
file: markRaw(file),
|
|
12
12
|
variants: file.story.variants.map(v => mapVariant(v)),
|
|
13
|
+
slots: () => ({}),
|
|
13
14
|
},
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -42,6 +43,7 @@ export function mapVariant (variant: Variant): Variant {
|
|
|
42
43
|
...variant,
|
|
43
44
|
state: null,
|
|
44
45
|
initState: null,
|
|
46
|
+
setupApp: null,
|
|
45
47
|
slots: () => ({}),
|
|
46
48
|
previewReady: false,
|
|
47
49
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -4,8 +4,8 @@ export { hstEvent } from './app/util/events'
|
|
|
4
4
|
|
|
5
5
|
export type Vue3StorySetupHandler = (payload: {
|
|
6
6
|
app: App
|
|
7
|
-
story
|
|
8
|
-
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 {
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
12
|
+
// @TODO if (vue3)
|
|
13
|
+
{
|
|
14
|
+
const { run } = await import('./vue3/run.js')
|
|
15
|
+
result = await run(payload)
|
|
16
|
+
}
|
|
29
17
|
|
|
30
|
-
|
|
31
|
-
app.unmount()
|
|
18
|
+
return result
|
|
32
19
|
}
|
|
File without changes
|
|
@@ -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(
|
|
55
|
+
await run({
|
|
56
|
+
file: payload.storyFile,
|
|
57
|
+
storyData,
|
|
58
|
+
el,
|
|
59
|
+
})
|
|
55
60
|
|
|
56
61
|
destroyDomEnv()
|
|
57
62
|
|
package/src/node/search.ts
CHANGED
|
@@ -1,50 +1,57 @@
|
|
|
1
1
|
import { createRequire } from 'module'
|
|
2
2
|
import flexsearch from 'flexsearch'
|
|
3
3
|
import path from 'pathe'
|
|
4
|
+
import Case from 'case'
|
|
4
5
|
import { Context } from './context.js'
|
|
5
6
|
import { loadModule } from './load.js'
|
|
6
7
|
|
|
7
8
|
const require = createRequire(import.meta.url)
|
|
8
9
|
|
|
9
10
|
export async function generateSearchData (ctx: Context) {
|
|
11
|
+
let uid = 0
|
|
12
|
+
const idMap: Record<number, { id: string, kind: string }> = {}
|
|
10
13
|
const flexsearchRoot = path.dirname(require.resolve('flexsearch/package.json'))
|
|
11
14
|
const searchIndex = new flexsearch.Document({
|
|
12
|
-
preset: '
|
|
15
|
+
preset: 'memory',
|
|
13
16
|
document: {
|
|
14
17
|
id: 'id',
|
|
15
18
|
index: [
|
|
16
19
|
'title',
|
|
17
20
|
'docs',
|
|
18
21
|
],
|
|
19
|
-
store: [
|
|
20
|
-
'kind',
|
|
21
|
-
],
|
|
22
22
|
},
|
|
23
23
|
charset: await loadModule(`${flexsearchRoot}/dist/module/lang/latin/advanced.js`),
|
|
24
24
|
language: await loadModule(`${flexsearchRoot}/dist/module/lang/en.js`),
|
|
25
|
-
tokenize: '
|
|
25
|
+
tokenize: 'forward',
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
+
function addToIdMap (id: string, kind: string) {
|
|
29
|
+
const n = uid++
|
|
30
|
+
idMap[n] = { id, kind }
|
|
31
|
+
return n
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
for (const storyFile of ctx.storyFiles) {
|
|
29
35
|
if (storyFile.story) {
|
|
30
36
|
searchIndex.add({
|
|
31
|
-
id: storyFile.story.id,
|
|
32
|
-
|
|
33
|
-
title: storyFile.story.title,
|
|
37
|
+
id: addToIdMap(storyFile.story.id, 'story'),
|
|
38
|
+
title: processTitle(storyFile.story.title),
|
|
34
39
|
docs: '', // @TODO
|
|
35
40
|
})
|
|
36
41
|
for (const variant of storyFile.story.variants) {
|
|
37
42
|
searchIndex.add({
|
|
38
|
-
id: `${storyFile.story.id}:${variant.id}`,
|
|
39
|
-
|
|
40
|
-
title: `${storyFile.story.title} ${variant.title}`,
|
|
43
|
+
id: addToIdMap(`${storyFile.story.id}:${variant.id}`, 'variant'),
|
|
44
|
+
title: processTitle(`${storyFile.story.title} ${variant.title}`),
|
|
41
45
|
docs: '', // @TODO
|
|
42
46
|
})
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
return
|
|
51
|
+
return {
|
|
52
|
+
index: await exportSearchIndex(searchIndex),
|
|
53
|
+
idMap,
|
|
54
|
+
}
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
const exportKeys = new Set([
|
|
@@ -73,3 +80,7 @@ async function exportSearchIndex (index) {
|
|
|
73
80
|
})
|
|
74
81
|
})
|
|
75
82
|
}
|
|
83
|
+
|
|
84
|
+
function processTitle (title: string) {
|
|
85
|
+
return title.split(' ').map(str => Case.lower(str)).join(' ')
|
|
86
|
+
}
|
package/src/node/vite.ts
CHANGED
|
@@ -57,6 +57,9 @@ export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
|
|
|
57
57
|
dirname(require.resolve('vscode-oniguruma/package.json')),
|
|
58
58
|
dirname(require.resolve('case/package.json')),
|
|
59
59
|
],
|
|
60
|
+
exclude: [
|
|
61
|
+
'histoire/client',
|
|
62
|
+
],
|
|
60
63
|
},
|
|
61
64
|
server: {
|
|
62
65
|
fs: {
|