gridstack 11.5.1 → 12.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +16 -3
  2. package/dist/angular/README.md +0 -1
  3. package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
  4. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
  5. package/dist/angular/esm2020/lib/gridstack.component.mjs +2 -2
  6. package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
  7. package/dist/angular/esm2020/lib/types.mjs +2 -2
  8. package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
  9. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  10. package/dist/angular/fesm2020/gridstack-angular.mjs +5 -5
  11. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  12. package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
  13. package/dist/angular/lib/gridstack.component.d.ts +1 -1
  14. package/dist/angular/lib/types.d.ts +1 -1
  15. package/dist/angular/src/base-widget.ts +1 -1
  16. package/dist/angular/src/gridstack-item.component.ts +1 -1
  17. package/dist/angular/src/gridstack.component.ts +1 -1
  18. package/dist/angular/src/gridstack.module.ts +1 -1
  19. package/dist/dd-base-impl.d.ts +1 -1
  20. package/dist/dd-base-impl.js +1 -1
  21. package/dist/dd-base-impl.js.map +1 -1
  22. package/dist/dd-draggable.d.ts +1 -1
  23. package/dist/dd-draggable.js +1 -1
  24. package/dist/dd-draggable.js.map +1 -1
  25. package/dist/dd-droppable.d.ts +1 -1
  26. package/dist/dd-droppable.js +1 -1
  27. package/dist/dd-droppable.js.map +1 -1
  28. package/dist/dd-element.d.ts +1 -1
  29. package/dist/dd-element.js +1 -1
  30. package/dist/dd-element.js.map +1 -1
  31. package/dist/dd-gridstack.d.ts +1 -1
  32. package/dist/dd-gridstack.js +1 -1
  33. package/dist/dd-gridstack.js.map +1 -1
  34. package/dist/dd-manager.d.ts +1 -1
  35. package/dist/dd-manager.js +1 -1
  36. package/dist/dd-manager.js.map +1 -1
  37. package/dist/dd-resizable-handle.d.ts +1 -1
  38. package/dist/dd-resizable-handle.js +1 -1
  39. package/dist/dd-resizable-handle.js.map +1 -1
  40. package/dist/dd-resizable.d.ts +1 -1
  41. package/dist/dd-resizable.js +3 -2
  42. package/dist/dd-resizable.js.map +1 -1
  43. package/dist/dd-touch.d.ts +1 -1
  44. package/dist/dd-touch.js +1 -1
  45. package/dist/dd-touch.js.map +1 -1
  46. package/dist/gridstack-all.js +1 -1
  47. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  48. package/dist/gridstack-all.js.map +1 -1
  49. package/dist/gridstack-engine.d.ts +1 -1
  50. package/dist/gridstack-engine.js +1 -1
  51. package/dist/gridstack-engine.js.map +1 -1
  52. package/dist/gridstack.css +25 -79
  53. package/dist/gridstack.d.ts +6 -5
  54. package/dist/gridstack.js +132 -203
  55. package/dist/gridstack.js.map +1 -1
  56. package/dist/gridstack.min.css +1 -1
  57. package/dist/src/gridstack.scss +22 -21
  58. package/dist/types.d.ts +4 -2
  59. package/dist/types.js +1 -2
  60. package/dist/types.js.map +1 -1
  61. package/dist/utils.d.ts +1 -14
  62. package/dist/utils.js +1 -45
  63. package/dist/utils.js.map +1 -1
  64. package/doc/CHANGES.md +17 -0
  65. package/doc/README.md +0 -3
  66. package/package.json +2 -4
  67. package/dist/angular/node_modules/tslib/README.md +0 -164
  68. package/dist/es5/dd-base-impl.d.ts +0 -20
  69. package/dist/es5/dd-base-impl.js +0 -41
  70. package/dist/es5/dd-base-impl.js.map +0 -1
  71. package/dist/es5/dd-draggable.d.ts +0 -20
  72. package/dist/es5/dd-draggable.js +0 -408
  73. package/dist/es5/dd-draggable.js.map +0 -1
  74. package/dist/es5/dd-droppable.d.ts +0 -26
  75. package/dist/es5/dd-droppable.js +0 -185
  76. package/dist/es5/dd-droppable.js.map +0 -1
  77. package/dist/es5/dd-element.d.ts +0 -27
  78. package/dist/es5/dd-element.js +0 -96
  79. package/dist/es5/dd-element.js.map +0 -1
  80. package/dist/es5/dd-gridstack.d.ts +0 -34
  81. package/dist/es5/dd-gridstack.js +0 -154
  82. package/dist/es5/dd-gridstack.js.map +0 -1
  83. package/dist/es5/dd-manager.d.ts +0 -22
  84. package/dist/es5/dd-manager.js +0 -17
  85. package/dist/es5/dd-manager.js.map +0 -1
  86. package/dist/es5/dd-resizable-handle.d.ts +0 -18
  87. package/dist/es5/dd-resizable-handle.js +0 -117
  88. package/dist/es5/dd-resizable-handle.js.map +0 -1
  89. package/dist/es5/dd-resizable.d.ts +0 -30
  90. package/dist/es5/dd-resizable.js +0 -330
  91. package/dist/es5/dd-resizable.js.map +0 -1
  92. package/dist/es5/dd-touch.d.ts +0 -33
  93. package/dist/es5/dd-touch.js +0 -157
  94. package/dist/es5/dd-touch.js.map +0 -1
  95. package/dist/es5/gridstack-all.js +0 -3
  96. package/dist/es5/gridstack-all.js.LICENSE.txt +0 -7
  97. package/dist/es5/gridstack-all.js.map +0 -1
  98. package/dist/es5/gridstack-engine.d.ts +0 -107
  99. package/dist/es5/gridstack-engine.js +0 -1070
  100. package/dist/es5/gridstack-engine.js.map +0 -1
  101. package/dist/es5/gridstack-poly.js +0 -356
  102. package/dist/es5/gridstack.d.ts +0 -453
  103. package/dist/es5/gridstack.js +0 -2717
  104. package/dist/es5/gridstack.js.map +0 -1
  105. package/dist/es5/types.d.ts +0 -324
  106. package/dist/es5/types.js +0 -39
  107. package/dist/es5/types.js.map +0 -1
  108. package/dist/es5/utils.d.ts +0 -117
  109. package/dist/es5/utils.js +0 -677
  110. package/dist/es5/utils.js.map +0 -1
  111. package/dist/gridstack-extra.css +0 -373
  112. package/dist/gridstack-extra.min.css +0 -1
  113. package/dist/src/gridstack-extra.scss +0 -25
