Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,265 @@
'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 _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactDraggable = require('react-draggable');
var _cloneElement = require('./cloneElement');
var _cloneElement2 = _interopRequireDefault(_cloneElement);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Resizable = function (_React$Component) {
_inherits(Resizable, _React$Component);
function Resizable() {
var _temp, _this, _ret;
_classCallCheck(this, Resizable);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
resizing: false,
width: _this.props.width, height: _this.props.height,
slackW: 0, slackH: 0
}, _temp), _possibleConstructorReturn(_this, _ret);
}
Resizable.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
// If parent changes height/width, set that in our state.
if (!this.state.resizing && (nextProps.width !== this.props.width || nextProps.height !== this.props.height)) {
this.setState({
width: nextProps.width,
height: nextProps.height
});
}
};
Resizable.prototype.lockAspectRatio = function lockAspectRatio(width, height, aspectRatio) {
height = width / aspectRatio;
width = height * aspectRatio;
return [width, height];
};
// If you do this, be careful of constraints
Resizable.prototype.runConstraints = function runConstraints(width, height) {
var _ref = [this.props.minConstraints, this.props.maxConstraints],
min = _ref[0],
max = _ref[1];
if (this.props.lockAspectRatio) {
var ratio = this.state.width / this.state.height;
height = width / ratio;
width = height * ratio;
}
if (!min && !max) return [width, height];
var oldW = width,
oldH = height;
// Add slack to the values used to calculate bound position. This will ensure that if
// we start removing slack, the element won't react to it right away until it's been
// completely removed.
var _state = this.state,
slackW = _state.slackW,
slackH = _state.slackH;
width += slackW;
height += slackH;
if (min) {
width = Math.max(min[0], width);
height = Math.max(min[1], height);
}
if (max) {
width = Math.min(max[0], width);
height = Math.min(max[1], height);
}
// If the numbers changed, we must have introduced some slack. Record it for the next iteration.
slackW += oldW - width;
slackH += oldH - height;
if (slackW !== this.state.slackW || slackH !== this.state.slackH) {
this.setState({ slackW: slackW, slackH: slackH });
}
return [width, height];
};
/**
* Wrapper around drag events to provide more useful data.
*
* @param {String} handlerName Handler name to wrap.
* @return {Function} Handler function.
*/
Resizable.prototype.resizeHandler = function resizeHandler(handlerName) {
var _this2 = this;
return function (e, _ref2) {
var node = _ref2.node,
deltaX = _ref2.deltaX,
deltaY = _ref2.deltaY;
// Axis restrictions
var canDragX = _this2.props.axis === 'both' || _this2.props.axis === 'x';
var canDragY = _this2.props.axis === 'both' || _this2.props.axis === 'y';
// Update w/h
var width = _this2.state.width + (canDragX ? deltaX : 0);
var height = _this2.state.height + (canDragY ? deltaY : 0);
// Early return if no change
var widthChanged = width !== _this2.state.width,
heightChanged = height !== _this2.state.height;
if (handlerName === 'onResize' && !widthChanged && !heightChanged) return;
// Set the appropriate state for this handler.
var _runConstraints = _this2.runConstraints(width, height);
width = _runConstraints[0];
height = _runConstraints[1];
var newState = {};
if (handlerName === 'onResizeStart') {
newState.resizing = true;
} else if (handlerName === 'onResizeStop') {
newState.resizing = false;
newState.slackW = newState.slackH = 0;
} else {
// Early return if no change after constraints
if (width === _this2.state.width && height === _this2.state.height) return;
newState.width = width;
newState.height = height;
}
var hasCb = typeof _this2.props[handlerName] === 'function';
if (hasCb) {
if (typeof e.persist === 'function') e.persist();
_this2.setState(newState, function () {
return _this2.props[handlerName](e, { node: node, size: { width: width, height: height } });
});
} else {
_this2.setState(newState);
}
};
};
Resizable.prototype.render = function render() {
// eslint-disable-next-line no-unused-vars
var _props = this.props,
children = _props.children,
draggableOpts = _props.draggableOpts,
width = _props.width,
height = _props.height,
handleSize = _props.handleSize,
lockAspectRatio = _props.lockAspectRatio,
axis = _props.axis,
minConstraints = _props.minConstraints,
maxConstraints = _props.maxConstraints,
onResize = _props.onResize,
onResizeStop = _props.onResizeStop,
onResizeStart = _props.onResizeStart,
p = _objectWithoutProperties(_props, ['children', 'draggableOpts', 'width', 'height', 'handleSize', 'lockAspectRatio', 'axis', 'minConstraints', 'maxConstraints', 'onResize', 'onResizeStop', 'onResizeStart']);
var className = p.className ? p.className + ' react-resizable' : 'react-resizable';
// What we're doing here is getting the child of this element, and cloning it with this element's props.
// We are then defining its children as:
// Its original children (resizable's child's children), and
// A draggable handle.
return (0, _cloneElement2.default)(children, _extends({}, p, {
className: className,
children: [children.props.children, _react2.default.createElement(
_reactDraggable.DraggableCore,
_extends({}, draggableOpts, {
key: 'resizableHandle',
onStop: this.resizeHandler('onResizeStop'),
onStart: this.resizeHandler('onResizeStart'),
onDrag: this.resizeHandler('onResize')
}),
_react2.default.createElement('span', { className: 'react-resizable-handle' })
)]
}));
};
return Resizable;
}(_react2.default.Component);
Resizable.propTypes = {
//
// Required Props
//
// Require that one and only one child be present.
children: _propTypes2.default.element.isRequired,
// Initial w/h
width: _propTypes2.default.number.isRequired,
height: _propTypes2.default.number.isRequired,
//
// Optional props
//
// If you change this, be sure to update your css
handleSize: _propTypes2.default.array,
// If true, will only allow width/height to move in lockstep
lockAspectRatio: _propTypes2.default.bool,
// Restricts resizing to a particular axis (default: 'both')
// 'both' - allows resizing by width or height
// 'x' - only allows the width to be changed
// 'y' - only allows the height to be changed
// 'none' - disables resizing altogether
axis: _propTypes2.default.oneOf(['both', 'x', 'y', 'none']),
// Min/max size
minConstraints: _propTypes2.default.arrayOf(_propTypes2.default.number),
maxConstraints: _propTypes2.default.arrayOf(_propTypes2.default.number),
// Callbacks
onResizeStop: _propTypes2.default.func,
onResizeStart: _propTypes2.default.func,
onResize: _propTypes2.default.func,
// These will be passed wholesale to react-draggable's DraggableCore
draggableOpts: _propTypes2.default.object
};
Resizable.defaultProps = {
handleSize: [20, 20],
lockAspectRatio: false,
axis: 'both',
minConstraints: [20, 20],
maxConstraints: [Infinity, Infinity]
};
exports.default = Resizable;

