@tamagui/create-menu 2.0.0-1

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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/MenuPredefined.cjs +182 -0
  3. package/dist/cjs/MenuPredefined.js +162 -0
  4. package/dist/cjs/MenuPredefined.js.map +6 -0
  5. package/dist/cjs/MenuPredefined.native.js +185 -0
  6. package/dist/cjs/MenuPredefined.native.js.map +1 -0
  7. package/dist/cjs/createBaseMenu.cjs +927 -0
  8. package/dist/cjs/createBaseMenu.js +724 -0
  9. package/dist/cjs/createBaseMenu.js.map +6 -0
  10. package/dist/cjs/createBaseMenu.native.js +1105 -0
  11. package/dist/cjs/createBaseMenu.native.js.map +1 -0
  12. package/dist/cjs/createNativeMenu/createNativeMenu.cjs +224 -0
  13. package/dist/cjs/createNativeMenu/createNativeMenu.js +172 -0
  14. package/dist/cjs/createNativeMenu/createNativeMenu.js.map +6 -0
  15. package/dist/cjs/createNativeMenu/createNativeMenu.native.js +287 -0
  16. package/dist/cjs/createNativeMenu/createNativeMenu.native.js.map +1 -0
  17. package/dist/cjs/createNativeMenu/createNativeMenuTypes.cjs +16 -0
  18. package/dist/cjs/createNativeMenu/createNativeMenuTypes.js +14 -0
  19. package/dist/cjs/createNativeMenu/createNativeMenuTypes.js.map +6 -0
  20. package/dist/cjs/createNativeMenu/createNativeMenuTypes.native.js +19 -0
  21. package/dist/cjs/createNativeMenu/createNativeMenuTypes.native.js.map +1 -0
  22. package/dist/cjs/createNativeMenu/index.cjs +19 -0
  23. package/dist/cjs/createNativeMenu/index.js +16 -0
  24. package/dist/cjs/createNativeMenu/index.js.map +6 -0
  25. package/dist/cjs/createNativeMenu/index.native.js +22 -0
  26. package/dist/cjs/createNativeMenu/index.native.js.map +1 -0
  27. package/dist/cjs/createNativeMenu/utils.cjs +68 -0
  28. package/dist/cjs/createNativeMenu/utils.js +66 -0
  29. package/dist/cjs/createNativeMenu/utils.js.map +6 -0
  30. package/dist/cjs/createNativeMenu/utils.native.js +94 -0
  31. package/dist/cjs/createNativeMenu/utils.native.js.map +1 -0
  32. package/dist/cjs/createNativeMenu/withNativeMenu.cjs +37 -0
  33. package/dist/cjs/createNativeMenu/withNativeMenu.js +30 -0
  34. package/dist/cjs/createNativeMenu/withNativeMenu.js.map +6 -0
  35. package/dist/cjs/createNativeMenu/withNativeMenu.native.js +43 -0
  36. package/dist/cjs/createNativeMenu/withNativeMenu.native.js.map +1 -0
  37. package/dist/cjs/index.cjs +30 -0
  38. package/dist/cjs/index.js +24 -0
  39. package/dist/cjs/index.js.map +6 -0
  40. package/dist/cjs/index.native.js +33 -0
  41. package/dist/cjs/index.native.js.map +1 -0
  42. package/dist/esm/MenuPredefined.js +147 -0
  43. package/dist/esm/MenuPredefined.js.map +6 -0
  44. package/dist/esm/MenuPredefined.mjs +159 -0
  45. package/dist/esm/MenuPredefined.mjs.map +1 -0
  46. package/dist/esm/MenuPredefined.native.js +159 -0
  47. package/dist/esm/MenuPredefined.native.js.map +1 -0
  48. package/dist/esm/createBaseMenu.js +729 -0
  49. package/dist/esm/createBaseMenu.js.map +6 -0
  50. package/dist/esm/createBaseMenu.mjs +893 -0
  51. package/dist/esm/createBaseMenu.mjs.map +1 -0
  52. package/dist/esm/createBaseMenu.native.js +1068 -0
  53. package/dist/esm/createBaseMenu.native.js.map +1 -0
  54. package/dist/esm/createNativeMenu/createNativeMenu.js +150 -0
  55. package/dist/esm/createNativeMenu/createNativeMenu.js.map +6 -0
  56. package/dist/esm/createNativeMenu/createNativeMenu.mjs +190 -0
  57. package/dist/esm/createNativeMenu/createNativeMenu.mjs.map +1 -0
  58. package/dist/esm/createNativeMenu/createNativeMenu.native.js +250 -0
  59. package/dist/esm/createNativeMenu/createNativeMenu.native.js.map +1 -0
  60. package/dist/esm/createNativeMenu/createNativeMenuTypes.js +1 -0
  61. package/dist/esm/createNativeMenu/createNativeMenuTypes.js.map +6 -0
  62. package/dist/esm/createNativeMenu/createNativeMenuTypes.mjs +2 -0
  63. package/dist/esm/createNativeMenu/createNativeMenuTypes.mjs.map +1 -0
  64. package/dist/esm/createNativeMenu/createNativeMenuTypes.native.js +2 -0
  65. package/dist/esm/createNativeMenu/createNativeMenuTypes.native.js.map +1 -0
  66. package/dist/esm/createNativeMenu/index.js +3 -0
  67. package/dist/esm/createNativeMenu/index.js.map +6 -0
  68. package/dist/esm/createNativeMenu/index.mjs +3 -0
  69. package/dist/esm/createNativeMenu/index.mjs.map +1 -0
  70. package/dist/esm/createNativeMenu/index.native.js +3 -0
  71. package/dist/esm/createNativeMenu/index.native.js.map +1 -0
  72. package/dist/esm/createNativeMenu/utils.js +47 -0
  73. package/dist/esm/createNativeMenu/utils.js.map +6 -0
  74. package/dist/esm/createNativeMenu/utils.mjs +29 -0
  75. package/dist/esm/createNativeMenu/utils.mjs.map +1 -0
  76. package/dist/esm/createNativeMenu/utils.native.js +52 -0
  77. package/dist/esm/createNativeMenu/utils.native.js.map +1 -0
  78. package/dist/esm/createNativeMenu/withNativeMenu.js +15 -0
  79. package/dist/esm/createNativeMenu/withNativeMenu.js.map +6 -0
  80. package/dist/esm/createNativeMenu/withNativeMenu.mjs +14 -0
  81. package/dist/esm/createNativeMenu/withNativeMenu.mjs.map +1 -0
  82. package/dist/esm/createNativeMenu/withNativeMenu.native.js +17 -0
  83. package/dist/esm/createNativeMenu/withNativeMenu.native.js.map +1 -0
  84. package/dist/esm/index.js +8 -0
  85. package/dist/esm/index.js.map +6 -0
  86. package/dist/esm/index.mjs +6 -0
  87. package/dist/esm/index.mjs.map +1 -0
  88. package/dist/esm/index.native.js +6 -0
  89. package/dist/esm/index.native.js.map +1 -0
  90. package/dist/jsx/MenuPredefined.js +147 -0
  91. package/dist/jsx/MenuPredefined.js.map +6 -0
  92. package/dist/jsx/MenuPredefined.mjs +159 -0
  93. package/dist/jsx/MenuPredefined.mjs.map +1 -0
  94. package/dist/jsx/MenuPredefined.native.js +185 -0
  95. package/dist/jsx/MenuPredefined.native.js.map +1 -0
  96. package/dist/jsx/createBaseMenu.js +729 -0
  97. package/dist/jsx/createBaseMenu.js.map +6 -0
  98. package/dist/jsx/createBaseMenu.mjs +893 -0
  99. package/dist/jsx/createBaseMenu.mjs.map +1 -0
  100. package/dist/jsx/createBaseMenu.native.js +1105 -0
  101. package/dist/jsx/createBaseMenu.native.js.map +1 -0
  102. package/dist/jsx/createNativeMenu/createNativeMenu.js +150 -0
  103. package/dist/jsx/createNativeMenu/createNativeMenu.js.map +6 -0
  104. package/dist/jsx/createNativeMenu/createNativeMenu.mjs +190 -0
  105. package/dist/jsx/createNativeMenu/createNativeMenu.mjs.map +1 -0
  106. package/dist/jsx/createNativeMenu/createNativeMenu.native.js +287 -0
  107. package/dist/jsx/createNativeMenu/createNativeMenu.native.js.map +1 -0
  108. package/dist/jsx/createNativeMenu/createNativeMenuTypes.js +1 -0
  109. package/dist/jsx/createNativeMenu/createNativeMenuTypes.js.map +6 -0
  110. package/dist/jsx/createNativeMenu/createNativeMenuTypes.mjs +2 -0
  111. package/dist/jsx/createNativeMenu/createNativeMenuTypes.mjs.map +1 -0
  112. package/dist/jsx/createNativeMenu/createNativeMenuTypes.native.js +19 -0
  113. package/dist/jsx/createNativeMenu/createNativeMenuTypes.native.js.map +1 -0
  114. package/dist/jsx/createNativeMenu/index.js +3 -0
  115. package/dist/jsx/createNativeMenu/index.js.map +6 -0
  116. package/dist/jsx/createNativeMenu/index.mjs +3 -0
  117. package/dist/jsx/createNativeMenu/index.mjs.map +1 -0
  118. package/dist/jsx/createNativeMenu/index.native.js +22 -0
  119. package/dist/jsx/createNativeMenu/index.native.js.map +1 -0
  120. package/dist/jsx/createNativeMenu/utils.js +47 -0
  121. package/dist/jsx/createNativeMenu/utils.js.map +6 -0
  122. package/dist/jsx/createNativeMenu/utils.mjs +29 -0
  123. package/dist/jsx/createNativeMenu/utils.mjs.map +1 -0
  124. package/dist/jsx/createNativeMenu/utils.native.js +94 -0
  125. package/dist/jsx/createNativeMenu/utils.native.js.map +1 -0
  126. package/dist/jsx/createNativeMenu/withNativeMenu.js +15 -0
  127. package/dist/jsx/createNativeMenu/withNativeMenu.js.map +6 -0
  128. package/dist/jsx/createNativeMenu/withNativeMenu.mjs +14 -0
  129. package/dist/jsx/createNativeMenu/withNativeMenu.mjs.map +1 -0
  130. package/dist/jsx/createNativeMenu/withNativeMenu.native.js +43 -0
  131. package/dist/jsx/createNativeMenu/withNativeMenu.native.js.map +1 -0
  132. package/dist/jsx/index.js +8 -0
  133. package/dist/jsx/index.js.map +6 -0
  134. package/dist/jsx/index.mjs +6 -0
  135. package/dist/jsx/index.mjs.map +1 -0
  136. package/dist/jsx/index.native.js +33 -0
  137. package/dist/jsx/index.native.js.map +1 -0
  138. package/package.json +80 -0
  139. package/src/MenuPredefined.tsx +195 -0
  140. package/src/createBaseMenu.tsx +1703 -0
  141. package/src/createNativeMenu/createNativeMenu.tsx +372 -0
  142. package/src/createNativeMenu/createNativeMenuTypes.ts +214 -0
  143. package/src/createNativeMenu/index.tsx +7 -0
  144. package/src/createNativeMenu/utils.tsx +150 -0
  145. package/src/createNativeMenu/withNativeMenu.tsx +38 -0
  146. package/src/index.tsx +9 -0
  147. package/types/MenuPredefined.d.ts +28 -0
  148. package/types/MenuPredefined.d.ts.map +1 -0
  149. package/types/createBaseMenu.d.ts +207 -0
  150. package/types/createBaseMenu.d.ts.map +1 -0
  151. package/types/createNativeMenu/createNativeMenu.d.ts +42 -0
  152. package/types/createNativeMenu/createNativeMenu.d.ts.map +1 -0
  153. package/types/createNativeMenu/createNativeMenuTypes.d.ts +188 -0
  154. package/types/createNativeMenu/createNativeMenuTypes.d.ts.map +1 -0
  155. package/types/createNativeMenu/index.d.ts +4 -0
  156. package/types/createNativeMenu/index.d.ts.map +1 -0
  157. package/types/createNativeMenu/utils.d.ts +38 -0
  158. package/types/createNativeMenu/utils.d.ts.map +1 -0
  159. package/types/createNativeMenu/withNativeMenu.d.ts +9 -0
  160. package/types/createNativeMenu/withNativeMenu.d.ts.map +1 -0
  161. package/types/index.d.ts +6 -0
  162. package/types/index.d.ts.map +1 -0
