@vercel/geistdocs 1.25.1-canary.bd8995b → 1.25.1-canary.e20ff18
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/cli/index.js +1 -1
- package/dist/components/blockquote.d.ts +3 -0
- package/dist/components/blockquote.d.ts.map +1 -0
- package/dist/components/blockquote.js +3 -0
- package/dist/components/callout.d.ts +13 -10
- package/dist/components/callout.d.ts.map +1 -1
- package/dist/components/callout.js +6 -6
- package/dist/components/code-block-tabs.d.ts.map +1 -1
- package/dist/components/code-block-tabs.js +3 -1
- package/dist/components/code-block.d.ts.map +1 -1
- package/dist/components/code-block.js +1 -1
- package/dist/components/command-prompt.d.ts.map +1 -1
- package/dist/components/command-prompt.js +15 -22
- package/dist/components/copy-prompt.d.ts +2 -1
- package/dist/components/copy-prompt.d.ts.map +1 -1
- package/dist/components/copy-prompt.js +2 -2
- package/dist/components/heading.d.ts +7 -0
- package/dist/components/heading.d.ts.map +1 -0
- package/dist/components/heading.js +14 -0
- package/dist/components/table.d.ts +3 -0
- package/dist/components/table.d.ts.map +1 -0
- package/dist/components/table.js +3 -0
- package/dist/controls.d.ts.map +1 -1
- package/dist/controls.js +4 -3
- package/dist/internal/chat/activity.d.ts +20 -0
- package/dist/internal/chat/activity.d.ts.map +1 -0
- package/dist/internal/chat/activity.js +43 -0
- package/dist/internal/chat/context.d.ts +2 -0
- package/dist/internal/chat/context.d.ts.map +1 -1
- package/dist/internal/chat/context.js +24 -3
- package/dist/internal/chat/dots-spinner.d.ts.map +1 -1
- package/dist/internal/chat/dots-spinner.js +15 -9
- package/dist/internal/chat/loading-skeleton.d.ts +7 -0
- package/dist/internal/chat/loading-skeleton.d.ts.map +1 -0
- package/dist/internal/chat/loading-skeleton.js +46 -0
- package/dist/internal/chat/message-metadata.d.ts.map +1 -1
- package/dist/internal/chat/message-metadata.js +15 -30
- package/dist/internal/chat/message-sources.d.ts +3 -0
- package/dist/internal/chat/message-sources.d.ts.map +1 -0
- package/dist/internal/chat/message-sources.js +23 -0
- package/dist/internal/chat/message.d.ts.map +1 -1
- package/dist/internal/chat/message.js +57 -5
- package/dist/internal/chat/shell.d.ts.map +1 -1
- package/dist/internal/chat/shell.js +17 -17
- package/dist/internal/chat/source-chunks.d.ts +9 -0
- package/dist/internal/chat/source-chunks.d.ts.map +1 -0
- package/dist/internal/chat/source-chunks.js +7 -0
- package/dist/internal/chat/sources.d.ts.map +1 -1
- package/dist/internal/chat/sources.js +4 -1
- package/dist/internal/mousedown-navigation-utils.d.ts +5 -0
- package/dist/internal/mousedown-navigation-utils.d.ts.map +1 -0
- package/dist/internal/mousedown-navigation-utils.js +95 -0
- package/dist/internal/mousedown-navigation.d.ts +10 -0
- package/dist/internal/mousedown-navigation.d.ts.map +1 -0
- package/dist/internal/mousedown-navigation.js +42 -0
- package/dist/internal/navbar/desktop-menu.js +1 -1
- package/dist/internal/navbar/mobile-menu.d.ts.map +1 -1
- package/dist/internal/navbar/mobile-menu.js +8 -13
- package/dist/internal/navbar/navbar-shell.d.ts.map +1 -1
- package/dist/internal/navbar/navbar-shell.js +2 -1
- package/dist/internal/page-actions-client.d.ts.map +1 -1
- package/dist/internal/page-actions-client.js +36 -32
- package/dist/internal/provider-client.d.ts.map +1 -1
- package/dist/internal/provider-client.js +29 -5
- package/dist/internal/search.d.ts.map +1 -1
- package/dist/internal/search.js +1 -1
- package/dist/internal/sidebar-responsive.d.ts +0 -1
- package/dist/internal/sidebar-responsive.d.ts.map +1 -1
- package/dist/internal/sidebar-responsive.js +0 -9
- package/dist/internal/sidebar-tree.d.ts.map +1 -1
- package/dist/internal/sidebar-tree.js +6 -1
- package/dist/internal/sidebar.d.ts.map +1 -1
- package/dist/internal/sidebar.js +78 -49
- package/dist/internal/table-of-contents.d.ts.map +1 -1
- package/dist/internal/table-of-contents.js +1 -1
- package/dist/internal/toc-items.d.ts.map +1 -1
- package/dist/internal/toc-items.js +16 -6
- package/dist/internal/ui/dropdown-menu.js +6 -6
- package/dist/internal/ui/navigation-menu.js +2 -2
- package/dist/internal/use-mobile.d.ts.map +1 -1
- package/dist/internal/use-mobile.js +2 -12
- package/dist/layout.d.ts +1 -0
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +2 -0
- package/dist/mdx.d.ts.map +1 -1
- package/dist/mdx.js +13 -1
- package/dist/pages/docs.d.ts.map +1 -1
- package/dist/pages/docs.js +11 -3
- package/dist/routes/chat.d.ts +1 -1
- package/dist/routes/chat.d.ts.map +1 -1
- package/dist/routes/chat.js +31 -14
- package/dist/versions.js +2 -2
- package/docs/agents.md +4 -3
- package/docs/llms.txt +316 -32
- package/docs/manifest.json +12 -3
- package/docs/pages/ask-ai.md +2 -2
- package/docs/pages/deployment.md +30 -5
- package/docs/pages/getting-started.md +38 -12
- package/docs/pages/guides/nested-navigation.md +1 -1
- package/docs/pages/md.md +1 -1
- package/docs/pages/migration-2.md +106 -0
- package/docs/pages/migration.md +5 -2
- package/docs/pages/syntax.md +125 -6
- package/docs/sitemap.md +3 -2
- package/package.json +3 -3
- package/template/app/[lang]/layout.tsx +4 -0
- package/template/app/styles/geistdocs.css +1 -1
- package/template/components/ui/button.tsx +1 -1
- package/template/content/docs/ask-ai.cn.mdx +2 -2
- package/template/content/docs/ask-ai.mdx +2 -2
- package/template/content/docs/deployment.mdx +31 -6
- package/template/content/docs/getting-started.mdx +39 -13
- package/template/content/docs/guides/nested-navigation.mdx +1 -1
- package/template/content/docs/md.mdx +1 -1
- package/template/content/docs/meta.json +1 -0
- package/template/content/docs/migration-2.mdx +106 -0
- package/template/content/docs/migration.mdx +5 -1
- package/template/content/docs/syntax.mdx +131 -6
- package/template/package.json +2 -2
- package/theme.css +39 -101
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loading-skeleton.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/loading-skeleton.tsx"],"names":[],"mappings":"AAsCA,eAAO,MAAM,wBAAwB,+CAyCpC,CAAC;AAEF,eAAO,MAAM,iBAAiB,+CAsB7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,sBAGjC;IACD,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,4CAmBA,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Skeleton } from "@vercel/geistcn/components/skeleton";
|
|
4
|
+
import { cn } from "@vercel/geistcn/utils";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
const getMessageCount = async (title) => {
|
|
7
|
+
const name = title.replaceAll(" ", "").toLowerCase();
|
|
8
|
+
if ("databases" in indexedDB) {
|
|
9
|
+
const databases = await indexedDB.databases();
|
|
10
|
+
if (!databases.some((database) => database.name === name)) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
const request = indexedDB.open(name);
|
|
16
|
+
request.onerror = () => resolve(0);
|
|
17
|
+
request.onupgradeneeded = () => {
|
|
18
|
+
request.transaction?.abort();
|
|
19
|
+
resolve(0);
|
|
20
|
+
};
|
|
21
|
+
request.onsuccess = () => {
|
|
22
|
+
const database = request.result;
|
|
23
|
+
if (!database.objectStoreNames.contains("messages")) {
|
|
24
|
+
database.close();
|
|
25
|
+
resolve(0);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const transaction = database.transaction("messages", "readonly");
|
|
29
|
+
const count = transaction.objectStore("messages").count();
|
|
30
|
+
count.onerror = () => resolve(0);
|
|
31
|
+
count.onsuccess = () => resolve(count.result);
|
|
32
|
+
transaction.oncomplete = () => database.close();
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const ChatConversationSkeleton = () => (_jsxs("div", { className: "relative flex flex-1 flex-col justify-start gap-7 overflow-hidden px-4 pt-12 pb-4", children: [_jsxs("div", { className: "relative mr-2 ml-auto w-[260px]", children: [_jsx("div", { className: "relative min-h-10 animate-pulse rounded-[10px] bg-gray-200" }), _jsx("svg", { "aria-hidden": "true", className: "absolute right-[2.5px] -bottom-[0.5px] z-10 translate-x-1/2 fill-gray-200/80", height: "14", viewBox: "0 0 18 14", width: "18", children: _jsx("path", { d: "M0.866025 8.80383L11.2583 0.803833C11.2583 0.803833 12.0621 9.5 17.2583 13.1961C12.0621 13.1961 0.866025 8.80383 0.866025 8.80383Z" }) })] }), _jsx(Skeleton, { height: 25, width: "20%" }), _jsxs("div", { className: "flex shrink-0 flex-col gap-4", children: [_jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "66%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "75%" })] }), _jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "50%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "83%" }), _jsx(Skeleton, { height: 20, width: "66%" })] }), _jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "75%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "50%" })] }), _jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "66%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "75%" }), _jsx(Skeleton, { height: 20, width: "33%" })] })] }), _jsx("div", { className: "absolute inset-x-0 bottom-0 h-52 bg-gradient-to-t from-background-100 via-background-100 to-transparent" })] }));
|
|
37
|
+
export const ChatEmptySkeleton = () => (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "flex h-16 shrink-0 items-center justify-between px-3.5 py-2", children: [_jsx(Skeleton, { height: 20, width: 56 }), _jsx("div", { className: "flex items-center gap-1", children: [0, 1, 2, 3].map((item) => (_jsx(Skeleton, { height: 32, rounded: true, width: 32 }, item))) })] }), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col justify-end", children: [_jsxs("div", { className: "flex flex-col gap-2 px-4 pt-4", children: [[0, 1, 2, 3].map((item) => (_jsx(Skeleton, { block: true, height: 36, width: "100%" }, item))), _jsx(Skeleton, { className: "mt-3 mb-2 ml-2", height: 16, width: "72%" })] }), _jsx("div", { className: "p-4", children: _jsx(Skeleton, { block: true, className: "rounded-[12px]", height: 88, width: "100%" }) })] })] }));
|
|
38
|
+
export const ChatLoadingSkeleton = ({ isMobile, title, }) => {
|
|
39
|
+
const [conversation, setConversation] = useState(false);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
getMessageCount(title).then((count) => setConversation(count > 0));
|
|
42
|
+
}, [title]);
|
|
43
|
+
return (_jsx("div", { className: cn("fixed z-45 flex flex-col bg-background-100", isMobile
|
|
44
|
+
? "inset-x-0 bottom-0 h-[80dvh] rounded-t-xl"
|
|
45
|
+
: "inset-y-0 right-0 w-[400px] border-l"), children: conversation ? _jsx(ChatConversationSkeleton, {}) : _jsx(ChatEmptySkeleton, {}) }));
|
|
46
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-metadata.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message-metadata.tsx"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"message-metadata.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message-metadata.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,IAAI,CAAC;AAMlD,UAAU,oBAAoB;IAC5B,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;CAC3B;AAQD,eAAO,MAAM,eAAe,GAAI,wBAG7B,oBAAoB,mDA0DtB,CAAC"}
|
|
@@ -1,44 +1,29 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { IconBookmark, IconChevronDown } from "@vercel/geistcn-assets/icons";
|
|
4
|
-
import {
|
|
4
|
+
import { isToolUIPart } from "ai";
|
|
5
|
+
import { getMessageActivity } from "./activity";
|
|
5
6
|
import { DotsSpinner } from "./dots-spinner";
|
|
7
|
+
import { getMessageSources } from "./message-sources";
|
|
6
8
|
import { Source, Sources, SourcesContent, SourcesTrigger } from "./sources";
|
|
7
|
-
const WORD_SEPARATOR_PATTERN = /[_-]+/g;
|
|
8
9
|
const LoadingContainer = ({ children }) => (_jsx("div", { className: "h-12 animate-pulse pt-2 text-gray-900 text-sm", children: children }));
|
|
9
|
-
const getToolActivityLabel = (part) => {
|
|
10
|
-
const name = getToolName(part).replace(WORD_SEPARATOR_PATTERN, " ").trim();
|
|
11
|
-
return name ? `Running ${name}...` : "Working...";
|
|
12
|
-
};
|
|
13
10
|
export const MessageMetadata = ({ parts, inProgress, }) => {
|
|
11
|
+
const activity = getMessageActivity({ inProgress, parts });
|
|
12
|
+
if (activity) {
|
|
13
|
+
return (_jsxs(LoadingContainer, { children: [_jsx(DotsSpinner, {}), " ", activity.label] }));
|
|
14
|
+
}
|
|
14
15
|
const lastPart = parts
|
|
15
|
-
.filter((part) => part.type === "text" ||
|
|
16
|
+
.filter((part) => part.type === "text" || isToolUIPart(part))
|
|
16
17
|
.at(-1);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (lastPart.type === "reasoning" &&
|
|
21
|
-
lastPart.state !== "done" &&
|
|
22
|
-
inProgress) {
|
|
23
|
-
return (_jsxs(LoadingContainer, { children: [_jsx(DotsSpinner, {}), " Thinking..."] }));
|
|
24
|
-
}
|
|
25
|
-
const tool = isToolUIPart(lastPart) ? lastPart : null;
|
|
26
|
-
const hasTextPart = parts.some((part) => part.type === "text");
|
|
27
|
-
const sources = Array.from(new Map(parts
|
|
28
|
-
.filter((part) => part.type === "source-url")
|
|
29
|
-
.map((part) => [part.url, part])).values());
|
|
30
|
-
if (sources.length > 0 && !hasTextPart && inProgress) {
|
|
31
|
-
return (_jsxs(LoadingContainer, { children: [_jsx(DotsSpinner, {}), " Searching..."] }));
|
|
32
|
-
}
|
|
33
|
-
if (tool &&
|
|
34
|
-
inProgress &&
|
|
35
|
-
(tool.state === "input-streaming" || tool.state === "input-available")) {
|
|
36
|
-
return (_jsxs(LoadingContainer, { children: [_jsx(DotsSpinner, {}), " ", getToolActivityLabel(tool)] }));
|
|
37
|
-
}
|
|
38
|
-
if (sources.length > 0 && !(tool && inProgress)) {
|
|
18
|
+
const tool = lastPart && isToolUIPart(lastPart) ? lastPart : null;
|
|
19
|
+
const sources = getMessageSources(parts);
|
|
20
|
+
if (sources.length > 0) {
|
|
39
21
|
return (_jsxs(Sources, { className: "mb-4", children: [_jsxs(SourcesTrigger, { className: "w-full max-w-fit cursor-pointer justify-between gap-2 py-1 pr-3 pl-0 text-left", count: sources.length, children: [_jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx(IconBookmark, { className: "size-4", color: "gray-900" }), _jsxs("p", { className: "text-gray-900 text-xs", children: ["Used ", sources.length, " source", sources.length === 1 ? "" : "s"] })] }), _jsx(IconChevronDown, { className: "size-4 transition-transform duration-200 group-data-[state=open]:rotate-180", color: "gray-900" })] }), _jsx(SourcesContent, { children: _jsx("ul", { className: "mt-1.5 list-disc pl-4", children: sources.map((source) => (_jsx("li", { className: "my-1.5", children: _jsx(Source, { href: source.url, title: source.title }) }, source.url))) }) })] }));
|
|
40
22
|
}
|
|
41
|
-
if (!tool
|
|
23
|
+
if (!tool) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (tool.state === "output-available") {
|
|
42
27
|
return null;
|
|
43
28
|
}
|
|
44
29
|
return _jsx("div", { className: "h-12" });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-sources.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message-sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,IAAI,CAAC;AAgBxE,eAAO,MAAM,iBAAiB,GAC5B,OAAO,SAAS,CAAC,OAAO,CAAC,KACxB,eAAe,EAuBf,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isToolUIPart } from "ai";
|
|
2
|
+
const isToolSource = (value) => typeof value === "object" &&
|
|
3
|
+
value !== null &&
|
|
4
|
+
"documentUri" in value &&
|
|
5
|
+
typeof value.documentUri === "string" &&
|
|
6
|
+
"documentTitle" in value &&
|
|
7
|
+
typeof value.documentTitle === "string";
|
|
8
|
+
export const getMessageSources = (parts) => Array.from(new Map([
|
|
9
|
+
...parts.filter((part) => part.type === "source-url"),
|
|
10
|
+
...parts
|
|
11
|
+
.filter((part) => isToolUIPart(part) && part.state === "output-available")
|
|
12
|
+
.flatMap((part) => {
|
|
13
|
+
if (!Array.isArray(part.output)) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
return part.output.filter(isToolSource).map((source, index) => ({
|
|
17
|
+
type: "source-url",
|
|
18
|
+
sourceId: `tool-${part.toolCallId}-${source.chunkIndex ?? index}-${source.documentUri}`,
|
|
19
|
+
url: source.documentUri,
|
|
20
|
+
title: source.documentTitle,
|
|
21
|
+
}));
|
|
22
|
+
}),
|
|
23
|
+
].map((source) => [source.url, source])).values());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAEL,UAAU,EAEX,MAAM,YAAY,CAAC;AAoLpB,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG;IAC1D,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;CAChD,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,+BAA+B,YAAY,4CASlE,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;AAEjE,eAAO,MAAM,cAAc,GAAI,mCAI5B,mBAAmB,4CAqBrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,OAAO,UAAU,CAAC,CAAC;AAErE,eAAO,MAAM,eAAe,gEACA,oBAAoB,6CAa/C,CAAC"}
|
|
@@ -1,11 +1,63 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { cjk } from "@streamdown/cjk";
|
|
4
|
-
import {
|
|
4
|
+
import { CodeBlock } from "@vercel/geistcn/components/code-block";
|
|
5
|
+
import { Modal, ModalAction, ModalActions, ModalBody, ModalHeader, ModalSubtitle, ModalTitle, } from "@vercel/geistcn/components/modal";
|
|
5
6
|
import { cn } from "@vercel/geistcn/utils";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import { IconArrowUpRightSmall } from "@vercel/geistcn-assets/icons";
|
|
8
|
+
import { memo, useState } from "react";
|
|
9
|
+
import { Streamdown, } from "streamdown";
|
|
10
|
+
const CODE_LANGUAGE_PATTERN = /language-([\w-]+)/;
|
|
11
|
+
const FILENAME_PATTERN = /filename="([^"]+)"/;
|
|
12
|
+
const LinkSafetyModal = ({ isOpen, onClose, onConfirm, url, }) => {
|
|
13
|
+
return (_jsxs(Modal, { active: isOpen, drawer: false, onClickOutside: onClose, style: {
|
|
14
|
+
background: "var(--ds-background-200)",
|
|
15
|
+
boxShadow: "var(--ds-shadow-modal)",
|
|
16
|
+
}, width: 448, children: [_jsxs(ModalBody, { className: "bg-background-200", padding: 24, children: [_jsxs(ModalHeader, { children: [_jsx(ModalTitle, { children: "Open external link?" }), _jsx(ModalSubtitle, { children: "You\u2019re about to visit an external website." })] }), _jsx("div", { className: "break-all rounded-md bg-gray-100 p-3 font-mono text-copy-13", children: url })] }), _jsxs(ModalActions, { children: [_jsx(ModalAction, { onClick: onClose, variant: "secondary", children: "Cancel" }), _jsx(ModalAction, { onClick: onConfirm, children: "Open link" })] })] }));
|
|
17
|
+
};
|
|
18
|
+
const ChatLink = ({ children, className, href, node: _node, ...props }) => {
|
|
19
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
20
|
+
const external = typeof href === "string" &&
|
|
21
|
+
(href.startsWith("http://") || href.startsWith("https://"));
|
|
22
|
+
if (!external) {
|
|
23
|
+
return (_jsx("a", { className: cn("font-normal text-gray-1000! underline decoration-1 decoration-gray-700 underline-offset-4 hover:text-gray-1000! hover:decoration-gray-1000 hover:opacity-100!", className), href: href, ...props, children: children }));
|
|
24
|
+
}
|
|
25
|
+
return (_jsxs(_Fragment, { children: [_jsxs("button", { className: cn("group wrap-anywhere cursor-pointer appearance-none text-left font-normal text-gray-1000! no-underline hover:text-gray-1000! hover:opacity-100!", className), onClick: () => setIsOpen(true), type: "button", children: [_jsx("span", { className: "underline decoration-1 decoration-gray-700 underline-offset-4 group-hover:decoration-gray-1000", children: children }), _jsxs("span", { className: "whitespace-nowrap", children: ["\u00a0", _jsx("span", { className: "inline-flex -translate-y-1 align-text-bottom", children: _jsx(IconArrowUpRightSmall, { size: 16 }) })] })] }), _jsx(LinkSafetyModal, { isOpen: isOpen, onClose: () => setIsOpen(false), onConfirm: () => {
|
|
26
|
+
window.open(href, "_blank", "noreferrer");
|
|
27
|
+
setIsOpen(false);
|
|
28
|
+
}, url: href })] }));
|
|
29
|
+
};
|
|
30
|
+
const CHAT_RESPONSE_COMPONENTS = {
|
|
31
|
+
a: ChatLink,
|
|
32
|
+
code: ({ children, className, node, ...props }) => {
|
|
33
|
+
const inline = node?.position?.start.line === node?.position?.end.line;
|
|
34
|
+
if (inline) {
|
|
35
|
+
return (_jsx("code", { className: cn("rounded bg-gray-100 px-1 py-0.5 font-mono text-sm", className), ...props, children: children }));
|
|
36
|
+
}
|
|
37
|
+
const codeContent = Array.isArray(children)
|
|
38
|
+
? children.join("")
|
|
39
|
+
: String(children);
|
|
40
|
+
const language = CODE_LANGUAGE_PATTERN.exec(className ?? "")?.[1] ?? "text";
|
|
41
|
+
const meta = node?.data?.meta;
|
|
42
|
+
const filename = typeof meta === "string" ? FILENAME_PATTERN.exec(meta)?.[1] : undefined;
|
|
43
|
+
const cleanedCode = codeContent
|
|
44
|
+
.replaceAll("```$", "")
|
|
45
|
+
.replaceAll("```*", "")
|
|
46
|
+
.replaceAll("```-", "")
|
|
47
|
+
.replaceAll("```_", "")
|
|
48
|
+
.replaceAll("```_$", "")
|
|
49
|
+
.trim();
|
|
50
|
+
return (_jsx(CodeBlock, { className: cn("my-4", className), filename: filename, language: language, children: cleanedCode }));
|
|
51
|
+
},
|
|
52
|
+
h1: ({ children, className, node: _node, ...props }) => (_jsx("h1", { className: cn("font-semibold text-xl", className), ...props, children: children })),
|
|
53
|
+
h2: ({ children, className, node: _node, ...props }) => (_jsx("h2", { className: cn("font-semibold text-xl", className), ...props, children: children })),
|
|
54
|
+
h3: ({ children, className, node: _node, ...props }) => (_jsx("h3", { className: cn("font-semibold text-lg", className), ...props, children: children })),
|
|
55
|
+
h4: ({ children, className, node: _node, ...props }) => (_jsx("h4", { className: cn("font-semibold text-lg", className), ...props, children: children })),
|
|
56
|
+
h5: ({ children, className, node: _node, ...props }) => (_jsx("h5", { className: cn("font-semibold text-base", className), ...props, children: children })),
|
|
57
|
+
h6: ({ children, className, node: _node, ...props }) => (_jsx("h6", { className: cn("font-semibold text-sm", className), ...props, children: children })),
|
|
58
|
+
pre: ({ children, className }) => _jsx("pre", { className: className, children: children }),
|
|
59
|
+
};
|
|
8
60
|
export const Message = ({ className, from, ...props }) => (_jsx("div", { className: cn("group flex w-full flex-col gap-2 py-4 [&>div]:max-w-[80%]", from === "user" ? "is-user items-end" : "is-assistant items-start", className), ...props }));
|
|
9
61
|
export const MessageContent = ({ children, className, ...props }) => (_jsxs("div", { className: cn("relative flex min-h-10 w-fit min-w-0 max-w-full flex-col gap-2 whitespace-normal rounded-[12px] px-4 py-2 text-left text-sm leading-relaxed", "group-[.is-user]:bg-gray-1000 group-[.is-user]:text-white group-[.is-user]:dark:bg-gray-100 group-[.is-user]:dark:text-gray-1000", "group-[.is-assistant]:min-h-0 group-[.is-assistant]:px-0 group-[.is-assistant]:py-0 group-[.is-assistant]:text-gray-1000", className), ...props, children: [_jsx("div", { className: "is-user:dark", children: children }), _jsx("svg", { "aria-hidden": "true", className: "absolute right-[2.5px] -bottom-[0.5px] hidden translate-x-1/2 group-[.is-user]:block group-[.is-user]:fill-gray-1000 group-[.is-user]:dark:fill-gray-100", height: "14", viewBox: "0 0 18 14", width: "18", children: _jsx("path", { d: "M0.866025 8.80383L11.2583 0.803833C11.2583 0.803833 12.0621 9.5 17.2583 13.1961C12.0621 13.1961 0.866025 8.80383 0.866025 8.80383Z" }) })] }));
|
|
10
|
-
export const MessageResponse = memo(({ className, ...props }) => (_jsx(Streamdown, { className: cn("size-full whitespace-normal text-left text-sm leading-relaxed [&>*:first-child]:mt-0 [&>*:last-child]:mb-0", className),
|
|
62
|
+
export const MessageResponse = memo(({ className, ...props }) => (_jsx(Streamdown, { className: cn("size-full whitespace-normal text-left text-sm leading-relaxed [&>*:first-child]:mt-0 [&>*:last-child]:mb-0", className), components: CHAT_RESPONSE_COMPONENTS, linkSafety: { enabled: true, renderModal: LinkSafetyModal }, plugins: { cjk }, ...props })), (prevProps, nextProps) => prevProps.children === nextProps.children);
|
|
11
63
|
MessageResponse.displayName = "MessageResponse";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/shell.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/shell.tsx"],"names":[],"mappings":"AAwYA,eAAO,MAAM,kBAAkB,sDAsD9B,CAAC"}
|
|
@@ -18,6 +18,7 @@ import { Portal } from "radix-ui";
|
|
|
18
18
|
import { useCallback, useEffect, useId, useMemo, useRef, useState, } from "react";
|
|
19
19
|
import { getPublicPath } from "../../config";
|
|
20
20
|
import { useIsMobile } from "../use-mobile";
|
|
21
|
+
import { isActiveAssistantMessage, shouldShowPendingActivity, } from "./activity";
|
|
21
22
|
import { useGeistdocsChat } from "./context";
|
|
22
23
|
import { Conversation, ConversationContent, ConversationScrollButton, } from "./conversation";
|
|
23
24
|
import { CopyChat } from "./copy-chat";
|
|
@@ -175,9 +176,13 @@ const GeistdocsChatInner = ({ isOpen }) => {
|
|
|
175
176
|
if (isLoading) {
|
|
176
177
|
return (_jsx("div", { className: "flex size-full w-full flex-col items-center justify-center overflow-hidden whitespace-nowrap rounded-xl xl:max-w-md xl:border xl:bg-background-100", children: _jsx(Spinner, {}) }));
|
|
177
178
|
}
|
|
178
|
-
return (_jsxs("aside", { "aria-label": "Ask AI chat", className: "flex size-full w-full flex-col overflow-hidden whitespace-nowrap bg-background-100", children: [_jsxs("div", { className: "sticky top-0 z-10 flex h-16 items-center justify-between bg-background-100 py-2 pr-2 pl-3.5", children: [_jsx("h2", { className: "font-semibold text-sm", children: "Ask AI" }), _jsxs("div", { className: "flex items-center gap-0.5", children: [_jsx(CopyChat, { messages: messages }), _jsx(Tooltip, { position: "bottom", text: "Delete chat", children: _jsx(Button, { "aria-label": "Delete chat", className: "text-gray-800! disabled:bg-gray-alpha-100!", disabled: messages.length === 0, onClick: handleClearChat, shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: _jsx(IconTrash, { size: 14 }) }) }), _jsx(Tooltip, { position: "bottom", text: "Close chat", children: _jsx(Button, { "aria-label": "Close chat", className: "text-gray-800! shadow-none", onClick: () => setIsOpen(false), shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: _jsx(IconChevronDoubleRight, { size: 14 }) }) })] })] }), _jsxs(Conversation, { children: [_jsxs(ConversationContent, { children: [messages.map((message) => (_jsxs(Message, { from: message.role, children: [_jsx(MessageMetadata, { inProgress:
|
|
179
|
+
return (_jsxs("aside", { "aria-label": "Ask AI chat", className: "flex size-full w-full flex-col overflow-hidden whitespace-nowrap bg-background-100", children: [_jsxs("div", { className: "sticky top-0 z-10 flex h-16 items-center justify-between bg-background-100 py-2 pr-2 pl-3.5", children: [_jsx("h2", { className: "font-semibold text-sm", children: "Ask AI" }), _jsxs("div", { className: "flex items-center gap-0.5", children: [_jsx(CopyChat, { messages: messages }), _jsx(Tooltip, { position: "bottom", text: "Delete chat", children: _jsx(Button, { "aria-label": "Delete chat", className: "text-gray-800! disabled:bg-gray-alpha-100!", disabled: messages.length === 0, onClick: handleClearChat, shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: _jsx(IconTrash, { size: 14 }) }) }), _jsx(Tooltip, { position: "bottom", text: "Close chat", children: _jsx(Button, { "aria-label": "Close chat", className: "text-gray-800! shadow-none", onClick: () => setIsOpen(false), shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: _jsx(IconChevronDoubleRight, { size: 14 }) }) })] })] }), _jsxs(Conversation, { children: [_jsxs(ConversationContent, { children: [messages.map((message, index) => (_jsxs(Message, { from: message.role, children: [_jsx(MessageMetadata, { inProgress: isActiveAssistantMessage({
|
|
180
|
+
index,
|
|
181
|
+
messages,
|
|
182
|
+
status,
|
|
183
|
+
}), parts: message.parts }), message.parts
|
|
179
184
|
.filter((part) => part.type === "text")
|
|
180
|
-
.map((part) => (_jsx(MessageContent, { children: _jsx(MessageResponse, { className: "text-wrap", children: part.text }) }, `${message.id}-${part.type}-${part.text}`)))] }, message.id))), status
|
|
185
|
+
.map((part) => (_jsx(MessageContent, { children: _jsx(MessageResponse, { className: "text-wrap", children: part.text }) }, `${message.id}-${part.type}-${part.text}`)))] }, message.id))), shouldShowPendingActivity({ messages, status }) ? (_jsx("div", { className: "h-12 animate-pulse pt-2 text-gray-900 text-sm", children: _jsx(DotsSpinner, {}) })) : null] }), _jsx(ConversationScrollButton, {})] }), _jsxs("div", { className: "relative grid w-auto shrink-0 gap-3 whitespace-normal p-4 text-left", children: [messages.length ? null : (_jsxs(_Fragment, { children: [_jsx(Suggestions, { className: "w-full cursor-text", children: suggestions.slice(0, 4).map((text, index) => (_jsx(Suggestion, { className: "w-full", icon: suggestionIcons[index], onClick: handleSuggestionClick, suggestion: text, variant: "tertiary" }, text))) }), _jsxs("p", { className: "mb-3 whitespace-normal px-2 text-left text-gray-900 text-label-14", children: ["Tip: You can open and close chat with", _jsx(Kbd, { className: "material-base ml-1.5 text-gray-900", meta: true, small: true }), _jsx(Kbd, { className: "material-base ml-1 font-mono! text-gray-900", small: true, children: "I" })] })] })), _jsx(ChatPromptInput, { onChange: setPrompt, onStop: stop, onSubmit: (event) => {
|
|
181
186
|
event.preventDefault();
|
|
182
187
|
handleSubmit().catch((error) => {
|
|
183
188
|
console.error("Failed to submit chat message:", error);
|
|
@@ -189,26 +194,21 @@ const GeistdocsChatErrorBoundary = catchError(GeistdocsChatErrorFallback);
|
|
|
189
194
|
export const GeistdocsChatShell = () => {
|
|
190
195
|
const { enabled, isOpen, setIsOpen } = useGeistdocsChat();
|
|
191
196
|
const isMobile = useIsMobile();
|
|
192
|
-
useEffect(() => {
|
|
193
|
-
const handleKeyDown = (event) => {
|
|
194
|
-
if ((event.metaKey || event.ctrlKey) &&
|
|
195
|
-
!event.altKey &&
|
|
196
|
-
!event.shiftKey &&
|
|
197
|
-
event.key.toLowerCase() === "i") {
|
|
198
|
-
event.preventDefault();
|
|
199
|
-
setIsOpen((prev) => !prev);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
203
|
-
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
204
|
-
}, [setIsOpen]);
|
|
205
197
|
if (!enabled) {
|
|
206
198
|
return null;
|
|
207
199
|
}
|
|
208
|
-
return (_jsxs(_Fragment, { children: [
|
|
200
|
+
return (_jsxs(_Fragment, { children: [isOpen ? (_jsx("style", { children: `
|
|
201
|
+
html {
|
|
202
|
+
scrollbar-width: none !important;
|
|
203
|
+
-ms-overflow-style: none !important;
|
|
204
|
+
}
|
|
205
|
+
html::-webkit-scrollbar {
|
|
206
|
+
display: none !important;
|
|
207
|
+
}
|
|
208
|
+
` })) : null, _jsx(Portal.Root, { children: _jsx("div", { className: cn(
|
|
209
209
|
// z-45 keeps the panel above the sticky navbar (z-40) but below
|
|
210
210
|
// modal surfaces like the search command menu, dialogs, and
|
|
211
211
|
// dropdowns (z-50), so opening the command menu paints over an
|
|
212
212
|
// open chat panel.
|
|
213
|
-
"fixed inset-y-0 right-0 z-45
|
|
213
|
+
"fixed inset-y-0 right-0 z-45 hidden h-full w-[400px] max-w-[75vw] flex-col gap-4 border-l bg-background-100 transition-transform min-[768px]:flex", "translate-x-full data-[state=open]:translate-x-0"), "data-state": isOpen ? "open" : "closed", children: _jsx(GeistdocsChatErrorBoundary, { onClose: () => setIsOpen(false), children: _jsx(GeistdocsChatInner, { isOpen: isOpen }) }) }) }), _jsx("div", { className: "min-[768px]:hidden", children: _jsxs(Drawer, { className: "flex flex-col bg-background-100", height: "80dvh", onDismiss: () => setIsOpen(false), show: isMobile && isOpen, children: [_jsx(DrawerTitle, { className: "sr-only", children: "Ask AI" }), _jsx(GeistdocsChatErrorBoundary, { onClose: () => setIsOpen(false), children: _jsx(GeistdocsChatInner, { isOpen: isOpen }) })] }) })] }));
|
|
214
214
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { UIMessageChunk } from "ai";
|
|
2
|
+
export interface CitableDocument {
|
|
3
|
+
slug: string;
|
|
4
|
+
title: string;
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const createSourceChunk: (doc: CitableDocument, index?: number) => UIMessageChunk;
|
|
8
|
+
export declare const createSourceChunks: (docs: CitableDocument[]) => UIMessageChunk[];
|
|
9
|
+
//# sourceMappingURL=source-chunks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-chunks.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/source-chunks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AAEzC,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,iBAAiB,GAC5B,KAAK,eAAe,EACpB,cAAS,KACR,cAKD,CAAC;AAEH,eAAO,MAAM,kBAAkB,GAAI,MAAM,eAAe,EAAE,KAAG,cAAc,EAC9C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/sources.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;AAEjD,eAAO,MAAM,OAAO,GAAI,yBAAyB,YAAY,4CAK5D,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,kBAAkB,CAAC,GAAG;IAC5E,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,0CAK5B,mBAAmB,4CAerB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc,GAAI,yBAG5B,mBAAmB,4CAErB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,eAAO,MAAM,MAAM,GAAI,qCAAqC,WAAW,
|
|
1
|
+
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/sources.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;AAEjD,eAAO,MAAM,OAAO,GAAI,yBAAyB,YAAY,4CAK5D,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,kBAAkB,CAAC,GAAG;IAC5E,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,0CAK5B,mBAAmB,4CAerB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc,GAAI,yBAG5B,mBAAmB,4CAErB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,eAAO,MAAM,MAAM,GAAI,qCAAqC,WAAW,4CAgBtE,CAAC"}
|
|
@@ -6,4 +6,7 @@ import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "../ui/coll
|
|
|
6
6
|
export const Sources = ({ className, ...props }) => (_jsx(Collapsible, { className: cn("not-prose text-gray-600 text-xs", className), ...props }));
|
|
7
7
|
export const SourcesTrigger = ({ className, count, children, ...props }) => (_jsx(CollapsibleTrigger, { className: cn("group flex items-center rounded-md border-none bg-transparent", className), ...props, children: children ?? (_jsxs(_Fragment, { children: [_jsxs("p", { className: "font-medium", children: ["Used ", count, " sources"] }), _jsx(IconChevronDown, { className: "h-4 w-4 transition-transform duration-200 group-data-[state=open]:rotate-180" })] })) }));
|
|
8
8
|
export const SourcesContent = ({ className, ...props }) => (_jsx(CollapsibleContent, { className: cn("flex flex-col", className), ...props }));
|
|
9
|
-
export const Source = ({ href, title, children, ...props }) =>
|
|
9
|
+
export const Source = ({ href, title, children, ...props }) => {
|
|
10
|
+
const external = href.startsWith("http://") || href.startsWith("https://");
|
|
11
|
+
return (_jsx("a", { className: "inline-flex min-w-0 max-w-full items-center underline underline-offset-1", href: href, rel: external ? "noreferrer" : undefined, target: external ? "_blank" : undefined, ...props, children: children ?? (_jsx("span", { className: "truncate font-medium text-gray-1000", children: title })) }));
|
|
12
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PointerEvent as ReactPointerEvent } from "react";
|
|
2
|
+
export declare const getMouseDownRouterHref: (href: string, basePath: string | undefined) => string;
|
|
3
|
+
export declare const findMouseDownNavigationAnchor: (target: EventTarget | null, boundary: EventTarget | null) => HTMLAnchorElement | null;
|
|
4
|
+
export declare const shouldNavigateOnPointerDown: (event: ReactPointerEvent, anchor: HTMLAnchorElement) => boolean;
|
|
5
|
+
//# sourceMappingURL=mousedown-navigation-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mousedown-navigation-utils.d.ts","sourceRoot":"","sources":["../../src/internal/mousedown-navigation-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAwB/D,eAAO,MAAM,sBAAsB,GACjC,MAAM,MAAM,EACZ,UAAU,MAAM,GAAG,SAAS,WAoB7B,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,QAAQ,WAAW,GAAG,IAAI,EAC1B,UAAU,WAAW,GAAG,IAAI,KAC3B,iBAAiB,GAAG,IAWtB,CAAC;AAyBF,eAAO,MAAM,2BAA2B,GACtC,OAAO,iBAAiB,EACxB,QAAQ,iBAAiB,YA0C1B,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const TRAILING_SLASH_PATTERN = /\/$/;
|
|
2
|
+
const normalizeRouterBasePath = (basePath) => {
|
|
3
|
+
if (!basePath || basePath === "/") {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
const normalized = basePath.startsWith("/") ? basePath : `/${basePath}`;
|
|
7
|
+
return normalized.replace(TRAILING_SLASH_PATTERN, "");
|
|
8
|
+
};
|
|
9
|
+
const NESTED_CONTROL_TAGS = new Set([
|
|
10
|
+
"BUTTON",
|
|
11
|
+
"INPUT",
|
|
12
|
+
"LABEL",
|
|
13
|
+
"SELECT",
|
|
14
|
+
"SUMMARY",
|
|
15
|
+
"TEXTAREA",
|
|
16
|
+
]);
|
|
17
|
+
const HANDLED_KEY = "__geistdocsMouseDownNavigationHandled";
|
|
18
|
+
export const getMouseDownRouterHref = (href, basePath) => {
|
|
19
|
+
const normalizedBasePath = normalizeRouterBasePath(basePath);
|
|
20
|
+
if (!normalizedBasePath) {
|
|
21
|
+
return href;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const url = new URL(href, window.location.origin);
|
|
25
|
+
if (url.pathname === normalizedBasePath) {
|
|
26
|
+
return `/${url.search}${url.hash}`;
|
|
27
|
+
}
|
|
28
|
+
if (url.pathname.startsWith(`${normalizedBasePath}/`)) {
|
|
29
|
+
return `${url.pathname.slice(normalizedBasePath.length)}${url.search}${url.hash}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return href;
|
|
34
|
+
}
|
|
35
|
+
return href;
|
|
36
|
+
};
|
|
37
|
+
export const findMouseDownNavigationAnchor = (target, boundary) => {
|
|
38
|
+
let element = target;
|
|
39
|
+
while (element && element !== boundary) {
|
|
40
|
+
if (element.tagName === "A") {
|
|
41
|
+
return element;
|
|
42
|
+
}
|
|
43
|
+
element = element.parentElement;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
47
|
+
const startsOnNestedControl = (target, anchor) => {
|
|
48
|
+
if (anchor.hasAttribute("data-no-mousedown-nav")) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
let element = target;
|
|
52
|
+
while (element && element !== anchor) {
|
|
53
|
+
if (element.hasAttribute("data-no-mousedown-nav") ||
|
|
54
|
+
NESTED_CONTROL_TAGS.has(element.tagName) ||
|
|
55
|
+
element.getAttribute("role") === "button") {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
element = element.parentElement;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
export const shouldNavigateOnPointerDown = (event, anchor) => {
|
|
63
|
+
if (event.defaultPrevented ||
|
|
64
|
+
event.button !== 0 ||
|
|
65
|
+
event.pointerType !== "mouse" ||
|
|
66
|
+
event.altKey ||
|
|
67
|
+
event.ctrlKey ||
|
|
68
|
+
event.metaKey ||
|
|
69
|
+
event.shiftKey ||
|
|
70
|
+
startsOnNestedControl(event.target, anchor)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const nativeEvent = event.nativeEvent;
|
|
74
|
+
if (nativeEvent[HANDLED_KEY] === true) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const target = anchor.getAttribute("target");
|
|
78
|
+
if ((target && target !== "_self") || anchor.hasAttribute("download")) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const href = anchor.getAttribute("href");
|
|
82
|
+
if (!href || href.startsWith("#")) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
if (new URL(href, window.location.origin).origin !== window.location.origin) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
nativeEvent[HANDLED_KEY] = true;
|
|
94
|
+
return true;
|
|
95
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Starts same-origin mouse navigation on pointer down, matching Vercel's
|
|
4
|
+
* marketing navbar behavior. Browser click behavior remains the fallback for
|
|
5
|
+
* keyboard activation, touch, modified clicks, downloads, and external links.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MouseDownNavigation: ({ children }: {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
//# sourceMappingURL=mousedown-navigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mousedown-navigation.d.ts","sourceRoot":"","sources":["../../src/internal/mousedown-navigation.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,SAAS,EAIf,MAAM,OAAO,CAAC;AAQf;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,cAAc;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,4CAkDxE,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRouter } from "next/navigation";
|
|
4
|
+
import { useCallback, useRef, } from "react";
|
|
5
|
+
import { useGeistdocsConfig } from "./config-context";
|
|
6
|
+
import { findMouseDownNavigationAnchor, getMouseDownRouterHref, shouldNavigateOnPointerDown, } from "./mousedown-navigation-utils";
|
|
7
|
+
/**
|
|
8
|
+
* Starts same-origin mouse navigation on pointer down, matching Vercel's
|
|
9
|
+
* marketing navbar behavior. Browser click behavior remains the fallback for
|
|
10
|
+
* keyboard activation, touch, modified clicks, downloads, and external links.
|
|
11
|
+
*/
|
|
12
|
+
export const MouseDownNavigation = ({ children }) => {
|
|
13
|
+
const router = useRouter();
|
|
14
|
+
const { basePath } = useGeistdocsConfig();
|
|
15
|
+
const navigated = useRef(false);
|
|
16
|
+
const onPointerDownCapture = useCallback((event) => {
|
|
17
|
+
// A drag-off has no follow-up click inside this wrapper. Clear stale
|
|
18
|
+
// state at the beginning of every pointer interaction.
|
|
19
|
+
navigated.current = false;
|
|
20
|
+
const anchor = findMouseDownNavigationAnchor(event.target, event.currentTarget);
|
|
21
|
+
if (!(anchor && shouldNavigateOnPointerDown(event, anchor))) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const href = anchor.getAttribute("href");
|
|
25
|
+
if (!href) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
navigated.current = true;
|
|
29
|
+
router.push(getMouseDownRouterHref(href, basePath), {
|
|
30
|
+
scroll: anchor.getAttribute("data-scroll") !== "false",
|
|
31
|
+
});
|
|
32
|
+
}, [basePath, router]);
|
|
33
|
+
const onClickCapture = useCallback((event) => {
|
|
34
|
+
if (navigated.current) {
|
|
35
|
+
// Prevent Next.js/the browser from navigating a second time without
|
|
36
|
+
// stopping propagation, so click handlers and analytics still run.
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
navigated.current = false;
|
|
39
|
+
}
|
|
40
|
+
}, []);
|
|
41
|
+
return (_jsx("div", { onClickCapture: onClickCapture, onPointerDownCapture: onPointerDownCapture, style: { display: "contents" }, children: children }));
|
|
42
|
+
};
|
|
@@ -49,5 +49,5 @@ const DropdownNavItem = ({ first, item, }) => {
|
|
|
49
49
|
export const DesktopMenu = ({ items, className }) => {
|
|
50
50
|
const isActive = useNavActive();
|
|
51
51
|
const [navOpen, setNavOpen] = useState(false);
|
|
52
|
-
return (_jsxs(_Fragment, { children: [_jsx(NavigationMenu, { "aria-label": "Primary navigation", delayDuration: 0, onValueChange: (value) => setNavOpen(Boolean(value)), skipDelayDuration: 0, viewport: false, children: _jsx(NavigationMenuList, { className: cn("h-16 items-stretch gap-0", className), children: items.map((item, index) => "items" in item ? (_jsx(DropdownNavItem, { first: index === 0, item: item }, item.label)) : (_jsx(NavigationMenuItem, { className: "flex", children: _jsx(NavigationMenuLink, { active: isActive(item.href), asChild: true, className: topLevelItemClassName(index === 0), children: item.href.startsWith("http") ? (_jsxs("a", { className: "flex flex-row items-center gap-1", href: item.href, rel: "noopener", target: "_blank", children: [item.label, _jsx(IconArrowUpRightSmall, { "aria-hidden": "true", className: "will-change-transform", size: 12 })] })) : (_jsx(LocalizedLink, { href: item.href, children: item.label })) }) }, item.href))) }) }), _jsx("div", { "aria-hidden": "true", className: cn("pointer-events-none fixed inset-x-0 top-16 bottom-0 z-0 bg-background-200/60", navOpen ? "opacity-100" : "opacity-0") })] }));
|
|
52
|
+
return (_jsxs(_Fragment, { children: [_jsx(NavigationMenu, { "aria-label": "Primary navigation", delayDuration: 0, onValueChange: (value) => setNavOpen(Boolean(value)), skipDelayDuration: 0, viewport: false, children: _jsx(NavigationMenuList, { className: cn("h-16 items-stretch gap-0", className), children: items.map((item, index) => "items" in item ? (_jsx(DropdownNavItem, { first: index === 0, item: item }, item.label)) : (_jsx(NavigationMenuItem, { className: "flex", children: _jsx(NavigationMenuLink, { active: isActive(item.href), asChild: true, className: topLevelItemClassName(index === 0), children: item.href.startsWith("http") ? (_jsxs("a", { className: "flex flex-row items-center gap-1", href: item.href, rel: "noopener", target: "_blank", children: [item.label, _jsx(IconArrowUpRightSmall, { "aria-hidden": "true", className: cn(navOpen && "will-change-transform"), size: 12 })] })) : (_jsx(LocalizedLink, { href: item.href, children: item.label })) }) }, item.href))) }) }), _jsx("div", { "aria-hidden": "true", className: cn("pointer-events-none fixed inset-x-0 top-16 bottom-0 z-0 bg-background-200/60", navOpen ? "opacity-100" : "opacity-0") })] }));
|
|
53
53
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mobile-menu.d.ts","sourceRoot":"","sources":["../../../src/internal/navbar/mobile-menu.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mobile-menu.d.ts","sourceRoot":"","sources":["../../../src/internal/navbar/mobile-menu.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,yBAAyB,EAEzB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAQtB,UAAU,eAAe;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,GAAG,EAAE,gBAAgB,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,yBAAyB,EAAE,CAAC;IAC1C,mEAAmE;IACnE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA6PD,eAAO,MAAM,UAAU,GAAI,0DAMxB,eAAe,4CA4HjB,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { ThemeSwitcher } from "@vercel/geistcn/components/theme-switcher";
|
|
4
4
|
import { cn } from "@vercel/geistcn/utils";
|
|
5
5
|
import { IconChevronDownSmall } from "@vercel/geistcn-assets/icons";
|
|
6
|
+
import { useMediaQuery } from "phase/react";
|
|
6
7
|
import { useEffect, useState } from "react";
|
|
7
8
|
import { SearchButton } from "../../controls";
|
|
8
9
|
import { ExternalArrow } from "../external-arrow";
|
|
@@ -50,9 +51,10 @@ function OssCollapsible({ sections, onLinkClick, }) {
|
|
|
50
51
|
return (_jsxs("details", { className: "group flex flex-col", name: "geistdocs-mobile-nav", children: [_jsxs("summary", { className: "flex min-h-11 cursor-pointer list-none items-center justify-between rounded-md px-3 font-normal text-2xl text-gray-900 outline-none transition-colors hover:bg-gray-alpha-100 hover:text-gray-1000 [&::-webkit-details-marker]:hidden", children: [_jsxs("span", { children: ["Vercel OSS", _jsx(ExternalArrow, { className: "mt-1" })] }), _jsx(IconChevronDownSmall, { className: "relative shrink-0 text-gray-700 transition-transform duration-150 group-open:rotate-180", size: 24 })] }), _jsx("div", { className: "flex flex-col gap-6 px-3 py-4", children: sections.map((section) => (_jsxs("div", { className: "flex flex-col", children: [_jsx("p", { className: "mb-2 font-mono text-gray-700 text-xs uppercase tracking-wider", children: section.heading }), _jsx("ul", { className: "-mx-3 flex list-none flex-col", children: section.items.map((product) => (_jsx("li", { children: _jsx(SubNavLink, { external: product.external ?? product.href.startsWith("http"), href: product.href, onClick: onLinkClick, children: product.label }) }, product.href))) })] }, section.heading))) })] }));
|
|
51
52
|
}
|
|
52
53
|
function MobileMenuButton({ expanded, onClick, }) {
|
|
53
|
-
return (_jsx("button", { "aria-expanded": expanded, "aria-label": expanded ? "Close menu" : "Open menu", className: "relative flex @min-[1024px]:hidden size-8 items-center justify-center rounded-full border border-gray-200 transition-colors hover:bg-gray-100", "data-slot": "mobile-menu-toggle", onClick: onClick, type: "button", children: _jsxs("span", { className: "flex flex-col items-center justify-center gap-[5px]", children: [_jsx("span", { className: cn("block h-[1.5px] w-3.5 bg-gray-1000 transition-
|
|
54
|
+
return (_jsx("button", { "aria-expanded": expanded, "aria-label": expanded ? "Close menu" : "Open menu", className: "relative flex @min-[1024px]:hidden size-8 items-center justify-center rounded-full border border-gray-200 transition-colors hover:bg-gray-100", "data-slot": "mobile-menu-toggle", onClick: onClick, type: "button", children: _jsxs("span", { className: "flex flex-col items-center justify-center gap-[5px]", children: [_jsx("span", { className: cn("block h-[1.5px] w-3.5 bg-gray-1000 transition-transform duration-150", expanded && "translate-y-[3.25px] rotate-45") }), _jsx("span", { className: cn("block h-[1.5px] w-3.5 bg-gray-1000 transition-transform duration-150", expanded && "-translate-y-[3.25px] -rotate-45") })] }) }));
|
|
54
55
|
}
|
|
55
56
|
export const MobileMenu = ({ activeProduct, githubUrl, nav, ossProducts, showOss = false, }) => {
|
|
57
|
+
const isDesktop = useMediaQuery("(min-width: 1024px)");
|
|
56
58
|
const [show, setShow] = useState(false);
|
|
57
59
|
const isActive = useNavActive();
|
|
58
60
|
// Resolve the default/custom list and drop the active product here on the
|
|
@@ -83,18 +85,11 @@ export const MobileMenu = ({ activeProduct, githubUrl, nav, ossProducts, showOss
|
|
|
83
85
|
useEffect(() => {
|
|
84
86
|
setShow(false);
|
|
85
87
|
}, []);
|
|
86
|
-
// Close the sheet when resizing up to desktop (also releases the scroll lock).
|
|
87
88
|
useEffect(() => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
onChange();
|
|
95
|
-
mq.addEventListener("change", onChange);
|
|
96
|
-
return () => mq.removeEventListener("change", onChange);
|
|
97
|
-
}, []);
|
|
89
|
+
if (isDesktop) {
|
|
90
|
+
setShow(false);
|
|
91
|
+
}
|
|
92
|
+
}, [isDesktop]);
|
|
98
93
|
useEffect(() => {
|
|
99
94
|
const handleEscape = (e) => {
|
|
100
95
|
if (e.key === "Escape" && show) {
|
|
@@ -113,7 +108,7 @@ export const MobileMenu = ({ activeProduct, githubUrl, nav, ossProducts, showOss
|
|
|
113
108
|
const close = () => setShow(false);
|
|
114
109
|
return (_jsxs(_Fragment, { children: [_jsx(MobileMenuButton, { expanded: show, onClick: () => setShow(!show) }), _jsx("div", { className: cn("fixed inset-0 top-16 z-40 @min-[1024px]:hidden bg-background-200 transition-opacity duration-200", show
|
|
115
110
|
? "pointer-events-auto opacity-100"
|
|
116
|
-
: "pointer-events-none opacity-0"), onClick: close }), _jsxs("div", { className: cn("fixed inset-x-0 top-16 bottom-0 z-40 @min-[1024px]:hidden overflow-y-auto bg-background-200 px-2 transition-
|
|
111
|
+
: "pointer-events-none opacity-0"), onClick: close }), _jsxs("div", { className: cn("fixed inset-x-0 top-16 bottom-0 z-40 @min-[1024px]:hidden overflow-y-auto bg-background-200 px-2 transition-[transform,opacity] duration-200", show
|
|
117
112
|
? "translate-y-0 opacity-100"
|
|
118
113
|
: "pointer-events-none -translate-y-2 opacity-0"), children: [_jsx("div", { className: "p-4", children: _jsx(SearchButton, { className: "w-full py-4.5", onClick: close }) }), _jsxs("nav", { className: "flex flex-col px-1", children: [nav.map((item) => "items" in item ? (_jsx(NavDropdownCollapsible, { dropdown: item, onLinkClick: close }, item.label)) : (_jsx(NavLink, { active: isActive(item.href), external: item.href.startsWith("http"), href: item.href, onClick: close, children: item.label }, item.href))), githubUrl ? (_jsx(NavLink, { external: true, href: githubUrl, onClick: close, children: "GitHub" })) : null, _jsx(OssCollapsible, { onLinkClick: close, sections: ossSections })] }), _jsx("div", { className: "mt-2 flex justify-end px-4 py-4", children: _jsx(ThemeSwitcher, { small: true }) })] })] }));
|
|
119
114
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navbar-shell.d.ts","sourceRoot":"","sources":["../../../src/internal/navbar/navbar-shell.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"navbar-shell.d.ts","sourceRoot":"","sources":["../../../src/internal/navbar/navbar-shell.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAM5D,eAAO,MAAM,WAAW,GAAI,cAAc;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,4CAqBhE,CAAC"}
|