@rescui/switcher 0.13.5-RUI-297-Add-react-compiler-to-the-packages-build-dbbefd7b8.10 → 0.13.5-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,5 +1,7 @@
1
1
  "use client";
2
- import React, { createContext, useRef, useCallback, useState, useEffect, useContext, cloneElement } from 'react';
2
+ import _extends from '@babel/runtime-corejs3/helpers/esm/extends';
3
+ import { c } from 'react-compiler-runtime';
4
+ import React, { useRef, useState, useEffect, createContext, useContext, cloneElement } from 'react';
3
5
  import PropTypes from 'prop-types';
4
6
  import cn from 'classnames';
5
7
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
@@ -13,7 +15,6 @@ const noop = () => {};
13
15
  const verticalSwitcherContext = /*#__PURE__*/createContext({
14
16
  switcherValue: null,
15
17
  onChange: noop,
16
- handleOptionRef: () => noop,
17
18
  disabled: null,
18
19
  name: null
19
20
  });
@@ -30,212 +31,500 @@ const themeToClass = {
30
31
  const modeToClass = {
31
32
  classic: styles.modeClassic,
32
33
  rock: styles.modeRock
33
- }; // eslint-disable-next-line complexity
34
-
35
- const processOptions = _ref => {
36
- let {
37
- rawOptions,
38
- value,
39
- iconPosition
40
- } = _ref;
41
- const options = [];
42
- let foundIndexByValue = null;
43
- let currentIndex = 0;
44
- let withLeftIcons = false;
45
-
46
- for (const option of rawOptions) {
47
- options.push({
48
- label: option.label,
49
- value: option.value,
50
- icon: option.icon,
51
- 'aria-label': option['aria-label']
52
- });
53
-
54
- if ( /*#__PURE__*/React.isValidElement(option.icon) && iconPosition === 'left') {
55
- withLeftIcons = true;
56
- }
57
-
58
- if (option.value === value && foundIndexByValue === null) {
59
- foundIndexByValue = currentIndex;
60
- }
61
-
62
- currentIndex++;
63
- } // If some options on the first depth level have icons, we should align all other options accordingly
64
-
65
-
66
- if (withLeftIcons) {
67
- options.forEach(option => {
68
- if (! /*#__PURE__*/React.isValidElement(option.icon)) {
69
- option.icon = /*#__PURE__*/React.createElement("span", {
70
- className: styles.fakeIcon
71
- });
72
- }
73
- });
74
- }
34
+ };
75
35
 
76
- return {
77
- options,
78
- activeIndex: foundIndexByValue ?? 0
79
- };
36
+ const findIndexByValue = (options, value) => {
37
+ const index = options.findIndex(option => option.value === value);
38
+ return index === -1 ? 0 : index;
80
39
  }; // check for ignored jsx values and empty string, more info https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored
81
40
 
82
41
 
83
42
  const isNodeEmpty = node => node === null || typeof node === 'undefined' || node === false || node === true || node === '';
84
43
 
85
- function Option(_ref2) {
86
- let {
44
+ function Option(t0) {
45
+ const $ = c(28);
46
+ const {
87
47
  label,
88
48
  value,
89
49
  icon,
90
- index,
91
- 'aria-label': ariaLabel
92
- } = _ref2;
50
+ "aria-label": ariaLabel
51
+ } = t0;
93
52
  const {
94
53
  switcherValue,
95
54
  onChange,
96
- handleOptionRef,
97
55
  disabled,
98
56
  name
99
57
  } = useContext(verticalSwitcherContext);
100
58
  const selected = switcherValue === value;
101
- const isWithoutText = isNodeEmpty(label);
102
- return /*#__PURE__*/React.createElement("label", {
103
- key: String(value),
104
- ref: handleOptionRef(index),
105
- "data-rs-internal": 'vertical-switcher__option',
106
- className: cn(styles.option, selected && styles.selected),
107
- "data-test": cn(`vertical-switcher-option`, selected && ' vertical-switcher-option-selected'),
108
- "aria-label": ariaLabel
109
- }, /*#__PURE__*/React.createElement("input", {
110
- type: "radio",
111
- value: String(value),
112
- onChange: () => onChange(value),
113
- className: styles.radio,
114
- checked: selected,
115
- disabled: disabled,
116
- name: name
117
- }), /*#__PURE__*/React.isValidElement(icon) && /*#__PURE__*/cloneElement(icon, {
118
- className: cn(icon.props.className, styles.icon),
119
- 'data-render-all-sizes': true
120
- }), !isWithoutText && /*#__PURE__*/React.createElement("span", {
121
- className: styles.optionLabel
122
- }, label));
59
+ let t1;
60
+
61
+ if ($[0] !== label) {
62
+ t1 = isNodeEmpty(label);
63
+ $[0] = label;
64
+ $[1] = t1;
65
+ } else {
66
+ t1 = $[1];
67
+ }
68
+
69
+ const isWithoutText = t1;
70
+ const t2 = String(value);
71
+ const t3 = selected && styles.selected;
72
+ let t4;
73
+
74
+ if ($[2] !== t3) {
75
+ t4 = cn(styles.option, t3);
76
+ $[2] = t3;
77
+ $[3] = t4;
78
+ } else {
79
+ t4 = $[3];
80
+ }
81
+
82
+ const t5 = selected && " vertical-switcher-option-selected";
83
+ let t6;
84
+
85
+ if ($[4] !== t5) {
86
+ t6 = cn("vertical-switcher-option", t5);
87
+ $[4] = t5;
88
+ $[5] = t6;
89
+ } else {
90
+ t6 = $[5];
91
+ }
92
+
93
+ const t7 = String(value);
94
+ let t8;
95
+
96
+ if ($[6] !== onChange || $[7] !== value) {
97
+ t8 = () => onChange(value);
98
+
99
+ $[6] = onChange;
100
+ $[7] = value;
101
+ $[8] = t8;
102
+ } else {
103
+ t8 = $[8];
104
+ }
105
+
106
+ let t9;
107
+
108
+ if ($[9] !== disabled || $[10] !== name || $[11] !== selected || $[12] !== t7 || $[13] !== t8) {
109
+ t9 = /*#__PURE__*/React.createElement("input", {
110
+ type: "radio",
111
+ value: t7,
112
+ onChange: t8,
113
+ className: styles.radio,
114
+ checked: selected,
115
+ disabled: disabled,
116
+ name: name
117
+ });
118
+ $[9] = disabled;
119
+ $[10] = name;
120
+ $[11] = selected;
121
+ $[12] = t7;
122
+ $[13] = t8;
123
+ $[14] = t9;
124
+ } else {
125
+ t9 = $[14];
126
+ }
127
+
128
+ let t10;
129
+
130
+ if ($[15] !== icon) {
131
+ t10 = /*#__PURE__*/ /*#__PURE__*/React.isValidElement(icon) && /*#__PURE__*/cloneElement(icon, {
132
+ className: cn(icon.props.className, styles.icon),
133
+ "data-render-all-sizes": true
134
+ });
135
+ $[15] = icon;
136
+ $[16] = t10;
137
+ } else {
138
+ t10 = $[16];
139
+ }
140
+
141
+ let t11;
142
+
143
+ if ($[17] !== isWithoutText || $[18] !== label) {
144
+ t11 = !isWithoutText && /*#__PURE__*/React.createElement("span", {
145
+ className: styles.optionLabel
146
+ }, label);
147
+ $[17] = isWithoutText;
148
+ $[18] = label;
149
+ $[19] = t11;
150
+ } else {
151
+ t11 = $[19];
152
+ }
153
+
154
+ let t12;
155
+
156
+ if ($[20] !== ariaLabel || $[21] !== t10 || $[22] !== t11 || $[23] !== t2 || $[24] !== t4 || $[25] !== t6 || $[26] !== t9) {
157
+ t12 = /*#__PURE__*/React.createElement("label", {
158
+ key: t2,
159
+ "data-rs-internal": "vertical-switcher__option",
160
+ className: t4,
161
+ "data-test": t6,
162
+ "aria-label": ariaLabel
163
+ }, t9, t10, t11);
164
+ $[20] = ariaLabel;
165
+ $[21] = t10;
166
+ $[22] = t11;
167
+ $[23] = t2;
168
+ $[24] = t4;
169
+ $[25] = t6;
170
+ $[26] = t9;
171
+ $[27] = t12;
172
+ } else {
173
+ t12 = $[27];
174
+ }
175
+
176
+ return t12;
123
177
  }
124
178
 
125
- function VerticalSwitcher(_ref3) {
126
- let {
127
- className,
128
- theme: themeFromProps,
129
- size = 'm',
130
- disabled,
131
- options: rawOptions,
132
- value: switcherValue,
133
- mode = 'classic',
134
- iconPosition = 'left',
135
- onChange,
136
- style,
137
- name,
138
- ...rest
139
- } = _ref3;
140
- const refsArray = useRef([]);
179
+ function VerticalSwitcher(t0) {
180
+ const $ = c(65);
181
+ let className;
182
+ let disabled;
183
+ let name;
184
+ let onChange;
185
+ let options;
186
+ let rest;
187
+ let style;
188
+ let switcherValue;
189
+ let t1;
190
+ let t2;
191
+ let t3;
192
+ let themeFromProps;
193
+
194
+ if ($[0] !== t0) {
195
+ ({
196
+ className,
197
+ theme: themeFromProps,
198
+ size: t1,
199
+ disabled,
200
+ options,
201
+ value: switcherValue,
202
+ mode: t2,
203
+ iconPosition: t3,
204
+ onChange,
205
+ style,
206
+ name,
207
+ ...rest
208
+ } = t0);
209
+ $[0] = t0;
210
+ $[1] = className;
211
+ $[2] = disabled;
212
+ $[3] = name;
213
+ $[4] = onChange;
214
+ $[5] = options;
215
+ $[6] = rest;
216
+ $[7] = style;
217
+ $[8] = switcherValue;
218
+ $[9] = t1;
219
+ $[10] = t2;
220
+ $[11] = t3;
221
+ $[12] = themeFromProps;
222
+ } else {
223
+ className = $[1];
224
+ disabled = $[2];
225
+ name = $[3];
226
+ onChange = $[4];
227
+ options = $[5];
228
+ rest = $[6];
229
+ style = $[7];
230
+ switcherValue = $[8];
231
+ t1 = $[9];
232
+ t2 = $[10];
233
+ t3 = $[11];
234
+ themeFromProps = $[12];
235
+ }
236
+
237
+ const size = t1 === undefined ? "m" : t1;
238
+ const mode = t2 === undefined ? "classic" : t2;
239
+ const iconPosition = t3 === undefined ? "left" : t3;
141
240
  const containerRef = useRef(null);
142
241
  const theme = useThemeWithUndefined(themeFromProps);
143
242
  const uniqueId = useSafeId();
144
- const {
145
- options,
146
- activeIndex
147
- } = processOptions({
148
- rawOptions,
149
- value: switcherValue,
150
- iconPosition
151
- });
152
- const handleOptionRef = useCallback(index => ref => {
153
- if (!ref) {
154
- return;
155
- }
243
+ let t4;
156
244
 
157
- if (refsArray.current[index] !== ref) {
158
- refsArray.current[index] = ref;
159
- }
160
- }, []);
161
- const [mark, setMark] = useState({
162
- offset: 0,
163
- height: 0,
164
- hidden: true
165
- });
245
+ if ($[13] !== options || $[14] !== switcherValue) {
246
+ t4 = findIndexByValue(options, switcherValue);
247
+ $[13] = options;
248
+ $[14] = switcherValue;
249
+ $[15] = t4;
250
+ } else {
251
+ t4 = $[15];
252
+ }
253
+
254
+ const activeIndex = t4;
255
+ let t5;
256
+
257
+ if ($[16] !== iconPosition || $[17] !== options) {
258
+ t5 = iconPosition === "left" && options.some(_temp);
259
+ $[16] = iconPosition;
260
+ $[17] = options;
261
+ $[18] = t5;
262
+ } else {
263
+ t5 = $[18];
264
+ }
265
+
266
+ const withLeftIcons = t5;
267
+ let t6;
268
+
269
+ if ($[19] === Symbol.for("react.memo_cache_sentinel")) {
270
+ t6 = {
271
+ offset: 0,
272
+ height: 0,
273
+ hidden: true
274
+ };
275
+ $[19] = t6;
276
+ } else {
277
+ t6 = $[19];
278
+ }
279
+
280
+ const [mark, setMark] = useState(t6);
166
281
  const [isMarkTransitionEnabled, setIsMarkTransitionEnabled] = useState(false);
167
282
  const firstMarkUpdate = useRef(true);
283
+ let t7;
168
284
 
169
- const updateMark = function () {
170
- let isValueChanged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
171
- const activeEl = refsArray.current[activeIndex];
285
+ if ($[20] !== activeIndex) {
286
+ t7 = t8 => {
287
+ const isValueChanged = t8 === undefined ? false : t8;
288
+ const activeEl = containerRef.current?.children.item(activeIndex);
172
289
 
173
- if (!activeEl) {
174
- return;
175
- }
290
+ if (!activeEl) {
291
+ return;
292
+ }
176
293
 
177
- const parentEl = activeEl.parentElement;
178
- const activeElBox = activeEl.getBoundingClientRect();
179
- const parentBox = parentEl.getBoundingClientRect();
180
- setMark({
181
- // standard activeEl.offsetTop always return rounded value, so it does not suit us
182
- offset: activeElBox.top - parentBox.top + parentEl.scrollTop,
183
- height: activeElBox.height,
184
- hidden: false
185
- });
294
+ const parentEl = activeEl.parentElement;
295
+ const activeElBox = activeEl.getBoundingClientRect();
296
+ const parentBox = parentEl.getBoundingClientRect();
297
+ setMark({
298
+ offset: activeElBox.top - parentBox.top + parentEl.scrollTop,
299
+ height: activeElBox.height,
300
+ hidden: false
301
+ });
186
302
 
187
- if (firstMarkUpdate.current) {
188
- firstMarkUpdate.current = false;
189
- setIsMarkTransitionEnabled(false);
190
- } else {
191
- setIsMarkTransitionEnabled(isValueChanged);
192
- }
193
- }; // eslint-disable-next-line react-hooks/exhaustive-deps
194
-
195
-
196
- useEffect(() => updateMark(true), [activeIndex]);
197
- useResizeObserver(containerRef, () => updateMark(false), {
198
- ignoreFirstCall: true
199
- });
200
- return /*#__PURE__*/React.createElement("span", { ...rest,
201
- className: cn(className, styles.verticalSwitcher, sizeToClass[size], themeToClass[theme], modeToClass[mode], disabled && styles.disabled, mark.hidden && styles.hiddenMark, iconPosition === 'right' ? styles.alignIconRight : styles.alignIconLeft),
202
- ref: containerRef,
203
- "data-rs-internal": 'vertical-switcher',
204
- "data-test": cn(`vertical-switcher`, disabled && `vertical-switcher-disabled`),
205
- style: { ...style,
206
- '--_rs-switcher-vertical-mark-transition-duration': isMarkTransitionEnabled ? MARK_TRANSITION_DURATION : '0s'
207
- },
208
- role: "radiogroup"
209
- }, /*#__PURE__*/React.createElement(verticalSwitcherContext.Provider, {
210
- value: {
211
- switcherValue: options[activeIndex]?.value,
303
+ if (firstMarkUpdate.current) {
304
+ firstMarkUpdate.current = false;
305
+ setIsMarkTransitionEnabled(false);
306
+ } else {
307
+ setIsMarkTransitionEnabled(isValueChanged);
308
+ }
309
+ };
310
+
311
+ $[20] = activeIndex;
312
+ $[21] = t7;
313
+ } else {
314
+ t7 = $[21];
315
+ }
316
+
317
+ const updateMark = t7;
318
+ let t8;
319
+ let t9;
320
+
321
+ if ($[22] !== updateMark) {
322
+ t8 = () => updateMark(true);
323
+
324
+ t9 = [updateMark];
325
+ $[22] = updateMark;
326
+ $[23] = t8;
327
+ $[24] = t9;
328
+ } else {
329
+ t8 = $[23];
330
+ t9 = $[24];
331
+ }
332
+
333
+ useEffect(t8, t9);
334
+ let t10;
335
+
336
+ if ($[25] !== updateMark) {
337
+ t10 = () => updateMark(false);
338
+
339
+ $[25] = updateMark;
340
+ $[26] = t10;
341
+ } else {
342
+ t10 = $[26];
343
+ }
344
+
345
+ let t11;
346
+
347
+ if ($[27] === Symbol.for("react.memo_cache_sentinel")) {
348
+ t11 = {
349
+ ignoreFirstCall: true
350
+ };
351
+ $[27] = t11;
352
+ } else {
353
+ t11 = $[27];
354
+ }
355
+
356
+ useResizeObserver(containerRef, t10, t11);
357
+ const t12 = sizeToClass[size];
358
+ const t13 = themeToClass[theme];
359
+ const t14 = modeToClass[mode];
360
+ const t15 = disabled && styles.disabled;
361
+ const t16 = mark.hidden && styles.hiddenMark;
362
+ const t17 = iconPosition === "right" ? styles.alignIconRight : styles.alignIconLeft;
363
+ let t18;
364
+
365
+ if ($[28] !== className || $[29] !== t12 || $[30] !== t13 || $[31] !== t14 || $[32] !== t15 || $[33] !== t16 || $[34] !== t17) {
366
+ t18 = cn(className, styles.verticalSwitcher, t12, t13, t14, t15, t16, t17);
367
+ $[28] = className;
368
+ $[29] = t12;
369
+ $[30] = t13;
370
+ $[31] = t14;
371
+ $[32] = t15;
372
+ $[33] = t16;
373
+ $[34] = t17;
374
+ $[35] = t18;
375
+ } else {
376
+ t18 = $[35];
377
+ }
378
+
379
+ const t19 = disabled && "vertical-switcher-disabled";
380
+ let t20;
381
+
382
+ if ($[36] !== t19) {
383
+ t20 = cn("vertical-switcher", t19);
384
+ $[36] = t19;
385
+ $[37] = t20;
386
+ } else {
387
+ t20 = $[37];
388
+ }
389
+
390
+ const t21 = isMarkTransitionEnabled ? MARK_TRANSITION_DURATION : "0s";
391
+ let t22;
392
+
393
+ if ($[38] !== style || $[39] !== t21) {
394
+ t22 = { ...style,
395
+ "--_rs-switcher-vertical-mark-transition-duration": t21
396
+ };
397
+ $[38] = style;
398
+ $[39] = t21;
399
+ $[40] = t22;
400
+ } else {
401
+ t22 = $[40];
402
+ }
403
+
404
+ const t23 = options[activeIndex]?.value;
405
+ const t24 = name ?? `rs-vertical-switcher-${uniqueId}`;
406
+ let t25;
407
+
408
+ if ($[41] !== disabled || $[42] !== onChange || $[43] !== t23 || $[44] !== t24) {
409
+ t25 = {
410
+ switcherValue: t23,
212
411
  onChange,
213
- handleOptionRef,
214
412
  disabled,
215
- name: name ?? `rs-vertical-switcher-${uniqueId}`
413
+ name: t24
414
+ };
415
+ $[41] = disabled;
416
+ $[42] = onChange;
417
+ $[43] = t23;
418
+ $[44] = t24;
419
+ $[45] = t25;
420
+ } else {
421
+ t25 = $[45];
422
+ }
423
+
424
+ let t26;
425
+
426
+ if ($[46] !== options || $[47] !== withLeftIcons) {
427
+ let t27;
428
+
429
+ if ($[49] !== withLeftIcons) {
430
+ t27 = t28 => {
431
+ const {
432
+ value,
433
+ label,
434
+ icon,
435
+ "aria-label": optionAriaLabel
436
+ } = t28;
437
+ return /*#__PURE__*/React.createElement(Option, {
438
+ key: String(value),
439
+ value: value,
440
+ label: label,
441
+ icon: withLeftIcons && ! /*#__PURE__*/React.isValidElement(icon) ? /*#__PURE__*/React.createElement("span", {
442
+ className: styles.fakeIcon
443
+ }) : icon,
444
+ "aria-label": optionAriaLabel
445
+ });
446
+ };
447
+
448
+ $[49] = withLeftIcons;
449
+ $[50] = t27;
450
+ } else {
451
+ t27 = $[50];
216
452
  }
217
- }, options.map((_ref4, index) => {
218
- let {
219
- value,
220
- label,
221
- icon,
222
- 'aria-label': optionAriaLabel
223
- } = _ref4;
224
- return /*#__PURE__*/React.createElement(Option, {
225
- key: String(value),
226
- value: value,
227
- label: label,
228
- icon: icon,
229
- index: index,
230
- "aria-label": optionAriaLabel
453
+
454
+ t26 = options.map(t27);
455
+ $[46] = options;
456
+ $[47] = withLeftIcons;
457
+ $[48] = t26;
458
+ } else {
459
+ t26 = $[48];
460
+ }
461
+
462
+ let t27;
463
+
464
+ if ($[51] === Symbol.for("react.memo_cache_sentinel")) {
465
+ t27 = cn(styles.mark);
466
+ $[51] = t27;
467
+ } else {
468
+ t27 = $[51];
469
+ }
470
+
471
+ let t28;
472
+
473
+ if ($[52] !== mark.height || $[53] !== mark.offset) {
474
+ t28 = /*#__PURE__*/React.createElement("span", {
475
+ className: t27,
476
+ style: {
477
+ top: mark.offset,
478
+ height: mark.height
479
+ }
231
480
  });
232
- }), /*#__PURE__*/React.createElement("span", {
233
- className: cn(styles.mark),
234
- style: {
235
- top: mark.offset,
236
- height: mark.height
237
- }
238
- })));
481
+ $[52] = mark.height;
482
+ $[53] = mark.offset;
483
+ $[54] = t28;
484
+ } else {
485
+ t28 = $[54];
486
+ }
487
+
488
+ let t29;
489
+
490
+ if ($[55] !== t25 || $[56] !== t26 || $[57] !== t28) {
491
+ t29 = /*#__PURE__*/React.createElement(verticalSwitcherContext.Provider, {
492
+ value: t25
493
+ }, t26, t28);
494
+ $[55] = t25;
495
+ $[56] = t26;
496
+ $[57] = t28;
497
+ $[58] = t29;
498
+ } else {
499
+ t29 = $[58];
500
+ }
501
+
502
+ let t30;
503
+
504
+ if ($[59] !== rest || $[60] !== t18 || $[61] !== t20 || $[62] !== t22 || $[63] !== t29) {
505
+ t30 = /*#__PURE__*/React.createElement("span", _extends({}, rest, {
506
+ className: t18,
507
+ ref: containerRef,
508
+ "data-rs-internal": "vertical-switcher",
509
+ "data-test": t20,
510
+ style: t22,
511
+ role: "radiogroup"
512
+ }), t29);
513
+ $[59] = rest;
514
+ $[60] = t18;
515
+ $[61] = t20;
516
+ $[62] = t22;
517
+ $[63] = t29;
518
+ $[64] = t30;
519
+ } else {
520
+ t30 = $[64];
521
+ }
522
+
523
+ return t30;
524
+ }
525
+
526
+ function _temp(option) {
527
+ return /*#__PURE__*/React.isValidElement(option.icon);
239
528
  }
240
529
 
241
530
  const optionPropType = PropTypes.shape({