package/dist/gridstack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GridStack 11.5.1
2
+ * GridStack 12.1.0
3
3
  * https://gridstackjs.com/
4
4
  *
5
5
  * Copyright (c) 2021-2024 Alain Dumesny
@@ -178,41 +178,19 @@ class GridStack {
178
178
  if (opts.alwaysShowResizeHandle !== undefined) {
179
179
  opts._alwaysShowResizeHandle = opts.alwaysShowResizeHandle;
180
180
  }
181
- let bk = opts.columnOpts?.breakpoints;
182
- // LEGACY: oneColumnMode stuff changed in v10.x - check if user explicitly set something to convert over
183
- const oldOpts = opts;
184
- if (oldOpts.oneColumnModeDomSort) {
185
- delete oldOpts.oneColumnModeDomSort;
186
- console.log('warning: Gridstack oneColumnModeDomSort no longer supported. Use GridStackOptions.columnOpts instead.');
187
- }
188
- if (oldOpts.oneColumnSize || oldOpts.disableOneColumnMode === false) {
189
- const oneSize = oldOpts.oneColumnSize || 768;
190
- delete oldOpts.oneColumnSize;
191
- delete oldOpts.disableOneColumnMode;
192
- opts.columnOpts = opts.columnOpts || {};
193
- bk = opts.columnOpts.breakpoints = opts.columnOpts.breakpoints || [];
194
- let oneColumn = bk.find(b => b.c === 1);
195
- if (!oneColumn) {
196
- oneColumn = { c: 1, w: oneSize };
197
- bk.push(oneColumn, { c: 12, w: oneSize + 1 });
198
- }
199
- else
200
- oneColumn.w = oneSize;
201
- }
202
- //...end LEGACY
203
181
  // cleanup responsive opts (must have columnWidth | breakpoints) then sort breakpoints by size (so we can match during resize)
204
182
  const resp = opts.columnOpts;
205
183
  if (resp) {
206
- if (!resp.columnWidth && !resp.breakpoints?.length) {
184
+ const bk = resp.breakpoints;
185
+ if (!resp.columnWidth && !bk?.length) {
207
186
  delete opts.columnOpts;
208
- bk = undefined;
209
187
  }
210
188
  else {
211
189
  resp.columnMax = resp.columnMax || 12;
190
+ if (bk?.length > 1)
191
+ bk.sort((a, b) => (b.w || 0) - (a.w || 0));
212
192
  }
213
193
  }
214
- if (bk?.length > 1)
215
- bk.sort((a, b) => (b.w || 0) - (a.w || 0));
216
194
  // elements DOM attributes override any passed options (like CSS style) - merge the two together
217
195
  const defaults = {
218
196
  ...Utils.cloneDeep(gridDefaults),
@@ -234,9 +212,9 @@ class GridStack {
234
212
  }
235
213
  opts = Utils.defaults(opts, defaults);
236
214
  this._initMargin(); // part of settings defaults...
237
- // Now check if we're loading into 1 column mode FIRST so we don't do un-necessary work (like cellHeight = width / 12 then go 1 column)
215
+ // Now check if we're loading into !12 column mode FIRST so we don't do un-necessary work (like cellHeight = width / 12 then go 1 column)
238
216
  this.checkDynamicColumn();
239
- this.el.classList.add('gs-' + opts.column);
217
+ this._updateColumnVar(opts);
240
218
  if (opts.rtl === 'auto') {
241
219
  opts.rtl = (el.style.direction === 'rtl');
242
220
  }
@@ -255,7 +233,7 @@ class GridStack {
255
233
  this._isAutoCellHeight = (opts.cellHeight === 'auto');
256
234
  if (this._isAutoCellHeight || opts.cellHeight === 'initial') {
257
235
  // make the cell content square initially (will use resize/column event to keep it square)
258
- this.cellHeight(undefined, false);
236
+ this.cellHeight(undefined);
259
237
  }
260
238
  else {
261
239
  // append unit if any are set
@@ -263,14 +241,14 @@ class GridStack {
263
241
  opts.cellHeight = opts.cellHeight + opts.cellHeightUnit;
264
242
  delete opts.cellHeightUnit;
265
243
  }
266
- this.cellHeight(opts.cellHeight, false);
244
+ const val = opts.cellHeight;
245
+ delete opts.cellHeight; // force initial cellHeight() call to set the value
246
+ this.cellHeight(val);
267
247
  }
268
248
  // see if we need to adjust auto-hide
269
249
  if (opts.alwaysShowResizeHandle === 'mobile') {
270
250
  opts.alwaysShowResizeHandle = isTouch;
271
251
  }
272
- this._styleSheetClass = 'gs-id-' + GridStackEngine._idSeq++;
273
- this.el.classList.add(this._styleSheetClass);
274
252
  this._setStaticClass();
275
253
  const engineClass = opts.engineClass || GridStack.engineClass || GridStackEngine;
276
254
  this.engine = new engineClass({
@@ -278,8 +256,6 @@ class GridStack {
278
256
  float: opts.float,
279
257
  maxRow: opts.maxRow,
280
258
  onChange: (cbNodes) => {
281
- let maxH = 0;
282
- this.engine.nodes.forEach(n => { maxH = Math.max(maxH, n.y + n.h); });
283
259
  cbNodes.forEach(n => {
284
260
  const el = n.el;
285
261
  if (!el)
@@ -293,11 +269,9 @@ class GridStack {
293
269
  this._writePosAttr(el, n);
294
270
  }
295
271
  });
296
- this._updateStyles(false, maxH); // false = don't recreate, just append if need be
272
+ this._updateContainerHeight();
297
273
  }
298
274
  });
299
- // create initial global styles BEFORE loading children so resizeToContent margin can be calculated correctly
300
- this._updateStyles(false, 0);
301
275
  if (opts.auto) {
302
276
  this.batchUpdate(); // prevent in between re-layout #1535 TODO: this only set float=true, need to prevent collision check...
303
277
  this.engine._loading = true; // loading collision check
@@ -312,7 +286,6 @@ class GridStack {
312
286
  if (children.length)
313
287
  this.load(children); // don't load empty
314
288
  }
315
- // if (this.engine.nodes.length) this._updateStyles(); // update based on # of children. done in engine onChange CB
316
289
  this.setAnimation();
317
290
  // dynamic grids require pausing during drag to detect over to nest vs push
318
291
  if (opts.subGridDynamic && !DDManager.pauseDrag)
@@ -323,6 +296,11 @@ class GridStack {
323
296
  this._setupAcceptWidget();
324
297
  this._updateResizeEvent();
325
298
  }
299
+ _updateColumnVar(opts = this.opts) {
300
+ this.el.classList.add('gs-' + opts.column);
301
+ if (typeof opts.column === 'number')
302
+ this.el.style.setProperty('--gs-column-width', `${100 / opts.column}%`);
303
+ }
326
304
  /**
327
305
  * add a new widget and returns it.
328
306
  *
@@ -604,8 +582,18 @@ class GridStack {
604
582
  items.forEach(n => { maxColumn = Math.max(maxColumn, (n.x || 0) + n.w); });
605
583
  if (maxColumn > this.engine.defaultColumn)
606
584
  this.engine.defaultColumn = maxColumn;
607
- if (maxColumn > column)
608
- this.engine.cacheLayout(items, maxColumn, true);
585
+ if (maxColumn > column) {
586
+ // if we're loading (from empty) into a smaller column, check for special responsive layout
587
+ if (this.engine.nodes.length === 0 && this.responseLayout) {
588
+ this.engine.nodes = items;
589
+ this.engine.columnChanged(maxColumn, column, this.responseLayout);
590
+ items = this.engine.nodes;
591
+ this.engine.nodes = [];
592
+ delete this.responseLayout;
593
+ }
594
+ else
595
+ this.engine.cacheLayout(items, maxColumn, true);
596
+ }
609
597
  // if given a different callback, temporally set it as global option so creating will use it
610
598
  const prevCB = GridStack.addRemoveCB;
611
599
  if (typeof (addRemove) === 'function')
@@ -738,16 +726,15 @@ class GridStack {
738
726
  *
739
727
  * @param val the cell height. If not passed (undefined), cells content will be made square (match width minus margin),
740
728
  * if pass 0 the CSS will be generated by the application instead.
741
- * @param update (Optional) if false, styles will not be updated
742
729
  *
743
730
  * @example
744
731
  * grid.cellHeight(100); // same as 100px
745
732
  * grid.cellHeight('70px');
746
733
  * grid.cellHeight(grid.cellWidth() * 1.2);
747
734
  */
748
- cellHeight(val, update = true) {
735
+ cellHeight(val) {
749
736
  // if not called internally, check if we're changing mode
750
- if (update && val !== undefined) {
737
+ if (val !== undefined) {
751
738
  if (this._isAutoCellHeight !== (val === 'auto')) {
752
739
  this._isAutoCellHeight = (val === 'auto');
753
740
  this._updateResizeEvent();
@@ -768,10 +755,10 @@ class GridStack {
768
755
  }
769
756
  this.opts.cellHeightUnit = data.unit;
770
757
  this.opts.cellHeight = data.h;
758
+ // finally update var and container
759
+ this.el.style.setProperty('--gs-cell-height', `${this.opts.cellHeight}${this.opts.cellHeightUnit}`);
760
+ this._updateContainerHeight();
771
761
  this.resizeToContentCheck();
772
- if (update) {
773
- this._updateStyles(true); // true = force re-create for current # of rows
774
- }
775
762
  return this;
776
763
  }
777
764
  /** Gets current cell width. */
@@ -825,8 +812,6 @@ class GridStack {
825
812
  /**
826
813
  * set the number of columns in the grid. Will update existing widgets to conform to new number of columns,
827
814
  * as well as cache the original layout so you can revert back to previous positions without loss.
828
- * Requires `gridstack-extra.css` or `gridstack-extra.min.css` for [2-11],
829
- * else you will need to generate correct CSS (see https://github.com/gridstack/gridstack.js#change-grid-columns)
830
815
  * @param column - Integer > 0 (default 12).
831
816
  * @param layout specify the type of re-layout that will happen (position, size, etc...).
832
817
  * Note: items will never be outside of the current column boundaries. default ('moveScale'). Ignored for 1 column
@@ -836,15 +821,16 @@ class GridStack {
836
821
  return this;
837
822
  const oldColumn = this.getColumn();
838
823
  this.opts.column = column;
839
- if (!this.engine)
840
- return this; // called in constructor, noting else to do
824
+ if (!this.engine) {
825
+ // called in constructor, noting else to do but remember that breakpoint layout
826
+ this.responseLayout = layout;
827
+ return this;
828
+ }
841
829
  this.engine.column = column;
842
830
  this.el.classList.remove('gs-' + oldColumn);
843
- this.el.classList.add('gs-' + column);
844
- // update the items now, checking if we have a custom children layout
845
- /*const newChildren = this.opts.columnOpts?.breakpoints?.find(r => r.c === column)?.children;
846
- if (newChildren) this.load(newChildren);
847
- else*/ this.engine.columnChanged(oldColumn, column, layout);
831
+ this._updateColumnVar();
832
+ // update the items now
833
+ this.engine.columnChanged(oldColumn, column, layout);
848
834
  if (this._isAutoCellHeight)
849
835
  this.cellHeight();
850
836
  this.resizeToContentCheck(true); // wait for width resizing
@@ -878,14 +864,13 @@ class GridStack {
878
864
  this.setAnimation(false);
879
865
  if (!removeDOM) {
880
866
  this.removeAll(removeDOM);
881
- this.el.classList.remove(this._styleSheetClass);
882
867
  this.el.removeAttribute('gs-current-row');
883
868
  }
884
869
  else {
885
870
  this.el.parentNode.removeChild(this.el);
886
871
  }
887
- this._removeStylesheet();
888
- delete this.parentGridNode?.subGrid;
872
+ if (this.parentGridNode)
873
+ delete this.parentGridNode.subGrid;
889
874
  delete this.parentGridNode;
890
875
  delete this.opts;
891
876
  delete this._placeholder?.gridstackNode;
@@ -967,8 +952,8 @@ class GridStack {
967
952
  */
968
953
  makeWidget(els, options) {
969
954
  const el = GridStack.getElement(els);
970
- if (!el)
971
- return;
955
+ if (!el || el.gridstackNode)
956
+ return el;
972
957
  if (!el.parentElement)
973
958
  this.el.appendChild(el);
974
959
  this._prepareElement(el, true, options);
@@ -1120,6 +1105,7 @@ class GridStack {
1120
1105
  else {
1121
1106
  this.el.classList.remove('grid-stack-animate');
1122
1107
  }
1108
+ this.opts.animate = doAnimate;
1123
1109
  return this;
1124
1110
  }
1125
1111
  /** @internal */
@@ -1154,23 +1140,33 @@ class GridStack {
1154
1140
  */
1155
1141
  updateOptions(o) {
1156
1142
  const opts = this.opts;
1157
- if (o.acceptWidgets !== undefined)
1143
+ if (o === opts)
1144
+ return this; // nothing to do
1145
+ if (o.acceptWidgets !== undefined) {
1146
+ opts.acceptWidgets = o.acceptWidgets;
1158
1147
  this._setupAcceptWidget();
1159
- if (o.animate !== undefined)
1160
- this.setAnimation();
1161
- if (o.cellHeight) {
1162
- this.cellHeight(o.cellHeight, true);
1163
- delete o.cellHeight;
1164
1148
  }
1165
- if (o.class && o.class !== opts.class) {
1149
+ if (o.animate !== undefined)
1150
+ this.setAnimation(o.animate);
1151
+ if (o.cellHeight)
1152
+ this.cellHeight(o.cellHeight);
1153
+ if (o.class !== undefined && o.class !== opts.class) {
1166
1154
  if (opts.class)
1167
1155
  this.el.classList.remove(opts.class);
1168
- this.el.classList.add(o.class);
1156
+ if (o.class)
1157
+ this.el.classList.add(o.class);
1158
+ }
1159
+ // responsive column take over actual count (keep what we have now)
1160
+ if (o.columnOpts) {
1161
+ this.opts.columnOpts = o.columnOpts;
1162
+ this.checkDynamicColumn();
1169
1163
  }
1170
- if (typeof (o.column) === 'number' && !o.columnOpts) {
1164
+ else if (o.columnOpts === null && this.opts.columnOpts) {
1165
+ delete this.opts.columnOpts;
1166
+ this._updateResizeEvent();
1167
+ }
1168
+ else if (typeof (o.column) === 'number')
1171
1169
  this.column(o.column);
1172
- delete o.column;
1173
- } // responsive column take over actual count
1174
1170
  if (o.margin !== undefined)
1175
1171
  this.margin(o.margin);
1176
1172
  if (o.staticGrid !== undefined)
@@ -1182,16 +1178,18 @@ class GridStack {
1182
1178
  if (o.float !== undefined)
1183
1179
  this.float(o.float);
1184
1180
  if (o.row !== undefined) {
1185
- opts.minRow = opts.maxRow = o.row;
1181
+ opts.minRow = opts.maxRow = opts.row = o.row;
1186
1182
  }
1187
- if (o.children?.length) {
1188
- this.load(o.children);
1189
- delete o.children;
1183
+ else {
1184
+ if (opts.minRow !== undefined)
1185
+ opts.minRow = o.minRow;
1186
+ if (opts.maxRow !== undefined)
1187
+ opts.maxRow = o.maxRow;
1190
1188
  }
1189
+ if (o.children?.length)
1190
+ this.load(o.children);
1191
1191
  // TBD if we have a real need for these (more complex code)
1192
1192
  // alwaysShowResizeHandle, draggable, handle, handleClass, itemClass, layout, placeholderClass, placeholderText, resizable, removable, row,...
1193
- // rest are just copied over...
1194
- this.opts = { ...this.opts, ...o };
1195
1193
  return this;
1196
1194
  }
1197
1195
  /**
@@ -1230,8 +1228,7 @@ class GridStack {
1230
1228
  // restore any sub-grid back
1231
1229
  if (n.subGrid?.el) {
1232
1230
  itemContent.appendChild(n.subGrid.el);
1233
- if (!n.subGrid.opts.styleInHead)
1234
- n.subGrid._updateStyles(true); // force create
1231
+ n.subGrid._updateContainerHeight();
1235
1232
  }
1236
1233
  }
1237
1234
  delete w.content;
@@ -1316,7 +1313,7 @@ class GridStack {
1316
1313
  // sub-grid - use their actual row count * their cell height, BUT append any content outside of the grid (eg: above text)
1317
1314
  wantedH = n.subGrid.getRow() * n.subGrid.getCellHeight(true);
1318
1315
  const subRec = n.subGrid.el.getBoundingClientRect();
1319
- const parentRec = n.subGrid.el.parentElement.getBoundingClientRect();
1316
+ const parentRec = el.getBoundingClientRect();
1320
1317
  wantedH += subRec.top - parentRec.top;
1321
1318
  }
1322
1319
  else if (n.subGridOpts?.children?.length) {
@@ -1390,7 +1387,7 @@ class GridStack {
1390
1387
  */
1391
1388
  margin(value) {
1392
1389
  const isMultiValue = (typeof value === 'string' && value.split(' ').length > 1);
1393
- // check if we can skip re-creating our CSS file... won't check if multi values (too much hassle)
1390
+ // check if we can skip... won't check if multi values (too much hassle)
1394
1391
  if (!isMultiValue) {
1395
1392
  const data = Utils.parseHeight(value);
1396
1393
  if (this.opts.marginUnit === data.unit && this.opts.margin === data.h)
@@ -1400,7 +1397,6 @@ class GridStack {
1400
1397
  this.opts.margin = value;
1401
1398
  this.opts.marginTop = this.opts.marginBottom = this.opts.marginLeft = this.opts.marginRight = undefined;
1402
1399
  this._initMargin();
1403
- this._updateStyles(true); // true = force re-create
1404
1400
  return this;
1405
1401
  }
1406
1402
  /** returns current margin number value (undefined if 4 sides don't match) */
@@ -1472,75 +1468,12 @@ class GridStack {
1472
1468
  /** @internal */
1473
1469
  _triggerEvent(type, data) {
1474
1470
  const event = data ? new CustomEvent(type, { bubbles: false, detail: data }) : new Event(type);
1475
- this.el.dispatchEvent(event);
1476
- return this;
1477
- }
1478
- /** @internal called to delete the current dynamic style sheet used for our layout */
1479
- _removeStylesheet() {
1480
- if (this._styles) {
1481
- const styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode;
1482
- Utils.removeStylesheet(this._styleSheetClass, styleLocation);
1483
- delete this._styles;
1484
- }
1485
- return this;
1486
- }
1487
- /** @internal updated/create the CSS styles for row based layout and initial margin setting */
1488
- _updateStyles(forceUpdate = false, maxH) {
1489
- // call to delete existing one if we change cellHeight / margin
1490
- if (forceUpdate) {
1491
- this._removeStylesheet();
1492
- }
1493
- if (maxH === undefined)
1494
- maxH = this.getRow();
1495
- this._updateContainerHeight();
1496
- // if user is telling us they will handle the CSS themselves by setting heights to 0. Do we need this opts really ??
1497
- if (this.opts.cellHeight === 0) {
1498
- return this;
1499
- }
1500
- const cellHeight = this.opts.cellHeight;
1501
- const cellHeightUnit = this.opts.cellHeightUnit;
1502
- const prefix = `.${this._styleSheetClass} > .${this.opts.itemClass}`;
1503
- // create one as needed
1504
- if (!this._styles) {
1505
- // insert style to parent (instead of 'head' by default) to support WebComponent
1506
- const styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode;
1507
- this._styles = Utils.createStylesheet(this._styleSheetClass, styleLocation, {
1508
- nonce: this.opts.nonce,
1509
- });
1510
- if (!this._styles)
1511
- return this;
1512
- this._styles._max = 0;
1513
- // these are done once only
1514
- Utils.addCSSRule(this._styles, prefix, `height: ${cellHeight}${cellHeightUnit}`);
1515
- // content margins
1516
- const top = this.opts.marginTop + this.opts.marginUnit;
1517
- const bottom = this.opts.marginBottom + this.opts.marginUnit;
1518
- const right = this.opts.marginRight + this.opts.marginUnit;
1519
- const left = this.opts.marginLeft + this.opts.marginUnit;
1520
- const content = `${prefix} > .grid-stack-item-content`;
1521
- const placeholder = `.${this._styleSheetClass} > .grid-stack-placeholder > .placeholder-content`;
1522
- Utils.addCSSRule(this._styles, content, `top: ${top}; right: ${right}; bottom: ${bottom}; left: ${left};`);
1523
- Utils.addCSSRule(this._styles, placeholder, `top: ${top}; right: ${right}; bottom: ${bottom}; left: ${left};`);
1524
- // resize handles offset (to match margin)
1525
- Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-n`, `top: ${top};`);
1526
- Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-s`, `bottom: ${bottom}`);
1527
- Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-ne`, `right: ${right}; top: ${top}`);
1528
- Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-e`, `right: ${right}`);
1529
- Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-se`, `right: ${right}; bottom: ${bottom}`);
1530
- Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-nw`, `left: ${left}; top: ${top}`);
1531
- Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-w`, `left: ${left}`);
1532
- Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-sw`, `left: ${left}; bottom: ${bottom}`);
1533
- }
1534
- // now update the height specific fields
1535
- maxH = maxH || this._styles._max;
1536
- if (maxH > this._styles._max) {
1537
- const getHeight = (rows) => (cellHeight * rows) + cellHeightUnit;
1538
- for (let i = this._styles._max + 1; i <= maxH; i++) { // start at 1
1539
- Utils.addCSSRule(this._styles, `${prefix}[gs-y="${i}"]`, `top: ${getHeight(i)}`);
1540
- Utils.addCSSRule(this._styles, `${prefix}[gs-h="${i + 1}"]`, `height: ${getHeight(i + 1)}`); // start at 2
1541
- }
1542
- this._styles._max = maxH;
1543
- }
1471
+ // check if we're nested, and if so call the outermost grid to trigger the event
1472
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
1473
+ let grid = this;
1474
+ while (grid.parentGridNode)
1475
+ grid = grid.parentGridNode.grid;
1476
+ grid.el.dispatchEvent(event);
1544
1477
  return this;
1545
1478
  }
1546
1479
  /** @internal */
@@ -1594,14 +1527,19 @@ class GridStack {
1594
1527
  this.prepareDragDrop(node.el);
1595
1528
  return this;
1596
1529
  }
1597
- /** @internal call to write position x,y,w,h attributes back to element */
1530
+ /** @internal write position CSS vars and x,y,w,h attributes (not used for CSS but by users) back to element */
1598
1531
  _writePosAttr(el, n) {
1599
- if (n.x !== undefined && n.x !== null) {
1600
- el.setAttribute('gs-x', String(n.x));
1601
- }
1602
- if (n.y !== undefined && n.y !== null) {
1603
- el.setAttribute('gs-y', String(n.y));
1604
- }
1532
+ // Avoid overwriting the inline style of the element during drag/resize, but always update the placeholder
1533
+ if ((!n._moving && !n._resizing) || this._placeholder === el) {
1534
+ // width/height:1 x/y:0 is set by default in the main CSS, so no need to set inlined vars
1535
+ el.style.top = n.y ? (n.y === 1 ? `var(--gs-cell-height)` : `calc(${n.y} * var(--gs-cell-height))`) : null;
1536
+ el.style.left = n.x ? (n.x === 1 ? `var(--gs-column-width)` : `calc(${n.x} * var(--gs-column-width))`) : null;
1537
+ el.style.width = n.w > 1 ? `calc(${n.w} * var(--gs-column-width))` : null;
1538
+ el.style.height = n.h > 1 ? `calc(${n.h} * var(--gs-cell-height))` : null;
1539
+ }
1540
+ // NOTE: those are technically not needed anymore (v12+) as we have CSS vars for everything, but some users depends on them to render item size using CSS
1541
+ n.x > 0 ? el.setAttribute('gs-x', String(n.x)) : el.removeAttribute('gs-x');
1542
+ n.y > 0 ? el.setAttribute('gs-y', String(n.y)) : el.removeAttribute('gs-y');
1605
1543
  n.w > 1 ? el.setAttribute('gs-w', String(n.w)) : el.removeAttribute('gs-w');
1606
1544
  n.h > 1 ? el.setAttribute('gs-h', String(n.h)) : el.removeAttribute('gs-h');
1607
1545
  return this;
@@ -1749,7 +1687,9 @@ class GridStack {
1749
1687
  if (Utils.shouldSizeToContent(n))
1750
1688
  this.resizeToContentCBCheck(n.el);
1751
1689
  });
1690
+ this._ignoreLayoutsNodeChange = true; // loop through each node will set/reset around each move, so set it here again
1752
1691
  this.batchUpdate(false);
1692
+ this._ignoreLayoutsNodeChange = false;
1753
1693
  }
1754
1694
  // call this regardless of shouldSizeToContent because widget might need to stretch to take available space after a resize
1755
1695
  if (this._gsEventHandler['resizecontent'])
@@ -1807,42 +1747,27 @@ class GridStack {
1807
1747
  margin = this.opts.margin = data.h;
1808
1748
  }
1809
1749
  // see if top/bottom/left/right need to be set as well
1810
- if (this.opts.marginTop === undefined) {
1811
- this.opts.marginTop = margin;
1812
- }
1813
- else {
1814
- data = Utils.parseHeight(this.opts.marginTop);
1815
- this.opts.marginTop = data.h;
1816
- delete this.opts.margin;
1817
- }
1818
- if (this.opts.marginBottom === undefined) {
1819
- this.opts.marginBottom = margin;
1820
- }
1821
- else {
1822
- data = Utils.parseHeight(this.opts.marginBottom);
1823
- this.opts.marginBottom = data.h;
1824
- delete this.opts.margin;
1825
- }
1826
- if (this.opts.marginRight === undefined) {
1827
- this.opts.marginRight = margin;
1828
- }
1829
- else {
1830
- data = Utils.parseHeight(this.opts.marginRight);
1831
- this.opts.marginRight = data.h;
1832
- delete this.opts.margin;
1833
- }
1834
- if (this.opts.marginLeft === undefined) {
1835
- this.opts.marginLeft = margin;
1836
- }
1837
- else {
1838
- data = Utils.parseHeight(this.opts.marginLeft);
1839
- this.opts.marginLeft = data.h;
1840
- delete this.opts.margin;
1841
- }
1750
+ const keys = ['marginTop', 'marginRight', 'marginBottom', 'marginLeft'];
1751
+ keys.forEach(k => {
1752
+ if (this.opts[k] === undefined) {
1753
+ this.opts[k] = margin;
1754
+ }
1755
+ else {
1756
+ data = Utils.parseHeight(this.opts[k]);
1757
+ this.opts[k] = data.h;
1758
+ delete this.opts.margin;
1759
+ }
1760
+ });
1842
1761
  this.opts.marginUnit = data.unit; // in case side were spelled out, use those units instead...
1843
1762
  if (this.opts.marginTop === this.opts.marginBottom && this.opts.marginLeft === this.opts.marginRight && this.opts.marginTop === this.opts.marginRight) {
1844
1763
  this.opts.margin = this.opts.marginTop; // makes it easier to check for no-ops in setMargin()
1845
1764
  }
1765
+ // finally Update the CSS margin variables (inside the cell height) */
1766
+ const style = this.el.style;
1767
+ style.setProperty('--gs-item-margin-top', `${this.opts.marginTop}${this.opts.marginUnit}`);
1768
+ style.setProperty('--gs-item-margin-bottom', `${this.opts.marginBottom}${this.opts.marginUnit}`);
1769
+ style.setProperty('--gs-item-margin-right', `${this.opts.marginRight}${this.opts.marginUnit}`);
1770
+ style.setProperty('--gs-item-margin-left', `${this.opts.marginLeft}${this.opts.marginUnit}`);
1846
1771
  return this;
1847
1772
  }
1848
1773
  /* ===========================================================================================
@@ -2252,8 +2177,6 @@ class GridStack {
2252
2177
  this.resizeToContentCheck(false, node);
2253
2178
  if (subGrid) {
2254
2179
  subGrid.parentGridNode = node;
2255
- if (!subGrid.opts.styleInHead)
2256
- subGrid._updateStyles(true); // re-create sub-grid styles now that we've moved
2257
2180
  }
2258
2181
  this._updateContainerHeight();
2259
2182
  }
@@ -2328,9 +2251,7 @@ class GridStack {
2328
2251
  /** called when item starts moving/resizing */
2329
2252
  const onStartMoving = (event, ui) => {
2330
2253
  // trigger any 'dragstart' / 'resizestart' manually
2331
- if (this._gsEventHandler[event.type]) {
2332
- this._gsEventHandler[event.type](event, event.target);
2333
- }
2254
+ this.triggerEvent(event, event.target);
2334
2255
  cellWidth = this.cellWidth();
2335
2256
  cellHeight = this.getCellHeight(true); // force pixels for calculations
2336
2257
  this._onStartMoving(el, event, ui, node, cellWidth, cellHeight);
@@ -2344,6 +2265,7 @@ class GridStack {
2344
2265
  this.placeholder.remove();
2345
2266
  delete this.placeholder.gridstackNode;
2346
2267
  delete node._moving;
2268
+ delete node._resizing;
2347
2269
  delete node._event;
2348
2270
  delete node._lastTried;
2349
2271
  const widthChanged = node.w !== node._orig.w;
@@ -2372,9 +2294,7 @@ class GridStack {
2372
2294
  // move to new placeholder location
2373
2295
  this._writePosAttr(target, node);
2374
2296
  }
2375
- if (this._gsEventHandler[event.type]) {
2376
- this._gsEventHandler[event.type](event, target);
2377
- }
2297
+ this.triggerEvent(event, target);
2378
2298
  }
2379
2299
  // @ts-ignore
2380
2300
  this._extraDragRow = 0; // @ts-ignore
@@ -2436,6 +2356,7 @@ class GridStack {
2436
2356
  node._lastUiPosition = ui.position;
2437
2357
  node._prevYPix = ui.position.top;
2438
2358
  node._moving = (event.type === 'dragstart'); // 'dropover' are not initially moving so they can go exactly where they enter (will push stuff out of the way)
2359
+ node._resizing = (event.type === 'resizestart');
2439
2360
  delete node._lastTried;
2440
2361
  if (event.type === 'dropover' && node._temporaryRemoved) {
2441
2362
  // console.log('engine.addNode x=' + node.x); // TEST
@@ -2538,9 +2459,17 @@ class GridStack {
2538
2459
  if (!node._sidebarOrig) {
2539
2460
  this._writePosAttr(target, node);
2540
2461
  }
2541
- if (this._gsEventHandler[event.type]) {
2542
- this._gsEventHandler[event.type](event, target);
2543
- }
2462
+ this.triggerEvent(event, target);
2463
+ }
2464
+ }
2465
+ /** call given event callback on our main top-most grid (if we're nested) */
2466
+ triggerEvent(event, target) {
2467
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
2468
+ let grid = this;
2469
+ while (grid.parentGridNode)
2470
+ grid = grid.parentGridNode.grid;
2471
+ if (grid._gsEventHandler[event.type]) {
2472
+ grid._gsEventHandler[event.type](event, target);
2544
2473
  }
2545
2474
  }
2546
2475
  /** @internal called when item leaving our area by either cursor dropout event
@@ -2596,6 +2525,6 @@ GridStack.resizeToContentParent = '.grid-stack-item-content';
2596
2525
  GridStack.Utils = Utils;
2597
2526
  /** scoping so users can call new GridStack.Engine(12) for example */
2598
2527
  GridStack.Engine = GridStackEngine;
2599
- GridStack.GDRev = '11.5.1';
2528
+ GridStack.GDRev = '12.1.0';
2600
2529
  export { GridStack };
2601
2530
  //# sourceMappingURL=gridstack.js.map