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