@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.
@@ -1,8 +1,8 @@
1
1
  "use client";
2
- import React, { useRef, useState, useCallback, useMemo, useEffect, cloneElement } from 'react';
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'; // arrow (32) + shadow (10) + shadow blur (~8) + item focus outline (4)
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
- const useScrollableList = _ref2 => {
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
- } = _ref2;
122
- const tabRefs = useRef(new Map()); // reset targeted element on scrolling by arrows
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
- }, setShowArrows] = useState({
130
- showLeftArrow: false,
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
- if (isSelectedItem) {
144
- activeNodeRef.current = node;
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
- const setTabRef = createTabRef(counter, isSelectedItem);
165
- const patchedItem = patchItemIfNeeded({
166
- child,
167
- itemId: counter,
168
- childValue,
169
- ...restProps,
170
- onFocus: e => {
171
- if (onFocusFromProps) {
172
- onFocusFromProps(e);
173
- }
174
-
175
- onFocus(e);
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
- return child;
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
- useEffect(() => {
207
- if (!activeNodeRef.current) {
208
- return;
209
- }
234
+ if (isSelectedItem) {
235
+ setActiveNode(node);
236
+ }
237
+ };
210
238
 
211
- setTargetedEl(activeNodeRef.current);
212
- }, [value, childrenWithValues]);
213
- const setArrowsVisibility = useCallback(() => {
214
- if (!scrollableRef.current) {
215
- return;
216
- }
239
+ $[3] = t5;
240
+ } else {
241
+ t5 = $[3];
242
+ }
217
243
 
218
- setShowArrows(calculateArrowsVisibility(scrollableRef.current));
219
- }, []); // update arrows while smooth scrolling
244
+ const createTabRef = t5;
245
+ let t6;
220
246
 
221
- useEffect(() => {
222
- const scrollContainer = scrollableRef.current;
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
- if (!scrollContainer) {
225
- return null;
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
- scrollContainer.addEventListener('scroll', setArrowsVisibility, {
229
- passive: true
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
- const updateScrollState = () => {
235
- const scrollableEl = scrollableRef.current;
283
+ if ($[11] !== scrollableRef) {
284
+ t8 = () => {
285
+ if (!scrollableRef.current) {
286
+ return;
287
+ }
236
288
 
237
- if (!scrollableEl) {
238
- return;
239
- }
289
+ setShowArrows(calculateArrowsVisibility(scrollableRef.current));
290
+ };
240
291
 
241
- if (targetedEl) {
242
- scrollIntoView(targetedEl, scrollableEl);
243
- }
292
+ $[11] = scrollableRef;
293
+ $[12] = t8;
294
+ } else {
295
+ t8 = $[12];
296
+ }
244
297
 
245
- setArrowsVisibility();
246
- }; // look at the containers resizes
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
- useResizeObserver(containerRef, updateScrollState, {
250
- ignoreFirstCall: true
251
- });
252
- useResizeObserver(scrollableRef, updateScrollState, {
253
- ignoreFirstCall: true
254
- });
255
- useEffect(updateScrollState, [targetedEl, setArrowsVisibility]);
256
- return {
257
- selectedId,
258
- prepareDirectionScroller,
259
- tabRefs,
260
- childrenWithValues,
261
- showLeftArrow,
262
- showRightArrow
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 };
@@ -1,3 +1,8 @@
1
+ @property --_rs-theme-dark-coefficient{
2
+ syntax:'<number>';
3
+ inherits:true;
4
+ initial-value:0;
5
+ }
1
6
  @define-mixin rs-tab-list-size-m{
2
7
  &:not(html){
3
8
  --_rs-tab-list-tab-vertical-padding:8px;
@@ -1,3 +1,8 @@
1
+ @property --_rs-theme-dark-coefficient{
2
+ syntax:'<number>';
3
+ inherits:true;
4
+ initial-value:0;
5
+ }
1
6
  @define-mixin rs-tab-list-size-m{
2
7
  &:not(html){
3
8
  --_rs-tab-list-tab-vertical-padding:8px;
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, ["data-e2e"]: e2eId, compareValues, value, onChange, children, theme: themeFromProps, ...restProps }: TabListProps<T>): React.JSX.Element;
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>;