@rspress/core 0.0.13 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +33 -26
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +24 -49
- package/dist/loader.js.map +1 -1
- package/dist/runtime/App.d.ts +8 -0
- package/dist/runtime/Content.d.ts +6 -0
- package/dist/runtime/NoSSR.d.ts +4 -0
- package/dist/runtime/clientEntry.d.ts +1 -0
- package/dist/runtime/hooks.d.ts +22 -0
- package/dist/runtime/index.d.ts +6 -0
- package/dist/runtime/ssrEntry.d.ts +6 -0
- package/dist/runtime/tsconfig.json +9 -0
- package/dist/runtime/utils.d.ts +6 -0
- package/dist/theme/bundle.css +56 -53
- package/dist/theme/bundle.d.ts +7 -1
- package/dist/theme/bundle.js +410 -422
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +14 -14
- package/src/runtime/global.d.ts +49 -0
- package/src/runtime/tsconfig.json +9 -0
- package/src/theme-default/components/LocalSideBar/{index.module.scss → index.scss} +6 -5
- package/src/theme-default/components/LocalSideBar/index.tsx +4 -4
- package/src/theme-default/components/Search/SearchPanel.tsx +339 -0
- package/src/theme-default/components/Search/index.tsx +6 -326
- package/src/theme-default/index.ts +1 -1
- package/src/theme-default/layout/DocLayout/index.module.scss +6 -3
- package/src/theme-default/layout/DocLayout/index.tsx +9 -7
- package/src/theme-default/logic/useAppearance.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"@mdx-js/loader": "2.2.1",
|
|
41
41
|
"@mdx-js/mdx": "2.2.1",
|
|
42
42
|
"@mdx-js/react": "2.2.1",
|
|
43
|
-
"@modern-js/builder": "2.35.
|
|
44
|
-
"@modern-js/builder-rspack-provider": "2.35.
|
|
45
|
-
"@
|
|
46
|
-
"@modern-js/utils": "2.35.
|
|
43
|
+
"@modern-js/builder": "2.35.1",
|
|
44
|
+
"@modern-js/builder-rspack-provider": "2.35.1",
|
|
45
|
+
"@rspress/mdx-rs": "0.3.1",
|
|
46
|
+
"@modern-js/utils": "2.35.1",
|
|
47
47
|
"@types/compression": "^1.7.2",
|
|
48
48
|
"@types/polka": "^0.5.4",
|
|
49
49
|
"autoprefixer": "10.4.13",
|
|
@@ -89,20 +89,20 @@
|
|
|
89
89
|
"unist-util-visit-children": "^2.0.1",
|
|
90
90
|
"yaml-front-matter": "^4.1.1",
|
|
91
91
|
"rspack-plugin-virtual-module": "0.1.12",
|
|
92
|
-
"@rspress/shared": "0.
|
|
93
|
-
"@rspress/plugin-medium-zoom": "0.
|
|
94
|
-
"@rspress/plugin-last-updated": "0.
|
|
95
|
-
"@rspress/plugin-auto-nav-sidebar": "0.
|
|
96
|
-
"@rspress/plugin-container-syntax": "0.
|
|
92
|
+
"@rspress/shared": "0.1.1",
|
|
93
|
+
"@rspress/plugin-medium-zoom": "0.1.1",
|
|
94
|
+
"@rspress/plugin-last-updated": "0.1.1",
|
|
95
|
+
"@rspress/plugin-auto-nav-sidebar": "0.1.1",
|
|
96
|
+
"@rspress/plugin-container-syntax": "0.1.1"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"react": ">=17"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
|
-
"@modern-js/plugin-tailwindcss": "2.35.
|
|
103
|
-
"@modern-js/plugin-testing": "2.35.
|
|
104
|
-
"@modern-js/tsconfig": "2.35.
|
|
105
|
-
"@modern-js/types": "2.35.
|
|
102
|
+
"@modern-js/plugin-tailwindcss": "2.35.1",
|
|
103
|
+
"@modern-js/plugin-testing": "2.35.1",
|
|
104
|
+
"@modern-js/tsconfig": "2.35.1",
|
|
105
|
+
"@modern-js/types": "2.35.1",
|
|
106
106
|
"@types/body-scroll-lock": "^3.1.0",
|
|
107
107
|
"@types/fs-extra": "^9.0.13",
|
|
108
108
|
"@types/hast": "^2.3.4",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
declare module 'virtual-routes' {
|
|
2
|
+
export { Route } from 'node/route/RouteService';
|
|
3
|
+
|
|
4
|
+
export const routes: Route[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare module 'virtual-routes-ssr' {
|
|
8
|
+
export { Route } from 'node/route/RouteService';
|
|
9
|
+
|
|
10
|
+
export const routes: Route[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module 'virtual-site-data' {
|
|
14
|
+
import { SiteData } from 'shared/types';
|
|
15
|
+
import ThemeConfig from 'shared/types/defaultTheme';
|
|
16
|
+
|
|
17
|
+
const data: SiteData<ThemeConfig>;
|
|
18
|
+
export default data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module 'virtual-search-index-hash' {
|
|
22
|
+
const hash: string;
|
|
23
|
+
export default hash;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare module 'virtual-global-components' {
|
|
27
|
+
import { ComponentType } from 'react';
|
|
28
|
+
|
|
29
|
+
const components: (ComponentType | [ComponentType, any])[];
|
|
30
|
+
export default components;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare module 'virtual-global-styles';
|
|
34
|
+
|
|
35
|
+
declare module 'virtual-i18n-text';
|
|
36
|
+
|
|
37
|
+
declare module 'virtual-search-hooks' {
|
|
38
|
+
export const onSearch: (query: string) => void | Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare module '*.module.scss' {
|
|
42
|
+
const classes: { [key: string]: string };
|
|
43
|
+
export default classes;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare module '*.svg' {
|
|
47
|
+
export const ReactComponent: React.SFC<React.SVGProps<SVGSVGElement>>;
|
|
48
|
+
export default ReactComponent;
|
|
49
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// Only appear on mobile
|
|
2
|
+
.rspress-sidebar-menu {
|
|
2
3
|
position: sticky;
|
|
3
4
|
top: 0;
|
|
4
5
|
left: 0;
|
|
@@ -11,7 +12,7 @@
|
|
|
11
12
|
color: var(--rp-c-text-1);
|
|
12
13
|
background-color: var(--rp-c-bg);
|
|
13
14
|
padding-left: 10px;
|
|
14
|
-
|
|
15
|
+
> button {
|
|
15
16
|
padding: 12px;
|
|
16
17
|
transition: color 0.5s;
|
|
17
18
|
&:hover {
|
|
@@ -20,15 +21,15 @@
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
@media (min-width: 960px) {
|
|
23
|
-
.
|
|
24
|
+
.rspress-sidebar-menu {
|
|
24
25
|
display: none;
|
|
25
26
|
}
|
|
26
|
-
.
|
|
27
|
+
.rspress-sidebar-back-drop {
|
|
27
28
|
display: none;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
.
|
|
32
|
+
.rspress-sidebar-back-drop {
|
|
32
33
|
position: fixed;
|
|
33
34
|
top: 0;
|
|
34
35
|
right: 0;
|
|
@@ -2,7 +2,7 @@ import { Fragment, useEffect, useState } from 'react';
|
|
|
2
2
|
import { NormalizedSidebarGroup, SidebarItem } from '@rspress/shared';
|
|
3
3
|
import { SideBar } from '../Sidebar';
|
|
4
4
|
import MenuIcon from '../../assets/menu.svg';
|
|
5
|
-
import
|
|
5
|
+
import './index.scss';
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
8
8
|
pathname: string;
|
|
@@ -27,8 +27,8 @@ export function SideMenu(props: Props) {
|
|
|
27
27
|
|
|
28
28
|
return (
|
|
29
29
|
<Fragment>
|
|
30
|
-
<div className=
|
|
31
|
-
<button onClick={openSidebar} className=
|
|
30
|
+
<div className="rspress-sidebar-menu">
|
|
31
|
+
<button onClick={openSidebar} className="flex-center">
|
|
32
32
|
<div className="text-md mr-2">
|
|
33
33
|
<MenuIcon />
|
|
34
34
|
</div>
|
|
@@ -42,7 +42,7 @@ export function SideMenu(props: Props) {
|
|
|
42
42
|
isSidebarOpen={isSidebarOpen}
|
|
43
43
|
/>
|
|
44
44
|
{isSidebarOpen ? (
|
|
45
|
-
<div onClick={closeSidebar} className=
|
|
45
|
+
<div onClick={closeSidebar} className="rspress-sidebar-back-drop" />
|
|
46
46
|
) : null}
|
|
47
47
|
</Fragment>
|
|
48
48
|
);
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { createPortal } from 'react-dom';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { groupBy, debounce } from 'lodash-es';
|
|
4
|
+
import { onSearch } from 'virtual-search-hooks';
|
|
5
|
+
import { SearchOptions } from '@rspress/shared';
|
|
6
|
+
import { getSidebarGroupData } from '../../logic/useSidebarData';
|
|
7
|
+
import { useLocaleSiteData } from '../../logic/useLocaleSiteData';
|
|
8
|
+
import { Tabs, Tab } from '../Tabs';
|
|
9
|
+
import styles from './index.module.scss';
|
|
10
|
+
import SearchSvg from './assets/search.svg';
|
|
11
|
+
import LoadingSvg from './assets/loading.svg';
|
|
12
|
+
import CloseSvg from './assets/close.svg';
|
|
13
|
+
import { MatchResult, MatchResultItem, PageSearcher } from './logic/search';
|
|
14
|
+
import { SuggestItem } from './SuggestItem';
|
|
15
|
+
import { normalizeSearchIndexes, removeDomain } from './logic/util';
|
|
16
|
+
import { NoSearchResult } from './NoSearchResult';
|
|
17
|
+
import { isProduction, usePageData } from '@/runtime';
|
|
18
|
+
|
|
19
|
+
const KEY_CODE = {
|
|
20
|
+
ARROW_UP: 'ArrowUp',
|
|
21
|
+
ARROW_DOWN: 'ArrowDown',
|
|
22
|
+
ENTER: 'Enter',
|
|
23
|
+
SEARCH: 'KeyK',
|
|
24
|
+
ESC: 'Escape',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const RECOMMEND_WORD: Record<string, string> = {
|
|
28
|
+
zh: '其它站点推荐结果',
|
|
29
|
+
en: 'Other Site Search Results',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export interface SearchPanelProps {
|
|
33
|
+
focused: boolean;
|
|
34
|
+
setFocused: (focused: boolean) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
|
|
38
|
+
const [query, setQuery] = useState('');
|
|
39
|
+
const [searchResult, setSearchResult] = useState<MatchResult>({
|
|
40
|
+
current: [],
|
|
41
|
+
others: [],
|
|
42
|
+
});
|
|
43
|
+
const searchInputRef = useRef<HTMLInputElement | null>(null);
|
|
44
|
+
const [initing, setIniting] = useState(true);
|
|
45
|
+
const [currentSuggestionIndex, setCurrentSuggestionIndex] = useState(0);
|
|
46
|
+
const pageSearcherRef = useRef<PageSearcher | null>(null);
|
|
47
|
+
const {
|
|
48
|
+
siteData,
|
|
49
|
+
page: { lang },
|
|
50
|
+
} = usePageData();
|
|
51
|
+
const { sidebar } = useLocaleSiteData();
|
|
52
|
+
const { search } = siteData;
|
|
53
|
+
|
|
54
|
+
const suggestions = [
|
|
55
|
+
...searchResult.current,
|
|
56
|
+
...searchResult.others.map(item => item.items),
|
|
57
|
+
].flat();
|
|
58
|
+
|
|
59
|
+
// We need to extract the group name by the link so that we can divide the search result into different groups.
|
|
60
|
+
const extractGroupName = (link: string) =>
|
|
61
|
+
getSidebarGroupData(sidebar, link).group;
|
|
62
|
+
|
|
63
|
+
async function initPageSearcher() {
|
|
64
|
+
if (search === false) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const pageSearcher = new PageSearcher({
|
|
68
|
+
...search,
|
|
69
|
+
currentLang: lang,
|
|
70
|
+
extractGroupName,
|
|
71
|
+
});
|
|
72
|
+
pageSearcherRef.current = pageSearcher;
|
|
73
|
+
await pageSearcherRef.current.init();
|
|
74
|
+
setIniting(false);
|
|
75
|
+
const query = searchInputRef.current?.value;
|
|
76
|
+
if (query) {
|
|
77
|
+
const matched = await pageSearcherRef.current?.match(query);
|
|
78
|
+
setSearchResult(matched || { current: [], others: [] });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
84
|
+
switch (e.code) {
|
|
85
|
+
case KEY_CODE.SEARCH:
|
|
86
|
+
if (e.ctrlKey || e.metaKey) {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
setFocused(!focused);
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
case KEY_CODE.ARROW_DOWN:
|
|
92
|
+
if (focused) {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
setCurrentSuggestionIndex(
|
|
95
|
+
(currentSuggestionIndex + 1) % suggestions.length,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
case KEY_CODE.ARROW_UP:
|
|
100
|
+
if (focused) {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
setCurrentSuggestionIndex(
|
|
103
|
+
(currentSuggestionIndex - 1 + suggestions.length) %
|
|
104
|
+
suggestions.length,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case KEY_CODE.ENTER:
|
|
109
|
+
if (currentSuggestionIndex >= 0) {
|
|
110
|
+
const suggestion = suggestions[currentSuggestionIndex];
|
|
111
|
+
const isCurrent =
|
|
112
|
+
currentSuggestionIndex < searchResult.current.length;
|
|
113
|
+
if (isCurrent) {
|
|
114
|
+
window.location.href = isProduction()
|
|
115
|
+
? suggestion.link
|
|
116
|
+
: removeDomain(suggestion.link);
|
|
117
|
+
setFocused(false);
|
|
118
|
+
} else {
|
|
119
|
+
window.open(suggestion.link);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
case KEY_CODE.ESC:
|
|
124
|
+
setFocused(false);
|
|
125
|
+
break;
|
|
126
|
+
default:
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
document.addEventListener('keydown', onKeyDown);
|
|
131
|
+
return () => {
|
|
132
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
133
|
+
};
|
|
134
|
+
}, [
|
|
135
|
+
setCurrentSuggestionIndex,
|
|
136
|
+
setFocused,
|
|
137
|
+
suggestions,
|
|
138
|
+
currentSuggestionIndex,
|
|
139
|
+
]);
|
|
140
|
+
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (focused) {
|
|
143
|
+
setSearchResult({ current: [], others: [] });
|
|
144
|
+
if (!pageSearcherRef.current) {
|
|
145
|
+
initPageSearcher();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}, [focused]);
|
|
149
|
+
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
!initing && initPageSearcher();
|
|
152
|
+
// init pageSearcher again when lang changed
|
|
153
|
+
}, [lang]);
|
|
154
|
+
|
|
155
|
+
const onQueryChanged = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
156
|
+
const newQuery = e.target.value;
|
|
157
|
+
setQuery(newQuery);
|
|
158
|
+
if (newQuery) {
|
|
159
|
+
await onSearch(newQuery);
|
|
160
|
+
const matched = await pageSearcherRef.current?.match(newQuery);
|
|
161
|
+
setSearchResult(matched || { current: [], others: [] });
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const normalizeSuggestions = (suggestions: MatchResultItem[]) =>
|
|
166
|
+
groupBy(suggestions, 'group');
|
|
167
|
+
|
|
168
|
+
// accumulateIndex is used to calculate the index of the suggestion in the whole list.
|
|
169
|
+
let accumulateIndex = -1;
|
|
170
|
+
|
|
171
|
+
const renderSearchResult = (
|
|
172
|
+
result: MatchResult,
|
|
173
|
+
searchOptions: SearchOptions,
|
|
174
|
+
) => {
|
|
175
|
+
if (!suggestions.length && !initing) {
|
|
176
|
+
return <NoSearchResult query={query} />;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const hasOtherResult =
|
|
180
|
+
searchResult.others.map(item => item.items).flat().length > 0;
|
|
181
|
+
|
|
182
|
+
const tabValues = result.others.map(item => {
|
|
183
|
+
if (!searchOptions || searchOptions.mode !== 'remote') {
|
|
184
|
+
return item;
|
|
185
|
+
}
|
|
186
|
+
const indexItem = normalizeSearchIndexes(
|
|
187
|
+
searchOptions.searchIndexes || [],
|
|
188
|
+
).find(indexInfo => indexInfo.value === item.index);
|
|
189
|
+
return indexItem.label;
|
|
190
|
+
}) as string[];
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<div>
|
|
194
|
+
{/* current index */}
|
|
195
|
+
{renderSearchResultItem(result.current)}
|
|
196
|
+
{/* other indexes */}
|
|
197
|
+
{hasOtherResult && (
|
|
198
|
+
<h2 className={styles.groupTitle}>{RECOMMEND_WORD[lang]}</h2>
|
|
199
|
+
)}
|
|
200
|
+
<div style={{ marginTop: '-12px' }}>
|
|
201
|
+
<Tabs values={tabValues} tabContainerClassName={styles.tabClassName}>
|
|
202
|
+
{result.others.map(item => (
|
|
203
|
+
<Tab key={item.index}>
|
|
204
|
+
{renderSearchResultItem(item.items, false)}
|
|
205
|
+
</Tab>
|
|
206
|
+
))}
|
|
207
|
+
</Tabs>
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const renderSearchResultItem = (
|
|
214
|
+
suggestionList: MatchResultItem[],
|
|
215
|
+
isCurrent = true,
|
|
216
|
+
) => {
|
|
217
|
+
// if no result, show no result
|
|
218
|
+
if (suggestionList.length === 0 && !initing) {
|
|
219
|
+
return (
|
|
220
|
+
<div className="mt-4 flex-center">
|
|
221
|
+
<div
|
|
222
|
+
className="p-2 font-bold text-md"
|
|
223
|
+
style={{
|
|
224
|
+
color: '#2c3e50',
|
|
225
|
+
}}
|
|
226
|
+
>
|
|
227
|
+
No results found
|
|
228
|
+
</div>
|
|
229
|
+
</div>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
const normalizedSuggestions = normalizeSuggestions(suggestionList);
|
|
233
|
+
return (
|
|
234
|
+
<ul className={styles.suggestList}>
|
|
235
|
+
{Object.keys(normalizedSuggestions).map(group => {
|
|
236
|
+
const groupSuggestions = normalizedSuggestions[group] || [];
|
|
237
|
+
return (
|
|
238
|
+
<li key={group}>
|
|
239
|
+
{isCurrent && <h2 className={styles.groupTitle}>{group}</h2>}
|
|
240
|
+
<ul className="pb-2">
|
|
241
|
+
{groupSuggestions.map(suggestion => {
|
|
242
|
+
accumulateIndex++;
|
|
243
|
+
const suggestionIndex = accumulateIndex;
|
|
244
|
+
return (
|
|
245
|
+
<SuggestItem
|
|
246
|
+
key={`${suggestion.title}-${suggestionIndex}`}
|
|
247
|
+
suggestion={suggestion}
|
|
248
|
+
isCurrent={suggestionIndex === currentSuggestionIndex}
|
|
249
|
+
setCurrentSuggestionIndex={() => {
|
|
250
|
+
setCurrentSuggestionIndex(suggestionIndex);
|
|
251
|
+
}}
|
|
252
|
+
closeSearch={() => setFocused(false)}
|
|
253
|
+
inCurrentDocIndex={
|
|
254
|
+
suggestionIndex < searchResult.current.length
|
|
255
|
+
}
|
|
256
|
+
/>
|
|
257
|
+
);
|
|
258
|
+
})}
|
|
259
|
+
</ul>
|
|
260
|
+
</li>
|
|
261
|
+
);
|
|
262
|
+
})}
|
|
263
|
+
</ul>
|
|
264
|
+
);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<>
|
|
269
|
+
{focused &&
|
|
270
|
+
createPortal(
|
|
271
|
+
<div className={styles.mask} onClick={() => setFocused(false)}>
|
|
272
|
+
<div
|
|
273
|
+
className={`${styles.modal}`}
|
|
274
|
+
onClick={e => {
|
|
275
|
+
setFocused(true);
|
|
276
|
+
e.stopPropagation();
|
|
277
|
+
}}
|
|
278
|
+
>
|
|
279
|
+
<div className="flex items-center">
|
|
280
|
+
<div className={styles.inputForm}>
|
|
281
|
+
<label>
|
|
282
|
+
<SearchSvg />
|
|
283
|
+
</label>
|
|
284
|
+
<input
|
|
285
|
+
className={styles.input}
|
|
286
|
+
ref={searchInputRef}
|
|
287
|
+
placeholder="Search Docs"
|
|
288
|
+
aria-label="Search"
|
|
289
|
+
autoComplete="off"
|
|
290
|
+
autoFocus
|
|
291
|
+
onChange={debounce(onQueryChanged, 150)}
|
|
292
|
+
/>
|
|
293
|
+
<label>
|
|
294
|
+
<CloseSvg
|
|
295
|
+
className={styles.close}
|
|
296
|
+
onClick={e => {
|
|
297
|
+
if (searchInputRef.current) {
|
|
298
|
+
e.stopPropagation();
|
|
299
|
+
if (!query) {
|
|
300
|
+
setFocused(false);
|
|
301
|
+
} else {
|
|
302
|
+
searchInputRef.current.value = '';
|
|
303
|
+
setQuery('');
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}}
|
|
307
|
+
/>
|
|
308
|
+
</label>
|
|
309
|
+
</div>
|
|
310
|
+
<h2
|
|
311
|
+
className="text-brand ml-2 sm:hidden cursor-pointer"
|
|
312
|
+
onClick={e => {
|
|
313
|
+
e.stopPropagation();
|
|
314
|
+
setFocused(false);
|
|
315
|
+
}}
|
|
316
|
+
>
|
|
317
|
+
Cancel
|
|
318
|
+
</h2>
|
|
319
|
+
</div>
|
|
320
|
+
|
|
321
|
+
{query ? (
|
|
322
|
+
<div className={`${styles.searchHits} rspress-scrollbar`}>
|
|
323
|
+
{renderSearchResult(searchResult, search)}
|
|
324
|
+
</div>
|
|
325
|
+
) : null}
|
|
326
|
+
{initing && (
|
|
327
|
+
<div className="flex-center">
|
|
328
|
+
<div className="p-2 text-sm">
|
|
329
|
+
<LoadingSvg />
|
|
330
|
+
</div>
|
|
331
|
+
</div>
|
|
332
|
+
)}
|
|
333
|
+
</div>
|
|
334
|
+
</div>,
|
|
335
|
+
document.getElementById('search-container')!,
|
|
336
|
+
)}
|
|
337
|
+
</>
|
|
338
|
+
);
|
|
339
|
+
}
|