gridstack 8.2.0 → 8.2.2

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 (116) hide show
  1. package/README.md +3 -3
  2. package/angular/README.md +21 -21
  3. package/angular/package.json +1 -1
  4. package/angular/projects/demo/src/app/app.component.ts +7 -7
  5. package/angular/projects/demo/src/app/dummy.component.ts +1 -1
  6. package/angular/projects/lib/package.json +1 -1
  7. package/angular/projects/lib/src/lib/base-widget.ts +1 -1
  8. package/angular/projects/lib/src/lib/gridstack-item.component.ts +1 -1
  9. package/angular/projects/lib/src/lib/gridstack.component.ts +1 -1
  10. package/angular/projects/lib/src/lib/gridstack.module.ts +1 -1
  11. package/dist/angular/README.md +21 -21
  12. package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
  13. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
  14. package/dist/angular/esm2020/lib/gridstack.component.mjs +2 -2
  15. package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
  16. package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
  17. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  18. package/dist/angular/fesm2020/gridstack-angular.mjs +4 -4
  19. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  20. package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
  21. package/dist/angular/lib/gridstack.component.d.ts +1 -1
  22. package/dist/angular/package.json +1 -1
  23. package/dist/angular/src/base-widget.ts +1 -1
  24. package/dist/angular/src/gridstack-item.component.ts +1 -1
  25. package/dist/angular/src/gridstack.component.ts +1 -1
  26. package/dist/angular/src/gridstack.module.ts +1 -1
  27. package/dist/dd-base-impl.d.ts +1 -1
  28. package/dist/dd-base-impl.js +1 -1
  29. package/dist/dd-base-impl.js.map +1 -1
  30. package/dist/dd-draggable.d.ts +1 -1
  31. package/dist/dd-draggable.js +1 -2
  32. package/dist/dd-draggable.js.map +1 -1
  33. package/dist/dd-droppable.d.ts +1 -1
  34. package/dist/dd-droppable.js +1 -1
  35. package/dist/dd-droppable.js.map +1 -1
  36. package/dist/dd-element.d.ts +1 -1
  37. package/dist/dd-element.js +1 -1
  38. package/dist/dd-element.js.map +1 -1
  39. package/dist/dd-gridstack.d.ts +1 -1
  40. package/dist/dd-gridstack.js +1 -1
  41. package/dist/dd-gridstack.js.map +1 -1
  42. package/dist/dd-manager.d.ts +1 -1
  43. package/dist/dd-manager.js +1 -1
  44. package/dist/dd-manager.js.map +1 -1
  45. package/dist/dd-resizable-handle.d.ts +1 -1
  46. package/dist/dd-resizable-handle.js +1 -1
  47. package/dist/dd-resizable-handle.js.map +1 -1
  48. package/dist/dd-resizable.d.ts +1 -1
  49. package/dist/dd-resizable.js +1 -1
  50. package/dist/dd-resizable.js.map +1 -1
  51. package/dist/dd-touch.d.ts +1 -1
  52. package/dist/dd-touch.js +1 -1
  53. package/dist/dd-touch.js.map +1 -1
  54. package/dist/es5/dd-base-impl.d.ts +1 -1
  55. package/dist/es5/dd-base-impl.js +1 -1
  56. package/dist/es5/dd-base-impl.js.map +1 -1
  57. package/dist/es5/dd-draggable.d.ts +1 -1
  58. package/dist/es5/dd-draggable.js +1 -2
  59. package/dist/es5/dd-draggable.js.map +1 -1
  60. package/dist/es5/dd-droppable.d.ts +1 -1
  61. package/dist/es5/dd-droppable.js +1 -1
  62. package/dist/es5/dd-droppable.js.map +1 -1
  63. package/dist/es5/dd-element.d.ts +1 -1
  64. package/dist/es5/dd-element.js +1 -1
  65. package/dist/es5/dd-element.js.map +1 -1
  66. package/dist/es5/dd-gridstack.d.ts +1 -1
  67. package/dist/es5/dd-gridstack.js +1 -1
  68. package/dist/es5/dd-gridstack.js.map +1 -1
  69. package/dist/es5/dd-manager.d.ts +1 -1
  70. package/dist/es5/dd-manager.js +1 -1
  71. package/dist/es5/dd-manager.js.map +1 -1
  72. package/dist/es5/dd-resizable-handle.d.ts +1 -1
  73. package/dist/es5/dd-resizable-handle.js +1 -1
  74. package/dist/es5/dd-resizable-handle.js.map +1 -1
  75. package/dist/es5/dd-resizable.d.ts +1 -1
  76. package/dist/es5/dd-resizable.js +1 -1
  77. package/dist/es5/dd-resizable.js.map +1 -1
  78. package/dist/es5/dd-touch.d.ts +1 -1
  79. package/dist/es5/dd-touch.js +1 -1
  80. package/dist/es5/dd-touch.js.map +1 -1
  81. package/dist/es5/gridstack-all.js +1 -3
  82. package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
  83. package/dist/es5/gridstack-all.js.map +1 -1
  84. package/dist/es5/gridstack-engine.d.ts +1 -1
  85. package/dist/es5/gridstack-engine.js +10 -6
  86. package/dist/es5/gridstack-engine.js.map +1 -1
  87. package/dist/es5/gridstack-poly.js +1 -1
  88. package/dist/es5/gridstack.d.ts +4 -4
  89. package/dist/es5/gridstack.js +58 -59
  90. package/dist/es5/gridstack.js.map +1 -1
  91. package/dist/es5/types.d.ts +2 -4
  92. package/dist/es5/types.js +1 -1
  93. package/dist/es5/types.js.map +1 -1
  94. package/dist/es5/utils.d.ts +1 -1
  95. package/dist/es5/utils.js +3 -3
  96. package/dist/es5/utils.js.map +1 -1
  97. package/dist/gridstack-all.js +1 -3
  98. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  99. package/dist/gridstack-all.js.map +1 -1
  100. package/dist/gridstack-engine.d.ts +1 -1
  101. package/dist/gridstack-engine.js +10 -6
  102. package/dist/gridstack-engine.js.map +1 -1
  103. package/dist/gridstack.css +11 -8
  104. package/dist/gridstack.d.ts +4 -4
  105. package/dist/gridstack.js +57 -59
  106. package/dist/gridstack.js.map +1 -1
  107. package/dist/gridstack.min.css +1 -1
  108. package/dist/src/gridstack.scss +12 -11
  109. package/dist/types.d.ts +2 -4
  110. package/dist/types.js +1 -1
  111. package/dist/types.js.map +1 -1
  112. package/dist/utils.d.ts +1 -1
  113. package/dist/utils.js +3 -3
  114. package/dist/utils.js.map +1 -1
  115. package/doc/CHANGES.md +13 -0
  116. package/package.json +1 -1
