Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -1,24 +1,24 @@
'use strict';
"use strict";
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _react = require('react');
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes = require("prop-types");
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactDraggable = require('react-draggable');
var _reactDraggable = require("react-draggable");
var _reactResizable = require('react-resizable');
var _reactResizable = require("react-resizable");
var _utils = require('./utils');
var _utils = require("./utils");
var _classnames = require('classnames');
var _classnames = require("classnames");
var _classnames2 = _interopRequireDefault(_classnames);
@@ -48,7 +48,7 @@ var GridItem = function (_React$Component) {
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
resizing: null,
dragging: null,
className: ''
className: ""
}, _temp), _possibleConstructorReturn(_this, _ret);
}
@@ -197,17 +197,16 @@ var GridItem = function (_React$Component) {
// CSS Transforms support (default)
if (useCSSTransforms) {
style = (0, _utils.setTransform)(pos);
}
// top,left (slow)
else {
style = (0, _utils.setTopLeft)(pos);
} else {
// top,left (slow)
style = (0, _utils.setTopLeft)(pos);
// This is used for server rendering.
if (usePercentages) {
style.left = (0, _utils.perc)(pos.left / containerWidth);
style.width = (0, _utils.perc)(pos.width / containerWidth);
}
// This is used for server rendering.
if (usePercentages) {
style.left = (0, _utils.perc)(pos.left / containerWidth);
style.width = (0, _utils.perc)(pos.width / containerWidth);
}
}
return style;
};
@@ -223,11 +222,12 @@ var GridItem = function (_React$Component) {
return _react2.default.createElement(
_reactDraggable.DraggableCore,
{
onStart: this.onDragHandler('onDragStart'),
onDrag: this.onDragHandler('onDrag'),
onStop: this.onDragHandler('onDragStop'),
onStart: this.onDragHandler("onDragStart"),
onDrag: this.onDragHandler("onDrag"),
onStop: this.onDragHandler("onDragStop"),
handle: this.props.handle,
cancel: ".react-resizable-handle" + (this.props.cancel ? "," + this.props.cancel : "") },
cancel: ".react-resizable-handle" + (this.props.cancel ? "," + this.props.cancel : "")
},
child
);
};
@@ -265,9 +265,10 @@ var GridItem = function (_React$Component) {
height: position.height,
minConstraints: minConstraints,
maxConstraints: maxConstraints,
onResizeStop: this.onResizeHandler('onResizeStop'),
onResizeStart: this.onResizeHandler('onResizeStart'),
onResize: this.onResizeHandler('onResize') },
onResizeStop: this.onResizeHandler("onResizeStop"),
onResizeStart: this.onResizeHandler("onResizeStart"),
onResize: this.onResizeHandler("onResize")
},
child
);
};
@@ -297,37 +298,40 @@ var GridItem = function (_React$Component) {
// Get new XY
switch (handlerName) {
case 'onDragStart':
case "onDragStart":
{
// ToDo this wont work on nested parents
var parentRect = node.offsetParent.getBoundingClientRect();
// TODO: this wont work on nested parents
var offsetParent = node.offsetParent;
if (!offsetParent) return;
var parentRect = offsetParent.getBoundingClientRect();
var clientRect = node.getBoundingClientRect();
newPosition.left = clientRect.left - parentRect.left + node.offsetParent.scrollLeft;
newPosition.top = clientRect.top - parentRect.top + node.offsetParent.scrollTop;
newPosition.left = clientRect.left - parentRect.left + offsetParent.scrollLeft;
newPosition.top = clientRect.top - parentRect.top + offsetParent.scrollTop;
_this2.setState({ dragging: newPosition });
break;
}
case 'onDrag':
if (!_this2.state.dragging) throw new Error('onDrag called before onDragStart.');
case "onDrag":
if (!_this2.state.dragging) throw new Error("onDrag called before onDragStart.");
newPosition.left = _this2.state.dragging.left + deltaX;
newPosition.top = _this2.state.dragging.top + deltaY;
_this2.setState({ dragging: newPosition });
break;
case 'onDragStop':
if (!_this2.state.dragging) throw new Error('onDragEnd called before onDragStart.');
case "onDragStop":
if (!_this2.state.dragging) throw new Error("onDragEnd called before onDragStart.");
newPosition.left = _this2.state.dragging.left;
newPosition.top = _this2.state.dragging.top;
_this2.setState({ dragging: null });
break;
default:
throw new Error('onDragHandler called with unrecognized handlerName: ' + handlerName);
throw new Error("onDragHandler called with unrecognized handlerName: " + handlerName);
}
var _calcXY = _this2.calcXY(newPosition.top, newPosition.left),
x = _calcXY.x,
y = _calcXY.y;
handler.call(_this2, _this2.props.i, x, y, { e: e, node: node, newPosition: newPosition });
return handler.call(_this2, _this2.props.i, x, y, { e: e, node: node, newPosition: newPosition });
};
};
@@ -376,7 +380,7 @@ var GridItem = function (_React$Component) {
w = Math.max(Math.min(w, maxW), minW);
h = Math.max(Math.min(h, maxH), minH);
_this3.setState({ resizing: handlerName === 'onResizeStop' ? null : size });
_this3.setState({ resizing: handlerName === "onResizeStop" ? null : size });
handler.call(_this3, i, w, h, { e: e, node: node, size: size });
};
@@ -398,11 +402,11 @@ var GridItem = function (_React$Component) {
// Create the child element. We clone the existing element but modify its className and style.
var newChild = _react2.default.cloneElement(child, {
className: (0, _classnames2.default)('react-grid-item', child.props.className, this.props.className, {
className: (0, _classnames2.default)("react-grid-item", child.props.className, this.props.className, {
static: this.props.static,
resizing: Boolean(this.state.resizing),
'react-draggable': isDraggable,
'react-draggable-dragging': Boolean(this.state.dragging),
"react-draggable": isDraggable,
"react-draggable-dragging": Boolean(this.state.dragging),
cssTransforms: useCSSTransforms
}),
// We can set the width and height on the child, but unfortunately we can't set the position.
@@ -442,26 +446,26 @@ GridItem.propTypes = {
// All optional
minW: function minW(props, propName) {
var value = props[propName];
if (typeof value !== 'number') return new Error('minWidth not Number');
if (value > props.w || value > props.maxW) return new Error('minWidth larger than item width/maxWidth');
if (typeof value !== "number") return new Error("minWidth not Number");
if (value > props.w || value > props.maxW) return new Error("minWidth larger than item width/maxWidth");
},
maxW: function maxW(props, propName) {
var value = props[propName];
if (typeof value !== 'number') return new Error('maxWidth not Number');
if (value < props.w || value < props.minW) return new Error('maxWidth smaller than item width/minWidth');
if (typeof value !== "number") return new Error("maxWidth not Number");
if (value < props.w || value < props.minW) return new Error("maxWidth smaller than item width/minWidth");
},
minH: function minH(props, propName) {
var value = props[propName];
if (typeof value !== 'number') return new Error('minHeight not Number');
if (value > props.h || value > props.maxH) return new Error('minHeight larger than item height/maxHeight');
if (typeof value !== "number") return new Error("minHeight not Number");
if (value > props.h || value > props.maxH) return new Error("minHeight larger than item height/maxHeight");
},
maxH: function maxH(props, propName) {
var value = props[propName];
if (typeof value !== 'number') return new Error('maxHeight not Number');
if (value < props.h || value < props.minH) return new Error('maxHeight smaller than item height/minHeight');
if (typeof value !== "number") return new Error("maxHeight not Number");
if (value < props.h || value < props.minH) return new Error("maxHeight smaller than item height/minHeight");
},
// ID is nice to have for callbacks
@@ -491,9 +495,9 @@ GridItem.propTypes = {
cancel: _propTypes2.default.string
};
GridItem.defaultProps = {
className: '',
cancel: '',
handle: '',
className: "",
cancel: "",
handle: "",
minH: 1,
minW: 1,
maxH: Infinity,