@@ -79,10 +79,64 @@ export interface GraphNodeManager {
7979 cleanup ( ) : void
8080}
8181
82+ export function safeWidgetMapper (
83+ node : LGraphNode ,
84+ slotMetadata : Map < string , WidgetSlotMetadata >
85+ ) : ( widget : IBaseWidget ) => SafeWidgetData {
86+ const nodeDefStore = useNodeDefStore ( )
87+ return function ( widget ) {
88+ try {
89+ // TODO: Use widget.getReactiveData() once TypeScript types are updated
90+ let value = widget . value
91+
92+ // For combo widgets, if value is undefined, use the first option as default
93+ if (
94+ value === undefined &&
95+ widget . type === 'combo' &&
96+ widget . options ?. values &&
97+ Array . isArray ( widget . options . values ) &&
98+ widget . options . values . length > 0
99+ ) {
100+ value = widget . options . values [ 0 ]
101+ }
102+ const spec = nodeDefStore . getInputSpecForWidget ( node , widget . name )
103+ const slotInfo = slotMetadata . get ( widget . name )
104+
105+ return {
106+ name : widget . name ,
107+ type : widget . type ,
108+ value : value ,
109+ label : widget . label ,
110+ options : widget . options ? { ...widget . options } : undefined ,
111+ callback : widget . callback ,
112+ spec,
113+ slotMetadata : slotInfo ,
114+ isDOMWidget : isDOMWidget ( widget )
115+ }
116+ } catch ( error ) {
117+ return {
118+ name : widget . name || 'unknown' ,
119+ type : widget . type || 'text' ,
120+ value : undefined
121+ }
122+ }
123+ }
124+ }
125+
126+ export function isValidWidgetValue ( value : unknown ) : value is WidgetValue {
127+ return (
128+ value === null ||
129+ value === undefined ||
130+ typeof value === 'string' ||
131+ typeof value === 'number' ||
132+ typeof value === 'boolean' ||
133+ typeof value === 'object'
134+ )
135+ }
136+
82137export function useGraphNodeManager ( graph : LGraph ) : GraphNodeManager {
83138 // Get layout mutations composable
84139 const { createNode, deleteNode, setSource } = useLayoutMutations ( )
85- const nodeDefStore = useNodeDefStore ( )
86140 // Safe reactive data extracted from LiteGraph nodes
87141 const vueNodeData = reactive ( new Map < string , VueNodeData > ( ) )
88142
@@ -148,45 +202,7 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager {
148202 linked : input . link != null
149203 } )
150204 } )
151- return (
152- node . widgets ?. map ( ( widget ) => {
153- try {
154- // TODO: Use widget.getReactiveData() once TypeScript types are updated
155- let value = widget . value
156-
157- // For combo widgets, if value is undefined, use the first option as default
158- if (
159- value === undefined &&
160- widget . type === 'combo' &&
161- widget . options ?. values &&
162- Array . isArray ( widget . options . values ) &&
163- widget . options . values . length > 0
164- ) {
165- value = widget . options . values [ 0 ]
166- }
167- const spec = nodeDefStore . getInputSpecForWidget ( node , widget . name )
168- const slotInfo = slotMetadata . get ( widget . name )
169-
170- return {
171- name : widget . name ,
172- type : widget . type ,
173- value : value ,
174- label : widget . label ,
175- options : widget . options ? { ...widget . options } : undefined ,
176- callback : widget . callback ,
177- spec,
178- slotMetadata : slotInfo ,
179- isDOMWidget : isDOMWidget ( widget )
180- }
181- } catch ( error ) {
182- return {
183- name : widget . name || 'unknown' ,
184- type : widget . type || 'text' ,
185- value : undefined
186- }
187- }
188- } ) ?? [ ]
189- )
205+ return node . widgets ?. map ( safeWidgetMapper ( node , slotMetadata ) ) ?? [ ]
190206 } )
191207
192208 const nodeType =
0 commit comments