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/.flowconfig CHANGED
@@ -1,5 +1,5 @@
1
1
  [version]
2
- ^0.145.0
2
+ ^0.158.0
3
3
 
4
4
  [ignore]
5
5
  <PROJECT_ROOT>/build/.*
@@ -11,10 +11,8 @@
11
11
  [include]
12
12
 
13
13
  [libs]
14
- interfaces/
15
14
  flow-typed/
16
15
 
17
16
  [options]
18
- sharedmemory.heap_size=3221225472
19
17
  emoji=true
20
18
  module.use_strict=true
package/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # Changelog
2
2
 
3
+ 1.3.0 (Aug 27, 2021)
4
+ ---
5
+
6
+ ### New Features
7
+ - `allowOverlap` prop, when `true`, allows overlapping grid items. [#1470](https://github.com/react-grid-layout/react-grid-layout/pull/1470)
8
+ - Add `onDropDragOver` callback. [#1395](https://github.com/react-grid-layout/react-grid-layout/pull/1395)
9
+ - Use this callback to dynamically adjust the `droppingItem` based on what is being dragged over. Return `w` and `h` to adjust the item. It is then [spread into the dropping placeholder](https://github.com/react-grid-layout/react-grid-layout/pull/1395/files#diff-83ab569936bfd4bf0460a4f23653ecbe8bc88509062c95e75c9402218b2b8733R609).
10
+ - This callback has the type:
11
+ - `onDragOver: (e: DragOverEvent) => { w: number, h: number } | false;`
12
+ - Return `false` to short-circuit the dragover.
13
+
14
+ ### Bugfixes
15
+ - Remove sorting when `compactType` is `null`. [#1474](https://github.com/react-grid-layout/react-grid-layout/pull/1474)
16
+ - Droppable fixes for Chrome behavior. [#1442](https://github.com/react-grid-layout/react-grid-layout/issues/1442) [#1448](https://github.com/react-grid-layout/react-grid-layout/issues/1442)
17
+ - Allow `null` children as a convenience so that inline expressions don't break the library. [#1296](https://github.com/react-grid-layout/react-grid-layout/pull/1296)
18
+ - Various dependency upgrades.
19
+
20
+ ### Documentation
21
+ - Add docs on using custom components as grid children.
22
+ - Note required class on resizable handles for proper styling.
23
+
24
+
25
+ 1.2.5 (May 10, 2021)
26
+ ---
27
+
28
+ ### Bugfixes
29
+ - Ensure no negative positions are possible when compacting
30
+ - Thanks @DonnyLi [#829](https://github.com/react-grid-layout/react-grid-layout/pull/829)
31
+ - Fixes [#535](https://github.com/react-grid-layout/react-grid-layout/issues/535)
32
+ - Fix resizing on mobile. This was caused by the `ref` refactor to remove ReactDOM in 1.2.3.
33
+ - Fixes #[1458](https://github.com/react-grid-layout/react-grid-layout/issues/1458)
34
+ - Note: this upgrades `react-resizable` to `3.0.1`, which like our other deps, is only compatible with `React@>=16.3`.
35
+
36
+ ### Documentation
37
+ - Document new arity of `resizeHandle` (`(axis: ResizeHandleAxis, ref: ReactRef<HTMLElement>) => React$Element`)
38
+ - Remove references to the deprecated `verticalCompact` prop
39
+
40
+ 1.2.4 (Mar 18, 2021)
41
+ ---
42
+
43
+ *This version fixes a serious render bug in `<WidthProvider>`. 1.2.3 should not be used.*
44
+
45
+ ### Bugfixes
46
+ - Fix failure to mount when layout is WidthProvider-wrapped and `measureBeforeMount` is `true`.
47
+ - Ref: [#1428](https://github.com/react-grid-layout/react-grid-layout/issues/1428)
48
+ - `<WidthProvider>` no longer updates grid with if it has been set to 0. This prevents unnecessary updates
49
+ if the grid is set to `display: none;`. Thanks @405go [#1427](https://github.com/react-grid-layout/react-grid-layout/pull/1427)
50
+
3
51
  1.2.3 (Mar 16, 2021)
4
52
  ---
5
53
 
package/README.md CHANGED
@@ -55,6 +55,7 @@ RGL is React-only and does not require jQuery.
55
55
  1. [Bounded Layout](https://react-grid-layout.github.io/react-grid-layout/examples/16-bounded.html)
56
56
  1. [Resizable Handles](https://react-grid-layout.github.io/react-grid-layout/examples/17-resizable-handles.html)
57
57
  1. [Scaled Containers](https://react-grid-layout.github.io/react-grid-layout/examples/18-scale.html)
58
+ 1. [Allow Overlap](https://react-grid-layout.github.io/react-grid-layout/examples/19-allow-overlap.html)
58
59
 
59
60
  #### Projects Using React-Grid-Layout
60
61
 
@@ -74,6 +75,7 @@ RGL is React-only and does not require jQuery.
74
75
  - [Hakkiri](https://www.hakkiri.io)
75
76
  - [Ubidots](https://help.ubidots.com/en/articles/2400308-create-dashboards-and-widgets)
76
77
  - [Statsout](https://statsout.com/)
78
+ - [Datto RMM](https://www.datto.com/uk/products/rmm/)
77
79
 
78
80
  *Know of others? Create a PR to let me know!*
79
81
 
@@ -266,6 +268,7 @@ cols: ?number = 12,
266
268
  // A CSS selector for tags that will not be draggable.
267
269
  // For example: draggableCancel:'.MyNonDraggableAreaClassName'
268
270
  // If you forget the leading . it will not work.
271
+ // .react-resizable-handle" is always prepended to this value.
269
272
  draggableCancel: ?string = '',
270
273
 
271
274
  // A CSS selector for tags that will act as the draggable handle.
@@ -273,9 +276,6 @@ draggableCancel: ?string = '',
273
276
  // If you forget the leading . it will not work.
274
277
  draggableHandle: ?string = '',
275
278
 
276
- // If true, the layout will compact vertically
277
- verticalCompact: ?boolean = true,
278
-
279
279
  // Compaction type.
280
280
  compactType: ?('vertical' | 'horizontal') = 'vertical';
281
281
 
@@ -318,9 +318,14 @@ useCSSTransforms: ?boolean = true,
318
318
  // we should set scale coefficient to avoid render artefacts while dragging.
319
319
  transformScale: ?number = 1,
320
320
 
321
+ // If true, grid can be placed one over the other.
322
+ // If set, implies `preventCollision`.
323
+ allowOverlap: ?boolean = false,
324
+
321
325
  // If true, grid items won't change position when being
322
- // dragged over.
323
- preventCollision: ?boolean = false;
326
+ // dragged over. If `allowOverlap` is still false,
327
+ // this simply won't allow one to drop on an existing object.
328
+ preventCollision: ?boolean = false,
324
329
 
325
330
  // If true, droppable elements (with `draggable={true}` attribute)
326
331
  // can be dropped on the grid. It triggers "onDrop" callback
@@ -332,7 +337,7 @@ preventCollision: ?boolean = false;
332
337
  // along with `draggable={true}` otherwise this feature will work incorrect.
333
338
  // onDragStart attribute is required for Firefox for a dragging initialization
334
339
  // @see https://bugzilla.mozilla.org/show_bug.cgi?id=568313
335
- isDroppable: ?boolean = false
340
+ isDroppable: ?boolean = false,
336
341
  // Defines which resize handles should be rendered
337
342
  // Allows for any combination of:
338
343
  // 's' - South handle (bottom-center)
@@ -343,9 +348,12 @@ isDroppable: ?boolean = false
343
348
  // 'nw' - Northwest handle (top-left)
344
349
  // 'se' - Southeast handle (bottom-right)
345
350
  // 'ne' - Northeast handle (top-right)
346
- resizeHandles: ?Array<'s' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne'> = ['se']
351
+ resizeHandles: ?Array<'s' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne'> = ['se'],
347
352
  // Custom component for resize handles
348
- resizeHandle?: ReactElement<any> | ((resizeHandleAxis: ResizeHandleAxis) => ReactElement<any>)
353
+ // See `handle` as used in https://github.com/react-grid-layout/react-resizable#resize-handle
354
+ // Your component should have the class `.react-resizable-handle`, or you should add your custom
355
+ // class to the `draggableCancel` prop.
356
+ resizeHandle?: ReactElement<any> | ((resizeHandleAxis: ResizeHandleAxis, ref: ReactRef<HTMLElement>) => ReactElement<any>),
349
357
 
350
358
  //
351
359
  // Callbacks
@@ -360,7 +368,7 @@ onLayoutChange: (layout: Layout) => void,
360
368
  // 'start' and 'stop' callbacks pass `undefined` for 'placeholder'.
361
369
  //
362
370
  type ItemCallback = (layout: Layout, oldItem: LayoutItem, newItem: LayoutItem,
363
- placeholder: LayoutItem, e: MouseEvent, element: HTMLElement) => void;
371
+ placeholder: LayoutItem, e: MouseEvent, element: HTMLElement) => void,
364
372
 
365
373
  // Calls when drag starts.
366
374
  onDragStart: ItemCallback,
@@ -374,12 +382,21 @@ onResizeStart: ItemCallback,
374
382
  onResize: ItemCallback,
375
383
  // Calls when resize is complete.
376
384
  onResizeStop: ItemCallback,
385
+
386
+ //
387
+ // Dropover functionality
388
+ //
389
+
377
390
  // Calls when an element has been dropped into the grid from outside.
378
- onDrop: (layout: Layout, item: ?LayoutItem, e: Event) => void
391
+ onDrop: (layout: Layout, item: ?LayoutItem, e: Event) => void,
392
+ // Calls when an element is being dragged over the grid from outside as above.
393
+ // This callback should return an object to dynamically change the droppingItem size
394
+ // Return false to short-circuit the dragover
395
+ onDropDragOver: (e: DragOverEvent) => ?({|w?: number, h?: number|} | false),
379
396
 
380
397
  // Ref for getting a reference for the grid's wrapping div.
381
398
  // You can use this instead of a regular ref and the deprecated `ReactDOM.findDOMNode()`` function.
382
- innerRef: ?React.Ref<"div">
399
+ innerRef: ?React.Ref<"div">,
383
400
  ```
384
401
 
385
402
  ### Responsive Grid Layout Props
@@ -397,16 +414,16 @@ cols: ?Object = {lg: 12, md: 10, sm: 6, xs: 4, xxs: 2},
397
414
 
398
415
 
399
416
  // margin (in pixels). Can be specified either as horizontal and vertical margin, e.g. `[10, 10]` or as a breakpoint -> margin map, e.g. `{lg: [10, 10], md: [10, 10], ...}.
400
- margin: [number, number] | {[breakpoint: $Keys<breakpoints>]: [number, number]}
417
+ margin: [number, number] | {[breakpoint: $Keys<breakpoints>]: [number, number]},
401
418
 
402
419
 
403
420
  // containerPadding (in pixels). Can be specified either as horizontal and vertical padding, e.g. `[10, 10]` or as a breakpoint -> containerPadding map, e.g. `{lg: [10, 10], md: [10, 10], ...}.
404
- containerPadding: [number, number] | {[breakpoint: $Keys<breakpoints>]: [number, number]}
421
+ containerPadding: [number, number] | {[breakpoint: $Keys<breakpoints>]: [number, number]},
405
422
 
406
423
 
407
424
  // layouts is an object mapping breakpoints to layouts.
408
425
  // e.g. {lg: Layout, md: Layout, ...}
409
- layouts: {[key: $Keys<breakpoints>]: Layout}
426
+ layouts: {[key: $Keys<breakpoints>]: Layout},
410
427
 
411
428
  //
412
429
  // Callbacks
@@ -509,11 +526,34 @@ function MyGrid(props) {
509
526
 
510
527
  Because the `children` prop doesn't change between rerenders, updates to `<MyGrid>` won't result in new renders, improving performance.
511
528
 
529
+ ### Custom Child Components and Draggable Handles
530
+
531
+ If you use React Components as grid children, they need to do a few things:
532
+
533
+ 1. Forward refs to an underlying DOM node, and
534
+ 2. Forward `style` and `className` to that same DOM node.
535
+
536
+ For example:
537
+
538
+ ```js
539
+ const CustomGridItemComponent = React.forwardRef(({style, className, ...props}, ref) => {
540
+ return (
541
+ <div style={{ /* styles */, ...style}} className={className} ref={ref}>
542
+ {/* Some other content */}
543
+ </div>
544
+ );
545
+ }
546
+ ```
547
+
548
+ The same is true of custom elements as draggable handles using the `draggableHandle` prop. This is so that
549
+ the underlying `react-draggable` library can get a reference to the DOM node underneath, manipulate
550
+ positioning via `style`, and set classes.
551
+
512
552
  ## Contribute
513
553
 
514
554
  If you have a feature request, please add it as an issue or make a pull request.
515
555
 
516
- If you have a bug to report, please reproduce the bug in [CodeSandbox](https://codesandbox.io/s/5wy3rz5z1x?module=%2Fsrc%2FShowcaseLayout.js) to help
556
+ If you have a bug to report, please reproduce the bug in [CodeSandbox](https://codesandbox.io/s/staging-bush-3lvt7?file=/src/ShowcaseLayout.js) to help
517
557
  us easily isolate it.
518
558
 
519
559
  ## TODO List
@@ -529,5 +569,5 @@ us easily isolate it.
529
569
  - [x] Static elements
530
570
  - [x] Persistent id per item for predictable localstorage restores, even when # items changes
531
571
  - [x] Min/max w/h per item
532
- - [ ] Resizable handles on other corners
572
+ - [x] Resizable handles on other corners
533
573
  - [ ] Configurable w/h per breakpoint
package/build/GridItem.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -21,27 +21,27 @@ var _calculateUtils = require("./calculateUtils");
21
21
 
22
22
  var _ReactGridLayoutPropTypes = require("./ReactGridLayoutPropTypes");
23
23
 
24
- var _classnames = _interopRequireDefault(require("classnames"));
24
+ var _clsx = _interopRequireDefault(require("clsx"));
25
25
 
26
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
27
 
28
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
28
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
29
29
 
30
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
30
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
31
31
 
32
32
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
33
33
 
34
34
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
35
35
 
36
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
36
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
37
37
 
38
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
38
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
39
39
 
40
40
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
41
41
 
42
42
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
43
43
 
44
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
44
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
45
45
 
46
46
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
47
47
 
@@ -414,10 +414,10 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
414
414
  var maxes = (0, _calculateUtils.calcGridItemPosition)(positionParams, 0, 0, maxW, maxH);
415
415
  var minConstraints = [mins.width, mins.height];
416
416
  var maxConstraints = [Math.min(maxes.width, maxWidth), Math.min(maxes.height, Infinity)];
417
- return /*#__PURE__*/_react.default.createElement(_reactResizable.Resizable, {
417
+ return /*#__PURE__*/_react.default.createElement(_reactResizable.Resizable // These are opts for the resize handle itself
418
+ , {
418
419
  draggableOpts: {
419
- disabled: !isResizable,
420
- nodeRef: this.elementRef
420
+ disabled: !isResizable
421
421
  },
422
422
  className: isResizable ? undefined : "react-resizable-hide",
423
423
  width: position.width,
@@ -512,7 +512,7 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
512
512
 
513
513
  var newChild = /*#__PURE__*/_react.default.cloneElement(child, {
514
514
  ref: this.elementRef,
515
- className: (0, _classnames.default)("react-grid-item", child.props.className, this.props.className, {
515
+ className: (0, _clsx.default)("react-grid-item", child.props.className, this.props.className, {
516
516
  static: this.props.static,
517
517
  resizing: Boolean(this.state.resizing),
518
518
  "react-draggable": isDraggable,
@@ -592,7 +592,7 @@ _defineProperty(GridItem, "propTypes", {
592
592
  // ID is nice to have for callbacks
593
593
  i: _propTypes.default.string.isRequired,
594
594
  // Resize handle options
595
- resizeHandles: _ReactGridLayoutPropTypes.resizeHandlesType,
595
+ resizeHandles: _ReactGridLayoutPropTypes.resizeHandleAxesType,
596
596
  resizeHandle: _ReactGridLayoutPropTypes.resizeHandleType,
597
597
  // Functions
598
598
  onDragStop: _propTypes.default.func,