react-grid-layout 0.16.4 → 0.17.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/.babelrc.js +25 -0
- package/.browserslistrc +3 -0
- package/.flowconfig +1 -1
- package/.prettierignore +2 -0
- package/.prettierrc +18 -0
- package/.travis.yml +2 -2
- package/CHANGELOG.md +69 -0
- package/README.md +99 -52
- package/build/GridItem.js +596 -414
- package/build/ReactGridLayout.js +648 -423
- package/build/ResponsiveReactGridLayout.js +270 -151
- package/build/components/WidthProvider.js +96 -53
- package/build/responsiveUtils.js +56 -12
- package/build/utils.js +376 -183
- package/css/styles.css +4 -0
- package/index.js +5 -5
- package/index.js.flow +5 -7
- package/interfaces/classnames.js +1 -0
- package/{build/GridItem.js.flow → lib/GridItem.jsx} +230 -96
- package/{build/ReactGridLayout.js.flow → lib/ReactGridLayout.jsx} +220 -35
- package/{build/ResponsiveReactGridLayout.js.flow → lib/ResponsiveReactGridLayout.jsx} +73 -20
- package/{build/components/WidthProvider.js.flow → lib/components/WidthProvider.jsx} +1 -1
- package/{build/responsiveUtils.js.flow → lib/responsiveUtils.js} +0 -0
- package/{build/utils.js.flow → lib/utils.js} +49 -37
- package/package.json +37 -43
- package/.babelrc +0 -12
- package/.jshintignore +0 -1
- package/.jshintrc +0 -10
|
@@ -1,227 +1,346 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
exports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
4
7
|
|
|
5
|
-
var
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
6
9
|
|
|
7
|
-
var
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
11
|
|
|
9
|
-
var
|
|
12
|
+
var _lodash = _interopRequireDefault(require("lodash.isequal"));
|
|
10
13
|
|
|
11
|
-
var
|
|
14
|
+
var _utils = require("./utils");
|
|
12
15
|
|
|
13
|
-
var
|
|
16
|
+
var _responsiveUtils = require("./responsiveUtils");
|
|
14
17
|
|
|
15
|
-
var
|
|
18
|
+
var _ReactGridLayout = _interopRequireDefault(require("./ReactGridLayout"));
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
function _typeof(obj) { 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); }
|
|
20
23
|
|
|
21
|
-
var
|
|
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); }
|
|
22
25
|
|
|
23
|
-
var
|
|
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; }
|
|
24
27
|
|
|
25
|
-
var
|
|
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; }
|
|
26
29
|
|
|
27
|
-
function
|
|
30
|
+
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; }
|
|
28
31
|
|
|
29
|
-
function
|
|
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; }
|
|
30
33
|
|
|
31
34
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
32
35
|
|
|
33
|
-
function
|
|
36
|
+
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); } }
|
|
37
|
+
|
|
38
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
39
|
+
|
|
40
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
41
|
+
|
|
42
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
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 _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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
47
|
+
|
|
48
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
34
49
|
|
|
35
|
-
function
|
|
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; }
|
|
36
51
|
|
|
37
52
|
var type = function type(obj) {
|
|
38
53
|
return Object.prototype.toString.call(obj);
|
|
39
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Get a value of margin or containerPadding.
|
|
57
|
+
*
|
|
58
|
+
* @param {Array | Object} param Margin | containerPadding, e.g. [10, 10] | {lg: [10, 10], ...}.
|
|
59
|
+
* @param {String} breakpoint Breakpoint: lg, md, sm, xs and etc.
|
|
60
|
+
* @return {Array}
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
function getIndentationValue(param
|
|
65
|
+
/*: { [key: string]: [number, number] } | [number, number]*/
|
|
66
|
+
, breakpoint
|
|
67
|
+
/*: string*/
|
|
68
|
+
) {
|
|
69
|
+
return Array.isArray(param) ? param : param[breakpoint];
|
|
70
|
+
}
|
|
71
|
+
/*:: type State = {
|
|
72
|
+
layout: Layout,
|
|
73
|
+
breakpoint: string,
|
|
74
|
+
cols: number,
|
|
75
|
+
layouts?: { [key: string]: Layout }
|
|
76
|
+
};*/
|
|
77
|
+
|
|
78
|
+
/*:: type Props<Breakpoint: string = string> = {
|
|
79
|
+
...$Exact<RGLProps>,
|
|
80
|
+
|
|
81
|
+
// Responsive config
|
|
82
|
+
breakpoint: Breakpoint,
|
|
83
|
+
breakpoints: { [key: Breakpoint]: number },
|
|
84
|
+
cols: { [key: Breakpoint]: number },
|
|
85
|
+
layouts: { [key: Breakpoint]: Layout },
|
|
86
|
+
width: number,
|
|
87
|
+
margin: { [key: Breakpoint]: [number, number] } | [number, number],
|
|
88
|
+
containerPadding: { [key: Breakpoint]: [number, number] } | [number, number],
|
|
40
89
|
|
|
41
|
-
|
|
90
|
+
// Callbacks
|
|
91
|
+
onBreakpointChange: (Breakpoint, cols: number) => void,
|
|
92
|
+
onLayoutChange: (Layout, { [key: Breakpoint]: Layout }) => void,
|
|
93
|
+
onWidthChange: (
|
|
94
|
+
containerWidth: number,
|
|
95
|
+
margin: [number, number],
|
|
96
|
+
cols: number,
|
|
97
|
+
containerPadding: [number, number] | null
|
|
98
|
+
) => void
|
|
99
|
+
};*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
var ResponsiveReactGridLayout =
|
|
103
|
+
/*#__PURE__*/
|
|
104
|
+
function (_React$Component) {
|
|
42
105
|
_inherits(ResponsiveReactGridLayout, _React$Component);
|
|
43
106
|
|
|
44
107
|
function ResponsiveReactGridLayout() {
|
|
45
|
-
var
|
|
108
|
+
var _getPrototypeOf2;
|
|
109
|
+
|
|
110
|
+
var _this;
|
|
46
111
|
|
|
47
112
|
_classCallCheck(this, ResponsiveReactGridLayout);
|
|
48
113
|
|
|
49
|
-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
114
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
50
115
|
args[_key] = arguments[_key];
|
|
51
116
|
}
|
|
52
117
|
|
|
53
|
-
|
|
54
|
-
var _extends2;
|
|
55
|
-
|
|
56
|
-
_this.props.onLayoutChange(layout, _extends({}, _this.props.layouts, (_extends2 = {}, _extends2[_this.state.breakpoint] = layout, _extends2)));
|
|
57
|
-
}, _temp), _possibleConstructorReturn(_this, _ret);
|
|
58
|
-
}
|
|
59
|
-
// This should only include propTypes needed in this code; RGL itself
|
|
60
|
-
// will do validation of the rest props passed to it.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
ResponsiveReactGridLayout.prototype.generateInitialState = function generateInitialState() {
|
|
64
|
-
var _props = this.props,
|
|
65
|
-
width = _props.width,
|
|
66
|
-
breakpoints = _props.breakpoints,
|
|
67
|
-
layouts = _props.layouts,
|
|
68
|
-
cols = _props.cols;
|
|
69
|
-
|
|
70
|
-
var breakpoint = (0, _responsiveUtils.getBreakpointFromWidth)(breakpoints, width);
|
|
71
|
-
var colNo = (0, _responsiveUtils.getColsFromBreakpoint)(breakpoint, cols);
|
|
72
|
-
// verticalCompact compatibility, now deprecated
|
|
73
|
-
var compactType = this.props.verticalCompact === false ? null : this.props.compactType;
|
|
74
|
-
// Get the initial layout. This can tricky; we try to generate one however possible if one doesn't exist
|
|
75
|
-
// for this layout.
|
|
76
|
-
var initialLayout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(layouts, breakpoints, breakpoint, breakpoint, colNo, compactType);
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
layout: initialLayout,
|
|
80
|
-
breakpoint: breakpoint,
|
|
81
|
-
cols: colNo
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
ResponsiveReactGridLayout.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
|
86
|
-
// Allow parent to set width or breakpoint directly.
|
|
87
|
-
if (nextProps.width != this.props.width || nextProps.breakpoint !== this.props.breakpoint || !(0, _lodash2.default)(nextProps.breakpoints, this.props.breakpoints) || !(0, _lodash2.default)(nextProps.cols, this.props.cols)) {
|
|
88
|
-
this.onWidthChange(nextProps);
|
|
89
|
-
} else if (!(0, _lodash2.default)(nextProps.layouts, this.props.layouts)) {
|
|
90
|
-
// Allow parent to set layouts directly.
|
|
91
|
-
var _state = this.state,
|
|
92
|
-
_breakpoint = _state.breakpoint,
|
|
93
|
-
_cols = _state.cols;
|
|
94
|
-
|
|
95
|
-
// Since we're setting an entirely new layout object, we must generate a new responsive layout
|
|
96
|
-
// if one does not exist.
|
|
97
|
-
|
|
98
|
-
var newLayout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(nextProps.layouts, nextProps.breakpoints, _breakpoint, _breakpoint, _cols, nextProps.compactType);
|
|
99
|
-
this.setState({ layout: newLayout });
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// wrap layouts so we do not need to pass layouts to child
|
|
118
|
+
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(ResponsiveReactGridLayout)).call.apply(_getPrototypeOf2, [this].concat(args)));
|
|
104
119
|
|
|
120
|
+
_defineProperty(_assertThisInitialized(_this), "state", _this.generateInitialState());
|
|
105
121
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
var breakpoints = nextProps.breakpoints,
|
|
112
|
-
cols = nextProps.cols,
|
|
113
|
-
layouts = nextProps.layouts,
|
|
114
|
-
compactType = nextProps.compactType;
|
|
115
|
-
|
|
116
|
-
var newBreakpoint = nextProps.breakpoint || (0, _responsiveUtils.getBreakpointFromWidth)(nextProps.breakpoints, nextProps.width);
|
|
117
|
-
|
|
118
|
-
var lastBreakpoint = this.state.breakpoint;
|
|
119
|
-
|
|
120
|
-
// Breakpoint change
|
|
121
|
-
if (lastBreakpoint !== newBreakpoint || this.props.breakpoints !== breakpoints || this.props.cols !== cols) {
|
|
122
|
-
// Preserve the current layout if the current breakpoint is not present in the next layouts.
|
|
123
|
-
if (!(lastBreakpoint in layouts)) layouts[lastBreakpoint] = (0, _utils.cloneLayout)(this.state.layout);
|
|
122
|
+
_defineProperty(_assertThisInitialized(_this), "onLayoutChange", function (layout
|
|
123
|
+
/*: Layout*/
|
|
124
|
+
) {
|
|
125
|
+
_this.props.onLayoutChange(layout, _objectSpread({}, _this.props.layouts, _defineProperty({}, _this.state.breakpoint, layout)));
|
|
126
|
+
});
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var _layout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(layouts, breakpoints, newBreakpoint, lastBreakpoint, newCols, compactType);
|
|
128
|
+
return _this;
|
|
129
|
+
}
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
_createClass(ResponsiveReactGridLayout, [{
|
|
132
|
+
key: "generateInitialState",
|
|
133
|
+
value: function generateInitialState()
|
|
134
|
+
/*: State*/
|
|
135
|
+
{
|
|
136
|
+
var _this$props = this.props,
|
|
137
|
+
width = _this$props.width,
|
|
138
|
+
breakpoints = _this$props.breakpoints,
|
|
139
|
+
layouts = _this$props.layouts,
|
|
140
|
+
cols = _this$props.cols;
|
|
141
|
+
var breakpoint = (0, _responsiveUtils.getBreakpointFromWidth)(breakpoints, width);
|
|
142
|
+
var colNo = (0, _responsiveUtils.getColsFromBreakpoint)(breakpoint, cols); // verticalCompact compatibility, now deprecated
|
|
143
|
+
|
|
144
|
+
var compactType = this.props.verticalCompact === false ? null : this.props.compactType; // Get the initial layout. This can tricky; we try to generate one however possible if one doesn't exist
|
|
145
|
+
// for this layout.
|
|
146
|
+
|
|
147
|
+
var initialLayout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(layouts, breakpoints, breakpoint, breakpoint, colNo, compactType);
|
|
148
|
+
return {
|
|
149
|
+
layout: initialLayout,
|
|
150
|
+
breakpoint: breakpoint,
|
|
151
|
+
cols: colNo
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}, {
|
|
155
|
+
key: "componentDidUpdate",
|
|
156
|
+
value: function componentDidUpdate(prevProps
|
|
157
|
+
/*: Props<*>*/
|
|
158
|
+
) {
|
|
159
|
+
// Allow parent to set width or breakpoint directly.
|
|
160
|
+
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(this.props);
|
|
162
|
+
}
|
|
163
|
+
} // wrap layouts so we do not need to pass layouts to child
|
|
164
|
+
|
|
165
|
+
}, {
|
|
166
|
+
key: "onWidthChange",
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* When the width changes work through breakpoints and reset state with the new width & breakpoint.
|
|
170
|
+
* Width changes are necessary to figure out the widget widths.
|
|
171
|
+
*/
|
|
172
|
+
value: function onWidthChange(nextProps
|
|
173
|
+
/*: Props<*>*/
|
|
174
|
+
) {
|
|
175
|
+
var breakpoints = nextProps.breakpoints,
|
|
176
|
+
cols = nextProps.cols,
|
|
177
|
+
layouts = nextProps.layouts,
|
|
178
|
+
compactType = nextProps.compactType;
|
|
179
|
+
var newBreakpoint = nextProps.breakpoint || (0, _responsiveUtils.getBreakpointFromWidth)(nextProps.breakpoints, nextProps.width);
|
|
180
|
+
var lastBreakpoint = this.state.breakpoint;
|
|
181
|
+
var newCols
|
|
182
|
+
/*: number*/
|
|
183
|
+
= (0, _responsiveUtils.getColsFromBreakpoint)(newBreakpoint, cols); // Breakpoint change
|
|
184
|
+
|
|
185
|
+
if (lastBreakpoint !== newBreakpoint || this.props.breakpoints !== breakpoints || this.props.cols !== cols) {
|
|
186
|
+
// Preserve the current layout if the current breakpoint is not present in the next layouts.
|
|
187
|
+
if (!(lastBreakpoint in layouts)) layouts[lastBreakpoint] = (0, _utils.cloneLayout)(this.state.layout); // Find or generate a new layout.
|
|
188
|
+
|
|
189
|
+
var layout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(layouts, breakpoints, newBreakpoint, lastBreakpoint, newCols, compactType); // This adds missing items.
|
|
190
|
+
|
|
191
|
+
layout = (0, _utils.synchronizeLayoutWithChildren)(layout, nextProps.children, newCols, compactType); // Store the new layout.
|
|
192
|
+
|
|
193
|
+
layouts[newBreakpoint] = layout; // callbacks
|
|
194
|
+
|
|
195
|
+
this.props.onLayoutChange(layout, layouts);
|
|
196
|
+
this.props.onBreakpointChange(newBreakpoint, newCols);
|
|
197
|
+
this.setState({
|
|
198
|
+
breakpoint: newBreakpoint,
|
|
199
|
+
layout: layout,
|
|
200
|
+
cols: newCols
|
|
201
|
+
});
|
|
202
|
+
}
|
|
131
203
|
|
|
132
|
-
|
|
133
|
-
|
|
204
|
+
var margin = getIndentationValue(nextProps.margin, newBreakpoint);
|
|
205
|
+
var containerPadding = getIndentationValue(nextProps.containerPadding, newBreakpoint); //call onWidthChange on every change of width, not only on breakpoint changes
|
|
134
206
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
207
|
+
this.props.onWidthChange(nextProps.width, margin, newCols, containerPadding);
|
|
208
|
+
}
|
|
209
|
+
}, {
|
|
210
|
+
key: "render",
|
|
211
|
+
value: function render() {
|
|
212
|
+
/* eslint-disable no-unused-vars */
|
|
213
|
+
var _this$props2 = this.props,
|
|
214
|
+
breakpoint = _this$props2.breakpoint,
|
|
215
|
+
breakpoints = _this$props2.breakpoints,
|
|
216
|
+
cols = _this$props2.cols,
|
|
217
|
+
layouts = _this$props2.layouts,
|
|
218
|
+
margin = _this$props2.margin,
|
|
219
|
+
containerPadding = _this$props2.containerPadding,
|
|
220
|
+
onBreakpointChange = _this$props2.onBreakpointChange,
|
|
221
|
+
onLayoutChange = _this$props2.onLayoutChange,
|
|
222
|
+
onWidthChange = _this$props2.onWidthChange,
|
|
223
|
+
other = _objectWithoutProperties(_this$props2, ["breakpoint", "breakpoints", "cols", "layouts", "margin", "containerPadding", "onBreakpointChange", "onLayoutChange", "onWidthChange"]);
|
|
224
|
+
/* eslint-enable no-unused-vars */
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
return _react.default.createElement(_ReactGridLayout.default, _extends({}, other, {
|
|
228
|
+
margin: getIndentationValue(margin, this.state.breakpoint),
|
|
229
|
+
containerPadding: getIndentationValue(containerPadding, this.state.breakpoint),
|
|
230
|
+
onLayoutChange: this.onLayoutChange,
|
|
231
|
+
layout: this.state.layout,
|
|
232
|
+
cols: this.state.cols
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
}], [{
|
|
236
|
+
key: "getDerivedStateFromProps",
|
|
237
|
+
value: function getDerivedStateFromProps(nextProps
|
|
238
|
+
/*: Props<*>*/
|
|
239
|
+
, prevState
|
|
240
|
+
/*: State*/
|
|
241
|
+
) {
|
|
242
|
+
if (!(0, _lodash.default)(nextProps.layouts, prevState.layouts)) {
|
|
243
|
+
// Allow parent to set layouts directly.
|
|
244
|
+
var breakpoint = prevState.breakpoint,
|
|
245
|
+
_cols = prevState.cols; // Since we're setting an entirely new layout object, we must generate a new responsive layout
|
|
246
|
+
// if one does not exist.
|
|
247
|
+
|
|
248
|
+
var newLayout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(nextProps.layouts, nextProps.breakpoints, breakpoint, breakpoint, _cols, nextProps.compactType);
|
|
249
|
+
return {
|
|
250
|
+
layout: newLayout,
|
|
251
|
+
layouts: nextProps.layouts
|
|
252
|
+
};
|
|
253
|
+
}
|
|
139
254
|
|
|
140
|
-
|
|
141
|
-
breakpoint: newBreakpoint,
|
|
142
|
-
layout: _layout,
|
|
143
|
-
cols: newCols
|
|
144
|
-
});
|
|
255
|
+
return null;
|
|
145
256
|
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
ResponsiveReactGridLayout.prototype.render = function render() {
|
|
149
|
-
/* eslint-disable no-unused-vars */
|
|
150
|
-
var _props2 = this.props,
|
|
151
|
-
breakpoint = _props2.breakpoint,
|
|
152
|
-
breakpoints = _props2.breakpoints,
|
|
153
|
-
cols = _props2.cols,
|
|
154
|
-
layouts = _props2.layouts,
|
|
155
|
-
onBreakpointChange = _props2.onBreakpointChange,
|
|
156
|
-
onLayoutChange = _props2.onLayoutChange,
|
|
157
|
-
onWidthChange = _props2.onWidthChange,
|
|
158
|
-
other = _objectWithoutProperties(_props2, ["breakpoint", "breakpoints", "cols", "layouts", "onBreakpointChange", "onLayoutChange", "onWidthChange"]);
|
|
159
|
-
/* eslint-enable no-unused-vars */
|
|
160
|
-
|
|
161
|
-
return _react2.default.createElement(_ReactGridLayout2.default, _extends({}, other, {
|
|
162
|
-
onLayoutChange: this.onLayoutChange,
|
|
163
|
-
layout: this.state.layout,
|
|
164
|
-
cols: this.state.cols
|
|
165
|
-
}));
|
|
166
|
-
};
|
|
257
|
+
}]);
|
|
167
258
|
|
|
168
259
|
return ResponsiveReactGridLayout;
|
|
169
|
-
}(
|
|
260
|
+
}(_react.default.Component);
|
|
261
|
+
|
|
262
|
+
exports.default = ResponsiveReactGridLayout;
|
|
170
263
|
|
|
171
|
-
ResponsiveReactGridLayout
|
|
264
|
+
_defineProperty(ResponsiveReactGridLayout, "propTypes", {
|
|
172
265
|
//
|
|
173
266
|
// Basic props
|
|
174
267
|
//
|
|
175
|
-
|
|
176
268
|
// Optional, but if you are managing width yourself you may want to set the breakpoint
|
|
177
269
|
// yourself as well.
|
|
178
|
-
breakpoint:
|
|
179
|
-
|
|
270
|
+
breakpoint: _propTypes.default.string,
|
|
180
271
|
// {name: pxVal}, e.g. {lg: 1200, md: 996, sm: 768, xs: 480}
|
|
181
|
-
breakpoints:
|
|
182
|
-
|
|
272
|
+
breakpoints: _propTypes.default.object,
|
|
183
273
|
// # of cols. This is a breakpoint -> cols map
|
|
184
|
-
cols:
|
|
185
|
-
|
|
274
|
+
cols: _propTypes.default.object,
|
|
275
|
+
// # of margin. This is a breakpoint -> margin map
|
|
276
|
+
// e.g. { lg: [5, 5], md: [10, 10], sm: [15, 15] }
|
|
277
|
+
// Margin between items [x, y] in px
|
|
278
|
+
// e.g. [10, 10]
|
|
279
|
+
margin: _propTypes.default.oneOfType([_propTypes.default.array, _propTypes.default.object]),
|
|
280
|
+
// # of containerPadding. This is a breakpoint -> containerPadding map
|
|
281
|
+
// e.g. { lg: [5, 5], md: [10, 10], sm: [15, 15] }
|
|
282
|
+
// Padding inside the container [x, y] in px
|
|
283
|
+
// e.g. [10, 10]
|
|
284
|
+
containerPadding: _propTypes.default.oneOfType([_propTypes.default.array, _propTypes.default.object]),
|
|
186
285
|
// layouts is an object mapping breakpoints to layouts.
|
|
187
286
|
// e.g. {lg: Layout, md: Layout, ...}
|
|
188
|
-
layouts: function layouts(props
|
|
287
|
+
layouts: function layouts(props
|
|
288
|
+
/*: Props<>*/
|
|
289
|
+
, propName
|
|
290
|
+
/*: string*/
|
|
291
|
+
) {
|
|
189
292
|
if (type(props[propName]) !== "[object Object]") {
|
|
190
293
|
throw new Error("Layout property must be an object. Received: " + type(props[propName]));
|
|
191
294
|
}
|
|
295
|
+
|
|
192
296
|
Object.keys(props[propName]).forEach(function (key) {
|
|
193
297
|
if (!(key in props.breakpoints)) {
|
|
194
298
|
throw new Error("Each key in layouts must align with a key in breakpoints.");
|
|
195
299
|
}
|
|
300
|
+
|
|
196
301
|
(0, _utils.validateLayout)(props.layouts[key], "layouts." + key);
|
|
197
302
|
});
|
|
198
303
|
},
|
|
199
|
-
|
|
200
|
-
|
|
201
304
|
// The width of this component.
|
|
202
305
|
// Required in this propTypes stanza because generateInitialState() will fail without it.
|
|
203
|
-
width:
|
|
204
|
-
|
|
306
|
+
width: _propTypes.default.number.isRequired,
|
|
205
307
|
//
|
|
206
308
|
// Callbacks
|
|
207
309
|
//
|
|
208
|
-
|
|
209
310
|
// Calls back with breakpoint and new # cols
|
|
210
|
-
onBreakpointChange:
|
|
211
|
-
|
|
311
|
+
onBreakpointChange: _propTypes.default.func,
|
|
212
312
|
// Callback so you can save the layout.
|
|
213
313
|
// Calls back with (currentLayout, allLayouts). allLayouts are keyed by breakpoint.
|
|
214
|
-
onLayoutChange:
|
|
215
|
-
|
|
314
|
+
onLayoutChange: _propTypes.default.func,
|
|
216
315
|
// Calls back with (containerWidth, margin, cols, containerPadding)
|
|
217
|
-
onWidthChange:
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
316
|
+
onWidthChange: _propTypes.default.func
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
_defineProperty(ResponsiveReactGridLayout, "defaultProps", {
|
|
320
|
+
breakpoints: {
|
|
321
|
+
lg: 1200,
|
|
322
|
+
md: 996,
|
|
323
|
+
sm: 768,
|
|
324
|
+
xs: 480,
|
|
325
|
+
xxs: 0
|
|
326
|
+
},
|
|
327
|
+
cols: {
|
|
328
|
+
lg: 12,
|
|
329
|
+
md: 10,
|
|
330
|
+
sm: 6,
|
|
331
|
+
xs: 4,
|
|
332
|
+
xxs: 2
|
|
333
|
+
},
|
|
222
334
|
layouts: {},
|
|
335
|
+
margin: [10, 10],
|
|
336
|
+
containerPadding: {
|
|
337
|
+
lg: null,
|
|
338
|
+
md: null,
|
|
339
|
+
sm: null,
|
|
340
|
+
xs: null,
|
|
341
|
+
xxs: null
|
|
342
|
+
},
|
|
223
343
|
onBreakpointChange: _utils.noop,
|
|
224
344
|
onLayoutChange: _utils.noop,
|
|
225
345
|
onWidthChange: _utils.noop
|
|
226
|
-
};
|
|
227
|
-
exports.default = ResponsiveReactGridLayout;
|
|
346
|
+
});
|