gridstack 8.3.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 (116) hide show
  1. package/README.md +9 -2
  2. package/angular/projects/demo/src/app/app.component.html +32 -0
  3. package/angular/projects/demo/src/app/app.component.ts +20 -5
  4. package/angular/projects/demo/src/styles.css +37 -0
  5. package/angular/projects/lib/package.json +1 -1
  6. package/angular/projects/lib/src/lib/base-widget.ts +1 -1
  7. package/angular/projects/lib/src/lib/gridstack-item.component.ts +1 -1
  8. package/angular/projects/lib/src/lib/gridstack.component.ts +1 -1
  9. package/angular/projects/lib/src/lib/gridstack.module.ts +1 -1
  10. package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
  11. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
  12. package/dist/angular/esm2020/lib/gridstack.component.mjs +2 -2
  13. package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
  14. package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
  15. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  16. package/dist/angular/fesm2020/gridstack-angular.mjs +4 -4
  17. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  18. package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
  19. package/dist/angular/lib/gridstack.component.d.ts +1 -1
  20. package/dist/angular/package.json +1 -1
  21. package/dist/angular/src/base-widget.ts +1 -1
  22. package/dist/angular/src/gridstack-item.component.ts +1 -1
  23. package/dist/angular/src/gridstack.component.ts +1 -1
  24. package/dist/angular/src/gridstack.module.ts +1 -1
  25. package/dist/dd-base-impl.d.ts +1 -1
  26. package/dist/dd-base-impl.js +1 -1
  27. package/dist/dd-base-impl.js.map +1 -1
  28. package/dist/dd-draggable.d.ts +1 -1
  29. package/dist/dd-draggable.js +1 -1
  30. package/dist/dd-draggable.js.map +1 -1
  31. package/dist/dd-droppable.d.ts +1 -1
  32. package/dist/dd-droppable.js +2 -2
  33. package/dist/dd-droppable.js.map +1 -1
  34. package/dist/dd-element.d.ts +1 -1
  35. package/dist/dd-element.js +1 -1
  36. package/dist/dd-element.js.map +1 -1
  37. package/dist/dd-gridstack.d.ts +1 -1
  38. package/dist/dd-gridstack.js +1 -1
  39. package/dist/dd-gridstack.js.map +1 -1
  40. package/dist/dd-manager.d.ts +1 -1
  41. package/dist/dd-manager.js +1 -1
  42. package/dist/dd-manager.js.map +1 -1
  43. package/dist/dd-resizable-handle.d.ts +1 -1
  44. package/dist/dd-resizable-handle.js +1 -1
  45. package/dist/dd-resizable-handle.js.map +1 -1
  46. package/dist/dd-resizable.d.ts +1 -1
  47. package/dist/dd-resizable.js +1 -1
  48. package/dist/dd-resizable.js.map +1 -1
  49. package/dist/dd-touch.d.ts +1 -1
  50. package/dist/dd-touch.js +1 -1
  51. package/dist/dd-touch.js.map +1 -1
  52. package/dist/es5/dd-base-impl.d.ts +1 -1
  53. package/dist/es5/dd-base-impl.js +1 -1
  54. package/dist/es5/dd-base-impl.js.map +1 -1
  55. package/dist/es5/dd-draggable.d.ts +1 -1
  56. package/dist/es5/dd-draggable.js +1 -1
  57. package/dist/es5/dd-draggable.js.map +1 -1
  58. package/dist/es5/dd-droppable.d.ts +1 -1
  59. package/dist/es5/dd-droppable.js +2 -2
  60. package/dist/es5/dd-droppable.js.map +1 -1
  61. package/dist/es5/dd-element.d.ts +1 -1
  62. package/dist/es5/dd-element.js +1 -1
  63. package/dist/es5/dd-element.js.map +1 -1
  64. package/dist/es5/dd-gridstack.d.ts +1 -1
  65. package/dist/es5/dd-gridstack.js +1 -1
  66. package/dist/es5/dd-gridstack.js.map +1 -1
  67. package/dist/es5/dd-manager.d.ts +1 -1
  68. package/dist/es5/dd-manager.js +1 -1
  69. package/dist/es5/dd-manager.js.map +1 -1
  70. package/dist/es5/dd-resizable-handle.d.ts +1 -1
  71. package/dist/es5/dd-resizable-handle.js +1 -1
  72. package/dist/es5/dd-resizable-handle.js.map +1 -1
  73. package/dist/es5/dd-resizable.d.ts +1 -1
  74. package/dist/es5/dd-resizable.js +1 -1
  75. package/dist/es5/dd-resizable.js.map +1 -1
  76. package/dist/es5/dd-touch.d.ts +1 -1
  77. package/dist/es5/dd-touch.js +1 -1
  78. package/dist/es5/dd-touch.js.map +1 -1
  79. package/dist/es5/gridstack-all.js +1 -1
  80. package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
  81. package/dist/es5/gridstack-all.js.map +1 -1
  82. package/dist/es5/gridstack-engine.d.ts +1 -1
  83. package/dist/es5/gridstack-engine.js +23 -15
  84. package/dist/es5/gridstack-engine.js.map +1 -1
  85. package/dist/es5/gridstack-poly.js +1 -1
  86. package/dist/es5/gridstack.d.ts +21 -8
  87. package/dist/es5/gridstack.js +167 -80
  88. package/dist/es5/gridstack.js.map +1 -1
  89. package/dist/es5/types.d.ts +10 -2
  90. package/dist/es5/types.js +3 -2
  91. package/dist/es5/types.js.map +1 -1
  92. package/dist/es5/utils.d.ts +3 -1
  93. package/dist/es5/utils.js +7 -3
  94. package/dist/es5/utils.js.map +1 -1
  95. package/dist/gridstack-all.js +1 -1
  96. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  97. package/dist/gridstack-all.js.map +1 -1
  98. package/dist/gridstack-engine.d.ts +1 -1
  99. package/dist/gridstack-engine.js +21 -15
  100. package/dist/gridstack-engine.js.map +1 -1
  101. package/dist/gridstack.css +4 -1
  102. package/dist/gridstack.d.ts +21 -8
  103. package/dist/gridstack.js +157 -77
  104. package/dist/gridstack.js.map +1 -1
  105. package/dist/gridstack.min.css +1 -1
  106. package/dist/src/gridstack.scss +4 -1
  107. package/dist/types.d.ts +10 -2
  108. package/dist/types.js +3 -2
  109. package/dist/types.js.map +1 -1
  110. package/dist/utils.d.ts +3 -1
  111. package/dist/utils.js +7 -3
  112. package/dist/utils.js.map +1 -1
  113. package/doc/CHANGES.md +12 -0
  114. package/doc/README.md +3 -1
  115. package/package.json +1 -1
  116. package/angular/projects/demo/src/environments/environment.prod.ts +0 -3
