Skip to content

Commit f4a8e6b

Browse files
committed
collide: dragging from outside fix
* ran into inf loop when dragging from outside
1 parent 691cca1 commit f4a8e6b

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/gridstack-dd.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
165165
let h = node.h || Math.round(el.offsetHeight / this.getCellHeight(true)) || 1;
166166

167167
// copy the node original values (min/max/id/etc...) but override width/height/other flags which are this grid specific
168-
let newNode = this.engine.prepareNode({...node, ...{w, h, _added: false, _temporary: true}});
169-
newNode._isOutOfGrid = true;
168+
let newNode = this.engine.prepareNode({...node, ...{w, h, _added: false, _temporary: true, _isOutOfGrid: true}});
170169
el.gridstackNode = newNode;
171170
el._gridstackNodeOrig = node;
172171

src/gridstack-engine.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ export class GridStackEngine {
8484

8585
let didMove = false;
8686
let newOpt: GridStackMoveOpts = {nested: true, pack: false, sanitize: false};
87-
while (collide = collide || this.collide(node, nn)) { // we could start colliding more than 1 item... so repeat for each
87+
while (collide = collide || this.collide(node, nn)) { // could collide with more than 1 item... so repeat for each
8888
let moved: boolean;
89-
// if colliding with locked item, OR moving down to a different sized item (not handle with swap) that could take our place, move ourself past instead
89+
// if colliding with locked item, OR moving down to a different sized item
90+
// (not handled with swap) that could take our place, move ourself past it instead
91+
// but remember that skip down so we only do this one (and push others otherwise).
9092
if (collide.locked || (node._moving && !node._skipDown && nn.y > node.y &&
9193
!this.float && !this.collide(collide, {...collide, y: node.y}, node)) &&
9294
Utils.isIntercepted(collide, {x: node.x-0.5, y: node.y-0.5, w: node.w+1, h: node.h+1})) {
@@ -96,7 +98,7 @@ export class GridStackEngine {
9698
if (collide.locked && moved) {
9799
Utils.copyPos(nn, node); // moving after lock become our new desired location
98100
} else if (moved && opt.pack && !collide.locked) {
99-
// we moved after and are will pack, do it now and keep the original drop location to see what else we might push way
101+
// we moved after and will pack: do it now and keep the original drop location to see what else we might push way
100102
this._packNodes();
101103
}
102104
didMove = didMove || moved;
@@ -534,10 +536,11 @@ export class GridStackEngine {
534536

535537
/** true if x,y or w,h are different after clamping to min/max */
536538
public changedPosConstrain(node: GridStackNode, p: GridStackPosition): boolean {
537-
if (node.x !== p.x || node.y !== p.y) return true;
538-
// check constrained w,h
539+
// make sure w,h are set
539540
p.w = p.w || node.w;
540541
p.h = p.h || node.h;
542+
if (node.x !== p.x || node.y !== p.y) return true;
543+
// check constrained w,h
541544
if (node.maxW) { p.w = Math.min(p.w, node.maxW); }
542545
if (node.maxH) { p.h = Math.min(p.h, node.maxH); }
543546
if (node.minW) { p.w = Math.max(p.w, node.minW); }

0 commit comments

Comments
 (0)