react-resizable 3.0.5 → 3.1.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.
@@ -6,47 +6,44 @@ var React = _interopRequireWildcard(require("react"));
6
6
  var _propTypes = _interopRequireDefault(require("prop-types"));
7
7
  var _Resizable = _interopRequireDefault(require("./Resizable"));
8
8
  var _propTypes2 = require("./propTypes");
9
- var _excluded = ["handle", "handleSize", "onResize", "onResizeStart", "onResizeStop", "draggableOpts", "minConstraints", "maxConstraints", "lockAspectRatio", "axis", "width", "height", "resizeHandles", "style", "transformScale"];
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- 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; }
13
- function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
- 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; }
17
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
- 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); }
19
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
20
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
21
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
22
- var ResizableBox = /*#__PURE__*/function (_React$Component) {
23
- _inheritsLoose(ResizableBox, _React$Component);
24
- function ResizableBox() {
25
- var _this;
26
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
27
- args[_key] = arguments[_key];
28
- }
29
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
30
- _this.state = {
31
- width: _this.props.width,
32
- height: _this.props.height,
33
- propsWidth: _this.props.width,
34
- propsHeight: _this.props.height
9
+ const _excluded = ["handle", "handleSize", "onResize", "onResizeStart", "onResizeStop", "draggableOpts", "minConstraints", "maxConstraints", "lockAspectRatio", "axis", "width", "height", "resizeHandles", "style", "transformScale"];
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
13
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
17
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
19
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
20
+ // ElementConfig gives us an object type where all items present in `defaultProps` are made optional.
21
+ // <ResizableBox> does not have defaultProps, so we can use this type to tell Flow that we don't
22
+ // care about that and will handle it in <Resizable> instead.
23
+ // A <ResizableBox> can also have a `style` property.
24
+
25
+ class ResizableBox extends React.Component {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.state = {
29
+ width: this.props.width,
30
+ height: this.props.height,
31
+ propsWidth: this.props.width,
32
+ propsHeight: this.props.height
35
33
  };
36
- _this.onResize = function (e, data) {
37
- var size = data.size;
38
- if (_this.props.onResize) {
39
- e.persist == null ? void 0 : e.persist();
40
- _this.setState(size, function () {
41
- return _this.props.onResize && _this.props.onResize(e, data);
42
- });
34
+ this.onResize = (e, data) => {
35
+ const {
36
+ size
37
+ } = data;
38
+ if (this.props.onResize) {
39
+ e.persist?.();
40
+ this.setState(size, () => this.props.onResize && this.props.onResize(e, data));
43
41
  } else {
44
- _this.setState(size);
42
+ this.setState(size);
45
43
  }
46
44
  };
47
- return _this;
48
45
  }
49
- ResizableBox.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
46
+ static getDerivedStateFromProps(props, state) {
50
47
  // If parent changes height/width, set that in our state.
51
48
  if (state.propsWidth !== props.width || state.propsHeight !== props.height) {
52
49
  return {
@@ -57,29 +54,30 @@ var ResizableBox = /*#__PURE__*/function (_React$Component) {
57
54
  };
58
55
  }
59
56
  return null;
60
- };
61
- var _proto = ResizableBox.prototype;
62
- _proto.render = function render() {
57
+ }
58
+ render() {
63
59
  // Basic wrapper around a Resizable instance.
64
60
  // If you use Resizable directly, you are responsible for updating the child component
65
61
  // with a new width and height.
66
- var _this$props = this.props,
67
- handle = _this$props.handle,
68
- handleSize = _this$props.handleSize,
69
- onResize = _this$props.onResize,
70
- onResizeStart = _this$props.onResizeStart,
71
- onResizeStop = _this$props.onResizeStop,
72
- draggableOpts = _this$props.draggableOpts,
73
- minConstraints = _this$props.minConstraints,
74
- maxConstraints = _this$props.maxConstraints,
75
- lockAspectRatio = _this$props.lockAspectRatio,
76
- axis = _this$props.axis,
77
- width = _this$props.width,
78
- height = _this$props.height,
79
- resizeHandles = _this$props.resizeHandles,
80
- style = _this$props.style,
81
- transformScale = _this$props.transformScale,
82
- props = _objectWithoutPropertiesLoose(_this$props, _excluded);
62
+ const _this$props = this.props,
63
+ {
64
+ handle,
65
+ handleSize,
66
+ onResize,
67
+ onResizeStart,
68
+ onResizeStop,
69
+ draggableOpts,
70
+ minConstraints,
71
+ maxConstraints,
72
+ lockAspectRatio,
73
+ axis,
74
+ width,
75
+ height,
76
+ resizeHandles,
77
+ style,
78
+ transformScale
79
+ } = _this$props,
80
+ props = _objectWithoutProperties(_this$props, _excluded);
83
81
  return /*#__PURE__*/React.createElement(_Resizable.default, {
84
82
  axis: axis,
85
83
  draggableOpts: draggableOpts,
@@ -101,9 +99,8 @@ var ResizableBox = /*#__PURE__*/function (_React$Component) {
101
99
  height: this.state.height + 'px'
102
100
  })
103
101
  })));
104
- };
105
- return ResizableBox;
106
- }(React.Component);
102
+ }
103
+ }
107
104
  exports.default = ResizableBox;
