react-resizable 1.8.0 → 1.11.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.
Files changed (48) hide show
  1. package/.babelrc +10 -4
  2. package/.browserslistrc +3 -0
  3. package/.eslintrc +10 -6
  4. package/.flowconfig +10 -10
  5. package/CHANGELOG.md +61 -32
  6. package/README.md +14 -4
  7. package/__tests__/Resizable.test.js +245 -0
  8. package/__tests__/ResizableBox.test.js +99 -0
  9. package/__tests__/__snapshots__/Resizable.test.js.snap +29 -0
  10. package/__tests__/__snapshots__/ResizableBox.test.js.snap +23 -0
  11. package/build/Resizable.js +172 -208
  12. package/build/Resizable.js.flow +99 -178
  13. package/build/ResizableBox.js +95 -79
  14. package/build/ResizableBox.js.flow +58 -33
  15. package/build/propTypes.js +112 -0
  16. package/build/propTypes.js.flow +135 -0
  17. package/build/utils.js +27 -0
  18. package/build/{cloneElement.js.flow → utils.js.flow} +2 -2
  19. package/coverage/clover.xml +107 -0
  20. package/coverage/coverage-final.json +5 -0
  21. package/coverage/lcov-report/Resizable.js.html +665 -0
  22. package/coverage/lcov-report/ResizableBox.js.html +374 -0
  23. package/coverage/lcov-report/base.css +224 -0
  24. package/coverage/lcov-report/block-navigation.js +79 -0
  25. package/coverage/lcov-report/favicon.png +0 -0
  26. package/coverage/lcov-report/flow-typed/npm/index.html +111 -0
  27. package/coverage/lcov-report/flow-typed/npm/jest_v26.x.x.js.html +3734 -0
  28. package/coverage/lcov-report/index.html +156 -0
  29. package/coverage/lcov-report/prettify.css +1 -0
  30. package/coverage/lcov-report/prettify.js +2 -0
  31. package/coverage/lcov-report/propTypes.js.html +485 -0
  32. package/coverage/lcov-report/react-resizable/dist/bundle.js.html +95 -0
  33. package/coverage/lcov-report/react-resizable/dist/index.html +111 -0
  34. package/coverage/lcov-report/react-resizable/flow-typed/npm/index.html +111 -0
  35. package/coverage/lcov-report/react-resizable/flow-typed/npm/jest_v26.x.x.js.html +3734 -0
  36. package/coverage/lcov-report/react-resizable/index.html +111 -0
  37. package/coverage/lcov-report/react-resizable/index.js.html +101 -0
  38. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  39. package/coverage/lcov-report/sorter.js +170 -0
  40. package/coverage/lcov-report/utils.js.html +122 -0
  41. package/coverage/lcov.info +233 -0
  42. package/dist/bundle.js +6 -0
  43. package/flow-typed/npm/jest_v26.x.x.js +1218 -0
  44. package/package.json +34 -26
  45. package/setupTests/enzyme.js +4 -0
  46. package/.github/ISSUE_TEMPLATE.md +0 -23
  47. package/.github/PULL_REQUEST_TEMPLATE.md +0 -5
  48. package/build/cloneElement.js +0 -20
@@ -1,103 +1,13 @@
1
1
  // @flow
2
2
  import React from 'react';
3
- import PropTypes from 'prop-types';
3
+ import type {Node as ReactNode} from 'react';
4
4
  import {DraggableCore} from 'react-draggable';
5
- import cloneElement from './cloneElement';
6
- import type {Element as ReactElement, Node as ReactNode} from 'react';
5
+ import {cloneElement} from './utils';
6
+ import {resizableProps} from "./propTypes";
7
+ import type {ResizeHandleAxis, Props, ResizableState, DragCallbackData} from './propTypes';
7
8
 
