gridstack 11.5.1 → 12.0.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 +15 -2
  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/es5/dd-base-impl.d.ts +1 -1
  47. package/dist/es5/dd-base-impl.js +1 -1
  48. package/dist/es5/dd-base-impl.js.map +1 -1
  49. package/dist/es5/dd-draggable.d.ts +1 -1
  50. package/dist/es5/dd-draggable.js +1 -1
  51. package/dist/es5/dd-draggable.js.map +1 -1
  52. package/dist/es5/dd-droppable.d.ts +1 -1
  53. package/dist/es5/dd-droppable.js +1 -1
  54. package/dist/es5/dd-droppable.js.map +1 -1
  55. package/dist/es5/dd-element.d.ts +1 -1
  56. package/dist/es5/dd-element.js +1 -1
  57. package/dist/es5/dd-element.js.map +1 -1
  58. package/dist/es5/dd-gridstack.d.ts +1 -1
  59. package/dist/es5/dd-gridstack.js +1 -1
  60. package/dist/es5/dd-gridstack.js.map +1 -1
  61. package/dist/es5/dd-manager.d.ts +1 -1
  62. package/dist/es5/dd-manager.js +1 -1
  63. package/dist/es5/dd-manager.js.map +1 -1
  64. package/dist/es5/dd-resizable-handle.d.ts +1 -1
  65. package/dist/es5/dd-resizable-handle.js +1 -1
  66. package/dist/es5/dd-resizable-handle.js.map +1 -1
  67. package/dist/es5/dd-resizable.d.ts +1 -1
  68. package/dist/es5/dd-resizable.js +3 -2
  69. package/dist/es5/dd-resizable.js.map +1 -1
  70. package/dist/es5/dd-touch.d.ts +1 -1
  71. package/dist/es5/dd-touch.js +1 -1
  72. package/dist/es5/dd-touch.js.map +1 -1
  73. package/dist/es5/gridstack-all.js +1 -1
  74. package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
  75. package/dist/es5/gridstack-all.js.map +1 -1
  76. package/dist/es5/gridstack-engine.d.ts +1 -1
  77. package/dist/es5/gridstack-engine.js +1 -1
  78. package/dist/es5/gridstack-engine.js.map +1 -1
  79. package/dist/es5/gridstack-poly.js +1 -1
  80. package/dist/es5/gridstack.d.ts +4 -5
  81. package/dist/es5/gridstack.js +85 -158
  82. package/dist/es5/gridstack.js.map +1 -1
  83. package/dist/es5/types.d.ts +4 -2
  84. package/dist/es5/types.js +1 -2
  85. package/dist/es5/types.js.map +1 -1
  86. package/dist/es5/utils.d.ts +1 -14
  87. package/dist/es5/utils.js +1 -45
  88. package/dist/es5/utils.js.map +1 -1
  89. package/dist/gridstack-all.js +1 -1
  90. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  91. package/dist/gridstack-all.js.map +1 -1
  92. package/dist/gridstack-engine.d.ts +1 -1
  93. package/dist/gridstack-engine.js +1 -1
  94. package/dist/gridstack-engine.js.map +1 -1
  95. package/dist/gridstack.css +25 -79
  96. package/dist/gridstack.d.ts +4 -5
  97. package/dist/gridstack.js +77 -150
  98. package/dist/gridstack.js.map +1 -1
  99. package/dist/gridstack.min.css +1 -1
  100. package/dist/src/gridstack.scss +22 -21
  101. package/dist/types.d.ts +4 -2
  102. package/dist/types.js +1 -2
  103. package/dist/types.js.map +1 -1
  104. package/dist/utils.d.ts +1 -14
  105. package/dist/utils.js +1 -45
  106. package/dist/utils.js.map +1 -1
  107. package/doc/CHANGES.md +7 -0
  108. package/doc/README.md +0 -3
  109. package/package.json +1 -1
  110. package/dist/angular/node_modules/tslib/README.md +0 -164
  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.0.0
3
3
  * https://gridstackjs.com/
4
4
  *
5
5
  * Copyright (c) 2021-2024 Alain Dumesny
@@ -234,9 +234,9 @@ class GridStack {
234
234
  }
