From 3b8b1bab8db7ed860c139347454a2ce42413f69a Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 20 Feb 2026 19:39:04 -0800 Subject: [PATCH 01/18] feat: add slot context menu with rename for Vue nodes Add right-click context menu on slot connection dots in Vue nodes (Nodes 2.0) with a 'Rename slot' option, matching litegraph parity. - Slot rename respects nameLocked and widget-input filtering - Uses dialogService.prompt() for rename input - Menu position tracks canvas pan/zoom via RAF sync Amp-Thread-ID: https://ampcode.com/threads/T-019c7db2-dbb3-7090-ba79-856d7f630a42 --- src/components/graph/GraphCanvas.vue | 2 + .../vueNodes/components/InputSlot.vue | 12 ++ .../vueNodes/components/OutputSlot.vue | 12 ++ .../vueNodes/components/SlotContextMenu.vue | 157 ++++++++++++++++++ .../composables/useSlotContextMenu.test.ts | 156 +++++++++++++++++ .../composables/useSlotContextMenu.ts | 69 ++++++++ 6 files changed, 408 insertions(+) create mode 100644 src/renderer/extensions/vueNodes/components/SlotContextMenu.vue create mode 100644 src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts create mode 100644 src/renderer/extensions/vueNodes/composables/useSlotContextMenu.ts diff --git a/src/components/graph/GraphCanvas.vue b/src/components/graph/GraphCanvas.vue index 967b8f00f32..8967b8982c8 100644 --- a/src/components/graph/GraphCanvas.vue +++ b/src/components/graph/GraphCanvas.vue @@ -115,6 +115,7 @@ + @@ -154,6 +155,7 @@ import NodeContextMenu from '@/components/graph/NodeContextMenu.vue' import NodeDragPreview from '@/components/graph/NodeDragPreview.vue' import NodeSelectionModeBanner from '@/components/graph/NodeSelectionModeBanner.vue' import SelectionToolbox from '@/components/graph/SelectionToolbox.vue' +import SlotContextMenu from '@/renderer/extensions/vueNodes/components/SlotContextMenu.vue' import TitleEditor from '@/components/graph/TitleEditor.vue' import NodePropertiesPanel from '@/components/rightSidePanel/RightSidePanel.vue' import { useAgentDockMount } from '@/workbench/extensions/agent/composables/useAgentDockMount' diff --git a/src/renderer/extensions/vueNodes/components/InputSlot.vue b/src/renderer/extensions/vueNodes/components/InputSlot.vue index f9f20d65735..67ceea29353 100644 --- a/src/renderer/extensions/vueNodes/components/InputSlot.vue +++ b/src/renderer/extensions/vueNodes/components/InputSlot.vue @@ -31,6 +31,7 @@ @click="onClick" @dblclick="onDoubleClick" @pointerdown="onPointerDown" + @contextmenu.stop.prevent="onSlotContextMenu" /> @@ -63,6 +64,8 @@ import type { INodeSlot } from '@/lib/litegraph/src/litegraph' import { useSlotLinkDragUIState } from '@/renderer/core/canvas/links/slotLinkDragUIState' import { getSlotKey } from '@/renderer/core/layout/slots/slotIdentifier' import { useNodeTooltips } from '@/renderer/extensions/vueNodes/composables/useNodeTooltips' +import { showSlotMenu } from '@/renderer/extensions/vueNodes/composables/useSlotContextMenu' +import { useSlotElementTracking } from '@/renderer/extensions/vueNodes/composables/useSlotElementTracking' import { useSlotLinkInteraction } from '@/renderer/extensions/vueNodes/composables/useSlotLinkInteraction' import { cn } from '@comfyorg/tailwind-utils' import type { NodeId } from '@/types/nodeId' @@ -128,4 +131,13 @@ const { onClick, onDoubleClick, onPointerDown } = useSlotLinkInteraction({ index: props.index, type: 'input' }) + +function onSlotContextMenu(event: MouseEvent) { + if (!props.nodeId) return + showSlotMenu(event, { + nodeId: props.nodeId, + slotIndex: props.index, + isInput: true + }) +} diff --git a/src/renderer/extensions/vueNodes/components/OutputSlot.vue b/src/renderer/extensions/vueNodes/components/OutputSlot.vue index 2e1a8a743a3..cafa10e175d 100644 --- a/src/renderer/extensions/vueNodes/components/OutputSlot.vue +++ b/src/renderer/extensions/vueNodes/components/OutputSlot.vue @@ -20,6 +20,7 @@ class="w-3 translate-x-1/2" :slot-data @pointerdown="onPointerDown" + @contextmenu.stop.prevent="onSlotContextMenu" /> @@ -34,6 +35,8 @@ import { RenderShape } from '@/lib/litegraph/src/types/globalEnums' import { useSlotLinkDragUIState } from '@/renderer/core/canvas/links/slotLinkDragUIState' import { getSlotKey } from '@/renderer/core/layout/slots/slotIdentifier' import { useNodeTooltips } from '@/renderer/extensions/vueNodes/composables/useNodeTooltips' +import { showSlotMenu } from '@/renderer/extensions/vueNodes/composables/useSlotContextMenu' +import { useSlotElementTracking } from '@/renderer/extensions/vueNodes/composables/useSlotElementTracking' import { useSlotLinkInteraction } from '@/renderer/extensions/vueNodes/composables/useSlotLinkInteraction' import { cn } from '@comfyorg/tailwind-utils' import type { NodeId } from '@/types/nodeId' @@ -112,4 +115,13 @@ const { onPointerDown } = useSlotLinkInteraction({ index: props.index, type: 'output' }) + +function onSlotContextMenu(event: MouseEvent) { + if (!props.nodeId) return + showSlotMenu(event, { + nodeId: props.nodeId, + slotIndex: props.index, + isInput: false + }) +} diff --git a/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue b/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue new file mode 100644 index 00000000000..d5454f10959 --- /dev/null +++ b/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue @@ -0,0 +1,157 @@ + + + diff --git a/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts b/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts new file mode 100644 index 00000000000..4ec8abf9186 --- /dev/null +++ b/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts @@ -0,0 +1,156 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +const { mockGraph, mockCanvas } = vi.hoisted(() => { + const mockGraph = { + getNodeById: vi.fn(), + beforeChange: vi.fn(), + afterChange: vi.fn() + } + const mockCanvas = { + graph: mockGraph as typeof mockGraph | null, + setDirty: vi.fn() + } + return { mockGraph, mockCanvas } +}) + +vi.mock('@/scripts/app', () => ({ + app: { canvas: mockCanvas } +})) + +import { canRenameSlot, renameSlot } from './useSlotContextMenu' + +describe('canRenameSlot', () => { + beforeEach(() => { + vi.clearAllMocks() + mockCanvas.graph = mockGraph + }) + + it('returns false when graph is null', () => { + mockCanvas.graph = null + expect(canRenameSlot({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + false + ) + }) + + it('returns false when node is not found', () => { + mockGraph.getNodeById.mockReturnValue(null) + expect(canRenameSlot({ nodeId: '99', slotIndex: 0, isInput: true })).toBe( + false + ) + }) + + it('returns true for a normal input slot', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: null, name: 'image' }], + outputs: [] + }) + expect(canRenameSlot({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + true + ) + }) + + it('returns true for a normal output slot', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [], + outputs: [{ type: 'IMAGE', links: [], name: 'image' }] + }) + expect(canRenameSlot({ nodeId: '1', slotIndex: 0, isInput: false })).toBe( + true + ) + }) + + it('returns false when slot is nameLocked', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: null, name: 'image', nameLocked: true }], + outputs: [] + }) + expect(canRenameSlot({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + false + ) + }) + + it('returns false when input slot has a widget', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [ + { type: 'INT', link: 5, name: 'steps', widget: { name: 'steps' } } + ], + outputs: [] + }) + expect(canRenameSlot({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + false + ) + }) + + it('returns false when slot index is out of range', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [], + outputs: [] + }) + expect(canRenameSlot({ nodeId: '1', slotIndex: 5, isInput: true })).toBe( + false + ) + }) +}) + +describe('renameSlot', () => { + beforeEach(() => { + vi.clearAllMocks() + mockCanvas.graph = mockGraph + }) + + it('does nothing when graph is null', () => { + mockCanvas.graph = null + renameSlot({ nodeId: '1', slotIndex: 0, isInput: true }, 'new') + expect(mockGraph.beforeChange).not.toHaveBeenCalled() + }) + + it('does nothing when node is not found', () => { + mockGraph.getNodeById.mockReturnValue(null) + renameSlot({ nodeId: '99', slotIndex: 0, isInput: true }, 'new') + expect(mockGraph.beforeChange).not.toHaveBeenCalled() + }) + + it('renames an input slot label', () => { + const inputSlot = { type: 'IMAGE', link: null, name: 'image', label: '' } + mockGraph.getNodeById.mockReturnValue({ + getInputInfo: () => inputSlot, + getOutputInfo: () => null + }) + + renameSlot({ nodeId: '1', slotIndex: 0, isInput: true }, 'my_image') + + expect(inputSlot.label).toBe('my_image') + expect(mockGraph.beforeChange).toHaveBeenCalled() + expect(mockGraph.afterChange).toHaveBeenCalled() + expect(mockCanvas.setDirty).toHaveBeenCalledWith(true, true) + }) + + it('renames an output slot label', () => { + const outputSlot = { + type: 'MODEL', + links: [], + name: 'model', + label: '' + } + mockGraph.getNodeById.mockReturnValue({ + getInputInfo: () => null, + getOutputInfo: () => outputSlot + }) + + renameSlot({ nodeId: '1', slotIndex: 0, isInput: false }, 'my_model') + + expect(outputSlot.label).toBe('my_model') + expect(mockGraph.beforeChange).toHaveBeenCalled() + expect(mockGraph.afterChange).toHaveBeenCalled() + }) + + it('does nothing when slot info is null', () => { + mockGraph.getNodeById.mockReturnValue({ + getInputInfo: () => null, + getOutputInfo: () => null + }) + + renameSlot({ nodeId: '1', slotIndex: 0, isInput: true }, 'new') + expect(mockGraph.beforeChange).not.toHaveBeenCalled() + }) +}) diff --git a/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.ts b/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.ts new file mode 100644 index 00000000000..81879f75f98 --- /dev/null +++ b/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.ts @@ -0,0 +1,69 @@ +import type { Ref } from 'vue' + +import type { NodeId } from '@/lib/litegraph/src/LGraphNode' +import { app } from '@/scripts/app' + +interface SlotMenuContext { + nodeId: NodeId + slotIndex: number + isInput: boolean +} + +interface SlotMenuInstance { + show: (event: MouseEvent, context: SlotMenuContext) => void + hide: () => void + isOpen: Ref +} + +let slotMenuInstance: SlotMenuInstance | null = null + +export function registerSlotMenuInstance( + instance: SlotMenuInstance | null +): void { + slotMenuInstance = instance +} + +export function showSlotMenu( + event: MouseEvent, + context: SlotMenuContext +): void { + slotMenuInstance?.show(event, context) +} + +export function renameSlot(context: SlotMenuContext, newLabel: string): void { + const graph = app.canvas?.graph + if (!graph) return + + const node = graph.getNodeById(context.nodeId) + if (!node) return + + const slotInfo = context.isInput + ? node.getInputInfo(context.slotIndex) + : node.getOutputInfo(context.slotIndex) + if (!slotInfo) return + + graph.beforeChange() + slotInfo.label = newLabel + app.canvas?.setDirty(true, true) + graph.afterChange() +} + +export function canRenameSlot(context: SlotMenuContext): boolean { + const graph = app.canvas?.graph + if (!graph) return false + + const node = graph.getNodeById(context.nodeId) + if (!node) return false + + const slotInfo = context.isInput + ? node.inputs?.[context.slotIndex] + : node.outputs?.[context.slotIndex] + if (!slotInfo) return false + + if (slotInfo.nameLocked) return false + if (context.isInput && 'widget' in slotInfo && slotInfo.widget) return false + + return true +} + +export type { SlotMenuContext } From e83a7912e07f1fd3457f23e5ab9cea30f07e9d2a Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 12 Mar 2026 07:36:35 -0700 Subject: [PATCH 02/18] fix: guard renameSlot with canRenameSlot check Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9045#discussion_r2835782400 https://github.com/Comfy-Org/ComfyUI_frontend/pull/9045#discussion_r2835782394 --- .../composables/useSlotContextMenu.test.ts | 28 +++++++++++++++++-- .../composables/useSlotContextMenu.ts | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts b/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts index 4ec8abf9186..3cc8b0fd4c9 100644 --- a/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts +++ b/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts @@ -19,7 +19,7 @@ vi.mock('@/scripts/app', () => ({ import { canRenameSlot, renameSlot } from './useSlotContextMenu' -describe('canRenameSlot', () => { +describe(canRenameSlot, () => { beforeEach(() => { vi.clearAllMocks() mockCanvas.graph = mockGraph @@ -92,7 +92,7 @@ describe('canRenameSlot', () => { }) }) -describe('renameSlot', () => { +describe(renameSlot, () => { beforeEach(() => { vi.clearAllMocks() mockCanvas.graph = mockGraph @@ -110,9 +110,31 @@ describe('renameSlot', () => { expect(mockGraph.beforeChange).not.toHaveBeenCalled() }) + it('does nothing when slot is nameLocked', () => { + const inputSlot = { + type: 'IMAGE', + link: null, + name: 'image', + label: '', + nameLocked: true + } + mockGraph.getNodeById.mockReturnValue({ + inputs: [inputSlot], + outputs: [], + getInputInfo: () => inputSlot, + getOutputInfo: () => null + }) + + renameSlot({ nodeId: '1', slotIndex: 0, isInput: true }, 'new') + expect(mockGraph.beforeChange).not.toHaveBeenCalled() + expect(inputSlot.label).toBe('') + }) + it('renames an input slot label', () => { const inputSlot = { type: 'IMAGE', link: null, name: 'image', label: '' } mockGraph.getNodeById.mockReturnValue({ + inputs: [inputSlot], + outputs: [], getInputInfo: () => inputSlot, getOutputInfo: () => null }) @@ -133,6 +155,8 @@ describe('renameSlot', () => { label: '' } mockGraph.getNodeById.mockReturnValue({ + inputs: [], + outputs: [outputSlot], getInputInfo: () => null, getOutputInfo: () => outputSlot }) diff --git a/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.ts b/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.ts index 81879f75f98..b7f7b59670b 100644 --- a/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.ts +++ b/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.ts @@ -31,6 +31,8 @@ export function showSlotMenu( } export function renameSlot(context: SlotMenuContext, newLabel: string): void { + if (!canRenameSlot(context)) return + const graph = app.canvas?.graph if (!graph) return From a15fc2ebc0724af162605fa64b5c85f72511bb68 Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 12 Mar 2026 07:37:20 -0700 Subject: [PATCH 03/18] fix: guard onSlotContextMenu to prevent empty menu popup Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9045#discussion_r2924250194 --- .../extensions/vueNodes/components/InputSlot.vue | 13 +++++++------ .../extensions/vueNodes/components/OutputSlot.vue | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/renderer/extensions/vueNodes/components/InputSlot.vue b/src/renderer/extensions/vueNodes/components/InputSlot.vue index 67ceea29353..68ca41e6cc0 100644 --- a/src/renderer/extensions/vueNodes/components/InputSlot.vue +++ b/src/renderer/extensions/vueNodes/components/InputSlot.vue @@ -64,7 +64,10 @@ import type { INodeSlot } from '@/lib/litegraph/src/litegraph' import { useSlotLinkDragUIState } from '@/renderer/core/canvas/links/slotLinkDragUIState' import { getSlotKey } from '@/renderer/core/layout/slots/slotIdentifier' import { useNodeTooltips } from '@/renderer/extensions/vueNodes/composables/useNodeTooltips' -import { showSlotMenu } from '@/renderer/extensions/vueNodes/composables/useSlotContextMenu' +import { + canRenameSlot, + showSlotMenu +} from '@/renderer/extensions/vueNodes/composables/useSlotContextMenu' import { useSlotElementTracking } from '@/renderer/extensions/vueNodes/composables/useSlotElementTracking' import { useSlotLinkInteraction } from '@/renderer/extensions/vueNodes/composables/useSlotLinkInteraction' import { cn } from '@comfyorg/tailwind-utils' @@ -134,10 +137,8 @@ const { onClick, onDoubleClick, onPointerDown } = useSlotLinkInteraction({ function onSlotContextMenu(event: MouseEvent) { if (!props.nodeId) return - showSlotMenu(event, { - nodeId: props.nodeId, - slotIndex: props.index, - isInput: true - }) + const ctx = { nodeId: props.nodeId, slotIndex: props.index, isInput: true } + if (!canRenameSlot(ctx)) return + showSlotMenu(event, ctx) } diff --git a/src/renderer/extensions/vueNodes/components/OutputSlot.vue b/src/renderer/extensions/vueNodes/components/OutputSlot.vue index cafa10e175d..798403ad80e 100644 --- a/src/renderer/extensions/vueNodes/components/OutputSlot.vue +++ b/src/renderer/extensions/vueNodes/components/OutputSlot.vue @@ -35,7 +35,10 @@ import { RenderShape } from '@/lib/litegraph/src/types/globalEnums' import { useSlotLinkDragUIState } from '@/renderer/core/canvas/links/slotLinkDragUIState' import { getSlotKey } from '@/renderer/core/layout/slots/slotIdentifier' import { useNodeTooltips } from '@/renderer/extensions/vueNodes/composables/useNodeTooltips' -import { showSlotMenu } from '@/renderer/extensions/vueNodes/composables/useSlotContextMenu' +import { + canRenameSlot, + showSlotMenu +} from '@/renderer/extensions/vueNodes/composables/useSlotContextMenu' import { useSlotElementTracking } from '@/renderer/extensions/vueNodes/composables/useSlotElementTracking' import { useSlotLinkInteraction } from '@/renderer/extensions/vueNodes/composables/useSlotLinkInteraction' import { cn } from '@comfyorg/tailwind-utils' @@ -118,10 +121,8 @@ const { onPointerDown } = useSlotLinkInteraction({ function onSlotContextMenu(event: MouseEvent) { if (!props.nodeId) return - showSlotMenu(event, { - nodeId: props.nodeId, - slotIndex: props.index, - isInput: false - }) + const ctx = { nodeId: props.nodeId, slotIndex: props.index, isInput: false } + if (!canRenameSlot(ctx)) return + showSlotMenu(event, ctx) } From a036e45b328da468f8bc7862143fb2a4255b3652 Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 12 Mar 2026 07:37:35 -0700 Subject: [PATCH 04/18] fix: reject empty string in handleRename to prevent ghost labels Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9045#discussion_r2924258161 --- src/renderer/extensions/vueNodes/components/SlotContextMenu.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue b/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue index d5454f10959..a9b590df383 100644 --- a/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue +++ b/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue @@ -109,7 +109,7 @@ async function handleRename(ctx: SlotMenuContext) { title: t('g.rename'), message: t('g.enterNewNamePrompt') }) - if (newLabel === null) return + if (!newLabel) return renameSlot(ctx, newLabel) } From 1f59eaba18219e0f1e5001c2af26cb7f8d257c78 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 13 Mar 2026 09:38:10 -0700 Subject: [PATCH 05/18] test: add comprehensive slot context menu tests (TDD red phase) Tests for all slot context menu actions: - canRenameSlot, canDisconnectSlot, canRemoveSlot, hasAnySlotAction - renameSlot, disconnectSlotLinks, removeSlot - Guard conditions, happy paths, and slot refresh triggers - 35 tests covering full LiteGraph slot menu parity --- .../composables/useSlotContextMenu.test.ts | 336 +++++++++++++++++- 1 file changed, 323 insertions(+), 13 deletions(-) diff --git a/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts b/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts index 3cc8b0fd4c9..33f5bdc3326 100644 --- a/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts +++ b/src/renderer/extensions/vueNodes/composables/useSlotContextMenu.test.ts @@ -4,7 +4,8 @@ const { mockGraph, mockCanvas } = vi.hoisted(() => { const mockGraph = { getNodeById: vi.fn(), beforeChange: vi.fn(), - afterChange: vi.fn() + afterChange: vi.fn(), + trigger: vi.fn() } const mockCanvas = { graph: mockGraph as typeof mockGraph | null, @@ -17,7 +18,15 @@ vi.mock('@/scripts/app', () => ({ app: { canvas: mockCanvas } })) -import { canRenameSlot, renameSlot } from './useSlotContextMenu' +import { + canDisconnectSlot, + canRemoveSlot, + canRenameSlot, + disconnectSlotLinks, + hasAnySlotAction, + removeSlot, + renameSlot +} from './useSlotContextMenu' describe(canRenameSlot, () => { beforeEach(() => { @@ -32,14 +41,14 @@ describe(canRenameSlot, () => { ) }) - it('returns false when node is not found', () => { + it('returns false when node not found', () => { mockGraph.getNodeById.mockReturnValue(null) expect(canRenameSlot({ nodeId: '99', slotIndex: 0, isInput: true })).toBe( false ) }) - it('returns true for a normal input slot', () => { + it('returns true for normal input slot', () => { mockGraph.getNodeById.mockReturnValue({ inputs: [{ type: 'IMAGE', link: null, name: 'image' }], outputs: [] @@ -49,7 +58,7 @@ describe(canRenameSlot, () => { ) }) - it('returns true for a normal output slot', () => { + it('returns true for normal output slot', () => { mockGraph.getNodeById.mockReturnValue({ inputs: [], outputs: [{ type: 'IMAGE', links: [], name: 'image' }] @@ -81,7 +90,7 @@ describe(canRenameSlot, () => { ) }) - it('returns false when slot index is out of range', () => { + it('returns false when slot index out of range', () => { mockGraph.getNodeById.mockReturnValue({ inputs: [], outputs: [] @@ -92,6 +101,167 @@ describe(canRenameSlot, () => { }) }) +describe(canDisconnectSlot, () => { + beforeEach(() => { + vi.clearAllMocks() + mockCanvas.graph = mockGraph + }) + + it('returns false when graph is null', () => { + mockCanvas.graph = null + expect( + canDisconnectSlot({ nodeId: '1', slotIndex: 0, isInput: true }) + ).toBe(false) + }) + + it('returns true for input with link', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: 42, name: 'image' }], + outputs: [] + }) + expect( + canDisconnectSlot({ nodeId: '1', slotIndex: 0, isInput: true }) + ).toBe(true) + }) + + it('returns false for input without link', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: null, name: 'image' }], + outputs: [] + }) + expect( + canDisconnectSlot({ nodeId: '1', slotIndex: 0, isInput: true }) + ).toBe(false) + }) + + it('returns true for output with links', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [], + outputs: [{ type: 'IMAGE', links: [1, 2], name: 'image' }] + }) + expect( + canDisconnectSlot({ nodeId: '1', slotIndex: 0, isInput: false }) + ).toBe(true) + }) + + it('returns false for output with empty links array', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [], + outputs: [{ type: 'IMAGE', links: [], name: 'image' }] + }) + expect( + canDisconnectSlot({ nodeId: '1', slotIndex: 0, isInput: false }) + ).toBe(false) + }) + + it('returns false for output with null links', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [], + outputs: [{ type: 'IMAGE', links: null, name: 'image' }] + }) + expect( + canDisconnectSlot({ nodeId: '1', slotIndex: 0, isInput: false }) + ).toBe(false) + }) +}) + +describe(canRemoveSlot, () => { + beforeEach(() => { + vi.clearAllMocks() + mockCanvas.graph = mockGraph + }) + + it('returns false when graph is null', () => { + mockCanvas.graph = null + expect(canRemoveSlot({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + false + ) + }) + + it('returns true when removable is true and not locked', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: null, name: 'image', removable: true }], + outputs: [] + }) + expect(canRemoveSlot({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + true + ) + }) + + it('returns false when removable is false', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: null, name: 'image', removable: false }], + outputs: [] + }) + expect(canRemoveSlot({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + false + ) + }) + + it('returns false when locked is true', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [ + { + type: 'IMAGE', + link: null, + name: 'image', + removable: true, + locked: true + } + ], + outputs: [] + }) + expect(canRemoveSlot({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + false + ) + }) +}) + +describe(hasAnySlotAction, () => { + beforeEach(() => { + vi.clearAllMocks() + mockCanvas.graph = mockGraph + }) + + it('returns true when rename is available', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: null, name: 'image' }], + outputs: [] + }) + expect(hasAnySlotAction({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + true + ) + }) + + it('returns true when disconnect is available', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: 42, name: 'image', nameLocked: true }], + outputs: [] + }) + expect(hasAnySlotAction({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + true + ) + }) + + it('returns false when no action available', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [ + { + type: 'IMAGE', + link: null, + name: 'image', + nameLocked: true, + removable: false + } + ], + outputs: [] + }) + expect(hasAnySlotAction({ nodeId: '1', slotIndex: 0, isInput: true })).toBe( + false + ) + }) +}) + describe(renameSlot, () => { beforeEach(() => { vi.clearAllMocks() @@ -104,13 +274,7 @@ describe(renameSlot, () => { expect(mockGraph.beforeChange).not.toHaveBeenCalled() }) - it('does nothing when node is not found', () => { - mockGraph.getNodeById.mockReturnValue(null) - renameSlot({ nodeId: '99', slotIndex: 0, isInput: true }, 'new') - expect(mockGraph.beforeChange).not.toHaveBeenCalled() - }) - - it('does nothing when slot is nameLocked', () => { + it('does nothing when nameLocked', () => { const inputSlot = { type: 'IMAGE', link: null, @@ -168,8 +332,26 @@ describe(renameSlot, () => { expect(mockGraph.afterChange).toHaveBeenCalled() }) + it('triggers slot refresh event after rename', () => { + const inputSlot = { type: 'IMAGE', link: null, name: 'image', label: '' } + mockGraph.getNodeById.mockReturnValue({ + inputs: [inputSlot], + outputs: [], + getInputInfo: () => inputSlot, + getOutputInfo: () => null + }) + + renameSlot({ nodeId: '1', slotIndex: 0, isInput: true }, 'renamed') + + expect(mockGraph.trigger).toHaveBeenCalledWith('node:slot-label:changed', { + nodeId: '1' + }) + }) + it('does nothing when slot info is null', () => { mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: null, name: 'image' }], + outputs: [], getInputInfo: () => null, getOutputInfo: () => null }) @@ -178,3 +360,131 @@ describe(renameSlot, () => { expect(mockGraph.beforeChange).not.toHaveBeenCalled() }) }) + +describe(disconnectSlotLinks, () => { + beforeEach(() => { + vi.clearAllMocks() + mockCanvas.graph = mockGraph + }) + + it('does nothing when graph is null', () => { + mockCanvas.graph = null + disconnectSlotLinks({ nodeId: '1', slotIndex: 0, isInput: true }) + expect(mockGraph.beforeChange).not.toHaveBeenCalled() + }) + + it('disconnects an input slot', () => { + const disconnectInput = vi.fn() + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: 42, name: 'image' }], + outputs: [], + disconnectInput + }) + + disconnectSlotLinks({ nodeId: '1', slotIndex: 0, isInput: true }) + + expect(mockGraph.beforeChange).toHaveBeenCalled() + expect(disconnectInput).toHaveBeenCalledWith(0, true) + expect(mockGraph.afterChange).toHaveBeenCalled() + expect(mockCanvas.setDirty).toHaveBeenCalledWith(true, true) + }) + + it('disconnects an output slot', () => { + const disconnectOutput = vi.fn() + mockGraph.getNodeById.mockReturnValue({ + inputs: [], + outputs: [{ type: 'IMAGE', links: [1, 2], name: 'image' }], + disconnectOutput + }) + + disconnectSlotLinks({ nodeId: '1', slotIndex: 0, isInput: false }) + + expect(mockGraph.beforeChange).toHaveBeenCalled() + expect(disconnectOutput).toHaveBeenCalledWith(0) + expect(mockGraph.afterChange).toHaveBeenCalled() + expect(mockCanvas.setDirty).toHaveBeenCalledWith(true, true) + }) + + it('triggers slot refresh event after disconnect', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: 42, name: 'image' }], + outputs: [], + disconnectInput: vi.fn() + }) + + disconnectSlotLinks({ nodeId: '1', slotIndex: 0, isInput: true }) + + expect(mockGraph.trigger).toHaveBeenCalledWith('node:slot-label:changed', { + nodeId: '1' + }) + }) +}) + +describe(removeSlot, () => { + beforeEach(() => { + vi.clearAllMocks() + mockCanvas.graph = mockGraph + }) + + it('does nothing when graph is null', () => { + mockCanvas.graph = null + removeSlot({ nodeId: '1', slotIndex: 0, isInput: true }) + expect(mockGraph.beforeChange).not.toHaveBeenCalled() + }) + + it('removes an input slot', () => { + const removeInput = vi.fn() + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: null, name: 'image', removable: true }], + outputs: [], + removeInput + }) + + removeSlot({ nodeId: '1', slotIndex: 0, isInput: true }) + + expect(mockGraph.beforeChange).toHaveBeenCalled() + expect(removeInput).toHaveBeenCalledWith(0) + expect(mockGraph.afterChange).toHaveBeenCalled() + expect(mockCanvas.setDirty).toHaveBeenCalledWith(true, true) + }) + + it('removes an output slot', () => { + const removeOutput = vi.fn() + mockGraph.getNodeById.mockReturnValue({ + inputs: [], + outputs: [{ type: 'IMAGE', links: [], name: 'image', removable: true }], + removeOutput + }) + + removeSlot({ nodeId: '1', slotIndex: 0, isInput: false }) + + expect(mockGraph.beforeChange).toHaveBeenCalled() + expect(removeOutput).toHaveBeenCalledWith(0) + expect(mockGraph.afterChange).toHaveBeenCalled() + expect(mockCanvas.setDirty).toHaveBeenCalledWith(true, true) + }) + + it('does nothing when not removable', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: null, name: 'image', removable: false }], + outputs: [] + }) + + removeSlot({ nodeId: '1', slotIndex: 0, isInput: true }) + expect(mockGraph.beforeChange).not.toHaveBeenCalled() + }) + + it('triggers slot refresh event after remove', () => { + mockGraph.getNodeById.mockReturnValue({ + inputs: [{ type: 'IMAGE', link: null, name: 'image', removable: true }], + outputs: [], + removeInput: vi.fn() + }) + + removeSlot({ nodeId: '1', slotIndex: 0, isInput: true }) + + expect(mockGraph.trigger).toHaveBeenCalledWith('node:slot-label:changed', { + nodeId: '1' + }) + }) +}) From b39e14d946cc6e7a266b195ec852dd9bafafb603 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 13 Mar 2026 09:38:24 -0700 Subject: [PATCH 06/18] feat: rework slot context menu with full LiteGraph parity - Drop PrimeVue ContextMenu, use custom teleported imperative menu - Add Disconnect Links and Remove Slot actions (LiteGraph parity) - Extract useCanvasAnchoredPosition composable from NodeContextMenu - Fix slot label reactivity: add node:slot-label:changed graph event that triggers refreshNodeSlots to update both inputs and outputs - Refresh shallowReactive inputs via splice for property changes - Refresh outputs via spread copy for label changes - Use hasAnySlotAction guard instead of canRenameSlot in slot components - Add i18n keys: disconnectLinks, removeSlot --- src/components/graph/NodeContextMenu.vue | 81 +------- .../graph/useCanvasAnchoredPosition.ts | 77 +++++++ src/locales/en/main.json | 2 + .../vueNodes/components/InputSlot.vue | 4 +- .../vueNodes/components/OutputSlot.vue | 4 +- .../vueNodes/components/SlotContextMenu.vue | 190 ++++++++---------- .../composables/useSlotContextMenu.ts | 121 +++++++++-- 7 files changed, 273 insertions(+), 206 deletions(-) create mode 100644 src/composables/graph/useCanvasAnchoredPosition.ts diff --git a/src/components/graph/NodeContextMenu.vue b/src/components/graph/NodeContextMenu.vue index 788b5780f65..a19795575ee 100644 --- a/src/components/graph/NodeContextMenu.vue +++ b/src/components/graph/NodeContextMenu.vue @@ -46,11 +46,12 @@ diff --git a/src/renderer/extensions/vueNodes/components/OutputSlot.vue b/src/renderer/extensions/vueNodes/components/OutputSlot.vue index 798403ad80e..6f40aa6290a 100644 --- a/src/renderer/extensions/vueNodes/components/OutputSlot.vue +++ b/src/renderer/extensions/vueNodes/components/OutputSlot.vue @@ -36,7 +36,7 @@ import { useSlotLinkDragUIState } from '@/renderer/core/canvas/links/slotLinkDra import { getSlotKey } from '@/renderer/core/layout/slots/slotIdentifier' import { useNodeTooltips } from '@/renderer/extensions/vueNodes/composables/useNodeTooltips' import { - canRenameSlot, + hasAnySlotAction, showSlotMenu } from '@/renderer/extensions/vueNodes/composables/useSlotContextMenu' import { useSlotElementTracking } from '@/renderer/extensions/vueNodes/composables/useSlotElementTracking' @@ -122,7 +122,7 @@ const { onPointerDown } = useSlotLinkInteraction({ function onSlotContextMenu(event: MouseEvent) { if (!props.nodeId) return const ctx = { nodeId: props.nodeId, slotIndex: props.index, isInput: false } - if (!canRenameSlot(ctx)) return + if (!hasAnySlotAction(ctx)) return showSlotMenu(event, ctx) } diff --git a/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue b/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue index a9b590df383..f7865e75ee6 100644 --- a/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue +++ b/src/renderer/extensions/vueNodes/components/SlotContextMenu.vue @@ -1,29 +1,57 @@