View File

@@ -0,0 +1,232 @@
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import {DraggableCore} from 'react-draggable';
import cloneElement from './cloneElement';
import type {Element as ReactElement, Node as ReactNode} from 'react';
type Axis = 'both' | 'x' | 'y' | 'none';
type State = {
resizing: boolean,
width: number, height: number,
slackW: number, slackH: number
};
type DragCallbackData = {
node: HTMLElement,
x: number, y: number,
deltaX: number, deltaY: number,
lastX: number, lastY: number
};
export type ResizeCallbackData = {
node: HTMLElement,
size: {width: number, height: number}
};
export type Props = {
children: ReactElement<any>,
className?: ?string,
width: number,
height: number,
handleSize: [number, number],
lockAspectRatio: boolean,
axis: Axis,
minConstraints: [number, number],
maxConstraints: [number, number],
onResizeStop?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
onResizeStart?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
onResize?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
draggableOpts?: ?Object
};
export default class Resizable extends React.Component<Props, State> {
static propTypes = {
//
// Required Props
//
// Require that one and only one child be present.
children: PropTypes.element.isRequired,
// Initial w/h
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
//
// Optional props
//
// If you change this, be sure to update your css
handleSize: PropTypes.array,
// If true, will only allow width/height to move in lockstep
lockAspectRatio: PropTypes.bool,
// Restricts resizing to a particular axis (default: 'both')
// 'both' - allows resizing by width or height
// 'x' - only allows the width to be changed
// 'y' - only allows the height to be changed
// 'none' - disables resizing altogether
axis: PropTypes.oneOf(['both', 'x', 'y', 'none']),
// Min/max size
minConstraints: PropTypes.arrayOf(PropTypes.number),
maxConstraints: PropTypes.arrayOf(PropTypes.number),
// Callbacks
onResizeStop: PropTypes.func,
onResizeStart: PropTypes.func,
onResize: PropTypes.func,
// These will be passed wholesale to react-draggable's DraggableCore
draggableOpts: PropTypes.object
};
static defaultProps = {
handleSize: [20, 20],
lockAspectRatio: false,
axis: 'both',
minConstraints: [20, 20],
maxConstraints: [Infinity, Infinity]
};
state: State = {
resizing: false,
width: this.props.width, height: this.props.height,
slackW: 0, slackH: 0
};
componentWillReceiveProps(nextProps: Object) {
// If parent changes height/width, set that in our state.
if (!this.state.resizing &&
(nextProps.width !== this.props.width || nextProps.height !== this.props.height)) {
this.setState({
width: nextProps.width,
height: nextProps.height
});
}
}
lockAspectRatio(width: number, height: number, aspectRatio: number): [number, number] {
height = width / aspectRatio;
width = height * aspectRatio;
return [width, height];
}
// If you do this, be careful of constraints
runConstraints(width: number, height: number): [number, number] {
const [min, max] = [this.props.minConstraints, this.props.maxConstraints];
if (this.props.lockAspectRatio) {
const ratio = this.state.width / this.state.height;
height = width / ratio;
width = height * ratio;
}
if (!min && !max) return [width, height];
const [oldW, oldH] = [width, height];
// Add slack to the values used to calculate bound position. This will ensure that if
// we start removing slack, the element won't react to it right away until it's been
// completely removed.
let {slackW, slackH} = this.state;
width += slackW;
height += slackH;
if (min) {
width = Math.max(min[0], width);
height = Math.max(min[1], height);
}
if (max) {
width = Math.min(max[0], width);
height = Math.min(max[1], height);
}
// If the numbers changed, we must have introduced some slack. Record it for the next iteration.
slackW += (oldW - width);
slackH += (oldH - height);
if (slackW !== this.state.slackW || slackH !== this.state.slackH) {
this.setState({slackW, slackH});
}
return [width, height];
}
/**
* Wrapper around drag events to provide more useful data.
*
* @param {String} handlerName Handler name to wrap.
* @return {Function} Handler function.
*/
resizeHandler(handlerName: string): Function {
return (e: SyntheticEvent<> | MouseEvent, {node, deltaX, deltaY}: DragCallbackData) => {
// Axis restrictions
const canDragX = this.props.axis === 'both' || this.props.axis === 'x';
const canDragY = this.props.axis === 'both' || this.props.axis === 'y';
// Update w/h
let width = this.state.width + (canDragX ? deltaX : 0);
let height = this.state.height + (canDragY ? deltaY : 0);
// Early return if no change
const widthChanged = width !== this.state.width, heightChanged = height !== this.state.height;
if (handlerName === 'onResize' && !widthChanged && !heightChanged) return;
[width, height] = this.runConstraints(width, height);
// Set the appropriate state for this handler.
const newState = {};
if (handlerName === 'onResizeStart') {
newState.resizing = true;
} else if (handlerName === 'onResizeStop') {
newState.resizing = false;
newState.slackW = newState.slackH = 0;
} else {
// Early return if no change after constraints
if (width === this.state.width && height === this.state.height) return;
newState.width = width;
newState.height = height;
}
const hasCb = typeof this.props[handlerName] === 'function';
if (hasCb) {
if (typeof e.persist === 'function') e.persist();
this.setState(newState, () => this.props[handlerName](e, {node, size: {width, height}}));
} else {
this.setState(newState);
}
};
}
render(): ReactNode {
// eslint-disable-next-line no-unused-vars
const {children, draggableOpts, width, height, handleSize,
lockAspectRatio, axis, minConstraints, maxConstraints, onResize,
onResizeStop, onResizeStart, ...p} = this.props;
const className = p.className ?
`${p.className} react-resizable`:
'react-resizable';
// What we're doing here is getting the child of this element, and cloning it with this element's props.
// We are then defining its children as:
// Its original children (resizable's child's children), and
// A draggable handle.
return cloneElement(children, {
...p,
className,
children: [
children.props.children,
<DraggableCore
{...draggableOpts}
key="resizableHandle"
onStop={this.resizeHandler('onResizeStop')}
onStart={this.resizeHandler('onResizeStart')}
onDrag={this.resizeHandler('onResize')}
>
<span className="react-resizable-handle" />
</DraggableCore>
]
});
}
}

