@react-aria/interactions 3.26.0 → 3.27.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/PressResponder.main.js +2 -3
- package/dist/PressResponder.main.js.map +1 -1
- package/dist/PressResponder.mjs +3 -4
- package/dist/PressResponder.module.js +3 -4
- package/dist/PressResponder.module.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useFocusVisible.main.js +7 -6
- package/dist/useFocusVisible.main.js.map +1 -1
- package/dist/useFocusVisible.mjs +8 -7
- package/dist/useFocusVisible.module.js +8 -7
- package/dist/useFocusVisible.module.js.map +1 -1
- package/dist/useFocusWithin.main.js +3 -3
- package/dist/useFocusWithin.main.js.map +1 -1
- package/dist/useFocusWithin.mjs +4 -4
- package/dist/useFocusWithin.module.js +4 -4
- package/dist/useFocusWithin.module.js.map +1 -1
- package/dist/useHover.main.js +3 -3
- package/dist/useHover.main.js.map +1 -1
- package/dist/useHover.mjs +4 -4
- package/dist/useHover.module.js +4 -4
- package/dist/useHover.module.js.map +1 -1
- package/dist/useInteractOutside.main.js +1 -1
- package/dist/useInteractOutside.main.js.map +1 -1
- package/dist/useInteractOutside.mjs +2 -2
- package/dist/useInteractOutside.module.js +2 -2
- package/dist/useInteractOutside.module.js.map +1 -1
- package/dist/usePress.main.js +12 -4
- package/dist/usePress.main.js.map +1 -1
- package/dist/usePress.mjs +12 -4
- package/dist/usePress.module.js +12 -4
- package/dist/usePress.module.js.map +1 -1
- package/package.json +4 -4
- package/src/PressResponder.tsx +3 -4
- package/src/useFocusVisible.ts +6 -2
- package/src/useFocusWithin.ts +3 -3
- package/src/useHover.ts +3 -3
- package/src/useInteractOutside.ts +2 -2
- package/src/usePress.ts +17 -5
package/dist/useFocusWithin.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {createSyntheticEvent as $8a9cb279dc87e130$export$525bc4921d56d4a, setEventTarget as $8a9cb279dc87e130$export$c2b7abe5d61ec696, useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.mjs";
|
|
2
2
|
import {useRef as $3b9Q0$useRef, useCallback as $3b9Q0$useCallback} from "react";
|
|
3
|
-
import {useGlobalListeners as $3b9Q0$useGlobalListeners,
|
|
3
|
+
import {useGlobalListeners as $3b9Q0$useGlobalListeners, nodeContains as $3b9Q0$nodeContains, getOwnerDocument as $3b9Q0$getOwnerDocument, getActiveElement as $3b9Q0$getActiveElement, getEventTarget as $3b9Q0$getEventTarget} from "@react-aria/utils";
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -27,11 +27,11 @@ function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
|
|
|
27
27
|
let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $3b9Q0$useGlobalListeners)();
|
|
28
28
|
let onBlur = (0, $3b9Q0$useCallback)((e)=>{
|
|
29
29
|
// Ignore events bubbling through portals.
|
|
30
|
-
if (!e.currentTarget
|
|
30
|
+
if (!(0, $3b9Q0$nodeContains)(e.currentTarget, e.target)) return;
|
|
31
31
|
// We don't want to trigger onBlurWithin and then immediately onFocusWithin again
|
|
32
32
|
// when moving focus inside the element. Only trigger if the currentTarget doesn't
|
|
33
33
|
// include the relatedTarget (where focus is moving).
|
|
34
|
-
if (state.current.isFocusWithin && !e.currentTarget
|
|
34
|
+
if (state.current.isFocusWithin && !(0, $3b9Q0$nodeContains)(e.currentTarget, e.relatedTarget)) {
|
|
35
35
|
state.current.isFocusWithin = false;
|
|
36
36
|
removeAllGlobalListeners();
|
|
37
37
|
if (onBlurWithin) onBlurWithin(e);
|
|
@@ -46,7 +46,7 @@ function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
|
|
|
46
46
|
let onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
|
|
47
47
|
let onFocus = (0, $3b9Q0$useCallback)((e)=>{
|
|
48
48
|
// Ignore events bubbling through portals.
|
|
49
|
-
if (!e.currentTarget
|
|
49
|
+
if (!(0, $3b9Q0$nodeContains)(e.currentTarget, e.target)) return;
|
|
50
50
|
// Double check that document.activeElement actually matches e.target in case a previously chained
|
|
51
51
|
// focus handler already moved focus somewhere else.
|
|
52
52
|
const ownerDocument = (0, $3b9Q0$getOwnerDocument)(e.target);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {createSyntheticEvent as $8a9cb279dc87e130$export$525bc4921d56d4a, setEventTarget as $8a9cb279dc87e130$export$c2b7abe5d61ec696, useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.module.js";
|
|
2
2
|
import {useRef as $3b9Q0$useRef, useCallback as $3b9Q0$useCallback} from "react";
|
|
3
|
-
import {useGlobalListeners as $3b9Q0$useGlobalListeners,
|
|
3
|
+
import {useGlobalListeners as $3b9Q0$useGlobalListeners, nodeContains as $3b9Q0$nodeContains, getOwnerDocument as $3b9Q0$getOwnerDocument, getActiveElement as $3b9Q0$getActiveElement, getEventTarget as $3b9Q0$getEventTarget} from "@react-aria/utils";
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -27,11 +27,11 @@ function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
|
|
|
27
27
|
let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $3b9Q0$useGlobalListeners)();
|
|
28
28
|
let onBlur = (0, $3b9Q0$useCallback)((e)=>{
|
|
29
29
|
// Ignore events bubbling through portals.
|
|
30
|
-
if (!e.currentTarget
|
|
30
|
+
if (!(0, $3b9Q0$nodeContains)(e.currentTarget, e.target)) return;
|
|
31
31
|
// We don't want to trigger onBlurWithin and then immediately onFocusWithin again
|
|
32
32
|
// when moving focus inside the element. Only trigger if the currentTarget doesn't
|
|
33
33
|
// include the relatedTarget (where focus is moving).
|
|
34
|
-
if (state.current.isFocusWithin && !e.currentTarget
|
|
34
|
+
if (state.current.isFocusWithin && !(0, $3b9Q0$nodeContains)(e.currentTarget, e.relatedTarget)) {
|
|
35
35
|
state.current.isFocusWithin = false;
|
|
36
36
|
removeAllGlobalListeners();
|
|
37
37
|
if (onBlurWithin) onBlurWithin(e);
|
|
@@ -46,7 +46,7 @@ function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
|
|
|
46
46
|
let onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
|
|
47
47
|
let onFocus = (0, $3b9Q0$useCallback)((e)=>{
|
|
48
48
|
// Ignore events bubbling through portals.
|
|
49
|
-
if (!e.currentTarget
|
|
49
|
+
if (!(0, $3b9Q0$nodeContains)(e.currentTarget, e.target)) return;
|
|
50
50
|
// Double check that document.activeElement actually matches e.target in case a previously chained
|
|
51
51
|
// focus handler already moved focus somewhere else.
|
|
52
52
|
const ownerDocument = (0, $3b9Q0$getOwnerDocument)(e.target);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AA0B3G,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,qBAAC,iBAAiB,4BAAE,wBAAwB,EAAC,GAAG,CAAA,GAAA,yBAAiB;IAErE,IAAI,SAAS,CAAA,GAAA,kBAAU,EAAE,CAAC;QACxB,0CAA0C;QAC1C,IAAI,CAAC,
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AA0B3G,SAAS,0CAAe,KAAuB;IACpD,IA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,gBAAgB,EAAE,aAAa;YACnC,kBAAkB,eAAe,SAAS,CAAA;gBACxC,IAAI,MAAM,OAAO,CAAC,aAAa,IAAI,CAAC,CAAA,GAAA,mBAAW,EAAE,eAAe,EAAE,MAAM,GAAc;oBACpF,IAAI,cAAc,IAAI,cAAc,WAAW,CAAE,UAAU,CAAC,QAAQ;wBAAC,eAAe,EAAE,MAAM;oBAAA;oBAC5F,CAAA,GAAA,yCAAa,EAAE,aAAa;oBAC5B,IAAI,QAAQ,CAAA,GAAA,wCAAmB,EAAc;oBAC7C,OAAO;gBACT;YACF,GAAG;gBAAC,SAAS;YAAI;QACnB;IACF,GAAG;QAAC;QAAe;QAAqB;QAAkB;QAAmB;KAAO;IAEpF,IAAI,YACF,OAAO;QACL,kBAAkB;YAChB,0DAA0D;YAC1D,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 {createSyntheticEvent, setEventTarget, useSyntheticBlurEvent} from './utils';\nimport {DOMAttributes} from '@react-types/shared';\nimport {FocusEvent, useCallback, useRef} from 'react';\nimport {getActiveElement, getEventTarget, getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/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 {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n let onBlur = useCallback((e: FocusEvent) => {\n // Ignore events bubbling through portals.\n if (!nodeContains(e.currentTarget, e.target)) {\n return;\n }\n\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 && !nodeContains(e.currentTarget as Element, e.relatedTarget as Element)) {\n state.current.isFocusWithin = false;\n removeAllGlobalListeners();\n\n if (onBlurWithin) {\n onBlurWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(false);\n }\n }\n }, [onBlurWithin, onFocusWithinChange, state, removeAllGlobalListeners]);\n\n let onSyntheticFocus = useSyntheticBlurEvent(onBlur);\n let onFocus = useCallback((e: FocusEvent) => {\n // Ignore events bubbling through portals.\n if (!nodeContains(e.currentTarget, e.target)) {\n return;\n }\n\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n const ownerDocument = getOwnerDocument(e.target);\n const activeElement = getActiveElement(ownerDocument);\n if (!state.current.isFocusWithin && activeElement === getEventTarget(e.nativeEvent)) {\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 // Browsers don't fire blur events when elements are removed from the DOM.\n // However, if a focus event occurs outside the element we're tracking, we\n // can manually fire onBlur.\n let currentTarget = e.currentTarget;\n addGlobalListener(ownerDocument, 'focus', e => {\n if (state.current.isFocusWithin && !nodeContains(currentTarget, e.target as Element)) {\n let nativeEvent = new ownerDocument.defaultView!.FocusEvent('blur', {relatedTarget: e.target});\n setEventTarget(nativeEvent, currentTarget);\n let event = createSyntheticEvent<FocusEvent>(nativeEvent);\n onBlur(event);\n }\n }, {capture: true});\n }\n }, [onFocusWithin, onFocusWithinChange, onSyntheticFocus, addGlobalListener, onBlur]);\n\n if (isDisabled) {\n return {\n focusWithinProps: {\n // These cannot be 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"}
|
package/dist/useHover.main.js
CHANGED
|
@@ -69,7 +69,7 @@ function $ffbc150311c75f01$export$ae780daf29e6d456(props) {
|
|
|
69
69
|
let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $82z6W$react.useMemo)(()=>{
|
|
70
70
|
let triggerHoverStart = (event, pointerType)=>{
|
|
71
71
|
state.pointerType = pointerType;
|
|
72
|
-
if (isDisabled || pointerType === 'touch' || state.isHovered || !event.currentTarget
|
|
72
|
+
if (isDisabled || pointerType === 'touch' || state.isHovered || !(0, $82z6W$reactariautils.nodeContains)(event.currentTarget, event.target)) return;
|
|
73
73
|
state.isHovered = true;
|
|
74
74
|
let target = event.currentTarget;
|
|
75
75
|
state.target = target;
|
|
@@ -112,7 +112,7 @@ function $ffbc150311c75f01$export$ae780daf29e6d456(props) {
|
|
|
112
112
|
triggerHoverStart(e, e.pointerType);
|
|
113
113
|
};
|
|
114
114
|
hoverProps.onPointerLeave = (e)=>{
|
|
115
|
-
if (!isDisabled && e.currentTarget
|
|
115
|
+
if (!isDisabled && (0, $82z6W$reactariautils.nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, e.pointerType);
|
|
116
116
|
};
|
|
117
117
|
} else if (process.env.NODE_ENV === 'test') {
|
|
118
118
|
hoverProps.onTouchStart = ()=>{
|
|
@@ -123,7 +123,7 @@ function $ffbc150311c75f01$export$ae780daf29e6d456(props) {
|
|
|
123
123
|
state.ignoreEmulatedMouseEvents = false;
|
|
124
124
|
};
|
|
125
125
|
hoverProps.onMouseLeave = (e)=>{
|
|
126
|
-
if (!isDisabled && e.currentTarget
|
|
126
|
+
if (!isDisabled && (0, $82z6W$reactariautils.nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, 'mouse');
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;AAiBlH,oGAAoG;AACpG,iFAAiF;AACjF,sDAAsD;AACtD,IAAI,wDAAkC;AACtC,IAAI,mCAAa;AAEjB,SAAS;IACP,wDAAkC;IAElC,wFAAwF;IACxF,sFAAsF;IACtF,wFAAwF;IACxF,oEAAoE;IACpE,WAAW;QACT,wDAAkC;IACpC,GAAG;AACL;AAEA,SAAS,+CAAyB,CAAe;IAC/C,IAAI,EAAE,WAAW,KAAK,SACpB;AAEJ;AAEA,SAAS;IACP,IAAI,OAAO,aAAa,aACtB;IAGF,IAAI,qCAAe,GAAG;QACpB,IAAI,OAAO,iBAAiB,aAC1B,SAAS,gBAAgB,CAAC,aAAa;aAClC,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,QAClC,SAAS,gBAAgB,CAAC,YAAY;IAE1C;IAEA;IACA,OAAO;QACL;QACA,IAAI,mCAAa,GACf;QAGF,IAAI,OAAO,iBAAiB,aAC1B,SA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GAAG;QAAC;KAAW;IAEf,OAAO;oBACL;mBACA;IACF;AACF","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 {getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/utils';\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: PointerEvent) {\n if (e.pointerType === 'touch') {\n setGlobalIgnoreEmulatedMouseEvents();\n }\n}\n\nfunction setupGlobalTouchEvents() {\n if (typeof document === 'undefined') {\n return;\n }\n\n if (hoverCount === 0) {\n if (typeof PointerEvent !== 'undefined') {\n document.addEventListener('pointerup', handleGlobalPointerEvent);\n } else if (process.env.NODE_ENV === 'test') {\n document.addEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\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 if (process.env.NODE_ENV === 'test') {\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 let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\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 // When an element that is hovered over is removed, no pointerleave event is fired by the browser,\n // even though the originally hovered target may have shrunk in size so it is no longer hovered.\n // However, a pointerover event will be fired on the new target the mouse is over.\n // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.\n addGlobalListener(getOwnerDocument(event.target), 'pointerover', e => {\n if (state.isHovered && state.target && !nodeContains(state.target, e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n }, {capture: true});\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 let target = state.target;\n state.pointerType = '';\n state.target = null;\n\n if (pointerType === 'touch' || !state.isHovered || !target) {\n return;\n }\n\n state.isHovered = false;\n removeAllGlobalListeners();\n\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 if (process.env.NODE_ENV === 'test') {\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, addGlobalListener, removeAllGlobalListeners]);\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"],"names":[],"version":3,"file":"useHover.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;AAiBlH,oGAAoG;AACpG,iFAAiF;AACjF,sDAAsD;AACtD,IAAI,wDAAkC;AACtC,IAAI,mCAAa;AAEjB,SAAS;IACP,wDAAkC;IAElC,wFAAwF;IACxF,sFAAsF;IACtF,wFAAwF;IACxF,oEAAoE;IACpE,WAAW;QACT,wDAAkC;IACpC,GAAG;AACL;AAEA,SAAS,+CAAyB,CAAe;IAC/C,IAAI,EAAE,WAAW,KAAK,SACpB;AAEJ;AAEA,SAAS;IACP,IAAI,OAAO,aAAa,aACtB;IAGF,IAAI,qCAAe,GAAG;QACpB,IAAI,OAAO,iBAAiB,aAC1B,SAAS,gBAAgB,CAAC,aAAa;aAClC,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,QAClC,SAAS,gBAAgB,CAAC,YAAY;IAE1C;IAEA;IACA,OAAO;QACL;QACA,IAAI,mCAAa,GACf;QAGF,IAAI,OAAO,iBAAiB,aAC1B,SAAS,mBAAmB,CAAC,aAAa;aACrC,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,QAClC,SAAS,mBAAmB,CAAC,YAAY;IAE7C;AACF;AAMO,SAAS,0CAAS,KAAiB;IACxC,IAAI,gBACF,YAAY,iBACZ,aAAa,cACb,UAAU,cACV,UAAU,EACX,GAAG;IAEJ,IAAI,CAAC,WAAW,WAAW,GAAG,CAAA,GAAA,qBAAO,EAAE;IACvC,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAE;QACjB,WAAW;QACX,2BAA2B;QAC3B,aAAa;QACb,QAAQ;IACV,GAAG,OAAO;IAEV,CAAA,GAAA,sBAAQ,EAAE,8CAAwB,EAAE;IACpC,IAAI,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,kBAAkB,GAAG,EAAE,WAAW;YACpC;YAEA,WAAW,cAAc,GAAG,CAAC;gBAC3B,IAAI,CAAC,cAAc,CAAA,GAAA,kCAAW,EAAE,EAAE,aAAa,EAAE,EAAE,MAAM,GACvD,gBAAgB,GAAG,EAAE,WAAW;YAEpC;QACF,OAAO,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,QAAQ;YAC1C,WAAW,YAAY,GAAG;gBACxB,MAAM,yBAAyB,GAAG;YACpC;YAEA,WAAW,YAAY,GAAG,CAAC;gBACzB,IAAI,CAAC,MAAM,yBAAyB,IAAI,CAAC,uDACvC,kBAAkB,GAAG;gBAGvB,MAAM,yBAAyB,GAAG;YACpC;YAEA,WAAW,YAAY,GAAG,CAAC;gBACzB,IAAI,CAAC,cAAc,CAAA,GAAA,kCAAW,EAAE,EAAE,aAAa,EAAE,EAAE,MAAM,GACvD,gBAAgB,GAAG;YAEvB;QACF;QACA,OAAO;wBAAC;6BAAY;QAAe;IACrC,GAAG;QAAC;QAAc;QAAe;QAAY;QAAY;QAAO;QAAmB;KAAyB;IAE5G,CAAA,GAAA,sBAAQ,EAAE;QACR,iEAAiE;QACjE,qFAAqF;QACrF,IAAI,YACF,gBAAgB;YAAC,eAAe,MAAM,MAAM;QAAA,GAAG,MAAM,WAAW;IAEpE,uDAAuD;IACvD,GAAG;QAAC;KAAW;IAEf,OAAO;oBACL;mBACA;IACF;AACF","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 {getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/utils';\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: PointerEvent) {\n if (e.pointerType === 'touch') {\n setGlobalIgnoreEmulatedMouseEvents();\n }\n}\n\nfunction setupGlobalTouchEvents() {\n if (typeof document === 'undefined') {\n return;\n }\n\n if (hoverCount === 0) {\n if (typeof PointerEvent !== 'undefined') {\n document.addEventListener('pointerup', handleGlobalPointerEvent);\n } else if (process.env.NODE_ENV === 'test') {\n document.addEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\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 if (process.env.NODE_ENV === 'test') {\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 let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n let {hoverProps, triggerHoverEnd} = useMemo(() => {\n let triggerHoverStart = (event, pointerType) => {\n state.pointerType = pointerType;\n if (isDisabled || pointerType === 'touch' || state.isHovered || !nodeContains(event.currentTarget, event.target)) {\n return;\n }\n\n state.isHovered = true;\n let target = event.currentTarget;\n state.target = target;\n\n // When an element that is hovered over is removed, no pointerleave event is fired by the browser,\n // even though the originally hovered target may have shrunk in size so it is no longer hovered.\n // However, a pointerover event will be fired on the new target the mouse is over.\n // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.\n addGlobalListener(getOwnerDocument(event.target), 'pointerover', e => {\n if (state.isHovered && state.target && !nodeContains(state.target, e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n }, {capture: true});\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 let target = state.target;\n state.pointerType = '';\n state.target = null;\n\n if (pointerType === 'touch' || !state.isHovered || !target) {\n return;\n }\n\n state.isHovered = false;\n removeAllGlobalListeners();\n\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 && nodeContains(e.currentTarget, e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n };\n } else if (process.env.NODE_ENV === 'test') {\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 && nodeContains(e.currentTarget, e.target as Element)) {\n triggerHoverEnd(e, 'mouse');\n }\n };\n }\n return {hoverProps, triggerHoverEnd};\n }, [onHoverStart, onHoverChange, onHoverEnd, isDisabled, state, addGlobalListener, removeAllGlobalListeners]);\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"],"names":[],"version":3,"file":"useHover.main.js.map"}
|
package/dist/useHover.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useGlobalListeners as $AWxnT$useGlobalListeners,
|
|
1
|
+
import {useGlobalListeners as $AWxnT$useGlobalListeners, nodeContains as $AWxnT$nodeContains, getOwnerDocument as $AWxnT$getOwnerDocument} from "@react-aria/utils";
|
|
2
2
|
import {useState as $AWxnT$useState, useRef as $AWxnT$useRef, useEffect as $AWxnT$useEffect, useMemo as $AWxnT$useMemo} from "react";
|
|
3
3
|
|
|
4
4
|
/*
|
|
@@ -63,7 +63,7 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
63
63
|
let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $AWxnT$useMemo)(()=>{
|
|
64
64
|
let triggerHoverStart = (event, pointerType)=>{
|
|
65
65
|
state.pointerType = pointerType;
|
|
66
|
-
if (isDisabled || pointerType === 'touch' || state.isHovered || !event.currentTarget
|
|
66
|
+
if (isDisabled || pointerType === 'touch' || state.isHovered || !(0, $AWxnT$nodeContains)(event.currentTarget, event.target)) return;
|
|
67
67
|
state.isHovered = true;
|
|
68
68
|
let target = event.currentTarget;
|
|
69
69
|
state.target = target;
|
|
@@ -106,7 +106,7 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
106
106
|
triggerHoverStart(e, e.pointerType);
|
|
107
107
|
};
|
|
108
108
|
hoverProps.onPointerLeave = (e)=>{
|
|
109
|
-
if (!isDisabled && e.currentTarget
|
|
109
|
+
if (!isDisabled && (0, $AWxnT$nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, e.pointerType);
|
|
110
110
|
};
|
|
111
111
|
} else if (process.env.NODE_ENV === 'test') {
|
|
112
112
|
hoverProps.onTouchStart = ()=>{
|
|
@@ -117,7 +117,7 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
117
117
|
state.ignoreEmulatedMouseEvents = false;
|
|
118
118
|
};
|
|
119
119
|
hoverProps.onMouseLeave = (e)=>{
|
|
120
|
-
if (!isDisabled && e.currentTarget
|
|
120
|
+
if (!isDisabled && (0, $AWxnT$nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, 'mouse');
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
123
|
return {
|
package/dist/useHover.module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useGlobalListeners as $AWxnT$useGlobalListeners,
|
|
1
|
+
import {useGlobalListeners as $AWxnT$useGlobalListeners, nodeContains as $AWxnT$nodeContains, getOwnerDocument as $AWxnT$getOwnerDocument} from "@react-aria/utils";
|
|
2
2
|
import {useState as $AWxnT$useState, useRef as $AWxnT$useRef, useEffect as $AWxnT$useEffect, useMemo as $AWxnT$useMemo} from "react";
|
|
3
3
|
|
|
4
4
|
/*
|
|
@@ -63,7 +63,7 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
63
63
|
let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $AWxnT$useMemo)(()=>{
|
|
64
64
|
let triggerHoverStart = (event, pointerType)=>{
|
|
65
65
|
state.pointerType = pointerType;
|
|
66
|
-
if (isDisabled || pointerType === 'touch' || state.isHovered || !event.currentTarget
|
|
66
|
+
if (isDisabled || pointerType === 'touch' || state.isHovered || !(0, $AWxnT$nodeContains)(event.currentTarget, event.target)) return;
|
|
67
67
|
state.isHovered = true;
|
|
68
68
|
let target = event.currentTarget;
|
|
69
69
|
state.target = target;
|
|
@@ -106,7 +106,7 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
106
106
|
triggerHoverStart(e, e.pointerType);
|
|
107
107
|
};
|
|
108
108
|
hoverProps.onPointerLeave = (e)=>{
|
|
109
|
-
if (!isDisabled && e.currentTarget
|
|
109
|
+
if (!isDisabled && (0, $AWxnT$nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, e.pointerType);
|
|
110
110
|
};
|
|
111
111
|
} else if (process.env.NODE_ENV === 'test') {
|
|
112
112
|
hoverProps.onTouchStart = ()=>{
|
|
@@ -117,7 +117,7 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
117
117
|
state.ignoreEmulatedMouseEvents = false;
|
|
118
118
|
};
|
|
119
119
|
hoverProps.onMouseLeave = (e)=>{
|
|
120
|
-
if (!isDisabled && e.currentTarget
|
|
120
|
+
if (!isDisabled && (0, $AWxnT$nodeContains)(e.currentTarget, e.target)) triggerHoverEnd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Ac,GAAG,CAAC;gBAC3B,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAClD,gBAAgB,GAAG,EAAE,WAAW;YAEpC;QACF,OAAO,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,QAAQ;YAC1C,WAAW,YAAY,GAAG;gBACxB,MAAM,yBAAyB,GAAG;YACpC;YAEA,WAAW,YAAY,GAAG,CAAC;gBACzB,IAAI,CAAC,MAAM,yBAAyB,IAAI,CAAC,uDACvC,kBAAkB,GAAG;gBAGvB,MAAM,yBAAyB,GAAG;YACpC;YAEA,WAAW,YAAY,GAAG,CAAC;gBACzB,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAClD,gBAAgB,GAAG;YAEvB;QACF;QACA,OAAO;wBAAC;6BAAY;QAAe;IACrC,GAAG;QAAC;QAAc;QAAe;QAAY;QAAY;QAAO;QAAmB;KAAyB;IAE5G,CAAA,GAAA,gBAAQ,EAAE;QACR,iEAAiE;QACjE,qFAAqF;QACrF,IAAI,YACF,gBAAgB;YAAC,eAAe,MAAM,MAAM;QAAA,GAAG,MAAM,WAAW;IAEpE,uDAAuD;IACvD,GAAG;QAAC;KAAW;IAEf,OAAO;oBACL;mBACA;IACF;AACF","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 {getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/utils';\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: PointerEvent) {\n if (e.pointerType === 'touch') {\n setGlobalIgnoreEmulatedMouseEvents();\n }\n}\n\nfunction setupGlobalTouchEvents() {\n if (typeof document === 'undefined') {\n return;\n }\n\n if (hoverCount === 0) {\n if (typeof PointerEvent !== 'undefined') {\n document.addEventListener('pointerup', handleGlobalPointerEvent);\n } else if (process.env.NODE_ENV === 'test') {\n document.addEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\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 if (process.env.NODE_ENV === 'test') {\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 let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\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 // When an element that is hovered over is removed, no pointerleave event is fired by the browser,\n // even though the originally hovered target may have shrunk in size so it is no longer hovered.\n // However, a pointerover event will be fired on the new target the mouse is over.\n // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.\n addGlobalListener(getOwnerDocument(event.target), 'pointerover', e => {\n if (state.isHovered && state.target && !nodeContains(state.target, e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n }, {capture: true});\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 let target = state.target;\n state.pointerType = '';\n state.target = null;\n\n if (pointerType === 'touch' || !state.isHovered || !target) {\n return;\n }\n\n state.isHovered = false;\n removeAllGlobalListeners();\n\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 if (process.env.NODE_ENV === 'test') {\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, addGlobalListener, removeAllGlobalListeners]);\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"],"names":[],"version":3,"file":"useHover.module.js.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;AAiBlH,oGAAoG;AACpG,iFAAiF;AACjF,sDAAsD;AACtD,IAAI,wDAAkC;AACtC,IAAI,mCAAa;AAEjB,SAAS;IACP,wDAAkC;IAElC,wFAAwF;IACxF,sFAAsF;IACtF,wFAAwF;IACxF,oEAAoE;IACpE,WAAW;QACT,wDAAkC;IACpC,GAAG;AACL;AAEA,SAAS,+CAAyB,CAAe;IAC/C,IAAI,EAAE,WAAW,KAAK,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CAAA,GAAA,mBAAW,EAAE,EAAE,aAAa,EAAE,EAAE,MAAM,GACvD,gBAAgB,GAAG;YAEvB;QACF;QACA,OAAO;wBAAC;6BAAY;QAAe;IACrC,GAAG;QAAC;QAAc;QAAe;QAAY;QAAY;QAAO;QAAmB;KAAyB;IAE5G,CAAA,GAAA,gBAAQ,EAAE;QACR,iEAAiE;QACjE,qFAAqF;QACrF,IAAI,YACF,gBAAgB;YAAC,eAAe,MAAM,MAAM;QAAA,GAAG,MAAM,WAAW;IAEpE,uDAAuD;IACvD,GAAG;QAAC;KAAW;IAEf,OAAO;oBACL;mBACA;IACF;AACF","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 {getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/utils';\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: PointerEvent) {\n if (e.pointerType === 'touch') {\n setGlobalIgnoreEmulatedMouseEvents();\n }\n}\n\nfunction setupGlobalTouchEvents() {\n if (typeof document === 'undefined') {\n return;\n }\n\n if (hoverCount === 0) {\n if (typeof PointerEvent !== 'undefined') {\n document.addEventListener('pointerup', handleGlobalPointerEvent);\n } else if (process.env.NODE_ENV === 'test') {\n document.addEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\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 if (process.env.NODE_ENV === 'test') {\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 let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n let {hoverProps, triggerHoverEnd} = useMemo(() => {\n let triggerHoverStart = (event, pointerType) => {\n state.pointerType = pointerType;\n if (isDisabled || pointerType === 'touch' || state.isHovered || !nodeContains(event.currentTarget, event.target)) {\n return;\n }\n\n state.isHovered = true;\n let target = event.currentTarget;\n state.target = target;\n\n // When an element that is hovered over is removed, no pointerleave event is fired by the browser,\n // even though the originally hovered target may have shrunk in size so it is no longer hovered.\n // However, a pointerover event will be fired on the new target the mouse is over.\n // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.\n addGlobalListener(getOwnerDocument(event.target), 'pointerover', e => {\n if (state.isHovered && state.target && !nodeContains(state.target, e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n }, {capture: true});\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 let target = state.target;\n state.pointerType = '';\n state.target = null;\n\n if (pointerType === 'touch' || !state.isHovered || !target) {\n return;\n }\n\n state.isHovered = false;\n removeAllGlobalListeners();\n\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 && nodeContains(e.currentTarget, e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n };\n } else if (process.env.NODE_ENV === 'test') {\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 && nodeContains(e.currentTarget, e.target as Element)) {\n triggerHoverEnd(e, 'mouse');\n }\n };\n }\n return {hoverProps, triggerHoverEnd};\n }, [onHoverStart, onHoverChange, onHoverEnd, isDisabled, state, addGlobalListener, removeAllGlobalListeners]);\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"],"names":[],"version":3,"file":"useHover.module.js.map"}
|
|
@@ -90,7 +90,7 @@ function $edcfa848c42f94f4$var$isValidEvent(event, ref) {
|
|
|
90
90
|
if (event.target) {
|
|
91
91
|
// if the event target is no longer in the document, ignore
|
|
92
92
|
const ownerDocument = event.target.ownerDocument;
|
|
93
|
-
if (!ownerDocument || !ownerDocument.documentElement
|
|
93
|
+
if (!ownerDocument || !(0, $9Icr4$reactariautils.nodeContains)(ownerDocument.documentElement, event.target)) return false;
|
|
94
94
|
// If the target is within a top layer element (e.g. toasts), ignore.
|
|
95
95
|
if (event.target.closest('[data-react-aria-top-layer]')) return false;
|
|
96
96
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;AAkB3G,SAAS,0CAAmB,KAA2B;IAC5D,IAAI,OAAC,GAAG,qBAAE,iBAAiB,cAAE,UAAU,0BAAE,sBAAsB,EAAC,GAAG;IACnE,IAAI,WAAW,CAAA,GAAA,mBAAK,EAAE;QACpB,eAAe;QACf,2BAA2B;IAC7B;IAEA,IAAI,gBAAgB,CAAA,GAAA,oCAAa,EAAE,CAAC;QAClC,IAAI,qBAAqB,mCAAa,GAAG,M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iB,CAAC,CAAA,GAAA,kCAAW,EAAE,cAAc,eAAe,EAAE,MAAM,MAAM,GAC7E,OAAO;QAET,qEAAqE;QACrE,IAAI,MAAM,MAAM,CAAC,OAAO,CAAC,gCACvB,OAAO;IAEX;IAEA,IAAI,CAAC,IAAI,OAAO,EACd,OAAO;IAGT,sFAAsF;IACtF,+FAA+F;IAC/F,yFAAyF;IACzF,sEAAsE;IACtE,OAAO,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,OAAO;AACnD","sources":["packages/@react-aria/interactions/src/useInteractOutside.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 {getOwnerDocument, nodeContains, useEffectEvent} from '@react-aria/utils';\nimport {RefObject} from '@react-types/shared';\nimport {useEffect, useRef} from 'react';\n\nexport interface InteractOutsideProps {\n ref: RefObject<Element | null>,\n onInteractOutside?: (e: PointerEvent) => void,\n onInteractOutsideStart?: (e: PointerEvent) => void,\n /** Whether the interact outside events should be disabled. */\n isDisabled?: boolean\n}\n\n/**\n * Example, used in components like Dialogs and Popovers so they can close\n * when a user clicks outside them.\n */\nexport function useInteractOutside(props: InteractOutsideProps): void {\n let {ref, onInteractOutside, isDisabled, onInteractOutsideStart} = props;\n let stateRef = useRef({\n isPointerDown: false,\n ignoreEmulatedMouseEvents: false\n });\n\n let onPointerDown = useEffectEvent((e) => {\n if (onInteractOutside && isValidEvent(e, ref)) {\n if (onInteractOutsideStart) {\n onInteractOutsideStart(e);\n }\n stateRef.current.isPointerDown = true;\n }\n });\n\n let triggerInteractOutside = useEffectEvent((e: PointerEvent) => {\n if (onInteractOutside) {\n onInteractOutside(e);\n }\n });\n\n useEffect(() => {\n let state = stateRef.current;\n if (isDisabled) {\n return;\n }\n\n const element = ref.current;\n const documentObject = getOwnerDocument(element);\n\n // Use pointer events if available. Otherwise, fall back to mouse and touch events.\n if (typeof PointerEvent !== 'undefined') {\n let onClick = (e) => {\n if (state.isPointerDown && isValidEvent(e, ref)) {\n triggerInteractOutside(e);\n }\n state.isPointerDown = false;\n };\n\n // changing these to capture phase fixed combobox\n // Use click instead of pointerup to avoid Android Chrome issue\n // https://issues.chromium.org/issues/40732224\n documentObject.addEventListener('pointerdown', onPointerDown, true);\n documentObject.addEventListener('click', onClick, true);\n\n return () => {\n documentObject.removeEventListener('pointerdown', onPointerDown, true);\n documentObject.removeEventListener('click', onClick, true);\n };\n } else if (process.env.NODE_ENV === 'test') {\n let onMouseUp = (e) => {\n if (state.ignoreEmulatedMouseEvents) {\n state.ignoreEmulatedMouseEvents = false;\n } else if (state.isPointerDown && isValidEvent(e, ref)) {\n triggerInteractOutside(e);\n }\n state.isPointerDown = false;\n };\n\n let onTouchEnd = (e) => {\n state.ignoreEmulatedMouseEvents = true;\n if (state.isPointerDown && isValidEvent(e, ref)) {\n triggerInteractOutside(e);\n }\n state.isPointerDown = false;\n };\n\n documentObject.addEventListener('mousedown', onPointerDown, true);\n documentObject.addEventListener('mouseup', onMouseUp, true);\n documentObject.addEventListener('touchstart', onPointerDown, true);\n documentObject.addEventListener('touchend', onTouchEnd, true);\n\n return () => {\n documentObject.removeEventListener('mousedown', onPointerDown, true);\n documentObject.removeEventListener('mouseup', onMouseUp, true);\n documentObject.removeEventListener('touchstart', onPointerDown, true);\n documentObject.removeEventListener('touchend', onTouchEnd, true);\n };\n }\n }, [ref, isDisabled]);\n}\n\nfunction isValidEvent(event, ref) {\n if (event.button > 0) {\n return false;\n }\n if (event.target) {\n // if the event target is no longer in the document, ignore\n const ownerDocument = event.target.ownerDocument;\n if (!ownerDocument || !nodeContains(ownerDocument.documentElement, event.target)) {\n return false;\n }\n // If the target is within a top layer element (e.g. toasts), ignore.\n if (event.target.closest('[data-react-aria-top-layer]')) {\n return false;\n }\n }\n\n if (!ref.current) {\n return false;\n }\n\n // When the event source is inside a Shadow DOM, event.target is just the shadow root.\n // Using event.composedPath instead means we can get the actual element inside the shadow root.\n // This only works if the shadow root is open, there is no way to detect if it is closed.\n // If the event composed path contains the ref, interaction is inside.\n return !event.composedPath().includes(ref.current);\n}\n"],"names":[],"version":3,"file":"useInteractOutside.main.js.map"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useEffectEvent as $ispOf$useEffectEvent, getOwnerDocument as $ispOf$getOwnerDocument} from "@react-aria/utils";
|
|
1
|
+
import {useEffectEvent as $ispOf$useEffectEvent, getOwnerDocument as $ispOf$getOwnerDocument, nodeContains as $ispOf$nodeContains} from "@react-aria/utils";
|
|
2
2
|
import {useRef as $ispOf$useRef, useEffect as $ispOf$useEffect} from "react";
|
|
3
3
|
|
|
4
4
|
/*
|
|
@@ -84,7 +84,7 @@ function $e0b6e0b68ec7f50f$var$isValidEvent(event, ref) {
|
|
|
84
84
|
if (event.target) {
|
|
85
85
|
// if the event target is no longer in the document, ignore
|
|
86
86
|
const ownerDocument = event.target.ownerDocument;
|
|
87
|
-
if (!ownerDocument || !ownerDocument.documentElement
|
|
87
|
+
if (!ownerDocument || !(0, $ispOf$nodeContains)(ownerDocument.documentElement, event.target)) return false;
|
|
88
88
|
// If the target is within a top layer element (e.g. toasts), ignore.
|
|
89
89
|
if (event.target.closest('[data-react-aria-top-layer]')) return false;
|
|
90
90
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useEffectEvent as $ispOf$useEffectEvent, getOwnerDocument as $ispOf$getOwnerDocument} from "@react-aria/utils";
|
|
1
|
+
import {useEffectEvent as $ispOf$useEffectEvent, getOwnerDocument as $ispOf$getOwnerDocument, nodeContains as $ispOf$nodeContains} from "@react-aria/utils";
|
|
2
2
|
import {useRef as $ispOf$useRef, useEffect as $ispOf$useEffect} from "react";
|
|
3
3
|
|
|
4
4
|
/*
|
|
@@ -84,7 +84,7 @@ function $e0b6e0b68ec7f50f$var$isValidEvent(event, ref) {
|
|
|
84
84
|
if (event.target) {
|
|
85
85
|
// if the event target is no longer in the document, ignore
|
|
86
86
|
const ownerDocument = event.target.ownerDocument;
|
|
87
|
-
if (!ownerDocument || !ownerDocument.documentElement
|
|
87
|
+
if (!ownerDocument || !(0, $ispOf$nodeContains)(ownerDocument.documentElement, event.target)) return false;
|
|
88
88
|
// If the target is within a top layer element (e.g. toasts), ignore.
|
|
89
89
|
if (event.target.closest('[data-react-aria-top-layer]')) return false;
|
|
90
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;AAkB3G,SAAS,0CAAmB,KAA2B;IAC5D,IAAI,OAAC,GAAG,qBAAE,iBAAiB,cAAE,UAAU,0BAAE,sBAAsB,EAAC,GAAG;IACnE,IAAI,WAAW,CAAA,GAAA,aAAK,EAAE;QACpB,eAAe;QACf,2BAA2B;IAC7B;IAEA,IAAI,gBAAgB,CAAA,GAAA,qBAAa,EAAE,CAAC;QAClC,IAAI,qBAAqB,mCAAa,GAAG,MAAM;YAC7C,IAAI,wBACF,uBAAuB;YAEzB,SAAS,OAAO,CAAC,aAAa,GAAG;QACnC;IACF;IAEA,IAAI,yBAAyB,CAAA,GAAA,qBAAa,EAAE,CAAC;QAC3C,IAAI,mBACF,kBAAkB;IAEtB;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,QAAQ,SAAS,OAAO;QAC5B,IAAI,YACF;QAGF,MA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CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,OAAO;AACnD","sources":["packages/@react-aria/interactions/src/useInteractOutside.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 {getOwnerDocument, nodeContains, useEffectEvent} from '@react-aria/utils';\nimport {RefObject} from '@react-types/shared';\nimport {useEffect, useRef} from 'react';\n\nexport interface InteractOutsideProps {\n ref: RefObject<Element | null>,\n onInteractOutside?: (e: PointerEvent) => void,\n onInteractOutsideStart?: (e: PointerEvent) => void,\n /** Whether the interact outside events should be disabled. */\n isDisabled?: boolean\n}\n\n/**\n * Example, used in components like Dialogs and Popovers so they can close\n * when a user clicks outside them.\n */\nexport function useInteractOutside(props: InteractOutsideProps): void {\n let {ref, onInteractOutside, isDisabled, onInteractOutsideStart} = props;\n let stateRef = useRef({\n isPointerDown: false,\n ignoreEmulatedMouseEvents: false\n });\n\n let onPointerDown = useEffectEvent((e) => {\n if (onInteractOutside && isValidEvent(e, ref)) {\n if (onInteractOutsideStart) {\n onInteractOutsideStart(e);\n }\n stateRef.current.isPointerDown = true;\n }\n });\n\n let triggerInteractOutside = useEffectEvent((e: PointerEvent) => {\n if (onInteractOutside) {\n onInteractOutside(e);\n }\n });\n\n useEffect(() => {\n let state = stateRef.current;\n if (isDisabled) {\n return;\n }\n\n const element = ref.current;\n const documentObject = getOwnerDocument(element);\n\n // Use pointer events if available. Otherwise, fall back to mouse and touch events.\n if (typeof PointerEvent !== 'undefined') {\n let onClick = (e) => {\n if (state.isPointerDown && isValidEvent(e, ref)) {\n triggerInteractOutside(e);\n }\n state.isPointerDown = false;\n };\n\n // changing these to capture phase fixed combobox\n // Use click instead of pointerup to avoid Android Chrome issue\n // https://issues.chromium.org/issues/40732224\n documentObject.addEventListener('pointerdown', onPointerDown, true);\n documentObject.addEventListener('click', onClick, true);\n\n return () => {\n documentObject.removeEventListener('pointerdown', onPointerDown, true);\n documentObject.removeEventListener('click', onClick, true);\n };\n } else if (process.env.NODE_ENV === 'test') {\n let onMouseUp = (e) => {\n if (state.ignoreEmulatedMouseEvents) {\n state.ignoreEmulatedMouseEvents = false;\n } else if (state.isPointerDown && isValidEvent(e, ref)) {\n triggerInteractOutside(e);\n }\n state.isPointerDown = false;\n };\n\n let onTouchEnd = (e) => {\n state.ignoreEmulatedMouseEvents = true;\n if (state.isPointerDown && isValidEvent(e, ref)) {\n triggerInteractOutside(e);\n }\n state.isPointerDown = false;\n };\n\n documentObject.addEventListener('mousedown', onPointerDown, true);\n documentObject.addEventListener('mouseup', onMouseUp, true);\n documentObject.addEventListener('touchstart', onPointerDown, true);\n documentObject.addEventListener('touchend', onTouchEnd, true);\n\n return () => {\n documentObject.removeEventListener('mousedown', onPointerDown, true);\n documentObject.removeEventListener('mouseup', onMouseUp, true);\n documentObject.removeEventListener('touchstart', onPointerDown, true);\n documentObject.removeEventListener('touchend', onTouchEnd, true);\n };\n }\n }, [ref, isDisabled]);\n}\n\nfunction isValidEvent(event, ref) {\n if (event.button > 0) {\n return false;\n }\n if (event.target) {\n // if the event target is no longer in the document, ignore\n const ownerDocument = event.target.ownerDocument;\n if (!ownerDocument || !nodeContains(ownerDocument.documentElement, event.target)) {\n return false;\n }\n // If the target is within a top layer element (e.g. toasts), ignore.\n if (event.target.closest('[data-react-aria-top-layer]')) {\n return false;\n }\n }\n\n if (!ref.current) {\n return false;\n }\n\n // When the event source is inside a Shadow DOM, event.target is just the shadow root.\n // Using event.composedPath instead means we can get the actual element inside the shadow root.\n // This only works if the shadow root is open, there is no way to detect if it is closed.\n // If the event composed path contains the ref, interaction is inside.\n return !event.composedPath().includes(ref.current);\n}\n"],"names":[],"version":3,"file":"useInteractOutside.module.js.map"}
|
package/dist/usePress.main.js
CHANGED
|
@@ -41,7 +41,9 @@ function $0294ea432cd92340$var$usePressResponderContext(props) {
|
|
|
41
41
|
// Consume context from <PressResponder> and merge with props.
|
|
42
42
|
let context = (0, $bBqCQ$react.useContext)((0, $01d3f539e91688c8$exports.PressResponderContext));
|
|
43
43
|
if (context) {
|
|
44
|
-
|
|
44
|
+
// Prevent mergeProps from merging ref.
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
46
|
+
let { register: register, ref: ref, ...contextProps } = context;
|
|
45
47
|
props = (0, $bBqCQ$reactariautils.mergeProps)(contextProps, props);
|
|
46
48
|
register();
|
|
47
49
|
}
|
|
@@ -89,6 +91,7 @@ class $0294ea432cd92340$var$PressEvent {
|
|
|
89
91
|
this.altKey = originalEvent.altKey;
|
|
90
92
|
this.x = x;
|
|
91
93
|
this.y = y;
|
|
94
|
+
this.key = originalEvent.key;
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
const $0294ea432cd92340$var$LINK_CLICKED = Symbol('linkClicked');
|
|
@@ -330,7 +333,7 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
330
333
|
state.ignoreEmulatedMouseEvents = false;
|
|
331
334
|
return;
|
|
332
335
|
}
|
|
333
|
-
if (state.target && state.target
|
|
336
|
+
if (state.target && (0, $bBqCQ$reactariautils.nodeContains)(state.target, e.target) && state.pointerType != null) ;
|
|
334
337
|
else cancelEvent(e);
|
|
335
338
|
state.isOverTarget = false;
|
|
336
339
|
};
|
|
@@ -439,7 +442,11 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
439
442
|
// Release pointer capture so that touch interactions can leave the original target.
|
|
440
443
|
// This enables onPointerLeave and onPointerEnter to fire.
|
|
441
444
|
let target = (0, $bBqCQ$reactariautils.getEventTarget)(e.nativeEvent);
|
|
442
|
-
if ('releasePointerCapture' in target)
|
|
445
|
+
if ('releasePointerCapture' in target) {
|
|
446
|
+
if ('hasPointerCapture' in target) {
|
|
447
|
+
if (target.hasPointerCapture(e.pointerId)) target.releasePointerCapture(e.pointerId);
|
|
448
|
+
} else target.releasePointerCapture(e.pointerId);
|
|
449
|
+
}
|
|
443
450
|
}
|
|
444
451
|
if (shouldStopPropagation) e.stopPropagation();
|
|
445
452
|
};
|
|
@@ -696,7 +703,8 @@ function $0294ea432cd92340$var$createEvent(target, e) {
|
|
|
696
703
|
metaKey: e.metaKey,
|
|
697
704
|
altKey: e.altKey,
|
|
698
705
|
clientX: clientX,
|
|
699
|
-
clientY: clientY
|
|
706
|
+
clientY: clientY,
|
|
707
|
+
key: e.key
|
|
700
708
|
};
|
|
701
709
|
}
|
|
702
710
|
function $0294ea432cd92340$var$getPointClientRect(point) {
|