@tamagui/create-menu 2.0.0-rc.8 → 2.0.0

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