gridstack 8.4.0 → 9.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 (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 +1 -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 +1 -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 +128 -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 +121 -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 +6 -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.0
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,56 @@ 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 _a;
1196
+ var n = el === null || el === void 0 ? void 0 : el.gridstackNode;
1197
+ if (!n)
1198
+ return;
1199
+ if (el.parentElement !== n.grid.el)
1200
+ return; // skip if we are not inside a grid
1201
+ var height = el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1202
+ if (!height)
1203
+ return; // 0 when hidden, skip
1204
+ var item = el.querySelector(GridStack.resizeToContentParent);
1205
+ if (!item)
1206
+ return;
1207
+ var itemH = item.clientHeight; // available height to our child (minus border, padding...)
1208
+ var wantedH = ((_a = item.firstChild) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height) || itemH; // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1209
+ if (itemH === wantedH)
1210
+ return;
1211
+ height += wantedH - itemH;
1212
+ var cell = _this.getCellHeight();
1213
+ if (!cell)
1214
+ return;
1215
+ var h = Math.ceil(height / cell);
1216
+ if (n.maxH && h > n.maxH)
1217
+ h = n.maxH;
1218
+ if (h !== n.h) {
1219
+ _this._ignoreLayoutsNodeChange = true;
1220
+ _this.moveNode(n, { h: h });
1221
+ delete _this._ignoreLayoutsNodeChange;
1222
+ }
1223
+ });
1224
+ };
1225
+ /** call the user resize (so we can do extra work) else our build in version */
1226
+ GridStack.prototype.resizeToContentCheck = function (el) {
1227
+ if (GridStack.resizeToContentCB)
1228
+ GridStack.resizeToContentCB(el);
1229
+ else
1230
+ this.resizeToContent(el);
1231
+ };
1185
1232
  /**
1186
1233
  * 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
1234
  * @param value margin value
@@ -1379,6 +1426,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1379
1426
  if (!utils_1.Utils.same(node, copy)) {
1380
1427
  this._writeAttr(el, node);
1381
1428
  }
1429
+ if (utils_1.Utils.shouldFitToContent(node))
1430
+ el.classList.add('fit-to-content');
1382
1431
  this._prepareDragDropByNode(node);
1383
1432
  return this;
1384
1433
  };
@@ -1474,67 +1523,87 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1474
1523
  return this;
1475
1524
  };
1476
1525
  /**
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)
1526
+ * called when we are being resized - check if the one Column Mode needs to be turned on/off
1527
+ * and remember the prev columns we used, or get our count from parent, as well as check for cellHeight==='auto' (square)
1528
+ * or `fitToContent` gridItem options.
1479
1529
  */
1480
- GridStack.prototype.onParentResize = function () {
1481
- var _this = this;
1482
- if (!this.el || !this.el.clientWidth)
1530
+ GridStack.prototype.onResize = function () {
1531
+ var _a;
1532
+ if (!((_a = this.el) === null || _a === void 0 ? void 0 : _a.clientWidth))
1483
1533
  return; // return if we're gone or no size yet (will get called again)
1484
- var changedColumn = false;
1534
+ if (this.prevWidth === this.el.clientWidth)
1535
+ return; // no-op
1536
+ this.prevWidth = this.el.clientWidth;
1537
+ // console.log('onResize ', this.el.clientWidth);
1538
+ this.batchUpdate();
1485
1539
  // see if we're nested and take our column count from our parent....
1540
+ var columnChanged = false;
1486
1541
  if (this._autoColumn && this.parentGridItem) {
1487
1542
  if (this.opts.column !== this.parentGridItem.w) {
1488
- changedColumn = true;
1489
1543
  this.column(this.parentGridItem.w, 'none');
1544
+ columnChanged = true;
1490
1545
  }
1491
1546
  }
1492
1547
  else {
1493
1548
  // else check for 1 column in/out behavior
1494
- var oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize;
1549
+ var oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize ||
1550
+ (this.opts.column === 1 && !this._prevColumn);
1495
1551
  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
1552
+ // if (this.opts.animate) this.setAnimation(false); // 1 <-> 12 is too radical, turn off animation and we need it for fitToContent
1500
1553
  this.column(oneColumn ? 1 : this._prevColumn);
1501
- if (this.opts.animate) {
1502
- this.setAnimation(true);
1503
- }
1554
+ // if (this.opts.animate) setTimeout(() => this.setAnimation(true));
1555
+ columnChanged = true;
1504
1556
  }
1505
1557
  }
1506
1558
  // 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
1559
+ if (this._isAutoCellHeight)
1560
+ this.cellHeight();
1561
+ // update any nested grids, or items size
1520
1562
  this.engine.nodes.forEach(function (n) {
1521
1563
  if (n.subGrid)
1522
- n.subGrid.onParentResize();
1564
+ n.subGrid.onResize();
1523
1565
  });
1566
+ this.doContentResize(columnChanged);
1567
+ this.batchUpdate(false);
1524
1568
  return this;
1525
1569
  };
