histoire 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundled/BaseEmpty.js +13 -0
- package/dist/bundled/HomeView.js +23 -0
- package/dist/bundled/MobileOverlay.js +303 -0
- package/dist/bundled/SearchPane.js +504 -0
- package/dist/bundled/StoryView.js +2330 -0
- package/dist/bundled/api.js +32 -0
- package/dist/bundled/config.js +4 -0
- package/dist/bundled/const.js +5 -0
- package/dist/bundled/dark.js +4 -0
- package/dist/bundled/events.js +29 -0
- package/dist/bundled/global-components.js +203 -0
- package/dist/bundled/index.js +7 -0
- package/dist/bundled/index2.js +762 -0
- package/dist/bundled/reactivity.js +96 -0
- package/dist/bundled/sandbox.js +97 -0
- package/dist/bundled/search-docs-data.js +7 -0
- package/dist/bundled/story.js +59 -0
- package/dist/bundled/style.css +102 -0
- package/dist/client/app/App.vue +2 -2
- package/dist/client/app/api.d.ts +1 -0
- package/dist/client/app/api.js +1 -0
- package/dist/client/app/codegen/vue3.js +1 -3
- package/dist/client/app/components/HomeView.vue +1 -1
- package/dist/client/app/components/app/AppLogo.vue +1 -1
- package/dist/client/app/components/app/MobileOverlay.vue +0 -1
- package/dist/client/app/components/base/BaseEmpty.vue +1 -1
- package/dist/client/app/components/base/BaseOverflowMenu.vue +1 -1
- package/dist/client/app/components/exposed/Story.vue +1 -1
- package/dist/client/app/components/panel/StoryEvent.vue +1 -0
- package/dist/client/app/components/search/SearchItem.vue +1 -1
- package/dist/client/app/components/search/SearchPane.vue +108 -25
- package/dist/client/app/components/search/search-docs-data.d.ts +3 -0
- package/dist/client/app/components/search/{search-data.js → search-docs-data.js} +1 -2
- package/dist/client/app/components/search/search-title-data.d.ts +3 -0
- package/dist/client/app/components/search/search-title-data.js +7 -0
- package/dist/client/app/components/search/types.d.ts +7 -0
- package/dist/client/app/components/search/types.js +1 -0
- package/dist/client/app/components/story/StoryVariantGridItem.vue +1 -1
- package/dist/client/app/components/story/StoryVariantListItem.vue +1 -1
- package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +6 -3
- package/dist/client/app/components/tree/StoryListItem.vue +1 -1
- package/dist/client/app/global-components.js +0 -1
- package/dist/client/app/index.d.ts +1 -1
- package/dist/client/app/index.js +21 -19
- package/dist/client/app/sandbox.d.ts +1 -1
- package/dist/client/app/sandbox.js +0 -2
- package/dist/client/app/stores/events.d.ts +1 -1
- package/dist/client/app/stores/events.js +1 -2
- package/dist/client/app/stores/folder.js +0 -1
- package/dist/client/app/stores/story.js +0 -1
- package/dist/client/app/types.js +0 -1
- package/dist/client/app/util/events.d.ts +1 -1
- package/dist/client/app/util/events.js +2 -3
- package/dist/client/app/util/keyboard.js +0 -1
- package/dist/client/app/util/mapping.js +0 -1
- package/dist/client/app/util/preview-settings.js +0 -1
- package/dist/client/app/util/reactivity.js +0 -1
- package/dist/client/app/util/scroll.js +0 -1
- package/dist/client/app/util/variant.js +0 -1
- package/dist/client/bundle-index.js +5 -0
- package/dist/client/bundle-main.js +5 -0
- package/dist/client/bundle-sandbox.js +3 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -2
- package/dist/client/server/vue3/run.js +8 -1
- package/dist/controls.js +0 -1
- package/dist/node/alias.js +1 -1
- package/dist/node/build.js +4 -4
- package/dist/node/builtin-plugins/tailwind-tokens.js +1 -1
- package/dist/node/search.d.ts +15 -1
- package/dist/node/search.js +78 -32
- package/dist/node/server.js +2 -2
- package/dist/node/types.d.ts +1 -0
- package/dist/node/vite.d.ts +4 -2
- package/dist/node/vite.js +24 -28
- package/package.json +11 -10
- package/src/client/app/App.vue +2 -2
- package/src/client/app/api.ts +1 -0
- package/src/client/app/codegen/vue3.ts +1 -2
- package/src/client/app/components/HomeView.vue +1 -1
- package/src/client/app/components/app/AppLogo.vue +1 -1
- package/src/client/app/components/app/MobileOverlay.vue +0 -1
- package/src/client/app/components/base/BaseEmpty.vue +1 -1
- package/src/client/app/components/base/BaseOverflowMenu.vue +1 -1
- package/src/client/app/components/exposed/Story.vue +1 -1
- package/src/client/app/components/panel/StoryEvent.vue +1 -0
- package/src/client/app/components/search/SearchItem.vue +1 -1
- package/src/client/app/components/search/SearchPane.vue +108 -25
- package/src/client/app/components/search/search-docs-data.ts +10 -0
- package/src/client/app/components/search/search-title-data.ts +10 -0
- package/src/client/app/components/search/types.ts +4 -0
- package/src/client/app/components/story/StoryVariantGridItem.vue +1 -1
- package/src/client/app/components/story/StoryVariantListItem.vue +1 -1
- package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +6 -3
- package/src/client/app/components/tree/StoryListItem.vue +1 -1
- package/src/client/app/index.ts +23 -19
- package/src/client/app/sandbox.ts +0 -1
- package/src/client/app/stores/events.ts +1 -1
- package/src/client/app/util/events.ts +2 -2
- package/src/client/bundle-index.js +5 -0
- package/src/client/bundle-main.js +5 -0
- package/src/client/bundle-sandbox.js +3 -0
- package/src/client/index.ts +1 -1
- package/src/client/server/vue3/run.ts +11 -0
- package/src/node/alias.ts +1 -1
- package/src/node/build.ts +4 -4
- package/src/node/builtin-plugins/tailwind-tokens.ts +1 -1
- package/src/node/search.ts +87 -32
- package/src/node/server.ts +2 -2
- package/src/node/types.ts +1 -0
- package/src/node/vite.ts +24 -29
- package/vite.config.ts +46 -0
- package/dist/client/app/codegen/vue3.js.map +0 -1
- package/dist/client/app/components/search/search-data.d.ts +0 -2
- package/dist/client/app/components/search/search-data.js.map +0 -1
- package/dist/client/app/global-components.js.map +0 -1
- package/dist/client/app/index.js.map +0 -1
- package/dist/client/app/sandbox.js.map +0 -1
- package/dist/client/app/stores/events.js.map +0 -1
- package/dist/client/app/stores/folder.js.map +0 -1
- package/dist/client/app/stores/story.js.map +0 -1
- package/dist/client/app/types.js.map +0 -1
- package/dist/client/app/util/events.js.map +0 -1
- package/dist/client/app/util/keyboard.js.map +0 -1
- package/dist/client/app/util/mapping.js.map +0 -1
- package/dist/client/app/util/preview-settings.js.map +0 -1
- package/dist/client/app/util/reactivity.js.map +0 -1
- package/dist/client/app/util/scroll.js.map +0 -1
- package/dist/client/app/util/variant.js.map +0 -1
- package/dist/client/index.js.map +0 -1
- package/dist/client/server/vue3/run.js.map +0 -1
- package/dist/controls.js.map +0 -1
- package/src/client/app/components/search/search-data.ts +0 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { useFocus, useDebounce } from '@vueuse/core'
|
|
3
|
-
import { ref, watch } from 'vue'
|
|
3
|
+
import { computed, ref, watch } from 'vue'
|
|
4
4
|
import { Icon } from '@iconify/vue'
|
|
5
5
|
import flexsearch from 'flexsearch'
|
|
6
6
|
import charset from 'flexsearch/dist/module/lang/latin/advanced.js'
|
|
@@ -9,7 +9,10 @@ import { useStoryStore } from '../../stores/story'
|
|
|
9
9
|
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
10
10
|
import type { SearchResult, Story, Variant } from '../../types'
|
|
11
11
|
import SearchItem from './SearchItem.vue'
|
|
12
|
-
import { searchData, onUpdate } from './search-data
|
|
12
|
+
import { searchData, onUpdate } from './search-title-data'
|
|
13
|
+
import type { SearchData } from './types'
|
|
14
|
+
|
|
15
|
+
const DocSearchData = () => import('./search-docs-data')
|
|
13
16
|
|
|
14
17
|
const props = defineProps({
|
|
15
18
|
shown: {
|
|
@@ -42,34 +45,40 @@ watch(() => props.shown, value => {
|
|
|
42
45
|
}
|
|
43
46
|
})
|
|
44
47
|
|
|
45
|
-
//
|
|
48
|
+
// Index
|
|
46
49
|
|
|
47
50
|
const searchInputText = ref('')
|
|
48
51
|
const rateLimitedSearch = useDebounce(searchInputText, 50)
|
|
49
52
|
|
|
50
53
|
const storyStore = useStoryStore()
|
|
51
54
|
|
|
52
|
-
let
|
|
55
|
+
let titleSearchIndex: flexsearch.Document<any, any>
|
|
56
|
+
let titleIdMap: SearchData['idMap']
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
function createIndex () {
|
|
59
|
+
return new flexsearch.Document({
|
|
56
60
|
preset: 'match',
|
|
57
61
|
document: {
|
|
58
62
|
id: 'id',
|
|
59
63
|
index: [
|
|
60
|
-
'
|
|
61
|
-
'docs',
|
|
64
|
+
'text',
|
|
62
65
|
],
|
|
63
66
|
},
|
|
64
67
|
worker: true,
|
|
65
68
|
charset,
|
|
66
69
|
language,
|
|
67
|
-
tokenize: '
|
|
70
|
+
tokenize: 'forward',
|
|
68
71
|
})
|
|
72
|
+
}
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
async function loadSearchIndex (data: SearchData) {
|
|
75
|
+
titleSearchIndex = createIndex()
|
|
76
|
+
|
|
77
|
+
for (const key of Object.keys(data.index)) {
|
|
78
|
+
await titleSearchIndex.import(key, data.index[key])
|
|
72
79
|
}
|
|
80
|
+
|
|
81
|
+
titleIdMap = data.idMap
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
loadSearchIndex(searchData)
|
|
@@ -78,26 +87,57 @@ onUpdate(searchData => {
|
|
|
78
87
|
loadSearchIndex(searchData)
|
|
79
88
|
})
|
|
80
89
|
|
|
81
|
-
|
|
90
|
+
let docSearchIndex: flexsearch.Document<any, any>
|
|
91
|
+
let docIdMap: SearchData['idMap']
|
|
92
|
+
|
|
93
|
+
async function loadDocSearchIndex () {
|
|
94
|
+
async function load (data: SearchData) {
|
|
95
|
+
docSearchIndex = createIndex()
|
|
96
|
+
|
|
97
|
+
for (const key of Object.keys(data.index)) {
|
|
98
|
+
await docSearchIndex.import(key, data.index[key])
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
docIdMap = data.idMap
|
|
102
|
+
|
|
103
|
+
if (rateLimitedSearch.value) {
|
|
104
|
+
searchOnDocField(rateLimitedSearch.value)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const searchDataModule = await DocSearchData()
|
|
109
|
+
|
|
110
|
+
load(searchDataModule.searchData)
|
|
111
|
+
// Handle HMR
|
|
112
|
+
searchDataModule.onUpdate(searchData => {
|
|
113
|
+
load(searchData)
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
loadDocSearchIndex()
|
|
118
|
+
|
|
119
|
+
// Search
|
|
120
|
+
|
|
121
|
+
const titleResults = ref<SearchResult[]>([])
|
|
82
122
|
|
|
83
123
|
watch(rateLimitedSearch, async value => {
|
|
84
124
|
const list: SearchResult[] = []
|
|
85
|
-
const raw = await
|
|
86
|
-
enrich: true,
|
|
87
|
-
})
|
|
125
|
+
const raw = await titleSearchIndex.search(value)
|
|
88
126
|
let rank = 0
|
|
89
127
|
for (const field of raw) {
|
|
90
|
-
for (const
|
|
91
|
-
|
|
128
|
+
for (const id of field.result) {
|
|
129
|
+
const idMapData = titleIdMap[id]
|
|
130
|
+
if (!idMapData) continue
|
|
131
|
+
switch (idMapData.kind) {
|
|
92
132
|
case 'story': {
|
|
93
|
-
list.push(storyResultFactory(storyStore.getStoryById(
|
|
133
|
+
list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank))
|
|
94
134
|
rank++
|
|
95
135
|
break
|
|
96
136
|
}
|
|
97
137
|
case 'variant': {
|
|
98
|
-
const [storyId] =
|
|
138
|
+
const [storyId] = idMapData.id.split(':')
|
|
99
139
|
const story = storyStore.getStoryById(storyId)
|
|
100
|
-
const variant = storyStore.getVariantById(
|
|
140
|
+
const variant = storyStore.getVariantById(idMapData.id)
|
|
101
141
|
list.push(variantResultFactory(story, variant, rank))
|
|
102
142
|
rank++
|
|
103
143
|
break
|
|
@@ -105,14 +145,40 @@ watch(rateLimitedSearch, async value => {
|
|
|
105
145
|
}
|
|
106
146
|
}
|
|
107
147
|
}
|
|
108
|
-
|
|
148
|
+
titleResults.value = list
|
|
109
149
|
})
|
|
110
150
|
|
|
151
|
+
const docsResults = ref<SearchResult[]>([])
|
|
152
|
+
|
|
153
|
+
async function searchOnDocField (query: string) {
|
|
154
|
+
if (docSearchIndex) {
|
|
155
|
+
const list: SearchResult[] = []
|
|
156
|
+
const raw = await docSearchIndex.search(query)
|
|
157
|
+
let rank = 0
|
|
158
|
+
for (const field of raw) {
|
|
159
|
+
for (const id of field.result) {
|
|
160
|
+
const idMapData = docIdMap[id]
|
|
161
|
+
if (!idMapData) continue
|
|
162
|
+
switch (idMapData.kind) {
|
|
163
|
+
case 'story': {
|
|
164
|
+
list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank))
|
|
165
|
+
rank++
|
|
166
|
+
break
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
docsResults.value = list
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
watch(rateLimitedSearch, searchOnDocField)
|
|
176
|
+
|
|
111
177
|
function storyResultFactory (story: Story, rank: number): SearchResult {
|
|
112
178
|
return {
|
|
113
179
|
kind: 'story',
|
|
114
180
|
rank,
|
|
115
|
-
id: story.id
|
|
181
|
+
id: `story:${story.id}`,
|
|
116
182
|
title: story.title,
|
|
117
183
|
route: {
|
|
118
184
|
name: 'story',
|
|
@@ -130,7 +196,7 @@ function variantResultFactory (story: Story, variant: Variant, rank: number): Se
|
|
|
130
196
|
return {
|
|
131
197
|
kind: 'variant',
|
|
132
198
|
rank,
|
|
133
|
-
id: variant.id
|
|
199
|
+
id: `variant:${story.id}:${variant.id}`,
|
|
134
200
|
title: variant.title,
|
|
135
201
|
route: {
|
|
136
202
|
name: 'story',
|
|
@@ -147,6 +213,20 @@ function variantResultFactory (story: Story, variant: Variant, rank: number): Se
|
|
|
147
213
|
}
|
|
148
214
|
}
|
|
149
215
|
|
|
216
|
+
const results = computed(() => {
|
|
217
|
+
const list = [...titleResults.value]
|
|
218
|
+
const seen = {}
|
|
219
|
+
for (const r of titleResults.value) {
|
|
220
|
+
seen[r.id] = true
|
|
221
|
+
}
|
|
222
|
+
for (const r of docsResults.value) {
|
|
223
|
+
if (!seen[r.id]) {
|
|
224
|
+
list.push(r)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return list
|
|
228
|
+
})
|
|
229
|
+
|
|
150
230
|
// Selection
|
|
151
231
|
|
|
152
232
|
const selectedIndex = ref(0)
|
|
@@ -191,7 +271,10 @@ function selectPrevious () {
|
|
|
191
271
|
>
|
|
192
272
|
</div>
|
|
193
273
|
|
|
194
|
-
<BaseEmpty
|
|
274
|
+
<BaseEmpty
|
|
275
|
+
v-if="rateLimitedSearch && !results.length"
|
|
276
|
+
class="no-animation"
|
|
277
|
+
>
|
|
195
278
|
No results
|
|
196
279
|
</BaseEmpty>
|
|
197
280
|
|
|
@@ -201,7 +284,7 @@ function selectPrevious () {
|
|
|
201
284
|
>
|
|
202
285
|
<SearchItem
|
|
203
286
|
v-for="(result, index) of results"
|
|
204
|
-
:key="
|
|
287
|
+
:key="result.id"
|
|
205
288
|
:result="result"
|
|
206
289
|
:selected="index === selectedIndex"
|
|
207
290
|
@close="close()"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { markRaw } from 'vue'
|
|
2
|
+
// @ts-expect-error virtual module
|
|
3
|
+
import { searchData as _searchData, onUpdate as _onUpdate } from '$histoire-search-docs-data'
|
|
4
|
+
import type { SearchData } from './types.js'
|
|
5
|
+
|
|
6
|
+
export const searchData: SearchData = markRaw(_searchData)
|
|
7
|
+
|
|
8
|
+
export function onUpdate (cb: (data: SearchData) => unknown) {
|
|
9
|
+
_onUpdate(cb)
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { markRaw } from 'vue'
|
|
2
|
+
// @ts-expect-error virtual module
|
|
3
|
+
import { searchData as _searchData, onUpdate as _onUpdate } from '$histoire-search-title-data'
|
|
4
|
+
import type { SearchData } from './types.js'
|
|
5
|
+
|
|
6
|
+
export const searchData: SearchData = markRaw(_searchData)
|
|
7
|
+
|
|
8
|
+
export function onUpdate (cb: (data: SearchData) => unknown) {
|
|
9
|
+
_onUpdate(cb)
|
|
10
|
+
}
|
|
@@ -6,7 +6,7 @@ import { useResizeObserver } from '@vueuse/core'
|
|
|
6
6
|
import { useCurrentVariantRoute } from '../../util/variant'
|
|
7
7
|
import type { Story, Variant } from '../../types'
|
|
8
8
|
import SandboxVue3 from '../sandbox/SandboxVue3.vue'
|
|
9
|
-
import { useScrollOnActive } from '../../util/scroll
|
|
9
|
+
import { useScrollOnActive } from '../../util/scroll'
|
|
10
10
|
|
|
11
11
|
const props = defineProps({
|
|
12
12
|
variant: {
|
|
@@ -4,7 +4,7 @@ import { useCurrentVariantRoute } from '../../util/variant'
|
|
|
4
4
|
import type { Variant } from '../../types'
|
|
5
5
|
import BaseListItemLink from '../base/BaseListItemLink.vue'
|
|
6
6
|
import { Icon } from '@iconify/vue'
|
|
7
|
-
import { useScrollOnActive } from '../../util/scroll
|
|
7
|
+
import { useScrollOnActive } from '../../util/scroll'
|
|
8
8
|
|
|
9
9
|
const props = defineProps({
|
|
10
10
|
variant: {
|
|
@@ -11,6 +11,7 @@ const props = defineProps<{
|
|
|
11
11
|
Object.assign(props.variant, {
|
|
12
12
|
previewReady: false,
|
|
13
13
|
})
|
|
14
|
+
|
|
14
15
|
function onReady () {
|
|
15
16
|
Object.assign(props.variant, {
|
|
16
17
|
previewReady: true,
|
|
@@ -25,13 +26,15 @@ function onReady () {
|
|
|
25
26
|
>
|
|
26
27
|
<div
|
|
27
28
|
:style="isResponsiveEnabled ? {
|
|
28
|
-
width: finalWidth ? `${finalWidth}px` :
|
|
29
|
-
height: finalHeight ? `${finalHeight}px` :
|
|
30
|
-
} :
|
|
29
|
+
width: finalWidth ? `${finalWidth}px` : '100%',
|
|
30
|
+
height: finalHeight ? `${finalHeight}px` : '100%',
|
|
31
|
+
} : { width: '100%', height: '100%' }"
|
|
31
32
|
>
|
|
32
33
|
<SandboxVue3
|
|
34
|
+
:key="`${story.id}-${variant.id}`"
|
|
33
35
|
:variant="variant"
|
|
34
36
|
:story="story"
|
|
37
|
+
class="htw-h-full"
|
|
35
38
|
@ready="onReady"
|
|
36
39
|
/>
|
|
37
40
|
</div>
|
|
@@ -4,7 +4,7 @@ import BaseListItemLink from '../base/BaseListItemLink.vue'
|
|
|
4
4
|
import { Icon } from '@iconify/vue'
|
|
5
5
|
import { computed, ref, withDefaults } from 'vue'
|
|
6
6
|
import { useRoute } from 'vue-router'
|
|
7
|
-
import { useScrollOnActive } from '../../util/scroll
|
|
7
|
+
import { useScrollOnActive } from '../../util/scroll'
|
|
8
8
|
|
|
9
9
|
const props = withDefaults(defineProps<{
|
|
10
10
|
story: Story
|
package/src/client/app/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
/* eslint-disable import/first */
|
|
2
|
+
|
|
3
|
+
// export * from 'vue'
|
|
3
4
|
|
|
5
|
+
import '$histoire-theme'
|
|
4
6
|
import { createApp } from 'vue'
|
|
5
7
|
import { createPinia } from 'pinia'
|
|
6
8
|
import FloatingVue from 'floating-vue'
|
|
@@ -8,21 +10,23 @@ import App from './App.vue'
|
|
|
8
10
|
import { registerGlobalComponents } from './global-components.js'
|
|
9
11
|
import { router } from './router'
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
app
|
|
13
|
-
app.use(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
export function mountMainApp () {
|
|
14
|
+
const app = createApp(App)
|
|
15
|
+
app.use(createPinia())
|
|
16
|
+
app.use(FloatingVue, {
|
|
17
|
+
overflowPadding: 4,
|
|
18
|
+
arrowPadding: 8,
|
|
19
|
+
themes: {
|
|
20
|
+
tooltip: {
|
|
21
|
+
distance: 8,
|
|
22
|
+
},
|
|
23
|
+
dropdown: {
|
|
24
|
+
computeTransformOrigin: true,
|
|
25
|
+
distance: 8,
|
|
26
|
+
},
|
|
23
27
|
},
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
app
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
})
|
|
29
|
+
app.use(router)
|
|
30
|
+
registerGlobalComponents(app)
|
|
31
|
+
app.mount('#app')
|
|
32
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { useEventsStore } from '../stores/events.js'
|
|
2
1
|
import { EVENT_SEND } from './const'
|
|
3
2
|
|
|
4
|
-
export function hstEvent (name: string, argument) {
|
|
3
|
+
export async function hstEvent (name: string, argument) {
|
|
5
4
|
console.log('[histoire] Event fired', { name, argument })
|
|
6
5
|
const event = {
|
|
7
6
|
name,
|
|
@@ -13,6 +12,7 @@ export function hstEvent (name: string, argument) {
|
|
|
13
12
|
event,
|
|
14
13
|
})
|
|
15
14
|
} else {
|
|
15
|
+
const { useEventsStore } = await import('../stores/events.js')
|
|
16
16
|
useEventsStore().addEvent(event)
|
|
17
17
|
}
|
|
18
18
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import * as setup from '$histoire-setup'
|
|
|
8
8
|
|
|
9
9
|
export async function run ({ file, storyData, el }: ServerRunPayload) {
|
|
10
10
|
const { default: Comp } = await import(file.moduleId)
|
|
11
|
+
|
|
11
12
|
const app = createApp({
|
|
12
13
|
provide: {
|
|
13
14
|
addStory (data) {
|
|
@@ -34,5 +35,15 @@ export async function run ({ file, storyData, el }: ServerRunPayload) {
|
|
|
34
35
|
registerVueComponents(app)
|
|
35
36
|
|
|
36
37
|
app.mount(el)
|
|
38
|
+
|
|
39
|
+
if (Comp.doc) {
|
|
40
|
+
const el = document.createElement('div')
|
|
41
|
+
el.innerHTML = Comp.doc
|
|
42
|
+
const text = el.textContent
|
|
43
|
+
storyData.forEach(s => {
|
|
44
|
+
s.docsText = text
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
37
48
|
app.unmount()
|
|
38
49
|
}
|
package/src/node/alias.ts
CHANGED
|
@@ -4,6 +4,6 @@ import { fileURLToPath } from 'url'
|
|
|
4
4
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
5
5
|
|
|
6
6
|
export const DIST_PATH = join(__dirname, '../')
|
|
7
|
-
export const APP_PATH = join(DIST_PATH, 'client'
|
|
7
|
+
export const APP_PATH = join(DIST_PATH, 'client')
|
|
8
8
|
|
|
9
9
|
export const TEMP_PATH = join(process.cwd(), 'node_modules', '.histoire')
|
package/src/node/build.ts
CHANGED
|
@@ -67,8 +67,8 @@ export async function build (ctx: Context) {
|
|
|
67
67
|
build: {
|
|
68
68
|
rollupOptions: {
|
|
69
69
|
input: [
|
|
70
|
-
join(APP_PATH, '
|
|
71
|
-
join(APP_PATH, 'sandbox.js'),
|
|
70
|
+
join(APP_PATH, 'bundle-main.js'),
|
|
71
|
+
join(APP_PATH, 'bundle-sandbox.js'),
|
|
72
72
|
],
|
|
73
73
|
output: {
|
|
74
74
|
manualChunks (id) {
|
|
@@ -101,14 +101,14 @@ export async function build (ctx: Context) {
|
|
|
101
101
|
const prefetchHtml = generateScriptLinks(prefetchOutputs.map(o => o.fileName), 'prefetch', ctx, resolvedViteConfig)
|
|
102
102
|
|
|
103
103
|
// Index
|
|
104
|
-
const indexOutput = result.output.find(o => o.name === '
|
|
104
|
+
const indexOutput = result.output.find(o => o.name === 'bundle-main' && o.type === 'chunk')
|
|
105
105
|
const indexHtml = generateEntryHtml(indexOutput.fileName, styleOutput.fileName, {
|
|
106
106
|
HEAD: `${preloadHtml}${prefetchHtml}`,
|
|
107
107
|
}, ctx, resolvedViteConfig)
|
|
108
108
|
await writeFile('index.html', indexHtml, ctx)
|
|
109
109
|
|
|
110
110
|
// Sandbox
|
|
111
|
-
const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk')
|
|
111
|
+
const sandboxOutput = result.output.find(o => o.name === 'bundle-sandbox' && o.type === 'chunk')
|
|
112
112
|
const sandboxHtml = generateEntryHtml(sandboxOutput.fileName, styleOutput.fileName, {}, ctx, resolvedViteConfig)
|
|
113
113
|
await writeFile('__sandbox.html', sandboxHtml, ctx)
|
|
114
114
|
|
|
@@ -94,7 +94,7 @@ defineExpose({
|
|
|
94
94
|
})
|
|
95
95
|
</script>
|
|
96
96
|
<template>
|
|
97
|
-
<Story id="tailwind" title="Tailwind" group="design-system" icon="mdi:tailwind" responsiveDisabled>
|
|
97
|
+
<Story id="tailwind" title="Tailwind" group="design-system" icon="mdi:tailwind" responsiveDisabled :layout="{ type: 'single', iframe: false }">
|
|
98
98
|
<Variant id="background-color" title="Background Color" icon="carbon:color-palette">
|
|
99
99
|
<HstColorShades
|
|
100
100
|
v-for="(shades, key) of config.theme.backgroundColor"
|
package/src/node/search.ts
CHANGED
|
@@ -1,60 +1,93 @@
|
|
|
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
|
-
export async function
|
|
10
|
+
export async function generateTitleSearchData (ctx: Context) {
|
|
11
|
+
const searchIndex = await createIndex()
|
|
12
|
+
const { idMap, addToIdMap } = createIdMap()
|
|
13
|
+
|
|
14
|
+
for (const storyFile of ctx.storyFiles) {
|
|
15
|
+
if (storyFile.story) {
|
|
16
|
+
searchIndex.add({
|
|
17
|
+
id: addToIdMap(storyFile.story.id, 'story'),
|
|
18
|
+
text: convertTitleToSentence(storyFile.story.title),
|
|
19
|
+
})
|
|
20
|
+
for (const variant of storyFile.story.variants) {
|
|
21
|
+
searchIndex.add({
|
|
22
|
+
id: addToIdMap(`${storyFile.story.id}:${variant.id}`, 'variant'),
|
|
23
|
+
text: convertTitleToSentence(`${storyFile.story.title} ${variant.title}`),
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
index: await exportSearchIndex(searchIndex),
|
|
31
|
+
idMap,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function generateDocSearchData (ctx: Context) {
|
|
36
|
+
const searchIndex = await createIndex()
|
|
37
|
+
const { idMap, addToIdMap } = createIdMap()
|
|
38
|
+
|
|
39
|
+
for (const storyFile of ctx.storyFiles) {
|
|
40
|
+
if (storyFile.story && storyFile.story.docsText) {
|
|
41
|
+
searchIndex.add({
|
|
42
|
+
id: addToIdMap(storyFile.story.id, 'story'),
|
|
43
|
+
text: storyFile.story.docsText,
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
index: await exportSearchIndex(searchIndex),
|
|
50
|
+
idMap,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function createIndex () {
|
|
10
55
|
const flexsearchRoot = path.dirname(require.resolve('flexsearch/package.json'))
|
|
11
|
-
|
|
56
|
+
return new flexsearch.Document({
|
|
12
57
|
preset: 'match',
|
|
13
58
|
document: {
|
|
14
59
|
id: 'id',
|
|
15
60
|
index: [
|
|
16
|
-
'
|
|
17
|
-
'docs',
|
|
18
|
-
],
|
|
19
|
-
store: [
|
|
20
|
-
'kind',
|
|
61
|
+
'text',
|
|
21
62
|
],
|
|
22
63
|
},
|
|
23
64
|
charset: await loadModule(`${flexsearchRoot}/dist/module/lang/latin/advanced.js`),
|
|
24
65
|
language: await loadModule(`${flexsearchRoot}/dist/module/lang/en.js`),
|
|
25
|
-
tokenize: '
|
|
66
|
+
tokenize: 'forward',
|
|
26
67
|
})
|
|
68
|
+
}
|
|
27
69
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (const variant of storyFile.story.variants) {
|
|
37
|
-
searchIndex.add({
|
|
38
|
-
id: `${storyFile.story.id}:${variant.id}`,
|
|
39
|
-
kind: 'variant',
|
|
40
|
-
title: `${storyFile.story.title} ${variant.title}`,
|
|
41
|
-
docs: '', // @TODO
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
}
|
|
70
|
+
function createIdMap () {
|
|
71
|
+
let uid = 0
|
|
72
|
+
const idMap: Record<number, { id: string, kind: string }> = {}
|
|
73
|
+
|
|
74
|
+
function addToIdMap (id: string, kind: string) {
|
|
75
|
+
const n = uid++
|
|
76
|
+
idMap[n] = { id, kind }
|
|
77
|
+
return n
|
|
45
78
|
}
|
|
46
79
|
|
|
47
|
-
return
|
|
80
|
+
return {
|
|
81
|
+
idMap,
|
|
82
|
+
addToIdMap,
|
|
83
|
+
}
|
|
48
84
|
}
|
|
49
85
|
|
|
50
86
|
const exportKeys = new Set([
|
|
51
87
|
'reg',
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
'docs.cfg',
|
|
56
|
-
'docs.map',
|
|
57
|
-
'docs.ctx',
|
|
88
|
+
'text.cfg',
|
|
89
|
+
'text.map',
|
|
90
|
+
'text.ctx',
|
|
58
91
|
'tag',
|
|
59
92
|
'store',
|
|
60
93
|
])
|
|
@@ -73,3 +106,25 @@ async function exportSearchIndex (index) {
|
|
|
73
106
|
})
|
|
74
107
|
})
|
|
75
108
|
}
|
|
109
|
+
|
|
110
|
+
function convertTitleToSentence (text: string) {
|
|
111
|
+
return text.split(' ').map(str => Case.lower(str)).join(' ')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// @TODO clear handlers when SearchPane unmounts
|
|
115
|
+
export function getSearchDataJS (data: any) {
|
|
116
|
+
return `export let searchData = ${JSON.stringify(data)}
|
|
117
|
+
const handlers = []
|
|
118
|
+
export function onUpdate (cb) {
|
|
119
|
+
handlers.push(cb)
|
|
120
|
+
}
|
|
121
|
+
if (import.meta.hot) {
|
|
122
|
+
import.meta.hot.accept(newModule => {
|
|
123
|
+
searchData = newModule.searchData
|
|
124
|
+
handlers.forEach(h => {
|
|
125
|
+
h(newModule.searchData)
|
|
126
|
+
newModule.onUpdate(h)
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
}`
|
|
130
|
+
}
|
package/src/node/server.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createServer as createViteServer } from 'vite'
|
|
2
2
|
import { Context } from './context.js'
|
|
3
|
-
import { createVitePlugins,
|
|
3
|
+
import { createVitePlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js'
|
|
4
4
|
import { notifyStoryChange, onStoryChange, watchStories } from './stories.js'
|
|
5
5
|
import { useCollectStories } from './collect/index.js'
|
|
6
6
|
import type { StoryFile } from './types.js'
|
|
@@ -112,7 +112,7 @@ export async function createServer (ctx: Context, port: number) {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
invalidateModule(RESOLVED_STORIES_ID)
|
|
115
|
-
invalidateModule(
|
|
115
|
+
invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID)
|
|
116
116
|
})
|
|
117
117
|
|
|
118
118
|
async function close () {
|