@rspress/core 2.1.1 → 2.1.2
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/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/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/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/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 +50 -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,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 ? {
|
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];
|
|
@@ -1,50 +1,66 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
2
2
|
const SYNC_STORAGE_EVENT_NAME = 'RSPRESS_SYNC_STORAGE_EVENT_NAME';
|
|
3
|
+
const getStorageItem = (key)=>{
|
|
4
|
+
if ("u" < typeof window) return null;
|
|
5
|
+
try {
|
|
6
|
+
return window.localStorage.getItem(key);
|
|
7
|
+
} catch {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const setStorageItem = (key, value)=>{
|
|
12
|
+
if ("u" < typeof window) return;
|
|
13
|
+
try {
|
|
14
|
+
if (null == value) window.localStorage.removeItem(key);
|
|
15
|
+
else window.localStorage.setItem(key, value);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.warn(`[useStorageValue] Failed to set localStorage key "${key}":`, error);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
3
20
|
const useStorageValue = (key, defaultValue)=>{
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
21
|
+
const subscribe = useCallback((onStoreChange)=>{
|
|
22
|
+
const handleStorage = (event)=>{
|
|
23
|
+
if (event.key === key || null === event.key) onStoreChange();
|
|
24
|
+
};
|
|
25
|
+
const handleCustomEvent = (event)=>{
|
|
26
|
+
const customEvent = event;
|
|
27
|
+
if (customEvent.detail?.key === key) onStoreChange();
|
|
28
|
+
};
|
|
29
|
+
window.addEventListener('storage', handleStorage);
|
|
30
|
+
window.addEventListener(SYNC_STORAGE_EVENT_NAME, handleCustomEvent);
|
|
31
|
+
return ()=>{
|
|
32
|
+
window.removeEventListener('storage', handleStorage);
|
|
33
|
+
window.removeEventListener(SYNC_STORAGE_EVENT_NAME, handleCustomEvent);
|
|
34
|
+
};
|
|
9
35
|
}, [
|
|
10
36
|
key
|
|
11
37
|
]);
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
38
|
+
const getSnapshot = useCallback(()=>{
|
|
39
|
+
const raw = getStorageItem(key);
|
|
40
|
+
return null !== raw ? raw : defaultValue;
|
|
41
|
+
}, [
|
|
42
|
+
key,
|
|
43
|
+
defaultValue
|
|
44
|
+
]);
|
|
45
|
+
const getServerSnapshot = useCallback(()=>defaultValue, [
|
|
46
|
+
defaultValue
|
|
47
|
+
]);
|
|
48
|
+
const value = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
49
|
+
const setValue = useCallback((action)=>{
|
|
50
|
+
const currentStored = getStorageItem(key);
|
|
51
|
+
const currentValue = null !== currentStored ? currentStored : defaultValue;
|
|
52
|
+
const nextValue = 'function' == typeof action ? action(currentValue) : action;
|
|
53
|
+
null == nextValue ? setStorageItem(key, null) : setStorageItem(key, String(nextValue));
|
|
54
|
+
if ("u" > typeof window) window.dispatchEvent(new CustomEvent(SYNC_STORAGE_EVENT_NAME, {
|
|
18
55
|
detail: {
|
|
19
56
|
key,
|
|
20
|
-
newValue:
|
|
57
|
+
newValue: nextValue
|
|
21
58
|
}
|
|
22
59
|
}));
|
|
23
|
-
}, [
|
|
24
|
-
key
|
|
25
|
-
]);
|
|
26
|
-
useEffect(()=>{
|
|
27
|
-
const listener = (e)=>{
|
|
28
|
-
if (e.key === key) setValueInternal(localStorage.getItem(key) ?? defaultValue);
|
|
29
|
-
};
|
|
30
|
-
window.addEventListener('storage', listener);
|
|
31
|
-
return ()=>{
|
|
32
|
-
window.removeEventListener('storage', listener);
|
|
33
|
-
};
|
|
34
60
|
}, [
|
|
35
61
|
key,
|
|
36
62
|
defaultValue
|
|
37
63
|
]);
|
|
38
|
-
useEffect(()=>{
|
|
39
|
-
const listener = (e)=>{
|
|
40
|
-
const { key: eventKey, newValue } = e.detail;
|
|
41
|
-
if (eventKey === key) setValueInternal(newValue ?? defaultValue);
|
|
42
|
-
};
|
|
43
|
-
window.addEventListener(SYNC_STORAGE_EVENT_NAME, listener);
|
|
44
|
-
return ()=>{
|
|
45
|
-
window.removeEventListener(SYNC_STORAGE_EVENT_NAME, listener);
|
|
46
|
-
};
|
|
47
|
-
}, []);
|
|
48
64
|
return [
|
|
49
65
|
value,
|
|
50
66
|
setValue
|
package/dist/y~0.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@mdx-js/react": "^3.1.1",
|
|
63
63
|
"@rsbuild/core": "^2.2.14",
|
|
64
64
|
"@rsbuild/plugin-react": "~2.1.1",
|
|
65
|
-
"@rspress/shared": "2.1.
|
|
65
|
+
"@rspress/shared": "2.1.2",
|
|
66
66
|
"@shikijs/rehype": "^4.2.0",
|
|
67
67
|
"@shikijs/transformers": "^4.2.0",
|
|
68
68
|
"@types/mdast": "^4.0.4",
|
|
@@ -85,8 +85,8 @@
|
|
|
85
85
|
"react-router-dom": "^7.18.5",
|
|
86
86
|
"rehype-external-links": "^3.0.0",
|
|
87
87
|
"rehype-raw": "^7.0.0",
|
|
88
|
-
"remark-cjk-friendly": "^2.3.
|
|
89
|
-
"remark-cjk-friendly-gfm-strikethrough": "^2.3.
|
|
88
|
+
"remark-cjk-friendly": "^2.3.4",
|
|
89
|
+
"remark-cjk-friendly-gfm-strikethrough": "^2.3.3",
|
|
90
90
|
"remark-gfm": "^4.0.1",
|
|
91
91
|
"remark-mdx": "^3.1.1",
|
|
92
92
|
"remark-parse": "^11.0.0",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"@types/node": "^22.8.1",
|
|
109
109
|
"@types/nprogress": "^0.2.3",
|
|
110
110
|
"@types/react-dom": "^19.3.0",
|
|
111
|
-
"@types/web": "^0.0.
|
|
111
|
+
"@types/web": "^0.0.362",
|
|
112
112
|
"cac": "^7.1.0",
|
|
113
113
|
"execa": "8.0.1",
|
|
114
114
|
"mdast-util-directive": "^3.1.1",
|