@tamagui/create-menu 2.7.7 → 3.0.0-beta.643.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 (113) hide show
  1. package/dist/cjs/createBaseMenu.cjs +1033 -1247
  2. package/dist/cjs/createBaseMenu.native.cjs +1217 -0
  3. package/dist/cjs/createBaseMenu.native.js +1155 -1387
  4. package/dist/cjs/createBaseMenu.native.js.map +1 -1
  5. package/dist/cjs/createNativeMenu/createNativeMenu.cjs +346 -377
  6. package/dist/cjs/createNativeMenu/createNativeMenu.native.cjs +439 -0
  7. package/dist/cjs/createNativeMenu/createNativeMenu.native.js +405 -439
  8. package/dist/cjs/createNativeMenu/createNativeMenu.native.js.map +1 -1
  9. package/dist/cjs/createNativeMenu/createNativeMenuTypes.cjs +10 -11
  10. package/dist/cjs/createNativeMenu/createNativeMenuTypes.native.cjs +19 -0
  11. package/dist/cjs/createNativeMenu/createNativeMenuTypes.native.js +10 -10
  12. package/dist/cjs/createNativeMenu/createNativeMenuTypes.native.js.map +1 -1
  13. package/dist/cjs/createNativeMenu/utils.cjs +76 -86
  14. package/dist/cjs/createNativeMenu/utils.native.cjs +107 -0
  15. package/dist/cjs/createNativeMenu/utils.native.js +82 -92
  16. package/dist/cjs/createNativeMenu/utils.native.js.map +1 -1
  17. package/dist/cjs/createNativeMenu/withNativeMenu.cjs +27 -35
  18. package/dist/cjs/createNativeMenu/withNativeMenu.native.cjs +42 -0
  19. package/dist/cjs/createNativeMenu/withNativeMenu.native.js +27 -34
  20. package/dist/cjs/createNativeMenu/withNativeMenu.native.js.map +1 -1
  21. package/dist/cjs/index.cjs +9 -20
  22. package/dist/cjs/index.native.cjs +23 -0
  23. package/dist/cjs/index.native.js +10 -20
  24. package/dist/cjs/index.native.js.map +1 -1
  25. package/dist/esm/createBaseMenu.mjs +1021 -1225
  26. package/dist/esm/createBaseMenu.mjs.map +1 -1
  27. package/dist/esm/createBaseMenu.native.js +1144 -1367
  28. package/dist/esm/createBaseMenu.native.js.map +1 -1
  29. package/dist/esm/createNativeMenu/createNativeMenu.mjs +332 -353
  30. package/dist/esm/createNativeMenu/createNativeMenu.mjs.map +1 -1
  31. package/dist/esm/createNativeMenu/createNativeMenu.native.js +392 -417
  32. package/dist/esm/createNativeMenu/createNativeMenu.native.js.map +1 -1
  33. package/dist/esm/createNativeMenu/createNativeMenuTypes.mjs +0 -2
  34. package/dist/esm/createNativeMenu/createNativeMenuTypes.native.js +0 -2
  35. package/dist/esm/createNativeMenu/utils.mjs +55 -57
  36. package/dist/esm/createNativeMenu/utils.mjs.map +1 -1
  37. package/dist/esm/createNativeMenu/utils.native.js +62 -65
  38. package/dist/esm/createNativeMenu/utils.native.js.map +1 -1
  39. package/dist/esm/createNativeMenu/withNativeMenu.mjs +14 -17
  40. package/dist/esm/createNativeMenu/withNativeMenu.mjs.map +1 -1
  41. package/dist/esm/createNativeMenu/withNativeMenu.native.js +15 -18
  42. package/dist/esm/createNativeMenu/withNativeMenu.native.js.map +1 -1
  43. package/dist/esm/index.js +5 -6
  44. package/dist/esm/index.mjs +5 -6
  45. package/dist/esm/index.native.js +5 -6
  46. package/dist/jsx/createBaseMenu.mjs +1021 -1225
  47. package/dist/jsx/createBaseMenu.mjs.map +1 -1
  48. package/dist/jsx/createBaseMenu.native.cjs +1217 -0
  49. package/dist/jsx/createBaseMenu.native.js +1155 -1387
  50. package/dist/jsx/createBaseMenu.native.js.map +1 -1
  51. package/dist/jsx/createNativeMenu/createNativeMenu.mjs +332 -353
  52. package/dist/jsx/createNativeMenu/createNativeMenu.mjs.map +1 -1
  53. package/dist/jsx/createNativeMenu/createNativeMenu.native.cjs +439 -0
  54. package/dist/jsx/createNativeMenu/createNativeMenu.native.js +405 -439
  55. package/dist/jsx/createNativeMenu/createNativeMenu.native.js.map +1 -1
  56. package/dist/jsx/createNativeMenu/createNativeMenuTypes.mjs +0 -2
  57. package/dist/jsx/createNativeMenu/createNativeMenuTypes.native.cjs +19 -0
  58. package/dist/jsx/createNativeMenu/createNativeMenuTypes.native.js +10 -10
  59. package/dist/jsx/createNativeMenu/createNativeMenuTypes.native.js.map +1 -1
  60. package/dist/jsx/createNativeMenu/utils.mjs +55 -57
  61. package/dist/jsx/createNativeMenu/utils.mjs.map +1 -1
  62. package/dist/jsx/createNativeMenu/utils.native.cjs +107 -0
  63. package/dist/jsx/createNativeMenu/utils.native.js +82 -92
  64. package/dist/jsx/createNativeMenu/utils.native.js.map +1 -1
  65. package/dist/jsx/createNativeMenu/withNativeMenu.mjs +14 -17
  66. package/dist/jsx/createNativeMenu/withNativeMenu.mjs.map +1 -1
  67. package/dist/jsx/createNativeMenu/withNativeMenu.native.cjs +42 -0
  68. package/dist/jsx/createNativeMenu/withNativeMenu.native.js +27 -34
  69. package/dist/jsx/createNativeMenu/withNativeMenu.native.js.map +1 -1
  70. package/dist/jsx/index.js +5 -6
  71. package/dist/jsx/index.mjs +5 -6
  72. package/dist/jsx/index.native.cjs +23 -0
  73. package/dist/jsx/index.native.js +10 -20
  74. package/dist/jsx/index.native.js.map +1 -1
  75. package/package.json +23 -22
  76. package/src/createBaseMenu.tsx +211 -231
  77. package/src/createNativeMenu/createNativeMenuTypes.ts +0 -6
  78. package/src/createNativeMenu/utils.tsx +6 -6
  79. package/src/createNativeMenu/withNativeMenu.tsx +1 -2
  80. package/src/index.tsx +0 -1
  81. package/types/createBaseMenu.d.ts +38 -126
  82. package/types/createBaseMenu.d.ts.map +1 -1
  83. package/types/createNativeMenu/createNativeMenu.d.ts +1 -1
  84. package/types/createNativeMenu/createNativeMenu.d.ts.map +1 -1
  85. package/types/createNativeMenu/createNativeMenuTypes.d.ts +0 -6
  86. package/types/createNativeMenu/createNativeMenuTypes.d.ts.map +1 -1
  87. package/types/createNativeMenu/utils.d.ts +5 -5
  88. package/types/createNativeMenu/utils.d.ts.map +1 -1
  89. package/types/createNativeMenu/withNativeMenu.d.ts.map +1 -1
  90. package/types/index.d.ts +0 -1
  91. package/types/index.d.ts.map +1 -1
  92. package/dist/cjs/MenuPredefined.cjs +0 -191
  93. package/dist/cjs/MenuPredefined.native.js +0 -194
  94. package/dist/cjs/MenuPredefined.native.js.map +0 -1
  95. package/dist/esm/MenuPredefined.mjs +0 -166
  96. package/dist/esm/MenuPredefined.mjs.map +0 -1
  97. package/dist/esm/MenuPredefined.native.js +0 -166
  98. package/dist/esm/MenuPredefined.native.js.map +0 -1
  99. package/dist/esm/createNativeMenu/createNativeMenuTypes.mjs.map +0 -1
  100. package/dist/esm/createNativeMenu/createNativeMenuTypes.native.js.map +0 -1
  101. package/dist/esm/index.js.map +0 -1
  102. package/dist/esm/index.mjs.map +0 -1
  103. package/dist/esm/index.native.js.map +0 -1
  104. package/dist/jsx/MenuPredefined.mjs +0 -166
  105. package/dist/jsx/MenuPredefined.mjs.map +0 -1
  106. package/dist/jsx/MenuPredefined.native.js +0 -194
  107. package/dist/jsx/MenuPredefined.native.js.map +0 -1
  108. package/dist/jsx/createNativeMenu/createNativeMenuTypes.mjs.map +0 -1
  109. package/dist/jsx/index.js.map +0 -1
  110. package/dist/jsx/index.mjs.map +0 -1
  111. package/src/MenuPredefined.tsx +0 -204
  112. package/types/MenuPredefined.d.ts +0 -31
  113. package/types/MenuPredefined.d.ts.map +0 -1
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
5
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7,44 +8,37 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
8
  var __getProtoOf = Object.getPrototypeOf;
8
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
10
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
14
15
  };
15
16
  var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
- get: () => from[key],
19
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
- });
21
- }
22
- return to;
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: () => from[key],
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
23
24
  };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
30
- value: mod,
31
- enumerable: true
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
32
28
  }) : target, mod));
33
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
- value: true
35
- }), mod);
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
30
  var createBaseMenu_exports = {};
37
- __export(createBaseMenu_exports, {
38
- createBaseMenu: () => createBaseMenu
39
- });
31
+ __export(createBaseMenu_exports, { createBaseMenu: () => createBaseMenu });
40
32
  module.exports = __toCommonJS(createBaseMenu_exports);
41
33
  var import_jsx_runtime = require("react/jsx-runtime");
34
+ var import_core = require("@tamagui/core");
42
35
  var import_animate = require("@tamagui/animate");
43
36
  var import_animate_presence = require("@tamagui/animate-presence");
44
37
  var import_collection = require("@tamagui/collection");
45
38
  var import_dismissable = require("@tamagui/dismissable");
46
39
  var import_focus_guard = require("@tamagui/focus-guard");
47
40
  var import_focus_scope = require("@tamagui/focus-scope");
41
+ var import_image = require("@tamagui/image");
48
42
  var PopperPrimitive = __toESM(require("@tamagui/popper"), 1);
49
43
  var import_portal = require("@tamagui/portal");
50
44
  var import_remove_scroll = require("@tamagui/remove-scroll");
@@ -54,1398 +48,1172 @@ var import_use_direction = require("@tamagui/use-direction");
54
48
  var import_web = require("@tamagui/web");
55
49
  var React = __toESM(require("react"), 1);
56
50
  var import_react = require("react");
57
- var import_MenuPredefined = require("./MenuPredefined.native.js");
58
51
  function _instanceof(left, right) {
59
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
60
- return !!right[Symbol.hasInstance](left);
61
- } else {
62
- return left instanceof right;
63
- }
52
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
53
+ return !!right[Symbol.hasInstance](left);
54
+ } else {
55
+ return left instanceof right;
56
+ }
64
57
  }
65
58
  function _type_of(obj) {
66
- "@swc/helpers - typeof";
67
-
68
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
59
+ "@swc/helpers - typeof";
60
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
69
61
  }
70
62
  function whenMouse(handler) {
71
- return function (event) {
72
- return event.pointerType === "mouse" ? handler(event) : void 0;
73
- };
63
+ return function(event) {
64
+ return event.pointerType === "mouse" ? handler(event) : void 0;
65
+ };
74
66
  }
75
67
  var SELECTION_KEYS = ["Enter", " "];
76
- var FIRST_KEYS = ["ArrowDown", "PageUp", "Home"];
77
- var LAST_KEYS = ["ArrowUp", "PageDown", "End"];
68
+ var FIRST_KEYS = [
69
+ "ArrowDown",
70
+ "PageUp",
71
+ "Home"
72
+ ];
73
+ var LAST_KEYS = [
74
+ "ArrowUp",
75
+ "PageDown",
76
+ "End"
77
+ ];
78
78
  var FIRST_LAST_KEYS = [...FIRST_KEYS, ...LAST_KEYS];
79
79
  var SUB_OPEN_KEYS = {
80
- ltr: [...SELECTION_KEYS, "ArrowRight"],
81
- rtl: [...SELECTION_KEYS, "ArrowLeft"]
80
+ ltr: [...SELECTION_KEYS, "ArrowRight"],
81
+ rtl: [...SELECTION_KEYS, "ArrowLeft"]
82
82
  };
83
83
  var SUB_CLOSE_KEYS = {
84
- ltr: ["ArrowLeft"],
85
- rtl: ["ArrowRight"]
84
+ ltr: ["ArrowLeft"],
85
+ rtl: ["ArrowRight"]
86
86
  };
87
87
  var MENU_NAME = "Menu";
88
88
  var [Collection, useCollection] = (0, import_collection.createCollection)(MENU_NAME);
89
- var {
90
- Provider: MenuProvider,
91
- useStyledContext: useMenuContext
92
- } = (0, import_web.createStyledContext)();
93
- var {
94
- Provider: MenuRootProvider,
95
- useStyledContext: useMenuRootContext
96
- } = (0, import_web.createStyledContext)();
89
+ var { Provider: MenuProvider, useStyledContext: useMenuContext } = (0, import_web.createStyledContext)();
90
+ var { Provider: MenuRootProvider, useStyledContext: useMenuRootContext } = (0, import_web.createStyledContext)();
97
91
  var MENU_CONTEXT = "MenuContext";
