react-grid-layout 2.0.0 → 2.1.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 (70) hide show
  1. package/README.md +97 -25
  2. package/css/styles.css +0 -1
  3. package/dist/{ResponsiveGridLayout-D6lFRE3f.d.mts → ResponsiveGridLayout-BkHF9YHa.d.mts} +10 -1
  4. package/dist/{ResponsiveGridLayout-CH4s0tKj.d.ts → ResponsiveGridLayout-CLn16-X3.d.ts} +10 -1
  5. package/dist/{calculate-CwYDW8na.d.mts → calculate-DsVTldEE.d.ts} +30 -2
  6. package/dist/{calculate-mgLpNJ5O.d.ts → calculate-DwbL1D06.d.mts} +30 -2
  7. package/dist/{chunk-4HNUMWQK.mjs → chunk-2O3ZME4Q.mjs} +178 -297
  8. package/dist/chunk-2O3ZME4Q.mjs.map +1 -0
  9. package/dist/chunk-526JND3R.mjs +3 -0
  10. package/dist/{chunk-ZWN22PS2.mjs.map → chunk-526JND3R.mjs.map} +1 -1
  11. package/dist/chunk-7ELO5FRW.js +4 -0
  12. package/dist/{chunk-PBQSHIID.js.map → chunk-7ELO5FRW.js.map} +1 -1
  13. package/dist/chunk-AWM66AWF.mjs +422 -0
  14. package/dist/chunk-AWM66AWF.mjs.map +1 -0
  15. package/dist/chunk-BJFPTW5Q.js +449 -0
  16. package/dist/chunk-BJFPTW5Q.js.map +1 -0
  17. package/dist/{chunk-3WO4SAYB.js → chunk-FN6MIZ24.js} +221 -345
  18. package/dist/chunk-FN6MIZ24.js.map +1 -0
  19. package/dist/{chunk-H5KMDLY3.js → chunk-GPZBANOK.js} +40 -39
  20. package/dist/chunk-GPZBANOK.js.map +1 -0
  21. package/dist/{chunk-ZCXE6SR5.mjs → chunk-LWF5EYMO.mjs} +4 -3
  22. package/dist/chunk-LWF5EYMO.mjs.map +1 -0
  23. package/dist/{chunk-R35HZZTA.mjs → chunk-MXXN7GUE.mjs} +170 -62
  24. package/dist/chunk-MXXN7GUE.mjs.map +1 -0
  25. package/dist/{chunk-BFTKGAP3.js → chunk-QRW3ND4U.js} +230 -122
  26. package/dist/chunk-QRW3ND4U.js.map +1 -0
  27. package/dist/core.d.mts +159 -6
  28. package/dist/core.d.ts +159 -6
  29. package/dist/core.js +141 -85
  30. package/dist/core.mjs +3 -3
  31. package/dist/extras.d.mts +133 -3
  32. package/dist/extras.d.ts +133 -3
  33. package/dist/extras.js +373 -2
  34. package/dist/extras.js.map +1 -1
  35. package/dist/extras.mjs +367 -2
  36. package/dist/extras.mjs.map +1 -1
  37. package/dist/index.d.mts +5 -5
  38. package/dist/index.d.ts +5 -5
  39. package/dist/index.js +64 -64
  40. package/dist/index.mjs +5 -5
  41. package/dist/legacy.d.mts +2 -2
  42. package/dist/legacy.d.ts +2 -2
  43. package/dist/legacy.js +26 -25
  44. package/dist/legacy.js.map +1 -1
  45. package/dist/legacy.mjs +16 -15
  46. package/dist/legacy.mjs.map +1 -1
  47. package/dist/{position-Dk2b4ZMS.d.ts → position-C8a5g6bb.d.mts} +11 -6
  48. package/dist/{position-BmN1z36J.d.mts → position-H8tBL91b.d.ts} +11 -6
  49. package/dist/react.d.mts +11 -5
  50. package/dist/react.d.ts +11 -5
  51. package/dist/react.js +38 -38
  52. package/dist/react.mjs +5 -5
  53. package/dist/{responsive-CJxefsYw.d.mts → responsive-BB5d98xz.d.mts} +1 -1
  54. package/dist/{responsive-C4L1ESlm.d.ts → responsive-BXI-GCXG.d.ts} +1 -1
  55. package/dist/{types-Cxf4nHNr.d.mts → types-CokovIMH.d.mts} +98 -4
  56. package/dist/{types-Cxf4nHNr.d.ts → types-CokovIMH.d.ts} +98 -4
  57. package/index-dev.js +16 -0
  58. package/package.json +2 -1
  59. package/dist/chunk-2KUHNJXF.mjs +0 -90
  60. package/dist/chunk-2KUHNJXF.mjs.map +0 -1
  61. package/dist/chunk-3WO4SAYB.js.map +0 -1
  62. package/dist/chunk-4HNUMWQK.mjs.map +0 -1
  63. package/dist/chunk-BFTKGAP3.js.map +0 -1
  64. package/dist/chunk-F6NQPYKT.js +0 -98
  65. package/dist/chunk-F6NQPYKT.js.map +0 -1
  66. package/dist/chunk-H5KMDLY3.js.map +0 -1
  67. package/dist/chunk-PBQSHIID.js +0 -4
  68. package/dist/chunk-R35HZZTA.mjs.map +0 -1
  69. package/dist/chunk-ZCXE6SR5.mjs.map +0 -1
  70. package/dist/chunk-ZWN22PS2.mjs +0 -3
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunk3WO4SAYB_js = require('./chunk-3WO4SAYB.js');
4
- var chunkF6NQPYKT_js = require('./chunk-F6NQPYKT.js');
3
+ var chunkFN6MIZ24_js = require('./chunk-FN6MIZ24.js');
4
+ var chunkBJFPTW5Q_js = require('./chunk-BJFPTW5Q.js');
5
5
  var React2 = require('react');
6
6
  var reactDraggable = require('react-draggable');
7
7
  var reactResizable = require('react-resizable');