View File

@@ -0,0 +1,118 @@
'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 _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _Resizable = require('./Resizable');
var _Resizable2 = _interopRequireDefault(_Resizable);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// An example use of Resizable.
var ResizableBox = function (_React$Component) {
_inherits(ResizableBox, _React$Component);
function ResizableBox() {
var _temp, _this, _ret;
_classCallCheck(this, ResizableBox);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
width: _this.props.width,
height: _this.props.height
}, _this.onResize = function (e, data) {
var size = data.size;
var width = size.width,
height = size.height;
if (_this.props.onResize) {
e.persist && e.persist();
_this.setState(size, function () {
return _this.props.onResize && _this.props.onResize(e, data);
});
} else {
_this.setState(size);
}
}, _temp), _possibleConstructorReturn(_this, _ret);
}
ResizableBox.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
if (nextProps.width !== this.props.width || nextProps.height !== this.props.height) {
this.setState({
width: nextProps.width,
height: nextProps.height
});
}
};
ResizableBox.prototype.render = function render() {
// Basic wrapper around a Resizable instance.
// If you use Resizable directly, you are responsible for updating the child component
// with a new width and height.
var _props = this.props,
handleSize = _props.handleSize,
onResize = _props.onResize,
onResizeStart = _props.onResizeStart,
onResizeStop = _props.onResizeStop,
draggableOpts = _props.draggableOpts,
minConstraints = _props.minConstraints,
maxConstraints = _props.maxConstraints,
lockAspectRatio = _props.lockAspectRatio,
axis = _props.axis,
width = _props.width,
height = _props.height,
props = _objectWithoutProperties(_props, ['handleSize', 'onResize', 'onResizeStart', 'onResizeStop', 'draggableOpts', 'minConstraints', 'maxConstraints', 'lockAspectRatio', 'axis', 'width', 'height']);
return _react2.default.createElement(
_Resizable2.default,
{
handleSize: handleSize,
width: this.state.width,
height: this.state.height,
onResizeStart: onResizeStart,
onResize: this.onResize,
onResizeStop: onResizeStop,
draggableOpts: draggableOpts,
minConstraints: minConstraints,
maxConstraints: maxConstraints,
lockAspectRatio: lockAspectRatio,
axis: axis
},
_react2.default.createElement('div', _extends({ style: { width: this.state.width + 'px', height: this.state.height + 'px' } }, props))
);
};
return ResizableBox;
}(_react2.default.Component);
ResizableBox.propTypes = {
height: _propTypes2.default.number,
width: _propTypes2.default.number
};
ResizableBox.defaultProps = {
handleSize: [20, 20]
};
exports.default = ResizableBox;

