gridstack 9.0.2 → 9.1.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 +1 -1
  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 +2 -2
  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 +2 -2
  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 +2 -2
  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 +2 -2
  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 +3 -2
  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 +9 -6
  84. package/dist/es5/gridstack.js +83 -66
  85. package/dist/es5/gridstack.js.map +1 -1
  86. package/dist/es5/types.d.ts +10 -7
  87. package/dist/es5/types.js +1 -1
  88. package/dist/es5/types.js.map +1 -1
  89. package/dist/es5/utils.d.ts +2 -2
  90. package/dist/es5/utils.js +4 -4
  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 +3 -2
  97. package/dist/gridstack-engine.js.map +1 -1
  98. package/dist/gridstack.css +2 -2
  99. package/dist/gridstack.d.ts +9 -6
  100. package/dist/gridstack.js +80 -65
  101. package/dist/gridstack.js.map +1 -1
  102. package/dist/gridstack.min.css +1 -1
  103. package/dist/src/gridstack.scss +2 -2
  104. package/dist/types.d.ts +10 -7
  105. package/dist/types.js +1 -1
  106. package/dist/types.js.map +1 -1
  107. package/dist/utils.d.ts +2 -2
  108. package/dist/utils.js +4 -4
  109. package/dist/utils.js.map +1 -1
  110. package/doc/CHANGES.md +14 -3
  111. package/doc/README.md +3 -2
  112. package/package.json +1 -1
package/dist/gridstack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GridStack 9.0.2
2
+ * GridStack 9.1.1
3
3
  * https://gridstackjs.com/
4
4
  *
5
5
  * Copyright (c) 2021-2022 Alain Dumesny
@@ -674,7 +674,7 @@ class GridStack {
674
674
  }
675
675
  this.opts.cellHeightUnit = data.unit;
676
676
  this.opts.cellHeight = data.h;
677
- this.doContentResize(false);
677
+ this.doContentResize(false, true); // no anim wait, but use attributes since we only change row height
678
678
  if (update) {
679
679
  this._updateStyles(true); // true = force re-create for current # of rows
680
680
  }
