react-grid-layout 1.2.4 → 1.3.2
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 +371 -236
- package/README.md +122 -62
- package/build/GridItem.js +12 -12
- package/build/ReactGridLayout.js +306 -325
- package/build/ReactGridLayoutPropTypes.js +11 -5
- package/build/ResponsiveReactGridLayout.js +16 -10
- package/build/calculateUtils.js +8 -8
- package/build/components/WidthProvider.js +11 -9
- package/build/fastRGLPropsEqual.js +1 -1
- package/build/responsiveUtils.js +1 -1
- package/build/utils.js +48 -53
- package/coverage/clover.xml +761 -0
- package/coverage/coverage-final.json +15 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/react-grid-layout/index-dev.js.html +104 -0
- package/coverage/lcov-report/react-grid-layout/lib/GridItem.jsx.html +2099 -0
- package/coverage/lcov-report/react-grid-layout/lib/ReactGridLayout.jsx.html +2453 -0
- package/coverage/lcov-report/react-grid-layout/lib/ReactGridLayoutPropTypes.js.html +833 -0
- package/coverage/lcov-report/react-grid-layout/lib/ResponsiveReactGridLayout.jsx.html +1133 -0
- package/coverage/lcov-report/react-grid-layout/lib/calculateUtils.js.html +557 -0
- package/coverage/lcov-report/react-grid-layout/lib/components/WidthProvider.jsx.html +410 -0
- package/coverage/lcov-report/react-grid-layout/lib/fastRGLPropsEqual.js.html +224 -0
- package/coverage/lcov-report/react-grid-layout/lib/responsiveUtils.js.html +440 -0
- package/coverage/lcov-report/react-grid-layout/lib/utils.js.html +2456 -0
- package/coverage/lcov-report/react-grid-layout/test/examples/0-showcase.jsx.html +521 -0
- package/coverage/lcov-report/react-grid-layout/test/examples/1-basic.jsx.html +284 -0
- package/coverage/lcov-report/react-grid-layout/test/examples/15-drag-from-outside.jsx.html +506 -0
- package/coverage/lcov-report/react-grid-layout/test/util/deepFreeze.js.html +248 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +1584 -0
- 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 +15 -10
- package/lib/ReactGridLayout.jsx +101 -62
- package/lib/ReactGridLayoutPropTypes.js +38 -17
- package/lib/ResponsiveReactGridLayout.jsx +7 -1
- package/lib/components/WidthProvider.jsx +2 -2
- package/lib/utils.js +45 -40
- package/package.json +48 -34
- package/.husky/pre-commit +0 -6
- package/.travis.yml +0 -9
- 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,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.
|
|
@@ -463,14 +469,23 @@ export function moveElement(
|
|
|
463
469
|
// $FlowIgnore acceptable modification of read-only array as it was recently cloned
|
|
464
470
|
if (movingUp) sorted = sorted.reverse();
|
|
465
471
|
const collisions = getAllCollisions(sorted, l);
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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.
|
|
469
484
|
log(`Collision prevented on ${l.i}, reverting.`);
|
|
470
485
|
l.x = oldX;
|
|
471
486
|
l.y = oldY;
|
|
472
487
|
l.moved = false;
|
|
473
|
-
return layout;
|
|
488
|
+
return layout; // did not change so don't clone
|
|
474
489
|
}
|
|
475
490
|
|
|
476
491
|
// Move each item that collides away from this element.
|
|
@@ -621,7 +636,8 @@ export function sortLayoutItems(
|
|
|
621
636
|
compactType: CompactType
|
|
622
637
|
): Layout {
|
|
623
638
|
if (compactType === "horizontal") return sortLayoutItemsByColRow(layout);
|
|
624
|
-
|
|
639
|
+
if (compactType === "vertical") return sortLayoutItemsByRowCol(layout);
|
|
640
|
+
else return layout;
|
|
625
641
|
}
|
|
626
642
|
|
|
627
643
|
/**
|
|
@@ -671,21 +687,25 @@ export function synchronizeLayoutWithChildren(
|
|
|
671
687
|
initialLayout: Layout,
|
|
672
688
|
children: ReactChildren,
|
|
673
689
|
cols: number,
|
|
674
|
-
compactType: CompactType
|
|
690
|
+
compactType: CompactType,
|
|
691
|
+
allowOverlap: ?boolean
|
|
675
692
|
): Layout {
|
|
676
693
|
initialLayout = initialLayout || [];
|
|
677
694
|
|
|
678
695
|
// Generate one layout item per child.
|
|
679
696
|
const layout: LayoutItem[] = [];
|
|
680
|
-
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
|
+
|
|
681
701
|
// Don't overwrite if it already exists.
|
|
682
702
|
const exists = getLayoutItem(initialLayout, String(child.key));
|
|
683
703
|
if (exists) {
|
|
684
|
-
layout
|
|
704
|
+
layout.push(cloneLayoutItem(exists));
|
|
685
705
|
} else {
|
|
686
706
|
if (!isProduction && child.props._grid) {
|
|
687
707
|
console.warn(
|
|
688
|
-
"`_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. " +
|
|
689
709
|
"Please use `data-grid` or add your properties directly to the `layout`."
|
|
690
710
|
);
|
|
691
711
|
}
|
|
@@ -697,24 +717,28 @@ export function synchronizeLayoutWithChildren(
|
|
|
697
717
|
validateLayout([g], "ReactGridLayout.children");
|
|
698
718
|
}
|
|
699
719
|
// FIXME clone not really necessary here
|
|
700
|
-
layout
|
|
720
|
+
layout.push(cloneLayoutItem({ ...g, i: child.key }));
|
|
701
721
|
} else {
|
|
702
722
|
// Nothing provided: ensure this is added to the bottom
|
|
703
723
|
// FIXME clone not really necessary here
|
|
704
|
-
layout
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
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
|
+
);
|
|
711
733
|
}
|
|
712
734
|
}
|
|
713
735
|
});
|
|
714
736
|
|
|
715
737
|
// Correct the layout.
|
|
716
738
|
const correctedLayout = correctBounds(layout, { cols: cols });
|
|
717
|
-
return
|
|
739
|
+
return allowOverlap
|
|
740
|
+
? correctedLayout
|
|
741
|
+
: compact(correctedLayout, compactType, cols);
|
|
718
742
|
}
|
|
719
743
|
|
|
720
744
|
/**
|
|
@@ -746,20 +770,6 @@ export function validateLayout(
|
|
|
746
770
|
);
|
|
747
771
|
}
|
|
748
772
|
}
|
|
749
|
-
if (item.i && typeof item.i !== "string") {
|
|
750
|
-
throw new Error(
|
|
751
|
-
"ReactGridLayout: " + contextName + "[" + i + "].i must be a string!"
|
|
752
|
-
);
|
|
753
|
-
}
|
|
754
|
-
if (item.static !== undefined && typeof item.static !== "boolean") {
|
|
755
|
-
throw new Error(
|
|
756
|
-
"ReactGridLayout: " +
|
|
757
|
-
contextName +
|
|
758
|
-
"[" +
|
|
759
|
-
i +
|
|
760
|
-
"].static must be a boolean!"
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
773
|
}
|
|
764
774
|
}
|
|
765
775
|
|
|
@@ -771,11 +781,6 @@ export function compactType(
|
|
|
771
781
|
return verticalCompact === false ? null : compactType;
|
|
772
782
|
}
|
|
773
783
|
|
|
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
784
|
function log(...args) {
|
|
780
785
|
if (!DEBUG) return;
|
|
781
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.2
|
|
3
|
+
"version": "1.3.2",
|
|
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,52 +37,54 @@
|
|
|
35
37
|
},
|
|
36
38
|
"homepage": "https://github.com/STRML/react-grid-layout",
|
|
37
39
|
"dependencies": {
|
|
38
|
-
"
|
|
40
|
+
"@babel/eslint-parser": "^7.16.3",
|
|
41
|
+
"clsx": "^1.1.1",
|
|
39
42
|
"lodash.isequal": "^4.0.0",
|
|
40
43
|
"prop-types": "^15.0.0",
|
|
41
44
|
"react-draggable": "^4.0.0",
|
|
42
|
-
"react-resizable": "^
|
|
45
|
+
"react-resizable": "^3.0.4"
|
|
43
46
|
},
|
|
44
47
|
"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.
|
|
53
|
-
"
|
|
54
|
-
"babel-jest": "^
|
|
48
|
+
"@babel/cli": "^7.14.8",
|
|
49
|
+
"@babel/core": "^7.15.0",
|
|
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",
|
|
55
58
|
"babel-loader": "^8.2.2",
|
|
56
59
|
"babel-plugin-preval": "^5.0.0",
|
|
57
|
-
"css-loader": "^
|
|
60
|
+
"css-loader": "^6.2.0",
|
|
58
61
|
"ejs": "^3.1.6",
|
|
59
62
|
"enzyme": "^3.11.0",
|
|
60
63
|
"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
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
64
|
+
"enzyme-to-json": "^3.6.2",
|
|
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",
|
|
72
76
|
"lodash": "^4.17.21",
|
|
73
77
|
"opener": "^1.5.2",
|
|
74
|
-
"prettier": "^2.2
|
|
78
|
+
"prettier": "^2.3.2",
|
|
75
79
|
"react": "^16.13.1",
|
|
76
80
|
"react-dom": "^16.13.1",
|
|
77
81
|
"react-hot-loader": "^4.13.0",
|
|
78
82
|
"react-transform-hmr": "^1.0.2",
|
|
79
|
-
"style-loader": "^2.
|
|
83
|
+
"style-loader": "^3.2.1",
|
|
80
84
|
"timsort": "^0.3.0",
|
|
81
|
-
"webpack": "^5.
|
|
82
|
-
"webpack-cli": "^4.
|
|
83
|
-
"webpack-dev-server": "^
|
|
85
|
+
"webpack": "^5.51.1",
|
|
86
|
+
"webpack-cli": "^4.8.0",
|
|
87
|
+
"webpack-dev-server": "^4.0.0"
|
|
84
88
|
},
|
|
85
89
|
"peerDependencies": {
|
|
86
90
|
"react": ">= 16.3.0",
|
|
@@ -99,11 +103,21 @@
|
|
|
99
103
|
"testMatch": [
|
|
100
104
|
"<rootDir>/test/spec/*.js"
|
|
101
105
|
],
|
|
102
|
-
"
|
|
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
|
+
}
|
|
103
116
|
},
|
|
104
117
|
"lint-staged": {
|
|
105
118
|
"*.{js,jsx,css}": [
|
|
106
|
-
"
|
|
119
|
+
"eslint --ext .js,.jsx --fix",
|
|
120
|
+
"yarn fmt"
|
|
107
121
|
]
|
|
108
122
|
}
|
|
109
|
-
}
|
|
123
|
+
}
|
package/.husky/pre-commit
DELETED
package/.travis.yml
DELETED