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
package/dist/gridstack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GridStack 8.4.0
2
+ * GridStack 9.0.1
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,60 @@ 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 child = item.firstElementChild;
1131
+ // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1132
+ if (!child) {
1133
+ console.log(`Error: resizeToContent() '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`);
1134
+ return;
1135
+ }
1136
+ const itemH = item.clientHeight; // available height to our child (minus border, padding...)
1137
+ const wantedH = child.getBoundingClientRect().height || itemH;
1138
+ if (itemH === wantedH)
1139
+ return;
1140
+ height += wantedH - itemH;
1141
+ const cell = this.getCellHeight();
1142
+ if (!cell)
1143
+ return;
1144
+ let h = Math.ceil(height / cell);
1145
+ if (n.maxH && h > n.maxH)
1146
+ h = n.maxH;
1147
+ if (h !== n.h) {
1148
+ this._ignoreLayoutsNodeChange = true;
1149
+ this.moveNode(n, { h });
1150
+ delete this._ignoreLayoutsNodeChange;
1151
+ }
1152
+ });
1153
+ }
1154
+ /** call the user resize (so we can do extra work) else our build in version */
1155
+ resizeToContentCheck(el) {
1156
+ if (GridStack.resizeToContentCB)
1157
+ GridStack.resizeToContentCB(el);
1158
+ else
1159
+ this.resizeToContent(el);
1160
+ }
1110
1161
  /**
1111
1162
  * 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
1163
  * @param value margin value
@@ -1300,6 +1351,8 @@ class GridStack {
1300
1351
  if (!Utils.same(node, copy)) {
1301
1352
  this._writeAttr(el, node);
1302
1353
  }
1354
+ if (Utils.shouldFitToContent(node))
1355
+ el.classList.add('fit-to-content');
1303
1356
  this._prepareDragDropByNode(node);
1304
1357
  return this;
1305
1358
  }
@@ -1393,65 +1446,84 @@ class GridStack {
1393
1446
  return this;
1394
1447
  }
1395
1448
  /**
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)
1449
+ * called when we are being resized - check if the one Column Mode needs to be turned on/off
1450
+ * and remember the prev columns we used, or get our count from parent, as well as check for cellHeight==='auto' (square)
1451
+ * or `fitToContent` gridItem options.
1398
1452
  */
1399
- onParentResize() {
1400
- if (!this.el || !this.el.clientWidth)
1453
+ onResize() {
1454
+ if (!this.el?.clientWidth)
1401
1455
  return; // return if we're gone or no size yet (will get called again)
1402
- let changedColumn = false;
1456
+ if (this.prevWidth === this.el.clientWidth)
1457
+ return; // no-op
1458
+ this.prevWidth = this.el.clientWidth;
1459
+ // console.log('onResize ', this.el.clientWidth);
1460
+ this.batchUpdate();
1403
1461
  // see if we're nested and take our column count from our parent....
1462
+ let columnChanged = false;
1404
1463
  if (this._autoColumn && this.parentGridItem) {
1405
1464
  if (this.opts.column !== this.parentGridItem.w) {
1406
- changedColumn = true;
1407
1465
  this.column(this.parentGridItem.w, 'none');
1466
+ columnChanged = true;
1408
1467
  }
1409
1468
  }
1410
1469
  else {
1411
1470
  // else check for 1 column in/out behavior
1412
- let oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize;
1471
+ let oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize ||
1472
+ (this.opts.column === 1 && !this._prevColumn);
1413
1473
  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
1474
+ // if (this.opts.animate) this.setAnimation(false); // 1 <-> 12 is too radical, turn off animation and we need it for fitToContent
1418
1475
  this.column(oneColumn ? 1 : this._prevColumn);
1419
- if (this.opts.animate) {
1420
- this.setAnimation(true);
1421
- }
1476
+ // if (this.opts.animate) setTimeout(() => this.setAnimation(true));
1477
+ columnChanged = true;
1422
1478
  }
1423
1479
  }
1424
1480
  // 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
1481
+ if (this._isAutoCellHeight)
1482
+ this.cellHeight();
1483
+ // update any nested grids, or items size
1438
1484
  this.engine.nodes.forEach(n => {
1439
1485
  if (n.subGrid)
1440
- n.subGrid.onParentResize();
1486
+ n.subGrid.onResize();
1441
1487
  });
1488
+ this.doContentResize(columnChanged);
1489
+ this.batchUpdate(false);
1442
1490
  return this;
1443
1491
  }
