gridstack 10.0.1 → 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 +12 -7
  85. package/dist/es5/gridstack.js +68 -27
  86. package/dist/es5/gridstack.js.map +1 -1
  87. package/dist/es5/types.d.ts +1 -1
  88. package/dist/es5/types.js +1 -1
  89. package/dist/es5/types.js.map +1 -1
  90. package/dist/es5/utils.d.ts +12 -1
  91. package/dist/es5/utils.js +28 -2
  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 +12 -7
  101. package/dist/gridstack.js +67 -28
  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 +1 -1
  106. package/dist/types.js +1 -1
  107. package/dist/types.js.map +1 -1
  108. package/dist/utils.d.ts +12 -1
  109. package/dist/utils.js +28 -2
  110. package/dist/utils.js.map +1 -1
  111. package/doc/CHANGES.md +12 -0
  112. package/doc/README.md +1 -1
  113. package/package.json +1 -1
package/dist/gridstack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GridStack 10.0.1
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,8 @@ 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 };
158
164
  el.gridstack = this;
159
165
  this.el = el; // exposed HTML element to the user
160
166
  opts = opts || {}; // handles null/undefined/0
@@ -180,7 +186,7 @@ class GridStack {
180
186
  const oldOpts = opts;
181
187
  if (oldOpts.oneColumnModeDomSort) {
182
188
  delete oldOpts.oneColumnModeDomSort;
183
- 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.');
184
190
  }
185
191
  if (oldOpts.oneColumnSize || oldOpts.disableOneColumnMode === false) {
186
192
  const oneSize = oldOpts.oneColumnSize || 768;
@@ -390,6 +396,7 @@ class GridStack {
390
396
  * @param el gridItem element to convert
391
397
  * @param ops (optional) sub-grid options, else default to node, then parent settings, else defaults
392
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
393
400
  * @returns newly created grid
394
401
  */
395
402
  makeSubGrid(el, ops, nodeToAdd, saveContent = true) {
@@ -407,7 +414,7 @@ class GridStack {
407
414
  grid = grid.parentGridItem?.grid;
408
415
  }
409
416
  //... and set the create options
410
- ops = Utils.cloneDeep({ ...(subGridTemplate || {}), children: undefined, ...(ops || node.subGridOpts) });
417
+ ops = Utils.cloneDeep({ ...(subGridTemplate || {}), children: undefined, ...(ops || node.subGridOpts || {}) });
411
418
  node.subGridOpts = ops;
412
419
  // if column special case it set, remember that flag and set default
413
420
  let autoColumn;
@@ -688,13 +695,20 @@ class GridStack {
688
695
  (!forcePixel || !this.opts.cellHeightUnit || this.opts.cellHeightUnit === 'px')) {
689
696
  return this.opts.cellHeight;
690
697
  }
691
- // do rem/em to px conversion
698
+ // do rem/em/cm/mm to px conversion
692
699
  if (this.opts.cellHeightUnit === 'rem') {
693
700
  return this.opts.cellHeight * parseFloat(getComputedStyle(document.documentElement).fontSize);
694
701
  }
695
702
  if (this.opts.cellHeightUnit === 'em') {
696
703
  return this.opts.cellHeight * parseFloat(getComputedStyle(this.el).fontSize);
697
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
+ }
698
712
  // else get first cell height
699
713
  let el = this.el.querySelector('.' + this.opts.itemClass);
700
714
  if (el) {
@@ -818,7 +832,7 @@ class GridStack {
818
832
  // update the items now, checking if we have a custom children layout
819
833
  /*const newChildren = this.opts.columnOpts?.breakpoints?.find(r => r.c === column)?.children;
820
834
  if (newChildren) this.load(newChildren);
821
- else*/ this.engine.columnChanged(oldColumn, column, undefined, layout);
835
+ else*/ this.engine.columnChanged(oldColumn, column, layout);
822
836
  if (this._isAutoCellHeight)
823
837
  this.cellHeight();
824
838
  this.resizeToContentCheck(true); // wait for width resizing
@@ -957,22 +971,6 @@ class GridStack {
957
971
  delete this._ignoreLayoutsNodeChange;
958
972
  return el;
959
973
  }
960
- /**
961
- * Event handler that extracts our CustomEvent data out automatically for receiving custom
962
- * notifications (see doc for supported events)
963
- * @param name of the event (see possible values) or list of names space separated
964
- * @param callback function called with event and optional second/third param
965
- * (see README documentation for each signature).
966
- *
967
- * @example
968
- * grid.on('added', function(e, items) { log('added ', items)} );
969
- * or
970
- * grid.on('added removed change', function(e, items) { log(e.type, items)} );
971
- *
972
- * Note: in some cases it is the same as calling native handler and parsing the event.
973
- * grid.el.addEventListener('added', function(event) { log('added ', event.detail)} );
974
- *
975
- */
976
974
  on(name, callback) {
977
975
  // check for array of names being passed instead
978
976
  if (name.indexOf(' ') !== -1) {
@@ -998,13 +996,13 @@ class GridStack {
998
996
  this._gsEventHandler[name] = callback;
999
997
  }
1000
998
  else {
1001
- console.log('GridStack.on(' + name + ') event not supported');
999
+ console.error('GridStack.on(' + name + ') event not supported');
1002
1000
  }
1003
1001
  return this;
1004
1002
  }
1005
1003
  /**
1006
- * unsubscribe from the 'on' event below
1007
- * @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
1008
1006
  */
1009
1007
  off(name) {
1010
1008
  // check for array of names being passed instead
@@ -1024,7 +1022,7 @@ class GridStack {
1024
1022
  }
1025
1023
  /** remove all event handlers */
1026
1024
  offAll() {
1027
- Object.keys(this._gsEventHandler).forEach(key => this.off(key));
1025
+ Object.keys(this._gsEventHandler).forEach((key) => this.off(key));
1028
1026
  return this;
1029
1027
  }
1030
1028
  /**
@@ -1237,7 +1235,7 @@ class GridStack {
1237
1235
  // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1238
1236
  const child = item.firstElementChild;
1239
1237
  if (!child) {
1240
- 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.`);
1241
1239
  return;
1242
1240
  }
1243
1241
  wantedH = child.getBoundingClientRect().height || itemH;
@@ -1404,6 +1402,8 @@ class GridStack {
1404
1402
  Utils.addCSSRule(this._styles, content, `top: ${top}; right: ${right}; bottom: ${bottom}; left: ${left};`);
1405
1403
  Utils.addCSSRule(this._styles, placeholder, `top: ${top}; right: ${right}; bottom: ${bottom}; left: ${left};`);
1406
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}`);
1407
1407
  Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-ne`, `right: ${right}`);
1408
1408
  Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-e`, `right: ${right}`);
1409
1409
  Utils.addCSSRule(this._styles, `${prefix} > .ui-resizable-se`, `right: ${right}; bottom: ${bottom}`);
@@ -1868,11 +1868,27 @@ class GridStack {
1868
1868
  if (!node)
1869
1869
  return;
1870
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
+ }
1871
1882
  let parent = this.el.getBoundingClientRect();
1872
1883
  let { top, left } = helper.getBoundingClientRect();
1873
1884
  left -= parent.left;
1874
1885
  top -= parent.top;
1875
- let ui = { position: { top, left } };
1886
+ let ui = {
1887
+ position: {
1888
+ top: top * this.dragTransform.xScale,
1889
+ left: left * this.dragTransform.yScale
1890
+ }
1891
+ };
1876
1892
  if (node._temporaryRemoved) {
1877
1893
  node.x = Math.max(0, Math.round(left / cellWidth));
1878
1894
  node.y = Math.max(0, Math.round(top / cellHeight));
@@ -2211,6 +2227,26 @@ class GridStack {
2211
2227
  this._writePosAttr(this.placeholder, node);
2212
2228
  this.el.appendChild(this.placeholder);
2213
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
+ }
2214
2250
  node.el = this.placeholder;
2215
2251
  node._lastUiPosition = ui.position;
2216
2252
  node._prevYPix = ui.position.top;
@@ -2327,6 +2363,9 @@ class GridStack {
2327
2363
  let node = el.gridstackNode;
2328
2364
  if (!node)
2329
2365
  return;
2366
+ helper = helper || el;
2367
+ // restore the scale of the helper on leave
2368
+ helper.style.transform = 'scale(1)';
2330
2369
  dd.off(el, 'drag'); // no need to track while being outside
2331
2370
  // this gets called when cursor leaves and shape is outside, so only do this once
2332
2371
  if (node._temporaryRemoved)
@@ -2361,6 +2400,6 @@ GridStack.resizeToContentParent = '.grid-stack-item-content';
2361
2400
  GridStack.Utils = Utils;
2362
2401
  /** scoping so users can call new GridStack.Engine(12) for example */
2363
2402
  GridStack.Engine = GridStackEngine;
2364
- GridStack.GDRev = '10.0.1';
2403
+ GridStack.GDRev = '10.1.0';
2365
2404
  export { GridStack };
2366
2405
  //# sourceMappingURL=gridstack.js.map