@@ -58,10 +58,44 @@ import {
5858import { getOrderedInputSpecs } from '@/workbench/utils/nodeDefOrderingUtil'
5959
6060import { useExtensionService } from './extensionService'
61+ import {
62+ extentionsImportEventHas ,
63+ importExtensionsByEvent
64+ } from '@/extensions/dispatch'
6165
6266export const CONFIG = Symbol ( )
6367export const GET_CONFIG = Symbol ( )
6468
69+ function addInputsAndimportWidgetsAsNeeded ( options : {
70+ orderedInputSpecs : InputSpec [ ]
71+ addInputSocket : ( inputSpec : InputSpec ) => void
72+ addInputWidget : ( inputSpec : InputSpec ) => void
73+ } ) {
74+ const { orderedInputSpecs, addInputSocket, addInputWidget } = options
75+ const awaitedInputSpecs : InputSpec [ ] = [ ]
76+ const syncInputSpecs : InputSpec [ ] = [ ]
77+ const importJobs : Promise < void > [ ] = [ ]
78+ for ( const inputSpec of orderedInputSpecs ) {
79+ const widgetType = inputSpec . widgetType ?? inputSpec . type
80+ if ( extentionsImportEventHas ( `onWidgets:${ widgetType } ` ) ) {
81+ importJobs . push ( importExtensionsByEvent ( `onWidgets:${ widgetType } ` ) )
82+ awaitedInputSpecs . push ( inputSpec )
83+ } else {
84+ syncInputSpecs . push ( inputSpec )
85+ }
86+ }
87+
88+ ; ( async ( ) => {
89+ await Promise . all ( importJobs )
90+ for ( const inputSpec of awaitedInputSpecs ) addInputSocket ( inputSpec )
91+ for ( const inputSpec of awaitedInputSpecs ) addInputWidget ( inputSpec )
92+ } ) ( )
93+
94+ // Create sockets and widgets in the determined order
95+ for ( const inputSpec of syncInputSpecs ) addInputSocket ( inputSpec )
96+ for ( const inputSpec of syncInputSpecs ) addInputWidget ( inputSpec )
97+ }
98+
6599/**
66100 * Service that augments litegraph with ComfyUI specific functionality.
67101 */
@@ -244,12 +278,11 @@ export const useLitegraphService = () => {
244278 // Use input_order if available to ensure consistent widget ordering
245279 const nodeDefImpl = ComfyNode . nodeData as ComfyNodeDefImpl
246280 const orderedInputSpecs = getOrderedInputSpecs ( nodeDefImpl , inputs )
247-
248- // Create sockets and widgets in the determined order
249- for ( const inputSpec of orderedInputSpecs )
250- this . #addInputSocket( inputSpec )
251- for ( const inputSpec of orderedInputSpecs )
252- this . #addInputWidget( inputSpec )
281+ addInputsAndimportWidgetsAsNeeded ( {
282+ orderedInputSpecs,
283+ addInputSocket : this . #addInputSocket. bind ( this ) ,
284+ addInputWidget : this . #addInputWidget. bind ( this )
285+ } )
253286 }
254287
255288 /**
@@ -521,11 +554,11 @@ export const useLitegraphService = () => {
521554 const nodeDefImpl = ComfyNode . nodeData as ComfyNodeDefImpl
522555 const orderedInputSpecs = getOrderedInputSpecs ( nodeDefImpl , inputs )
523556
524- // Create sockets and widgets in the determined order
525- for ( const inputSpec of orderedInputSpecs )
526- this . #addInputSocket( inputSpec )
527- for ( const inputSpec of orderedInputSpecs )
528- this . #addInputWidget ( inputSpec )
557+ addInputsAndimportWidgetsAsNeeded ( {
558+ orderedInputSpecs,
559+ addInputSocket : this . #addInputSocket. bind ( this ) ,
560+ addInputWidget : this . #addInputWidget . bind ( this )
561+ } )
529562 }
530563
531564 /**
0 commit comments