@rspress/core 2.0.8 → 2.0.10
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/0~execa.js +8 -8
- package/dist/0~rslib-runtime.js +20 -0
- package/dist/0~tinypool.js +828 -0
- package/dist/{8311.js → 1688.js} +1 -7
- package/dist/{7397.js → 2240.js} +4 -2
- package/dist/2287.js +2458 -0
- package/dist/{1361.js → 3294.js} +1 -1
- package/dist/{1965.js → 3425.js} +0 -1
- package/dist/8006.js +77 -0
- package/dist/8857.js +4826 -0
- package/dist/8857.js.LICENSE.txt +41 -0
- package/dist/cli/index.js +14 -7
- package/dist/config/loadConfigFile.js +1 -1
- package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.scss +1 -1
- package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.tsx +17 -21
- package/dist/eject-theme/components/CodeButtonGroup/index.scss +1 -1
- package/dist/eject-theme/components/DocContent/doc.scss +16 -41
- package/dist/eject-theme/components/FallbackHeading/index.tsx +1 -1
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +4 -1
- package/dist/eject-theme/components/Llms/LlmsCopyButton.scss +3 -3
- package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +13 -6
- package/dist/eject-theme/components/Llms/LlmsCopyRow.tsx +13 -5
- package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +7 -3
- package/dist/eject-theme/components/Outline/index.scss +1 -1
- package/dist/eject-theme/components/Prompt/icons.tsx +80 -0
- package/dist/eject-theme/components/Prompt/index.scss +478 -0
- package/dist/eject-theme/components/Prompt/index.tsx +335 -0
- package/dist/eject-theme/components/Search/SearchPanel.tsx +1 -1
- package/dist/eject-theme/components/SidebarMenu/index.tsx +5 -1
- package/dist/eject-theme/components/Steps/index.scss +32 -13
- package/dist/node/PluginDriver.js +1 -1
- package/dist/node/auto-nav-sidebar/index.js +1 -1
- package/dist/node/auto-nav-sidebar/locales.js +1 -1
- package/dist/node/auto-nav-sidebar/normalize.js +10 -6
- package/dist/node/auto-nav-sidebar/utils.js +8 -2
- package/dist/node/auto-nav-sidebar/walk.js +2 -8
- package/dist/node/constants.js +1 -1
- package/dist/node/eject.js +12 -7
- package/dist/node/initRsbuild.js +6 -6
- package/dist/node/logger/hint.js +9 -6
- package/dist/node/mdx/options.js +13 -2
- package/dist/node/mdx/processor.js +1 -1
- package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
- package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
- package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +6 -2
- package/dist/node/mdx/remarkPlugins/image.d.ts +7 -2
- package/dist/node/mdx/remarkPlugins/image.js +51 -2
- package/dist/node/mdx/remarkPlugins/link.js +7 -3
- package/dist/node/mdx/remarkPlugins/toc.js +1 -1
- package/dist/node/route/RoutePage.js +1 -1
- package/dist/node/route/RouteService.js +1 -1
- package/dist/node/route/extractPageData.js +75 -26
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +28 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +28 -0
- package/dist/node/runtimeModule/i18n.js +10 -6
- package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +1 -1
- package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
- package/dist/node/serve.js +1 -1
- package/dist/node/ssg/renderPage.js +8 -4
- package/dist/node/ssg/renderPageWorker.js +1 -1
- package/dist/node/ssg/renderPages.js +9 -5
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
- package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
- package/dist/node/ssg-md/renderPage.js +8 -4
- package/dist/node/ssg-md/renderPages.js +7 -3
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
- package/dist/node/utils/checkLanguageParity.js +1 -1
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/error.js +5 -2
- package/dist/node/utils/flattenMdxContent.js +1 -1
- package/dist/node/utils/fs.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/normalizePath.js +1 -1
- package/dist/node/utils/reactAlias.js +7 -3
- package/dist/runtime/App.js +4 -1
- package/dist/runtime/index.d.ts +2 -1
- package/dist/runtime/index.js +2 -1
- package/dist/runtime/initPageData.d.ts +3 -0
- package/dist/runtime/initPageData.js +37 -2
- package/dist/runtime/ssrClientEntry.js +4 -2
- package/dist/theme/assets/success.js +1 -1
- package/dist/theme/assets/wrapped.js +1 -1
- package/dist/theme/components/CodeButtonGroup/CopyCodeButton.css +1 -1
- package/dist/theme/components/CodeButtonGroup/CopyCodeButton.js +14 -12
- package/dist/theme/components/CodeButtonGroup/index.css +1 -1
- package/dist/theme/components/DocContent/doc.css +14 -21
- package/dist/theme/components/FallbackHeading/index.js +1 -1
- package/dist/theme/components/Link/useLinkNavigate.js +3 -2
- package/dist/theme/components/Llms/LlmsCopyButton.css +5 -5
- package/dist/theme/components/Llms/LlmsCopyButton.js +5 -6
- package/dist/theme/components/Llms/LlmsCopyRow.js +5 -5
- package/dist/theme/components/Llms/LlmsViewOptions.js +1 -3
- package/dist/theme/components/Outline/index.css +1 -1
- package/dist/theme/components/Prompt/icons.d.ts +10 -0
- package/dist/theme/components/Prompt/icons.js +64 -0
- package/dist/theme/components/Prompt/index.css +352 -0
- package/dist/theme/components/Prompt/index.d.ts +33 -0
- package/dist/theme/components/Prompt/index.js +262 -0
- package/dist/theme/components/Search/SearchPanel.js +1 -1
- package/dist/theme/components/SidebarMenu/index.js +2 -1
- package/dist/theme/components/Steps/index.css +23 -12
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/index.js +3 -0
- package/dist/theme/layout/DocLayout/index.css +5 -1
- package/dist/theme/layout/DocLayout/index.js +8 -4
- package/dist/theme/logic/copyToClipboard.d.ts +1 -0
- package/dist/theme/{components/Llms/copy.js → logic/copyToClipboard.js} +4 -3
- package/dist/theme/logic/getCopyableText.d.ts +5 -0
- package/dist/theme/logic/getCopyableText.js +52 -0
- package/dist/theme/logic/useThemeState.js +1 -1
- package/dist/theme/styles/vars/base-vars.css +4 -4
- package/package.json +20 -23
- package/dist/4454.js +0 -8
- package/dist/7319.js +0 -88
- package/dist/8885.js +0 -4
- package/dist/eject-theme/components/Llms/copy.ts +0 -12
- package/dist/theme/components/Llms/copy.d.ts +0 -1
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { useI18n } from '@rspress/core/runtime';
|
|
2
|
+
import {
|
|
3
|
+
copyToClipboard,
|
|
4
|
+
IconArrowDown,
|
|
5
|
+
IconCopy,
|
|
6
|
+
IconSuccess,
|
|
7
|
+
renderInlineMarkdown,
|
|
8
|
+
SvgWrapper,
|
|
9
|
+
} from '@rspress/core/theme';
|
|
10
|
+
import clsx from 'clsx';
|
|
11
|
+
import { useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
12
|
+
import { AGENT_ICONS } from './icons';
|
|
13
|
+
import './index.scss';
|
|
14
|
+
|
|
15
|
+
const ROTATE_INTERVAL = 3500;
|
|
16
|
+
const FADE_DURATION = 400;
|
|
17
|
+
|
|
18
|
+
function RotatingIcon({ index, fading }: { index: number; fading: boolean }) {
|
|
19
|
+
return (
|
|
20
|
+
<span
|
|
21
|
+
className={clsx('rp-prompt__icon', fading && 'rp-prompt__icon--fade-out')}
|
|
22
|
+
title={AGENT_ICONS[index].name}
|
|
23
|
+
>
|
|
24
|
+
{AGENT_ICONS[index].svg}
|
|
25
|
+
</span>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function useRotatingIcon() {
|
|
30
|
+
const [iconIndex, setIconIndex] = useState(0);
|
|
31
|
+
const [fading, setFading] = useState(false);
|
|
32
|
+
const rotateTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const timer = setInterval(() => {
|
|
36
|
+
setFading(true);
|
|
37
|
+
rotateTimeoutRef.current = setTimeout(() => {
|
|
38
|
+
setIconIndex(prev => (prev + 1) % AGENT_ICONS.length);
|
|
39
|
+
setFading(false);
|
|
40
|
+
rotateTimeoutRef.current = null;
|
|
41
|
+
}, FADE_DURATION);
|
|
42
|
+
}, ROTATE_INTERVAL);
|
|
43
|
+
return () => {
|
|
44
|
+
clearInterval(timer);
|
|
45
|
+
if (rotateTimeoutRef.current) {
|
|
46
|
+
clearTimeout(rotateTimeoutRef.current);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
return { fading, iconIndex };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface PromptProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
55
|
+
/**
|
|
56
|
+
* Render custom MDX content without copy or collapse behavior.
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
custom?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Inline description rendered in the prompt header.
|
|
62
|
+
*/
|
|
63
|
+
description?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Header label for the prompt block.
|
|
66
|
+
* @default 'Agent Prompt'
|
|
67
|
+
*/
|
|
68
|
+
title?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Eyebrow label shown above the title.
|
|
71
|
+
* @default 'For your Agent'
|
|
72
|
+
*/
|
|
73
|
+
eyebrow?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Controls the initial folded state.
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
defaultCollapsed?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* The prompt text to display and copy.
|
|
81
|
+
*/
|
|
82
|
+
prompt?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function CustomPrompt({
|
|
86
|
+
children,
|
|
87
|
+
className,
|
|
88
|
+
defaultCollapsed: _defaultCollapsed,
|
|
89
|
+
description: _description,
|
|
90
|
+
eyebrow = 'For your Agent',
|
|
91
|
+
prompt: _prompt,
|
|
92
|
+
style,
|
|
93
|
+
title: _title,
|
|
94
|
+
...props
|
|
95
|
+
}: PromptProps) {
|
|
96
|
+
const { fading, iconIndex } = useRotatingIcon();
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div
|
|
100
|
+
{...props}
|
|
101
|
+
className={clsx('rp-prompt', 'rp-prompt--custom', className)}
|
|
102
|
+
style={
|
|
103
|
+
{
|
|
104
|
+
'--rp-prompt-accent': AGENT_ICONS[iconIndex].color,
|
|
105
|
+
...style,
|
|
106
|
+
} as React.CSSProperties
|
|
107
|
+
}
|
|
108
|
+
>
|
|
109
|
+
<div className="rp-prompt__backdrop" />
|
|
110
|
+
<div className="rp-prompt__panel">
|
|
111
|
+
<div className="rp-prompt__meta">
|
|
112
|
+
<span className="rp-prompt__eyebrow">
|
|
113
|
+
<RotatingIcon index={iconIndex} fading={fading} />
|
|
114
|
+
{eyebrow}
|
|
115
|
+
</span>
|
|
116
|
+
</div>
|
|
117
|
+
<div className="rp-prompt__custom-content">{children}</div>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function CopyablePrompt({
|
|
124
|
+
className,
|
|
125
|
+
defaultCollapsed = true,
|
|
126
|
+
description,
|
|
127
|
+
eyebrow = 'For your Agent',
|
|
128
|
+
onClick,
|
|
129
|
+
prompt,
|
|
130
|
+
style,
|
|
131
|
+
title = 'Agent Prompt',
|
|
132
|
+
...props
|
|
133
|
+
}: PromptProps) {
|
|
134
|
+
const t = useI18n();
|
|
135
|
+
const contentId = useId();
|
|
136
|
+
const [collapsed, setCollapsed] = useState(defaultCollapsed);
|
|
137
|
+
const [copied, setCopied] = useState(false);
|
|
138
|
+
const { fading, iconIndex } = useRotatingIcon();
|
|
139
|
+
const [ripples, setRipples] = useState<
|
|
140
|
+
Array<{ id: number; x: number; y: number }>
|
|
141
|
+
>([]);
|
|
142
|
+
const cardRef = useRef<HTMLDivElement>(null);
|
|
143
|
+
const copyTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
144
|
+
const rippleTimersRef = useRef<Set<ReturnType<typeof setTimeout>>>(new Set());
|
|
145
|
+
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
return () => {
|
|
148
|
+
copyTimerRef.current && clearTimeout(copyTimerRef.current);
|
|
149
|
+
rippleTimersRef.current.forEach(clearTimeout);
|
|
150
|
+
rippleTimersRef.current.clear();
|
|
151
|
+
};
|
|
152
|
+
}, []);
|
|
153
|
+
|
|
154
|
+
const handleCopy = useCallback(async () => {
|
|
155
|
+
if (!prompt) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const isCopied = await copyToClipboard(prompt);
|
|
160
|
+
if (!isCopied) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
setCopied(true);
|
|
165
|
+
|
|
166
|
+
if (copyTimerRef.current) {
|
|
167
|
+
clearTimeout(copyTimerRef.current);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
copyTimerRef.current = setTimeout(() => {
|
|
171
|
+
setCopied(false);
|
|
172
|
+
copyTimerRef.current = null;
|
|
173
|
+
}, 2000);
|
|
174
|
+
}, [prompt]);
|
|
175
|
+
|
|
176
|
+
const handleCardActivate = useCallback(
|
|
177
|
+
(e: React.MouseEvent<HTMLDivElement>) => {
|
|
178
|
+
onClick?.(e);
|
|
179
|
+
if (e.defaultPrevented) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (window.getSelection()?.toString()) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const target = e.target as HTMLElement;
|
|
188
|
+
if (
|
|
189
|
+
target.closest(
|
|
190
|
+
'a, button, .rp-prompt__action-copy, .rp-prompt__action-toggle',
|
|
191
|
+
)
|
|
192
|
+
) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const rect = cardRef.current?.getBoundingClientRect();
|
|
197
|
+
if (!rect) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const id = Date.now() + Math.random();
|
|
202
|
+
setRipples(prev => [
|
|
203
|
+
...prev,
|
|
204
|
+
{ id, x: e.clientX - rect.left, y: e.clientY - rect.top },
|
|
205
|
+
]);
|
|
206
|
+
const timer = setTimeout(() => {
|
|
207
|
+
setRipples(prev => prev.filter(r => r.id !== id));
|
|
208
|
+
rippleTimersRef.current.delete(timer);
|
|
209
|
+
}, 600);
|
|
210
|
+
rippleTimersRef.current.add(timer);
|
|
211
|
+
|
|
212
|
+
void handleCopy();
|
|
213
|
+
},
|
|
214
|
+
[handleCopy, onClick],
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<div
|
|
219
|
+
{...props}
|
|
220
|
+
ref={cardRef}
|
|
221
|
+
className={clsx('rp-prompt', className)}
|
|
222
|
+
style={
|
|
223
|
+
{
|
|
224
|
+
'--rp-prompt-accent': AGENT_ICONS[iconIndex].color,
|
|
225
|
+
...style,
|
|
226
|
+
} as React.CSSProperties
|
|
227
|
+
}
|
|
228
|
+
onClick={handleCardActivate}
|
|
229
|
+
>
|
|
230
|
+
<div className="rp-prompt__backdrop" />
|
|
231
|
+
{ripples.map(r => (
|
|
232
|
+
<span
|
|
233
|
+
key={r.id}
|
|
234
|
+
className="rp-prompt__ripple"
|
|
235
|
+
style={{ left: r.x, top: r.y }}
|
|
236
|
+
/>
|
|
237
|
+
))}
|
|
238
|
+
<div className="rp-prompt__panel">
|
|
239
|
+
<div className="rp-prompt__header">
|
|
240
|
+
<div
|
|
241
|
+
className={clsx(
|
|
242
|
+
'rp-prompt__meta',
|
|
243
|
+
copied && 'rp-prompt__meta--copied',
|
|
244
|
+
)}
|
|
245
|
+
>
|
|
246
|
+
<span className="rp-prompt__eyebrow">
|
|
247
|
+
<RotatingIcon index={iconIndex} fading={fading} />
|
|
248
|
+
{eyebrow}
|
|
249
|
+
</span>
|
|
250
|
+
</div>
|
|
251
|
+
<div className="rp-prompt__header-row">
|
|
252
|
+
<div className="rp-prompt__header-left">
|
|
253
|
+
<div className="rp-prompt__title-with-icon">
|
|
254
|
+
<div className="rp-prompt__title">{title}</div>
|
|
255
|
+
</div>
|
|
256
|
+
{description ? (
|
|
257
|
+
<p
|
|
258
|
+
className="rp-prompt__description"
|
|
259
|
+
{...renderInlineMarkdown(description)}
|
|
260
|
+
/>
|
|
261
|
+
) : null}
|
|
262
|
+
</div>
|
|
263
|
+
<div className="rp-prompt__header-actions">
|
|
264
|
+
<button
|
|
265
|
+
type="button"
|
|
266
|
+
className={clsx(
|
|
267
|
+
'rp-prompt__action-copy',
|
|
268
|
+
copied && 'rp-prompt__action-copy--copied',
|
|
269
|
+
)}
|
|
270
|
+
onClick={e => {
|
|
271
|
+
e.stopPropagation();
|
|
272
|
+
void handleCopy();
|
|
273
|
+
}}
|
|
274
|
+
title={t('promptCopyText')}
|
|
275
|
+
>
|
|
276
|
+
<SvgWrapper
|
|
277
|
+
icon={copied ? IconSuccess : IconCopy}
|
|
278
|
+
className="rp-prompt__action-icon"
|
|
279
|
+
/>
|
|
280
|
+
<span>
|
|
281
|
+
{copied ? t('promptCopiedText') : t('promptCopyText')}
|
|
282
|
+
</span>
|
|
283
|
+
</button>
|
|
284
|
+
<button
|
|
285
|
+
type="button"
|
|
286
|
+
className="rp-prompt__action-toggle"
|
|
287
|
+
onClick={e => {
|
|
288
|
+
e.stopPropagation();
|
|
289
|
+
setCollapsed(value => !value);
|
|
290
|
+
}}
|
|
291
|
+
aria-controls={contentId}
|
|
292
|
+
aria-expanded={!collapsed}
|
|
293
|
+
title={
|
|
294
|
+
collapsed ? t('promptExpandText') : t('promptCollapseText')
|
|
295
|
+
}
|
|
296
|
+
>
|
|
297
|
+
<SvgWrapper
|
|
298
|
+
icon={IconArrowDown}
|
|
299
|
+
className={clsx(
|
|
300
|
+
'rp-prompt__action-toggle-icon',
|
|
301
|
+
!collapsed && 'rp-prompt__action-toggle-icon--expanded',
|
|
302
|
+
)}
|
|
303
|
+
/>
|
|
304
|
+
</button>
|
|
305
|
+
</div>
|
|
306
|
+
</div>
|
|
307
|
+
</div>
|
|
308
|
+
|
|
309
|
+
<div
|
|
310
|
+
id={contentId}
|
|
311
|
+
className={clsx(
|
|
312
|
+
'rp-prompt__content',
|
|
313
|
+
collapsed && 'rp-prompt__content--collapsed',
|
|
314
|
+
)}
|
|
315
|
+
aria-hidden={collapsed}
|
|
316
|
+
>
|
|
317
|
+
<div className="rp-prompt__content-inner">
|
|
318
|
+
<div
|
|
319
|
+
className="rp-prompt__content-body"
|
|
320
|
+
style={{ whiteSpace: 'pre-wrap' }}
|
|
321
|
+
>
|
|
322
|
+
{prompt}
|
|
323
|
+
</div>
|
|
324
|
+
</div>
|
|
325
|
+
</div>
|
|
326
|
+
</div>
|
|
327
|
+
</div>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function Prompt({ custom = false, ...props }: PromptProps) {
|
|
332
|
+
return custom ? <CustomPrompt {...props} /> : <CopyablePrompt {...props} />;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export default Prompt;
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
Tabs,
|
|
9
9
|
useLinkNavigate,
|
|
10
10
|
} from '@rspress/core/theme';
|
|
11
|
-
import { debounce } from 'lodash-es';
|
|
11
|
+
import { debounce } from '@rspress/shared/lodash-es';
|
|
12
12
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
13
13
|
import { createPortal } from 'react-dom';
|
|
14
14
|
import * as userSearchHooks from 'virtual-search-hooks';
|
|
@@ -37,8 +37,12 @@ export const SidebarMenu = forwardRef(
|
|
|
37
37
|
const { scrolledHeader } = useActiveAnchor(headers);
|
|
38
38
|
|
|
39
39
|
const {
|
|
40
|
-
frontmatter: {
|
|
40
|
+
frontmatter: {
|
|
41
|
+
sidebar: sidebarConfig = true,
|
|
42
|
+
outline: showOutline = true,
|
|
43
|
+
},
|
|
41
44
|
} = useFrontmatter();
|
|
45
|
+
const showSidebar = sidebarConfig === true;
|
|
42
46
|
|
|
43
47
|
function openSidebar() {
|
|
44
48
|
onIsSidebarOpenChange(true);
|
|
@@ -1,35 +1,54 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--rp-steps-gap: 24px;
|
|
3
|
+
--rp-steps-size: 30px;
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
.rp-steps {
|
|
2
|
-
margin-left:
|
|
3
|
-
margin-bottom:
|
|
7
|
+
margin-left: 1rem;
|
|
8
|
+
margin-bottom: 2.5rem;
|
|
4
9
|
border-left: 1px solid var(--rp-c-text-3);
|
|
5
|
-
padding-left:
|
|
10
|
+
padding-left: var(--rp-steps-gap);
|
|
6
11
|
counter-reset: step;
|
|
7
12
|
|
|
8
13
|
h3 {
|
|
9
14
|
counter-increment: step;
|
|
10
|
-
margin-top:
|
|
15
|
+
margin-top: 0;
|
|
11
16
|
position: relative;
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
min-height: 30px;
|
|
12
20
|
|
|
13
21
|
&::before {
|
|
22
|
+
// position
|
|
14
23
|
content: counter(step);
|
|
15
24
|
position: absolute;
|
|
16
|
-
left: -
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
left: calc(-1 * var(--rp-steps-gap));
|
|
26
|
+
transform: translate(-50%, 0);
|
|
27
|
+
|
|
28
|
+
// size
|
|
29
|
+
width: var(--rp-steps-size);
|
|
30
|
+
height: var(--rp-steps-size);
|
|
31
|
+
line-height: var(--rp-steps-size);
|
|
32
|
+
|
|
33
|
+
// text
|
|
19
34
|
display: flex;
|
|
20
35
|
align-items: center;
|
|
21
36
|
justify-content: center;
|
|
22
37
|
font-size: 1.1rem;
|
|
23
|
-
font-weight:
|
|
24
|
-
line-height: 30px;
|
|
38
|
+
font-weight: 500;
|
|
25
39
|
color: var(--rp-c-text-1);
|
|
26
|
-
|
|
40
|
+
|
|
41
|
+
// style
|
|
42
|
+
background-color: var(--rp-c-bg);
|
|
43
|
+
outline: 6px solid var(--rp-c-bg);
|
|
27
44
|
border: 1.5px solid var(--rp-c-text-3);
|
|
28
45
|
border-radius: 50%;
|
|
29
46
|
}
|
|
30
|
-
}
|
|
31
47
|
|
|
32
|
-
|
|
33
|
-
|
|
48
|
+
/* anchor link: move to the front and ensure it's clickable */
|
|
49
|
+
.rp-header-anchor {
|
|
50
|
+
position: absolute;
|
|
51
|
+
left: calc(-1 * var(--rp-steps-gap) - var(--rp-steps-size) / 2);
|
|
52
|
+
}
|
|
34
53
|
}
|
|
35
54
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addTrailingSlash, node_path, addLeadingSlash } from "../
|
|
1
|
+
import { addTrailingSlash, node_path, addLeadingSlash } from "../2287.js";
|
|
2
2
|
import { createError } from "./utils/error.js";
|
|
3
3
|
import { haveNavSidebarConfig as auto_nav_sidebar_haveNavSidebarConfig } from "./auto-nav-sidebar/index.js";
|
|
4
4
|
class PluginDriver {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../
|
|
1
|
+
import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../2287.js";
|
|
2
2
|
import { processLocales, combineWalkResult } from "./locales.js";
|
|
3
3
|
import { walk } from "./walk.js";
|
|
4
4
|
async function runAutoNavSide(config, metaFileSet, mdFileSet) {
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __webpack_require__ } from "../../0~rslib-runtime.js";
|
|
2
|
+
import "../../8006.js";
|
|
3
|
+
import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../2287.js";
|
|
2
4
|
import { createError } from "../utils/error.js";
|
|
3
5
|
import { PUBLIC_DIR } from "../constants.js";
|
|
4
6
|
import { pathExists, extractInfoFromFrontmatterWithAbsolutePath, readJson } from "./utils.js";
|
|
5
7
|
import { absolutePathToRoutePath, addRoutePrefix } from "../route/RoutePage.js";
|
|
6
8
|
import { RouteService } from "../route/RouteService.js";
|
|
9
|
+
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
10
|
+
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
|
7
11
|
const AUTO_NAV_SIDEBAR_ERROR_PREFIX = '[auto-nav-sidebar] ';
|
|
8
12
|
function getFileKey(realPath, docsDir) {
|
|
9
|
-
return realPath ? slash(
|
|
13
|
+
return realPath ? slash(external_node_path_relative(docsDir, realPath).replace(extname(realPath), '')) : '';
|
|
10
14
|
}
|
|
11
15
|
async function fsDirToMetaItems(workDir, docsDir, extensions) {
|
|
12
16
|
let subItems;
|
|
13
17
|
try {
|
|
14
|
-
subItems = (await
|
|
18
|
+
subItems = (await promises_readdir(workDir)).sort((a, b)=>{
|
|
15
19
|
const aIsIndex = 'index' === a.replace(/\.[^/.]+$/, '');
|
|
16
20
|
const bIsIndex = 'index' === b.replace(/\.[^/.]+$/, '');
|
|
17
21
|
if (aIsIndex !== bIsIndex) return aIsIndex ? -1 : 1;
|
|
@@ -19,7 +23,7 @@ async function fsDirToMetaItems(workDir, docsDir, extensions) {
|
|
|
19
23
|
});
|
|
20
24
|
} catch (e) {
|
|
21
25
|
const metaFilePath = join(workDir, '_meta.json');
|
|
22
|
-
throw createError(`${AUTO_NAV_SIDEBAR_ERROR_PREFIX}Failed to read directory: ${
|
|
26
|
+
throw createError(`${AUTO_NAV_SIDEBAR_ERROR_PREFIX}Failed to read directory: ${picocolors_default().yellow(workDir)}, maybe it does not exist. Please check it in ${picocolors_default().cyan(metaFilePath)}. (${e})`);
|
|
23
27
|
}
|
|
24
28
|
subItems = subItems.filter((item)=>{
|
|
25
29
|
const hasExtension = extensions.some((ext)=>item.endsWith(ext));
|
|
@@ -79,13 +83,13 @@ async function metaFileItemToSidebarItem(metaItemRaw, workDir, docsDir, extensio
|
|
|
79
83
|
} : metaItemRaw;
|
|
80
84
|
const { name, context, label, overviewHeaders, tag } = metaItem;
|
|
81
85
|
const metaFilePath = join(workDir, '_meta.json');
|
|
82
|
-
if ('string' != typeof name) throw createError(`${AUTO_NAV_SIDEBAR_ERROR_PREFIX}The file name "${name}" is not a string, please check it in ${
|
|
86
|
+
if ('string' != typeof name) throw createError(`${AUTO_NAV_SIDEBAR_ERROR_PREFIX}The file name "${name}" is not a string, please check it in ${picocolors_default().cyan(metaFilePath)}.`);
|
|
83
87
|
const absolutePath = join(workDir, name);
|
|
84
88
|
let absolutePathWithExt;
|
|
85
89
|
try {
|
|
86
90
|
absolutePathWithExt = await detectFilePath(absolutePath, extensions);
|
|
87
91
|
} catch {
|
|
88
|
-
throw createError(`${AUTO_NAV_SIDEBAR_ERROR_PREFIX}${
|
|
92
|
+
throw createError(`${AUTO_NAV_SIDEBAR_ERROR_PREFIX}${picocolors_default().white('Missing page file:')} ${picocolors_default().yellow(`"${absolutePath}"`)}\n${picocolors_default().white('Please check')} ${picocolors_default().cyan(join(workDir, '_meta.json'))}.`);
|
|
89
93
|
}
|
|
90
94
|
const link = absolutePathToRoutePath(absolutePathWithExt, docsDir);
|
|
91
95
|
const routeService = RouteService.getInstance();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../
|
|
1
|
+
import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../2287.js";
|
|
2
|
+
import { createError } from "../utils/error.js";
|
|
2
3
|
async function pathExists(path) {
|
|
3
4
|
try {
|
|
4
5
|
await promises.access(path);
|
|
@@ -9,7 +10,12 @@ async function pathExists(path) {
|
|
|
9
10
|
}
|
|
10
11
|
async function readJson(path) {
|
|
11
12
|
const raw = await promises.readFile(path, 'utf8');
|
|
12
|
-
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(raw);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
const detail = error instanceof Error ? error.message : 'Unknown JSON parse error';
|
|
17
|
+
throw createError(`[auto-nav-sidebar] Failed to parse JSON file "${path}": ${detail}`);
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
20
|
async function extractInfoFromFrontmatterWithAbsolutePath(absolutePath, rootDir) {
|
|
15
21
|
const fileHandle = await promises.open(absolutePath, 'r');
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { isExternalUrl, node_path, promises } from "../../
|
|
1
|
+
import { isExternalUrl, node_path, promises } from "../../2287.js";
|
|
2
2
|
import { pathExists } from "../utils/fs.js";
|
|
3
3
|
import { readJson } from "./utils.js";
|
|
4
|
-
import { createError } from "../utils/error.js";
|
|
5
4
|
import { addRoutePrefix } from "../route/RoutePage.js";
|
|
6
5
|
import { hintNavJsonChangeThenPanic } from "../logger/hint.js";
|
|
7
6
|
import { scanSideMeta } from "./normalize.js";
|
|
@@ -11,12 +10,7 @@ async function scanNav(workDir, docsDir, metaFileSet) {
|
|
|
11
10
|
const isRootNavJsonExist = await pathExists(rootNavJson);
|
|
12
11
|
if (isRootNavJsonExist) {
|
|
13
12
|
metaFileSet.add(rootNavJson);
|
|
14
|
-
|
|
15
|
-
navConfig = await readJson(rootNavJson);
|
|
16
|
-
} catch (e) {
|
|
17
|
-
if (e instanceof Error) throw createError(`[auto-nav-sidebar] Generate nav meta error: ${rootNavJson} failed, original error is (${e.message})`);
|
|
18
|
-
throw e;
|
|
19
|
-
}
|
|
13
|
+
navConfig = await readJson(rootNavJson);
|
|
20
14
|
} else navConfig = [];
|
|
21
15
|
navConfig.forEach((navItem)=>{
|
|
22
16
|
if ('items' in navItem) navItem.items.forEach((item)=>{
|
package/dist/node/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRequire, node_path, package_namespaceObject } from "../
|
|
1
|
+
import { createRequire, node_path, package_namespaceObject } from "../8006.js";
|
|
2
2
|
const constants_require = createRequire(import.meta.url);
|
|
3
3
|
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
4
4
|
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
package/dist/node/eject.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __webpack_require__ } from "../0~rslib-runtime.js";
|
|
2
|
+
import "../8006.js";
|
|
3
|
+
import { node_path, logger, promises } from "../8857.js";
|
|
2
4
|
import { EJECTED_THEME } from "./constants.js";
|
|
5
|
+
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
6
|
+
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
|
3
7
|
let _themeComponentsPathOverride;
|
|
4
8
|
function getThemeComponentsPath() {
|
|
5
9
|
if (_themeComponentsPathOverride) return _themeComponentsPathOverride;
|
|
@@ -24,6 +28,7 @@ async function getAvailableComponents() {
|
|
|
24
28
|
'PackageManagerTabs',
|
|
25
29
|
'PrevNextPage',
|
|
26
30
|
'OverviewGroup',
|
|
31
|
+
'Prompt',
|
|
27
32
|
'Root',
|
|
28
33
|
'SocialLinks',
|
|
29
34
|
'Steps'
|
|
@@ -71,7 +76,7 @@ async function transformDirectory(dir) {
|
|
|
71
76
|
async function ejectComponent(componentName, cwd = process.cwd()) {
|
|
72
77
|
const exists = await componentExists(componentName);
|
|
73
78
|
if (!exists) {
|
|
74
|
-
logger.error(`Component ${
|
|
79
|
+
logger.error(`Component ${picocolors_default().cyan(componentName)} not found in theme.`);
|
|
75
80
|
const available = await getAvailableComponents();
|
|
76
81
|
logger.info(`\nAvailable components:\n${available.map((c)=>` - ${c}`).join('\n')}`);
|
|
77
82
|
process.exit(1);
|
|
@@ -82,7 +87,7 @@ async function ejectComponent(componentName, cwd = process.cwd()) {
|
|
|
82
87
|
const destComponentPath = node_path.join(destThemePath, componentName);
|
|
83
88
|
try {
|
|
84
89
|
await promises.access(destComponentPath);
|
|
85
|
-
logger.warn(`Component ${
|
|
90
|
+
logger.warn(`Component ${picocolors_default().cyan(componentName)} already exists in ${picocolors_default().yellow(node_path.relative(cwd, destComponentPath))}`);
|
|
86
91
|
logger.info('Overwriting existing component...');
|
|
87
92
|
} catch {}
|
|
88
93
|
try {
|
|
@@ -91,8 +96,8 @@ async function ejectComponent(componentName, cwd = process.cwd()) {
|
|
|
91
96
|
});
|
|
92
97
|
await copyDir(sourceComponentPath, destComponentPath);
|
|
93
98
|
await transformDirectory(destComponentPath);
|
|
94
|
-
logger.success(`✨ Component ${
|
|
95
|
-
logger.info(`Component files copied to: ${
|
|
99
|
+
logger.success(`✨ Component ${picocolors_default().cyan(componentName)} ejected successfully!`);
|
|
100
|
+
logger.info(`Component files copied to: ${picocolors_default().green(node_path.relative(cwd, destComponentPath))}\nYou can now customize the component. To use it in your theme, you'll need to:\n 1. Re-export it in your custom \`theme/index.tsx\` file\n 2. Edit it by yourself`);
|
|
96
101
|
} catch (error) {
|
|
97
102
|
logger.error(`Failed to eject component: ${error}`);
|
|
98
103
|
throw error;
|
|
@@ -102,9 +107,9 @@ async function listComponents() {
|
|
|
102
107
|
const components = await getAvailableComponents();
|
|
103
108
|
logger.info(`📦 Available components to eject:\n`);
|
|
104
109
|
components.forEach((component)=>{
|
|
105
|
-
logger.info(` ${
|
|
110
|
+
logger.info(` ${picocolors_default().cyan('•')} ${component}`);
|
|
106
111
|
});
|
|
107
|
-
logger.info(`💡 Usage: ${
|
|
112
|
+
logger.info(`💡 Usage: ${picocolors_default().dim('rspress eject <ComponentName>')}\n`);
|
|
108
113
|
}
|
|
109
114
|
var eject__setThemeComponentsPathForTesting = void 0;
|
|
110
115
|
var eject_getAvailableComponents = void 0;
|
package/dist/node/initRsbuild.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { external_node_process_cwd, node_path, external_node_url_fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, external_node_module_createRequire, removeTrailingSlash, pluginVirtualModule, pluginReact, MDX_OR_MD_REGEXP } from "../2287.js";
|
|
2
2
|
import { createError } from "./utils/error.js";
|
|
3
3
|
import { PUBLIC_DIR, CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY, inlineThemeScript, NODE_SSG_BUNDLE_FOLDER, isProduction, PACKAGE_ROOT, SSR_SERVER_ENTRY, TEMPLATE_PATH, NODE_SSG_MD_BUNDLE_FOLDER, DEFAULT_THEME, NODE_SSG_MD_BUNDLE_NAME, DEFAULT_TITLE, NODE_SSG_BUNDLE_NAME } from "./constants.js";
|
|
4
4
|
import { hintBuilderPluginsBreakingChange, hintThemeBreakingChange } from "./logger/hint.js";
|
|
@@ -14,11 +14,11 @@ import { siteDataVMPlugin } from "./runtimeModule/siteData/rsbuildPlugin.js";
|
|
|
14
14
|
import { rsbuildPluginSSG } from "./ssg/rsbuildPluginSSG.js";
|
|
15
15
|
import { rsbuildPluginCSR } from "./ssg/rsbuildPluginCSR.js";
|
|
16
16
|
import { rsbuildPluginSSGMD } from "./ssg-md/rsbuildPluginSSGMD.js";
|
|
17
|
-
import { package_namespaceObject } from "../
|
|
17
|
+
import { package_namespaceObject } from "../8006.js";
|
|
18
18
|
function isPluginIncluded(config, pluginName) {
|
|
19
19
|
return Boolean(config.builderConfig?.plugins?.some((plugin)=>plugin && plugin.name === pluginName));
|
|
20
20
|
}
|
|
21
|
-
const initRsbuild_require =
|
|
21
|
+
const initRsbuild_require = external_node_module_createRequire(import.meta.url);
|
|
22
22
|
async function getVirtualModulesFromPlugins(pluginDriver) {
|
|
23
23
|
const runtimeModule = {};
|
|
24
24
|
const modulesByPlugin = await pluginDriver.addRuntimeModules();
|
|
@@ -29,14 +29,14 @@ async function getVirtualModulesFromPlugins(pluginDriver) {
|
|
|
29
29
|
return runtimeModule;
|
|
30
30
|
}
|
|
31
31
|
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver) {
|
|
32
|
-
const CUSTOM_THEME_DIR = node_path.isAbsolute(config.themeDir) ? config.themeDir : node_path.join(
|
|
32
|
+
const CUSTOM_THEME_DIR = node_path.isAbsolute(config.themeDir) ? config.themeDir : node_path.join(external_node_process_cwd(), config.themeDir);
|
|
33
33
|
const outDir = config?.outDir ?? OUTPUT_DIR;
|
|
34
34
|
const base = config?.base ?? '/';
|
|
35
35
|
const assetPrefix = isProduction() ? addTrailingSlash(config?.builderConfig?.output?.assetPrefix ?? base) : '/';
|
|
36
36
|
const normalizeIcon = (icon)=>{
|
|
37
37
|
if (!icon) return;
|
|
38
38
|
icon = icon.toString();
|
|
39
|
-
if (icon.startsWith('file://')) icon =
|
|
39
|
+
if (icon.startsWith('file://')) icon = external_node_url_fileURLToPath(icon);
|
|
40
40
|
else if (node_path.isAbsolute(icon)) return node_path.join(userDocRoot, PUBLIC_DIR, icon);
|
|
41
41
|
return icon;
|
|
42
42
|
};
|
|
@@ -202,7 +202,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
202
202
|
chain.module.rule('MDX').type("javascript/auto").test(MDX_OR_MD_REGEXP).resolve.merge({
|
|
203
203
|
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
204
204
|
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
205
|
-
}).end().oneOf('MDXCompile').use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(
|
|
205
|
+
}).end().oneOf('MDXCompile').use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(external_node_url_fileURLToPath(new URL('./mdx/loader.js', import.meta.url))).options({
|
|
206
206
|
config,
|
|
207
207
|
docDirectory: userDocRoot,
|
|
208
208
|
routeService,
|