react-zoom-pan-pinch 3.2.0 → 3.3.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.
package/dist/index.d.ts CHANGED
@@ -165,6 +165,9 @@ type ReactZoomPanPinchProps = {
165
165
  velocityDisabled?: boolean;
166
166
  lockAxisX?: boolean;
167
167
  lockAxisY?: boolean;
168
+ allowLeftClickPan?: boolean;
169
+ allowMiddleClickPan?: boolean;
170
+ allowRightClickPan?: boolean;
168
171
  activationKeys?: string[];
169
172
  excluded?: string[];
170
173
  };
package/dist/index.esm.js CHANGED
@@ -216,28 +216,6 @@ var calculateBounds = function (contextInstance, newScale) {
216
216
  var bounds = getBounds(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, Boolean(centerZoomedOut));
217
217
  return bounds;
218
218
  };
219
- function clamp(v, min, max) {
220
- return Math.max(min, Math.min(v, max));
221
- }
222
- // Based on @aholachek ;)
223
- // https://twitter.com/chpwn/status/285540192096497664
224
- // iOS constant = 0.55
225
- // https://medium.com/@nathangitter/building-fluid-interfaces-ios-swift-9732bb934bf5
226
- function rubberband(distance, dimension, constant) {
227
- if (dimension === 0 || Math.abs(dimension) === Infinity)
228
- return Math.pow(distance, (constant * 5));
229
- return (distance * dimension * constant) / (dimension + constant * distance);
230
- }
231
- function rubberbandIfOutOfBounds(position, min, max, constant) {
232
- if (constant === void 0) { constant = 0.15; }
233
- if (constant === 0)
234
- return clamp(position, min, max);
235
- if (position < min)
236
- return -rubberband(min - position, max - min, constant) + min;
237
- if (position > max)
238
- return +rubberband(position - max, max - min, constant) + max;
239
- return position;
240
- }
241
219
  /**
242
220
  * Keeps value between given bounds, used for limiting view to given boundaries
243
221
  * 1# eg. boundLimiter(2, 0, 3, true) => 2
@@ -268,10 +246,8 @@ function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, pa
268
246
  paddingX = paddingValueX;
269
247
  paddingY = paddingValueY;
270
248
  }
271
- var rubberbandX = rubberbandIfOutOfBounds(positionX, minPositionX, maxPositionX);
272
- var rubberbandY = rubberbandIfOutOfBounds(positionY, minPositionY, maxPositionY);
273
- var x = boundLimiter(rubberbandX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
274
- var y = boundLimiter(rubberbandY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
249
+ var x = boundLimiter(positionX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
250
+ var y = boundLimiter(positionY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
275
251
  return { x: x, y: y };
276
252
  }
277
253
 
@@ -691,6 +667,9 @@ var initialSetup = {
691
667
  velocityDisabled: false,
692
668
  lockAxisX: false,
693
669
  lockAxisY: false,
670
+ allowLeftClickPan: true,
671
+ allowMiddleClickPan: true,
672
+ allowRightClickPan: true,
694
673
  activationKeys: [],
695
674
  excluded: [],
696
675
  },
@@ -1449,6 +1428,12 @@ var ZoomPanPinch = /** @class */ (function () {
1449
1428
  var keysPressed = _this.isPressingKeys(_this.setup.panning.activationKeys);
1450
1429
  if (!keysPressed)
1451
1430
  return;
1431
+ if (event.button === 0 && !_this.setup.panning.allowLeftClickPan)
1432
+ return;
1433
+ if (event.button === 1 && !_this.setup.panning.allowMiddleClickPan)
1434
+ return;
1435
+ if (event.button === 2 && !_this.setup.panning.allowRightClickPan)
1436
+ return;
1452
1437
  event.preventDefault();
1453
1438
  event.stopPropagation();
1454
1439
  handleCancelAnimation(_this);
@@ -1698,9 +1683,6 @@ var TransformWrapper = React.forwardRef(function (props, ref) {
1698
1683
  useImperativeHandle(ref, function () { return getControls(instance); }, [instance]);
1699
1684
  useEffect(function () {
1700
1685
  instance.update(props);
1701
- return function () {
1702
- instance.cleanupWindowEvents();
1703
- };
1704
1686
  }, [instance, props]);
1705
1687
  return React.createElement(Context.Provider, { value: instance }, content);
1706
1688
  });
@@ -1916,16 +1898,19 @@ styleInject(css_248z);
1916
1898
 
1917
1899
  var TransformComponent = function (_a) {
1918
1900
  var children = _a.children, _b = _a.wrapperClass, wrapperClass = _b === void 0 ? "" : _b, _c = _a.contentClass, contentClass = _c === void 0 ? "" : _c, wrapperStyle = _a.wrapperStyle, contentStyle = _a.contentStyle, _d = _a.wrapperProps, wrapperProps = _d === void 0 ? {} : _d, _e = _a.contentProps, contentProps = _e === void 0 ? {} : _e;
1919
- var init = useContext(Context).init;
1901
+ var _f = useContext(Context), init = _f.init, cleanupWindowEvents = _f.cleanupWindowEvents;
1920
1902
  var wrapperRef = useRef(null);
1921
1903
  var contentRef = useRef(null);
1922
1904
  useEffect(function () {
1923
1905
  var wrapper = wrapperRef.current;
1924
1906
  var content = contentRef.current;
1925
1907
  if (wrapper !== null && content !== null && init) {
1926
- init(wrapper, content);
1908
+ init === null || init === void 0 ? void 0 : init(wrapper, content);
1927
1909
  }
1928
1910
  // eslint-disable-next-line react-hooks/exhaustive-deps
1911
+ return function () {
1912
+ cleanupWindowEvents === null || cleanupWindowEvents === void 0 ? void 0 : cleanupWindowEvents();
1913
+ };
1929
1914
  }, []);
1930
1915
  return (React.createElement("div", __assign({}, wrapperProps, { ref: wrapperRef, className: "react-transform-wrapper ".concat(styles.wrapper, " ").concat(wrapperClass), style: wrapperStyle }),
1931
1916
  React.createElement("div", __assign({}, contentProps, { ref: contentRef, className: "react-transform-component ".concat(styles.content, " ").concat(contentClass), style: contentStyle }), children)));