gridstack 9.5.1 → 10.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 (114) hide show
  1. package/README.md +11 -1
  2. package/angular/package.json +1 -1
  3. package/angular/projects/demo/src/app/app.component.ts +0 -2
  4. package/angular/projects/lib/package.json +1 -1
  5. package/angular/projects/lib/src/lib/base-widget.ts +1 -1
  6. package/angular/projects/lib/src/lib/gridstack-item.component.ts +1 -1
  7. package/angular/projects/lib/src/lib/gridstack.component.ts +1 -1
  8. package/angular/projects/lib/src/lib/gridstack.module.ts +1 -1
  9. package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
  10. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
  11. package/dist/angular/esm2020/lib/gridstack.component.mjs +2 -2
  12. package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
  13. package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
  14. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  15. package/dist/angular/fesm2020/gridstack-angular.mjs +4 -4
  16. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  17. package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
  18. package/dist/angular/lib/gridstack.component.d.ts +1 -1
  19. package/dist/angular/package.json +1 -1
  20. package/dist/angular/src/base-widget.ts +1 -1
  21. package/dist/angular/src/gridstack-item.component.ts +1 -1
  22. package/dist/angular/src/gridstack.component.ts +1 -1
  23. package/dist/angular/src/gridstack.module.ts +1 -1
  24. package/dist/dd-base-impl.d.ts +1 -1
  25. package/dist/dd-base-impl.js +1 -1
  26. package/dist/dd-base-impl.js.map +1 -1
  27. package/dist/dd-draggable.d.ts +1 -1
  28. package/dist/dd-draggable.js +1 -1
  29. package/dist/dd-draggable.js.map +1 -1
  30. package/dist/dd-droppable.d.ts +1 -1
  31. package/dist/dd-droppable.js +1 -1
  32. package/dist/dd-droppable.js.map +1 -1
  33. package/dist/dd-element.d.ts +1 -1
  34. package/dist/dd-element.js +1 -1
  35. package/dist/dd-element.js.map +1 -1
  36. package/dist/dd-gridstack.d.ts +1 -1
  37. package/dist/dd-gridstack.js +1 -1
  38. package/dist/dd-gridstack.js.map +1 -1
  39. package/dist/dd-manager.d.ts +1 -1
  40. package/dist/dd-manager.js +1 -1
  41. package/dist/dd-manager.js.map +1 -1
  42. package/dist/dd-resizable-handle.d.ts +1 -1
  43. package/dist/dd-resizable-handle.js +1 -1
  44. package/dist/dd-resizable-handle.js.map +1 -1
  45. package/dist/dd-resizable.d.ts +1 -1
  46. package/dist/dd-resizable.js +1 -1
  47. package/dist/dd-resizable.js.map +1 -1
  48. package/dist/dd-touch.d.ts +1 -1
  49. package/dist/dd-touch.js +1 -1
  50. package/dist/dd-touch.js.map +1 -1
  51. package/dist/es5/dd-base-impl.d.ts +1 -1
  52. package/dist/es5/dd-base-impl.js +1 -1
  53. package/dist/es5/dd-base-impl.js.map +1 -1
  54. package/dist/es5/dd-draggable.d.ts +1 -1
  55. package/dist/es5/dd-draggable.js +1 -1
  56. package/dist/es5/dd-draggable.js.map +1 -1
  57. package/dist/es5/dd-droppable.d.ts +1 -1
  58. package/dist/es5/dd-droppable.js +1 -1
  59. package/dist/es5/dd-droppable.js.map +1 -1
  60. package/dist/es5/dd-element.d.ts +1 -1
  61. package/dist/es5/dd-element.js +1 -1
  62. package/dist/es5/dd-element.js.map +1 -1
  63. package/dist/es5/dd-gridstack.d.ts +1 -1
  64. package/dist/es5/dd-gridstack.js +1 -1
  65. package/dist/es5/dd-gridstack.js.map +1 -1
  66. package/dist/es5/dd-manager.d.ts +1 -1
  67. package/dist/es5/dd-manager.js +1 -1
  68. package/dist/es5/dd-manager.js.map +1 -1
  69. package/dist/es5/dd-resizable-handle.d.ts +1 -1
  70. package/dist/es5/dd-resizable-handle.js +1 -1
  71. package/dist/es5/dd-resizable-handle.js.map +1 -1
  72. package/dist/es5/dd-resizable.d.ts +1 -1
  73. package/dist/es5/dd-resizable.js +1 -1
  74. package/dist/es5/dd-resizable.js.map +1 -1
  75. package/dist/es5/dd-touch.d.ts +1 -1
  76. package/dist/es5/dd-touch.js +1 -1
  77. package/dist/es5/dd-touch.js.map +1 -1
  78. package/dist/es5/gridstack-all.js +1 -1
  79. package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
  80. package/dist/es5/gridstack-all.js.map +1 -1
  81. package/dist/es5/gridstack-engine.d.ts +1 -1
  82. package/dist/es5/gridstack-engine.js +1 -1
  83. package/dist/es5/gridstack-engine.js.map +1 -1
  84. package/dist/es5/gridstack-poly.js +1 -1
  85. package/dist/es5/gridstack.d.ts +11 -7
  86. package/dist/es5/gridstack.js +183 -127
  87. package/dist/es5/gridstack.js.map +1 -1
  88. package/dist/es5/types.d.ts +27 -13
  89. package/dist/es5/types.js +1 -4
  90. package/dist/es5/types.js.map +1 -1
  91. package/dist/es5/utils.d.ts +2 -2
  92. package/dist/es5/utils.js +4 -3
  93. package/dist/es5/utils.js.map +1 -1
  94. package/dist/gridstack-all.js +1 -1
  95. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  96. package/dist/gridstack-all.js.map +1 -1
  97. package/dist/gridstack-engine.d.ts +1 -1
  98. package/dist/gridstack-engine.js +1 -1
  99. package/dist/gridstack-engine.js.map +1 -1
  100. package/dist/gridstack.css +2 -2
  101. package/dist/gridstack.d.ts +11 -7
  102. package/dist/gridstack.js +180 -124
  103. package/dist/gridstack.js.map +1 -1
  104. package/dist/gridstack.min.css +1 -1
  105. package/dist/src/gridstack.scss +2 -2
  106. package/dist/types.d.ts +27 -13
  107. package/dist/types.js +1 -4
  108. package/dist/types.js.map +1 -1
  109. package/dist/utils.d.ts +2 -2
  110. package/dist/utils.js +4 -3
  111. package/dist/utils.js.map +1 -1
  112. package/doc/CHANGES.md +15 -1
  113. package/doc/README.md +23 -10
  114. package/package.json +2 -2
