@@ -43,7 +43,8 @@ export interface CellPosition {
43
43
}
44
44
45
45
interface GridCSSStyleSheet extends CSSStyleSheet {
46
- _max ?: number ; // internal tracker of the max # of rows we created
46
+ _id ?: string ; // random id we will use to style us
47
+ _max ?: number ; // internal tracker of the max # of rows we created\
47
48
}
48
49
49
50
/**
@@ -137,8 +138,6 @@ export class GridStack {
137
138
/** @internal */
138
139
private _prevColumn : number ;
139
140
/** @internal */
140
- private _stylesId : string ;
141
- /** @internal */
142
141
private _gsEventHandler = { } ;
143
142
/** @internal */
144
143
private _styles : GridCSSStyleSheet ;
@@ -191,7 +190,7 @@ export class GridStack {
191
190
float : false ,
192
191
staticGrid : false ,
193
192
_class : 'grid-stack-instance-' + ( Math . random ( ) * 10000 ) . toFixed ( 0 ) ,
194
- animate : Utils . toBool ( el . getAttribute ( 'data-gs-animate' ) ) || false ,
193
+ animate : true ,
195
194
alwaysShowResizeHandle : false ,
196
195
resizable : {
197
196
autoHide : ! ( opts . alwaysShowResizeHandle || false ) ,
@@ -222,6 +221,9 @@ export class GridStack {
222
221
disableOneColumnMode : false ,
223
222
oneColumnModeDomSort : false
224
223
} ;
224
+ if ( el . getAttribute ( 'data-gs-animate' ) ) {
225
+ defaults . animate = Utils . toBool ( el . getAttribute ( 'data-gs-animate' ) )
226
+ }
225
227
226
228
this . opts = Utils . defaults ( opts , defaults ) ;
227
229
this . initMargin ( ) ;
@@ -259,8 +261,7 @@ export class GridStack {
259
261
this . el . classList . add ( this . opts . _class ) ;
260
262
261
263
this . _setStaticClass ( ) ;
262
-
263
- this . _initStyles ( ) ;
264
+ this . _updateStyles ( ) ;
264
265
265
266
this . engine = new GridStackEngine ( this . opts . column , ( cbNodes , removeDOM = true ) => {
266
267
let maxHeight = 0 ;
@@ -273,7 +274,7 @@ export class GridStack {
273
274
this . _writeAttrs ( el , n . x , n . y , n . width , n . height ) ;
274
275
}
275
276
} ) ;
276
- this . _updateStyles ( maxHeight + 10 ) ;
277
+ this . _updateStyles ( false , maxHeight ) ; // false = don't recreate, just append if need be
277
278
} ,
278
279
this . opts . float ,
279
280
this . opts . maxRow ) ;
@@ -451,7 +452,7 @@ export class GridStack {
451
452
this . opts . cellHeight = data . height ;
452
453
453
454
if ( update ) {
454
- this . _updateStyles ( ) ;
455
+ this . _updateStyles ( true ) ; // true = force re-create
455
456
}
456
457
this . _resizeNestedGrids ( this . el ) ;
457
458
return this ;
@@ -551,7 +552,7 @@ export class GridStack {
551
552
} else {
552
553
this . el . parentNode . removeChild ( this . el ) ;
553
554
}
554
- Utils . removeStylesheet ( this . _stylesId ) ;
555
+ this . _removeStylesheet ( ) ;
555
556
delete this . engine ;
556
557
return this ;
557
558
}
@@ -1002,7 +1003,7 @@ export class GridStack {
1002
1003
this . opts . marginLeft =
1003
1004
this . opts . marginRight =
1004
1005
this . opts . margin = data . height ;
1005
- this . _updateStyles ( ) ;
1006
+ this . _updateStyles ( true ) ; // true = force re-create
1006
1007
1007
1008
return this ;
1008
1009
}
@@ -1075,43 +1076,43 @@ export class GridStack {
1075
1076
return this ;
1076
1077
}
1077
1078
1078
- /** @internal */
1079
- private _initStyles ( ) : GridStack {
1080
- if ( this . _stylesId ) {
1081
- Utils . removeStylesheet ( this . _stylesId ) ;
1082
- }
1083
- this . _stylesId = 'gridstack-style-' + ( Math . random ( ) * 100000 ) . toFixed ( ) ;
1084
- // insert style to parent (instead of 'head' by default) to support WebComponent
1085
- let styleLocation = this . opts . styleInHead ? undefined : this . el . parentNode as HTMLElement ;
1086
- this . _styles = Utils . createStylesheet ( this . _stylesId , styleLocation ) ;
1087
- if ( this . _styles !== null ) {
1088
- this . _styles . _max = 0 ;
1079
+ /** @internal called to delete the current dynamic style sheet used for our layout */
1080
+ private _removeStylesheet ( ) : GridStack {
1081
+
1082
+ if ( this . _styles ) {
1083
+ Utils . removeStylesheet ( this . _styles . _id ) ;
1084
+ delete this . _styles ;
1089
1085
}
1090
1086
return this ;
1091
1087
}
1092
1088
1093
- /** @internal updated the CSS styles for row based layout and initial margin setting */
1094
- private _updateStyles ( maxHeight ?: number ) : GridStack {
1095
- if ( ! this . _styles ) {
1096
- return this ;
1097
- }
1098
- if ( maxHeight === undefined ) {
1099
- maxHeight = this . _styles . _max ;
1089
+ /** @internal updated/create the CSS styles for row based layout and initial margin setting */
1090
+ private _updateStyles ( forceUpdate = false , maxHeight ?: number ) : GridStack {
1091
+ // call to delete existing one if we change cellHeight / margin
1092
+ if ( forceUpdate ) {
1093
+ this . _removeStylesheet ( ) ;
1100
1094
}
1101
- this . _initStyles ( ) ;
1095
+
1102
1096
this . _updateContainerHeight ( ) ;
1103
- if ( ! this . opts . cellHeight ) { // The rest will be handled by CSS
1104
- return this ;
1105
- }
1106
- if ( this . _styles . _max !== 0 && maxHeight <= this . _styles . _max ) { // Keep it increasing
1097
+ if ( ! this . opts . cellHeight ) { // The rest will be handled by CSS TODO: I don't understand this usage
1107
1098
return this ;
1108
1099
}
1100
+
1109
1101
let cellHeight = this . opts . cellHeight as number ;
1110
1102
let cellHeightUnit = this . opts . cellHeightUnit ;
1111
1103
let prefix = `.${ this . opts . _class } > .${ this . opts . itemClass } ` ;
1112
1104
1113
- // these are done once only
1114
- if ( this . _styles . _max === 0 ) {
1105
+ // create one as needed
1106
+ if ( ! this . _styles ) {
1107
+ let id = 'gridstack-style-' + ( Math . random ( ) * 100000 ) . toFixed ( ) ;
1108
+ // insert style to parent (instead of 'head' by default) to support WebComponent
1109
+ let styleLocation = this . opts . styleInHead ? undefined : this . el . parentNode as HTMLElement ;
1110
+ this . _styles = Utils . createStylesheet ( id , styleLocation ) ;
1111
+ if ( ! this . _styles ) { return this ; }
1112
+ this . _styles . _id = id ;
1113
+ this . _styles . _max = 0 ;
1114
+
1115
+ // these are done once only
1115
1116
Utils . addCSSRule ( this . _styles , prefix , `min-height: ${ cellHeight } ${ cellHeightUnit } ` ) ;
1116
1117
// content margins
1117
1118
let top : string = this . opts . marginTop + this . opts . marginUnit ;
@@ -1131,6 +1132,8 @@ export class GridStack {
1131
1132
Utils . addCSSRule ( this . _styles , `${ prefix } > .ui-resizable-sw` , `left: ${ left } ; bottom: ${ bottom } ` ) ;
1132
1133
}
1133
1134
1135
+ // now update the height specific fields
1136
+ maxHeight = maxHeight || this . _styles . _max ;
1134
1137
if ( maxHeight > this . _styles . _max ) {
1135
1138
let getHeight = ( rows : number ) : string => ( cellHeight * rows ) + cellHeightUnit ;
1136
1139
for ( let i = this . _styles . _max + 1 ; i <= maxHeight ; i ++ ) { // start at 1
@@ -1147,7 +1150,7 @@ export class GridStack {
1147
1150
1148
1151
/** @internal */
1149
1152
private _updateContainerHeight ( ) : GridStack {
1150
- if ( this . engine . batchMode ) { return this ; }
1153
+ if ( ! this . engine || this . engine . batchMode ) { return this ; }
1151
1154
let row = this . getRow ( ) ; // checks for minRow already
1152
1155
// check for css min height
1153
1156
let cssMinHeight = parseInt ( getComputedStyle ( this . el ) [ 'min-height' ] ) ;
0 commit comments