98
- function createBaseMenu(param) {
99
- var {
100
- Item: _Item = import_MenuPredefined.MenuPredefined.MenuItem,
101
- Title: _Title = import_MenuPredefined.MenuPredefined.Title,
102
- SubTitle: _SubTitle = import_MenuPredefined.MenuPredefined.SubTitle,
103
- Image: _Image = import_MenuPredefined.MenuPredefined.MenuImage,
104
- Icon: _Icon = import_MenuPredefined.MenuPredefined.MenuIcon,
105
- Indicator: _Indicator = import_MenuPredefined.MenuPredefined.MenuIndicator,
106
- Separator: _Separator = import_MenuPredefined.MenuPredefined.MenuSeparator,
107
- MenuGroup: _MenuGroup = import_MenuPredefined.MenuPredefined.MenuGroup,
108
- Label: _Label = import_MenuPredefined.MenuPredefined.MenuLabel
109
- } = param;
110
- var MenuComp = function (props) {
111
- var direction = (0, import_use_direction.useDirection)(props.dir);
112
- var defaultPlacement = direction === "rtl" ? "bottom-end" : "bottom-start";
113
- var {
114
- scope = MENU_CONTEXT,
115
- open = false,
116
- children,
117
- dir,
118
- onOpenChange,
119
- modal = true,
120
- allowFlip = {
121
- padding: 10
122
- },
123
- stayInFrame = {
124
- padding: 10
125
- },
126
- placement = defaultPlacement,
127
- resize = true,
128
- offset = 10,
129
- ...rest
130
- } = props;
131
- var [content, setContent] = React.useState(null);
132
- var isUsingKeyboardRef = React.useRef(false);
133
- var handleOpenChange = (0, import_use_callback_ref.useCallbackRef)(onOpenChange);
134
- if (import_web.isWeb) {
135
- React.useEffect(function () {
136
- var handleKeyDown = function () {
137
- isUsingKeyboardRef.current = true;
138
- document.addEventListener("pointerdown", handlePointer, {
139
- capture: true,
140
- once: true
141
- });
142
- document.addEventListener("pointermove", handlePointer, {
143
- capture: true,
144
- once: true
145
- });
146
- };
147
- var handlePointer = function () {
148
- return isUsingKeyboardRef.current = false;
149
- };
150
- document.addEventListener("keydown", handleKeyDown, {
151
- capture: true
152
- });
153
- return function () {
154
- document.removeEventListener("keydown", handleKeyDown, {
155
- capture: true
156
- });
157
- document.removeEventListener("pointerdown", handlePointer, {
158
- capture: true
159
- });
160
- document.removeEventListener("pointermove", handlePointer, {
161
- capture: true
162
- });
163
- };
164
- }, []);
165
- }
166
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.Popper, {
167
- scope,
168
- open,
169
- placement,
170
- allowFlip,
171
- stayInFrame,
172
- resize,
173
- offset,
174
- ...rest,
175
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuProvider, {
176
- scope,
177
- open,
178
- onOpenChange: handleOpenChange,
179
- content,
180
- onContentChange: setContent,
181
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuRootProvider, {
182
- scope,
183
- open,
184
- onClose: React.useCallback(function () {
185
- return handleOpenChange(false);
186
- }, [handleOpenChange]),
187
- isUsingKeyboardRef,
188
- dir: direction,
189
- modal,
190
- children: (/** this provider is just to avoid crashing when using useSubMenuContext() inside MenuPortal */
191
- /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuSubProvider, {
192
- scope,
193
- children
194
- }))
195
- })
196
- })
197
- });
198
- };
199
- var RepropagateMenuAndMenuRootProvider = function (props) {
200
- var {
201
- scope = MENU_CONTEXT,
202
- menuContext,
203
- rootContext,
204
- popperContext,
205
- menuSubContext,
206
- children
207
- } = props;
208
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.PopperProvider, {
209
- ...popperContext,
210
- scope,
211
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuProvider, {
212
- scope,
213
- ...menuContext,
214
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuRootProvider, {
215
- scope,
216
- ...rootContext,
217
- children: menuSubContext ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuSubProvider, {
218
- scope,
219
- ...menuSubContext,
220
- children
221
- }) : children
222
- })
223
- })
224
- });
225
- };
226
- MenuComp.displayName = MENU_NAME;
227
- var ANCHOR_NAME = "MenuAnchor";
228
- var MenuAnchor = function (props) {
229
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.PopperAnchor, {
230
- scope: MENU_CONTEXT,
231
- ...props
232
- });
233
- };
234
- MenuAnchor.displayName = ANCHOR_NAME;
235
- var PORTAL_NAME = "MenuPortal";
236
- var {
237
- Provider: PortalProvider,
238
- useStyledContext: usePortalContext
239
- } = (0, import_web.createStyledContext)(void 0, "Portal");
240
- var MenuPortal = function (props) {
241
- var {
242
- scope = MENU_CONTEXT,
243
- forceMount,
244
- zIndex,
245
- children
246
- } = props;
247
- var menuContext = useMenuContext(scope);
248
- var rootContext = useMenuRootContext(scope);
249
- var popperContext = PopperPrimitive.usePopperContext(scope);
250
- var menuSubContext = useMenuSubContext(scope);
251
- var themeName = (0, import_web.useThemeName)();
252
- var themedChildren = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_web.Theme, {
253
- forceClassName: true,
254
- name: themeName,
255
- children
256
- });
257
- var content = (0, import_portal.needsPortalRepropagation)() ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(RepropagateMenuAndMenuRootProvider, {
258
- menuContext,
259
- rootContext,
260
- popperContext,
261
- menuSubContext,
262
- scope,
263
- children: themedChildren
264
- }) : themedChildren;
265
- var isPresent = forceMount || rootContext.open && menuContext.open;
266
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_animate.Animate, {
267
- type: "presence",
268
- present: isPresent,
269
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.Portal, {
270
- stackZIndex: true,
271
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
272
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PortalProvider, {
273
- scope,
274
- forceMount,
275
- children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_web.View, {
276
- zIndex: zIndex || 100,
277
- inset: 0,
278
- position: "absolute",
279
- children: [!!menuContext.open && !import_web.isWeb && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_web.View, {
280
- inset: 0,
281
- position: "absolute",
282
- onPress: function () {
283
- return menuContext.onOpenChange(!menuContext.open);
284
- }
285
- }), content]
286
- })
287
- })
288
- })
289
- })
290
- });
291
- };
292
- MenuPortal.displayName = PORTAL_NAME;
293
- var CONTENT_NAME = "MenuContent";
294
- var {
295
- Provider: MenuContentProvider,
296
- useStyledContext: useMenuContentContext
297
- } = (0, import_web.createStyledContext)();
298
- var MenuContentFrame = (0, import_web.styled)(PopperPrimitive.PopperContentFrame, {
299
- name: CONTENT_NAME
300
- });
301
- var MenuContent = MenuContentFrame.styleable(function (props, forwardedRef) {
302
- var scope = props.scope || MENU_CONTEXT;
303
- var portalContext = usePortalContext(scope);
304
- var {
305
- forceMount = portalContext.forceMount,
306
- ...contentProps
307
- } = props;
308
- var rootContext = useMenuRootContext(scope);
309
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Provider, {
310
- scope,
311
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Slot, {
312
- scope,
313
- children: rootContext.modal ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuRootContentModal, {
314
- ...contentProps,
315
- ref: forwardedRef
316
- }) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuRootContentNonModal, {
317
- ...contentProps,
318
- ref: forwardedRef
319
- })
320
- })
321
- });
322
- });
323
- var MenuRootContentModal = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
324
- var scope = props.scope || MENU_CONTEXT;
325
- var context = useMenuContext(scope);
326
- var ref = React.useRef(null);
327
- var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref);
328
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuContentImpl, {
329
- ...props,
330
- scope,
331
- ref: composedRefs,
332
- // we make sure we're not trapping once it's been closed
333
- // (closed !== unmounted when animating out)
334
- trapFocus: context.open,
335
- // make sure to only disable pointer events when open
336
- // this avoids blocking interactions while animating out
337
- disableOutsidePointerEvents: context.open,
338
- disableOutsideScroll: false,
339
- // When focus is trapped, a `focusout` event may still happen.
340
- // We make sure we don't trigger our `onDismiss` in such case.
341
- onFocusOutside: (0, import_web.composeEventHandlers)(props.onFocusOutside, function (event) {
342
- return event.preventDefault();
343
- }, {
344
- checkDefaultPrevented: false
345
- }),
346
- onDismiss: function () {
347
- return context.onOpenChange(false);
348
- }
349
- });
350
- });
351
- var MenuRootContentNonModal = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
352
- var scope = props.scope || MENU_CONTEXT;
353
- var context = useMenuContext(scope);
354
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuContentImpl, {
355
- ...props,
356
- scope,
357
- ref: forwardedRef,
358
- trapFocus: false,
359
- disableOutsidePointerEvents: false,
360
- disableOutsideScroll: false,
361
- onDismiss: function () {
362
- return context.onOpenChange(false);
363
- }
364
- });
365
- });
366
- var MenuContentImpl = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
367
- var {
368
- scope = MENU_CONTEXT,
369
- loop = false,
370
- trapFocus,
371
- onOpenAutoFocus,
372
- onCloseAutoFocus,
373
- disableOutsidePointerEvents,
374
- onEntryFocus,
375
- onEscapeKeyDown,
376
- onPointerDownOutside,
377
- onFocusOutside,
378
- onInteractOutside,
379
- onDismiss,
380
- disableOutsideScroll,
381
- disableDismissOnScroll = false,
382
- unstyled = process.env.TAMAGUI_HEADLESS === "1",
383
- ...contentProps
384
- } = props;
385
- var context = useMenuContext(scope);
386
- var rootContext = useMenuRootContext(scope);
387
- var popperContext = PopperPrimitive.usePopperContext(scope);
388
- var getItems = useCollection(scope);
389
- var [currentItemId, setCurrentItemId] = React.useState(null);
390
- var contentRef = React.useRef(null);
391
- var focusableContentRef = React.useRef(null);
392
- var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, contentRef, context.onContentChange);
393
- var timerRef = React.useRef(0);
394
- var searchRef = React.useRef("");
395
- var pointerGraceTimerRef = React.useRef(0);
396
- var pointerGraceIntentRef = React.useRef(null);
397
- var pointerDirRef = React.useRef("right");
398
- var lastPointerXRef = React.useRef(0);
399
- var handleTypeaheadSearch = function (key) {
400
- var _items_find, _items_find1;
401
- var search = searchRef.current + key;
402
- var items = getItems().filter(function (item) {
403
- return !item.disabled;
404
- });
405
- var currentItem = document.activeElement;
406
- var currentMatch = (_items_find = items.find(function (item) {
407
- return item.ref.current === currentItem;
408
- })) === null || _items_find === void 0 ? void 0 : _items_find.textValue;
409
- var values = items.map(function (item) {
410
- return item.textValue;
411
- });
412
- var nextMatch = getNextMatch(values, search, currentMatch);
413
- var newItem = (_items_find1 = items.find(function (item) {
414
- return item.textValue === nextMatch;
415
- })) === null || _items_find1 === void 0 ? void 0 : _items_find1.ref.current;
416
- (function updateSearch(value) {
417
- searchRef.current = value;
418
- clearTimeout(timerRef.current);
419
- if (value !== "") timerRef.current = setTimeout(function () {
420
- return updateSearch("");
421
- }, 1e3);
422
- })(search);
423
- if (newItem) {
424
- setTimeout(function () {
425
- return newItem.focus();
426
- });
427
- }
428
- };
429
- React.useEffect(function () {
430
- return function () {
431
- return clearTimeout(timerRef.current);
432
- };
433
- }, []);
434
- React.useEffect(function () {
435
- if (!import_web.isWeb || !context.open) return;
436
- var frame = requestAnimationFrame(function () {
437
- var container = contentRef.current;
438
- var el = container === null || container === void 0 ? void 0 : container.querySelector("[data-tamagui-menu-content]");
439
- if (el) focusableContentRef.current = el;
440
- });
441
- return function () {
442
- return cancelAnimationFrame(frame);
443
- };
444
- }, [context.open]);
445
- React.useEffect(function () {
446
- if (!import_web.isWeb || disableDismissOnScroll || !context.open) return;
447
- var handleScroll = function (event) {
448
- var _popperContext_refs_reference, _popperContext_refs;
449
- var scrolled = event.target;
450
- if (!scrolled) return;
451
- var content2 = contentRef.current;
452
- if (content2 === null || content2 === void 0 ? void 0 : content2.contains(scrolled)) return;
453
- var reference = (_popperContext_refs = popperContext.refs) === null || _popperContext_refs === void 0 ? void 0 : (_popperContext_refs_reference = _popperContext_refs.reference) === null || _popperContext_refs_reference === void 0 ? void 0 : _popperContext_refs_reference.current;
454
- var _reference_contextElement;
455
- var anchor = _instanceof(reference, Element) ? reference : (_reference_contextElement = reference === null || reference === void 0 ? void 0 : reference.contextElement) !== null && _reference_contextElement !== void 0 ? _reference_contextElement : null;
456
- if (anchor && !scrolled.contains(anchor)) return;
457
- onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss();
458
- };
459
- window.addEventListener("scroll", handleScroll, {
460
- capture: true,
461
- passive: true
462
- });
463
- return function () {
464
- window.removeEventListener("scroll", handleScroll, {
465
- capture: true
466
- });
467
- };
468
- }, [disableDismissOnScroll, context.open, onDismiss, popperContext.refs]);
469
- if (import_web.isWeb) {
470
- (0, import_focus_guard.useFocusGuards)();
471
- }
472
- var isPointerMovingToSubmenu = React.useCallback(function (event) {
473
- var _pointerGraceIntentRef_current, _pointerGraceIntentRef_current1;
474
- var isMovingTowards = pointerDirRef.current === ((_pointerGraceIntentRef_current = pointerGraceIntentRef.current) === null || _pointerGraceIntentRef_current === void 0 ? void 0 : _pointerGraceIntentRef_current.side);
475
- var inArea = isPointerInGraceArea(event, (_pointerGraceIntentRef_current1 = pointerGraceIntentRef.current) === null || _pointerGraceIntentRef_current1 === void 0 ? void 0 : _pointerGraceIntentRef_current1.area);
476
- return isMovingTowards && inArea;
477
- }, []);
478
- var content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.PopperContent, {
479
- role: "menu",
480
- // tabIndex allows the content to be focusable so that onItemLeave can
481
- // focus the content frame and properly blur the previously focused item
482
- tabIndex: -1,
483
- unstyled,
484
- ...(!unstyled && {
485
- backgroundColor: "$background",
486
- borderWidth: 1,
487
- borderColor: "$borderColor",
488
- outlineWidth: 0,
489
- minWidth: 180
490
- }),
491
- "aria-orientation": "vertical",
492
- "data-state": getOpenState(context.open),
493
- "data-tamagui-menu-content": "",
494
- // TODO
495
- // @ts-ignore
496
- dir: rootContext.dir,
497
- scope: scope || MENU_CONTEXT,
498
- ...contentProps,
499
- ref: composedRefs,
500
- className: contentProps.transition ? void 0 : contentProps.className,
501
- ...(import_web.isWeb ? {
502
- onKeyDown: (0, import_web.composeEventHandlers)(contentProps.onKeyDown, function (event) {
503
- var target = event.target;
504
- var isKeyDownInside = target.closest("[data-tamagui-menu-content]") === event.currentTarget;
505
- var isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
506
- var isCharacterKey = event.key.length === 1;
507
- if (isKeyDownInside) {
508
- if (event.key === "Tab") event.preventDefault();
509
- if (!isModifierKey && isCharacterKey) handleTypeaheadSearch(event.key);
510
- }
511
- var isOnContentFrame = event.target.hasAttribute("data-tamagui-menu-content");
512
- if (!isKeyDownInside || !isOnContentFrame) return;
513
- if (!FIRST_LAST_KEYS.includes(event.key)) return;
514
- event.preventDefault();
515
- var items = getItems().filter(function (item) {
516
- return !item.disabled;
517
- });
518
- var candidateNodes = items.map(function (item) {
519
- return item.ref.current;
520
- });
521
- if (LAST_KEYS.includes(event.key)) candidateNodes.reverse();
522
- focusFirst(candidateNodes, {
523
- focusVisible: true
524
- });
525
- }),
526
- // TODO
527
- // @ts-ignore
528
- onBlur: (0, import_web.composeEventHandlers)(props.onBlur, function (event) {
529
- var _event_currentTarget;
530
- if (!((_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0 ? void 0 : _event_currentTarget.contains(event.target))) {
531
- clearTimeout(timerRef.current);
532
- searchRef.current = "";
533
- }
534
- }),
535
- // TODO
536
- onPointerMove: (0, import_web.composeEventHandlers)(props.onPointerMove, function (event) {
537
- var _event_currentTarget;
538
- if (event.pointerType !== "mouse") return;
539
- var target = event.target;
540
- var pointerXHasChanged = lastPointerXRef.current !== event.clientX;
541
- if (((_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0 ? void 0 : _event_currentTarget.contains(target)) && pointerXHasChanged) {
542
- var newDir = event.clientX > lastPointerXRef.current ? "right" : "left";
543
- pointerDirRef.current = newDir;
544
- lastPointerXRef.current = event.clientX;
545
- }
546
- })
547
- } : {})
548
- });
549
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuContentProvider, {
550
- scope,
551
- searchRef,
552
- onItemEnter: React.useCallback(function (event) {
553
- if (isPointerMovingToSubmenu(event)) event.preventDefault();
554
- }, [isPointerMovingToSubmenu]),
555
- onItemLeave: React.useCallback(function (event) {
556
- var _focusableContentRef_current;
557
- if (isPointerMovingToSubmenu(event)) return;
558
- (_focusableContentRef_current = focusableContentRef.current) === null || _focusableContentRef_current === void 0 ? void 0 : _focusableContentRef_current.focus();
559
- setCurrentItemId(null);
560
- }, [isPointerMovingToSubmenu]),
561
- onTriggerLeave: React.useCallback(function (event) {
562
- if (isPointerMovingToSubmenu(event)) event.preventDefault();
563
- }, [isPointerMovingToSubmenu]),
564
- pointerGraceTimerRef,
565
- onPointerGraceIntentChange: React.useCallback(function (intent) {
566
- pointerGraceIntentRef.current = intent;
567
- }, []),
568
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_remove_scroll.RemoveScroll, {
569
- enabled: disableOutsideScroll,
570
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_focus_scope.FocusScope, {
571
- asChild: false,
572
- trapped: trapFocus,
573
- onMountAutoFocus: (0, import_web.composeEventHandlers)(onOpenAutoFocus, function (event) {
574
- event.preventDefault();
575
- var content2 = document.querySelector("[data-tamagui-menu-content]");
576
- content2 === null || content2 === void 0 ? void 0 : content2.focus({
577
- preventScroll: true
578
- });
579
- }),
580
- onUnmountAutoFocus: onCloseAutoFocus,
581
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dismissable.Dismissable, {
582
- disableOutsidePointerEvents,
583
- onEscapeKeyDown,
584
- onPointerDownOutside,
585
- onFocusOutside,
586
- onInteractOutside,
587
- onDismiss,
588
- asChild: true,
589
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup, {
590
- asChild: true,
591
- __scopeRovingFocusGroup: scope || MENU_CONTEXT,
592
- dir: rootContext.dir,
593
- orientation: "vertical",
594
- loop,
595
- currentTabStopId: currentItemId,
596
- onCurrentTabStopIdChange: setCurrentItemId,
597
- onEntryFocus: (0, import_web.composeEventHandlers)(onEntryFocus, function (event) {
598
- if (!rootContext.isUsingKeyboardRef.current) {
599
- event.preventDefault();
600
- }
601
- }),
602
- children: content
603
- })
604
- })
605
- })
606
- })
607
- });
608
- });
609
- MenuContent.displayName = CONTENT_NAME;
610
- var ITEM_NAME = "MenuItem";
611
- var ITEM_SELECT = "menu.itemSelect";
612
- var MenuItem = _Item.styleable(function (props, forwardedRef) {
613
- var {
614
- disabled = false,
615
- onSelect,
616
- preventCloseOnSelect,
617
- children,
618
- scope = MENU_CONTEXT,
619
- // filter out native-only props that shouldn't reach the DOM
620
- // @ts-ignore
621
- destructive,
622
- // @ts-ignore
623
- hidden,
624
- // @ts-ignore
625
- androidIconName,
626
- // @ts-ignore
627
- iosIconName,
628
- ...itemProps
629
- } = props;
630
- var ref = React.useRef(null);
631
- var rootContext = useMenuRootContext(scope);
632
- var contentContext = useMenuContentContext(scope);
633
- var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref);
634
- var isPointerDownRef = React.useRef(false);
635
- var handleSelect = function () {
636
- var menuItem = ref.current;
637
- if (!disabled && menuItem) {
638
- if (import_web.isWeb) {
639
- var menuItemEl = menuItem;
640
- var itemSelectEvent = new CustomEvent(ITEM_SELECT, {
641
- bubbles: true,
642
- cancelable: true
643
- });
644
- menuItemEl.addEventListener(ITEM_SELECT, function (event) {
645
- return onSelect === null || onSelect === void 0 ? void 0 : onSelect(event);
646
- }, {
647
- once: true
648
- });
649
- (0, import_dismissable.dispatchDiscreteCustomEvent)(menuItemEl, itemSelectEvent);
650
- if (itemSelectEvent.defaultPrevented || preventCloseOnSelect) {
651
- isPointerDownRef.current = false;
652
- } else {
653
- rootContext.onClose();
654
- }
655
- } else {
656
- onSelect === null || onSelect === void 0 ? void 0 : onSelect({
657
- target: menuItem
658
- });
659
- isPointerDownRef.current = false;
660
- if (!preventCloseOnSelect) {
661
- rootContext.onClose();
662
- }
663
- }
664
- }
665
- };
666
- var content = typeof children === "string" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_web.Text, {
667
- children
668
- }) : children;
669
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuItemImpl, {
670
- outlineStyle: "none",
671
- ...itemProps,
672
- scope,
673
- // @ts-ignore
674
- ref: composedRefs,
675
- disabled,
676
- onPress: (0, import_web.composeEventHandlers)(props.onPress, handleSelect),
677
- onPointerDown: function (event) {
678
- var _props_onPointerDown;
679
- (_props_onPointerDown = props.onPointerDown) === null || _props_onPointerDown === void 0 ? void 0 : _props_onPointerDown.call(props, event);
680
- isPointerDownRef.current = true;
681
- },
682
- onPointerUp: (0, import_web.composeEventHandlers)(props.onPointerUp, function (event) {
683
- if (import_web.isWeb) {
684
- var _event_currentTarget;
685
- if (!isPointerDownRef.current) (_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0 ? void 0 : _event_currentTarget.click();
686
- }
687
- }),
688
- ...(import_web.isWeb ? {
689
- onKeyDown: (0, import_web.composeEventHandlers)(props.onKeyDown, function (event) {
690
- var isTypingAhead = contentContext.searchRef.current !== "";
691
- if (disabled || isTypingAhead && event.key === " ") return;
692
- if (SELECTION_KEYS.includes(event.key)) {
693
- var _event_currentTarget;
694
- (_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0 ? void 0 : _event_currentTarget.click();
695
- event.preventDefault();
696
- }
697
- })
698
- } : {}),
699
- children: content
700
- });
701
- });
702
- var MenuItemImpl = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
703
- var {
704
- scope = MENU_CONTEXT,
705
- disabled = false,
706
- textValue,
707
- unstyled = process.env.TAMAGUI_HEADLESS === "1",
708
- ...itemProps
709
- } = props;
710
- var contentContext = useMenuContentContext(scope);
711
- var ref = React.useRef(null);
712
- var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref);
713
- var [isFocused, setIsFocused] = React.useState(false);
714
- var [textContent, setTextContent] = React.useState("");
715
- if (import_web.isWeb) {
716
- React.useEffect(function () {
717
- var menuItem = ref.current;
718
- if (menuItem) {
719
- var _menuItem_textContent;
720
- setTextContent(((_menuItem_textContent = menuItem.textContent) !== null && _menuItem_textContent !== void 0 ? _menuItem_textContent : "").trim());
721
- }
722
- }, [itemProps.children]);
723
- }
724
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.ItemSlot, {
725
- scope,
726
- disabled,
727
- textValue: textValue !== null && textValue !== void 0 ? textValue : textContent,
728
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
729
- asChild: true,
730
- __scopeRovingFocusGroup: scope,
731
- focusable: !disabled,
732
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Item, {
733
- unstyled,
734
- componentName: ITEM_NAME,
735
- role: "menuitem",
736
- "data-highlighted": isFocused ? "" : void 0,
737
- "aria-disabled": disabled || void 0,
738
- "data-disabled": disabled ? "" : void 0,
739
- ...itemProps,
740
- ref: composedRefs,
741
- /**
742
- * We focus items on `pointerMove` to achieve the following:
743
- *
744
- * - Mouse over an item (it focuses)
745
- * - Leave mouse where it is and use keyboard to focus a different item
746
- * - Wiggle mouse without it leaving previously focused item
747
- * - Previously focused item should re-focus
748
- *
749
- * If we used `mouseOver`/`mouseEnter` it would not re-focus when the mouse
750
- * wiggles. This is to match native menu implementation.
751
- */
752
- onPointerMove: (0, import_web.composeEventHandlers)(props.onPointerMove, function (event) {
753
- if (event.pointerType !== "mouse") return;
754
- if (disabled) {
755
- contentContext.onItemLeave(event);
756
- } else {
757
- contentContext.onItemEnter(event);
758
- if (!event.defaultPrevented) {
759
- var item = event.currentTarget;
760
- item.focus({
761
- preventScroll: true,
762
- focusVisible: false
763
- });
764
- }
765
- }
766
- }),
767
- onPointerLeave: (0, import_web.composeEventHandlers)(props.onPointerLeave, function (event) {
768
- contentContext.onItemLeave(event);
769
- }),
770
- onFocus: (0, import_web.composeEventHandlers)(props.onFocus, function () {
771
- return setIsFocused(true);
772
- }),
773
- onBlur: (0, import_web.composeEventHandlers)(props.onBlur, function () {
774
- return setIsFocused(false);
775
- })
776
- })
777
- })
778
- });
779
- });
780
- MenuItem.displayName = ITEM_NAME;
781
- var ITEM_TITLE_NAME = "MenuItemTitle";
782
- var MenuItemTitle = _Title.styleable(function (props, forwardedRef) {
783
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Title, {
784
- ...props,
785
- ref: forwardedRef
786
- });
787
- });
788
- MenuItemTitle.displayName = ITEM_TITLE_NAME;
789
- var ITEM_SUB_TITLE_NAME = "MenuItemSubTitle";
790
- var MenuItemSubTitle = _SubTitle.styleable(function (props, forwardedRef) {
791
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_SubTitle, {
792
- ...props,
793
- ref: forwardedRef
794
- });
795
- });
796
- MenuItemSubTitle.displayName = ITEM_SUB_TITLE_NAME;
797
- var ITEM_IMAGE = "MenuItemImage";
798
- var MenuItemImage = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
799
- var {
800
- // @ts-ignore - native menu ios config
801
- ios,
802
- // @ts-ignore
803
- androidIconName,
804
- // @ts-ignore
805
- iosIconName,
806
- ...rest
807
- } = props;
808
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Image, {
809
- ...rest,
810
- ref: forwardedRef
811
- });
812
- });
813
- MenuItemImage.displayName = ITEM_IMAGE;
814
- var ITEM_ICON = "MenuItemIcon";
815
- var MenuItemIcon = _Icon.styleable(function (props, forwardedRef) {
816
- var {
817
- // @ts-ignore
818
- ios,
819
- // @ts-ignore
820
- android,
821
- // @ts-ignore
822
- androidIconName,
823
- // @ts-ignore
824
- iosIconName,
825
- ...rest
826
- } = props;
827
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Icon, {
828
- ...rest,
829
- ref: forwardedRef
830
- });
831
- });
832
- MenuItemIcon.displayName = ITEM_ICON;
833
- var CHECKBOX_ITEM_NAME = "MenuCheckboxItem";
834
- var MenuCheckboxItem = _Item.styleable(function (props, forwardedRef) {
835
- var {
836
- checked = false,
837
- onCheckedChange,
838
- scope = MENU_CONTEXT,
839
- // filter out native-only props
840
- // @ts-ignore - native menu value state
841
- value,
842
- // @ts-ignore - native menu value change handler
843
- onValueChange,
844
- ...checkboxItemProps
845
- } = props;
846
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ItemIndicatorProvider, {
847
- scope,
848
- checked,
849
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuItem, {
850
- componentName: CHECKBOX_ITEM_NAME,
851
- role: import_web.isWeb ? "menuitemcheckbox" : "menuitem",
852
- "aria-checked": isIndeterminate(checked) ? "mixed" : checked,
853
- ...checkboxItemProps,
854
- scope,
855
- ref: forwardedRef,
856
- "data-state": getCheckedState(checked),
857
- onSelect: (0, import_web.composeEventHandlers)(checkboxItemProps.onSelect, function () {
858
- return onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(isIndeterminate(checked) ? true : !checked);
859
- }, {
860
- checkDefaultPrevented: false
861
- })
862
- })
863
- });
864
- });
865
- MenuCheckboxItem.displayName = CHECKBOX_ITEM_NAME;
866
- var RADIO_GROUP_NAME = "MenuRadioGroup";
867
- var {
868
- Provider: RadioGroupProvider,
869
- useStyledContext: useRadioGroupContext
870
- } = (0, import_web.createStyledContext)();
871
- var MenuRadioGroup = _MenuGroup.styleable(function (props, forwardedRef) {
872
- var {
873
- value,
874
- onValueChange,
875
- scope = MENU_CONTEXT,
876
- ...groupProps
877
- } = props;
878
- var handleValueChange = (0, import_use_callback_ref.useCallbackRef)(onValueChange);
879
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(RadioGroupProvider, {
880
- scope,
881
- value,
882
- onValueChange: handleValueChange,
883
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(_MenuGroup, {
884
- componentName: RADIO_GROUP_NAME,
885
- ...groupProps,
886
- ref: forwardedRef
887
- })
888
- });
889
- });
890
- MenuRadioGroup.displayName = RADIO_GROUP_NAME;
891
- var RADIO_ITEM_NAME = "MenuRadioItem";
892
- var MenuRadioItem = _Item.styleable(function (props, forwardedRef) {
893
- var {
894
- value,
895
- scope = MENU_CONTEXT,
896
- ...radioItemProps
897
- } = props;
898
- var context = useRadioGroupContext(scope);
899
- var checked = value === context.value;
900
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ItemIndicatorProvider, {
901
- scope,
902
- checked,
903
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuItem, {
904
- componentName: RADIO_ITEM_NAME,
905
- ...radioItemProps,
906
- scope,
907
- "aria-checked": checked,
908
- ref: forwardedRef,
909
- role: import_web.isWeb ? "menuitemradio" : "menuitem",
910
- "data-state": getCheckedState(checked),
911
- onSelect: (0, import_web.composeEventHandlers)(radioItemProps.onSelect, function () {
912
- var _context_onValueChange;
913
- return (_context_onValueChange = context.onValueChange) === null || _context_onValueChange === void 0 ? void 0 : _context_onValueChange.call(context, value);
914
- }, {
915
- checkDefaultPrevented: false
916
- })
917
- })
918
- });
919
- });
920
- MenuRadioItem.displayName = RADIO_ITEM_NAME;
921
- var ITEM_INDICATOR_NAME = "MenuItemIndicator";
922
- var {
923
- Provider: ItemIndicatorProvider,
924
- useStyledContext: useItemIndicatorContext
925
- } = (0, import_web.createStyledContext)();
926
- var MenuItemIndicator = _Indicator.styleable(function (props, forwardedRef) {
927
- var {
928
- scope = MENU_CONTEXT,
929
- forceMount,
930
- ...itemIndicatorProps
931
- } = props;
932
- var indicatorContext = useItemIndicatorContext(scope);
933
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, {
934
- children: forceMount || isIndeterminate(indicatorContext.checked) || indicatorContext.checked === true ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Indicator, {
935
- componentName: ITEM_INDICATOR_NAME,
936
- render: "span",
937
- ...itemIndicatorProps,
938
- ref: forwardedRef,
939
- "data-state": getCheckedState(indicatorContext.checked)
940
- }) : null
941
- });
942
- });
943
- MenuItemIndicator.displayName = ITEM_INDICATOR_NAME;
944
- var MenuArrow = /* @__PURE__ */React.forwardRef(function MenuArrow2(props, forwardedRef) {
945
- var {
946
- scope = MENU_CONTEXT,
947
- unstyled = process.env.TAMAGUI_HEADLESS === "1",
948
- ...rest
949
- } = props;
950
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.PopperArrow, {
951
- scope,
952
- componentName: "PopperArrow",
953
- unstyled,
954
- ...(!unstyled && {
955
- backgroundColor: "$background"
956
- }),
957
- ...rest,
958
- ref: forwardedRef
959
- });
960
- });
961
- var SUB_NAME = "MenuSub";
962
- var {
963
- Provider: MenuSubProvider,
964
- useStyledContext: useMenuSubContext
965
- } = (0, import_web.createStyledContext)();
966
- var MenuSub = function (props) {
967
- var _parentPopperContext_placement;
968
- var isTouchDevice = (0, import_web.useIsTouchDevice)();
969
- var {
970
- scope = MENU_CONTEXT
971
- } = props;
972
- var rootContext = useMenuRootContext(scope);
973
- var parentPopperContext = PopperPrimitive.usePopperContext(scope);
974
- var parentSide = (_parentPopperContext_placement = parentPopperContext.placement) === null || _parentPopperContext_placement === void 0 ? void 0 : _parentPopperContext_placement.split("-")[0];
975
- var isNestedSubmenu = parentSide === "left" || parentSide === "right";
976
- var defaultPlacement = isTouchDevice ? "bottom" : isNestedSubmenu ? `${parentSide}-start` : rootContext.dir === "rtl" ? "left-start" : "right-start";
977
- var {
978
- children,
979
- open = false,
980
- onOpenChange,
981
- allowFlip: allowFlipProp = {
982
- padding: 10
983
- },
984
- stayInFrame = {
985
- padding: 10
986
- },
987
- placement = defaultPlacement,
988
- ...rest
989
- } = props;
990
- var allowFlip = React.useMemo(function () {
991
- if (!isNestedSubmenu || typeof allowFlipProp === "boolean") return allowFlipProp;
992
- if (allowFlipProp.fallbackPlacements) return allowFlipProp;
993
- var side = placement.split("-")[0];
994
- var align = placement.split("-")[1] || "start";
995
- var otherAlign = align === "start" ? "end" : "start";
996
- if (side === "left" || side === "right") {
997
- var oppositeSide = side === "right" ? "left" : "right";
998
- return {
999
- ...((typeof allowFlipProp === "undefined" ? "undefined" : _type_of(allowFlipProp)) === "object" ? allowFlipProp : {}),
1000
- fallbackPlacements: [`${side}-${otherAlign}`, `${oppositeSide}-${align}`, `${oppositeSide}-${otherAlign}`]
1001
- };
1002
- }
1003
- return allowFlipProp;
1004
- }, [isNestedSubmenu, allowFlipProp, placement]);
1005
- var parentMenuContext = useMenuContext(scope);
1006
- var [trigger, setTrigger] = React.useState(null);
1007
- var [content, setContent] = React.useState(null);
1008
- var handleOpenChange = (0, import_use_callback_ref.useCallbackRef)(onOpenChange);
1009
- React.useEffect(function () {
1010
- if (parentMenuContext.open === false) handleOpenChange(false);
1011
- return function () {
1012
- return handleOpenChange(false);
1013
- };
1014
- }, [parentMenuContext.open, handleOpenChange]);
1015
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.Popper, {
1016
- open,
1017
- placement,
1018
- allowFlip,
1019
- stayInFrame,
1020
- ...rest,
1021
- scope,
1022
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuProvider, {
1023
- scope,
1024
- open,
1025
- onOpenChange: handleOpenChange,
1026
- content,
1027
- onContentChange: setContent,
1028
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuSubProvider, {
1029
- scope,
1030
- contentId: (0, import_react.useId)(),
1031
- triggerId: (0, import_react.useId)(),
1032
- trigger,
1033
- onTriggerChange: setTrigger,
1034
- children
1035
- })
1036
- })
1037
- });
1038
- };
1039
- MenuSub.displayName = SUB_NAME;
1040
- var SUB_TRIGGER_NAME = "MenuSubTrigger";
1041
- var MenuSubTrigger = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
1042
- var scope = props.scope || MENU_CONTEXT;
1043
- var context = useMenuContext(scope);
1044
- var rootContext = useMenuRootContext(scope);
1045
- var subContext = useMenuSubContext(scope);
1046
- var contentContext = useMenuContentContext(scope);
1047
- var popperContext = PopperPrimitive.usePopperContext(scope);
1048
- var openTimerRef = React.useRef(null);
1049
- var {
1050
- pointerGraceTimerRef,
1051
- onPointerGraceIntentChange
1052
- } = contentContext;
1053
- var effectiveDir = rootContext.dir;
1054
- var clearOpenTimer = React.useCallback(function () {
1055
- if (openTimerRef.current) window.clearTimeout(openTimerRef.current);
1056
- openTimerRef.current = null;
1057
- }, []);
1058
- React.useEffect(function () {
1059
- return clearOpenTimer;
1060
- }, [clearOpenTimer]);
1061
- React.useEffect(function () {
1062
- var pointerGraceTimer = pointerGraceTimerRef.current;
1063
- return function () {
1064
- window.clearTimeout(pointerGraceTimer);
1065
- onPointerGraceIntentChange(null);
1066
- };
1067
- }, [pointerGraceTimerRef, onPointerGraceIntentChange]);
1068
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuAnchor, {
1069
- componentName: SUB_TRIGGER_NAME,
1070
- asChild: "except-style",
1071
- scope,
1072
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuItemImpl, {
1073
- id: subContext.triggerId,
1074
- "aria-haspopup": "menu",
1075
- "aria-expanded": context.open,
1076
- "aria-controls": subContext.contentId,
1077
- "data-state": getOpenState(context.open),
1078
- outlineStyle: "none",
1079
- ...props,
1080
- ref: (0, import_web.composeRefs)(forwardedRef, subContext.onTriggerChange),
1081
- // This is redundant for mouse users but we cannot determine pointer type from
1082
- // click event and we cannot use pointerup event (see git history for reasons why)
1083
- onPress: function (event) {
1084
- var _props_onPress;
1085
- (_props_onPress = props.onPress) === null || _props_onPress === void 0 ? void 0 : _props_onPress.call(props, event);
1086
- if (props.disabled || event.defaultPrevented) return;
1087
- if (import_web.isWeb) {
1088
- event.currentTarget.focus();
1089
- }
1090
- if (!context.open) context.onOpenChange(true);
1091
- },
1092
- onPointerMove: (0, import_web.composeEventHandlers)(props.onPointerMove,
1093
- // @ts-ignore
1094
- whenMouse(function (event) {
1095
- contentContext.onItemEnter(event);
1096
- if (event.defaultPrevented) return;
1097
- if (!props.disabled && !context.open && !openTimerRef.current) {
1098
- contentContext.onPointerGraceIntentChange(null);
1099
- openTimerRef.current = window.setTimeout(function () {
1100
- context.onOpenChange(true);
1101
- clearOpenTimer();
1102
- }, 100);
1103
- }
1104
- })),
1105
- onPointerLeave: (0, import_web.composeEventHandlers)(props.onPointerLeave, function (eventIn) {
1106
- var _context_content;
1107
- var event = eventIn;
1108
- clearOpenTimer();
1109
- var contentRect = (_context_content = context.content) === null || _context_content === void 0 ? void 0 : _context_content.getBoundingClientRect();
1110
- if (contentRect) {
1111
- var _contentEl_dataset, _sideEl_dataset;
1112
- var contentEl = context.content;
1113
- var sideEl = (contentEl === null || contentEl === void 0 ? void 0 : (_contentEl_dataset = contentEl.dataset) === null || _contentEl_dataset === void 0 ? void 0 : _contentEl_dataset.side) ? contentEl : contentEl === null || contentEl === void 0 ? void 0 : contentEl.querySelector("[data-side]");
1114
- var side = (sideEl === null || sideEl === void 0 ? void 0 : (_sideEl_dataset = sideEl.dataset) === null || _sideEl_dataset === void 0 ? void 0 : _sideEl_dataset.side) || "right";
1115
- var rightSide = side === "right";
1116
- var bleed = rightSide ? -5 : 5;
1117
- var contentNearEdge = contentRect[rightSide ? "left" : "right"];
1118
- var contentFarEdge = contentRect[rightSide ? "right" : "left"];
1119
- var polygon = {
1120
- area: [
1121
- // Apply a bleed on clientX to ensure that our exit point is
1122
- // consistently within polygon bounds
1123
- {
1124
- x: event.clientX + bleed,
1125
- y: event.clientY
1126
- }, {
1127
- x: contentNearEdge,
1128
- y: contentRect.top
1129
- }, {
1130
- x: contentFarEdge,
1131
- y: contentRect.top
1132
- }, {
1133
- x: contentFarEdge,
1134
- y: contentRect.bottom
1135
- }, {
1136
- x: contentNearEdge,
1137
- y: contentRect.bottom
1138
- }],
1139
- side
1140
- };
1141
- contentContext.onPointerGraceIntentChange(polygon);
1142
- window.clearTimeout(pointerGraceTimerRef.current);
1143
- pointerGraceTimerRef.current = window.setTimeout(function () {
1144
- return contentContext.onPointerGraceIntentChange(null);
1145
- }, 300);
1146
- } else if (import_web.isWeb && subContext.trigger) {
1147
- var triggerEl = subContext.trigger;
1148
- var triggerRect = triggerEl === null || triggerEl === void 0 ? void 0 : triggerEl.getBoundingClientRect();
1149
- if (triggerRect) {
1150
- var _popperContext_placement;
1151
- var placementSide = (_popperContext_placement = popperContext.placement) === null || _popperContext_placement === void 0 ? void 0 : _popperContext_placement.split("-")[0];
1152
- var side1 = placementSide === "left" || placementSide === "right" ? placementSide : rootContext.dir === "rtl" ? "left" : "right";
1153
- var rightSide1 = side1 === "right";
1154
- var bleed1 = rightSide1 ? -5 : 5;
1155
- var nearEdge = rightSide1 ? triggerRect.right + 4 : triggerRect.left - 4;
1156
- var farEdge = rightSide1 ? nearEdge + 200 : nearEdge - 200;
1157
- var polygon1 = {
1158
- area: [{
1159
- x: event.clientX + bleed1,
1160
- y: event.clientY
1161
- }, {
1162
- x: nearEdge,
1163
- y: triggerRect.top - 50
1164
- }, {
1165
- x: farEdge,
1166
- y: triggerRect.top - 50
1167
- }, {
1168
- x: farEdge,
1169
- y: triggerRect.bottom + 50
1170
- }, {
1171
- x: nearEdge,
1172
- y: triggerRect.bottom + 50
1173
- }],
1174
- side: side1
1175
- };
1176
- contentContext.onPointerGraceIntentChange(polygon1);
1177
- window.clearTimeout(pointerGraceTimerRef.current);
1178
- pointerGraceTimerRef.current = window.setTimeout(function () {
1179
- return contentContext.onPointerGraceIntentChange(null);
1180
- }, 300);
1181
- }
1182
- } else {
1183
- contentContext.onTriggerLeave(event);
1184
- if (event.defaultPrevented) return;
1185
- contentContext.onPointerGraceIntentChange(null);
1186
- }
1187
- }),
1188
- ...(import_web.isWeb ? {
1189
- onKeyDown: (0, import_web.composeEventHandlers)(props.onKeyDown, function (event) {
1190
- var isTypingAhead = contentContext.searchRef.current !== "";
1191
- if (props.disabled || isTypingAhead && event.key === " ") return;
1192
- var willOpen = SUB_OPEN_KEYS[effectiveDir].includes(event.key);
1193
- if (willOpen) {
1194
- var _popperContext_refs, _context_content;
1195
- if (context.open && context.content) {
1196
- var _contentEl_querySelector;
1197
- var contentEl = context.content;
1198
- var firstItem = (_contentEl_querySelector = contentEl.querySelector) === null || _contentEl_querySelector === void 0 ? void 0 : _contentEl_querySelector.call(contentEl, '[role="menuitem"]:not([data-disabled])');
1199
- if (firstItem) {
1200
- firstItem.focus({
1201
- focusVisible: true
1202
- });
1203
- event.preventDefault();
1204
- return;
1205
- }
1206
- }
1207
- var triggerEl = event.currentTarget;
1208
- (_popperContext_refs = popperContext.refs) === null || _popperContext_refs === void 0 ? void 0 : _popperContext_refs.setReference(triggerEl);
1209
- context.onOpenChange(true);
1210
- requestAnimationFrame(function () {
1211
- var _popperContext_update;
1212
- (_popperContext_update = popperContext.update) === null || _popperContext_update === void 0 ? void 0 : _popperContext_update.call(popperContext);
1213
- });
1214
- (_context_content = context.content) === null || _context_content === void 0 ? void 0 : _context_content.focus({
1215
- focusVisible: true
1216
- });
1217
- event.preventDefault();
1218
- }
1219
- })
1220
- } : null)
1221
- })
1222
- });
1223
- });
1224
- MenuSubTrigger.displayName = SUB_TRIGGER_NAME;
1225
- var SUB_CONTENT_NAME = "MenuSubContent";
1226
- var MenuSubContentFrame = (0, import_web.styled)(PopperPrimitive.PopperContentFrame, {
1227
- name: SUB_CONTENT_NAME
1228
- });
1229
- var MenuSubContent = MenuSubContentFrame.styleable(function (props, forwardedRef) {
1230
- var _popperContext_placement;
1231
- var scope = props.scope || MENU_CONTEXT;
1232
- var portalContext = usePortalContext(scope);
1233
- var {
1234
- forceMount = portalContext.forceMount,
1235
- ...subContentProps
1236
- } = props;
1237
- var context = useMenuContext(scope);
1238
- var rootContext = useMenuRootContext(scope);
1239
- var subContext = useMenuSubContext(scope);
1240
- var popperContext = PopperPrimitive.usePopperContext(scope);
1241
- var ref = React.useRef(null);
1242
- var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref);
1243
- var placementSide = (_popperContext_placement = popperContext.placement) === null || _popperContext_placement === void 0 ? void 0 : _popperContext_placement.split("-")[0];
1244
- var dataSide = placementSide === "left" || placementSide === "right" ? placementSide : rootContext.dir === "rtl" ? "left" : "right";
1245
- var effectiveDir = rootContext.dir;
1246
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Provider, {
1247
- scope,
1248
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Slot, {
1249
- scope,
1250
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuContentImpl, {
1251
- id: subContext.contentId,
1252
- "aria-labelledby": subContext.triggerId,
1253
- ...subContentProps,
1254
- ref: composedRefs,
1255
- "data-side": dataSide,
1256
- disableOutsidePointerEvents: false,
1257
- disableOutsideScroll: false,
1258
- trapFocus: false,
1259
- onOpenAutoFocus: function (event) {
1260
- if (rootContext.isUsingKeyboardRef.current) {
1261
- var _root_querySelector, _this;
1262
- var root = ref.current;
1263
- var content = root === null || root === void 0 ? void 0 : (_root_querySelector = root.querySelector) === null || _root_querySelector === void 0 ? void 0 : _root_querySelector.call(root, "[data-tamagui-menu-content]");
1264
- (_this = content || root) === null || _this === void 0 ? void 0 : _this.focus({
1265
- preventScroll: true
1266
- });
1267
- }
1268
- event.preventDefault();
1269
- },
1270
- // The menu might close because of focusing another menu item in the parent menu. We
1271
- // don't want it to refocus the trigger in that case so we handle trigger focus ourselves.
1272
- onCloseAutoFocus: function (event) {
1273
- return event.preventDefault();
1274
- },
1275
- onFocusOutside: (0, import_web.composeEventHandlers)(props.onFocusOutside, function (event) {
1276
- if (event.target !== subContext.trigger) context.onOpenChange(false);
1277
- }),
1278
- onEscapeKeyDown: (0, import_web.composeEventHandlers)(props.onEscapeKeyDown, function (event) {
1279
- var _subContext_trigger;
1280
- context.onOpenChange(false);
1281
- (_subContext_trigger = subContext.trigger) === null || _subContext_trigger === void 0 ? void 0 : _subContext_trigger.focus({
1282
- focusVisible: true
1283
- });
1284
- event.preventDefault();
1285
- }),
1286
- ...(import_web.isWeb ? {
1287
- onKeyDown: (0, import_web.composeEventHandlers)(props.onKeyDown, function (event) {
1288
- var isKeyDownInside = event.currentTarget.contains(event.target);
1289
- var isCloseKey = SUB_CLOSE_KEYS[effectiveDir].includes(event.key);
1290
- if (isKeyDownInside && isCloseKey) {
1291
- var _subContext_trigger;
1292
- context.onOpenChange(false);
1293
- (_subContext_trigger = subContext.trigger) === null || _subContext_trigger === void 0 ? void 0 : _subContext_trigger.focus({
1294
- focusVisible: true
1295
- });
1296
- event.preventDefault();
1297
- }
1298
- })
1299
- } : null)
1300
- })
1301
- })
1302
- });
1303
- });
1304
- MenuSubContent.displayName = SUB_CONTENT_NAME;
1305
- var Anchor = MenuAnchor;
1306
- var Portal = MenuPortal;
1307
- var Content = MenuContent;
1308
- var Group = _MenuGroup.styleable(function (props, ref) {
1309
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_MenuGroup, {
1310
- ...props,
1311
- ref
1312
- });
1313
- });
1314
- Group.displayName = "MenuGroup";
1315
- var Label = _Label.styleable(function (props, ref) {
1316
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Label, {
1317
- ...props,
1318
- ref
1319
- });
1320
- });
1321
- Label.displayName = "MenuLabel";
1322
- var Item = MenuItem;
1323
- var CheckboxItem = MenuCheckboxItem;
1324
- var RadioGroup = MenuRadioGroup;
1325
- var RadioItem = MenuRadioItem;
1326
- var ItemIndicator = MenuItemIndicator;
1327
- var Separator = _Separator.styleable(function (props, ref) {
1328
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Separator, {
1329
- ...props,
1330
- ref
1331
- });
1332
- });
1333
- Separator.displayName = "MenuSeparator";
1334
- var Arrow = MenuArrow;
1335
- var Sub = MenuSub;
1336
- var SubTrigger = MenuSubTrigger;
1337
- var SubContent = MenuSubContent;
1338
- var ItemTitle = MenuItemTitle;
1339
- var ItemSubtitle = MenuItemSubTitle;
1340
- var ItemImage = MenuItemImage;
1341
- var ItemIcon = MenuItemIcon;
1342
- var Menu = (0, import_web.withStaticProperties)(MenuComp, {
1343
- Anchor,
1344
- Portal,
1345
- Content,
1346
- Group,
1347
- Label,
1348
- Item,
1349
- CheckboxItem,
1350
- RadioGroup,
1351
- RadioItem,
1352
- ItemIndicator,
1353
- Separator,
1354
- Arrow,
1355
- Sub,
1356
- SubTrigger,
1357
- SubContent,
1358
- ItemTitle,
1359
- ItemSubtitle,
1360
- ItemImage,
1361
- ItemIcon
1362
- });
1363
- return {
1364
- Menu
1365
- };
92
+ var MenuImageFrame = (0, import_web.styled)(import_image.Image, { displayName: "MenuItemImage" });
93
+ function createBaseMenu() {
94
+ var MenuComp = function(props) {
95
+ var direction = (0, import_use_direction.useDirection)(props.dir);
96
+ var defaultPlacement = direction === "rtl" ? "bottom-end" : "bottom-start";
97
+ var { scope = MENU_CONTEXT, open = false, children, dir, onOpenChange, modal = true, allowFlip = { padding: 10 }, stayInFrame = { padding: 10 }, placement = defaultPlacement, resize = true, offset = 10, ...rest } = props;
98
+ var [content, setContent] = React.useState(null);
99
+ var isUsingKeyboardRef = React.useRef(false);
100
+ var handleOpenChange = (0, import_use_callback_ref.useCallbackRef)(onOpenChange);
101
+ if (import_web.isWeb) {
102
+ React.useEffect(function() {
103
+ var handleKeyDown = function() {
104
+ isUsingKeyboardRef.current = true;
105
+ document.addEventListener("pointerdown", handlePointer, {
106
+ capture: true,
107
+ once: true
108
+ });
109
+ document.addEventListener("pointermove", handlePointer, {
110
+ capture: true,
111
+ once: true
112
+ });
113
+ };
114
+ var handlePointer = function() {
115
+ return isUsingKeyboardRef.current = false;
116
+ };
117
+ document.addEventListener("keydown", handleKeyDown, { capture: true });
118
+ return function() {
119
+ document.removeEventListener("keydown", handleKeyDown, { capture: true });
120
+ document.removeEventListener("pointerdown", handlePointer, { capture: true });
121
+ document.removeEventListener("pointermove", handlePointer, { capture: true });
122
+ };
123
+ }, []);
124
+ }
125
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperPrimitive.Popper, {
126
+ scope,
127
+ open,
128
+ placement,
129
+ allowFlip,
130
+ stayInFrame,
131
+ resize,
132
+ offset,
133
+ ...rest,
134
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuProvider, {
135
+ scope,
136
+ open,
137
+ onOpenChange: handleOpenChange,
138
+ content,
139
+ onContentChange: setContent,
140
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuRootProvider, {
141
+ scope,
142
+ open,
143
+ onClose: React.useCallback(function() {
144
+ return handleOpenChange(false);
145
+ }, [handleOpenChange]),
146
+ isUsingKeyboardRef,
147
+ dir: direction,
148
+ modal,
149
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuSubProvider, {
150
+ scope,
151
+ children
152
+ })
153
+ })
154
+ })
155
+ });
156
+ };
157
+ var RepropagateMenuAndMenuRootProvider = function(props) {
158
+ var { scope = MENU_CONTEXT, menuContext, rootContext, popperContext, menuSubContext, children } = props;
159
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperPrimitive.PopperProvider, {
160
+ ...popperContext,
161
+ scope,
162
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuProvider, {
163
+ scope,
164
+ ...menuContext,
165
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuRootProvider, {
166
+ scope,
167
+ ...rootContext,
168
+ children: menuSubContext ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuSubProvider, {
169
+ scope,
170
+ ...menuSubContext,
171
+ children
172
+ }) : children
173
+ })
174
+ })
175
+ });
176
+ };
177
+ MenuComp.displayName = MENU_NAME;
178
+ var ANCHOR_NAME = "MenuAnchor";
179
+ var MenuAnchor = function(props) {
180
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperPrimitive.PopperAnchor, {
181
+ scope: MENU_CONTEXT,
182
+ ...props
183
+ });
184
+ };
185
+ MenuAnchor.displayName = ANCHOR_NAME;
186
+ var PORTAL_NAME = "MenuPortal";
187
+ var { Provider: PortalProvider, useStyledContext: usePortalContext } = (0, import_web.createStyledContext)(void 0, "Portal");
188
+ var MenuPortal = function(props) {
189
+ var { scope = MENU_CONTEXT, forceMount, zIndex, children } = props;
190
+ var menuContext = useMenuContext(scope);
191
+ var rootContext = useMenuRootContext(scope);
192
+ var popperContext = PopperPrimitive.usePopperContext(scope);
193
+ var menuSubContext = useMenuSubContext(scope);
194
+ var themeName = (0, import_web.useThemeName)();
195
+ var themedChildren = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.Theme, {
196
+ forceClassName: true,
197
+ name: themeName,
198
+ children
199
+ });
200
+ var content = (0, import_portal.needsPortalRepropagation)() ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RepropagateMenuAndMenuRootProvider, {
201
+ menuContext,
202
+ rootContext,
203
+ popperContext,
204
+ menuSubContext,
205
+ scope,
206
+ children: themedChildren
207
+ }) : themedChildren;
208
+ var isPresent = forceMount || rootContext.open && menuContext.open;
209
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_animate.Animate, {
210
+ type: "presence",
211
+ present: isPresent,
212
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.Portal, {
213
+ stackZIndex: true,
214
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalProvider, {
215
+ scope,
216
+ forceMount,
217
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_web.View, {
218
+ zIndex: zIndex || 100,
219
+ inset: 0,
220
+ position: "absolute",
221
+ children: [!!menuContext.open && !import_web.isWeb && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.View, {
222
+ inset: 0,
223
+ position: "absolute",
224
+ onPress: function() {
225
+ return menuContext.onOpenChange(!menuContext.open);
226
+ }
227
+ }), content]
228
+ })
229
+ }) })
230
+ })
231
+ });
232
+ };
233
+ MenuPortal.displayName = PORTAL_NAME;
234
+ var CONTENT_NAME = "MenuContent";
235
+ var { Provider: MenuContentProvider, useStyledContext: useMenuContentContext } = (0, import_web.createStyledContext)();
236
+ var MenuContentFrame = (0, import_web.styled)(PopperPrimitive.PopperContentFrame, { displayName: CONTENT_NAME });
237
+ var MenuContent = (0, import_core.createStyledHOC)(MenuContentFrame, function(props, forwardedRef) {
238
+ var scope = props.scope || MENU_CONTEXT;
239
+ var portalContext = usePortalContext(scope);
240
+ var { forceMount = portalContext.forceMount, ...contentProps } = props;
241
+ var rootContext = useMenuRootContext(scope);
242
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Provider, {
243
+ scope,
244
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Slot, {
245
+ scope,
246
+ children: rootContext.modal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuRootContentModal, {
247
+ ...contentProps,
248
+ ref: forwardedRef
249
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuRootContentNonModal, {
250
+ ...contentProps,
251
+ ref: forwardedRef
252
+ })
253
+ })
254
+ });
255
+ });
256
+ var MenuRootContentModal = (0, import_core.createRefComponent)(function(props, forwardedRef) {
257
+ var scope = props.scope || MENU_CONTEXT;
258
+ var context = useMenuContext(scope);
259
+ var ref = React.useRef(null);
260
+ var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref);
261
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuContentImpl, {
262
+ ...props,
263
+ scope,
264
+ ref: composedRefs,
265
+ trapFocus: context.open,
266
+ disableOutsidePointerEvents: context.open,
267
+ disableOutsideScroll: false,
268
+ onFocusOutside: (0, import_web.composeEventHandlers)(props.onFocusOutside, function(event) {
269
+ return event.cancel();
270
+ }, { checkDefaultPrevented: false }),
271
+ onDismiss: function() {
272
+ return context.onOpenChange(false);
273
+ }
274
+ });
275
+ });
276
+ var MenuRootContentNonModal = (0, import_core.createRefComponent)(function(props, forwardedRef) {
277
+ var scope = props.scope || MENU_CONTEXT;
278
+ var context = useMenuContext(scope);
279
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuContentImpl, {
280
+ ...props,
281
+ scope,
282
+ ref: forwardedRef,
283
+ trapFocus: false,
284
+ disableOutsidePointerEvents: false,
285
+ disableOutsideScroll: false,
286
+ onDismiss: function() {
287
+ return context.onOpenChange(false);
288
+ }
289
+ });
290
+ });
291
+ var MenuContentImpl = (0, import_core.createRefComponent)(function(props, forwardedRef) {
292
+ var { scope = MENU_CONTEXT, loop = false, trapFocus, onOpenAutoFocus, onCloseAutoFocus, disableOutsidePointerEvents, onEntryFocus, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, onDismiss, disableOutsideScroll, disableDismissOnScroll = false, ...contentProps } = props;
293
+ var context = useMenuContext(scope);
294
+ var rootContext = useMenuRootContext(scope);
295
+ var popperContext = PopperPrimitive.usePopperContext(scope);
296
+ var getItems = useCollection(scope);
297
+ var [currentItemId, setCurrentItemId] = React.useState(null);
298
+ var contentRef = React.useRef(null);
299
+ var focusableContentRef = React.useRef(null);
300
+ var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, contentRef, context.onContentChange);
301
+ var timerRef = React.useRef(0);
302
+ var searchRef = React.useRef("");
303
+ var pointerGraceTimerRef = React.useRef(0);
304
+ var pointerGraceIntentRef = React.useRef(null);
305
+ var pointerDirRef = React.useRef("right");
306
+ var lastPointerXRef = React.useRef(0);
307
+ var handleTypeaheadSearch = function(key) {
308
+ var _items_find, _items_find1;
309
+ var search = searchRef.current + key;
310
+ var items = getItems().filter(function(item) {
311
+ return !item.disabled;
312
+ });
313
+ var currentItem = document.activeElement;
314
+ var currentMatch = (_items_find = items.find(function(item) {
315
+ return item.ref.current === currentItem;
316
+ })) === null || _items_find === void 0 ? void 0 : _items_find.textValue;
317
+ var values = items.map(function(item) {
318
+ return item.textValue;
319
+ });
320
+ var nextMatch = getNextMatch(values, search, currentMatch);
321
+ var newItem = (_items_find1 = items.find(function(item) {
322
+ return item.textValue === nextMatch;
323
+ })) === null || _items_find1 === void 0 ? void 0 : _items_find1.ref.current;
324
+ (function updateSearch(value) {
325
+ searchRef.current = value;
326
+ clearTimeout(timerRef.current);
327
+ if (value !== "") timerRef.current = setTimeout(function() {
328
+ return updateSearch("");
329
+ }, 1e3);
330
+ })(search);
331
+ if (newItem) {
332
+ setTimeout(function() {
333
+ return newItem.focus();
334
+ });
335
+ }
336
+ };
337
+ React.useEffect(function() {
338
+ return function() {
339
+ return clearTimeout(timerRef.current);
340
+ };
341
+ }, []);
342
+ React.useEffect(function() {
343
+ if (!import_web.isWeb || !context.open) return;
344
+ var frame = requestAnimationFrame(function() {
345
+ var container = contentRef.current;
346
+ var el = container === null || container === void 0 ? void 0 : container.querySelector("[data-tamagui-menu-content]");
347
+ if (el) focusableContentRef.current = el;
348
+ });
349
+ return function() {
350
+ return cancelAnimationFrame(frame);
351
+ };
352
+ }, [context.open]);
353
+ React.useEffect(function() {
354
+ if (!import_web.isWeb || disableDismissOnScroll || !context.open) return;
355
+ var handleScroll = function(event) {
356
+ var _popperContext_refs_reference, _popperContext_refs;
357
+ var scrolled = event.target;
358
+ if (!scrolled) return;
359
+ var content2 = contentRef.current;
360
+ if (content2 === null || content2 === void 0 ? void 0 : content2.contains(scrolled)) return;
361
+ var reference = (_popperContext_refs = popperContext.refs) === null || _popperContext_refs === void 0 ? void 0 : (_popperContext_refs_reference = _popperContext_refs.reference) === null || _popperContext_refs_reference === void 0 ? void 0 : _popperContext_refs_reference.current;
362
+ var _reference_contextElement;
363
+ var anchor = _instanceof(reference, Element) ? reference : (_reference_contextElement = reference === null || reference === void 0 ? void 0 : reference.contextElement) !== null && _reference_contextElement !== void 0 ? _reference_contextElement : null;
364
+ if (anchor && !scrolled.contains(anchor)) return;
365
+ context.onOpenChange(false);
366
+ };
367
+ window.addEventListener("scroll", handleScroll, {
368
+ capture: true,
369
+ passive: true
370
+ });
371
+ return function() {
372
+ window.removeEventListener("scroll", handleScroll, { capture: true });
373
+ };
374
+ }, [
375
+ disableDismissOnScroll,
376
+ context.open,
377
+ context.onOpenChange,
378
+ popperContext.refs
379
+ ]);
380
+ if (import_web.isWeb) {
381
+ (0, import_focus_guard.useFocusGuards)();
382
+ }
383
+ var isPointerMovingToSubmenu = React.useCallback(function(event) {
384
+ var _pointerGraceIntentRef_current, _pointerGraceIntentRef_current1;
385
+ var isMovingTowards = pointerDirRef.current === ((_pointerGraceIntentRef_current = pointerGraceIntentRef.current) === null || _pointerGraceIntentRef_current === void 0 ? void 0 : _pointerGraceIntentRef_current.side);
386
+ var inArea = isPointerInGraceArea(event, (_pointerGraceIntentRef_current1 = pointerGraceIntentRef.current) === null || _pointerGraceIntentRef_current1 === void 0 ? void 0 : _pointerGraceIntentRef_current1.area);
387
+ return isMovingTowards && inArea;
388
+ }, []);
389
+ var content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperPrimitive.PopperContent, {
390
+ role: "menu",
391
+ tabIndex: -1,
392
+ "aria-orientation": "vertical",
393
+ "data-state": getOpenState(context.open),
394
+ "data-tamagui-menu-content": "",
395
+ dir: rootContext.dir,
396
+ scope: scope || MENU_CONTEXT,
397
+ ...contentProps,
398
+ ref: composedRefs,
399
+ className: contentProps.transition ? void 0 : contentProps.className,
400
+ ...import_web.isWeb ? {
401
+ onKeyDown: (0, import_web.composeEventHandlers)(contentProps.onKeyDown, function(event) {
402
+ var target = event.target;
403
+ var isKeyDownInside = target.closest("[data-tamagui-menu-content]") === event.currentTarget;
404
+ var isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
405
+ var isCharacterKey = event.key.length === 1;
406
+ if (isKeyDownInside) {
407
+ if (event.key === "Tab") event.preventDefault();
408
+ if (!isModifierKey && isCharacterKey) handleTypeaheadSearch(event.key);
409
+ }
410
+ var isOnContentFrame = event.target.hasAttribute("data-tamagui-menu-content");
411
+ if (!isKeyDownInside || !isOnContentFrame) return;
412
+ if (!FIRST_LAST_KEYS.includes(event.key)) return;
413
+ event.preventDefault();
414
+ var items = getItems().filter(function(item) {
415
+ return !item.disabled;
416
+ });
417
+ var candidateNodes = items.map(function(item) {
418
+ return item.ref.current;
419
+ });
420
+ if (LAST_KEYS.includes(event.key)) candidateNodes.reverse();
421
+ focusFirst(candidateNodes, { focusVisible: true });
422
+ }),
423
+ onBlur: (0, import_web.composeEventHandlers)(props.onBlur, function(event) {
424
+ var _event_currentTarget;
425
+ if (!((_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0 ? void 0 : _event_currentTarget.contains(event.target))) {
426
+ clearTimeout(timerRef.current);
427
+ searchRef.current = "";
428
+ }
429
+ }),
430
+ onPointerMove: (0, import_web.composeEventHandlers)(props.onPointerMove, function(event) {
431
+ var _event_currentTarget;
432
+ if (event.pointerType !== "mouse") return;
433
+ var target = event.target;
434
+ var pointerXHasChanged = lastPointerXRef.current !== event.clientX;
435
+ if (((_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0 ? void 0 : _event_currentTarget.contains(target)) && pointerXHasChanged) {
436
+ var newDir = event.clientX > lastPointerXRef.current ? "right" : "left";
437
+ pointerDirRef.current = newDir;
438
+ lastPointerXRef.current = event.clientX;
439
+ }
440
+ })
441
+ } : {}
442
+ });
443
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuContentProvider, {
444
+ scope,
445
+ searchRef,
446
+ onItemEnter: React.useCallback(function(event) {
447
+ if (isPointerMovingToSubmenu(event)) event.preventDefault();
448
+ }, [isPointerMovingToSubmenu]),
449
+ onItemLeave: React.useCallback(function(event) {
450
+ var _focusableContentRef_current;
451
+ if (isPointerMovingToSubmenu(event)) return;
452
+ (_focusableContentRef_current = focusableContentRef.current) === null || _focusableContentRef_current === void 0 ? void 0 : _focusableContentRef_current.focus();
453
+ setCurrentItemId(null);
454
+ }, [isPointerMovingToSubmenu]),
455
+ onTriggerLeave: React.useCallback(function(event) {
456
+ if (isPointerMovingToSubmenu(event)) event.preventDefault();
457
+ }, [isPointerMovingToSubmenu]),
458
+ pointerGraceTimerRef,
459
+ onPointerGraceIntentChange: React.useCallback(function(intent) {
460
+ pointerGraceIntentRef.current = intent;
461
+ }, []),
462
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remove_scroll.RemoveScroll, {
463
+ enabled: disableOutsideScroll,
464
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_focus_scope.FocusScope, {
465
+ asChild: false,
466
+ trapped: trapFocus,
467
+ onMountAutoFocus: (0, import_web.composeEventHandlers)(onOpenAutoFocus, function(event) {
468
+ event.cancel();
469
+ var content2 = document.querySelector("[data-tamagui-menu-content]");
470
+ content2 === null || content2 === void 0 ? void 0 : content2.focus({ preventScroll: true });
471
+ }),
472
+ onUnmountAutoFocus: onCloseAutoFocus,
473
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dismissable.Dismissable, {
474
+ disableOutsidePointerEvents,
475
+ onEscapeKeyDown,
476
+ onPointerDownOutside,
477
+ onFocusOutside,
478
+ onInteractOutside,
479
+ onDismiss,
480
+ asChild: true,
481
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup, {
482
+ asChild: true,
483
+ __scopeRovingFocusGroup: scope || MENU_CONTEXT,
484
+ dir: rootContext.dir,
485
+ orientation: "vertical",
486
+ loop,
487
+ currentTabStopId: currentItemId,
488
+ onCurrentTabStopIdChange: setCurrentItemId,
489
+ onEntryFocus: (0, import_web.composeEventHandlers)(onEntryFocus, function(event) {
490
+ if (!rootContext.isUsingKeyboardRef.current) {
491
+ event.cancel();
492
+ }
493
+ }),
494
+ children: content
495
+ })
496
+ })
497
+ })
498
+ })
499
+ });
500
+ });
501
+ MenuContent.displayName = CONTENT_NAME;
502
+ var ITEM_NAME = "MenuItem";
503
+ var ITEM_SELECT = "menu.itemSelect";
504
+ var MenuItem = (0, import_core.createStyledHOC)(import_web.View, function(props, forwardedRef) {
505
+ var { disabled = false, onSelect, preventCloseOnSelect, children, scope = MENU_CONTEXT, destructive, hidden, androidIconName, ...itemProps } = props;
506
+ var ref = React.useRef(null);
507
+ var rootContext = useMenuRootContext(scope);
508
+ var contentContext = useMenuContentContext(scope);
509
+ var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref);
510
+ var isPointerDownRef = React.useRef(false);
511
+ var handleSelect = function() {
512
+ var menuItem = ref.current;
513
+ if (!disabled && menuItem) {
514
+ if (import_web.isWeb) {
515
+ var menuItemEl = menuItem;
516
+ var itemSelectEvent = new CustomEvent(ITEM_SELECT, {
517
+ bubbles: true,
518
+ cancelable: true
519
+ });
520
+ menuItemEl.addEventListener(ITEM_SELECT, function(event) {
521
+ return onSelect === null || onSelect === void 0 ? void 0 : onSelect(event);
522
+ }, { once: true });
523
+ (0, import_dismissable.dispatchDiscreteCustomEvent)(menuItemEl, itemSelectEvent);
524
+ if (itemSelectEvent.defaultPrevented || preventCloseOnSelect) {
525
+ isPointerDownRef.current = false;
526
+ } else {
527
+ rootContext.onClose();
528
+ }
529
+ } else {
530
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect({ target: menuItem });
531
+ isPointerDownRef.current = false;
532
+ if (!preventCloseOnSelect) {
533
+ rootContext.onClose();
534
+ }
535
+ }
536
+ }
537
+ };
538
+ var content = typeof children === "string" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.Text, { children }) : children;
539
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuItemImpl, {
540
+ ...itemProps,
541
+ scope,
542
+ ref: composedRefs,
543
+ disabled,
544
+ onPress: (0, import_web.composeEventHandlers)(props.onPress, handleSelect),
545
+ onPointerDown: function(event) {
546
+ var _props_onPointerDown;
547
+ (_props_onPointerDown = props.onPointerDown) === null || _props_onPointerDown === void 0 ? void 0 : _props_onPointerDown.call(props, event);
548
+ isPointerDownRef.current = true;
549
+ },
550
+ onPointerUp: (0, import_web.composeEventHandlers)(props.onPointerUp, function(event) {
551
+ if (import_web.isWeb) {
552
+ var _event_currentTarget;
553
+ if (!isPointerDownRef.current) (_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0 ? void 0 : _event_currentTarget.click();
554
+ }
555
+ }),
556
+ ...import_web.isWeb ? { onKeyDown: (0, import_web.composeEventHandlers)(props.onKeyDown, function(event) {
557
+ var isTypingAhead = contentContext.searchRef.current !== "";
558
+ if (disabled || isTypingAhead && event.key === " ") return;
559
+ if (SELECTION_KEYS.includes(event.key)) {
560
+ var _event_currentTarget;
561
+ (_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0 ? void 0 : _event_currentTarget.click();
562
+ event.preventDefault();
563
+ }
564
+ }) } : {},
565
+ children: content
566
+ });
567
+ });
568
+ var MenuItemImpl = (0, import_core.createRefComponent)(function(props, forwardedRef) {
569
+ var { scope = MENU_CONTEXT, className, disabled = false, textValue, ...itemProps } = props;
570
+ var contentContext = useMenuContentContext(scope);
571
+ var ref = React.useRef(null);
572
+ var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref);
573
+ var [isFocused, setIsFocused] = React.useState(false);
574
+ var [textContent, setTextContent] = React.useState("");
575
+ if (import_web.isWeb) {
576
+ React.useEffect(function() {
577
+ var menuItem = ref.current;
578
+ if (menuItem) {
579
+ var _menuItem_textContent;
580
+ setTextContent(((_menuItem_textContent = menuItem.textContent) !== null && _menuItem_textContent !== void 0 ? _menuItem_textContent : "").trim());
581
+ }
582
+ }, [itemProps.children]);
583
+ }
584
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.ItemSlot, {
585
+ scope,
586
+ disabled,
587
+ textValue: textValue !== null && textValue !== void 0 ? textValue : textContent,
588
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
589
+ asChild: true,
590
+ __scopeRovingFocusGroup: scope,
591
+ tabIndex: disabled ? -1 : 0,
592
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.View, {
593
+ className: `is_${ITEM_NAME} ${className || ""}`.trim(),
594
+ role: "menuitem",
595
+ "data-highlighted": isFocused ? "" : void 0,
596
+ "aria-disabled": disabled || void 0,
597
+ "data-disabled": disabled ? "" : void 0,
598
+ ...itemProps,
599
+ ref: composedRefs,
600
+ /**
601
+ * We focus items on `pointerMove` to achieve the following:
602
+ *
603
+ * - Mouse over an item (it focuses)
604
+ * - Leave mouse where it is and use keyboard to focus a different item
605
+ * - Wiggle mouse without it leaving previously focused item
606
+ * - Previously focused item should re-focus
607
+ *
608
+ * If we used `mouseOver`/`mouseEnter` it would not re-focus when the mouse
609
+ * wiggles. This is to match native menu implementation.
610
+ */
611
+ onPointerMove: (0, import_web.composeEventHandlers)(props.onPointerMove, function(event) {
612
+ if (event.pointerType !== "mouse") return;
613
+ if (disabled) {
614
+ contentContext.onItemLeave(event);
615
+ } else {
616
+ contentContext.onItemEnter(event);
617
+ if (!event.defaultPrevented) {
618
+ var item = event.currentTarget;
619
+ item.focus({
620
+ preventScroll: true,
621
+ focusVisible: false
622
+ });
623
+ }
624
+ }
625
+ }),
626
+ onPointerLeave: (0, import_web.composeEventHandlers)(props.onPointerLeave, function(event) {
627
+ contentContext.onItemLeave(event);
628
+ }),
629
+ onFocus: (0, import_web.composeEventHandlers)(props.onFocus, function() {
630
+ return setIsFocused(true);
631
+ }),
632
+ onBlur: (0, import_web.composeEventHandlers)(props.onBlur, function() {
633
+ return setIsFocused(false);
634
+ })
635
+ })
636
+ })
637
+ });
638
+ });
639
+ MenuItem.displayName = ITEM_NAME;
640
+ var ITEM_TITLE_NAME = "MenuItemTitle";
641
+ var MenuItemTitle = (0, import_core.createStyledHOC)(import_web.Text, function(props, forwardedRef) {
642
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.Text, {
643
+ ...props,
644
+ ref: forwardedRef
645
+ });
646
+ });
647
+ MenuItemTitle.displayName = ITEM_TITLE_NAME;
648
+ var ITEM_SUB_TITLE_NAME = "MenuItemSubTitle";
649
+ var MenuItemSubTitle = (0, import_core.createStyledHOC)(import_web.Text, function(props, forwardedRef) {
650
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.Text, {
651
+ ...props,
652
+ ref: forwardedRef
653
+ });
654
+ });
655
+ MenuItemSubTitle.displayName = ITEM_SUB_TITLE_NAME;
656
+ var ITEM_IMAGE = "MenuItemImage";
657
+ var MenuItemImage = (0, import_core.createRefComponent)(function(props, forwardedRef) {
658
+ var { ios, androidIconName, ...rest } = props;
659
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuImageFrame, {
660
+ ...rest,
661
+ ref: forwardedRef
662
+ });
663
+ });
664
+ MenuItemImage.displayName = ITEM_IMAGE;
665
+ var ITEM_ICON = "MenuItemIcon";
666
+ var MenuItemIcon = (0, import_core.createStyledHOC)(import_web.View, function(props, forwardedRef) {
667
+ var { ios, android, androidIconName, ...rest } = props;
668
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.View, {
669
+ ...rest,
670
+ ref: forwardedRef
671
+ });
672
+ });
673
+ MenuItemIcon.displayName = ITEM_ICON;
674
+ var CHECKBOX_ITEM_NAME = "MenuCheckboxItem";
675
+ var MenuCheckboxItem = (0, import_core.createStyledHOC)(import_web.View, function(props, forwardedRef) {
676
+ var { checked = false, onCheckedChange, scope = MENU_CONTEXT, value, onValueChange, className, ...checkboxItemProps } = props;
677
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ItemIndicatorProvider, {
678
+ scope,
679
+ checked,
680
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuItem, {
681
+ className: `is_${CHECKBOX_ITEM_NAME} ${className || ""}`.trim(),
682
+ role: import_web.isWeb ? "menuitemcheckbox" : "menuitem",
683
+ "aria-checked": isIndeterminate(checked) ? "mixed" : checked,
684
+ ...checkboxItemProps,
685
+ scope,
686
+ ref: forwardedRef,
687
+ "data-state": getCheckedState(checked),
688
+ onSelect: (0, import_web.composeEventHandlers)(checkboxItemProps.onSelect, function() {
689
+ return onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(isIndeterminate(checked) ? true : !checked);
690
+ }, { checkDefaultPrevented: false })
691
+ })
692
+ });
693
+ });
694
+ MenuCheckboxItem.displayName = CHECKBOX_ITEM_NAME;
695
+ var RADIO_GROUP_NAME = "MenuRadioGroup";
696
+ var { Provider: RadioGroupProvider, useStyledContext: useRadioGroupContext } = (0, import_web.createStyledContext)();
697
+ var MenuRadioGroup = (0, import_core.createStyledHOC)(import_web.View, function(props, forwardedRef) {
698
+ var { value, onValueChange, scope = MENU_CONTEXT, className, ...groupProps } = props;
699
+ var handleValueChange = (0, import_use_callback_ref.useCallbackRef)(onValueChange);
700
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadioGroupProvider, {
701
+ scope,
702
+ value,
703
+ onValueChange: handleValueChange,
704
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.View, {
705
+ className: `is_${RADIO_GROUP_NAME} ${className || ""}`.trim(),
706
+ ...groupProps,
707
+ ref: forwardedRef
708
+ })
709
+ });
710
+ });
711
+ MenuRadioGroup.displayName = RADIO_GROUP_NAME;
712
+ var RADIO_ITEM_NAME = "MenuRadioItem";
713
+ var MenuRadioItem = (0, import_core.createStyledHOC)(import_web.View, function(props, forwardedRef) {
714
+ var { value, scope = MENU_CONTEXT, className, ...radioItemProps } = props;
715
+ var context = useRadioGroupContext(scope);
716
+ var checked = value === context.value;
717
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ItemIndicatorProvider, {
718
+ scope,
719
+ checked,
720
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuItem, {
721
+ className: `is_${RADIO_ITEM_NAME} ${className || ""}`.trim(),
722
+ ...radioItemProps,
723
+ scope,
724
+ "aria-checked": checked,
725
+ ref: forwardedRef,
726
+ role: import_web.isWeb ? "menuitemradio" : "menuitem",
727
+ "data-state": getCheckedState(checked),
728
+ onSelect: (0, import_web.composeEventHandlers)(radioItemProps.onSelect, function() {
729
+ var _context_onValueChange;
730
+ return (_context_onValueChange = context.onValueChange) === null || _context_onValueChange === void 0 ? void 0 : _context_onValueChange.call(context, value);
731
+ }, { checkDefaultPrevented: false })
732
+ })
733
+ });
734
+ });
735
+ MenuRadioItem.displayName = RADIO_ITEM_NAME;
736
+ var ITEM_INDICATOR_NAME = "MenuItemIndicator";
737
+ var { Provider: ItemIndicatorProvider, useStyledContext: useItemIndicatorContext } = (0, import_web.createStyledContext)();
738
+ var MenuItemIndicator = (0, import_core.createStyledHOC)(import_web.View, function(props, forwardedRef) {
739
+ var { scope = MENU_CONTEXT, className, forceMount, ...itemIndicatorProps } = props;
740
+ var indicatorContext = useItemIndicatorContext(scope);
741
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, { children: forceMount || isIndeterminate(indicatorContext.checked) || indicatorContext.checked === true ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.View, {
742
+ className: `is_${ITEM_INDICATOR_NAME} ${className || ""}`.trim(),
743
+ render: "span",
744
+ ...itemIndicatorProps,
745
+ ref: forwardedRef,
746
+ "data-state": getCheckedState(indicatorContext.checked)
747
+ }) : null });
748
+ });
749
+ MenuItemIndicator.displayName = ITEM_INDICATOR_NAME;
750
+ var MenuArrow = (0, import_core.createRefComponent)(function MenuArrow2(props, forwardedRef) {
751
+ var { scope = MENU_CONTEXT, className, ...rest } = props;
752
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperPrimitive.PopperArrow, {
753
+ scope,
754
+ className: `is_PopperArrow ${className || ""}`.trim(),
755
+ ...rest,
756
+ ref: forwardedRef
757
+ });
758
+ });
759
+ var SUB_NAME = "MenuSub";
760
+ var { Provider: MenuSubProvider, useStyledContext: useMenuSubContext } = (0, import_web.createStyledContext)();
761
+ var MenuSub = function(props) {
762
+ var _parentPopperContext_placement;
763
+ var isTouchDevice = (0, import_web.useIsTouchDevice)();
764
+ var { scope = MENU_CONTEXT } = props;
765
+ var rootContext = useMenuRootContext(scope);
766
+ var parentPopperContext = PopperPrimitive.usePopperContext(scope);
767
+ var parentSide = (_parentPopperContext_placement = parentPopperContext.placement) === null || _parentPopperContext_placement === void 0 ? void 0 : _parentPopperContext_placement.split("-")[0];
768
+ var isNestedSubmenu = parentSide === "left" || parentSide === "right";
769
+ var defaultPlacement = isTouchDevice ? "bottom" : isNestedSubmenu ? `${parentSide}-start` : rootContext.dir === "rtl" ? "left-start" : "right-start";
770
+ var { children, open = false, onOpenChange, allowFlip: allowFlipProp = { padding: 10 }, stayInFrame = { padding: 10 }, placement = defaultPlacement, ...rest } = props;
771
+ var allowFlip = React.useMemo(function() {
772
+ if (!isNestedSubmenu || typeof allowFlipProp === "boolean") return allowFlipProp;
773
+ if (allowFlipProp.fallbackPlacements) return allowFlipProp;
774
+ var side = placement.split("-")[0];
775
+ var align = placement.split("-")[1] || "start";
776
+ var otherAlign = align === "start" ? "end" : "start";
777
+ if (side === "left" || side === "right") {
778
+ var oppositeSide = side === "right" ? "left" : "right";
779
+ return {
780
+ ...(typeof allowFlipProp === "undefined" ? "undefined" : _type_of(allowFlipProp)) === "object" ? allowFlipProp : {},
781
+ fallbackPlacements: [
782
+ `${side}-${otherAlign}`,
783
+ `${oppositeSide}-${align}`,
784
+ `${oppositeSide}-${otherAlign}`
785
+ ]
786
+ };
787
+ }
788
+ return allowFlipProp;
789
+ }, [
790
+ isNestedSubmenu,
791
+ allowFlipProp,
792
+ placement
793
+ ]);
794
+ var parentMenuContext = useMenuContext(scope);
795
+ var [trigger, setTrigger] = React.useState(null);
796
+ var [content, setContent] = React.useState(null);
797
+ var handleOpenChange = (0, import_use_callback_ref.useCallbackRef)(onOpenChange);
798
+ React.useEffect(function() {
799
+ if (parentMenuContext.open === false) handleOpenChange(false);
800
+ return function() {
801
+ return handleOpenChange(false);
802
+ };
803
+ }, [parentMenuContext.open, handleOpenChange]);
804
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperPrimitive.Popper, {
805
+ open,
806
+ placement,
807
+ allowFlip,
808
+ stayInFrame,
809
+ ...rest,
810
+ scope,
811
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuProvider, {
812
+ scope,
813
+ open,
814
+ onOpenChange: handleOpenChange,
815
+ content,
816
+ onContentChange: setContent,
817
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuSubProvider, {
818
+ scope,
819
+ contentId: (0, import_react.useId)(),
820
+ triggerId: (0, import_react.useId)(),
821
+ trigger,
822
+ onTriggerChange: setTrigger,
823
+ children
824
+ })
825
+ })
826
+ });
827
+ };
828
+ MenuSub.displayName = SUB_NAME;
829
+ var SUB_TRIGGER_NAME = "MenuSubTrigger";
830
+ var MenuSubTrigger = (0, import_core.createRefComponent)(function(props, forwardedRef) {
831
+ var scope = props.scope || MENU_CONTEXT;
832
+ var context = useMenuContext(scope);
833
+ var rootContext = useMenuRootContext(scope);
834
+ var subContext = useMenuSubContext(scope);
835
+ var contentContext = useMenuContentContext(scope);
836
+ var popperContext = PopperPrimitive.usePopperContext(scope);
837
+ var openTimerRef = React.useRef(null);
838
+ var { pointerGraceTimerRef, onPointerGraceIntentChange } = contentContext;
839
+ var effectiveDir = rootContext.dir;
840
+ var clearOpenTimer = React.useCallback(function() {
841
+ if (openTimerRef.current) window.clearTimeout(openTimerRef.current);
842
+ openTimerRef.current = null;
843
+ }, []);
844
+ React.useEffect(function() {
845
+ return clearOpenTimer;
846
+ }, [clearOpenTimer]);
847
+ React.useEffect(function() {
848
+ var pointerGraceTimer = pointerGraceTimerRef.current;
849
+ return function() {
850
+ window.clearTimeout(pointerGraceTimer);
851
+ onPointerGraceIntentChange(null);
852
+ };
853
+ }, [pointerGraceTimerRef, onPointerGraceIntentChange]);
854
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuAnchor, {
855
+ className: `is_${SUB_TRIGGER_NAME}`,
856
+ asChild: "except-style",
857
+ scope,
858
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuItemImpl, {
859
+ id: subContext.triggerId,
860
+ "aria-haspopup": "menu",
861
+ "aria-expanded": context.open,
862
+ "aria-controls": subContext.contentId,
863
+ "data-state": getOpenState(context.open),
864
+ ...props,
865
+ ref: (0, import_web.composeRefs)(forwardedRef, subContext.onTriggerChange),
866
+ onPress: function(event) {
867
+ var _props_onPress;
868
+ (_props_onPress = props.onPress) === null || _props_onPress === void 0 ? void 0 : _props_onPress.call(props, event);
869
+ if (props.disabled || event.defaultPrevented) return;
870
+ if (import_web.isWeb) {
871
+ event.currentTarget.focus();
872
+ }
873
+ if (!context.open) context.onOpenChange(true);
874
+ },
875
+ onPointerMove: (0, import_web.composeEventHandlers)(props.onPointerMove, whenMouse(function(event) {
876
+ contentContext.onItemEnter(event);
877
+ if (event.defaultPrevented) return;
878
+ if (!props.disabled && !context.open && !openTimerRef.current) {
879
+ contentContext.onPointerGraceIntentChange(null);
880
+ openTimerRef.current = window.setTimeout(function() {
881
+ context.onOpenChange(true);
882
+ clearOpenTimer();
883
+ }, 100);
884
+ }
885
+ })),
886
+ onPointerLeave: (0, import_web.composeEventHandlers)(props.onPointerLeave, function(eventIn) {
887
+ var _context_content;
888
+ var event = eventIn;
889
+ clearOpenTimer();
890
+ var contentRect = (_context_content = context.content) === null || _context_content === void 0 ? void 0 : _context_content.getBoundingClientRect();
891
+ if (contentRect) {
892
+ var _contentEl_dataset, _sideEl_dataset;
893
+ var contentEl = context.content;
894
+ var sideEl = (contentEl === null || contentEl === void 0 ? void 0 : (_contentEl_dataset = contentEl.dataset) === null || _contentEl_dataset === void 0 ? void 0 : _contentEl_dataset.side) ? contentEl : contentEl === null || contentEl === void 0 ? void 0 : contentEl.querySelector("[data-side]");
895
+ var side = (sideEl === null || sideEl === void 0 ? void 0 : (_sideEl_dataset = sideEl.dataset) === null || _sideEl_dataset === void 0 ? void 0 : _sideEl_dataset.side) || "right";
896
+ var rightSide = side === "right";
897
+ var bleed = rightSide ? -5 : 5;
898
+ var contentNearEdge = contentRect[rightSide ? "left" : "right"];
899
+ var contentFarEdge = contentRect[rightSide ? "right" : "left"];
900
+ var polygon = {
901
+ area: [
902
+ {
903
+ x: event.clientX + bleed,
904
+ y: event.clientY
905
+ },
906
+ {
907
+ x: contentNearEdge,
908
+ y: contentRect.top
909
+ },
910
+ {
911
+ x: contentFarEdge,
912
+ y: contentRect.top
913
+ },
914
+ {
915
+ x: contentFarEdge,
916
+ y: contentRect.bottom
917
+ },
918
+ {
919
+ x: contentNearEdge,
920
+ y: contentRect.bottom
921
+ }
922
+ ],
923
+ side
924
+ };
925
+ contentContext.onPointerGraceIntentChange(polygon);
926
+ window.clearTimeout(pointerGraceTimerRef.current);
927
+ pointerGraceTimerRef.current = window.setTimeout(function() {
928
+ return contentContext.onPointerGraceIntentChange(null);
929
+ }, 300);
930
+ } else if (import_web.isWeb && subContext.trigger) {
931
+ var triggerEl = subContext.trigger;
932
+ var triggerRect = triggerEl === null || triggerEl === void 0 ? void 0 : triggerEl.getBoundingClientRect();
933
+ if (triggerRect) {
934
+ var _popperContext_placement;
935
+ var placementSide = (_popperContext_placement = popperContext.placement) === null || _popperContext_placement === void 0 ? void 0 : _popperContext_placement.split("-")[0];
936
+ var side1 = placementSide === "left" || placementSide === "right" ? placementSide : rootContext.dir === "rtl" ? "left" : "right";
937
+ var rightSide1 = side1 === "right";
938
+ var bleed1 = rightSide1 ? -5 : 5;
939
+ var nearEdge = rightSide1 ? triggerRect.right + 4 : triggerRect.left - 4;
940
+ var farEdge = rightSide1 ? nearEdge + 200 : nearEdge - 200;
941
+ var polygon1 = {
942
+ area: [
943
+ {
944
+ x: event.clientX + bleed1,
945
+ y: event.clientY
946
+ },
947
+ {
948
+ x: nearEdge,
949
+ y: triggerRect.top - 50
950
+ },
951
+ {
952
+ x: farEdge,
953
+ y: triggerRect.top - 50
954
+ },
955
+ {
956
+ x: farEdge,
957
+ y: triggerRect.bottom + 50
958
+ },
959
+ {
960
+ x: nearEdge,
961
+ y: triggerRect.bottom + 50
962
+ }
963
+ ],
964
+ side: side1
965
+ };
966
+ contentContext.onPointerGraceIntentChange(polygon1);
967
+ window.clearTimeout(pointerGraceTimerRef.current);
968
+ pointerGraceTimerRef.current = window.setTimeout(function() {
969
+ return contentContext.onPointerGraceIntentChange(null);
970
+ }, 300);
971
+ }
972
+ } else {
973
+ contentContext.onTriggerLeave(event);
974
+ if (event.defaultPrevented) return;
975
+ contentContext.onPointerGraceIntentChange(null);
976
+ }
977
+ }),
978
+ ...import_web.isWeb ? { onKeyDown: (0, import_web.composeEventHandlers)(props.onKeyDown, function(event) {
979
+ var isTypingAhead = contentContext.searchRef.current !== "";
980
+ if (props.disabled || isTypingAhead && event.key === " ") return;
981
+ var willOpen = SUB_OPEN_KEYS[effectiveDir].includes(event.key);
982
+ if (willOpen) {
983
+ var _popperContext_refs, _context_content;
984
+ if (context.open && context.content) {
985
+ var _contentEl_querySelector;
986
+ var contentEl = context.content;
987
+ var firstItem = (_contentEl_querySelector = contentEl.querySelector) === null || _contentEl_querySelector === void 0 ? void 0 : _contentEl_querySelector.call(contentEl, "[role=\"menuitem\"]:not([data-disabled])");
988
+ if (firstItem) {
989
+ firstItem.focus({ focusVisible: true });
990
+ event.preventDefault();
991
+ return;
992
+ }
993
+ }
994
+ var triggerEl = event.currentTarget;
995
+ (_popperContext_refs = popperContext.refs) === null || _popperContext_refs === void 0 ? void 0 : _popperContext_refs.setReference(triggerEl);
996
+ context.onOpenChange(true);
997
+ requestAnimationFrame(function() {
998
+ var _popperContext_update;
999
+ (_popperContext_update = popperContext.update) === null || _popperContext_update === void 0 ? void 0 : _popperContext_update.call(popperContext);
1000
+ });
1001
+ (_context_content = context.content) === null || _context_content === void 0 ? void 0 : _context_content.focus({ focusVisible: true });
1002
+ event.preventDefault();
1003
+ }
1004
+ }) } : null
1005
+ })
1006
+ });
1007
+ });
1008
+ MenuSubTrigger.displayName = SUB_TRIGGER_NAME;
1009
+ var SUB_CONTENT_NAME = "MenuSubContent";
1010
+ var MenuSubContentFrame = (0, import_web.styled)(PopperPrimitive.PopperContentFrame, { displayName: SUB_CONTENT_NAME });
1011
+ var MenuSubContent = (0, import_core.createStyledHOC)(MenuSubContentFrame, function(props, forwardedRef) {
1012
+ var _popperContext_placement;
1013
+ var scope = props.scope || MENU_CONTEXT;
1014
+ var portalContext = usePortalContext(scope);
1015
+ var { forceMount = portalContext.forceMount, ...subContentProps } = props;
1016
+ var context = useMenuContext(scope);
1017
+ var rootContext = useMenuRootContext(scope);
1018
+ var subContext = useMenuSubContext(scope);
1019
+ var popperContext = PopperPrimitive.usePopperContext(scope);
1020
+ var ref = React.useRef(null);
1021
+ var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref);
1022
+ var placementSide = (_popperContext_placement = popperContext.placement) === null || _popperContext_placement === void 0 ? void 0 : _popperContext_placement.split("-")[0];
1023
+ var dataSide = placementSide === "left" || placementSide === "right" ? placementSide : rootContext.dir === "rtl" ? "left" : "right";
1024
+ var effectiveDir = rootContext.dir;
1025
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Provider, {
1026
+ scope,
1027
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Slot, {
1028
+ scope,
1029
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuContentImpl, {
1030
+ id: subContext.contentId,
1031
+ "aria-labelledby": subContext.triggerId,
1032
+ ...subContentProps,
1033
+ ref: composedRefs,
1034
+ "data-side": dataSide,
1035
+ disableOutsidePointerEvents: false,
1036
+ disableOutsideScroll: false,
1037
+ trapFocus: false,
1038
+ onOpenAutoFocus: function(event) {
1039
+ if (rootContext.isUsingKeyboardRef.current) {
1040
+ var _root_querySelector, _this;
1041
+ var root = ref.current;
1042
+ var content = root === null || root === void 0 ? void 0 : (_root_querySelector = root.querySelector) === null || _root_querySelector === void 0 ? void 0 : _root_querySelector.call(root, "[data-tamagui-menu-content]");
1043
+ (_this = content || root) === null || _this === void 0 ? void 0 : _this.focus({ preventScroll: true });
1044
+ }
1045
+ event.cancel();
1046
+ },
1047
+ onCloseAutoFocus: function(event) {
1048
+ return event.cancel();
1049
+ },
1050
+ onFocusOutside: (0, import_web.composeEventHandlers)(props.onFocusOutside, function(event) {
1051
+ var _event_event;
1052
+ if (((_event_event = event.event) === null || _event_event === void 0 ? void 0 : _event_event.target) !== subContext.trigger) context.onOpenChange(false);
1053
+ }),
1054
+ onEscapeKeyDown: (0, import_web.composeEventHandlers)(props.onEscapeKeyDown, function(event) {
1055
+ var _subContext_trigger, _event_event_preventDefault, _event_event;
1056
+ context.onOpenChange(false);
1057
+ (_subContext_trigger = subContext.trigger) === null || _subContext_trigger === void 0 ? void 0 : _subContext_trigger.focus({ focusVisible: true });
1058
+ event.cancel();
1059
+ (_event_event = event.event) === null || _event_event === void 0 ? void 0 : (_event_event_preventDefault = _event_event.preventDefault) === null || _event_event_preventDefault === void 0 ? void 0 : _event_event_preventDefault.call(_event_event);
1060
+ }),
1061
+ ...import_web.isWeb ? { onKeyDown: (0, import_web.composeEventHandlers)(props.onKeyDown, function(event) {
1062
+ var isKeyDownInside = event.currentTarget.contains(event.target);
1063
+ var isCloseKey = SUB_CLOSE_KEYS[effectiveDir].includes(event.key);
1064
+ if (isKeyDownInside && isCloseKey) {
1065
+ var _subContext_trigger;
1066
+ context.onOpenChange(false);
1067
+ (_subContext_trigger = subContext.trigger) === null || _subContext_trigger === void 0 ? void 0 : _subContext_trigger.focus({ focusVisible: true });
1068
+ event.preventDefault();
1069
+ }
1070
+ }) } : null
1071
+ })
1072
+ })
1073
+ });
1074
+ });
1075
+ MenuSubContent.displayName = SUB_CONTENT_NAME;
1076
+ var Anchor = MenuAnchor;
1077
+ var Portal = MenuPortal;
1078
+ var Content = MenuContent;
1079
+ var Group = (0, import_core.createStyledHOC)(import_web.View, function(props, ref) {
1080
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.View, {
1081
+ role: "group",
1082
+ ...props,
1083
+ ref
1084
+ });
1085
+ });
1086
+ Group.displayName = "MenuGroup";
1087
+ var Label = (0, import_core.createStyledHOC)(import_web.Text, function(props, ref) {
1088
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.Text, {
1089
+ ...props,
1090
+ ref
1091
+ });
1092
+ });
1093
+ Label.displayName = "MenuLabel";
1094
+ var Item = MenuItem;
1095
+ var CheckboxItem = MenuCheckboxItem;
1096
+ var RadioGroup = MenuRadioGroup;
1097
+ var RadioItem = MenuRadioItem;
1098
+ var ItemIndicator = MenuItemIndicator;
1099
+ var Separator = (0, import_core.createStyledHOC)(import_web.View, function(props, ref) {
1100
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.View, {
1101
+ role: "separator",
1102
+ "aria-orientation": "horizontal",
1103
+ ...props,
1104
+ ref
1105
+ });
1106
+ });
1107
+ Separator.displayName = "MenuSeparator";
1108
+ var Arrow = MenuArrow;
1109
+ var Sub = MenuSub;
1110
+ var SubTrigger = MenuSubTrigger;
1111
+ var SubContent = MenuSubContent;
1112
+ var ItemTitle = MenuItemTitle;
1113
+ var ItemSubtitle = MenuItemSubTitle;
1114
+ var ItemImage = MenuItemImage;
1115
+ var ItemIcon = MenuItemIcon;
1116
+ var Menu = (0, import_web.withStaticProperties)(MenuComp, {
1117
+ Anchor,
1118
+ Portal,
1119
+ Content,
1120
+ Group,
1121
+ Label,
1122
+ Item,
1123
+ CheckboxItem,
1124
+ RadioGroup,
1125
+ RadioItem,
1126
+ ItemIndicator,
1127
+ Separator,
1128
+ Arrow,
1129
+ Sub,
1130
+ SubTrigger,
1131
+ SubContent,
1132
+ ItemTitle,
1133
+ ItemSubtitle,
1134
+ ItemImage,
1135
+ ItemIcon
1136
+ });
1137
+ return { Menu };
1366
1138
  }
