File size: 5,200 Bytes
7ece09e 8f72426 90bf6ec 8f72426 57f0b3e 8f72426 7ece09e 8f72426 7ece09e 8f72426 7ece09e 8f72426 90bf6ec 8f72426 90bf6ec 8f72426 90bf6ec 8f72426 90bf6ec 8f72426 57f0b3e 8f72426 7ece09e 8f72426 7ece09e 8f72426 90bf6ec 8f72426 7ece09e 8f72426 130ee8d 8f72426 db325d1 728039f db325d1 8f72426 728039f 8f72426 7ece09e 8f72426 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | 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<HTMLDivElement>(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: <Wand2 className="w-4 h-4" />,
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: <LinkIcon className="w-4 h-4" />,
label: "Copy share link",
sub: "Copies a URL that restores this pipeline",
onClick: onShare,
},
{
key: "export",
icon: <Code2 className="w-4 h-4" />,
label: "Export .py",
sub: "Download pipeline as a Python script",
disabled: !canExport,
onClick: onExport,
},
{
key: "clear",
icon: <Trash2 className="w-4 h-4" />,
label: "Clear canvas",
sub: "Remove every block and link",
disabled: !canClear,
tone: "danger",
mobileOnly: true,
onClick: onClear,
},
];
return (
<div ref={rootRef} className={`relative ${className}`}>
<button
type="button"
onClick={() => setOpen((v) => !v)}
// h-8: the canvas toolbar's uniform control height.
className="btn h-8"
title="More actions"
aria-label="More actions"
aria-haspopup="menu"
aria-expanded={open}
>
<MoreHorizontal className="w-4 h-4" />
</button>
{open && (
// Mobile (<sm): viewport-pinned (canvas toolbar can scroll
// horizontally on tiny screens, so an absolute-anchored menu
// could end up off-edge). top-14 = just under the header, the
// same pin PresetPicker/BlockPicker use — the old top-24 hung
// the menu 2.5rem below its row-1 siblings (audit S3).
// Desktop (≥sm): anchored to the button.
<div
role="menu"
className="fixed right-3 top-14 sm:absolute sm:right-0 sm:top-full sm:mt-1 rounded-lg border border-edge bg-surface shadow-xl z-30 p-1.5 flex flex-col gap-0.5 w-[min(18rem,calc(100vw-1.5rem))]"
>
{items.map((it) => (
<button
key={it.key}
type="button"
role="menuitem"
disabled={it.disabled}
onClick={() => {
if (it.disabled) return;
it.onClick();
setOpen(false);
}}
className={`${it.mobileOnly ? "md:hidden " : ""}flex items-start gap-3 px-3 py-2 rounded-md text-left transition-colors border border-transparent disabled:opacity-40 disabled:cursor-not-allowed ${
it.tone === "danger"
? "hover:bg-danger/10 hover:border-danger/40 text-ink"
: "hover:bg-surfaceAlt hover:border-edge/60 text-ink"
}`}
>
<span
className={`shrink-0 mt-0.5 ${
it.tone === "danger" ? "text-danger" : "text-mute"
}`}
>
{it.icon}
</span>
<span className="min-w-0">
<span className="block text-sm font-medium">{it.label}</span>
{it.sub && (
<span className="block text-[11px] text-mute leading-snug mt-0.5">
{it.sub}
</span>
)}
</span>
</button>
))}
</div>
)}
</div>
);
}
|