Skip to content

Commit

Permalink
fix to drag between 2 grids and back
Browse files Browse the repository at this point in the history
* fix for gridstack#1484, introduced in 2.0.1
* make sure we reset _added flag when leaving other grid and we get back
  • Loading branch information
adumesny committed Nov 27, 2020
1 parent 4933987 commit fe2e173
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Change log

- we now have a React example, in addition to Vue - Angular is next!. thanks [@eloparco](https://github.com/eloparco)
- fix placeholder not having custom `GridStackOptions.itemClass`. thanks [@pablosichert](https://github.com/pablosichert)
- fix [1484](https://github.com/gridstack/gridstack.js/issues/1484) draging between 2 grids and back (regression in 2.0.1)
- del `ddPlugin` grid option as we only have one drag&drop plugin at runtime, which is defined by the include you use (HTML5 vs jquery vs none)

## 2.2.0 (2020-11-7)
Expand Down
17 changes: 13 additions & 4 deletions src/gridstack-dd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
}
})
.on(this.el, 'dropover', (event, el: GridItemHTMLElement) => {
// ignore dropping on ourself, and prevent parent from receiving event
// ignore drop enter on ourself, and prevent parent from receiving event
let node = el.gridstackNode || {};
if (node.grid === this) { return false; }
if (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.width || !node.height)) {
Expand Down Expand Up @@ -151,12 +154,18 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
return false; // prevent parent from receiving msg (which may be grid as well)
})
.on(this.el, 'dropout', (event, el: GridItemHTMLElement) => {
let node = el.gridstackNode;
if (!node) { return; }

// clear any added flag now that we are leaving #1484
delete node._added;

// jquery-ui bug. Must verify widget is being dropped out
// check node variable that gets set when widget is out of grid
let node = el.gridstackNode;
if (!node || !node._isOutOfGrid) {
if (!node._isOutOfGrid) {
return;
}

GridStackDD.get().off(el, 'drag');
node.el = null;
this.engine.removeNode(node);
Expand Down

0 comments on commit fe2e173

Please sign in to comment.