react-grid-layout 2.0.0 → 2.1.1
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.
- package/README.md +117 -28
- package/css/styles.css +0 -1
- package/dist/{ResponsiveGridLayout-D6lFRE3f.d.mts → ResponsiveGridLayout-BkHF9YHa.d.mts} +10 -1
- package/dist/{ResponsiveGridLayout-CH4s0tKj.d.ts → ResponsiveGridLayout-CLn16-X3.d.ts} +10 -1
- package/dist/{calculate-CwYDW8na.d.mts → calculate-DsVTldEE.d.ts} +30 -2
- package/dist/{calculate-mgLpNJ5O.d.ts → calculate-DwbL1D06.d.mts} +30 -2
- package/dist/chunk-526JND3R.mjs +3 -0
- package/dist/{chunk-ZWN22PS2.mjs.map → chunk-526JND3R.mjs.map} +1 -1
- package/dist/chunk-7ELO5FRW.js +4 -0
- package/dist/{chunk-PBQSHIID.js.map → chunk-7ELO5FRW.js.map} +1 -1
- package/dist/chunk-AWM66AWF.mjs +422 -0
- package/dist/chunk-AWM66AWF.mjs.map +1 -0
- package/dist/chunk-BJFPTW5Q.js +449 -0
- package/dist/chunk-BJFPTW5Q.js.map +1 -0
- package/dist/{chunk-4HNUMWQK.mjs → chunk-FLITZMQC.mjs} +198 -311
- package/dist/chunk-FLITZMQC.mjs.map +1 -0
- package/dist/{chunk-ZCXE6SR5.mjs → chunk-LIKX67MZ.mjs} +7 -5
- package/dist/chunk-LIKX67MZ.mjs.map +1 -0
- package/dist/{chunk-R35HZZTA.mjs → chunk-PLWMASMX.mjs} +208 -90
- package/dist/chunk-PLWMASMX.mjs.map +1 -0
- package/dist/{chunk-BFTKGAP3.js → chunk-RB2IKK5B.js} +260 -142
- package/dist/chunk-RB2IKK5B.js.map +1 -0
- package/dist/{chunk-3WO4SAYB.js → chunk-WWS3M5Y3.js} +238 -355
- package/dist/chunk-WWS3M5Y3.js.map +1 -0
- package/dist/{chunk-H5KMDLY3.js → chunk-YQQYHEEG.js} +43 -41
- package/dist/chunk-YQQYHEEG.js.map +1 -0
- package/dist/core.d.mts +159 -6
- package/dist/core.d.ts +159 -6
- package/dist/core.js +145 -85
- package/dist/core.mjs +3 -3
- package/dist/extras.d.mts +133 -3
- package/dist/extras.d.ts +133 -3
- package/dist/extras.js +373 -2
- package/dist/extras.js.map +1 -1
- package/dist/extras.mjs +367 -2
- package/dist/extras.mjs.map +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +64 -64
- package/dist/index.mjs +5 -5
- package/dist/legacy.d.mts +2 -2
- package/dist/legacy.d.ts +2 -2
- package/dist/legacy.js +26 -25
- package/dist/legacy.js.map +1 -1
- package/dist/legacy.mjs +16 -15
- package/dist/legacy.mjs.map +1 -1
- package/dist/{position-Dk2b4ZMS.d.ts → position-CXNzFxI0.d.mts} +18 -7
- package/dist/{position-BmN1z36J.d.mts → position-Dk0FRWA9.d.ts} +18 -7
- package/dist/react.d.mts +11 -5
- package/dist/react.d.ts +11 -5
- package/dist/react.js +38 -38
- package/dist/react.mjs +5 -5
- package/dist/{responsive-CJxefsYw.d.mts → responsive-BB5d98xz.d.mts} +1 -1
- package/dist/{responsive-C4L1ESlm.d.ts → responsive-BXI-GCXG.d.ts} +1 -1
- package/dist/{types-Cxf4nHNr.d.mts → types-CokovIMH.d.mts} +98 -4
- package/dist/{types-Cxf4nHNr.d.ts → types-CokovIMH.d.ts} +98 -4
- package/index-dev.js +16 -0
- package/package.json +5 -3
- package/dist/chunk-2KUHNJXF.mjs +0 -90
- package/dist/chunk-2KUHNJXF.mjs.map +0 -1
- package/dist/chunk-3WO4SAYB.js.map +0 -1
- package/dist/chunk-4HNUMWQK.mjs.map +0 -1
- package/dist/chunk-BFTKGAP3.js.map +0 -1
- package/dist/chunk-F6NQPYKT.js +0 -98
- package/dist/chunk-F6NQPYKT.js.map +0 -1
- package/dist/chunk-H5KMDLY3.js.map +0 -1
- package/dist/chunk-PBQSHIID.js +0 -4
- package/dist/chunk-R35HZZTA.mjs.map +0 -1
- package/dist/chunk-ZCXE6SR5.mjs.map +0 -1
- package/dist/chunk-ZWN22PS2.mjs +0 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setTransform, setTopLeft, perc, resizeItemInDirection, defaultPositionStrategy, defaultGridConfig, defaultDragConfig, defaultResizeConfig, defaultDropConfig, getCompactor,
|
|
2
|
-
import {
|
|
1
|
+
import { defaultConstraints, setTransform, setTopLeft, perc, applyPositionConstraints, resizeItemInDirection, applySizeConstraints, defaultPositionStrategy, defaultGridConfig, defaultDragConfig, defaultResizeConfig, defaultDropConfig, getCompactor, compact, getBreakpointFromWidth, getColsFromBreakpoint, findOrGenerateResponsiveLayout, getIndentationValue } from './chunk-FLITZMQC.mjs';
|
|
2
|
+
import { calcXYRaw, calcGridItemWHPx, clamp, calcGridColWidth, calcWHRaw, calcGridItemPosition, bottom, getLayoutItem, cloneLayoutItem, moveElement, withLayoutItem, getAllCollisions, calcXY, cloneLayout, correctBounds } from './chunk-AWM66AWF.mjs';
|
|
3
3
|
import React2, { useState, useRef, useMemo, useCallback, useEffect } from 'react';
|
|
4
4
|
import { DraggableCore } from 'react-draggable';
|
|
5
5
|
import { Resizable } from 'react-resizable';
|
|
@@ -39,6 +39,9 @@ function GridItem(props) {
|
|
|
39
39
|
i,
|
|
40
40
|
resizeHandles,
|
|
41
41
|
resizeHandle,
|
|
42
|
+
constraints = defaultConstraints,
|
|
43
|
+
layoutItem,
|
|
44
|
+
layout = [],
|
|
42
45
|
onDragStart: onDragStartProp,
|
|
43
46
|
onDrag: onDragProp,
|
|
44
47
|
onDragStop: onDragStopProp,
|
|
@@ -70,6 +73,33 @@ function GridItem(props) {
|
|
|
70
73
|
}),
|
|
71
74
|
[cols, containerPadding, containerWidth, margin, maxRows, rowHeight]
|
|
72
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
|
+
);
|
|
73
103
|
const createStyle = useCallback(
|
|
74
104
|
(pos2) => {
|
|
75
105
|
if (useCSSTransforms) {
|
|
@@ -104,12 +134,17 @@ function GridItem(props) {
|
|
|
104
134
|
};
|
|
105
135
|
dragPositionRef.current = newPosition;
|
|
106
136
|
setDragging(true);
|
|
107
|
-
const
|
|
137
|
+
const rawPos = calcXYRaw(
|
|
108
138
|
positionParams,
|
|
109
139
|
newPosition.top,
|
|
110
|
-
newPosition.left
|
|
111
|
-
|
|
112
|
-
|
|
140
|
+
newPosition.left
|
|
141
|
+
);
|
|
142
|
+
const { x: newX, y: newY } = applyPositionConstraints(
|
|
143
|
+
constraints,
|
|
144
|
+
effectiveLayoutItem,
|
|
145
|
+
rawPos.x,
|
|
146
|
+
rawPos.y,
|
|
147
|
+
constraintContext
|
|
113
148
|
);
|
|
114
149
|
onDragStartProp(i, newX, newY, {
|
|
115
150
|
e,
|
|
@@ -117,7 +152,15 @@ function GridItem(props) {
|
|
|
117
152
|
newPosition
|
|
118
153
|
});
|
|
119
154
|
},
|
|
120
|
-
[
|
|
155
|
+
[
|
|
156
|
+
onDragStartProp,
|
|
157
|
+
transformScale,
|
|
158
|
+
positionParams,
|
|
159
|
+
constraints,
|
|
160
|
+
effectiveLayoutItem,
|
|
161
|
+
constraintContext,
|
|
162
|
+
i
|
|
163
|
+
]
|
|
121
164
|
);
|
|
122
165
|
const onDrag = useCallback(
|
|
123
166
|
(e, { node, deltaX, deltaY }) => {
|
|
@@ -136,7 +179,14 @@ function GridItem(props) {
|
|
|
136
179
|
}
|
|
137
180
|
const newPosition = { top, left };
|
|
138
181
|
dragPositionRef.current = newPosition;
|
|
139
|
-
const
|
|
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
|
+
);
|
|
140
190
|
onDragProp(i, newX, newY, {
|
|
141
191
|
e,
|
|
142
192
|
node,
|
|
@@ -153,7 +203,10 @@ function GridItem(props) {
|
|
|
153
203
|
positionParams,
|
|
154
204
|
containerWidth,
|
|
155
205
|
w,
|
|
156
|
-
i
|
|
206
|
+
i,
|
|
207
|
+
constraints,
|
|
208
|
+
effectiveLayoutItem,
|
|
209
|
+
constraintContext
|
|
157
210
|
]
|
|
158
211
|
);
|
|
159
212
|
const onDragStop = useCallback(
|
|
@@ -163,14 +216,29 @@ function GridItem(props) {
|
|
|
163
216
|
const newPosition = { top, left };
|
|
164
217
|
setDragging(false);
|
|
165
218
|
dragPositionRef.current = { left: 0, top: 0 };
|
|
166
|
-
const
|
|
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
|
+
);
|
|
167
227
|
onDragStopProp(i, newX, newY, {
|
|
168
228
|
e,
|
|
169
229
|
node,
|
|
170
230
|
newPosition
|
|
171
231
|
});
|
|
172
232
|
},
|
|
173
|
-
[
|
|
233
|
+
[
|
|
234
|
+
onDragStopProp,
|
|
235
|
+
dragging,
|
|
236
|
+
positionParams,
|
|
237
|
+
constraints,
|
|
238
|
+
effectiveLayoutItem,
|
|
239
|
+
constraintContext,
|
|
240
|
+
i
|
|
241
|
+
]
|
|
174
242
|
);
|
|
175
243
|
const onResizeHandler = useCallback(
|
|
176
244
|
(e, { node, size, handle: resizeHandle2 }, position, handlerName) => {
|
|
@@ -192,16 +260,19 @@ function GridItem(props) {
|
|
|
192
260
|
};
|
|
193
261
|
}
|
|
194
262
|
resizePositionRef.current = updatedSize;
|
|
195
|
-
|
|
263
|
+
const rawSize = calcWHRaw(
|
|
196
264
|
positionParams,
|
|
197
265
|
updatedSize.width,
|
|
198
|
-
updatedSize.height
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
|
202
275
|
);
|
|
203
|
-
newW = clamp(newW, Math.max(minW, 1), maxW);
|
|
204
|
-
newH = clamp(newH, minH, maxH);
|
|
205
276
|
handler(i, newW, newH, {
|
|
206
277
|
e: e.nativeEvent,
|
|
207
278
|
node,
|
|
@@ -217,11 +288,10 @@ function GridItem(props) {
|
|
|
217
288
|
positionParams,
|
|
218
289
|
x,
|
|
219
290
|
y,
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
i
|
|
291
|
+
i,
|
|
292
|
+
constraints,
|
|
293
|
+
effectiveLayoutItem,
|
|
294
|
+
constraintContext
|
|
225
295
|
]
|
|
226
296
|
);
|
|
227
297
|
const handleResizeStart = useCallback(
|
|
@@ -306,14 +376,12 @@ function GridItem(props) {
|
|
|
306
376
|
resizing ? resizePositionRef.current : null
|
|
307
377
|
);
|
|
308
378
|
const child = React2.Children.only(children);
|
|
309
|
-
const
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const maxConstraints = [
|
|
314
|
-
Math.min(maxes.width, maxWidth),
|
|
315
|
-
Math.min(maxes.height, Infinity)
|
|
379
|
+
const minGridUnit = calcGridItemPosition(positionParams, 0, 0, 1, 1);
|
|
380
|
+
const minConstraints = [
|
|
381
|
+
minGridUnit.width,
|
|
382
|
+
minGridUnit.height
|
|
316
383
|
];
|
|
384
|
+
const maxConstraints = [Infinity, Infinity];
|
|
317
385
|
const childProps = child.props;
|
|
318
386
|
const childClassName = childProps["className"];
|
|
319
387
|
const childStyle = childProps["style"];
|
|
@@ -443,6 +511,7 @@ function GridLayout(props) {
|
|
|
443
511
|
dropConfig: dropConfigProp,
|
|
444
512
|
positionStrategy = defaultPositionStrategy,
|
|
445
513
|
compactor: compactorProp,
|
|
514
|
+
constraints = defaultConstraints,
|
|
446
515
|
// Layout data
|
|
447
516
|
layout: propsLayout = [],
|
|
448
517
|
droppingItem: droppingItemProp,
|
|
@@ -529,6 +598,8 @@ function GridLayout(props) {
|
|
|
529
598
|
const prevPropsLayoutRef = useRef(propsLayout);
|
|
530
599
|
const prevChildrenRef = useRef(children);
|
|
531
600
|
const prevCompactTypeRef = useRef(compactType);
|
|
601
|
+
const layoutRef = useRef(layout);
|
|
602
|
+
layoutRef.current = layout;
|
|
532
603
|
useEffect(() => {
|
|
533
604
|
setMounted(true);
|
|
534
605
|
if (!deepEqual(layout, propsLayout)) {
|
|
@@ -537,6 +608,7 @@ function GridLayout(props) {
|
|
|
537
608
|
}, []);
|
|
538
609
|
useEffect(() => {
|
|
539
610
|
if (activeDrag) return;
|
|
611
|
+
if (droppingDOMNode) return;
|
|
540
612
|
const layoutChanged = !deepEqual(propsLayout, prevPropsLayoutRef.current);
|
|
541
613
|
const childrenChanged = !childrenEqual(children, prevChildrenRef.current);
|
|
542
614
|
const compactTypeChanged = compactType !== prevCompactTypeRef.current;
|
|
@@ -561,6 +633,7 @@ function GridLayout(props) {
|
|
|
561
633
|
compactType,
|
|
562
634
|
allowOverlap,
|
|
563
635
|
activeDrag,
|
|
636
|
+
droppingDOMNode,
|
|
564
637
|
layout
|
|
565
638
|
]);
|
|
566
639
|
useEffect(() => {
|
|
@@ -577,7 +650,8 @@ function GridLayout(props) {
|
|
|
577
650
|
}, [autoSize, layout, rowHeight, margin, effectiveContainerPadding]);
|
|
578
651
|
const onDragStart = useCallback(
|
|
579
652
|
(i, _x, _y, data) => {
|
|
580
|
-
const
|
|
653
|
+
const currentLayout = layoutRef.current;
|
|
654
|
+
const l = getLayoutItem(currentLayout, i);
|
|
581
655
|
if (!l) return;
|
|
582
656
|
const placeholder = {
|
|
583
657
|
w: l.w,
|
|
@@ -587,16 +661,17 @@ function GridLayout(props) {
|
|
|
587
661
|
i
|
|
588
662
|
};
|
|
589
663
|
oldDragItemRef.current = cloneLayoutItem(l);
|
|
590
|
-
oldLayoutRef.current =
|
|
664
|
+
oldLayoutRef.current = currentLayout;
|
|
591
665
|
setActiveDrag(placeholder);
|
|
592
|
-
onDragStartProp(
|
|
666
|
+
onDragStartProp(currentLayout, l, l, null, data.e, data.node);
|
|
593
667
|
},
|
|
594
|
-
[
|
|
668
|
+
[onDragStartProp]
|
|
595
669
|
);
|
|
596
670
|
const onDrag = useCallback(
|
|
597
671
|
(i, x, y, data) => {
|
|
672
|
+
const currentLayout = layoutRef.current;
|
|
598
673
|
const oldDragItem = oldDragItemRef.current;
|
|
599
|
-
const l = getLayoutItem(
|
|
674
|
+
const l = getLayoutItem(currentLayout, i);
|
|
600
675
|
if (!l) return;
|
|
601
676
|
const placeholder = {
|
|
602
677
|
w: l.w,
|
|
@@ -606,7 +681,7 @@ function GridLayout(props) {
|
|
|
606
681
|
i
|
|
607
682
|
};
|
|
608
683
|
const newLayout = moveElement(
|
|
609
|
-
|
|
684
|
+
currentLayout,
|
|
610
685
|
l,
|
|
611
686
|
x,
|
|
612
687
|
y,
|
|
@@ -622,16 +697,17 @@ function GridLayout(props) {
|
|
|
622
697
|
);
|
|
623
698
|
setActiveDrag(placeholder);
|
|
624
699
|
},
|
|
625
|
-
[
|
|
700
|
+
[preventCollision, compactType, cols, allowOverlap, onDragProp]
|
|
626
701
|
);
|
|
627
702
|
const onDragStop = useCallback(
|
|
628
703
|
(i, x, y, data) => {
|
|
629
704
|
if (!activeDrag) return;
|
|
705
|
+
const currentLayout = layoutRef.current;
|
|
630
706
|
const oldDragItem = oldDragItemRef.current;
|
|
631
|
-
const l = getLayoutItem(
|
|
707
|
+
const l = getLayoutItem(currentLayout, i);
|
|
632
708
|
if (!l) return;
|
|
633
709
|
const newLayout = moveElement(
|
|
634
|
-
|
|
710
|
+
currentLayout,
|
|
635
711
|
l,
|
|
636
712
|
x,
|
|
637
713
|
y,
|
|
@@ -654,7 +730,6 @@ function GridLayout(props) {
|
|
|
654
730
|
},
|
|
655
731
|
[
|
|
656
732
|
activeDrag,
|
|
657
|
-
layout,
|
|
658
733
|
preventCollision,
|
|
659
734
|
compactType,
|
|
660
735
|
cols,
|
|
@@ -665,23 +740,25 @@ function GridLayout(props) {
|
|
|
665
740
|
);
|
|
666
741
|
const onResizeStart = useCallback(
|
|
667
742
|
(i, _w, _h, data) => {
|
|
668
|
-
const
|
|
743
|
+
const currentLayout = layoutRef.current;
|
|
744
|
+
const l = getLayoutItem(currentLayout, i);
|
|
669
745
|
if (!l) return;
|
|
670
746
|
oldResizeItemRef.current = cloneLayoutItem(l);
|
|
671
|
-
oldLayoutRef.current =
|
|
747
|
+
oldLayoutRef.current = currentLayout;
|
|
672
748
|
setResizing(true);
|
|
673
|
-
onResizeStartProp(
|
|
749
|
+
onResizeStartProp(currentLayout, l, l, null, data.e, data.node);
|
|
674
750
|
},
|
|
675
|
-
[
|
|
751
|
+
[onResizeStartProp]
|
|
676
752
|
);
|
|
677
753
|
const onResize = useCallback(
|
|
678
754
|
(i, w, h, data) => {
|
|
755
|
+
const currentLayout = layoutRef.current;
|
|
679
756
|
const oldResizeItem = oldResizeItemRef.current;
|
|
680
757
|
const { handle } = data;
|
|
681
758
|
let shouldMoveItem = false;
|
|
682
759
|
let newX;
|
|
683
760
|
let newY;
|
|
684
|
-
const [newLayout, l] = withLayoutItem(
|
|
761
|
+
const [newLayout, l] = withLayoutItem(currentLayout, i, (item) => {
|
|
685
762
|
newX = item.x;
|
|
686
763
|
newY = item.y;
|
|
687
764
|
if (["sw", "w", "nw", "n", "ne"].includes(handle)) {
|
|
@@ -698,7 +775,7 @@ function GridLayout(props) {
|
|
|
698
775
|
shouldMoveItem = true;
|
|
699
776
|
}
|
|
700
777
|
if (preventCollision && !allowOverlap) {
|
|
701
|
-
const collisions = getAllCollisions(
|
|
778
|
+
const collisions = getAllCollisions(currentLayout, {
|
|
702
779
|
...item,
|
|
703
780
|
w,
|
|
704
781
|
h,
|
|
@@ -753,13 +830,14 @@ function GridLayout(props) {
|
|
|
753
830
|
);
|
|
754
831
|
setActiveDrag(placeholder);
|
|
755
832
|
},
|
|
756
|
-
[
|
|
833
|
+
[preventCollision, allowOverlap, compactType, cols, onResizeProp]
|
|
757
834
|
);
|
|
758
835
|
const onResizeStop = useCallback(
|
|
759
836
|
(i, _w, _h, data) => {
|
|
837
|
+
const currentLayout = layoutRef.current;
|
|
760
838
|
const oldResizeItem = oldResizeItemRef.current;
|
|
761
|
-
const l = getLayoutItem(
|
|
762
|
-
const finalLayout = allowOverlap ?
|
|
839
|
+
const l = getLayoutItem(currentLayout, i);
|
|
840
|
+
const finalLayout = allowOverlap ? currentLayout : compact(currentLayout, compactType, cols);
|
|
763
841
|
onResizeStopProp(
|
|
764
842
|
finalLayout,
|
|
765
843
|
oldResizeItem,
|
|
@@ -778,11 +856,12 @@ function GridLayout(props) {
|
|
|
778
856
|
onLayoutChange(finalLayout);
|
|
779
857
|
}
|
|
780
858
|
},
|
|
781
|
-
[
|
|
859
|
+
[allowOverlap, compactType, cols, onResizeStopProp, onLayoutChange]
|
|
782
860
|
);
|
|
783
861
|
const removeDroppingPlaceholder = useCallback(() => {
|
|
862
|
+
const currentLayout = layoutRef.current;
|
|
784
863
|
const newLayout = compact(
|
|
785
|
-
|
|
864
|
+
currentLayout.filter((l) => l.i !== droppingItem.i),
|
|
786
865
|
compactType,
|
|
787
866
|
cols,
|
|
788
867
|
allowOverlap
|
|
@@ -791,7 +870,7 @@ function GridLayout(props) {
|
|
|
791
870
|
setDroppingDOMNode(null);
|
|
792
871
|
setActiveDrag(null);
|
|
793
872
|
setDroppingPosition(void 0);
|
|
794
|
-
}, [
|
|
873
|
+
}, [droppingItem.i, compactType, cols, allowOverlap]);
|
|
795
874
|
const handleDragOver = useCallback(
|
|
796
875
|
(e) => {
|
|
797
876
|
e.preventDefault();
|
|
@@ -801,42 +880,62 @@ function GridLayout(props) {
|
|
|
801
880
|
)) {
|
|
802
881
|
return false;
|
|
803
882
|
}
|
|
804
|
-
const
|
|
805
|
-
if (
|
|
883
|
+
const rawResult = onDropDragOverProp(e);
|
|
884
|
+
if (rawResult === false) {
|
|
806
885
|
if (droppingDOMNode) {
|
|
807
886
|
removeDroppingPlaceholder();
|
|
808
887
|
}
|
|
809
888
|
return false;
|
|
810
889
|
}
|
|
890
|
+
const {
|
|
891
|
+
dragOffsetX = 0,
|
|
892
|
+
dragOffsetY = 0,
|
|
893
|
+
...onDragOverResult
|
|
894
|
+
} = rawResult ?? {};
|
|
811
895
|
const finalDroppingItem = { ...droppingItem, ...onDragOverResult };
|
|
812
896
|
const gridRect = e.currentTarget.getBoundingClientRect();
|
|
813
|
-
const
|
|
814
|
-
|
|
897
|
+
const positionParams = {
|
|
898
|
+
cols,
|
|
899
|
+
margin,
|
|
900
|
+
maxRows,
|
|
901
|
+
rowHeight,
|
|
902
|
+
containerWidth: width,
|
|
903
|
+
containerPadding: effectiveContainerPadding
|
|
904
|
+
};
|
|
905
|
+
const actualColWidth = calcGridColWidth(positionParams);
|
|
906
|
+
const itemPixelWidth = calcGridItemWHPx(
|
|
907
|
+
finalDroppingItem.w,
|
|
908
|
+
actualColWidth,
|
|
909
|
+
margin[0]
|
|
910
|
+
);
|
|
911
|
+
const itemPixelHeight = calcGridItemWHPx(
|
|
912
|
+
finalDroppingItem.h,
|
|
913
|
+
rowHeight,
|
|
914
|
+
margin[1]
|
|
915
|
+
);
|
|
916
|
+
const itemCenterOffsetX = itemPixelWidth / 2;
|
|
917
|
+
const itemCenterOffsetY = itemPixelHeight / 2;
|
|
918
|
+
const rawGridX = e.clientX - gridRect.left + dragOffsetX - itemCenterOffsetX;
|
|
919
|
+
const rawGridY = e.clientY - gridRect.top + dragOffsetY - itemCenterOffsetY;
|
|
920
|
+
const clampedGridX = Math.max(0, rawGridX);
|
|
921
|
+
const clampedGridY = Math.max(0, rawGridY);
|
|
815
922
|
const newDroppingPosition = {
|
|
816
|
-
left:
|
|
817
|
-
top:
|
|
923
|
+
left: clampedGridX / transformScale,
|
|
924
|
+
top: clampedGridY / transformScale,
|
|
818
925
|
e: e.nativeEvent
|
|
819
926
|
};
|
|
820
927
|
if (!droppingDOMNode) {
|
|
821
|
-
const positionParams = {
|
|
822
|
-
cols,
|
|
823
|
-
margin,
|
|
824
|
-
maxRows,
|
|
825
|
-
rowHeight,
|
|
826
|
-
containerWidth: width,
|
|
827
|
-
containerPadding: effectiveContainerPadding
|
|
828
|
-
};
|
|
829
928
|
const calculatedPosition = calcXY(
|
|
830
929
|
positionParams,
|
|
831
|
-
|
|
832
|
-
|
|
930
|
+
clampedGridY,
|
|
931
|
+
clampedGridX,
|
|
833
932
|
finalDroppingItem.w,
|
|
834
933
|
finalDroppingItem.h
|
|
835
934
|
);
|
|
836
935
|
setDroppingDOMNode(/* @__PURE__ */ jsx("div", {}, finalDroppingItem.i));
|
|
837
936
|
setDroppingPosition(newDroppingPosition);
|
|
838
937
|
setLayout([
|
|
839
|
-
...
|
|
938
|
+
...layoutRef.current,
|
|
840
939
|
{
|
|
841
940
|
...finalDroppingItem,
|
|
842
941
|
x: calculatedPosition.x,
|
|
@@ -846,7 +945,7 @@ function GridLayout(props) {
|
|
|
846
945
|
}
|
|
847
946
|
]);
|
|
848
947
|
} else if (droppingPosition) {
|
|
849
|
-
const shouldUpdate = droppingPosition.left !==
|
|
948
|
+
const shouldUpdate = droppingPosition.left !== newDroppingPosition.left || droppingPosition.top !== newDroppingPosition.top;
|
|
850
949
|
if (shouldUpdate) {
|
|
851
950
|
setDroppingPosition(newDroppingPosition);
|
|
852
951
|
}
|
|
@@ -864,8 +963,7 @@ function GridLayout(props) {
|
|
|
864
963
|
maxRows,
|
|
865
964
|
rowHeight,
|
|
866
965
|
width,
|
|
867
|
-
effectiveContainerPadding
|
|
868
|
-
layout
|
|
966
|
+
effectiveContainerPadding
|
|
869
967
|
]
|
|
870
968
|
);
|
|
871
969
|
const handleDragLeave = useCallback(
|
|
@@ -888,12 +986,13 @@ function GridLayout(props) {
|
|
|
888
986
|
(e) => {
|
|
889
987
|
e.preventDefault();
|
|
890
988
|
e.stopPropagation();
|
|
891
|
-
const
|
|
989
|
+
const currentLayout = layoutRef.current;
|
|
990
|
+
const item = currentLayout.find((l) => l.i === droppingItem.i);
|
|
892
991
|
dragEnterCounterRef.current = 0;
|
|
893
992
|
removeDroppingPlaceholder();
|
|
894
|
-
onDropProp(
|
|
993
|
+
onDropProp(currentLayout, item, e.nativeEvent);
|
|
895
994
|
},
|
|
896
|
-
[
|
|
995
|
+
[droppingItem.i, removeDroppingPlaceholder, onDropProp]
|
|
897
996
|
);
|
|
898
997
|
const processGridItem = useCallback(
|
|
899
998
|
(child, isDroppingItem) => {
|
|
@@ -941,6 +1040,9 @@ function GridLayout(props) {
|
|
|
941
1040
|
droppingPosition: isDroppingItem ? droppingPosition : void 0,
|
|
942
1041
|
resizeHandles: resizeHandlesOptions,
|
|
943
1042
|
resizeHandle: resizeHandleElement,
|
|
1043
|
+
constraints,
|
|
1044
|
+
layoutItem: l,
|
|
1045
|
+
layout,
|
|
944
1046
|
children: child
|
|
945
1047
|
},
|
|
946
1048
|
l.i
|
|
@@ -970,7 +1072,8 @@ function GridLayout(props) {
|
|
|
970
1072
|
transformScale,
|
|
971
1073
|
droppingPosition,
|
|
972
1074
|
resizeHandles,
|
|
973
|
-
resizeHandle
|
|
1075
|
+
resizeHandle,
|
|
1076
|
+
constraints
|
|
974
1077
|
]
|
|
975
1078
|
);
|
|
976
1079
|
const renderPlaceholder = () => {
|
|
@@ -995,6 +1098,8 @@ function GridLayout(props) {
|
|
|
995
1098
|
isBounded: false,
|
|
996
1099
|
useCSSTransforms,
|
|
997
1100
|
transformScale,
|
|
1101
|
+
constraints,
|
|
1102
|
+
layout,
|
|
998
1103
|
children: /* @__PURE__ */ jsx("div", {})
|
|
999
1104
|
}
|
|
1000
1105
|
);
|
|
@@ -1133,9 +1238,13 @@ function ResponsiveGridLayout(props) {
|
|
|
1133
1238
|
const prevColsRef = useRef(colsConfig);
|
|
1134
1239
|
const prevLayoutsRef = useRef(propsLayouts);
|
|
1135
1240
|
const prevCompactTypeRef = useRef(compactType);
|
|
1241
|
+
const layoutsRef = useRef(layouts);
|
|
1136
1242
|
useEffect(() => {
|
|
1243
|
+
layoutsRef.current = layouts;
|
|
1244
|
+
}, [layouts]);
|
|
1245
|
+
const derivedLayout = useMemo(() => {
|
|
1137
1246
|
if (!deepEqual(propsLayouts, prevLayoutsRef.current)) {
|
|
1138
|
-
|
|
1247
|
+
return findOrGenerateResponsiveLayout(
|
|
1139
1248
|
propsLayouts,
|
|
1140
1249
|
breakpoints,
|
|
1141
1250
|
breakpoint,
|
|
@@ -1143,34 +1252,41 @@ function ResponsiveGridLayout(props) {
|
|
|
1143
1252
|
cols,
|
|
1144
1253
|
compactType
|
|
1145
1254
|
);
|
|
1146
|
-
|
|
1255
|
+
}
|
|
1256
|
+
return null;
|
|
1257
|
+
}, [propsLayouts, breakpoints, breakpoint, cols, compactType]);
|
|
1258
|
+
const effectiveLayout = derivedLayout ?? layout;
|
|
1259
|
+
useEffect(() => {
|
|
1260
|
+
if (derivedLayout !== null) {
|
|
1261
|
+
setLayout(derivedLayout);
|
|
1147
1262
|
setLayouts(propsLayouts);
|
|
1263
|
+
layoutsRef.current = propsLayouts;
|
|
1148
1264
|
prevLayoutsRef.current = propsLayouts;
|
|
1149
1265
|
}
|
|
1150
|
-
}, [
|
|
1266
|
+
}, [derivedLayout, propsLayouts]);
|
|
1151
1267
|
useEffect(() => {
|
|
1152
1268
|
if (compactType !== prevCompactTypeRef.current) {
|
|
1153
1269
|
const newLayout = compact(
|
|
1154
|
-
cloneLayout(
|
|
1270
|
+
cloneLayout(effectiveLayout),
|
|
1155
1271
|
compactType,
|
|
1156
1272
|
cols,
|
|
1157
1273
|
allowOverlap
|
|
1158
1274
|
);
|
|
1159
1275
|
const newLayouts = {
|
|
1160
|
-
...
|
|
1276
|
+
...layoutsRef.current,
|
|
1161
1277
|
[breakpoint]: newLayout
|
|
1162
1278
|
};
|
|
1163
1279
|
setLayout(newLayout);
|
|
1164
1280
|
setLayouts(newLayouts);
|
|
1281
|
+
layoutsRef.current = newLayouts;
|
|
1165
1282
|
onLayoutChange(newLayout, newLayouts);
|
|
1166
1283
|
prevCompactTypeRef.current = compactType;
|
|
1167
1284
|
}
|
|
1168
1285
|
}, [
|
|
1169
1286
|
compactType,
|
|
1170
|
-
|
|
1287
|
+
effectiveLayout,
|
|
1171
1288
|
cols,
|
|
1172
1289
|
allowOverlap,
|
|
1173
|
-
layouts,
|
|
1174
1290
|
breakpoint,
|
|
1175
1291
|
onLayoutChange
|
|
1176
1292
|
]);
|
|
@@ -1187,7 +1303,7 @@ function ResponsiveGridLayout(props) {
|
|
|
1187
1303
|
const newCols = getColsFromBreakpoint(newBreakpoint, colsConfig);
|
|
1188
1304
|
const lastBreakpoint = breakpoint;
|
|
1189
1305
|
if (lastBreakpoint !== newBreakpoint || breakpointsChanged || colsChanged) {
|
|
1190
|
-
const newLayouts = { ...
|
|
1306
|
+
const newLayouts = { ...layoutsRef.current };
|
|
1191
1307
|
if (!newLayouts[lastBreakpoint]) {
|
|
1192
1308
|
newLayouts[lastBreakpoint] = cloneLayout(layout);
|
|
1193
1309
|
}
|
|
@@ -1211,6 +1327,7 @@ function ResponsiveGridLayout(props) {
|
|
|
1211
1327
|
setCols(newCols);
|
|
1212
1328
|
setLayout(newLayout);
|
|
1213
1329
|
setLayouts(newLayouts);
|
|
1330
|
+
layoutsRef.current = newLayouts;
|
|
1214
1331
|
onBreakpointChange(newBreakpoint, newCols);
|
|
1215
1332
|
onLayoutChange(newLayout, newLayouts);
|
|
1216
1333
|
}
|
|
@@ -1236,7 +1353,6 @@ function ResponsiveGridLayout(props) {
|
|
|
1236
1353
|
breakpoint,
|
|
1237
1354
|
cols,
|
|
1238
1355
|
layout,
|
|
1239
|
-
layouts,
|
|
1240
1356
|
children,
|
|
1241
1357
|
compactType,
|
|
1242
1358
|
allowOverlap,
|
|
@@ -1248,15 +1364,17 @@ function ResponsiveGridLayout(props) {
|
|
|
1248
1364
|
]);
|
|
1249
1365
|
const handleLayoutChange = useCallback(
|
|
1250
1366
|
(newLayout) => {
|
|
1367
|
+
const currentLayouts = layoutsRef.current;
|
|
1251
1368
|
const newLayouts = {
|
|
1252
|
-
...
|
|
1369
|
+
...currentLayouts,
|
|
1253
1370
|
[breakpoint]: newLayout
|
|
1254
1371
|
};
|
|
1255
1372
|
setLayout(newLayout);
|
|
1256
1373
|
setLayouts(newLayouts);
|
|
1374
|
+
layoutsRef.current = newLayouts;
|
|
1257
1375
|
onLayoutChange(newLayout, newLayouts);
|
|
1258
1376
|
},
|
|
1259
|
-
[
|
|
1377
|
+
[breakpoint, onLayoutChange]
|
|
1260
1378
|
);
|
|
1261
1379
|
const currentMargin = useMemo(() => {
|
|
1262
1380
|
return getIndentationValue(
|
|
@@ -1289,12 +1407,12 @@ function ResponsiveGridLayout(props) {
|
|
|
1289
1407
|
gridConfig,
|
|
1290
1408
|
compactor,
|
|
1291
1409
|
onLayoutChange: handleLayoutChange,
|
|
1292
|
-
layout,
|
|
1410
|
+
layout: effectiveLayout,
|
|
1293
1411
|
children
|
|
1294
1412
|
}
|
|
1295
1413
|
);
|
|
1296
1414
|
}
|
|
1297
1415
|
|
|
1298
1416
|
export { GridItem, GridLayout, ResponsiveGridLayout };
|
|
1299
|
-
//# sourceMappingURL=chunk-
|
|
1300
|
-
//# sourceMappingURL=chunk-
|
|
1417
|
+
//# sourceMappingURL=chunk-PLWMASMX.mjs.map
|
|
1418
|
+
//# sourceMappingURL=chunk-PLWMASMX.mjs.map
|