@sguisse/react-grid-layout 2.2.3-sguisse.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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -0
  3. package/css/styles.css +120 -0
  4. package/dist/ResponsiveGridLayout-B_6TXsWM.d.ts +80 -0
  5. package/dist/ResponsiveGridLayout-Bin5MBC3.d.mts +80 -0
  6. package/dist/calculate-CoBSgofg.d.mts +196 -0
  7. package/dist/calculate-K0IBpu53.d.ts +196 -0
  8. package/dist/chunk-7BT7XXIT.js +74 -0
  9. package/dist/chunk-G3PAJYGP.mjs +72 -0
  10. package/dist/chunk-ITLZ7N2R.mjs +456 -0
  11. package/dist/chunk-J4LTYI7L.js +485 -0
  12. package/dist/chunk-KKV4ZCG4.mjs +583 -0
  13. package/dist/chunk-LQOPWRJR.js +623 -0
  14. package/dist/chunk-O3KX3VYW.mjs +1 -0
  15. package/dist/chunk-STBCV65G.js +3159 -0
  16. package/dist/chunk-UZL6BMXQ.mjs +3146 -0
  17. package/dist/chunk-ZJHF4QM5.js +2 -0
  18. package/dist/core.d.mts +160 -0
  19. package/dist/core.d.ts +160 -0
  20. package/dist/core.js +268 -0
  21. package/dist/core.mjs +3 -0
  22. package/dist/extras.d.mts +208 -0
  23. package/dist/extras.d.ts +208 -0
  24. package/dist/extras.js +388 -0
  25. package/dist/extras.mjs +380 -0
  26. package/dist/index.d.mts +7 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/index.js +152 -0
  29. package/dist/index.mjs +5 -0
  30. package/dist/legacy.d.mts +163 -0
  31. package/dist/legacy.d.ts +163 -0
  32. package/dist/legacy.js +331 -0
  33. package/dist/legacy.mjs +319 -0
  34. package/dist/position-BeP60S5h.d.ts +316 -0
  35. package/dist/position-CeG3Nr4z.d.mts +316 -0
  36. package/dist/react.d.mts +214 -0
  37. package/dist/react.d.ts +214 -0
  38. package/dist/react.js +94 -0
  39. package/dist/react.mjs +5 -0
  40. package/dist/responsive-D4zBXLkH.d.ts +145 -0
  41. package/dist/responsive-DQi_9rBi.d.mts +145 -0
  42. package/dist/types-Dbg8jAWj.d.mts +458 -0
  43. package/dist/types-Dbg8jAWj.d.ts +458 -0
  44. package/index-dev.js +23 -0
  45. package/index.js +8 -0
  46. package/package.json +238 -0
