react-grid-layout 1.3.4 → 1.4.0
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/.packj.yaml +153 -0
- package/.prettierignore +2 -1
- package/.prettierrc +0 -1
- package/CHANGELOG.md +36 -0
- package/README.md +35 -6
- package/build/GridItem.js +590 -493
- package/build/ReactGridLayout.js +534 -592
- package/build/ReactGridLayoutPropTypes.js +51 -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 +290 -443
- 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 +140 -50
- package/lib/ReactGridLayout.jsx +64 -23
- package/lib/ResponsiveReactGridLayout.jsx +4 -4
- package/lib/calculateUtils.js +20 -4
- package/lib/components/WidthProvider.jsx +18 -16
- package/lib/utils.js +76 -21
- package/margin.png +0 -0
- package/package.json +40 -36
package/build/ReactGridLayout.js
CHANGED
|
@@ -1,253 +1,253 @@
|
|
|
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
|
-
var _lodash = _interopRequireDefault(require("lodash.isequal"));
|
|
13
|
-
|
|
8
|
+
var _fastEquals = require("fast-equals");
|
|
14
9
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
15
|
-
|
|
16
10
|
var _utils = require("./utils");
|
|
17
|
-
|
|
18
11
|
var _calculateUtils = require("./calculateUtils");
|
|
19
|
-
|
|
20
12
|
var _GridItem = _interopRequireDefault(require("./GridItem"));
|
|
21
|
-
|
|
22
13
|
var _ReactGridLayoutPropTypes = _interopRequireDefault(require("./ReactGridLayoutPropTypes"));
|
|
23
|
-
|
|
24
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
63
|
-
|
|
64
|
-
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); }; }
|
|
65
|
-
|
|
66
|
-
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); }
|
|
67
|
-
|
|
68
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
69
|
-
|
|
70
|
-
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; } }
|
|
71
|
-
|
|
72
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
73
|
-
|
|
74
|
-
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; }
|
|
75
|
-
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
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); }
|
|
20
|
+
/*:: import type {
|
|
21
|
+
ChildrenArray as ReactChildrenArray,
|
|
22
|
+
Element as ReactElement
|
|
23
|
+
} from "react";*/
|
|
24
|
+
/*:: import type {
|
|
25
|
+
CompactType,
|
|
26
|
+
GridResizeEvent,
|
|
27
|
+
GridDragEvent,
|
|
28
|
+
DragOverEvent,
|
|
29
|
+
Layout,
|
|
30
|
+
DroppingPosition,
|
|
31
|
+
LayoutItem
|
|
32
|
+
} from "./utils";*/
|
|
33
|
+
// Types
|
|
34
|
+
/*:: import type { PositionParams } from "./calculateUtils";*/
|
|
35
|
+
/*:: type State = {
|
|
36
|
+
activeDrag: ?LayoutItem,
|
|
37
|
+
layout: Layout,
|
|
38
|
+
mounted: boolean,
|
|
39
|
+
oldDragItem: ?LayoutItem,
|
|
40
|
+
oldLayout: ?Layout,
|
|
41
|
+
oldResizeItem: ?LayoutItem,
|
|
42
|
+
resizing: boolean,
|
|
43
|
+
droppingDOMNode: ?ReactElement<any>,
|
|
44
|
+
droppingPosition?: DroppingPosition,
|
|
45
|
+
// Mirrored props
|
|
46
|
+
children: ReactChildrenArray<ReactElement<any>>,
|
|
47
|
+
compactType?: CompactType,
|
|
48
|
+
propsLayout?: Layout
|
|
49
|
+
};*/
|
|
50
|
+
/*:: import type { Props, DefaultProps } from "./ReactGridLayoutPropTypes";*/
|
|
76
51
|
// End Types
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
52
|
+
const layoutClassName = "react-grid-layout";
|
|
53
|
+
let isFirefox = false;
|
|
54
|
+
// Try...catch will protect from navigator not existing (e.g. node) or a bad implementation of navigator
|
|
80
55
|
try {
|
|
81
56
|
isFirefox = /firefox/i.test(navigator.userAgent);
|
|
82
57
|
} catch (e) {
|
|
83
58
|
/* Ignore */
|
|
84
59
|
}
|
|
60
|
+
|
|
85
61
|
/**
|
|
86
62
|
* A reactive, fluid grid layout with draggable, resizable components.
|
|
87
63
|
*/
|
|
88
64
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var _super = _createSuper(ReactGridLayout);
|
|
94
|
-
|
|
95
|
-
function ReactGridLayout() {
|
|
96
|
-
var _this;
|
|
97
|
-
|
|
98
|
-
_classCallCheck(this, ReactGridLayout);
|
|
99
|
-
|
|
100
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
101
|
-
args[_key] = arguments[_key];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
105
|
-
|
|
106
|
-
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
65
|
+
class ReactGridLayout extends React.Component /*:: <Props, State>*/{
|
|
66
|
+
constructor() {
|
|
67
|
+
super(...arguments);
|
|
68
|
+
_defineProperty(this, "state", {
|
|
107
69
|
activeDrag: null,
|
|
108
|
-
layout: (0, _utils.synchronizeLayoutWithChildren)(
|
|
109
|
-
|
|
70
|
+
layout: (0, _utils.synchronizeLayoutWithChildren)(this.props.layout, this.props.children, this.props.cols,
|
|
71
|
+
// Legacy support for verticalCompact: false
|
|
72
|
+
(0, _utils.compactType)(this.props), this.props.allowOverlap),
|
|
110
73
|
mounted: false,
|
|
111
74
|
oldDragItem: null,
|
|
112
75
|
oldLayout: null,
|
|
113
76
|
oldResizeItem: null,
|
|
77
|
+
resizing: false,
|
|
114
78
|
droppingDOMNode: null,
|
|
115
79
|
children: []
|
|
116
80
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
, _ref) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
81
|
+
_defineProperty(this, "dragEnterCounter", 0);
|
|
82
|
+
/**
|
|
83
|
+
* When dragging starts
|
|
84
|
+
* @param {String} i Id of the child
|
|
85
|
+
* @param {Number} x X position of the move
|
|
86
|
+
* @param {Number} y Y position of the move
|
|
87
|
+
* @param {Event} e The mousedown event
|
|
88
|
+
* @param {Element} node The current dragging DOM element
|
|
89
|
+
*/
|
|
90
|
+
_defineProperty(this, "onDragStart", (i /*: string*/, x /*: number*/, y /*: number*/, _ref /*:: */) => {
|
|
91
|
+
let {
|
|
92
|
+
e,
|
|
93
|
+
node
|
|
94
|
+
} /*: GridDragEvent*/ = _ref /*: GridDragEvent*/;
|
|
95
|
+
const {
|
|
96
|
+
layout
|
|
97
|
+
} = this.state;
|
|
98
|
+
const l = (0, _utils.getLayoutItem)(layout, i);
|
|
131
99
|
if (!l) return;
|
|
132
|
-
|
|
133
|
-
_this.setState({
|
|
100
|
+
this.setState({
|
|
134
101
|
oldDragItem: (0, _utils.cloneLayoutItem)(l),
|
|
135
102
|
oldLayout: layout
|
|
136
103
|
});
|
|
137
|
-
|
|
138
|
-
return _this.props.onDragStart(layout, l, l, null, e, node);
|
|
104
|
+
return this.props.onDragStart(layout, l, l, null, e, node);
|
|
139
105
|
});
|
|
106
|
+
/**
|
|
107
|
+
* Each drag movement create a new dragelement and move the element to the dragged location
|
|
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
|
+
_defineProperty(this, "onDrag", (i, x, y, _ref2) => {
|
|
115
|
+
let {
|
|
116
|
+
e,
|
|
117
|
+
node
|
|
118
|
+
} = _ref2;
|
|
119
|
+
const {
|
|
120
|
+
oldDragItem
|
|
121
|
+
} = this.state;
|
|
122
|
+
let {
|
|
123
|
+
layout
|
|
124
|
+
} = this.state;
|
|
125
|
+
const {
|
|
126
|
+
cols,
|
|
127
|
+
allowOverlap,
|
|
128
|
+
preventCollision
|
|
129
|
+
} = this.props;
|
|
130
|
+
const l = (0, _utils.getLayoutItem)(layout, i);
|
|
131
|
+
if (!l) return;
|
|
140
132
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
node = _ref2.node;
|
|
144
|
-
var oldDragItem = _this.state.oldDragItem;
|
|
145
|
-
var layout = _this.state.layout;
|
|
146
|
-
var _this$props = _this.props,
|
|
147
|
-
cols = _this$props.cols,
|
|
148
|
-
allowOverlap = _this$props.allowOverlap,
|
|
149
|
-
preventCollision = _this$props.preventCollision;
|
|
150
|
-
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
151
|
-
if (!l) return; // Create placeholder (display only)
|
|
152
|
-
|
|
153
|
-
var placeholder = {
|
|
133
|
+
// Create placeholder (display only)
|
|
134
|
+
const placeholder = {
|
|
154
135
|
w: l.w,
|
|
155
136
|
h: l.h,
|
|
156
137
|
x: l.x,
|
|
157
138
|
y: l.y,
|
|
158
139
|
placeholder: true,
|
|
159
140
|
i: i
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
var isUserAction = true;
|
|
163
|
-
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(_this.props), cols, allowOverlap);
|
|
164
|
-
|
|
165
|
-
_this.props.onDrag(layout, oldDragItem, l, placeholder, e, node);
|
|
141
|
+
};
|
|
166
142
|
|
|
167
|
-
|
|
168
|
-
|
|
143
|
+
// Move the element to the dragged location.
|
|
144
|
+
const isUserAction = true;
|
|
145
|
+
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(this.props), cols, allowOverlap);
|
|
146
|
+
this.props.onDrag(layout, oldDragItem, l, placeholder, e, node);
|
|
147
|
+
this.setState({
|
|
148
|
+
layout: allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols),
|
|
169
149
|
activeDrag: placeholder
|
|
170
150
|
});
|
|
171
151
|
});
|
|
152
|
+
/**
|
|
153
|
+
* When dragging stops, figure out which position the element is closest to and update its x and y.
|
|
154
|
+
* @param {String} i Index of the child.
|
|
155
|
+
* @param {Number} x X position of the move
|
|
156
|
+
* @param {Number} y Y position of the move
|
|
157
|
+
* @param {Event} e The mousedown event
|
|
158
|
+
* @param {Element} node The current dragging DOM element
|
|
159
|
+
*/
|
|
160
|
+
_defineProperty(this, "onDragStop", (i, x, y, _ref3) => {
|
|
161
|
+
let {
|
|
162
|
+
e,
|
|
163
|
+
node
|
|
164
|
+
} = _ref3;
|
|
165
|
+
if (!this.state.activeDrag) return;
|
|
166
|
+
const {
|
|
167
|
+
oldDragItem
|
|
168
|
+
} = this.state;
|
|
169
|
+
let {
|
|
170
|
+
layout
|
|
171
|
+
} = this.state;
|
|
172
|
+
const {
|
|
173
|
+
cols,
|
|
174
|
+
preventCollision,
|
|
175
|
+
allowOverlap
|
|
176
|
+
} = this.props;
|
|
177
|
+
const l = (0, _utils.getLayoutItem)(layout, i);
|
|
178
|
+
if (!l) return;
|
|
172
179
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (!_this.state.activeDrag) return;
|
|
177
|
-
var oldDragItem = _this.state.oldDragItem;
|
|
178
|
-
var layout = _this.state.layout;
|
|
179
|
-
var _this$props2 = _this.props,
|
|
180
|
-
cols = _this$props2.cols,
|
|
181
|
-
preventCollision = _this$props2.preventCollision,
|
|
182
|
-
allowOverlap = _this$props2.allowOverlap;
|
|
183
|
-
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
184
|
-
if (!l) return; // Move the element here
|
|
185
|
-
|
|
186
|
-
var isUserAction = true;
|
|
187
|
-
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(_this.props), cols, allowOverlap);
|
|
188
|
-
|
|
189
|
-
_this.props.onDragStop(layout, oldDragItem, l, null, e, node); // Set state
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var newLayout = allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(_this.props), cols);
|
|
193
|
-
var oldLayout = _this.state.oldLayout;
|
|
180
|
+
// Move the element here
|
|
181
|
+
const isUserAction = true;
|
|
182
|
+
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(this.props), cols, allowOverlap);
|
|
194
183
|
|
|
195
|
-
|
|
184
|
+
// Set state
|
|
185
|
+
const newLayout = allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols);
|
|
186
|
+
this.props.onDragStop(newLayout, oldDragItem, l, null, e, node);
|
|
187
|
+
const {
|
|
188
|
+
oldLayout
|
|
189
|
+
} = this.state;
|
|
190
|
+
this.setState({
|
|
196
191
|
activeDrag: null,
|
|
197
192
|
layout: newLayout,
|
|
198
193
|
oldDragItem: null,
|
|
199
194
|
oldLayout: null
|
|
200
195
|
});
|
|
201
|
-
|
|
202
|
-
_this.onLayoutMaybeChanged(newLayout, oldLayout);
|
|
196
|
+
this.onLayoutMaybeChanged(newLayout, oldLayout);
|
|
203
197
|
});
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
198
|
+
_defineProperty(this, "onResizeStart", (i, w, h, _ref4) => {
|
|
199
|
+
let {
|
|
200
|
+
e,
|
|
201
|
+
node
|
|
202
|
+
} = _ref4;
|
|
203
|
+
const {
|
|
204
|
+
layout
|
|
205
|
+
} = this.state;
|
|
206
|
+
const l = (0, _utils.getLayoutItem)(layout, i);
|
|
210
207
|
if (!l) return;
|
|
211
|
-
|
|
212
|
-
_this.setState({
|
|
208
|
+
this.setState({
|
|
213
209
|
oldResizeItem: (0, _utils.cloneLayoutItem)(l),
|
|
214
|
-
oldLayout:
|
|
210
|
+
oldLayout: this.state.layout,
|
|
211
|
+
resizing: true
|
|
215
212
|
});
|
|
216
|
-
|
|
217
|
-
_this.props.onResizeStart(layout, l, l, null, e, node);
|
|
213
|
+
this.props.onResizeStart(layout, l, l, null, e, node);
|
|
218
214
|
});
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
215
|
+
_defineProperty(this, "onResize", (i, w, h, _ref5) => {
|
|
216
|
+
let {
|
|
217
|
+
e,
|
|
218
|
+
node,
|
|
219
|
+
size,
|
|
220
|
+
handle
|
|
221
|
+
} = _ref5;
|
|
222
|
+
const {
|
|
223
|
+
oldResizeItem
|
|
224
|
+
} = this.state;
|
|
225
|
+
let {
|
|
226
|
+
layout
|
|
227
|
+
} = this.state;
|
|
228
|
+
const {
|
|
229
|
+
cols,
|
|
230
|
+
preventCollision,
|
|
231
|
+
allowOverlap
|
|
232
|
+
} = this.props;
|
|
233
|
+
const [newLayout, l] = (0, _utils.withLayoutItem)(layout, i, l => {
|
|
232
234
|
// Something like quad tree should be used
|
|
233
235
|
// to find collisions faster
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
let hasCollisions;
|
|
236
237
|
if (preventCollision && !allowOverlap) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
hasCollisions = collisions.length > 0; // If we're colliding, we need adjust the placeholder.
|
|
238
|
+
const collisions = (0, _utils.getAllCollisions)(layout, {
|
|
239
|
+
...l,
|
|
240
|
+
w,
|
|
241
|
+
h
|
|
242
|
+
}).filter(layoutItem => layoutItem.i !== l.i);
|
|
243
|
+
hasCollisions = collisions.length > 0;
|
|
244
244
|
|
|
245
245
|
// If we're colliding, we need adjust the placeholder.
|
|
246
246
|
if (hasCollisions) {
|
|
247
247
|
// adjust w && h to maximum allowed space
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
collisions.forEach(
|
|
248
|
+
let leastX = Infinity,
|
|
249
|
+
leastY = Infinity;
|
|
250
|
+
collisions.forEach(layoutItem => {
|
|
251
251
|
if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
|
|
252
252
|
if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
|
|
253
253
|
});
|
|
@@ -255,23 +255,38 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
|
|
|
255
255
|
if (Number.isFinite(leastY)) l.h = leastY - l.y;
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
|
-
|
|
259
|
-
if (!hasCollisions) {
|
|
260
|
-
// Set new width and height.
|
|
261
|
-
l.w = w;
|
|
262
|
-
l.h = h;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
258
|
return l;
|
|
266
|
-
})
|
|
267
|
-
_withLayoutItem2 = _slicedToArray(_withLayoutItem, 2),
|
|
268
|
-
newLayout = _withLayoutItem2[0],
|
|
269
|
-
l = _withLayoutItem2[1]; // Shouldn't ever happen, but typechecking makes it necessary
|
|
270
|
-
|
|
259
|
+
});
|
|
271
260
|
|
|
272
|
-
|
|
261
|
+
// Shouldn't ever happen, but typechecking makes it necessary
|
|
262
|
+
if (!l) return;
|
|
263
|
+
let finalLayout;
|
|
264
|
+
if (["sw", "w", "nw", "n", "ne"].indexOf(handle) !== -1) {
|
|
265
|
+
let x = l.x;
|
|
266
|
+
let y = l.y;
|
|
267
|
+
if (["sw", "nw", "w"].indexOf(handle) !== -1) {
|
|
268
|
+
x = l.x + (l.w - w);
|
|
269
|
+
w = l.x !== x && x < 0 ? l.w : w;
|
|
270
|
+
x = x < 0 ? 0 : x;
|
|
271
|
+
}
|
|
272
|
+
if (["ne", "n", "nw"].indexOf(handle) !== -1) {
|
|
273
|
+
y = l.y + (l.h - h);
|
|
274
|
+
h = l.y !== y && y < 0 ? l.h : h;
|
|
275
|
+
y = y < 0 ? 0 : y;
|
|
276
|
+
}
|
|
277
|
+
l.w = w;
|
|
278
|
+
l.h = h;
|
|
279
|
+
// Move the element to the new position.
|
|
280
|
+
const isUserAction = true;
|
|
281
|
+
finalLayout = (0, _utils.moveElement)(newLayout, l, x, y, isUserAction, this.props.preventCollision, (0, _utils.compactType)(this.props), cols, allowOverlap);
|
|
282
|
+
} else {
|
|
283
|
+
l.w = w;
|
|
284
|
+
l.h = h;
|
|
285
|
+
finalLayout = newLayout;
|
|
286
|
+
}
|
|
273
287
|
|
|
274
|
-
|
|
288
|
+
// Create placeholder element (display only)
|
|
289
|
+
const placeholder = {
|
|
275
290
|
w: l.w,
|
|
276
291
|
h: l.h,
|
|
277
292
|
x: l.x,
|
|
@@ -279,474 +294,401 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
|
|
|
279
294
|
static: true,
|
|
280
295
|
i: i
|
|
281
296
|
};
|
|
297
|
+
this.props.onResize(finalLayout, oldResizeItem, l, placeholder, e, node);
|
|
282
298
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
_this.setState({
|
|
287
|
-
layout: allowOverlap ? newLayout : (0, _utils.compact)(newLayout, (0, _utils.compactType)(_this.props), cols),
|
|
299
|
+
// Re-compact the newLayout and set the drag placeholder.
|
|
300
|
+
this.setState({
|
|
301
|
+
layout: allowOverlap ? finalLayout : (0, _utils.compact)(finalLayout, (0, _utils.compactType)(this.props), cols),
|
|
288
302
|
activeDrag: placeholder
|
|
289
303
|
});
|
|
290
304
|
});
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
305
|
+
_defineProperty(this, "onResizeStop", (i, w, h, _ref6) => {
|
|
306
|
+
let {
|
|
307
|
+
e,
|
|
308
|
+
node
|
|
309
|
+
} = _ref6;
|
|
310
|
+
const {
|
|
311
|
+
layout,
|
|
312
|
+
oldResizeItem
|
|
313
|
+
} = this.state;
|
|
314
|
+
const {
|
|
315
|
+
cols,
|
|
316
|
+
allowOverlap
|
|
317
|
+
} = this.props;
|
|
318
|
+
const l = (0, _utils.getLayoutItem)(layout, i);
|
|
319
|
+
|
|
320
|
+
// Set state
|
|
321
|
+
const newLayout = allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols);
|
|
322
|
+
this.props.onResizeStop(newLayout, oldResizeItem, l, null, e, node);
|
|
323
|
+
const {
|
|
324
|
+
oldLayout
|
|
325
|
+
} = this.state;
|
|
326
|
+
this.setState({
|
|
310
327
|
activeDrag: null,
|
|
311
328
|
layout: newLayout,
|
|
312
329
|
oldResizeItem: null,
|
|
313
|
-
oldLayout: null
|
|
330
|
+
oldLayout: null,
|
|
331
|
+
resizing: false
|
|
314
332
|
});
|
|
315
|
-
|
|
316
|
-
_this.onLayoutMaybeChanged(newLayout, oldLayout);
|
|
333
|
+
this.onLayoutMaybeChanged(newLayout, oldLayout);
|
|
317
334
|
});
|
|
318
|
-
|
|
319
|
-
|
|
335
|
+
// Called while dragging an element. Part of browser native drag/drop API.
|
|
336
|
+
// Native event target might be the layout itself, or an element within the layout.
|
|
337
|
+
_defineProperty(this, "onDragOver", e => {
|
|
320
338
|
var _e$nativeEvent$target;
|
|
321
|
-
|
|
322
339
|
e.preventDefault(); // Prevent any browser native action
|
|
340
|
+
e.stopPropagation();
|
|
323
341
|
|
|
324
|
-
|
|
342
|
+
// we should ignore events from layout's children in Firefox
|
|
325
343
|
// to avoid unpredictable jumping of a dropping placeholder
|
|
326
344
|
// FIXME remove this hack
|
|
327
|
-
|
|
328
|
-
|
|
345
|
+
if (isFirefox &&
|
|
346
|
+
// $FlowIgnore can't figure this out
|
|
329
347
|
!((_e$nativeEvent$target = e.nativeEvent.target) !== null && _e$nativeEvent$target !== void 0 && _e$nativeEvent$target.classList.contains(layoutClassName))) {
|
|
330
348
|
return false;
|
|
331
349
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
350
|
+
const {
|
|
351
|
+
droppingItem,
|
|
352
|
+
onDropDragOver,
|
|
353
|
+
margin,
|
|
354
|
+
cols,
|
|
355
|
+
rowHeight,
|
|
356
|
+
maxRows,
|
|
357
|
+
width,
|
|
358
|
+
containerPadding,
|
|
359
|
+
transformScale
|
|
360
|
+
} = this.props;
|
|
361
|
+
// Allow user to customize the dropping item or short-circuit the drop based on the results
|
|
343
362
|
// of the `onDragOver(e: Event)` callback.
|
|
344
|
-
|
|
345
|
-
var onDragOverResult = onDropDragOver === null || onDropDragOver === void 0 ? void 0 : onDropDragOver(e);
|
|
346
|
-
|
|
363
|
+
const onDragOverResult = onDropDragOver === null || onDropDragOver === void 0 ? void 0 : onDropDragOver(e);
|
|
347
364
|
if (onDragOverResult === false) {
|
|
348
|
-
if (
|
|
349
|
-
|
|
365
|
+
if (this.state.droppingDOMNode) {
|
|
366
|
+
this.removeDroppingPlaceholder();
|
|
350
367
|
}
|
|
351
|
-
|
|
352
368
|
return false;
|
|
353
369
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
370
|
+
const finalDroppingItem = {
|
|
371
|
+
...droppingItem,
|
|
372
|
+
...onDragOverResult
|
|
373
|
+
};
|
|
374
|
+
const {
|
|
375
|
+
layout
|
|
376
|
+
} = this.state;
|
|
377
|
+
// This is relative to the DOM element that this event fired for.
|
|
378
|
+
const {
|
|
379
|
+
layerX,
|
|
380
|
+
layerY
|
|
381
|
+
} = e.nativeEvent;
|
|
382
|
+
const droppingPosition = {
|
|
363
383
|
left: layerX / transformScale,
|
|
364
384
|
top: layerY / transformScale,
|
|
365
|
-
e
|
|
385
|
+
e
|
|
366
386
|
};
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
margin: margin,
|
|
374
|
-
maxRows: maxRows,
|
|
375
|
-
rowHeight: rowHeight,
|
|
387
|
+
if (!this.state.droppingDOMNode) {
|
|
388
|
+
const positionParams /*: PositionParams*/ = {
|
|
389
|
+
cols,
|
|
390
|
+
margin,
|
|
391
|
+
maxRows,
|
|
392
|
+
rowHeight,
|
|
376
393
|
containerWidth: width,
|
|
377
394
|
containerPadding: containerPadding || margin
|
|
378
395
|
};
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
_this.setState({
|
|
396
|
+
const calculatedPosition = (0, _calculateUtils.calcXY)(positionParams, layerY, layerX, finalDroppingItem.w, finalDroppingItem.h);
|
|
397
|
+
this.setState({
|
|
382
398
|
droppingDOMNode: /*#__PURE__*/React.createElement("div", {
|
|
383
399
|
key: finalDroppingItem.i
|
|
384
400
|
}),
|
|
385
|
-
droppingPosition
|
|
386
|
-
layout: [
|
|
401
|
+
droppingPosition,
|
|
402
|
+
layout: [...layout, {
|
|
403
|
+
...finalDroppingItem,
|
|
387
404
|
x: calculatedPosition.x,
|
|
388
405
|
y: calculatedPosition.y,
|
|
389
406
|
static: false,
|
|
390
407
|
isDraggable: true
|
|
391
|
-
}
|
|
408
|
+
}]
|
|
392
409
|
});
|
|
393
|
-
} else if (
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
410
|
+
} else if (this.state.droppingPosition) {
|
|
411
|
+
const {
|
|
412
|
+
left,
|
|
413
|
+
top
|
|
414
|
+
} = this.state.droppingPosition;
|
|
415
|
+
const shouldUpdatePosition = left != layerX || top != layerY;
|
|
399
416
|
if (shouldUpdatePosition) {
|
|
400
|
-
|
|
401
|
-
droppingPosition
|
|
417
|
+
this.setState({
|
|
418
|
+
droppingPosition
|
|
402
419
|
});
|
|
403
420
|
}
|
|
404
421
|
}
|
|
405
422
|
});
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
_this.setState({
|
|
423
|
+
_defineProperty(this, "removeDroppingPlaceholder", () => {
|
|
424
|
+
const {
|
|
425
|
+
droppingItem,
|
|
426
|
+
cols
|
|
427
|
+
} = this.props;
|
|
428
|
+
const {
|
|
429
|
+
layout
|
|
430
|
+
} = this.state;
|
|
431
|
+
const newLayout = (0, _utils.compact)(layout.filter(l => l.i !== droppingItem.i), (0, _utils.compactType)(this.props), cols, this.props.allowOverlap);
|
|
432
|
+
this.setState({
|
|
417
433
|
layout: newLayout,
|
|
418
434
|
droppingDOMNode: null,
|
|
419
435
|
activeDrag: null,
|
|
420
436
|
droppingPosition: undefined
|
|
421
437
|
});
|
|
422
438
|
});
|
|
423
|
-
|
|
424
|
-
_defineProperty(_assertThisInitialized(_this), "onDragLeave", function (e) {
|
|
439
|
+
_defineProperty(this, "onDragLeave", e => {
|
|
425
440
|
e.preventDefault(); // Prevent any browser native action
|
|
426
|
-
|
|
427
441
|
e.stopPropagation();
|
|
428
|
-
|
|
442
|
+
this.dragEnterCounter--;
|
|
443
|
+
|
|
444
|
+
// onDragLeave can be triggered on each layout's child.
|
|
429
445
|
// But we know that count of dragEnter and dragLeave events
|
|
430
446
|
// will be balanced after leaving the layout's container
|
|
431
447
|
// so we can increase and decrease count of dragEnter and
|
|
432
448
|
// when it'll be equal to 0 we'll remove the placeholder
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
_this.removeDroppingPlaceholder();
|
|
449
|
+
if (this.dragEnterCounter === 0) {
|
|
450
|
+
this.removeDroppingPlaceholder();
|
|
436
451
|
}
|
|
437
452
|
});
|
|
438
|
-
|
|
439
|
-
_defineProperty(_assertThisInitialized(_this), "onDragEnter", function (e) {
|
|
453
|
+
_defineProperty(this, "onDragEnter", e => {
|
|
440
454
|
e.preventDefault(); // Prevent any browser native action
|
|
441
|
-
|
|
442
455
|
e.stopPropagation();
|
|
443
|
-
|
|
456
|
+
this.dragEnterCounter++;
|
|
444
457
|
});
|
|
445
|
-
|
|
446
|
-
_defineProperty(_assertThisInitialized(_this), "onDrop", function (e
|
|
447
|
-
/*: Event*/
|
|
448
|
-
) {
|
|
458
|
+
_defineProperty(this, "onDrop", (e /*: Event*/) => {
|
|
449
459
|
e.preventDefault(); // Prevent any browser native action
|
|
450
|
-
|
|
451
460
|
e.stopPropagation();
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
461
|
+
const {
|
|
462
|
+
droppingItem
|
|
463
|
+
} = this.props;
|
|
464
|
+
const {
|
|
465
|
+
layout
|
|
466
|
+
} = this.state;
|
|
467
|
+
const item = layout.find(l => l.i === droppingItem.i);
|
|
468
|
+
|
|
469
|
+
// reset dragEnter counter on drop
|
|
470
|
+
this.dragEnterCounter = 0;
|
|
471
|
+
this.removeDroppingPlaceholder();
|
|
472
|
+
this.props.onDrop(layout, item, e);
|
|
463
473
|
});
|
|
464
|
-
|
|
465
|
-
return _this;
|
|
466
474
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
key: "shouldComponentUpdate",
|
|
480
|
-
value: function shouldComponentUpdate(nextProps
|
|
481
|
-
/*: Props*/
|
|
482
|
-
, nextState
|
|
483
|
-
/*: State*/
|
|
484
|
-
)
|
|
485
|
-
/*: boolean*/
|
|
486
|
-
{
|
|
487
|
-
return (// NOTE: this is almost always unequal. Therefore the only way to get better performance
|
|
488
|
-
// from SCU is if the user intentionally memoizes children. If they do, and they can
|
|
489
|
-
// handle changes properly, performance will increase.
|
|
490
|
-
this.props.children !== nextProps.children || !(0, _utils.fastRGLPropsEqual)(this.props, nextProps, _lodash.default) || this.state.activeDrag !== nextState.activeDrag || this.state.mounted !== nextState.mounted || this.state.droppingPosition !== nextState.droppingPosition
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
}, {
|
|
494
|
-
key: "componentDidUpdate",
|
|
495
|
-
value: function componentDidUpdate(prevProps
|
|
496
|
-
/*: Props*/
|
|
497
|
-
, prevState
|
|
498
|
-
/*: State*/
|
|
499
|
-
) {
|
|
500
|
-
if (!this.state.activeDrag) {
|
|
501
|
-
var newLayout = this.state.layout;
|
|
502
|
-
var oldLayout = prevState.layout;
|
|
503
|
-
this.onLayoutMaybeChanged(newLayout, oldLayout);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* Calculates a pixel value for the container.
|
|
508
|
-
* @return {String} Container height in pixels.
|
|
509
|
-
*/
|
|
510
|
-
|
|
511
|
-
}, {
|
|
512
|
-
key: "containerHeight",
|
|
513
|
-
value: function containerHeight()
|
|
514
|
-
/*: ?string*/
|
|
515
|
-
{
|
|
516
|
-
if (!this.props.autoSize) return;
|
|
517
|
-
var nbRow = (0, _utils.bottom)(this.state.layout);
|
|
518
|
-
var containerPaddingY = this.props.containerPadding ? this.props.containerPadding[1] : this.props.margin[1];
|
|
519
|
-
return nbRow * this.props.rowHeight + (nbRow - 1) * this.props.margin[1] + containerPaddingY * 2 + "px";
|
|
475
|
+
componentDidMount() {
|
|
476
|
+
this.setState({
|
|
477
|
+
mounted: true
|
|
478
|
+
});
|
|
479
|
+
// Possibly call back with layout on mount. This should be done after correcting the layout width
|
|
480
|
+
// to ensure we don't rerender with the wrong width.
|
|
481
|
+
this.onLayoutMaybeChanged(this.state.layout, this.props.layout);
|
|
482
|
+
}
|
|
483
|
+
static getDerivedStateFromProps(nextProps /*: Props*/, prevState /*: State*/) /*: $Shape<State> | null*/{
|
|
484
|
+
let newLayoutBase;
|
|
485
|
+
if (prevState.activeDrag) {
|
|
486
|
+
return null;
|
|
520
487
|
}
|
|
521
|
-
/**
|
|
522
|
-
* When dragging starts
|
|
523
|
-
* @param {String} i Id of the child
|
|
524
|
-
* @param {Number} x X position of the move
|
|
525
|
-
* @param {Number} y Y position of the move
|
|
526
|
-
* @param {Event} e The mousedown event
|
|
527
|
-
* @param {Element} node The current dragging DOM element
|
|
528
|
-
*/
|
|
529
488
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
,
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
if (!(0, _lodash.default)(oldLayout, newLayout)) {
|
|
540
|
-
this.props.onLayoutChange(newLayout);
|
|
541
|
-
}
|
|
489
|
+
// Legacy support for compactType
|
|
490
|
+
// Allow parent to set layout directly.
|
|
491
|
+
if (!(0, _fastEquals.deepEqual)(nextProps.layout, prevState.propsLayout) || nextProps.compactType !== prevState.compactType) {
|
|
492
|
+
newLayoutBase = nextProps.layout;
|
|
493
|
+
} else if (!(0, _utils.childrenEqual)(nextProps.children, prevState.children)) {
|
|
494
|
+
// If children change, also regenerate the layout. Use our state
|
|
495
|
+
// as the base in case because it may be more up to date than
|
|
496
|
+
// what is in props.
|
|
497
|
+
newLayoutBase = prevState.layout;
|
|
542
498
|
}
|
|
543
|
-
}, {
|
|
544
|
-
key: "placeholder",
|
|
545
|
-
value:
|
|
546
|
-
/**
|
|
547
|
-
* Create a placeholder object.
|
|
548
|
-
* @return {Element} Placeholder div.
|
|
549
|
-
*/
|
|
550
|
-
function placeholder()
|
|
551
|
-
/*: ?ReactElement<any>*/
|
|
552
|
-
{
|
|
553
|
-
var activeDrag = this.state.activeDrag;
|
|
554
|
-
if (!activeDrag) return null;
|
|
555
|
-
var _this$props7 = this.props,
|
|
556
|
-
width = _this$props7.width,
|
|
557
|
-
cols = _this$props7.cols,
|
|
558
|
-
margin = _this$props7.margin,
|
|
559
|
-
containerPadding = _this$props7.containerPadding,
|
|
560
|
-
rowHeight = _this$props7.rowHeight,
|
|
561
|
-
maxRows = _this$props7.maxRows,
|
|
562
|
-
useCSSTransforms = _this$props7.useCSSTransforms,
|
|
563
|
-
transformScale = _this$props7.transformScale; // {...this.state.activeDrag} is pretty slow, actually
|
|
564
499
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
maxRows: maxRows,
|
|
577
|
-
rowHeight: rowHeight,
|
|
578
|
-
isDraggable: false,
|
|
579
|
-
isResizable: false,
|
|
580
|
-
isBounded: false,
|
|
581
|
-
useCSSTransforms: useCSSTransforms,
|
|
582
|
-
transformScale: transformScale
|
|
583
|
-
}, /*#__PURE__*/React.createElement("div", null));
|
|
500
|
+
// We need to regenerate the layout.
|
|
501
|
+
if (newLayoutBase) {
|
|
502
|
+
const newLayout = (0, _utils.synchronizeLayoutWithChildren)(newLayoutBase, nextProps.children, nextProps.cols, (0, _utils.compactType)(nextProps), nextProps.allowOverlap);
|
|
503
|
+
return {
|
|
504
|
+
layout: newLayout,
|
|
505
|
+
// We need to save these props to state for using
|
|
506
|
+
// getDerivedStateFromProps instead of componentDidMount (in which we would get extra rerender)
|
|
507
|
+
compactType: nextProps.compactType,
|
|
508
|
+
children: nextProps.children,
|
|
509
|
+
propsLayout: nextProps.layout
|
|
510
|
+
};
|
|
584
511
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
if (!child || !child.key) return;
|
|
601
|
-
var l = (0, _utils.getLayoutItem)(this.state.layout, String(child.key));
|
|
602
|
-
if (!l) return null;
|
|
603
|
-
var _this$props8 = this.props,
|
|
604
|
-
width = _this$props8.width,
|
|
605
|
-
cols = _this$props8.cols,
|
|
606
|
-
margin = _this$props8.margin,
|
|
607
|
-
containerPadding = _this$props8.containerPadding,
|
|
608
|
-
rowHeight = _this$props8.rowHeight,
|
|
609
|
-
maxRows = _this$props8.maxRows,
|
|
610
|
-
isDraggable = _this$props8.isDraggable,
|
|
611
|
-
isResizable = _this$props8.isResizable,
|
|
612
|
-
isBounded = _this$props8.isBounded,
|
|
613
|
-
useCSSTransforms = _this$props8.useCSSTransforms,
|
|
614
|
-
transformScale = _this$props8.transformScale,
|
|
615
|
-
draggableCancel = _this$props8.draggableCancel,
|
|
616
|
-
draggableHandle = _this$props8.draggableHandle,
|
|
617
|
-
resizeHandles = _this$props8.resizeHandles,
|
|
618
|
-
resizeHandle = _this$props8.resizeHandle;
|
|
619
|
-
var _this$state3 = this.state,
|
|
620
|
-
mounted = _this$state3.mounted,
|
|
621
|
-
droppingPosition = _this$state3.droppingPosition; // Determine user manipulations possible.
|
|
622
|
-
// If an item is static, it can't be manipulated by default.
|
|
623
|
-
// Any properties defined directly on the grid item will take precedence.
|
|
624
|
-
|
|
625
|
-
var draggable = typeof l.isDraggable === "boolean" ? l.isDraggable : !l.static && isDraggable;
|
|
626
|
-
var resizable = typeof l.isResizable === "boolean" ? l.isResizable : !l.static && isResizable;
|
|
627
|
-
var resizeHandlesOptions = l.resizeHandles || resizeHandles; // isBounded set on child if set on parent, and child is not explicitly false
|
|
628
|
-
|
|
629
|
-
var bounded = draggable && isBounded && l.isBounded !== false;
|
|
630
|
-
return /*#__PURE__*/React.createElement(_GridItem.default, {
|
|
631
|
-
containerWidth: width,
|
|
632
|
-
cols: cols,
|
|
633
|
-
margin: margin,
|
|
634
|
-
containerPadding: containerPadding || margin,
|
|
635
|
-
maxRows: maxRows,
|
|
636
|
-
rowHeight: rowHeight,
|
|
637
|
-
cancel: draggableCancel,
|
|
638
|
-
handle: draggableHandle,
|
|
639
|
-
onDragStop: this.onDragStop,
|
|
640
|
-
onDragStart: this.onDragStart,
|
|
641
|
-
onDrag: this.onDrag,
|
|
642
|
-
onResizeStart: this.onResizeStart,
|
|
643
|
-
onResize: this.onResize,
|
|
644
|
-
onResizeStop: this.onResizeStop,
|
|
645
|
-
isDraggable: draggable,
|
|
646
|
-
isResizable: resizable,
|
|
647
|
-
isBounded: bounded,
|
|
648
|
-
useCSSTransforms: useCSSTransforms && mounted,
|
|
649
|
-
usePercentages: !mounted,
|
|
650
|
-
transformScale: transformScale,
|
|
651
|
-
w: l.w,
|
|
652
|
-
h: l.h,
|
|
653
|
-
x: l.x,
|
|
654
|
-
y: l.y,
|
|
655
|
-
i: l.i,
|
|
656
|
-
minH: l.minH,
|
|
657
|
-
minW: l.minW,
|
|
658
|
-
maxH: l.maxH,
|
|
659
|
-
maxW: l.maxW,
|
|
660
|
-
static: l.static,
|
|
661
|
-
droppingPosition: isDroppingItem ? droppingPosition : undefined,
|
|
662
|
-
resizeHandles: resizeHandlesOptions,
|
|
663
|
-
resizeHandle: resizeHandle
|
|
664
|
-
}, child);
|
|
665
|
-
} // Called while dragging an element. Part of browser native drag/drop API.
|
|
666
|
-
// Native event target might be the layout itself, or an element within the layout.
|
|
667
|
-
|
|
668
|
-
}, {
|
|
669
|
-
key: "render",
|
|
670
|
-
value: function render()
|
|
671
|
-
/*: React.Element<"div">*/
|
|
672
|
-
{
|
|
673
|
-
var _this2 = this;
|
|
674
|
-
|
|
675
|
-
var _this$props9 = this.props,
|
|
676
|
-
className = _this$props9.className,
|
|
677
|
-
style = _this$props9.style,
|
|
678
|
-
isDroppable = _this$props9.isDroppable,
|
|
679
|
-
innerRef = _this$props9.innerRef;
|
|
680
|
-
var mergedClassName = (0, _clsx.default)(layoutClassName, className);
|
|
681
|
-
|
|
682
|
-
var mergedStyle = _objectSpread({
|
|
683
|
-
height: this.containerHeight()
|
|
684
|
-
}, style);
|
|
685
|
-
|
|
686
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
687
|
-
ref: innerRef,
|
|
688
|
-
className: mergedClassName,
|
|
689
|
-
style: mergedStyle,
|
|
690
|
-
onDrop: isDroppable ? this.onDrop : _utils.noop,
|
|
691
|
-
onDragLeave: isDroppable ? this.onDragLeave : _utils.noop,
|
|
692
|
-
onDragEnter: isDroppable ? this.onDragEnter : _utils.noop,
|
|
693
|
-
onDragOver: isDroppable ? this.onDragOver : _utils.noop
|
|
694
|
-
}, React.Children.map(this.props.children, function (child) {
|
|
695
|
-
return _this2.processGridItem(child);
|
|
696
|
-
}), isDroppable && this.state.droppingDOMNode && this.processGridItem(this.state.droppingDOMNode, true), this.placeholder());
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
shouldComponentUpdate(nextProps /*: Props*/, nextState /*: State*/) /*: boolean*/{
|
|
515
|
+
return (
|
|
516
|
+
// NOTE: this is almost always unequal. Therefore the only way to get better performance
|
|
517
|
+
// from SCU is if the user intentionally memoizes children. If they do, and they can
|
|
518
|
+
// handle changes properly, performance will increase.
|
|
519
|
+
this.props.children !== nextProps.children || !(0, _utils.fastRGLPropsEqual)(this.props, nextProps, _fastEquals.deepEqual) || this.state.activeDrag !== nextState.activeDrag || this.state.mounted !== nextState.mounted || this.state.droppingPosition !== nextState.droppingPosition
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
componentDidUpdate(prevProps /*: Props*/, prevState /*: State*/) {
|
|
523
|
+
if (!this.state.activeDrag) {
|
|
524
|
+
const newLayout = this.state.layout;
|
|
525
|
+
const oldLayout = prevState.layout;
|
|
526
|
+
this.onLayoutMaybeChanged(newLayout, oldLayout);
|
|
697
527
|
}
|
|
698
|
-
}
|
|
699
|
-
key: "getDerivedStateFromProps",
|
|
700
|
-
value: function getDerivedStateFromProps(nextProps
|
|
701
|
-
/*: Props*/
|
|
702
|
-
, prevState
|
|
703
|
-
/*: State*/
|
|
704
|
-
)
|
|
705
|
-
/*: $Shape<State> | null*/
|
|
706
|
-
{
|
|
707
|
-
var newLayoutBase;
|
|
708
|
-
|
|
709
|
-
if (prevState.activeDrag) {
|
|
710
|
-
return null;
|
|
711
|
-
} // Legacy support for compactType
|
|
712
|
-
// Allow parent to set layout directly.
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
if (!(0, _lodash.default)(nextProps.layout, prevState.propsLayout) || nextProps.compactType !== prevState.compactType) {
|
|
716
|
-
newLayoutBase = nextProps.layout;
|
|
717
|
-
} else if (!(0, _utils.childrenEqual)(nextProps.children, prevState.children)) {
|
|
718
|
-
// If children change, also regenerate the layout. Use our state
|
|
719
|
-
// as the base in case because it may be more up to date than
|
|
720
|
-
// what is in props.
|
|
721
|
-
newLayoutBase = prevState.layout;
|
|
722
|
-
} // We need to regenerate the layout.
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
if (newLayoutBase) {
|
|
726
|
-
var newLayout = (0, _utils.synchronizeLayoutWithChildren)(newLayoutBase, nextProps.children, nextProps.cols, (0, _utils.compactType)(nextProps), nextProps.allowOverlap);
|
|
727
|
-
return {
|
|
728
|
-
layout: newLayout,
|
|
729
|
-
// We need to save these props to state for using
|
|
730
|
-
// getDerivedStateFromProps instead of componentDidMount (in which we would get extra rerender)
|
|
731
|
-
compactType: nextProps.compactType,
|
|
732
|
-
children: nextProps.children,
|
|
733
|
-
propsLayout: nextProps.layout
|
|
734
|
-
};
|
|
735
|
-
}
|
|
528
|
+
}
|
|
736
529
|
|
|
737
|
-
|
|
530
|
+
/**
|
|
531
|
+
* Calculates a pixel value for the container.
|
|
532
|
+
* @return {String} Container height in pixels.
|
|
533
|
+
*/
|
|
534
|
+
containerHeight() /*: ?string*/{
|
|
535
|
+
if (!this.props.autoSize) return;
|
|
536
|
+
const nbRow = (0, _utils.bottom)(this.state.layout);
|
|
537
|
+
const containerPaddingY = this.props.containerPadding ? this.props.containerPadding[1] : this.props.margin[1];
|
|
538
|
+
return nbRow * this.props.rowHeight + (nbRow - 1) * this.props.margin[1] + containerPaddingY * 2 + "px";
|
|
539
|
+
}
|
|
540
|
+
onLayoutMaybeChanged(newLayout /*: Layout*/, oldLayout /*: ?Layout*/) {
|
|
541
|
+
if (!oldLayout) oldLayout = this.state.layout;
|
|
542
|
+
if (!(0, _fastEquals.deepEqual)(oldLayout, newLayout)) {
|
|
543
|
+
this.props.onLayoutChange(newLayout);
|
|
738
544
|
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Create a placeholder object.
|
|
548
|
+
* @return {Element} Placeholder div.
|
|
549
|
+
*/
|
|
550
|
+
placeholder() /*: ?ReactElement<any>*/{
|
|
551
|
+
const {
|
|
552
|
+
activeDrag
|
|
553
|
+
} = this.state;
|
|
554
|
+
if (!activeDrag) return null;
|
|
555
|
+
const {
|
|
556
|
+
width,
|
|
557
|
+
cols,
|
|
558
|
+
margin,
|
|
559
|
+
containerPadding,
|
|
560
|
+
rowHeight,
|
|
561
|
+
maxRows,
|
|
562
|
+
useCSSTransforms,
|
|
563
|
+
transformScale
|
|
564
|
+
} = this.props;
|
|
565
|
+
|
|
566
|
+
// {...this.state.activeDrag} is pretty slow, actually
|
|
567
|
+
return /*#__PURE__*/React.createElement(_GridItem.default, {
|
|
568
|
+
w: activeDrag.w,
|
|
569
|
+
h: activeDrag.h,
|
|
570
|
+
x: activeDrag.x,
|
|
571
|
+
y: activeDrag.y,
|
|
572
|
+
i: activeDrag.i,
|
|
573
|
+
className: "react-grid-placeholder ".concat(this.state.resizing ? "placeholder-resizing" : ""),
|
|
574
|
+
containerWidth: width,
|
|
575
|
+
cols: cols,
|
|
576
|
+
margin: margin,
|
|
577
|
+
containerPadding: containerPadding || margin,
|
|
578
|
+
maxRows: maxRows,
|
|
579
|
+
rowHeight: rowHeight,
|
|
580
|
+
isDraggable: false,
|
|
581
|
+
isResizable: false,
|
|
582
|
+
isBounded: false,
|
|
583
|
+
useCSSTransforms: useCSSTransforms,
|
|
584
|
+
transformScale: transformScale
|
|
585
|
+
}, /*#__PURE__*/React.createElement("div", null));
|
|
586
|
+
}
|
|
743
587
|
|
|
588
|
+
/**
|
|
589
|
+
* Given a grid item, set its style attributes & surround in a <Draggable>.
|
|
590
|
+
* @param {Element} child React element.
|
|
591
|
+
* @return {Element} Element wrapped in draggable and properly placed.
|
|
592
|
+
*/
|
|
593
|
+
processGridItem(child /*: ReactElement<any>*/, isDroppingItem /*: boolean*/) /*: ?ReactElement<any>*/{
|
|
594
|
+
if (!child || !child.key) return;
|
|
595
|
+
const l = (0, _utils.getLayoutItem)(this.state.layout, String(child.key));
|
|
596
|
+
if (!l) return null;
|
|
597
|
+
const {
|
|
598
|
+
width,
|
|
599
|
+
cols,
|
|
600
|
+
margin,
|
|
601
|
+
containerPadding,
|
|
602
|
+
rowHeight,
|
|
603
|
+
maxRows,
|
|
604
|
+
isDraggable,
|
|
605
|
+
isResizable,
|
|
606
|
+
isBounded,
|
|
607
|
+
useCSSTransforms,
|
|
608
|
+
transformScale,
|
|
609
|
+
draggableCancel,
|
|
610
|
+
draggableHandle,
|
|
611
|
+
resizeHandles,
|
|
612
|
+
resizeHandle
|
|
613
|
+
} = this.props;
|
|
614
|
+
const {
|
|
615
|
+
mounted,
|
|
616
|
+
droppingPosition
|
|
617
|
+
} = this.state;
|
|
618
|
+
|
|
619
|
+
// Determine user manipulations possible.
|
|
620
|
+
// If an item is static, it can't be manipulated by default.
|
|
621
|
+
// Any properties defined directly on the grid item will take precedence.
|
|
622
|
+
const draggable = typeof l.isDraggable === "boolean" ? l.isDraggable : !l.static && isDraggable;
|
|
623
|
+
const resizable = typeof l.isResizable === "boolean" ? l.isResizable : !l.static && isResizable;
|
|
624
|
+
const resizeHandlesOptions = l.resizeHandles || resizeHandles;
|
|
625
|
+
|
|
626
|
+
// isBounded set on child if set on parent, and child is not explicitly false
|
|
627
|
+
const bounded = draggable && isBounded && l.isBounded !== false;
|
|
628
|
+
return /*#__PURE__*/React.createElement(_GridItem.default, {
|
|
629
|
+
containerWidth: width,
|
|
630
|
+
cols: cols,
|
|
631
|
+
margin: margin,
|
|
632
|
+
containerPadding: containerPadding || margin,
|
|
633
|
+
maxRows: maxRows,
|
|
634
|
+
rowHeight: rowHeight,
|
|
635
|
+
cancel: draggableCancel,
|
|
636
|
+
handle: draggableHandle,
|
|
637
|
+
onDragStop: this.onDragStop,
|
|
638
|
+
onDragStart: this.onDragStart,
|
|
639
|
+
onDrag: this.onDrag,
|
|
640
|
+
onResizeStart: this.onResizeStart,
|
|
641
|
+
onResize: this.onResize,
|
|
642
|
+
onResizeStop: this.onResizeStop,
|
|
643
|
+
isDraggable: draggable,
|
|
644
|
+
isResizable: resizable,
|
|
645
|
+
isBounded: bounded,
|
|
646
|
+
useCSSTransforms: useCSSTransforms && mounted,
|
|
647
|
+
usePercentages: !mounted,
|
|
648
|
+
transformScale: transformScale,
|
|
649
|
+
w: l.w,
|
|
650
|
+
h: l.h,
|
|
651
|
+
x: l.x,
|
|
652
|
+
y: l.y,
|
|
653
|
+
i: l.i,
|
|
654
|
+
minH: l.minH,
|
|
655
|
+
minW: l.minW,
|
|
656
|
+
maxH: l.maxH,
|
|
657
|
+
maxW: l.maxW,
|
|
658
|
+
static: l.static,
|
|
659
|
+
droppingPosition: isDroppingItem ? droppingPosition : undefined,
|
|
660
|
+
resizeHandles: resizeHandlesOptions,
|
|
661
|
+
resizeHandle: resizeHandle
|
|
662
|
+
}, child);
|
|
663
|
+
}
|
|
664
|
+
render() /*: React.Element<"div">*/{
|
|
665
|
+
const {
|
|
666
|
+
className,
|
|
667
|
+
style,
|
|
668
|
+
isDroppable,
|
|
669
|
+
innerRef
|
|
670
|
+
} = this.props;
|
|
671
|
+
const mergedClassName = (0, _clsx.default)(layoutClassName, className);
|
|
672
|
+
const mergedStyle = {
|
|
673
|
+
height: this.containerHeight(),
|
|
674
|
+
...style
|
|
675
|
+
};
|
|
676
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
677
|
+
ref: innerRef,
|
|
678
|
+
className: mergedClassName,
|
|
679
|
+
style: mergedStyle,
|
|
680
|
+
onDrop: isDroppable ? this.onDrop : _utils.noop,
|
|
681
|
+
onDragLeave: isDroppable ? this.onDragLeave : _utils.noop,
|
|
682
|
+
onDragEnter: isDroppable ? this.onDragEnter : _utils.noop,
|
|
683
|
+
onDragOver: isDroppable ? this.onDragOver : _utils.noop
|
|
684
|
+
}, React.Children.map(this.props.children, child => this.processGridItem(child)), isDroppable && this.state.droppingDOMNode && this.processGridItem(this.state.droppingDOMNode, true), this.placeholder());
|
|
685
|
+
}
|
|
686
|
+
}
|
|
744
687
|
exports.default = ReactGridLayout;
|
|
745
|
-
|
|
688
|
+
// TODO publish internal ReactClass displayName transform
|
|
746
689
|
_defineProperty(ReactGridLayout, "displayName", "ReactGridLayout");
|
|
747
|
-
|
|
690
|
+
// Refactored to another module to make way for preval
|
|
748
691
|
_defineProperty(ReactGridLayout, "propTypes", _ReactGridLayoutPropTypes.default);
|
|
749
|
-
|
|
750
692
|
_defineProperty(ReactGridLayout, "defaultProps", {
|
|
751
693
|
autoSize: true,
|
|
752
694
|
cols: 12,
|