Remove broken/unused widget[TARGET] (#2795)

This commit is contained in:
Chenlei Hu
2025-03-01 21:26:50 -05:00
committed by GitHub
parent ba2797c332
commit f5c21814f9
2 changed files with 12 additions and 44 deletions

View File

@@ -144,7 +144,6 @@ app.registerExtension({
const color = LGraphCanvas.link_type_colors[displayType] const color = LGraphCanvas.link_type_colors[displayType]
let widgetConfig let widgetConfig
let targetWidget
let widgetType let widgetType
// Update the types of each node // Update the types of each node
for (const node of updateNodes) { for (const node of updateNodes) {
@@ -171,11 +170,6 @@ app.registerExtension({
widgetConfig = config[1] ?? {} widgetConfig = config[1] ?? {}
widgetType = config[0] widgetType = config[0]
} }
if (!targetWidget) {
targetWidget = targetNode.widgets?.find(
(w) => w.name === (targetInput.widget as any).name
)
}
const merged = mergeIfValid(targetInput, [ const merged = mergeIfValid(targetInput, [
config[0], config[0],
@@ -192,11 +186,10 @@ app.registerExtension({
for (const node of updateNodes) { for (const node of updateNodes) {
if (widgetConfig && outputType) { if (widgetConfig && outputType) {
node.inputs[0].widget = { name: 'value' } node.inputs[0].widget = { name: 'value' }
setWidgetConfig( setWidgetConfig(node.inputs[0], [
node.inputs[0], widgetType ?? displayType,
[widgetType ?? displayType, widgetConfig], widgetConfig
targetWidget ])
)
} else { } else {
setWidgetConfig(node.inputs[0], null) setWidgetConfig(node.inputs[0], null)
} }

View File

@@ -33,7 +33,6 @@ const VALID_TYPES = [
] ]
const CONFIG = Symbol() const CONFIG = Symbol()
const GET_CONFIG = Symbol() const GET_CONFIG = Symbol()
const TARGET = Symbol() // Used for reroutes to specify the real target widget
const replacePropertyName = 'Run widget replace on values' const replacePropertyName = 'Run widget replace on values'
export class PrimitiveNode extends LGraphNode { export class PrimitiveNode extends LGraphNode {
@@ -54,22 +53,8 @@ export class PrimitiveNode extends LGraphNode {
applyToGraph(extraLinks: LLink[] = []) { applyToGraph(extraLinks: LLink[] = []) {
if (!this.outputs[0].links?.length) return if (!this.outputs[0].links?.length) return
function get_links(node: LGraphNode): number[] {
let links: number[] = []
for (const l of node.outputs[0].links) {
const linkInfo = app.graph.links[l]
const n = node.graph.getNodeById(linkInfo.target_id)
if (n.type == 'Reroute') {
links = links.concat(get_links(n))
} else {
links.push(l)
}
}
return links
}
let links = [ let links = [
...get_links(this).map((l) => app.graph.links[l]), ...this.outputs[0].links.map((l) => app.graph.links[l]),
...extraLinks ...extraLinks
] ]
let v = this.widgets?.[0].value let v = this.widgets?.[0].value
@@ -82,13 +67,9 @@ export class PrimitiveNode extends LGraphNode {
const node = this.graph.getNodeById(linkInfo.target_id) const node = this.graph.getNodeById(linkInfo.target_id)
const input = node.inputs[linkInfo.target_slot] const input = node.inputs[linkInfo.target_slot]
let widget: IWidget | undefined let widget: IWidget | undefined
if (input.widget[TARGET]) { const widgetName = (input.widget as { name: string }).name
widget = input.widget[TARGET] if (widgetName) {
} else { widget = node.widgets.find((w) => w.name === widgetName)
const widgetName = (input.widget as { name: string }).name
if (widgetName) {
widget = node.widgets.find((w) => w.name === widgetName)
}
} }
if (widget) { if (widget) {
@@ -221,8 +202,7 @@ export class PrimitiveNode extends LGraphNode {
widget[CONFIG] ?? config, widget[CONFIG] ?? config,
theirNode, theirNode,
widget.name, widget.name,
recreating, recreating
widget[TARGET]
) )
} }
@@ -230,8 +210,7 @@ export class PrimitiveNode extends LGraphNode {
inputData: InputSpec, inputData: InputSpec,
node: LGraphNode, node: LGraphNode,
widgetName: string, widgetName: string,
recreating: boolean, recreating: boolean
targetWidget: IWidget | undefined
) { ) {
let type = inputData[0] let type = inputData[0]
@@ -249,9 +228,7 @@ export class PrimitiveNode extends LGraphNode {
widget = this.addWidget(type, 'value', null, () => {}, {}) widget = this.addWidget(type, 'value', null, () => {}, {})
} }
if (targetWidget) { if (node?.widgets && widget) {
widget.value = targetWidget.value
} else if (node?.widgets && widget) {
const theirWidget = node.widgets.find((w) => w.name === widgetName) const theirWidget = node.widgets.find((w) => w.name === widgetName)
if (theirWidget) { if (theirWidget) {
widget.value = theirWidget.value widget.value = theirWidget.value
@@ -596,13 +573,11 @@ function isValidCombo(combo: string[], obj: unknown) {
export function setWidgetConfig( export function setWidgetConfig(
slot: INodeInputSlot | INodeOutputSlot, slot: INodeInputSlot | INodeOutputSlot,
config: InputSpec, config: InputSpec
target?: IWidget
) { ) {
if (!slot.widget) return if (!slot.widget) return
if (config) { if (config) {
slot.widget[GET_CONFIG] = () => config slot.widget[GET_CONFIG] = () => config
slot.widget[TARGET] = target
} else { } else {
delete slot.widget delete slot.widget
} }