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.
- package/.babelrc +10 -4
- package/.browserslistrc +3 -0
- package/.eslintrc +10 -6
- package/.flowconfig +10 -10
- package/CHANGELOG.md +61 -32
- package/README.md +14 -4
- package/__tests__/Resizable.test.js +245 -0
- package/__tests__/ResizableBox.test.js +99 -0
- package/__tests__/__snapshots__/Resizable.test.js.snap +29 -0
- package/__tests__/__snapshots__/ResizableBox.test.js.snap +23 -0
- package/build/Resizable.js +172 -208
- package/build/Resizable.js.flow +99 -178
- package/build/ResizableBox.js +95 -79
- package/build/ResizableBox.js.flow +58 -33
- package/build/propTypes.js +112 -0
- package/build/propTypes.js.flow +135 -0
- package/build/utils.js +27 -0
- package/build/{cloneElement.js.flow → utils.js.flow} +2 -2
- package/coverage/clover.xml +107 -0
- package/coverage/coverage-final.json +5 -0
- package/coverage/lcov-report/Resizable.js.html +665 -0
- package/coverage/lcov-report/ResizableBox.js.html +374 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/flow-typed/npm/index.html +111 -0
- package/coverage/lcov-report/flow-typed/npm/jest_v26.x.x.js.html +3734 -0
- package/coverage/lcov-report/index.html +156 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/propTypes.js.html +485 -0
- package/coverage/lcov-report/react-resizable/dist/bundle.js.html +95 -0
- package/coverage/lcov-report/react-resizable/dist/index.html +111 -0
- package/coverage/lcov-report/react-resizable/flow-typed/npm/index.html +111 -0
- package/coverage/lcov-report/react-resizable/flow-typed/npm/jest_v26.x.x.js.html +3734 -0
- package/coverage/lcov-report/react-resizable/index.html +111 -0
- package/coverage/lcov-report/react-resizable/index.js.html +101 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov-report/utils.js.html +122 -0
- package/coverage/lcov.info +233 -0
- package/dist/bundle.js +6 -0
- package/flow-typed/npm/jest_v26.x.x.js +1218 -0
- package/package.json +34 -26
- package/setupTests/enzyme.js +4 -0
- package/.github/ISSUE_TEMPLATE.md +0 -23
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -5
- package/build/cloneElement.js +0 -20
package/build/Resizable.js.flow
CHANGED
|
@@ -1,103 +1,13 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import
|
|
3
|
+
import type {Node as ReactNode} from 'react';
|
|
4
4
|
import {DraggableCore} from 'react-draggable';
|
|
5
|
-
import cloneElement from './
|
|
6
|
-
import
|
|
5
|
+
import {cloneElement} from './utils';
|
|
6
|
+
import {resizableProps} from "./propTypes";
|
|
7
|
+
import type {ResizeHandleAxis, Props, ResizableState, DragCallbackData} from './propTypes';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
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:
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
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
|
|
140
|
-
|
|
141
|
-
|
|
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
|
|
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
|
|
165
|
-
slackW
|
|
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:
|
|
181
|
-
return (e: SyntheticEvent
|
|
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') &&
|
|
185
|
-
const canDragY = (this.props.axis === 'both' || this.props.axis === 'y') &&
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
//
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
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(
|
|
154
|
+
renderResizeHandle(resizeHandleAxis: ResizeHandleAxis): ReactNode {
|
|
231
155
|
const {handle} = this.props;
|
|
232
156
|
if (handle) {
|
|
233
157
|
if (typeof handle === 'function') {
|
|
234
|
-
return handle(
|
|
158
|
+
return handle(resizeHandleAxis);
|
|
235
159
|
}
|
|
236
160
|
return handle;
|
|
237
161
|
}
|
|
238
|
-
return <span className={`react-resizable-handle react-resizable-handle-${
|
|
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
|
-
|
|
245
|
-
|
|
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(
|
|
180
|
+
...children.props.children,
|
|
181
|
+
...resizeHandles.map((handleAxis) => (
|
|
261
182
|
<DraggableCore
|
|
262
183
|
{...draggableOpts}
|
|
263
|
-
key={`resizableHandle-${
|
|
264
|
-
onStop={this.resizeHandler('onResizeStop',
|
|
265
|
-
onStart={this.resizeHandler('onResizeStart',
|
|
266
|
-
onDrag={this.resizeHandler('onResize',
|
|
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(
|
|
189
|
+
{this.renderResizeHandle(handleAxis)}
|
|
269
190
|
</DraggableCore>
|
|
270
191
|
))
|
|
271
192
|
]
|
package/build/ResizableBox.js
CHANGED
|
@@ -1,122 +1,138 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
4
5
|
|
|
5
|
-
var
|
|
6
|
+
var React = _interopRequireWildcard(require("react"));
|
|
6
7
|
|
|
7
|
-
var
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _Resizable = _interopRequireDefault(require("./Resizable"));
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _propTypes2 = require("./propTypes");
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
15
|
|
|
15
|
-
var
|
|
16
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
16
17
|
|
|
17
|
-
var
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
34
|
+
var ResizableBox = /*#__PURE__*/function (_React$Component) {
|
|
35
|
+
_inheritsLoose(ResizableBox, _React$Component);
|
|
37
36
|
|
|
38
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return _this;
|
|
60
68
|
}
|
|
61
69
|
|
|
62
|
-
ResizableBox.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
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
|
|
76
|
-
handle =
|
|
77
|
-
handleSize =
|
|
78
|
-
onResize =
|
|
79
|
-
onResizeStart =
|
|
80
|
-
onResizeStop =
|
|
81
|
-
draggableOpts =
|
|
82
|
-
minConstraints =
|
|
83
|
-
maxConstraints =
|
|
84
|
-
lockAspectRatio =
|
|
85
|
-
axis =
|
|
86
|
-
width =
|
|
87
|
-
height =
|
|
88
|
-
resizeHandles =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
}(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
+
}));
|