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,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,21 +430,26 @@ 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
- e: e.nativeEvent,
448
+ // react-resizable forwards react-draggable's callback event, which is
449
+ // already a native MouseEvent/TouchEvent and has no `nativeEvent`.
450
+ // Reading it unconditionally handed consumers `undefined` (#2264).
451
+ // The drag handlers above pass the raw event for the same reason.
452
+ e: e.nativeEvent ?? e,
373
453
  node,
374
454
  size: updatedSize,
375
455
  handle: resizeHandle2
@@ -390,7 +470,7 @@ function GridItem(props) {
390
470
  const handleResizeStart = React2.useCallback(
391
471
  (e, data) => {
392
472
  setResizing(true);
393
- const pos2 = chunkA5WIFECI_js.calcGridItemPosition(positionParams, x, y, w, h);
473
+ const pos2 = chunkVJJIA3HC_js.calcGridItemPosition(positionParams, x, y, w, h);
394
474
  const typedData = {
395
475
  ...data,
396
476
  handle: data.handle
@@ -401,7 +481,7 @@ function GridItem(props) {
401
481
  );
402
482
  const handleResize = React2.useCallback(
403
483
  (e, data) => {
404
- const pos2 = chunkA5WIFECI_js.calcGridItemPosition(positionParams, x, y, w, h);
484
+ const pos2 = chunkVJJIA3HC_js.calcGridItemPosition(positionParams, x, y, w, h);
405
485
  const typedData = {
406
486
  ...data,
407
487
  handle: data.handle
@@ -414,7 +494,7 @@ function GridItem(props) {
414
494
  (e, data) => {
415
495
  setResizing(false);
416
496
  resizePositionRef.current = { top: 0, left: 0, width: 0, height: 0 };
417
- const pos2 = chunkA5WIFECI_js.calcGridItemPosition(positionParams, x, y, w, h);
497
+ const pos2 = chunkVJJIA3HC_js.calcGridItemPosition(positionParams, x, y, w, h);
418
498
  const typedData = {
419
499
  ...data,
420
500
  handle: data.handle
@@ -465,7 +545,7 @@ function GridItem(props) {
465
545
  }
466
546
  prevDroppingPositionRef.current = droppingPosition;
467
547
  }, [droppingPosition, dragging, i]);
468
- const pos = chunkA5WIFECI_js.calcGridItemPosition(
548
+ const pos = chunkVJJIA3HC_js.calcGridItemPosition(
469
549
  positionParams,
470
550
  x,
471
551
  y,
@@ -475,14 +555,14 @@ function GridItem(props) {
475
555
  resizing ? resizePositionRef.current : null
476
556
  );
477
557
  const child = React2__default.default.Children.only(children);
478
- const colWidth = chunkA5WIFECI_js.calcGridColWidth(positionParams);
558
+ const colWidth = chunkVJJIA3HC_js.calcGridColWidth(positionParams);
479
559
  const minConstraints = [
480
- chunkA5WIFECI_js.calcGridItemWHPx(minW, colWidth, margin[0]),
481
- chunkA5WIFECI_js.calcGridItemWHPx(minH, rowHeight, margin[1])
560
+ chunkVJJIA3HC_js.calcGridItemWHPx(minW, colWidth, margin[0]),
561
+ chunkVJJIA3HC_js.calcGridItemWHPx(minH, rowHeight, margin[1])
482
562
  ];
483
563
  const maxConstraints = [
484
- chunkA5WIFECI_js.calcGridItemWHPx(maxW, colWidth, margin[0]),
485
- chunkA5WIFECI_js.calcGridItemWHPx(maxH, rowHeight, margin[1])
564
+ chunkVJJIA3HC_js.calcGridItemWHPx(maxW, colWidth, margin[0]),
565
+ chunkVJJIA3HC_js.calcGridItemWHPx(maxH, rowHeight, margin[1])
486
566
  ];
487
567
  const childProps = child.props;
488
568
  const childClassName = childProps["className"];
@@ -532,12 +612,104 @@ function GridItem(props) {
532
612
  handle,
533
613
  cancel: ".react-resizable-handle" + (cancel ? "," + cancel : ""),
534
614
  scale: transformScale,
615
+ allowMobileScroll,
535
616
  nodeRef: elementRef,
536
617
  children: newChild
537
618
  }
538
619
  );
539
620
  return newChild;
540
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
+ }
541
713
  var noop = () => {
542
714
  };
543
715
  var layoutClassName = "react-grid-layout";
@@ -566,7 +738,7 @@ function synchronizeLayoutWithChildren(initialLayout, children, cols, compactor)
566
738
  childKeys.add(key);
567
739
  const existingItem = initialLayout.find((l) => l.i === key);
568
740
  if (existingItem) {
569
- layout.push(chunkA5WIFECI_js.cloneLayoutItem(existingItem));
741
+ layout.push(chunkVJJIA3HC_js.cloneLayoutItem(existingItem));
570
742
  } else {
571
743
  const childProps = child.props;
572
744
  const dataGrid = childProps["data-grid"];
@@ -591,14 +763,14 @@ function synchronizeLayoutWithChildren(initialLayout, children, cols, compactor)
591
763
  layout.push({
592
764
  i: key,
593
765
  x: 0,
594
- y: chunkA5WIFECI_js.bottom(layout),
766
+ y: chunkVJJIA3HC_js.bottom(layout),
595
767
  w: 1,
596
768
  h: 1
597
769
  });
598
770
  }
599
771
  }
600
772
  });
601
- const corrected = chunkA5WIFECI_js.correctBounds(layout, { cols });
773
+ const corrected = chunkVJJIA3HC_js.correctBounds(layout, { cols });
602
774
  return compactor.compact(corrected, cols);
603
775
  }
604
776
  function GridLayout(props) {
@@ -611,9 +783,9 @@ function GridLayout(props) {
611
783
  dragConfig: dragConfigProp,
612
784
  resizeConfig: resizeConfigProp,
613
785
  dropConfig: dropConfigProp,
614
- positionStrategy = chunk55DQUWLA_js.defaultPositionStrategy,
786
+ positionStrategy = chunkQAIA5KAO_js.defaultPositionStrategy,
615
787
  compactor: compactorProp,
616
- constraints = chunk55DQUWLA_js.defaultConstraints,
788
+ constraints = chunkQAIA5KAO_js.defaultConstraints,
617
789
  // Layout data
618
790
  layout: propsLayout = [],
619
791
  droppingItem: droppingItemProp,
@@ -634,19 +806,19 @@ function GridLayout(props) {
634
806
  onDropDragOver: onDropDragOverProp = noop
635
807
  } = props;
636
808
  const gridConfig = React2.useMemo(
637
- () => ({ ...chunk55DQUWLA_js.defaultGridConfig, ...gridConfigProp }),
809
+ () => ({ ...chunkQAIA5KAO_js.defaultGridConfig, ...gridConfigProp }),
638
810
  [gridConfigProp]
639
811
  );
640
812
  const dragConfig = React2.useMemo(
641
- () => ({ ...chunk55DQUWLA_js.defaultDragConfig, ...dragConfigProp }),
813
+ () => ({ ...chunkQAIA5KAO_js.defaultDragConfig, ...dragConfigProp }),
642
814
  [dragConfigProp]
643
815
  );
644
816
  const resizeConfig = React2.useMemo(
645
- () => ({ ...chunk55DQUWLA_js.defaultResizeConfig, ...resizeConfigProp }),
817
+ () => ({ ...chunkQAIA5KAO_js.defaultResizeConfig, ...resizeConfigProp }),
646
818
  [resizeConfigProp]
647
819
  );
648
820
  const dropConfig = React2.useMemo(
649
- () => ({ ...chunk55DQUWLA_js.defaultDropConfig, ...dropConfigProp }),
821
+ () => ({ ...chunkQAIA5KAO_js.defaultDropConfig, ...dropConfigProp }),
650
822
  [dropConfigProp]
651
823
  );
652
824
  const { cols, rowHeight, maxRows, margin, containerPadding } = gridConfig;
@@ -655,7 +827,8 @@ function GridLayout(props) {
655
827
  bounded: isBounded,
656
828
  handle: draggableHandle,
657
829
  cancel: draggableCancel,
658
- threshold: dragThreshold
830
+ threshold: dragThreshold,
831
+ allowMobileScroll: dragAllowMobileScroll
659
832
  } = dragConfig;
660
833
  const {
661
834
  enabled: isResizable,
@@ -665,9 +838,11 @@ function GridLayout(props) {
665
838
  const {
666
839
  enabled: isDroppable,
667
840
  defaultItem: defaultDropItem,
668
- onDragOver: dropConfigOnDragOver
841
+ onDragOver: dropConfigOnDragOver,
842
+ touchEnabled = true,
843
+ touchDragSource = "[data-rgl-draggable]"
669
844
  } = dropConfig;
670
- const compactor = compactorProp ?? chunk55DQUWLA_js.getCompactor("vertical");
845
+ const compactor = compactorProp ?? chunkQAIA5KAO_js.getCompactor("vertical");
671
846
  const compactType = compactor.type;
672
847
  const allowOverlap = compactor.allowOverlap;
673
848
  const preventCollision = compactor.preventCollision ?? false;
@@ -691,6 +866,8 @@ function GridLayout(props) {
691
866
  null
692
867
  );
693
868
  const [droppingPosition, setDroppingPosition] = React2.useState();
869
+ const droppingPositionRef = React2.useRef(void 0);
870
+ droppingPositionRef.current = droppingPosition;
694
871
  const oldDragItemRef = React2.useRef(null);
695
872
  const oldResizeItemRef = React2.useRef(null);
696
873
  const oldLayoutRef = React2.useRef(null);
@@ -699,6 +876,15 @@ function GridLayout(props) {
699
876
  const prevPropsLayoutRef = React2.useRef(propsLayout);
700
877
  const prevChildrenRef = React2.useRef(children);
701
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
+ });
702
888
  const layoutRef = React2.useRef(layout);
703
889
  layoutRef.current = layout;
704
890
  React2.useEffect(() => {
@@ -739,22 +925,22 @@ function GridLayout(props) {
739
925
  layout
740
926
  ]);
741
927
  React2.useEffect(() => {
742
- if (!activeDrag && !fastEquals.deepEqual(layout, prevLayoutRef.current)) {
928
+ if (!activeDrag && !droppingDOMNode && !fastEquals.deepEqual(layout, prevLayoutRef.current)) {
743
929
  prevLayoutRef.current = layout;
744
930
  const publicLayout = layout.filter((l) => l.i !== droppingItem.i);
745
931
  onLayoutChange(publicLayout);
746
932
  }
747
- }, [layout, activeDrag, onLayoutChange, droppingItem.i]);
933
+ }, [layout, activeDrag, droppingDOMNode, onLayoutChange, droppingItem.i]);
748
934
  const containerHeight = React2.useMemo(() => {
749
935
  if (!autoSize) return void 0;
750
- const nbRow = chunkA5WIFECI_js.bottom(layout);
936
+ const nbRow = chunkVJJIA3HC_js.bottom(layout);
751
937
  const containerPaddingY = effectiveContainerPadding[1];
752
938
  return nbRow * rowHeight + (nbRow - 1) * margin[1] + containerPaddingY * 2 + "px";
753
939
  }, [autoSize, layout, rowHeight, margin, effectiveContainerPadding]);
754
940
  const onDragStart = React2.useCallback(
755
941
  (i, _x, _y, data) => {
756
942
  const currentLayout = layoutRef.current;
757
- const l = chunkA5WIFECI_js.getLayoutItem(currentLayout, i);
943
+ const l = chunkVJJIA3HC_js.getLayoutItem(currentLayout, i);
758
944
  if (!l) return;
759
945
  const placeholder = {
760
946
  w: l.w,
@@ -763,7 +949,7 @@ function GridLayout(props) {
763
949
  y: l.y,
764
950
  i
765
951
  };
766
- oldDragItemRef.current = chunkA5WIFECI_js.cloneLayoutItem(l);
952
+ oldDragItemRef.current = chunkVJJIA3HC_js.cloneLayoutItem(l);
767
953
  oldLayoutRef.current = currentLayout;
768
954
  setActiveDrag(placeholder);
769
955
  onDragStartProp(currentLayout, l, l, null, data.e, data.node);
@@ -774,7 +960,7 @@ function GridLayout(props) {
774
960
  (i, x, y, data) => {
775
961
  const currentLayout = layoutRef.current;
776
962
  const oldDragItem = oldDragItemRef.current;
777
- const l = chunkA5WIFECI_js.getLayoutItem(currentLayout, i);
963
+ const l = chunkVJJIA3HC_js.getLayoutItem(currentLayout, i);
778
964
  if (!l) return;
779
965
  const placeholder = {
780
966
  w: l.w,
@@ -783,7 +969,7 @@ function GridLayout(props) {
783
969
  y: l.y,
784
970
  i
785
971
  };
786
- const newLayout = chunkA5WIFECI_js.moveElement(
972
+ const newLayout = chunkVJJIA3HC_js.moveElement(
787
973
  currentLayout,
788
974
  l,
789
975
  x,
@@ -802,12 +988,12 @@ function GridLayout(props) {
802
988
  );
803
989
  const onDragStop = React2.useCallback(
804
990
  (i, x, y, data) => {
805
- if (!activeDrag) return;
991
+ if (!oldDragItemRef.current) return;
806
992
  const currentLayout = layoutRef.current;
807
993
  const oldDragItem = oldDragItemRef.current;
808
- const l = chunkA5WIFECI_js.getLayoutItem(currentLayout, i);
994
+ const l = chunkVJJIA3HC_js.getLayoutItem(currentLayout, i);
809
995
  if (!l) return;
810
- const newLayout = chunkA5WIFECI_js.moveElement(
996
+ const newLayout = chunkVJJIA3HC_js.moveElement(
811
997
  currentLayout,
812
998
  l,
813
999
  x,
@@ -830,7 +1016,6 @@ function GridLayout(props) {
830
1016
  }
831
1017
  },
832
1018
  [
833
- activeDrag,
834
1019
  preventCollision,
835
1020
  compactType,
836
1021
  cols,
@@ -843,9 +1028,9 @@ function GridLayout(props) {
843
1028
  const onResizeStart = React2.useCallback(
844
1029
  (i, _w, _h, data) => {
845
1030
  const currentLayout = layoutRef.current;
846
- const l = chunkA5WIFECI_js.getLayoutItem(currentLayout, i);
1031
+ const l = chunkVJJIA3HC_js.getLayoutItem(currentLayout, i);
847
1032
  if (!l) return;
848
- oldResizeItemRef.current = chunkA5WIFECI_js.cloneLayoutItem(l);
1033
+ oldResizeItemRef.current = chunkVJJIA3HC_js.cloneLayoutItem(l);
849
1034
  oldLayoutRef.current = currentLayout;
850
1035
  setResizing(true);
851
1036
  onResizeStartProp(currentLayout, l, l, null, data.e, data.node);
@@ -860,7 +1045,7 @@ function GridLayout(props) {
860
1045
  let shouldMoveItem = false;
861
1046
  let newX;
862
1047
  let newY;
863
- const [newLayout, l] = chunkA5WIFECI_js.withLayoutItem(currentLayout, i, (item) => {
1048
+ const [newLayout, l] = chunkVJJIA3HC_js.withLayoutItem(currentLayout, i, (item) => {
864
1049
  newX = item.x;
865
1050
  newY = item.y;
866
1051
  if (["sw", "w", "nw", "n", "ne"].includes(handle)) {
@@ -877,7 +1062,7 @@ function GridLayout(props) {
877
1062
  shouldMoveItem = true;
878
1063
  }
879
1064
  if (preventCollision && !allowOverlap) {
880
- const collisions = chunkA5WIFECI_js.getAllCollisions(currentLayout, {
1065
+ const collisions = chunkVJJIA3HC_js.getAllCollisions(currentLayout, {
881
1066
  ...item,
882
1067
  w,
883
1068
  h,
@@ -894,12 +1079,15 @@ function GridLayout(props) {
894
1079
  }
895
1080
  item.w = w;
896
1081
  item.h = h;
1082
+ if (handle === "n" || handle === "nw" || handle === "ne") {
1083
+ item.y = newY ?? item.y;
1084
+ }
897
1085
  return item;
898
1086
  });
899
1087
  if (!l) return;
900
1088
  let finalLayout = newLayout;
901
1089
  if (shouldMoveItem && newX !== void 0 && newY !== void 0) {
902
- finalLayout = chunkA5WIFECI_js.moveElement(
1090
+ finalLayout = chunkVJJIA3HC_js.moveElement(
903
1091
  newLayout,
904
1092
  l,
905
1093
  newX,
@@ -927,7 +1115,14 @@ function GridLayout(props) {
927
1115
  data.e,
928
1116
  data.node
929
1117
  );
930
- 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);
931
1126
  setActiveDrag(placeholder);
932
1127
  },
933
1128
  [preventCollision, compactType, cols, allowOverlap, compactor, onResizeProp]
@@ -936,7 +1131,7 @@ function GridLayout(props) {
936
1131
  (i, _w, _h, data) => {
937
1132
  const currentLayout = layoutRef.current;
938
1133
  const oldResizeItem = oldResizeItemRef.current;
939
- const l = chunkA5WIFECI_js.getLayoutItem(currentLayout, i);
1134
+ const l = chunkVJJIA3HC_js.getLayoutItem(currentLayout, i);
940
1135
  const finalLayout = compactor.compact(currentLayout, cols);
941
1136
  onResizeStopProp(
942
1137
  finalLayout,
@@ -958,6 +1153,73 @@ function GridLayout(props) {
958
1153
  },
959
1154
  [cols, compactor, onResizeStopProp, onLayoutChange]
960
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
+ );
961
1223
  const removeDroppingPlaceholder = React2.useCallback(() => {
962
1224
  const currentLayout = layoutRef.current;
963
1225
  const hasDroppingItem = currentLayout.some((l) => l.i === droppingItem.i);
@@ -998,74 +1260,36 @@ function GridLayout(props) {
998
1260
  ...onDragOverResult
999
1261
  } = rawResult ?? {};
1000
1262
  const finalDroppingItem = { ...droppingItem, ...onDragOverResult };
1001
- const gridRect = e.currentTarget.getBoundingClientRect();
1002
- 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,
1003
1272
  cols,
1004
1273
  margin,
1005
1274
  maxRows,
1006
1275
  rowHeight,
1007
- containerWidth: width,
1276
+ width,
1008
1277
  containerPadding: effectiveContainerPadding
1009
- };
1010
- const actualColWidth = chunkA5WIFECI_js.calcGridColWidth(positionParams);
1011
- const itemPixelWidth = chunkA5WIFECI_js.calcGridItemWHPx(
1012
- finalDroppingItem.w,
1013
- actualColWidth,
1014
- margin[0]
1015
- );
1016
- const itemPixelHeight = chunkA5WIFECI_js.calcGridItemWHPx(
1017
- finalDroppingItem.h,
1018
- rowHeight,
1019
- margin[1]
1278
+ });
1279
+ placeDroppingItem(
1280
+ finalDroppingItem,
1281
+ newDroppingPosition,
1282
+ calculatedXY,
1283
+ !!droppingDOMNode
1020
1284
  );
1021
- const itemCenterOffsetX = itemPixelWidth / 2;
1022
- const itemCenterOffsetY = itemPixelHeight / 2;
1023
- const rawGridX = e.clientX - gridRect.left + dragOffsetX - itemCenterOffsetX;
1024
- const rawGridY = e.clientY - gridRect.top + dragOffsetY - itemCenterOffsetY;
1025
- const clampedGridX = Math.max(0, rawGridX);
1026
- const clampedGridY = Math.max(0, rawGridY);
1027
- const newDroppingPosition = {
1028
- left: clampedGridX / transformScale,
1029
- top: clampedGridY / transformScale,
1030
- e: e.nativeEvent
1031
- };
1032
- if (!droppingDOMNode) {
1033
- const calculatedPosition = chunkA5WIFECI_js.calcXY(
1034
- positionParams,
1035
- clampedGridY,
1036
- clampedGridX,
1037
- finalDroppingItem.w,
1038
- finalDroppingItem.h
1039
- );
1040
- setDroppingDOMNode(/* @__PURE__ */ jsxRuntime.jsx("div", {}, finalDroppingItem.i));
1041
- setDroppingPosition(newDroppingPosition);
1042
- const baseLayout = layoutRef.current.filter(
1043
- (l) => l.i !== finalDroppingItem.i
1044
- );
1045
- setLayout([
1046
- ...baseLayout,
1047
- {
1048
- ...finalDroppingItem,
1049
- x: calculatedPosition.x,
1050
- y: calculatedPosition.y,
1051
- static: false,
1052
- isDraggable: true
1053
- }
1054
- ]);
1055
- } else if (droppingPosition) {
1056
- const shouldUpdate = droppingPosition.left !== newDroppingPosition.left || droppingPosition.top !== newDroppingPosition.top;
1057
- if (shouldUpdate) {
1058
- setDroppingPosition(newDroppingPosition);
1059
- }
1060
- }
1061
1285
  },
1062
1286
  [
1063
1287
  droppingDOMNode,
1064
- droppingPosition,
1065
1288
  droppingItem,
1066
1289
  dropConfigOnDragOver,
1067
1290
  onDropDragOverProp,
1068
1291
  removeDroppingPlaceholder,
1292
+ placeDroppingItem,
1069
1293
  transformScale,
1070
1294
  cols,
1071
1295
  margin,
@@ -1094,22 +1318,110 @@ function GridLayout(props) {
1094
1318
  e.stopPropagation();
1095
1319
  dragEnterCounterRef.current++;
1096
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
+ );
1097
1330
  const handleDrop = React2.useCallback(
1098
1331
  (e) => {
1099
1332
  e.preventDefault();
1100
1333
  e.stopPropagation();
1101
- const currentLayout = layoutRef.current;
1102
- const item = currentLayout.find((l) => l.i === droppingItem.i);
1103
1334
  dragEnterCounterRef.current = 0;
1104
- removeDroppingPlaceholder();
1105
- onDropProp(currentLayout, item, e.nativeEvent);
1335
+ commitDrop(e.nativeEvent);
1106
1336
  },
1107
- [droppingItem.i, removeDroppingPlaceholder, onDropProp]
1337
+ [commitDrop]
1108
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
+ ]);
1109
1421
  const processGridItem = React2.useCallback(
1110
1422
  (child, isDroppingItem) => {
1111
1423
  if (!child || !child.key) return null;
1112
- const l = chunkA5WIFECI_js.getLayoutItem(layout, String(child.key));
1424
+ const l = chunkVJJIA3HC_js.getLayoutItem(layout, String(child.key));
1113
1425
  if (!l) return null;
1114
1426
  const draggable = typeof l.isDraggable === "boolean" ? l.isDraggable : !l.static && isDraggable;
1115
1427
  const resizable = typeof l.isResizable === "boolean" ? l.isResizable : !l.static && isResizable;
@@ -1136,6 +1448,7 @@ function GridLayout(props) {
1136
1448
  isDraggable: draggable,
1137
1449
  isResizable: resizable,
1138
1450
  isBounded: bounded,
1451
+ allowMobileScroll: dragAllowMobileScroll,
1139
1452
  useCSSTransforms: useCSSTransforms && mounted,
1140
1453
  usePercentages: !mounted,
1141
1454
  transformScale,
@@ -1220,6 +1533,17 @@ function GridLayout(props) {
1220
1533
  }
1221
1534
  );
1222
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
+ );
1223
1547
  const mergedClassName = clsx__default.default(layoutClassName, className);
1224
1548
  const mergedStyle = {
1225
1549
  height: containerHeight,
@@ -1228,7 +1552,7 @@ function GridLayout(props) {
1228
1552
  return /* @__PURE__ */ jsxRuntime.jsxs(
1229
1553
  "div",
1230
1554
  {
1231
- ref: innerRef,
1555
+ ref: setGridRef,
1232
1556
  className: mergedClassName,
1233
1557
  style: mergedStyle,
1234
1558
  onDrop: isDroppable ? handleDrop : void 0,
@@ -1262,20 +1586,33 @@ var DEFAULT_COLS = {
1262
1586
  };
1263
1587
  var noop2 = () => {
1264
1588
  };
1265
- function synchronizeLayoutWithChildren2(initialLayout, children, cols, compactor) {
1589
+ function synchronizeLayoutWithChildren2(initialLayout, children, cols, compactor, reSeedFromDataGrid = false) {
1266
1590
  const layout = [];
1267
1591
  React2__default.default.Children.forEach(children, (child) => {
1268
1592
  if (!React2__default.default.isValidElement(child) || child.key === null) return;
1269
1593
  const key = String(child.key);
1594
+ const childProps = child.props;
1595
+ const dataGrid = childProps["data-grid"];
1270
1596
  const existingItem = initialLayout.find((l) => l.i === key);
1271
1597
  if (existingItem) {
1272
- layout.push({
1273
- ...existingItem,
1274
- i: key
1275
- });
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
+ }
1276
1615
  } else {
1277
- const childProps = child.props;
1278
- const dataGrid = childProps["data-grid"];
1279
1616
  if (dataGrid) {
1280
1617
  layout.push({
1281
1618
  i: key,
@@ -1297,17 +1634,17 @@ function synchronizeLayoutWithChildren2(initialLayout, children, cols, compactor
1297
1634
  layout.push({
1298
1635
  i: key,
1299
1636
  x: 0,
1300
- y: chunkA5WIFECI_js.bottom(layout),
1637
+ y: chunkVJJIA3HC_js.bottom(layout),
1301
1638
  w: 1,
1302
1639
  h: 1
1303
1640
  });
1304
1641
  }
1305
1642
  }
1306
1643
  });
1307
- const corrected = chunkA5WIFECI_js.correctBounds(layout, { cols });
1644
+ const corrected = chunkVJJIA3HC_js.correctBounds(layout, { cols });
1308
1645
  return compactor.compact(corrected, cols);
1309
1646
  }
1310
- function ResponsiveGridLayout(props) {
1647
+ function ResponsiveGridLayoutInner(props) {
1311
1648
  const {
1312
1649
  children,
1313
1650
  width,
@@ -1325,17 +1662,17 @@ function ResponsiveGridLayout(props) {
1325
1662
  onWidthChange = noop2,
1326
1663
  ...restProps
1327
1664
  } = props;
1328
- const compactor = compactorProp ?? chunk55DQUWLA_js.getCompactor("vertical");
1665
+ const compactor = compactorProp ?? chunkQAIA5KAO_js.getCompactor("vertical");
1329
1666
  const compactType = compactor.type;
1330
1667
  const allowOverlap = compactor.allowOverlap;
1331
1668
  const initialBreakpoint = React2.useMemo(() => {
1332
- return propBreakpoint ?? chunk55DQUWLA_js.getBreakpointFromWidth(breakpoints, width);
1669
+ return propBreakpoint ?? chunkQAIA5KAO_js.getBreakpointFromWidth(breakpoints, width);
1333
1670
  }, []);
1334
1671
  const initialCols = React2.useMemo(() => {
1335
- return chunk55DQUWLA_js.getColsFromBreakpoint(initialBreakpoint, colsConfig);
1672
+ return chunkQAIA5KAO_js.getColsFromBreakpoint(initialBreakpoint, colsConfig);
1336
1673
  }, [initialBreakpoint, colsConfig]);
1337
1674
  const initialLayout = React2.useMemo(() => {
1338
- return chunk55DQUWLA_js.findOrGenerateResponsiveLayout(
1675
+ return chunkQAIA5KAO_js.findOrGenerateResponsiveLayout(
1339
1676
  propsLayouts,
1340
1677
  breakpoints,
1341
1678
  initialBreakpoint,
@@ -1360,7 +1697,7 @@ function ResponsiveGridLayout(props) {
1360
1697
  }, [layouts]);
1361
1698
  const derivedLayout = React2.useMemo(() => {
1362
1699
  if (!fastEquals.deepEqual(propsLayouts, prevLayoutsRef.current)) {
1363
- return chunk55DQUWLA_js.findOrGenerateResponsiveLayout(
1700
+ return chunkQAIA5KAO_js.findOrGenerateResponsiveLayout(
1364
1701
  propsLayouts,
1365
1702
  breakpoints,
1366
1703
  breakpoint,
@@ -1382,7 +1719,7 @@ function ResponsiveGridLayout(props) {
1382
1719
  }, [derivedLayout, propsLayouts]);
1383
1720
  React2.useEffect(() => {
1384
1721
  if (compactType !== prevCompactTypeRef.current) {
1385
- const newLayout = compactor.compact(chunkA5WIFECI_js.cloneLayout(effectiveLayout), cols);
1722
+ const newLayout = compactor.compact(chunkVJJIA3HC_js.cloneLayout(effectiveLayout), cols);
1386
1723
  const newLayouts = {
1387
1724
  ...layoutsRef.current,
1388
1725
  [breakpoint]: newLayout
@@ -1411,15 +1748,15 @@ function ResponsiveGridLayout(props) {
1411
1748
  );
1412
1749
  const colsChanged = !fastEquals.deepEqual(colsConfig, prevColsRef.current);
1413
1750
  if (widthChanged || breakpointPropChanged || breakpointsChanged || colsChanged) {
1414
- const newBreakpoint = propBreakpoint ?? chunk55DQUWLA_js.getBreakpointFromWidth(breakpoints, width);
1415
- const newCols = chunk55DQUWLA_js.getColsFromBreakpoint(newBreakpoint, colsConfig);
1751
+ const newBreakpoint = propBreakpoint ?? chunkQAIA5KAO_js.getBreakpointFromWidth(breakpoints, width);
1752
+ const newCols = chunkQAIA5KAO_js.getColsFromBreakpoint(newBreakpoint, colsConfig);
1416
1753
  const lastBreakpoint = breakpoint;
1417
1754
  if (lastBreakpoint !== newBreakpoint || breakpointsChanged || colsChanged) {
1418
1755
  const newLayouts = { ...layoutsRef.current };
1419
1756
  if (!newLayouts[lastBreakpoint]) {
1420
- newLayouts[lastBreakpoint] = chunkA5WIFECI_js.cloneLayout(layout);
1757
+ newLayouts[lastBreakpoint] = chunkVJJIA3HC_js.cloneLayout(layout);
1421
1758
  }
1422
- let newLayout = chunk55DQUWLA_js.findOrGenerateResponsiveLayout(
1759
+ let newLayout = chunkQAIA5KAO_js.findOrGenerateResponsiveLayout(
1423
1760
  newLayouts,
1424
1761
  breakpoints,
1425
1762
  newBreakpoint,
@@ -1427,11 +1764,13 @@ function ResponsiveGridLayout(props) {
1427
1764
  newCols,
1428
1765
  compactor
1429
1766
  );
1767
+ const layoutWasGenerated = !newLayouts[newBreakpoint];
1430
1768
  newLayout = synchronizeLayoutWithChildren2(
1431
1769
  newLayout,
1432
1770
  children,
1433
1771
  newCols,
1434
- compactor
1772
+ compactor,
1773
+ layoutWasGenerated
1435
1774
  );
1436
1775
  newLayouts[newBreakpoint] = newLayout;
1437
1776
  setBreakpoint(newBreakpoint);
@@ -1442,11 +1781,11 @@ function ResponsiveGridLayout(props) {
1442
1781
  onBreakpointChange(newBreakpoint, newCols);
1443
1782
  onLayoutChange(newLayout, newLayouts);
1444
1783
  }
1445
- const currentMargin2 = chunk55DQUWLA_js.getIndentationValue(
1784
+ const currentMargin2 = chunkQAIA5KAO_js.getIndentationValue(
1446
1785
  propMargin,
1447
1786
  newBreakpoint
1448
1787
  );
1449
- const currentPadding = propContainerPadding ? chunk55DQUWLA_js.getIndentationValue(
1788
+ const currentPadding = propContainerPadding ? chunkQAIA5KAO_js.getIndentationValue(
1450
1789
  propContainerPadding,
1451
1790
  newBreakpoint
1452
1791
  ) : null;
@@ -1489,14 +1828,14 @@ function ResponsiveGridLayout(props) {
1489
1828
  [breakpoint, onLayoutChange]
1490
1829
  );
1491
1830
  const currentMargin = React2.useMemo(() => {
1492
- return chunk55DQUWLA_js.getIndentationValue(
1831
+ return chunkQAIA5KAO_js.getIndentationValue(
1493
1832
  propMargin,
1494
1833
  breakpoint
1495
1834
  );
1496
1835
  }, [propMargin, breakpoint]);
1497
1836
  const currentContainerPadding = React2.useMemo(() => {
1498
1837
  if (propContainerPadding === null) return null;
1499
- return chunk55DQUWLA_js.getIndentationValue(
1838
+ return chunkQAIA5KAO_js.getIndentationValue(
1500
1839
  propContainerPadding,
1501
1840
  breakpoint
1502
1841
  );
@@ -1524,7 +1863,13 @@ function ResponsiveGridLayout(props) {
1524
1863
  }
1525
1864
  );
1526
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";
1527
1872
 
1528
1873
  exports.GridItem = GridItem;
1529
1874
  exports.GridLayout = GridLayout;
1530
- exports.ResponsiveGridLayout = ResponsiveGridLayout;
1875
+ exports.ResponsiveGridLayoutWithRef = ResponsiveGridLayoutWithRef;