gridstack 9.1.0 → 9.2.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 (110) hide show
  1. package/angular/projects/lib/package.json +1 -1
  2. package/angular/projects/lib/src/lib/base-widget.ts +1 -1
  3. package/angular/projects/lib/src/lib/gridstack-item.component.ts +1 -1
  4. package/angular/projects/lib/src/lib/gridstack.component.ts +1 -1
  5. package/angular/projects/lib/src/lib/gridstack.module.ts +1 -1
  6. package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
  7. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
  8. package/dist/angular/esm2020/lib/gridstack.component.mjs +2 -2
  9. package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
  10. package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
  11. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  12. package/dist/angular/fesm2020/gridstack-angular.mjs +4 -4
  13. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  14. package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
  15. package/dist/angular/lib/gridstack.component.d.ts +1 -1
  16. package/dist/angular/package.json +1 -1
  17. package/dist/angular/src/base-widget.ts +1 -1
  18. package/dist/angular/src/gridstack-item.component.ts +1 -1
  19. package/dist/angular/src/gridstack.component.ts +1 -1
  20. package/dist/angular/src/gridstack.module.ts +1 -1
  21. package/dist/dd-base-impl.d.ts +1 -1
  22. package/dist/dd-base-impl.js +1 -1
  23. package/dist/dd-base-impl.js.map +1 -1
  24. package/dist/dd-draggable.d.ts +1 -1
  25. package/dist/dd-draggable.js +2 -2
  26. package/dist/dd-draggable.js.map +1 -1
  27. package/dist/dd-droppable.d.ts +1 -1
  28. package/dist/dd-droppable.js +1 -1
  29. package/dist/dd-droppable.js.map +1 -1
  30. package/dist/dd-element.d.ts +1 -1
  31. package/dist/dd-element.js +1 -1
  32. package/dist/dd-element.js.map +1 -1
  33. package/dist/dd-gridstack.d.ts +1 -1
  34. package/dist/dd-gridstack.js +1 -1
  35. package/dist/dd-gridstack.js.map +1 -1
  36. package/dist/dd-manager.d.ts +1 -1
  37. package/dist/dd-manager.js +1 -1
  38. package/dist/dd-manager.js.map +1 -1
  39. package/dist/dd-resizable-handle.d.ts +1 -1
  40. package/dist/dd-resizable-handle.js +1 -1
  41. package/dist/dd-resizable-handle.js.map +1 -1
  42. package/dist/dd-resizable.d.ts +1 -1
  43. package/dist/dd-resizable.js +2 -2
  44. package/dist/dd-resizable.js.map +1 -1
  45. package/dist/dd-touch.d.ts +1 -1
  46. package/dist/dd-touch.js +1 -1
  47. package/dist/dd-touch.js.map +1 -1
  48. package/dist/es5/dd-base-impl.d.ts +1 -1
  49. package/dist/es5/dd-base-impl.js +1 -1
  50. package/dist/es5/dd-base-impl.js.map +1 -1
  51. package/dist/es5/dd-draggable.d.ts +1 -1
  52. package/dist/es5/dd-draggable.js +2 -2
  53. package/dist/es5/dd-draggable.js.map +1 -1
  54. package/dist/es5/dd-droppable.d.ts +1 -1
  55. package/dist/es5/dd-droppable.js +1 -1
  56. package/dist/es5/dd-droppable.js.map +1 -1
  57. package/dist/es5/dd-element.d.ts +1 -1
  58. package/dist/es5/dd-element.js +1 -1
  59. package/dist/es5/dd-element.js.map +1 -1
  60. package/dist/es5/dd-gridstack.d.ts +1 -1
  61. package/dist/es5/dd-gridstack.js +1 -1
  62. package/dist/es5/dd-gridstack.js.map +1 -1
  63. package/dist/es5/dd-manager.d.ts +1 -1
  64. package/dist/es5/dd-manager.js +1 -1
  65. package/dist/es5/dd-manager.js.map +1 -1
  66. package/dist/es5/dd-resizable-handle.d.ts +1 -1
  67. package/dist/es5/dd-resizable-handle.js +1 -1
  68. package/dist/es5/dd-resizable-handle.js.map +1 -1
  69. package/dist/es5/dd-resizable.d.ts +1 -1
  70. package/dist/es5/dd-resizable.js +2 -2
  71. package/dist/es5/dd-resizable.js.map +1 -1
  72. package/dist/es5/dd-touch.d.ts +1 -1
  73. package/dist/es5/dd-touch.js +1 -1
  74. package/dist/es5/dd-touch.js.map +1 -1
  75. package/dist/es5/gridstack-all.js +1 -1
  76. package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
  77. package/dist/es5/gridstack-all.js.map +1 -1
  78. package/dist/es5/gridstack-engine.d.ts +1 -1
  79. package/dist/es5/gridstack-engine.js +6 -4
  80. package/dist/es5/gridstack-engine.js.map +1 -1
  81. package/dist/es5/gridstack-poly.js +1 -1
  82. package/dist/es5/gridstack.d.ts +12 -8
  83. package/dist/es5/gridstack.js +97 -80
  84. package/dist/es5/gridstack.js.map +1 -1
  85. package/dist/es5/types.d.ts +7 -7
  86. package/dist/es5/types.js +1 -1
  87. package/dist/es5/types.js.map +1 -1
  88. package/dist/es5/utils.d.ts +1 -1
  89. package/dist/es5/utils.js +2 -2
  90. package/dist/es5/utils.js.map +1 -1
  91. package/dist/gridstack-all.js +1 -1
  92. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  93. package/dist/gridstack-all.js.map +1 -1
  94. package/dist/gridstack-engine.d.ts +1 -1
  95. package/dist/gridstack-engine.js +6 -4
  96. package/dist/gridstack-engine.js.map +1 -1
  97. package/dist/gridstack.css +2 -2
  98. package/dist/gridstack.d.ts +12 -8
  99. package/dist/gridstack.js +94 -79
  100. package/dist/gridstack.js.map +1 -1
  101. package/dist/gridstack.min.css +1 -1
  102. package/dist/src/gridstack.scss +2 -2
  103. package/dist/types.d.ts +7 -7
  104. package/dist/types.js +1 -1
  105. package/dist/types.js.map +1 -1
  106. package/dist/utils.d.ts +1 -1
  107. package/dist/utils.js +2 -2
  108. package/dist/utils.js.map +1 -1
  109. package/doc/CHANGES.md +10 -0
  110. package/package.json +1 -1
