gridstack 8.4.0 → 9.0.1

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 (112) hide show
  1. package/README.md +9 -2
  2. package/angular/projects/lib/package.json +1 -1
  3. package/angular/projects/lib/src/lib/base-widget.ts +1 -1
  4. package/angular/projects/lib/src/lib/gridstack-item.component.ts +1 -1
  5. package/angular/projects/lib/src/lib/gridstack.component.ts +1 -1
  6. package/angular/projects/lib/src/lib/gridstack.module.ts +1 -1
  7. package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
  8. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
  9. package/dist/angular/esm2020/lib/gridstack.component.mjs +2 -2
  10. package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
  11. package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
  12. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  13. package/dist/angular/fesm2020/gridstack-angular.mjs +4 -4
  14. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  15. package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
  16. package/dist/angular/lib/gridstack.component.d.ts +1 -1
  17. package/dist/angular/package.json +1 -1
  18. package/dist/angular/src/base-widget.ts +1 -1
  19. package/dist/angular/src/gridstack-item.component.ts +1 -1
  20. package/dist/angular/src/gridstack.component.ts +1 -1
  21. package/dist/angular/src/gridstack.module.ts +1 -1
  22. package/dist/dd-base-impl.d.ts +1 -1
  23. package/dist/dd-base-impl.js +1 -1
  24. package/dist/dd-base-impl.js.map +1 -1
  25. package/dist/dd-draggable.d.ts +1 -1
  26. package/dist/dd-draggable.js +1 -1
  27. package/dist/dd-draggable.js.map +1 -1
  28. package/dist/dd-droppable.d.ts +1 -1
  29. package/dist/dd-droppable.js +1 -1
  30. package/dist/dd-droppable.js.map +1 -1
  31. package/dist/dd-element.d.ts +1 -1
  32. package/dist/dd-element.js +1 -1
  33. package/dist/dd-element.js.map +1 -1
  34. package/dist/dd-gridstack.d.ts +1 -1
  35. package/dist/dd-gridstack.js +1 -1
  36. package/dist/dd-gridstack.js.map +1 -1
  37. package/dist/dd-manager.d.ts +1 -1
  38. package/dist/dd-manager.js +1 -1
  39. package/dist/dd-manager.js.map +1 -1
  40. package/dist/dd-resizable-handle.d.ts +1 -1
  41. package/dist/dd-resizable-handle.js +1 -1
  42. package/dist/dd-resizable-handle.js.map +1 -1
  43. package/dist/dd-resizable.d.ts +1 -1
  44. package/dist/dd-resizable.js +1 -1
  45. package/dist/dd-resizable.js.map +1 -1
  46. package/dist/dd-touch.d.ts +1 -1
  47. package/dist/dd-touch.js +7 -1
  48. package/dist/dd-touch.js.map +1 -1
  49. package/dist/es5/dd-base-impl.d.ts +1 -1
  50. package/dist/es5/dd-base-impl.js +1 -1
  51. package/dist/es5/dd-base-impl.js.map +1 -1
  52. package/dist/es5/dd-draggable.d.ts +1 -1
  53. package/dist/es5/dd-draggable.js +1 -1
  54. package/dist/es5/dd-draggable.js.map +1 -1
  55. package/dist/es5/dd-droppable.d.ts +1 -1
  56. package/dist/es5/dd-droppable.js +1 -1
  57. package/dist/es5/dd-droppable.js.map +1 -1
  58. package/dist/es5/dd-element.d.ts +1 -1
  59. package/dist/es5/dd-element.js +1 -1
  60. package/dist/es5/dd-element.js.map +1 -1
  61. package/dist/es5/dd-gridstack.d.ts +1 -1
  62. package/dist/es5/dd-gridstack.js +1 -1
  63. package/dist/es5/dd-gridstack.js.map +1 -1
  64. package/dist/es5/dd-manager.d.ts +1 -1
  65. package/dist/es5/dd-manager.js +1 -1
  66. package/dist/es5/dd-manager.js.map +1 -1
  67. package/dist/es5/dd-resizable-handle.d.ts +1 -1
  68. package/dist/es5/dd-resizable-handle.js +1 -1
  69. package/dist/es5/dd-resizable-handle.js.map +1 -1
  70. package/dist/es5/dd-resizable.d.ts +1 -1
  71. package/dist/es5/dd-resizable.js +1 -1
  72. package/dist/es5/dd-resizable.js.map +1 -1
  73. package/dist/es5/dd-touch.d.ts +1 -1
  74. package/dist/es5/dd-touch.js +7 -1
  75. package/dist/es5/dd-touch.js.map +1 -1
  76. package/dist/es5/gridstack-all.js +1 -1
  77. package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
  78. package/dist/es5/gridstack-all.js.map +1 -1
  79. package/dist/es5/gridstack-engine.d.ts +1 -1
  80. package/dist/es5/gridstack-engine.js +19 -13
  81. package/dist/es5/gridstack-engine.js.map +1 -1
  82. package/dist/es5/gridstack-poly.js +1 -1
  83. package/dist/es5/gridstack.d.ts +21 -8
  84. package/dist/es5/gridstack.js +136 -55
  85. package/dist/es5/gridstack.js.map +1 -1
  86. package/dist/es5/types.d.ts +7 -1
  87. package/dist/es5/types.js +1 -1
  88. package/dist/es5/types.js.map +1 -1
  89. package/dist/es5/utils.d.ts +3 -1
  90. package/dist/es5/utils.js +5 -1
  91. package/dist/es5/utils.js.map +1 -1
  92. package/dist/gridstack-all.js +1 -1
  93. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  94. package/dist/gridstack-all.js.map +1 -1
  95. package/dist/gridstack-engine.d.ts +1 -1
  96. package/dist/gridstack-engine.js +17 -13
  97. package/dist/gridstack-engine.js.map +1 -1
  98. package/dist/gridstack.css +4 -1
  99. package/dist/gridstack.d.ts +21 -8
  100. package/dist/gridstack.js +130 -54
  101. package/dist/gridstack.js.map +1 -1
  102. package/dist/gridstack.min.css +1 -1
  103. package/dist/src/gridstack.scss +4 -1
  104. package/dist/types.d.ts +7 -1
  105. package/dist/types.js +1 -1
  106. package/dist/types.js.map +1 -1
  107. package/dist/utils.d.ts +3 -1
  108. package/dist/utils.js +5 -1
  109. package/dist/utils.js.map +1 -1
  110. package/doc/CHANGES.md +11 -0
  111. package/doc/README.md +2 -0
  112. 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.4.0
