@rspress/core 2.0.21 → 2.0.23
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/bin/rspress.js +3 -1
- package/dist/{2711~0.js → a~0.js} +90 -70
- package/dist/{8472~0.js → b~0.js} +19 -14
- package/dist/cli/index.js +12 -13
- package/dist/config/loadConfigFile.d.ts +3 -4
- package/dist/config/loadConfigFile.js +13 -17
- package/dist/{7748~0.js → d~0.js} +0 -2
- package/dist/eject-theme/components/Llms/LlmsHint.test.tsx +8 -0
- package/dist/eject-theme/components/Llms/LlmsHint.tsx +11 -3
- package/dist/eject-theme/components/Nav/NavMenu.scss +4 -0
- package/dist/eject-theme/components/Nav/NavMenu.tsx +20 -13
- package/dist/eject-theme/components/Nav/index.tsx +30 -4
- package/dist/eject-theme/components/NavHamburger/index.tsx +11 -3
- package/dist/eject-theme/components/NavList/context.ts +3 -0
- package/dist/eject-theme/components/NavList/index.tsx +24 -0
- package/dist/eject-theme/components/NavScreen/NavScreenMenu.test.tsx +59 -0
- package/dist/eject-theme/components/NavScreen/NavScreenMenu.tsx +43 -2
- package/dist/eject-theme/components/NavScreen/index.scss +0 -6
- package/dist/eject-theme/components/NavScreen/index.tsx +20 -3
- package/dist/eject-theme/components/ReadPercent/useReadPercent.ts +1 -1
- package/dist/eject-theme/components/Search/SearchButton.scss +1 -0
- package/dist/eject-theme/components/Search/SearchPanel.scss +51 -12
- package/dist/eject-theme/components/Search/SearchPanel.tsx +62 -216
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +39 -17
- package/dist/eject-theme/components/Search/useSearchPanel.ts +217 -0
- package/dist/eject-theme/components/SocialLinks/SocialLink.tsx +2 -2
- package/dist/eject-theme/components/SourceCode/index.tsx +1 -1
- package/dist/eject-theme/components/Steps/index.scss +1 -1
- package/dist/eject-theme/components/SwitchAppearance/getClipPath.test.ts +15 -0
- package/dist/eject-theme/components/SwitchAppearance/getClipPath.ts +26 -0
- package/dist/eject-theme/components/SwitchAppearance/index.tsx +22 -26
- package/dist/eject-theme/components/Tabs/index.tsx +14 -14
- package/dist/index.js +1 -1
- package/dist/node/PluginDriver.d.ts +1 -1
- package/dist/node/PluginDriver.js +5 -9
- package/dist/node/auto-nav-sidebar/index.js +1 -1
- package/dist/node/auto-nav-sidebar/locales.js +1 -1
- package/dist/node/auto-nav-sidebar/normalize.js +6 -6
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/build.d.ts +3 -2
- package/dist/node/build.js +9 -3
- package/dist/node/constants.js +1 -1
- package/dist/node/dev.d.ts +4 -4
- package/dist/node/dev.js +8 -6
- package/dist/node/eject.js +5 -5
- package/dist/node/initRsbuild.d.ts +2 -3
- package/dist/node/initRsbuild.js +9 -7
- package/dist/node/last-updated/index.js +2 -2
- package/dist/node/logger/hint.js +4 -4
- package/dist/node/mdx/options.js +1 -1
- package/dist/node/mdx/processor.js +3 -3
- package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
- package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
- package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
- package/dist/node/mdx/remarkPlugins/containerSyntax.js +6 -5
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +5 -5
- package/dist/node/mdx/remarkPlugins/image.js +5 -5
- package/dist/node/mdx/remarkPlugins/link.js +5 -5
- package/dist/node/mdx/remarkPlugins/toc.js +1 -1
- package/dist/node/medium-zoom/index.js +1 -1
- package/dist/node/route/RoutePage.js +6 -4
- package/dist/node/route/RouteService.js +3 -3
- package/dist/node/route/extractPageData.js +20 -7
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/i18n.js +5 -5
- package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +1 -1
- package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
- package/dist/node/serve.d.ts +3 -3
- package/dist/node/serve.js +10 -4
- package/dist/node/ssg/alternateLinks.js +1 -1
- package/dist/node/ssg/htmlFile.js +1 -1
- package/dist/node/ssg/renderHtmlTemplate.js +4 -3
- package/dist/node/ssg/renderPage.js +5 -5
- package/dist/node/ssg/renderPageWorker.js +2 -2
- package/dist/node/ssg/renderPages.js +6 -6
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
- package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
- package/dist/node/ssg-md/renderPage.js +5 -5
- package/dist/node/ssg-md/renderPages.js +6 -6
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
- package/dist/node/utils/checkLanguageParity.js +5 -7
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/error.js +4 -4
- package/dist/node/utils/flattenMdxContent.js +2 -2
- package/dist/node/utils/fs.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/index.d.ts +1 -1
- package/dist/node/utils/reactAlias.js +5 -5
- package/dist/node/utils/slash.d.ts +1 -0
- package/dist/node/utils/slash.js +4 -0
- package/dist/{864~0.js → n~0.js} +42 -41
- package/dist/rslib-runtime~0.js +27 -35
- package/dist/runtime/App.js +3 -2
- package/dist/runtime/hooks/createExternalStore.d.ts +4 -0
- package/dist/runtime/hooks/createExternalStore.js +20 -0
- package/dist/runtime/hooks/useGlobalComponents.d.ts +1 -0
- package/dist/runtime/hooks/useGlobalComponents.js +10 -0
- package/dist/runtime/hooks/useI18n.js +5 -3
- package/dist/runtime/hooks/useI18nText.d.ts +1 -0
- package/dist/runtime/hooks/useI18nText.js +10 -0
- package/dist/runtime/hooks/usePages.d.ts +2 -0
- package/dist/runtime/hooks/usePages.js +12 -3
- package/dist/runtime/hooks/useSearchHooks.d.ts +8 -0
- package/dist/runtime/hooks/useSearchHooks.js +14 -0
- package/dist/runtime/hooks/useSite.d.ts +1 -0
- package/dist/runtime/hooks/useSite.js +9 -2
- package/dist/runtime/index.d.ts +3 -1
- package/dist/runtime/index.js +5 -1
- package/dist/runtime/initPageData.js +10 -10
- package/dist/runtime/route.js +5 -5
- package/dist/runtime/utils.js +6 -6
- package/dist/theme/components/Link/useLinkNavigate.js +1 -1
- package/dist/theme/components/Llms/LlmsHint.js +23 -6
- package/dist/theme/components/Nav/NavMenu.css +4 -0
- package/dist/theme/components/Nav/NavMenu.d.ts +4 -2
- package/dist/theme/components/Nav/NavMenu.js +17 -9
- package/dist/theme/components/Nav/index.d.ts +7 -1
- package/dist/theme/components/Nav/index.js +13 -4
- package/dist/theme/components/NavHamburger/index.d.ts +2 -1
- package/dist/theme/components/NavHamburger/index.js +8 -2
- package/dist/theme/components/NavList/context.d.ts +1 -0
- package/dist/theme/components/NavList/context.js +3 -0
- package/dist/theme/components/NavList/index.d.ts +6 -0
- package/dist/theme/components/NavList/index.js +17 -0
- package/dist/theme/components/NavScreen/NavScreenMenu.d.ts +3 -2
- package/dist/theme/components/NavScreen/NavScreenMenu.js +42 -6
- package/dist/theme/components/NavScreen/index.css +0 -10
- package/dist/theme/components/NavScreen/index.d.ts +2 -1
- package/dist/theme/components/NavScreen/index.js +11 -3
- package/dist/theme/components/PackageManagerTabs/index.js +2 -2
- package/dist/theme/components/ReadPercent/useReadPercent.js +1 -0
- package/dist/theme/components/Search/SearchButton.css +1 -0
- package/dist/theme/components/Search/SearchPanel.css +47 -9
- package/dist/theme/components/Search/SearchPanel.js +104 -210
- package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +1 -0
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +24 -14
- package/dist/theme/components/Search/logic/search.js +1 -1
- package/dist/theme/components/Search/useSearchPanel.d.ts +23 -0
- package/dist/theme/components/Search/useSearchPanel.js +155 -0
- package/dist/theme/components/SocialLinks/SocialLink.js +2 -2
- package/dist/theme/components/SourceCode/index.js +1 -1
- package/dist/theme/components/Steps/index.css +3 -3
- package/dist/theme/components/SwitchAppearance/getClipPath.d.ts +8 -0
- package/dist/theme/components/SwitchAppearance/getClipPath.js +13 -0
- package/dist/theme/components/SwitchAppearance/index.js +9 -7
- package/dist/theme/components/Tabs/index.js +4 -4
- package/dist/theme/components/Tag/index.js +2 -2
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/index.js +1 -0
- package/dist/theme/layout/DocLayout/index.js +2 -2
- package/dist/theme/layout/Layout/index.js +12 -4
- package/dist/theme/logic/useFullTextSearch.js +6 -1
- package/dist/theme/logic/utils.d.ts +0 -2
- package/dist/theme/logic/utils.js +56 -6
- package/dist/theme/styles/vars/shiki-vars.css +1 -1
- package/dist/tinypool~0.js +5 -3
- package/dist/{4538~0.js → t~0.js} +2 -2
- package/package.json +15 -16
- package/dist/eject-theme/components/NavScreen/NavScreenMenuOthers.tsx +0 -29
- package/dist/node/utils/normalizePath.d.ts +0 -3
- package/dist/node/utils/normalizePath.js +0 -10
- package/dist/theme/components/NavScreen/NavScreenMenuOthers.d.ts +0 -2
- package/dist/theme/components/NavScreen/NavScreenMenuOthers.js +0 -30
- package/dist/theme/logic/useHandler.d.ts +0 -6
- package/dist/theme/logic/useHandler.js +0 -7
- /package/dist/{9857~0.js → 4~0.js} +0 -0
- /package/dist/{8016~0.js → i~0.js} +0 -0
- /package/dist/{5357~0.js → r~0.js} +0 -0
- /package/dist/{102~0.js → t2~0.js} +0 -0
- /package/dist/{9940~0.js → tx~0.js} +0 -0
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useI18n,
|
|
3
|
-
import { IconClose,
|
|
4
|
-
import {
|
|
5
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Head, useI18n, useSearchHooks } from "@rspress/core/runtime";
|
|
3
|
+
import { IconClose, IconSearch, SvgWrapper, Tab, Tabs, useLinkNavigate } from "@rspress/core/theme";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
5
|
import { createPortal } from "react-dom";
|
|
7
|
-
import * as __rspack_external_virtual_search_hooks_705b6e40 from "virtual-search-hooks";
|
|
8
|
-
import { PageSearcher } from "./logic/search.js";
|
|
9
6
|
import { RenderType } from "./logic/types.js";
|
|
10
7
|
import { NoSearchResult } from "./NoSearchResult.js";
|
|
11
8
|
import "./SearchPanel.css";
|
|
12
9
|
import { SuggestItem } from "./SuggestItem.js";
|
|
10
|
+
import { useSearchPanel } from "./useSearchPanel.js";
|
|
13
11
|
const KEY_CODE = {
|
|
14
12
|
ARROW_UP: 'ArrowUp',
|
|
15
13
|
ARROW_DOWN: 'ArrowDown',
|
|
@@ -17,12 +15,6 @@ const KEY_CODE = {
|
|
|
17
15
|
SEARCH: 'KeyK',
|
|
18
16
|
ESC: 'Escape'
|
|
19
17
|
};
|
|
20
|
-
const useDebounce = (cb)=>{
|
|
21
|
-
const cbRef = useRef(cb);
|
|
22
|
-
cbRef.current = cb;
|
|
23
|
-
const debounced = useCallback(debounce((...args)=>cbRef.current(...args), 150), []);
|
|
24
|
-
return debounced;
|
|
25
|
-
};
|
|
26
18
|
const normalizeSuggestions = (suggestions)=>suggestions.reduce((groups, item)=>{
|
|
27
19
|
const group = item.title;
|
|
28
20
|
if (!groups.has(group)) groups.set(group, []);
|
|
@@ -30,15 +22,7 @@ const normalizeSuggestions = (suggestions)=>suggestions.reduce((groups, item)=>{
|
|
|
30
22
|
return groups;
|
|
31
23
|
}, new Map());
|
|
32
24
|
function SearchPanel({ focused, setFocused }) {
|
|
33
|
-
const [query, setQuery] = useState('');
|
|
34
|
-
const [searchResult, setSearchResult] = useState([]);
|
|
35
25
|
const searchInputRef = useRef(null);
|
|
36
|
-
const [isSearching, setIsSearching] = useState(false);
|
|
37
|
-
const [resultTabIndex, setResultTabIndex] = useState(0);
|
|
38
|
-
const [currentSuggestionIndex, setCurrentSuggestionIndex] = useState(0);
|
|
39
|
-
const pageSearcherRef = useRef(null);
|
|
40
|
-
const pageSearcherConfigRef = useRef(null);
|
|
41
|
-
const [initStatus, setInitStatus] = useState('initial');
|
|
42
26
|
const searchResultRef = useRef(null);
|
|
43
27
|
const searchResultTabRef = useRef(null);
|
|
44
28
|
const mousePositionRef = useRef({
|
|
@@ -60,49 +44,14 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
60
44
|
});
|
|
61
45
|
}
|
|
62
46
|
};
|
|
63
|
-
const { siteData, page: { lang, version } } = usePageData();
|
|
64
47
|
const t = useI18n();
|
|
48
|
+
const userSearchHooks = useSearchHooks();
|
|
65
49
|
const navigate = useLinkNavigate();
|
|
66
|
-
const {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
result: [],
|
|
72
|
-
renderType: RenderType.Default
|
|
73
|
-
}
|
|
74
|
-
];
|
|
75
|
-
const currentSuggestions = searchResult[resultTabIndex]?.result ?? [];
|
|
76
|
-
const currentRenderType = searchResult[resultTabIndex]?.renderType ?? RenderType.Default;
|
|
77
|
-
if (false === search) return null;
|
|
78
|
-
const createSearcher = ()=>{
|
|
79
|
-
if (pageSearcherRef.current) return pageSearcherRef.current;
|
|
80
|
-
const pageSearcherConfig = {
|
|
81
|
-
currentLang: lang,
|
|
82
|
-
currentVersion: version
|
|
83
|
-
};
|
|
84
|
-
const pageSearcher = new PageSearcher({
|
|
85
|
-
indexName: siteTitle,
|
|
86
|
-
...search,
|
|
87
|
-
...pageSearcherConfig
|
|
88
|
-
});
|
|
89
|
-
pageSearcherRef.current = pageSearcher;
|
|
90
|
-
pageSearcherConfigRef.current = pageSearcherConfig;
|
|
91
|
-
return pageSearcherRef.current;
|
|
92
|
-
};
|
|
93
|
-
async function initSearch() {
|
|
94
|
-
if ('initial' !== initStatus) return;
|
|
95
|
-
const searcher = createSearcher();
|
|
96
|
-
setInitStatus('initing');
|
|
97
|
-
await searcher.init();
|
|
98
|
-
setInitStatus('inited');
|
|
99
|
-
const query = searchInputRef.current?.value;
|
|
100
|
-
if (query) {
|
|
101
|
-
const matched = await searcher.match(query);
|
|
102
|
-
setSearchResult(matched || DEFAULT_RESULT);
|
|
103
|
-
setIsSearching(false);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
50
|
+
const { currentRenderType, currentSuggestions, currentSuggestionIndex, clearQuery, handleQueryInput, initStatus, isSearching, query, resultTabIndex, searchError, searchIndexURL, searchResult, searchEnabled, setCurrentSuggestionIndex, setResultTabIndex } = useSearchPanel({
|
|
51
|
+
focused,
|
|
52
|
+
searchInputRef
|
|
53
|
+
});
|
|
54
|
+
if (!searchEnabled) return null;
|
|
106
55
|
const clearSearchState = ()=>{
|
|
107
56
|
setFocused(false);
|
|
108
57
|
setResultTabIndex(0);
|
|
@@ -140,11 +89,13 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
140
89
|
break;
|
|
141
90
|
case KEY_CODE.ENTER:
|
|
142
91
|
if (e.isComposing) return;
|
|
143
|
-
if (currentSuggestionIndex >= 0 && currentRenderType === RenderType.Default) {
|
|
92
|
+
if (focused && currentSuggestionIndex >= 0 && currentRenderType === RenderType.Default) {
|
|
144
93
|
const flatSuggestions = Array.from(normalizeSuggestions(currentSuggestions).values()).flat();
|
|
145
94
|
const suggestion = flatSuggestions[currentSuggestionIndex];
|
|
146
|
-
|
|
147
|
-
|
|
95
|
+
if (suggestion) {
|
|
96
|
+
navigate(suggestion.link);
|
|
97
|
+
clearSearchState();
|
|
98
|
+
}
|
|
148
99
|
}
|
|
149
100
|
break;
|
|
150
101
|
case KEY_CODE.ESC:
|
|
@@ -166,81 +117,12 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
166
117
|
currentSuggestions,
|
|
167
118
|
currentSuggestionIndex
|
|
168
119
|
]);
|
|
169
|
-
|
|
170
|
-
if (focused) {
|
|
171
|
-
setSearchResult(DEFAULT_RESULT);
|
|
172
|
-
initSearch();
|
|
173
|
-
} else setQuery('');
|
|
174
|
-
}, [
|
|
175
|
-
focused
|
|
176
|
-
]);
|
|
177
|
-
useEffect(()=>{
|
|
178
|
-
let idleCallbackID;
|
|
179
|
-
if ('requestIdleCallback' in window && !pageSearcherRef.current) idleCallbackID = window.requestIdleCallback(()=>{
|
|
180
|
-
const searcher = createSearcher();
|
|
181
|
-
searcher.fetchSearchIndex();
|
|
182
|
-
});
|
|
183
|
-
return ()=>{
|
|
184
|
-
if (void 0 !== idleCallbackID && 'cancelIdleCallback' in window) window.cancelIdleCallback(idleCallbackID);
|
|
185
|
-
};
|
|
186
|
-
}, []);
|
|
187
|
-
useEffect(()=>{
|
|
188
|
-
const { currentLang, currentVersion } = pageSearcherConfigRef.current ?? {};
|
|
189
|
-
const isLangChanged = lang !== currentLang;
|
|
190
|
-
const isVersionChanged = versionedSearch && version !== currentVersion;
|
|
191
|
-
if (isLangChanged || isVersionChanged) {
|
|
192
|
-
setInitStatus('initial');
|
|
193
|
-
pageSearcherRef.current = null;
|
|
194
|
-
const searcher = createSearcher();
|
|
195
|
-
searcher.fetchSearchIndex();
|
|
196
|
-
}
|
|
197
|
-
}, [
|
|
198
|
-
lang,
|
|
199
|
-
version,
|
|
200
|
-
versionedSearch
|
|
201
|
-
]);
|
|
202
|
-
const handleQueryChangedImpl = async (value)=>{
|
|
203
|
-
let newQuery = value;
|
|
204
|
-
setQuery(newQuery);
|
|
205
|
-
if (newQuery) {
|
|
206
|
-
const searchResult = [];
|
|
207
|
-
if ("beforeSearch" in __rspack_external_virtual_search_hooks_705b6e40) {
|
|
208
|
-
const key = 'beforeSearch';
|
|
209
|
-
const transformedQuery = await __rspack_external_virtual_search_hooks_705b6e40[key](newQuery);
|
|
210
|
-
if (transformedQuery) newQuery = transformedQuery;
|
|
211
|
-
}
|
|
212
|
-
const defaultSearchResult = await pageSearcherRef.current?.match(newQuery);
|
|
213
|
-
if (defaultSearchResult) searchResult.push(...defaultSearchResult);
|
|
214
|
-
if ("onSearch" in __rspack_external_virtual_search_hooks_705b6e40) {
|
|
215
|
-
const key = 'onSearch';
|
|
216
|
-
const customSearchResult = await __rspack_external_virtual_search_hooks_705b6e40[key](newQuery, searchResult);
|
|
217
|
-
if (customSearchResult) searchResult.push(...customSearchResult.map((item)=>({
|
|
218
|
-
renderType: RenderType.Custom,
|
|
219
|
-
...item
|
|
220
|
-
})));
|
|
221
|
-
}
|
|
222
|
-
if ("afterSearch" in __rspack_external_virtual_search_hooks_705b6e40) {
|
|
223
|
-
const key = 'afterSearch';
|
|
224
|
-
await __rspack_external_virtual_search_hooks_705b6e40[key](newQuery, searchResult);
|
|
225
|
-
}
|
|
226
|
-
const currQuery = searchInputRef.current?.value;
|
|
227
|
-
if (currQuery === newQuery) {
|
|
228
|
-
setCurrentSuggestionIndex(0);
|
|
229
|
-
setSearchResult(searchResult || DEFAULT_RESULT);
|
|
230
|
-
setIsSearching(false);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
const handleQueryChange = useDebounce(handleQueryChangedImpl);
|
|
235
|
-
const renderSearchResult = (result, isSearching)=>{
|
|
120
|
+
const renderSearchResult = (result)=>{
|
|
236
121
|
if (1 === result.length) {
|
|
237
122
|
const currentSearchResult = result[0].result;
|
|
238
|
-
if (0 === currentSearchResult.length && !isSearching) return /*#__PURE__*/ jsx(NoSearchResult, {
|
|
239
|
-
query: query
|
|
240
|
-
});
|
|
241
123
|
return /*#__PURE__*/ jsx("div", {
|
|
242
124
|
ref: searchResultTabRef,
|
|
243
|
-
children: renderSearchResultItem(currentSearchResult
|
|
125
|
+
children: renderSearchResultItem(currentSearchResult)
|
|
244
126
|
});
|
|
245
127
|
}
|
|
246
128
|
const renderKey = 'render';
|
|
@@ -255,20 +137,14 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
255
137
|
children: result.map((item)=>/*#__PURE__*/ jsxs(Tab, {
|
|
256
138
|
label: item.group,
|
|
257
139
|
children: [
|
|
258
|
-
item.renderType === RenderType.Default && renderSearchResultItem(item.result
|
|
259
|
-
item.renderType === RenderType.Custom &&
|
|
140
|
+
item.renderType === RenderType.Default && renderSearchResultItem(item.result),
|
|
141
|
+
item.renderType === RenderType.Custom && userSearchHooks[renderKey]?.(item.result)
|
|
260
142
|
]
|
|
261
143
|
}, item.group))
|
|
262
144
|
});
|
|
263
145
|
};
|
|
264
|
-
const renderSearchResultItem = (suggestionList
|
|
265
|
-
if (
|
|
266
|
-
className: "rp-search-panel__loading",
|
|
267
|
-
children: /*#__PURE__*/ jsx(SvgWrapper, {
|
|
268
|
-
icon: IconLoading
|
|
269
|
-
})
|
|
270
|
-
});
|
|
271
|
-
if (0 === suggestionList.length && 'inited' === initStatus) return /*#__PURE__*/ jsx(NoSearchResult, {
|
|
146
|
+
const renderSearchResultItem = (suggestionList)=>{
|
|
147
|
+
if (0 === suggestionList.length && 'inited' === initStatus) return isSearching ? null : /*#__PURE__*/ jsx(NoSearchResult, {
|
|
272
148
|
query: query
|
|
273
149
|
});
|
|
274
150
|
const normalizedSuggestions = normalizeSuggestions(suggestionList);
|
|
@@ -308,75 +184,93 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
308
184
|
})
|
|
309
185
|
});
|
|
310
186
|
};
|
|
311
|
-
return /*#__PURE__*/
|
|
312
|
-
children:
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
187
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
188
|
+
children: [
|
|
189
|
+
searchIndexURL && /*#__PURE__*/ jsx(Head, {
|
|
190
|
+
children: /*#__PURE__*/ jsx("link", {
|
|
191
|
+
rel: "prefetch",
|
|
192
|
+
href: searchIndexURL
|
|
193
|
+
})
|
|
194
|
+
}),
|
|
195
|
+
focused && /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx("div", {
|
|
196
|
+
className: "rp-search-panel__mask",
|
|
197
|
+
onClick: ()=>{
|
|
198
|
+
clearSearchState();
|
|
322
199
|
},
|
|
323
|
-
children:
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
searchInputRef.current.value = '';
|
|
354
|
-
setQuery('');
|
|
355
|
-
} else clearSearchState();
|
|
356
|
-
}
|
|
200
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
201
|
+
className: "rp-search-panel__modal",
|
|
202
|
+
onClick: (e)=>{
|
|
203
|
+
setFocused(true);
|
|
204
|
+
e.stopPropagation();
|
|
205
|
+
},
|
|
206
|
+
children: [
|
|
207
|
+
/*#__PURE__*/ jsxs("div", {
|
|
208
|
+
className: "rp-search-panel__header",
|
|
209
|
+
children: [
|
|
210
|
+
/*#__PURE__*/ jsxs("div", {
|
|
211
|
+
className: "rp-search-panel__input-form",
|
|
212
|
+
children: [
|
|
213
|
+
/*#__PURE__*/ jsx("label", {
|
|
214
|
+
children: /*#__PURE__*/ jsx(SvgWrapper, {
|
|
215
|
+
icon: IconSearch,
|
|
216
|
+
className: `rp-search-panel__search-icon${'initing' === initStatus || isSearching ? ' rp-search-panel__search-icon--loading' : ''}`
|
|
217
|
+
})
|
|
218
|
+
}),
|
|
219
|
+
/*#__PURE__*/ jsx("input", {
|
|
220
|
+
className: "rp-search-panel__input",
|
|
221
|
+
ref: searchInputRef,
|
|
222
|
+
placeholder: t('searchPlaceholderText'),
|
|
223
|
+
"aria-label": "SearchPanelInput",
|
|
224
|
+
autoComplete: "off",
|
|
225
|
+
autoFocus: true,
|
|
226
|
+
inputMode: "search",
|
|
227
|
+
onChange: (e)=>{
|
|
228
|
+
const value = e.target.value;
|
|
229
|
+
handleQueryInput(value);
|
|
357
230
|
}
|
|
231
|
+
}),
|
|
232
|
+
/*#__PURE__*/ jsx("label", {
|
|
233
|
+
children: /*#__PURE__*/ jsx(SvgWrapper, {
|
|
234
|
+
icon: IconClose,
|
|
235
|
+
className: "rp-search-panel__close",
|
|
236
|
+
onClick: (e)=>{
|
|
237
|
+
if (searchInputRef.current) {
|
|
238
|
+
e.stopPropagation();
|
|
239
|
+
if (query) {
|
|
240
|
+
searchInputRef.current.value = '';
|
|
241
|
+
clearQuery();
|
|
242
|
+
} else clearSearchState();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
})
|
|
358
246
|
})
|
|
359
|
-
|
|
247
|
+
]
|
|
248
|
+
}),
|
|
249
|
+
/*#__PURE__*/ jsx("h2", {
|
|
250
|
+
className: "rp-search-panel__cancel",
|
|
251
|
+
onClick: (e)=>{
|
|
252
|
+
e.stopPropagation();
|
|
253
|
+
clearSearchState();
|
|
254
|
+
},
|
|
255
|
+
children: t('searchPanelCancelText')
|
|
256
|
+
})
|
|
257
|
+
]
|
|
258
|
+
}),
|
|
259
|
+
(query || 'error' === initStatus) && ('inited' === initStatus || 'error' === initStatus) ? /*#__PURE__*/ jsx("div", {
|
|
260
|
+
className: "rp-search-panel__results rp-scrollbar",
|
|
261
|
+
ref: searchResultRef,
|
|
262
|
+
children: 'error' === initStatus ? /*#__PURE__*/ jsxs("div", {
|
|
263
|
+
className: "rp-search-panel__error",
|
|
264
|
+
children: [
|
|
265
|
+
"Error: ",
|
|
266
|
+
searchError
|
|
360
267
|
]
|
|
361
|
-
})
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
},
|
|
368
|
-
children: t('searchPanelCancelText')
|
|
369
|
-
})
|
|
370
|
-
]
|
|
371
|
-
}),
|
|
372
|
-
query && 'inited' === initStatus ? /*#__PURE__*/ jsx("div", {
|
|
373
|
-
className: "rp-search-panel__results rp-scrollbar",
|
|
374
|
-
ref: searchResultRef,
|
|
375
|
-
children: renderSearchResult(searchResult, isSearching)
|
|
376
|
-
}) : null
|
|
377
|
-
]
|
|
378
|
-
})
|
|
379
|
-
}), document.getElementById('__rspress_modal_container'))
|
|
268
|
+
}) : renderSearchResult(searchResult)
|
|
269
|
+
}) : null
|
|
270
|
+
]
|
|
271
|
+
})
|
|
272
|
+
}), document.getElementById('__rspress_modal_container'))
|
|
273
|
+
]
|
|
380
274
|
});
|
|
381
275
|
}
|
|
382
276
|
export { SearchPanel };
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { type PageIndexInfo } from '@rspress/shared';
|
|
6
6
|
import { type Provider, type SearchQuery } from '../Provider.js';
|
|
7
7
|
import type { SearchOptions } from '../types.js';
|
|
8
|
+
export declare function getSearchIndexURL(lang: string, version: string): string | undefined;
|
|
8
9
|
export declare class LocalProvider implements Provider {
|
|
9
10
|
#private;
|
|
10
11
|
fetchSearchIndex(options: SearchOptions): Promise<PageIndexInfo[]>;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { SEARCH_INDEX_NAME, removeTrailingSlash } from "@rspress/shared";
|
|
2
2
|
import { Document } from "flexsearch";
|
|
3
|
-
import { searchIndexHash } from "
|
|
3
|
+
import { searchIndexHash } from "@rspress/core/runtime";
|
|
4
4
|
import { LOCAL_INDEX } from "../Provider.js";
|
|
5
5
|
import { normalizeTextCase } from "../util.js";
|
|
6
|
+
function getSearchIndexURL(lang, version) {
|
|
7
|
+
const searchIndexGroupID = `${version ?? ''}###${lang ?? ''}`;
|
|
8
|
+
const searchIndexHashValue = searchIndexHash[searchIndexGroupID];
|
|
9
|
+
if (!searchIndexHashValue) return;
|
|
10
|
+
const searchIndexVersion = version ? `.${version.replace('.', '_')}` : '';
|
|
11
|
+
const searchIndexLang = lang ? `.${lang}` : '';
|
|
12
|
+
return `${removeTrailingSlash(__webpack_public_path__)}/static/${SEARCH_INDEX_NAME}${searchIndexVersion}${searchIndexLang}.${searchIndexHashValue}.json`;
|
|
13
|
+
}
|
|
6
14
|
const cjkRegex = /[\u3131-\u314e|\u314f-\u3163|\uac00-\ud7a3]|[\u4E00-\u9FCC\u3400-\u4DB5\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\ud840-\ud868][\udc00-\udfff]|\ud869[\udc00-\uded6\udf00-\udfff]|[\ud86a-\ud86c][\udc00-\udfff]|\ud86d[\udc00-\udf34\udf40-\udfff]|\ud86e[\udc00-\udc1d]|[\u3041-\u3096]|[\u30A1-\u30FA]/giu;
|
|
7
15
|
const cyrillicRegex = /[\u0400-\u04FF]/g;
|
|
8
16
|
function tokenize(str, regex) {
|
|
@@ -20,23 +28,20 @@ class LocalProvider {
|
|
|
20
28
|
#cyrillicIndex;
|
|
21
29
|
#fetchPromise;
|
|
22
30
|
async #getPages(lang, version) {
|
|
23
|
-
const
|
|
24
|
-
if (!
|
|
25
|
-
const searchIndexVersion = version ? `.${version.replace('.', '_')}` : '';
|
|
26
|
-
const searchIndexLang = lang ? `.${lang}` : '';
|
|
27
|
-
const searchIndexURL = `${removeTrailingSlash(__webpack_public_path__)}/static/${SEARCH_INDEX_NAME}${searchIndexVersion}${searchIndexLang}.${searchIndexHash[searchIndexGroupID]}.json`;
|
|
31
|
+
const searchIndexURL = getSearchIndexURL(lang, version);
|
|
32
|
+
if (!searchIndexURL) return [];
|
|
28
33
|
const handleError = (result)=>{
|
|
29
34
|
console.error('Failed to fetch search index, please reload the page and try again.');
|
|
30
35
|
console.error(result);
|
|
36
|
+
throw result instanceof Error ? result : new Error('Failed to fetch search index');
|
|
31
37
|
};
|
|
32
38
|
try {
|
|
33
39
|
const result = await fetch(searchIndexURL);
|
|
34
40
|
if (result.ok) return result.json();
|
|
35
|
-
|
|
41
|
+
throw result;
|
|
36
42
|
} catch (error) {
|
|
37
|
-
handleError(error);
|
|
43
|
+
return handleError(error);
|
|
38
44
|
}
|
|
39
|
-
return [];
|
|
40
45
|
}
|
|
41
46
|
async fetchSearchIndex(options) {
|
|
42
47
|
if (this.#fetchPromise) return this.#fetchPromise;
|
|
@@ -65,7 +70,12 @@ class LocalProvider {
|
|
|
65
70
|
},
|
|
66
71
|
cache: 100
|
|
67
72
|
};
|
|
68
|
-
this.#index = new Document(
|
|
73
|
+
this.#index = new Document({
|
|
74
|
+
...createOptions,
|
|
75
|
+
encoder: {
|
|
76
|
+
maxlength: 64
|
|
77
|
+
}
|
|
78
|
+
});
|
|
69
79
|
this.#cjkIndex = new Document({
|
|
70
80
|
...createOptions,
|
|
71
81
|
encoder: {
|
|
@@ -78,12 +88,12 @@ class LocalProvider {
|
|
|
78
88
|
finalize: (str)=>str.flatMap((s)=>tokenize(s, cyrillicRegex))
|
|
79
89
|
}
|
|
80
90
|
});
|
|
91
|
+
const pending = [];
|
|
81
92
|
for (const item of pagesForSearch){
|
|
82
93
|
const flexSearchItem = item;
|
|
83
|
-
this.#index.addAsync(item.routePath, flexSearchItem);
|
|
84
|
-
this.#cjkIndex.addAsync(item.routePath, flexSearchItem);
|
|
85
|
-
this.#cyrillicIndex.addAsync(item.routePath, flexSearchItem);
|
|
94
|
+
pending.push(this.#index.addAsync(item.routePath, flexSearchItem), this.#cjkIndex.addAsync(item.routePath, flexSearchItem), this.#cyrillicIndex.addAsync(item.routePath, flexSearchItem));
|
|
86
95
|
}
|
|
96
|
+
await Promise.all(pending);
|
|
87
97
|
}
|
|
88
98
|
async search(query) {
|
|
89
99
|
const { keyword, limit } = query;
|
|
@@ -122,4 +132,4 @@ class LocalProvider {
|
|
|
122
132
|
];
|
|
123
133
|
}
|
|
124
134
|
}
|
|
125
|
-
export { LocalProvider };
|
|
135
|
+
export { LocalProvider, getSearchIndexURL };
|
|
@@ -110,7 +110,7 @@ class PageSearcher {
|
|
|
110
110
|
const getCurrentHeader = (currentIndex)=>{
|
|
111
111
|
const currentHeaderIndex = headersIndex.findIndex((hIndex, position)=>{
|
|
112
112
|
if (!(position < toc.length - 1)) return hIndex < currentIndex;
|
|
113
|
-
{
|
|
113
|
+
else {
|
|
114
114
|
const next = headersIndex[position + 1];
|
|
115
115
|
if (hIndex <= currentIndex && next >= currentIndex) return true;
|
|
116
116
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type { MatchResult } from './logic/types.js';
|
|
3
|
+
import { RenderType } from './logic/types.js';
|
|
4
|
+
export declare function useSearchPanel({ focused, searchInputRef, }: {
|
|
5
|
+
focused: boolean;
|
|
6
|
+
searchInputRef: RefObject<HTMLInputElement | null>;
|
|
7
|
+
}): {
|
|
8
|
+
searchEnabled: boolean;
|
|
9
|
+
clearQuery: () => void;
|
|
10
|
+
currentRenderType: RenderType;
|
|
11
|
+
currentSuggestions: import("./logic/types.js").DefaultMatchResultItem[];
|
|
12
|
+
handleQueryInput: (value: string) => void;
|
|
13
|
+
initStatus: "error" | "inited" | "initial" | "initing";
|
|
14
|
+
isSearching: boolean;
|
|
15
|
+
resultTabIndex: number;
|
|
16
|
+
searchError: string | undefined;
|
|
17
|
+
searchIndexURL: string | undefined;
|
|
18
|
+
searchResult: MatchResult;
|
|
19
|
+
query: string;
|
|
20
|
+
currentSuggestionIndex: number;
|
|
21
|
+
setCurrentSuggestionIndex: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
22
|
+
setResultTabIndex: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
23
|
+
};
|