@@ -73,7 +73,7 @@ export abstract class GridStackDD extends GridStackDDI {
73
73
********************************************************************************/
74
74
75
75
/** @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 {
77
77
78
78
// check if we need to disable things
79
79
if ( this . opts . staticGrid || ! this . opts . acceptWidgets ) {
@@ -171,7 +171,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
171
171
cellHeight = this . getCellHeight ( true ) ;
172
172
173
173
// load any element attributes if we don't have a node
174
- if ( ! node ) {
174
+ if ( ! node ) { // @ts -ignore
175
175
node = this . _readAttr ( el ) ;
176
176
}
177
177
if ( ! node . grid ) {
@@ -265,14 +265,14 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
265
265
if ( ! wasAdded ) return false ;
266
266
el . gridstackNode = node ;
267
267
node . el = el ;
268
-
268
+ // @ts -ignore
269
269
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
271
271
this . _writeAttr ( el , node ) ;
272
- this . el . appendChild ( el ) ;
272
+ this . el . appendChild ( el ) ; // @ts -ignore
273
273
this . _updateContainerHeight ( ) ;
274
- this . engine . addedNodes . push ( node ) ;
275
- this . _triggerAddEvent ( ) ;
274
+ this . engine . addedNodes . push ( node ) ; // @ts -ignore
275
+ this . _triggerAddEvent ( ) ; // @ts -ignore
276
276
this . _triggerChangeEvent ( ) ;
277
277
278
278
this . engine . endUpdate ( ) ;
@@ -304,7 +304,7 @@ function _itemRemoving(el: GridItemHTMLElement, remove: boolean) {
304
304
}
305
305
306
306
/** @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 {
308
308
if ( ! this . opts . staticGrid && typeof this . opts . removable === 'string' ) {
309
309
let trashEl = document . querySelector ( this . opts . removable ) as HTMLElement ;
310
310
if ( ! trashEl ) return this ;
@@ -325,7 +325,7 @@ GridStack.prototype._setupRemoveDrop = function(): GridStack {
325
325
* Called during GridStack.init() as options, but can also be called directly (last param are cached) in case the toolbar
326
326
* is dynamically create and needs to change later.
327
327
**/
328
- GridStack . setupDragIn = function ( _dragIn ?: string , _dragInOptions ?: DDDragInOpt ) {
328
+ GridStack . setupDragIn = function ( this : GridStack , _dragIn ?: string , _dragInOptions ?: DDDragInOpt ) {
329
329
let dragIn : string ;
330
330
let dragInOptions : DDDragInOpt ;
331
331
const dragInDefaultOptions : DDDragInOpt = {
@@ -348,7 +348,7 @@ GridStack.setupDragIn = function(_dragIn?: string, _dragInOptions?: DDDragInOpt)
348
348
}
349
349
350
350
/** @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 {
352
352
let el = node . el ;
353
353
let dd = GridStackDD . get ( ) ;
354
354
@@ -411,22 +411,22 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
411
411
} else {
412
412
if ( ! node . _temporaryRemoved ) {
413
413
// move to new placeholder location
414
- Utils . removePositioningStyles ( target ) ;
414
+ Utils . removePositioningStyles ( target ) ; // @ts -ignore
415
415
this . _writePosAttr ( target , node ) ;
416
416
} else {
417
417
// got removed - restore item back to before dragging position
418
418
Utils . removePositioningStyles ( target ) ;
419
- Utils . copyPos ( node , node . _orig ) ;
419
+ Utils . copyPos ( node , node . _orig ) ; // @ts -ignore
420
420
this . _writePosAttr ( target , node ) ;
421
421
this . engine . addNode ( node ) ;
422
422
}
423
423
if ( this . _gsEventHandler [ event . type ] ) {
424
424
this . _gsEventHandler [ event . type ] ( event , target ) ;
425
425
}
426
426
}
427
-
428
- this . _extraDragRow = 0 ;
429
- this . _updateContainerHeight ( ) ;
427
+ // @ts -ignore
428
+ this . _extraDragRow = 0 ; // @ts -ignore
429
+ this . _updateContainerHeight ( ) ; // @ts -ignore
430
430
this . _triggerChangeEvent ( ) ;
431
431
432
432
this . engine . endUpdate ( ) ;
@@ -464,10 +464,10 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
464
464
}
465
465
466
466
/** @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 ) {
468
468
this . engine . cleanNodes ( )
469
469
. beginUpdate ( node ) ;
470
-
470
+ // @ts -ignore
471
471
this . _writePosAttr ( this . placeholder , node )
472
472
this . el . appendChild ( this . placeholder ) ;
473
473
// TEST console.log('_onStartMoving placeholder')
@@ -485,7 +485,7 @@ GridStack.prototype._onStartMoving = function(el: GridItemHTMLElement, event: Ev
485
485
}
486
486
487
487
// 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 ) ;
489
489
if ( event . type === 'resizestart' ) {
490
490
let dd = GridStackDD . get ( )
491
491
. resizable ( el , 'option' , 'minWidth' , cellWidth * ( node . minW || 1 ) )
@@ -499,7 +499,7 @@ GridStack.prototype._onStartMoving = function(el: GridItemHTMLElement, event: Ev
499
499
* or shape is outside our boundaries. remove it from us, and mark temporary if this was
500
500
* our item to start with else restore prev node values from prev grid it came from.
501
501
**/
502
- GridStack . prototype . _leave = function ( el : GridItemHTMLElement , helper ?: GridItemHTMLElement ) {
502
+ GridStack . prototype . _leave = function ( this : GridStack , el : GridItemHTMLElement , helper ?: GridItemHTMLElement ) {
503
503
let node = el . gridstackNode ;
504
504
if ( ! node ) return ;
505
505
@@ -532,9 +532,13 @@ GridStack.prototype._leave = function(el: GridItemHTMLElement, helper?: GridItem
532
532
}
533
533
534
534
/** @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 ) {
536
536
let p = { ...node . _orig } ; // could be undefined (_isExternal) which is ok (drag only set x,y and w,h will default to node value)
537
537
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 ;
538
542
539
543
if ( event . type === 'drag' ) {
540
544
if ( node . _temporaryRemoved ) return ; // handled by dropover
@@ -543,21 +547,21 @@ GridStack.prototype._dragOrResize = function(el: GridItemHTMLElement, event: Eve
543
547
Utils . updateScrollPosition ( el , ui . position , distance ) ;
544
548
545
549
// 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 ) ;
548
552
p . x = Math . round ( left / cellWidth ) ;
549
553
p . y = Math . round ( top / cellHeight ) ;
550
554
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
552
556
let prev = this . _extraDragRow ;
553
557
if ( this . engine . collide ( node , p ) ) {
554
558
let row = this . getRow ( ) ;
555
559
let extra = Math . max ( 0 , ( p . y + node . h ) - row ) ;
556
560
if ( this . opts . maxRow && row + extra > this . opts . maxRow ) {
557
561
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
561
565
if ( this . _extraDragRow !== prev ) this . _updateContainerHeight ( ) ;
562
566
563
567
if ( node . x === p . x && node . y === p . y ) return ; // skip same
@@ -569,14 +573,14 @@ GridStack.prototype._dragOrResize = function(el: GridItemHTMLElement, event: Eve
569
573
Utils . updateScrollResize ( event as MouseEvent , el , cellHeight ) ;
570
574
571
575
// 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 ) ;
574
578
if ( node . w === p . w && node . h === p . h ) return ;
575
579
if ( node . _lastTried && node . _lastTried . w === p . w && node . _lastTried . h === p . h ) return ; // skip one we tried (but failed)
576
580
577
581
// 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 ;
580
584
p . x = Math . round ( left / cellWidth ) ;
581
585
p . y = Math . round ( top / cellHeight ) ;
582
586
@@ -585,20 +589,20 @@ GridStack.prototype._dragOrResize = function(el: GridItemHTMLElement, event: Eve
585
589
586
590
node . _lastTried = p ; // set as last tried (will nuke if we go there)
587
591
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
592
596
} ;
593
597
if ( this . engine . moveNodeCheck ( node , { ...p , cellWidth, cellHeight, rect} ) ) {
594
598
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 ) ;
596
600
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
599
603
this . _updateContainerHeight ( ) ;
600
604
601
- let target = event . target as GridItemHTMLElement ;
605
+ let target = event . target as GridItemHTMLElement ; // @ts -ignore
602
606
this . _writePosAttr ( target , node ) ;
603
607
if ( this . _gsEventHandler [ event . type ] ) {
604
608
this . _gsEventHandler [ event . type ] ( event , target ) ;
@@ -611,7 +615,7 @@ GridStack.prototype._dragOrResize = function(el: GridItemHTMLElement, event: Eve
611
615
* @param els widget or selector to modify.
612
616
* @param val if true widget will be draggable.
613
617
*/
614
- GridStack . prototype . movable = function ( els : GridStackElement , val : boolean ) : GridStack {
618
+ GridStack . prototype . movable = function ( this : GridStack , els : GridStackElement , val : boolean ) : GridStack {
615
619
if ( this . opts . staticGrid ) return this ; // can't move a static grid!
616
620
GridStack . getElements ( els ) . forEach ( el => {
617
621
let node = el . gridstackNode ;
@@ -627,7 +631,7 @@ GridStack.prototype.movable = function(els: GridStackElement, val: boolean): Gri
627
631
* @param els widget or selector to modify
628
632
* @param val if true widget will be resizable.
629
633
*/
630
- GridStack . prototype . resizable = function ( els : GridStackElement , val : boolean ) : GridStack {
634
+ GridStack . prototype . resizable = function ( this : GridStack , els : GridStackElement , val : boolean ) : GridStack {
631
635
if ( this . opts . staticGrid ) return this ; // can't resize a static grid!
632
636
GridStack . getElements ( els ) . forEach ( el => {
633
637
let node = el . gridstackNode ;
@@ -648,10 +652,10 @@ GridStack.prototype.resizable = function(els: GridStackElement, val: boolean): G
648
652
* grid.enableMove(false);
649
653
* grid.enableResize(false);
650
654
*/
651
- GridStack . prototype . disable = function ( ) : GridStack {
655
+ GridStack . prototype . disable = function ( this : GridStack ) : GridStack {
652
656
if ( this . opts . staticGrid ) return ;
653
657
this . enableMove ( false ) ;
654
- this . enableResize ( false ) ;
658
+ this . enableResize ( false ) ; // @ts -ignore
655
659
this . _triggerEvent ( 'disable' ) ;
656
660
return this ;
657
661
}
@@ -664,24 +668,24 @@ GridStack.prototype.disable = function(): GridStack {
664
668
* grid.enableMove(true);
665
669
* grid.enableResize(true);
666
670
*/
667
- GridStack . prototype . enable = function ( ) : GridStack {
671
+ GridStack . prototype . enable = function ( this : GridStack ) : GridStack {
668
672
if ( this . opts . staticGrid ) return ;
669
673
this . enableMove ( true ) ;
670
- this . enableResize ( true ) ;
674
+ this . enableResize ( true ) ; // @ts -ignore
671
675
this . _triggerEvent ( 'enable' ) ;
672
676
return this ;
673
677
}
674
678
675
679
/** 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 {
677
681
if ( this . opts . staticGrid ) return this ; // can't move a static grid!
678
682
this . opts . disableDrag = ! doEnable ; // FIRST before we update children as grid overrides #1658
679
683
this . engine . nodes . forEach ( n => this . movable ( n . el , doEnable ) ) ;
680
684
return this ;
681
685
}
682
686
683
687
/** 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 {
685
689
if ( this . opts . staticGrid ) return this ; // can't size a static grid!
686
690
this . opts . disableResize = ! doEnable ; // FIRST before we update children as grid overrides #1658
687
691
this . engine . nodes . forEach ( n => this . resizable ( n . el , doEnable ) ) ;
0 commit comments