histoire 0.3.3 → 0.4.2
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/bundled/vue.runtime.esm-bundler.js +8657 -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 -2
- 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/BaseOverflowMenu.vue +1 -1
- package/dist/client/app/components/exposed/Story.vue +1 -1
- package/dist/client/app/components/search/SearchItem.vue +1 -1
- package/dist/client/app/components/search/SearchPane.vue +96 -21
- 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 -1
- 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/{search-data.d.ts → types.d.ts} +0 -2
- 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/index.d.ts +1 -1
- package/dist/client/app/index.js +21 -18
- package/dist/client/app/sandbox.d.ts +1 -1
- package/dist/client/app/sandbox.js +0 -1
- package/dist/client/app/util/events.d.ts +1 -1
- package/dist/client/app/util/events.js +2 -2
- 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 -1
- package/dist/client/server/vue3/run.js +8 -0
- 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 +9 -1
- package/dist/node/search.js +69 -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 +22 -29
- package/package.json +7 -6
- 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/BaseOverflowMenu.vue +1 -1
- package/src/client/app/components/exposed/Story.vue +1 -1
- package/src/client/app/components/search/SearchItem.vue +1 -1
- package/src/client/app/components/search/SearchPane.vue +96 -21
- package/src/client/app/components/search/{search-data.ts → search-docs-data.ts} +2 -6
- 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/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 +77 -33
- package/src/node/server.ts +2 -2
- package/src/node/types.ts +1 -0
- package/src/node/vite.ts +22 -30
- package/vite.config.ts +46 -0
package/dist/node/search.js
CHANGED
|
@@ -4,57 +4,77 @@ import path from 'pathe';
|
|
|
4
4
|
import Case from 'case';
|
|
5
5
|
import { loadModule } from './load.js';
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
7
|
-
export async function
|
|
8
|
-
|
|
9
|
-
const idMap =
|
|
7
|
+
export async function generateTitleSearchData(ctx) {
|
|
8
|
+
const searchIndex = await createIndex();
|
|
9
|
+
const { idMap, addToIdMap } = createIdMap();
|
|
10
|
+
for (const storyFile of ctx.storyFiles) {
|
|
11
|
+
if (storyFile.story) {
|
|
12
|
+
searchIndex.add({
|
|
13
|
+
id: addToIdMap(storyFile.story.id, 'story'),
|
|
14
|
+
text: convertTitleToSentence(storyFile.story.title),
|
|
15
|
+
});
|
|
16
|
+
for (const variant of storyFile.story.variants) {
|
|
17
|
+
searchIndex.add({
|
|
18
|
+
id: addToIdMap(`${storyFile.story.id}:${variant.id}`, 'variant'),
|
|
19
|
+
text: convertTitleToSentence(`${storyFile.story.title} ${variant.title}`),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
index: await exportSearchIndex(searchIndex),
|
|
26
|
+
idMap,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export async function generateDocSearchData(ctx) {
|
|
30
|
+
const searchIndex = await createIndex();
|
|
31
|
+
const { idMap, addToIdMap } = createIdMap();
|
|
32
|
+
for (const storyFile of ctx.storyFiles) {
|
|
33
|
+
if (storyFile.story && storyFile.story.docsText) {
|
|
34
|
+
searchIndex.add({
|
|
35
|
+
id: addToIdMap(storyFile.story.id, 'story'),
|
|
36
|
+
text: storyFile.story.docsText,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
index: await exportSearchIndex(searchIndex),
|
|
42
|
+
idMap,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function createIndex() {
|
|
10
46
|
const flexsearchRoot = path.dirname(require.resolve('flexsearch/package.json'));
|
|
11
|
-
|
|
12
|
-
preset: '
|
|
47
|
+
return new flexsearch.Document({
|
|
48
|
+
preset: 'match',
|
|
13
49
|
document: {
|
|
14
50
|
id: 'id',
|
|
15
51
|
index: [
|
|
16
|
-
'
|
|
17
|
-
'docs',
|
|
52
|
+
'text',
|
|
18
53
|
],
|
|
19
54
|
},
|
|
20
55
|
charset: await loadModule(`${flexsearchRoot}/dist/module/lang/latin/advanced.js`),
|
|
21
56
|
language: await loadModule(`${flexsearchRoot}/dist/module/lang/en.js`),
|
|
22
57
|
tokenize: 'forward',
|
|
23
58
|
});
|
|
59
|
+
}
|
|
60
|
+
function createIdMap() {
|
|
61
|
+
let uid = 0;
|
|
62
|
+
const idMap = {};
|
|
24
63
|
function addToIdMap(id, kind) {
|
|
25
64
|
const n = uid++;
|
|
26
65
|
idMap[n] = { id, kind };
|
|
27
66
|
return n;
|
|
28
67
|
}
|
|
29
|
-
for (const storyFile of ctx.storyFiles) {
|
|
30
|
-
if (storyFile.story) {
|
|
31
|
-
searchIndex.add({
|
|
32
|
-
id: addToIdMap(storyFile.story.id, 'story'),
|
|
33
|
-
title: processTitle(storyFile.story.title),
|
|
34
|
-
docs: '', // @TODO
|
|
35
|
-
});
|
|
36
|
-
for (const variant of storyFile.story.variants) {
|
|
37
|
-
searchIndex.add({
|
|
38
|
-
id: addToIdMap(`${storyFile.story.id}:${variant.id}`, 'variant'),
|
|
39
|
-
title: processTitle(`${storyFile.story.title} ${variant.title}`),
|
|
40
|
-
docs: '', // @TODO
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
68
|
return {
|
|
46
|
-
index: await exportSearchIndex(searchIndex),
|
|
47
69
|
idMap,
|
|
70
|
+
addToIdMap,
|
|
48
71
|
};
|
|
49
72
|
}
|
|
50
73
|
const exportKeys = new Set([
|
|
51
74
|
'reg',
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
'docs.cfg',
|
|
56
|
-
'docs.map',
|
|
57
|
-
'docs.ctx',
|
|
75
|
+
'text.cfg',
|
|
76
|
+
'text.map',
|
|
77
|
+
'text.ctx',
|
|
58
78
|
'tag',
|
|
59
79
|
'store',
|
|
60
80
|
]);
|
|
@@ -72,6 +92,23 @@ async function exportSearchIndex(index) {
|
|
|
72
92
|
});
|
|
73
93
|
});
|
|
74
94
|
}
|
|
75
|
-
function
|
|
76
|
-
return
|
|
95
|
+
function convertTitleToSentence(text) {
|
|
96
|
+
return text.split(' ').map(str => Case.lower(str)).join(' ');
|
|
97
|
+
}
|
|
98
|
+
// @TODO clear handlers when SearchPane unmounts
|
|
99
|
+
export function getSearchDataJS(data) {
|
|
100
|
+
return `export let searchData = ${JSON.stringify(data)}
|
|
101
|
+
const handlers = []
|
|
102
|
+
export function onUpdate (cb) {
|
|
103
|
+
handlers.push(cb)
|
|
104
|
+
}
|
|
105
|
+
if (import.meta.hot) {
|
|
106
|
+
import.meta.hot.accept(newModule => {
|
|
107
|
+
searchData = newModule.searchData
|
|
108
|
+
handlers.forEach(h => {
|
|
109
|
+
h(newModule.searchData)
|
|
110
|
+
newModule.onUpdate(h)
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
}`;
|
|
77
114
|
}
|
package/dist/node/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createServer as createViteServer } from 'vite';
|
|
2
|
-
import { createVitePlugins,
|
|
2
|
+
import { createVitePlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js';
|
|
3
3
|
import { notifyStoryChange, onStoryChange, watchStories } from './stories.js';
|
|
4
4
|
import { useCollectStories } from './collect/index.js';
|
|
5
5
|
import { DevPluginApi } from './plugin.js';
|
|
@@ -94,7 +94,7 @@ export async function createServer(ctx, port) {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
invalidateModule(RESOLVED_STORIES_ID);
|
|
97
|
-
invalidateModule(
|
|
97
|
+
invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
98
98
|
});
|
|
99
99
|
async function close() {
|
|
100
100
|
for (const cb of pluginOnCleanups) {
|
package/dist/node/types.d.ts
CHANGED
package/dist/node/vite.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare const CONFIG_ID = "$histoire-config";
|
|
|
8
8
|
export declare const RESOLVED_CONFIG_ID: string;
|
|
9
9
|
export declare const THEME_ID = "$histoire-theme";
|
|
10
10
|
export declare const RESOLVED_THEME_ID: string;
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
11
|
+
export declare const SEARCH_TITLE_DATA_ID = "$histoire-search-title-data";
|
|
12
|
+
export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
|
|
13
|
+
export declare const SEARCH_DOCS_DATA_ID = "$histoire-search-docs-data";
|
|
14
|
+
export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
|
|
13
15
|
export declare function createVitePlugins(ctx: Context): Promise<VitePlugin[]>;
|
package/dist/node/vite.js
CHANGED
|
@@ -7,7 +7,7 @@ import { notifyStoryChange } from './stories.js';
|
|
|
7
7
|
import { makeTree } from './tree.js';
|
|
8
8
|
import { parseColor } from './colors.js';
|
|
9
9
|
import { createMarkdownRenderer } from './markdown.js';
|
|
10
|
-
import {
|
|
10
|
+
import { getSearchDataJS, generateDocSearchData, generateTitleSearchData } from './search.js';
|
|
11
11
|
const require = createRequire(import.meta.url);
|
|
12
12
|
export const STORIES_ID = '$histoire-stories';
|
|
13
13
|
export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`;
|
|
@@ -17,15 +17,13 @@ export const CONFIG_ID = '$histoire-config';
|
|
|
17
17
|
export const RESOLVED_CONFIG_ID = `/${CONFIG_ID}-resolved`;
|
|
18
18
|
export const THEME_ID = '$histoire-theme';
|
|
19
19
|
export const RESOLVED_THEME_ID = `/${THEME_ID}-resolved.css`;
|
|
20
|
-
export const
|
|
21
|
-
export const
|
|
20
|
+
export const SEARCH_TITLE_DATA_ID = '$histoire-search-title-data';
|
|
21
|
+
export const RESOLVED_SEARCH_TITLE_DATA_ID = `/${SEARCH_TITLE_DATA_ID}-resolved`;
|
|
22
|
+
export const SEARCH_DOCS_DATA_ID = '$histoire-search-docs-data';
|
|
23
|
+
export const RESOLVED_SEARCH_DOCS_DATA_ID = `/${SEARCH_DOCS_DATA_ID}-resolved`;
|
|
22
24
|
export async function createVitePlugins(ctx) {
|
|
23
25
|
const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
|
|
24
|
-
const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue');
|
|
25
26
|
const plugins = [];
|
|
26
|
-
if (!hasVuePlugin) {
|
|
27
|
-
plugins.push((await import('@vitejs/plugin-vue')).default());
|
|
28
|
-
}
|
|
29
27
|
if (ctx.config.vite) {
|
|
30
28
|
plugins.push({
|
|
31
29
|
name: 'histoire-vite-config-override',
|
|
@@ -42,14 +40,13 @@ export async function createVitePlugins(ctx) {
|
|
|
42
40
|
// force include vue to avoid duplicated copies when linked + optimized
|
|
43
41
|
include: [
|
|
44
42
|
'vue',
|
|
45
|
-
dirname(require.resolve('@vue/runtime-core/package.json')),
|
|
46
43
|
dirname(require.resolve('shiki/package.json')),
|
|
47
44
|
dirname(require.resolve('vscode-textmate/package.json')),
|
|
48
45
|
dirname(require.resolve('vscode-oniguruma/package.json')),
|
|
49
46
|
dirname(require.resolve('case/package.json')),
|
|
50
47
|
],
|
|
51
48
|
exclude: [
|
|
52
|
-
'histoire
|
|
49
|
+
'histoire',
|
|
53
50
|
],
|
|
54
51
|
},
|
|
55
52
|
server: {
|
|
@@ -83,8 +80,11 @@ export async function createVitePlugins(ctx) {
|
|
|
83
80
|
if (id.startsWith(THEME_ID)) {
|
|
84
81
|
return RESOLVED_THEME_ID;
|
|
85
82
|
}
|
|
86
|
-
if (id.startsWith(
|
|
87
|
-
return
|
|
83
|
+
if (id.startsWith(SEARCH_TITLE_DATA_ID)) {
|
|
84
|
+
return RESOLVED_SEARCH_TITLE_DATA_ID;
|
|
85
|
+
}
|
|
86
|
+
if (id.startsWith(SEARCH_DOCS_DATA_ID)) {
|
|
87
|
+
return RESOLVED_SEARCH_DOCS_DATA_ID;
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
90
|
async load(id) {
|
|
@@ -94,7 +94,10 @@ export async function createVitePlugins(ctx) {
|
|
|
94
94
|
return {
|
|
95
95
|
id: file.id,
|
|
96
96
|
path: file.treePath,
|
|
97
|
-
story:
|
|
97
|
+
story: {
|
|
98
|
+
...file.story,
|
|
99
|
+
docsText: undefined,
|
|
100
|
+
},
|
|
98
101
|
framework: 'vue3',
|
|
99
102
|
index,
|
|
100
103
|
};
|
|
@@ -142,21 +145,11 @@ if (import.meta.hot) {
|
|
|
142
145
|
css += '}';
|
|
143
146
|
return css;
|
|
144
147
|
}
|
|
145
|
-
if (id ===
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
if (import.meta.hot) {
|
|
152
|
-
import.meta.hot.accept(newModule => {
|
|
153
|
-
searchData = newModule.searchData
|
|
154
|
-
handlers.forEach(h => {
|
|
155
|
-
h(newModule.searchData)
|
|
156
|
-
newModule.onUpdate(h)
|
|
157
|
-
})
|
|
158
|
-
})
|
|
159
|
-
}`;
|
|
148
|
+
if (id === RESOLVED_SEARCH_TITLE_DATA_ID) {
|
|
149
|
+
return getSearchDataJS(await generateTitleSearchData(ctx));
|
|
150
|
+
}
|
|
151
|
+
if (id === RESOLVED_SEARCH_DOCS_DATA_ID) {
|
|
152
|
+
return getSearchDataJS(await generateDocSearchData(ctx));
|
|
160
153
|
}
|
|
161
154
|
},
|
|
162
155
|
handleHotUpdate(updateContext) {
|
|
@@ -189,7 +182,7 @@ if (import.meta.hot) {
|
|
|
189
182
|
}
|
|
190
183
|
}
|
|
191
184
|
</script>
|
|
192
|
-
<script type="module" src="/@fs/${APP_PATH}/sandbox.js"></script>
|
|
185
|
+
<script type="module" src="/@fs/${APP_PATH}/bundle-sandbox.js"></script>
|
|
193
186
|
</body>
|
|
194
187
|
</html>`;
|
|
195
188
|
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
@@ -218,7 +211,7 @@ if (import.meta.hot) {
|
|
|
218
211
|
</head>
|
|
219
212
|
<body>
|
|
220
213
|
<div id="app"></div>
|
|
221
|
-
<script type="module" src="/@fs/${APP_PATH}/
|
|
214
|
+
<script type="module" src="/@fs/${APP_PATH}/bundle-main.js"></script>
|
|
222
215
|
</body>
|
|
223
216
|
</html>`;
|
|
224
217
|
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"types": "./dist/node/index.d.ts"
|
|
22
22
|
},
|
|
23
23
|
"./client": {
|
|
24
|
-
"import": "./dist/client/index.js",
|
|
24
|
+
"import": "./dist/client/bundle-index.js",
|
|
25
25
|
"types": "./dist/client/index.d.ts"
|
|
26
26
|
},
|
|
27
27
|
"./*": "./*"
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"histoire": "./bin.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@histoire/controls": "^0.
|
|
36
|
+
"@histoire/controls": "^0.4.2",
|
|
37
37
|
"@iconify/vue": "^3.2.1",
|
|
38
|
-
"@
|
|
38
|
+
"@types/markdown-it": "^12.2.3",
|
|
39
39
|
"@vueuse/core": "^8.2.5",
|
|
40
40
|
"birpc": "^0.1.1",
|
|
41
41
|
"case": "^1.6.3",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"@types/fs-extra": "^9.0.13",
|
|
76
76
|
"@types/markdown-it": "^12.2.3",
|
|
77
77
|
"@types/node": "^17.0.23",
|
|
78
|
+
"@vitejs/plugin-vue": "^2.3.1",
|
|
78
79
|
"autoprefixer": "^10.4.4",
|
|
79
80
|
"concurrently": "^7.1.0",
|
|
80
81
|
"postcss": "^8.4.12",
|
|
@@ -85,9 +86,9 @@
|
|
|
85
86
|
"vue": "^3.2.31"
|
|
86
87
|
},
|
|
87
88
|
"scripts": {
|
|
88
|
-
"build": "rimraf dist && tsc -d && pnpm run build:css && node ./scripts/copy.mjs",
|
|
89
|
+
"build": "rimraf dist && tsc -d && vite build && pnpm run build:css && node ./scripts/copy.mjs",
|
|
89
90
|
"build:css": "tailwindcss -i src/client/app/style/main.pcss -o ./dist/style.css -c tailwind.config.cjs --postcss postcss.config.cjs",
|
|
90
|
-
"watch": "concurrently \"tsc -d -w --sourceMap\" \"pnpm run build:css --watch\" \"node ./scripts/watchAndCopy.mjs\"",
|
|
91
|
+
"watch": "concurrently \"tsc -d -w --sourceMap\" \"vite build --watch\" \"pnpm run build:css --watch\" \"node ./scripts/watchAndCopy.mjs\"",
|
|
91
92
|
"test:open": "peeky open",
|
|
92
93
|
"test": "peeky run"
|
|
93
94
|
}
|
package/src/client/app/App.vue
CHANGED
|
@@ -15,8 +15,8 @@ import type { StoryFile, Tree } from './types'
|
|
|
15
15
|
import { useStoryStore } from './stores/story'
|
|
16
16
|
import { mapFile } from './util/mapping'
|
|
17
17
|
import { useTitle } from '@vueuse/core'
|
|
18
|
-
import { histoireConfig } from './util/config
|
|
19
|
-
import { onKeyboardShortcut } from './util/keyboard
|
|
18
|
+
import { histoireConfig } from './util/config'
|
|
19
|
+
import { onKeyboardShortcut } from './util/keyboard'
|
|
20
20
|
import { isMobile } from './util/responsive'
|
|
21
21
|
import Breadcrumb from './components/app/Breadcrumb.vue'
|
|
22
22
|
import SearchModal from './components/search/SearchModal.vue'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { hstEvent } from './util/events.js'
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
// @TODO remove no-check and fix vnode type errors
|
|
3
3
|
|
|
4
|
-
import { VNode, vModelText, vModelCheckbox, vModelSelect, vModelRadio, vModelDynamic } from 'vue'
|
|
5
|
-
import { Text } from '@vue/runtime-core'
|
|
4
|
+
import { VNode, vModelText, vModelCheckbox, vModelSelect, vModelRadio, vModelDynamic, Text } from 'vue'
|
|
6
5
|
import { pascal } from 'case'
|
|
7
6
|
import { createAutoBuildingObject, indent } from './util'
|
|
8
7
|
import { serializeJs } from './serialize-js'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed } from 'vue'
|
|
3
|
-
import { histoireConfig, customLogos } from '../util/config
|
|
3
|
+
import { histoireConfig, customLogos } from '../util/config'
|
|
4
4
|
import HistoireLogo from '../assets/histoire.svg'
|
|
5
5
|
|
|
6
6
|
const logoUrl = computed(() => histoireConfig.theme?.logo?.square ? customLogos.square : HistoireLogo)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { isDark } from '../../util/dark'
|
|
3
3
|
import { computed } from 'vue'
|
|
4
|
-
import { histoireConfig, customLogos } from '../../util/config
|
|
4
|
+
import { histoireConfig, customLogos } from '../../util/config'
|
|
5
5
|
|
|
6
6
|
import HistoireLogoDark from '../../assets/histoire-text-dark.svg'
|
|
7
7
|
import HistoireLogoLight from '../../assets/histoire-text.svg'
|
|
@@ -70,7 +70,7 @@ const ChildWrapper = {
|
|
|
70
70
|
*/
|
|
71
71
|
const ChildrenRender = (props, { slots }) => {
|
|
72
72
|
const [fragment] = slots.default()
|
|
73
|
-
return fragment.children.map((vnode, index) => h(ChildWrapper, { index }, [vnode]))
|
|
73
|
+
return fragment.children.map((vnode, index) => h(ChildWrapper, { index }, () => [vnode]))
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { computed, defineComponent, provide, useAttrs, VNode, h, PropType, getCurrentInstance } from 'vue'
|
|
3
|
-
import { Story } from '../../types.js'
|
|
3
|
+
import type { Story } from '../../types.js'
|
|
4
4
|
import Variant from './Variant.vue'
|
|
5
5
|
|
|
6
6
|
export default defineComponent({
|
|
@@ -3,7 +3,7 @@ import { PropType, ref, toRefs } from 'vue'
|
|
|
3
3
|
import { useRouter } from 'vue-router'
|
|
4
4
|
import { Icon } from '@iconify/vue'
|
|
5
5
|
import { SearchResult } from '../../types'
|
|
6
|
-
import { onKeyboardShortcut } from '../../util/keyboard
|
|
6
|
+
import { onKeyboardShortcut } from '../../util/keyboard'
|
|
7
7
|
import BaseListItemLink from '../base/BaseListItemLink.vue'
|
|
8
8
|
import { useScrollOnActive } from '../../util/scroll'
|
|
9
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
|
|
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,37 +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
|
|
53
|
-
let
|
|
55
|
+
let titleSearchIndex: flexsearch.Document<any, any>
|
|
56
|
+
let titleIdMap: SearchData['idMap']
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
function createIndex () {
|
|
59
|
+
return new flexsearch.Document({
|
|
57
60
|
preset: 'match',
|
|
58
61
|
document: {
|
|
59
62
|
id: 'id',
|
|
60
63
|
index: [
|
|
61
|
-
'
|
|
62
|
-
'docs',
|
|
64
|
+
'text',
|
|
63
65
|
],
|
|
64
66
|
},
|
|
65
67
|
worker: true,
|
|
66
68
|
charset,
|
|
67
69
|
language,
|
|
68
|
-
tokenize: '
|
|
70
|
+
tokenize: 'forward',
|
|
69
71
|
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function loadSearchIndex (data: SearchData) {
|
|
75
|
+
titleSearchIndex = createIndex()
|
|
70
76
|
|
|
71
77
|
for (const key of Object.keys(data.index)) {
|
|
72
|
-
await
|
|
78
|
+
await titleSearchIndex.import(key, data.index[key])
|
|
73
79
|
}
|
|
74
80
|
|
|
75
|
-
|
|
81
|
+
titleIdMap = data.idMap
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
loadSearchIndex(searchData)
|
|
@@ -81,17 +87,46 @@ onUpdate(searchData => {
|
|
|
81
87
|
loadSearchIndex(searchData)
|
|
82
88
|
})
|
|
83
89
|
|
|
84
|
-
|
|
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[]>([])
|
|
85
122
|
|
|
86
123
|
watch(rateLimitedSearch, async value => {
|
|
87
124
|
const list: SearchResult[] = []
|
|
88
|
-
const raw = await
|
|
89
|
-
enrich: true,
|
|
90
|
-
})
|
|
125
|
+
const raw = await titleSearchIndex.search(value)
|
|
91
126
|
let rank = 0
|
|
92
127
|
for (const field of raw) {
|
|
93
128
|
for (const id of field.result) {
|
|
94
|
-
const idMapData =
|
|
129
|
+
const idMapData = titleIdMap[id]
|
|
95
130
|
if (!idMapData) continue
|
|
96
131
|
switch (idMapData.kind) {
|
|
97
132
|
case 'story': {
|
|
@@ -110,14 +145,40 @@ watch(rateLimitedSearch, async value => {
|
|
|
110
145
|
}
|
|
111
146
|
}
|
|
112
147
|
}
|
|
113
|
-
|
|
148
|
+
titleResults.value = list
|
|
114
149
|
})
|
|
115
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
|
+
|
|
116
177
|
function storyResultFactory (story: Story, rank: number): SearchResult {
|
|
117
178
|
return {
|
|
118
179
|
kind: 'story',
|
|
119
180
|
rank,
|
|
120
|
-
id: story.id
|
|
181
|
+
id: `story:${story.id}`,
|
|
121
182
|
title: story.title,
|
|
122
183
|
route: {
|
|
123
184
|
name: 'story',
|
|
@@ -135,7 +196,7 @@ function variantResultFactory (story: Story, variant: Variant, rank: number): Se
|
|
|
135
196
|
return {
|
|
136
197
|
kind: 'variant',
|
|
137
198
|
rank,
|
|
138
|
-
id:
|
|
199
|
+
id: `variant:${story.id}:${variant.id}`,
|
|
139
200
|
title: variant.title,
|
|
140
201
|
route: {
|
|
141
202
|
name: 'story',
|
|
@@ -152,6 +213,20 @@ function variantResultFactory (story: Story, variant: Variant, rank: number): Se
|
|
|
152
213
|
}
|
|
153
214
|
}
|
|
154
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
|
+
|
|
155
230
|
// Selection
|
|
156
231
|
|
|
157
232
|
const selectedIndex = ref(0)
|
|
@@ -209,7 +284,7 @@ function selectPrevious () {
|
|
|
209
284
|
>
|
|
210
285
|
<SearchItem
|
|
211
286
|
v-for="(result, index) of results"
|
|
212
|
-
:key="
|
|
287
|
+
:key="result.id"
|
|
213
288
|
:result="result"
|
|
214
289
|
:selected="index === selectedIndex"
|
|
215
290
|
@close="close()"
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { markRaw } from 'vue'
|
|
2
2
|
// @ts-expect-error virtual module
|
|
3
|
-
import { searchData as _searchData, onUpdate as _onUpdate } from '$histoire-search-data'
|
|
4
|
-
|
|
5
|
-
export interface SearchData {
|
|
6
|
-
index: Record<string, any>
|
|
7
|
-
idMap: Record<number, { id: string, kind: string }>
|
|
8
|
-
}
|
|
3
|
+
import { searchData as _searchData, onUpdate as _onUpdate } from '$histoire-search-docs-data'
|
|
4
|
+
import type { SearchData } from './types.js'
|
|
9
5
|
|
|
10
6
|
export const searchData: SearchData = markRaw(_searchData)
|
|
11
7
|
|
|
@@ -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: {
|