@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.
package/lib/switcher.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use client";
2
- import React, { cloneElement, useRef, useCallback, useState, useEffect } 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, cloneElement } from 'react';
3
5
  import PropTypes from 'prop-types';
4
6
  import cn from 'classnames';
5
7
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
@@ -30,8 +32,9 @@ const findIndexByValue = (options, value) => {
30
32
 
31
33
  const isNodeEmpty = node => node === null || typeof node === 'undefined' || node === false || node === true || node === '';
32
34
 
33
- const optionRenderer = (_ref, ref) => {
34
- let {
35
+ const Option = t0 => {
36
+ const $ = c(22);
37
+ const {
35
38
  label,
36
39
  value,
37
40
  icon,
@@ -39,132 +42,391 @@ const optionRenderer = (_ref, ref) => {
39
42
  onChange,
40
43
  selected,
41
44
  name,
42
- 'aria-label': ariaLabel
43
- } = _ref;
44
- const isWithoutText = isNodeEmpty(label);
45
- return /*#__PURE__*/React.createElement("label", {
46
- ref: ref,
47
- key: String(value),
48
- "data-rs-internal": 'switcher__option',
49
- className: cn(styles.option, selected && styles.selected),
50
45
  "aria-label": ariaLabel
51
- }, /*#__PURE__*/React.createElement("input", {
52
- type: "radio",
53
- value: String(value),
54
- onChange: onChange,
55
- className: styles.radio,
56
- checked: selected,
57
- disabled: disabled,
58
- name: name
59
- }), /*#__PURE__*/React.isValidElement(icon) && /*#__PURE__*/cloneElement(icon, {
60
- className: cn(icon.props.className, styles.icon),
61
- 'data-render-all-sizes': true
62
- }), !isWithoutText && /*#__PURE__*/React.createElement("span", null, label));
46
+ } = t0;
47
+ let t1;
48
+
49
+ if ($[0] !== label) {
50
+ t1 = isNodeEmpty(label);
51
+ $[0] = label;
52
+ $[1] = t1;
53
+ } else {
54
+ t1 = $[1];
55
+ }
56
+
57
+ const isWithoutText = t1;
58
+ const t2 = String(value);
59
+ const t3 = selected && styles.selected;
60
+ let t4;
61
+
62
+ if ($[2] !== t3) {
63
+ t4 = cn(styles.option, t3);
64
+ $[2] = t3;
65
+ $[3] = t4;
66
+ } else {
67
+ t4 = $[3];
68
+ }
69
+
70
+ const t5 = String(value);
71
+ let t6;
72
+
73
+ if ($[4] !== disabled || $[5] !== name || $[6] !== onChange || $[7] !== selected || $[8] !== t5) {
74
+ t6 = /*#__PURE__*/React.createElement("input", {
75
+ type: "radio",
76
+ value: t5,
77
+ onChange: onChange,
78
+ className: styles.radio,
79
+ checked: selected,
80
+ disabled: disabled,
81
+ name: name
82
+ });
83
+ $[4] = disabled;
84
+ $[5] = name;
85
+ $[6] = onChange;
86
+ $[7] = selected;
87
+ $[8] = t5;
88
+ $[9] = t6;
89
+ } else {
90
+ t6 = $[9];
91
+ }
92
+
93
+ let t7;
94
+
95
+ if ($[10] !== icon) {
96
+ t7 = /*#__PURE__*/ /*#__PURE__*/React.isValidElement(icon) && /*#__PURE__*/cloneElement(icon, {
97
+ className: cn(icon.props.className, styles.icon),
98
+ "data-render-all-sizes": true
99
+ });
100
+ $[10] = icon;
101
+ $[11] = t7;
102
+ } else {
103
+ t7 = $[11];
104
+ }
105
+
106
+ let t8;
107
+
108
+ if ($[12] !== isWithoutText || $[13] !== label) {
109
+ t8 = !isWithoutText && /*#__PURE__*/React.createElement("span", null, label);
110
+ $[12] = isWithoutText;
111
+ $[13] = label;
112
+ $[14] = t8;
113
+ } else {
114
+ t8 = $[14];
115
+ }
116
+
117
+ let t9;
118
+
119
+ if ($[15] !== ariaLabel || $[16] !== t2 || $[17] !== t4 || $[18] !== t6 || $[19] !== t7 || $[20] !== t8) {
120
+ t9 = /*#__PURE__*/React.createElement("label", {
121
+ key: t2,
122
+ "data-rs-internal": "switcher__option",
123
+ className: t4,
124
+ "aria-label": ariaLabel
125
+ }, t6, t7, t8);
126
+ $[15] = ariaLabel;
127
+ $[16] = t2;
128
+ $[17] = t4;
129
+ $[18] = t6;
130
+ $[19] = t7;
131
+ $[20] = t8;
132
+ $[21] = t9;
133
+ } else {
134
+ t9 = $[21];
135
+ }
136
+
137
+ return t9;
63
138
  };
64
139
 
65
- const Option = /*#__PURE__*/React.forwardRef(optionRenderer);
140
+ function Switcher(t0) {
141
+ const $ = c(57);
142
+ let className;
143
+ let disabled;
144
+ let name;
145
+ let onChange;
146
+ let options;
147
+ let rest;
148
+ let style;
149
+ let switcherValue;
150
+ let t1;
151
+ let t2;
152
+ let t3;
153
+ let t4;
154
+ let themeFromProps;
66
155
 
67
- function Switcher(_ref2) {
68
- let {
69
- className,
70
- theme: themeFromProps,
71
- size = 'm',
72
- disabled,
73
- compact = false,
74
- options,
75
- value: switcherValue,
76
- mode = 'classic',
77
- iconPosition = 'left',
78
- onChange,
79
- style,
80
- name,
81
- ...rest
82
- } = _ref2;
83
- const refsArray = useRef([]);
156
+ if ($[0] !== t0) {
157
+ ({
158
+ className,
159
+ theme: themeFromProps,
160
+ size: t1,
161
+ disabled,
162
+ compact: t2,
163
+ options,
164
+ value: switcherValue,
165
+ mode: t3,
166
+ iconPosition: t4,
167
+ onChange,
168
+ style,
169
+ name,
170
+ ...rest
171
+ } = t0);
172
+ $[0] = t0;
173
+ $[1] = className;
174
+ $[2] = disabled;
175
+ $[3] = name;
176
+ $[4] = onChange;
177
+ $[5] = options;
178
+ $[6] = rest;
179
+ $[7] = style;
180
+ $[8] = switcherValue;
181
+ $[9] = t1;
182
+ $[10] = t2;
183
+ $[11] = t3;
184
+ $[12] = t4;
185
+ $[13] = themeFromProps;
186
+ } else {
187
+ className = $[1];
188
+ disabled = $[2];
189
+ name = $[3];
190
+ onChange = $[4];
191
+ options = $[5];
192
+ rest = $[6];
193
+ style = $[7];
194
+ switcherValue = $[8];
195
+ t1 = $[9];
196
+ t2 = $[10];
197
+ t3 = $[11];
198
+ t4 = $[12];
199
+ themeFromProps = $[13];
200
+ }
201
+
202
+ const size = t1 === undefined ? "m" : t1;
203
+ const compact = t2 === undefined ? false : t2;
204
+ const mode = t3 === undefined ? "classic" : t3;
205
+ const iconPosition = t4 === undefined ? "left" : t4;
84
206
  const containerRef = useRef(null);
85
207
  const theme = useThemeWithUndefined(themeFromProps);
86
208
  const uniqueId = useSafeId();
87
- const handleOptionRef = useCallback(index => ref => {
88
- if (!ref) {
89
- return;
90
- }
91
-
92
- if (refsArray.current[index] !== ref) {
93
- refsArray.current[index] = ref;
94
- }
95
- }, []);
96
- const activeIndex = findIndexByValue(options, switcherValue);
97
- const [mark, setMark] = useState({
98
- offset: 0,
99
- width: 0,
100
- hidden: true
101
- });
209
+ let t5;
210
+
211
+ if ($[14] !== options || $[15] !== switcherValue) {
212
+ t5 = findIndexByValue(options, switcherValue);
213
+ $[14] = options;
214
+ $[15] = switcherValue;
215
+ $[16] = t5;
216
+ } else {
217
+ t5 = $[16];
218
+ }
219
+
220
+ const activeIndex = t5;
221
+ let t6;
222
+
223
+ if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
224
+ t6 = {
225
+ offset: 0,
226
+ width: 0,
227
+ hidden: true
228
+ };
229
+ $[17] = t6;
230
+ } else {
231
+ t6 = $[17];
232
+ }
233
+
234
+ const [mark, setMark] = useState(t6);
102
235
  const [isMarkTransitionEnabled, setIsMarkTransitionEnabled] = useState(false);
103
236
  const firstMarkUpdate = useRef(true);
237
+ let t7;
238
+
239
+ if ($[18] !== activeIndex) {
240
+ t7 = t8 => {
241
+ const isValueChanged = t8 === undefined ? false : t8;
242
+ const activeEl = containerRef.current?.children.item(activeIndex);
104
243
 
105
- const updateMark = function () {
106
- let isValueChanged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
107
- const activeEl = refsArray.current[activeIndex];
108
-
109
- if (!activeEl) {
110
- return;
111
- }
112
-
113
- const activeElBox = activeEl.getBoundingClientRect();
114
- const parentBox = activeEl.parentElement.getBoundingClientRect();
115
- setMark({
116
- // standard activeEl.offsetLeft always return rounded value, so it does not suit us
117
- offset: activeElBox.left - parentBox.left,
118
- width: activeElBox.width,
119
- hidden: false
244
+ if (!activeEl) {
245
+ return;
246
+ }
247
+
248
+ const activeElBox = activeEl.getBoundingClientRect();
249
+ const parentBox = activeEl.parentElement.getBoundingClientRect();
250
+ setMark({
251
+ offset: activeElBox.left - parentBox.left,
252
+ width: activeElBox.width,
253
+ hidden: false
254
+ });
255
+
256
+ if (firstMarkUpdate.current) {
257
+ firstMarkUpdate.current = false;
258
+ setIsMarkTransitionEnabled(false);
259
+ } else {
260
+ setIsMarkTransitionEnabled(isValueChanged);
261
+ }
262
+ };
263
+
264
+ $[18] = activeIndex;
265
+ $[19] = t7;
266
+ } else {
267
+ t7 = $[19];
268
+ }
269
+
270
+ const updateMark = t7;
271
+ let t8;
272
+ let t9;
273
+
274
+ if ($[20] !== updateMark) {
275
+ t8 = () => updateMark(true);
276
+
277
+ t9 = [updateMark];
278
+ $[20] = updateMark;
279
+ $[21] = t8;
280
+ $[22] = t9;
281
+ } else {
282
+ t8 = $[21];
283
+ t9 = $[22];
284
+ }
285
+
286
+ useEffect(t8, t9);
287
+ let t10;
288
+
289
+ if ($[23] !== updateMark) {
290
+ t10 = () => updateMark(false);
291
+
292
+ $[23] = updateMark;
293
+ $[24] = t10;
294
+ } else {
295
+ t10 = $[24];
296
+ }
297
+
298
+ useResizeObserver(containerRef, t10);
299
+ const t11 = sizeToClass[size];
300
+ const t12 = themeToClass[theme];
301
+ const t13 = modeToClass[mode];
302
+ const t14 = disabled && styles.disabled;
303
+ const t15 = compact && styles.compact;
304
+ const t16 = mark.hidden && styles.hiddenMark;
305
+ const t17 = iconPosition === "right" ? styles.alignIconRight : styles.alignIconLeft;
306
+ let t18;
307
+
308
+ if ($[25] !== className || $[26] !== t11 || $[27] !== t12 || $[28] !== t13 || $[29] !== t14 || $[30] !== t15 || $[31] !== t16 || $[32] !== t17) {
309
+ t18 = cn(className, styles.switcher, t11, t12, t13, t14, t15, t16, t17);
310
+ $[25] = className;
311
+ $[26] = t11;
312
+ $[27] = t12;
313
+ $[28] = t13;
314
+ $[29] = t14;
315
+ $[30] = t15;
316
+ $[31] = t16;
317
+ $[32] = t17;
318
+ $[33] = t18;
319
+ } else {
320
+ t18 = $[33];
321
+ }
322
+
323
+ const t19 = disabled && "switcher-disabled";
324
+ let t20;
325
+
326
+ if ($[34] !== t19) {
327
+ t20 = cn("switcher", t19);
328
+ $[34] = t19;
329
+ $[35] = t20;
330
+ } else {
331
+ t20 = $[35];
332
+ }
333
+
334
+ const t21 = isMarkTransitionEnabled ? MARK_TRANSITION_DURATION : "0s";
335
+ let t22;
336
+
337
+ if ($[36] !== style || $[37] !== t21) {
338
+ t22 = { ...style,
339
+ "--_rs-switcher-mark-transition-duration": t21
340
+ };
341
+ $[36] = style;
342
+ $[37] = t21;
343
+ $[38] = t22;
344
+ } else {
345
+ t22 = $[38];
346
+ }
347
+
348
+ let t23;
349
+
350
+ if ($[39] !== activeIndex || $[40] !== disabled || $[41] !== name || $[42] !== onChange || $[43] !== options || $[44] !== uniqueId) {
351
+ t23 = options.map((t24, index) => {
352
+ const {
353
+ value,
354
+ label,
355
+ icon,
356
+ "aria-label": optionAriaLabel
357
+ } = t24;
358
+ return /*#__PURE__*/React.createElement(Option, {
359
+ key: String(value),
360
+ value: value,
361
+ label: label,
362
+ icon: icon,
363
+ disabled: disabled,
364
+ onChange: () => onChange(value),
365
+ selected: options[activeIndex]?.value === value,
366
+ name: name ?? `rs-switcher-${uniqueId}`,
367
+ "aria-label": optionAriaLabel
368
+ });
120
369
  });
370
+ $[39] = activeIndex;
371
+ $[40] = disabled;
372
+ $[41] = name;
373
+ $[42] = onChange;
374
+ $[43] = options;
375
+ $[44] = uniqueId;
376
+ $[45] = t23;
377
+ } else {
378
+ t23 = $[45];
379
+ }
121
380
 
122
- if (firstMarkUpdate.current) {
123
- firstMarkUpdate.current = false;
124
- setIsMarkTransitionEnabled(false);
125
- } else {
126
- setIsMarkTransitionEnabled(isValueChanged);
127
- }
128
- }; // eslint-disable-next-line react-hooks/exhaustive-deps
129
-
130
-
131
- useEffect(() => updateMark(true), [activeIndex]);
132
- useResizeObserver(containerRef, () => updateMark(false));
133
- return /*#__PURE__*/React.createElement("span", { ...rest,
134
- className: cn(className, styles.switcher, sizeToClass[size], themeToClass[theme], modeToClass[mode], disabled && styles.disabled, compact && styles.compact, mark.hidden && styles.hiddenMark, iconPosition === 'right' ? styles.alignIconRight : styles.alignIconLeft),
135
- ref: containerRef,
136
- "data-rs-internal": 'switcher',
137
- "data-test": cn(`switcher`, disabled && `switcher-disabled`),
138
- style: { ...style,
139
- '--_rs-switcher-mark-transition-duration': isMarkTransitionEnabled ? MARK_TRANSITION_DURATION : '0s'
140
- },
141
- role: "radiogroup"
142
- }, options.map((_ref3, index) => {
143
- let {
144
- value,
145
- label,
146
- icon,
147
- 'aria-label': optionAriaLabel
148
- } = _ref3;
149
- return /*#__PURE__*/React.createElement(Option, {
150
- key: String(value),
151
- value: value,
152
- label: label,
153
- icon: icon,
154
- disabled: disabled,
155
- onChange: () => onChange(value),
156
- ref: handleOptionRef(index),
157
- selected: options[activeIndex]?.value === value,
158
- name: name ?? `rs-switcher-${uniqueId}`,
159
- "aria-label": optionAriaLabel
381
+ let t24;
382
+
383
+ if ($[46] === Symbol.for("react.memo_cache_sentinel")) {
384
+ t24 = cn(styles.mark);
385
+ $[46] = t24;
386
+ } else {
387
+ t24 = $[46];
388
+ }
389
+
390
+ let t25;
391
+
392
+ if ($[47] !== mark.offset || $[48] !== mark.width) {
393
+ t25 = /*#__PURE__*/React.createElement("span", {
394
+ className: t24,
395
+ style: {
396
+ left: mark.offset,
397
+ width: mark.width
398
+ }
160
399
  });
161
- }), /*#__PURE__*/React.createElement("span", {
162
- className: cn(styles.mark),
163
- style: {
164
- left: mark.offset,
165
- width: mark.width
166
- }
167
- }));
400
+ $[47] = mark.offset;
401
+ $[48] = mark.width;
402
+ $[49] = t25;
403
+ } else {
404
+ t25 = $[49];
405
+ }
406
+
407
+ let t26;
408
+
409
+ if ($[50] !== rest || $[51] !== t18 || $[52] !== t20 || $[53] !== t22 || $[54] !== t23 || $[55] !== t25) {
410
+ t26 = /*#__PURE__*/React.createElement("span", _extends({}, rest, {
411
+ className: t18,
412
+ ref: containerRef,
413
+ "data-rs-internal": "switcher",
414
+ "data-test": t20,
415
+ style: t22,
416
+ role: "radiogroup"
417
+ }), t23, t25);
418
+ $[50] = rest;
419
+ $[51] = t18;
420
+ $[52] = t20;
421
+ $[53] = t22;
422
+ $[54] = t23;
423
+ $[55] = t25;
424
+ $[56] = t26;
425
+ } else {
426
+ t26 = $[56];
427
+ }
428
+
429
+ return t26;
168
430
  }
169
431
 
170
432
  const optionPropType = PropTypes.shape({
@@ -1,22 +1,22 @@
1
1
  var styles = {
2
- "themeLight": "_themeLight_1wk58a3_6",
3
- "themeDark": "_themeDark_1wk58a3_9",
4
- "sizeXS": "_sizeXS_1wk58a3_13",
5
- "sizeS": "_sizeS_1wk58a3_16",
6
- "sizeM": "_sizeM_1wk58a3_19",
7
- "sizeL": "_sizeL_1wk58a3_22",
8
- "modeClassic": "_modeClassic_1wk58a3_26",
9
- "modeRock": "_modeRock_1wk58a3_29",
10
- "compact": "_compact_1wk58a3_33",
11
- "switcher": "_switcher_1wk58a3_37",
12
- "disabled": "_disabled_1wk58a3_55",
13
- "alignIconLeft": "_alignIconLeft_1wk58a3_60",
14
- "alignIconRight": "_alignIconRight_1wk58a3_63",
15
- "option": "_option_1wk58a3_67",
16
- "selected": "_selected_1wk58a3_118",
17
- "hiddenMark": "_hiddenMark_1wk58a3_127",
18
- "icon": "_icon_1wk58a3_158",
19
- "mark": "_mark_1wk58a3_171",
20
- "radio": "_radio_1wk58a3_199"
2
+ "themeLight": "_themeLight_1m1pz9v_6",
3
+ "themeDark": "_themeDark_1m1pz9v_9",
4
+ "sizeXS": "_sizeXS_1m1pz9v_13",
5
+ "sizeS": "_sizeS_1m1pz9v_16",
6
+ "sizeM": "_sizeM_1m1pz9v_19",
7
+ "sizeL": "_sizeL_1m1pz9v_22",
8
+ "modeClassic": "_modeClassic_1m1pz9v_26",
9
+ "modeRock": "_modeRock_1m1pz9v_29",
10
+ "compact": "_compact_1m1pz9v_33",
11
+ "switcher": "_switcher_1m1pz9v_37",
12
+ "disabled": "_disabled_1m1pz9v_55",
13
+ "alignIconLeft": "_alignIconLeft_1m1pz9v_60",
14
+ "alignIconRight": "_alignIconRight_1m1pz9v_63",
15
+ "option": "_option_1m1pz9v_67",
16
+ "selected": "_selected_1m1pz9v_118",
17
+ "hiddenMark": "_hiddenMark_1m1pz9v_127",
18
+ "icon": "_icon_1m1pz9v_158",
19
+ "mark": "_mark_1m1pz9v_171",
20
+ "radio": "_radio_1m1pz9v_199"
21
21
  };
22
22
  export { styles as default };
@@ -1,2 +1,4 @@
1
1
  import React from 'react';
2
- export declare const useSafeId: typeof React.useId;
2
+ declare function useFallbackId(): number;
3
+ export declare const useSafeId: typeof React.useId | typeof useFallbackId;
4
+ export {};
@@ -1,15 +1,10 @@
1
- import React, { useRef } from 'react';
1
+ import React, { useState } from 'react';
2
+ let nextFallbackId = 0;
2
3
 
3
- const useFallbackId = () => {
4
- const id = useRef(null);
4
+ function useFallbackId() {
5
+ const [id] = useState(() => nextFallbackId++);
6
+ return id;
7
+ }
5
8
 
6
- if (id.current === null) {
7
- id.current = useFallbackId.counter++;
8
- }
9
-
10
- return id.current.toString();
11
- };
12
-
13
- useFallbackId.counter = 0;
14
9
  const useSafeId = React.useId ?? useFallbackId;
15
10
  export { useSafeId };
@@ -40,7 +40,7 @@ interface VerticalSwitcherExplicitProps<ValueType, OptionsValueType extends Valu
40
40
  name?: string;
41
41
  }
42
42
  export type VerticalSwitcherProps<ValueType, OptionsValueType extends ValueType> = VerticalSwitcherExplicitProps<ValueType, OptionsValueType> & Omit<React.HTMLProps<HTMLSpanElement>, keyof VerticalSwitcherExplicitProps<ValueType, OptionsValueType>>;
43
- export declare function VerticalSwitcher<ValueType, OptionsValueType extends ValueType = ValueType>({ className, theme: themeFromProps, size, disabled, options: rawOptions, value: switcherValue, mode, iconPosition, onChange, style, name, ...rest }: VerticalSwitcherProps<ValueType, OptionsValueType>): JSX.Element;
43
+ export declare function VerticalSwitcher<ValueType, OptionsValueType extends ValueType = ValueType>({ className, theme: themeFromProps, size, disabled, options, value: switcherValue, mode, iconPosition, onChange, style, name, ...rest }: VerticalSwitcherProps<ValueType, OptionsValueType>): JSX.Element;
44
44
  export declare namespace VerticalSwitcher {
45
45
  var propTypes: {
46
46
  options: PropTypes.Validator<PropTypes.InferProps<{