react-grid-layout 2.2.3 → 2.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 (40) hide show
  1. package/README.md +5 -0
  2. package/dist/{ResponsiveGridLayout-BjVraYMQ.d.mts → ResponsiveGridLayout-BSYEMZ9d.d.ts} +4 -4
  3. package/dist/{ResponsiveGridLayout-BrhkSyZk.d.ts → ResponsiveGridLayout-RNuyRTPe.d.mts} +4 -4
  4. package/dist/{calculate-DH4EVtn1.d.mts → calculate-BXoe3Mfz.d.mts} +1 -1
  5. package/dist/{calculate-rP3DHexe.d.ts → calculate-Tc1WkIxl.d.ts} +1 -1
  6. package/dist/{chunk-BPZQUJ7Y.js → chunk-CUP5Y2ZG.js} +500 -155
  7. package/dist/{chunk-55DQUWLA.js → chunk-QAIA5KAO.js} +33 -22
  8. package/dist/{chunk-7MZZ6T4J.js → chunk-SL4EZ2NU.js} +67 -38
  9. package/dist/{chunk-PZLKKWSX.mjs → chunk-TW4BCTKD.mjs} +37 -8
  10. package/dist/{chunk-KDANGDDL.mjs → chunk-VBU6B7II.mjs} +13 -2
  11. package/dist/{chunk-A5WIFECI.js → chunk-VJJIA3HC.js} +7 -3
  12. package/dist/{chunk-WGL5FSZH.mjs → chunk-Z6CWRR74.mjs} +431 -86
  13. package/dist/{chunk-76RTO6EO.mjs → chunk-ZYNFVPDS.mjs} +7 -3
  14. package/dist/core.d.mts +5 -5
  15. package/dist/core.d.ts +5 -5
  16. package/dist/core.js +67 -67
  17. package/dist/core.mjs +2 -2
  18. package/dist/extras.d.mts +2 -2
  19. package/dist/extras.d.ts +2 -2
  20. package/dist/extras.js +8 -8
  21. package/dist/extras.mjs +1 -1
  22. package/dist/index.d.mts +5 -5
  23. package/dist/index.d.ts +5 -5
  24. package/dist/index.js +39 -39
  25. package/dist/index.mjs +4 -4
  26. package/dist/legacy.d.mts +18 -9
  27. package/dist/legacy.d.ts +18 -9
  28. package/dist/legacy.js +35 -25
  29. package/dist/legacy.mjs +18 -9
  30. package/dist/{position-CSgQSjwQ.d.ts → position-VdYnMJql.d.ts} +1 -1
  31. package/dist/{position-BV-g3Ezg.d.mts → position-iPly-ecb.d.mts} +1 -1
  32. package/dist/react.d.mts +24 -6
  33. package/dist/react.d.ts +24 -6
  34. package/dist/react.js +25 -25
  35. package/dist/react.mjs +4 -4
  36. package/dist/{responsive-BrTV_0tK.d.mts → responsive-BVtXrrTF.d.mts} +1 -1
  37. package/dist/{responsive-C_YtBQYq.d.ts → responsive-C6s9JAJU.d.ts} +1 -1
  38. package/dist/{types-jd8MiKM1.d.mts → types-DlzNckle.d.mts} +22 -0
  39. package/dist/{types-jd8MiKM1.d.ts → types-DlzNckle.d.ts} +22 -0
  40. package/package.json +3 -2
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkA5WIFECI_js = require('./chunk-A5WIFECI.js');
3
+ var chunkVJJIA3HC_js = require('./chunk-VJJIA3HC.js');
4
4
 
5
5
  // src/core/constraints.ts
6
6
  function clamp(value, min, max) {
@@ -40,6 +40,15 @@ var containerBounds = {
40
40
  x: clamp(x, 0, Math.max(0, cols - item.w)),
41
41
  y: clamp(y, 0, Math.max(0, visibleRows - item.h))
42
42
  };
43
+ },
44
+ constrainSize(item, w, h, handle, { cols, maxRows, containerHeight, rowHeight, margin }) {
45
+ const visibleRows = containerHeight > 0 ? Math.floor((containerHeight + margin[1]) / (rowHeight + margin[1])) : maxRows;
46
+ const maxW = handle === "w" || handle === "nw" || handle === "sw" ? item.x + item.w : cols - item.x;
47
+ const maxH = handle === "n" || handle === "nw" || handle === "ne" ? item.y + item.h : visibleRows - item.y;
48
+ return {
49
+ w: clamp(w, 1, Math.max(1, maxW)),
50
+ h: clamp(h, 1, Math.max(1, maxH))
51
+ };
43
52
  }
44
53
  };