View File

@@ -0,0 +1,71 @@
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import Resizable from './Resizable';
import type {Props as ResizableProps, ResizeCallbackData} from './Resizable';
import type {Node as ReactNode} from 'react';
type State = {width: number, height: number};
// An example use of Resizable.
export default class ResizableBox extends React.Component<ResizableProps, State> {
static propTypes = {
height: PropTypes.number,
width: PropTypes.number
};
static defaultProps = {
handleSize: [20,20]
};
state: State = {
width: this.props.width,
height: this.props.height,
};
onResize = (e: SyntheticEvent<>, data: ResizeCallbackData) => {
const {size} = data;
const {width, height} = size;
if (this.props.onResize) {
e.persist && e.persist();
this.setState(size, () => this.props.onResize && this.props.onResize(e, data));
} else {
this.setState(size);
}
};
componentWillReceiveProps(nextProps: ResizableProps) {
if (nextProps.width !== this.props.width || nextProps.height !== this.props.height) {
this.setState({
width: nextProps.width,
height: nextProps.height
});
}
}
render(): ReactNode {
// Basic wrapper around a Resizable instance.
// If you use Resizable directly, you are responsible for updating the child component
// with a new width and height.
const {handleSize, onResize, onResizeStart, onResizeStop, draggableOpts,
minConstraints, maxConstraints, lockAspectRatio, axis, width, height, ...props} = this.props;
return (
<Resizable
handleSize={handleSize}
width={this.state.width}
height={this.state.height}
onResizeStart={onResizeStart}
onResize={this.onResize}
onResizeStop={onResizeStop}
draggableOpts={draggableOpts}
minConstraints={minConstraints}
maxConstraints={maxConstraints}
lockAspectRatio={lockAspectRatio}
axis={axis}
>
<div style={{width: this.state.width + 'px', height: this.state.height + 'px'}} {...props} />
</Resizable>
);
}
}

View File

@@ -0,0 +1,20 @@
'use strict';
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 _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// React.addons.cloneWithProps look-alike that merges style & className.
module.exports = function cloneElement(element, props) {
if (props.style && element.props.style) {
props.style = _extends({}, element.props.style, props.style);
}
if (props.className && element.props.className) {
props.className = element.props.className + ' ' + props.className;
}
return _react2.default.cloneElement(element, props);
};

View File

@@ -0,0 +1,14 @@
// @flow
import React from 'react';
import type {Element as ReactElement} from 'react';
// React.addons.cloneWithProps look-alike that merges style & className.
module.exports = function cloneElement(element: ReactElement<any>, props: Object): ReactElement<any> {
if (props.style && element.props.style) {
props.style = {...element.props.style, ...props.style};
}
if (props.className && element.props.className) {
props.className = `${element.props.className} ${props.className}`;
}
return React.cloneElement(element, props);
};