@@ -46,6 +46,9 @@ function GridItem(props) {
46
46
  i,
47
47
  resizeHandles,
48
48
  resizeHandle,
49
+ constraints = chunkFN6MIZ24_js.defaultConstraints,
50
+ layoutItem,
51
+ layout = [],
49
52
  onDragStart: onDragStartProp,
50
53
  onDrag: onDragProp,
51
54
  onDragStop: onDragStopProp,
@@ -77,17 +80,44 @@ function GridItem(props) {
77
80
  }),
78
81
  [cols, containerPadding, containerWidth, margin, maxRows, rowHeight]
79
82
  );
83
+ const constraintContext = React2.useMemo(
84
+ () => ({
85
+ cols,
86
+ maxRows,
87
+ containerWidth,
88
+ containerHeight: 0,
89
+ // Auto-height grids don't have a fixed container height
90
+ rowHeight,
91
+ margin,
92
+ layout
93
+ }),
94
+ [cols, maxRows, containerWidth, rowHeight, margin, layout]
95
+ );
96
+ const effectiveLayoutItem = React2.useMemo(
97
+ () => layoutItem ?? {
98
+ i,
99
+ x,
100
+ y,
101
+ w,
102
+ h,
103
+ minW,
104
+ maxW,
105
+ minH,
106
+ maxH
107
+ },
108
+ [layoutItem, i, x, y, w, h, minW, maxW, minH, maxH]
109
+ );
80
110
  const createStyle = React2.useCallback(
81
111
  (pos2) => {
82
112
  if (useCSSTransforms) {
83
- return chunk3WO4SAYB_js.setTransform(pos2);
113
+ return chunkFN6MIZ24_js.setTransform(pos2);
84
114
  }
85
- const styleObj = chunk3WO4SAYB_js.setTopLeft(pos2);
115
+ const styleObj = chunkFN6MIZ24_js.setTopLeft(pos2);
86
116
  if (usePercentages) {
87
117
  return {
88
118
  ...styleObj,
89
- left: chunk3WO4SAYB_js.perc(pos2.left / containerWidth),
90
- width: chunk3WO4SAYB_js.perc(pos2.width / containerWidth)
119
+ left: chunkFN6MIZ24_js.perc(pos2.left / containerWidth),
120
+ width: chunkFN6MIZ24_js.perc(pos2.width / containerWidth)
91
121
  };
92
122
  }
93
123
  return styleObj;
@@ -111,12 +141,17 @@ function GridItem(props) {
111
141
  };
112
142
  dragPositionRef.current = newPosition;
113
143
  setDragging(true);
114
- const { x: newX, y: newY } = chunkF6NQPYKT_js.calcXY(
144
+ const rawPos = chunkBJFPTW5Q_js.calcXYRaw(
115
145
  positionParams,
116
146
  newPosition.top,
117
- newPosition.left,
118
- w,
119
- h
147
+ newPosition.left
148
+ );
149
+ const { x: newX, y: newY } = chunkFN6MIZ24_js.applyPositionConstraints(
150
+ constraints,
151
+ effectiveLayoutItem,
152
+ rawPos.x,
153
+ rawPos.y,
154
+ constraintContext
120
155
  );
121
156
  onDragStartProp(i, newX, newY, {
122
157
  e,
@@ -124,7 +159,15 @@ function GridItem(props) {
124
159
  newPosition
125
160
  });
126
161
  },
127
- [onDragStartProp, transformScale, positionParams, w, h, i]
162
+ [
163
+ onDragStartProp,
164
+ transformScale,
165
+ positionParams,
166
+ constraints,
167
+ effectiveLayoutItem,
168
+ constraintContext,
169
+ i
170
+ ]
128
171
  );
129
172
  const onDrag = React2.useCallback(
130
173
  (e, { node, deltaX, deltaY }) => {
@@ -134,16 +177,23 @@ function GridItem(props) {
134
177
  if (isBounded) {
135
178
  const { offsetParent } = node;
136
179
  if (offsetParent) {
137
- const bottomBoundary = offsetParent.clientHeight - chunkF6NQPYKT_js.calcGridItemWHPx(h, rowHeight, margin[1]);
138
- top = chunkF6NQPYKT_js.clamp(top, 0, bottomBoundary);
139
- const colWidth = chunkF6NQPYKT_js.calcGridColWidth(positionParams);
140
- const rightBoundary = containerWidth - chunkF6NQPYKT_js.calcGridItemWHPx(w, colWidth, margin[0]);
141
- left = chunkF6NQPYKT_js.clamp(left, 0, rightBoundary);
180
+ const bottomBoundary = offsetParent.clientHeight - chunkBJFPTW5Q_js.calcGridItemWHPx(h, rowHeight, margin[1]);
181
+ top = chunkBJFPTW5Q_js.clamp(top, 0, bottomBoundary);
182
+ const colWidth = chunkBJFPTW5Q_js.calcGridColWidth(positionParams);
183
+ const rightBoundary = containerWidth - chunkBJFPTW5Q_js.calcGridItemWHPx(w, colWidth, margin[0]);
184
+ left = chunkBJFPTW5Q_js.clamp(left, 0, rightBoundary);
142
185
  }
143
186
  }
144
187
  const newPosition = { top, left };
145
188
  dragPositionRef.current = newPosition;
146
- const { x: newX, y: newY } = chunkF6NQPYKT_js.calcXY(positionParams, top, left, w, h);
189
+ const rawPos = chunkBJFPTW5Q_js.calcXYRaw(positionParams, top, left);
190
+ const { x: newX, y: newY } = chunkFN6MIZ24_js.applyPositionConstraints(
191
+ constraints,
192
+ effectiveLayoutItem,
193
+ rawPos.x,
194
+ rawPos.y,
195
+ constraintContext
196
+ );
147
197
  onDragProp(i, newX, newY, {
148
198
  e,
149
199
  node,
@@ -160,7 +210,10 @@ function GridItem(props) {
160
210
  positionParams,
161
211
  containerWidth,
162
212
  w,
163
- i
213
+ i,
214
+ constraints,
215
+ effectiveLayoutItem,
216
+ constraintContext
164
217
  ]
165
218
  );
166
219
  const onDragStop = React2.useCallback(
@@ -170,14 +223,29 @@ function GridItem(props) {
170
223
  const newPosition = { top, left };
171
224
  setDragging(false);
172
225
  dragPositionRef.current = { left: 0, top: 0 };
173
- const { x: newX, y: newY } = chunkF6NQPYKT_js.calcXY(positionParams, top, left, w, h);
226
+ const rawPos = chunkBJFPTW5Q_js.calcXYRaw(positionParams, top, left);
227
+ const { x: newX, y: newY } = chunkFN6MIZ24_js.applyPositionConstraints(
228
+ constraints,
229
+ effectiveLayoutItem,
230
+ rawPos.x,
231
+ rawPos.y,
232
+ constraintContext
233
+ );
174
234
  onDragStopProp(i, newX, newY, {
175
235
  e,
176
236
  node,
177
237
  newPosition
178
238
  });
179
239
  },
180
- [onDragStopProp, dragging, positionParams, w, h, i]
240
+ [
241
+ onDragStopProp,
242
+ dragging,
243
+ positionParams,
244
+ constraints,
245
+ effectiveLayoutItem,
246
+ constraintContext,
247
+ i
248
+ ]
181
249
  );
182
250
  const onResizeHandler = React2.useCallback(
183
251
  (e, { node, size, handle: resizeHandle2 }, position, handlerName) => {
@@ -185,7 +253,7 @@ function GridItem(props) {
185
253
  if (!handler) return;
186
254
  let updatedSize;
187
255
  if (node) {
188
- updatedSize = chunk3WO4SAYB_js.resizeItemInDirection(
256
+ updatedSize = chunkFN6MIZ24_js.resizeItemInDirection(
189
257
  resizeHandle2,
190
258
  position,
191
259
  size,
@@ -199,16 +267,19 @@ function GridItem(props) {
199
267
  };
200
268
  }
201
269
  resizePositionRef.current = updatedSize;
202
- let { w: newW, h: newH } = chunkF6NQPYKT_js.calcWH(
270
+ const rawSize = chunkBJFPTW5Q_js.calcWHRaw(
203
271
  positionParams,
204
272
  updatedSize.width,
205
- updatedSize.height,
206
- x,
207
- y,
208
- resizeHandle2
273
+ updatedSize.height
274
+ );
275
+ const { w: newW, h: newH } = chunkFN6MIZ24_js.applySizeConstraints(
276
+ constraints,
277
+ effectiveLayoutItem,
278
+ rawSize.w,
279
+ rawSize.h,
280
+ resizeHandle2,
281
+ constraintContext
209
282
  );
210
- newW = chunkF6NQPYKT_js.clamp(newW, Math.max(minW, 1), maxW);
211
- newH = chunkF6NQPYKT_js.clamp(newH, minH, maxH);
212
283
  handler(i, newW, newH, {
213
284
  e: e.nativeEvent,
214
285
  node,
@@ -224,17 +295,16 @@ function GridItem(props) {
224
295
  positionParams,
225
296
  x,
226
297
  y,
227
- minW,
228
- maxW,
229
- minH,
230
- maxH,
231
- i
298
+ i,
299
+ constraints,
300
+ effectiveLayoutItem,
301
+ constraintContext
232
302
  ]
233
303
  );
234
304
  const handleResizeStart = React2.useCallback(
235
305
  (e, data) => {
236
306
  setResizing(true);
237
- const pos2 = chunkF6NQPYKT_js.calcGridItemPosition(positionParams, x, y, w, h);
307
+ const pos2 = chunkBJFPTW5Q_js.calcGridItemPosition(positionParams, x, y, w, h);
238
308
  const typedData = {
239
309
  ...data,
240
310
  handle: data.handle
@@ -245,7 +315,7 @@ function GridItem(props) {
245
315
  );
246
316
  const handleResize = React2.useCallback(
247
317
  (e, data) => {
248
- const pos2 = chunkF6NQPYKT_js.calcGridItemPosition(positionParams, x, y, w, h);
318
+ const pos2 = chunkBJFPTW5Q_js.calcGridItemPosition(positionParams, x, y, w, h);
249
319
  const typedData = {
250
320
  ...data,
251
321
  handle: data.handle
@@ -258,7 +328,7 @@ function GridItem(props) {
258
328
  (e, data) => {
259
329
  setResizing(false);
260
330
  resizePositionRef.current = { top: 0, left: 0, width: 0, height: 0 };
261
- const pos2 = chunkF6NQPYKT_js.calcGridItemPosition(positionParams, x, y, w, h);
331
+ const pos2 = chunkBJFPTW5Q_js.calcGridItemPosition(positionParams, x, y, w, h);
262
332
  const typedData = {
263
333
  ...data,
264
334
  handle: data.handle
@@ -303,7 +373,7 @@ function GridItem(props) {
303
373
  }
304
374
  prevDroppingPositionRef.current = droppingPosition;
305
375
  }, [droppingPosition, dragging, onDragStart, onDrag]);
306
- const pos = chunkF6NQPYKT_js.calcGridItemPosition(
376
+ const pos = chunkBJFPTW5Q_js.calcGridItemPosition(
307
377
  positionParams,
308
378
  x,
309
379
  y,
@@ -313,14 +383,12 @@ function GridItem(props) {
313
383
  resizing ? resizePositionRef.current : null
314
384
  );
315
385
  const child = React2__default.default.Children.only(children);
316
- const maxWidth = chunkF6NQPYKT_js.calcGridItemPosition(positionParams, 0, 0, cols, 0).width;
317
- const mins = chunkF6NQPYKT_js.calcGridItemPosition(positionParams, 0, 0, minW, minH);
318
- const maxes = chunkF6NQPYKT_js.calcGridItemPosition(positionParams, 0, 0, maxW, maxH);
319
- const minConstraints = [mins.width, mins.height];
320
- const maxConstraints = [
321
- Math.min(maxes.width, maxWidth),
322
- Math.min(maxes.height, Infinity)
386
+ const minGridUnit = chunkBJFPTW5Q_js.calcGridItemPosition(positionParams, 0, 0, 1, 1);
387
+ const minConstraints = [
388
+ minGridUnit.width,
389
+ minGridUnit.height
323
390
  ];
391
+ const maxConstraints = [Infinity, Infinity];
324
392
  const childProps = child.props;
325
393
  const childClassName = childProps["className"];
326
394
  const childStyle = childProps["style"];
@@ -403,7 +471,7 @@ function synchronizeLayoutWithChildren(initialLayout, children, cols, compactTyp
403
471
  childKeys.add(key);
404
472
  const existingItem = initialLayout.find((l) => l.i === key);
405
473
  if (existingItem) {
406
- layout.push(chunk3WO4SAYB_js.cloneLayoutItem(existingItem));
474
+ layout.push(chunkBJFPTW5Q_js.cloneLayoutItem(existingItem));
407
475
  } else {
408
476
  const childProps = child.props;
409
477
  const dataGrid = childProps["data-grid"];
@@ -428,15 +496,15 @@ function synchronizeLayoutWithChildren(initialLayout, children, cols, compactTyp
428
496
  layout.push({
429
497
  i: key,
430
498
  x: 0,
431
- y: chunk3WO4SAYB_js.bottom(layout),
499
+ y: chunkBJFPTW5Q_js.bottom(layout),
432
500
  w: 1,
433
501
  h: 1
434
502
  });
435
503
  }
436
504
  }
437
505
  });
438
- const corrected = chunk3WO4SAYB_js.correctBounds(layout, { cols });
439
- return chunk3WO4SAYB_js.compact(corrected, compactType, cols, allowOverlap);
506
+ const corrected = chunkBJFPTW5Q_js.correctBounds(layout, { cols });
507
+ return chunkFN6MIZ24_js.compact(corrected, compactType, cols, allowOverlap);
440
508
  }
441
509
  function GridLayout(props) {
442
510
  const {
@@ -448,8 +516,9 @@ function GridLayout(props) {
448
516
  dragConfig: dragConfigProp,
449
517
  resizeConfig: resizeConfigProp,
450
518
  dropConfig: dropConfigProp,
451
- positionStrategy = chunk3WO4SAYB_js.defaultPositionStrategy,
519
+ positionStrategy = chunkFN6MIZ24_js.defaultPositionStrategy,
452
520
  compactor: compactorProp,
521
+ constraints = chunkFN6MIZ24_js.defaultConstraints,
453
522
  // Layout data
454
523
  layout: propsLayout = [],
455
524
  droppingItem: droppingItemProp,
@@ -470,19 +539,19 @@ function GridLayout(props) {
470
539
  onDropDragOver: onDropDragOverProp = noop
471
540
  } = props;
472
541
  const gridConfig = React2.useMemo(
473
- () => ({ ...chunk3WO4SAYB_js.defaultGridConfig, ...gridConfigProp }),
542
+ () => ({ ...chunkFN6MIZ24_js.defaultGridConfig, ...gridConfigProp }),
474
543
  [gridConfigProp]
475
544
  );
476
545
  const dragConfig = React2.useMemo(
477
- () => ({ ...chunk3WO4SAYB_js.defaultDragConfig, ...dragConfigProp }),
546
+ () => ({ ...chunkFN6MIZ24_js.defaultDragConfig, ...dragConfigProp }),
478
547
  [dragConfigProp]
479
548
  );
480
549
  const resizeConfig = React2.useMemo(
481
- () => ({ ...chunk3WO4SAYB_js.defaultResizeConfig, ...resizeConfigProp }),
550
+ () => ({ ...chunkFN6MIZ24_js.defaultResizeConfig, ...resizeConfigProp }),
482
551
  [resizeConfigProp]
483
552
  );
484
553
  const dropConfig = React2.useMemo(
485
- () => ({ ...chunk3WO4SAYB_js.defaultDropConfig, ...dropConfigProp }),
554
+ () => ({ ...chunkFN6MIZ24_js.defaultDropConfig, ...dropConfigProp }),
486
555
  [dropConfigProp]
487
556
  );
488
557
  const { cols, rowHeight, maxRows, margin, containerPadding } = gridConfig;
@@ -498,7 +567,7 @@ function GridLayout(props) {
498
567
  handleComponent: resizeHandle
499
568
  } = resizeConfig;
500
569
  const { enabled: isDroppable, defaultItem: defaultDropItem } = dropConfig;
501
- const compactor = compactorProp ?? chunk3WO4SAYB_js.getCompactor("vertical");
570
+ const compactor = compactorProp ?? chunkFN6MIZ24_js.getCompactor("vertical");
502
571
  const compactType = compactor.type;
503
572
  const allowOverlap = compactor.allowOverlap;
504
573
  const preventCollision = compactor.preventCollision ?? false;
@@ -578,13 +647,13 @@ function GridLayout(props) {
578
647
  }, [layout, activeDrag, onLayoutChange]);
579
648
  const containerHeight = React2.useMemo(() => {
580
649
  if (!autoSize) return void 0;
581
- const nbRow = chunk3WO4SAYB_js.bottom(layout);
650
+ const nbRow = chunkBJFPTW5Q_js.bottom(layout);
582
651
  const containerPaddingY = effectiveContainerPadding[1];
583
652
  return nbRow * rowHeight + (nbRow - 1) * margin[1] + containerPaddingY * 2 + "px";
584
653
  }, [autoSize, layout, rowHeight, margin, effectiveContainerPadding]);
585
654
  const onDragStart = React2.useCallback(
586
655
  (i, _x, _y, data) => {
587
- const l = chunk3WO4SAYB_js.getLayoutItem(layout, i);
656
+ const l = chunkBJFPTW5Q_js.getLayoutItem(layout, i);
588
657
  if (!l) return;
589
658
  const placeholder = {
590
659
  w: l.w,
@@ -593,7 +662,7 @@ function GridLayout(props) {
593
662
  y: l.y,
594
663
  i
595
664
  };
596
- oldDragItemRef.current = chunk3WO4SAYB_js.cloneLayoutItem(l);
665
+ oldDragItemRef.current = chunkBJFPTW5Q_js.cloneLayoutItem(l);
597
666
  oldLayoutRef.current = layout;
598
667
  setActiveDrag(placeholder);
599
668
  onDragStartProp(layout, l, l, null, data.e, data.node);
@@ -603,7 +672,7 @@ function GridLayout(props) {
603
672
  const onDrag = React2.useCallback(
604
673
  (i, x, y, data) => {
605
674
  const oldDragItem = oldDragItemRef.current;
606
- const l = chunk3WO4SAYB_js.getLayoutItem(layout, i);
675
+ const l = chunkBJFPTW5Q_js.getLayoutItem(layout, i);
607
676
  if (!l) return;
608
677
  const placeholder = {
609
678
  w: l.w,
@@ -612,7 +681,7 @@ function GridLayout(props) {
612
681
  y: l.y,
613
682
  i
614
683
  };
615
- const newLayout = chunk3WO4SAYB_js.moveElement(
684
+ const newLayout = chunkBJFPTW5Q_js.moveElement(
616
685
  layout,
617
686
  l,
618
687
  x,
@@ -625,7 +694,7 @@ function GridLayout(props) {
625
694
  );
626
695
  onDragProp(newLayout, oldDragItem, l, placeholder, data.e, data.node);
627
696
  setLayout(
628
- allowOverlap ? newLayout : chunk3WO4SAYB_js.compact(newLayout, compactType, cols)
697
+ allowOverlap ? newLayout : chunkFN6MIZ24_js.compact(newLayout, compactType, cols)
629
698
  );
630
699
  setActiveDrag(placeholder);
631
700
  },
@@ -635,9 +704,9 @@ function GridLayout(props) {
635
704
  (i, x, y, data) => {
636
705
  if (!activeDrag) return;
637
706
  const oldDragItem = oldDragItemRef.current;
638
- const l = chunk3WO4SAYB_js.getLayoutItem(layout, i);
707
+ const l = chunkBJFPTW5Q_js.getLayoutItem(layout, i);
639
708
  if (!l) return;
640
- const newLayout = chunk3WO4SAYB_js.moveElement(
709
+ const newLayout = chunkBJFPTW5Q_js.moveElement(
641
710
  layout,
642
711
  l,
643
712
  x,
@@ -648,7 +717,7 @@ function GridLayout(props) {
648
717
  cols,
649
718
  allowOverlap
650
719
  );
651
- const finalLayout = allowOverlap ? newLayout : chunk3WO4SAYB_js.compact(newLayout, compactType, cols);
720
+ const finalLayout = allowOverlap ? newLayout : chunkFN6MIZ24_js.compact(newLayout, compactType, cols);
652
721
  onDragStopProp(finalLayout, oldDragItem, l, null, data.e, data.node);
653
722
  const oldLayout = oldLayoutRef.current;
654
723
  oldDragItemRef.current = null;
@@ -672,9 +741,9 @@ function GridLayout(props) {
672
741
  );
673
742
  const onResizeStart = React2.useCallback(
674
743
  (i, _w, _h, data) => {
675
- const l = chunk3WO4SAYB_js.getLayoutItem(layout, i);
744
+ const l = chunkBJFPTW5Q_js.getLayoutItem(layout, i);
676
745
  if (!l) return;
677
- oldResizeItemRef.current = chunk3WO4SAYB_js.cloneLayoutItem(l);
746
+ oldResizeItemRef.current = chunkBJFPTW5Q_js.cloneLayoutItem(l);
678
747
  oldLayoutRef.current = layout;
679
748
  setResizing(true);
680
749
  onResizeStartProp(layout, l, l, null, data.e, data.node);
@@ -688,7 +757,7 @@ function GridLayout(props) {
688
757
  let shouldMoveItem = false;
689
758
  let newX;
690
759
  let newY;
691
- const [newLayout, l] = chunk3WO4SAYB_js.withLayoutItem(layout, i, (item) => {
760
+ const [newLayout, l] = chunkBJFPTW5Q_js.withLayoutItem(layout, i, (item) => {
692
761
  newX = item.x;
693
762
  newY = item.y;
694
763
  if (["sw", "w", "nw", "n", "ne"].includes(handle)) {
@@ -705,7 +774,7 @@ function GridLayout(props) {
705
774
  shouldMoveItem = true;
706
775
  }
707
776
  if (preventCollision && !allowOverlap) {
708
- const collisions = chunk3WO4SAYB_js.getAllCollisions(layout, {
777
+ const collisions = chunkBJFPTW5Q_js.getAllCollisions(layout, {
709
778
  ...item,
710
779
  w,
711
780
  h,
@@ -727,7 +796,7 @@ function GridLayout(props) {
727
796
  if (!l) return;
728
797
  let finalLayout = newLayout;
729
798
  if (shouldMoveItem && newX !== void 0 && newY !== void 0) {
730
- finalLayout = chunk3WO4SAYB_js.moveElement(
799
+ finalLayout = chunkBJFPTW5Q_js.moveElement(
731
800
  newLayout,
732
801
  l,
733
802
  newX,
@@ -756,7 +825,7 @@ function GridLayout(props) {
756
825
  data.node
757
826
  );
758
827
  setLayout(
759
- allowOverlap ? finalLayout : chunk3WO4SAYB_js.compact(finalLayout, compactType, cols)
828
+ allowOverlap ? finalLayout : chunkFN6MIZ24_js.compact(finalLayout, compactType, cols)
760
829
  );
761
830
  setActiveDrag(placeholder);
762
831
  },
@@ -765,8 +834,8 @@ function GridLayout(props) {
765
834
  const onResizeStop = React2.useCallback(
766
835
  (i, _w, _h, data) => {
767
836
  const oldResizeItem = oldResizeItemRef.current;
768
- const l = chunk3WO4SAYB_js.getLayoutItem(layout, i);
769
- const finalLayout = allowOverlap ? layout : chunk3WO4SAYB_js.compact(layout, compactType, cols);
837
+ const l = chunkBJFPTW5Q_js.getLayoutItem(layout, i);
838
+ const finalLayout = allowOverlap ? layout : chunkFN6MIZ24_js.compact(layout, compactType, cols);
770
839
  onResizeStopProp(
771
840
  finalLayout,
772
841
  oldResizeItem,
@@ -788,7 +857,7 @@ function GridLayout(props) {
788
857
  [layout, allowOverlap, compactType, cols, onResizeStopProp, onLayoutChange]
789
858
  );
790
859
  const removeDroppingPlaceholder = React2.useCallback(() => {
791
- const newLayout = chunk3WO4SAYB_js.compact(
860
+ const newLayout = chunkFN6MIZ24_js.compact(
792
861
  layout.filter((l) => l.i !== droppingItem.i),
793
862
  compactType,
794
863
  cols,
@@ -808,35 +877,55 @@ function GridLayout(props) {
808
877
  )) {
809
878
  return false;
810
879
  }
811
- const onDragOverResult = onDropDragOverProp(e);
812
- if (onDragOverResult === false) {
880
+ const rawResult = onDropDragOverProp(e);
881
+ if (rawResult === false) {
813
882
  if (droppingDOMNode) {
814
883
  removeDroppingPlaceholder();
815
884
  }
816
885
  return false;
817
886
  }
887
+ const {
888
+ dragOffsetX = 0,
889
+ dragOffsetY = 0,
890
+ ...onDragOverResult
891
+ } = rawResult ?? {};
818
892
  const finalDroppingItem = { ...droppingItem, ...onDragOverResult };
819
893
  const gridRect = e.currentTarget.getBoundingClientRect();
820
- const layerX = e.clientX - gridRect.left;
821
- const layerY = e.clientY - gridRect.top;
894
+ const positionParams = {
895
+ cols,
896
+ margin,
897
+ maxRows,
898
+ rowHeight,
899
+ containerWidth: width,
900
+ containerPadding: effectiveContainerPadding
901
+ };
902
+ const actualColWidth = chunkBJFPTW5Q_js.calcGridColWidth(positionParams);
903
+ const itemPixelWidth = chunkBJFPTW5Q_js.calcGridItemWHPx(
904
+ finalDroppingItem.w,
905
+ actualColWidth,
906
+ margin[0]
907
+ );
908
+ const itemPixelHeight = chunkBJFPTW5Q_js.calcGridItemWHPx(
909
+ finalDroppingItem.h,
910
+ rowHeight,
911
+ margin[1]
912
+ );
913
+ const itemCenterOffsetX = itemPixelWidth / 2;
914
+ const itemCenterOffsetY = itemPixelHeight / 2;
915
+ const rawGridX = e.clientX - gridRect.left + dragOffsetX - itemCenterOffsetX;
916
+ const rawGridY = e.clientY - gridRect.top + dragOffsetY - itemCenterOffsetY;
917
+ const clampedGridX = Math.max(0, rawGridX);
918
+ const clampedGridY = Math.max(0, rawGridY);
822
919
  const newDroppingPosition = {
823
- left: layerX / transformScale,
824
- top: layerY / transformScale,
920
+ left: clampedGridX / transformScale,
921
+ top: clampedGridY / transformScale,
825
922
  e: e.nativeEvent
826
923
  };
827
924
  if (!droppingDOMNode) {
828
- const positionParams = {
829
- cols,
830
- margin,
831
- maxRows,
832
- rowHeight,
833
- containerWidth: width,
834
- containerPadding: effectiveContainerPadding
835
- };
836
- const calculatedPosition = chunkF6NQPYKT_js.calcXY(
925
+ const calculatedPosition = chunkBJFPTW5Q_js.calcXY(
837
926
  positionParams,
838
- layerY,
839
- layerX,
927
+ clampedGridY,
928
+ clampedGridX,
840
929
  finalDroppingItem.w,
841
930
  finalDroppingItem.h
842
931
  );
@@ -853,7 +942,7 @@ function GridLayout(props) {
853
942
  }
854
943
  ]);
855
944
  } else if (droppingPosition) {
856
- const shouldUpdate = droppingPosition.left !== layerX || droppingPosition.top !== layerY;
945
+ const shouldUpdate = droppingPosition.left !== newDroppingPosition.left || droppingPosition.top !== newDroppingPosition.top;
857
946
  if (shouldUpdate) {
858
947
  setDroppingPosition(newDroppingPosition);
859
948
  }
@@ -905,7 +994,7 @@ function GridLayout(props) {
905
994
  const processGridItem = React2.useCallback(
906
995
  (child, isDroppingItem) => {
907
996
  if (!child || !child.key) return null;
908
- const l = chunk3WO4SAYB_js.getLayoutItem(layout, String(child.key));
997
+ const l = chunkBJFPTW5Q_js.getLayoutItem(layout, String(child.key));
909
998
  if (!l) return null;
910
999
  const draggable = typeof l.isDraggable === "boolean" ? l.isDraggable : !l.static && isDraggable;
911
1000
  const resizable = typeof l.isResizable === "boolean" ? l.isResizable : !l.static && isResizable;
@@ -948,6 +1037,9 @@ function GridLayout(props) {
948
1037
  droppingPosition: isDroppingItem ? droppingPosition : void 0,
949
1038
  resizeHandles: resizeHandlesOptions,
950
1039
  resizeHandle: resizeHandleElement,
1040
+ constraints,
1041
+ layoutItem: l,
1042
+ layout,
951
1043
  children: child
952
1044
  },
953
1045
  l.i
@@ -977,7 +1069,8 @@ function GridLayout(props) {
977
1069
  transformScale,
978
1070
  droppingPosition,
979
1071
  resizeHandles,
980
- resizeHandle
1072
+ resizeHandle,
1073
+ constraints
981
1074
  ]
982
1075
  );
983
1076
  const renderPlaceholder = () => {
@@ -1002,6 +1095,8 @@ function GridLayout(props) {
1002
1095
  isBounded: false,
1003
1096
  useCSSTransforms,
1004
1097
  transformScale,
1098
+ constraints,
1099
+ layout,
1005
1100
  children: /* @__PURE__ */ jsxRuntime.jsx("div", {})
1006
1101
  }
1007
1102
  );
@@ -1083,15 +1178,15 @@ function synchronizeLayoutWithChildren2(initialLayout, children, cols, compactTy
1083
1178
  layout.push({
1084
1179
  i: key,
1085
1180
  x: 0,
1086
- y: chunk3WO4SAYB_js.bottom(layout),
1181
+ y: chunkBJFPTW5Q_js.bottom(layout),
1087
1182
  w: 1,
1088
1183
  h: 1
1089
1184
  });
1090
1185
  }
1091
1186
  }
1092
1187
  });
1093
- const corrected = chunk3WO4SAYB_js.correctBounds(layout, { cols });
1094
- return chunk3WO4SAYB_js.compact(corrected, compactType, cols, allowOverlap);
1188
+ const corrected = chunkBJFPTW5Q_js.correctBounds(layout, { cols });
1189
+ return chunkFN6MIZ24_js.compact(corrected, compactType, cols, allowOverlap);
1095
1190
  }
1096
1191
  function ResponsiveGridLayout(props) {
1097
1192
  const {
@@ -1111,17 +1206,17 @@ function ResponsiveGridLayout(props) {
1111
1206
  onWidthChange = noop2,
1112
1207
  ...restProps
1113
1208
  } = props;
1114
- const compactor = compactorProp ?? chunk3WO4SAYB_js.getCompactor("vertical");
1209
+ const compactor = compactorProp ?? chunkFN6MIZ24_js.getCompactor("vertical");
1115
1210
  const compactType = compactor.type;
1116
1211
  const allowOverlap = compactor.allowOverlap;
1117
1212
  const initialBreakpoint = React2.useMemo(() => {
1118
- return propBreakpoint ?? chunk3WO4SAYB_js.getBreakpointFromWidth(breakpoints, width);
1213
+ return propBreakpoint ?? chunkFN6MIZ24_js.getBreakpointFromWidth(breakpoints, width);
1119
1214
  }, []);
1120
1215
  const initialCols = React2.useMemo(() => {
1121
- return chunk3WO4SAYB_js.getColsFromBreakpoint(initialBreakpoint, colsConfig);
1216
+ return chunkFN6MIZ24_js.getColsFromBreakpoint(initialBreakpoint, colsConfig);
1122
1217
  }, [initialBreakpoint, colsConfig]);
1123
1218
  const initialLayout = React2.useMemo(() => {
1124
- return chunk3WO4SAYB_js.findOrGenerateResponsiveLayout(
1219
+ return chunkFN6MIZ24_js.findOrGenerateResponsiveLayout(
1125
1220
  propsLayouts,
1126
1221
  breakpoints,
1127
1222
  initialBreakpoint,
@@ -1140,9 +1235,13 @@ function ResponsiveGridLayout(props) {
1140
1235
  const prevColsRef = React2.useRef(colsConfig);
1141
1236
  const prevLayoutsRef = React2.useRef(propsLayouts);
1142
1237
  const prevCompactTypeRef = React2.useRef(compactType);
1238
+ const layoutsRef = React2.useRef(layouts);
1143
1239
  React2.useEffect(() => {
1240
+ layoutsRef.current = layouts;
1241
+ }, [layouts]);
1242
+ const derivedLayout = React2.useMemo(() => {
1144
1243
  if (!fastEquals.deepEqual(propsLayouts, prevLayoutsRef.current)) {
1145
- const newLayout = chunk3WO4SAYB_js.findOrGenerateResponsiveLayout(
1244
+ return chunkFN6MIZ24_js.findOrGenerateResponsiveLayout(
1146
1245
  propsLayouts,
1147
1246
  breakpoints,
1148
1247
  breakpoint,
@@ -1150,34 +1249,41 @@ function ResponsiveGridLayout(props) {
1150
1249
  cols,
1151
1250
  compactType
1152
1251
  );
1153
- setLayout(newLayout);
1252
+ }
1253
+ return null;
1254
+ }, [propsLayouts, breakpoints, breakpoint, cols, compactType]);
1255
+ const effectiveLayout = derivedLayout ?? layout;
1256
+ React2.useEffect(() => {
1257
+ if (derivedLayout !== null) {
1258
+ setLayout(derivedLayout);
1154
1259
  setLayouts(propsLayouts);
1260
+ layoutsRef.current = propsLayouts;
1155
1261
  prevLayoutsRef.current = propsLayouts;
1156
1262
  }
1157
- }, [propsLayouts, breakpoints, breakpoint, cols, compactType]);
1263
+ }, [derivedLayout, propsLayouts]);
1158
1264
  React2.useEffect(() => {
1159
1265
  if (compactType !== prevCompactTypeRef.current) {
1160
- const newLayout = chunk3WO4SAYB_js.compact(
1161
- chunk3WO4SAYB_js.cloneLayout(layout),
1266
+ const newLayout = chunkFN6MIZ24_js.compact(
1267
+ chunkBJFPTW5Q_js.cloneLayout(effectiveLayout),
1162
1268
  compactType,
1163
1269
  cols,
1164
1270
  allowOverlap
1165
1271
  );
1166
1272
  const newLayouts = {
1167
- ...layouts,
1273
+ ...layoutsRef.current,
1168
1274
  [breakpoint]: newLayout
1169
1275
  };
1170
1276
  setLayout(newLayout);
1171
1277
  setLayouts(newLayouts);
1278
+ layoutsRef.current = newLayouts;
1172
1279
  onLayoutChange(newLayout, newLayouts);
1173
1280
  prevCompactTypeRef.current = compactType;
1174
1281
  }
1175
1282
  }, [
1176
1283
  compactType,
1177
- layout,
1284
+ effectiveLayout,
1178
1285
  cols,
1179
1286
  allowOverlap,
1180
- layouts,
1181
1287
  breakpoint,
1182
1288
  onLayoutChange
1183
1289
  ]);
@@ -1190,15 +1296,15 @@ function ResponsiveGridLayout(props) {
1190
1296
  );
1191
1297
  const colsChanged = !fastEquals.deepEqual(colsConfig, prevColsRef.current);
1192
1298
  if (widthChanged || breakpointPropChanged || breakpointsChanged || colsChanged) {
1193
- const newBreakpoint = propBreakpoint ?? chunk3WO4SAYB_js.getBreakpointFromWidth(breakpoints, width);
1194
- const newCols = chunk3WO4SAYB_js.getColsFromBreakpoint(newBreakpoint, colsConfig);
1299
+ const newBreakpoint = propBreakpoint ?? chunkFN6MIZ24_js.getBreakpointFromWidth(breakpoints, width);
1300
+ const newCols = chunkFN6MIZ24_js.getColsFromBreakpoint(newBreakpoint, colsConfig);
1195
1301
  const lastBreakpoint = breakpoint;
1196
1302
  if (lastBreakpoint !== newBreakpoint || breakpointsChanged || colsChanged) {
1197
- const newLayouts = { ...layouts };
1303
+ const newLayouts = { ...layoutsRef.current };
1198
1304
  if (!newLayouts[lastBreakpoint]) {
1199
- newLayouts[lastBreakpoint] = chunk3WO4SAYB_js.cloneLayout(layout);
1305
+ newLayouts[lastBreakpoint] = chunkBJFPTW5Q_js.cloneLayout(layout);
1200
1306
  }
1201
- let newLayout = chunk3WO4SAYB_js.findOrGenerateResponsiveLayout(
1307
+ let newLayout = chunkFN6MIZ24_js.findOrGenerateResponsiveLayout(
1202
1308
  newLayouts,
1203
1309
  breakpoints,
1204
1310
  newBreakpoint,
@@ -1218,14 +1324,15 @@ function ResponsiveGridLayout(props) {
1218
1324
  setCols(newCols);
1219
1325
  setLayout(newLayout);
1220
1326
  setLayouts(newLayouts);
1327
+ layoutsRef.current = newLayouts;
1221
1328
  onBreakpointChange(newBreakpoint, newCols);
1222
1329
  onLayoutChange(newLayout, newLayouts);
1223
1330
  }
1224
- const currentMargin2 = chunk3WO4SAYB_js.getIndentationValue(
1331
+ const currentMargin2 = chunkFN6MIZ24_js.getIndentationValue(
1225
1332
  propMargin,
1226
1333
  newBreakpoint
1227
1334
  );
1228
- const currentPadding = propContainerPadding ? chunk3WO4SAYB_js.getIndentationValue(
1335
+ const currentPadding = propContainerPadding ? chunkFN6MIZ24_js.getIndentationValue(
1229
1336
  propContainerPadding,
1230
1337
  newBreakpoint
1231
1338
  ) : null;
@@ -1243,7 +1350,6 @@ function ResponsiveGridLayout(props) {
1243
1350
  breakpoint,
1244
1351
  cols,
1245
1352
  layout,
1246
- layouts,
1247
1353
  children,
1248
1354
  compactType,
1249
1355
  allowOverlap,
@@ -1255,25 +1361,27 @@ function ResponsiveGridLayout(props) {
1255
1361
  ]);
1256
1362
  const handleLayoutChange = React2.useCallback(
1257
1363
  (newLayout) => {
1364
+ const currentLayouts = layoutsRef.current;
1258
1365
  const newLayouts = {
1259
- ...layouts,
1366
+ ...currentLayouts,
1260
1367
  [breakpoint]: newLayout
1261
1368
  };
1262
1369
  setLayout(newLayout);
1263
1370
  setLayouts(newLayouts);
1371
+ layoutsRef.current = newLayouts;
1264
1372
  onLayoutChange(newLayout, newLayouts);
1265
1373
  },
1266
- [layouts, breakpoint, onLayoutChange]
1374
+ [breakpoint, onLayoutChange]
1267
1375
  );
1268
1376
  const currentMargin = React2.useMemo(() => {
1269
- return chunk3WO4SAYB_js.getIndentationValue(
1377
+ return chunkFN6MIZ24_js.getIndentationValue(
1270
1378
  propMargin,
1271
1379
  breakpoint
1272
1380
  );
1273
1381
  }, [propMargin, breakpoint]);
1274
1382
  const currentContainerPadding = React2.useMemo(() => {
1275
1383
  if (propContainerPadding === null) return null;
1276
- return chunk3WO4SAYB_js.getIndentationValue(
1384
+ return chunkFN6MIZ24_js.getIndentationValue(
1277
1385
  propContainerPadding,
1278
1386
  breakpoint
1279
1387
  );
@@ -1296,7 +1404,7 @@ function ResponsiveGridLayout(props) {
1296
1404
  gridConfig,
1297
1405
  compactor,
1298
1406
  onLayoutChange: handleLayoutChange,
1299
- layout,
1407
+ layout: effectiveLayout,
1300
1408
  children
1301
1409
  }
1302
1410
  );
@@ -1305,5 +1413,5 @@ function ResponsiveGridLayout(props) {
1305
1413
  exports.GridItem = GridItem;
1306
1414
  exports.GridLayout = GridLayout;
1307
1415
  exports.ResponsiveGridLayout = ResponsiveGridLayout;
1308
- //# sourceMappingURL=chunk-BFTKGAP3.js.map
1309
- //# sourceMappingURL=chunk-BFTKGAP3.js.map
1416
+ //# sourceMappingURL=chunk-QRW3ND4U.js.map
1417
+ //# sourceMappingURL=chunk-QRW3ND4U.js.map