108
105
  // PropTypes are identical to <Resizable>, except that children are not strictly required to be present.
109
106
  ResizableBox.propTypes = _objectSpread(_objectSpread({}, _propTypes2.resizableProps), {}, {
@@ -4,8 +4,10 @@ exports.__esModule = true;
4
4
  exports.resizableProps = void 0;
5
5
  var _propTypes = _interopRequireDefault(require("prop-types"));
6
6
  var _reactDraggable = require("react-draggable");
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
- var resizableProps = {
7
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
+ /* global Element */
9
+ // <Resizable>
10
+ const resizableProps = exports.resizableProps = {
9
11
  /*
10
12
  * Restricts resizing to a particular axis (default: 'both')
11
13
  * 'both' - allows resizing by width or height
@@ -28,7 +30,7 @@ var resizableProps = {
28
30
  children: _propTypes.default.node,
29
31
  disabled: _propTypes.default.bool,
30
32
  enableUserSelectHack: _propTypes.default.bool,
31
- offsetParent: _propTypes.default.node,
33
+ offsetParent: _propTypes.default.instanceOf(Element),
32
34
  grid: _propTypes.default.arrayOf(_propTypes.default.number),
33
35
  handle: _propTypes.default.string,
34
36
  nodeRef: _propTypes.default.object,
@@ -41,17 +43,16 @@ var resizableProps = {
41
43
  /*
42
44
  * Initial height
43
45
  * */
44
- height: function height() {
46
+ height: function () {
45
47
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
46
48
  args[_key] = arguments[_key];
47
49
  }
48
- var props = args[0];
50
+ const [props] = args;
49
51
  // Required if resizing height or both
50
52
  if (props.axis === 'both' || props.axis === 'y') {
51
- var _PropTypes$number;
52
- return (_PropTypes$number = _propTypes.default.number).isRequired.apply(_PropTypes$number, args);
53
+ return _propTypes.default.number.isRequired(...args);
53
54
  }
54
- return _propTypes.default.number.apply(_propTypes.default, args);
55
+ return _propTypes.default.number(...args);
55
56
  },
56
57
  /*
57
58
  * Customize cursor resize handle
@@ -101,17 +102,15 @@ var resizableProps = {
101
102
  /*
102
103
  * Initial width
103
104
  */
104
- width: function width() {
105
+ width: function () {
105
106
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
106
107
  args[_key2] = arguments[_key2];
107
108
  }
108
- var props = args[0];
109
+ const [props] = args;
109
110
  // Required if resizing width or both
110
111
  if (props.axis === 'both' || props.axis === 'x') {
111
- var _PropTypes$number2;
112
- return (_PropTypes$number2 = _propTypes.default.number).isRequired.apply(_PropTypes$number2, args);
112
+ return _propTypes.default.number.isRequired(...args);
113
113
  }
114
- return _propTypes.default.number.apply(_propTypes.default, args);
114
+ return _propTypes.default.number(...args);
115
115
  }
116
- };
117
- exports.resizableProps = resizableProps;
116
+ };
@@ -1,4 +1,5 @@
1
1
  // @flow
2
+ /* global Element */
2
3
  import PropTypes from 'prop-types';
3
4
  import {DraggableCore} from "react-draggable";
4
5
  import type {Element as ReactElement, ElementConfig} from 'react';
@@ -75,7 +76,7 @@ export const resizableProps: Object = {
75
76
  children: PropTypes.node,
76
77
  disabled: PropTypes.bool,
77
78
  enableUserSelectHack: PropTypes.bool,
78
- offsetParent: PropTypes.node,
79
+ offsetParent: PropTypes.instanceOf(Element),
79
80
  grid: PropTypes.arrayOf(PropTypes.number),
80
81
  handle: PropTypes.string,
81
82
  nodeRef: PropTypes.object,
package/build/utils.js CHANGED
@@ -3,19 +3,19 @@
3
3
  exports.__esModule = true;
4
4
  exports.cloneElement = cloneElement;
5
5
  var _react = _interopRequireDefault(require("react"));
6
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
- 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; }
10
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
- 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); }
6
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
11
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
12
12
  // React.addons.cloneWithProps look-alike that merges style & className.
13
13
  function cloneElement(element, props) {
14
14
  if (props.style && element.props.style) {
15
15
  props.style = _objectSpread(_objectSpread({}, element.props.style), props.style);
16
16
  }
17
17
  if (props.className && element.props.className) {
18
- props.className = element.props.className + " " + props.className;
18
+ props.className = `${element.props.className} ${props.className}`;
19
19
  }
20
20
  return /*#__PURE__*/_react.default.cloneElement(element, props);
21
21
  }