@react-aria/interactions 3.21.0 → 3.21.2
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/PressResponder.main.js +62 -0
- package/dist/PressResponder.main.js.map +1 -0
- package/dist/PressResponder.mjs +52 -0
- package/dist/PressResponder.module.js +52 -0
- package/dist/PressResponder.module.js.map +1 -0
- package/dist/Pressable.main.js +43 -0
- package/dist/Pressable.main.js.map +1 -0
- package/dist/Pressable.mjs +34 -0
- package/dist/Pressable.module.js +34 -0
- package/dist/Pressable.module.js.map +1 -0
- package/dist/context.main.js +30 -0
- package/dist/context.main.js.map +1 -0
- package/dist/context.mjs +21 -0
- package/dist/context.module.js +21 -0
- package/dist/context.module.js.map +1 -0
- package/dist/createEventHandler.main.js +42 -0
- package/dist/createEventHandler.main.js.map +1 -0
- package/dist/createEventHandler.mjs +37 -0
- package/dist/createEventHandler.module.js +37 -0
- package/dist/createEventHandler.module.js.map +1 -0
- package/dist/import.mjs +12 -1771
- package/dist/main.js +31 -1794
- package/dist/main.js.map +1 -1
- package/dist/module.js +12 -1771
- package/dist/module.js.map +1 -1
- package/dist/textSelection.main.js +77 -0
- package/dist/textSelection.main.js.map +1 -0
- package/dist/textSelection.mjs +71 -0
- package/dist/textSelection.module.js +71 -0
- package/dist/textSelection.module.js.map +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useFocus.main.js +64 -0
- package/dist/useFocus.main.js.map +1 -0
- package/dist/useFocus.mjs +59 -0
- package/dist/useFocus.module.js +59 -0
- package/dist/useFocus.module.js.map +1 -0
- package/dist/useFocusVisible.main.js +248 -0
- package/dist/useFocusVisible.main.js.map +1 -0
- package/dist/useFocusVisible.mjs +237 -0
- package/dist/useFocusVisible.module.js +237 -0
- package/dist/useFocusVisible.module.js.map +1 -0
- package/dist/useFocusWithin.main.js +76 -0
- package/dist/useFocusWithin.main.js.map +1 -0
- package/dist/useFocusWithin.mjs +71 -0
- package/dist/useFocusWithin.module.js +71 -0
- package/dist/useFocusWithin.module.js.map +1 -0
- package/dist/useHover.main.js +142 -0
- package/dist/useHover.main.js.map +1 -0
- package/dist/useHover.mjs +137 -0
- package/dist/useHover.module.js +137 -0
- package/dist/useHover.module.js.map +1 -0
- package/dist/useInteractOutside.main.js +101 -0
- package/dist/useInteractOutside.main.js.map +1 -0
- package/dist/useInteractOutside.mjs +96 -0
- package/dist/useInteractOutside.module.js +96 -0
- package/dist/useInteractOutside.module.js.map +1 -0
- package/dist/useKeyboard.main.js +30 -0
- package/dist/useKeyboard.main.js.map +1 -0
- package/dist/useKeyboard.mjs +25 -0
- package/dist/useKeyboard.module.js +25 -0
- package/dist/useKeyboard.module.js.map +1 -0
- package/dist/useLongPress.main.js +84 -0
- package/dist/useLongPress.main.js.map +1 -0
- package/dist/useLongPress.mjs +79 -0
- package/dist/useLongPress.module.js +79 -0
- package/dist/useLongPress.module.js.map +1 -0
- package/dist/useMove.main.js +236 -0
- package/dist/useMove.main.js.map +1 -0
- package/dist/useMove.mjs +231 -0
- package/dist/useMove.module.js +231 -0
- package/dist/useMove.module.js.map +1 -0
- package/dist/usePress.main.js +571 -0
- package/dist/usePress.main.js.map +1 -0
- package/dist/usePress.mjs +566 -0
- package/dist/usePress.module.js +566 -0
- package/dist/usePress.module.js.map +1 -0
- package/dist/useScrollWheel.main.js +41 -0
- package/dist/useScrollWheel.main.js.map +1 -0
- package/dist/useScrollWheel.mjs +36 -0
- package/dist/useScrollWheel.module.js +36 -0
- package/dist/useScrollWheel.module.js.map +1 -0
- package/dist/utils.main.js +120 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +115 -0
- package/dist/utils.module.js +115 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +5 -5
- package/src/useFocus.ts +5 -1
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {disableTextSelection as $14c0b72509d70225$export$16a4697467175487, restoreTextSelection as $14c0b72509d70225$export$b0d6fa1ab32e3295} from "./textSelection.module.js";
|
|
2
|
+
import {useRef as $5GN7j$useRef, useMemo as $5GN7j$useMemo} from "react";
|
|
3
|
+
import {useGlobalListeners as $5GN7j$useGlobalListeners, useEffectEvent as $5GN7j$useEffectEvent} from "@react-aria/utils";
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
7
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
+
* governing permissions and limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
19
|
+
let { onMoveStart: onMoveStart, onMove: onMove, onMoveEnd: onMoveEnd } = props;
|
|
20
|
+
let state = (0, $5GN7j$useRef)({
|
|
21
|
+
didMove: false,
|
|
22
|
+
lastPosition: null,
|
|
23
|
+
id: null
|
|
24
|
+
});
|
|
25
|
+
let { addGlobalListener: addGlobalListener, removeGlobalListener: removeGlobalListener } = (0, $5GN7j$useGlobalListeners)();
|
|
26
|
+
let move = (0, $5GN7j$useEffectEvent)((originalEvent, pointerType, deltaX, deltaY)=>{
|
|
27
|
+
if (deltaX === 0 && deltaY === 0) return;
|
|
28
|
+
if (!state.current.didMove) {
|
|
29
|
+
state.current.didMove = true;
|
|
30
|
+
onMoveStart === null || onMoveStart === void 0 ? void 0 : onMoveStart({
|
|
31
|
+
type: "movestart",
|
|
32
|
+
pointerType: pointerType,
|
|
33
|
+
shiftKey: originalEvent.shiftKey,
|
|
34
|
+
metaKey: originalEvent.metaKey,
|
|
35
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
36
|
+
altKey: originalEvent.altKey
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
onMove === null || onMove === void 0 ? void 0 : onMove({
|
|
40
|
+
type: "move",
|
|
41
|
+
pointerType: pointerType,
|
|
42
|
+
deltaX: deltaX,
|
|
43
|
+
deltaY: deltaY,
|
|
44
|
+
shiftKey: originalEvent.shiftKey,
|
|
45
|
+
metaKey: originalEvent.metaKey,
|
|
46
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
47
|
+
altKey: originalEvent.altKey
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
let end = (0, $5GN7j$useEffectEvent)((originalEvent, pointerType)=>{
|
|
51
|
+
(0, $14c0b72509d70225$export$b0d6fa1ab32e3295)();
|
|
52
|
+
if (state.current.didMove) onMoveEnd === null || onMoveEnd === void 0 ? void 0 : onMoveEnd({
|
|
53
|
+
type: "moveend",
|
|
54
|
+
pointerType: pointerType,
|
|
55
|
+
shiftKey: originalEvent.shiftKey,
|
|
56
|
+
metaKey: originalEvent.metaKey,
|
|
57
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
58
|
+
altKey: originalEvent.altKey
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
let moveProps = (0, $5GN7j$useMemo)(()=>{
|
|
62
|
+
let moveProps = {};
|
|
63
|
+
let start = ()=>{
|
|
64
|
+
(0, $14c0b72509d70225$export$16a4697467175487)();
|
|
65
|
+
state.current.didMove = false;
|
|
66
|
+
};
|
|
67
|
+
if (typeof PointerEvent === "undefined") {
|
|
68
|
+
let onMouseMove = (e)=>{
|
|
69
|
+
if (e.button === 0) {
|
|
70
|
+
var _state_current_lastPosition, _state_current_lastPosition1;
|
|
71
|
+
var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
|
|
72
|
+
move(e, "mouse", e.pageX - ((_state_current_lastPosition_pageX = (_state_current_lastPosition = state.current.lastPosition) === null || _state_current_lastPosition === void 0 ? void 0 : _state_current_lastPosition.pageX) !== null && _state_current_lastPosition_pageX !== void 0 ? _state_current_lastPosition_pageX : 0), e.pageY - ((_state_current_lastPosition_pageY = (_state_current_lastPosition1 = state.current.lastPosition) === null || _state_current_lastPosition1 === void 0 ? void 0 : _state_current_lastPosition1.pageY) !== null && _state_current_lastPosition_pageY !== void 0 ? _state_current_lastPosition_pageY : 0));
|
|
73
|
+
state.current.lastPosition = {
|
|
74
|
+
pageX: e.pageX,
|
|
75
|
+
pageY: e.pageY
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
let onMouseUp = (e)=>{
|
|
80
|
+
if (e.button === 0) {
|
|
81
|
+
end(e, "mouse");
|
|
82
|
+
removeGlobalListener(window, "mousemove", onMouseMove, false);
|
|
83
|
+
removeGlobalListener(window, "mouseup", onMouseUp, false);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
moveProps.onMouseDown = (e)=>{
|
|
87
|
+
if (e.button === 0) {
|
|
88
|
+
start();
|
|
89
|
+
e.stopPropagation();
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
state.current.lastPosition = {
|
|
92
|
+
pageX: e.pageX,
|
|
93
|
+
pageY: e.pageY
|
|
94
|
+
};
|
|
95
|
+
addGlobalListener(window, "mousemove", onMouseMove, false);
|
|
96
|
+
addGlobalListener(window, "mouseup", onMouseUp, false);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
let onTouchMove = (e)=>{
|
|
100
|
+
let touch = [
|
|
101
|
+
...e.changedTouches
|
|
102
|
+
].findIndex(({ identifier: identifier })=>identifier === state.current.id);
|
|
103
|
+
if (touch >= 0) {
|
|
104
|
+
var _state_current_lastPosition, _state_current_lastPosition1;
|
|
105
|
+
let { pageX: pageX, pageY: pageY } = e.changedTouches[touch];
|
|
106
|
+
var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
|
|
107
|
+
move(e, "touch", pageX - ((_state_current_lastPosition_pageX = (_state_current_lastPosition = state.current.lastPosition) === null || _state_current_lastPosition === void 0 ? void 0 : _state_current_lastPosition.pageX) !== null && _state_current_lastPosition_pageX !== void 0 ? _state_current_lastPosition_pageX : 0), pageY - ((_state_current_lastPosition_pageY = (_state_current_lastPosition1 = state.current.lastPosition) === null || _state_current_lastPosition1 === void 0 ? void 0 : _state_current_lastPosition1.pageY) !== null && _state_current_lastPosition_pageY !== void 0 ? _state_current_lastPosition_pageY : 0));
|
|
108
|
+
state.current.lastPosition = {
|
|
109
|
+
pageX: pageX,
|
|
110
|
+
pageY: pageY
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
let onTouchEnd = (e)=>{
|
|
115
|
+
let touch = [
|
|
116
|
+
...e.changedTouches
|
|
117
|
+
].findIndex(({ identifier: identifier })=>identifier === state.current.id);
|
|
118
|
+
if (touch >= 0) {
|
|
119
|
+
end(e, "touch");
|
|
120
|
+
state.current.id = null;
|
|
121
|
+
removeGlobalListener(window, "touchmove", onTouchMove);
|
|
122
|
+
removeGlobalListener(window, "touchend", onTouchEnd);
|
|
123
|
+
removeGlobalListener(window, "touchcancel", onTouchEnd);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
moveProps.onTouchStart = (e)=>{
|
|
127
|
+
if (e.changedTouches.length === 0 || state.current.id != null) return;
|
|
128
|
+
let { pageX: pageX, pageY: pageY, identifier: identifier } = e.changedTouches[0];
|
|
129
|
+
start();
|
|
130
|
+
e.stopPropagation();
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
state.current.lastPosition = {
|
|
133
|
+
pageX: pageX,
|
|
134
|
+
pageY: pageY
|
|
135
|
+
};
|
|
136
|
+
state.current.id = identifier;
|
|
137
|
+
addGlobalListener(window, "touchmove", onTouchMove, false);
|
|
138
|
+
addGlobalListener(window, "touchend", onTouchEnd, false);
|
|
139
|
+
addGlobalListener(window, "touchcancel", onTouchEnd, false);
|
|
140
|
+
};
|
|
141
|
+
} else {
|
|
142
|
+
let onPointerMove = (e)=>{
|
|
143
|
+
if (e.pointerId === state.current.id) {
|
|
144
|
+
var _state_current_lastPosition, _state_current_lastPosition1;
|
|
145
|
+
let pointerType = e.pointerType || "mouse";
|
|
146
|
+
var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
|
|
147
|
+
// Problems with PointerEvent#movementX/movementY:
|
|
148
|
+
// 1. it is always 0 on macOS Safari.
|
|
149
|
+
// 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
|
|
150
|
+
move(e, pointerType, e.pageX - ((_state_current_lastPosition_pageX = (_state_current_lastPosition = state.current.lastPosition) === null || _state_current_lastPosition === void 0 ? void 0 : _state_current_lastPosition.pageX) !== null && _state_current_lastPosition_pageX !== void 0 ? _state_current_lastPosition_pageX : 0), e.pageY - ((_state_current_lastPosition_pageY = (_state_current_lastPosition1 = state.current.lastPosition) === null || _state_current_lastPosition1 === void 0 ? void 0 : _state_current_lastPosition1.pageY) !== null && _state_current_lastPosition_pageY !== void 0 ? _state_current_lastPosition_pageY : 0));
|
|
151
|
+
state.current.lastPosition = {
|
|
152
|
+
pageX: e.pageX,
|
|
153
|
+
pageY: e.pageY
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
let onPointerUp = (e)=>{
|
|
158
|
+
if (e.pointerId === state.current.id) {
|
|
159
|
+
let pointerType = e.pointerType || "mouse";
|
|
160
|
+
end(e, pointerType);
|
|
161
|
+
state.current.id = null;
|
|
162
|
+
removeGlobalListener(window, "pointermove", onPointerMove, false);
|
|
163
|
+
removeGlobalListener(window, "pointerup", onPointerUp, false);
|
|
164
|
+
removeGlobalListener(window, "pointercancel", onPointerUp, false);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
moveProps.onPointerDown = (e)=>{
|
|
168
|
+
if (e.button === 0 && state.current.id == null) {
|
|
169
|
+
start();
|
|
170
|
+
e.stopPropagation();
|
|
171
|
+
e.preventDefault();
|
|
172
|
+
state.current.lastPosition = {
|
|
173
|
+
pageX: e.pageX,
|
|
174
|
+
pageY: e.pageY
|
|
175
|
+
};
|
|
176
|
+
state.current.id = e.pointerId;
|
|
177
|
+
addGlobalListener(window, "pointermove", onPointerMove, false);
|
|
178
|
+
addGlobalListener(window, "pointerup", onPointerUp, false);
|
|
179
|
+
addGlobalListener(window, "pointercancel", onPointerUp, false);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
let triggerKeyboardMove = (e, deltaX, deltaY)=>{
|
|
184
|
+
start();
|
|
185
|
+
move(e, "keyboard", deltaX, deltaY);
|
|
186
|
+
end(e, "keyboard");
|
|
187
|
+
};
|
|
188
|
+
moveProps.onKeyDown = (e)=>{
|
|
189
|
+
switch(e.key){
|
|
190
|
+
case "Left":
|
|
191
|
+
case "ArrowLeft":
|
|
192
|
+
e.preventDefault();
|
|
193
|
+
e.stopPropagation();
|
|
194
|
+
triggerKeyboardMove(e, -1, 0);
|
|
195
|
+
break;
|
|
196
|
+
case "Right":
|
|
197
|
+
case "ArrowRight":
|
|
198
|
+
e.preventDefault();
|
|
199
|
+
e.stopPropagation();
|
|
200
|
+
triggerKeyboardMove(e, 1, 0);
|
|
201
|
+
break;
|
|
202
|
+
case "Up":
|
|
203
|
+
case "ArrowUp":
|
|
204
|
+
e.preventDefault();
|
|
205
|
+
e.stopPropagation();
|
|
206
|
+
triggerKeyboardMove(e, 0, -1);
|
|
207
|
+
break;
|
|
208
|
+
case "Down":
|
|
209
|
+
case "ArrowDown":
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
e.stopPropagation();
|
|
212
|
+
triggerKeyboardMove(e, 0, 1);
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
return moveProps;
|
|
217
|
+
}, [
|
|
218
|
+
state,
|
|
219
|
+
addGlobalListener,
|
|
220
|
+
removeGlobalListener,
|
|
221
|
+
move,
|
|
222
|
+
end
|
|
223
|
+
]);
|
|
224
|
+
return {
|
|
225
|
+
moveProps: movePro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OAAO,EAAE,KAAK;oBAAA;oBAC5D,MAAM,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS;oBAC9B,kBAAkB,QAAQ,eAAe,eAAe;oBACxD,kBAAkB,QAAQ,aAAa,aAAa;oBACpD,kBAAkB,QAAQ,iBAAiB,aAAa;gBAC1D;YACF;QACF;QAEA,IAAI,sBAAsB,CAAC,GAAc,QAAgB;YACvD;YACA,KAAK,GAAG,YAAY,QAAQ;YAC5B,IAAI,GAAG;QACT;QAEA,UAAU,SAAS,GAAG,CAAC;YACrB,OAAQ,EAAE,GAAG;gBACX,KAAK;gBACL,KAAK;oBACH,EAAE,cAAc;oBAChB,EAAE,eAAe;oBACjB,oBAAoB,GAAG,IAAI;oBAC3B;gBACF,KAAK;gBACL,KAAK;oBACH,EAAE,cAAc;oBAChB,EAAE,eAAe;oBACjB,oBAAoB,GAAG,GAAG;oBAC1B;gBACF,KAAK;gBACL,KAAK;oBACH,EAAE,cAAc;oBAChB,EAAE,eAAe;oBACjB,oBAAoB,GAAG,GAAG;oBAC1B;gBACF,KAAK;gBACL,KAAK;oBACH,EAAE,cAAc;oBAChB,EAAE,eAAe;oBACjB,oBAAoB,GAAG,GAAG;oBAC1B;YACJ;QACF;QAEA,OAAO;IACT,GAAG;QAAC;QAAO;QAAmB;QAAsB;QAAM;KAAI;IAE9D,OAAO;mBAAC;IAAS;AACnB","sources":["packages/@react-aria/interactions/src/useMove.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {disableTextSelection, restoreTextSelection} from './textSelection';\nimport {DOMAttributes, MoveEvents, PointerType} from '@react-types/shared';\nimport React, {useMemo, useRef} from 'react';\nimport {useEffectEvent, useGlobalListeners} from '@react-aria/utils';\n\nexport interface MoveResult {\n /** Props to spread on the target element. */\n moveProps: DOMAttributes\n}\n\ninterface EventBase {\n shiftKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean,\n altKey: boolean\n}\n\n/**\n * Handles move interactions across mouse, touch, and keyboard, including dragging with\n * the mouse or touch, and using the arrow keys. Normalizes behavior across browsers and\n * platforms, and ignores emulated mouse events on touch devices.\n */\nexport function useMove(props: MoveEvents): MoveResult {\n let {onMoveStart, onMove, onMoveEnd} = props;\n\n let state = useRef<{\n didMove: boolean,\n lastPosition: {pageX: number, pageY: number} | null,\n id: number | null\n }>({didMove: false, lastPosition: null, id: null});\n\n let {addGlobalListener, removeGlobalListener} = useGlobalListeners();\n\n let move = useEffectEvent((originalEvent: EventBase, pointerType: PointerType, deltaX: number, deltaY: number) => {\n if (deltaX === 0 && deltaY === 0) {\n return;\n }\n\n if (!state.current.didMove) {\n state.current.didMove = true;\n onMoveStart?.({\n type: 'movestart',\n pointerType,\n shiftKey: originalEvent.shiftKey,\n metaKey: originalEvent.metaKey,\n ctrlKey: originalEvent.ctrlKey,\n altKey: originalEvent.altKey\n });\n }\n onMove?.({\n type: 'move',\n pointerType,\n deltaX: deltaX,\n deltaY: deltaY,\n shiftKey: originalEvent.shiftKey,\n metaKey: originalEvent.metaKey,\n ctrlKey: originalEvent.ctrlKey,\n altKey: originalEvent.altKey\n });\n });\n\n let end = useEffectEvent((originalEvent: EventBase, pointerType: PointerType) => {\n restoreTextSelection();\n if (state.current.didMove) {\n onMoveEnd?.({\n type: 'moveend',\n pointerType,\n shiftKey: originalEvent.shiftKey,\n metaKey: originalEvent.metaKey,\n ctrlKey: originalEvent.ctrlKey,\n altKey: originalEvent.altKey\n });\n }\n });\n\n let moveProps = useMemo(() => {\n let moveProps: DOMAttributes = {};\n\n let start = () => {\n disableTextSelection();\n state.current.didMove = false;\n };\n\n if (typeof PointerEvent === 'undefined') {\n let onMouseMove = (e: MouseEvent) => {\n if (e.button === 0) {\n move(e, 'mouse', e.pageX - (state.current.lastPosition?.pageX ?? 0), e.pageY - (state.current.lastPosition?.pageY ?? 0));\n state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n }\n };\n let onMouseUp = (e: MouseEvent) => {\n if (e.button === 0) {\n end(e, 'mouse');\n removeGlobalListener(window, 'mousemove', onMouseMove, false);\n removeGlobalListener(window, 'mouseup', onMouseUp, false);\n }\n };\n moveProps.onMouseDown = (e: React.MouseEvent) => {\n if (e.button === 0) {\n start();\n e.stopPropagation();\n e.preventDefault();\n state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n addGlobalListener(window, 'mousemove', onMouseMove, false);\n addGlobalListener(window, 'mouseup', onMouseUp, false);\n }\n };\n\n let onTouchMove = (e: TouchEvent) => {\n let touch = [...e.changedTouches].findIndex(({identifier}) => identifier === state.current.id);\n if (touch >= 0) {\n let {pageX, pageY} = e.changedTouches[touch];\n move(e, 'touch', pageX - (state.current.lastPosition?.pageX ?? 0), pageY - (state.current.lastPosition?.pageY ?? 0));\n state.current.lastPosition = {pageX, pageY};\n }\n };\n let onTouchEnd = (e: TouchEvent) => {\n let touch = [...e.changedTouches].findIndex(({identifier}) => identifier === state.current.id);\n if (touch >= 0) {\n end(e, 'touch');\n state.current.id = null;\n removeGlobalListener(window, 'touchmove', onTouchMove);\n removeGlobalListener(window, 'touchend', onTouchEnd);\n removeGlobalListener(window, 'touchcancel', onTouchEnd);\n }\n };\n moveProps.onTouchStart = (e: React.TouchEvent) => {\n if (e.changedTouches.length === 0 || state.current.id != null) {\n return;\n }\n\n let {pageX, pageY, identifier} = e.changedTouches[0];\n start();\n e.stopPropagation();\n e.preventDefault();\n state.current.lastPosition = {pageX, pageY};\n state.current.id = identifier;\n addGlobalListener(window, 'touchmove', onTouchMove, false);\n addGlobalListener(window, 'touchend', onTouchEnd, false);\n addGlobalListener(window, 'touchcancel', onTouchEnd, false);\n };\n } else {\n let onPointerMove = (e: PointerEvent) => {\n if (e.pointerId === state.current.id) {\n let pointerType = (e.pointerType || 'mouse') as PointerType;\n\n // Problems with PointerEvent#movementX/movementY:\n // 1. it is always 0 on macOS Safari.\n // 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS\n move(e, pointerType, e.pageX - (state.current.lastPosition?.pageX ?? 0), e.pageY - (state.current.lastPosition?.pageY ?? 0));\n state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n }\n };\n\n let onPointerUp = (e: PointerEvent) => {\n if (e.pointerId === state.current.id) {\n let pointerType = (e.pointerType || 'mouse') as PointerType;\n end(e, pointerType);\n state.current.id = null;\n removeGlobalListener(window, 'pointermove', onPointerMove, false);\n removeGlobalListener(window, 'pointerup', onPointerUp, false);\n removeGlobalListener(window, 'pointercancel', onPointerUp, false);\n }\n };\n\n moveProps.onPointerDown = (e: React.PointerEvent) => {\n if (e.button === 0 && state.current.id == null) {\n start();\n e.stopPropagation();\n e.preventDefault();\n state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n state.current.id = e.pointerId;\n addGlobalListener(window, 'pointermove', onPointerMove, false);\n addGlobalListener(window, 'pointerup', onPointerUp, false);\n addGlobalListener(window, 'pointercancel', onPointerUp, false);\n }\n };\n }\n\n let triggerKeyboardMove = (e: EventBase, deltaX: number, deltaY: number) => {\n start();\n move(e, 'keyboard', deltaX, deltaY);\n end(e, 'keyboard');\n };\n\n moveProps.onKeyDown = (e) => {\n switch (e.key) {\n case 'Left':\n case 'ArrowLeft':\n e.preventDefault();\n e.stopPropagation();\n triggerKeyboardMove(e, -1, 0);\n break;\n case 'Right':\n case 'ArrowRight':\n e.preventDefault();\n e.stopPropagation();\n triggerKeyboardMove(e, 1, 0);\n break;\n case 'Up':\n case 'ArrowUp':\n e.preventDefault();\n e.stopPropagation();\n triggerKeyboardMove(e, 0, -1);\n break;\n case 'Down':\n case 'ArrowDown':\n e.preventDefault();\n e.stopPropagation();\n triggerKeyboardMove(e, 0, 1);\n break;\n }\n };\n\n return moveProps;\n }, [state, addGlobalListener, removeGlobalListener, move, end]);\n\n return {moveProps};\n}\n"],"names":[],"version":3,"file":"useMove.module.js.map"}
|