@farming-labs/nuxt-theme 0.0.2-beta.17
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/package.json +71 -0
- package/src/components/Breadcrumb.vue +45 -0
- package/src/components/DocsContent.vue +77 -0
- package/src/components/DocsLayout.vue +354 -0
- package/src/components/DocsPage.vue +146 -0
- package/src/components/FloatingAIChat.vue +436 -0
- package/src/components/SearchDialog.vue +94 -0
- package/src/components/TableOfContents.vue +302 -0
- package/src/components/ThemeToggle.vue +42 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +18 -0
- package/src/lib/renderMarkdown.js +108 -0
- package/src/themes/colorful.d.ts +2 -0
- package/src/themes/colorful.js +42 -0
- package/src/themes/darksharp.d.ts +4 -0
- package/src/themes/darksharp.js +42 -0
- package/src/themes/default.d.ts +4 -0
- package/src/themes/default.js +42 -0
- package/src/themes/pixel-border.d.ts +4 -0
- package/src/themes/pixel-border.js +38 -0
- package/styles/colorful-bundle.css +2 -0
- package/styles/colorful.css +148 -0
- package/styles/darksharp-bundle.css +6 -0
- package/styles/darksharp.css +206 -0
- package/styles/docs.css +2218 -0
- package/styles/pixel-border-bundle.css +6 -0
- package/styles/pixel-border.css +606 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, onMounted, watch } from "vue";
|
|
3
|
+
import Breadcrumb from "./Breadcrumb.vue";
|
|
4
|
+
import TableOfContents from "./TableOfContents.vue";
|
|
5
|
+
|
|
6
|
+
const props = withDefaults(
|
|
7
|
+
defineProps<{
|
|
8
|
+
tocEnabled?: boolean;
|
|
9
|
+
tocStyle?: "default" | "directional";
|
|
10
|
+
breadcrumbEnabled?: boolean;
|
|
11
|
+
entry?: string;
|
|
12
|
+
previousPage?: { name: string; url: string } | null;
|
|
13
|
+
nextPage?: { name: string; url: string } | null;
|
|
14
|
+
editOnGithub?: string | null;
|
|
15
|
+
lastModified?: string | null;
|
|
16
|
+
}>(),
|
|
17
|
+
{
|
|
18
|
+
tocEnabled: true,
|
|
19
|
+
tocStyle: "default",
|
|
20
|
+
breadcrumbEnabled: true,
|
|
21
|
+
entry: "docs",
|
|
22
|
+
previousPage: null,
|
|
23
|
+
nextPage: null,
|
|
24
|
+
editOnGithub: null,
|
|
25
|
+
lastModified: null,
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const route = useRoute();
|
|
30
|
+
const tocItems = ref<{ title: string; url: string; depth: number }[]>([]);
|
|
31
|
+
|
|
32
|
+
function scanHeadings() {
|
|
33
|
+
requestAnimationFrame(() => {
|
|
34
|
+
const container = document.querySelector(".fd-page-body");
|
|
35
|
+
if (!container) return;
|
|
36
|
+
const headings = container.querySelectorAll("h2[id], h3[id], h4[id]");
|
|
37
|
+
tocItems.value = Array.from(headings).map((el) => ({
|
|
38
|
+
title: (el.textContent ?? "").replace(/^#\s*/, ""),
|
|
39
|
+
url: `#${el.id}`,
|
|
40
|
+
depth: parseInt(el.tagName[1], 10),
|
|
41
|
+
}));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function wireInteractive() {
|
|
46
|
+
requestAnimationFrame(() => {
|
|
47
|
+
document.querySelectorAll(".fd-copy-btn").forEach((btn) => {
|
|
48
|
+
btn.addEventListener("click", () => {
|
|
49
|
+
const code = btn
|
|
50
|
+
.getAttribute("data-code")
|
|
51
|
+
?.replace(/&/g, "&")
|
|
52
|
+
.replace(/</g, "<")
|
|
53
|
+
.replace(/>/g, ">")
|
|
54
|
+
.replace(/"/g, '"');
|
|
55
|
+
if (!code) return;
|
|
56
|
+
navigator.clipboard.writeText(code).then(() => {
|
|
57
|
+
btn.classList.add("fd-copy-btn-copied");
|
|
58
|
+
btn.innerHTML =
|
|
59
|
+
'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>';
|
|
60
|
+
setTimeout(() => {
|
|
61
|
+
btn.classList.remove("fd-copy-btn-copied");
|
|
62
|
+
btn.innerHTML =
|
|
63
|
+
'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>';
|
|
64
|
+
}, 2000);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
document.querySelectorAll("[data-tabs]").forEach((tabs) => {
|
|
69
|
+
tabs.querySelectorAll(".fd-tab-trigger").forEach((trigger) => {
|
|
70
|
+
trigger.addEventListener("click", () => {
|
|
71
|
+
const val = trigger.getAttribute("data-tab-value");
|
|
72
|
+
tabs.querySelectorAll(".fd-tab-trigger").forEach((t) => {
|
|
73
|
+
t.classList.toggle("fd-tab-active", t.getAttribute("data-tab-value") === val);
|
|
74
|
+
t.setAttribute("aria-selected", String(t.getAttribute("data-tab-value") === val));
|
|
75
|
+
});
|
|
76
|
+
tabs.querySelectorAll(".fd-tab-panel").forEach((p) => {
|
|
77
|
+
p.classList.toggle("fd-tab-panel-active", p.getAttribute("data-tab-panel") === val);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
onMounted(() => {
|
|
86
|
+
scanHeadings();
|
|
87
|
+
wireInteractive();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
watch(() => route.path, () => {
|
|
91
|
+
scanHeadings();
|
|
92
|
+
wireInteractive();
|
|
93
|
+
});
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<template>
|
|
97
|
+
<div class="fd-page">
|
|
98
|
+
<article class="fd-page-article" id="nd-page">
|
|
99
|
+
<Breadcrumb v-if="breadcrumbEnabled" :pathname="route.path" :entry="entry" />
|
|
100
|
+
|
|
101
|
+
<div class="fd-page-body">
|
|
102
|
+
<slot />
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<footer class="fd-page-footer">
|
|
106
|
+
<div v-if="editOnGithub || lastModified" class="fd-edit-on-github">
|
|
107
|
+
<a v-if="editOnGithub" :href="editOnGithub" target="_blank" rel="noopener noreferrer">
|
|
108
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
109
|
+
<path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7" />
|
|
110
|
+
<path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z" />
|
|
111
|
+
</svg>
|
|
112
|
+
Edit on GitHub
|
|
113
|
+
</a>
|
|
114
|
+
<span v-if="lastModified" class="fd-last-modified">Last updated: {{ lastModified }}</span>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
<nav v-if="previousPage || nextPage" class="fd-page-nav" aria-label="Page navigation">
|
|
118
|
+
<NuxtLink v-if="previousPage" :to="previousPage.url" class="fd-page-nav-card fd-page-nav-prev">
|
|
119
|
+
<span class="fd-page-nav-label">
|
|
120
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
121
|
+
<polyline points="15 18 9 12 15 6" />
|
|
122
|
+
</svg>
|
|
123
|
+
Previous
|
|
124
|
+
</span>
|
|
125
|
+
<span class="fd-page-nav-title">{{ previousPage.name }}</span>
|
|
126
|
+
</NuxtLink>
|
|
127
|
+
<div v-else></div>
|
|
128
|
+
<NuxtLink v-if="nextPage" :to="nextPage.url" class="fd-page-nav-card fd-page-nav-next">
|
|
129
|
+
<span class="fd-page-nav-label">
|
|
130
|
+
Next
|
|
131
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
132
|
+
<polyline points="9 18 15 12 9 6" />
|
|
133
|
+
</svg>
|
|
134
|
+
</span>
|
|
135
|
+
<span class="fd-page-nav-title">{{ nextPage.name }}</span>
|
|
136
|
+
</NuxtLink>
|
|
137
|
+
<div v-else></div>
|
|
138
|
+
</nav>
|
|
139
|
+
</footer>
|
|
140
|
+
</article>
|
|
141
|
+
|
|
142
|
+
<aside v-if="tocEnabled" class="fd-toc">
|
|
143
|
+
<TableOfContents :items="tocItems" :toc-style="tocStyle" />
|
|
144
|
+
</aside>
|
|
145
|
+
</div>
|
|
146
|
+
</template>
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed, watch, nextTick, onMounted } from "vue";
|
|
3
|
+
import { renderMarkdown } from "../lib/renderMarkdown.js";
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
api?: string;
|
|
8
|
+
suggestedQuestions?: string[];
|
|
9
|
+
aiLabel?: string;
|
|
10
|
+
position?: string;
|
|
11
|
+
floatingStyle?: "panel" | "modal" | "popover" | "full-modal";
|
|
12
|
+
triggerComponent?: object | null;
|
|
13
|
+
}>(),
|
|
14
|
+
{
|
|
15
|
+
api: "/api/docs",
|
|
16
|
+
suggestedQuestions: () => [],
|
|
17
|
+
aiLabel: "AI",
|
|
18
|
+
position: "bottom-right",
|
|
19
|
+
floatingStyle: "panel",
|
|
20
|
+
triggerComponent: null,
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const mounted = ref(false);
|
|
25
|
+
const isOpen = ref(false);
|
|
26
|
+
const messages = ref<{ role: string; content: string }[]>([]);
|
|
27
|
+
const aiInput = ref("");
|
|
28
|
+
const isStreaming = ref(false);
|
|
29
|
+
const fmListEl = ref<HTMLElement | null>(null);
|
|
30
|
+
const fmInputEl = ref<HTMLTextAreaElement | null>(null);
|
|
31
|
+
const messagesEndEl = ref<HTMLElement | null>(null);
|
|
32
|
+
|
|
33
|
+
onMounted(() => { mounted.value = true; });
|
|
34
|
+
|
|
35
|
+
const isFullModal = computed(() => props.floatingStyle === "full-modal");
|
|
36
|
+
const isModal = computed(() => props.floatingStyle === "modal");
|
|
37
|
+
const label = computed(() => props.aiLabel || "AI");
|
|
38
|
+
const canSend = computed(() => !!aiInput.value.trim() && !isStreaming.value);
|
|
39
|
+
const showSuggestions = computed(() => messages.value.length === 0 && !isStreaming.value);
|
|
40
|
+
|
|
41
|
+
const BTN_POSITIONS: Record<string, string> = {
|
|
42
|
+
"bottom-right": "bottom:24px;right:24px",
|
|
43
|
+
"bottom-left": "bottom:24px;left:24px",
|
|
44
|
+
"bottom-center": "bottom:24px;left:50%;transform:translateX(-50%)",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const PANEL_POSITIONS: Record<string, string> = {
|
|
48
|
+
"bottom-right": "bottom:80px;right:24px",
|
|
49
|
+
"bottom-left": "bottom:80px;left:24px",
|
|
50
|
+
"bottom-center": "bottom:80px;left:50%;transform:translateX(-50%)",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const btnStyle = computed(() => BTN_POSITIONS[props.position] ?? BTN_POSITIONS["bottom-right"]);
|
|
54
|
+
|
|
55
|
+
const containerStyle = computed(() => {
|
|
56
|
+
switch (props.floatingStyle) {
|
|
57
|
+
case "modal":
|
|
58
|
+
return "top:50%;left:50%;transform:translate(-50%,-50%);width:min(680px,calc(100vw - 32px));height:min(560px,calc(100vh - 64px))";
|
|
59
|
+
case "popover":
|
|
60
|
+
return `${PANEL_POSITIONS[props.position] ?? PANEL_POSITIONS["bottom-right"]};width:min(360px,calc(100vw - 48px));height:min(400px,calc(100vh - 120px))`;
|
|
61
|
+
default:
|
|
62
|
+
return `${PANEL_POSITIONS[props.position] ?? PANEL_POSITIONS["bottom-right"]};width:min(400px,calc(100vw - 48px));height:min(500px,calc(100vh - 120px))`;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const animation = computed(() =>
|
|
67
|
+
props.floatingStyle === "modal"
|
|
68
|
+
? "fd-ai-float-center-in 200ms ease-out"
|
|
69
|
+
: "fd-ai-float-in 200ms ease-out"
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
watch(isOpen, (open) => {
|
|
73
|
+
if (open && (isModal.value || isFullModal.value)) {
|
|
74
|
+
document.body.style.overflow = "hidden";
|
|
75
|
+
} else {
|
|
76
|
+
document.body.style.overflow = "";
|
|
77
|
+
}
|
|
78
|
+
if (open && isFullModal.value) {
|
|
79
|
+
nextTick(() => fmInputEl.value?.focus());
|
|
80
|
+
}
|
|
81
|
+
if (open && !isFullModal.value) {
|
|
82
|
+
nextTick(() => {
|
|
83
|
+
const input = document.querySelector(".fd-ai-input") as HTMLInputElement;
|
|
84
|
+
input?.focus();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
watch(() => messages.value.length, () => {
|
|
90
|
+
if (isFullModal.value && fmListEl.value) {
|
|
91
|
+
nextTick(() => fmListEl.value?.scrollTo({ top: fmListEl.value.scrollHeight, behavior: "smooth" }));
|
|
92
|
+
}
|
|
93
|
+
if (!isFullModal.value) {
|
|
94
|
+
nextTick(() => messagesEndEl.value?.scrollIntoView({ behavior: "smooth" }));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
async function submitQuestion(question: string) {
|
|
99
|
+
if (!question.trim() || isStreaming.value) return;
|
|
100
|
+
const userMsg = { role: "user", content: question };
|
|
101
|
+
const newMessages = [...messages.value, userMsg];
|
|
102
|
+
aiInput.value = "";
|
|
103
|
+
isStreaming.value = true;
|
|
104
|
+
messages.value = [...newMessages, { role: "assistant", content: "" }];
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const res = await fetch(props.api, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: { "Content-Type": "application/json" },
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
messages: newMessages.map((m) => ({ role: m.role, content: m.content })),
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if (!res.ok) {
|
|
116
|
+
const err = await res.json().catch(() => ({}));
|
|
117
|
+
messages.value = [...newMessages, { role: "assistant", content: (err as any).error ?? "Something went wrong." }];
|
|
118
|
+
isStreaming.value = false;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const reader = res.body!.getReader();
|
|
123
|
+
const decoder = new TextDecoder();
|
|
124
|
+
let buffer = "";
|
|
125
|
+
let assistantContent = "";
|
|
126
|
+
|
|
127
|
+
while (true) {
|
|
128
|
+
const { done, value } = await reader.read();
|
|
129
|
+
if (done) break;
|
|
130
|
+
buffer += decoder.decode(value, { stream: true });
|
|
131
|
+
const lines = buffer.split("\n");
|
|
132
|
+
buffer = lines.pop() ?? "";
|
|
133
|
+
for (const line of lines) {
|
|
134
|
+
if (line.startsWith("data: ")) {
|
|
135
|
+
const data = line.slice(6).trim();
|
|
136
|
+
if (data === "[DONE]") continue;
|
|
137
|
+
try {
|
|
138
|
+
const json = JSON.parse(data);
|
|
139
|
+
const content = json.choices?.[0]?.delta?.content;
|
|
140
|
+
if (content) {
|
|
141
|
+
assistantContent += content;
|
|
142
|
+
messages.value = [...newMessages, { role: "assistant", content: assistantContent }];
|
|
143
|
+
}
|
|
144
|
+
} catch {}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
messages.value = [...newMessages, { role: "assistant", content: assistantContent }];
|
|
149
|
+
} catch {
|
|
150
|
+
messages.value = [...newMessages, { role: "assistant", content: "Failed to connect. Please try again." }];
|
|
151
|
+
}
|
|
152
|
+
isStreaming.value = false;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function clearChat() {
|
|
156
|
+
if (!isStreaming.value) {
|
|
157
|
+
messages.value = [];
|
|
158
|
+
aiInput.value = "";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
163
|
+
if (e.key === "Escape" && isOpen.value) isOpen.value = false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function handleFmKeyDown(e: KeyboardEvent) {
|
|
167
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
submitQuestion(aiInput.value);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
</script>
|
|
173
|
+
|
|
174
|
+
<template>
|
|
175
|
+
<!-- ═══ FULL-MODAL: overlay + messages (only when full-modal AND open) ═══ -->
|
|
176
|
+
<Teleport to="body" v-if="mounted && isFullModal && isOpen">
|
|
177
|
+
<div class="fd-ai-fm-overlay" @click.self="isOpen = false" @keydown="handleKeydown">
|
|
178
|
+
<div class="fd-ai-fm-topbar">
|
|
179
|
+
<button class="fd-ai-fm-close-btn" type="button" aria-label="Close" @click="isOpen = false">
|
|
180
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
181
|
+
<path d="M18 6 6 18" /><path d="m6 6 12 12" />
|
|
182
|
+
</svg>
|
|
183
|
+
</button>
|
|
184
|
+
</div>
|
|
185
|
+
<div ref="fmListEl" class="fd-ai-fm-messages">
|
|
186
|
+
<div class="fd-ai-fm-messages-inner">
|
|
187
|
+
<div v-for="(msg, i) in messages" :key="i" class="fd-ai-fm-msg" :data-role="msg.role">
|
|
188
|
+
<div class="fd-ai-fm-msg-label" :data-role="msg.role">
|
|
189
|
+
{{ msg.role === "user" ? "you" : label }}
|
|
190
|
+
</div>
|
|
191
|
+
<div class="fd-ai-fm-msg-content">
|
|
192
|
+
<template v-if="msg.content">
|
|
193
|
+
<div v-html="renderMarkdown(msg.content)" />
|
|
194
|
+
</template>
|
|
195
|
+
<div v-else class="fd-ai-fm-thinking">
|
|
196
|
+
<span class="fd-ai-fm-thinking-dot" />
|
|
197
|
+
<span class="fd-ai-fm-thinking-dot" />
|
|
198
|
+
<span class="fd-ai-fm-thinking-dot" />
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
</Teleport>
|
|
206
|
+
|
|
207
|
+
<!-- ═══ FULL-MODAL: bottom input bar (only when full-modal) ═══ -->
|
|
208
|
+
<Teleport to="body" v-if="mounted && isFullModal">
|
|
209
|
+
<div
|
|
210
|
+
class="fd-ai-fm-input-bar"
|
|
211
|
+
:class="isOpen ? 'fd-ai-fm-input-bar--open' : 'fd-ai-fm-input-bar--closed'"
|
|
212
|
+
:style="isOpen ? undefined : btnStyle"
|
|
213
|
+
>
|
|
214
|
+
<div
|
|
215
|
+
v-if="!isOpen && triggerComponent"
|
|
216
|
+
class="fd-ai-floating-trigger"
|
|
217
|
+
:style="btnStyle"
|
|
218
|
+
@click="isOpen = true"
|
|
219
|
+
>
|
|
220
|
+
<component :is="triggerComponent" />
|
|
221
|
+
</div>
|
|
222
|
+
<button
|
|
223
|
+
v-else-if="!isOpen"
|
|
224
|
+
class="fd-ai-fm-trigger-btn"
|
|
225
|
+
type="button"
|
|
226
|
+
:aria-label="`Ask ${label}`"
|
|
227
|
+
@click="isOpen = true"
|
|
228
|
+
>
|
|
229
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
230
|
+
<path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" />
|
|
231
|
+
<path d="M20 3v4" /><path d="M22 5h-4" />
|
|
232
|
+
</svg>
|
|
233
|
+
<span>Ask {{ label }}</span>
|
|
234
|
+
</button>
|
|
235
|
+
|
|
236
|
+
<div v-else class="fd-ai-fm-input-container">
|
|
237
|
+
<div class="fd-ai-fm-input-wrap">
|
|
238
|
+
<textarea
|
|
239
|
+
ref="fmInputEl"
|
|
240
|
+
v-model="aiInput"
|
|
241
|
+
class="fd-ai-fm-input"
|
|
242
|
+
:placeholder="isStreaming ? 'answering...' : `Ask ${label}`"
|
|
243
|
+
:disabled="isStreaming"
|
|
244
|
+
rows="1"
|
|
245
|
+
@keydown="handleFmKeyDown"
|
|
246
|
+
/>
|
|
247
|
+
<button
|
|
248
|
+
v-if="isStreaming"
|
|
249
|
+
class="fd-ai-fm-send-btn"
|
|
250
|
+
type="button"
|
|
251
|
+
aria-label="Stop"
|
|
252
|
+
@click="isStreaming = false"
|
|
253
|
+
>
|
|
254
|
+
<span class="fd-ai-loading-dots">
|
|
255
|
+
<span class="fd-ai-loading-dot" />
|
|
256
|
+
<span class="fd-ai-loading-dot" />
|
|
257
|
+
<span class="fd-ai-loading-dot" />
|
|
258
|
+
</span>
|
|
259
|
+
</button>
|
|
260
|
+
<button
|
|
261
|
+
v-else
|
|
262
|
+
class="fd-ai-fm-send-btn"
|
|
263
|
+
type="button"
|
|
264
|
+
:data-active="canSend"
|
|
265
|
+
:disabled="!canSend"
|
|
266
|
+
aria-label="Send"
|
|
267
|
+
@click="submitQuestion(aiInput)"
|
|
268
|
+
>
|
|
269
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
270
|
+
<path d="m5 12 7-7 7 7" /><path d="M12 19V5" />
|
|
271
|
+
</svg>
|
|
272
|
+
</button>
|
|
273
|
+
</div>
|
|
274
|
+
|
|
275
|
+
<div v-if="showSuggestions && suggestedQuestions.length > 0" class="fd-ai-fm-suggestions-area">
|
|
276
|
+
<div class="fd-ai-fm-suggestions-label">Try asking:</div>
|
|
277
|
+
<div class="fd-ai-fm-suggestions">
|
|
278
|
+
<button
|
|
279
|
+
v-for="q in suggestedQuestions"
|
|
280
|
+
:key="q"
|
|
281
|
+
type="button"
|
|
282
|
+
class="fd-ai-fm-suggestion"
|
|
283
|
+
@click="submitQuestion(q)"
|
|
284
|
+
>
|
|
285
|
+
{{ q }}
|
|
286
|
+
</button>
|
|
287
|
+
</div>
|
|
288
|
+
</div>
|
|
289
|
+
|
|
290
|
+
<div class="fd-ai-fm-footer-bar">
|
|
291
|
+
<button
|
|
292
|
+
v-if="messages.length > 0"
|
|
293
|
+
class="fd-ai-fm-clear-btn"
|
|
294
|
+
type="button"
|
|
295
|
+
:aria-disabled="isStreaming"
|
|
296
|
+
@click="clearChat"
|
|
297
|
+
>
|
|
298
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
299
|
+
<path d="M3 6h18" /><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" /><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2" />
|
|
300
|
+
</svg>
|
|
301
|
+
<span>Clear</span>
|
|
302
|
+
</button>
|
|
303
|
+
<div v-else class="fd-ai-fm-footer-hint">
|
|
304
|
+
AI can be inaccurate, please verify the information.
|
|
305
|
+
</div>
|
|
306
|
+
</div>
|
|
307
|
+
</div>
|
|
308
|
+
</div>
|
|
309
|
+
</Teleport>
|
|
310
|
+
|
|
311
|
+
<!-- ═══ PANEL/MODAL/POPOVER: backdrop (only for modal style when open) ═══ -->
|
|
312
|
+
<Teleport to="body" v-if="mounted && !isFullModal && isOpen && isModal">
|
|
313
|
+
<div class="fd-ai-overlay" @click="isOpen = false" />
|
|
314
|
+
</Teleport>
|
|
315
|
+
|
|
316
|
+
<!-- ═══ PANEL/MODAL/POPOVER: dialog (only when NOT full-modal AND open) ═══ -->
|
|
317
|
+
<Teleport to="body" v-if="mounted && !isFullModal && isOpen">
|
|
318
|
+
<div
|
|
319
|
+
class="fd-ai-dialog"
|
|
320
|
+
:style="`${containerStyle};animation:${animation}`"
|
|
321
|
+
@click.stop
|
|
322
|
+
@keydown="handleKeydown"
|
|
323
|
+
>
|
|
324
|
+
<div class="fd-ai-header">
|
|
325
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
326
|
+
<path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" />
|
|
327
|
+
</svg>
|
|
328
|
+
<span class="fd-ai-header-title">Ask {{ label }}</span>
|
|
329
|
+
<button type="button" class="fd-ai-close-btn" aria-label="Close" @click="isOpen = false">
|
|
330
|
+
<kbd class="fd-ai-esc">ESC</kbd>
|
|
331
|
+
</button>
|
|
332
|
+
</div>
|
|
333
|
+
|
|
334
|
+
<div class="fd-ai-messages">
|
|
335
|
+
<template v-if="messages.length === 0 && !isStreaming">
|
|
336
|
+
<div class="fd-ai-empty">
|
|
337
|
+
<div class="fd-ai-empty-title">Ask anything about the docs</div>
|
|
338
|
+
<div class="fd-ai-empty-desc">Get instant answers from the documentation.</div>
|
|
339
|
+
<div v-if="suggestedQuestions.length > 0" class="fd-ai-suggestions">
|
|
340
|
+
<button
|
|
341
|
+
v-for="q in suggestedQuestions"
|
|
342
|
+
:key="q"
|
|
343
|
+
type="button"
|
|
344
|
+
class="fd-ai-suggestion"
|
|
345
|
+
@click="submitQuestion(q)"
|
|
346
|
+
>
|
|
347
|
+
{{ q }}
|
|
348
|
+
</button>
|
|
349
|
+
</div>
|
|
350
|
+
</div>
|
|
351
|
+
</template>
|
|
352
|
+
<template v-for="(msg, i) in messages" :key="i">
|
|
353
|
+
<div class="fd-ai-msg" :data-role="msg.role">
|
|
354
|
+
<div class="fd-ai-msg-label">
|
|
355
|
+
{{ msg.role === "user" ? "You" : label }}
|
|
356
|
+
</div>
|
|
357
|
+
<div v-if="msg.role === 'user'" class="fd-ai-bubble-user">{{ msg.content }}</div>
|
|
358
|
+
<div v-else class="fd-ai-bubble-ai">
|
|
359
|
+
<template v-if="msg.content">
|
|
360
|
+
<div v-html="renderMarkdown(msg.content)" />
|
|
361
|
+
</template>
|
|
362
|
+
<span v-else class="fd-ai-loading">
|
|
363
|
+
<span class="fd-ai-loading-text">{{ label }} is thinking</span>
|
|
364
|
+
<span class="fd-ai-loading-dots">
|
|
365
|
+
<span class="fd-ai-loading-dot" />
|
|
366
|
+
<span class="fd-ai-loading-dot" />
|
|
367
|
+
<span class="fd-ai-loading-dot" />
|
|
368
|
+
</span>
|
|
369
|
+
</span>
|
|
370
|
+
</div>
|
|
371
|
+
</div>
|
|
372
|
+
</template>
|
|
373
|
+
<div ref="messagesEndEl" />
|
|
374
|
+
</div>
|
|
375
|
+
|
|
376
|
+
<div class="fd-ai-chat-footer">
|
|
377
|
+
<div class="fd-ai-input-wrap">
|
|
378
|
+
<input
|
|
379
|
+
v-model="aiInput"
|
|
380
|
+
type="text"
|
|
381
|
+
class="fd-ai-input"
|
|
382
|
+
:placeholder="isStreaming ? `${label} is answering...` : `Ask ${label}...`"
|
|
383
|
+
:disabled="isStreaming"
|
|
384
|
+
@keydown.enter.prevent="submitQuestion(aiInput)"
|
|
385
|
+
/>
|
|
386
|
+
<button
|
|
387
|
+
type="button"
|
|
388
|
+
class="fd-ai-send-btn"
|
|
389
|
+
:data-active="canSend"
|
|
390
|
+
:disabled="!canSend"
|
|
391
|
+
aria-label="Send"
|
|
392
|
+
@click="submitQuestion(aiInput)"
|
|
393
|
+
>
|
|
394
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
395
|
+
<path d="m5 12 7-7 7 7" /><path d="M12 19V5" />
|
|
396
|
+
</svg>
|
|
397
|
+
</button>
|
|
398
|
+
</div>
|
|
399
|
+
<button
|
|
400
|
+
v-if="messages.length > 0 && !isStreaming"
|
|
401
|
+
type="button"
|
|
402
|
+
class="fd-ai-clear-btn"
|
|
403
|
+
@click="clearChat"
|
|
404
|
+
>
|
|
405
|
+
Clear conversation
|
|
406
|
+
</button>
|
|
407
|
+
</div>
|
|
408
|
+
</div>
|
|
409
|
+
</Teleport>
|
|
410
|
+
|
|
411
|
+
<!-- ═══ PANEL/MODAL/POPOVER: icon trigger (only when NOT full-modal AND NOT open) ═══ -->
|
|
412
|
+
<Teleport to="body" v-if="mounted && !isFullModal && !isOpen">
|
|
413
|
+
<div
|
|
414
|
+
v-if="triggerComponent"
|
|
415
|
+
class="fd-ai-floating-trigger"
|
|
416
|
+
:style="btnStyle"
|
|
417
|
+
@click="isOpen = true"
|
|
418
|
+
>
|
|
419
|
+
<component :is="triggerComponent" />
|
|
420
|
+
</div>
|
|
421
|
+
<button
|
|
422
|
+
v-else
|
|
423
|
+
type="button"
|
|
424
|
+
class="fd-ai-floating-btn"
|
|
425
|
+
:style="btnStyle"
|
|
426
|
+
:aria-label="`Ask ${label}`"
|
|
427
|
+
@click="isOpen = true"
|
|
428
|
+
>
|
|
429
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
430
|
+
<path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" />
|
|
431
|
+
<path d="M20 3v4" /><path d="M22 5h-4" />
|
|
432
|
+
</svg>
|
|
433
|
+
<span>Ask {{ label }}</span>
|
|
434
|
+
</button>
|
|
435
|
+
</Teleport>
|
|
436
|
+
</template>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, watch, onMounted } from "vue";
|
|
3
|
+
|
|
4
|
+
const emit = defineEmits<{ (e: "close"): void }>();
|
|
5
|
+
|
|
6
|
+
const query = ref("");
|
|
7
|
+
const results = ref<{ content: string; url?: string; description?: string }[]>([]);
|
|
8
|
+
const loading = ref(false);
|
|
9
|
+
const inputEl = ref<HTMLInputElement | null>(null);
|
|
10
|
+
|
|
11
|
+
let debounceTimer: ReturnType<typeof setTimeout>;
|
|
12
|
+
|
|
13
|
+
watch(query, (q) => {
|
|
14
|
+
clearTimeout(debounceTimer);
|
|
15
|
+
if (!q.trim()) {
|
|
16
|
+
results.value = [];
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
loading.value = true;
|
|
20
|
+
debounceTimer = setTimeout(async () => {
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch(`/api/docs?query=${encodeURIComponent(q)}`);
|
|
23
|
+
if (res.ok) {
|
|
24
|
+
const data = await res.json();
|
|
25
|
+
results.value = data ?? [];
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
results.value = [];
|
|
29
|
+
} finally {
|
|
30
|
+
loading.value = false;
|
|
31
|
+
}
|
|
32
|
+
}, 200);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
onMounted(() => {
|
|
36
|
+
inputEl.value?.focus();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function navigate(url: string) {
|
|
40
|
+
emit("close");
|
|
41
|
+
if (typeof navigateTo === "function") {
|
|
42
|
+
navigateTo(url);
|
|
43
|
+
} else {
|
|
44
|
+
window.location.href = url;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
49
|
+
if (e.key === "Escape") emit("close");
|
|
50
|
+
}
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<template>
|
|
54
|
+
<div
|
|
55
|
+
class="fd-search-overlay"
|
|
56
|
+
role="dialog"
|
|
57
|
+
@click.self="emit('close')"
|
|
58
|
+
@keydown="handleKeydown"
|
|
59
|
+
>
|
|
60
|
+
<div class="fd-search-dialog" role="document" @click.stop>
|
|
61
|
+
<div class="fd-search-input-wrap">
|
|
62
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
63
|
+
<circle cx="11" cy="11" r="8" />
|
|
64
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
65
|
+
</svg>
|
|
66
|
+
<input
|
|
67
|
+
ref="inputEl"
|
|
68
|
+
v-model="query"
|
|
69
|
+
class="fd-search-input"
|
|
70
|
+
placeholder="Search documentation..."
|
|
71
|
+
type="text"
|
|
72
|
+
/>
|
|
73
|
+
<kbd class="fd-search-kbd">ESC</kbd>
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<div class="fd-search-results">
|
|
77
|
+
<div v-if="loading" class="fd-search-empty">Searching...</div>
|
|
78
|
+
<div v-else-if="query && results.length === 0" class="fd-search-empty">
|
|
79
|
+
No results found for "{{ query }}"
|
|
80
|
+
</div>
|
|
81
|
+
<button
|
|
82
|
+
v-for="result in results"
|
|
83
|
+
v-else
|
|
84
|
+
:key="result.url ?? result.content"
|
|
85
|
+
class="fd-search-result"
|
|
86
|
+
@click="result.url && navigate(result.url)"
|
|
87
|
+
>
|
|
88
|
+
<span class="fd-search-result-title">{{ result.content }}</span>
|
|
89
|
+
<span v-if="result.url" class="fd-search-result-url">{{ result.url }}</span>
|
|
90
|
+
</button>
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
</template>
|