@@ -0,0 +1,458 @@
1
+ /**
2
+ * Core types for react-grid-layout v2
3
+ *
4
+ * These types are framework-agnostic and define the data structures
5
+ * used by the layout algorithms.
6
+ */
7
+ /**
8
+ * Axis identifiers for resize handles.
9
+ * - Cardinal: 'n', 's', 'e', 'w' (north, south, east, west)
10
+ * - Diagonal: 'ne', 'nw', 'se', 'sw'
11
+ */
12
+ type ResizeHandleAxis = "s" | "w" | "e" | "n" | "sw" | "nw" | "se" | "ne";
13
+ /**
14
+ * A single item in the grid layout.
15
+ *
16
+ * Position (x, y) is in grid units, not pixels.
17
+ * Size (w, h) is in grid units.
18
+ */
19
+ interface LayoutItem {
20
+ /** Unique identifier for this item */
21
+ i: string;
22
+ /** X position in grid units (0-indexed from left) */
23
+ x: number;
24
+ /** Y position in grid units (0-indexed from top) */
25
+ y: number;
26
+ /** Width in grid units */
27
+ w: number;
28
+ /** Height in grid units */
29
+ h: number;
30
+ /** Minimum width in grid units */
31
+ minW?: number;
32
+ /** Minimum height in grid units */
33
+ minH?: number;
34
+ /** Maximum width in grid units */
35
+ maxW?: number;
36
+ /** Maximum height in grid units */
37
+ maxH?: number;
38
+ /**
39
+ * If true, item cannot be dragged or resized, and other items
40
+ * will move around it during compaction.
41
+ */
42
+ static?: boolean;
43
+ /**
44
+ * If false, item cannot be dragged (but may still be resizable).
45
+ * Overrides grid-level isDraggable for this item.
46
+ */
47
+ isDraggable?: boolean;
48
+ /**
49
+ * If false, item cannot be resized (but may still be draggable).
50
+ * Overrides grid-level isResizable for this item.
51
+ */
52
+ isResizable?: boolean;
53
+ /**
54
+ * Which resize handles to show for this item.
55
+ * Overrides grid-level resizeHandles for this item.
56
+ */
57
+ resizeHandles?: ResizeHandleAxis[];
58
+ /**
59
+ * If true, item is constrained to the grid container bounds.
60
+ * Overrides grid-level isBounded for this item.
61
+ */
62
+ isBounded?: boolean;
63
+ /**
64
+ * Internal flag set during drag/resize operations to indicate
65
+ * the item has moved from its original position.
66
+ * @internal
67
+ */
68
+ moved?: boolean;
69
+ /**
70
+ * Per-item layout constraints.
71
+ * Applied in addition to grid-level constraints.
72
+ */
73
+ constraints?: LayoutConstraint[];
74
+ }
75
+ /**
76
+ * A layout is a readonly array of layout items.
77
+ * Layouts should be treated as immutable.
78
+ */
79
+ type Layout = readonly LayoutItem[];
80
+ /**
81
+ * Pixel position and size of an element.
82
+ */
83
+ interface Position {
84
+ left: number;
85
+ top: number;
86
+ width: number;
87
+ height: number;
88
+ }
89
+ /**
90
+ * Partial position (just coordinates, no size).
91
+ */
92
+ interface PartialPosition {
93
+ left: number;
94
+ top: number;
95
+ }
96
+ /**
97
+ * Size in pixels.
98
+ */
99
+ interface Size {
100
+ width: number;
101
+ height: number;
102
+ }
103
+ /**
104
+ * Position when dropping an external element onto the grid.
105
+ */
106
+ interface DroppingPosition {
107
+ left: number;
108
+ top: number;
109
+ e: Event;
110
+ }
111
+ /**
112
+ * Legacy-compatible drag callback data shape used during drag operations.
113
+ */
114
+ interface ReactDraggableCallbackData {
115
+ node: HTMLElement;
116
+ x?: number;
117
+ y?: number;
118
+ deltaX: number;
119
+ deltaY: number;
120
+ lastX?: number;
121
+ lastY?: number;
122
+ }
123
+ /**
124
+ * Grid-level drag event data.
125
+ */
126
+ interface GridDragEvent {
127
+ e: Event;
128
+ node: HTMLElement;
129
+ newPosition: PartialPosition;
130
+ }
131
+ /**
132
+ * Grid-level resize event data.
133
+ */
134
+ interface GridResizeEvent {
135
+ e: Event;
136
+ node: HTMLElement;
137
+ size: Size;
138
+ handle: ResizeHandleAxis;
139
+ }
140
+ /**
141
+ * Drag-over event with layer coordinates.
142
+ */
143
+ interface DragOverEvent extends MouseEvent {
144
+ nativeEvent: Event & {
145
+ layerX: number;
146
+ layerY: number;
147
+ };
148
+ }
149
+ /**
150
+ * Type of compaction to apply to the layout.
151
+ * - 'vertical': Items compact upward (default)
152
+ * - 'horizontal': Items compact leftward
153
+ * - 'wrap': Items arranged in wrapped-paragraph style (like words in text)
154
+ * - null: No compaction (free-form positioning)
155
+ */
156
+ type CompactType = "horizontal" | "vertical" | "wrap" | null;
157
+ /**
158
+ * Standard callback signature for layout change events.
159
+ *
160
+ * @param layout - The current layout after the change
161
+ * @param oldItem - The item before the change (null if not applicable)
162
+ * @param newItem - The item after the change (null if not applicable)
163
+ * @param placeholder - The placeholder item during drag/resize (null at start)
164
+ * @param event - The DOM event that triggered the change
165
+ * @param element - The DOM element being manipulated (null if not applicable)
166
+ */
167
+ type EventCallback = (layout: Layout, oldItem: LayoutItem | null, newItem: LayoutItem | null, placeholder: LayoutItem | null, event: Event, element: HTMLElement | null) => void;
168
+ /**
169
+ * Callback when layout changes for any reason.
170
+ */
171
+ type OnLayoutChangeCallback = (layout: Layout) => void;
172
+ /**
173
+ * Interface for layout compaction strategies.
174
+ *
175
+ * Implement this interface to create custom compaction algorithms.
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * const myCompactor: Compactor = {
180
+ * type: 'vertical',
181
+ * allowOverlap: false,
182
+ * compact(layout, cols) {
183
+ * // Custom compaction logic
184
+ * return compactedLayout;
185
+ * }
186
+ * };
187
+ * ```
188
+ */
189
+ interface Compactor {
190
+ /** Compaction type identifier */
191
+ readonly type: CompactType;
192
+ /**
193
+ * Whether items can overlap (stack on top of each other).
194
+ *
195
+ * When true:
196
+ * - Items can be placed on top of other items
197
+ * - Dragging into another item does NOT push it away
198
+ * - Compaction is skipped after drag/resize
199
+ */
200
+ readonly allowOverlap: boolean;
201
+ /**
202
+ * Whether to block movement that would cause collision.
203
+ *
204
+ * When true (and allowOverlap is false):
205
+ * - Dragging into another item is blocked (item snaps back)
206
+ * - Other items are NOT pushed away
207
+ * - Only affects drag/resize, not compaction
208
+ *
209
+ * Has no effect when allowOverlap is true.
210
+ */
211
+ readonly preventCollision?: boolean;
212
+ /**
213
+ * Compact the layout.
214
+ *
215
+ * @param layout - The layout to compact
216
+ * @param cols - Number of columns in the grid
217
+ * @returns The compacted layout
218
+ */
219
+ compact(layout: Layout, cols: number): Layout;
220
+ }
221
+ /**
222
+ * Interface for CSS positioning strategies.
223
+ *
224
+ * Implement this interface to customize how items are positioned in the DOM.
225
+ * Built-in strategies: transformStrategy, absoluteStrategy.
226
+ *
227
+ * @example
228
+ * ```typescript
229
+ * // Use transform-based positioning (default, better performance)
230
+ * <GridLayout positionStrategy={transformStrategy} />
231
+ *
232
+ * // Use top/left positioning (for environments where transforms cause issues)
233
+ * <GridLayout positionStrategy={absoluteStrategy} />
234
+ *
235
+ * // Use scaled transforms (for scaled containers)
236
+ * <GridLayout positionStrategy={createScaledStrategy(0.5)} />
237
+ * ```
238
+ */
239
+ interface PositionStrategy {
240
+ /** Strategy type identifier */
241
+ readonly type: "transform" | "absolute";
242
+ /** Scale factor for drag/resize calculations */
243
+ readonly scale: number;
244
+ /**
245
+ * Convert pixel position to CSS style object.
246
+ *
247
+ * @param pos - Position in pixels
248
+ * @returns CSS properties for positioning the element
249
+ */
250
+ calcStyle(pos: Position): React.CSSProperties;
251
+ /**
252
+ * Calculate position during drag operations, accounting for transforms and scale.
253
+ *
254
+ * This method is optional. When not provided, react-draggable uses its built-in
255
+ * parent-relative coordinate calculation. Only override this when you need custom
256
+ * coordinate handling, such as for scaled containers.
257
+ *
258
+ * @param clientX - Mouse client X position
259
+ * @param clientY - Mouse client Y position
260
+ * @param offsetX - Offset from element origin X
261
+ * @param offsetY - Offset from element origin Y
262
+ * @returns Adjusted left/top position
263
+ */
264
+ calcDragPosition?(clientX: number, clientY: number, offsetX: number, offsetY: number): PartialPosition;
265
+ }
266
+ /**
267
+ * Context provided to constraint functions during drag/resize operations.
268
+ */
269
+ interface ConstraintContext {
270
+ /** Number of columns in the grid */
271
+ cols: number;
272
+ /** Maximum number of rows (Infinity if unbounded) */
273
+ maxRows: number;
274
+ /** Container width in pixels */
275
+ containerWidth: number;
276
+ /** Container height in pixels (may be 0 if auto-height) */
277
+ containerHeight: number;
278
+ /** Row height in pixels */
279
+ rowHeight: number;
280
+ /** Margin between items [x, y] in pixels */
281
+ margin: readonly [number, number];
282
+ /** Current layout state */
283
+ layout: Layout;
284
+ }
285
+ /**
286
+ * Interface for layout constraints.
287
+ *
288
+ * Implement this interface to create custom position/size constraints.
289
+ * Built-in constraints: gridBounds, minMaxSize, containerBounds, boundedX, boundedY.
290
+ *
291
+ * @example
292
+ * ```typescript
293
+ * // Grid-level constraints
294
+ * <GridLayout constraints={[gridBounds, minMaxSize, aspectRatio(16/9)]} />
295
+ *
296
+ * // Per-item constraints
297
+ * const layout = [
298
+ * { i: 'video', x: 0, y: 0, w: 4, h: 2, constraints: [aspectRatio(16/9)] }
299
+ * ];
300
+ * ```
301
+ */
302
+ interface LayoutConstraint {
303
+ /** Constraint identifier for debugging */
304
+ readonly name: string;
305
+ /**
306
+ * Constrain position during drag operations.
307
+ * Called after grid unit conversion, before layout update.
308
+ *
309
+ * @param item - The item being dragged
310
+ * @param x - Proposed x position in grid units
311
+ * @param y - Proposed y position in grid units
312
+ * @param context - Grid context (cols, maxRows, etc.)
313
+ * @returns Constrained x, y position
314
+ */
315
+ constrainPosition?(item: LayoutItem, x: number, y: number, context: ConstraintContext): {
316
+ x: number;
317
+ y: number;
318
+ };
319
+ /**
320
+ * Constrain size during resize operations.
321
+ * Called after grid unit conversion, before layout update.
322
+ *
323
+ * @param item - The item being resized
324
+ * @param w - Proposed width in grid units
325
+ * @param h - Proposed height in grid units
326
+ * @param handle - Which resize handle is being used
327
+ * @param context - Grid context (cols, maxRows, etc.)
328
+ * @returns Constrained w, h size
329
+ */
330
+ constrainSize?(item: LayoutItem, w: number, h: number, handle: ResizeHandleAxis, context: ConstraintContext): {
331
+ w: number;
332
+ h: number;
333
+ };
334
+ }
335
+ /**
336
+ * Grid measurement configuration.
337
+ * Groups all grid metrics (columns, row height, margins).
338
+ */
339
+ interface GridConfig {
340
+ /** Number of columns in the grid (default: 12) */
341
+ cols: number;
342
+ /** Height of a single row in pixels (default: 150) */
343
+ rowHeight: number;
344
+ /** [horizontal, vertical] margin between items in pixels (default: [10, 10]) */
345
+ margin: readonly [number, number];
346
+ /** [horizontal, vertical] padding inside the container (default: null, uses margin) */
347
+ containerPadding: readonly [number, number] | null;
348
+ /** Maximum number of rows (default: Infinity) */
349
+ maxRows: number;
350
+ }
351
+ /** Default grid configuration */
352
+ declare const defaultGridConfig: GridConfig;
353
+ /**
354
+ * Drag behavior configuration.
355
+ * Groups all drag-related settings.
356
+ */
357
+ interface DragConfig {
358
+ /** Whether items can be dragged (default: true) */
359
+ enabled: boolean;
360
+ /** Whether items are bounded to the container (default: false) */
361
+ bounded: boolean;
362
+ /** CSS selector for drag handle (e.g., '.drag-handle') */
363
+ handle?: string;
364
+ /** CSS selector for elements that should not trigger drag */
365
+ cancel?: string;
366
+ /**
367
+ * Minimum pixels to move before drag starts.
368
+ * Helps distinguish click from drag (fixes #1341, #1401).
369
+ * @default 3
370
+ */
371
+ threshold: number;
372
+ }
373
+ /** Default drag configuration */
374
+ declare const defaultDragConfig: DragConfig;
375
+ /**
376
+ * Resize behavior configuration.
377
+ * Groups all resize-related settings.
378
+ */
379
+ interface ResizeConfig {
380
+ /** Whether items can be resized (default: true) */
381
+ enabled: boolean;
382
+ /** Which resize handles to show (default: ['se']) */
383
+ handles: readonly ResizeHandleAxis[];
384
+ /**
385
+ * Custom resize handle component.
386
+ * Can be a React node or a function that receives the axis.
387
+ */
388
+ handleComponent?: React.ReactNode | ((axis: ResizeHandleAxis, ref: React.Ref<HTMLElement>) => React.ReactNode);
389
+ }
390
+ /** Default resize configuration */
391
+ declare const defaultResizeConfig: ResizeConfig;
392
+ /**
393
+ * Drop configuration (for dropping external elements).
394
+ * Groups all drop-related settings.
395
+ */
396
+ interface DropConfig {
397
+ /** Whether external elements can be dropped on the grid (default: false) */
398
+ enabled: boolean;
399
+ /** Default size for dropped items (default: { w: 1, h: 1 }) */
400
+ defaultItem: {
401
+ w: number;
402
+ h: number;
403
+ };
404
+ /**
405
+ * Called when dragging over the grid.
406
+ * Return dimensions to override defaultItem, or false to reject the drop.
407
+ * Can also return dragOffsetX/dragOffsetY to specify cursor offset for centering.
408
+ */
409
+ onDragOver?: (e: DragEvent) => {
410
+ w?: number;
411
+ h?: number;
412
+ dragOffsetX?: number;
413
+ dragOffsetY?: number;
414
+ } | false | void;
415
+ }
416
+ /** Default drop configuration */
417
+ declare const defaultDropConfig: DropConfig;
418
+ /**
419
+ * Breakpoint name (e.g., 'lg', 'md', 'sm', 'xs', 'xxs').
420
+ */
421
+ type Breakpoint = string;
422
+ /**
423
+ * Map of breakpoint name to pixel width.
424
+ * Generic type B allows custom breakpoint strings.
425
+ */
426
+ type Breakpoints<B extends Breakpoint = Breakpoint> = Record<B, number>;
427
+ /**
428
+ * Map of breakpoint name to number of columns.
429
+ * Generic type B allows custom breakpoint strings.
430
+ */
431
+ type BreakpointCols<B extends Breakpoint = Breakpoint> = Record<B, number>;
432
+ /**
433
+ * Map of breakpoint name to layout.
434
+ * Generic type B allows custom breakpoint strings.
435
+ */
436
+ type ResponsiveLayouts<B extends Breakpoint = Breakpoint> = Partial<Record<B, Layout>>;
437
+ /**
438
+ * Callback when breakpoint changes.
439
+ */
440
+ type OnBreakpointChangeCallback<B extends Breakpoint = Breakpoint> = (newBreakpoint: B, cols: number) => void;
441
+ /**
442
+ * Makes all properties in T mutable (removes readonly).
443
+ */
444
+ type Mutable<T> = {
445
+ -readonly [P in keyof T]: T[P];
446
+ };
447
+ /**
448
+ * Deep partial - all properties and nested properties are optional.
449
+ */
450
+ type DeepPartial<T> = {
451
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
452
+ };
453
+ /**
454
+ * Extract the element type from an array type.
455
+ */
456
+ type ArrayElement<T> = T extends readonly (infer U)[] ? U : never;
457
+
458
+ export { type ArrayElement as A, type Breakpoint as B, type CompactType as C, type DroppingPosition as D, type EventCallback as E, type GridDragEvent as G, type Layout as L, type Mutable as M, type OnBreakpointChangeCallback as O, type Position as P, type ResizeHandleAxis as R, type Size as S, type Breakpoints as a, type Compactor as b, type GridResizeEvent as c, type LayoutItem as d, type ResponsiveLayouts as e, type LayoutConstraint as f, type ConstraintContext as g, type BreakpointCols as h, type DeepPartial as i, type DragConfig as j, type DragOverEvent as k, type DropConfig as l, type GridConfig as m, type OnLayoutChangeCallback as n, type PartialPosition as o, type PositionStrategy as p, type ReactDraggableCallbackData as q, type ResizeConfig as r, defaultDragConfig as s, defaultDropConfig as t, defaultGridConfig as u, defaultResizeConfig as v };