-
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
Open
christian-byrne
wants to merge
3
commits into
main
Choose a base branch
from
vue-node/instrument-widget-links
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+188
−73
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,7 +13,18 @@ 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, | ||||||
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 +34,7 @@ export interface SafeWidgetData { | |||||
options?: Record<string, unknown> | ||||||
callback?: ((value: unknown) => void) | undefined | ||||||
spec?: InputSpec | ||||||
slotMetadata?: WidgetSlotMetadata | ||||||
} | ||||||
|
||||||
export interface VueNodeData { | ||||||
|
@@ -66,6 +78,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 | ||||||
}) | ||||||
} | ||||||
|
||||||
// Extract safe data from LiteGraph node for Vue consumption | ||||||
const extractVueNodeData = (node: LGraphNode): VueNodeData => { | ||||||
// Determine subgraph ID - null for root graph, string for subgraphs | ||||||
|
@@ -74,6 +102,16 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { | |||||
? String(node.graph.id) | ||||||
: null | ||||||
// Extract safe widget data | ||||||
const slotMetadata = new Map<string, WidgetSlotMetadata>() | ||||||
|
||||||
node.inputs?.forEach((input, index) => { | ||||||
if (!input?.widget?.name) return | ||||||
slotMetadata.set(input.widget.name, { | ||||||
index, | ||||||
linked: input.link != null | ||||||
}) | ||||||
}) | ||||||
|
||||||
const safeWidgets = node.widgets?.map((widget) => { | ||||||
try { | ||||||
// TODO: Use widget.getReactiveData() once TypeScript types are updated | ||||||
|
@@ -90,6 +128,7 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { | |||||
value = widget.options.values[0] | ||||||
} | ||||||
const spec = nodeDefStore.getInputSpecForWidget(node, widget.name) | ||||||
const slotInfo = slotMetadata.get(widget.name) | ||||||
|
||||||
return { | ||||||
name: widget.name, | ||||||
|
@@ -98,7 +137,8 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { | |||||
label: widget.label, | ||||||
options: widget.options ? { ...widget.options } : undefined, | ||||||
callback: widget.callback, | ||||||
spec | ||||||
spec, | ||||||
slotMetadata: slotInfo | ||||||
} | ||||||
} catch (error) { | ||||||
return { | ||||||
|
@@ -405,37 +445,27 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { | |||||
handleNodeRemoved(node, originalOnNodeRemoved) | ||||||
} | ||||||
|
||||||
// Listen for property change events from instrumented nodes | ||||||
graph.onTrigger = (action: string, param: unknown) => { | ||||||
if ( | ||||||
action === 'node:property:changed' && | ||||||
param && | ||||||
typeof param === 'object' | ||||||
) { | ||||||
const event = param as { | ||||||
nodeId: string | number | ||||||
property: string | ||||||
oldValue: unknown | ||||||
newValue: unknown | ||||||
} | ||||||
|
||||||
const nodeId = String(event.nodeId) | ||||||
const triggerHandlers: { | ||||||
[K in LGraphTriggerAction]: (event: LGraphTriggerParam<K>) => void | ||||||
} = { | ||||||
'node:property:changed': (propertyEvent) => { | ||||||
const nodeId = String(propertyEvent.nodeId) | ||||||
const currentData = vueNodeData.get(nodeId) | ||||||
|
||||||
if (currentData) { | ||||||
switch (event.property) { | ||||||
switch (propertyEvent.property) { | ||||||
case 'title': | ||||||
vueNodeData.set(nodeId, { | ||||||
...currentData, | ||||||
title: String(event.newValue) | ||||||
title: String(propertyEvent.newValue) | ||||||
}) | ||||||
break | ||||||
case 'flags.collapsed': | ||||||
vueNodeData.set(nodeId, { | ||||||
...currentData, | ||||||
flags: { | ||||||
...currentData.flags, | ||||||
collapsed: Boolean(event.newValue) | ||||||
collapsed: Boolean(propertyEvent.newValue) | ||||||
} | ||||||
}) | ||||||
break | ||||||
|
@@ -444,63 +474,59 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { | |||||
...currentData, | ||||||
flags: { | ||||||
...currentData.flags, | ||||||
pinned: Boolean(event.newValue) | ||||||
pinned: Boolean(propertyEvent.newValue) | ||||||
} | ||||||
}) | ||||||
break | ||||||
case 'mode': | ||||||
vueNodeData.set(nodeId, { | ||||||
...currentData, | ||||||
mode: typeof event.newValue === 'number' ? event.newValue : 0 | ||||||
mode: | ||||||
typeof propertyEvent.newValue === 'number' | ||||||
? propertyEvent.newValue | ||||||
: 0 | ||||||
}) | ||||||
break | ||||||
case 'color': | ||||||
vueNodeData.set(nodeId, { | ||||||
...currentData, | ||||||
color: | ||||||
typeof event.newValue === 'string' | ||||||
? event.newValue | ||||||
typeof propertyEvent.newValue === 'string' | ||||||
? propertyEvent.newValue | ||||||
: undefined | ||||||
}) | ||||||
break | ||||||
case 'bgcolor': | ||||||
vueNodeData.set(nodeId, { | ||||||
...currentData, | ||||||
bgcolor: | ||||||
typeof event.newValue === 'string' | ||||||
? event.newValue | ||||||
typeof propertyEvent.newValue === 'string' | ||||||
? propertyEvent.newValue | ||||||
: undefined | ||||||
}) | ||||||
} | ||||||
} | ||||||
} else if ( | ||||||
action === 'node:slot-errors:changed' && | ||||||
param && | ||||||
typeof param === 'object' | ||||||
) { | ||||||
const event = param as { nodeId: string | number } | ||||||
const nodeId = String(event.nodeId) | ||||||
const litegraphNode = nodeRefs.get(nodeId) | ||||||
const currentData = vueNodeData.get(nodeId) | ||||||
|
||||||
if (litegraphNode && currentData) { | ||||||
// Re-extract slot data with updated hasErrors properties | ||||||
vueNodeData.set(nodeId, { | ||||||
...currentData, | ||||||
inputs: litegraphNode.inputs | ||||||
? [...litegraphNode.inputs] | ||||||
: undefined, | ||||||
outputs: litegraphNode.outputs | ||||||
? [...litegraphNode.outputs] | ||||||
: undefined | ||||||
}) | ||||||
}, | ||||||
'node:slot-errors:changed': (slotErrorsEvent) => { | ||||||
refreshNodeSlots(String(slotErrorsEvent.nodeId)) | ||||||
}, | ||||||
'node:slot-links:changed': (slotLinksEvent) => { | ||||||
if (slotLinksEvent.slotType === NodeSlotType.INPUT) { | ||||||
refreshNodeSlots(String(slotLinksEvent.nodeId)) | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
// Call original trigger handler if it exists | ||||||
if (originalOnTrigger) { | ||||||
originalOnTrigger(action, param) | ||||||
const isTriggerAction = (value: string): value is LGraphTriggerAction => | ||||||
Object.prototype.hasOwnProperty.call(triggerHandlers, value) | ||||||
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.
Suggested change
|
||||||
|
||||||
graph.onTrigger = (action: string, event: unknown) => { | ||||||
if (isTriggerAction(action)) { | ||||||
const handler = triggerHandlers[action] as (payload: unknown) => void | ||||||
handler(event) | ||||||
} | ||||||
|
||||||
originalOnTrigger?.(action, event) | ||||||
} | ||||||
|
||||||
// Initialize state | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { NodeSlotType } from './globalEnums' | ||
|
||
interface NodePropertyChangedEvent { | ||
nodeId: string | number | ||
property: string | ||
oldValue: unknown | ||
newValue: unknown | ||
} | ||
|
||
interface NodeSlotErrorsChangedEvent { | ||
nodeId: string | number | ||
} | ||
|
||
interface NodeSlotLinksChangedEvent { | ||
nodeId: string | number | ||
slotType: NodeSlotType | ||
slotIndex: number | ||
connected: boolean | ||
linkId: number | ||
} | ||
|
||
type LGraphTriggerEventMap = { | ||
'node:property:changed': NodePropertyChangedEvent | ||
'node:slot-errors:changed': NodeSlotErrorsChangedEvent | ||
'node:slot-links:changed': NodeSlotLinksChangedEvent | ||
} | ||
|
||
export type LGraphTriggerAction = keyof LGraphTriggerEventMap | ||
|
||
export type LGraphTriggerParam<A extends LGraphTriggerAction> = | ||
A extends keyof LGraphTriggerEventMap ? LGraphTriggerEventMap[A] : unknown | ||
|
||
export type LGraphTriggerHandler = { | ||
<A extends LGraphTriggerAction>(action: A, param: LGraphTriggerParam<A>): void | ||
(action: string, param: unknown): void | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.