react-grid-layout 1.3.4 → 1.4.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 +1 -0
- package/.prettierignore +2 -1
- package/.prettierrc +0 -1
- package/CHANGELOG.md +36 -0
- package/README.md +35 -6
- package/build/GridItem.js +483 -493
- package/build/ReactGridLayout.js +534 -592
- package/build/ReactGridLayoutPropTypes.js +43 -48
- package/build/ResponsiveReactGridLayout.js +144 -238
- package/build/calculateUtils.js +76 -115
- package/build/components/WidthProvider.js +79 -122
- package/build/responsiveUtils.js +33 -63
- package/build/utils.js +402 -442
- package/css/styles.css +8 -3
- package/dist/react-grid-layout.min.js +1 -1
- package/dist/react-grid-layout.min.js.map +1 -1
- package/index.js +1 -0
- package/lib/GridItem.jsx +71 -70
- package/lib/ReactGridLayout.jsx +64 -23
- package/lib/ReactGridLayoutPropTypes.js +2 -10
- package/lib/ResponsiveReactGridLayout.jsx +4 -4
- package/lib/calculateUtils.js +20 -4
- package/lib/components/WidthProvider.jsx +18 -16
- package/lib/utils.js +208 -22
- package/package.json +43 -36
package/.flowconfig
CHANGED
package/.prettierignore
CHANGED
package/.prettierrc
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.0 (Sep 11, 2023)
|
|
4
|
+
|
|
5
|
+
Hey, it's been a long time! Taking a year and a half off is a pretty "open-source" thing to do, thanks for bearing with me.
|
|
6
|
+
|
|
7
|
+
### New Features
|
|
8
|
+
|
|
9
|
+
- **Grid items can now be resized left and up!** Thanks to @ludovic and @dseif for all the hard work they did on this. [#1917](https://github.com/react-grid-layout/react-grid-layout/pull/1917)
|
|
10
|
+
- To use, specify `resizeHandles` directions on your `<GridItem>`s. See [the example](/test/examples/20-resizable-handles.jsx) for more on how to do this.
|
|
11
|
+
- See also [the demo](https://react-grid-layout.github.io/react-grid-layout/examples/20-resizable-handles.html).
|
|
12
|
+
- `<WidthProvider>` now uses a `ResizeObserver` instead of hooking into the window's `'resize'` event. [#1839](https://github.com/react-grid-layout/react-grid-layout/pull/1839)
|
|
13
|
+
- This should not be breaking for any users but introduces a new dependency, [resize-observer-polyfill](https://www.npmjs.com/package/resize-observer-polyfill). It will not be imported unless you use `<WidthProvider>`.
|
|
14
|
+
|
|
15
|
+
### Bugfixes
|
|
16
|
+
|
|
17
|
+
- Fixed `horizontal` compact not always moving grid elements as far left as possible. [#1822](https://github.com/react-grid-layout/react-grid-layout/pull/1822)
|
|
18
|
+
- Fixed a bug when `allowOverlap={true}` and `compactType={null}`, where collisions would still be processed. [#1782](https://github.com/react-grid-layout/react-grid-layout/pull/1782)
|
|
19
|
+
- Fixed `onResizeStop` and `onDragStop` callbacks not returning updated layout. [#1613](https://github.com/react-grid-layout/react-grid-layout/pull/1613)
|
|
20
|
+
- An item will now rerender when `data-grid` props change. [#718](https://github.com/react-grid-layout/react-grid-layout/issues/718)
|
|
21
|
+
- Corrected draggableHandle configuration in static elements example [#1826](https://github.com/react-grid-layout/react-grid-layout/pull/1826)
|
|
22
|
+
|
|
23
|
+
### Internal Changes
|
|
24
|
+
|
|
25
|
+
- Various dependency upgrades and upgraded tests.
|
|
26
|
+
- Removed long-deprecated `_grid` property.
|
|
27
|
+
- Various doc updates.
|
|
28
|
+
|
|
29
|
+
## 1.3.4 (Feb 21, 2022)
|
|
30
|
+
|
|
31
|
+
### Bugfixes
|
|
32
|
+
|
|
33
|
+
- Add `e.stopPropagation()` on drag events to better support nested grids. Thanks @rogerfar [#1494](https://github.com/react-grid-layout/react-grid-layout/pull/1494).
|
|
34
|
+
|
|
35
|
+
### Internal Changes
|
|
36
|
+
|
|
37
|
+
- Various dependency upgrades.
|
|
38
|
+
|
|
3
39
|
## 1.3.3 (Jan 24, 2022)
|
|
4
40
|
|
|
5
41
|
This was a quick release to improve package size and dependency use. Thanks @salvoravida [#1655](https://github.com/react-grid-layout/react-grid-layout/pull/1655)
|
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ RGL is React-only and does not require jQuery.
|
|
|
57
57
|
1. [Resizable Handles](https://react-grid-layout.github.io/react-grid-layout/examples/17-resizable-handles.html)
|
|
58
58
|
1. [Scaled Containers](https://react-grid-layout.github.io/react-grid-layout/examples/18-scale.html)
|
|
59
59
|
1. [Allow Overlap](https://react-grid-layout.github.io/react-grid-layout/examples/19-allow-overlap.html)
|
|
60
|
+
1. [All Resizable Handles](https://react-grid-layout.github.io/react-grid-layout/examples/20-resizable-handles.html)
|
|
60
61
|
|
|
61
62
|
#### Projects Using React-Grid-Layout
|
|
62
63
|
|
|
@@ -357,7 +358,7 @@ preventCollision: ?boolean = false,
|
|
|
357
358
|
// onDragStart attribute is required for Firefox for a dragging initialization
|
|
358
359
|
// @see https://bugzilla.mozilla.org/show_bug.cgi?id=568313
|
|
359
360
|
isDroppable: ?boolean = false,
|
|
360
|
-
// Defines which resize handles should be rendered
|
|
361
|
+
// Defines which resize handles should be rendered.
|
|
361
362
|
// Allows for any combination of:
|
|
362
363
|
// 's' - South handle (bottom-center)
|
|
363
364
|
// 'w' - West handle (left-center)
|
|
@@ -367,6 +368,8 @@ isDroppable: ?boolean = false,
|
|
|
367
368
|
// 'nw' - Northwest handle (top-left)
|
|
368
369
|
// 'se' - Southeast handle (bottom-right)
|
|
369
370
|
// 'ne' - Northeast handle (top-right)
|
|
371
|
+
//
|
|
372
|
+
// Note that changing this property dynamically does not work due to a restriction in react-resizable.
|
|
370
373
|
resizeHandles: ?Array<'s' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne'> = ['se'],
|
|
371
374
|
// Custom component for resize handles
|
|
372
375
|
// See `handle` as used in https://github.com/react-grid-layout/react-resizable#resize-handle
|
|
@@ -468,6 +471,8 @@ RGL supports the following properties on grid items or layout items. When initia
|
|
|
468
471
|
build a layout array (as in the first example above), or attach this object as the `data-grid` property
|
|
469
472
|
to each of your child elements (as in the second example).
|
|
470
473
|
|
|
474
|
+
If `data-grid` is provided on an item, it will take precedence over an item in the `layout` with the same key (`i`).
|
|
475
|
+
|
|
471
476
|
Note that if a grid item is provided but incomplete (missing one of `x, y, w, or h`), an error
|
|
472
477
|
will be thrown so you can correct your layout.
|
|
473
478
|
|
|
@@ -504,13 +509,27 @@ will be draggable, even if the item is marked `static: true`.
|
|
|
504
509
|
// If false, will not be resizable. Overrides `static`.
|
|
505
510
|
isResizable: ?boolean = true,
|
|
506
511
|
// By default, a handle is only shown on the bottom-right (southeast) corner.
|
|
507
|
-
//
|
|
512
|
+
// As of RGL >= 1.4.0, resizing on any corner works just fine!
|
|
508
513
|
resizeHandles?: ?Array<'s' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne'> = ['se']
|
|
509
514
|
// If true and draggable, item will be moved only within grid.
|
|
510
515
|
isBounded: ?boolean = false
|
|
511
516
|
}
|
|
512
517
|
```
|
|
513
518
|
|
|
519
|
+
### Grid Item Heights and Widths
|
|
520
|
+
|
|
521
|
+
Grid item widths are based on container and number of columns. The size of a grid unit's height is based on `rowHeight`.
|
|
522
|
+
|
|
523
|
+
Note that an item that has `h=2` is _not exactly twice as tall as one with `h=1` unless you have no `margin`_!
|
|
524
|
+
|
|
525
|
+
In order for the grid to not be ragged, when an item spans grid units, it must also span margins. So you must add the height or width or the margin you are spanning for each unit. So actual pixel height is `(rowHeight * h) + (marginH * (h - 1)`.
|
|
526
|
+
|
|
527
|
+
For example, with `rowHeight=30`, `margin=[10,10]` and a unit with height 4, the calculation is `(30 * 4) + (10 * 3)`
|
|
528
|
+
|
|
529
|
+

|
|
530
|
+
|
|
531
|
+
If this is a problem for you, set `margin=[0,0]` and handle visual spacing between your elements inside the elements' content.
|
|
532
|
+
|
|
514
533
|
### Performance
|
|
515
534
|
|
|
516
535
|
`<ReactGridLayout>` has [an optimized `shouldComponentUpdate` implementation](lib/ReactGridLayout.jsx), but it relies on the user memoizing the `children` array:
|
|
@@ -546,23 +565,33 @@ function MyGrid(props) {
|
|
|
546
565
|
|
|
547
566
|
Because the `children` prop doesn't change between rerenders, updates to `<MyGrid>` won't result in new renders, improving performance.
|
|
548
567
|
|
|
568
|
+
### React Hooks Performance
|
|
569
|
+
|
|
570
|
+
Using hooks to save your layout state on change will cause the layouts to re-render as the ResponsiveGridLayout will change it's value on every render.
|
|
571
|
+
To avoid this you should wrap your WidthProvider in a useMemo:
|
|
572
|
+
|
|
573
|
+
```js
|
|
574
|
+
const ResponsiveReactGridLayout = useMemo(() => WidthProvider(Responsive), []);
|
|
575
|
+
```
|
|
576
|
+
|
|
549
577
|
### Custom Child Components and Draggable Handles
|
|
550
578
|
|
|
551
579
|
If you use React Components as grid children, they need to do a few things:
|
|
552
580
|
|
|
553
581
|
1. Forward refs to an underlying DOM node, and
|
|
554
|
-
2. Forward `style` and `
|
|
582
|
+
2. Forward `style`,`className`, `onMouseDown`, `onMouseUp` and `onTouchEnd` to that same DOM node.
|
|
555
583
|
|
|
556
584
|
For example:
|
|
557
585
|
|
|
558
586
|
```js
|
|
559
|
-
const CustomGridItemComponent = React.forwardRef(({style, className, ...props}, ref) => {
|
|
587
|
+
const CustomGridItemComponent = React.forwardRef(({style, className, onMouseDown, onMouseUp, onTouchEnd, children, ...props}, ref) => {
|
|
560
588
|
return (
|
|
561
|
-
<div style={{ /* styles */, ...style}} className={className} ref={ref}>
|
|
589
|
+
<div style={{ /* styles */, ...style}} className={className} ref={ref} onMouseDown={onMouseDown} onMouseUp={onMouseUp} onTouchEnd={onTouchEnd}>
|
|
562
590
|
{/* Some other content */}
|
|
591
|
+
{children} {/* Make sure to include children to add resizable handle */}
|
|
563
592
|
</div>
|
|
564
593
|
);
|
|
565
|
-
}
|
|
594
|
+
})
|
|
566
595
|
```
|
|
567
596
|
|
|
568
597
|
The same is true of custom elements as draggable handles using the `draggableHandle` prop. This is so that
|