77 */
88import { GridStackEngine } from './gridstack-engine' ;
99import { Utils , HeightData , obsolete } from './utils' ;
10- import { ColumnOptions , GridItemHTMLElement , GridStackElement , GridStackEventHandlerCallback ,
10+ import { GridDefaults , ColumnOptions , GridItemHTMLElement , GridStackElement , GridStackEventHandlerCallback ,
1111 GridStackNode , GridStackOptions , GridStackWidget , numberOrString , DDUIData , DDDragInOpt , GridStackPosition } from './types' ;
1212
1313// 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 {
3939 _max ?: number ; // internal tracker of the max # of rows we created\
4040}
4141
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-
8242/**
8343 * Main gridstack class - you will need to call `GridStack.init()` first to initialize your grid.
8444 * Note: your grid elements MUST have the following classes for the CSS layout to work:
@@ -200,6 +160,11 @@ export class GridStack {
200160
201161 protected static engineClass : typeof GridStackEngine ;
202162
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+
203168 /** @internal create placeholder DIV as needed */
204169 public get placeholder ( ) : HTMLElement {
205170 if ( ! this . _placeholder ) {
@@ -275,7 +240,6 @@ export class GridStack {
275240 minRow : rowAttr ? rowAttr : Utils . toNumber ( el . getAttribute ( 'gs-min-row' ) ) || GridDefaults . minRow ,
276241 maxRow : rowAttr ? rowAttr : Utils . toNumber ( el . getAttribute ( 'gs-max-row' ) ) || GridDefaults . maxRow ,
277242 staticGrid : Utils . toBool ( el . getAttribute ( 'gs-static' ) ) || GridDefaults . staticGrid ,
278- _styleSheetClass : 'grid-stack-instance-' + ( Math . random ( ) * 10000 ) . toFixed ( 0 ) ,
279243 draggable : {
280244 handle : ( opts . handleClass ? '.' + opts . handleClass : ( opts . handle ? opts . handle : '' ) ) || GridDefaults . draggable . handle ,
281245 } ,
@@ -307,8 +271,8 @@ export class GridStack {
307271 // check if we're been nested, and if so update our style and keep pointer around (used during save)
308272 let parentGridItemEl = Utils . closestByClass ( this . el , GridDefaults . itemClass ) as GridItemHTMLElement ;
309273 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 ;
312276 parentGridItemEl . classList . add ( 'grid-stack-nested' ) ;
313277 this . el . classList . add ( 'grid-stack-nested' ) ;
314278 }
@@ -331,7 +295,8 @@ export class GridStack {
331295 this . opts . alwaysShowResizeHandle = isTouch ;
332296 }
333297
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 ) ;
335300
336301 this . _setStaticClass ( ) ;
337302
@@ -771,13 +736,13 @@ export class GridStack {
771736 this . setAnimation ( false ) ;
772737 if ( ! removeDOM ) {
773738 this . removeAll ( removeDOM ) ;
774- this . el . classList . remove ( this . opts . _styleSheetClass ) ;
739+ this . el . classList . remove ( this . _styleSheetClass ) ;
775740 } else {
776741 this . el . parentNode . removeChild ( this . el ) ;
777742 }
778743 this . _removeStylesheet ( ) ;
779744 this . el . removeAttribute ( 'gs-current-row' ) ;
780- delete this . opts . _isNested ;
745+ delete this . _isNested ;
781746 delete this . opts ;
782747 delete this . _placeholder ;
783748 delete this . engine ;
@@ -1207,7 +1172,7 @@ export class GridStack {
12071172
12081173 let cellHeight = this . opts . cellHeight as number ;
12091174 let cellHeightUnit = this . opts . cellHeightUnit ;
1210- let prefix = `.${ this . opts . _styleSheetClass } > .${ this . opts . itemClass } ` ;
1175+ let prefix = `.${ this . _styleSheetClass } > .${ this . opts . itemClass } ` ;
12111176
12121177 // create one as needed
12131178 if ( ! this . _styles ) {
@@ -1227,7 +1192,7 @@ export class GridStack {
12271192 let right : string = this . opts . marginRight + this . opts . marginUnit ;
12281193 let left : string = this . opts . marginLeft + this . opts . marginUnit ;
12291194 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` ;
12311196 Utils . addCSSRule ( this . _styles , content , `top: ${ top } ; right: ${ right } ; bottom: ${ bottom } ; left: ${ left } ;` ) ;
12321197 Utils . addCSSRule ( this . _styles , placeholder , `top: ${ top } ; right: ${ right } ; bottom: ${ bottom } ; left: ${ left } ;` ) ;
12331198 // resize handles offset (to match margin)
@@ -1389,10 +1354,10 @@ export class GridStack {
13891354 let changedColumn = false ;
13901355
13911356 // 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 ) {
13941359 changedColumn = true ;
1395- this . column ( this . opts . _isNested . w , 'none' ) ;
1360+ this . column ( this . _isNested . w , 'none' ) ;
13961361 }
13971362 } else {
13981363 // else check for 1 column in/out behavior
@@ -1429,7 +1394,7 @@ export class GridStack {
14291394 /** add or remove the window size event handler */
14301395 protected _updateWindowResizeEvent ( forceRemove = false ) : GridStack {
14311396 // 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 ;
14331398
14341399 if ( ! forceRemove && workTodo && ! this . _windowResizeBind ) {
14351400 this . _windowResizeBind = this . onParentResize . bind ( this ) ; // so we can properly remove later
0 commit comments