@react-aria/interactions 3.27.0 → 3.28.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.
Files changed (118) hide show
  1. package/dist/import.mjs +21 -15
  2. package/dist/main.js +45 -39
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +21 -15
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +31 -0
  7. package/package.json +16 -15
  8. package/src/index.ts +31 -35
  9. package/dist/PressResponder.main.js +0 -61
  10. package/dist/PressResponder.main.js.map +0 -1
  11. package/dist/PressResponder.mjs +0 -51
  12. package/dist/PressResponder.module.js +0 -51
  13. package/dist/PressResponder.module.js.map +0 -1
  14. package/dist/Pressable.main.js +0 -69
  15. package/dist/Pressable.main.js.map +0 -1
  16. package/dist/Pressable.mjs +0 -60
  17. package/dist/Pressable.module.js +0 -60
  18. package/dist/Pressable.module.js.map +0 -1
  19. package/dist/context.main.js +0 -30
  20. package/dist/context.main.js.map +0 -1
  21. package/dist/context.mjs +0 -21
  22. package/dist/context.module.js +0 -21
  23. package/dist/context.module.js.map +0 -1
  24. package/dist/createEventHandler.main.js +0 -46
  25. package/dist/createEventHandler.main.js.map +0 -1
  26. package/dist/createEventHandler.mjs +0 -41
  27. package/dist/createEventHandler.module.js +0 -41
  28. package/dist/createEventHandler.module.js.map +0 -1
  29. package/dist/focusSafely.main.js +0 -40
  30. package/dist/focusSafely.main.js.map +0 -1
  31. package/dist/focusSafely.mjs +0 -35
  32. package/dist/focusSafely.module.js +0 -35
  33. package/dist/focusSafely.module.js.map +0 -1
  34. package/dist/textSelection.main.js +0 -77
  35. package/dist/textSelection.main.js.map +0 -1
  36. package/dist/textSelection.mjs +0 -71
  37. package/dist/textSelection.module.js +0 -71
  38. package/dist/textSelection.module.js.map +0 -1
  39. package/dist/types.d.ts +0 -255
  40. package/dist/types.d.ts.map +0 -1
  41. package/dist/useFocus.main.js +0 -65
  42. package/dist/useFocus.main.js.map +0 -1
  43. package/dist/useFocus.mjs +0 -60
  44. package/dist/useFocus.module.js +0 -60
  45. package/dist/useFocus.module.js.map +0 -1
  46. package/dist/useFocusVisible.main.js +0 -265
  47. package/dist/useFocusVisible.main.js.map +0 -1
  48. package/dist/useFocusVisible.mjs +0 -253
  49. package/dist/useFocusVisible.module.js +0 -253
  50. package/dist/useFocusVisible.module.js.map +0 -1
  51. package/dist/useFocusWithin.main.js +0 -105
  52. package/dist/useFocusWithin.main.js.map +0 -1
  53. package/dist/useFocusWithin.mjs +0 -100
  54. package/dist/useFocusWithin.module.js +0 -100
  55. package/dist/useFocusWithin.module.js.map +0 -1
  56. package/dist/useFocusable.main.js +0 -113
  57. package/dist/useFocusable.main.js.map +0 -1
  58. package/dist/useFocusable.mjs +0 -101
  59. package/dist/useFocusable.module.js +0 -101
  60. package/dist/useFocusable.module.js.map +0 -1
  61. package/dist/useHover.main.js +0 -159
  62. package/dist/useHover.main.js.map +0 -1
  63. package/dist/useHover.mjs +0 -154
  64. package/dist/useHover.module.js +0 -154
  65. package/dist/useHover.module.js.map +0 -1
  66. package/dist/useInteractOutside.main.js +0 -106
  67. package/dist/useInteractOutside.main.js.map +0 -1
  68. package/dist/useInteractOutside.mjs +0 -101
  69. package/dist/useInteractOutside.module.js +0 -101
  70. package/dist/useInteractOutside.module.js.map +0 -1
  71. package/dist/useKeyboard.main.js +0 -30
  72. package/dist/useKeyboard.main.js.map +0 -1
  73. package/dist/useKeyboard.mjs +0 -25
  74. package/dist/useKeyboard.module.js +0 -25
  75. package/dist/useKeyboard.module.js.map +0 -1
  76. package/dist/useLongPress.main.js +0 -86
  77. package/dist/useLongPress.main.js.map +0 -1
  78. package/dist/useLongPress.mjs +0 -81
  79. package/dist/useLongPress.module.js +0 -81
  80. package/dist/useLongPress.module.js.map +0 -1
  81. package/dist/useMove.main.js +0 -272
  82. package/dist/useMove.main.js.map +0 -1
  83. package/dist/useMove.mjs +0 -267
  84. package/dist/useMove.module.js +0 -267
  85. package/dist/useMove.module.js.map +0 -1
  86. package/dist/usePress.main.js +0 -763
  87. package/dist/usePress.main.js.map +0 -1
  88. package/dist/usePress.mjs +0 -758
  89. package/dist/usePress.module.js +0 -758
  90. package/dist/usePress.module.js.map +0 -1
  91. package/dist/useScrollWheel.main.js +0 -41
  92. package/dist/useScrollWheel.main.js.map +0 -1
  93. package/dist/useScrollWheel.mjs +0 -36
  94. package/dist/useScrollWheel.module.js +0 -36
  95. package/dist/useScrollWheel.module.js.map +0 -1
  96. package/dist/utils.main.js +0 -163
  97. package/dist/utils.main.js.map +0 -1
  98. package/dist/utils.mjs +0 -154
  99. package/dist/utils.module.js +0 -154
  100. package/dist/utils.module.js.map +0 -1
  101. package/src/PressResponder.tsx +0 -67
  102. package/src/Pressable.tsx +0 -97
  103. package/src/context.ts +0 -23
  104. package/src/createEventHandler.ts +0 -55
  105. package/src/focusSafely.ts +0 -45
  106. package/src/textSelection.ts +0 -101
  107. package/src/useFocus.ts +0 -87
  108. package/src/useFocusVisible.ts +0 -357
  109. package/src/useFocusWithin.ts +0 -132
  110. package/src/useFocusable.tsx +0 -191
  111. package/src/useHover.ts +0 -222
  112. package/src/useInteractOutside.ts +0 -142
  113. package/src/useKeyboard.ts +0 -36
  114. package/src/useLongPress.ts +0 -135
  115. package/src/useMove.ts +0 -259
  116. package/src/usePress.ts +0 -1093
  117. package/src/useScrollWheel.ts +0 -41
  118. package/src/utils.ts +0 -174