39
+ * GridStack 9.0.1
40
40
  * https://gridstackjs.com/
41
41
  *
42
42
  * Copyright (c) 2021-2022 Alain Dumesny
@@ -202,7 +202,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
202
202
  dd_manager_1.DDManager.pauseDrag = this.opts.draggable.pause;
203
203
  this._setupRemoveDrop();
204
204
  this._setupAcceptWidget();
205
- this._updateWindowResizeEvent();
205
+ this._updateResizeEvent();
206
206
  }
207
207
  /**
208
208
  * initializing the HTML element, or selector string, into a grid will return the grid. Calling it again will
@@ -666,6 +666,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
666
666
  if (flag === void 0) { flag = true; }
667
667
  this.engine.batchUpdate(flag);
668
668
  if (!flag) {
669
+ this._updateContainerHeight();
669
670
  this._triggerRemoveEvent();
670
671
  this._triggerAddEvent();
671
672
  this._triggerChangeEvent();
@@ -711,7 +712,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
711
712
  if (update && val !== undefined) {
712
713
  if (this._isAutoCellHeight !== (val === 'auto')) {
713
714
  this._isAutoCellHeight = (val === 'auto');
714
- this._updateWindowResizeEvent();
715
+ this._updateResizeEvent();
715
716
  }
716
717
  }
717
718
  if (val === 'initial' || val === 'auto') {
@@ -769,7 +770,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
769
770
  */
770
771
  GridStack.prototype.column = function (column, layout) {
771
772
  if (layout === void 0) { layout = 'moveScale'; }
772
- if (column < 1 || this.opts.column === column)
773
+ if (!column || column < 1 || this.opts.column === column)
773
774
  return this;
774
775
  var oldColumn = this.getColumn();
775
776
  // if we go into 1 column mode (which happens if we're sized less than minW unless disableOneColumnMode is on)
@@ -799,6 +800,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
799
800
  this.engine.columnChanged(oldColumn, column, domNodes, layout);
800
801
  if (this._isAutoCellHeight)
801
802
  this.cellHeight();
803
+ this.doContentResize();
802
804
  // and trigger our event last...
803
805
  this._ignoreLayoutsNodeChange = true; // skip layout update
804
806
  this._triggerChangeEvent();
@@ -826,7 +828,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
826
828
  if (!this.el)
827
829
  return; // prevent multiple calls
828
830
  this.offAll();
829
- this._updateWindowResizeEvent(true);
831
+ this._updateResizeEvent(true);
830
832
  this.setStatic(true, false); // permanently removes DD but don't set CSS class (we're going away)
831
833
  this.setAnimation(false);
832
834
  if (!removeDOM) {
@@ -974,7 +976,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
974
976
  }
975
977
  this.el.addEventListener(name, this._gsEventHandler[name]);
976
978
  }
