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
package/build/ReactGridLayout.js
CHANGED
|
@@ -1,353 +1,528 @@
|
|
|
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 _classnames = _interopRequireDefault(require("classnames"));
|
|
12
15
|
|
|
13
|
-
var
|
|
16
|
+
var _utils = require("./utils");
|
|
14
17
|
|
|
15
|
-
var
|
|
18
|
+
var _GridItem = _interopRequireDefault(require("./GridItem"));
|
|
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 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; }
|
|
22
25
|
|
|
23
|
-
var
|
|
26
|
+
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; }
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
|
28
31
|
|
|
29
|
-
function
|
|
32
|
+
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
|
30
33
|
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
34
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
|
34
35
|
|
|
35
|
-
function
|
|
36
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
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); } }
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
* A reactive, fluid grid layout with draggable, resizable components.
|
|
41
|
-
*/
|
|
40
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
var ReactGridLayout = function (_React$Component) {
|
|
45
|
-
_inherits(ReactGridLayout, _React$Component);
|
|
42
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
function ReactGridLayout(props, context) {
|
|
49
|
-
_classCallCheck(this, ReactGridLayout);
|
|
44
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
50
45
|
|
|
51
|
-
|
|
46
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
52
47
|
|
|
53
|
-
|
|
48
|
+
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); }
|
|
54
49
|
|
|
55
|
-
|
|
56
|
-
return _this;
|
|
57
|
-
}
|
|
50
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
this.setState({ mounted: true });
|
|
61
|
-
// Possibly call back with layout on mount. This should be done after correcting the layout width
|
|
62
|
-
// to ensure we don't rerender with the wrong width.
|
|
63
|
-
this.onLayoutMaybeChanged(this.state.layout, this.props.layout);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
ReactGridLayout.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
|
67
|
-
var newLayoutBase = void 0;
|
|
68
|
-
// Legacy support for compactType
|
|
69
|
-
// Allow parent to set layout directly.
|
|
70
|
-
if (!(0, _lodash2.default)(nextProps.layout, this.props.layout) || nextProps.compactType !== this.props.compactType) {
|
|
71
|
-
newLayoutBase = nextProps.layout;
|
|
72
|
-
} else if (!(0, _utils.childrenEqual)(this.props.children, nextProps.children)) {
|
|
73
|
-
// If children change, also regenerate the layout. Use our state
|
|
74
|
-
// as the base in case because it may be more up to date than
|
|
75
|
-
// what is in props.
|
|
76
|
-
newLayoutBase = this.state.layout;
|
|
77
|
-
}
|
|
52
|
+
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; }
|
|
78
53
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
ReactGridLayout.prototype.containerHeight = function containerHeight() {
|
|
95
|
-
if (!this.props.autoSize) return;
|
|
96
|
-
var nbRow = (0, _utils.bottom)(this.state.layout);
|
|
97
|
-
var containerPaddingY = this.props.containerPadding ? this.props.containerPadding[1] : this.props.margin[1];
|
|
98
|
-
return nbRow * this.props.rowHeight + (nbRow - 1) * this.props.margin[1] + containerPaddingY * 2 + "px";
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
ReactGridLayout.prototype.compactType = function compactType(props) {
|
|
102
|
-
if (!props) props = this.props;
|
|
103
|
-
return props.verticalCompact === false ? null : props.compactType;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* When dragging starts
|
|
108
|
-
* @param {String} i Id of the child
|
|
109
|
-
* @param {Number} x X position of the move
|
|
110
|
-
* @param {Number} y Y position of the move
|
|
111
|
-
* @param {Event} e The mousedown event
|
|
112
|
-
* @param {Element} node The current dragging DOM element
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
ReactGridLayout.prototype.onDragStart = function onDragStart(i, x, y, _ref) {
|
|
117
|
-
var e = _ref.e,
|
|
118
|
-
node = _ref.node;
|
|
119
|
-
var layout = this.state.layout;
|
|
120
|
-
|
|
121
|
-
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
122
|
-
if (!l) return;
|
|
123
|
-
|
|
124
|
-
this.setState({
|
|
125
|
-
oldDragItem: (0, _utils.cloneLayoutItem)(l),
|
|
126
|
-
oldLayout: this.state.layout
|
|
127
|
-
});
|
|
54
|
+
// End Types
|
|
55
|
+
var compactType = function compactType(props
|
|
56
|
+
/*: Props*/
|
|
57
|
+
)
|
|
58
|
+
/*: CompactType*/
|
|
59
|
+
{
|
|
60
|
+
var _ref = props || {},
|
|
61
|
+
verticalCompact = _ref.verticalCompact,
|
|
62
|
+
compactType = _ref.compactType;
|
|
63
|
+
|
|
64
|
+
return verticalCompact === false ? null : compactType;
|
|
65
|
+
};
|
|
128
66
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Each drag movement create a new dragelement and move the element to the dragged location
|
|
134
|
-
* @param {String} i Id of the child
|
|
135
|
-
* @param {Number} x X position of the move
|
|
136
|
-
* @param {Number} y Y position of the move
|
|
137
|
-
* @param {Event} e The mousedown event
|
|
138
|
-
* @param {Element} node The current dragging DOM element
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
ReactGridLayout.prototype.onDrag = function onDrag(i, x, y, _ref2) {
|
|
143
|
-
var e = _ref2.e,
|
|
144
|
-
node = _ref2.node;
|
|
145
|
-
var oldDragItem = this.state.oldDragItem;
|
|
146
|
-
var layout = this.state.layout;
|
|
147
|
-
var cols = this.props.cols;
|
|
148
|
-
|
|
149
|
-
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
150
|
-
if (!l) return;
|
|
151
|
-
|
|
152
|
-
// Create placeholder (display only)
|
|
153
|
-
var placeholder = {
|
|
154
|
-
w: l.w,
|
|
155
|
-
h: l.h,
|
|
156
|
-
x: l.x,
|
|
157
|
-
y: l.y,
|
|
158
|
-
placeholder: true,
|
|
159
|
-
i: i
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// Move the element to the dragged location.
|
|
163
|
-
var isUserAction = true;
|
|
164
|
-
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, this.props.preventCollision, this.compactType(), cols);
|
|
165
|
-
|
|
166
|
-
this.props.onDrag(layout, oldDragItem, l, placeholder, e, node);
|
|
167
|
-
|
|
168
|
-
this.setState({
|
|
169
|
-
layout: (0, _utils.compact)(layout, this.compactType(), cols),
|
|
170
|
-
activeDrag: placeholder
|
|
171
|
-
});
|
|
172
|
-
};
|
|
67
|
+
var layoutClassName = "react-grid-layout";
|
|
68
|
+
var isFirefox = false; // Try...catch will protect from navigator not existing (e.g. node) or a bad implementation of navigator
|
|
173
69
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
* @param {Number} y Y position of the move
|
|
179
|
-
* @param {Event} e The mousedown event
|
|
180
|
-
* @param {Element} node The current dragging DOM element
|
|
181
|
-
*/
|
|
70
|
+
try {
|
|
71
|
+
isFirefox = navigator.userAgent.toLowerCase().includes("firefox");
|
|
72
|
+
} catch (e) {}
|
|
73
|
+
/* Ignore */
|
|
182
74
|
|
|
75
|
+
/**
|
|
76
|
+
* A reactive, fluid grid layout with draggable, resizable components.
|
|
77
|
+
*/
|
|
183
78
|
|
|
184
|
-
ReactGridLayout.prototype.onDragStop = function onDragStop(i, x, y, _ref3) {
|
|
185
|
-
var e = _ref3.e,
|
|
186
|
-
node = _ref3.node;
|
|
187
|
-
var oldDragItem = this.state.oldDragItem;
|
|
188
|
-
var layout = this.state.layout;
|
|
189
|
-
var _props = this.props,
|
|
190
|
-
cols = _props.cols,
|
|
191
|
-
preventCollision = _props.preventCollision;
|
|
192
79
|
|
|
193
|
-
|
|
194
|
-
|
|
80
|
+
var ReactGridLayout =
|
|
81
|
+
/*#__PURE__*/
|
|
82
|
+
function (_React$Component) {
|
|
83
|
+
_inherits(ReactGridLayout, _React$Component);
|
|
195
84
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
85
|
+
// TODO publish internal ReactClass displayName transform
|
|
86
|
+
function ReactGridLayout(props
|
|
87
|
+
/*: Props*/
|
|
88
|
+
, context
|
|
89
|
+
/*: any*/
|
|
90
|
+
)
|
|
91
|
+
/*: void*/
|
|
92
|
+
{
|
|
93
|
+
var _this;
|
|
199
94
|
|
|
200
|
-
this
|
|
95
|
+
_classCallCheck(this, ReactGridLayout);
|
|
201
96
|
|
|
202
|
-
|
|
203
|
-
var newLayout = (0, _utils.compact)(layout, this.compactType(), cols);
|
|
204
|
-
var oldLayout = this.state.oldLayout;
|
|
97
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(ReactGridLayout).call(this, props, context));
|
|
205
98
|
|
|
206
|
-
|
|
99
|
+
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
207
100
|
activeDrag: null,
|
|
208
|
-
layout:
|
|
101
|
+
layout: (0, _utils.synchronizeLayoutWithChildren)(_this.props.layout, _this.props.children, _this.props.cols, // Legacy support for verticalCompact: false
|
|
102
|
+
compactType(_this.props)),
|
|
103
|
+
mounted: false,
|
|
209
104
|
oldDragItem: null,
|
|
210
|
-
oldLayout: null
|
|
105
|
+
oldLayout: null,
|
|
106
|
+
oldResizeItem: null,
|
|
107
|
+
droppingDOMNode: null,
|
|
108
|
+
children: []
|
|
211
109
|
});
|
|
212
110
|
|
|
213
|
-
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
ReactGridLayout.prototype.onLayoutMaybeChanged = function onLayoutMaybeChanged(newLayout, oldLayout) {
|
|
217
|
-
if (!oldLayout) oldLayout = this.state.layout;
|
|
218
|
-
if (!(0, _lodash2.default)(oldLayout, newLayout)) {
|
|
219
|
-
this.props.onLayoutChange(newLayout);
|
|
220
|
-
}
|
|
221
|
-
};
|
|
111
|
+
_defineProperty(_assertThisInitialized(_this), "dragEnterCounter", 0);
|
|
222
112
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
113
|
+
_defineProperty(_assertThisInitialized(_this), "onDragOver", function (e
|
|
114
|
+
/*: DragOverEvent*/
|
|
115
|
+
) {
|
|
116
|
+
// we should ignore events from layout's children in Firefox
|
|
117
|
+
// to avoid unpredictable jumping of a dropping placeholder
|
|
118
|
+
if (isFirefox && !e.nativeEvent.target.className.includes(layoutClassName)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
227
121
|
|
|
228
|
-
|
|
229
|
-
|
|
122
|
+
var droppingItem = _this.props.droppingItem;
|
|
123
|
+
var layout = _this.state.layout;
|
|
124
|
+
var _e$nativeEvent = e.nativeEvent,
|
|
125
|
+
layerX = _e$nativeEvent.layerX,
|
|
126
|
+
layerY = _e$nativeEvent.layerY;
|
|
127
|
+
var droppingPosition = {
|
|
128
|
+
x: layerX,
|
|
129
|
+
y: layerY,
|
|
130
|
+
e: e
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
if (!_this.state.droppingDOMNode) {
|
|
134
|
+
_this.setState({
|
|
135
|
+
droppingDOMNode: _react.default.createElement("div", {
|
|
136
|
+
key: droppingItem.i
|
|
137
|
+
}),
|
|
138
|
+
droppingPosition: droppingPosition,
|
|
139
|
+
layout: [].concat(_toConsumableArray(layout), [_objectSpread({}, droppingItem, {
|
|
140
|
+
x: 0,
|
|
141
|
+
y: 0,
|
|
142
|
+
static: false,
|
|
143
|
+
isDraggable: true
|
|
144
|
+
})])
|
|
145
|
+
});
|
|
146
|
+
} else if (_this.state.droppingPosition) {
|
|
147
|
+
var shouldUpdatePosition = _this.state.droppingPosition.x != layerX || _this.state.droppingPosition.y != layerY;
|
|
148
|
+
shouldUpdatePosition && _this.setState({
|
|
149
|
+
droppingPosition: droppingPosition
|
|
150
|
+
});
|
|
151
|
+
}
|
|
230
152
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
oldLayout: this.state.layout
|
|
153
|
+
e.stopPropagation();
|
|
154
|
+
e.preventDefault();
|
|
234
155
|
});
|
|
235
156
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (!l) return;
|
|
251
|
-
|
|
252
|
-
// Something like quad tree should be used
|
|
253
|
-
// to find collisions faster
|
|
254
|
-
var hasCollisions = void 0;
|
|
255
|
-
if (preventCollision) {
|
|
256
|
-
var collisions = (0, _utils.getAllCollisions)(layout, _extends({}, l, { w: w, h: h })).filter(function (layoutItem) {
|
|
257
|
-
return layoutItem.i !== l.i;
|
|
157
|
+
_defineProperty(_assertThisInitialized(_this), "removeDroppingPlaceholder", function () {
|
|
158
|
+
var _this$props = _this.props,
|
|
159
|
+
droppingItem = _this$props.droppingItem,
|
|
160
|
+
cols = _this$props.cols;
|
|
161
|
+
var layout = _this.state.layout;
|
|
162
|
+
var newLayout = (0, _utils.compact)(layout.filter(function (l) {
|
|
163
|
+
return l.i !== droppingItem.i;
|
|
164
|
+
}), compactType(_this.props), cols);
|
|
165
|
+
|
|
166
|
+
_this.setState({
|
|
167
|
+
layout: newLayout,
|
|
168
|
+
droppingDOMNode: null,
|
|
169
|
+
activeDrag: null,
|
|
170
|
+
droppingPosition: undefined
|
|
258
171
|
});
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
// If we're colliding, we need adjust the placeholder.
|
|
262
|
-
if (hasCollisions) {
|
|
263
|
-
// adjust w && h to maximum allowed space
|
|
264
|
-
var leastX = Infinity,
|
|
265
|
-
leastY = Infinity;
|
|
266
|
-
collisions.forEach(function (layoutItem) {
|
|
267
|
-
if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
|
|
268
|
-
if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
|
|
269
|
-
});
|
|
172
|
+
});
|
|
270
173
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
174
|
+
_defineProperty(_assertThisInitialized(_this), "onDragLeave", function () {
|
|
175
|
+
_this.dragEnterCounter--; // onDragLeave can be triggered on each layout's child.
|
|
176
|
+
// But we know that count of dragEnter and dragLeave events
|
|
177
|
+
// will be balanced after leaving the layout's container
|
|
178
|
+
// so we can increase and decrease count of dragEnter and
|
|
179
|
+
// when it'll be equal to 0 we'll remove the placeholder
|
|
275
180
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
181
|
+
if (_this.dragEnterCounter === 0) {
|
|
182
|
+
_this.removeDroppingPlaceholder();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
281
185
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
w: l.w,
|
|
285
|
-
h: l.h,
|
|
286
|
-
x: l.x,
|
|
287
|
-
y: l.y,
|
|
288
|
-
static: true,
|
|
289
|
-
i: i
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
this.props.onResize(layout, oldResizeItem, l, placeholder, e, node);
|
|
293
|
-
|
|
294
|
-
// Re-compact the layout and set the drag placeholder.
|
|
295
|
-
this.setState({
|
|
296
|
-
layout: (0, _utils.compact)(layout, this.compactType(), cols),
|
|
297
|
-
activeDrag: placeholder
|
|
186
|
+
_defineProperty(_assertThisInitialized(_this), "onDragEnter", function () {
|
|
187
|
+
_this.dragEnterCounter++;
|
|
298
188
|
});
|
|
299
|
-
};
|
|
300
189
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
var _state2 = this.state,
|
|
305
|
-
layout = _state2.layout,
|
|
306
|
-
oldResizeItem = _state2.oldResizeItem;
|
|
307
|
-
var cols = this.props.cols;
|
|
190
|
+
_defineProperty(_assertThisInitialized(_this), "onDrop", function () {
|
|
191
|
+
var droppingItem = _this.props.droppingItem;
|
|
192
|
+
var layout = _this.state.layout;
|
|
308
193
|
|
|
309
|
-
|
|
194
|
+
var _ref2 = layout.find(function (l) {
|
|
195
|
+
return l.i === droppingItem.i;
|
|
196
|
+
}) || {},
|
|
197
|
+
x = _ref2.x,
|
|
198
|
+
y = _ref2.y,
|
|
199
|
+
w = _ref2.w,
|
|
200
|
+
h = _ref2.h; // reset gragEnter counter on drop
|
|
310
201
|
|
|
311
|
-
this.props.onResizeStop(layout, oldResizeItem, l, null, e, node);
|
|
312
202
|
|
|
313
|
-
|
|
314
|
-
var newLayout = (0, _utils.compact)(layout, this.compactType(), cols);
|
|
315
|
-
var oldLayout = this.state.oldLayout;
|
|
203
|
+
_this.dragEnterCounter = 0;
|
|
316
204
|
|
|
317
|
-
|
|
318
|
-
activeDrag: null,
|
|
319
|
-
layout: newLayout,
|
|
320
|
-
oldResizeItem: null,
|
|
321
|
-
oldLayout: null
|
|
322
|
-
});
|
|
205
|
+
_this.removeDroppingPlaceholder();
|
|
323
206
|
|
|
324
|
-
|
|
325
|
-
|
|
207
|
+
_this.props.onDrop({
|
|
208
|
+
x: x,
|
|
209
|
+
y: y,
|
|
210
|
+
w: w,
|
|
211
|
+
h: h
|
|
212
|
+
});
|
|
213
|
+
});
|
|
326
214
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
*/
|
|
215
|
+
(0, _utils.autoBindHandlers)(_assertThisInitialized(_this), ["onDragStart", "onDrag", "onDragStop", "onResizeStart", "onResize", "onResizeStop"]);
|
|
216
|
+
return _this;
|
|
217
|
+
}
|
|
331
218
|
|
|
219
|
+
_createClass(ReactGridLayout, [{
|
|
220
|
+
key: "componentDidMount",
|
|
221
|
+
value: function componentDidMount() {
|
|
222
|
+
this.setState({
|
|
223
|
+
mounted: true
|
|
224
|
+
}); // Possibly call back with layout on mount. This should be done after correcting the layout width
|
|
225
|
+
// to ensure we don't rerender with the wrong width.
|
|
332
226
|
|
|
333
|
-
|
|
334
|
-
|
|
227
|
+
this.onLayoutMaybeChanged(this.state.layout, this.props.layout);
|
|
228
|
+
}
|
|
229
|
+
}, {
|
|
230
|
+
key: "componentDidUpdate",
|
|
231
|
+
value: function componentDidUpdate(prevProps
|
|
232
|
+
/*: Props*/
|
|
233
|
+
, prevState
|
|
234
|
+
/*: State*/
|
|
235
|
+
) {
|
|
236
|
+
if (!this.state.activeDrag) {
|
|
237
|
+
var newLayout = this.state.layout;
|
|
238
|
+
var oldLayout = prevState.layout;
|
|
239
|
+
this.onLayoutMaybeChanged(newLayout, oldLayout);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Calculates a pixel value for the container.
|
|
244
|
+
* @return {String} Container height in pixels.
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
}, {
|
|
248
|
+
key: "containerHeight",
|
|
249
|
+
value: function containerHeight() {
|
|
250
|
+
if (!this.props.autoSize) return;
|
|
251
|
+
var nbRow = (0, _utils.bottom)(this.state.layout);
|
|
252
|
+
var containerPaddingY = this.props.containerPadding ? this.props.containerPadding[1] : this.props.margin[1];
|
|
253
|
+
return nbRow * this.props.rowHeight + (nbRow - 1) * this.props.margin[1] + containerPaddingY * 2 + "px";
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* When dragging starts
|
|
257
|
+
* @param {String} i Id of the child
|
|
258
|
+
* @param {Number} x X position of the move
|
|
259
|
+
* @param {Number} y Y position of the move
|
|
260
|
+
* @param {Event} e The mousedown event
|
|
261
|
+
* @param {Element} node The current dragging DOM element
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
}, {
|
|
265
|
+
key: "onDragStart",
|
|
266
|
+
value: function onDragStart(i
|
|
267
|
+
/*: string*/
|
|
268
|
+
, x
|
|
269
|
+
/*: number*/
|
|
270
|
+
, y
|
|
271
|
+
/*: number*/
|
|
272
|
+
, _ref3) {
|
|
273
|
+
var e = _ref3.e,
|
|
274
|
+
node = _ref3.node;
|
|
275
|
+
var layout = this.state.layout;
|
|
276
|
+
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
277
|
+
if (!l) return;
|
|
278
|
+
this.setState({
|
|
279
|
+
oldDragItem: (0, _utils.cloneLayoutItem)(l),
|
|
280
|
+
oldLayout: this.state.layout
|
|
281
|
+
});
|
|
282
|
+
return this.props.onDragStart(layout, l, l, null, e, node);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Each drag movement create a new dragelement and move the element to the dragged location
|
|
286
|
+
* @param {String} i Id of the child
|
|
287
|
+
* @param {Number} x X position of the move
|
|
288
|
+
* @param {Number} y Y position of the move
|
|
289
|
+
* @param {Event} e The mousedown event
|
|
290
|
+
* @param {Element} node The current dragging DOM element
|
|
291
|
+
*/
|
|
292
|
+
|
|
293
|
+
}, {
|
|
294
|
+
key: "onDrag",
|
|
295
|
+
value: function onDrag(i
|
|
296
|
+
/*: string*/
|
|
297
|
+
, x
|
|
298
|
+
/*: number*/
|
|
299
|
+
, y
|
|
300
|
+
/*: number*/
|
|
301
|
+
, _ref4) {
|
|
302
|
+
var e = _ref4.e,
|
|
303
|
+
node = _ref4.node;
|
|
304
|
+
var oldDragItem = this.state.oldDragItem;
|
|
305
|
+
var layout = this.state.layout;
|
|
306
|
+
var cols = this.props.cols;
|
|
307
|
+
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
308
|
+
if (!l) return; // Create placeholder (display only)
|
|
309
|
+
|
|
310
|
+
var placeholder = {
|
|
311
|
+
w: l.w,
|
|
312
|
+
h: l.h,
|
|
313
|
+
x: l.x,
|
|
314
|
+
y: l.y,
|
|
315
|
+
placeholder: true,
|
|
316
|
+
i: i
|
|
317
|
+
}; // Move the element to the dragged location.
|
|
318
|
+
|
|
319
|
+
var isUserAction = true;
|
|
320
|
+
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, this.props.preventCollision, compactType(this.props), cols);
|
|
321
|
+
this.props.onDrag(layout, oldDragItem, l, placeholder, e, node);
|
|
322
|
+
this.setState({
|
|
323
|
+
layout: (0, _utils.compact)(layout, compactType(this.props), cols),
|
|
324
|
+
activeDrag: placeholder
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* When dragging stops, figure out which position the element is closest to and update its x and y.
|
|
329
|
+
* @param {String} i Index of the child.
|
|
330
|
+
* @param {Number} x X position of the move
|
|
331
|
+
* @param {Number} y Y position of the move
|
|
332
|
+
* @param {Event} e The mousedown event
|
|
333
|
+
* @param {Element} node The current dragging DOM element
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
}, {
|
|
337
|
+
key: "onDragStop",
|
|
338
|
+
value: function onDragStop(i
|
|
339
|
+
/*: string*/
|
|
340
|
+
, x
|
|
341
|
+
/*: number*/
|
|
342
|
+
, y
|
|
343
|
+
/*: number*/
|
|
344
|
+
, _ref5) {
|
|
345
|
+
var e = _ref5.e,
|
|
346
|
+
node = _ref5.node;
|
|
347
|
+
var oldDragItem = this.state.oldDragItem;
|
|
348
|
+
var layout = this.state.layout;
|
|
349
|
+
var _this$props2 = this.props,
|
|
350
|
+
cols = _this$props2.cols,
|
|
351
|
+
preventCollision = _this$props2.preventCollision;
|
|
352
|
+
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
353
|
+
if (!l) return; // Move the element here
|
|
354
|
+
|
|
355
|
+
var isUserAction = true;
|
|
356
|
+
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, compactType(this.props), cols);
|
|
357
|
+
|
|
358
|
+
if (this.state.activeDrag) {
|
|
359
|
+
this.props.onDragStop(layout, oldDragItem, l, null, e, node);
|
|
360
|
+
} // Set state
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
var newLayout = (0, _utils.compact)(layout, compactType(this.props), cols);
|
|
364
|
+
var oldLayout = this.state.oldLayout;
|
|
365
|
+
this.setState({
|
|
366
|
+
activeDrag: null,
|
|
367
|
+
layout: newLayout,
|
|
368
|
+
oldDragItem: null,
|
|
369
|
+
oldLayout: null
|
|
370
|
+
});
|
|
371
|
+
this.onLayoutMaybeChanged(newLayout, oldLayout);
|
|
372
|
+
}
|
|
373
|
+
}, {
|
|
374
|
+
key: "onLayoutMaybeChanged",
|
|
375
|
+
value: function onLayoutMaybeChanged(newLayout
|
|
376
|
+
/*: Layout*/
|
|
377
|
+
, oldLayout
|
|
378
|
+
/*: ?Layout*/
|
|
379
|
+
) {
|
|
380
|
+
if (!oldLayout) oldLayout = this.state.layout;
|
|
381
|
+
|
|
382
|
+
if (!(0, _lodash.default)(oldLayout, newLayout)) {
|
|
383
|
+
this.props.onLayoutChange(newLayout);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}, {
|
|
387
|
+
key: "onResizeStart",
|
|
388
|
+
value: function onResizeStart(i
|
|
389
|
+
/*: string*/
|
|
390
|
+
, w
|
|
391
|
+
/*: number*/
|
|
392
|
+
, h
|
|
393
|
+
/*: number*/
|
|
394
|
+
, _ref6) {
|
|
395
|
+
var e = _ref6.e,
|
|
396
|
+
node = _ref6.node;
|
|
397
|
+
var layout = this.state.layout;
|
|
398
|
+
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
399
|
+
if (!l) return;
|
|
400
|
+
this.setState({
|
|
401
|
+
oldResizeItem: (0, _utils.cloneLayoutItem)(l),
|
|
402
|
+
oldLayout: this.state.layout
|
|
403
|
+
});
|
|
404
|
+
this.props.onResizeStart(layout, l, l, null, e, node);
|
|
405
|
+
}
|
|
406
|
+
}, {
|
|
407
|
+
key: "onResize",
|
|
408
|
+
value: function onResize(i
|
|
409
|
+
/*: string*/
|
|
410
|
+
, w
|
|
411
|
+
/*: number*/
|
|
412
|
+
, h
|
|
413
|
+
/*: number*/
|
|
414
|
+
, _ref7) {
|
|
415
|
+
var e = _ref7.e,
|
|
416
|
+
node = _ref7.node;
|
|
417
|
+
var _this$state = this.state,
|
|
418
|
+
layout = _this$state.layout,
|
|
419
|
+
oldResizeItem = _this$state.oldResizeItem;
|
|
420
|
+
var _this$props3 = this.props,
|
|
421
|
+
cols = _this$props3.cols,
|
|
422
|
+
preventCollision = _this$props3.preventCollision;
|
|
423
|
+
var l
|
|
424
|
+
/*: ?LayoutItem*/
|
|
425
|
+
= (0, _utils.getLayoutItem)(layout, i);
|
|
426
|
+
if (!l) return; // Something like quad tree should be used
|
|
427
|
+
// to find collisions faster
|
|
428
|
+
|
|
429
|
+
var hasCollisions;
|
|
430
|
+
|
|
431
|
+
if (preventCollision) {
|
|
432
|
+
var collisions = (0, _utils.getAllCollisions)(layout, _objectSpread({}, l, {
|
|
433
|
+
w: w,
|
|
434
|
+
h: h
|
|
435
|
+
})).filter(function (layoutItem) {
|
|
436
|
+
return layoutItem.i !== l.i;
|
|
437
|
+
});
|
|
438
|
+
hasCollisions = collisions.length > 0; // If we're colliding, we need adjust the placeholder.
|
|
439
|
+
|
|
440
|
+
if (hasCollisions) {
|
|
441
|
+
// adjust w && h to maximum allowed space
|
|
442
|
+
var leastX = Infinity,
|
|
443
|
+
leastY = Infinity;
|
|
444
|
+
collisions.forEach(function (layoutItem) {
|
|
445
|
+
if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
|
|
446
|
+
if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
|
|
447
|
+
});
|
|
448
|
+
if (Number.isFinite(leastX)) l.w = leastX - l.x;
|
|
449
|
+
if (Number.isFinite(leastY)) l.h = leastY - l.y;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
335
452
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
containerPadding = _props3.containerPadding,
|
|
342
|
-
rowHeight = _props3.rowHeight,
|
|
343
|
-
maxRows = _props3.maxRows,
|
|
344
|
-
useCSSTransforms = _props3.useCSSTransforms;
|
|
453
|
+
if (!hasCollisions) {
|
|
454
|
+
// Set new width and height.
|
|
455
|
+
l.w = w;
|
|
456
|
+
l.h = h;
|
|
457
|
+
} // Create placeholder element (display only)
|
|
345
458
|
|
|
346
|
-
// {...this.state.activeDrag} is pretty slow, actually
|
|
347
459
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
460
|
+
var placeholder = {
|
|
461
|
+
w: l.w,
|
|
462
|
+
h: l.h,
|
|
463
|
+
x: l.x,
|
|
464
|
+
y: l.y,
|
|
465
|
+
static: true,
|
|
466
|
+
i: i
|
|
467
|
+
};
|
|
468
|
+
this.props.onResize(layout, oldResizeItem, l, placeholder, e, node); // Re-compact the layout and set the drag placeholder.
|
|
469
|
+
|
|
470
|
+
this.setState({
|
|
471
|
+
layout: (0, _utils.compact)(layout, compactType(this.props), cols),
|
|
472
|
+
activeDrag: placeholder
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}, {
|
|
476
|
+
key: "onResizeStop",
|
|
477
|
+
value: function onResizeStop(i
|
|
478
|
+
/*: string*/
|
|
479
|
+
, w
|
|
480
|
+
/*: number*/
|
|
481
|
+
, h
|
|
482
|
+
/*: number*/
|
|
483
|
+
, _ref8) {
|
|
484
|
+
var e = _ref8.e,
|
|
485
|
+
node = _ref8.node;
|
|
486
|
+
var _this$state2 = this.state,
|
|
487
|
+
layout = _this$state2.layout,
|
|
488
|
+
oldResizeItem = _this$state2.oldResizeItem;
|
|
489
|
+
var cols = this.props.cols;
|
|
490
|
+
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
491
|
+
this.props.onResizeStop(layout, oldResizeItem, l, null, e, node); // Set state
|
|
492
|
+
|
|
493
|
+
var newLayout = (0, _utils.compact)(layout, compactType(this.props), cols);
|
|
494
|
+
var oldLayout = this.state.oldLayout;
|
|
495
|
+
this.setState({
|
|
496
|
+
activeDrag: null,
|
|
497
|
+
layout: newLayout,
|
|
498
|
+
oldResizeItem: null,
|
|
499
|
+
oldLayout: null
|
|
500
|
+
});
|
|
501
|
+
this.onLayoutMaybeChanged(newLayout, oldLayout);
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Create a placeholder object.
|
|
505
|
+
* @return {Element} Placeholder div.
|
|
506
|
+
*/
|
|
507
|
+
|
|
508
|
+
}, {
|
|
509
|
+
key: "placeholder",
|
|
510
|
+
value: function placeholder()
|
|
511
|
+
/*: ?ReactElement<any>*/
|
|
512
|
+
{
|
|
513
|
+
var activeDrag = this.state.activeDrag;
|
|
514
|
+
if (!activeDrag) return null;
|
|
515
|
+
var _this$props4 = this.props,
|
|
516
|
+
width = _this$props4.width,
|
|
517
|
+
cols = _this$props4.cols,
|
|
518
|
+
margin = _this$props4.margin,
|
|
519
|
+
containerPadding = _this$props4.containerPadding,
|
|
520
|
+
rowHeight = _this$props4.rowHeight,
|
|
521
|
+
maxRows = _this$props4.maxRows,
|
|
522
|
+
useCSSTransforms = _this$props4.useCSSTransforms,
|
|
523
|
+
transformScale = _this$props4.transformScale; // {...this.state.activeDrag} is pretty slow, actually
|
|
524
|
+
|
|
525
|
+
return _react.default.createElement(_GridItem.default, {
|
|
351
526
|
w: activeDrag.w,
|
|
352
527
|
h: activeDrag.h,
|
|
353
528
|
x: activeDrag.x,
|
|
@@ -362,45 +537,48 @@ var ReactGridLayout = function (_React$Component) {
|
|
|
362
537
|
rowHeight: rowHeight,
|
|
363
538
|
isDraggable: false,
|
|
364
539
|
isResizable: false,
|
|
365
|
-
useCSSTransforms: useCSSTransforms
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
540
|
+
useCSSTransforms: useCSSTransforms,
|
|
541
|
+
transformScale: transformScale
|
|
542
|
+
}, _react.default.createElement("div", null));
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Given a grid item, set its style attributes & surround in a <Draggable>.
|
|
546
|
+
* @param {Element} child React element.
|
|
547
|
+
* @return {Element} Element wrapped in draggable and properly placed.
|
|
548
|
+
*/
|
|
549
|
+
|
|
550
|
+
}, {
|
|
551
|
+
key: "processGridItem",
|
|
552
|
+
value: function processGridItem(child
|
|
553
|
+
/*: ReactElement<any>*/
|
|
554
|
+
, isDroppingItem
|
|
555
|
+
/*: boolean*/
|
|
556
|
+
)
|
|
557
|
+
/*: ?ReactElement<any>*/
|
|
558
|
+
{
|
|
559
|
+
if (!child || !child.key) return;
|
|
560
|
+
var l = (0, _utils.getLayoutItem)(this.state.layout, String(child.key));
|
|
561
|
+
if (!l) return null;
|
|
562
|
+
var _this$props5 = this.props,
|
|
563
|
+
width = _this$props5.width,
|
|
564
|
+
cols = _this$props5.cols,
|
|
565
|
+
margin = _this$props5.margin,
|
|
566
|
+
containerPadding = _this$props5.containerPadding,
|
|
567
|
+
rowHeight = _this$props5.rowHeight,
|
|
568
|
+
maxRows = _this$props5.maxRows,
|
|
569
|
+
isDraggable = _this$props5.isDraggable,
|
|
570
|
+
isResizable = _this$props5.isResizable,
|
|
571
|
+
useCSSTransforms = _this$props5.useCSSTransforms,
|
|
572
|
+
transformScale = _this$props5.transformScale,
|
|
573
|
+
draggableCancel = _this$props5.draggableCancel,
|
|
574
|
+
draggableHandle = _this$props5.draggableHandle;
|
|
575
|
+
var _this$state3 = this.state,
|
|
576
|
+
mounted = _this$state3.mounted,
|
|
577
|
+
droppingPosition = _this$state3.droppingPosition; // Parse 'static'. Any properties defined directly on the grid item will take precedence.
|
|
578
|
+
|
|
579
|
+
var draggable = Boolean(!l.static && isDraggable && (l.isDraggable || l.isDraggable == null));
|
|
580
|
+
var resizable = Boolean(!l.static && isResizable && (l.isResizable || l.isResizable == null));
|
|
581
|
+
return _react.default.createElement(_GridItem.default, {
|
|
404
582
|
containerWidth: width,
|
|
405
583
|
cols: cols,
|
|
406
584
|
margin: margin,
|
|
@@ -419,6 +597,7 @@ var ReactGridLayout = function (_React$Component) {
|
|
|
419
597
|
isResizable: resizable,
|
|
420
598
|
useCSSTransforms: useCSSTransforms && mounted,
|
|
421
599
|
usePercentages: !mounted,
|
|
600
|
+
transformScale: transformScale,
|
|
422
601
|
w: l.w,
|
|
423
602
|
h: l.h,
|
|
424
603
|
x: l.x,
|
|
@@ -428,148 +607,200 @@ var ReactGridLayout = function (_React$Component) {
|
|
|
428
607
|
minW: l.minW,
|
|
429
608
|
maxH: l.maxH,
|
|
430
609
|
maxW: l.maxW,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
child
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
610
|
+
static: l.static,
|
|
611
|
+
droppingPosition: isDroppingItem ? droppingPosition : undefined
|
|
612
|
+
}, child);
|
|
613
|
+
}
|
|
614
|
+
}, {
|
|
615
|
+
key: "render",
|
|
616
|
+
value: function render() {
|
|
617
|
+
var _this2 = this;
|
|
618
|
+
|
|
619
|
+
var _this$props6 = this.props,
|
|
620
|
+
className = _this$props6.className,
|
|
621
|
+
style = _this$props6.style,
|
|
622
|
+
isDroppable = _this$props6.isDroppable;
|
|
623
|
+
var mergedClassName = (0, _classnames.default)(layoutClassName, className);
|
|
624
|
+
|
|
625
|
+
var mergedStyle = _objectSpread({
|
|
626
|
+
height: this.containerHeight()
|
|
627
|
+
}, style);
|
|
628
|
+
|
|
629
|
+
return _react.default.createElement("div", {
|
|
630
|
+
className: mergedClassName,
|
|
631
|
+
style: mergedStyle,
|
|
632
|
+
onDrop: isDroppable ? this.onDrop : _utils.noop,
|
|
633
|
+
onDragLeave: isDroppable ? this.onDragLeave : _utils.noop,
|
|
634
|
+
onDragEnter: isDroppable ? this.onDragEnter : _utils.noop,
|
|
635
|
+
onDragOver: isDroppable ? this.onDragOver : _utils.noop
|
|
636
|
+
}, _react.default.Children.map(this.props.children, function (child) {
|
|
637
|
+
return _this2.processGridItem(child);
|
|
638
|
+
}), isDroppable && this.state.droppingDOMNode && this.processGridItem(this.state.droppingDOMNode, true), this.placeholder());
|
|
639
|
+
}
|
|
640
|
+
}], [{
|
|
641
|
+
key: "getDerivedStateFromProps",
|
|
642
|
+
value: function getDerivedStateFromProps(nextProps
|
|
643
|
+
/*: Props*/
|
|
644
|
+
, prevState
|
|
645
|
+
/*: State*/
|
|
646
|
+
) {
|
|
647
|
+
var newLayoutBase;
|
|
648
|
+
|
|
649
|
+
if (prevState.activeDrag) {
|
|
650
|
+
return null;
|
|
651
|
+
} // Legacy support for compactType
|
|
652
|
+
// Allow parent to set layout directly.
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
if (!(0, _lodash.default)(nextProps.layout, prevState.propsLayout) || nextProps.compactType !== prevState.compactType) {
|
|
656
|
+
newLayoutBase = nextProps.layout;
|
|
657
|
+
} else if (!(0, _utils.childrenEqual)(nextProps.children, prevState.children)) {
|
|
658
|
+
// If children change, also regenerate the layout. Use our state
|
|
659
|
+
// as the base in case because it may be more up to date than
|
|
660
|
+
// what is in props.
|
|
661
|
+
newLayoutBase = prevState.layout;
|
|
662
|
+
} // We need to regenerate the layout.
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
if (newLayoutBase) {
|
|
666
|
+
var newLayout = (0, _utils.synchronizeLayoutWithChildren)(newLayoutBase, nextProps.children, nextProps.cols, compactType(nextProps));
|
|
667
|
+
return {
|
|
668
|
+
layout: newLayout,
|
|
669
|
+
// We need to save these props to state for using
|
|
670
|
+
// getDerivedStateFromProps instead of componentDidMount (in which we would get extra rerender)
|
|
671
|
+
compactType: nextProps.compactType,
|
|
672
|
+
children: nextProps.children,
|
|
673
|
+
propsLayout: nextProps.layout
|
|
674
|
+
};
|
|
675
|
+
}
|
|
443
676
|
|
|
677
|
+
return null;
|
|
678
|
+
}
|
|
679
|
+
}]);
|
|
444
680
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
height: this.containerHeight()
|
|
448
|
-
}, style);
|
|
681
|
+
return ReactGridLayout;
|
|
682
|
+
}(_react.default.Component);
|
|
449
683
|
|
|
450
|
-
|
|
451
|
-
"div",
|
|
452
|
-
{ className: mergedClassName, style: mergedStyle },
|
|
453
|
-
_react2.default.Children.map(this.props.children, function (child) {
|
|
454
|
-
return _this2.processGridItem(child);
|
|
455
|
-
}),
|
|
456
|
-
this.placeholder()
|
|
457
|
-
);
|
|
458
|
-
};
|
|
684
|
+
exports.default = ReactGridLayout;
|
|
459
685
|
|
|
460
|
-
|
|
461
|
-
}(_react2.default.Component);
|
|
686
|
+
_defineProperty(ReactGridLayout, "displayName", "ReactGridLayout");
|
|
462
687
|
|
|
463
|
-
ReactGridLayout
|
|
464
|
-
ReactGridLayout.propTypes = {
|
|
688
|
+
_defineProperty(ReactGridLayout, "propTypes", {
|
|
465
689
|
//
|
|
466
690
|
// Basic props
|
|
467
691
|
//
|
|
468
|
-
className:
|
|
469
|
-
style:
|
|
470
|
-
|
|
692
|
+
className: _propTypes.default.string,
|
|
693
|
+
style: _propTypes.default.object,
|
|
471
694
|
// This can be set explicitly. If it is not set, it will automatically
|
|
472
695
|
// be set to the container width. Note that resizes will *not* cause this to adjust.
|
|
473
696
|
// If you need that behavior, use WidthProvider.
|
|
474
|
-
width:
|
|
475
|
-
|
|
697
|
+
width: _propTypes.default.number,
|
|
476
698
|
// If true, the container height swells and contracts to fit contents
|
|
477
|
-
autoSize:
|
|
699
|
+
autoSize: _propTypes.default.bool,
|
|
478
700
|
// # of cols.
|
|
479
|
-
cols:
|
|
480
|
-
|
|
701
|
+
cols: _propTypes.default.number,
|
|
481
702
|
// A selector that will not be draggable.
|
|
482
|
-
draggableCancel:
|
|
703
|
+
draggableCancel: _propTypes.default.string,
|
|
483
704
|
// A selector for the draggable handler
|
|
484
|
-
draggableHandle:
|
|
485
|
-
|
|
705
|
+
draggableHandle: _propTypes.default.string,
|
|
486
706
|
// Deprecated
|
|
487
|
-
verticalCompact: function verticalCompact(props
|
|
707
|
+
verticalCompact: function verticalCompact(props
|
|
708
|
+
/*: Props*/
|
|
709
|
+
) {
|
|
488
710
|
if (props.verticalCompact === false && process.env.NODE_ENV !== "production") {
|
|
489
|
-
console.warn(
|
|
490
|
-
// eslint-disable-line no-console
|
|
711
|
+
console.warn( // eslint-disable-line no-console
|
|
491
712
|
"`verticalCompact` on <ReactGridLayout> is deprecated and will be removed soon. " + 'Use `compactType`: "horizontal" | "vertical" | null.');
|
|
492
713
|
}
|
|
493
714
|
},
|
|
494
715
|
// Choose vertical or hotizontal compaction
|
|
495
|
-
compactType:
|
|
496
|
-
|
|
716
|
+
compactType: _propTypes.default.oneOf(["vertical", "horizontal"]),
|
|
497
717
|
// layout is an array of object with the format:
|
|
498
718
|
// {x: Number, y: Number, w: Number, h: Number, i: String}
|
|
499
|
-
layout: function layout(props
|
|
500
|
-
|
|
501
|
-
|
|
719
|
+
layout: function layout(props
|
|
720
|
+
/*: Props*/
|
|
721
|
+
) {
|
|
722
|
+
var layout = props.layout; // I hope you're setting the data-grid property on the grid items
|
|
723
|
+
|
|
502
724
|
if (layout === undefined) return;
|
|
503
725
|
(0, _utils.validateLayout)(layout, "layout");
|
|
504
726
|
},
|
|
505
|
-
|
|
506
727
|
//
|
|
507
728
|
// Grid Dimensions
|
|
508
729
|
//
|
|
509
|
-
|
|
510
730
|
// Margin between items [x, y] in px
|
|
511
|
-
margin:
|
|
731
|
+
margin: _propTypes.default.arrayOf(_propTypes.default.number),
|
|
512
732
|
// Padding inside the container [x, y] in px
|
|
513
|
-
containerPadding:
|
|
733
|
+
containerPadding: _propTypes.default.arrayOf(_propTypes.default.number),
|
|
514
734
|
// Rows have a static height, but you can change this based on breakpoints if you like
|
|
515
|
-
rowHeight:
|
|
735
|
+
rowHeight: _propTypes.default.number,
|
|
516
736
|
// Default Infinity, but you can specify a max here if you like.
|
|
517
737
|
// Note that this isn't fully fleshed out and won't error if you specify a layout that
|
|
518
738
|
// extends beyond the row capacity. It will, however, not allow users to drag/resize
|
|
519
739
|
// an item past the barrier. They can push items beyond the barrier, though.
|
|
520
740
|
// Intentionally not documented for this reason.
|
|
521
|
-
maxRows:
|
|
522
|
-
|
|
741
|
+
maxRows: _propTypes.default.number,
|
|
523
742
|
//
|
|
524
743
|
// Flags
|
|
525
744
|
//
|
|
526
|
-
isDraggable:
|
|
527
|
-
isResizable:
|
|
745
|
+
isDraggable: _propTypes.default.bool,
|
|
746
|
+
isResizable: _propTypes.default.bool,
|
|
528
747
|
// If true, grid items won't change position when being dragged over.
|
|
529
|
-
preventCollision:
|
|
748
|
+
preventCollision: _propTypes.default.bool,
|
|
530
749
|
// Use CSS transforms instead of top/left
|
|
531
|
-
useCSSTransforms:
|
|
532
|
-
|
|
750
|
+
useCSSTransforms: _propTypes.default.bool,
|
|
751
|
+
// parent layout transform scale
|
|
752
|
+
transformScale: _propTypes.default.number,
|
|
753
|
+
// If true, an external element can trigger onDrop callback with a specific grid position as a parameter
|
|
754
|
+
isDroppable: _propTypes.default.bool,
|
|
533
755
|
//
|
|
534
756
|
// Callbacks
|
|
535
757
|
//
|
|
536
|
-
|
|
537
758
|
// Callback so you can save the layout. Calls after each drag & resize stops.
|
|
538
|
-
onLayoutChange:
|
|
539
|
-
|
|
759
|
+
onLayoutChange: _propTypes.default.func,
|
|
540
760
|
// Calls when drag starts. Callback is of the signature (layout, oldItem, newItem, placeholder, e, ?node).
|
|
541
761
|
// All callbacks below have the same signature. 'start' and 'stop' callbacks omit the 'placeholder'.
|
|
542
|
-
onDragStart:
|
|
762
|
+
onDragStart: _propTypes.default.func,
|
|
543
763
|
// Calls on each drag movement.
|
|
544
|
-
onDrag:
|
|
764
|
+
onDrag: _propTypes.default.func,
|
|
545
765
|
// Calls when drag is complete.
|
|
546
|
-
onDragStop:
|
|
766
|
+
onDragStop: _propTypes.default.func,
|
|
547
767
|
//Calls when resize starts.
|
|
548
|
-
onResizeStart:
|
|
768
|
+
onResizeStart: _propTypes.default.func,
|
|
549
769
|
// Calls when resize movement happens.
|
|
550
|
-
onResize:
|
|
770
|
+
onResize: _propTypes.default.func,
|
|
551
771
|
// Calls when resize is complete.
|
|
552
|
-
onResizeStop:
|
|
553
|
-
|
|
772
|
+
onResizeStop: _propTypes.default.func,
|
|
773
|
+
// Calls when some element is dropped.
|
|
774
|
+
onDrop: _propTypes.default.func,
|
|
554
775
|
//
|
|
555
776
|
// Other validations
|
|
556
777
|
//
|
|
557
|
-
|
|
778
|
+
droppingItem: _propTypes.default.shape({
|
|
779
|
+
i: _propTypes.default.string.isRequired,
|
|
780
|
+
w: _propTypes.default.number.isRequired,
|
|
781
|
+
h: _propTypes.default.number.isRequired
|
|
782
|
+
}),
|
|
558
783
|
// Children must not have duplicate keys.
|
|
559
|
-
children: function children(props
|
|
560
|
-
|
|
784
|
+
children: function children(props
|
|
785
|
+
/*: Props*/
|
|
786
|
+
, propName
|
|
787
|
+
/*: string*/
|
|
788
|
+
) {
|
|
789
|
+
var children = props[propName]; // Check children keys for duplicates. Throw if found.
|
|
561
790
|
|
|
562
|
-
// Check children keys for duplicates. Throw if found.
|
|
563
791
|
var keys = {};
|
|
564
|
-
|
|
792
|
+
|
|
793
|
+
_react.default.Children.forEach(children, function (child) {
|
|
565
794
|
if (keys[child.key]) {
|
|
566
795
|
throw new Error('Duplicate child key "' + child.key + '" found! This will cause problems in ReactGridLayout.');
|
|
567
796
|
}
|
|
797
|
+
|
|
568
798
|
keys[child.key] = true;
|
|
569
799
|
});
|
|
570
800
|
}
|
|
571
|
-
};
|
|
572
|
-
|
|
801
|
+
});
|
|
802
|
+
|
|
803
|
+
_defineProperty(ReactGridLayout, "defaultProps", {
|
|
573
804
|
autoSize: true,
|
|
574
805
|
cols: 12,
|
|
575
806
|
className: "",
|
|
@@ -578,35 +809,29 @@ ReactGridLayout.defaultProps = {
|
|
|
578
809
|
draggableCancel: "",
|
|
579
810
|
containerPadding: null,
|
|
580
811
|
rowHeight: 150,
|
|
581
|
-
maxRows: Infinity,
|
|
812
|
+
maxRows: Infinity,
|
|
813
|
+
// infinite vertical growth
|
|
582
814
|
layout: [],
|
|
583
815
|
margin: [10, 10],
|
|
584
816
|
isDraggable: true,
|
|
585
817
|
isResizable: true,
|
|
818
|
+
isDroppable: false,
|
|
586
819
|
useCSSTransforms: true,
|
|
820
|
+
transformScale: 1,
|
|
587
821
|
verticalCompact: true,
|
|
588
822
|
compactType: "vertical",
|
|
589
823
|
preventCollision: false,
|
|
824
|
+
droppingItem: {
|
|
825
|
+
i: "__dropping-elem__",
|
|
826
|
+
h: 1,
|
|
827
|
+
w: 1
|
|
828
|
+
},
|
|
590
829
|
onLayoutChange: _utils.noop,
|
|
591
830
|
onDragStart: _utils.noop,
|
|
592
831
|
onDrag: _utils.noop,
|
|
593
832
|
onDragStop: _utils.noop,
|
|
594
833
|
onResizeStart: _utils.noop,
|
|
595
834
|
onResize: _utils.noop,
|
|
596
|
-
onResizeStop: _utils.noop
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
var _initialiseProps = function _initialiseProps() {
|
|
600
|
-
this.state = {
|
|
601
|
-
activeDrag: null,
|
|
602
|
-
layout: (0, _utils.synchronizeLayoutWithChildren)(this.props.layout, this.props.children, this.props.cols,
|
|
603
|
-
// Legacy support for verticalCompact: false
|
|
604
|
-
this.compactType()),
|
|
605
|
-
mounted: false,
|
|
606
|
-
oldDragItem: null,
|
|
607
|
-
oldLayout: null,
|
|
608
|
-
oldResizeItem: null
|
|
609
|
-
};
|
|
610
|
-
};
|
|
611
|
-
|
|
612
|
-
exports.default = ReactGridLayout;
|
|
835
|
+
onResizeStop: _utils.noop,
|
|
836
|
+
onDrop: _utils.noop
|
|
837
|
+
});
|