@farming-labs/theme 0.0.2-beta.4
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/_virtual/_rolldown/runtime.mjs +7 -0
- package/dist/ai-search-dialog.d.mts +37 -0
- package/dist/ai-search-dialog.mjs +937 -0
- package/dist/darksharp/index.d.mts +97 -0
- package/dist/darksharp/index.mjs +111 -0
- package/dist/default/index.d.mts +97 -0
- package/dist/default/index.mjs +110 -0
- package/dist/docs-ai-features.d.mts +23 -0
- package/dist/docs-ai-features.mjs +81 -0
- package/dist/docs-api.d.mts +68 -0
- package/dist/docs-api.mjs +204 -0
- package/dist/docs-layout.d.mts +33 -0
- package/dist/docs-layout.mjs +331 -0
- package/dist/docs-page-client.d.mts +46 -0
- package/dist/docs-page-client.mjs +128 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +12 -0
- package/dist/mdx.d.mts +38 -0
- package/dist/mdx.mjs +27 -0
- package/dist/page-actions.d.mts +21 -0
- package/dist/page-actions.mjs +155 -0
- package/dist/pixel-border/index.d.mts +87 -0
- package/dist/pixel-border/index.mjs +95 -0
- package/dist/provider.d.mts +14 -0
- package/dist/provider.mjs +29 -0
- package/dist/search.d.mts +34 -0
- package/dist/search.mjs +36 -0
- package/dist/serialize-icon.d.mts +4 -0
- package/dist/serialize-icon.mjs +16 -0
- package/dist/theme.d.mts +2 -0
- package/dist/theme.mjs +3 -0
- package/package.json +90 -0
- package/styles/ai.css +894 -0
- package/styles/base.css +298 -0
- package/styles/darksharp.css +433 -0
- package/styles/default.css +88 -0
- package/styles/fumadocs.css +2 -0
- package/styles/pixel-border.css +671 -0
- package/styles/presets/base.css +14 -0
- package/styles/presets/black.css +14 -0
- package/styles/presets/neutral.css +14 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { DocsTheme } from "@farming-labs/docs";
|
|
2
|
+
|
|
3
|
+
//#region src/darksharp/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Darksharp UI defaults — all-black, sharp edges, zero-radius aesthetic.
|
|
6
|
+
*
|
|
7
|
+
* Theme authors can import and extend:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { DarksharpUIDefaults } from "@farming-labs/theme/darksharp";
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
declare const DarksharpUIDefaults: {
|
|
13
|
+
colors: {
|
|
14
|
+
primary: string;
|
|
15
|
+
background: string;
|
|
16
|
+
muted: string;
|
|
17
|
+
border: string;
|
|
18
|
+
};
|
|
19
|
+
typography: {
|
|
20
|
+
font: {
|
|
21
|
+
style: {
|
|
22
|
+
sans: string;
|
|
23
|
+
mono: string;
|
|
24
|
+
};
|
|
25
|
+
h1: {
|
|
26
|
+
size: string;
|
|
27
|
+
weight: number;
|
|
28
|
+
lineHeight: string;
|
|
29
|
+
letterSpacing: string;
|
|
30
|
+
};
|
|
31
|
+
h2: {
|
|
32
|
+
size: string;
|
|
33
|
+
weight: number;
|
|
34
|
+
lineHeight: string;
|
|
35
|
+
};
|
|
36
|
+
h3: {
|
|
37
|
+
size: string;
|
|
38
|
+
weight: number;
|
|
39
|
+
lineHeight: string;
|
|
40
|
+
};
|
|
41
|
+
h4: {
|
|
42
|
+
size: string;
|
|
43
|
+
weight: number;
|
|
44
|
+
lineHeight: string;
|
|
45
|
+
};
|
|
46
|
+
body: {
|
|
47
|
+
size: string;
|
|
48
|
+
weight: number;
|
|
49
|
+
lineHeight: string;
|
|
50
|
+
};
|
|
51
|
+
small: {
|
|
52
|
+
size: string;
|
|
53
|
+
weight: number;
|
|
54
|
+
lineHeight: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
layout: {
|
|
59
|
+
contentWidth: number;
|
|
60
|
+
sidebarWidth: number;
|
|
61
|
+
toc: {
|
|
62
|
+
enabled: boolean;
|
|
63
|
+
depth: number;
|
|
64
|
+
};
|
|
65
|
+
header: {
|
|
66
|
+
height: number;
|
|
67
|
+
sticky: boolean;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
components: {
|
|
71
|
+
Callout: {
|
|
72
|
+
variant: string;
|
|
73
|
+
icon: boolean;
|
|
74
|
+
};
|
|
75
|
+
CodeBlock: {
|
|
76
|
+
showCopyButton: boolean;
|
|
77
|
+
};
|
|
78
|
+
Tabs: {
|
|
79
|
+
style: string;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Darksharp theme preset factory.
|
|
85
|
+
*
|
|
86
|
+
* Built with `createTheme` — the same helper theme authors use.
|
|
87
|
+
* All-black background, near-zero border-radius, minimal & sharp aesthetic.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { darksharp } from "@farming-labs/theme/darksharp";
|
|
92
|
+
* export default defineDocs({ theme: darksharp() });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare const darksharp: (overrides?: Partial<DocsTheme>) => DocsTheme;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { DarksharpUIDefaults, darksharp };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createTheme } from "@farming-labs/docs";
|
|
2
|
+
|
|
3
|
+
//#region src/darksharp/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Darksharp fumadocs theme preset — all-black, sharp edges, zero-radius look.
|
|
6
|
+
* Inspired by better-auth.com documentation style.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { darksharp } from "@farming-labs/theme/darksharp";
|
|
11
|
+
*
|
|
12
|
+
* export default defineDocs({
|
|
13
|
+
* entry: "docs",
|
|
14
|
+
* theme: darksharp({ ui: { colors: { primary: "#ffffff" } } }),
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* CSS: `@import "@farming-labs/theme/darksharp/css";`
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Darksharp UI defaults — all-black, sharp edges, zero-radius aesthetic.
|
|
22
|
+
*
|
|
23
|
+
* Theme authors can import and extend:
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { DarksharpUIDefaults } from "@farming-labs/theme/darksharp";
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
const DarksharpUIDefaults = {
|
|
29
|
+
colors: {
|
|
30
|
+
primary: "#fafaf9",
|
|
31
|
+
background: "#000000",
|
|
32
|
+
muted: "#a8a29e",
|
|
33
|
+
border: "#292524"
|
|
34
|
+
},
|
|
35
|
+
typography: { font: {
|
|
36
|
+
style: {
|
|
37
|
+
sans: "Geist, system-ui, sans-serif",
|
|
38
|
+
mono: "Geist Mono, monospace"
|
|
39
|
+
},
|
|
40
|
+
h1: {
|
|
41
|
+
size: "2rem",
|
|
42
|
+
weight: 700,
|
|
43
|
+
lineHeight: "1.2",
|
|
44
|
+
letterSpacing: "-0.02em"
|
|
45
|
+
},
|
|
46
|
+
h2: {
|
|
47
|
+
size: "1.5rem",
|
|
48
|
+
weight: 600,
|
|
49
|
+
lineHeight: "1.3"
|
|
50
|
+
},
|
|
51
|
+
h3: {
|
|
52
|
+
size: "1.25rem",
|
|
53
|
+
weight: 600,
|
|
54
|
+
lineHeight: "1.4"
|
|
55
|
+
},
|
|
56
|
+
h4: {
|
|
57
|
+
size: "1.125rem",
|
|
58
|
+
weight: 600,
|
|
59
|
+
lineHeight: "1.4"
|
|
60
|
+
},
|
|
61
|
+
body: {
|
|
62
|
+
size: "1rem",
|
|
63
|
+
weight: 400,
|
|
64
|
+
lineHeight: "1.75"
|
|
65
|
+
},
|
|
66
|
+
small: {
|
|
67
|
+
size: "0.875rem",
|
|
68
|
+
weight: 400,
|
|
69
|
+
lineHeight: "1.5"
|
|
70
|
+
}
|
|
71
|
+
} },
|
|
72
|
+
layout: {
|
|
73
|
+
contentWidth: 768,
|
|
74
|
+
sidebarWidth: 280,
|
|
75
|
+
toc: {
|
|
76
|
+
enabled: true,
|
|
77
|
+
depth: 3
|
|
78
|
+
},
|
|
79
|
+
header: {
|
|
80
|
+
height: 56,
|
|
81
|
+
sticky: true
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
components: {
|
|
85
|
+
Callout: {
|
|
86
|
+
variant: "soft",
|
|
87
|
+
icon: true
|
|
88
|
+
},
|
|
89
|
+
CodeBlock: { showCopyButton: true },
|
|
90
|
+
Tabs: { style: "default" }
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Darksharp theme preset factory.
|
|
95
|
+
*
|
|
96
|
+
* Built with `createTheme` — the same helper theme authors use.
|
|
97
|
+
* All-black background, near-zero border-radius, minimal & sharp aesthetic.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { darksharp } from "@farming-labs/theme/darksharp";
|
|
102
|
+
* export default defineDocs({ theme: darksharp() });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
const darksharp = createTheme({
|
|
106
|
+
name: "fumadocs-darksharp",
|
|
107
|
+
ui: DarksharpUIDefaults
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
export { DarksharpUIDefaults, darksharp };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { DocsTheme } from "@farming-labs/docs";
|
|
2
|
+
|
|
3
|
+
//#region src/default/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Default UI configuration — neutral palette, standard border-radius.
|
|
6
|
+
*
|
|
7
|
+
* Theme authors can import this and extend it:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { DefaultUIDefaults } from "@farming-labs/theme/default";
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
declare const DefaultUIDefaults: {
|
|
13
|
+
colors: {
|
|
14
|
+
primary: string;
|
|
15
|
+
background: string;
|
|
16
|
+
muted: string;
|
|
17
|
+
border: string;
|
|
18
|
+
};
|
|
19
|
+
typography: {
|
|
20
|
+
font: {
|
|
21
|
+
style: {
|
|
22
|
+
sans: string;
|
|
23
|
+
mono: string;
|
|
24
|
+
};
|
|
25
|
+
h1: {
|
|
26
|
+
size: string;
|
|
27
|
+
weight: number;
|
|
28
|
+
lineHeight: string;
|
|
29
|
+
letterSpacing: string;
|
|
30
|
+
};
|
|
31
|
+
h2: {
|
|
32
|
+
size: string;
|
|
33
|
+
weight: number;
|
|
34
|
+
lineHeight: string;
|
|
35
|
+
};
|
|
36
|
+
h3: {
|
|
37
|
+
size: string;
|
|
38
|
+
weight: number;
|
|
39
|
+
lineHeight: string;
|
|
40
|
+
};
|
|
41
|
+
h4: {
|
|
42
|
+
size: string;
|
|
43
|
+
weight: number;
|
|
44
|
+
lineHeight: string;
|
|
45
|
+
};
|
|
46
|
+
body: {
|
|
47
|
+
size: string;
|
|
48
|
+
weight: number;
|
|
49
|
+
lineHeight: string;
|
|
50
|
+
};
|
|
51
|
+
small: {
|
|
52
|
+
size: string;
|
|
53
|
+
weight: number;
|
|
54
|
+
lineHeight: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
layout: {
|
|
59
|
+
contentWidth: number;
|
|
60
|
+
sidebarWidth: number;
|
|
61
|
+
toc: {
|
|
62
|
+
enabled: boolean;
|
|
63
|
+
depth: number;
|
|
64
|
+
};
|
|
65
|
+
header: {
|
|
66
|
+
height: number;
|
|
67
|
+
sticky: boolean;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
components: {
|
|
71
|
+
Callout: {
|
|
72
|
+
variant: string;
|
|
73
|
+
icon: boolean;
|
|
74
|
+
};
|
|
75
|
+
CodeBlock: {
|
|
76
|
+
showCopyButton: boolean;
|
|
77
|
+
};
|
|
78
|
+
Tabs: {
|
|
79
|
+
style: string;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Default fumadocs theme preset factory.
|
|
85
|
+
*
|
|
86
|
+
* Built with `createTheme` — the same helper theme authors use.
|
|
87
|
+
* Merges user overrides on top of sensible defaults.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { fumadocs } from "@farming-labs/theme/default";
|
|
92
|
+
* export default defineDocs({ theme: fumadocs({ ui: { colors: { primary: "#22c55e" } } }) });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare const fumadocs: (overrides?: Partial<DocsTheme>) => DocsTheme;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { DefaultUIDefaults, fumadocs };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createTheme } from "@farming-labs/docs";
|
|
2
|
+
|
|
3
|
+
//#region src/default/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Default fumadocs theme preset — neutral colors, standard radius.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { fumadocs } from "@farming-labs/theme/default";
|
|
10
|
+
*
|
|
11
|
+
* export default defineDocs({
|
|
12
|
+
* entry: "docs",
|
|
13
|
+
* theme: fumadocs({ ui: { colors: { primary: "#22c55e" } } }),
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* CSS: `@import "@farming-labs/theme/default/css";`
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Default UI configuration — neutral palette, standard border-radius.
|
|
21
|
+
*
|
|
22
|
+
* Theme authors can import this and extend it:
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { DefaultUIDefaults } from "@farming-labs/theme/default";
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const DefaultUIDefaults = {
|
|
28
|
+
colors: {
|
|
29
|
+
primary: "#6366f1",
|
|
30
|
+
background: "#ffffff",
|
|
31
|
+
muted: "#64748b",
|
|
32
|
+
border: "#e5e7eb"
|
|
33
|
+
},
|
|
34
|
+
typography: { font: {
|
|
35
|
+
style: {
|
|
36
|
+
sans: "Inter, system-ui, sans-serif",
|
|
37
|
+
mono: "JetBrains Mono, monospace"
|
|
38
|
+
},
|
|
39
|
+
h1: {
|
|
40
|
+
size: "2rem",
|
|
41
|
+
weight: 700,
|
|
42
|
+
lineHeight: "1.2",
|
|
43
|
+
letterSpacing: "-0.02em"
|
|
44
|
+
},
|
|
45
|
+
h2: {
|
|
46
|
+
size: "1.5rem",
|
|
47
|
+
weight: 600,
|
|
48
|
+
lineHeight: "1.3"
|
|
49
|
+
},
|
|
50
|
+
h3: {
|
|
51
|
+
size: "1.25rem",
|
|
52
|
+
weight: 600,
|
|
53
|
+
lineHeight: "1.4"
|
|
54
|
+
},
|
|
55
|
+
h4: {
|
|
56
|
+
size: "1.125rem",
|
|
57
|
+
weight: 600,
|
|
58
|
+
lineHeight: "1.4"
|
|
59
|
+
},
|
|
60
|
+
body: {
|
|
61
|
+
size: "1rem",
|
|
62
|
+
weight: 400,
|
|
63
|
+
lineHeight: "1.75"
|
|
64
|
+
},
|
|
65
|
+
small: {
|
|
66
|
+
size: "0.875rem",
|
|
67
|
+
weight: 400,
|
|
68
|
+
lineHeight: "1.5"
|
|
69
|
+
}
|
|
70
|
+
} },
|
|
71
|
+
layout: {
|
|
72
|
+
contentWidth: 768,
|
|
73
|
+
sidebarWidth: 280,
|
|
74
|
+
toc: {
|
|
75
|
+
enabled: true,
|
|
76
|
+
depth: 3
|
|
77
|
+
},
|
|
78
|
+
header: {
|
|
79
|
+
height: 72,
|
|
80
|
+
sticky: true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
components: {
|
|
84
|
+
Callout: {
|
|
85
|
+
variant: "soft",
|
|
86
|
+
icon: true
|
|
87
|
+
},
|
|
88
|
+
CodeBlock: { showCopyButton: true },
|
|
89
|
+
Tabs: { style: "default" }
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Default fumadocs theme preset factory.
|
|
94
|
+
*
|
|
95
|
+
* Built with `createTheme` — the same helper theme authors use.
|
|
96
|
+
* Merges user overrides on top of sensible defaults.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { fumadocs } from "@farming-labs/theme/default";
|
|
101
|
+
* export default defineDocs({ theme: fumadocs({ ui: { colors: { primary: "#22c55e" } } }) });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
const fumadocs = createTheme({
|
|
105
|
+
name: "fumadocs-default",
|
|
106
|
+
ui: DefaultUIDefaults
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
export { DefaultUIDefaults, fumadocs };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
//#region src/docs-ai-features.d.ts
|
|
4
|
+
interface DocsAIFeaturesProps {
|
|
5
|
+
mode: "search" | "floating";
|
|
6
|
+
position?: "bottom-right" | "bottom-left" | "bottom-center";
|
|
7
|
+
floatingStyle?: "panel" | "modal" | "popover" | "full-modal";
|
|
8
|
+
triggerComponentHtml?: string;
|
|
9
|
+
suggestedQuestions?: string[];
|
|
10
|
+
aiLabel?: string;
|
|
11
|
+
loadingComponentHtml?: string;
|
|
12
|
+
}
|
|
13
|
+
declare function DocsAIFeatures({
|
|
14
|
+
mode,
|
|
15
|
+
position,
|
|
16
|
+
floatingStyle,
|
|
17
|
+
triggerComponentHtml,
|
|
18
|
+
suggestedQuestions,
|
|
19
|
+
aiLabel,
|
|
20
|
+
loadingComponentHtml
|
|
21
|
+
}: DocsAIFeaturesProps): react_jsx_runtime0.JSX.Element;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { DocsAIFeatures };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { DocsSearchDialog, FloatingAIChat } from "./ai-search-dialog.mjs";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/docs-ai-features.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Client component injected by `createDocsLayout` when `ai` is configured.
|
|
10
|
+
*
|
|
11
|
+
* Handles both modes:
|
|
12
|
+
* - "search": Intercepts Cmd+K / Ctrl+K and opens the custom search dialog
|
|
13
|
+
* with Search + Ask AI tabs (prevents fumadocs' default dialog from opening).
|
|
14
|
+
* - "floating": Renders the floating chat widget with configurable position,
|
|
15
|
+
* style, and trigger component.
|
|
16
|
+
*
|
|
17
|
+
* This component is rendered inside the docs layout so the user's root layout
|
|
18
|
+
* never needs to be modified — AI features work purely from `docs.config.tsx`.
|
|
19
|
+
*/
|
|
20
|
+
function DocsAIFeatures({ mode, position = "bottom-right", floatingStyle = "panel", triggerComponentHtml, suggestedQuestions, aiLabel, loadingComponentHtml }) {
|
|
21
|
+
if (mode === "search") return /* @__PURE__ */ jsx(SearchModeAI, {
|
|
22
|
+
suggestedQuestions,
|
|
23
|
+
aiLabel,
|
|
24
|
+
loadingComponentHtml
|
|
25
|
+
});
|
|
26
|
+
return /* @__PURE__ */ jsx(FloatingAIChat, {
|
|
27
|
+
api: "/api/docs",
|
|
28
|
+
position,
|
|
29
|
+
floatingStyle,
|
|
30
|
+
triggerComponentHtml,
|
|
31
|
+
suggestedQuestions,
|
|
32
|
+
aiLabel,
|
|
33
|
+
loadingComponentHtml
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Search mode: intercepts Cmd+K / Ctrl+K globally and opens the
|
|
38
|
+
* custom search dialog (with Search + Ask AI tabs) instead of
|
|
39
|
+
* fumadocs' built-in search dialog.
|
|
40
|
+
*/
|
|
41
|
+
function SearchModeAI({ suggestedQuestions, aiLabel, loadingComponentHtml }) {
|
|
42
|
+
const [open, setOpen] = useState(false);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
function handler(e) {
|
|
45
|
+
if ((e.metaKey || e.ctrlKey) && e.key === "k") {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
e.stopPropagation();
|
|
48
|
+
e.stopImmediatePropagation();
|
|
49
|
+
setOpen(true);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
document.addEventListener("keydown", handler, true);
|
|
53
|
+
return () => document.removeEventListener("keydown", handler, true);
|
|
54
|
+
}, []);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
function handler(e) {
|
|
57
|
+
const button = e.target.closest("button");
|
|
58
|
+
if (!button) return;
|
|
59
|
+
const text = button.textContent || "";
|
|
60
|
+
if (text.includes("Search") && (text.includes("⌘") || text.includes("K"))) {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
e.stopPropagation();
|
|
63
|
+
e.stopImmediatePropagation();
|
|
64
|
+
setOpen(true);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
document.addEventListener("click", handler, true);
|
|
68
|
+
return () => document.removeEventListener("click", handler, true);
|
|
69
|
+
}, []);
|
|
70
|
+
return /* @__PURE__ */ jsx(DocsSearchDialog, {
|
|
71
|
+
open,
|
|
72
|
+
onOpenChange: setOpen,
|
|
73
|
+
api: "/api/docs",
|
|
74
|
+
suggestedQuestions,
|
|
75
|
+
aiLabel,
|
|
76
|
+
loadingComponentHtml
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { DocsAIFeatures };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/docs-api.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Unified docs API handler for @farming-labs/theme.
|
|
4
|
+
*
|
|
5
|
+
* A single route handler that serves **both** search and AI chat:
|
|
6
|
+
*
|
|
7
|
+
* - `GET /api/docs?query=…` → full-text search over indexed MDX pages
|
|
8
|
+
* - `POST /api/docs` → RAG-powered "Ask AI" (searches relevant docs,
|
|
9
|
+
* then streams an LLM response using the docs as context)
|
|
10
|
+
*
|
|
11
|
+
* This replaces the old `createDocsSearchAPI` — one handler, one route.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // app/api/docs/route.ts (auto-generated by withDocs)
|
|
16
|
+
* import { createDocsAPI } from "@farming-labs/theme/api";
|
|
17
|
+
* export const { GET, POST } = createDocsAPI();
|
|
18
|
+
* export const revalidate = false;
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
interface AIOptions {
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
model?: string;
|
|
24
|
+
systemPrompt?: string;
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
apiKey?: string;
|
|
27
|
+
maxResults?: number;
|
|
28
|
+
}
|
|
29
|
+
interface DocsAPIOptions {
|
|
30
|
+
/** Docs entry folder (default: read from docs.config) */
|
|
31
|
+
entry?: string;
|
|
32
|
+
/** Search language (default: "english") */
|
|
33
|
+
language?: string;
|
|
34
|
+
/** AI chat configuration */
|
|
35
|
+
ai?: AIOptions;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a unified docs API route handler.
|
|
39
|
+
*
|
|
40
|
+
* Returns `{ GET, POST }` for use in a Next.js route handler:
|
|
41
|
+
* - **GET** → full-text search (same as the old `createDocsSearchAPI`)
|
|
42
|
+
* - **POST** → AI-powered chat with RAG (when AI is enabled in config)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* // app/api/docs/route.ts
|
|
47
|
+
* import { createDocsAPI } from "@farming-labs/theme/api";
|
|
48
|
+
* export const { GET, POST } = createDocsAPI();
|
|
49
|
+
* export const revalidate = false;
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param options - Optional overrides (entry, language, ai config)
|
|
53
|
+
*/
|
|
54
|
+
declare function createDocsAPI(options?: DocsAPIOptions): {
|
|
55
|
+
/**
|
|
56
|
+
* GET handler — full-text search.
|
|
57
|
+
* Query: `?query=search+term`
|
|
58
|
+
*/
|
|
59
|
+
GET: (request: Request) => Promise<Response>;
|
|
60
|
+
/**
|
|
61
|
+
* POST handler — AI chat with RAG.
|
|
62
|
+
* Body: `{ messages: [{ role: "user", content: "How do I …?" }] }`
|
|
63
|
+
* Response: SSE stream of chat completion chunks.
|
|
64
|
+
*/
|
|
65
|
+
POST(request: Request): Promise<Response>;
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { createDocsAPI };
|