From 1a482d750bed96ebb22ad7b5d63e079a7fd3a717 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Tue, 11 Mar 2025 03:05:06 +1100 Subject: [PATCH] [TMP] Support downstream output widget in serialisation (#735) - Ref: https://github.com/Comfy-Org/litegraph.js/pull/732#issuecomment-2710796369 --- src/NodeSlot.ts | 22 +++++++++++++++------- src/types/serialisation.ts | 4 +++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/NodeSlot.ts b/src/NodeSlot.ts index 71f61322c..263d6cd00 100644 --- a/src/NodeSlot.ts +++ b/src/NodeSlot.ts @@ -38,23 +38,31 @@ export function shallowCloneCommonProps(slot: CommonIoSlotProps): CommonIoSlotPr } export function inputAsSerialisable(slot: INodeInputSlot): ISerialisableNodeInput { - const widgetInputProps = slot.widget + const { link } = slot + const widgetOrPos = slot.widget ? { widget: { name: slot.widget.name } } : { pos: slot.pos } return { ...shallowCloneCommonProps(slot), - ...widgetInputProps, - link: slot.link, + ...widgetOrPos, + link, } } -export function outputAsSerialisable(slot: INodeOutputSlot): ISerialisableNodeOutput { +export function outputAsSerialisable(slot: INodeOutputSlot & { widget?: IWidget }): ISerialisableNodeOutput { + const { pos, slot_index, links, widget } = slot + // Output widgets do not exist in Litegraph; this is a temporary downstream workaround. + const outputWidget = widget + ? { widget: { name: widget.name } } + : null + return { ...shallowCloneCommonProps(slot), - pos: slot.pos, - slot_index: slot.slot_index, - links: slot.links, + ...outputWidget, + pos, + slot_index, + links, } } diff --git a/src/types/serialisation.ts b/src/types/serialisation.ts index 5a27258e3..a46033136 100644 --- a/src/types/serialisation.ts +++ b/src/types/serialisation.ts @@ -43,7 +43,9 @@ export interface SerialisableGraph { export type ISerialisableNodeInput = Omit & { widget?: { name: string } } -export type ISerialisableNodeOutput = Omit +export type ISerialisableNodeOutput = Omit & { + widget?: { name: string } +} /** Serialised LGraphNode */ export interface ISerialisedNode {