package/dist/gridstack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GridStack 8.3.0
2
+ * GridStack 9.0.0
3
3
  * https://gridstackjs.com/
4
4
  *
5
5
  * Copyright (c) 2021-2022 Alain Dumesny
@@ -185,7 +185,8 @@ class GridStack {
185
185
  handle: (opts.handleClass ? '.' + opts.handleClass : (opts.handle ? opts.handle : '')) || gridDefaults.draggable.handle,
186
186
  },
187
187
  removableOptions: {
188
- accept: opts.itemClass ? '.' + opts.itemClass : gridDefaults.removableOptions.accept,
188
+ accept: opts.itemClass || gridDefaults.removableOptions.accept,
189
+ decline: gridDefaults.removableOptions.decline
189
190
  },
190
191
  };
191
192
  if (el.getAttribute('gs-animate')) { // default to true, but if set to false use that instead
@@ -279,7 +280,7 @@ class GridStack {
279
280
  DDManager.pauseDrag = this.opts.draggable.pause;
280
281
  this._setupRemoveDrop();
281
282
  this._setupAcceptWidget();
282
- this._updateWindowResizeEvent();
283
+ this._updateResizeEvent();
283
284
  }
284
285
  /**
285
286
  * add a new widget and returns it.
@@ -541,11 +542,13 @@ class GridStack {
541
542
  * see http://gridstackjs.com/demo/serialization.html
542
543
  **/
543
544
  load(layout, addRemove = GridStack.addRemoveCB || true) {
544
- let items = GridStack.Utils.sort([...layout], -1, this._prevColumn || this.getColumn()); // make copy before we mod/sort
545
- this._insertNotAppend = true; // since create in reverse order...
545
+ // if passed list has coordinates, use them (insert from end to beginning for conflict resolution) else force widget same order
546
+ const haveCoord = layout.some(w => w.x !== undefined || w.y !== undefined);
547
+ let items = haveCoord ? Utils.sort(layout, -1, this._prevColumn || this.getColumn()) : layout;
548
+ this._insertNotAppend = haveCoord; // if we create in reverse order...
546
549
  // if we're loading a layout into for example 1 column (_prevColumn is set only when going to 1) and items don't fit, make sure to save
547
550
  // the original wanted layout so we can scale back up correctly #1471
548
- if (this._prevColumn && this._prevColumn !== this.opts.column && items.some(n => (n.x + n.w) > this.opts.column)) {
551
+ if (this._prevColumn && this._prevColumn !== this.opts.column && items.some(n => ((n.x || 0) + n.w) > this.opts.column)) {
549
552
  this._ignoreLayoutsNodeChange = true; // skip layout update
550
553
  this.engine.cacheLayout(items, this._prevColumn, true);
551
554
  }
@@ -568,10 +571,19 @@ class GridStack {
568
571
  }
569
572
  });
570
573
  }
