react-grid-layout 2.2.4 → 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-QAWP6PEK.js → chunk-CUP5Y2ZG.js} +495 -154
  7. package/dist/{chunk-55DQUWLA.js → chunk-QAIA5KAO.js} +33 -22
  8. package/dist/{chunk-BMN6M2VL.js → chunk-SL4EZ2NU.js} +49 -34
  9. package/dist/{chunk-LY5GT7Q2.mjs → chunk-TW4BCTKD.mjs} +19 -4
  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-7ZM5LVH2.mjs → chunk-Z6CWRR74.mjs} +426 -85
  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 +33 -23
  29. package/dist/legacy.mjs +16 -7
  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,7 +1,7 @@
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 React2 = require('react');
6
6
  var reactDraggable = require('react-draggable');
7
7
  var reactResizable = require('react-resizable');
@@ -14,7 +14,71 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
  var React2__default = /*#__PURE__*/_interopDefault(React2);
15
15
  var clsx__default = /*#__PURE__*/_interopDefault(clsx);
16
16
 
17
- function GridItem(props) {
17
+ // src/react/components/edgeScroll.ts
18
+ var EDGE_THRESHOLD = 50;
19
+ var SCROLL_STEP = 12;
20
+ function getNearestScrollable(node) {
21
+ let el = node;
22
+ while (el) {
23
+ const style = window.getComputedStyle(el);
24
+ const overflowY = style.overflowY;
25
+ const scrollable = (overflowY === "auto" || overflowY === "scroll") && el.scrollHeight > el.clientHeight;
26
+ if (scrollable) return el;
27
+ el = el.parentElement;
28
+ }
29
+ return null;
30
+ }
31
+ function createEdgeScrollController(node) {
32
+ const scrollContainer = getNearestScrollable(node);
33
+ let rafId = null;
34
+ let lastX = 0;
35
+ let lastY = 0;
36
+ let running = false;
37
+ function step() {
38
+ const container = scrollContainer;
39
+ if (!container) return;
40
+ const rect = container.getBoundingClientRect();
41
+ const { clientHeight, scrollTop, scrollHeight } = container;
42
+ const { scrollLeft, scrollWidth, clientWidth } = container;
43
+ let dy = 0;
44
+ let dx = 0;
45
+ if (lastY < rect.top + EDGE_THRESHOLD && scrollTop > 0) {
46
+ dy = -SCROLL_STEP;
47
+ } else if (lastY > rect.bottom - EDGE_THRESHOLD && scrollTop + clientHeight < scrollHeight) {
48
+ dy = SCROLL_STEP;
49
+ }
50
+ if (lastX < rect.left + EDGE_THRESHOLD && scrollLeft > 0) {
51
+ dx = -SCROLL_STEP;
52
+ } else if (lastX > rect.right - EDGE_THRESHOLD && scrollLeft + clientWidth < scrollWidth) {
53
+ dx = SCROLL_STEP;
54
+ }
55
+ if (dy !== 0 || dx !== 0) {
56
+ container.scrollTop += dy;
57
+ container.scrollLeft += dx;
58
+ }
59
+ if (running) {
60
+ rafId = requestAnimationFrame(step);
61
+ }
62
+ }
63
+ return {
64
+ feed(clientX, clientY) {
65
+ lastX = clientX;
66
+ lastY = clientY;
67
+ if (!running) {
68
+ running = true;
69
+ rafId = requestAnimationFrame(step);
70
+ }
71
+ },
72
+ stop() {
73
+ running = false;
74
+ if (rafId !== null) {
75
+ cancelAnimationFrame(rafId);
76
+ rafId = null;
77
+ }
78
+ }
79
+ };
80
+ }
81
+ function GridItemInner(props) {
18
82
  const {
19
83
  children,
20
84
  cols,
@@ -26,6 +90,7 @@ function GridItem(props) {
26
90
  isDraggable,
27
91
  isResizable,
28
92
  isBounded,
93
+ allowMobileScroll,
29
94
  static: isStatic,
30
95
  useCSSTransforms = true,
31
96
  usePercentages = false,
@@ -48,7 +113,7 @@ function GridItem(props) {
48
113
  i,
49
114
  resizeHandles,
50
115
  resizeHandle,
51
- constraints = chunk55DQUWLA_js.defaultConstraints,
116
+ constraints = chunkQAIA5KAO_js.defaultConstraints,
52
117
  layoutItem,
53
118
  layout = [],
54
119
  onDragStart: onDragStartProp,
@@ -78,6 +143,7 @@ function GridItem(props) {
78
143
  const dragPendingRef = React2.useRef(false);
79
144
  const initialDragClientRef = React2.useRef({ x: 0, y: 0 });
80
145
  const thresholdExceededRef = React2.useRef(false);
146
+ const edgeScrollRef = React2.useRef(null);
81
147
  const positionParams = React2.useMemo(
82
148
  () => ({
83
149
  cols,
@@ -95,7 +161,7 @@ function GridItem(props) {
95
161
  maxRows,
96
162
  containerWidth,
97
163
  containerHeight: 0,
98
- // Auto-height grids don't have a fixed container height
164
+ // Overridden per-interaction with the measured container height
99
165
  rowHeight,
100
166
  margin,
101
167
  // Use empty layout here - the actual layout will be accessed via layoutRef when needed
@@ -105,8 +171,9 @@ function GridItem(props) {
105
171
  [cols, maxRows, containerWidth, rowHeight, margin]
106
172
  );
107
173
  const getConstraintContext = React2.useCallback(
108
- () => ({
174
+ (containerHeight) => ({
109
175
  ...constraintContext,
176
+ containerHeight: containerHeight ?? constraintContext.containerHeight,
110
177
  layout: layoutRef.current
111
178
  }),
112
179
  [constraintContext]
@@ -131,14 +198,14 @@ function GridItem(props) {
131
198
  return positionStrategy.calcStyle(pos2);
132
199
  }
133
200
  if (useCSSTransforms) {
134
- return chunk55DQUWLA_js.setTransform(pos2);
201
+ return chunkQAIA5KAO_js.setTransform(pos2);
135
202
  }
136
- const styleObj = chunk55DQUWLA_js.setTopLeft(pos2);
203
+ const styleObj = chunkQAIA5KAO_js.setTopLeft(pos2);
137
204
  if (usePercentages) {
138
205
  return {
139
206
  ...styleObj,
140
- left: chunk55DQUWLA_js.perc(pos2.left / containerWidth),
141
- width: chunk55DQUWLA_js.perc(pos2.width / containerWidth)
207
+ left: chunkQAIA5KAO_js.perc(pos2.left / containerWidth),
208
+ width: chunkQAIA5KAO_js.perc(pos2.width / containerWidth)
142
209
  };
143
210
  }
144
211
  return styleObj;
@@ -172,6 +239,11 @@ function GridItem(props) {
172
239
  };
173
240
  }
174
241
  dragPositionRef.current = newPosition;
242
+ if (!edgeScrollRef.current) {
243
+ edgeScrollRef.current = createEdgeScrollController(
244
+ node instanceof HTMLElement ? node : null
245
+ );
246
+ }
175
247
  if (dragThreshold > 0) {
176
248
  const mouseEvent = e;
177
249
  initialDragClientRef.current = {
@@ -184,12 +256,12 @@ function GridItem(props) {
184
256
  return;
185
257
  }
186
258
  setDragging(true);
187
- const rawPos = chunkA5WIFECI_js.calcXYRaw(
259
+ const rawPos = chunkVJJIA3HC_js.calcXYRaw(
188
260
  positionParams,
189
261
  newPosition.top,
190
262
  newPosition.left
191
263
  );
192
- const { x: newX, y: newY } = chunk55DQUWLA_js.applyPositionConstraints(
264
+ const { x: newX, y: newY } = chunkQAIA5KAO_js.applyPositionConstraints(
193
265
  constraints,
194
266
  effectiveLayoutItem,
195
267
  rawPos.x,
@@ -228,12 +300,12 @@ function GridItem(props) {
228
300
  thresholdExceededRef.current = true;
229
301
  dragPendingRef.current = false;
230
302
  if (onDragStartProp) {
231
- const rawPos2 = chunkA5WIFECI_js.calcXYRaw(
303
+ const rawPos2 = chunkVJJIA3HC_js.calcXYRaw(
232
304
  positionParams,
233
305
  dragPositionRef.current.top,
234
306
  dragPositionRef.current.left
235
307
  );
236
- const { x: startX, y: startY } = chunk55DQUWLA_js.applyPositionConstraints(
308
+ const { x: startX, y: startY } = chunkQAIA5KAO_js.applyPositionConstraints(
237
309
  constraints,
238
310
  effectiveLayoutItem,
239
311
  rawPos2.x,
@@ -247,22 +319,23 @@ function GridItem(props) {
247
319
  });
248
320
  }
249
321
  }
322
+ edgeScrollRef.current?.feed(mouseEvent.clientX, mouseEvent.clientY);
250
323
  let top = dragPositionRef.current.top + deltaY;
251
324
  let left = dragPositionRef.current.left + deltaX;
252
325
  if (isBounded) {
253
326
  const { offsetParent } = node;
254
327
  if (offsetParent) {
255
- const bottomBoundary = offsetParent.clientHeight - chunkA5WIFECI_js.calcGridItemWHPx(h, rowHeight, margin[1]);
256
- top = chunkA5WIFECI_js.clamp(top, 0, bottomBoundary);
257
- const colWidth2 = chunkA5WIFECI_js.calcGridColWidth(positionParams);
258
- const rightBoundary = containerWidth - chunkA5WIFECI_js.calcGridItemWHPx(w, colWidth2, margin[0]);
259
- left = chunkA5WIFECI_js.clamp(left, 0, rightBoundary);
328
+ const bottomBoundary = offsetParent.clientHeight - chunkVJJIA3HC_js.calcGridItemWHPx(h, rowHeight, margin[1]);
329
+ top = chunkVJJIA3HC_js.clamp(top, 0, bottomBoundary);
330
+ const colWidth2 = chunkVJJIA3HC_js.calcGridColWidth(positionParams);
331
+ const rightBoundary = containerWidth - chunkVJJIA3HC_js.calcGridItemWHPx(w, colWidth2, margin[0]);
332
+ left = chunkVJJIA3HC_js.clamp(left, 0, rightBoundary);
260
333
  }
261
334
  }
262
335
  const newPosition = { top, left };
263
336
  dragPositionRef.current = newPosition;
264
- const rawPos = chunkA5WIFECI_js.calcXYRaw(positionParams, top, left);
265
- const { x: newX, y: newY } = chunk55DQUWLA_js.applyPositionConstraints(
337
+ const rawPos = chunkVJJIA3HC_js.calcXYRaw(positionParams, top, left);
338
+ const { x: newX, y: newY } = chunkQAIA5KAO_js.applyPositionConstraints(
266
339
  constraints,
267
340
  effectiveLayoutItem,
268
341
  rawPos.x,
@@ -296,6 +369,8 @@ function GridItem(props) {
296
369
  const onDragStop = React2.useCallback(
297
370
  (e, { node }) => {
298
371
  if (!onDragStopProp || !dragging) return;
372
+ edgeScrollRef.current?.stop();
373
+ edgeScrollRef.current = null;
299
374
  const wasPending = dragPendingRef.current;
300
375
  dragPendingRef.current = false;
301
376
  thresholdExceededRef.current = false;
@@ -309,8 +384,8 @@ function GridItem(props) {
309
384
  const newPosition = { top, left };
310
385
  setDragging(false);
311
386
  dragPositionRef.current = { left: 0, top: 0 };
312
- const rawPos = chunkA5WIFECI_js.calcXYRaw(positionParams, top, left);
313
- const { x: newX, y: newY } = chunk55DQUWLA_js.applyPositionConstraints(
387
+ const rawPos = chunkVJJIA3HC_js.calcXYRaw(positionParams, top, left);
388
+ const { x: newX, y: newY } = chunkQAIA5KAO_js.applyPositionConstraints(
314
389
  constraints,
315
390
  effectiveLayoutItem,
316
391
  rawPos.x,
@@ -341,7 +416,7 @@ function GridItem(props) {
341
416
  if (!handler) return;
342
417
  let updatedSize;
343
418
  if (node) {
344
- updatedSize = chunk55DQUWLA_js.resizeItemInDirection(
419
+ updatedSize = chunkQAIA5KAO_js.resizeItemInDirection(
345
420
  resizeHandle2,
346
421
  position,
347
422
  size,
@@ -355,18 +430,19 @@ function GridItem(props) {
355
430
  };
356
431
  }
357
432
  resizePositionRef.current = updatedSize;
358
- const rawSize = chunkA5WIFECI_js.calcWHRaw(
433
+ const containerHeight = node?.offsetParent?.clientHeight ?? 0;
434
+ const rawSize = chunkVJJIA3HC_js.calcWHRaw(
359
435
  positionParams,
360
436
  updatedSize.width,
361
437
  updatedSize.height
362
438
  );
363
- const { w: newW, h: newH } = chunk55DQUWLA_js.applySizeConstraints(
439
+ const { w: newW, h: newH } = chunkQAIA5KAO_js.applySizeConstraints(
364
440
  constraints,
365
441
  effectiveLayoutItem,
366
442
  rawSize.w,
367
443
  rawSize.h,
368
444
  resizeHandle2,
369
- getConstraintContext()
445
+ getConstraintContext(containerHeight)
370
446
  );
371
447
  handler(i, newW, newH, {
372
448
  // react-resizable forwards react-draggable's callback event, which is
@@ -394,7 +470,7 @@ function GridItem(props) {
394
470
  const handleResizeStart = React2.useCallback(
395
471
  (e, data) => {
396
472
  setResizing(true);
397
- const pos2 = chunkA5WIFECI_js.calcGridItemPosition(positionParams, x, y, w, h);
473
+ const pos2 = chunkVJJIA3HC_js.calcGridItemPosition(positionParams, x, y, w, h);
398
474
  const typedData = {
399
475
  ...data,
400
476
  handle: data.handle
@@ -405,7 +481,7 @@ function GridItem(props) {
405
481
  );
406
482
  const handleResize = React2.useCallback(
407
483
  (e, data) => {
408
- const pos2 = chunkA5WIFECI_js.calcGridItemPosition(positionParams, x, y, w, h);
484
+ const pos2 = chunkVJJIA3HC_js.calcGridItemPosition(positionParams, x, y, w, h);
409
485
  const typedData = {
410
486
  ...data,
411
487
  handle: data.handle
@@ -418,7 +494,7 @@ function GridItem(props) {
418
494
  (e, data) => {
419
495
  setResizing(false);
420
496
  resizePositionRef.current = { top: 0, left: 0, width: 0, height: 0 };
421
- const pos2 = chunkA5WIFECI_js.calcGridItemPosition(positionParams, x, y, w, h);
497
+ const pos2 = chunkVJJIA3HC_js.calcGridItemPosition(positionParams, x, y, w, h);
422
498
  const typedData = {
423
499
  ...data,
424
500
  handle: data.handle
@@ -469,7 +545,7 @@ function GridItem(props) {
469
545
  }
470
546
  prevDroppingPositionRef.current = droppingPosition;
471
547
  }, [droppingPosition, dragging, i]);
472
- const pos = chunkA5WIFECI_js.calcGridItemPosition(
548
+ const pos = chunkVJJIA3HC_js.calcGridItemPosition(
473
549
  positionParams,
474
550
  x,
475
551
  y,
@@ -479,14 +555,14 @@ function GridItem(props) {
479
555
  resizing ? resizePositionRef.current : null
480
556
  );
481
557
  const child = React2__default.default.Children.only(children);
482
- const colWidth = chunkA5WIFECI_js.calcGridColWidth(positionParams);
558
+ const colWidth = chunkVJJIA3HC_js.calcGridColWidth(positionParams);
483
559
  const minConstraints = [
484
- chunkA5WIFECI_js.calcGridItemWHPx(minW, colWidth, margin[0]),
485
- chunkA5WIFECI_js.calcGridItemWHPx(minH, rowHeight, margin[1])
560
+ chunkVJJIA3HC_js.calcGridItemWHPx(minW, colWidth, margin[0]),
561
+ chunkVJJIA3HC_js.calcGridItemWHPx(minH, rowHeight, margin[1])
486
562
  ];
487
563
  const maxConstraints = [
488
- chunkA5WIFECI_js.calcGridItemWHPx(maxW, colWidth, margin[0]),
489
- chunkA5WIFECI_js.calcGridItemWHPx(maxH, rowHeight, margin[1])
564
+ chunkVJJIA3HC_js.calcGridItemWHPx(maxW, colWidth, margin[0]),
565
+ chunkVJJIA3HC_js.calcGridItemWHPx(maxH, rowHeight, margin[1])
490
566
  ];
491
567
  const childProps = child.props;
492
568
  const childClassName = childProps["className"];
@@ -536,12 +612,104 @@ function GridItem(props) {
536
612
  handle,
537
613
  cancel: ".react-resizable-handle" + (cancel ? "," + cancel : ""),
538
614
  scale: transformScale,
615
+ allowMobileScroll,
539
616
  nodeRef: elementRef,
540
617
  children: newChild
541
618
  }
542
619
  );
543
620
  return newChild;
544
621
  }
622
+ var GridItem = React2__default.default.memo(GridItemInner, (prev, next) => {
623
+ if (prev.x !== next.x || prev.y !== next.y) return false;
624
+ if (prev.w !== next.w || prev.h !== next.h) return false;
625
+ if (prev.minW !== next.minW || prev.maxW !== next.maxW) return false;
626
+ if (prev.minH !== next.minH || prev.maxH !== next.maxH) return false;
627
+ if (prev.cols !== next.cols) return false;
628
+ if (prev.containerWidth !== next.containerWidth) return false;
629
+ if (prev.rowHeight !== next.rowHeight) return false;
630
+ if (prev.maxRows !== next.maxRows) return false;
631
+ if (prev.margin !== next.margin) return false;
632
+ if (prev.containerPadding !== next.containerPadding) return false;
633
+ if (prev.transformScale !== next.transformScale) return false;
634
+ if (prev.isDraggable !== next.isDraggable) return false;
635
+ if (prev.isResizable !== next.isResizable) return false;
636
+ if (prev.isBounded !== next.isBounded) return false;
637
+ if (prev.allowMobileScroll !== next.allowMobileScroll) return false;
638
+ if (prev.useCSSTransforms !== next.useCSSTransforms) return false;
639
+ if (prev.usePercentages !== next.usePercentages) return false;
640
+ if (prev.children !== next.children) return false;
641
+ if (prev.onDrag !== next.onDrag) return false;
642
+ if (prev.onDragStop !== next.onDragStop) return false;
643
+ if (prev.onResize !== next.onResize) return false;
644
+ if (prev.onResizeStop !== next.onResizeStop) return false;
645
+ if (prev.droppingPosition !== next.droppingPosition) return false;
646
+ return true;
647
+ });
648
+ GridItem.displayName = "GridItem";
649
+
650
+ // src/react/components/dropMath.ts
651
+ function computeDropPosition(input) {
652
+ const {
653
+ clientX,
654
+ clientY,
655
+ gridElement,
656
+ droppingItem,
657
+ event,
658
+ dragOffsetX = 0,
659
+ dragOffsetY = 0,
660
+ transformScale,
661
+ cols,
662
+ margin,
663
+ maxRows,
664
+ rowHeight,
665
+ width,
666
+ containerPadding
667
+ } = input;
668
+ const gridRect = gridElement.getBoundingClientRect();
669
+ const positionParams = {
670
+ cols,
671
+ margin,
672
+ maxRows,
673
+ rowHeight,
674
+ containerWidth: width,
675
+ containerPadding
676
+ };
677
+ const actualColWidth = chunkVJJIA3HC_js.calcGridColWidth(positionParams);
678
+ const itemPixelWidth = chunkVJJIA3HC_js.calcGridItemWHPx(
679
+ droppingItem.w,
680
+ actualColWidth,
681
+ margin[0]
682
+ );
683
+ const itemPixelHeight = chunkVJJIA3HC_js.calcGridItemWHPx(
684
+ droppingItem.h,
685
+ rowHeight,
686
+ margin[1]
687
+ );
688
+ const itemCenterOffsetX = itemPixelWidth / 2;
689
+ const itemCenterOffsetY = itemPixelHeight / 2;
690
+ const scrollLeft = gridElement.scrollLeft ?? 0;
691
+ const scrollTop = gridElement.scrollTop ?? 0;
692
+ const rawGridX = clientX - gridRect.left + scrollLeft + dragOffsetX - itemCenterOffsetX;
693
+ const rawGridY = clientY - gridRect.top + scrollTop + dragOffsetY - itemCenterOffsetY;
694
+ const clampedGridX = Math.max(0, rawGridX);
695
+ const clampedGridY = Math.max(0, rawGridY);
696
+ const newDroppingPosition = {
697
+ left: clampedGridX / transformScale,
698
+ top: clampedGridY / transformScale,
699
+ e: event
700
+ };
701
+ const calculatedXY = chunkVJJIA3HC_js.calcXY(
702
+ positionParams,
703
+ clampedGridY,
704
+ clampedGridX,
705
+ droppingItem.w,
706
+ droppingItem.h
707
+ );
708
+ return {
709
+ newDroppingPosition,
710
+ calculatedXY
711
+ };
712
+ }
545
713
  var noop = () => {
546
714
  };
547
715
  var layoutClassName = "react-grid-layout";
@@ -570,7 +738,7 @@ function synchronizeLayoutWithChildren(initialLayout, children, cols, compactor)
570
738
  childKeys.add(key);
571
739
  const existingItem = initialLayout.find((l) => l.i === key);
572
740
  if (existingItem) {
573
- layout.push(chunkA5WIFECI_js.cloneLayoutItem(existingItem));
741
+ layout.push(chunkVJJIA3HC_js.cloneLayoutItem(existingItem));
574
742
  } else {
575
743
  const childProps = child.props;
576
744
  const dataGrid = childProps["data-grid"];
@@ -595,14 +763,14 @@ function synchronizeLayoutWithChildren(initialLayout, children, cols, compactor)
595
763
  layout.push({
596
764
  i: key,
597
765
  x: 0,
598
- y: chunkA5WIFECI_js.bottom(layout),
766
+ y: chunkVJJIA3HC_js.bottom(layout),
599
767
  w: 1,
600
768
  h: 1
601
769
  });
602
770
  }
603
771
  }
604
772
  });
605
- const corrected = chunkA5WIFECI_js.correctBounds(layout, { cols });
773
+ const corrected = chunkVJJIA3HC_js.correctBounds(layout, { cols });
606
774
  return compactor.compact(corrected, cols);
607
775
  }
608
776
  function GridLayout(props) {
@@ -615,9 +783,9 @@ function GridLayout(props) {
615
783
  dragConfig: dragConfigProp,
616
784
  resizeConfig: resizeConfigProp,
617
785
  dropConfig: dropConfigProp,
618
- positionStrategy = chunk55DQUWLA_js.defaultPositionStrategy,
786
+ positionStrategy = chunkQAIA5KAO_js.defaultPositionStrategy,
619
787
  compactor: compactorProp,
620
- constraints = chunk55DQUWLA_js.defaultConstraints,
788
+ constraints = chunkQAIA5KAO_js.defaultConstraints,
621
789
  // Layout data
622
790
  layout: propsLayout = [],
623
791
  droppingItem: droppingItemProp,
@@ -638,19 +806,19 @@ function GridLayout(props) {
638
806
  onDropDragOver: onDropDragOverProp = noop
639
807
  } = props;
640
808
  const gridConfig = React2.useMemo(
641
- () => ({ ...chunk55DQUWLA_js.defaultGridConfig, ...gridConfigProp }),
809
+ () => ({ ...chunkQAIA5KAO_js.defaultGridConfig, ...gridConfigProp }),
642
810
  [gridConfigProp]
643
811
  );
644
812
  const dragConfig = React2.useMemo(
645
- () => ({ ...chunk55DQUWLA_js.defaultDragConfig, ...dragConfigProp }),
813
+ () => ({ ...chunkQAIA5KAO_js.defaultDragConfig, ...dragConfigProp }),
646
814
  [dragConfigProp]
647
815
  );
648
816
  const resizeConfig = React2.useMemo(
649
- () => ({ ...chunk55DQUWLA_js.defaultResizeConfig, ...resizeConfigProp }),
817
+ () => ({ ...chunkQAIA5KAO_js.defaultResizeConfig, ...resizeConfigProp }),
650
818
  [resizeConfigProp]
651
819
  );
652
820
  const dropConfig = React2.useMemo(
653
- () => ({ ...chunk55DQUWLA_js.defaultDropConfig, ...dropConfigProp }),
821
+ () => ({ ...chunkQAIA5KAO_js.defaultDropConfig, ...dropConfigProp }),
654
822
  [dropConfigProp]
655
823
  );
656
824
  const { cols, rowHeight, maxRows, margin, containerPadding } = gridConfig;
@@ -659,7 +827,8 @@ function GridLayout(props) {
659
827
  bounded: isBounded,
660
828
  handle: draggableHandle,
661
829
  cancel: draggableCancel,
662
- threshold: dragThreshold
830
+ threshold: dragThreshold,
831
+ allowMobileScroll: dragAllowMobileScroll
663
832
  } = dragConfig;
664
833
  const {
665
834
  enabled: isResizable,
@@ -669,9 +838,11 @@ function GridLayout(props) {
669
838
  const {
670
839
  enabled: isDroppable,
671
840
  defaultItem: defaultDropItem,
672
- onDragOver: dropConfigOnDragOver
841
+ onDragOver: dropConfigOnDragOver,
842
+ touchEnabled = true,
843
+ touchDragSource = "[data-rgl-draggable]"
673
844
  } = dropConfig;
674
- const compactor = compactorProp ?? chunk55DQUWLA_js.getCompactor("vertical");
845
+ const compactor = compactorProp ?? chunkQAIA5KAO_js.getCompactor("vertical");
675
846
  const compactType = compactor.type;
676
847
  const allowOverlap = compactor.allowOverlap;
677
848
  const preventCollision = compactor.preventCollision ?? false;
@@ -695,6 +866,8 @@ function GridLayout(props) {
695
866
  null
696
867
  );
697
868
  const [droppingPosition, setDroppingPosition] = React2.useState();
869
+ const droppingPositionRef = React2.useRef(void 0);
870
+ droppingPositionRef.current = droppingPosition;
698
871
  const oldDragItemRef = React2.useRef(null);
699
872
  const oldResizeItemRef = React2.useRef(null);
700
873
  const oldLayoutRef = React2.useRef(null);
@@ -703,6 +876,15 @@ function GridLayout(props) {
703
876
  const prevPropsLayoutRef = React2.useRef(propsLayout);
704
877
  const prevChildrenRef = React2.useRef(children);
705
878
  const prevCompactTypeRef = React2.useRef(compactType);
879
+ const gridContainerRef = React2.useRef(null);
880
+ const touchDragActiveRef = React2.useRef(false);
881
+ const activeTouchIdRef = React2.useRef(null);
882
+ const droppingDOMNodeRef = React2.useRef(null);
883
+ droppingDOMNodeRef.current = droppingDOMNode;
884
+ const onDropPropRef = React2.useRef(onDropProp);
885
+ React2.useLayoutEffect(() => {
886
+ onDropPropRef.current = onDropProp;
887
+ });
706
888
  const layoutRef = React2.useRef(layout);
707
889
  layoutRef.current = layout;
708
890
  React2.useEffect(() => {
@@ -743,22 +925,22 @@ function GridLayout(props) {
743
925
  layout
744
926
  ]);
745
927
  React2.useEffect(() => {
746
- if (!activeDrag && !fastEquals.deepEqual(layout, prevLayoutRef.current)) {
928
+ if (!activeDrag && !droppingDOMNode && !fastEquals.deepEqual(layout, prevLayoutRef.current)) {
747
929
  prevLayoutRef.current = layout;
748
930
  const publicLayout = layout.filter((l) => l.i !== droppingItem.i);
749
931
  onLayoutChange(publicLayout);
750
932
  }
751
- }, [layout, activeDrag, onLayoutChange, droppingItem.i]);
933
+ }, [layout, activeDrag, droppingDOMNode, onLayoutChange, droppingItem.i]);
752
934
  const containerHeight = React2.useMemo(() => {
753
935
  if (!autoSize) return void 0;
754
- const nbRow = chunkA5WIFECI_js.bottom(layout);
936
+ const nbRow = chunkVJJIA3HC_js.bottom(layout);
755
937
  const containerPaddingY = effectiveContainerPadding[1];
756
938
  return nbRow * rowHeight + (nbRow - 1) * margin[1] + containerPaddingY * 2 + "px";
757
939
  }, [autoSize, layout, rowHeight, margin, effectiveContainerPadding]);
758
940
  const onDragStart = React2.useCallback(
759
941
  (i, _x, _y, data) => {
760
942
  const currentLayout = layoutRef.current;
761
- const l = chunkA5WIFECI_js.getLayoutItem(currentLayout, i);
943
+ const l = chunkVJJIA3HC_js.getLayoutItem(currentLayout, i);
762
944
  if (!l) return;
763
945
  const placeholder = {
764
946
  w: l.w,
@@ -767,7 +949,7 @@ function GridLayout(props) {
767
949
  y: l.y,
768
950
  i
769
951
  };
770
- oldDragItemRef.current = chunkA5WIFECI_js.cloneLayoutItem(l);
952
+ oldDragItemRef.current = chunkVJJIA3HC_js.cloneLayoutItem(l);
771
953
  oldLayoutRef.current = currentLayout;
772
954
  setActiveDrag(placeholder);
773
955
  onDragStartProp(currentLayout, l, l, null, data.e, data.node);
@@ -778,7 +960,7 @@ function GridLayout(props) {
778
960
  (i, x, y, data) => {
779
961
  const currentLayout = layoutRef.current;
780
962
  const oldDragItem = oldDragItemRef.current;
781
- const l = chunkA5WIFECI_js.getLayoutItem(currentLayout, i);
963
+ const l = chunkVJJIA3HC_js.getLayoutItem(currentLayout, i);
782
964
  if (!l) return;
783
965
  const placeholder = {
784
966
  w: l.w,
@@ -787,7 +969,7 @@ function GridLayout(props) {
787
969
  y: l.y,
788
970
  i
789
971
  };
790
- const newLayout = chunkA5WIFECI_js.moveElement(
972
+ const newLayout = chunkVJJIA3HC_js.moveElement(
791
973
  currentLayout,
792
974
  l,
793
975
  x,
@@ -806,12 +988,12 @@ function GridLayout(props) {
806
988
  );
807
989
  const onDragStop = React2.useCallback(
808
990
  (i, x, y, data) => {
809
- if (!activeDrag) return;
991
+ if (!oldDragItemRef.current) return;
810
992
  const currentLayout = layoutRef.current;
811
993
  const oldDragItem = oldDragItemRef.current;
812
- const l = chunkA5WIFECI_js.getLayoutItem(currentLayout, i);
994
+ const l = chunkVJJIA3HC_js.getLayoutItem(currentLayout, i);
813
995
  if (!l) return;
814
- const newLayout = chunkA5WIFECI_js.moveElement(
996
+ const newLayout = chunkVJJIA3HC_js.moveElement(
815
997
  currentLayout,
816
998
  l,
817
999
  x,
@@ -834,7 +1016,6 @@ function GridLayout(props) {
834
1016
  }
835
1017
  },
836
1018
  [
837
- activeDrag,
838
1019
  preventCollision,
839
1020
  compactType,
840
1021
  cols,
@@ -847,9 +1028,9 @@ function GridLayout(props) {
847
1028
  const onResizeStart = React2.useCallback(
848
1029
  (i, _w, _h, data) => {
849
1030
  const currentLayout = layoutRef.current;
850
- const l = chunkA5WIFECI_js.getLayoutItem(currentLayout, i);
1031
+ const l = chunkVJJIA3HC_js.getLayoutItem(currentLayout, i);
851
1032
  if (!l) return;
852
- oldResizeItemRef.current = chunkA5WIFECI_js.cloneLayoutItem(l);
1033
+ oldResizeItemRef.current = chunkVJJIA3HC_js.cloneLayoutItem(l);
853
1034
  oldLayoutRef.current = currentLayout;
854
1035
  setResizing(true);
855
1036
  onResizeStartProp(currentLayout, l, l, null, data.e, data.node);
@@ -864,7 +1045,7 @@ function GridLayout(props) {
864
1045
  let shouldMoveItem = false;
865
1046
  let newX;
866
1047
  let newY;
867
- const [newLayout, l] = chunkA5WIFECI_js.withLayoutItem(currentLayout, i, (item) => {
1048
+ const [newLayout, l] = chunkVJJIA3HC_js.withLayoutItem(currentLayout, i, (item) => {
868
1049
  newX = item.x;
869
1050
  newY = item.y;
870
1051
  if (["sw", "w", "nw", "n", "ne"].includes(handle)) {
@@ -881,7 +1062,7 @@ function GridLayout(props) {
881
1062
  shouldMoveItem = true;
882
1063
  }
883
1064
  if (preventCollision && !allowOverlap) {
884
- const collisions = chunkA5WIFECI_js.getAllCollisions(currentLayout, {
1065
+ const collisions = chunkVJJIA3HC_js.getAllCollisions(currentLayout, {
885
1066
  ...item,
886
1067
  w,
887
1068
  h,
@@ -898,12 +1079,15 @@ function GridLayout(props) {
898
1079
  }
899
1080
  item.w = w;
900
1081
  item.h = h;
1082
+ if (handle === "n" || handle === "nw" || handle === "ne") {
1083
+ item.y = newY ?? item.y;
1084
+ }
901
1085
  return item;
902
1086
  });
903
1087
  if (!l) return;
904
1088
  let finalLayout = newLayout;
905
1089
  if (shouldMoveItem && newX !== void 0 && newY !== void 0) {
906
- finalLayout = chunkA5WIFECI_js.moveElement(
1090
+ finalLayout = chunkVJJIA3HC_js.moveElement(
907
1091
  newLayout,
908
1092
  l,
909
1093
  newX,
@@ -931,7 +1115,14 @@ function GridLayout(props) {
931
1115
  data.e,
932
1116
  data.node
933
1117
  );
934
- setLayout(compactor.compact(finalLayout, cols));
1118
+ const compactedLayout = compactor.compact(finalLayout, cols);
1119
+ if (handle === "n" || handle === "nw" || handle === "ne") {
1120
+ const resized = compactedLayout.find((item) => item.i === i);
1121
+ if (resized) {
1122
+ resized.y = l.y;
1123
+ }
1124
+ }
1125
+ setLayout(compactedLayout);
935
1126
  setActiveDrag(placeholder);
936
1127
  },
937
1128
  [preventCollision, compactType, cols, allowOverlap, compactor, onResizeProp]
@@ -940,7 +1131,7 @@ function GridLayout(props) {
940
1131
  (i, _w, _h, data) => {
941
1132
  const currentLayout = layoutRef.current;
942
1133
  const oldResizeItem = oldResizeItemRef.current;
943
- const l = chunkA5WIFECI_js.getLayoutItem(currentLayout, i);
1134
+ const l = chunkVJJIA3HC_js.getLayoutItem(currentLayout, i);
944
1135
  const finalLayout = compactor.compact(currentLayout, cols);
945
1136
  onResizeStopProp(
946
1137
  finalLayout,
@@ -962,6 +1153,73 @@ function GridLayout(props) {
962
1153
  },
963
1154
  [cols, compactor, onResizeStopProp, onLayoutChange]
964
1155
  );
1156
+ const placeDroppingItem = React2.useCallback(
1157
+ (itemToPlace, newDroppingPosition, calculatedXY, hasPlaceholder) => {
1158
+ if (!hasPlaceholder) {
1159
+ setDroppingDOMNode(/* @__PURE__ */ jsxRuntime.jsx("div", {}, itemToPlace.i));
1160
+ setDroppingPosition(newDroppingPosition);
1161
+ const baseLayout = layoutRef.current.filter((l) => l.i !== itemToPlace.i);
1162
+ setLayout([
1163
+ ...baseLayout,
1164
+ {
1165
+ ...itemToPlace,
1166
+ x: calculatedXY.x,
1167
+ y: calculatedXY.y,
1168
+ static: false,
1169
+ isDraggable: true
1170
+ }
1171
+ ]);
1172
+ } else if (droppingPositionRef.current) {
1173
+ const shouldUpdate = droppingPositionRef.current.left !== newDroppingPosition.left || droppingPositionRef.current.top !== newDroppingPosition.top;
1174
+ if (shouldUpdate) {
1175
+ setDroppingPosition(newDroppingPosition);
1176
+ setLayout(
1177
+ (currentLayout) => currentLayout.map(
1178
+ (item) => item.i === itemToPlace.i && (item.x !== calculatedXY.x || item.y !== calculatedXY.y) ? { ...item, x: calculatedXY.x, y: calculatedXY.y } : item
1179
+ )
1180
+ );
1181
+ }
1182
+ }
1183
+ },
1184
+ []
1185
+ );
1186
+ const applyTouchDropPosition = React2.useCallback(
1187
+ (clientX, clientY, nativeEvent) => {
1188
+ const gridEl = gridContainerRef.current;
1189
+ if (!gridEl) return;
1190
+ const { newDroppingPosition, calculatedXY } = computeDropPosition({
1191
+ clientX,
1192
+ clientY,
1193
+ gridElement: gridEl,
1194
+ droppingItem,
1195
+ event: nativeEvent,
1196
+ transformScale,
1197
+ cols,
1198
+ margin,
1199
+ maxRows,
1200
+ rowHeight,
1201
+ width,
1202
+ containerPadding: effectiveContainerPadding
1203
+ });
1204
+ placeDroppingItem(
1205
+ droppingItem,
1206
+ newDroppingPosition,
1207
+ calculatedXY,
1208
+ !!droppingDOMNodeRef.current
1209
+ );
1210
+ },
1211
+ [
1212
+ droppingItem,
1213
+ transformScale,
1214
+ cols,
1215
+ margin,
1216
+ maxRows,
1217
+ rowHeight,
1218
+ width,
1219
+ effectiveContainerPadding,
1220
+ placeDroppingItem
1221
+ ]
1222
+ );
965
1223
  const removeDroppingPlaceholder = React2.useCallback(() => {
966
1224
  const currentLayout = layoutRef.current;
967
1225
  const hasDroppingItem = currentLayout.some((l) => l.i === droppingItem.i);
@@ -1002,74 +1260,36 @@ function GridLayout(props) {
1002
1260
  ...onDragOverResult
1003
1261
  } = rawResult ?? {};
1004
1262
  const finalDroppingItem = { ...droppingItem, ...onDragOverResult };
1005
- const gridRect = e.currentTarget.getBoundingClientRect();
1006
- const positionParams = {
1263
+ const { newDroppingPosition, calculatedXY } = computeDropPosition({
1264
+ clientX: e.clientX,
1265
+ clientY: e.clientY,
1266
+ gridElement: e.currentTarget,
1267
+ droppingItem: finalDroppingItem,
1268
+ event: e.nativeEvent,
1269
+ dragOffsetX,
1270
+ dragOffsetY,
1271
+ transformScale,
1007
1272
  cols,
1008
1273
  margin,
1009
1274
  maxRows,
1010
1275
  rowHeight,
1011
- containerWidth: width,
1276
+ width,
1012
1277
  containerPadding: effectiveContainerPadding
1013
- };
1014
- const actualColWidth = chunkA5WIFECI_js.calcGridColWidth(positionParams);
1015
- const itemPixelWidth = chunkA5WIFECI_js.calcGridItemWHPx(
1016
- finalDroppingItem.w,
1017
- actualColWidth,
1018
- margin[0]
1019
- );
1020
- const itemPixelHeight = chunkA5WIFECI_js.calcGridItemWHPx(
1021
- finalDroppingItem.h,
1022
- rowHeight,
1023
- margin[1]
1278
+ });
1279
+ placeDroppingItem(
1280
+ finalDroppingItem,
1281
+ newDroppingPosition,
1282
+ calculatedXY,
1283
+ !!droppingDOMNode
1024
1284
  );
1025
- const itemCenterOffsetX = itemPixelWidth / 2;
1026
- const itemCenterOffsetY = itemPixelHeight / 2;
1027
- const rawGridX = e.clientX - gridRect.left + dragOffsetX - itemCenterOffsetX;
1028
- const rawGridY = e.clientY - gridRect.top + dragOffsetY - itemCenterOffsetY;
1029
- const clampedGridX = Math.max(0, rawGridX);
1030
- const clampedGridY = Math.max(0, rawGridY);
1031
- const newDroppingPosition = {
1032
- left: clampedGridX / transformScale,
1033
- top: clampedGridY / transformScale,
1034
- e: e.nativeEvent
1035
- };
1036
- if (!droppingDOMNode) {
1037
- const calculatedPosition = chunkA5WIFECI_js.calcXY(
1038
- positionParams,
1039
- clampedGridY,
1040
- clampedGridX,
1041
- finalDroppingItem.w,
1042
- finalDroppingItem.h
1043
- );
1044
- setDroppingDOMNode(/* @__PURE__ */ jsxRuntime.jsx("div", {}, finalDroppingItem.i));
1045
- setDroppingPosition(newDroppingPosition);
1046
- const baseLayout = layoutRef.current.filter(
1047
- (l) => l.i !== finalDroppingItem.i
1048
- );
1049
- setLayout([
1050
- ...baseLayout,
1051
- {
1052
- ...finalDroppingItem,
1053
- x: calculatedPosition.x,
1054
- y: calculatedPosition.y,
1055
- static: false,
1056
- isDraggable: true
1057
- }
1058
- ]);
1059
- } else if (droppingPosition) {
1060
- const shouldUpdate = droppingPosition.left !== newDroppingPosition.left || droppingPosition.top !== newDroppingPosition.top;
1061
- if (shouldUpdate) {
1062
- setDroppingPosition(newDroppingPosition);
1063
- }
1064
- }
1065
1285
  },
1066
1286
  [
1067
1287
  droppingDOMNode,
1068
- droppingPosition,
1069
1288
  droppingItem,
1070
1289
  dropConfigOnDragOver,
1071
1290
  onDropDragOverProp,
1072
1291
  removeDroppingPlaceholder,
1292
+ placeDroppingItem,
1073
1293
  transformScale,
1074
1294
  cols,
1075
1295
  margin,
@@ -1098,22 +1318,110 @@ function GridLayout(props) {
1098
1318
  e.stopPropagation();
1099
1319
  dragEnterCounterRef.current++;
1100
1320
  }, []);
1321
+ const commitDrop = React2.useCallback(
1322
+ (nativeEvent) => {
1323
+ const currentLayout = layoutRef.current;
1324
+ const item = currentLayout.find((l) => l.i === droppingItem.i);
1325
+ removeDroppingPlaceholder();
1326
+ onDropPropRef.current(currentLayout, item, nativeEvent);
1327
+ },
1328
+ [droppingItem.i, removeDroppingPlaceholder]
1329
+ );
1101
1330
  const handleDrop = React2.useCallback(
1102
1331
  (e) => {
1103
1332
  e.preventDefault();
1104
1333
  e.stopPropagation();
1105
- const currentLayout = layoutRef.current;
1106
- const item = currentLayout.find((l) => l.i === droppingItem.i);
1107
1334
  dragEnterCounterRef.current = 0;
1108
- removeDroppingPlaceholder();
1109
- onDropProp(currentLayout, item, e.nativeEvent);
1335
+ commitDrop(e.nativeEvent);
1110
1336
  },
1111
- [droppingItem.i, removeDroppingPlaceholder, onDropProp]
1337
+ [commitDrop]
1112
1338
  );
1339
+ React2.useEffect(() => {
1340
+ if (!isDroppable || !touchEnabled) return;
1341
+ const gridEl = gridContainerRef.current;
1342
+ if (!gridEl) return;
1343
+ const isOverGrid = (clientX, clientY) => {
1344
+ const el = document.elementFromPoint(clientX, clientY);
1345
+ return el ? gridEl.contains(el) : false;
1346
+ };
1347
+ const isSourceElement = (target) => {
1348
+ if (!(target instanceof HTMLElement)) return false;
1349
+ return target.closest(touchDragSource) !== null;
1350
+ };
1351
+ const getTouch = (e) => {
1352
+ const touches = e.changedTouches;
1353
+ if (!touches || touches.length === 0) return void 0;
1354
+ const id = activeTouchIdRef.current;
1355
+ if (id === null) return touches[0];
1356
+ for (let i = 0; i < touches.length; i++) {
1357
+ const touch = touches[i];
1358
+ if (touch && touch.identifier === id) return touch;
1359
+ }
1360
+ return void 0;
1361
+ };
1362
+ const handleTouchStart = (e) => {
1363
+ if (!isSourceElement(e.target)) return;
1364
+ if (activeTouchIdRef.current !== null) return;
1365
+ e.preventDefault();
1366
+ const touch = e.changedTouches?.[0];
1367
+ if (!touch) return;
1368
+ activeTouchIdRef.current = touch.identifier;
1369
+ touchDragActiveRef.current = true;
1370
+ };
1371
+ const handleTouchMove = (e) => {
1372
+ if (!touchDragActiveRef.current) return;
1373
+ e.preventDefault();
1374
+ const touch = getTouch(e);
1375
+ if (!touch) return;
1376
+ if (!isOverGrid(touch.clientX, touch.clientY)) {
1377
+ if (droppingDOMNodeRef.current) removeDroppingPlaceholder();
1378
+ return;
1379
+ }
1380
+ applyTouchDropPosition(touch.clientX, touch.clientY, e);
1381
+ };
1382
+ const handleTouchEnd = (e) => {
1383
+ if (!touchDragActiveRef.current) return;
1384
+ e.preventDefault();
1385
+ const touch = getTouch(e);
1386
+ touchDragActiveRef.current = false;
1387
+ activeTouchIdRef.current = null;
1388
+ if (!touch) return;
1389
+ if (!isOverGrid(touch.clientX, touch.clientY)) {
1390
+ removeDroppingPlaceholder();
1391
+ return;
1392
+ }
1393
+ commitDrop(e);
1394
+ };
1395
+ const handleTouchCancel = () => {
1396
+ if (!touchDragActiveRef.current) return;
1397
+ touchDragActiveRef.current = false;
1398
+ activeTouchIdRef.current = null;
1399
+ removeDroppingPlaceholder();
1400
+ };
1401
+ const opts = { passive: false };
1402
+ document.addEventListener("touchstart", handleTouchStart, opts);
1403
+ document.addEventListener("touchmove", handleTouchMove, opts);
1404
+ document.addEventListener("touchend", handleTouchEnd, opts);
1405
+ document.addEventListener("touchcancel", handleTouchCancel, opts);
1406
+ return () => {
1407
+ document.removeEventListener("touchstart", handleTouchStart, opts);
1408
+ document.removeEventListener("touchmove", handleTouchMove, opts);
1409
+ document.removeEventListener("touchend", handleTouchEnd, opts);
1410
+ document.removeEventListener("touchcancel", handleTouchCancel, opts);
1411
+ };
1412
+ }, [
1413
+ isDroppable,
1414
+ touchEnabled,
1415
+ touchDragSource,
1416
+ applyTouchDropPosition,
1417
+ removeDroppingPlaceholder,
1418
+ commitDrop,
1419
+ droppingItem.i
1420
+ ]);
1113
1421
  const processGridItem = React2.useCallback(
1114
1422
  (child, isDroppingItem) => {
1115
1423
  if (!child || !child.key) return null;
1116
- const l = chunkA5WIFECI_js.getLayoutItem(layout, String(child.key));
1424
+ const l = chunkVJJIA3HC_js.getLayoutItem(layout, String(child.key));
1117
1425
  if (!l) return null;
1118
1426
  const draggable = typeof l.isDraggable === "boolean" ? l.isDraggable : !l.static && isDraggable;
1119
1427
  const resizable = typeof l.isResizable === "boolean" ? l.isResizable : !l.static && isResizable;
@@ -1140,6 +1448,7 @@ function GridLayout(props) {
1140
1448
  isDraggable: draggable,
1141
1449
  isResizable: resizable,
1142
1450
  isBounded: bounded,
1451
+ allowMobileScroll: dragAllowMobileScroll,
1143
1452
  useCSSTransforms: useCSSTransforms && mounted,
1144
1453
  usePercentages: !mounted,
1145
1454
  transformScale,
@@ -1224,6 +1533,17 @@ function GridLayout(props) {
1224
1533
  }
1225
1534
  );
1226
1535
  };
1536
+ const setGridRef = React2.useCallback(
1537
+ (node) => {
1538
+ gridContainerRef.current = node;
1539
+ if (typeof innerRef === "function") {
1540
+ innerRef(node);
1541
+ } else if (innerRef && "current" in innerRef) {
1542
+ innerRef.current = node;
1543
+ }
1544
+ },
1545
+ [innerRef]
1546
+ );
1227
1547
  const mergedClassName = clsx__default.default(layoutClassName, className);
1228
1548
  const mergedStyle = {
1229
1549
  height: containerHeight,
@@ -1232,7 +1552,7 @@ function GridLayout(props) {
1232
1552
  return /* @__PURE__ */ jsxRuntime.jsxs(
1233
1553
  "div",
1234
1554
  {
1235
- ref: innerRef,
1555
+ ref: setGridRef,
1236
1556
  className: mergedClassName,
1237
1557
  style: mergedStyle,
1238
1558
  onDrop: isDroppable ? handleDrop : void 0,
@@ -1266,20 +1586,33 @@ var DEFAULT_COLS = {
1266
1586
  };
1267
1587
  var noop2 = () => {
1268
1588
  };
1269
- function synchronizeLayoutWithChildren2(initialLayout, children, cols, compactor) {
1589
+ function synchronizeLayoutWithChildren2(initialLayout, children, cols, compactor, reSeedFromDataGrid = false) {
1270
1590
  const layout = [];
1271
1591
  React2__default.default.Children.forEach(children, (child) => {
1272
1592
  if (!React2__default.default.isValidElement(child) || child.key === null) return;
1273
1593
  const key = String(child.key);
1594
+ const childProps = child.props;
1595
+ const dataGrid = childProps["data-grid"];
1274
1596
  const existingItem = initialLayout.find((l) => l.i === key);
1275
1597
  if (existingItem) {
1276
- layout.push({
1277
- ...existingItem,
1278
- i: key
1279
- });
1598
+ if (reSeedFromDataGrid && dataGrid) {
1599
+ layout.push({
1600
+ ...existingItem,
1601
+ i: key,
1602
+ w: dataGrid.w ?? existingItem.w,
1603
+ h: dataGrid.h ?? existingItem.h,
1604
+ minW: dataGrid.minW ?? existingItem.minW,
1605
+ maxW: dataGrid.maxW ?? existingItem.maxW,
1606
+ minH: dataGrid.minH ?? existingItem.minH,
1607
+ maxH: dataGrid.maxH ?? existingItem.maxH
1608
+ });
1609
+ } else {
1610
+ layout.push({
1611
+ ...existingItem,
1612
+ i: key
1613
+ });
1614
+ }
1280
1615
  } else {
1281
- const childProps = child.props;
1282
- const dataGrid = childProps["data-grid"];
1283
1616
  if (dataGrid) {
1284
1617
  layout.push({
1285
1618
  i: key,
@@ -1301,17 +1634,17 @@ function synchronizeLayoutWithChildren2(initialLayout, children, cols, compactor
1301
1634
  layout.push({
1302
1635
  i: key,
1303
1636
  x: 0,
1304
- y: chunkA5WIFECI_js.bottom(layout),
1637
+ y: chunkVJJIA3HC_js.bottom(layout),
1305
1638
  w: 1,
1306
1639
  h: 1
1307
1640
  });
1308
1641
  }
1309
1642
  }
1310
1643
  });
1311
- const corrected = chunkA5WIFECI_js.correctBounds(layout, { cols });
1644
+ const corrected = chunkVJJIA3HC_js.correctBounds(layout, { cols });
1312
1645
  return compactor.compact(corrected, cols);
1313
1646
  }
1314
- function ResponsiveGridLayout(props) {
1647
+ function ResponsiveGridLayoutInner(props) {
1315
1648
  const {
1316
1649
  children,
1317
1650
  width,
@@ -1329,17 +1662,17 @@ function ResponsiveGridLayout(props) {
1329
1662
  onWidthChange = noop2,
1330
1663
  ...restProps
1331
1664
  } = props;
1332
- const compactor = compactorProp ?? chunk55DQUWLA_js.getCompactor("vertical");
1665
+ const compactor = compactorProp ?? chunkQAIA5KAO_js.getCompactor("vertical");
1333
1666
  const compactType = compactor.type;
1334
1667
  const allowOverlap = compactor.allowOverlap;
1335
1668
  const initialBreakpoint = React2.useMemo(() => {
1336
- return propBreakpoint ?? chunk55DQUWLA_js.getBreakpointFromWidth(breakpoints, width);
1669
+ return propBreakpoint ?? chunkQAIA5KAO_js.getBreakpointFromWidth(breakpoints, width);
1337
1670
  }, []);
1338
1671
  const initialCols = React2.useMemo(() => {
1339
- return chunk55DQUWLA_js.getColsFromBreakpoint(initialBreakpoint, colsConfig);
1672
+ return chunkQAIA5KAO_js.getColsFromBreakpoint(initialBreakpoint, colsConfig);
1340
1673
  }, [initialBreakpoint, colsConfig]);
1341
1674
  const initialLayout = React2.useMemo(() => {
1342
- return chunk55DQUWLA_js.findOrGenerateResponsiveLayout(
1675
+ return chunkQAIA5KAO_js.findOrGenerateResponsiveLayout(
1343
1676
  propsLayouts,
1344
1677
  breakpoints,
1345
1678
  initialBreakpoint,
@@ -1364,7 +1697,7 @@ function ResponsiveGridLayout(props) {
1364
1697
  }, [layouts]);
1365
1698
  const derivedLayout = React2.useMemo(() => {
1366
1699
  if (!fastEquals.deepEqual(propsLayouts, prevLayoutsRef.current)) {
1367
- return chunk55DQUWLA_js.findOrGenerateResponsiveLayout(
1700
+ return chunkQAIA5KAO_js.findOrGenerateResponsiveLayout(
1368
1701
  propsLayouts,
1369
1702
  breakpoints,
1370
1703
  breakpoint,
@@ -1386,7 +1719,7 @@ function ResponsiveGridLayout(props) {
1386
1719
  }, [derivedLayout, propsLayouts]);
1387
1720
  React2.useEffect(() => {
1388
1721
  if (compactType !== prevCompactTypeRef.current) {
1389
- const newLayout = compactor.compact(chunkA5WIFECI_js.cloneLayout(effectiveLayout), cols);
1722
+ const newLayout = compactor.compact(chunkVJJIA3HC_js.cloneLayout(effectiveLayout), cols);
1390
1723
  const newLayouts = {
1391
1724
  ...layoutsRef.current,
1392
1725
  [breakpoint]: newLayout
@@ -1415,15 +1748,15 @@ function ResponsiveGridLayout(props) {
1415
1748
  );
1416
1749
  const colsChanged = !fastEquals.deepEqual(colsConfig, prevColsRef.current);
1417
1750
  if (widthChanged || breakpointPropChanged || breakpointsChanged || colsChanged) {
1418
- const newBreakpoint = propBreakpoint ?? chunk55DQUWLA_js.getBreakpointFromWidth(breakpoints, width);
1419
- const newCols = chunk55DQUWLA_js.getColsFromBreakpoint(newBreakpoint, colsConfig);
1751
+ const newBreakpoint = propBreakpoint ?? chunkQAIA5KAO_js.getBreakpointFromWidth(breakpoints, width);
1752
+ const newCols = chunkQAIA5KAO_js.getColsFromBreakpoint(newBreakpoint, colsConfig);
1420
1753
  const lastBreakpoint = breakpoint;
1421
1754
  if (lastBreakpoint !== newBreakpoint || breakpointsChanged || colsChanged) {
1422
1755
  const newLayouts = { ...layoutsRef.current };
1423
1756
  if (!newLayouts[lastBreakpoint]) {
1424
- newLayouts[lastBreakpoint] = chunkA5WIFECI_js.cloneLayout(layout);
1757
+ newLayouts[lastBreakpoint] = chunkVJJIA3HC_js.cloneLayout(layout);
1425
1758
  }
1426
- let newLayout = chunk55DQUWLA_js.findOrGenerateResponsiveLayout(
1759
+ let newLayout = chunkQAIA5KAO_js.findOrGenerateResponsiveLayout(
1427
1760
  newLayouts,
1428
1761
  breakpoints,
1429
1762
  newBreakpoint,
@@ -1431,11 +1764,13 @@ function ResponsiveGridLayout(props) {
1431
1764
  newCols,
1432
1765
  compactor
1433
1766
  );
1767
+ const layoutWasGenerated = !newLayouts[newBreakpoint];
1434
1768
  newLayout = synchronizeLayoutWithChildren2(
1435
1769
  newLayout,
1436
1770
  children,
1437
1771
  newCols,
1438
- compactor
1772
+ compactor,
1773
+ layoutWasGenerated
1439
1774
  );
1440
1775
  newLayouts[newBreakpoint] = newLayout;
1441
1776
  setBreakpoint(newBreakpoint);
@@ -1446,11 +1781,11 @@ function ResponsiveGridLayout(props) {
1446
1781
  onBreakpointChange(newBreakpoint, newCols);
1447
1782
  onLayoutChange(newLayout, newLayouts);
1448
1783
  }
1449
- const currentMargin2 = chunk55DQUWLA_js.getIndentationValue(
1784
+ const currentMargin2 = chunkQAIA5KAO_js.getIndentationValue(
1450
1785
  propMargin,
1451
1786
  newBreakpoint
1452
1787
  );
1453
- const currentPadding = propContainerPadding ? chunk55DQUWLA_js.getIndentationValue(
1788
+ const currentPadding = propContainerPadding ? chunkQAIA5KAO_js.getIndentationValue(
1454
1789
  propContainerPadding,
1455
1790
  newBreakpoint
1456
1791
  ) : null;
@@ -1493,14 +1828,14 @@ function ResponsiveGridLayout(props) {
1493
1828
  [breakpoint, onLayoutChange]
1494
1829
  );
1495
1830
  const currentMargin = React2.useMemo(() => {
1496
- return chunk55DQUWLA_js.getIndentationValue(
1831
+ return chunkQAIA5KAO_js.getIndentationValue(
1497
1832
  propMargin,
1498
1833
  breakpoint
1499
1834
  );
1500
1835
  }, [propMargin, breakpoint]);
1501
1836
  const currentContainerPadding = React2.useMemo(() => {
1502
1837
  if (propContainerPadding === null) return null;
1503
- return chunk55DQUWLA_js.getIndentationValue(
1838
+ return chunkQAIA5KAO_js.getIndentationValue(
1504
1839
  propContainerPadding,
1505
1840
  breakpoint
1506
1841
  );
@@ -1528,7 +1863,13 @@ function ResponsiveGridLayout(props) {
1528
1863
  }
1529
1864
  );
1530
1865
  }
1866
+ var ResponsiveGridLayoutWithRef = React2__default.default.forwardRef(function ResponsiveGridLayoutForwardRef(props, ref) {
1867
+ const { innerRef, ...rest } = props;
1868
+ const effectiveInnerRef = innerRef ?? ref;
1869
+ return /* @__PURE__ */ jsxRuntime.jsx(ResponsiveGridLayoutInner, { ...rest, innerRef: effectiveInnerRef });
1870
+ });
1871
+ ResponsiveGridLayoutWithRef.displayName = "ResponsiveGridLayout";
1531
1872
 
1532
1873
  exports.GridItem = GridItem;
1533
1874
  exports.GridLayout = GridLayout;
1534
- exports.ResponsiveGridLayout = ResponsiveGridLayout;
1875
+ exports.ResponsiveGridLayoutWithRef = ResponsiveGridLayoutWithRef;