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