@xsolla/xui-context-menu 0.187.2 → 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.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/ContextMenu.tsx
|
|
2
|
-
import {
|
|
2
|
+
import React5, {
|
|
3
3
|
cloneElement,
|
|
4
4
|
forwardRef,
|
|
5
5
|
isValidElement,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
useRef as useRef2,
|
|
11
11
|
useState as useState4
|
|
12
12
|
} from "react";
|
|
13
|
+
import { createPortal as createPortal3 } from "react-dom";
|
|
13
14
|
|
|
14
15
|
// ../../foundation/primitives-web/src/Box.tsx
|
|
15
16
|
import React2 from "react";
|
|
@@ -266,8 +267,8 @@ Box.displayName = "Box";
|
|
|
266
267
|
import {
|
|
267
268
|
useResolvedTheme as useResolvedTheme2,
|
|
268
269
|
useId as useId2,
|
|
269
|
-
useOverlayLayer as
|
|
270
|
-
LAYER_OFFSET as
|
|
270
|
+
useOverlayLayer as useOverlayLayer3,
|
|
271
|
+
LAYER_OFFSET as LAYER_OFFSET3,
|
|
271
272
|
useModalStackDepth
|
|
272
273
|
} from "@xsolla/xui-core";
|
|
273
274
|
import { Spinner } from "@xsolla/xui-spinner";
|
|
@@ -301,7 +302,7 @@ import {
|
|
|
301
302
|
import { Typography } from "@xsolla/xui-typography";
|
|
302
303
|
import { Checkbox } from "@xsolla/xui-checkbox";
|
|
303
304
|
import { Radio } from "@xsolla/xui-radio";
|
|
304
|
-
import { Search } from "@xsolla/xui-icons-base";
|
|
305
|
+
import { Search, Remove } from "@xsolla/xui-icons-base";
|
|
305
306
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
306
307
|
var sizeToVariants = {
|
|
307
308
|
xl: { label: "bodyLg", description: "bodyLg", headingAccent: "bodyLgAccent" },
|
|
@@ -885,6 +886,19 @@ var SearchCell = ({
|
|
|
885
886
|
registerCell(id, { type: "search" });
|
|
886
887
|
return () => unregisterCell(id);
|
|
887
888
|
}, [registerCell, unregisterCell, id]);
|
|
889
|
+
const inputRef = React3.useRef(null);
|
|
890
|
+
const hasValue = (value ?? "") !== "";
|
|
891
|
+
const handleClear = () => {
|
|
892
|
+
onValueChange?.("");
|
|
893
|
+
if (onChange && inputRef.current) {
|
|
894
|
+
inputRef.current.value = "";
|
|
895
|
+
onChange({
|
|
896
|
+
target: inputRef.current,
|
|
897
|
+
currentTarget: inputRef.current
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
inputRef.current?.focus();
|
|
901
|
+
};
|
|
888
902
|
return /* @__PURE__ */ jsx2(
|
|
889
903
|
"div",
|
|
890
904
|
{
|
|
@@ -918,7 +932,8 @@ var SearchCell = ({
|
|
|
918
932
|
/* @__PURE__ */ jsx2(
|
|
919
933
|
"input",
|
|
920
934
|
{
|
|
921
|
-
|
|
935
|
+
ref: inputRef,
|
|
936
|
+
type: "text",
|
|
922
937
|
role: "searchbox",
|
|
923
938
|
"aria-label": ariaLabel,
|
|
924
939
|
placeholder,
|
|
@@ -942,6 +957,37 @@ var SearchCell = ({
|
|
|
942
957
|
lineHeight: `${sizing.searchLineHeight}px`
|
|
943
958
|
}
|
|
944
959
|
}
|
|
960
|
+
),
|
|
961
|
+
hasValue && /* @__PURE__ */ jsx2(
|
|
962
|
+
"button",
|
|
963
|
+
{
|
|
964
|
+
type: "button",
|
|
965
|
+
"aria-label": "Clear search",
|
|
966
|
+
"data-testid": "ctxmenu-search-clear",
|
|
967
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
968
|
+
onClick: handleClear,
|
|
969
|
+
style: {
|
|
970
|
+
display: "inline-flex",
|
|
971
|
+
alignItems: "center",
|
|
972
|
+
justifyContent: "center",
|
|
973
|
+
flexShrink: 0,
|
|
974
|
+
padding: 0,
|
|
975
|
+
margin: 0,
|
|
976
|
+
border: "none",
|
|
977
|
+
background: "transparent",
|
|
978
|
+
cursor: "pointer",
|
|
979
|
+
color: theme.colors.control.input.placeholder
|
|
980
|
+
},
|
|
981
|
+
children: /* @__PURE__ */ jsx2(
|
|
982
|
+
Remove,
|
|
983
|
+
{
|
|
984
|
+
variant: "line",
|
|
985
|
+
size: sizing.searchIconSize,
|
|
986
|
+
color: theme.colors.control.input.placeholder,
|
|
987
|
+
"aria-hidden": true
|
|
988
|
+
}
|
|
989
|
+
)
|
|
990
|
+
}
|
|
945
991
|
)
|
|
946
992
|
]
|
|
947
993
|
}
|
|
@@ -986,9 +1032,15 @@ import {
|
|
|
986
1032
|
useLayoutEffect as useLayoutEffect2,
|
|
987
1033
|
useCallback
|
|
988
1034
|
} from "react";
|
|
989
|
-
import {
|
|
1035
|
+
import { createPortal as createPortal2 } from "react-dom";
|
|
1036
|
+
import {
|
|
1037
|
+
useDesignSystem,
|
|
1038
|
+
useOverlayLayer as useOverlayLayer2,
|
|
1039
|
+
LAYER_OFFSET as LAYER_OFFSET2
|
|
1040
|
+
} from "@xsolla/xui-core";
|
|
990
1041
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
991
1042
|
var SUBMENU_GAP2 = 4;
|
|
1043
|
+
var VIEWPORT_PADDING = 8;
|
|
992
1044
|
var OPEN_DELAY_MS = 200;
|
|
993
1045
|
var CLOSE_GRACE_MS = 100;
|
|
994
1046
|
var _submenuIdCounter = 0;
|
|
@@ -1002,6 +1054,7 @@ var ContextMenuSubmenu = ({
|
|
|
1002
1054
|
}) => {
|
|
1003
1055
|
const { theme } = useDesignSystem();
|
|
1004
1056
|
const xuiTheme = theme;
|
|
1057
|
+
const overlayLayer = useOverlayLayer2();
|
|
1005
1058
|
const context = useContextMenu();
|
|
1006
1059
|
const size = propSize || context?.size || "md";
|
|
1007
1060
|
const sizeStyles = xuiTheme.sizing.contextMenu(size);
|
|
@@ -1014,7 +1067,7 @@ var ContextMenuSubmenu = ({
|
|
|
1014
1067
|
const [isOpen, setIsOpen] = useState2(false);
|
|
1015
1068
|
const [visible, setVisible] = useState2(false);
|
|
1016
1069
|
const [openLeft, setOpenLeft] = useState2(false);
|
|
1017
|
-
const [
|
|
1070
|
+
const [pos, setPos] = useState2(null);
|
|
1018
1071
|
const triggerRef = useRef(null);
|
|
1019
1072
|
const submenuRef = useRef(null);
|
|
1020
1073
|
const openTimerRef = useRef(null);
|
|
@@ -1029,43 +1082,44 @@ var ContextMenuSubmenu = ({
|
|
|
1029
1082
|
setIsOpen(false);
|
|
1030
1083
|
}
|
|
1031
1084
|
}, [context?.activeSubmenuId, submenuId]);
|
|
1032
|
-
const calculatePlacement = useCallback(() => {
|
|
1033
|
-
if (!triggerRef.current) return;
|
|
1034
|
-
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
1035
|
-
const estimatedWidth = sizeStyles.minWidth + 32;
|
|
1036
|
-
const wouldOverflowRight = triggerRect.right + estimatedWidth + SUBMENU_GAP2 > window.innerWidth - 8;
|
|
1037
|
-
const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - estimatedWidth >= 8;
|
|
1038
|
-
setOpenLeft(wouldOverflowRight && hasSpaceOnLeft);
|
|
1039
|
-
setTopOffset(0);
|
|
1040
|
-
}, [sizeStyles.minWidth]);
|
|
1041
1085
|
useLayoutEffect2(() => {
|
|
1042
|
-
if (!isOpen
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
const wouldOverflowRight = triggerRect.right + submenuRect.width + SUBMENU_GAP2 > window.innerWidth - 8;
|
|
1046
|
-
const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - submenuRect.width >= 8;
|
|
1047
|
-
setOpenLeft(wouldOverflowRight && hasSpaceOnLeft);
|
|
1048
|
-
const overflowBottom = triggerRect.top + submenuRect.height - (window.innerHeight - 8);
|
|
1049
|
-
if (overflowBottom > 0) {
|
|
1050
|
-
setTopOffset(-Math.min(overflowBottom, triggerRect.top - 8));
|
|
1051
|
-
} else {
|
|
1052
|
-
setTopOffset(0);
|
|
1086
|
+
if (!isOpen) {
|
|
1087
|
+
setPos(null);
|
|
1088
|
+
return;
|
|
1053
1089
|
}
|
|
1090
|
+
const compute = () => {
|
|
1091
|
+
const trigger = triggerRef.current;
|
|
1092
|
+
const panel = submenuRef.current;
|
|
1093
|
+
if (!trigger || !panel) return;
|
|
1094
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
1095
|
+
const submenuRect = panel.getBoundingClientRect();
|
|
1096
|
+
const wouldOverflowRight = triggerRect.right + submenuRect.width + SUBMENU_GAP2 > window.innerWidth - VIEWPORT_PADDING;
|
|
1097
|
+
const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - submenuRect.width >= VIEWPORT_PADDING;
|
|
1098
|
+
const nextOpenLeft = wouldOverflowRight && hasSpaceOnLeft;
|
|
1099
|
+
setOpenLeft(nextOpenLeft);
|
|
1100
|
+
const left = nextOpenLeft ? triggerRect.left - SUBMENU_GAP2 - submenuRect.width : triggerRect.right + SUBMENU_GAP2;
|
|
1101
|
+
const overflowBottom = triggerRect.top + submenuRect.height - (window.innerHeight - VIEWPORT_PADDING);
|
|
1102
|
+
const top = overflowBottom > 0 ? triggerRect.top - Math.min(overflowBottom, triggerRect.top - VIEWPORT_PADDING) : triggerRect.top;
|
|
1103
|
+
setPos({ left, top });
|
|
1104
|
+
};
|
|
1105
|
+
compute();
|
|
1106
|
+
const onResize = () => compute();
|
|
1107
|
+
window.addEventListener("resize", onResize);
|
|
1108
|
+
return () => window.removeEventListener("resize", onResize);
|
|
1054
1109
|
}, [isOpen]);
|
|
1055
1110
|
useEffect2(() => {
|
|
1056
|
-
if (!isOpen) {
|
|
1111
|
+
if (!isOpen || !pos) {
|
|
1057
1112
|
setVisible(false);
|
|
1058
1113
|
return;
|
|
1059
1114
|
}
|
|
1060
1115
|
const raf = requestAnimationFrame(() => setVisible(true));
|
|
1061
1116
|
return () => cancelAnimationFrame(raf);
|
|
1062
|
-
}, [isOpen]);
|
|
1117
|
+
}, [isOpen, pos]);
|
|
1063
1118
|
useEffect2(() => () => clearTimers(), [clearTimers]);
|
|
1064
1119
|
const handleTriggerEnter = () => {
|
|
1065
1120
|
if (disabled) return;
|
|
1066
1121
|
clearTimers();
|
|
1067
1122
|
openTimerRef.current = setTimeout(() => {
|
|
1068
|
-
calculatePlacement();
|
|
1069
1123
|
setIsOpen(true);
|
|
1070
1124
|
context?.setActiveSubmenuId(submenuId);
|
|
1071
1125
|
}, OPEN_DELAY_MS);
|
|
@@ -1089,7 +1143,47 @@ var ContextMenuSubmenu = ({
|
|
|
1089
1143
|
}
|
|
1090
1144
|
}, CLOSE_GRACE_MS);
|
|
1091
1145
|
};
|
|
1092
|
-
const
|
|
1146
|
+
const submenuPanel = /* @__PURE__ */ jsx3(
|
|
1147
|
+
"div",
|
|
1148
|
+
{
|
|
1149
|
+
ref: submenuRef,
|
|
1150
|
+
"data-xui-context-menu-portal": submenuId,
|
|
1151
|
+
"data-xui-context-menu-owner": context?.menuId,
|
|
1152
|
+
onMouseEnter: handleSubmenuEnter,
|
|
1153
|
+
onMouseLeave: handleSubmenuLeave,
|
|
1154
|
+
style: {
|
|
1155
|
+
position: "fixed",
|
|
1156
|
+
left: pos ? pos.left : 0,
|
|
1157
|
+
top: pos ? pos.top : 0,
|
|
1158
|
+
// Hidden until measured to avoid a flash at (0,0).
|
|
1159
|
+
visibility: pos ? "visible" : "hidden",
|
|
1160
|
+
// One step above the parent panel. The overlay-layer context flows
|
|
1161
|
+
// through the portal, so a submenu inside a modal stays above panel and
|
|
1162
|
+
// modal; nested submenus tie and DOM order resolves the stack.
|
|
1163
|
+
zIndex: overlayLayer + LAYER_OFFSET2.menu + 1,
|
|
1164
|
+
opacity: visible ? 1 : 0,
|
|
1165
|
+
transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
|
|
1166
|
+
transition: "opacity 100ms ease, transform 100ms ease"
|
|
1167
|
+
},
|
|
1168
|
+
"data-testid": `${testId}-content`,
|
|
1169
|
+
children: /* @__PURE__ */ jsx3(
|
|
1170
|
+
Box,
|
|
1171
|
+
{
|
|
1172
|
+
role: "menu",
|
|
1173
|
+
backgroundColor: xuiTheme.colors.background.secondary,
|
|
1174
|
+
borderColor: xuiTheme.colors.border.secondary,
|
|
1175
|
+
borderWidth: 1,
|
|
1176
|
+
borderRadius,
|
|
1177
|
+
paddingVertical: sizeStyles.paddingVertical,
|
|
1178
|
+
style: {
|
|
1179
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
|
|
1180
|
+
minWidth: sizeStyles.minWidth
|
|
1181
|
+
},
|
|
1182
|
+
children
|
|
1183
|
+
}
|
|
1184
|
+
)
|
|
1185
|
+
}
|
|
1186
|
+
);
|
|
1093
1187
|
return /* @__PURE__ */ jsxs2(
|
|
1094
1188
|
"div",
|
|
1095
1189
|
{
|
|
@@ -1111,40 +1205,7 @@ var ContextMenuSubmenu = ({
|
|
|
1111
1205
|
"data-testid": `${testId}-trigger`
|
|
1112
1206
|
}
|
|
1113
1207
|
),
|
|
1114
|
-
isOpen &&
|
|
1115
|
-
"div",
|
|
1116
|
-
{
|
|
1117
|
-
ref: submenuRef,
|
|
1118
|
-
onMouseEnter: handleSubmenuEnter,
|
|
1119
|
-
onMouseLeave: handleSubmenuLeave,
|
|
1120
|
-
style: {
|
|
1121
|
-
position: "absolute",
|
|
1122
|
-
top: topOffset,
|
|
1123
|
-
...submenuPositionStyle,
|
|
1124
|
-
zIndex: 1001,
|
|
1125
|
-
opacity: visible ? 1 : 0,
|
|
1126
|
-
transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
|
|
1127
|
-
transition: "opacity 100ms ease, transform 100ms ease"
|
|
1128
|
-
},
|
|
1129
|
-
"data-testid": `${testId}-content`,
|
|
1130
|
-
children: /* @__PURE__ */ jsx3(
|
|
1131
|
-
Box,
|
|
1132
|
-
{
|
|
1133
|
-
role: "menu",
|
|
1134
|
-
backgroundColor: xuiTheme.colors.background.secondary,
|
|
1135
|
-
borderColor: xuiTheme.colors.border.secondary,
|
|
1136
|
-
borderWidth: 1,
|
|
1137
|
-
borderRadius,
|
|
1138
|
-
paddingVertical: sizeStyles.paddingVertical,
|
|
1139
|
-
style: {
|
|
1140
|
-
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
|
|
1141
|
-
minWidth: sizeStyles.minWidth
|
|
1142
|
-
},
|
|
1143
|
-
children
|
|
1144
|
-
}
|
|
1145
|
-
)
|
|
1146
|
-
}
|
|
1147
|
-
)
|
|
1208
|
+
isOpen && typeof document !== "undefined" ? createPortal2(submenuPanel, document.body) : null
|
|
1148
1209
|
]
|
|
1149
1210
|
}
|
|
1150
1211
|
);
|
|
@@ -1161,7 +1222,6 @@ var joinPlacement = (vertical, horizontal) => `${vertical}-${horizontal}`;
|
|
|
1161
1222
|
var useContextMenuPosition = ({
|
|
1162
1223
|
triggerRef,
|
|
1163
1224
|
panelRef,
|
|
1164
|
-
containerRef,
|
|
1165
1225
|
isOpen,
|
|
1166
1226
|
placement = "bottom-start",
|
|
1167
1227
|
offset = 4
|
|
@@ -1175,7 +1235,6 @@ var useContextMenuPosition = ({
|
|
|
1175
1235
|
const compute = () => {
|
|
1176
1236
|
const trigger = triggerRef.current;
|
|
1177
1237
|
const panel = panelRef.current;
|
|
1178
|
-
const container = containerRef.current;
|
|
1179
1238
|
if (!trigger || !panel) return;
|
|
1180
1239
|
const triggerRect = trigger.getBoundingClientRect();
|
|
1181
1240
|
const panelRect = panel.getBoundingClientRect();
|
|
@@ -1215,15 +1274,6 @@ var useContextMenuPosition = ({
|
|
|
1215
1274
|
}
|
|
1216
1275
|
}
|
|
1217
1276
|
}
|
|
1218
|
-
if (container) {
|
|
1219
|
-
const containerRect = container.getBoundingClientRect();
|
|
1220
|
-
const cOffsetW = container.offsetWidth;
|
|
1221
|
-
const cOffsetH = container.offsetHeight;
|
|
1222
|
-
const scaleX = cOffsetW > 0 ? containerRect.width / cOffsetW : 1;
|
|
1223
|
-
const scaleY = cOffsetH > 0 ? containerRect.height / cOffsetH : 1;
|
|
1224
|
-
left = (left - containerRect.left) / (scaleX || 1);
|
|
1225
|
-
top = (top - containerRect.top) / (scaleY || 1);
|
|
1226
|
-
}
|
|
1227
1277
|
const next = {
|
|
1228
1278
|
top,
|
|
1229
1279
|
left,
|
|
@@ -1239,7 +1289,7 @@ var useContextMenuPosition = ({
|
|
|
1239
1289
|
return () => {
|
|
1240
1290
|
window.removeEventListener("resize", onResize);
|
|
1241
1291
|
};
|
|
1242
|
-
}, [isOpen, placement, offset, triggerRef, panelRef
|
|
1292
|
+
}, [isOpen, placement, offset, triggerRef, panelRef]);
|
|
1243
1293
|
return resolved;
|
|
1244
1294
|
};
|
|
1245
1295
|
|
|
@@ -1373,7 +1423,8 @@ var ARROW_HALF = ARROW_SIZE / 2;
|
|
|
1373
1423
|
var ARROW_EDGE_OFFSET = 12;
|
|
1374
1424
|
var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
|
|
1375
1425
|
var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
|
|
1376
|
-
var
|
|
1426
|
+
var DROPDOWN_LAYER_SELECTOR = '[data-modal-id],[role="listbox"]';
|
|
1427
|
+
var ownLayerSelector = (menuId) => `${DROPDOWN_LAYER_SELECTOR},[data-xui-context-menu-portal="${menuId}"],[data-xui-context-menu-owner="${menuId}"]`;
|
|
1377
1428
|
var textFromNode = (node) => {
|
|
1378
1429
|
if (node === null || node === void 0 || typeof node === "boolean")
|
|
1379
1430
|
return "";
|
|
@@ -1444,7 +1495,7 @@ var ContextMenuRoot = forwardRef(
|
|
|
1444
1495
|
});
|
|
1445
1496
|
const xuiTheme = rawTheme;
|
|
1446
1497
|
const menuId = useId2();
|
|
1447
|
-
const overlayLayer =
|
|
1498
|
+
const overlayLayer = useOverlayLayer3();
|
|
1448
1499
|
const modalStackDepth = useModalStackDepth();
|
|
1449
1500
|
const openModalDepthRef = useRef2(null);
|
|
1450
1501
|
const [internalIsOpen, setInternalIsOpen] = useState4(false);
|
|
@@ -1465,7 +1516,6 @@ var ContextMenuRoot = forwardRef(
|
|
|
1465
1516
|
const positioned = useContextMenuPosition({
|
|
1466
1517
|
triggerRef,
|
|
1467
1518
|
panelRef,
|
|
1468
|
-
containerRef,
|
|
1469
1519
|
isOpen: isOpen && !!trigger && !position,
|
|
1470
1520
|
placement,
|
|
1471
1521
|
offset: positionOffset
|
|
@@ -1578,10 +1628,11 @@ var ContextMenuRoot = forwardRef(
|
|
|
1578
1628
|
const target = event.target;
|
|
1579
1629
|
if (!target) return;
|
|
1580
1630
|
if (containerRef.current?.contains(target)) return;
|
|
1631
|
+
const selector = ownLayerSelector(menuId);
|
|
1581
1632
|
const path = typeof event.composedPath === "function" ? event.composedPath() : [];
|
|
1582
1633
|
const isInsidePortaledLayer = path.length ? path.some(
|
|
1583
|
-
(node) => node instanceof Element && node.matches(
|
|
1584
|
-
) : target instanceof Element && !!target.closest(
|
|
1634
|
+
(node) => node instanceof Element && node.matches(selector)
|
|
1635
|
+
) : target instanceof Element && !!target.closest(selector);
|
|
1585
1636
|
if (isInsidePortaledLayer) return;
|
|
1586
1637
|
closeMenu();
|
|
1587
1638
|
};
|
|
@@ -1592,7 +1643,7 @@ var ContextMenuRoot = forwardRef(
|
|
|
1592
1643
|
document.removeEventListener("mousedown", onMouseDown);
|
|
1593
1644
|
window.removeEventListener("scroll", onScroll);
|
|
1594
1645
|
};
|
|
1595
|
-
}, [isOpen, trigger, closeMenu]);
|
|
1646
|
+
}, [isOpen, trigger, closeMenu, menuId]);
|
|
1596
1647
|
useLayoutEffect4(() => {
|
|
1597
1648
|
if (!isOpen || !panelRef.current) return;
|
|
1598
1649
|
const searchbox = panelRef.current.querySelector('[role="searchbox"]');
|
|
@@ -1677,6 +1728,31 @@ var ContextMenuRoot = forwardRef(
|
|
|
1677
1728
|
);
|
|
1678
1729
|
};
|
|
1679
1730
|
const renderedItems = searchable ? filterItems(items, debouncedQuery) : [...items];
|
|
1731
|
+
const searchHeader = searchable ? /* @__PURE__ */ jsx4(
|
|
1732
|
+
"div",
|
|
1733
|
+
{
|
|
1734
|
+
"data-sticky": "top",
|
|
1735
|
+
style: {
|
|
1736
|
+
position: "sticky",
|
|
1737
|
+
top: 0,
|
|
1738
|
+
zIndex: 1,
|
|
1739
|
+
backgroundColor: xuiTheme.colors.background.secondary
|
|
1740
|
+
},
|
|
1741
|
+
children: /* @__PURE__ */ jsx4(
|
|
1742
|
+
ContextMenuItem,
|
|
1743
|
+
{
|
|
1744
|
+
type: "search",
|
|
1745
|
+
value: query,
|
|
1746
|
+
onValueChange: setQuery,
|
|
1747
|
+
placeholder: "Search",
|
|
1748
|
+
autoFocus: true,
|
|
1749
|
+
themeMode,
|
|
1750
|
+
themeProductContext
|
|
1751
|
+
}
|
|
1752
|
+
)
|
|
1753
|
+
},
|
|
1754
|
+
"context-menu-search"
|
|
1755
|
+
) : null;
|
|
1680
1756
|
const renderContent = () => {
|
|
1681
1757
|
if (loading || isLoading || type === "loading") {
|
|
1682
1758
|
const brandColor = xuiTheme.colors.control.brand.primary.bg;
|
|
@@ -1692,38 +1768,28 @@ var ContextMenuRoot = forwardRef(
|
|
|
1692
1768
|
);
|
|
1693
1769
|
}
|
|
1694
1770
|
if (children) return children;
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
position: "sticky",
|
|
1704
|
-
top: 0,
|
|
1705
|
-
zIndex: 1,
|
|
1706
|
-
backgroundColor: xuiTheme.colors.background.secondary
|
|
1707
|
-
},
|
|
1708
|
-
children: /* @__PURE__ */ jsx4(
|
|
1709
|
-
ContextMenuItem,
|
|
1710
|
-
{
|
|
1711
|
-
type: "search",
|
|
1712
|
-
value: query,
|
|
1713
|
-
onValueChange: setQuery,
|
|
1714
|
-
placeholder: "Search",
|
|
1715
|
-
autoFocus: true,
|
|
1716
|
-
themeMode,
|
|
1717
|
-
themeProductContext
|
|
1718
|
-
}
|
|
1719
|
-
)
|
|
1771
|
+
if (renderedItems.length === 0) {
|
|
1772
|
+
const emptyNode = empty ?? /* @__PURE__ */ jsx4(
|
|
1773
|
+
"div",
|
|
1774
|
+
{
|
|
1775
|
+
style: {
|
|
1776
|
+
padding: 16,
|
|
1777
|
+
textAlign: "center",
|
|
1778
|
+
color: xuiTheme.colors.content.tertiary
|
|
1720
1779
|
},
|
|
1721
|
-
|
|
1722
|
-
|
|
1780
|
+
children: emptyMessage
|
|
1781
|
+
},
|
|
1782
|
+
"context-menu-empty"
|
|
1723
1783
|
);
|
|
1784
|
+
if (!searchHeader) return emptyNode;
|
|
1785
|
+
return [
|
|
1786
|
+
searchHeader,
|
|
1787
|
+
/* @__PURE__ */ jsx4(React5.Fragment, { children: emptyNode }, "context-menu-empty")
|
|
1788
|
+
];
|
|
1724
1789
|
}
|
|
1725
|
-
|
|
1726
|
-
|
|
1790
|
+
const content = renderedItems.map(renderPresetItem);
|
|
1791
|
+
if (searchHeader) content.unshift(searchHeader);
|
|
1792
|
+
return content;
|
|
1727
1793
|
};
|
|
1728
1794
|
const assignPanelRef = (node) => {
|
|
1729
1795
|
panelRef.current = node;
|
|
@@ -1776,11 +1842,11 @@ var ContextMenuRoot = forwardRef(
|
|
|
1776
1842
|
left: position.x,
|
|
1777
1843
|
top: position.y
|
|
1778
1844
|
} : trigger ? positioned ? {
|
|
1779
|
-
position: "
|
|
1845
|
+
position: "fixed",
|
|
1780
1846
|
left: positioned.left,
|
|
1781
1847
|
top: positioned.top
|
|
1782
1848
|
} : {
|
|
1783
|
-
position: "
|
|
1849
|
+
position: "fixed",
|
|
1784
1850
|
visibility: "hidden"
|
|
1785
1851
|
} : void 0;
|
|
1786
1852
|
return /* @__PURE__ */ jsx4(ContextMenuContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs3(
|
|
@@ -1793,50 +1859,60 @@ var ContextMenuRoot = forwardRef(
|
|
|
1793
1859
|
},
|
|
1794
1860
|
children: [
|
|
1795
1861
|
triggerNode,
|
|
1796
|
-
isOpen &&
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1862
|
+
isOpen && (() => {
|
|
1863
|
+
const panelNode = /* @__PURE__ */ jsx4(
|
|
1864
|
+
Box,
|
|
1865
|
+
{
|
|
1866
|
+
ref: assignPanelRef,
|
|
1867
|
+
role: "menu",
|
|
1868
|
+
"aria-label": ariaLabel,
|
|
1869
|
+
"data-testid": dataTestId ?? testID ?? "context-menu",
|
|
1870
|
+
"data-xui-context-menu-portal": trigger || position ? menuId : void 0,
|
|
1871
|
+
"data-placement": resolvedPlacement,
|
|
1872
|
+
backgroundColor: xuiTheme.colors.background.secondary,
|
|
1873
|
+
borderColor: xuiTheme.colors.border.secondary,
|
|
1874
|
+
borderWidth: 1,
|
|
1875
|
+
borderRadius,
|
|
1876
|
+
paddingVertical: sizeStyles.paddingVertical,
|
|
1877
|
+
width,
|
|
1878
|
+
minWidth: sizeStyles.minWidth,
|
|
1879
|
+
tabIndex: -1,
|
|
1880
|
+
onKeyDown: keyboard.handleKeyDown,
|
|
1881
|
+
onMouseLeave: () => setActiveIndex(-1),
|
|
1882
|
+
style: {
|
|
1883
|
+
...positionStyle,
|
|
1884
|
+
...style,
|
|
1885
|
+
zIndex: overlayLayer + LAYER_OFFSET3.menu,
|
|
1886
|
+
boxShadow: PANEL_SHADOW,
|
|
1887
|
+
...withArrow ? {
|
|
1888
|
+
overflow: "visible"
|
|
1889
|
+
} : {
|
|
1890
|
+
maxHeight,
|
|
1891
|
+
overflowY: "auto"
|
|
1892
|
+
},
|
|
1893
|
+
outline: "none"
|
|
1824
1894
|
},
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1895
|
+
children: withArrow ? /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
1896
|
+
/* @__PURE__ */ jsx4(
|
|
1897
|
+
"span",
|
|
1898
|
+
{
|
|
1899
|
+
"aria-hidden": "true",
|
|
1900
|
+
"data-testid": "context-menu-arrow",
|
|
1901
|
+
style: getArrowStyle(resolvedPlacement)
|
|
1902
|
+
}
|
|
1903
|
+
),
|
|
1904
|
+
/* @__PURE__ */ jsx4(
|
|
1905
|
+
"div",
|
|
1906
|
+
{
|
|
1907
|
+
style: { maxHeight, overflowY: "auto", borderRadius },
|
|
1908
|
+
children: renderContent()
|
|
1909
|
+
}
|
|
1910
|
+
)
|
|
1911
|
+
] }) : renderContent()
|
|
1912
|
+
}
|
|
1913
|
+
);
|
|
1914
|
+
return trigger || position ? typeof document !== "undefined" ? createPortal3(panelNode, document.body) : null : panelNode;
|
|
1915
|
+
})()
|
|
1840
1916
|
]
|
|
1841
1917
|
}
|
|
1842
1918
|
) });
|