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
@@ -1,6 +1,6 @@
1
1
  /**
2
- * gridstack-engine.ts 12.2.2
3
- * Copyright (c) 2021-2024 Alain Dumesny - see GridStack root license
2
+ * gridstack-engine.ts 12.3.0
3
+ * Copyright (c) 2021-2025 Alain Dumesny - see GridStack root license
4
4
  */
5
5
  import { GridStackNode, GridStackPosition, GridStackMoveOpts, SaveFcn, CompactOptions } from './types';
6
6
  /** callback to update the DOM attributes since this class is generic (no HTML or other info) for items that changed - see _notify() */
@@ -14,10 +14,17 @@ export interface GridStackEngineOptions {
14
14
  onChange?: OnChangeCB;
15
15
  }
16
16
  /**
17
- * Defines the GridStack engine that does most no DOM grid manipulation.
18
- * See GridStack methods and vars for descriptions.
17
+ * Defines the GridStack engine that handles all grid layout calculations and node positioning.
18
+ * This is the core engine that performs grid manipulation without any DOM operations.
19
19
  *
20
- * NOTE: values should not be modified directly - call the main GridStack API instead
20
+ * The engine manages:
21
+ * - Node positioning and collision detection
22
+ * - Layout algorithms (compact, float, etc.)
23
+ * - Grid resizing and column changes
24
+ * - Widget movement and resizing logic
25
+ *
26
+ * NOTE: Values should not be modified directly - use the main GridStack API instead
27
+ * to ensure proper DOM updates and event triggers.
21
28
  */
