react-grid-layout 1.2.5 → 1.3.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/.babelrc.js +3 -2
- package/.eslintignore +3 -0
- package/.flowconfig +1 -3
- package/.prettierignore +1 -0
- package/CHANGELOG.md +383 -246
- package/README.md +122 -60
- package/build/GridItem.js +8 -8
- package/build/ReactGridLayout.js +304 -324
- package/build/ReactGridLayoutPropTypes.js +7 -1
- package/build/ResponsiveReactGridLayout.js +14 -8
- package/build/calculateUtils.js +8 -8
- package/build/components/WidthProvider.js +9 -7
- package/build/fastRGLPropsEqual.js +1 -1
- package/build/responsiveUtils.js +1 -1
- package/build/utils.js +44 -52
- package/dist/react-grid-layout.min.js +1 -2
- package/dist/react-grid-layout.min.js.map +1 -1
- package/index.js +4 -2
- package/lib/GridItem.jsx +10 -5
- package/lib/ReactGridLayout.jsx +101 -62
- package/lib/ReactGridLayoutPropTypes.js +33 -12
- package/lib/ResponsiveReactGridLayout.jsx +7 -1
- package/lib/components/WidthProvider.jsx +2 -2
- package/lib/utils.js +42 -42
- package/package.json +46 -33
- package/dist/react-grid-layout.min.js.LICENSE.txt +0 -5
package/lib/utils.js
CHANGED
|
@@ -159,8 +159,8 @@ export function cloneLayoutItem(layoutItem: LayoutItem): LayoutItem {
|
|
|
159
159
|
*/
|
|
160
160
|
export function childrenEqual(a: ReactChildren, b: ReactChildren): boolean {
|
|
161
161
|
return isEqual(
|
|
162
|
-
React.Children.map(a, c => c
|
|
163
|
-
React.Children.map(b, c => c
|
|
162
|
+
React.Children.map(a, c => c?.key),
|
|
163
|
+
React.Children.map(b, c => c?.key)
|
|
164
164
|
);
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -328,11 +328,11 @@ export function compactItem(
|
|
|
328
328
|
l.y++;
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
|
-
|
|
331
|
+
|
|
332
332
|
// Ensure that there are no negative positions
|
|
333
333
|
l.y = Math.max(l.y, 0);
|
|
334
334
|
l.x = Math.max(l.x, 0);
|
|
335
|
-
|
|
335
|
+
|
|
336
336
|
return l;
|
|
337
337
|
}
|
|
338
338
|
|
|
@@ -434,7 +434,8 @@ export function moveElement(
|
|
|
434
434
|
isUserAction: ?boolean,
|
|
435
435
|
preventCollision: ?boolean,
|
|
436
436
|
compactType: CompactType,
|
|
437
|
-
cols: number
|
|
437
|
+
cols: number,
|
|
438
|
+
allowOverlap: ?boolean
|
|
438
439
|
): Layout {
|
|
439
440
|
// If this is static and not explicitly enabled as draggable,
|
|
440
441
|
// no move is possible, so we can short-circuit this immediately.
|
|
@@ -468,14 +469,23 @@ export function moveElement(
|
|
|
468
469
|
// $FlowIgnore acceptable modification of read-only array as it was recently cloned
|
|
469
470
|
if (movingUp) sorted = sorted.reverse();
|
|
470
471
|
const collisions = getAllCollisions(sorted, l);
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
472
|
+
const hasCollisions = collisions.length > 0;
|
|
473
|
+
|
|
474
|
+
// We may have collisions. We can short-circuit if we've turned off collisions or
|
|
475
|
+
// allowed overlap.
|
|
476
|
+
if (hasCollisions && allowOverlap) {
|
|
477
|
+
// Easy, we don't need to resolve collisions. But we *did* change the layout,
|
|
478
|
+
// so clone it on the way out.
|
|
479
|
+
return cloneLayout(layout);
|
|
480
|
+
} else if (hasCollisions && preventCollision) {
|
|
481
|
+
// If we are preventing collision but not allowing overlap, we need to
|
|
482
|
+
// revert the position of this element so it goes to where it came from, rather
|
|
483
|
+
// than the user's desired location.
|
|
474
484
|
log(`Collision prevented on ${l.i}, reverting.`);
|
|
475
485
|
l.x = oldX;
|
|
476
486
|
l.y = oldY;
|
|
477
487
|
l.moved = false;
|
|
478
|
-
return layout;
|
|
488
|
+
return layout; // did not change so don't clone
|
|
479
489
|
}
|
|
480
490
|
|
|
481
491
|
// Move each item that collides away from this element.
|
|
@@ -626,7 +636,8 @@ export function sortLayoutItems(
|
|
|
626
636
|
compactType: CompactType
|
|
627
637
|
): Layout {
|
|
628
638
|
if (compactType === "horizontal") return sortLayoutItemsByColRow(layout);
|
|
629
|
-
|
|
639
|
+
if (compactType === "vertical") return sortLayoutItemsByRowCol(layout);
|
|
640
|
+
else return layout;
|
|
630
641
|
}
|
|
631
642
|
|
|
632
643
|
/**
|
|
@@ -676,21 +687,25 @@ export function synchronizeLayoutWithChildren(
|
|
|
676
687
|
initialLayout: Layout,
|
|
677
688
|
children: ReactChildren,
|
|
678
689
|
cols: number,
|
|
679
|
-
compactType: CompactType
|
|
690
|
+
compactType: CompactType,
|
|
691
|
+
allowOverlap: ?boolean
|
|
680
692
|
): Layout {
|
|
681
693
|
initialLayout = initialLayout || [];
|
|
682
694
|
|
|
683
695
|
// Generate one layout item per child.
|
|
684
696
|
const layout: LayoutItem[] = [];
|
|
685
|
-
React.Children.forEach(children, (child: ReactElement<any
|
|
697
|
+
React.Children.forEach(children, (child: ReactElement<any>) => {
|
|
698
|
+
// Child may not exist
|
|
699
|
+
if (child?.key == null) return;
|
|
700
|
+
|
|
686
701
|
// Don't overwrite if it already exists.
|
|
687
702
|
const exists = getLayoutItem(initialLayout, String(child.key));
|
|
688
703
|
if (exists) {
|
|
689
|
-
layout
|
|
704
|
+
layout.push(cloneLayoutItem(exists));
|
|
690
705
|
} else {
|
|
691
706
|
if (!isProduction && child.props._grid) {
|
|
692
707
|
console.warn(
|
|
693
|
-
"`_grid` properties on children have been deprecated as of React 15.2. " +
|
|
708
|
+
"`_grid` properties on children have been deprecated as of React 15.2. " +
|
|
694
709
|
"Please use `data-grid` or add your properties directly to the `layout`."
|
|
695
710
|
);
|
|
696
711
|
}
|
|
@@ -702,24 +717,28 @@ export function synchronizeLayoutWithChildren(
|
|
|
702
717
|
validateLayout([g], "ReactGridLayout.children");
|
|
703
718
|
}
|
|
704
719
|
// FIXME clone not really necessary here
|
|
705
|
-
layout
|
|
720
|
+
layout.push(cloneLayoutItem({ ...g, i: child.key }));
|
|
706
721
|
} else {
|
|
707
722
|
// Nothing provided: ensure this is added to the bottom
|
|
708
723
|
// FIXME clone not really necessary here
|
|
709
|
-
layout
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
724
|
+
layout.push(
|
|
725
|
+
cloneLayoutItem({
|
|
726
|
+
w: 1,
|
|
727
|
+
h: 1,
|
|
728
|
+
x: 0,
|
|
729
|
+
y: bottom(layout),
|
|
730
|
+
i: String(child.key)
|
|
731
|
+
})
|
|
732
|
+
);
|
|
716
733
|
}
|
|
717
734
|
}
|
|
718
735
|
});
|
|
719
736
|
|
|
720
737
|
// Correct the layout.
|
|
721
738
|
const correctedLayout = correctBounds(layout, { cols: cols });
|
|
722
|
-
return
|
|
739
|
+
return allowOverlap
|
|
740
|
+
? correctedLayout
|
|
741
|
+
: compact(correctedLayout, compactType, cols);
|
|
723
742
|
}
|
|
724
743
|
|
|
725
744
|
/**
|
|
@@ -751,20 +770,6 @@ export function validateLayout(
|
|
|
751
770
|
);
|
|
752
771
|
}
|
|
753
772
|
}
|
|
754
|
-
if (item.i && typeof item.i !== "string") {
|
|
755
|
-
throw new Error(
|
|
756
|
-
"ReactGridLayout: " + contextName + "[" + i + "].i must be a string!"
|
|
757
|
-
);
|
|
758
|
-
}
|
|
759
|
-
if (item.static !== undefined && typeof item.static !== "boolean") {
|
|
760
|
-
throw new Error(
|
|
761
|
-
"ReactGridLayout: " +
|
|
762
|
-
contextName +
|
|
763
|
-
"[" +
|
|
764
|
-
i +
|
|
765
|
-
"].static must be a boolean!"
|
|
766
|
-
);
|
|
767
|
-
}
|
|
768
773
|
}
|
|
769
774
|
}
|
|
770
775
|
|
|
@@ -776,11 +781,6 @@ export function compactType(
|
|
|
776
781
|
return verticalCompact === false ? null : compactType;
|
|
777
782
|
}
|
|
778
783
|
|
|
779
|
-
// Flow can't really figure this out, so we just use Object
|
|
780
|
-
export function autoBindHandlers(el: Object, fns: Array<string>): void {
|
|
781
|
-
fns.forEach(key => (el[key] = el[key].bind(el)));
|
|
782
|
-
}
|
|
783
|
-
|
|
784
784
|
function log(...args) {
|
|
785
785
|
if (!DEBUG) return;
|
|
786
786
|
// eslint-disable-next-line no-console
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-grid-layout",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "A draggable and resizable grid layout with responsive breakpoints, for React.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"dev": "make dev",
|
|
13
13
|
"prepublishOnly": "make build",
|
|
14
14
|
"validate": "npm ls",
|
|
15
|
-
"flow": "flow"
|
|
15
|
+
"flow": "flow",
|
|
16
|
+
"fmt": "prettier --write ./**.{json,js,yml,md}",
|
|
17
|
+
"fmt:check": "prettier --check ./**.{json,js,yml,md}"
|
|
16
18
|
},
|
|
17
19
|
"repository": {
|
|
18
20
|
"type": "git",
|
|
@@ -35,53 +37,54 @@
|
|
|
35
37
|
},
|
|
36
38
|
"homepage": "https://github.com/STRML/react-grid-layout",
|
|
37
39
|
"dependencies": {
|
|
38
|
-
"
|
|
40
|
+
"clsx": "^1.1.1",
|
|
39
41
|
"lodash.isequal": "^4.0.0",
|
|
40
42
|
"prop-types": "^15.0.0",
|
|
41
43
|
"react-draggable": "^4.0.0",
|
|
42
|
-
"react-resizable": "^3.0.
|
|
44
|
+
"react-resizable": "^3.0.4"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
|
-
"@babel/cli": "^7.
|
|
46
|
-
"@babel/core": "^7.
|
|
47
|
-
"@babel/
|
|
48
|
-
"@babel/plugin-
|
|
49
|
-
"@babel/
|
|
50
|
-
"@babel/preset-
|
|
51
|
-
"@babel/preset-
|
|
52
|
-
"@babel/
|
|
53
|
-
"@
|
|
54
|
-
"
|
|
55
|
-
"babel-jest": "^
|
|
47
|
+
"@babel/cli": "^7.14.8",
|
|
48
|
+
"@babel/core": "^7.15.0",
|
|
49
|
+
"@babel/eslint-parser": "^7.16.3",
|
|
50
|
+
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
|
51
|
+
"@babel/plugin-transform-flow-comments": "^7.14.5",
|
|
52
|
+
"@babel/preset-env": "^7.15.0",
|
|
53
|
+
"@babel/preset-flow": "^7.14.5",
|
|
54
|
+
"@babel/preset-react": "^7.14.5",
|
|
55
|
+
"@babel/register": "^7.15.3",
|
|
56
|
+
"@webpack-cli/serve": "^1.5.2",
|
|
57
|
+
"babel-jest": "^27.0.6",
|
|
56
58
|
"babel-loader": "^8.2.2",
|
|
57
59
|
"babel-plugin-preval": "^5.0.0",
|
|
58
|
-
"css-loader": "^
|
|
60
|
+
"css-loader": "^6.2.0",
|
|
59
61
|
"ejs": "^3.1.6",
|
|
60
62
|
"enzyme": "^3.11.0",
|
|
61
63
|
"enzyme-adapter-react-16": "^1.15.6",
|
|
62
64
|
"enzyme-to-json": "^3.6.2",
|
|
63
|
-
"eslint": "^7.
|
|
64
|
-
"eslint-plugin-flowtype": "^5.
|
|
65
|
-
"eslint-plugin-mocha": "^
|
|
66
|
-
"eslint-plugin-react": "^7.
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
65
|
+
"eslint": "^7.32.0",
|
|
66
|
+
"eslint-plugin-flowtype": "^5.9.0",
|
|
67
|
+
"eslint-plugin-mocha": "^9.0.0",
|
|
68
|
+
"eslint-plugin-react": "^7.24.0",
|
|
69
|
+
"eslint-plugin-unicorn": "^39.0.0",
|
|
70
|
+
"exports-loader": "^3.0.0",
|
|
71
|
+
"flow-bin": "^0.158.0",
|
|
72
|
+
"husky": "^7.0.2",
|
|
73
|
+
"imports-loader": "^3.0.0",
|
|
74
|
+
"jest": "^27.0.6",
|
|
75
|
+
"lint-staged": "^11.1.2",
|
|
73
76
|
"lodash": "^4.17.21",
|
|
74
77
|
"opener": "^1.5.2",
|
|
75
|
-
"prettier": "^2.3.
|
|
78
|
+
"prettier": "^2.3.2",
|
|
76
79
|
"react": "^16.13.1",
|
|
77
80
|
"react-dom": "^16.13.1",
|
|
78
81
|
"react-hot-loader": "^4.13.0",
|
|
79
82
|
"react-transform-hmr": "^1.0.2",
|
|
80
|
-
"style-loader": "^2.
|
|
83
|
+
"style-loader": "^3.2.1",
|
|
81
84
|
"timsort": "^0.3.0",
|
|
82
|
-
"webpack": "^5.
|
|
83
|
-
"webpack-cli": "^4.
|
|
84
|
-
"webpack-dev-server": "^
|
|
85
|
+
"webpack": "^5.51.1",
|
|
86
|
+
"webpack-cli": "^4.8.0",
|
|
87
|
+
"webpack-dev-server": "^4.0.0"
|
|
85
88
|
},
|
|
86
89
|
"peerDependencies": {
|
|
87
90
|
"react": ">= 16.3.0",
|
|
@@ -100,11 +103,21 @@
|
|
|
100
103
|
"testMatch": [
|
|
101
104
|
"<rootDir>/test/spec/*.js"
|
|
102
105
|
],
|
|
103
|
-
"
|
|
106
|
+
"testEnvironment": "jsdom",
|
|
107
|
+
"testURL": "http://localhost",
|
|
108
|
+
"coverageThreshold": {
|
|
109
|
+
"global": {
|
|
110
|
+
"statements": 77.43,
|
|
111
|
+
"branches": 72.02,
|
|
112
|
+
"functions": 77.12,
|
|
113
|
+
"lines": 78.93
|
|
114
|
+
}
|
|
115
|
+
}
|
|
104
116
|
},
|
|
105
117
|
"lint-staged": {
|
|
106
118
|
"*.{js,jsx,css}": [
|
|
107
|
-
"
|
|
119
|
+
"eslint --ext .js,.jsx --fix",
|
|
120
|
+
"yarn fmt"
|
|
108
121
|
]
|
|
109
122
|
}
|
|
110
123
|
}
|