@@ -36,7 +36,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.GridStack = void 0;
38
38
  /*!
39
- * GridStack 8.2.0
39
+ * GridStack 8.2.2
40
40
  * https://gridstackjs.com/
41
41
  *
42
42
  * Copyright (c) 2021-2022 Alain Dumesny
@@ -369,6 +369,10 @@ var GridStack = exports.GridStack = /** @class */ (function () {
369
369
  }
370
370
  if (!el)
371
371
  return;
372
+ // if the caller ended up initializing the widget in addRemoveCB, or we stared with one already, skip the rest
373
+ node = el.gridstackNode;
374
+ if (node && el.parentElement === this.el && this.engine.nodes.find(function (n) { return n._id === node._id; }))
375
+ return el;
372
376
  // Tempting to initialize the passed in opt with default and valid values, but this break knockout demos
373
377
  // as the actual value are filled in when _prepareElement() calls el.getAttribute('gs-xyz') before adding the node.
374
378
  // So make sure we load any DOM attributes that are not specified in passed in options (which override)
@@ -383,21 +387,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
383
387
  else {
384
388
  this.el.appendChild(el);
385
389
  }
386
- // similar to makeWidget() that doesn't read attr again and worse re-create a new node and loose any _id
387
- this._prepareElement(el, true, options);
388
- this._updateContainerHeight();
389
- // see if there is a sub-grid to create
390
- if (node.subGridOpts) {
391
- this.makeSubGrid(node.el, node.subGridOpts, undefined, false); // node.subGrid will be used as option in method, no need to pass
392
- }
393
- // if we're adding an item into 1 column (_prevColumn is set only when going to 1) make sure
394
- // we don't override the larger 12 column layout that was already saved. #1985
395
- if (this._prevColumn && this.opts.column === 1) {
396
- this._ignoreLayoutsNodeChange = true;
397
- }
398
- this._triggerAddEvent();
399
- this._triggerChangeEvent();
400
- delete this._ignoreLayoutsNodeChange;
390
+ this.makeWidget(el, options);
401
391
  return el;
402
392
  };
