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.cjs.js +16 -31
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.esm.js +16 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/src/models/context.model.d.ts +3 -0
- package/package.json +1 -1
- package/src/components/transform-component/transform-component.tsx +5 -2
- package/src/components/transform-wrapper/transform-wrapper.tsx +0 -3
- package/src/constants/state.constants.ts +3 -0
- package/src/core/bounds/bounds.utils.ts +2 -13
- package/src/core/instance.core.ts +4 -0
- package/src/models/context.model.ts +3 -0
- package/src/stories/docs/props.tsx +18 -0
|
@@ -62,6 +62,9 @@ export type ReactZoomPanPinchProps = {
|
|
|
62
62
|
velocityDisabled?: boolean;
|
|
63
63
|
lockAxisX?: boolean;
|
|
64
64
|
lockAxisY?: boolean;
|
|
65
|
+
allowLeftClickPan?: boolean;
|
|
66
|
+
allowMiddleClickPan?: boolean;
|
|
67
|
+
allowRightClickPan?: boolean;
|
|
65
68
|
activationKeys?: string[];
|
|
66
69
|
excluded?: string[];
|
|
67
70
|
};
|
package/package.json
CHANGED
|
@@ -24,7 +24,7 @@ export const TransformComponent: React.FC<Props> = ({
|
|
|
24
24
|
wrapperProps = {},
|
|
25
25
|
contentProps = {},
|
|
26
26
|
}: Props) => {
|
|
27
|
-
const { init } = useContext(Context);
|
|
27
|
+
const { init, cleanupWindowEvents } = useContext(Context);
|
|
28
28
|
|
|
29
29
|
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
|
30
30
|
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
@@ -33,9 +33,12 @@ export const TransformComponent: React.FC<Props> = ({
|
|
|
33
33
|
const wrapper = wrapperRef.current;
|
|
34
34
|
const content = contentRef.current;
|
|
35
35
|
if (wrapper !== null && content !== null && init) {
|
|
36
|
-
init(wrapper, content);
|
|
36
|
+
init?.(wrapper, content);
|
|
37
37
|
}
|
|
38
38
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
39
|
+
return () => {
|
|
40
|
+
cleanupWindowEvents?.();
|
|
41
|
+
};
|
|
39
42
|
}, []);
|
|
40
43
|
|
|
41
44
|
return (
|
|
@@ -32,9 +32,6 @@ export const TransformWrapper = React.forwardRef(
|
|
|
32
32
|
|
|
33
33
|
useEffect(() => {
|
|
34
34
|
instance.update(props);
|
|
35
|
-
return () => {
|
|
36
|
-
instance.cleanupWindowEvents();
|
|
37
|
-
};
|
|
38
35
|
}, [instance, props]);
|
|
39
36
|
|
|
40
37
|
return <Context.Provider value={instance}>{content}</Context.Provider>;
|
|
@@ -170,26 +170,15 @@ export function getMouseBoundedPosition(
|
|
|
170
170
|
paddingY = paddingValueY;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
const rubberbandX = rubberbandIfOutOfBounds(
|
|
174
|
-
positionX,
|
|
175
|
-
minPositionX,
|
|
176
|
-
maxPositionX,
|
|
177
|
-
);
|
|
178
|
-
const rubberbandY = rubberbandIfOutOfBounds(
|
|
179
|
-
positionY,
|
|
180
|
-
minPositionY,
|
|
181
|
-
maxPositionY,
|
|
182
|
-
);
|
|
183
|
-
|
|
184
173
|
const x = boundLimiter(
|
|
185
|
-
|
|
174
|
+
positionX,
|
|
186
175
|
minPositionX - paddingX,
|
|
187
176
|
maxPositionX + paddingX,
|
|
188
177
|
limitToBounds,
|
|
189
178
|
);
|
|
190
179
|
|
|
191
180
|
const y = boundLimiter(
|
|
192
|
-
|
|
181
|
+
positionY,
|
|
193
182
|
minPositionY - paddingY,
|
|
194
183
|
maxPositionY + paddingY,
|
|
195
184
|
limitToBounds,
|
|
@@ -208,6 +208,10 @@ export class ZoomPanPinch {
|
|
|
208
208
|
const keysPressed = this.isPressingKeys(this.setup.panning.activationKeys);
|
|
209
209
|
if (!keysPressed) return;
|
|
210
210
|
|
|
211
|
+
if (event.button === 0 && !this.setup.panning.allowLeftClickPan) return;
|
|
212
|
+
if (event.button === 1 && !this.setup.panning.allowMiddleClickPan) return;
|
|
213
|
+
if (event.button === 2 && !this.setup.panning.allowRightClickPan) return;
|
|
214
|
+
|
|
211
215
|
event.preventDefault();
|
|
212
216
|
event.stopPropagation();
|
|
213
217
|
|
|
@@ -81,6 +81,9 @@ export type ReactZoomPanPinchProps = {
|
|
|
81
81
|
velocityDisabled?: boolean;
|
|
82
82
|
lockAxisX?: boolean;
|
|
83
83
|
lockAxisY?: boolean;
|
|
84
|
+
allowLeftClickPan?: boolean;
|
|
85
|
+
allowMiddleClickPan?: boolean;
|
|
86
|
+
allowRightClickPan?: boolean;
|
|
84
87
|
activationKeys?: string[];
|
|
85
88
|
excluded?: string[];
|
|
86
89
|
};
|
|
@@ -248,6 +248,24 @@ export const wrapperPropsTable: ComponentProps = {
|
|
|
248
248
|
description:
|
|
249
249
|
"Disable the panning feature for the Y axis (prevents vertical panning).",
|
|
250
250
|
},
|
|
251
|
+
allowLeftClickPan: {
|
|
252
|
+
type: ["boolean"],
|
|
253
|
+
defaultValue: String(initialSetup.panning.allowLeftClickPan),
|
|
254
|
+
description:
|
|
255
|
+
"Allow left click to initiate panning",
|
|
256
|
+
},
|
|
257
|
+
allowMiddleClickPan: {
|
|
258
|
+
type: ["boolean"],
|
|
259
|
+
defaultValue: String(initialSetup.panning.allowMiddleClickPan),
|
|
260
|
+
description:
|
|
261
|
+
"Allow middle click to initiate panning",
|
|
262
|
+
},
|
|
263
|
+
allowRightClickPan: {
|
|
264
|
+
type: ["boolean"],
|
|
265
|
+
defaultValue: String(initialSetup.panning.allowRightClickPan),
|
|
266
|
+
description:
|
|
267
|
+
"Allow right click to initiate panning",
|
|
268
|
+
},
|
|
251
269
|
activationKeys: {
|
|
252
270
|
type: ["string[]"],
|
|
253
271
|
defaultValue: String(initialSetup.panning.activationKeys),
|