@react-aria/interactions 3.7.0 → 3.8.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/main.js +1283 -1856
- package/dist/main.js.map +1 -1
- package/dist/module.js +1238 -1770
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/useFocusVisible.ts +3 -1
- package/src/useMove.ts +39 -24
- package/src/usePress.ts +17 -9
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;AGwBA,2BAA4B,SAAQ,WAAW;IAC7C,+FAA+F;IAC/F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,yEAAyE;IACzE,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC;AAED,+BAAgC,SAAQ,UAAU;IAChD,mCAAmC;IACnC,GAAG,CAAC,EAAE,UAAU,WAAW,CAAC,CAAA;CAC7B;AAsBD;IACE,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAC;IACnB,6CAA6C;IAC7C,UAAU,EAAE,eAAe,WAAW,CAAC,CAAA;CACxC;AAeD;;;;GAIG;AACH,yBAAyB,KAAK,EAAE,cAAc,GAAG,WAAW,CA0jB3D;ACtoBD,wBAAyB,SAAQ,UAAU;IACzC,QAAQ,EAAE,aAAa,eAAe,WAAW,CAAC,EAAE,MAAM,CAAC,CAAA;CAC5D;AAED,OAAO,MAAM,6FAUX,CAAC;ACbH,6BAA8B,SAAQ,UAAU;IAC9C,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,OAAO,MAAM,uGA8BX,CAAC;AC/BH,oBAAqB,SAAQ,WAAW;IACtC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E,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC7C;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC;AAED;IACE,6CAA6C;IAC7C,cAAc,EAAE,eAAe,WAAW,CAAC,CAAA;CAC5C;AAID;;;GAGG;AACH,6BAA6B,KAAK,EAAE,cAAc,GAAG,eAAe,CAwEnE","sources":["packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/textSelection.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/utils.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/context.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/usePress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/Pressable.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/PressResponder.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocus.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusVisible.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusWithin.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useHover.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useInteractOutside.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/createEventHandler.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useKeyboard.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useMove.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useScrollWheel.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useLongPress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/index.ts","packages/@react-aria/interactions/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"/*\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\nexport * from './Pressable';\nexport * from './PressResponder';\nexport * from './useFocus';\nexport * from './useFocusVisible';\nexport * from './useFocusWithin';\nexport * from './useHover';\nexport * from './useInteractOutside';\nexport * from './useKeyboard';\nexport * from './useMove';\nexport * from './usePress';\nexport * from './useScrollWheel';\nexport * from './useLongPress';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/interactions",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.2",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/utils": "^3.
|
|
22
|
-
"@react-types/shared": "^3.
|
|
21
|
+
"@react-aria/utils": "^3.11.3",
|
|
22
|
+
"@react-types/shared": "^3.11.2"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "ed8d8d984c2f7f2c31e8b18795b97858a95e4729"
|
|
31
31
|
}
|
package/src/useFocusVisible.ts
CHANGED
|
@@ -231,6 +231,8 @@ export function useFocusVisibleListener(fn: FocusVisibleHandler, deps: ReadonlyA
|
|
|
231
231
|
fn(isFocusVisible());
|
|
232
232
|
};
|
|
233
233
|
changeHandlers.add(handler);
|
|
234
|
-
return () =>
|
|
234
|
+
return () => {
|
|
235
|
+
changeHandlers.delete(handler);
|
|
236
|
+
};
|
|
235
237
|
}, deps);
|
|
236
238
|
}
|
package/src/useMove.ts
CHANGED
|
@@ -20,6 +20,13 @@ interface MoveResult {
|
|
|
20
20
|
moveProps: HTMLAttributes<HTMLElement>
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
interface EventBase {
|
|
24
|
+
shiftKey: boolean,
|
|
25
|
+
ctrlKey: boolean,
|
|
26
|
+
metaKey: boolean,
|
|
27
|
+
altKey: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
/**
|
|
24
31
|
* Handles move interactions across mouse, touch, and keyboard, including dragging with
|
|
25
32
|
* the mouse or touch, and using the arrow keys. Normalizes behavior across browsers and
|
|
@@ -43,7 +50,7 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
43
50
|
disableTextSelection();
|
|
44
51
|
state.current.didMove = false;
|
|
45
52
|
};
|
|
46
|
-
let move = (pointerType: PointerType, deltaX: number, deltaY: number) => {
|
|
53
|
+
let move = (originalEvent: EventBase, pointerType: PointerType, deltaX: number, deltaY: number) => {
|
|
47
54
|
if (deltaX === 0 && deltaY === 0) {
|
|
48
55
|
return;
|
|
49
56
|
}
|
|
@@ -52,22 +59,34 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
52
59
|
state.current.didMove = true;
|
|
53
60
|
onMoveStart?.({
|
|
54
61
|
type: 'movestart',
|
|
55
|
-
pointerType
|
|
62
|
+
pointerType,
|
|
63
|
+
shiftKey: originalEvent.shiftKey,
|
|
64
|
+
metaKey: originalEvent.metaKey,
|
|
65
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
66
|
+
altKey: originalEvent.altKey
|
|
56
67
|
});
|
|
57
68
|
}
|
|
58
69
|
onMove({
|
|
59
70
|
type: 'move',
|
|
60
71
|
pointerType,
|
|
61
72
|
deltaX: deltaX,
|
|
62
|
-
deltaY: deltaY
|
|
73
|
+
deltaY: deltaY,
|
|
74
|
+
shiftKey: originalEvent.shiftKey,
|
|
75
|
+
metaKey: originalEvent.metaKey,
|
|
76
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
77
|
+
altKey: originalEvent.altKey
|
|
63
78
|
});
|
|
64
79
|
};
|
|
65
|
-
let end = (pointerType: PointerType) => {
|
|
80
|
+
let end = (originalEvent: EventBase, pointerType: PointerType) => {
|
|
66
81
|
restoreTextSelection();
|
|
67
82
|
if (state.current.didMove) {
|
|
68
83
|
onMoveEnd?.({
|
|
69
84
|
type: 'moveend',
|
|
70
|
-
pointerType
|
|
85
|
+
pointerType,
|
|
86
|
+
shiftKey: originalEvent.shiftKey,
|
|
87
|
+
metaKey: originalEvent.metaKey,
|
|
88
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
89
|
+
altKey: originalEvent.altKey
|
|
71
90
|
});
|
|
72
91
|
}
|
|
73
92
|
};
|
|
@@ -75,13 +94,13 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
75
94
|
if (typeof PointerEvent === 'undefined') {
|
|
76
95
|
let onMouseMove = (e: MouseEvent) => {
|
|
77
96
|
if (e.button === 0) {
|
|
78
|
-
move('mouse', e.pageX - state.current.lastPosition.pageX, e.pageY - state.current.lastPosition.pageY);
|
|
97
|
+
move(e, 'mouse', e.pageX - state.current.lastPosition.pageX, e.pageY - state.current.lastPosition.pageY);
|
|
79
98
|
state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};
|
|
80
99
|
}
|
|
81
100
|
};
|
|
82
101
|
let onMouseUp = (e: MouseEvent) => {
|
|
83
102
|
if (e.button === 0) {
|
|
84
|
-
end('mouse');
|
|
103
|
+
end(e, 'mouse');
|
|
85
104
|
removeGlobalListener(window, 'mousemove', onMouseMove, false);
|
|
86
105
|
removeGlobalListener(window, 'mouseup', onMouseUp, false);
|
|
87
106
|
}
|
|
@@ -98,19 +117,17 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
98
117
|
};
|
|
99
118
|
|
|
100
119
|
let onTouchMove = (e: TouchEvent) => {
|
|
101
|
-
// @ts-ignore
|
|
102
120
|
let touch = [...e.changedTouches].findIndex(({identifier}) => identifier === state.current.id);
|
|
103
121
|
if (touch >= 0) {
|
|
104
122
|
let {pageX, pageY} = e.changedTouches[touch];
|
|
105
|
-
move('touch', pageX - state.current.lastPosition.pageX, pageY - state.current.lastPosition.pageY);
|
|
123
|
+
move(e, 'touch', pageX - state.current.lastPosition.pageX, pageY - state.current.lastPosition.pageY);
|
|
106
124
|
state.current.lastPosition = {pageX, pageY};
|
|
107
125
|
}
|
|
108
126
|
};
|
|
109
127
|
let onTouchEnd = (e: TouchEvent) => {
|
|
110
|
-
// @ts-ignore
|
|
111
128
|
let touch = [...e.changedTouches].findIndex(({identifier}) => identifier === state.current.id);
|
|
112
129
|
if (touch >= 0) {
|
|
113
|
-
end('touch');
|
|
130
|
+
end(e, 'touch');
|
|
114
131
|
state.current.id = null;
|
|
115
132
|
removeGlobalListener(window, 'touchmove', onTouchMove);
|
|
116
133
|
removeGlobalListener(window, 'touchend', onTouchEnd);
|
|
@@ -135,22 +152,20 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
135
152
|
} else {
|
|
136
153
|
let onPointerMove = (e: PointerEvent) => {
|
|
137
154
|
if (e.pointerId === state.current.id) {
|
|
138
|
-
|
|
139
|
-
let pointerType: PointerType = e.pointerType || 'mouse';
|
|
155
|
+
let pointerType = (e.pointerType || 'mouse') as PointerType;
|
|
140
156
|
|
|
141
157
|
// Problems with PointerEvent#movementX/movementY:
|
|
142
158
|
// 1. it is always 0 on macOS Safari.
|
|
143
159
|
// 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
|
|
144
|
-
move(pointerType, e.pageX - state.current.lastPosition.pageX, e.pageY - state.current.lastPosition.pageY);
|
|
160
|
+
move(e, pointerType, e.pageX - state.current.lastPosition.pageX, e.pageY - state.current.lastPosition.pageY);
|
|
145
161
|
state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};
|
|
146
162
|
}
|
|
147
163
|
};
|
|
148
164
|
|
|
149
165
|
let onPointerUp = (e: PointerEvent) => {
|
|
150
166
|
if (e.pointerId === state.current.id) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
end(pointerType);
|
|
167
|
+
let pointerType = (e.pointerType || 'mouse') as PointerType;
|
|
168
|
+
end(e, pointerType);
|
|
154
169
|
state.current.id = null;
|
|
155
170
|
removeGlobalListener(window, 'pointermove', onPointerMove, false);
|
|
156
171
|
removeGlobalListener(window, 'pointerup', onPointerUp, false);
|
|
@@ -172,10 +187,10 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
172
187
|
};
|
|
173
188
|
}
|
|
174
189
|
|
|
175
|
-
let triggerKeyboardMove = (deltaX: number, deltaY: number) => {
|
|
190
|
+
let triggerKeyboardMove = (e: EventBase, deltaX: number, deltaY: number) => {
|
|
176
191
|
start();
|
|
177
|
-
move('keyboard', deltaX, deltaY);
|
|
178
|
-
end('keyboard');
|
|
192
|
+
move(e, 'keyboard', deltaX, deltaY);
|
|
193
|
+
end(e, 'keyboard');
|
|
179
194
|
};
|
|
180
195
|
|
|
181
196
|
moveProps.onKeyDown = (e) => {
|
|
@@ -184,25 +199,25 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
184
199
|
case 'ArrowLeft':
|
|
185
200
|
e.preventDefault();
|
|
186
201
|
e.stopPropagation();
|
|
187
|
-
triggerKeyboardMove(-1, 0);
|
|
202
|
+
triggerKeyboardMove(e, -1, 0);
|
|
188
203
|
break;
|
|
189
204
|
case 'Right':
|
|
190
205
|
case 'ArrowRight':
|
|
191
206
|
e.preventDefault();
|
|
192
207
|
e.stopPropagation();
|
|
193
|
-
triggerKeyboardMove(1, 0);
|
|
208
|
+
triggerKeyboardMove(e, 1, 0);
|
|
194
209
|
break;
|
|
195
210
|
case 'Up':
|
|
196
211
|
case 'ArrowUp':
|
|
197
212
|
e.preventDefault();
|
|
198
213
|
e.stopPropagation();
|
|
199
|
-
triggerKeyboardMove(0, -1);
|
|
214
|
+
triggerKeyboardMove(e, 0, -1);
|
|
200
215
|
break;
|
|
201
216
|
case 'Down':
|
|
202
217
|
case 'ArrowDown':
|
|
203
218
|
e.preventDefault();
|
|
204
219
|
e.stopPropagation();
|
|
205
|
-
triggerKeyboardMove(0, 1);
|
|
220
|
+
triggerKeyboardMove(e, 0, 1);
|
|
206
221
|
break;
|
|
207
222
|
}
|
|
208
223
|
};
|
package/src/usePress.ts
CHANGED
|
@@ -103,7 +103,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
103
103
|
shouldCancelOnPointerExit,
|
|
104
104
|
allowTextSelectionOnPress,
|
|
105
105
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
106
|
-
ref: _, // Removing `ref` from `domProps` because TypeScript is dumb
|
|
106
|
+
ref: _, // Removing `ref` from `domProps` because TypeScript is dumb
|
|
107
107
|
...domProps
|
|
108
108
|
} = usePressResponderContext(props);
|
|
109
109
|
let propsRef = useRef<PressHookProps>(null);
|
|
@@ -229,7 +229,9 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
229
229
|
let pressProps: HTMLAttributes<HTMLElement> = {
|
|
230
230
|
onKeyDown(e) {
|
|
231
231
|
if (isValidKeyboardEvent(e.nativeEvent) && e.currentTarget.contains(e.target as HTMLElement)) {
|
|
232
|
-
e.
|
|
232
|
+
if (shouldPreventDefaultKeyboard(e.target as Element)) {
|
|
233
|
+
e.preventDefault();
|
|
234
|
+
}
|
|
233
235
|
e.stopPropagation();
|
|
234
236
|
|
|
235
237
|
// If the event is repeating, it may have started on a different element
|
|
@@ -283,7 +285,9 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
283
285
|
|
|
284
286
|
let onKeyUp = (e: KeyboardEvent) => {
|
|
285
287
|
if (state.isPressed && isValidKeyboardEvent(e)) {
|
|
286
|
-
e.
|
|
288
|
+
if (shouldPreventDefaultKeyboard(e.target as Element)) {
|
|
289
|
+
e.preventDefault();
|
|
290
|
+
}
|
|
287
291
|
e.stopPropagation();
|
|
288
292
|
|
|
289
293
|
state.isPressed = false;
|
|
@@ -317,7 +321,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
317
321
|
|
|
318
322
|
// Due to browser inconsistencies, especially on mobile browsers, we prevent
|
|
319
323
|
// default on pointer down and handle focusing the pressable element ourselves.
|
|
320
|
-
if (shouldPreventDefault(e.
|
|
324
|
+
if (shouldPreventDefault(e.currentTarget as HTMLElement)) {
|
|
321
325
|
e.preventDefault();
|
|
322
326
|
}
|
|
323
327
|
|
|
@@ -355,7 +359,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
355
359
|
// Chrome and Firefox on touch Windows devices require mouse down events
|
|
356
360
|
// to be canceled in addition to pointer events, or an extra asynchronous
|
|
357
361
|
// focus event will be fired.
|
|
358
|
-
if (shouldPreventDefault(e.
|
|
362
|
+
if (shouldPreventDefault(e.currentTarget as HTMLElement)) {
|
|
359
363
|
e.preventDefault();
|
|
360
364
|
}
|
|
361
365
|
|
|
@@ -439,7 +443,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
439
443
|
|
|
440
444
|
// Due to browser inconsistencies, especially on mobile browsers, we prevent
|
|
441
445
|
// default on mouse down and handle focusing the pressable element ourselves.
|
|
442
|
-
if (shouldPreventDefault(e.
|
|
446
|
+
if (shouldPreventDefault(e.currentTarget as HTMLElement)) {
|
|
443
447
|
e.preventDefault();
|
|
444
448
|
}
|
|
445
449
|
|
|
@@ -760,9 +764,13 @@ function isOverTarget(point: EventPoint, target: HTMLElement) {
|
|
|
760
764
|
return areRectanglesOverlapping(rect, pointRect);
|
|
761
765
|
}
|
|
762
766
|
|
|
763
|
-
function shouldPreventDefault(target:
|
|
764
|
-
// We cannot prevent default if the target is
|
|
765
|
-
return !target.
|
|
767
|
+
function shouldPreventDefault(target: HTMLElement) {
|
|
768
|
+
// We cannot prevent default if the target is a draggable element.
|
|
769
|
+
return !target.draggable;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
function shouldPreventDefaultKeyboard(target: Element) {
|
|
773
|
+
return !((target.tagName === 'INPUT' || target.tagName === 'BUTTON') && (target as HTMLButtonElement | HTMLInputElement).type === 'submit');
|
|
766
774
|
}
|
|
767
775
|
|
|
768
776
|
function isVirtualPointerEvent(event: PointerEvent) {
|