1367
1139
  function getOpenState(open) {
1368
- return open ? "open" : "closed";
1140
+ return open ? "open" : "closed";
1369
1141
  }
1370
1142
  function isIndeterminate(checked) {
1371
- return checked === "indeterminate";
1143
+ return checked === "indeterminate";
1372
1144
  }
1373
1145
  function getCheckedState(checked) {
1374
- return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
1146
+ return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
1375
1147
  }
1376
1148
  function focusFirst(candidates, options) {
1377
- var PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
1378
- var _iteratorNormalCompletion = true,
1379
- _didIteratorError = false,
1380
- _iteratorError = void 0;
1381
- try {
1382
- for (var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
1383
- var candidate = _step.value;
1384
- if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
1385
- candidate.focus({
1386
- preventScroll: true,
1387
- focusVisible: options === null || options === void 0 ? void 0 : options.focusVisible
1388
- });
1389
- if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
1390
- }
1391
- } catch (err) {
1392
- _didIteratorError = true;
1393
- _iteratorError = err;
1394
- } finally {
1395
- try {
1396
- if (!_iteratorNormalCompletion && _iterator.return != null) {
1397
- _iterator.return();
1398
- }
1399
- } finally {
1400
- if (_didIteratorError) {
1401
- throw _iteratorError;
1402
- }
1403
- }
1404
- }
1149
+ var PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
1150
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1151
+ try {
1152
+ for (var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
1153
+ var candidate = _step.value;
1154
+ if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
1155
+ candidate.focus({
1156
+ preventScroll: true,
1157
+ focusVisible: options === null || options === void 0 ? void 0 : options.focusVisible
1158
+ });
1159
+ if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
1160
+ }
1161
+ } catch (err) {
1162
+ _didIteratorError = true;
1163
+ _iteratorError = err;
1164
+ } finally {
1165
+ try {
1166
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1167
+ _iterator.return();
1168
+ }
1169
+ } finally {
1170
+ if (_didIteratorError) {
1171
+ throw _iteratorError;
1172
+ }
1173
+ }
1174
+ }
1405
1175
  }
