@tamagui/react-native-use-responder-events 1.13.2 → 1.13.4
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/cjs/ResponderSystem.js +1 -388
- package/dist/cjs/ResponderSystem.js.map +2 -2
- package/dist/cjs/ResponderTouchHistoryStore.js +5 -193
- package/dist/cjs/ResponderTouchHistoryStore.js.map +2 -2
- package/dist/cjs/createResponderEvent.js +1 -150
- package/dist/cjs/createResponderEvent.js.map +2 -2
- package/dist/cjs/index.js +1 -18
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +1 -97
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/useResponderEvents.js +1 -79
- package/dist/cjs/useResponderEvents.js.map +2 -2
- package/dist/cjs/utils.js +2 -173
- package/dist/cjs/utils.js.map +2 -2
- package/dist/esm/ResponderSystem.js +1 -364
- package/dist/esm/ResponderSystem.js.map +2 -2
- package/dist/esm/ResponderSystem.mjs +1 -364
- package/dist/esm/ResponderSystem.mjs.map +2 -2
- package/dist/esm/ResponderTouchHistoryStore.js +5 -169
- package/dist/esm/ResponderTouchHistoryStore.js.map +2 -2
- package/dist/esm/ResponderTouchHistoryStore.mjs +5 -169
- package/dist/esm/ResponderTouchHistoryStore.mjs.map +2 -2
- package/dist/esm/createResponderEvent.js +1 -128
- package/dist/esm/createResponderEvent.js.map +2 -2
- package/dist/esm/createResponderEvent.mjs +1 -128
- package/dist/esm/createResponderEvent.mjs.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/types.js +1 -54
- package/dist/esm/types.js.map +2 -2
- package/dist/esm/types.mjs +1 -54
- package/dist/esm/types.mjs.map +2 -2
- package/dist/esm/useResponderEvents.js +1 -44
- package/dist/esm/useResponderEvents.js.map +2 -2
- package/dist/esm/useResponderEvents.mjs +1 -44
- package/dist/esm/useResponderEvents.mjs.map +2 -2
- package/dist/esm/utils.js +2 -141
- package/dist/esm/utils.js.map +2 -2
- package/dist/esm/utils.mjs +2 -141
- package/dist/esm/utils.mjs.map +2 -2
- package/package.json +2 -2
|
@@ -1,80 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var useResponderEvents_exports = {};
|
|
31
|
-
__export(useResponderEvents_exports, {
|
|
32
|
-
useResponderEvents: () => useResponderEvents
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(useResponderEvents_exports);
|
|
35
|
-
var React = __toESM(require("react"));
|
|
36
|
-
var ResponderSystem = __toESM(require("./ResponderSystem"));
|
|
37
|
-
__reExport(useResponderEvents_exports, require("./utils"), module.exports);
|
|
38
|
-
const emptyObject = {};
|
|
39
|
-
function useResponderEvents(hostRef, config = emptyObject) {
|
|
40
|
-
const id = React.useId();
|
|
41
|
-
const isAttachedRef = React.useRef(false);
|
|
42
|
-
React.useEffect(() => {
|
|
43
|
-
ResponderSystem.attachListeners();
|
|
44
|
-
return () => {
|
|
45
|
-
ResponderSystem.removeNode(id);
|
|
46
|
-
};
|
|
47
|
-
}, [id]);
|
|
48
|
-
React.useEffect(() => {
|
|
49
|
-
const {
|
|
50
|
-
onMoveShouldSetResponder,
|
|
51
|
-
onMoveShouldSetResponderCapture,
|
|
52
|
-
onScrollShouldSetResponder,
|
|
53
|
-
onScrollShouldSetResponderCapture,
|
|
54
|
-
onSelectionChangeShouldSetResponder,
|
|
55
|
-
onSelectionChangeShouldSetResponderCapture,
|
|
56
|
-
onStartShouldSetResponder,
|
|
57
|
-
onStartShouldSetResponderCapture
|
|
58
|
-
} = config;
|
|
59
|
-
const requiresResponderSystem = onMoveShouldSetResponder != null || onMoveShouldSetResponderCapture != null || onScrollShouldSetResponder != null || onScrollShouldSetResponderCapture != null || onSelectionChangeShouldSetResponder != null || onSelectionChangeShouldSetResponderCapture != null || onStartShouldSetResponder != null || onStartShouldSetResponderCapture != null;
|
|
60
|
-
const node = hostRef.current;
|
|
61
|
-
if (requiresResponderSystem) {
|
|
62
|
-
ResponderSystem.addNode(id, node, config);
|
|
63
|
-
isAttachedRef.current = true;
|
|
64
|
-
} else if (isAttachedRef.current) {
|
|
65
|
-
ResponderSystem.removeNode(id);
|
|
66
|
-
isAttachedRef.current = false;
|
|
67
|
-
}
|
|
68
|
-
}, [config, hostRef, id]);
|
|
69
|
-
if (process.env.NODE_ENV === "development") {
|
|
70
|
-
React.useDebugValue({
|
|
71
|
-
isResponder: hostRef.current === ResponderSystem.getResponderNode()
|
|
72
|
-
});
|
|
73
|
-
React.useDebugValue(config);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
-
0 && (module.exports = {
|
|
78
|
-
useResponderEvents
|
|
79
|
-
});
|
|
1
|
+
"use strict";var y=Object.create;var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var V=(e,o)=>{for(var n in o)d(e,n,{get:o[n],enumerable:!0})},l=(e,o,n,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of b(o))!D.call(e,t)&&t!==n&&d(e,t,{get:()=>o[t],enumerable:!(r=E(o,t))||r.enumerable});return e},S=(e,o,n)=>(l(e,o,"default"),n&&l(n,o,"default")),a=(e,o,n)=>(n=e!=null?y(g(e)):{},l(o||!e||!e.__esModule?d(n,"default",{value:e,enumerable:!0}):n,e)),x=e=>l(d({},"__esModule",{value:!0}),e);var p={};V(p,{useResponderEvents:()=>O});module.exports=x(p);var s=a(require("react")),u=a(require("./ResponderSystem"));S(p,require("./utils"),module.exports);const M={};function O(e,o=M){const n=s.useId(),r=s.useRef(!1);s.useEffect(()=>(u.attachListeners(),()=>{u.removeNode(n)}),[n]),s.useEffect(()=>{const{onMoveShouldSetResponder:t,onMoveShouldSetResponderCapture:c,onScrollShouldSetResponder:R,onScrollShouldSetResponderCapture:m,onSelectionChangeShouldSetResponder:f,onSelectionChangeShouldSetResponderCapture:i,onStartShouldSetResponder:h,onStartShouldSetResponderCapture:v}=o,C=t!=null||c!=null||R!=null||m!=null||f!=null||i!=null||h!=null||v!=null,N=e.current;C?(u.addNode(n,N,o),r.current=!0):r.current&&(u.removeNode(n),r.current=!1)},[o,e,n]),process.env.NODE_ENV==="development"&&(s.useDebugValue({isResponder:e.current===u.getResponderNode()}),s.useDebugValue(o))}0&&(module.exports={useResponderEvents});
|
|
80
2
|
//# sourceMappingURL=useResponderEvents.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/useResponderEvents.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Copyright (c) Nicolas Gallagher\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport * as React from 'react'\n\nimport * as ResponderSystem from './ResponderSystem'\n\nexport * from './utils'\n\nconst emptyObject = {}\n\nexport function useResponderEvents(\n hostRef: any,\n config: ResponderSystem.ResponderConfig = emptyObject,\n) {\n const id = React.useId()\n const isAttachedRef = React.useRef(false)\n\n // This is a separate effects so it doesn't run when the config changes.\n // On initial mount, attach global listeners if needed.\n // On unmount, remove node potentially attached to the Responder System.\n React.useEffect(() => {\n ResponderSystem.attachListeners()\n return () => {\n ResponderSystem.removeNode(id)\n }\n }, [id])\n\n // Register and unregister with the Responder System as necessary\n React.useEffect(() => {\n const {\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n } = config\n\n const requiresResponderSystem =\n onMoveShouldSetResponder != null ||\n onMoveShouldSetResponderCapture != null ||\n onScrollShouldSetResponder != null ||\n onScrollShouldSetResponderCapture != null ||\n onSelectionChangeShouldSetResponder != null ||\n onSelectionChangeShouldSetResponderCapture != null ||\n onStartShouldSetResponder != null ||\n onStartShouldSetResponderCapture != null\n\n const node = hostRef.current\n\n if (requiresResponderSystem) {\n ResponderSystem.addNode(id, node, config)\n isAttachedRef.current = true\n } else if (isAttachedRef.current) {\n ResponderSystem.removeNode(id)\n isAttachedRef.current = false\n }\n }, [config, hostRef, id])\n\n if (process.env.NODE_ENV === 'development') {\n React.useDebugValue({\n isResponder: hostRef.current === ResponderSystem.getResponderNode(),\n })\n React.useDebugValue(config)\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "wmBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,eAAAC,EAAAH,GAMA,IAAAI,EAAuB,oBAEvBC,EAAiC,gCAEjCC,EAAAN,EAAc,mBAVd,gBAYA,MAAMO,EAAc,CAAC,EAEd,SAASL,EACdM,EACAC,EAA0CF,EAC1C,CACA,MAAMG,EAAKN,EAAM,MAAM,EACjBO,EAAgBP,EAAM,OAAO,EAAK,EAKxCA,EAAM,UAAU,KACdC,EAAgB,gBAAgB,EACzB,IAAM,CACXA,EAAgB,WAAWK,CAAE,CAC/B,GACC,CAACA,CAAE,CAAC,EAGPN,EAAM,UAAU,IAAM,CACpB,KAAM,CACJ,yBAAAQ,EACA,gCAAAC,EACA,2BAAAC,EACA,kCAAAC,EACA,oCAAAC,EACA,2CAAAC,EACA,0BAAAC,EACA,iCAAAC,CACF,EAAIV,EAEEW,EACJR,GAA4B,MAC5BC,GAAmC,MACnCC,GAA8B,MAC9BC,GAAqC,MACrCC,GAAuC,MACvCC,GAA8C,MAC9CC,GAA6B,MAC7BC,GAAoC,KAEhCE,EAAOb,EAAQ,QAEjBY,GACFf,EAAgB,QAAQK,EAAIW,EAAMZ,CAAM,EACxCE,EAAc,QAAU,IACfA,EAAc,UACvBN,EAAgB,WAAWK,CAAE,EAC7BC,EAAc,QAAU,GAE5B,EAAG,CAACF,EAAQD,EAASE,CAAE,CAAC,EAEpB,QAAQ,IAAI,WAAa,gBAC3BN,EAAM,cAAc,CAClB,YAAaI,EAAQ,UAAYH,EAAgB,iBAAiB,CACpE,CAAC,EACDD,EAAM,cAAcK,CAAM,EAE9B",
|
|
6
|
+
"names": ["useResponderEvents_exports", "__export", "useResponderEvents", "__toCommonJS", "React", "ResponderSystem", "__reExport", "emptyObject", "hostRef", "config", "id", "isAttachedRef", "onMoveShouldSetResponder", "onMoveShouldSetResponderCapture", "onScrollShouldSetResponder", "onScrollShouldSetResponderCapture", "onSelectionChangeShouldSetResponder", "onSelectionChangeShouldSetResponderCapture", "onStartShouldSetResponder", "onStartShouldSetResponderCapture", "requiresResponderSystem", "node"]
|
|
7
7
|
}
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,174 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var utils_exports = {};
|
|
20
|
-
__export(utils_exports, {
|
|
21
|
-
canUseDOM: () => canUseDOM,
|
|
22
|
-
getBoundingClientRect: () => getBoundingClientRect,
|
|
23
|
-
getLowestCommonAncestor: () => getLowestCommonAncestor,
|
|
24
|
-
getResponderPaths: () => getResponderPaths,
|
|
25
|
-
hasTargetTouches: () => hasTargetTouches,
|
|
26
|
-
hasValidSelection: () => hasValidSelection,
|
|
27
|
-
isPrimaryPointerDown: () => isPrimaryPointerDown,
|
|
28
|
-
isSelectionValid: () => isSelectionValid,
|
|
29
|
-
setResponderId: () => setResponderId
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(utils_exports);
|
|
32
|
-
const keyName = "__reactResponderId";
|
|
33
|
-
const canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
34
|
-
const getBoundingClientRect = (node) => {
|
|
35
|
-
if (!node)
|
|
36
|
-
return;
|
|
37
|
-
if (node.nodeType !== 1)
|
|
38
|
-
return;
|
|
39
|
-
if (node.getBoundingClientRect) {
|
|
40
|
-
return node.getBoundingClientRect();
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
function getEventPath(domEvent) {
|
|
44
|
-
var _a;
|
|
45
|
-
if (domEvent.type === "selectionchange") {
|
|
46
|
-
const target = (_a = window.getSelection()) == null ? void 0 : _a.anchorNode;
|
|
47
|
-
return composedPathFallback(target);
|
|
48
|
-
} else {
|
|
49
|
-
const path = domEvent.composedPath != null ? domEvent.composedPath() : composedPathFallback(domEvent.target);
|
|
50
|
-
return path;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function composedPathFallback(target) {
|
|
54
|
-
const path = [];
|
|
55
|
-
while (target != null && target !== document.body) {
|
|
56
|
-
path.push(target);
|
|
57
|
-
target = target.parentNode;
|
|
58
|
-
}
|
|
59
|
-
return path;
|
|
60
|
-
}
|
|
61
|
-
function getResponderId(node) {
|
|
62
|
-
if (node != null) {
|
|
63
|
-
return node[keyName];
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
function setResponderId(node, id) {
|
|
68
|
-
if (node != null) {
|
|
69
|
-
node[keyName] = id;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function getResponderPaths(domEvent) {
|
|
73
|
-
const idPath = [];
|
|
74
|
-
const nodePath = [];
|
|
75
|
-
const eventPath = getEventPath(domEvent);
|
|
76
|
-
for (let i = 0; i < eventPath.length; i++) {
|
|
77
|
-
const node = eventPath[i];
|
|
78
|
-
const id = getResponderId(node);
|
|
79
|
-
if (id != null) {
|
|
80
|
-
idPath.push(id);
|
|
81
|
-
nodePath.push(node);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return { idPath, nodePath };
|
|
85
|
-
}
|
|
86
|
-
function getLowestCommonAncestor(pathA, pathB) {
|
|
87
|
-
let pathALength = pathA.length;
|
|
88
|
-
let pathBLength = pathB.length;
|
|
89
|
-
if (
|
|
90
|
-
// If either path is empty
|
|
91
|
-
pathALength === 0 || pathBLength === 0 || // If the last elements aren't the same there can't be a common ancestor
|
|
92
|
-
// that is connected to the responder system
|
|
93
|
-
pathA[pathALength - 1] !== pathB[pathBLength - 1]
|
|
94
|
-
) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
let itemA = pathA[0];
|
|
98
|
-
let indexA = 0;
|
|
99
|
-
let itemB = pathB[0];
|
|
100
|
-
let indexB = 0;
|
|
101
|
-
if (pathALength - pathBLength > 0) {
|
|
102
|
-
indexA = pathALength - pathBLength;
|
|
103
|
-
itemA = pathA[indexA];
|
|
104
|
-
pathALength = pathBLength;
|
|
105
|
-
}
|
|
106
|
-
if (pathBLength - pathALength > 0) {
|
|
107
|
-
indexB = pathBLength - pathALength;
|
|
108
|
-
itemB = pathB[indexB];
|
|
109
|
-
pathBLength = pathALength;
|
|
110
|
-
}
|
|
111
|
-
let depth = pathALength;
|
|
112
|
-
while (depth--) {
|
|
113
|
-
if (itemA === itemB) {
|
|
114
|
-
return itemA;
|
|
115
|
-
}
|
|
116
|
-
itemA = pathA[indexA++];
|
|
117
|
-
itemB = pathB[indexB++];
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
function hasTargetTouches(target, touches) {
|
|
122
|
-
if (!touches || touches.length === 0) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
for (let i = 0; i < touches.length; i++) {
|
|
126
|
-
const node = touches[i].target;
|
|
127
|
-
if (node != null) {
|
|
128
|
-
if (target.contains(node)) {
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
function hasValidSelection(domEvent) {
|
|
136
|
-
if (domEvent.type === "selectionchange") {
|
|
137
|
-
return isSelectionValid();
|
|
138
|
-
}
|
|
139
|
-
return domEvent.type === "select";
|
|
140
|
-
}
|
|
141
|
-
function isPrimaryPointerDown(domEvent) {
|
|
142
|
-
const { altKey, button, buttons, ctrlKey, type } = domEvent;
|
|
143
|
-
const isTouch = type === "touchstart" || type === "touchmove";
|
|
144
|
-
const isPrimaryMouseDown = type === "mousedown" && (button === 0 || buttons === 1);
|
|
145
|
-
const isPrimaryMouseMove = type === "mousemove" && buttons === 1;
|
|
146
|
-
const noModifiers = altKey === false && ctrlKey === false;
|
|
147
|
-
if (isTouch || isPrimaryMouseDown && noModifiers || isPrimaryMouseMove && noModifiers) {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
function isSelectionValid() {
|
|
153
|
-
const selection = window.getSelection();
|
|
154
|
-
if (!selection)
|
|
155
|
-
return false;
|
|
156
|
-
const string = selection.toString();
|
|
157
|
-
const anchorNode = selection.anchorNode;
|
|
158
|
-
const focusNode = selection.focusNode;
|
|
159
|
-
const isTextNode = anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE || focusNode && focusNode.nodeType === window.Node.TEXT_NODE;
|
|
160
|
-
return string.length >= 1 && string !== "\n" && !!isTextNode;
|
|
161
|
-
}
|
|
162
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
-
0 && (module.exports = {
|
|
164
|
-
canUseDOM,
|
|
165
|
-
getBoundingClientRect,
|
|
166
|
-
getLowestCommonAncestor,
|
|
167
|
-
getResponderPaths,
|
|
168
|
-
hasTargetTouches,
|
|
169
|
-
hasValidSelection,
|
|
170
|
-
isPrimaryPointerDown,
|
|
171
|
-
isSelectionValid,
|
|
172
|
-
setResponderId
|
|
173
|
-
});
|
|
1
|
+
"use strict";var u=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var w=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},m=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!g.call(n,r)&&r!==t&&u(n,r,{get:()=>e[r],enumerable:!(o=h(e,r))||o.enumerable});return n};var P=n=>m(u({},"__esModule",{value:!0}),n);var L={};w(L,{canUseDOM:()=>x,getBoundingClientRect:()=>N,getLowestCommonAncestor:()=>A,getResponderPaths:()=>M,hasTargetTouches:()=>D,hasValidSelection:()=>S,isPrimaryPointerDown:()=>C,isSelectionValid:()=>y,setResponderId:()=>R});module.exports=P(L);const d="__reactResponderId",x=!!(typeof window<"u"&&window.document&&window.document.createElement),N=n=>{if(n&&n.nodeType===1&&n.getBoundingClientRect)return n.getBoundingClientRect()};function T(n){var e;if(n.type==="selectionchange"){const t=(e=window.getSelection())==null?void 0:e.anchorNode;return f(t)}else return n.composedPath!=null?n.composedPath():f(n.target)}function f(n){const e=[];for(;n!=null&&n!==document.body;)e.push(n),n=n.parentNode;return e}function b(n){return n!=null?n[d]:null}function R(n,e){n!=null&&(n[d]=e)}function M(n){const e=[],t=[],o=T(n);for(let r=0;r<o.length;r++){const i=o[r],l=b(i);l!=null&&(e.push(l),t.push(i))}return{idPath:e,nodePath:t}}function A(n,e){let t=n.length,o=e.length;if(t===0||o===0||n[t-1]!==e[o-1])return null;let r=n[0],i=0,l=e[0],c=0;t-o>0&&(i=t-o,r=n[i],t=o),o-t>0&&(c=o-t,l=e[c],o=t);let s=t;for(;s--;){if(r===l)return r;r=n[i++],l=e[c++]}return null}function D(n,e){if(!e||e.length===0)return!1;for(let t=0;t<e.length;t++){const o=e[t].target;if(o!=null&&n.contains(o))return!0}return!1}function S(n){return n.type==="selectionchange"?y():n.type==="select"}function C(n){const{altKey:e,button:t,buttons:o,ctrlKey:r,type:i}=n,l=i==="touchstart"||i==="touchmove",c=i==="mousedown"&&(t===0||o===1),s=i==="mousemove"&&o===1,a=e===!1&&r===!1;return!!(l||c&&a||s&&a)}function y(){const n=window.getSelection();if(!n)return!1;const e=n.toString(),t=n.anchorNode,o=n.focusNode,r=t&&t.nodeType===window.Node.TEXT_NODE||o&&o.nodeType===window.Node.TEXT_NODE;return e.length>=1&&e!==`
|
|
2
|
+
`&&!!r}0&&(module.exports={canUseDOM,getBoundingClientRect,getLowestCommonAncestor,getResponderPaths,hasTargetTouches,hasValidSelection,isPrimaryPointerDown,isSelectionValid,setResponderId});
|
|
174
3
|
//# sourceMappingURL=utils.js.map
|
package/dist/cjs/utils.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Copyright (c) Nicolas Gallagher\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nconst keyName = '__reactResponderId'\n\nexport const canUseDOM = !!(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n)\n\nexport const getBoundingClientRect = (node: HTMLElement | null): void | DOMRect => {\n if (!node) return\n if (node.nodeType !== 1) return\n if (node.getBoundingClientRect) {\n return node.getBoundingClientRect()\n }\n}\n\nfunction getEventPath(domEvent: any): Array<any> {\n // The 'selectionchange' event always has the 'document' as the target.\n // Use the anchor node as the initial target to reconstruct a path.\n // (We actually only need the first \"responder\" node in practice.)\n if (domEvent.type === 'selectionchange') {\n const target = window.getSelection()?.anchorNode\n return composedPathFallback(target)\n } else {\n const path =\n domEvent.composedPath != null\n ? domEvent.composedPath()\n : composedPathFallback(domEvent.target)\n return path\n }\n}\n\nfunction composedPathFallback(target: any): Array<any> {\n const path: any[] = []\n while (target != null && target !== document.body) {\n path.push(target)\n target = target.parentNode\n }\n return path\n}\n\n/**\n * Retrieve the responderId from a host node\n */\nfunction getResponderId(node: any): number | null {\n if (node != null) {\n return node[keyName]\n }\n return null\n}\n\n/**\n * Store the responderId on a host node\n */\nexport function setResponderId(node: any, id: any) {\n if (node != null) {\n node[keyName] = id\n }\n}\n\n/**\n * Filter the event path to contain only the nodes attached to the responder system\n */\nexport function getResponderPaths(domEvent: any): {\n idPath: Array<number>\n nodePath: Array<any>\n} {\n const idPath: any[] = []\n const nodePath: any[] = []\n const eventPath = getEventPath(domEvent)\n for (let i = 0; i < eventPath.length; i++) {\n const node = eventPath[i]\n const id = getResponderId(node)\n if (id != null) {\n idPath.push(id)\n nodePath.push(node)\n }\n }\n return { idPath, nodePath }\n}\n\n/**\n * Walk the paths and find the first common ancestor\n */\nexport function getLowestCommonAncestor(pathA: Array<any>, pathB: Array<any>): any {\n let pathALength = pathA.length\n let pathBLength = pathB.length\n if (\n // If either path is empty\n pathALength === 0 ||\n pathBLength === 0 ||\n // If the last elements aren't the same there can't be a common ancestor\n // that is connected to the responder system\n pathA[pathALength - 1] !== pathB[pathBLength - 1]\n ) {\n return null\n }\n\n let itemA = pathA[0]\n let indexA = 0\n let itemB = pathB[0]\n let indexB = 0\n\n // If A is deeper, skip indices that can't match.\n if (pathALength - pathBLength > 0) {\n indexA = pathALength - pathBLength\n itemA = pathA[indexA]\n pathALength = pathBLength\n }\n\n // If B is deeper, skip indices that can't match\n if (pathBLength - pathALength > 0) {\n indexB = pathBLength - pathALength\n itemB = pathB[indexB]\n pathBLength = pathALength\n }\n\n // Walk in lockstep until a match is found\n let depth = pathALength\n while (depth--) {\n if (itemA === itemB) {\n return itemA\n }\n itemA = pathA[indexA++]\n itemB = pathB[indexB++]\n }\n return null\n}\n\n/**\n * Determine whether any of the active touches are within the current responder.\n * This cannot rely on W3C `targetTouches`, as neither IE11 nor Safari implement it.\n */\nexport function hasTargetTouches(target: any, touches: any): boolean {\n if (!touches || touches.length === 0) {\n return false\n }\n for (let i = 0; i < touches.length; i++) {\n const node = touches[i].target\n if (node != null) {\n if (target.contains(node)) {\n return true\n }\n }\n }\n return false\n}\n\n/**\n * Ignore 'selectionchange' events that don't correspond with a person's intent to\n * select text.\n */\nexport function hasValidSelection(domEvent: any): boolean {\n if (domEvent.type === 'selectionchange') {\n return isSelectionValid()\n }\n return domEvent.type === 'select'\n}\n\n/**\n * Events are only valid if the primary button was used without specific modifier keys.\n */\nexport function isPrimaryPointerDown(domEvent: any): boolean {\n const { altKey, button, buttons, ctrlKey, type } = domEvent\n const isTouch = type === 'touchstart' || type === 'touchmove'\n const isPrimaryMouseDown = type === 'mousedown' && (button === 0 || buttons === 1)\n const isPrimaryMouseMove = type === 'mousemove' && buttons === 1\n const noModifiers = altKey === false && ctrlKey === false\n\n if (\n isTouch ||\n (isPrimaryMouseDown && noModifiers) ||\n (isPrimaryMouseMove && noModifiers)\n ) {\n return true\n }\n return false\n}\n\nexport function isSelectionValid(): boolean {\n const selection = window.getSelection()\n if (!selection) return false\n const string = selection.toString()\n const anchorNode = selection.anchorNode\n const focusNode = selection.focusNode\n const isTextNode =\n (anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE) ||\n (focusNode && focusNode.nodeType === window.Node.TEXT_NODE)\n return string.length >= 1 && string !== '\\n' && !!isTextNode\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,0BAAAC,EAAA,4BAAAC,EAAA,sBAAAC,EAAA,qBAAAC,EAAA,sBAAAC,EAAA,yBAAAC,EAAA,qBAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAX,GAMA,MAAMY,EAAU,qBAEHV,EAAY,CAAC,EACxB,OAAO,OAAW,KAClB,OAAO,UACP,OAAO,SAAS,eAGLC,EAAyBU,GAA6C,CACjF,GAAKA,GACDA,EAAK,WAA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AAU,WAAa,OAAO,KAAK,UACnD,OAAOF,EAAO,QAAU,GAAKA,IAAW;AAAA,GAAQ,CAAC,CAACG,CACpD",
|
|
6
|
+
"names": ["utils_exports", "__export", "canUseDOM", "getBoundingClientRect", "getLowestCommonAncestor", "getResponderPaths", "hasTargetTouches", "hasValidSelection", "isPrimaryPointerDown", "isSelectionValid", "setResponderId", "__toCommonJS", "keyName", "node", "getEventPath", "domEvent", "_a", "target", "composedPathFallback", "path", "getResponderId", "id", "idPath", "nodePath", "eventPath", "i", "pathA", "pathB", "pathALength", "pathBLength", "itemA", "indexA", "itemB", "indexB", "depth", "touches", "altKey", "button", "buttons", "ctrlKey", "type", "isTouch", "isPrimaryMouseDown", "isPrimaryMouseMove", "noModifiers", "selection", "string", "anchorNode", "focusNode", "isTextNode"]
|
|
7
7
|
}
|