@react-aria/menu 3.0.0-alpha.1 → 3.0.0-nightly-4980928d3-240906

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 (222) hide show
  1. package/README.md +1 -1
  2. package/dist/ar-AE.main.js +6 -0
  3. package/dist/ar-AE.main.js.map +1 -0
  4. package/dist/ar-AE.mjs +8 -0
  5. package/dist/ar-AE.module.js +8 -0
  6. package/dist/ar-AE.module.js.map +1 -0
  7. package/dist/bg-BG.main.js +6 -0
  8. package/dist/bg-BG.main.js.map +1 -0
  9. package/dist/bg-BG.mjs +8 -0
  10. package/dist/bg-BG.module.js +8 -0
  11. package/dist/bg-BG.module.js.map +1 -0
  12. package/dist/cs-CZ.main.js +6 -0
  13. package/dist/cs-CZ.main.js.map +1 -0
  14. package/dist/cs-CZ.mjs +8 -0
  15. package/dist/cs-CZ.module.js +8 -0
  16. package/dist/cs-CZ.module.js.map +1 -0
  17. package/dist/da-DK.main.js +6 -0
  18. package/dist/da-DK.main.js.map +1 -0
  19. package/dist/da-DK.mjs +8 -0
  20. package/dist/da-DK.module.js +8 -0
  21. package/dist/da-DK.module.js.map +1 -0
  22. package/dist/de-DE.main.js +6 -0
  23. package/dist/de-DE.main.js.map +1 -0
  24. package/dist/de-DE.mjs +8 -0
  25. package/dist/de-DE.module.js +8 -0
  26. package/dist/de-DE.module.js.map +1 -0
  27. package/dist/el-GR.main.js +6 -0
  28. package/dist/el-GR.main.js.map +1 -0
  29. package/dist/el-GR.mjs +8 -0
  30. package/dist/el-GR.module.js +8 -0
  31. package/dist/el-GR.module.js.map +1 -0
  32. package/dist/en-US.main.js +6 -0
  33. package/dist/en-US.main.js.map +1 -0
  34. package/dist/en-US.mjs +8 -0
  35. package/dist/en-US.module.js +8 -0
  36. package/dist/en-US.module.js.map +1 -0
  37. package/dist/es-ES.main.js +6 -0
  38. package/dist/es-ES.main.js.map +1 -0
  39. package/dist/es-ES.mjs +8 -0
  40. package/dist/es-ES.module.js +8 -0
  41. package/dist/es-ES.module.js.map +1 -0
  42. package/dist/et-EE.main.js +6 -0
  43. package/dist/et-EE.main.js.map +1 -0
  44. package/dist/et-EE.mjs +8 -0
  45. package/dist/et-EE.module.js +8 -0
  46. package/dist/et-EE.module.js.map +1 -0
  47. package/dist/fi-FI.main.js +6 -0
  48. package/dist/fi-FI.main.js.map +1 -0
  49. package/dist/fi-FI.mjs +8 -0
  50. package/dist/fi-FI.module.js +8 -0
  51. package/dist/fi-FI.module.js.map +1 -0
  52. package/dist/fr-FR.main.js +6 -0
  53. package/dist/fr-FR.main.js.map +1 -0
  54. package/dist/fr-FR.mjs +8 -0
  55. package/dist/fr-FR.module.js +8 -0
  56. package/dist/fr-FR.module.js.map +1 -0
  57. package/dist/he-IL.main.js +6 -0
  58. package/dist/he-IL.main.js.map +1 -0
  59. package/dist/he-IL.mjs +8 -0
  60. package/dist/he-IL.module.js +8 -0
  61. package/dist/he-IL.module.js.map +1 -0
  62. package/dist/hr-HR.main.js +6 -0
  63. package/dist/hr-HR.main.js.map +1 -0
  64. package/dist/hr-HR.mjs +8 -0
  65. package/dist/hr-HR.module.js +8 -0
  66. package/dist/hr-HR.module.js.map +1 -0
  67. package/dist/hu-HU.main.js +6 -0
  68. package/dist/hu-HU.main.js.map +1 -0
  69. package/dist/hu-HU.mjs +8 -0
  70. package/dist/hu-HU.module.js +8 -0
  71. package/dist/hu-HU.module.js.map +1 -0
  72. package/dist/import.mjs +25 -0
  73. package/dist/intlStrings.main.js +108 -0
  74. package/dist/intlStrings.main.js.map +1 -0
  75. package/dist/intlStrings.mjs +110 -0
  76. package/dist/intlStrings.module.js +110 -0
  77. package/dist/intlStrings.module.js.map +1 -0
  78. package/dist/it-IT.main.js +6 -0
  79. package/dist/it-IT.main.js.map +1 -0
  80. package/dist/it-IT.mjs +8 -0
  81. package/dist/it-IT.module.js +8 -0
  82. package/dist/it-IT.module.js.map +1 -0
  83. package/dist/ja-JP.main.js +6 -0
  84. package/dist/ja-JP.main.js.map +1 -0
  85. package/dist/ja-JP.mjs +8 -0
  86. package/dist/ja-JP.module.js +8 -0
  87. package/dist/ja-JP.module.js.map +1 -0
  88. package/dist/ko-KR.main.js +6 -0
  89. package/dist/ko-KR.main.js.map +1 -0
  90. package/dist/ko-KR.mjs +8 -0
  91. package/dist/ko-KR.module.js +8 -0
  92. package/dist/ko-KR.module.js.map +1 -0
  93. package/dist/lt-LT.main.js +6 -0
  94. package/dist/lt-LT.main.js.map +1 -0
  95. package/dist/lt-LT.mjs +8 -0
  96. package/dist/lt-LT.module.js +8 -0
  97. package/dist/lt-LT.module.js.map +1 -0
  98. package/dist/lv-LV.main.js +6 -0
  99. package/dist/lv-LV.main.js.map +1 -0
  100. package/dist/lv-LV.mjs +8 -0
  101. package/dist/lv-LV.module.js +8 -0
  102. package/dist/lv-LV.module.js.map +1 -0
  103. package/dist/main.js +24 -251
  104. package/dist/main.js.map +1 -0
  105. package/dist/module.js +18 -232
  106. package/dist/module.js.map +1 -0
  107. package/dist/nb-NO.main.js +6 -0
  108. package/dist/nb-NO.main.js.map +1 -0
  109. package/dist/nb-NO.mjs +8 -0
  110. package/dist/nb-NO.module.js +8 -0
  111. package/dist/nb-NO.module.js.map +1 -0
  112. package/dist/nl-NL.main.js +6 -0
  113. package/dist/nl-NL.main.js.map +1 -0
  114. package/dist/nl-NL.mjs +8 -0
  115. package/dist/nl-NL.module.js +8 -0
  116. package/dist/nl-NL.module.js.map +1 -0
  117. package/dist/pl-PL.main.js +6 -0
  118. package/dist/pl-PL.main.js.map +1 -0
  119. package/dist/pl-PL.mjs +8 -0
  120. package/dist/pl-PL.module.js +8 -0
  121. package/dist/pl-PL.module.js.map +1 -0
  122. package/dist/pt-BR.main.js +6 -0
  123. package/dist/pt-BR.main.js.map +1 -0
  124. package/dist/pt-BR.mjs +8 -0
  125. package/dist/pt-BR.module.js +8 -0
  126. package/dist/pt-BR.module.js.map +1 -0
  127. package/dist/pt-PT.main.js +6 -0
  128. package/dist/pt-PT.main.js.map +1 -0
  129. package/dist/pt-PT.mjs +8 -0
  130. package/dist/pt-PT.module.js +8 -0
  131. package/dist/pt-PT.module.js.map +1 -0
  132. package/dist/ro-RO.main.js +6 -0
  133. package/dist/ro-RO.main.js.map +1 -0
  134. package/dist/ro-RO.mjs +8 -0
  135. package/dist/ro-RO.module.js +8 -0
  136. package/dist/ro-RO.module.js.map +1 -0
  137. package/dist/ru-RU.main.js +6 -0
  138. package/dist/ru-RU.main.js.map +1 -0
  139. package/dist/ru-RU.mjs +8 -0
  140. package/dist/ru-RU.module.js +8 -0
  141. package/dist/ru-RU.module.js.map +1 -0
  142. package/dist/sk-SK.main.js +6 -0
  143. package/dist/sk-SK.main.js.map +1 -0
  144. package/dist/sk-SK.mjs +8 -0
  145. package/dist/sk-SK.module.js +8 -0
  146. package/dist/sk-SK.module.js.map +1 -0
  147. package/dist/sl-SI.main.js +6 -0
  148. package/dist/sl-SI.main.js.map +1 -0
  149. package/dist/sl-SI.mjs +8 -0
  150. package/dist/sl-SI.module.js +8 -0
  151. package/dist/sl-SI.module.js.map +1 -0
  152. package/dist/sr-SP.main.js +6 -0
  153. package/dist/sr-SP.main.js.map +1 -0
  154. package/dist/sr-SP.mjs +8 -0
  155. package/dist/sr-SP.module.js +8 -0
  156. package/dist/sr-SP.module.js.map +1 -0
  157. package/dist/sv-SE.main.js +6 -0
  158. package/dist/sv-SE.main.js.map +1 -0
  159. package/dist/sv-SE.mjs +8 -0
  160. package/dist/sv-SE.module.js +8 -0
  161. package/dist/sv-SE.module.js.map +1 -0
  162. package/dist/tr-TR.main.js +6 -0
  163. package/dist/tr-TR.main.js.map +1 -0
  164. package/dist/tr-TR.mjs +8 -0
  165. package/dist/tr-TR.module.js +8 -0
  166. package/dist/tr-TR.module.js.map +1 -0
  167. package/dist/types.d.ts +156 -36
  168. package/dist/types.d.ts.map +1 -1
  169. package/dist/uk-UA.main.js +6 -0
  170. package/dist/uk-UA.main.js.map +1 -0
  171. package/dist/uk-UA.mjs +8 -0
  172. package/dist/uk-UA.module.js +8 -0
  173. package/dist/uk-UA.module.js.map +1 -0
  174. package/dist/useMenu.main.js +59 -0
  175. package/dist/useMenu.main.js.map +1 -0
  176. package/dist/useMenu.mjs +53 -0
  177. package/dist/useMenu.module.js +53 -0
  178. package/dist/useMenu.module.js.map +1 -0
  179. package/dist/useMenuItem.main.js +181 -0
  180. package/dist/useMenuItem.main.js.map +1 -0
  181. package/dist/useMenuItem.mjs +176 -0
  182. package/dist/useMenuItem.module.js +176 -0
  183. package/dist/useMenuItem.module.js.map +1 -0
  184. package/dist/useMenuSection.main.js +43 -0
  185. package/dist/useMenuSection.main.js.map +1 -0
  186. package/dist/useMenuSection.mjs +38 -0
  187. package/dist/useMenuSection.module.js +38 -0
  188. package/dist/useMenuSection.module.js.map +1 -0
  189. package/dist/useMenuTrigger.main.js +103 -0
  190. package/dist/useMenuTrigger.main.js.map +1 -0
  191. package/dist/useMenuTrigger.mjs +98 -0
  192. package/dist/useMenuTrigger.module.js +98 -0
  193. package/dist/useMenuTrigger.module.js.map +1 -0
  194. package/dist/useSafelyMouseToSubmenu.main.js +134 -0
  195. package/dist/useSafelyMouseToSubmenu.main.js.map +1 -0
  196. package/dist/useSafelyMouseToSubmenu.mjs +129 -0
  197. package/dist/useSafelyMouseToSubmenu.module.js +129 -0
  198. package/dist/useSafelyMouseToSubmenu.module.js.map +1 -0
  199. package/dist/useSubmenuTrigger.main.js +169 -0
  200. package/dist/useSubmenuTrigger.main.js.map +1 -0
  201. package/dist/useSubmenuTrigger.mjs +164 -0
  202. package/dist/useSubmenuTrigger.module.js +164 -0
  203. package/dist/useSubmenuTrigger.module.js.map +1 -0
  204. package/dist/zh-CN.main.js +6 -0
  205. package/dist/zh-CN.main.js.map +1 -0
  206. package/dist/zh-CN.mjs +8 -0
  207. package/dist/zh-CN.module.js +8 -0
  208. package/dist/zh-CN.module.js.map +1 -0
  209. package/dist/zh-TW.main.js +6 -0
  210. package/dist/zh-TW.main.js.map +1 -0
  211. package/dist/zh-TW.mjs +8 -0
  212. package/dist/zh-TW.module.js +8 -0
  213. package/dist/zh-TW.module.js.map +1 -0
  214. package/package.json +26 -16
  215. package/src/index.ts +24 -0
  216. package/src/useMenu.ts +88 -0
  217. package/src/useMenuItem.ts +299 -0
  218. package/src/useMenuSection.ts +61 -0
  219. package/src/useMenuTrigger.ts +144 -0
  220. package/src/useSafelyMouseToSubmenu.ts +161 -0
  221. package/src/useSubmenuTrigger.ts +243 -0
  222. package/LICENSE +0 -201
