1
1
import { createSharedComposable } from '@vueuse/core'
2
- import { readonly , ref , shallowRef , watch } from 'vue'
2
+ import { shallowRef , watch } from 'vue'
3
3
4
4
import { useGraphNodeManager } from '@/composables/graph/useGraphNodeManager'
5
- import type {
6
- GraphNodeManager ,
7
- VueNodeData
8
- } from '@/composables/graph/useGraphNodeManager'
5
+ import type { GraphNodeManager } from '@/composables/graph/useGraphNodeManager'
9
6
import { useVueFeatureFlags } from '@/composables/useVueFeatureFlags'
10
7
import type { LGraphCanvas , LGraphNode } from '@/lib/litegraph/src/litegraph'
11
8
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
@@ -22,31 +19,19 @@ function useVueNodeLifecycleIndividual() {
22
19
const { shouldRenderVueNodes } = useVueFeatureFlags ( )
23
20
24
21
const nodeManager = shallowRef < GraphNodeManager | null > ( null )
25
- const cleanupNodeManager = shallowRef < ( ( ) => void ) | null > ( null )
26
22
27
- // Sync management
28
- const slotSync = shallowRef < ReturnType < typeof useSlotLayoutSync > | null > ( null )
29
- const slotSyncStarted = ref ( false )
30
- const linkSync = shallowRef < ReturnType < typeof useLinkLayoutSync > | null > ( null )
31
-
32
- // Vue node data state
33
- const vueNodeData = ref < ReadonlyMap < string , VueNodeData > > ( new Map ( ) )
34
-
35
- // Trigger for forcing computed re-evaluation
36
- const nodeDataTrigger = ref ( 0 )
23
+ const { startSync } = useLayoutSync ( )
24
+ const linkSyncManager = useLinkLayoutSync ( )
25
+ const slotSyncManager = useSlotLayoutSync ( )
37
26
38
27
const initializeNodeManager = ( ) => {
39
28
// Use canvas graph if available (handles subgraph contexts), fallback to app graph
40
- const activeGraph = comfyApp . canvas ?. graph || comfyApp . graph
29
+ const activeGraph = comfyApp . canvas ?. graph
41
30
if ( ! activeGraph || nodeManager . value ) return
42
31
43
32
// Initialize the core node manager
44
33
const manager = useGraphNodeManager ( activeGraph )
45
34
nodeManager . value = manager
46
- cleanupNodeManager . value = manager . cleanup
47
-
48
- // Use the manager's data maps
49
- vueNodeData . value = manager . vueNodeData
50
35
51
36
// Initialize layout system with existing nodes from active graph
52
37
const nodes = activeGraph . _nodes . map ( ( node : LGraphNode ) => ( {
@@ -76,46 +61,29 @@ function useVueNodeLifecycleIndividual() {
76
61
}
77
62
78
63
// Initialize layout sync (one-way: Layout Store → LiteGraph)
79
- const { startSync } = useLayoutSync ( )
80
64
startSync ( canvasStore . canvas )
81
65
82
- // Initialize link layout sync for event-driven updates
83
- const linkSyncManager = useLinkLayoutSync ( )
84
- linkSync . value = linkSyncManager
85
66
if ( comfyApp . canvas ) {
86
67
linkSyncManager . start ( comfyApp . canvas )
87
68
}
88
-
89
- // Force computed properties to re-evaluate
90
- nodeDataTrigger . value ++
91
69
}
92
70
93
71
const disposeNodeManagerAndSyncs = ( ) => {
94
72
if ( ! nodeManager . value ) return
95
73
96
74
try {
97
- cleanupNodeManager . value ?. ( )
75
+ nodeManager . value . cleanup ( )
98
76
} catch {
99
77
/* empty */
100
78
}
101
79
nodeManager . value = null
102
- cleanupNodeManager . value = null
103
-
104
- // Clean up link layout sync
105
- if ( linkSync . value ) {
106
- linkSync . value . stop ( )
107
- linkSync . value = null
108
- }
109
80
110
- // Reset reactive maps to clean state
111
- vueNodeData . value = new Map ( )
81
+ linkSyncManager . stop ( )
112
82
}
113
83
114
84
// Watch for Vue nodes enabled state changes
115
85
watch (
116
- ( ) =>
117
- shouldRenderVueNodes . value &&
118
- Boolean ( comfyApp . canvas ?. graph || comfyApp . graph ) ,
86
+ ( ) => shouldRenderVueNodes . value && Boolean ( comfyApp . canvas ?. graph ) ,
119
87
( enabled ) => {
120
88
if ( enabled ) {
121
89
initializeNodeManager ( )
@@ -138,47 +106,42 @@ function useVueNodeLifecycleIndividual() {
138
106
}
139
107
140
108
// Switching to Vue
141
- if ( vueMode && slotSyncStarted . value ) {
142
- slotSync . value ?. stop ( )
143
- slotSyncStarted . value = false
109
+ if ( vueMode ) {
110
+ slotSyncManager . stop ( )
144
111
}
145
112
146
113
// Switching to LG
147
114
const shouldRun = Boolean ( canvas ?. graph ) && ! vueMode
148
- if ( shouldRun && ! slotSyncStarted . value && canvas ) {
149
- // Initialize slot sync if not already created
150
- if ( ! slotSync . value ) {
151
- slotSync . value = useSlotLayoutSync ( )
152
- }
153
- const started = slotSync . value . attemptStart ( canvas as LGraphCanvas )
154
- slotSyncStarted . value = started
115
+ if ( shouldRun && canvas ) {
116
+ slotSyncManager . attemptStart ( canvas as LGraphCanvas )
155
117
}
156
118
} ,
157
119
{ immediate : true }
158
120
)
159
121
160
122
// Handle case where Vue nodes are enabled but graph starts empty
161
123
const setupEmptyGraphListener = ( ) => {
124
+ const activeGraph = comfyApp . canvas ?. graph
162
125
if (
163
- shouldRenderVueNodes . value &&
164
- comfyApp . graph &&
165
- ! nodeManager . value &&
166
- comfyApp . graph . _nodes . length === 0
126
+ ! shouldRenderVueNodes . value ||
127
+ nodeManager . value ||
128
+ activeGraph ?. _nodes . length !== 0
167
129
) {
168
- const originalOnNodeAdded = comfyApp . graph . onNodeAdded
169
- comfyApp . graph . onNodeAdded = function ( node : LGraphNode ) {
170
- // Restore original handler
171
- comfyApp . graph . onNodeAdded = originalOnNodeAdded
172
-
173
- // Initialize node manager if needed
174
- if ( shouldRenderVueNodes . value && ! nodeManager . value ) {
175
- initializeNodeManager ( )
176
- }
177
-
178
- // Call original handler
179
- if ( originalOnNodeAdded ) {
180
- originalOnNodeAdded . call ( this , node )
181
- }
130
+ return
131
+ }
132
+ const originalOnNodeAdded = activeGraph . onNodeAdded
133
+ activeGraph . onNodeAdded = function ( node : LGraphNode ) {
134
+ // Restore original handler
135
+ activeGraph . onNodeAdded = originalOnNodeAdded
136
+
137
+ // Initialize node manager if needed
138
+ if ( shouldRenderVueNodes . value && ! nodeManager . value ) {
139
+ initializeNodeManager ( )
140
+ }
141
+
142
+ // Call original handler
143
+ if ( originalOnNodeAdded ) {
144
+ originalOnNodeAdded . call ( this , node )
182
145
}
183
146
}
184
147
}
@@ -189,20 +152,12 @@ function useVueNodeLifecycleIndividual() {
189
152
nodeManager . value . cleanup ( )
190
153
nodeManager . value = null
191
154
}
192
- if ( slotSyncStarted . value ) {
193
- slotSync . value ?. stop ( )
194
- slotSyncStarted . value = false
195
- }
196
- slotSync . value = null
197
- if ( linkSync . value ) {
198
- linkSync . value . stop ( )
199
- linkSync . value = null
200
- }
155
+ slotSyncManager . stop ( )
156
+ linkSyncManager . stop ( )
201
157
}
202
158
203
159
return {
204
- vueNodeData,
205
- nodeManager : readonly ( nodeManager ) ,
160
+ nodeManager,
206
161
207
162
// Lifecycle methods
208
163
initializeNodeManager,
0 commit comments