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