react-grid-layout 1.2.3 → 1.3.1

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/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.key),
163
- React.Children.map(b, c => c.key)
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
- // There was a collision; abort
468
- if (preventCollision && collisions.length) {
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
- else return sortLayoutItemsByRowCol(layout);
639
+ if (compactType === "vertical") return sortLayoutItemsByRowCol(layout);
640
+ else return layout;
625
641
  }
626
642
 
627
643
  /**
@@ -671,17 +687,21 @@ 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>, i: number) => {
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[i] = cloneLayoutItem(exists);
704
+ layout.push(cloneLayoutItem(exists));
685
705
  } else {
686
706
  if (!isProduction && child.props._grid) {
687
707
  console.warn(
@@ -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[i] = cloneLayoutItem({ ...g, i: child.key });
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[i] = cloneLayoutItem({
705
- w: 1,
706
- h: 1,
707
- x: 0,
708
- y: bottom(layout),
709
- i: String(child.key)
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 compact(correctedLayout, compactType, cols);
739
+ return allowOverlap
740
+ ? correctedLayout
741
+ : compact(correctedLayout, compactType, cols);
718
742
  }
719
743
 
720
744
  /**
@@ -771,11 +795,6 @@ export function compactType(
771
795
  return verticalCompact === false ? null : compactType;
772
796
  }
773
797
 
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
798
  function log(...args) {
780
799
  if (!DEBUG) return;
781
800
  // 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",
3
+ "version": "1.3.1",
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,53 @@
35
35
  },
36
36
  "homepage": "https://github.com/STRML/react-grid-layout",
37
37
  "dependencies": {
38
- "classnames": "2.x",
38
+ "clsx": "^1.1.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": "^1.10.0"
42
+ "react-resizable": "^3.0.4"
43
43
  },
44
44
  "devDependencies": {
45
- "@babel/cli": "^7.13.0",
46
- "@babel/core": "^7.13.8",
47
- "@babel/plugin-proposal-class-properties": "^7.13.0",
48
- "@babel/plugin-transform-flow-comments": "^7.12.13",
49
- "@babel/preset-env": "^7.13.8",
50
- "@babel/preset-flow": "^7.12.13",
51
- "@babel/preset-react": "^7.12.13",
52
- "@babel/register": "^7.13.8",
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": "^26.6.3",
55
+ "babel-jest": "^27.0.6",
55
56
  "babel-loader": "^8.2.2",
56
57
  "babel-plugin-preval": "^5.0.0",
57
- "css-loader": "^5.1.1",
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.1",
62
- "eslint": "^7.21.0",
63
- "eslint-plugin-flowtype": "^5.3.1",
64
- "eslint-plugin-mocha": "^8.0.0",
65
- "eslint-plugin-react": "^7.22.0",
66
- "exports-loader": "^2.0.0",
67
- "flow-bin": "^0.145.0",
68
- "husky": "^5.1.2",
69
- "imports-loader": "^2.0.0",
70
- "jest": "^26.6.3",
71
- "lint-staged": "^10.5.4",
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.1",
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.0.0",
80
+ "style-loader": "^3.2.1",
80
81
  "timsort": "^0.3.0",
81
- "webpack": "^5.24.2",
82
- "webpack-cli": "^4.5.0",
83
- "webpack-dev-server": "^3.11.2"
82
+ "webpack": "^5.51.1",
83
+ "webpack-cli": "^4.8.0",
84
+ "webpack-dev-server": "^4.0.0"
84
85
  },
85
86
  "peerDependencies": {
86
87
  "react": ">= 16.3.0",
@@ -99,6 +100,7 @@
99
100
  "testMatch": [
100
101
  "<rootDir>/test/spec/*.js"
101
102
  ],
103
+ "testEnvironment": "jsdom",
102
104
  "testURL": "http://localhost"
103
105
  },
104
106
  "lint-staged": {
package/.husky/pre-commit DELETED
@@ -1,6 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- yarn lint-staged
5
- make lint
6
- make test
package/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - 10
4
- - 12
5
- - "lts/*"
6
- script:
7
- - make build test
8
- cache: yarn
9
-
@@ -1,5 +0,0 @@
1
- /*!
2
- Copyright (c) 2017 Jed Watson.
3
- Licensed under the MIT License (MIT), see
4
- http://jedwatson.github.io/classnames
5
- */