react-zoom-pan-pinch 4.0.6 → 4.1.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/README.md +6 -1
- package/dist/index.cjs.js +486 -132
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +68 -7
- package/dist/index.esm.js +487 -134
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/keep-scale/keep-scale.tsx +13 -4
- package/src/components/mini-map/mini-map.tsx +10 -21
- package/src/components/transform-component/transform-component.tsx +8 -1
- package/src/components/transform-wrapper/transform-wrapper.tsx +14 -1
- package/src/components/virtualize/virtualize.tsx +32 -19
- package/src/core/animations/animations.utils.ts +50 -18
- package/src/core/double-click/double-click.logic.ts +5 -0
- package/src/core/handlers/handlers.logic.ts +160 -28
- package/src/core/handlers/handlers.utils.ts +182 -55
- package/src/core/instance.core.ts +51 -3
- package/src/core/pan/panning.logic.ts +10 -1
- package/src/core/pan/panning.utils.ts +6 -6
- package/src/core/wheel/wheel.logic.ts +13 -2
- package/src/core/wheel/wheel.utils.ts +4 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-transform-component.tsx +1 -1
- package/src/hooks/use-zoom-pan-pinch.tsx +9 -3
- package/src/models/context.model.ts +21 -0
- package/src/utils/context.utils.ts +6 -0
- package/src/utils/effect.utils.ts +11 -0
- package/src/utils/helpers.utils.ts +37 -0
- package/src/utils/index.ts +1 -0
|
@@ -13,6 +13,43 @@ export const isExcludedNode = (
|
|
|
13
13
|
);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
const EDITABLE_TAGS = new Set(["INPUT", "TEXTAREA", "SELECT", "OPTION"]);
|
|
17
|
+
const CONTENT_EDITABLE_SELECTOR =
|
|
18
|
+
'[contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"]';
|
|
19
|
+
const DRAGGABLE_SELECTOR = '[draggable="true"]';
|
|
20
|
+
|
|
21
|
+
const asElement = (node: EventTarget | null): HTMLElement | null => {
|
|
22
|
+
// Duck-typed on purpose: `instanceof Element` fails for nodes that belong
|
|
23
|
+
// to another window (portals, popups), see #290.
|
|
24
|
+
if (!node || typeof (node as HTMLElement).closest !== "function") {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return node as HTMLElement;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Form controls and contenteditable regions (or anything nested inside them).
|
|
32
|
+
* Starting a pan or a double-click zoom from these would steal focus and block
|
|
33
|
+
* native text editing (#437, #544).
|
|
34
|
+
*/
|
|
35
|
+
export const isEditableTarget = (node: EventTarget | null): boolean => {
|
|
36
|
+
const element = asElement(node);
|
|
37
|
+
if (!element) return false;
|
|
38
|
+
if (EDITABLE_TAGS.has(element.tagName)) return true;
|
|
39
|
+
if (element.isContentEditable) return true;
|
|
40
|
+
return element.closest(CONTENT_EDITABLE_SELECTOR) !== null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* HTML5 drag sources (or anything nested inside them). A pan started here
|
|
45
|
+
* would call `preventDefault` on mousedown and cancel the native drag (#460).
|
|
46
|
+
*/
|
|
47
|
+
export const isDraggableTarget = (node: EventTarget | null): boolean => {
|
|
48
|
+
const element = asElement(node);
|
|
49
|
+
if (!element) return false;
|
|
50
|
+
return element.closest(DRAGGABLE_SELECTOR) !== null;
|
|
51
|
+
};
|
|
52
|
+
|
|
16
53
|
export const cancelTimeout = (
|
|
17
54
|
timeout: ReturnType<typeof setTimeout> | null,
|
|
18
55
|
): void => {
|
package/src/utils/index.ts
CHANGED