mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 18:52:19 +00:00
[backport core/1.33] Remove app.graph usage from widgetInput code (#7010)
Backport of #7008 to `core/1.33` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7010-backport-core-1-33-Remove-app-graph-usage-from-widgetInput-code-2b86d73d3650811f9da1c5869f352e10) by [Unito](https://www.unito.io) Co-authored-by: AustinMroz <austin@comfy.org>
This commit is contained in:
@@ -7,9 +7,9 @@ import type {
|
|||||||
INodeInputSlot,
|
INodeInputSlot,
|
||||||
INodeOutputSlot,
|
INodeOutputSlot,
|
||||||
ISlotType,
|
ISlotType,
|
||||||
LLink,
|
LLink
|
||||||
Point
|
|
||||||
} from '@/lib/litegraph/src/litegraph'
|
} from '@/lib/litegraph/src/litegraph'
|
||||||
|
import { NodeSlot } from '@/lib/litegraph/src/node/NodeSlot'
|
||||||
import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events'
|
import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events'
|
||||||
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
|
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
|
||||||
import type { InputSpec } from '@/schemas/nodeDefSchema'
|
import type { InputSpec } from '@/schemas/nodeDefSchema'
|
||||||
@@ -37,15 +37,15 @@ export class PrimitiveNode extends LGraphNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override applyToGraph(extraLinks: LLink[] = []) {
|
override applyToGraph(extraLinks: LLink[] = []) {
|
||||||
if (!this.outputs[0].links?.length) return
|
if (!this.outputs[0].links?.length || !this.graph) return
|
||||||
|
|
||||||
const links = [
|
const links = [
|
||||||
...this.outputs[0].links.map((l) => app.graph.links[l]),
|
...this.outputs[0].links.map((l) => this.graph!.links[l]),
|
||||||
...extraLinks
|
...extraLinks
|
||||||
]
|
]
|
||||||
let v = this.widgets?.[0].value
|
let v = this.widgets?.[0].value
|
||||||
if (v && this.properties[replacePropertyName]) {
|
if (v && this.properties[replacePropertyName]) {
|
||||||
v = applyTextReplacements(app.graph, v as string)
|
v = applyTextReplacements(this.graph, v as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// For each output link copy our value over the original widget value
|
// For each output link copy our value over the original widget value
|
||||||
@@ -331,13 +331,13 @@ export class PrimitiveNode extends LGraphNode {
|
|||||||
const config1 = (output.widget?.[GET_CONFIG] as () => InputSpec)?.()
|
const config1 = (output.widget?.[GET_CONFIG] as () => InputSpec)?.()
|
||||||
if (!config1) return
|
if (!config1) return
|
||||||
const isNumber = config1[0] === 'INT' || config1[0] === 'FLOAT'
|
const isNumber = config1[0] === 'INT' || config1[0] === 'FLOAT'
|
||||||
if (!isNumber) return
|
if (!isNumber || !this.graph) return
|
||||||
|
|
||||||
for (const linkId of links) {
|
for (const linkId of links) {
|
||||||
const link = app.graph.links[linkId]
|
const link = this.graph.links[linkId]
|
||||||
if (!link) continue // Can be null when removing a node
|
if (!link) continue // Can be null when removing a node
|
||||||
|
|
||||||
const theirNode = app.graph.getNodeById(link.target_id)
|
const theirNode = this.graph.getNodeById(link.target_id)
|
||||||
if (!theirNode) continue
|
if (!theirNode) continue
|
||||||
const theirInput = theirNode.inputs[link.target_slot]
|
const theirInput = theirNode.inputs[link.target_slot]
|
||||||
|
|
||||||
@@ -441,10 +441,7 @@ function getWidgetType(config: InputSpec) {
|
|||||||
return { type }
|
return { type }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setWidgetConfig(
|
export function setWidgetConfig(slot: INodeInputSlot, config?: InputSpec) {
|
||||||
slot: INodeInputSlot | INodeOutputSlot,
|
|
||||||
config?: InputSpec
|
|
||||||
) {
|
|
||||||
if (!slot.widget) return
|
if (!slot.widget) return
|
||||||
if (config) {
|
if (config) {
|
||||||
slot.widget[GET_CONFIG] = () => config
|
slot.widget[GET_CONFIG] = () => config
|
||||||
@@ -452,19 +449,18 @@ export function setWidgetConfig(
|
|||||||
delete slot.widget
|
delete slot.widget
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('link' in slot) {
|
if (!(slot instanceof NodeSlot)) return
|
||||||
const link = app.graph.links[slot.link ?? -1]
|
const graph = slot.node.graph
|
||||||
if (link) {
|
if (!graph) return
|
||||||
const originNode = app.graph.getNodeById(link.origin_id)
|
const link = graph.links[slot.link ?? -1]
|
||||||
if (originNode && isPrimitiveNode(originNode)) {
|
if (!link) return
|
||||||
if (config) {
|
const originNode = graph.getNodeById(link.origin_id)
|
||||||
originNode.recreateWidget()
|
if (!originNode || !isPrimitiveNode(originNode)) return
|
||||||
} else if (!app.configuringGraph) {
|
if (config) {
|
||||||
originNode.disconnectOutput(0)
|
originNode.recreateWidget()
|
||||||
originNode.onLastDisconnect()
|
} else if (!app.configuringGraph) {
|
||||||
}
|
originNode.disconnectOutput(0)
|
||||||
}
|
originNode.onLastDisconnect()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,15 +551,6 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
function isNodeAtPos(pos: Point) {
|
|
||||||
for (const n of app.graph.nodes) {
|
|
||||||
if (n.pos[0] === pos[0] && n.pos[1] === pos[1]) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
||||||
nodeType.prototype.onInputDblClick = function (
|
nodeType.prototype.onInputDblClick = function (
|
||||||
@@ -589,18 +576,18 @@ app.registerExtension({
|
|||||||
|
|
||||||
// Create a primitive node
|
// Create a primitive node
|
||||||
const node = LiteGraph.createNode('PrimitiveNode')
|
const node = LiteGraph.createNode('PrimitiveNode')
|
||||||
if (!node) return r
|
const graph = app.canvas.graph
|
||||||
|
if (!node || !graph) return r
|
||||||
|
|
||||||
this.graph?.add(node)
|
graph?.add(node)
|
||||||
|
|
||||||
// Calculate a position that won't directly overlap another node
|
// Calculate a position that won't directly overlap another node
|
||||||
const pos: [number, number] = [
|
const pos: [number, number] = [
|
||||||
this.pos[0] - node.size[0] - 30,
|
this.pos[0] - node.size[0] - 30,
|
||||||
this.pos[1]
|
this.pos[1]
|
||||||
]
|
]
|
||||||
while (isNodeAtPos(pos)) {
|
while (graph.getNodeOnPos(pos[0], pos[1], graph.nodes))
|
||||||
pos[1] += LiteGraph.NODE_TITLE_HEIGHT
|
pos[1] += LiteGraph.NODE_TITLE_HEIGHT
|
||||||
}
|
|
||||||
|
|
||||||
node.pos = pos
|
node.pos = pos
|
||||||
node.connect(0, this, slot)
|
node.connect(0, this, slot)
|
||||||
|
|||||||
Reference in New Issue
Block a user