@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
package/dist/import.mjs CHANGED
@@ -1,264 +1,8 @@
1
- import $c0398ad35c3639b7$exports from "./ar-AE.mjs";
2
- import $7af657c4165927c3$exports from "./bg-BG.mjs";
3
- import $d95d4da6d531ab81$exports from "./cs-CZ.mjs";
4
- import $24ebda9c775dca17$exports from "./da-DK.mjs";
5
- import $743e0dfca6cab1e9$exports from "./de-DE.mjs";
6
- import $a2f41026e05f1c84$exports from "./el-GR.mjs";
7
- import $43b800e97c901737$exports from "./en-US.mjs";
8
- import $442f5f6ac211e29f$exports from "./es-ES.mjs";
9
- import $dff280acfeb2d8ac$exports from "./et-EE.mjs";
10
- import $51608325613944d7$exports from "./fi-FI.mjs";
11
- import $c4a1b1eabeaa87be$exports from "./fr-FR.mjs";
12
- import $8c74815cdee18d1b$exports from "./he-IL.mjs";
13
- import $fd0e9ef6a7fe0ec9$exports from "./hr-HR.mjs";
14
- import $a89a74a39eba465a$exports from "./hu-HU.mjs";
15
- import $edc7c66594a0ae8a$exports from "./it-IT.mjs";
16
- import $f1ab51510712db52$exports from "./ja-JP.mjs";
17
- import $f9b672d9b82fa3d6$exports from "./ko-KR.mjs";
18
- import $a385f3910feda499$exports from "./lt-LT.mjs";
19
- import $4f1bde932c441789$exports from "./lv-LV.mjs";
20
- import $914a51a8a594d5be$exports from "./nb-NO.mjs";
21
- import $89aaf803103bb500$exports from "./nl-NL.mjs";
22
- import $c685891476dbaaca$exports from "./pl-PL.mjs";
23
- import $885879b9b10c2959$exports from "./pt-BR.mjs";
24
- import $6b39616688a51692$exports from "./pt-PT.mjs";
25
- import $f26362aed63f47e2$exports from "./ro-RO.mjs";
26
- import $06cbade644558bf0$exports from "./ru-RU.mjs";
27
- import $0a391ff68f9d59b1$exports from "./sk-SK.mjs";
28
- import $8193cf0e649c7928$exports from "./sl-SI.mjs";
29
- import $f398debcce5a5c55$exports from "./sr-SP.mjs";
30
- import $9e9fef000aa4c013$exports from "./sv-SE.mjs";
31
- import $c016c8183bbe3d68$exports from "./tr-TR.mjs";
32
- import $ca4f6c8462244e62$exports from "./uk-UA.mjs";
33
- import $2d9960c02ccac927$exports from "./zh-CN.mjs";
34
- import $f1b682a4c8c5631c$exports from "./zh-TW.mjs";
35
- import {useId as $1Hnir$useId, filterDOMProps as $1Hnir$filterDOMProps, mergeProps as $1Hnir$mergeProps, useRouter as $1Hnir$useRouter, useSlotId as $1Hnir$useSlotId, useLinkProps as $1Hnir$useLinkProps, useEffectEvent as $1Hnir$useEffectEvent, useLayoutEffect as $1Hnir$useLayoutEffect, useResizeObserver as $1Hnir$useResizeObserver} from "@react-aria/utils";
36
- import {useLocalizedStringFormatter as $1Hnir$useLocalizedStringFormatter, useLocale as $1Hnir$useLocale} from "@react-aria/i18n";
37
- import {useLongPress as $1Hnir$useLongPress, usePress as $1Hnir$usePress, useHover as $1Hnir$useHover, isFocusVisible as $1Hnir$isFocusVisible, useKeyboard as $1Hnir$useKeyboard, useFocus as $1Hnir$useFocus, useInteractionModality as $1Hnir$useInteractionModality} from "@react-aria/interactions";
38
- import {useOverlayTrigger as $1Hnir$useOverlayTrigger} from "@react-aria/overlays";
39
- import {useSelectableList as $1Hnir$useSelectableList, useSelectableItem as $1Hnir$useSelectableItem} from "@react-aria/selection";
40
- import {getItemCount as $1Hnir$getItemCount} from "@react-stately/collections";
41
- import {useRef as $1Hnir$useRef, useCallback as $1Hnir$useCallback, useState as $1Hnir$useState, useEffect as $1Hnir$useEffect} from "react";
42
-
43
-
44
- function $parcel$interopDefault(a) {
45
- return a && a.__esModule ? a.default : a;
46
- }
47
- /*
48
- * Copyright 2020 Adobe. All rights reserved.
49
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
50
- * you may not use this file except in compliance with the License. You may obtain a copy
51
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
52
- *
53
- * Unless required by applicable law or agreed to in writing, software distributed under
54
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
55
- * OF ANY KIND, either express or implied. See the License for the specific language
56
- * governing permissions and limitations under the License.
57
- */ /*
58
- * Copyright 2020 Adobe. All rights reserved.
59
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
60
- * you may not use this file except in compliance with the License. You may obtain a copy
61
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
62
- *
63
- * Unless required by applicable law or agreed to in writing, software distributed under
64
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
65
- * OF ANY KIND, either express or implied. See the License for the specific language
66
- * governing permissions and limitations under the License.
67
- */ var $2cbb7ca666678a14$exports = {};
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
- $2cbb7ca666678a14$exports = {
103
- "ar-AE": $c0398ad35c3639b7$exports,
104
- "bg-BG": $7af657c4165927c3$exports,
105
- "cs-CZ": $d95d4da6d531ab81$exports,
106
- "da-DK": $24ebda9c775dca17$exports,
107
- "de-DE": $743e0dfca6cab1e9$exports,
108
- "el-GR": $a2f41026e05f1c84$exports,
109
- "en-US": $43b800e97c901737$exports,
110
- "es-ES": $442f5f6ac211e29f$exports,
111
- "et-EE": $dff280acfeb2d8ac$exports,
112
- "fi-FI": $51608325613944d7$exports,
113
- "fr-FR": $c4a1b1eabeaa87be$exports,
114
- "he-IL": $8c74815cdee18d1b$exports,
115
- "hr-HR": $fd0e9ef6a7fe0ec9$exports,
116
- "hu-HU": $a89a74a39eba465a$exports,
117
- "it-IT": $edc7c66594a0ae8a$exports,
118
- "ja-JP": $f1ab51510712db52$exports,
119
- "ko-KR": $f9b672d9b82fa3d6$exports,
120
- "lt-LT": $a385f3910feda499$exports,
121
- "lv-LV": $4f1bde932c441789$exports,
122
- "nb-NO": $914a51a8a594d5be$exports,
123
- "nl-NL": $89aaf803103bb500$exports,
124
- "pl-PL": $c685891476dbaaca$exports,
125
- "pt-BR": $885879b9b10c2959$exports,
126
- "pt-PT": $6b39616688a51692$exports,
127
- "ro-RO": $f26362aed63f47e2$exports,
128
- "ru-RU": $06cbade644558bf0$exports,
129
- "sk-SK": $0a391ff68f9d59b1$exports,
130
- "sl-SI": $8193cf0e649c7928$exports,
131
- "sr-SP": $f398debcce5a5c55$exports,
132
- "sv-SE": $9e9fef000aa4c013$exports,
133
- "tr-TR": $c016c8183bbe3d68$exports,
134
- "uk-UA": $ca4f6c8462244e62$exports,
135
- "zh-CN": $2d9960c02ccac927$exports,
136
- "zh-TW": $f1b682a4c8c5631c$exports
137
- };
138
-
139
-
140
-
141
-
142
-
143
-
144
- function $168583247155ddda$export$dc9c12ed27dd1b49(props, state, ref) {
145
- let { type: type = "menu", isDisabled: isDisabled, trigger: trigger = "press" } = props;
146
- let menuTriggerId = (0, $1Hnir$useId)();
147
- let { triggerProps: triggerProps, overlayProps: overlayProps } = (0, $1Hnir$useOverlayTrigger)({
148
- type: type
149
- }, state, ref);
150
- let onKeyDown = (e)=>{
151
- if (isDisabled) return;
152
- if (trigger === "longPress" && !e.altKey) return;
153
- if (ref && ref.current) switch(e.key){
154
- case "Enter":
155
- case " ":
156
- if (trigger === "longPress") return;
157
- // fallthrough
158
- case "ArrowDown":
159
- // Stop propagation, unless it would already be handled by useKeyboard.
160
- if (!("continuePropagation" in e)) e.stopPropagation();
161
- e.preventDefault();
162
- state.toggle("first");
163
- break;
164
- case "ArrowUp":
165
- if (!("continuePropagation" in e)) e.stopPropagation();
166
- e.preventDefault();
167
- state.toggle("last");
168
- break;
169
- default:
170
- // Allow other keys.
171
- if ("continuePropagation" in e) e.continuePropagation();
172
- }
173
- };
174
- let stringFormatter = (0, $1Hnir$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($2cbb7ca666678a14$exports))), "@react-aria/menu");
175
- let { longPressProps: longPressProps } = (0, $1Hnir$useLongPress)({
176
- isDisabled: isDisabled || trigger !== "longPress",
177
- accessibilityDescription: stringFormatter.format("longPressMessage"),
178
- onLongPressStart () {
179
- state.close();
180
- },
181
- onLongPress () {
182
- state.open("first");
183
- }
184
- });
185
- let pressProps = {
186
- onPressStart (e) {
187
- // For consistency with native, open the menu on mouse/key down, but touch up.
188
- if (e.pointerType !== "touch" && e.pointerType !== "keyboard" && !isDisabled) // If opened with a screen reader, auto focus the first item.
189
- // Otherwise, the menu itself will be focused.
190
- state.open(e.pointerType === "virtual" ? "first" : null);
191
- },
192
- onPress (e) {
193
- if (e.pointerType === "touch" && !isDisabled) state.toggle();
194
- }
195
- };
196
- // omit onPress from triggerProps since we override it above.
197
- delete triggerProps.onPress;
198
- return {
199
- menuTriggerProps: {
200
- ...triggerProps,
201
- ...trigger === "press" ? pressProps : longPressProps,
202
- id: menuTriggerId,
203
- onKeyDown: onKeyDown
204
- },
205
- menuProps: {
206
- ...overlayProps,
207
- "aria-labelledby": menuTriggerId,
208
- autoFocus: state.focusStrategy || true,
209
- onClose: state.close
210
- }
211
- };
212
- }
213
-
214
-
215
- /*
216
- * Copyright 2020 Adobe. All rights reserved.
217
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
218
- * you may not use this file except in compliance with the License. You may obtain a copy
219
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
220
- *
221
- * Unless required by applicable law or agreed to in writing, software distributed under
222
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
223
- * OF ANY KIND, either express or implied. See the License for the specific language
224
- * governing permissions and limitations under the License.
225
- */
226
-
227
- const $d5336fe17ce95402$export$6f49b4016bfc8d56 = new WeakMap();
228
- function $d5336fe17ce95402$export$38eaa17faae8f579(props, state, ref) {
229
- let { shouldFocusWrap: shouldFocusWrap = true, onKeyDown: onKeyDown, onKeyUp: onKeyUp, ...otherProps } = props;
230
- if (!props["aria-label"] && !props["aria-labelledby"]) console.warn("An aria-label or aria-labelledby prop is required for accessibility.");
231
- let domProps = (0, $1Hnir$filterDOMProps)(props, {
232
- labelable: true
233
- });
234
- let { listProps: listProps } = (0, $1Hnir$useSelectableList)({
235
- ...otherProps,
236
- ref: ref,
237
- selectionManager: state.selectionManager,
238
- collection: state.collection,
239
- disabledKeys: state.disabledKeys,
240
- shouldFocusWrap: shouldFocusWrap,
241
- linkBehavior: "override"
242
- });
243
- $d5336fe17ce95402$export$6f49b4016bfc8d56.set(state, {
244
- onClose: props.onClose,
245
- onAction: props.onAction
246
- });
247
- return {
248
- menuProps: (0, $1Hnir$mergeProps)(domProps, {
249
- onKeyDown: onKeyDown,
250
- onKeyUp: onKeyUp
251
- }, {
252
- role: "menu",
253
- ...listProps,
254
- onKeyDown: (e)=>{
255
- // don't clear the menu selected keys if the user is presses escape since escape closes the menu
256
- if (e.key !== "Escape") listProps.onKeyDown(e);
257
- }
258
- })
259
- };
260
- }
261
-
1
+ import {useMenuTrigger as $168583247155ddda$export$dc9c12ed27dd1b49} from "./useMenuTrigger.mjs";
2
+ import {useMenu as $d5336fe17ce95402$export$38eaa17faae8f579} from "./useMenu.mjs";
3
+ import {useMenuItem as $a2e5df62f93c7633$export$9d32628fc2aea7da} from "./useMenuItem.mjs";
4
+ import {useMenuSection as $3e5eb2498db5b506$export$73f7a44322579622} from "./useMenuSection.mjs";
5
+ import {UNSTABLE_useSubmenuTrigger as $0065b146e7192841$export$3819f8ee9f4ce664} from "./useSubmenuTrigger.mjs";
262
6
 
