'use client'; import {useMemo, useState} from 'react'; import {Check, ChevronDown, Copy, ExternalLinkIcon, MessageCircleIcon} from 'lucide-react'; import {cn} from '../lib/cn'; import {useCopyButton} from 'fumadocs-ui/utils/use-copy-button'; import {buttonVariants} from './ui/button'; import {Popover, PopoverContent, PopoverTrigger} from 'fumadocs-ui/components/ui/popover'; import {cva} from 'class-variance-authority'; 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( 'text-sm p-2 rounded-lg inline-flex items-center gap-2 hover:text-fd-accent-foreground hover:bg-fd-accent [&_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 Scira AI', href: `https://scira.ai/?${new URLSearchParams({ q, })}`, icon: ( Scira AI ), }, { 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: , }, ]; }, [githubUrl, markdownUrl]); return ( Open {items.map(item => ( {item.icon} {item.title} ))} ); }