1444
- /** add or remove the window size event handler */
1445
- _updateWindowResizeEvent(forceRemove = false) {
1492
+ doContentResize(delay = true, n = undefined) {
1493
+ // update any gridItem height with fitToContent, but wait for DOM $animation_speed to settle if we changed column count
1494
+ // 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 ?
1495
+ setTimeout(() => {
1496
+ if (n) {
1497
+ if (Utils.shouldFitToContent(n))
1498
+ this.resizeToContentCheck(n.el);
1499
+ }
1500
+ else {
1501
+ const nodes = [...this.engine.nodes]; // in case order changes while resizing one
1502
+ this.batchUpdate();
1503
+ nodes.forEach(n => {
1504
+ if (Utils.shouldFitToContent(n))
1505
+ this.resizeToContentCheck(n.el);
1506
+ });
1507
+ this.batchUpdate(false);
1508
+ }
1509
+ if (this._gsEventHandler['resizeContent'])
1510
+ this._gsEventHandler['resizeContent'](null, n ? [n] : this.engine.nodes);
1511
+ }, delay ? 300 + 10 : 0);
1512
+ }
1513
+ /** add or remove the grid element size event handler */
1514
+ _updateResizeEvent(forceRemove = false) {
1446
1515
  // 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
1516
+ // or supporting new fitToContent option.
1517
+ const trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.fitToContent || !this.opts.disableOneColumnMode || this.engine.nodes.find(n => n.fitToContent));
1518
+ if (!forceRemove && trackSize && !this.resizeObserver) {
1519
+ this._sizeThrottle = Utils.throttle(() => this.onResize(), this.opts.cellHeightThrottle);
1520
+ this.resizeObserver = new ResizeObserver(entries => this._sizeThrottle());
1521
+ this.resizeObserver.observe(this.el);
1522
+ }
1523
+ else if ((forceRemove || !trackSize) && this.resizeObserver) {
1524
+ this.resizeObserver.disconnect();
1525
+ delete this.resizeObserver;
1526
+ delete this._sizeThrottle;
1455
1527
  }
1456
1528
  return this;
1457
1529
  }
@@ -1991,6 +2063,8 @@ class GridStack {
1991
2063
  this._updateContainerHeight(); // @ts-ignore
1992
2064
  this._triggerChangeEvent();
1993
2065
  this.engine.endUpdate();
2066
+ if (event.type === 'resizestop')
2067
+ this.doContentResize(false, node);
1994
2068
  };
1995
2069
  dd.draggable(el, {
1996
2070
  start: onStartMoving,
@@ -2114,7 +2188,7 @@ class GridStack {
2114
2188
  this.engine.cacheRects(cellWidth, cellHeight, mTop, mRight, mBottom, mLeft);
2115
2189
  delete node._skipDown;
2116
2190
  if (resizing && node.subGrid)
2117
- node.subGrid.onParentResize();
2191
+ node.subGrid.onResize();
2118
2192
  this._extraDragRow = 0; // @ts-ignore
2119
2193
  this._updateContainerHeight();
2120
2194
  let target = event.target; // @ts-ignore
@@ -2160,10 +2234,12 @@ class GridStack {
2160
2234
  // legacy method removed
2161
2235
  commit() { obsolete(this, this.batchUpdate(false), 'commit', 'batchUpdate', '5.2'); return this; }
2162
2236
  }
2237
+ /** parent class for sizing content. defaults to '.grid-stack-item-content' */
2238
+ GridStack.resizeToContentParent = '.grid-stack-item-content';
2163
2239
  /** scoping so users can call GridStack.Utils.sort() for example */
2164
2240
  GridStack.Utils = Utils;
2165
2241
  /** scoping so users can call new GridStack.Engine(12) for example */
2166
2242
  GridStack.Engine = GridStackEngine;
2167
- GridStack.GDRev = '8.4.0';
2243
+ GridStack.GDRev = '9.0.1';
2168
2244
  export { GridStack };
2169
2245
  //# sourceMappingURL=gridstack.js.map