22
29
  export declare class GridStackEngine {
23
30
  column: number;
@@ -30,49 +37,251 @@ export declare class GridStackEngine {
30
37
  /** true when grid.load() already cached the layout and can skip out of bound caching info */
31
38
  skipCacheUpdate?: boolean;
32
39
  constructor(opts?: GridStackEngineOptions);
40
+ /**
41
+ * Enable/disable batch mode for multiple operations to optimize performance.
42
+ * When enabled, layout updates are deferred until batch mode is disabled.
43
+ *
44
+ * @param flag true to enable batch mode, false to disable and apply changes
45
+ * @param doPack if true (default), pack/compact nodes when disabling batch mode
46
+ * @returns the engine instance for chaining
47
+ *
48
+ * @example
49
+ * // Start batch mode for multiple operations
50
+ * engine.batchUpdate(true);
51
+ * engine.addNode(node1);
52
+ * engine.addNode(node2);
53
+ * engine.batchUpdate(false); // Apply all changes at once
54
+ */
33
55
  batchUpdate(flag?: boolean, doPack?: boolean): GridStackEngine;
34
56
  protected _useEntireRowArea(node: GridStackNode, nn: GridStackPosition): boolean;
35
- /** return the nodes that intercept the given node. Optionally a different area can be used, as well as a second node to skip */
57
+ /**
58
+ * Return the first node that intercepts/collides with the given node or area.
59
+ * Used for collision detection during drag and drop operations.
60
+ *
61
+ * @param skip the node to skip in collision detection (usually the node being moved)
62
+ * @param area the area to check for collisions (defaults to skip node's area)
63
+ * @param skip2 optional second node to skip in collision detection
64
+ * @returns the first colliding node, or undefined if no collision
65
+ *
66
+ * @example
67
+ * const colliding = engine.collide(draggedNode, {x: 2, y: 1, w: 2, h: 1});
68
+ * if (colliding) {
69
+ * console.log('Would collide with:', colliding.id);
70
+ * }
71
+ */
36
72
  collide(skip: GridStackNode, area?: GridStackNode, skip2?: GridStackNode): GridStackNode | undefined;
73
+ /**
74
+ * Return all nodes that intercept/collide with the given node or area.
75
+ * Similar to collide() but returns all colliding nodes instead of just the first.
76
+ *
77
+ * @param skip the node to skip in collision detection
78
+ * @param area the area to check for collisions (defaults to skip node's area)
79
+ * @param skip2 optional second node to skip in collision detection
80
+ * @returns array of all colliding nodes
81
+ *
82
+ * @example
83
+ * const allCollisions = engine.collideAll(draggedNode);
84
+ * console.log('Colliding with', allCollisions.length, 'nodes');
85
+ */
37
86
  collideAll(skip: GridStackNode, area?: GridStackNode, skip2?: GridStackNode): GridStackNode[];
38
87
  /** does a pixel coverage collision based on where we started, returning the node that has the most coverage that is >50% mid line */
39
88
  protected directionCollideCoverage(node: GridStackNode, o: GridStackMoveOpts, collides: GridStackNode[]): GridStackNode | undefined;
40
- /** does a pixel coverage returning the node that has the most coverage by area */
41
- /** called to cache the nodes pixel rectangles used for collision detection during drag */
42
- cacheRects(w: number, h: number, top: number, right: number, bottom: number, left: number): GridStackEngine;
43
- /** called to possibly swap between 2 nodes (same size or column, not locked, touching), returning true if successful */
89
+ /**
90
+ * Attempt to swap the positions of two nodes if they meet swapping criteria.
91
+ * Nodes can swap if they are the same size or in the same column/row, not locked, and touching.
92
+ *
93
+ * @param a first node to swap
94
+ * @param b second node to swap
95
+ * @returns true if swap was successful, false if not possible, undefined if not applicable
96
+ *
97
+ * @example
98
+ * const swapped = engine.swap(nodeA, nodeB);
99
+ * if (swapped) {
100
+ * console.log('Nodes swapped successfully');
101
+ * }
102
+ */
44
103
  swap(a: GridStackNode, b: GridStackNode): boolean | undefined;
104
+ /**
105
+ * Check if the specified rectangular area is empty (no nodes occupy any part of it).
106
+ *
107
+ * @param x the x coordinate (column) of the area to check
108
+ * @param y the y coordinate (row) of the area to check
109
+ * @param w the width in columns of the area to check
110
+ * @param h the height in rows of the area to check
111
+ * @returns true if the area is completely empty, false if any node overlaps
112
+ *
113
+ * @example
114
+ * if (engine.isAreaEmpty(2, 1, 3, 2)) {
115
+ * console.log('Area is available for placement');
116
+ * }
117
+ */
45
118
  isAreaEmpty(x: number, y: number, w: number, h: number): boolean;
46
- /** re-layout grid items to reclaim any empty space - optionally keeping the sort order exactly the same ('list' mode) vs truly finding an empty spaces */
119
+ /**
120
+ * Re-layout grid items to reclaim any empty space.
121
+ * This optimizes the grid layout by moving items to fill gaps.
122
+ *
123
+ * @param layout layout algorithm to use:
124
+ * - 'compact' (default): find truly empty spaces, may reorder items
125
+ * - 'list': keep the sort order exactly the same, move items up sequentially
126
+ * @param doSort if true (default), sort nodes by position before compacting
127
+ * @returns the engine instance for chaining
128
+ *
129
+ * @example
130
+ * // Compact to fill empty spaces
131
+ * engine.compact();
132
+ *
133
+ * // Compact preserving item order
134
+ * engine.compact('list');
135
+ */
47
136
  compact(layout?: CompactOptions, doSort?: boolean): GridStackEngine;
48
- /** enable/disable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html) */
137
+ /**
138
+ * Enable/disable floating widgets (default: `false`).
139
+ * When floating is enabled, widgets can move up to fill empty spaces.
140
+ * See [example](http://gridstackjs.com/demo/float.html)
141
+ *
142
+ * @param val true to enable floating, false to disable
143
+ *
144
+ * @example
145
+ * engine.float = true; // Enable floating
146
+ * engine.float = false; // Disable floating (default)
147
+ */
49
148
  set float(val: boolean);
50
- /** float getter method */
149
+ /**
150
+ * Get the current floating mode setting.
151
+ *
152
+ * @returns true if floating is enabled, false otherwise
153
+ *
154
+ * @example
155
+ * const isFloating = engine.float;
156
+ * console.log('Floating enabled:', isFloating);
157
+ */
51
158
  get float(): boolean;
52
- /** sort the nodes array from first to last, or reverse. Called during collision/placement to force an order */
159
+ /**
160
+ * Sort the nodes array from first to last, or reverse.
161
+ * This is called during collision/placement operations to enforce a specific order.
162
+ *
163
+ * @param dir sort direction: 1 for ascending (first to last), -1 for descending (last to first)
164
+ * @returns the engine instance for chaining
165
+ *
166
+ * @example
167
+ * engine.sortNodes(); // Sort ascending (default)
168
+ * engine.sortNodes(-1); // Sort descending
169
+ */
53
170
  sortNodes(dir?: 1 | -1): GridStackEngine;
54
171
  /**
55
- * given a random node, makes sure it's coordinates/values are valid in the current grid
56
- * @param node to adjust
57
- * @param resizing if out of bound, resize down or move into the grid to fit ?
172
+ * Prepare and validate a node's coordinates and values for the current grid.
173
+ * This ensures the node has valid position, size, and properties before being added to the grid.
174
+ *
175
+ * @param node the node to prepare and validate
176
+ * @param resizing if true, resize the node down if it's out of bounds; if false, move it to fit
177
+ * @returns the prepared node with valid coordinates
178
+ *
179
+ * @example
180
+ * const node = { w: 3, h: 2, content: 'Hello' };
181
+ * const prepared = engine.prepareNode(node);
182
+ * console.log('Node prepared at:', prepared.x, prepared.y);
58
183
  */
59
184
  prepareNode(node: GridStackNode, resizing?: boolean): GridStackNode;
60
- /** part2 of preparing a node to fit inside our grid - checks for x,y,w from grid dimensions */
185
+ /**
186
+ * Part 2 of preparing a node to fit inside the grid - validates and fixes coordinates and dimensions.
187
+ * This ensures the node fits within grid boundaries and respects min/max constraints.
188
+ *
189
+ * @param node the node to validate and fix
190
+ * @param resizing if true, resize the node to fit; if false, move the node to fit
191
+ * @returns the engine instance for chaining
192
+ *
193
+ * @example
194
+ * // Fix a node that might be out of bounds
195
+ * engine.nodeBoundFix(node, true); // Resize to fit
196
+ * engine.nodeBoundFix(node, false); // Move to fit
197
+ */
61
198
  nodeBoundFix(node: GridStackNode, resizing?: boolean): GridStackEngine;
62
- /** returns a list of modified nodes from their original values */
199
+ /**
200
+ * Returns a list of nodes that have been modified from their original values.
201
+ * This is used to track which nodes need DOM updates.
202
+ *
203
+ * @param verify if true, performs additional verification by comparing current vs original positions
204
+ * @returns array of nodes that have been modified
205
+ *
206
+ * @example
207
+ * const changed = engine.getDirtyNodes();
208
+ * console.log('Modified nodes:', changed.length);
209
+ *
210
+ * // Get verified dirty nodes
211
+ * const verified = engine.getDirtyNodes(true);
212
+ */
63
213
  getDirtyNodes(verify?: boolean): GridStackNode[];
64
- /** find the first available empty spot for the given node width/height, updating the x,y attributes. return true if found.
65
- * optionally you can pass your own existing node list and column count, otherwise defaults to that engine data.
66
- * Optionally pass a widget to start search AFTER, meaning the order will remain the same but possibly have empty slots we skipped
214
+ /**
215
+ * Find the first available empty spot for the given node dimensions.
216
+ * Updates the node's x,y attributes with the found position.
217
+ *
218
+ * @param node the node to find a position for (w,h must be set)
219
+ * @param nodeList optional list of nodes to check against (defaults to engine nodes)
220
+ * @param column optional column count (defaults to engine column count)
221
+ * @param after optional node to start search after (maintains order)
222
+ * @returns true if an empty position was found and node was updated
223
+ *
224
+ * @example
225
+ * const node = { w: 2, h: 1 };
226
+ * if (engine.findEmptyPosition(node)) {
227
+ * console.log('Found position at:', node.x, node.y);
228
+ * }
67
229
  */
68
230
  findEmptyPosition(node: GridStackNode, nodeList?: GridStackNode[], column?: number, after?: GridStackNode): boolean;
69
- /** call to add the given node to our list, fixing collision and re-packing */
231
+ /**
232
+ * Add the given node to the grid, handling collision detection and re-packing.
233
+ * This is the main method for adding new widgets to the engine.
234
+ *
235
+ * @param node the node to add to the grid
236
+ * @param triggerAddEvent if true, adds node to addedNodes list for event triggering
237
+ * @param after optional node to place this node after (for ordering)
238
+ * @returns the added node (or existing node if duplicate)
239
+ *
240
+ * @example
241
+ * const node = { x: 0, y: 0, w: 2, h: 1, content: 'Hello' };
242
+ * const added = engine.addNode(node, true);
243
+ */
70
244
  addNode(node: GridStackNode, triggerAddEvent?: boolean, after?: GridStackNode): GridStackNode;
245
+ /**
246
+ * Remove the given node from the grid.
247
+ *
248
+ * @param node the node to remove
249
+ * @param removeDOM if true (default), marks node for DOM removal
250
+ * @param triggerEvent if true, adds node to removedNodes list for event triggering
251
+ * @returns the engine instance for chaining
252
+ *
253
+ * @example
254
+ * engine.removeNode(node, true, true);
255
+ */
71
256
  removeNode(node: GridStackNode, removeDOM?: boolean, triggerEvent?: boolean): GridStackEngine;
257
+ /**
258
+ * Remove all nodes from the grid.
259
+ *
260
+ * @param removeDOM if true (default), marks all nodes for DOM removal
261
+ * @param triggerEvent if true (default), triggers removal events
262
+ * @returns the engine instance for chaining
263
+ *
264
+ * @example
265
+ * engine.removeAll(); // Remove all nodes
266
+ */
72
267
  removeAll(removeDOM?: boolean, triggerEvent?: boolean): GridStackEngine;
73
- /** checks if item can be moved (layout constrain) vs moveNode(), returning true if was able to move.
74
- * In more complicated cases (maxRow) it will attempt at moving the item and fixing
75
- * others in a clone first, then apply those changes if still within specs. */
268
+ /**
269
+ * Check if a node can be moved to a new position, considering layout constraints.
270
+ * This is a safer version of moveNode() that validates the move first.
271
+ *
272
+ * For complex cases (like maxRow constraints), it simulates the move in a clone first,
273
+ * then applies the changes only if they meet all specifications.
274
+ *
275
+ * @param node the node to move
276
+ * @param o move options including target position
277
+ * @returns true if the node was successfully moved
278
+ *
279
+ * @example
280
+ * const canMove = engine.moveNodeCheck(node, { x: 2, y: 1 });
281
+ * if (canMove) {
282
+ * console.log('Node moved successfully');
283
+ * }
284
+ */
76
285
  moveNodeCheck(node: GridStackNode, o: GridStackMoveOpts): boolean;
77
286
  /** return true if can fit in grid height constrain only (always true if no maxRow) */
78
287
  willItFit(node: GridStackNode): boolean;