react-grid-layout 1.5.3 → 2.0.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.
Files changed (95) hide show
  1. package/README.md +1074 -432
  2. package/css/styles.css +6 -4
  3. package/dist/ResponsiveGridLayout-CH4s0tKj.d.ts +124 -0
  4. package/dist/ResponsiveGridLayout-D6lFRE3f.d.mts +124 -0
  5. package/dist/calculate-CwYDW8na.d.mts +168 -0
  6. package/dist/calculate-mgLpNJ5O.d.ts +168 -0
  7. package/dist/chunk-2KUHNJXF.mjs +90 -0
  8. package/dist/chunk-2KUHNJXF.mjs.map +1 -0
  9. package/dist/chunk-3WO4SAYB.js +868 -0
  10. package/dist/chunk-3WO4SAYB.js.map +1 -0
  11. package/dist/chunk-4HNUMWQK.mjs +822 -0
  12. package/dist/chunk-4HNUMWQK.mjs.map +1 -0
  13. package/dist/chunk-BFTKGAP3.js +1309 -0
  14. package/dist/chunk-BFTKGAP3.js.map +1 -0
  15. package/dist/chunk-F6NQPYKT.js +98 -0
  16. package/dist/chunk-F6NQPYKT.js.map +1 -0
  17. package/dist/chunk-H5KMDLY3.js +434 -0
  18. package/dist/chunk-H5KMDLY3.js.map +1 -0
  19. package/dist/chunk-PBQSHIID.js +4 -0
  20. package/dist/chunk-PBQSHIID.js.map +1 -0
  21. package/dist/chunk-R35HZZTA.mjs +1300 -0
  22. package/dist/chunk-R35HZZTA.mjs.map +1 -0
  23. package/dist/chunk-ZCXE6SR5.mjs +428 -0
  24. package/dist/chunk-ZCXE6SR5.mjs.map +1 -0
  25. package/dist/chunk-ZWN22PS2.mjs +3 -0
  26. package/dist/chunk-ZWN22PS2.mjs.map +1 -0
  27. package/dist/core.d.mts +33 -0
  28. package/dist/core.d.ts +33 -0
  29. package/dist/core.js +218 -0
  30. package/dist/core.js.map +1 -0
  31. package/dist/core.mjs +5 -0
  32. package/dist/core.mjs.map +1 -0
  33. package/dist/extras.d.mts +78 -0
  34. package/dist/extras.d.ts +78 -0
  35. package/dist/extras.js +91 -0
  36. package/dist/extras.js.map +1 -0
  37. package/dist/extras.mjs +89 -0
  38. package/dist/extras.mjs.map +1 -0
  39. package/dist/index.d.mts +7 -0
  40. package/dist/index.d.ts +7 -0
  41. package/dist/index.js +154 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/index.mjs +7 -0
  44. package/dist/index.mjs.map +1 -0
  45. package/dist/legacy.d.mts +163 -0
  46. package/dist/legacy.d.ts +163 -0
  47. package/dist/legacy.js +319 -0
  48. package/dist/legacy.js.map +1 -0
  49. package/dist/legacy.mjs +307 -0
  50. package/dist/legacy.mjs.map +1 -0
  51. package/dist/position-BmN1z36J.d.mts +319 -0
  52. package/dist/position-Dk2b4ZMS.d.ts +319 -0
  53. package/dist/react.d.mts +351 -0
  54. package/dist/react.d.ts +351 -0
  55. package/dist/react.js +96 -0
  56. package/dist/react.js.map +1 -0
  57. package/dist/react.mjs +7 -0
  58. package/dist/react.mjs.map +1 -0
  59. package/dist/responsive-C4L1ESlm.d.ts +145 -0
  60. package/dist/responsive-CJxefsYw.d.mts +145 -0
  61. package/dist/types-Cxf4nHNr.d.mts +375 -0
  62. package/dist/types-Cxf4nHNr.d.ts +375 -0
  63. package/index-dev.js +8 -0
  64. package/package.json +132 -40
  65. package/.babelrc.js +0 -22
  66. package/.browserslistrc +0 -3
  67. package/.eslintignore +0 -4
  68. package/.flowconfig +0 -20
  69. package/.prettierignore +0 -4
  70. package/.prettierrc +0 -17
  71. package/CHANGELOG.md +0 -985
  72. package/build/GridItem.js +0 -638
  73. package/build/ReactGridLayout.js +0 -741
  74. package/build/ReactGridLayoutPropTypes.js +0 -210
  75. package/build/ResponsiveReactGridLayout.js +0 -297
  76. package/build/calculateUtils.js +0 -165
  77. package/build/components/WidthProvider.js +0 -115
  78. package/build/fastRGLPropsEqual.js +0 -5
  79. package/build/responsiveUtils.js +0 -101
  80. package/build/utils.js +0 -842
  81. package/dist/react-grid-layout.min.js +0 -2
  82. package/dist/react-grid-layout.min.js.map +0 -1
  83. package/index.js.flow +0 -8
  84. package/ip_fetcher +0 -0
  85. package/ip_fetcher.c +0 -47
  86. package/lib/GridItem.jsx +0 -689
  87. package/lib/ReactGridLayout.jsx +0 -855
  88. package/lib/ReactGridLayoutPropTypes.js +0 -241
  89. package/lib/ResponsiveReactGridLayout.jsx +0 -349
  90. package/lib/calculateUtils.js +0 -169
  91. package/lib/components/WidthProvider.jsx +0 -110
  92. package/lib/fastRGLPropsEqual.js +0 -46
  93. package/lib/responsiveUtils.js +0 -118
  94. package/lib/utils.js +0 -995
  95. package/yarn-error.log +0 -7780
