gridstack 11.3.0 → 11.5.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 (112) hide show
  1. package/README.md +4 -4
  2. package/dist/angular/README.md +4 -4
  3. package/dist/angular/esm2020/index.mjs +3 -2
  4. package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
  5. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +8 -8
  6. package/dist/angular/esm2020/lib/gridstack.component.mjs +13 -13
  7. package/dist/angular/esm2020/lib/gridstack.module.mjs +10 -10
  8. package/dist/angular/esm2020/lib/types.mjs +6 -0
  9. package/dist/angular/fesm2015/gridstack-angular.mjs +57 -57
  10. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  11. package/dist/angular/fesm2020/gridstack-angular.mjs +62 -57
  12. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  13. package/dist/angular/index.d.ts +2 -1
  14. package/dist/angular/lib/base-widget.d.ts +1 -1
  15. package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
  16. package/dist/angular/lib/gridstack.component.d.ts +7 -25
  17. package/dist/angular/lib/gridstack.module.d.ts +3 -3
  18. package/dist/angular/lib/types.d.ts +24 -0
  19. package/dist/angular/src/base-widget.ts +2 -2
  20. package/dist/angular/src/gridstack-item.component.ts +4 -4
  21. package/dist/angular/src/gridstack.component.ts +15 -34
  22. package/dist/angular/src/gridstack.module.ts +4 -4
  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 +2 -2
  28. package/dist/dd-draggable.js.map +1 -1
  29. package/dist/dd-droppable.d.ts +1 -1
  30. package/dist/dd-droppable.js +1 -1
  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 +10 -13
  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 +1 -1
  43. package/dist/dd-resizable-handle.js.map +1 -1
  44. package/dist/dd-resizable.d.ts +1 -1
  45. package/dist/dd-resizable.js +1 -1
  46. package/dist/dd-resizable.js.map +1 -1
  47. package/dist/dd-touch.d.ts +1 -1
  48. package/dist/dd-touch.js +4 -39
  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 +2 -2
  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 +1 -1
  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 +10 -14
  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 +1 -1
  70. package/dist/es5/dd-resizable-handle.js.map +1 -1
  71. package/dist/es5/dd-resizable.d.ts +1 -1
  72. package/dist/es5/dd-resizable.js +1 -1
  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 +4 -39
  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 -9
  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 +17 -3
  85. package/dist/es5/gridstack.js +126 -34
  86. package/dist/es5/gridstack.js.map +1 -1
  87. package/dist/es5/types.d.ts +2 -2
  88. package/dist/es5/types.js +1 -1
  89. package/dist/es5/types.js.map +1 -1
  90. package/dist/es5/utils.d.ts +5 -5
  91. package/dist/es5/utils.js +24 -42
  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 -9
  98. package/dist/gridstack-engine.js.map +1 -1
  99. package/dist/gridstack.css +1 -1
  100. package/dist/gridstack.d.ts +17 -3
  101. package/dist/gridstack.js +122 -34
  102. package/dist/gridstack.js.map +1 -1
  103. package/dist/src/gridstack.scss +1 -1
  104. package/dist/types.d.ts +2 -2
  105. package/dist/types.js +1 -1
  106. package/dist/types.js.map +1 -1
  107. package/dist/utils.d.ts +5 -5
  108. package/dist/utils.js +23 -40
  109. package/dist/utils.js.map +1 -1
  110. package/doc/CHANGES.md +19 -0
  111. package/doc/README.md +10 -4
  112. package/package.json +1 -1
package/dist/gridstack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GridStack 11.3.0
2
+ * GridStack 11.5.0
3
3
  * https://gridstackjs.com/
4
4
  *
5
5
  * Copyright (c) 2021-2024 Alain Dumesny
@@ -355,7 +355,7 @@ class GridStack {
355
355
  el = GridStack.addRemoveCB(this.el, w, true, false);
356
356
  }
357
357
  else {
358
- el = Utils.createWidgetDivs(this.opts.itemClass, node);
358
+ el = this.createWidgetDivs(node);
359
359
  }
360
360
  if (!el)
361
361
  return;
@@ -374,6 +374,27 @@ class GridStack {
374
374
  this.makeWidget(el, w);
375
375
  return el;
376
376
  }
