mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-22 15:54:09 +00:00
Serialize NodeInputSlot.widget (#622)
Serialize linked widget on node input slot properly according to current
save format in
76818b54e6/src/extensions/core/widgetInputs.ts
This commit is contained in:
@@ -7,6 +7,7 @@ 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"
|
||||
|
||||
export interface ConnectionColorContext {
|
||||
default_connection_color: {
|
||||
@@ -33,16 +34,13 @@ interface IDrawOptions {
|
||||
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) {
|
||||
delete serialized._data
|
||||
}
|
||||
// Widget input slots' pos is calculated during layout, so we don't need to serialize it.
|
||||
if (isWidgetInputSlot(slot) && "pos" in serialized) {
|
||||
delete serialized.pos
|
||||
}
|
||||
return serialized
|
||||
return omitBy({
|
||||
...slot,
|
||||
_layoutElement: undefined,
|
||||
_data: undefined,
|
||||
pos: isWidgetInputSlot(slot) ? undefined : slot.pos,
|
||||
widget: isWidgetInputSlot(slot) && slot.widget?.name ? { name: slot.widget.name } : undefined,
|
||||
}, value => value === undefined) as ISerialisedNodeInputSlot | ISerialisedNodeOutputSlot
|
||||
}
|
||||
|
||||
export function toNodeSlotClass(slot: INodeSlot): NodeSlot {
|
||||
|
||||
@@ -41,7 +41,7 @@ export interface SerialisableGraph {
|
||||
}
|
||||
|
||||
export type ISerialisedNodeInputSlot = Omit<INodeInputSlot, "_layoutElement"> & {
|
||||
widget?: { name?: string }
|
||||
widget?: { name: string }
|
||||
}
|
||||
export type ISerialisedNodeOutputSlot = Omit<INodeOutputSlot, "_layoutElement" | "_data">
|
||||
|
||||
|
||||
5
src/utils/object.ts
Normal file
5
src/utils/object.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export function omitBy<T extends object>(obj: T, predicate: (value: any) => boolean): Partial<T> {
|
||||
return Object.fromEntries(
|
||||
Object.entries(obj).filter(([_key, value]) => !predicate(value)),
|
||||
) as Partial<T>
|
||||
}
|
||||
Reference in New Issue
Block a user