"use client"; import { cva } from "class-variance-authority"; import { buttonVariants } from "fumadocs-ui/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger, } from "fumadocs-ui/components/ui/popover"; import { useCopyButton } from "fumadocs-ui/utils/use-copy-button"; import { Check, ChevronDown, Copy, ExternalLinkIcon, MessageCircleIcon, SearchIcon, } from "lucide-react"; import { useMemo, useState } from "react"; import { cn } from "../../../lib/cn"; const cache = new Map(); export function LLMCopyButton({ /** * A URL to fetch the raw Markdown/MDX content of page */ markdownUrl, }: { markdownUrl: string; }) { const [isLoading, setLoading] = useState(false); const [checked, onClick] = useCopyButton(async () => { const cached = cache.get(markdownUrl); if (cached) return navigator.clipboard.writeText(cached); setLoading(true); try { await navigator.clipboard.write([ new ClipboardItem({ "text/plain": fetch(markdownUrl).then(async (res) => { const content = await res.text(); cache.set(markdownUrl, content); return content; }), }), ]); } finally { setLoading(false); } }); return ( ); } const optionVariants = cva( "inline-flex items-center gap-2 rounded-lg p-2 text-sm hover:bg-fd-accent hover:text-fd-accent-foreground [&_svg]:size-4", ); export function ViewOptions({ markdownUrl, githubUrl, }: { /** * A URL to the raw Markdown/MDX content of page */ markdownUrl: string; /** * Source file URL on GitHub */ githubUrl: string; }) { const items = useMemo(() => { const fullMarkdownUrl = typeof window !== "undefined" ? new URL(markdownUrl, window.location.origin) : "loading"; const q = `Read ${fullMarkdownUrl}, I want to ask questions about it.`; return [ { title: "Open in GitHub", href: githubUrl, icon: ( GitHub ), }, { title: "Open in ChatGPT", href: `https://chatgpt.com/?${new URLSearchParams({ hints: "search", q, })}`, icon: ( OpenAI ), }, { title: "Open in Claude", href: `https://claude.ai/new?${new URLSearchParams({ q, })}`, icon: ( Anthropic ), }, { title: "Open in T3 Chat", href: `https://t3.chat/new?${new URLSearchParams({ q, })}`, icon: , }, { title: "Open in Scira AI", href: `https://scira.ai/?${new URLSearchParams({ q, })}`, icon: , }, ]; }, [githubUrl, markdownUrl]); return ( Open {items.map((item) => ( {item.icon} {item.title} ))} ); }