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
package/dist/gridstack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GridStack 8.4.0
2
+ * GridStack 9.0.0
3
3
  * https://gridstackjs.com/
4
4
  *
5
5
  * Copyright (c) 2021-2022 Alain Dumesny
@@ -280,7 +280,7 @@ class GridStack {
280
280
  DDManager.pauseDrag = this.opts.draggable.pause;
281
281
  this._setupRemoveDrop();
282
282
  this._setupAcceptWidget();
283
- this._updateWindowResizeEvent();
283
+ this._updateResizeEvent();
284
284
  }
285
285
  /**
286
286
  * add a new widget and returns it.
@@ -612,6 +612,7 @@ class GridStack {
612
612
  batchUpdate(flag = true) {
613
613
  this.engine.batchUpdate(flag);
614
614
  if (!flag) {
615
+ this._updateContainerHeight();
615
616
  this._triggerRemoveEvent();
616
617
  this._triggerAddEvent();
617
618
  this._triggerChangeEvent();
@@ -655,7 +656,7 @@ class GridStack {
655
656
  if (update && val !== undefined) {
656
657
  if (this._isAutoCellHeight !== (val === 'auto')) {
657
658
  this._isAutoCellHeight = (val === 'auto');
658
- this._updateWindowResizeEvent();
659
+ this._updateResizeEvent();
659
660
  }
660
661
  }
661
662
  if (val === 'initial' || val === 'auto') {
@@ -710,7 +711,7 @@ class GridStack {
710
711
  * Note: items will never be outside of the current column boundaries. default ('moveScale'). Ignored for 1 column
711
712
  */
