From 1842aa0dfe30a55515ffc5ee742452cbcf035416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Fekete?= Date: Wed, 13 Sep 2023 22:09:11 +0200 Subject: [PATCH] Remove added node from layout cache on drop event --- src/gridstack-engine.ts | 11 +++++++++++ src/gridstack.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/src/gridstack-engine.ts b/src/gridstack-engine.ts index 876f24583..fae180a16 100644 --- a/src/gridstack-engine.ts +++ b/src/gridstack-engine.ts @@ -958,6 +958,17 @@ export class GridStackEngine { return this._layouts?.[column]?.findIndex(l => l._id === n._id) ?? -1; } + public removeNodeFromLayoutCache(n: GridStackNode) { + if (!this._layouts) { + return; + } + for (let i = 0; i < this._layouts.length; i++) { + let index = this.findCacheLayout(n, i); + if (index !== -1) { + this._layouts[i].splice(index, 1); + } + } + } /** called to remove all internal values but the _id */ public cleanupNode(node: GridStackNode): GridStackEngine { diff --git a/src/gridstack.ts b/src/gridstack.ts index 62e127224..366fc316d 100644 --- a/src/gridstack.ts +++ b/src/gridstack.ts @@ -2135,6 +2135,7 @@ export class GridStack { this._updateContainerHeight(); this.engine.addedNodes.push(node);// @ts-ignore this._triggerAddEvent();// @ts-ignore + this.engine.removeNodeFromLayoutCache(node); this._triggerChangeEvent(); this.engine.endUpdate();