@react-aria/menu 3.20.0 → 3.22.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 (227) hide show
  1. package/dist/import.mjs +2 -10
  2. package/dist/main.js +6 -14
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +2 -10
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +2 -0
  7. package/package.json +15 -24
  8. package/src/index.ts +2 -11
  9. package/dist/ar-AE.main.js +0 -6
  10. package/dist/ar-AE.main.js.map +0 -1
  11. package/dist/ar-AE.mjs +0 -8
  12. package/dist/ar-AE.module.js +0 -8
  13. package/dist/ar-AE.module.js.map +0 -1
  14. package/dist/bg-BG.main.js +0 -6
  15. package/dist/bg-BG.main.js.map +0 -1
  16. package/dist/bg-BG.mjs +0 -8
  17. package/dist/bg-BG.module.js +0 -8
  18. package/dist/bg-BG.module.js.map +0 -1
  19. package/dist/cs-CZ.main.js +0 -6
  20. package/dist/cs-CZ.main.js.map +0 -1
  21. package/dist/cs-CZ.mjs +0 -8
  22. package/dist/cs-CZ.module.js +0 -8
  23. package/dist/cs-CZ.module.js.map +0 -1
  24. package/dist/da-DK.main.js +0 -6
  25. package/dist/da-DK.main.js.map +0 -1
  26. package/dist/da-DK.mjs +0 -8
  27. package/dist/da-DK.module.js +0 -8
  28. package/dist/da-DK.module.js.map +0 -1
  29. package/dist/de-DE.main.js +0 -6
  30. package/dist/de-DE.main.js.map +0 -1
  31. package/dist/de-DE.mjs +0 -8
  32. package/dist/de-DE.module.js +0 -8
  33. package/dist/de-DE.module.js.map +0 -1
  34. package/dist/el-GR.main.js +0 -6
  35. package/dist/el-GR.main.js.map +0 -1
  36. package/dist/el-GR.mjs +0 -8
  37. package/dist/el-GR.module.js +0 -8
  38. package/dist/el-GR.module.js.map +0 -1
  39. package/dist/en-US.main.js +0 -6
  40. package/dist/en-US.main.js.map +0 -1
  41. package/dist/en-US.mjs +0 -8
  42. package/dist/en-US.module.js +0 -8
  43. package/dist/en-US.module.js.map +0 -1
  44. package/dist/es-ES.main.js +0 -6
  45. package/dist/es-ES.main.js.map +0 -1
  46. package/dist/es-ES.mjs +0 -8
  47. package/dist/es-ES.module.js +0 -8
  48. package/dist/es-ES.module.js.map +0 -1
  49. package/dist/et-EE.main.js +0 -6
  50. package/dist/et-EE.main.js.map +0 -1
  51. package/dist/et-EE.mjs +0 -8
  52. package/dist/et-EE.module.js +0 -8
  53. package/dist/et-EE.module.js.map +0 -1
  54. package/dist/fi-FI.main.js +0 -6
  55. package/dist/fi-FI.main.js.map +0 -1
  56. package/dist/fi-FI.mjs +0 -8
  57. package/dist/fi-FI.module.js +0 -8
  58. package/dist/fi-FI.module.js.map +0 -1
  59. package/dist/fr-FR.main.js +0 -6
  60. package/dist/fr-FR.main.js.map +0 -1
  61. package/dist/fr-FR.mjs +0 -8
  62. package/dist/fr-FR.module.js +0 -8
  63. package/dist/fr-FR.module.js.map +0 -1
  64. package/dist/he-IL.main.js +0 -6
  65. package/dist/he-IL.main.js.map +0 -1
  66. package/dist/he-IL.mjs +0 -8
  67. package/dist/he-IL.module.js +0 -8
  68. package/dist/he-IL.module.js.map +0 -1
  69. package/dist/hr-HR.main.js +0 -6
  70. package/dist/hr-HR.main.js.map +0 -1
  71. package/dist/hr-HR.mjs +0 -8
  72. package/dist/hr-HR.module.js +0 -8
  73. package/dist/hr-HR.module.js.map +0 -1
  74. package/dist/hu-HU.main.js +0 -6
  75. package/dist/hu-HU.main.js.map +0 -1
  76. package/dist/hu-HU.mjs +0 -8
  77. package/dist/hu-HU.module.js +0 -8
  78. package/dist/hu-HU.module.js.map +0 -1
  79. package/dist/intlStrings.main.js +0 -108
  80. package/dist/intlStrings.main.js.map +0 -1
  81. package/dist/intlStrings.mjs +0 -110
  82. package/dist/intlStrings.module.js +0 -110
  83. package/dist/intlStrings.module.js.map +0 -1
  84. package/dist/it-IT.main.js +0 -6
  85. package/dist/it-IT.main.js.map +0 -1
  86. package/dist/it-IT.mjs +0 -8
  87. package/dist/it-IT.module.js +0 -8
  88. package/dist/it-IT.module.js.map +0 -1
  89. package/dist/ja-JP.main.js +0 -6
  90. package/dist/ja-JP.main.js.map +0 -1
  91. package/dist/ja-JP.mjs +0 -8
  92. package/dist/ja-JP.module.js +0 -8
  93. package/dist/ja-JP.module.js.map +0 -1
  94. package/dist/ko-KR.main.js +0 -6
  95. package/dist/ko-KR.main.js.map +0 -1
  96. package/dist/ko-KR.mjs +0 -8
  97. package/dist/ko-KR.module.js +0 -8
  98. package/dist/ko-KR.module.js.map +0 -1
  99. package/dist/lt-LT.main.js +0 -6
  100. package/dist/lt-LT.main.js.map +0 -1
  101. package/dist/lt-LT.mjs +0 -8
  102. package/dist/lt-LT.module.js +0 -8
  103. package/dist/lt-LT.module.js.map +0 -1
  104. package/dist/lv-LV.main.js +0 -6
  105. package/dist/lv-LV.main.js.map +0 -1
  106. package/dist/lv-LV.mjs +0 -8
  107. package/dist/lv-LV.module.js +0 -8
  108. package/dist/lv-LV.module.js.map +0 -1
  109. package/dist/nb-NO.main.js +0 -6
  110. package/dist/nb-NO.main.js.map +0 -1
  111. package/dist/nb-NO.mjs +0 -8
  112. package/dist/nb-NO.module.js +0 -8
  113. package/dist/nb-NO.module.js.map +0 -1
  114. package/dist/nl-NL.main.js +0 -6
  115. package/dist/nl-NL.main.js.map +0 -1
  116. package/dist/nl-NL.mjs +0 -8
  117. package/dist/nl-NL.module.js +0 -8
  118. package/dist/nl-NL.module.js.map +0 -1
  119. package/dist/pl-PL.main.js +0 -6
  120. package/dist/pl-PL.main.js.map +0 -1
  121. package/dist/pl-PL.mjs +0 -8
  122. package/dist/pl-PL.module.js +0 -8
  123. package/dist/pl-PL.module.js.map +0 -1
  124. package/dist/pt-BR.main.js +0 -6
  125. package/dist/pt-BR.main.js.map +0 -1
  126. package/dist/pt-BR.mjs +0 -8
  127. package/dist/pt-BR.module.js +0 -8
  128. package/dist/pt-BR.module.js.map +0 -1
  129. package/dist/pt-PT.main.js +0 -6
  130. package/dist/pt-PT.main.js.map +0 -1
  131. package/dist/pt-PT.mjs +0 -8
  132. package/dist/pt-PT.module.js +0 -8
  133. package/dist/pt-PT.module.js.map +0 -1
  134. package/dist/ro-RO.main.js +0 -6
  135. package/dist/ro-RO.main.js.map +0 -1
  136. package/dist/ro-RO.mjs +0 -8
  137. package/dist/ro-RO.module.js +0 -8
  138. package/dist/ro-RO.module.js.map +0 -1
  139. package/dist/ru-RU.main.js +0 -6
  140. package/dist/ru-RU.main.js.map +0 -1
  141. package/dist/ru-RU.mjs +0 -8
  142. package/dist/ru-RU.module.js +0 -8
  143. package/dist/ru-RU.module.js.map +0 -1
  144. package/dist/sk-SK.main.js +0 -6
  145. package/dist/sk-SK.main.js.map +0 -1
  146. package/dist/sk-SK.mjs +0 -8
  147. package/dist/sk-SK.module.js +0 -8
  148. package/dist/sk-SK.module.js.map +0 -1
  149. package/dist/sl-SI.main.js +0 -6
  150. package/dist/sl-SI.main.js.map +0 -1
  151. package/dist/sl-SI.mjs +0 -8
  152. package/dist/sl-SI.module.js +0 -8
  153. package/dist/sl-SI.module.js.map +0 -1
  154. package/dist/sr-SP.main.js +0 -6
  155. package/dist/sr-SP.main.js.map +0 -1
  156. package/dist/sr-SP.mjs +0 -8
  157. package/dist/sr-SP.module.js +0 -8
  158. package/dist/sr-SP.module.js.map +0 -1
  159. package/dist/sv-SE.main.js +0 -6
  160. package/dist/sv-SE.main.js.map +0 -1
  161. package/dist/sv-SE.mjs +0 -8
  162. package/dist/sv-SE.module.js +0 -8
  163. package/dist/sv-SE.module.js.map +0 -1
  164. package/dist/tr-TR.main.js +0 -6
  165. package/dist/tr-TR.main.js.map +0 -1
  166. package/dist/tr-TR.mjs +0 -8
  167. package/dist/tr-TR.module.js +0 -8
  168. package/dist/tr-TR.module.js.map +0 -1
  169. package/dist/types.d.ts +0 -191
  170. package/dist/types.d.ts.map +0 -1
  171. package/dist/uk-UA.main.js +0 -6
  172. package/dist/uk-UA.main.js.map +0 -1
  173. package/dist/uk-UA.mjs +0 -8
  174. package/dist/uk-UA.module.js +0 -8
  175. package/dist/uk-UA.module.js.map +0 -1
  176. package/dist/useMenu.main.js +0 -61
  177. package/dist/useMenu.main.js.map +0 -1
  178. package/dist/useMenu.mjs +0 -56
  179. package/dist/useMenu.module.js +0 -56
  180. package/dist/useMenu.module.js.map +0 -1
  181. package/dist/useMenuItem.main.js +0 -217
  182. package/dist/useMenuItem.main.js.map +0 -1
  183. package/dist/useMenuItem.mjs +0 -212
  184. package/dist/useMenuItem.module.js +0 -212
  185. package/dist/useMenuItem.module.js.map +0 -1
  186. package/dist/useMenuSection.main.js +0 -43
  187. package/dist/useMenuSection.main.js.map +0 -1
  188. package/dist/useMenuSection.mjs +0 -38
  189. package/dist/useMenuSection.module.js +0 -38
  190. package/dist/useMenuSection.module.js.map +0 -1
  191. package/dist/useMenuTrigger.main.js +0 -117
  192. package/dist/useMenuTrigger.main.js.map +0 -1
  193. package/dist/useMenuTrigger.mjs +0 -112
  194. package/dist/useMenuTrigger.module.js +0 -112
  195. package/dist/useMenuTrigger.module.js.map +0 -1
  196. package/dist/useSafelyMouseToSubmenu.main.js +0 -143
  197. package/dist/useSafelyMouseToSubmenu.main.js.map +0 -1
  198. package/dist/useSafelyMouseToSubmenu.mjs +0 -138
  199. package/dist/useSafelyMouseToSubmenu.module.js +0 -138
  200. package/dist/useSafelyMouseToSubmenu.module.js.map +0 -1
  201. package/dist/useSubmenuTrigger.main.js +0 -184
  202. package/dist/useSubmenuTrigger.main.js.map +0 -1
  203. package/dist/useSubmenuTrigger.mjs +0 -179
  204. package/dist/useSubmenuTrigger.module.js +0 -179
  205. package/dist/useSubmenuTrigger.module.js.map +0 -1
  206. package/dist/utils.main.js +0 -20
  207. package/dist/utils.main.js.map +0 -1
  208. package/dist/utils.mjs +0 -15
  209. package/dist/utils.module.js +0 -15
  210. package/dist/utils.module.js.map +0 -1
  211. package/dist/zh-CN.main.js +0 -6
  212. package/dist/zh-CN.main.js.map +0 -1
  213. package/dist/zh-CN.mjs +0 -8
  214. package/dist/zh-CN.module.js +0 -8
  215. package/dist/zh-CN.module.js.map +0 -1
  216. package/dist/zh-TW.main.js +0 -6
  217. package/dist/zh-TW.main.js.map +0 -1
  218. package/dist/zh-TW.mjs +0 -8
  219. package/dist/zh-TW.module.js +0 -8
  220. package/dist/zh-TW.module.js.map +0 -1
  221. package/src/useMenu.ts +0 -86
  222. package/src/useMenuItem.ts +0 -350
  223. package/src/useMenuSection.ts +0 -61
  224. package/src/useMenuTrigger.ts +0 -156
  225. package/src/useSafelyMouseToSubmenu.ts +0 -178
  226. package/src/useSubmenuTrigger.ts +0 -262
  227. package/src/utils.ts +0 -22