@@ -0,0 +1,893 @@
1
+ import { Animate } from "@tamagui/animate";
2
+ import { AnimatePresence as Presence } from "@tamagui/animate-presence";
3
+ import { createCollection } from "@tamagui/collection";
4
+ import { Dismissable as DismissableLayer, dispatchDiscreteCustomEvent } from "@tamagui/dismissable";
5
+ import { useFocusGuards } from "@tamagui/focus-guard";
6
+ import { FocusScope } from "@tamagui/focus-scope";
7
+ import * as PopperPrimitive from "@tamagui/popper";
8
+ import { Portal as PortalPrimitive } from "@tamagui/portal";
9
+ import { RemoveScroll } from "@tamagui/remove-scroll";
10
+ import { RovingFocusGroup } from "@tamagui/roving-focus";
11
+ import { useCallbackRef } from "@tamagui/use-callback-ref";
12
+ import { useDirection } from "@tamagui/use-direction";
13
+ import { Text, View, composeEventHandlers, composeRefs, createStyledContext, isAndroid, isWeb, useComposedRefs, withStaticProperties } from "@tamagui/web";
14
+ import * as React from "react";
15
+ import { useId } from "react";
16
+ import { MenuPredefined } from "./MenuPredefined.mjs";
17
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
18
+ function whenMouse(handler) {
19
+ return event => event.pointerType === "mouse" ? handler(event) : void 0;
20
+ }
21
+ const SELECTION_KEYS = ["Enter", " "],
22
+ FIRST_KEYS = ["ArrowDown", "PageUp", "Home"],
23
+ LAST_KEYS = ["ArrowUp", "PageDown", "End"],
24
+ FIRST_LAST_KEYS = [...FIRST_KEYS, ...LAST_KEYS],
25
+ SUB_OPEN_KEYS = {
26
+ ltr: [...SELECTION_KEYS, "ArrowRight"],
27
+ rtl: [...SELECTION_KEYS, "ArrowLeft"]
28
+ },
29
+ SUB_CLOSE_KEYS = {
30
+ ltr: ["ArrowLeft"],
31
+ rtl: ["ArrowRight"]
32
+ },
33
+ MENU_NAME = "Menu",
34
+ [Collection, useCollection] = createCollection(MENU_NAME),
35
+ {
36
+ Provider: MenuProvider,
37
+ useStyledContext: useMenuContext
38
+ } = createStyledContext(),
39
+ {
40
+ Provider: MenuRootProvider,
41
+ useStyledContext: useMenuRootContext
42
+ } = createStyledContext(),
43
+ MENU_CONTEXT = "MenuContext";
44
+ function createBaseMenu({
45
+ Item: _Item = MenuPredefined.MenuItem,
46
+ Title: _Title = MenuPredefined.Title,
47
+ SubTitle: _SubTitle = MenuPredefined.SubTitle,
48
+ Image: _Image = MenuPredefined.MenuImage,
49
+ Icon: _Icon = MenuPredefined.MenuIcon,
50
+ Indicator: _Indicator = MenuPredefined.MenuIndicator,
51
+ Separator: _Separator = MenuPredefined.MenuSeparator,
52
+ MenuGroup: _MenuGroup = MenuPredefined.MenuGroup,
53
+ Label: _Label = MenuPredefined.MenuLabel
54
+ }) {
55
+ const MenuComp = props => {
56
+ const {
57
+ scope = MENU_CONTEXT,
58
+ open = !1,
59
+ children,
60
+ dir,
61
+ onOpenChange,
62
+ modal = !0,
63
+ ...rest
64
+ } = props,
65
+ [content, setContent] = React.useState(null),
66
+ isUsingKeyboardRef = React.useRef(!1),
67
+ handleOpenChange = useCallbackRef(onOpenChange),
68
+ direction = useDirection(dir);
69
+ return isWeb && React.useEffect(() => {
70
+ const handleKeyDown = () => {
71
+ isUsingKeyboardRef.current = !0, document.addEventListener("pointerdown", handlePointer, {
72
+ capture: !0,
73
+ once: !0
74
+ }), document.addEventListener("pointermove", handlePointer, {
75
+ capture: !0,
76
+ once: !0
77
+ });
78
+ },
79
+ handlePointer = () => isUsingKeyboardRef.current = !1;
80
+ return document.addEventListener("keydown", handleKeyDown, {
81
+ capture: !0
82
+ }), () => {
83
+ document.removeEventListener("keydown", handleKeyDown, {
84
+ capture: !0
85
+ }), document.removeEventListener("pointerdown", handlePointer, {
86
+ capture: !0
87
+ }), document.removeEventListener("pointermove", handlePointer, {
88
+ capture: !0
89
+ });
90
+ };
91
+ }, []), /* @__PURE__ */jsx(PopperPrimitive.Popper, {
92
+ scope,
93
+ ...rest,
94
+ children: /* @__PURE__ */jsx(MenuProvider, {
95
+ scope,
96
+ open,
97
+ onOpenChange: handleOpenChange,
98
+ content,
99
+ onContentChange: setContent,
100
+ children: /* @__PURE__ */jsx(MenuRootProvider, {
101
+ scope,
102
+ onClose: React.useCallback(() => handleOpenChange(!1), [handleOpenChange]),
103
+ isUsingKeyboardRef,
104
+ dir: direction,
105
+ modal,
106
+ children: /* @__PURE__ */jsx(MenuSubProvider, {
107
+ scope,
108
+ children
109
+ })
110
+ })
111
+ })
112
+ });
113
+ },
114
+ RepropagateMenuAndMenuRootProvider = props => {
115
+ const {
116
+ scope = MENU_CONTEXT,
117
+ menuContext,
118
+ rootContext,
119
+ popperContext,
120
+ menuSubContext,
121
+ children
122
+ } = props;
123
+ return /* @__PURE__ */jsx(PopperPrimitive.PopperProvider, {
124
+ ...popperContext,
125
+ scope,
126
+ children: /* @__PURE__ */jsx(MenuProvider, {
127
+ scope,
128
+ ...menuContext,
129
+ children: /* @__PURE__ */jsx(MenuRootProvider, {
130
+ scope,
131
+ ...rootContext,
132
+ children: menuSubContext ? /* @__PURE__ */jsx(MenuSubProvider, {
133
+ scope,
134
+ ...menuSubContext,
135
+ children
136
+ }) : children
137
+ })
138
+ })
139
+ });
140
+ };
141
+ MenuComp.displayName = MENU_NAME;
142
+ const ANCHOR_NAME = "MenuAnchor",
143
+ MenuAnchor = props => /* @__PURE__ */jsx(PopperPrimitive.PopperAnchor, {
144
+ scope: MENU_CONTEXT,
145
+ ...props
146
+ });
147
+ MenuAnchor.displayName = ANCHOR_NAME;
148
+ const PORTAL_NAME = "MenuPortal",
149
+ {
150
+ Provider: PortalProvider,
151
+ useStyledContext: usePortalContext
152
+ } = createStyledContext(void 0, "Portal"),
153
+ MenuPortal = props => {
154
+ const {
155
+ scope = MENU_CONTEXT,
156
+ forceMount,
157
+ zIndex,
158
+ children
159
+ } = props,
160
+ menuContext = useMenuContext(scope),
161
+ rootContext = useMenuRootContext(scope),
162
+ popperContext = PopperPrimitive.usePopperContext(scope),
163
+ menuSubContext = useMenuSubContext(scope),
164
+ content = isAndroid ? /* @__PURE__ */jsx(RepropagateMenuAndMenuRootProvider, {
165
+ menuContext,
166
+ rootContext,
167
+ popperContext,
168
+ menuSubContext,
169
+ scope,
170
+ children
171
+ }) : children;
172
+ return /* @__PURE__ */jsx(Animate, {
173
+ type: "presence",
174
+ present: forceMount || menuContext.open,
175
+ children: /* @__PURE__ */jsx(PortalPrimitive, {
176
+ children: /* @__PURE__ */jsx(Fragment, {
177
+ children: /* @__PURE__ */jsx(PortalProvider, {
178
+ scope,
179
+ forceMount,
180
+ children: /* @__PURE__ */jsxs(View, {
181
+ zIndex: zIndex || 100,
182
+ inset: 0,
183
+ position: "absolute",
184
+ children: [!!menuContext.open && !isWeb && /* @__PURE__ */jsx(View, {
185
+ inset: 0,
186
+ position: "absolute",
187
+ onPress: () => menuContext.onOpenChange(!menuContext.open)
188
+ }), content]
189
+ })
190
+ })
191
+ })
192
+ })
193
+ });
194
+ };
195
+ MenuPortal.displayName = PORTAL_NAME;
196
+ const CONTENT_NAME = "MenuContent",
197
+ {
198
+ Provider: MenuContentProvider,
199
+ useStyledContext: useMenuContentContext
200
+ } = createStyledContext(),
201
+ MenuContent = React.forwardRef((props, forwardedRef) => {
202
+ const scope = props.scope || MENU_CONTEXT,
203
+ portalContext = usePortalContext(scope),
204
+ {
205
+ forceMount = portalContext.forceMount,
206
+ ...contentProps
207
+ } = props,
208
+ rootContext = useMenuRootContext(scope);
209
+ return /* @__PURE__ */jsx(Collection.Provider, {
210
+ scope,
211
+ children: /* @__PURE__ */jsx(Collection.Slot, {
212
+ scope,
213
+ children: rootContext.modal ? /* @__PURE__ */jsx(MenuRootContentModal, {
214
+ ...contentProps,
215
+ ref: forwardedRef
216
+ }) : /* @__PURE__ */jsx(MenuRootContentNonModal, {
217
+ ...contentProps,
218
+ ref: forwardedRef
219
+ })
220
+ })
221
+ });
222
+ }),
223
+ MenuRootContentModal = React.forwardRef((props, forwardedRef) => {
224
+ const scope = props.scope || MENU_CONTEXT,
225
+ context = useMenuContext(scope),
226
+ ref = React.useRef(null),
227
+ composedRefs = useComposedRefs(forwardedRef, ref);
228
+ return /* @__PURE__ */jsx(MenuContentImpl, {
229
+ ...props,
230
+ scope,
231
+ ref: composedRefs,
232
+ trapFocus: context.open,
233
+ disableOutsidePointerEvents: context.open,
234
+ disableOutsideScroll: !0,
235
+ onFocusOutside: composeEventHandlers(props.onFocusOutside, event => event.preventDefault(), {
236
+ checkDefaultPrevented: !1
237
+ }),
238
+ onDismiss: () => context.onOpenChange(!1)
239
+ });
240
+ }),
241
+ MenuRootContentNonModal = React.forwardRef((props, forwardedRef) => {
242
+ const scope = props.scope || MENU_CONTEXT,
243
+ context = useMenuContext(scope);
244
+ return /* @__PURE__ */jsx(MenuContentImpl, {
245
+ ...props,
246
+ scope,
247
+ ref: forwardedRef,
248
+ trapFocus: !1,
249
+ disableOutsidePointerEvents: !1,
250
+ disableOutsideScroll: !1,
251
+ onDismiss: () => context.onOpenChange(!1)
252
+ });
253
+ }),
254
+ MenuContentImpl = React.forwardRef((props, forwardedRef) => {
255
+ const {
256
+ scope = MENU_CONTEXT,
257
+ loop = !1,
258
+ trapFocus,
259
+ onOpenAutoFocus,
260
+ onCloseAutoFocus,
261
+ disableOutsidePointerEvents,
262
+ onEntryFocus,
263
+ onEscapeKeyDown,
264
+ onPointerDownOutside,
265
+ onFocusOutside,
266
+ onInteractOutside,
267
+ onDismiss,
268
+ disableOutsideScroll,
269
+ unstyled = process.env.TAMAGUI_HEADLESS === "1",
270
+ ...contentProps
271
+ } = props,
272
+ context = useMenuContext(scope),
273
+ rootContext = useMenuRootContext(scope),
274
+ getItems = useCollection(scope),
275
+ [currentItemId, setCurrentItemId] = React.useState(null),
276
+ contentRef = React.useRef(null),
277
+ composedRefs = useComposedRefs(forwardedRef, contentRef, context.onContentChange),
278
+ timerRef = React.useRef(0),
279
+ searchRef = React.useRef(""),
280
+ pointerGraceTimerRef = React.useRef(0),
281
+ pointerGraceIntentRef = React.useRef(null),
282
+ pointerDirRef = React.useRef("right"),
283
+ lastPointerXRef = React.useRef(0),
284
+ handleTypeaheadSearch = key => {
285
+ const search = searchRef.current + key,
286
+ items = getItems().filter(item => !item.disabled),
287
+ currentItem = document.activeElement,
288
+ currentMatch = items.find(item => item.ref.current === currentItem)?.textValue,
289
+ values = items.map(item => item.textValue),
290
+ nextMatch = getNextMatch(values, search, currentMatch),
291
+ newItem = items.find(item => item.textValue === nextMatch)?.ref.current;
292
+ (function updateSearch(value) {
293
+ searchRef.current = value, clearTimeout(timerRef.current), value !== "" && (timerRef.current = setTimeout(() => updateSearch(""), 1e3));
294
+ })(search), newItem && setTimeout(() => newItem.focus());
295
+ };
296
+ React.useEffect(() => () => clearTimeout(timerRef.current), []), isWeb && useFocusGuards();
297
+ const isPointerMovingToSubmenu = React.useCallback(event => pointerDirRef.current === pointerGraceIntentRef.current?.side && isPointerInGraceArea(event, pointerGraceIntentRef.current?.area), []),
298
+ content = /* @__PURE__ */jsx(PopperPrimitive.PopperContent, {
299
+ role: "menu",
300
+ ...(!unstyled && {
301
+ elevation: 30,
302
+ paddingVertical: "$2",
303
+ backgroundColor: "$background",
304
+ borderColor: "$borderColor",
305
+ outlineWidth: 0
306
+ }),
307
+ "aria-orientation": "vertical",
308
+ "data-state": getOpenState(context.open),
309
+ "data-tamagui-menu-content": "",
310
+ dir: rootContext.dir,
311
+ scope: scope || MENU_CONTEXT,
312
+ ...contentProps,
313
+ ref: composedRefs,
314
+ className: contentProps.animation ? void 0 : contentProps.className,
315
+ ...(isWeb ? {
316
+ onKeyDown: composeEventHandlers(contentProps.onKeyDown, event => {
317
+ const isKeyDownInside = event.target.closest("[data-tamagui-menu-content]") === event.currentTarget,
318
+ isModifierKey = event.ctrlKey || event.altKey || event.metaKey,
319
+ isCharacterKey = event.key.length === 1;
320
+ isKeyDownInside && (event.key === "Tab" && event.preventDefault(), !isModifierKey && isCharacterKey && handleTypeaheadSearch(event.key));
321
+ const content2 = contentRef.current;
322
+ if (event.target !== content2 || !FIRST_LAST_KEYS.includes(event.key)) return;
323
+ event.preventDefault();
324
+ const candidateNodes = getItems().filter(item => !item.disabled).map(item => item.ref.current);
325
+ LAST_KEYS.includes(event.key) && candidateNodes.reverse(), focusFirst(candidateNodes);
326
+ }),
327
+ // TODO
328
+ // @ts-ignore
329
+ onBlur: composeEventHandlers(props.onBlur, event => {
330
+ event.currentTarget?.contains(event.target) || (clearTimeout(timerRef.current), searchRef.current = "");
331
+ }),
332
+ // TODO
333
+ onPointerMove: composeEventHandlers(props.onPointerMove, event => {
334
+ if (event.pointerType !== "mouse") return;
335
+ const target = event.target,
336
+ pointerXHasChanged = lastPointerXRef.current !== event.clientX;
337
+ if (event.currentTarget?.contains(target) && pointerXHasChanged) {
338
+ const newDir = event.clientX > lastPointerXRef.current ? "right" : "left";
339
+ pointerDirRef.current = newDir, lastPointerXRef.current = event.clientX;
340
+ }
341
+ })
342
+ } : {})
343
+ });
344
+ return /* @__PURE__ */jsx(MenuContentProvider, {
345
+ scope,
346
+ searchRef,
347
+ onItemEnter: React.useCallback(event => {
348
+ isPointerMovingToSubmenu(event) && event.preventDefault();
349
+ }, [isPointerMovingToSubmenu]),
350
+ onItemLeave: React.useCallback(event => {
351
+ isPointerMovingToSubmenu(event) || (contentRef.current?.focus(), setCurrentItemId(null));
352
+ }, [isPointerMovingToSubmenu]),
353
+ onTriggerLeave: React.useCallback(event => {
354
+ isPointerMovingToSubmenu(event) && event.preventDefault();
355
+ }, [isPointerMovingToSubmenu]),
356
+ pointerGraceTimerRef,
357
+ onPointerGraceIntentChange: React.useCallback(intent => {
358
+ pointerGraceIntentRef.current = intent;
359
+ }, []),
360
+ children: /* @__PURE__ */jsx(RemoveScroll, {
361
+ enabled: disableOutsideScroll,
362
+ children: /* @__PURE__ */jsx(FocusScope, {
363
+ asChild: !1,
364
+ trapped: trapFocus,
365
+ onMountAutoFocus: composeEventHandlers(onOpenAutoFocus, event => {
366
+ event.preventDefault(), contentRef.current?.focus();
367
+ }),
368
+ onUnmountAutoFocus: onCloseAutoFocus,
369
+ children: /* @__PURE__ */jsx(DismissableLayer, {
370
+ disableOutsidePointerEvents,
371
+ onEscapeKeyDown,
372
+ onPointerDownOutside,
373
+ onFocusOutside,
374
+ onInteractOutside,
375
+ onDismiss,
376
+ asChild: !0,
377
+ children: /* @__PURE__ */jsx(RovingFocusGroup, {
378
+ asChild: !0,
379
+ __scopeRovingFocusGroup: scope || MENU_CONTEXT,
380
+ dir: rootContext.dir,
381
+ orientation: "vertical",
382
+ loop,
383
+ currentTabStopId: currentItemId,
384
+ onCurrentTabStopIdChange: setCurrentItemId,
385
+ onEntryFocus: composeEventHandlers(onEntryFocus, event => {
386
+ rootContext.isUsingKeyboardRef.current || event.preventDefault();
387
+ }),
388
+ children: content
389
+ })
390
+ })
391
+ })
392
+ })
393
+ });
394
+ });
395
+ MenuContent.displayName = CONTENT_NAME;
396
+ const ITEM_NAME = "MenuItem",
397
+ ITEM_SELECT = "menu.itemSelect",
398
+ MenuItem = React.forwardRef((props, forwardedRef) => {
399
+ const {
400
+ disabled = !1,
401
+ onSelect,
402
+ children,
403
+ scope = MENU_CONTEXT,
404
+ ...itemProps
405
+ } = props,
406
+ ref = React.useRef(null),
407
+ rootContext = useMenuRootContext(scope),
408
+ contentContext = useMenuContentContext(scope),
409
+ composedRefs = useComposedRefs(forwardedRef, ref),
410
+ isPointerDownRef = React.useRef(!1),
411
+ handleSelect = () => {
412
+ const menuItem = ref.current;
413
+ if (!disabled && menuItem) if (isWeb) {
414
+ const itemSelectEvent = new CustomEvent(ITEM_SELECT, {
415
+ bubbles: !0,
416
+ cancelable: !0
417
+ });
418
+ menuItem.addEventListener(ITEM_SELECT, event => onSelect?.(event), {
419
+ once: !0
420
+ }), dispatchDiscreteCustomEvent(menuItem, itemSelectEvent), itemSelectEvent.defaultPrevented ? isPointerDownRef.current = !1 : rootContext.onClose();
421
+ } else onSelect?.({
422
+ target: menuItem
423
+ }), isPointerDownRef.current = !1, rootContext.onClose();
424
+ },
425
+ content = typeof children == "string" ? /* @__PURE__ */jsx(Text, {
426
+ children
427
+ }) : children;
428
+ return /* @__PURE__ */jsx(MenuItemImpl, {
429
+ outlineStyle: "none",
430
+ ...itemProps,
431
+ scope,
432
+ ref: composedRefs,
433
+ disabled,
434
+ onPress: composeEventHandlers(props.onPress, handleSelect),
435
+ onPointerDown: event => {
436
+ props.onPointerDown?.(event), isPointerDownRef.current = !0;
437
+ },
438
+ onPointerUp: composeEventHandlers(props.onPointerUp, event => {
439
+ isWeb && (isPointerDownRef.current || event.currentTarget?.click());
440
+ }),
441
+ ...(isWeb ? {
442
+ onKeyDown: composeEventHandlers(props.onKeyDown, event => {
443
+ const isTypingAhead = contentContext.searchRef.current !== "";
444
+ disabled || isTypingAhead && event.key === " " || SELECTION_KEYS.includes(event.key) && (event.currentTarget?.click(), event.preventDefault());
445
+ })
446
+ } : {}),
447
+ children: content
448
+ });
449
+ }),
450
+ MenuItemImpl = React.forwardRef((props, forwardedRef) => {
451
+ const {
452
+ scope = MENU_CONTEXT,
453
+ disabled = !1,
454
+ textValue,
455
+ unstyled = process.env.TAMAGUI_HEADLESS === "1",
456
+ ...itemProps
457
+ } = props,
458
+ contentContext = useMenuContentContext(scope),
459
+ ref = React.useRef(null),
460
+ composedRefs = useComposedRefs(forwardedRef, ref),
461
+ [isFocused, setIsFocused] = React.useState(!1),
462
+ [textContent, setTextContent] = React.useState("");
463
+ return isWeb && React.useEffect(() => {
464
+ const menuItem = ref.current;
465
+ menuItem && setTextContent((menuItem.textContent ?? "").trim());
466
+ }, [itemProps.children]), /* @__PURE__ */jsx(Collection.ItemSlot, {
467
+ scope,
468
+ disabled,
469
+ textValue: textValue ?? textContent,
470
+ children: /* @__PURE__ */jsx(RovingFocusGroup.Item, {
471
+ asChild: !0,
472
+ __scopeRovingFocusGroup: scope,
473
+ focusable: !disabled,
474
+ ...(!unstyled && {
475
+ flexDirection: "row",
476
+ alignItems: "center"
477
+ }),
478
+ ...itemProps,
479
+ children: /* @__PURE__ */jsx(_Item, {
480
+ ...(!unstyled && {
481
+ hoverTheme: !0,
482
+ pressTheme: !0,
483
+ focusTheme: !0,
484
+ paddingVertical: "$2",
485
+ paddingHorizontal: "$4",
486
+ width: "100%"
487
+ }),
488
+ componentName: ITEM_NAME,
489
+ role: "menuitem",
490
+ "data-highlighted": isFocused ? "" : void 0,
491
+ "aria-disabled": disabled || void 0,
492
+ "data-disabled": disabled ? "" : void 0,
493
+ ...itemProps,
494
+ ref: composedRefs,
495
+ onPointerMove: composeEventHandlers(props.onPointerMove, event => {
496
+ event.pointerType === "mouse" && (disabled ? contentContext.onItemLeave(event) : (contentContext.onItemEnter(event), event.defaultPrevented || event.currentTarget.focus()));
497
+ }),
498
+ onPointerLeave: composeEventHandlers(props.onPointerLeave, event => {
499
+ contentContext.onItemLeave(event);
500
+ }),
501
+ onFocus: composeEventHandlers(props.onFocus, () => setIsFocused(!0)),
502
+ onBlur: composeEventHandlers(props.onBlur, () => setIsFocused(!1))
503
+ })
504
+ })
505
+ });
506
+ });
507
+ MenuItem.displayName = ITEM_NAME;
508
+ const ITEM_TITLE_NAME = "MenuItemTitle",
509
+ MenuItemTitle = _Title.styleable((props, forwardedRef) => /* @__PURE__ */jsx(_Title, {
510
+ ...props,
511
+ ref: forwardedRef
512
+ }));
513
+ MenuItemTitle.displayName = ITEM_TITLE_NAME;
514
+ const ITEM_SUB_TITLE_NAME = "MenuItemSubTitle",
515
+ MenuItemSubTitle = _SubTitle.styleable((props, forwardedRef) => /* @__PURE__ */jsx(_SubTitle, {
516
+ ...props,
517
+ ref: forwardedRef
518
+ }));
519
+ MenuItemSubTitle.displayName = ITEM_SUB_TITLE_NAME;
520
+ const ITEM_IMAGE = "MenuItemImage",
521
+ MenuItemImage = React.forwardRef((props, forwardedRef) => /* @__PURE__ */jsx(_Image, {
522
+ ...props,
523
+ ref: forwardedRef
524
+ }));
525
+ MenuItemImage.displayName = ITEM_IMAGE;
526
+ const ITEM_ICON = "MenuItemIcon",
527
+ MenuItemIcon = _Icon;
528
+ MenuItemIcon.displayName = ITEM_ICON;
529
+ const CHECKBOX_ITEM_NAME = "MenuCheckboxItem",
530
+ MenuCheckboxItem = React.forwardRef((props, forwardedRef) => {
531
+ const {
532
+ checked = !1,
533
+ onCheckedChange,
534
+ scope = MENU_CONTEXT,
535
+ ...checkboxItemProps
536
+ } = props;
537
+ return /* @__PURE__ */jsx(ItemIndicatorProvider, {
538
+ scope,
539
+ checked,
540
+ children: /* @__PURE__ */jsx(MenuItem, {
541
+ componentName: CHECKBOX_ITEM_NAME,
542
+ role: isWeb ? "menuitemcheckbox" : "menuitem",
543
+ "aria-checked": isIndeterminate(checked) ? "mixed" : checked,
544
+ ...checkboxItemProps,
545
+ scope,
546
+ ref: forwardedRef,
547
+ "data-state": getCheckedState(checked),
548
+ onSelect: composeEventHandlers(checkboxItemProps.onSelect, () => onCheckedChange?.(isIndeterminate(checked) ? !0 : !checked), {
549
+ checkDefaultPrevented: !1
550
+ })
551
+ })
552
+ });
553
+ });
554
+ MenuCheckboxItem.displayName = CHECKBOX_ITEM_NAME;
555
+ const RADIO_GROUP_NAME = "MenuRadioGroup",
556
+ {
557
+ Provider: RadioGroupProvider,
558
+ useStyledContext: useRadioGroupContext
559
+ } = createStyledContext(),
560
+ MenuRadioGroup = _MenuGroup.styleable((props, forwardedRef) => {
561
+ const {
562
+ value,
563
+ onValueChange,
564
+ scope = MENU_CONTEXT,
565
+ ...groupProps
566
+ } = props,
567
+ handleValueChange = useCallbackRef(onValueChange);
568
+ return /* @__PURE__ */jsx(RadioGroupProvider, {
569
+ scope,
570
+ value,
571
+ onValueChange: handleValueChange,
572
+ children: /* @__PURE__ */jsx(_MenuGroup, {
573
+ componentName: RADIO_GROUP_NAME,
574
+ ...groupProps,
575
+ ref: forwardedRef
576
+ })
577
+ });
578
+ });
579
+ MenuRadioGroup.displayName = RADIO_GROUP_NAME;
580
+ const RADIO_ITEM_NAME = "MenuRadioItem",
581
+ MenuRadioItem = React.forwardRef((props, forwardedRef) => {
582
+ const {
583
+ value,
584
+ scope = MENU_CONTEXT,
585
+ ...radioItemProps
586
+ } = props,
587
+ context = useRadioGroupContext(scope),
588
+ checked = value === context.value;
589
+ return /* @__PURE__ */jsx(ItemIndicatorProvider, {
590
+ scope,
591
+ checked,
592
+ children: /* @__PURE__ */jsx(MenuItem, {
593
+ componentName: RADIO_ITEM_NAME,
594
+ ...radioItemProps,
595
+ scope,
596
+ "aria-checked": checked,
597
+ ref: forwardedRef,
598
+ role: isWeb ? "menuitemradio" : "menuitem",
599
+ "data-state": getCheckedState(checked),
600
+ onSelect: composeEventHandlers(radioItemProps.onSelect, () => context.onValueChange?.(value), {
601
+ checkDefaultPrevented: !1
602
+ })
603
+ })
604
+ });
605
+ });
606
+ MenuRadioItem.displayName = RADIO_ITEM_NAME;
607
+ const ITEM_INDICATOR_NAME = "MenuItemIndicator",
608
+ {
609
+ Provider: ItemIndicatorProvider,
610
+ useStyledContext: useItemIndicatorContext
611
+ } = createStyledContext(),
612
+ MenuItemIndicator = _Indicator.styleable((props, forwardedRef) => {
613
+ const {
614
+ scope = MENU_CONTEXT,
615
+ forceMount,
616
+ ...itemIndicatorProps
617
+ } = props,
618
+ indicatorContext = useItemIndicatorContext(scope);
619
+ return /* @__PURE__ */jsx(Presence, {
620
+ children: forceMount || isIndeterminate(indicatorContext.checked) || indicatorContext.checked === !0 ? /* @__PURE__ */jsx(_Indicator, {
621
+ componentName: ITEM_INDICATOR_NAME,
622
+ tag: "span",
623
+ ...itemIndicatorProps,
624
+ ref: forwardedRef,
625
+ "data-state": getCheckedState(indicatorContext.checked)
626
+ }) : null
627
+ });
628
+ });
629
+ MenuItemIndicator.displayName = ITEM_INDICATOR_NAME;
630
+ const MenuArrow = React.forwardRef(function (props, forwardedRef) {
631
+ const {
632
+ scope = MENU_CONTEXT,
633
+ unstyled = process.env.TAMAGUI_HEADLESS === "1",
634
+ ...rest
635
+ } = props;
636
+ return /* @__PURE__ */jsx(PopperPrimitive.PopperArrow, {
637
+ scope,
638
+ componentName: "PopperArrow",
639
+ ...(!unstyled && {
640
+ backgroundColor: "$background"
641
+ }),
642
+ ...rest,
643
+ ref: forwardedRef
644
+ });
645
+ }),
646
+ SUB_NAME = "MenuSub",
647
+ {
648
+ Provider: MenuSubProvider,
649
+ useStyledContext: useMenuSubContext
650
+ } = createStyledContext(),
651
+ MenuSub = props => {
652
+ const {
653
+ scope = MENU_CONTEXT,
654
+ children,
655
+ open = !1,
656
+ onOpenChange,
657
+ ...rest
658
+ } = props,
659
+ parentMenuContext = useMenuContext(scope),
660
+ [trigger, setTrigger] = React.useState(null),
661
+ [content, setContent] = React.useState(null),
662
+ handleOpenChange = useCallbackRef(onOpenChange);
663
+ return React.useEffect(() => (parentMenuContext.open === !1 && handleOpenChange(!1), () => handleOpenChange(!1)), [parentMenuContext.open, handleOpenChange]), /* @__PURE__ */jsx(PopperPrimitive.Popper, {
664
+ ...rest,
665
+ scope,
666
+ children: /* @__PURE__ */jsx(MenuProvider, {
667
+ scope,
668
+ open,
669
+ onOpenChange: handleOpenChange,
670
+ content,
671
+ onContentChange: setContent,
672
+ children: /* @__PURE__ */jsx(MenuSubProvider, {
673
+ scope,
674
+ contentId: useId(),
675
+ triggerId: useId(),
676
+ trigger,
677
+ onTriggerChange: setTrigger,
678
+ children
679
+ })
680
+ })
681
+ });
682
+ };
683
+ MenuSub.displayName = SUB_NAME;
684
+ const SUB_TRIGGER_NAME = "MenuSubTrigger",
685
+ MenuSubTrigger = React.forwardRef((props, forwardedRef) => {
686
+ const scope = props.scope || MENU_CONTEXT,
687
+ context = useMenuContext(scope),
688
+ rootContext = useMenuRootContext(scope),
689
+ subContext = useMenuSubContext(scope),
690
+ contentContext = useMenuContentContext(scope),
691
+ openTimerRef = React.useRef(null),
692
+ {
693
+ pointerGraceTimerRef,
694
+ onPointerGraceIntentChange
695
+ } = contentContext,
696
+ clearOpenTimer = React.useCallback(() => {
697
+ openTimerRef.current && window.clearTimeout(openTimerRef.current), openTimerRef.current = null;
698
+ }, []);
699
+ return React.useEffect(() => clearOpenTimer, [clearOpenTimer]), React.useEffect(() => {
700
+ const pointerGraceTimer = pointerGraceTimerRef.current;
701
+ return () => {
702
+ window.clearTimeout(pointerGraceTimer), onPointerGraceIntentChange(null);
703
+ };
704
+ }, [pointerGraceTimerRef, onPointerGraceIntentChange]), /* @__PURE__ */jsx(MenuAnchor, {
705
+ componentName: SUB_TRIGGER_NAME,
706
+ asChild: !0,
707
+ scope,
708
+ children: /* @__PURE__ */jsx(MenuItemImpl, {
709
+ id: subContext.triggerId,
710
+ "aria-haspopup": "menu",
711
+ "aria-expanded": context.open,
712
+ "aria-controls": subContext.contentId,
713
+ "data-state": getOpenState(context.open),
714
+ outlineStyle: "none",
715
+ ...props,
716
+ ref: composeRefs(forwardedRef, subContext.onTriggerChange),
717
+ onPress: event => {
718
+ props.onPress?.(event), !(props.disabled || event.defaultPrevented) && (isWeb && event.currentTarget.focus(), context.open || context.onOpenChange(!0));
719
+ },
720
+ onPointerMove: composeEventHandlers(props.onPointerMove,
721
+ // @ts-ignore
722
+ whenMouse(event => {
723
+ contentContext.onItemEnter(event), !event.defaultPrevented && !props.disabled && !context.open && !openTimerRef.current && (contentContext.onPointerGraceIntentChange(null), openTimerRef.current = window.setTimeout(() => {
724
+ context.onOpenChange(!0), clearOpenTimer();
725
+ }, 100));
726
+ })),
727
+ onPointerLeave: composeEventHandlers(props.onPointerLeave, eventIn => {
728
+ const event = eventIn;
729
+ clearOpenTimer();
730
+ const contentRect = context.content?.getBoundingClientRect();
731
+ if (contentRect) {
732
+ const side = context.content?.dataset.side,
733
+ rightSide = side === "right",
734
+ bleed = rightSide ? -5 : 5,
735
+ contentNearEdge = contentRect[rightSide ? "left" : "right"],
736
+ contentFarEdge = contentRect[rightSide ? "right" : "left"];
737
+ contentContext.onPointerGraceIntentChange({
738
+ area: [
739
+ // Apply a bleed on clientX to ensure that our exit point is
740
+ // consistently within polygon bounds
741
+ {
742
+ x: event.clientX + bleed,
743
+ y: event.clientY
744
+ }, {
745
+ x: contentNearEdge,
746
+ y: contentRect.top
747
+ }, {
748
+ x: contentFarEdge,
749
+ y: contentRect.top
750
+ }, {
751
+ x: contentFarEdge,
752
+ y: contentRect.bottom
753
+ }, {
754
+ x: contentNearEdge,
755
+ y: contentRect.bottom
756
+ }],
757
+ side
758
+ }), window.clearTimeout(pointerGraceTimerRef.current), pointerGraceTimerRef.current = window.setTimeout(() => contentContext.onPointerGraceIntentChange(null), 300);
759
+ } else {
760
+ if (contentContext.onTriggerLeave(event), event.defaultPrevented) return;
761
+ contentContext.onPointerGraceIntentChange(null);
762
+ }
763
+ }),
764
+ ...(isWeb ? {
765
+ onKeyDown: composeEventHandlers(props.onKeyDown, event => {
766
+ const isTypingAhead = contentContext.searchRef.current !== "";
767
+ props.disabled || isTypingAhead && event.key === " " || SUB_OPEN_KEYS[rootContext.dir].includes(event.key) && (context.onOpenChange(!0), context.content?.focus(), event.preventDefault());
768
+ })
769
+ } : null)
770
+ })
771
+ });
772
+ });
773
+ MenuSubTrigger.displayName = SUB_TRIGGER_NAME;
774
+ const SUB_CONTENT_NAME = "MenuSubContent",
775
+ MenuSubContent = React.forwardRef((props, forwardedRef) => {
776
+ const scope = props.scope || MENU_CONTEXT,
777
+ portalContext = usePortalContext(scope),
778
+ {
779
+ forceMount = portalContext.forceMount,
780
+ ...subContentProps
781
+ } = props,
782
+ context = useMenuContext(scope),
783
+ rootContext = useMenuRootContext(scope),
784
+ subContext = useMenuSubContext(scope),
785
+ ref = React.useRef(null),
786
+ composedRefs = useComposedRefs(forwardedRef, ref);
787
+ return /* @__PURE__ */jsx(Collection.Provider, {
788
+ scope,
789
+ children: /* @__PURE__ */jsx(Collection.Slot, {
790
+ scope,
791
+ children: /* @__PURE__ */jsx(MenuContentImpl, {
792
+ id: subContext.contentId,
793
+ "aria-labelledby": subContext.triggerId,
794
+ ...subContentProps,
795
+ ref: composedRefs,
796
+ "data-side": rootContext.dir === "rtl" ? "left" : "right",
797
+ disableOutsidePointerEvents: !1,
798
+ disableOutsideScroll: !1,
799
+ trapFocus: !1,
800
+ onOpenAutoFocus: event => {
801
+ rootContext.isUsingKeyboardRef.current && ref.current?.focus(), event.preventDefault();
802
+ },
803
+ onCloseAutoFocus: event => event.preventDefault(),
804
+ onFocusOutside: composeEventHandlers(props.onFocusOutside, event => {
805
+ event.target !== subContext.trigger && context.onOpenChange(!1);
806
+ }),
807
+ onEscapeKeyDown: composeEventHandlers(props.onEscapeKeyDown, event => {
808
+ rootContext.onClose(), event.preventDefault();
809
+ }),
810
+ ...(isWeb ? {
811
+ onKeyDown: composeEventHandlers(props.onKeyDown, event => {
812
+ const isKeyDownInside = event.currentTarget.contains(event.target),
813
+ isCloseKey = SUB_CLOSE_KEYS[rootContext.dir].includes(event.key);
814
+ isKeyDownInside && isCloseKey && (context.onOpenChange(!1), subContext.trigger?.focus(), event.preventDefault());
815
+ })
816
+ } : null)
817
+ })
818
+ })
819
+ });
820
+ });
821
+ return MenuSubContent.displayName = SUB_CONTENT_NAME, {
822
+ Menu: withStaticProperties(MenuComp, {
823
+ Anchor: MenuAnchor,
824
+ Portal: MenuPortal,
825
+ Content: MenuContent,
826
+ Group: _MenuGroup,
827
+ Label: _Label,
828
+ Item: MenuItem,
829
+ CheckboxItem: MenuCheckboxItem,
830
+ RadioGroup: MenuRadioGroup,
831
+ RadioItem: MenuRadioItem,
832
+ ItemIndicator: MenuItemIndicator,
833
+ Separator: _Separator,
834
+ Arrow: MenuArrow,
835
+ Sub: MenuSub,
836
+ SubTrigger: MenuSubTrigger,
837
+ SubContent: MenuSubContent,
838
+ ItemTitle: MenuItemTitle,
839
+ ItemSubtitle: MenuItemSubTitle,
840
+ ItemImage: MenuItemImage,
841
+ ItemIcon: MenuItemIcon
842
+ })
843
+ };
844
+ }
845
+ function getOpenState(open) {
846
+ return open ? "open" : "closed";
847
+ }
848
+ function isIndeterminate(checked) {
849
+ return checked === "indeterminate";
850
+ }
851
+ function getCheckedState(checked) {
852
+ return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
853
+ }
854
+ function focusFirst(candidates) {
855
+ const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
856
+ for (const candidate of candidates) if (candidate === PREVIOUSLY_FOCUSED_ELEMENT || (candidate.focus(), document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT)) return;
857
+ }
858
+ function wrapArray(array, startIndex) {
859
+ return array.map((_, index) => array[(startIndex + index) % array.length]);
860
+ }
861
+ function getNextMatch(values, search, currentMatch) {
862
+ const normalizedSearch = search.length > 1 && Array.from(search).every(char => char === search[0]) ? search[0] : search,
863
+ currentMatchIndex = currentMatch ? values.indexOf(currentMatch) : -1;
864
+ let wrappedValues = wrapArray(values, Math.max(currentMatchIndex, 0));
865
+ normalizedSearch.length === 1 && (wrappedValues = wrappedValues.filter(v => v !== currentMatch));
866
+ const nextMatch = wrappedValues.find(value => value.toLowerCase().startsWith(normalizedSearch.toLowerCase()));
867
+ return nextMatch !== currentMatch ? nextMatch : void 0;
868
+ }
869
+ function isPointInPolygon(point, polygon) {
870
+ const {
871
+ x,
872
+ y
873
+ } = point;
874
+ let inside = !1;
875
+ for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
876
+ const xi = polygon[i].x,
877
+ yi = polygon[i].y,
878
+ xj = polygon[j].x,
879
+ yj = polygon[j].y;
880
+ yi > y != yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi && (inside = !inside);
881
+ }
882
+ return inside;
883
+ }
884
+ function isPointerInGraceArea(event, area) {
885
+ if (!area) return !1;
886
+ const cursorPos = {
887
+ x: event.clientX,
888
+ y: event.clientY
889
+ };
890
+ return isPointInPolygon(cursorPos, area);
891
+ }
892
+ export { createBaseMenu };
893
+ //# sourceMappingURL=createBaseMenu.mjs.map