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/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 = require("./build/ResponsiveReactGridLayout").default;
3
+ module.exports.Responsive =
4
+ require("./build/ResponsiveReactGridLayout").default;
4
5
  module.exports.Responsive.utils = require("./build/responsiveUtils");
5
- module.exports.WidthProvider = require("./build/components/WidthProvider").default;
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 classNames from "classnames";
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(positionParams, 0, 0, cols - x, 0)
385
- .width;
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: classNames(
642
+ className: clsx(
638
643
  "react-grid-item",
639
644
  child.props.className,
640
645
  this.props.className,
@@ -2,7 +2,7 @@
2
2
  import * as React from "react";
3
3
 
4
4
  import isEqual from "lodash.isequal";
5
- import classNames from "classnames";
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: this.state.layout
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
- this.props.preventCollision,
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 = { left: layerX / transformScale, top: layerY / transformScale, e };
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 = classNames(layoutClassName, className);
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 classNames from "classnames";
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={classNames(this.props.className, layoutClassName)}
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
- // There was a collision; abort
474
- if (preventCollision && collisions.length) {
475
- if (!allowOverlap) {
476
- log(`Collision prevented on ${l.i}, reverting.`);
477
- l.x = oldX;
478
- l.y = oldY;
479
- l.moved = false;
480
- }
481
- return layout;
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. " + // eslint-disable-line
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(cloneLayoutItem({
718
- w: 1,
719
- h: 1,
720
- x: 0,
721
- y: bottom(layout),
722
- i: String(child.key)
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.0",
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
- "classnames": "2.3.1",
40
+ "clsx": "^1.1.1",
39
41
  "lodash.isequal": "^4.0.0",
40
- "prop-types": "^15.0.0",
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.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",
54
- "babel-eslint": "^10.1.0",
55
- "babel-jest": "^27.0.6",
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.0.0",
58
- "css-loader": "^6.2.0",
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": "^7.32.0",
64
- "eslint-plugin-flowtype": "^5.9.0",
65
- "eslint-plugin-mocha": "^9.0.0",
66
- "eslint-plugin-react": "^7.24.0",
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.158.0",
71
+ "flow-bin": "^0.172.0",
69
72
  "husky": "^7.0.2",
70
73
  "imports-loader": "^3.0.0",
71
- "jest": "^27.0.6",
72
- "lint-staged": "^11.1.2",
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.51.1",
83
- "webpack-cli": "^4.8.0",
84
- "webpack-dev-server": "^4.0.0"
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
- "prettier --write"
119
+ "eslint --ext .js,.jsx --fix",
120
+ "yarn fmt"
109
121
  ]
110
122
  }
111
- }
123
+ }
@@ -1,5 +0,0 @@
1
- /*!
2
- Copyright (c) 2018 Jed Watson.
3
- Licensed under the MIT License (MIT), see
4
- http://jedwatson.github.io/classnames
5
- */