@react-aria/menu 3.13.2-nightly.4555 → 3.13.2-nightly.4560

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 (75) hide show
  1. package/dist/ar-AE.mjs +1 -1
  2. package/dist/bg-BG.mjs +1 -1
  3. package/dist/cs-CZ.mjs +1 -1
  4. package/dist/da-DK.mjs +1 -1
  5. package/dist/de-DE.mjs +1 -1
  6. package/dist/el-GR.mjs +1 -1
  7. package/dist/en-US.mjs +1 -1
  8. package/dist/es-ES.mjs +1 -1
  9. package/dist/et-EE.mjs +1 -1
  10. package/dist/fi-FI.mjs +1 -1
  11. package/dist/fr-FR.mjs +1 -1
  12. package/dist/he-IL.mjs +1 -1
  13. package/dist/hr-HR.mjs +1 -1
  14. package/dist/hu-HU.mjs +1 -1
  15. package/dist/import.mjs +5 -721
  16. package/dist/intlStrings.main.js +108 -0
  17. package/dist/intlStrings.main.js.map +1 -0
  18. package/dist/intlStrings.mjs +110 -0
  19. package/dist/intlStrings.module.js +110 -0
  20. package/dist/intlStrings.module.js.map +1 -0
  21. package/dist/it-IT.mjs +1 -1
  22. package/dist/ja-JP.mjs +1 -1
  23. package/dist/ko-KR.mjs +1 -1
  24. package/dist/lt-LT.mjs +1 -1
  25. package/dist/lv-LV.mjs +1 -1
  26. package/dist/main.js +10 -726
  27. package/dist/main.js.map +1 -1
  28. package/dist/module.js +5 -721
  29. package/dist/module.js.map +1 -1
  30. package/dist/nb-NO.mjs +1 -1
  31. package/dist/nl-NL.mjs +1 -1
  32. package/dist/pl-PL.mjs +1 -1
  33. package/dist/pt-BR.mjs +1 -1
  34. package/dist/pt-PT.mjs +1 -1
  35. package/dist/ro-RO.mjs +1 -1
  36. package/dist/ru-RU.mjs +1 -1
  37. package/dist/sk-SK.mjs +1 -1
  38. package/dist/sl-SI.mjs +1 -1
  39. package/dist/sr-SP.mjs +1 -1
  40. package/dist/sv-SE.mjs +1 -1
  41. package/dist/tr-TR.mjs +1 -1
  42. package/dist/uk-UA.mjs +1 -1
  43. package/dist/useMenu.main.js +59 -0
  44. package/dist/useMenu.main.js.map +1 -0
  45. package/dist/useMenu.mjs +53 -0
  46. package/dist/useMenu.module.js +53 -0
  47. package/dist/useMenu.module.js.map +1 -0
  48. package/dist/useMenuItem.main.js +175 -0
  49. package/dist/useMenuItem.main.js.map +1 -0
  50. package/dist/useMenuItem.mjs +170 -0
  51. package/dist/useMenuItem.module.js +170 -0
  52. package/dist/useMenuItem.module.js.map +1 -0
  53. package/dist/useMenuSection.main.js +43 -0
  54. package/dist/useMenuSection.main.js.map +1 -0
  55. package/dist/useMenuSection.mjs +38 -0
  56. package/dist/useMenuSection.module.js +38 -0
  57. package/dist/useMenuSection.module.js.map +1 -0
  58. package/dist/useMenuTrigger.main.js +103 -0
  59. package/dist/useMenuTrigger.main.js.map +1 -0
  60. package/dist/useMenuTrigger.mjs +98 -0
  61. package/dist/useMenuTrigger.module.js +98 -0
  62. package/dist/useMenuTrigger.module.js.map +1 -0
  63. package/dist/useSafelyMouseToSubmenu.main.js +134 -0
  64. package/dist/useSafelyMouseToSubmenu.main.js.map +1 -0
  65. package/dist/useSafelyMouseToSubmenu.mjs +129 -0
  66. package/dist/useSafelyMouseToSubmenu.module.js +129 -0
  67. package/dist/useSafelyMouseToSubmenu.module.js.map +1 -0
  68. package/dist/useSubmenuTrigger.main.js +169 -0
  69. package/dist/useSubmenuTrigger.main.js.map +1 -0
  70. package/dist/useSubmenuTrigger.mjs +164 -0
  71. package/dist/useSubmenuTrigger.module.js +164 -0
  72. package/dist/useSubmenuTrigger.module.js.map +1 -0
  73. package/dist/zh-CN.mjs +1 -1
  74. package/dist/zh-TW.mjs +1 -1
  75. package/package.json +14 -14
