Add support for LiteGraph to convert to classes (#334)

* Add support for LiteGraph to convert to classes

* Fix large context menu search regression

* Remove debug code

* Fix regression from rename & prototype change

* Fix super() calls to match LGraphNode
This commit is contained in:
filtered
2024-08-11 23:46:54 +10:00
committed by GitHub
parent 0f3b58b610
commit e2141a81e2
7 changed files with 49 additions and 37 deletions

View File

@@ -1983,8 +1983,15 @@ export class ComfyApp {
async registerNodeDef(nodeId: string, nodeData: ComfyNodeDef) {
const self = this
const node = Object.assign(
function ComfyNode() {
const node = class ComfyNode extends LGraphNode {
static comfyClass? = nodeData.name
// TODO: change to "title?" once litegraph.d.ts has been updated
static title = nodeData.display_name || nodeData.name
static nodeData? = nodeData
static category?: string
constructor(title?: string) {
super(title)
var inputs = nodeData['input']['required']
if (nodeData['input']['optional'] != undefined) {
inputs = Object.assign(
@@ -2050,13 +2057,9 @@ export class ComfyApp {
this.serialize_widgets = true
app.#invokeExtensionsAsync('nodeCreated', this)
},
{
title: nodeData.display_name || nodeData.name,
comfyClass: nodeData.name,
nodeData
}
)
}
// @ts-expect-error
node.prototype.comfyClass = nodeData.name
this.#addNodeContextMenuHandler(node)
@@ -2064,9 +2067,7 @@ export class ComfyApp {
this.#addNodeKeyHandler(node)
await this.#invokeExtensionsAsync('beforeRegisterNodeDef', node, nodeData)
// @ts-expect-error
LiteGraph.registerNodeType(nodeId, node)
// @ts-expect-error
node.category = nodeData.category
}

View File

@@ -254,7 +254,6 @@ export function addDomClippingSetting(): void {
})
}
//@ts-ignore
LGraphNode.prototype.addDOMWidget = function (
name: string,
type: string,