gridstack 12.2.2 → 12.3.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 (71) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -3
  3. package/dist/angular/README.md +2 -0
  4. package/dist/angular/esm2020/lib/base-widget.mjs +63 -7
  5. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +33 -4
  6. package/dist/angular/esm2020/lib/gridstack.component.mjs +97 -16
  7. package/dist/angular/esm2020/lib/gridstack.module.mjs +25 -3
  8. package/dist/angular/esm2020/lib/types.mjs +2 -2
  9. package/dist/angular/fesm2015/gridstack-angular.mjs +191 -25
  10. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  11. package/dist/angular/fesm2020/gridstack-angular.mjs +192 -26
  12. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  13. package/dist/angular/lib/base-widget.d.ts +42 -5
  14. package/dist/angular/lib/gridstack-item.component.d.ts +49 -7
  15. package/dist/angular/lib/gridstack.component.d.ts +137 -22
  16. package/dist/angular/lib/gridstack.module.d.ts +23 -0
  17. package/dist/angular/lib/types.d.ts +32 -5
  18. package/dist/angular/package.json +1 -1
  19. package/dist/angular/src/base-widget.ts +68 -9
  20. package/dist/angular/src/gridstack-item.component.ts +49 -7
  21. package/dist/angular/src/gridstack.component.ts +154 -23
  22. package/dist/angular/src/gridstack.module.ts +24 -2
  23. package/dist/angular/src/types.ts +54 -0
  24. package/dist/dd-base-impl.d.ts +52 -3
  25. package/dist/dd-base-impl.js +41 -3
  26. package/dist/dd-base-impl.js.map +1 -1
  27. package/dist/dd-draggable.d.ts +2 -2
  28. package/dist/dd-draggable.js +4 -2
  29. package/dist/dd-draggable.js.map +1 -1
  30. package/dist/dd-droppable.d.ts +2 -2
  31. package/dist/dd-droppable.js +2 -2
  32. package/dist/dd-droppable.js.map +1 -1
  33. package/dist/dd-element.d.ts +2 -2
  34. package/dist/dd-element.js +2 -2
  35. package/dist/dd-element.js.map +1 -1
  36. package/dist/dd-gridstack.d.ts +54 -6
  37. package/dist/dd-gridstack.js +32 -2
  38. package/dist/dd-gridstack.js.map +1 -1
  39. package/dist/dd-manager.d.ts +29 -8
  40. package/dist/dd-manager.js +7 -3
  41. package/dist/dd-manager.js.map +1 -1
  42. package/dist/dd-resizable-handle.d.ts +2 -2
  43. package/dist/dd-resizable-handle.js +2 -2
  44. package/dist/dd-resizable-handle.js.map +1 -1
  45. package/dist/dd-resizable.d.ts +2 -2
  46. package/dist/dd-resizable.js +2 -2
  47. package/dist/dd-resizable.js.map +1 -1
  48. package/dist/dd-touch.d.ts +2 -2
  49. package/dist/dd-touch.js +2 -2
  50. package/dist/dd-touch.js.map +1 -1
  51. package/dist/gridstack-all.js +1 -1
  52. package/dist/gridstack-all.js.LICENSE.txt +2 -2
  53. package/dist/gridstack-all.js.map +1 -1
  54. package/dist/gridstack-engine.d.ts +235 -26
  55. package/dist/gridstack-engine.js +275 -29
  56. package/dist/gridstack-engine.js.map +1 -1
  57. package/dist/gridstack.css +2 -2
  58. package/dist/gridstack.d.ts +424 -82
  59. package/dist/gridstack.js +408 -76
  60. package/dist/gridstack.js.map +1 -1
  61. package/dist/src/gridstack.scss +2 -2
  62. package/dist/types.d.ts +130 -29
  63. package/dist/types.js +6 -3
  64. package/dist/types.js.map +1 -1
  65. package/dist/utils.d.ts +208 -29
  66. package/dist/utils.js +275 -61
  67. package/dist/utils.js.map +1 -1
  68. package/doc/API.md +6192 -0
  69. package/package.json +14 -3
  70. package/doc/CHANGES.md +0 -962
  71. package/doc/README.md +0 -642
package/dist/gridstack.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /*!
2
- * GridStack 12.2.2
2
+ * GridStack 12.3.0
3
3
  * https://gridstackjs.com/
4
4
  *
5
- * Copyright (c) 2021-2024 Alain Dumesny
5
+ * Copyright (c) 2021-2025 Alain Dumesny
6
6
  * see root license https://github.com/gridstack/gridstack.js/tree/master/LICENSE
7
7
  */
8
8
  import { GridStackEngine } from './gridstack-engine';
@@ -23,6 +23,13 @@ export * from './types';
23
23
  export * from './utils';
24
24
  export * from './gridstack-engine';
25
25
  export * from './dd-gridstack';
