@rescui/tab-list 0.18.3-RUI-297-Add-react-compiler-to-the-packages-build-dbbefd7b8.10 → 0.18.3-RUI-297-Add-react-compiler-to-the-packages-build-8aaaed4be.39
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/index.css.js +12 -12
- package/lib/_virtual/left-outline.js +294 -63
- package/lib/_virtual/right-outline.js +294 -63
- package/lib/index.css +94 -79
- package/lib/parts/separator.p.module.css.js +3 -3
- package/lib/parts/tab-list-context.js +3 -1
- package/lib/parts/tab-list.p.module.css.js +25 -25
- package/lib/parts/tab-separator.js +30 -6
- package/lib/parts/tab.js +191 -47
- package/lib/parts/use-indicator.d.ts +3 -4
- package/lib/parts/use-indicator.js +131 -47
- package/lib/parts/use-roving-tab-index.js +58 -28
- package/lib/parts/use-scrollable-list.d.ts +2 -2
- package/lib/parts/use-scrollable-list.js +277 -129
- package/lib/public-api.p.css +5 -0
- package/lib/public-api.pcss +5 -0
- package/lib/tab-list.d.ts +1 -1
- package/lib/tab-list.js +378 -82
- package/package.json +9 -8
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
2
|
+
import { c } from 'react-compiler-runtime';
|
|
3
|
+
import React, { useRef, useState, useEffect, cloneElement } from 'react';
|
|
3
4
|
import { useResizeObserver } from '@rescui/use-resize-observer';
|
|
4
|
-
import { deepMap } from './deep-map.js';
|
|
5
|
-
|
|
5
|
+
import { deepMap } from './deep-map.js';
|
|
6
6
|
const ARROW_AREA_WIDTH_IN_PX = 54;
|
|
7
7
|
|
|
8
8
|
function patchItemIfNeeded(_ref) {
|
|
@@ -109,158 +109,306 @@ function scrollIntoView(activeNode, parentNode) {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
let
|
|
112
|
+
function getChildrenWithValues(children, compareValues, value, CompareItem, onFocus, createTabRef) {
|
|
113
|
+
let counter = 0;
|
|
114
|
+
let currentSelectedItemId = null;
|
|
115
|
+
const items = deepMap(children, child => {
|
|
116
|
+
if (child.type === CompareItem) {
|
|
117
|
+
const {
|
|
118
|
+
value: childValue = counter,
|
|
119
|
+
onFocus: onFocusFromProps,
|
|
120
|
+
...restProps
|
|
121
|
+
} = child.props;
|
|
122
|
+
const hasAlreadySelectedItem = currentSelectedItemId === null;
|
|
123
|
+
const isSelectedItem = hasAlreadySelectedItem && compareValues(value, childValue);
|
|
124
|
+
|
|
125
|
+
if (isSelectedItem) {
|
|
126
|
+
currentSelectedItemId = counter;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const setTabRef = createTabRef(counter, isSelectedItem);
|
|
130
|
+
const patchedItem = patchItemIfNeeded({
|
|
131
|
+
child,
|
|
132
|
+
itemId: counter,
|
|
133
|
+
childValue,
|
|
134
|
+
...restProps,
|
|
135
|
+
onFocus: event => {
|
|
136
|
+
if (onFocusFromProps) {
|
|
137
|
+
onFocusFromProps(event);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
onFocus(event);
|
|
141
|
+
},
|
|
142
|
+
ref: node => {
|
|
143
|
+
setTabRef(node);
|
|
144
|
+
const childRef = child.ref;
|
|
145
|
+
|
|
146
|
+
if (typeof childRef === 'function') {
|
|
147
|
+
childRef(node);
|
|
148
|
+
} else if (childRef) {
|
|
149
|
+
childRef.current = node;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
counter += 1;
|
|
154
|
+
return patchedItem;
|
|
155
|
+
} else {
|
|
156
|
+
return child;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
childrenWithValues: React.Children.toArray(items),
|
|
161
|
+
selectedId: currentSelectedItemId
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const useScrollableList = t0 => {
|
|
166
|
+
const $ = c(32);
|
|
167
|
+
const {
|
|
114
168
|
children,
|
|
115
169
|
compareValues,
|
|
116
170
|
value,
|
|
117
171
|
CompareItem,
|
|
118
|
-
activeNodeRef,
|
|
119
172
|
scrollableRef,
|
|
120
173
|
containerRef
|
|
121
|
-
} =
|
|
122
|
-
|
|
123
|
-
// so on window resize there wouldn't scroll to it
|
|
174
|
+
} = t0;
|
|
175
|
+
let t1;
|
|
124
176
|
|
|
177
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
178
|
+
t1 = new Map();
|
|
179
|
+
$[0] = t1;
|
|
180
|
+
} else {
|
|
181
|
+
t1 = $[0];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const tabRefs = useRef(t1);
|
|
125
185
|
const [targetedEl, setTargetedEl] = useState(null);
|
|
126
|
-
const [
|
|
186
|
+
const [activeNode, setActiveNode] = useState(null);
|
|
187
|
+
const [prevActiveNode, setPrevActiveNode] = useState(null);
|
|
188
|
+
|
|
189
|
+
if (activeNode !== prevActiveNode) {
|
|
190
|
+
setPrevActiveNode(activeNode);
|
|
191
|
+
setTargetedEl(activeNode);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let t2;
|
|
195
|
+
|
|
196
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
197
|
+
t2 = {
|
|
198
|
+
showLeftArrow: false,
|
|
199
|
+
showRightArrow: false
|
|
200
|
+
};
|
|
201
|
+
$[1] = t2;
|
|
202
|
+
} else {
|
|
203
|
+
t2 = $[1];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const [t3, setShowArrows] = useState(t2);
|
|
207
|
+
const {
|
|
127
208
|
showLeftArrow,
|
|
128
209
|
showRightArrow
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
showRightArrow: false
|
|
132
|
-
});
|
|
133
|
-
const onFocus = useCallback(e => {
|
|
134
|
-
setTargetedEl(e.target);
|
|
135
|
-
}, []);
|
|
136
|
-
const createTabRef = useCallback((itemId, isSelectedItem) => node => {
|
|
137
|
-
if (node) {
|
|
138
|
-
tabRefs.current.set(itemId, node);
|
|
139
|
-
} else {
|
|
140
|
-
tabRefs.current.delete(itemId);
|
|
141
|
-
}
|
|
210
|
+
} = t3;
|
|
211
|
+
let t4;
|
|
142
212
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const [childrenWithValues, selectedId] = useMemo(() => {
|
|
148
|
-
let counter = 0;
|
|
149
|
-
let currentSelectedItemId = null;
|
|
150
|
-
const items = deepMap(children, child => {
|
|
151
|
-
if (child.type === CompareItem) {
|
|
152
|
-
const {
|
|
153
|
-
value: childValue = counter,
|
|
154
|
-
onFocus: onFocusFromProps,
|
|
155
|
-
...restProps
|
|
156
|
-
} = child.props;
|
|
157
|
-
const hasAlreadySelectedItem = currentSelectedItemId === null;
|
|
158
|
-
const isSelectedItem = hasAlreadySelectedItem && compareValues(value, childValue);
|
|
159
|
-
|
|
160
|
-
if (isSelectedItem) {
|
|
161
|
-
currentSelectedItemId = counter;
|
|
162
|
-
}
|
|
213
|
+
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
214
|
+
t4 = e => {
|
|
215
|
+
setTargetedEl(e.target);
|
|
216
|
+
};
|
|
163
217
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
},
|
|
177
|
-
ref: node => {
|
|
178
|
-
setTabRef(node);
|
|
179
|
-
const childRef = child.ref;
|
|
180
|
-
|
|
181
|
-
if (typeof childRef === 'function') {
|
|
182
|
-
childRef(node);
|
|
183
|
-
} else if (childRef) {
|
|
184
|
-
childRef.current = node;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
counter += 1;
|
|
189
|
-
return patchedItem;
|
|
218
|
+
$[2] = t4;
|
|
219
|
+
} else {
|
|
220
|
+
t4 = $[2];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const onFocus = t4;
|
|
224
|
+
let t5;
|
|
225
|
+
|
|
226
|
+
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
|
|
227
|
+
t5 = (itemId, isSelectedItem) => node => {
|
|
228
|
+
if (node) {
|
|
229
|
+
tabRefs.current.set(itemId, node);
|
|
190
230
|
} else {
|
|
191
|
-
|
|
231
|
+
tabRefs.current.delete(itemId);
|
|
192
232
|
}
|
|
193
|
-
});
|
|
194
|
-
return [React.Children.toArray(items), currentSelectedItemId];
|
|
195
|
-
}, [children, value, compareValues, onFocus, CompareItem, createTabRef]);
|
|
196
|
-
|
|
197
|
-
const prepareDirectionScroller = direction => () => {
|
|
198
|
-
const {
|
|
199
|
-
current
|
|
200
|
-
} = scrollableRef;
|
|
201
|
-
const left = Math.max(current.clientWidth - 2 * ARROW_AREA_WIDTH_IN_PX, 30) * (direction === 'right' ? 1 : -1);
|
|
202
|
-
setTargetedEl(null);
|
|
203
|
-
scrollElementBy(current, left);
|
|
204
|
-
};
|
|
205
233
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
234
|
+
if (isSelectedItem) {
|
|
235
|
+
setActiveNode(node);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
210
238
|
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
239
|
+
$[3] = t5;
|
|
240
|
+
} else {
|
|
241
|
+
t5 = $[3];
|
|
242
|
+
}
|
|
217
243
|
|
|
218
|
-
|
|
219
|
-
|
|
244
|
+
const createTabRef = t5;
|
|
245
|
+
let t6;
|
|
220
246
|
|
|
221
|
-
|
|
222
|
-
|
|
247
|
+
if ($[4] !== CompareItem || $[5] !== children || $[6] !== compareValues || $[7] !== value) {
|
|
248
|
+
t6 = getChildrenWithValues(children, compareValues, value, CompareItem, onFocus, createTabRef);
|
|
249
|
+
$[4] = CompareItem;
|
|
250
|
+
$[5] = children;
|
|
251
|
+
$[6] = compareValues;
|
|
252
|
+
$[7] = value;
|
|
253
|
+
$[8] = t6;
|
|
254
|
+
} else {
|
|
255
|
+
t6 = $[8];
|
|
256
|
+
}
|
|
223
257
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
258
|
+
const {
|
|
259
|
+
childrenWithValues,
|
|
260
|
+
selectedId
|
|
261
|
+
} = t6;
|
|
262
|
+
let t7;
|
|
263
|
+
|
|
264
|
+
if ($[9] !== scrollableRef) {
|
|
265
|
+
t7 = direction => () => {
|
|
266
|
+
const {
|
|
267
|
+
current
|
|
268
|
+
} = scrollableRef;
|
|
269
|
+
const left = Math.max(current.clientWidth - 2 * ARROW_AREA_WIDTH_IN_PX, 30) * (direction === "right" ? 1 : -1);
|
|
270
|
+
setTargetedEl(null);
|
|
271
|
+
scrollElementBy(current, left);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
$[9] = scrollableRef;
|
|
275
|
+
$[10] = t7;
|
|
276
|
+
} else {
|
|
277
|
+
t7 = $[10];
|
|
278
|
+
}
|
|
227
279
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
});
|
|
231
|
-
return () => scrollContainer.removeEventListener('scroll', setArrowsVisibility);
|
|
232
|
-
}, [setArrowsVisibility]); // scrollIntoView active element when it changes or the component resizes
|
|
280
|
+
const prepareDirectionScroller = t7;
|
|
281
|
+
let t8;
|
|
233
282
|
|
|
234
|
-
|
|
235
|
-
|
|
283
|
+
if ($[11] !== scrollableRef) {
|
|
284
|
+
t8 = () => {
|
|
285
|
+
if (!scrollableRef.current) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
236
288
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
289
|
+
setShowArrows(calculateArrowsVisibility(scrollableRef.current));
|
|
290
|
+
};
|
|
240
291
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
292
|
+
$[11] = scrollableRef;
|
|
293
|
+
$[12] = t8;
|
|
294
|
+
} else {
|
|
295
|
+
t8 = $[12];
|
|
296
|
+
}
|
|
244
297
|
|
|
245
|
-
|
|
246
|
-
|
|
298
|
+
const setArrowsVisibility = t8;
|
|
299
|
+
let t10;
|
|
300
|
+
let t9;
|
|
247
301
|
|
|
302
|
+
if ($[13] !== scrollableRef || $[14] !== setArrowsVisibility) {
|
|
303
|
+
t9 = () => {
|
|
304
|
+
const scrollContainer = scrollableRef.current;
|
|
248
305
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
306
|
+
if (!scrollContainer) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
scrollContainer.addEventListener("scroll", setArrowsVisibility, {
|
|
311
|
+
passive: true
|
|
312
|
+
});
|
|
313
|
+
return () => scrollContainer.removeEventListener("scroll", setArrowsVisibility);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
t10 = [scrollableRef, setArrowsVisibility];
|
|
317
|
+
$[13] = scrollableRef;
|
|
318
|
+
$[14] = setArrowsVisibility;
|
|
319
|
+
$[15] = t10;
|
|
320
|
+
$[16] = t9;
|
|
321
|
+
} else {
|
|
322
|
+
t10 = $[15];
|
|
323
|
+
t9 = $[16];
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
useEffect(t9, t10);
|
|
327
|
+
let t11;
|
|
328
|
+
|
|
329
|
+
if ($[17] !== scrollableRef || $[18] !== setArrowsVisibility || $[19] !== targetedEl) {
|
|
330
|
+
t11 = () => {
|
|
331
|
+
const scrollableEl = scrollableRef.current;
|
|
332
|
+
|
|
333
|
+
if (!scrollableEl) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (targetedEl) {
|
|
338
|
+
scrollIntoView(targetedEl, scrollableEl);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
setArrowsVisibility();
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
$[17] = scrollableRef;
|
|
345
|
+
$[18] = setArrowsVisibility;
|
|
346
|
+
$[19] = targetedEl;
|
|
347
|
+
$[20] = t11;
|
|
348
|
+
} else {
|
|
349
|
+
t11 = $[20];
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const updateScrollState = t11;
|
|
353
|
+
let t12;
|
|
354
|
+
|
|
355
|
+
if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
|
|
356
|
+
t12 = {
|
|
357
|
+
ignoreFirstCall: true
|
|
358
|
+
};
|
|
359
|
+
$[21] = t12;
|
|
360
|
+
} else {
|
|
361
|
+
t12 = $[21];
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
useResizeObserver(containerRef, updateScrollState, t12);
|
|
365
|
+
let t13;
|
|
366
|
+
|
|
367
|
+
if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
|
|
368
|
+
t13 = {
|
|
369
|
+
ignoreFirstCall: true
|
|
370
|
+
};
|
|
371
|
+
$[22] = t13;
|
|
372
|
+
} else {
|
|
373
|
+
t13 = $[22];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
useResizeObserver(scrollableRef, updateScrollState, t13);
|
|
377
|
+
let t14;
|
|
378
|
+
|
|
379
|
+
if ($[23] !== updateScrollState) {
|
|
380
|
+
t14 = [updateScrollState];
|
|
381
|
+
$[23] = updateScrollState;
|
|
382
|
+
$[24] = t14;
|
|
383
|
+
} else {
|
|
384
|
+
t14 = $[24];
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
useEffect(updateScrollState, t14);
|
|
388
|
+
let t15;
|
|
389
|
+
|
|
390
|
+
if ($[25] !== activeNode || $[26] !== childrenWithValues || $[27] !== prepareDirectionScroller || $[28] !== selectedId || $[29] !== showLeftArrow || $[30] !== showRightArrow) {
|
|
391
|
+
t15 = {
|
|
392
|
+
selectedId,
|
|
393
|
+
activeNode,
|
|
394
|
+
prepareDirectionScroller,
|
|
395
|
+
tabRefs,
|
|
396
|
+
childrenWithValues,
|
|
397
|
+
showLeftArrow,
|
|
398
|
+
showRightArrow
|
|
399
|
+
};
|
|
400
|
+
$[25] = activeNode;
|
|
401
|
+
$[26] = childrenWithValues;
|
|
402
|
+
$[27] = prepareDirectionScroller;
|
|
403
|
+
$[28] = selectedId;
|
|
404
|
+
$[29] = showLeftArrow;
|
|
405
|
+
$[30] = showRightArrow;
|
|
406
|
+
$[31] = t15;
|
|
407
|
+
} else {
|
|
408
|
+
t15 = $[31];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return t15;
|
|
264
412
|
};
|
|
265
413
|
|
|
266
414
|
export { useScrollableList };
|
package/lib/public-api.p.css
CHANGED
package/lib/public-api.pcss
CHANGED
package/lib/tab-list.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type TabListProps<T extends TabListValueType> = {
|
|
|
25
25
|
compareValues?: ScrollableListCompareValueType<T>;
|
|
26
26
|
};
|
|
27
27
|
declare const TabList: {
|
|
28
|
-
<T extends TabListValueType>({ size, sparse, className, mode, short,
|
|
28
|
+
<T extends TabListValueType>({ size, sparse, className, mode, short, "data-e2e": e2eId, compareValues, value, onChange, children, theme: themeFromProps, ...restProps }: TabListProps<T>): React.JSX.Element;
|
|
29
29
|
displayName: string;
|
|
30
30
|
propTypes: {
|
|
31
31
|
size: PropTypes.Requireable<string>;
|