fix(ui): mount a fresh canvas menu at each right-click

This commit is contained in:
sam committed 2026-10-24 21:50:23 +11:00
1 parent fed94b87d8
commit 96e27f634e
2 files changed
+7 -11

No files matched your search

+6 -10
View File
@@ -263,18 +263,14 @@ watch(anchor, async (node) => {
// The right-click menu opens at the pointer, for the step under it or for the
// canvas itself.
const menu = ref<{ open: boolean; x: number; y: number; step?: StepNodeData }>({ open: false, x: 0, y: 0 });
// The menu closes for a tick before each opening: the outside right-click has
// already closed it in this tick, and reopening in the same one would keep
// the old anchor.
async function openMenu(event: MouseEvent, step?: StepNodeData): Promise<void> {
// Each opening is a fresh menu (seq keys it): a right-click elsewhere while
// one is closing would otherwise reopen it at the old anchor.
const menu = ref<{ open: boolean; x: number; y: number; step?: StepNodeData; seq: number }>({ open: false, x: 0, y: 0, seq: 0 });
function openMenu(event: MouseEvent, step?: StepNodeData): void {
if (!editable.value) return;
event.preventDefault();
const box = container.value?.getBoundingClientRect();
const next = { open: true, x: event.clientX - (box?.left ?? 0), y: event.clientY - (box?.top ?? 0), step };
menu.value = { ...menu.value, open: false };
await nextTick();
menu.value = next;
menu.value = { open: true, x: event.clientX - (box?.left ?? 0), y: event.clientY - (box?.top ?? 0), step, seq: menu.value.seq + 1 };
}
function onNodeMenu({ event, node }: NodeMouseEvent): void {
if (node.type !== "step" || (node.data as StepNodeData).kind === "workflow") return;
@@ -332,7 +328,7 @@ const beforePath = computed(() => menuPath.value ? [...menuPath.value.slice(0, -
</DialogContent>
</Dialog>
<DropdownMenu v-model:open="menu.open" :modal="false">
<DropdownMenu :key="menu.seq" v-model:open="menu.open" :modal="false">
<DropdownMenuTrigger as-child>
<span class="pointer-events-none absolute size-0" :style="{ left: `${menu.x}px`, top: `${menu.y}px` }" />
</DropdownMenuTrigger>