mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 02:32:18 +00:00
[Type] Add type annotations for widgetInputs litegraph hooks (#2793)
This commit is contained in:
@@ -799,7 +799,10 @@ app.registerExtension({
|
|||||||
// Add menu options to convert to/from widgets
|
// Add menu options to convert to/from widgets
|
||||||
const origGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions
|
const origGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions
|
||||||
// @ts-expect-error adding extra property
|
// @ts-expect-error adding extra property
|
||||||
nodeType.prototype.convertWidgetToInput = function (widget) {
|
nodeType.prototype.convertWidgetToInput = function (
|
||||||
|
this: LGraphNode,
|
||||||
|
widget: IWidget
|
||||||
|
) {
|
||||||
const config = getConfig.call(this, widget.name) ?? [
|
const config = getConfig.call(this, widget.name) ?? [
|
||||||
widget.type,
|
widget.type,
|
||||||
widget.options || {}
|
widget.options || {}
|
||||||
@@ -826,7 +829,11 @@ app.registerExtension({
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeType.prototype.getExtraMenuOptions = function (_, options) {
|
nodeType.prototype.getExtraMenuOptions = function (
|
||||||
|
this: LGraphNode,
|
||||||
|
_,
|
||||||
|
options
|
||||||
|
) {
|
||||||
const r = origGetExtraMenuOptions
|
const r = origGetExtraMenuOptions
|
||||||
? origGetExtraMenuOptions.apply(this, arguments)
|
? origGetExtraMenuOptions.apply(this, arguments)
|
||||||
: undefined
|
: undefined
|
||||||
@@ -909,7 +916,7 @@ app.registerExtension({
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeType.prototype.onGraphConfigured = function () {
|
nodeType.prototype.onGraphConfigured = function (this: LGraphNode) {
|
||||||
if (!this.inputs) return
|
if (!this.inputs) return
|
||||||
this.widgets ??= []
|
this.widgets ??= []
|
||||||
|
|
||||||
@@ -921,7 +928,9 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup old widget config
|
// Cleanup old widget config
|
||||||
|
// @ts-expect-error WidgetRef
|
||||||
if (input.widget.config) {
|
if (input.widget.config) {
|
||||||
|
// @ts-expect-error WidgetRef
|
||||||
if (input.widget.config[0] instanceof Array) {
|
if (input.widget.config[0] instanceof Array) {
|
||||||
// If we are an old converted combo then replace the input type and the stored link data
|
// If we are an old converted combo then replace the input type and the stored link data
|
||||||
input.type = 'COMBO'
|
input.type = 'COMBO'
|
||||||
@@ -931,6 +940,7 @@ app.registerExtension({
|
|||||||
link.type = input.type
|
link.type = input.type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// @ts-expect-error WidgetRef
|
||||||
delete input.widget.config
|
delete input.widget.config
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -938,14 +948,14 @@ app.registerExtension({
|
|||||||
if (w) {
|
if (w) {
|
||||||
hideWidget(this, w)
|
hideWidget(this, w)
|
||||||
} else {
|
} else {
|
||||||
convertToWidget(this, input)
|
convertToWidget(this, w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const origOnNodeCreated = nodeType.prototype.onNodeCreated
|
const origOnNodeCreated = nodeType.prototype.onNodeCreated
|
||||||
nodeType.prototype.onNodeCreated = function () {
|
nodeType.prototype.onNodeCreated = function (this: LGraphNode) {
|
||||||
const r = origOnNodeCreated ? origOnNodeCreated.apply(this) : undefined
|
const r = origOnNodeCreated ? origOnNodeCreated.apply(this) : undefined
|
||||||
|
|
||||||
// When node is created, convert any force/default inputs
|
// When node is created, convert any force/default inputs
|
||||||
@@ -965,7 +975,7 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const origOnConfigure = nodeType.prototype.onConfigure
|
const origOnConfigure = nodeType.prototype.onConfigure
|
||||||
nodeType.prototype.onConfigure = function () {
|
nodeType.prototype.onConfigure = function (this: LGraphNode) {
|
||||||
const r = origOnConfigure
|
const r = origOnConfigure
|
||||||
? origOnConfigure.apply(this, arguments)
|
? origOnConfigure.apply(this, arguments)
|
||||||
: undefined
|
: undefined
|
||||||
@@ -998,7 +1008,10 @@ app.registerExtension({
|
|||||||
// Double click a widget input to automatically attach a primitive
|
// Double click a widget input to automatically attach a primitive
|
||||||
const origOnInputDblClick = nodeType.prototype.onInputDblClick
|
const origOnInputDblClick = nodeType.prototype.onInputDblClick
|
||||||
const ignoreDblClick = Symbol()
|
const ignoreDblClick = Symbol()
|
||||||
nodeType.prototype.onInputDblClick = function (slot) {
|
nodeType.prototype.onInputDblClick = function (
|
||||||
|
this: LGraphNode,
|
||||||
|
slot: number
|
||||||
|
) {
|
||||||
const r = origOnInputDblClick
|
const r = origOnInputDblClick
|
||||||
? origOnInputDblClick.apply(this, arguments)
|
? origOnInputDblClick.apply(this, arguments)
|
||||||
: undefined
|
: undefined
|
||||||
@@ -1043,6 +1056,7 @@ app.registerExtension({
|
|||||||
// Prevent connecting COMBO lists to converted inputs that dont match types
|
// Prevent connecting COMBO lists to converted inputs that dont match types
|
||||||
const onConnectInput = nodeType.prototype.onConnectInput
|
const onConnectInput = nodeType.prototype.onConnectInput
|
||||||
nodeType.prototype.onConnectInput = function (
|
nodeType.prototype.onConnectInput = function (
|
||||||
|
this: LGraphNode,
|
||||||
targetSlot: number,
|
targetSlot: number,
|
||||||
type: string,
|
type: string,
|
||||||
output: INodeOutputSlot,
|
output: INodeOutputSlot,
|
||||||
|
|||||||
Reference in New Issue
Block a user