@@ -156,7 +156,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
156156 if ( node && node . grid && node . grid !== this && ! node . _temporaryRemoved ) {
157157 // TEST console.log('dropover without leave');
158158 let otherGrid = node . grid ;
159- otherGrid . _leave ( el . gridstackNode , el , helper , true ) ; // MATCH line 222
159+ otherGrid . _leave ( el , helper ) ;
160160 }
161161
162162 // get grid screen coordinates and cell dimensions
@@ -196,6 +196,9 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
196196 node . _temporaryRemoved = true ; // so we can insert it
197197 }
198198
199+ // clear any marked for complete removal (Note: don't check _isAboutToRemove as that is cleared above - just do it)
200+ _itemRemoving ( node . el , false ) ;
201+
199202 GridStackDD . get ( ) . on ( el , 'drag' , onDrag ) ;
200203 // make sure this is called at least once when going fast #1578
201204 onDrag ( event as DragEvent , el , helper ) ;
@@ -209,7 +212,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
209212 // fix #1578 when dragging fast, we might get leave after other grid gets enter (which calls us to clean)
210213 // so skip this one if we're not the active grid really..
211214 if ( ! node . grid || node . grid === this ) {
212- this . _leave ( node , el , helper , true ) ; // MATCH line 166
215+ this . _leave ( el , helper ) ;
213216 }
214217 return false ; // prevent parent from receiving msg (which may be grid as well)
215218 } )
@@ -287,6 +290,14 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
287290 return this ;
288291}
289292
293+ /** @internal mark item for removal */
294+ function _itemRemoving ( el : GridItemHTMLElement , remove : boolean ) {
295+ let node = el . gridstackNode ;
296+ if ( ! node || ! node . grid ) return ;
297+ remove ? node . _isAboutToRemove = true : delete node . _isAboutToRemove ;
298+ remove ? el . classList . add ( 'grid-stack-item-removing' ) : el . classList . remove ( 'grid-stack-item-removing' ) ;
299+ }
300+
290301/** @internal called to setup a trash drop zone if the user specifies it */
291302GridStack . prototype . _setupRemoveDrop = function ( ) : GridStack {
292303 if ( ! this . opts . staticGrid && typeof this . opts . removable === 'string' ) {
@@ -297,18 +308,8 @@ GridStack.prototype._setupRemoveDrop = function(): GridStack {
297308 // and Native DD only has 1 event CB (having a list and technically a per grid removableOptions complicates things greatly)
298309 if ( ! GridStackDD . get ( ) . isDroppable ( trashEl ) ) {
299310 GridStackDD . get ( ) . droppable ( trashEl , this . opts . removableOptions )
300- . on ( trashEl , 'dropover' , function ( event , el ) { // don't use => notation to avoid using 'this' as grid by mistake...
301- let node = el . gridstackNode ;
302- if ( ! node || ! node . grid ) return ;
303- node . _isAboutToRemove = true ;
304- el . classList . add ( 'grid-stack-item-removing' ) ;
305- } )
306- . on ( trashEl , 'dropout' , function ( event , el ) { // same
307- let node = el . gridstackNode ;
308- if ( ! node || ! node . grid ) return ;
309- delete node . _isAboutToRemove ;
310- el . classList . remove ( 'grid-stack-item-removing' ) ;
311- } ) ;
311+ . on ( trashEl , 'dropover' , ( event , el ) => _itemRemoving ( el , true ) )
312+ . on ( trashEl , 'dropout' , ( event , el ) => _itemRemoving ( el , false ) ) ;
312313 }
313314 }
314315 return this ;
@@ -494,12 +495,11 @@ GridStack.prototype._onStartMoving = function(el: GridItemHTMLElement, event: Ev
494495 * or shape is outside our boundaries. remove it from us, and mark temporary if this was
495496 * our item to start with else restore prev node values from prev grid it came from.
496497 **/
497- GridStack . prototype . _leave = function ( node : GridStackNode , el : GridItemHTMLElement , helper ?: GridItemHTMLElement , dropoutEvent = false ) {
498+ GridStack . prototype . _leave = function ( el : GridItemHTMLElement , helper ?: GridItemHTMLElement ) {
499+ let node = el . gridstackNode ;
498500 if ( ! node ) return ;
499501
500- if ( dropoutEvent ) {
501- GridStackDD . get ( ) . off ( el , 'drag' ) ; // no need to track while being outside
502- }
502+ GridStackDD . get ( ) . off ( el , 'drag' ) ; // no need to track while being outside
503503
504504 // this gets called when cursor leaves and shape is outside, so only do this once
505505 if ( node . _temporaryRemoved ) return ;
@@ -508,6 +508,11 @@ GridStack.prototype._leave = function(node: GridStackNode, el: GridItemHTMLEleme
508508 this . engine . removeNode ( node ) ; // remove placeholder as well, otherwise it's a sign node is not in our list, which is a bigger issue
509509 node . el = node . _isExternal && helper ? helper : el ; // point back to real item being dragged
510510
511+ if ( this . opts . removable === true ) { // boolean vs a class string
512+ // item leaving us and we are supposed to remove on leave (no need to drag onto trash) mark it so
513+ _itemRemoving ( el , true ) ;
514+ }
515+
511516 // finally if item originally came from another grid, but left us, restore things back to prev info
512517 if ( el . _gridstackNodeOrig ) {
513518 // TEST console.log('leave delete _gridstackNodeOrig')
0 commit comments