@rspress/core 2.1.1 → 2.1.3
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/eject-theme/components/Llms/LlmsOpenRow.tsx +14 -3
- package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +18 -2
- package/dist/eject-theme/components/PageTabs/index.tsx +8 -18
- package/dist/eject-theme/components/Prompt/index.test.tsx +91 -0
- package/dist/eject-theme/components/Prompt/index.tsx +31 -0
- package/dist/eject-theme/components/Search/useSearchPanel.ts +85 -81
- package/dist/eject-theme/components/Sidebar/SidebarItem.scss +10 -7
- package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +2 -2
- package/dist/eject-theme/components/Tabs/index.test.tsx +31 -8
- package/dist/node/runtimeModule/i18n/DEFAULT_I18N_TEXT.d.ts +463 -0
- package/dist/node/runtimeModule/i18n/DEFAULT_I18N_TEXT.js +497 -34
- package/dist/theme/assets/markdown.js +22 -0
- package/dist/theme/components/Llms/LlmsOpenRow.js +11 -2
- package/dist/theme/components/Llms/LlmsViewOptions.d.ts +4 -2
- package/dist/theme/components/Llms/LlmsViewOptions.js +14 -2
- package/dist/theme/components/PageTabs/index.js +10 -14
- package/dist/theme/components/Prompt/index.js +29 -1
- package/dist/theme/components/Search/useSearchPanel.js +66 -65
- package/dist/theme/components/Sidebar/SidebarItem.css +9 -11
- package/dist/theme/components/Sidebar/SidebarItem.js +2 -2
- package/dist/theme/hooks/useDynamicToc.js +21 -9
- package/dist/theme/icons.d.ts +5 -0
- package/dist/theme/icons.js +3 -1
- package/dist/theme/logic/useStorageValue.d.ts +2 -1
- package/dist/theme/logic/useStorageValue.js +51 -34
- package/dist/y~0.js +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
const SvgMarkdown = (props)=>/*#__PURE__*/ jsxs("svg", {
|
|
4
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
5
|
+
width: 24,
|
|
6
|
+
height: 24,
|
|
7
|
+
fill: "currentColor",
|
|
8
|
+
viewBox: "0 0 208 128",
|
|
9
|
+
...props,
|
|
10
|
+
children: [
|
|
11
|
+
/*#__PURE__*/ jsx("path", {
|
|
12
|
+
fillRule: "evenodd",
|
|
13
|
+
d: "M15 10a5 5 0 0 0-5 5v98a5 5 0 0 0 5 5h178a5 5 0 0 0 5-5V15a5 5 0 0 0-5-5zM0 15C0 6.716 6.716 0 15 0h178c8.284 0 15 6.716 15 15v98c0 8.284-6.716 15-15 15H15c-8.284 0-15-6.716-15-15z",
|
|
14
|
+
clipRule: "evenodd"
|
|
15
|
+
}),
|
|
16
|
+
/*#__PURE__*/ jsx("path", {
|
|
17
|
+
d: "M30 98V30h20l20 25 20-25h20v68H90V59L70 84 50 59v39zm125 0-30-33h20V30h20v35h20z"
|
|
18
|
+
})
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
var markdown = SvgMarkdown;
|
|
22
|
+
export default markdown;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useI18n, useSite } from "@rspress/core/runtime";
|
|
3
|
-
import { IconAnthropic, IconExternalLink, IconLink, IconOpenAI, IconOpenInChat, SvgWrapper, copyToClipboard } from "@rspress/core/theme";
|
|
3
|
+
import { IconAnthropic, IconExternalLink, IconLink, IconMarkdown, IconOpenAI, IconOpenInChat, SvgWrapper, copyToClipboard } from "@rspress/core/theme";
|
|
4
4
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import "./LlmsOpenRow.css";
|
|
6
6
|
import "./LlmsViewOptions.css";
|
|
7
7
|
import { useMdUrl } from "./useMdUrl.js";
|
|
8
8
|
const DEFAULT_OPTIONS = [
|
|
9
9
|
'markdownLink',
|
|
10
|
+
'viewMarkdown',
|
|
10
11
|
'chatgpt',
|
|
11
12
|
'claude'
|
|
12
13
|
];
|
|
@@ -41,6 +42,13 @@ function LlmsOpenRow() {
|
|
|
41
42
|
copyToClipboard(fullMarkdownUrl);
|
|
42
43
|
}
|
|
43
44
|
},
|
|
45
|
+
viewMarkdown: {
|
|
46
|
+
title: t('viewMarkdownText'),
|
|
47
|
+
href: pathname,
|
|
48
|
+
icon: /*#__PURE__*/ jsx(SvgWrapper, {
|
|
49
|
+
icon: IconMarkdown
|
|
50
|
+
})
|
|
51
|
+
},
|
|
44
52
|
chatgpt: {
|
|
45
53
|
title: t('openInText', {
|
|
46
54
|
name: 'ChatGPT'
|
|
@@ -66,6 +74,7 @@ function LlmsOpenRow() {
|
|
|
66
74
|
}
|
|
67
75
|
}), [
|
|
68
76
|
fullMarkdownUrl,
|
|
77
|
+
pathname,
|
|
69
78
|
t,
|
|
70
79
|
q
|
|
71
80
|
]);
|
|
@@ -80,7 +89,7 @@ function LlmsOpenRow() {
|
|
|
80
89
|
children: [
|
|
81
90
|
/*#__PURE__*/ jsxs("button", {
|
|
82
91
|
className: "rp-outline__action-row",
|
|
83
|
-
onClick: ()=>setIsOpen(
|
|
92
|
+
onClick: ()=>setIsOpen((prevOpen)=>!prevOpen),
|
|
84
93
|
children: [
|
|
85
94
|
/*#__PURE__*/ jsx(SvgWrapper, {
|
|
86
95
|
icon: IconOpenInChat
|
|
@@ -9,11 +9,13 @@ export type LlmsViewOptionsItem = {
|
|
|
9
9
|
title: string;
|
|
10
10
|
href: string;
|
|
11
11
|
icon?: React.ReactNode;
|
|
12
|
-
} | 'markdownLink' | 'chatgpt' | 'claude';
|
|
12
|
+
} | 'markdownLink' | 'viewMarkdown' | 'chatgpt' | 'claude';
|
|
13
13
|
export interface LlmsViewOptionsProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
14
14
|
/**
|
|
15
15
|
* Default options for the dropdown.
|
|
16
|
-
* @default ['markdownLink', 'chatgpt', 'claude']
|
|
16
|
+
* @default ['markdownLink', 'viewMarkdown', 'chatgpt', 'claude']
|
|
17
|
+
* - 'markdownLink': Copy Markdown link
|
|
18
|
+
* - 'viewMarkdown': View as Markdown
|
|
17
19
|
* - 'chatgpt': Open in ChatGPT
|
|
18
20
|
* - 'claude': Open in Claude
|
|
19
21
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*! LICENSE: LlmsViewOptions.js.LICENSE.txt */
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useI18n, useSite } from "@rspress/core/runtime";
|
|
4
|
-
import { IconAnthropic, IconDown, IconExternalLink, IconLink, IconOpenAI, SvgWrapper, copyToClipboard } from "@rspress/core/theme";
|
|
4
|
+
import { IconAnthropic, IconDown, IconExternalLink, IconLink, IconMarkdown, IconOpenAI, SvgWrapper, copyToClipboard } from "@rspress/core/theme";
|
|
5
5
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
6
6
|
import "./index.css";
|
|
7
7
|
import "./LlmsViewOptions.css";
|
|
@@ -12,6 +12,7 @@ import { useMdUrl } from "./useMdUrl.js";
|
|
|
12
12
|
* @license MIT
|
|
13
13
|
*/ const DEFAULT_OPTIONS = [
|
|
14
14
|
'markdownLink',
|
|
15
|
+
'viewMarkdown',
|
|
15
16
|
'chatgpt',
|
|
16
17
|
'claude'
|
|
17
18
|
];
|
|
@@ -32,7 +33,7 @@ function LlmsViewOptions({ options: propsOptions }) {
|
|
|
32
33
|
};
|
|
33
34
|
}, []);
|
|
34
35
|
const toggleDropdown = ()=>{
|
|
35
|
-
setIsOpen(
|
|
36
|
+
setIsOpen((prevOpen)=>!prevOpen);
|
|
36
37
|
};
|
|
37
38
|
const { pathname } = useMdUrl();
|
|
38
39
|
const t = useI18n();
|
|
@@ -49,6 +50,13 @@ function LlmsViewOptions({ options: propsOptions }) {
|
|
|
49
50
|
copyToClipboard(fullMarkdownUrl);
|
|
50
51
|
}
|
|
51
52
|
},
|
|
53
|
+
viewMarkdown: {
|
|
54
|
+
title: t('viewMarkdownText'),
|
|
55
|
+
href: pathname,
|
|
56
|
+
icon: /*#__PURE__*/ jsx(SvgWrapper, {
|
|
57
|
+
icon: IconMarkdown
|
|
58
|
+
})
|
|
59
|
+
},
|
|
52
60
|
chatgpt: {
|
|
53
61
|
title: t('openInText', {
|
|
54
62
|
name: 'ChatGPT'
|
|
@@ -79,6 +87,7 @@ function LlmsViewOptions({ options: propsOptions }) {
|
|
|
79
87
|
]);
|
|
80
88
|
const renderableItems = useMemo(()=>options.map((option)=>{
|
|
81
89
|
if ('markdownLink' === option) return items.markdownLink;
|
|
90
|
+
if ('viewMarkdown' === option) return items.viewMarkdown;
|
|
82
91
|
if ('chatgpt' === option) return items.chatgpt;
|
|
83
92
|
if ('claude' === option) return items.claude;
|
|
84
93
|
if ('object' == typeof option && 'title' in option && 'string' == typeof option.title && ('href' in option || 'onClick' in option)) return option;
|
|
@@ -92,6 +101,9 @@ function LlmsViewOptions({ options: propsOptions }) {
|
|
|
92
101
|
children: /*#__PURE__*/ jsxs("button", {
|
|
93
102
|
ref: dropdownRef,
|
|
94
103
|
onClick: toggleDropdown,
|
|
104
|
+
"aria-label": "View options",
|
|
105
|
+
"aria-expanded": isOpen,
|
|
106
|
+
"aria-haspopup": "true",
|
|
95
107
|
className: `rp-llms-button rp-llms-view-options__trigger ${isOpen ? 'rp-llms-view-options__trigger--active' : ''}`,
|
|
96
108
|
children: [
|
|
97
109
|
/*#__PURE__*/ jsx(SvgWrapper, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useSearchParams } from "@rspress/core/runtime";
|
|
2
|
+
import { useLocation, useSearchParams } from "@rspress/core/runtime";
|
|
3
3
|
import clsx from "clsx";
|
|
4
4
|
import { Children, forwardRef, isValidElement, useEffect, useMemo } from "react";
|
|
5
5
|
import "./index.css";
|
|
@@ -17,19 +17,22 @@ function getTabValuesFromChildren(children) {
|
|
|
17
17
|
}
|
|
18
18
|
function usePageTabs(id, children) {
|
|
19
19
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
20
|
+
const { search } = useLocation();
|
|
20
21
|
const tabValues = useMemo(()=>getTabValuesFromChildren(children), [
|
|
21
22
|
children
|
|
22
23
|
]);
|
|
23
24
|
function navigateToTab(index) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const nextSearchParams = new URLSearchParams(searchParams);
|
|
26
|
+
if (0 === index) nextSearchParams.delete(id);
|
|
27
|
+
else nextSearchParams.set(id, String(index));
|
|
28
|
+
setSearchParams(nextSearchParams);
|
|
27
29
|
}
|
|
28
30
|
useEffect(()=>{
|
|
29
|
-
const currIndex = Number(
|
|
31
|
+
const currIndex = Number(new URLSearchParams(search).get(id) ?? '0');
|
|
30
32
|
if (!Number.isNaN(currIndex)) document.body.dataset.pageTabsActiveIndex = currIndex.toString();
|
|
31
33
|
}, [
|
|
32
|
-
|
|
34
|
+
id,
|
|
35
|
+
search
|
|
33
36
|
]);
|
|
34
37
|
const injectScript = `(function () {
|
|
35
38
|
var searchParams = new URLSearchParams(window.location.search);
|
|
@@ -44,12 +47,10 @@ function usePageTabs(id, children) {
|
|
|
44
47
|
injectScript
|
|
45
48
|
};
|
|
46
49
|
}
|
|
47
|
-
let renderCountForTocUpdate = 0;
|
|
48
50
|
const PageTabs = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
49
51
|
const { children: rawChildren, tabPosition = 'left', className, id = 'page' } = props;
|
|
50
52
|
const children = Children.toArray(rawChildren).filter((child)=>!('string' == typeof child && '' === child.trim()) && /*#__PURE__*/ isValidElement(child));
|
|
51
53
|
const { tabValues, navigateToTab, injectScript } = usePageTabs(id, children);
|
|
52
|
-
renderCountForTocUpdate++;
|
|
53
54
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
54
55
|
children: [
|
|
55
56
|
/*#__PURE__*/ jsx("script", {
|
|
@@ -85,12 +86,7 @@ const PageTabs = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
85
86
|
}, 'string' == typeof label ? label : index))
|
|
86
87
|
})
|
|
87
88
|
]
|
|
88
|
-
})
|
|
89
|
-
renderCountForTocUpdate % 2 === 0 ? /*#__PURE__*/ jsx("h2", {
|
|
90
|
-
style: {
|
|
91
|
-
display: 'none'
|
|
92
|
-
}
|
|
93
|
-
}) : null
|
|
89
|
+
})
|
|
94
90
|
]
|
|
95
91
|
});
|
|
96
92
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useI18n } from "@rspress/core/runtime";
|
|
3
3
|
import { IconArrowDown, IconCopy, IconSuccess, SvgWrapper, copyToClipboard, renderInlineMarkdown } from "@rspress/core/theme";
|
|
4
4
|
import clsx from "clsx";
|
|
@@ -251,6 +251,34 @@ function CopyablePrompt({ className, defaultCollapsed = true, description, eyebr
|
|
|
251
251
|
});
|
|
252
252
|
}
|
|
253
253
|
function Prompt({ custom = false, ...props }) {
|
|
254
|
+
if (import.meta.env.SSG_MD) {
|
|
255
|
+
const { children, description, eyebrow = 'For your Agent', prompt, title = 'Agent Prompt' } = props;
|
|
256
|
+
if (custom) return /*#__PURE__*/ jsxs(Fragment, {
|
|
257
|
+
children: [
|
|
258
|
+
/*#__PURE__*/ jsx("p", {
|
|
259
|
+
children: /*#__PURE__*/ jsx("strong", {
|
|
260
|
+
children: eyebrow
|
|
261
|
+
})
|
|
262
|
+
}),
|
|
263
|
+
children
|
|
264
|
+
]
|
|
265
|
+
});
|
|
266
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
267
|
+
children: [
|
|
268
|
+
/*#__PURE__*/ jsx("p", {
|
|
269
|
+
children: /*#__PURE__*/ jsx("strong", {
|
|
270
|
+
children: title
|
|
271
|
+
})
|
|
272
|
+
}),
|
|
273
|
+
description ? /*#__PURE__*/ jsx("p", {
|
|
274
|
+
children: description
|
|
275
|
+
}) : null,
|
|
276
|
+
prompt ? /*#__PURE__*/ jsx("pre", {
|
|
277
|
+
children: `<prompt>\n${prompt}\n</prompt>`
|
|
278
|
+
}) : null
|
|
279
|
+
]
|
|
280
|
+
});
|
|
281
|
+
}
|
|
254
282
|
return custom ? /*#__PURE__*/ jsx(CustomPrompt, {
|
|
255
283
|
...props
|
|
256
284
|
}) : /*#__PURE__*/ jsx(CopyablePrompt, {
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { usePageData, useSearchHooks, useWebMcp } from "@rspress/core/runtime";
|
|
2
2
|
import { debounce } from "@rspress/shared/lodash-es";
|
|
3
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { getSearchIndexURL } from "./logic/providers/LocalProvider.js";
|
|
5
5
|
import { PageSearcher } from "./logic/search.js";
|
|
6
6
|
import { RenderType } from "./logic/types.js";
|
|
7
7
|
import { defineTool, queryField, toWebMcpSearchResults } from "../../webMcp/tools.js";
|
|
8
|
-
const useDebounce = (cb)=>{
|
|
9
|
-
const cbRef = useRef(cb);
|
|
10
|
-
cbRef.current = cb;
|
|
11
|
-
return useCallback(debounce((...args)=>cbRef.current(...args), 150), []);
|
|
12
|
-
};
|
|
13
8
|
function useSearchPanel({ focused, searchInputRef }) {
|
|
14
9
|
const { siteData, page: { lang, version } } = usePageData();
|
|
15
10
|
const userSearchHooks = useSearchHooks();
|
|
@@ -27,8 +22,9 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
27
22
|
const initializationRef = useRef(void 0);
|
|
28
23
|
const searchEnabled = false !== search;
|
|
29
24
|
const searchOptions = false === search ? {} : search;
|
|
30
|
-
const
|
|
31
|
-
const
|
|
25
|
+
const isSearchVersioned = searchEnabled && (search?.versioned ?? true);
|
|
26
|
+
const searchVersion = isSearchVersioned ? version : '';
|
|
27
|
+
const searchIndexURL = searchEnabled ? getSearchIndexURL(lang, searchVersion) : void 0;
|
|
32
28
|
const DEFAULT_RESULT = [
|
|
33
29
|
{
|
|
34
30
|
group: siteTitle,
|
|
@@ -38,7 +34,7 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
38
34
|
];
|
|
39
35
|
const createSearcher = ()=>{
|
|
40
36
|
const previous = pageSearcherConfigRef.current;
|
|
41
|
-
if (pageSearcherRef.current && previous?.currentLang === lang && (!
|
|
37
|
+
if (pageSearcherRef.current && previous?.currentLang === lang && (!isSearchVersioned || previous.currentVersion === version) && pageSearcherURLRef.current === searchIndexURL) return pageSearcherRef.current;
|
|
42
38
|
const pageSearcherConfig = {
|
|
43
39
|
currentLang: lang,
|
|
44
40
|
currentVersion: version
|
|
@@ -99,89 +95,94 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
99
95
|
], async (args)=>toWebMcpSearchResults(await searchDocs(args.query, args.limit ?? 10))),
|
|
100
96
|
enabled: searchEnabled && Boolean(searchIndexURL || userSearchHooks.onSearch)
|
|
101
97
|
});
|
|
98
|
+
const requestIdRef = useRef(0);
|
|
99
|
+
const scheduleQuery = useMemo(()=>debounce((run)=>run(), 150), []);
|
|
100
|
+
const invalidateQuery = useCallback(()=>{
|
|
101
|
+
requestIdRef.current++;
|
|
102
|
+
scheduleQuery.cancel();
|
|
103
|
+
}, [
|
|
104
|
+
scheduleQuery
|
|
105
|
+
]);
|
|
106
|
+
useLayoutEffect(()=>invalidateQuery, [
|
|
107
|
+
focused,
|
|
108
|
+
searchEnabled,
|
|
109
|
+
lang,
|
|
110
|
+
searchVersion,
|
|
111
|
+
searchIndexURL,
|
|
112
|
+
invalidateQuery
|
|
113
|
+
]);
|
|
114
|
+
useLayoutEffect(()=>{
|
|
115
|
+
pageSearcherRef.current = null;
|
|
116
|
+
setInitStatus('initial');
|
|
117
|
+
setSearchError(void 0);
|
|
118
|
+
}, [
|
|
119
|
+
searchEnabled,
|
|
120
|
+
lang,
|
|
121
|
+
searchVersion,
|
|
122
|
+
searchIndexURL
|
|
123
|
+
]);
|
|
102
124
|
const initSearch = async ()=>{
|
|
103
|
-
if ('initial' !== initStatus) return;
|
|
104
125
|
const searcher = createSearcher();
|
|
126
|
+
if ('initial' !== initStatus && initializationRef.current?.searcher === searcher) return;
|
|
105
127
|
setSearchError(void 0);
|
|
106
128
|
setInitStatus('initing');
|
|
107
129
|
try {
|
|
108
130
|
await initializeSearcher(searcher);
|
|
131
|
+
if (pageSearcherRef.current === searcher) setInitStatus('inited');
|
|
109
132
|
} catch (error) {
|
|
110
|
-
if (pageSearcherRef.current
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (pageSearcherRef.current !== searcher) return;
|
|
117
|
-
setInitStatus('inited');
|
|
118
|
-
const currentQuery = searchInputRef.current?.value;
|
|
119
|
-
if (currentQuery) {
|
|
120
|
-
const matched = await searcher.match(currentQuery);
|
|
121
|
-
if (pageSearcherRef.current !== searcher || searchInputRef.current?.value !== currentQuery) return;
|
|
122
|
-
setSearchResult(matched || DEFAULT_RESULT);
|
|
123
|
-
setIsSearching(false);
|
|
133
|
+
if (pageSearcherRef.current === searcher) {
|
|
134
|
+
setSearchError(error instanceof Error ? error.message : String(error));
|
|
135
|
+
setInitStatus('error');
|
|
136
|
+
}
|
|
124
137
|
}
|
|
125
138
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
initSearch();
|
|
131
|
-
} else setQuery('');
|
|
132
|
-
}, [
|
|
133
|
-
focused,
|
|
134
|
-
searchEnabled
|
|
135
|
-
]);
|
|
136
|
-
useEffect(()=>{
|
|
137
|
-
if (!searchEnabled) return;
|
|
138
|
-
const { currentLang, currentVersion } = pageSearcherConfigRef.current ?? {};
|
|
139
|
-
const isLangChanged = lang !== currentLang;
|
|
140
|
-
const isVersionChanged = versionedSearch && version !== currentVersion;
|
|
141
|
-
const isIndexChanged = pageSearcherURLRef.current !== searchIndexURL;
|
|
142
|
-
if (isLangChanged || isVersionChanged || isIndexChanged) {
|
|
143
|
-
setInitStatus('initial');
|
|
144
|
-
setSearchError(void 0);
|
|
145
|
-
setIsSearching(false);
|
|
146
|
-
pageSearcherRef.current = null;
|
|
147
|
-
}
|
|
148
|
-
}, [
|
|
149
|
-
lang,
|
|
150
|
-
version,
|
|
151
|
-
versionedSearch,
|
|
152
|
-
searchEnabled,
|
|
153
|
-
searchIndexURL
|
|
154
|
-
]);
|
|
155
|
-
const handleQueryChangedImpl = async (value)=>{
|
|
156
|
-
const newQuery = value;
|
|
157
|
-
setQuery(newQuery);
|
|
158
|
-
if (!newQuery) return void setIsSearching(false);
|
|
139
|
+
const runQuery = async (value, requestId)=>{
|
|
140
|
+
const isCurrent = ()=>requestId === requestIdRef.current && searchInputRef.current?.value === value;
|
|
141
|
+
if (!isCurrent()) return;
|
|
142
|
+
setQuery(value);
|
|
159
143
|
try {
|
|
160
144
|
const result = await searchDocs(value);
|
|
161
|
-
if (
|
|
145
|
+
if (isCurrent()) {
|
|
162
146
|
setSearchError(void 0);
|
|
163
147
|
setInitStatus('inited');
|
|
164
148
|
setCurrentSuggestionIndex(0);
|
|
165
|
-
setSearchResult(result
|
|
149
|
+
setSearchResult(result);
|
|
166
150
|
setIsSearching(false);
|
|
167
151
|
}
|
|
168
152
|
} catch (error) {
|
|
169
|
-
if (
|
|
153
|
+
if (isCurrent()) {
|
|
170
154
|
setSearchError(error instanceof Error ? error.message : String(error));
|
|
171
155
|
setInitStatus('error');
|
|
172
156
|
setIsSearching(false);
|
|
173
157
|
}
|
|
174
158
|
}
|
|
175
159
|
};
|
|
176
|
-
const handleQueryChange = useDebounce(handleQueryChangedImpl);
|
|
177
|
-
const handleQueryInput = (value)=>{
|
|
178
|
-
setIsSearching(Boolean(value));
|
|
179
|
-
handleQueryChange(value);
|
|
180
|
-
};
|
|
181
160
|
const clearQuery = ()=>{
|
|
161
|
+
invalidateQuery();
|
|
182
162
|
setQuery('');
|
|
183
163
|
setIsSearching(false);
|
|
184
164
|
};
|
|
165
|
+
const handleQueryInput = (value)=>{
|
|
166
|
+
if (!value) return void clearQuery();
|
|
167
|
+
const requestId = ++requestIdRef.current;
|
|
168
|
+
setIsSearching(true);
|
|
169
|
+
scheduleQuery(()=>{
|
|
170
|
+
runQuery(value, requestId);
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
useEffect(()=>{
|
|
174
|
+
if (!focused || !searchEnabled) return void clearQuery();
|
|
175
|
+
setSearchResult(DEFAULT_RESULT);
|
|
176
|
+
const value = searchInputRef.current?.value;
|
|
177
|
+
if (value) handleQueryInput(value);
|
|
178
|
+
else initSearch();
|
|
179
|
+
}, [
|
|
180
|
+
focused,
|
|
181
|
+
searchEnabled,
|
|
182
|
+
lang,
|
|
183
|
+
searchVersion,
|
|
184
|
+
searchIndexURL
|
|
185
|
+
]);
|
|
185
186
|
return {
|
|
186
187
|
searchEnabled,
|
|
187
188
|
clearQuery,
|
|
@@ -32,15 +32,14 @@
|
|
|
32
32
|
display: inline-block;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
.rp-sidebar-item--active {
|
|
35
|
+
.rp-sidebar-item--active, .rp-sidebar-item--active:hover {
|
|
36
36
|
color: var(--rp-c-link);
|
|
37
37
|
background-color: var(--rp-c-brand-tint);
|
|
38
|
-
font-weight: 600;
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
.rp-sidebar-item
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
.rp-sidebar-item:focus-visible {
|
|
41
|
+
outline: 2px solid var(--rp-c-brand);
|
|
42
|
+
outline-offset: -2px;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
.rp-sidebar-item--group-item:before {
|
|
@@ -48,20 +47,19 @@
|
|
|
48
47
|
background-color: var(--rp-c-divider-light);
|
|
49
48
|
width: 1px;
|
|
50
49
|
position: absolute;
|
|
51
|
-
top:
|
|
50
|
+
top: -2px;
|
|
52
51
|
bottom: 0;
|
|
53
|
-
left:
|
|
52
|
+
left: -7px;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
.rp-sidebar-item--group-item.rp-sidebar-item--active .rp-sidebar-item__left:before {
|
|
57
56
|
content: "";
|
|
58
57
|
background-color: var(--rp-c-brand);
|
|
59
58
|
width: 1px;
|
|
60
|
-
height: calc(50% - 4px);
|
|
61
59
|
position: absolute;
|
|
62
|
-
top:
|
|
63
|
-
bottom:
|
|
64
|
-
left:
|
|
60
|
+
top: 8px;
|
|
61
|
+
bottom: 8px;
|
|
62
|
+
left: -7px;
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
.rp-sidebar-item__left {
|
|
@@ -57,7 +57,7 @@ function SidebarItemRaw({ active, text, icon, tag, link, context, className, lef
|
|
|
57
57
|
'rp-sidebar-item--pending': isPending
|
|
58
58
|
}, className),
|
|
59
59
|
style: {
|
|
60
|
-
|
|
60
|
+
marginLeft: 24 * depth
|
|
61
61
|
},
|
|
62
62
|
'data-depth': depth,
|
|
63
63
|
...context ? {
|
|
@@ -72,7 +72,7 @@ function SidebarItemRaw({ active, text, icon, tag, link, context, className, lef
|
|
|
72
72
|
'rp-sidebar-item--active': active
|
|
73
73
|
}, className),
|
|
74
74
|
style: {
|
|
75
|
-
|
|
75
|
+
marginLeft: 24 * depth
|
|
76
76
|
},
|
|
77
77
|
'data-depth': depth,
|
|
78
78
|
...context ? {
|
|
@@ -64,17 +64,23 @@ const useWatchToc = ()=>{
|
|
|
64
64
|
if (target && !observer) {
|
|
65
65
|
observer = new MutationObserver((mutationList)=>{
|
|
66
66
|
let needUpdate = false;
|
|
67
|
-
check: for (const mutation of mutationList)
|
|
68
|
-
mutation.
|
|
69
|
-
mutation.removedNodes
|
|
70
|
-
])for (const node of nodes){
|
|
71
|
-
if (TOC_HEADING_TAGS.has(node.tagName) || node.parentElement?.closest('h2,h3,h4')) {
|
|
67
|
+
check: for (const mutation of mutationList){
|
|
68
|
+
if ('attributes' === mutation.type) {
|
|
72
69
|
needUpdate = true;
|
|
73
|
-
break
|
|
70
|
+
break;
|
|
74
71
|
}
|
|
75
|
-
for (const
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
for (const nodes of [
|
|
73
|
+
mutation.addedNodes,
|
|
74
|
+
mutation.removedNodes
|
|
75
|
+
])for (const node of nodes){
|
|
76
|
+
if (TOC_HEADING_TAGS.has(node.tagName) || node.parentElement?.closest('h2,h3,h4')) {
|
|
77
|
+
needUpdate = true;
|
|
78
|
+
break check;
|
|
79
|
+
}
|
|
80
|
+
for (const child of node.childNodes)if (TOC_HEADING_TAGS.has(child.tagName)) {
|
|
81
|
+
needUpdate = true;
|
|
82
|
+
break check;
|
|
83
|
+
}
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
86
|
needUpdate && updateHeaders(target, pathname);
|
|
@@ -83,6 +89,12 @@ const useWatchToc = ()=>{
|
|
|
83
89
|
childList: true,
|
|
84
90
|
subtree: true
|
|
85
91
|
});
|
|
92
|
+
observer.observe(document.body, {
|
|
93
|
+
attributes: true,
|
|
94
|
+
attributeFilter: [
|
|
95
|
+
'data-page-tabs-active-index'
|
|
96
|
+
]
|
|
97
|
+
});
|
|
86
98
|
}
|
|
87
99
|
return ()=>{
|
|
88
100
|
observer?.disconnect();
|
package/dist/theme/icons.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ export declare const IconHeader: Icon;
|
|
|
20
20
|
export declare const IconJsdelivr: Icon;
|
|
21
21
|
export declare const IconJump: Icon;
|
|
22
22
|
export declare const IconLoading: Icon;
|
|
23
|
+
/**
|
|
24
|
+
* Markdown Mark by Dustin Curtis, dedicated to the public domain.
|
|
25
|
+
* @see https://github.com/dcurtis/markdown-mark
|
|
26
|
+
*/
|
|
27
|
+
export declare const IconMarkdown: Icon;
|
|
23
28
|
export declare const IconMenu: Icon;
|
|
24
29
|
export declare const IconMoon: Icon;
|
|
25
30
|
export declare const IconNpm: Icon;
|
package/dist/theme/icons.js
CHANGED
|
@@ -20,6 +20,7 @@ import jsdelivr from "./assets/jsdelivr.js";
|
|
|
20
20
|
import jump from "./assets/jump.js";
|
|
21
21
|
import assets_link from "./assets/link.js";
|
|
22
22
|
import loading from "./assets/loading.js";
|
|
23
|
+
import markdown from "./assets/markdown.js";
|
|
23
24
|
import menu from "./assets/menu.js";
|
|
24
25
|
import moon from "./assets/moon.js";
|
|
25
26
|
import npm from "./assets/npm.js";
|
|
@@ -56,6 +57,7 @@ const IconHeader = header;
|
|
|
56
57
|
const IconJsdelivr = jsdelivr;
|
|
57
58
|
const IconJump = jump;
|
|
58
59
|
const IconLoading = loading;
|
|
60
|
+
const IconMarkdown = markdown;
|
|
59
61
|
const IconMenu = menu;
|
|
60
62
|
const IconMoon = moon;
|
|
61
63
|
const IconNpm = npm;
|
|
@@ -72,4 +74,4 @@ const IconWrap = wrap;
|
|
|
72
74
|
const IconWrapped = wrapped;
|
|
73
75
|
const IconYarn = yarn;
|
|
74
76
|
const IconLink = assets_link;
|
|
75
|
-
export { IconAnthropic, IconArrowDown, IconArrowRight, IconBun, IconClose, IconCopy, IconDeno, IconDeprecated, IconDown, IconEdit, IconEmpty, IconExperimental, IconExternalLink, IconFile, IconGithub, IconGitlab, IconHeader, IconJsdelivr, IconJump, IconLink, IconLoading, IconMenu, IconMoon, IconNpm, IconOpenAI, IconOpenInChat, IconPnpm, IconScrollToTop, IconSearch, IconSmallMenu, IconSuccess, IconSun, IconTitle, IconUnpkg, IconWrap, IconWrapped, IconYarn };
|
|
77
|
+
export { IconAnthropic, IconArrowDown, IconArrowRight, IconBun, IconClose, IconCopy, IconDeno, IconDeprecated, IconDown, IconEdit, IconEmpty, IconExperimental, IconExternalLink, IconFile, IconGithub, IconGitlab, IconHeader, IconJsdelivr, IconJump, IconLink, IconLoading, IconMarkdown, IconMenu, IconMoon, IconNpm, IconOpenAI, IconOpenInChat, IconPnpm, IconScrollToTop, IconSearch, IconSmallMenu, IconSuccess, IconSun, IconTitle, IconUnpkg, IconWrap, IconWrapped, IconYarn };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export type StorageAction<T> = T | ((prevState: T) => T);
|
|
1
2
|
/**
|
|
2
3
|
* Read/update the value in localStorage, and keeping it in sync with other tabs.
|
|
3
4
|
* @internal
|
|
4
5
|
*/
|
|
5
|
-
export declare const useStorageValue: <T>(key: string, defaultValue: T) => readonly [T, (
|
|
6
|
+
export declare const useStorageValue: <T>(key: string, defaultValue: T) => readonly [T, (action: StorageAction<T>) => void];
|