@@ -1,101 +0,0 @@
1
- import {focusSafely as $3ad3f6e1647bc98d$export$80f3e147d781571c} from "./focusSafely.module.js";
2
- import {useFocus as $a1ea59d68270f0dd$export$f8168d8dd8fd66e6} from "./useFocus.module.js";
3
- import {useKeyboard as $46d819fcbaf35654$export$8f71654801c2f7cd} from "./useKeyboard.module.js";
4
- import {useSyncRef as $fcPuG$useSyncRef, useObjectRef as $fcPuG$useObjectRef, mergeProps as $fcPuG$mergeProps, getOwnerWindow as $fcPuG$getOwnerWindow, isFocusable as $fcPuG$isFocusable, mergeRefs as $fcPuG$mergeRefs} from "@react-aria/utils";
5
- import $fcPuG$react, {useContext as $fcPuG$useContext, useRef as $fcPuG$useRef, useEffect as $fcPuG$useEffect, forwardRef as $fcPuG$forwardRef} from "react";
6
-
7
- /*
8
- * Copyright 2020 Adobe. All rights reserved.
9
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License. You may obtain a copy
11
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software distributed under
14
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
- * OF ANY KIND, either express or implied. See the License for the specific language
16
- * governing permissions and limitations under the License.
17
- */
18
-
19
-
20
-
21
-
22
- let $f645667febf57a63$export$f9762fab77588ecb = /*#__PURE__*/ (0, $fcPuG$react).createContext(null);
23
- function $f645667febf57a63$var$useFocusableContext(ref) {
24
- let context = (0, $fcPuG$useContext)($f645667febf57a63$export$f9762fab77588ecb) || {};
25
- (0, $fcPuG$useSyncRef)(context, ref);
26
- // eslint-disable-next-line
27
- let { ref: _, ...otherProps } = context;
28
- return otherProps;
29
- }
30
- const $f645667febf57a63$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, $fcPuG$react).forwardRef(function FocusableProvider(props, ref) {
31
- let { children: children, ...otherProps } = props;
32
- let objRef = (0, $fcPuG$useObjectRef)(ref);
33
- let context = {
34
- ...otherProps,
35
- ref: objRef
36
- };
37
- return /*#__PURE__*/ (0, $fcPuG$react).createElement($f645667febf57a63$export$f9762fab77588ecb.Provider, {
38
- value: context
39
- }, children);
40
- });
41
- function $f645667febf57a63$export$4c014de7c8940b4c(props, domRef) {
42
- let { focusProps: focusProps } = (0, $a1ea59d68270f0dd$export$f8168d8dd8fd66e6)(props);
43
- let { keyboardProps: keyboardProps } = (0, $46d819fcbaf35654$export$8f71654801c2f7cd)(props);
44
- let interactions = (0, $fcPuG$mergeProps)(focusProps, keyboardProps);
45
- let domProps = $f645667febf57a63$var$useFocusableContext(domRef);
46
- let interactionProps = props.isDisabled ? {} : domProps;
47
- let autoFocusRef = (0, $fcPuG$useRef)(props.autoFocus);
48
- (0, $fcPuG$useEffect)(()=>{
49
- if (autoFocusRef.current && domRef.current) (0, $3ad3f6e1647bc98d$export$80f3e147d781571c)(domRef.current);
50
- autoFocusRef.current = false;
51
- }, [
52
- domRef
53
- ]);
54
- // Always set a tabIndex so that Safari allows focusing native buttons and inputs.
55
- let tabIndex = props.excludeFromTabOrder ? -1 : 0;
56
- if (props.isDisabled) tabIndex = undefined;
57
- return {
58
- focusableProps: (0, $fcPuG$mergeProps)({
59
- ...interactions,
60
- tabIndex: tabIndex
61
- }, interactionProps)
62
- };
63
- }
64
- const $f645667febf57a63$export$35a3bebf7ef2d934 = /*#__PURE__*/ (0, $fcPuG$forwardRef)(({ children: children, ...props }, ref)=>{
65
- ref = (0, $fcPuG$useObjectRef)(ref);
66
- let { focusableProps: focusableProps } = $f645667febf57a63$export$4c014de7c8940b4c(props, ref);
67
- let child = (0, $fcPuG$react).Children.only(children);
68
- (0, $fcPuG$useEffect)(()=>{
69
- if (process.env.NODE_ENV === 'production') return;
70
- let el = ref.current;
71
- if (!el || !(el instanceof (0, $fcPuG$getOwnerWindow)(el).Element)) {
72
- console.error('<Focusable> child must forward its ref to a DOM element.');
73
- return;
74
- }
75
- if (!props.isDisabled && !(0, $fcPuG$isFocusable)(el)) {
76
- console.warn('<Focusable> child must be focusable. Please ensure the tabIndex prop is passed through.');
77
- return;
78
- }
79
- if (el.localName !== 'button' && el.localName !== 'input' && el.localName !== 'select' && el.localName !== 'textarea' && el.localName !== 'a' && el.localName !== 'area' && el.localName !== 'summary' && el.localName !== 'img' && el.localName !== 'svg') {
80
- let role = el.getAttribute('role');
81
- if (!role) console.warn('<Focusable> child must have an interactive ARIA role.');
82
- else if (// https://w3c.github.io/aria/#widget_roles
83
- role !== 'application' && role !== 'button' && role !== 'checkbox' && role !== 'combobox' && role !== 'gridcell' && role !== 'link' && role !== 'menuitem' && role !== 'menuitemcheckbox' && role !== 'menuitemradio' && role !== 'option' && role !== 'radio' && role !== 'searchbox' && role !== 'separator' && role !== 'slider' && role !== 'spinbutton' && role !== 'switch' && role !== 'tab' && role !== 'tabpanel' && role !== 'textbox' && role !== 'treeitem' && // aria-describedby is also announced on these roles
84
- role !== 'img' && role !== 'meter' && role !== 'progressbar') console.warn(`<Focusable> child must have an interactive ARIA role. Got "${role}".`);
85
- }
86
- }, [
87
- ref,
88
- props.isDisabled
89
- ]);
90
- // @ts-ignore
91
- let childRef = parseInt((0, $fcPuG$react).version, 10) < 19 ? child.ref : child.props.ref;
92
- return /*#__PURE__*/ (0, $fcPuG$react).cloneElement(child, {
93
- ...(0, $fcPuG$mergeProps)(focusableProps, child.props),
94
- // @ts-ignore
95
- ref: (0, $fcPuG$mergeRefs)(childRef, ref)
96
- });
97
- });
98
-
99
-
100
- export {$f645667febf57a63$export$f9762fab77588ecb as FocusableContext, $f645667febf57a63$export$13f3202a3e5ddd5 as FocusableProvider, $f645667febf57a63$export$4c014de7c8940b4c as useFocusable, $f645667febf57a63$export$35a3bebf7ef2d934 as Focusable};
101
- //# sourceMappingURL=useFocusable.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAyBM,IAAI,0DAAgE,CAAA,GAAA,YAAI,EAAE,aAAa,CAA+B;AAE7H,SAAS,0CAAoB,GAAuC;IAClE,IAAI,UAAU,CAAA,GAAA,iBAAS,EAAE,8CAAqB,CAAC;IAC/C,CAAA,GAAA,iBAAS,EAAE,SAAS;IAEpB,2BAA2B;IAC3B,IAAI,EAAC,KAAK,CAAC,EAAE,GAAG,YAAW,GAAG;IAC9B,OAAO;AACT;AAKO,MAAM,yDAEb,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC,SAAS,kBAAkB,KAA6B,EAAE,GAAmC;IAC5G,IAAI,YAAC,QAAQ,EAAE,GAAG,YAAW,GAAG;IAChC,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C3B;AAEJ","sources":["packages/@react-aria/interactions/src/useFocusable.tsx"],"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\nimport {DOMAttributes, FocusableDOMProps, FocusableElement, FocusableProps, RefObject} from '@react-types/shared';\nimport {focusSafely} from './';\nimport {getOwnerWindow, isFocusable, mergeProps, mergeRefs, useObjectRef, useSyncRef} from '@react-aria/utils';\nimport React, {ForwardedRef, forwardRef, MutableRefObject, ReactElement, ReactNode, useContext, useEffect, useRef} from 'react';\nimport {useFocus} from './useFocus';\nimport {useKeyboard} from './useKeyboard';\n\nexport interface FocusableOptions<T = FocusableElement> extends FocusableProps<T>, FocusableDOMProps {\n /** Whether focus should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusableProviderProps extends DOMAttributes {\n /** The child element to provide DOM props to. */\n children?: ReactNode\n}\n\ninterface FocusableContextValue extends FocusableProviderProps {\n ref?: MutableRefObject<FocusableElement | null>\n}\n\n// Exported for @react-aria/collections, which forwards this context.\n/** @private */\nexport let FocusableContext: React.Context<FocusableContextValue | null> = React.createContext<FocusableContextValue | null>(null);\n\nfunction useFocusableContext(ref: RefObject<FocusableElement | null>): FocusableContextValue {\n let context = useContext(FocusableContext) || {};\n useSyncRef(context, ref);\n\n // eslint-disable-next-line\n let {ref: _, ...otherProps} = context;\n return otherProps;\n}\n\n/**\n * Provides DOM props to the nearest focusable child.\n */\nexport const FocusableProvider:\n React.ForwardRefExoticComponent<FocusableProviderProps & React.RefAttributes<FocusableElement>> =\nReact.forwardRef(function FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {\n let {children, ...otherProps} = props;\n let objRef = useObjectRef(ref);\n let context = {\n ...otherProps,\n ref: objRef\n };\n\n return (\n <FocusableContext.Provider value={context}>\n {children}\n </FocusableContext.Provider>\n );\n});\n\nexport interface FocusableAria {\n /** Props for the focusable element. */\n focusableProps: DOMAttributes\n}\n\n/**\n * Used to make an element focusable and capable of auto focus.\n */\nexport function useFocusable<T extends FocusableElement = FocusableElement>(props: FocusableOptions<T>, domRef: RefObject<FocusableElement | null>): FocusableAria {\n let {focusProps} = useFocus(props);\n let {keyboardProps} = useKeyboard(props);\n let interactions = mergeProps(focusProps, keyboardProps);\n let domProps = useFocusableContext(domRef);\n let interactionProps = props.isDisabled ? {} : domProps;\n let autoFocusRef = useRef(props.autoFocus);\n\n useEffect(() => {\n if (autoFocusRef.current && domRef.current) {\n focusSafely(domRef.current);\n }\n autoFocusRef.current = false;\n }, [domRef]);\n\n // Always set a tabIndex so that Safari allows focusing native buttons and inputs.\n let tabIndex: number | undefined = props.excludeFromTabOrder ? -1 : 0;\n if (props.isDisabled) {\n tabIndex = undefined;\n }\n\n return {\n focusableProps: mergeProps(\n {\n ...interactions,\n tabIndex\n },\n interactionProps\n )\n };\n}\n\nexport interface FocusableComponentProps extends FocusableOptions {\n children: ReactElement<DOMAttributes, string>\n}\n\nexport const Focusable:\n React.ForwardRefExoticComponent<FocusableComponentProps & React.RefAttributes<FocusableElement>> =\nforwardRef(({children, ...props}: FocusableComponentProps, ref: ForwardedRef<FocusableElement>) => {\n ref = useObjectRef(ref);\n let {focusableProps} = useFocusable(props, ref);\n let child = React.Children.only(children);\n\n useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return;\n }\n\n let el = ref.current;\n if (!el || !(el instanceof getOwnerWindow(el).Element)) {\n console.error('<Focusable> child must forward its ref to a DOM element.');\n return;\n }\n\n if (!props.isDisabled && !isFocusable(el)) {\n console.warn('<Focusable> child must be focusable. Please ensure the tabIndex prop is passed through.');\n return;\n }\n\n if (\n el.localName !== 'button' &&\n el.localName !== 'input' &&\n el.localName !== 'select' &&\n el.localName !== 'textarea' &&\n el.localName !== 'a' &&\n el.localName !== 'area' &&\n el.localName !== 'summary' &&\n el.localName !== 'img' &&\n el.localName !== 'svg'\n ) {\n let role = el.getAttribute('role');\n if (!role) {\n console.warn('<Focusable> child must have an interactive ARIA role.');\n } else if (\n // https://w3c.github.io/aria/#widget_roles\n role !== 'application' &&\n role !== 'button' &&\n role !== 'checkbox' &&\n role !== 'combobox' &&\n role !== 'gridcell' &&\n role !== 'link' &&\n role !== 'menuitem' &&\n role !== 'menuitemcheckbox' &&\n role !== 'menuitemradio' &&\n role !== 'option' &&\n role !== 'radio' &&\n role !== 'searchbox' &&\n role !== 'separator' &&\n role !== 'slider' &&\n role !== 'spinbutton' &&\n role !== 'switch' &&\n role !== 'tab' &&\n role !== 'tabpanel' &&\n role !== 'textbox' &&\n role !== 'treeitem' &&\n // aria-describedby is also announced on these roles\n role !== 'img' &&\n role !== 'meter' &&\n role !== 'progressbar'\n ) {\n console.warn(`<Focusable> child must have an interactive ARIA role. Got \"${role}\".`);\n }\n }\n }, [ref, props.isDisabled]);\n\n // @ts-ignore\n let childRef = parseInt(React.version, 10) < 19 ? child.ref : child.props.ref;\n\n return React.cloneElement(\n child,\n {\n ...mergeProps(focusableProps, child.props),\n // @ts-ignore\n ref: mergeRefs(childRef, ref)\n }\n );\n});\n"],"names":[],"version":3,"file":"useFocusable.module.js.map"}
@@ -1,159 +0,0 @@
1
- var $82z6W$reactariautils = require("@react-aria/utils");
2
- var $82z6W$react = require("react");
3
-
4
-
5
- function $parcel$export(e, n, v, s) {
6
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
- }
8
-
9
- $parcel$export(module.exports, "useHover", () => $ffbc150311c75f01$export$ae780daf29e6d456);
10
- /*
11
- * Copyright 2020 Adobe. All rights reserved.
12
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License. You may obtain a copy
14
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software distributed under
17
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
- * OF ANY KIND, either express or implied. See the License for the specific language
19
- * governing permissions and limitations under the License.
20
- */ // Portions of the code in this file are based on code from react.
21
- // Original licensing for the following can be found in the
22
- // NOTICE file in the root directory of this source tree.
23
- // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
24
-
25
-
26
- // iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
27
- // We want to ignore these emulated events so they do not trigger hover behavior.
28
- // See https://bugs.webkit.org/show_bug.cgi?id=214609.
29
- let $ffbc150311c75f01$var$globalIgnoreEmulatedMouseEvents = false;
30
- let $ffbc150311c75f01$var$hoverCount = 0;
31
- function $ffbc150311c75f01$var$setGlobalIgnoreEmulatedMouseEvents() {
32
- $ffbc150311c75f01$var$globalIgnoreEmulatedMouseEvents = true;
33
- // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter
34
- // with pointerType="mouse" immediately after onPointerUp and before onFocus. On other
35
- // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in
36
- // the distant future because a user previously touched the element.
37
- setTimeout(()=>{
38
- $ffbc150311c75f01$var$globalIgnoreEmulatedMouseEvents = false;
39
- }, 50);
40
- }
41
- function $ffbc150311c75f01$var$handleGlobalPointerEvent(e) {
42
- if (e.pointerType === 'touch') $ffbc150311c75f01$var$setGlobalIgnoreEmulatedMouseEvents();
43
- }
44
- function $ffbc150311c75f01$var$setupGlobalTouchEvents() {
45
- if (typeof document === 'undefined') return;
46
- if ($ffbc150311c75f01$var$hoverCount === 0) {
47
- if (typeof PointerEvent !== 'undefined') document.addEventListener('pointerup', $ffbc150311c75f01$var$handleGlobalPointerEvent);
48
- else if (process.env.NODE_ENV === 'test') document.addEventListener('touchend', $ffbc150311c75f01$var$setGlobalIgnoreEmulatedMouseEvents);
49
- }
50
- $ffbc150311c75f01$var$hoverCount++;
51
- return ()=>{
52
- $ffbc150311c75f01$var$hoverCount--;
53
- if ($ffbc150311c75f01$var$hoverCount > 0) return;
54
- if (typeof PointerEvent !== 'undefined') document.removeEventListener('pointerup', $ffbc150311c75f01$var$handleGlobalPointerEvent);
55
- else if (process.env.NODE_ENV === 'test') document.removeEventListener('touchend', $ffbc150311c75f01$var$setGlobalIgnoreEmulatedMouseEvents);
56
- };
57
- }
58
- function $ffbc150311c75f01$export$ae780daf29e6d456(props) {
59
- let { onHoverStart: onHoverStart, onHoverChange: onHoverChange, onHoverEnd: onHoverEnd, isDisabled: isDisabled } = props;
60
- let [isHovered, setHovered] = (0, $82z6W$react.useState)(false);
61
- let state = (0, $82z6W$react.useRef)({
62
- isHovered: false,
63
- ignoreEmulatedMouseEvents: false,
64
- pointerType: '',
65
- target: null
66
- }).current;
67
- (0, $82z6W$react.useEffect)($ffbc150311c75f01$var$setupGlobalTouchEvents, []);
68
- let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $82z6W$reactariautils.useGlobalListeners)();
69
- let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $82z6W$react.useMemo)(()=>{
70
- let triggerHoverStart = (event, pointerType)=>{
71
- state.pointerType = pointerType;
72
- if (isDisabled || pointerType === 'touch' || state.isHovered || !(0, $82z6W$reactariautils.nodeContains)(event.currentTarget, event.target)) return;
73
- state.isHovered = true;
74
- let target = event.currentTarget;
75
- state.target = target;
76
- // When an element that is hovered over is removed, no pointerleave event is fired by the browser,
77
- // even though the originally hovered target may have shrunk in size so it is no longer hovered.
78
- // However, a pointerover event will be fired on the new target the mouse is over.
79
- // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.
80
- addGlobalListener((0, $82z6W$reactariautils.getOwnerDocument)(event.target), 'pointerover', (e)=>{
81
- if (state.isHovered && state.target && !(0, $82z6W$reactariautils.nodeContains)(state.target, e.target)) triggerHoverEnd(e, e.pointerType);
82
- }, {
83
- capture: true
84
- });
85
- if (onHoverStart) onHoverStart({
86
- type: 'hoverstart',
87
- target: target,
88
- pointerType: pointerType
89
- });
90
- if (onHoverChange) onHoverChange(true);
91
- setHovered(true);
92
- };
93
- let triggerHoverEnd = (event, pointerType)=>{
94
- let target = state.target;
95
- state.pointerType = '';
96
- state.target = null;
97
- if (pointerType === 'touch' || !state.isHovered || !target) return;
98
- state.isHovered = false;
99
- removeAllGlobalListeners();
100
- if (onHoverEnd) onHoverEnd({
101
- type: 'hoverend',
102
- target: target,
103
- pointerType: pointerType
104
- });
105
- if (onHoverChange) onHoverChange(false);
106
- setHovered(false);
107
- };
108
- let hoverProps = {};
109
- if (typeof PointerEvent !== 'undefined') {
110
- hoverProps.onPointerEnter = (e)=>{
111
- if ($ffbc150311c75f01$var$globalIgnoreEmulatedMouseEvents && e.pointerType === 'mouse') return;
112
- triggerHoverStart(e, e.pointerType);
113
- };
114
- hoverProps.onPointerLeave = (e)=>{
115
- if (!isDisabled && (0, $82z6W$reactariautils.nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, e.pointerType);
116
- };
117
- } else if (process.env.NODE_ENV === 'test') {
118
- hoverProps.onTouchStart = ()=>{
119
- state.ignoreEmulatedMouseEvents = true;
120
- };
121
- hoverProps.onMouseEnter = (e)=>{
122
- if (!state.ignoreEmulatedMouseEvents && !$ffbc150311c75f01$var$globalIgnoreEmulatedMouseEvents) triggerHoverStart(e, 'mouse');
123
- state.ignoreEmulatedMouseEvents = false;
124
- };
125
- hoverProps.onMouseLeave = (e)=>{
126
- if (!isDisabled && (0, $82z6W$reactariautils.nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, 'mouse');
127
- };
128
- }
129
- return {
130
- hoverProps: hoverProps,
131
- triggerHoverEnd: triggerHoverEnd
132
- };
133
- }, [
134
- onHoverStart,
135
- onHoverChange,
136
- onHoverEnd,
137
- isDisabled,
138
- state,
139
- addGlobalListener,
140
- removeAllGlobalListeners
141
- ]);
142
- (0, $82z6W$react.useEffect)(()=>{
143
- // Call the triggerHoverEnd as soon as isDisabled changes to true
144
- // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering
145
- if (isDisabled) triggerHoverEnd({
146
- currentTarget: state.target
147
- }, state.pointerType);
148
- // eslint-disable-next-line react-hooks/exhaustive-deps
149
- }, [
150
- isDisabled
151
- ]);
152
- return {
153
- hoverProps: hoverProps,
154
- isHovered: isHovered
155
- };
156
- }
157
-
158
-
159
- //# sourceMappingURL=useHover.main.js.map
@@ -1 +0,0 @@
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,iB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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 DELETED
@@ -1,154 +0,0 @@
1
- import {useGlobalListeners as $AWxnT$useGlobalListeners, nodeContains as $AWxnT$nodeContains, getOwnerDocument as $AWxnT$getOwnerDocument} from "@react-aria/utils";
2
- import {useState as $AWxnT$useState, useRef as $AWxnT$useRef, useEffect as $AWxnT$useEffect, useMemo as $AWxnT$useMemo} 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
- // iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
21
- // We want to ignore these emulated events so they do not trigger hover behavior.
22
- // See https://bugs.webkit.org/show_bug.cgi?id=214609.
23
- let $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
24
- let $6179b936705e76d3$var$hoverCount = 0;
25
- function $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents() {
26
- $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = true;
27
- // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter
28
- // with pointerType="mouse" immediately after onPointerUp and before onFocus. On other
29
- // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in
30
- // the distant future because a user previously touched the element.
31
- setTimeout(()=>{
32
- $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
33
- }, 50);
34
- }
35
- function $6179b936705e76d3$var$handleGlobalPointerEvent(e) {
36
- if (e.pointerType === 'touch') $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents();
37
- }
38
- function $6179b936705e76d3$var$setupGlobalTouchEvents() {
39
- if (typeof document === 'undefined') return;
40
- if ($6179b936705e76d3$var$hoverCount === 0) {
41
- if (typeof PointerEvent !== 'undefined') document.addEventListener('pointerup', $6179b936705e76d3$var$handleGlobalPointerEvent);
42
- else if (process.env.NODE_ENV === 'test') document.addEventListener('touchend', $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
43
- }
44
- $6179b936705e76d3$var$hoverCount++;
45
- return ()=>{
46
- $6179b936705e76d3$var$hoverCount--;
47
- if ($6179b936705e76d3$var$hoverCount > 0) return;
48
- if (typeof PointerEvent !== 'undefined') document.removeEventListener('pointerup', $6179b936705e76d3$var$handleGlobalPointerEvent);
49
- else if (process.env.NODE_ENV === 'test') document.removeEventListener('touchend', $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
50
- };
51
- }
52
- function $6179b936705e76d3$export$ae780daf29e6d456(props) {
53
- let { onHoverStart: onHoverStart, onHoverChange: onHoverChange, onHoverEnd: onHoverEnd, isDisabled: isDisabled } = props;
54
- let [isHovered, setHovered] = (0, $AWxnT$useState)(false);
55
- let state = (0, $AWxnT$useRef)({
56
- isHovered: false,
57
- ignoreEmulatedMouseEvents: false,
58
- pointerType: '',
59
- target: null
60
- }).current;
61
- (0, $AWxnT$useEffect)($6179b936705e76d3$var$setupGlobalTouchEvents, []);
62
- let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $AWxnT$useGlobalListeners)();
63
- let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $AWxnT$useMemo)(()=>{
64
- let triggerHoverStart = (event, pointerType)=>{
65
- state.pointerType = pointerType;
66
- if (isDisabled || pointerType === 'touch' || state.isHovered || !(0, $AWxnT$nodeContains)(event.currentTarget, event.target)) return;
67
- state.isHovered = true;
68
- let target = event.currentTarget;
69
- state.target = target;
70
- // When an element that is hovered over is removed, no pointerleave event is fired by the browser,
71
- // even though the originally hovered target may have shrunk in size so it is no longer hovered.
72
- // However, a pointerover event will be fired on the new target the mouse is over.
73
- // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.
74
- addGlobalListener((0, $AWxnT$getOwnerDocument)(event.target), 'pointerover', (e)=>{
75
- if (state.isHovered && state.target && !(0, $AWxnT$nodeContains)(state.target, e.target)) triggerHoverEnd(e, e.pointerType);
76
- }, {
77
- capture: true
78
- });
79
- if (onHoverStart) onHoverStart({
80
- type: 'hoverstart',
81
- target: target,
82
- pointerType: pointerType
83
- });
84
- if (onHoverChange) onHoverChange(true);
85
- setHovered(true);
86
- };
87
- let triggerHoverEnd = (event, pointerType)=>{
88
- let target = state.target;
89
- state.pointerType = '';
90
- state.target = null;
91
- if (pointerType === 'touch' || !state.isHovered || !target) return;
92
- state.isHovered = false;
93
- removeAllGlobalListeners();
94
- if (onHoverEnd) onHoverEnd({
95
- type: 'hoverend',
96
- target: target,
97
- pointerType: pointerType
98
- });
99
- if (onHoverChange) onHoverChange(false);
100
- setHovered(false);
101
- };
102
- let hoverProps = {};
103
- if (typeof PointerEvent !== 'undefined') {
104
- hoverProps.onPointerEnter = (e)=>{
105
- if ($6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents && e.pointerType === 'mouse') return;
106
- triggerHoverStart(e, e.pointerType);
107
- };
108
- hoverProps.onPointerLeave = (e)=>{
109
- if (!isDisabled && (0, $AWxnT$nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, e.pointerType);
110
- };
111
- } else if (process.env.NODE_ENV === 'test') {
112
- hoverProps.onTouchStart = ()=>{
113
- state.ignoreEmulatedMouseEvents = true;
114
- };
115
- hoverProps.onMouseEnter = (e)=>{
116
- if (!state.ignoreEmulatedMouseEvents && !$6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents) triggerHoverStart(e, 'mouse');
117
- state.ignoreEmulatedMouseEvents = false;
118
- };
119
- hoverProps.onMouseLeave = (e)=>{
120
- if (!isDisabled && (0, $AWxnT$nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, 'mouse');
121
- };
122
- }
123
- return {
124
- hoverProps: hoverProps,
125
- triggerHoverEnd: triggerHoverEnd
126
- };
127
- }, [
128
- onHoverStart,
129
- onHoverChange,
130
- onHoverEnd,
131
- isDisabled,
132
- state,
133
- addGlobalListener,
134
- removeAllGlobalListeners
135
- ]);
136
- (0, $AWxnT$useEffect)(()=>{
137
- // Call the triggerHoverEnd as soon as isDisabled changes to true
138
- // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering
139
- if (isDisabled) triggerHoverEnd({
140
- currentTarget: state.target
141
- }, state.pointerType);
142
- // eslint-disable-next-line react-hooks/exhaustive-deps
143
- }, [
144
- isDisabled
145
- ]);
146
- return {
147
- hoverProps: hoverProps,
148
- isHovered: isHovered
149
- };
150
- }
151
-
152
-
153
- export {$6179b936705e76d3$export$ae780daf29e6d456 as useHover};
154
- //# sourceMappingURL=useHover.module.js.map
@@ -1,154 +0,0 @@
1
- import {useGlobalListeners as $AWxnT$useGlobalListeners, nodeContains as $AWxnT$nodeContains, getOwnerDocument as $AWxnT$getOwnerDocument} from "@react-aria/utils";
2
- import {useState as $AWxnT$useState, useRef as $AWxnT$useRef, useEffect as $AWxnT$useEffect, useMemo as $AWxnT$useMemo} 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
- // iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
21
- // We want to ignore these emulated events so they do not trigger hover behavior.
22
- // See https://bugs.webkit.org/show_bug.cgi?id=214609.
23
- let $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
24
- let $6179b936705e76d3$var$hoverCount = 0;
25
- function $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents() {
26
- $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = true;
27
- // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter
28
- // with pointerType="mouse" immediately after onPointerUp and before onFocus. On other
29
- // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in
30
- // the distant future because a user previously touched the element.
31
- setTimeout(()=>{
32
- $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
33
- }, 50);
34
- }
35
- function $6179b936705e76d3$var$handleGlobalPointerEvent(e) {
36
- if (e.pointerType === 'touch') $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents();
37
- }
38
- function $6179b936705e76d3$var$setupGlobalTouchEvents() {
39
- if (typeof document === 'undefined') return;
40
- if ($6179b936705e76d3$var$hoverCount === 0) {
41
- if (typeof PointerEvent !== 'undefined') document.addEventListener('pointerup', $6179b936705e76d3$var$handleGlobalPointerEvent);
42
- else if (process.env.NODE_ENV === 'test') document.addEventListener('touchend', $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
43
- }
44
- $6179b936705e76d3$var$hoverCount++;
45
- return ()=>{
46
- $6179b936705e76d3$var$hoverCount--;
47
- if ($6179b936705e76d3$var$hoverCount > 0) return;
48
- if (typeof PointerEvent !== 'undefined') document.removeEventListener('pointerup', $6179b936705e76d3$var$handleGlobalPointerEvent);
49
- else if (process.env.NODE_ENV === 'test') document.removeEventListener('touchend', $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
50
- };
51
- }
52
- function $6179b936705e76d3$export$ae780daf29e6d456(props) {
53
- let { onHoverStart: onHoverStart, onHoverChange: onHoverChange, onHoverEnd: onHoverEnd, isDisabled: isDisabled } = props;
54
- let [isHovered, setHovered] = (0, $AWxnT$useState)(false);
55
- let state = (0, $AWxnT$useRef)({
56
- isHovered: false,
57
- ignoreEmulatedMouseEvents: false,
58
- pointerType: '',
59
- target: null
60
- }).current;
61
- (0, $AWxnT$useEffect)($6179b936705e76d3$var$setupGlobalTouchEvents, []);
62
- let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $AWxnT$useGlobalListeners)();
63
- let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $AWxnT$useMemo)(()=>{
64
- let triggerHoverStart = (event, pointerType)=>{
65
- state.pointerType = pointerType;
66
- if (isDisabled || pointerType === 'touch' || state.isHovered || !(0, $AWxnT$nodeContains)(event.currentTarget, event.target)) return;
67
- state.isHovered = true;
68
- let target = event.currentTarget;
69
- state.target = target;
70
- // When an element that is hovered over is removed, no pointerleave event is fired by the browser,
71
- // even though the originally hovered target may have shrunk in size so it is no longer hovered.
72
- // However, a pointerover event will be fired on the new target the mouse is over.
73
- // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.
74
- addGlobalListener((0, $AWxnT$getOwnerDocument)(event.target), 'pointerover', (e)=>{
75
- if (state.isHovered && state.target && !(0, $AWxnT$nodeContains)(state.target, e.target)) triggerHoverEnd(e, e.pointerType);
76
- }, {
77
- capture: true
78
- });
79
- if (onHoverStart) onHoverStart({
80
- type: 'hoverstart',
81
- target: target,
82
- pointerType: pointerType
83
- });
84
- if (onHoverChange) onHoverChange(true);
85
- setHovered(true);
86
- };
87
- let triggerHoverEnd = (event, pointerType)=>{
88
- let target = state.target;
89
- state.pointerType = '';
90
- state.target = null;
91
- if (pointerType === 'touch' || !state.isHovered || !target) return;
92
- state.isHovered = false;
93
- removeAllGlobalListeners();
94
- if (onHoverEnd) onHoverEnd({
95
- type: 'hoverend',
96
- target: target,
97
- pointerType: pointerType
98
- });
99
- if (onHoverChange) onHoverChange(false);
100
- setHovered(false);
101
- };
102
- let hoverProps = {};
103
- if (typeof PointerEvent !== 'undefined') {
104
- hoverProps.onPointerEnter = (e)=>{
105
- if ($6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents && e.pointerType === 'mouse') return;
106
- triggerHoverStart(e, e.pointerType);
107
- };
108
- hoverProps.onPointerLeave = (e)=>{
109
- if (!isDisabled && (0, $AWxnT$nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, e.pointerType);
110
- };
111
- } else if (process.env.NODE_ENV === 'test') {
112
- hoverProps.onTouchStart = ()=>{
113
- state.ignoreEmulatedMouseEvents = true;
114
- };
115
- hoverProps.onMouseEnter = (e)=>{
116
- if (!state.ignoreEmulatedMouseEvents && !$6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents) triggerHoverStart(e, 'mouse');
117
- state.ignoreEmulatedMouseEvents = false;
118
- };
119
- hoverProps.onMouseLeave = (e)=>{
120
- if (!isDisabled && (0, $AWxnT$nodeContains)(e.currentTarget, e.target)) triggerHoverEnd(e, 'mouse');
121
- };
122
- }
123
- return {
124
- hoverProps: hoverProps,
125
- triggerHoverEnd: triggerHoverEnd
126
- };
127
- }, [
128
- onHoverStart,
129
- onHoverChange,
130
- onHoverEnd,
131
- isDisabled,
132
- state,
133
- addGlobalListener,
134
- removeAllGlobalListeners
135
- ]);
136
- (0, $AWxnT$useEffect)(()=>{
137
- // Call the triggerHoverEnd as soon as isDisabled changes to true
138
- // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering
139
- if (isDisabled) triggerHoverEnd({
140
- currentTarget: state.target
141
- }, state.pointerType);
142
- // eslint-disable-next-line react-hooks/exhaustive-deps
143
- }, [
144
- isDisabled
145
- ]);
146
- return {
147
- hoverProps: hoverProps,
148
- isHovered: isHovered
149
- };
150
- }
151
-
152
-
153
- export {$6179b936705e76d3$export$ae780daf29e6d456 as useHover};
154
- //# sourceMappingURL=useHover.module.js.map
@@ -1 +0,0 @@
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,eAAO,EAAE;IACvC,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE;QACjB,WAAW;QACX,2BAA2B;QAC3B,aAAa;QACb,QAAQ;IACV,GAAG,OAAO;IAEV,CAAA,GAAA,gBAAQ,EAAE,8CAAwB,EAAE;IACpC,IAA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F,kBAAkB,GAAG,EAAE,WAAW;YACpC;YAEA,WAAW,cAAc,GAAG,CAAC;gBAC3B,IAAI,CAAC,cAAc,CAAA,GAAA,mBAAW,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,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"}