1526
- /** add or remove the window size event handler */
1527
- GridStack.prototype._updateWindowResizeEvent = function (forceRemove) {
1570
+ GridStack.prototype.doContentResize = function (delay, n) {
1571
+ var _this = this;
1572
+ if (delay === void 0) { delay = true; }
1573
+ if (n === void 0) { n = undefined; }
1574
+ // update any gridItem height with fitToContent, but wait for DOM $animation_speed to settle if we changed column count
1575
+ // 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 ?
1576
+ setTimeout(function () {
1577
+ if (n) {
1578
+ if (utils_1.Utils.shouldFitToContent(n))
1579
+ _this.resizeToContentCheck(n.el);
1580
+ }
1581
+ else {
1582
+ _this.engine.nodes.forEach(function (n) {
1583
+ if (utils_1.Utils.shouldFitToContent(n))
1584
+ _this.resizeToContentCheck(n.el);
1585
+ });
1586
+ }
1587
+ if (_this._gsEventHandler['resizeContent'])
1588
+ _this._gsEventHandler['resizeContent'](null, n ? [n] : _this.engine.nodes);
1589
+ }, delay ? 300 + 10 : 0);
1590
+ };
1591
+ /** add or remove the grid element size event handler */
1592
+ GridStack.prototype._updateResizeEvent = function (forceRemove) {
1593
+ var _this = this;
1528
1594
  if (forceRemove === void 0) { forceRemove = false; }
1529
1595
  // 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
1596
+ // or supporting new fitToContent option.
1597
+ var trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.fitToContent || !this.opts.disableOneColumnMode || this.engine.nodes.find(function (n) { return n.fitToContent; }));
1598
+ if (!forceRemove && trackSize && !this.resizeObserver) {
1599
+ this._sizeThrottle = utils_1.Utils.throttle(function () { return _this.onResize(); }, this.opts.cellHeightThrottle);
1600
+ this.resizeObserver = new ResizeObserver(function (entries) { return _this._sizeThrottle(); });
1601
+ this.resizeObserver.observe(this.el);
1602
+ }
1603
+ else if ((forceRemove || !trackSize) && this.resizeObserver) {
1604
+ this.resizeObserver.disconnect();
1605
+ delete this.resizeObserver;
1606
+ delete this._sizeThrottle;
1538
1607
  }
1539
1608
  return this;
1540
1609
  };
@@ -2094,6 +2163,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2094
2163
  _this._updateContainerHeight(); // @ts-ignore
2095
2164
  _this._triggerChangeEvent();
2096
2165
  _this.engine.endUpdate();
2166
+ if (event.type === 'resizestop')
2167
+ _this.doContentResize(false, node);
2097
2168
  };
2098
2169
  dd.draggable(el, {
2099
2170
  start: onStartMoving,
@@ -2217,7 +2288,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2217
2288
  this.engine.cacheRects(cellWidth, cellHeight, mTop, mRight, mBottom, mLeft);
2218
2289
  delete node._skipDown;
2219
2290
  if (resizing && node.subGrid)
2220
- node.subGrid.onParentResize();
2291
+ node.subGrid.onResize();
2221
2292
  this._extraDragRow = 0; // @ts-ignore
2222
2293
  this._updateContainerHeight();
2223
2294
  var target = event.target; // @ts-ignore
@@ -2262,11 +2333,13 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2262
2333
  };
2263
2334
  // legacy method removed
2264
2335
  GridStack.prototype.commit = function () { (0, utils_1.obsolete)(this, this.batchUpdate(false), 'commit', 'batchUpdate', '5.2'); return this; };
2336
+ /** parent class for sizing content. defaults to '.grid-stack-item-content' */
2337
+ GridStack.resizeToContentParent = '.grid-stack-item-content';
2265
2338
  /** scoping so users can call GridStack.Utils.sort() for example */
2266
2339
  GridStack.Utils = utils_1.Utils;
2267
2340
  /** scoping so users can call new GridStack.Engine(12) for example */
2268
2341
  GridStack.Engine = gridstack_engine_1.GridStackEngine;
2269
- GridStack.GDRev = '8.4.0';
2342
+ GridStack.GDRev = '9.0.0';
2270
2343
  return GridStack;
2271
2344
  }());
2272
2345
  //# sourceMappingURL=gridstack.js.map