8
- type Axis = 'both' | 'x' | 'y' | 'none';
9
- type ResizeHandle = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne';
10
- type State = {
11
- resizing: boolean,
12
- width: number, height: number,
13
- slackW: number, slackH: number
14
- };
15
- type DragCallbackData = {
16
- node: HTMLElement,
17
- x: number, y: number,
18
- deltaX: number, deltaY: number,
19
- lastX: number, lastY: number
20
- };
21
- export type ResizeCallbackData = {
22
- node: HTMLElement,
23
- size: {width: number, height: number},
24
- handle: ResizeHandle
25
- };
26
- export type Props = {
27
- children: ReactElement<any>,
28
- className?: ?string,
29
- width: number,
30
- height: number,
31
- handle: ReactElement<any> | (resizeHandle: ResizeHandle) => ReactElement<any>,
32
- handleSize: [number, number],
33
- lockAspectRatio: boolean,
34
- axis: Axis,
35
- minConstraints: [number, number],
36
- maxConstraints: [number, number],
37
- onResizeStop?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
38
- onResizeStart?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
39
- onResize?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
40
- draggableOpts?: ?Object,
41
- resizeHandles: ResizeHandle[]
42
- };
43
-
44
- export default class Resizable extends React.Component<Props, State> {
45
- static propTypes = {
46
- //
47
- // Required Props
48
- //
49
-
50
- // Require that one and only one child be present.
51
- children: PropTypes.element.isRequired,
52
-
53
- // Initial w/h
54
- width: PropTypes.number.isRequired,
55
- height: PropTypes.number.isRequired,
56
-
57
- //
58
- // Optional props
59
- //
60
-
61
- // Custom resize handle
62
- handle: PropTypes.element,
63
-
64
- // If you change this, be sure to update your css
65
- handleSize: PropTypes.array,
66
-
67
- // Defines which resize handles should be rendered (default: 'se')
68
- // Allows for any combination of:
69
- // 's' - South handle (bottom-center)
70
- // 'w' - West handle (left-center)
71
- // 'e' - East handle (right-center)
72
- // 'n' - North handle (top-center)
73
- // 'sw' - Southwest handle (bottom-left)
74
- // 'nw' - Northwest handle (top-left)
75
- // 'se' - Southeast handle (bottom-right)
76
- // 'ne' - Northeast handle (top-center)
77
- resizeHandles: PropTypes.arrayOf(PropTypes.oneOf(['s', 'w', 'e', 'n', 'sw', 'nw', 'se', 'ne'])),
78
-
79
- // If true, will only allow width/height to move in lockstep
80
- lockAspectRatio: PropTypes.bool,
81
-
82
- // Restricts resizing to a particular axis (default: 'both')
83
- // 'both' - allows resizing by width or height
84
- // 'x' - only allows the width to be changed
85
- // 'y' - only allows the height to be changed
86
- // 'none' - disables resizing altogether
87
- axis: PropTypes.oneOf(['both', 'x', 'y', 'none']),
88
-
89
- // Min/max size
90
- minConstraints: PropTypes.arrayOf(PropTypes.number),
91
- maxConstraints: PropTypes.arrayOf(PropTypes.number),
92
-
93
- // Callbacks
94
- onResizeStop: PropTypes.func,
95
- onResizeStart: PropTypes.func,
96
- onResize: PropTypes.func,
97
-
98
- // These will be passed wholesale to react-draggable's DraggableCore
99
- draggableOpts: PropTypes.object
100
- };
9
+ export default class Resizable extends React.Component<Props, ResizableState> {
10
+ static propTypes = resizableProps;
101
11
 
102
12
  static defaultProps = {
103
13
  handleSize: [20, 20],
@@ -105,24 +15,17 @@ export default class Resizable extends React.Component<Props, State> {
105
15
  axis: 'both',
106
16
  minConstraints: [20, 20],
107
17
  maxConstraints: [Infinity, Infinity],
108
- resizeHandles: ['se']
18
+ resizeHandles: ['se'],
19
+ transformScale: 1
109
20
  };
110
21
 
111
- state: State = {
112
- resizing: false,
113
- width: this.props.width, height: this.props.height,
114
- slackW: 0, slackH: 0
115
- };
22
+ state: ResizableState = undefined;
116
23
 
117
- componentWillReceiveProps(nextProps: Object) {
118
- // If parent changes height/width, set that in our state.
119
- if (!this.state.resizing &&
120
- (nextProps.width !== this.props.width || nextProps.height !== this.props.height)) {
121
- this.setState({
122
- width: nextProps.width,
123
- height: nextProps.height
124
- });
125
- }
24
+ lastHandleRect: ?ClientRect = null;
25
+ slack: ?[number, number] = null;
26
+
27
+ componentWillUnmount() {
28
+ this.resetData();
126
29
  }
127
30
 
128
31
  lockAspectRatio(width: number, height: number, aspectRatio: number): [number, number] {
@@ -131,24 +34,37 @@ export default class Resizable extends React.Component<Props, State> {
131
34
  return [width, height];
132
35
  }
133
36
 
134
- // If you do this, be careful of constraints
37
+ resetData() {
38
+ this.lastHandleRect = this.slack = null;
39
+ }
40
+
41
+ // Clamp width and height within provided constraints
135
42
  runConstraints(width: number, height: number): [number, number] {
136
43
  const [min, max] = [this.props.minConstraints, this.props.maxConstraints];
44
+ if (!min && !max) return [width, height];
137
45
 
46
+ // If constraining to min and max, we need to also fit width and height to aspect ratio.
138
47
  if (this.props.lockAspectRatio) {
139
- const ratio = this.state.width / this.state.height;
140
- height = width / ratio;
141
- width = height * ratio;
48
+ const resizingHorizontally = height === this.props.height;
49
+ if (resizingHorizontally) {
50
+ const ratio = this.props.width / this.props.height;
51
+ height = width / ratio;
52
+ width = height * ratio;
53
+ } else {
54
+ // Take into account vertical resize with N/S handles on locked aspect
55
+ // ratio. Calculate the change height-first, instead of width-first
56
+ const ratio = this.props.height / this.props.width;
57
+ width = height / ratio;
58
+ height = width * ratio;
59
+ }
142
60
  }
143
61
 
144
- if (!min && !max) return [width, height];
145
-
146
62
  const [oldW, oldH] = [width, height];
147
63
 
148
64
  // Add slack to the values used to calculate bound position. This will ensure that if
149
65
  // we start removing slack, the element won't react to it right away until it's been
150
66
  // completely removed.
151
- let {slackW, slackH} = this.state;
67
+ let [slackW, slackH] = this.slack || [0, 0];
152
68
  width += slackW;
153
69
  height += slackH;
154
70
 
@@ -161,12 +77,8 @@ export default class Resizable extends React.Component<Props, State> {
161
77
  height = Math.min(max[1], height);
162
78
  }
163
79
 
164
- // If the numbers changed, we must have introduced some slack. Record it for the next iteration.
165
- slackW += (oldW - width);
166
- slackH += (oldH - height);
167
- if (slackW !== this.state.slackW || slackH !== this.state.slackH) {
168
- this.setState({slackW, slackH});
169
- }
80
+ // If the width or height changed, we must have introduced some slack. Record it for the next iteration.
81
+ this.slack = [slackW + (oldW - width), slackH + (oldH - height)];
170
82
 
171
83
  return [width, height];
172
84
  }
@@ -177,76 +89,85 @@ export default class Resizable extends React.Component<Props, State> {
177
89
  * @param {String} handlerName Handler name to wrap.
178
90
  * @return {Function} Handler function.
179
91
  */
180
- resizeHandler(handlerName: string, axis: ResizeHandle): Function {
181
- return (e: SyntheticEvent<> | MouseEvent, {node, deltaX, deltaY}: DragCallbackData) => {
92
+ resizeHandler(handlerName: 'onResize' | 'onResizeStart' | 'onResizeStop', axis: ResizeHandleAxis): Function {
93
+ return (e: SyntheticEvent<>, {node, deltaX, deltaY}: DragCallbackData) => {
94
+ // Reset data in case it was left over somehow (should not be possible)
95
+ if (handlerName === 'onResizeStart') this.resetData();
182
96
 
183
97
  // Axis restrictions
184
- const canDragX = (this.props.axis === 'both' || this.props.axis === 'x') && ['n', 's'].indexOf(axis) === -1;
185
- const canDragY = (this.props.axis === 'both' || this.props.axis === 'y') && ['e', 'w'].indexOf(axis) === -1;
186
-
187
- // reverse delta if using top or left drag handles
188
- if (canDragX && axis[axis.length - 1] === 'w') {
189
- deltaX = -deltaX;
190
- }
191
- if (canDragY && axis[0] === 'n') {
192
- deltaY = -deltaY;
98
+ const canDragX = (this.props.axis === 'both' || this.props.axis === 'x') && axis !== 'n' && axis !== 's';
99
+ const canDragY = (this.props.axis === 'both' || this.props.axis === 'y') && axis !== 'e' && axis !== 'w';
100
+ // No dragging possible.
101
+ if (!canDragX && !canDragY) return;
102
+
103
+ // Decompose axis for later use
104
+ const axisV = axis[0];
105
+ const axisH = axis[axis.length - 1]; // intentionally not axis[1], so that this catches axis === 'w' for example
106
+
107
+ // Track the element being dragged to account for changes in position.
108
+ // If a handle's position is changed between callbacks, we need to factor this in to the next callback.
109
+ // Failure to do so will cause the element to "skip" when resized upwards or leftwards.
110
+ const handleRect = node.getBoundingClientRect();
111
+ if (this.lastHandleRect != null) {
112
+ // If the handle has repositioned on either axis since last render,
113
+ // we need to increase our callback values by this much.
114
+ // Only checking 'n', 'w' since resizing by 's', 'w' won't affect the overall position on page,
115
+ if (axisH === 'w') {
116
+ const deltaLeftSinceLast = handleRect.left - this.lastHandleRect.left;
117
+ deltaX += deltaLeftSinceLast;
118
+ }
119
+ if (axisV === 'n') {
120
+ const deltaTopSinceLast = handleRect.top - this.lastHandleRect.top;
121
+ deltaY += deltaTopSinceLast;
122
+ }
193
123
  }
124
+ // Storage of last rect so we know how much it has really moved.
125
+ this.lastHandleRect = handleRect;
194
126
 
195
- // Update w/h
196
- let width = this.state.width + (canDragX ? deltaX : 0);
197
- let height = this.state.height + (canDragY ? deltaY : 0);
127
+ // Reverse delta if using top or left drag handles.
128
+ if (axisH === 'w') deltaX = -deltaX;
129
+ if (axisV === 'n') deltaY = -deltaY;
198
130
 
199
- // Early return if no change
200
- const widthChanged = width !== this.state.width, heightChanged = height !== this.state.height;
201
- if (handlerName === 'onResize' && !widthChanged && !heightChanged) return;
131
+ // Update w/h by the deltas. Also factor in transformScale.
132
+ let width = this.props.width + (canDragX ? deltaX / this.props.transformScale : 0);
133
+ let height = this.props.height + (canDragY ? deltaY / this.props.transformScale : 0);
202
134
 
135
+ // Run user-provided constraints.
203
136
  [width, height] = this.runConstraints(width, height);
204
137
 
205
- // Set the appropriate state for this handler.
206
- const newState = {};
207
- if (handlerName === 'onResizeStart') {
208
- newState.resizing = true;
209
- } else if (handlerName === 'onResizeStop') {
210
- newState.resizing = false;
211
- newState.slackW = newState.slackH = 0;
212
- } else {
213
- // Early return if no change after constraints
214
- if (width === this.state.width && height === this.state.height) return;
215
- newState.width = width;
216
- newState.height = height;
217
- }
138
+ const dimensionsChanged = width !== this.props.width || height !== this.props.height;
218
139
 
219
- const hasCb = typeof this.props[handlerName] === 'function';
220
- if (hasCb) {
221
- // $FlowIgnore isn't refining this correctly to SyntheticEvent
140
+ // Call user-supplied callback if present.
141
+ const cb = typeof this.props[handlerName] === 'function' ? this.props[handlerName] : null;
142
+ // Don't call 'onResize' if dimensions haven't changed.
143
+ const shouldSkipCb = handlerName === 'onResize' && !dimensionsChanged;
144
+ if (cb && !shouldSkipCb) {
222
145
  if (typeof e.persist === 'function') e.persist();
223
- this.setState(newState, () => this.props[handlerName](e, {node, size: {width, height}, handle: axis}));
224
- } else {
225
- this.setState(newState);
146
+ cb(e, {node, size: {width, height}, handle: axis});
226
147
  }
148
+
149
+ // Reset internal data
150
+ if (handlerName === 'onResizeStop') this.resetData();
227
151
  };
228
152
  }
229
153
 
230
- renderResizeHandle(resizeHandle: ResizeHandle): ReactNode {
154
+ renderResizeHandle(resizeHandleAxis: ResizeHandleAxis): ReactNode {
231
155
  const {handle} = this.props;
232
156
  if (handle) {
233
157
  if (typeof handle === 'function') {
234
- return handle(resizeHandle);
158
+ return handle(resizeHandleAxis);
235
159
  }
236
160
  return handle;
237
161
  }
238
- return <span className={`react-resizable-handle react-resizable-handle-${resizeHandle}`} />;
162
+ return <span className={`react-resizable-handle react-resizable-handle-${resizeHandleAxis}`} />;
239
163
  }
240
164
 
241
165
  render(): ReactNode {
166
+ // Pass along only props not meant for the `<Resizable>`.`
242
167
  // eslint-disable-next-line no-unused-vars
243
- const {children, draggableOpts, width, height, handleSize,
244
- lockAspectRatio, axis, minConstraints, maxConstraints, onResize,
245
- onResizeStop, onResizeStart, resizeHandles, ...p} = this.props;
246
-
247
- const className = p.className ?
248
- `${p.className} react-resizable`:
249
- 'react-resizable';
168
+ const {children, className, draggableOpts, width, height, handle, handleSize,
169
+ lockAspectRatio, axis, minConstraints, maxConstraints, onResize,
170
+ onResizeStop, onResizeStart, resizeHandles, transformScale, ...p} = this.props;
250
171
 
251
172
  // What we're doing here is getting the child of this element, and cloning it with this element's props.
252
173
  // We are then defining its children as:
@@ -254,18 +175,18 @@ export default class Resizable extends React.Component<Props, State> {
254
175
  // One or more draggable handles.
255
176
  return cloneElement(children, {
256
177
  ...p,
257
- className,
178
+ className: `${className ? `${className} ` : ''}react-resizable`,
258
179
  children: [
259
- children.props.children,
260
- resizeHandles.map(h => (
180
+ ...children.props.children,
181
+ ...resizeHandles.map((handleAxis) => (
261
182
  <DraggableCore
262
183
  {...draggableOpts}
263
- key={`resizableHandle-${h}`}
264
- onStop={this.resizeHandler('onResizeStop', h)}
265
- onStart={this.resizeHandler('onResizeStart', h)}
266
- onDrag={this.resizeHandler('onResize', h)}
184
+ key={`resizableHandle-${handleAxis}`}
185
+ onStop={this.resizeHandler('onResizeStop', handleAxis)}
186
+ onStart={this.resizeHandler('onResizeStart', handleAxis)}
187
+ onDrag={this.resizeHandler('onResize', handleAxis)}
267
188
  >
268
- {this.renderResizeHandle(h)}
189
+ {this.renderResizeHandle(handleAxis)}
269
190
  </DraggableCore>
270
191
  ))
271
192
  ]
@@ -1,122 +1,138 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
+ exports.default = void 0;
4
5
 
5
- 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; };
6
+ var React = _interopRequireWildcard(require("react"));
6
7
 
7
- var _react = require('react');
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
9
 
9
- var _react2 = _interopRequireDefault(_react);
10
+ var _Resizable = _interopRequireDefault(require("./Resizable"));
10
11
 
11
- var _propTypes = require('prop-types');
12
+ var _propTypes2 = require("./propTypes");
12
13
 
13
- var _propTypes2 = _interopRequireDefault(_propTypes);
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15
 
15
- var _Resizable = require('./Resizable');
16
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
16
17
 
17
- var _Resizable2 = _interopRequireDefault(_Resizable);
18
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
18
19
 
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+ function _extends() { _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; }; return _extends.apply(this, arguments); }
20
21
 
21
- 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; }
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
22
23
 
23
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
24
25
 
25
- 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; }
26
+ 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; }
26
27
 
27
- 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; }
28
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
28
29
 
29
- // An example use of Resizable.
30
- var ResizableBox = function (_React$Component) {
31
- _inherits(ResizableBox, _React$Component);
30
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
32
31
 
33
- function ResizableBox() {
34
- var _temp, _this, _ret;
32
+ 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; }
35
33
 
36
- _classCallCheck(this, ResizableBox);
34
+ var ResizableBox = /*#__PURE__*/function (_React$Component) {
35
+ _inheritsLoose(ResizableBox, _React$Component);
37
36
 
38
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
37
+ function ResizableBox() {
38
+ var _this;
39
+
40
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
39
41
  args[_key] = arguments[_key];
40
42
  }
41
43
 
42
- return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
44
+ _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
45
+
46
+ _defineProperty(_assertThisInitialized(_this), "state", {
43
47
  width: _this.props.width,
44
- height: _this.props.height
45
- }, _this.onResize = function (e, data) {
46
- var size = data.size;
47
- var width = size.width,
48
- height = size.height;
48
+ height: _this.props.height,
49
+ propsWidth: _this.props.width,
50
+ propsHeight: _this.props.height
51
+ });
49
52
 
53
+ _defineProperty(_assertThisInitialized(_this), "onResize", function (e, data) {
54
+ var size = data.size;
50
55
 
51
56
  if (_this.props.onResize) {
52
57
  e.persist && e.persist();
58
+
53
59
  _this.setState(size, function () {
54
60
  return _this.props.onResize && _this.props.onResize(e, data);
55
61
  });
56
62
  } else {
57
63
  _this.setState(size);
58
64
  }
59
- }, _temp), _possibleConstructorReturn(_this, _ret);
65
+ });
66
+
67
+ return _this;
60
68
  }
61
69
 
62
- ResizableBox.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
63
- if (nextProps.width !== this.props.width || nextProps.height !== this.props.height) {
64
- this.setState({
65
- width: nextProps.width,
66
- height: nextProps.height
67
- });
70
+ ResizableBox.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
71
+ // If parent changes height/width, set that in our state.
72
+ if (state.propsWidth !== props.width || state.propsHeight !== props.height) {
73
+ return {
74
+ width: props.width,
75
+ height: props.height,
76
+ propsWidth: props.width,
77
+ propsHeight: props.height
78
+ };
68
79
  }
80
+
81
+ return null;
69
82
  };
70
83
 
71
- ResizableBox.prototype.render = function render() {
84
+ var _proto = ResizableBox.prototype;
85
+
86
+ _proto.render = function render() {
72
87
  // Basic wrapper around a Resizable instance.
73
88
  // If you use Resizable directly, you are responsible for updating the child component
74
89
  // with a new width and height.
75
- var _props = this.props,
76
- handle = _props.handle,
77
- handleSize = _props.handleSize,
78
- onResize = _props.onResize,
79
- onResizeStart = _props.onResizeStart,
80
- onResizeStop = _props.onResizeStop,
81
- draggableOpts = _props.draggableOpts,
82
- minConstraints = _props.minConstraints,
83
- maxConstraints = _props.maxConstraints,
84
- lockAspectRatio = _props.lockAspectRatio,
85
- axis = _props.axis,
86
- width = _props.width,
87
- height = _props.height,
88
- resizeHandles = _props.resizeHandles,
89
- props = _objectWithoutProperties(_props, ['handle', 'handleSize', 'onResize', 'onResizeStart', 'onResizeStop', 'draggableOpts', 'minConstraints', 'maxConstraints', 'lockAspectRatio', 'axis', 'width', 'height', 'resizeHandles']);
90
-
91
- return _react2.default.createElement(
92
- _Resizable2.default,
93
- {
94
- handle: handle,
95
- handleSize: handleSize,
96
- width: this.state.width,
97
- height: this.state.height,
98
- onResizeStart: onResizeStart,
99
- onResize: this.onResize,
100
- onResizeStop: onResizeStop,
101
- draggableOpts: draggableOpts,
102
- minConstraints: minConstraints,
103
- maxConstraints: maxConstraints,
104
- lockAspectRatio: lockAspectRatio,
105
- axis: axis,
106
- resizeHandles: resizeHandles
107
- },
108
- _react2.default.createElement('div', _extends({ style: { width: this.state.width + 'px', height: this.state.height + 'px' } }, props))
109
- );
90
+ var _this$props = this.props,
91
+ handle = _this$props.handle,
92
+ handleSize = _this$props.handleSize,
93
+ onResize = _this$props.onResize,
94
+ onResizeStart = _this$props.onResizeStart,
95
+ onResizeStop = _this$props.onResizeStop,
96
+ draggableOpts = _this$props.draggableOpts,
97
+ minConstraints = _this$props.minConstraints,
98
+ maxConstraints = _this$props.maxConstraints,
99
+ lockAspectRatio = _this$props.lockAspectRatio,
100
+ axis = _this$props.axis,
101
+ width = _this$props.width,
102
+ height = _this$props.height,
103
+ resizeHandles = _this$props.resizeHandles,
104
+ style = _this$props.style,
105
+ transformScale = _this$props.transformScale,
106
+ props = _objectWithoutPropertiesLoose(_this$props, ["handle", "handleSize", "onResize", "onResizeStart", "onResizeStop", "draggableOpts", "minConstraints", "maxConstraints", "lockAspectRatio", "axis", "width", "height", "resizeHandles", "style", "transformScale"]);
107
+
108
+ return /*#__PURE__*/React.createElement(_Resizable.default, {
109
+ axis: axis,
110
+ draggableOpts: draggableOpts,
111
+ handle: handle,
112
+ handleSize: handleSize,
113
+ height: this.state.height,
114
+ lockAspectRatio: lockAspectRatio,
115
+ maxConstraints: maxConstraints,
116
+ minConstraints: minConstraints,
117
+ onResizeStart: onResizeStart,
118
+ onResize: this.onResize,
119
+ onResizeStop: onResizeStop,
120
+ resizeHandles: resizeHandles,
121
+ transformScale: transformScale,
122
+ width: this.state.width
123
+ }, /*#__PURE__*/React.createElement("div", _extends({}, props, {
124
+ style: _objectSpread(_objectSpread({}, style), {}, {
125
+ width: this.state.width + 'px',
126
+ height: this.state.height + 'px'
127
+ })
128
+ })));
110
129
  };
111
130
 
112
131
  return ResizableBox;
113
- }(_react2.default.Component);
114
-
115
- ResizableBox.propTypes = {
116
- height: _propTypes2.default.number,
117
- width: _propTypes2.default.number
118
- };
119
- ResizableBox.defaultProps = {
120
- handleSize: [20, 20]
121
- };
122
- exports.default = ResizableBox;
132
+ }(React.Component);
133
+
134
+ exports.default = ResizableBox;
135
+
136
+ _defineProperty(ResizableBox, "propTypes", _objectSpread(_objectSpread({}, _propTypes2.resizableProps), {}, {
137
+ children: _propTypes.default.element
138
+ }));