'use client'; import { type ComponentProps, useMemo, useState } from 'react'; import { Check, ChevronDown, Copy, ExternalLinkIcon, TextIcon } from 'lucide-react'; import { cn } from '../../lib/cn'; import { useCopyButton } from 'fumadocs-ui/utils/use-copy-button'; import { Popover, PopoverTrigger, PopoverContent } from '../ui/popover'; import { buttonVariants } from '../ui/button'; const cache = new Map>(); export function MarkdownCopyButton({ markdownUrl, ...props }: ComponentProps<'button'> & { /** * A URL to fetch the raw Markdown/MDX content of page */ markdownUrl: string; }) { const [isLoading, setLoading] = useState(false); const [checked, onClick] = useCopyButton(async () => { const cached = cache.get(markdownUrl); if (cached) return navigator.clipboard.writeText(await cached); setLoading(true); try { const promise = fetch(markdownUrl).then((res) => res.text()); cache.set(markdownUrl, promise); await navigator.clipboard.write([ new ClipboardItem({ 'text/plain': promise, }), ]); } finally { setLoading(false); } }); return ( ); } export function ViewOptionsPopover({ markdownUrl, githubUrl, ...props }: ComponentProps & { /** * A URL to the raw Markdown/MDX content of page */ markdownUrl: string; /** * Source file URL on GitHub */ githubUrl: string; }) { const items = useMemo(() => { const pageUrl = typeof window !== 'undefined' ? window.location.href : 'loading'; const q = `Read ${pageUrl}, I want to ask questions about it.`; return [ { title: 'Open in GitHub', href: githubUrl, icon: ( GitHub ), }, { title: 'View as Markdown', href: markdownUrl, icon: , }, { 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 Cursor', icon: ( Cursor ), href: `https://cursor.com/link/prompt?${new URLSearchParams({ text: q, })}`, }, ]; }, [githubUrl, markdownUrl]); return ( Open {items.map((item) => ( {item.icon} {item.title} ))} ); }