@react-aria/interactions 3.25.6 → 3.26.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/focusSafely.main.js +4 -4
- package/dist/focusSafely.main.js.map +1 -1
- package/dist/focusSafely.mjs +4 -4
- package/dist/focusSafely.module.js +4 -4
- package/dist/focusSafely.module.js.map +1 -1
- package/dist/import.mjs +2 -2
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useFocusVisible.main.js +12 -2
- package/dist/useFocusVisible.main.js.map +1 -1
- package/dist/useFocusVisible.mjs +13 -4
- package/dist/useFocusVisible.module.js +13 -4
- package/dist/useFocusVisible.module.js.map +1 -1
- package/dist/useInteractOutside.main.js +1 -3
- package/dist/useInteractOutside.main.js.map +1 -1
- package/dist/useInteractOutside.mjs +1 -3
- package/dist/useInteractOutside.module.js +1 -3
- package/dist/useInteractOutside.module.js.map +1 -1
- package/dist/useMove.main.js +110 -74
- package/dist/useMove.main.js.map +1 -1
- package/dist/useMove.mjs +112 -76
- package/dist/useMove.module.js +112 -76
- package/dist/useMove.module.js.map +1 -1
- package/dist/usePress.main.js +186 -114
- package/dist/usePress.main.js.map +1 -1
- package/dist/usePress.mjs +188 -116
- package/dist/usePress.module.js +188 -116
- package/dist/usePress.module.js.map +1 -1
- package/dist/utils.main.js +2 -5
- package/dist/utils.main.js.map +1 -1
- package/dist/utils.mjs +3 -6
- package/dist/utils.module.js +3 -6
- package/dist/utils.module.js.map +1 -1
- package/package.json +3 -3
- package/src/focusSafely.ts +4 -4
- package/src/index.ts +1 -0
- package/src/useFocusVisible.ts +15 -3
- package/src/useInteractOutside.ts +1 -1
- package/src/useMove.ts +85 -57
- package/src/usePress.ts +183 -147
- package/src/utils.ts +3 -7
package/dist/useMove.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {disableTextSelection as $14c0b72509d70225$export$16a4697467175487, restoreTextSelection as $14c0b72509d70225$export$b0d6fa1ab32e3295} from "./textSelection.mjs";
|
|
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";
|
|
2
|
+
import {useRef as $5GN7j$useRef, useCallback as $5GN7j$useCallback, useState as $5GN7j$useState, useMemo as $5GN7j$useMemo} from "react";
|
|
3
|
+
import {useGlobalListeners as $5GN7j$useGlobalListeners, useEffectEvent as $5GN7j$useEffectEvent, useLayoutEffect as $5GN7j$useLayoutEffect} from "@react-aria/utils";
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -23,7 +23,7 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
23
23
|
id: null
|
|
24
24
|
});
|
|
25
25
|
let { addGlobalListener: addGlobalListener, removeGlobalListener: removeGlobalListener } = (0, $5GN7j$useGlobalListeners)();
|
|
26
|
-
let move = (0, $5GN7j$
|
|
26
|
+
let move = (0, $5GN7j$useCallback)((originalEvent, pointerType, deltaX, deltaY)=>{
|
|
27
27
|
if (deltaX === 0 && deltaY === 0) return;
|
|
28
28
|
if (!state.current.didMove) {
|
|
29
29
|
state.current.didMove = true;
|
|
@@ -46,8 +46,13 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
46
46
|
ctrlKey: originalEvent.ctrlKey,
|
|
47
47
|
altKey: originalEvent.altKey
|
|
48
48
|
});
|
|
49
|
-
}
|
|
50
|
-
|
|
49
|
+
}, [
|
|
50
|
+
onMoveStart,
|
|
51
|
+
onMove,
|
|
52
|
+
state
|
|
53
|
+
]);
|
|
54
|
+
let moveEvent = (0, $5GN7j$useEffectEvent)(move);
|
|
55
|
+
let end = (0, $5GN7j$useCallback)((originalEvent, pointerType)=>{
|
|
51
56
|
(0, $14c0b72509d70225$export$b0d6fa1ab32e3295)();
|
|
52
57
|
if (state.current.didMove) onMoveEnd === null || onMoveEnd === void 0 ? void 0 : onMoveEnd({
|
|
53
58
|
type: 'moveend',
|
|
@@ -57,45 +62,75 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
57
62
|
ctrlKey: originalEvent.ctrlKey,
|
|
58
63
|
altKey: originalEvent.altKey
|
|
59
64
|
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
let
|
|
69
|
-
if (e.
|
|
65
|
+
}, [
|
|
66
|
+
onMoveEnd,
|
|
67
|
+
state
|
|
68
|
+
]);
|
|
69
|
+
let endEvent = (0, $5GN7j$useEffectEvent)(end);
|
|
70
|
+
let [pointerDown, setPointerDown] = (0, $5GN7j$useState)(null);
|
|
71
|
+
(0, $5GN7j$useLayoutEffect)(()=>{
|
|
72
|
+
if (pointerDown === 'pointer') {
|
|
73
|
+
let onPointerMove = (e)=>{
|
|
74
|
+
if (e.pointerId === state.current.id) {
|
|
70
75
|
var _state_current_lastPosition, _state_current_lastPosition1;
|
|
76
|
+
let pointerType = e.pointerType || 'mouse';
|
|
71
77
|
var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
|
|
72
|
-
|
|
78
|
+
// Problems with PointerEvent#movementX/movementY:
|
|
79
|
+
// 1. it is always 0 on macOS Safari.
|
|
80
|
+
// 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
|
|
81
|
+
moveEvent(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));
|
|
73
82
|
state.current.lastPosition = {
|
|
74
83
|
pageX: e.pageX,
|
|
75
84
|
pageY: e.pageY
|
|
76
85
|
};
|
|
77
86
|
}
|
|
78
87
|
};
|
|
79
|
-
let
|
|
80
|
-
if (e.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
let onPointerUp = (e)=>{
|
|
89
|
+
if (e.pointerId === state.current.id) {
|
|
90
|
+
let pointerType = e.pointerType || 'mouse';
|
|
91
|
+
endEvent(e, pointerType);
|
|
92
|
+
state.current.id = null;
|
|
93
|
+
removeGlobalListener(window, 'pointermove', onPointerMove, false);
|
|
94
|
+
removeGlobalListener(window, 'pointerup', onPointerUp, false);
|
|
95
|
+
removeGlobalListener(window, 'pointercancel', onPointerUp, false);
|
|
96
|
+
setPointerDown(null);
|
|
84
97
|
}
|
|
85
98
|
};
|
|
86
|
-
|
|
99
|
+
addGlobalListener(window, 'pointermove', onPointerMove, false);
|
|
100
|
+
addGlobalListener(window, 'pointerup', onPointerUp, false);
|
|
101
|
+
addGlobalListener(window, 'pointercancel', onPointerUp, false);
|
|
102
|
+
return ()=>{
|
|
103
|
+
removeGlobalListener(window, 'pointermove', onPointerMove, false);
|
|
104
|
+
removeGlobalListener(window, 'pointerup', onPointerUp, false);
|
|
105
|
+
removeGlobalListener(window, 'pointercancel', onPointerUp, false);
|
|
106
|
+
};
|
|
107
|
+
} else if (pointerDown === 'mouse' && process.env.NODE_ENV === 'test') {
|
|
108
|
+
let onMouseMove = (e)=>{
|
|
87
109
|
if (e.button === 0) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
e.
|
|
110
|
+
var _state_current_lastPosition, _state_current_lastPosition1;
|
|
111
|
+
var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
|
|
112
|
+
moveEvent(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));
|
|
91
113
|
state.current.lastPosition = {
|
|
92
114
|
pageX: e.pageX,
|
|
93
115
|
pageY: e.pageY
|
|
94
116
|
};
|
|
95
|
-
addGlobalListener(window, 'mousemove', onMouseMove, false);
|
|
96
|
-
addGlobalListener(window, 'mouseup', onMouseUp, false);
|
|
97
117
|
}
|
|
98
118
|
};
|
|
119
|
+
let onMouseUp = (e)=>{
|
|
120
|
+
if (e.button === 0) {
|
|
121
|
+
endEvent(e, 'mouse');
|
|
122
|
+
removeGlobalListener(window, 'mousemove', onMouseMove, false);
|
|
123
|
+
removeGlobalListener(window, 'mouseup', onMouseUp, false);
|
|
124
|
+
setPointerDown(null);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
addGlobalListener(window, 'mousemove', onMouseMove, false);
|
|
128
|
+
addGlobalListener(window, 'mouseup', onMouseUp, false);
|
|
129
|
+
return ()=>{
|
|
130
|
+
removeGlobalListener(window, 'mousemove', onMouseMove, false);
|
|
131
|
+
removeGlobalListener(window, 'mouseup', onMouseUp, false);
|
|
132
|
+
};
|
|
133
|
+
} else if (pointerDown === 'touch' && process.env.NODE_ENV === 'test') {
|
|
99
134
|
let onTouchMove = (e)=>{
|
|
100
135
|
let touch = [
|
|
101
136
|
...e.changedTouches
|
|
@@ -104,7 +139,7 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
104
139
|
var _state_current_lastPosition, _state_current_lastPosition1;
|
|
105
140
|
let { pageX: pageX, pageY: pageY } = e.changedTouches[touch];
|
|
106
141
|
var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
|
|
107
|
-
|
|
142
|
+
moveEvent(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
143
|
state.current.lastPosition = {
|
|
109
144
|
pageX: pageX,
|
|
110
145
|
pageY: pageY
|
|
@@ -116,11 +151,45 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
116
151
|
...e.changedTouches
|
|
117
152
|
].findIndex(({ identifier: identifier })=>identifier === state.current.id);
|
|
118
153
|
if (touch >= 0) {
|
|
119
|
-
|
|
154
|
+
endEvent(e, 'touch');
|
|
120
155
|
state.current.id = null;
|
|
121
156
|
removeGlobalListener(window, 'touchmove', onTouchMove);
|
|
122
157
|
removeGlobalListener(window, 'touchend', onTouchEnd);
|
|
123
158
|
removeGlobalListener(window, 'touchcancel', onTouchEnd);
|
|
159
|
+
setPointerDown(null);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
addGlobalListener(window, 'touchmove', onTouchMove, false);
|
|
163
|
+
addGlobalListener(window, 'touchend', onTouchEnd, false);
|
|
164
|
+
addGlobalListener(window, 'touchcancel', onTouchEnd, false);
|
|
165
|
+
return ()=>{
|
|
166
|
+
removeGlobalListener(window, 'touchmove', onTouchMove, false);
|
|
167
|
+
removeGlobalListener(window, 'touchend', onTouchEnd, false);
|
|
168
|
+
removeGlobalListener(window, 'touchcancel', onTouchEnd, false);
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}, [
|
|
172
|
+
pointerDown,
|
|
173
|
+
addGlobalListener,
|
|
174
|
+
removeGlobalListener
|
|
175
|
+
]);
|
|
176
|
+
let moveProps = (0, $5GN7j$useMemo)(()=>{
|
|
177
|
+
let moveProps = {};
|
|
178
|
+
let start = ()=>{
|
|
179
|
+
(0, $14c0b72509d70225$export$16a4697467175487)();
|
|
180
|
+
state.current.didMove = false;
|
|
181
|
+
};
|
|
182
|
+
if (typeof PointerEvent === 'undefined' && process.env.NODE_ENV === 'test') {
|
|
183
|
+
moveProps.onMouseDown = (e)=>{
|
|
184
|
+
if (e.button === 0) {
|
|
185
|
+
start();
|
|
186
|
+
e.stopPropagation();
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
state.current.lastPosition = {
|
|
189
|
+
pageX: e.pageX,
|
|
190
|
+
pageY: e.pageY
|
|
191
|
+
};
|
|
192
|
+
setPointerDown('mouse');
|
|
124
193
|
}
|
|
125
194
|
};
|
|
126
195
|
moveProps.onTouchStart = (e)=>{
|
|
@@ -134,52 +203,21 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
134
203
|
pageY: pageY
|
|
135
204
|
};
|
|
136
205
|
state.current.id = identifier;
|
|
137
|
-
|
|
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
|
-
}
|
|
206
|
+
setPointerDown('touch');
|
|
156
207
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
}
|
|
208
|
+
} else moveProps.onPointerDown = (e)=>{
|
|
209
|
+
if (e.button === 0 && state.current.id == null) {
|
|
210
|
+
start();
|
|
211
|
+
e.stopPropagation();
|
|
212
|
+
e.preventDefault();
|
|
213
|
+
state.current.lastPosition = {
|
|
214
|
+
pageX: e.pageX,
|
|
215
|
+
pageY: e.pageY
|
|
216
|
+
};
|
|
217
|
+
state.current.id = e.pointerId;
|
|
218
|
+
setPointerDown('pointer');
|
|
219
|
+
}
|
|
220
|
+
};
|
|
183
221
|
let triggerKeyboardMove = (e, deltaX, deltaY)=>{
|
|
184
222
|
start();
|
|
185
223
|
move(e, 'keyboard', deltaX, deltaY);
|
|
@@ -216,8 +254,6 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
216
254
|
return moveProps;
|
|
217
255
|
}, [
|
|
218
256
|
state,
|
|
219
|
-
addGlobalListener,
|
|
220
|
-
removeGlobalListener,
|
|
221
257
|
move,
|
|
222
258
|
end
|
|
223
259
|
]);
|
package/dist/useMove.module.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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";
|
|
2
|
+
import {useRef as $5GN7j$useRef, useCallback as $5GN7j$useCallback, useState as $5GN7j$useState, useMemo as $5GN7j$useMemo} from "react";
|
|
3
|
+
import {useGlobalListeners as $5GN7j$useGlobalListeners, useEffectEvent as $5GN7j$useEffectEvent, useLayoutEffect as $5GN7j$useLayoutEffect} from "@react-aria/utils";
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -23,7 +23,7 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
23
23
|
id: null
|
|
24
24
|
});
|
|
25
25
|
let { addGlobalListener: addGlobalListener, removeGlobalListener: removeGlobalListener } = (0, $5GN7j$useGlobalListeners)();
|
|
26
|
-
let move = (0, $5GN7j$
|
|
26
|
+
let move = (0, $5GN7j$useCallback)((originalEvent, pointerType, deltaX, deltaY)=>{
|
|
27
27
|
if (deltaX === 0 && deltaY === 0) return;
|
|
28
28
|
if (!state.current.didMove) {
|
|
29
29
|
state.current.didMove = true;
|
|
@@ -46,8 +46,13 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
46
46
|
ctrlKey: originalEvent.ctrlKey,
|
|
47
47
|
altKey: originalEvent.altKey
|
|
48
48
|
});
|
|
49
|
-
}
|
|
50
|
-
|
|
49
|
+
}, [
|
|
50
|
+
onMoveStart,
|
|
51
|
+
onMove,
|
|
52
|
+
state
|
|
53
|
+
]);
|
|
54
|
+
let moveEvent = (0, $5GN7j$useEffectEvent)(move);
|
|
55
|
+
let end = (0, $5GN7j$useCallback)((originalEvent, pointerType)=>{
|
|
51
56
|
(0, $14c0b72509d70225$export$b0d6fa1ab32e3295)();
|
|
52
57
|
if (state.current.didMove) onMoveEnd === null || onMoveEnd === void 0 ? void 0 : onMoveEnd({
|
|
53
58
|
type: 'moveend',
|
|
@@ -57,45 +62,75 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
57
62
|
ctrlKey: originalEvent.ctrlKey,
|
|
58
63
|
altKey: originalEvent.altKey
|
|
59
64
|
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
let
|
|
69
|
-
if (e.
|
|
65
|
+
}, [
|
|
66
|
+
onMoveEnd,
|
|
67
|
+
state
|
|
68
|
+
]);
|
|
69
|
+
let endEvent = (0, $5GN7j$useEffectEvent)(end);
|
|
70
|
+
let [pointerDown, setPointerDown] = (0, $5GN7j$useState)(null);
|
|
71
|
+
(0, $5GN7j$useLayoutEffect)(()=>{
|
|
72
|
+
if (pointerDown === 'pointer') {
|
|
73
|
+
let onPointerMove = (e)=>{
|
|
74
|
+
if (e.pointerId === state.current.id) {
|
|
70
75
|
var _state_current_lastPosition, _state_current_lastPosition1;
|
|
76
|
+
let pointerType = e.pointerType || 'mouse';
|
|
71
77
|
var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
|
|
72
|
-
|
|
78
|
+
// Problems with PointerEvent#movementX/movementY:
|
|
79
|
+
// 1. it is always 0 on macOS Safari.
|
|
80
|
+
// 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
|
|
81
|
+
moveEvent(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));
|
|
73
82
|
state.current.lastPosition = {
|
|
74
83
|
pageX: e.pageX,
|
|
75
84
|
pageY: e.pageY
|
|
76
85
|
};
|
|
77
86
|
}
|
|
78
87
|
};
|
|
79
|
-
let
|
|
80
|
-
if (e.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
let onPointerUp = (e)=>{
|
|
89
|
+
if (e.pointerId === state.current.id) {
|
|
90
|
+
let pointerType = e.pointerType || 'mouse';
|
|
91
|
+
endEvent(e, pointerType);
|
|
92
|
+
state.current.id = null;
|
|
93
|
+
removeGlobalListener(window, 'pointermove', onPointerMove, false);
|
|
94
|
+
removeGlobalListener(window, 'pointerup', onPointerUp, false);
|
|
95
|
+
removeGlobalListener(window, 'pointercancel', onPointerUp, false);
|
|
96
|
+
setPointerDown(null);
|
|
84
97
|
}
|
|
85
98
|
};
|
|
86
|
-
|
|
99
|
+
addGlobalListener(window, 'pointermove', onPointerMove, false);
|
|
100
|
+
addGlobalListener(window, 'pointerup', onPointerUp, false);
|
|
101
|
+
addGlobalListener(window, 'pointercancel', onPointerUp, false);
|
|
102
|
+
return ()=>{
|
|
103
|
+
removeGlobalListener(window, 'pointermove', onPointerMove, false);
|
|
104
|
+
removeGlobalListener(window, 'pointerup', onPointerUp, false);
|
|
105
|
+
removeGlobalListener(window, 'pointercancel', onPointerUp, false);
|
|
106
|
+
};
|
|
107
|
+
} else if (pointerDown === 'mouse' && process.env.NODE_ENV === 'test') {
|
|
108
|
+
let onMouseMove = (e)=>{
|
|
87
109
|
if (e.button === 0) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
e.
|
|
110
|
+
var _state_current_lastPosition, _state_current_lastPosition1;
|
|
111
|
+
var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
|
|
112
|
+
moveEvent(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));
|
|
91
113
|
state.current.lastPosition = {
|
|
92
114
|
pageX: e.pageX,
|
|
93
115
|
pageY: e.pageY
|
|
94
116
|
};
|
|
95
|
-
addGlobalListener(window, 'mousemove', onMouseMove, false);
|
|
96
|
-
addGlobalListener(window, 'mouseup', onMouseUp, false);
|
|
97
117
|
}
|
|
98
118
|
};
|
|
119
|
+
let onMouseUp = (e)=>{
|
|
120
|
+
if (e.button === 0) {
|
|
121
|
+
endEvent(e, 'mouse');
|
|
122
|
+
removeGlobalListener(window, 'mousemove', onMouseMove, false);
|
|
123
|
+
removeGlobalListener(window, 'mouseup', onMouseUp, false);
|
|
124
|
+
setPointerDown(null);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
addGlobalListener(window, 'mousemove', onMouseMove, false);
|
|
128
|
+
addGlobalListener(window, 'mouseup', onMouseUp, false);
|
|
129
|
+
return ()=>{
|
|
130
|
+
removeGlobalListener(window, 'mousemove', onMouseMove, false);
|
|
131
|
+
removeGlobalListener(window, 'mouseup', onMouseUp, false);
|
|
132
|
+
};
|
|
133
|
+
} else if (pointerDown === 'touch' && process.env.NODE_ENV === 'test') {
|
|
99
134
|
let onTouchMove = (e)=>{
|
|
100
135
|
let touch = [
|
|
101
136
|
...e.changedTouches
|
|
@@ -104,7 +139,7 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
104
139
|
var _state_current_lastPosition, _state_current_lastPosition1;
|
|
105
140
|
let { pageX: pageX, pageY: pageY } = e.changedTouches[touch];
|
|
106
141
|
var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
|
|
107
|
-
|
|
142
|
+
moveEvent(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
143
|
state.current.lastPosition = {
|
|
109
144
|
pageX: pageX,
|
|
110
145
|
pageY: pageY
|
|
@@ -116,11 +151,45 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
116
151
|
...e.changedTouches
|
|
117
152
|
].findIndex(({ identifier: identifier })=>identifier === state.current.id);
|
|
118
153
|
if (touch >= 0) {
|
|
119
|
-
|
|
154
|
+
endEvent(e, 'touch');
|
|
120
155
|
state.current.id = null;
|
|
121
156
|
removeGlobalListener(window, 'touchmove', onTouchMove);
|
|
122
157
|
removeGlobalListener(window, 'touchend', onTouchEnd);
|
|
123
158
|
removeGlobalListener(window, 'touchcancel', onTouchEnd);
|
|
159
|
+
setPointerDown(null);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
addGlobalListener(window, 'touchmove', onTouchMove, false);
|
|
163
|
+
addGlobalListener(window, 'touchend', onTouchEnd, false);
|
|
164
|
+
addGlobalListener(window, 'touchcancel', onTouchEnd, false);
|
|
165
|
+
return ()=>{
|
|
166
|
+
removeGlobalListener(window, 'touchmove', onTouchMove, false);
|
|
167
|
+
removeGlobalListener(window, 'touchend', onTouchEnd, false);
|
|
168
|
+
removeGlobalListener(window, 'touchcancel', onTouchEnd, false);
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}, [
|
|
172
|
+
pointerDown,
|
|
173
|
+
addGlobalListener,
|
|
174
|
+
removeGlobalListener
|
|
175
|
+
]);
|
|
176
|
+
let moveProps = (0, $5GN7j$useMemo)(()=>{
|
|
177
|
+
let moveProps = {};
|
|
178
|
+
let start = ()=>{
|
|
179
|
+
(0, $14c0b72509d70225$export$16a4697467175487)();
|
|
180
|
+
state.current.didMove = false;
|
|
181
|
+
};
|
|
182
|
+
if (typeof PointerEvent === 'undefined' && process.env.NODE_ENV === 'test') {
|
|
183
|
+
moveProps.onMouseDown = (e)=>{
|
|
184
|
+
if (e.button === 0) {
|
|
185
|
+
start();
|
|
186
|
+
e.stopPropagation();
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
state.current.lastPosition = {
|
|
189
|
+
pageX: e.pageX,
|
|
190
|
+
pageY: e.pageY
|
|
191
|
+
};
|
|
192
|
+
setPointerDown('mouse');
|
|
124
193
|
}
|
|
125
194
|
};
|
|
126
195
|
moveProps.onTouchStart = (e)=>{
|
|
@@ -134,52 +203,21 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
134
203
|
pageY: pageY
|
|
135
204
|
};
|
|
136
205
|
state.current.id = identifier;
|
|
137
|
-
|
|
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
|
-
}
|
|
206
|
+
setPointerDown('touch');
|
|
156
207
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
}
|
|
208
|
+
} else moveProps.onPointerDown = (e)=>{
|
|
209
|
+
if (e.button === 0 && state.current.id == null) {
|
|
210
|
+
start();
|
|
211
|
+
e.stopPropagation();
|
|
212
|
+
e.preventDefault();
|
|
213
|
+
state.current.lastPosition = {
|
|
214
|
+
pageX: e.pageX,
|
|
215
|
+
pageY: e.pageY
|
|
216
|
+
};
|
|
217
|
+
state.current.id = e.pointerId;
|
|
218
|
+
setPointerDown('pointer');
|
|
219
|
+
}
|
|
220
|
+
};
|
|
183
221
|
let triggerKeyboardMove = (e, deltaX, deltaY)=>{
|
|
184
222
|
start();
|
|
185
223
|
move(e, 'keyboard', deltaX, deltaY);
|
|
@@ -216,8 +254,6 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
216
254
|
return moveProps;
|
|
217
255
|
}, [
|
|
218
256
|
state,
|
|
219
|
-
addGlobalListener,
|
|
220
|
-
removeGlobalListener,
|
|
221
257
|
move,
|
|
222
258
|
end
|
|
223
259
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAwBM,SAAS,0CAAQ,KAAiB;IACvC,IAAI,eAAC,WAAW,UAAE,MAAM,aAAE,SAAS,EAAC,GAAG;IAEvC,IAAI,QAAQ,CAAA,GAAA,aAAK,EAId;QAAC,SAAS;QAAO,cAAc;QAAM,IAAI;IAAI;IAEhD,IAAI,qBAAC,iBAAiB,wBAAE,oBAAoB,EAAC,GAAG,CAAA,GAAA,yBAAiB;IAEjE,IAAI,OAAO,CAAA,GAAA,qBAAa,EAAE,CAAC,eAA0B,aAA0B,QAAgB;QAC7F,IAAI,WAAW,KAAK,WAAW,GAC7B;QAGF,IAAI,CAAC,MAAM,OAAO,CA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AAK;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' && process.env.NODE_ENV === 'test') {\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"}
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAwBM,SAAS,0CAAQ,KAAiB;IACvC,IAAI,eAAC,WAAW,UAAE,MAAM,aAAE,SAAS,EAAC,GAAG;IAEvC,IAAI,QAAQ,CAAA,GAAA,aAAK,EAId;QAAC,SAAS;QAAO,cAAc;QAAM,IAAI;IAAI;IAEhD,IAAI,qBAAC,iBAAiB,wBAAE,oBAAoB,EAAC,GAAG,CAAA,GAAA,yBAAiB;IAEjE,IAAI,OAAO,CAAA,GAAA,kBAAU,EAAE,CAAC,eAA0B,aAA0B,QAAgB;QAC1F,IAAI,WAAW,KAAK,WA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,GAAG,EAAE,cAAc,CAAC,EAAE;gBACpD;gBACA,EAAE,eAAe;gBACjB,EAAE,cAAc;gBAChB,MAAM,OAAO,CAAC,YAAY,GAAG;2BAAC;2BAAO;gBAAK;gBAC1C,MAAM,OAAO,CAAC,EAAE,GAAG;gBACnB,eAAe;YACjB;QACF,OACE,UAAU,aAAa,GAAG,CAAC;YACzB,IAAI,EAAE,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,EAAE,IAAI,MAAM;gBAC9C;gBACA,EAAE,eAAe;gBACjB,EAAE,cAAc;gBAChB,MAAM,OAAO,CAAC,YAAY,GAAG;oBAAC,OAAO,EAAE,KAAK;oBAAE,OAAO,EAAE,KAAK;gBAAA;gBAC5D,MAAM,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS;gBAC9B,eAAe;YACjB;QACF;QAGF,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;QAAM;KAAI;IAErB,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, {useCallback, useMemo, useRef, useState} from 'react';\nimport {useEffectEvent, useGlobalListeners, useLayoutEffect} 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 = useCallback((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 }, [onMoveStart, onMove, state]);\n let moveEvent = useEffectEvent(move);\n\n let end = useCallback((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 }, [onMoveEnd, state]);\n let endEvent = useEffectEvent(end);\n\n let [pointerDown, setPointerDown] = useState<'pointer' | 'mouse' | 'touch' | null>(null);\n useLayoutEffect(() => {\n if (pointerDown === 'pointer') {\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 moveEvent(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 endEvent(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 setPointerDown(null);\n }\n };\n addGlobalListener(window, 'pointermove', onPointerMove, false);\n addGlobalListener(window, 'pointerup', onPointerUp, false);\n addGlobalListener(window, 'pointercancel', onPointerUp, false);\n return () => {\n removeGlobalListener(window, 'pointermove', onPointerMove, false);\n removeGlobalListener(window, 'pointerup', onPointerUp, false);\n removeGlobalListener(window, 'pointercancel', onPointerUp, false);\n };\n } else if (pointerDown === 'mouse' && process.env.NODE_ENV === 'test') {\n let onMouseMove = (e: MouseEvent) => {\n if (e.button === 0) {\n moveEvent(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 endEvent(e, 'mouse');\n removeGlobalListener(window, 'mousemove', onMouseMove, false);\n removeGlobalListener(window, 'mouseup', onMouseUp, false);\n setPointerDown(null);\n }\n };\n addGlobalListener(window, 'mousemove', onMouseMove, false);\n addGlobalListener(window, 'mouseup', onMouseUp, false);\n return () => {\n removeGlobalListener(window, 'mousemove', onMouseMove, false);\n removeGlobalListener(window, 'mouseup', onMouseUp, false);\n };\n } else if (pointerDown === 'touch' && process.env.NODE_ENV === 'test') {\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 moveEvent(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 endEvent(e, 'touch');\n state.current.id = null;\n removeGlobalListener(window, 'touchmove', onTouchMove);\n removeGlobalListener(window, 'touchend', onTouchEnd);\n removeGlobalListener(window, 'touchcancel', onTouchEnd);\n setPointerDown(null);\n }\n };\n addGlobalListener(window, 'touchmove', onTouchMove, false);\n addGlobalListener(window, 'touchend', onTouchEnd, false);\n addGlobalListener(window, 'touchcancel', onTouchEnd, false);\n return () => {\n removeGlobalListener(window, 'touchmove', onTouchMove, false);\n removeGlobalListener(window, 'touchend', onTouchEnd, false);\n removeGlobalListener(window, 'touchcancel', onTouchEnd, false);\n };\n }\n }, [pointerDown, addGlobalListener, removeGlobalListener]);\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' && process.env.NODE_ENV === 'test') {\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 setPointerDown('mouse');\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 setPointerDown('touch');\n };\n } else {\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 setPointerDown('pointer');\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, move, end]);\n\n return {moveProps};\n}\n"],"names":[],"version":3,"file":"useMove.module.js.map"}
|