react-grid-layout 1.3.0 → 1.3.4
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 +2 -1
- package/.prettierignore +1 -0
- package/CHANGELOG.md +377 -262
- package/README.md +73 -51
- package/build/GridItem.js +7 -7
- package/build/ReactGridLayout.js +14 -10
- package/build/ReactGridLayoutPropTypes.js +1 -1
- package/build/ResponsiveReactGridLayout.js +5 -5
- package/build/calculateUtils.js +2 -2
- package/build/components/WidthProvider.js +8 -8
- package/build/responsiveUtils.js +1 -1
- package/build/utils.js +31 -33
- 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 +13 -6
- package/lib/components/WidthProvider.jsx +2 -2
- package/lib/utils.js +27 -32
- package/package.json +42 -30
- package/dist/react-grid-layout.min.js.LICENSE.txt +0 -5
- package/foo.html +0 -388
package/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
module.exports = require("./build/ReactGridLayout").default;
|
|
2
2
|
module.exports.utils = require("./build/utils");
|
|
3
|
-
module.exports.Responsive =
|
|
3
|
+
module.exports.Responsive =
|
|
4
|
+
require("./build/ResponsiveReactGridLayout").default;
|
|
4
5
|
module.exports.Responsive.utils = require("./build/responsiveUtils");
|
|
5
|
-
module.exports.WidthProvider =
|
|
6
|
+
module.exports.WidthProvider =
|
|
7
|
+
require("./build/components/WidthProvider").default;
|
package/lib/GridItem.jsx
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
resizeHandleAxesType,
|
|
17
17
|
resizeHandleType
|
|
18
18
|
} from "./ReactGridLayoutPropTypes";
|
|
19
|
-
import
|
|
19
|
+
import clsx from "clsx";
|
|
20
20
|
import type { Element as ReactElement, Node as ReactNode } from "react";
|
|
21
21
|
|
|
22
22
|
import type {
|
|
@@ -381,8 +381,13 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
381
381
|
const positionParams = this.getPositionParams();
|
|
382
382
|
|
|
383
383
|
// This is the max possible width - doesn't go to infinity because of the width of the window
|
|
384
|
-
const maxWidth = calcGridItemPosition(
|
|
385
|
-
|
|
384
|
+
const maxWidth = calcGridItemPosition(
|
|
385
|
+
positionParams,
|
|
386
|
+
0,
|
|
387
|
+
0,
|
|
388
|
+
cols - x,
|
|
389
|
+
0
|
|
390
|
+
).width;
|
|
386
391
|
|
|
387
392
|
// Calculate min/max constraints using our min & maxes
|
|
388
393
|
const mins = calcGridItemPosition(positionParams, 0, 0, minW, minH);
|
|
@@ -396,7 +401,7 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
396
401
|
<Resizable
|
|
397
402
|
// These are opts for the resize handle itself
|
|
398
403
|
draggableOpts={{
|
|
399
|
-
disabled: !isResizable
|
|
404
|
+
disabled: !isResizable
|
|
400
405
|
}}
|
|
401
406
|
className={isResizable ? undefined : "react-resizable-hide"}
|
|
402
407
|
width={position.width}
|
|
@@ -634,7 +639,7 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
634
639
|
// Create the child element. We clone the existing element but modify its className and style.
|
|
635
640
|
let newChild = React.cloneElement(child, {
|
|
636
641
|
ref: this.elementRef,
|
|
637
|
-
className:
|
|
642
|
+
className: clsx(
|
|
638
643
|
"react-grid-item",
|
|
639
644
|
child.props.className,
|
|
640
645
|
this.props.className,
|
package/lib/ReactGridLayout.jsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
4
|
import isEqual from "lodash.isequal";
|
|
5
|
-
import
|
|
5
|
+
import clsx from "clsx";
|
|
6
6
|
import {
|
|
7
7
|
bottom,
|
|
8
8
|
childrenEqual,
|
|
@@ -252,7 +252,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
252
252
|
|
|
253
253
|
this.setState({
|
|
254
254
|
oldDragItem: cloneLayoutItem(l),
|
|
255
|
-
oldLayout:
|
|
255
|
+
oldLayout: layout
|
|
256
256
|
});
|
|
257
257
|
|
|
258
258
|
return this.props.onDragStart(layout, l, l, null, e, node);
|
|
@@ -274,7 +274,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
274
274
|
) => {
|
|
275
275
|
const { oldDragItem } = this.state;
|
|
276
276
|
let { layout } = this.state;
|
|
277
|
-
const { cols, allowOverlap } = this.props;
|
|
277
|
+
const { cols, allowOverlap, preventCollision } = this.props;
|
|
278
278
|
const l = getLayoutItem(layout, i);
|
|
279
279
|
if (!l) return;
|
|
280
280
|
|
|
@@ -296,7 +296,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
296
296
|
x,
|
|
297
297
|
y,
|
|
298
298
|
isUserAction,
|
|
299
|
-
|
|
299
|
+
preventCollision,
|
|
300
300
|
compactType(this.props),
|
|
301
301
|
cols,
|
|
302
302
|
allowOverlap
|
|
@@ -659,7 +659,11 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
659
659
|
const { layout } = this.state;
|
|
660
660
|
// This is relative to the DOM element that this event fired for.
|
|
661
661
|
const { layerX, layerY } = e.nativeEvent;
|
|
662
|
-
const droppingPosition = {
|
|
662
|
+
const droppingPosition = {
|
|
663
|
+
left: layerX / transformScale,
|
|
664
|
+
top: layerY / transformScale,
|
|
665
|
+
e
|
|
666
|
+
};
|
|
663
667
|
|
|
664
668
|
if (!this.state.droppingDOMNode) {
|
|
665
669
|
const positionParams: PositionParams = {
|
|
@@ -722,6 +726,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
722
726
|
|
|
723
727
|
onDragLeave: EventHandler = e => {
|
|
724
728
|
e.preventDefault(); // Prevent any browser native action
|
|
729
|
+
e.stopPropagation();
|
|
725
730
|
this.dragEnterCounter--;
|
|
726
731
|
|
|
727
732
|
// onDragLeave can be triggered on each layout's child.
|
|
@@ -736,11 +741,13 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
736
741
|
|
|
737
742
|
onDragEnter: EventHandler = e => {
|
|
738
743
|
e.preventDefault(); // Prevent any browser native action
|
|
744
|
+
e.stopPropagation();
|
|
739
745
|
this.dragEnterCounter++;
|
|
740
746
|
};
|
|
741
747
|
|
|
742
748
|
onDrop: EventHandler = (e: Event) => {
|
|
743
749
|
e.preventDefault(); // Prevent any browser native action
|
|
750
|
+
e.stopPropagation();
|
|
744
751
|
const { droppingItem } = this.props;
|
|
745
752
|
const { layout } = this.state;
|
|
746
753
|
const item = layout.find(l => l.i === droppingItem.i);
|
|
@@ -756,7 +763,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
756
763
|
render(): React.Element<"div"> {
|
|
757
764
|
const { className, style, isDroppable, innerRef } = this.props;
|
|
758
765
|
|
|
759
|
-
const mergedClassName =
|
|
766
|
+
const mergedClassName = clsx(layoutClassName, className);
|
|
760
767
|
const mergedStyle = {
|
|
761
768
|
height: this.containerHeight(),
|
|
762
769
|
...style
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
|
-
import
|
|
4
|
+
import clsx from "clsx";
|
|
5
5
|
import type { ReactRef } from "../ReactGridLayoutPropTypes";
|
|
6
6
|
|
|
7
7
|
type WPDefaultProps = {|
|
|
@@ -88,7 +88,7 @@ export default function WidthProvideRGL<Config>(
|
|
|
88
88
|
if (measureBeforeMount && !this.mounted) {
|
|
89
89
|
return (
|
|
90
90
|
<div
|
|
91
|
-
className={
|
|
91
|
+
className={clsx(this.props.className, layoutClassName)}
|
|
92
92
|
style={this.props.style}
|
|
93
93
|
// $FlowIgnore ref types
|
|
94
94
|
ref={this.elementRef}
|
package/lib/utils.js
CHANGED
|
@@ -469,16 +469,23 @@ export function moveElement(
|
|
|
469
469
|
// $FlowIgnore acceptable modification of read-only array as it was recently cloned
|
|
470
470
|
if (movingUp) sorted = sorted.reverse();
|
|
471
471
|
const collisions = getAllCollisions(sorted, l);
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
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.
|
|
484
|
+
log(`Collision prevented on ${l.i}, reverting.`);
|
|
485
|
+
l.x = oldX;
|
|
486
|
+
l.y = oldY;
|
|
487
|
+
l.moved = false;
|
|
488
|
+
return layout; // did not change so don't clone
|
|
482
489
|
}
|
|
483
490
|
|
|
484
491
|
// Move each item that collides away from this element.
|
|
@@ -698,7 +705,7 @@ export function synchronizeLayoutWithChildren(
|
|
|
698
705
|
} else {
|
|
699
706
|
if (!isProduction && child.props._grid) {
|
|
700
707
|
console.warn(
|
|
701
|
-
"`_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. " +
|
|
702
709
|
"Please use `data-grid` or add your properties directly to the `layout`."
|
|
703
710
|
);
|
|
704
711
|
}
|
|
@@ -714,13 +721,15 @@ export function synchronizeLayoutWithChildren(
|
|
|
714
721
|
} else {
|
|
715
722
|
// Nothing provided: ensure this is added to the bottom
|
|
716
723
|
// FIXME clone not really necessary here
|
|
717
|
-
layout.push(
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
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
|
+
);
|
|
724
733
|
}
|
|
725
734
|
}
|
|
726
735
|
});
|
|
@@ -761,20 +770,6 @@ export function validateLayout(
|
|
|
761
770
|
);
|
|
762
771
|
}
|
|
763
772
|
}
|
|
764
|
-
if (item.i && typeof item.i !== "string") {
|
|
765
|
-
throw new Error(
|
|
766
|
-
"ReactGridLayout: " + contextName + "[" + i + "].i must be a string!"
|
|
767
|
-
);
|
|
768
|
-
}
|
|
769
|
-
if (item.static !== undefined && typeof item.static !== "boolean") {
|
|
770
|
-
throw new Error(
|
|
771
|
-
"ReactGridLayout: " +
|
|
772
|
-
contextName +
|
|
773
|
-
"[" +
|
|
774
|
-
i +
|
|
775
|
-
"].static must be a boolean!"
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
773
|
}
|
|
779
774
|
}
|
|
780
775
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-grid-layout",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
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,41 +37,42 @@
|
|
|
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
|
-
"prop-types": "^15.
|
|
42
|
+
"prop-types": "^15.8.1",
|
|
41
43
|
"react-draggable": "^4.0.0",
|
|
42
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": "^27.
|
|
47
|
+
"@babel/cli": "^7.17.3",
|
|
48
|
+
"@babel/core": "^7.17.5",
|
|
49
|
+
"@babel/eslint-parser": "^7.17.0",
|
|
50
|
+
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
51
|
+
"@babel/plugin-transform-flow-comments": "^7.16.7",
|
|
52
|
+
"@babel/preset-env": "^7.16.11",
|
|
53
|
+
"@babel/preset-flow": "^7.16.7",
|
|
54
|
+
"@babel/preset-react": "^7.16.7",
|
|
55
|
+
"@babel/register": "^7.17.0",
|
|
56
|
+
"@webpack-cli/serve": "^1.6.1",
|
|
57
|
+
"babel-jest": "^27.5.1",
|
|
56
58
|
"babel-loader": "^8.2.2",
|
|
57
|
-
"babel-plugin-preval": "^5.
|
|
58
|
-
"css-loader": "^6.
|
|
59
|
+
"babel-plugin-preval": "^5.1.0",
|
|
60
|
+
"css-loader": "^6.6.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": "^
|
|
64
|
-
"eslint-plugin-flowtype": "^
|
|
65
|
-
"eslint-plugin-mocha": "^
|
|
66
|
-
"eslint-plugin-react": "^7.
|
|
65
|
+
"eslint": "^8.9.0",
|
|
66
|
+
"eslint-plugin-flowtype": "^8.0.3",
|
|
67
|
+
"eslint-plugin-mocha": "^10.0.3",
|
|
68
|
+
"eslint-plugin-react": "^7.28.0",
|
|
69
|
+
"eslint-plugin-unicorn": "^41.0.0",
|
|
67
70
|
"exports-loader": "^3.0.0",
|
|
68
|
-
"flow-bin": "^0.
|
|
71
|
+
"flow-bin": "^0.172.0",
|
|
69
72
|
"husky": "^7.0.2",
|
|
70
73
|
"imports-loader": "^3.0.0",
|
|
71
|
-
"jest": "^27.
|
|
72
|
-
"lint-staged": "^
|
|
74
|
+
"jest": "^27.5.1",
|
|
75
|
+
"lint-staged": "^12.3.4",
|
|
73
76
|
"lodash": "^4.17.21",
|
|
74
77
|
"opener": "^1.5.2",
|
|
75
78
|
"prettier": "^2.3.2",
|
|
@@ -79,9 +82,9 @@
|
|
|
79
82
|
"react-transform-hmr": "^1.0.2",
|
|
80
83
|
"style-loader": "^3.2.1",
|
|
81
84
|
"timsort": "^0.3.0",
|
|
82
|
-
"webpack": "^5.
|
|
83
|
-
"webpack-cli": "^4.
|
|
84
|
-
"webpack-dev-server": "^4.
|
|
85
|
+
"webpack": "^5.69.1",
|
|
86
|
+
"webpack-cli": "^4.9.2",
|
|
87
|
+
"webpack-dev-server": "^4.7.4"
|
|
85
88
|
},
|
|
86
89
|
"peerDependencies": {
|
|
87
90
|
"react": ">= 16.3.0",
|
|
@@ -101,11 +104,20 @@
|
|
|
101
104
|
"<rootDir>/test/spec/*.js"
|
|
102
105
|
],
|
|
103
106
|
"testEnvironment": "jsdom",
|
|
104
|
-
"testURL": "http://localhost"
|
|
107
|
+
"testURL": "http://localhost",
|
|
108
|
+
"coverageThreshold": {
|
|
109
|
+
"global": {
|
|
110
|
+
"statements": 77,
|
|
111
|
+
"branches": 72,
|
|
112
|
+
"functions": 77,
|
|
113
|
+
"lines": 78
|
|
114
|
+
}
|
|
115
|
+
}
|
|
105
116
|
},
|
|
106
117
|
"lint-staged": {
|
|
107
118
|
"*.{js,jsx,css}": [
|
|
108
|
-
"
|
|
119
|
+
"eslint --ext .js,.jsx --fix",
|
|
120
|
+
"yarn fmt"
|
|
109
121
|
]
|
|
110
122
|
}
|
|
111
|
-
}
|
|
123
|
+
}
|