377
+ /** create the default grid item divs, and content (possibly lazy loaded) by using GridStack.renderCB() */
378
+ createWidgetDivs(n) {
379
+ const el = Utils.createDiv(['grid-stack-item', this.opts.itemClass]);
380
+ const cont = Utils.createDiv(['grid-stack-item-content'], el);
381
+ if (Utils.lazyLoad(n)) {
382
+ if (!n.visibleObservable) {
383
+ n.visibleObservable = new IntersectionObserver(([entry]) => {
384
+ if (entry.isIntersecting) {
385
+ n.visibleObservable?.disconnect();
386
+ delete n.visibleObservable;
387
+ GridStack.renderCB(cont, n);
388
+ n.grid?.prepareDragDrop(n.el);
389
+ }
390
+ });
391
+ window.setTimeout(() => n.visibleObservable?.observe(el)); // wait until callee sets position attributes
392
+ }
393
+ }
394
+ else
395
+ GridStack.renderCB(cont, n);
396
+ return el;
397
+ }
377
398
  /**
378
399
  * Convert an existing gridItem element into a sub-grid with the given (optional) options, else inherit them
379
400
  * from the parent's subGrid options.
@@ -433,7 +454,7 @@ class GridStack {
433
454
  newItem.appendChild(content);
434
455
  content = Utils.createDiv(['grid-stack-item-content'], node.el);
435
456
  }
436
- this._prepareDragDropByNode(node); // ... and restore original D&D
457
+ this.prepareDragDrop(node.el); // ... and restore original D&D
437
458
  }
438
459
  // if we're adding an additional item, make the container large enough to have them both
439
460
  if (nodeToAdd) {
@@ -562,8 +583,8 @@ class GridStack {
562
583
  /**
563
584
  * load the widgets from a list. This will call update() on each (matching by id) or add/remove widgets that are not there.
564
585
  *
565
- * @param layout list of widgets definition to update/create
566
- * @param addAndRemove boolean (default true) or callback method can be passed to control if and how missing widgets can be added/removed, giving
586
+ * @param items list of widgets definition to update/create
587
+ * @param addRemove boolean (default true) or callback method can be passed to control if and how missing widgets can be added/removed, giving
567
588
  * the user control of insertion.
568
589
  *
569
590
  * @example
@@ -1117,7 +1138,7 @@ class GridStack {
1117
1138
  this._setupRemoveDrop();
1118
1139
  this._setupAcceptWidget();
1119
1140
  this.engine.nodes.forEach(n => {
1120
- this._prepareDragDropByNode(n); // either delete or init Drag&drop
1141
+ this.prepareDragDrop(n.el); // either delete or init Drag&drop
1121
1142
  if (n.subGrid && recurse)
1122
1143
  n.subGrid.setStatic(val, updateClass, recurse);
1123
1144
  });
@@ -1126,26 +1147,64 @@ class GridStack {
1126
1147
  }
1127
1148
  return this;
1128
1149
  }
1150
+ /**
1151
+ * Updates the passed in options on the grid (similar to update(widget) for for the grid options).
1152
+ * @param options PARTIAL grid options to update - only items specified will be updated.
1153
+ * NOTE: not all options updating are currently supported (lot of code, unlikely to change)
1154
+ */
1155
+ updateOptions(o) {
1156
+ const opts = this.opts;
1157
+ if (o.acceptWidgets !== undefined)
1158
+ this._setupAcceptWidget();
1159
+ if (o.animate !== undefined)
1160
+ this.setAnimation();
1161
+ if (o.cellHeight) {
1162
+ this.cellHeight(o.cellHeight, true);
1163
+ delete o.cellHeight;
1164
+ }
1165
+ if (o.class && o.class !== opts.class) {
1166
+ if (opts.class)
1167
+ this.el.classList.remove(opts.class);
1168
+ this.el.classList.add(o.class);
1169
+ }
1170
+ if (typeof (o.column) === 'number' && !o.columnOpts) {
1171
+ this.column(o.column);
1172
+ delete o.column;
1173
+ } // responsive column take over actual count
1174
+ if (o.margin !== undefined)
1175
+ this.margin(o.margin);
1176
+ if (o.staticGrid !== undefined)
1177
+ this.setStatic(o.staticGrid);
1178
+ if (o.disableDrag !== undefined && !o.staticGrid)
1179
+ this.enableMove(!o.disableDrag);
1180
+ if (o.disableResize !== undefined && !o.staticGrid)
1181
+ this.enableResize(!o.disableResize);
1182
+ if (o.float !== undefined)
1183
+ this.float(o.float);
1184
+ if (o.row !== undefined) {
1185
+ opts.minRow = opts.maxRow = o.row;
1186
+ }
1187
+ if (o.children?.length) {
1188
+ this.load(o.children);
1189
+ delete o.children;
1190
+ }
1191
+ // TBD if we have a real need for these (more complex code)
1192
+ // alwaysShowResizeHandle, draggable, handle, handleClass, itemClass, layout, placeholderClass, placeholderText, resizable, removable, row,...
1193
+ // rest are just copied over...
1194
+ this.opts = { ...this.opts, ...o };
1195
+ return this;
1196
+ }
1129
1197
  /**
1130
1198
  * Updates widget position/size and other info. Note: if you need to call this on all nodes, use load() instead which will update what changed.
1131
1199
  * @param els widget or selector of objects to modify (note: setting the same x,y for multiple items will be indeterministic and likely unwanted)
1132
1200
  * @param opt new widget options (x,y,w,h, etc..). Only those set will be updated.
1133
1201
  */