1406
1176
  function wrapArray(array, startIndex) {
1407
- return array.map(function (_, index) {
1408
- return array[(startIndex + index) % array.length];
1409
- });
1177
+ return array.map(function(_, index) {
1178
+ return array[(startIndex + index) % array.length];
1179
+ });
1410
1180
  }
1411
1181
  function getNextMatch(values, search, currentMatch) {
1412
- var isRepeated = search.length > 1 && Array.from(search).every(function (char) {
1413
- return char === search[0];
1414
- });
1415
- var normalizedSearch = isRepeated ? search[0] : search;
1416
- var currentMatchIndex = currentMatch ? values.indexOf(currentMatch) : -1;
1417
- var wrappedValues = wrapArray(values, Math.max(currentMatchIndex, 0));
1418
- var excludeCurrentMatch = normalizedSearch.length === 1;
1419
- if (excludeCurrentMatch) wrappedValues = wrappedValues.filter(function (v) {
1420
- return v !== currentMatch;
1421
- });
1422
- var nextMatch = wrappedValues.find(function (value) {
1423
- return value.toLowerCase().startsWith(normalizedSearch.toLowerCase());
1424
- });
1425
- return nextMatch !== currentMatch ? nextMatch : void 0;
1182
+ var isRepeated = search.length > 1 && Array.from(search).every(function(char) {
1183
+ return char === search[0];
1184
+ });
1185
+ var normalizedSearch = isRepeated ? search[0] : search;
1186
+ var currentMatchIndex = currentMatch ? values.indexOf(currentMatch) : -1;
1187
+ var wrappedValues = wrapArray(values, Math.max(currentMatchIndex, 0));
1188
+ var excludeCurrentMatch = normalizedSearch.length === 1;
1189
+ if (excludeCurrentMatch) wrappedValues = wrappedValues.filter(function(v) {
1190
+ return v !== currentMatch;
1191
+ });
1192
+ var nextMatch = wrappedValues.find(function(value) {
1193
+ return value.toLowerCase().startsWith(normalizedSearch.toLowerCase());
1194
+ });
1195
+ return nextMatch !== currentMatch ? nextMatch : void 0;
1426
1196
  }
