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