Type serialized NodeSlot (#605)

This commit is contained in:
Chenlei Hu
2025-02-25 19:38:14 -05:00
committed by GitHub
parent dbe016b934
commit 953ae434ea
3 changed files with 14 additions and 5 deletions

View File

@@ -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

View File

@@ -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<T extends INodeSlot>(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) {

View File

@@ -40,6 +40,11 @@ export interface SerialisableGraph {
extra?: Record<any, any>
}
export type ISerialisedNodeInputSlot = Omit<INodeInputSlot, "_layoutElement"> & {
widget?: { name?: string }
}
export type ISerialisedNodeOutputSlot = Omit<INodeOutputSlot, "_layoutElement" | "_data">
/** 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<unknown>
shape?: RenderShape
boxcolor?: string