From df569d375a256c83065f6fb09bbf0b18fabe5b53 Mon Sep 17 00:00:00 2001 From: Muhamad Ilyas Mustafa Date: Thu, 2 May 2024 09:22:12 +0700 Subject: [PATCH 1/2] fix issue on failed drag, shouldn't throw an error --- src/gridstack.ts | 2 +- src/utils.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gridstack.ts b/src/gridstack.ts index dd37a7f54..2839ebf57 100644 --- a/src/gridstack.ts +++ b/src/gridstack.ts @@ -2251,8 +2251,8 @@ export class GridStack { if (wasAdded) { this.engine.cleanupNode(node); // removes all internal _xyz values node.grid = this; + delete node.grid._isTemp; } - delete node.grid._isTemp; dd.off(el, 'drag'); // if we made a copy ('helper' which is temp) of the original node then insert a copy, else we move the original node (#1102) // as the helper will be nuked by jquery-ui otherwise. TODO: update old code path diff --git a/src/utils.ts b/src/utils.ts index e4bd6787f..22eaa88fe 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -111,9 +111,9 @@ export class Utils { /** true if we should resize to content. strict=true when only 'sizeToContent:true' and not a number which lets user adjust */ static shouldSizeToContent(n: GridStackNode | undefined, strict = false): boolean { - return n?.grid && (strict ? - (n.sizeToContent === true || (n.grid.opts.sizeToContent === true && n.sizeToContent === undefined)) : - (!!n.sizeToContent || (n.grid.opts.sizeToContent && n.sizeToContent !== false))); + return n?.grid && (strict ? + (n.sizeToContent === true || (n.grid.opts.sizeToContent === true && n.sizeToContent === undefined)) : + (!!n.sizeToContent || (n.grid.opts.sizeToContent && n.sizeToContent !== false))); } /** returns true if a and b overlap */ From 2b0146c1554398e79177cf99c1b978d89c8fe786 Mon Sep 17 00:00:00 2001 From: Muhamad Ilyas Mustafa Date: Tue, 14 May 2024 10:40:56 +0700 Subject: [PATCH 2/2] move the code to orinal position, use optional chaining instead --- src/gridstack.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gridstack.ts b/src/gridstack.ts index 2839ebf57..52e95249a 100644 --- a/src/gridstack.ts +++ b/src/gridstack.ts @@ -2251,8 +2251,8 @@ export class GridStack { if (wasAdded) { this.engine.cleanupNode(node); // removes all internal _xyz values node.grid = this; - delete node.grid._isTemp; } + delete node.grid?._isTemp; dd.off(el, 'drag'); // if we made a copy ('helper' which is temp) of the original node then insert a copy, else we move the original node (#1102) // as the helper will be nuked by jquery-ui otherwise. TODO: update old code path