@rspress/core 2.0.20 → 2.0.22
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/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/Banner/index.tsx +50 -9
- package/dist/eject-theme/components/Callout/index.scss +6 -1
- package/dist/eject-theme/components/CodeBlock/index.scss +2 -0
- package/dist/eject-theme/components/DocContent/doc.scss +2 -2
- package/dist/eject-theme/components/Link/getHref.test.ts +33 -0
- package/dist/eject-theme/components/Link/getHref.ts +60 -0
- package/dist/eject-theme/components/Link/index.tsx +7 -6
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +6 -51
- 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 +19 -3
- package/dist/eject-theme/components/Nav/NavMenu.tsx +20 -13
- package/dist/eject-theme/components/Nav/index.scss +3 -1
- 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/Prompt/index.scss +2 -1
- 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 +54 -212
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +38 -16
- package/dist/eject-theme/components/Search/useSearchPanel.ts +216 -0
- 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/global.scss +18 -0
- package/dist/eject-theme/components/SwitchAppearance/index.tsx +26 -35
- 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 +1 -1
- 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} +41 -41
- package/dist/{2711~0.js → o~0.js} +90 -56
- package/dist/rslib-runtime~0.js +27 -35
- package/dist/theme/components/Banner/index.js +53 -9
- package/dist/theme/components/Callout/index.css +6 -1
- package/dist/theme/components/CodeBlock/index.css +2 -0
- package/dist/theme/components/DocContent/doc.css +2 -2
- package/dist/theme/components/Link/getHref.d.ts +8 -0
- package/dist/theme/components/Link/getHref.js +33 -0
- package/dist/theme/components/Link/index.js +7 -6
- package/dist/theme/components/Link/useLinkNavigate.d.ts +0 -7
- package/dist/theme/components/Link/useLinkNavigate.js +8 -32
- package/dist/theme/components/Llms/LlmsHint.js +23 -6
- package/dist/theme/components/Nav/NavMenu.css +18 -6
- 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.css +3 -1
- 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/Prompt/index.css +2 -1
- 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 +97 -205
- package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +1 -0
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +23 -13
- 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/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/global.css +12 -0
- package/dist/theme/components/SwitchAppearance/index.js +11 -15
- 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/applyThemeToDOM.d.ts +2 -0
- package/dist/theme/logic/applyThemeToDOM.js +17 -0
- package/dist/theme/logic/useFullTextSearch.js +6 -1
- package/dist/theme/logic/useThemeState.d.ts +1 -2
- package/dist/theme/logic/useThemeState.js +1 -7
- 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/dist/{8472~0.js → v~0.js} +1 -1
- package/package.json +11 -12
- 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,11 +1,47 @@
|
|
|
1
|
-
import { Fragment, jsx } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment as external_react_Fragment } from "react";
|
|
2
3
|
import { NavScreenMenuItem } from "./NavScreenMenuItem.js";
|
|
3
4
|
import "./NavScreenMenu.css";
|
|
4
|
-
function NavScreenMenu({ menuItems }) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
function NavScreenMenu({ menuItems, beforeLeftNavItems, afterLeftNavItems, beforeRightNavItems, afterRightNavItems }) {
|
|
6
|
+
let firstLeft = -1;
|
|
7
|
+
let lastLeft = -1;
|
|
8
|
+
let firstRight = -1;
|
|
9
|
+
let lastRight = -1;
|
|
10
|
+
menuItems.forEach((item, index)=>{
|
|
11
|
+
if ('left' === item.position) {
|
|
12
|
+
if (-1 === firstLeft) firstLeft = index;
|
|
13
|
+
lastLeft = index;
|
|
14
|
+
} else {
|
|
15
|
+
if (-1 === firstRight) firstRight = index;
|
|
16
|
+
lastRight = index;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
20
|
+
children: [
|
|
21
|
+
-1 === firstLeft ? /*#__PURE__*/ jsxs(Fragment, {
|
|
22
|
+
children: [
|
|
23
|
+
beforeLeftNavItems,
|
|
24
|
+
afterLeftNavItems
|
|
25
|
+
]
|
|
26
|
+
}) : null,
|
|
27
|
+
menuItems.map((item, index)=>/*#__PURE__*/ jsxs(external_react_Fragment, {
|
|
28
|
+
children: [
|
|
29
|
+
index === firstLeft ? beforeLeftNavItems : null,
|
|
30
|
+
index === firstRight ? beforeRightNavItems : null,
|
|
31
|
+
/*#__PURE__*/ jsx(NavScreenMenuItem, {
|
|
32
|
+
menuItem: item
|
|
33
|
+
}),
|
|
34
|
+
index === lastLeft ? afterLeftNavItems : null,
|
|
35
|
+
index === lastRight ? afterRightNavItems : null
|
|
36
|
+
]
|
|
37
|
+
}, index)),
|
|
38
|
+
-1 === firstRight ? /*#__PURE__*/ jsxs(Fragment, {
|
|
39
|
+
children: [
|
|
40
|
+
beforeRightNavItems,
|
|
41
|
+
afterRightNavItems
|
|
42
|
+
]
|
|
43
|
+
}) : null
|
|
44
|
+
]
|
|
9
45
|
});
|
|
10
46
|
}
|
|
11
47
|
export { NavScreenMenu };
|
|
@@ -23,16 +23,6 @@
|
|
|
23
23
|
display: flex;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
.rp-nav-screen__others {
|
|
27
|
-
display: flex;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@media (width <= 1280px) {
|
|
31
|
-
.rp-nav-screen__others {
|
|
32
|
-
display: none;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
26
|
.rp-nav-screen-divider {
|
|
37
27
|
background-color: var(--rp-c-divider-light);
|
|
38
28
|
width: 100%;
|
|
@@ -5,6 +5,7 @@ import { clearAllBodyScrollLocks, disableBodyScroll } from "body-scroll-lock";
|
|
|
5
5
|
import clsx from "clsx";
|
|
6
6
|
import { useEffect, useRef } from "react";
|
|
7
7
|
import "./index.css";
|
|
8
|
+
import { NavListContext } from "../NavList/context.js";
|
|
8
9
|
import { NavScreenAppearance } from "./NavScreenAppearance.js";
|
|
9
10
|
import { NavScreenLangs } from "./NavScreenLangs.js";
|
|
10
11
|
import { NavScreenMenu } from "./NavScreenMenu.js";
|
|
@@ -15,7 +16,7 @@ function NavScreenDivider() {
|
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
function NavScreen(props) {
|
|
18
|
-
const { isScreenOpen, toggleScreen } = props;
|
|
19
|
+
const { isScreenOpen, toggleScreen, beforeLeftNavItems, afterLeftNavItems, beforeRightNavItems, afterRightNavItems } = props;
|
|
19
20
|
const screen = useRef(null);
|
|
20
21
|
const menuItems = useNav();
|
|
21
22
|
useEffect(()=>{
|
|
@@ -47,8 +48,15 @@ function NavScreen(props) {
|
|
|
47
48
|
className: "rp-nav-screen__container",
|
|
48
49
|
onClick: (e)=>e.stopPropagation(),
|
|
49
50
|
children: [
|
|
50
|
-
/*#__PURE__*/ jsx(
|
|
51
|
-
|
|
51
|
+
/*#__PURE__*/ jsx(NavListContext.Provider, {
|
|
52
|
+
value: "screen",
|
|
53
|
+
children: /*#__PURE__*/ jsx(NavScreenMenu, {
|
|
54
|
+
menuItems: menuItems,
|
|
55
|
+
beforeLeftNavItems: beforeLeftNavItems,
|
|
56
|
+
afterLeftNavItems: afterLeftNavItems,
|
|
57
|
+
beforeRightNavItems: beforeRightNavItems,
|
|
58
|
+
afterRightNavItems: afterRightNavItems
|
|
59
|
+
})
|
|
52
60
|
}),
|
|
53
61
|
/*#__PURE__*/ jsx(NavScreenDivider, {}),
|
|
54
62
|
/*#__PURE__*/ jsx(NavScreenAppearance, {}),
|
|
@@ -80,8 +80,8 @@ function PackageManagerTabs({ command, exec, dlx, additionalTabs = [] }) {
|
|
|
80
80
|
default:
|
|
81
81
|
return packageManager;
|
|
82
82
|
}
|
|
83
|
-
if (!exec) return packageManager;
|
|
84
|
-
switch(packageManager){
|
|
83
|
+
else if (!exec) return packageManager;
|
|
84
|
+
else switch(packageManager){
|
|
85
85
|
case 'npm':
|
|
86
86
|
return 'npx';
|
|
87
87
|
case 'yarn':
|
|
@@ -302,7 +302,8 @@
|
|
|
302
302
|
|
|
303
303
|
.rp-prompt__custom-content a {
|
|
304
304
|
color: var(--rp-prompt-accent, var(--rp-c-brand-dark));
|
|
305
|
-
|
|
305
|
+
text-underline-offset: 4px;
|
|
306
|
+
text-decoration: underline;
|
|
306
307
|
}
|
|
307
308
|
|
|
308
309
|
.rp-prompt__custom-content a > code, .rp-prompt__custom-content a:hover > code {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
.rp-search-panel__mask {
|
|
2
2
|
backdrop-filter: blur(5px);
|
|
3
|
-
z-index:
|
|
3
|
+
z-index: 1000;
|
|
4
4
|
background: #3c3c3c66;
|
|
5
5
|
position: fixed;
|
|
6
6
|
inset: 0;
|
|
@@ -13,9 +13,16 @@
|
|
|
13
13
|
height: auto;
|
|
14
14
|
margin: 80px auto auto;
|
|
15
15
|
padding: 20px;
|
|
16
|
+
animation: .18s ease-out rp-search-panel-in;
|
|
16
17
|
position: relative;
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
@media (prefers-reduced-motion: reduce) {
|
|
21
|
+
.rp-search-panel__modal {
|
|
22
|
+
animation: none;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
.rp-search-panel__header {
|
|
20
27
|
align-items: center;
|
|
21
28
|
display: flex;
|
|
@@ -24,6 +31,7 @@
|
|
|
24
31
|
.rp-search-panel__cancel {
|
|
25
32
|
color: var(--rp-c-brand);
|
|
26
33
|
cursor: pointer;
|
|
34
|
+
white-space: nowrap;
|
|
27
35
|
margin-left: .5rem;
|
|
28
36
|
}
|
|
29
37
|
|
|
@@ -65,18 +73,31 @@
|
|
|
65
73
|
transition: color .3s;
|
|
66
74
|
}
|
|
67
75
|
|
|
76
|
+
.rp-search-panel__search-icon--loading {
|
|
77
|
+
animation: 1s ease-in-out infinite rp-search-panel-icon-loading;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@media (prefers-reduced-motion: reduce) {
|
|
81
|
+
.rp-search-panel__search-icon--loading {
|
|
82
|
+
animation: none;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.rp-search-panel__search-icon {
|
|
87
|
+
font-size: 20px;
|
|
88
|
+
display: inline-block;
|
|
89
|
+
}
|
|
90
|
+
|
|
68
91
|
.rp-search-panel__results {
|
|
69
92
|
max-height: calc(100vh - 230px);
|
|
70
93
|
padding-right: 2px;
|
|
71
94
|
overflow: scroll;
|
|
72
95
|
}
|
|
73
96
|
|
|
74
|
-
.rp-search-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
margin: 2rem 0;
|
|
79
|
-
display: flex;
|
|
97
|
+
.rp-search-panel__error {
|
|
98
|
+
color: var(--rp-c-text-2);
|
|
99
|
+
text-align: center;
|
|
100
|
+
padding: 2rem 0;
|
|
80
101
|
}
|
|
81
102
|
|
|
82
103
|
.rp-search-panel__tabs {
|
|
@@ -97,14 +118,14 @@
|
|
|
97
118
|
|
|
98
119
|
@media (width <= 960px) {
|
|
99
120
|
.rp-search-panel__modal {
|
|
100
|
-
margin-top:
|
|
121
|
+
margin-top: calc(32px + env(safe-area-inset-top, 0px));
|
|
101
122
|
}
|
|
102
123
|
|
|
103
124
|
.rp-search-panel__input-form {
|
|
104
125
|
height: 40px;
|
|
105
126
|
}
|
|
106
127
|
|
|
107
|
-
.rp-search-
|
|
128
|
+
.rp-search-panel__search-icon, .rp-search-panel__close {
|
|
108
129
|
width: 16px;
|
|
109
130
|
height: 16px;
|
|
110
131
|
}
|
|
@@ -114,3 +135,20 @@
|
|
|
114
135
|
}
|
|
115
136
|
}
|
|
116
137
|
|
|
138
|
+
@keyframes rp-search-panel-in {
|
|
139
|
+
from {
|
|
140
|
+
opacity: 0;
|
|
141
|
+
transform: translateY(-8px) scale(.98);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@keyframes rp-search-panel-icon-loading {
|
|
146
|
+
0%, 100% {
|
|
147
|
+
opacity: 1;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
50% {
|
|
151
|
+
opacity: .35;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { IconClose,
|
|
4
|
-
import {
|
|
5
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Head, useI18n } 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
6
|
import * as __rspack_external_virtual_search_hooks_705b6e40 from "virtual-search-hooks";
|
|
8
|
-
import { PageSearcher } from "./logic/search.js";
|
|
9
7
|
import { RenderType } from "./logic/types.js";
|
|
10
8
|
import { NoSearchResult } from "./NoSearchResult.js";
|
|
11
9
|
import "./SearchPanel.css";
|
|
12
10
|
import { SuggestItem } from "./SuggestItem.js";
|
|
11
|
+
import { useSearchPanel } from "./useSearchPanel.js";
|
|
13
12
|
const KEY_CODE = {
|
|
14
13
|
ARROW_UP: 'ArrowUp',
|
|
15
14
|
ARROW_DOWN: 'ArrowDown',
|
|
@@ -17,12 +16,6 @@ const KEY_CODE = {
|
|
|
17
16
|
SEARCH: 'KeyK',
|
|
18
17
|
ESC: 'Escape'
|
|
19
18
|
};
|
|
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
19
|
const normalizeSuggestions = (suggestions)=>suggestions.reduce((groups, item)=>{
|
|
27
20
|
const group = item.title;
|
|
28
21
|
if (!groups.has(group)) groups.set(group, []);
|
|
@@ -30,15 +23,7 @@ const normalizeSuggestions = (suggestions)=>suggestions.reduce((groups, item)=>{
|
|
|
30
23
|
return groups;
|
|
31
24
|
}, new Map());
|
|
32
25
|
function SearchPanel({ focused, setFocused }) {
|
|
33
|
-
const [query, setQuery] = useState('');
|
|
34
|
-
const [searchResult, setSearchResult] = useState([]);
|
|
35
26
|
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
27
|
const searchResultRef = useRef(null);
|
|
43
28
|
const searchResultTabRef = useRef(null);
|
|
44
29
|
const mousePositionRef = useRef({
|
|
@@ -60,49 +45,13 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
60
45
|
});
|
|
61
46
|
}
|
|
62
47
|
};
|
|
63
|
-
const { siteData, page: { lang, version } } = usePageData();
|
|
64
48
|
const t = useI18n();
|
|
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);
|
|
@@ -166,81 +115,12 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
166
115
|
currentSuggestions,
|
|
167
116
|
currentSuggestionIndex
|
|
168
117
|
]);
|
|
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)=>{
|
|
118
|
+
const renderSearchResult = (result)=>{
|
|
236
119
|
if (1 === result.length) {
|
|
237
120
|
const currentSearchResult = result[0].result;
|
|
238
|
-
if (0 === currentSearchResult.length && !isSearching) return /*#__PURE__*/ jsx(NoSearchResult, {
|
|
239
|
-
query: query
|
|
240
|
-
});
|
|
241
121
|
return /*#__PURE__*/ jsx("div", {
|
|
242
122
|
ref: searchResultTabRef,
|
|
243
|
-
children: renderSearchResultItem(currentSearchResult
|
|
123
|
+
children: renderSearchResultItem(currentSearchResult)
|
|
244
124
|
});
|
|
245
125
|
}
|
|
246
126
|
const renderKey = 'render';
|
|
@@ -255,20 +135,14 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
255
135
|
children: result.map((item)=>/*#__PURE__*/ jsxs(Tab, {
|
|
256
136
|
label: item.group,
|
|
257
137
|
children: [
|
|
258
|
-
item.renderType === RenderType.Default && renderSearchResultItem(item.result
|
|
138
|
+
item.renderType === RenderType.Default && renderSearchResultItem(item.result),
|
|
259
139
|
item.renderType === RenderType.Custom && __rspack_external_virtual_search_hooks_705b6e40[renderKey](item.result)
|
|
260
140
|
]
|
|
261
141
|
}, item.group))
|
|
262
142
|
});
|
|
263
143
|
};
|
|
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, {
|
|
144
|
+
const renderSearchResultItem = (suggestionList)=>{
|
|
145
|
+
if (0 === suggestionList.length && 'inited' === initStatus) return isSearching ? null : /*#__PURE__*/ jsx(NoSearchResult, {
|
|
272
146
|
query: query
|
|
273
147
|
});
|
|
274
148
|
const normalizedSuggestions = normalizeSuggestions(suggestionList);
|
|
@@ -308,75 +182,93 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
308
182
|
})
|
|
309
183
|
});
|
|
310
184
|
};
|
|
311
|
-
return /*#__PURE__*/
|
|
312
|
-
children:
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
185
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
186
|
+
children: [
|
|
187
|
+
searchIndexURL && /*#__PURE__*/ jsx(Head, {
|
|
188
|
+
children: /*#__PURE__*/ jsx("link", {
|
|
189
|
+
rel: "prefetch",
|
|
190
|
+
href: searchIndexURL
|
|
191
|
+
})
|
|
192
|
+
}),
|
|
193
|
+
focused && /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx("div", {
|
|
194
|
+
className: "rp-search-panel__mask",
|
|
195
|
+
onClick: ()=>{
|
|
196
|
+
clearSearchState();
|
|
322
197
|
},
|
|
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
|
-
}
|
|
198
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
199
|
+
className: "rp-search-panel__modal",
|
|
200
|
+
onClick: (e)=>{
|
|
201
|
+
setFocused(true);
|
|
202
|
+
e.stopPropagation();
|
|
203
|
+
},
|
|
204
|
+
children: [
|
|
205
|
+
/*#__PURE__*/ jsxs("div", {
|
|
206
|
+
className: "rp-search-panel__header",
|
|
207
|
+
children: [
|
|
208
|
+
/*#__PURE__*/ jsxs("div", {
|
|
209
|
+
className: "rp-search-panel__input-form",
|
|
210
|
+
children: [
|
|
211
|
+
/*#__PURE__*/ jsx("label", {
|
|
212
|
+
children: /*#__PURE__*/ jsx(SvgWrapper, {
|
|
213
|
+
icon: IconSearch,
|
|
214
|
+
className: `rp-search-panel__search-icon${'initing' === initStatus || isSearching ? ' rp-search-panel__search-icon--loading' : ''}`
|
|
215
|
+
})
|
|
216
|
+
}),
|
|
217
|
+
/*#__PURE__*/ jsx("input", {
|
|
218
|
+
className: "rp-search-panel__input",
|
|
219
|
+
ref: searchInputRef,
|
|
220
|
+
placeholder: t('searchPlaceholderText'),
|
|
221
|
+
"aria-label": "SearchPanelInput",
|
|
222
|
+
autoComplete: "off",
|
|
223
|
+
autoFocus: true,
|
|
224
|
+
inputMode: "search",
|
|
225
|
+
onChange: (e)=>{
|
|
226
|
+
const value = e.target.value;
|
|
227
|
+
handleQueryInput(value);
|
|
357
228
|
}
|
|
229
|
+
}),
|
|
230
|
+
/*#__PURE__*/ jsx("label", {
|
|
231
|
+
children: /*#__PURE__*/ jsx(SvgWrapper, {
|
|
232
|
+
icon: IconClose,
|
|
233
|
+
className: "rp-search-panel__close",
|
|
234
|
+
onClick: (e)=>{
|
|
235
|
+
if (searchInputRef.current) {
|
|
236
|
+
e.stopPropagation();
|
|
237
|
+
if (query) {
|
|
238
|
+
searchInputRef.current.value = '';
|
|
239
|
+
clearQuery();
|
|
240
|
+
} else clearSearchState();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
})
|
|
358
244
|
})
|
|
359
|
-
|
|
245
|
+
]
|
|
246
|
+
}),
|
|
247
|
+
/*#__PURE__*/ jsx("h2", {
|
|
248
|
+
className: "rp-search-panel__cancel",
|
|
249
|
+
onClick: (e)=>{
|
|
250
|
+
e.stopPropagation();
|
|
251
|
+
clearSearchState();
|
|
252
|
+
},
|
|
253
|
+
children: t('searchPanelCancelText')
|
|
254
|
+
})
|
|
255
|
+
]
|
|
256
|
+
}),
|
|
257
|
+
(query || 'error' === initStatus) && ('inited' === initStatus || 'error' === initStatus) ? /*#__PURE__*/ jsx("div", {
|
|
258
|
+
className: "rp-search-panel__results rp-scrollbar",
|
|
259
|
+
ref: searchResultRef,
|
|
260
|
+
children: 'error' === initStatus ? /*#__PURE__*/ jsxs("div", {
|
|
261
|
+
className: "rp-search-panel__error",
|
|
262
|
+
children: [
|
|
263
|
+
"Error: ",
|
|
264
|
+
searchError
|
|
360
265
|
]
|
|
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'))
|
|
266
|
+
}) : renderSearchResult(searchResult)
|
|
267
|
+
}) : null
|
|
268
|
+
]
|
|
269
|
+
})
|
|
270
|
+
}), document.getElementById('__rspress_modal_container'))
|
|
271
|
+
]
|
|
380
272
|
});
|
|
381
273
|
}
|
|
382
274
|
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[]>;
|