@@ -0,0 +1,169 @@
1
+ var $62347d8c4183e713$exports = require("./useSafelyMouseToSubmenu.main.js");
2
+ var $23MMN$react = require("react");
3
+ var $23MMN$reactariautils = require("@react-aria/utils");
4
+ var $23MMN$reactariai18n = require("@react-aria/i18n");
5
+
6
+
7
+ function $parcel$export(e, n, v, s) {
8
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
+ }
10
+
11
+ $parcel$export(module.exports, "UNSTABLE_useSubmenuTrigger", () => $5f4753043c9f6cdf$export$3819f8ee9f4ce664);
12
+ /*
13
+ * Copyright 2023 Adobe. All rights reserved.
14
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License. You may obtain a copy
16
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software distributed under
19
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20
+ * OF ANY KIND, either express or implied. See the License for the specific language
21
+ * governing permissions and limitations under the License.
22
+ */
23
+
24
+
25
+
26
+ function $5f4753043c9f6cdf$export$3819f8ee9f4ce664(props, state, ref) {
27
+ let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type = "menu", isDisabled: isDisabled, node: node, delay: delay = 200 } = props;
28
+ let submenuTriggerId = (0, $23MMN$reactariautils.useId)();
29
+ let overlayId = (0, $23MMN$reactariautils.useId)();
30
+ let { direction: direction } = (0, $23MMN$reactariai18n.useLocale)();
31
+ let openTimeout = (0, $23MMN$react.useRef)();
32
+ let cancelOpenTimeout = (0, $23MMN$react.useCallback)(()=>{
33
+ if (openTimeout.current) {
34
+ clearTimeout(openTimeout.current);
35
+ openTimeout.current = undefined;
36
+ }
37
+ }, [
38
+ openTimeout
39
+ ]);
40
+ let onSubmenuOpen = (0, $23MMN$reactariautils.useEffectEvent)((focusStrategy)=>{
41
+ cancelOpenTimeout();
42
+ state.open(focusStrategy);
43
+ });
44
+ let onSubmenuClose = (0, $23MMN$reactariautils.useEffectEvent)(()=>{
45
+ cancelOpenTimeout();
46
+ state.close();
47
+ });
48
+ (0, $23MMN$reactariautils.useLayoutEffect)(()=>{
49
+ return ()=>{
50
+ cancelOpenTimeout();
51
+ };
52
+ }, [
53
+ cancelOpenTimeout
54
+ ]);
55
+ let submenuKeyDown = (e)=>{
56
+ switch(e.key){
57
+ case "ArrowLeft":
58
+ if (direction === "ltr" && e.currentTarget.contains(e.target)) {
59
+ e.stopPropagation();
60
+ onSubmenuClose();
61
+ ref.current.focus();
62
+ }
63
+ break;
64
+ case "ArrowRight":
65
+ if (direction === "rtl" && e.currentTarget.contains(e.target)) {
66
+ e.stopPropagation();
67
+ onSubmenuClose();
68
+ ref.current.focus();
69
+ }
70
+ break;
71
+ case "Escape":
72
+ e.stopPropagation();
73
+ state.closeAll();
74
+ break;
75
+ }
76
+ };
77
+ let submenuProps = {
78
+ id: overlayId,
79
+ "aria-label": node.textValue,
80
+ submenuLevel: state.submenuLevel,
81
+ ...type === "menu" && {
82
+ onClose: state.closeAll,
83
+ autoFocus: state.focusStrategy,
84
+ onKeyDown: submenuKeyDown
85
+ }
86
+ };
87
+ let submenuTriggerKeyDown = (e)=>{
88
+ switch(e.key){
89
+ case "ArrowRight":
90
+ if (!isDisabled) {
91
+ if (direction === "ltr") {
92
+ if (!state.isOpen) onSubmenuOpen("first");
93
+ if (type === "menu" && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) submenuRef.current.focus();
94
+ } else if (state.isOpen) onSubmenuClose();
95
+ else e.continuePropagation();
96
+ }
97
+ break;
98
+ case "ArrowLeft":
99
+ if (!isDisabled) {
100
+ if (direction === "rtl") {
101
+ if (!state.isOpen) onSubmenuOpen("first");
102
+ if (type === "menu" && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) submenuRef.current.focus();
103
+ } else if (state.isOpen) onSubmenuClose();
104
+ else e.continuePropagation();
105
+ }
106
+ break;
107
+ case "Escape":
108
+ state.closeAll();
109
+ break;
110
+ default:
111
+ e.continuePropagation();
112
+ break;
113
+ }
114
+ };
115
+ let onPressStart = (e)=>{
116
+ if (!isDisabled && (e.pointerType === "virtual" || e.pointerType === "keyboard")) // If opened with a screen reader or keyboard, auto focus the first submenu item.
117
+ onSubmenuOpen("first");
118
+ };
119
+ let onPress = (e)=>{
120
+ if (!isDisabled && (e.pointerType === "touch" || e.pointerType === "mouse")) // For touch or on a desktop device with a small screen open on press up to possible problems with
121
+ // press up happening on the newly opened tray items
122
+ onSubmenuOpen();
123
+ };
124
+ let onHoverChange = (isHovered)=>{
125
+ if (!isDisabled) {
126
+ if (isHovered && !state.isOpen) {
127
+ if (!openTimeout.current) openTimeout.current = setTimeout(()=>{
128
+ onSubmenuOpen();
129
+ }, delay);
130
+ } else if (!isHovered) cancelOpenTimeout();
131
+ }
132
+ };
133
+ let onBlur = (e)=>{
134
+ if (state.isOpen && parentMenuRef.current.contains(e.relatedTarget)) onSubmenuClose();
135
+ };
136
+ let shouldCloseOnInteractOutside = (target)=>{
137
+ if (target !== ref.current) return true;
138
+ return false;
139
+ };
140
+ (0, $62347d8c4183e713$exports.useSafelyMouseToSubmenu)({
141
+ menuRef: parentMenuRef,
142
+ submenuRef: submenuRef,
143
+ isOpen: state.isOpen,
144
+ isDisabled: isDisabled
145
+ });
146
+ return {
147
+ submenuTriggerProps: {
148
+ id: submenuTriggerId,
149
+ "aria-controls": state.isOpen ? overlayId : undefined,
150
+ "aria-haspopup": !isDisabled ? type : undefined,
151
+ "aria-expanded": state.isOpen ? "true" : "false",
152
+ onPressStart: onPressStart,
153
+ onPress: onPress,
154
+ onHoverChange: onHoverChange,
155
+ onKeyDown: submenuTriggerKeyDown,
156
+ onBlur: onBlur,
157
+ isOpen: state.isOpen
158
+ },
159
+ submenuProps: submenuProps,
160
+ popoverProps: {
161
+ isNonModal: true,
162
+ disableFocusManagement: true,
163
+ shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
164
+ }
165
+ };
166
+ }
167
+
168
+
169
+ //# sourceMappingURL=useSubmenuTrigger.main.js.map
@@ -0,0 +1 @@
1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,IAAI,CAAC,YAAY;YACf,IAAI,aAAa,CAAC,MAAM,MAAM,EAC5B;gBAAA,IAAI,CAAC,YAAY,OAAO,EACtB,YAAY,OAAO,GAAG,WAAW;oBAC/B;gBACF,GAAG;YACL,OACK,IAAI,CAAC,WACV;QAEJ;IACF;IAEA,IAAI,SAAS,CAAC;QACZ,IAAI,MAAM,MAAM,IAAI,cAAc,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa,GAChE;IAEJ;IAEA,IAAI,+BAA+B,CAAC;QAClC,IAAI,WAAW,IAAI,OAAO,EACxB,OAAO;QAGT,OAAO;IACT;IAEA,CAAA,GAAA,iDAAsB,EAAE;QAAC,SAAS;oBAAe;QAAY,QAAQ,MAAM,MAAM;QAAE,YAAY;IAAU;IAEzG,OAAO;QACL,qBAAqB;YACnB,IAAI;YACJ,iBAAiB,MAAM,MAAM,GAAG,YAAY;YAC5C,iBAAiB,CAAC,aAAa,OAAO;YACtC,iBAAiB,MAAM,MAAM,GAAG,SAAS;0BACzC;qBACA;2BACA;YACA,WAAW;oBACX;YACA,QAAQ,MAAM,MAAM;QACtB;sBACA;QACA,cAAc;YACZ,YAAY;YACZ,wBAAwB;0CACxB;QACF;IACF;AACF","sources":["packages/@react-aria/menu/src/useSubmenuTrigger.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {AriaMenuItemProps} from './useMenuItem';\nimport {AriaMenuOptions} from './useMenu';\nimport type {AriaPopoverProps, OverlayProps} from '@react-aria/overlays';\nimport {FocusableElement, FocusStrategy, KeyboardEvent, PressEvent, Node as RSNode} from '@react-types/shared';\nimport {RefObject, useCallback, useRef} from 'react';\nimport type {SubmenuTriggerState} from '@react-stately/menu';\nimport {useEffectEvent, useId, useLayoutEffect} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\nimport {useSafelyMouseToSubmenu} from './useSafelyMouseToSubmenu';\n\nexport interface AriaSubmenuTriggerProps {\n /** An object representing the submenu trigger menu item. Contains all the relevant information that makes up the menu item. */\n node: RSNode<unknown>,\n /** Whether the submenu trigger is disabled. */\n isDisabled?: boolean,\n /** The type of the contents that the submenu trigger opens. */\n type?: 'dialog' | 'menu',\n /** Ref of the menu that contains the submenu trigger. */\n parentMenuRef: RefObject<HTMLElement>,\n /** Ref of the submenu opened by the submenu trigger. */\n submenuRef: RefObject<HTMLElement>,\n /**\n * The delay time in milliseconds for the submenu to appear after hovering over the trigger.\n * @default 200\n */\n delay?: number\n}\n\ninterface SubmenuTriggerProps extends AriaMenuItemProps {\n /** Whether the submenu trigger is in an expanded state. */\n isOpen: boolean\n}\n\ninterface SubmenuProps<T> extends AriaMenuOptions<T> {\n /** The level of the submenu. */\n submenuLevel: number\n}\n\nexport interface SubmenuTriggerAria<T> {\n /** Props for the submenu trigger menu item. */\n submenuTriggerProps: SubmenuTriggerProps,\n /** Props for the submenu controlled by the submenu trigger menu item. */\n submenuProps: SubmenuProps<T>,\n /** Props for the submenu's popover container. */\n popoverProps: Pick<AriaPopoverProps, 'isNonModal' | 'shouldCloseOnInteractOutside'> & Pick<OverlayProps, 'disableFocusManagement'>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a submenu trigger and its associated submenu.\n * @param props - Props for the submenu trigger and refs attach to its submenu and parent menu.\n * @param state - State for the submenu trigger.\n * @param ref - Ref to the submenu trigger element.\n */\nexport function UNSTABLE_useSubmenuTrigger<T>(props: AriaSubmenuTriggerProps, state: SubmenuTriggerState, ref: RefObject<FocusableElement>): SubmenuTriggerAria<T> {\n let {parentMenuRef, submenuRef, type = 'menu', isDisabled, node, delay = 200} = props;\n let submenuTriggerId = useId();\n let overlayId = useId();\n let {direction} = useLocale();\n let openTimeout = useRef<ReturnType<typeof setTimeout> | undefined>();\n let cancelOpenTimeout = useCallback(() => {\n if (openTimeout.current) {\n clearTimeout(openTimeout.current);\n openTimeout.current = undefined;\n }\n }, [openTimeout]);\n\n let onSubmenuOpen = useEffectEvent((focusStrategy?: FocusStrategy) => {\n cancelOpenTimeout();\n state.open(focusStrategy);\n });\n\n let onSubmenuClose = useEffectEvent(() => {\n cancelOpenTimeout();\n state.close();\n });\n\n useLayoutEffect(() => {\n return () => {\n cancelOpenTimeout();\n };\n }, [cancelOpenTimeout]);\n\n let submenuKeyDown = (e: KeyboardEvent) => {\n switch (e.key) {\n case 'ArrowLeft':\n if (direction === 'ltr' && e.currentTarget.contains(e.target as Element)) {\n e.stopPropagation();\n onSubmenuClose();\n ref.current.focus();\n }\n break;\n case 'ArrowRight':\n if (direction === 'rtl' && e.currentTarget.contains(e.target as Element)) {\n e.stopPropagation();\n onSubmenuClose();\n ref.current.focus();\n }\n break;\n case 'Escape':\n e.stopPropagation();\n state.closeAll();\n break;\n }\n };\n\n let submenuProps = {\n id: overlayId,\n 'aria-label': node.textValue,\n submenuLevel: state.submenuLevel,\n ...(type === 'menu' && {\n onClose: state.closeAll,\n autoFocus: state.focusStrategy,\n onKeyDown: submenuKeyDown\n })\n };\n\n let submenuTriggerKeyDown = (e: KeyboardEvent) => {\n switch (e.key) {\n case 'ArrowRight':\n if (!isDisabled) {\n if (direction === 'ltr') {\n if (!state.isOpen) {\n onSubmenuOpen('first');\n }\n\n if (type === 'menu' && !!submenuRef?.current && document.activeElement === ref?.current) {\n submenuRef.current.focus();\n }\n } else if (state.isOpen) {\n onSubmenuClose();\n } else {\n e.continuePropagation();\n }\n }\n\n break;\n case 'ArrowLeft':\n if (!isDisabled) {\n if (direction === 'rtl') {\n if (!state.isOpen) {\n onSubmenuOpen('first');\n }\n\n if (type === 'menu' && !!submenuRef?.current && document.activeElement === ref?.current) {\n submenuRef.current.focus();\n }\n } else if (state.isOpen) {\n onSubmenuClose();\n } else {\n e.continuePropagation();\n }\n }\n break;\n case 'Escape':\n state.closeAll();\n break;\n default:\n e.continuePropagation();\n break;\n }\n };\n\n let onPressStart = (e: PressEvent) => {\n if (!isDisabled && (e.pointerType === 'virtual' || e.pointerType === 'keyboard')) {\n // If opened with a screen reader or keyboard, auto focus the first submenu item.\n onSubmenuOpen('first');\n }\n };\n\n let onPress = (e: PressEvent) => {\n if (!isDisabled && (e.pointerType === 'touch' || e.pointerType === 'mouse')) {\n // For touch or on a desktop device with a small screen open on press up to possible problems with\n // press up happening on the newly opened tray items\n onSubmenuOpen();\n }\n };\n\n let onHoverChange = (isHovered) => {\n if (!isDisabled) {\n if (isHovered && !state.isOpen) {\n if (!openTimeout.current) {\n openTimeout.current = setTimeout(() => {\n onSubmenuOpen();\n }, delay);\n }\n } else if (!isHovered) {\n cancelOpenTimeout();\n }\n }\n };\n\n let onBlur = (e) => {\n if (state.isOpen && parentMenuRef.current.contains(e.relatedTarget)) {\n onSubmenuClose();\n }\n };\n\n let shouldCloseOnInteractOutside = (target) => {\n if (target !== ref.current) {\n return true;\n }\n\n return false;\n };\n\n useSafelyMouseToSubmenu({menuRef: parentMenuRef, submenuRef, isOpen: state.isOpen, isDisabled: isDisabled});\n\n return {\n submenuTriggerProps: {\n id: submenuTriggerId,\n 'aria-controls': state.isOpen ? overlayId : undefined,\n 'aria-haspopup': !isDisabled ? type : undefined,\n 'aria-expanded': state.isOpen ? 'true' : 'false',\n onPressStart,\n onPress,\n onHoverChange,\n onKeyDown: submenuTriggerKeyDown,\n onBlur,\n isOpen: state.isOpen\n },\n submenuProps,\n popoverProps: {\n isNonModal: true,\n disableFocusManagement: true,\n shouldCloseOnInteractOutside\n }\n };\n}\n"],"names":[],"version":3,"file":"useSubmenuTrigger.main.js.map"}
@@ -0,0 +1,164 @@
1
+ import {useSafelyMouseToSubmenu as $d275435c250248f8$export$85ec83e04c95f50a} from "./useSafelyMouseToSubmenu.mjs";
2
+ import {useRef as $dXlYe$useRef, useCallback as $dXlYe$useCallback} from "react";
3
+ import {useId as $dXlYe$useId, useEffectEvent as $dXlYe$useEffectEvent, useLayoutEffect as $dXlYe$useLayoutEffect} from "@react-aria/utils";
4
+ import {useLocale as $dXlYe$useLocale} from "@react-aria/i18n";
5
+
6
+ /*
7
+ * Copyright 2023 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $0065b146e7192841$export$3819f8ee9f4ce664(props, state, ref) {
21
+ let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type = "menu", isDisabled: isDisabled, node: node, delay: delay = 200 } = props;
22
+ let submenuTriggerId = (0, $dXlYe$useId)();
23
+ let overlayId = (0, $dXlYe$useId)();
24
+ let { direction: direction } = (0, $dXlYe$useLocale)();
25
+ let openTimeout = (0, $dXlYe$useRef)();
26
+ let cancelOpenTimeout = (0, $dXlYe$useCallback)(()=>{
27
+ if (openTimeout.current) {
28
+ clearTimeout(openTimeout.current);
29
+ openTimeout.current = undefined;
30
+ }
31
+ }, [
32
+ openTimeout
33
+ ]);
34
+ let onSubmenuOpen = (0, $dXlYe$useEffectEvent)((focusStrategy)=>{
35
+ cancelOpenTimeout();
36
+ state.open(focusStrategy);
37
+ });
38
+ let onSubmenuClose = (0, $dXlYe$useEffectEvent)(()=>{
39
+ cancelOpenTimeout();
40
+ state.close();
41
+ });
42
+ (0, $dXlYe$useLayoutEffect)(()=>{
43
+ return ()=>{
44
+ cancelOpenTimeout();
45
+ };
46
+ }, [
47
+ cancelOpenTimeout
48
+ ]);
49
+ let submenuKeyDown = (e)=>{
50
+ switch(e.key){
51
+ case "ArrowLeft":
52
+ if (direction === "ltr" && e.currentTarget.contains(e.target)) {
53
+ e.stopPropagation();
54
+ onSubmenuClose();
55
+ ref.current.focus();
56
+ }
57
+ break;
58
+ case "ArrowRight":
59
+ if (direction === "rtl" && e.currentTarget.contains(e.target)) {
60
+ e.stopPropagation();
61
+ onSubmenuClose();
62
+ ref.current.focus();
63
+ }
64
+ break;
65
+ case "Escape":
66
+ e.stopPropagation();
67
+ state.closeAll();
68
+ break;
69
+ }
70
+ };
71
+ let submenuProps = {
72
+ id: overlayId,
73
+ "aria-label": node.textValue,
74
+ submenuLevel: state.submenuLevel,
75
+ ...type === "menu" && {
76
+ onClose: state.closeAll,
77
+ autoFocus: state.focusStrategy,
78
+ onKeyDown: submenuKeyDown
79
+ }
80
+ };
81
+ let submenuTriggerKeyDown = (e)=>{
82
+ switch(e.key){
83
+ case "ArrowRight":
84
+ if (!isDisabled) {
85
+ if (direction === "ltr") {
86
+ if (!state.isOpen) onSubmenuOpen("first");
87
+ if (type === "menu" && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) submenuRef.current.focus();
88
+ } else if (state.isOpen) onSubmenuClose();
89
+ else e.continuePropagation();
90
+ }
91
+ break;
92
+ case "ArrowLeft":
93
+ if (!isDisabled) {
94
+ if (direction === "rtl") {
95
+ if (!state.isOpen) onSubmenuOpen("first");
96
+ if (type === "menu" && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) submenuRef.current.focus();
97
+ } else if (state.isOpen) onSubmenuClose();
98
+ else e.continuePropagation();
99
+ }
100
+ break;
101
+ case "Escape":
102
+ state.closeAll();
103
+ break;
104
+ default:
105
+ e.continuePropagation();
106
+ break;
107
+ }
108
+ };
109
+ let onPressStart = (e)=>{
110
+ if (!isDisabled && (e.pointerType === "virtual" || e.pointerType === "keyboard")) // If opened with a screen reader or keyboard, auto focus the first submenu item.
111
+ onSubmenuOpen("first");
112
+ };
113
+ let onPress = (e)=>{
114
+ if (!isDisabled && (e.pointerType === "touch" || e.pointerType === "mouse")) // For touch or on a desktop device with a small screen open on press up to possible problems with
115
+ // press up happening on the newly opened tray items
116
+ onSubmenuOpen();
117
+ };
118
+ let onHoverChange = (isHovered)=>{
119
+ if (!isDisabled) {
120
+ if (isHovered && !state.isOpen) {
121
+ if (!openTimeout.current) openTimeout.current = setTimeout(()=>{
122
+ onSubmenuOpen();
123
+ }, delay);
124
+ } else if (!isHovered) cancelOpenTimeout();
125
+ }
126
+ };
127
+ let onBlur = (e)=>{
128
+ if (state.isOpen && parentMenuRef.current.contains(e.relatedTarget)) onSubmenuClose();
129
+ };
130
+ let shouldCloseOnInteractOutside = (target)=>{
131
+ if (target !== ref.current) return true;
132
+ return false;
133
+ };
134
+ (0, $d275435c250248f8$export$85ec83e04c95f50a)({
135
+ menuRef: parentMenuRef,
136
+ submenuRef: submenuRef,
137
+ isOpen: state.isOpen,
138
+ isDisabled: isDisabled
139
+ });
140
+ return {
141
+ submenuTriggerProps: {
142
+ id: submenuTriggerId,
143
+ "aria-controls": state.isOpen ? overlayId : undefined,
144
+ "aria-haspopup": !isDisabled ? type : undefined,
145
+ "aria-expanded": state.isOpen ? "true" : "false",
146
+ onPressStart: onPressStart,
147
+ onPress: onPress,
148
+ onHoverChange: onHoverChange,
149
+ onKeyDown: submenuTriggerKeyDown,
150
+ onBlur: onBlur,
151
+ isOpen: state.isOpen
152
+ },
153
+ submenuProps: submenuProps,
154
+ popoverProps: {
155
+ isNonModal: true,
156
+ disableFocusManagement: true,
157
+ shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
158
+ }
159
+ };
160
+ }
161
+
162
+
163
+ export {$0065b146e7192841$export$3819f8ee9f4ce664 as UNSTABLE_useSubmenuTrigger};
164
+ //# sourceMappingURL=useSubmenuTrigger.mjs.map
@@ -0,0 +1,164 @@
1
+ import {useSafelyMouseToSubmenu as $d275435c250248f8$export$85ec83e04c95f50a} from "./useSafelyMouseToSubmenu.module.js";
2
+ import {useRef as $dXlYe$useRef, useCallback as $dXlYe$useCallback} from "react";
3
+ import {useId as $dXlYe$useId, useEffectEvent as $dXlYe$useEffectEvent, useLayoutEffect as $dXlYe$useLayoutEffect} from "@react-aria/utils";
4
+ import {useLocale as $dXlYe$useLocale} from "@react-aria/i18n";
5
+
6
+ /*
7
+ * Copyright 2023 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $0065b146e7192841$export$3819f8ee9f4ce664(props, state, ref) {
21
+ let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type = "menu", isDisabled: isDisabled, node: node, delay: delay = 200 } = props;
22
+ let submenuTriggerId = (0, $dXlYe$useId)();
23
+ let overlayId = (0, $dXlYe$useId)();
24
+ let { direction: direction } = (0, $dXlYe$useLocale)();
25
+ let openTimeout = (0, $dXlYe$useRef)();
26
+ let cancelOpenTimeout = (0, $dXlYe$useCallback)(()=>{
27
+ if (openTimeout.current) {
28
+ clearTimeout(openTimeout.current);
29
+ openTimeout.current = undefined;
30
+ }
31
+ }, [
32
+ openTimeout
33
+ ]);
34
+ let onSubmenuOpen = (0, $dXlYe$useEffectEvent)((focusStrategy)=>{
35
+ cancelOpenTimeout();
36
+ state.open(focusStrategy);
37
+ });
38
+ let onSubmenuClose = (0, $dXlYe$useEffectEvent)(()=>{
39
+ cancelOpenTimeout();
40
+ state.close();
41
+ });
42
+ (0, $dXlYe$useLayoutEffect)(()=>{
43
+ return ()=>{
44
+ cancelOpenTimeout();
45
+ };
46
+ }, [
47
+ cancelOpenTimeout
48
+ ]);
49
+ let submenuKeyDown = (e)=>{
50
+ switch(e.key){
51
+ case "ArrowLeft":
52
+ if (direction === "ltr" && e.currentTarget.contains(e.target)) {
53
+ e.stopPropagation();
54
+ onSubmenuClose();
55
+ ref.current.focus();
56
+ }
57
+ break;
58
+ case "ArrowRight":
59
+ if (direction === "rtl" && e.currentTarget.contains(e.target)) {
60
+ e.stopPropagation();
61
+ onSubmenuClose();
62
+ ref.current.focus();
63
+ }
64
+ break;
65
+ case "Escape":
66
+ e.stopPropagation();
67
+ state.closeAll();
68
+ break;
69
+ }
70
+ };
71
+ let submenuProps = {
72
+ id: overlayId,
73
+ "aria-label": node.textValue,
74
+ submenuLevel: state.submenuLevel,
75
+ ...type === "menu" && {
76
+ onClose: state.closeAll,
77
+ autoFocus: state.focusStrategy,
78
+ onKeyDown: submenuKeyDown
79
+ }
80
+ };
81
+ let submenuTriggerKeyDown = (e)=>{
82
+ switch(e.key){
83
+ case "ArrowRight":
84
+ if (!isDisabled) {
85
+ if (direction === "ltr") {
86
+ if (!state.isOpen) onSubmenuOpen("first");
87
+ if (type === "menu" && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) submenuRef.current.focus();
88
+ } else if (state.isOpen) onSubmenuClose();
89
+ else e.continuePropagation();
90
+ }
91
+ break;
92
+ case "ArrowLeft":
93
+ if (!isDisabled) {
94
+ if (direction === "rtl") {
95
+ if (!state.isOpen) onSubmenuOpen("first");
96
+ if (type === "menu" && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) submenuRef.current.focus();
97
+ } else if (state.isOpen) onSubmenuClose();
98
+ else e.continuePropagation();
99
+ }
100
+ break;
101
+ case "Escape":
102
+ state.closeAll();
103
+ break;
104
+ default:
105
+ e.continuePropagation();
106
+ break;
107
+ }
108
+ };
109
+ let onPressStart = (e)=>{
110
+ if (!isDisabled && (e.pointerType === "virtual" || e.pointerType === "keyboard")) // If opened with a screen reader or keyboard, auto focus the first submenu item.
111
+ onSubmenuOpen("first");
112
+ };
113
+ let onPress = (e)=>{
114
+ if (!isDisabled && (e.pointerType === "touch" || e.pointerType === "mouse")) // For touch or on a desktop device with a small screen open on press up to possible problems with
115
+ // press up happening on the newly opened tray items
116
+ onSubmenuOpen();
117
+ };
118
+ let onHoverChange = (isHovered)=>{
119
+ if (!isDisabled) {
120
+ if (isHovered && !state.isOpen) {
121
+ if (!openTimeout.current) openTimeout.current = setTimeout(()=>{
122
+ onSubmenuOpen();
123
+ }, delay);
124
+ } else if (!isHovered) cancelOpenTimeout();
125
+ }
126
+ };
127
+ let onBlur = (e)=>{
128
+ if (state.isOpen && parentMenuRef.current.contains(e.relatedTarget)) onSubmenuClose();
129
+ };
130
+ let shouldCloseOnInteractOutside = (target)=>{
131
+ if (target !== ref.current) return true;
132
+ return false;
133
+ };
134
+ (0, $d275435c250248f8$export$85ec83e04c95f50a)({
135
+ menuRef: parentMenuRef,
136
+ submenuRef: submenuRef,
137
+ isOpen: state.isOpen,
138
+ isDisabled: isDisabled
139
+ });
140
+ return {
141
+ submenuTriggerProps: {
142
+ id: submenuTriggerId,
143
+ "aria-controls": state.isOpen ? overlayId : undefined,
144
+ "aria-haspopup": !isDisabled ? type : undefined,
145
+ "aria-expanded": state.isOpen ? "true" : "false",
146
+ onPressStart: onPressStart,
147
+ onPress: onPress,
148
+ onHoverChange: onHoverChange,
149
+ onKeyDown: submenuTriggerKeyDown,
150
+ onBlur: onBlur,
151
+ isOpen: state.isOpen
152
+ },
153
+ submenuProps: submenuProps,
154
+ popoverProps: {
155
+ isNonModal: true,
156
+ disableFocusManagement: true,
157
+ shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
158
+ }
159
+ };
160
+ }
161
+
162
+
163
+ export {$0065b146e7192841$export$3819f8ee9f4ce664 as UNSTABLE_useSubmenuTrigger};
164
+ //# sourceMappingURL=useSubmenuTrigger.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAuDM,SAAS,0CAA8B,KAA8B,EAAE,KAA0B,EAAE,GAAgC;IACxI,IAAI,iBAAC,aAAa,cAAE,UAAU,QAAE,OAAO,oBAAQ,UAAU,QAAE,IAAI,SAAE,QAAQ,KAAI,GAAG;IAChF,IAAI,mBAAmB,CAAA,GAAA,YAAI;IAC3B,IAAI,YAAY,CAAA,GAAA,YAAI;IACpB,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,cAAc,CAAA,GAAA,aAAK;IACvB,IAAI,oBAAoB,CAAA,GAAA,kBAAU,EAAE;QAClC,IAAI,YAAY,OAAO,EAAE;YACvB,aAAa,YAAY,OAAO;YAChC,YAAY,OAAO,GAAG;QACxB;IACF,GAAG;QAAC;KAAY;IAEhB,IAAI,gBAAgB,CAAA,GAAA,qBAAa,EAAE,CAAC;QAClC;QACA,MAAM,IAAI,CAAC;IACb;IAEA,IAAI,iBAAiB,CAAA,GAAA,qBAAa,EAAE;QAClC;QACA,MAAM,KAAK;IACb;IAEA,CAAA,GAAA,sBAAc,EAAE;QACd,OAAO;YACL;QACF;IACF,GAAG;QAAC;KAAkB;IAEtB,IAAI,iBAAiB,CAAC;QACpB,OAAQ,EAAE,GAAG;YACX,KAAK;gBACH,IAAI,cAAc,SAAS,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAc;oBACxE,EAAE,eAAe;oBACjB;oBACA,IAAI,OAAO,CAAC,KAAK;gBACnB;gBACA;YACF,KAAK;gBACH,IAAI,cAAc,SAAS,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAc;oBACxE,EAAE,eAAe;oBACjB;oBACA,IA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AC,cAAe,CAAA,EAAE,WAAW,KAAK,WAAW,EAAE,WAAW,KAAK,OAAM,GACvE,kGAAkG;QAClG,oDAAoD;QACpD;IAEJ;IAEA,IAAI,gBAAgB,CAAC;QACnB,IAAI,CAAC,YAAY;YACf,IAAI,aAAa,CAAC,MAAM,MAAM,EAC5B;gBAAA,IAAI,CAAC,YAAY,OAAO,EACtB,YAAY,OAAO,GAAG,WAAW;oBAC/B;gBACF,GAAG;YACL,OACK,IAAI,CAAC,WACV;QAEJ;IACF;IAEA,IAAI,SAAS,CAAC;QACZ,IAAI,MAAM,MAAM,IAAI,cAAc,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa,GAChE;IAEJ;IAEA,IAAI,+BAA+B,CAAC;QAClC,IAAI,WAAW,IAAI,OAAO,EACxB,OAAO;QAGT,OAAO;IACT;IAEA,CAAA,GAAA,yCAAsB,EAAE;QAAC,SAAS;oBAAe;QAAY,QAAQ,MAAM,MAAM;QAAE,YAAY;IAAU;IAEzG,OAAO;QACL,qBAAqB;YACnB,IAAI;YACJ,iBAAiB,MAAM,MAAM,GAAG,YAAY;YAC5C,iBAAiB,CAAC,aAAa,OAAO;YACtC,iBAAiB,MAAM,MAAM,GAAG,SAAS;0BACzC;qBACA;2BACA;YACA,WAAW;oBACX;YACA,QAAQ,MAAM,MAAM;QACtB;sBACA;QACA,cAAc;YACZ,YAAY;YACZ,wBAAwB;0CACxB;QACF;IACF;AACF","sources":["packages/@react-aria/menu/src/useSubmenuTrigger.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {AriaMenuItemProps} from './useMenuItem';\nimport {AriaMenuOptions} from './useMenu';\nimport type {AriaPopoverProps, OverlayProps} from '@react-aria/overlays';\nimport {FocusableElement, FocusStrategy, KeyboardEvent, PressEvent, Node as RSNode} from '@react-types/shared';\nimport {RefObject, useCallback, useRef} from 'react';\nimport type {SubmenuTriggerState} from '@react-stately/menu';\nimport {useEffectEvent, useId, useLayoutEffect} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\nimport {useSafelyMouseToSubmenu} from './useSafelyMouseToSubmenu';\n\nexport interface AriaSubmenuTriggerProps {\n /** An object representing the submenu trigger menu item. Contains all the relevant information that makes up the menu item. */\n node: RSNode<unknown>,\n /** Whether the submenu trigger is disabled. */\n isDisabled?: boolean,\n /** The type of the contents that the submenu trigger opens. */\n type?: 'dialog' | 'menu',\n /** Ref of the menu that contains the submenu trigger. */\n parentMenuRef: RefObject<HTMLElement>,\n /** Ref of the submenu opened by the submenu trigger. */\n submenuRef: RefObject<HTMLElement>,\n /**\n * The delay time in milliseconds for the submenu to appear after hovering over the trigger.\n * @default 200\n */\n delay?: number\n}\n\ninterface SubmenuTriggerProps extends AriaMenuItemProps {\n /** Whether the submenu trigger is in an expanded state. */\n isOpen: boolean\n}\n\ninterface SubmenuProps<T> extends AriaMenuOptions<T> {\n /** The level of the submenu. */\n submenuLevel: number\n}\n\nexport interface SubmenuTriggerAria<T> {\n /** Props for the submenu trigger menu item. */\n submenuTriggerProps: SubmenuTriggerProps,\n /** Props for the submenu controlled by the submenu trigger menu item. */\n submenuProps: SubmenuProps<T>,\n /** Props for the submenu's popover container. */\n popoverProps: Pick<AriaPopoverProps, 'isNonModal' | 'shouldCloseOnInteractOutside'> & Pick<OverlayProps, 'disableFocusManagement'>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a submenu trigger and its associated submenu.\n * @param props - Props for the submenu trigger and refs attach to its submenu and parent menu.\n * @param state - State for the submenu trigger.\n * @param ref - Ref to the submenu trigger element.\n */\nexport function UNSTABLE_useSubmenuTrigger<T>(props: AriaSubmenuTriggerProps, state: SubmenuTriggerState, ref: RefObject<FocusableElement>): SubmenuTriggerAria<T> {\n let {parentMenuRef, submenuRef, type = 'menu', isDisabled, node, delay = 200} = props;\n let submenuTriggerId = useId();\n let overlayId = useId();\n let {direction} = useLocale();\n let openTimeout = useRef<ReturnType<typeof setTimeout> | undefined>();\n let cancelOpenTimeout = useCallback(() => {\n if (openTimeout.current) {\n clearTimeout(openTimeout.current);\n openTimeout.current = undefined;\n }\n }, [openTimeout]);\n\n let onSubmenuOpen = useEffectEvent((focusStrategy?: FocusStrategy) => {\n cancelOpenTimeout();\n state.open(focusStrategy);\n });\n\n let onSubmenuClose = useEffectEvent(() => {\n cancelOpenTimeout();\n state.close();\n });\n\n useLayoutEffect(() => {\n return () => {\n cancelOpenTimeout();\n };\n }, [cancelOpenTimeout]);\n\n let submenuKeyDown = (e: KeyboardEvent) => {\n switch (e.key) {\n case 'ArrowLeft':\n if (direction === 'ltr' && e.currentTarget.contains(e.target as Element)) {\n e.stopPropagation();\n onSubmenuClose();\n ref.current.focus();\n }\n break;\n case 'ArrowRight':\n if (direction === 'rtl' && e.currentTarget.contains(e.target as Element)) {\n e.stopPropagation();\n onSubmenuClose();\n ref.current.focus();\n }\n break;\n case 'Escape':\n e.stopPropagation();\n state.closeAll();\n break;\n }\n };\n\n let submenuProps = {\n id: overlayId,\n 'aria-label': node.textValue,\n submenuLevel: state.submenuLevel,\n ...(type === 'menu' && {\n onClose: state.closeAll,\n autoFocus: state.focusStrategy,\n onKeyDown: submenuKeyDown\n })\n };\n\n let submenuTriggerKeyDown = (e: KeyboardEvent) => {\n switch (e.key) {\n case 'ArrowRight':\n if (!isDisabled) {\n if (direction === 'ltr') {\n if (!state.isOpen) {\n onSubmenuOpen('first');\n }\n\n if (type === 'menu' && !!submenuRef?.current && document.activeElement === ref?.current) {\n submenuRef.current.focus();\n }\n } else if (state.isOpen) {\n onSubmenuClose();\n } else {\n e.continuePropagation();\n }\n }\n\n break;\n case 'ArrowLeft':\n if (!isDisabled) {\n if (direction === 'rtl') {\n if (!state.isOpen) {\n onSubmenuOpen('first');\n }\n\n if (type === 'menu' && !!submenuRef?.current && document.activeElement === ref?.current) {\n submenuRef.current.focus();\n }\n } else if (state.isOpen) {\n onSubmenuClose();\n } else {\n e.continuePropagation();\n }\n }\n break;\n case 'Escape':\n state.closeAll();\n break;\n default:\n e.continuePropagation();\n break;\n }\n };\n\n let onPressStart = (e: PressEvent) => {\n if (!isDisabled && (e.pointerType === 'virtual' || e.pointerType === 'keyboard')) {\n // If opened with a screen reader or keyboard, auto focus the first submenu item.\n onSubmenuOpen('first');\n }\n };\n\n let onPress = (e: PressEvent) => {\n if (!isDisabled && (e.pointerType === 'touch' || e.pointerType === 'mouse')) {\n // For touch or on a desktop device with a small screen open on press up to possible problems with\n // press up happening on the newly opened tray items\n onSubmenuOpen();\n }\n };\n\n let onHoverChange = (isHovered) => {\n if (!isDisabled) {\n if (isHovered && !state.isOpen) {\n if (!openTimeout.current) {\n openTimeout.current = setTimeout(() => {\n onSubmenuOpen();\n }, delay);\n }\n } else if (!isHovered) {\n cancelOpenTimeout();\n }\n }\n };\n\n let onBlur = (e) => {\n if (state.isOpen && parentMenuRef.current.contains(e.relatedTarget)) {\n onSubmenuClose();\n }\n };\n\n let shouldCloseOnInteractOutside = (target) => {\n if (target !== ref.current) {\n return true;\n }\n\n return false;\n };\n\n useSafelyMouseToSubmenu({menuRef: parentMenuRef, submenuRef, isOpen: state.isOpen, isDisabled: isDisabled});\n\n return {\n submenuTriggerProps: {\n id: submenuTriggerId,\n 'aria-controls': state.isOpen ? overlayId : undefined,\n 'aria-haspopup': !isDisabled ? type : undefined,\n 'aria-expanded': state.isOpen ? 'true' : 'false',\n onPressStart,\n onPress,\n onHoverChange,\n onKeyDown: submenuTriggerKeyDown,\n onBlur,\n isOpen: state.isOpen\n },\n submenuProps,\n popoverProps: {\n isNonModal: true,\n disableFocusManagement: true,\n shouldCloseOnInteractOutside\n }\n };\n}\n"],"names":[],"version":3,"file":"useSubmenuTrigger.module.js.map"}
package/dist/zh-CN.mjs CHANGED
@@ -5,4 +5,4 @@ $2d9960c02ccac927$exports = {
5
5
 
6
6
 
7
7
  export {$2d9960c02ccac927$exports as default};
8
- //# sourceMappingURL=zh-CN.module.js.map
8
+ //# sourceMappingURL=zh-CN.mjs.map
package/dist/zh-TW.mjs CHANGED
@@ -5,4 +5,4 @@ $f1b682a4c8c5631c$exports = {
5
5
 
6
6
 
7
7
  export {$f1b682a4c8c5631c$exports as default};
8
- //# sourceMappingURL=zh-TW.module.js.map
8
+ //# sourceMappingURL=zh-TW.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/menu",
3
- "version": "3.13.2-nightly.4555+81162ea39",
3
+ "version": "3.13.2-nightly.4560+72775d272",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,18 +22,18 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "3.0.0-nightly.2843+81162ea39",
26
- "@react-aria/i18n": "3.0.0-nightly.2843+81162ea39",
27
- "@react-aria/interactions": "3.0.0-nightly.2843+81162ea39",
28
- "@react-aria/overlays": "3.0.0-nightly.2843+81162ea39",
29
- "@react-aria/selection": "3.0.0-nightly.2843+81162ea39",
30
- "@react-aria/utils": "3.0.0-nightly.2843+81162ea39",
31
- "@react-stately/collections": "3.0.0-nightly.2843+81162ea39",
32
- "@react-stately/menu": "3.6.2-nightly.4555+81162ea39",
33
- "@react-stately/tree": "3.0.0-nightly.2843+81162ea39",
34
- "@react-types/button": "3.9.3-nightly.4555+81162ea39",
35
- "@react-types/menu": "3.9.8-nightly.4555+81162ea39",
36
- "@react-types/shared": "3.0.0-nightly.2843+81162ea39",
25
+ "@react-aria/focus": "3.0.0-nightly.2848+72775d272",
26
+ "@react-aria/i18n": "3.0.0-nightly.2848+72775d272",
27
+ "@react-aria/interactions": "3.0.0-nightly.2848+72775d272",
28
+ "@react-aria/overlays": "3.0.0-nightly.2848+72775d272",
29
+ "@react-aria/selection": "3.0.0-nightly.2848+72775d272",
30
+ "@react-aria/utils": "3.0.0-nightly.2848+72775d272",
31
+ "@react-stately/collections": "3.0.0-nightly.2848+72775d272",
32
+ "@react-stately/menu": "3.6.2-nightly.4560+72775d272",
33
+ "@react-stately/tree": "3.0.0-nightly.2848+72775d272",
34
+ "@react-types/button": "3.9.3-nightly.4560+72775d272",
35
+ "@react-types/menu": "3.9.8-nightly.4560+72775d272",
36
+ "@react-types/shared": "3.0.0-nightly.2848+72775d272",
37
37
  "@swc/helpers": "^0.5.0"
38
38
  },
39
39
  "peerDependencies": {
@@ -43,5 +43,5 @@
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  },
46
- "gitHead": "81162ea392926d06ec3d25c228e6f9b6b5479d59"
46
+ "gitHead": "72775d272be04cfa32d26ec821bc68513d92a72b"
47
47
  }