Skip to content

Commit 586003c

Browse files
authored
Merge pull request #1708 from adumesny/master
collision: final 2 grids with maxRow
2 parents f4e82c0 + 00a8214 commit 586003c

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

demo/two_vertical.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ <h1>Two vertical grids demo - with maxRow</h1>
2828
GridStack.init(opts, document.getElementById('grid1'))
2929
.load([{x:0, y:0, content: '0'}, {x:1, y:0, content: '1'}]);
3030
GridStack.init(opts, document.getElementById('grid2'))
31-
.load([{x:0, y:0, content: '2'}, {x:2, y:0, content: '3'}]);
31+
.load([{x:0, y:0, content: '2'}, {x:1, y:0, content: '3'}]);
3232
</script>
3333
</body>
3434
</html>

doc/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Change log
5454
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
5555
## 4.0.3-dev
5656

57+
- fix [#1687](https://github.com/gridstack/gridstack.js/issues/1687) more fix for drag between 2 grids with `row / maxRow` broken in 4.x
58+
5759
## 4.0.3 (2021-3-28)
5860

5961
- fix [#1693](https://github.com/gridstack/gridstack.js/issues/1693) `load` after `init()` broken in 4.x

src/gridstack-dd.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
103103
GridStackDD.get().off(el, 'drag'); // stop calling us
104104
return; // full grid or can't grow
105105
}
106+
if (node._willFitPos) {
107+
// use the auto position instead #1687
108+
Utils.copyPos(node, node._willFitPos);
109+
delete node._willFitPos;
110+
}
106111
}
107112

108113
// re-use the existing node dragging method

src/gridstack-engine.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ export class GridStackEngine {
540540
if (!canMove) return false;
541541

542542
// if clone was able to move, copy those mods over to us now instead of caller trying to do this all over!
543-
// Note: we can't use the list directly as elements and other parts point to actual node struct, so copy content
543+
// Note: we can't use the list directly as elements and other parts point to actual node, so copy content
544544
clone.nodes.filter(n => n._dirty).forEach(c => {
545545
let n = this.nodes.find(a => a._id === c._id);
546546
if (!n) return;
@@ -553,6 +553,7 @@ export class GridStackEngine {
553553

554554
/** return true if can fit in grid height constrain only (always true if no maxRow) */
555555
public willItFit(node: GridStackNode): boolean {
556+
delete node._willFitPos;
556557
if (!this.maxRow) return true;
557558
// create a clone with NO maxRow and check if still within size
558559
let clone = new GridStackEngine({
@@ -564,7 +565,11 @@ export class GridStackEngine {
564565
this.cleanupNode(n);
565566
delete n.el; delete n._id; delete n.content; delete n.grid;
566567
clone.addNode(n);
567-
return clone.getRow() <= this.maxRow;
568+
if (clone.getRow() <= this.maxRow) {
569+
node._willFitPos = Utils.copyPos({}, n);
570+
return true;
571+
}
572+
return false;
568573
}
569574

570575
/** true if x,y or w,h are different after clamping to min/max */

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ export interface GridStackNode extends GridStackWidget {
342342
_lastUiPosition?: Position;
343343
/** @internal set on the item being dragged/resized remember the last positions we've tried (but failed) so we don't try again during drag/resize */
344344
_lastTried?: GridStackPosition;
345+
/** @internal position willItFit() will use to position the item */
346+
_willFitPos?: GridStackPosition;
345347
/** @internal last drag Y pixel position used to incrementally update V scroll bar */
346348
_prevYPix?: number;
347349
/** @internal true if we've remove the item from ourself (dragging out) but might revert it back (release on nothing -> goes back) */

0 commit comments

Comments
 (0)