@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/native/index.d.mts
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/native/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/native/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_react6 = require("react");
|
|
45
|
+
var import_react6 = __toESM(require("react"));
|
|
46
|
+
var import_react_dom3 = require("react-dom");
|
|
46
47
|
|
|
47
48
|
// ../../foundation/primitives-native/src/Box.tsx
|
|
48
49
|
var import_react_native = require("react-native");
|
|
@@ -830,6 +831,19 @@ var SearchCell = ({
|
|
|
830
831
|
registerCell(id, { type: "search" });
|
|
831
832
|
return () => unregisterCell(id);
|
|
832
833
|
}, [registerCell, unregisterCell, id]);
|
|
834
|
+
const inputRef = import_react2.default.useRef(null);
|
|
835
|
+
const hasValue = (value ?? "") !== "";
|
|
836
|
+
const handleClear = () => {
|
|
837
|
+
onValueChange?.("");
|
|
838
|
+
if (onChange && inputRef.current) {
|
|
839
|
+
inputRef.current.value = "";
|
|
840
|
+
onChange({
|
|
841
|
+
target: inputRef.current,
|
|
842
|
+
currentTarget: inputRef.current
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
inputRef.current?.focus();
|
|
846
|
+
};
|
|
833
847
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
834
848
|
"div",
|
|
835
849
|
{
|
|
@@ -863,7 +877,8 @@ var SearchCell = ({
|
|
|
863
877
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
864
878
|
"input",
|
|
865
879
|
{
|
|
866
|
-
|
|
880
|
+
ref: inputRef,
|
|
881
|
+
type: "text",
|
|
867
882
|
role: "searchbox",
|
|
868
883
|
"aria-label": ariaLabel,
|
|
869
884
|
placeholder,
|
|
@@ -887,6 +902,37 @@ var SearchCell = ({
|
|
|
887
902
|
lineHeight: `${sizing.searchLineHeight}px`
|
|
888
903
|
}
|
|
889
904
|
}
|
|
905
|
+
),
|
|
906
|
+
hasValue && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
907
|
+
"button",
|
|
908
|
+
{
|
|
909
|
+
type: "button",
|
|
910
|
+
"aria-label": "Clear search",
|
|
911
|
+
"data-testid": "ctxmenu-search-clear",
|
|
912
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
913
|
+
onClick: handleClear,
|
|
914
|
+
style: {
|
|
915
|
+
display: "inline-flex",
|
|
916
|
+
alignItems: "center",
|
|
917
|
+
justifyContent: "center",
|
|
918
|
+
flexShrink: 0,
|
|
919
|
+
padding: 0,
|
|
920
|
+
margin: 0,
|
|
921
|
+
border: "none",
|
|
922
|
+
background: "transparent",
|
|
923
|
+
cursor: "pointer",
|
|
924
|
+
color: theme.colors.control.input.placeholder
|
|
925
|
+
},
|
|
926
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
927
|
+
import_xui_icons_base.Remove,
|
|
928
|
+
{
|
|
929
|
+
variant: "line",
|
|
930
|
+
size: sizing.searchIconSize,
|
|
931
|
+
color: theme.colors.control.input.placeholder,
|
|
932
|
+
"aria-hidden": true
|
|
933
|
+
}
|
|
934
|
+
)
|
|
935
|
+
}
|
|
890
936
|
)
|
|
891
937
|
]
|
|
892
938
|
}
|
|
@@ -925,9 +971,11 @@ var DividerCell = ({ themeMode, themeProductContext, "data-testid": testId }) =>
|
|
|
925
971
|
|
|
926
972
|
// src/ContextMenuSubmenu.tsx
|
|
927
973
|
var import_react3 = require("react");
|
|
974
|
+
var import_react_dom2 = require("react-dom");
|
|
928
975
|
var import_xui_core2 = require("@xsolla/xui-core");
|
|
929
976
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
930
977
|
var SUBMENU_GAP2 = 4;
|
|
978
|
+
var VIEWPORT_PADDING = 8;
|
|
931
979
|
var OPEN_DELAY_MS = 200;
|
|
932
980
|
var CLOSE_GRACE_MS = 100;
|
|
933
981
|
var _submenuIdCounter = 0;
|
|
@@ -941,6 +989,7 @@ var ContextMenuSubmenu = ({
|
|
|
941
989
|
}) => {
|
|
942
990
|
const { theme } = (0, import_xui_core2.useDesignSystem)();
|
|
943
991
|
const xuiTheme = theme;
|
|
992
|
+
const overlayLayer = (0, import_xui_core2.useOverlayLayer)();
|
|
944
993
|
const context = useContextMenu();
|
|
945
994
|
const size = propSize || context?.size || "md";
|
|
946
995
|
const sizeStyles = xuiTheme.sizing.contextMenu(size);
|
|
@@ -953,7 +1002,7 @@ var ContextMenuSubmenu = ({
|
|
|
953
1002
|
const [isOpen, setIsOpen] = (0, import_react3.useState)(false);
|
|
954
1003
|
const [visible, setVisible] = (0, import_react3.useState)(false);
|
|
955
1004
|
const [openLeft, setOpenLeft] = (0, import_react3.useState)(false);
|
|
956
|
-
const [
|
|
1005
|
+
const [pos, setPos] = (0, import_react3.useState)(null);
|
|
957
1006
|
const triggerRef = (0, import_react3.useRef)(null);
|
|
958
1007
|
const submenuRef = (0, import_react3.useRef)(null);
|
|
959
1008
|
const openTimerRef = (0, import_react3.useRef)(null);
|
|
@@ -968,43 +1017,44 @@ var ContextMenuSubmenu = ({
|
|
|
968
1017
|
setIsOpen(false);
|
|
969
1018
|
}
|
|
970
1019
|
}, [context?.activeSubmenuId, submenuId]);
|
|
971
|
-
const calculatePlacement = (0, import_react3.useCallback)(() => {
|
|
972
|
-
if (!triggerRef.current) return;
|
|
973
|
-
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
974
|
-
const estimatedWidth = sizeStyles.minWidth + 32;
|
|
975
|
-
const wouldOverflowRight = triggerRect.right + estimatedWidth + SUBMENU_GAP2 > window.innerWidth - 8;
|
|
976
|
-
const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - estimatedWidth >= 8;
|
|
977
|
-
setOpenLeft(wouldOverflowRight && hasSpaceOnLeft);
|
|
978
|
-
setTopOffset(0);
|
|
979
|
-
}, [sizeStyles.minWidth]);
|
|
980
1020
|
(0, import_react3.useLayoutEffect)(() => {
|
|
981
|
-
if (!isOpen
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
const wouldOverflowRight = triggerRect.right + submenuRect.width + SUBMENU_GAP2 > window.innerWidth - 8;
|
|
985
|
-
const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - submenuRect.width >= 8;
|
|
986
|
-
setOpenLeft(wouldOverflowRight && hasSpaceOnLeft);
|
|
987
|
-
const overflowBottom = triggerRect.top + submenuRect.height - (window.innerHeight - 8);
|
|
988
|
-
if (overflowBottom > 0) {
|
|
989
|
-
setTopOffset(-Math.min(overflowBottom, triggerRect.top - 8));
|
|
990
|
-
} else {
|
|
991
|
-
setTopOffset(0);
|
|
1021
|
+
if (!isOpen) {
|
|
1022
|
+
setPos(null);
|
|
1023
|
+
return;
|
|
992
1024
|
}
|
|
1025
|
+
const compute = () => {
|
|
1026
|
+
const trigger = triggerRef.current;
|
|
1027
|
+
const panel = submenuRef.current;
|
|
1028
|
+
if (!trigger || !panel) return;
|
|
1029
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
1030
|
+
const submenuRect = panel.getBoundingClientRect();
|
|
1031
|
+
const wouldOverflowRight = triggerRect.right + submenuRect.width + SUBMENU_GAP2 > window.innerWidth - VIEWPORT_PADDING;
|
|
1032
|
+
const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - submenuRect.width >= VIEWPORT_PADDING;
|
|
1033
|
+
const nextOpenLeft = wouldOverflowRight && hasSpaceOnLeft;
|
|
1034
|
+
setOpenLeft(nextOpenLeft);
|
|
1035
|
+
const left = nextOpenLeft ? triggerRect.left - SUBMENU_GAP2 - submenuRect.width : triggerRect.right + SUBMENU_GAP2;
|
|
1036
|
+
const overflowBottom = triggerRect.top + submenuRect.height - (window.innerHeight - VIEWPORT_PADDING);
|
|
1037
|
+
const top = overflowBottom > 0 ? triggerRect.top - Math.min(overflowBottom, triggerRect.top - VIEWPORT_PADDING) : triggerRect.top;
|
|
1038
|
+
setPos({ left, top });
|
|
1039
|
+
};
|
|
1040
|
+
compute();
|
|
1041
|
+
const onResize = () => compute();
|
|
1042
|
+
window.addEventListener("resize", onResize);
|
|
1043
|
+
return () => window.removeEventListener("resize", onResize);
|
|
993
1044
|
}, [isOpen]);
|
|
994
1045
|
(0, import_react3.useEffect)(() => {
|
|
995
|
-
if (!isOpen) {
|
|
1046
|
+
if (!isOpen || !pos) {
|
|
996
1047
|
setVisible(false);
|
|
997
1048
|
return;
|
|
998
1049
|
}
|
|
999
1050
|
const raf = requestAnimationFrame(() => setVisible(true));
|
|
1000
1051
|
return () => cancelAnimationFrame(raf);
|
|
1001
|
-
}, [isOpen]);
|
|
1052
|
+
}, [isOpen, pos]);
|
|
1002
1053
|
(0, import_react3.useEffect)(() => () => clearTimers(), [clearTimers]);
|
|
1003
1054
|
const handleTriggerEnter = () => {
|
|
1004
1055
|
if (disabled) return;
|
|
1005
1056
|
clearTimers();
|
|
1006
1057
|
openTimerRef.current = setTimeout(() => {
|
|
1007
|
-
calculatePlacement();
|
|
1008
1058
|
setIsOpen(true);
|
|
1009
1059
|
context?.setActiveSubmenuId(submenuId);
|
|
1010
1060
|
}, OPEN_DELAY_MS);
|
|
@@ -1028,7 +1078,47 @@ var ContextMenuSubmenu = ({
|
|
|
1028
1078
|
}
|
|
1029
1079
|
}, CLOSE_GRACE_MS);
|
|
1030
1080
|
};
|
|
1031
|
-
const
|
|
1081
|
+
const submenuPanel = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1082
|
+
"div",
|
|
1083
|
+
{
|
|
1084
|
+
ref: submenuRef,
|
|
1085
|
+
"data-xui-context-menu-portal": submenuId,
|
|
1086
|
+
"data-xui-context-menu-owner": context?.menuId,
|
|
1087
|
+
onMouseEnter: handleSubmenuEnter,
|
|
1088
|
+
onMouseLeave: handleSubmenuLeave,
|
|
1089
|
+
style: {
|
|
1090
|
+
position: "fixed",
|
|
1091
|
+
left: pos ? pos.left : 0,
|
|
1092
|
+
top: pos ? pos.top : 0,
|
|
1093
|
+
// Hidden until measured to avoid a flash at (0,0).
|
|
1094
|
+
visibility: pos ? "visible" : "hidden",
|
|
1095
|
+
// One step above the parent panel. The overlay-layer context flows
|
|
1096
|
+
// through the portal, so a submenu inside a modal stays above panel and
|
|
1097
|
+
// modal; nested submenus tie and DOM order resolves the stack.
|
|
1098
|
+
zIndex: overlayLayer + import_xui_core2.LAYER_OFFSET.menu + 1,
|
|
1099
|
+
opacity: visible ? 1 : 0,
|
|
1100
|
+
transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
|
|
1101
|
+
transition: "opacity 100ms ease, transform 100ms ease"
|
|
1102
|
+
},
|
|
1103
|
+
"data-testid": `${testId}-content`,
|
|
1104
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1105
|
+
Box,
|
|
1106
|
+
{
|
|
1107
|
+
role: "menu",
|
|
1108
|
+
backgroundColor: xuiTheme.colors.background.secondary,
|
|
1109
|
+
borderColor: xuiTheme.colors.border.secondary,
|
|
1110
|
+
borderWidth: 1,
|
|
1111
|
+
borderRadius,
|
|
1112
|
+
paddingVertical: sizeStyles.paddingVertical,
|
|
1113
|
+
style: {
|
|
1114
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
|
|
1115
|
+
minWidth: sizeStyles.minWidth
|
|
1116
|
+
},
|
|
1117
|
+
children
|
|
1118
|
+
}
|
|
1119
|
+
)
|
|
1120
|
+
}
|
|
1121
|
+
);
|
|
1032
1122
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1033
1123
|
"div",
|
|
1034
1124
|
{
|
|
@@ -1050,40 +1140,7 @@ var ContextMenuSubmenu = ({
|
|
|
1050
1140
|
"data-testid": `${testId}-trigger`
|
|
1051
1141
|
}
|
|
1052
1142
|
),
|
|
1053
|
-
isOpen &&
|
|
1054
|
-
"div",
|
|
1055
|
-
{
|
|
1056
|
-
ref: submenuRef,
|
|
1057
|
-
onMouseEnter: handleSubmenuEnter,
|
|
1058
|
-
onMouseLeave: handleSubmenuLeave,
|
|
1059
|
-
style: {
|
|
1060
|
-
position: "absolute",
|
|
1061
|
-
top: topOffset,
|
|
1062
|
-
...submenuPositionStyle,
|
|
1063
|
-
zIndex: 1001,
|
|
1064
|
-
opacity: visible ? 1 : 0,
|
|
1065
|
-
transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
|
|
1066
|
-
transition: "opacity 100ms ease, transform 100ms ease"
|
|
1067
|
-
},
|
|
1068
|
-
"data-testid": `${testId}-content`,
|
|
1069
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1070
|
-
Box,
|
|
1071
|
-
{
|
|
1072
|
-
role: "menu",
|
|
1073
|
-
backgroundColor: xuiTheme.colors.background.secondary,
|
|
1074
|
-
borderColor: xuiTheme.colors.border.secondary,
|
|
1075
|
-
borderWidth: 1,
|
|
1076
|
-
borderRadius,
|
|
1077
|
-
paddingVertical: sizeStyles.paddingVertical,
|
|
1078
|
-
style: {
|
|
1079
|
-
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
|
|
1080
|
-
minWidth: sizeStyles.minWidth
|
|
1081
|
-
},
|
|
1082
|
-
children
|
|
1083
|
-
}
|
|
1084
|
-
)
|
|
1085
|
-
}
|
|
1086
|
-
)
|
|
1143
|
+
isOpen && typeof document !== "undefined" ? (0, import_react_dom2.createPortal)(submenuPanel, document.body) : null
|
|
1087
1144
|
]
|
|
1088
1145
|
}
|
|
1089
1146
|
);
|
|
@@ -1100,7 +1157,6 @@ var joinPlacement = (vertical, horizontal) => `${vertical}-${horizontal}`;
|
|
|
1100
1157
|
var useContextMenuPosition = ({
|
|
1101
1158
|
triggerRef,
|
|
1102
1159
|
panelRef,
|
|
1103
|
-
containerRef,
|
|
1104
1160
|
isOpen,
|
|
1105
1161
|
placement = "bottom-start",
|
|
1106
1162
|
offset = 4
|
|
@@ -1114,7 +1170,6 @@ var useContextMenuPosition = ({
|
|
|
1114
1170
|
const compute = () => {
|
|
1115
1171
|
const trigger = triggerRef.current;
|
|
1116
1172
|
const panel = panelRef.current;
|
|
1117
|
-
const container = containerRef.current;
|
|
1118
1173
|
if (!trigger || !panel) return;
|
|
1119
1174
|
const triggerRect = trigger.getBoundingClientRect();
|
|
1120
1175
|
const panelRect = panel.getBoundingClientRect();
|
|
@@ -1154,15 +1209,6 @@ var useContextMenuPosition = ({
|
|
|
1154
1209
|
}
|
|
1155
1210
|
}
|
|
1156
1211
|
}
|
|
1157
|
-
if (container) {
|
|
1158
|
-
const containerRect = container.getBoundingClientRect();
|
|
1159
|
-
const cOffsetW = container.offsetWidth;
|
|
1160
|
-
const cOffsetH = container.offsetHeight;
|
|
1161
|
-
const scaleX = cOffsetW > 0 ? containerRect.width / cOffsetW : 1;
|
|
1162
|
-
const scaleY = cOffsetH > 0 ? containerRect.height / cOffsetH : 1;
|
|
1163
|
-
left = (left - containerRect.left) / (scaleX || 1);
|
|
1164
|
-
top = (top - containerRect.top) / (scaleY || 1);
|
|
1165
|
-
}
|
|
1166
1212
|
const next = {
|
|
1167
1213
|
top,
|
|
1168
1214
|
left,
|
|
@@ -1178,7 +1224,7 @@ var useContextMenuPosition = ({
|
|
|
1178
1224
|
return () => {
|
|
1179
1225
|
window.removeEventListener("resize", onResize);
|
|
1180
1226
|
};
|
|
1181
|
-
}, [isOpen, placement, offset, triggerRef, panelRef
|
|
1227
|
+
}, [isOpen, placement, offset, triggerRef, panelRef]);
|
|
1182
1228
|
return resolved;
|
|
1183
1229
|
};
|
|
1184
1230
|
|
|
@@ -1312,7 +1358,8 @@ var ARROW_HALF = ARROW_SIZE / 2;
|
|
|
1312
1358
|
var ARROW_EDGE_OFFSET = 12;
|
|
1313
1359
|
var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
|
|
1314
1360
|
var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
|
|
1315
|
-
var
|
|
1361
|
+
var DROPDOWN_LAYER_SELECTOR = '[data-modal-id],[role="listbox"]';
|
|
1362
|
+
var ownLayerSelector = (menuId) => `${DROPDOWN_LAYER_SELECTOR},[data-xui-context-menu-portal="${menuId}"],[data-xui-context-menu-owner="${menuId}"]`;
|
|
1316
1363
|
var textFromNode = (node) => {
|
|
1317
1364
|
if (node === null || node === void 0 || typeof node === "boolean")
|
|
1318
1365
|
return "";
|
|
@@ -1404,7 +1451,6 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1404
1451
|
const positioned = useContextMenuPosition({
|
|
1405
1452
|
triggerRef,
|
|
1406
1453
|
panelRef,
|
|
1407
|
-
containerRef,
|
|
1408
1454
|
isOpen: isOpen && !!trigger && !position,
|
|
1409
1455
|
placement,
|
|
1410
1456
|
offset: positionOffset
|
|
@@ -1517,10 +1563,11 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1517
1563
|
const target = event.target;
|
|
1518
1564
|
if (!target) return;
|
|
1519
1565
|
if (containerRef.current?.contains(target)) return;
|
|
1566
|
+
const selector = ownLayerSelector(menuId);
|
|
1520
1567
|
const path = typeof event.composedPath === "function" ? event.composedPath() : [];
|
|
1521
1568
|
const isInsidePortaledLayer = path.length ? path.some(
|
|
1522
|
-
(node) => node instanceof Element && node.matches(
|
|
1523
|
-
) : target instanceof Element && !!target.closest(
|
|
1569
|
+
(node) => node instanceof Element && node.matches(selector)
|
|
1570
|
+
) : target instanceof Element && !!target.closest(selector);
|
|
1524
1571
|
if (isInsidePortaledLayer) return;
|
|
1525
1572
|
closeMenu();
|
|
1526
1573
|
};
|
|
@@ -1531,7 +1578,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1531
1578
|
document.removeEventListener("mousedown", onMouseDown);
|
|
1532
1579
|
window.removeEventListener("scroll", onScroll);
|
|
1533
1580
|
};
|
|
1534
|
-
}, [isOpen, trigger, closeMenu]);
|
|
1581
|
+
}, [isOpen, trigger, closeMenu, menuId]);
|
|
1535
1582
|
(0, import_react6.useLayoutEffect)(() => {
|
|
1536
1583
|
if (!isOpen || !panelRef.current) return;
|
|
1537
1584
|
const searchbox = panelRef.current.querySelector('[role="searchbox"]');
|
|
@@ -1616,6 +1663,31 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1616
1663
|
);
|
|
1617
1664
|
};
|
|
1618
1665
|
const renderedItems = searchable ? filterItems(items, debouncedQuery) : [...items];
|
|
1666
|
+
const searchHeader = searchable ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1667
|
+
"div",
|
|
1668
|
+
{
|
|
1669
|
+
"data-sticky": "top",
|
|
1670
|
+
style: {
|
|
1671
|
+
position: "sticky",
|
|
1672
|
+
top: 0,
|
|
1673
|
+
zIndex: 1,
|
|
1674
|
+
backgroundColor: xuiTheme.colors.background.secondary
|
|
1675
|
+
},
|
|
1676
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1677
|
+
ContextMenuItem,
|
|
1678
|
+
{
|
|
1679
|
+
type: "search",
|
|
1680
|
+
value: query,
|
|
1681
|
+
onValueChange: setQuery,
|
|
1682
|
+
placeholder: "Search",
|
|
1683
|
+
autoFocus: true,
|
|
1684
|
+
themeMode,
|
|
1685
|
+
themeProductContext
|
|
1686
|
+
}
|
|
1687
|
+
)
|
|
1688
|
+
},
|
|
1689
|
+
"context-menu-search"
|
|
1690
|
+
) : null;
|
|
1619
1691
|
const renderContent = () => {
|
|
1620
1692
|
if (loading || isLoading || type === "loading") {
|
|
1621
1693
|
const brandColor = xuiTheme.colors.control.brand.primary.bg;
|
|
@@ -1631,38 +1703,28 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1631
1703
|
);
|
|
1632
1704
|
}
|
|
1633
1705
|
if (children) return children;
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
position: "sticky",
|
|
1643
|
-
top: 0,
|
|
1644
|
-
zIndex: 1,
|
|
1645
|
-
backgroundColor: xuiTheme.colors.background.secondary
|
|
1646
|
-
},
|
|
1647
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1648
|
-
ContextMenuItem,
|
|
1649
|
-
{
|
|
1650
|
-
type: "search",
|
|
1651
|
-
value: query,
|
|
1652
|
-
onValueChange: setQuery,
|
|
1653
|
-
placeholder: "Search",
|
|
1654
|
-
autoFocus: true,
|
|
1655
|
-
themeMode,
|
|
1656
|
-
themeProductContext
|
|
1657
|
-
}
|
|
1658
|
-
)
|
|
1706
|
+
if (renderedItems.length === 0) {
|
|
1707
|
+
const emptyNode = empty ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1708
|
+
"div",
|
|
1709
|
+
{
|
|
1710
|
+
style: {
|
|
1711
|
+
padding: 16,
|
|
1712
|
+
textAlign: "center",
|
|
1713
|
+
color: xuiTheme.colors.content.tertiary
|
|
1659
1714
|
},
|
|
1660
|
-
|
|
1661
|
-
|
|
1715
|
+
children: emptyMessage
|
|
1716
|
+
},
|
|
1717
|
+
"context-menu-empty"
|
|
1662
1718
|
);
|
|
1719
|
+
if (!searchHeader) return emptyNode;
|
|
1720
|
+
return [
|
|
1721
|
+
searchHeader,
|
|
1722
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react6.default.Fragment, { children: emptyNode }, "context-menu-empty")
|
|
1723
|
+
];
|
|
1663
1724
|
}
|
|
1664
|
-
|
|
1665
|
-
|
|
1725
|
+
const content = renderedItems.map(renderPresetItem);
|
|
1726
|
+
if (searchHeader) content.unshift(searchHeader);
|
|
1727
|
+
return content;
|
|
1666
1728
|
};
|
|
1667
1729
|
const assignPanelRef = (node) => {
|
|
1668
1730
|
panelRef.current = node;
|
|
@@ -1715,11 +1777,11 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1715
1777
|
left: position.x,
|
|
1716
1778
|
top: position.y
|
|
1717
1779
|
} : trigger ? positioned ? {
|
|
1718
|
-
position: "
|
|
1780
|
+
position: "fixed",
|
|
1719
1781
|
left: positioned.left,
|
|
1720
1782
|
top: positioned.top
|
|
1721
1783
|
} : {
|
|
1722
|
-
position: "
|
|
1784
|
+
position: "fixed",
|
|
1723
1785
|
visibility: "hidden"
|
|
1724
1786
|
} : void 0;
|
|
1725
1787
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ContextMenuContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
@@ -1732,50 +1794,60 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1732
1794
|
},
|
|
1733
1795
|
children: [
|
|
1734
1796
|
triggerNode,
|
|
1735
|
-
isOpen &&
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1797
|
+
isOpen && (() => {
|
|
1798
|
+
const panelNode = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1799
|
+
Box,
|
|
1800
|
+
{
|
|
1801
|
+
ref: assignPanelRef,
|
|
1802
|
+
role: "menu",
|
|
1803
|
+
"aria-label": ariaLabel,
|
|
1804
|
+
"data-testid": dataTestId ?? testID ?? "context-menu",
|
|
1805
|
+
"data-xui-context-menu-portal": trigger || position ? menuId : void 0,
|
|
1806
|
+
"data-placement": resolvedPlacement,
|
|
1807
|
+
backgroundColor: xuiTheme.colors.background.secondary,
|
|
1808
|
+
borderColor: xuiTheme.colors.border.secondary,
|
|
1809
|
+
borderWidth: 1,
|
|
1810
|
+
borderRadius,
|
|
1811
|
+
paddingVertical: sizeStyles.paddingVertical,
|
|
1812
|
+
width,
|
|
1813
|
+
minWidth: sizeStyles.minWidth,
|
|
1814
|
+
tabIndex: -1,
|
|
1815
|
+
onKeyDown: keyboard.handleKeyDown,
|
|
1816
|
+
onMouseLeave: () => setActiveIndex(-1),
|
|
1817
|
+
style: {
|
|
1818
|
+
...positionStyle,
|
|
1819
|
+
...style,
|
|
1820
|
+
zIndex: overlayLayer + import_xui_core3.LAYER_OFFSET.menu,
|
|
1821
|
+
boxShadow: PANEL_SHADOW,
|
|
1822
|
+
...withArrow ? {
|
|
1823
|
+
overflow: "visible"
|
|
1824
|
+
} : {
|
|
1825
|
+
maxHeight,
|
|
1826
|
+
overflowY: "auto"
|
|
1827
|
+
},
|
|
1828
|
+
outline: "none"
|
|
1763
1829
|
},
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1830
|
+
children: withArrow ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1831
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1832
|
+
"span",
|
|
1833
|
+
{
|
|
1834
|
+
"aria-hidden": "true",
|
|
1835
|
+
"data-testid": "context-menu-arrow",
|
|
1836
|
+
style: getArrowStyle(resolvedPlacement)
|
|
1837
|
+
}
|
|
1838
|
+
),
|
|
1839
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1840
|
+
"div",
|
|
1841
|
+
{
|
|
1842
|
+
style: { maxHeight, overflowY: "auto", borderRadius },
|
|
1843
|
+
children: renderContent()
|
|
1844
|
+
}
|
|
1845
|
+
)
|
|
1846
|
+
] }) : renderContent()
|
|
1847
|
+
}
|
|
1848
|
+
);
|
|
1849
|
+
return trigger || position ? typeof document !== "undefined" ? (0, import_react_dom3.createPortal)(panelNode, document.body) : null : panelNode;
|
|
1850
|
+
})()
|
|
1779
1851
|
]
|
|
1780
1852
|
}
|
|
1781
1853
|
) });
|