import { useCallback, useRef, useState } from "react"; import { Code2, Link as LinkIcon, MoreHorizontal, Trash2, Wand2, } from "lucide-react"; import { useDismissOn } from "../lib/useDismissOn"; /** * Overflow menu for the canvas toolbar's AUTHORING cluster — rendered * at EVERY width since the authoring-vs-evidence cluster split. * * Contents by width: * * always: Share + Export .py — rarely-used authoring actions, * demoted out of permanent chrome but one click away; * * < md only: Auto-connect + Clear join the menu (their standalone * toolbar buttons are md-gated), keeping the phone toolbar to * three visible controls. The rows carry `md:hidden` so exactly * one reachable copy of each action exists at any width. * * Closes itself on outside click and Escape (useDismissOn). */ export function MoreMenu({ className = "", canAutoConnect, hasEdgesToReplace, canClear, canExport, onAutoConnect, onShare, onExport, onClear, }: { className?: string; canAutoConnect: boolean; hasEdgesToReplace: boolean; canClear: boolean; canExport: boolean; onAutoConnect: () => void; onShare: () => void; onExport: () => void; onClear: () => void; }) { const [open, setOpen] = useState(false); const rootRef = useRef(null); useDismissOn(open, rootRef, useCallback(() => setOpen(false), [])); const items: { key: string; icon: React.ReactNode; label: string; sub?: string; disabled?: boolean; tone?: "default" | "danger"; /** true = this action has its own toolbar button at ≥md, so its * menu row hides there (md:hidden) — one reachable copy only. */ mobileOnly?: boolean; onClick: () => void; }[] = [ { key: "auto", icon: , label: "Auto-connect", sub: hasEdgesToReplace ? "Re-wire all blocks (replaces existing links)" : "Wire all blocks into a sensible chain", disabled: !canAutoConnect, mobileOnly: true, onClick: onAutoConnect, }, { key: "share", icon: , label: "Copy share link", sub: "Copies a URL that restores this pipeline", onClick: onShare, }, { key: "export", icon: , label: "Export .py", sub: "Download pipeline as a Python script", disabled: !canExport, onClick: onExport, }, { key: "clear", icon: , label: "Clear canvas", sub: "Remove every block and link", disabled: !canClear, tone: "danger", mobileOnly: true, onClick: onClear, }, ]; return (
{open && ( // Mobile ( {items.map((it) => ( ))}
)} ); }