[API] Require always-exported node properties be defined (#821)

Now required:

- `type`
- `pos`
- `size`
- `flags`
- `order`
- `mode`
This commit is contained in:
filtered
2025-03-23 03:25:57 +11:00
committed by GitHub
parent 6380037d1f
commit 0dd060a369
5 changed files with 21 additions and 22 deletions

View File

@@ -659,7 +659,6 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
}
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<SerialisableGraph> {
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

View File

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

View File

@@ -68,7 +68,7 @@ export interface LiteGraphCanvasEvent extends CustomEvent<CanvasEventDetail> {}
export interface LGraphNodeConstructor<T extends LGraphNode = LGraphNode> {
title: string
type?: string
type: string
size?: Size
min_height?: number
slot_start_y?: number

View File

@@ -67,12 +67,12 @@ export type ISerialisableNodeOutput = Omit<INodeOutputSlot, "_layoutElement" | "
export interface ISerialisedNode {
title?: string
id: NodeId
type?: string
pos?: Point
size?: Size
flags?: INodeFlags
order?: number
mode?: number
type: string
pos: Point
size: Size
flags: INodeFlags
order: number
mode: number
outputs?: ISerialisableNodeOutput[]
inputs?: ISerialisableNodeInput[]
properties?: Dictionary<NodeProperty | undefined>

View File

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