@xsolla/xui-context-menu 0.202.1 → 0.202.3
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 +8 -47
- package/native/index.d.ts +8 -47
- package/native/index.js +39 -32
- package/native/index.js.map +1 -1
- package/native/index.mjs +39 -32
- package/native/index.mjs.map +1 -1
- package/package.json +10 -10
- package/web/index.d.mts +8 -47
- package/web/index.d.ts +8 -47
- package/web/index.js +39 -32
- package/web/index.js.map +1 -1
- package/web/index.mjs +39 -32
- package/web/index.mjs.map +1 -1
package/web/index.d.mts
CHANGED
|
@@ -44,19 +44,7 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
|
|
|
44
44
|
leadingIcon?: ReactNode;
|
|
45
45
|
/** Status indicator slot rendered before the label group (e.g. `<Status />`). */
|
|
46
46
|
status?: ReactNode;
|
|
47
|
-
/**
|
|
48
|
-
* Vertical placement of the `status` slot within the cell.
|
|
49
|
-
*
|
|
50
|
-
* - `true` (default) — the indicator is aligned to the **first line** of the
|
|
51
|
-
* label and stays there when the label wraps or a `description` makes the
|
|
52
|
-
* cell taller.
|
|
53
|
-
* - `false` — the indicator is centred on the full height of the cell. This
|
|
54
|
-
* restores the previous behaviour for consumers that depend on it.
|
|
55
|
-
*
|
|
56
|
-
* Has no effect when `status` is not provided.
|
|
57
|
-
*
|
|
58
|
-
* @default true
|
|
59
|
-
*/
|
|
47
|
+
/** Align `status` to the label's first line rather than the cell's full height. Defaults to `true`. */
|
|
60
48
|
statusTopAlignment?: boolean;
|
|
61
49
|
iconWrapper?: ReactNode;
|
|
62
50
|
slot?: ReactNode;
|
|
@@ -73,20 +61,14 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
|
|
|
73
61
|
onSelect?: () => void;
|
|
74
62
|
onCheckedChange?: (checked: boolean) => void;
|
|
75
63
|
}
|
|
76
|
-
/**
|
|
77
|
-
* A search cell rendered at the top of the menu. When `searchable` is set on the
|
|
78
|
-
* panel this cell is auto-rendered and stays mounted even when the query matches
|
|
79
|
-
* nothing, so the user can clear it without reopening the menu. A trailing clear
|
|
80
|
-
* (×) button appears whenever the field has a value; pressing it empties the
|
|
81
|
-
* query (fires `onValueChange("")`) and refocuses the input.
|
|
82
|
-
*/
|
|
64
|
+
/** A search cell at the top of the menu; auto-rendered when `searchable` is set. */
|
|
83
65
|
interface ContextMenuSearchItemProps extends ContextMenuItemBaseProps {
|
|
84
66
|
type: "search";
|
|
85
67
|
/** Controlled value of the search input. */
|
|
86
68
|
value?: string;
|
|
87
69
|
/** Raw change event; fires alongside `onValueChange`. */
|
|
88
70
|
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
89
|
-
/**
|
|
71
|
+
/** Next string value. Also fires with `""` when the clear button is pressed. */
|
|
90
72
|
onValueChange?: (value: string) => void;
|
|
91
73
|
placeholder?: string;
|
|
92
74
|
autoFocus?: boolean;
|
|
@@ -112,25 +94,11 @@ interface ContextMenuProps extends ThemeOverrideProps {
|
|
|
112
94
|
emptyMessage?: string;
|
|
113
95
|
empty?: ReactNode;
|
|
114
96
|
trigger?: ReactNode;
|
|
115
|
-
/**
|
|
116
|
-
* When `true`, the trigger fills the full width of its parent instead of
|
|
117
|
-
* shrinking to its content width. Defaults to `false`.
|
|
118
|
-
*/
|
|
97
|
+
/** Trigger fills its parent's width instead of hugging its content. Defaults to `false`. */
|
|
119
98
|
triggerFullWidth?: boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Menu placement relative to the trigger element. The `*-center` variants
|
|
122
|
-
* horizontally center the panel on the trigger; every variant auto-flips on
|
|
123
|
-
* the vertical axis (and `start`/`end` flip horizontally) when the menu
|
|
124
|
-
* would clip the viewport. Only applies to trigger-anchored menus (ignored
|
|
125
|
-
* when `position` is set). Defaults to `"bottom-start"`.
|
|
126
|
-
*/
|
|
99
|
+
/** Placement relative to the trigger; auto-flips to stay in the viewport. Ignored when `position` is set. Defaults to `"bottom-start"`. */
|
|
127
100
|
placement?: ContextMenuPlacement;
|
|
128
|
-
/**
|
|
129
|
-
* Gap in pixels between the trigger and the menu. When `withArrow` is set
|
|
130
|
-
* this is measured to the arrow's tip; otherwise to the panel edge. Only
|
|
131
|
-
* applies to trigger-anchored menus (ignored when `position` is set).
|
|
132
|
-
* Defaults to `4`.
|
|
133
|
-
*/
|
|
101
|
+
/** Gap in px to the panel edge, or to the arrow tip when `withArrow` is set. Defaults to `4`. */
|
|
134
102
|
offset?: number;
|
|
135
103
|
position?: ContextMenuPosition;
|
|
136
104
|
isOpen?: boolean;
|
|
@@ -138,11 +106,7 @@ interface ContextMenuProps extends ThemeOverrideProps {
|
|
|
138
106
|
closeOnSelect?: boolean;
|
|
139
107
|
width?: number | string;
|
|
140
108
|
maxHeight?: number;
|
|
141
|
-
/**
|
|
142
|
-
* Render a directional arrow on the panel edge pointing toward the trigger,
|
|
143
|
-
* mirroring the Tooltip arrow. Only applies to trigger-anchored menus.
|
|
144
|
-
* Defaults to `false`.
|
|
145
|
-
*/
|
|
109
|
+
/** Arrow on the panel edge pointing at the trigger. Defaults to `false`. */
|
|
146
110
|
withArrow?: boolean;
|
|
147
111
|
onSelect?: (item: ContextMenuOptionItemProps) => void;
|
|
148
112
|
"aria-label"?: string;
|
|
@@ -151,15 +115,12 @@ interface ContextMenuProps extends ThemeOverrideProps {
|
|
|
151
115
|
style?: CSSProperties;
|
|
152
116
|
}
|
|
153
117
|
interface ContextMenuSubmenuProps {
|
|
154
|
-
/** Text label for the submenu trigger item */
|
|
155
118
|
label: ReactNode;
|
|
156
|
-
/** Leading icon for the trigger item */
|
|
157
119
|
icon?: ReactNode;
|
|
158
|
-
/** Whether the trigger item is disabled */
|
|
159
120
|
disabled?: boolean;
|
|
160
121
|
/** Submenu panel contents */
|
|
161
122
|
children: ReactNode;
|
|
162
|
-
/**
|
|
123
|
+
/** Inherited from the parent menu when omitted */
|
|
163
124
|
size?: ContextMenuSize;
|
|
164
125
|
"data-testid"?: string;
|
|
165
126
|
}
|
package/web/index.d.ts
CHANGED
|
@@ -44,19 +44,7 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
|
|
|
44
44
|
leadingIcon?: ReactNode;
|
|
45
45
|
/** Status indicator slot rendered before the label group (e.g. `<Status />`). */
|
|
46
46
|
status?: ReactNode;
|
|
47
|
-
/**
|
|
48
|
-
* Vertical placement of the `status` slot within the cell.
|
|
49
|
-
*
|
|
50
|
-
* - `true` (default) — the indicator is aligned to the **first line** of the
|
|
51
|
-
* label and stays there when the label wraps or a `description` makes the
|
|
52
|
-
* cell taller.
|
|
53
|
-
* - `false` — the indicator is centred on the full height of the cell. This
|
|
54
|
-
* restores the previous behaviour for consumers that depend on it.
|
|
55
|
-
*
|
|
56
|
-
* Has no effect when `status` is not provided.
|
|
57
|
-
*
|
|
58
|
-
* @default true
|
|
59
|
-
*/
|
|
47
|
+
/** Align `status` to the label's first line rather than the cell's full height. Defaults to `true`. */
|
|
60
48
|
statusTopAlignment?: boolean;
|
|
61
49
|
iconWrapper?: ReactNode;
|
|
62
50
|
slot?: ReactNode;
|
|
@@ -73,20 +61,14 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
|
|
|
73
61
|
onSelect?: () => void;
|
|
74
62
|
onCheckedChange?: (checked: boolean) => void;
|
|
75
63
|
}
|
|
76
|
-
/**
|
|
77
|
-
* A search cell rendered at the top of the menu. When `searchable` is set on the
|
|
78
|
-
* panel this cell is auto-rendered and stays mounted even when the query matches
|
|
79
|
-
* nothing, so the user can clear it without reopening the menu. A trailing clear
|
|
80
|
-
* (×) button appears whenever the field has a value; pressing it empties the
|
|
81
|
-
* query (fires `onValueChange("")`) and refocuses the input.
|
|
82
|
-
*/
|
|
64
|
+
/** A search cell at the top of the menu; auto-rendered when `searchable` is set. */
|
|
83
65
|
interface ContextMenuSearchItemProps extends ContextMenuItemBaseProps {
|
|
84
66
|
type: "search";
|
|
85
67
|
/** Controlled value of the search input. */
|
|
86
68
|
value?: string;
|
|
87
69
|
/** Raw change event; fires alongside `onValueChange`. */
|
|
88
70
|
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
89
|
-
/**
|
|
71
|
+
/** Next string value. Also fires with `""` when the clear button is pressed. */
|
|
90
72
|
onValueChange?: (value: string) => void;
|
|
91
73
|
placeholder?: string;
|
|
92
74
|
autoFocus?: boolean;
|
|
@@ -112,25 +94,11 @@ interface ContextMenuProps extends ThemeOverrideProps {
|
|
|
112
94
|
emptyMessage?: string;
|
|
113
95
|
empty?: ReactNode;
|
|
114
96
|
trigger?: ReactNode;
|
|
115
|
-
/**
|
|
116
|
-
* When `true`, the trigger fills the full width of its parent instead of
|
|
117
|
-
* shrinking to its content width. Defaults to `false`.
|
|
118
|
-
*/
|
|
97
|
+
/** Trigger fills its parent's width instead of hugging its content. Defaults to `false`. */
|
|
119
98
|
triggerFullWidth?: boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Menu placement relative to the trigger element. The `*-center` variants
|
|
122
|
-
* horizontally center the panel on the trigger; every variant auto-flips on
|
|
123
|
-
* the vertical axis (and `start`/`end` flip horizontally) when the menu
|
|
124
|
-
* would clip the viewport. Only applies to trigger-anchored menus (ignored
|
|
125
|
-
* when `position` is set). Defaults to `"bottom-start"`.
|
|
126
|
-
*/
|
|
99
|
+
/** Placement relative to the trigger; auto-flips to stay in the viewport. Ignored when `position` is set. Defaults to `"bottom-start"`. */
|
|
127
100
|
placement?: ContextMenuPlacement;
|
|
128
|
-
/**
|
|
129
|
-
* Gap in pixels between the trigger and the menu. When `withArrow` is set
|
|
130
|
-
* this is measured to the arrow's tip; otherwise to the panel edge. Only
|
|
131
|
-
* applies to trigger-anchored menus (ignored when `position` is set).
|
|
132
|
-
* Defaults to `4`.
|
|
133
|
-
*/
|
|
101
|
+
/** Gap in px to the panel edge, or to the arrow tip when `withArrow` is set. Defaults to `4`. */
|
|
134
102
|
offset?: number;
|
|
135
103
|
position?: ContextMenuPosition;
|
|
136
104
|
isOpen?: boolean;
|
|
@@ -138,11 +106,7 @@ interface ContextMenuProps extends ThemeOverrideProps {
|
|
|
138
106
|
closeOnSelect?: boolean;
|
|
139
107
|
width?: number | string;
|
|
140
108
|
maxHeight?: number;
|
|
141
|
-
/**
|
|
142
|
-
* Render a directional arrow on the panel edge pointing toward the trigger,
|
|
143
|
-
* mirroring the Tooltip arrow. Only applies to trigger-anchored menus.
|
|
144
|
-
* Defaults to `false`.
|
|
145
|
-
*/
|
|
109
|
+
/** Arrow on the panel edge pointing at the trigger. Defaults to `false`. */
|
|
146
110
|
withArrow?: boolean;
|
|
147
111
|
onSelect?: (item: ContextMenuOptionItemProps) => void;
|
|
148
112
|
"aria-label"?: string;
|
|
@@ -151,15 +115,12 @@ interface ContextMenuProps extends ThemeOverrideProps {
|
|
|
151
115
|
style?: CSSProperties;
|
|
152
116
|
}
|
|
153
117
|
interface ContextMenuSubmenuProps {
|
|
154
|
-
/** Text label for the submenu trigger item */
|
|
155
118
|
label: ReactNode;
|
|
156
|
-
/** Leading icon for the trigger item */
|
|
157
119
|
icon?: ReactNode;
|
|
158
|
-
/** Whether the trigger item is disabled */
|
|
159
120
|
disabled?: boolean;
|
|
160
121
|
/** Submenu panel contents */
|
|
161
122
|
children: ReactNode;
|
|
162
|
-
/**
|
|
123
|
+
/** Inherited from the parent menu when omitted */
|
|
163
124
|
size?: ContextMenuSize;
|
|
164
125
|
"data-testid"?: string;
|
|
165
126
|
}
|
package/web/index.js
CHANGED
|
@@ -751,11 +751,7 @@ var OptionCell = ({
|
|
|
751
751
|
display: "inline-flex",
|
|
752
752
|
alignItems: "center",
|
|
753
753
|
flexShrink: 0,
|
|
754
|
-
//
|
|
755
|
-
// the height of one label line, so the dot centres on the FIRST
|
|
756
|
-
// line and stays there when the label wraps or a `description`
|
|
757
|
-
// pushes the row taller. Without it the row's `alignItems:center`
|
|
758
|
-
// floats the dot to the middle of a multi-line cell.
|
|
754
|
+
// One label line tall, so the dot centres on that line when text wraps.
|
|
759
755
|
...statusTopAlignment ? { alignSelf: "flex-start", minHeight: labelLineHeight } : {}
|
|
760
756
|
},
|
|
761
757
|
children: status
|
|
@@ -857,8 +853,7 @@ var OptionCell = ({
|
|
|
857
853
|
position: "fixed",
|
|
858
854
|
top: submenuPos.top,
|
|
859
855
|
left: submenuPos.left,
|
|
860
|
-
// Same band as the parent
|
|
861
|
-
// the DOM so it paints above it (holds for arbitrary nesting depth).
|
|
856
|
+
// Same band as the parent; later DOM order paints it above.
|
|
862
857
|
zIndex: overlayLayer + import_xui_core.LAYER_OFFSET.menu
|
|
863
858
|
},
|
|
864
859
|
children: submenu
|
|
@@ -1222,9 +1217,7 @@ var ContextMenuSubmenu = ({
|
|
|
1222
1217
|
top: pos ? pos.top : 0,
|
|
1223
1218
|
// Hidden until measured to avoid a flash at (0,0).
|
|
1224
1219
|
visibility: pos ? "visible" : "hidden",
|
|
1225
|
-
// One step above the parent panel
|
|
1226
|
-
// through the portal, so a submenu inside a modal stays above panel and
|
|
1227
|
-
// modal; nested submenus tie and DOM order resolves the stack.
|
|
1220
|
+
// One step above the parent panel; nested ties resolve by DOM order.
|
|
1228
1221
|
zIndex: overlayLayer + import_xui_core2.LAYER_OFFSET.menu + 1,
|
|
1229
1222
|
opacity: visible ? 1 : 0,
|
|
1230
1223
|
transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
|
|
@@ -1490,6 +1483,15 @@ var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
|
|
|
1490
1483
|
var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
|
|
1491
1484
|
var DROPDOWN_LAYER_SELECTOR = '[data-modal-id],[role="listbox"]';
|
|
1492
1485
|
var ownLayerSelector = (menuId) => `${DROPDOWN_LAYER_SELECTOR},[data-xui-context-menu-portal="${menuId}"],[data-xui-context-menu-owner="${menuId}"]`;
|
|
1486
|
+
var isInOwnLayer = (event, selector) => {
|
|
1487
|
+
const path = typeof event.composedPath === "function" ? event.composedPath() : [];
|
|
1488
|
+
if (path.length)
|
|
1489
|
+
return path.some(
|
|
1490
|
+
(node) => node instanceof Element && node.matches(selector)
|
|
1491
|
+
);
|
|
1492
|
+
const target = event.target;
|
|
1493
|
+
return target instanceof Element && !!target.closest(selector);
|
|
1494
|
+
};
|
|
1493
1495
|
var textFromNode = (node) => {
|
|
1494
1496
|
if (node === null || node === void 0 || typeof node === "boolean")
|
|
1495
1497
|
return "";
|
|
@@ -1693,12 +1695,7 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1693
1695
|
const target = event.target;
|
|
1694
1696
|
if (!target) return;
|
|
1695
1697
|
if (containerRef.current?.contains(target)) return;
|
|
1696
|
-
|
|
1697
|
-
const path = typeof event.composedPath === "function" ? event.composedPath() : [];
|
|
1698
|
-
const isInsidePortaledLayer = path.length ? path.some(
|
|
1699
|
-
(node) => node instanceof Element && node.matches(selector)
|
|
1700
|
-
) : target instanceof Element && !!target.closest(selector);
|
|
1701
|
-
if (isInsidePortaledLayer) return;
|
|
1698
|
+
if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
|
|
1702
1699
|
closeMenu();
|
|
1703
1700
|
};
|
|
1704
1701
|
const onScroll = (event) => {
|
|
@@ -1706,6 +1703,7 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1706
1703
|
if (target instanceof Node && (containerRef.current?.contains(target) || panelRef.current?.contains(target))) {
|
|
1707
1704
|
return;
|
|
1708
1705
|
}
|
|
1706
|
+
if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
|
|
1709
1707
|
closeMenu();
|
|
1710
1708
|
};
|
|
1711
1709
|
document.addEventListener("mousedown", onMouseDown);
|
|
@@ -1880,22 +1878,26 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1880
1878
|
firstChild instanceof HTMLElement ? firstChild : node
|
|
1881
1879
|
);
|
|
1882
1880
|
};
|
|
1883
|
-
const triggerNode = trigger && (0, import_react8.isValidElement)(trigger) ?
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1881
|
+
const triggerNode = trigger && (0, import_react8.isValidElement)(trigger) ? (
|
|
1882
|
+
// Presentational click shim; the wrapped trigger owns keyboard activation.
|
|
1883
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1884
|
+
"span",
|
|
1885
|
+
{
|
|
1886
|
+
ref: assignTriggerWrapperRef,
|
|
1887
|
+
role: "presentation",
|
|
1888
|
+
onClick: (event) => {
|
|
1889
|
+
if (!event.defaultPrevented) toggleMenu();
|
|
1890
|
+
},
|
|
1891
|
+
style: {
|
|
1892
|
+
display: "inline-flex",
|
|
1893
|
+
width: triggerFullWidth ? "100%" : "auto"
|
|
1894
|
+
},
|
|
1895
|
+
children: (0, import_react8.cloneElement)(trigger, {
|
|
1896
|
+
"aria-haspopup": "menu",
|
|
1897
|
+
"aria-expanded": isOpen ? "true" : "false"
|
|
1898
|
+
})
|
|
1899
|
+
}
|
|
1900
|
+
)
|
|
1899
1901
|
) : trigger ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1900
1902
|
"span",
|
|
1901
1903
|
{
|
|
@@ -1905,6 +1907,11 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
|
|
|
1905
1907
|
"aria-haspopup": "menu",
|
|
1906
1908
|
"aria-expanded": isOpen ? "true" : "false",
|
|
1907
1909
|
onClick: toggleMenu,
|
|
1910
|
+
onKeyDown: (event) => {
|
|
1911
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
1912
|
+
event.preventDefault();
|
|
1913
|
+
toggleMenu();
|
|
1914
|
+
},
|
|
1908
1915
|
children: trigger
|
|
1909
1916
|
}
|
|
1910
1917
|
) : null;
|