977
- else if (name === 'drag' || name === 'dragstart' || name === 'dragstop' || name === 'resizestart' || name === 'resize' || name === 'resizestop' || name === 'dropped') {
979
+ else if (name === 'drag' || name === 'dragstart' || name === 'dragstop' || name === 'resizestart' || name === 'resize'
980
+ || name === 'resizestop' || name === 'dropped' || name === 'resizecontent') {
978
981
  // drag&drop stop events NEED to be call them AFTER we update node attributes so handle them ourself.
979
982
  // do same for start event to make it easier...
980
983
  this._gsEventHandler[name] = callback;
@@ -1165,14 +1168,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1165
1168
  }
1166
1169
  utils_1.Utils.sanitizeMinMax(n);
1167
1170
  // finally move the widget
1168
- if (m) {
1169
- _this.engine.cleanNodes()
1170
- .beginUpdate(n)
1171
- .moveNode(n, m);
1172
- _this._updateContainerHeight();
1173
- _this._triggerChangeEvent();
1174
- _this.engine.endUpdate();
1175
- }
1171
+ if (m)
1172
+ _this.moveNode(n, m);
1176
1173
  if (changed) { // move will only update x,y,w,h so update the rest too
1177
1174
  _this._writeAttr(el, n);
1178
1175
  }
@@ -1182,6 +1179,61 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1182
1179
  });
1183
1180
  return this;
1184
1181
  };
1182
+ GridStack.prototype.moveNode = function (n, m) {
1183
+ this.engine.cleanNodes()
1184
+ .beginUpdate(n)
1185
+ .moveNode(n, m);
1186
+ this._updateContainerHeight();
1187
+ this._triggerChangeEvent();
1188
+ this.engine.endUpdate();
1189
+ };
1190
+ /** Updates widget height to match the content height to avoid v-scrollbar or dead space.
1191
+ Note: this assumes only 1 child under '.grid-stack-item-content' (sized to gridItem minus padding) that is at the entire content size wanted */
1192
+ GridStack.prototype.resizeToContent = function (els) {
1193
+ var _this = this;
1194
+ GridStack.getElements(els).forEach(function (el) {
1195
+ var n = el === null || el === void 0 ? void 0 : el.gridstackNode;
1196
+ if (!n)
1197
+ return;
1198
+ if (el.parentElement !== n.grid.el)
1199
+ return; // skip if we are not inside a grid
1200
+ var height = el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1201
+ if (!height)
1202
+ return; // 0 when hidden, skip
1203
+ var item = el.querySelector(GridStack.resizeToContentParent);
1204
+ if (!item)
1205
+ return;
1206
+ var child = item.firstElementChild;
1207
+ // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1208
+ if (!child) {
1209
+ console.log("Error: resizeToContent() '".concat(GridStack.resizeToContentParent, "'.firstElementChild is null, make sure to have a div like container. Skipping sizing."));
1210
+ return;
1211
+ }
1212
+ var itemH = item.clientHeight; // available height to our child (minus border, padding...)
1213
+ var wantedH = child.getBoundingClientRect().height || itemH;
1214
+ if (itemH === wantedH)
1215
+ return;
1216
+ height += wantedH - itemH;
1217
+ var cell = _this.getCellHeight();
1218
+ if (!cell)
1219
+ return;
1220
+ var h = Math.ceil(height / cell);
1221
+ if (n.maxH && h > n.maxH)
1222
+ h = n.maxH;
1223
+ if (h !== n.h) {
1224
+ _this._ignoreLayoutsNodeChange = true;
1225
+ _this.moveNode(n, { h: h });
1226
+ delete _this._ignoreLayoutsNodeChange;
1227
+ }
1228
+ });
1229
+ };
1230
+ /** call the user resize (so we can do extra work) else our build in version */
1231
+ GridStack.prototype.resizeToContentCheck = function (el) {
1232
+ if (GridStack.resizeToContentCB)
1233
+ GridStack.resizeToContentCB(el);
1234
+ else
1235
+ this.resizeToContent(el);
1236
+ };
1185
1237
  /**
1186
1238
  * Updates the margins which will set all 4 sides at once - see `GridStackOptions.margin` for format options (CSS string format of 1,2,4 values or single number).
1187
1239
  * @param value margin value
@@ -1379,6 +1431,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1379
1431
  if (!utils_1.Utils.same(node, copy)) {
1380
1432
  this._writeAttr(el, node);
1381
1433
  }
1434
+ if (utils_1.Utils.shouldFitToContent(node))
1435
+ el.classList.add('fit-to-content');
1382
1436
  this._prepareDragDropByNode(node);
1383
1437
  return this;
1384
1438
  };
@@ -1474,67 +1528,90 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1474
1528
  return this;
1475
1529
  };
1476
1530
  /**
1477
- * called when we are being resized by the window - check if the one Column Mode needs to be turned on/off
1478
- * and remember the prev columns we used, or get our count from parent, as well as check for auto cell height (square)
1531
+ * called when we are being resized - check if the one Column Mode needs to be turned on/off
1532
+ * and remember the prev columns we used, or get our count from parent, as well as check for cellHeight==='auto' (square)
1533
+ * or `fitToContent` gridItem options.
1479
1534
  */
