'use client'; import { useMemo } from 'react'; import { FileText } from 'lucide-react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@djangocfg/ui-core/components'; import { cn } from '@djangocfg/ui-core/lib'; import { MarkdownMessage } from '../../dev/code/MarkdownMessage'; export interface PastedTextDialogProps { /** Whether the dialog is open. */ open: boolean; /** Open-state change handler (Esc / overlay click / close button). */ onOpenChange: (open: boolean) => void; /** The raw pasted text to preview. */ text: string; /** Short title shown in the header (the chip's derived title). */ title?: string; } /** * Read-only preview for a "Pasted text" attachment chunk. * * Renders the raw paste through `MarkdownMessage` — the same chat-tuned * renderer used for message bubbles, so fenced code blocks, tables and * GFM all come out formatted, with the plain-text fast path kicking in * for prose-only pastes. View-only by design: there is no edit affordance. * * Built on ui-core's radix `Dialog` primitive with local open-state — it * does not touch the global `dialog-service` (that service is shaped for * imperative string-message alerts/confirms, not arbitrary content). The * caller owns `open` so the chip can drive it from a click. */ export function PastedTextDialog({ open, onOpenChange, text, title, }: PastedTextDialogProps) { // A rough size hint for the header (chars / KB) — cheap, derived. const meta = useMemo(() => { const chars = text.length; const kb = new Blob([text]).size / 1024; return kb >= 1 ? `${chars.toLocaleString()} chars · ${kb.toFixed(1)} KB` : `${chars.toLocaleString()} chars`; }, [text]); return ( e.preventDefault()} > {title ?? 'Pasted text'}

{meta}

{/* Scrollable body — `MarkdownMessage` formats the paste. */}
); } export default PastedTextDialog;