@@ -36,7 +36,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.GridStack = void 0;
38
38
  /*!
39
- * GridStack 9.5.1
39
+ * GridStack 10.0.1
40
40
  * https://gridstackjs.com/
41
41
  *
42
42
  * Copyright (c) 2021-2022 Alain Dumesny
@@ -54,7 +54,6 @@ var types_1 = require("./types");
54
54
  var dd_gridstack_1 = require("./dd-gridstack");
55
55
  var dd_touch_1 = require("./dd-touch");
56
56
  var dd_manager_1 = require("./dd-manager");
57
- /** global instance */
58
57
  var dd = new dd_gridstack_1.DDGridStack;
59
58
  // export all dependent file as well to make it easier for users to just import the main file
60
59
  __exportStar(require("./types"), exports);
@@ -80,11 +79,12 @@ var GridStack = exports.GridStack = /** @class */ (function () {
80
79
  function GridStack(el, opts) {
81
80
  if (opts === void 0) { opts = {}; }
82
81
  var _this = this;
83
- var _a, _b;
82
+ var _a, _b, _c, _d;
84
83
  /** @internal */
85
84
  this._gsEventHandler = {};
86
85
  /** @internal extra row added when dragging at the bottom of the grid */
87
86
  this._extraDragRow = 0;
87
+ el.gridstack = this;
88
88
  this.el = el; // exposed HTML element to the user
89
89
  opts = opts || {}; // handles null/undefined/0
90
90
  if (!el.classList.contains('grid-stack')) {
@@ -104,6 +104,41 @@ var GridStack = exports.GridStack = /** @class */ (function () {
104
104
  if (opts.alwaysShowResizeHandle !== undefined) {
105
105
  opts._alwaysShowResizeHandle = opts.alwaysShowResizeHandle;
106
106
  }
107
+ var bk = (_a = opts.columnOpts) === null || _a === void 0 ? void 0 : _a.breakpoints;
108
+ // LEGACY: oneColumnMode stuff changed in v10.x - check if user explicitly set something to convert over
109
+ var oldOpts = opts;
110
+ if (oldOpts.oneColumnModeDomSort) {
111
+ delete oldOpts.oneColumnModeDomSort;
112
+ console.log('Error: Gridstack oneColumnModeDomSort no longer supported. Check GridStackOptions.columnOpts instead.');
113
+ }
114
+ if (oldOpts.oneColumnSize || oldOpts.disableOneColumnMode === false) {
115
+ var oneSize = oldOpts.oneColumnSize || 768;
116
+ delete oldOpts.oneColumnSize;
117
+ delete oldOpts.disableOneColumnMode;
118
+ opts.columnOpts = opts.columnOpts || {};
119
+ bk = opts.columnOpts.breakpoints = opts.columnOpts.breakpoints || [];
120
+ var oneColumn = bk.find(function (b) { return b.c === 1; });
121
+ if (!oneColumn) {
122
+ oneColumn = { c: 1, w: oneSize };
123
+ bk.push(oneColumn, { c: 12, w: oneSize + 1 });
124
+ }
125
+ else
126
+ oneColumn.w = oneSize;
127
+ }
128
+ //...end LEGACY
129
+ // cleanup responsive opts (must have columnWidth | breakpoints) then sort breakpoints by size (so we can match during resize)
130
+ var resp = opts.columnOpts;
131
+ if (resp) {
132
+ if (!resp.columnWidth && !((_b = resp.breakpoints) === null || _b === void 0 ? void 0 : _b.length)) {
133
+ delete opts.columnOpts;
134
+ bk = undefined;
135
+ }
136
+ else {
137
+ resp.columnMax = resp.columnMax || 12;
138
+ }
139
+ }
140
+ if ((bk === null || bk === void 0 ? void 0 : bk.length) > 1)
141
+ bk.sort(function (a, b) { return (b.w || 0) - (a.w || 0); });
107
142
  // elements DOM attributes override any passed options (like CSS style) - merge the two together
108
143
  var defaults = __assign(__assign({}, utils_1.Utils.cloneDeep(types_1.gridDefaults)), { column: utils_1.Utils.toNumber(el.getAttribute('gs-column')) || types_1.gridDefaults.column, minRow: rowAttr ? rowAttr : utils_1.Utils.toNumber(el.getAttribute('gs-min-row')) || types_1.gridDefaults.minRow, maxRow: rowAttr ? rowAttr : utils_1.Utils.toNumber(el.getAttribute('gs-max-row')) || types_1.gridDefaults.maxRow, staticGrid: utils_1.Utils.toBool(el.getAttribute('gs-static')) || types_1.gridDefaults.staticGrid, draggable: {
109
144
  handle: (opts.handleClass ? '.' + opts.handleClass : (opts.handle ? opts.handle : '')) || types_1.gridDefaults.draggable.handle,
@@ -118,10 +153,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
118
153
  opts = null; // make sure we use this.opts instead
119
154
  this._initMargin(); // part of settings defaults...
120
155
  // Now check if we're loading into 1 column mode FIRST so we don't do un-necessary work (like cellHeight = width / 12 then go 1 column)
121
- if (this.opts.column !== 1 && !this.opts.disableOneColumnMode && this._widthOrContainer() <= this.opts.oneColumnSize) {
122
- this._prevColumn = this.getColumn();
123
- this.opts.column = 1;
124
- }
156
+ this.checkDynamicColumn();
157
+ this.el.classList.add('gs-' + this.opts.column);
125
158
  if (this.opts.rtl === 'auto') {
126
159
  this.opts.rtl = (el.style.direction === 'rtl');
127
160
  }
@@ -129,7 +162,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
129
162
  this.el.classList.add('grid-stack-rtl');
130
163
  }
131
164
  // check if we're been nested, and if so update our style and keep pointer around (used during save)
132
- var grandParent = (_a = this.el.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement;
165
+ var grandParent = (_c = this.el.parentElement) === null || _c === void 0 ? void 0 : _c.parentElement;
133
166
  var parentGridItem = (grandParent === null || grandParent === void 0 ? void 0 : grandParent.classList.contains(types_1.gridDefaults.itemClass)) ? grandParent.gridstackNode : undefined;
134
167
  if (parentGridItem) {
135
168
  parentGridItem.subGrid = this;
@@ -181,6 +214,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
181
214
  _this._updateStyles(false, maxH); // false = don't recreate, just append if need be
182
215
  }
183
216
  });
217
+ // create initial global styles BEFORE loading children so resizeToContent margin can be calculated correctly
218
+ this._updateStyles(false, 0);
184
219
  if (this.opts.auto) {
185
220
  this.batchUpdate(); // prevent in between re-layout #1535 TODO: this only set float=true, need to prevent collision check...
186
221
  this.getGridItems().forEach(function (el) { return _this._prepareElement(el); });
@@ -193,13 +228,12 @@ var GridStack = exports.GridStack = /** @class */ (function () {
193
228
  if (children.length)
194
229
  this.load(children); // don't load empty
195
230
  }
231
+ // if (this.engine.nodes.length) this._updateStyles(); // update based on # of children. done in engine onChange CB
196
232
  this.setAnimation(this.opts.animate);
197
- this._updateStyles();
198
- this.el.classList.add('gs-' + this.opts.column);
199
233
  // dynamic grids require pausing during drag to detect over to nest vs push
200
234
  if (this.opts.subGridDynamic && !dd_manager_1.DDManager.pauseDrag)
201
235
  dd_manager_1.DDManager.pauseDrag = true;
202
- if (((_b = this.opts.draggable) === null || _b === void 0 ? void 0 : _b.pause) !== undefined)
236
+ if (((_d = this.opts.draggable) === null || _d === void 0 ? void 0 : _d.pause) !== undefined)
203
237
  dd_manager_1.DDManager.pauseDrag = this.opts.draggable.pause;
204
238
  this._setupRemoveDrop();
205
239
  this._setupAcceptWidget();
@@ -424,7 +458,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
424
458
  if (ops.column === 'auto') {
425
459
  autoColumn = true;
426
460
  ops.column = Math.max(node.w || 1, (nodeToAdd === null || nodeToAdd === void 0 ? void 0 : nodeToAdd.w) || 1);
427
- ops.disableOneColumnMode = true; // driven by parent
461
+ delete ops.columnOpts; // driven by parent
428
462
  }
429
463
  // if we're converting an existing full item, move over the content to be the first sub item in the new grid
430
464
  var content = node.el.querySelector('.grid-stack-item-content');
@@ -566,7 +600,6 @@ var GridStack = exports.GridStack = /** @class */ (function () {
566
600
  }
567
601
  if (this._autoColumn) {
568
602
  o.column = 'auto';
569
- delete o.disableOneColumnMode;
570
603
  }
571
604
  var origShow = o._alwaysShowResizeHandle;
572
605
  delete o._alwaysShowResizeHandle;
@@ -596,17 +629,17 @@ var GridStack = exports.GridStack = /** @class */ (function () {
596
629
  var _this = this;
597
630
  if (addRemove === void 0) { addRemove = GridStack.addRemoveCB || true; }
598
631
  items = utils_1.Utils.cloneDeep(items); // so we can mod
599
- // if passed list has coordinates, use them (insert from end to beginning for conflict resolution) else force widget same order
632
+ var column = this.getColumn();
633
+ // if passed list has coordinates, use them (insert from end to beginning for conflict resolution) else keep widget order
600
634
  var haveCoord = items.some(function (w) { return w.x !== undefined || w.y !== undefined; });
601
635
  if (haveCoord)
602
- items = utils_1.Utils.sort(items, -1, this._prevColumn || this.getColumn());
636
+ items = utils_1.Utils.sort(items, -1, column);
603
637
  this._insertNotAppend = haveCoord; // if we create in reverse order...
604
- // 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
638
+ // if we're loading a layout into for example 1 column and items don't fit, make sure to save
605
639
  // the original wanted layout so we can scale back up correctly #1471
606
- var column = this.opts.column;
607
- if (this._prevColumn && this._prevColumn !== column && items.some(function (n) { return ((n.x || 0) + n.w) > column; })) {
640
+ if (items.some(function (n) { return ((n.x || 0) + (n.w || 1)) > column; })) {
608
641
  this._ignoreLayoutsNodeChange = true; // skip layout update
609
- this.engine.cacheLayout(items, this._prevColumn, true);
642
+ this.engine.cacheLayout(items, 12, true); // TODO: 12 is arbitrary. use max value in layout ?
610
643
  }
611
644
  // if given a different callback, temporally set it as global option so creating will use it
612
645
  var prevCB = GridStack.addRemoveCB;
@@ -614,6 +647,10 @@ var GridStack = exports.GridStack = /** @class */ (function () {
614
647
  GridStack.addRemoveCB = addRemove;
615
648
  var removed = [];
616
649
  this.batchUpdate();
650
+ // if we are blank (loading into empty like startup) temp remove animation
651
+ var noAnim = !this.engine.nodes.length;
652
+ if (noAnim)
653
+ this.setAnimation(false);
617
654
  // see if any items are missing from new layout and need to be removed first
618
655
  if (addRemove) {
619
656
  var copyNodes = __spreadArray([], this.engine.nodes, true); // don't loop through array you modify
@@ -639,22 +676,20 @@ var GridStack = exports.GridStack = /** @class */ (function () {
639
676
  } // remove if found from list
640
677
  return true;
641
678
  });
642
- var widthChanged = false;
643
679
  items.forEach(function (w) {
644
680
  var _a;
645
681
  var item = utils_1.Utils.find(updateNodes, w.id);
646
682
  if (item) {
647
- // if item sizes to content, re-use the exiting height so it's a better guess at the final size 9same if width doesn't change)
683
+ // if item sizes to content, re-use the exiting height so it's a better guess at the final size (same if width doesn't change)
648
684
  if (utils_1.Utils.shouldSizeToContent(item))
649
685
  w.h = item.h;
650
686
  // check if missing coord, in which case find next empty slot with new (or old if missing) sizes
651
- _this.engine.nodeBoundFix(w); // before widthChanged is checked below...
687
+ _this.engine.nodeBoundFix(w);
652
688
  if (w.autoPosition || w.x === undefined || w.y === undefined) {
653
689
  w.w = w.w || item.w;
654
690
  w.h = w.h || item.h;
655
691
  _this.engine.findEmptyPosition(w);
656
692
  }
657
- widthChanged = widthChanged || (w.w !== undefined && w.w !== item.w);
658
693
  // add back to current list BUT force a collision check if it 'appears' we didn't change to make sure we don't overlap others now
659
694
  _this.engine.nodes.push(item);
660
695
  if (utils_1.Utils.samePos(item, w)) {
@@ -674,12 +709,14 @@ var GridStack = exports.GridStack = /** @class */ (function () {
674
709
  }
675
710
  });
676
711
  this.engine.removedNodes = removed;
677
- this.doContentResize(widthChanged, true); // we only need to wait for animation if we changed any widths
678
712
  this.batchUpdate(false);
679
713
  // after commit, clear that flag
680
714
  delete this._ignoreLayoutsNodeChange;
681
715
  delete this._insertNotAppend;
682
716
  prevCB ? GridStack.addRemoveCB = prevCB : delete GridStack.addRemoveCB;
717
+ // delay adding animation back
718
+ if (noAnim && this.opts.animate)
719
+ setTimeout(function () { return _this.setAnimation(_this.opts.animate); });
683
720
  return this;
684
721
  };
685
722
  /**
@@ -706,11 +743,18 @@ var GridStack = exports.GridStack = /** @class */ (function () {
706
743
  (!forcePixel || !this.opts.cellHeightUnit || this.opts.cellHeightUnit === 'px')) {
707
744
  return this.opts.cellHeight;
708
745
  }
746
+ // do rem/em to px conversion
747
+ if (this.opts.cellHeightUnit === 'rem') {
748
+ return this.opts.cellHeight * parseFloat(getComputedStyle(document.documentElement).fontSize);
749
+ }
750
+ if (this.opts.cellHeightUnit === 'em') {
751
+ return this.opts.cellHeight * parseFloat(getComputedStyle(this.el).fontSize);
752
+ }
709
753
  // else get first cell height
710
754
  var el = this.el.querySelector('.' + this.opts.itemClass);
711
755
  if (el) {
712
- var height = utils_1.Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
713
- return Math.round(el.offsetHeight / height);
756
+ var h = utils_1.Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
757
+ return Math.round(el.offsetHeight / h);
714
758
  }
715
759
  // else do entire grid and # of rows (but doesn't work if min-height is the actual constrain)
716
760
  var rows = parseInt(this.el.getAttribute('gs-current-row'));
@@ -754,7 +798,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
754
798
  }
755
799
  this.opts.cellHeightUnit = data.unit;
756
800
  this.opts.cellHeight = data.h;
757
- this.doContentResize(false, true); // no anim wait, but use attributes since we only change row height
801
+ this.resizeToContentCheck();
758
802
  if (update) {
759
803
  this._updateStyles(true); // true = force re-create for current # of rows
760
804
  }
@@ -764,11 +808,40 @@ var GridStack = exports.GridStack = /** @class */ (function () {
764
808
  GridStack.prototype.cellWidth = function () {
765
809
  return this._widthOrContainer() / this.getColumn();
766
810
  };
767
- /** return our expected width (or parent) for 1 column check */
768
- GridStack.prototype._widthOrContainer = function () {
811
+ /** return our expected width (or parent) , and optionally of window for dynamic column check */
812
+ GridStack.prototype._widthOrContainer = function (forBreakpoint) {
813
+ var _a;
814
+ if (forBreakpoint === void 0) { forBreakpoint = false; }
769
815
  // use `offsetWidth` or `clientWidth` (no scrollbar) ?
770
816
  // https://stackoverflow.com/questions/21064101/understanding-offsetwidth-clientwidth-scrollwidth-and-height-respectively
771
- return (this.el.clientWidth || this.el.parentElement.clientWidth || window.innerWidth);
817
+ return forBreakpoint && ((_a = this.opts.columnOpts) === null || _a === void 0 ? void 0 : _a.breakpointForWindow) ? window.innerWidth : (this.el.clientWidth || this.el.parentElement.clientWidth || window.innerWidth);
818
+ };
819
+ /** checks for dynamic column count for our current size, returning true if changed */
820
+ GridStack.prototype.checkDynamicColumn = function () {
821
+ var _a, _b;
822
+ var resp = this.opts.columnOpts;
823
+ if (!resp || (!resp.columnWidth && !((_a = resp.breakpoints) === null || _a === void 0 ? void 0 : _a.length)))
824
+ return false;
825
+ var column = this.getColumn();
826
+ var newColumn = column;
827
+ var w = this._widthOrContainer(true);
828
+ if (resp.columnWidth) {
829
+ newColumn = Math.min(Math.round(w / resp.columnWidth) || 1, resp.columnMax);
830
+ }
831
+ else {
832
+ // find the closest breakpoint (already sorted big to small) that matches
833
+ newColumn = resp.columnMax;
834
+ var i = 0;
835
+ while (i < resp.breakpoints.length && w <= resp.breakpoints[i].w) {
836
+ newColumn = resp.breakpoints[i++].c || column;
837
+ }
838
+ }
839
+ if (newColumn !== column) {
840
+ var bk = (_b = resp.breakpoints) === null || _b === void 0 ? void 0 : _b.find(function (b) { return b.c === newColumn; });
841
+ this.column(newColumn, (bk === null || bk === void 0 ? void 0 : bk.layout) || resp.layout);
842
+ return true;
843
+ }
844
+ return false;
772
845
  };
773
846
  /**
774
847
  * re-layout grid items to reclaim any empty space. Options are:
@@ -798,34 +871,19 @@ var GridStack = exports.GridStack = /** @class */ (function () {
798
871
  if (!column || column < 1 || this.opts.column === column)
799
872
  return this;
800
873
  var oldColumn = this.getColumn();
801
- // if we go into 1 column mode due to size change (disableOneColumnMode is off and we hit min width)
802
- // then remember the original columns so we can restore.
803
- if (column === 1 && !this.opts.disableOneColumnMode) {
804
- this._prevColumn = oldColumn;
805
- }
806
- else {
807
- delete this._prevColumn;
808
- }
874
+ this.opts.column = column;
875
+ if (!this.engine)
876
+ return this; // called in constructor, noting else to do
877
+ this.engine.column = column;
809
878
  this.el.classList.remove('gs-' + oldColumn);
810
879
  this.el.classList.add('gs-' + column);
811
- this.opts.column = this.engine.column = column;
812
- // update the items now - see if the dom order nodes should be passed instead (else default to current list)
813
- var domNodes;
814
- if (column === 1 && this.opts.oneColumnModeDomSort) {
815
- domNodes = [];
816
- this.getGridItems().forEach(function (el) {
817
- if (el.gridstackNode) {
818
- domNodes.push(el.gridstackNode);
819
- }
820
- });
821
- if (!domNodes.length) {
822
- domNodes = undefined;
823
- }
824
- }
825
- this.engine.columnChanged(oldColumn, column, domNodes, layout);
880
+ // update the items now, checking if we have a custom children layout
881
+ /*const newChildren = this.opts.columnOpts?.breakpoints?.find(r => r.c === column)?.children;
882
+ if (newChildren) this.load(newChildren);
883
+ else*/ this.engine.columnChanged(oldColumn, column, undefined, layout);
826
884
  if (this._isAutoCellHeight)
827
885
  this.cellHeight();
828
- this.doContentResize();
886
+ this.resizeToContentCheck(true); // wait for width resizing
829
887
  // and trigger our event last...
830
888
  this._ignoreLayoutsNodeChange = true; // skip layout update
831
889
  this._triggerChangeEvent();
@@ -835,9 +893,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
835
893
  /**
836
894
  * get the number of columns in the grid (default 12)
837
895
  */
838
- GridStack.prototype.getColumn = function () {
839
- return this.opts.column;
840
- };
896
+ GridStack.prototype.getColumn = function () { return this.opts.column; };
841
897
  /** returns an array of grid HTML elements (no placeholder) - used to iterate through our children in DOM order */
842
898
  GridStack.prototype.getGridItems = function () {
843
899
  var _this = this;
@@ -952,14 +1008,13 @@ var GridStack = exports.GridStack = /** @class */ (function () {
952
1008
  this._prepareElement(el, true, options);
953
1009
  var node = el.gridstackNode;
954
1010
  this._updateContainerHeight();
955
- this.doContentResize(false, false, node);
956
1011
  // see if there is a sub-grid to create
957
1012
  if (node.subGridOpts) {
958
1013
  this.makeSubGrid(el, node.subGridOpts, undefined, false); // node.subGrid will be used as option in method, no need to pass
959
1014
  }
960
- // if we're adding an item into 1 column (_prevColumn is set only when going to 1) make sure
1015
+ // if we're adding an item into 1 column make sure
961
1016
  // we don't override the larger 12 column layout that was already saved. #1985
962
- if (this._prevColumn && this.opts.column === 1) {
1017
+ if (this.opts.column === 1) {
963
1018
  this._ignoreLayoutsNodeChange = true;
964
1019
  }
965
1020
  this._triggerAddEvent();
@@ -991,8 +1046,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
991
1046
  names.forEach(function (name) { return _this.on(name, callback); });
992
1047
  return this;
993
1048
  }
1049
+ // native CustomEvent handlers - cash the generic handlers so we can easily remove
994
1050
  if (name === 'change' || name === 'added' || name === 'removed' || name === 'enable' || name === 'disable') {
995
- // native CustomEvent handlers - cash the generic handlers so we can easily remove
996
1051
  var noData = (name === 'enable' || name === 'disable');
997
1052
  if (noData) {
998
1053
  this._gsEventHandler[name] = function (event) { return callback(event); };
@@ -1009,7 +1064,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1009
1064
  this._gsEventHandler[name] = callback;
1010
1065
  }
1011
1066
  else {
1012
- console.log('GridStack.on(' + name + ') event not supported, but you can still use $(".grid-stack").on(...) while jquery-ui is still used internally.');
1067
+ console.log('GridStack.on(' + name + ') event not supported');
1013
1068
  }
1014
1069
  return this;
1015
1070
  };
@@ -1106,6 +1161,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1106
1161
  }
1107
1162
  return this;
1108
1163
  };
1164
+ /** @internal */
1165
+ GridStack.prototype.hasAnimationCSS = function () { return this.el.classList.contains('grid-stack-animate'); };
1109
1166
  /**
1110
1167
  * Toggle the grid static state, which permanently removes/add Drag&Drop support, unlike disable()/enable() that just turns it off/on.
1111
1168
  * Also toggle the grid-stack-static class.
@@ -1196,8 +1253,11 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1196
1253
  }
1197
1254
  utils_1.Utils.sanitizeMinMax(n);
1198
1255
  // finally move the widget and update attr
1199
- if (m)
1256
+ if (m) {
1257
+ var widthChanged = (m.w !== undefined && m.w !== n.w);
1200
1258
  _this.moveNode(n, m);
1259
+ _this.resizeToContentCheck(widthChanged, n); // wait for animation if we changed width
1260
+ }
1201
1261
  if (m || changed) {
1202
1262
  _this._writeAttr(el, n);
1203
1263
  }
@@ -1218,10 +1278,10 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1218
1278
  /**
1219
1279
  * Updates widget height to match the content height to avoid v-scrollbar or dead space.
1220
1280
  * 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.
1221
- * 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
1281
+ * @param el grid item element
1282
+ * @param useNodeH 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
1222
1283
  */
1223
- GridStack.prototype.resizeToContent = function (el, useAttrSize) {
1224
- if (useAttrSize === void 0) { useAttrSize = false; }
1284
+ GridStack.prototype.resizeToContent = function (el) {
1225
1285
  if (!el)
1226
1286
  return;
1227
1287
  el.classList.remove('size-to-content-max');
@@ -1231,14 +1291,12 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1231
1291
  if (!n)
1232
1292
  return;
1233
1293
  var grid = n.grid;
1234
- if (!grid)
1235
- return;
1236
- if (el.parentElement !== grid.el)
1294
+ if (!grid || el.parentElement !== grid.el)
1237
1295
  return; // skip if we are not inside a grid
1238
- var cell = grid.getCellHeight();
1296
+ var cell = grid.getCellHeight(true);
1239
1297
  if (!cell)
1240
1298
  return;
1241
- var height = useAttrSize && n.h ? n.h * cell : el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1299
+ var height = n.h ? n.h * cell : el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1242
1300
  var item;
1243
1301
  if (n.resizeToContentParent)
1244
1302
  item = el.querySelector(n.resizeToContentParent);
@@ -1247,11 +1305,11 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1247
1305
  if (!item)
1248
1306
  return;
1249
1307
  var padding = el.clientHeight - item.clientHeight; // full - available height to our child (minus border, padding...)
1250
- var 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)
1308
+ var 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)
1251
1309
  var wantedH;
1252
1310
  if (n.subGrid) {
1253
1311
  // sub-grid - use their actual row count * their cell height
1254
- wantedH = n.subGrid.getRow() * n.subGrid.getCellHeight();
1312
+ wantedH = n.subGrid.getRow() * n.subGrid.getCellHeight(true);
1255
1313
  }
1256
1314
  else {
1257
1315
  // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
@@ -1283,12 +1341,11 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1283
1341
  }
1284
1342
  };
1285
1343
  /** call the user resize (so they can do extra work) else our build in version */
1286
- GridStack.prototype.resizeToContentCheck = function (el, useAttr) {
1287
- if (useAttr === void 0) { useAttr = false; }
1344
+ GridStack.prototype.resizeToContentCBCheck = function (el) {
1288
1345
  if (GridStack.resizeToContentCB)
1289
- GridStack.resizeToContentCB(el, useAttr);
1346
+ GridStack.resizeToContentCB(el);
1290
1347
  else
1291
- this.resizeToContent(el, useAttr);
1348
+ this.resizeToContent(el);
1292
1349
  };
1293
1350
  /**
1294
1351
  * 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).
@@ -1383,7 +1440,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1383
1440
  /** @internal called to delete the current dynamic style sheet used for our layout */
1384
1441
  GridStack.prototype._removeStylesheet = function () {
1385
1442
  if (this._styles) {
1386
- utils_1.Utils.removeStylesheet(this._styleSheetClass);
1443
+ var styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode;
1444
+ utils_1.Utils.removeStylesheet(this._styleSheetClass, styleLocation);
1387
1445
  delete this._styles;
1388
1446
  }
1389
1447
  return this;
@@ -1395,7 +1453,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1395
1453
  if (forceUpdate) {
1396
1454
  this._removeStylesheet();
1397
1455
  }
1398
- if (!maxH)
1456
+ if (maxH === undefined)
1399
1457
  maxH = this.getRow();
1400
1458
  this._updateContainerHeight();
1401
1459
  // if user is telling us they will handle the CSS themselves by setting heights to 0. Do we need this opts really ??
@@ -1475,26 +1533,25 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1475
1533
  }
1476
1534
  // if we're a nested grid inside an sizeToContent item, tell it to resize itself too
1477
1535
  if (parent && !parent.grid.engine.batchMode && utils_1.Utils.shouldSizeToContent(parent)) {
1478
- parent.grid.resizeToContentCheck(parent.el);
1536
+ parent.grid.resizeToContentCBCheck(parent.el);
1479
1537
  }
1480
1538
  return this;
1481
1539
  };
1482
1540
  /** @internal */
1483
1541
  GridStack.prototype._prepareElement = function (el, triggerAddEvent, node) {
1484
1542
  if (triggerAddEvent === void 0) { triggerAddEvent = false; }
1485
- el.classList.add(this.opts.itemClass);
1486
1543
  node = node || this._readAttr(el);
1487
1544
  el.gridstackNode = node;
1488
1545
  node.el = el;
1489
1546
  node.grid = this;
1490
- var copy = __assign({}, node);
1491
1547
  node = this.engine.addNode(node, triggerAddEvent);
1492
- // write node attr back in case there was collision or we have to fix bad values during addNode()
1493
- if (!utils_1.Utils.same(node, copy)) {
1494
- this._writeAttr(el, node);
1495
- }
1496
- if (utils_1.Utils.shouldSizeToContent(node))
1497
- el.classList.add('size-to-content');
1548
+ // write the dom sizes and class
1549
+ this._writeAttr(el, node);
1550
+ el.classList.add(types_1.gridDefaults.itemClass, this.opts.itemClass);
1551
+ var sizeToContent = utils_1.Utils.shouldSizeToContent(node);
1552
+ sizeToContent ? el.classList.add('size-to-content') : el.classList.remove('size-to-content');
1553
+ if (sizeToContent)
1554
+ this.resizeToContentCheck(false, node);
1498
1555
  this._prepareDragDropByNode(node);
1499
1556
  return this;
1500
1557
  };
@@ -1612,15 +1669,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1612
1669
  }
1613
1670
  }
1614
1671
  else {
1615
- // else check for 1 column in/out behavior
1616
- var oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize ||
1617
- (this.opts.column === 1 && !this._prevColumn);
1618
- if ((this.opts.column === 1) !== oneColumn) {
1619
- // if (this.opts.animate) this.setAnimation(false); // 1 <-> 12 is too radical, turn off animation and we need it for sizeToContent
1620
- this.column(oneColumn ? 1 : this._prevColumn);
1621
- // if (this.opts.animate) setTimeout(() => this.setAnimation(true));
1622
- columnChanged = true;
1623
- }
1672
+ // else check for dynamic column
1673
+ columnChanged = this.checkDynamicColumn();
1624
1674
  }
1625
1675
  // make the cells content square again
1626
1676
  if (this._isAutoCellHeight)
@@ -1631,46 +1681,46 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1631
1681
  n.subGrid.onResize();
1632
1682
  });
1633
1683
  if (!this._skipInitialResize)
1634
- this.doContentResize(columnChanged); // wait for anim of column changed (DOM reflow before we can size correctly)
1684
+ this.resizeToContentCheck(columnChanged); // wait for anim of column changed (DOM reflow before we can size correctly)
1635
1685
  delete this._skipInitialResize;
1636
1686
  this.batchUpdate(false);
1637
1687
  return this;
1638
1688
  };
1639
- GridStack.prototype.doContentResize = function (delay, useAttr, n) {
1689
+ /** resizes content for given node (or all) if shouldSizeToContent() is true */
1690
+ GridStack.prototype.resizeToContentCheck = function (delay, n) {
1640
1691
  var _this = this;
1641
- if (delay === void 0) { delay = true; }
1642
- if (useAttr === void 0) { useAttr = false; }
1692
+ if (delay === void 0) { delay = false; }
1643
1693
  if (n === void 0) { n = undefined; }
1694
+ if (!this.engine)
1695
+ return; // we've been deleted in between!
1644
1696
  // update any gridItem height with sizeToContent, but wait for DOM $animation_speed to settle if we changed column count
1645
1697
  // 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 ?
1646
- setTimeout(function () {
1647
- if (!_this.engine)
1648
- return; // we've been deleted in between!
1649
- if (n) {
1698
+ if (delay && this.hasAnimationCSS())
1699
+ return setTimeout(function () { return _this.resizeToContentCheck(false, n); }, 300 + 10);
1700
+ if (n) {
1701
+ if (utils_1.Utils.shouldSizeToContent(n))
1702
+ this.resizeToContentCBCheck(n.el);
1703
+ }
1704
+ else if (this.engine.nodes.some(function (n) { return utils_1.Utils.shouldSizeToContent(n); })) {
1705
+ var nodes = __spreadArray([], this.engine.nodes, true); // in case order changes while resizing one
1706
+ this.batchUpdate();
1707
+ nodes.forEach(function (n) {
1650
1708
  if (utils_1.Utils.shouldSizeToContent(n))
1651
- _this.resizeToContentCheck(n.el, useAttr);
1652
- }
1653
- else if (_this.engine.nodes.some(function (n) { return utils_1.Utils.shouldSizeToContent(n); })) {
1654
- var nodes = __spreadArray([], _this.engine.nodes, true); // in case order changes while resizing one
1655
- _this.batchUpdate();
1656
- nodes.forEach(function (n) {
1657
- if (utils_1.Utils.shouldSizeToContent(n))
1658
- _this.resizeToContentCheck(n.el, useAttr);
1659
- });
1660
- _this.batchUpdate(false);
1661
- }
1662
- // call this regardless of shouldSizeToContent because widget might need to stretch to take available space after a resize
1663
- if (_this._gsEventHandler['resizecontent'])
1664
- _this._gsEventHandler['resizecontent'](null, n ? [n] : _this.engine.nodes);
1665
- }, delay ? 300 + 10 : 0);
1709
+ _this.resizeToContentCBCheck(n.el);
1710
+ });
1711
+ this.batchUpdate(false);
1712
+ }
1713
+ // call this regardless of shouldSizeToContent because widget might need to stretch to take available space after a resize
1714
+ if (this._gsEventHandler['resizecontent'])
1715
+ this._gsEventHandler['resizecontent'](null, n ? [n] : this.engine.nodes);
1666
1716
  };
1667
1717
  /** add or remove the grid element size event handler */
1668
1718
  GridStack.prototype._updateResizeEvent = function (forceRemove) {
1669
1719
  var _this = this;
1670
1720
  if (forceRemove === void 0) { forceRemove = false; }
1671
- // 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)
1721
+ // only add event if we're not nested (parent will call us) and we're auto sizing cells or supporting dynamic column (i.e. doing work)
1672
1722
  // or supporting new sizeToContent option.
1673
- var trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.sizeToContent || !this.opts.disableOneColumnMode
1723
+ var trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.sizeToContent || this.opts.columnOpts
1674
1724
  || this.engine.nodes.find(function (n) { return n.sizeToContent; }));
1675
1725
  if (!forceRemove && trackSize && !this.resizeObserver) {
1676
1726
  this._sizeThrottle = utils_1.Utils.throttle(function () { return _this.onResize(); }, this.opts.cellHeightThrottle);
@@ -2071,6 +2121,10 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2071
2121
  return false;
2072
2122
  var wasAdded = !!_this.placeholder.parentElement; // skip items not actually added to us because of constrains, but do cleanup #1419
2073
2123
  _this.placeholder.remove();
2124
+ // disable animation when replacing a placeholder (already positioned) with actual content
2125
+ var noAnim = wasAdded && _this.opts.animate;
2126
+ if (noAnim)
2127
+ _this.setAnimation(false);
2074
2128
  // notify previous grid of removal
2075
2129
  // console.log('drop delete _gridstackNodeOrig') // TEST
2076
2130
  var origNode = el._gridstackNodeOrig;
@@ -2115,15 +2169,13 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2115
2169
  // @ts-ignore
2116
2170
  utils_1.Utils.copyPos(node, _this._readAttr(_this.placeholder)); // placeholder values as moving VERY fast can throw things off #1578
2117
2171
  utils_1.Utils.removePositioningStyles(el); // @ts-ignore
2118
- _this._writeAttr(el, node);
2119
- el.classList.add(types_1.gridDefaults.itemClass, _this.opts.itemClass);
2120
2172
  _this.el.appendChild(el); // @ts-ignore // TODO: now would be ideal time to _removeHelperStyle() overriding floating styles (native only)
2173
+ _this._prepareElement(el, true, node);
2121
2174
  if (subGrid) {
2122
2175
  subGrid.parentGridItem = node;
2123
2176
  if (!subGrid.opts.styleInHead)
2124
2177
  subGrid._updateStyles(true); // re-create sub-grid styles now that we've moved
2125
2178
  }
2126
- _this._prepareDragDropByNode(node);
2127
2179
  _this._updateContainerHeight();
2128
2180
  _this.engine.addedNodes.push(node); // @ts-ignore
2129
2181
  _this._triggerAddEvent(); // @ts-ignore
@@ -2132,6 +2184,9 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2132
2184
  if (_this._gsEventHandler['dropped']) {
2133
2185
  _this._gsEventHandler['dropped'](__assign(__assign({}, event), { type: 'dropped' }), origNode && origNode.grid ? origNode : undefined, node);
2134
2186
  }
2187
+ // delay adding animation back
2188
+ if (noAnim)
2189
+ setTimeout(function () { return _this.setAnimation(_this.opts.animate); });
2135
2190
  return false; // prevent parent from receiving msg (which may be grid as well)
2136
2191
  });
2137
2192
  return this;
@@ -2201,6 +2256,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2201
2256
  delete node._moving;
2202
2257
  delete node._event;
2203
2258
  delete node._lastTried;
2259
+ var widthChanged = node.w !== node._orig.w;
2204
2260
  // if the item has moved to another grid, we're done here
2205
2261
  var target = event.target;
2206
2262
  if (!target.gridstackNode || target.gridstackNode.grid !== _this)
@@ -2238,7 +2294,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2238
2294
  if (event.type === 'resizestop') {
2239
2295
  if (Number.isInteger(node.sizeToContent))
2240
2296
  node.sizeToContent = node.h; // new soft limit
2241
- _this.doContentResize(false, true, node); // no amin wait as will use the actual sized coordinate attr
2297
+ _this.resizeToContentCheck(widthChanged, node); // wait for width animation if changed
2242
2298
  }
2243
2299
  };
2244
2300
  dd.draggable(el, {
@@ -2414,7 +2470,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2414
2470
  GridStack.Utils = utils_1.Utils;
2415
2471
  /** scoping so users can call new GridStack.Engine(12) for example */
2416
2472
  GridStack.Engine = gridstack_engine_1.GridStackEngine;
2417
- GridStack.GDRev = '9.5.1';
2473
+ GridStack.GDRev = '10.0.1';
2418
2474
  return GridStack;
2419
2475
  }());
2420
2476
  //# sourceMappingURL=gridstack.js.map