26
+ export * from './dd-manager';
27
+ export * from './dd-element';
28
+ export * from './dd-draggable';
29
+ export * from './dd-droppable';
30
+ export * from './dd-resizable';
31
+ export * from './dd-resizable-handle';
32
+ export * from './dd-base-impl';
26
33
  /**
27
34
  * Main gridstack class - you will need to call `GridStack.init()` first to initialize your grid.
28
35
  * Note: your grid elements MUST have the following classes for the CSS layout to work:
@@ -132,7 +139,10 @@ class GridStack {
132
139
  static registerEngine(engineClass) {
133
140
  GridStack.engineClass = engineClass;
134
141
  }
135
- /** @internal create placeholder DIV as needed */
142
+ /**
143
+ * @internal create placeholder DIV as needed
144
+ * @returns the placeholder element for indicating drop zones during drag operations
145
+ */
136
146
  get placeholder() {
137
147
  if (!this._placeholder) {
138
148
  this._placeholder = Utils.createDiv([this.opts.placeholderClass, gridDefaults.itemClass, this.opts.itemClass]);
@@ -315,6 +325,8 @@ class GridStack {
315
325
  * @param w GridStackWidget definition. used MakeWidget(el) if you have dom element instead.
316
326
  */
317
327
  addWidget(w) {
328
+ if (!w)
329
+ return;
318
330
  if (typeof w === 'string') {
319
331
  console.error('V11: GridStack.addWidget() does not support string anymore. see #2736');
320
332
  return;
@@ -326,7 +338,7 @@ class GridStack {
326
338
  let el;
327
339
  let node = w;
328
340
  node.grid = this;
329
- if (node?.el) {
341
+ if (node.el) {
330
342
  el = node.el; // re-use element stored in the node
331
343
  }
332
344
  else if (GridStack.addRemoveCB) {
@@ -352,7 +364,15 @@ class GridStack {
352
364
  this.makeWidget(el, w);
353
365
  return el;
354
366
  }
355
- /** create the default grid item divs, and content (possibly lazy loaded) by using GridStack.renderCB() */
367
+ /**
368
+ * Create the default grid item divs and content (possibly lazy loaded) by using GridStack.renderCB().
369
+ *
370
+ * @param n GridStackNode definition containing widget configuration
371
+ * @returns the created HTML element with proper grid item structure
372
+ *
373
+ * @example
374
+ * const element = grid.createWidgetDivs({ w: 2, h: 1, content: 'Hello World' });
375
+ */
356
376
  createWidgetDivs(n) {
357
377
  const el = Utils.createDiv(['grid-stack-item', this.opts.itemClass]);
358
378
  const cont = Utils.createDiv(['grid-stack-item-content'], el);
@@ -448,7 +468,7 @@ class GridStack {
448
468
  subGrid._isTemp = true; // prevent re-nesting as we add over
449
469
  if (autoColumn)
450
470
  subGrid._autoColumn = true;
451
- // add the original content back as a child of hte newly created grid
471
+ // add the original content back as a child of the newly created grid
452
472
  if (saveContent) {
453
473
  subGrid.makeWidget(newItem, newItemOpt);
454
474
  }
@@ -559,14 +579,39 @@ class GridStack {
559
579
  return list;
560
580
  }
561
581
  /**
562
- * load the widgets from a list. This will call update() on each (matching by id) or add/remove widgets that are not there.
582
+ * Load widgets from a list. This will call update() on each (matching by id) or add/remove widgets that are not there.
583
+ * Used to restore a grid layout for a saved layout list (see `save()`).
563
584
  *
564
585
  * @param items list of widgets definition to update/create
565
586
  * @param addRemove boolean (default true) or callback method can be passed to control if and how missing widgets can be added/removed, giving
566
587
  * the user control of insertion.
588
+ * @returns the grid instance for chaining
567
589
  *
568
590
  * @example
569
- * see http://gridstackjs.com/demo/serialization.html
591
+ * // Basic usage with saved layout
592
+ * const savedLayout = grid.save(); // Save current layout
593
+ * // ... later restore it
594
+ * grid.load(savedLayout);
595
+ *
596
+ * // Load with custom add/remove callback
597
+ * grid.load(layout, (items, grid, add) => {
598
+ * if (add) {
599
+ * // Custom logic for adding new widgets
600
+ * items.forEach(item => {
601
+ * const el = document.createElement('div');
602
+ * el.innerHTML = item.content || '';
603
+ * grid.addWidget(el, item);
604
+ * });
605
+ * } else {
606
+ * // Custom logic for removing widgets
607
+ * items.forEach(item => grid.removeWidget(item.el));
608
+ * }
609
+ * });
610
+ *
611
+ * // Load without adding/removing missing widgets
612
+ * grid.load(layout, false);
613
+ *
614
+ * @see {@link http://gridstackjs.com/demo/serialization.html} for complete example
570
615
  */
571
616
  load(items, addRemove = GridStack.addRemoveCB || true) {
572
617
  items = Utils.cloneDeep(items); // so we can mod
@@ -688,7 +733,17 @@ class GridStack {
688
733
  return this;
689
734
  }
690
735
  /**
691
- * Gets current cell height.
736
+ * Gets the current cell height in pixels. This takes into account the unit type and converts to pixels if necessary.
737
+ *
738
+ * @param forcePixel if true, forces conversion to pixels even when cellHeight is specified in other units
739
+ * @returns the cell height in pixels
740
+ *
741
+ * @example
742
+ * const height = grid.getCellHeight();
743
+ * console.log('Cell height:', height, 'px');
744
+ *
745
+ * // Force pixel conversion
746
+ * const pixelHeight = grid.getCellHeight(true);
692
747
  */
693
748
  getCellHeight(forcePixel = false) {
694
749
  if (this.opts.cellHeight && this.opts.cellHeight !== 'auto' &&
@@ -720,17 +775,21 @@ class GridStack {
720
775
  return rows ? Math.round(this.el.getBoundingClientRect().height / rows) : this.opts.cellHeight;
721
776
  }
722
777
  /**
723
- * Update current cell height - see `GridStackOptions.cellHeight` for format.
724
- * This method rebuilds an internal CSS style sheet.
725
- * Note: You can expect performance issues if call this method too often.
778
+ * Update current cell height - see `GridStackOptions.cellHeight` for format by updating eh Browser CSS variable.
726
779
  *
727
- * @param val the cell height. If not passed (undefined), cells content will be made square (match width minus margin),
728
- * if pass 0 the CSS will be generated by the application instead.
780
+ * @param val the cell height. Options:
781
+ * - `undefined`: cells content will be made square (match width minus margin)
782
+ * - `0`: the CSS will be generated by the application instead
783
+ * - number: height in pixels
784
+ * - string: height with units (e.g., '70px', '5rem', '2em')
785
+ * @returns the grid instance for chaining
729
786
  *
730
787
  * @example
731
- * grid.cellHeight(100); // same as 100px
732
- * grid.cellHeight('70px');
733
- * grid.cellHeight(grid.cellWidth() * 1.2);
788
+ * grid.cellHeight(100); // 100px height
789
+ * grid.cellHeight('70px'); // explicit pixel height
790
+ * grid.cellHeight('5rem'); // relative to root font size
791
+ * grid.cellHeight(grid.cellWidth() * 1.2); // aspect ratio
792
+ * grid.cellHeight('auto'); // auto-size based on content
734
793
  */
735
794
  cellHeight(val) {
736
795
  // if not called internally, check if we're changing mode
@@ -762,6 +821,18 @@ class GridStack {
762
821
  return this;
763
822
  }
764
823
  /** Gets current cell width. */
824
+ /**
825
+ * Gets the current cell width in pixels. This is calculated based on the grid container width divided by the number of columns.
826
+ *
827
+ * @returns the cell width in pixels
828
+ *
829
+ * @example
830
+ * const width = grid.cellWidth();
831
+ * console.log('Cell width:', width, 'px');
832
+ *
833
+ * // Use cell width to calculate widget dimensions
834
+ * const widgetWidth = width * 3; // For a 3-column wide widget
835
+ */
765
836
  cellWidth() {
766
837
  return this._widthOrContainer() / this.getColumn();
767
838
  }
@@ -798,11 +869,25 @@ class GridStack {
798
869
  return false;
799
870
  }
800
871
  /**
801
- * re-layout grid items to reclaim any empty space. Options are:
802
- * 'list' keep the widget left->right order the same, even if that means leaving an empty slot if things don't fit
803
- * 'compact' might re-order items to fill any empty space
872
+ * Re-layout grid items to reclaim any empty space. This is useful after removing widgets
873
+ * or when you want to optimize the layout.
874
+ *
875
+ * @param layout layout type. Options:
876
+ * - 'compact' (default): might re-order items to fill any empty space
877
+ * - 'list': keep the widget left->right order the same, even if that means leaving an empty slot if things don't fit
878
+ * @param doSort re-sort items first based on x,y position. Set to false to do your own sorting ahead (default: true)
879
+ * @returns the grid instance for chaining
880
+ *
881
+ * @example
882
+ * // Compact layout after removing widgets
883
+ * grid.removeWidget('.widget-to-remove');
884
+ * grid.compact();
885
+ *
886
+ * // Use list layout (preserve order)
887
+ * grid.compact('list');
804
888
  *
805
- * doSort - 'false' to let you do your own sorting ahead in case you need to control a different order. (default to sort)
889
+ * // Compact without sorting first
890
+ * grid.compact('compact', false);
806
891
  */
807
892
  compact(layout = 'compact', doSort = true) {
808
893
  this.engine.compact(layout, doSort);
@@ -810,11 +895,32 @@ class GridStack {
810
895
  return this;
811
896
  }
812
897
  /**
813
- * set the number of columns in the grid. Will update existing widgets to conform to new number of columns,
898
+ * Set the number of columns in the grid. Will update existing widgets to conform to new number of columns,
814
899
  * as well as cache the original layout so you can revert back to previous positions without loss.
815
- * @param column - Integer > 0 (default 12).
816
- * @param layout specify the type of re-layout that will happen (position, size, etc...).
817
- * Note: items will never be outside of the current column boundaries. default ('moveScale'). Ignored for 1 column
900
+ *
901
+ * Requires `gridstack-extra.css` or `gridstack-extra.min.css` for [2-11] columns,
902
+ * else you will need to generate correct CSS.
903
+ * See: https://github.com/gridstack/gridstack.js#change-grid-columns
904
+ *
905
+ * @param column Integer > 0 (default 12)
906
+ * @param layout specify the type of re-layout that will happen. Options:
907
+ * - 'moveScale' (default): scale widget positions and sizes
908
+ * - 'move': keep widget sizes, only move positions
909
+ * - 'scale': keep widget positions, only scale sizes
910
+ * - 'none': don't change widget positions or sizes
911
+ * Note: items will never be outside of the current column boundaries.
912
+ * Ignored for `column=1` as we always want to vertically stack.
913
+ * @returns the grid instance for chaining
914
+ *
915
+ * @example
916
+ * // Change to 6 columns with default scaling
917
+ * grid.column(6);
918
+ *
919
+ * // Change to 4 columns, only move positions
920
+ * grid.column(4, 'move');
921
+ *
922
+ * // Single column layout (vertical stack)
923
+ * grid.column(1);
818
924
  */
819
925
  column(column, layout = 'moveScale') {
820
926
  if (!column || column < 1 || this.opts.column === column)
@@ -841,15 +947,42 @@ class GridStack {
841
947
  return this;
842
948
  }
843
949
  /**
844
- * get the number of columns in the grid (default 12)
950
+ * Get the number of columns in the grid (default 12).
951
+ *
952
+ * @returns the current number of columns in the grid
953
+ *
954
+ * @example
955
+ * const columnCount = grid.getColumn(); // returns 12 by default
845
956
  */
846
957
  getColumn() { return this.opts.column; }
847
- /** returns an array of grid HTML elements (no placeholder) - used to iterate through our children in DOM order */
958
+ /**
959
+ * Returns an array of grid HTML elements (no placeholder) - used to iterate through our children in DOM order.
960
+ * This method excludes placeholder elements and returns only actual grid items.
961
+ *
962
+ * @returns array of GridItemHTMLElement instances representing all grid items
963
+ *
964
+ * @example
965
+ * const items = grid.getGridItems();
966
+ * items.forEach(item => {
967
+ * console.log('Item ID:', item.gridstackNode.id);
968
+ * });
969
+ */
848
970
  getGridItems() {
849
971
  return Array.from(this.el.children)
850
972
  .filter((el) => el.matches('.' + this.opts.itemClass) && !el.matches('.' + this.opts.placeholderClass));
851
973
  }
852
- /** true if changeCB should be ignored due to column change, sizeToContent, loading, etc... which caller can ignore for dirty flag case */
974
+ /**
975
+ * Returns true if change callbacks should be ignored due to column change, sizeToContent, loading, etc.
976
+ * This is useful for callers who want to implement dirty flag functionality.
977
+ *
978
+ * @returns true if change callbacks are currently being ignored
979
+ *
980
+ * @example
981
+ * if (!grid.isIgnoreChangeCB()) {
982
+ * // Process the change event
983
+ * console.log('Grid layout changed');
984
+ * }
985
+ */
853
986
  isIgnoreChangeCB() { return this._ignoreLayoutsNodeChange; }
854
987
  /**
855
988
  * Destroys a grid instance. DO NOT CALL any methods or access any vars after this as it will free up members.
@@ -881,7 +1014,15 @@ class GridStack {
881
1014
  return this;
882
1015
  }
883
1016
  /**
884
- * enable/disable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html)
1017
+ * Enable/disable floating widgets (default: `false`). When enabled, widgets can float up to fill empty spaces.
1018
+ * See [example](http://gridstackjs.com/demo/float.html)
1019
+ *
1020
+ * @param val true to enable floating, false to disable
1021
+ * @returns the grid instance for chaining
1022
+ *
1023
+ * @example
1024
+ * grid.float(true); // Enable floating
1025
+ * grid.float(false); // Disable floating (default)
885
1026
  */
886
1027
  float(val) {
887
1028
  if (this.opts.float !== val) {
@@ -891,7 +1032,13 @@ class GridStack {
891
1032
  return this;
892
1033
  }
893
1034
  /**
894
- * get the current float mode
1035
+ * Get the current float mode setting.
1036
+ *
1037
+ * @returns true if floating is enabled, false otherwise
1038
+ *
1039
+ * @example
1040
+ * const isFloating = grid.getFloat();
1041
+ * console.log('Floating enabled:', isFloating);
895
1042
  */
896
1043
  getFloat() {
897
1044
  return this.engine.float;
@@ -923,16 +1070,33 @@ class GridStack {
923
1070
  const rowHeight = (box.height / parseInt(this.el.getAttribute('gs-current-row')));
924
1071
  return { x: Math.floor(relativeLeft / columnWidth), y: Math.floor(relativeTop / rowHeight) };
925
1072
  }
926
- /** returns the current number of rows, which will be at least `minRow` if set */
1073
+ /**
1074
+ * Returns the current number of rows, which will be at least `minRow` if set.
1075
+ * The row count is based on the highest positioned widget in the grid.
1076
+ *
1077
+ * @returns the current number of rows in the grid
1078
+ *
1079
+ * @example
1080
+ * const rowCount = grid.getRow();
1081
+ * console.log('Grid has', rowCount, 'rows');
1082
+ */
927
1083
  getRow() {
928
1084
  return Math.max(this.engine.getRow(), this.opts.minRow || 0);
929
1085
  }
930
1086
  /**
931
- * Checks if specified area is empty.
932
- * @param x the position x.
933
- * @param y the position y.
934
- * @param w the width of to check
935
- * @param h the height of to check
1087
+ * Checks if the specified rectangular area is empty (no widgets occupy any part of it).
1088
+ *
1089
+ * @param x the x coordinate (column) of the area to check
1090
+ * @param y the y coordinate (row) of the area to check
1091
+ * @param w the width in columns of the area to check
1092
+ * @param h the height in rows of the area to check
1093
+ * @returns true if the area is completely empty, false if any widget overlaps
1094
+ *
1095
+ * @example
1096
+ * // Check if a 2x2 area at position (1,1) is empty
1097
+ * if (grid.isAreaEmpty(1, 1, 2, 2)) {
1098
+ * console.log('Area is available for placement');
1099
+ * }
936
1100
  */
937
1101
  isAreaEmpty(x, y, w, h) {
938
1102
  return this.engine.isAreaEmpty(x, y, w, h);
@@ -941,14 +1105,25 @@ class GridStack {
941
1105
  * If you add elements to your grid by hand (or have some framework creating DOM), you have to tell gridstack afterwards to make them widgets.
942
1106
  * If you want gridstack to add the elements for you, use `addWidget()` instead.
943
1107
  * Makes the given element a widget and returns it.
1108
+ *
944
1109
  * @param els widget or single selector to convert.
945
1110
  * @param options widget definition to use instead of reading attributes or using default sizing values
1111
+ * @returns the converted GridItemHTMLElement
946
1112
  *
947
1113
  * @example
948
1114
  * const grid = GridStack.init();
949
- * grid.el.innerHtml = '<div id="1" gs-w="3"></div><div id="2"></div>';
950
- * grid.makeWidget('1');
951
- * grid.makeWidget('2', {w:2, content: 'hello'});
1115
+ *
1116
+ * // Create HTML content manually, possibly looking like:
1117
+ * // <div id="item-1" gs-x="0" gs-y="0" gs-w="3" gs-h="2"></div>
1118
+ * grid.el.innerHTML = '<div id="item-1" gs-w="3"></div><div id="item-2"></div>';
1119
+ *
1120
+ * // Convert existing elements to widgets
1121
+ * grid.makeWidget('#item-1'); // Uses gs-* attributes from DOM
1122
+ * grid.makeWidget('#item-2', {w: 2, h: 1, content: 'Hello World'});
1123
+ *
1124
+ * // Or pass DOM element directly
1125
+ * const element = document.getElementById('item-3');
1126
+ * grid.makeWidget(element, {x: 0, y: 1, w: 4, h: 2});
952
1127
  */
953
1128
  makeWidget(els, options) {
954
1129
  const el = GridStack.getElement(els);
@@ -1025,7 +1200,14 @@ class GridStack {
1025
1200
  delete this._gsEventHandler[name];
1026
1201
  return this;
1027
1202
  }
1028
- /** remove all event handlers */
1203
+ /**
1204
+ * Remove all event handlers from the grid. This is useful for cleanup when destroying a grid.
1205
+ *
1206
+ * @returns the grid instance for chaining
1207
+ *
1208
+ * @example
1209
+ * grid.offAll(); // Remove all event listeners
1210
+ */
1029
1211
  offAll() {
1030
1212
  Object.keys(this._gsEventHandler).forEach((key) => this.off(key));
1031
1213
  return this;
@@ -1196,9 +1378,30 @@ class GridStack {
1196
1378
  return this;
1197
1379
  }
1198
1380
  /**
1199
- * 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.
1200
- * @param els widget or selector of objects to modify (note: setting the same x,y for multiple items will be indeterministic and likely unwanted)
1201
- * @param opt new widget options (x,y,w,h, etc..). Only those set will be updated.
1381
+ * Updates widget position/size and other info. This is used to change widget properties after creation.
1382
+ * Can update position, size, content, and other widget properties.
1383
+ *
1384
+ * Note: If you need to call this on all nodes, use load() instead which will update what changed.
1385
+ * Setting the same x,y for multiple items will be indeterministic and likely unwanted.
1386
+ *
1387
+ * @param els widget element(s) or selector to modify
1388
+ * @param opt new widget options (x,y,w,h, etc.). Only those set will be updated.
1389
+ * @returns the grid instance for chaining
1390
+ *
1391
+ * @example
1392
+ * // Update widget size and position
1393
+ * grid.update('.my-widget', { x: 2, y: 1, w: 3, h: 2 });
1394
+ *
1395
+ * // Update widget content
1396
+ * grid.update(widget, { content: '<p>New content</p>' });
1397
+ *
1398
+ * // Update multiple properties
1399
+ * grid.update('#my-widget', {
1400
+ * w: 4,
1401
+ * h: 3,
1402
+ * noResize: true,
1403
+ * locked: true
1404
+ * });
1202
1405
  */
1203
1406
  update(els, opt) {
1204
1407
  GridStack.getElements(els).forEach(el => {
@@ -1283,10 +1486,22 @@ class GridStack {
1283
1486
  }
1284
1487
  }
1285
1488
  /**
1286
- * Updates widget height to match the content height to avoid v-scrollbar or dead space.
1287
- * 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.
1288
- * @param el grid item element
1289
- * @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
1489
+ * Updates widget height to match the content height to avoid vertical scrollbars or dead space.
1490
+ * This automatically adjusts the widget height based on its content size.
1491
+ *
1492
+ * Note: This assumes only 1 child under resizeToContentParent='.grid-stack-item-content'
1493
+ * (sized to gridItem minus padding) that represents the entire content size.
1494
+ *
1495
+ * @param el the grid item element to resize
1496
+ *
1497
+ * @example
1498
+ * // Resize a widget to fit its content
1499
+ * const widget = document.querySelector('.grid-stack-item');
1500
+ * grid.resizeToContent(widget);
1501
+ *
1502
+ * // This is commonly used with dynamic content:
1503
+ * widget.querySelector('.content').innerHTML = 'New longer content...';
1504
+ * grid.resizeToContent(widget);
1290
1505
  */
1291
1506
  resizeToContent(el) {
1292
1507
  if (!el)
@@ -1361,9 +1576,20 @@ class GridStack {
1361
1576
  else
1362
1577
  this.resizeToContent(el);
1363
1578
  }
1364
- /** rotate (by swapping w & h) the passed in node - called when user press 'r' during dragging
1365
- * @param els widget or selector of objects to modify
1366
- * @param relative optional pixel coord relative to upper/left corner to rotate around (will keep that cell under cursor)
1579
+ /**
1580
+ * Rotate widgets by swapping their width and height. This is typically called when the user presses 'r' during dragging.
1581
+ * The rotation swaps the w/h dimensions and adjusts min/max constraints accordingly.
1582
+ *
1583
+ * @param els widget element(s) or selector to rotate
1584
+ * @param relative optional pixel coordinate relative to upper/left corner to rotate around (keeps that cell under cursor)
1585
+ * @returns the grid instance for chaining
1586
+ *
1587
+ * @example
1588
+ * // Rotate a specific widget
1589
+ * grid.rotate('.my-widget');
1590
+ *
1591
+ * // Rotate with relative positioning during drag
1592
+ * grid.rotate(widget, { left: 50, top: 30 });
1367
1593
  */
1368
1594
  rotate(els, relative) {
1369
1595
  GridStack.getElements(els).forEach(el => {
@@ -1387,8 +1613,19 @@ class GridStack {
1387
1613
  return this;
1388
1614
  }
1389
1615
  /**
1390
- * 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).
1391
- * @param value margin value
1616
+ * Updates the margins which will set all 4 sides at once - see `GridStackOptions.margin` for format options.
1617
+ * Supports CSS string format of 1, 2, or 4 values or a single number.
1618
+ *
1619
+ * @param value margin value - can be:
1620
+ * - Single number: `10` (applies to all sides)
1621
+ * - Two values: `'10px 20px'` (top/bottom, left/right)
1622
+ * - Four values: `'10px 20px 5px 15px'` (top, right, bottom, left)
1623
+ * @returns the grid instance for chaining
1624
+ *
1625
+ * @example
1626
+ * grid.margin(10); // 10px all sides
1627
+ * grid.margin('10px 20px'); // 10px top/bottom, 20px left/right
1628
+ * grid.margin('5px 10px 15px 20px'); // Different for each side
1392
1629
  */
1393
1630
  margin(value) {
1394
1631
  const isMultiValue = (typeof value === 'string' && value.split(' ').length > 1);
@@ -1404,7 +1641,20 @@ class GridStack {
1404
1641
  this._initMargin();
1405
1642
  return this;
1406
1643
  }
1407
- /** returns current margin number value (undefined if 4 sides don't match) */
1644
+ /**
1645
+ * Returns the current margin value as a number (undefined if the 4 sides don't match).
1646
+ * This only returns a number if all sides have the same margin value.
1647
+ *
1648
+ * @returns the margin value in pixels, or undefined if sides have different values
1649
+ *
1650
+ * @example
1651
+ * const margin = grid.getMargin();
1652
+ * if (margin !== undefined) {
1653
+ * console.log('Uniform margin:', margin, 'px');
1654
+ * } else {
1655
+ * console.log('Margins are different on different sides');
1656
+ * }
1657
+ */
1408
1658
  getMargin() { return this.opts.margin; }
1409
1659
  /**
1410
1660
  * Returns true if the height of the grid will be less than the vertical
@@ -1782,7 +2032,16 @@ class GridStack {
1782
2032
  * but caused loading issues in prod - see https://github.com/gridstack/gridstack.js/issues/2039
1783
2033
  * ===========================================================================================
1784
2034
  */
1785
- /** get the global (but static to this code) DD implementation */
2035
+ /**
2036
+ * Get the global drag & drop implementation instance.
2037
+ * This provides access to the underlying drag & drop functionality.
2038
+ *
2039
+ * @returns the DDGridStack instance used for drag & drop operations
2040
+ *
2041
+ * @example
2042
+ * const dd = GridStack.getDD();
2043
+ * // Access drag & drop functionality
2044
+ */
1786
2045
  static getDD() {
1787
2046
  return dd;
1788
2047
  }
@@ -1809,10 +2068,22 @@ class GridStack {
1809
2068
  });
1810
2069
  }
1811
2070
  /**
1812
- * Enables/Disables dragging by the user of specific grid element. If you want all items, and have it affect future items, use enableMove() instead. No-op for static grids.
1813
- * IF you are looking to prevent an item from moving (due to being pushed around by another during collision) use locked property instead.
1814
- * @param els widget or selector to modify.
1815
- * @param val if true widget will be draggable, assuming the parent grid isn't noMove or static.
2071
+ * Enables/Disables dragging by the user for specific grid elements.
2072
+ * For all items and future items, use enableMove() instead. No-op for static grids.
2073
+ *
2074
+ * Note: If you want to prevent an item from moving due to being pushed around by another
2075
+ * during collision, use the 'locked' property instead.
2076
+ *
2077
+ * @param els widget element(s) or selector to modify
2078
+ * @param val if true widget will be draggable, assuming the parent grid isn't noMove or static
2079
+ * @returns the grid instance for chaining
2080
+ *
2081
+ * @example
2082
+ * // Make specific widgets draggable
2083
+ * grid.movable('.my-widget', true);
2084
+ *
2085
+ * // Disable dragging for specific widgets
2086
+ * grid.movable('#fixed-widget', false);
1816
2087
  */
1817
2088
  movable(els, val) {
1818
2089
  if (this.opts.staticGrid)
@@ -1827,9 +2098,19 @@ class GridStack {
1827
2098
  return this;
1828
2099
  }
1829
2100
  /**
1830
- * Enables/Disables user resizing of specific grid element. If you want all items, and have it affect future items, use enableResize() instead. No-op for static grids.
1831
- * @param els widget or selector to modify
1832
- * @param val if true widget will be resizable, assuming the parent grid isn't noResize or static.
2101
+ * Enables/Disables user resizing for specific grid elements.
2102
+ * For all items and future items, use enableResize() instead. No-op for static grids.
2103
+ *
2104
+ * @param els widget element(s) or selector to modify
2105
+ * @param val if true widget will be resizable, assuming the parent grid isn't noResize or static
2106
+ * @returns the grid instance for chaining
2107
+ *
2108
+ * @example
2109
+ * // Make specific widgets resizable
2110
+ * grid.resizable('.my-widget', true);
2111
+ *
2112
+ * // Disable resizing for specific widgets
2113
+ * grid.resizable('#fixed-size-widget', false);
1833
2114
  */
1834
2115
  resizable(els, val) {
1835
2116
  if (this.opts.staticGrid)
@@ -1846,12 +2127,24 @@ class GridStack {
1846
2127
  /**
1847
2128
  * Temporarily disables widgets moving/resizing.
1848
2129
  * If you want a more permanent way (which freezes up resources) use `setStatic(true)` instead.
1849
- * Note: no-op for static grid
2130
+ *
2131
+ * Note: This is a no-op for static grids.
2132
+ *
1850
2133
  * This is a shortcut for:
2134
+ * ```typescript
2135
+ * grid.enableMove(false);
2136
+ * grid.enableResize(false);
2137
+ * ```
2138
+ *
2139
+ * @param recurse if true (default), sub-grids also get updated
2140
+ * @returns the grid instance for chaining
2141
+ *
1851
2142
  * @example
1852
- * grid.enableMove(false);
1853
- * grid.enableResize(false);
1854
- * @param recurse true (default) if sub-grids also get updated
2143
+ * // Disable all interactions
2144
+ * grid.disable();
2145
+ *
2146
+ * // Disable only this grid, not sub-grids
2147
+ * grid.disable(false);
1855
2148
  */
1856
2149
  disable(recurse = true) {
1857
2150
  if (this.opts.staticGrid)
@@ -1863,12 +2156,23 @@ class GridStack {
1863
2156
  }
1864
2157
  /**
1865
2158
  * Re-enables widgets moving/resizing - see disable().
1866
- * Note: no-op for static grid.
2159
+ * Note: This is a no-op for static grids.
2160
+ *
1867
2161
  * This is a shortcut for:
2162
+ * ```typescript
2163
+ * grid.enableMove(true);
2164
+ * grid.enableResize(true);
2165
+ * ```
2166
+ *
2167
+ * @param recurse if true (default), sub-grids also get updated
2168
+ * @returns the grid instance for chaining
2169
+ *
1868
2170
  * @example
1869
- * grid.enableMove(true);
1870
- * grid.enableResize(true);
1871
- * @param recurse true (default) if sub-grids also get updated
2171
+ * // Re-enable all interactions
2172
+ * grid.enable();
2173
+ *
2174
+ * // Enable only this grid, not sub-grids
2175
+ * grid.enable(false);
1872
2176
  */
1873
2177
  enable(recurse = true) {
1874
2178
  if (this.opts.staticGrid)
@@ -1879,8 +2183,22 @@ class GridStack {
1879
2183
  return this;
1880
2184
  }
1881
2185
  /**
1882
- * Enables/disables widget moving. No-op for static grids, and locally defined items still overrule
1883
- * @param recurse true (default) if sub-grids also get updated
2186
+ * Enables/disables widget moving for all widgets. No-op for static grids.
2187
+ * Note: locally defined items (with noMove property) still override this setting.
2188
+ *
2189
+ * @param doEnable if true widgets will be movable, if false moving is disabled
2190
+ * @param recurse if true (default), sub-grids also get updated
2191
+ * @returns the grid instance for chaining
2192
+ *
2193
+ * @example
2194
+ * // Enable moving for all widgets
2195
+ * grid.enableMove(true);
2196
+ *
2197
+ * // Disable moving for all widgets
2198
+ * grid.enableMove(false);
2199
+ *
2200
+ * // Enable only this grid, not sub-grids
2201
+ * grid.enableMove(true, false);
1884
2202
  */
1885
2203
  enableMove(doEnable, recurse = true) {
1886
2204
  if (this.opts.staticGrid)
@@ -1894,8 +2212,22 @@ class GridStack {
1894
2212
  return this;
1895
2213
  }
1896
2214
  /**
1897
- * Enables/disables widget resizing. No-op for static grids.
1898
- * @param recurse true (default) if sub-grids also get updated
2215
+ * Enables/disables widget resizing for all widgets. No-op for static grids.
2216
+ * Note: locally defined items (with noResize property) still override this setting.
2217
+ *
2218
+ * @param doEnable if true widgets will be resizable, if false resizing is disabled
2219
+ * @param recurse if true (default), sub-grids also get updated
2220
+ * @returns the grid instance for chaining
2221
+ *
2222
+ * @example
2223
+ * // Enable resizing for all widgets
2224
+ * grid.enableResize(true);
2225
+ *
2226
+ * // Disable resizing for all widgets
2227
+ * grid.enableResize(false);
2228
+ *
2229
+ * // Enable only this grid, not sub-grids
2230
+ * grid.enableResize(true, false);
1899
2231
  */
1900
2232
  enableResize(doEnable, recurse = true) {
1901
2233
  if (this.opts.staticGrid)
@@ -2290,8 +2622,7 @@ class GridStack {
2290
2622
  else {
2291
2623
  Utils.removePositioningStyles(target);
2292
2624
  if (node._temporaryRemoved) {
2293
- // got removed - restore item back to before dragging position
2294
- Utils.copyPos(node, node._orig); // @ts-ignore
2625
+ // use last position we were at (not _orig as we may have pushed others and moved) and add it back
2295
2626
  this._writePosAttr(target, node);
2296
2627
  this.engine.addNode(node);
2297
2628
  }
@@ -2530,6 +2861,7 @@ GridStack.resizeToContentParent = '.grid-stack-item-content';
2530
2861
  GridStack.Utils = Utils;
2531
2862
  /** scoping so users can call new GridStack.Engine(12) for example */
2532
2863
  GridStack.Engine = GridStackEngine;
2533
- GridStack.GDRev = '12.2.2';
2864
+ /** @internal current version compiled in code */
2865
+ GridStack.GDRev = '12.3.0';
2534
2866
  export { GridStack };
2535
2867
  //# sourceMappingURL=gridstack.js.map