@@ -73,7 +73,7 @@ export abstract class GridStackDD extends GridStackDDI {
7373 ********************************************************************************/
7474
7575/** @internal called to add drag over to support widgets being added externally */
76- GridStack . prototype . _setupAcceptWidget = function ( ) : GridStack {
76+ GridStack . prototype . _setupAcceptWidget = function ( this : GridStack ) : GridStack {
7777
7878 // check if we need to disable things
7979 if ( this . opts . staticGrid || ! this . opts . acceptWidgets ) {
@@ -171,7 +171,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
171171 cellHeight = this . getCellHeight ( true ) ;
172172
173173 // load any element attributes if we don't have a node
174- if ( ! node ) {
174+ if ( ! node ) { // @ts -ignore
175175 node = this . _readAttr ( el ) ;
176176 }
177177 if ( ! node . grid ) {
@@ -265,14 +265,14 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
265265 if ( ! wasAdded ) return false ;
266266 el . gridstackNode = node ;
267267 node . el = el ;
268-
268+ // @ts -ignore
269269 Utils . copyPos ( node , this . _readAttr ( this . placeholder ) ) ; // placeholder values as moving VERY fast can throw things off #1578
270- Utils . removePositioningStyles ( el ) ;
270+ Utils . removePositioningStyles ( el ) ; // @ts -ignore
271271 this . _writeAttr ( el , node ) ;
272- this . el . appendChild ( el ) ;
272+ this . el . appendChild ( el ) ; // @ts -ignore
273273 this . _updateContainerHeight ( ) ;
274- this . engine . addedNodes . push ( node ) ;
275- this . _triggerAddEvent ( ) ;
274+ this . engine . addedNodes . push ( node ) ; // @ts -ignore
275+ this . _triggerAddEvent ( ) ; // @ts -ignore
276276 this . _triggerChangeEvent ( ) ;
277277
278278 this . engine . endUpdate ( ) ;
@@ -304,7 +304,7 @@ function _itemRemoving(el: GridItemHTMLElement, remove: boolean) {
304304}
305305
306306/** @internal called to setup a trash drop zone if the user specifies it */
307- GridStack . prototype . _setupRemoveDrop = function ( ) : GridStack {
307+ GridStack . prototype . _setupRemoveDrop = function ( this : GridStack ) : GridStack {
308308 if ( ! this . opts . staticGrid && typeof this . opts . removable === 'string' ) {
309309 let trashEl = document . querySelector ( this . opts . removable ) as HTMLElement ;
310310 if ( ! trashEl ) return this ;
@@ -325,7 +325,7 @@ GridStack.prototype._setupRemoveDrop = function(): GridStack {
325325 * Called during GridStack.init() as options, but can also be called directly (last param are cached) in case the toolbar
326326 * is dynamically create and needs to change later.
327327 **/
328- GridStack . setupDragIn = function ( _dragIn ?: string , _dragInOptions ?: DDDragInOpt ) {
328+ GridStack . setupDragIn = function ( this : GridStack , _dragIn ?: string , _dragInOptions ?: DDDragInOpt ) {
329329 let dragIn : string ;
330330 let dragInOptions : DDDragInOpt ;
331331 const dragInDefaultOptions : DDDragInOpt = {
@@ -348,7 +348,7 @@ GridStack.setupDragIn = function(_dragIn?: string, _dragInOptions?: DDDragInOpt)
348348}
349349
350350/** @internal prepares the element for drag&drop **/
351- GridStack . prototype . _prepareDragDropByNode = function ( node : GridStackNode ) : GridStack {
351+ GridStack . prototype . _prepareDragDropByNode = function ( this : GridStack , node : GridStackNode ) : GridStack {
352352 let el = node . el ;
353353 let dd = GridStackDD . get ( ) ;
354354
@@ -411,22 +411,22 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
411411 } else {
412412 if ( ! node . _temporaryRemoved ) {
413413 // move to new placeholder location
414- Utils . removePositioningStyles ( target ) ;
414+ Utils . removePositioningStyles ( target ) ; // @ts -ignore
415415 this . _writePosAttr ( target , node ) ;
416416 } else {
417417 // got removed - restore item back to before dragging position
418418 Utils . removePositioningStyles ( target ) ;
419- Utils . copyPos ( node , node . _orig ) ;
419+ Utils . copyPos ( node , node . _orig ) ; // @ts -ignore
420420 this . _writePosAttr ( target , node ) ;
421421 this . engine . addNode ( node ) ;
422422 }
423423 if ( this . _gsEventHandler [ event . type ] ) {
424424 this . _gsEventHandler [ event . type ] ( event , target ) ;
425425 }
426426 }
427-
428- this . _extraDragRow = 0 ;
429- this . _updateContainerHeight ( ) ;
427+ // @ts -ignore
428+ this . _extraDragRow = 0 ; // @ts -ignore
429+ this . _updateContainerHeight ( ) ; // @ts -ignore
430430 this . _triggerChangeEvent ( ) ;
431431
432432 this . engine . endUpdate ( ) ;
@@ -464,10 +464,10 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
464464}
465465
466466/** @internal called when item is starting a drag/resize */
467- GridStack . prototype . _onStartMoving = function ( el : GridItemHTMLElement , event : Event , ui : DDUIData , node : GridStackNode , cellWidth : number , cellHeight : number ) {
467+ GridStack . prototype . _onStartMoving = function ( this : GridStack , el : GridItemHTMLElement , event : Event , ui : DDUIData , node : GridStackNode , cellWidth : number , cellHeight : number ) {
468468 this . engine . cleanNodes ( )
469469 . beginUpdate ( node ) ;
470-
470+ // @ts -ignore
471471 this . _writePosAttr ( this . placeholder , node )
472472 this . el . appendChild ( this . placeholder ) ;
473473 // TEST console.log('_onStartMoving placeholder')
@@ -485,7 +485,7 @@ GridStack.prototype._onStartMoving = function(el: GridItemHTMLElement, event: Ev
485485 }
486486
487487 // set the min/max resize info
488- this . engine . cacheRects ( cellWidth , cellHeight , this . opts . marginTop , this . opts . marginRight , this . opts . marginBottom , this . opts . marginLeft ) ;
488+ this . engine . cacheRects ( cellWidth , cellHeight , this . opts . marginTop as number , this . opts . marginRight as number , this . opts . marginBottom as number , this . opts . marginLeft as number ) ;
489489 if ( event . type === 'resizestart' ) {
490490 let dd = GridStackDD . get ( )
491491 . resizable ( el , 'option' , 'minWidth' , cellWidth * ( node . minW || 1 ) )
@@ -499,7 +499,7 @@ GridStack.prototype._onStartMoving = function(el: GridItemHTMLElement, event: Ev
499499 * or shape is outside our boundaries. remove it from us, and mark temporary if this was
500500 * our item to start with else restore prev node values from prev grid it came from.
501501 **/
502- GridStack . prototype . _leave = function ( el : GridItemHTMLElement , helper ?: GridItemHTMLElement ) {
502+ GridStack . prototype . _leave = function ( this : GridStack , el : GridItemHTMLElement , helper ?: GridItemHTMLElement ) {
503503 let node = el . gridstackNode ;
504504 if ( ! node ) return ;
505505
@@ -532,9 +532,13 @@ GridStack.prototype._leave = function(el: GridItemHTMLElement, helper?: GridItem
532532}
533533
534534/** @internal called when item is being dragged/resized */
535- GridStack . prototype . _dragOrResize = function ( el : GridItemHTMLElement , event : Event , ui : DDUIData , node : GridStackNode , cellWidth : number , cellHeight : number ) {
535+ GridStack . prototype . _dragOrResize = function ( this : GridStack , el : GridItemHTMLElement , event : Event , ui : DDUIData , node : GridStackNode , cellWidth : number , cellHeight : number ) {
536536 let p = { ...node . _orig } ; // could be undefined (_isExternal) which is ok (drag only set x,y and w,h will default to node value)
537537 let resizing : boolean ;
538+ const mLeft = this . opts . marginLeft as number ,
539+ mRight = this . opts . marginRight as number ,
540+ mTop = this . opts . marginTop as number ,
541+ mBottom = this . opts . marginBottom as number ;
538542
539543 if ( event . type === 'drag' ) {
540544 if ( node . _temporaryRemoved ) return ; // handled by dropover
@@ -543,21 +547,21 @@ GridStack.prototype._dragOrResize = function(el: GridItemHTMLElement, event: Eve
543547 Utils . updateScrollPosition ( el , ui . position , distance ) ;
544548
545549 // get new position taking into account the margin in the direction we are moving! (need to pass mid point by margin)
546- let left = ui . position . left + ( ui . position . left > node . _lastUiPosition . left ? - this . opts . marginRight : this . opts . marginLeft ) ;
547- let top = ui . position . top + ( ui . position . top > node . _lastUiPosition . top ? - this . opts . marginBottom : this . opts . marginTop ) ;
550+ let left = ui . position . left + ( ui . position . left > node . _lastUiPosition . left ? - mRight : mLeft ) ;
551+ let top = ui . position . top + ( ui . position . top > node . _lastUiPosition . top ? - mBottom : mTop ) ;
548552 p . x = Math . round ( left / cellWidth ) ;
549553 p . y = Math . round ( top / cellHeight ) ;
550554
551- // if we're at the bottom hitting something else, grow the grid so cursor doesn't leave when trying to place below others
555+ // @ts -ignore// if we're at the bottom hitting something else, grow the grid so cursor doesn't leave when trying to place below others
552556 let prev = this . _extraDragRow ;
553557 if ( this . engine . collide ( node , p ) ) {
554558 let row = this . getRow ( ) ;
555559 let extra = Math . max ( 0 , ( p . y + node . h ) - row ) ;
556560 if ( this . opts . maxRow && row + extra > this . opts . maxRow ) {
557561 extra = Math . max ( 0 , this . opts . maxRow - row ) ;
558- }
559- this . _extraDragRow = extra ;
560- } else this . _extraDragRow = 0 ;
562+ } // @ts -ignore
563+ this . _extraDragRow = extra ; // @ts -ignore
564+ } else this . _extraDragRow = 0 ; // @ts -ignore
561565 if ( this . _extraDragRow !== prev ) this . _updateContainerHeight ( ) ;
562566
563567 if ( node . x === p . x && node . y === p . y ) return ; // skip same
@@ -569,14 +573,14 @@ GridStack.prototype._dragOrResize = function(el: GridItemHTMLElement, event: Eve
569573 Utils . updateScrollResize ( event as MouseEvent , el , cellHeight ) ;
570574
571575 // get new size
572- p . w = Math . round ( ( ui . size . width - this . opts . marginLeft ) / cellWidth ) ;
573- p . h = Math . round ( ( ui . size . height - this . opts . marginTop ) / cellHeight ) ;
576+ p . w = Math . round ( ( ui . size . width - mLeft ) / cellWidth ) ;
577+ p . h = Math . round ( ( ui . size . height - mTop ) / cellHeight ) ;
574578 if ( node . w === p . w && node . h === p . h ) return ;
575579 if ( node . _lastTried && node . _lastTried . w === p . w && node . _lastTried . h === p . h ) return ; // skip one we tried (but failed)
576580
577581 // if we size on left/top side this might move us, so get possible new position as well
578- let left = ui . position . left + this . opts . marginLeft ;
579- let top = ui . position . top + this . opts . marginTop ;
582+ let left = ui . position . left + mLeft ;
583+ let top = ui . position . top + mTop ;
580584 p . x = Math . round ( left / cellWidth ) ;
581585 p . y = Math . round ( top / cellHeight ) ;
582586
@@ -585,20 +589,20 @@ GridStack.prototype._dragOrResize = function(el: GridItemHTMLElement, event: Eve
585589
586590 node . _lastTried = p ; // set as last tried (will nuke if we go there)
587591 let rect : GridStackPosition = { // screen pix of the dragged box
588- x : ui . position . left + this . opts . marginLeft ,
589- y : ui . position . top + this . opts . marginTop ,
590- w : ( ui . size ? ui . size . width : node . w * cellWidth ) - this . opts . marginLeft - this . opts . marginRight ,
591- h : ( ui . size ? ui . size . height : node . h * cellHeight ) - this . opts . marginTop - this . opts . marginBottom
592+ x : ui . position . left + mLeft ,
593+ y : ui . position . top + mTop ,
594+ w : ( ui . size ? ui . size . width : node . w * cellWidth ) - mLeft - mRight ,
595+ h : ( ui . size ? ui . size . height : node . h * cellHeight ) - mTop - mBottom
592596 } ;
593597 if ( this . engine . moveNodeCheck ( node , { ...p , cellWidth, cellHeight, rect} ) ) {
594598 node . _lastUiPosition = ui . position ;
595- this . engine . cacheRects ( cellWidth , cellHeight , this . opts . marginTop , this . opts . marginRight , this . opts . marginBottom , this . opts . marginLeft ) ;
599+ this . engine . cacheRects ( cellWidth , cellHeight , mTop , mRight , mBottom , mLeft ) ;
596600 delete node . _skipDown ;
597- if ( resizing && node . subGrid ) { ( node . subGrid as GridStack ) . onParentResize ( ) ; }
598- this . _extraDragRow = 0 ;
601+ if ( resizing && node . subGrid ) { ( node . subGrid as GridStack ) . onParentResize ( ) ; } // @ts -ignore
602+ this . _extraDragRow = 0 ; // @ts -ignore
599603 this . _updateContainerHeight ( ) ;
600604
601- let target = event . target as GridItemHTMLElement ;
605+ let target = event . target as GridItemHTMLElement ; // @ts -ignore
602606 this . _writePosAttr ( target , node ) ;
603607 if ( this . _gsEventHandler [ event . type ] ) {
604608 this . _gsEventHandler [ event . type ] ( event , target ) ;
@@ -611,7 +615,7 @@ GridStack.prototype._dragOrResize = function(el: GridItemHTMLElement, event: Eve
611615 * @param els widget or selector to modify.
612616 * @param val if true widget will be draggable.
613617 */
614- GridStack . prototype . movable = function ( els : GridStackElement , val : boolean ) : GridStack {
618+ GridStack . prototype . movable = function ( this : GridStack , els : GridStackElement , val : boolean ) : GridStack {
615619 if ( this . opts . staticGrid ) return this ; // can't move a static grid!
616620 GridStack . getElements ( els ) . forEach ( el => {
617621 let node = el . gridstackNode ;
@@ -627,7 +631,7 @@ GridStack.prototype.movable = function(els: GridStackElement, val: boolean): Gri
627631 * @param els widget or selector to modify
628632 * @param val if true widget will be resizable.
629633 */
630- GridStack . prototype . resizable = function ( els : GridStackElement , val : boolean ) : GridStack {
634+ GridStack . prototype . resizable = function ( this : GridStack , els : GridStackElement , val : boolean ) : GridStack {
631635 if ( this . opts . staticGrid ) return this ; // can't resize a static grid!
632636 GridStack . getElements ( els ) . forEach ( el => {
633637 let node = el . gridstackNode ;
@@ -648,10 +652,10 @@ GridStack.prototype.resizable = function(els: GridStackElement, val: boolean): G
648652 * grid.enableMove(false);
649653 * grid.enableResize(false);
650654 */
651- GridStack . prototype . disable = function ( ) : GridStack {
655+ GridStack . prototype . disable = function ( this : GridStack ) : GridStack {
652656 if ( this . opts . staticGrid ) return ;
653657 this . enableMove ( false ) ;
654- this . enableResize ( false ) ;
658+ this . enableResize ( false ) ; // @ts -ignore
655659 this . _triggerEvent ( 'disable' ) ;
656660 return this ;
657661}
@@ -664,24 +668,24 @@ GridStack.prototype.disable = function(): GridStack {
664668 * grid.enableMove(true);
665669 * grid.enableResize(true);
666670 */
667- GridStack . prototype . enable = function ( ) : GridStack {
671+ GridStack . prototype . enable = function ( this : GridStack ) : GridStack {
668672 if ( this . opts . staticGrid ) return ;
669673 this . enableMove ( true ) ;
670- this . enableResize ( true ) ;
674+ this . enableResize ( true ) ; // @ts -ignore
671675 this . _triggerEvent ( 'enable' ) ;
672676 return this ;
673677}
674678
675679/** Enables/disables widget moving. No-op for static grids. */
676- GridStack . prototype . enableMove = function ( doEnable : boolean ) : GridStack {
680+ GridStack . prototype . enableMove = function ( this : GridStack , doEnable : boolean ) : GridStack {
677681 if ( this . opts . staticGrid ) return this ; // can't move a static grid!
678682 this . opts . disableDrag = ! doEnable ; // FIRST before we update children as grid overrides #1658
679683 this . engine . nodes . forEach ( n => this . movable ( n . el , doEnable ) ) ;
680684 return this ;
681685}
682686
683687/** Enables/disables widget resizing. No-op for static grids. */
684- GridStack . prototype . enableResize = function ( doEnable : boolean ) : GridStack {
688+ GridStack . prototype . enableResize = function ( this : GridStack , doEnable : boolean ) : GridStack {
685689 if ( this . opts . staticGrid ) return this ; // can't size a static grid!
686690 this . opts . disableResize = ! doEnable ; // FIRST before we update children as grid overrides #1658
687691 this . engine . nodes . forEach ( n => this . resizable ( n . el , doEnable ) ) ;
0 commit comments