mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 10:42:44 +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 })))
|
await Promise.all([...callbacks].map((cb) => cb({ event })))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function extentionsImportEventHas(event: string) {
|
||||||
|
return eventMap.has(event)
|
||||||
|
}
|
||||||
|
|
||||||
function onceExtImportEvent(event: string, callback: EventCallback) {
|
function onceExtImportEvent(event: string, callback: EventCallback) {
|
||||||
if (eventMap.has(event)) {
|
if (eventMap.has(event)) {
|
||||||
eventMap.get(event)!.add(callback)
|
eventMap.get(event)!.add(callback)
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ export function normalizationActivationEvents(
|
|||||||
|
|
||||||
if (activationEvents.includes('onWidgets:contributes')) {
|
if (activationEvents.includes('onWidgets:contributes')) {
|
||||||
for (const contribute of contributes) {
|
for (const contribute of contributes) {
|
||||||
events.push(`onWidgets:${contribute.name}`)
|
|
||||||
if (contribute.widgets) {
|
if (contribute.widgets) {
|
||||||
for (const widget of contribute.widgets) {
|
for (const widget of contribute.widgets) {
|
||||||
events.push(`onWidgets:${widget}`)
|
events.push(`onWidgets:${widget}`)
|
||||||
|
|||||||
@@ -58,10 +58,44 @@ import {
|
|||||||
import { getOrderedInputSpecs } from '@/workbench/utils/nodeDefOrderingUtil'
|
import { getOrderedInputSpecs } from '@/workbench/utils/nodeDefOrderingUtil'
|
||||||
|
|
||||||
import { useExtensionService } from './extensionService'
|
import { useExtensionService } from './extensionService'
|
||||||
|
import {
|
||||||
|
extentionsImportEventHas,
|
||||||
|
importExtensionsByEvent
|
||||||
|
} from '@/extensions/dispatch'
|
||||||
|
|
||||||
export const CONFIG = Symbol()
|
export const CONFIG = Symbol()
|
||||||
export const GET_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.
|
* 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
|
// Use input_order if available to ensure consistent widget ordering
|
||||||
const nodeDefImpl = ComfyNode.nodeData as ComfyNodeDefImpl
|
const nodeDefImpl = ComfyNode.nodeData as ComfyNodeDefImpl
|
||||||
const orderedInputSpecs = getOrderedInputSpecs(nodeDefImpl, inputs)
|
const orderedInputSpecs = getOrderedInputSpecs(nodeDefImpl, inputs)
|
||||||
|
addInputsAndimportWidgetsAsNeeded({
|
||||||
// Create sockets and widgets in the determined order
|
orderedInputSpecs,
|
||||||
for (const inputSpec of orderedInputSpecs)
|
addInputSocket: this.#addInputSocket.bind(this),
|
||||||
this.#addInputSocket(inputSpec)
|
addInputWidget: this.#addInputWidget.bind(this)
|
||||||
for (const inputSpec of orderedInputSpecs)
|
})
|
||||||
this.#addInputWidget(inputSpec)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -521,11 +554,11 @@ export const useLitegraphService = () => {
|
|||||||
const nodeDefImpl = ComfyNode.nodeData as ComfyNodeDefImpl
|
const nodeDefImpl = ComfyNode.nodeData as ComfyNodeDefImpl
|
||||||
const orderedInputSpecs = getOrderedInputSpecs(nodeDefImpl, inputs)
|
const orderedInputSpecs = getOrderedInputSpecs(nodeDefImpl, inputs)
|
||||||
|
|
||||||
// Create sockets and widgets in the determined order
|
addInputsAndimportWidgetsAsNeeded({
|
||||||
for (const inputSpec of orderedInputSpecs)
|
orderedInputSpecs,
|
||||||
this.#addInputSocket(inputSpec)
|
addInputSocket: this.#addInputSocket.bind(this),
|
||||||
for (const inputSpec of orderedInputSpecs)
|
addInputWidget: this.#addInputWidget.bind(this)
|
||||||
this.#addInputWidget(inputSpec)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user