package/dist/gridstack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GridStack 9.1.0
2
+ * GridStack 9.2.0
3
3
  * https://gridstackjs.com/
4
4
  *
5
5
  * Copyright (c) 2021-2022 Alain Dumesny
@@ -540,7 +540,7 @@ class GridStack {
540
540
  *
541
541
  * @example
542
542
  * see http://gridstackjs.com/demo/serialization.html
543
- **/
543
+ */
544
544
  load(layout, addRemove = GridStack.addRemoveCB || true) {
545
545
  // if passed list has coordinates, use them (insert from end to beginning for conflict resolution) else force widget same order
546
546
  const haveCoord = layout.some(w => w.x !== undefined || w.y !== undefined);
@@ -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
  }
@@ -696,7 +696,7 @@ class GridStack {
696
696
  * 'compact' might re-order items to fill any empty space
697
697
  *
698
698
  * doSort - 'false' to let you do your own sorting ahead in case you need to control a different order. (default to sort)
699
- **/
699
+ */
700
700
  compact(layout = 'compact', doSort = true) {
701
701
  this.engine.compact(layout, doSort);
702
702
  this._triggerChangeEvent();
@@ -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,71 +1114,76 @@ 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
- if (!el.clientHeight)
1122
- return; // 0 when hidden, skip
1123
- let n = el?.gridstackNode;
1124
- if (!n)
1125
- return;
1126
- const grid = n.grid;
1127
- if (grid !== this)
1128
- return grid?.resizeToContent(el);
1129
- if (el.parentElement !== this.el)
1130
- return; // skip if we are not inside a grid
1131
- const cell = this.getCellHeight();
1132
- if (!cell)
1133
- return;
1134
- let height = n.h ? n.h * cell : el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1135
- let item;
1136
- if (n.resizeToContentParent)
1137
- item = el.querySelector(n.resizeToContentParent);
1138
- if (!item)
1139
- item = el.querySelector(GridStack.resizeToContentParent);
1140
- if (!item)
1141
- return;
1142
- const child = item.firstElementChild;
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 padding = el.clientHeight - item.clientHeight; // full - available height to our child (minus border, padding...)
1146
+ 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)
1147
+ let wantedH;
1148
+ if (n.subGrid) {
1149
+ // sub-grid - use their actual row count * their cell height
1150
+ wantedH = n.subGrid.getRow() * n.subGrid.getCellHeight();
1151
+ }
1152
+ else {
1143
1153
  // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1154
+ const child = item.firstElementChild;
1144
1155
  if (!child) {
1145
1156
  console.log(`Error: resizeToContent() '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`);
1146
1157
  return;
1147
1158
  }
1148
- const padding = el.clientHeight - item.clientHeight; // full - available height to our child (minus border, padding...)
1149
- 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)
1150
- const wantedH = child.getBoundingClientRect().height || itemH;
1151
- if (itemH === wantedH)
1152
- return;
1153
- height += wantedH - itemH;
1154
- let h = Math.ceil(height / cell);
1155
- // check for min/max and special sizing
1156
- const softMax = Number.isInteger(n.sizeToContent) ? n.sizeToContent : 0;
1157
- if (softMax) {
1158
- if (h > softMax) {
1159
- h = softMax;
1160
- el.classList.remove('size-to-content'); // get v-scroll back
1161
- }
1162
- else
1163
- el.classList.add('size-to-content');
1164
- }
1165
- if (n.minH && h < n.minH)
1166
- h = n.minH;
1167
- else if (n.maxH && h > n.maxH)
1168
- h = n.maxH;
1169
- if (h !== n.h) {
1170
- this._ignoreLayoutsNodeChange = true;
1171
- this.moveNode(n, { h });
1172
- delete this._ignoreLayoutsNodeChange;
1173
- }
1174
- });
1159
+ wantedH = child.getBoundingClientRect().height || itemH;
1160
+ }
1161
+ if (itemH === wantedH)
1162
+ return;
1163
+ height += wantedH - itemH;
1164
+ let h = Math.ceil(height / cell);
1165
+ // check for min/max and special sizing
1166
+ const softMax = Number.isInteger(n.sizeToContent) ? n.sizeToContent : 0;
1167
+ if (softMax && h > softMax) {
1168
+ h = softMax;
1169
+ el.classList.add('size-to-content-max'); // get v-scroll back
1170
+ }
1171
+ if (n.minH && h < n.minH)
1172
+ h = n.minH;
1173
+ else if (n.maxH && h > n.maxH)
1174
+ h = n.maxH;
1175
+ if (h !== n.h) {
1176
+ grid._ignoreLayoutsNodeChange = true;
1177
+ grid.moveNode(n, { h });
1178
+ delete grid._ignoreLayoutsNodeChange;
1179
+ }
1175
1180
  }
