react-grid-layout 1.4.1 → 1.4.3
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/CHANGELOG.md +20 -0
- package/build/ReactGridLayout.js +46 -32
- package/dist/react-grid-layout.min.js +1 -1
- package/dist/react-grid-layout.min.js.map +1 -1
- package/lib/ReactGridLayout.jsx +54 -37
- package/package.json +6 -4
package/lib/ReactGridLayout.jsx
CHANGED
|
@@ -251,10 +251,21 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
251
251
|
const { layout } = this.state;
|
|
252
252
|
const l = getLayoutItem(layout, i);
|
|
253
253
|
if (!l) return;
|
|
254
|
+
|
|
255
|
+
// Create placeholder (display only)
|
|
256
|
+
const placeholder = {
|
|
257
|
+
w: l.w,
|
|
258
|
+
h: l.h,
|
|
259
|
+
x: l.x,
|
|
260
|
+
y: l.y,
|
|
261
|
+
placeholder: true,
|
|
262
|
+
i: i
|
|
263
|
+
};
|
|
254
264
|
|
|
255
265
|
this.setState({
|
|
256
266
|
oldDragItem: cloneLayoutItem(l),
|
|
257
|
-
oldLayout: layout
|
|
267
|
+
oldLayout: layout,
|
|
268
|
+
activeDrag: placeholder
|
|
258
269
|
});
|
|
259
270
|
|
|
260
271
|
return this.props.onDragStart(layout, l, l, null, e, node);
|
|
@@ -405,55 +416,65 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
405
416
|
let { layout } = this.state;
|
|
406
417
|
const { cols, preventCollision, allowOverlap } = this.props;
|
|
407
418
|
|
|
419
|
+
let shouldMoveItem = false;
|
|
420
|
+
let finalLayout;
|
|
421
|
+
let x;
|
|
422
|
+
let y;
|
|
423
|
+
|
|
408
424
|
const [newLayout, l] = withLayoutItem(layout, i, l => {
|
|
425
|
+
let hasCollisions;
|
|
426
|
+
x = l.x;
|
|
427
|
+
y = l.y;
|
|
428
|
+
if (["sw", "w", "nw", "n", "ne"].indexOf(handle) !== -1) {
|
|
429
|
+
if (["sw", "nw", "w"].indexOf(handle) !== -1) {
|
|
430
|
+
x = l.x + (l.w - w);
|
|
431
|
+
w = l.x !== x && x < 0 ? l.w : w;
|
|
432
|
+
x = x < 0 ? 0 : x;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (["ne", "n", "nw"].indexOf(handle) !== -1) {
|
|
436
|
+
y = l.y + (l.h - h);
|
|
437
|
+
h = l.y !== y && y < 0 ? l.h : h;
|
|
438
|
+
y = y < 0 ? 0 : y;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
shouldMoveItem = true;
|
|
442
|
+
}
|
|
443
|
+
|
|
409
444
|
// Something like quad tree should be used
|
|
410
445
|
// to find collisions faster
|
|
411
|
-
let hasCollisions;
|
|
412
446
|
if (preventCollision && !allowOverlap) {
|
|
413
|
-
const collisions = getAllCollisions(layout, {
|
|
414
|
-
|
|
415
|
-
|
|
447
|
+
const collisions = getAllCollisions(layout, {
|
|
448
|
+
...l,
|
|
449
|
+
w,
|
|
450
|
+
h,
|
|
451
|
+
x,
|
|
452
|
+
y
|
|
453
|
+
}).filter(layoutItem => layoutItem.i !== l.i);
|
|
416
454
|
hasCollisions = collisions.length > 0;
|
|
417
455
|
|
|
418
456
|
// If we're colliding, we need adjust the placeholder.
|
|
419
457
|
if (hasCollisions) {
|
|
420
|
-
//
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
if (Number.isFinite(leastX)) l.w = leastX - l.x;
|
|
429
|
-
if (Number.isFinite(leastY)) l.h = leastY - l.y;
|
|
458
|
+
// Reset layoutItem dimensions if there were collisions
|
|
459
|
+
y = l.y;
|
|
460
|
+
h = l.h;
|
|
461
|
+
x = l.x;
|
|
462
|
+
w = l.w;
|
|
463
|
+
shouldMoveItem = false;
|
|
430
464
|
}
|
|
431
465
|
}
|
|
432
466
|
|
|
467
|
+
l.w = w;
|
|
468
|
+
l.h = h;
|
|
469
|
+
|
|
433
470
|
return l;
|
|
434
471
|
});
|
|
435
472
|
|
|
436
473
|
// Shouldn't ever happen, but typechecking makes it necessary
|
|
437
474
|
if (!l) return;
|
|
438
475
|
|
|
439
|
-
|
|
440
|
-
if (
|
|
441
|
-
let x = l.x;
|
|
442
|
-
let y = l.y;
|
|
443
|
-
if (["sw", "nw", "w"].indexOf(handle) !== -1) {
|
|
444
|
-
x = l.x + (l.w - w);
|
|
445
|
-
w = l.x !== x && x < 0 ? l.w : w;
|
|
446
|
-
x = x < 0 ? 0 : x;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
if (["ne", "n", "nw"].indexOf(handle) !== -1) {
|
|
450
|
-
y = l.y + (l.h - h);
|
|
451
|
-
h = l.y !== y && y < 0 ? l.h : h;
|
|
452
|
-
y = y < 0 ? 0 : y;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
l.w = w;
|
|
456
|
-
l.h = h;
|
|
476
|
+
finalLayout = newLayout;
|
|
477
|
+
if (shouldMoveItem) {
|
|
457
478
|
// Move the element to the new position.
|
|
458
479
|
const isUserAction = true;
|
|
459
480
|
finalLayout = moveElement(
|
|
@@ -467,10 +488,6 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
467
488
|
cols,
|
|
468
489
|
allowOverlap
|
|
469
490
|
);
|
|
470
|
-
} else {
|
|
471
|
-
l.w = w;
|
|
472
|
-
l.h = h;
|
|
473
|
-
finalLayout = newLayout;
|
|
474
491
|
}
|
|
475
492
|
|
|
476
493
|
// Create placeholder element (display only)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-grid-layout",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "A draggable and resizable grid layout with responsive breakpoints, for React.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -122,9 +122,11 @@
|
|
|
122
122
|
}
|
|
123
123
|
},
|
|
124
124
|
"lint-staged": {
|
|
125
|
-
"*.{js,jsx
|
|
126
|
-
"eslint --ext .js,.jsx --fix"
|
|
127
|
-
|
|
125
|
+
"*.{js,jsx}": [
|
|
126
|
+
"eslint --ext .js,.jsx --fix"
|
|
127
|
+
],
|
|
128
|
+
"*": [
|
|
129
|
+
"prettier --ignore-unknown --write"
|
|
128
130
|
]
|
|
129
131
|
}
|
|
130
132
|
}
|