@rspress/core 1.2.0 → 1.3.0
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.d.ts +2 -0
- package/dist/index.js +53 -40
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js.map +1 -1
- package/dist/runtime/App.js +8 -4
- package/dist/runtime/clientEntry.js +7 -4
- package/dist/runtime/ssrEntry.js +2 -2
- package/package.json +19 -15
- package/runtime.ts +1 -1
- package/src/runtime/App.tsx +8 -4
- package/src/runtime/clientEntry.tsx +7 -4
- package/src/runtime/ssrEntry.tsx +2 -2
- package/theme.ts +2 -2
- package/dist/runtime/Content.d.ts +0 -6
- package/dist/runtime/Content.js +0 -33
- package/dist/runtime/NoSSR.d.ts +0 -4
- package/dist/runtime/NoSSR.js +0 -17
- package/dist/runtime/hooks.d.ts +0 -39
- package/dist/runtime/hooks.js +0 -54
- package/dist/runtime/index.d.ts +0 -6
- package/dist/runtime/index.js +0 -34
- package/dist/runtime/utils.d.ts +0 -8
- package/dist/runtime/utils.js +0 -45
- package/dist/theme/bundle.css +0 -2691
- package/dist/theme/bundle.d.ts +0 -176
- package/dist/theme/bundle.js +0 -4433
- package/dist/theme/bundle.js.map +0 -1
- package/dist/theme/index.js +0 -6
- package/src/runtime/Content.tsx +0 -43
- package/src/runtime/NoSSR.tsx +0 -16
- package/src/runtime/hooks.ts +0 -110
- package/src/runtime/index.ts +0 -17
- package/src/runtime/utils.ts +0 -46
- package/src/theme-default/assets/arrow-down.svg +0 -1
- package/src/theme-default/assets/arrow-right.svg +0 -1
- package/src/theme-default/assets/copy.svg +0 -1
- package/src/theme-default/assets/down.svg +0 -1
- package/src/theme-default/assets/github.svg +0 -1
- package/src/theme-default/assets/loading.svg +0 -1
- package/src/theme-default/assets/menu.svg +0 -1
- package/src/theme-default/assets/moon.svg +0 -3
- package/src/theme-default/assets/right.svg +0 -1
- package/src/theme-default/assets/small-menu.svg +0 -1
- package/src/theme-default/assets/success.svg +0 -1
- package/src/theme-default/assets/sun.svg +0 -11
- package/src/theme-default/assets/translator.svg +0 -1
- package/src/theme-default/components/Aside/index.css +0 -22
- package/src/theme-default/components/Aside/index.tsx +0 -75
- package/src/theme-default/components/BackDrop/index.module.scss +0 -14
- package/src/theme-default/components/BackDrop/index.tsx +0 -13
- package/src/theme-default/components/Button/index.module.scss +0 -68
- package/src/theme-default/components/Button/index.tsx +0 -40
- package/src/theme-default/components/DocFooter/index.module.scss +0 -60
- package/src/theme-default/components/DocFooter/index.tsx +0 -66
- package/src/theme-default/components/EditLink/index.module.scss +0 -11
- package/src/theme-default/components/EditLink/index.tsx +0 -18
- package/src/theme-default/components/HomeFeatures/index.module.scss +0 -50
- package/src/theme-default/components/HomeFeatures/index.tsx +0 -65
- package/src/theme-default/components/HomeFooter/index.tsx +0 -15
- package/src/theme-default/components/HomeHero/index.module.scss +0 -42
- package/src/theme-default/components/HomeHero/index.tsx +0 -75
- package/src/theme-default/components/Link/index.module.scss +0 -9
- package/src/theme-default/components/Link/index.tsx +0 -90
- package/src/theme-default/components/LocalSideBar/index.scss +0 -40
- package/src/theme-default/components/LocalSideBar/index.tsx +0 -39
- package/src/theme-default/components/Nav/NavBarTitle.tsx +0 -43
- package/src/theme-default/components/Nav/NavMenuGroup.tsx +0 -156
- package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +0 -40
- package/src/theme-default/components/Nav/NavTranslations.tsx +0 -16
- package/src/theme-default/components/Nav/NavVersions.tsx +0 -16
- package/src/theme-default/components/Nav/index.module.scss +0 -115
- package/src/theme-default/components/Nav/index.tsx +0 -150
- package/src/theme-default/components/Nav/menuDataHooks.tsx +0 -75
- package/src/theme-default/components/NavHambmger/index.module.scss +0 -81
- package/src/theme-default/components/NavHambmger/index.tsx +0 -39
- package/src/theme-default/components/NavScreen/NavScreenMenuGroup.tsx +0 -95
- package/src/theme-default/components/NavScreen/index.module.scss +0 -88
- package/src/theme-default/components/NavScreen/index.tsx +0 -123
- package/src/theme-default/components/Overview/index.module.scss +0 -154
- package/src/theme-default/components/Overview/index.tsx +0 -136
- package/src/theme-default/components/PackageManagerTabs/icons/Bun.tsx +0 -101
- package/src/theme-default/components/PackageManagerTabs/icons/Npm.tsx +0 -16
- package/src/theme-default/components/PackageManagerTabs/icons/Pnpm.tsx +0 -22
- package/src/theme-default/components/PackageManagerTabs/icons/Yarn.tsx +0 -18
- package/src/theme-default/components/PackageManagerTabs/index.scss +0 -5
- package/src/theme-default/components/PackageManagerTabs/index.tsx +0 -110
- package/src/theme-default/components/Search/NoSearchResult.tsx +0 -13
- package/src/theme-default/components/Search/SearchPanel.tsx +0 -340
- package/src/theme-default/components/Search/SuggestItem.tsx +0 -135
- package/src/theme-default/components/Search/assets/close.svg +0 -1
- package/src/theme-default/components/Search/assets/file.svg +0 -1
- package/src/theme-default/components/Search/assets/header.svg +0 -1
- package/src/theme-default/components/Search/assets/jump.svg +0 -1
- package/src/theme-default/components/Search/assets/loading.svg +0 -1
- package/src/theme-default/components/Search/assets/search.svg +0 -1
- package/src/theme-default/components/Search/assets/title.svg +0 -1
- package/src/theme-default/components/Search/empty.svg +0 -4
- package/src/theme-default/components/Search/index.module.scss +0 -236
- package/src/theme-default/components/Search/index.tsx +0 -39
- package/src/theme-default/components/Search/logic/Provider.ts +0 -35
- package/src/theme-default/components/Search/logic/providers/LocalProvider.ts +0 -102
- package/src/theme-default/components/Search/logic/providers/RemoteProvider.ts +0 -40
- package/src/theme-default/components/Search/logic/search.ts +0 -341
- package/src/theme-default/components/Search/logic/util.test.ts +0 -21
- package/src/theme-default/components/Search/logic/util.ts +0 -127
- package/src/theme-default/components/Sidebar/SidebarGroup.tsx +0 -180
- package/src/theme-default/components/Sidebar/SidebarItem.tsx +0 -61
- package/src/theme-default/components/Sidebar/index.module.scss +0 -142
- package/src/theme-default/components/Sidebar/index.tsx +0 -156
- package/src/theme-default/components/SocialLinks/HiddenLinks.tsx +0 -30
- package/src/theme-default/components/SocialLinks/LinkContent.tsx +0 -90
- package/src/theme-default/components/SocialLinks/ShownLinks.tsx +0 -32
- package/src/theme-default/components/SocialLinks/index.module.scss +0 -18
- package/src/theme-default/components/SocialLinks/index.tsx +0 -36
- package/src/theme-default/components/SocialLinks/presetIcons.tsx +0 -165
- package/src/theme-default/components/SwitchAppearance/index.module.scss +0 -15
- package/src/theme-default/components/SwitchAppearance/index.tsx +0 -35
- package/src/theme-default/components/Tabs/index.module.scss +0 -46
- package/src/theme-default/components/Tabs/index.tsx +0 -123
- package/src/theme-default/components/Tag/index.tsx +0 -18
- package/src/theme-default/components/Toc/index.css +0 -18
- package/src/theme-default/components/Toc/index.tsx +0 -42
- package/src/theme-default/index.ts +0 -26
- package/src/theme-default/layout/DocLayout/docComponents/code.tsx +0 -112
- package/src/theme-default/layout/DocLayout/docComponents/hr.tsx +0 -10
- package/src/theme-default/layout/DocLayout/docComponents/index.module.scss +0 -69
- package/src/theme-default/layout/DocLayout/docComponents/index.tsx +0 -33
- package/src/theme-default/layout/DocLayout/docComponents/link.tsx +0 -22
- package/src/theme-default/layout/DocLayout/docComponents/list.tsx +0 -13
- package/src/theme-default/layout/DocLayout/docComponents/paragraph.tsx +0 -19
- package/src/theme-default/layout/DocLayout/docComponents/pre.tsx +0 -37
- package/src/theme-default/layout/DocLayout/docComponents/prisim-theme.ts +0 -73
- package/src/theme-default/layout/DocLayout/docComponents/table.tsx +0 -37
- package/src/theme-default/layout/DocLayout/docComponents/title.tsx +0 -40
- package/src/theme-default/layout/DocLayout/index.module.scss +0 -138
- package/src/theme-default/layout/DocLayout/index.tsx +0 -125
- package/src/theme-default/layout/HomeLayout/index.css +0 -18
- package/src/theme-default/layout/HomeLayout/index.tsx +0 -39
- package/src/theme-default/layout/Layout/index.tsx +0 -176
- package/src/theme-default/layout/NotFountLayout/index.tsx +0 -40
- package/src/theme-default/logic/TabDataContext.ts +0 -14
- package/src/theme-default/logic/index.ts +0 -8
- package/src/theme-default/logic/sideEffects.ts +0 -174
- package/src/theme-default/logic/useAppearance.ts +0 -57
- package/src/theme-default/logic/useEditLink.ts +0 -33
- package/src/theme-default/logic/useHiddenNav.ts +0 -58
- package/src/theme-default/logic/useLocaleSiteData.ts +0 -26
- package/src/theme-default/logic/useNav.ts +0 -36
- package/src/theme-default/logic/usePathUtils.ts +0 -73
- package/src/theme-default/logic/usePrevNextPage.ts +0 -40
- package/src/theme-default/logic/useSidebarData.ts +0 -73
- package/src/theme-default/logic/utils.ts +0 -38
- package/src/theme-default/styles/base.css +0 -102
- package/src/theme-default/styles/code.css +0 -177
- package/src/theme-default/styles/index.ts +0 -7
- package/src/theme-default/styles/scrollbar.css +0 -28
- package/src/theme-default/styles/vars.css +0 -81
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { Tabs, Tab } from '../Tabs';
|
|
2
|
-
import { Pre } from '../../layout/DocLayout/docComponents/pre';
|
|
3
|
-
import { Code } from '../../layout/DocLayout/docComponents/code';
|
|
4
|
-
import { Npm } from './icons/Npm';
|
|
5
|
-
import { Yarn } from './icons/Yarn';
|
|
6
|
-
import { Pnpm } from './icons/Pnpm';
|
|
7
|
-
import { Bun } from './icons/Bun';
|
|
8
|
-
import './index.scss';
|
|
9
|
-
|
|
10
|
-
export interface PackageManagerTabProps {
|
|
11
|
-
command:
|
|
12
|
-
| string
|
|
13
|
-
| {
|
|
14
|
-
npm: string;
|
|
15
|
-
yarn: string;
|
|
16
|
-
pnpm: string;
|
|
17
|
-
bun: string;
|
|
18
|
-
};
|
|
19
|
-
additionalTabs?: {
|
|
20
|
-
tool: string;
|
|
21
|
-
icon?: React.ReactNode;
|
|
22
|
-
}[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function normalizeCommand(command: string): string {
|
|
26
|
-
if (!command.includes('install')) {
|
|
27
|
-
return command;
|
|
28
|
-
}
|
|
29
|
-
// If command include `install` and package name, replace `install` with `add`
|
|
30
|
-
const pureCommand = command
|
|
31
|
-
.split(' ')
|
|
32
|
-
.filter(item => !item.startsWith('-') && !item.startsWith('--'))
|
|
33
|
-
.join(' ');
|
|
34
|
-
if (pureCommand === 'yarn install' || pureCommand === 'bun install') {
|
|
35
|
-
return command;
|
|
36
|
-
} else {
|
|
37
|
-
return command.replace('install', 'add');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function PackageManagerTabs({
|
|
42
|
-
command,
|
|
43
|
-
additionalTabs = [],
|
|
44
|
-
}: PackageManagerTabProps) {
|
|
45
|
-
let commandInfo: {
|
|
46
|
-
npm: string;
|
|
47
|
-
yarn: string;
|
|
48
|
-
pnpm: string;
|
|
49
|
-
bun: string;
|
|
50
|
-
[key: string]: string;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// Init Icons
|
|
54
|
-
const packageMangerToIcon = {
|
|
55
|
-
npm: <Npm />,
|
|
56
|
-
yarn: <Yarn />,
|
|
57
|
-
pnpm: <Pnpm />,
|
|
58
|
-
bun: <Bun />,
|
|
59
|
-
};
|
|
60
|
-
additionalTabs.forEach(tab => {
|
|
61
|
-
packageMangerToIcon[tab.tool] = tab.icon;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Init Command
|
|
65
|
-
if (typeof command === 'string') {
|
|
66
|
-
commandInfo = {
|
|
67
|
-
npm: `npm ${command}`,
|
|
68
|
-
yarn: `yarn ${command}`,
|
|
69
|
-
pnpm: `pnpm ${command}`,
|
|
70
|
-
bun: `bun ${command}`,
|
|
71
|
-
};
|
|
72
|
-
additionalTabs.forEach(tab => {
|
|
73
|
-
commandInfo[tab.tool] = `${tab.tool} ${command}`;
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
commandInfo = command;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Normalize yarn/bun command
|
|
80
|
-
commandInfo.yarn = normalizeCommand(commandInfo.yarn);
|
|
81
|
-
commandInfo.bun = normalizeCommand(commandInfo.bun);
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<Tabs
|
|
85
|
-
values={Object.entries(commandInfo).map(([key]) => (
|
|
86
|
-
<div
|
|
87
|
-
key={key}
|
|
88
|
-
style={{
|
|
89
|
-
display: 'flex',
|
|
90
|
-
alignItems: 'center',
|
|
91
|
-
fontSize: 15,
|
|
92
|
-
}}
|
|
93
|
-
>
|
|
94
|
-
{packageMangerToIcon[key]}
|
|
95
|
-
<span style={{ marginLeft: 6, marginBottom: 2 }}>{key}</span>
|
|
96
|
-
</div>
|
|
97
|
-
))}
|
|
98
|
-
>
|
|
99
|
-
{Object.entries(commandInfo).map(([key, value]) => (
|
|
100
|
-
<Tab key={key}>
|
|
101
|
-
<Pre>
|
|
102
|
-
<Code className="language-js">{value}</Code>
|
|
103
|
-
</Pre>
|
|
104
|
-
</Tab>
|
|
105
|
-
))}
|
|
106
|
-
</Tabs>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export { Tab } from '@theme';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Empty from './empty.svg';
|
|
2
|
-
|
|
3
|
-
export function NoSearchResult({ query }: { query: string }) {
|
|
4
|
-
return (
|
|
5
|
-
<div className="flex flex-col items-center pt-8 pb-2">
|
|
6
|
-
<Empty className="mb-4 opacity-80" />
|
|
7
|
-
<p className="mb-2">
|
|
8
|
-
No results for <b>"{query}"</b>.
|
|
9
|
-
</p>
|
|
10
|
-
<p>Please try again with a different keyword.</p>
|
|
11
|
-
</div>
|
|
12
|
-
);
|
|
13
|
-
}
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-lines */
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
3
|
-
import { useEffect, useRef, useState } from 'react';
|
|
4
|
-
import { groupBy, debounce } from 'lodash-es';
|
|
5
|
-
import { onSearch } from 'virtual-search-hooks';
|
|
6
|
-
import { SearchOptions } from '@rspress/shared';
|
|
7
|
-
import { getSidebarGroupData } from '../../logic/useSidebarData';
|
|
8
|
-
import { useLocaleSiteData } from '../../logic/useLocaleSiteData';
|
|
9
|
-
import { Tabs, Tab } from '../Tabs';
|
|
10
|
-
import styles from './index.module.scss';
|
|
11
|
-
import SearchSvg from './assets/search.svg';
|
|
12
|
-
import LoadingSvg from './assets/loading.svg';
|
|
13
|
-
import CloseSvg from './assets/close.svg';
|
|
14
|
-
import { MatchResult, MatchResultItem, PageSearcher } from './logic/search';
|
|
15
|
-
import { SuggestItem } from './SuggestItem';
|
|
16
|
-
import { normalizeSearchIndexes, removeDomain } from './logic/util';
|
|
17
|
-
import { NoSearchResult } from './NoSearchResult';
|
|
18
|
-
import { isProduction, usePageData } from '@/runtime';
|
|
19
|
-
|
|
20
|
-
const KEY_CODE = {
|
|
21
|
-
ARROW_UP: 'ArrowUp',
|
|
22
|
-
ARROW_DOWN: 'ArrowDown',
|
|
23
|
-
ENTER: 'Enter',
|
|
24
|
-
SEARCH: 'KeyK',
|
|
25
|
-
ESC: 'Escape',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const RECOMMEND_WORD: Record<string, string> = {
|
|
29
|
-
zh: '其它站点推荐结果',
|
|
30
|
-
en: 'Other Site Search Results',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export interface SearchPanelProps {
|
|
34
|
-
focused: boolean;
|
|
35
|
-
setFocused: (focused: boolean) => void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
|
|
39
|
-
const [query, setQuery] = useState('');
|
|
40
|
-
const [searchResult, setSearchResult] = useState<MatchResult>({
|
|
41
|
-
current: [],
|
|
42
|
-
others: [],
|
|
43
|
-
});
|
|
44
|
-
const searchInputRef = useRef<HTMLInputElement | null>(null);
|
|
45
|
-
const [initing, setIniting] = useState(true);
|
|
46
|
-
const [currentSuggestionIndex, setCurrentSuggestionIndex] = useState(0);
|
|
47
|
-
const pageSearcherRef = useRef<PageSearcher | null>(null);
|
|
48
|
-
const {
|
|
49
|
-
siteData,
|
|
50
|
-
page: { lang },
|
|
51
|
-
} = usePageData();
|
|
52
|
-
const { sidebar } = useLocaleSiteData();
|
|
53
|
-
const { search } = siteData;
|
|
54
|
-
|
|
55
|
-
const suggestions = [
|
|
56
|
-
...searchResult.current,
|
|
57
|
-
...searchResult.others.map(item => item.items),
|
|
58
|
-
].flat();
|
|
59
|
-
|
|
60
|
-
// We need to extract the group name by the link so that we can divide the search result into different groups.
|
|
61
|
-
const extractGroupName = (link: string) =>
|
|
62
|
-
getSidebarGroupData(sidebar, link).group;
|
|
63
|
-
|
|
64
|
-
async function initPageSearcher() {
|
|
65
|
-
if (search === false) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const pageSearcher = new PageSearcher({
|
|
69
|
-
...search,
|
|
70
|
-
currentLang: lang,
|
|
71
|
-
extractGroupName,
|
|
72
|
-
});
|
|
73
|
-
pageSearcherRef.current = pageSearcher;
|
|
74
|
-
await pageSearcherRef.current.init();
|
|
75
|
-
setIniting(false);
|
|
76
|
-
const query = searchInputRef.current?.value;
|
|
77
|
-
if (query) {
|
|
78
|
-
const matched = await pageSearcherRef.current?.match(query);
|
|
79
|
-
setSearchResult(matched || { current: [], others: [] });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
const onKeyDown = (e: KeyboardEvent) => {
|
|
85
|
-
switch (e.code) {
|
|
86
|
-
case KEY_CODE.SEARCH:
|
|
87
|
-
if (e.ctrlKey || e.metaKey) {
|
|
88
|
-
e.preventDefault();
|
|
89
|
-
setFocused(!focused);
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
case KEY_CODE.ARROW_DOWN:
|
|
93
|
-
if (focused) {
|
|
94
|
-
e.preventDefault();
|
|
95
|
-
setCurrentSuggestionIndex(
|
|
96
|
-
(currentSuggestionIndex + 1) % suggestions.length,
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
break;
|
|
100
|
-
case KEY_CODE.ARROW_UP:
|
|
101
|
-
if (focused) {
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
setCurrentSuggestionIndex(
|
|
104
|
-
(currentSuggestionIndex - 1 + suggestions.length) %
|
|
105
|
-
suggestions.length,
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
case KEY_CODE.ENTER:
|
|
110
|
-
if (currentSuggestionIndex >= 0) {
|
|
111
|
-
const suggestion = suggestions[currentSuggestionIndex];
|
|
112
|
-
const isCurrent =
|
|
113
|
-
currentSuggestionIndex < searchResult.current.length;
|
|
114
|
-
if (isCurrent) {
|
|
115
|
-
window.location.href = isProduction()
|
|
116
|
-
? suggestion.link
|
|
117
|
-
: removeDomain(suggestion.link);
|
|
118
|
-
setFocused(false);
|
|
119
|
-
} else {
|
|
120
|
-
window.open(suggestion.link);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
break;
|
|
124
|
-
case KEY_CODE.ESC:
|
|
125
|
-
setFocused(false);
|
|
126
|
-
break;
|
|
127
|
-
default:
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
document.addEventListener('keydown', onKeyDown);
|
|
132
|
-
return () => {
|
|
133
|
-
document.removeEventListener('keydown', onKeyDown);
|
|
134
|
-
};
|
|
135
|
-
}, [
|
|
136
|
-
setCurrentSuggestionIndex,
|
|
137
|
-
setFocused,
|
|
138
|
-
suggestions,
|
|
139
|
-
currentSuggestionIndex,
|
|
140
|
-
]);
|
|
141
|
-
|
|
142
|
-
useEffect(() => {
|
|
143
|
-
if (focused) {
|
|
144
|
-
setSearchResult({ current: [], others: [] });
|
|
145
|
-
if (!pageSearcherRef.current) {
|
|
146
|
-
initPageSearcher();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}, [focused]);
|
|
150
|
-
|
|
151
|
-
useEffect(() => {
|
|
152
|
-
!initing && initPageSearcher();
|
|
153
|
-
// init pageSearcher again when lang changed
|
|
154
|
-
}, [lang]);
|
|
155
|
-
|
|
156
|
-
const onQueryChanged = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
157
|
-
const newQuery = e.target.value;
|
|
158
|
-
setQuery(newQuery);
|
|
159
|
-
if (newQuery) {
|
|
160
|
-
await onSearch(newQuery);
|
|
161
|
-
const matched = await pageSearcherRef.current?.match(newQuery);
|
|
162
|
-
setSearchResult(matched || { current: [], others: [] });
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const normalizeSuggestions = (suggestions: MatchResultItem[]) =>
|
|
167
|
-
groupBy(suggestions, 'group');
|
|
168
|
-
|
|
169
|
-
// accumulateIndex is used to calculate the index of the suggestion in the whole list.
|
|
170
|
-
let accumulateIndex = -1;
|
|
171
|
-
|
|
172
|
-
const renderSearchResult = (
|
|
173
|
-
result: MatchResult,
|
|
174
|
-
searchOptions: SearchOptions,
|
|
175
|
-
) => {
|
|
176
|
-
if (!suggestions.length && !initing) {
|
|
177
|
-
return <NoSearchResult query={query} />;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const hasOtherResult =
|
|
181
|
-
searchResult.others.map(item => item.items).flat().length > 0;
|
|
182
|
-
|
|
183
|
-
const tabValues = result.others.map(item => {
|
|
184
|
-
if (!searchOptions || searchOptions.mode !== 'remote') {
|
|
185
|
-
return item;
|
|
186
|
-
}
|
|
187
|
-
const indexItem = normalizeSearchIndexes(
|
|
188
|
-
searchOptions.searchIndexes || [],
|
|
189
|
-
).find(indexInfo => indexInfo.value === item.index);
|
|
190
|
-
return indexItem.label;
|
|
191
|
-
}) as string[];
|
|
192
|
-
|
|
193
|
-
return (
|
|
194
|
-
<div>
|
|
195
|
-
{/* current index */}
|
|
196
|
-
{renderSearchResultItem(result.current)}
|
|
197
|
-
{/* other indexes */}
|
|
198
|
-
{hasOtherResult && (
|
|
199
|
-
<h2 className={styles.groupTitle}>{RECOMMEND_WORD[lang]}</h2>
|
|
200
|
-
)}
|
|
201
|
-
<div style={{ marginTop: '-12px' }}>
|
|
202
|
-
<Tabs values={tabValues} tabContainerClassName={styles.tabClassName}>
|
|
203
|
-
{result.others.map(item => (
|
|
204
|
-
<Tab key={item.index}>
|
|
205
|
-
{renderSearchResultItem(item.items, false)}
|
|
206
|
-
</Tab>
|
|
207
|
-
))}
|
|
208
|
-
</Tabs>
|
|
209
|
-
</div>
|
|
210
|
-
</div>
|
|
211
|
-
);
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
const renderSearchResultItem = (
|
|
215
|
-
suggestionList: MatchResultItem[],
|
|
216
|
-
isCurrent = true,
|
|
217
|
-
) => {
|
|
218
|
-
// if no result, show no result
|
|
219
|
-
if (suggestionList.length === 0 && !initing) {
|
|
220
|
-
return (
|
|
221
|
-
<div className="mt-4 flex-center">
|
|
222
|
-
<div
|
|
223
|
-
className="p-2 font-bold text-md"
|
|
224
|
-
style={{
|
|
225
|
-
color: '#2c3e50',
|
|
226
|
-
}}
|
|
227
|
-
>
|
|
228
|
-
No results found
|
|
229
|
-
</div>
|
|
230
|
-
</div>
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
const normalizedSuggestions = normalizeSuggestions(suggestionList);
|
|
234
|
-
return (
|
|
235
|
-
<ul className={styles.suggestList}>
|
|
236
|
-
{Object.keys(normalizedSuggestions).map(group => {
|
|
237
|
-
const groupSuggestions = normalizedSuggestions[group] || [];
|
|
238
|
-
return (
|
|
239
|
-
<li key={group}>
|
|
240
|
-
{isCurrent && <h2 className={styles.groupTitle}>{group}</h2>}
|
|
241
|
-
<ul className="pb-2">
|
|
242
|
-
{groupSuggestions.map(suggestion => {
|
|
243
|
-
accumulateIndex++;
|
|
244
|
-
const suggestionIndex = accumulateIndex;
|
|
245
|
-
return (
|
|
246
|
-
<SuggestItem
|
|
247
|
-
key={`${suggestion.title}-${suggestionIndex}`}
|
|
248
|
-
suggestion={suggestion}
|
|
249
|
-
isCurrent={suggestionIndex === currentSuggestionIndex}
|
|
250
|
-
setCurrentSuggestionIndex={() => {
|
|
251
|
-
setCurrentSuggestionIndex(suggestionIndex);
|
|
252
|
-
}}
|
|
253
|
-
closeSearch={() => setFocused(false)}
|
|
254
|
-
inCurrentDocIndex={
|
|
255
|
-
suggestionIndex < searchResult.current.length
|
|
256
|
-
}
|
|
257
|
-
/>
|
|
258
|
-
);
|
|
259
|
-
})}
|
|
260
|
-
</ul>
|
|
261
|
-
</li>
|
|
262
|
-
);
|
|
263
|
-
})}
|
|
264
|
-
</ul>
|
|
265
|
-
);
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
return (
|
|
269
|
-
<>
|
|
270
|
-
{focused &&
|
|
271
|
-
createPortal(
|
|
272
|
-
<div className={styles.mask} onClick={() => setFocused(false)}>
|
|
273
|
-
<div
|
|
274
|
-
className={`${styles.modal}`}
|
|
275
|
-
onClick={e => {
|
|
276
|
-
setFocused(true);
|
|
277
|
-
e.stopPropagation();
|
|
278
|
-
}}
|
|
279
|
-
>
|
|
280
|
-
<div className="flex items-center">
|
|
281
|
-
<div className={styles.inputForm}>
|
|
282
|
-
<label>
|
|
283
|
-
<SearchSvg />
|
|
284
|
-
</label>
|
|
285
|
-
<input
|
|
286
|
-
className={styles.input}
|
|
287
|
-
ref={searchInputRef}
|
|
288
|
-
placeholder="Search Docs"
|
|
289
|
-
aria-label="Search"
|
|
290
|
-
autoComplete="off"
|
|
291
|
-
autoFocus
|
|
292
|
-
onChange={debounce(onQueryChanged, 150)}
|
|
293
|
-
/>
|
|
294
|
-
<label>
|
|
295
|
-
<CloseSvg
|
|
296
|
-
className={styles.close}
|
|
297
|
-
onClick={e => {
|
|
298
|
-
if (searchInputRef.current) {
|
|
299
|
-
e.stopPropagation();
|
|
300
|
-
if (!query) {
|
|
301
|
-
setFocused(false);
|
|
302
|
-
} else {
|
|
303
|
-
searchInputRef.current.value = '';
|
|
304
|
-
setQuery('');
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}}
|
|
308
|
-
/>
|
|
309
|
-
</label>
|
|
310
|
-
</div>
|
|
311
|
-
<h2
|
|
312
|
-
className="text-brand ml-2 sm:hidden cursor-pointer"
|
|
313
|
-
onClick={e => {
|
|
314
|
-
e.stopPropagation();
|
|
315
|
-
setFocused(false);
|
|
316
|
-
}}
|
|
317
|
-
>
|
|
318
|
-
Cancel
|
|
319
|
-
</h2>
|
|
320
|
-
</div>
|
|
321
|
-
|
|
322
|
-
{query ? (
|
|
323
|
-
<div className={`${styles.searchHits} rspress-scrollbar`}>
|
|
324
|
-
{renderSearchResult(searchResult, search)}
|
|
325
|
-
</div>
|
|
326
|
-
) : null}
|
|
327
|
-
{initing && (
|
|
328
|
-
<div className="flex-center">
|
|
329
|
-
<div className="p-2 text-sm">
|
|
330
|
-
<LoadingSvg />
|
|
331
|
-
</div>
|
|
332
|
-
</div>
|
|
333
|
-
)}
|
|
334
|
-
</div>
|
|
335
|
-
</div>,
|
|
336
|
-
document.getElementById('search-container')!,
|
|
337
|
-
)}
|
|
338
|
-
</>
|
|
339
|
-
);
|
|
340
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import FileSvg from './assets/file.svg';
|
|
2
|
-
import JumpSvg from './assets/jump.svg';
|
|
3
|
-
import HeaderSvg from './assets/header.svg';
|
|
4
|
-
import TitleSvg from './assets/title.svg';
|
|
5
|
-
import { HightlightInfo, MatchResultItem } from './logic/search';
|
|
6
|
-
import styles from './index.module.scss';
|
|
7
|
-
import { getSlicedStrByByteLength, removeDomain } from './logic/util';
|
|
8
|
-
import { isProduction } from '@/runtime';
|
|
9
|
-
|
|
10
|
-
const ICON_MAP = {
|
|
11
|
-
title: TitleSvg,
|
|
12
|
-
header: HeaderSvg,
|
|
13
|
-
content: FileSvg,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export function SuggestItem({
|
|
17
|
-
suggestion,
|
|
18
|
-
closeSearch,
|
|
19
|
-
isCurrent,
|
|
20
|
-
setCurrentSuggestionIndex,
|
|
21
|
-
inCurrentDocIndex,
|
|
22
|
-
}: {
|
|
23
|
-
suggestion: MatchResultItem;
|
|
24
|
-
closeSearch: () => void;
|
|
25
|
-
isCurrent: boolean;
|
|
26
|
-
setCurrentSuggestionIndex: () => void;
|
|
27
|
-
inCurrentDocIndex: boolean;
|
|
28
|
-
}) {
|
|
29
|
-
const HitIcon = ICON_MAP[suggestion.type];
|
|
30
|
-
const link =
|
|
31
|
-
inCurrentDocIndex && !isProduction()
|
|
32
|
-
? removeDomain(suggestion.link)
|
|
33
|
-
: suggestion.link;
|
|
34
|
-
|
|
35
|
-
const getHighlightedFragments = (
|
|
36
|
-
rawText: string,
|
|
37
|
-
highlights: HightlightInfo[],
|
|
38
|
-
) => {
|
|
39
|
-
// Split raw text into several parts, and add styles.mark className to the parts that need to be highlighted.
|
|
40
|
-
// highlightInfoList is an array of objects, each object contains the start index and the length of the part that needs to be highlighted.
|
|
41
|
-
// For example, if the statement is "This is a statement", and the query is "is", then highlightInfoList is [{start: 2, length: 2}, {start: 5, length: 2}].
|
|
42
|
-
const framegmentList = [];
|
|
43
|
-
let lastIndex = 0;
|
|
44
|
-
for (const highlightInfo of highlights) {
|
|
45
|
-
const { start, length } = highlightInfo;
|
|
46
|
-
const prefix = rawText.slice(lastIndex, start);
|
|
47
|
-
const queryStr = getSlicedStrByByteLength(rawText, start, length);
|
|
48
|
-
framegmentList.push(prefix);
|
|
49
|
-
framegmentList.push(
|
|
50
|
-
<span key={start} className={styles.mark}>
|
|
51
|
-
{queryStr}
|
|
52
|
-
</span>,
|
|
53
|
-
);
|
|
54
|
-
lastIndex = start + queryStr.length;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (lastIndex < rawText.length) {
|
|
58
|
-
framegmentList.push(rawText.slice(lastIndex));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return framegmentList;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const renderHeaderMatch = () => {
|
|
65
|
-
if (suggestion.type === 'header' || suggestion.type === 'title') {
|
|
66
|
-
const { header, highlightInfoList } = suggestion;
|
|
67
|
-
return (
|
|
68
|
-
<div className="font-medium">
|
|
69
|
-
{getHighlightedFragments(header, highlightInfoList)}
|
|
70
|
-
</div>
|
|
71
|
-
);
|
|
72
|
-
} else {
|
|
73
|
-
return <div className="font-medium">{suggestion.header}</div>;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const renderStatementMatch = () => {
|
|
77
|
-
if (suggestion.type !== 'content') {
|
|
78
|
-
return <div></div>;
|
|
79
|
-
}
|
|
80
|
-
const { statement, highlightInfoList } = suggestion;
|
|
81
|
-
return (
|
|
82
|
-
<div className="text-sm text-gray-light w-full">
|
|
83
|
-
{getHighlightedFragments(statement, highlightInfoList)}
|
|
84
|
-
</div>
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
let hitContent = null;
|
|
89
|
-
|
|
90
|
-
switch (suggestion.type) {
|
|
91
|
-
case 'title':
|
|
92
|
-
case 'header':
|
|
93
|
-
hitContent = renderHeaderMatch();
|
|
94
|
-
break;
|
|
95
|
-
case 'content':
|
|
96
|
-
hitContent = (
|
|
97
|
-
<>
|
|
98
|
-
{renderStatementMatch()}
|
|
99
|
-
<p className={styles.titleForContent}>{suggestion.title}</p>
|
|
100
|
-
</>
|
|
101
|
-
);
|
|
102
|
-
break;
|
|
103
|
-
default:
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return (
|
|
108
|
-
<li
|
|
109
|
-
key={suggestion.link}
|
|
110
|
-
className={`${styles.suggestItem} ${isCurrent ? styles.current : ''}`}
|
|
111
|
-
onMouseEnter={setCurrentSuggestionIndex}
|
|
112
|
-
>
|
|
113
|
-
<a
|
|
114
|
-
href={link}
|
|
115
|
-
onClick={e => {
|
|
116
|
-
closeSearch();
|
|
117
|
-
e.stopPropagation();
|
|
118
|
-
}}
|
|
119
|
-
target={inCurrentDocIndex ? '_self' : '_blank'}
|
|
120
|
-
>
|
|
121
|
-
<div className={styles.suggestItemContainer}>
|
|
122
|
-
<div className={styles.hitIcon}>
|
|
123
|
-
<HitIcon />
|
|
124
|
-
</div>
|
|
125
|
-
<div className={styles.contentWrapper}>
|
|
126
|
-
<span>{hitContent}</span>
|
|
127
|
-
</div>
|
|
128
|
-
<div className={styles.actionIcon}>
|
|
129
|
-
<JumpSvg />
|
|
130
|
-
</div>
|
|
131
|
-
</div>
|
|
132
|
-
</a>
|
|
133
|
-
</li>
|
|
134
|
-
);
|
|
135
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 32 32"><path fill="currentColor" d="M24 9.4L22.6 8L16 14.6L9.4 8L8 9.4l6.6 6.6L8 22.6L9.4 24l6.6-6.6l6.6 6.6l1.4-1.4l-6.6-6.6L24 9.4z"/></svg>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 32 32"><circle cx="22" cy="24" r="2" fill="currentColor"/><path fill="none" d="M22 28a4 4 0 1 1 4-4a4.004 4.004 0 0 1-4 4Zm0-6a2 2 0 1 0 2 2a2.003 2.003 0 0 0-2-2Z"/><path fill="currentColor" d="M29.777 23.479A8.64 8.64 0 0 0 22 18a8.64 8.64 0 0 0-7.777 5.479L14 24l.223.521A8.64 8.64 0 0 0 22 30a8.64 8.64 0 0 0 7.777-5.479L30 24ZM22 28a4 4 0 1 1 4-4a4.005 4.005 0 0 1-4 4Z"/><path fill="currentColor" d="M12 28H8V4h8v6a2.006 2.006 0 0 0 2 2h6v4h2v-6a.91.91 0 0 0-.3-.7l-7-7A.909.909 0 0 0 18 2H8a2.006 2.006 0 0 0-2 2v24a2.006 2.006 0 0 0 2 2h4Zm6-23.6l5.6 5.6H18Z"/></svg>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 32 32"><path fill="currentColor" d="M28 12v-2h-6V4h-2v6h-8V4h-2v6H4v2h6v8H4v2h6v6h2v-6h8v6h2v-6h6v-2h-6v-8Zm-8 8h-8v-8h8Z"/></svg>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 32 32"><path fill="currentColor" d="M13.414 17.586L18 22.172V8H8V6h10a2.002 2.002 0 0 1 2 2v14.172l4.586-4.586L26 19l-7 7l-7-7Z"/></svg>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg width="32" height="32" viewBox="0 0 24 24"><g fill="none" stroke="var(--rp-c-brand)" stroke-linecap="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" stroke-opacity=".3" d="M12 3C16.9706 3 21 7.02944 21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="1.3s" values="60;0"/></path><path stroke-dasharray="15" stroke-dashoffset="15" d="M12 3C16.9706 3 21 7.02944 21 12"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.3s" values="15;0"/><animateTransform attributeName="transform" dur="1.5s" repeatCount="indefinite" type="rotate" values="0 12 12;360 12 12"/></path></g></svg>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg width="24" height="24" viewBox="0 0 32 32"><path fill="var(--rp-c-gray)" d="m29 27.586l-7.552-7.552a11.018 11.018 0 1 0-1.414 1.414L27.586 29ZM4 13a9 9 0 1 1 9 9a9.01 9.01 0 0 1-9-9Z"/></svg>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M4 4a2 2 0 0 1 2-2h8a1 1 0 0 1 .707.293l5 5A1 1 0 0 1 20 8v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4zm13.586 4L14 4.414V8h3.586zM12 4H6v16h12V10h-5a1 1 0 0 1-1-1V4z"/></svg>
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<path d="M24 5V11M31 12L35 8M17 12L13 8M40 41H8C6.89543 41 6 40.1046 6 39L6 30.5407C6 30.1866 6.09402 29.8388 6.27244 29.533L12.4212 18.9923C12.7796 18.3778 13.4374 18 14.1487 18H33.8513C34.5626 18 35.2204 18.3778 35.5788 18.9923L41.7276 29.533C41.906 29.8388 42 30.1866 42 30.5407V39C42 40.1046 41.1046 41 40 41Z" stroke="currentColor" stroke-width="4"/>
|
|
3
|
-
<path d="M41.5 30L28 30C28 30 27 33 24 33C21 33 20 30 20 30H6.5" stroke="currentColor" stroke-width="4"/>
|
|
4
|
-
</svg>
|