({ containerRef, code, isLoading, svgToPng, children }: MermaidButtonProps)
| 21 | } |
| 22 | |
| 23 | export function MermaidButton({ containerRef, code, isLoading, svgToPng, children }: MermaidButtonProps) { |
| 24 | const [showModal, setShowModal] = useState(false) |
| 25 | const [zoomLevel, setZoomLevel] = useState(1) |
| 26 | const [copyFeedback, setCopyFeedback] = useState(false) |
| 27 | const [isHovering, setIsHovering] = useState(false) |
| 28 | const [modalViewMode, setModalViewMode] = useState<"diagram" | "code">("diagram") |
| 29 | const [isDragging, setIsDragging] = useState(false) |
| 30 | const [dragPosition, setDragPosition] = useState({ x: 0, y: 0 }) |
| 31 | const { copyWithFeedback } = useCopyToClipboard() |
| 32 | const { t } = useAppTranslation() |
| 33 | |
| 34 | /** |
| 35 | * Opens a modal with the diagram for zooming |
| 36 | */ |
| 37 | const handleZoom = async (e: React.MouseEvent) => { |
| 38 | e.stopPropagation() |
| 39 | setShowModal(true) |
| 40 | setZoomLevel(1) |
| 41 | setModalViewMode("diagram") |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Copies the diagram text to clipboard |
| 46 | */ |
| 47 | const handleCopy = async (e: React.MouseEvent) => { |
| 48 | e.stopPropagation() |
| 49 | |
| 50 | try { |
| 51 | await copyWithFeedback(code, e) |
| 52 | |
| 53 | // Show feedback |
| 54 | setCopyFeedback(true) |
| 55 | setTimeout(() => setCopyFeedback(false), 2000) |
| 56 | } catch (err) { |
| 57 | console.error("Error copying text:", err instanceof Error ? err.message : String(err)) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Saves the diagram as an image file |
| 63 | */ |
| 64 | const handleSave = async (e: React.MouseEvent) => { |
| 65 | e.stopPropagation() |
| 66 | |
| 67 | // Get the SVG element from the container |
| 68 | const svgEl = containerRef.current?.querySelector("svg") |
| 69 | if (!svgEl) { |
| 70 | console.error("SVG element not found") |
| 71 | return |
| 72 | } |
| 73 | |
| 74 | try { |
| 75 | // Convert SVG to PNG |
| 76 | const pngDataUrl = await svgToPng(svgEl) |
| 77 | |
| 78 | // Send message to VSCode to save the image |
| 79 | vscode.postMessage({ |
| 80 | type: "saveImage", |
nothing calls this directly
no test coverage detected