45
54
  var boundedX = {
@@ -343,7 +352,9 @@ var defaultResizeConfig = {
343
352
  };
344
353
  var defaultDropConfig = {
345
354
  enabled: false,
346
- defaultItem: { w: 1, h: 1 }
355
+ defaultItem: { w: 1, h: 1 },
356
+ touchEnabled: true,
357
+ touchDragSource: "[data-rgl-draggable]"
347
358
  };
348
359
 
349
360
  // src/core/compactors.ts
@@ -351,13 +362,13 @@ function resolveCompactionCollision(layout, item, moveToCoord, axis, hasStatics)
351
362
  const sizeProp = axis === "x" ? "w" : "h";
352
363
  item[axis] += 1;
353
364
  const itemIndex = layout.findIndex((l) => l.i === item.i);
354
- const layoutHasStatics = hasStatics ?? chunkA5WIFECI_js.getStatics(layout).length > 0;
365
+ const layoutHasStatics = hasStatics ?? chunkVJJIA3HC_js.getStatics(layout).length > 0;
355
366
  for (let i = itemIndex + 1; i < layout.length; i++) {
356
367
  const otherItem = layout[i];
357
368
  if (otherItem === void 0) continue;
358
369
  if (otherItem.static) continue;
359
370
  if (!layoutHasStatics && otherItem.y > item.y + item.h) break;
360
- if (chunkA5WIFECI_js.collides(item, otherItem)) {
371
+ if (chunkVJJIA3HC_js.collides(item, otherItem)) {
361
372
  resolveCompactionCollision(
362
373
  layout,
363
374
  otherItem,
@@ -373,11 +384,11 @@ function compactItemVertical(compareWith, l, fullLayout, maxY) {
373
384
  l.x = Math.max(l.x, 0);
374
385
  l.y = Math.max(l.y, 0);
375
386
  l.y = Math.min(maxY, l.y);
376
- while (l.y > 0 && !chunkA5WIFECI_js.getFirstCollision(compareWith, l)) {
387
+ while (l.y > 0 && !chunkVJJIA3HC_js.getFirstCollision(compareWith, l)) {
377
388
  l.y--;
378
389
  }
379
390
  let collision;
380
- while ((collision = chunkA5WIFECI_js.getFirstCollision(compareWith, l)) !== void 0) {
391
+ while ((collision = chunkVJJIA3HC_js.getFirstCollision(compareWith, l)) !== void 0) {
381
392
  resolveCompactionCollision(fullLayout, l, collision.y + collision.h, "y");
382
393
  }
383
394
  l.y = Math.max(l.y, 0);
@@ -386,16 +397,16 @@ function compactItemVertical(compareWith, l, fullLayout, maxY) {
386
397
  function compactItemHorizontal(compareWith, l, cols, fullLayout) {
387
398
  l.x = Math.max(l.x, 0);
388
399
  l.y = Math.max(l.y, 0);
389
- while (l.x > 0 && !chunkA5WIFECI_js.getFirstCollision(compareWith, l)) {
400
+ while (l.x > 0 && !chunkVJJIA3HC_js.getFirstCollision(compareWith, l)) {
390
401
  l.x--;
391
402
  }
392
403
  let collision;
393
- while ((collision = chunkA5WIFECI_js.getFirstCollision(compareWith, l)) !== void 0) {
404
+ while ((collision = chunkVJJIA3HC_js.getFirstCollision(compareWith, l)) !== void 0) {
394
405
  resolveCompactionCollision(fullLayout, l, collision.x + collision.w, "x");
395
406
  if (l.x + l.w > cols) {
396
407
  l.x = cols - l.w;
397
408
  l.y++;
398
- while (l.x > 0 && !chunkA5WIFECI_js.getFirstCollision(compareWith, l)) {
409
+ while (l.x > 0 && !chunkVJJIA3HC_js.getFirstCollision(compareWith, l)) {
399
410
  l.x--;
400
411
  }
401
412
  }
@@ -407,14 +418,14 @@ var verticalCompactor = {
407
418
  type: "vertical",
408
419
  allowOverlap: false,
409
420
  compact(layout, _cols) {
410
- const compareWith = chunkA5WIFECI_js.getStatics(layout);
411
- let maxY = chunkA5WIFECI_js.bottom(compareWith);
412
- const sorted = chunkA5WIFECI_js.sortLayoutItemsByRowCol(layout);
421
+ const compareWith = chunkVJJIA3HC_js.getStatics(layout);
422
+ let maxY = chunkVJJIA3HC_js.bottom(compareWith);
423
+ const sorted = chunkVJJIA3HC_js.sortLayoutItemsByRowCol(layout);
413
424
  const out = new Array(layout.length);
414
425
  for (let i = 0; i < sorted.length; i++) {
415
426
  const sortedItem = sorted[i];
416
427
  if (sortedItem === void 0) continue;
417
- let l = chunkA5WIFECI_js.cloneLayoutItem(sortedItem);
428
+ let l = chunkVJJIA3HC_js.cloneLayoutItem(sortedItem);
418
429
  if (!l.static) {
419
430
  l = compactItemVertical(compareWith, l, sorted, maxY);
420
431
  maxY = Math.max(maxY, l.y + l.h);
@@ -431,13 +442,13 @@ var horizontalCompactor = {
431
442
  type: "horizontal",
432
443
  allowOverlap: false,
433
444
  compact(layout, cols) {
434
- const compareWith = chunkA5WIFECI_js.getStatics(layout);
435
- const sorted = chunkA5WIFECI_js.sortLayoutItemsByColRow(layout);
445
+ const compareWith = chunkVJJIA3HC_js.getStatics(layout);
446
+ const sorted = chunkVJJIA3HC_js.sortLayoutItemsByColRow(layout);
436
447
  const out = new Array(layout.length);
437
448
  for (let i = 0; i < sorted.length; i++) {
438
449
  const sortedItem = sorted[i];
439
450
  if (sortedItem === void 0) continue;
440
- let l = chunkA5WIFECI_js.cloneLayoutItem(sortedItem);
451
+ let l = chunkVJJIA3HC_js.cloneLayoutItem(sortedItem);
441
452
  if (!l.static) {
442
453
  l = compactItemHorizontal(compareWith, l, cols, sorted);
443
454
  compareWith.push(l);
@@ -453,21 +464,21 @@ var noCompactor = {
453
464
  type: null,
454
465
  allowOverlap: false,
455
466
  compact(layout, _cols) {
456
- return chunkA5WIFECI_js.cloneLayout(layout);
467
+ return chunkVJJIA3HC_js.cloneLayout(layout);
457
468
  }
458
469
  };
459
470
  var verticalOverlapCompactor = {
460
471
  ...verticalCompactor,
461
472
  allowOverlap: true,
462
473
  compact(layout, _cols) {
463
- return chunkA5WIFECI_js.cloneLayout(layout);
474
+ return chunkVJJIA3HC_js.cloneLayout(layout);
464
475
  }
465
476
  };
466
477
  var horizontalOverlapCompactor = {
467
478
  ...horizontalCompactor,
468
479
  allowOverlap: true,
469
480
  compact(layout, _cols) {
470
- return chunkA5WIFECI_js.cloneLayout(layout);
481
+ return chunkVJJIA3HC_js.cloneLayout(layout);
471
482
  }
472
483
  };
473
484
  var noOverlapCompactor = {
@@ -525,7 +536,7 @@ function getColsFromBreakpoint(breakpoint, cols) {
525
536
  function findOrGenerateResponsiveLayout(layouts, breakpoints, breakpoint, lastBreakpoint, cols, compactTypeOrCompactor) {
526
537
  const existingLayout = layouts[breakpoint];
527
538
  if (existingLayout) {
528
- return chunkA5WIFECI_js.cloneLayout(existingLayout);
539
+ return chunkVJJIA3HC_js.cloneLayout(existingLayout);
529
540
  }
530
541
  let layout = layouts[lastBreakpoint];
531
542
  const breakpointsSorted = sortBreakpoints(breakpoints);
@@ -541,8 +552,8 @@ function findOrGenerateResponsiveLayout(layouts, breakpoints, breakpoint, lastBr
541
552
  break;
542
553
  }
543
554
  }
544
- const clonedLayout = chunkA5WIFECI_js.cloneLayout(layout || []);
545
- const corrected = chunkA5WIFECI_js.correctBounds(clonedLayout, { cols });
555
+ const clonedLayout = chunkVJJIA3HC_js.cloneLayout(layout || []);
556
+ const corrected = chunkVJJIA3HC_js.correctBounds(clonedLayout, { cols });
546
557
  const compactor = typeof compactTypeOrCompactor === "object" && compactTypeOrCompactor !== null ? compactTypeOrCompactor : getCompactor(compactTypeOrCompactor);
547
558
  return compactor.compact(corrected, cols);
548
559
  }
@@ -1,12 +1,30 @@
1
1
  'use strict';
2
2
 
3
- var chunk55DQUWLA_js = require('./chunk-55DQUWLA.js');
4
- var chunkA5WIFECI_js = require('./chunk-A5WIFECI.js');
3
+ var chunkQAIA5KAO_js = require('./chunk-QAIA5KAO.js');
4
+ var chunkVJJIA3HC_js = require('./chunk-VJJIA3HC.js');
5
5
  var react = require('react');
6
6
  var fastEquals = require('fast-equals');
7
7
 
8
+ function getContentWidth(node) {
9
+ const style = typeof globalThis.getComputedStyle === "function" ? globalThis.getComputedStyle(node) : null;
10
+ if (!style) return node.clientWidth;
11
+ const px = (value) => {
12
+ const parsed = Number.parseFloat(value);
13
+ return Number.isFinite(parsed) ? parsed : 0;
14
+ };
15
+ const computed = Number.parseFloat(style.width);
16
+ if (Number.isFinite(computed)) return Math.max(0, computed);
17
+ return Math.max(
18
+ 0,
19
+ node.clientWidth - px(style.paddingLeft) - px(style.paddingRight)
20
+ );
21
+ }
8
22
  function useContainerWidth(options = {}) {
9
- const { measureBeforeMount = false, initialWidth = 1280 } = options;
23
+ const {
24
+ measureBeforeMount = false,
25
+ initialWidth = 1280,
26
+ debounceTimeout
27
+ } = options;
10
28
  const [width, setWidth] = react.useState(initialWidth);
11
29
  const [mounted, setMounted] = react.useState(!measureBeforeMount);
12
30
  const containerRef = react.useRef(null);
@@ -14,8 +32,8 @@ function useContainerWidth(options = {}) {
14
32
  const measureWidth = react.useCallback(() => {
15
33
  const node = containerRef.current;
16
34
  if (node) {
17
- const newWidth = node.offsetWidth;
18
- setWidth(newWidth);
35
+ const newWidth = Math.round(getContentWidth(node));
36
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
19
37
  if (!mounted) {
20
38
  setMounted(true);
21
39
  }
@@ -27,15 +45,24 @@ function useContainerWidth(options = {}) {
27
45
  measureWidth();
28
46
  if (typeof ResizeObserver !== "undefined") {
29
47
  let rafId = null;
48
+ let debounceTimer;
30
49
  observerRef.current = new ResizeObserver((entries) => {
31
50
  const entry = entries[0];
32
51
  if (entry) {
33
- const newWidth = entry.contentRect.width;
52
+ const newWidth = Math.round(entry.contentRect.width);
53
+ if (debounceTimeout && debounceTimeout > 0) {
54
+ window.clearTimeout(debounceTimer);
55
+ debounceTimer = window.setTimeout(() => {
56
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
57
+ debounceTimer = void 0;
58
+ }, debounceTimeout);
59
+ return;
60
+ }
34
61
  if (rafId !== null) {
35
62
  cancelAnimationFrame(rafId);
36
63
  }
37
64
  rafId = requestAnimationFrame(() => {
38
- setWidth(newWidth);
65
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
39
66
  rafId = null;
40
67
  });
41
68
  }
@@ -45,6 +72,8 @@ function useContainerWidth(options = {}) {
45
72
  if (rafId !== null) {
46
73
  cancelAnimationFrame(rafId);
47
74
  }
75
+ window.clearTimeout(debounceTimer);
76
+ debounceTimer = void 0;
48
77
  if (observerRef.current) {
49
78
  observerRef.current.disconnect();
50
79
  observerRef.current = null;
@@ -57,7 +86,7 @@ function useContainerWidth(options = {}) {
57
86
  observerRef.current = null;
58
87
  }
59
88
  };
60
- }, [measureWidth]);
89
+ }, [measureWidth, debounceTimeout]);
61
90
  return {
62
91
  width,
63
92
  mounted,
@@ -71,11 +100,11 @@ function useGridLayout(options) {
71
100
  cols,
72
101
  preventCollision = false,
73
102
  onLayoutChange,
74
- compactor = chunk55DQUWLA_js.verticalCompactor
103
+ compactor = chunkQAIA5KAO_js.verticalCompactor
75
104
  } = options;
76
105
  const isDraggingRef = react.useRef(false);
77
106
  const [layout, setLayoutState] = react.useState(() => {
78
- const corrected = chunkA5WIFECI_js.correctBounds(chunkA5WIFECI_js.cloneLayout(propsLayout), { cols });
107
+ const corrected = chunkVJJIA3HC_js.correctBounds(chunkVJJIA3HC_js.cloneLayout(propsLayout), { cols });
79
108
  return compactor.compact(corrected, cols);
80
109
  });
81
110
  const [dragState, setDragState] = react.useState({
@@ -95,7 +124,7 @@ function useGridLayout(options) {
95
124
  const prevLayoutRef = react.useRef(layout);
96
125
  const setLayout = react.useCallback(
97
126
  (newLayout) => {
98
- const corrected = chunkA5WIFECI_js.correctBounds(chunkA5WIFECI_js.cloneLayout(newLayout), { cols });
127
+ const corrected = chunkVJJIA3HC_js.correctBounds(chunkVJJIA3HC_js.cloneLayout(newLayout), { cols });
99
128
  const compacted = compactor.compact(corrected, cols);
100
129
  setLayoutState(compacted);
101
130
  },
@@ -115,11 +144,11 @@ function useGridLayout(options) {
115
144
  }, [layout, onLayoutChange]);
116
145
  const onDragStart = react.useCallback(
117
146
  (itemId, x, y) => {
118
- const item = chunkA5WIFECI_js.getLayoutItem(layout, itemId);
147
+ const item = chunkVJJIA3HC_js.getLayoutItem(layout, itemId);
119
148
  if (!item) return null;
120
149
  isDraggingRef.current = true;
121
150
  const placeholder = {
122
- ...chunkA5WIFECI_js.cloneLayoutItem(item),
151
+ ...chunkVJJIA3HC_js.cloneLayoutItem(item),
123
152
  x,
124
153
  y,
125
154
  static: false,
@@ -127,8 +156,8 @@ function useGridLayout(options) {
127
156
  };
128
157
  setDragState({
129
158
  activeDrag: placeholder,
130
- oldDragItem: chunkA5WIFECI_js.cloneLayoutItem(item),
131
- oldLayout: chunkA5WIFECI_js.cloneLayout(layout)
159
+ oldDragItem: chunkVJJIA3HC_js.cloneLayoutItem(item),
160
+ oldLayout: chunkVJJIA3HC_js.cloneLayout(layout)
132
161
  });
133
162
  return placeholder;
134
163
  },
@@ -136,13 +165,13 @@ function useGridLayout(options) {
136
165
  );
137
166
  const onDrag = react.useCallback(
138
167
  (itemId, x, y) => {
139
- const item = chunkA5WIFECI_js.getLayoutItem(layout, itemId);
168
+ const item = chunkVJJIA3HC_js.getLayoutItem(layout, itemId);
140
169
  if (!item) return;
141
170
  setDragState((prev) => ({
142
171
  ...prev,
143
172
  activeDrag: prev.activeDrag ? { ...prev.activeDrag, x, y } : null
144
173
  }));
145
- const newLayout = chunkA5WIFECI_js.moveElement(
174
+ const newLayout = chunkVJJIA3HC_js.moveElement(
146
175
  layout,
147
176
  item,
148
177
  x,
@@ -161,9 +190,9 @@ function useGridLayout(options) {
161
190
  );
162
191
  const onDragStop = react.useCallback(
163
192
  (itemId, x, y) => {
164
- const item = chunkA5WIFECI_js.getLayoutItem(layout, itemId);
193
+ const item = chunkVJJIA3HC_js.getLayoutItem(layout, itemId);
165
194
  if (!item) return;
166
- const newLayout = chunkA5WIFECI_js.moveElement(
195
+ const newLayout = chunkVJJIA3HC_js.moveElement(
167
196
  layout,
168
197
  item,
169
198
  x,
@@ -187,12 +216,12 @@ function useGridLayout(options) {
187
216
  );
188
217
  const onResizeStart = react.useCallback(
189
218
  (itemId) => {
190
- const item = chunkA5WIFECI_js.getLayoutItem(layout, itemId);
219
+ const item = chunkVJJIA3HC_js.getLayoutItem(layout, itemId);
191
220
  if (!item) return null;
192
221
  setResizeState({
193
222
  resizing: true,
194
- oldResizeItem: chunkA5WIFECI_js.cloneLayoutItem(item),
195
- oldLayout: chunkA5WIFECI_js.cloneLayout(layout)
223
+ oldResizeItem: chunkVJJIA3HC_js.cloneLayoutItem(item),
224
+ oldLayout: chunkVJJIA3HC_js.cloneLayout(layout)
196
225
  });
197
226
  return item;
198
227
  },
@@ -213,7 +242,7 @@ function useGridLayout(options) {
213
242
  }
214
243
  return item;
215
244
  });
216
- const corrected = chunkA5WIFECI_js.correctBounds(newLayout, { cols });
245
+ const corrected = chunkVJJIA3HC_js.correctBounds(newLayout, { cols });
217
246
  const compacted = compactor.compact(corrected, cols);
218
247
  setLayoutState(compacted);
219
248
  },
@@ -232,10 +261,10 @@ function useGridLayout(options) {
232
261
  );
233
262
  const onDropDragOver = react.useCallback(
234
263
  (droppingItem, position) => {
235
- const existingItem = chunkA5WIFECI_js.getLayoutItem(layout, droppingItem.i);
264
+ const existingItem = chunkVJJIA3HC_js.getLayoutItem(layout, droppingItem.i);
236
265
  if (!existingItem) {
237
266
  const newLayout = [...layout, droppingItem];
238
- const corrected = chunkA5WIFECI_js.correctBounds(newLayout, { cols });
267
+ const corrected = chunkVJJIA3HC_js.correctBounds(newLayout, { cols });
239
268
  const compacted = compactor.compact(corrected, cols);
240
269
  setLayoutState(compacted);
241
270
  }
@@ -267,7 +296,7 @@ function useGridLayout(options) {
267
296
  }
268
297
  return item;
269
298
  });
270
- const corrected = chunkA5WIFECI_js.correctBounds(newLayout, { cols });
299
+ const corrected = chunkVJJIA3HC_js.correctBounds(newLayout, { cols });
271
300
  const compacted = compactor.compact(corrected, cols);
272
301
  setLayoutState(compacted);
273
302
  setDropState({
@@ -277,7 +306,7 @@ function useGridLayout(options) {
277
306
  },
278
307
  [layout, cols, compactor]
279
308
  );
280
- const containerHeight = react.useMemo(() => chunkA5WIFECI_js.bottom(layout), [layout]);
309
+ const containerHeight = react.useMemo(() => chunkVJJIA3HC_js.bottom(layout), [layout]);
281
310
  const isInteracting = dragState.activeDrag !== null || resizeState.resizing || dropState.droppingPosition !== null;
282
311
  return {
283
312
  layout,
@@ -319,23 +348,23 @@ function useResponsiveLayout(options) {
319
348
  breakpoints = DEFAULT_BREAKPOINTS,
320
349
  cols: colsConfig = DEFAULT_COLS,
321
350
  layouts: propsLayouts = {},
322
- compactor = chunk55DQUWLA_js.verticalCompactor,
351
+ compactor = chunkQAIA5KAO_js.verticalCompactor,
323
352
  onBreakpointChange,
324
353
  onLayoutChange,
325
354
  onWidthChange
326
355
  } = options;
327
356
  const sortedBreakpoints = react.useMemo(
328
- () => chunk55DQUWLA_js.sortBreakpoints(breakpoints),
357
+ () => chunkQAIA5KAO_js.sortBreakpoints(breakpoints),
329
358
  [breakpoints]
330
359
  );
331
360
  const initialBreakpoint = react.useMemo(
332
- () => chunk55DQUWLA_js.getBreakpointFromWidth(breakpoints, width),
361
+ () => chunkQAIA5KAO_js.getBreakpointFromWidth(breakpoints, width),
333
362
  // Only calculate on mount, not on width changes
334
363
  // eslint-disable-next-line react-hooks/exhaustive-deps
335
364
  []
336
365
  );
337
366
  const initialCols = react.useMemo(
338
- () => chunk55DQUWLA_js.getColsFromBreakpoint(initialBreakpoint, colsConfig),
367
+ () => chunkQAIA5KAO_js.getColsFromBreakpoint(initialBreakpoint, colsConfig),
339
368
  [initialBreakpoint, colsConfig]
340
369
  );
341
370
  const [breakpoint, setBreakpoint] = react.useState(initialBreakpoint);
@@ -345,7 +374,7 @@ function useResponsiveLayout(options) {
345
374
  for (const bp of sortedBreakpoints) {
346
375
  const layout2 = propsLayouts[bp];
347
376
  if (layout2) {
348
- cloned[bp] = chunkA5WIFECI_js.cloneLayout(layout2);
377
+ cloned[bp] = chunkVJJIA3HC_js.cloneLayout(layout2);
349
378
  }
350
379
  }
351
380
  return cloned;
@@ -355,7 +384,7 @@ function useResponsiveLayout(options) {
355
384
  const prevPropsLayoutsRef = react.useRef(propsLayouts);
356
385
  const prevLayoutsRef = react.useRef(layouts);
357
386
  const layout = react.useMemo(() => {
358
- return chunk55DQUWLA_js.findOrGenerateResponsiveLayout(
387
+ return chunkQAIA5KAO_js.findOrGenerateResponsiveLayout(
359
388
  layouts,
360
389
  breakpoints,
361
390
  breakpoint,
@@ -367,7 +396,7 @@ function useResponsiveLayout(options) {
367
396
  const setLayoutForBreakpoint = react.useCallback((bp, newLayout) => {
368
397
  setLayoutsState((prev) => ({
369
398
  ...prev,
370
- [bp]: chunkA5WIFECI_js.cloneLayout(newLayout)
399
+ [bp]: chunkVJJIA3HC_js.cloneLayout(newLayout)
371
400
  }));
372
401
  }, []);
373
402
  const setLayouts = react.useCallback((newLayouts) => {
@@ -375,7 +404,7 @@ function useResponsiveLayout(options) {
375
404
  for (const bp of Object.keys(newLayouts)) {
376
405
  const layoutForBp = newLayouts[bp];
377
406
  if (layoutForBp) {
378
- cloned[bp] = chunkA5WIFECI_js.cloneLayout(layoutForBp);
407
+ cloned[bp] = chunkVJJIA3HC_js.cloneLayout(layoutForBp);
379
408
  }
380
409
  }
381
410
  setLayoutsState(cloned);
@@ -383,11 +412,11 @@ function useResponsiveLayout(options) {
383
412
  react.useEffect(() => {
384
413
  if (prevWidthRef.current === width) return;
385
414
  prevWidthRef.current = width;
386
- const newBreakpoint = chunk55DQUWLA_js.getBreakpointFromWidth(breakpoints, width);
387
- const newCols = chunk55DQUWLA_js.getColsFromBreakpoint(newBreakpoint, colsConfig);
415
+ const newBreakpoint = chunkQAIA5KAO_js.getBreakpointFromWidth(breakpoints, width);
416
+ const newCols = chunkQAIA5KAO_js.getColsFromBreakpoint(newBreakpoint, colsConfig);
388
417
  onWidthChange?.(width, [10, 10], newCols, null);
389
418
  if (newBreakpoint !== breakpoint) {
390
- const newLayout = chunk55DQUWLA_js.findOrGenerateResponsiveLayout(
419
+ const newLayout = chunkQAIA5KAO_js.findOrGenerateResponsiveLayout(
391
420
  layouts,
392
421
  breakpoints,
393
422
  newBreakpoint,
@@ -1,10 +1,28 @@
1
- import { verticalCompactor, sortBreakpoints, getBreakpointFromWidth, getColsFromBreakpoint, findOrGenerateResponsiveLayout } from './chunk-KDANGDDL.mjs';
2
- import { correctBounds, cloneLayout, getLayoutItem, cloneLayoutItem, moveElement, bottom } from './chunk-76RTO6EO.mjs';
1
+ import { verticalCompactor, sortBreakpoints, getBreakpointFromWidth, getColsFromBreakpoint, findOrGenerateResponsiveLayout } from './chunk-VBU6B7II.mjs';
2
+ import { correctBounds, cloneLayout, getLayoutItem, cloneLayoutItem, moveElement, bottom } from './chunk-ZYNFVPDS.mjs';
3
3
  import { useState, useRef, useCallback, useEffect, useMemo } from 'react';
4
4
  import { deepEqual } from 'fast-equals';
5
5
 
6
+ function getContentWidth(node) {
7
+ const style = typeof globalThis.getComputedStyle === "function" ? globalThis.getComputedStyle(node) : null;
8
+ if (!style) return node.clientWidth;
9
+ const px = (value) => {
10
+ const parsed = Number.parseFloat(value);
11
+ return Number.isFinite(parsed) ? parsed : 0;
12
+ };
13
+ const computed = Number.parseFloat(style.width);
14
+ if (Number.isFinite(computed)) return Math.max(0, computed);
15
+ return Math.max(
16
+ 0,
17
+ node.clientWidth - px(style.paddingLeft) - px(style.paddingRight)
18
+ );
19
+ }
6
20
  function useContainerWidth(options = {}) {
7
- const { measureBeforeMount = false, initialWidth = 1280 } = options;
21
+ const {
22
+ measureBeforeMount = false,
23
+ initialWidth = 1280,
24
+ debounceTimeout
25
+ } = options;
8
26
  const [width, setWidth] = useState(initialWidth);
9
27
  const [mounted, setMounted] = useState(!measureBeforeMount);
10
28
  const containerRef = useRef(null);
@@ -12,8 +30,8 @@ function useContainerWidth(options = {}) {
12
30
  const measureWidth = useCallback(() => {
13
31
  const node = containerRef.current;
14
32
  if (node) {
15
- const newWidth = node.offsetWidth;
16
- setWidth(newWidth);
33
+ const newWidth = Math.round(getContentWidth(node));
34
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
17
35
  if (!mounted) {
18
36
  setMounted(true);
19
37
  }
@@ -25,15 +43,24 @@ function useContainerWidth(options = {}) {
25
43
  measureWidth();
26
44
  if (typeof ResizeObserver !== "undefined") {
27
45
  let rafId = null;
46
+ let debounceTimer;
28
47
  observerRef.current = new ResizeObserver((entries) => {
29
48
  const entry = entries[0];
30
49
  if (entry) {
31
- const newWidth = entry.contentRect.width;
50
+ const newWidth = Math.round(entry.contentRect.width);
51
+ if (debounceTimeout && debounceTimeout > 0) {
52
+ window.clearTimeout(debounceTimer);
53
+ debounceTimer = window.setTimeout(() => {
54
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
55
+ debounceTimer = void 0;
56
+ }, debounceTimeout);
57
+ return;
58
+ }
32
59
  if (rafId !== null) {
33
60
  cancelAnimationFrame(rafId);
34
61
  }
35
62
  rafId = requestAnimationFrame(() => {
36
- setWidth(newWidth);
63
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
37
64
  rafId = null;
38
65
  });
39
66
  }
@@ -43,6 +70,8 @@ function useContainerWidth(options = {}) {
43
70
  if (rafId !== null) {
44
71
  cancelAnimationFrame(rafId);
45
72
  }
73
+ window.clearTimeout(debounceTimer);
74
+ debounceTimer = void 0;
46
75
  if (observerRef.current) {
47
76
  observerRef.current.disconnect();
48
77
  observerRef.current = null;
@@ -55,7 +84,7 @@ function useContainerWidth(options = {}) {
55
84
  observerRef.current = null;
56
85
  }
57
86
  };
58
- }, [measureWidth]);
87
+ }, [measureWidth, debounceTimeout]);
59
88
  return {
60
89
  width,
61
90
  mounted,
@@ -1,4 +1,4 @@
1
- import { getStatics, collides, getFirstCollision, bottom, sortLayoutItemsByRowCol, cloneLayoutItem, sortLayoutItemsByColRow, cloneLayout, correctBounds } from './chunk-76RTO6EO.mjs';
1
+ import { getStatics, collides, getFirstCollision, bottom, sortLayoutItemsByRowCol, cloneLayoutItem, sortLayoutItemsByColRow, cloneLayout, correctBounds } from './chunk-ZYNFVPDS.mjs';
2
2
 
3
3
  // src/core/constraints.ts
4
4
  function clamp(value, min, max) {
@@ -38,6 +38,15 @@ var containerBounds = {
38
38
  x: clamp(x, 0, Math.max(0, cols - item.w)),
39
39
  y: clamp(y, 0, Math.max(0, visibleRows - item.h))
40
40
  };
41
+ },
42
+ constrainSize(item, w, h, handle, { cols, maxRows, containerHeight, rowHeight, margin }) {
43
+ const visibleRows = containerHeight > 0 ? Math.floor((containerHeight + margin[1]) / (rowHeight + margin[1])) : maxRows;
44
+ const maxW = handle === "w" || handle === "nw" || handle === "sw" ? item.x + item.w : cols - item.x;
45
+ const maxH = handle === "n" || handle === "nw" || handle === "ne" ? item.y + item.h : visibleRows - item.y;
46
+ return {
47
+ w: clamp(w, 1, Math.max(1, maxW)),
48
+ h: clamp(h, 1, Math.max(1, maxH))
49
+ };
41
50
  }
42
51
  };
43
52
  var boundedX = {
@@ -341,7 +350,9 @@ var defaultResizeConfig = {
341
350
  };
342
351
  var defaultDropConfig = {
343
352
  enabled: false,
344
- defaultItem: { w: 1, h: 1 }
353
+ defaultItem: { w: 1, h: 1 },
354
+ touchEnabled: true,
355
+ touchDragSource: "[data-rgl-draggable]"
345
356
  };
346
357
 
347
358
  // src/core/compactors.ts
@@ -268,6 +268,9 @@ function correctBounds(layout, bounds) {
268
268
  l.x = 0;
269
269
  l.w = bounds.cols;
270
270
  }
271
+ if (l.y === Infinity) {
272
+ l.y = bottom(collidesWith);
273
+ }
271
274
  if (!l.static) {
272
275
  collidesWith.push(l);
273
276
  } else {
@@ -330,7 +333,7 @@ function moveElement(layout, l, x, y, isUserAction, preventCollision, compactTyp
330
333
  return resultLayout;
331
334
  }
332
335
  function moveElementAwayFromCollision(layout, collidesWith, itemToMove, isUserAction, compactType, cols) {
333
- const compactH = compactType === "horizontal";
336
+ const compactH = compactType === "horizontal" || compactType === "wrap";
334
337
  const compactV = compactType === "vertical";
335
338
  const preventCollision = collidesWith.static;
336
339
  if (isUserAction) {
@@ -366,8 +369,9 @@ function moveElementAwayFromCollision(layout, collidesWith, itemToMove, isUserAc
366
369
  compactType);
367
370
  }
368
371
  if (collisionNorth && compactType === null) {
369
- collidesWith.y = itemToMove.y;
370
- itemToMove.y = itemToMove.y + itemToMove.h;
372
+ const newCollidesY = itemToMove.y;
373
+ collidesWith.y = newCollidesY;
374
+ itemToMove.y = newCollidesY + collidesWith.h;
371
375
  return [...layout];
372
376
  }
373
377
  if (collisionWest && compactH) {