@react-aria/interactions 3.20.1 → 3.21.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/import.mjs +80 -32
- package/dist/main.js +79 -30
- package/dist/main.js.map +1 -1
- package/dist/module.js +80 -32
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/DOMPropsContext.ts +1 -1
- package/src/index.ts +1 -0
- package/src/useFocusVisible.ts +103 -27
- package/src/usePress.ts +12 -13
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useObjectRef as $bx7SL$useObjectRef, mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, useEffectEvent as $bx7SL$useEffectEvent, getOwnerDocument as $bx7SL$getOwnerDocument, isMac as $bx7SL$isMac, openLink as $bx7SL$openLink, isVirtualClick as $bx7SL$isVirtualClick, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isVirtualPointerEvent as $bx7SL$isVirtualPointerEvent, getOwnerWindow as $bx7SL$getOwnerWindow, isIOS as $bx7SL$isIOS, runAfterTransition as $bx7SL$runAfterTransition, useLayoutEffect as $bx7SL$useLayoutEffect, useEvent as $bx7SL$useEvent, useDescription as $bx7SL$useDescription} from "@react-aria/utils";
|
|
1
|
+
import {useObjectRef as $bx7SL$useObjectRef, mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, useEffectEvent as $bx7SL$useEffectEvent, getOwnerDocument as $bx7SL$getOwnerDocument, chain as $bx7SL$chain, isMac as $bx7SL$isMac, openLink as $bx7SL$openLink, isVirtualClick as $bx7SL$isVirtualClick, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isVirtualPointerEvent as $bx7SL$isVirtualPointerEvent, getOwnerWindow as $bx7SL$getOwnerWindow, isIOS as $bx7SL$isIOS, runAfterTransition as $bx7SL$runAfterTransition, useLayoutEffect as $bx7SL$useLayoutEffect, useEvent as $bx7SL$useEvent, useDescription as $bx7SL$useDescription} from "@react-aria/utils";
|
|
2
2
|
import $bx7SL$react, {useContext as $bx7SL$useContext, useState as $bx7SL$useState, useRef as $bx7SL$useRef, useMemo as $bx7SL$useMemo, useEffect as $bx7SL$useEffect, useCallback as $bx7SL$useCallback} from "react";
|
|
3
3
|
import {_ as $bx7SL$_} from "@swc/helpers/_/_class_private_field_get";
|
|
4
4
|
import {_ as $bx7SL$_1} from "@swc/helpers/_/_class_private_field_init";
|
|
@@ -43,6 +43,7 @@ import {useIsSSR as $bx7SL$useIsSSR} from "@react-aria/ssr";
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
|
|
46
|
+
|
|
46
47
|
/*
|
|
47
48
|
* Copyright 2020 Adobe. All rights reserved.
|
|
48
49
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -110,7 +111,6 @@ function $14c0b72509d70225$export$b0d6fa1ab32e3295(target) {
|
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
|
|
113
|
-
|
|
114
114
|
/*
|
|
115
115
|
* Copyright 2020 Adobe. All rights reserved.
|
|
116
116
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -261,8 +261,13 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
261
261
|
state.isPressed = true;
|
|
262
262
|
shouldStopPropagation = triggerPressStart(e, "keyboard");
|
|
263
263
|
// Focus may move before the key up event, so register the event on the document
|
|
264
|
-
// instead of the same element where the key down event occurred.
|
|
265
|
-
|
|
264
|
+
// instead of the same element where the key down event occurred. Make it capturing so that it will trigger
|
|
265
|
+
// before stopPropagation from useKeyboard on a child element may happen and thus we can still call triggerPress for the parent element.
|
|
266
|
+
let originalTarget = e.currentTarget;
|
|
267
|
+
let pressUp = (e)=>{
|
|
268
|
+
if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e, originalTarget) && !e.repeat && originalTarget.contains(e.target) && state.target) triggerPressUp($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard");
|
|
269
|
+
};
|
|
270
|
+
addGlobalListener((0, $bx7SL$getOwnerDocument)(e.currentTarget), "keyup", (0, $bx7SL$chain)(pressUp, onKeyUp), true);
|
|
266
271
|
}
|
|
267
272
|
if (shouldStopPropagation) e.stopPropagation();
|
|
268
273
|
// Keep track of the keydown events that occur while the Meta (e.g. Command) key is held.
|
|
@@ -275,9 +280,6 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
275
280
|
if (e.metaKey && (0, $bx7SL$isMac)()) (_state_metaKeyEvents = state.metaKeyEvents) === null || _state_metaKeyEvents === void 0 ? void 0 : _state_metaKeyEvents.set(e.key, e.nativeEvent);
|
|
276
281
|
} else if (e.key === "Meta") state.metaKeyEvents = new Map();
|
|
277
282
|
},
|
|
278
|
-
onKeyUp (e) {
|
|
279
|
-
if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && !e.repeat && e.currentTarget.contains(e.target) && state.target) triggerPressUp($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard");
|
|
280
|
-
},
|
|
281
283
|
onClick (e) {
|
|
282
284
|
if (e && !e.currentTarget.contains(e.target)) return;
|
|
283
285
|
if (e && e.button === 0 && !state.isTriggeringEvent && !(0, $bx7SL$openLink).isOpening) {
|
|
@@ -305,9 +307,8 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
305
307
|
var _state_metaKeyEvents1;
|
|
306
308
|
if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
|
|
307
309
|
let target = e.target;
|
|
308
|
-
|
|
310
|
+
triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
|
|
309
311
|
removeAllGlobalListeners();
|
|
310
|
-
if (shouldStopPropagation) e.stopPropagation();
|
|
311
312
|
// If a link was triggered with a key other than Enter, open the URL ourselves.
|
|
312
313
|
// This means the link has a role override, and the default browser behavior
|
|
313
314
|
// only applies when using the Enter key.
|
|
@@ -904,7 +905,7 @@ function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
|
|
|
904
905
|
|
|
905
906
|
let $507fabe10e71c6fb$var$currentModality = null;
|
|
906
907
|
let $507fabe10e71c6fb$var$changeHandlers = new Set();
|
|
907
|
-
let $507fabe10e71c6fb$
|
|
908
|
+
let $507fabe10e71c6fb$export$d90243b58daecda7 = new Map(); // We use a map here to support setting event listeners across multiple document objects.
|
|
908
909
|
let $507fabe10e71c6fb$var$hasEventBeforeFocus = false;
|
|
909
910
|
let $507fabe10e71c6fb$var$hasBlurredWindowRecently = false;
|
|
910
911
|
// Only Tab or Esc keys will make focus visible on text input elements
|
|
@@ -963,39 +964,82 @@ function $507fabe10e71c6fb$var$handleWindowBlur() {
|
|
|
963
964
|
}
|
|
964
965
|
/**
|
|
965
966
|
* Setup global event listeners to control when keyboard focus style should be visible.
|
|
966
|
-
*/ function $507fabe10e71c6fb$var$setupGlobalFocusEvents() {
|
|
967
|
-
if (typeof window === "undefined" || $507fabe10e71c6fb$
|
|
967
|
+
*/ function $507fabe10e71c6fb$var$setupGlobalFocusEvents(element) {
|
|
968
|
+
if (typeof window === "undefined" || $507fabe10e71c6fb$export$d90243b58daecda7.get((0, $bx7SL$getOwnerWindow)(element))) return;
|
|
969
|
+
const windowObject = (0, $bx7SL$getOwnerWindow)(element);
|
|
970
|
+
const documentObject = (0, $bx7SL$getOwnerDocument)(element);
|
|
968
971
|
// Programmatic focus() calls shouldn't affect the current input modality.
|
|
969
972
|
// However, we need to detect other cases when a focus event occurs without
|
|
970
973
|
// a preceding user event (e.g. screen reader focus). Overriding the focus
|
|
971
974
|
// method on HTMLElement.prototype is a bit hacky, but works.
|
|
972
|
-
let focus = HTMLElement.prototype.focus;
|
|
973
|
-
HTMLElement.prototype.focus = function() {
|
|
975
|
+
let focus = windowObject.HTMLElement.prototype.focus;
|
|
976
|
+
windowObject.HTMLElement.prototype.focus = function() {
|
|
974
977
|
$507fabe10e71c6fb$var$hasEventBeforeFocus = true;
|
|
975
978
|
focus.apply(this, arguments);
|
|
976
979
|
};
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
+
documentObject.addEventListener("keydown", $507fabe10e71c6fb$var$handleKeyboardEvent, true);
|
|
981
|
+
documentObject.addEventListener("keyup", $507fabe10e71c6fb$var$handleKeyboardEvent, true);
|
|
982
|
+
documentObject.addEventListener("click", $507fabe10e71c6fb$var$handleClickEvent, true);
|
|
980
983
|
// Register focus events on the window so they are sure to happen
|
|
981
984
|
// before React's event listeners (registered on the document).
|
|
982
|
-
|
|
983
|
-
|
|
985
|
+
windowObject.addEventListener("focus", $507fabe10e71c6fb$var$handleFocusEvent, true);
|
|
986
|
+
windowObject.addEventListener("blur", $507fabe10e71c6fb$var$handleWindowBlur, false);
|
|
984
987
|
if (typeof PointerEvent !== "undefined") {
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
+
documentObject.addEventListener("pointerdown", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
989
|
+
documentObject.addEventListener("pointermove", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
990
|
+
documentObject.addEventListener("pointerup", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
988
991
|
} else {
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
+
documentObject.addEventListener("mousedown", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
993
|
+
documentObject.addEventListener("mousemove", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
994
|
+
documentObject.addEventListener("mouseup", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
992
995
|
}
|
|
993
|
-
|
|
996
|
+
// Add unmount handler
|
|
997
|
+
windowObject.addEventListener("beforeunload", ()=>{
|
|
998
|
+
$507fabe10e71c6fb$var$tearDownWindowFocusTracking(element);
|
|
999
|
+
}, {
|
|
1000
|
+
once: true
|
|
1001
|
+
});
|
|
1002
|
+
$507fabe10e71c6fb$export$d90243b58daecda7.set(windowObject, {
|
|
1003
|
+
focus: focus
|
|
1004
|
+
});
|
|
994
1005
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1006
|
+
const $507fabe10e71c6fb$var$tearDownWindowFocusTracking = (element, loadListener)=>{
|
|
1007
|
+
const windowObject = (0, $bx7SL$getOwnerWindow)(element);
|
|
1008
|
+
const documentObject = (0, $bx7SL$getOwnerDocument)(element);
|
|
1009
|
+
if (loadListener) documentObject.removeEventListener("DOMContentLoaded", loadListener);
|
|
1010
|
+
if (!$507fabe10e71c6fb$export$d90243b58daecda7.has(windowObject)) return;
|
|
1011
|
+
windowObject.HTMLElement.prototype.focus = $507fabe10e71c6fb$export$d90243b58daecda7.get(windowObject).focus;
|
|
1012
|
+
documentObject.removeEventListener("keydown", $507fabe10e71c6fb$var$handleKeyboardEvent, true);
|
|
1013
|
+
documentObject.removeEventListener("keyup", $507fabe10e71c6fb$var$handleKeyboardEvent, true);
|
|
1014
|
+
documentObject.removeEventListener("click", $507fabe10e71c6fb$var$handleClickEvent, true);
|
|
1015
|
+
windowObject.removeEventListener("focus", $507fabe10e71c6fb$var$handleFocusEvent, true);
|
|
1016
|
+
windowObject.removeEventListener("blur", $507fabe10e71c6fb$var$handleWindowBlur, false);
|
|
1017
|
+
if (typeof PointerEvent !== "undefined") {
|
|
1018
|
+
documentObject.removeEventListener("pointerdown", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
1019
|
+
documentObject.removeEventListener("pointermove", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
1020
|
+
documentObject.removeEventListener("pointerup", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
1021
|
+
} else {
|
|
1022
|
+
documentObject.removeEventListener("mousedown", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
1023
|
+
documentObject.removeEventListener("mousemove", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
1024
|
+
documentObject.removeEventListener("mouseup", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
1025
|
+
}
|
|
1026
|
+
$507fabe10e71c6fb$export$d90243b58daecda7.delete(windowObject);
|
|
1027
|
+
};
|
|
1028
|
+
function $507fabe10e71c6fb$export$2f1888112f558a7d(element) {
|
|
1029
|
+
const documentObject = (0, $bx7SL$getOwnerDocument)(element);
|
|
1030
|
+
let loadListener;
|
|
1031
|
+
if (documentObject.readyState !== "loading") $507fabe10e71c6fb$var$setupGlobalFocusEvents(element);
|
|
1032
|
+
else {
|
|
1033
|
+
loadListener = ()=>{
|
|
1034
|
+
$507fabe10e71c6fb$var$setupGlobalFocusEvents(element);
|
|
1035
|
+
};
|
|
1036
|
+
documentObject.addEventListener("DOMContentLoaded", loadListener);
|
|
1037
|
+
}
|
|
1038
|
+
return ()=>$507fabe10e71c6fb$var$tearDownWindowFocusTracking(element, loadListener);
|
|
998
1039
|
}
|
|
1040
|
+
// Server-side rendering does not have the document object defined
|
|
1041
|
+
// eslint-disable-next-line no-restricted-globals
|
|
1042
|
+
if (typeof document !== "undefined") $507fabe10e71c6fb$export$2f1888112f558a7d();
|
|
999
1043
|
function $507fabe10e71c6fb$export$b9b3dfddab17db27() {
|
|
1000
1044
|
return $507fabe10e71c6fb$var$currentModality !== "pointer";
|
|
1001
1045
|
}
|
|
@@ -1036,8 +1080,12 @@ const $507fabe10e71c6fb$var$nonTextInputTypes = new Set([
|
|
|
1036
1080
|
* focus visible style can be properly set.
|
|
1037
1081
|
*/ function $507fabe10e71c6fb$var$isKeyboardFocusEvent(isTextInput, modality, e) {
|
|
1038
1082
|
var _e_target;
|
|
1039
|
-
|
|
1040
|
-
|
|
1083
|
+
const IHTMLInputElement = typeof window !== "undefined" ? (0, $bx7SL$getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLInputElement : HTMLInputElement;
|
|
1084
|
+
const IHTMLTextAreaElement = typeof window !== "undefined" ? (0, $bx7SL$getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLTextAreaElement : HTMLTextAreaElement;
|
|
1085
|
+
const IHTMLElement = typeof window !== "undefined" ? (0, $bx7SL$getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLElement : HTMLElement;
|
|
1086
|
+
const IKeyboardEvent = typeof window !== "undefined" ? (0, $bx7SL$getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).KeyboardEvent : KeyboardEvent;
|
|
1087
|
+
isTextInput = isTextInput || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLInputElement && !$507fabe10e71c6fb$var$nonTextInputTypes.has(e === null || e === void 0 ? void 0 : (_e_target = e.target) === null || _e_target === void 0 ? void 0 : _e_target.type) || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLTextAreaElement || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLElement && (e === null || e === void 0 ? void 0 : e.target.isContentEditable);
|
|
1088
|
+
return !(isTextInput && modality === "keyboard" && e instanceof IKeyboardEvent && !$507fabe10e71c6fb$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]);
|
|
1041
1089
|
}
|
|
1042
1090
|
function $507fabe10e71c6fb$export$ffd9e5021c1fb2d6(props = {}) {
|
|
1043
1091
|
let { isTextInput: isTextInput, autoFocus: autoFocus } = props;
|
|
@@ -1746,5 +1794,5 @@ function $8a26561d2877236e$export$c24ed0104d07eab9(props) {
|
|
|
1746
1794
|
|
|
1747
1795
|
|
|
1748
1796
|
|
|
1749
|
-
export {$3b117e43dc0ca95d$export$27c701ed9e449e99 as Pressable, $f1ab8c75478c6f73$export$3351871ee4b288b8 as PressResponder, $f1ab8c75478c6f73$export$cf75428e0b9ed1ea as ClearPressResponder, $a1ea59d68270f0dd$export$f8168d8dd8fd66e6 as useFocus, $507fabe10e71c6fb$export$b9b3dfddab17db27 as isFocusVisible, $507fabe10e71c6fb$export$630ff653c5ada6a9 as getInteractionModality, $507fabe10e71c6fb$export$8397ddfc504fdb9a as setInteractionModality, $507fabe10e71c6fb$export$98e20ec92f614cfe as useInteractionModality, $507fabe10e71c6fb$export$ffd9e5021c1fb2d6 as useFocusVisible, $507fabe10e71c6fb$export$ec71b4b83ac08ec3 as useFocusVisibleListener, $9ab94262bd0047c7$export$420e68273165f4ec as useFocusWithin, $6179b936705e76d3$export$ae780daf29e6d456 as useHover, $e0b6e0b68ec7f50f$export$872b660ac5a1ff98 as useInteractOutside, $46d819fcbaf35654$export$8f71654801c2f7cd as useKeyboard, $e8a7022cf87cba2a$export$36da96379f79f245 as useMove, $f6c31cce2adf654f$export$45712eceda6fad21 as usePress, $7d0a636d7a4dcefd$export$2123ff2b87c81ca as useScrollWheel, $8a26561d2877236e$export$c24ed0104d07eab9 as useLongPress};
|
|
1797
|
+
export {$3b117e43dc0ca95d$export$27c701ed9e449e99 as Pressable, $f1ab8c75478c6f73$export$3351871ee4b288b8 as PressResponder, $f1ab8c75478c6f73$export$cf75428e0b9ed1ea as ClearPressResponder, $a1ea59d68270f0dd$export$f8168d8dd8fd66e6 as useFocus, $507fabe10e71c6fb$export$b9b3dfddab17db27 as isFocusVisible, $507fabe10e71c6fb$export$630ff653c5ada6a9 as getInteractionModality, $507fabe10e71c6fb$export$8397ddfc504fdb9a as setInteractionModality, $507fabe10e71c6fb$export$2f1888112f558a7d as addWindowFocusTracking, $507fabe10e71c6fb$export$98e20ec92f614cfe as useInteractionModality, $507fabe10e71c6fb$export$ffd9e5021c1fb2d6 as useFocusVisible, $507fabe10e71c6fb$export$ec71b4b83ac08ec3 as useFocusVisibleListener, $9ab94262bd0047c7$export$420e68273165f4ec as useFocusWithin, $6179b936705e76d3$export$ae780daf29e6d456 as useHover, $e0b6e0b68ec7f50f$export$872b660ac5a1ff98 as useInteractOutside, $46d819fcbaf35654$export$8f71654801c2f7cd as useKeyboard, $e8a7022cf87cba2a$export$36da96379f79f245 as useMove, $f6c31cce2adf654f$export$45712eceda6fad21 as usePress, $7d0a636d7a4dcefd$export$2123ff2b87c81ca as useScrollWheel, $8a26561d2877236e$export$c24ed0104d07eab9 as useLongPress};
|
|
1750
1798
|
//# sourceMappingURL=module.js.map
|