Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/two_vertical.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h1>Two vertical grids demo - with maxRow</h1>
GridStack.init(opts, document.getElementById('grid1'))
.load([{x:0, y:0, content: '0'}, {x:1, y:0, content: '1'}]);
GridStack.init(opts, document.getElementById('grid2'))
.load([{x:0, y:0, content: '2'}, {x:2, y:0, content: '3'}]);
.load([{x:0, y:0, content: '2'}, {x:1, y:0, content: '3'}]);
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Change log
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## 4.0.3-dev

- fix [#1687](https://github.com/gridstack/gridstack.js/issues/1687) more fix for drag between 2 grids with `row / maxRow` broken in 4.x

## 4.0.3 (2021-3-28)

- fix [#1693](https://github.com/gridstack/gridstack.js/issues/1693) `load` after `init()` broken in 4.x
Expand Down
5 changes: 5 additions & 0 deletions src/gridstack-dd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
GridStackDD.get().off(el, 'drag'); // stop calling us
return; // full grid or can't grow
}
if (node._willFitPos) {
// use the auto position instead #1687
Utils.copyPos(node, node._willFitPos);
delete node._willFitPos;
}
}

// re-use the existing node dragging method
Expand Down
9 changes: 7 additions & 2 deletions src/gridstack-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export class GridStackEngine {
if (!canMove) return false;

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

/** return true if can fit in grid height constrain only (always true if no maxRow) */
public willItFit(node: GridStackNode): boolean {
delete node._willFitPos;
if (!this.maxRow) return true;
// create a clone with NO maxRow and check if still within size
let clone = new GridStackEngine({
Expand All @@ -564,7 +565,11 @@ export class GridStackEngine {
this.cleanupNode(n);
delete n.el; delete n._id; delete n.content; delete n.grid;
clone.addNode(n);
return clone.getRow() <= this.maxRow;
if (clone.getRow() <= this.maxRow) {
node._willFitPos = Utils.copyPos({}, n);
return true;
}
return false;
}

/** true if x,y or w,h are different after clamping to min/max */
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ export interface GridStackNode extends GridStackWidget {
_lastUiPosition?: Position;
/** @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 */
_lastTried?: GridStackPosition;
/** @internal position willItFit() will use to position the item */
_willFitPos?: GridStackPosition;
/** @internal last drag Y pixel position used to incrementally update V scroll bar */
_prevYPix?: number;
/** @internal true if we've remove the item from ourself (dragging out) but might revert it back (release on nothing -> goes back) */
Expand Down