571
- // now add/update the widgets
574
+ // now add/update the widgets - starting with an empty list to reduce collision and add no-coord ones at next available spot
575
+ let copyNodes = this.engine.nodes;
576
+ this.engine.nodes = [];
572
577
  items.forEach(w => {
573
- let item = (w.id !== undefined) ? this.engine.nodes.find(n => n.id === w.id) : undefined;
578
+ let item = (w.id !== undefined) ? copyNodes.find(n => n.id === w.id) : undefined;
574
579
  if (item) {
580
+ // check if missing coord, in which case find next empty slot with new (or old if missing) sizes
581
+ if (w.autoPosition || w.x === undefined || w.y === undefined) {
582
+ w.w = w.w || item.w;
583
+ w.h = w.h || item.h;
584
+ this.engine.findEmptyPosition(w);
585
+ }
586
+ this.engine.nodes.push(item); // now back to current list...
575
587
  this.update(item.el, w);
576
588
  if (w.subGridOpts?.children) { // update any sub grid as well
577
589
  let sub = item.el.querySelector('.grid-stack');
@@ -600,6 +612,7 @@ class GridStack {
600
612
  batchUpdate(flag = true) {
601
613
  this.engine.batchUpdate(flag);
602
614
  if (!flag) {
615
+ this._updateContainerHeight();
603
616
  this._triggerRemoveEvent();
604
617
  this._triggerAddEvent();
605
618
  this._triggerChangeEvent();
@@ -643,7 +656,7 @@ class GridStack {
643
656
  if (update && val !== undefined) {
644
657
  if (this._isAutoCellHeight !== (val === 'auto')) {
645
658
  this._isAutoCellHeight = (val === 'auto');
646
- this._updateWindowResizeEvent();
659
+ this._updateResizeEvent();
647
660
  }
648
661
  }
649
662
  if (val === 'initial' || val === 'auto') {
@@ -698,7 +711,7 @@ class GridStack {
698
711
  * Note: items will never be outside of the current column boundaries. default ('moveScale'). Ignored for 1 column
699
712
  */
700
713
  column(column, layout = 'moveScale') {
701
- if (column < 1 || this.opts.column === column)
714
+ if (!column || column < 1 || this.opts.column === column)
702
715
  return this;
703
716
  let oldColumn = this.getColumn();
704
717
  // if we go into 1 column mode (which happens if we're sized less than minW unless disableOneColumnMode is on)
@@ -728,6 +741,7 @@ class GridStack {
728
741
  this.engine.columnChanged(oldColumn, column, domNodes, layout);
729
742
  if (this._isAutoCellHeight)
730
743
  this.cellHeight();
744
+ this.doContentResize();
731
745
  // and trigger our event last...
732
746
  this._ignoreLayoutsNodeChange = true; // skip layout update
733
747
  this._triggerChangeEvent();
@@ -753,7 +767,7 @@ class GridStack {
753
767
  if (!this.el)
754
768
  return; // prevent multiple calls
755
769
  this.offAll();
756
- this._updateWindowResizeEvent(true);
770
+ this._updateResizeEvent(true);
757
771
  this.setStatic(true, false); // permanently removes DD but don't set CSS class (we're going away)
758
772
  this.setAnimation(false);
759
773
  if (!removeDOM) {
@@ -899,7 +913,8 @@ class GridStack {
899
913
  }
900
914
  this.el.addEventListener(name, this._gsEventHandler[name]);
901
915
  }
902
- 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') {
903
918
  // drag&drop stop events NEED to be call them AFTER we update node attributes so handle them ourself.
904
919
  // do same for start event to make it easier...
905
920
  this._gsEventHandler[name] = callback;
@@ -1033,9 +1048,9 @@ class GridStack {
1033
1048
  return this.update(els, opt);
1034
1049
  }
1035
1050
  GridStack.getElements(els).forEach(el => {
1036
- if (!el || !el.gridstackNode)
1051
+ let n = el?.gridstackNode;
1052
+ if (!n)
1037
1053
  return;
1038
- let n = el.gridstackNode;
1039
1054
  let w = Utils.cloneDeep(opt); // make a copy we can modify in case they re-use it or multiple items
1040
1055
  delete w.autoPosition;
1041
1056
  // move/resize widget if anything changed
@@ -1053,10 +1068,16 @@ class GridStack {
1053
1068
  m = {}; // will use node position but validate values
1054
1069
  }
1055
1070
  // check for content changing
1056
- if (w.content) {
1057
- let sub = el.querySelector('.grid-stack-item-content');
1058
- if (sub && sub.innerHTML !== w.content) {
1059
- sub.innerHTML = w.content;
1071
+ if (w.content !== undefined) {
1072
+ const itemContent = el.querySelector('.grid-stack-item-content');
1073
+ if (!itemContent || itemContent.innerHTML === w.content)
1074
+ return;
1075
+ itemContent.innerHTML = w.content;
1076
+ // restore any sub-grid back
1077
+ if (n.subGrid?.el) {
1078
+ itemContent.appendChild(n.subGrid.el);
1079
+ if (!n.subGrid.opts.styleInHead)
1080
+ n.subGrid._updateStyles(true); // force create
1060
1081
  }
1061
1082
  delete w.content;
1062
1083
  }
@@ -1072,14 +1093,8 @@ class GridStack {
1072
1093
  }
1073
1094
  Utils.sanitizeMinMax(n);
1074
1095
  // finally move the widget
1075
- if (m) {
1076
- this.engine.cleanNodes()
1077
- .beginUpdate(n)
1078
- .moveNode(n, m);
1079
- this._updateContainerHeight();
1080
- this._triggerChangeEvent();
1081
- this.engine.endUpdate();
1082
- }
1096
+ if (m)
1097
+ this.moveNode(n, m);
1083
1098
  if (changed) { // move will only update x,y,w,h so update the rest too
1084
1099
  this._writeAttr(el, n);
1085
1100
  }
@@ -1089,6 +1104,54 @@ class GridStack {
1089
1104
  });
1090
1105
  return this;
1091
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
+ }
1092
1155
  /**
1093
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).
1094
1157
  * @param value margin value
@@ -1282,6 +1345,8 @@ class GridStack {
1282
1345
  if (!Utils.same(node, copy)) {
1283
1346
  this._writeAttr(el, node);
1284
1347
  }
1348
+ if (Utils.shouldFitToContent(node))
1349
+ el.classList.add('fit-to-content');
1285
1350
  this._prepareDragDropByNode(node);
1286
1351
  return this;
1287
1352
  }
@@ -1375,65 +1440,81 @@ class GridStack {
1375
1440
  return this;
1376
1441
  }
1377
1442
  /**
1378
- * called when we are being resized by the window - check if the one Column Mode needs to be turned on/off
1379
- * 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.
1380
1446
  */
1381
- onParentResize() {
1382
- if (!this.el || !this.el.clientWidth)
1447
+ onResize() {
1448
+ if (!this.el?.clientWidth)
1383
1449
  return; // return if we're gone or no size yet (will get called again)
1384
- 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();
1385
1455
  // see if we're nested and take our column count from our parent....
1456
+ let columnChanged = false;
1386
1457
  if (this._autoColumn && this.parentGridItem) {
1387
1458
  if (this.opts.column !== this.parentGridItem.w) {
1388
- changedColumn = true;
1389
1459
  this.column(this.parentGridItem.w, 'none');
1460
+ columnChanged = true;
1390
1461
  }
1391
1462
  }
1392
1463
  else {
1393
1464
  // else check for 1 column in/out behavior
1394
- 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);
1395
1467
  if ((this.opts.column === 1) !== oneColumn) {
1396
- changedColumn = true;
1397
- if (this.opts.animate) {
1398
- this.setAnimation(false);
1399
- } // 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
1400
1469
  this.column(oneColumn ? 1 : this._prevColumn);
1401
- if (this.opts.animate) {
1402
- this.setAnimation(true);
1403
- }
1470
+ // if (this.opts.animate) setTimeout(() => this.setAnimation(true));
1471
+ columnChanged = true;
1404
1472
  }
1405
1473
  }
1406
1474
  // make the cells content square again
1407
- if (this._isAutoCellHeight) {
1408
- if (!changedColumn && this.opts.cellHeightThrottle) {
1409
- if (!this._cellHeightThrottle) {
1410
- this._cellHeightThrottle = Utils.throttle(() => this.cellHeight(), this.opts.cellHeightThrottle);
1411
- }
1412
- this._cellHeightThrottle();
1413
- }
1414
- else {
1415
- // immediate update if we've changed column count or have no threshold
1416
- this.cellHeight();
1417
- }
1418
- }
1419
- // finally update any nested grids
1475
+ if (this._isAutoCellHeight)
1476
+ this.cellHeight();
1477
+ // update any nested grids, or items size
1420
1478
  this.engine.nodes.forEach(n => {
1421
1479
  if (n.subGrid)
1422
- n.subGrid.onParentResize();
1480
+ n.subGrid.onResize();
1423
1481
  });
1482
+ this.doContentResize(columnChanged);
1483
+ this.batchUpdate(false);
1424
1484
  return this;
1425
1485
  }
1426
- /** add or remove the window size event handler */
1427
- _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) {
1428
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)
1429
- const workTodo = (this._isAutoCellHeight || !this.opts.disableOneColumnMode) && !this.parentGridItem;
1430
- if (!forceRemove && workTodo && !this._windowResizeBind) {
1431
- this._windowResizeBind = this.onParentResize.bind(this); // so we can properly remove later
1432
- window.addEventListener('resize', this._windowResizeBind);
1433
- }
1434
- else if ((forceRemove || !workTodo) && this._windowResizeBind) {
1435
- window.removeEventListener('resize', this._windowResizeBind);
1436
- 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;
1437
1518
  }
1438
1519
  return this;
1439
1520
  }
@@ -1879,7 +1960,7 @@ class GridStack {
1879
1960
  /** @internal mark item for removal */
1880
1961
  _itemRemoving(el, remove) {
1881
1962
  let node = el ? el.gridstackNode : undefined;
1882
- if (!node || !node.grid)
1963
+ if (!node || !node.grid || el.classList.contains(this.opts.removableOptions.decline))
1883
1964
  return;
1884
1965
  remove ? node._isAboutToRemove = true : delete node._isAboutToRemove;
1885
1966
  remove ? el.classList.add('grid-stack-item-removing') : el.classList.remove('grid-stack-item-removing');
@@ -1945,17 +2026,12 @@ class GridStack {
1945
2026
  return;
1946
2027
  node.el = target;
1947
2028
  if (node._isAboutToRemove) {
1948
- let gridToNotify = el.gridstackNode.grid;
1949
- if (gridToNotify._gsEventHandler[event.type]) {
1950
- gridToNotify._gsEventHandler[event.type](event, target);
2029
+ let grid = el.gridstackNode.grid;
2030
+ if (grid._gsEventHandler[event.type]) {
2031
+ grid._gsEventHandler[event.type](event, target);
1951
2032
  }
1952
- this._removeDD(el);
1953
- gridToNotify.engine.removedNodes.push(node);
1954
- gridToNotify._triggerRemoveEvent();
1955
- // break circular links and remove DOM
1956
- delete el.gridstackNode;
1957
- delete node.el;
1958
- el.remove();
2033
+ grid.engine.nodes.push(node); // temp add it back so we can proper remove it next
2034
+ grid.removeWidget(el, true, true);
1959
2035
  }
1960
2036
  else {
1961
2037
  Utils.removePositioningStyles(target);
@@ -1978,6 +2054,8 @@ class GridStack {
1978
2054
  this._updateContainerHeight(); // @ts-ignore
1979
2055
  this._triggerChangeEvent();
1980
2056
  this.engine.endUpdate();
2057
+ if (event.type === 'resizestop')
2058
+ this.doContentResize(false, node);
1981
2059
  };
1982
2060
  dd.draggable(el, {
1983
2061
  start: onStartMoving,
@@ -2101,7 +2179,7 @@ class GridStack {
2101
2179
  this.engine.cacheRects(cellWidth, cellHeight, mTop, mRight, mBottom, mLeft);
2102
2180
  delete node._skipDown;
2103
2181
  if (resizing && node.subGrid)
2104
- node.subGrid.onParentResize();
2182
+ node.subGrid.onResize();
2105
2183
  this._extraDragRow = 0; // @ts-ignore
2106
2184
  this._updateContainerHeight();
2107
2185
  let target = event.target; // @ts-ignore
@@ -2147,10 +2225,12 @@ class GridStack {
2147
2225
  // legacy method removed
2148
2226
  commit() { obsolete(this, this.batchUpdate(false), 'commit', 'batchUpdate', '5.2'); return this; }
2149
2227
  }
2228
+ /** parent class for sizing content. defaults to '.grid-stack-item-content' */
2229
+ GridStack.resizeToContentParent = '.grid-stack-item-content';
2150
2230
  /** scoping so users can call GridStack.Utils.sort() for example */
2151
2231
  GridStack.Utils = Utils;
2152
2232
  /** scoping so users can call new GridStack.Engine(12) for example */
2153
2233
  GridStack.Engine = GridStackEngine;
2154
- GridStack.GDRev = '8.3.0';
2234
+ GridStack.GDRev = '9.0.0';
2155
2235
  export { GridStack };
2156
2236
  //# sourceMappingURL=gridstack.js.map