react-resizable 3.1.3 → 3.2.0

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.
@@ -9,7 +9,6 @@ var _propTypes = require("./propTypes");
9
9
  const _excluded = ["children", "className", "draggableOpts", "width", "height", "handle", "handleSize", "lockAspectRatio", "axis", "minConstraints", "maxConstraints", "onResize", "onResizeStop", "onResizeStart", "resizeHandles", "transformScale"];
10
10
  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); }
11
11
  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); }
12
- 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; }
13
12
  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; }
14
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; }
15
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; }
@@ -35,11 +34,10 @@ class Resizable extends React.Component {
35
34
 
36
35
  // Clamp width and height within provided constraints
37
36
  runConstraints(width, height) {
38
- const {
39
- minConstraints,
40
- maxConstraints,
41
- lockAspectRatio
42
- } = this.props;
37
+ const _this$props = this.props,
38
+ minConstraints = _this$props.minConstraints,
39
+ maxConstraints = _this$props.maxConstraints,
40
+ lockAspectRatio = _this$props.lockAspectRatio;
43
41
  // short circuit
44
42
  if (!minConstraints && !maxConstraints && !lockAspectRatio) return [width, height];
45
43
 
@@ -59,12 +57,15 @@ class Resizable extends React.Component {
59
57
  width = height * ratio;
60
58
  }
61
59
  }
62
- const [oldW, oldH] = [width, height];
60
+ const oldW = width,
61
+ oldH = height;
63
62
 
64
63
  // Add slack to the values used to calculate bound position. This will ensure that if
65
64
  // we start removing slack, the element won't react to it right away until it's been
66
65
  // completely removed.
67
- let [slackW, slackH] = this.slack || [0, 0];
66
+ let _ref = this.slack || [0, 0],
67
+ slackW = _ref[0],
68
+ slackH = _ref[1];
68
69
  width += slackW;
69
70
  height += slackH;
70
71
  if (minConstraints) {
@@ -88,12 +89,11 @@ class Resizable extends React.Component {
88
89
  * @return {Function} Handler function.
89
90
  */
90
91
  resizeHandler(handlerName, axis) {
91
- return (e, _ref) => {
92
- let {
93
- node,
94
- deltaX,
95
- deltaY
96
- } = _ref;
92
+ return (e, _ref2) => {
93
+ var _this$lastSize$width, _this$lastSize, _this$lastSize$height, _this$lastSize2;
94
+ let node = _ref2.node,
95
+ deltaX = _ref2.deltaX,
96
+ deltaY = _ref2.deltaY;
97
97
  // Reset data in case it was left over somehow (should not be possible)
98
98
  if (handlerName === 'onResizeStart') this.resetData();
99
99
 
@@ -132,21 +132,29 @@ class Resizable extends React.Component {
132
132
  if (axisV === 'n') deltaY = -deltaY;
133
133
 
134
134
  // Update w/h by the deltas. Also factor in transformScale.
135
- let width = this.props.width + (canDragX ? deltaX / this.props.transformScale : 0);
136
- let height = this.props.height + (canDragY ? deltaY / this.props.transformScale : 0);
135
+ // Use lastSize (if available) instead of props to avoid losing deltas
136
+ // when React can't re-render between consecutive mouse events.
137
+ const baseWidth = (_this$lastSize$width = (_this$lastSize = this.lastSize) == null ? void 0 : _this$lastSize.width) != null ? _this$lastSize$width : this.props.width;
138
+ const baseHeight = (_this$lastSize$height = (_this$lastSize2 = this.lastSize) == null ? void 0 : _this$lastSize2.height) != null ? _this$lastSize$height : this.props.height;
139
+ let width = baseWidth + (canDragX ? deltaX / this.props.transformScale : 0);
140
+ let height = baseHeight + (canDragY ? deltaY / this.props.transformScale : 0);
137
141
 
138
142
  // Run user-provided constraints.
139
- [width, height] = this.runConstraints(width, height);
140
-
141
143
  // For onResizeStop, use the last size from onResize rather than recalculating.
142
144
  // This avoids issues where props.width/height are stale due to React's batched updates.
145
+ var _this$runConstraints = this.runConstraints(width, height);
146
+ width = _this$runConstraints[0];
147
+ height = _this$runConstraints[1];
143
148
  if (handlerName === 'onResizeStop' && this.lastSize) {
144
- ({
145
- width,
146
- height
147
- } = this.lastSize);
149
+ var _this$lastSize3 = this.lastSize;
150
+ width = _this$lastSize3.width;
151
+ height = _this$lastSize3.height;
148
152
  }
149
- const dimensionsChanged = width !== this.props.width || height !== this.props.height;
153
+
154
+ // Compare against the base (lastSize-or-props) so that callbacks correctly
155
+ // suppress when the net delta is zero, even if props are stale relative to
156
+ // the accumulated lastSize.
157
+ const dimensionsChanged = width !== baseWidth || height !== baseHeight;
150
158
 
151
159
  // Store the size for use in onResizeStop. We do this after the onResizeStop check
152
160
  // above so we don't overwrite the stored value with a potentially stale calculation.
@@ -162,7 +170,7 @@ class Resizable extends React.Component {
162
170
  // Don't call 'onResize' if dimensions haven't changed.
163
171
  const shouldSkipCb = handlerName === 'onResize' && !dimensionsChanged;
164
172
  if (cb && !shouldSkipCb) {
165
- e.persist?.();
173
+ e.persist == null || e.persist();
166
174
  cb(e, {
167
175
  node,
168
176
  size: {
@@ -181,13 +189,11 @@ class Resizable extends React.Component {
181
189
  // Render a resize handle given an axis & DOM ref. Ref *must* be attached for
182
190
  // the underlying draggable library to work properly.
183
191
  renderResizeHandle(handleAxis, ref) {
184
- const {
185
- handle
186
- } = this.props;
192
+ const handle = this.props.handle;
187
193
  // No handle provided, make the default
188
194
  if (!handle) {
189
195
  return /*#__PURE__*/React.createElement("span", {
190
- className: `react-resizable-handle react-resizable-handle-${handleAxis}`,
196
+ className: "react-resizable-handle react-resizable-handle-" + handleAxis,
191
197
  ref: ref
192
198
  });
193
199
  }
@@ -208,39 +214,38 @@ class Resizable extends React.Component {
208
214
  render() {
209
215
  // Pass along only props not meant for the `<Resizable>`.`
210
216
  // eslint-disable-next-line no-unused-vars
211
- const _this$props = this.props,
212
- {
213
- children,
214
- className,
215
- draggableOpts,
216
- width,
217
- height,
218
- handle,
219
- handleSize,
220
- lockAspectRatio,
221
- axis,
222
- minConstraints,
223
- maxConstraints,
224
- onResize,
225
- onResizeStop,
226
- onResizeStart,
227
- resizeHandles,
228
- transformScale
229
- } = _this$props,
230
- p = _objectWithoutProperties(_this$props, _excluded);
217
+ const _this$props2 = this.props,
218
+ children = _this$props2.children,
219
+ className = _this$props2.className,
220
+ draggableOpts = _this$props2.draggableOpts,
221
+ width = _this$props2.width,
222
+ height = _this$props2.height,
223
+ handle = _this$props2.handle,
224
+ handleSize = _this$props2.handleSize,
225
+ lockAspectRatio = _this$props2.lockAspectRatio,
226
+ axis = _this$props2.axis,
227
+ minConstraints = _this$props2.minConstraints,
228
+ maxConstraints = _this$props2.maxConstraints,
229
+ onResize = _this$props2.onResize,
230
+ onResizeStop = _this$props2.onResizeStop,
231
+ onResizeStart = _this$props2.onResizeStart,
232
+ resizeHandles = _this$props2.resizeHandles,
233
+ transformScale = _this$props2.transformScale,
234
+ p = _objectWithoutPropertiesLoose(_this$props2, _excluded);
231
235
 
232
236
  // What we're doing here is getting the child of this element, and cloning it with this element's props.
233
237
  // We are then defining its children as:
234
238
  // 1. Its original children (resizable's child's children), and
235
239
  // 2. One or more draggable handles.
236
240
  return (0, _utils.cloneElement)(children, _objectSpread(_objectSpread({}, p), {}, {
237
- className: `${className ? `${className} ` : ''}react-resizable`,
241
+ className: (className ? className + " " : '') + "react-resizable",
238
242
  children: [...React.Children.toArray(children.props.children), ...resizeHandles.map(handleAxis => {
243
+ var _this$handleRefs$hand;
239
244
  // Create a ref to the handle so that `<DraggableCore>` doesn't have to use ReactDOM.findDOMNode().
240
- const ref = this.handleRefs[handleAxis] ?? (this.handleRefs[handleAxis] = /*#__PURE__*/React.createRef());
245
+ const ref = (_this$handleRefs$hand = this.handleRefs[handleAxis]) != null ? _this$handleRefs$hand : this.handleRefs[handleAxis] = /*#__PURE__*/React.createRef();
241
246
  return /*#__PURE__*/React.createElement(_reactDraggable.DraggableCore, _extends({}, draggableOpts, {
242
247
  nodeRef: ref,
243
- key: `resizableHandle-${handleAxis}`,
248
+ key: "resizableHandle-" + handleAxis,
244
249
  onStop: this.resizeHandler('onResizeStop', handleAxis),
245
250
  onStart: this.resizeHandler('onResizeStart', handleAxis),
246
251
  onDrag: this.resizeHandler('onResize', handleAxis)
@@ -127,8 +127,12 @@ export default class Resizable extends React.Component<Props, void> {
127
127
  if (axisV === 'n') deltaY = -deltaY;
128
128
 
129
129
  // Update w/h by the deltas. Also factor in transformScale.
130
- let width = this.props.width + (canDragX ? deltaX / this.props.transformScale : 0);
131
- let height = this.props.height + (canDragY ? deltaY / this.props.transformScale : 0);
130
+ // Use lastSize (if available) instead of props to avoid losing deltas
131
+ // when React can't re-render between consecutive mouse events.
132
+ const baseWidth = this.lastSize?.width ?? this.props.width;
133
+ const baseHeight = this.lastSize?.height ?? this.props.height;
134
+ let width = baseWidth + (canDragX ? deltaX / this.props.transformScale : 0);
135
+ let height = baseHeight + (canDragY ? deltaY / this.props.transformScale : 0);
132
136
 
133
137
  // Run user-provided constraints.
134
138
  [width, height] = this.runConstraints(width, height);
@@ -139,7 +143,10 @@ export default class Resizable extends React.Component<Props, void> {
139
143
  ({width, height} = this.lastSize);
140
144
  }
141
145
 
142
- const dimensionsChanged = width !== this.props.width || height !== this.props.height;
146
+ // Compare against the base (lastSize-or-props) so that callbacks correctly
147
+ // suppress when the net delta is zero, even if props are stale relative to
148
+ // the accumulated lastSize.
149
+ const dimensionsChanged = width !== baseWidth || height !== baseHeight;
143
150
 
144
151
  // Store the size for use in onResizeStop. We do this after the onResizeStop check
145
152
  // above so we don't overwrite the stored value with a potentially stale calculation.
@@ -15,7 +15,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
15
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
16
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
17
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
18
  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
19
  // ElementConfig gives us an object type where all items present in `defaultProps` are made optional.
21
20
  // <ResizableBox> does not have defaultProps, so we can use this type to tell Flow that we don't
@@ -32,11 +31,9 @@ class ResizableBox extends React.Component {
32
31
  propsHeight: this.props.height
33
32
  };
34
33
  this.onResize = (e, data) => {
35
- const {
36
- size
37
- } = data;
34
+ const size = data.size;
38
35
  if (this.props.onResize) {
39
- e.persist?.();
36
+ e.persist == null || e.persist();
40
37
  this.setState(size, () => this.props.onResize && this.props.onResize(e, data));
41
38
  } else {
42
39
  this.setState(size);
@@ -60,24 +57,22 @@ class ResizableBox extends React.Component {
60
57
  // If you use Resizable directly, you are responsible for updating the child component
61
58
  // with a new width and height.
62
59
  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);
60
+ handle = _this$props.handle,
61
+ handleSize = _this$props.handleSize,
62
+ onResize = _this$props.onResize,
63
+ onResizeStart = _this$props.onResizeStart,
64
+ onResizeStop = _this$props.onResizeStop,
65
+ draggableOpts = _this$props.draggableOpts,
66
+ minConstraints = _this$props.minConstraints,
67
+ maxConstraints = _this$props.maxConstraints,
68
+ lockAspectRatio = _this$props.lockAspectRatio,
69
+ axis = _this$props.axis,
70
+ width = _this$props.width,
71
+ height = _this$props.height,
72
+ resizeHandles = _this$props.resizeHandles,
73
+ style = _this$props.style,
74
+ transformScale = _this$props.transformScale,
75
+ props = _objectWithoutPropertiesLoose(_this$props, _excluded);
81
76
  return /*#__PURE__*/React.createElement(_Resizable.default, {
82
77
  axis: axis,
83
78
  draggableOpts: draggableOpts,
@@ -48,7 +48,7 @@ const resizableProps = exports.resizableProps = {
48
48
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
49
49
  args[_key] = arguments[_key];
50
50
  }
51
- const [props] = args;
51
+ const props = args[0];
52
52
  // Required if resizing height or both
53
53
  if (props.axis === 'both' || props.axis === 'y') {
54
54
  return _propTypes.default.number.isRequired(...args);
@@ -107,7 +107,7 @@ const resizableProps = exports.resizableProps = {
107
107
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
108
108
  args[_key2] = arguments[_key2];
109
109
  }
110
- const [props] = args;
110
+ const props = args[0];
111
111
  // Required if resizing width or both
112
112
  if (props.axis === 'both' || props.axis === 'x') {
113
113
  return _propTypes.default.number.isRequired(...args);
package/build/utils.js CHANGED
@@ -15,7 +15,7 @@ function cloneElement(element, props) {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable",
3
- "version": "3.1.3",
3
+ "version": "3.2.0",
4
4
  "description": "A component that is resizable with handles.",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -37,35 +37,36 @@
37
37
  },
38
38
  "homepage": "https://github.com/react-grid-layout/react-resizable",
39
39
  "devDependencies": {
40
- "@babel/cli": "^7.28.3",
41
- "@babel/core": "^7.28.5",
42
- "@babel/eslint-parser": "^7.28.5",
40
+ "@babel/cli": "^7.28.6",
41
+ "@babel/core": "^7.29.0",
42
+ "@babel/eslint-parser": "^7.28.6",
43
43
  "@babel/plugin-proposal-class-properties": "^7.18.6",
44
44
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
45
- "@babel/preset-env": "^7.28.5",
45
+ "@babel/preset-env": "^7.29.5",
46
46
  "@babel/preset-flow": "^7.27.1",
47
47
  "@babel/preset-react": "^7.28.5",
48
+ "@eslint/js": "^9.39.4",
48
49
  "@testing-library/dom": "^10.4.1",
49
50
  "@testing-library/jest-dom": "^6.1.0",
50
- "@testing-library/react": "^16.3.1",
51
+ "@testing-library/react": "^16.3.2",
51
52
  "@testing-library/user-event": "^14.5.0",
52
- "babel-loader": "^10.0.0",
53
+ "babel-loader": "^10.1.1",
53
54
  "cross-env": "^10.1.0",
54
- "css-loader": "^7.1.2",
55
- "eslint": "^9.39.2",
56
- "eslint-plugin-jest": "^29.11.3",
55
+ "css-loader": "^7.1.4",
56
+ "eslint": "^9.39.4",
57
+ "eslint-plugin-jest": "^29.15.2",
57
58
  "eslint-plugin-react": "^7.37.5",
58
59
  "flow-bin": "^0.153.0",
59
- "jest": "^30.2.0",
60
- "jest-environment-jsdom": "^30.2.0",
61
- "lodash": "^4.17.20",
60
+ "jest": "^30.4.2",
61
+ "jest-environment-jsdom": "^30.4.1",
62
+ "lodash": "^4.18.1",
62
63
  "pre-commit": "^1.1.2",
63
- "react": "^19.2.3",
64
- "react-dom": "^19.2.3",
64
+ "react": "^19.2.6",
65
+ "react-dom": "^19.2.6",
65
66
  "style-loader": "^4.0.0",
66
- "webpack": "^5.104.1",
67
- "webpack-cli": "^6.0.1",
68
- "webpack-dev-server": "^5.2.2"
67
+ "webpack": "^5.106.2",
68
+ "webpack-cli": "^7.0.2",
69
+ "webpack-dev-server": "^5.2.4"
69
70
  },
70
71
  "dependencies": {
71
72
  "prop-types": "15.x",