@@ -1,169 +0,0 @@
1
- // @flow
2
- import type { Position } from "./utils";
3
-
4
- export type PositionParams = {
5
- margin: [number, number],
6
- containerPadding: [number, number],
7
- containerWidth: number,
8
- cols: number,
9
- rowHeight: number,
10
- maxRows: number
11
- };
12
-
13
- // Helper for generating column width
14
- export function calcGridColWidth(positionParams: PositionParams): number {
15
- const { margin, containerPadding, containerWidth, cols } = positionParams;
16
- return (
17
- (containerWidth - margin[0] * (cols - 1) - containerPadding[0] * 2) / cols
18
- );
19
- }
20
-
21
- // This can either be called:
22
- // calcGridItemWHPx(w, colWidth, margin[0])
23
- // or
24
- // calcGridItemWHPx(h, rowHeight, margin[1])
25
- export function calcGridItemWHPx(
26
- gridUnits: number,
27
- colOrRowSize: number,
28
- marginPx: number
29
- ): number {
30
- // 0 * Infinity === NaN, which causes problems with resize contraints
31
- if (!Number.isFinite(gridUnits)) return gridUnits;
32
- return Math.round(
33
- colOrRowSize * gridUnits + Math.max(0, gridUnits - 1) * marginPx
34
- );
35
- }
36
-
37
- /**
38
- * Return position on the page given an x, y, w, h.
39
- * left, top, width, height are all in pixels.
40
- * @param {PositionParams} positionParams Parameters of grid needed for coordinates calculations.
41
- * @param {Number} x X coordinate in grid units.
42
- * @param {Number} y Y coordinate in grid units.
43
- * @param {Number} w W coordinate in grid units.
44
- * @param {Number} h H coordinate in grid units.
45
- * @return {Position} Object containing coords.
46
- */
47
- export function calcGridItemPosition(
48
- positionParams: PositionParams,
49
- x: number,
50
- y: number,
51
- w: number,
52
- h: number,
53
- state: ?Object
54
- ): Position {
55
- const { margin, containerPadding, rowHeight } = positionParams;
56
- const colWidth = calcGridColWidth(positionParams);
57
- const out = {};
58
-
59
- // If resizing, use the exact width and height as returned from resizing callbacks.
60
- if (state && state.resizing) {
61
- out.width = Math.round(state.resizing.width);
62
- out.height = Math.round(state.resizing.height);
63
- }
64
- // Otherwise, calculate from grid units.
65
- else {
66
- out.width = calcGridItemWHPx(w, colWidth, margin[0]);
67
- out.height = calcGridItemWHPx(h, rowHeight, margin[1]);
68
- }
69
-
70
- // If dragging, use the exact width and height as returned from dragging callbacks.
71
- if (state && state.dragging) {
72
- out.top = Math.round(state.dragging.top);
73
- out.left = Math.round(state.dragging.left);
74
- } else if (
75
- state &&
76
- state.resizing &&
77
- typeof state.resizing.top === "number" &&
78
- typeof state.resizing.left === "number"
79
- ) {
80
- out.top = Math.round(state.resizing.top);
81
- out.left = Math.round(state.resizing.left);
82
- }
83
- // Otherwise, calculate from grid units.
84
- else {
85
- out.top = Math.round((rowHeight + margin[1]) * y + containerPadding[1]);
86
- out.left = Math.round((colWidth + margin[0]) * x + containerPadding[0]);
87
- }
88
-
89
- return out;
90
- }
91
-
92
- /**
93
- * Translate x and y coordinates from pixels to grid units.
94
- * @param {PositionParams} positionParams Parameters of grid needed for coordinates calculations.
95
- * @param {Number} top Top position (relative to parent) in pixels.
96
- * @param {Number} left Left position (relative to parent) in pixels.
97
- * @param {Number} w W coordinate in grid units.
98
- * @param {Number} h H coordinate in grid units.
99
- * @return {Object} x and y in grid units.
100
- */
101
- export function calcXY(
102
- positionParams: PositionParams,
103
- top: number,
104
- left: number,
105
- w: number,
106
- h: number
107
- ): { x: number, y: number } {
108
- const { margin, containerPadding, cols, rowHeight, maxRows } = positionParams;
109
- const colWidth = calcGridColWidth(positionParams);
110
-
111
- // left = containerPaddingX + x * (colWidth + marginX)
112
- // x * (colWidth + marginX) = left - containerPaddingX
113
- // x = (left - containerPaddingX) / (colWidth + marginX)
114
- let x = Math.round((left - containerPadding[0]) / (colWidth + margin[0]));
115
- let y = Math.round((top - containerPadding[1]) / (rowHeight + margin[1]));
116
-
117
- // Capping
118
- x = clamp(x, 0, cols - w);
119
- y = clamp(y, 0, maxRows - h);
120
- return { x, y };
121
- }
122
-
123
- /**
124
- * Given a height and width in pixel values, calculate grid units.
125
- * @param {PositionParams} positionParams Parameters of grid needed for coordinates calcluations.
126
- * @param {Number} height Height in pixels.
127
- * @param {Number} width Width in pixels.
128
- * @param {Number} x X coordinate in grid units.
129
- * @param {Number} y Y coordinate in grid units.
130
- * @param {String} handle Resize Handle.
131
- * @return {Object} w, h as grid units.
132
- */
133
- export function calcWH(
134
- positionParams: PositionParams,
135
- width: number,
136
- height: number,
137
- x: number,
138
- y: number,
139
- handle: string
140
- ): { w: number, h: number } {
141
- const { margin, maxRows, cols, rowHeight } = positionParams;
142
- const colWidth = calcGridColWidth(positionParams);
143
-
144
- // width = colWidth * w - (margin * (w - 1))
145
- // ...
146
- // w = (width + margin) / (colWidth + margin)
147
- let w = Math.round((width + margin[0]) / (colWidth + margin[0]));
148
- let h = Math.round((height + margin[1]) / (rowHeight + margin[1]));
149
-
150
- // Capping
151
- let _w = clamp(w, 0, cols - x);
152
- let _h = clamp(h, 0, maxRows - y);
153
- if (["sw", "w", "nw"].indexOf(handle) !== -1) {
154
- _w = clamp(w, 0, cols);
155
- }
156
- if (["nw", "n", "ne"].indexOf(handle) !== -1) {
157
- _h = clamp(h, 0, maxRows);
158
- }
159
- return { w: _w, h: _h };
160
- }
161
-
162
- // Similar to _.clamp
163
- export function clamp(
164
- num: number,
165
- lowerBound: number,
166
- upperBound: number
167
- ): number {
168
- return Math.max(Math.min(num, upperBound), lowerBound);
169
- }
@@ -1,110 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
- import PropTypes from "prop-types";
4
- import ResizeObserver from "resize-observer-polyfill";
5
- import clsx from "clsx";
6
- import type { ReactRef } from "../ReactGridLayoutPropTypes";
7
-
8
- type WPDefaultProps = {|
9
- measureBeforeMount: boolean
10
- |};
11
-
12
- // eslint-disable-next-line no-unused-vars
13
- type WPProps = {|
14
- className?: string,
15
- style?: Object,
16
- ...WPDefaultProps
17
- |};
18
-
19
- type WPState = {|
20
- width: number
21
- |};
22
-
23
- type ComposedProps<Config> = {|
24
- ...Config,
25
- measureBeforeMount?: boolean,
26
- className?: string,
27
- style?: Object,
28
- width?: number
29
- |};
30
-
31
- const layoutClassName = "react-grid-layout";
32
-
33
- /*
34
- * A simple HOC that provides facility for listening to container resizes.
35
- *
36
- * The Flow type is pretty janky here. I can't just spread `WPProps` into this returned object - I wish I could - but it triggers
37
- * a flow bug of some sort that causes it to stop typechecking.
38
- */
39
- export default function WidthProvideRGL<Config>(
40
- ComposedComponent: React.AbstractComponent<Config>
41
- ): React.AbstractComponent<ComposedProps<Config>> {
42
- return class WidthProvider extends React.Component<
43
- ComposedProps<Config>,
44
- WPState
45
- > {
46
- static defaultProps: WPDefaultProps = {
47
- measureBeforeMount: false
48
- };
49
-
50
- static propTypes = {
51
- // If true, will not render children until mounted. Useful for getting the exact width before
52
- // rendering, to prevent any unsightly resizing.
53
- measureBeforeMount: PropTypes.bool
54
- };
55
-
56
- state: WPState = {
57
- width: 1280
58
- };
59
-
60
- elementRef: ReactRef<HTMLDivElement> = React.createRef();
61
- mounted: boolean = false;
62
- resizeObserver: ResizeObserver;
63
-
64
- componentDidMount() {
65
- this.mounted = true;
66
- this.resizeObserver = new ResizeObserver(entries => {
67
- const node = this.elementRef.current;
68
- if (node instanceof HTMLElement) {
69
- const width = entries[0].contentRect.width;
70
- this.setState({ width });
71
- }
72
- });
73
- const node = this.elementRef.current;
74
- if (node instanceof HTMLElement) {
75
- this.resizeObserver.observe(node);
76
- }
77
- }
78
-
79
- componentWillUnmount() {
80
- this.mounted = false;
81
- const node = this.elementRef.current;
82
- if (node instanceof HTMLElement) {
83
- this.resizeObserver.unobserve(node);
84
- }
85
- this.resizeObserver.disconnect();
86
- }
87
-
88
- render() {
89
- const { measureBeforeMount, ...rest } = this.props;
90
- if (measureBeforeMount && !this.mounted) {
91
- return (
92
- <div
93
- className={clsx(this.props.className, layoutClassName)}
94
- style={this.props.style}
95
- // $FlowIgnore ref types
96
- ref={this.elementRef}
97
- />
98
- );
99
- }
100
-
101
- return (
102
- <ComposedComponent
103
- innerRef={this.elementRef}
104
- {...rest}
105
- {...this.state}
106
- />
107
- );
108
- }
109
- };
110
- }
@@ -1,46 +0,0 @@
1
- // @preval
2
-
3
- require("@babel/register");
4
-
5
- // Fast way to compare RGL props in shouldComponentUpdate.
6
- // Generates the fastest possible comparison of the type:
7
- // function (a, b) { return a.className === b.className && a.style === b.style && ... }
8
- // This avoids enumerating keys, avoids us keeping our own key list, and can be very easily optimized.
9
-
10
- const PropTypes = require("prop-types");
11
- const propTypes = require("./ReactGridLayoutPropTypes").default;
12
- const keys = Object.keys(propTypes);
13
-
14
- // Remove 'children' key as we don't want to compare it
15
- keys.splice(keys.indexOf("children"), 1);
16
-
17
- // Returns a code string indicating what to do here.
18
- // In most cases we want to do a simple equality comparison,
19
- // but we have some arrays and tuples and objects we want
20
- // to do a shallow comparison on.
21
- function getEqualType(key) {
22
- if (
23
- [
24
- PropTypes.number,
25
- PropTypes.bool,
26
- PropTypes.string,
27
- PropTypes.func
28
- ].includes(propTypes[key])
29
- ) {
30
- return `(a.${key} === b.${key})`;
31
- }
32
- return `isEqualImpl(a.${key}, b.${key})`;
33
- }
34
-
35
- // Exports a function that compares a and b. `isEqualImpl` is a required
36
- // third prop, as we can't otherwise access it.
37
- module.exports = () =>
38
- eval(`
39
- function fastRGLPropsEqual(a, b, isEqualImpl) {
40
- if (a === b) return true;
41
- return (
42
- ${keys.map(getEqualType).join(" && ")}
43
- );
44
- }
45
- fastRGLPropsEqual;
46
- `);
@@ -1,118 +0,0 @@
1
- // @flow
2
-
3
- import { cloneLayout, compact, correctBounds } from "./utils";
4
-
5
- import type { CompactType, Layout } from "./utils";
6
-
7
- export type Breakpoint = string;
8
- export type DefaultBreakpoints = "lg" | "md" | "sm" | "xs" | "xxs";
9
-
10
- // + indicates read-only
11
- export type ResponsiveLayout<T: Breakpoint> = {
12
- +[breakpoint: T]: Layout
13
- };
14
- export type Breakpoints<T: Breakpoint> = {
15
- +[breakpoint: T]: number
16
- };
17
-
18
- export type OnLayoutChangeCallback = (
19
- Layout,
20
- { [key: Breakpoint]: Layout }
21
- ) => void;
22
-
23
- /**
24
- * Given a width, find the highest breakpoint that matches is valid for it (width > breakpoint).
25
- *
26
- * @param {Object} breakpoints Breakpoints object (e.g. {lg: 1200, md: 960, ...})
27
- * @param {Number} width Screen width.
28
- * @return {String} Highest breakpoint that is less than width.
29
- */
30
- export function getBreakpointFromWidth(
31
- breakpoints: Breakpoints<Breakpoint>,
32
- width: number
33
- ): Breakpoint {
34
- const sorted = sortBreakpoints(breakpoints);
35
- let matching = sorted[0];
36
- for (let i = 1, len = sorted.length; i < len; i++) {
37
- const breakpointName = sorted[i];
38
- if (width > breakpoints[breakpointName]) matching = breakpointName;
39
- }
40
- return matching;
41
- }
42
-
43
- /**
44
- * Given a breakpoint, get the # of cols set for it.
45
- * @param {String} breakpoint Breakpoint name.
46
- * @param {Object} cols Map of breakpoints to cols.
47
- * @return {Number} Number of cols.
48
- */
49
- export function getColsFromBreakpoint(
50
- breakpoint: Breakpoint,
51
- cols: Breakpoints<Breakpoint>
52
- ): number {
53
- if (!cols[breakpoint]) {
54
- throw new Error(
55
- "ResponsiveReactGridLayout: `cols` entry for breakpoint " +
56
- breakpoint +
57
- " is missing!"
58
- );
59
- }
60
- return cols[breakpoint];
61
- }
62
-
63
- /**
64
- * Given existing layouts and a new breakpoint, find or generate a new layout.
65
- *
66
- * This finds the layout above the new one and generates from it, if it exists.
67
- *
68
- * @param {Object} layouts Existing layouts.
69
- * @param {Array} breakpoints All breakpoints.
70
- * @param {String} breakpoint New breakpoint.
71
- * @param {String} breakpoint Last breakpoint (for fallback).
72
- * @param {Number} cols Column count at new breakpoint.
73
- * @param {Boolean} verticalCompact Whether or not to compact the layout
74
- * vertically.
75
- * @return {Array} New layout.
76
- */
77
- export function findOrGenerateResponsiveLayout(
78
- layouts: ResponsiveLayout<Breakpoint>,
79
- breakpoints: Breakpoints<Breakpoint>,
80
- breakpoint: Breakpoint,
81
- lastBreakpoint: Breakpoint,
82
- cols: number,
83
- compactType: CompactType
84
- ): Layout {
85
- // If it already exists, just return it.
86
- if (layouts[breakpoint]) return cloneLayout(layouts[breakpoint]);
87
- // Find or generate the next layout
88
- let layout = layouts[lastBreakpoint];
89
- const breakpointsSorted = sortBreakpoints(breakpoints);
90
- const breakpointsAbove = breakpointsSorted.slice(
91
- breakpointsSorted.indexOf(breakpoint)
92
- );
93
- for (let i = 0, len = breakpointsAbove.length; i < len; i++) {
94
- const b = breakpointsAbove[i];
95
- if (layouts[b]) {
96
- layout = layouts[b];
97
- break;
98
- }
99
- }
100
- layout = cloneLayout(layout || []); // clone layout so we don't modify existing items
101
- return compact(correctBounds(layout, { cols: cols }), compactType, cols);
102
- }
103
-
104
- /**
105
- * Given breakpoints, return an array of breakpoints sorted by width. This is usually
106
- * e.g. ['xxs', 'xs', 'sm', ...]
107
- *
108
- * @param {Object} breakpoints Key/value pair of breakpoint names to widths.
109
- * @return {Array} Sorted breakpoints.
110
- */
111
- export function sortBreakpoints(
112
- breakpoints: Breakpoints<Breakpoint>
113
- ): Array<Breakpoint> {
114
- const keys: Array<string> = Object.keys(breakpoints);
115
- return keys.sort(function (a, b) {
116
- return breakpoints[a] - breakpoints[b];
117
- });
118
- }