1427
1197
  function isPointInPolygon(point, polygon) {
1428
- var {
1429
- x,
1430
- y
1431
- } = point;
1432
- var inside = false;
1433
- for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
1434
- var xi = polygon[i].x;
1435
- var yi = polygon[i].y;
1436
- var xj = polygon[j].x;
1437
- var yj = polygon[j].y;
1438
- var intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
1439
- if (intersect) inside = !inside;
1440
- }
1441
- return inside;
1198
+ var { x, y } = point;
1199
+ var inside = false;
1200
+ for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
1201
+ var xi = polygon[i].x;
1202
+ var yi = polygon[i].y;
1203
+ var xj = polygon[j].x;
1204
+ var yj = polygon[j].y;
1205
+ var intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
1206
+ if (intersect) inside = !inside;
1207
+ }
1208
+ return inside;
1442
1209
  }
1443
1210
  function isPointerInGraceArea(event, area) {
1444
- if (!area) return false;
1445
- var cursorPos = {
1446
- x: event.clientX,
1447
- y: event.clientY
1448
- };
1449
- return isPointInPolygon(cursorPos, area);
1211
+ if (!area) return false;
1212
+ var cursorPos = {
1213
+ x: event.clientX,
1214
+ y: event.clientY
1215
+ };
1216
+ return isPointInPolygon(cursorPos, area);
1450
1217
  }
1218
+
1451
1219
  //# sourceMappingURL=createBaseMenu.native.js.map