gridstack 10.0.0 → 10.1.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 (113) hide show
  1. package/README.md +2 -2
  2. package/angular/package.json +1 -1
  3. package/angular/projects/lib/package.json +1 -1
  4. package/angular/projects/lib/src/lib/base-widget.ts +1 -1
  5. package/angular/projects/lib/src/lib/gridstack-item.component.ts +1 -1
  6. package/angular/projects/lib/src/lib/gridstack.component.ts +1 -1
  7. package/angular/projects/lib/src/lib/gridstack.module.ts +1 -1
  8. package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
  9. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
  10. package/dist/angular/esm2020/lib/gridstack.component.mjs +2 -2
  11. package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
  12. package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
  13. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  14. package/dist/angular/fesm2020/gridstack-angular.mjs +4 -4
  15. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  16. package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
  17. package/dist/angular/lib/gridstack.component.d.ts +1 -1
  18. package/dist/angular/package.json +1 -1
  19. package/dist/angular/src/base-widget.ts +1 -1
  20. package/dist/angular/src/gridstack-item.component.ts +1 -1
  21. package/dist/angular/src/gridstack.component.ts +1 -1
  22. package/dist/angular/src/gridstack.module.ts +1 -1
  23. package/dist/dd-base-impl.d.ts +1 -1
  24. package/dist/dd-base-impl.js +1 -1
  25. package/dist/dd-base-impl.js.map +1 -1
  26. package/dist/dd-draggable.d.ts +1 -1
  27. package/dist/dd-draggable.js +18 -29
  28. package/dist/dd-draggable.js.map +1 -1
  29. package/dist/dd-droppable.d.ts +1 -1
  30. package/dist/dd-droppable.js +13 -11
  31. package/dist/dd-droppable.js.map +1 -1
  32. package/dist/dd-element.d.ts +1 -1
  33. package/dist/dd-element.js +1 -1
  34. package/dist/dd-element.js.map +1 -1
  35. package/dist/dd-gridstack.d.ts +1 -1
  36. package/dist/dd-gridstack.js +14 -4
  37. package/dist/dd-gridstack.js.map +1 -1
  38. package/dist/dd-manager.d.ts +1 -1
  39. package/dist/dd-manager.js +1 -1
  40. package/dist/dd-manager.js.map +1 -1
  41. package/dist/dd-resizable-handle.d.ts +1 -1
  42. package/dist/dd-resizable-handle.js +3 -3
  43. package/dist/dd-resizable-handle.js.map +1 -1
  44. package/dist/dd-resizable.d.ts +3 -3
  45. package/dist/dd-resizable.js +7 -22
  46. package/dist/dd-resizable.js.map +1 -1
  47. package/dist/dd-touch.d.ts +1 -1
  48. package/dist/dd-touch.js +1 -1
  49. package/dist/dd-touch.js.map +1 -1
  50. package/dist/es5/dd-base-impl.d.ts +1 -1
  51. package/dist/es5/dd-base-impl.js +1 -1
  52. package/dist/es5/dd-base-impl.js.map +1 -1
  53. package/dist/es5/dd-draggable.d.ts +1 -1
  54. package/dist/es5/dd-draggable.js +18 -29
  55. package/dist/es5/dd-draggable.js.map +1 -1
  56. package/dist/es5/dd-droppable.d.ts +1 -1
  57. package/dist/es5/dd-droppable.js +14 -11
  58. package/dist/es5/dd-droppable.js.map +1 -1
  59. package/dist/es5/dd-element.d.ts +1 -1
  60. package/dist/es5/dd-element.js +1 -1
  61. package/dist/es5/dd-element.js.map +1 -1
  62. package/dist/es5/dd-gridstack.d.ts +1 -1
  63. package/dist/es5/dd-gridstack.js +13 -3
  64. package/dist/es5/dd-gridstack.js.map +1 -1
  65. package/dist/es5/dd-manager.d.ts +1 -1
  66. package/dist/es5/dd-manager.js +1 -1
  67. package/dist/es5/dd-manager.js.map +1 -1
  68. package/dist/es5/dd-resizable-handle.d.ts +1 -1
  69. package/dist/es5/dd-resizable-handle.js +3 -3
  70. package/dist/es5/dd-resizable-handle.js.map +1 -1
  71. package/dist/es5/dd-resizable.d.ts +3 -3
  72. package/dist/es5/dd-resizable.js +7 -22
  73. package/dist/es5/dd-resizable.js.map +1 -1
  74. package/dist/es5/dd-touch.d.ts +1 -1
  75. package/dist/es5/dd-touch.js +1 -1
  76. package/dist/es5/dd-touch.js.map +1 -1
  77. package/dist/es5/gridstack-all.js +1 -1
  78. package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
  79. package/dist/es5/gridstack-all.js.map +1 -1
  80. package/dist/es5/gridstack-engine.d.ts +1 -1
  81. package/dist/es5/gridstack-engine.js +9 -24
  82. package/dist/es5/gridstack-engine.js.map +1 -1
  83. package/dist/es5/gridstack-poly.js +1 -1
  84. package/dist/es5/gridstack.d.ts +18 -11
  85. package/dist/es5/gridstack.js +153 -91
  86. package/dist/es5/gridstack.js.map +1 -1
  87. package/dist/es5/types.d.ts +3 -3
  88. package/dist/es5/types.js +1 -1
  89. package/dist/es5/types.js.map +1 -1
  90. package/dist/es5/utils.d.ts +13 -2
  91. package/dist/es5/utils.js +31 -4
  92. package/dist/es5/utils.js.map +1 -1
  93. package/dist/gridstack-all.js +1 -1
  94. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  95. package/dist/gridstack-all.js.map +1 -1
  96. package/dist/gridstack-engine.d.ts +1 -1
  97. package/dist/gridstack-engine.js +9 -24
  98. package/dist/gridstack-engine.js.map +1 -1
  99. package/dist/gridstack.css +2 -2
  100. package/dist/gridstack.d.ts +18 -11
  101. package/dist/gridstack.js +155 -92
  102. package/dist/gridstack.js.map +1 -1
  103. package/dist/gridstack.min.css +1 -1
  104. package/dist/src/gridstack.scss +2 -2
  105. package/dist/types.d.ts +3 -3
  106. package/dist/types.js +1 -1
  107. package/dist/types.js.map +1 -1
  108. package/dist/utils.d.ts +13 -2
  109. package/dist/utils.js +31 -4
  110. package/dist/utils.js.map +1 -1
  111. package/doc/CHANGES.md +22 -1
  112. package/doc/README.md +7 -7
  113. 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 10.0.0
