From 3277ac1f1682ba4011dc2abd9564b9cbe5723923 Mon Sep 17 00:00:00 2001 From: huchenlei Date: Fri, 6 Dec 2024 17:46:24 -0500 Subject: [PATCH] Add LGraph.empty --- src/LGraph.ts | 10 ++++++++++ src/LGraphCanvas.ts | 13 +++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/LGraph.ts b/src/LGraph.ts index 75e4028..65b522f 100644 --- a/src/LGraph.ts +++ b/src/LGraph.ts @@ -115,6 +115,16 @@ export class LGraph implements LinkNetwork, Serialisable { inputs: Dictionary outputs: Dictionary + /** @returns Whether the graph has no items */ + get empty(): boolean { + return this.positionableItems.length === 0 + } + + /** @returns All items on the canvas that can be selected */ + get positionableItems(): Positionable[] { + return [...this._nodes, ...this._groups, ...this.reroutes.values()] + } + #reroutes = new Map() /** All reroutes in this graph. */ public get reroutes(): Map { diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index eb0772a..77cc394 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -3954,15 +3954,12 @@ export class LGraphCanvas { } } - /** - * @returns All items on the canvas that can be selected - */ + get empty(): boolean { + return this.graph.empty + } + get positionableItems(): Positionable[] { - return [ - ...this.graph._nodes, - ...this.graph._groups, - ...this.graph.reroutes.values(), - ] + return this.graph.positionableItems } /**