@xsolla/xui-context-menu 0.187.3 → 0.188.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/native/index.d.mts +11 -2
- package/native/index.d.ts +11 -2
- package/native/index.js +224 -152
- package/native/index.js.map +1 -1
- package/native/index.mjs +233 -157
- package/native/index.mjs.map +1 -1
- package/package.json +10 -10
- package/web/index.d.mts +11 -2
- package/web/index.d.ts +11 -2
- package/web/index.js +224 -152
- package/web/index.js.map +1 -1
- package/web/index.mjs +233 -157
- package/web/index.mjs.map +1 -1
package/web/index.d.ts
CHANGED
|
@@ -58,10 +58,20 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
|
|
|
58
58
|
onSelect?: () => void;
|
|
59
59
|
onCheckedChange?: (checked: boolean) => void;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* A search cell rendered at the top of the menu. When `searchable` is set on the
|
|
63
|
+
* panel this cell is auto-rendered and stays mounted even when the query matches
|
|
64
|
+
* nothing, so the user can clear it without reopening the menu. A trailing clear
|
|
65
|
+
* (×) button appears whenever the field has a value; pressing it empties the
|
|
66
|
+
* query (fires `onValueChange("")`) and refocuses the input.
|
|
67
|
+
*/
|
|
61
68
|
interface ContextMenuSearchItemProps extends ContextMenuItemBaseProps {
|
|
62
69
|
type: "search";
|
|
70
|
+
/** Controlled value of the search input. */
|
|
63
71
|
value?: string;
|
|
72
|
+
/** Raw change event; fires alongside `onValueChange`. */
|
|
64
73
|
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
74
|
+
/** Change callback with the next string value. Also invoked with `""` when the clear button is pressed. */
|
|
65
75
|
onValueChange?: (value: string) => void;
|
|
66
76
|
placeholder?: string;
|
|
67
77
|
autoFocus?: boolean;
|
|
@@ -186,7 +196,6 @@ declare const useContextMenuRequired: () => ContextMenuContextValue;
|
|
|
186
196
|
interface UseContextMenuPositionOptions {
|
|
187
197
|
triggerRef: RefObject<HTMLElement | null>;
|
|
188
198
|
panelRef: RefObject<HTMLElement | null>;
|
|
189
|
-
containerRef: RefObject<HTMLElement | null>;
|
|
190
199
|
isOpen: boolean;
|
|
191
200
|
placement?: ContextMenuPlacement;
|
|
192
201
|
offset?: number;
|
|
@@ -196,6 +205,6 @@ interface ResolvedPosition {
|
|
|
196
205
|
left: number;
|
|
197
206
|
placement: ContextMenuPlacement;
|
|
198
207
|
}
|
|
199
|
-
declare const useContextMenuPosition: ({ triggerRef, panelRef,
|
|
208
|
+
declare const useContextMenuPosition: ({ triggerRef, panelRef, isOpen, placement, offset, }: UseContextMenuPositionOptions) => ResolvedPosition | undefined;
|
|
200
209
|
|
|
201
210
|
export { ContextMenu, ContextMenuContext, type ContextMenuContextValue, type ContextMenuDividerItemProps, type ContextMenuHeadingItemProps, ContextMenuItem, type ContextMenuItemProps, type ContextMenuOptionItemProps, type ContextMenuPlacement, type ContextMenuPosition, type ContextMenuPresetType, type ContextMenuProps, type ContextMenuSearchItemProps, type ContextMenuSize, type ContextMenuSizing, ContextMenuSubmenu, type ContextMenuSubmenuProps, useContextMenu, useContextMenuPosition, useContextMenuRequired, useKeyboardNavigation };
|
package/web/index.js
CHANGED
|
@@ -42,7 +42,8 @@ __export(index_exports, {
|
|
|
42
42
|
module.exports = __toCommonJS(index_exports);
|
|
43
43
|
|
|
44
44
|
// src/ContextMenu.tsx
|
|
45
|
-
var import_react8 = require("react");
|
|
45
|
+
var import_react8 = __toESM(require("react"));
|
|
46
|
+
var import_react_dom3 = require("react-dom");
|
|
46
47
|
|
|
47
48
|
// ../../foundation/primitives-web/src/Box.tsx
|
|
48
49
|
var import_react2 = __toESM(require("react"));
|
|
@@ -907,6 +908,19 @@ var SearchCell = ({
|
|
|
907
908
|
registerCell(id, { type: "search" });
|
|
908
909
|
return () => unregisterCell(id);
|
|
909
910
|
}, [registerCell, unregisterCell, id]);
|
|
911
|
+
const inputRef = import_react4.default.useRef(null);
|
|
912
|
+
const hasValue = (value ?? "") !== "";
|
|
913
|
+
const handleClear = () => {
|
|
914
|
+
onValueChange?.("");
|
|
915
|
+
if (onChange && inputRef.current) {
|
|
916
|
+
inputRef.current.value = "";
|
|
917
|
+
onChange({
|
|
918
|
+
target: inputRef.current,
|
|
919
|
+
currentTarget: inputRef.current
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
inputRef.current?.focus();
|
|
923
|
+
};
|
|
910
924
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
911
925
|
"div",
|
|
912
926
|
{
|
|
@@ -940,7 +954,8 @@ var SearchCell = ({
|
|
|
940
954
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
941
955
|
"input",
|
|
942
956
|
{
|
|
943
|
-
|
|
957
|
+
ref: inputRef,
|
|
958
|
+
type: "text",
|
|
944
959
|
role: "searchbox",
|
|
945
960
|
"aria-label": ariaLabel,
|
|
946
961
|
placeholder,
|
|
@@ -964,6 +979,37 @@ var SearchCell = ({
|
|
|
964
979
|
lineHeight: `${sizing.searchLineHeight}px`
|
|
965
980
|
}
|
|
966
981
|
}
|
|
982
|
+
),
|
|
983
|
+
hasValue && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
984
|
+
"button",
|
|
985
|
+
{
|
|
986
|
+
type: "button",
|
|
987
|
+
"aria-label": "Clear search",
|
|
988
|
+
"data-testid": "ctxmenu-search-clear",
|
|
989
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
990
|
+
onClick: handleClear,
|
|
991
|
+
style: {
|
|
992
|
+
display: "inline-flex",
|
|
993
|
+
alignItems: "center",
|
|
994
|
+
justifyContent: "center",
|
|
995
|
+
flexShrink: 0,
|
|
996
|
+
padding: 0,
|
|
997
|
+
margin: 0,
|
|
998
|
+
border: "none",
|
|
999
|
+
background: "transparent",
|
|
1000
|
+
cursor: "pointer",
|
|
1001
|
+
color: theme.colors.control.input.placeholder
|
|
1002
|
+
},
|
|
1003
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1004
|
+
import_xui_icons_base.Remove,
|
|
1005
|
+
{
|
|
1006
|
+
variant: "line",
|
|
1007
|
+
size: sizing.searchIconSize,
|
|
1008
|
+
color: theme.colors.control.input.placeholder,
|
|
1009
|
+
"aria-hidden": true
|
|
1010
|
+
}
|
|
1011
|
+
)
|
|
1012
|
+
}
|
|
967
1013
|
)
|
|
968
1014
|
]
|
|
969
1015
|
}
|
|
@@ -1002,9 +1048,11 @@ var DividerCell = ({ themeMode, themeProductContext, "data-testid": testId }) =>
|
|
|
1002
1048
|
|
|
1003
1049
|
// src/ContextMenuSubmenu.tsx
|
|
1004
1050
|
var import_react5 = require("react");
|
|
1051
|
+
var import_react_dom2 = require("react-dom");
|
|
1005
1052
|
var import_xui_core2 = require("@xsolla/xui-core");
|
|
1006
1053
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1007
1054
|
var SUBMENU_GAP2 = 4;
|
|
1055
|
+
var VIEWPORT_PADDING = 8;
|
|
1008
1056
|
var OPEN_DELAY_MS = 200;
|
|
1009
1057
|
var CLOSE_GRACE_MS = 100;
|
|
1010
1058
|
var _submenuIdCounter = 0;
|
|
@@ -1018,6 +1066,7 @@ var ContextMenuSubmenu = ({
|
|
|
1018
1066
|
}) => {
|
|
1019
1067
|
const { theme } = (0, import_xui_core2.useDesignSystem)();
|
|
1020
1068
|
const xuiTheme = theme;
|
|
1069
|
+
const overlayLayer = (0, import_xui_core2.useOverlayLayer)();
|
|
1021
1070
|
const context = useContextMenu();
|
|
1022
1071
|
const size = propSize || context?.size || "md";
|
|
1023
1072
|
const sizeStyles = xuiTheme.sizing.contextMenu(size);
|
|
@@ -1030,7 +1079,7 @@ var ContextMenuSubmenu = ({
|
|
|
1030
1079
|
const [isOpen, setIsOpen] = (0, import_react5.useState)(false);
|
|
1031
1080
|
const [visible, setVisible] = (0, import_react5.useState)(false);
|
|
1032
1081
|
const [openLeft, setOpenLeft] = (0, import_react5.useState)(false);
|
|
1033
|
-
const [
|
|
1082
|
+
const [pos, setPos] = (0, import_react5.useState)(null);
|
|
1034
1083
|
const triggerRef = (0, import_react5.useRef)(null);
|
|
1035
1084
|
const submenuRef = (0, import_react5.useRef)(null);
|
|
1036
1085
|
const openTimerRef = (0, import_react5.useRef)(null);
|
|
@@ -1045,43 +1094,44 @@ var ContextMenuSubmenu = ({
|
|
|
1045
1094
|
setIsOpen(false);
|
|
1046
1095
|
}
|
|
1047
1096
|
}, [context?.activeSubmenuId, submenuId]);
|
|
1048
|
-
const calculatePlacement = (0, import_react5.useCallback)(() => {
|
|
1049
|
-
if (!triggerRef.current) return;
|
|
1050
|
-
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
1051
|
-
const estimatedWidth = sizeStyles.minWidth + 32;
|
|
1052
|
-
const wouldOverflowRight = triggerRect.right + estimatedWidth + SUBMENU_GAP2 > window.innerWidth - 8;
|
|
1053
|
-
const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - estimatedWidth >= 8;
|
|
1054
|
-
setOpenLeft(wouldOverflowRight && hasSpaceOnLeft);
|
|
1055
|
-
setTopOffset(0);
|
|
1056
|
-
}, [sizeStyles.minWidth]);
|
|
1057
1097
|
(0, import_react5.useLayoutEffect)(() => {
|
|
1058
|
-
if (!isOpen
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
const wouldOverflowRight = triggerRect.right + submenuRect.width + SUBMENU_GAP2 > window.innerWidth - 8;
|
|
1062
|
-
const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - submenuRect.width >= 8;
|
|
1063
|
-
setOpenLeft(wouldOverflowRight && hasSpaceOnLeft);
|
|
1064
|
-
const overflowBottom = triggerRect.top + submenuRect.height - (window.innerHeight - 8);
|
|
1065
|
-
if (overflowBottom > 0) {
|
|
1066
|
-
setTopOffset(-Math.min(overflowBottom, triggerRect.top - 8));
|
|
1067
|
-
} else {
|
|
1068
|
-
setTopOffset(0);
|
|
1098
|
+
if (!isOpen) {
|
|
1099
|
+
setPos(null);
|
|
1100
|
+
return;
|
|
1069
1101
|
}
|
|
1102
|
+
const compute = () => {
|
|
1103
|
+
const trigger = triggerRef.current;
|
|
1104
|
+
const panel = submenuRef.current;
|
|
1105
|
+
if (!trigger || !panel) return;
|
|
1106
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
1107
|
+
const submenuRect = panel.getBoundingClientRect();
|
|
1108
|
+
const wouldOverflowRight = triggerRect.right + submenuRect.width + SUBMENU_GAP2 > window.innerWidth - VIEWPORT_PADDING;
|
|
1109
|
+
const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - submenuRect.width >= VIEWPORT_PADDING;
|
|
1110
|
+
const nextOpenLeft = wouldOverflowRight && hasSpaceOnLeft;
|
|
1111
|
+
setOpenLeft(nextOpenLeft);
|
|
1112
|
+
const left = nextOpenLeft ? triggerRect.left - SUBMENU_GAP2 - submenuRect.width : triggerRect.right + SUBMENU_GAP2;
|
|
1113
|
+
const overflowBottom = triggerRect.top + submenuRect.height - (window.innerHeight - VIEWPORT_PADDING);
|
|
1114
|
+
const top = overflowBottom > 0 ? triggerRect.top - Math.min(overflowBottom, triggerRect.top - VIEWPORT_PADDING) : triggerRect.top;
|
|
1115
|
+
setPos({ left, top });
|
|
1116
|
+
};
|
|
1117
|
+
compute();
|
|
1118
|
+
const onResize = () => compute();
|
|
1119
|
+
window.addEventListener("resize", onResize);
|
|
1120
|
+
return () => window.removeEventListener("resize", onResize);
|
|
1070
1121
|
}, [isOpen]);
|
|
1071
1122
|
(0, import_react5.useEffect)(() => {
|
|
1072
|
-
if (!isOpen) {
|
|
1123
|
+
if (!isOpen || !pos) {
|
|
1073
1124
|
setVisible(false);
|
|
1074
1125
|
return;
|
|
1075
1126
|
}
|
|
1076
1127
|
const raf = requestAnimationFrame(() => setVisible(true));
|
|
1077
1128
|
return () => cancelAnimationFrame(raf);
|
|
1078
|
-
}, [isOpen]);
|
|
1129
|
+
}, [isOpen, pos]);
|
|
1079
1130
|
(0, import_react5.useEffect)(() => () => clearTimers(), [clearTimers]);
|
|
1080
1131
|
const handleTriggerEnter = () => {
|
|
1081
1132
|
if (disabled) return;
|
|
1082
1133
|
clearTimers();
|
|
1083
1134
|
openTimerRef.current = setTimeout(() => {
|
|
1084
|
-
calculatePlacement();
|
|
1085
1135
|
setIsOpen(true);
|
|
1086
1136
|
context?.setActiveSubmenuId(submenuId);
|
|
1087
1137
|
}, OPEN_DELAY_MS);
|
|
@@ -1105,7 +1155,47 @@ var ContextMenuSubmenu = ({
|
|
|
1105
1155
|
}
|
|
1106
1156
|
}, CLOSE_GRACE_MS);
|
|
1107
1157
|
};
|
|
1108
|
-
const
|
|
1158
|
+
const submenuPanel = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1159
|
+
"div",
|
|
1160
|
+
{
|
|
1161
|
+
ref: submenuRef,
|
|
1162
|
+
"data-xui-context-menu-portal": submenuId,
|
|
1163
|
+
"data-xui-context-menu-owner": context?.menuId,
|
|
1164
|
+
onMouseEnter: handleSubmenuEnter,
|
|
1165
|
+
onMouseLeave: handleSubmenuLeave,
|
|
1166
|
+
style: {
|
|
1167
|
+
position: "fixed",
|
|
1168
|
+
left: pos ? pos.left : 0,
|
|
1169
|
+
top: pos ? pos.top : 0,
|
|
1170
|
+
// Hidden until measured to avoid a flash at (0,0).
|
|
1171
|
+
visibility: pos ? "visible" : "hidden",
|
|
1172
|
+
// One step above the parent panel. The overlay-layer context flows
|
|
1173
|
+
// through the portal, so a submenu inside a modal stays above panel and
|
|
1174
|
+
// modal; nested submenus tie and DOM order resolves the stack.
|
|
1175
|
+
zIndex: overlayLayer + import_xui_core2.LAYER_OFFSET.menu + 1,
|
|
1176
|
+
opacity: visible ? 1 : 0,
|
|
1177
|
+
transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
|
|
1178
|
+
transition: "opacity 100ms ease, transform 100ms ease"
|
|
1179
|
+
},
|
|
1180
|
+
"data-testid": `${testId}-content`,
|
|
1181
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1182
|
+
Box,
|
|
1183
|
+
{
|
|
1184
|
+
role: "menu",
|
|
1185
|
+
backgroundColor: xuiTheme.colors.background.secondary,
|
|
1186
|
+
borderColor: xuiTheme.colors.border.secondary,
|
|
1187
|
+
borderWidth: 1,
|
|
1188
|
+
borderRadius,
|
|
1189
|
+
paddingVertical: sizeStyles.paddingVertical,
|
|
1190
|
+
style: {
|
|
1191
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
|
|
1192
|
+
minWidth: sizeStyles.minWidth
|
|
1193
|
+
},
|
|
1194
|
+
children
|
|
1195
|
+
}
|
|
1196
|
+
)
|
|
1197
|
+
}
|
|
1198
|
+
);
|
|
1109
1199
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1110
1200
|
"div",
|
|
1111
1201
|
{
|
|
@@ -1127,40 +1217,7 @@ var ContextMenuSubmenu = ({
|
|
|
1127
1217
|
"data-testid": `${testId}-trigger`
|
|
1128
1218
|
}
|
|
1129
1219
|
),
|
|
1130
|
-
isOpen &&
|
|
1131
|
-
"div",
|
|
1132
|
-
{
|
|
1133
|
-
ref: submenuRef,
|
|
1134
|
-
onMouseEnter: handleSubmenuEnter,
|
|
1135
|
-
onMouseLeave: handleSubmenuLeave,
|
|
1136
|
-
style: {
|
|
1137
|
-
position: "absolute",
|
|
1138
|
-
top: topOffset,
|
|
1139
|
-
...submenuPositionStyle,
|
|
1140
|
-
zIndex: 1001,
|
|
1141
|
-
opacity: visible ? 1 : 0,
|
|
1142
|
-
transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
|
|
1143
|
-
transition: "opacity 100ms ease, transform 100ms ease"
|
|
1144
|
-
},
|
|
1145
|
-
"data-testid": `${testId}-content`,
|
|
1146
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1147
|
-
Box,
|
|
1148
|
-
{
|
|
1149
|
-
role: "menu",
|
|
1150
|
-
backgroundColor: xuiTheme.colors.background.secondary,
|
|
1151
|
-
borderColor: xuiTheme.colors.border.secondary,
|
|
1152
|
-
borderWidth: 1,
|
|
1153
|
-
borderRadius,
|
|
1154
|
-
paddingVertical: sizeStyles.paddingVertical,
|
|
1155
|
-
style: {
|
|
1156
|
-
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
|
|
1157
|
-
minWidth: sizeStyles.minWidth
|
|
1158
|
-
},
|
|
1159
|
-
children
|
|
1160
|
-
}
|
|
1161
|
-
)
|
|
1162
|
-
}
|
|
1163
|
-
)
|
|
1220
|
+
isOpen && typeof document !== "undefined" ? (0, import_react_dom2.createPortal)(submenuPanel, document.body) : null
|
|
1164
1221
|
]
|
|
1165
1222
|
}
|
|
1166
1223
|
);
|
|
@@ -1177,7 +1234,6 @@ var joinPlacement = (vertical, horizontal) => `${vertical}-${horizontal}`;
|
|
|
1177
1234
|
var useContextMenuPosition = ({
|
|
1178
1235
|
triggerRef,
|
|
1179
1236
|
panelRef,
|
|
1180
|
-
containerRef,
|
|
1181
1237
|
isOpen,
|
|
1182
1238
|
placement = "bottom-start",
|
|
1183
1239
|
offset = 4
|
|
@@ -1191,7 +1247,6 @@ var useContextMenuPosition = ({
|
|
|
1191
1247
|
const compute = () => {
|
|
1192
1248
|
const trigger = triggerRef.current;
|
|
1193
1249
|
const panel = panelRef.current;
|
|
1194
|
-
const container = containerRef.current;
|
|
1195
1250
|
if (!trigger || !panel) return;
|
|
1196
1251
|
const triggerRect = trigger.getBoundingClientRect();
|
|
1197
1252
|
const panelRect = panel.getBoundingClientRect();
|
|
@@ -1231,15 +1286,6 @@ var useContextMenuPosition = ({
|
|
|
1231
1286
|
}
|
|
1232
1287
|
}
|
|
1233
1288
|
}
|
|
1234
|
-
if (container) {
|
|
1235
|
-
const containerRect = container.getBoundingClientRect();
|
|
1236
|
-
const cOffsetW = container.offsetWidth;
|
|
1237
|
-
const cOffsetH = container.offsetHeight;
|
|
1238
|
-
const scaleX = cOffsetW > 0 ? containerRect.width / cOffsetW : 1;
|
|
1239
|
-
const scaleY = cOffsetH > 0 ? containerRect.height / cOffsetH : 1;
|
|
1240
|
-
left = (left - containerRect.left) / (scaleX || 1);
|
|
1241
|
-
top = (top - containerRect.top) / (scaleY || 1);
|
|
1242
|
-
}
|
|
1243
1289
|
const next = {
|
|
1244
1290
|
top,
|
|
1245
1291
|
left,
|
|
@@ -1255,7 +1301,7 @@ var useContextMenuPosition = ({
|
|
|
1255
1301
|
return () => {
|
|
1256
1302
|
window.removeEventListener("resize", onResize);
|
|
1257
1303
|
};
|
|
1258
|
-
}, [isOpen, placement, offset, triggerRef, panelRef
|
|
1304
|
+
}, [isOpen, placement, offset, triggerRef, panelRef]);
|
|
1259
1305
|
return resolved;
|
|
1260
1306
|
};
|
|
1261
1307
|
|
|
@@ -1389,7 +1435,8 @@ var ARROW_HALF = ARROW_SIZE / 2;
|
|
|
1389
1435
|
var ARROW_EDGE_OFFSET = 12;
|
|
1390
1436
|
var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
|
|
1391
1437
|
var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
|
|
1392
|
-
var
|
|
1438
|
+
var DROPDOWN_LAYER_SELECTOR = '[data-modal-id],[role="listbox"]';
|
|
1439
|
+
var ownLayerSelector = (menuId) => `${DROPDOWN_LAYER_SELECTOR},[data-xui-context-menu-portal="${menuId}"],[data-xui-context-menu-owner="${menuId}"]`;
|
|
1393
1440
|
var textFromNode = (node) => {
|
|
1394
1441
|
if (node === null || node === void 0 || typeof node === "boolean")
|
|
1395
1442
|
return "";
|
|
@@ -1481,7 +1528,6 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1481
1528
|
const positioned = useContextMenuPosition({
|
|
1482
1529
|
triggerRef,
|
|
1483
1530
|
panelRef,
|
|
1484
|
-
containerRef,
|
|
1485
1531
|
isOpen: isOpen && !!trigger && !position,
|
|
1486
1532
|
placement,
|
|
1487
1533
|
offset: positionOffset
|
|
@@ -1594,10 +1640,11 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1594
1640
|
const target = event.target;
|
|
1595
1641
|
if (!target) return;
|
|
1596
1642
|
if (containerRef.current?.contains(target)) return;
|
|
1643
|
+
const selector = ownLayerSelector(menuId);
|
|
1597
1644
|
const path = typeof event.composedPath === "function" ? event.composedPath() : [];
|
|
1598
1645
|
const isInsidePortaledLayer = path.length ? path.some(
|
|
1599
|
-
(node) => node instanceof Element && node.matches(
|
|
1600
|
-
) : target instanceof Element && !!target.closest(
|
|
1646
|
+
(node) => node instanceof Element && node.matches(selector)
|
|
1647
|
+
) : target instanceof Element && !!target.closest(selector);
|
|
1601
1648
|
if (isInsidePortaledLayer) return;
|
|
1602
1649
|
closeMenu();
|
|
1603
1650
|
};
|
|
@@ -1608,7 +1655,7 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1608
1655
|
document.removeEventListener("mousedown", onMouseDown);
|
|
1609
1656
|
window.removeEventListener("scroll", onScroll);
|
|
1610
1657
|
};
|
|
1611
|
-
}, [isOpen, trigger, closeMenu]);
|
|
1658
|
+
}, [isOpen, trigger, closeMenu, menuId]);
|
|
1612
1659
|
(0, import_react8.useLayoutEffect)(() => {
|
|
1613
1660
|
if (!isOpen || !panelRef.current) return;
|
|
1614
1661
|
const searchbox = panelRef.current.querySelector('[role="searchbox"]');
|
|
@@ -1693,6 +1740,31 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1693
1740
|
);
|
|
1694
1741
|
};
|
|
1695
1742
|
const renderedItems = searchable ? filterItems(items, debouncedQuery) : [...items];
|
|
1743
|
+
const searchHeader = searchable ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1744
|
+
"div",
|
|
1745
|
+
{
|
|
1746
|
+
"data-sticky": "top",
|
|
1747
|
+
style: {
|
|
1748
|
+
position: "sticky",
|
|
1749
|
+
top: 0,
|
|
1750
|
+
zIndex: 1,
|
|
1751
|
+
backgroundColor: xuiTheme.colors.background.secondary
|
|
1752
|
+
},
|
|
1753
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1754
|
+
ContextMenuItem,
|
|
1755
|
+
{
|
|
1756
|
+
type: "search",
|
|
1757
|
+
value: query,
|
|
1758
|
+
onValueChange: setQuery,
|
|
1759
|
+
placeholder: "Search",
|
|
1760
|
+
autoFocus: true,
|
|
1761
|
+
themeMode,
|
|
1762
|
+
themeProductContext
|
|
1763
|
+
}
|
|
1764
|
+
)
|
|
1765
|
+
},
|
|
1766
|
+
"context-menu-search"
|
|
1767
|
+
) : null;
|
|
1696
1768
|
const renderContent = () => {
|
|
1697
1769
|
if (loading || isLoading || type === "loading") {
|
|
1698
1770
|
const brandColor = xuiTheme.colors.control.brand.primary.bg;
|
|
@@ -1708,38 +1780,28 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1708
1780
|
);
|
|
1709
1781
|
}
|
|
1710
1782
|
if (children) return children;
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
position: "sticky",
|
|
1720
|
-
top: 0,
|
|
1721
|
-
zIndex: 1,
|
|
1722
|
-
backgroundColor: xuiTheme.colors.background.secondary
|
|
1723
|
-
},
|
|
1724
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1725
|
-
ContextMenuItem,
|
|
1726
|
-
{
|
|
1727
|
-
type: "search",
|
|
1728
|
-
value: query,
|
|
1729
|
-
onValueChange: setQuery,
|
|
1730
|
-
placeholder: "Search",
|
|
1731
|
-
autoFocus: true,
|
|
1732
|
-
themeMode,
|
|
1733
|
-
themeProductContext
|
|
1734
|
-
}
|
|
1735
|
-
)
|
|
1783
|
+
if (renderedItems.length === 0) {
|
|
1784
|
+
const emptyNode = empty ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1785
|
+
"div",
|
|
1786
|
+
{
|
|
1787
|
+
style: {
|
|
1788
|
+
padding: 16,
|
|
1789
|
+
textAlign: "center",
|
|
1790
|
+
color: xuiTheme.colors.content.tertiary
|
|
1736
1791
|
},
|
|
1737
|
-
|
|
1738
|
-
|
|
1792
|
+
children: emptyMessage
|
|
1793
|
+
},
|
|
1794
|
+
"context-menu-empty"
|
|
1739
1795
|
);
|
|
1796
|
+
if (!searchHeader) return emptyNode;
|
|
1797
|
+
return [
|
|
1798
|
+
searchHeader,
|
|
1799
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react8.default.Fragment, { children: emptyNode }, "context-menu-empty")
|
|
1800
|
+
];
|
|
1740
1801
|
}
|
|
1741
|
-
|
|
1742
|
-
|
|
1802
|
+
const content = renderedItems.map(renderPresetItem);
|
|
1803
|
+
if (searchHeader) content.unshift(searchHeader);
|
|
1804
|
+
return content;
|
|
1743
1805
|
};
|
|
1744
1806
|
const assignPanelRef = (node) => {
|
|
1745
1807
|
panelRef.current = node;
|
|
@@ -1792,11 +1854,11 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1792
1854
|
left: position.x,
|
|
1793
1855
|
top: position.y
|
|
1794
1856
|
} : trigger ? positioned ? {
|
|
1795
|
-
position: "
|
|
1857
|
+
position: "fixed",
|
|
1796
1858
|
left: positioned.left,
|
|
1797
1859
|
top: positioned.top
|
|
1798
1860
|
} : {
|
|
1799
|
-
position: "
|
|
1861
|
+
position: "fixed",
|
|
1800
1862
|
visibility: "hidden"
|
|
1801
1863
|
} : void 0;
|
|
1802
1864
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ContextMenuContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
@@ -1809,50 +1871,60 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1809
1871
|
},
|
|
1810
1872
|
children: [
|
|
1811
1873
|
triggerNode,
|
|
1812
|
-
isOpen &&
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1874
|
+
isOpen && (() => {
|
|
1875
|
+
const panelNode = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1876
|
+
Box,
|
|
1877
|
+
{
|
|
1878
|
+
ref: assignPanelRef,
|
|
1879
|
+
role: "menu",
|
|
1880
|
+
"aria-label": ariaLabel,
|
|
1881
|
+
"data-testid": dataTestId ?? testID ?? "context-menu",
|
|
1882
|
+
"data-xui-context-menu-portal": trigger || position ? menuId : void 0,
|
|
1883
|
+
"data-placement": resolvedPlacement,
|
|
1884
|
+
backgroundColor: xuiTheme.colors.background.secondary,
|
|
1885
|
+
borderColor: xuiTheme.colors.border.secondary,
|
|
1886
|
+
borderWidth: 1,
|
|
1887
|
+
borderRadius,
|
|
1888
|
+
paddingVertical: sizeStyles.paddingVertical,
|
|
1889
|
+
width,
|
|
1890
|
+
minWidth: sizeStyles.minWidth,
|
|
1891
|
+
tabIndex: -1,
|
|
1892
|
+
onKeyDown: keyboard.handleKeyDown,
|
|
1893
|
+
onMouseLeave: () => setActiveIndex(-1),
|
|
1894
|
+
style: {
|
|
1895
|
+
...positionStyle,
|
|
1896
|
+
...style,
|
|
1897
|
+
zIndex: overlayLayer + import_xui_core3.LAYER_OFFSET.menu,
|
|
1898
|
+
boxShadow: PANEL_SHADOW,
|
|
1899
|
+
...withArrow ? {
|
|
1900
|
+
overflow: "visible"
|
|
1901
|
+
} : {
|
|
1902
|
+
maxHeight,
|
|
1903
|
+
overflowY: "auto"
|
|
1904
|
+
},
|
|
1905
|
+
outline: "none"
|
|
1840
1906
|
},
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1907
|
+
children: withArrow ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1908
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1909
|
+
"span",
|
|
1910
|
+
{
|
|
1911
|
+
"aria-hidden": "true",
|
|
1912
|
+
"data-testid": "context-menu-arrow",
|
|
1913
|
+
style: getArrowStyle(resolvedPlacement)
|
|
1914
|
+
}
|
|
1915
|
+
),
|
|
1916
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1917
|
+
"div",
|
|
1918
|
+
{
|
|
1919
|
+
style: { maxHeight, overflowY: "auto", borderRadius },
|
|
1920
|
+
children: renderContent()
|
|
1921
|
+
}
|
|
1922
|
+
)
|
|
1923
|
+
] }) : renderContent()
|
|
1924
|
+
}
|
|
1925
|
+
);
|
|
1926
|
+
return trigger || position ? typeof document !== "undefined" ? (0, import_react_dom3.createPortal)(panelNode, document.body) : null : panelNode;
|
|
1927
|
+
})()
|
|
1856
1928
|
]
|
|
1857
1929
|
}
|
|
1858
1930
|
) });
|