@@ -866,7 +866,7 @@ class GridStack {
866
866
  this._prepareElement(el, true, options);
867
867
  const node = el.gridstackNode;
868
868
  this._updateContainerHeight();
869
- this.doContentResize(false, node);
869
+ this.doContentResize(false, false, node);
870
870
  // see if there is a sub-grid to create
871
871
  if (node.subGridOpts) {
872
872
  this.makeSubGrid(el, node.subGridOpts, undefined, false); // node.subGrid will be used as option in method, no need to pass
@@ -1114,57 +1114,69 @@ class GridStack {
1114
1114
  this._triggerChangeEvent();
1115
1115
  this.engine.endUpdate();
1116
1116
  }
1117
- /** Updates widget height to match the content height to avoid v-scrollbar or dead space.
1118
- Note: this assumes only 1 child under '.grid-stack-item-content' (sized to gridItem minus padding) that is at the entire content size wanted */
1119
- resizeToContent(els) {
1120
- GridStack.getElements(els).forEach(el => {
1121
- let n = el?.gridstackNode;
1122
- if (!n)
1123
- return;
1124
- const grid = n.grid;
1125
- if (grid !== this)
1126
- return grid?.resizeToContent(el);
1127
- if (el.parentElement !== this.el)
1128
- return; // skip if we are not inside a grid
1129
- const cell = this.getCellHeight();
1130
- if (!cell)
1131
- return;
1132
- let height = n.h ? n.h * cell : el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1133
- if (!height)
1134
- return; // 0 when hidden, skip
1135
- const item = el.querySelector(GridStack.resizeToContentParent);
1136
- if (!item)
1137
- return;
1138
- const child = item.firstElementChild;
1139
- // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1140
- if (!child) {
1141
- console.log(`Error: resizeToContent() '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`);
1142
- return;
1143
- }
1144
- const padding = el.clientHeight - item.clientHeight; // full - available height to our child (minus border, padding...)
1145
- const itemH = n.h ? n.h * cell - padding : item.clientHeight; // calculated to what cellHeight is or will become (rather than actual to prevent waiting for animation to finish)
1146
- const wantedH = child.getBoundingClientRect().height || itemH;
1147
- if (itemH === wantedH)
1148
- return;
1149
- height += wantedH - itemH;
1150
- let h = Math.ceil(height / cell);
1151
- if (n.minH && h < n.minH)
1152
- h = n.minH;
1153
- else if (n.maxH && h > n.maxH)
1154
- h = n.maxH;
1155
- if (h !== n.h) {
1156
- this._ignoreLayoutsNodeChange = true;
1157
- this.moveNode(n, { h });
1158
- delete this._ignoreLayoutsNodeChange;
1159
- }
1160
- });
1117
+ /**
1118
+ * Updates widget height to match the content height to avoid v-scrollbar or dead space.
1119
+ * Note: this assumes only 1 child under resizeToContentParent='.grid-stack-item-content' (sized to gridItem minus padding) that is at the entire content size wanted.
1120
+ * useAttrSize set to true if GridStackNode.h should be used instead of actual container height when we don't need to wait for animation to finish to get actual DOM heights
1121
+ **/
1122
+ resizeToContent(el, useAttrSize = false) {
1123
+ el?.classList.remove('size-to-content-max');
1124
+ if (!el?.clientHeight)
1125
+ return; // 0 when hidden, skip
1126
+ let n = el.gridstackNode;
1127
+ if (!n)
1128
+ return;
1129
+ const grid = n.grid;
1130
+ if (!grid)
1131
+ return;
1132
+ if (el.parentElement !== grid.el)
1133
+ return; // skip if we are not inside a grid
1134
+ const cell = grid.getCellHeight();
1135
+ if (!cell)
1136
+ return;
1137
+ let height = useAttrSize && n.h ? n.h * cell : el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1138
+ let item;
1139
+ if (n.resizeToContentParent)
1140
+ item = el.querySelector(n.resizeToContentParent);
1141
+ if (!item)
1142
+ item = el.querySelector(GridStack.resizeToContentParent);
1143
+ if (!item)
1144
+ return;
1145
+ const child = item.firstElementChild;
1146
+ // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1147
+ if (!child) {
1148
+ console.log(`Error: resizeToContent() '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`);
1149
+ return;
1150
+ }
1151
+ const padding = el.clientHeight - item.clientHeight; // full - available height to our child (minus border, padding...)
1152
+ const itemH = useAttrSize && n.h ? n.h * cell - padding : item.clientHeight; // calculated to what cellHeight is or will become (rather than actual to prevent waiting for animation to finish)
1153
+ const wantedH = child.getBoundingClientRect().height || itemH;
1154
+ if (itemH === wantedH)
1155
+ return;
1156
+ height += wantedH - itemH;
1157
+ let h = Math.ceil(height / cell);
1158
+ // check for min/max and special sizing
1159
+ const softMax = Number.isInteger(n.sizeToContent) ? n.sizeToContent : 0;
1160
+ if (softMax && h > softMax) {
1161
+ h = softMax;
1162
+ el.classList.add('size-to-content-max'); // get v-scroll back
1163
+ }
1164
+ if (n.minH && h < n.minH)
1165
+ h = n.minH;
1166
+ else if (n.maxH && h > n.maxH)
1167
+ h = n.maxH;
1168
+ if (h !== n.h) {
1169
+ grid._ignoreLayoutsNodeChange = true;
1170
+ grid.moveNode(n, { h });
1171
+ delete grid._ignoreLayoutsNodeChange;
1172
+ }
1161
1173
  }
1162
1174
  /** call the user resize (so we can do extra work) else our build in version */
1163
- resizeToContentCheck(el) {
1175
+ resizeToContentCheck(el, useAttr = false) {
1164
1176
  if (GridStack.resizeToContentCB)
1165
1177
  GridStack.resizeToContentCB(el);
1166
1178
  else
1167
- this.resizeToContent(el);
1179
+ this.resizeToContent(el, useAttr);
1168
1180
  }
1169
1181
  /**
1170
1182
  * 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).
@@ -1359,8 +1371,8 @@ class GridStack {
1359
1371
  if (!Utils.same(node, copy)) {
1360
1372
  this._writeAttr(el, node);
1361
1373
  }
1362
- if (Utils.shouldFitToContent(node))
1363
- el.classList.add('fit-to-content');
1374
+ if (Utils.shouldSizeToContent(node))
1375
+ el.classList.add('size-to-content');
1364
1376
  this._prepareDragDropByNode(node);
1365
1377
  return this;
1366
1378
  }
@@ -1456,7 +1468,7 @@ class GridStack {
1456
1468
  /**
1457
1469
  * called when we are being resized - check if the one Column Mode needs to be turned on/off
1458
1470
  * and remember the prev columns we used, or get our count from parent, as well as check for cellHeight==='auto' (square)
1459
- * or `fitToContent` gridItem options.
1471
+ * or `sizeToContent` gridItem options.
1460
1472
  */
1461
1473
  onResize() {
1462
1474
  if (!this.el?.clientWidth)
@@ -1479,7 +1491,7 @@ class GridStack {
1479
1491
  let oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize ||
1480
1492
  (this.opts.column === 1 && !this._prevColumn);
1481
1493
  if ((this.opts.column === 1) !== oneColumn) {
1482
- // if (this.opts.animate) this.setAnimation(false); // 1 <-> 12 is too radical, turn off animation and we need it for fitToContent
1494
+ // if (this.opts.animate) this.setAnimation(false); // 1 <-> 12 is too radical, turn off animation and we need it for sizeToContent
1483
1495
  this.column(oneColumn ? 1 : this._prevColumn);
1484
1496
  // if (this.opts.animate) setTimeout(() => this.setAnimation(true));
1485
1497
  columnChanged = true;
@@ -1493,24 +1505,24 @@ class GridStack {
1493
1505
  if (n.subGrid)
1494
1506
  n.subGrid.onResize();
1495
1507
  });
1496
- this.doContentResize(columnChanged);
1508
+ this.doContentResize(columnChanged); // wait for anim of column changed (DOM reflow before we can size correctly)
1497
1509
  this.batchUpdate(false);
1498
1510
  return this;
1499
1511
  }
1500
- doContentResize(delay = true, n = undefined) {
1501
- // update any gridItem height with fitToContent, but wait for DOM $animation_speed to settle if we changed column count
1512
+ doContentResize(delay = true, useAttr = false, n = undefined) {
1513
+ // update any gridItem height with sizeToContent, but wait for DOM $animation_speed to settle if we changed column count
1502
1514
  // 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 ?
1503
1515
  setTimeout(() => {
1504
1516
  if (n) {
1505
- if (Utils.shouldFitToContent(n))
1506
- this.resizeToContentCheck(n.el);
1517
+ if (Utils.shouldSizeToContent(n))
1518
+ this.resizeToContentCheck(n.el, useAttr);
1507
1519
  }
1508
1520
  else {
1509
1521
  const nodes = [...this.engine.nodes]; // in case order changes while resizing one
1510
1522
  this.batchUpdate();
1511
1523
  nodes.forEach(n => {
1512
- if (Utils.shouldFitToContent(n))
1513
- this.resizeToContentCheck(n.el);
1524
+ if (Utils.shouldSizeToContent(n))
1525
+ this.resizeToContentCheck(n.el, useAttr);
1514
1526
  });
1515
1527
  this.batchUpdate(false);
1516
1528
  }
@@ -1521,8 +1533,8 @@ class GridStack {
1521
1533
  /** add or remove the grid element size event handler */
1522
1534
  _updateResizeEvent(forceRemove = false) {
1523
1535
  // 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)
1524
- // or supporting new fitToContent option.
1525
- const trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.fitToContent || !this.opts.disableOneColumnMode || this.engine.nodes.find(n => n.fitToContent));
1536
+ // or supporting new sizeToContent option.
1537
+ const trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.sizeToContent || !this.opts.disableOneColumnMode || this.engine.nodes.find(n => n.sizeToContent));
1526
1538
  if (!forceRemove && trackSize && !this.resizeObserver) {
1527
1539
  this._sizeThrottle = Utils.throttle(() => this.onResize(), this.opts.cellHeightThrottle);
1528
1540
  this.resizeObserver = new ResizeObserver(entries => this._sizeThrottle());
@@ -2071,8 +2083,11 @@ class GridStack {
2071
2083
  this._updateContainerHeight(); // @ts-ignore
2072
2084
  this._triggerChangeEvent();
2073
2085
  this.engine.endUpdate();
2074
- if (event.type === 'resizestop')
2075
- this.doContentResize(false, node);
2086
+ if (event.type === 'resizestop') {
2087
+ if (Number.isInteger(node.sizeToContent))
2088
+ node.sizeToContent = node.h; // new soft limit
2089
+ this.doContentResize(false, true, node); // no amin wait as will use the actual sized coordinate attr
2090
+ }
2076
2091
  };
2077
2092
  dd.draggable(el, {
2078
2093
  start: onStartMoving,
@@ -2248,6 +2263,6 @@ GridStack.resizeToContentParent = '.grid-stack-item-content';
2248
2263
  GridStack.Utils = Utils;
2249
2264
  /** scoping so users can call new GridStack.Engine(12) for example */
2250
2265
  GridStack.Engine = GridStackEngine;
2251
- GridStack.GDRev = '9.0.2';
2266
+ GridStack.GDRev = '9.1.1';
2252
2267
  export { GridStack };
2253
2268
  //# sourceMappingURL=gridstack.js.map