gridstack 12.3.2 → 12.3.3
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.
- package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
- package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
- package/dist/angular/esm2020/lib/gridstack.component.mjs +2 -2
- package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
- package/dist/angular/esm2020/lib/types.mjs +2 -2
- package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
- package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
- package/dist/angular/fesm2020/gridstack-angular.mjs +5 -5
- package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
- package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
- package/dist/angular/lib/gridstack.component.d.ts +1 -1
- package/dist/angular/lib/types.d.ts +1 -1
- package/dist/angular/package.json +1 -1
- package/dist/angular/src/base-widget.ts +1 -1
- package/dist/angular/src/gridstack-item.component.ts +1 -1
- package/dist/angular/src/gridstack.component.ts +1 -1
- package/dist/angular/src/gridstack.module.ts +1 -1
- package/dist/angular/src/types.ts +1 -1
- package/dist/gridstack-all.js +1 -1
- package/dist/gridstack-all.js.LICENSE.txt +1 -1
- package/dist/gridstack-all.js.map +1 -1
- package/dist/gridstack.css +1 -1
- package/dist/spec/gridstack-engine-spec.d.ts +1 -0
- package/dist/spec/gridstack-engine-spec.js +358 -0
- package/dist/spec/gridstack-engine-spec.js.map +1 -0
- package/dist/spec/gridstack-spec.d.ts +1 -0
- package/dist/spec/gridstack-spec.js +1780 -0
- package/dist/spec/gridstack-spec.js.map +1 -0
- package/dist/spec/integration/gridstack-integration.spec.d.ts +1 -0
- package/dist/spec/integration/gridstack-integration.spec.js +171 -0
- package/dist/spec/integration/gridstack-integration.spec.js.map +1 -0
- package/dist/spec/regression-spec.d.ts +1 -0
- package/dist/spec/regression-spec.js +100 -0
- package/dist/spec/regression-spec.js.map +1 -0
- package/dist/spec/utils-spec.d.ts +1 -0
- package/dist/spec/utils-spec.js +243 -0
- package/dist/spec/utils-spec.js.map +1 -0
- package/dist/src/dd-base-impl.d.ts +69 -0
- package/dist/src/dd-base-impl.js +70 -0
- package/dist/src/dd-base-impl.js.map +1 -0
- package/dist/src/dd-draggable.d.ts +20 -0
- package/dist/src/dd-draggable.js +364 -0
- package/dist/src/dd-draggable.js.map +1 -0
- package/dist/src/dd-droppable.d.ts +26 -0
- package/dist/src/dd-droppable.js +149 -0
- package/dist/src/dd-droppable.js.map +1 -0
- package/dist/src/dd-element.d.ts +27 -0
- package/dist/src/dd-element.js +91 -0
- package/dist/src/dd-element.js.map +1 -0
- package/dist/src/dd-gridstack.d.ts +82 -0
- package/dist/src/dd-gridstack.js +165 -0
- package/dist/src/dd-gridstack.js.map +1 -0
- package/dist/src/dd-manager.d.ts +43 -0
- package/dist/src/dd-manager.js +14 -0
- package/dist/src/dd-manager.js.map +1 -0
- package/dist/src/dd-resizable-handle.d.ts +18 -0
- package/dist/src/dd-resizable-handle.js +113 -0
- package/dist/src/dd-resizable-handle.js.map +1 -0
- package/dist/src/dd-resizable.d.ts +30 -0
- package/dist/src/dd-resizable.js +304 -0
- package/dist/src/dd-resizable.js.map +1 -0
- package/dist/src/dd-touch.d.ts +33 -0
- package/dist/src/dd-touch.js +145 -0
- package/dist/src/dd-touch.js.map +1 -0
- package/dist/src/gridstack-engine.d.ts +321 -0
- package/dist/src/gridstack-engine.js +1272 -0
- package/dist/src/gridstack-engine.js.map +1 -0
- package/dist/src/gridstack.d.ts +802 -0
- package/dist/src/gridstack.js +2872 -0
- package/dist/src/gridstack.js.map +1 -0
- package/dist/src/gridstack.scss +1 -1
- package/dist/src/types.d.ts +427 -0
- package/dist/src/types.js +38 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +283 -0
- package/dist/src/utils.js +790 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +74 -0
- package/dist/vitest.config.js.map +1 -0
- package/dist/vitest.setup.d.ts +1 -0
- package/dist/vitest.setup.js +90 -0
- package/dist/vitest.setup.js.map +1 -0
- package/doc/API.md +22 -22
- package/package.json +21 -9
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* utils.ts 12.3.3
|
|
3
|
+
* Copyright (c) 2021-2025 Alain Dumesny - see GridStack root license
|
|
4
|
+
*/
|
|
5
|
+
import { GridStackElement, GridStackNode, numberOrString, GridStackPosition, GridStackWidget } from './types';
|
|
6
|
+
export interface HeightData {
|
|
7
|
+
h: number;
|
|
8
|
+
unit: string;
|
|
9
|
+
}
|
|
10
|
+
export interface DragTransform {
|
|
11
|
+
xScale: number;
|
|
12
|
+
yScale: number;
|
|
13
|
+
xOffset: number;
|
|
14
|
+
yOffset: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Collection of utility methods used throughout GridStack.
|
|
18
|
+
* These are general-purpose helper functions for DOM manipulation,
|
|
19
|
+
* positioning calculations, object operations, and more.
|
|
20
|
+
*/
|
|
21
|
+
export declare class Utils {
|
|
22
|
+
/**
|
|
23
|
+
* Convert a potential selector into an actual list of HTML elements.
|
|
24
|
+
* Supports CSS selectors, element references, and special ID handling.
|
|
25
|
+
*
|
|
26
|
+
* @param els selector string, HTMLElement, or array of elements
|
|
27
|
+
* @param root optional root element to search within (defaults to document, useful for shadow DOM)
|
|
28
|
+
* @returns array of HTML elements matching the selector
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const elements = Utils.getElements('.grid-item');
|
|
32
|
+
* const byId = Utils.getElements('#myWidget');
|
|
33
|
+
* const fromShadow = Utils.getElements('.item', shadowRoot);
|
|
34
|
+
*/
|
|
35
|
+
static getElements(els: GridStackElement, root?: HTMLElement | Document): HTMLElement[];
|
|
36
|
+
/**
|
|
37
|
+
* Convert a potential selector into a single HTML element.
|
|
38
|
+
* Similar to getElements() but returns only the first match.
|
|
39
|
+
*
|
|
40
|
+
* @param els selector string or HTMLElement
|
|
41
|
+
* @param root optional root element to search within (defaults to document)
|
|
42
|
+
* @returns the first HTML element matching the selector, or null if not found
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const element = Utils.getElement('#myWidget');
|
|
46
|
+
* const first = Utils.getElement('.grid-item');
|
|
47
|
+
*/
|
|
48
|
+
static getElement(els: GridStackElement, root?: HTMLElement | Document): HTMLElement;
|
|
49
|
+
/**
|
|
50
|
+
* Check if a widget should be lazy loaded based on node or grid settings.
|
|
51
|
+
*
|
|
52
|
+
* @param n the grid node to check
|
|
53
|
+
* @returns true if the item should be lazy loaded
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* if (Utils.lazyLoad(node)) {
|
|
57
|
+
* // Set up intersection observer for lazy loading
|
|
58
|
+
* }
|
|
59
|
+
*/
|
|
60
|
+
static lazyLoad(n: GridStackNode): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Create a div element with the specified CSS classes.
|
|
63
|
+
*
|
|
64
|
+
* @param classes array of CSS class names to add
|
|
65
|
+
* @param parent optional parent element to append the div to
|
|
66
|
+
* @returns the created div element
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const div = Utils.createDiv(['grid-item', 'draggable']);
|
|
70
|
+
* const nested = Utils.createDiv(['content'], parentDiv);
|
|
71
|
+
*/
|
|
72
|
+
static createDiv(classes: string[], parent?: HTMLElement): HTMLElement;
|
|
73
|
+
/**
|
|
74
|
+
* Check if a widget should resize to fit its content.
|
|
75
|
+
*
|
|
76
|
+
* @param n the grid node to check (can be undefined)
|
|
77
|
+
* @param strict if true, only returns true for explicit sizeToContent:true (not numbers)
|
|
78
|
+
* @returns true if the widget should resize to content
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* if (Utils.shouldSizeToContent(node)) {
|
|
82
|
+
* // Trigger content-based resizing
|
|
83
|
+
* }
|
|
84
|
+
*/
|
|
85
|
+
static shouldSizeToContent(n: GridStackNode | undefined, strict?: boolean): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Check if two grid positions overlap/intersect.
|
|
88
|
+
*
|
|
89
|
+
* @param a first position with x, y, w, h properties
|
|
90
|
+
* @param b second position with x, y, w, h properties
|
|
91
|
+
* @returns true if the positions overlap
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* const overlaps = Utils.isIntercepted(
|
|
95
|
+
* {x: 0, y: 0, w: 2, h: 1},
|
|
96
|
+
* {x: 1, y: 0, w: 2, h: 1}
|
|
97
|
+
* ); // true - they overlap
|
|
98
|
+
*/
|
|
99
|
+
static isIntercepted(a: GridStackPosition, b: GridStackPosition): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Check if two grid positions are touching (edges or corners).
|
|
102
|
+
*
|
|
103
|
+
* @param a first position
|
|
104
|
+
* @param b second position
|
|
105
|
+
* @returns true if the positions are touching
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* const touching = Utils.isTouching(
|
|
109
|
+
* {x: 0, y: 0, w: 2, h: 1},
|
|
110
|
+
* {x: 2, y: 0, w: 1, h: 1}
|
|
111
|
+
* ); // true - they share an edge
|
|
112
|
+
*/
|
|
113
|
+
static isTouching(a: GridStackPosition, b: GridStackPosition): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Calculate the overlapping area between two grid positions.
|
|
116
|
+
*
|
|
117
|
+
* @param a first position
|
|
118
|
+
* @param b second position
|
|
119
|
+
* @returns the area of overlap (0 if no overlap)
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* const overlap = Utils.areaIntercept(
|
|
123
|
+
* {x: 0, y: 0, w: 3, h: 2},
|
|
124
|
+
* {x: 1, y: 0, w: 3, h: 2}
|
|
125
|
+
* ); // returns 4 (2x2 overlap)
|
|
126
|
+
*/
|
|
127
|
+
static areaIntercept(a: GridStackPosition, b: GridStackPosition): number;
|
|
128
|
+
/**
|
|
129
|
+
* Calculate the total area of a grid position.
|
|
130
|
+
*
|
|
131
|
+
* @param a position with width and height
|
|
132
|
+
* @returns the total area (width * height)
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* const area = Utils.area({x: 0, y: 0, w: 3, h: 2}); // returns 6
|
|
136
|
+
*/
|
|
137
|
+
static area(a: GridStackPosition): number;
|
|
138
|
+
/**
|
|
139
|
+
* Sort an array of grid nodes by position (y first, then x).
|
|
140
|
+
*
|
|
141
|
+
* @param nodes array of nodes to sort
|
|
142
|
+
* @param dir sort direction: 1 for ascending (top-left first), -1 for descending
|
|
143
|
+
* @returns the sorted array (modifies original)
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* const sorted = Utils.sort(nodes); // Sort top-left to bottom-right
|
|
147
|
+
* const reverse = Utils.sort(nodes, -1); // Sort bottom-right to top-left
|
|
148
|
+
*/
|
|
149
|
+
static sort(nodes: GridStackNode[], dir?: 1 | -1): GridStackNode[];
|
|
150
|
+
/**
|
|
151
|
+
* Find a grid node by its ID.
|
|
152
|
+
*
|
|
153
|
+
* @param nodes array of nodes to search
|
|
154
|
+
* @param id the ID to search for
|
|
155
|
+
* @returns the node with matching ID, or undefined if not found
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const node = Utils.find(nodes, 'widget-1');
|
|
159
|
+
* if (node) console.log('Found node at:', node.x, node.y);
|
|
160
|
+
*/
|
|
161
|
+
static find(nodes: GridStackNode[], id: string): GridStackNode | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Convert various value types to boolean.
|
|
164
|
+
* Handles strings like 'false', 'no', '0' as false.
|
|
165
|
+
*
|
|
166
|
+
* @param v value to convert
|
|
167
|
+
* @returns boolean representation
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* Utils.toBool('true'); // true
|
|
171
|
+
* Utils.toBool('false'); // false
|
|
172
|
+
* Utils.toBool('no'); // false
|
|
173
|
+
* Utils.toBool('1'); // true
|
|
174
|
+
*/
|
|
175
|
+
static toBool(v: unknown): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Convert a string value to a number, handling null and empty strings.
|
|
178
|
+
*
|
|
179
|
+
* @param value string or null value to convert
|
|
180
|
+
* @returns number value, or undefined for null/empty strings
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* Utils.toNumber('42'); // 42
|
|
184
|
+
* Utils.toNumber(''); // undefined
|
|
185
|
+
* Utils.toNumber(null); // undefined
|
|
186
|
+
*/
|
|
187
|
+
static toNumber(value: null | string): number;
|
|
188
|
+
/**
|
|
189
|
+
* Parse a height value with units into numeric value and unit string.
|
|
190
|
+
* Supports px, em, rem, vh, vw, %, cm, mm units.
|
|
191
|
+
*
|
|
192
|
+
* @param val height value as number or string with units
|
|
193
|
+
* @returns object with h (height) and unit properties
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* Utils.parseHeight('100px'); // {h: 100, unit: 'px'}
|
|
197
|
+
* Utils.parseHeight('2rem'); // {h: 2, unit: 'rem'}
|
|
198
|
+
* Utils.parseHeight(50); // {h: 50, unit: 'px'}
|
|
199
|
+
*/
|
|
200
|
+
static parseHeight(val: numberOrString): HeightData;
|
|
201
|
+
/**
|
|
202
|
+
* Copy unset fields from source objects to target object (shallow merge with defaults).
|
|
203
|
+
* Similar to Object.assign but only sets undefined/null fields.
|
|
204
|
+
*
|
|
205
|
+
* @param target the object to copy defaults into
|
|
206
|
+
* @param sources one or more source objects to copy defaults from
|
|
207
|
+
* @returns the modified target object
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* const config = { width: 100 };
|
|
211
|
+
* Utils.defaults(config, { width: 200, height: 50 });
|
|
212
|
+
* // config is now { width: 100, height: 50 }
|
|
213
|
+
*/
|
|
214
|
+
static defaults(target: any, ...sources: any[]): {};
|
|
215
|
+
/**
|
|
216
|
+
* Compare two objects for equality (shallow comparison).
|
|
217
|
+
* Checks if objects have the same fields and values at one level deep.
|
|
218
|
+
*
|
|
219
|
+
* @param a first object to compare
|
|
220
|
+
* @param b second object to compare
|
|
221
|
+
* @returns true if objects have the same values
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* Utils.same({x: 1, y: 2}, {x: 1, y: 2}); // true
|
|
225
|
+
* Utils.same({x: 1}, {x: 1, y: 2}); // false
|
|
226
|
+
*/
|
|
227
|
+
static same(a: unknown, b: unknown): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Copy position and size properties from one widget to another.
|
|
230
|
+
* Copies x, y, w, h and optionally min/max constraints.
|
|
231
|
+
*
|
|
232
|
+
* @param a target widget to copy to
|
|
233
|
+
* @param b source widget to copy from
|
|
234
|
+
* @param doMinMax if true, also copy min/max width/height constraints
|
|
235
|
+
* @returns the target widget (a)
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* Utils.copyPos(widget1, widget2); // Copy position/size
|
|
239
|
+
* Utils.copyPos(widget1, widget2, true); // Also copy constraints
|
|
240
|
+
*/
|
|
241
|
+
static copyPos(a: GridStackWidget, b: GridStackWidget, doMinMax?: boolean): GridStackWidget;
|
|
242
|
+
/** true if a and b has same size & position */
|
|
243
|
+
static samePos(a: GridStackPosition, b: GridStackPosition): boolean;
|
|
244
|
+
/** given a node, makes sure it's min/max are valid */
|
|
245
|
+
static sanitizeMinMax(node: GridStackNode): void;
|
|
246
|
+
/** removes field from the first object if same as the second objects (like diffing) and internal '_' for saving */
|
|
247
|
+
static removeInternalAndSame(a: unknown, b: unknown): void;
|
|
248
|
+
/** removes internal fields '_' and default values for saving */
|
|
249
|
+
static removeInternalForSave(n: GridStackNode, removeEl?: boolean): void;
|
|
250
|
+
/** return the closest parent (or itself) matching the given class */
|
|
251
|
+
/** delay calling the given function for given delay, preventing new calls from happening while waiting */
|
|
252
|
+
static throttle(func: () => void, delay: number): () => void;
|
|
253
|
+
static removePositioningStyles(el: HTMLElement): void;
|
|
254
|
+
/** single level clone, returning a new object with same top fields. This will share sub objects and arrays */
|
|
255
|
+
static clone<T>(obj: T): T;
|
|
256
|
+
/**
|
|
257
|
+
* Recursive clone version that returns a full copy, checking for nested objects and arrays ONLY.
|
|
258
|
+
* Note: this will use as-is any key starting with double __ (and not copy inside) some lib have circular dependencies.
|
|
259
|
+
*/
|
|
260
|
+
static cloneDeep<T>(obj: T): T;
|
|
261
|
+
/** deep clone the given HTML node, removing teh unique id field */
|
|
262
|
+
static cloneNode(el: HTMLElement): HTMLElement;
|
|
263
|
+
static appendTo(el: HTMLElement, parent: string | HTMLElement): void;
|
|
264
|
+
static addElStyles(el: HTMLElement, styles: {
|
|
265
|
+
[prop: string]: string | string[];
|
|
266
|
+
}): void;
|
|
267
|
+
static initEvent<T>(e: DragEvent | MouseEvent, info: {
|
|
268
|
+
type: string;
|
|
269
|
+
target?: EventTarget;
|
|
270
|
+
}): T;
|
|
271
|
+
/** copies the MouseEvent (or convert Touch) properties and sends it as another event to the given target */
|
|
272
|
+
static simulateMouseEvent(e: MouseEvent | Touch, simulatedType: string, target?: EventTarget): void;
|
|
273
|
+
/**
|
|
274
|
+
* defines an element that is used to get the offset and scale from grid transforms
|
|
275
|
+
* returns the scale and offsets from said element
|
|
276
|
+
*/
|
|
277
|
+
static getValuesFromTransformedElement(parent: HTMLElement): DragTransform;
|
|
278
|
+
/** swap the given object 2 field values */
|
|
279
|
+
static swap(o: unknown, a: string, b: string): void;
|
|
280
|
+
/** returns true if event is inside the given element rectangle */
|
|
281
|
+
/** true if the item can be rotated (checking for prop, not space available) */
|
|
282
|
+
static canBeRotated(n: GridStackNode): boolean;
|
|
283
|
+
}
|