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