712
713
  column(column, layout = 'moveScale') {
713
- if (column < 1 || this.opts.column === column)
714
+ if (!column || column < 1 || this.opts.column === column)
714
715
  return this;
715
716
  let oldColumn = this.getColumn();
716
717
  // if we go into 1 column mode (which happens if we're sized less than minW unless disableOneColumnMode is on)
@@ -740,6 +741,7 @@ class GridStack {
740
741
  this.engine.columnChanged(oldColumn, column, domNodes, layout);
741
742
  if (this._isAutoCellHeight)
742
743
  this.cellHeight();
744
+ this.doContentResize();
743
745
  // and trigger our event last...
744
746
  this._ignoreLayoutsNodeChange = true; // skip layout update
745
747
  this._triggerChangeEvent();
@@ -765,7 +767,7 @@ class GridStack {
765
767
  if (!this.el)
766
768
  return; // prevent multiple calls
767
769
  this.offAll();
768
- this._updateWindowResizeEvent(true);
770
+ this._updateResizeEvent(true);
769
771
  this.setStatic(true, false); // permanently removes DD but don't set CSS class (we're going away)
770
772
  this.setAnimation(false);
771
773
  if (!removeDOM) {
@@ -911,7 +913,8 @@ class GridStack {
911
913
  }
912
914
  this.el.addEventListener(name, this._gsEventHandler[name]);
913
915
  }
914
- else if (name === 'drag' || name === 'dragstart' || name === 'dragstop' || name === 'resizestart' || name === 'resize' || name === 'resizestop' || name === 'dropped') {
916
+ else if (name === 'drag' || name === 'dragstart' || name === 'dragstop' || name === 'resizestart' || name === 'resize'
917
+ || name === 'resizestop' || name === 'dropped' || name === 'resizecontent') {
915
918
  // drag&drop stop events NEED to be call them AFTER we update node attributes so handle them ourself.
916
919
  // do same for start event to make it easier...
917
920
  this._gsEventHandler[name] = callback;
@@ -1090,14 +1093,8 @@ class GridStack {
1090
1093
  }
1091
1094
  Utils.sanitizeMinMax(n);
1092
1095
  // finally move the widget
1093
- if (m) {
1094
- this.engine.cleanNodes()
1095
- .beginUpdate(n)
1096
- .moveNode(n, m);
1097
- this._updateContainerHeight();
1098
- this._triggerChangeEvent();
1099
- this.engine.endUpdate();
1100
- }
1096
+ if (m)
1097
+ this.moveNode(n, m);
1101
1098
  if (changed) { // move will only update x,y,w,h so update the rest too
1102
1099
  this._writeAttr(el, n);
1103
1100
  }
@@ -1107,6 +1104,54 @@ class GridStack {
1107
1104
  });
1108
1105
  return this;
1109
1106
  }
1107
+ moveNode(n, m) {
1108
+ this.engine.cleanNodes()
1109
+ .beginUpdate(n)
1110
+ .moveNode(n, m);
1111
+ this._updateContainerHeight();
1112
+ this._triggerChangeEvent();
1113
+ this.engine.endUpdate();
1114
+ }
1115
+ /** Updates widget height to match the content height to avoid v-scrollbar or dead space.
1116
+ Note: this assumes only 1 child under '.grid-stack-item-content' (sized to gridItem minus padding) that is at the entire content size wanted */
1117
+ resizeToContent(els) {
1118
+ GridStack.getElements(els).forEach(el => {
1119
+ let n = el?.gridstackNode;
1120
+ if (!n)
1121
+ return;
1122
+ if (el.parentElement !== n.grid.el)
1123
+ return; // skip if we are not inside a grid
1124
+ let height = el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1125
+ if (!height)
1126
+ return; // 0 when hidden, skip
1127
+ const item = el.querySelector(GridStack.resizeToContentParent);
1128
+ if (!item)
1129
+ return;
1130
+ const itemH = item.clientHeight; // available height to our child (minus border, padding...)
1131
+ const wantedH = item.firstChild?.getBoundingClientRect().height || itemH; // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1132
+ if (itemH === wantedH)
1133
+ return;
1134
+ height += wantedH - itemH;
1135
+ const cell = this.getCellHeight();
1136
+ if (!cell)
1137
+ return;
1138
+ let h = Math.ceil(height / cell);
1139
+ if (n.maxH && h > n.maxH)
1140
+ h = n.maxH;
1141
+ if (h !== n.h) {
1142
+ this._ignoreLayoutsNodeChange = true;
1143
+ this.moveNode(n, { h });
1144
+ delete this._ignoreLayoutsNodeChange;
1145
+ }
1146
+ });
1147
+ }
1148
+ /** call the user resize (so we can do extra work) else our build in version */
1149
+ resizeToContentCheck(el) {
1150
+ if (GridStack.resizeToContentCB)
1151
+ GridStack.resizeToContentCB(el);
1152
+ else
1153
+ this.resizeToContent(el);
1154
+ }
1110
1155
  /**
1111
1156
  * 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).
1112
1157
  * @param value margin value
@@ -1300,6 +1345,8 @@ class GridStack {
1300
1345
  if (!Utils.same(node, copy)) {
1301
1346
  this._writeAttr(el, node);
1302
1347
  }
1348
+ if (Utils.shouldFitToContent(node))
1349
+ el.classList.add('fit-to-content');
1303
1350
  this._prepareDragDropByNode(node);
1304
1351
  return this;
1305
1352
  }
@@ -1393,65 +1440,81 @@ class GridStack {
1393
1440
  return this;
1394
1441
  }
1395
1442
  /**
1396
- * called when we are being resized by the window - check if the one Column Mode needs to be turned on/off
1397
- * and remember the prev columns we used, or get our count from parent, as well as check for auto cell height (square)
1443
+ * called when we are being resized - check if the one Column Mode needs to be turned on/off
1444
+ * and remember the prev columns we used, or get our count from parent, as well as check for cellHeight==='auto' (square)
1445
+ * or `fitToContent` gridItem options.
1398
1446
  */
1399
- onParentResize() {
1400
- if (!this.el || !this.el.clientWidth)
1447
+ onResize() {
1448
+ if (!this.el?.clientWidth)
1401
1449
  return; // return if we're gone or no size yet (will get called again)
1402
- let changedColumn = false;
1450
+ if (this.prevWidth === this.el.clientWidth)
1451
+ return; // no-op
1452
+ this.prevWidth = this.el.clientWidth;
1453
+ // console.log('onResize ', this.el.clientWidth);
1454
+ this.batchUpdate();
1403
1455
  // see if we're nested and take our column count from our parent....
1456
+ let columnChanged = false;
1404
1457
  if (this._autoColumn && this.parentGridItem) {
1405
1458
  if (this.opts.column !== this.parentGridItem.w) {
1406
- changedColumn = true;
1407
1459
  this.column(this.parentGridItem.w, 'none');
1460
+ columnChanged = true;
1408
1461
  }
1409
1462
  }
1410
1463
  else {
1411
1464
  // else check for 1 column in/out behavior
1412
- let oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize;
1465
+ let oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize ||
1466
+ (this.opts.column === 1 && !this._prevColumn);
1413
1467
  if ((this.opts.column === 1) !== oneColumn) {
1414
- changedColumn = true;
1415
- if (this.opts.animate) {
1416
- this.setAnimation(false);
1417
- } // 1 <-> 12 is too radical, turn off animation
1468
+ // if (this.opts.animate) this.setAnimation(false); // 1 <-> 12 is too radical, turn off animation and we need it for fitToContent
1418
1469
  this.column(oneColumn ? 1 : this._prevColumn);
1419
- if (this.opts.animate) {
1420
- this.setAnimation(true);
1421
- }
1470
+ // if (this.opts.animate) setTimeout(() => this.setAnimation(true));
1471
+ columnChanged = true;
1422
1472
  }
1423
1473
  }
1424
1474
  // make the cells content square again
1425
- if (this._isAutoCellHeight) {
1426
- if (!changedColumn && this.opts.cellHeightThrottle) {
1427
- if (!this._cellHeightThrottle) {
1428
- this._cellHeightThrottle = Utils.throttle(() => this.cellHeight(), this.opts.cellHeightThrottle);
1429
- }
1430
- this._cellHeightThrottle();
1431
- }
1432
- else {
1433
- // immediate update if we've changed column count or have no threshold
1434
- this.cellHeight();
1435
- }
1436
- }
1437
- // finally update any nested grids
1475
+ if (this._isAutoCellHeight)
1476
+ this.cellHeight();
1477
+ // update any nested grids, or items size
1438
1478
  this.engine.nodes.forEach(n => {
1439
1479
  if (n.subGrid)
1440
- n.subGrid.onParentResize();
1480
+ n.subGrid.onResize();
1441
1481
  });
1482
+ this.doContentResize(columnChanged);
1483
+ this.batchUpdate(false);
1442
1484
  return this;
1443
1485
  }
1444
- /** add or remove the window size event handler */
1445
- _updateWindowResizeEvent(forceRemove = false) {
1486
+ doContentResize(delay = true, n = undefined) {
1487
+ // update any gridItem height with fitToContent, but wait for DOM $animation_speed to settle if we changed column count
1488
+ // 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 ?
1489
+ setTimeout(() => {
1490
+ if (n) {
1491
+ if (Utils.shouldFitToContent(n))
1492
+ this.resizeToContentCheck(n.el);
1493
+ }
1494
+ else {
1495
+ this.engine.nodes.forEach(n => {
1496
+ if (Utils.shouldFitToContent(n))
1497
+ this.resizeToContentCheck(n.el);
1498
+ });
1499
+ }
1500
+ if (this._gsEventHandler['resizeContent'])
1501
+ this._gsEventHandler['resizeContent'](null, n ? [n] : this.engine.nodes);
1502
+ }, delay ? 300 + 10 : 0);
1503
+ }
1504
+ /** add or remove the grid element size event handler */
1505
+ _updateResizeEvent(forceRemove = false) {
1446
1506
  // 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)
1447
- const workTodo = (this._isAutoCellHeight || !this.opts.disableOneColumnMode) && !this.parentGridItem;
1448
- if (!forceRemove && workTodo && !this._windowResizeBind) {
1449
- this._windowResizeBind = this.onParentResize.bind(this); // so we can properly remove later
1450
- window.addEventListener('resize', this._windowResizeBind);
1451
- }
1452
- else if ((forceRemove || !workTodo) && this._windowResizeBind) {
1453
- window.removeEventListener('resize', this._windowResizeBind);
1454
- delete this._windowResizeBind; // remove link to us so we can free
1507
+ // or supporting new fitToContent option.
1508
+ const trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.fitToContent || !this.opts.disableOneColumnMode || this.engine.nodes.find(n => n.fitToContent));
1509
+ if (!forceRemove && trackSize && !this.resizeObserver) {
1510
+ this._sizeThrottle = Utils.throttle(() => this.onResize(), this.opts.cellHeightThrottle);
1511
+ this.resizeObserver = new ResizeObserver(entries => this._sizeThrottle());
1512
+ this.resizeObserver.observe(this.el);
1513
+ }
1514
+ else if ((forceRemove || !trackSize) && this.resizeObserver) {
1515
+ this.resizeObserver.disconnect();
1516
+ delete this.resizeObserver;
1517
+ delete this._sizeThrottle;
1455
1518
  }
1456
1519
  return this;
1457
1520
  }
@@ -1991,6 +2054,8 @@ class GridStack {
1991
2054
  this._updateContainerHeight(); // @ts-ignore
1992
2055
  this._triggerChangeEvent();
1993
2056
  this.engine.endUpdate();
2057
+ if (event.type === 'resizestop')
2058
+ this.doContentResize(false, node);
1994
2059
  };
1995
2060
  dd.draggable(el, {
1996
2061
  start: onStartMoving,
@@ -2114,7 +2179,7 @@ class GridStack {
2114
2179
  this.engine.cacheRects(cellWidth, cellHeight, mTop, mRight, mBottom, mLeft);
2115
2180
  delete node._skipDown;
2116
2181
  if (resizing && node.subGrid)
2117
- node.subGrid.onParentResize();
2182
+ node.subGrid.onResize();
2118
2183
  this._extraDragRow = 0; // @ts-ignore
2119
2184
  this._updateContainerHeight();
2120
2185
  let target = event.target; // @ts-ignore
@@ -2160,10 +2225,12 @@ class GridStack {
2160
2225
  // legacy method removed
2161
2226
  commit() { obsolete(this, this.batchUpdate(false), 'commit', 'batchUpdate', '5.2'); return this; }
2162
2227
  }
2228
+ /** parent class for sizing content. defaults to '.grid-stack-item-content' */
2229
+ GridStack.resizeToContentParent = '.grid-stack-item-content';
2163
2230
  /** scoping so users can call GridStack.Utils.sort() for example */
2164
2231
  GridStack.Utils = Utils;
2165
2232
  /** scoping so users can call new GridStack.Engine(12) for example */
2166
2233
  GridStack.Engine = GridStackEngine;
2167
- GridStack.GDRev = '8.4.0';
2234
+ GridStack.GDRev = '9.0.0';
2168
2235
  export { GridStack };
2169
2236
  //# sourceMappingURL=gridstack.js.map