@@ -0,0 +1,59 @@
1
+ var $6CumN$reactariautils = require("@react-aria/utils");
2
+ var $6CumN$reactariaselection = require("@react-aria/selection");
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, "menuData", () => $a3815f0132802737$export$6f49b4016bfc8d56);
10
+ $parcel$export(module.exports, "useMenu", () => $a3815f0132802737$export$38eaa17faae8f579);
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
+ const $a3815f0132802737$export$6f49b4016bfc8d56 = new WeakMap();
24
+ function $a3815f0132802737$export$38eaa17faae8f579(props, state, ref) {
25
+ let { shouldFocusWrap: shouldFocusWrap = true, onKeyDown: onKeyDown, onKeyUp: onKeyUp, ...otherProps } = props;
26
+ if (!props['aria-label'] && !props['aria-labelledby']) console.warn('An aria-label or aria-labelledby prop is required for accessibility.');
27
+ let domProps = (0, $6CumN$reactariautils.filterDOMProps)(props, {
28
+ labelable: true
29
+ });
30
+ let { listProps: listProps } = (0, $6CumN$reactariaselection.useSelectableList)({
31
+ ...otherProps,
32
+ ref: ref,
33
+ selectionManager: state.selectionManager,
34
+ collection: state.collection,
35
+ disabledKeys: state.disabledKeys,
36
+ shouldFocusWrap: shouldFocusWrap,
37
+ linkBehavior: 'override'
38
+ });
39
+ $a3815f0132802737$export$6f49b4016bfc8d56.set(state, {
40
+ onClose: props.onClose,
41
+ onAction: props.onAction
42
+ });
43
+ return {
44
+ menuProps: (0, $6CumN$reactariautils.mergeProps)(domProps, {
45
+ onKeyDown: onKeyDown,
46
+ onKeyUp: onKeyUp
47
+ }, {
48
+ role: 'menu',
49
+ ...listProps,
50
+ onKeyDown: (e)=>{
51
+ // don't clear the menu selected keys if the user is presses escape since escape closes the menu
52
+ if (e.key !== 'Escape') listProps.onKeyDown(e);
53
+ }
54
+ })
55
+ };
56
+ }
57
+
58
+
59
+ //# sourceMappingURL=useMenu.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA6BM,MAAM,4CAAW,IAAI;AAQrB,SAAS,0CAAW,KAAyB,EAAE,KAAmB,EAAE,GAAkC;IAC3G,IAAI,mBACF,kBAAkB,iBAClB,SAAS,WACT,OAAO,EACP,GAAG,YACJ,GAAG;IAEJ,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,kBAAkB,EACnD,QAAQ,IAAI,CAAC;IAGf,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IACrD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,2CAAgB,EAAE;QAClC,GAAG,UAAU;aACb;QACA,kBAAkB,MAAM,gBAAgB;QACxC,YAAY,MAAM,UAAU;QAC5B,cAAc,MAAM,YAAY;yBAChC;QACA,cAAc;IAChB;IAEA,0CAAS,GAAG,CAAC,OAAO;QAClB,SAAS,MAAM,OAAO;QACtB,UAAU,MAAM,QAAQ;IAC1B;IAEA,OAAO;QACL,WAAW,CAAA,GAAA,gCAAS,EAAE,UAAU;uBAAC;qBAAW;QAAO,GAAG;YACpD,MAAM;YACN,GAAG,SAAS;YACZ,WAAW,CAAC;gBACV,gGAAgG;gBAChG,IAAI,EAAE,GAAG,KAAK,UACZ,UAAU,SAAS,CAAC;YAExB;QACF;IACF;AACF","sources":["packages/@react-aria/menu/src/useMenu.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 {AriaMenuProps} from '@react-types/menu';\nimport {DOMAttributes, Key, KeyboardDelegate, KeyboardEvents, RefObject} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableList} from '@react-aria/selection';\n\nexport interface MenuAria {\n /** Props for the menu element. */\n menuProps: DOMAttributes\n}\n\nexport interface AriaMenuOptions<T> extends Omit<AriaMenuProps<T>, 'children'>, KeyboardEvents {\n /** Whether the menu uses virtual scrolling. */\n isVirtualized?: boolean,\n\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate\n}\n\ninterface MenuData {\n onClose?: () => void,\n onAction?: (key: Key) => void\n}\n\nexport const menuData = new WeakMap<TreeState<unknown>, MenuData>();\n\n/**\n * Provides the behavior and accessibility implementation for a menu component.\n * A menu displays a list of actions or options that a user can choose.\n * @param props - Props for the menu.\n * @param state - State for the menu, as returned by `useListState`.\n */\nexport function useMenu<T>(props: AriaMenuOptions<T>, state: TreeState<T>, ref: RefObject<HTMLElement | null>): MenuAria {\n let {\n shouldFocusWrap = true,\n onKeyDown,\n onKeyUp,\n ...otherProps\n } = props;\n\n if (!props['aria-label'] && !props['aria-labelledby']) {\n console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n }\n\n let domProps = filterDOMProps(props, {labelable: true});\n let {listProps} = useSelectableList({\n ...otherProps,\n ref,\n selectionManager: state.selectionManager,\n collection: state.collection,\n disabledKeys: state.disabledKeys,\n shouldFocusWrap,\n linkBehavior: 'override'\n });\n\n menuData.set(state, {\n onClose: props.onClose,\n onAction: props.onAction\n });\n\n return {\n menuProps: mergeProps(domProps, {onKeyDown, onKeyUp}, {\n role: 'menu',\n ...listProps,\n onKeyDown: (e) => {\n // don't clear the menu selected keys if the user is presses escape since escape closes the menu\n if (e.key !== 'Escape') {\n listProps.onKeyDown(e);\n }\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"useMenu.main.js.map"}
@@ -0,0 +1,53 @@
1
+ import {filterDOMProps as $ieN2F$filterDOMProps, mergeProps as $ieN2F$mergeProps} from "@react-aria/utils";
2
+ import {useSelectableList as $ieN2F$useSelectableList} from "@react-aria/selection";
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
+ */
15
+
16
+ const $d5336fe17ce95402$export$6f49b4016bfc8d56 = new WeakMap();
17
+ function $d5336fe17ce95402$export$38eaa17faae8f579(props, state, ref) {
18
+ let { shouldFocusWrap: shouldFocusWrap = true, onKeyDown: onKeyDown, onKeyUp: onKeyUp, ...otherProps } = props;
19
+ if (!props['aria-label'] && !props['aria-labelledby']) console.warn('An aria-label or aria-labelledby prop is required for accessibility.');
20
+ let domProps = (0, $ieN2F$filterDOMProps)(props, {
21
+ labelable: true
22
+ });
23
+ let { listProps: listProps } = (0, $ieN2F$useSelectableList)({
24
+ ...otherProps,
25
+ ref: ref,
26
+ selectionManager: state.selectionManager,
27
+ collection: state.collection,
28
+ disabledKeys: state.disabledKeys,
29
+ shouldFocusWrap: shouldFocusWrap,
30
+ linkBehavior: 'override'
31
+ });
32
+ $d5336fe17ce95402$export$6f49b4016bfc8d56.set(state, {
33
+ onClose: props.onClose,
34
+ onAction: props.onAction
35
+ });
36
+ return {
37
+ menuProps: (0, $ieN2F$mergeProps)(domProps, {
38
+ onKeyDown: onKeyDown,
39
+ onKeyUp: onKeyUp
40
+ }, {
41
+ role: 'menu',
42
+ ...listProps,
43
+ onKeyDown: (e)=>{
44
+ // don't clear the menu selected keys if the user is presses escape since escape closes the menu
45
+ if (e.key !== 'Escape') listProps.onKeyDown(e);
46
+ }
47
+ })
48
+ };
49
+ }
50
+
51
+
52
+ export {$d5336fe17ce95402$export$6f49b4016bfc8d56 as menuData, $d5336fe17ce95402$export$38eaa17faae8f579 as useMenu};
53
+ //# sourceMappingURL=useMenu.module.js.map
@@ -0,0 +1,53 @@
1
+ import {filterDOMProps as $ieN2F$filterDOMProps, mergeProps as $ieN2F$mergeProps} from "@react-aria/utils";
2
+ import {useSelectableList as $ieN2F$useSelectableList} from "@react-aria/selection";
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
+ */
15
+
16
+ const $d5336fe17ce95402$export$6f49b4016bfc8d56 = new WeakMap();
17
+ function $d5336fe17ce95402$export$38eaa17faae8f579(props, state, ref) {
18
+ let { shouldFocusWrap: shouldFocusWrap = true, onKeyDown: onKeyDown, onKeyUp: onKeyUp, ...otherProps } = props;
19
+ if (!props['aria-label'] && !props['aria-labelledby']) console.warn('An aria-label or aria-labelledby prop is required for accessibility.');
20
+ let domProps = (0, $ieN2F$filterDOMProps)(props, {
21
+ labelable: true
22
+ });
23
+ let { listProps: listProps } = (0, $ieN2F$useSelectableList)({
24
+ ...otherProps,
25
+ ref: ref,
26
+ selectionManager: state.selectionManager,
27
+ collection: state.collection,
28
+ disabledKeys: state.disabledKeys,
29
+ shouldFocusWrap: shouldFocusWrap,
30
+ linkBehavior: 'override'
31
+ });
32
+ $d5336fe17ce95402$export$6f49b4016bfc8d56.set(state, {
33
+ onClose: props.onClose,
34
+ onAction: props.onAction
35
+ });
36
+ return {
37
+ menuProps: (0, $ieN2F$mergeProps)(domProps, {
38
+ onKeyDown: onKeyDown,
39
+ onKeyUp: onKeyUp
40
+ }, {
41
+ role: 'menu',
42
+ ...listProps,
43
+ onKeyDown: (e)=>{
44
+ // don't clear the menu selected keys if the user is presses escape since escape closes the menu
45
+ if (e.key !== 'Escape') listProps.onKeyDown(e);
46
+ }
47
+ })
48
+ };
49
+ }
50
+
51
+
52
+ export {$d5336fe17ce95402$export$6f49b4016bfc8d56 as menuData, $d5336fe17ce95402$export$38eaa17faae8f579 as useMenu};
53
+ //# sourceMappingURL=useMenu.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA6BM,MAAM,4CAAW,IAAI;AAQrB,SAAS,0CAAW,KAAyB,EAAE,KAAmB,EAAE,GAAkC;IAC3G,IAAI,mBACF,kBAAkB,iBAClB,SAAS,WACT,OAAO,EACP,GAAG,YACJ,GAAG;IAEJ,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,kBAAkB,EACnD,QAAQ,IAAI,CAAC;IAGf,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IACrD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,wBAAgB,EAAE;QAClC,GAAG,UAAU;aACb;QACA,kBAAkB,MAAM,gBAAgB;QACxC,YAAY,MAAM,UAAU;QAC5B,cAAc,MAAM,YAAY;yBAChC;QACA,cAAc;IAChB;IAEA,0CAAS,GAAG,CAAC,OAAO;QAClB,SAAS,MAAM,OAAO;QACtB,UAAU,MAAM,QAAQ;IAC1B;IAEA,OAAO;QACL,WAAW,CAAA,GAAA,iBAAS,EAAE,UAAU;uBAAC;qBAAW;QAAO,GAAG;YACpD,MAAM;YACN,GAAG,SAAS;YACZ,WAAW,CAAC;gBACV,gGAAgG;gBAChG,IAAI,EAAE,GAAG,KAAK,UACZ,UAAU,SAAS,CAAC;YAExB;QACF;IACF;AACF","sources":["packages/@react-aria/menu/src/useMenu.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 {AriaMenuProps} from '@react-types/menu';\nimport {DOMAttributes, Key, KeyboardDelegate, KeyboardEvents, RefObject} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableList} from '@react-aria/selection';\n\nexport interface MenuAria {\n /** Props for the menu element. */\n menuProps: DOMAttributes\n}\n\nexport interface AriaMenuOptions<T> extends Omit<AriaMenuProps<T>, 'children'>, KeyboardEvents {\n /** Whether the menu uses virtual scrolling. */\n isVirtualized?: boolean,\n\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate\n}\n\ninterface MenuData {\n onClose?: () => void,\n onAction?: (key: Key) => void\n}\n\nexport const menuData = new WeakMap<TreeState<unknown>, MenuData>();\n\n/**\n * Provides the behavior and accessibility implementation for a menu component.\n * A menu displays a list of actions or options that a user can choose.\n * @param props - Props for the menu.\n * @param state - State for the menu, as returned by `useListState`.\n */\nexport function useMenu<T>(props: AriaMenuOptions<T>, state: TreeState<T>, ref: RefObject<HTMLElement | null>): MenuAria {\n let {\n shouldFocusWrap = true,\n onKeyDown,\n onKeyUp,\n ...otherProps\n } = props;\n\n if (!props['aria-label'] && !props['aria-labelledby']) {\n console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n }\n\n let domProps = filterDOMProps(props, {labelable: true});\n let {listProps} = useSelectableList({\n ...otherProps,\n ref,\n selectionManager: state.selectionManager,\n collection: state.collection,\n disabledKeys: state.disabledKeys,\n shouldFocusWrap,\n linkBehavior: 'override'\n });\n\n menuData.set(state, {\n onClose: props.onClose,\n onAction: props.onAction\n });\n\n return {\n menuProps: mergeProps(domProps, {onKeyDown, onKeyUp}, {\n role: 'menu',\n ...listProps,\n onKeyDown: (e) => {\n // don't clear the menu selected keys if the user is presses escape since escape closes the menu\n if (e.key !== 'Escape') {\n listProps.onKeyDown(e);\n }\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"useMenu.module.js.map"}
@@ -0,0 +1,181 @@
1
+ var $a3815f0132802737$exports = require("./useMenu.main.js");
2
+ var $byVdR$reactariautils = require("@react-aria/utils");
3
+ var $byVdR$reactstatelycollections = require("@react-stately/collections");
4
+ var $byVdR$reactariainteractions = require("@react-aria/interactions");
5
+ var $byVdR$reactariaselection = require("@react-aria/selection");
6
+
7
+
8
+ function $parcel$export(e, n, v, s) {
9
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
+ }
11
+
12
+ $parcel$export(module.exports, "useMenuItem", () => $38191ed02615ec07$export$9d32628fc2aea7da);
13
+ /*
14
+ * Copyright 2020 Adobe. All rights reserved.
15
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License. You may obtain a copy
17
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software distributed under
20
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
+ * OF ANY KIND, either express or implied. See the License for the specific language
22
+ * governing permissions and limitations under the License.
23
+ */
24
+
25
+
26
+
27
+
28
+ function $38191ed02615ec07$export$9d32628fc2aea7da(props, state, ref) {
29
+ let { id: id, key: key, closeOnSelect: closeOnSelect, isVirtualized: isVirtualized, 'aria-haspopup': hasPopup, onPressStart: pressStartProp, onPressUp: pressUpProp, onPress: onPress, onPressChange: onPressChange, onPressEnd: onPressEnd, onHoverStart: hoverStartProp, onHoverChange: onHoverChange, onHoverEnd: onHoverEnd, onKeyDown: onKeyDown, onKeyUp: onKeyUp, onFocus: onFocus, onFocusChange: onFocusChange, onBlur: onBlur } = props;
30
+ let isTrigger = !!hasPopup;
31
+ var _props_isDisabled;
32
+ let isDisabled = (_props_isDisabled = props.isDisabled) !== null && _props_isDisabled !== void 0 ? _props_isDisabled : state.selectionManager.isDisabled(key);
33
+ var _props_isSelected;
34
+ let isSelected = (_props_isSelected = props.isSelected) !== null && _props_isSelected !== void 0 ? _props_isSelected : state.selectionManager.isSelected(key);
35
+ let data = (0, $a3815f0132802737$exports.menuData).get(state);
36
+ let item = state.collection.getItem(key);
37
+ let onClose = props.onClose || data.onClose;
38
+ let router = (0, $byVdR$reactariautils.useRouter)();
39
+ let performAction = (e)=>{
40
+ var _item_props;
41
+ if (isTrigger) return;
42
+ if (item === null || item === void 0 ? void 0 : (_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.onAction) item.props.onAction();
43
+ else if (props.onAction) props.onAction(key);
44
+ if (data.onAction) {
45
+ // Must reassign to variable otherwise `this` binding gets messed up. Something to do with WeakMap.
46
+ let onAction = data.onAction;
47
+ onAction(key);
48
+ }
49
+ if (e.target instanceof HTMLAnchorElement) router.open(e.target, e, item.props.href, item.props.routerOptions);
50
+ };
51
+ let role = 'menuitem';
52
+ if (!isTrigger) {
53
+ if (state.selectionManager.selectionMode === 'single') role = 'menuitemradio';
54
+ else if (state.selectionManager.selectionMode === 'multiple') role = 'menuitemcheckbox';
55
+ }
56
+ let labelId = (0, $byVdR$reactariautils.useSlotId)();
57
+ let descriptionId = (0, $byVdR$reactariautils.useSlotId)();
58
+ let keyboardId = (0, $byVdR$reactariautils.useSlotId)();
59
+ let ariaProps = {
60
+ id: id,
61
+ 'aria-disabled': isDisabled || undefined,
62
+ role: role,
63
+ 'aria-label': props['aria-label'],
64
+ 'aria-labelledby': labelId,
65
+ 'aria-describedby': [
66
+ descriptionId,
67
+ keyboardId
68
+ ].filter(Boolean).join(' ') || undefined,
69
+ 'aria-controls': props['aria-controls'],
70
+ 'aria-haspopup': hasPopup,
71
+ 'aria-expanded': props['aria-expanded']
72
+ };
73
+ if (state.selectionManager.selectionMode !== 'none' && !isTrigger) ariaProps['aria-checked'] = isSelected;
74
+ if (isVirtualized) {
75
+ ariaProps['aria-posinset'] = item === null || item === void 0 ? void 0 : item.index;
76
+ ariaProps['aria-setsize'] = (0, $byVdR$reactstatelycollections.getItemCount)(state.collection);
77
+ }
78
+ let onPressStart = (e)=>{
79
+ if (e.pointerType === 'keyboard') performAction(e);
80
+ pressStartProp === null || pressStartProp === void 0 ? void 0 : pressStartProp(e);
81
+ };
82
+ let onPressUp = (e)=>{
83
+ if (e.pointerType !== 'keyboard') {
84
+ performAction(e);
85
+ // Pressing a menu item should close by default in single selection mode but not multiple
86
+ // selection mode, except if overridden by the closeOnSelect prop.
87
+ if (!isTrigger && onClose && (closeOnSelect !== null && closeOnSelect !== void 0 ? closeOnSelect : state.selectionManager.selectionMode !== 'multiple' || state.selectionManager.isLink(key))) onClose();
88
+ }
89
+ pressUpProp === null || pressUpProp === void 0 ? void 0 : pressUpProp(e);
90
+ };
91
+ let { itemProps: itemProps, isFocused: isFocused } = (0, $byVdR$reactariaselection.useSelectableItem)({
92
+ selectionManager: state.selectionManager,
93
+ key: key,
94
+ ref: ref,
95
+ shouldSelectOnPressUp: true,
96
+ allowsDifferentPressOrigin: true,
97
+ // Disable all handling of links in useSelectable item
98
+ // because we handle it ourselves. The behavior of menus
99
+ // is slightly different from other collections because
100
+ // actions are performed on key down rather than key up.
101
+ linkBehavior: 'none'
102
+ });
103
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $byVdR$reactariainteractions.usePress)({
104
+ onPressStart: onPressStart,
105
+ onPress: onPress,
106
+ onPressUp: onPressUp,
107
+ onPressChange: onPressChange,
108
+ onPressEnd: onPressEnd,
109
+ isDisabled: isDisabled
110
+ });
111
+ let { hoverProps: hoverProps } = (0, $byVdR$reactariainteractions.useHover)({
112
+ isDisabled: isDisabled,
113
+ onHoverStart (e) {
114
+ if (!(0, $byVdR$reactariainteractions.isFocusVisible)()) {
115
+ state.selectionManager.setFocused(true);
116
+ state.selectionManager.setFocusedKey(key);
117
+ }
118
+ hoverStartProp === null || hoverStartProp === void 0 ? void 0 : hoverStartProp(e);
119
+ },
120
+ onHoverChange: onHoverChange,
121
+ onHoverEnd: onHoverEnd
122
+ });
123
+ let { keyboardProps: keyboardProps } = (0, $byVdR$reactariainteractions.useKeyboard)({
124
+ onKeyDown: (e)=>{
125
+ // Ignore repeating events, which may have started on the menu trigger before moving
126
+ // focus to the menu item. We want to wait for a second complete key press sequence.
127
+ if (e.repeat) {
128
+ e.continuePropagation();
129
+ return;
130
+ }
131
+ switch(e.key){
132
+ case ' ':
133
+ if (!isDisabled && state.selectionManager.selectionMode === 'none' && !isTrigger && closeOnSelect !== false && onClose) onClose();
134
+ break;
135
+ case 'Enter':
136
+ // The Enter key should always close on select, except if overridden.
137
+ if (!isDisabled && closeOnSelect !== false && !isTrigger && onClose) onClose();
138
+ break;
139
+ default:
140
+ if (!isTrigger) e.continuePropagation();
141
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
142
+ break;
143
+ }
144
+ },
145
+ onKeyUp: onKeyUp
146
+ });
147
+ let { focusProps: focusProps } = (0, $byVdR$reactariainteractions.useFocus)({
148
+ onBlur: onBlur,
149
+ onFocus: onFocus,
150
+ onFocusChange: onFocusChange
151
+ });
152
+ let domProps = (0, $byVdR$reactariautils.filterDOMProps)(item.props);
153
+ delete domProps.id;
154
+ let linkProps = (0, $byVdR$reactariautils.useLinkProps)(item.props);
155
+ return {
156
+ menuItemProps: {
157
+ ...ariaProps,
158
+ ...(0, $byVdR$reactariautils.mergeProps)(domProps, linkProps, isTrigger ? {
159
+ onFocus: itemProps.onFocus,
160
+ 'data-key': itemProps['data-key']
161
+ } : itemProps, pressProps, hoverProps, keyboardProps, focusProps),
162
+ tabIndex: itemProps.tabIndex != null ? -1 : undefined
163
+ },
164
+ labelProps: {
165
+ id: labelId
166
+ },
167
+ descriptionProps: {
168
+ id: descriptionId
169
+ },
170
+ keyboardShortcutProps: {
171
+ id: keyboardId
172
+ },
173
+ isFocused: isFocused,
174
+ isSelected: isSelected,
175
+ isPressed: isPressed,
176
+ isDisabled: isDisabled
177
+ };
178
+ }
179
+
180
+
181
+ //# sourceMappingURL=useMenuItem.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAyFM,SAAS,0CAAe,KAAwB,EAAE,KAAmB,EAAE,GAAuC;IACnH,IAAI,MACF,EAAE,OACF,GAAG,iBACH,aAAa,iBACb,aAAa,EACb,iBAAiB,QAAQ,EACzB,cAAc,cAAc,EAC5B,WAAW,WAAW,WACtB,OAAO,iBACP,aAAa,cACb,UAAU,EACV,cAAc,cAAc,iBAC5B,aAAa,cACb,UAAU,aACV,SAAS,WACT,OA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kB;YAChB,IAAI;QACN;QACA,uBAAuB;YACrB,IAAI;QACN;mBACA;oBACA;mBACA;oBACA;IACF;AACF","sources":["packages/@react-aria/menu/src/useMenuItem.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 {DOMAttributes, DOMProps, FocusableElement, FocusEvents, HoverEvents, Key, KeyboardEvents, PressEvent, PressEvents, RefObject, RouterOptions} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useLinkProps, useRouter, useSlotId} from '@react-aria/utils';\nimport {getItemCount} from '@react-stately/collections';\nimport {isFocusVisible, useFocus, useHover, useKeyboard, usePress} from '@react-aria/interactions';\nimport {menuData} from './useMenu';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableItem} from '@react-aria/selection';\n\nexport interface MenuItemAria {\n /** Props for the menu item element. */\n menuItemProps: DOMAttributes,\n\n /** Props for the main text element inside the menu item. */\n labelProps: DOMAttributes,\n\n /** Props for the description text element inside the menu item, if any. */\n descriptionProps: DOMAttributes,\n\n /** Props for the keyboard shortcut text element inside the item, if any. */\n keyboardShortcutProps: DOMAttributes,\n\n /** Whether the item is currently focused. */\n isFocused: boolean,\n /** Whether the item is currently selected. */\n isSelected: boolean,\n /** Whether the item is currently in a pressed state. */\n isPressed: boolean,\n /** Whether the item is disabled. */\n isDisabled: boolean\n}\n\nexport interface AriaMenuItemProps extends DOMProps, PressEvents, HoverEvents, KeyboardEvents, FocusEvents {\n /**\n * Whether the menu item is disabled.\n * @deprecated - pass disabledKeys to useTreeState instead.\n */\n isDisabled?: boolean,\n\n /**\n * Whether the menu item is selected.\n * @deprecated - pass selectedKeys to useTreeState instead.\n */\n isSelected?: boolean,\n\n /** A screen reader only label for the menu item. */\n 'aria-label'?: string,\n\n /** The unique key for the menu item. */\n key?: Key,\n\n /**\n * Handler that is called when the menu should close after selecting an item.\n * @deprecated - pass to the menu instead.\n */\n onClose?: () => void,\n\n /**\n * Whether the menu should close when the menu item is selected.\n * @default true\n */\n closeOnSelect?: boolean,\n\n /** Whether the menu item is contained in a virtual scrolling menu. */\n isVirtualized?: boolean,\n\n /**\n * Handler that is called when the user activates the item.\n * @deprecated - pass to the menu instead.\n */\n onAction?: (key: Key) => void,\n\n /** What kind of popup the item opens. */\n 'aria-haspopup'?: 'menu' | 'dialog',\n\n /** Indicates whether the menu item's popup element is expanded or collapsed. */\n 'aria-expanded'?: boolean | 'true' | 'false',\n\n /** Identifies the menu item's popup element whose contents or presence is controlled by the menu item. */\n 'aria-controls'?: string\n}\n\n/**\n * Provides the behavior and accessibility implementation for an item in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the item.\n * @param state - State for the menu, as returned by `useTreeState`.\n */\nexport function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, ref: RefObject<FocusableElement | null>): MenuItemAria {\n let {\n id,\n key,\n closeOnSelect,\n isVirtualized,\n 'aria-haspopup': hasPopup,\n onPressStart: pressStartProp,\n onPressUp: pressUpProp,\n onPress,\n onPressChange,\n onPressEnd,\n onHoverStart: hoverStartProp,\n onHoverChange,\n onHoverEnd,\n onKeyDown,\n onKeyUp,\n onFocus,\n onFocusChange,\n onBlur\n } = props;\n\n let isTrigger = !!hasPopup;\n let isDisabled = props.isDisabled ?? state.selectionManager.isDisabled(key);\n let isSelected = props.isSelected ?? state.selectionManager.isSelected(key);\n let data = menuData.get(state);\n let item = state.collection.getItem(key);\n let onClose = props.onClose || data.onClose;\n let router = useRouter();\n let performAction = (e: PressEvent) => {\n if (isTrigger) {\n return;\n }\n\n if (item?.props?.onAction) {\n item.props.onAction();\n } else if (props.onAction) {\n props.onAction(key);\n }\n\n if (data.onAction) {\n // Must reassign to variable otherwise `this` binding gets messed up. Something to do with WeakMap.\n let onAction = data.onAction;\n onAction(key);\n }\n\n if (e.target instanceof HTMLAnchorElement) {\n router.open(e.target, e, item.props.href, item.props.routerOptions as RouterOptions);\n }\n };\n\n let role = 'menuitem';\n if (!isTrigger) {\n if (state.selectionManager.selectionMode === 'single') {\n role = 'menuitemradio';\n } else if (state.selectionManager.selectionMode === 'multiple') {\n role = 'menuitemcheckbox';\n }\n }\n\n let labelId = useSlotId();\n let descriptionId = useSlotId();\n let keyboardId = useSlotId();\n\n let ariaProps = {\n id,\n 'aria-disabled': isDisabled || undefined,\n role,\n 'aria-label': props['aria-label'],\n 'aria-labelledby': labelId,\n 'aria-describedby': [descriptionId, keyboardId].filter(Boolean).join(' ') || undefined,\n 'aria-controls': props['aria-controls'],\n 'aria-haspopup': hasPopup,\n 'aria-expanded': props['aria-expanded']\n };\n\n if (state.selectionManager.selectionMode !== 'none' && !isTrigger) {\n ariaProps['aria-checked'] = isSelected;\n }\n\n if (isVirtualized) {\n ariaProps['aria-posinset'] = item?.index;\n ariaProps['aria-setsize'] = getItemCount(state.collection);\n }\n\n let onPressStart = (e: PressEvent) => {\n if (e.pointerType === 'keyboard') {\n performAction(e);\n }\n\n pressStartProp?.(e);\n };\n\n let onPressUp = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard') {\n performAction(e);\n\n // Pressing a menu item should close by default in single selection mode but not multiple\n // selection mode, except if overridden by the closeOnSelect prop.\n if (!isTrigger && onClose && (closeOnSelect ?? (state.selectionManager.selectionMode !== 'multiple' || state.selectionManager.isLink(key)))) {\n onClose();\n }\n }\n\n pressUpProp?.(e);\n };\n\n let {itemProps, isFocused} = useSelectableItem({\n selectionManager: state.selectionManager,\n key,\n ref,\n shouldSelectOnPressUp: true,\n allowsDifferentPressOrigin: true,\n // Disable all handling of links in useSelectable item\n // because we handle it ourselves. The behavior of menus\n // is slightly different from other collections because\n // actions are performed on key down rather than key up.\n linkBehavior: 'none'\n });\n\n let {pressProps, isPressed} = usePress({\n onPressStart,\n onPress,\n onPressUp,\n onPressChange,\n onPressEnd,\n isDisabled\n });\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart(e) {\n if (!isFocusVisible()) {\n state.selectionManager.setFocused(true);\n state.selectionManager.setFocusedKey(key);\n }\n hoverStartProp?.(e);\n },\n onHoverChange,\n onHoverEnd\n });\n\n let {keyboardProps} = useKeyboard({\n onKeyDown: (e) => {\n // Ignore repeating events, which may have started on the menu trigger before moving\n // focus to the menu item. We want to wait for a second complete key press sequence.\n if (e.repeat) {\n e.continuePropagation();\n return;\n }\n\n switch (e.key) {\n case ' ':\n if (!isDisabled && state.selectionManager.selectionMode === 'none' && !isTrigger && closeOnSelect !== false && onClose) {\n onClose();\n }\n break;\n case 'Enter':\n // The Enter key should always close on select, except if overridden.\n if (!isDisabled && closeOnSelect !== false && !isTrigger && onClose) {\n onClose();\n }\n break;\n default:\n if (!isTrigger) {\n e.continuePropagation();\n }\n\n onKeyDown?.(e);\n break;\n }\n },\n onKeyUp\n });\n\n let {focusProps} = useFocus({onBlur, onFocus, onFocusChange});\n let domProps = filterDOMProps(item.props);\n delete domProps.id;\n let linkProps = useLinkProps(item.props);\n\n return {\n menuItemProps: {\n ...ariaProps,\n ...mergeProps(domProps, linkProps, isTrigger ? {onFocus: itemProps.onFocus, 'data-key': itemProps['data-key']} : itemProps, pressProps, hoverProps, keyboardProps, focusProps),\n tabIndex: itemProps.tabIndex != null ? -1 : undefined\n },\n labelProps: {\n id: labelId\n },\n descriptionProps: {\n id: descriptionId\n },\n keyboardShortcutProps: {\n id: keyboardId\n },\n isFocused,\n isSelected,\n isPressed,\n isDisabled\n };\n}\n"],"names":[],"version":3,"file":"useMenuItem.main.js.map"}
@@ -0,0 +1,176 @@
1
+ import {menuData as $d5336fe17ce95402$export$6f49b4016bfc8d56} from "./useMenu.mjs";
2
+ import {useRouter as $7Kjv5$useRouter, useSlotId as $7Kjv5$useSlotId, filterDOMProps as $7Kjv5$filterDOMProps, useLinkProps as $7Kjv5$useLinkProps, mergeProps as $7Kjv5$mergeProps} from "@react-aria/utils";
3
+ import {getItemCount as $7Kjv5$getItemCount} from "@react-stately/collections";
4
+ import {usePress as $7Kjv5$usePress, useHover as $7Kjv5$useHover, isFocusVisible as $7Kjv5$isFocusVisible, useKeyboard as $7Kjv5$useKeyboard, useFocus as $7Kjv5$useFocus} from "@react-aria/interactions";
5
+ import {useSelectableItem as $7Kjv5$useSelectableItem} from "@react-aria/selection";
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
+ function $a2e5df62f93c7633$export$9d32628fc2aea7da(props, state, ref) {
23
+ let { id: id, key: key, closeOnSelect: closeOnSelect, isVirtualized: isVirtualized, 'aria-haspopup': hasPopup, onPressStart: pressStartProp, onPressUp: pressUpProp, onPress: onPress, onPressChange: onPressChange, onPressEnd: onPressEnd, onHoverStart: hoverStartProp, onHoverChange: onHoverChange, onHoverEnd: onHoverEnd, onKeyDown: onKeyDown, onKeyUp: onKeyUp, onFocus: onFocus, onFocusChange: onFocusChange, onBlur: onBlur } = props;
24
+ let isTrigger = !!hasPopup;
25
+ var _props_isDisabled;
26
+ let isDisabled = (_props_isDisabled = props.isDisabled) !== null && _props_isDisabled !== void 0 ? _props_isDisabled : state.selectionManager.isDisabled(key);
27
+ var _props_isSelected;
28
+ let isSelected = (_props_isSelected = props.isSelected) !== null && _props_isSelected !== void 0 ? _props_isSelected : state.selectionManager.isSelected(key);
29
+ let data = (0, $d5336fe17ce95402$export$6f49b4016bfc8d56).get(state);
30
+ let item = state.collection.getItem(key);
31
+ let onClose = props.onClose || data.onClose;
32
+ let router = (0, $7Kjv5$useRouter)();
33
+ let performAction = (e)=>{
34
+ var _item_props;
35
+ if (isTrigger) return;
36
+ if (item === null || item === void 0 ? void 0 : (_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.onAction) item.props.onAction();
37
+ else if (props.onAction) props.onAction(key);
38
+ if (data.onAction) {
39
+ // Must reassign to variable otherwise `this` binding gets messed up. Something to do with WeakMap.
40
+ let onAction = data.onAction;
41
+ onAction(key);
42
+ }
43
+ if (e.target instanceof HTMLAnchorElement) router.open(e.target, e, item.props.href, item.props.routerOptions);
44
+ };
45
+ let role = 'menuitem';
46
+ if (!isTrigger) {
47
+ if (state.selectionManager.selectionMode === 'single') role = 'menuitemradio';
48
+ else if (state.selectionManager.selectionMode === 'multiple') role = 'menuitemcheckbox';
49
+ }
50
+ let labelId = (0, $7Kjv5$useSlotId)();
51
+ let descriptionId = (0, $7Kjv5$useSlotId)();
52
+ let keyboardId = (0, $7Kjv5$useSlotId)();
53
+ let ariaProps = {
54
+ id: id,
55
+ 'aria-disabled': isDisabled || undefined,
56
+ role: role,
57
+ 'aria-label': props['aria-label'],
58
+ 'aria-labelledby': labelId,
59
+ 'aria-describedby': [
60
+ descriptionId,
61
+ keyboardId
62
+ ].filter(Boolean).join(' ') || undefined,
63
+ 'aria-controls': props['aria-controls'],
64
+ 'aria-haspopup': hasPopup,
65
+ 'aria-expanded': props['aria-expanded']
66
+ };
67
+ if (state.selectionManager.selectionMode !== 'none' && !isTrigger) ariaProps['aria-checked'] = isSelected;
68
+ if (isVirtualized) {
69
+ ariaProps['aria-posinset'] = item === null || item === void 0 ? void 0 : item.index;
70
+ ariaProps['aria-setsize'] = (0, $7Kjv5$getItemCount)(state.collection);
71
+ }
72
+ let onPressStart = (e)=>{
73
+ if (e.pointerType === 'keyboard') performAction(e);
74
+ pressStartProp === null || pressStartProp === void 0 ? void 0 : pressStartProp(e);
75
+ };
76
+ let onPressUp = (e)=>{
77
+ if (e.pointerType !== 'keyboard') {
78
+ performAction(e);
79
+ // Pressing a menu item should close by default in single selection mode but not multiple
80
+ // selection mode, except if overridden by the closeOnSelect prop.
81
+ if (!isTrigger && onClose && (closeOnSelect !== null && closeOnSelect !== void 0 ? closeOnSelect : state.selectionManager.selectionMode !== 'multiple' || state.selectionManager.isLink(key))) onClose();
82
+ }
83
+ pressUpProp === null || pressUpProp === void 0 ? void 0 : pressUpProp(e);
84
+ };
85
+ let { itemProps: itemProps, isFocused: isFocused } = (0, $7Kjv5$useSelectableItem)({
86
+ selectionManager: state.selectionManager,
87
+ key: key,
88
+ ref: ref,
89
+ shouldSelectOnPressUp: true,
90
+ allowsDifferentPressOrigin: true,
91
+ // Disable all handling of links in useSelectable item
92
+ // because we handle it ourselves. The behavior of menus
93
+ // is slightly different from other collections because
94
+ // actions are performed on key down rather than key up.
95
+ linkBehavior: 'none'
96
+ });
97
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $7Kjv5$usePress)({
98
+ onPressStart: onPressStart,
99
+ onPress: onPress,
100
+ onPressUp: onPressUp,
101
+ onPressChange: onPressChange,
102
+ onPressEnd: onPressEnd,
103
+ isDisabled: isDisabled
104
+ });
105
+ let { hoverProps: hoverProps } = (0, $7Kjv5$useHover)({
106
+ isDisabled: isDisabled,
107
+ onHoverStart (e) {
108
+ if (!(0, $7Kjv5$isFocusVisible)()) {
109
+ state.selectionManager.setFocused(true);
110
+ state.selectionManager.setFocusedKey(key);
111
+ }
112
+ hoverStartProp === null || hoverStartProp === void 0 ? void 0 : hoverStartProp(e);
113
+ },
114
+ onHoverChange: onHoverChange,
115
+ onHoverEnd: onHoverEnd
116
+ });
117
+ let { keyboardProps: keyboardProps } = (0, $7Kjv5$useKeyboard)({
118
+ onKeyDown: (e)=>{
119
+ // Ignore repeating events, which may have started on the menu trigger before moving
120
+ // focus to the menu item. We want to wait for a second complete key press sequence.
121
+ if (e.repeat) {
122
+ e.continuePropagation();
123
+ return;
124
+ }
125
+ switch(e.key){
126
+ case ' ':
127
+ if (!isDisabled && state.selectionManager.selectionMode === 'none' && !isTrigger && closeOnSelect !== false && onClose) onClose();
128
+ break;
129
+ case 'Enter':
130
+ // The Enter key should always close on select, except if overridden.
131
+ if (!isDisabled && closeOnSelect !== false && !isTrigger && onClose) onClose();
132
+ break;
133
+ default:
134
+ if (!isTrigger) e.continuePropagation();
135
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
136
+ break;
137
+ }
138
+ },
139
+ onKeyUp: onKeyUp
140
+ });
141
+ let { focusProps: focusProps } = (0, $7Kjv5$useFocus)({
142
+ onBlur: onBlur,
143
+ onFocus: onFocus,
144
+ onFocusChange: onFocusChange
145
+ });
146
+ let domProps = (0, $7Kjv5$filterDOMProps)(item.props);
147
+ delete domProps.id;
148
+ let linkProps = (0, $7Kjv5$useLinkProps)(item.props);
149
+ return {
150
+ menuItemProps: {
151
+ ...ariaProps,
152
+ ...(0, $7Kjv5$mergeProps)(domProps, linkProps, isTrigger ? {
153
+ onFocus: itemProps.onFocus,
154
+ 'data-key': itemProps['data-key']
155
+ } : itemProps, pressProps, hoverProps, keyboardProps, focusProps),
156
+ tabIndex: itemProps.tabIndex != null ? -1 : undefined
157
+ },
158
+ labelProps: {
159
+ id: labelId
160
+ },
161
+ descriptionProps: {
162
+ id: descriptionId
163
+ },
164
+ keyboardShortcutProps: {
165
+ id: keyboardId
166
+ },
167
+ isFocused: isFocused,
168
+ isSelected: isSelected,
169
+ isPressed: isPressed,
170
+ isDisabled: isDisabled
171
+ };
172
+ }
173
+
174
+
175
+ export {$a2e5df62f93c7633$export$9d32628fc2aea7da as useMenuItem};
176
+ //# sourceMappingURL=useMenuItem.module.js.map