@rspress/core 2.0.9 → 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 +1 -1
- package/dist/{740.js → 2287.js} +127 -139
- package/dist/8006.js +1 -1
- package/dist/8857.js +2 -3
- package/dist/cli/index.js +7 -4
- package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.tsx +17 -21
- package/dist/eject-theme/components/DocContent/doc.scss +14 -41
- 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/SidebarMenu/index.tsx +5 -1
- 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 +2 -2
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/eject.js +1 -0
- package/dist/node/initRsbuild.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 +1 -1
- 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 +1 -1
- 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/renderPages.js +1 -1
- 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/renderPage.js +1 -1
- package/dist/node/ssg-md/renderPages.js +1 -1
- 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/flattenMdxContent.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/reactAlias.js +1 -1
- package/dist/theme/components/CodeButtonGroup/CopyCodeButton.js +14 -12
- package/dist/theme/components/DocContent/doc.css +13 -21
- 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/SidebarMenu/index.js +2 -1
- 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/styles/vars/base-vars.css +4 -4
- package/package.json +13 -13
- package/dist/eject-theme/components/Llms/copy.ts +0 -12
- package/dist/theme/components/Llms/copy.d.ts +0 -1
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useI18n } from "@rspress/core/runtime";
|
|
3
|
+
import { IconArrowDown, IconCopy, IconSuccess, SvgWrapper, copyToClipboard, renderInlineMarkdown } from "@rspress/core/theme";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
6
|
+
import { AGENT_ICONS } from "./icons.js";
|
|
7
|
+
import "./index.css";
|
|
8
|
+
const ROTATE_INTERVAL = 3500;
|
|
9
|
+
const FADE_DURATION = 400;
|
|
10
|
+
function RotatingIcon({ index, fading }) {
|
|
11
|
+
return /*#__PURE__*/ jsx("span", {
|
|
12
|
+
className: clsx('rp-prompt__icon', fading && 'rp-prompt__icon--fade-out'),
|
|
13
|
+
title: AGENT_ICONS[index].name,
|
|
14
|
+
children: AGENT_ICONS[index].svg
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function useRotatingIcon() {
|
|
18
|
+
const [iconIndex, setIconIndex] = useState(0);
|
|
19
|
+
const [fading, setFading] = useState(false);
|
|
20
|
+
const rotateTimeoutRef = useRef(null);
|
|
21
|
+
useEffect(()=>{
|
|
22
|
+
const timer = setInterval(()=>{
|
|
23
|
+
setFading(true);
|
|
24
|
+
rotateTimeoutRef.current = setTimeout(()=>{
|
|
25
|
+
setIconIndex((prev)=>(prev + 1) % AGENT_ICONS.length);
|
|
26
|
+
setFading(false);
|
|
27
|
+
rotateTimeoutRef.current = null;
|
|
28
|
+
}, FADE_DURATION);
|
|
29
|
+
}, ROTATE_INTERVAL);
|
|
30
|
+
return ()=>{
|
|
31
|
+
clearInterval(timer);
|
|
32
|
+
if (rotateTimeoutRef.current) clearTimeout(rotateTimeoutRef.current);
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
return {
|
|
36
|
+
fading,
|
|
37
|
+
iconIndex
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function CustomPrompt({ children, className, defaultCollapsed: _defaultCollapsed, description: _description, eyebrow = 'For your Agent', prompt: _prompt, style, title: _title, ...props }) {
|
|
41
|
+
const { fading, iconIndex } = useRotatingIcon();
|
|
42
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
43
|
+
...props,
|
|
44
|
+
className: clsx('rp-prompt', 'rp-prompt--custom', className),
|
|
45
|
+
style: {
|
|
46
|
+
'--rp-prompt-accent': AGENT_ICONS[iconIndex].color,
|
|
47
|
+
...style
|
|
48
|
+
},
|
|
49
|
+
children: [
|
|
50
|
+
/*#__PURE__*/ jsx("div", {
|
|
51
|
+
className: "rp-prompt__backdrop"
|
|
52
|
+
}),
|
|
53
|
+
/*#__PURE__*/ jsxs("div", {
|
|
54
|
+
className: "rp-prompt__panel",
|
|
55
|
+
children: [
|
|
56
|
+
/*#__PURE__*/ jsx("div", {
|
|
57
|
+
className: "rp-prompt__meta",
|
|
58
|
+
children: /*#__PURE__*/ jsxs("span", {
|
|
59
|
+
className: "rp-prompt__eyebrow",
|
|
60
|
+
children: [
|
|
61
|
+
/*#__PURE__*/ jsx(RotatingIcon, {
|
|
62
|
+
index: iconIndex,
|
|
63
|
+
fading: fading
|
|
64
|
+
}),
|
|
65
|
+
eyebrow
|
|
66
|
+
]
|
|
67
|
+
})
|
|
68
|
+
}),
|
|
69
|
+
/*#__PURE__*/ jsx("div", {
|
|
70
|
+
className: "rp-prompt__custom-content",
|
|
71
|
+
children: children
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
})
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function CopyablePrompt({ className, defaultCollapsed = true, description, eyebrow = 'For your Agent', onClick, prompt, style, title = 'Agent Prompt', ...props }) {
|
|
79
|
+
const t = useI18n();
|
|
80
|
+
const contentId = useId();
|
|
81
|
+
const [collapsed, setCollapsed] = useState(defaultCollapsed);
|
|
82
|
+
const [copied, setCopied] = useState(false);
|
|
83
|
+
const { fading, iconIndex } = useRotatingIcon();
|
|
84
|
+
const [ripples, setRipples] = useState([]);
|
|
85
|
+
const cardRef = useRef(null);
|
|
86
|
+
const copyTimerRef = useRef(null);
|
|
87
|
+
const rippleTimersRef = useRef(new Set());
|
|
88
|
+
useEffect(()=>()=>{
|
|
89
|
+
copyTimerRef.current && clearTimeout(copyTimerRef.current);
|
|
90
|
+
rippleTimersRef.current.forEach(clearTimeout);
|
|
91
|
+
rippleTimersRef.current.clear();
|
|
92
|
+
}, []);
|
|
93
|
+
const handleCopy = useCallback(async ()=>{
|
|
94
|
+
if (!prompt) return;
|
|
95
|
+
const isCopied = await copyToClipboard(prompt);
|
|
96
|
+
if (!isCopied) return;
|
|
97
|
+
setCopied(true);
|
|
98
|
+
if (copyTimerRef.current) clearTimeout(copyTimerRef.current);
|
|
99
|
+
copyTimerRef.current = setTimeout(()=>{
|
|
100
|
+
setCopied(false);
|
|
101
|
+
copyTimerRef.current = null;
|
|
102
|
+
}, 2000);
|
|
103
|
+
}, [
|
|
104
|
+
prompt
|
|
105
|
+
]);
|
|
106
|
+
const handleCardActivate = useCallback((e)=>{
|
|
107
|
+
onClick?.(e);
|
|
108
|
+
if (e.defaultPrevented) return;
|
|
109
|
+
if (window.getSelection()?.toString()) return;
|
|
110
|
+
const target = e.target;
|
|
111
|
+
if (target.closest('a, button, .rp-prompt__action-copy, .rp-prompt__action-toggle')) return;
|
|
112
|
+
const rect = cardRef.current?.getBoundingClientRect();
|
|
113
|
+
if (!rect) return;
|
|
114
|
+
const id = Date.now() + Math.random();
|
|
115
|
+
setRipples((prev)=>[
|
|
116
|
+
...prev,
|
|
117
|
+
{
|
|
118
|
+
id,
|
|
119
|
+
x: e.clientX - rect.left,
|
|
120
|
+
y: e.clientY - rect.top
|
|
121
|
+
}
|
|
122
|
+
]);
|
|
123
|
+
const timer = setTimeout(()=>{
|
|
124
|
+
setRipples((prev)=>prev.filter((r)=>r.id !== id));
|
|
125
|
+
rippleTimersRef.current.delete(timer);
|
|
126
|
+
}, 600);
|
|
127
|
+
rippleTimersRef.current.add(timer);
|
|
128
|
+
handleCopy();
|
|
129
|
+
}, [
|
|
130
|
+
handleCopy,
|
|
131
|
+
onClick
|
|
132
|
+
]);
|
|
133
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
134
|
+
...props,
|
|
135
|
+
ref: cardRef,
|
|
136
|
+
className: clsx('rp-prompt', className),
|
|
137
|
+
style: {
|
|
138
|
+
'--rp-prompt-accent': AGENT_ICONS[iconIndex].color,
|
|
139
|
+
...style
|
|
140
|
+
},
|
|
141
|
+
onClick: handleCardActivate,
|
|
142
|
+
children: [
|
|
143
|
+
/*#__PURE__*/ jsx("div", {
|
|
144
|
+
className: "rp-prompt__backdrop"
|
|
145
|
+
}),
|
|
146
|
+
ripples.map((r)=>/*#__PURE__*/ jsx("span", {
|
|
147
|
+
className: "rp-prompt__ripple",
|
|
148
|
+
style: {
|
|
149
|
+
left: r.x,
|
|
150
|
+
top: r.y
|
|
151
|
+
}
|
|
152
|
+
}, r.id)),
|
|
153
|
+
/*#__PURE__*/ jsxs("div", {
|
|
154
|
+
className: "rp-prompt__panel",
|
|
155
|
+
children: [
|
|
156
|
+
/*#__PURE__*/ jsxs("div", {
|
|
157
|
+
className: "rp-prompt__header",
|
|
158
|
+
children: [
|
|
159
|
+
/*#__PURE__*/ jsx("div", {
|
|
160
|
+
className: clsx('rp-prompt__meta', copied && 'rp-prompt__meta--copied'),
|
|
161
|
+
children: /*#__PURE__*/ jsxs("span", {
|
|
162
|
+
className: "rp-prompt__eyebrow",
|
|
163
|
+
children: [
|
|
164
|
+
/*#__PURE__*/ jsx(RotatingIcon, {
|
|
165
|
+
index: iconIndex,
|
|
166
|
+
fading: fading
|
|
167
|
+
}),
|
|
168
|
+
eyebrow
|
|
169
|
+
]
|
|
170
|
+
})
|
|
171
|
+
}),
|
|
172
|
+
/*#__PURE__*/ jsxs("div", {
|
|
173
|
+
className: "rp-prompt__header-row",
|
|
174
|
+
children: [
|
|
175
|
+
/*#__PURE__*/ jsxs("div", {
|
|
176
|
+
className: "rp-prompt__header-left",
|
|
177
|
+
children: [
|
|
178
|
+
/*#__PURE__*/ jsx("div", {
|
|
179
|
+
className: "rp-prompt__title-with-icon",
|
|
180
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
181
|
+
className: "rp-prompt__title",
|
|
182
|
+
children: title
|
|
183
|
+
})
|
|
184
|
+
}),
|
|
185
|
+
description ? /*#__PURE__*/ jsx("p", {
|
|
186
|
+
className: "rp-prompt__description",
|
|
187
|
+
...renderInlineMarkdown(description)
|
|
188
|
+
}) : null
|
|
189
|
+
]
|
|
190
|
+
}),
|
|
191
|
+
/*#__PURE__*/ jsxs("div", {
|
|
192
|
+
className: "rp-prompt__header-actions",
|
|
193
|
+
children: [
|
|
194
|
+
/*#__PURE__*/ jsxs("button", {
|
|
195
|
+
type: "button",
|
|
196
|
+
className: clsx('rp-prompt__action-copy', copied && 'rp-prompt__action-copy--copied'),
|
|
197
|
+
onClick: (e)=>{
|
|
198
|
+
e.stopPropagation();
|
|
199
|
+
handleCopy();
|
|
200
|
+
},
|
|
201
|
+
title: t('promptCopyText'),
|
|
202
|
+
children: [
|
|
203
|
+
/*#__PURE__*/ jsx(SvgWrapper, {
|
|
204
|
+
icon: copied ? IconSuccess : IconCopy,
|
|
205
|
+
className: "rp-prompt__action-icon"
|
|
206
|
+
}),
|
|
207
|
+
/*#__PURE__*/ jsx("span", {
|
|
208
|
+
children: copied ? t('promptCopiedText') : t('promptCopyText')
|
|
209
|
+
})
|
|
210
|
+
]
|
|
211
|
+
}),
|
|
212
|
+
/*#__PURE__*/ jsx("button", {
|
|
213
|
+
type: "button",
|
|
214
|
+
className: "rp-prompt__action-toggle",
|
|
215
|
+
onClick: (e)=>{
|
|
216
|
+
e.stopPropagation();
|
|
217
|
+
setCollapsed((value)=>!value);
|
|
218
|
+
},
|
|
219
|
+
"aria-controls": contentId,
|
|
220
|
+
"aria-expanded": !collapsed,
|
|
221
|
+
title: collapsed ? t('promptExpandText') : t('promptCollapseText'),
|
|
222
|
+
children: /*#__PURE__*/ jsx(SvgWrapper, {
|
|
223
|
+
icon: IconArrowDown,
|
|
224
|
+
className: clsx('rp-prompt__action-toggle-icon', !collapsed && 'rp-prompt__action-toggle-icon--expanded')
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
]
|
|
228
|
+
})
|
|
229
|
+
]
|
|
230
|
+
})
|
|
231
|
+
]
|
|
232
|
+
}),
|
|
233
|
+
/*#__PURE__*/ jsx("div", {
|
|
234
|
+
id: contentId,
|
|
235
|
+
className: clsx('rp-prompt__content', collapsed && 'rp-prompt__content--collapsed'),
|
|
236
|
+
"aria-hidden": collapsed,
|
|
237
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
238
|
+
className: "rp-prompt__content-inner",
|
|
239
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
240
|
+
className: "rp-prompt__content-body",
|
|
241
|
+
style: {
|
|
242
|
+
whiteSpace: 'pre-wrap'
|
|
243
|
+
},
|
|
244
|
+
children: prompt
|
|
245
|
+
})
|
|
246
|
+
})
|
|
247
|
+
})
|
|
248
|
+
]
|
|
249
|
+
})
|
|
250
|
+
]
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function Prompt({ custom = false, ...props }) {
|
|
254
|
+
return custom ? /*#__PURE__*/ jsx(CustomPrompt, {
|
|
255
|
+
...props
|
|
256
|
+
}) : /*#__PURE__*/ jsx(CopyablePrompt, {
|
|
257
|
+
...props
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
var components_Prompt = Prompt;
|
|
261
|
+
export default components_Prompt;
|
|
262
|
+
export { Prompt };
|
|
@@ -10,7 +10,8 @@ const SidebarMenu = /*#__PURE__*/ forwardRef(({ isSidebarOpen, onIsSidebarOpenCh
|
|
|
10
10
|
const { pathname, hash } = useLocation();
|
|
11
11
|
const headers = useDynamicToc();
|
|
12
12
|
const { scrolledHeader } = useActiveAnchor(headers);
|
|
13
|
-
const { frontmatter: { sidebar:
|
|
13
|
+
const { frontmatter: { sidebar: sidebarConfig = true, outline: showOutline = true } } = useFrontmatter();
|
|
14
|
+
const showSidebar = true === sidebarConfig;
|
|
14
15
|
function openSidebar() {
|
|
15
16
|
onIsSidebarOpenChange(true);
|
|
16
17
|
}
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export { type Group, type GroupItem, OverviewGroup, } from './components/Overvie
|
|
|
33
33
|
export { type PackageManagerTabProps, PackageManagerTabs, } from './components/PackageManagerTabs/index.js';
|
|
34
34
|
export { PageTab, type PageTabProps, PageTabs, type PageTabsProps, } from './components/PageTabs/index.js';
|
|
35
35
|
export { PrevNextPage } from './components/PrevNextPage/index.js';
|
|
36
|
+
export { Prompt, type PromptProps } from './components/Prompt/index.js';
|
|
36
37
|
export { ReadPercent } from './components/ReadPercent/index.js';
|
|
37
38
|
export { useReadPercent } from './components/ReadPercent/useReadPercent.js';
|
|
38
39
|
export { Root, type RootProps } from './components/Root/index.js';
|
|
@@ -57,6 +58,8 @@ export { DocLayout, type DocLayoutProps } from './layout/DocLayout/index.js';
|
|
|
57
58
|
export { HomeLayout, type HomeLayoutProps } from './layout/HomeLayout/index.js';
|
|
58
59
|
export { Layout, type LayoutProps } from './layout/Layout/index.js';
|
|
59
60
|
export { NotFoundLayout } from './layout/NotFountLayout/index.js';
|
|
61
|
+
export { copyToClipboard } from './logic/copyToClipboard.js';
|
|
62
|
+
export { getCopyableText } from './logic/getCopyableText.js';
|
|
60
63
|
export { mergeRefs } from './logic/mergeRefs.js';
|
|
61
64
|
export { useFullTextSearch } from './logic/useFullTextSearch.js';
|
|
62
65
|
export { usePrevNextPage } from './logic/usePrevNextPage.js';
|
package/dist/theme/index.js
CHANGED
|
@@ -33,6 +33,7 @@ export { OverviewGroup } from "./components/OverviewGroup/index.js";
|
|
|
33
33
|
export { PackageManagerTabs } from "./components/PackageManagerTabs/index.js";
|
|
34
34
|
export { PageTab, PageTabs } from "./components/PageTabs/index.js";
|
|
35
35
|
export { PrevNextPage } from "./components/PrevNextPage/index.js";
|
|
36
|
+
export { Prompt } from "./components/Prompt/index.js";
|
|
36
37
|
export { ReadPercent } from "./components/ReadPercent/index.js";
|
|
37
38
|
export { useReadPercent } from "./components/ReadPercent/useReadPercent.js";
|
|
38
39
|
export { Root } from "./components/Root/index.js";
|
|
@@ -55,6 +56,8 @@ export { DocLayout } from "./layout/DocLayout/index.js";
|
|
|
55
56
|
export { HomeLayout } from "./layout/HomeLayout/index.js";
|
|
56
57
|
export { Layout } from "./layout/Layout/index.js";
|
|
57
58
|
export { NotFoundLayout } from "./layout/NotFountLayout/index.js";
|
|
59
|
+
export { copyToClipboard } from "./logic/copyToClipboard.js";
|
|
60
|
+
export { getCopyableText } from "./logic/getCopyableText.js";
|
|
58
61
|
export { mergeRefs } from "./logic/mergeRefs.js";
|
|
59
62
|
export { useFullTextSearch } from "./logic/useFullTextSearch.js";
|
|
60
63
|
export { usePrevNextPage } from "./logic/usePrevNextPage.js";
|
|
@@ -115,10 +115,14 @@
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
.rp-doc-layout__sidebar-placeholder {
|
|
118
|
-
width:
|
|
118
|
+
width: 12vw;
|
|
119
119
|
margin-left: var(--rp-sidebar-margin-left);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
.rp-doc-layout__sidebar-placeholder--legacy {
|
|
123
|
+
width: var(--rp-sidebar-width);
|
|
124
|
+
}
|
|
125
|
+
|
|
122
126
|
.rp-doc-layout__outline {
|
|
123
127
|
margin-right: var(--rp-outline-margin-right);
|
|
124
128
|
padding-bottom: var(--rp-content-padding-y);
|
|
@@ -8,7 +8,11 @@ function DocLayout(props) {
|
|
|
8
8
|
const { beforeDocFooter, afterDocFooter, beforeDoc, afterDoc, beforeDocContent, afterDocContent, beforeOutline, afterOutline, beforeSidebar, afterSidebar, components } = props;
|
|
9
9
|
const { frontmatter } = useFrontmatter();
|
|
10
10
|
const isOverviewPage = frontmatter?.overview ?? false;
|
|
11
|
-
const
|
|
11
|
+
const sidebar = frontmatter?.sidebar ?? true;
|
|
12
|
+
const showSidebar = true === sidebar;
|
|
13
|
+
const showSidebarPlaceholder = false === sidebar || 'placeholder' === sidebar;
|
|
14
|
+
const isLegacyPlaceholder = 'placeholder' === sidebar;
|
|
15
|
+
const { outline: showOutline = true, footer: showDocFooter = true, pageType } = frontmatter;
|
|
12
16
|
if (process.env.__SSR_MD__) return /*#__PURE__*/ jsx(Fragment, {
|
|
13
17
|
children: isOverviewPage ? /*#__PURE__*/ jsx(Overview, {
|
|
14
18
|
content: /*#__PURE__*/ jsx(DocContent, {
|
|
@@ -40,12 +44,12 @@ function DocLayout(props) {
|
|
|
40
44
|
/*#__PURE__*/ jsx(Sidebar, {}),
|
|
41
45
|
afterSidebar
|
|
42
46
|
]
|
|
43
|
-
}) : /*#__PURE__*/ jsx("aside", {
|
|
44
|
-
className:
|
|
47
|
+
}) : showSidebarPlaceholder ? /*#__PURE__*/ jsx("aside", {
|
|
48
|
+
className: clsx('rp-doc-layout__sidebar-placeholder', isLegacyPlaceholder && 'rp-doc-layout__sidebar-placeholder--legacy'),
|
|
45
49
|
style: isDocWide ? {
|
|
46
50
|
width: '0'
|
|
47
51
|
} : {}
|
|
48
|
-
}),
|
|
52
|
+
}) : null,
|
|
49
53
|
isOverviewPage ? /*#__PURE__*/ jsx(Fragment, {
|
|
50
54
|
children: /*#__PURE__*/ jsxs("main", {
|
|
51
55
|
className: "rp-doc-layout__overview",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function copyToClipboard(text: string): Promise<boolean>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import copy_to_clipboard from "copy-to-clipboard";
|
|
2
2
|
async function copyToClipboard(text) {
|
|
3
|
-
if (navigator.clipboard?.writeText) try {
|
|
3
|
+
if ("u" > typeof navigator && navigator.clipboard?.writeText) try {
|
|
4
4
|
await navigator.clipboard.writeText(text);
|
|
5
|
-
return;
|
|
5
|
+
return true;
|
|
6
6
|
} catch {}
|
|
7
|
-
|
|
7
|
+
if ("u" < typeof document) return false;
|
|
8
|
+
return copy_to_clipboard(text);
|
|
8
9
|
}
|
|
9
10
|
export { copyToClipboard };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
function getCopyableText(element, options = {}) {
|
|
2
|
+
if (!element) return '';
|
|
3
|
+
const { ignoreClasses = [], ignoreSelectors = [] } = options;
|
|
4
|
+
const nodeFilter = element.ownerDocument.defaultView?.NodeFilter ?? NodeFilter;
|
|
5
|
+
const walk = element.ownerDocument.createTreeWalker(element, nodeFilter.SHOW_TEXT);
|
|
6
|
+
let text = '';
|
|
7
|
+
let node = walk.nextNode();
|
|
8
|
+
const markdownState = {
|
|
9
|
+
seenNodes: new WeakSet()
|
|
10
|
+
};
|
|
11
|
+
let previousBlock = null;
|
|
12
|
+
while(node){
|
|
13
|
+
const parentElement = node.parentElement;
|
|
14
|
+
const shouldIgnore = !parentElement || ignoreClasses.some((className)=>parentElement.classList.contains(className)) || ignoreSelectors.some((selector)=>parentElement.closest(selector));
|
|
15
|
+
if (!shouldIgnore) {
|
|
16
|
+
const currentBlock = getBlockElement(parentElement, element);
|
|
17
|
+
if ((node.previousSibling?.nodeName === 'BR' || parentElement.previousSibling?.nodeName === 'BR') && !text.endsWith('\n')) text += '\n';
|
|
18
|
+
if (currentBlock && previousBlock && currentBlock !== previousBlock && !text.endsWith('\n')) text += '\n';
|
|
19
|
+
text += toMarkdown(parentElement, markdownState);
|
|
20
|
+
text += node.nodeValue ?? '';
|
|
21
|
+
previousBlock = currentBlock;
|
|
22
|
+
}
|
|
23
|
+
node = walk.nextNode();
|
|
24
|
+
}
|
|
25
|
+
return text;
|
|
26
|
+
}
|
|
27
|
+
function getBlockElement(element, rootElement) {
|
|
28
|
+
const blockElement = element.closest('li, p, div, pre, blockquote');
|
|
29
|
+
if (!blockElement) return null;
|
|
30
|
+
return rootElement.contains(blockElement) ? blockElement : null;
|
|
31
|
+
}
|
|
32
|
+
function toMarkdown(node, state) {
|
|
33
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return '';
|
|
34
|
+
const element = node;
|
|
35
|
+
const listItem = element.closest('li');
|
|
36
|
+
if (listItem && !state.seenNodes.has(listItem)) {
|
|
37
|
+
state.seenNodes.add(listItem);
|
|
38
|
+
return toMarkdownListItem(listItem);
|
|
39
|
+
}
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
function toMarkdownListItem(listItem) {
|
|
43
|
+
const list = listItem.parentElement;
|
|
44
|
+
if (!list) return '- ';
|
|
45
|
+
if ('OL' === list.tagName) {
|
|
46
|
+
const listItems = Array.from(list.children).filter((child)=>'LI' === child.tagName);
|
|
47
|
+
const index = listItems.indexOf(listItem);
|
|
48
|
+
return `${index + 1}. `;
|
|
49
|
+
}
|
|
50
|
+
return '- ';
|
|
51
|
+
}
|
|
52
|
+
export { getCopyableText };
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
--rp-c-text-3: #3c3c3c54;
|
|
12
12
|
--rp-c-text-4: #3c3c3c2e;
|
|
13
13
|
--rp-c-text-code: #476582;
|
|
14
|
-
--rp-c-text-code-bg: #
|
|
15
|
-
--rp-c-text-code-border: #
|
|
14
|
+
--rp-c-text-code-bg: #99a1b30f;
|
|
15
|
+
--rp-c-text-code-border: #00000009;
|
|
16
16
|
--rp-c-link: var(--rp-c-brand-dark);
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
--rp-c-text-3: #ebebeb61;
|
|
30
30
|
--rp-c-text-4: #ebebeb2e;
|
|
31
31
|
--rp-c-text-code: #c9def1;
|
|
32
|
-
--rp-c-text-code-bg: #
|
|
33
|
-
--rp-c-text-code-border: #
|
|
32
|
+
--rp-c-text-code-bg: #ffffff0f;
|
|
33
|
+
--rp-c-text-code-border: #ffffff0a;
|
|
34
34
|
--rp-c-link: var(--rp-c-brand-light);
|
|
35
35
|
}
|
|
36
36
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@mdx-js/mdx": "^3.1.1",
|
|
62
62
|
"@mdx-js/react": "^3.1.1",
|
|
63
|
-
"@rsbuild/core": "2.0.
|
|
64
|
-
"@rsbuild/plugin-react": "~
|
|
63
|
+
"@rsbuild/core": "^2.0.2",
|
|
64
|
+
"@rsbuild/plugin-react": "~2.0.0",
|
|
65
65
|
"@shikijs/rehype": "^4.0.2",
|
|
66
66
|
"@types/unist": "^3.0.3",
|
|
67
67
|
"@unhead/react": "^2.1.13",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
76
76
|
"medium-zoom": "1.1.0",
|
|
77
77
|
"nprogress": "^0.2.0",
|
|
78
|
-
"react": "^19.2.
|
|
79
|
-
"react-dom": "^19.2.
|
|
78
|
+
"react": "^19.2.5",
|
|
79
|
+
"react-dom": "^19.2.5",
|
|
80
80
|
"react-lazy-with-preload": "^2.2.1",
|
|
81
81
|
"react-reconciler": "0.33.0",
|
|
82
82
|
"react-render-to-markdown": "19.0.1",
|
|
@@ -95,13 +95,13 @@
|
|
|
95
95
|
"unist-util-remove": "^4.0.0",
|
|
96
96
|
"unist-util-visit": "^5.1.0",
|
|
97
97
|
"unist-util-visit-children": "^3.0.0",
|
|
98
|
-
"@rspress/shared": "2.0.
|
|
98
|
+
"@rspress/shared": "2.0.10"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@microsoft/api-extractor": "^7.57.7",
|
|
102
102
|
"@rsbuild/plugin-sass": "~1.5.1",
|
|
103
|
-
"@rsbuild/plugin-svgr": "^
|
|
104
|
-
"@rslib/core": "0.21.
|
|
103
|
+
"@rsbuild/plugin-svgr": "^2.0.1",
|
|
104
|
+
"@rslib/core": "0.21.3",
|
|
105
105
|
"@types/body-scroll-lock": "^3.1.2",
|
|
106
106
|
"@types/hast": "^3.0.4",
|
|
107
107
|
"@types/mdast": "^4.0.4",
|
|
@@ -110,21 +110,21 @@
|
|
|
110
110
|
"@types/react": "^19.2.14",
|
|
111
111
|
"@types/react-dom": "^19.2.3",
|
|
112
112
|
"@types/react-reconciler": "^0.33.0",
|
|
113
|
-
"@types/web": "^0.0.
|
|
113
|
+
"@types/web": "^0.0.347",
|
|
114
114
|
"cac": "^7.0.0",
|
|
115
115
|
"chokidar": "^3.6.0",
|
|
116
116
|
"execa": "8.0.1",
|
|
117
117
|
"mdast-util-directive": "^3.1.0",
|
|
118
118
|
"mdast-util-mdx-expression": "^2.0.1",
|
|
119
|
-
"memfs": "^4.57.
|
|
119
|
+
"memfs": "^4.57.2",
|
|
120
120
|
"p-map": "^7.0.4",
|
|
121
121
|
"picocolors": "^1.1.1",
|
|
122
|
-
"postcss": "8.5.
|
|
122
|
+
"postcss": "8.5.12",
|
|
123
123
|
"remark-directive": "^4.0.0",
|
|
124
124
|
"rsbuild-plugin-publint": "^0.3.4",
|
|
125
|
-
"rsbuild-plugin-virtual-module": "0.4.
|
|
125
|
+
"rsbuild-plugin-virtual-module": "0.4.2",
|
|
126
126
|
"tailwindcss": "^3.4.19",
|
|
127
|
-
"tinyglobby": "^0.2.
|
|
127
|
+
"tinyglobby": "^0.2.16",
|
|
128
128
|
"tinypool": "^1.1.1",
|
|
129
129
|
"ts-json-schema-generator": "^2.9.0",
|
|
130
130
|
"typescript": "^5.8.2",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function copyToClipboard(text: string): Promise<void>;
|