mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-22 15:29:44 +00:00
Move widget link drop conversion to widgetInputs (#2001)
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
@@ -3,8 +3,13 @@ import { ComfyWidgets, addValueControlWidgets } from '../../scripts/widgets'
|
||||
import { app } from '../../scripts/app'
|
||||
import { applyTextReplacements } from '../../scripts/utils'
|
||||
import { LiteGraph, LGraphNode } from '@comfyorg/litegraph'
|
||||
import type { INodeInputSlot, IWidget } from '@comfyorg/litegraph'
|
||||
import type {
|
||||
INodeInputSlot,
|
||||
IWidget,
|
||||
LiteGraphCanvasEvent
|
||||
} from '@comfyorg/litegraph'
|
||||
import type { InputSpec } from '@/types/apiTypes'
|
||||
import { useNodeDefStore } from '@/stores/nodeDefStore'
|
||||
|
||||
const CONVERTED_TYPE = 'converted-widget'
|
||||
const VALID_TYPES = [
|
||||
@@ -721,6 +726,40 @@ app.registerExtension({
|
||||
defaultValue: true
|
||||
})
|
||||
},
|
||||
setup() {
|
||||
app.canvas.getWidgetLinkType = function (widget, node) {
|
||||
const nodeDefStore = useNodeDefStore()
|
||||
const nodeDef = nodeDefStore.nodeDefsByName[node.type]
|
||||
const input = nodeDef.inputs.getInput(widget.name)
|
||||
return input?.type
|
||||
}
|
||||
|
||||
document.addEventListener(
|
||||
'litegraph:canvas',
|
||||
async (e: LiteGraphCanvasEvent) => {
|
||||
if (e.detail.subType === 'connectingWidgetLink') {
|
||||
const { node, link, widget } = e.detail
|
||||
if (!node || !link || !widget) return
|
||||
|
||||
const nodeData = node.constructor.nodeData
|
||||
if (!nodeData) return
|
||||
const all = {
|
||||
...nodeData?.input?.required,
|
||||
...nodeData?.input?.optional
|
||||
}
|
||||
const inputSpec = all[widget.name]
|
||||
if (!inputSpec) return
|
||||
|
||||
const input = convertToInput(node, widget, inputSpec)
|
||||
if (!input) return
|
||||
|
||||
const originNode = link.node
|
||||
|
||||
originNode.connect(link.slot, node, node.inputs.lastIndexOf(input))
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
// Add menu options to convert to/from widgets
|
||||
const origGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions
|
||||
|
||||
Reference in New Issue
Block a user