@tamagui/create-menu 2.0.0-rc.4 → 2.0.0-rc.40

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