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

Skip to content

Commit 6b8c361

Browse files
committed
* when swapping shapes in maxRow grid, make sure we still check for 50% coverage
1 parent e15e52f commit 6b8c361

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Change log
7373

7474
## 6.0.1-dev (TBD)
7575
* fixed [#2034](https://github.com/gridstack/gridstack.js/issues/2034) `removeWidget()` breaking resize handle feedback
76+
* fixed [#2043](https://github.com/gridstack/gridstack.js/issues/2043) when swapping shapes in maxRow grid, make sure we still check for 50% coverage
7677

7778
## 6.0.1 (2022-08-27)
7879
* fixed `float(val)` to set on grid and engine, so save() will read it.

src/dd-resizable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
120120
this.el.removeEventListener('mouseout', this._mouseOut);
121121
if (DDManager.overResizeElement === this) {
122122
delete DDManager.overResizeElement;
123-
}
123+
}
124124
}
125125
return this;
126126
}

src/gridstack-engine.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export class GridStackEngine {
175175
collide = n;
176176
}
177177
});
178+
o.collide = collide; // save it so we don't have to find it again
178179
return collide;
179180
}
180181

@@ -541,12 +542,12 @@ export class GridStackEngine {
541542
});
542543
if (!clonedNode) return false;
543544

544-
// make sure we are still valid size
545-
let canMove = clone.moveNode(clonedNode, o) && clone.getRow() <= this.maxRow;
546-
// turns out we can't grow, then see if we can swap instead (ex: full grid) if we're not resizing
547-
if (!canMove && !o.resizing) {
548-
let collide = this.collide(node, o);
549-
if (collide && this.swap(node, collide)) {
545+
// check if we're covering 50% collision and could move
546+
let canMove = clone.moveNode(clonedNode, o);
547+
// make sure we are still valid grid max, else check if we can force a swap (float=true, or different shapes) on non-resize
548+
if (!o.resizing && canMove && o.collide && this.float && clone.getRow() > this.maxRow) {
549+
let collide = o.collide.el.gridstackNode; // find the source node the clone collided with
550+
if (this.swap(node, collide)) { // swaps and mark dirty
550551
this._notify();
551552
return true;
552553
}

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ export interface GridStackMoveOpts extends GridStackPosition {
253253
rect?: GridStackPosition;
254254
/** true if we're live resizing */
255255
resizing?: boolean;
256+
/** best node (most coverage) we collied with */
257+
collide?: GridStackNode;
256258
}
257259

258260
export interface GridStackPosition {

0 commit comments

Comments
 (0)