@react-aria/menu 3.20.0 → 3.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +2 -10
- package/dist/main.js +6 -14
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -10
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/package.json +15 -24
- package/src/index.ts +2 -11
- package/dist/ar-AE.main.js +0 -6
- package/dist/ar-AE.main.js.map +0 -1
- package/dist/ar-AE.mjs +0 -8
- package/dist/ar-AE.module.js +0 -8
- package/dist/ar-AE.module.js.map +0 -1
- package/dist/bg-BG.main.js +0 -6
- package/dist/bg-BG.main.js.map +0 -1
- package/dist/bg-BG.mjs +0 -8
- package/dist/bg-BG.module.js +0 -8
- package/dist/bg-BG.module.js.map +0 -1
- package/dist/cs-CZ.main.js +0 -6
- package/dist/cs-CZ.main.js.map +0 -1
- package/dist/cs-CZ.mjs +0 -8
- package/dist/cs-CZ.module.js +0 -8
- package/dist/cs-CZ.module.js.map +0 -1
- package/dist/da-DK.main.js +0 -6
- package/dist/da-DK.main.js.map +0 -1
- package/dist/da-DK.mjs +0 -8
- package/dist/da-DK.module.js +0 -8
- package/dist/da-DK.module.js.map +0 -1
- package/dist/de-DE.main.js +0 -6
- package/dist/de-DE.main.js.map +0 -1
- package/dist/de-DE.mjs +0 -8
- package/dist/de-DE.module.js +0 -8
- package/dist/de-DE.module.js.map +0 -1
- package/dist/el-GR.main.js +0 -6
- package/dist/el-GR.main.js.map +0 -1
- package/dist/el-GR.mjs +0 -8
- package/dist/el-GR.module.js +0 -8
- package/dist/el-GR.module.js.map +0 -1
- package/dist/en-US.main.js +0 -6
- package/dist/en-US.main.js.map +0 -1
- package/dist/en-US.mjs +0 -8
- package/dist/en-US.module.js +0 -8
- package/dist/en-US.module.js.map +0 -1
- package/dist/es-ES.main.js +0 -6
- package/dist/es-ES.main.js.map +0 -1
- package/dist/es-ES.mjs +0 -8
- package/dist/es-ES.module.js +0 -8
- package/dist/es-ES.module.js.map +0 -1
- package/dist/et-EE.main.js +0 -6
- package/dist/et-EE.main.js.map +0 -1
- package/dist/et-EE.mjs +0 -8
- package/dist/et-EE.module.js +0 -8
- package/dist/et-EE.module.js.map +0 -1
- package/dist/fi-FI.main.js +0 -6
- package/dist/fi-FI.main.js.map +0 -1
- package/dist/fi-FI.mjs +0 -8
- package/dist/fi-FI.module.js +0 -8
- package/dist/fi-FI.module.js.map +0 -1
- package/dist/fr-FR.main.js +0 -6
- package/dist/fr-FR.main.js.map +0 -1
- package/dist/fr-FR.mjs +0 -8
- package/dist/fr-FR.module.js +0 -8
- package/dist/fr-FR.module.js.map +0 -1
- package/dist/he-IL.main.js +0 -6
- package/dist/he-IL.main.js.map +0 -1
- package/dist/he-IL.mjs +0 -8
- package/dist/he-IL.module.js +0 -8
- package/dist/he-IL.module.js.map +0 -1
- package/dist/hr-HR.main.js +0 -6
- package/dist/hr-HR.main.js.map +0 -1
- package/dist/hr-HR.mjs +0 -8
- package/dist/hr-HR.module.js +0 -8
- package/dist/hr-HR.module.js.map +0 -1
- package/dist/hu-HU.main.js +0 -6
- package/dist/hu-HU.main.js.map +0 -1
- package/dist/hu-HU.mjs +0 -8
- package/dist/hu-HU.module.js +0 -8
- package/dist/hu-HU.module.js.map +0 -1
- package/dist/intlStrings.main.js +0 -108
- package/dist/intlStrings.main.js.map +0 -1
- package/dist/intlStrings.mjs +0 -110
- package/dist/intlStrings.module.js +0 -110
- package/dist/intlStrings.module.js.map +0 -1
- package/dist/it-IT.main.js +0 -6
- package/dist/it-IT.main.js.map +0 -1
- package/dist/it-IT.mjs +0 -8
- package/dist/it-IT.module.js +0 -8
- package/dist/it-IT.module.js.map +0 -1
- package/dist/ja-JP.main.js +0 -6
- package/dist/ja-JP.main.js.map +0 -1
- package/dist/ja-JP.mjs +0 -8
- package/dist/ja-JP.module.js +0 -8
- package/dist/ja-JP.module.js.map +0 -1
- package/dist/ko-KR.main.js +0 -6
- package/dist/ko-KR.main.js.map +0 -1
- package/dist/ko-KR.mjs +0 -8
- package/dist/ko-KR.module.js +0 -8
- package/dist/ko-KR.module.js.map +0 -1
- package/dist/lt-LT.main.js +0 -6
- package/dist/lt-LT.main.js.map +0 -1
- package/dist/lt-LT.mjs +0 -8
- package/dist/lt-LT.module.js +0 -8
- package/dist/lt-LT.module.js.map +0 -1
- package/dist/lv-LV.main.js +0 -6
- package/dist/lv-LV.main.js.map +0 -1
- package/dist/lv-LV.mjs +0 -8
- package/dist/lv-LV.module.js +0 -8
- package/dist/lv-LV.module.js.map +0 -1
- package/dist/nb-NO.main.js +0 -6
- package/dist/nb-NO.main.js.map +0 -1
- package/dist/nb-NO.mjs +0 -8
- package/dist/nb-NO.module.js +0 -8
- package/dist/nb-NO.module.js.map +0 -1
- package/dist/nl-NL.main.js +0 -6
- package/dist/nl-NL.main.js.map +0 -1
- package/dist/nl-NL.mjs +0 -8
- package/dist/nl-NL.module.js +0 -8
- package/dist/nl-NL.module.js.map +0 -1
- package/dist/pl-PL.main.js +0 -6
- package/dist/pl-PL.main.js.map +0 -1
- package/dist/pl-PL.mjs +0 -8
- package/dist/pl-PL.module.js +0 -8
- package/dist/pl-PL.module.js.map +0 -1
- package/dist/pt-BR.main.js +0 -6
- package/dist/pt-BR.main.js.map +0 -1
- package/dist/pt-BR.mjs +0 -8
- package/dist/pt-BR.module.js +0 -8
- package/dist/pt-BR.module.js.map +0 -1
- package/dist/pt-PT.main.js +0 -6
- package/dist/pt-PT.main.js.map +0 -1
- package/dist/pt-PT.mjs +0 -8
- package/dist/pt-PT.module.js +0 -8
- package/dist/pt-PT.module.js.map +0 -1
- package/dist/ro-RO.main.js +0 -6
- package/dist/ro-RO.main.js.map +0 -1
- package/dist/ro-RO.mjs +0 -8
- package/dist/ro-RO.module.js +0 -8
- package/dist/ro-RO.module.js.map +0 -1
- package/dist/ru-RU.main.js +0 -6
- package/dist/ru-RU.main.js.map +0 -1
- package/dist/ru-RU.mjs +0 -8
- package/dist/ru-RU.module.js +0 -8
- package/dist/ru-RU.module.js.map +0 -1
- package/dist/sk-SK.main.js +0 -6
- package/dist/sk-SK.main.js.map +0 -1
- package/dist/sk-SK.mjs +0 -8
- package/dist/sk-SK.module.js +0 -8
- package/dist/sk-SK.module.js.map +0 -1
- package/dist/sl-SI.main.js +0 -6
- package/dist/sl-SI.main.js.map +0 -1
- package/dist/sl-SI.mjs +0 -8
- package/dist/sl-SI.module.js +0 -8
- package/dist/sl-SI.module.js.map +0 -1
- package/dist/sr-SP.main.js +0 -6
- package/dist/sr-SP.main.js.map +0 -1
- package/dist/sr-SP.mjs +0 -8
- package/dist/sr-SP.module.js +0 -8
- package/dist/sr-SP.module.js.map +0 -1
- package/dist/sv-SE.main.js +0 -6
- package/dist/sv-SE.main.js.map +0 -1
- package/dist/sv-SE.mjs +0 -8
- package/dist/sv-SE.module.js +0 -8
- package/dist/sv-SE.module.js.map +0 -1
- package/dist/tr-TR.main.js +0 -6
- package/dist/tr-TR.main.js.map +0 -1
- package/dist/tr-TR.mjs +0 -8
- package/dist/tr-TR.module.js +0 -8
- package/dist/tr-TR.module.js.map +0 -1
- package/dist/types.d.ts +0 -191
- package/dist/types.d.ts.map +0 -1
- package/dist/uk-UA.main.js +0 -6
- package/dist/uk-UA.main.js.map +0 -1
- package/dist/uk-UA.mjs +0 -8
- package/dist/uk-UA.module.js +0 -8
- package/dist/uk-UA.module.js.map +0 -1
- package/dist/useMenu.main.js +0 -61
- package/dist/useMenu.main.js.map +0 -1
- package/dist/useMenu.mjs +0 -56
- package/dist/useMenu.module.js +0 -56
- package/dist/useMenu.module.js.map +0 -1
- package/dist/useMenuItem.main.js +0 -217
- package/dist/useMenuItem.main.js.map +0 -1
- package/dist/useMenuItem.mjs +0 -212
- package/dist/useMenuItem.module.js +0 -212
- package/dist/useMenuItem.module.js.map +0 -1
- package/dist/useMenuSection.main.js +0 -43
- package/dist/useMenuSection.main.js.map +0 -1
- package/dist/useMenuSection.mjs +0 -38
- package/dist/useMenuSection.module.js +0 -38
- package/dist/useMenuSection.module.js.map +0 -1
- package/dist/useMenuTrigger.main.js +0 -117
- package/dist/useMenuTrigger.main.js.map +0 -1
- package/dist/useMenuTrigger.mjs +0 -112
- package/dist/useMenuTrigger.module.js +0 -112
- package/dist/useMenuTrigger.module.js.map +0 -1
- package/dist/useSafelyMouseToSubmenu.main.js +0 -143
- package/dist/useSafelyMouseToSubmenu.main.js.map +0 -1
- package/dist/useSafelyMouseToSubmenu.mjs +0 -138
- package/dist/useSafelyMouseToSubmenu.module.js +0 -138
- package/dist/useSafelyMouseToSubmenu.module.js.map +0 -1
- package/dist/useSubmenuTrigger.main.js +0 -184
- package/dist/useSubmenuTrigger.main.js.map +0 -1
- package/dist/useSubmenuTrigger.mjs +0 -179
- package/dist/useSubmenuTrigger.module.js +0 -179
- package/dist/useSubmenuTrigger.module.js.map +0 -1
- package/dist/utils.main.js +0 -20
- package/dist/utils.main.js.map +0 -1
- package/dist/utils.mjs +0 -15
- package/dist/utils.module.js +0 -15
- package/dist/utils.module.js.map +0 -1
- package/dist/zh-CN.main.js +0 -6
- package/dist/zh-CN.main.js.map +0 -1
- package/dist/zh-CN.mjs +0 -8
- package/dist/zh-CN.module.js +0 -8
- package/dist/zh-CN.module.js.map +0 -1
- package/dist/zh-TW.main.js +0 -6
- package/dist/zh-TW.main.js.map +0 -1
- package/dist/zh-TW.mjs +0 -8
- package/dist/zh-TW.module.js +0 -8
- package/dist/zh-TW.module.js.map +0 -1
- package/src/useMenu.ts +0 -86
- package/src/useMenuItem.ts +0 -350
- package/src/useMenuSection.ts +0 -61
- package/src/useMenuTrigger.ts +0 -156
- package/src/useSafelyMouseToSubmenu.ts +0 -178
- package/src/useSubmenuTrigger.ts +0 -262
- package/src/utils.ts +0 -22
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import {useSafelyMouseToSubmenu as $d275435c250248f8$export$85ec83e04c95f50a} from "./useSafelyMouseToSubmenu.mjs";
|
|
2
|
-
import {useId as $dXlYe$useId, useLayoutEffect as $dXlYe$useLayoutEffect, nodeContains as $dXlYe$nodeContains, focusWithoutScrolling as $dXlYe$focusWithoutScrolling, useEvent as $dXlYe$useEvent} from "@react-aria/utils";
|
|
3
|
-
import {useRef as $dXlYe$useRef, useCallback as $dXlYe$useCallback} from "react";
|
|
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$7138b0d059a6e743(props, state, ref) {
|
|
21
|
-
let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type = 'menu', isDisabled: isDisabled, delay: delay = 200, shouldUseVirtualFocus: shouldUseVirtualFocus } = 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)(undefined);
|
|
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$useCallback)((focusStrategy)=>{
|
|
35
|
-
cancelOpenTimeout();
|
|
36
|
-
state.open(focusStrategy);
|
|
37
|
-
}, [
|
|
38
|
-
state,
|
|
39
|
-
cancelOpenTimeout
|
|
40
|
-
]);
|
|
41
|
-
let onSubmenuClose = (0, $dXlYe$useCallback)(()=>{
|
|
42
|
-
cancelOpenTimeout();
|
|
43
|
-
state.close();
|
|
44
|
-
}, [
|
|
45
|
-
state,
|
|
46
|
-
cancelOpenTimeout
|
|
47
|
-
]);
|
|
48
|
-
(0, $dXlYe$useLayoutEffect)(()=>{
|
|
49
|
-
return ()=>{
|
|
50
|
-
cancelOpenTimeout();
|
|
51
|
-
};
|
|
52
|
-
}, [
|
|
53
|
-
cancelOpenTimeout
|
|
54
|
-
]);
|
|
55
|
-
let submenuKeyDown = (e)=>{
|
|
56
|
-
// If focus is not within the menu, assume virtual focus is being used.
|
|
57
|
-
// This means some other input element is also within the popover, so we shouldn't close the menu.
|
|
58
|
-
if (!(0, $dXlYe$nodeContains)(e.currentTarget, document.activeElement)) return;
|
|
59
|
-
switch(e.key){
|
|
60
|
-
case 'ArrowLeft':
|
|
61
|
-
if (direction === 'ltr' && (0, $dXlYe$nodeContains)(e.currentTarget, e.target)) {
|
|
62
|
-
e.preventDefault();
|
|
63
|
-
e.stopPropagation();
|
|
64
|
-
onSubmenuClose();
|
|
65
|
-
if (!shouldUseVirtualFocus && ref.current) (0, $dXlYe$focusWithoutScrolling)(ref.current);
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
case 'ArrowRight':
|
|
69
|
-
if (direction === 'rtl' && (0, $dXlYe$nodeContains)(e.currentTarget, e.target)) {
|
|
70
|
-
e.preventDefault();
|
|
71
|
-
e.stopPropagation();
|
|
72
|
-
onSubmenuClose();
|
|
73
|
-
if (!shouldUseVirtualFocus && ref.current) (0, $dXlYe$focusWithoutScrolling)(ref.current);
|
|
74
|
-
}
|
|
75
|
-
break;
|
|
76
|
-
case 'Escape':
|
|
77
|
-
// TODO: can remove this when we fix collection event leaks
|
|
78
|
-
if ((0, $dXlYe$nodeContains)(submenuRef.current, e.target)) {
|
|
79
|
-
e.stopPropagation();
|
|
80
|
-
onSubmenuClose();
|
|
81
|
-
if (!shouldUseVirtualFocus && ref.current) (0, $dXlYe$focusWithoutScrolling)(ref.current);
|
|
82
|
-
}
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
var _state_focusStrategy;
|
|
87
|
-
let submenuProps = {
|
|
88
|
-
id: overlayId,
|
|
89
|
-
'aria-labelledby': submenuTriggerId,
|
|
90
|
-
submenuLevel: state.submenuLevel,
|
|
91
|
-
...type === 'menu' && {
|
|
92
|
-
onClose: state.closeAll,
|
|
93
|
-
autoFocus: (_state_focusStrategy = state.focusStrategy) !== null && _state_focusStrategy !== void 0 ? _state_focusStrategy : undefined,
|
|
94
|
-
onKeyDown: submenuKeyDown
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
let submenuTriggerKeyDown = (e)=>{
|
|
98
|
-
switch(e.key){
|
|
99
|
-
case 'ArrowRight':
|
|
100
|
-
if (!isDisabled) {
|
|
101
|
-
if (direction === 'ltr') {
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
if (!state.isOpen) onSubmenuOpen('first');
|
|
104
|
-
if (type === 'menu' && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) (0, $dXlYe$focusWithoutScrolling)(submenuRef.current);
|
|
105
|
-
} else if (state.isOpen) onSubmenuClose();
|
|
106
|
-
else e.continuePropagation();
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
case 'ArrowLeft':
|
|
110
|
-
if (!isDisabled) {
|
|
111
|
-
if (direction === 'rtl') {
|
|
112
|
-
e.preventDefault();
|
|
113
|
-
if (!state.isOpen) onSubmenuOpen('first');
|
|
114
|
-
if (type === 'menu' && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) (0, $dXlYe$focusWithoutScrolling)(submenuRef.current);
|
|
115
|
-
} else if (state.isOpen) onSubmenuClose();
|
|
116
|
-
else e.continuePropagation();
|
|
117
|
-
}
|
|
118
|
-
break;
|
|
119
|
-
default:
|
|
120
|
-
e.continuePropagation();
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
let onPressStart = (e)=>{
|
|
125
|
-
if (!isDisabled && (e.pointerType === 'virtual' || e.pointerType === 'keyboard')) // If opened with a screen reader or keyboard, auto focus the first submenu item.
|
|
126
|
-
onSubmenuOpen('first');
|
|
127
|
-
};
|
|
128
|
-
let onPress = (e)=>{
|
|
129
|
-
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
|
|
130
|
-
// press up happening on the newly opened tray items
|
|
131
|
-
onSubmenuOpen();
|
|
132
|
-
};
|
|
133
|
-
let onHoverChange = (isHovered)=>{
|
|
134
|
-
if (!isDisabled) {
|
|
135
|
-
if (isHovered && !state.isOpen) {
|
|
136
|
-
if (!openTimeout.current) openTimeout.current = setTimeout(()=>{
|
|
137
|
-
onSubmenuOpen();
|
|
138
|
-
}, delay);
|
|
139
|
-
} else if (!isHovered) cancelOpenTimeout();
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
(0, $dXlYe$useEvent)(parentMenuRef, 'focusin', (e)=>{
|
|
143
|
-
// If we detect focus moved to a different item in the same menu that the currently open submenu trigger is in
|
|
144
|
-
// then close the submenu. This is for a case where the user hovers a root menu item when multiple submenus are open
|
|
145
|
-
if (state.isOpen && (0, $dXlYe$nodeContains)(parentMenuRef.current, e.target) && e.target !== ref.current) onSubmenuClose();
|
|
146
|
-
});
|
|
147
|
-
let shouldCloseOnInteractOutside = (target)=>{
|
|
148
|
-
if (target !== ref.current) return true;
|
|
149
|
-
return false;
|
|
150
|
-
};
|
|
151
|
-
(0, $d275435c250248f8$export$85ec83e04c95f50a)({
|
|
152
|
-
menuRef: parentMenuRef,
|
|
153
|
-
submenuRef: submenuRef,
|
|
154
|
-
isOpen: state.isOpen,
|
|
155
|
-
isDisabled: isDisabled
|
|
156
|
-
});
|
|
157
|
-
return {
|
|
158
|
-
submenuTriggerProps: {
|
|
159
|
-
id: submenuTriggerId,
|
|
160
|
-
'aria-controls': state.isOpen ? overlayId : undefined,
|
|
161
|
-
'aria-haspopup': !isDisabled ? type : undefined,
|
|
162
|
-
'aria-expanded': state.isOpen ? 'true' : 'false',
|
|
163
|
-
onPressStart: onPressStart,
|
|
164
|
-
onPress: onPress,
|
|
165
|
-
onHoverChange: onHoverChange,
|
|
166
|
-
onKeyDown: submenuTriggerKeyDown,
|
|
167
|
-
isOpen: state.isOpen
|
|
168
|
-
},
|
|
169
|
-
submenuProps: submenuProps,
|
|
170
|
-
popoverProps: {
|
|
171
|
-
isNonModal: true,
|
|
172
|
-
shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
export {$0065b146e7192841$export$7138b0d059a6e743 as useSubmenuTrigger};
|
|
179
|
-
//# sourceMappingURL=useSubmenuTrigger.module.js.map
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import {useSafelyMouseToSubmenu as $d275435c250248f8$export$85ec83e04c95f50a} from "./useSafelyMouseToSubmenu.module.js";
|
|
2
|
-
import {useId as $dXlYe$useId, useLayoutEffect as $dXlYe$useLayoutEffect, nodeContains as $dXlYe$nodeContains, focusWithoutScrolling as $dXlYe$focusWithoutScrolling, useEvent as $dXlYe$useEvent} from "@react-aria/utils";
|
|
3
|
-
import {useRef as $dXlYe$useRef, useCallback as $dXlYe$useCallback} from "react";
|
|
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$7138b0d059a6e743(props, state, ref) {
|
|
21
|
-
let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type = 'menu', isDisabled: isDisabled, delay: delay = 200, shouldUseVirtualFocus: shouldUseVirtualFocus } = 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)(undefined);
|
|
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$useCallback)((focusStrategy)=>{
|
|
35
|
-
cancelOpenTimeout();
|
|
36
|
-
state.open(focusStrategy);
|
|
37
|
-
}, [
|
|
38
|
-
state,
|
|
39
|
-
cancelOpenTimeout
|
|
40
|
-
]);
|
|
41
|
-
let onSubmenuClose = (0, $dXlYe$useCallback)(()=>{
|
|
42
|
-
cancelOpenTimeout();
|
|
43
|
-
state.close();
|
|
44
|
-
}, [
|
|
45
|
-
state,
|
|
46
|
-
cancelOpenTimeout
|
|
47
|
-
]);
|
|
48
|
-
(0, $dXlYe$useLayoutEffect)(()=>{
|
|
49
|
-
return ()=>{
|
|
50
|
-
cancelOpenTimeout();
|
|
51
|
-
};
|
|
52
|
-
}, [
|
|
53
|
-
cancelOpenTimeout
|
|
54
|
-
]);
|
|
55
|
-
let submenuKeyDown = (e)=>{
|
|
56
|
-
// If focus is not within the menu, assume virtual focus is being used.
|
|
57
|
-
// This means some other input element is also within the popover, so we shouldn't close the menu.
|
|
58
|
-
if (!(0, $dXlYe$nodeContains)(e.currentTarget, document.activeElement)) return;
|
|
59
|
-
switch(e.key){
|
|
60
|
-
case 'ArrowLeft':
|
|
61
|
-
if (direction === 'ltr' && (0, $dXlYe$nodeContains)(e.currentTarget, e.target)) {
|
|
62
|
-
e.preventDefault();
|
|
63
|
-
e.stopPropagation();
|
|
64
|
-
onSubmenuClose();
|
|
65
|
-
if (!shouldUseVirtualFocus && ref.current) (0, $dXlYe$focusWithoutScrolling)(ref.current);
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
case 'ArrowRight':
|
|
69
|
-
if (direction === 'rtl' && (0, $dXlYe$nodeContains)(e.currentTarget, e.target)) {
|
|
70
|
-
e.preventDefault();
|
|
71
|
-
e.stopPropagation();
|
|
72
|
-
onSubmenuClose();
|
|
73
|
-
if (!shouldUseVirtualFocus && ref.current) (0, $dXlYe$focusWithoutScrolling)(ref.current);
|
|
74
|
-
}
|
|
75
|
-
break;
|
|
76
|
-
case 'Escape':
|
|
77
|
-
// TODO: can remove this when we fix collection event leaks
|
|
78
|
-
if ((0, $dXlYe$nodeContains)(submenuRef.current, e.target)) {
|
|
79
|
-
e.stopPropagation();
|
|
80
|
-
onSubmenuClose();
|
|
81
|
-
if (!shouldUseVirtualFocus && ref.current) (0, $dXlYe$focusWithoutScrolling)(ref.current);
|
|
82
|
-
}
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
var _state_focusStrategy;
|
|
87
|
-
let submenuProps = {
|
|
88
|
-
id: overlayId,
|
|
89
|
-
'aria-labelledby': submenuTriggerId,
|
|
90
|
-
submenuLevel: state.submenuLevel,
|
|
91
|
-
...type === 'menu' && {
|
|
92
|
-
onClose: state.closeAll,
|
|
93
|
-
autoFocus: (_state_focusStrategy = state.focusStrategy) !== null && _state_focusStrategy !== void 0 ? _state_focusStrategy : undefined,
|
|
94
|
-
onKeyDown: submenuKeyDown
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
let submenuTriggerKeyDown = (e)=>{
|
|
98
|
-
switch(e.key){
|
|
99
|
-
case 'ArrowRight':
|
|
100
|
-
if (!isDisabled) {
|
|
101
|
-
if (direction === 'ltr') {
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
if (!state.isOpen) onSubmenuOpen('first');
|
|
104
|
-
if (type === 'menu' && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) (0, $dXlYe$focusWithoutScrolling)(submenuRef.current);
|
|
105
|
-
} else if (state.isOpen) onSubmenuClose();
|
|
106
|
-
else e.continuePropagation();
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
case 'ArrowLeft':
|
|
110
|
-
if (!isDisabled) {
|
|
111
|
-
if (direction === 'rtl') {
|
|
112
|
-
e.preventDefault();
|
|
113
|
-
if (!state.isOpen) onSubmenuOpen('first');
|
|
114
|
-
if (type === 'menu' && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) (0, $dXlYe$focusWithoutScrolling)(submenuRef.current);
|
|
115
|
-
} else if (state.isOpen) onSubmenuClose();
|
|
116
|
-
else e.continuePropagation();
|
|
117
|
-
}
|
|
118
|
-
break;
|
|
119
|
-
default:
|
|
120
|
-
e.continuePropagation();
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
let onPressStart = (e)=>{
|
|
125
|
-
if (!isDisabled && (e.pointerType === 'virtual' || e.pointerType === 'keyboard')) // If opened with a screen reader or keyboard, auto focus the first submenu item.
|
|
126
|
-
onSubmenuOpen('first');
|
|
127
|
-
};
|
|
128
|
-
let onPress = (e)=>{
|
|
129
|
-
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
|
|
130
|
-
// press up happening on the newly opened tray items
|
|
131
|
-
onSubmenuOpen();
|
|
132
|
-
};
|
|
133
|
-
let onHoverChange = (isHovered)=>{
|
|
134
|
-
if (!isDisabled) {
|
|
135
|
-
if (isHovered && !state.isOpen) {
|
|
136
|
-
if (!openTimeout.current) openTimeout.current = setTimeout(()=>{
|
|
137
|
-
onSubmenuOpen();
|
|
138
|
-
}, delay);
|
|
139
|
-
} else if (!isHovered) cancelOpenTimeout();
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
(0, $dXlYe$useEvent)(parentMenuRef, 'focusin', (e)=>{
|
|
143
|
-
// If we detect focus moved to a different item in the same menu that the currently open submenu trigger is in
|
|
144
|
-
// then close the submenu. This is for a case where the user hovers a root menu item when multiple submenus are open
|
|
145
|
-
if (state.isOpen && (0, $dXlYe$nodeContains)(parentMenuRef.current, e.target) && e.target !== ref.current) onSubmenuClose();
|
|
146
|
-
});
|
|
147
|
-
let shouldCloseOnInteractOutside = (target)=>{
|
|
148
|
-
if (target !== ref.current) return true;
|
|
149
|
-
return false;
|
|
150
|
-
};
|
|
151
|
-
(0, $d275435c250248f8$export$85ec83e04c95f50a)({
|
|
152
|
-
menuRef: parentMenuRef,
|
|
153
|
-
submenuRef: submenuRef,
|
|
154
|
-
isOpen: state.isOpen,
|
|
155
|
-
isDisabled: isDisabled
|
|
156
|
-
});
|
|
157
|
-
return {
|
|
158
|
-
submenuTriggerProps: {
|
|
159
|
-
id: submenuTriggerId,
|
|
160
|
-
'aria-controls': state.isOpen ? overlayId : undefined,
|
|
161
|
-
'aria-haspopup': !isDisabled ? type : undefined,
|
|
162
|
-
'aria-expanded': state.isOpen ? 'true' : 'false',
|
|
163
|
-
onPressStart: onPressStart,
|
|
164
|
-
onPress: onPress,
|
|
165
|
-
onHoverChange: onHoverChange,
|
|
166
|
-
onKeyDown: submenuTriggerKeyDown,
|
|
167
|
-
isOpen: state.isOpen
|
|
168
|
-
},
|
|
169
|
-
submenuProps: submenuProps,
|
|
170
|
-
popoverProps: {
|
|
171
|
-
isNonModal: true,
|
|
172
|
-
shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
export {$0065b146e7192841$export$7138b0d059a6e743 as useSubmenuTrigger};
|
|
179
|
-
//# sourceMappingURL=useSubmenuTrigger.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"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","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, Node, PressEvent, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, nodeContains, useEvent, useId, useLayoutEffect} from '@react-aria/utils';\nimport type {SubmenuTriggerState} from '@react-stately/menu';\nimport {useCallback, useRef} from 'react';\nimport {useLocale} from '@react-aria/i18n';\nimport {useSafelyMouseToSubmenu} from './useSafelyMouseToSubmenu';\n\nexport interface AriaSubmenuTriggerProps {\n /**\n * An object representing the submenu trigger menu item. Contains all the relevant information that makes up the menu item.\n * @deprecated\n */\n node?: Node<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 | null>,\n /** Ref of the submenu opened by the submenu trigger. */\n submenuRef: RefObject<HTMLElement | null>,\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 /** Whether the submenu trigger uses virtual focus. */\n shouldUseVirtualFocus?: boolean\n}\n\ninterface SubmenuTriggerProps extends Omit<AriaMenuItemProps, 'key'> {\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 useSubmenuTrigger<T>(props: AriaSubmenuTriggerProps, state: SubmenuTriggerState, ref: RefObject<FocusableElement | null>): SubmenuTriggerAria<T> {\n let {parentMenuRef, submenuRef, type = 'menu', isDisabled, delay = 200, shouldUseVirtualFocus} = props;\n let submenuTriggerId = useId();\n let overlayId = useId();\n let {direction} = useLocale();\n let openTimeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let cancelOpenTimeout = useCallback(() => {\n if (openTimeout.current) {\n clearTimeout(openTimeout.current);\n openTimeout.current = undefined;\n }\n }, [openTimeout]);\n\n let onSubmenuOpen = useCallback((focusStrategy?: FocusStrategy) => {\n cancelOpenTimeout();\n state.open(focusStrategy);\n }, [state, cancelOpenTimeout]);\n\n let onSubmenuClose = useCallback(() => {\n cancelOpenTimeout();\n state.close();\n }, [state, cancelOpenTimeout]);\n\n useLayoutEffect(() => {\n return () => {\n cancelOpenTimeout();\n };\n }, [cancelOpenTimeout]);\n\n let submenuKeyDown = (e: KeyboardEvent) => {\n // If focus is not within the menu, assume virtual focus is being used.\n // This means some other input element is also within the popover, so we shouldn't close the menu.\n if (!nodeContains(e.currentTarget, document.activeElement)) {\n return;\n }\n\n switch (e.key) {\n case 'ArrowLeft':\n if (direction === 'ltr' && nodeContains(e.currentTarget, e.target as Element)) {\n e.preventDefault();\n e.stopPropagation();\n onSubmenuClose();\n if (!shouldUseVirtualFocus && ref.current) {\n focusWithoutScrolling(ref.current);\n }\n }\n break;\n case 'ArrowRight':\n if (direction === 'rtl' && nodeContains(e.currentTarget, e.target as Element)) {\n e.preventDefault();\n e.stopPropagation();\n onSubmenuClose();\n if (!shouldUseVirtualFocus && ref.current) {\n focusWithoutScrolling(ref.current);\n }\n }\n break;\n case 'Escape':\n // TODO: can remove this when we fix collection event leaks\n if (nodeContains(submenuRef.current, e.target as Element)) {\n e.stopPropagation();\n onSubmenuClose();\n if (!shouldUseVirtualFocus && ref.current) {\n focusWithoutScrolling(ref.current);\n }\n }\n break;\n }\n };\n\n let submenuProps = {\n id: overlayId,\n 'aria-labelledby': submenuTriggerId,\n submenuLevel: state.submenuLevel,\n ...(type === 'menu' && {\n onClose: state.closeAll,\n autoFocus: state.focusStrategy ?? undefined,\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 e.preventDefault();\n if (!state.isOpen) {\n onSubmenuOpen('first');\n }\n\n if (type === 'menu' && !!submenuRef?.current && document.activeElement === ref?.current) {\n focusWithoutScrolling(submenuRef.current);\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 e.preventDefault();\n if (!state.isOpen) {\n onSubmenuOpen('first');\n }\n\n if (type === 'menu' && !!submenuRef?.current && document.activeElement === ref?.current) {\n focusWithoutScrolling(submenuRef.current);\n }\n } else if (state.isOpen) {\n onSubmenuClose();\n } else {\n e.continuePropagation();\n }\n }\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 useEvent(parentMenuRef, 'focusin', (e) => {\n // If we detect focus moved to a different item in the same menu that the currently open submenu trigger is in\n // then close the submenu. This is for a case where the user hovers a root menu item when multiple submenus are open\n if (state.isOpen && (nodeContains(parentMenuRef.current, e.target as HTMLElement) && e.target !== ref.current)) {\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 isOpen: state.isOpen\n },\n submenuProps,\n popoverProps: {\n isNonModal: true,\n shouldCloseOnInteractOutside\n }\n };\n}\n"],"names":[],"version":3,"file":"useSubmenuTrigger.module.js.map"}
|
package/dist/utils.main.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
function $parcel$export(e, n, v, s) {
|
|
3
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
$parcel$export(module.exports, "menuData", () => $815e346b11b84016$export$6f49b4016bfc8d56);
|
|
7
|
-
/*
|
|
8
|
-
* Copyright 2024 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
|
-
*/ const $815e346b11b84016$export$6f49b4016bfc8d56 = new WeakMap();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=utils.main.js.map
|
package/dist/utils.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAkD,IAAI","sources":["packages/@react-aria/menu/src/utils.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {Key} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\n\ninterface MenuData {\n onClose?: () => void,\n onAction?: (key: Key) => void,\n shouldUseVirtualFocus?: boolean\n}\n\nexport const menuData: WeakMap<TreeState<unknown>, MenuData> = new WeakMap<TreeState<unknown>, MenuData>();\n"],"names":[],"version":3,"file":"utils.main.js.map"}
|
package/dist/utils.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/ const $fc79756100351201$export$6f49b4016bfc8d56 = new WeakMap();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export {$fc79756100351201$export$6f49b4016bfc8d56 as menuData};
|
|
15
|
-
//# sourceMappingURL=utils.module.js.map
|
package/dist/utils.module.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/ const $fc79756100351201$export$6f49b4016bfc8d56 = new WeakMap();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export {$fc79756100351201$export$6f49b4016bfc8d56 as menuData};
|
|
15
|
-
//# sourceMappingURL=utils.module.js.map
|
package/dist/utils.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAkD,IAAI","sources":["packages/@react-aria/menu/src/utils.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {Key} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\n\ninterface MenuData {\n onClose?: () => void,\n onAction?: (key: Key) => void,\n shouldUseVirtualFocus?: boolean\n}\n\nexport const menuData: WeakMap<TreeState<unknown>, MenuData> = new WeakMap<TreeState<unknown>, MenuData>();\n"],"names":[],"version":3,"file":"utils.module.js.map"}
|
package/dist/zh-CN.main.js
DELETED
package/dist/zh-CN.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,iBAAiB;IAAG,oBAAoB,CAAC,uHAAqB,CAAC;AAC/D","sources":["packages/@react-aria/menu/intl/zh-CN.json"],"sourcesContent":["{\n \"longPressMessage\": \"长按或按 Alt + 向下方向键以打开菜单\"\n}\n"],"names":[],"version":3,"file":"zh-CN.main.js.map"}
|
package/dist/zh-CN.mjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
var $2d9960c02ccac927$exports = {};
|
|
2
|
-
$2d9960c02ccac927$exports = {
|
|
3
|
-
"longPressMessage": `\u{957F}\u{6309}\u{6216}\u{6309} Alt + \u{5411}\u{4E0B}\u{65B9}\u{5411}\u{952E}\u{4EE5}\u{6253}\u{5F00}\u{83DC}\u{5355}`
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {$2d9960c02ccac927$exports as default};
|
|
8
|
-
//# sourceMappingURL=zh-CN.module.js.map
|
package/dist/zh-CN.module.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
var $2d9960c02ccac927$exports = {};
|
|
2
|
-
$2d9960c02ccac927$exports = {
|
|
3
|
-
"longPressMessage": `\u{957F}\u{6309}\u{6216}\u{6309} Alt + \u{5411}\u{4E0B}\u{65B9}\u{5411}\u{952E}\u{4EE5}\u{6253}\u{5F00}\u{83DC}\u{5355}`
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {$2d9960c02ccac927$exports as default};
|
|
8
|
-
//# sourceMappingURL=zh-CN.module.js.map
|
package/dist/zh-CN.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";AAAA,4BAAiB;IAAG,oBAAoB,CAAC,uHAAqB,CAAC;AAC/D","sources":["packages/@react-aria/menu/intl/zh-CN.json"],"sourcesContent":["{\n \"longPressMessage\": \"长按或按 Alt + 向下方向键以打开菜单\"\n}\n"],"names":[],"version":3,"file":"zh-CN.module.js.map"}
|
package/dist/zh-TW.main.js
DELETED
package/dist/zh-TW.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,iBAAiB;IAAG,oBAAoB,CAAC,6GAAkB,CAAC;AAC5D","sources":["packages/@react-aria/menu/intl/zh-TW.json"],"sourcesContent":["{\n \"longPressMessage\": \"長按或按 Alt+向下鍵以開啟功能表\"\n}\n"],"names":[],"version":3,"file":"zh-TW.main.js.map"}
|
package/dist/zh-TW.mjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
var $f1b682a4c8c5631c$exports = {};
|
|
2
|
-
$f1b682a4c8c5631c$exports = {
|
|
3
|
-
"longPressMessage": `\u{9577}\u{6309}\u{6216}\u{6309} Alt+\u{5411}\u{4E0B}\u{9375}\u{4EE5}\u{958B}\u{555F}\u{529F}\u{80FD}\u{8868}`
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {$f1b682a4c8c5631c$exports as default};
|
|
8
|
-
//# sourceMappingURL=zh-TW.module.js.map
|
package/dist/zh-TW.module.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
var $f1b682a4c8c5631c$exports = {};
|
|
2
|
-
$f1b682a4c8c5631c$exports = {
|
|
3
|
-
"longPressMessage": `\u{9577}\u{6309}\u{6216}\u{6309} Alt+\u{5411}\u{4E0B}\u{9375}\u{4EE5}\u{958B}\u{555F}\u{529F}\u{80FD}\u{8868}`
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {$f1b682a4c8c5631c$exports as default};
|
|
8
|
-
//# sourceMappingURL=zh-TW.module.js.map
|
package/dist/zh-TW.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";AAAA,4BAAiB;IAAG,oBAAoB,CAAC,6GAAkB,CAAC;AAC5D","sources":["packages/@react-aria/menu/intl/zh-TW.json"],"sourcesContent":["{\n \"longPressMessage\": \"長按或按 Alt+向下鍵以開啟功能表\"\n}\n"],"names":[],"version":3,"file":"zh-TW.module.js.map"}
|
package/src/useMenu.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaMenuProps} from '@react-types/menu';
|
|
14
|
-
import {DOMAttributes, KeyboardDelegate, KeyboardEvents, RefObject} from '@react-types/shared';
|
|
15
|
-
import {filterDOMProps, mergeProps} from '@react-aria/utils';
|
|
16
|
-
import {menuData} from './utils';
|
|
17
|
-
import {TreeState} from '@react-stately/tree';
|
|
18
|
-
import {useSelectableList} from '@react-aria/selection';
|
|
19
|
-
|
|
20
|
-
export interface MenuAria {
|
|
21
|
-
/** Props for the menu element. */
|
|
22
|
-
menuProps: DOMAttributes
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface AriaMenuOptions<T> extends Omit<AriaMenuProps<T>, 'children'>, KeyboardEvents {
|
|
26
|
-
/** Whether the menu uses virtual scrolling. */
|
|
27
|
-
isVirtualized?: boolean,
|
|
28
|
-
/**
|
|
29
|
-
* An optional keyboard delegate implementation for type to select,
|
|
30
|
-
* to override the default.
|
|
31
|
-
*/
|
|
32
|
-
keyboardDelegate?: KeyboardDelegate,
|
|
33
|
-
/**
|
|
34
|
-
* Whether the menu items should use virtual focus instead of being focused directly.
|
|
35
|
-
*/
|
|
36
|
-
shouldUseVirtualFocus?: boolean
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Provides the behavior and accessibility implementation for a menu component.
|
|
41
|
-
* A menu displays a list of actions or options that a user can choose.
|
|
42
|
-
* @param props - Props for the menu.
|
|
43
|
-
* @param state - State for the menu, as returned by `useListState`.
|
|
44
|
-
*/
|
|
45
|
-
export function useMenu<T>(props: AriaMenuOptions<T>, state: TreeState<T>, ref: RefObject<HTMLElement | null>): MenuAria {
|
|
46
|
-
let {
|
|
47
|
-
shouldFocusWrap = true,
|
|
48
|
-
onKeyDown,
|
|
49
|
-
onKeyUp,
|
|
50
|
-
...otherProps
|
|
51
|
-
} = props;
|
|
52
|
-
|
|
53
|
-
if (!props['aria-label'] && !props['aria-labelledby'] && process.env.NODE_ENV !== 'production') {
|
|
54
|
-
console.warn('An aria-label or aria-labelledby prop is required for accessibility.');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let domProps = filterDOMProps(props, {labelable: true});
|
|
58
|
-
let {listProps} = useSelectableList({
|
|
59
|
-
...otherProps,
|
|
60
|
-
ref,
|
|
61
|
-
selectionManager: state.selectionManager,
|
|
62
|
-
collection: state.collection,
|
|
63
|
-
disabledKeys: state.disabledKeys,
|
|
64
|
-
shouldFocusWrap,
|
|
65
|
-
linkBehavior: 'override'
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
menuData.set(state, {
|
|
69
|
-
onClose: props.onClose,
|
|
70
|
-
onAction: props.onAction,
|
|
71
|
-
shouldUseVirtualFocus: props.shouldUseVirtualFocus
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
menuProps: mergeProps(domProps, {onKeyDown, onKeyUp}, {
|
|
76
|
-
role: 'menu',
|
|
77
|
-
...listProps,
|
|
78
|
-
onKeyDown: (e) => {
|
|
79
|
-
// don't clear the menu selected keys if the user is presses escape since escape closes the menu
|
|
80
|
-
if (e.key !== 'Escape' || props.shouldUseVirtualFocus) {
|
|
81
|
-
listProps.onKeyDown?.(e);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
};
|
|
86
|
-
}
|