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
|
@@ -4,13 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.resizeHandleType = exports.resizeHandleAxesType = exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
10
|
+
/*:: import type {
|
|
11
|
+
Ref,
|
|
12
|
+
ChildrenArray as ReactChildrenArray,
|
|
13
|
+
Element as ReactElement
|
|
14
|
+
} from "react";*/
|
|
15
|
+
/*:: import type {
|
|
16
|
+
DragOverEvent,
|
|
17
|
+
EventCallback,
|
|
18
|
+
CompactType,
|
|
19
|
+
Layout,
|
|
20
|
+
LayoutItem,
|
|
21
|
+
ResizeHandleAxis
|
|
22
|
+
} from "./utils";*/
|
|
23
|
+
/*:: export type ReactRef<T: HTMLElement> = {|
|
|
24
|
+
+current: T | null
|
|
25
|
+
|};*/
|
|
26
|
+
// util
|
|
27
|
+
/*:: export type ResizeHandle =
|
|
28
|
+
| ReactElement<any>
|
|
29
|
+
| ((
|
|
30
|
+
resizeHandleAxis: ResizeHandleAxis,
|
|
31
|
+
ref: ReactRef<HTMLElement>
|
|
32
|
+
) => ReactElement<any>);*/
|
|
14
33
|
// Defines which resize handles should be rendered (default: 'se')
|
|
15
34
|
// Allows for any combination of:
|
|
16
35
|
// 's' - South handle (bottom-center)
|
|
@@ -21,16 +40,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
40
|
// 'nw' - Northwest handle (top-left)
|
|
22
41
|
// 'se' - Southeast handle (bottom-right)
|
|
23
42
|
// 'ne' - Northeast handle (top-right)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
= _propTypes.default.arrayOf(_propTypes.default.oneOf(["s", "w", "e", "n", "sw", "nw", "se", "ne"])); // Custom component for resize handles
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
const resizeHandleAxesType /*: ReactPropsChainableTypeChecker*/ = _propTypes.default.arrayOf(_propTypes.default.oneOf(["s", "w", "e", "n", "sw", "nw", "se", "ne"]));
|
|
44
|
+
// Custom component for resize handles
|
|
29
45
|
exports.resizeHandleAxesType = resizeHandleAxesType;
|
|
30
|
-
|
|
31
|
-
var resizeHandleType
|
|
32
|
-
/*: ReactPropsChainableTypeChecker*/
|
|
33
|
-
= _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]);
|
|
46
|
+
const resizeHandleType /*: ReactPropsChainableTypeChecker*/ = _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]);
|
|
34
47
|
/*:: export type Props = {|
|
|
35
48
|
className: string,
|
|
36
49
|
style: Object,
|
|
@@ -71,7 +84,6 @@ var resizeHandleType
|
|
|
71
84
|
children: ReactChildrenArray<ReactElement<any>>,
|
|
72
85
|
innerRef?: Ref<"div">
|
|
73
86
|
|};*/
|
|
74
|
-
|
|
75
87
|
/*:: export type DefaultProps = $Diff<
|
|
76
88
|
Props,
|
|
77
89
|
{
|
|
@@ -79,8 +91,6 @@ var resizeHandleType
|
|
|
79
91
|
width: number
|
|
80
92
|
}
|
|
81
93
|
>;*/
|
|
82
|
-
|
|
83
|
-
|
|
84
94
|
exports.resizeHandleType = resizeHandleType;
|
|
85
95
|
var _default = {
|
|
86
96
|
//
|
|
@@ -101,40 +111,31 @@ var _default = {
|
|
|
101
111
|
// A selector for the draggable handler
|
|
102
112
|
draggableHandle: _propTypes.default.string,
|
|
103
113
|
// Deprecated
|
|
104
|
-
verticalCompact: function
|
|
105
|
-
/*: Props*/
|
|
106
|
-
) {
|
|
114
|
+
verticalCompact: function (props /*: Props*/) {
|
|
107
115
|
if (props.verticalCompact === false && process.env.NODE_ENV !== "production") {
|
|
108
|
-
console.warn(
|
|
116
|
+
console.warn(
|
|
117
|
+
// eslint-disable-line no-console
|
|
109
118
|
"`verticalCompact` on <ReactGridLayout> is deprecated and will be removed soon. " + 'Use `compactType`: "horizontal" | "vertical" | null.');
|
|
110
119
|
}
|
|
111
120
|
},
|
|
112
121
|
// Choose vertical or hotizontal compaction
|
|
113
|
-
compactType: (_propTypes.default.oneOf(["vertical", "horizontal"])
|
|
114
|
-
/*: ReactPropsChainableTypeChecker*/
|
|
115
|
-
),
|
|
122
|
+
compactType: (_propTypes.default.oneOf(["vertical", "horizontal"]) /*: ReactPropsChainableTypeChecker*/),
|
|
116
123
|
// layout is an array of object with the format:
|
|
117
124
|
// {x: Number, y: Number, w: Number, h: Number, i: String}
|
|
118
|
-
layout: function
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
var layout = props.layout; // I hope you're setting the data-grid property on the grid items
|
|
122
|
-
|
|
125
|
+
layout: function (props /*: Props*/) {
|
|
126
|
+
var layout = props.layout;
|
|
127
|
+
// I hope you're setting the data-grid property on the grid items
|
|
123
128
|
if (layout === undefined) return;
|
|
124
|
-
|
|
125
129
|
require("./utils").validateLayout(layout, "layout");
|
|
126
130
|
},
|
|
127
131
|
//
|
|
128
132
|
// Grid Dimensions
|
|
129
133
|
//
|
|
134
|
+
|
|
130
135
|
// Margin between items [x, y] in px
|
|
131
|
-
margin: (_propTypes.default.arrayOf(_propTypes.default.number)
|
|
132
|
-
/*: ReactPropsChainableTypeChecker*/
|
|
133
|
-
),
|
|
136
|
+
margin: (_propTypes.default.arrayOf(_propTypes.default.number) /*: ReactPropsChainableTypeChecker*/),
|
|
134
137
|
// Padding inside the container [x, y] in px
|
|
135
|
-
containerPadding: (_propTypes.default.arrayOf(_propTypes.default.number)
|
|
136
|
-
/*: ReactPropsChainableTypeChecker*/
|
|
137
|
-
),
|
|
138
|
+
containerPadding: (_propTypes.default.arrayOf(_propTypes.default.number) /*: ReactPropsChainableTypeChecker*/),
|
|
138
139
|
// Rows have a static height, but you can change this based on breakpoints if you like
|
|
139
140
|
rowHeight: _propTypes.default.number,
|
|
140
141
|
// Default Infinity, but you can specify a max here if you like.
|
|
@@ -165,6 +166,7 @@ var _default = {
|
|
|
165
166
|
//
|
|
166
167
|
// Callbacks
|
|
167
168
|
//
|
|
169
|
+
|
|
168
170
|
// Callback so you can save the layout. Calls after each drag & resize stops.
|
|
169
171
|
onLayoutChange: _propTypes.default.func,
|
|
170
172
|
// Calls when drag starts. Callback is of the signature (layout, oldItem, newItem, placeholder, e, ?node).
|
|
@@ -185,30 +187,23 @@ var _default = {
|
|
|
185
187
|
//
|
|
186
188
|
// Other validations
|
|
187
189
|
//
|
|
190
|
+
|
|
188
191
|
droppingItem: (_propTypes.default.shape({
|
|
189
192
|
i: _propTypes.default.string.isRequired,
|
|
190
193
|
w: _propTypes.default.number.isRequired,
|
|
191
194
|
h: _propTypes.default.number.isRequired
|
|
192
|
-
})
|
|
193
|
-
/*: ReactPropsChainableTypeChecker*/
|
|
194
|
-
),
|
|
195
|
+
}) /*: ReactPropsChainableTypeChecker*/),
|
|
195
196
|
// Children must not have duplicate keys.
|
|
196
|
-
children: function
|
|
197
|
-
|
|
198
|
-
, propName
|
|
199
|
-
/*: string*/
|
|
200
|
-
) {
|
|
201
|
-
var children = props[propName]; // Check children keys for duplicates. Throw if found.
|
|
202
|
-
|
|
203
|
-
var keys = {};
|
|
197
|
+
children: function (props /*: Props*/, propName /*: string*/) {
|
|
198
|
+
const children = props[propName];
|
|
204
199
|
|
|
200
|
+
// Check children keys for duplicates. Throw if found.
|
|
201
|
+
const keys = {};
|
|
205
202
|
_react.default.Children.forEach(children, function (child) {
|
|
206
203
|
if ((child === null || child === void 0 ? void 0 : child.key) == null) return;
|
|
207
|
-
|
|
208
204
|
if (keys[child.key]) {
|
|
209
205
|
throw new Error('Duplicate child key "' + child.key + '" found! This will cause problems in ReactGridLayout.');
|
|
210
206
|
}
|
|
211
|
-
|
|
212
207
|
keys[child.key] = true;
|
|
213
208
|
});
|
|
214
209
|
},
|
|
@@ -1,68 +1,25 @@
|
|
|
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 = void 0;
|
|
9
|
-
|
|
10
7
|
var React = _interopRequireWildcard(require("react"));
|
|
11
|
-
|
|
12
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
|
|
14
|
-
var _lodash = _interopRequireDefault(require("lodash.isequal"));
|
|
15
|
-
|
|
9
|
+
var _fastEquals = require("fast-equals");
|
|
16
10
|
var _utils = require("./utils");
|
|
17
|
-
|
|
18
11
|
var _responsiveUtils = require("./responsiveUtils");
|
|
19
|
-
|
|
20
12
|
var _ReactGridLayout = _interopRequireDefault(require("./ReactGridLayout"));
|
|
21
|
-
|
|
22
|
-
var _excluded = ["breakpoint", "breakpoints", "cols", "layouts", "margin", "containerPadding", "onBreakpointChange", "onLayoutChange", "onWidthChange"];
|
|
23
|
-
|
|
24
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
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; }
|
|
33
|
-
|
|
34
|
-
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; }
|
|
35
|
-
|
|
36
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
37
|
-
|
|
38
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
39
|
-
|
|
40
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
41
|
-
|
|
42
|
-
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); } }
|
|
43
|
-
|
|
44
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); 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); }
|
|
49
|
-
|
|
50
|
-
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); }; }
|
|
51
|
-
|
|
52
|
-
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); }
|
|
53
|
-
|
|
54
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
55
|
-
|
|
56
|
-
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; } }
|
|
57
|
-
|
|
58
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
59
|
-
|
|
60
|
-
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; }
|
|
61
|
-
|
|
14
|
+
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); }
|
|
15
|
+
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; }
|
|
16
|
+
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); }
|
|
17
|
+
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; }
|
|
18
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
19
|
+
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); } /*:: import { type Layout, type Pick } from "./utils";*/ /*:: import { type ResponsiveLayout, type OnLayoutChangeCallback, type Breakpoints } from "./responsiveUtils";*/
|
|
62
20
|
// $FlowFixMe[method-unbinding]
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
};
|
|
21
|
+
const type = obj => Object.prototype.toString.call(obj);
|
|
22
|
+
|
|
66
23
|
/**
|
|
67
24
|
* Get a value of margin or containerPadding.
|
|
68
25
|
*
|
|
@@ -70,20 +27,10 @@ var type = function type(obj) {
|
|
|
70
27
|
* @param {String} breakpoint Breakpoint: lg, md, sm, xs and etc.
|
|
71
28
|
* @return {Array}
|
|
72
29
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/*:: <T: ?[number, number]>*/
|
|
77
|
-
(param
|
|
78
|
-
/*: { [key: string]: T } | T*/
|
|
79
|
-
, breakpoint
|
|
80
|
-
/*: string*/
|
|
81
|
-
)
|
|
82
|
-
/*: T*/
|
|
83
|
-
{
|
|
30
|
+
function getIndentationValue /*:: <T: ?[number, number]>*/(param /*: { [key: string]: T } | T*/, breakpoint /*: string*/) /*: T*/{
|
|
31
|
+
// $FlowIgnore TODO fix this typedef
|
|
32
|
+
if (param == null) return null;
|
|
84
33
|
// $FlowIgnore TODO fix this typedef
|
|
85
|
-
if (param == null) return null; // $FlowIgnore TODO fix this typedef
|
|
86
|
-
|
|
87
34
|
return Array.isArray(param) ? param : param[breakpoint];
|
|
88
35
|
}
|
|
89
36
|
/*:: type State = {
|
|
@@ -92,7 +39,6 @@ function getIndentationValue
|
|
|
92
39
|
cols: number,
|
|
93
40
|
layouts?: ResponsiveLayout<string>
|
|
94
41
|
};*/
|
|
95
|
-
|
|
96
42
|
/*:: type Props<Breakpoint: string = string> = {|
|
|
97
43
|
...React.ElementConfig<typeof ReactGridLayout>,
|
|
98
44
|
|
|
@@ -116,7 +62,6 @@ function getIndentationValue
|
|
|
116
62
|
containerPadding: ?[number, number]
|
|
117
63
|
) => void
|
|
118
64
|
|};*/
|
|
119
|
-
|
|
120
65
|
/*:: type DefaultProps = Pick<
|
|
121
66
|
Props<>,
|
|
122
67
|
{|
|
|
@@ -131,181 +76,148 @@ function getIndentationValue
|
|
|
131
76
|
onWidthChange: 0
|
|
132
77
|
|}
|
|
133
78
|
>;*/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
151
|
-
|
|
152
|
-
_defineProperty(_assertThisInitialized(_this), "state", _this.generateInitialState());
|
|
153
|
-
|
|
154
|
-
_defineProperty(_assertThisInitialized(_this), "onLayoutChange", function (layout
|
|
155
|
-
/*: Layout*/
|
|
156
|
-
) {
|
|
157
|
-
_this.props.onLayoutChange(layout, _objectSpread(_objectSpread({}, _this.props.layouts), {}, _defineProperty({}, _this.state.breakpoint, layout)));
|
|
79
|
+
class ResponsiveReactGridLayout extends React.Component
|
|
80
|
+
/*:: <
|
|
81
|
+
Props<>,
|
|
82
|
+
State
|
|
83
|
+
>*/
|
|
84
|
+
{
|
|
85
|
+
constructor() {
|
|
86
|
+
super(...arguments);
|
|
87
|
+
_defineProperty(this, "state", this.generateInitialState());
|
|
88
|
+
// wrap layouts so we do not need to pass layouts to child
|
|
89
|
+
_defineProperty(this, "onLayoutChange", (layout /*: Layout*/) => {
|
|
90
|
+
this.props.onLayoutChange(layout, {
|
|
91
|
+
...this.props.layouts,
|
|
92
|
+
[this.state.breakpoint]: layout
|
|
93
|
+
});
|
|
158
94
|
});
|
|
159
|
-
|
|
160
|
-
return _this;
|
|
161
95
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
96
|
+
generateInitialState() /*: State*/{
|
|
97
|
+
const {
|
|
98
|
+
width,
|
|
99
|
+
breakpoints,
|
|
100
|
+
layouts,
|
|
101
|
+
cols
|
|
102
|
+
} = this.props;
|
|
103
|
+
const breakpoint = (0, _responsiveUtils.getBreakpointFromWidth)(breakpoints, width);
|
|
104
|
+
const colNo = (0, _responsiveUtils.getColsFromBreakpoint)(breakpoint, cols);
|
|
105
|
+
// verticalCompact compatibility, now deprecated
|
|
106
|
+
const compactType = this.props.verticalCompact === false ? null : this.props.compactType;
|
|
107
|
+
// Get the initial layout. This can tricky; we try to generate one however possible if one doesn't exist
|
|
108
|
+
// for this layout.
|
|
109
|
+
const initialLayout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(layouts, breakpoints, breakpoint, breakpoint, colNo, compactType);
|
|
110
|
+
return {
|
|
111
|
+
layout: initialLayout,
|
|
112
|
+
breakpoint: breakpoint,
|
|
113
|
+
cols: colNo
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
static getDerivedStateFromProps(nextProps /*: Props<*>*/, prevState /*: State*/) /*: ?$Shape<State>*/{
|
|
117
|
+
if (!(0, _fastEquals.deepEqual)(nextProps.layouts, prevState.layouts)) {
|
|
118
|
+
// Allow parent to set layouts directly.
|
|
119
|
+
const {
|
|
120
|
+
breakpoint,
|
|
121
|
+
cols
|
|
122
|
+
} = prevState;
|
|
123
|
+
|
|
124
|
+
// Since we're setting an entirely new layout object, we must generate a new responsive layout
|
|
125
|
+
// if one does not exist.
|
|
126
|
+
const newLayout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(nextProps.layouts, nextProps.breakpoints, breakpoint, breakpoint, cols, nextProps.compactType);
|
|
180
127
|
return {
|
|
181
|
-
layout:
|
|
182
|
-
|
|
183
|
-
cols: colNo
|
|
128
|
+
layout: newLayout,
|
|
129
|
+
layouts: nextProps.layouts
|
|
184
130
|
};
|
|
185
131
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
) {
|
|
191
|
-
|
|
192
|
-
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)) {
|
|
193
|
-
this.onWidthChange(prevProps);
|
|
194
|
-
}
|
|
195
|
-
} // wrap layouts so we do not need to pass layouts to child
|
|
196
|
-
|
|
197
|
-
}, {
|
|
198
|
-
key: "onWidthChange",
|
|
199
|
-
value:
|
|
200
|
-
/**
|
|
201
|
-
* When the width changes work through breakpoints and reset state with the new width & breakpoint.
|
|
202
|
-
* Width changes are necessary to figure out the widget widths.
|
|
203
|
-
*/
|
|
204
|
-
function onWidthChange(prevProps
|
|
205
|
-
/*: Props<*>*/
|
|
206
|
-
) {
|
|
207
|
-
var _this$props2 = this.props,
|
|
208
|
-
breakpoints = _this$props2.breakpoints,
|
|
209
|
-
cols = _this$props2.cols,
|
|
210
|
-
layouts = _this$props2.layouts,
|
|
211
|
-
compactType = _this$props2.compactType;
|
|
212
|
-
var newBreakpoint = this.props.breakpoint || (0, _responsiveUtils.getBreakpointFromWidth)(this.props.breakpoints, this.props.width);
|
|
213
|
-
var lastBreakpoint = this.state.breakpoint;
|
|
214
|
-
var newCols
|
|
215
|
-
/*: number*/
|
|
216
|
-
= (0, _responsiveUtils.getColsFromBreakpoint)(newBreakpoint, cols);
|
|
217
|
-
|
|
218
|
-
var newLayouts = _objectSpread({}, layouts); // Breakpoint change
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (lastBreakpoint !== newBreakpoint || prevProps.breakpoints !== breakpoints || prevProps.cols !== cols) {
|
|
222
|
-
// Preserve the current layout if the current breakpoint is not present in the next layouts.
|
|
223
|
-
if (!(lastBreakpoint in newLayouts)) newLayouts[lastBreakpoint] = (0, _utils.cloneLayout)(this.state.layout); // Find or generate a new layout.
|
|
224
|
-
|
|
225
|
-
var layout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(newLayouts, breakpoints, newBreakpoint, lastBreakpoint, newCols, compactType); // This adds missing items.
|
|
226
|
-
|
|
227
|
-
layout = (0, _utils.synchronizeLayoutWithChildren)(layout, this.props.children, newCols, compactType, this.props.allowOverlap); // Store the new layout.
|
|
228
|
-
|
|
229
|
-
newLayouts[newBreakpoint] = layout; // callbacks
|
|
230
|
-
|
|
231
|
-
this.props.onLayoutChange(layout, newLayouts);
|
|
232
|
-
this.props.onBreakpointChange(newBreakpoint, newCols);
|
|
233
|
-
this.setState({
|
|
234
|
-
breakpoint: newBreakpoint,
|
|
235
|
-
layout: layout,
|
|
236
|
-
cols: newCols
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
var margin = getIndentationValue(this.props.margin, newBreakpoint);
|
|
241
|
-
var containerPadding = getIndentationValue(this.props.containerPadding, newBreakpoint); //call onWidthChange on every change of width, not only on breakpoint changes
|
|
242
|
-
|
|
243
|
-
this.props.onWidthChange(this.props.width, margin, newCols, containerPadding);
|
|
244
|
-
}
|
|
245
|
-
}, {
|
|
246
|
-
key: "render",
|
|
247
|
-
value: function render()
|
|
248
|
-
/*: React.Element<typeof ReactGridLayout>*/
|
|
249
|
-
{
|
|
250
|
-
/* eslint-disable no-unused-vars */
|
|
251
|
-
var _this$props3 = this.props,
|
|
252
|
-
breakpoint = _this$props3.breakpoint,
|
|
253
|
-
breakpoints = _this$props3.breakpoints,
|
|
254
|
-
cols = _this$props3.cols,
|
|
255
|
-
layouts = _this$props3.layouts,
|
|
256
|
-
margin = _this$props3.margin,
|
|
257
|
-
containerPadding = _this$props3.containerPadding,
|
|
258
|
-
onBreakpointChange = _this$props3.onBreakpointChange,
|
|
259
|
-
onLayoutChange = _this$props3.onLayoutChange,
|
|
260
|
-
onWidthChange = _this$props3.onWidthChange,
|
|
261
|
-
other = _objectWithoutProperties(_this$props3, _excluded);
|
|
262
|
-
/* eslint-enable no-unused-vars */
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return /*#__PURE__*/React.createElement(_ReactGridLayout.default, _extends({}, other, {
|
|
266
|
-
// $FlowIgnore should allow nullable here due to DefaultProps
|
|
267
|
-
margin: getIndentationValue(margin, this.state.breakpoint),
|
|
268
|
-
containerPadding: getIndentationValue(containerPadding, this.state.breakpoint),
|
|
269
|
-
onLayoutChange: this.onLayoutChange,
|
|
270
|
-
layout: this.state.layout,
|
|
271
|
-
cols: this.state.cols
|
|
272
|
-
}));
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
componentDidUpdate(prevProps /*: Props<*>*/) {
|
|
135
|
+
// Allow parent to set width or breakpoint directly.
|
|
136
|
+
if (this.props.width != prevProps.width || this.props.breakpoint !== prevProps.breakpoint || !(0, _fastEquals.deepEqual)(this.props.breakpoints, prevProps.breakpoints) || !(0, _fastEquals.deepEqual)(this.props.cols, prevProps.cols)) {
|
|
137
|
+
this.onWidthChange(prevProps);
|
|
273
138
|
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* When the width changes work through breakpoints and reset state with the new width & breakpoint.
|
|
142
|
+
* Width changes are necessary to figure out the widget widths.
|
|
143
|
+
*/
|
|
144
|
+
onWidthChange(prevProps /*: Props<*>*/) {
|
|
145
|
+
const {
|
|
146
|
+
breakpoints,
|
|
147
|
+
cols,
|
|
148
|
+
layouts,
|
|
149
|
+
compactType
|
|
150
|
+
} = this.props;
|
|
151
|
+
const newBreakpoint = this.props.breakpoint || (0, _responsiveUtils.getBreakpointFromWidth)(this.props.breakpoints, this.props.width);
|
|
152
|
+
const lastBreakpoint = this.state.breakpoint;
|
|
153
|
+
const newCols /*: number*/ = (0, _responsiveUtils.getColsFromBreakpoint)(newBreakpoint, cols);
|
|
154
|
+
const newLayouts = {
|
|
155
|
+
...layouts
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// Breakpoint change
|
|
159
|
+
if (lastBreakpoint !== newBreakpoint || prevProps.breakpoints !== breakpoints || prevProps.cols !== cols) {
|
|
160
|
+
// Preserve the current layout if the current breakpoint is not present in the next layouts.
|
|
161
|
+
if (!(lastBreakpoint in newLayouts)) newLayouts[lastBreakpoint] = (0, _utils.cloneLayout)(this.state.layout);
|
|
162
|
+
|
|
163
|
+
// Find or generate a new layout.
|
|
164
|
+
let layout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(newLayouts, breakpoints, newBreakpoint, lastBreakpoint, newCols, compactType);
|
|
165
|
+
|
|
166
|
+
// This adds missing items.
|
|
167
|
+
layout = (0, _utils.synchronizeLayoutWithChildren)(layout, this.props.children, newCols, compactType, this.props.allowOverlap);
|
|
168
|
+
|
|
169
|
+
// Store the new layout.
|
|
170
|
+
newLayouts[newBreakpoint] = layout;
|
|
171
|
+
|
|
172
|
+
// callbacks
|
|
173
|
+
this.props.onLayoutChange(layout, newLayouts);
|
|
174
|
+
this.props.onBreakpointChange(newBreakpoint, newCols);
|
|
175
|
+
this.setState({
|
|
176
|
+
breakpoint: newBreakpoint,
|
|
177
|
+
layout: layout,
|
|
178
|
+
cols: newCols
|
|
179
|
+
});
|
|
297
180
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return ResponsiveReactGridLayout;
|
|
301
|
-
}(React.Component);
|
|
181
|
+
const margin = getIndentationValue(this.props.margin, newBreakpoint);
|
|
182
|
+
const containerPadding = getIndentationValue(this.props.containerPadding, newBreakpoint);
|
|
302
183
|
|
|
184
|
+
//call onWidthChange on every change of width, not only on breakpoint changes
|
|
185
|
+
this.props.onWidthChange(this.props.width, margin, newCols, containerPadding);
|
|
186
|
+
}
|
|
187
|
+
render() /*: React.Element<typeof ReactGridLayout>*/{
|
|
188
|
+
/* eslint-disable no-unused-vars */
|
|
189
|
+
const {
|
|
190
|
+
breakpoint,
|
|
191
|
+
breakpoints,
|
|
192
|
+
cols,
|
|
193
|
+
layouts,
|
|
194
|
+
margin,
|
|
195
|
+
containerPadding,
|
|
196
|
+
onBreakpointChange,
|
|
197
|
+
onLayoutChange,
|
|
198
|
+
onWidthChange,
|
|
199
|
+
...other
|
|
200
|
+
} = this.props;
|
|
201
|
+
/* eslint-enable no-unused-vars */
|
|
202
|
+
|
|
203
|
+
return /*#__PURE__*/React.createElement(_ReactGridLayout.default, _extends({}, other, {
|
|
204
|
+
// $FlowIgnore should allow nullable here due to DefaultProps
|
|
205
|
+
margin: getIndentationValue(margin, this.state.breakpoint),
|
|
206
|
+
containerPadding: getIndentationValue(containerPadding, this.state.breakpoint),
|
|
207
|
+
onLayoutChange: this.onLayoutChange,
|
|
208
|
+
layout: this.state.layout,
|
|
209
|
+
cols: this.state.cols
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
303
213
|
exports.default = ResponsiveReactGridLayout;
|
|
304
|
-
|
|
214
|
+
// This should only include propTypes needed in this code; RGL itself
|
|
215
|
+
// will do validation of the rest props passed to it.
|
|
305
216
|
_defineProperty(ResponsiveReactGridLayout, "propTypes", {
|
|
306
217
|
//
|
|
307
218
|
// Basic props
|
|
308
219
|
//
|
|
220
|
+
|
|
309
221
|
// Optional, but if you are managing width yourself you may want to set the breakpoint
|
|
310
222
|
// yourself as well.
|
|
311
223
|
breakpoint: _propTypes.default.string,
|
|
@@ -326,20 +238,14 @@ _defineProperty(ResponsiveReactGridLayout, "propTypes", {
|
|
|
326
238
|
containerPadding: _propTypes.default.oneOfType([_propTypes.default.array, _propTypes.default.object]),
|
|
327
239
|
// layouts is an object mapping breakpoints to layouts.
|
|
328
240
|
// e.g. {lg: Layout, md: Layout, ...}
|
|
329
|
-
layouts
|
|
330
|
-
/*: Props<>*/
|
|
331
|
-
, propName
|
|
332
|
-
/*: string*/
|
|
333
|
-
) {
|
|
241
|
+
layouts(props /*: Props<>*/, propName /*: string*/) {
|
|
334
242
|
if (type(props[propName]) !== "[object Object]") {
|
|
335
243
|
throw new Error("Layout property must be an object. Received: " + type(props[propName]));
|
|
336
244
|
}
|
|
337
|
-
|
|
338
|
-
Object.keys(props[propName]).forEach(function (key) {
|
|
245
|
+
Object.keys(props[propName]).forEach(key => {
|
|
339
246
|
if (!(key in props.breakpoints)) {
|
|
340
247
|
throw new Error("Each key in layouts must align with a key in breakpoints.");
|
|
341
248
|
}
|
|
342
|
-
|
|
343
249
|
(0, _utils.validateLayout)(props.layouts[key], "layouts." + key);
|
|
344
250
|
});
|
|
345
251
|
},
|
|
@@ -349,6 +255,7 @@ _defineProperty(ResponsiveReactGridLayout, "propTypes", {
|
|
|
349
255
|
//
|
|
350
256
|
// Callbacks
|
|
351
257
|
//
|
|
258
|
+
|
|
352
259
|
// Calls back with breakpoint and new # cols
|
|
353
260
|
onBreakpointChange: _propTypes.default.func,
|
|
354
261
|
// Callback so you can save the layout.
|
|
@@ -357,7 +264,6 @@ _defineProperty(ResponsiveReactGridLayout, "propTypes", {
|
|
|
357
264
|
// Calls back with (containerWidth, margin, cols, containerPadding)
|
|
358
265
|
onWidthChange: _propTypes.default.func
|
|
359
266
|
});
|
|
360
|
-
|
|
361
267
|
_defineProperty(ResponsiveReactGridLayout, "defaultProps", {
|
|
362
268
|
breakpoints: {
|
|
363
269
|
lg: 1200,
|