Skip to content

Commit 35c9f2a

Browse files
authored
Merge pull request #1636 from adumesny/develop
collision: fix dragging long items from outside
2 parents d6b3bbc + 74d8b91 commit 35c9f2a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/gridstack-dd.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
107107
node.x = Math.max(0, Math.round(left / cellWidth));
108108
node.y = Math.max(0, Math.round(top / cellHeight));
109109
delete node.autoPosition;
110+
this.engine.nodeBoundFix(node);
110111

111112
// don't accept *initial* location if doesn't fit #1419 (locked drop region, or can't grow), but maybe try if it will go somewhere
112113
if (!this.engine.willItFit(node)) {
@@ -508,13 +509,13 @@ GridStack.prototype._dragOrResize = function(event: Event, ui: DDUIData, node: G
508509
let top = ui.position.top + (ui.position.top > node._lastUiPosition.top ? -this.opts.marginBottom : this.opts.marginTop);
509510
let x = Math.round(left / cellWidth);
510511
let y = Math.round(top / cellHeight);
512+
let w = node.w;
513+
let h = node.h;
511514
if (node._isOutOfGrid) {
512515
// items coming from outside are handled by 'dragout' event instead, so make coordinates fit
513-
x = Math.max(0, x);
514-
y = Math.max(0, y);
516+
let fix = this.engine.nodeBoundFix({x, y, w, h});
517+
x = fix.x; y = fix.y; w = fix.w; h = fix.h;
515518
}
516-
let w = node.w;
517-
let h = node.h;
518519
let resizing: boolean;
519520

520521
if (event.type === 'drag') {

src/gridstack-engine.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ export class GridStackEngine {
315315
if (node.minW) { node.w = Math.max(node.w, node.minW); }
316316
if (node.minH) { node.h = Math.max(node.h, node.minH); }
317317

318+
return this.nodeBoundFix(node, resizing);
319+
}
320+
321+
/** part2 of preparing a node to fit inside our grid - checks for x,y from grid dimensions */
322+
public nodeBoundFix(node: GridStackNode, resizing?: boolean): GridStackNode {
318323
if (node.w > this.column) {
319324
node.w = this.column;
320325
} else if (node.w < 1) {

0 commit comments

Comments
 (0)