403
393
  /**
@@ -633,7 +623,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
633
623
  // now add/update the widgets
634
624
  items.forEach(function (w) {
635
625
  var _a;
636
- var item = (w.id || w.id === 0) ? _this.engine.nodes.find(function (n) { return n.id === w.id; }) : undefined;
626
+ var item = (w.id !== undefined) ? _this.engine.nodes.find(function (n) { return n.id === w.id; }) : undefined;
637
627
  if (item) {
638
628
  _this.update(item.el, w);
639
629
  if ((_a = w.subGridOpts) === null || _a === void 0 ? void 0 : _a.children) { // update any sub grid as well
@@ -682,7 +672,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
682
672
  // else get first cell height
683
673
  var el = this.el.querySelector('.' + this.opts.itemClass);
684
674
  if (el) {
685
- var height = utils_1.Utils.toNumber(el.getAttribute('gs-h'));
675
+ var height = utils_1.Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
686
676
  return Math.round(el.offsetHeight / height);
687
677
  }
688
678
  // else do entire grid and # of rows (but doesn't work if min-height is the actual constrain)
@@ -914,8 +904,19 @@ var GridStack = exports.GridStack = /** @class */ (function () {
914
904
  var el = GridStack.getElement(els);
915
905
  this._prepareElement(el, true, options);
916
906
  this._updateContainerHeight();
907
+ // see if there is a sub-grid to create
908
+ var node = el.gridstackNode;
909
+ if (node.subGridOpts) {
910
+ this.makeSubGrid(el, node.subGridOpts, undefined, false); // node.subGrid will be used as option in method, no need to pass
911
+ }
912
+ // if we're adding an item into 1 column (_prevColumn is set only when going to 1) make sure
913
+ // we don't override the larger 12 column layout that was already saved. #1985
914
+ if (this._prevColumn && this.opts.column === 1) {
915
+ this._ignoreLayoutsNodeChange = true;
916
+ }
917
917
  this._triggerAddEvent();
918
918
  this._triggerChangeEvent();
919
+ delete this._ignoreLayoutsNodeChange;
919
920
  return el;
920
921
  };
921
922
  /**
@@ -1067,9 +1068,9 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1067
1068
  var _this = this;
1068
1069
  if (updateClass === void 0) { updateClass = true; }
1069
1070
  if (recurse === void 0) { recurse = true; }
1070
- if (this.opts.staticGrid === val)
1071
+ if (!!this.opts.staticGrid === val)
1071
1072
  return this;
1072
- this.opts.staticGrid = val;
1073
+ val ? this.opts.staticGrid = true : delete this.opts.staticGrid;
1073
1074
  this._setupRemoveDrop();
1074
1075
  this._setupAcceptWidget();
1075
1076
  this.engine.nodes.forEach(function (n) {
@@ -1389,16 +1390,13 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1389
1390
  return this;
1390
1391
  };
1391
1392
  /** @internal call to read any default attributes from element */
1392
- GridStack.prototype._readAttr = function (el) {
1393
+ GridStack.prototype._readAttr = function (el, clearDefaultAttr) {
1394
+ if (clearDefaultAttr === void 0) { clearDefaultAttr = true; }
1393
1395
  var n = {};
1394
1396
  n.x = utils_1.Utils.toNumber(el.getAttribute('gs-x'));
1395
1397
  n.y = utils_1.Utils.toNumber(el.getAttribute('gs-y'));
1396
1398
  n.w = utils_1.Utils.toNumber(el.getAttribute('gs-w'));
1397
1399
  n.h = utils_1.Utils.toNumber(el.getAttribute('gs-h'));
1398
- if (!(n.w > 1))
1399
- el.removeAttribute('gs-w');
1400
- if (!(n.h > 1))
1401
- el.removeAttribute('gs-h');
1402
1400
  n.autoPosition = utils_1.Utils.toBool(el.getAttribute('gs-auto-position'));
1403
1401
  n.noResize = utils_1.Utils.toBool(el.getAttribute('gs-no-resize'));
1404
1402
  n.noMove = utils_1.Utils.toBool(el.getAttribute('gs-no-move'));
@@ -1406,17 +1404,24 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1406
1404
  n.id = el.getAttribute('gs-id');
1407
1405
  // read but never written out
1408
1406
  n.maxW = utils_1.Utils.toNumber(el.getAttribute('gs-max-w'));
1409
- if (n.maxW)
1410
- el.removeAttribute('gs-max-w');
1411
1407
  n.minW = utils_1.Utils.toNumber(el.getAttribute('gs-min-w'));
1412
- if (n.minW)
1413
- el.removeAttribute('gs-min-w');
1414
1408
  n.maxH = utils_1.Utils.toNumber(el.getAttribute('gs-max-h'));
1415
- if (n.maxH)
1416
- el.removeAttribute('gs-max-h');
1417
1409
  n.minH = utils_1.Utils.toNumber(el.getAttribute('gs-min-h'));
1418
- if (n.minH)
1419
- el.removeAttribute('gs-min-h');
1410
+ // v8.x optimization to reduce un-needed attr that don't render or are default CSS
1411
+ if (clearDefaultAttr) {
1412
+ if (n.w === 1)
1413
+ el.removeAttribute('gs-w');
1414
+ if (n.h === 1)
1415
+ el.removeAttribute('gs-h');
1416
+ if (n.maxW)
1417
+ el.removeAttribute('gs-max-w');
1418
+ if (n.minW)
1419
+ el.removeAttribute('gs-min-w');
1420
+ if (n.maxH)
1421
+ el.removeAttribute('gs-max-h');
1422
+ if (n.minH)
1423
+ el.removeAttribute('gs-min-h');
1424
+ }
1420
1425
  // remove any key not found (null or false which is default)
1421
1426
  for (var key in n) {
1422
1427
  if (!n.hasOwnProperty(key))
@@ -1617,42 +1622,36 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1617
1622
  * Enables/Disables dragging by the user of specific grid element. If you want all items, and have it affect future items, use enableMove() instead. No-op for static grids.
1618
1623
  * IF you are looking to prevent an item from moving (due to being pushed around by another during collision) use locked property instead.
1619
1624
  * @param els widget or selector to modify.
1620
- * @param val if true widget will be draggable.
1625
+ * @param val if true widget will be draggable, assuming the parent grid isn't noMove or static.
1621
1626
  */
1622
1627
  GridStack.prototype.movable = function (els, val) {
1623
1628
  var _this = this;
1624
1629
  if (this.opts.staticGrid)
1625
1630
  return this; // can't move a static grid!
1626
1631
  GridStack.getElements(els).forEach(function (el) {
1627
- var node = el.gridstackNode;
1628
- if (!node)
1632
+ var n = el.gridstackNode;
1633
+ if (!n)
1629
1634
  return;
1630
- if (val)
1631
- delete node.noMove;
1632
- else
1633
- node.noMove = true;
1634
- _this._prepareDragDropByNode(node); // init DD if need be, and adjust
1635
+ val ? delete n.noMove : n.noMove = true;
1636
+ _this._prepareDragDropByNode(n); // init DD if need be, and adjust
1635
1637
  });
1636
1638
  return this;
1637
1639
  };
1638
1640
  /**
1639
1641
  * Enables/Disables user resizing of specific grid element. If you want all items, and have it affect future items, use enableResize() instead. No-op for static grids.
1640
1642
  * @param els widget or selector to modify
1641
- * @param val if true widget will be resizable.
1643
+ * @param val if true widget will be resizable, assuming the parent grid isn't noResize or static.
1642
1644
  */
1643
1645
  GridStack.prototype.resizable = function (els, val) {
1644
1646
  var _this = this;
1645
1647
  if (this.opts.staticGrid)
1646
1648
  return this; // can't resize a static grid!
1647
1649
  GridStack.getElements(els).forEach(function (el) {
1648
- var node = el.gridstackNode;
1649
- if (!node)
1650
+ var n = el.gridstackNode;
1651
+ if (!n)
1650
1652
  return;
1651
- if (val)
1652
- delete node.noResize;
1653
- else
1654
- node.noResize = true;
1655
- _this._prepareDragDropByNode(node); // init DD if need be, and adjust
1653
+ val ? delete n.noResize : n.noResize = true;
1654
+ _this._prepareDragDropByNode(n); // init DD if need be, and adjust
1656
1655
  });
1657
1656
  return this;
1658
1657
  };
@@ -1671,7 +1670,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1671
1670
  if (this.opts.staticGrid)
1672
1671
  return;
1673
1672
  this.enableMove(false, recurse);
1674
- this.enableResize(false, recurse); // @ts-ignore
1673
+ this.enableResize(false, recurse);
1675
1674
  this._triggerEvent('disable');
1676
1675
  return this;
1677
1676
  };
@@ -1689,12 +1688,12 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1689
1688
  if (this.opts.staticGrid)
1690
1689
  return;
1691
1690
  this.enableMove(true, recurse);
1692
- this.enableResize(true, recurse); // @ts-ignore
1691
+ this.enableResize(true, recurse);
1693
1692
  this._triggerEvent('enable');
1694
1693
  return this;
1695
1694
  };
1696
1695
  /**
1697
- * Enables/disables widget moving. No-op for static grids.
1696
+ * Enables/disables widget moving. No-op for static grids, and locally defined items still overrule
1698
1697
  * @param recurse true (default) if sub-grids also get updated
1699
1698
  */
1700
1699
  GridStack.prototype.enableMove = function (doEnable, recurse) {
@@ -1702,9 +1701,9 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1702
1701
  if (recurse === void 0) { recurse = true; }
1703
1702
  if (this.opts.staticGrid)
1704
1703
  return this; // can't move a static grid!
1705
- this.opts.disableDrag = !doEnable; // FIRST before we update children as grid overrides #1658
1704
+ doEnable ? delete this.opts.disableDrag : this.opts.disableDrag = true; // FIRST before we update children as grid overrides #1658
1706
1705
  this.engine.nodes.forEach(function (n) {
1707
- _this.movable(n.el, doEnable);
1706
+ _this._prepareDragDropByNode(n);
1708
1707
  if (n.subGrid && recurse)
1709
1708
  n.subGrid.enableMove(doEnable, recurse);
1710
1709
  });
@@ -1719,9 +1718,9 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1719
1718
  if (recurse === void 0) { recurse = true; }
1720
1719
  if (this.opts.staticGrid)
1721
1720
  return this; // can't size a static grid!
1722
- this.opts.disableResize = !doEnable; // FIRST before we update children as grid overrides #1658
1721
+ doEnable ? delete this.opts.disableResize : this.opts.disableResize = true; // FIRST before we update children as grid overrides #1658
1723
1722
  this.engine.nodes.forEach(function (n) {
1724
- _this.resizable(n.el, doEnable);
1723
+ _this._prepareDragDropByNode(n);
1725
1724
  if (n.subGrid && recurse)
1726
1725
  n.subGrid.enableResize(doEnable, recurse);
1727
1726
  });
@@ -1829,8 +1828,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1829
1828
  cellWidth = _this.cellWidth();
1830
1829
  cellHeight = _this.getCellHeight(true);
1831
1830
  // load any element attributes if we don't have a node
1832
- if (!node) { // @ts-ignore private read only on ourself
1833
- node = _this._readAttr(el);
1831
+ if (!node) {
1832
+ node = _this._readAttr(el, false); // don't wipe external (e.g. drag toolbar) attr #2354
1834
1833
  }
1835
1834
  if (!node.grid) {
1836
1835
  node._isExternal = true;
@@ -2245,7 +2244,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2245
2244
  GridStack.Utils = utils_1.Utils;
2246
2245
  /** scoping so users can call new GridStack.Engine(12) for example */
2247
2246
  GridStack.Engine = gridstack_engine_1.GridStackEngine;
2248
- GridStack.GDRev = '8.2.0';
2247
+ GridStack.GDRev = '8.2.2';
2249
2248
  return GridStack;
2250
2249
  }());
2251
2250
  //# sourceMappingURL=gridstack.js.map