1480
- GridStack.prototype.onParentResize = function () {
1481
- var _this = this;
1482
- if (!this.el || !this.el.clientWidth)
1535
+ GridStack.prototype.onResize = function () {
1536
+ var _a;
1537
+ if (!((_a = this.el) === null || _a === void 0 ? void 0 : _a.clientWidth))
1483
1538
  return; // return if we're gone or no size yet (will get called again)
1484
- var changedColumn = false;
1539
+ if (this.prevWidth === this.el.clientWidth)
1540
+ return; // no-op
1541
+ this.prevWidth = this.el.clientWidth;
1542
+ // console.log('onResize ', this.el.clientWidth);
1543
+ this.batchUpdate();
1485
1544
  // see if we're nested and take our column count from our parent....
1545
+ var columnChanged = false;
1486
1546
  if (this._autoColumn && this.parentGridItem) {
1487
1547
  if (this.opts.column !== this.parentGridItem.w) {
1488
- changedColumn = true;
1489
1548
  this.column(this.parentGridItem.w, 'none');
1549
+ columnChanged = true;
1490
1550
  }
1491
1551
  }
1492
1552
  else {
1493
1553
  // else check for 1 column in/out behavior
1494
- var oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize;
1554
+ var oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize ||
1555
+ (this.opts.column === 1 && !this._prevColumn);
1495
1556
  if ((this.opts.column === 1) !== oneColumn) {
1496
- changedColumn = true;
1497
- if (this.opts.animate) {
1498
- this.setAnimation(false);
1499
- } // 1 <-> 12 is too radical, turn off animation
1557
+ // if (this.opts.animate) this.setAnimation(false); // 1 <-> 12 is too radical, turn off animation and we need it for fitToContent
1500
1558
  this.column(oneColumn ? 1 : this._prevColumn);
1501
- if (this.opts.animate) {
1502
- this.setAnimation(true);
1503
- }
1559
+ // if (this.opts.animate) setTimeout(() => this.setAnimation(true));
1560
+ columnChanged = true;
1504
1561
  }
1505
1562
  }
1506
1563
  // make the cells content square again
1507
- if (this._isAutoCellHeight) {
1508
- if (!changedColumn && this.opts.cellHeightThrottle) {
1509
- if (!this._cellHeightThrottle) {
1510
- this._cellHeightThrottle = utils_1.Utils.throttle(function () { return _this.cellHeight(); }, this.opts.cellHeightThrottle);
1511
- }
1512
- this._cellHeightThrottle();
1513
- }
1514
- else {
1515
- // immediate update if we've changed column count or have no threshold
1516
- this.cellHeight();
1517
- }
1518
- }
1519
- // finally update any nested grids
1564
+ if (this._isAutoCellHeight)
1565
+ this.cellHeight();
1566
+ // update any nested grids, or items size
1520
1567
  this.engine.nodes.forEach(function (n) {
1521
1568
  if (n.subGrid)
1522
- n.subGrid.onParentResize();
1569
+ n.subGrid.onResize();
1523
1570
  });
1571
+ this.doContentResize(columnChanged);
1572
+ this.batchUpdate(false);
1524
1573
  return this;
1525
1574
  };
1526
- /** add or remove the window size event handler */
1527
- GridStack.prototype._updateWindowResizeEvent = function (forceRemove) {
1575
+ GridStack.prototype.doContentResize = function (delay, n) {
1576
+ var _this = this;
1577
+ if (delay === void 0) { delay = true; }
1578
+ if (n === void 0) { n = undefined; }
1579
+ // update any gridItem height with fitToContent, but wait for DOM $animation_speed to settle if we changed column count
1580
+ // TODO: is there a way to know what the final (post animation) size of the content will be so we can animate the column width and height together rather than sequentially ?
1581
+ setTimeout(function () {
1582
+ if (n) {
1583
+ if (utils_1.Utils.shouldFitToContent(n))
1584
+ _this.resizeToContentCheck(n.el);
1585
+ }
1586
+ else {
1587
+ var nodes = __spreadArray([], _this.engine.nodes, true); // in case order changes while resizing one
1588
+ _this.batchUpdate();
1589
+ nodes.forEach(function (n) {
1590
+ if (utils_1.Utils.shouldFitToContent(n))
1591
+ _this.resizeToContentCheck(n.el);
1592
+ });
1593
+ _this.batchUpdate(false);
1594
+ }
1595
+ if (_this._gsEventHandler['resizeContent'])
1596
+ _this._gsEventHandler['resizeContent'](null, n ? [n] : _this.engine.nodes);
1597
+ }, delay ? 300 + 10 : 0);
1598
+ };
1599
+ /** add or remove the grid element size event handler */
1600
+ GridStack.prototype._updateResizeEvent = function (forceRemove) {
1601
+ var _this = this;
1528
1602
  if (forceRemove === void 0) { forceRemove = false; }
1529
1603
  // 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)
1530
- var workTodo = (this._isAutoCellHeight || !this.opts.disableOneColumnMode) && !this.parentGridItem;
1531
- if (!forceRemove && workTodo && !this._windowResizeBind) {
1532
- this._windowResizeBind = this.onParentResize.bind(this); // so we can properly remove later
1533
- window.addEventListener('resize', this._windowResizeBind);
1534
- }
1535
- else if ((forceRemove || !workTodo) && this._windowResizeBind) {
1536
- window.removeEventListener('resize', this._windowResizeBind);
1537
- delete this._windowResizeBind; // remove link to us so we can free
1604
+ // or supporting new fitToContent option.
1605
+ var trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.fitToContent || !this.opts.disableOneColumnMode || this.engine.nodes.find(function (n) { return n.fitToContent; }));
1606
+ if (!forceRemove && trackSize && !this.resizeObserver) {
1607
+ this._sizeThrottle = utils_1.Utils.throttle(function () { return _this.onResize(); }, this.opts.cellHeightThrottle);
1608
+ this.resizeObserver = new ResizeObserver(function (entries) { return _this._sizeThrottle(); });
1609
+ this.resizeObserver.observe(this.el);
1610
+ }
1611
+ else if ((forceRemove || !trackSize) && this.resizeObserver) {
1612
+ this.resizeObserver.disconnect();
1613
+ delete this.resizeObserver;
1614
+ delete this._sizeThrottle;
1538
1615
  }
1539
1616
  return this;
1540
1617
  };
@@ -2094,6 +2171,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2094
2171
  _this._updateContainerHeight(); // @ts-ignore
2095
2172
  _this._triggerChangeEvent();
2096
2173
  _this.engine.endUpdate();
2174
+ if (event.type === 'resizestop')
2175
+ _this.doContentResize(false, node);
2097
2176
  };
2098
2177
  dd.draggable(el, {
2099
2178
  start: onStartMoving,
@@ -2217,7 +2296,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2217
2296
  this.engine.cacheRects(cellWidth, cellHeight, mTop, mRight, mBottom, mLeft);
2218
2297
  delete node._skipDown;
2219
2298
  if (resizing && node.subGrid)
2220
- node.subGrid.onParentResize();
2299
+ node.subGrid.onResize();
2221
2300
  this._extraDragRow = 0; // @ts-ignore
2222
2301
  this._updateContainerHeight();
2223
2302
  var target = event.target; // @ts-ignore
@@ -2262,11 +2341,13 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2262
2341
  };
2263
2342
  // legacy method removed
2264
2343
  GridStack.prototype.commit = function () { (0, utils_1.obsolete)(this, this.batchUpdate(false), 'commit', 'batchUpdate', '5.2'); return this; };
2344
+ /** parent class for sizing content. defaults to '.grid-stack-item-content' */
2345
+ GridStack.resizeToContentParent = '.grid-stack-item-content';
2265
2346
  /** scoping so users can call GridStack.Utils.sort() for example */
2266
2347
  GridStack.Utils = utils_1.Utils;
2267
2348
  /** scoping so users can call new GridStack.Engine(12) for example */
2268
2349
  GridStack.Engine = gridstack_engine_1.GridStackEngine;
2269
- GridStack.GDRev = '8.4.0';
2350
+ GridStack.GDRev = '9.0.1';
2270
2351
  return GridStack;
2271
2352
  }());
2272
2353
  //# sourceMappingURL=gridstack.js.map