@@ -42,6 +42,9 @@ interface GridCSSStyleSheet extends CSSStyleSheet {
4242 _max ?: number ; // internal tracker of the max # of rows we created\
4343}
4444
45+ /** current drag&drop plugin being used - first grid will initialize */
46+ let dd : GridStackDD ;
47+
4548/**
4649 * Main gridstack class - you will need to call `GridStack.init()` first to initialize your grid.
4750 * Note: your grid elements MUST have the following classes for the CSS layout to work:
@@ -123,9 +126,6 @@ export class GridStack {
123126 /** grid options - public for classes to access, but use methods to modify! */
124127 public opts : GridStackOptions ;
125128
126- /** current drag&drop plugin being used */
127- public dd : GridStackDD ;
128-
129129 /** @internal */
130130 private placeholder : HTMLElement ;
131131 /** @internal */
@@ -223,12 +223,7 @@ export class GridStack {
223223 this . opts = Utils . defaults ( opts , defaults ) ;
224224 this . initMargin ( ) ;
225225
226- if ( this . opts . ddPlugin === false ) {
227- this . opts . ddPlugin = GridStackDD ;
228- } else if ( this . opts . ddPlugin === undefined ) {
229- this . opts . ddPlugin = GridStackDD . get ( ) ;
230- }
231- this . dd = new ( this . opts . ddPlugin as typeof GridStackDD ) ( this ) ;
226+ dd = dd || new ( GridStackDD . get ( ) ) ( ) ;
232227
233228 if ( this . opts . rtl === 'auto' ) {
234229 this . opts . rtl = el . style . direction === 'rtl' ;
@@ -792,11 +787,11 @@ export class GridStack {
792787 if ( ! node ) { return }
793788 node . noMove = ! ( val || false ) ;
794789 if ( node . noMove ) {
795- this . dd . draggable ( el , 'disable' ) ;
790+ dd . draggable ( el , 'disable' ) ;
796791 el . classList . remove ( 'ui-draggable-handle' ) ;
797792 } else {
798793 this . _prepareDragDropByNode ( node ) ; // init DD if need be
799- this . dd . draggable ( el , 'enable' ) ;
794+ dd . draggable ( el , 'enable' ) ;
800795 el . classList . remove ( 'ui-draggable-handle' ) ;
801796 }
802797 } ) ;
@@ -904,7 +899,7 @@ export class GridStack {
904899
905900 // remove our DOM data (circular link) and drag&drop permanently
906901 delete el . gridstackNode ;
907- this . dd . remove ( el ) ;
902+ dd . remove ( el ) ;
908903
909904 this . engine . removeNode ( node , removeDOM , triggerEvent ) ;
910905
@@ -927,7 +922,7 @@ export class GridStack {
927922 // always remove our DOM data (circular link) before list gets emptied and drag&drop permanently
928923 this . engine . nodes . forEach ( n => {
929924 delete n . el . gridstackNode ;
930- this . dd . remove ( n . el ) ;
925+ dd . remove ( n . el ) ;
931926 } ) ;
932927 this . engine . removeAll ( removeDOM ) ;
933928 this . _triggerRemoveEvent ( ) ;
@@ -962,10 +957,10 @@ export class GridStack {
962957 if ( ! node ) { return ; }
963958 node . noResize = ! ( val || false ) ;
964959 if ( node . noResize ) {
965- this . dd . resizable ( el , 'disable' ) ;
960+ dd . resizable ( el , 'disable' ) ;
966961 } else {
967962 this . _prepareDragDropByNode ( node ) ; // init DD if need be
968- this . dd . resizable ( el , 'enable' ) ;
963+ dd . resizable ( el , 'enable' ) ;
969964 }
970965 } ) ;
971966 return this ;
@@ -1230,7 +1225,7 @@ export class GridStack {
12301225 if ( this . opts . staticGrid || node . locked ||
12311226 ( ( node . noMove || this . opts . disableDrag ) && ( node . noResize || this . opts . disableResize ) ) ) {
12321227 if ( node . _initDD ) {
1233- this . dd . remove ( node . el ) ; // nukes everything instead of just disable, will add some styles back next
1228+ dd . remove ( node . el ) ; // nukes everything instead of just disable, will add some styles back next
12341229 delete node . _initDD ;
12351230 }
12361231 node . el . classList . add ( 'ui-draggable-disabled' , 'ui-resizable-disabled' ) ; // add styles one might depend on #1435
@@ -1274,8 +1269,8 @@ export class GridStack {
12741269 node . _beforeDragY = node . y ;
12751270 node . _prevYPix = ui . position . top ;
12761271
1277- this . dd . resizable ( el , 'option' , 'minWidth' , cellWidth * ( node . minWidth || 1 ) ) ;
1278- this . dd . resizable ( el , 'option' , 'minHeight' , cellHeight * ( node . minHeight || 1 ) ) ;
1272+ dd . resizable ( el , 'option' , 'minWidth' , cellWidth * ( node . minWidth || 1 ) ) ;
1273+ dd . resizable ( el , 'option' , 'minHeight' , cellHeight * ( node . minHeight || 1 ) ) ;
12791274 }
12801275
12811276 /** called when item is being dragged/resized */
@@ -1357,7 +1352,7 @@ export class GridStack {
13571352 gridToNotify . _gsEventHandler [ event . type ] ( event , target ) ;
13581353 }
13591354 gridToNotify . engine . removedNodes . push ( node ) ;
1360- gridToNotify . dd . remove ( el ) ;
1355+ dd . remove ( el ) ;
13611356 delete el . gridstackNode ; // hint we're removing it next and break circular link
13621357 gridToNotify . _triggerRemoveEvent ( ) ;
13631358 if ( el . parentElement ) {
@@ -1392,7 +1387,7 @@ export class GridStack {
13921387 }
13931388 }
13941389
1395- this . dd
1390+ dd
13961391 . draggable ( el , {
13971392 start : onStartMoving ,
13981393 stop : onEndMoving ,
@@ -1407,10 +1402,10 @@ export class GridStack {
14071402
14081403 // finally fine tune drag vs move by disabling any part...
14091404 if ( node . noMove || this . opts . disableDrag ) {
1410- this . dd . draggable ( el , 'disable' ) ;
1405+ dd . draggable ( el , 'disable' ) ;
14111406 }
14121407 if ( node . noResize || this . opts . disableResize ) {
1413- this . dd . resizable ( el , 'disable' ) ;
1408+ dd . resizable ( el , 'disable' ) ;
14141409 }
14151410 return this ;
14161411 }
@@ -1585,8 +1580,8 @@ export class GridStack {
15851580 /** @internal call to setup dragging in from the outside (say toolbar), with options */
15861581 private _setupDragIn ( ) : GridStack {
15871582 if ( ! this . opts . staticGrid && typeof this . opts . dragIn === 'string' ) {
1588- if ( ! this . dd . isDraggable ( this . opts . dragIn ) ) {
1589- this . dd . dragIn ( this . opts . dragIn , this . opts . dragInOptions ) ;
1583+ if ( ! dd . isDraggable ( this . opts . dragIn ) ) {
1584+ dd . dragIn ( this . opts . dragIn , this . opts . dragInOptions ) ;
15901585 }
15911586 }
15921587 return this ;
@@ -1597,10 +1592,10 @@ export class GridStack {
15971592 if ( ! this . opts . staticGrid && typeof this . opts . removable === 'string' ) {
15981593 let trashZone = document . querySelector ( this . opts . removable ) as HTMLElement ;
15991594 if ( ! trashZone ) return this ;
1600- if ( ! this . dd . isDroppable ( trashZone ) ) {
1601- this . dd . droppable ( trashZone , this . opts . removableOptions ) ;
1595+ if ( ! dd . isDroppable ( trashZone ) ) {
1596+ dd . droppable ( trashZone , this . opts . removableOptions ) ;
16021597 }
1603- this . dd
1598+ dd
16041599 . on ( trashZone , 'dropover' , ( event , el ) => {
16051600 let node = el . gridstackNode ;
16061601 if ( ! node || node . grid !== this ) return ;
@@ -1650,7 +1645,7 @@ export class GridStack {
16501645 }
16511646 } ;
16521647
1653- this . dd
1648+ dd
16541649 . droppable ( this . el , {
16551650 accept : ( el : GridItemHTMLElement ) => {
16561651 let node : GridStackNode = el . gridstackNode ;
@@ -1690,7 +1685,7 @@ export class GridStack {
16901685 el . gridstackNode = newNode ;
16911686 el . _gridstackNodeOrig = node ;
16921687
1693- this . dd . on ( el , 'drag' , onDrag ) ;
1688+ dd . on ( el , 'drag' , onDrag ) ;
16941689 return false ; // prevent parent from receiving msg (which may be grid as well)
16951690 } )
16961691 . on ( this . el , 'dropout' , ( event , el : GridItemHTMLElement ) => {
@@ -1700,7 +1695,7 @@ export class GridStack {
17001695 if ( ! node || ! node . _isOutOfGrid ) {
17011696 return ;
17021697 }
1703- this . dd . off ( el , 'drag' ) ;
1698+ dd . off ( el , 'drag' ) ;
17041699 node . el = null ;
17051700 this . engine . removeNode ( node ) ;
17061701 if ( this . placeholder . parentNode === this . el ) {
@@ -1729,7 +1724,7 @@ export class GridStack {
17291724 this . engine . cleanupNode ( node ) ; // removes all internal _xyz values (including the _id so add that back)
17301725 node . _id = _id ;
17311726 node . grid = this ;
1732- this . dd . off ( el , 'drag' ) ;
1727+ dd . off ( el , 'drag' ) ;
17331728 // if we made a copy ('helper' which is temp) of the original node then insert a copy, else we move the original node (#1102)
17341729 // as the helper will be nuked by jqueryui otherwise
17351730 if ( helper !== el ) {
@@ -1738,7 +1733,7 @@ export class GridStack {
17381733 el = el . cloneNode ( true ) as GridItemHTMLElement ;
17391734 } else {
17401735 el . remove ( ) ; // reduce flicker as we change depth here, and size further down
1741- this . dd . remove ( el ) ;
1736+ dd . remove ( el ) ;
17421737 }
17431738 el . gridstackNode = node ;
17441739 node . el = el ;
0 commit comments