235
235
  opts = Utils.defaults(opts, defaults);
236
236
  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)
237
+ // 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
238
  this.checkDynamicColumn();
239
- this.el.classList.add('gs-' + opts.column);
239
+ this._updateColumnVar(opts);
240
240
  if (opts.rtl === 'auto') {
241
241
  opts.rtl = (el.style.direction === 'rtl');
242
242
  }
@@ -255,7 +255,7 @@ class GridStack {
255
255
  this._isAutoCellHeight = (opts.cellHeight === 'auto');
256
256
  if (this._isAutoCellHeight || opts.cellHeight === 'initial') {
257
257
  // make the cell content square initially (will use resize/column event to keep it square)
258
- this.cellHeight(undefined, false);
258
+ this.cellHeight(undefined);
259
259
  }
260
260
  else {
261
261
  // append unit if any are set
@@ -263,14 +263,14 @@ class GridStack {
263
263
  opts.cellHeight = opts.cellHeight + opts.cellHeightUnit;
264
264
  delete opts.cellHeightUnit;
265
265
  }
266
- this.cellHeight(opts.cellHeight, false);
266
+ const val = opts.cellHeight;
267
+ delete opts.cellHeight; // force initial cellHeight() call to set the value
268
+ this.cellHeight(val);
267
269
  }
268
270
  // see if we need to adjust auto-hide
269
271
  if (opts.alwaysShowResizeHandle === 'mobile') {
270
272
  opts.alwaysShowResizeHandle = isTouch;
271
273
  }
272
- this._styleSheetClass = 'gs-id-' + GridStackEngine._idSeq++;
273
- this.el.classList.add(this._styleSheetClass);
274
274
  this._setStaticClass();
275
275
  const engineClass = opts.engineClass || GridStack.engineClass || GridStackEngine;
276
276
  this.engine = new engineClass({
@@ -278,8 +278,6 @@ class GridStack {
278
278
  float: opts.float,
279
279
  maxRow: opts.maxRow,
280
280
  onChange: (cbNodes) => {
281
- let maxH = 0;
282
- this.engine.nodes.forEach(n => { maxH = Math.max(maxH, n.y + n.h); });
283
281
  cbNodes.forEach(n => {
284
282
  const el = n.el;
285
283
  if (!el)
@@ -293,11 +291,9 @@ class GridStack {
293
291
  this._writePosAttr(el, n);
294
292
  }
295
293
  });
296
- this._updateStyles(false, maxH); // false = don't recreate, just append if need be
294
+ this._updateContainerHeight();
297
295
  }
298
296
  });
299
- // create initial global styles BEFORE loading children so resizeToContent margin can be calculated correctly
300
- this._updateStyles(false, 0);
301
297
  if (opts.auto) {
302
298
  this.batchUpdate(); // prevent in between re-layout #1535 TODO: this only set float=true, need to prevent collision check...
303
299
  this.engine._loading = true; // loading collision check
@@ -312,7 +308,6 @@ class GridStack {
312
308
  if (children.length)
313
309
  this.load(children); // don't load empty
314
310
  }
315
- // if (this.engine.nodes.length) this._updateStyles(); // update based on # of children. done in engine onChange CB
316
311
  this.setAnimation();
317
312
  // dynamic grids require pausing during drag to detect over to nest vs push
318
313
  if (opts.subGridDynamic && !DDManager.pauseDrag)
@@ -323,6 +318,11 @@ class GridStack {
323
318
  this._setupAcceptWidget();
324
319
  this._updateResizeEvent();
325
320
  }
321
+ _updateColumnVar(opts = this.opts) {
322
+ this.el.classList.add('gs-' + opts.column);
323
+ if (typeof opts.column === 'number')
324
+ this.el.style.setProperty('--gs-column-width', `${100 / opts.column}%`);
325
+ }
326
326
  /**
327
327
  * add a new widget and returns it.
328
328
  *
@@ -604,8 +604,18 @@ class GridStack {
604
604
  items.forEach(n => { maxColumn = Math.max(maxColumn, (n.x || 0) + n.w); });
605
605
  if (maxColumn > this.engine.defaultColumn)
606
606
  this.engine.defaultColumn = maxColumn;
607
- if (maxColumn > column)
608
- this.engine.cacheLayout(items, maxColumn, true);
607
+ if (maxColumn > column) {
608
+ // if we're loading (from empty) into a smaller column, check for special responsive layout
609
+ if (this.engine.nodes.length === 0 && this.responseLayout) {
610
+ this.engine.nodes = items;
611
+ this.engine.columnChanged(maxColumn, column, this.responseLayout);
612
+ items = this.engine.nodes;
613
+ this.engine.nodes = [];
614
+ delete this.responseLayout;
615
+ }
616
+ else
617
+ this.engine.cacheLayout(items, maxColumn, true);
618
+ }
609
619
  // if given a different callback, temporally set it as global option so creating will use it
610
620
  const prevCB = GridStack.addRemoveCB;
611
621
  if (typeof (addRemove) === 'function')
@@ -738,16 +748,15 @@ class GridStack {
738
748
  *
739
749
  * @param val the cell height. If not passed (undefined), cells content will be made square (match width minus margin),
740
750
  * if pass 0 the CSS will be generated by the application instead.
741
- * @param update (Optional) if false, styles will not be updated
742
751
  *
743
752
  * @example
744
753
  * grid.cellHeight(100); // same as 100px
745
754
  * grid.cellHeight('70px');
746
755
  * grid.cellHeight(grid.cellWidth() * 1.2);
747
756
  */
748
- cellHeight(val, update = true) {
757
+ cellHeight(val) {
749
758
  // if not called internally, check if we're changing mode
750
- if (update && val !== undefined) {
759
+ if (val !== undefined) {
751
760
  if (this._isAutoCellHeight !== (val === 'auto')) {
752
761
  this._isAutoCellHeight = (val === 'auto');
753
762
  this._updateResizeEvent();
@@ -768,10 +777,10 @@ class GridStack {
768
777
  }
769
778
  this.opts.cellHeightUnit = data.unit;
770
779
  this.opts.cellHeight = data.h;
780
+ // finally update var and container
781
+ this.el.style.setProperty('--gs-cell-height', `${this.opts.cellHeight}${this.opts.cellHeightUnit}`);
782
+ this._updateContainerHeight();
771
783
  this.resizeToContentCheck();
772
- if (update) {
773
- this._updateStyles(true); // true = force re-create for current # of rows
774
- }
775
784
  return this;
776
785
  }
777
786
  /** Gets current cell width. */
@@ -825,8 +834,6 @@ class GridStack {
825
834
  /**
826
835
  * set the number of columns in the grid. Will update existing widgets to conform to new number of columns,
827
836
  * 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
837
  * @param column - Integer > 0 (default 12).
831
838
  * @param layout specify the type of re-layout that will happen (position, size, etc...).
832
839
  * Note: items will never be outside of the current column boundaries. default ('moveScale'). Ignored for 1 column
@@ -836,15 +843,16 @@ class GridStack {
836
843
  return this;
837
844
  const oldColumn = this.getColumn();
838
845
  this.opts.column = column;
839
- if (!this.engine)
840
- return this; // called in constructor, noting else to do
846
+ if (!this.engine) {
847
+ // called in constructor, noting else to do but remember that breakpoint layout
848
+ this.responseLayout = layout;
849
+ return this;
850
+ }
841
851
  this.engine.column = column;
842
852
  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);
853
+ this._updateColumnVar();
854
+ // update the items now
855
+ this.engine.columnChanged(oldColumn, column, layout);
848
856
  if (this._isAutoCellHeight)
849
857
  this.cellHeight();
850
858
  this.resizeToContentCheck(true); // wait for width resizing
@@ -878,14 +886,13 @@ class GridStack {
878
886
  this.setAnimation(false);
879
887
  if (!removeDOM) {
880
888
  this.removeAll(removeDOM);
881
- this.el.classList.remove(this._styleSheetClass);
882
889
  this.el.removeAttribute('gs-current-row');
883
890
  }
884
891
  else {
885
892
  this.el.parentNode.removeChild(this.el);
886
893
  }
887
- this._removeStylesheet();
888
- delete this.parentGridNode?.subGrid;
894
+ if (this.parentGridNode)
895
+ delete this.parentGridNode.subGrid;
889
896
  delete this.parentGridNode;
890
897
  delete this.opts;
891
898
  delete this._placeholder?.gridstackNode;
@@ -967,8 +974,8 @@ class GridStack {
967
974
  */
968
975
  makeWidget(els, options) {
969
976
  const el = GridStack.getElement(els);
970
- if (!el)
971
- return;
977
+ if (!el || el.gridstackNode)
978
+ return el;
972
979
  if (!el.parentElement)
973
980
  this.el.appendChild(el);
974
981
  this._prepareElement(el, true, options);
@@ -1159,7 +1166,7 @@ class GridStack {
1159
1166
  if (o.animate !== undefined)
1160
1167
  this.setAnimation();
1161
1168
  if (o.cellHeight) {
1162
- this.cellHeight(o.cellHeight, true);
1169
+ this.cellHeight(o.cellHeight);
1163
1170
  delete o.cellHeight;
1164
1171
  }
1165
1172
  if (o.class && o.class !== opts.class) {
@@ -1230,8 +1237,7 @@ class GridStack {
1230
1237
  // restore any sub-grid back
1231
1238
  if (n.subGrid?.el) {
1232
1239
  itemContent.appendChild(n.subGrid.el);
1233
- if (!n.subGrid.opts.styleInHead)
1234
- n.subGrid._updateStyles(true); // force create
1240
+ n.subGrid._updateContainerHeight();
1235
1241
  }
1236
1242
  }
1237
1243
  delete w.content;
@@ -1390,7 +1396,7 @@ class GridStack {
1390
1396
  */
1391
1397
  margin(value) {
1392
1398
  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)
1399
+ // check if we can skip... won't check if multi values (too much hassle)
1394
1400
  if (!isMultiValue) {
1395
1401
  const data = Utils.parseHeight(value);
1396
1402
  if (this.opts.marginUnit === data.unit && this.opts.margin === data.h)
@@ -1400,7 +1406,6 @@ class GridStack {
1400
1406
  this.opts.margin = value;
1401
1407
  this.opts.marginTop = this.opts.marginBottom = this.opts.marginLeft = this.opts.marginRight = undefined;
1402
1408
  this._initMargin();
1403
- this._updateStyles(true); // true = force re-create
1404
1409
  return this;
1405
1410
  }
1406
1411
  /** returns current margin number value (undefined if 4 sides don't match) */
@@ -1475,74 +1480,6 @@ class GridStack {
1475
1480
  this.el.dispatchEvent(event);
1476
1481
  return this;
1477
1482
  }
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
- }
1544
- return this;
1545
- }
1546
1483
  /** @internal */
1547
1484
  _updateContainerHeight() {
1548
1485
  if (!this.engine || this.engine.batchMode)
@@ -1594,14 +1531,19 @@ class GridStack {
1594
1531
  this.prepareDragDrop(node.el);
1595
1532
  return this;
1596
1533
  }
1597
- /** @internal call to write position x,y,w,h attributes back to element */
1534
+ /** @internal write position CSS vars and x,y,w,h attributes (not used for CSS but by users) back to element */
1598
1535
  _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
- }
1536
+ // Avoid overwriting the inline style of the element during drag/resize, but always update the placeholder
1537
+ if ((!n._moving && !n._resizing) || this._placeholder === el) {
1538
+ // width/height:1 x/y:0 is set by default in the main CSS, so no need to set inlined vars
1539
+ el.style.top = n.y ? (n.y === 1 ? `var(--gs-cell-height)` : `calc(${n.y} * var(--gs-cell-height))`) : null;
1540
+ el.style.left = n.x ? (n.x === 1 ? `var(--gs-column-width)` : `calc(${n.x} * var(--gs-column-width))`) : null;
1541
+ el.style.width = n.w > 1 ? `calc(${n.w} * var(--gs-column-width))` : null;
1542
+ el.style.height = n.h > 1 ? `calc(${n.h} * var(--gs-cell-height))` : null;
1543
+ }
1544
+ // 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
1545
+ n.x > 0 ? el.setAttribute('gs-x', String(n.x)) : el.removeAttribute('gs-x');
1546
+ n.y > 0 ? el.setAttribute('gs-y', String(n.y)) : el.removeAttribute('gs-y');
1605
1547
  n.w > 1 ? el.setAttribute('gs-w', String(n.w)) : el.removeAttribute('gs-w');
1606
1548
  n.h > 1 ? el.setAttribute('gs-h', String(n.h)) : el.removeAttribute('gs-h');
1607
1549
  return this;
@@ -1807,42 +1749,27 @@ class GridStack {
1807
1749
  margin = this.opts.margin = data.h;
1808
1750
  }
1809
1751
  // 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
- }
1752
+ const keys = ['marginTop', 'marginRight', 'marginBottom', 'marginLeft'];
1753
+ keys.forEach(k => {
1754
+ if (this.opts[k] === undefined) {
1755
+ this.opts[k] = margin;
1756
+ }
1757
+ else {
1758
+ data = Utils.parseHeight(this.opts[k]);
1759
+ this.opts[k] = data.h;
1760
+ delete this.opts.margin;
1761
+ }
1762
+ });
1842
1763
  this.opts.marginUnit = data.unit; // in case side were spelled out, use those units instead...
1843
1764
  if (this.opts.marginTop === this.opts.marginBottom && this.opts.marginLeft === this.opts.marginRight && this.opts.marginTop === this.opts.marginRight) {
1844
1765
  this.opts.margin = this.opts.marginTop; // makes it easier to check for no-ops in setMargin()
1845
1766
  }
1767
+ // finally Update the CSS margin variables (inside the cell height) */
1768
+ const style = this.el.style;
1769
+ style.setProperty('--gs-item-margin-top', `${this.opts.marginTop}${this.opts.marginUnit}`);
1770
+ style.setProperty('--gs-item-margin-bottom', `${this.opts.marginBottom}${this.opts.marginUnit}`);
1771
+ style.setProperty('--gs-item-margin-right', `${this.opts.marginRight}${this.opts.marginUnit}`);
1772
+ style.setProperty('--gs-item-margin-left', `${this.opts.marginLeft}${this.opts.marginUnit}`);
1846
1773
  return this;
1847
1774
  }
1848
1775
  /* ===========================================================================================
@@ -2252,8 +2179,6 @@ class GridStack {
2252
2179
  this.resizeToContentCheck(false, node);
2253
2180
  if (subGrid) {
2254
2181
  subGrid.parentGridNode = node;
2255
- if (!subGrid.opts.styleInHead)
2256
- subGrid._updateStyles(true); // re-create sub-grid styles now that we've moved
2257
2182
  }
2258
2183
  this._updateContainerHeight();
2259
2184
  }
@@ -2344,6 +2269,7 @@ class GridStack {
2344
2269
  this.placeholder.remove();
2345
2270
  delete this.placeholder.gridstackNode;
2346
2271
  delete node._moving;
2272
+ delete node._resizing;
2347
2273
  delete node._event;
2348
2274
  delete node._lastTried;
2349
2275
  const widthChanged = node.w !== node._orig.w;
@@ -2436,6 +2362,7 @@ class GridStack {
2436
2362
  node._lastUiPosition = ui.position;
2437
2363
  node._prevYPix = ui.position.top;
2438
2364
  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)
2365
+ node._resizing = (event.type === 'resizestart');
2439
2366
  delete node._lastTried;
2440
2367
  if (event.type === 'dropover' && node._temporaryRemoved) {
2441
2368
  // console.log('engine.addNode x=' + node.x); // TEST
@@ -2596,6 +2523,6 @@ GridStack.resizeToContentParent = '.grid-stack-item-content';
2596
2523
  GridStack.Utils = Utils;
2597
2524
  /** scoping so users can call new GridStack.Engine(12) for example */
2598
2525
  GridStack.Engine = GridStackEngine;
2599
- GridStack.GDRev = '11.5.1';
2526
+ GridStack.GDRev = '12.0.0';
2600
2527
  export { GridStack };
2601
2528
  //# sourceMappingURL=gridstack.js.map