@react-aria/interactions 3.21.1 → 3.21.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/PressResponder.main.js +62 -0
  2. package/dist/PressResponder.main.js.map +1 -0
  3. package/dist/PressResponder.mjs +52 -0
  4. package/dist/PressResponder.module.js +52 -0
  5. package/dist/PressResponder.module.js.map +1 -0
  6. package/dist/Pressable.main.js +43 -0
  7. package/dist/Pressable.main.js.map +1 -0
  8. package/dist/Pressable.mjs +34 -0
  9. package/dist/Pressable.module.js +34 -0
  10. package/dist/Pressable.module.js.map +1 -0
  11. package/dist/context.main.js +30 -0
  12. package/dist/context.main.js.map +1 -0
  13. package/dist/context.mjs +21 -0
  14. package/dist/context.module.js +21 -0
  15. package/dist/context.module.js.map +1 -0
  16. package/dist/createEventHandler.main.js +42 -0
  17. package/dist/createEventHandler.main.js.map +1 -0
  18. package/dist/createEventHandler.mjs +37 -0
  19. package/dist/createEventHandler.module.js +37 -0
  20. package/dist/createEventHandler.module.js.map +1 -0
  21. package/dist/import.mjs +12 -1771
  22. package/dist/main.js +31 -1794
  23. package/dist/main.js.map +1 -1
  24. package/dist/module.js +12 -1771
  25. package/dist/module.js.map +1 -1
  26. package/dist/textSelection.main.js +77 -0
  27. package/dist/textSelection.main.js.map +1 -0
  28. package/dist/textSelection.mjs +71 -0
  29. package/dist/textSelection.module.js +71 -0
  30. package/dist/textSelection.module.js.map +1 -0
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/useFocus.main.js +64 -0
  33. package/dist/useFocus.main.js.map +1 -0
  34. package/dist/useFocus.mjs +59 -0
  35. package/dist/useFocus.module.js +59 -0
  36. package/dist/useFocus.module.js.map +1 -0
  37. package/dist/useFocusVisible.main.js +248 -0
  38. package/dist/useFocusVisible.main.js.map +1 -0
  39. package/dist/useFocusVisible.mjs +237 -0
  40. package/dist/useFocusVisible.module.js +237 -0
  41. package/dist/useFocusVisible.module.js.map +1 -0
  42. package/dist/useFocusWithin.main.js +76 -0
  43. package/dist/useFocusWithin.main.js.map +1 -0
  44. package/dist/useFocusWithin.mjs +71 -0
  45. package/dist/useFocusWithin.module.js +71 -0
  46. package/dist/useFocusWithin.module.js.map +1 -0
  47. package/dist/useHover.main.js +142 -0
  48. package/dist/useHover.main.js.map +1 -0
  49. package/dist/useHover.mjs +137 -0
  50. package/dist/useHover.module.js +137 -0
  51. package/dist/useHover.module.js.map +1 -0
  52. package/dist/useInteractOutside.main.js +101 -0
  53. package/dist/useInteractOutside.main.js.map +1 -0
  54. package/dist/useInteractOutside.mjs +96 -0
  55. package/dist/useInteractOutside.module.js +96 -0
  56. package/dist/useInteractOutside.module.js.map +1 -0
  57. package/dist/useKeyboard.main.js +30 -0
  58. package/dist/useKeyboard.main.js.map +1 -0
  59. package/dist/useKeyboard.mjs +25 -0
  60. package/dist/useKeyboard.module.js +25 -0
  61. package/dist/useKeyboard.module.js.map +1 -0
  62. package/dist/useLongPress.main.js +84 -0
  63. package/dist/useLongPress.main.js.map +1 -0
  64. package/dist/useLongPress.mjs +79 -0
  65. package/dist/useLongPress.module.js +79 -0
  66. package/dist/useLongPress.module.js.map +1 -0
  67. package/dist/useMove.main.js +236 -0
  68. package/dist/useMove.main.js.map +1 -0
  69. package/dist/useMove.mjs +231 -0
  70. package/dist/useMove.module.js +231 -0
  71. package/dist/useMove.module.js.map +1 -0
  72. package/dist/usePress.main.js +571 -0
  73. package/dist/usePress.main.js.map +1 -0
  74. package/dist/usePress.mjs +566 -0
  75. package/dist/usePress.module.js +566 -0
  76. package/dist/usePress.module.js.map +1 -0
  77. package/dist/useScrollWheel.main.js +41 -0
  78. package/dist/useScrollWheel.main.js.map +1 -0
  79. package/dist/useScrollWheel.mjs +36 -0
  80. package/dist/useScrollWheel.module.js +36 -0
  81. package/dist/useScrollWheel.module.js.map +1 -0
  82. package/dist/utils.main.js +120 -0
  83. package/dist/utils.main.js.map +1 -0
  84. package/dist/utils.mjs +115 -0
  85. package/dist/utils.module.js +115 -0
  86. package/dist/utils.module.js.map +1 -0
  87. package/package.json +5 -5
  88. package/src/useFocus.ts +5 -1
