react-grid-layout
Advanced tools
Comparing version
@@ -252,15 +252,36 @@ "use strict"; | ||
// Short circuit if there is a collision in no rearrangement mode. | ||
if (preventCollision && (0, _utils.getFirstCollision)(layout, _extends({}, l, { w: w, h: h }))) { | ||
return; | ||
// Something like quad tree should be used | ||
// to find collisions faster | ||
var hasCollisions = void 0; | ||
if (preventCollision) { | ||
var collisions = (0, _utils.getAllCollisions)(layout, _extends({}, l, { w: w, h: h })).filter(function (layoutItem) { | ||
return layoutItem.i !== l.i; | ||
}); | ||
hasCollisions = collisions.length > 0; | ||
// If we're colliding, we need adjust the placeholder. | ||
if (hasCollisions) { | ||
// adjust w && h to maximum allowed space | ||
var leastX = Infinity, | ||
leastY = Infinity; | ||
collisions.forEach(function (layoutItem) { | ||
if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x); | ||
if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y); | ||
}); | ||
if (Number.isFinite(leastX)) l.w = leastX - l.x; | ||
if (Number.isFinite(leastY)) l.h = leastY - l.y; | ||
} | ||
} | ||
// Set new width and height. | ||
l.w = w; | ||
l.h = h; | ||
if (!hasCollisions) { | ||
// Set new width and height. | ||
l.w = w; | ||
l.h = h; | ||
} | ||
// Create placeholder element (display only) | ||
var placeholder = { | ||
w: w, | ||
h: h, | ||
w: l.w, | ||
h: l.h, | ||
x: l.x, | ||
@@ -359,3 +380,3 @@ y: l.y, | ||
ReactGridLayout.prototype.processGridItem = function processGridItem(child) { | ||
if (!child.key) return; | ||
if (!child || !child.key) return; | ||
var l = (0, _utils.getLayoutItem)(this.state.layout, String(child.key)); | ||
@@ -362,0 +383,0 @@ if (!l) return null; |
{ | ||
"name": "react-grid-layout", | ||
"version": "0.16.3", | ||
"version": "0.16.4", | ||
"description": "A draggable and resizable grid layout with responsive breakpoints, for React.", | ||
@@ -49,3 +49,3 @@ "main": "index.js", | ||
"babel-eslint": "^8.2.1", | ||
"babel-jest": "^22.1.0", | ||
"babel-jest": "^22.2.2", | ||
"babel-loader": "^7.1.2", | ||
@@ -62,13 +62,13 @@ "babel-plugin-espower": "^2.4.0", | ||
"ejs": "^2.4.1", | ||
"eslint": "^4.16.0", | ||
"eslint-plugin-flowtype": "^2.42.0", | ||
"eslint": "^4.17.0", | ||
"eslint-plugin-flowtype": "^2.44.0", | ||
"eslint-plugin-mocha": "^4.11.0", | ||
"eslint-plugin-react": "^7.6.1", | ||
"exports-loader": "^0.6.4", | ||
"flow-bin": "^0.64.0", | ||
"exports-loader": "^0.7.0", | ||
"flow-bin": "^0.65.0", | ||
"husky": "^0.14.3", | ||
"imports-loader": "^0.7.1", | ||
"jest-cli": "^22.1.4", | ||
"jest-cli": "^22.3.0", | ||
"lint-staged": "^6.1.0", | ||
"lodash": "^4.3.0", | ||
"lodash": "^4.17.5", | ||
"opener": "^1.4.3", | ||
@@ -81,5 +81,5 @@ "power-assert": "^1.4.4", | ||
"react-transform-hmr": "^1.0.2", | ||
"style-loader": "^0.20.1", | ||
"style-loader": "^0.20.2", | ||
"valiquire": "^0.3.0", | ||
"webpack": "^3.10.0", | ||
"webpack": "^3.11.0", | ||
"webpack-dev-server": "^2.11.1" | ||
@@ -86,0 +86,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
175140
0.85%1786
1.08%