@rescui/menu 0.14.1 → 0.15.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/lib/_virtual/check-outline.js +294 -63
- package/lib/_virtual/index.css.js +12 -12
- package/lib/index.css +68 -68
- package/lib/menu.js +374 -119
- package/lib/menu.p.module.css.js +34 -34
- package/lib/parts/divider.js +53 -11
- package/lib/parts/group-header.js +43 -11
- package/lib/parts/menu-context.js +72 -15
- package/lib/parts/menu-item.js +305 -92
- package/lib/parts/use-menu-keyboard-navigation.js +225 -110
- package/package.json +7 -7
|
@@ -1,132 +1,247 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import _includesInstanceProperty from
|
|
3
|
-
import {
|
|
2
|
+
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
3
|
+
import { c } from 'react-compiler-runtime';
|
|
4
|
+
import { useState, useRef, useEffect } from 'react';
|
|
4
5
|
import { getFirstItem, getLastItem, getPrevItem, getNextItem, htmlElementsComparator } from './navigation-utils.js';
|
|
5
6
|
|
|
6
7
|
function getSortedItems(itemsSet) {
|
|
7
8
|
return Array.from(itemsSet.values()).sort(htmlElementsComparator);
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
function useMenuKeyboardNavigation(
|
|
11
|
-
|
|
11
|
+
function useMenuKeyboardNavigation(t0) {
|
|
12
|
+
const $ = c(14);
|
|
13
|
+
const {
|
|
12
14
|
activateFirstItem
|
|
13
|
-
} =
|
|
15
|
+
} = t0;
|
|
14
16
|
const [currentActiveItemEl, setCurrentActiveItemEl] = useState(null);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
let t1;
|
|
18
|
+
|
|
19
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
20
|
+
t1 = (el, t2) => {
|
|
21
|
+
const {
|
|
22
|
+
scroll: t3
|
|
23
|
+
} = t2 === undefined ? {} : t2;
|
|
24
|
+
const scroll = t3 === undefined ? false : t3;
|
|
25
|
+
setCurrentActiveItemEl(el ?? null);
|
|
26
|
+
|
|
27
|
+
if (el) {
|
|
28
|
+
el.focus({
|
|
29
|
+
preventScroll: !scroll
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
$[0] = t1;
|
|
35
|
+
} else {
|
|
36
|
+
t1 = $[0];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const setCurrentActiveItemAndFocus = t1;
|
|
40
|
+
let t2;
|
|
41
|
+
|
|
42
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
43
|
+
t2 = new Set();
|
|
44
|
+
$[1] = t2;
|
|
45
|
+
} else {
|
|
46
|
+
t2 = $[1];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const menuItemsSet = useRef(t2);
|
|
28
50
|
const activateFirstItemTimeoutIdRef = useRef(null);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
let t3;
|
|
52
|
+
|
|
53
|
+
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
54
|
+
t3 = () => {
|
|
55
|
+
if (activateFirstItemTimeoutIdRef.current) {
|
|
56
|
+
clearTimeout(activateFirstItemTimeoutIdRef.current);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
activateFirstItemTimeoutIdRef.current = setTimeout(() => {
|
|
60
|
+
setCurrentActiveItemAndFocus(getFirstItem(getSortedItems(menuItemsSet.current)));
|
|
61
|
+
}, 50);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
$[2] = t3;
|
|
65
|
+
} else {
|
|
66
|
+
t3 = $[2];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const scheduleActivateFirstItem = t3;
|
|
70
|
+
let t4;
|
|
71
|
+
|
|
72
|
+
if ($[3] !== activateFirstItem) {
|
|
73
|
+
t4 = ref => {
|
|
74
|
+
if (!ref || menuItemsSet.current.has(ref)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
menuItemsSet.current.add(ref);
|
|
79
|
+
|
|
80
|
+
if (activateFirstItem) {
|
|
81
|
+
scheduleActivateFirstItem();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
$[3] = activateFirstItem;
|
|
86
|
+
$[4] = t4;
|
|
87
|
+
} else {
|
|
88
|
+
t4 = $[4];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const registerItem = t4;
|
|
92
|
+
let t5;
|
|
93
|
+
|
|
94
|
+
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
|
|
95
|
+
t5 = ref_0 => {
|
|
96
|
+
menuItemsSet.current.delete(ref_0);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
$[5] = t5;
|
|
100
|
+
} else {
|
|
101
|
+
t5 = $[5];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const unregisterItem = t5;
|
|
105
|
+
let t6;
|
|
106
|
+
let t7;
|
|
107
|
+
|
|
108
|
+
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
109
|
+
t6 = () => () => {
|
|
54
110
|
if (activateFirstItemTimeoutIdRef.current) {
|
|
55
111
|
clearTimeout(activateFirstItemTimeoutIdRef.current);
|
|
56
112
|
}
|
|
57
113
|
|
|
58
114
|
menuItemsSet.current.clear();
|
|
59
115
|
};
|
|
60
|
-
}, []);
|
|
61
|
-
const handleItemFocus = useCallback(ref => {
|
|
62
|
-
if (!ref) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
setCurrentActiveItemEl(ref);
|
|
67
|
-
}, [setCurrentActiveItemEl]);
|
|
68
|
-
const handleItemKeyDown = useCallback( // eslint-disable-next-line complexity
|
|
69
|
-
(e, ref) => {
|
|
70
|
-
var _context;
|
|
71
|
-
|
|
72
|
-
if (!_includesInstanceProperty(_context = ['ArrowDown', 'ArrowUp', 'Home', 'End', ' ', 'Enter']).call(_context, e.key)) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const items = getSortedItems(menuItemsSet.current);
|
|
77
|
-
|
|
78
|
-
switch (e.key) {
|
|
79
|
-
case 'ArrowDown':
|
|
80
|
-
e.preventDefault();
|
|
81
|
-
setCurrentActiveItemAndFocus(getNextItem(items, ref), {
|
|
82
|
-
scroll: true
|
|
83
|
-
});
|
|
84
|
-
break;
|
|
85
116
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
117
|
+
t7 = [];
|
|
118
|
+
$[6] = t6;
|
|
119
|
+
$[7] = t7;
|
|
120
|
+
} else {
|
|
121
|
+
t6 = $[6];
|
|
122
|
+
t7 = $[7];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
useEffect(t6, t7);
|
|
126
|
+
let t8;
|
|
127
|
+
|
|
128
|
+
if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
|
|
129
|
+
t8 = ref_1 => {
|
|
130
|
+
if (!ref_1) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
92
133
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
setCurrentActiveItemAndFocus(getFirstItem(items), {
|
|
96
|
-
scroll: true
|
|
97
|
-
});
|
|
98
|
-
break;
|
|
134
|
+
setCurrentActiveItemEl(ref_1);
|
|
135
|
+
};
|
|
99
136
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
137
|
+
$[8] = t8;
|
|
138
|
+
} else {
|
|
139
|
+
t8 = $[8];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const handleItemFocus = t8;
|
|
143
|
+
let t9;
|
|
144
|
+
|
|
145
|
+
if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
|
|
146
|
+
t9 = (e, ref_2) => {
|
|
147
|
+
var _context;
|
|
148
|
+
|
|
149
|
+
if (!_includesInstanceProperty(_context = ["ArrowDown", "ArrowUp", "Home", "End", " ", "Enter"]).call(_context, e.key)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const items = getSortedItems(menuItemsSet.current);
|
|
154
|
+
|
|
155
|
+
bb44: switch (e.key) {
|
|
156
|
+
case "ArrowDown":
|
|
157
|
+
{
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
setCurrentActiveItemAndFocus(getNextItem(items, ref_2), {
|
|
160
|
+
scroll: true
|
|
161
|
+
});
|
|
162
|
+
break bb44;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
case "ArrowUp":
|
|
166
|
+
{
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
setCurrentActiveItemAndFocus(getPrevItem(items, ref_2), {
|
|
169
|
+
scroll: true
|
|
170
|
+
});
|
|
171
|
+
break bb44;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
case "Home":
|
|
175
|
+
{
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
setCurrentActiveItemAndFocus(getFirstItem(items), {
|
|
178
|
+
scroll: true
|
|
179
|
+
});
|
|
180
|
+
break bb44;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
case "End":
|
|
184
|
+
{
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
setCurrentActiveItemAndFocus(getLastItem(items), {
|
|
187
|
+
scroll: true
|
|
188
|
+
});
|
|
189
|
+
break bb44;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
case " ":
|
|
193
|
+
case "Enter":
|
|
194
|
+
{
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
ref_2?.click?.();
|
|
197
|
+
break bb44;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
$[9] = t9;
|
|
203
|
+
} else {
|
|
204
|
+
t9 = $[9];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const handleItemKeyDown = t9;
|
|
208
|
+
let t10;
|
|
209
|
+
|
|
210
|
+
if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
|
|
211
|
+
t10 = ref_3 => {
|
|
212
|
+
if (!ref_3) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
setCurrentActiveItemAndFocus(ref_3);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
$[10] = t10;
|
|
220
|
+
} else {
|
|
221
|
+
t10 = $[10];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const handleItemMouseEnter = t10;
|
|
225
|
+
let t11;
|
|
226
|
+
|
|
227
|
+
if ($[11] !== currentActiveItemEl || $[12] !== registerItem) {
|
|
228
|
+
t11 = {
|
|
229
|
+
currentActiveItemEl,
|
|
230
|
+
setCurrentActiveItemEl,
|
|
231
|
+
registerItem,
|
|
232
|
+
unregisterItem,
|
|
233
|
+
handleItemFocus,
|
|
234
|
+
handleItemKeyDown,
|
|
235
|
+
handleItemMouseEnter
|
|
236
|
+
};
|
|
237
|
+
$[11] = currentActiveItemEl;
|
|
238
|
+
$[12] = registerItem;
|
|
239
|
+
$[13] = t11;
|
|
240
|
+
} else {
|
|
241
|
+
t11 = $[13];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return t11;
|
|
130
245
|
}
|
|
131
246
|
|
|
132
247
|
export { useMenuKeyboardNavigation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/menu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/runtime-corejs3": "^7.26.0",
|
|
20
20
|
"classnames": "^2.2.6",
|
|
21
|
-
"
|
|
21
|
+
"react-compiler-runtime": "^1.0.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@rescui/ui-contexts": "^0.6.0",
|
|
25
25
|
"prop-types": "^15",
|
|
26
|
-
"react": ">=
|
|
26
|
+
"react": ">=17.0.0 <20"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@rescui/colors": "^0.3.
|
|
29
|
+
"@rescui/colors": "^0.3.4",
|
|
30
30
|
"@rescui/postcss-preset-library": "^0.2.3",
|
|
31
|
-
"@rescui/scripts": "^0.5.
|
|
32
|
-
"@rescui/typography": "^0.
|
|
31
|
+
"@rescui/scripts": "^0.5.3",
|
|
32
|
+
"@rescui/typography": "^0.28.0",
|
|
33
33
|
"@rescui/visual-regression": "^0.1.4",
|
|
34
34
|
"postcss": "^8.3.0"
|
|
35
35
|
},
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"build-pcss-api": "rescui-scripts build-pcss-api --file public-api.p.css"
|
|
39
39
|
},
|
|
40
40
|
"nx": {},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "8ffbbe20b8bcbb9ea15204113ab603675d4c03cd"
|
|
42
42
|
}
|