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/build/calculateUtils.js
CHANGED
|
@@ -9,9 +9,7 @@ exports.calcGridItemWHPx = calcGridItemWHPx;
|
|
|
9
9
|
exports.calcWH = calcWH;
|
|
10
10
|
exports.calcXY = calcXY;
|
|
11
11
|
exports.clamp = clamp;
|
|
12
|
-
|
|
13
12
|
/*:: import type { Position } from "./utils";*/
|
|
14
|
-
|
|
15
13
|
/*:: export type PositionParams = {
|
|
16
14
|
margin: [number, number],
|
|
17
15
|
containerPadding: [number, number],
|
|
@@ -21,35 +19,26 @@ exports.clamp = clamp;
|
|
|
21
19
|
maxRows: number
|
|
22
20
|
};*/
|
|
23
21
|
// Helper for generating column width
|
|
24
|
-
function calcGridColWidth(positionParams
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
containerWidth = positionParams.containerWidth,
|
|
32
|
-
cols = positionParams.cols;
|
|
22
|
+
function calcGridColWidth(positionParams /*: PositionParams*/) /*: number*/{
|
|
23
|
+
const {
|
|
24
|
+
margin,
|
|
25
|
+
containerPadding,
|
|
26
|
+
containerWidth,
|
|
27
|
+
cols
|
|
28
|
+
} = positionParams;
|
|
33
29
|
return (containerWidth - margin[0] * (cols - 1) - containerPadding[0] * 2) / cols;
|
|
34
|
-
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// This can either be called:
|
|
35
33
|
// calcGridItemWHPx(w, colWidth, margin[0])
|
|
36
34
|
// or
|
|
37
35
|
// calcGridItemWHPx(h, rowHeight, margin[1])
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
function calcGridItemWHPx(gridUnits
|
|
41
|
-
/*: number*/
|
|
42
|
-
, colOrRowSize
|
|
43
|
-
/*: number*/
|
|
44
|
-
, marginPx
|
|
45
|
-
/*: number*/
|
|
46
|
-
)
|
|
47
|
-
/*: number*/
|
|
48
|
-
{
|
|
36
|
+
function calcGridItemWHPx(gridUnits /*: number*/, colOrRowSize /*: number*/, marginPx /*: number*/) /*: number*/{
|
|
49
37
|
// 0 * Infinity === NaN, which causes problems with resize contraints
|
|
50
38
|
if (!Number.isFinite(gridUnits)) return gridUnits;
|
|
51
39
|
return Math.round(colOrRowSize * gridUnits + Math.max(0, gridUnits - 1) * marginPx);
|
|
52
40
|
}
|
|
41
|
+
|
|
53
42
|
/**
|
|
54
43
|
* Return position on the page given an x, y, w, h.
|
|
55
44
|
* left, top, width, height are all in pixels.
|
|
@@ -60,50 +49,42 @@ function calcGridItemWHPx(gridUnits
|
|
|
60
49
|
* @param {Number} h H coordinate in grid units.
|
|
61
50
|
* @return {Position} Object containing coords.
|
|
62
51
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
, h
|
|
74
|
-
/*: number*/
|
|
75
|
-
, state
|
|
76
|
-
/*: ?Object*/
|
|
77
|
-
)
|
|
78
|
-
/*: Position*/
|
|
79
|
-
{
|
|
80
|
-
var margin = positionParams.margin,
|
|
81
|
-
containerPadding = positionParams.containerPadding,
|
|
82
|
-
rowHeight = positionParams.rowHeight;
|
|
83
|
-
var colWidth = calcGridColWidth(positionParams);
|
|
84
|
-
var out = {}; // If resizing, use the exact width and height as returned from resizing callbacks.
|
|
85
|
-
|
|
52
|
+
function calcGridItemPosition(positionParams /*: PositionParams*/, x /*: number*/, y /*: number*/, w /*: number*/, h /*: number*/, state /*: ?Object*/) /*: Position*/{
|
|
53
|
+
const {
|
|
54
|
+
margin,
|
|
55
|
+
containerPadding,
|
|
56
|
+
rowHeight
|
|
57
|
+
} = positionParams;
|
|
58
|
+
const colWidth = calcGridColWidth(positionParams);
|
|
59
|
+
const out = {};
|
|
60
|
+
|
|
61
|
+
// If resizing, use the exact width and height as returned from resizing callbacks.
|
|
86
62
|
if (state && state.resizing) {
|
|
87
63
|
out.width = Math.round(state.resizing.width);
|
|
88
64
|
out.height = Math.round(state.resizing.height);
|
|
89
|
-
}
|
|
65
|
+
}
|
|
66
|
+
// Otherwise, calculate from grid units.
|
|
90
67
|
else {
|
|
91
68
|
out.width = calcGridItemWHPx(w, colWidth, margin[0]);
|
|
92
69
|
out.height = calcGridItemWHPx(h, rowHeight, margin[1]);
|
|
93
|
-
}
|
|
94
|
-
|
|
70
|
+
}
|
|
95
71
|
|
|
72
|
+
// If dragging, use the exact width and height as returned from dragging callbacks.
|
|
96
73
|
if (state && state.dragging) {
|
|
97
74
|
out.top = Math.round(state.dragging.top);
|
|
98
75
|
out.left = Math.round(state.dragging.left);
|
|
99
|
-
}
|
|
76
|
+
} else if (state && state.resizing && typeof state.resizing.top === "number" && typeof state.resizing.left === "number") {
|
|
77
|
+
out.top = Math.round(state.resizing.top);
|
|
78
|
+
out.left = Math.round(state.resizing.left);
|
|
79
|
+
}
|
|
80
|
+
// Otherwise, calculate from grid units.
|
|
100
81
|
else {
|
|
101
82
|
out.top = Math.round((rowHeight + margin[1]) * y + containerPadding[1]);
|
|
102
83
|
out.left = Math.round((colWidth + margin[0]) * x + containerPadding[0]);
|
|
103
84
|
}
|
|
104
|
-
|
|
105
85
|
return out;
|
|
106
86
|
}
|
|
87
|
+
|
|
107
88
|
/**
|
|
108
89
|
* Translate x and y coordinates from pixels to grid units.
|
|
109
90
|
* @param {PositionParams} positionParams Parameters of grid needed for coordinates calculations.
|
|
@@ -113,43 +94,34 @@ function calcGridItemPosition(positionParams
|
|
|
113
94
|
* @param {Number} h H coordinate in grid units.
|
|
114
95
|
* @return {Object} x and y in grid units.
|
|
115
96
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
, h
|
|
127
|
-
/*: number*/
|
|
128
|
-
)
|
|
129
|
-
/*: { x: number, y: number }*/
|
|
130
|
-
{
|
|
131
|
-
var margin = positionParams.margin,
|
|
132
|
-
cols = positionParams.cols,
|
|
133
|
-
rowHeight = positionParams.rowHeight,
|
|
134
|
-
maxRows = positionParams.maxRows;
|
|
135
|
-
var colWidth = calcGridColWidth(positionParams); // left = colWidth * x + margin * (x + 1)
|
|
97
|
+
function calcXY(positionParams /*: PositionParams*/, top /*: number*/, left /*: number*/, w /*: number*/, h /*: number*/) /*: { x: number, y: number }*/{
|
|
98
|
+
const {
|
|
99
|
+
margin,
|
|
100
|
+
cols,
|
|
101
|
+
rowHeight,
|
|
102
|
+
maxRows
|
|
103
|
+
} = positionParams;
|
|
104
|
+
const colWidth = calcGridColWidth(positionParams);
|
|
105
|
+
|
|
106
|
+
// left = colWidth * x + margin * (x + 1)
|
|
136
107
|
// l = cx + m(x+1)
|
|
137
108
|
// l = cx + mx + m
|
|
138
109
|
// l - m = cx + mx
|
|
139
110
|
// l - m = x(c + m)
|
|
140
111
|
// (l - m) / (c + m) = x
|
|
141
112
|
// x = (left - margin) / (coldWidth + margin)
|
|
113
|
+
let x = Math.round((left - margin[0]) / (colWidth + margin[0]));
|
|
114
|
+
let y = Math.round((top - margin[1]) / (rowHeight + margin[1]));
|
|
142
115
|
|
|
143
|
-
|
|
144
|
-
var y = Math.round((top - margin[1]) / (rowHeight + margin[1])); // Capping
|
|
145
|
-
|
|
116
|
+
// Capping
|
|
146
117
|
x = clamp(x, 0, cols - w);
|
|
147
118
|
y = clamp(y, 0, maxRows - h);
|
|
148
119
|
return {
|
|
149
|
-
x
|
|
150
|
-
y
|
|
120
|
+
x,
|
|
121
|
+
y
|
|
151
122
|
};
|
|
152
123
|
}
|
|
124
|
+
|
|
153
125
|
/**
|
|
154
126
|
* Given a height and width in pixel values, calculate grid units.
|
|
155
127
|
* @param {PositionParams} positionParams Parameters of grid needed for coordinates calcluations.
|
|
@@ -157,51 +129,40 @@ function calcXY(positionParams
|
|
|
157
129
|
* @param {Number} width Width in pixels.
|
|
158
130
|
* @param {Number} x X coordinate in grid units.
|
|
159
131
|
* @param {Number} y Y coordinate in grid units.
|
|
132
|
+
* @param {String} handle Resize Handle.
|
|
160
133
|
* @return {Object} w, h as grid units.
|
|
161
134
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
, y
|
|
173
|
-
/*: number*/
|
|
174
|
-
)
|
|
175
|
-
/*: { w: number, h: number }*/
|
|
176
|
-
{
|
|
177
|
-
var margin = positionParams.margin,
|
|
178
|
-
maxRows = positionParams.maxRows,
|
|
179
|
-
cols = positionParams.cols,
|
|
180
|
-
rowHeight = positionParams.rowHeight;
|
|
181
|
-
var colWidth = calcGridColWidth(positionParams); // width = colWidth * w - (margin * (w - 1))
|
|
135
|
+
function calcWH(positionParams /*: PositionParams*/, width /*: number*/, height /*: number*/, x /*: number*/, y /*: number*/, handle /*: string*/) /*: { w: number, h: number }*/{
|
|
136
|
+
const {
|
|
137
|
+
margin,
|
|
138
|
+
maxRows,
|
|
139
|
+
cols,
|
|
140
|
+
rowHeight
|
|
141
|
+
} = positionParams;
|
|
142
|
+
const colWidth = calcGridColWidth(positionParams);
|
|
143
|
+
|
|
144
|
+
// width = colWidth * w - (margin * (w - 1))
|
|
182
145
|
// ...
|
|
183
146
|
// w = (width + margin) / (colWidth + margin)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
+
}
|
|
190
159
|
return {
|
|
191
|
-
w:
|
|
192
|
-
h:
|
|
160
|
+
w: _w,
|
|
161
|
+
h: _h
|
|
193
162
|
};
|
|
194
|
-
}
|
|
195
|
-
|
|
163
|
+
}
|
|
196
164
|
|
|
197
|
-
|
|
198
|
-
/*: number*/
|
|
199
|
-
, lowerBound
|
|
200
|
-
/*: number*/
|
|
201
|
-
, upperBound
|
|
202
|
-
/*: number*/
|
|
203
|
-
)
|
|
204
|
-
/*: number*/
|
|
205
|
-
{
|
|
165
|
+
// Similar to _.clamp
|
|
166
|
+
function clamp(num /*: number*/, lowerBound /*: number*/, upperBound /*: number*/) /*: number*/{
|
|
206
167
|
return Math.max(Math.min(num, upperBound), lowerBound);
|
|
207
168
|
}
|
|
@@ -1,151 +1,108 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
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
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.default = WidthProvideRGL;
|
|
9
|
-
|
|
10
7
|
var React = _interopRequireWildcard(require("react"));
|
|
11
|
-
|
|
12
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
|
|
9
|
+
var _resizeObserverPolyfill = _interopRequireDefault(require("resize-observer-polyfill"));
|
|
14
10
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
15
|
-
|
|
16
|
-
var _excluded = ["measureBeforeMount"];
|
|
17
|
-
|
|
18
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
15
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
|
+
/*:: import type { ReactRef } from "../ReactGridLayoutPropTypes";*/
|
|
19
|
+
/*:: type WPDefaultProps = {|
|
|
20
|
+
measureBeforeMount: boolean
|
|
21
|
+
|};*/
|
|
22
|
+
/*:: type WPProps = {|
|
|
23
|
+
className?: string,
|
|
24
|
+
style?: Object,
|
|
25
|
+
...WPDefaultProps
|
|
26
|
+
|};*/
|
|
27
|
+
// eslint-disable-next-line no-unused-vars
|
|
28
|
+
/*:: type WPState = {|
|
|
29
|
+
width: number
|
|
30
|
+
|};*/
|
|
31
|
+
/*:: type ComposedProps<Config> = {|
|
|
32
|
+
...Config,
|
|
33
|
+
measureBeforeMount?: boolean,
|
|
34
|
+
className?: string,
|
|
35
|
+
style?: Object,
|
|
36
|
+
width?: number
|
|
37
|
+
|};*/
|
|
38
|
+
const layoutClassName = "react-grid-layout";
|
|
19
39
|
|
|
20
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
-
|
|
22
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
|
|
24
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
25
|
-
|
|
26
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
27
|
-
|
|
28
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
29
|
-
|
|
30
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
31
|
-
|
|
32
|
-
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); } }
|
|
33
|
-
|
|
34
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
35
|
-
|
|
36
|
-
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
37
|
-
|
|
38
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
39
|
-
|
|
40
|
-
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); }; }
|
|
41
|
-
|
|
42
|
-
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); }
|
|
43
|
-
|
|
44
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
45
|
-
|
|
46
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
47
|
-
|
|
48
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
49
|
-
|
|
50
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
51
|
-
|
|
52
|
-
var layoutClassName = "react-grid-layout";
|
|
53
40
|
/*
|
|
54
41
|
* A simple HOC that provides facility for listening to container resizes.
|
|
55
42
|
*
|
|
56
43
|
* The Flow type is pretty janky here. I can't just spread `WPProps` into this returned object - I wish I could - but it triggers
|
|
57
44
|
* a flow bug of some sort that causes it to stop typechecking.
|
|
58
45
|
*/
|
|
59
|
-
|
|
60
|
-
function WidthProvideRGL
|
|
61
|
-
/*:: <Config>*/
|
|
62
|
-
(ComposedComponent
|
|
63
|
-
/*: React.AbstractComponent<Config>*/
|
|
64
|
-
)
|
|
65
|
-
/*: React.AbstractComponent<ComposedProps<Config>>*/
|
|
66
|
-
{
|
|
46
|
+
function WidthProvideRGL /*:: <Config>*/(ComposedComponent /*: React.AbstractComponent<Config>*/) /*: React.AbstractComponent<ComposedProps<Config>>*/{
|
|
67
47
|
var _class;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
_classCallCheck(this, WidthProvider);
|
|
78
|
-
|
|
79
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
80
|
-
args[_key] = arguments[_key];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
84
|
-
|
|
85
|
-
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
48
|
+
return _class = class WidthProvider extends React.Component
|
|
49
|
+
/*:: <
|
|
50
|
+
ComposedProps<Config>,
|
|
51
|
+
WPState
|
|
52
|
+
>*/
|
|
53
|
+
{
|
|
54
|
+
constructor() {
|
|
55
|
+
super(...arguments);
|
|
56
|
+
_defineProperty(this, "state", {
|
|
86
57
|
width: 1280
|
|
87
58
|
});
|
|
88
|
-
|
|
89
|
-
_defineProperty(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
_this.setState({
|
|
101
|
-
width: node.offsetWidth
|
|
59
|
+
_defineProperty(this, "elementRef", /*#__PURE__*/React.createRef());
|
|
60
|
+
_defineProperty(this, "mounted", false);
|
|
61
|
+
_defineProperty(this, "resizeObserver", void 0);
|
|
62
|
+
}
|
|
63
|
+
componentDidMount() {
|
|
64
|
+
this.mounted = true;
|
|
65
|
+
this.resizeObserver = new _resizeObserverPolyfill.default(entries => {
|
|
66
|
+
const node = this.elementRef.current;
|
|
67
|
+
if (node instanceof HTMLElement) {
|
|
68
|
+
const width = entries[0].contentRect.width;
|
|
69
|
+
this.setState({
|
|
70
|
+
width
|
|
102
71
|
});
|
|
103
72
|
}
|
|
104
73
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
_createClass(WidthProvider, [{
|
|
110
|
-
key: "componentDidMount",
|
|
111
|
-
value: function componentDidMount() {
|
|
112
|
-
this.mounted = true;
|
|
113
|
-
window.addEventListener("resize", this.onWindowResize); // Call to properly set the breakpoint and resize the elements.
|
|
114
|
-
// Note that if you're doing a full-width element, this can get a little wonky if a scrollbar
|
|
115
|
-
// appears because of the grid. In that case, fire your own resize event, or set `overflow: scroll` on your body.
|
|
116
|
-
|
|
117
|
-
this.onWindowResize();
|
|
74
|
+
const node = this.elementRef.current;
|
|
75
|
+
if (node instanceof HTMLElement) {
|
|
76
|
+
this.resizeObserver.observe(node);
|
|
118
77
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
78
|
+
}
|
|
79
|
+
componentWillUnmount() {
|
|
80
|
+
this.mounted = false;
|
|
81
|
+
const node = this.elementRef.current;
|
|
82
|
+
if (node instanceof HTMLElement) {
|
|
83
|
+
this.resizeObserver.unobserve(node);
|
|
124
84
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return /*#__PURE__*/React.createElement(ComposedComponent, _extends({
|
|
142
|
-
innerRef: this.elementRef
|
|
143
|
-
}, rest, this.state));
|
|
85
|
+
this.resizeObserver.disconnect();
|
|
86
|
+
}
|
|
87
|
+
render() {
|
|
88
|
+
const {
|
|
89
|
+
measureBeforeMount,
|
|
90
|
+
...rest
|
|
91
|
+
} = this.props;
|
|
92
|
+
if (measureBeforeMount && !this.mounted) {
|
|
93
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
94
|
+
className: (0, _clsx.default)(this.props.className, layoutClassName),
|
|
95
|
+
style: this.props.style
|
|
96
|
+
// $FlowIgnore ref types
|
|
97
|
+
,
|
|
98
|
+
ref: this.elementRef
|
|
99
|
+
});
|
|
144
100
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
101
|
+
return /*#__PURE__*/React.createElement(ComposedComponent, _extends({
|
|
102
|
+
innerRef: this.elementRef
|
|
103
|
+
}, rest, this.state));
|
|
104
|
+
}
|
|
105
|
+
}, _defineProperty(_class, "defaultProps", {
|
|
149
106
|
measureBeforeMount: false
|
|
150
107
|
}), _defineProperty(_class, "propTypes", {
|
|
151
108
|
// If true, will not render children until mounted. Useful for getting the exact width before
|
package/build/responsiveUtils.js
CHANGED
|
@@ -7,9 +7,21 @@ exports.findOrGenerateResponsiveLayout = findOrGenerateResponsiveLayout;
|
|
|
7
7
|
exports.getBreakpointFromWidth = getBreakpointFromWidth;
|
|
8
8
|
exports.getColsFromBreakpoint = getColsFromBreakpoint;
|
|
9
9
|
exports.sortBreakpoints = sortBreakpoints;
|
|
10
|
-
|
|
11
10
|
var _utils = require("./utils");
|
|
12
|
-
|
|
11
|
+
/*:: import type { CompactType, Layout } from "./utils";*/
|
|
12
|
+
/*:: export type Breakpoint = string;*/
|
|
13
|
+
/*:: export type DefaultBreakpoints = "lg" | "md" | "sm" | "xs" | "xxs";*/
|
|
14
|
+
/*:: export type ResponsiveLayout<T: Breakpoint> = {
|
|
15
|
+
+[breakpoint: T]: Layout
|
|
16
|
+
};*/
|
|
17
|
+
// + indicates read-only
|
|
18
|
+
/*:: export type Breakpoints<T: Breakpoint> = {
|
|
19
|
+
+[breakpoint: T]: number
|
|
20
|
+
};*/
|
|
21
|
+
/*:: export type OnLayoutChangeCallback = (
|
|
22
|
+
Layout,
|
|
23
|
+
{ [key: Breakpoint]: Layout }
|
|
24
|
+
) => void;*/
|
|
13
25
|
/**
|
|
14
26
|
* Given a width, find the highest breakpoint that matches is valid for it (width > breakpoint).
|
|
15
27
|
*
|
|
@@ -17,44 +29,29 @@ var _utils = require("./utils");
|
|
|
17
29
|
* @param {Number} width Screen width.
|
|
18
30
|
* @return {String} Highest breakpoint that is less than width.
|
|
19
31
|
*/
|
|
20
|
-
function getBreakpointFromWidth(breakpoints
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/*: Breakpoint*/
|
|
26
|
-
{
|
|
27
|
-
var sorted = sortBreakpoints(breakpoints);
|
|
28
|
-
var matching = sorted[0];
|
|
29
|
-
|
|
30
|
-
for (var i = 1, len = sorted.length; i < len; i++) {
|
|
31
|
-
var breakpointName = sorted[i];
|
|
32
|
+
function getBreakpointFromWidth(breakpoints /*: Breakpoints<Breakpoint>*/, width /*: number*/) /*: Breakpoint*/{
|
|
33
|
+
const sorted = sortBreakpoints(breakpoints);
|
|
34
|
+
let matching = sorted[0];
|
|
35
|
+
for (let i = 1, len = sorted.length; i < len; i++) {
|
|
36
|
+
const breakpointName = sorted[i];
|
|
32
37
|
if (width > breakpoints[breakpointName]) matching = breakpointName;
|
|
33
38
|
}
|
|
34
|
-
|
|
35
39
|
return matching;
|
|
36
40
|
}
|
|
41
|
+
|
|
37
42
|
/**
|
|
38
43
|
* Given a breakpoint, get the # of cols set for it.
|
|
39
44
|
* @param {String} breakpoint Breakpoint name.
|
|
40
45
|
* @param {Object} cols Map of breakpoints to cols.
|
|
41
46
|
* @return {Number} Number of cols.
|
|
42
47
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
function getColsFromBreakpoint(breakpoint
|
|
46
|
-
/*: Breakpoint*/
|
|
47
|
-
, cols
|
|
48
|
-
/*: Breakpoints<Breakpoint>*/
|
|
49
|
-
)
|
|
50
|
-
/*: number*/
|
|
51
|
-
{
|
|
48
|
+
function getColsFromBreakpoint(breakpoint /*: Breakpoint*/, cols /*: Breakpoints<Breakpoint>*/) /*: number*/{
|
|
52
49
|
if (!cols[breakpoint]) {
|
|
53
50
|
throw new Error("ResponsiveReactGridLayout: `cols` entry for breakpoint " + breakpoint + " is missing!");
|
|
54
51
|
}
|
|
55
|
-
|
|
56
52
|
return cols[breakpoint];
|
|
57
53
|
}
|
|
54
|
+
|
|
58
55
|
/**
|
|
59
56
|
* Given existing layouts and a new breakpoint, find or generate a new layout.
|
|
60
57
|
*
|
|
@@ -69,45 +66,26 @@ function getColsFromBreakpoint(breakpoint
|
|
|
69
66
|
* vertically.
|
|
70
67
|
* @return {Array} New layout.
|
|
71
68
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
function findOrGenerateResponsiveLayout(layouts
|
|
75
|
-
/*: ResponsiveLayout<Breakpoint>*/
|
|
76
|
-
, breakpoints
|
|
77
|
-
/*: Breakpoints<Breakpoint>*/
|
|
78
|
-
, breakpoint
|
|
79
|
-
/*: Breakpoint*/
|
|
80
|
-
, lastBreakpoint
|
|
81
|
-
/*: Breakpoint*/
|
|
82
|
-
, cols
|
|
83
|
-
/*: number*/
|
|
84
|
-
, compactType
|
|
85
|
-
/*: CompactType*/
|
|
86
|
-
)
|
|
87
|
-
/*: Layout*/
|
|
88
|
-
{
|
|
69
|
+
function findOrGenerateResponsiveLayout(layouts /*: ResponsiveLayout<Breakpoint>*/, breakpoints /*: Breakpoints<Breakpoint>*/, breakpoint /*: Breakpoint*/, lastBreakpoint /*: Breakpoint*/, cols /*: number*/, compactType /*: CompactType*/) /*: Layout*/{
|
|
89
70
|
// If it already exists, just return it.
|
|
90
|
-
if (layouts[breakpoint]) return (0, _utils.cloneLayout)(layouts[breakpoint]);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var b = breakpointsAbove[i];
|
|
98
|
-
|
|
71
|
+
if (layouts[breakpoint]) return (0, _utils.cloneLayout)(layouts[breakpoint]);
|
|
72
|
+
// Find or generate the next layout
|
|
73
|
+
let layout = layouts[lastBreakpoint];
|
|
74
|
+
const breakpointsSorted = sortBreakpoints(breakpoints);
|
|
75
|
+
const breakpointsAbove = breakpointsSorted.slice(breakpointsSorted.indexOf(breakpoint));
|
|
76
|
+
for (let i = 0, len = breakpointsAbove.length; i < len; i++) {
|
|
77
|
+
const b = breakpointsAbove[i];
|
|
99
78
|
if (layouts[b]) {
|
|
100
79
|
layout = layouts[b];
|
|
101
80
|
break;
|
|
102
81
|
}
|
|
103
82
|
}
|
|
104
|
-
|
|
105
83
|
layout = (0, _utils.cloneLayout)(layout || []); // clone layout so we don't modify existing items
|
|
106
|
-
|
|
107
84
|
return (0, _utils.compact)((0, _utils.correctBounds)(layout, {
|
|
108
85
|
cols: cols
|
|
109
86
|
}), compactType, cols);
|
|
110
87
|
}
|
|
88
|
+
|
|
111
89
|
/**
|
|
112
90
|
* Given breakpoints, return an array of breakpoints sorted by width. This is usually
|
|
113
91
|
* e.g. ['xxs', 'xs', 'sm', ...]
|
|
@@ -115,16 +93,8 @@ function findOrGenerateResponsiveLayout(layouts
|
|
|
115
93
|
* @param {Object} breakpoints Key/value pair of breakpoint names to widths.
|
|
116
94
|
* @return {Array} Sorted breakpoints.
|
|
117
95
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
function sortBreakpoints(breakpoints
|
|
121
|
-
/*: Breakpoints<Breakpoint>*/
|
|
122
|
-
)
|
|
123
|
-
/*: Array<Breakpoint>*/
|
|
124
|
-
{
|
|
125
|
-
var keys
|
|
126
|
-
/*: Array<string>*/
|
|
127
|
-
= Object.keys(breakpoints);
|
|
96
|
+
function sortBreakpoints(breakpoints /*: Breakpoints<Breakpoint>*/) /*: Array<Breakpoint>*/{
|
|
97
|
+
const keys /*: Array<string>*/ = Object.keys(breakpoints);
|
|
128
98
|
return keys.sort(function (a, b) {
|
|
129
99
|
return breakpoints[a] - breakpoints[b];
|
|
130
100
|
});
|