Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 391b144

Browse files
authored
Merge pull request gridstack#1383 from adumesny/develop
fix two drop shadows
2 parents 5697a98 + d4e1038 commit 391b144

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Change log
4545
- fix nested grid resize [1361](https://github.com/gridstack/gridstack.js/issues/1361)
4646
- fix resize with `cellHeight` '6rem' '6em' not working [1356](https://github.com/gridstack/gridstack.js/issues/1356)
4747
- fix preserve attributes (min/max/id/etc...) when dragging between grids [1367](https://github.com/gridstack/gridstack.js/issues/1367)
48+
- fix 2 drop shadows when dragging between grids [393](https://github.com/gridstack/gridstack.js/issues/393)
4849

4950
## 2.0.0 (2020-09-07)
5051

src/gridstack.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,24 +1238,24 @@ export class GridStack {
12381238
let distance = ui.position.top - node._prevYPix;
12391239
node._prevYPix = ui.position.top;
12401240
Utils.updateScrollPosition(el, ui.position, distance);
1241-
if (el.dataset.inTrashZone || x < 0 || x >= this.engine.column || y < 0 ||
1242-
(!this.engine.float && y > this.engine.getRow())) {
1243-
if (!node._temporaryRemoved) {
1244-
if (this.opts.removable === true) {
1245-
this._setupRemovingTimeout(el);
1246-
}
1247-
1248-
x = node._beforeDragX;
1249-
y = node._beforeDragY;
1241+
// if inTrash, outside of the bounds or added to another grid (#393) temporarily remove it from us
1242+
if (el.dataset.inTrashZone || x < 0 || x >= this.engine.column || y < 0 || (!this.engine.float && y > this.engine.getRow()) || node._added) {
1243+
if (node._temporaryRemoved) { return; }
1244+
if (this.opts.removable === true) {
1245+
this._setupRemovingTimeout(el);
1246+
}
12501247

1251-
if (this.placeholder.parentNode === this.el) { this.el.removeChild(this.placeholder) }
1252-
this.engine.removeNode(node);
1253-
this._updateContainerHeight();
1248+
x = node._beforeDragX;
1249+
y = node._beforeDragY;
12541250

1255-
node._temporaryRemoved = true;
1256-
} else {
1257-
return;
1251+
if (this.placeholder.parentNode === this.el) {
1252+
this.placeholder.remove();
12581253
}
1254+
this.engine.removeNode(node);
1255+
this._updateContainerHeight();
1256+
1257+
node._temporaryRemoved = true;
1258+
delete node._added; // no need for this now
12591259
} else {
12601260
this._clearRemovingTimeout(el);
12611261

@@ -1290,7 +1290,9 @@ export class GridStack {
12901290

12911291
/** called when the item stops moving/resizing */
12921292
let onEndMoving = (event: Event) => {
1293-
if (this.placeholder.parentNode === this.el) { this.el.removeChild(this.placeholder) }
1293+
if (this.placeholder.parentNode === this.el) {
1294+
this.placeholder.remove();
1295+
}
12941296

12951297
// if the item has moved to another grid, we're done here
12961298
let target: GridItemHTMLElement = event.target as GridItemHTMLElement;
@@ -1620,6 +1622,11 @@ export class GridStack {
16201622
if (h > 0) { node.height = h; }
16211623
}
16221624

1625+
// if the item came from another grid, let it know it was added here to removed duplicate shadow #393
1626+
if (node.grid && node.grid !== this) {
1627+
node._added = true;
1628+
}
1629+
16231630
// if not calculate the grid size based on element outer size
16241631
let width = node.width || Math.round(el.offsetWidth / this.cellWidth()) || 1;
16251632
let height = node.height || Math.round(el.offsetHeight / this.getCellHeight(true)) || 1;
@@ -1644,7 +1651,7 @@ export class GridStack {
16441651
node.el = null;
16451652
this.engine.removeNode(node);
16461653
if (this.placeholder.parentNode === this.el) {
1647-
this.el.removeChild(this.placeholder);
1654+
this.placeholder.remove();
16481655
}
16491656
this._updateContainerHeight();
16501657
el.gridstackNode = el._gridstackNodeOrig;

0 commit comments

Comments
 (0)