@react-aria/interactions 3.20.0 → 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 +81 -33
- package/dist/main.js +80 -31
- package/dist/main.js.map +1 -1
- package/dist/module.js +81 -33
- 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 +4 -4
- package/src/DOMPropsContext.ts +1 -1
- package/src/index.ts +1 -0
- package/src/textSelection.ts +2 -2
- package/src/useFocusVisible.ts +103 -27
- package/src/usePress.ts +12 -13
package/dist/import.mjs
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");
|
|
@@ -102,7 +103,7 @@ function $14c0b72509d70225$export$b0d6fa1ab32e3295(target) {
|
|
|
102
103
|
{
|
|
103
104
|
if (target && $14c0b72509d70225$var$modifiedElementMap.has(target)) {
|
|
104
105
|
let targetOldUserSelect = $14c0b72509d70225$var$modifiedElementMap.get(target);
|
|
105
|
-
if (target.style.userSelect === "none"
|
|
106
|
+
if (target.style.userSelect === "none") target.style.userSelect = targetOldUserSelect;
|
|
106
107
|
if (target.getAttribute("style") === "") target.removeAttribute("style");
|
|
107
108
|
$14c0b72509d70225$var$modifiedElementMap.delete(target);
|
|
108
109
|
}
|
|
@@ -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
|
package/dist/main.js
CHANGED
|
@@ -21,6 +21,7 @@ $parcel$export(module.exports, "useFocus", () => $5cb73d0ce355b0dc$export$f8168d
|
|
|
21
21
|
$parcel$export(module.exports, "isFocusVisible", () => $e77252a287ef94ab$export$b9b3dfddab17db27);
|
|
22
22
|
$parcel$export(module.exports, "getInteractionModality", () => $e77252a287ef94ab$export$630ff653c5ada6a9);
|
|
23
23
|
$parcel$export(module.exports, "setInteractionModality", () => $e77252a287ef94ab$export$8397ddfc504fdb9a);
|
|
24
|
+
$parcel$export(module.exports, "addWindowFocusTracking", () => $e77252a287ef94ab$export$2f1888112f558a7d);
|
|
24
25
|
$parcel$export(module.exports, "useInteractionModality", () => $e77252a287ef94ab$export$98e20ec92f614cfe);
|
|
25
26
|
$parcel$export(module.exports, "useFocusVisible", () => $e77252a287ef94ab$export$ffd9e5021c1fb2d6);
|
|
26
27
|
$parcel$export(module.exports, "useFocusVisibleListener", () => $e77252a287ef94ab$export$ec71b4b83ac08ec3);
|
|
@@ -70,6 +71,7 @@ $parcel$export(module.exports, "useLongPress", () => $3cd7b5d0eebf0ca9$export$c2
|
|
|
70
71
|
|
|
71
72
|
|
|
72
73
|
|
|
74
|
+
|
|
73
75
|
/*
|
|
74
76
|
* Copyright 2020 Adobe. All rights reserved.
|
|
75
77
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -129,7 +131,7 @@ function $f7e14e656343df57$export$b0d6fa1ab32e3295(target) {
|
|
|
129
131
|
{
|
|
130
132
|
if (target && $f7e14e656343df57$var$modifiedElementMap.has(target)) {
|
|
131
133
|
let targetOldUserSelect = $f7e14e656343df57$var$modifiedElementMap.get(target);
|
|
132
|
-
if (target.style.userSelect === "none"
|
|
134
|
+
if (target.style.userSelect === "none") target.style.userSelect = targetOldUserSelect;
|
|
133
135
|
if (target.getAttribute("style") === "") target.removeAttribute("style");
|
|
134
136
|
$f7e14e656343df57$var$modifiedElementMap.delete(target);
|
|
135
137
|
}
|
|
@@ -137,7 +139,6 @@ function $f7e14e656343df57$export$b0d6fa1ab32e3295(target) {
|
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
|
|
140
|
-
|
|
141
142
|
/*
|
|
142
143
|
* Copyright 2020 Adobe. All rights reserved.
|
|
143
144
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -288,8 +289,13 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
288
289
|
state.isPressed = true;
|
|
289
290
|
shouldStopPropagation = triggerPressStart(e, "keyboard");
|
|
290
291
|
// Focus may move before the key up event, so register the event on the document
|
|
291
|
-
// instead of the same element where the key down event occurred.
|
|
292
|
-
|
|
292
|
+
// instead of the same element where the key down event occurred. Make it capturing so that it will trigger
|
|
293
|
+
// before stopPropagation from useKeyboard on a child element may happen and thus we can still call triggerPress for the parent element.
|
|
294
|
+
let originalTarget = e.currentTarget;
|
|
295
|
+
let pressUp = (e)=>{
|
|
296
|
+
if ($0294ea432cd92340$var$isValidKeyboardEvent(e, originalTarget) && !e.repeat && originalTarget.contains(e.target) && state.target) triggerPressUp($0294ea432cd92340$var$createEvent(state.target, e), "keyboard");
|
|
297
|
+
};
|
|
298
|
+
addGlobalListener((0, $goTMa$reactariautils.getOwnerDocument)(e.currentTarget), "keyup", (0, $goTMa$reactariautils.chain)(pressUp, onKeyUp), true);
|
|
293
299
|
}
|
|
294
300
|
if (shouldStopPropagation) e.stopPropagation();
|
|
295
301
|
// Keep track of the keydown events that occur while the Meta (e.g. Command) key is held.
|
|
@@ -302,9 +308,6 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
302
308
|
if (e.metaKey && (0, $goTMa$reactariautils.isMac)()) (_state_metaKeyEvents = state.metaKeyEvents) === null || _state_metaKeyEvents === void 0 ? void 0 : _state_metaKeyEvents.set(e.key, e.nativeEvent);
|
|
303
309
|
} else if (e.key === "Meta") state.metaKeyEvents = new Map();
|
|
304
310
|
},
|
|
305
|
-
onKeyUp (e) {
|
|
306
|
-
if ($0294ea432cd92340$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && !e.repeat && e.currentTarget.contains(e.target) && state.target) triggerPressUp($0294ea432cd92340$var$createEvent(state.target, e), "keyboard");
|
|
307
|
-
},
|
|
308
311
|
onClick (e) {
|
|
309
312
|
if (e && !e.currentTarget.contains(e.target)) return;
|
|
310
313
|
if (e && e.button === 0 && !state.isTriggeringEvent && !(0, $goTMa$reactariautils.openLink).isOpening) {
|
|
@@ -332,9 +335,8 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
332
335
|
var _state_metaKeyEvents1;
|
|
333
336
|
if ($0294ea432cd92340$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
|
|
334
337
|
let target = e.target;
|
|
335
|
-
|
|
338
|
+
triggerPressEnd($0294ea432cd92340$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
|
|
336
339
|
removeAllGlobalListeners();
|
|
337
|
-
if (shouldStopPropagation) e.stopPropagation();
|
|
338
340
|
// If a link was triggered with a key other than Enter, open the URL ourselves.
|
|
339
341
|
// This means the link has a role override, and the default browser behavior
|
|
340
342
|
// only applies when using the Enter key.
|
|
@@ -931,7 +933,7 @@ function $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6(props) {
|
|
|
931
933
|
|
|
932
934
|
let $e77252a287ef94ab$var$currentModality = null;
|
|
933
935
|
let $e77252a287ef94ab$var$changeHandlers = new Set();
|
|
934
|
-
let $e77252a287ef94ab$
|
|
936
|
+
let $e77252a287ef94ab$export$d90243b58daecda7 = new Map(); // We use a map here to support setting event listeners across multiple document objects.
|
|
935
937
|
let $e77252a287ef94ab$var$hasEventBeforeFocus = false;
|
|
936
938
|
let $e77252a287ef94ab$var$hasBlurredWindowRecently = false;
|
|
937
939
|
// Only Tab or Esc keys will make focus visible on text input elements
|
|
@@ -990,39 +992,82 @@ function $e77252a287ef94ab$var$handleWindowBlur() {
|
|
|
990
992
|
}
|
|
991
993
|
/**
|
|
992
994
|
* Setup global event listeners to control when keyboard focus style should be visible.
|
|
993
|
-
*/ function $e77252a287ef94ab$var$setupGlobalFocusEvents() {
|
|
994
|
-
if (typeof window === "undefined" || $e77252a287ef94ab$
|
|
995
|
+
*/ function $e77252a287ef94ab$var$setupGlobalFocusEvents(element) {
|
|
996
|
+
if (typeof window === "undefined" || $e77252a287ef94ab$export$d90243b58daecda7.get((0, $goTMa$reactariautils.getOwnerWindow)(element))) return;
|
|
997
|
+
const windowObject = (0, $goTMa$reactariautils.getOwnerWindow)(element);
|
|
998
|
+
const documentObject = (0, $goTMa$reactariautils.getOwnerDocument)(element);
|
|
995
999
|
// Programmatic focus() calls shouldn't affect the current input modality.
|
|
996
1000
|
// However, we need to detect other cases when a focus event occurs without
|
|
997
1001
|
// a preceding user event (e.g. screen reader focus). Overriding the focus
|
|
998
1002
|
// method on HTMLElement.prototype is a bit hacky, but works.
|
|
999
|
-
let focus = HTMLElement.prototype.focus;
|
|
1000
|
-
HTMLElement.prototype.focus = function() {
|
|
1003
|
+
let focus = windowObject.HTMLElement.prototype.focus;
|
|
1004
|
+
windowObject.HTMLElement.prototype.focus = function() {
|
|
1001
1005
|
$e77252a287ef94ab$var$hasEventBeforeFocus = true;
|
|
1002
1006
|
focus.apply(this, arguments);
|
|
1003
1007
|
};
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1008
|
+
documentObject.addEventListener("keydown", $e77252a287ef94ab$var$handleKeyboardEvent, true);
|
|
1009
|
+
documentObject.addEventListener("keyup", $e77252a287ef94ab$var$handleKeyboardEvent, true);
|
|
1010
|
+
documentObject.addEventListener("click", $e77252a287ef94ab$var$handleClickEvent, true);
|
|
1007
1011
|
// Register focus events on the window so they are sure to happen
|
|
1008
1012
|
// before React's event listeners (registered on the document).
|
|
1009
|
-
|
|
1010
|
-
|
|
1013
|
+
windowObject.addEventListener("focus", $e77252a287ef94ab$var$handleFocusEvent, true);
|
|
1014
|
+
windowObject.addEventListener("blur", $e77252a287ef94ab$var$handleWindowBlur, false);
|
|
1011
1015
|
if (typeof PointerEvent !== "undefined") {
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1016
|
+
documentObject.addEventListener("pointerdown", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1017
|
+
documentObject.addEventListener("pointermove", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1018
|
+
documentObject.addEventListener("pointerup", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1015
1019
|
} else {
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1020
|
+
documentObject.addEventListener("mousedown", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1021
|
+
documentObject.addEventListener("mousemove", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1022
|
+
documentObject.addEventListener("mouseup", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1019
1023
|
}
|
|
1020
|
-
|
|
1024
|
+
// Add unmount handler
|
|
1025
|
+
windowObject.addEventListener("beforeunload", ()=>{
|
|
1026
|
+
$e77252a287ef94ab$var$tearDownWindowFocusTracking(element);
|
|
1027
|
+
}, {
|
|
1028
|
+
once: true
|
|
1029
|
+
});
|
|
1030
|
+
$e77252a287ef94ab$export$d90243b58daecda7.set(windowObject, {
|
|
1031
|
+
focus: focus
|
|
1032
|
+
});
|
|
1021
1033
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1034
|
+
const $e77252a287ef94ab$var$tearDownWindowFocusTracking = (element, loadListener)=>{
|
|
1035
|
+
const windowObject = (0, $goTMa$reactariautils.getOwnerWindow)(element);
|
|
1036
|
+
const documentObject = (0, $goTMa$reactariautils.getOwnerDocument)(element);
|
|
1037
|
+
if (loadListener) documentObject.removeEventListener("DOMContentLoaded", loadListener);
|
|
1038
|
+
if (!$e77252a287ef94ab$export$d90243b58daecda7.has(windowObject)) return;
|
|
1039
|
+
windowObject.HTMLElement.prototype.focus = $e77252a287ef94ab$export$d90243b58daecda7.get(windowObject).focus;
|
|
1040
|
+
documentObject.removeEventListener("keydown", $e77252a287ef94ab$var$handleKeyboardEvent, true);
|
|
1041
|
+
documentObject.removeEventListener("keyup", $e77252a287ef94ab$var$handleKeyboardEvent, true);
|
|
1042
|
+
documentObject.removeEventListener("click", $e77252a287ef94ab$var$handleClickEvent, true);
|
|
1043
|
+
windowObject.removeEventListener("focus", $e77252a287ef94ab$var$handleFocusEvent, true);
|
|
1044
|
+
windowObject.removeEventListener("blur", $e77252a287ef94ab$var$handleWindowBlur, false);
|
|
1045
|
+
if (typeof PointerEvent !== "undefined") {
|
|
1046
|
+
documentObject.removeEventListener("pointerdown", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1047
|
+
documentObject.removeEventListener("pointermove", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1048
|
+
documentObject.removeEventListener("pointerup", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1049
|
+
} else {
|
|
1050
|
+
documentObject.removeEventListener("mousedown", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1051
|
+
documentObject.removeEventListener("mousemove", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1052
|
+
documentObject.removeEventListener("mouseup", $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
1053
|
+
}
|
|
1054
|
+
$e77252a287ef94ab$export$d90243b58daecda7.delete(windowObject);
|
|
1055
|
+
};
|
|
1056
|
+
function $e77252a287ef94ab$export$2f1888112f558a7d(element) {
|
|
1057
|
+
const documentObject = (0, $goTMa$reactariautils.getOwnerDocument)(element);
|
|
1058
|
+
let loadListener;
|
|
1059
|
+
if (documentObject.readyState !== "loading") $e77252a287ef94ab$var$setupGlobalFocusEvents(element);
|
|
1060
|
+
else {
|
|
1061
|
+
loadListener = ()=>{
|
|
1062
|
+
$e77252a287ef94ab$var$setupGlobalFocusEvents(element);
|
|
1063
|
+
};
|
|
1064
|
+
documentObject.addEventListener("DOMContentLoaded", loadListener);
|
|
1065
|
+
}
|
|
1066
|
+
return ()=>$e77252a287ef94ab$var$tearDownWindowFocusTracking(element, loadListener);
|
|
1025
1067
|
}
|
|
1068
|
+
// Server-side rendering does not have the document object defined
|
|
1069
|
+
// eslint-disable-next-line no-restricted-globals
|
|
1070
|
+
if (typeof document !== "undefined") $e77252a287ef94ab$export$2f1888112f558a7d();
|
|
1026
1071
|
function $e77252a287ef94ab$export$b9b3dfddab17db27() {
|
|
1027
1072
|
return $e77252a287ef94ab$var$currentModality !== "pointer";
|
|
1028
1073
|
}
|
|
@@ -1063,8 +1108,12 @@ const $e77252a287ef94ab$var$nonTextInputTypes = new Set([
|
|
|
1063
1108
|
* focus visible style can be properly set.
|
|
1064
1109
|
*/ function $e77252a287ef94ab$var$isKeyboardFocusEvent(isTextInput, modality, e) {
|
|
1065
1110
|
var _e_target;
|
|
1066
|
-
|
|
1067
|
-
|
|
1111
|
+
const IHTMLInputElement = typeof window !== "undefined" ? (0, $goTMa$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLInputElement : HTMLInputElement;
|
|
1112
|
+
const IHTMLTextAreaElement = typeof window !== "undefined" ? (0, $goTMa$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLTextAreaElement : HTMLTextAreaElement;
|
|
1113
|
+
const IHTMLElement = typeof window !== "undefined" ? (0, $goTMa$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLElement : HTMLElement;
|
|
1114
|
+
const IKeyboardEvent = typeof window !== "undefined" ? (0, $goTMa$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).KeyboardEvent : KeyboardEvent;
|
|
1115
|
+
isTextInput = isTextInput || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLInputElement && !$e77252a287ef94ab$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);
|
|
1116
|
+
return !(isTextInput && modality === "keyboard" && e instanceof IKeyboardEvent && !$e77252a287ef94ab$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]);
|
|
1068
1117
|
}
|
|
1069
1118
|
function $e77252a287ef94ab$export$ffd9e5021c1fb2d6(props = {}) {
|
|
1070
1119
|
let { isTextInput: isTextInput, autoFocus: autoFocus } = props;
|