From 8d13204c6cbec16aad91745eca4aae7d11b79ba9 Mon Sep 17 00:00:00 2001 From: Alain Dumesny Date: Sun, 6 Dec 2020 09:36:16 -0800 Subject: [PATCH] support all options for new dragged in widgets * fix #1472 * dragEnter now loads all widget attributes if we don't have a node (dragged from toolbar) --- demo/two.html | 6 ++---- doc/CHANGES.md | 5 +++++ src/gridstack-dd.ts | 13 +++++-------- src/gridstack.ts | 3 ++- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/demo/two.html b/demo/two.html index a2955e8d5..ad5c9f656 100644 --- a/demo/two.html +++ b/demo/two.html @@ -50,16 +50,14 @@

Two grids demo

diff --git a/doc/CHANGES.md b/doc/CHANGES.md index d01965ea2..b69803772 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -46,7 +46,12 @@ Change log ## 3.1.0-dev - fix [1419](https://github.com/gridstack/gridstack.js/issues/1419) dragging into a fixed row grid works better (check if it will fit, else try to append, else won't insert) +-- **possible BREAK** (unlikely you use engine directly) +* engine constructor takes Options struct rather than spelling arguments (easier to extend/use) +* `canBePlacedWithRespectToHeight()` -> `willItFit()` like grid method + - fix [1330](https://github.com/gridstack/gridstack.js/issues/1330) `maxW` does not work as intended with resizable handle `"w"` +- fix [1472](https://github.com/gridstack/gridstack.js/issues/1472) support all options for new dragged in widgets (read all `gs-xyz` attributes) ## 3.1.0 (2020-12-4) diff --git a/src/gridstack-dd.ts b/src/gridstack-dd.ts index 2f6fb9e08..9d583924d 100644 --- a/src/gridstack-dd.ts +++ b/src/gridstack-dd.ts @@ -130,18 +130,15 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack { }) .on(this.el, 'dropover', (event, el: GridItemHTMLElement) => { // ignore drop enter on ourself, and prevent parent from receiving event - let node = el.gridstackNode || {}; - if (node.grid === this) { + let node = el.gridstackNode; + if (node && node.grid === this) { delete node._added; // reset this to track placeholder again in case we were over other grid #1484 (dropout doesn't always clear) return false; } - // see if we already have a node with widget/height and check for attributes - if (el.getAttribute && (!node.w || !node.h)) { - let w = parseInt(el.getAttribute('gs-w')); - if (w > 0) { node.w = w; } - let h = parseInt(el.getAttribute('gs-h')); - if (h > 0) { node.h = h; } + // load any element attributes if we don't have a node + if (!node) { + node = this._readAttr(el); } // if the item came from another grid, let it know it was added here to removed duplicate shadow #393 diff --git a/src/gridstack.ts b/src/gridstack.ts index 6620597ea..004463a14 100644 --- a/src/gridstack.ts +++ b/src/gridstack.ts @@ -1307,7 +1307,8 @@ export class GridStack { } /** @internal call to read any default attributes from element */ - private _readAttr(el: HTMLElement, node: GridStackNode = {}): GridStackWidget { + private _readAttr(el: HTMLElement): GridStackWidget { + let node: GridStackNode = {}; node.x = Utils.toNumber(el.getAttribute('gs-x')); node.y = Utils.toNumber(el.getAttribute('gs-y')); node.w = Utils.toNumber(el.getAttribute('gs-w'));