react-grid-layout 1.3.3 → 1.4.0

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,9 +1,11 @@
1
1
  [version]
2
- ^0.158.0
2
+ ^0.172.0
3
3
 
4
4
  [ignore]
5
5
  <PROJECT_ROOT>/build/.*
6
6
  <PROJECT_ROOT>/dist/.*
7
+ <PROJECT_ROOT>/node_modules/resolve/.*
8
+ <PROJECT_ROOT>/node_modules/.*/resolve/.*
7
9
  # Speeds parsing:
8
10
  .*/node_modules/@babel.*
9
11
  .*/node_modules/babel.*
package/.packj.yaml ADDED
@@ -0,0 +1,153 @@
1
+ #
2
+ # Audit policies
3
+ #
4
+ audit:
5
+ alerts:
6
+ #
7
+ # category: malicious packages (publicly known and unknown)
8
+ #
9
+ malicious:
10
+ contains known malware:
11
+ - reason: package is known to contain a dangerous malware
12
+ - enabled: true
13
+ typo-squatting or repo-jacking package:
14
+ - reason: package impersonates another popular package to propagate malware
15
+ - enabled: true
16
+
17
+ #
18
+ # alert category: suspicious packages (potentially malicious)
19
+ #
20
+ suspicious:
21
+ inconsistent with repo source:
22
+ - reason: package code inconsistent with the public repo source code
23
+ - enabled: false # WIP
24
+ overwrites system binaries:
25
+ - reason: package code inconsistent with the public repo source code
26
+ - enabled: false # WIP
27
+
28
+ #
29
+ # alert category: packages vulnerable to code exploits
30
+ #
31
+ vulnerable:
32
+ contains known vulnerabilities:
33
+ - reason: known vulnerabilities (CVEs) in package code could be exploited
34
+ - enabled: true
35
+ insecure network communication:
36
+ - reason: package code uses insecure network communication (not https)
37
+ - enabled: false # WIP
38
+
39
+ #
40
+ # packages with undesirable or "risky" attributes
41
+ #
42
+ undesirable:
43
+ package is old or abandoned:
44
+ - reason: old or abandoned packages receive no security updates and are risky
45
+ - enabled: true
46
+
47
+ invalid or no author email:
48
+ - reason: a package with lack of or invalid author email suggests 2FA not enabled
49
+ - enabled: true
50
+
51
+ invalid or no homepage:
52
+ - reason: a package with no or invalid homepage may not be preferable
53
+ - enabled: false
54
+
55
+ no source repo:
56
+ - reason: lack of public source repo may suggest malicious intention
57
+ - enabled: true
58
+
59
+ fewer downloads:
60
+ - reason: a package with few downloads may not be preferable
61
+ - enabled: true
62
+
63
+ no or insufficient readme:
64
+ - reason: a package with lack of documentation may not be preferable
65
+ - enabled: false
66
+
67
+ fewer versions or releases:
68
+ - reason: few versions suggest unstable or inactive project
69
+ - enabled: true
70
+
71
+ too many dependencies:
72
+ - reason: too many dependencies increase attack surface
73
+ - enabled: false
74
+
75
+ version release after a long gap:
76
+ - reason: a release after a long time may indicate account hijacking
77
+ - enabled: false
78
+
79
+ contains custom installation hooks:
80
+ - reason: custom installation hooks may download or execute malicious code
81
+ - enabled: false # WIP
82
+
83
+ #
84
+ # type: repo stats
85
+ #
86
+ few source repo stars:
87
+ - reason: a package with few repo stars may not be preferable
88
+ - enabled: false
89
+
90
+ few source repo forks:
91
+ - reason: a package with few repo forks may not be preferable
92
+ - enabled: false
93
+
94
+ forked source repo:
95
+ - reason: a forked copy of a popular package may contain malicious code
96
+ - enabled: true
97
+
98
+ #
99
+ # type: APIs and permissions
100
+ #
101
+ generates new code:
102
+ - reason: package generates new code at runtime, which could be malicious
103
+ - enabled: false
104
+ forks or exits OS processes:
105
+ - reason: package spawns new operating system processes, which could be malicious
106
+ - enabled: false
107
+ accesses obfuscated (hidden) code:
108
+ - enabled: true
109
+ accesses environment variables:
110
+ - enabled: false
111
+ changes system/environment variables:
112
+ - enabled: false
113
+ accesses files and dirs:
114
+ - enabled: false
115
+ communicates with external network:
116
+ - enabled: false
117
+ reads user input:
118
+ - enabled: false
119
+
120
+ #
121
+ # Sandboxing policies
122
+ #
123
+ sandbox:
124
+ rules:
125
+ #
126
+ # File system (allow or block accesses to file/dirs)
127
+ #
128
+ # ~/ represents home dir
129
+ # . represents cwd dir
130
+ #
131
+ # NOTE: only ONE 'allow' and 'block' lines are allowed
132
+ #
133
+ fs:
134
+ # TODO: customize as per your threat model
135
+
136
+ # block access to home dir and all other locations (except the ones below)
137
+ block: ~/, /
138
+ allow: ., ~/.cache, ~/.npm, ~/.local, ~/.ruby, /tmp, /proc, /etc, /var, /bin, /usr/include, /usr/local, /usr/bin, /usr/lib, /usr/share, /lib
139
+
140
+ #
141
+ # Network (allow or block domains/ports)
142
+ #
143
+ # NOTE: only ONE 'allow' and 'block' lines are allowed
144
+ #
145
+ network:
146
+
147
+ # TODO: customize as per your threat model
148
+
149
+ # block all external network communication (except the ones below)
150
+ block: 0.0.0.0
151
+
152
+ # For NPM packages
153
+ allow: registry.yarnpkg.com:0, npmjs.org:0, npmjs.com:0
package/.prettierignore CHANGED
@@ -1,3 +1,4 @@
1
1
  dist/