1176
1181
  /** call the user resize (so we can do extra work) else our build in version */
1177
- resizeToContentCheck(el) {
1182
+ resizeToContentCheck(el, useAttr = false) {
1178
1183
  if (GridStack.resizeToContentCB)
1179
1184
  GridStack.resizeToContentCB(el);
1180
1185
  else
1181
- this.resizeToContent(el);
1186
+ this.resizeToContent(el, useAttr);
1182
1187
  }
1183
1188
  /**
1184
1189
  * 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).
@@ -1351,13 +1356,18 @@ class GridStack {
1351
1356
  this.el.setAttribute('gs-current-row', String(row));
1352
1357
  if (row === 0) {
1353
1358
  this.el.style.removeProperty('min-height');
1354
- return this;
1355
1359
  }
1356
- let cellHeight = this.opts.cellHeight;
1357
- let unit = this.opts.cellHeightUnit;
1358
- if (!cellHeight)
1359
- return this;
1360
- this.el.style.minHeight = row * cellHeight + unit;
1360
+ else {
1361
+ let cellHeight = this.opts.cellHeight;
1362
+ let unit = this.opts.cellHeightUnit;
1363
+ if (!cellHeight)
1364
+ return this;
1365
+ this.el.style.minHeight = row * cellHeight + unit;
1366
+ }
1367
+ // if we're a nested grid inside an sizeToContent item, tell it to resize itself too
1368
+ if (this.parentGridItem && !this.parentGridItem.grid.engine.batchMode && Utils.shouldSizeToContent(this.parentGridItem)) {
1369
+ this.parentGridItem.grid.resizeToContentCheck(this.parentGridItem.el);
1370
+ }
1361
1371
  return this;
1362
1372
  }
1363
1373
  /** @internal */
@@ -1507,27 +1517,30 @@ class GridStack {
1507
1517
  if (n.subGrid)
1508
1518
  n.subGrid.onResize();
1509
1519
  });
