@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
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
IconAnthropic,
|
|
5
5
|
IconExternalLink,
|
|
6
6
|
IconLink,
|
|
7
|
+
IconMarkdown,
|
|
7
8
|
IconOpenAI,
|
|
8
9
|
IconOpenInChat,
|
|
9
10
|
SvgWrapper,
|
|
@@ -21,7 +22,12 @@ type MenuItem = {
|
|
|
21
22
|
onClick?: () => void;
|
|
22
23
|
};
|
|
23
24
|
|
|
24
|
-
const DEFAULT_OPTIONS = [
|
|
25
|
+
const DEFAULT_OPTIONS = [
|
|
26
|
+
'markdownLink',
|
|
27
|
+
'viewMarkdown',
|
|
28
|
+
'chatgpt',
|
|
29
|
+
'claude',
|
|
30
|
+
] as const;
|
|
25
31
|
|
|
26
32
|
export function LlmsOpenRow() {
|
|
27
33
|
const t = useI18n();
|
|
@@ -73,6 +79,11 @@ export function LlmsOpenRow() {
|
|
|
73
79
|
void copyToClipboard(fullMarkdownUrl);
|
|
74
80
|
},
|
|
75
81
|
},
|
|
82
|
+
viewMarkdown: {
|
|
83
|
+
title: t('viewMarkdownText'),
|
|
84
|
+
href: pathname,
|
|
85
|
+
icon: <SvgWrapper icon={IconMarkdown} />,
|
|
86
|
+
},
|
|
76
87
|
chatgpt: {
|
|
77
88
|
title: t('openInText', { name: 'ChatGPT' }),
|
|
78
89
|
href: `https://chatgpt.com/?${new URLSearchParams({ hints: 'search', q })}`,
|
|
@@ -84,7 +95,7 @@ export function LlmsOpenRow() {
|
|
|
84
95
|
icon: <SvgWrapper icon={IconAnthropic} />,
|
|
85
96
|
},
|
|
86
97
|
}),
|
|
87
|
-
[fullMarkdownUrl, t, q],
|
|
98
|
+
[fullMarkdownUrl, pathname, t, q],
|
|
88
99
|
);
|
|
89
100
|
|
|
90
101
|
const renderableItems = useMemo(
|
|
@@ -105,7 +116,7 @@ export function LlmsOpenRow() {
|
|
|
105
116
|
<div ref={containerRef} className="rp-outline__open-in-wrapper">
|
|
106
117
|
<button
|
|
107
118
|
className="rp-outline__action-row"
|
|
108
|
-
onClick={() => setIsOpen(!
|
|
119
|
+
onClick={() => setIsOpen(prevOpen => !prevOpen)}
|
|
109
120
|
>
|
|
110
121
|
<SvgWrapper icon={IconOpenInChat} />
|
|
111
122
|
<span>{t('openInText', { name: 'chat' })}</span>
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
IconDown,
|
|
11
11
|
IconExternalLink,
|
|
12
12
|
IconLink,
|
|
13
|
+
IconMarkdown,
|
|
13
14
|
IconOpenAI,
|
|
14
15
|
SvgWrapper,
|
|
15
16
|
} from '@rspress/core/theme';
|
|
@@ -31,6 +32,7 @@ export type LlmsViewOptionsItem =
|
|
|
31
32
|
icon?: React.ReactNode;
|
|
32
33
|
}
|
|
33
34
|
| 'markdownLink'
|
|
35
|
+
| 'viewMarkdown'
|
|
34
36
|
| 'chatgpt'
|
|
35
37
|
| 'claude';
|
|
36
38
|
|
|
@@ -44,7 +46,9 @@ type MenuItem = {
|
|
|
44
46
|
export interface LlmsViewOptionsProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
45
47
|
/**
|
|
46
48
|
* Default options for the dropdown.
|
|
47
|
-
* @default ['markdownLink', 'chatgpt', 'claude']
|
|
49
|
+
* @default ['markdownLink', 'viewMarkdown', 'chatgpt', 'claude']
|
|
50
|
+
* - 'markdownLink': Copy Markdown link
|
|
51
|
+
* - 'viewMarkdown': View as Markdown
|
|
48
52
|
* - 'chatgpt': Open in ChatGPT
|
|
49
53
|
* - 'claude': Open in Claude
|
|
50
54
|
*
|
|
@@ -67,6 +71,7 @@ export interface LlmsViewOptionsProps extends React.ButtonHTMLAttributes<HTMLBut
|
|
|
67
71
|
|
|
68
72
|
const DEFAULT_OPTIONS: LlmsViewOptionsItem[] = [
|
|
69
73
|
'markdownLink',
|
|
74
|
+
'viewMarkdown',
|
|
70
75
|
'chatgpt',
|
|
71
76
|
'claude',
|
|
72
77
|
];
|
|
@@ -101,7 +106,7 @@ export function LlmsViewOptions({
|
|
|
101
106
|
}, []);
|
|
102
107
|
|
|
103
108
|
const toggleDropdown = () => {
|
|
104
|
-
setIsOpen(!
|
|
109
|
+
setIsOpen(prevOpen => !prevOpen);
|
|
105
110
|
};
|
|
106
111
|
|
|
107
112
|
const { pathname } = useMdUrl();
|
|
@@ -122,6 +127,11 @@ export function LlmsViewOptions({
|
|
|
122
127
|
void copyToClipboard(fullMarkdownUrl);
|
|
123
128
|
},
|
|
124
129
|
},
|
|
130
|
+
viewMarkdown: {
|
|
131
|
+
title: t('viewMarkdownText'),
|
|
132
|
+
href: pathname,
|
|
133
|
+
icon: <SvgWrapper icon={IconMarkdown} />,
|
|
134
|
+
},
|
|
125
135
|
chatgpt: {
|
|
126
136
|
title: t('openInText', { name: 'ChatGPT' }),
|
|
127
137
|
href: `https://chatgpt.com/?${new URLSearchParams({
|
|
@@ -147,6 +157,9 @@ export function LlmsViewOptions({
|
|
|
147
157
|
if (option === 'markdownLink') {
|
|
148
158
|
return items.markdownLink;
|
|
149
159
|
}
|
|
160
|
+
if (option === 'viewMarkdown') {
|
|
161
|
+
return items.viewMarkdown;
|
|
162
|
+
}
|
|
150
163
|
if (option === 'chatgpt') {
|
|
151
164
|
return items.chatgpt;
|
|
152
165
|
}
|
|
@@ -176,6 +189,9 @@ export function LlmsViewOptions({
|
|
|
176
189
|
<button
|
|
177
190
|
ref={dropdownRef}
|
|
178
191
|
onClick={toggleDropdown}
|
|
192
|
+
aria-label="View options"
|
|
193
|
+
aria-expanded={isOpen}
|
|
194
|
+
aria-haspopup="true"
|
|
179
195
|
className={`rp-llms-button rp-llms-view-options__trigger ${
|
|
180
196
|
isOpen ? 'rp-llms-view-options__trigger--active' : ''
|
|
181
197
|
}`}
|
|
@@ -4,6 +4,8 @@ import { debounce } from '@rspress/shared/lodash-es';
|
|
|
4
4
|
import {
|
|
5
5
|
useCallback,
|
|
6
6
|
useEffect,
|
|
7
|
+
useLayoutEffect,
|
|
8
|
+
useMemo,
|
|
7
9
|
useRef,
|
|
8
10
|
useState,
|
|
9
11
|
type RefObject,
|
|
@@ -25,18 +27,6 @@ import {
|
|
|
25
27
|
toWebMcpSearchResults,
|
|
26
28
|
} from '../../webMcp/tools';
|
|
27
29
|
|
|
28
|
-
const useDebounce = <T extends (...args: any[]) => any>(cb: T) => {
|
|
29
|
-
const cbRef = useRef(cb);
|
|
30
|
-
cbRef.current = cb;
|
|
31
|
-
return useCallback(
|
|
32
|
-
debounce(
|
|
33
|
-
((...args: Parameters<T>): ReturnType<T> => cbRef.current(...args)) as T,
|
|
34
|
-
150,
|
|
35
|
-
),
|
|
36
|
-
[],
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
30
|
export function useSearchPanel({
|
|
41
31
|
focused,
|
|
42
32
|
searchInputRef,
|
|
@@ -67,9 +57,10 @@ export function useSearchPanel({
|
|
|
67
57
|
>(undefined);
|
|
68
58
|
const searchEnabled = search !== false;
|
|
69
59
|
const searchOptions: LocalSearchOptions = search === false ? {} : search;
|
|
70
|
-
const
|
|
60
|
+
const isSearchVersioned = searchEnabled && (search?.versioned ?? true);
|
|
61
|
+
const searchVersion = isSearchVersioned ? version : '';
|
|
71
62
|
const searchIndexURL = searchEnabled
|
|
72
|
-
? getSearchIndexURL(lang,
|
|
63
|
+
? getSearchIndexURL(lang, searchVersion)
|
|
73
64
|
: undefined;
|
|
74
65
|
const DEFAULT_RESULT = [
|
|
75
66
|
{ group: siteTitle, result: [], renderType: RenderType.Default },
|
|
@@ -80,7 +71,7 @@ export function useSearchPanel({
|
|
|
80
71
|
if (
|
|
81
72
|
pageSearcherRef.current &&
|
|
82
73
|
previous?.currentLang === lang &&
|
|
83
|
-
(!
|
|
74
|
+
(!isSearchVersioned || previous.currentVersion === version) &&
|
|
84
75
|
pageSearcherURLRef.current === searchIndexURL
|
|
85
76
|
) {
|
|
86
77
|
return pageSearcherRef.current;
|
|
@@ -162,88 +153,76 @@ export function useSearchPanel({
|
|
|
162
153
|
});
|
|
163
154
|
}
|
|
164
155
|
|
|
156
|
+
const requestIdRef = useRef(0);
|
|
157
|
+
const scheduleQuery = useMemo(
|
|
158
|
+
() => debounce((run: () => void) => run(), 150),
|
|
159
|
+
[],
|
|
160
|
+
);
|
|
161
|
+
const invalidateQuery = useCallback(() => {
|
|
162
|
+
requestIdRef.current++;
|
|
163
|
+
scheduleQuery.cancel();
|
|
164
|
+
}, [scheduleQuery]);
|
|
165
|
+
|
|
166
|
+
// A query belongs to the popup session and index that started it.
|
|
167
|
+
useLayoutEffect(
|
|
168
|
+
() => invalidateQuery,
|
|
169
|
+
[
|
|
170
|
+
focused,
|
|
171
|
+
searchEnabled,
|
|
172
|
+
lang,
|
|
173
|
+
searchVersion,
|
|
174
|
+
searchIndexURL,
|
|
175
|
+
invalidateQuery,
|
|
176
|
+
],
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
useLayoutEffect(() => {
|
|
180
|
+
pageSearcherRef.current = null;
|
|
181
|
+
setInitStatus('initial');
|
|
182
|
+
setSearchError(undefined);
|
|
183
|
+
}, [searchEnabled, lang, searchVersion, searchIndexURL]);
|
|
184
|
+
|
|
165
185
|
const initSearch = async () => {
|
|
166
|
-
|
|
186
|
+
const searcher = createSearcher();
|
|
187
|
+
if (
|
|
188
|
+
initStatus !== 'initial' &&
|
|
189
|
+
initializationRef.current?.searcher === searcher
|
|
190
|
+
) {
|
|
167
191
|
return;
|
|
168
192
|
}
|
|
169
|
-
const searcher = createSearcher();
|
|
170
193
|
setSearchError(undefined);
|
|
171
194
|
setInitStatus('initing');
|
|
172
195
|
try {
|
|
173
196
|
await initializeSearcher(searcher);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return;
|
|
197
|
+
if (pageSearcherRef.current === searcher) {
|
|
198
|
+
setInitStatus('inited');
|
|
177
199
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
if (pageSearcherRef.current !== searcher) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
setInitStatus('inited');
|
|
187
|
-
const currentQuery = searchInputRef.current?.value;
|
|
188
|
-
if (currentQuery) {
|
|
189
|
-
const matched = await searcher.match(currentQuery);
|
|
190
|
-
if (
|
|
191
|
-
pageSearcherRef.current !== searcher ||
|
|
192
|
-
searchInputRef.current?.value !== currentQuery
|
|
193
|
-
) {
|
|
194
|
-
return;
|
|
200
|
+
} catch (error) {
|
|
201
|
+
if (pageSearcherRef.current === searcher) {
|
|
202
|
+
setSearchError(error instanceof Error ? error.message : String(error));
|
|
203
|
+
setInitStatus('error');
|
|
195
204
|
}
|
|
196
|
-
setSearchResult(matched || DEFAULT_RESULT);
|
|
197
|
-
setIsSearching(false);
|
|
198
205
|
}
|
|
199
206
|
};
|
|
200
207
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
setSearchResult(DEFAULT_RESULT);
|
|
207
|
-
initSearch();
|
|
208
|
-
} else {
|
|
209
|
-
setQuery('');
|
|
210
|
-
}
|
|
211
|
-
}, [focused, searchEnabled]);
|
|
212
|
-
|
|
213
|
-
useEffect(() => {
|
|
214
|
-
if (!searchEnabled) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
const { currentLang, currentVersion } = pageSearcherConfigRef.current ?? {};
|
|
218
|
-
const isLangChanged = lang !== currentLang;
|
|
219
|
-
const isVersionChanged = versionedSearch && version !== currentVersion;
|
|
220
|
-
const isIndexChanged = pageSearcherURLRef.current !== searchIndexURL;
|
|
221
|
-
if (isLangChanged || isVersionChanged || isIndexChanged) {
|
|
222
|
-
setInitStatus('initial');
|
|
223
|
-
setSearchError(undefined);
|
|
224
|
-
setIsSearching(false);
|
|
225
|
-
pageSearcherRef.current = null;
|
|
226
|
-
}
|
|
227
|
-
}, [lang, version, versionedSearch, searchEnabled, searchIndexURL]);
|
|
208
|
+
const runQuery = async (value: string, requestId: number) => {
|
|
209
|
+
const isCurrent = () =>
|
|
210
|
+
requestId === requestIdRef.current &&
|
|
211
|
+
searchInputRef.current?.value === value;
|
|
212
|
+
if (!isCurrent()) return;
|
|
228
213
|
|
|
229
|
-
|
|
230
|
-
const newQuery = value;
|
|
231
|
-
setQuery(newQuery);
|
|
232
|
-
if (!newQuery) {
|
|
233
|
-
setIsSearching(false);
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
214
|
+
setQuery(value);
|
|
236
215
|
try {
|
|
237
216
|
const result = await searchDocs(value);
|
|
238
|
-
if (
|
|
217
|
+
if (isCurrent()) {
|
|
239
218
|
setSearchError(undefined);
|
|
240
219
|
setInitStatus('inited');
|
|
241
220
|
setCurrentSuggestionIndex(0);
|
|
242
|
-
setSearchResult(result
|
|
221
|
+
setSearchResult(result);
|
|
243
222
|
setIsSearching(false);
|
|
244
223
|
}
|
|
245
224
|
} catch (error) {
|
|
246
|
-
if (
|
|
225
|
+
if (isCurrent()) {
|
|
247
226
|
setSearchError(error instanceof Error ? error.message : String(error));
|
|
248
227
|
setInitStatus('error');
|
|
249
228
|
setIsSearching(false);
|
|
@@ -251,16 +230,41 @@ export function useSearchPanel({
|
|
|
251
230
|
}
|
|
252
231
|
};
|
|
253
232
|
|
|
254
|
-
const handleQueryChange = useDebounce(handleQueryChangedImpl);
|
|
255
|
-
const handleQueryInput = (value: string) => {
|
|
256
|
-
setIsSearching(Boolean(value));
|
|
257
|
-
handleQueryChange(value);
|
|
258
|
-
};
|
|
259
233
|
const clearQuery = () => {
|
|
234
|
+
invalidateQuery();
|
|
260
235
|
setQuery('');
|
|
261
236
|
setIsSearching(false);
|
|
262
237
|
};
|
|
263
238
|
|
|
239
|
+
const handleQueryInput = (value: string) => {
|
|
240
|
+
if (!value) {
|
|
241
|
+
clearQuery();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
// Assign the ID before debounce so a previous request cannot publish while
|
|
245
|
+
// the latest input is waiting to start, even if the text is identical.
|
|
246
|
+
const requestId = ++requestIdRef.current;
|
|
247
|
+
setIsSearching(true);
|
|
248
|
+
scheduleQuery(() => {
|
|
249
|
+
void runQuery(value, requestId);
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
if (!focused || !searchEnabled) {
|
|
255
|
+
clearQuery();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
setSearchResult(DEFAULT_RESULT);
|
|
260
|
+
const value = searchInputRef.current?.value;
|
|
261
|
+
if (value) {
|
|
262
|
+
handleQueryInput(value);
|
|
263
|
+
} else {
|
|
264
|
+
void initSearch();
|
|
265
|
+
}
|
|
266
|
+
}, [focused, searchEnabled, lang, searchVersion, searchIndexURL]);
|
|
267
|
+
|
|
264
268
|
return {
|
|
265
269
|
searchEnabled,
|
|
266
270
|
clearQuery,
|
|
@@ -40,18 +40,22 @@
|
|
|
40
40
|
&--active {
|
|
41
41
|
color: var(--rp-c-link);
|
|
42
42
|
background-color: var(--rp-c-brand-tint);
|
|
43
|
-
font-weight: 600;
|
|
44
43
|
&:hover {
|
|
45
44
|
color: var(--rp-c-link);
|
|
46
45
|
background-color: var(--rp-c-brand-tint);
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
|
|
49
|
+
&:focus-visible {
|
|
50
|
+
outline: 2px solid var(--rp-c-brand);
|
|
51
|
+
outline-offset: -2px;
|
|
52
|
+
}
|
|
53
|
+
|
|
50
54
|
&--group-item::before {
|
|
51
55
|
content: '';
|
|
52
56
|
position: absolute;
|
|
53
|
-
top:
|
|
54
|
-
left:
|
|
57
|
+
top: -2px;
|
|
58
|
+
left: -7px;
|
|
55
59
|
bottom: 0;
|
|
56
60
|
width: 1px;
|
|
57
61
|
background-color: var(--rp-c-divider-light);
|
|
@@ -61,10 +65,9 @@
|
|
|
61
65
|
.rp-sidebar-item__left::before {
|
|
62
66
|
content: '';
|
|
63
67
|
position: absolute;
|
|
64
|
-
top:
|
|
65
|
-
bottom:
|
|
66
|
-
left:
|
|
67
|
-
height: calc(50% - 4px);
|
|
68
|
+
top: 8px;
|
|
69
|
+
bottom: 8px;
|
|
70
|
+
left: -7px;
|
|
68
71
|
width: 1px;
|
|
69
72
|
background-color: var(--rp-c-brand);
|
|
70
73
|
}
|
|
@@ -88,7 +88,7 @@ export function SidebarItemRaw({
|
|
|
88
88
|
className,
|
|
89
89
|
)}
|
|
90
90
|
style={{
|
|
91
|
-
|
|
91
|
+
marginLeft: depth * 24,
|
|
92
92
|
}}
|
|
93
93
|
{...{ 'data-depth': depth }}
|
|
94
94
|
{...(context ? { 'data-context': context } : {})}
|
|
@@ -110,7 +110,7 @@ export function SidebarItemRaw({
|
|
|
110
110
|
className,
|
|
111
111
|
)}
|
|
112
112
|
style={{
|
|
113
|
-
|
|
113
|
+
marginLeft: depth * 24,
|
|
114
114
|
}}
|
|
115
115
|
{...{ 'data-depth': depth }}
|
|
116
116
|
{...(context ? { 'data-context': context } : {})}
|