react-grid-layout 1.3.0 → 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/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 {
@@ -634,7 +634,7 @@ export default class GridItem extends React.Component<Props, State> {
634
634
  // Create the child element. We clone the existing element but modify its className and style.
635
635
  let newChild = React.cloneElement(child, {
636
636
  ref: this.elementRef,
637
- className: classNames(
637
+ className: clsx(
638
638
  "react-grid-item",
639
639
  child.props.className,
640
640
  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 = {
@@ -756,7 +760,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
756
760
  render(): React.Element<"div"> {
757
761
  const { className, style, isDroppable, innerRef } = this.props;
758
762
 
759
- const mergedClassName = classNames(layoutClassName, className);
763
+ const mergedClassName = clsx(layoutClassName, className);
760
764
  const mergedStyle = {
761
765
  height: this.containerHeight(),
762
766
  ...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.
@@ -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
  });
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.1",
4
4
  "description": "A draggable and resizable grid layout with responsive breakpoints, for React.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "homepage": "https://github.com/STRML/react-grid-layout",
37
37
  "dependencies": {
38
- "classnames": "2.3.1",
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",
@@ -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
- */