react-grid-layout 1.5.3 → 2.0.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 (95) hide show
  1. package/README.md +1074 -432
  2. package/css/styles.css +6 -4
  3. package/dist/ResponsiveGridLayout-CH4s0tKj.d.ts +124 -0
  4. package/dist/ResponsiveGridLayout-D6lFRE3f.d.mts +124 -0
  5. package/dist/calculate-CwYDW8na.d.mts +168 -0
  6. package/dist/calculate-mgLpNJ5O.d.ts +168 -0
  7. package/dist/chunk-2KUHNJXF.mjs +90 -0
  8. package/dist/chunk-2KUHNJXF.mjs.map +1 -0
  9. package/dist/chunk-3WO4SAYB.js +868 -0
  10. package/dist/chunk-3WO4SAYB.js.map +1 -0
  11. package/dist/chunk-4HNUMWQK.mjs +822 -0
  12. package/dist/chunk-4HNUMWQK.mjs.map +1 -0
  13. package/dist/chunk-BFTKGAP3.js +1309 -0
  14. package/dist/chunk-BFTKGAP3.js.map +1 -0
  15. package/dist/chunk-F6NQPYKT.js +98 -0
  16. package/dist/chunk-F6NQPYKT.js.map +1 -0
  17. package/dist/chunk-H5KMDLY3.js +434 -0
  18. package/dist/chunk-H5KMDLY3.js.map +1 -0
  19. package/dist/chunk-PBQSHIID.js +4 -0
  20. package/dist/chunk-PBQSHIID.js.map +1 -0
  21. package/dist/chunk-R35HZZTA.mjs +1300 -0
  22. package/dist/chunk-R35HZZTA.mjs.map +1 -0
  23. package/dist/chunk-ZCXE6SR5.mjs +428 -0
  24. package/dist/chunk-ZCXE6SR5.mjs.map +1 -0
  25. package/dist/chunk-ZWN22PS2.mjs +3 -0
  26. package/dist/chunk-ZWN22PS2.mjs.map +1 -0
  27. package/dist/core.d.mts +33 -0
  28. package/dist/core.d.ts +33 -0
  29. package/dist/core.js +218 -0
  30. package/dist/core.js.map +1 -0
  31. package/dist/core.mjs +5 -0
  32. package/dist/core.mjs.map +1 -0
  33. package/dist/extras.d.mts +78 -0
  34. package/dist/extras.d.ts +78 -0
  35. package/dist/extras.js +91 -0
  36. package/dist/extras.js.map +1 -0
  37. package/dist/extras.mjs +89 -0
  38. package/dist/extras.mjs.map +1 -0
  39. package/dist/index.d.mts +7 -0
  40. package/dist/index.d.ts +7 -0
  41. package/dist/index.js +154 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/index.mjs +7 -0
  44. package/dist/index.mjs.map +1 -0
  45. package/dist/legacy.d.mts +163 -0
  46. package/dist/legacy.d.ts +163 -0
  47. package/dist/legacy.js +319 -0
  48. package/dist/legacy.js.map +1 -0
  49. package/dist/legacy.mjs +307 -0
  50. package/dist/legacy.mjs.map +1 -0
  51. package/dist/position-BmN1z36J.d.mts +319 -0
  52. package/dist/position-Dk2b4ZMS.d.ts +319 -0
  53. package/dist/react.d.mts +351 -0
  54. package/dist/react.d.ts +351 -0
  55. package/dist/react.js +96 -0
  56. package/dist/react.js.map +1 -0
  57. package/dist/react.mjs +7 -0
  58. package/dist/react.mjs.map +1 -0
  59. package/dist/responsive-C4L1ESlm.d.ts +145 -0
  60. package/dist/responsive-CJxefsYw.d.mts +145 -0
  61. package/dist/types-Cxf4nHNr.d.mts +375 -0
  62. package/dist/types-Cxf4nHNr.d.ts +375 -0
  63. package/index-dev.js +8 -0
  64. package/package.json +132 -40
  65. package/.babelrc.js +0 -22
  66. package/.browserslistrc +0 -3
  67. package/.eslintignore +0 -4
  68. package/.flowconfig +0 -20
  69. package/.prettierignore +0 -4
  70. package/.prettierrc +0 -17
  71. package/CHANGELOG.md +0 -985
  72. package/build/GridItem.js +0 -638
  73. package/build/ReactGridLayout.js +0 -741
  74. package/build/ReactGridLayoutPropTypes.js +0 -210
  75. package/build/ResponsiveReactGridLayout.js +0 -297
  76. package/build/calculateUtils.js +0 -165
  77. package/build/components/WidthProvider.js +0 -115
  78. package/build/fastRGLPropsEqual.js +0 -5
  79. package/build/responsiveUtils.js +0 -101
  80. package/build/utils.js +0 -842
  81. package/dist/react-grid-layout.min.js +0 -2
  82. package/dist/react-grid-layout.min.js.map +0 -1
  83. package/index.js.flow +0 -8
  84. package/ip_fetcher +0 -0
  85. package/ip_fetcher.c +0 -47
  86. package/lib/GridItem.jsx +0 -689
  87. package/lib/ReactGridLayout.jsx +0 -855
  88. package/lib/ReactGridLayoutPropTypes.js +0 -241
  89. package/lib/ResponsiveReactGridLayout.jsx +0 -349
  90. package/lib/calculateUtils.js +0 -169
  91. package/lib/components/WidthProvider.jsx +0 -110
  92. package/lib/fastRGLPropsEqual.js +0 -46
  93. package/lib/responsiveUtils.js +0 -118
  94. package/lib/utils.js +0 -995
  95. package/yarn-error.log +0 -7780
