@@ -81,7 +81,7 @@ export class GridStackEngine {
8181 nn = { x : 0 , y : node . y , w : this . column , h : node . h } ;
8282 }
8383 while ( true ) {
84- let collisionNode = this . nodes . find ( n => n !== node && Utils . isIntercepted ( n , nn ) , { node : node , nn : nn } ) ;
84+ let collisionNode = this . collide ( node , nn ) ;
8585 if ( ! collisionNode ) return this ;
8686 let moved ;
8787 if ( collisionNode . locked ) {
@@ -96,12 +96,14 @@ export class GridStackEngine {
9696 }
9797 }
9898
99+ /** return any intercepted node with the given area, skipping the passed in node (usually self) */
100+ public collide ( node : GridStackNode , area : GridStackNode = node ) : GridStackNode {
101+ return this . nodes . find ( n => n !== node && Utils . isIntercepted ( n , area ) ) ;
102+ }
103+
99104 public isAreaEmpty ( x : number , y : number , w : number , h : number ) : boolean {
100105 let nn : GridStackNode = { x : x || 0 , y : y || 0 , w : w || 1 , h : h || 1 } ;
101- let collisionNode = this . nodes . find ( n => {
102- return Utils . isIntercepted ( n , nn ) ;
103- } ) ;
104- return ! collisionNode ;
106+ return ! this . collide ( nn ) ;
105107 }
106108
107109 /** re-layout grid items to reclaim any empty space */
@@ -153,9 +155,7 @@ export class GridStackEngine {
153155 let newY = n . y ;
154156 while ( newY >= n . _packY ) {
155157 let box : GridStackWidget = { x : n . x , y : newY , w : n . w , h : n . h } ;
156- let collisionNode = this . nodes
157- . slice ( 0 , i )
158- . find ( bn => Utils . isIntercepted ( box , bn ) , { n : n , newY : newY } ) ;
158+ let collisionNode = this . nodes . slice ( 0 , i ) . find ( bn => Utils . isIntercepted ( box , bn ) ) ;
159159 if ( ! collisionNode ) {
160160 n . _dirty = true ;
161161 n . y = newY ;
@@ -171,10 +171,8 @@ export class GridStackEngine {
171171 let canBeMoved = i === 0 ;
172172 let box : GridStackWidget = { x : n . x , y : newY , w : n . w , h : n . h } ;
173173 if ( i > 0 ) {
174- let collisionNode = this . nodes
175- . slice ( 0 , i )
176- . find ( bn => Utils . isIntercepted ( box , bn ) , { n : n , newY : newY } ) ;
177- canBeMoved = collisionNode === undefined ;
174+ let collisionNode = this . nodes . slice ( 0 , i ) . find ( bn => Utils . isIntercepted ( box , bn ) ) ;
175+ canBeMoved = ! collisionNode ;
178176 }
179177
180178 if ( ! canBeMoved ) { break ; }
@@ -312,7 +310,7 @@ export class GridStackEngine {
312310 continue ;
313311 }
314312 let box = { x, y, w : node . w , h : node . h } ;
315- if ( ! this . nodes . find ( n => Utils . isIntercepted ( box , n ) , { x , y , node } ) ) {
313+ if ( ! this . nodes . find ( n => Utils . isIntercepted ( box , n ) ) ) {
316314 node . x = x ;
317315 node . y = y ;
318316 delete node . autoPosition ; // found our slot
@@ -409,6 +407,31 @@ export class GridStackEngine {
409407 return clone . getRow ( ) <= this . maxRow ;
410408 }
411409
410+ /** return true if the passed in node (x,y) is being dragged outside of the grid, and not added to bottom */
411+ public isOutside ( x : number , y : number , node : GridStackNode ) : boolean {
412+ // simple outside boundaries
413+ if ( x < 0 || x >= this . column || y < 0 ) return true ;
414+ if ( this . maxRow ) return ( y >= this . maxRow ) ;
415+ else if ( this . float ) return false ; // infinite grow with no maxRow
416+
417+ // see if dragging PAST bottom (row+1)
418+ let row = this . getRow ( ) ;
419+ if ( y < row || y === 0 ) return false ;
420+ if ( y > row ) return true ;
421+ // else check to see if we can add that item to the bottom... (y == row)
422+ if ( ! node . _temporaryRemoved ) {
423+ let clone = new GridStackEngine ( {
424+ column : this . column ,
425+ float : this . float ,
426+ nodes : this . nodes . filter ( n => n !== node ) . map ( n => { return { ...n } } )
427+ } ) ;
428+ let nn = { ...node , x, y} ;
429+ clone . addNode ( nn ) ;
430+ return nn . y === node . y && nn . x === node . x ; // didn't actually move, so last row was a drag out and not a new place...
431+ }
432+ return node . _temporaryRemoved ; // if still outside so we don't flicker back & forth
433+ }
434+
412435 public isNodeChangedPosition ( node : GridStackNode , x : number , y : number , w ?: number , h ?: number ) : boolean {
413436 if ( typeof x !== 'number' ) { x = node . x ; }
414437 if ( typeof y !== 'number' ) { y = node . y ; }
0 commit comments