-
Notifications
You must be signed in to change notification settings - Fork 377
fix Vue node widgets should be in disabled state if their slots are connected with a link #5834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
9318f6f
e0b9095
0e1a753
ba74c66
fdc29cf
cc5a27e
0e89600
07de517
ddbc895
eff8431
3e542a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,7 +13,19 @@ import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2' | |||||||||||||||||||||||
import { useNodeDefStore } from '@/stores/nodeDefStore' | ||||||||||||||||||||||||
import type { WidgetValue } from '@/types/simplifiedWidget' | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
import type { LGraph, LGraphNode } from '../../lib/litegraph/src/litegraph' | ||||||||||||||||||||||||
import type { | ||||||||||||||||||||||||
LGraph, | ||||||||||||||||||||||||
LGraphNode, | ||||||||||||||||||||||||
LGraphTriggerAction, | ||||||||||||||||||||||||
LGraphTriggerEvent, | ||||||||||||||||||||||||
LGraphTriggerParam | ||||||||||||||||||||||||
} from '../../lib/litegraph/src/litegraph' | ||||||||||||||||||||||||
import { NodeSlotType } from '../../lib/litegraph/src/types/globalEnums' | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export interface WidgetSlotMetadata { | ||||||||||||||||||||||||
index: number | ||||||||||||||||||||||||
linked: boolean | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export interface SafeWidgetData { | ||||||||||||||||||||||||
name: string | ||||||||||||||||||||||||
|
@@ -23,6 +35,7 @@ export interface SafeWidgetData { | |||||||||||||||||||||||
options?: Record<string, unknown> | ||||||||||||||||||||||||
callback?: ((value: unknown) => void) | undefined | ||||||||||||||||||||||||
spec?: InputSpec | ||||||||||||||||||||||||
slotMetadata?: WidgetSlotMetadata | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export interface VueNodeData { | ||||||||||||||||||||||||
|
@@ -66,6 +79,22 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { | |||||||||||||||||||||||
// Non-reactive storage for original LiteGraph nodes | ||||||||||||||||||||||||
const nodeRefs = new Map<string, LGraphNode>() | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const refreshNodeSlots = (nodeId: string) => { | ||||||||||||||||||||||||
const nodeRef = nodeRefs.get(nodeId) | ||||||||||||||||||||||||
const currentData = vueNodeData.get(nodeId) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if (!nodeRef || !currentData) return | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const refreshedData = extractVueNodeData(nodeRef) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
vueNodeData.set(nodeId, { | ||||||||||||||||||||||||
...currentData, | ||||||||||||||||||||||||
widgets: refreshedData.widgets, | ||||||||||||||||||||||||
inputs: refreshedData.inputs, | ||||||||||||||||||||||||
outputs: refreshedData.outputs | ||||||||||||||||||||||||
}) | ||||||||||||||||||||||||
|
const refreshedData = extractVueNodeData(nodeRef) | |
vueNodeData.set(nodeId, { | |
...currentData, | |
widgets: refreshedData.widgets, | |
inputs: refreshedData.inputs, | |
outputs: refreshedData.outputs | |
}) | |
const { widgets, inputs, outputs } = extractVueNodeData(nodeRef) | |
vueNodeData.set(nodeId, { ...currentData, widgets, inputs, outputs }) |
This is a sidegrade at best, but... I wanted to see if it would fit. After I checked, the "work" was already done, so please take / discard as you like.
christian-byrne marked this conversation as resolved.
Show resolved
Hide resolved
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2852,7 +2852,17 @@ export class LGraphNode | |
output.links ??= [] | ||
output.links.push(link.id) | ||
// connect in input | ||
inputNode.inputs[inputIndex].link = link.id | ||
const targetInput = inputNode.inputs[inputIndex] | ||
targetInput.link = link.id | ||
if (targetInput.widget) { | ||
graph.trigger('node:slot-links:changed', { | ||
christian-byrne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
nodeId: inputNode.id, | ||
slotType: NodeSlotType.INPUT, | ||
slotIndex: inputIndex, | ||
connected: true, | ||
linkId: link.id | ||
}) | ||
} | ||
|
||
// Reroutes | ||
const reroutes = LLink.getReroutes(graph, link) | ||
|
@@ -3009,6 +3019,15 @@ export class LGraphNode | |
const input = target.inputs[link_info.target_slot] | ||
// remove there | ||
input.link = null | ||
if (input.widget) { | ||
graph.trigger('node:slot-links:changed', { | ||
nodeId: target.id, | ||
slotType: NodeSlotType.INPUT, | ||
slotIndex: link_info.target_slot, | ||
connected: false, | ||
linkId: link_info.id | ||
}) | ||
Comment on lines
+3023
to
+3029
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is the same in all three locations, how would you feel about extracting something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would only be simplified if it were to be made a class instance property of some sort, which would start to go backwards a bit. If it's moved to a more pure helper, then it becomes even more code, I think. Don't see a way to simplify/refactor cleanly. |
||
} | ||
|
||
// remove the link from the links pool | ||
link_info.disconnect(graph, 'input') | ||
|
@@ -3045,6 +3064,15 @@ export class LGraphNode | |
const input = target.inputs[link_info.target_slot] | ||
// remove other side link | ||
input.link = null | ||
if (input.widget) { | ||
graph.trigger('node:slot-links:changed', { | ||
nodeId: target.id, | ||
slotType: NodeSlotType.INPUT, | ||
slotIndex: link_info.target_slot, | ||
connected: false, | ||
linkId: link_info.id | ||
}) | ||
} | ||
|
||
// link_info hasn't been modified so its ok | ||
target.onConnectionsChange?.( | ||
|
@@ -3114,6 +3142,15 @@ export class LGraphNode | |
const link_id = this.inputs[slot].link | ||
if (link_id != null) { | ||
this.inputs[slot].link = null | ||
if (input.widget) { | ||
graph.trigger('node:slot-links:changed', { | ||
nodeId: this.id, | ||
slotType: NodeSlotType.INPUT, | ||
slotIndex: slot, | ||
connected: false, | ||
linkId: link_id | ||
}) | ||
} | ||
|
||
// remove other side | ||
const link_info = graph._links.get(link_id) | ||
|
Uh oh!
There was an error while loading. Please reload this page.