react-grid-layout 0.17.1 → 0.18.3
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/.babelrc.js +10 -14
- package/.flowconfig +13 -1
- package/.travis.yml +3 -1
- package/CHANGELOG.md +66 -0
- package/README.md +47 -7
- package/__mocks__/react-grid-layout.js +2 -0
- package/build/GridItem.js +125 -211
- package/build/ReactGridLayout.js +142 -220
- package/build/ReactGridLayoutPropTypes.js +129 -0
- package/build/ResponsiveReactGridLayout.js +52 -44
- package/build/calculateUtils.js +177 -0
- package/build/components/WidthProvider.js +21 -11
- package/build/fastRGLPropsEqual.js +5 -0
- package/build/responsiveUtils.js +5 -5
- package/build/utils.js +77 -10
- package/css/styles.css +4 -0
- package/flow-typed/npm/classnames_v2.x.x.js +23 -0
- package/flow-typed/npm/enzyme_v3.x.x.js +143 -0
- package/flow-typed/npm/jest_v24.x.x.js +1182 -0
- package/lib/GridItem.jsx +125 -148
- package/lib/ReactGridLayout.jsx +83 -200
- package/lib/ReactGridLayoutPropTypes.js +179 -0
- package/lib/ResponsiveReactGridLayout.jsx +36 -28
- package/lib/calculateUtils.js +142 -0
- package/lib/components/WidthProvider.jsx +35 -16
- package/lib/fastRGLPropsEqual.js +46 -0
- package/lib/responsiveUtils.js +13 -20
- package/lib/utils.js +62 -10
- package/package.json +44 -29
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
var _default = {
|
|
15
|
+
//
|
|
16
|
+
// Basic props
|
|
17
|
+
//
|
|
18
|
+
className: _propTypes.default.string,
|
|
19
|
+
style: _propTypes.default.object,
|
|
20
|
+
// This can be set explicitly. If it is not set, it will automatically
|
|
21
|
+
// be set to the container width. Note that resizes will *not* cause this to adjust.
|
|
22
|
+
// If you need that behavior, use WidthProvider.
|
|
23
|
+
width: _propTypes.default.number,
|
|
24
|
+
// If true, the container height swells and contracts to fit contents
|
|
25
|
+
autoSize: _propTypes.default.bool,
|
|
26
|
+
// # of cols.
|
|
27
|
+
cols: _propTypes.default.number,
|
|
28
|
+
// A selector that will not be draggable.
|
|
29
|
+
draggableCancel: _propTypes.default.string,
|
|
30
|
+
// A selector for the draggable handler
|
|
31
|
+
draggableHandle: _propTypes.default.string,
|
|
32
|
+
// Deprecated
|
|
33
|
+
verticalCompact: function verticalCompact(props
|
|
34
|
+
/*: Props*/
|
|
35
|
+
) {
|
|
36
|
+
if (props.verticalCompact === false && process.env.NODE_ENV !== "production") {
|
|
37
|
+
console.warn( // eslint-disable-line no-console
|
|
38
|
+
"`verticalCompact` on <ReactGridLayout> is deprecated and will be removed soon. " + 'Use `compactType`: "horizontal" | "vertical" | null.');
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
// Choose vertical or hotizontal compaction
|
|
42
|
+
compactType: _propTypes.default.oneOf(["vertical", "horizontal"]),
|
|
43
|
+
// layout is an array of object with the format:
|
|
44
|
+
// {x: Number, y: Number, w: Number, h: Number, i: String}
|
|
45
|
+
layout: function layout(props
|
|
46
|
+
/*: Props*/
|
|
47
|
+
) {
|
|
48
|
+
var layout = props.layout; // I hope you're setting the data-grid property on the grid items
|
|
49
|
+
|
|
50
|
+
if (layout === undefined) return;
|
|
51
|
+
|
|
52
|
+
require("./utils").validateLayout(layout, "layout");
|
|
53
|
+
},
|
|
54
|
+
//
|
|
55
|
+
// Grid Dimensions
|
|
56
|
+
//
|
|
57
|
+
// Margin between items [x, y] in px
|
|
58
|
+
margin: _propTypes.default.arrayOf(_propTypes.default.number),
|
|
59
|
+
// Padding inside the container [x, y] in px
|
|
60
|
+
containerPadding: _propTypes.default.arrayOf(_propTypes.default.number),
|
|
61
|
+
// Rows have a static height, but you can change this based on breakpoints if you like
|
|
62
|
+
rowHeight: _propTypes.default.number,
|
|
63
|
+
// Default Infinity, but you can specify a max here if you like.
|
|
64
|
+
// Note that this isn't fully fleshed out and won't error if you specify a layout that
|
|
65
|
+
// extends beyond the row capacity. It will, however, not allow users to drag/resize
|
|
66
|
+
// an item past the barrier. They can push items beyond the barrier, though.
|
|
67
|
+
// Intentionally not documented for this reason.
|
|
68
|
+
maxRows: _propTypes.default.number,
|
|
69
|
+
//
|
|
70
|
+
// Flags
|
|
71
|
+
//
|
|
72
|
+
isDraggable: _propTypes.default.bool,
|
|
73
|
+
isResizable: _propTypes.default.bool,
|
|
74
|
+
// If true, grid items won't change position when being dragged over.
|
|
75
|
+
preventCollision: _propTypes.default.bool,
|
|
76
|
+
// Use CSS transforms instead of top/left
|
|
77
|
+
useCSSTransforms: _propTypes.default.bool,
|
|
78
|
+
// parent layout transform scale
|
|
79
|
+
transformScale: _propTypes.default.number,
|
|
80
|
+
// If true, an external element can trigger onDrop callback with a specific grid position as a parameter
|
|
81
|
+
isDroppable: _propTypes.default.bool,
|
|
82
|
+
//
|
|
83
|
+
// Callbacks
|
|
84
|
+
//
|
|
85
|
+
// Callback so you can save the layout. Calls after each drag & resize stops.
|
|
86
|
+
onLayoutChange: _propTypes.default.func,
|
|
87
|
+
// Calls when drag starts. Callback is of the signature (layout, oldItem, newItem, placeholder, e, ?node).
|
|
88
|
+
// All callbacks below have the same signature. 'start' and 'stop' callbacks omit the 'placeholder'.
|
|
89
|
+
onDragStart: _propTypes.default.func,
|
|
90
|
+
// Calls on each drag movement.
|
|
91
|
+
onDrag: _propTypes.default.func,
|
|
92
|
+
// Calls when drag is complete.
|
|
93
|
+
onDragStop: _propTypes.default.func,
|
|
94
|
+
//Calls when resize starts.
|
|
95
|
+
onResizeStart: _propTypes.default.func,
|
|
96
|
+
// Calls when resize movement happens.
|
|
97
|
+
onResize: _propTypes.default.func,
|
|
98
|
+
// Calls when resize is complete.
|
|
99
|
+
onResizeStop: _propTypes.default.func,
|
|
100
|
+
// Calls when some element is dropped.
|
|
101
|
+
onDrop: _propTypes.default.func,
|
|
102
|
+
//
|
|
103
|
+
// Other validations
|
|
104
|
+
//
|
|
105
|
+
droppingItem: _propTypes.default.shape({
|
|
106
|
+
i: _propTypes.default.string.isRequired,
|
|
107
|
+
w: _propTypes.default.number.isRequired,
|
|
108
|
+
h: _propTypes.default.number.isRequired
|
|
109
|
+
}),
|
|
110
|
+
// Children must not have duplicate keys.
|
|
111
|
+
children: function children(props
|
|
112
|
+
/*: Props*/
|
|
113
|
+
, propName
|
|
114
|
+
/*: string*/
|
|
115
|
+
) {
|
|
116
|
+
var children = props[propName]; // Check children keys for duplicates. Throw if found.
|
|
117
|
+
|
|
118
|
+
var keys = {};
|
|
119
|
+
|
|
120
|
+
_react.default.Children.forEach(children, function (child) {
|
|
121
|
+
if (keys[child.key]) {
|
|
122
|
+
throw new Error('Duplicate child key "' + child.key + '" found! This will cause problems in ReactGridLayout.');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
keys[child.key] = true;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
exports.default = _default;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -19,7 +19,11 @@ var _ReactGridLayout = _interopRequireDefault(require("./ReactGridLayout"));
|
|
|
19
19
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
|
|
22
|
-
function
|
|
22
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
23
|
+
|
|
24
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
|
25
|
+
|
|
26
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
23
27
|
|
|
24
28
|
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
29
|
|
|
@@ -29,7 +33,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
29
33
|
|
|
30
34
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
31
35
|
|
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
36
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
33
37
|
|
|
34
38
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
35
39
|
|
|
@@ -75,14 +79,14 @@ function getIndentationValue(param
|
|
|
75
79
|
layouts?: { [key: string]: Layout }
|
|
76
80
|
};*/
|
|
77
81
|
|
|
78
|
-
/*:: type Props<Breakpoint: string = string> = {
|
|
79
|
-
|
|
82
|
+
/*:: type Props<Breakpoint: string = string> = {|
|
|
83
|
+
...React.ElementConfig<typeof ReactGridLayout>,
|
|
80
84
|
|
|
81
85
|
// Responsive config
|
|
82
|
-
breakpoint
|
|
83
|
-
breakpoints:
|
|
86
|
+
breakpoint?: ?Breakpoint,
|
|
87
|
+
breakpoints: Breakpoints<Breakpoint>,
|
|
84
88
|
cols: { [key: Breakpoint]: number },
|
|
85
|
-
layouts:
|
|
89
|
+
layouts: ResponsiveLayout<Breakpoint>,
|
|
86
90
|
width: number,
|
|
87
91
|
margin: { [key: Breakpoint]: [number, number] } | [number, number],
|
|
88
92
|
containerPadding: { [key: Breakpoint]: [number, number] } | [number, number],
|
|
@@ -96,7 +100,7 @@ function getIndentationValue(param
|
|
|
96
100
|
cols: number,
|
|
97
101
|
containerPadding: [number, number] | null
|
|
98
102
|
) => void
|
|
99
|
-
};*/
|
|
103
|
+
|};*/
|
|
100
104
|
|
|
101
105
|
|
|
102
106
|
var ResponsiveReactGridLayout =
|
|
@@ -158,7 +162,7 @@ function (_React$Component) {
|
|
|
158
162
|
) {
|
|
159
163
|
// Allow parent to set width or breakpoint directly.
|
|
160
164
|
if (this.props.width != prevProps.width || this.props.breakpoint !== prevProps.breakpoint || !(0, _lodash.default)(this.props.breakpoints, prevProps.breakpoints) || !(0, _lodash.default)(this.props.cols, prevProps.cols)) {
|
|
161
|
-
this.onWidthChange(
|
|
165
|
+
this.onWidthChange(prevProps);
|
|
162
166
|
}
|
|
163
167
|
} // wrap layouts so we do not need to pass layouts to child
|
|
164
168
|
|
|
@@ -169,30 +173,34 @@ function (_React$Component) {
|
|
|
169
173
|
* When the width changes work through breakpoints and reset state with the new width & breakpoint.
|
|
170
174
|
* Width changes are necessary to figure out the widget widths.
|
|
171
175
|
*/
|
|
172
|
-
value: function onWidthChange(
|
|
176
|
+
value: function onWidthChange(prevProps
|
|
173
177
|
/*: Props<*>*/
|
|
174
178
|
) {
|
|
175
|
-
var
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
var _this$props2 = this.props,
|
|
180
|
+
breakpoints = _this$props2.breakpoints,
|
|
181
|
+
cols = _this$props2.cols,
|
|
182
|
+
layouts = _this$props2.layouts,
|
|
183
|
+
compactType = _this$props2.compactType;
|
|
184
|
+
var newBreakpoint = this.props.breakpoint || (0, _responsiveUtils.getBreakpointFromWidth)(this.props.breakpoints, this.props.width);
|
|
180
185
|
var lastBreakpoint = this.state.breakpoint;
|
|
181
186
|
var newCols
|
|
182
187
|
/*: number*/
|
|
183
|
-
= (0, _responsiveUtils.getColsFromBreakpoint)(newBreakpoint, cols);
|
|
188
|
+
= (0, _responsiveUtils.getColsFromBreakpoint)(newBreakpoint, cols);
|
|
184
189
|
|
|
185
|
-
|
|
190
|
+
var newLayouts = _objectSpread({}, layouts); // Breakpoint change
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
if (lastBreakpoint !== newBreakpoint || prevProps.breakpoints !== breakpoints || prevProps.cols !== cols) {
|
|
186
194
|
// Preserve the current layout if the current breakpoint is not present in the next layouts.
|
|
187
|
-
if (!(lastBreakpoint in
|
|
195
|
+
if (!(lastBreakpoint in newLayouts)) newLayouts[lastBreakpoint] = (0, _utils.cloneLayout)(this.state.layout); // Find or generate a new layout.
|
|
188
196
|
|
|
189
|
-
var layout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(
|
|
197
|
+
var layout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(newLayouts, breakpoints, newBreakpoint, lastBreakpoint, newCols, compactType); // This adds missing items.
|
|
190
198
|
|
|
191
|
-
layout = (0, _utils.synchronizeLayoutWithChildren)(layout,
|
|
199
|
+
layout = (0, _utils.synchronizeLayoutWithChildren)(layout, this.props.children, newCols, compactType); // Store the new layout.
|
|
192
200
|
|
|
193
|
-
|
|
201
|
+
newLayouts[newBreakpoint] = layout; // callbacks
|
|
194
202
|
|
|
195
|
-
this.props.onLayoutChange(layout,
|
|
203
|
+
this.props.onLayoutChange(layout, newLayouts);
|
|
196
204
|
this.props.onBreakpointChange(newBreakpoint, newCols);
|
|
197
205
|
this.setState({
|
|
198
206
|
breakpoint: newBreakpoint,
|
|
@@ -201,30 +209,30 @@ function (_React$Component) {
|
|
|
201
209
|
});
|
|
202
210
|
}
|
|
203
211
|
|
|
204
|
-
var margin = getIndentationValue(
|
|
205
|
-
var containerPadding = getIndentationValue(
|
|
212
|
+
var margin = getIndentationValue(this.props.margin, newBreakpoint);
|
|
213
|
+
var containerPadding = getIndentationValue(this.props.containerPadding, newBreakpoint); //call onWidthChange on every change of width, not only on breakpoint changes
|
|
206
214
|
|
|
207
|
-
this.props.onWidthChange(
|
|
215
|
+
this.props.onWidthChange(this.props.width, margin, newCols, containerPadding);
|
|
208
216
|
}
|
|
209
217
|
}, {
|
|
210
218
|
key: "render",
|
|
211
219
|
value: function render() {
|
|
212
220
|
/* eslint-disable no-unused-vars */
|
|
213
|
-
var _this$
|
|
214
|
-
breakpoint = _this$
|
|
215
|
-
breakpoints = _this$
|
|
216
|
-
cols = _this$
|
|
217
|
-
layouts = _this$
|
|
218
|
-
margin = _this$
|
|
219
|
-
containerPadding = _this$
|
|
220
|
-
onBreakpointChange = _this$
|
|
221
|
-
onLayoutChange = _this$
|
|
222
|
-
onWidthChange = _this$
|
|
223
|
-
other = _objectWithoutProperties(_this$
|
|
221
|
+
var _this$props3 = this.props,
|
|
222
|
+
breakpoint = _this$props3.breakpoint,
|
|
223
|
+
breakpoints = _this$props3.breakpoints,
|
|
224
|
+
cols = _this$props3.cols,
|
|
225
|
+
layouts = _this$props3.layouts,
|
|
226
|
+
margin = _this$props3.margin,
|
|
227
|
+
containerPadding = _this$props3.containerPadding,
|
|
228
|
+
onBreakpointChange = _this$props3.onBreakpointChange,
|
|
229
|
+
onLayoutChange = _this$props3.onLayoutChange,
|
|
230
|
+
onWidthChange = _this$props3.onWidthChange,
|
|
231
|
+
other = _objectWithoutProperties(_this$props3, ["breakpoint", "breakpoints", "cols", "layouts", "margin", "containerPadding", "onBreakpointChange", "onLayoutChange", "onWidthChange"]);
|
|
224
232
|
/* eslint-enable no-unused-vars */
|
|
225
233
|
|
|
226
234
|
|
|
227
|
-
return
|
|
235
|
+
return React.createElement(_ReactGridLayout.default, _extends({}, other, {
|
|
228
236
|
margin: getIndentationValue(margin, this.state.breakpoint),
|
|
229
237
|
containerPadding: getIndentationValue(containerPadding, this.state.breakpoint),
|
|
230
238
|
onLayoutChange: this.onLayoutChange,
|
|
@@ -257,7 +265,7 @@ function (_React$Component) {
|
|
|
257
265
|
}]);
|
|
258
266
|
|
|
259
267
|
return ResponsiveReactGridLayout;
|
|
260
|
-
}(
|
|
268
|
+
}(React.Component);
|
|
261
269
|
|
|
262
270
|
exports.default = ResponsiveReactGridLayout;
|
|
263
271
|
|
|
@@ -334,11 +342,11 @@ _defineProperty(ResponsiveReactGridLayout, "defaultProps", {
|
|
|
334
342
|
layouts: {},
|
|
335
343
|
margin: [10, 10],
|
|
336
344
|
containerPadding: {
|
|
337
|
-
lg:
|
|
338
|
-
md:
|
|
339
|
-
sm:
|
|
340
|
-
xs:
|
|
341
|
-
xxs:
|
|
345
|
+
lg: [0, 0],
|
|
346
|
+
md: [0, 0],
|
|
347
|
+
sm: [0, 0],
|
|
348
|
+
xs: [0, 0],
|
|
349
|
+
xxs: [0, 0]
|
|
342
350
|
},
|
|
343
351
|
onBreakpointChange: _utils.noop,
|
|
344
352
|
onLayoutChange: _utils.noop,
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calcGridColWidth = calcGridColWidth;
|
|
7
|
+
exports.calcGridItemPosition = calcGridItemPosition;
|
|
8
|
+
exports.calcXY = calcXY;
|
|
9
|
+
exports.calcWH = calcWH;
|
|
10
|
+
|
|
11
|
+
/*:: import type { Position } from "./utils";*/
|
|
12
|
+
|
|
13
|
+
/*:: export type PositionParams = {
|
|
14
|
+
margin: [number, number],
|
|
15
|
+
containerPadding: [number, number],
|
|
16
|
+
containerWidth: number,
|
|
17
|
+
cols: number,
|
|
18
|
+
rowHeight: number,
|
|
19
|
+
maxRows: number
|
|
20
|
+
};*/
|
|
21
|
+
// Helper for generating column width
|
|
22
|
+
function calcGridColWidth(positionParams
|
|
23
|
+
/*: PositionParams*/
|
|
24
|
+
)
|
|
25
|
+
/*: number*/
|
|
26
|
+
{
|
|
27
|
+
var margin = positionParams.margin,
|
|
28
|
+
containerPadding = positionParams.containerPadding,
|
|
29
|
+
containerWidth = positionParams.containerWidth,
|
|
30
|
+
cols = positionParams.cols;
|
|
31
|
+
return (containerWidth - margin[0] * (cols - 1) - containerPadding[0] * 2) / cols;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Return position on the page given an x, y, w, h.
|
|
35
|
+
* left, top, width, height are all in pixels.
|
|
36
|
+
* @param {PositionParams} positionParams Parameters of grid needed for coordinates calculations.
|
|
37
|
+
* @param {Number} x X coordinate in grid units.
|
|
38
|
+
* @param {Number} y Y coordinate in grid units.
|
|
39
|
+
* @param {Number} w W coordinate in grid units.
|
|
40
|
+
* @param {Number} h H coordinate in grid units.
|
|
41
|
+
* @return {Position} Object containing coords.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
function calcGridItemPosition(positionParams
|
|
46
|
+
/*: PositionParams*/
|
|
47
|
+
, x
|
|
48
|
+
/*: number*/
|
|
49
|
+
, y
|
|
50
|
+
/*: number*/
|
|
51
|
+
, w
|
|
52
|
+
/*: number*/
|
|
53
|
+
, h
|
|
54
|
+
/*: number*/
|
|
55
|
+
, state
|
|
56
|
+
/*: ?Object*/
|
|
57
|
+
)
|
|
58
|
+
/*: Position*/
|
|
59
|
+
{
|
|
60
|
+
var margin = positionParams.margin,
|
|
61
|
+
containerPadding = positionParams.containerPadding,
|
|
62
|
+
rowHeight = positionParams.rowHeight;
|
|
63
|
+
var colWidth = calcGridColWidth(positionParams);
|
|
64
|
+
var out = {}; // If resizing, use the exact width and height as returned from resizing callbacks.
|
|
65
|
+
|
|
66
|
+
if (state && state.resizing) {
|
|
67
|
+
out.width = Math.round(state.resizing.width);
|
|
68
|
+
out.height = Math.round(state.resizing.height);
|
|
69
|
+
} // Otherwise, calculate from grid units.
|
|
70
|
+
else {
|
|
71
|
+
// 0 * Infinity === NaN, which causes problems with resize constraints;
|
|
72
|
+
// Fix this if it occurs.
|
|
73
|
+
// Note we do it here rather than later because Math.round(Infinity) causes deopt
|
|
74
|
+
out.width = w === Infinity ? w : Math.round(colWidth * w + Math.max(0, w - 1) * margin[0]);
|
|
75
|
+
out.height = h === Infinity ? h : Math.round(rowHeight * h + Math.max(0, h - 1) * margin[1]);
|
|
76
|
+
} // If dragging, use the exact width and height as returned from dragging callbacks.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
if (state && state.dragging) {
|
|
80
|
+
out.top = Math.round(state.dragging.top);
|
|
81
|
+
out.left = Math.round(state.dragging.left);
|
|
82
|
+
} // Otherwise, calculate from grid units.
|
|
83
|
+
else {
|
|
84
|
+
out.top = Math.round((rowHeight + margin[1]) * y + containerPadding[1]);
|
|
85
|
+
out.left = Math.round((colWidth + margin[0]) * x + containerPadding[0]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Translate x and y coordinates from pixels to grid units.
|
|
92
|
+
* @param {PositionParams} positionParams Parameters of grid needed for coordinates calculations.
|
|
93
|
+
* @param {Number} top Top position (relative to parent) in pixels.
|
|
94
|
+
* @param {Number} left Left position (relative to parent) in pixels.
|
|
95
|
+
* @param {Number} w W coordinate in grid units.
|
|
96
|
+
* @param {Number} h H coordinate in grid units.
|
|
97
|
+
* @return {Object} x and y in grid units.
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
function calcXY(positionParams
|
|
102
|
+
/*: PositionParams*/
|
|
103
|
+
, top
|
|
104
|
+
/*: number*/
|
|
105
|
+
, left
|
|
106
|
+
/*: number*/
|
|
107
|
+
, w
|
|
108
|
+
/*: number*/
|
|
109
|
+
, h
|
|
110
|
+
/*: number*/
|
|
111
|
+
)
|
|
112
|
+
/*: { x: number, y: number }*/
|
|
113
|
+
{
|
|
114
|
+
var margin = positionParams.margin,
|
|
115
|
+
cols = positionParams.cols,
|
|
116
|
+
rowHeight = positionParams.rowHeight,
|
|
117
|
+
maxRows = positionParams.maxRows;
|
|
118
|
+
var colWidth = calcGridColWidth(positionParams); // left = colWidth * x + margin * (x + 1)
|
|
119
|
+
// l = cx + m(x+1)
|
|
120
|
+
// l = cx + mx + m
|
|
121
|
+
// l - m = cx + mx
|
|
122
|
+
// l - m = x(c + m)
|
|
123
|
+
// (l - m) / (c + m) = x
|
|
124
|
+
// x = (left - margin) / (coldWidth + margin)
|
|
125
|
+
|
|
126
|
+
var x = Math.round((left - margin[0]) / (colWidth + margin[0]));
|
|
127
|
+
var y = Math.round((top - margin[1]) / (rowHeight + margin[1])); // Capping
|
|
128
|
+
|
|
129
|
+
x = Math.max(Math.min(x, cols - w), 0);
|
|
130
|
+
y = Math.max(Math.min(y, maxRows - h), 0);
|
|
131
|
+
return {
|
|
132
|
+
x: x,
|
|
133
|
+
y: y
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Given a height and width in pixel values, calculate grid units.
|
|
138
|
+
* @param {PositionParams} positionParams Parameters of grid needed for coordinates calcluations.
|
|
139
|
+
* @param {Number} height Height in pixels.
|
|
140
|
+
* @param {Number} width Width in pixels.
|
|
141
|
+
* @param {Number} x X coordinate in grid units.
|
|
142
|
+
* @param {Number} y Y coordinate in grid units.
|
|
143
|
+
* @return {Object} w, h as grid units.
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
function calcWH(positionParams
|
|
148
|
+
/*: PositionParams*/
|
|
149
|
+
, width
|
|
150
|
+
/*: number*/
|
|
151
|
+
, height
|
|
152
|
+
/*: number*/
|
|
153
|
+
, x
|
|
154
|
+
/*: number*/
|
|
155
|
+
, y
|
|
156
|
+
/*: number*/
|
|
157
|
+
)
|
|
158
|
+
/*: { w: number, h: number }*/
|
|
159
|
+
{
|
|
160
|
+
var margin = positionParams.margin,
|
|
161
|
+
maxRows = positionParams.maxRows,
|
|
162
|
+
cols = positionParams.cols,
|
|
163
|
+
rowHeight = positionParams.rowHeight;
|
|
164
|
+
var colWidth = calcGridColWidth(positionParams); // width = colWidth * w - (margin * (w - 1))
|
|
165
|
+
// ...
|
|
166
|
+
// w = (width + margin) / (colWidth + margin)
|
|
167
|
+
|
|
168
|
+
var w = Math.round((width + margin[0]) / (colWidth + margin[0]));
|
|
169
|
+
var h = Math.round((height + margin[1]) / (rowHeight + margin[1])); // Capping
|
|
170
|
+
|
|
171
|
+
w = Math.max(Math.min(w, cols - x), 0);
|
|
172
|
+
h = Math.max(Math.min(h, maxRows - y), 0);
|
|
173
|
+
return {
|
|
174
|
+
w: w,
|
|
175
|
+
h: h
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = WidthProvider;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -13,7 +13,11 @@ var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
16
|
-
function
|
|
16
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
|
19
|
+
|
|
20
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
17
21
|
|
|
18
22
|
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); }
|
|
19
23
|
|
|
@@ -41,16 +45,22 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
41
45
|
|
|
42
46
|
/*
|
|
43
47
|
* A simple HOC that provides facility for listening to container resizes.
|
|
48
|
+
*
|
|
49
|
+
* The Flow type is pretty janky here. I can't just spread `WPProps` into this returned object - I wish I could - but it triggers
|
|
50
|
+
* a flow bug of some sort that causes it to stop typechecking.
|
|
44
51
|
*/
|
|
45
52
|
function WidthProvider
|
|
46
|
-
/*:: <
|
|
47
|
-
Props,
|
|
48
|
-
ComposedProps: { ...Props, ...WPProps }
|
|
49
|
-
>*/
|
|
53
|
+
/*:: <Config>*/
|
|
50
54
|
(ComposedComponent
|
|
51
|
-
/*:
|
|
55
|
+
/*: React.AbstractComponent<Config>*/
|
|
52
56
|
)
|
|
53
|
-
/*:
|
|
57
|
+
/*: React.AbstractComponent<{|
|
|
58
|
+
...Config,
|
|
59
|
+
measureBeforeMount?: boolean,
|
|
60
|
+
className?: string,
|
|
61
|
+
style?: Object,
|
|
62
|
+
width?: number
|
|
63
|
+
|}>*/
|
|
54
64
|
{
|
|
55
65
|
var _class, _temp;
|
|
56
66
|
|
|
@@ -116,18 +126,18 @@ function WidthProvider
|
|
|
116
126
|
rest = _objectWithoutProperties(_this$props, ["measureBeforeMount"]);
|
|
117
127
|
|
|
118
128
|
if (measureBeforeMount && !this.mounted) {
|
|
119
|
-
return
|
|
129
|
+
return React.createElement("div", {
|
|
120
130
|
className: this.props.className,
|
|
121
131
|
style: this.props.style
|
|
122
132
|
});
|
|
123
133
|
}
|
|
124
134
|
|
|
125
|
-
return
|
|
135
|
+
return React.createElement(ComposedComponent, _extends({}, rest, this.state));
|
|
126
136
|
}
|
|
127
137
|
}]);
|
|
128
138
|
|
|
129
139
|
return WidthProvider;
|
|
130
|
-
}(
|
|
140
|
+
}(React.Component), _defineProperty(_class, "defaultProps", {
|
|
131
141
|
measureBeforeMount: false
|
|
132
142
|
}), _defineProperty(_class, "propTypes", {
|
|
133
143
|
// If true, will not render children until mounted. Useful for getting the exact width before
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// this file was prevaled
|
|
2
|
+
module.exports = function fastRGLPropsEqual(a, b, isEqualImpl) {
|
|
3
|
+
if (a === b) return true;
|
|
4
|
+
return a.className === b.className && isEqualImpl(a.style, b.style) && a.width === b.width && a.autoSize === b.autoSize && a.cols === b.cols && a.draggableCancel === b.draggableCancel && a.draggableHandle === b.draggableHandle && isEqualImpl(a.verticalCompact, b.verticalCompact) && isEqualImpl(a.compactType, b.compactType) && isEqualImpl(a.layout, b.layout) && isEqualImpl(a.margin, b.margin) && isEqualImpl(a.containerPadding, b.containerPadding) && a.rowHeight === b.rowHeight && a.maxRows === b.maxRows && a.isDraggable === b.isDraggable && a.isResizable === b.isResizable && a.preventCollision === b.preventCollision && a.useCSSTransforms === b.useCSSTransforms && a.transformScale === b.transformScale && a.isDroppable === b.isDroppable && a.onLayoutChange === b.onLayoutChange && a.onDragStart === b.onDragStart && a.onDrag === b.onDrag && a.onDragStop === b.onDragStop && a.onResizeStart === b.onResizeStart && a.onResize === b.onResize && a.onResizeStop === b.onResizeStop && a.onDrop === b.onDrop && isEqualImpl(a.droppingItem, b.droppingItem);
|
|
5
|
+
};
|
package/build/responsiveUtils.js
CHANGED
|
@@ -18,7 +18,7 @@ var _utils = require("./utils");
|
|
|
18
18
|
* @return {String} Highest breakpoint that is less than width.
|
|
19
19
|
*/
|
|
20
20
|
function getBreakpointFromWidth(breakpoints
|
|
21
|
-
/*: Breakpoints
|
|
21
|
+
/*: Breakpoints<Breakpoint>*/
|
|
22
22
|
, width
|
|
23
23
|
/*: number*/
|
|
24
24
|
)
|
|
@@ -45,7 +45,7 @@ function getBreakpointFromWidth(breakpoints
|
|
|
45
45
|
function getColsFromBreakpoint(breakpoint
|
|
46
46
|
/*: Breakpoint*/
|
|
47
47
|
, cols
|
|
48
|
-
/*: Breakpoints
|
|
48
|
+
/*: Breakpoints<Breakpoint>*/
|
|
49
49
|
)
|
|
50
50
|
/*: number*/
|
|
51
51
|
{
|
|
@@ -72,9 +72,9 @@ function getColsFromBreakpoint(breakpoint
|
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
function findOrGenerateResponsiveLayout(layouts
|
|
75
|
-
/*: ResponsiveLayout
|
|
75
|
+
/*: ResponsiveLayout<Breakpoint>*/
|
|
76
76
|
, breakpoints
|
|
77
|
-
/*: Breakpoints
|
|
77
|
+
/*: Breakpoints<Breakpoint>*/
|
|
78
78
|
, breakpoint
|
|
79
79
|
/*: Breakpoint*/
|
|
80
80
|
, lastBreakpoint
|
|
@@ -118,7 +118,7 @@ function findOrGenerateResponsiveLayout(layouts
|
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
function sortBreakpoints(breakpoints
|
|
121
|
-
/*: Breakpoints
|
|
121
|
+
/*: Breakpoints<Breakpoint>*/
|
|
122
122
|
)
|
|
123
123
|
/*: Array<Breakpoint>*/
|
|
124
124
|
{
|