mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 06:47:33 +00:00
feat: send onWidgets event
This commit is contained in:
committed by
Alexander Brown
parent
f1856b7a17
commit
f1cb6dad20
@@ -73,6 +73,10 @@ export async function importExtensionsByEvent(event: string) {
|
||||
await Promise.all([...callbacks].map((cb) => cb({ event })))
|
||||
}
|
||||
|
||||
export function extentionsImportEventHas(event: string) {
|
||||
return eventMap.has(event)
|
||||
}
|
||||
|
||||
function onceExtImportEvent(event: string, callback: EventCallback) {
|
||||
if (eventMap.has(event)) {
|
||||
eventMap.get(event)!.add(callback)
|
||||
|
||||
@@ -81,7 +81,6 @@ export function normalizationActivationEvents(
|
||||
|
||||
if (activationEvents.includes('onWidgets:contributes')) {
|
||||
for (const contribute of contributes) {
|
||||
events.push(`onWidgets:${contribute.name}`)
|
||||
if (contribute.widgets) {
|
||||
for (const widget of contribute.widgets) {
|
||||
events.push(`onWidgets:${widget}`)
|
||||
|
||||
@@ -58,10 +58,44 @@ import {
|
||||
import { getOrderedInputSpecs } from '@/workbench/utils/nodeDefOrderingUtil'
|
||||
|
||||
import { useExtensionService } from './extensionService'
|
||||
import {
|
||||
extentionsImportEventHas,
|
||||
importExtensionsByEvent
|
||||
} from '@/extensions/dispatch'
|
||||
|
||||
export const CONFIG = Symbol()
|
||||
export const GET_CONFIG = Symbol()
|
||||
|
||||
function addInputsAndimportWidgetsAsNeeded(options: {
|
||||
orderedInputSpecs: InputSpec[]
|
||||
addInputSocket: (inputSpec: InputSpec) => void
|
||||
addInputWidget: (inputSpec: InputSpec) => void
|
||||
}) {
|
||||
const { orderedInputSpecs, addInputSocket, addInputWidget } = options
|
||||
const awaitedInputSpecs: InputSpec[] = []
|
||||
const syncInputSpecs: InputSpec[] = []
|
||||
const importJobs: Promise<void>[] = []
|
||||
for (const inputSpec of orderedInputSpecs) {
|
||||
const widgetType = inputSpec.widgetType ?? inputSpec.type
|
||||
if (extentionsImportEventHas(`onWidgets:${widgetType}`)) {
|
||||
importJobs.push(importExtensionsByEvent(`onWidgets:${widgetType}`))
|
||||
awaitedInputSpecs.push(inputSpec)
|
||||
} else {
|
||||
syncInputSpecs.push(inputSpec)
|
||||
}
|
||||
}
|
||||
|
||||
;(async () => {
|
||||
await Promise.all(importJobs)
|
||||
for (const inputSpec of awaitedInputSpecs) addInputSocket(inputSpec)
|
||||
for (const inputSpec of awaitedInputSpecs) addInputWidget(inputSpec)
|
||||
})()
|
||||
|
||||
// Create sockets and widgets in the determined order
|
||||
for (const inputSpec of syncInputSpecs) addInputSocket(inputSpec)
|
||||
for (const inputSpec of syncInputSpecs) addInputWidget(inputSpec)
|
||||
}
|
||||
|
||||
/**
|
||||
* Service that augments litegraph with ComfyUI specific functionality.
|
||||
*/
|
||||
@@ -244,12 +278,11 @@ export const useLitegraphService = () => {
|
||||
// Use input_order if available to ensure consistent widget ordering
|
||||
const nodeDefImpl = ComfyNode.nodeData as ComfyNodeDefImpl
|
||||
const orderedInputSpecs = getOrderedInputSpecs(nodeDefImpl, inputs)
|
||||
|
||||
// Create sockets and widgets in the determined order
|
||||
for (const inputSpec of orderedInputSpecs)
|
||||
this.#addInputSocket(inputSpec)
|
||||
for (const inputSpec of orderedInputSpecs)
|
||||
this.#addInputWidget(inputSpec)
|
||||
addInputsAndimportWidgetsAsNeeded({
|
||||
orderedInputSpecs,
|
||||
addInputSocket: this.#addInputSocket.bind(this),
|
||||
addInputWidget: this.#addInputWidget.bind(this)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -521,11 +554,11 @@ export const useLitegraphService = () => {
|
||||
const nodeDefImpl = ComfyNode.nodeData as ComfyNodeDefImpl
|
||||
const orderedInputSpecs = getOrderedInputSpecs(nodeDefImpl, inputs)
|
||||
|
||||
// Create sockets and widgets in the determined order
|
||||
for (const inputSpec of orderedInputSpecs)
|
||||
this.#addInputSocket(inputSpec)
|
||||
for (const inputSpec of orderedInputSpecs)
|
||||
this.#addInputWidget(inputSpec)
|
||||
addInputsAndimportWidgetsAsNeeded({
|
||||
orderedInputSpecs,
|
||||
addInputSocket: this.#addInputSocket.bind(this),
|
||||
addInputWidget: this.#addInputWidget.bind(this)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user