1510
- this.doContentResize(columnChanged);
1520
+ if (!this._skipInitialResize)
1521
+ this.doContentResize(columnChanged); // wait for anim of column changed (DOM reflow before we can size correctly)
1522
+ delete this._skipInitialResize;
1511
1523
  this.batchUpdate(false);
1512
1524
  return this;
1513
1525
  }
1514
- doContentResize(delay = true, n = undefined) {
1526
+ doContentResize(delay = true, useAttr = false, n = undefined) {
1515
1527
  // update any gridItem height with sizeToContent, but wait for DOM $animation_speed to settle if we changed column count
1516
1528
  // 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 ?
1517
1529
  setTimeout(() => {
1518
1530
  if (n) {
1519
1531
  if (Utils.shouldSizeToContent(n))
1520
- this.resizeToContentCheck(n.el);
1532
+ this.resizeToContentCheck(n.el, useAttr);
1521
1533
  }
1522
- else {
1534
+ else if (this.engine.nodes.some(n => Utils.shouldSizeToContent(n))) {
1523
1535
  const nodes = [...this.engine.nodes]; // in case order changes while resizing one
1524
1536
  this.batchUpdate();
1525
1537
  nodes.forEach(n => {
1526
1538
  if (Utils.shouldSizeToContent(n))
1527
- this.resizeToContentCheck(n.el);
1539
+ this.resizeToContentCheck(n.el, useAttr);
1528
1540
  });
1529
1541
  this.batchUpdate(false);
1530
1542
  }
1543
+ // call this regardless of shouldSizeToContent because widget might need to stretch to take available space after a resize
1531
1544
  if (this._gsEventHandler['resizecontent'])
1532
1545
  this._gsEventHandler['resizecontent'](null, n ? [n] : this.engine.nodes);
1533
1546
  }, delay ? 300 + 10 : 0);
@@ -1536,11 +1549,13 @@ class GridStack {
1536
1549
  _updateResizeEvent(forceRemove = false) {
1537
1550
  // 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)
1538
1551
  // or supporting new sizeToContent option.
1539
- const trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.sizeToContent || !this.opts.disableOneColumnMode || this.engine.nodes.find(n => n.sizeToContent));
1552
+ const trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.sizeToContent || !this.opts.disableOneColumnMode
1553
+ || this.engine.nodes.find(n => n.sizeToContent));
1540
1554
  if (!forceRemove && trackSize && !this.resizeObserver) {
1541
1555
  this._sizeThrottle = Utils.throttle(() => this.onResize(), this.opts.cellHeightThrottle);
1542
1556
  this.resizeObserver = new ResizeObserver(entries => this._sizeThrottle());
1543
1557
  this.resizeObserver.observe(this.el);
1558
+ this._skipInitialResize = true; // makeWidget will originally have called on startup
1544
1559
  }
1545
1560
  else if ((forceRemove || !trackSize) && this.resizeObserver) {
1546
1561
  this.resizeObserver.disconnect();
@@ -1636,7 +1651,7 @@ class GridStack {
1636
1651
  * @param dragIn string selector (ex: '.sidebar .grid-stack-item') or list of dom elements
1637
1652
  * @param dragInOptions options - see DDDragInOpt. (default: {handle: '.grid-stack-item-content', appendTo: 'body'}
1638
1653
  * @param root optional root which defaults to document (for shadow dom pas the parent HTMLDocument)
1639
- **/
1654
+ */
1640
1655
  static setupDragIn(dragIn, dragInOptions, root = document) {
1641
1656
  if (dragInOptions?.pause !== undefined) {
1642
1657
  DDManager.pauseDrag = dragInOptions.pause;
@@ -2013,7 +2028,7 @@ class GridStack {
2013
2028
  }
2014
2029
  return this;
2015
2030
  }
2016
- /** @internal prepares the element for drag&drop **/
2031
+ /** @internal prepares the element for drag&drop */
2017
2032
  _prepareDragDropByNode(node) {
2018
2033
  let el = node.el;
2019
2034
  const noMove = node.noMove || this.opts.disableDrag;
@@ -2088,7 +2103,7 @@ class GridStack {
2088
2103
  if (event.type === 'resizestop') {
2089
2104
  if (Number.isInteger(node.sizeToContent))
2090
2105
  node.sizeToContent = node.h; // new soft limit
2091
- this.doContentResize(false, node);
2106
+ this.doContentResize(false, true, node); // no amin wait as will use the actual sized coordinate attr
2092
2107
  }
2093
2108
  };
2094
2109
  dd.draggable(el, {
@@ -2107,7 +2122,7 @@ class GridStack {
2107
2122
  .resizable(el, noResize ? 'disable' : 'enable');
2108
2123
  return this;
2109
2124
  }
2110
- /** @internal handles actual drag/resize start **/
2125
+ /** @internal handles actual drag/resize start */
2111
2126
  _onStartMoving(el, event, ui, node, cellWidth, cellHeight) {
2112
2127
  this.engine.cleanNodes()
2113
2128
  .beginUpdate(node);
@@ -2138,7 +2153,7 @@ class GridStack {
2138
2153
  }
2139
2154
  }
2140
2155
  }
2141
- /** @internal handles actual drag/resize **/
2156
+ /** @internal handles actual drag/resize */
2142
2157
  _dragOrResize(el, event, ui, node, cellWidth, cellHeight) {
2143
2158
  let p = { ...node._orig }; // could be undefined (_isExternal) which is ok (drag only set x,y and w,h will default to node value)
2144
2159
  let resizing;
@@ -2226,7 +2241,7 @@ class GridStack {
2226
2241
  /** @internal called when item leaving our area by either cursor dropout event
2227
2242
  * or shape is outside our boundaries. remove it from us, and mark temporary if this was
2228
2243
  * our item to start with else restore prev node values from prev grid it came from.
2229
- **/
2244
+ */
2230
2245
  _leave(el, helper) {
2231
2246
  let node = el.gridstackNode;
2232
2247
  if (!node)
@@ -2265,6 +2280,6 @@ GridStack.resizeToContentParent = '.grid-stack-item-content';
2265
2280
  GridStack.Utils = Utils;
2266
2281
  /** scoping so users can call new GridStack.Engine(12) for example */
2267
2282
  GridStack.Engine = GridStackEngine;
2268
- GridStack.GDRev = '9.1.0';
2283
+ GridStack.GDRev = '9.2.0';
2269
2284
  export { GridStack };
2270
2285
  //# sourceMappingURL=gridstack.js.map