@windrun-huaiin/third-ui 5.6.1 → 5.8.0
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/fuma/mdx/index.d.mts +4 -13
- package/dist/fuma/mdx/index.d.ts +4 -13
- package/dist/fuma/mdx/index.js +19 -10
- package/dist/fuma/mdx/index.js.map +1 -1
- package/dist/fuma/mdx/index.mjs +19 -10
- package/dist/fuma/mdx/index.mjs.map +1 -1
- package/dist/fuma/server.d.mts +5 -3
- package/dist/fuma/server.d.ts +5 -3
- package/dist/fuma/server.js +6 -50
- package/dist/fuma/server.js.map +1 -1
- package/dist/fuma/server.mjs +6 -50
- package/dist/fuma/server.mjs.map +1 -1
- package/dist/toc-base-BC7kXpDU.d.mts +15 -0
- package/dist/toc-base-BC7kXpDU.d.ts +15 -0
- package/package.json +1 -1
- package/src/fuma/fuma-page-genarator.tsx +16 -6
- package/src/fuma/mdx/toc-base.tsx +25 -11
- package/src/fuma/mdx/toc-footer-wrapper.tsx +5 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface LLMCopyButtonProps {
|
|
4
|
+
llmApiUrl?: string;
|
|
5
|
+
sourceKey?: string;
|
|
6
|
+
}
|
|
7
|
+
declare function LLMCopyButton({ llmApiUrl, sourceKey }?: LLMCopyButtonProps): react_jsx_runtime.JSX.Element;
|
|
8
|
+
declare function EditOnGitHub({ url }: {
|
|
9
|
+
url: string;
|
|
10
|
+
}): react_jsx_runtime.JSX.Element;
|
|
11
|
+
declare function LastUpdatedDate({ date }: {
|
|
12
|
+
date: string | undefined;
|
|
13
|
+
}): react_jsx_runtime.JSX.Element;
|
|
14
|
+
|
|
15
|
+
export { EditOnGitHub as E, type LLMCopyButtonProps as L, LLMCopyButton as a, LastUpdatedDate as b };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface LLMCopyButtonProps {
|
|
4
|
+
llmApiUrl?: string;
|
|
5
|
+
sourceKey?: string;
|
|
6
|
+
}
|
|
7
|
+
declare function LLMCopyButton({ llmApiUrl, sourceKey }?: LLMCopyButtonProps): react_jsx_runtime.JSX.Element;
|
|
8
|
+
declare function EditOnGitHub({ url }: {
|
|
9
|
+
url: string;
|
|
10
|
+
}): react_jsx_runtime.JSX.Element;
|
|
11
|
+
declare function LastUpdatedDate({ date }: {
|
|
12
|
+
date: string | undefined;
|
|
13
|
+
}): react_jsx_runtime.JSX.Element;
|
|
14
|
+
|
|
15
|
+
export { EditOnGitHub as E, type LLMCopyButtonProps as L, LLMCopyButton as a, LastUpdatedDate as b };
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { DocsBody, DocsDescription, DocsPage, DocsTitle } from 'fumadocs-ui/page';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import { ReactNode, ReactElement, cloneElement } from 'react';
|
|
3
3
|
import { TocFooterWrapper } from '@third-ui/fuma/mdx';
|
|
4
|
+
import type { LLMCopyButtonProps, LLMCopyButton } from '@third-ui/fuma/mdx';
|
|
4
5
|
|
|
5
|
-
interface FumaPageParams {
|
|
6
|
+
interface FumaPageParams {
|
|
7
|
+
/*
|
|
8
|
+
* The source key of the mdx content, used to generate the edit path
|
|
9
|
+
*/
|
|
10
|
+
sourceKey: string;
|
|
6
11
|
/*
|
|
7
12
|
* The source of the mdx content
|
|
8
13
|
*/
|
|
@@ -20,9 +25,9 @@ interface FumaPageParams {
|
|
|
20
25
|
*/
|
|
21
26
|
githubBaseUrl?: string;
|
|
22
27
|
/*
|
|
23
|
-
*
|
|
28
|
+
* The copy button component, must be LLMCopyButton
|
|
24
29
|
*/
|
|
25
|
-
|
|
30
|
+
copyButtonComponent?: ReactElement<LLMCopyButtonProps, typeof LLMCopyButton>;
|
|
26
31
|
/*
|
|
27
32
|
* The site icon component to use in NotFoundPage
|
|
28
33
|
*/
|
|
@@ -34,11 +39,12 @@ interface FumaPageParams {
|
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
export function createFumaPage({
|
|
42
|
+
sourceKey,
|
|
37
43
|
mdxContentSource,
|
|
38
44
|
getMDXComponents,
|
|
39
45
|
mdxSourceDir,
|
|
40
46
|
githubBaseUrl,
|
|
41
|
-
|
|
47
|
+
copyButtonComponent,
|
|
42
48
|
siteIcon,
|
|
43
49
|
FallbackPage,
|
|
44
50
|
}: FumaPageParams) {
|
|
@@ -53,7 +59,11 @@ export function createFumaPage({
|
|
|
53
59
|
const tocFooterElement = (
|
|
54
60
|
<TocFooterWrapper
|
|
55
61
|
lastModified={page.data.date}
|
|
56
|
-
|
|
62
|
+
copyButtonComponent={
|
|
63
|
+
copyButtonComponent
|
|
64
|
+
? cloneElement(copyButtonComponent, { sourceKey })
|
|
65
|
+
: undefined
|
|
66
|
+
}
|
|
57
67
|
editPath={path}
|
|
58
68
|
githubBaseUrl={githubBaseUrl}
|
|
59
69
|
/>
|
|
@@ -9,7 +9,12 @@ import { Button } from '@base-ui/ui/button';
|
|
|
9
9
|
|
|
10
10
|
const cache = new Map<string, string>();
|
|
11
11
|
|
|
12
|
-
export
|
|
12
|
+
export interface LLMCopyButtonProps {
|
|
13
|
+
llmApiUrl?: string;
|
|
14
|
+
sourceKey?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function LLMCopyButton({ llmApiUrl, sourceKey }: LLMCopyButtonProps = {}) {
|
|
13
18
|
const [isLoading, setLoading] = useState(false);
|
|
14
19
|
const params = useParams();
|
|
15
20
|
const locale = params.locale as string;
|
|
@@ -21,21 +26,30 @@ export function LLMCopyButton({ llmApiUrl }: { llmApiUrl?: string } = {}) {
|
|
|
21
26
|
// Handle cases where slug might be undefined or empty
|
|
22
27
|
const path = (slug && Array.isArray(slug)) ? slug.join('/') : '';
|
|
23
28
|
const apiPrefix = llmApiUrl || '/api/llm-content';
|
|
24
|
-
|
|
29
|
+
let apiUrl = `${apiPrefix}?locale=${encodeURIComponent(locale)}&path=${encodeURIComponent(path)}`;
|
|
30
|
+
if (sourceKey) {
|
|
31
|
+
apiUrl += `&sourceKey=${encodeURIComponent(sourceKey)}`;
|
|
32
|
+
}
|
|
25
33
|
console.log('Fetching LLM content from:', apiUrl);
|
|
26
34
|
|
|
35
|
+
let content: string;
|
|
27
36
|
try {
|
|
28
|
-
|
|
29
|
-
cache.get(apiUrl)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
if (cache.has(apiUrl)) {
|
|
38
|
+
content = cache.get(apiUrl)!;
|
|
39
|
+
} else {
|
|
40
|
+
const res = await fetch(apiUrl);
|
|
41
|
+
if (!res.ok) {
|
|
42
|
+
content = `Error: Failed to fetch LLM content: ${res.status} ${res.statusText}`;
|
|
43
|
+
} else {
|
|
44
|
+
content = await res.text();
|
|
45
|
+
// only success then store cache
|
|
46
|
+
cache.set(apiUrl, content);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
37
49
|
await navigator.clipboard.writeText(content);
|
|
38
50
|
} catch (error) {
|
|
51
|
+
const errMsg = `Error: ${error instanceof Error ? error.message : String(error)}`;
|
|
52
|
+
await navigator.clipboard.writeText(errMsg);
|
|
39
53
|
console.error("Error fetching or copying LLM content:", error);
|
|
40
54
|
} finally {
|
|
41
55
|
setLoading(false);
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { EditOnGitHub, LastUpdatedDate
|
|
2
|
+
import { EditOnGitHub, LastUpdatedDate } from '@third-ui/fuma/mdx/toc-base';
|
|
3
|
+
import React from 'react';
|
|
3
4
|
|
|
4
5
|
interface TocFooterProps {
|
|
5
6
|
lastModified: string | undefined;
|
|
6
7
|
editPath?: string;
|
|
7
8
|
githubBaseUrl?: string;
|
|
8
|
-
|
|
9
|
+
copyButtonComponent?: React.ReactNode;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
export function TocFooterWrapper({ lastModified, editPath, githubBaseUrl,
|
|
12
|
+
export function TocFooterWrapper({ lastModified, editPath, githubBaseUrl, copyButtonComponent }: TocFooterProps) {
|
|
12
13
|
const showEdit = githubBaseUrl && editPath;
|
|
13
14
|
return (
|
|
14
15
|
<div className="flex flex-col gap-y-2 items-start m-4">
|
|
15
16
|
<LastUpdatedDate date={lastModified} />
|
|
16
|
-
{
|
|
17
|
+
{copyButtonComponent}
|
|
17
18
|
{showEdit && <EditOnGitHub url={`${githubBaseUrl}${editPath}`} />}
|
|
18
19
|
</div>
|
|
19
20
|
);
|