diff --git a/src/LGraph.ts b/src/LGraph.ts index b1f7a76e3..c164a6900 100644 --- a/src/LGraph.ts +++ b/src/LGraph.ts @@ -659,7 +659,6 @@ export class LGraph implements LinkNetwork, Serialisable { } ancestors.sort(function (a, b) { - // @ts-expect-error deprecated return a.order - b.order }) return ancestors @@ -1113,12 +1112,10 @@ export class LGraph implements LinkNetwork, Serialisable { checkNodeTypes() { const { _nodes } = this for (const [i, node] of _nodes.entries()) { - // @ts-expect-error deprecated const ctor = LiteGraph.registered_node_types[node.type] if (node.constructor == ctor) continue console.log("node being replaced by newer version:", node.type) - // @ts-expect-error deprecated const newnode = LiteGraph.createNode(node.type) if (!newnode) continue _nodes[i] = newnode diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index f1c158161..3ca7ac10d 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -173,7 +173,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { graph: LGraph | null = null id: NodeId - type: string | null = null + type: string = "" inputs: INodeInputSlot[] = [] outputs: INodeOutputSlot[] = [] // Not used @@ -190,9 +190,9 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { locked?: boolean - // Execution order, automatically computed during run - order?: number - mode?: LGraphEventMode + /** Execution order, automatically computed during run @see {@link LGraph.computeExecutionOrder} */ + order: number = 0 + mode: LGraphEventMode = LGraphEventMode.ALWAYS last_serialization?: ISerialisedNode serialize_widgets?: boolean /** @@ -323,6 +323,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { return this._pos } + /** Node position does not necessarily correlate to the top-left corner. */ public set pos(value) { if (!value || value.length < 2) return @@ -587,9 +588,10 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { overWidget: IWidget, ): boolean | undefined - constructor(title: string) { + constructor(title: string, type?: string) { this.id = LiteGraph.use_uuids ? LiteGraph.uuidv4() : -1 this.title = title || "Unnamed" + this.type = type ?? "" this.size = [LiteGraph.NODE_WIDTH, 60] this.pos = [10, 10] } @@ -690,7 +692,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { // create serialization object const o: ISerialisedNode = { id: this.id, - type: this.type ?? undefined, + type: this.type, pos: [this.pos[0], this.pos[1]], size: [this.size[0], this.size[1]], flags: LiteGraph.cloneObject(this.flags), diff --git a/src/litegraph.ts b/src/litegraph.ts index f166ec10d..8712f53ef 100644 --- a/src/litegraph.ts +++ b/src/litegraph.ts @@ -68,7 +68,7 @@ export interface LiteGraphCanvasEvent extends CustomEvent {} export interface LGraphNodeConstructor { title: string - type?: string + type: string size?: Size min_height?: number slot_start_y?: number diff --git a/src/types/serialisation.ts b/src/types/serialisation.ts index 04aad8c05..809b2c429 100644 --- a/src/types/serialisation.ts +++ b/src/types/serialisation.ts @@ -67,12 +67,12 @@ export type ISerialisableNodeOutput = Omit diff --git a/test/__snapshots__/LGraph.test.ts.snap b/test/__snapshots__/LGraph.test.ts.snap index 567bed734..200fdf69a 100644 --- a/test/__snapshots__/LGraph.test.ts.snap +++ b/test/__snapshots__/LGraph.test.ts.snap @@ -82,7 +82,7 @@ LGraph { }, "locked": undefined, "lostFocusAt": undefined, - "mode": undefined, + "mode": 0, "mouseOver": undefined, "order": 0, "outputs": [], @@ -95,7 +95,7 @@ LGraph { "serialize_widgets": undefined, "showAdvanced": undefined, "title": undefined, - "type": null, + "type": "", "widgets": undefined, "widgets_start_y": undefined, "widgets_up": undefined, @@ -148,7 +148,7 @@ LGraph { }, "locked": undefined, "lostFocusAt": undefined, - "mode": undefined, + "mode": 0, "mouseOver": undefined, "order": 0, "outputs": [], @@ -161,7 +161,7 @@ LGraph { "serialize_widgets": undefined, "showAdvanced": undefined, "title": undefined, - "type": null, + "type": "", "widgets": undefined, "widgets_start_y": undefined, "widgets_up": undefined, @@ -215,7 +215,7 @@ LGraph { }, "locked": undefined, "lostFocusAt": undefined, - "mode": undefined, + "mode": 0, "mouseOver": undefined, "order": 0, "outputs": [], @@ -228,7 +228,7 @@ LGraph { "serialize_widgets": undefined, "showAdvanced": undefined, "title": undefined, - "type": null, + "type": "", "widgets": undefined, "widgets_start_y": undefined, "widgets_up": undefined,