1134
1202
  update(els, opt) {
1135
- // support legacy call for now ?
1136
- if (arguments.length > 2) {
1137
- console.warn('gridstack.ts: `update(el, x, y, w, h)` is deprecated. Use `update(el, {x, w, content, ...})`. It will be removed soon');
1138
- // eslint-disable-next-line prefer-rest-params
1139
- const a = arguments;
1140
- let i = 1;
1141
- opt = { x: a[i++], y: a[i++], w: a[i++], h: a[i++] };
1142
- return this.update(els, opt);
1143
- }
1144
1203
  GridStack.getElements(els).forEach(el => {
1145
1204
  const n = el?.gridstackNode;
1146
1205
  if (!n)
1147
1206
  return;
1148
- const w = Utils.cloneDeep(opt); // make a copy we can modify in case they re-use it or multiple items
1207
+ const w = { ...Utils.copyPos({}, n), ...Utils.cloneDeep(opt) }; // make a copy we can modify in case they re-use it or multiple items
1149
1208
  this.engine.nodeBoundFix(w);
1150
1209
  delete w.autoPosition;
1151
1210
  // move/resize widget if anything changed
@@ -1205,7 +1264,7 @@ class GridStack {
1205
1264
  this._writeAttr(el, n);
1206
1265
  }
1207
1266
  if (ddChanged) {
1208
- this._prepareDragDropByNode(n);
1267
+ this.prepareDragDrop(n.el);
1209
1268
  }
1210
1269
  });
1211
1270
  return this;
@@ -1531,7 +1590,8 @@ class GridStack {
1531
1590
  sizeToContent ? el.classList.add('size-to-content') : el.classList.remove('size-to-content');
1532
1591
  if (sizeToContent)
1533
1592
  this.resizeToContentCheck(false, node);
1534
- this._prepareDragDropByNode(node);
1593
+ if (!Utils.lazyLoad(node))
1594
+ this.prepareDragDrop(node.el);
1535
1595
  return this;
1536
1596
  }
1537
1597
  /** @internal call to write position x,y,w,h attributes back to element */
@@ -1580,7 +1640,13 @@ class GridStack {
1580
1640
  n.noResize = Utils.toBool(el.getAttribute('gs-no-resize'));
1581
1641
  n.noMove = Utils.toBool(el.getAttribute('gs-no-move'));
1582
1642
  n.locked = Utils.toBool(el.getAttribute('gs-locked'));
1583
- n.sizeToContent = Utils.toBool(el.getAttribute('gs-size-to-content'));
1643
+ const attr = el.getAttribute('gs-size-to-content');
1644
+ if (attr) {
1645
+ if (attr === 'true' || attr === 'false')
1646
+ n.sizeToContent = Utils.toBool(attr);
1647
+ else
1648
+ n.sizeToContent = parseInt(attr, 10);
1649
+ }
1584
1650
  n.id = el.getAttribute('gs-id');
1585
1651
  // read but never written out
1586
1652
  n.maxW = Utils.toNumber(el.getAttribute('gs-max-w'));
@@ -1602,11 +1668,11 @@ class GridStack {
1602
1668
  if (n.minH)
1603
1669
  el.removeAttribute('gs-min-h');
1604
1670
  }
1605
- // remove any key not found (null or false which is default)
1671
+ // remove any key not found (null or false which is default, unless sizeToContent=false override)
1606
1672
  for (const key in n) {
1607
1673
  if (!n.hasOwnProperty(key))
1608
1674
  return;
1609
- if (!n[key] && n[key] !== 0) { // 0 can be valid value (x,y only really)
1675
+ if (!n[key] && n[key] !== 0 && key !== 'gs-size-to-content') { // 0 can be valid value (x,y only really)
1610
1676
  delete n[key];
1611
1677
  }
1612
1678
  }
@@ -1824,7 +1890,7 @@ class GridStack {
1824
1890
  if (!n)
1825
1891
  return;
1826
1892
  val ? delete n.noMove : n.noMove = true;
1827
- this._prepareDragDropByNode(n); // init DD if need be, and adjust
1893
+ this.prepareDragDrop(n.el); // init DD if need be, and adjust
1828
1894
  });
1829
1895
  return this;
1830
1896
  }
@@ -1841,7 +1907,7 @@ class GridStack {
1841
1907
  if (!n)
1842
1908
  return;
1843
1909
  val ? delete n.noResize : n.noResize = true;
1844
- this._prepareDragDropByNode(n); // init DD if need be, and adjust
1910
+ this.prepareDragDrop(n.el); // init DD if need be, and adjust
1845
1911
  });
