@tamagui/react-native-use-responder-events 2.7.7 → 3.0.0-beta.643.1
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.cjs +307 -344
- package/dist/cjs/ResponderSystem.native.cjs +357 -0
- package/dist/cjs/ResponderSystem.native.js +307 -343
- package/dist/cjs/ResponderSystem.native.js.map +1 -1
- package/dist/cjs/ResponderTouchHistoryStore.cjs +136 -149
- package/dist/cjs/ResponderTouchHistoryStore.native.cjs +217 -0
- package/dist/cjs/ResponderTouchHistoryStore.native.js +176 -189
- package/dist/cjs/ResponderTouchHistoryStore.native.js.map +1 -1
- package/dist/cjs/createResponderEvent.cjs +128 -132
- package/dist/cjs/createResponderEvent.native.cjs +147 -0
- package/dist/cjs/createResponderEvent.native.js +129 -132
- package/dist/cjs/createResponderEvent.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/types.cjs +40 -41
- package/dist/cjs/types.native.cjs +79 -0
- package/dist/cjs/types.native.js +40 -40
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/cjs/useResponderEvents.cjs +60 -85
- package/dist/cjs/useResponderEvents.native.cjs +87 -0
- package/dist/cjs/useResponderEvents.native.js +62 -86
- package/dist/cjs/useResponderEvents.native.js.map +1 -1
- package/dist/cjs/utils.cjs +123 -135
- package/dist/cjs/utils.native.cjs +160 -0
- package/dist/cjs/utils.native.js +124 -135
- package/dist/cjs/utils.native.js.map +1 -1
- package/dist/esm/ResponderSystem.mjs +291 -326
- package/dist/esm/ResponderSystem.mjs.map +1 -1
- package/dist/esm/ResponderSystem.native.js +291 -326
- package/dist/esm/ResponderSystem.native.js.map +1 -1
- package/dist/esm/ResponderTouchHistoryStore.mjs +123 -131
- package/dist/esm/ResponderTouchHistoryStore.mjs.map +1 -1
- package/dist/esm/ResponderTouchHistoryStore.native.js +163 -172
- package/dist/esm/ResponderTouchHistoryStore.native.js.map +1 -1
- package/dist/esm/createResponderEvent.mjs +115 -114
- package/dist/esm/createResponderEvent.mjs.map +1 -1
- package/dist/esm/createResponderEvent.native.js +116 -115
- package/dist/esm/createResponderEvent.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/esm/types.mjs +7 -6
- package/dist/esm/types.mjs.map +1 -1
- package/dist/esm/types.native.js +7 -6
- package/dist/esm/types.native.js.map +1 -1
- package/dist/esm/useResponderEvents.mjs +45 -61
- package/dist/esm/useResponderEvents.mjs.map +1 -1
- package/dist/esm/useResponderEvents.native.js +47 -63
- package/dist/esm/useResponderEvents.native.js.map +1 -1
- package/dist/esm/utils.mjs +101 -111
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/utils.native.js +102 -112
- package/dist/esm/utils.native.js.map +1 -1
- package/package.json +2 -2
- package/types/ResponderTouchHistoryStore.d.ts.map +1 -1
- package/types/utils.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
|
@@ -1,72 +1,56 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as ResponderSystem from "./ResponderSystem.native.js";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
export * from "./utils.native.js"
|
|
5
|
+
|
|
4
6
|
var emptyObject = {};
|
|
5
|
-
var Attached = /* @__PURE__ */new WeakMap();
|
|
6
|
-
var Ids = /* @__PURE__ */new WeakMap();
|
|
7
|
+
var Attached = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
var Ids = /* @__PURE__ */ new WeakMap();
|
|
7
9
|
function useResponderEvents(hostRef) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
React.useDebugValue(config);
|
|
31
|
-
}
|
|
10
|
+
var configIn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : emptyObject;
|
|
11
|
+
var _hostRef_current;
|
|
12
|
+
var config = getResponderConfigIfDefined(configIn);
|
|
13
|
+
var node = (hostRef === null || hostRef === void 0 ? void 0 : (_hostRef_current = hostRef.current) === null || _hostRef_current === void 0 ? void 0 : _hostRef_current.host) || (hostRef === null || hostRef === void 0 ? void 0 : hostRef.current);
|
|
14
|
+
React.useEffect(function() {
|
|
15
|
+
if (config === emptyObject) return;
|
|
16
|
+
ResponderSystem.attachListeners();
|
|
17
|
+
if (!Ids.has(hostRef)) {
|
|
18
|
+
Ids.set(hostRef, `${Math.random()}`);
|
|
19
|
+
}
|
|
20
|
+
var id = Ids.get(hostRef);
|
|
21
|
+
ResponderSystem.addNode(id, node, config);
|
|
22
|
+
Attached.set(hostRef, true);
|
|
23
|
+
return function() {
|
|
24
|
+
ResponderSystem.removeNode(node);
|
|
25
|
+
Attached.set(hostRef, false);
|
|
26
|
+
};
|
|
27
|
+
}, [config, hostRef]);
|
|
28
|
+
if (process.env.NODE_ENV === "development") {
|
|
29
|
+
React.useDebugValue({ isResponder: node === ResponderSystem.getResponderNode() });
|
|
30
|
+
React.useDebugValue(config);
|
|
31
|
+
}
|
|
32
32
|
}
|
|
33
33
|
function getResponderConfigIfDefined(param) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
onMoveShouldSetResponder,
|
|
54
|
-
onMoveShouldSetResponderCapture,
|
|
55
|
-
onResponderEnd,
|
|
56
|
-
onResponderGrant,
|
|
57
|
-
onResponderMove,
|
|
58
|
-
onResponderReject,
|
|
59
|
-
onResponderRelease,
|
|
60
|
-
onResponderStart,
|
|
61
|
-
onResponderTerminate,
|
|
62
|
-
onResponderTerminationRequest,
|
|
63
|
-
onScrollShouldSetResponder,
|
|
64
|
-
onScrollShouldSetResponderCapture,
|
|
65
|
-
onSelectionChangeShouldSetResponder,
|
|
66
|
-
onSelectionChangeShouldSetResponderCapture,
|
|
67
|
-
onStartShouldSetResponder,
|
|
68
|
-
onStartShouldSetResponderCapture
|
|
69
|
-
} : emptyObject;
|
|
34
|
+
var { onMoveShouldSetResponder, onMoveShouldSetResponderCapture, onResponderEnd, onResponderGrant, onResponderMove, onResponderReject, onResponderRelease, onResponderStart, onResponderTerminate, onResponderTerminationRequest, onScrollShouldSetResponder, onScrollShouldSetResponderCapture, onSelectionChangeShouldSetResponder, onSelectionChangeShouldSetResponderCapture, onStartShouldSetResponder, onStartShouldSetResponderCapture } = param;
|
|
35
|
+
return onMoveShouldSetResponder || onMoveShouldSetResponderCapture || onResponderEnd || onResponderGrant || onResponderMove || onResponderReject || onResponderRelease || onResponderStart || onResponderTerminate || onResponderTerminationRequest || onScrollShouldSetResponder || onScrollShouldSetResponderCapture || onSelectionChangeShouldSetResponder || onSelectionChangeShouldSetResponderCapture || onStartShouldSetResponder || onStartShouldSetResponderCapture ? {
|
|
36
|
+
onMoveShouldSetResponder,
|
|
37
|
+
onMoveShouldSetResponderCapture,
|
|
38
|
+
onResponderEnd,
|
|
39
|
+
onResponderGrant,
|
|
40
|
+
onResponderMove,
|
|
41
|
+
onResponderReject,
|
|
42
|
+
onResponderRelease,
|
|
43
|
+
onResponderStart,
|
|
44
|
+
onResponderTerminate,
|
|
45
|
+
onResponderTerminationRequest,
|
|
46
|
+
onScrollShouldSetResponder,
|
|
47
|
+
onScrollShouldSetResponderCapture,
|
|
48
|
+
onSelectionChangeShouldSetResponder,
|
|
49
|
+
onSelectionChangeShouldSetResponderCapture,
|
|
50
|
+
onStartShouldSetResponder,
|
|
51
|
+
onStartShouldSetResponderCapture
|
|
52
|
+
} : emptyObject;
|
|
70
53
|
}
|
|
54
|
+
|
|
71
55
|
export { getResponderConfigIfDefined, useResponderEvents };
|
|
72
56
|
//# sourceMappingURL=useResponderEvents.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useResponderEvents.native.js","names":[],"sources":["esm/useResponderEvents.native.js"],"sourcesContent":["import * as React from \"react\";\nimport * as ResponderSystem from \"./ResponderSystem\";\nexport * from \"./utils\";\nvar emptyObject = {};\nvar Attached = /* @__PURE__ */ new WeakMap();\nvar Ids = /* @__PURE__ */ new WeakMap();\nfunction useResponderEvents(hostRef) {\n var configIn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : emptyObject;\n var _hostRef_current;\n var config = getResponderConfigIfDefined(configIn);\n var node = (hostRef === null || hostRef === void 0 ? void 0 : (_hostRef_current = hostRef.current) === null || _hostRef_current === void 0 ? void 0 : _hostRef_current.host) || (hostRef === null || hostRef === void 0 ? void 0 : hostRef.current);\n React.useEffect(function() {\n if (config === emptyObject) return;\n ResponderSystem.attachListeners();\n if (!Ids.has(hostRef)) {\n Ids.set(hostRef, `${Math.random()}`);\n }\n var id = Ids.get(hostRef);\n ResponderSystem.addNode(id, node, config);\n Attached.set(hostRef, true);\n return function() {\n ResponderSystem.removeNode(node);\n Attached.set(hostRef, false);\n };\n }, [\n config,\n hostRef\n ]);\n if (process.env.NODE_ENV === \"development\") {\n React.useDebugValue({\n isResponder: node === ResponderSystem.getResponderNode()\n });\n React.useDebugValue(config);\n }\n}\nfunction getResponderConfigIfDefined(param) {\n var { onMoveShouldSetResponder, onMoveShouldSetResponderCapture, onResponderEnd, onResponderGrant, onResponderMove, onResponderReject, onResponderRelease, onResponderStart, onResponderTerminate, onResponderTerminationRequest, onScrollShouldSetResponder, onScrollShouldSetResponderCapture, onSelectionChangeShouldSetResponder, onSelectionChangeShouldSetResponderCapture, onStartShouldSetResponder, onStartShouldSetResponderCapture } = param;\n return onMoveShouldSetResponder || onMoveShouldSetResponderCapture || onResponderEnd || onResponderGrant || onResponderMove || onResponderReject || onResponderRelease || onResponderStart || onResponderTerminate || onResponderTerminationRequest || onScrollShouldSetResponder || onScrollShouldSetResponderCapture || onSelectionChangeShouldSetResponder || onSelectionChangeShouldSetResponderCapture || onStartShouldSetResponder || onStartShouldSetResponderCapture ? {\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture\n } : emptyObject;\n}\nexport {\n getResponderConfigIfDefined,\n useResponderEvents\n};\n//# sourceMappingURL=useResponderEvents.js.map\n"],"mappings":";;;;;;AAGA,IAAI,cAAc,CAAC;AACnB,IAAI,2BAA2B,IAAI,QAAQ;AAC3C,IAAI,sBAAsB,IAAI,QAAQ;AACtC,SAAS,mBAAmB,SAAS;CACnC,IAAI,WAAW,UAAU,SAAS,KAAK,UAAU,OAAO,KAAK,IAAI,UAAU,KAAK;CAChF,IAAI;CACJ,IAAI,SAAS,4BAA4B,QAAQ;CACjD,IAAI,QAAQ,YAAY,QAAQ,YAAY,KAAK,IAAI,KAAK,KAAK,mBAAmB,QAAQ,aAAa,QAAQ,qBAAqB,KAAK,IAAI,KAAK,IAAI,iBAAiB,UAAU,YAAY,QAAQ,YAAY,KAAK,IAAI,KAAK,IAAI,QAAQ;CAC3O,MAAM,UAAU,WAAW;EACzB,IAAI,WAAW,aAAa;EAC5B,gBAAgB,gBAAgB;EAChC,IAAI,CAAC,IAAI,IAAI,OAAO,GAAG;GACrB,IAAI,IAAI,SAAS,GAAG,KAAK,OAAO,GAAG;EACrC;EACA,IAAI,KAAK,IAAI,IAAI,OAAO;EACxB,gBAAgB,QAAQ,IAAI,MAAM,MAAM;EACxC,SAAS,IAAI,SAAS,IAAI;EAC1B,OAAO,WAAW;GAChB,gBAAgB,WAAW,IAAI;GAC/B,SAAS,IAAI,SAAS,KAAK;EAC7B;CACF,GAAG,CACD,QACA,OACF,CAAC;CACD,IAAI,QAAQ,IAAI,aAAa,eAAe;EAC1C,MAAM,cAAc,EAClB,aAAa,SAAS,gBAAgB,iBAAiB,EACzD,CAAC;EACD,MAAM,cAAc,MAAM;CAC5B;AACF;AACA,SAAS,4BAA4B,OAAO;CAC1C,IAAI,EAAE,0BAA0B,iCAAiC,gBAAgB,kBAAkB,iBAAiB,mBAAmB,oBAAoB,kBAAkB,sBAAsB,+BAA+B,4BAA4B,mCAAmC,qCAAqC,4CAA4C,2BAA2B,qCAAqC;CAClb,OAAO,4BAA4B,mCAAmC,kBAAkB,oBAAoB,mBAAmB,qBAAqB,sBAAsB,oBAAoB,wBAAwB,iCAAiC,8BAA8B,qCAAqC,uCAAuC,8CAA8C,6BAA6B,mCAAmC;EAC7c;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IAAI;AACN"}
|
package/dist/esm/utils.mjs
CHANGED
|
@@ -1,136 +1,126 @@
|
|
|
1
1
|
const keyName = "__reactResponderId";
|
|
2
2
|
const canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
3
|
-
const getBoundingClientRect = node => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const getBoundingClientRect = (node) => {
|
|
4
|
+
if (!node) return;
|
|
5
|
+
if (node.nodeType !== 1) return;
|
|
6
|
+
if (node.getBoundingClientRect) {
|
|
7
|
+
return node.getBoundingClientRect();
|
|
8
|
+
}
|
|
9
9
|
};
|
|
10
10
|
function getEventPath(domEvent) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
if (domEvent.type === "selectionchange") {
|
|
12
|
+
const target = window.getSelection()?.anchorNode;
|
|
13
|
+
return composedPathFallback(target);
|
|
14
|
+
}
|
|
15
|
+
const path = domEvent.composedPath != null ? domEvent.composedPath() : composedPathFallback(domEvent.target);
|
|
16
|
+
return path;
|
|
17
17
|
}
|
|
18
18
|
function composedPathFallback(target) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const path = [];
|
|
20
|
+
while (target != null && target !== document.body) {
|
|
21
|
+
path.push(target);
|
|
22
|
+
target = target.parentNode;
|
|
23
|
+
}
|
|
24
|
+
return path;
|
|
25
25
|
}
|
|
26
26
|
function getResponderId(node) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
if (node != null) {
|
|
28
|
+
return node[keyName];
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
31
|
}
|
|
32
32
|
function setResponderId(node, id) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if (node != null) {
|
|
34
|
+
node[keyName] = id;
|
|
35
|
+
}
|
|
36
36
|
}
|
|
37
37
|
function getResponderPaths(domEvent) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
const idPath = [];
|
|
39
|
+
const nodePath = [];
|
|
40
|
+
const eventPath = getEventPath(domEvent);
|
|
41
|
+
for (let i = 0; i < eventPath.length; i++) {
|
|
42
|
+
const node = eventPath[i];
|
|
43
|
+
const id = getResponderId(node);
|
|
44
|
+
if (id != null) {
|
|
45
|
+
idPath.push(id);
|
|
46
|
+
nodePath.push(node);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
idPath,
|
|
51
|
+
nodePath
|
|
52
|
+
};
|
|
53
53
|
}
|
|
54
54
|
function getLowestCommonAncestor(pathA, pathB) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
itemA = pathA[indexA++];
|
|
85
|
-
itemB = pathB[indexB++];
|
|
86
|
-
}
|
|
87
|
-
return null;
|
|
55
|
+
let pathALength = pathA.length;
|
|
56
|
+
let pathBLength = pathB.length;
|
|
57
|
+
if (pathALength === 0 || pathBLength === 0 || pathA[pathALength - 1] !== pathB[pathBLength - 1]) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
let itemA = pathA[0];
|
|
61
|
+
let indexA = 0;
|
|
62
|
+
let itemB = pathB[0];
|
|
63
|
+
let indexB = 0;
|
|
64
|
+
if (pathALength - pathBLength > 0) {
|
|
65
|
+
indexA = pathALength - pathBLength;
|
|
66
|
+
itemA = pathA[indexA];
|
|
67
|
+
pathALength = pathBLength;
|
|
68
|
+
}
|
|
69
|
+
if (pathBLength - pathALength > 0) {
|
|
70
|
+
indexB = pathBLength - pathALength;
|
|
71
|
+
itemB = pathB[indexB];
|
|
72
|
+
pathBLength = pathALength;
|
|
73
|
+
}
|
|
74
|
+
let depth = pathALength;
|
|
75
|
+
while (depth--) {
|
|
76
|
+
if (itemA === itemB) {
|
|
77
|
+
return itemA;
|
|
78
|
+
}
|
|
79
|
+
itemA = pathA[indexA++];
|
|
80
|
+
itemB = pathB[indexB++];
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
88
83
|
}
|
|
89
84
|
function hasTargetTouches(target, touches) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
85
|
+
if (!touches || touches.length === 0) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
for (let i = 0; i < touches.length; i++) {
|
|
89
|
+
const node = touches[i].target;
|
|
90
|
+
if (node != null) {
|
|
91
|
+
if (target.contains(node)) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
102
97
|
}
|
|
103
98
|
function hasValidSelection(domEvent) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
if (domEvent.type === "selectionchange") {
|
|
100
|
+
return isSelectionValid();
|
|
101
|
+
}
|
|
102
|
+
return domEvent.type === "select";
|
|
108
103
|
}
|
|
109
104
|
function isPrimaryPointerDown(domEvent) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const isPrimaryMouseMove = type === "mousemove" && buttons === 1;
|
|
120
|
-
const noModifiers = altKey === false && ctrlKey === false;
|
|
121
|
-
if (isTouch || isPrimaryMouseDown && noModifiers || isPrimaryMouseMove && noModifiers) {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
105
|
+
const { altKey, button, buttons, ctrlKey, type } = domEvent;
|
|
106
|
+
const isTouch = type === "touchstart" || type === "touchmove";
|
|
107
|
+
const isPrimaryMouseDown = type === "mousedown" && (button === 0 || buttons === 1);
|
|
108
|
+
const isPrimaryMouseMove = type === "mousemove" && buttons === 1;
|
|
109
|
+
const noModifiers = altKey === false && ctrlKey === false;
|
|
110
|
+
if (isTouch || isPrimaryMouseDown && noModifiers || isPrimaryMouseMove && noModifiers) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
125
114
|
}
|
|
126
115
|
function isSelectionValid() {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
116
|
+
const selection = window.getSelection();
|
|
117
|
+
if (!selection) return false;
|
|
118
|
+
const string = selection.toString();
|
|
119
|
+
const anchorNode = selection.anchorNode;
|
|
120
|
+
const focusNode = selection.focusNode;
|
|
121
|
+
const isTextNode = anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE || focusNode && focusNode.nodeType === window.Node.TEXT_NODE;
|
|
122
|
+
return string.length >= 1 && string !== "\n" && !!isTextNode;
|
|
134
123
|
}
|
|
124
|
+
|
|
135
125
|
export { canUseDOM, getBoundingClientRect, getLowestCommonAncestor, getResponderPaths, hasTargetTouches, hasValidSelection, isPrimaryPointerDown, isSelectionValid, setResponderId };
|
|
136
126
|
//# sourceMappingURL=utils.mjs.map
|
package/dist/esm/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["esm/utils.js"],"sourcesContent":["const keyName = \"__reactResponderId\";\nconst canUseDOM = !!(typeof window !== \"undefined\" && window.document && window.document.createElement);\nconst getBoundingClientRect = (node) => {\n if (!node) return;\n if (node.nodeType !== 1) return;\n if (node.getBoundingClientRect) {\n return node.getBoundingClientRect();\n }\n};\nfunction getEventPath(domEvent) {\n if (domEvent.type === \"selectionchange\") {\n const target = window.getSelection()?.anchorNode;\n return composedPathFallback(target);\n }\n const path = domEvent.composedPath != null ? domEvent.composedPath() : composedPathFallback(domEvent.target);\n return path;\n}\nfunction composedPathFallback(target) {\n const path = [];\n while (target != null && target !== document.body) {\n path.push(target);\n target = target.parentNode;\n }\n return path;\n}\nfunction getResponderId(node) {\n if (node != null) {\n return node[keyName];\n }\n return null;\n}\nfunction setResponderId(node, id) {\n if (node != null) {\n node[keyName] = id;\n }\n}\nfunction getResponderPaths(domEvent) {\n const idPath = [];\n const nodePath = [];\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}\nfunction getLowestCommonAncestor(pathA, pathB) {\n let pathALength = pathA.length;\n let pathBLength = pathB.length;\n if (\n // If either path is empty\n pathALength === 0 || pathBLength === 0 || // 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 let itemA = pathA[0];\n let indexA = 0;\n let itemB = pathB[0];\n let indexB = 0;\n if (pathALength - pathBLength > 0) {\n indexA = pathALength - pathBLength;\n itemA = pathA[indexA];\n pathALength = pathBLength;\n }\n if (pathBLength - pathALength > 0) {\n indexB = pathBLength - pathALength;\n itemB = pathB[indexB];\n pathBLength = pathALength;\n }\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}\nfunction hasTargetTouches(target, touches) {\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}\nfunction hasValidSelection(domEvent) {\n if (domEvent.type === \"selectionchange\") {\n return isSelectionValid();\n }\n return domEvent.type === \"select\";\n}\nfunction isPrimaryPointerDown(domEvent) {\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 if (isTouch || isPrimaryMouseDown && noModifiers || isPrimaryMouseMove && noModifiers) {\n return true;\n }\n return false;\n}\nfunction isSelectionValid() {\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 = anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE || focusNode && focusNode.nodeType === window.Node.TEXT_NODE;\n return string.length >= 1 && string !== \"\\n\" && !!isTextNode;\n}\nexport {\n canUseDOM,\n getBoundingClientRect,\n getLowestCommonAncestor,\n getResponderPaths,\n hasTargetTouches,\n hasValidSelection,\n isPrimaryPointerDown,\n isSelectionValid,\n setResponderId\n};\n//# sourceMappingURL=utils.js.map\n"],"mappings":";AAAA,MAAM,UAAU;AAChB,MAAM,YAAY,CAAC,EAAE,OAAO,WAAW,eAAe,OAAO,YAAY,OAAO,SAAS;AACzF,MAAM,yBAAyB,SAAS;CACtC,IAAI,CAAC,MAAM;CACX,IAAI,KAAK,aAAa,GAAG;CACzB,IAAI,KAAK,uBAAuB;EAC9B,OAAO,KAAK,sBAAsB;CACpC;AACF;AACA,SAAS,aAAa,UAAU;CAC9B,IAAI,SAAS,SAAS,mBAAmB;EACvC,MAAM,SAAS,OAAO,aAAa,GAAG;EACtC,OAAO,qBAAqB,MAAM;CACpC;CACA,MAAM,OAAO,SAAS,gBAAgB,OAAO,SAAS,aAAa,IAAI,qBAAqB,SAAS,MAAM;CAC3G,OAAO;AACT;AACA,SAAS,qBAAqB,QAAQ;CACpC,MAAM,OAAO,CAAC;CACd,OAAO,UAAU,QAAQ,WAAW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