From 953ae434ea2fd14dd61476843169e0931cdedd46 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Tue, 25 Feb 2025 19:38:14 -0500 Subject: [PATCH] Type serialized NodeSlot (#605) --- src/LGraphNode.ts | 4 ++-- src/NodeSlot.ts | 6 +++++- src/types/serialisation.ts | 9 +++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index 37918c549..51aa1c062 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -707,8 +707,8 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { if (this.constructor === LGraphNode && this.last_serialization) return this.last_serialization - if (this.inputs) o.inputs = this.inputs.map(serializeSlot) - if (this.outputs) o.outputs = this.outputs.map(serializeSlot) + if (this.inputs) o.inputs = this.inputs.map(input => serializeSlot(input)) + if (this.outputs) o.outputs = this.outputs.map(output => serializeSlot(output)) if (this.title && this.title != this.constructor.title) o.title = this.title diff --git a/src/NodeSlot.ts b/src/NodeSlot.ts index d6f9ecd25..3db50f4a7 100644 --- a/src/NodeSlot.ts +++ b/src/NodeSlot.ts @@ -4,6 +4,8 @@ import type { LinkId } from "./LLink" import { LinkDirection, RenderShape } from "./types/globalEnums" import { LabelPosition, SlotShape, SlotType } from "./draw" import { LiteGraph } from "./litegraph" +import { ISerialisedNodeOutputSlot } from "./types/serialisation" +import { ISerialisedNodeInputSlot } from "./types/serialisation" export interface ConnectionColorContext { default_connection_color: { @@ -27,7 +29,9 @@ interface IDrawOptions { highlight?: boolean } -export function serializeSlot(slot: T): T { +export function serializeSlot(slot: INodeInputSlot): ISerialisedNodeInputSlot +export function serializeSlot(slot: INodeOutputSlot): ISerialisedNodeOutputSlot +export function serializeSlot(slot: INodeInputSlot | INodeOutputSlot): ISerialisedNodeInputSlot | ISerialisedNodeOutputSlot { const serialized = { ...slot } delete serialized._layoutElement if ("_data" in serialized) { diff --git a/src/types/serialisation.ts b/src/types/serialisation.ts index 615f551b0..d19fefad0 100644 --- a/src/types/serialisation.ts +++ b/src/types/serialisation.ts @@ -40,6 +40,11 @@ export interface SerialisableGraph { extra?: Record } +export type ISerialisedNodeInputSlot = Omit & { + widget?: { name?: string } +} +export type ISerialisedNodeOutputSlot = Omit + /** Serialised LGraphNode */ export interface ISerialisedNode { title?: string @@ -50,8 +55,8 @@ export interface ISerialisedNode { flags?: INodeFlags order?: number mode?: number - outputs?: INodeOutputSlot[] - inputs?: INodeInputSlot[] + outputs?: ISerialisedNodeOutputSlot[] + inputs?: ISerialisedNodeInputSlot[] properties?: Dictionary shape?: RenderShape boxcolor?: string