react-grid-layout 1.2.2 → 1.3.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.
- package/.flowconfig +1 -3
- package/CHANGELOG.md +55 -0
- package/README.md +55 -16
- package/build/GridItem.js +14 -20
- package/build/ReactGridLayout.js +299 -319
- package/build/ReactGridLayoutPropTypes.js +11 -5
- package/build/ResponsiveReactGridLayout.js +12 -6
- package/build/calculateUtils.js +6 -6
- package/build/components/WidthProvider.js +31 -25
- package/build/fastRGLPropsEqual.js +1 -1
- package/build/utils.js +29 -32
- package/dist/react-grid-layout.min.js +1 -1
- package/dist/react-grid-layout.min.js.LICENSE.txt +1 -1
- package/dist/react-grid-layout.min.js.map +1 -1
- package/foo.html +388 -0
- package/lib/GridItem.jsx +18 -14
- package/lib/ReactGridLayout.jsx +93 -58
- package/lib/ReactGridLayoutPropTypes.js +40 -14
- package/lib/ResponsiveReactGridLayout.jsx +7 -1
- package/lib/components/WidthProvider.jsx +35 -23
- package/lib/utils.js +30 -20
- package/package.json +35 -29
- package/.husky/pre-commit +0 -6
- package/.travis.yml +0 -9
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,6 +328,11 @@ export function compactItem(
|
|
|
328
328
|
l.y++;
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
|
+
|
|
332
|
+
// Ensure that there are no negative positions
|
|
333
|
+
l.y = Math.max(l.y, 0);
|
|
334
|
+
l.x = Math.max(l.x, 0);
|
|
335
|
+
|
|
331
336
|
return l;
|
|
332
337
|
}
|
|
333
338
|
|
|
@@ -429,7 +434,8 @@ export function moveElement(
|
|
|
429
434
|
isUserAction: ?boolean,
|
|
430
435
|
preventCollision: ?boolean,
|
|
431
436
|
compactType: CompactType,
|
|
432
|
-
cols: number
|
|
437
|
+
cols: number,
|
|
438
|
+
allowOverlap: ?boolean
|
|
433
439
|
): Layout {
|
|
434
440
|
// If this is static and not explicitly enabled as draggable,
|
|
435
441
|
// no move is possible, so we can short-circuit this immediately.
|
|
@@ -466,10 +472,12 @@ export function moveElement(
|
|
|
466
472
|
|
|
467
473
|
// There was a collision; abort
|
|
468
474
|
if (preventCollision && collisions.length) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
475
|
+
if (!allowOverlap) {
|
|
476
|
+
log(`Collision prevented on ${l.i}, reverting.`);
|
|
477
|
+
l.x = oldX;
|
|
478
|
+
l.y = oldY;
|
|
479
|
+
l.moved = false;
|
|
480
|
+
}
|
|
473
481
|
return layout;
|
|
474
482
|
}
|
|
475
483
|
|
|
@@ -621,7 +629,8 @@ export function sortLayoutItems(
|
|
|
621
629
|
compactType: CompactType
|
|
622
630
|
): Layout {
|
|
623
631
|
if (compactType === "horizontal") return sortLayoutItemsByColRow(layout);
|
|
624
|
-
|
|
632
|
+
if (compactType === "vertical") return sortLayoutItemsByRowCol(layout);
|
|
633
|
+
else return layout;
|
|
625
634
|
}
|
|
626
635
|
|
|
627
636
|
/**
|
|
@@ -671,17 +680,21 @@ export function synchronizeLayoutWithChildren(
|
|
|
671
680
|
initialLayout: Layout,
|
|
672
681
|
children: ReactChildren,
|
|
673
682
|
cols: number,
|
|
674
|
-
compactType: CompactType
|
|
683
|
+
compactType: CompactType,
|
|
684
|
+
allowOverlap: ?boolean
|
|
675
685
|
): Layout {
|
|
676
686
|
initialLayout = initialLayout || [];
|
|
677
687
|
|
|
678
688
|
// Generate one layout item per child.
|
|
679
689
|
const layout: LayoutItem[] = [];
|
|
680
|
-
React.Children.forEach(children, (child: ReactElement<any
|
|
690
|
+
React.Children.forEach(children, (child: ReactElement<any>) => {
|
|
691
|
+
// Child may not exist
|
|
692
|
+
if (child?.key == null) return;
|
|
693
|
+
|
|
681
694
|
// Don't overwrite if it already exists.
|
|
682
695
|
const exists = getLayoutItem(initialLayout, String(child.key));
|
|
683
696
|
if (exists) {
|
|
684
|
-
layout
|
|
697
|
+
layout.push(cloneLayoutItem(exists));
|
|
685
698
|
} else {
|
|
686
699
|
if (!isProduction && child.props._grid) {
|
|
687
700
|
console.warn(
|
|
@@ -697,24 +710,26 @@ export function synchronizeLayoutWithChildren(
|
|
|
697
710
|
validateLayout([g], "ReactGridLayout.children");
|
|
698
711
|
}
|
|
699
712
|
// FIXME clone not really necessary here
|
|
700
|
-
layout
|
|
713
|
+
layout.push(cloneLayoutItem({ ...g, i: child.key }));
|
|
701
714
|
} else {
|
|
702
715
|
// Nothing provided: ensure this is added to the bottom
|
|
703
716
|
// FIXME clone not really necessary here
|
|
704
|
-
layout
|
|
717
|
+
layout.push(cloneLayoutItem({
|
|
705
718
|
w: 1,
|
|
706
719
|
h: 1,
|
|
707
720
|
x: 0,
|
|
708
721
|
y: bottom(layout),
|
|
709
722
|
i: String(child.key)
|
|
710
|
-
});
|
|
723
|
+
}));
|
|
711
724
|
}
|
|
712
725
|
}
|
|
713
726
|
});
|
|
714
727
|
|
|
715
728
|
// Correct the layout.
|
|
716
729
|
const correctedLayout = correctBounds(layout, { cols: cols });
|
|
717
|
-
return
|
|
730
|
+
return allowOverlap
|
|
731
|
+
? correctedLayout
|
|
732
|
+
: compact(correctedLayout, compactType, cols);
|
|
718
733
|
}
|
|
719
734
|
|
|
720
735
|
/**
|
|
@@ -771,11 +786,6 @@ export function compactType(
|
|
|
771
786
|
return verticalCompact === false ? null : compactType;
|
|
772
787
|
}
|
|
773
788
|
|
|
774
|
-
// Flow can't really figure this out, so we just use Object
|
|
775
|
-
export function autoBindHandlers(el: Object, fns: Array<string>): void {
|
|
776
|
-
fns.forEach(key => (el[key] = el[key].bind(el)));
|
|
777
|
-
}
|
|
778
|
-
|
|
779
789
|
function log(...args) {
|
|
780
790
|
if (!DEBUG) return;
|
|
781
791
|
// 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.0",
|
|
4
4
|
"description": "A draggable and resizable grid layout with responsive breakpoints, for React.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,52 +35,57 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/STRML/react-grid-layout",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"classnames": "2.
|
|
38
|
+
"classnames": "2.3.1",
|
|
39
39
|
"lodash.isequal": "^4.0.0",
|
|
40
40
|
"prop-types": "^15.0.0",
|
|
41
41
|
"react-draggable": "^4.0.0",
|
|
42
|
-
"react-resizable": "^
|
|
42
|
+
"react-resizable": "^3.0.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@babel/cli": "^7.
|
|
46
|
-
"@babel/core": "^7.
|
|
47
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
48
|
-
"@babel/plugin-transform-flow-comments": "^7.
|
|
49
|
-
"@babel/preset-env": "^7.
|
|
50
|
-
"@babel/preset-flow": "^7.
|
|
51
|
-
"@babel/preset-react": "^7.
|
|
52
|
-
"@babel/register": "^7.
|
|
45
|
+
"@babel/cli": "^7.14.8",
|
|
46
|
+
"@babel/core": "^7.15.0",
|
|
47
|
+
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
|
48
|
+
"@babel/plugin-transform-flow-comments": "^7.14.5",
|
|
49
|
+
"@babel/preset-env": "^7.15.0",
|
|
50
|
+
"@babel/preset-flow": "^7.14.5",
|
|
51
|
+
"@babel/preset-react": "^7.14.5",
|
|
52
|
+
"@babel/register": "^7.15.3",
|
|
53
|
+
"@webpack-cli/serve": "^1.5.2",
|
|
53
54
|
"babel-eslint": "^10.1.0",
|
|
54
|
-
"babel-jest": "^
|
|
55
|
+
"babel-jest": "^27.0.6",
|
|
55
56
|
"babel-loader": "^8.2.2",
|
|
56
57
|
"babel-plugin-preval": "^5.0.0",
|
|
57
|
-
"css-loader": "^
|
|
58
|
+
"css-loader": "^6.2.0",
|
|
58
59
|
"ejs": "^3.1.6",
|
|
59
60
|
"enzyme": "^3.11.0",
|
|
60
61
|
"enzyme-adapter-react-16": "^1.15.6",
|
|
61
|
-
"enzyme-to-json": "^3.6.
|
|
62
|
-
"eslint": "^7.
|
|
63
|
-
"eslint-plugin-flowtype": "^5.
|
|
64
|
-
"eslint-plugin-mocha": "^
|
|
65
|
-
"eslint-plugin-react": "^7.
|
|
66
|
-
"exports-loader": "^
|
|
67
|
-
"flow-bin": "^0.
|
|
68
|
-
"husky": "^
|
|
69
|
-
"imports-loader": "^
|
|
70
|
-
"jest": "^
|
|
71
|
-
"lint-staged": "^
|
|
62
|
+
"enzyme-to-json": "^3.6.2",
|
|
63
|
+
"eslint": "^7.32.0",
|
|
64
|
+
"eslint-plugin-flowtype": "^5.9.0",
|
|
65
|
+
"eslint-plugin-mocha": "^9.0.0",
|
|
66
|
+
"eslint-plugin-react": "^7.24.0",
|
|
67
|
+
"exports-loader": "^3.0.0",
|
|
68
|
+
"flow-bin": "^0.158.0",
|
|
69
|
+
"husky": "^7.0.2",
|
|
70
|
+
"imports-loader": "^3.0.0",
|
|
71
|
+
"jest": "^27.0.6",
|
|
72
|
+
"lint-staged": "^11.1.2",
|
|
72
73
|
"lodash": "^4.17.21",
|
|
73
74
|
"opener": "^1.5.2",
|
|
74
|
-
"prettier": "^2.2
|
|
75
|
+
"prettier": "^2.3.2",
|
|
75
76
|
"react": "^16.13.1",
|
|
76
77
|
"react-dom": "^16.13.1",
|
|
77
78
|
"react-hot-loader": "^4.13.0",
|
|
78
79
|
"react-transform-hmr": "^1.0.2",
|
|
79
|
-
"style-loader": "^2.
|
|
80
|
+
"style-loader": "^3.2.1",
|
|
80
81
|
"timsort": "^0.3.0",
|
|
81
|
-
"webpack": "^5.
|
|
82
|
-
"webpack-cli": "^4.
|
|
83
|
-
"webpack-dev-server": "^
|
|
82
|
+
"webpack": "^5.51.1",
|
|
83
|
+
"webpack-cli": "^4.8.0",
|
|
84
|
+
"webpack-dev-server": "^4.0.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": ">= 16.3.0",
|
|
88
|
+
"react-dom": ">= 16.3.0"
|
|
84
89
|
},
|
|
85
90
|
"publishConfig": {
|
|
86
91
|
"registry": "https://registry.npmjs.org"
|
|
@@ -95,6 +100,7 @@
|
|
|
95
100
|
"testMatch": [
|
|
96
101
|
"<rootDir>/test/spec/*.js"
|
|
97
102
|
],
|
|
103
|
+
"testEnvironment": "jsdom",
|
|
98
104
|
"testURL": "http://localhost"
|
|
99
105
|
},
|
|
100
106
|
"lint-staged": {
|
package/.husky/pre-commit
DELETED