39
+ * GridStack 10.1.0
40
40
  * https://gridstackjs.com/
41
41
  *
42
42
  * Copyright (c) 2021-2022 Alain Dumesny
@@ -84,6 +84,9 @@ var GridStack = exports.GridStack = /** @class */ (function () {
84
84
  this._gsEventHandler = {};
85
85
  /** @internal extra row added when dragging at the bottom of the grid */
86
86
  this._extraDragRow = 0;
87
+ /** @internal meant to store the scale of the active grid */
88
+ this.dragTransform = { xScale: 1, yScale: 1, xOffset: 0, yOffset: 0 };
89
+ el.gridstack = this;
87
90
  this.el = el; // exposed HTML element to the user
88
91
  opts = opts || {}; // handles null/undefined/0
89
92
  if (!el.classList.contains('grid-stack')) {
@@ -108,7 +111,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
108
111
  var oldOpts = opts;
109
112
  if (oldOpts.oneColumnModeDomSort) {
110
113
  delete oldOpts.oneColumnModeDomSort;
111
- console.log('Error: Gridstack oneColumnModeDomSort no longer supported. Check GridStackOptions.columnOpts instead.');
114
+ console.log('warning: Gridstack oneColumnModeDomSort no longer supported. Use GridStackOptions.columnOpts instead.');
112
115
  }
113
116
  if (oldOpts.oneColumnSize || oldOpts.disableOneColumnMode === false) {
114
117
  var oneSize = oldOpts.oneColumnSize || 768;
@@ -153,6 +156,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
153
156
  this._initMargin(); // part of settings defaults...
154
157
  // 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)
155
158
  this.checkDynamicColumn();
159
+ this.el.classList.add('gs-' + this.opts.column);
156
160
  if (this.opts.rtl === 'auto') {
157
161
  this.opts.rtl = (el.style.direction === 'rtl');
158
162
  }
@@ -212,6 +216,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
212
216
  _this._updateStyles(false, maxH); // false = don't recreate, just append if need be
213
217
  }
214
218
  });
219
+ // create initial global styles BEFORE loading children so resizeToContent margin can be calculated correctly
220
+ this._updateStyles(false, 0);
215
221
  if (this.opts.auto) {
216
222
  this.batchUpdate(); // prevent in between re-layout #1535 TODO: this only set float=true, need to prevent collision check...
217
223
  this.getGridItems().forEach(function (el) { return _this._prepareElement(el); });
@@ -224,9 +230,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
224
230
  if (children.length)
225
231
  this.load(children); // don't load empty
226
232
  }
233
+ // if (this.engine.nodes.length) this._updateStyles(); // update based on # of children. done in engine onChange CB
227
234
  this.setAnimation(this.opts.animate);
228
- this._updateStyles();
229
- this.el.classList.add('gs-' + this.opts.column);
230
235
  // dynamic grids require pausing during drag to detect over to nest vs push
231
236
  if (this.opts.subGridDynamic && !dd_manager_1.DDManager.pauseDrag)
232
237
  dd_manager_1.DDManager.pauseDrag = true;
@@ -252,6 +257,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
252
257
  GridStack.init = function (options, elOrString) {
253
258
  if (options === void 0) { options = {}; }
254
259
  if (elOrString === void 0) { elOrString = '.grid-stack'; }
260
+ if (typeof document === 'undefined')
261
+ return null; // temp workaround SSR
255
262
  var el = GridStack.getGridElement(elOrString);
256
263
  if (!el) {
257
264
  if (typeof elOrString === 'string') {
@@ -281,6 +288,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
281
288
  if (options === void 0) { options = {}; }
282
289
  if (selector === void 0) { selector = '.grid-stack'; }
283
290
  var grids = [];
291
+ if (typeof document === 'undefined')
292
+ return grids; // temp workaround SSR
284
293
  GridStack.getGridElements(selector).forEach(function (el) {
285
294
  if (!el.gridstack) {
286
295
  el.gridstack = new GridStack(el, utils_1.Utils.cloneDeep(options));
@@ -429,6 +438,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
429
438
  * @param el gridItem element to convert
430
439
  * @param ops (optional) sub-grid options, else default to node, then parent settings, else defaults
431
440
  * @param nodeToAdd (optional) node to add to the newly created sub grid (used when dragging over existing regular item)
441
+ * @param saveContent if true (default) the html inside .grid-stack-content will be saved to child widget
432
442
  * @returns newly created grid
433
443
  */
434
444
  GridStack.prototype.makeSubGrid = function (el, ops, nodeToAdd, saveContent) {
@@ -448,7 +458,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
448
458
  grid = (_c = grid.parentGridItem) === null || _c === void 0 ? void 0 : _c.grid;
449
459
  }
450
460
  //... and set the create options
451
- ops = utils_1.Utils.cloneDeep(__assign(__assign(__assign({}, (subGridTemplate || {})), { children: undefined }), (ops || node.subGridOpts)));
461
+ ops = utils_1.Utils.cloneDeep(__assign(__assign(__assign({}, (subGridTemplate || {})), { children: undefined }), (ops || node.subGridOpts || {})));
452
462
  node.subGridOpts = ops;
453
463
  // if column special case it set, remember that flag and set default
454
464
  var autoColumn;
@@ -644,6 +654,10 @@ var GridStack = exports.GridStack = /** @class */ (function () {
644
654
  GridStack.addRemoveCB = addRemove;
645
655
  var removed = [];
646
656
  this.batchUpdate();
657
+ // if we are blank (loading into empty like startup) temp remove animation
658
+ var noAnim = !this.engine.nodes.length;
659
+ if (noAnim)
660
+ this.setAnimation(false);
647
661
  // see if any items are missing from new layout and need to be removed first
648
662
  if (addRemove) {
649
663
  var copyNodes = __spreadArray([], this.engine.nodes, true); // don't loop through array you modify
@@ -669,22 +683,20 @@ var GridStack = exports.GridStack = /** @class */ (function () {
669
683
  } // remove if found from list
670
684
  return true;
671
685
  });
672
- var widthChanged = false;
673
686
  items.forEach(function (w) {
674
687
  var _a;
675
688
  var item = utils_1.Utils.find(updateNodes, w.id);
676
689
  if (item) {
677
- // 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)
690
+ // 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)
678
691
  if (utils_1.Utils.shouldSizeToContent(item))
679
692
  w.h = item.h;
680
693
  // check if missing coord, in which case find next empty slot with new (or old if missing) sizes
681
- _this.engine.nodeBoundFix(w); // before widthChanged is checked below...
694
+ _this.engine.nodeBoundFix(w);
682
695
  if (w.autoPosition || w.x === undefined || w.y === undefined) {
683
696
  w.w = w.w || item.w;
684
697
  w.h = w.h || item.h;
685
698
  _this.engine.findEmptyPosition(w);
686
699
  }
687
- widthChanged = widthChanged || (w.w !== undefined && w.w !== item.w);
688
700
  // 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
689
701
  _this.engine.nodes.push(item);
690
702
  if (utils_1.Utils.samePos(item, w)) {
@@ -704,12 +716,14 @@ var GridStack = exports.GridStack = /** @class */ (function () {
704
716
  }
705
717
  });
706
718
  this.engine.removedNodes = removed;
707
- this.doContentResize(widthChanged, true); // we only need to wait for animation if we changed any widths
708
719
  this.batchUpdate(false);
709
720
  // after commit, clear that flag
710
721
  delete this._ignoreLayoutsNodeChange;
711
722
  delete this._insertNotAppend;
712
723
  prevCB ? GridStack.addRemoveCB = prevCB : delete GridStack.addRemoveCB;
724
+ // delay adding animation back
725
+ if (noAnim && this.opts.animate)
726
+ setTimeout(function () { return _this.setAnimation(_this.opts.animate); });
713
727
  return this;
714
728
  };
715
729
  /**
@@ -736,11 +750,25 @@ var GridStack = exports.GridStack = /** @class */ (function () {
736
750
  (!forcePixel || !this.opts.cellHeightUnit || this.opts.cellHeightUnit === 'px')) {
737
751
  return this.opts.cellHeight;
738
752
  }
753
+ // do rem/em/cm/mm to px conversion
754
+ if (this.opts.cellHeightUnit === 'rem') {
755
+ return this.opts.cellHeight * parseFloat(getComputedStyle(document.documentElement).fontSize);
756
+ }
757
+ if (this.opts.cellHeightUnit === 'em') {
758
+ return this.opts.cellHeight * parseFloat(getComputedStyle(this.el).fontSize);
759
+ }
760
+ if (this.opts.cellHeightUnit === 'cm') {
761
+ // 1cm = 96px/2.54. See https://www.w3.org/TR/css-values-3/#absolute-lengths
762
+ return this.opts.cellHeight * (96 / 2.54);
763
+ }
764
+ if (this.opts.cellHeightUnit === 'mm') {
765
+ return this.opts.cellHeight * (96 / 2.54) / 10;
766
+ }
739
767
  // else get first cell height
740
768
  var el = this.el.querySelector('.' + this.opts.itemClass);
741
769
  if (el) {
742
- var height = utils_1.Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
743
- return Math.round(el.offsetHeight / height);
770
+ var h = utils_1.Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
771
+ return Math.round(el.offsetHeight / h);
744
772
  }
745
773
  // else do entire grid and # of rows (but doesn't work if min-height is the actual constrain)
746
774
  var rows = parseInt(this.el.getAttribute('gs-current-row'));
@@ -784,7 +812,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
784
812
  }
785
813
  this.opts.cellHeightUnit = data.unit;
786
814
  this.opts.cellHeight = data.h;
787
- this.doContentResize(false, true); // no anim wait, but use attributes since we only change row height
815
+ this.resizeToContentCheck();
788
816
  if (update) {
789
817
  this._updateStyles(true); // true = force re-create for current # of rows
790
818
  }
@@ -866,10 +894,10 @@ var GridStack = exports.GridStack = /** @class */ (function () {
866
894
  // update the items now, checking if we have a custom children layout
867
895
  /*const newChildren = this.opts.columnOpts?.breakpoints?.find(r => r.c === column)?.children;
868
896
  if (newChildren) this.load(newChildren);
869
- else*/ this.engine.columnChanged(oldColumn, column, undefined, layout);
897
+ else*/ this.engine.columnChanged(oldColumn, column, layout);
870
898
  if (this._isAutoCellHeight)
871
899
  this.cellHeight();
872
- this.doContentResize();
900
+ this.resizeToContentCheck(true); // wait for width resizing
873
901
  // and trigger our event last...
874
902
  this._ignoreLayoutsNodeChange = true; // skip layout update
875
903
  this._triggerChangeEvent();
@@ -994,7 +1022,6 @@ var GridStack = exports.GridStack = /** @class */ (function () {
994
1022
  this._prepareElement(el, true, options);
995
1023
  var node = el.gridstackNode;
996
1024
  this._updateContainerHeight();
997
- this.doContentResize(false, false, node);
998
1025
  // see if there is a sub-grid to create
999
1026
  if (node.subGridOpts) {
1000
1027
  this.makeSubGrid(el, node.subGridOpts, undefined, false); // node.subGrid will be used as option in method, no need to pass
@@ -1009,22 +1036,6 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1009
1036
  delete this._ignoreLayoutsNodeChange;
1010
1037
  return el;
1011
1038
  };
1012
- /**
1013
- * Event handler that extracts our CustomEvent data out automatically for receiving custom
1014
- * notifications (see doc for supported events)
1015
- * @param name of the event (see possible values) or list of names space separated
1016
- * @param callback function called with event and optional second/third param
1017
- * (see README documentation for each signature).
1018
- *
1019
- * @example
1020
- * grid.on('added', function(e, items) { log('added ', items)} );
1021
- * or
1022
- * grid.on('added removed change', function(e, items) { log(e.type, items)} );
1023
- *
1024
- * Note: in some cases it is the same as calling native handler and parsing the event.
1025
- * grid.el.addEventListener('added', function(event) { log('added ', event.detail)} );
1026
- *
1027
- */
1028
1039
  GridStack.prototype.on = function (name, callback) {
1029
1040
  var _this = this;
1030
1041
  // check for array of names being passed instead
@@ -1051,13 +1062,13 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1051
1062
  this._gsEventHandler[name] = callback;
1052
1063
  }
1053
1064
  else {
1054
- console.log('GridStack.on(' + name + ') event not supported');
1065
+ console.error('GridStack.on(' + name + ') event not supported');
1055
1066
  }
1056
1067
  return this;
1057
1068
  };
1058
1069
  /**
1059
- * unsubscribe from the 'on' event below
1060
- * @param name of the event (see possible values)
1070
+ * unsubscribe from the 'on' event GridStackEvent
1071
+ * @param name of the event (see possible values) or list of names space separated
1061
1072
  */
1062
1073
  GridStack.prototype.off = function (name) {
1063
1074
  var _this = this;
@@ -1148,6 +1159,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1148
1159
  }
1149
1160
  return this;
1150
1161
  };
1162
+ /** @internal */
1163
+ GridStack.prototype.hasAnimationCSS = function () { return this.el.classList.contains('grid-stack-animate'); };
1151
1164
  /**
1152
1165
  * Toggle the grid static state, which permanently removes/add Drag&Drop support, unlike disable()/enable() that just turns it off/on.
1153
1166
  * Also toggle the grid-stack-static class.
@@ -1238,8 +1251,11 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1238
1251
  }
1239
1252
  utils_1.Utils.sanitizeMinMax(n);
1240
1253
  // finally move the widget and update attr
1241
- if (m)
1254
+ if (m) {
1255
+ var widthChanged = (m.w !== undefined && m.w !== n.w);
1242
1256
  _this.moveNode(n, m);
1257
+ _this.resizeToContentCheck(widthChanged, n); // wait for animation if we changed width
1258
+ }
1243
1259
  if (m || changed) {
1244
1260
  _this._writeAttr(el, n);
1245
1261
  }
@@ -1260,10 +1276,10 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1260
1276
  /**
1261
1277
  * Updates widget height to match the content height to avoid v-scrollbar or dead space.
1262
1278
  * 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.
1263
- * 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
1279
+ * @param el grid item element
1280
+ * @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
1264
1281
  */
1265
- GridStack.prototype.resizeToContent = function (el, useAttrSize) {
1266
- if (useAttrSize === void 0) { useAttrSize = false; }
1282
+ GridStack.prototype.resizeToContent = function (el) {
1267
1283
  if (!el)
1268
1284
  return;
1269
1285
  el.classList.remove('size-to-content-max');
@@ -1273,14 +1289,12 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1273
1289
  if (!n)
1274
1290
  return;
1275
1291
  var grid = n.grid;
1276
- if (!grid)
1277
- return;
1278
- if (el.parentElement !== grid.el)
1292
+ if (!grid || el.parentElement !== grid.el)
1279
1293
  return; // skip if we are not inside a grid
1280
- var cell = grid.getCellHeight();
1294
+ var cell = grid.getCellHeight(true);
1281
1295
  if (!cell)
1282
1296
  return;
1283
- var height = useAttrSize && n.h ? n.h * cell : el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1297
+ var height = n.h ? n.h * cell : el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1284
1298
  var item;
1285
1299
  if (n.resizeToContentParent)
1286
1300
  item = el.querySelector(n.resizeToContentParent);
@@ -1289,17 +1303,17 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1289
1303
  if (!item)
1290
1304
  return;
1291
1305
  var padding = el.clientHeight - item.clientHeight; // full - available height to our child (minus border, padding...)
1292
- 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)
1306
+ 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)
1293
1307
  var wantedH;
1294
1308
  if (n.subGrid) {
1295
1309
  // sub-grid - use their actual row count * their cell height
1296
- wantedH = n.subGrid.getRow() * n.subGrid.getCellHeight();
1310
+ wantedH = n.subGrid.getRow() * n.subGrid.getCellHeight(true);
1297
1311
  }
1298
1312
  else {
1299
1313
  // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1300
1314
  var child = item.firstElementChild;
1301
1315
  if (!child) {
1302
- console.log("Error: resizeToContent() '".concat(GridStack.resizeToContentParent, "'.firstElementChild is null, make sure to have a div like container. Skipping sizing."));
1316
+ console.error("Error: GridStack.resizeToContent() widget id:".concat(n.id, " '").concat(GridStack.resizeToContentParent, "'.firstElementChild is null, make sure to have a div like container. Skipping sizing."));
1303
1317
  return;
1304
1318
  }
1305
1319
  wantedH = child.getBoundingClientRect().height || itemH;
@@ -1325,12 +1339,11 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1325
1339
  }
1326
1340
  };
1327
1341
  /** call the user resize (so they can do extra work) else our build in version */
1328
- GridStack.prototype.resizeToContentCheck = function (el, useAttr) {
1329
- if (useAttr === void 0) { useAttr = false; }
1342
+ GridStack.prototype.resizeToContentCBCheck = function (el) {
1330
1343
  if (GridStack.resizeToContentCB)
1331
- GridStack.resizeToContentCB(el, useAttr);
1344
+ GridStack.resizeToContentCB(el);
1332
1345
  else
1333
- this.resizeToContent(el, useAttr);
1346
+ this.resizeToContent(el);
1334
1347
  };
1335
1348
  /**
1336
1349
  * 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).
@@ -1425,7 +1438,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1425
1438
  /** @internal called to delete the current dynamic style sheet used for our layout */
1426
1439
  GridStack.prototype._removeStylesheet = function () {
1427
1440
  if (this._styles) {
1428
- utils_1.Utils.removeStylesheet(this._styleSheetClass);
1441
+ var styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode;
1442
+ utils_1.Utils.removeStylesheet(this._styleSheetClass, styleLocation);
1429
1443
  delete this._styles;
1430
1444
  }
1431
1445
  return this;
@@ -1437,7 +1451,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1437
1451
  if (forceUpdate) {
1438
1452
  this._removeStylesheet();
1439
1453
  }
1440
- if (!maxH)
1454
+ if (maxH === undefined)
1441
1455
  maxH = this.getRow();
1442
1456
  this._updateContainerHeight();
1443
1457
  // if user is telling us they will handle the CSS themselves by setting heights to 0. Do we need this opts really ??
@@ -1469,6 +1483,8 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1469
1483
  utils_1.Utils.addCSSRule(this._styles, content, "top: ".concat(top_1, "; right: ").concat(right, "; bottom: ").concat(bottom, "; left: ").concat(left, ";"));
1470
1484
  utils_1.Utils.addCSSRule(this._styles, placeholder, "top: ".concat(top_1, "; right: ").concat(right, "; bottom: ").concat(bottom, "; left: ").concat(left, ";"));
1471
1485
  // resize handles offset (to match margin)
1486
+ utils_1.Utils.addCSSRule(this._styles, "".concat(prefix, " > .ui-resizable-n"), "top: ".concat(top_1, ";"));
1487
+ utils_1.Utils.addCSSRule(this._styles, "".concat(prefix, " > .ui-resizable-s"), "bottom: ".concat(bottom));
1472
1488
  utils_1.Utils.addCSSRule(this._styles, "".concat(prefix, " > .ui-resizable-ne"), "right: ".concat(right));
1473
1489
  utils_1.Utils.addCSSRule(this._styles, "".concat(prefix, " > .ui-resizable-e"), "right: ".concat(right));
1474
1490
  utils_1.Utils.addCSSRule(this._styles, "".concat(prefix, " > .ui-resizable-se"), "right: ".concat(right, "; bottom: ").concat(bottom));
@@ -1517,26 +1533,25 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1517
1533
  }
1518
1534
  // if we're a nested grid inside an sizeToContent item, tell it to resize itself too
1519
1535
  if (parent && !parent.grid.engine.batchMode && utils_1.Utils.shouldSizeToContent(parent)) {
1520
- parent.grid.resizeToContentCheck(parent.el);
1536
+ parent.grid.resizeToContentCBCheck(parent.el);
1521
1537
  }
1522
1538
  return this;
1523
1539
  };
1524
1540
  /** @internal */
1525
1541
  GridStack.prototype._prepareElement = function (el, triggerAddEvent, node) {
1526
1542
  if (triggerAddEvent === void 0) { triggerAddEvent = false; }
1527
- el.classList.add(this.opts.itemClass);
1528
1543
  node = node || this._readAttr(el);
1529
1544
  el.gridstackNode = node;
1530
1545
  node.el = el;
1531
1546
  node.grid = this;
1532
- var copy = __assign({}, node);
1533
1547
  node = this.engine.addNode(node, triggerAddEvent);
1534
- // write node attr back in case there was collision or we have to fix bad values during addNode()
1535
- if (!utils_1.Utils.same(node, copy)) {
1536
- this._writeAttr(el, node);
1537
- }
1538
- if (utils_1.Utils.shouldSizeToContent(node))
1539
- 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);
1540
1555
  this._prepareDragDropByNode(node);
1541
1556
  return this;
1542
1557
  };
@@ -1666,38 +1681,38 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1666
1681
  n.subGrid.onResize();
1667
1682
  });
1668
1683
  if (!this._skipInitialResize)
1669
- 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)
1670
1685
  delete this._skipInitialResize;
1671
1686
  this.batchUpdate(false);
1672
1687
  return this;
1673
1688
  };
1674
- 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) {
1675
1691
  var _this = this;
1676
- if (delay === void 0) { delay = true; }
1677
- if (useAttr === void 0) { useAttr = false; }
1692
+ if (delay === void 0) { delay = false; }
1678
1693
  if (n === void 0) { n = undefined; }
1694
+ if (!this.engine)
1695
+ return; // we've been deleted in between!
1679
1696
  // update any gridItem height with sizeToContent, but wait for DOM $animation_speed to settle if we changed column count
1680
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 ?
1681
- setTimeout(function () {
1682
- if (!_this.engine)
1683
- return; // we've been deleted in between!
1684
- 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) {
1685
1708
  if (utils_1.Utils.shouldSizeToContent(n))
1686
- _this.resizeToContentCheck(n.el, useAttr);
1687
- }
1688
- else if (_this.engine.nodes.some(function (n) { return utils_1.Utils.shouldSizeToContent(n); })) {
1689
- var nodes = __spreadArray([], _this.engine.nodes, true); // in case order changes while resizing one
1690
- _this.batchUpdate();
1691
- nodes.forEach(function (n) {
1692
- if (utils_1.Utils.shouldSizeToContent(n))
1693
- _this.resizeToContentCheck(n.el, useAttr);
1694
- });
1695
- _this.batchUpdate(false);
1696
- }
1697
- // call this regardless of shouldSizeToContent because widget might need to stretch to take available space after a resize
1698
- if (_this._gsEventHandler['resizecontent'])
1699
- _this._gsEventHandler['resizecontent'](null, n ? [n] : _this.engine.nodes);
1700
- }, 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);
1701
1716
  };
1702
1717
  /** add or remove the grid element size event handler */
1703
1718
  GridStack.prototype._updateResizeEvent = function (forceRemove) {
@@ -1956,15 +1971,32 @@ var GridStack = exports.GridStack = /** @class */ (function () {
1956
1971
  var cellHeight, cellWidth;
1957
1972
  var onDrag = function (event, el, helper) {
1958
1973
  var _a;
1974
+ var _b;
1959
1975
  var node = el.gridstackNode;
1960
1976
  if (!node)
1961
1977
  return;
1962
1978
  helper = helper || el;
1979
+ // if the element is being dragged from outside, scale it down to match the grid's scale
1980
+ // and slightly adjust its position relative to the mouse
1981
+ if (!((_b = node.grid) === null || _b === void 0 ? void 0 : _b.el)) {
1982
+ // this scales the helper down
1983
+ helper.style.transform = "scale(".concat(1 / _this.dragTransform.xScale, ",").concat(1 / _this.dragTransform.yScale, ")");
1984
+ // this makes it so that the helper is well positioned relative to the mouse after scaling
1985
+ var helperRect = helper.getBoundingClientRect();
1986
+ helper.style.left = helperRect.x + (_this.dragTransform.xScale - 1) * (event.clientX - helperRect.x) / _this.dragTransform.xScale + 'px';
1987
+ helper.style.top = helperRect.y + (_this.dragTransform.yScale - 1) * (event.clientY - helperRect.y) / _this.dragTransform.yScale + 'px';
1988
+ helper.style.transformOrigin = "0px 0px";
1989
+ }
1963
1990
  var parent = _this.el.getBoundingClientRect();
1964
1991
  var top = (_a = helper.getBoundingClientRect(), _a.top), left = _a.left;
1965
1992
  left -= parent.left;
1966
1993
  top -= parent.top;
1967
- var ui = { position: { top: top, left: left } };
1994
+ var ui = {
1995
+ position: {
1996
+ top: top * _this.dragTransform.xScale,
1997
+ left: left * _this.dragTransform.yScale
1998
+ }
1999
+ };
1968
2000
  if (node._temporaryRemoved) {
1969
2001
  node.x = Math.max(0, Math.round(left / cellWidth));
1970
2002
  node.y = Math.max(0, Math.round(top / cellHeight));
@@ -2106,6 +2138,10 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2106
2138
  return false;
2107
2139
  var wasAdded = !!_this.placeholder.parentElement; // skip items not actually added to us because of constrains, but do cleanup #1419
2108
2140
  _this.placeholder.remove();
2141
+ // disable animation when replacing a placeholder (already positioned) with actual content
2142
+ var noAnim = wasAdded && _this.opts.animate;
2143
+ if (noAnim)
2144
+ _this.setAnimation(false);
2109
2145
  // notify previous grid of removal
2110
2146
  // console.log('drop delete _gridstackNodeOrig') // TEST
2111
2147
  var origNode = el._gridstackNodeOrig;
@@ -2150,15 +2186,13 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2150
2186
  // @ts-ignore
2151
2187
  utils_1.Utils.copyPos(node, _this._readAttr(_this.placeholder)); // placeholder values as moving VERY fast can throw things off #1578
2152
2188
  utils_1.Utils.removePositioningStyles(el); // @ts-ignore
2153
- _this._writeAttr(el, node);
2154
- el.classList.add(types_1.gridDefaults.itemClass, _this.opts.itemClass);
2155
2189
  _this.el.appendChild(el); // @ts-ignore // TODO: now would be ideal time to _removeHelperStyle() overriding floating styles (native only)
2190
+ _this._prepareElement(el, true, node);
2156
2191
  if (subGrid) {
2157
2192
  subGrid.parentGridItem = node;
2158
2193
  if (!subGrid.opts.styleInHead)
2159
2194
  subGrid._updateStyles(true); // re-create sub-grid styles now that we've moved
2160
2195
  }
2161
- _this._prepareDragDropByNode(node);
2162
2196
  _this._updateContainerHeight();
2163
2197
  _this.engine.addedNodes.push(node); // @ts-ignore
2164
2198
  _this._triggerAddEvent(); // @ts-ignore
@@ -2167,6 +2201,9 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2167
2201
  if (_this._gsEventHandler['dropped']) {
2168
2202
  _this._gsEventHandler['dropped'](__assign(__assign({}, event), { type: 'dropped' }), origNode && origNode.grid ? origNode : undefined, node);
2169
2203
  }
2204
+ // delay adding animation back
2205
+ if (noAnim)
2206
+ setTimeout(function () { return _this.setAnimation(_this.opts.animate); });
2170
2207
  return false; // prevent parent from receiving msg (which may be grid as well)
2171
2208
  });
2172
2209
  return this;
@@ -2236,6 +2273,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2236
2273
  delete node._moving;
2237
2274
  delete node._event;
2238
2275
  delete node._lastTried;
2276
+ var widthChanged = node.w !== node._orig.w;
2239
2277
  // if the item has moved to another grid, we're done here
2240
2278
  var target = event.target;
2241
2279
  if (!target.gridstackNode || target.gridstackNode.grid !== _this)
@@ -2273,7 +2311,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2273
2311
  if (event.type === 'resizestop') {
2274
2312
  if (Number.isInteger(node.sizeToContent))
2275
2313
  node.sizeToContent = node.h; // new soft limit
2276
- _this.doContentResize(false, true, node); // no amin wait as will use the actual sized coordinate attr
2314
+ _this.resizeToContentCheck(widthChanged, node); // wait for width animation if changed
2277
2315
  }
2278
2316
  };
2279
2317
  dd.draggable(el, {
@@ -2294,12 +2332,33 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2294
2332
  };
2295
2333
  /** @internal handles actual drag/resize start */
2296
2334
  GridStack.prototype._onStartMoving = function (el, event, ui, node, cellWidth, cellHeight) {
2335
+ var _a;
2297
2336
  this.engine.cleanNodes()
2298
2337
  .beginUpdate(node);
2299
2338
  // @ts-ignore
2300
2339
  this._writePosAttr(this.placeholder, node);
2301
2340
  this.el.appendChild(this.placeholder);
2302
2341
  // console.log('_onStartMoving placeholder') // TEST
2342
+ // if the element is inside a grid, it has already been scaled
2343
+ // we can use that as a scale reference
2344
+ if ((_a = node.grid) === null || _a === void 0 ? void 0 : _a.el) {
2345
+ this.dragTransform = utils_1.Utils.getValuesFromTransformedElement(el);
2346
+ }
2347
+ // if the element is being dragged from outside (not from any grid)
2348
+ // we use the grid as the transformation reference, since the helper is not subject to transformation
2349
+ else if (this.placeholder && this.placeholder.closest('.grid-stack')) {
2350
+ var gridEl = this.placeholder.closest('.grid-stack');
2351
+ this.dragTransform = utils_1.Utils.getValuesFromTransformedElement(gridEl);
2352
+ }
2353
+ // Fallback
2354
+ else {
2355
+ this.dragTransform = {
2356
+ xScale: 1,
2357
+ xOffset: 0,
2358
+ yScale: 1,
2359
+ yOffset: 0,
2360
+ };
2361
+ }
2303
2362
  node.el = this.placeholder;
2304
2363
  node._lastUiPosition = ui.position;
2305
2364
  node._prevYPix = ui.position.top;
@@ -2416,6 +2475,9 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2416
2475
  var node = el.gridstackNode;
2417
2476
  if (!node)
2418
2477
  return;
2478
+ helper = helper || el;
2479
+ // restore the scale of the helper on leave
2480
+ helper.style.transform = 'scale(1)';
2419
2481
  dd.off(el, 'drag'); // no need to track while being outside
2420
2482
  // this gets called when cursor leaves and shape is outside, so only do this once
2421
2483
  if (node._temporaryRemoved)
@@ -2449,7 +2511,7 @@ var GridStack = exports.GridStack = /** @class */ (function () {
2449
2511
  GridStack.Utils = utils_1.Utils;
2450
2512
  /** scoping so users can call new GridStack.Engine(12) for example */
2451
2513
  GridStack.Engine = gridstack_engine_1.GridStackEngine;
2452
- GridStack.GDRev = '10.0.0';
2514
+ GridStack.GDRev = '10.1.0';
2453
2515
  return GridStack;
2454
2516
  }());
2455
2517
  //# sourceMappingURL=gridstack.js.map