"use client"; /** * HtmlBlockPreview — readonly rendering of fenced ```html code blocks. * * Default view is "preview" (iframe) per the V2 plan; user can flip to * "source" to see the highlighted markup and Copy it. Maximize opens the * same iframe in a full-screen Dialog. * * Mounted by ReadonlyContent's `code` renderer for `lang === "html"`. The * `pre` renderer in ReadonlyContent recognizes this component by reference * and unwraps it from the default `
` envelope, matching the same * two-layer trick already used for MermaidDiagram. * * NOT used in the editable Tiptap NodeView — that path must keep * `` so the user can continue typing. */ import { useState } from "react"; import { Check, Code as CodeIcon, Copy, Eye, Maximize2, } from "lucide-react"; import { cn } from "@multica/ui/lib/utils"; import { copyText } from "@multica/ui/lib/clipboard"; import { Dialog, DialogContent, } from "@multica/ui/components/ui/dialog"; import { useT } from "../i18n"; import { CodeBlockStatic } from "./code-block-static"; import { HtmlPreviewBody } from "./html-preview-body"; const CODE_BLOCK_IFRAME_HEIGHT = "h-[480px]"; /** * Pixel twin of CODE_BLOCK_IFRAME_HEIGHT. The preview iframe is a fixed height, * so the near-viewport lazy shell (rich-content/lazy-rich-block.tsx) can * reserve exactly the space this component will occupy and mount with zero * layout shift. Keep the two in sync. */ export const HTML_BLOCK_PREVIEW_HEIGHT_PX = 480; // Label shown in the code-block header. Not a translatable string — it's a // language identifier (matches the `lang === "html"` token below). const HTML_LANGUAGE_LABEL = "html"; interface HtmlBlockPreviewProps { html: string; className?: string; } export function HtmlBlockPreview({ html, className }: HtmlBlockPreviewProps) { const { t } = useT("editor"); const [view, setView] = useState<"preview" | "source">("preview"); const [copied, setCopied] = useState(false); const [fullscreen, setFullscreen] = useState(false); const handleCopy = async () => { if (!html) return; if (await copyText(html)) { setCopied(true); setTimeout(() => setCopied(false), 2000); } }; const toggleView = () => setView((v) => (v === "preview" ? "source" : "preview")); return ( ); }{HTML_LANGUAGE_LABEL} {view === "preview" && ( )}{view === "preview" ? () : ( )}