263
7
  /*
264
8
  * Copyright 2020 Adobe. All rights reserved.
@@ -275,466 +19,6 @@ function $d5336fe17ce95402$export$38eaa17faae8f579(props, state, ref) {
275
19
 
276
20
 
277
21
 
278
- function $a2e5df62f93c7633$export$9d32628fc2aea7da(props, state, ref) {
279
- let { 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;
280
- let isTrigger = !!hasPopup;
281
- var _props_isDisabled;
282
- let isDisabled = (_props_isDisabled = props.isDisabled) !== null && _props_isDisabled !== void 0 ? _props_isDisabled : state.selectionManager.isDisabled(key);
283
- var _props_isSelected;
284
- let isSelected = (_props_isSelected = props.isSelected) !== null && _props_isSelected !== void 0 ? _props_isSelected : state.selectionManager.isSelected(key);
285
- let data = (0, $d5336fe17ce95402$export$6f49b4016bfc8d56).get(state);
286
- let item = state.collection.getItem(key);
287
- let onClose = props.onClose || data.onClose;
288
- let router = (0, $1Hnir$useRouter)();
289
- let performAction = (e)=>{
290
- var _item_props;
291
- if (isTrigger) return;
292
- 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();
293
- if (props.onAction) props.onAction(key);
294
- else if (data.onAction) data.onAction(key);
295
- if (e.target instanceof HTMLAnchorElement) router.open(e.target, e, item.props.href, item.props.routerOptions);
296
- };
297
- let role = "menuitem";
298
- if (!isTrigger) {
299
- if (state.selectionManager.selectionMode === "single") role = "menuitemradio";
300
- else if (state.selectionManager.selectionMode === "multiple") role = "menuitemcheckbox";
301
- }
302
- let labelId = (0, $1Hnir$useSlotId)();
303
- let descriptionId = (0, $1Hnir$useSlotId)();
304
- let keyboardId = (0, $1Hnir$useSlotId)();
305
- let ariaProps = {
306
- "aria-disabled": isDisabled || undefined,
307
- role: role,
308
- "aria-label": props["aria-label"],
309
- "aria-labelledby": labelId,
310
- "aria-describedby": [
311
- descriptionId,
312
- keyboardId
313
- ].filter(Boolean).join(" ") || undefined,
314
- "aria-controls": props["aria-controls"],
315
- "aria-haspopup": hasPopup,
316
- "aria-expanded": props["aria-expanded"]
317
- };
318
- if (state.selectionManager.selectionMode !== "none" && !isTrigger) ariaProps["aria-checked"] = isSelected;
319
- if (isVirtualized) {
320
- ariaProps["aria-posinset"] = item === null || item === void 0 ? void 0 : item.index;
321
- ariaProps["aria-setsize"] = (0, $1Hnir$getItemCount)(state.collection);
322
- }
323
- let onPressStart = (e)=>{
324
- if (e.pointerType === "keyboard") performAction(e);
325
- pressStartProp === null || pressStartProp === void 0 ? void 0 : pressStartProp(e);
326
- };
327
- let onPressUp = (e)=>{
328
- if (e.pointerType !== "keyboard") {
329
- performAction(e);
330
- // Pressing a menu item should close by default in single selection mode but not multiple
331
- // selection mode, except if overridden by the closeOnSelect prop.
332
- if (!isTrigger && onClose && (closeOnSelect !== null && closeOnSelect !== void 0 ? closeOnSelect : state.selectionManager.selectionMode !== "multiple" || state.selectionManager.isLink(key))) onClose();
333
- }
334
- pressUpProp === null || pressUpProp === void 0 ? void 0 : pressUpProp(e);
335
- };
336
- let { itemProps: itemProps, isFocused: isFocused } = (0, $1Hnir$useSelectableItem)({
337
- selectionManager: state.selectionManager,
338
- key: key,
339
- ref: ref,
340
- shouldSelectOnPressUp: true,
341
- allowsDifferentPressOrigin: true,
342
- // Disable all handling of links in useSelectable item
343
- // because we handle it ourselves. The behavior of menus
344
- // is slightly different from other collections because
345
- // actions are performed on key down rather than key up.
346
- linkBehavior: "none"
347
- });
348
- let { pressProps: pressProps, isPressed: isPressed } = (0, $1Hnir$usePress)({
349
- onPressStart: onPressStart,
350
- onPress: onPress,
351
- onPressUp: onPressUp,
352
- onPressChange: onPressChange,
353
- onPressEnd: onPressEnd,
354
- isDisabled: isDisabled
355
- });
356
- let { hoverProps: hoverProps } = (0, $1Hnir$useHover)({
357
- isDisabled: isDisabled,
358
- onHoverStart (e) {
359
- if (!(0, $1Hnir$isFocusVisible)()) {
360
- state.selectionManager.setFocused(true);
361
- state.selectionManager.setFocusedKey(key);
362
- }
363
- hoverStartProp === null || hoverStartProp === void 0 ? void 0 : hoverStartProp(e);
364
- },
365
- onHoverChange: onHoverChange,
366
- onHoverEnd: onHoverEnd
367
- });
368
- let { keyboardProps: keyboardProps } = (0, $1Hnir$useKeyboard)({
369
- onKeyDown: (e)=>{
370
- // Ignore repeating events, which may have started on the menu trigger before moving
371
- // focus to the menu item. We want to wait for a second complete key press sequence.
372
- if (e.repeat) {
373
- e.continuePropagation();
374
- return;
375
- }
376
- switch(e.key){
377
- case " ":
378
- if (!isDisabled && state.selectionManager.selectionMode === "none" && !isTrigger && closeOnSelect !== false && onClose) onClose();
379
- break;
380
- case "Enter":
381
- // The Enter key should always close on select, except if overridden.
382
- if (!isDisabled && closeOnSelect !== false && !isTrigger && onClose) onClose();
383
- break;
384
- default:
385
- if (!isTrigger) e.continuePropagation();
386
- onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
387
- break;
388
- }
389
- },
390
- onKeyUp: onKeyUp
391
- });
392
- let { focusProps: focusProps } = (0, $1Hnir$useFocus)({
393
- onBlur: onBlur,
394
- onFocus: onFocus,
395
- onFocusChange: onFocusChange
396
- });
397
- let domProps = (0, $1Hnir$filterDOMProps)(item.props);
398
- delete domProps.id;
399
- let linkProps = (0, $1Hnir$useLinkProps)(item.props);
400
- return {
401
- menuItemProps: {
402
- ...ariaProps,
403
- ...(0, $1Hnir$mergeProps)(domProps, linkProps, isTrigger ? {
404
- onFocus: itemProps.onFocus
405
- } : itemProps, pressProps, hoverProps, keyboardProps, focusProps),
406
- tabIndex: itemProps.tabIndex != null ? -1 : undefined
407
- },
408
- labelProps: {
409
- id: labelId
410
- },
411
- descriptionProps: {
412
- id: descriptionId
413
- },
414
- keyboardShortcutProps: {
415
- id: keyboardId
416
- },
417
- isFocused: isFocused,
418
- isSelected: isSelected,
419
- isPressed: isPressed,
420
- isDisabled: isDisabled
421
- };
422
- }
423
-
424
-
425
- /*
426
- * Copyright 2020 Adobe. All rights reserved.
427
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
428
- * you may not use this file except in compliance with the License. You may obtain a copy
429
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
430
- *
431
- * Unless required by applicable law or agreed to in writing, software distributed under
432
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
433
- * OF ANY KIND, either express or implied. See the License for the specific language
434
- * governing permissions and limitations under the License.
435
- */
436
- function $3e5eb2498db5b506$export$73f7a44322579622(props) {
437
- let { heading: heading, "aria-label": ariaLabel } = props;
438
- let headingId = (0, $1Hnir$useId)();
439
- return {
440
- itemProps: {
441
- role: "presentation"
442
- },
443
- headingProps: heading ? {
444
- // Techincally, menus cannot contain headings according to ARIA.
445
- // We hide the heading from assistive technology, using role="presentation",
446
- // and only use it as a label for the nested group.
447
- id: headingId,
448
- role: "presentation"
449
- } : {},
450
- groupProps: {
451
- role: "group",
452
- "aria-label": ariaLabel,
453
- "aria-labelledby": heading ? headingId : undefined
454
- }
455
- };
456
- }
457
-
458
-
459
- /*
460
- * Copyright 2023 Adobe. All rights reserved.
461
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
462
- * you may not use this file except in compliance with the License. You may obtain a copy
463
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
464
- *
465
- * Unless required by applicable law or agreed to in writing, software distributed under
466
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
467
- * OF ANY KIND, either express or implied. See the License for the specific language
468
- * governing permissions and limitations under the License.
469
- */
470
-
471
-
472
-
473
-
474
-
475
- const $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS = 2;
476
- const $d275435c250248f8$var$THROTTLE_TIME = 50;
477
- const $d275435c250248f8$var$TIMEOUT_TIME = 1000;
478
- const $d275435c250248f8$var$ANGLE_PADDING = Math.PI / 12; // 15°
479
- function $d275435c250248f8$export$85ec83e04c95f50a(options) {
480
- let { menuRef: menuRef, submenuRef: submenuRef, isOpen: isOpen, isDisabled: isDisabled } = options;
481
- let prevPointerPos = (0, $1Hnir$useRef)();
482
- let submenuRect = (0, $1Hnir$useRef)();
483
- let lastProcessedTime = (0, $1Hnir$useRef)(0);
484
- let timeout = (0, $1Hnir$useRef)();
485
- let autoCloseTimeout = (0, $1Hnir$useRef)();
486
- let submenuSide = (0, $1Hnir$useRef)();
487
- let movementsTowardsSubmenuCount = (0, $1Hnir$useRef)(2);
488
- let [preventPointerEvents, setPreventPointerEvents] = (0, $1Hnir$useState)(false);
489
- let updateSubmenuRect = ()=>{
490
- if (submenuRef.current) {
491
- submenuRect.current = submenuRef.current.getBoundingClientRect();
492
- submenuSide.current = undefined;
493
- }
494
- };
495
- (0, $1Hnir$useResizeObserver)({
496
- ref: submenuRef,
497
- onResize: updateSubmenuRect
498
- });
499
- let reset = ()=>{
500
- setPreventPointerEvents(false);
501
- movementsTowardsSubmenuCount.current = $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS;
502
- prevPointerPos.current = undefined;
503
- };
504
- let modality = (0, $1Hnir$useInteractionModality)();
505
- (0, $1Hnir$useEffect)(()=>{
506
- if (preventPointerEvents && menuRef.current) menuRef.current.style.pointerEvents = "none";
507
- else menuRef.current.style.pointerEvents = "";
508
- }, [
509
- menuRef,
510
- preventPointerEvents
511
- ]);
512
- (0, $1Hnir$useEffect)(()=>{
513
- let submenu = submenuRef.current;
514
- let menu = menuRef.current;
515
- if (isDisabled || !submenu || !isOpen || modality !== "pointer") {
516
- reset();
517
- return;
518
- }
519
- submenuRect.current = submenu.getBoundingClientRect();
520
- let onPointerMove = (e)=>{
521
- if (e.pointerType === "touch" || e.pointerType === "pen") return;
522
- let currentTime = Date.now();
523
- // Throttle
524
- if (currentTime - lastProcessedTime.current < $d275435c250248f8$var$THROTTLE_TIME) return;
525
- clearTimeout(timeout.current);
526
- clearTimeout(autoCloseTimeout.current);
527
- let { clientX: mouseX, clientY: mouseY } = e;
528
- if (!prevPointerPos.current) {
529
- prevPointerPos.current = {
530
- x: mouseX,
531
- y: mouseY
532
- };
533
- return;
534
- }
535
- if (!submenuRect.current) return;
536
- if (!submenuSide.current) submenuSide.current = mouseX > submenuRect.current.right ? "left" : "right";
537
- // Pointer is outside of parent menu
538
- if (mouseX < menu.getBoundingClientRect().left || mouseX > menu.getBoundingClientRect().right || mouseY < menu.getBoundingClientRect().top || mouseY > menu.getBoundingClientRect().bottom) {
539
- reset();
540
- return;
541
- }
542
- /* Check if pointer is moving towards submenu.
543
- Uses the 2-argument arctangent (https://en.wikipedia.org/wiki/Atan2) to calculate:
544
- - angle between previous pointer and top of submenu
545
- - angle between previous pointer and bottom of submenu
546
- - angle between previous pointer and current pointer (delta)
547
- If the pointer delta angle value is between the top and bottom angle values, we know the pointer is moving towards the submenu.
548
- */ let prevMouseX = prevPointerPos.current.x;
549
- let prevMouseY = prevPointerPos.current.y;
550
- let toSubmenuX = submenuSide.current === "right" ? submenuRect.current.left - prevMouseX : prevMouseX - submenuRect.current.right;
551
- let angleTop = Math.atan2(prevMouseY - submenuRect.current.top, toSubmenuX) + $d275435c250248f8$var$ANGLE_PADDING;
552
- let angleBottom = Math.atan2(prevMouseY - submenuRect.current.bottom, toSubmenuX) - $d275435c250248f8$var$ANGLE_PADDING;
553
- let anglePointer = Math.atan2(prevMouseY - mouseY, submenuSide.current === "left" ? -(mouseX - prevMouseX) : mouseX - prevMouseX);
554
- let isMovingTowardsSubmenu = anglePointer < angleTop && anglePointer > angleBottom;
555
- movementsTowardsSubmenuCount.current = isMovingTowardsSubmenu ? Math.min(movementsTowardsSubmenuCount.current + 1, $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS) : Math.max(movementsTowardsSubmenuCount.current - 1, 0);
556
- if (movementsTowardsSubmenuCount.current >= $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS) setPreventPointerEvents(true);
557
- else setPreventPointerEvents(false);
558
- lastProcessedTime.current = currentTime;
559
- prevPointerPos.current = {
560
- x: mouseX,
561
- y: mouseY
562
- };
563
- // If the pointer is moving towards the submenu, start a timeout to close if no other movements are made after 500ms.
564
- if (isMovingTowardsSubmenu) timeout.current = setTimeout(()=>{
565
- reset();
566
- autoCloseTimeout.current = setTimeout(()=>{
567
- // Fire a pointerover event to trigger the menu to close.
568
- // Wait until pointer-events:none is no longer applied
569
- let target = document.elementFromPoint(mouseX, mouseY);
570
- if (target && menu.contains(target)) target.dispatchEvent(new PointerEvent("pointerover", {
571
- bubbles: true,
572
- cancelable: true
573
- }));
574
- }, 100);
575
- }, $d275435c250248f8$var$TIMEOUT_TIME);
576
- };
577
- window.addEventListener("pointermove", onPointerMove);
578
- return ()=>{
579
- window.removeEventListener("pointermove", onPointerMove);
580
- clearTimeout(timeout.current);
581
- clearTimeout(autoCloseTimeout.current);
582
- movementsTowardsSubmenuCount.current = $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS;
583
- };
584
- }, [
585
- isDisabled,
586
- isOpen,
587
- menuRef,
588
- modality,
589
- setPreventPointerEvents,
590
- submenuRef
591
- ]);
592
- }
593
-
594
-
595
- function $0065b146e7192841$export$3819f8ee9f4ce664(props, state, ref) {
596
- let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type = "menu", isDisabled: isDisabled, node: node, delay: delay = 200 } = props;
597
- let submenuTriggerId = (0, $1Hnir$useId)();
598
- let overlayId = (0, $1Hnir$useId)();
599
- let { direction: direction } = (0, $1Hnir$useLocale)();
600
- let openTimeout = (0, $1Hnir$useRef)();
601
- let cancelOpenTimeout = (0, $1Hnir$useCallback)(()=>{
602
- if (openTimeout.current) {
603
- clearTimeout(openTimeout.current);
604
- openTimeout.current = undefined;
605
- }
606
- }, [
607
- openTimeout
608
- ]);
609
- let onSubmenuOpen = (0, $1Hnir$useEffectEvent)((focusStrategy)=>{
610
- cancelOpenTimeout();
611
- state.open(focusStrategy);
612
- });
613
- let onSubmenuClose = (0, $1Hnir$useEffectEvent)(()=>{
614
- cancelOpenTimeout();
615
- state.close();
616
- });
617
- (0, $1Hnir$useLayoutEffect)(()=>{
618
- return ()=>{
619
- cancelOpenTimeout();
620
- };
621
- }, [
622
- cancelOpenTimeout
623
- ]);
624
- let submenuKeyDown = (e)=>{
625
- switch(e.key){
626
- case "ArrowLeft":
627
- if (direction === "ltr" && e.currentTarget.contains(e.target)) {
628
- e.stopPropagation();
629
- onSubmenuClose();
630
- ref.current.focus();
631
- }
632
- break;
633
- case "ArrowRight":
634
- if (direction === "rtl" && e.currentTarget.contains(e.target)) {
635
- e.stopPropagation();
636
- onSubmenuClose();
637
- ref.current.focus();
638
- }
639
- break;
640
- case "Escape":
641
- e.stopPropagation();
642
- state.closeAll();
643
- break;
644
- }
645
- };
646
- let submenuProps = {
647
- id: overlayId,
648
- "aria-label": node.textValue,
649
- submenuLevel: state.submenuLevel,
650
- ...type === "menu" && {
651
- onClose: state.closeAll,
652
- autoFocus: state.focusStrategy,
653
- onKeyDown: submenuKeyDown
654
- }
655
- };
656
- let submenuTriggerKeyDown = (e)=>{
657
- switch(e.key){
658
- case "ArrowRight":
659
- if (!isDisabled) {
660
- if (direction === "ltr") {
661
- if (!state.isOpen) onSubmenuOpen("first");
662
- 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();
663
- } else if (state.isOpen) onSubmenuClose();
664
- else e.continuePropagation();
665
- }
666
- break;
667
- case "ArrowLeft":
668
- if (!isDisabled) {
669
- if (direction === "rtl") {
670
- if (!state.isOpen) onSubmenuOpen("first");
671
- 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();
672
- } else if (state.isOpen) onSubmenuClose();
673
- else e.continuePropagation();
674
- }
675
- break;
676
- case "Escape":
677
- state.closeAll();
678
- break;
679
- default:
680
- e.continuePropagation();
681
- break;
682
- }
683
- };
684
- let onPressStart = (e)=>{
685
- if (!isDisabled && (e.pointerType === "virtual" || e.pointerType === "keyboard")) // If opened with a screen reader or keyboard, auto focus the first submenu item.
686
- onSubmenuOpen("first");
687
- };
688
- let onPress = (e)=>{
689
- 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
690
- // press up happening on the newly opened tray items
691
- onSubmenuOpen();
692
- };
693
- let onHoverChange = (isHovered)=>{
694
- if (!isDisabled) {
695
- if (isHovered && !state.isOpen) {
696
- if (!openTimeout.current) openTimeout.current = setTimeout(()=>{
697
- onSubmenuOpen();
698
- }, delay);
699
- } else if (!isHovered) cancelOpenTimeout();
700
- }
701
- };
702
- let onBlur = (e)=>{
703
- if (state.isOpen && parentMenuRef.current.contains(e.relatedTarget)) onSubmenuClose();
704
- };
705
- let shouldCloseOnInteractOutside = (target)=>{
706
- if (target !== ref.current) return true;
707
- return false;
708
- };
709
- (0, $d275435c250248f8$export$85ec83e04c95f50a)({
710
- menuRef: parentMenuRef,
711
- submenuRef: submenuRef,
712
- isOpen: state.isOpen,
713
- isDisabled: isDisabled
714
- });
715
- return {
716
- submenuTriggerProps: {
717
- id: submenuTriggerId,
718
- "aria-controls": state.isOpen ? overlayId : undefined,
719
- "aria-haspopup": !isDisabled ? type : undefined,
720
- "aria-expanded": state.isOpen ? "true" : "false",
721
- onPressStart: onPressStart,
722
- onPress: onPress,
723
- onHoverChange: onHoverChange,
724
- onKeyDown: submenuTriggerKeyDown,
725
- onBlur: onBlur,
726
- isOpen: state.isOpen
727
- },
728
- submenuProps: submenuProps,
729
- popoverProps: {
730
- isNonModal: true,
731
- disableFocusManagement: true,
732
- shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
733
- }
734
- };
735
- }
736
-
737
-
738
22
 
739
23
 
740
24
  export {$168583247155ddda$export$dc9c12ed27dd1b49 as useMenuTrigger, $d5336fe17ce95402$export$38eaa17faae8f579 as useMenu, $a2e5df62f93c7633$export$9d32628fc2aea7da as useMenuItem, $3e5eb2498db5b506$export$73f7a44322579622 as useMenuSection, $0065b146e7192841$export$3819f8ee9f4ce664 as UNSTABLE_useSubmenuTrigger};