mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-26 01:34:07 +00:00
Add widget to node with missing definition (#3291)
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
60
src/scripts/errorNodeWidgets.ts
Normal file
60
src/scripts/errorNodeWidgets.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { IWidget, LGraphNode } from '@comfyorg/litegraph'
|
||||
|
||||
import { useChainCallback } from '@/composables/functional/useChainCallback'
|
||||
import { useBooleanWidget } from '@/composables/widgets/useBooleanWidget'
|
||||
import { useFloatWidget } from '@/composables/widgets/useFloatWidget'
|
||||
import { useStringWidget } from '@/composables/widgets/useStringWidget'
|
||||
|
||||
const StringWidget = useStringWidget()
|
||||
const FloatWidget = useFloatWidget()
|
||||
const BooleanWidget = useBooleanWidget()
|
||||
|
||||
function addWidgetFromValue(node: LGraphNode, value: unknown) {
|
||||
let widget: IWidget
|
||||
|
||||
if (typeof value === 'string') {
|
||||
widget = StringWidget(node, {
|
||||
type: 'STRING',
|
||||
name: 'UNKNOWN',
|
||||
multiline: value.length > 20
|
||||
})
|
||||
} else if (typeof value === 'number') {
|
||||
widget = FloatWidget(node, {
|
||||
type: 'FLOAT',
|
||||
name: 'UNKNOWN'
|
||||
})
|
||||
} else if (typeof value === 'boolean') {
|
||||
widget = BooleanWidget(node, {
|
||||
type: 'BOOLEAN',
|
||||
name: 'UNKNOWN'
|
||||
})
|
||||
} else {
|
||||
console.warn(`Unknown value type: ${typeof value}`)
|
||||
return
|
||||
}
|
||||
|
||||
widget.value = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Try add widgets to node with missing definition.
|
||||
*/
|
||||
LGraphNode.prototype.onConfigure = useChainCallback(
|
||||
LGraphNode.prototype.onConfigure,
|
||||
function (this: LGraphNode, info) {
|
||||
if (!this.has_errors || !info.widgets_values) return
|
||||
|
||||
/**
|
||||
* Note: Some custom nodes overrides the `widgets_values` property to an
|
||||
* object that has `length` property and index access. It is not safe to call
|
||||
* any array methods on it.
|
||||
* See example in https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite/blob/8629188458dc6cb832f871ece3bd273507e8a766/web/js/VHS.core.js#L59-L84
|
||||
*/
|
||||
for (let i = 0; i < info.widgets_values.length; i++) {
|
||||
const widgetValue = info.widgets_values[i]
|
||||
addWidgetFromValue(this, widgetValue)
|
||||
}
|
||||
|
||||
this.serialize_widgets = true
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user