1846
1912
  return this;
1847
1913
  }
@@ -1889,7 +1955,7 @@ class GridStack {
1889
1955
  return this; // can't move a static grid!
1890
1956
  doEnable ? delete this.opts.disableDrag : this.opts.disableDrag = true; // FIRST before we update children as grid overrides #1658
1891
1957
  this.engine.nodes.forEach(n => {
1892
- this._prepareDragDropByNode(n);
1958
+ this.prepareDragDrop(n.el);
1893
1959
  if (n.subGrid && recurse)
1894
1960
  n.subGrid.enableMove(doEnable, recurse);
1895
1961
  });
@@ -1904,7 +1970,7 @@ class GridStack {
1904
1970
  return this; // can't size a static grid!
1905
1971
  doEnable ? delete this.opts.disableResize : this.opts.disableResize = true; // FIRST before we update children as grid overrides #1658
1906
1972
  this.engine.nodes.forEach(n => {
1907
- this._prepareDragDropByNode(n);
1973
+ this.prepareDragDrop(n.el);
1908
1974
  if (n.subGrid && recurse)
1909
1975
  n.subGrid.enableResize(doEnable, recurse);
1910
1976
  });
@@ -2032,6 +2098,11 @@ class GridStack {
2032
2098
  // delete node._added; // reset this to track placeholder again in case we were over other grid #1484 (dropout doesn't always clear)
2033
2099
  return false; // prevent parent from receiving msg (which may be a grid as well)
2034
2100
  }
2101
+ // If sidebar item, restore the sidebar node size to ensure consistent behavior when dragging between grids
2102
+ if (node?._sidebarOrig) {
2103
+ node.w = node._sidebarOrig.w;
2104
+ node.h = node._sidebarOrig.h;
2105
+ }
2035
2106
  // fix #1578 when dragging fast, we may not get a leave on the previous grid so force one now
2036
2107
  if (node?.grid && node.grid !== this && !node._temporaryRemoved) {
2037
2108
  // console.log('dropover without leave'); // TEST
@@ -2042,7 +2113,7 @@ class GridStack {
2042
2113
  // cache cell dimensions (which don't change), position can animate if we removed an item in otherGrid that affects us...
2043
2114
  cellWidth = this.cellWidth();
2044
2115
  cellHeight = this.getCellHeight(true);
2045
- // sidebar items: load any element attributes if we don't have a node
2116
+ // sidebar items: load any element attributes if we don't have a node on first enter from the sidebar
2046
2117
  if (!node) {
2047
2118
  const attr = helper.getAttribute('data-gs-widget') || helper.getAttribute('gridstacknode'); // TBD: temp support for old V11.0.0 attribute
2048
2119
  if (attr) {
@@ -2057,6 +2128,8 @@ class GridStack {
2057
2128
  }
2058
2129
  if (!node)
2059
2130
  node = this._readAttr(helper); // used to pass false for #2354, but now we clone top level node
2131
+ // On first grid enter from sidebar, set the initial sidebar item size properties for the node
2132
+ node._sidebarOrig = { w: node.w, h: node.h };
2060
2133
  }
2061
2134
  if (!node.grid) { // sidebar item
2062
2135
  if (!node.el)
@@ -2225,19 +2298,28 @@ class GridStack {
2225
2298
  }
2226
2299
  return this;
2227
2300
  }
2228
- /** @internal prepares the element for drag&drop */
2229
- _prepareDragDropByNode(node) {
2230
- const el = node.el;
2301
+ /**
2302
+ * prepares the element for drag&drop - this is normally called by makeWidget() unless are are delay loading
2303
+ * @param el GridItemHTMLElement of the widget
2304
+ * @param [force=false]
2305
+ * */
2306
+ prepareDragDrop(el, force = false) {
2307
+ const node = el?.gridstackNode;
2308
+ if (!node)
2309
+ return;
2231
2310
  const noMove = node.noMove || this.opts.disableDrag;
2232
2311
  const noResize = node.noResize || this.opts.disableResize;
2233
2312
  // check for disabled grid first
2234
- if (this.opts.staticGrid || (noMove && noResize)) {
2313
+ const disable = node.locked || this.opts.staticGrid || (noMove && noResize);
2314
+ if (force || disable) {
2235
2315
  if (node._initDD) {
2236
2316
  this._removeDD(el); // nukes everything instead of just disable, will add some styles back next
2237
2317
  delete node._initDD;
2238
2318
  }
2239
- el.classList.add('ui-draggable-disabled', 'ui-resizable-disabled'); // add styles one might depend on #1435
2240
- return this;
2319
+ if (disable) {
2320
+ el.classList.add('ui-draggable-disabled', 'ui-resizable-disabled'); // add styles one might depend on #1435
2321
+ return this;
2322
+ }
2241
2323
  }
2242
2324
  if (!node._initDD) {
2243
2325
  // variables used/cashed between the 3 start/move/end methods, in addition to node passed above
@@ -2452,7 +2534,10 @@ class GridStack {
2452
2534
  this._extraDragRow = 0; // @ts-ignore
2453
2535
  this._updateContainerHeight();
2454
2536
  const target = event.target; // @ts-ignore
2455
- this._writePosAttr(target, node);
2537
+ // Do not write sidebar item attributes back to the original sidebar el
2538
+ if (!node._sidebarOrig) {
2539
+ this._writePosAttr(target, node);
2540
+ }
2456
2541
  if (this._gsEventHandler[event.type]) {
2457
2542
  this._gsEventHandler[event.type](event, target);
2458
2543
  }
@@ -2476,8 +2561,11 @@ class GridStack {
2476
2561
  node._temporaryRemoved = true;
2477
2562
  this.engine.removeNode(node); // remove placeholder as well, otherwise it's a sign node is not in our list, which is a bigger issue
2478
2563
  node.el = node._isExternal && helper ? helper : el; // point back to real item being dragged
2564
+ const sidebarOrig = node._sidebarOrig;
2479
2565
  if (node._isExternal)
2480
2566
  this.engine.cleanupNode(node);
2567
+ // Restore sidebar item initial size info to stay consistent when dragging between multiple grids
2568
+ node._sidebarOrig = sidebarOrig;
2481
2569
  if (this.opts.removable === true) { // boolean vs a class string
2482
2570
  // item leaving us and we are supposed to remove on leave (no need to drag onto trash) mark it so
2483
2571
  GridStack._itemRemoving(el, true);
@@ -2508,6 +2596,6 @@ GridStack.resizeToContentParent = '.grid-stack-item-content';
2508
2596
  GridStack.Utils = Utils;
2509
2597
  /** scoping so users can call new GridStack.Engine(12) for example */
2510
2598
  GridStack.Engine = GridStackEngine;
2511
- GridStack.GDRev = '11.3.0';
2599
+ GridStack.GDRev = '11.5.0';
2512
2600
  export { GridStack };
2513
2601
  //# sourceMappingURL=gridstack.js.map