react-grid-layout 1.5.3 → 2.1.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/README.md +1156 -442
- package/css/styles.css +5 -4
- package/dist/ResponsiveGridLayout-BkHF9YHa.d.mts +133 -0
- package/dist/ResponsiveGridLayout-CLn16-X3.d.ts +133 -0
- package/dist/calculate-DsVTldEE.d.ts +196 -0
- package/dist/calculate-DwbL1D06.d.mts +196 -0
- package/dist/chunk-2O3ZME4Q.mjs +703 -0
- package/dist/chunk-2O3ZME4Q.mjs.map +1 -0
- package/dist/chunk-526JND3R.mjs +3 -0
- package/dist/chunk-526JND3R.mjs.map +1 -0
- package/dist/chunk-7ELO5FRW.js +4 -0
- package/dist/chunk-7ELO5FRW.js.map +1 -0
- package/dist/chunk-AWM66AWF.mjs +422 -0
- package/dist/chunk-AWM66AWF.mjs.map +1 -0
- package/dist/chunk-BJFPTW5Q.js +449 -0
- package/dist/chunk-BJFPTW5Q.js.map +1 -0
- package/dist/chunk-FN6MIZ24.js +744 -0
- package/dist/chunk-FN6MIZ24.js.map +1 -0
- package/dist/chunk-GPZBANOK.js +435 -0
- package/dist/chunk-GPZBANOK.js.map +1 -0
- package/dist/chunk-LWF5EYMO.mjs +429 -0
- package/dist/chunk-LWF5EYMO.mjs.map +1 -0
- package/dist/chunk-MXXN7GUE.mjs +1408 -0
- package/dist/chunk-MXXN7GUE.mjs.map +1 -0
- package/dist/chunk-QRW3ND4U.js +1417 -0
- package/dist/chunk-QRW3ND4U.js.map +1 -0
- package/dist/core.d.mts +186 -0
- package/dist/core.d.ts +186 -0
- package/dist/core.js +274 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +5 -0
- package/dist/core.mjs.map +1 -0
- package/dist/extras.d.mts +208 -0
- package/dist/extras.d.ts +208 -0
- package/dist/extras.js +462 -0
- package/dist/extras.js.map +1 -0
- package/dist/extras.mjs +454 -0
- package/dist/extras.mjs.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +154 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +7 -0
- package/dist/index.mjs.map +1 -0
- package/dist/legacy.d.mts +163 -0
- package/dist/legacy.d.ts +163 -0
- package/dist/legacy.js +320 -0
- package/dist/legacy.js.map +1 -0
- package/dist/legacy.mjs +308 -0
- package/dist/legacy.mjs.map +1 -0
- package/dist/position-C8a5g6bb.d.mts +324 -0
- package/dist/position-H8tBL91b.d.ts +324 -0
- package/dist/react.d.mts +357 -0
- package/dist/react.d.ts +357 -0
- package/dist/react.js +96 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +7 -0
- package/dist/react.mjs.map +1 -0
- package/dist/responsive-BB5d98xz.d.mts +145 -0
- package/dist/responsive-BXI-GCXG.d.ts +145 -0
- package/dist/types-CokovIMH.d.mts +469 -0
- package/dist/types-CokovIMH.d.ts +469 -0
- package/index-dev.js +24 -0
- package/package.json +133 -40
- package/.babelrc.js +0 -22
- package/.browserslistrc +0 -3
- package/.eslintignore +0 -4
- package/.flowconfig +0 -20
- package/.prettierignore +0 -4
- package/.prettierrc +0 -17
- package/CHANGELOG.md +0 -985
- package/build/GridItem.js +0 -638
- package/build/ReactGridLayout.js +0 -741
- package/build/ReactGridLayoutPropTypes.js +0 -210
- package/build/ResponsiveReactGridLayout.js +0 -297
- package/build/calculateUtils.js +0 -165
- package/build/components/WidthProvider.js +0 -115
- package/build/fastRGLPropsEqual.js +0 -5
- package/build/responsiveUtils.js +0 -101
- package/build/utils.js +0 -842
- package/dist/react-grid-layout.min.js +0 -2
- package/dist/react-grid-layout.min.js.map +0 -1
- package/index.js.flow +0 -8
- package/ip_fetcher +0 -0
- package/ip_fetcher.c +0 -47
- package/lib/GridItem.jsx +0 -689
- package/lib/ReactGridLayout.jsx +0 -855
- package/lib/ReactGridLayoutPropTypes.js +0 -241
- package/lib/ResponsiveReactGridLayout.jsx +0 -349
- package/lib/calculateUtils.js +0 -169
- package/lib/components/WidthProvider.jsx +0 -110
- package/lib/fastRGLPropsEqual.js +0 -46
- package/lib/responsiveUtils.js +0 -118
- package/lib/utils.js +0 -995
- package/yarn-error.log +0 -7780
package/lib/calculateUtils.js
DELETED
|
@@ -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
|
-
}
|
package/lib/fastRGLPropsEqual.js
DELETED
|
@@ -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
|
-
`);
|
package/lib/responsiveUtils.js
DELETED
|
@@ -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
|
-
}
|