@@ -0,0 +1,71 @@
1
+ import {useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.mjs";
2
+ import {useRef as $3b9Q0$useRef, useCallback as $3b9Q0$useCallback} from "react";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */ // Portions of the code in this file are based on code from react.
15
+ // Original licensing for the following can be found in the
16
+ // NOTICE file in the root directory of this source tree.
17
+ // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
18
+
19
+
20
+ function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
21
+ let { isDisabled: isDisabled, onBlurWithin: onBlurWithin, onFocusWithin: onFocusWithin, onFocusWithinChange: onFocusWithinChange } = props;
22
+ let state = (0, $3b9Q0$useRef)({
23
+ isFocusWithin: false
24
+ });
25
+ let onBlur = (0, $3b9Q0$useCallback)((e)=>{
26
+ // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
27
+ // when moving focus inside the element. Only trigger if the currentTarget doesn't
28
+ // include the relatedTarget (where focus is moving).
29
+ if (state.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
30
+ state.current.isFocusWithin = false;
31
+ if (onBlurWithin) onBlurWithin(e);
32
+ if (onFocusWithinChange) onFocusWithinChange(false);
33
+ }
34
+ }, [
35
+ onBlurWithin,
36
+ onFocusWithinChange,
37
+ state
38
+ ]);
39
+ let onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
40
+ let onFocus = (0, $3b9Q0$useCallback)((e)=>{
41
+ // Double check that document.activeElement actually matches e.target in case a previously chained
42
+ // focus handler already moved focus somewhere else.
43
+ if (!state.current.isFocusWithin && document.activeElement === e.target) {
44
+ if (onFocusWithin) onFocusWithin(e);
45
+ if (onFocusWithinChange) onFocusWithinChange(true);
46
+ state.current.isFocusWithin = true;
47
+ onSyntheticFocus(e);
48
+ }
49
+ }, [
50
+ onFocusWithin,
51
+ onFocusWithinChange,
52
+ onSyntheticFocus
53
+ ]);
54
+ if (isDisabled) return {
55
+ focusWithinProps: {
56
+ // These should not have been null, that would conflict in mergeProps
57
+ onFocus: undefined,
58
+ onBlur: undefined
59
+ }
60
+ };
61
+ return {
62
+ focusWithinProps: {
63
+ onFocus: onFocus,
64
+ onBlur: onBlur
65
+ }
66
+ };
67
+ }
68
+
69
+
70
+ export {$9ab94262bd0047c7$export$420e68273165f4ec as useFocusWithin};
71
+ //# sourceMappingURL=useFocusWithin.mjs.map
@@ -0,0 +1,71 @@
1
+ import {useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.module.js";
2
+ import {useRef as $3b9Q0$useRef, useCallback as $3b9Q0$useCallback} from "react";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */ // Portions of the code in this file are based on code from react.
15
+ // Original licensing for the following can be found in the
16
+ // NOTICE file in the root directory of this source tree.
17
+ // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
18
+
19
+
20
+ function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
21
+ let { isDisabled: isDisabled, onBlurWithin: onBlurWithin, onFocusWithin: onFocusWithin, onFocusWithinChange: onFocusWithinChange } = props;
22
+ let state = (0, $3b9Q0$useRef)({
23
+ isFocusWithin: false
24
+ });
25
+ let onBlur = (0, $3b9Q0$useCallback)((e)=>{
26
+ // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
27
+ // when moving focus inside the element. Only trigger if the currentTarget doesn't
28
+ // include the relatedTarget (where focus is moving).
29
+ if (state.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
30
+ state.current.isFocusWithin = false;
31
+ if (onBlurWithin) onBlurWithin(e);
32
+ if (onFocusWithinChange) onFocusWithinChange(false);
33
+ }
34
+ }, [
35
+ onBlurWithin,
36
+ onFocusWithinChange,
37
+ state
38
+ ]);
39
+ let onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
40
+ let onFocus = (0, $3b9Q0$useCallback)((e)=>{
41
+ // Double check that document.activeElement actually matches e.target in case a previously chained
42
+ // focus handler already moved focus somewhere else.
43
+ if (!state.current.isFocusWithin && document.activeElement === e.target) {
44
+ if (onFocusWithin) onFocusWithin(e);
45
+ if (onFocusWithinChange) onFocusWithinChange(true);
46
+ state.current.isFocusWithin = true;
47
+ onSyntheticFocus(e);
48
+ }
49
+ }, [
50
+ onFocusWithin,
51
+ onFocusWithinChange,
52
+ onSyntheticFocus
53
+ ]);
54
+ if (isDisabled) return {
55
+ focusWithinProps: {
56
+ // These should not have been null, that would conflict in mergeProps
57
+ onFocus: undefined,
58
+ onBlur: undefined
59
+ }
60
+ };
61
+ return {
62
+ focusWithinProps: {
63
+ onFocus: onFocus,
64
+ onBlur: onBlur
65
+ }
66
+ };
67
+ }
68
+
69
+
70
+ export {$9ab94262bd0047c7$export$420e68273165f4ec as useFocusWithin};
71
+ //# sourceMappingURL=useFocusWithin.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;AAyB3G,SAAS,0CAAe,KAAuB;IACpD,IAAI,cACF,UAAU,gBACV,YAAY,iBACZ,aAAa,uBACb,mBAAmB,EACpB,GAAG;IACJ,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE;QACjB,eAAe;IACjB;IAEA,IAAI,SAAS,CAAA,GAAA,kBAAU,EAAE,CAAC;QACxB,iFAAiF;QACjF,kFAAkF;QAClF,qDAAqD;QACrD,IAAI,MAAM,OAAO,CAAC,aAAa,IAAI,CAAC,AAAC,EAAE,aAAa,CAAa,QAAQ,CAAC,EAAE,aAAa,GAAc;YACrG,MAAM,OAAO,CAAC,aAAa,GAAG;YAE9B,IAAI,cACF,aAAa;YAGf,IAAI,qBACF,oBAAoB;QAExB;IACF,GAAG;QAAC;QAAc;QAAqB;KAAM;IAE7C,IAAI,mBAAmB,CAAA,GAAA,yCAAoB,EAAE;IAC7C,IAAI,UAAU,CAAA,GAAA,kBAAU,EAAE,CAAC;QACzB,kGAAkG;QAClG,oDAAoD;QACpD,IAAI,CAAC,MAAM,OAAO,CAAC,aAAa,IAAI,SAAS,aAAa,KAAK,EAAE,MAAM,EAAE;YACvE,IAAI,eACF,cAAc;YAGhB,IAAI,qBACF,oBAAoB;YAGtB,MAAM,OAAO,CAAC,aAAa,GAAG;YAC9B,iBAAiB;QACnB;IACF,GAAG;QAAC;QAAe;QAAqB;KAAiB;IAEzD,IAAI,YACF,OAAO;QACL,kBAAkB;YAChB,qEAAqE;YACrE,SAAS;YACT,QAAQ;QACV;IACF;IAGF,OAAO;QACL,kBAAkB;qBAChB;oBACA;QACF;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocusWithin.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\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {DOMAttributes} from '@react-types/shared';\nimport {FocusEvent, useCallback, useRef} from 'react';\nimport {useSyntheticBlurEvent} from './utils';\n\nexport interface FocusWithinProps {\n /** Whether the focus within events should be disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the target element or a descendant receives focus. */\n onFocusWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the target element and all descendants lose focus. */\n onBlurWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the the focus within state changes. */\n onFocusWithinChange?: (isFocusWithin: boolean) => void\n}\n\nexport interface FocusWithinResult {\n /** Props to spread onto the target element. */\n focusWithinProps: DOMAttributes\n}\n\n/**\n * Handles focus events for the target and its descendants.\n */\nexport function useFocusWithin(props: FocusWithinProps): FocusWithinResult {\n let {\n isDisabled,\n onBlurWithin,\n onFocusWithin,\n onFocusWithinChange\n } = props;\n let state = useRef({\n isFocusWithin: false\n });\n\n let onBlur = useCallback((e: FocusEvent) => {\n // We don't want to trigger onBlurWithin and then immediately onFocusWithin again\n // when moving focus inside the element. Only trigger if the currentTarget doesn't\n // include the relatedTarget (where focus is moving).\n if (state.current.isFocusWithin && !(e.currentTarget as Element).contains(e.relatedTarget as Element)) {\n state.current.isFocusWithin = false;\n\n if (onBlurWithin) {\n onBlurWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(false);\n }\n }\n }, [onBlurWithin, onFocusWithinChange, state]);\n\n let onSyntheticFocus = useSyntheticBlurEvent(onBlur);\n let onFocus = useCallback((e: FocusEvent) => {\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n if (!state.current.isFocusWithin && document.activeElement === e.target) {\n if (onFocusWithin) {\n onFocusWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(true);\n }\n\n state.current.isFocusWithin = true;\n onSyntheticFocus(e);\n }\n }, [onFocusWithin, onFocusWithinChange, onSyntheticFocus]);\n\n if (isDisabled) {\n return {\n focusWithinProps: {\n // These should not have been null, that would conflict in mergeProps\n onFocus: undefined,\n onBlur: undefined\n }\n };\n }\n\n return {\n focusWithinProps: {\n onFocus,\n onBlur\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocusWithin.module.js.map"}
@@ -0,0 +1,142 @@
1
+ var $82z6W$react = require("react");
2
+
3
+
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ $parcel$export(module.exports, "useHover", () => $ffbc150311c75f01$export$ae780daf29e6d456);
9
+ /*
10
+ * Copyright 2020 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */ // Portions of the code in this file are based on code from react.
20
+ // Original licensing for the following can be found in the
21
+ // NOTICE file in the root directory of this source tree.
22
+ // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
23
+
24
+ // iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
25
+ // We want to ignore these emulated events so they do not trigger hover behavior.
26
+ // See https://bugs.webkit.org/show_bug.cgi?id=214609.
27
+ let $ffbc150311c75f01$var$globalIgnoreEmulatedMouseEvents = false;
28
+ let $ffbc150311c75f01$var$hoverCount = 0;
29
+ function $ffbc150311c75f01$var$setGlobalIgnoreEmulatedMouseEvents() {
30
+ $ffbc150311c75f01$var$globalIgnoreEmulatedMouseEvents = true;
31
+ // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter
32
+ // with pointerType="mouse" immediately after onPointerUp and before onFocus. On other
33
+ // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in
34
+ // the distant future because a user previously touched the element.
35
+ setTimeout(()=>{
36
+ $ffbc150311c75f01$var$globalIgnoreEmulatedMouseEvents = false;
37
+ }, 50);
38
+ }
39
+ function $ffbc150311c75f01$var$handleGlobalPointerEvent(e) {
40
+ if (e.pointerType === "touch") $ffbc150311c75f01$var$setGlobalIgnoreEmulatedMouseEvents();
41
+ }
42
+ function $ffbc150311c75f01$var$setupGlobalTouchEvents() {
43
+ if (typeof document === "undefined") return;
44
+ if (typeof PointerEvent !== "undefined") document.addEventListener("pointerup", $ffbc150311c75f01$var$handleGlobalPointerEvent);
45
+ else document.addEventListener("touchend", $ffbc150311c75f01$var$setGlobalIgnoreEmulatedMouseEvents);
46
+ $ffbc150311c75f01$var$hoverCount++;
47
+ return ()=>{
48
+ $ffbc150311c75f01$var$hoverCount--;
49
+ if ($ffbc150311c75f01$var$hoverCount > 0) return;
50
+ if (typeof PointerEvent !== "undefined") document.removeEventListener("pointerup", $ffbc150311c75f01$var$handleGlobalPointerEvent);
51
+ else document.removeEventListener("touchend", $ffbc150311c75f01$var$setGlobalIgnoreEmulatedMouseEvents);
52
+ };
53
+ }
54
+ function $ffbc150311c75f01$export$ae780daf29e6d456(props) {
55
+ let { onHoverStart: onHoverStart, onHoverChange: onHoverChange, onHoverEnd: onHoverEnd, isDisabled: isDisabled } = props;
56
+ let [isHovered, setHovered] = (0, $82z6W$react.useState)(false);
57
+ let state = (0, $82z6W$react.useRef)({
58
+ isHovered: false,
59
+ ignoreEmulatedMouseEvents: false,
60
+ pointerType: "",
61
+ target: null
62
+ }).current;
63
+ (0, $82z6W$react.useEffect)($ffbc150311c75f01$var$setupGlobalTouchEvents, []);
64
+ let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $82z6W$react.useMemo)(()=>{
65
+ let triggerHoverStart = (event, pointerType)=>{
66
+ state.pointerType = pointerType;
67
+ if (isDisabled || pointerType === "touch" || state.isHovered || !event.currentTarget.contains(event.target)) return;
68
+ state.isHovered = true;
69
+ let target = event.currentTarget;
70
+ state.target = target;
71
+ if (onHoverStart) onHoverStart({
72
+ type: "hoverstart",
73
+ target: target,
74
+ pointerType: pointerType
75
+ });
76
+ if (onHoverChange) onHoverChange(true);
77
+ setHovered(true);
78
+ };
79
+ let triggerHoverEnd = (event, pointerType)=>{
80
+ state.pointerType = "";
81
+ state.target = null;
82
+ if (pointerType === "touch" || !state.isHovered) return;
83
+ state.isHovered = false;
84
+ let target = event.currentTarget;
85
+ if (onHoverEnd) onHoverEnd({
86
+ type: "hoverend",
87
+ target: target,
88
+ pointerType: pointerType
89
+ });
90
+ if (onHoverChange) onHoverChange(false);
91
+ setHovered(false);
92
+ };
93
+ let hoverProps = {};
94
+ if (typeof PointerEvent !== "undefined") {
95
+ hoverProps.onPointerEnter = (e)=>{
96
+ if ($ffbc150311c75f01$var$globalIgnoreEmulatedMouseEvents && e.pointerType === "mouse") return;
97
+ triggerHoverStart(e, e.pointerType);
98
+ };
99
+ hoverProps.onPointerLeave = (e)=>{
100
+ if (!isDisabled && e.currentTarget.contains(e.target)) triggerHoverEnd(e, e.pointerType);
101
+ };
102
+ } else {
103
+ hoverProps.onTouchStart = ()=>{
104
+ state.ignoreEmulatedMouseEvents = true;
105
+ };
106
+ hoverProps.onMouseEnter = (e)=>{
107
+ if (!state.ignoreEmulatedMouseEvents && !$ffbc150311c75f01$var$globalIgnoreEmulatedMouseEvents) triggerHoverStart(e, "mouse");
108
+ state.ignoreEmulatedMouseEvents = false;
109
+ };
110
+ hoverProps.onMouseLeave = (e)=>{
111
+ if (!isDisabled && e.currentTarget.contains(e.target)) triggerHoverEnd(e, "mouse");
112
+ };
113
+ }
114
+ return {
115
+ hoverProps: hoverProps,
116
+ triggerHoverEnd: triggerHoverEnd
117
+ };
118
+ }, [
119
+ onHoverStart,
120
+ onHoverChange,
121
+ onHoverEnd,
122
+ isDisabled,
123
+ state
124
+ ]);
125
+ (0, $82z6W$react.useEffect)(()=>{
126
+ // Call the triggerHoverEnd as soon as isDisabled changes to true
127
+ // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering
128
+ if (isDisabled) triggerHoverEnd({
129
+ currentTarget: state.target
130
+ }, state.pointerType);
131
+ // eslint-disable-next-line react-hooks/exhaustive-deps
132
+ }, [
133
+ isDisabled
134
+ ]);
135
+ return {
136
+ hoverProps: hoverProps,
137
+ isHovered: isHovered
138
+ };
139
+ }
140
+
141
+
142
+ //# sourceMappingURL=useHover.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"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","sources":["packages/@react-aria/interactions/src/useHover.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\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {DOMAttributes, HoverEvents} from '@react-types/shared';\nimport {useEffect, useMemo, useRef, useState} from 'react';\n\nexport interface HoverProps extends HoverEvents {\n /** Whether the hover events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface HoverResult {\n /** Props to spread on the target element. */\n hoverProps: DOMAttributes,\n isHovered: boolean\n}\n\n// iOS fires onPointerEnter twice: once with pointerType=\"touch\" and again with pointerType=\"mouse\".\n// We want to ignore these emulated events so they do not trigger hover behavior.\n// See https://bugs.webkit.org/show_bug.cgi?id=214609.\nlet globalIgnoreEmulatedMouseEvents = false;\nlet hoverCount = 0;\n\nfunction setGlobalIgnoreEmulatedMouseEvents() {\n globalIgnoreEmulatedMouseEvents = true;\n\n // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter\n // with pointerType=\"mouse\" immediately after onPointerUp and before onFocus. On other\n // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in\n // the distant future because a user previously touched the element.\n setTimeout(() => {\n globalIgnoreEmulatedMouseEvents = false;\n }, 50);\n}\n\nfunction handleGlobalPointerEvent(e) {\n if (e.pointerType === 'touch') {\n setGlobalIgnoreEmulatedMouseEvents();\n }\n}\n\nfunction setupGlobalTouchEvents() {\n if (typeof document === 'undefined') {\n return;\n }\n\n if (typeof PointerEvent !== 'undefined') {\n document.addEventListener('pointerup', handleGlobalPointerEvent);\n } else {\n document.addEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\n\n hoverCount++;\n return () => {\n hoverCount--;\n if (hoverCount > 0) {\n return;\n }\n\n if (typeof PointerEvent !== 'undefined') {\n document.removeEventListener('pointerup', handleGlobalPointerEvent);\n } else {\n document.removeEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\n };\n}\n\n/**\n * Handles pointer hover interactions for an element. Normalizes behavior\n * across browsers and platforms, and ignores emulated mouse events on touch devices.\n */\nexport function useHover(props: HoverProps): HoverResult {\n let {\n onHoverStart,\n onHoverChange,\n onHoverEnd,\n isDisabled\n } = props;\n\n let [isHovered, setHovered] = useState(false);\n let state = useRef({\n isHovered: false,\n ignoreEmulatedMouseEvents: false,\n pointerType: '',\n target: null\n }).current;\n\n useEffect(setupGlobalTouchEvents, []);\n\n let {hoverProps, triggerHoverEnd} = useMemo(() => {\n let triggerHoverStart = (event, pointerType) => {\n state.pointerType = pointerType;\n if (isDisabled || pointerType === 'touch' || state.isHovered || !event.currentTarget.contains(event.target)) {\n return;\n }\n\n state.isHovered = true;\n let target = event.currentTarget;\n state.target = target;\n\n if (onHoverStart) {\n onHoverStart({\n type: 'hoverstart',\n target,\n pointerType\n });\n }\n\n if (onHoverChange) {\n onHoverChange(true);\n }\n\n setHovered(true);\n };\n\n let triggerHoverEnd = (event, pointerType) => {\n state.pointerType = '';\n state.target = null;\n\n if (pointerType === 'touch' || !state.isHovered) {\n return;\n }\n\n state.isHovered = false;\n let target = event.currentTarget;\n if (onHoverEnd) {\n onHoverEnd({\n type: 'hoverend',\n target,\n pointerType\n });\n }\n\n if (onHoverChange) {\n onHoverChange(false);\n }\n\n setHovered(false);\n };\n\n let hoverProps: DOMAttributes = {};\n\n if (typeof PointerEvent !== 'undefined') {\n hoverProps.onPointerEnter = (e) => {\n if (globalIgnoreEmulatedMouseEvents && e.pointerType === 'mouse') {\n return;\n }\n\n triggerHoverStart(e, e.pointerType);\n };\n\n hoverProps.onPointerLeave = (e) => {\n if (!isDisabled && e.currentTarget.contains(e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n };\n } else {\n hoverProps.onTouchStart = () => {\n state.ignoreEmulatedMouseEvents = true;\n };\n\n hoverProps.onMouseEnter = (e) => {\n if (!state.ignoreEmulatedMouseEvents && !globalIgnoreEmulatedMouseEvents) {\n triggerHoverStart(e, 'mouse');\n }\n\n state.ignoreEmulatedMouseEvents = false;\n };\n\n hoverProps.onMouseLeave = (e) => {\n if (!isDisabled && e.currentTarget.contains(e.target as Element)) {\n triggerHoverEnd(e, 'mouse');\n }\n };\n }\n return {hoverProps, triggerHoverEnd};\n }, [onHoverStart, onHoverChange, onHoverEnd, isDisabled, state]);\n\n useEffect(() => {\n // Call the triggerHoverEnd as soon as isDisabled changes to true\n // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering\n if (isDisabled) {\n triggerHoverEnd({currentTarget: state.target}, state.pointerType);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isDisabled]);\n\n return {\n hoverProps,\n isHovered\n };\n}\n\n"],"names":[],"version":3,"file":"useHover.main.js.map"}
@@ -0,0 +1,137 @@
1
+ import {useState as $AWxnT$useState, useRef as $AWxnT$useRef, useEffect as $AWxnT$useEffect, useMemo as $AWxnT$useMemo} from "react";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */ // Portions of the code in this file are based on code from react.
14
+ // Original licensing for the following can be found in the
15
+ // NOTICE file in the root directory of this source tree.
16
+ // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
17
+
18
+ // iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
19
+ // We want to ignore these emulated events so they do not trigger hover behavior.
20
+ // See https://bugs.webkit.org/show_bug.cgi?id=214609.
21
+ let $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
22
+ let $6179b936705e76d3$var$hoverCount = 0;
23
+ function $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents() {
24
+ $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = true;
25
+ // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter
26
+ // with pointerType="mouse" immediately after onPointerUp and before onFocus. On other
27
+ // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in
28
+ // the distant future because a user previously touched the element.
29
+ setTimeout(()=>{
30
+ $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
31
+ }, 50);
32
+ }
33
+ function $6179b936705e76d3$var$handleGlobalPointerEvent(e) {
34
+ if (e.pointerType === "touch") $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents();
35
+ }
36
+ function $6179b936705e76d3$var$setupGlobalTouchEvents() {
37
+ if (typeof document === "undefined") return;
38
+ if (typeof PointerEvent !== "undefined") document.addEventListener("pointerup", $6179b936705e76d3$var$handleGlobalPointerEvent);
39
+ else document.addEventListener("touchend", $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
40
+ $6179b936705e76d3$var$hoverCount++;
41
+ return ()=>{
42
+ $6179b936705e76d3$var$hoverCount--;
43
+ if ($6179b936705e76d3$var$hoverCount > 0) return;
44
+ if (typeof PointerEvent !== "undefined") document.removeEventListener("pointerup", $6179b936705e76d3$var$handleGlobalPointerEvent);
45
+ else document.removeEventListener("touchend", $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
46
+ };
47
+ }
48
+ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
49
+ let { onHoverStart: onHoverStart, onHoverChange: onHoverChange, onHoverEnd: onHoverEnd, isDisabled: isDisabled } = props;
50
+ let [isHovered, setHovered] = (0, $AWxnT$useState)(false);
51
+ let state = (0, $AWxnT$useRef)({
52
+ isHovered: false,
53
+ ignoreEmulatedMouseEvents: false,
54
+ pointerType: "",
55
+ target: null
56
+ }).current;
57
+ (0, $AWxnT$useEffect)($6179b936705e76d3$var$setupGlobalTouchEvents, []);
58
+ let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $AWxnT$useMemo)(()=>{
59
+ let triggerHoverStart = (event, pointerType)=>{
60
+ state.pointerType = pointerType;
61
+ if (isDisabled || pointerType === "touch" || state.isHovered || !event.currentTarget.contains(event.target)) return;
62
+ state.isHovered = true;
63
+ let target = event.currentTarget;
64
+ state.target = target;
65
+ if (onHoverStart) onHoverStart({
66
+ type: "hoverstart",
67
+ target: target,
68
+ pointerType: pointerType
69
+ });
70
+ if (onHoverChange) onHoverChange(true);
71
+ setHovered(true);
72
+ };
73
+ let triggerHoverEnd = (event, pointerType)=>{
74
+ state.pointerType = "";
75
+ state.target = null;
76
+ if (pointerType === "touch" || !state.isHovered) return;
77
+ state.isHovered = false;
78
+ let target = event.currentTarget;
79
+ if (onHoverEnd) onHoverEnd({
80
+ type: "hoverend",
81
+ target: target,
82
+ pointerType: pointerType
83
+ });
84
+ if (onHoverChange) onHoverChange(false);
85
+ setHovered(false);
86
+ };
87
+ let hoverProps = {};
88
+ if (typeof PointerEvent !== "undefined") {
89
+ hoverProps.onPointerEnter = (e)=>{
90
+ if ($6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents && e.pointerType === "mouse") return;
91
+ triggerHoverStart(e, e.pointerType);
92
+ };
93
+ hoverProps.onPointerLeave = (e)=>{
94
+ if (!isDisabled && e.currentTarget.contains(e.target)) triggerHoverEnd(e, e.pointerType);
95
+ };
96
+ } else {
97
+ hoverProps.onTouchStart = ()=>{
98
+ state.ignoreEmulatedMouseEvents = true;
99
+ };
100
+ hoverProps.onMouseEnter = (e)=>{
101
+ if (!state.ignoreEmulatedMouseEvents && !$6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents) triggerHoverStart(e, "mouse");
102
+ state.ignoreEmulatedMouseEvents = false;
103
+ };
104
+ hoverProps.onMouseLeave = (e)=>{
105
+ if (!isDisabled && e.currentTarget.contains(e.target)) triggerHoverEnd(e, "mouse");
106
+ };
107
+ }
108
+ return {
109
+ hoverProps: hoverProps,
110
+ triggerHoverEnd: triggerHoverEnd
111
+ };
112
+ }, [
113
+ onHoverStart,
114
+ onHoverChange,
115
+ onHoverEnd,
116
+ isDisabled,
117
+ state
118
+ ]);
119
+ (0, $AWxnT$useEffect)(()=>{
120
+ // Call the triggerHoverEnd as soon as isDisabled changes to true
121
+ // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering
122
+ if (isDisabled) triggerHoverEnd({
123
+ currentTarget: state.target
124
+ }, state.pointerType);
125
+ // eslint-disable-next-line react-hooks/exhaustive-deps
126
+ }, [
127
+ isDisabled
128
+ ]);
129
+ return {
130
+ hoverProps: hoverProps,
131
+ isHovered: isHovered
132
+ };
133
+ }
134
+
135
+
136
+ export {$6179b936705e76d3$export$ae780daf29e6d456 as useHover};
137
+ //# sourceMappingURL=useHover.mjs.map
@@ -0,0 +1,137 @@
1
+ import {useState as $AWxnT$useState, useRef as $AWxnT$useRef, useEffect as $AWxnT$useEffect, useMemo as $AWxnT$useMemo} from "react";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */ // Portions of the code in this file are based on code from react.
14
+ // Original licensing for the following can be found in the
15
+ // NOTICE file in the root directory of this source tree.
16
+ // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
17
+
18
+ // iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
19
+ // We want to ignore these emulated events so they do not trigger hover behavior.
20
+ // See https://bugs.webkit.org/show_bug.cgi?id=214609.
21
+ let $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
22
+ let $6179b936705e76d3$var$hoverCount = 0;
23
+ function $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents() {
24
+ $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = true;
25
+ // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter
26
+ // with pointerType="mouse" immediately after onPointerUp and before onFocus. On other
27
+ // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in
28
+ // the distant future because a user previously touched the element.
29
+ setTimeout(()=>{
30
+ $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
31
+ }, 50);
32
+ }
33
+ function $6179b936705e76d3$var$handleGlobalPointerEvent(e) {
34
+ if (e.pointerType === "touch") $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents();
35
+ }
36
+ function $6179b936705e76d3$var$setupGlobalTouchEvents() {
37
+ if (typeof document === "undefined") return;
38
+ if (typeof PointerEvent !== "undefined") document.addEventListener("pointerup", $6179b936705e76d3$var$handleGlobalPointerEvent);
39
+ else document.addEventListener("touchend", $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
40
+ $6179b936705e76d3$var$hoverCount++;
41
+ return ()=>{
42
+ $6179b936705e76d3$var$hoverCount--;
43
+ if ($6179b936705e76d3$var$hoverCount > 0) return;
44
+ if (typeof PointerEvent !== "undefined") document.removeEventListener("pointerup", $6179b936705e76d3$var$handleGlobalPointerEvent);
45
+ else document.removeEventListener("touchend", $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
46
+ };
47
+ }
48
+ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
49
+ let { onHoverStart: onHoverStart, onHoverChange: onHoverChange, onHoverEnd: onHoverEnd, isDisabled: isDisabled } = props;
50
+ let [isHovered, setHovered] = (0, $AWxnT$useState)(false);
51
+ let state = (0, $AWxnT$useRef)({
52
+ isHovered: false,
53
+ ignoreEmulatedMouseEvents: false,
54
+ pointerType: "",
55
+ target: null
56
+ }).current;
57
+ (0, $AWxnT$useEffect)($6179b936705e76d3$var$setupGlobalTouchEvents, []);
58
+ let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $AWxnT$useMemo)(()=>{
59
+ let triggerHoverStart = (event, pointerType)=>{
60
+ state.pointerType = pointerType;
61
+ if (isDisabled || pointerType === "touch" || state.isHovered || !event.currentTarget.contains(event.target)) return;
62
+ state.isHovered = true;
63
+ let target = event.currentTarget;
64
+ state.target = target;
65
+ if (onHoverStart) onHoverStart({
66
+ type: "hoverstart",
67
+ target: target,
68
+ pointerType: pointerType
69
+ });
70
+ if (onHoverChange) onHoverChange(true);
71
+ setHovered(true);
72
+ };
73
+ let triggerHoverEnd = (event, pointerType)=>{
74
+ state.pointerType = "";
75
+ state.target = null;
76
+ if (pointerType === "touch" || !state.isHovered) return;
77
+ state.isHovered = false;
78
+ let target = event.currentTarget;
79
+ if (onHoverEnd) onHoverEnd({
80
+ type: "hoverend",
81
+ target: target,
82
+ pointerType: pointerType
83
+ });
84
+ if (onHoverChange) onHoverChange(false);
85
+ setHovered(false);
86
+ };
87
+ let hoverProps = {};
88
+ if (typeof PointerEvent !== "undefined") {
89
+ hoverProps.onPointerEnter = (e)=>{
90
+ if ($6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents && e.pointerType === "mouse") return;
91
+ triggerHoverStart(e, e.pointerType);
92
+ };
93
+ hoverProps.onPointerLeave = (e)=>{
94
+ if (!isDisabled && e.currentTarget.contains(e.target)) triggerHoverEnd(e, e.pointerType);
95
+ };
96
+ } else {
97
+ hoverProps.onTouchStart = ()=>{
98
+ state.ignoreEmulatedMouseEvents = true;
99
+ };
100
+ hoverProps.onMouseEnter = (e)=>{
101
+ if (!state.ignoreEmulatedMouseEvents && !$6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents) triggerHoverStart(e, "mouse");
102
+ state.ignoreEmulatedMouseEvents = false;
103
+ };
104
+ hoverProps.onMouseLeave = (e)=>{
105
+ if (!isDisabled && e.currentTarget.contains(e.target)) triggerHoverEnd(e, "mouse");
106
+ };
107
+ }
108
+ return {
109
+ hoverProps: hoverProps,
110
+ triggerHoverEnd: triggerHoverEnd
111
+ };
112
+ }, [
113
+ onHoverStart,
114
+ onHoverChange,
115
+ onHoverEnd,
116
+ isDisabled,
117
+ state
118
+ ]);
119
+ (0, $AWxnT$useEffect)(()=>{
120
+ // Call the triggerHoverEnd as soon as isDisabled changes to true
121
+ // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering
122
+ if (isDisabled) triggerHoverEnd({
123
+ currentTarget: state.target
124
+ }, state.pointerType);
125
+ // eslint-disable-next-line react-hooks/exhaustive-deps
126
+ }, [
127
+ isDisabled
128
+ ]);
129
+ return {
130
+ hoverProps: hoverProps,
131
+ isHovered: isHovered
132
+ };
133
+ }
134
+
135
+
136
+ export {$6179b936705e76d3$export$ae780daf29e6d456 as useHover};
137
+ //# sourceMappingURL=useHover.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"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","sources":["packages/@react-aria/interactions/src/useHover.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\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {DOMAttributes, HoverEvents} from '@react-types/shared';\nimport {useEffect, useMemo, useRef, useState} from 'react';\n\nexport interface HoverProps extends HoverEvents {\n /** Whether the hover events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface HoverResult {\n /** Props to spread on the target element. */\n hoverProps: DOMAttributes,\n isHovered: boolean\n}\n\n// iOS fires onPointerEnter twice: once with pointerType=\"touch\" and again with pointerType=\"mouse\".\n// We want to ignore these emulated events so they do not trigger hover behavior.\n// See https://bugs.webkit.org/show_bug.cgi?id=214609.\nlet globalIgnoreEmulatedMouseEvents = false;\nlet hoverCount = 0;\n\nfunction setGlobalIgnoreEmulatedMouseEvents() {\n globalIgnoreEmulatedMouseEvents = true;\n\n // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter\n // with pointerType=\"mouse\" immediately after onPointerUp and before onFocus. On other\n // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in\n // the distant future because a user previously touched the element.\n setTimeout(() => {\n globalIgnoreEmulatedMouseEvents = false;\n }, 50);\n}\n\nfunction handleGlobalPointerEvent(e) {\n if (e.pointerType === 'touch') {\n setGlobalIgnoreEmulatedMouseEvents();\n }\n}\n\nfunction setupGlobalTouchEvents() {\n if (typeof document === 'undefined') {\n return;\n }\n\n if (typeof PointerEvent !== 'undefined') {\n document.addEventListener('pointerup', handleGlobalPointerEvent);\n } else {\n document.addEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\n\n hoverCount++;\n return () => {\n hoverCount--;\n if (hoverCount > 0) {\n return;\n }\n\n if (typeof PointerEvent !== 'undefined') {\n document.removeEventListener('pointerup', handleGlobalPointerEvent);\n } else {\n document.removeEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\n };\n}\n\n/**\n * Handles pointer hover interactions for an element. Normalizes behavior\n * across browsers and platforms, and ignores emulated mouse events on touch devices.\n */\nexport function useHover(props: HoverProps): HoverResult {\n let {\n onHoverStart,\n onHoverChange,\n onHoverEnd,\n isDisabled\n } = props;\n\n let [isHovered, setHovered] = useState(false);\n let state = useRef({\n isHovered: false,\n ignoreEmulatedMouseEvents: false,\n pointerType: '',\n target: null\n }).current;\n\n useEffect(setupGlobalTouchEvents, []);\n\n let {hoverProps, triggerHoverEnd} = useMemo(() => {\n let triggerHoverStart = (event, pointerType) => {\n state.pointerType = pointerType;\n if (isDisabled || pointerType === 'touch' || state.isHovered || !event.currentTarget.contains(event.target)) {\n return;\n }\n\n state.isHovered = true;\n let target = event.currentTarget;\n state.target = target;\n\n if (onHoverStart) {\n onHoverStart({\n type: 'hoverstart',\n target,\n pointerType\n });\n }\n\n if (onHoverChange) {\n onHoverChange(true);\n }\n\n setHovered(true);\n };\n\n let triggerHoverEnd = (event, pointerType) => {\n state.pointerType = '';\n state.target = null;\n\n if (pointerType === 'touch' || !state.isHovered) {\n return;\n }\n\n state.isHovered = false;\n let target = event.currentTarget;\n if (onHoverEnd) {\n onHoverEnd({\n type: 'hoverend',\n target,\n pointerType\n });\n }\n\n if (onHoverChange) {\n onHoverChange(false);\n }\n\n setHovered(false);\n };\n\n let hoverProps: DOMAttributes = {};\n\n if (typeof PointerEvent !== 'undefined') {\n hoverProps.onPointerEnter = (e) => {\n if (globalIgnoreEmulatedMouseEvents && e.pointerType === 'mouse') {\n return;\n }\n\n triggerHoverStart(e, e.pointerType);\n };\n\n hoverProps.onPointerLeave = (e) => {\n if (!isDisabled && e.currentTarget.contains(e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n };\n } else {\n hoverProps.onTouchStart = () => {\n state.ignoreEmulatedMouseEvents = true;\n };\n\n hoverProps.onMouseEnter = (e) => {\n if (!state.ignoreEmulatedMouseEvents && !globalIgnoreEmulatedMouseEvents) {\n triggerHoverStart(e, 'mouse');\n }\n\n state.ignoreEmulatedMouseEvents = false;\n };\n\n hoverProps.onMouseLeave = (e) => {\n if (!isDisabled && e.currentTarget.contains(e.target as Element)) {\n triggerHoverEnd(e, 'mouse');\n }\n };\n }\n return {hoverProps, triggerHoverEnd};\n }, [onHoverStart, onHoverChange, onHoverEnd, isDisabled, state]);\n\n useEffect(() => {\n // Call the triggerHoverEnd as soon as isDisabled changes to true\n // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering\n if (isDisabled) {\n triggerHoverEnd({currentTarget: state.target}, state.pointerType);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isDisabled]);\n\n return {\n hoverProps,\n isHovered\n };\n}\n\n"],"names":[],"version":3,"file":"useHover.module.js.map"}