@rspress/core 2.0.0-rc.5 → 2.0.0-rc.6
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~7675.4468968d.js → 0~7675.d236b058.js} +3 -3
- package/dist/{5485.b9ce9bdf.js → 5485.7586c86a.js} +1 -1
- package/dist/{5341.9eb6b114.js → 7786.421b464f.js} +2 -2
- package/dist/{1820.985588a0.js → 9348.1beb3e25.js} +6 -0
- package/dist/cli/index.js +2 -2
- package/dist/config/defineConfig.d.ts +40 -0
- package/dist/{cli/config → config}/loadConfigFile.js +2 -2
- package/dist/eject-theme/components/Callout/index.scss +6 -6
- package/dist/eject-theme/components/DocContent/docComponents/title.tsx +21 -2
- package/dist/eject-theme/components/Llms/LlmsContainer.scss +6 -0
- package/dist/eject-theme/components/Llms/LlmsContainer.tsx +9 -0
- package/dist/eject-theme/components/Llms/LlmsCopyButton.scss +57 -0
- package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +94 -0
- package/dist/eject-theme/components/Llms/LlmsViewOptions.scss +98 -0
- package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +259 -0
- package/dist/eject-theme/components/Llms/index.scss +42 -0
- package/dist/eject-theme/components/Llms/index.tsx +4 -0
- package/dist/eject-theme/components/Llms/useMdUrl.ts +14 -0
- package/dist/eject-theme/components/Nav/index.scss +3 -0
- package/dist/eject-theme/components/Nav/index.tsx +7 -2
- package/dist/eject-theme/components/{Nav/NavTitle.tsx → NavTitle/index.tsx} +15 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -3
- package/dist/node/PluginDriver.js +1 -1
- package/dist/node/auto-nav-sidebar/index.js +1 -1
- package/dist/node/auto-nav-sidebar/normalize.js +1 -1
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/constants.js +1 -1
- package/dist/node/eject.js +1 -0
- package/dist/node/initRsbuild.js +5 -4
- package/dist/node/last-updated/index.js +1 -1
- package/dist/node/mdx/{loader.7c249a26.js → loader.15e0b2d2.js} +0 -5
- package/dist/node/mdx/options.js +2 -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 +2 -3
- package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +1 -2
- package/dist/node/mdx/remarkPlugins/image.js +1 -2
- package/dist/node/mdx/remarkPlugins/link.js +1 -2
- package/dist/node/mdx/remarkPlugins/toc.d.ts +4 -3
- package/dist/node/mdx/remarkPlugins/toc.js +14 -11
- package/dist/node/route/RoutePage.d.ts +3 -1
- package/dist/node/route/RoutePage.js +4 -0
- package/dist/node/route/RouteService.js +2 -2
- package/dist/node/route/extractPageData.d.ts +5 -0
- package/dist/node/route/extractPageData.js +88 -57
- package/dist/node/route/normalizeRoutePath.js +2 -2
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +21 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +21 -0
- package/dist/node/runtimeModule/i18n.js +4 -3
- package/dist/node/runtimeModule/pageData/createPageData.js +9 -6
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +20 -14
- package/dist/node/runtimeModule/siteData/createSiteData.js +2 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
- package/dist/node/serve.js +1 -1
- package/dist/node/ssg/renderPage.js +1 -1
- package/dist/node/ssg/renderPageWorker.js +1 -1
- package/dist/node/ssg/renderPages.js +7 -3
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +2 -2
- package/dist/node/ssg-md/llms/llmsTxt.js +12 -2
- package/dist/node/ssg-md/remarkSplitMdx.js +2 -2
- 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/createHash.js +1 -1
- package/dist/node/utils/flattenMdxContent.js +2 -2
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/normalizePath.js +1 -1
- package/dist/node/utils/reactAlias.js +1 -1
- package/dist/runtime/hooks/useI18n.d.ts +1 -1
- package/dist/runtime/hooks/useI18n.js +2 -2
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/utils.d.ts +2 -2
- package/dist/runtime/utils.js +2 -2
- package/dist/theme/components/Callout/index.css +6 -6
- package/dist/theme/components/DocContent/docComponents/title.js +25 -5
- package/dist/theme/components/HomeHero/index.css +10 -10
- package/dist/theme/components/Llms/LlmsContainer.css +7 -0
- package/dist/theme/components/Llms/LlmsContainer.d.ts +5 -0
- package/dist/theme/components/Llms/LlmsContainer.js +9 -0
- package/dist/theme/components/Llms/LlmsCopyButton.css +57 -0
- package/dist/theme/components/Llms/LlmsCopyButton.d.ts +20 -0
- package/dist/theme/components/Llms/LlmsCopyButton.js +73 -0
- package/dist/theme/components/Llms/LlmsCopyButton.js.LICENSE.txt +5 -0
- package/dist/theme/components/Llms/LlmsViewOptions.css +93 -0
- package/dist/theme/components/Llms/LlmsViewOptions.d.ts +34 -0
- package/dist/theme/components/Llms/LlmsViewOptions.js +206 -0
- package/dist/theme/components/Llms/LlmsViewOptions.js.LICENSE.txt +5 -0
- package/dist/theme/components/Llms/index.css +32 -0
- package/dist/theme/components/Llms/index.d.ts +4 -0
- package/dist/theme/components/Llms/index.js +5 -0
- package/dist/theme/components/Llms/useMdUrl.d.ts +6 -0
- package/dist/theme/components/Llms/useMdUrl.js +15 -0
- package/dist/theme/components/Nav/index.css +1 -0
- package/dist/theme/components/Nav/index.js +1 -2
- package/dist/theme/components/{Nav/NavTitle.d.ts → NavTitle/index.d.ts} +1 -1
- package/dist/theme/components/{Nav/NavTitle.js → NavTitle/index.js} +11 -6
- package/dist/theme/components/PageTabs/index.css +1 -1
- package/dist/theme/components/Tabs/index.css +4 -4
- package/dist/theme/hooks/useDynamicToc.d.ts +2 -0
- package/dist/theme/hooks/useDynamicToc.js +3 -1
- package/dist/theme/index.d.ts +2 -0
- package/dist/theme/index.js +3 -1
- package/dist/theme/layout/Layout/index.js +1 -1
- package/package.json +15 -16
- package/dist/8813.4b28f4bb.js +0 -1
- package/dist/cli/config/index.d.ts +0 -2
- /package/dist/{cli/config/index.js → config/defineConfig.js} +0 -0
- /package/dist/{cli/config → config}/loadConfigFile.d.ts +0 -0
- /package/dist/eject-theme/components/{Nav/NavTitle.scss → NavTitle/index.scss} +0 -0
- /package/dist/theme/components/{Nav/NavTitle.css → NavTitle/index.css} +0 -0
|
@@ -7,10 +7,10 @@ import { Buffer } from "node:buffer";
|
|
|
7
7
|
import node_child_process, { ChildProcess } from "node:child_process";
|
|
8
8
|
import { setTimeout as promises_setTimeout } from "node:timers/promises";
|
|
9
9
|
import { debuglog } from "node:util";
|
|
10
|
-
import { node_process, node_os, constants } from "./
|
|
10
|
+
import { node_process, node_os, constants } from "./9348.1beb3e25.js";
|
|
11
11
|
import { node_path } from "./6289.29817fb4.js";
|
|
12
|
-
import { node_url } from "./5485.
|
|
13
|
-
import { createWriteStream, createReadStream, readFileSync } from "./
|
|
12
|
+
import { node_url } from "./5485.7586c86a.js";
|
|
13
|
+
import { createWriteStream, createReadStream, readFileSync } from "./7786.421b464f.js";
|
|
14
14
|
__webpack_require__.add({
|
|
15
15
|
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
16
16
|
const cp = __webpack_require__("child_process");
|
|
@@ -48,8 +48,8 @@ export { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME, DEFAULT_PAGE_EXTENSIONS
|
|
|
48
48
|
export { glob } from "tinyglobby";
|
|
49
49
|
export { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
50
50
|
export { chunk, groupBy } from "lodash-es";
|
|
51
|
-
export {
|
|
52
|
-
export {
|
|
51
|
+
export { default as remark_parse } from "remark-parse";
|
|
52
|
+
export { remove } from "unist-util-remove";
|
|
53
53
|
export { createReadStream, createWriteStream, default as node_fs, readFileSync } from "node:fs";
|
|
54
54
|
export { mergeRsbuildConfig, rspack as core_rspack } from "@rsbuild/core";
|
|
55
55
|
export { createHash } from "node:crypto";
|
|
@@ -2,4 +2,10 @@ export { MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash,
|
|
|
2
2
|
export { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
|
|
3
3
|
export { constants, default as node_os } from "node:os";
|
|
4
4
|
export { cwd, default as node_process } from "node:process";
|
|
5
|
+
export { default as remark_gfm } from "remark-gfm";
|
|
6
|
+
export { default as remark_stringify } from "remark-stringify";
|
|
7
|
+
export { unified } from "unified";
|
|
8
|
+
export { visit } from "unist-util-visit";
|
|
9
|
+
export { default as github_slugger } from "github-slugger";
|
|
10
|
+
export { visitChildren } from "unist-util-visit-children";
|
|
5
11
|
export { createProcessor, nodeTypes } from "@mdx-js/mdx";
|
package/dist/cli/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { node_path, logger, join, picocolors } from "../6289.29817fb4.js";
|
|
2
2
|
import { chokidar, cac } from "./index.44f3184c.js";
|
|
3
|
-
import { package_namespaceObject } from "../5485.
|
|
4
|
-
import { loadConfigFile, resolveDocRoot } from "
|
|
3
|
+
import { package_namespaceObject } from "../5485.7586c86a.js";
|
|
4
|
+
import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
|
|
5
5
|
import { dev } from "../node/dev.js";
|
|
6
6
|
import { PUBLIC_DIR } from "../node/constants.js";
|
|
7
7
|
import { build } from "../node/build.js";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { UserConfig } from '@rspress/shared';
|
|
2
|
+
/**
|
|
3
|
+
* A function that returns a Promise resolving to a UserConfig.
|
|
4
|
+
* Use this type when you need to perform async operations during configuration,
|
|
5
|
+
* such as fetching data or reading files.
|
|
6
|
+
*/
|
|
7
|
+
export type UserConfigAsyncFn = () => Promise<UserConfig>;
|
|
8
|
+
/**
|
|
9
|
+
* Define a static Rspress configuration object.
|
|
10
|
+
* @param config - The Rspress configuration object.
|
|
11
|
+
* @returns The same configuration object (enables type checking and IDE autocompletion).
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { defineConfig } from '@rspress/core';
|
|
15
|
+
*
|
|
16
|
+
* export default defineConfig({
|
|
17
|
+
* title: 'My Site',
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function defineConfig(config: UserConfig): UserConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Define an async Rspress configuration function.
|
|
24
|
+
* Use this overload when you need to perform async operations during configuration,
|
|
25
|
+
* such as fetching remote data, reading files, or dynamically generating config.
|
|
26
|
+
* @param config - An async function that returns the Rspress configuration.
|
|
27
|
+
* @returns The same async function (enables type checking and IDE autocompletion).
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { defineConfig } from '@rspress/core';
|
|
31
|
+
*
|
|
32
|
+
* export default defineConfig(async () => {
|
|
33
|
+
* const remoteConfig = await fetchConfig();
|
|
34
|
+
* return {
|
|
35
|
+
* title: remoteConfig.title,
|
|
36
|
+
* };
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function defineConfig(config: UserConfigAsyncFn): UserConfigAsyncFn;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { node_fs, DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME } from "
|
|
2
|
-
import { node_path, logger } from "
|
|
1
|
+
import { node_fs, DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME } from "../7786.421b464f.js";
|
|
2
|
+
import { node_path, logger } from "../6289.29817fb4.js";
|
|
3
3
|
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
|
|
4
4
|
async function loadConfigFile(customConfigFile) {
|
|
5
5
|
const baseDir = process.cwd();
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
// inline code
|
|
123
|
-
:not(pre
|
|
123
|
+
:not(pre) > code {
|
|
124
124
|
color: var(--rp-container-note-text);
|
|
125
125
|
background-color: var(--rp-container-note-code-bg);
|
|
126
126
|
}
|
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
// inline code
|
|
146
|
-
:not(pre
|
|
146
|
+
:not(pre) > code {
|
|
147
147
|
color: var(--rp-container-tip-text);
|
|
148
148
|
background-color: var(--rp-container-tip-code-bg);
|
|
149
149
|
}
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// inline code
|
|
169
|
-
:not(pre
|
|
169
|
+
:not(pre) > code {
|
|
170
170
|
color: var(--rp-container-info-text);
|
|
171
171
|
background-color: var(--rp-container-info-code-bg);
|
|
172
172
|
}
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
// inline code
|
|
192
|
-
:not(pre
|
|
192
|
+
:not(pre) > code {
|
|
193
193
|
color: var(--rp-container-warning-text);
|
|
194
194
|
background-color: var(--rp-container-warning-code-bg);
|
|
195
195
|
}
|
|
@@ -213,7 +213,7 @@
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
// inline code
|
|
216
|
-
:not(pre
|
|
216
|
+
:not(pre) > code {
|
|
217
217
|
color: var(--rp-container-danger-text);
|
|
218
218
|
background-color: var(--rp-container-danger-code-bg);
|
|
219
219
|
}
|
|
@@ -236,7 +236,7 @@
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
// inline code
|
|
239
|
-
:not(pre
|
|
239
|
+
:not(pre) > code {
|
|
240
240
|
color: var(--rp-container-details-text);
|
|
241
241
|
background-color: var(--rp-container-details-code-bg);
|
|
242
242
|
}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
+
import { useFrontmatter } from '@rspress/core/runtime';
|
|
2
|
+
import { LlmsContainer, LlmsCopyButton, LlmsViewOptions, Tag } from '@theme';
|
|
1
3
|
import clsx from 'clsx';
|
|
2
4
|
import type React from 'react';
|
|
3
5
|
|
|
4
6
|
export const H1 = (props: React.ComponentProps<'h1'>) => {
|
|
5
|
-
const { className, ...rest } = props;
|
|
6
|
-
|
|
7
|
+
const { className, children, ...rest } = props;
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
frontmatter: { tag },
|
|
11
|
+
} = useFrontmatter();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<h1 className={clsx('rp-toc-include', className)} {...rest}>
|
|
16
|
+
{children} <Tag tag={tag} />
|
|
17
|
+
</h1>
|
|
18
|
+
{process.env.ENABLE_LLMS_UI && (
|
|
19
|
+
<LlmsContainer>
|
|
20
|
+
<LlmsCopyButton />
|
|
21
|
+
<LlmsViewOptions />
|
|
22
|
+
</LlmsContainer>
|
|
23
|
+
)}
|
|
24
|
+
</>
|
|
25
|
+
);
|
|
7
26
|
};
|
|
8
27
|
|
|
9
28
|
export const H2 = (props: React.ComponentProps<'h2'>) => {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import './LlmsContainer.scss';
|
|
3
|
+
|
|
4
|
+
export interface LlmsContainerProps
|
|
5
|
+
extends React.HTMLAttributes<HTMLDivElement> {}
|
|
6
|
+
|
|
7
|
+
export function LlmsContainer(props: LlmsContainerProps) {
|
|
8
|
+
return <div {...props} className={'rp-not-doc rp-llms-container'} />;
|
|
9
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
.rp-llms-copy-button {
|
|
2
|
+
position: relative;
|
|
3
|
+
overflow: hidden;
|
|
4
|
+
|
|
5
|
+
&--loading.rp-llms-copy-button {
|
|
6
|
+
background: var(--rp-c-bg-mute);
|
|
7
|
+
opacity: 0.7;
|
|
8
|
+
cursor: wait;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&--success.rp-llms-copy-button {
|
|
12
|
+
color: var(--rp-c-green-1, #10b981);
|
|
13
|
+
border-color: var(--rp-c-green-1, #10b981);
|
|
14
|
+
background: var(--rp-c-bg-soft);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.rp-llms-copy-button--success .rp-llms-copy-button__icon-copy {
|
|
19
|
+
opacity: 0;
|
|
20
|
+
transform: translate(-50%, -50%) scale(0.5);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.rp-llms-copy-button--success .rp-llms-copy-button__icon-success {
|
|
24
|
+
opacity: 1;
|
|
25
|
+
visibility: visible;
|
|
26
|
+
transform: translate(-50%, -50%) scale(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.rp-llms-copy-button__icon-wrapper {
|
|
30
|
+
width: 16px;
|
|
31
|
+
height: 16px;
|
|
32
|
+
position: relative;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.rp-llms-copy-button__icon-copy {
|
|
36
|
+
width: 16px;
|
|
37
|
+
height: 16px;
|
|
38
|
+
position: absolute;
|
|
39
|
+
top: 50%;
|
|
40
|
+
left: 50%;
|
|
41
|
+
transform: translate(-50%, -50%) scale(1);
|
|
42
|
+
transition: all 0.2s ease;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.rp-llms-copy-button__icon-success {
|
|
46
|
+
width: 16px;
|
|
47
|
+
height: 16px;
|
|
48
|
+
position: absolute;
|
|
49
|
+
top: 50%;
|
|
50
|
+
left: 50%;
|
|
51
|
+
color: var(--rp-c-green-1, #10b981);
|
|
52
|
+
|
|
53
|
+
visibility: hidden;
|
|
54
|
+
opacity: 0;
|
|
55
|
+
transform: translate(-50%, -50%) scale(0.5);
|
|
56
|
+
transition: all 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
|
|
57
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inspired from fumadocs docsite
|
|
3
|
+
* @from https://github.com/fuma-nama/fumadocs/blob/5723bbe58ef805a5421a780abf235a10b251be2f/apps/docs/app/docs/%5B...slug%5D/page.client.tsx#L11
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
import { useI18n } from '@rspress/core/runtime';
|
|
7
|
+
import { IconCopy, IconSuccess } from '@theme';
|
|
8
|
+
import { useCallback, useRef, useState } from 'react';
|
|
9
|
+
import './index.scss';
|
|
10
|
+
import './LlmsCopyButton.scss';
|
|
11
|
+
import { useMdUrl } from './useMdUrl';
|
|
12
|
+
|
|
13
|
+
export interface LlmsCopyButtonProps
|
|
14
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
15
|
+
/**
|
|
16
|
+
* Text by language, used with `useLang`.
|
|
17
|
+
* @default en: 'Copy Markdown', zh: '\u590d\u5236 Markdown'
|
|
18
|
+
*/
|
|
19
|
+
textByLang?: Record<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Priority is higher than textByLang
|
|
22
|
+
* @default ''
|
|
23
|
+
*/
|
|
24
|
+
text?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Overrides the default click handler.
|
|
27
|
+
* If provided, the default copy to clipboard functionality will not be executed.
|
|
28
|
+
*/
|
|
29
|
+
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const cache = new Map<string, string>();
|
|
33
|
+
|
|
34
|
+
export function LlmsCopyButton(props: LlmsCopyButtonProps) {
|
|
35
|
+
const { onClick, ...otherProps } = props;
|
|
36
|
+
const t = useI18n();
|
|
37
|
+
|
|
38
|
+
const { pathname } = useMdUrl();
|
|
39
|
+
|
|
40
|
+
const [isLoading, setLoading] = useState(false);
|
|
41
|
+
const [isFinished, setFinished] = useState(false);
|
|
42
|
+
|
|
43
|
+
const timer = useRef<number | null>(null);
|
|
44
|
+
const handleClick = useCallback(async () => {
|
|
45
|
+
setLoading(true);
|
|
46
|
+
|
|
47
|
+
const url = pathname;
|
|
48
|
+
try {
|
|
49
|
+
const content: string =
|
|
50
|
+
cache.get(url) ?? (await fetch(url).then(res => res.text()));
|
|
51
|
+
|
|
52
|
+
cache.set(url, content);
|
|
53
|
+
await navigator.clipboard.writeText(content);
|
|
54
|
+
} finally {
|
|
55
|
+
setLoading(false);
|
|
56
|
+
setFinished(true);
|
|
57
|
+
if (timer.current) {
|
|
58
|
+
clearTimeout(timer.current);
|
|
59
|
+
timer.current = null;
|
|
60
|
+
}
|
|
61
|
+
timer.current = window.setTimeout(() => {
|
|
62
|
+
setFinished(false);
|
|
63
|
+
timer.current = null;
|
|
64
|
+
}, 500);
|
|
65
|
+
}
|
|
66
|
+
}, [pathname]);
|
|
67
|
+
|
|
68
|
+
if (!pathname) {
|
|
69
|
+
return <></>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<button
|
|
74
|
+
{...otherProps}
|
|
75
|
+
disabled={isLoading}
|
|
76
|
+
className={[
|
|
77
|
+
'rp-not-doc',
|
|
78
|
+
'rp-llms-button',
|
|
79
|
+
'rp-llms-copy-button',
|
|
80
|
+
isLoading ? 'rp-llms-copy-button--loading' : '',
|
|
81
|
+
isFinished ? 'rp-llms-copy-button--success' : '',
|
|
82
|
+
]
|
|
83
|
+
.filter(Boolean)
|
|
84
|
+
.join(' ')}
|
|
85
|
+
onClick={onClick ?? handleClick}
|
|
86
|
+
>
|
|
87
|
+
<div className="rp-llms-copy-button__icon-wrapper">
|
|
88
|
+
<IconSuccess className="rp-llms-copy-button__icon-success" />
|
|
89
|
+
<IconCopy className="rp-llms-copy-button__icon-copy" />
|
|
90
|
+
</div>
|
|
91
|
+
<span>{t('copyMarkdownText')}</span>
|
|
92
|
+
</button>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
.rp-llms-view-options__trigger {
|
|
2
|
+
position: relative;
|
|
3
|
+
|
|
4
|
+
&--active {
|
|
5
|
+
background: var(--rp-c-bg-mute);
|
|
6
|
+
color: var(--rp-c-text-1);
|
|
7
|
+
border-color: var(--rp-c-divider);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.rp-llms-view-options__arrow {
|
|
12
|
+
transition: transform 0.2s ease;
|
|
13
|
+
&--rotated {
|
|
14
|
+
transform: rotate(180deg);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.rp-llms-view-options__menu {
|
|
19
|
+
width: max-content;
|
|
20
|
+
min-width: 220px;
|
|
21
|
+
position: absolute;
|
|
22
|
+
top: calc(100% + 6px);
|
|
23
|
+
left: 0;
|
|
24
|
+
z-index: 100;
|
|
25
|
+
|
|
26
|
+
display: flex;
|
|
27
|
+
padding: 6px;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
align-items: flex-start;
|
|
30
|
+
|
|
31
|
+
border-radius: 10px;
|
|
32
|
+
border: 1px solid var(--rp-c-divider-light);
|
|
33
|
+
background: var(--rp-c-bg);
|
|
34
|
+
color: var(--rp-c-text-1);
|
|
35
|
+
|
|
36
|
+
box-shadow:
|
|
37
|
+
0 4px 20px -4px rgba(0, 0, 0, 0.15),
|
|
38
|
+
0 0 2px 0 rgba(0, 0, 0, 0.05);
|
|
39
|
+
transform-origin: top left;
|
|
40
|
+
animation: dropdownIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// dropdownIn
|
|
44
|
+
@keyframes dropdownIn {
|
|
45
|
+
from {
|
|
46
|
+
opacity: 0;
|
|
47
|
+
transform: translateY(-8px) scale(0.96);
|
|
48
|
+
}
|
|
49
|
+
to {
|
|
50
|
+
opacity: 1;
|
|
51
|
+
transform: translateY(0) scale(1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.rp-llms-view-options__menu-item {
|
|
56
|
+
display: flex;
|
|
57
|
+
align-items: center;
|
|
58
|
+
gap: 10px;
|
|
59
|
+
width: 100%;
|
|
60
|
+
padding: 8px 10px;
|
|
61
|
+
border: none;
|
|
62
|
+
background: transparent;
|
|
63
|
+
text-align: left;
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
font-size: 14px;
|
|
66
|
+
font-weight: 500;
|
|
67
|
+
border-radius: 6px;
|
|
68
|
+
color: var(--rp-c-text-2);
|
|
69
|
+
transition:
|
|
70
|
+
background 0.2s,
|
|
71
|
+
color 0.2s;
|
|
72
|
+
|
|
73
|
+
&:hover {
|
|
74
|
+
background: var(--rp-c-bg-mute);
|
|
75
|
+
color: var(--rp-c-text-1);
|
|
76
|
+
text-decoration: none;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&:active {
|
|
80
|
+
background: var(--rp-c-bg-soft);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.rp-llms-view-options__item-icon {
|
|
85
|
+
display: inline-flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
justify-content: center;
|
|
88
|
+
width: 16px;
|
|
89
|
+
height: 16px;
|
|
90
|
+
font-size: 16px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.rp-llms-view-options__external-icon {
|
|
94
|
+
margin-left: auto;
|
|
95
|
+
width: 16px;
|
|
96
|
+
height: 16px;
|
|
97
|
+
font-size: 16px;
|
|
98
|
+
}
|