mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-26 17:30:07 +00:00
Fix all unknown slot props are serialised (#732)
Ensures only specified properties are cloned for serialisation.
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import type { CanvasColour, Dictionary, INodeInputSlot, INodeOutputSlot, INodeSlot, ISlotType, IWidgetInputSlot, Point } from "./interfaces"
|
||||
import type { CanvasColour, Dictionary, INodeInputSlot, INodeOutputSlot, INodeSlot, ISlotType, IWidgetInputSlot, Point, SharedIntersection } from "./interfaces"
|
||||
import type { LinkId } from "./LLink"
|
||||
import type { IWidget } from "./types/widgets"
|
||||
|
||||
import { LabelPosition, SlotShape, SlotType } from "./draw"
|
||||
import { LiteGraph } from "./litegraph"
|
||||
import { LinkDirection, RenderShape } from "./types/globalEnums"
|
||||
import { ISerialisedNodeOutputSlot } from "./types/serialisation"
|
||||
import { ISerialisedNodeInputSlot } from "./types/serialisation"
|
||||
import { omitBy } from "./utils/object"
|
||||
import { ISerialisableNodeOutput } from "./types/serialisation"
|
||||
import { ISerialisableNodeInput } from "./types/serialisation"
|
||||
|
||||
export interface ConnectionColorContext {
|
||||
default_connection_color: {
|
||||
@@ -31,16 +30,32 @@ interface IDrawOptions {
|
||||
highlight?: boolean
|
||||
}
|
||||
|
||||
export function serializeSlot(slot: INodeInputSlot): ISerialisedNodeInputSlot
|
||||
export function serializeSlot(slot: INodeOutputSlot): ISerialisedNodeOutputSlot
|
||||
export function serializeSlot(slot: INodeInputSlot | INodeOutputSlot): ISerialisedNodeInputSlot | ISerialisedNodeOutputSlot {
|
||||
return omitBy({
|
||||
...slot,
|
||||
_layoutElement: undefined,
|
||||
_data: undefined,
|
||||
pos: isWidgetInputSlot(slot) ? undefined : slot.pos,
|
||||
widget: isWidgetInputSlot(slot) ? { name: slot.widget.name } : undefined,
|
||||
}, value => value === undefined) as ISerialisedNodeInputSlot | ISerialisedNodeOutputSlot
|
||||
type CommonIoSlotProps = SharedIntersection<ISerialisableNodeInput, ISerialisableNodeOutput>
|
||||
|
||||
export function shallowCloneCommonProps(slot: CommonIoSlotProps): CommonIoSlotProps {
|
||||
const { color_off, color_on, dir, label, localized_name, locked, name, nameLocked, removable, shape, type } = slot
|
||||
return { color_off, color_on, dir, label, localized_name, locked, name, nameLocked, removable, shape, type }
|
||||
}
|
||||
|
||||
export function inputAsSerialisable(slot: INodeInputSlot): ISerialisableNodeInput {
|
||||
const widgetInputProps = slot.widget
|
||||
? { widget: { name: slot.widget.name } }
|
||||
: { pos: slot.pos }
|
||||
|
||||
return {
|
||||
...shallowCloneCommonProps(slot),
|
||||
...widgetInputProps,
|
||||
link: slot.link,
|
||||
}
|
||||
}
|
||||
|
||||
export function outputAsSerialisable(slot: INodeOutputSlot): ISerialisableNodeOutput {
|
||||
return {
|
||||
...shallowCloneCommonProps(slot),
|
||||
pos: slot.pos,
|
||||
slot_index: slot.slot_index,
|
||||
links: slot.links,
|
||||
}
|
||||
}
|
||||
|
||||
export function toNodeSlotClass(slot: INodeSlot): NodeSlot {
|
||||
|
||||
Reference in New Issue
Block a user