@@ -1,117 +0,0 @@
1
- var $d1742ec2644a0949$exports = require("./intlStrings.main.js");
2
- var $jo7gW$reactariautils = require("@react-aria/utils");
3
- var $jo7gW$reactariainteractions = require("@react-aria/interactions");
4
- var $jo7gW$reactariai18n = require("@react-aria/i18n");
5
- var $jo7gW$reactariaoverlays = require("@react-aria/overlays");
6
-
7
-
8
- function $parcel$interopDefault(a) {
9
- return a && a.__esModule ? a.default : a;
10
- }
11
-
12
- function $parcel$export(e, n, v, s) {
13
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
14
- }
15
-
16
- $parcel$export(module.exports, "useMenuTrigger", () => $7211ab9328763fb9$export$dc9c12ed27dd1b49);
17
- /*
18
- * Copyright 2020 Adobe. All rights reserved.
19
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
20
- * you may not use this file except in compliance with the License. You may obtain a copy
21
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
22
- *
23
- * Unless required by applicable law or agreed to in writing, software distributed under
24
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
25
- * OF ANY KIND, either express or implied. See the License for the specific language
26
- * governing permissions and limitations under the License.
27
- */
28
-
29
-
30
-
31
-
32
- function $7211ab9328763fb9$export$dc9c12ed27dd1b49(props, state, ref) {
33
- let { type: type = 'menu', isDisabled: isDisabled, trigger: trigger = 'press' } = props;
34
- let menuTriggerId = (0, $jo7gW$reactariautils.useId)();
35
- let { triggerProps: triggerProps, overlayProps: overlayProps } = (0, $jo7gW$reactariaoverlays.useOverlayTrigger)({
36
- type: type
37
- }, state, ref);
38
- let onKeyDown = (e)=>{
39
- if (isDisabled) return;
40
- if (trigger === 'longPress' && !e.altKey) return;
41
- if (ref && ref.current) switch(e.key){
42
- case 'Enter':
43
- case ' ':
44
- // React puts listeners on the same root, so even if propagation was stopped, immediate propagation is still possible.
45
- // useTypeSelect will handle the spacebar first if it's running, so we don't want to open if it's handled it already.
46
- // We use isDefaultPrevented() instead of isPropagationStopped() because createEventHandler stops propagation by default.
47
- // And default prevented means that the event was handled by something else (typeahead), so we don't want to open the menu.
48
- if (trigger === 'longPress' || e.isDefaultPrevented()) return;
49
- // fallthrough
50
- case 'ArrowDown':
51
- // Stop propagation, unless it would already be handled by useKeyboard.
52
- if (!('continuePropagation' in e)) e.stopPropagation();
53
- e.preventDefault();
54
- state.toggle('first');
55
- break;
56
- case 'ArrowUp':
57
- if (!('continuePropagation' in e)) e.stopPropagation();
58
- e.preventDefault();
59
- state.toggle('last');
60
- break;
61
- default:
62
- // Allow other keys.
63
- if ('continuePropagation' in e) e.continuePropagation();
64
- }
65
- };
66
- let stringFormatter = (0, $jo7gW$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($d1742ec2644a0949$exports))), '@react-aria/menu');
67
- let { longPressProps: longPressProps } = (0, $jo7gW$reactariainteractions.useLongPress)({
68
- isDisabled: isDisabled || trigger !== 'longPress',
69
- accessibilityDescription: stringFormatter.format('longPressMessage'),
70
- onLongPressStart () {
71
- state.close();
72
- },
73
- onLongPress () {
74
- state.open('first');
75
- }
76
- });
77
- let pressProps = {
78
- preventFocusOnPress: true,
79
- onPressStart (e) {
80
- // For consistency with native, open the menu on mouse/key down, but touch up.
81
- if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {
82
- // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.
83
- (0, $jo7gW$reactariautils.focusWithoutScrolling)(e.target);
84
- // If opened with a screen reader, auto focus the first item.
85
- // Otherwise, the menu itself will be focused.
86
- state.open(e.pointerType === 'virtual' ? 'first' : null);
87
- }
88
- },
89
- onPress (e) {
90
- if (e.pointerType === 'touch' && !isDisabled) {
91
- // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.
92
- (0, $jo7gW$reactariautils.focusWithoutScrolling)(e.target);
93
- state.toggle();
94
- }
95
- }
96
- };
97
- // omit onPress from triggerProps since we override it above.
98
- delete triggerProps.onPress;
99
- return {
100
- // @ts-ignore - TODO we pass out both DOMAttributes AND AriaButtonProps, but useButton will discard the longPress event handlers, it's only through PressResponder magic that this works for RSP and RAC. it does not work in aria examples
101
- menuTriggerProps: {
102
- ...triggerProps,
103
- ...trigger === 'press' ? pressProps : longPressProps,
104
- id: menuTriggerId,
105
- onKeyDown: onKeyDown
106
- },
107
- menuProps: {
108
- ...overlayProps,
109
- 'aria-labelledby': menuTriggerId,
110
- autoFocus: state.focusStrategy || true,
111
- onClose: state.close
112
- }
113
- };
114
- }
115
-
116
-
117
- //# sourceMappingURL=useMenuTrigger.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAqCM,SAAS,0CAAkB,KAA2B,EAAE,KAAuB,EAAE,GAA8B;IACpH,IAAI,QACF,OAAO,oBACP,UAAU,WACV,UAAU,SACX,GAAG;IAEJ,IAAI,gBAAgB,CAAA,GAAA,2BAAI;IACxB,IAAI,gBAAC,YAAY,gBAAE,YAAY,EAAC,GAAG,CAAA,GAAA,0CAAgB,EAAE;cAAC;IAAI,GAAG,OAAO;IAEpE,IAAI,YAAY,CAAC;QACf,IAAI,YACF;QAGF,IAAI,YAAY,eAAe,CAAC,EAAE,MAAM,EACtC;QAGF,IAAI,OAAO,IA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IACF;IAEA,6DAA6D;IAC7D,OAAO,aAAa,OAAO;IAE3B,OAAO;QACL,2OAA2O;QAC3O,kBAAkB;YAChB,GAAG,YAAY;YACf,GAAI,YAAY,UAAU,aAAa,cAAc;YACrD,IAAI;uBACJ;QACF;QACA,WAAW;YACT,GAAG,YAAY;YACf,mBAAmB;YACnB,WAAW,MAAM,aAAa,IAAI;YAClC,SAAS,MAAM,KAAK;QACtB;IACF;AACF","sources":["packages/@react-aria/menu/src/useMenuTrigger.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\nimport {AriaButtonProps} from '@react-types/button';\nimport {AriaMenuOptions} from './useMenu';\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, useId} from '@react-aria/utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {MenuTriggerState} from '@react-stately/menu';\nimport {MenuTriggerType} from '@react-types/menu';\nimport {PressProps, useLongPress} from '@react-aria/interactions';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useOverlayTrigger} from '@react-aria/overlays';\n\nexport interface AriaMenuTriggerProps {\n /** The type of menu that the menu trigger opens. */\n type?: 'menu' | 'listbox',\n /** Whether menu trigger is disabled. */\n isDisabled?: boolean,\n /** How menu is triggered. */\n trigger?: MenuTriggerType\n}\n\nexport interface MenuTriggerAria<T> {\n /** Props for the menu trigger element. */\n menuTriggerProps: AriaButtonProps,\n\n /** Props for the menu. */\n menuProps: AriaMenuOptions<T>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu trigger.\n * @param props - Props for the menu trigger.\n * @param state - State for the menu trigger.\n * @param ref - Ref to the HTML element trigger for the menu.\n */\nexport function useMenuTrigger<T>(props: AriaMenuTriggerProps, state: MenuTriggerState, ref: RefObject<Element | null>): MenuTriggerAria<T> {\n let {\n type = 'menu',\n isDisabled,\n trigger = 'press'\n } = props;\n\n let menuTriggerId = useId();\n let {triggerProps, overlayProps} = useOverlayTrigger({type}, state, ref);\n\n let onKeyDown = (e) => {\n if (isDisabled) {\n return;\n }\n\n if (trigger === 'longPress' && !e.altKey) {\n return;\n }\n\n if (ref && ref.current) {\n switch (e.key) {\n case 'Enter':\n case ' ':\n // React puts listeners on the same root, so even if propagation was stopped, immediate propagation is still possible.\n // useTypeSelect will handle the spacebar first if it's running, so we don't want to open if it's handled it already.\n // We use isDefaultPrevented() instead of isPropagationStopped() because createEventHandler stops propagation by default.\n // And default prevented means that the event was handled by something else (typeahead), so we don't want to open the menu.\n if (trigger === 'longPress' || e.isDefaultPrevented()) {\n return;\n }\n // fallthrough\n case 'ArrowDown':\n // Stop propagation, unless it would already be handled by useKeyboard.\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('first');\n break;\n case 'ArrowUp':\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('last');\n break;\n default:\n // Allow other keys.\n if ('continuePropagation' in e) {\n e.continuePropagation();\n }\n }\n }\n };\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/menu');\n let {longPressProps} = useLongPress({\n isDisabled: isDisabled || trigger !== 'longPress',\n accessibilityDescription: stringFormatter.format('longPressMessage'),\n onLongPressStart() {\n state.close();\n },\n onLongPress() {\n state.open('first');\n }\n });\n\n let pressProps: PressProps = {\n preventFocusOnPress: true,\n onPressStart(e) {\n // For consistency with native, open the menu on mouse/key down, but touch up.\n if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {\n // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.\n focusWithoutScrolling(e.target as FocusableElement);\n\n // If opened with a screen reader, auto focus the first item.\n // Otherwise, the menu itself will be focused.\n state.open(e.pointerType === 'virtual' ? 'first' : null);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch' && !isDisabled) {\n // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.\n focusWithoutScrolling(e.target as FocusableElement);\n\n state.toggle();\n }\n }\n };\n\n // omit onPress from triggerProps since we override it above.\n delete triggerProps.onPress;\n\n return {\n // @ts-ignore - TODO we pass out both DOMAttributes AND AriaButtonProps, but useButton will discard the longPress event handlers, it's only through PressResponder magic that this works for RSP and RAC. it does not work in aria examples\n menuTriggerProps: {\n ...triggerProps,\n ...(trigger === 'press' ? pressProps : longPressProps),\n id: menuTriggerId,\n onKeyDown\n },\n menuProps: {\n ...overlayProps,\n 'aria-labelledby': menuTriggerId,\n autoFocus: state.focusStrategy || true,\n onClose: state.close\n }\n };\n}\n"],"names":[],"version":3,"file":"useMenuTrigger.main.js.map"}
@@ -1,112 +0,0 @@
1
- import $czs6v$intlStringsmodulejs from "./intlStrings.mjs";
2
- import {useId as $czs6v$useId, focusWithoutScrolling as $czs6v$focusWithoutScrolling} from "@react-aria/utils";
3
- import {useLongPress as $czs6v$useLongPress} from "@react-aria/interactions";
4
- import {useLocalizedStringFormatter as $czs6v$useLocalizedStringFormatter} from "@react-aria/i18n";
5
- import {useOverlayTrigger as $czs6v$useOverlayTrigger} from "@react-aria/overlays";
6
-
7
-
8
- function $parcel$interopDefault(a) {
9
- return a && a.__esModule ? a.default : a;
10
- }
11
- /*
12
- * Copyright 2020 Adobe. All rights reserved.
13
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License. You may obtain a copy
15
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software distributed under
18
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
- * OF ANY KIND, either express or implied. See the License for the specific language
20
- * governing permissions and limitations under the License.
21
- */
22
-
23
-
24
-
25
-
26
- function $168583247155ddda$export$dc9c12ed27dd1b49(props, state, ref) {
27
- let { type: type = 'menu', isDisabled: isDisabled, trigger: trigger = 'press' } = props;
28
- let menuTriggerId = (0, $czs6v$useId)();
29
- let { triggerProps: triggerProps, overlayProps: overlayProps } = (0, $czs6v$useOverlayTrigger)({
30
- type: type
31
- }, state, ref);
32
- let onKeyDown = (e)=>{
33
- if (isDisabled) return;
34
- if (trigger === 'longPress' && !e.altKey) return;
35
- if (ref && ref.current) switch(e.key){
36
- case 'Enter':
37
- case ' ':
38
- // React puts listeners on the same root, so even if propagation was stopped, immediate propagation is still possible.
39
- // useTypeSelect will handle the spacebar first if it's running, so we don't want to open if it's handled it already.
40
- // We use isDefaultPrevented() instead of isPropagationStopped() because createEventHandler stops propagation by default.
41
- // And default prevented means that the event was handled by something else (typeahead), so we don't want to open the menu.
42
- if (trigger === 'longPress' || e.isDefaultPrevented()) return;
43
- // fallthrough
44
- case 'ArrowDown':
45
- // Stop propagation, unless it would already be handled by useKeyboard.
46
- if (!('continuePropagation' in e)) e.stopPropagation();
47
- e.preventDefault();
48
- state.toggle('first');
49
- break;
50
- case 'ArrowUp':
51
- if (!('continuePropagation' in e)) e.stopPropagation();
52
- e.preventDefault();
53
- state.toggle('last');
54
- break;
55
- default:
56
- // Allow other keys.
57
- if ('continuePropagation' in e) e.continuePropagation();
58
- }
59
- };
60
- let stringFormatter = (0, $czs6v$useLocalizedStringFormatter)((0, ($parcel$interopDefault($czs6v$intlStringsmodulejs))), '@react-aria/menu');
61
- let { longPressProps: longPressProps } = (0, $czs6v$useLongPress)({
62
- isDisabled: isDisabled || trigger !== 'longPress',
63
- accessibilityDescription: stringFormatter.format('longPressMessage'),
64
- onLongPressStart () {
65
- state.close();
66
- },
67
- onLongPress () {
68
- state.open('first');
69
- }
70
- });
71
- let pressProps = {
72
- preventFocusOnPress: true,
73
- onPressStart (e) {
74
- // For consistency with native, open the menu on mouse/key down, but touch up.
75
- if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {
76
- // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.
77
- (0, $czs6v$focusWithoutScrolling)(e.target);
78
- // If opened with a screen reader, auto focus the first item.
79
- // Otherwise, the menu itself will be focused.
80
- state.open(e.pointerType === 'virtual' ? 'first' : null);
81
- }
82
- },
83
- onPress (e) {
84
- if (e.pointerType === 'touch' && !isDisabled) {
85
- // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.
86
- (0, $czs6v$focusWithoutScrolling)(e.target);
87
- state.toggle();
88
- }
89
- }
90
- };
91
- // omit onPress from triggerProps since we override it above.
92
- delete triggerProps.onPress;
93
- return {
94
- // @ts-ignore - TODO we pass out both DOMAttributes AND AriaButtonProps, but useButton will discard the longPress event handlers, it's only through PressResponder magic that this works for RSP and RAC. it does not work in aria examples
95
- menuTriggerProps: {
96
- ...triggerProps,
97
- ...trigger === 'press' ? pressProps : longPressProps,
98
- id: menuTriggerId,
99
- onKeyDown: onKeyDown
100
- },
101
- menuProps: {
102
- ...overlayProps,
103
- 'aria-labelledby': menuTriggerId,
104
- autoFocus: state.focusStrategy || true,
105
- onClose: state.close
106
- }
107
- };
108
- }
109
-
110
-
111
- export {$168583247155ddda$export$dc9c12ed27dd1b49 as useMenuTrigger};
112
- //# sourceMappingURL=useMenuTrigger.module.js.map
@@ -1,112 +0,0 @@
1
- import $czs6v$intlStringsmodulejs from "./intlStrings.module.js";
2
- import {useId as $czs6v$useId, focusWithoutScrolling as $czs6v$focusWithoutScrolling} from "@react-aria/utils";
3
- import {useLongPress as $czs6v$useLongPress} from "@react-aria/interactions";
4
- import {useLocalizedStringFormatter as $czs6v$useLocalizedStringFormatter} from "@react-aria/i18n";
5
- import {useOverlayTrigger as $czs6v$useOverlayTrigger} from "@react-aria/overlays";
6
-
7
-
8
- function $parcel$interopDefault(a) {
9
- return a && a.__esModule ? a.default : a;
10
- }
11
- /*
12
- * Copyright 2020 Adobe. All rights reserved.
13
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License. You may obtain a copy
15
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software distributed under
18
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
- * OF ANY KIND, either express or implied. See the License for the specific language
20
- * governing permissions and limitations under the License.
21
- */
22
-
23
-
24
-
25
-
26
- function $168583247155ddda$export$dc9c12ed27dd1b49(props, state, ref) {
27
- let { type: type = 'menu', isDisabled: isDisabled, trigger: trigger = 'press' } = props;
28
- let menuTriggerId = (0, $czs6v$useId)();
29
- let { triggerProps: triggerProps, overlayProps: overlayProps } = (0, $czs6v$useOverlayTrigger)({
30
- type: type
31
- }, state, ref);
32
- let onKeyDown = (e)=>{
33
- if (isDisabled) return;
34
- if (trigger === 'longPress' && !e.altKey) return;
35
- if (ref && ref.current) switch(e.key){
36
- case 'Enter':
37
- case ' ':
38
- // React puts listeners on the same root, so even if propagation was stopped, immediate propagation is still possible.
39
- // useTypeSelect will handle the spacebar first if it's running, so we don't want to open if it's handled it already.
40
- // We use isDefaultPrevented() instead of isPropagationStopped() because createEventHandler stops propagation by default.
41
- // And default prevented means that the event was handled by something else (typeahead), so we don't want to open the menu.
42
- if (trigger === 'longPress' || e.isDefaultPrevented()) return;
43
- // fallthrough
44
- case 'ArrowDown':
45
- // Stop propagation, unless it would already be handled by useKeyboard.
46
- if (!('continuePropagation' in e)) e.stopPropagation();
47
- e.preventDefault();
48
- state.toggle('first');
49
- break;
50
- case 'ArrowUp':
51
- if (!('continuePropagation' in e)) e.stopPropagation();
52
- e.preventDefault();
53
- state.toggle('last');
54
- break;
55
- default:
56
- // Allow other keys.
57
- if ('continuePropagation' in e) e.continuePropagation();
58
- }
59
- };
60
- let stringFormatter = (0, $czs6v$useLocalizedStringFormatter)((0, ($parcel$interopDefault($czs6v$intlStringsmodulejs))), '@react-aria/menu');
61
- let { longPressProps: longPressProps } = (0, $czs6v$useLongPress)({
62
- isDisabled: isDisabled || trigger !== 'longPress',
63
- accessibilityDescription: stringFormatter.format('longPressMessage'),
64
- onLongPressStart () {
65
- state.close();
66
- },
67
- onLongPress () {
68
- state.open('first');
69
- }
70
- });
71
- let pressProps = {
72
- preventFocusOnPress: true,
73
- onPressStart (e) {
74
- // For consistency with native, open the menu on mouse/key down, but touch up.
75
- if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {
76
- // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.
77
- (0, $czs6v$focusWithoutScrolling)(e.target);
78
- // If opened with a screen reader, auto focus the first item.
79
- // Otherwise, the menu itself will be focused.
80
- state.open(e.pointerType === 'virtual' ? 'first' : null);
81
- }
82
- },
83
- onPress (e) {
84
- if (e.pointerType === 'touch' && !isDisabled) {
85
- // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.
86
- (0, $czs6v$focusWithoutScrolling)(e.target);
87
- state.toggle();
88
- }
89
- }
90
- };
91
- // omit onPress from triggerProps since we override it above.
92
- delete triggerProps.onPress;
93
- return {
94
- // @ts-ignore - TODO we pass out both DOMAttributes AND AriaButtonProps, but useButton will discard the longPress event handlers, it's only through PressResponder magic that this works for RSP and RAC. it does not work in aria examples
95
- menuTriggerProps: {
96
- ...triggerProps,
97
- ...trigger === 'press' ? pressProps : longPressProps,
98
- id: menuTriggerId,
99
- onKeyDown: onKeyDown
100
- },
101
- menuProps: {
102
- ...overlayProps,
103
- 'aria-labelledby': menuTriggerId,
104
- autoFocus: state.focusStrategy || true,
105
- onClose: state.close
106
- }
107
- };
108
- }
109
-
110
-
111
- export {$168583247155ddda$export$dc9c12ed27dd1b49 as useMenuTrigger};
112
- //# sourceMappingURL=useMenuTrigger.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAqCM,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AE,WAAW,KAAK,cAAc,CAAC,YAAY;gBAC5E,iGAAiG;gBACjG,CAAA,GAAA,4BAAoB,EAAE,EAAE,MAAM;gBAE9B,6DAA6D;gBAC7D,8CAA8C;gBAC9C,MAAM,IAAI,CAAC,EAAE,WAAW,KAAK,YAAY,UAAU;YACrD;QACF;QACA,SAAQ,CAAC;YACP,IAAI,EAAE,WAAW,KAAK,WAAW,CAAC,YAAY;gBAC5C,iGAAiG;gBACjG,CAAA,GAAA,4BAAoB,EAAE,EAAE,MAAM;gBAE9B,MAAM,MAAM;YACd;QACF;IACF;IAEA,6DAA6D;IAC7D,OAAO,aAAa,OAAO;IAE3B,OAAO;QACL,2OAA2O;QAC3O,kBAAkB;YAChB,GAAG,YAAY;YACf,GAAI,YAAY,UAAU,aAAa,cAAc;YACrD,IAAI;uBACJ;QACF;QACA,WAAW;YACT,GAAG,YAAY;YACf,mBAAmB;YACnB,WAAW,MAAM,aAAa,IAAI;YAClC,SAAS,MAAM,KAAK;QACtB;IACF;AACF","sources":["packages/@react-aria/menu/src/useMenuTrigger.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\nimport {AriaButtonProps} from '@react-types/button';\nimport {AriaMenuOptions} from './useMenu';\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, useId} from '@react-aria/utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {MenuTriggerState} from '@react-stately/menu';\nimport {MenuTriggerType} from '@react-types/menu';\nimport {PressProps, useLongPress} from '@react-aria/interactions';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useOverlayTrigger} from '@react-aria/overlays';\n\nexport interface AriaMenuTriggerProps {\n /** The type of menu that the menu trigger opens. */\n type?: 'menu' | 'listbox',\n /** Whether menu trigger is disabled. */\n isDisabled?: boolean,\n /** How menu is triggered. */\n trigger?: MenuTriggerType\n}\n\nexport interface MenuTriggerAria<T> {\n /** Props for the menu trigger element. */\n menuTriggerProps: AriaButtonProps,\n\n /** Props for the menu. */\n menuProps: AriaMenuOptions<T>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu trigger.\n * @param props - Props for the menu trigger.\n * @param state - State for the menu trigger.\n * @param ref - Ref to the HTML element trigger for the menu.\n */\nexport function useMenuTrigger<T>(props: AriaMenuTriggerProps, state: MenuTriggerState, ref: RefObject<Element | null>): MenuTriggerAria<T> {\n let {\n type = 'menu',\n isDisabled,\n trigger = 'press'\n } = props;\n\n let menuTriggerId = useId();\n let {triggerProps, overlayProps} = useOverlayTrigger({type}, state, ref);\n\n let onKeyDown = (e) => {\n if (isDisabled) {\n return;\n }\n\n if (trigger === 'longPress' && !e.altKey) {\n return;\n }\n\n if (ref && ref.current) {\n switch (e.key) {\n case 'Enter':\n case ' ':\n // React puts listeners on the same root, so even if propagation was stopped, immediate propagation is still possible.\n // useTypeSelect will handle the spacebar first if it's running, so we don't want to open if it's handled it already.\n // We use isDefaultPrevented() instead of isPropagationStopped() because createEventHandler stops propagation by default.\n // And default prevented means that the event was handled by something else (typeahead), so we don't want to open the menu.\n if (trigger === 'longPress' || e.isDefaultPrevented()) {\n return;\n }\n // fallthrough\n case 'ArrowDown':\n // Stop propagation, unless it would already be handled by useKeyboard.\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('first');\n break;\n case 'ArrowUp':\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('last');\n break;\n default:\n // Allow other keys.\n if ('continuePropagation' in e) {\n e.continuePropagation();\n }\n }\n }\n };\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/menu');\n let {longPressProps} = useLongPress({\n isDisabled: isDisabled || trigger !== 'longPress',\n accessibilityDescription: stringFormatter.format('longPressMessage'),\n onLongPressStart() {\n state.close();\n },\n onLongPress() {\n state.open('first');\n }\n });\n\n let pressProps: PressProps = {\n preventFocusOnPress: true,\n onPressStart(e) {\n // For consistency with native, open the menu on mouse/key down, but touch up.\n if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {\n // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.\n focusWithoutScrolling(e.target as FocusableElement);\n\n // If opened with a screen reader, auto focus the first item.\n // Otherwise, the menu itself will be focused.\n state.open(e.pointerType === 'virtual' ? 'first' : null);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch' && !isDisabled) {\n // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.\n focusWithoutScrolling(e.target as FocusableElement);\n\n state.toggle();\n }\n }\n };\n\n // omit onPress from triggerProps since we override it above.\n delete triggerProps.onPress;\n\n return {\n // @ts-ignore - TODO we pass out both DOMAttributes AND AriaButtonProps, but useButton will discard the longPress event handlers, it's only through PressResponder magic that this works for RSP and RAC. it does not work in aria examples\n menuTriggerProps: {\n ...triggerProps,\n ...(trigger === 'press' ? pressProps : longPressProps),\n id: menuTriggerId,\n onKeyDown\n },\n menuProps: {\n ...overlayProps,\n 'aria-labelledby': menuTriggerId,\n autoFocus: state.focusStrategy || true,\n onClose: state.close\n }\n };\n}\n"],"names":[],"version":3,"file":"useMenuTrigger.module.js.map"}
@@ -1,143 +0,0 @@
1
- var $g3RPq$reactariautils = require("@react-aria/utils");
2
- var $g3RPq$react = require("react");
3
- var $g3RPq$reactariainteractions = require("@react-aria/interactions");
4
-
5
-
6
- function $parcel$export(e, n, v, s) {
7
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
- }
9
-
10
- $parcel$export(module.exports, "useSafelyMouseToSubmenu", () => $62347d8c4183e713$export$85ec83e04c95f50a);
11
-
12
-
13
-
14
- const $62347d8c4183e713$var$ALLOWED_INVALID_MOVEMENTS = 2;
15
- const $62347d8c4183e713$var$THROTTLE_TIME = 50;
16
- const $62347d8c4183e713$var$TIMEOUT_TIME = 1000;
17
- const $62347d8c4183e713$var$ANGLE_PADDING = Math.PI / 12; // 15°
18
- function $62347d8c4183e713$export$85ec83e04c95f50a(options) {
19
- let { menuRef: menuRef, submenuRef: submenuRef, isOpen: isOpen, isDisabled: isDisabled } = options;
20
- let prevPointerPos = (0, $g3RPq$react.useRef)(undefined);
21
- let submenuRect = (0, $g3RPq$react.useRef)(undefined);
22
- let lastProcessedTime = (0, $g3RPq$react.useRef)(0);
23
- let timeout = (0, $g3RPq$react.useRef)(undefined);
24
- let autoCloseTimeout = (0, $g3RPq$react.useRef)(undefined);
25
- let submenuSide = (0, $g3RPq$react.useRef)(undefined);
26
- let movementsTowardsSubmenuCount = (0, $g3RPq$react.useRef)(2);
27
- let [preventPointerEvents, setPreventPointerEvents] = (0, $g3RPq$react.useState)(false);
28
- let updateSubmenuRect = ()=>{
29
- if (submenuRef.current) {
30
- submenuRect.current = submenuRef.current.getBoundingClientRect();
31
- submenuSide.current = undefined;
32
- }
33
- };
34
- (0, $g3RPq$reactariautils.useResizeObserver)({
35
- ref: submenuRef,
36
- onResize: updateSubmenuRect
37
- });
38
- let reset = ()=>{
39
- setPreventPointerEvents(false);
40
- movementsTowardsSubmenuCount.current = $62347d8c4183e713$var$ALLOWED_INVALID_MOVEMENTS;
41
- prevPointerPos.current = undefined;
42
- };
43
- let modality = (0, $g3RPq$reactariainteractions.useInteractionModality)();
44
- // Prevent mouse down over safe triangle. Clicking while pointer-events: none is applied
45
- // will cause focus to move unexpectedly since it will go to an element behind the menu.
46
- let onPointerDown = (0, $g3RPq$reactariautils.useEffectEvent)((e)=>{
47
- if (preventPointerEvents) e.preventDefault();
48
- });
49
- (0, $g3RPq$react.useEffect)(()=>{
50
- if (preventPointerEvents && menuRef.current) menuRef.current.style.pointerEvents = 'none';
51
- else menuRef.current.style.pointerEvents = '';
52
- }, [
53
- menuRef,
54
- preventPointerEvents
55
- ]);
56
- (0, $g3RPq$reactariautils.useLayoutEffect)(()=>{
57
- let submenu = submenuRef.current;
58
- let menu = menuRef.current;
59
- if (isDisabled || !submenu || !isOpen || modality !== 'pointer' || !menu) {
60
- reset();
61
- return;
62
- }
63
- submenuRect.current = submenu.getBoundingClientRect();
64
- let onPointerMove = (e)=>{
65
- if (e.pointerType === 'touch' || e.pointerType === 'pen') return;
66
- let currentTime = Date.now();
67
- // Throttle
68
- if (currentTime - lastProcessedTime.current < $62347d8c4183e713$var$THROTTLE_TIME) return;
69
- clearTimeout(timeout.current);
70
- clearTimeout(autoCloseTimeout.current);
71
- let { clientX: mouseX, clientY: mouseY } = e;
72
- if (!prevPointerPos.current) {
73
- prevPointerPos.current = {
74
- x: mouseX,
75
- y: mouseY
76
- };
77
- return;
78
- }
79
- if (!submenuRect.current) return;
80
- if (!submenuSide.current) submenuSide.current = mouseX > submenuRect.current.right ? 'left' : 'right';
81
- // Pointer is outside of parent menu
82
- if (mouseX < menu.getBoundingClientRect().left || mouseX > menu.getBoundingClientRect().right || mouseY < menu.getBoundingClientRect().top || mouseY > menu.getBoundingClientRect().bottom) {
83
- reset();
84
- return;
85
- }
86
- /* Check if pointer is moving towards submenu.
87
- Uses the 2-argument arctangent (https://en.wikipedia.org/wiki/Atan2) to calculate:
88
- - angle between previous pointer and top of submenu
89
- - angle between previous pointer and bottom of submenu
90
- - angle between previous pointer and current pointer (delta)
91
- If the pointer delta angle value is between the top and bottom angle values, we know the pointer is moving towards the submenu.
92
- */ let prevMouseX = prevPointerPos.current.x;
93
- let prevMouseY = prevPointerPos.current.y;
94
- let toSubmenuX = submenuSide.current === 'right' ? submenuRect.current.left - prevMouseX : prevMouseX - submenuRect.current.right;
95
- let angleTop = Math.atan2(prevMouseY - submenuRect.current.top, toSubmenuX) + $62347d8c4183e713$var$ANGLE_PADDING;
96
- let angleBottom = Math.atan2(prevMouseY - submenuRect.current.bottom, toSubmenuX) - $62347d8c4183e713$var$ANGLE_PADDING;
97
- let anglePointer = Math.atan2(prevMouseY - mouseY, submenuSide.current === 'left' ? -(mouseX - prevMouseX) : mouseX - prevMouseX);
98
- let isMovingTowardsSubmenu = anglePointer < angleTop && anglePointer > angleBottom;
99
- movementsTowardsSubmenuCount.current = isMovingTowardsSubmenu ? Math.min(movementsTowardsSubmenuCount.current + 1, $62347d8c4183e713$var$ALLOWED_INVALID_MOVEMENTS) : Math.max(movementsTowardsSubmenuCount.current - 1, 0);
100
- if (movementsTowardsSubmenuCount.current >= $62347d8c4183e713$var$ALLOWED_INVALID_MOVEMENTS) setPreventPointerEvents(true);
101
- else setPreventPointerEvents(false);
102
- lastProcessedTime.current = currentTime;
103
- prevPointerPos.current = {
104
- x: mouseX,
105
- y: mouseY
106
- };
107
- // If the pointer is moving towards the submenu, start a timeout to close if no other movements are made after 500ms.
108
- if (isMovingTowardsSubmenu) timeout.current = setTimeout(()=>{
109
- reset();
110
- autoCloseTimeout.current = setTimeout(()=>{
111
- // Fire a pointerover event to trigger the menu to close.
112
- // Wait until pointer-events:none is no longer applied
113
- let target = document.elementFromPoint(mouseX, mouseY);
114
- if (target && (0, $g3RPq$reactariautils.nodeContains)(menu, target)) target.dispatchEvent(new PointerEvent('pointerover', {
115
- bubbles: true,
116
- cancelable: true
117
- }));
118
- }, 100);
119
- }, $62347d8c4183e713$var$TIMEOUT_TIME);
120
- };
121
- window.addEventListener('pointermove', onPointerMove);
122
- // Prevent pointer down over the safe triangle. See above comment.
123
- // Do not enable in tests, because JSDom doesn't do hit testing.
124
- if (process.env.NODE_ENV !== 'test') window.addEventListener('pointerdown', onPointerDown, true);
125
- return ()=>{
126
- window.removeEventListener('pointermove', onPointerMove);
127
- if (process.env.NODE_ENV !== 'test') window.removeEventListener('pointerdown', onPointerDown, true);
128
- clearTimeout(timeout.current);
129
- clearTimeout(autoCloseTimeout.current);
130
- movementsTowardsSubmenuCount.current = $62347d8c4183e713$var$ALLOWED_INVALID_MOVEMENTS;
131
- };
132
- }, [
133
- isDisabled,
134
- isOpen,
135
- menuRef,
136
- modality,
137
- setPreventPointerEvents,
138
- submenuRef
139
- ]);
140
- }
141
-
142
-
143
- //# sourceMappingURL=useSafelyMouseToSubmenu.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;;AAiBA,MAAM,kDAA4B;AAClC,MAAM,sCAAgB;AACtB,MAAM,qCAAe;AACrB,MAAM,sCAAgB,KAAK,EAAE,GAAG,IAAI,MAAM;AAMnC,SAAS,0CAAwB,OAAoC;IAC1E,IAAI,WAAC,OAAO,cAAE,UAAU,UAAE,MAAM,cAAE,UAAU,EAAC,GAAG;IAChD,IAAI,iBAAiB,CAAA,GAAA,mBAAK,EAAsC;IAChE,IAAI,cAAc,CAAA,GAAA,mBAAK,EAAuB;IAC9C,IAAI,oBAAoB,CAAA,GAAA,mBAAK,EAAU;IACvC,IAAI,UAAU,CAAA,GAAA,mBAAK,EAA6C;IAChE,IAAI,mBAAmB,CAAA,GAAA,mBAAK,EAA6C;IACzE,IAAI,cAAc,CAAA,GAAA,mBAAK,EAAgC;IACvD,IAAI,+BAA+B,CAAA,GAAA,mBAAK,EAAU;IAClD,IAAI,CAAC,sBAAsB,wBAAwB,GAAG,CAAA,GAAA,qBAAO,EAAE;IAE/D,IAAI,oBAAoB;QACtB,IAAI,WAAW,OAAO,EAAE;YACtB,YAAY,OAAO,GAAG,WAAW,OAAO,CAAC,qBAAqB;YAC9D,YAAY,OAAO,GAAG;QACxB;IACF;IACA,CAAA,GAAA,uCAAgB,EAAE;QAAC,KAAK;QAAY,UAAU;IAAiB;IAE/D,IAAI,QAAQ;QACV,wBAAwB;QACxB,6BAA6B,OAAO,GAAG;QACvC,eAAe,OAAO,GAAG;IAC3B;IAEA,IAAI,WAAW,CAAA,GAAA,mDAAqB;IAEpC,wFAAwF;IACxF,wFAAwF;IACx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AG,CAAC,QAAQ,KAAK,QAC3B,OAAO,gBAAgB,CAAC,eAAe,eAAe;QAGxD,OAAO;YACL,OAAO,mBAAmB,CAAC,eAAe;YAC1C,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,QAC3B,OAAO,mBAAmB,CAAC,eAAe,eAAe;YAE3D,aAAa,QAAQ,OAAO;YAC5B,aAAa,iBAAiB,OAAO;YACrC,6BAA6B,OAAO,GAAG;QACzC;IAEF,GAAG;QAAC;QAAY;QAAQ;QAAS;QAAU;QAAyB;KAAW;AACjF","sources":["packages/@react-aria/menu/src/useSafelyMouseToSubmenu.ts"],"sourcesContent":["\nimport {nodeContains, useEffectEvent, useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {RefObject} from '@react-types/shared';\nimport {useEffect, useRef, useState} from 'react';\nimport {useInteractionModality} from '@react-aria/interactions';\n\ninterface SafelyMouseToSubmenuOptions {\n /** Ref for the parent menu. */\n menuRef: RefObject<Element | null>,\n /** Ref for the submenu. */\n submenuRef: RefObject<Element | null>,\n /** Whether the submenu is open. */\n isOpen: boolean,\n /** Whether this feature is disabled. */\n isDisabled?: boolean\n}\n\nconst ALLOWED_INVALID_MOVEMENTS = 2;\nconst THROTTLE_TIME = 50;\nconst TIMEOUT_TIME = 1000;\nconst ANGLE_PADDING = Math.PI / 12; // 15°\n\n/**\n * Allows the user to move their pointer to the submenu without it closing when their mouse leaves the trigger element.\n * Prevents pointer events from going to the underlying menu if the user is moving their pointer towards the sub-menu.\n */\nexport function useSafelyMouseToSubmenu(options: SafelyMouseToSubmenuOptions): void {\n let {menuRef, submenuRef, isOpen, isDisabled} = options;\n let prevPointerPos = useRef<{x: number, y: number} | undefined>(undefined);\n let submenuRect = useRef<DOMRect | undefined>(undefined);\n let lastProcessedTime = useRef<number>(0);\n let timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let autoCloseTimeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let submenuSide = useRef<'left' | 'right' | undefined>(undefined);\n let movementsTowardsSubmenuCount = useRef<number>(2);\n let [preventPointerEvents, setPreventPointerEvents] = useState(false);\n\n let updateSubmenuRect = () => {\n if (submenuRef.current) {\n submenuRect.current = submenuRef.current.getBoundingClientRect();\n submenuSide.current = undefined;\n }\n };\n useResizeObserver({ref: submenuRef, onResize: updateSubmenuRect});\n\n let reset = () => {\n setPreventPointerEvents(false);\n movementsTowardsSubmenuCount.current = ALLOWED_INVALID_MOVEMENTS;\n prevPointerPos.current = undefined;\n };\n\n let modality = useInteractionModality();\n\n // Prevent mouse down over safe triangle. Clicking while pointer-events: none is applied\n // will cause focus to move unexpectedly since it will go to an element behind the menu.\n let onPointerDown = useEffectEvent((e: PointerEvent) => {\n if (preventPointerEvents) {\n e.preventDefault();\n }\n });\n\n useEffect(() => {\n if (preventPointerEvents && menuRef.current) {\n (menuRef.current as HTMLElement).style.pointerEvents = 'none';\n } else {\n (menuRef.current as HTMLElement).style.pointerEvents = '';\n }\n }, [menuRef, preventPointerEvents]);\n\n useLayoutEffect(() => {\n let submenu = submenuRef.current;\n let menu = menuRef.current;\n\n if (isDisabled || !submenu || !isOpen || modality !== 'pointer' || !menu) {\n reset();\n return;\n }\n submenuRect.current = submenu.getBoundingClientRect();\n\n let onPointerMove = (e: PointerEvent) => {\n if (e.pointerType === 'touch' || e.pointerType === 'pen') {\n return;\n }\n\n let currentTime = Date.now();\n\n // Throttle\n if (currentTime - lastProcessedTime.current < THROTTLE_TIME) {\n return;\n }\n clearTimeout(timeout.current);\n clearTimeout(autoCloseTimeout.current);\n\n let {clientX: mouseX, clientY: mouseY} = e;\n\n if (!prevPointerPos.current) {\n prevPointerPos.current = {x: mouseX, y: mouseY};\n return;\n }\n\n if (!submenuRect.current) {\n return;\n }\n\n if (!submenuSide.current) {\n submenuSide.current = mouseX > submenuRect.current.right ? 'left' : 'right';\n }\n\n // Pointer is outside of parent menu\n if (mouseX < menu.getBoundingClientRect().left || mouseX > menu.getBoundingClientRect().right || mouseY < menu.getBoundingClientRect().top || mouseY > menu.getBoundingClientRect().bottom) {\n reset();\n return;\n }\n\n /* Check if pointer is moving towards submenu.\n Uses the 2-argument arctangent (https://en.wikipedia.org/wiki/Atan2) to calculate:\n - angle between previous pointer and top of submenu\n - angle between previous pointer and bottom of submenu\n - angle between previous pointer and current pointer (delta)\n If the pointer delta angle value is between the top and bottom angle values, we know the pointer is moving towards the submenu.\n */\n let prevMouseX = prevPointerPos.current.x;\n let prevMouseY = prevPointerPos.current.y;\n let toSubmenuX = submenuSide.current === 'right' ? submenuRect.current.left - prevMouseX : prevMouseX - submenuRect.current.right;\n let angleTop = Math.atan2(prevMouseY - submenuRect.current.top, toSubmenuX) + ANGLE_PADDING;\n let angleBottom = Math.atan2(prevMouseY - submenuRect.current.bottom, toSubmenuX) - ANGLE_PADDING;\n let anglePointer = Math.atan2(prevMouseY - mouseY, (submenuSide.current === 'left' ? -(mouseX - prevMouseX) : mouseX - prevMouseX));\n let isMovingTowardsSubmenu = anglePointer < angleTop && anglePointer > angleBottom;\n\n movementsTowardsSubmenuCount.current = isMovingTowardsSubmenu ?\n Math.min(movementsTowardsSubmenuCount.current + 1, ALLOWED_INVALID_MOVEMENTS) :\n Math.max(movementsTowardsSubmenuCount.current - 1, 0);\n\n if (movementsTowardsSubmenuCount.current >= ALLOWED_INVALID_MOVEMENTS) {\n setPreventPointerEvents(true);\n } else {\n setPreventPointerEvents(false);\n }\n\n lastProcessedTime.current = currentTime;\n prevPointerPos.current = {x: mouseX, y: mouseY};\n\n // If the pointer is moving towards the submenu, start a timeout to close if no other movements are made after 500ms.\n if (isMovingTowardsSubmenu) {\n timeout.current = setTimeout(() => {\n reset();\n autoCloseTimeout.current = setTimeout(() => {\n // Fire a pointerover event to trigger the menu to close.\n // Wait until pointer-events:none is no longer applied\n let target = document.elementFromPoint(mouseX, mouseY);\n if (target && nodeContains(menu, target)) {\n target.dispatchEvent(new PointerEvent('pointerover', {bubbles: true, cancelable: true}));\n }\n }, 100);\n }, TIMEOUT_TIME);\n }\n };\n\n window.addEventListener('pointermove', onPointerMove);\n\n // Prevent pointer down over the safe triangle. See above comment.\n // Do not enable in tests, because JSDom doesn't do hit testing.\n if (process.env.NODE_ENV !== 'test') {\n window.addEventListener('pointerdown', onPointerDown, true);\n }\n\n return () => {\n window.removeEventListener('pointermove', onPointerMove);\n if (process.env.NODE_ENV !== 'test') {\n window.removeEventListener('pointerdown', onPointerDown, true);\n }\n clearTimeout(timeout.current);\n clearTimeout(autoCloseTimeout.current);\n movementsTowardsSubmenuCount.current = ALLOWED_INVALID_MOVEMENTS;\n };\n\n }, [isDisabled, isOpen, menuRef, modality, setPreventPointerEvents, submenuRef]);\n}\n"],"names":[],"version":3,"file":"useSafelyMouseToSubmenu.main.js.map"}