2
2
  examples/
3
- __mocks__/
3
+ __mocks__/
4
+ flow-typed/
package/.prettierrc CHANGED
@@ -8,7 +8,6 @@
8
8
  "jsxSingleQuote": false,
9
9
  "trailingComma": "none",
10
10
  "bracketSpacing": true,
11
- "jsxBracketSameLine": false,
12
11
  "arrowParens": "avoid",
13
12
  "requirePragma": false,
14
13
  "insertPragma": false,
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)
@@ -264,8 +300,8 @@ Thanks to @daynin and @n1ghtmare for taking an active role in maintaining RGL, a
264
300
 
265
301
  ### New Features
266
302
 
267
- - Added ability to drag items into the grid from outside. [#980](https://github.com/STRML/react-grid-layout/pull/980). See [the example](https://strml.github.io/react-grid-layout/examples/15-drag-from-outside.html).
268
- - This is especially exciting as it opens up new "widget toolbox" use cases such as [Example 14](https://strml.github.io/react-grid-layout/examples/14-toolbox.html) with more intuitive interaction. Thanks @daynin.
303
+ - Added ability to drag items into the grid from outside. [#980](https://github.com/STRML/react-grid-layout/pull/980). See [the example](https://react-grid-layout.github.io/react-grid-layout/examples/15-drag-from-outside.html).
304
+ - This is especially exciting as it opens up new "widget toolbox" use cases such as [Example 14](https://react-grid-layout.github.io/react-grid-layout/examples/14-toolbox.html) with more intuitive interaction. Thanks @daynin.
269
305
  - `transformScale` prop [#987](https://github.com/STRML/react-grid-layout/pull/987)
270
306
  - `<ResponsiveReactGridLayout>` now supports margin-per-breakpoint [#1016](https://github.com/STRML/react-grid-layout/pull/1016)
271
307
 
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
- // Note that resizing from the top or left is generally not intuitive.
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
+ ![margin](margin.png)
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 `className` to that same DOM node.
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