react-grid-layout 1.4.3 → 1.4.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/lib/GridItem.jsx CHANGED
@@ -503,15 +503,15 @@ export default class GridItem extends React.Component<Props, State> {
503
503
  const { offsetParent } = node;
504
504
 
505
505
  if (offsetParent) {
506
- const { margin, rowHeight } = this.props;
506
+ const { margin, rowHeight, containerPadding } = this.props;
507
507
  const bottomBoundary =
508
508
  offsetParent.clientHeight - calcGridItemWHPx(h, rowHeight, margin[1]);
509
- top = clamp(top, 0, bottomBoundary);
509
+ top = clamp(top - containerPadding[1], 0, bottomBoundary);
510
510
 
511
511
  const colWidth = calcGridColWidth(positionParams);
512
512
  const rightBoundary =
513
513
  containerWidth - calcGridItemWHPx(w, colWidth, margin[0]);
514
- left = clamp(left, 0, rightBoundary);
514
+ left = clamp(left - containerPadding[0], 0, rightBoundary);
515
515
  }
516
516
  }
517
517
 
@@ -519,7 +519,14 @@ export default class GridItem extends React.Component<Props, State> {
519
519
  this.setState({ dragging: newPosition });
520
520
 
521
521
  // Call callback with this data
522
- const { x, y } = calcXY(positionParams, top, left, w, h);
522
+ const { containerPadding } = this.props;
523
+ const { x, y } = calcXY(
524
+ positionParams,
525
+ top - containerPadding[1],
526
+ left - containerPadding[0],
527
+ w,
528
+ h
529
+ );
523
530
  return onDrag.call(this, i, x, y, {
524
531
  e,
525
532
  node,
@@ -539,12 +546,18 @@ export default class GridItem extends React.Component<Props, State> {
539
546
  if (!this.state.dragging) {
540
547
  throw new Error("onDragEnd called before onDragStart.");
541
548
  }
542
- const { w, h, i } = this.props;
549
+ const { w, h, i, containerPadding } = this.props;
543
550
  const { left, top } = this.state.dragging;
544
551
  const newPosition: PartialPosition = { top, left };
545
552
  this.setState({ dragging: null });
546
553
 
547
- const { x, y } = calcXY(this.getPositionParams(), top, left, w, h);
554
+ const { x, y } = calcXY(
555
+ this.getPositionParams(),
556
+ top - containerPadding[1],
557
+ left - containerPadding[0],
558
+ w,
559
+ h
560
+ );
548
561
 
549
562
  return onDragStop.call(this, i, x, y, {
550
563
  e,
@@ -251,7 +251,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
251
251
  const { layout } = this.state;
252
252
  const l = getLayoutItem(layout, i);
253
253
  if (!l) return;
254
-
254
+
255
255
  // Create placeholder (display only)
256
256
  const placeholder = {
257
257
  w: l.w,
@@ -413,7 +413,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
413
413
  { e, node, size, handle }
414
414
  ) => {
415
415
  const { oldResizeItem } = this.state;
416
- let { layout } = this.state;
416
+ const { layout } = this.state;
417
417
  const { cols, preventCollision, allowOverlap } = this.props;
418
418
 
419
419
  let shouldMoveItem = false;
@@ -714,8 +714,13 @@ export default class ReactGridLayout extends React.Component<Props, State> {
714
714
  const finalDroppingItem = { ...droppingItem, ...onDragOverResult };
715
715
 
716
716
  const { layout } = this.state;
717
- // This is relative to the DOM element that this event fired for.
718
- const { layerX, layerY } = e.nativeEvent;
717
+
718
+ // $FlowIgnore missing def
719
+ const gridRect = e.currentTarget.getBoundingClientRect(); // The grid's position in the viewport
720
+
721
+ // Calculate the mouse position relative to the grid
722
+ const layerX = e.clientX - gridRect.left;
723
+ const layerY = e.clientY - gridRect.top;
719
724
  const droppingPosition = {
720
725
  left: layerX / transformScale,
721
726
  top: layerY / transformScale,
package/lib/utils.js CHANGED
@@ -497,8 +497,8 @@ export function moveElement(
497
497
  compactType === "vertical" && typeof y === "number"
498
498
  ? oldY >= y
499
499
  : compactType === "horizontal" && typeof x === "number"
500
- ? oldX >= x
501
- : false;
500
+ ? oldX >= x
501
+ : false;
502
502
  // $FlowIgnore acceptable modification of read-only array as it was recently cloned
503
503
  if (movingUp) sorted = sorted.reverse();
504
504
  const collisions = getAllCollisions(sorted, l);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-grid-layout",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "A draggable and resizable grid layout with responsive breakpoints, for React.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,8 +13,8 @@
13
13
  "prepublishOnly": "make build",
14
14
  "validate": "npm ls",
15
15
  "flow": "flow",
16
- "fmt": "prettier --write ./**.{json,js,yml,md}",
17
- "fmt:check": "prettier --check ./**.{json,js,yml,md}"
16
+ "fmt": "prettier --write .",
17
+ "fmt:check": "prettier --check ."
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -48,17 +48,17 @@
48
48
  "fast-equals": "Bug in CRA5 causes fast-equals@5 to fail to import due to .cjs file. See https://github.com/react-grid-layout/react-grid-layout/issues/1904"
49
49
  },
50
50
  "devDependencies": {
51
- "@babel/cli": "^7.22.15",
52
- "@babel/core": "^7.22.17",
53
- "@babel/eslint-parser": "^7.22.15",
51
+ "@babel/cli": "^7.23.4",
52
+ "@babel/core": "^7.23.3",
53
+ "@babel/eslint-parser": "^7.23.3",
54
54
  "@babel/plugin-proposal-class-properties": "^7.18.6",
55
- "@babel/plugin-transform-flow-comments": "^7.22.10",
56
- "@babel/preset-env": "^7.22.15",
57
- "@babel/preset-flow": "^7.22.15",
58
- "@babel/preset-react": "^7.22.15",
55
+ "@babel/plugin-transform-flow-comments": "^7.23.3",
56
+ "@babel/preset-env": "^7.23.3",
57
+ "@babel/preset-flow": "^7.23.3",
58
+ "@babel/preset-react": "^7.23.3",
59
59
  "@babel/register": "^7.22.15",
60
60
  "@webpack-cli/serve": "^2.0.5",
61
- "babel-jest": "^29.6.4",
61
+ "babel-jest": "^29.7.0",
62
62
  "babel-loader": "^9.1.3",
63
63
  "babel-plugin-preval": "^5.1.0",
64
64
  "css-loader": "^6.8.1",
@@ -66,28 +66,28 @@
66
66
  "enzyme": "^3.11.0",
67
67
  "enzyme-adapter-react-16": "^1.15.7",
68
68
  "enzyme-to-json": "^3.6.2",
69
- "eslint": "^8.49.0",
69
+ "eslint": "^8.54.0",
70
70
  "eslint-plugin-flowtype": "^8.0.3",
71
- "eslint-plugin-mocha": "^10.1.0",
71
+ "eslint-plugin-mocha": "^10.2.0",
72
72
  "eslint-plugin-react": "^7.33.2",
73
- "eslint-plugin-unicorn": "^48.0.1",
73
+ "eslint-plugin-unicorn": "^49.0.0",
74
74
  "exports-loader": "^4.0.0",
75
75
  "flow-bin": "^0.172.0",
76
76
  "husky": "^8.0.3",
77
77
  "imports-loader": "^4.0.1",
78
- "jest": "^29.6.4",
79
- "jest-environment-jsdom": "^29.6.4",
80
- "lint-staged": "^14.0.1",
78
+ "jest": "^29.7.0",
79
+ "jest-environment-jsdom": "^29.7.0",
80
+ "lint-staged": "^15.1.0",
81
81
  "lodash": "^4.17.21",
82
82
  "opener": "^1.5.2",
83
- "prettier": "^3.0.3",
83
+ "prettier": "^3.1.0",
84
84
  "react": "^16.13.1",
85
85
  "react-dom": "^16.13.1",
86
86
  "react-hot-loader": "^4.13.1",
87
87
  "react-transform-hmr": "^1.0.2",
88
88
  "style-loader": "^3.3.3",
89
89
  "timsort": "^0.3.0",
90
- "webpack": "^5.88.2",
90
+ "webpack": "^5.89.0",
91
91
  "webpack-cli": "^5.1.4",
92
92
  "webpack-dev-server": "^4.15.1"
93
93
  },