Manage widget definitions with Pinia store (#1510)

* Fix compile

* nit

* Remove extensions.test

* nit
This commit is contained in:
Chenlei Hu
2024-11-11 17:23:52 -05:00
committed by GitHub
parent 64ef0f18b1
commit 1ff6e27d9c
12 changed files with 111 additions and 269 deletions

View File

@@ -1,6 +1,10 @@
// @ts-strict-ignore
import { ComfyLogging } from './logging'
import { ComfyWidgetConstructor, ComfyWidgets, initWidgets } from './widgets'
import {
type ComfyWidgetConstructor,
ComfyWidgets,
initWidgets
} from './widgets'
import { ComfyUI, $el } from './ui'
import { api } from './api'
import { defaultGraph } from './defaultGraph'
@@ -60,6 +64,7 @@ import { useCommandStore } from '@/stores/commandStore'
import { shallowReactive } from 'vue'
import { type IBaseWidget } from '@comfyorg/litegraph/dist/types/widgets'
import { workflowService } from '@/services/workflowService'
import { useWidgetStore } from '@/stores/widgetStore'
export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview'
@@ -142,7 +147,6 @@ export class ComfyApp {
storageLocation: StorageLocation
multiUserServer: boolean
ctx: CanvasRenderingContext2D
widgets: Record<string, ComfyWidgetConstructor>
bodyTop: HTMLElement
bodyLeft: HTMLElement
bodyRight: HTMLElement
@@ -167,6 +171,16 @@ export class ComfyApp {
return useWorkspaceStore().shiftDown
}
/**
* @deprecated Use useWidgetStore().widgets instead
*/
get widgets(): Record<string, ComfyWidgetConstructor> {
if (this.vueAppReady) {
return useWidgetStore().widgets
}
return ComfyWidgets
}
constructor() {
this.vueAppReady = false
this.ui = new ComfyUI(this)
@@ -1551,10 +1565,7 @@ export class ComfyApp {
}
const node = this.graph.getNodeById(detail.display_node || detail.node)
if (node) {
// @ts-expect-error
if (node.onExecuted)
// @ts-expect-error
node.onExecuted(detail.output)
if (node.onExecuted) node.onExecuted(detail.output)
}
})
@@ -1653,7 +1664,6 @@ export class ComfyApp {
app.graph.onConfigure = function () {
// Fire callbacks before the onConfigure, this is used by widget inputs to setup the config
for (const node of app.graph.nodes) {
// @ts-expect-error
node.onGraphConfigured?.()
}
@@ -1920,7 +1930,6 @@ export class ComfyApp {
const nodeDefArray: ComfyNodeDef[] = Object.values(allNodeDefs)
this.#invokeExtensions('beforeRegisterVueAppNodeDefs', nodeDefArray, this)
nodeDefStore.updateNodeDefs(nodeDefArray)
nodeDefStore.widgets = this.widgets
}
/**
@@ -1938,7 +1947,11 @@ export class ComfyApp {
}
}
getWidgetType(inputData, inputName) {
/**
* Remove the impl after groupNode jest tests are removed.
* @deprecated Use useWidgetStore().getWidgetType instead
*/
getWidgetType(inputData, inputName: string) {
const type = inputData[0]
if (Array.isArray(type)) {
@@ -2092,13 +2105,6 @@ export class ComfyApp {
async registerNodesFromDefs(defs: Record<string, ComfyNodeDef>) {
await this.#invokeExtensionsAsync('addCustomNodeDefs', defs)
// Generate list of known widgets
this.widgets = Object.assign(
{},
ComfyWidgets,
...(await this.#invokeExtensionsAsync('getCustomWidgets')).filter(Boolean)
)
// Register a node for each definition
for (const nodeId in defs) {
this.registerNodeDef(nodeId, defs[nodeId])

View File

@@ -268,7 +268,7 @@ LGraphNode.prototype.addDOMWidget = function (
name: string,
type: string,
element: HTMLElement,
options: Record<string, any>
options: Record<string, any> = {}
): DOMWidget {
options = { hideOnZoom: true, selectOn: ['focus', 'click'], ...options }

View File

@@ -2,10 +2,11 @@
import { api } from './api'
import './domWidget'
import type { ComfyApp } from './app'
import type { IWidget, LGraphNode } from '@comfyorg/litegraph'
import type { LGraphNode } from '@comfyorg/litegraph'
import { InputSpec } from '@/types/apiTypes'
import { useSettingStore } from '@/stores/settingStore'
import { useToastStore } from '@/stores/toastStore'
import type { IWidget } from '@comfyorg/litegraph'
export type ComfyWidgetConstructor = (
node: LGraphNode,