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
package/dist/gridstack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GridStack 10.0.0
2
+ * GridStack 10.1.0
3
3
  * https://gridstackjs.com/
4
4
  *
5
5
  * Copyright (c) 2021-2022 Alain Dumesny
@@ -48,6 +48,8 @@ class GridStack {
48
48
  * let grid = document.querySelector('.grid-stack').gridstack;
49
49
  */
50
50
  static init(options = {}, elOrString = '.grid-stack') {
51
+ if (typeof document === 'undefined')
52
+ return null; // temp workaround SSR
51
53
  let el = GridStack.getGridElement(elOrString);
52
54
  if (!el) {
53
55
  if (typeof elOrString === 'string') {
@@ -75,6 +77,8 @@ class GridStack {
75
77
  */
76
78
  static initAll(options = {}, selector = '.grid-stack') {
77
79
  let grids = [];
80
+ if (typeof document === 'undefined')
81
+ return grids; // temp workaround SSR
78
82
  GridStack.getGridElements(selector).forEach(el => {
79
83
  if (!el.gridstack) {
80
84
  el.gridstack = new GridStack(el, Utils.cloneDeep(options));
@@ -155,6 +159,9 @@ class GridStack {
155
159
  this._gsEventHandler = {};
156
160
  /** @internal extra row added when dragging at the bottom of the grid */
157
161
  this._extraDragRow = 0;
162
+ /** @internal meant to store the scale of the active grid */
163
+ this.dragTransform = { xScale: 1, yScale: 1, xOffset: 0, yOffset: 0 };
164
+ el.gridstack = this;
158
165
  this.el = el; // exposed HTML element to the user
159
166
  opts = opts || {}; // handles null/undefined/0
160
167
  if (!el.classList.contains('grid-stack')) {
@@ -179,7 +186,7 @@ class GridStack {
179
186
  const oldOpts = opts;
180
187
  if (oldOpts.oneColumnModeDomSort) {
181
188
  delete oldOpts.oneColumnModeDomSort;
182
- console.log('Error: Gridstack oneColumnModeDomSort no longer supported. Check GridStackOptions.columnOpts instead.');
189
+ console.log('warning: Gridstack oneColumnModeDomSort no longer supported. Use GridStackOptions.columnOpts instead.');
183
190
  }
184
191
  if (oldOpts.oneColumnSize || oldOpts.disableOneColumnMode === false) {
185
192
  const oneSize = oldOpts.oneColumnSize || 768;
@@ -231,6 +238,7 @@ class GridStack {
231
238
  this._initMargin(); // part of settings defaults...
232
239
  // 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)
233
240
  this.checkDynamicColumn();
241
+ this.el.classList.add('gs-' + this.opts.column);
234
242
  if (this.opts.rtl === 'auto') {
235
243
  this.opts.rtl = (el.style.direction === 'rtl');
236
244
  }
@@ -290,6 +298,8 @@ class GridStack {
290
298
  this._updateStyles(false, maxH); // false = don't recreate, just append if need be
291
299
  }
292
300
  });
301
+ // create initial global styles BEFORE loading children so resizeToContent margin can be calculated correctly
302
+ this._updateStyles(false, 0);
293
303
  if (this.opts.auto) {
294
304
  this.batchUpdate(); // prevent in between re-layout #1535 TODO: this only set float=true, need to prevent collision check...
295
305
  this.getGridItems().forEach(el => this._prepareElement(el));
@@ -302,9 +312,8 @@ class GridStack {
302
312
  if (children.length)
303
313
  this.load(children); // don't load empty
304
314
  }
315
+ // if (this.engine.nodes.length) this._updateStyles(); // update based on # of children. done in engine onChange CB
305
316
  this.setAnimation(this.opts.animate);
306
- this._updateStyles();
307
- this.el.classList.add('gs-' + this.opts.column);
308
317
  // dynamic grids require pausing during drag to detect over to nest vs push
309
318
  if (this.opts.subGridDynamic && !DDManager.pauseDrag)
310
319
  DDManager.pauseDrag = true;
@@ -387,6 +396,7 @@ class GridStack {
387
396
  * @param el gridItem element to convert
388
397
  * @param ops (optional) sub-grid options, else default to node, then parent settings, else defaults
389
398
  * @param nodeToAdd (optional) node to add to the newly created sub grid (used when dragging over existing regular item)
399
+ * @param saveContent if true (default) the html inside .grid-stack-content will be saved to child widget
390
400
  * @returns newly created grid
391
401
  */
392
402
  makeSubGrid(el, ops, nodeToAdd, saveContent = true) {
@@ -404,7 +414,7 @@ class GridStack {
404
414
  grid = grid.parentGridItem?.grid;
405
415
  }
406
416
  //... and set the create options
407
- ops = Utils.cloneDeep({ ...(subGridTemplate || {}), children: undefined, ...(ops || node.subGridOpts) });
417
+ ops = Utils.cloneDeep({ ...(subGridTemplate || {}), children: undefined, ...(ops || node.subGridOpts || {}) });
408
418
  node.subGridOpts = ops;
409
419
  // if column special case it set, remember that flag and set default
410
420
  let autoColumn;
@@ -592,6 +602,10 @@ class GridStack {
592
602
  GridStack.addRemoveCB = addRemove;
593
603
  let removed = [];
594
604
  this.batchUpdate();
605
+ // if we are blank (loading into empty like startup) temp remove animation
606
+ const noAnim = !this.engine.nodes.length;
607
+ if (noAnim)
608
+ this.setAnimation(false);
595
609
  // see if any items are missing from new layout and need to be removed first
596
610
  if (addRemove) {
597
611
  let copyNodes = [...this.engine.nodes]; // don't loop through array you modify
@@ -617,21 +631,19 @@ class GridStack {
617
631
  } // remove if found from list
618
632
  return true;
619
633
  });
620
- let widthChanged = false;
621
634
  items.forEach(w => {
622
635
  let item = Utils.find(updateNodes, w.id);
623
636
  if (item) {
624
- // 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)
637
+ // 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)
625
638
  if (Utils.shouldSizeToContent(item))
626
639
  w.h = item.h;
627
640
  // check if missing coord, in which case find next empty slot with new (or old if missing) sizes
628
- this.engine.nodeBoundFix(w); // before widthChanged is checked below...
641
+ this.engine.nodeBoundFix(w);
629
642
  if (w.autoPosition || w.x === undefined || w.y === undefined) {
630
643
  w.w = w.w || item.w;
631
644
  w.h = w.h || item.h;
632
645
  this.engine.findEmptyPosition(w);
633
646
  }
634
- widthChanged = widthChanged || (w.w !== undefined && w.w !== item.w);
635
647
  // 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
636
648
  this.engine.nodes.push(item);
637
649
  if (Utils.samePos(item, w)) {
@@ -651,12 +663,14 @@ class GridStack {
651
663
  }
652
664
  });
653
665
  this.engine.removedNodes = removed;
654
- this.doContentResize(widthChanged, true); // we only need to wait for animation if we changed any widths
655
666
  this.batchUpdate(false);
656
667
  // after commit, clear that flag
657
668
  delete this._ignoreLayoutsNodeChange;
658
669
  delete this._insertNotAppend;
659
670
  prevCB ? GridStack.addRemoveCB = prevCB : delete GridStack.addRemoveCB;
671
+ // delay adding animation back
672
+ if (noAnim && this.opts.animate)
673
+ setTimeout(() => this.setAnimation(this.opts.animate));
660
674
  return this;
661
675
  }
662
676
  /**
@@ -681,11 +695,25 @@ class GridStack {
681
695
  (!forcePixel || !this.opts.cellHeightUnit || this.opts.cellHeightUnit === 'px')) {
682
696
  return this.opts.cellHeight;
683
697
  }
698
+ // do rem/em/cm/mm to px conversion
699
+ if (this.opts.cellHeightUnit === 'rem') {
700
+ return this.opts.cellHeight * parseFloat(getComputedStyle(document.documentElement).fontSize);
701
+ }
702
+ if (this.opts.cellHeightUnit === 'em') {
703
+ return this.opts.cellHeight * parseFloat(getComputedStyle(this.el).fontSize);
704
+ }
705
+ if (this.opts.cellHeightUnit === 'cm') {
706
+ // 1cm = 96px/2.54. See https://www.w3.org/TR/css-values-3/#absolute-lengths
707
+ return this.opts.cellHeight * (96 / 2.54);
708
+ }
709
+ if (this.opts.cellHeightUnit === 'mm') {
710
+ return this.opts.cellHeight * (96 / 2.54) / 10;
711
+ }
684
712
  // else get first cell height
685
713
  let el = this.el.querySelector('.' + this.opts.itemClass);
686
714
  if (el) {
687
- let height = Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
688
- return Math.round(el.offsetHeight / height);
715
+ let h = Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
716
+ return Math.round(el.offsetHeight / h);
689
717
  }
690
718
  // else do entire grid and # of rows (but doesn't work if min-height is the actual constrain)
691
719
  let rows = parseInt(this.el.getAttribute('gs-current-row'));
@@ -728,7 +756,7 @@ class GridStack {
728
756
  }
729
757
  this.opts.cellHeightUnit = data.unit;
730
758
  this.opts.cellHeight = data.h;
731
- this.doContentResize(false, true); // no anim wait, but use attributes since we only change row height
759
+ this.resizeToContentCheck();
732
760
  if (update) {
733
761
  this._updateStyles(true); // true = force re-create for current # of rows
734
762
  }
@@ -804,10 +832,10 @@ class GridStack {
804
832
  // update the items now, checking if we have a custom children layout
805
833
  /*const newChildren = this.opts.columnOpts?.breakpoints?.find(r => r.c === column)?.children;
806
834
  if (newChildren) this.load(newChildren);
807
- else*/ this.engine.columnChanged(oldColumn, column, undefined, layout);
835
+ else*/ this.engine.columnChanged(oldColumn, column, layout);
808
836
  if (this._isAutoCellHeight)
809
837
  this.cellHeight();
810
- this.doContentResize();
838
+ this.resizeToContentCheck(true); // wait for width resizing
811
839
  // and trigger our event last...
812
840
  this._ignoreLayoutsNodeChange = true; // skip layout update
813
841
  this._triggerChangeEvent();
@@ -929,7 +957,6 @@ class GridStack {
929
957
  this._prepareElement(el, true, options);
930
958
  const node = el.gridstackNode;
931
959
  this._updateContainerHeight();
932
- this.doContentResize(false, false, node);
933
960
  // see if there is a sub-grid to create
934
961
  if (node.subGridOpts) {
935
962
  this.makeSubGrid(el, node.subGridOpts, undefined, false); // node.subGrid will be used as option in method, no need to pass
@@ -944,22 +971,6 @@ class GridStack {
944
971
  delete this._ignoreLayoutsNodeChange;
945
972
  return el;
946
973
  }
947
- /**
948
- * Event handler that extracts our CustomEvent data out automatically for receiving custom
949
- * notifications (see doc for supported events)
950
- * @param name of the event (see possible values) or list of names space separated
951
- * @param callback function called with event and optional second/third param
952
- * (see README documentation for each signature).
953
- *
954
- * @example
955
- * grid.on('added', function(e, items) { log('added ', items)} );
956
- * or
957
- * grid.on('added removed change', function(e, items) { log(e.type, items)} );
958
- *
959
- * Note: in some cases it is the same as calling native handler and parsing the event.
960
- * grid.el.addEventListener('added', function(event) { log('added ', event.detail)} );
961
- *
962
- */
963
974
  on(name, callback) {
964
975
  // check for array of names being passed instead
965
976
  if (name.indexOf(' ') !== -1) {
@@ -985,13 +996,13 @@ class GridStack {
985
996
  this._gsEventHandler[name] = callback;
986
997
  }
987
998
  else {
988
- console.log('GridStack.on(' + name + ') event not supported');
999
+ console.error('GridStack.on(' + name + ') event not supported');
989
1000
  }
990
1001
  return this;
991
1002
  }
992
1003
  /**
993
- * unsubscribe from the 'on' event below
994
- * @param name of the event (see possible values)
1004
+ * unsubscribe from the 'on' event GridStackEvent
1005
+ * @param name of the event (see possible values) or list of names space separated
995
1006
  */
996
1007
  off(name) {
997
1008
  // check for array of names being passed instead
@@ -1011,7 +1022,7 @@ class GridStack {
1011
1022
  }
1012
1023
  /** remove all event handlers */
1013
1024
  offAll() {
1014
- Object.keys(this._gsEventHandler).forEach(key => this.off(key));
1025
+ Object.keys(this._gsEventHandler).forEach((key) => this.off(key));
1015
1026
  return this;
1016
1027
  }
1017
1028
  /**
@@ -1075,6 +1086,8 @@ class GridStack {
1075
1086
  }
1076
1087
  return this;
1077
1088
  }
1089
+ /** @internal */
1090
+ hasAnimationCSS() { return this.el.classList.contains('grid-stack-animate'); }
1078
1091
  /**
1079
1092
  * Toggle the grid static state, which permanently removes/add Drag&Drop support, unlike disable()/enable() that just turns it off/on.
1080
1093
  * Also toggle the grid-stack-static class.
@@ -1160,8 +1173,11 @@ class GridStack {
1160
1173
  }
1161
1174
  Utils.sanitizeMinMax(n);
1162
1175
  // finally move the widget and update attr
1163
- if (m)
1176
+ if (m) {
1177
+ const widthChanged = (m.w !== undefined && m.w !== n.w);
1164
1178
  this.moveNode(n, m);
1179
+ this.resizeToContentCheck(widthChanged, n); // wait for animation if we changed width
1180
+ }
1165
1181
  if (m || changed) {
1166
1182
  this._writeAttr(el, n);
1167
1183
  }
@@ -1182,26 +1198,25 @@ class GridStack {
1182
1198
  /**
1183
1199
  * Updates widget height to match the content height to avoid v-scrollbar or dead space.
1184
1200
  * 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.
1185
- * 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
1201
+ * @param el grid item element
1202
+ * @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
1186
1203
  */
1187
- resizeToContent(el, useAttrSize = false) {
1204
+ resizeToContent(el) {
1188
1205
  if (!el)
1189
1206
  return;
1190
1207
  el.classList.remove('size-to-content-max');
1191
1208
  if (!el.clientHeight)
1192
1209
  return; // 0 when hidden, skip
1193
- let n = el.gridstackNode;
1210
+ const n = el.gridstackNode;
1194
1211
  if (!n)
1195
1212
  return;
1196
1213
  const grid = n.grid;
1197
- if (!grid)
1198
- return;
1199
- if (el.parentElement !== grid.el)
1214
+ if (!grid || el.parentElement !== grid.el)
1200
1215
  return; // skip if we are not inside a grid
1201
- const cell = grid.getCellHeight();
1216
+ const cell = grid.getCellHeight(true);
1202
1217
  if (!cell)
1203
1218
  return;
1204
- let height = useAttrSize && n.h ? n.h * cell : el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1219
+ let height = n.h ? n.h * cell : el.clientHeight; // getBoundingClientRect().height seem to flicker back and forth
1205
1220
  let item;
1206
1221
  if (n.resizeToContentParent)
1207
1222
  item = el.querySelector(n.resizeToContentParent);
@@ -1210,17 +1225,17 @@ class GridStack {
1210
1225
  if (!item)
1211
1226
  return;
1212
1227
  const padding = el.clientHeight - item.clientHeight; // full - available height to our child (minus border, padding...)
1213
- const itemH = useAttrSize && n.h ? n.h * cell - padding : item.clientHeight; // calculated to what cellHeight is or will become (rather than actual to prevent waiting for animation to finish)
1228
+ const itemH = n.h ? n.h * cell - padding : item.clientHeight; // calculated to what cellHeight is or will become (rather than actual to prevent waiting for animation to finish)
1214
1229
  let wantedH;
1215
1230
  if (n.subGrid) {
1216
1231
  // sub-grid - use their actual row count * their cell height
1217
- wantedH = n.subGrid.getRow() * n.subGrid.getCellHeight();
1232
+ wantedH = n.subGrid.getRow() * n.subGrid.getCellHeight(true);
1218
1233
  }
1219
1234
  else {
1220
1235
  // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1221
1236
  const child = item.firstElementChild;
1222
1237
  if (!child) {
1223
- console.log(`Error: resizeToContent() '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`);
1238
+ console.error(`Error: GridStack.resizeToContent() widget id:${n.id} '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`);
1224
1239
  return;
1225
1240
  }
1226
1241
  wantedH = child.getBoundingClientRect().height || itemH;
@@ -1246,11 +1261,11 @@ class GridStack {
1246
1261
  }
1247
1262
  }
1248
1263
  /** call the user resize (so they can do extra work) else our build in version */
1249
- resizeToContentCheck(el, useAttr = false) {
1264
+ resizeToContentCBCheck(el) {
1250
1265
  if (GridStack.resizeToContentCB)
1251
- GridStack.resizeToContentCB(el, useAttr);
1266
+ GridStack.resizeToContentCB(el);
1252
1267
  else
1253
- this.resizeToContent(el, useAttr);
1268
+ this.resizeToContent(el);
1254
1269
  }
1255
1270
  /**
1256
1271
  * 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).
@@ -1343,7 +1358,8 @@ class GridStack {
1343
1358
  /** @internal called to delete the current dynamic style sheet used for our layout */
1344
1359
  _removeStylesheet() {
1345
1360
  if (this._styles) {
1346
- Utils.removeStylesheet(this._styleSheetClass);
1361
+ const styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode;
1362
+ Utils.removeStylesheet(this._styleSheetClass, styleLocation);
1347
1363
  delete this._styles;
1348
1364
  }
1349
1365
  return this;
@@ -1354,7 +1370,7 @@ class GridStack {
1354
1370
  if (forceUpdate) {
1355
1371
  this._removeStylesheet();
1356
1372
  }
1357
- if (!maxH)
1373
+ if (maxH === undefined)
1358
1374
  maxH = this.getRow();
1359
1375
  this._updateContainerHeight();
1360
1376
  // if user is telling us they will handle the CSS themselves by setting heights to 0. Do we need this opts really ??
@@ -1367,7 +1383,7 @@ class GridStack {
1367
1383
  // create one as needed
1368
1384
  if (!this._styles) {
1369
1385
  // insert style to parent (instead of 'head' by default) to support WebComponent
1370
- let styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode;
1386
+ const styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode;
1371
1387
  this._styles = Utils.createStylesheet(this._styleSheetClass, styleLocation, {
1372
1388
  nonce: this.opts.nonce,
1373
1389
  });
@@ -1386,6 +1402,8 @@ class GridStack {
1386
1402
  Utils.addCSSRule(this._styles, content, `top: ${top}; right: ${right}; bottom: ${bottom}; left: ${left};`);
1387
1403
  Utils.addCSSRule(this._styles, placeholder, `top: ${top}; right: ${right}; bottom: ${bottom}; left: ${left};`);
1388
1404
  // resize handles offset (to match margin)
1405
+ Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-n`, `top: ${top};`);
1406
+ Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-s`, `bottom: ${bottom}`);
1389
1407
  Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-ne`, `right: ${right}`);
1390
1408
  Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-e`, `right: ${right}`);
1391
1409
  Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-se`, `right: ${right}; bottom: ${bottom}`);
@@ -1434,25 +1452,24 @@ class GridStack {
1434
1452
  }
1435
1453
  // if we're a nested grid inside an sizeToContent item, tell it to resize itself too
1436
1454
  if (parent && !parent.grid.engine.batchMode && Utils.shouldSizeToContent(parent)) {
1437
- parent.grid.resizeToContentCheck(parent.el);
1455
+ parent.grid.resizeToContentCBCheck(parent.el);
1438
1456
  }
1439
1457
  return this;
1440
1458
  }
1441
1459
  /** @internal */
1442
1460
  _prepareElement(el, triggerAddEvent = false, node) {
1443
- el.classList.add(this.opts.itemClass);
1444
1461
  node = node || this._readAttr(el);
1445
1462
  el.gridstackNode = node;
1446
1463
  node.el = el;
1447
1464
  node.grid = this;
1448
- let copy = { ...node };
1449
1465
  node = this.engine.addNode(node, triggerAddEvent);
1450
- // write node attr back in case there was collision or we have to fix bad values during addNode()
1451
- if (!Utils.same(node, copy)) {
1452
- this._writeAttr(el, node);
1453
- }
1454
- if (Utils.shouldSizeToContent(node))
1455
- el.classList.add('size-to-content');
1466
+ // write the dom sizes and class
1467
+ this._writeAttr(el, node);
1468
+ el.classList.add(gridDefaults.itemClass, this.opts.itemClass);
1469
+ const sizeToContent = Utils.shouldSizeToContent(node);
1470
+ sizeToContent ? el.classList.add('size-to-content') : el.classList.remove('size-to-content');
1471
+ if (sizeToContent)
1472
+ this.resizeToContentCheck(false, node);
1456
1473
  this._prepareDragDropByNode(node);
1457
1474
  return this;
1458
1475
  }
@@ -1579,34 +1596,35 @@ class GridStack {
1579
1596
  n.subGrid.onResize();
1580
1597
  });
1581
1598
  if (!this._skipInitialResize)
1582
- this.doContentResize(columnChanged); // wait for anim of column changed (DOM reflow before we can size correctly)
1599
+ this.resizeToContentCheck(columnChanged); // wait for anim of column changed (DOM reflow before we can size correctly)
1583
1600
  delete this._skipInitialResize;
1584
1601
  this.batchUpdate(false);
1585
1602
  return this;
1586
1603
  }
1587
- doContentResize(delay = true, useAttr = false, n = undefined) {
1604
+ /** resizes content for given node (or all) if shouldSizeToContent() is true */
1605
+ resizeToContentCheck(delay = false, n = undefined) {
1606
+ if (!this.engine)
1607
+ return; // we've been deleted in between!
1588
1608
  // update any gridItem height with sizeToContent, but wait for DOM $animation_speed to settle if we changed column count
1589
1609
  // 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 ?
1590
- setTimeout(() => {
1591
- if (!this.engine)
1592
- return; // we've been deleted in between!
1593
- if (n) {
1610
+ if (delay && this.hasAnimationCSS())
1611
+ return setTimeout(() => this.resizeToContentCheck(false, n), 300 + 10);
1612
+ if (n) {
1613
+ if (Utils.shouldSizeToContent(n))
1614
+ this.resizeToContentCBCheck(n.el);
1615
+ }
1616
+ else if (this.engine.nodes.some(n => Utils.shouldSizeToContent(n))) {
1617
+ const nodes = [...this.engine.nodes]; // in case order changes while resizing one
1618
+ this.batchUpdate();
1619
+ nodes.forEach(n => {
1594
1620
  if (Utils.shouldSizeToContent(n))
1595
- this.resizeToContentCheck(n.el, useAttr);
1596
- }
1597
- else if (this.engine.nodes.some(n => Utils.shouldSizeToContent(n))) {
1598
- const nodes = [...this.engine.nodes]; // in case order changes while resizing one
1599
- this.batchUpdate();
1600
- nodes.forEach(n => {
1601
- if (Utils.shouldSizeToContent(n))
1602
- this.resizeToContentCheck(n.el, useAttr);
1603
- });
1604
- this.batchUpdate(false);
1605
- }
1606
- // call this regardless of shouldSizeToContent because widget might need to stretch to take available space after a resize
1607
- if (this._gsEventHandler['resizecontent'])
1608
- this._gsEventHandler['resizecontent'](null, n ? [n] : this.engine.nodes);
1609
- }, delay ? 300 + 10 : 0);
1621
+ this.resizeToContentCBCheck(n.el);
1622
+ });
1623
+ this.batchUpdate(false);
1624
+ }
1625
+ // call this regardless of shouldSizeToContent because widget might need to stretch to take available space after a resize
1626
+ if (this._gsEventHandler['resizecontent'])
1627
+ this._gsEventHandler['resizecontent'](null, n ? [n] : this.engine.nodes);
1610
1628
  }
1611
1629
  /** add or remove the grid element size event handler */
1612
1630
  _updateResizeEvent(forceRemove = false) {
@@ -1737,7 +1755,7 @@ class GridStack {
1737
1755
  if (this.opts.staticGrid)
1738
1756
  return this; // can't move a static grid!
1739
1757
  GridStack.getElements(els).forEach(el => {
1740
- let n = el.gridstackNode;
1758
+ const n = el.gridstackNode;
1741
1759
  if (!n)
1742
1760
  return;
1743
1761
  val ? delete n.noMove : n.noMove = true;
@@ -1850,11 +1868,27 @@ class GridStack {
1850
1868
  if (!node)
1851
1869
  return;
1852
1870
  helper = helper || el;
1871
+ // if the element is being dragged from outside, scale it down to match the grid's scale
1872
+ // and slightly adjust its position relative to the mouse
1873
+ if (!node.grid?.el) {
1874
+ // this scales the helper down
1875
+ helper.style.transform = `scale(${1 / this.dragTransform.xScale},${1 / this.dragTransform.yScale})`;
1876
+ // this makes it so that the helper is well positioned relative to the mouse after scaling
1877
+ const helperRect = helper.getBoundingClientRect();
1878
+ helper.style.left = helperRect.x + (this.dragTransform.xScale - 1) * (event.clientX - helperRect.x) / this.dragTransform.xScale + 'px';
1879
+ helper.style.top = helperRect.y + (this.dragTransform.yScale - 1) * (event.clientY - helperRect.y) / this.dragTransform.yScale + 'px';
1880
+ helper.style.transformOrigin = `0px 0px`;
1881
+ }
1853
1882
  let parent = this.el.getBoundingClientRect();
1854
1883
  let { top, left } = helper.getBoundingClientRect();
1855
1884
  left -= parent.left;
1856
1885
  top -= parent.top;
1857
- let ui = { position: { top, left } };
1886
+ let ui = {
1887
+ position: {
1888
+ top: top * this.dragTransform.xScale,
1889
+ left: left * this.dragTransform.yScale
1890
+ }
1891
+ };
1858
1892
  if (node._temporaryRemoved) {
1859
1893
  node.x = Math.max(0, Math.round(left / cellWidth));
1860
1894
  node.y = Math.max(0, Math.round(top / cellHeight));
@@ -1993,8 +2027,12 @@ class GridStack {
1993
2027
  // ignore drop on ourself from ourself that didn't come from the outside - dragend will handle the simple move instead
1994
2028
  if (node?.grid === this && !node._isExternal)
1995
2029
  return false;
1996
- let wasAdded = !!this.placeholder.parentElement; // skip items not actually added to us because of constrains, but do cleanup #1419
2030
+ const wasAdded = !!this.placeholder.parentElement; // skip items not actually added to us because of constrains, but do cleanup #1419
1997
2031
  this.placeholder.remove();
2032
+ // disable animation when replacing a placeholder (already positioned) with actual content
2033
+ const noAnim = wasAdded && this.opts.animate;
2034
+ if (noAnim)
2035
+ this.setAnimation(false);
1998
2036
  // notify previous grid of removal
1999
2037
  // console.log('drop delete _gridstackNodeOrig') // TEST
2000
2038
  let origNode = el._gridstackNodeOrig;
@@ -2039,15 +2077,13 @@ class GridStack {
2039
2077
  // @ts-ignore
2040
2078
  Utils.copyPos(node, this._readAttr(this.placeholder)); // placeholder values as moving VERY fast can throw things off #1578
2041
2079
  Utils.removePositioningStyles(el); // @ts-ignore
2042
- this._writeAttr(el, node);
2043
- el.classList.add(gridDefaults.itemClass, this.opts.itemClass);
2044
2080
  this.el.appendChild(el); // @ts-ignore // TODO: now would be ideal time to _removeHelperStyle() overriding floating styles (native only)
2081
+ this._prepareElement(el, true, node);
2045
2082
  if (subGrid) {
2046
2083
  subGrid.parentGridItem = node;
2047
2084
  if (!subGrid.opts.styleInHead)
2048
2085
  subGrid._updateStyles(true); // re-create sub-grid styles now that we've moved
2049
2086
  }
2050
- this._prepareDragDropByNode(node);
2051
2087
  this._updateContainerHeight();
2052
2088
  this.engine.addedNodes.push(node); // @ts-ignore
2053
2089
  this._triggerAddEvent(); // @ts-ignore
@@ -2056,6 +2092,9 @@ class GridStack {
2056
2092
  if (this._gsEventHandler['dropped']) {
2057
2093
  this._gsEventHandler['dropped']({ ...event, type: 'dropped' }, origNode && origNode.grid ? origNode : undefined, node);
2058
2094
  }
2095
+ // delay adding animation back
2096
+ if (noAnim)
2097
+ setTimeout(() => this.setAnimation(this.opts.animate));
2059
2098
  return false; // prevent parent from receiving msg (which may be grid as well)
2060
2099
  });
2061
2100
  return this;
@@ -2123,6 +2162,7 @@ class GridStack {
2123
2162
  delete node._moving;
2124
2163
  delete node._event;
2125
2164
  delete node._lastTried;
2165
+ const widthChanged = node.w !== node._orig.w;
2126
2166
  // if the item has moved to another grid, we're done here
2127
2167
  let target = event.target;
2128
2168
  if (!target.gridstackNode || target.gridstackNode.grid !== this)
@@ -2160,7 +2200,7 @@ class GridStack {
2160
2200
  if (event.type === 'resizestop') {
2161
2201
  if (Number.isInteger(node.sizeToContent))
2162
2202
  node.sizeToContent = node.h; // new soft limit
2163
- this.doContentResize(false, true, node); // no amin wait as will use the actual sized coordinate attr
2203
+ this.resizeToContentCheck(widthChanged, node); // wait for width animation if changed
2164
2204
  }
2165
2205
  };
2166
2206
  dd.draggable(el, {
@@ -2187,6 +2227,26 @@ class GridStack {
2187
2227
  this._writePosAttr(this.placeholder, node);
2188
2228
  this.el.appendChild(this.placeholder);
2189
2229
  // console.log('_onStartMoving placeholder') // TEST
2230
+ // if the element is inside a grid, it has already been scaled
2231
+ // we can use that as a scale reference
2232
+ if (node.grid?.el) {
2233
+ this.dragTransform = Utils.getValuesFromTransformedElement(el);
2234
+ }
2235
+ // if the element is being dragged from outside (not from any grid)
2236
+ // we use the grid as the transformation reference, since the helper is not subject to transformation
2237
+ else if (this.placeholder && this.placeholder.closest('.grid-stack')) {
2238
+ const gridEl = this.placeholder.closest('.grid-stack');
2239
+ this.dragTransform = Utils.getValuesFromTransformedElement(gridEl);
2240
+ }
2241
+ // Fallback
2242
+ else {
2243
+ this.dragTransform = {
2244
+ xScale: 1,
2245
+ xOffset: 0,
2246
+ yScale: 1,
2247
+ yOffset: 0,
2248
+ };
2249
+ }
2190
2250
  node.el = this.placeholder;
2191
2251
  node._lastUiPosition = ui.position;
2192
2252
  node._prevYPix = ui.position.top;
@@ -2303,6 +2363,9 @@ class GridStack {
2303
2363
  let node = el.gridstackNode;
2304
2364
  if (!node)
2305
2365
  return;
2366
+ helper = helper || el;
2367
+ // restore the scale of the helper on leave
2368
+ helper.style.transform = 'scale(1)';
2306
2369
  dd.off(el, 'drag'); // no need to track while being outside
2307
2370
  // this gets called when cursor leaves and shape is outside, so only do this once
2308
2371
  if (node._temporaryRemoved)
@@ -2337,6 +2400,6 @@ GridStack.resizeToContentParent = '.grid-stack-item-content';
2337
2400
  GridStack.Utils = Utils;
2338
2401
  /** scoping so users can call new GridStack.Engine(12) for example */
2339
2402
  GridStack.Engine = GridStackEngine;
2340
- GridStack.GDRev = '10.0.0';
2403
+ GridStack.GDRev = '10.1.0';
2341
2404
  export { GridStack };
2342
2405
  //# sourceMappingURL=gridstack.js.map