@@ -0,0 +1,1300 @@
1
+ import { setTransform, setTopLeft, perc, resizeItemInDirection, defaultPositionStrategy, defaultGridConfig, defaultDragConfig, defaultResizeConfig, defaultDropConfig, getCompactor, bottom, getLayoutItem, cloneLayoutItem, moveElement, compact, withLayoutItem, getAllCollisions, getBreakpointFromWidth, getColsFromBreakpoint, findOrGenerateResponsiveLayout, cloneLayout, getIndentationValue, correctBounds } from './chunk-4HNUMWQK.mjs';
2
+ import { calcXY, calcGridItemWHPx, clamp, calcGridColWidth, calcWH, calcGridItemPosition } from './chunk-2KUHNJXF.mjs';
3
+ import React2, { useState, useRef, useMemo, useCallback, useEffect } from 'react';
4
+ import { DraggableCore } from 'react-draggable';
5
+ import { Resizable } from 'react-resizable';
6
+ import clsx from 'clsx';
7
+ import { jsx, jsxs } from 'react/jsx-runtime';
8
+ import { deepEqual } from 'fast-equals';
9
+
10
+ function GridItem(props) {
11
+ const {
12
+ children,
13
+ cols,
14
+ containerWidth,
15
+ margin,
16
+ containerPadding,
17
+ rowHeight,
18
+ maxRows,
19
+ isDraggable,
20
+ isResizable,
21
+ isBounded,
22
+ static: isStatic,
23
+ useCSSTransforms = true,
24
+ usePercentages = false,
25
+ transformScale = 1,
26
+ droppingPosition,
27
+ className = "",
28
+ style,
29
+ handle = "",
30
+ cancel = "",
31
+ x,
32
+ y,
33
+ w,
34
+ h,
35
+ minW = 1,
36
+ maxW = Infinity,
37
+ minH = 1,
38
+ maxH = Infinity,
39
+ i,
40
+ resizeHandles,
41
+ resizeHandle,
42
+ onDragStart: onDragStartProp,
43
+ onDrag: onDragProp,
44
+ onDragStop: onDragStopProp,
45
+ onResizeStart: onResizeStartProp,
46
+ onResize: onResizeProp,
47
+ onResizeStop: onResizeStopProp
48
+ } = props;
49
+ const [dragging, setDragging] = useState(false);
50
+ const [resizing, setResizing] = useState(false);
51
+ const elementRef = useRef(null);
52
+ const dragPositionRef = useRef({ left: 0, top: 0 });
53
+ const resizePositionRef = useRef({
54
+ top: 0,
55
+ left: 0,
56
+ width: 0,
57
+ height: 0
58
+ });
59
+ const prevDroppingPositionRef = useRef(
60
+ void 0
61
+ );
62
+ const positionParams = useMemo(
63
+ () => ({
64
+ cols,
65
+ containerPadding,
66
+ containerWidth,
67
+ margin,
68
+ maxRows,
69
+ rowHeight
70
+ }),
71
+ [cols, containerPadding, containerWidth, margin, maxRows, rowHeight]
72
+ );
73
+ const createStyle = useCallback(
74
+ (pos2) => {
75
+ if (useCSSTransforms) {
76
+ return setTransform(pos2);
77
+ }
78
+ const styleObj = setTopLeft(pos2);
79
+ if (usePercentages) {
80
+ return {
81
+ ...styleObj,
82
+ left: perc(pos2.left / containerWidth),
83
+ width: perc(pos2.width / containerWidth)
84
+ };
85
+ }
86
+ return styleObj;
87
+ },
88
+ [useCSSTransforms, usePercentages, containerWidth]
89
+ );
90
+ const onDragStart = useCallback(
91
+ (e, { node }) => {
92
+ if (!onDragStartProp) return;
93
+ const { offsetParent } = node;
94
+ if (!offsetParent) return;
95
+ const parentRect = offsetParent.getBoundingClientRect();
96
+ const clientRect = node.getBoundingClientRect();
97
+ const cLeft = clientRect.left / transformScale;
98
+ const pLeft = parentRect.left / transformScale;
99
+ const cTop = clientRect.top / transformScale;
100
+ const pTop = parentRect.top / transformScale;
101
+ const newPosition = {
102
+ left: cLeft - pLeft + offsetParent.scrollLeft,
103
+ top: cTop - pTop + offsetParent.scrollTop
104
+ };
105
+ dragPositionRef.current = newPosition;
106
+ setDragging(true);
107
+ const { x: newX, y: newY } = calcXY(
108
+ positionParams,
109
+ newPosition.top,
110
+ newPosition.left,
111
+ w,
112
+ h
113
+ );
114
+ onDragStartProp(i, newX, newY, {
115
+ e,
116
+ node,
117
+ newPosition
118
+ });
119
+ },
120
+ [onDragStartProp, transformScale, positionParams, w, h, i]
121
+ );
122
+ const onDrag = useCallback(
123
+ (e, { node, deltaX, deltaY }) => {
124
+ if (!onDragProp || !dragging) return;
125
+ let top = dragPositionRef.current.top + deltaY;
126
+ let left = dragPositionRef.current.left + deltaX;
127
+ if (isBounded) {
128
+ const { offsetParent } = node;
129
+ if (offsetParent) {
130
+ const bottomBoundary = offsetParent.clientHeight - calcGridItemWHPx(h, rowHeight, margin[1]);
131
+ top = clamp(top, 0, bottomBoundary);
132
+ const colWidth = calcGridColWidth(positionParams);
133
+ const rightBoundary = containerWidth - calcGridItemWHPx(w, colWidth, margin[0]);
134
+ left = clamp(left, 0, rightBoundary);
135
+ }
136
+ }
137
+ const newPosition = { top, left };
138
+ dragPositionRef.current = newPosition;
139
+ const { x: newX, y: newY } = calcXY(positionParams, top, left, w, h);
140
+ onDragProp(i, newX, newY, {
141
+ e,
142
+ node,
143
+ newPosition
144
+ });
145
+ },
146
+ [
147
+ onDragProp,
148
+ dragging,
149
+ isBounded,
150
+ h,
151
+ rowHeight,
152
+ margin,
153
+ positionParams,
154
+ containerWidth,
155
+ w,
156
+ i
157
+ ]
158
+ );
159
+ const onDragStop = useCallback(
160
+ (e, { node }) => {
161
+ if (!onDragStopProp || !dragging) return;
162
+ const { left, top } = dragPositionRef.current;
163
+ const newPosition = { top, left };
164
+ setDragging(false);
165
+ dragPositionRef.current = { left: 0, top: 0 };
166
+ const { x: newX, y: newY } = calcXY(positionParams, top, left, w, h);
167
+ onDragStopProp(i, newX, newY, {
168
+ e,
169
+ node,
170
+ newPosition
171
+ });
172
+ },
173
+ [onDragStopProp, dragging, positionParams, w, h, i]
174
+ );
175
+ const onResizeHandler = useCallback(
176
+ (e, { node, size, handle: resizeHandle2 }, position, handlerName) => {
177
+ const handler = handlerName === "onResizeStart" ? onResizeStartProp : handlerName === "onResize" ? onResizeProp : onResizeStopProp;
178
+ if (!handler) return;
179
+ let updatedSize;
180
+ if (node) {
181
+ updatedSize = resizeItemInDirection(
182
+ resizeHandle2,
183
+ position,
184
+ size,
185
+ containerWidth
186
+ );
187
+ } else {
188
+ updatedSize = {
189
+ ...size,
190
+ top: position.top,
191
+ left: position.left
192
+ };
193
+ }
194
+ resizePositionRef.current = updatedSize;
195
+ let { w: newW, h: newH } = calcWH(
196
+ positionParams,
197
+ updatedSize.width,
198
+ updatedSize.height,
199
+ x,
200
+ y,
201
+ resizeHandle2
202
+ );
203
+ newW = clamp(newW, Math.max(minW, 1), maxW);
204
+ newH = clamp(newH, minH, maxH);
205
+ handler(i, newW, newH, {
206
+ e: e.nativeEvent,
207
+ node,
208
+ size: updatedSize,
209
+ handle: resizeHandle2
210
+ });
211
+ },
212
+ [
213
+ onResizeStartProp,
214
+ onResizeProp,
215
+ onResizeStopProp,
216
+ containerWidth,
217
+ positionParams,
218
+ x,
219
+ y,
220
+ minW,
221
+ maxW,
222
+ minH,
223
+ maxH,
224
+ i
225
+ ]
226
+ );
227
+ const handleResizeStart = useCallback(
228
+ (e, data) => {
229
+ setResizing(true);
230
+ const pos2 = calcGridItemPosition(positionParams, x, y, w, h);
231
+ const typedData = {
232
+ ...data,
233
+ handle: data.handle
234
+ };
235
+ onResizeHandler(e, typedData, pos2, "onResizeStart");
236
+ },
237
+ [onResizeHandler, positionParams, x, y, w, h]
238
+ );
239
+ const handleResize = useCallback(
240
+ (e, data) => {
241
+ const pos2 = calcGridItemPosition(positionParams, x, y, w, h);
242
+ const typedData = {
243
+ ...data,
244
+ handle: data.handle
245
+ };
246
+ onResizeHandler(e, typedData, pos2, "onResize");
247
+ },
248
+ [onResizeHandler, positionParams, x, y, w, h]
249
+ );
250
+ const handleResizeStop = useCallback(
251
+ (e, data) => {
252
+ setResizing(false);
253
+ resizePositionRef.current = { top: 0, left: 0, width: 0, height: 0 };
254
+ const pos2 = calcGridItemPosition(positionParams, x, y, w, h);
255
+ const typedData = {
256
+ ...data,
257
+ handle: data.handle
258
+ };
259
+ onResizeHandler(e, typedData, pos2, "onResizeStop");
260
+ },
261
+ [onResizeHandler, positionParams, x, y, w, h]
262
+ );
263
+ useEffect(() => {
264
+ if (!droppingPosition) return;
265
+ const node = elementRef.current;
266
+ if (!node) return;
267
+ const prevDroppingPosition = prevDroppingPositionRef.current || {
268
+ left: 0,
269
+ top: 0
270
+ };
271
+ const shouldDrag = dragging && (droppingPosition.left !== prevDroppingPosition.left || droppingPosition.top !== prevDroppingPosition.top);
272
+ if (!dragging) {
273
+ const fakeData = {
274
+ node,
275
+ deltaX: droppingPosition.left,
276
+ deltaY: droppingPosition.top,
277
+ lastX: 0,
278
+ lastY: 0,
279
+ x: droppingPosition.left,
280
+ y: droppingPosition.top
281
+ };
282
+ onDragStart(droppingPosition.e, fakeData);
283
+ } else if (shouldDrag) {
284
+ const deltaX = droppingPosition.left - dragPositionRef.current.left;
285
+ const deltaY = droppingPosition.top - dragPositionRef.current.top;
286
+ const fakeData = {
287
+ node,
288
+ deltaX,
289
+ deltaY,
290
+ lastX: dragPositionRef.current.left,
291
+ lastY: dragPositionRef.current.top,
292
+ x: droppingPosition.left,
293
+ y: droppingPosition.top
294
+ };
295
+ onDrag(droppingPosition.e, fakeData);
296
+ }
297
+ prevDroppingPositionRef.current = droppingPosition;
298
+ }, [droppingPosition, dragging, onDragStart, onDrag]);
299
+ const pos = calcGridItemPosition(
300
+ positionParams,
301
+ x,
302
+ y,
303
+ w,
304
+ h,
305
+ dragging ? dragPositionRef.current : null,
306
+ resizing ? resizePositionRef.current : null
307
+ );
308
+ const child = React2.Children.only(children);
309
+ const maxWidth = calcGridItemPosition(positionParams, 0, 0, cols, 0).width;
310
+ const mins = calcGridItemPosition(positionParams, 0, 0, minW, minH);
311
+ const maxes = calcGridItemPosition(positionParams, 0, 0, maxW, maxH);
312
+ const minConstraints = [mins.width, mins.height];
313
+ const maxConstraints = [
314
+ Math.min(maxes.width, maxWidth),
315
+ Math.min(maxes.height, Infinity)
316
+ ];
317
+ const childProps = child.props;
318
+ const childClassName = childProps["className"];
319
+ const childStyle = childProps["style"];
320
+ let newChild = React2.cloneElement(child, {
321
+ ref: elementRef,
322
+ className: clsx("react-grid-item", childClassName, className, {
323
+ static: isStatic,
324
+ resizing,
325
+ "react-draggable": isDraggable,
326
+ "react-draggable-dragging": dragging,
327
+ dropping: Boolean(droppingPosition),
328
+ cssTransforms: useCSSTransforms
329
+ }),
330
+ style: {
331
+ ...style,
332
+ ...childStyle,
333
+ ...createStyle(pos)
334
+ }
335
+ });
336
+ const resizableHandle = resizeHandle;
337
+ newChild = /* @__PURE__ */ jsx(
338
+ Resizable,
339
+ {
340
+ draggableOpts: { disabled: !isResizable },
341
+ className: isResizable ? void 0 : "react-resizable-hide",
342
+ width: pos.width,
343
+ height: pos.height,
344
+ minConstraints,
345
+ maxConstraints,
346
+ onResizeStart: handleResizeStart,
347
+ onResize: handleResize,
348
+ onResizeStop: handleResizeStop,
349
+ transformScale,
350
+ resizeHandles,
351
+ handle: resizableHandle,
352
+ children: newChild
353
+ }
354
+ );
355
+ newChild = /* @__PURE__ */ jsx(
356
+ DraggableCore,
357
+ {
358
+ disabled: !isDraggable,
359
+ onStart: onDragStart,
360
+ onDrag,
361
+ onStop: onDragStop,
362
+ handle,
363
+ cancel: ".react-resizable-handle" + (cancel ? "," + cancel : ""),
364
+ scale: transformScale,
365
+ nodeRef: elementRef,
366
+ children: newChild
367
+ }
368
+ );
369
+ return newChild;
370
+ }
371
+ var noop = () => {
372
+ };
373
+ var layoutClassName = "react-grid-layout";
374
+ var isFirefox = false;
375
+ try {
376
+ isFirefox = /firefox/i.test(navigator.userAgent);
377
+ } catch {
378
+ }
379
+ function childrenEqual(a, b) {
380
+ const aArr = React2.Children.toArray(a);
381
+ const bArr = React2.Children.toArray(b);
382
+ if (aArr.length !== bArr.length) return false;
383
+ for (let i = 0; i < aArr.length; i++) {
384
+ const aChild = aArr[i];
385
+ const bChild = bArr[i];
386
+ if (aChild?.key !== bChild?.key) return false;
387
+ }
388
+ return true;
389
+ }
390
+ function synchronizeLayoutWithChildren(initialLayout, children, cols, compactType, allowOverlap) {
391
+ const layout = [];
392
+ const childKeys = /* @__PURE__ */ new Set();
393
+ React2.Children.forEach(children, (child) => {
394
+ if (!React2.isValidElement(child) || child.key === null) return;
395
+ const key = String(child.key);
396
+ childKeys.add(key);
397
+ const existingItem = initialLayout.find((l) => l.i === key);
398
+ if (existingItem) {
399
+ layout.push(cloneLayoutItem(existingItem));
400
+ } else {
401
+ const childProps = child.props;
402
+ const dataGrid = childProps["data-grid"];
403
+ if (dataGrid) {
404
+ layout.push({
405
+ i: key,
406
+ x: dataGrid.x ?? 0,
407
+ y: dataGrid.y ?? 0,
408
+ w: dataGrid.w ?? 1,
409
+ h: dataGrid.h ?? 1,
410
+ minW: dataGrid.minW,
411
+ maxW: dataGrid.maxW,
412
+ minH: dataGrid.minH,
413
+ maxH: dataGrid.maxH,
414
+ static: dataGrid.static,
415
+ isDraggable: dataGrid.isDraggable,
416
+ isResizable: dataGrid.isResizable,
417
+ resizeHandles: dataGrid.resizeHandles,
418
+ isBounded: dataGrid.isBounded
419
+ });
420
+ } else {
421
+ layout.push({
422
+ i: key,
423
+ x: 0,
424
+ y: bottom(layout),
425
+ w: 1,
426
+ h: 1
427
+ });
428
+ }
429
+ }
430
+ });
431
+ const corrected = correctBounds(layout, { cols });
432
+ return compact(corrected, compactType, cols, allowOverlap);
433
+ }
434
+ function GridLayout(props) {
435
+ const {
436
+ // Required
437
+ children,
438
+ width,
439
+ // Composable config interfaces
440
+ gridConfig: gridConfigProp,
441
+ dragConfig: dragConfigProp,
442
+ resizeConfig: resizeConfigProp,
443
+ dropConfig: dropConfigProp,
444
+ positionStrategy = defaultPositionStrategy,
445
+ compactor: compactorProp,
446
+ // Layout data
447
+ layout: propsLayout = [],
448
+ droppingItem: droppingItemProp,
449
+ // Container props
450
+ autoSize = true,
451
+ className = "",
452
+ style = {},
453
+ innerRef,
454
+ // Callbacks
455
+ onLayoutChange = noop,
456
+ onDragStart: onDragStartProp = noop,
457
+ onDrag: onDragProp = noop,
458
+ onDragStop: onDragStopProp = noop,
459
+ onResizeStart: onResizeStartProp = noop,
460
+ onResize: onResizeProp = noop,
461
+ onResizeStop: onResizeStopProp = noop,
462
+ onDrop: onDropProp = noop,
463
+ onDropDragOver: onDropDragOverProp = noop
464
+ } = props;
465
+ const gridConfig = useMemo(
466
+ () => ({ ...defaultGridConfig, ...gridConfigProp }),
467
+ [gridConfigProp]
468
+ );
469
+ const dragConfig = useMemo(
470
+ () => ({ ...defaultDragConfig, ...dragConfigProp }),
471
+ [dragConfigProp]
472
+ );
473
+ const resizeConfig = useMemo(
474
+ () => ({ ...defaultResizeConfig, ...resizeConfigProp }),
475
+ [resizeConfigProp]
476
+ );
477
+ const dropConfig = useMemo(
478
+ () => ({ ...defaultDropConfig, ...dropConfigProp }),
479
+ [dropConfigProp]
480
+ );
481
+ const { cols, rowHeight, maxRows, margin, containerPadding } = gridConfig;
482
+ const {
483
+ enabled: isDraggable,
484
+ bounded: isBounded,
485
+ handle: draggableHandle,
486
+ cancel: draggableCancel
487
+ } = dragConfig;
488
+ const {
489
+ enabled: isResizable,
490
+ handles: resizeHandles,
491
+ handleComponent: resizeHandle
492
+ } = resizeConfig;
493
+ const { enabled: isDroppable, defaultItem: defaultDropItem } = dropConfig;
494
+ const compactor = compactorProp ?? getCompactor("vertical");
495
+ const compactType = compactor.type;
496
+ const allowOverlap = compactor.allowOverlap;
497
+ const preventCollision = compactor.preventCollision ?? false;
498
+ const droppingItem = useMemo(
499
+ () => droppingItemProp ?? {
500
+ i: "__dropping-elem__",
501
+ ...defaultDropItem
502
+ },
503
+ [droppingItemProp, defaultDropItem]
504
+ );
505
+ const useCSSTransforms = positionStrategy.type === "transform";
506
+ const transformScale = positionStrategy.scale;
507
+ const effectiveContainerPadding = containerPadding ?? margin;
508
+ const [mounted, setMounted] = useState(false);
509
+ const [layout, setLayout] = useState(
510
+ () => synchronizeLayoutWithChildren(
511
+ propsLayout,
512
+ children,
513
+ cols,
514
+ compactType,
515
+ allowOverlap
516
+ )
517
+ );
518
+ const [activeDrag, setActiveDrag] = useState(null);
519
+ const [resizing, setResizing] = useState(false);
520
+ const [droppingDOMNode, setDroppingDOMNode] = useState(
521
+ null
522
+ );
523
+ const [droppingPosition, setDroppingPosition] = useState();
524
+ const oldDragItemRef = useRef(null);
525
+ const oldResizeItemRef = useRef(null);
526
+ const oldLayoutRef = useRef(null);
527
+ const dragEnterCounterRef = useRef(0);
528
+ const prevLayoutRef = useRef(layout);
529
+ const prevPropsLayoutRef = useRef(propsLayout);
530
+ const prevChildrenRef = useRef(children);
531
+ const prevCompactTypeRef = useRef(compactType);
532
+ useEffect(() => {
533
+ setMounted(true);
534
+ if (!deepEqual(layout, propsLayout)) {
535
+ onLayoutChange(layout);
536
+ }
537
+ }, []);
538
+ useEffect(() => {
539
+ if (activeDrag) return;
540
+ const layoutChanged = !deepEqual(propsLayout, prevPropsLayoutRef.current);
541
+ const childrenChanged = !childrenEqual(children, prevChildrenRef.current);
542
+ const compactTypeChanged = compactType !== prevCompactTypeRef.current;
543
+ if (layoutChanged || childrenChanged || compactTypeChanged) {
544
+ const baseLayout = layoutChanged ? propsLayout : layout;
545
+ const newLayout = synchronizeLayoutWithChildren(
546
+ baseLayout,
547
+ children,
548
+ cols,
549
+ compactType,
550
+ allowOverlap
551
+ );
552
+ setLayout(newLayout);
553
+ }
554
+ prevPropsLayoutRef.current = propsLayout;
555
+ prevChildrenRef.current = children;
556
+ prevCompactTypeRef.current = compactType;
557
+ }, [
558
+ propsLayout,
559
+ children,
560
+ cols,
561
+ compactType,
562
+ allowOverlap,
563
+ activeDrag,
564
+ layout
565
+ ]);
566
+ useEffect(() => {
567
+ if (!activeDrag && !deepEqual(layout, prevLayoutRef.current)) {
568
+ prevLayoutRef.current = layout;
569
+ onLayoutChange(layout);
570
+ }
571
+ }, [layout, activeDrag, onLayoutChange]);
572
+ const containerHeight = useMemo(() => {
573
+ if (!autoSize) return void 0;
574
+ const nbRow = bottom(layout);
575
+ const containerPaddingY = effectiveContainerPadding[1];
576
+ return nbRow * rowHeight + (nbRow - 1) * margin[1] + containerPaddingY * 2 + "px";
577
+ }, [autoSize, layout, rowHeight, margin, effectiveContainerPadding]);
578
+ const onDragStart = useCallback(
579
+ (i, _x, _y, data) => {
580
+ const l = getLayoutItem(layout, i);
581
+ if (!l) return;
582
+ const placeholder = {
583
+ w: l.w,
584
+ h: l.h,
585
+ x: l.x,
586
+ y: l.y,
587
+ i
588
+ };
589
+ oldDragItemRef.current = cloneLayoutItem(l);
590
+ oldLayoutRef.current = layout;
591
+ setActiveDrag(placeholder);
592
+ onDragStartProp(layout, l, l, null, data.e, data.node);
593
+ },
594
+ [layout, onDragStartProp]
595
+ );
596
+ const onDrag = useCallback(
597
+ (i, x, y, data) => {
598
+ const oldDragItem = oldDragItemRef.current;
599
+ const l = getLayoutItem(layout, i);
600
+ if (!l) return;
601
+ const placeholder = {
602
+ w: l.w,
603
+ h: l.h,
604
+ x: l.x,
605
+ y: l.y,
606
+ i
607
+ };
608
+ const newLayout = moveElement(
609
+ layout,
610
+ l,
611
+ x,
612
+ y,
613
+ true,
614
+ preventCollision,
615
+ compactType,
616
+ cols,
617
+ allowOverlap
618
+ );
619
+ onDragProp(newLayout, oldDragItem, l, placeholder, data.e, data.node);
620
+ setLayout(
621
+ allowOverlap ? newLayout : compact(newLayout, compactType, cols)
622
+ );
623
+ setActiveDrag(placeholder);
624
+ },
625
+ [layout, preventCollision, compactType, cols, allowOverlap, onDragProp]
626
+ );
627
+ const onDragStop = useCallback(
628
+ (i, x, y, data) => {
629
+ if (!activeDrag) return;
630
+ const oldDragItem = oldDragItemRef.current;
631
+ const l = getLayoutItem(layout, i);
632
+ if (!l) return;
633
+ const newLayout = moveElement(
634
+ layout,
635
+ l,
636
+ x,
637
+ y,
638
+ true,
639
+ preventCollision,
640
+ compactType,
641
+ cols,
642
+ allowOverlap
643
+ );
644
+ const finalLayout = allowOverlap ? newLayout : compact(newLayout, compactType, cols);
645
+ onDragStopProp(finalLayout, oldDragItem, l, null, data.e, data.node);
646
+ const oldLayout = oldLayoutRef.current;
647
+ oldDragItemRef.current = null;
648
+ oldLayoutRef.current = null;
649
+ setActiveDrag(null);
650
+ setLayout(finalLayout);
651
+ if (oldLayout && !deepEqual(oldLayout, finalLayout)) {
652
+ onLayoutChange(finalLayout);
653
+ }
654
+ },
655
+ [
656
+ activeDrag,
657
+ layout,
658
+ preventCollision,
659
+ compactType,
660
+ cols,
661
+ allowOverlap,
662
+ onDragStopProp,
663
+ onLayoutChange
664
+ ]
665
+ );
666
+ const onResizeStart = useCallback(
667
+ (i, _w, _h, data) => {
668
+ const l = getLayoutItem(layout, i);
669
+ if (!l) return;
670
+ oldResizeItemRef.current = cloneLayoutItem(l);
671
+ oldLayoutRef.current = layout;
672
+ setResizing(true);
673
+ onResizeStartProp(layout, l, l, null, data.e, data.node);
674
+ },
675
+ [layout, onResizeStartProp]
676
+ );
677
+ const onResize = useCallback(
678
+ (i, w, h, data) => {
679
+ const oldResizeItem = oldResizeItemRef.current;
680
+ const { handle } = data;
681
+ let shouldMoveItem = false;
682
+ let newX;
683
+ let newY;
684
+ const [newLayout, l] = withLayoutItem(layout, i, (item) => {
685
+ newX = item.x;
686
+ newY = item.y;
687
+ if (["sw", "w", "nw", "n", "ne"].includes(handle)) {
688
+ if (["sw", "nw", "w"].includes(handle)) {
689
+ newX = item.x + (item.w - w);
690
+ w = item.x !== newX && newX < 0 ? item.w : w;
691
+ newX = newX < 0 ? 0 : newX;
692
+ }
693
+ if (["ne", "n", "nw"].includes(handle)) {
694
+ newY = item.y + (item.h - h);
695
+ h = item.y !== newY && newY < 0 ? item.h : h;
696
+ newY = newY < 0 ? 0 : newY;
697
+ }
698
+ shouldMoveItem = true;
699
+ }
700
+ if (preventCollision && !allowOverlap) {
701
+ const collisions = getAllCollisions(layout, {
702
+ ...item,
703
+ w,
704
+ h,
705
+ x: newX ?? item.x,
706
+ y: newY ?? item.y
707
+ }).filter((layoutItem) => layoutItem.i !== item.i);
708
+ if (collisions.length > 0) {
709
+ newY = item.y;
710
+ h = item.h;
711
+ newX = item.x;
712
+ w = item.w;
713
+ shouldMoveItem = false;
714
+ }
715
+ }
716
+ item.w = w;
717
+ item.h = h;
718
+ return item;
719
+ });
720
+ if (!l) return;
721
+ let finalLayout = newLayout;
722
+ if (shouldMoveItem && newX !== void 0 && newY !== void 0) {
723
+ finalLayout = moveElement(
724
+ newLayout,
725
+ l,
726
+ newX,
727
+ newY,
728
+ true,
729
+ preventCollision,
730
+ compactType,
731
+ cols,
732
+ allowOverlap
733
+ );
734
+ }
735
+ const placeholder = {
736
+ w: l.w,
737
+ h: l.h,
738
+ x: l.x,
739
+ y: l.y,
740
+ i,
741
+ static: true
742
+ };
743
+ onResizeProp(
744
+ finalLayout,
745
+ oldResizeItem,
746
+ l,
747
+ placeholder,
748
+ data.e,
749
+ data.node
750
+ );
751
+ setLayout(
752
+ allowOverlap ? finalLayout : compact(finalLayout, compactType, cols)
753
+ );
754
+ setActiveDrag(placeholder);
755
+ },
756
+ [layout, preventCollision, allowOverlap, compactType, cols, onResizeProp]
757
+ );
758
+ const onResizeStop = useCallback(
759
+ (i, _w, _h, data) => {
760
+ const oldResizeItem = oldResizeItemRef.current;
761
+ const l = getLayoutItem(layout, i);
762
+ const finalLayout = allowOverlap ? layout : compact(layout, compactType, cols);
763
+ onResizeStopProp(
764
+ finalLayout,
765
+ oldResizeItem,
766
+ l ?? null,
767
+ null,
768
+ data.e,
769
+ data.node
770
+ );
771
+ const oldLayout = oldLayoutRef.current;
772
+ oldResizeItemRef.current = null;
773
+ oldLayoutRef.current = null;
774
+ setActiveDrag(null);
775
+ setResizing(false);
776
+ setLayout(finalLayout);
777
+ if (oldLayout && !deepEqual(oldLayout, finalLayout)) {
778
+ onLayoutChange(finalLayout);
779
+ }
780
+ },
781
+ [layout, allowOverlap, compactType, cols, onResizeStopProp, onLayoutChange]
782
+ );
783
+ const removeDroppingPlaceholder = useCallback(() => {
784
+ const newLayout = compact(
785
+ layout.filter((l) => l.i !== droppingItem.i),
786
+ compactType,
787
+ cols,
788
+ allowOverlap
789
+ );
790
+ setLayout(newLayout);
791
+ setDroppingDOMNode(null);
792
+ setActiveDrag(null);
793
+ setDroppingPosition(void 0);
794
+ }, [layout, droppingItem.i, compactType, cols, allowOverlap]);
795
+ const handleDragOver = useCallback(
796
+ (e) => {
797
+ e.preventDefault();
798
+ e.stopPropagation();
799
+ if (isFirefox && !e.nativeEvent.target?.classList.contains(
800
+ layoutClassName
801
+ )) {
802
+ return false;
803
+ }
804
+ const onDragOverResult = onDropDragOverProp(e);
805
+ if (onDragOverResult === false) {
806
+ if (droppingDOMNode) {
807
+ removeDroppingPlaceholder();
808
+ }
809
+ return false;
810
+ }
811
+ const finalDroppingItem = { ...droppingItem, ...onDragOverResult };
812
+ const gridRect = e.currentTarget.getBoundingClientRect();
813
+ const layerX = e.clientX - gridRect.left;
814
+ const layerY = e.clientY - gridRect.top;
815
+ const newDroppingPosition = {
816
+ left: layerX / transformScale,
817
+ top: layerY / transformScale,
818
+ e: e.nativeEvent
819
+ };
820
+ if (!droppingDOMNode) {
821
+ const positionParams = {
822
+ cols,
823
+ margin,
824
+ maxRows,
825
+ rowHeight,
826
+ containerWidth: width,
827
+ containerPadding: effectiveContainerPadding
828
+ };
829
+ const calculatedPosition = calcXY(
830
+ positionParams,
831
+ layerY,
832
+ layerX,
833
+ finalDroppingItem.w,
834
+ finalDroppingItem.h
835
+ );
836
+ setDroppingDOMNode(/* @__PURE__ */ jsx("div", {}, finalDroppingItem.i));
837
+ setDroppingPosition(newDroppingPosition);
838
+ setLayout([
839
+ ...layout,
840
+ {
841
+ ...finalDroppingItem,
842
+ x: calculatedPosition.x,
843
+ y: calculatedPosition.y,
844
+ static: false,
845
+ isDraggable: true
846
+ }
847
+ ]);
848
+ } else if (droppingPosition) {
849
+ const shouldUpdate = droppingPosition.left !== layerX || droppingPosition.top !== layerY;
850
+ if (shouldUpdate) {
851
+ setDroppingPosition(newDroppingPosition);
852
+ }
853
+ }
854
+ },
855
+ [
856
+ droppingDOMNode,
857
+ droppingPosition,
858
+ droppingItem,
859
+ onDropDragOverProp,
860
+ removeDroppingPlaceholder,
861
+ transformScale,
862
+ cols,
863
+ margin,
864
+ maxRows,
865
+ rowHeight,
866
+ width,
867
+ effectiveContainerPadding,
868
+ layout
869
+ ]
870
+ );
871
+ const handleDragLeave = useCallback(
872
+ (e) => {
873
+ e.preventDefault();
874
+ e.stopPropagation();
875
+ dragEnterCounterRef.current--;
876
+ if (dragEnterCounterRef.current === 0) {
877
+ removeDroppingPlaceholder();
878
+ }
879
+ },
880
+ [removeDroppingPlaceholder]
881
+ );
882
+ const handleDragEnter = useCallback((e) => {
883
+ e.preventDefault();
884
+ e.stopPropagation();
885
+ dragEnterCounterRef.current++;
886
+ }, []);
887
+ const handleDrop = useCallback(
888
+ (e) => {
889
+ e.preventDefault();
890
+ e.stopPropagation();
891
+ const item = layout.find((l) => l.i === droppingItem.i);
892
+ dragEnterCounterRef.current = 0;
893
+ removeDroppingPlaceholder();
894
+ onDropProp(layout, item, e.nativeEvent);
895
+ },
896
+ [layout, droppingItem.i, removeDroppingPlaceholder, onDropProp]
897
+ );
898
+ const processGridItem = useCallback(
899
+ (child, isDroppingItem) => {
900
+ if (!child || !child.key) return null;
901
+ const l = getLayoutItem(layout, String(child.key));
902
+ if (!l) return null;
903
+ const draggable = typeof l.isDraggable === "boolean" ? l.isDraggable : !l.static && isDraggable;
904
+ const resizable = typeof l.isResizable === "boolean" ? l.isResizable : !l.static && isResizable;
905
+ const resizeHandlesOptions = l.resizeHandles || [...resizeHandles];
906
+ const bounded = draggable && isBounded && l.isBounded !== false;
907
+ const resizeHandleElement = resizeHandle;
908
+ return /* @__PURE__ */ jsx(
909
+ GridItem,
910
+ {
911
+ containerWidth: width,
912
+ cols,
913
+ margin,
914
+ containerPadding: effectiveContainerPadding,
915
+ maxRows,
916
+ rowHeight,
917
+ cancel: draggableCancel,
918
+ handle: draggableHandle,
919
+ onDragStart,
920
+ onDrag,
921
+ onDragStop,
922
+ onResizeStart,
923
+ onResize,
924
+ onResizeStop,
925
+ isDraggable: draggable,
926
+ isResizable: resizable,
927
+ isBounded: bounded,
928
+ useCSSTransforms: useCSSTransforms && mounted,
929
+ usePercentages: !mounted,
930
+ transformScale,
931
+ w: l.w,
932
+ h: l.h,
933
+ x: l.x,
934
+ y: l.y,
935
+ i: l.i,
936
+ minH: l.minH,
937
+ minW: l.minW,
938
+ maxH: l.maxH,
939
+ maxW: l.maxW,
940
+ static: l.static,
941
+ droppingPosition: isDroppingItem ? droppingPosition : void 0,
942
+ resizeHandles: resizeHandlesOptions,
943
+ resizeHandle: resizeHandleElement,
944
+ children: child
945
+ },
946
+ l.i
947
+ );
948
+ },
949
+ [
950
+ layout,
951
+ width,
952
+ cols,
953
+ margin,
954
+ effectiveContainerPadding,
955
+ maxRows,
956
+ rowHeight,
957
+ draggableCancel,
958
+ draggableHandle,
959
+ onDragStart,
960
+ onDrag,
961
+ onDragStop,
962
+ onResizeStart,
963
+ onResize,
964
+ onResizeStop,
965
+ isDraggable,
966
+ isResizable,
967
+ isBounded,
968
+ useCSSTransforms,
969
+ mounted,
970
+ transformScale,
971
+ droppingPosition,
972
+ resizeHandles,
973
+ resizeHandle
974
+ ]
975
+ );
976
+ const renderPlaceholder = () => {
977
+ if (!activeDrag) return null;
978
+ return /* @__PURE__ */ jsx(
979
+ GridItem,
980
+ {
981
+ w: activeDrag.w,
982
+ h: activeDrag.h,
983
+ x: activeDrag.x,
984
+ y: activeDrag.y,
985
+ i: activeDrag.i,
986
+ className: `react-grid-placeholder ${resizing ? "placeholder-resizing" : ""}`,
987
+ containerWidth: width,
988
+ cols,
989
+ margin,
990
+ containerPadding: effectiveContainerPadding,
991
+ maxRows,
992
+ rowHeight,
993
+ isDraggable: false,
994
+ isResizable: false,
995
+ isBounded: false,
996
+ useCSSTransforms,
997
+ transformScale,
998
+ children: /* @__PURE__ */ jsx("div", {})
999
+ }
1000
+ );
1001
+ };
1002
+ const mergedClassName = clsx(layoutClassName, className);
1003
+ const mergedStyle = {
1004
+ height: containerHeight,
1005
+ ...style
1006
+ };
1007
+ return /* @__PURE__ */ jsxs(
1008
+ "div",
1009
+ {
1010
+ ref: innerRef,
1011
+ className: mergedClassName,
1012
+ style: mergedStyle,
1013
+ onDrop: isDroppable ? handleDrop : void 0,
1014
+ onDragLeave: isDroppable ? handleDragLeave : void 0,
1015
+ onDragEnter: isDroppable ? handleDragEnter : void 0,
1016
+ onDragOver: isDroppable ? handleDragOver : void 0,
1017
+ children: [
1018
+ React2.Children.map(children, (child) => {
1019
+ if (!React2.isValidElement(child)) return null;
1020
+ return processGridItem(child);
1021
+ }),
1022
+ isDroppable && droppingDOMNode && processGridItem(droppingDOMNode, true),
1023
+ renderPlaceholder()
1024
+ ]
1025
+ }
1026
+ );
1027
+ }
1028
+ var DEFAULT_BREAKPOINTS = {
1029
+ lg: 1200,
1030
+ md: 996,
1031
+ sm: 768,
1032
+ xs: 480,
1033
+ xxs: 0
1034
+ };
1035
+ var DEFAULT_COLS = {
1036
+ lg: 12,
1037
+ md: 10,
1038
+ sm: 6,
1039
+ xs: 4,
1040
+ xxs: 2
1041
+ };
1042
+ var noop2 = () => {
1043
+ };
1044
+ function synchronizeLayoutWithChildren2(initialLayout, children, cols, compactType, allowOverlap) {
1045
+ const layout = [];
1046
+ React2.Children.forEach(children, (child) => {
1047
+ if (!React2.isValidElement(child) || child.key === null) return;
1048
+ const key = String(child.key);
1049
+ const existingItem = initialLayout.find((l) => l.i === key);
1050
+ if (existingItem) {
1051
+ layout.push({
1052
+ ...existingItem,
1053
+ i: key
1054
+ });
1055
+ } else {
1056
+ const childProps = child.props;
1057
+ const dataGrid = childProps["data-grid"];
1058
+ if (dataGrid) {
1059
+ layout.push({
1060
+ i: key,
1061
+ x: dataGrid.x ?? 0,
1062
+ y: dataGrid.y ?? 0,
1063
+ w: dataGrid.w ?? 1,
1064
+ h: dataGrid.h ?? 1,
1065
+ minW: dataGrid.minW,
1066
+ maxW: dataGrid.maxW,
1067
+ minH: dataGrid.minH,
1068
+ maxH: dataGrid.maxH,
1069
+ static: dataGrid.static,
1070
+ isDraggable: dataGrid.isDraggable,
1071
+ isResizable: dataGrid.isResizable,
1072
+ resizeHandles: dataGrid.resizeHandles,
1073
+ isBounded: dataGrid.isBounded
1074
+ });
1075
+ } else {
1076
+ layout.push({
1077
+ i: key,
1078
+ x: 0,
1079
+ y: bottom(layout),
1080
+ w: 1,
1081
+ h: 1
1082
+ });
1083
+ }
1084
+ }
1085
+ });
1086
+ const corrected = correctBounds(layout, { cols });
1087
+ return compact(corrected, compactType, cols, allowOverlap);
1088
+ }
1089
+ function ResponsiveGridLayout(props) {
1090
+ const {
1091
+ children,
1092
+ width,
1093
+ breakpoint: propBreakpoint,
1094
+ breakpoints = DEFAULT_BREAKPOINTS,
1095
+ cols: colsConfig = DEFAULT_COLS,
1096
+ layouts: propsLayouts = {},
1097
+ rowHeight = 150,
1098
+ maxRows = Infinity,
1099
+ margin: propMargin = [10, 10],
1100
+ containerPadding: propContainerPadding = null,
1101
+ compactor: compactorProp,
1102
+ onBreakpointChange = noop2,
1103
+ onLayoutChange = noop2,
1104
+ onWidthChange = noop2,
1105
+ ...restProps
1106
+ } = props;
1107
+ const compactor = compactorProp ?? getCompactor("vertical");
1108
+ const compactType = compactor.type;
1109
+ const allowOverlap = compactor.allowOverlap;
1110
+ const initialBreakpoint = useMemo(() => {
1111
+ return propBreakpoint ?? getBreakpointFromWidth(breakpoints, width);
1112
+ }, []);
1113
+ const initialCols = useMemo(() => {
1114
+ return getColsFromBreakpoint(initialBreakpoint, colsConfig);
1115
+ }, [initialBreakpoint, colsConfig]);
1116
+ const initialLayout = useMemo(() => {
1117
+ return findOrGenerateResponsiveLayout(
1118
+ propsLayouts,
1119
+ breakpoints,
1120
+ initialBreakpoint,
1121
+ initialBreakpoint,
1122
+ initialCols,
1123
+ compactType
1124
+ );
1125
+ }, []);
1126
+ const [breakpoint, setBreakpoint] = useState(initialBreakpoint);
1127
+ const [cols, setCols] = useState(initialCols);
1128
+ const [layout, setLayout] = useState(initialLayout);
1129
+ const [layouts, setLayouts] = useState(propsLayouts);
1130
+ const prevWidthRef = useRef(width);
1131
+ const prevBreakpointRef = useRef(propBreakpoint);
1132
+ const prevBreakpointsRef = useRef(breakpoints);
1133
+ const prevColsRef = useRef(colsConfig);
1134
+ const prevLayoutsRef = useRef(propsLayouts);
1135
+ const prevCompactTypeRef = useRef(compactType);
1136
+ useEffect(() => {
1137
+ if (!deepEqual(propsLayouts, prevLayoutsRef.current)) {
1138
+ const newLayout = findOrGenerateResponsiveLayout(
1139
+ propsLayouts,
1140
+ breakpoints,
1141
+ breakpoint,
1142
+ breakpoint,
1143
+ cols,
1144
+ compactType
1145
+ );
1146
+ setLayout(newLayout);
1147
+ setLayouts(propsLayouts);
1148
+ prevLayoutsRef.current = propsLayouts;
1149
+ }
1150
+ }, [propsLayouts, breakpoints, breakpoint, cols, compactType]);
1151
+ useEffect(() => {
1152
+ if (compactType !== prevCompactTypeRef.current) {
1153
+ const newLayout = compact(
1154
+ cloneLayout(layout),
1155
+ compactType,
1156
+ cols,
1157
+ allowOverlap
1158
+ );
1159
+ const newLayouts = {
1160
+ ...layouts,
1161
+ [breakpoint]: newLayout
1162
+ };
1163
+ setLayout(newLayout);
1164
+ setLayouts(newLayouts);
1165
+ onLayoutChange(newLayout, newLayouts);
1166
+ prevCompactTypeRef.current = compactType;
1167
+ }
1168
+ }, [
1169
+ compactType,
1170
+ layout,
1171
+ cols,
1172
+ allowOverlap,
1173
+ layouts,
1174
+ breakpoint,
1175
+ onLayoutChange
1176
+ ]);
1177
+ useEffect(() => {
1178
+ const widthChanged = width !== prevWidthRef.current;
1179
+ const breakpointPropChanged = propBreakpoint !== prevBreakpointRef.current;
1180
+ const breakpointsChanged = !deepEqual(
1181
+ breakpoints,
1182
+ prevBreakpointsRef.current
1183
+ );
1184
+ const colsChanged = !deepEqual(colsConfig, prevColsRef.current);
1185
+ if (widthChanged || breakpointPropChanged || breakpointsChanged || colsChanged) {
1186
+ const newBreakpoint = propBreakpoint ?? getBreakpointFromWidth(breakpoints, width);
1187
+ const newCols = getColsFromBreakpoint(newBreakpoint, colsConfig);
1188
+ const lastBreakpoint = breakpoint;
1189
+ if (lastBreakpoint !== newBreakpoint || breakpointsChanged || colsChanged) {
1190
+ const newLayouts = { ...layouts };
1191
+ if (!newLayouts[lastBreakpoint]) {
1192
+ newLayouts[lastBreakpoint] = cloneLayout(layout);
1193
+ }
1194
+ let newLayout = findOrGenerateResponsiveLayout(
1195
+ newLayouts,
1196
+ breakpoints,
1197
+ newBreakpoint,
1198
+ lastBreakpoint,
1199
+ newCols,
1200
+ compactType
1201
+ );
1202
+ newLayout = synchronizeLayoutWithChildren2(
1203
+ newLayout,
1204
+ children,
1205
+ newCols,
1206
+ compactType,
1207
+ allowOverlap
1208
+ );
1209
+ newLayouts[newBreakpoint] = newLayout;
1210
+ setBreakpoint(newBreakpoint);
1211
+ setCols(newCols);
1212
+ setLayout(newLayout);
1213
+ setLayouts(newLayouts);
1214
+ onBreakpointChange(newBreakpoint, newCols);
1215
+ onLayoutChange(newLayout, newLayouts);
1216
+ }
1217
+ const currentMargin2 = getIndentationValue(
1218
+ propMargin,
1219
+ newBreakpoint
1220
+ );
1221
+ const currentPadding = propContainerPadding ? getIndentationValue(
1222
+ propContainerPadding,
1223
+ newBreakpoint
1224
+ ) : null;
1225
+ onWidthChange(width, currentMargin2, newCols, currentPadding);
1226
+ prevWidthRef.current = width;
1227
+ prevBreakpointRef.current = propBreakpoint;
1228
+ prevBreakpointsRef.current = breakpoints;
1229
+ prevColsRef.current = colsConfig;
1230
+ }
1231
+ }, [
1232
+ width,
1233
+ propBreakpoint,
1234
+ breakpoints,
1235
+ colsConfig,
1236
+ breakpoint,
1237
+ cols,
1238
+ layout,
1239
+ layouts,
1240
+ children,
1241
+ compactType,
1242
+ allowOverlap,
1243
+ propMargin,
1244
+ propContainerPadding,
1245
+ onBreakpointChange,
1246
+ onLayoutChange,
1247
+ onWidthChange
1248
+ ]);
1249
+ const handleLayoutChange = useCallback(
1250
+ (newLayout) => {
1251
+ const newLayouts = {
1252
+ ...layouts,
1253
+ [breakpoint]: newLayout
1254
+ };
1255
+ setLayout(newLayout);
1256
+ setLayouts(newLayouts);
1257
+ onLayoutChange(newLayout, newLayouts);
1258
+ },
1259
+ [layouts, breakpoint, onLayoutChange]
1260
+ );
1261
+ const currentMargin = useMemo(() => {
1262
+ return getIndentationValue(
1263
+ propMargin,
1264
+ breakpoint
1265
+ );
1266
+ }, [propMargin, breakpoint]);
1267
+ const currentContainerPadding = useMemo(() => {
1268
+ if (propContainerPadding === null) return null;
1269
+ return getIndentationValue(
1270
+ propContainerPadding,
1271
+ breakpoint
1272
+ );
1273
+ }, [propContainerPadding, breakpoint]);
1274
+ const gridConfig = useMemo(
1275
+ () => ({
1276
+ cols,
1277
+ rowHeight,
1278
+ maxRows,
1279
+ margin: currentMargin,
1280
+ containerPadding: currentContainerPadding
1281
+ }),
1282
+ [cols, rowHeight, maxRows, currentMargin, currentContainerPadding]
1283
+ );
1284
+ return /* @__PURE__ */ jsx(
1285
+ GridLayout,
1286
+ {
1287
+ ...restProps,
1288
+ width,
1289
+ gridConfig,
1290
+ compactor,
1291
+ onLayoutChange: handleLayoutChange,
1292
+ layout,
1293
+ children
1294
+ }
1295
+ );
1296
+ }
1297
+
1298
+ export { GridItem, GridLayout, ResponsiveGridLayout };
1299
+ //# sourceMappingURL=chunk-R35HZZTA.mjs.map
1300
+ //# sourceMappingURL=chunk-R35HZZTA.mjs.map