7
7
*/
8
8
import { GridStackEngine } from './gridstack-engine' ;
9
9
import { Utils , HeightData , obsolete } from './utils' ;
10
- import { ColumnOptions , GridItemHTMLElement , GridStackElement , GridStackEventHandlerCallback ,
10
+ import { GridDefaults , ColumnOptions , GridItemHTMLElement , GridStackElement , GridStackEventHandlerCallback ,
11
11
GridStackNode , GridStackOptions , GridStackWidget , numberOrString , DDUIData , DDDragInOpt , GridStackPosition } from './types' ;
12
12
13
13
// export all dependent file as well to make it easier for users to just import the main file
@@ -39,46 +39,6 @@ interface GridCSSStyleSheet extends CSSStyleSheet {
39
39
_max ?: number ; // internal tracker of the max # of rows we created\
40
40
}
41
41
42
- // default values for grid options - used during init and when saving out
43
- const GridDefaults : GridStackOptions = {
44
- column : 12 ,
45
- minRow : 0 ,
46
- maxRow : 0 ,
47
- itemClass : 'grid-stack-item' ,
48
- placeholderClass : 'grid-stack-placeholder' ,
49
- placeholderText : '' ,
50
- handle : '.grid-stack-item-content' ,
51
- handleClass : null ,
52
- styleInHead : false ,
53
- cellHeight : 'auto' ,
54
- cellHeightThrottle : 100 ,
55
- margin : 10 ,
56
- auto : true ,
57
- oneColumnSize : 768 ,
58
- float : false ,
59
- staticGrid : false ,
60
- animate : true ,
61
- alwaysShowResizeHandle : 'mobile' ,
62
- resizable : {
63
- handles : 'se'
64
- } ,
65
- draggable : {
66
- handle : '.grid-stack-item-content' ,
67
- appendTo : 'body'
68
- } ,
69
- disableDrag : false ,
70
- disableResize : false ,
71
- rtl : 'auto' ,
72
- removable : false ,
73
- removableOptions : {
74
- accept : '.grid-stack-item'
75
- } ,
76
- marginUnit : 'px' ,
77
- cellHeightUnit : 'px' ,
78
- disableOneColumnMode : false ,
79
- oneColumnModeDomSort : false ,
80
- } ;
81
-
82
42
/**
83
43
* Main gridstack class - you will need to call `GridStack.init()` first to initialize your grid.
84
44
* Note: your grid elements MUST have the following classes for the CSS layout to work:
@@ -200,6 +160,11 @@ export class GridStack {
200
160
201
161
protected static engineClass : typeof GridStackEngine ;
202
162
163
+ /** @internal point to a parent grid item if we're nested */
164
+ protected _isNested ?: GridStackNode ;
165
+ /** @internal unique class name for our generated CSS style sheet */
166
+ protected _styleSheetClass ?: string ;
167
+
203
168
/** @internal create placeholder DIV as needed */
204
169
public get placeholder ( ) : HTMLElement {
205
170
if ( ! this . _placeholder ) {
@@ -275,7 +240,6 @@ export class GridStack {
275
240
minRow : rowAttr ? rowAttr : Utils . toNumber ( el . getAttribute ( 'gs-min-row' ) ) || GridDefaults . minRow ,
276
241
maxRow : rowAttr ? rowAttr : Utils . toNumber ( el . getAttribute ( 'gs-max-row' ) ) || GridDefaults . maxRow ,
277
242
staticGrid : Utils . toBool ( el . getAttribute ( 'gs-static' ) ) || GridDefaults . staticGrid ,
278
- _styleSheetClass : 'grid-stack-instance-' + ( Math . random ( ) * 10000 ) . toFixed ( 0 ) ,
279
243
draggable : {
280
244
handle : ( opts . handleClass ? '.' + opts . handleClass : ( opts . handle ? opts . handle : '' ) ) || GridDefaults . draggable . handle ,
281
245
} ,
@@ -307,8 +271,8 @@ export class GridStack {
307
271
// check if we're been nested, and if so update our style and keep pointer around (used during save)
308
272
let parentGridItemEl = Utils . closestByClass ( this . el , GridDefaults . itemClass ) as GridItemHTMLElement ;
309
273
if ( parentGridItemEl && parentGridItemEl . gridstackNode ) {
310
- this . opts . _isNested = parentGridItemEl . gridstackNode ;
311
- this . opts . _isNested . subGrid = this ;
274
+ this . _isNested = parentGridItemEl . gridstackNode ;
275
+ this . _isNested . subGrid = this ;
312
276
parentGridItemEl . classList . add ( 'grid-stack-nested' ) ;
313
277
this . el . classList . add ( 'grid-stack-nested' ) ;
314
278
}
@@ -331,7 +295,8 @@ export class GridStack {
331
295
this . opts . alwaysShowResizeHandle = isTouch ;
332
296
}
333
297
334
- this . el . classList . add ( this . opts . _styleSheetClass ) ;
298
+ this . _styleSheetClass = 'grid-stack-instance-' + ( Math . random ( ) * 10000 ) . toFixed ( 0 )
299
+ this . el . classList . add ( this . _styleSheetClass ) ;
335
300
336
301
this . _setStaticClass ( ) ;
337
302
@@ -771,13 +736,13 @@ export class GridStack {
771
736
this . setAnimation ( false ) ;
772
737
if ( ! removeDOM ) {
773
738
this . removeAll ( removeDOM ) ;
774
- this . el . classList . remove ( this . opts . _styleSheetClass ) ;
739
+ this . el . classList . remove ( this . _styleSheetClass ) ;
775
740
} else {
776
741
this . el . parentNode . removeChild ( this . el ) ;
777
742
}
778
743
this . _removeStylesheet ( ) ;
779
744
this . el . removeAttribute ( 'gs-current-row' ) ;
780
- delete this . opts . _isNested ;
745
+ delete this . _isNested ;
781
746
delete this . opts ;
782
747
delete this . _placeholder ;
783
748
delete this . engine ;
@@ -1207,7 +1172,7 @@ export class GridStack {
1207
1172
1208
1173
let cellHeight = this . opts . cellHeight as number ;
1209
1174
let cellHeightUnit = this . opts . cellHeightUnit ;
1210
- let prefix = `.${ this . opts . _styleSheetClass } > .${ this . opts . itemClass } ` ;
1175
+ let prefix = `.${ this . _styleSheetClass } > .${ this . opts . itemClass } ` ;
1211
1176
1212
1177
// create one as needed
1213
1178
if ( ! this . _styles ) {
@@ -1227,7 +1192,7 @@ export class GridStack {
1227
1192
let right : string = this . opts . marginRight + this . opts . marginUnit ;
1228
1193
let left : string = this . opts . marginLeft + this . opts . marginUnit ;
1229
1194
let content = `${ prefix } > .grid-stack-item-content` ;
1230
- let placeholder = `.${ this . opts . _styleSheetClass } > .grid-stack-placeholder > .placeholder-content` ;
1195
+ let placeholder = `.${ this . _styleSheetClass } > .grid-stack-placeholder > .placeholder-content` ;
1231
1196
Utils . addCSSRule ( this . _styles , content , `top: ${ top } ; right: ${ right } ; bottom: ${ bottom } ; left: ${ left } ;` ) ;
1232
1197
Utils . addCSSRule ( this . _styles , placeholder , `top: ${ top } ; right: ${ right } ; bottom: ${ bottom } ; left: ${ left } ;` ) ;
1233
1198
// resize handles offset (to match margin)
@@ -1389,10 +1354,10 @@ export class GridStack {
1389
1354
let changedColumn = false ;
1390
1355
1391
1356
// see if we're nested and take our column count from our parent....
1392
- if ( this . _autoColumn && this . opts . _isNested ) {
1393
- if ( this . opts . column !== this . opts . _isNested . w ) {
1357
+ if ( this . _autoColumn && this . _isNested ) {
1358
+ if ( this . opts . column !== this . _isNested . w ) {
1394
1359
changedColumn = true ;
1395
- this . column ( this . opts . _isNested . w , 'none' ) ;
1360
+ this . column ( this . _isNested . w , 'none' ) ;
1396
1361
}
1397
1362
} else {
1398
1363
// else check for 1 column in/out behavior
@@ -1429,7 +1394,7 @@ export class GridStack {
1429
1394
/** add or remove the window size event handler */
1430
1395
protected _updateWindowResizeEvent ( forceRemove = false ) : GridStack {
1431
1396
// only add event if we're not nested (parent will call us) and we're auto sizing cells or supporting oneColumn (i.e. doing work)
1432
- const workTodo = ( this . _isAutoCellHeight || ! this . opts . disableOneColumnMode ) && ! this . opts . _isNested ;
1397
+ const workTodo = ( this . _isAutoCellHeight || ! this . opts . disableOneColumnMode ) && ! this . _isNested ;
1433
1398
1434
1399
if ( ! forceRemove && workTodo && ! this . _windowResizeBind ) {
1435
1400
this . _windowResizeBind = this . onParentResize . bind ( this ) ; // so we can properly remove later
0 commit comments