diff --git a/src/components/graph/GraphCanvas.vue b/src/components/graph/GraphCanvas.vue index c79ccaf27..e2d31755a 100644 --- a/src/components/graph/GraphCanvas.vue +++ b/src/components/graph/GraphCanvas.vue @@ -142,6 +142,9 @@ import type { LGraphCanvas, LGraphNode } from '@/lib/litegraph/src/litegraph' import { layoutStore } from '@/renderer/core/layout/store/LayoutStore' import { useLayout } from '@/renderer/core/layout/sync/useLayout' import { useLayoutSync } from '@/renderer/core/layout/sync/useLayoutSync' +import { useLinkLayoutSync } from '@/renderer/core/layout/sync/useLinkLayoutSync' +import { useSlotLayoutSync } from '@/renderer/core/layout/sync/useSlotLayoutSync' +import { LayoutSource } from '@/renderer/core/layout/types' import VueGraphNode from '@/renderer/extensions/vueNodes/components/LGraphNode.vue' import { UnauthorizedError, api } from '@/scripts/api' import { app as comfyApp } from '@/scripts/app' @@ -283,6 +286,10 @@ watch(canvasRef, () => { // Vue node lifecycle management - initialize after graph is ready let nodeManager: ReturnType | null = null let cleanupNodeManager: (() => void) | null = null + +// Slot layout sync management +let slotSync: ReturnType | null = null +let linkSync: ReturnType | null = null const vueNodeData = ref>(new Map()) const nodeState = ref>(new Map()) const nodePositions = ref>( @@ -324,15 +331,46 @@ const initializeNodeManager = () => { })) layoutStore.initializeFromLiteGraph(nodes) + // Seed reroutes into the Layout Store so hit-testing uses the new path + for (const reroute of comfyApp.graph.reroutes.values()) { + const [x, y] = reroute.pos + const parent = reroute.parentId ?? undefined + const linkIds = Array.from(reroute.linkIds) + layoutMutations.createReroute(reroute.id, { x, y }, parent, linkIds) + } + + // Seed existing links into the Layout Store (topology only) + for (const link of comfyApp.graph._links.values()) { + layoutMutations.createLink( + link.id, + link.origin_id, + link.origin_slot, + link.target_id, + link.target_slot + ) + } + // Initialize layout sync (one-way: Layout Store → LiteGraph) const { startSync } = useLayoutSync() startSync(canvasStore.canvas) + // Initialize slot layout sync for hit detection + slotSync = useSlotLayoutSync() + if (canvasStore.canvas) { + slotSync.start(canvasStore.canvas as LGraphCanvas) + } + + // Initialize link layout sync for event-driven updates + linkSync = useLinkLayoutSync() + if (canvasStore.canvas) { + linkSync.start(canvasStore.canvas as LGraphCanvas) + } + // Force computed properties to re-evaluate nodeDataTrigger.value++ } -const disposeNodeManager = () => { +const disposeNodeManagerAndSyncs = () => { if (!nodeManager) return try { cleanupNodeManager?.() @@ -341,6 +379,19 @@ const disposeNodeManager = () => { } nodeManager = null cleanupNodeManager = null + + // Clean up slot layout sync + if (slotSync) { + slotSync.stop() + slotSync = null + } + + // Clean up link layout sync + if (linkSync) { + linkSync.stop() + linkSync = null + } + // Reset reactive maps to inert defaults vueNodeData.value = new Map() nodeState.value = new Map() @@ -360,7 +411,7 @@ watch( if (enabled) { initializeNodeManager() } else { - disposeNodeManager() + disposeNodeManagerAndSyncs() } }, { immediate: true } @@ -509,7 +560,7 @@ const handleNodeSelect = (event: PointerEvent, nodeData: VueNodeData) => { // Bring node to front when clicked (similar to LiteGraph behavior) // Skip if node is pinned if (!node.flags?.pinned) { - layoutMutations.setSource('vue') + layoutMutations.setSource(LayoutSource.Vue) layoutMutations.bringNodeToFront(nodeData.id) } node.selected = true @@ -827,5 +878,17 @@ onUnmounted(() => { nodeManager.cleanup() nodeManager = null } + + // Clean up slot layout sync + if (slotSync) { + slotSync.stop() + slotSync = null + } + + // Clean up link layout sync + if (linkSync) { + linkSync.stop() + linkSync = null + } }) diff --git a/src/components/graph/debug/QuadTreeDebugSection.vue b/src/components/graph/debug/QuadTreeDebugSection.vue deleted file mode 100644 index 74d26e946..000000000 --- a/src/components/graph/debug/QuadTreeDebugSection.vue +++ /dev/null @@ -1,112 +0,0 @@ - - - - diff --git a/src/components/graph/debug/QuadTreeVisualization.vue b/src/components/graph/debug/QuadTreeVisualization.vue deleted file mode 100644 index 28ade900d..000000000 --- a/src/components/graph/debug/QuadTreeVisualization.vue +++ /dev/null @@ -1,112 +0,0 @@ - - - - - diff --git a/src/components/graph/vueWidgets/WidgetButton.vue b/src/components/graph/vueWidgets/WidgetButton.vue deleted file mode 100644 index ae8fb7567..000000000 --- a/src/components/graph/vueWidgets/WidgetButton.vue +++ /dev/null @@ -1,43 +0,0 @@ - - - diff --git a/src/components/graph/vueWidgets/WidgetChart.vue b/src/components/graph/vueWidgets/WidgetChart.vue deleted file mode 100644 index 1c40d35a7..000000000 --- a/src/components/graph/vueWidgets/WidgetChart.vue +++ /dev/null @@ -1,78 +0,0 @@ - - - diff --git a/src/components/graph/vueWidgets/WidgetColorPicker.vue b/src/components/graph/vueWidgets/WidgetColorPicker.vue deleted file mode 100644 index 16a3dd374..000000000 --- a/src/components/graph/vueWidgets/WidgetColorPicker.vue +++ /dev/null @@ -1,52 +0,0 @@ - - - - diff --git a/src/components/graph/vueWidgets/WidgetFileUpload.vue b/src/components/graph/vueWidgets/WidgetFileUpload.vue deleted file mode 100644 index e918a4302..000000000 --- a/src/components/graph/vueWidgets/WidgetFileUpload.vue +++ /dev/null @@ -1,324 +0,0 @@ - - - diff --git a/src/components/graph/vueWidgets/WidgetGalleria.vue b/src/components/graph/vueWidgets/WidgetGalleria.vue deleted file mode 100644 index 3603b7ab6..000000000 --- a/src/components/graph/vueWidgets/WidgetGalleria.vue +++ /dev/null @@ -1,123 +0,0 @@ - - - - - diff --git a/src/components/graph/vueWidgets/WidgetImage.vue b/src/components/graph/vueWidgets/WidgetImage.vue deleted file mode 100644 index d7af95cf0..000000000 --- a/src/components/graph/vueWidgets/WidgetImage.vue +++ /dev/null @@ -1,29 +0,0 @@ - - - diff --git a/src/components/graph/vueWidgets/WidgetImageCompare.vue b/src/components/graph/vueWidgets/WidgetImageCompare.vue deleted file mode 100644 index e51413a30..000000000 --- a/src/components/graph/vueWidgets/WidgetImageCompare.vue +++ /dev/null @@ -1,70 +0,0 @@ - - - diff --git a/src/components/graph/vueWidgets/WidgetInputText.vue b/src/components/graph/vueWidgets/WidgetInputText.vue deleted file mode 100644 index 924ce9ee3..000000000 --- a/src/components/graph/vueWidgets/WidgetInputText.vue +++ /dev/null @@ -1,46 +0,0 @@ - - - diff --git a/src/components/graph/vueWidgets/WidgetMarkdown.vue b/src/components/graph/vueWidgets/WidgetMarkdown.vue deleted file mode 100644 index 4749e561c..000000000 --- a/src/components/graph/vueWidgets/WidgetMarkdown.vue +++ /dev/null @@ -1,95 +0,0 @@ -