@rescui/collapse 0.8.2 → 0.8.4-RUI-297-Add-react-compiler-to-the-packages-build-dbbefd7b8.10

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/collapse.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use client";
2
- import React, { useRef, useContext, useState, useEffect } from 'react';
2
+ import _extends from '@babel/runtime-corejs3/helpers/esm/extends';
3
+ import { c } from 'react-compiler-runtime';
4
+ import React, { useState, useContext, useRef, useEffect } from 'react';
3
5
  import cn from 'classnames';
4
6
  import PropTypes from 'prop-types';
5
7
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
@@ -7,13 +9,9 @@ import { useResizeObserver } from '@rescui/use-resize-observer';
7
9
  import RightIcon from './_virtual/right.js';
8
10
  import PlusIcon from './_virtual/plus.js';
9
11
  import { collapseContext } from './context.js';
10
- import { useCollapseState, COLLAPSE_STATES, useStartedClosing } from './use-collapse-state.js';
12
+ import { useCollapseState, COLLAPSE_STATES } from './use-collapse-state.js';
13
+ import { useSafeId } from './use-safe-id.js';
11
14
  import styles from './collapse.p.module.css.js';
12
-
13
- function getRandId() {
14
- return Math.random().toString(36).substring(7);
15
- }
16
-
17
15
  const THEME_STYLES = {
18
16
  light: styles.themeLight,
19
17
  dark: styles.themeDark
@@ -34,26 +32,83 @@ const ICON_STYLES = {
34
32
  arrow: styles.iconArrow
35
33
  };
36
34
  const Collapse = /*#__PURE__*/React.forwardRef( // eslint-disable-next-line complexity
37
- (_ref, ref) => {
38
- let {
39
- children,
40
- className,
41
- openedClassName: openedClassnameFromProps,
42
- size: sizeFromProps,
43
- mode: modeFromProps,
44
- icon: iconFromProps,
45
- borderBottom: borderBottomFromProps,
46
- disableLeftPadding: disableLeftPaddingFromProps,
47
- title,
48
- isDefaultOpened = false,
49
- theme: themeFromProps,
50
- itemKey,
51
- ...restProps
52
- } = _ref;
53
- // using the trick from https://github.com/Yaska/react-use-id-hook/
54
- const {
55
- current: key
56
- } = useRef(itemKey ?? getRandId());
35
+ (t0, ref) => {
36
+ const $ = c(71);
37
+ let borderBottomFromProps;
38
+ let children;
39
+ let className;
40
+ let disableLeftPaddingFromProps;
41
+ let iconFromProps;
42
+ let itemKey;
43
+ let modeFromProps;
44
+ let openedClassnameFromProps;
45
+ let restProps;
46
+ let sizeFromProps;
47
+ let t1;
48
+ let themeFromProps;
49
+ let title;
50
+
51
+ if ($[0] !== t0) {
52
+ ({
53
+ children,
54
+ className,
55
+ openedClassName: openedClassnameFromProps,
56
+ size: sizeFromProps,
57
+ mode: modeFromProps,
58
+ icon: iconFromProps,
59
+ borderBottom: borderBottomFromProps,
60
+ disableLeftPadding: disableLeftPaddingFromProps,
61
+ title,
62
+ isDefaultOpened: t1,
63
+ theme: themeFromProps,
64
+ itemKey,
65
+ ...restProps
66
+ } = t0);
67
+ $[0] = t0;
68
+ $[1] = borderBottomFromProps;
69
+ $[2] = children;
70
+ $[3] = className;
71
+ $[4] = disableLeftPaddingFromProps;
72
+ $[5] = iconFromProps;
73
+ $[6] = itemKey;
74
+ $[7] = modeFromProps;
75
+ $[8] = openedClassnameFromProps;
76
+ $[9] = restProps;
77
+ $[10] = sizeFromProps;
78
+ $[11] = t1;
79
+ $[12] = themeFromProps;
80
+ $[13] = title;
81
+ } else {
82
+ borderBottomFromProps = $[1];
83
+ children = $[2];
84
+ className = $[3];
85
+ disableLeftPaddingFromProps = $[4];
86
+ iconFromProps = $[5];
87
+ itemKey = $[6];
88
+ modeFromProps = $[7];
89
+ openedClassnameFromProps = $[8];
90
+ restProps = $[9];
91
+ sizeFromProps = $[10];
92
+ t1 = $[11];
93
+ themeFromProps = $[12];
94
+ title = $[13];
95
+ }
96
+
97
+ const isDefaultOpened = t1 === undefined ? false : t1;
98
+ const uniqueId = useSafeId();
99
+ let t2;
100
+
101
+ if ($[14] !== itemKey || $[15] !== uniqueId) {
102
+ t2 = () => itemKey ?? uniqueId;
103
+
104
+ $[14] = itemKey;
105
+ $[15] = uniqueId;
106
+ $[16] = t2;
107
+ } else {
108
+ t2 = $[16];
109
+ }
110
+
111
+ const [key] = useState(t2);
57
112
  const theme = useThemeWithUndefined(themeFromProps);
58
113
  const {
59
114
  openedKey,
@@ -68,92 +123,260 @@ const Collapse = /*#__PURE__*/React.forwardRef( // eslint-disable-next-line comp
68
123
  disableLeftPadding: disableLeftPaddingFromContext,
69
124
  openedClassName: openedClassNameFromContext
70
125
  } = useContext(collapseContext);
71
- const size = sizeFromProps ?? sizeFromContext ?? 'm';
72
- const mode = modeFromProps ?? modeFromContext ?? 'classic';
73
- const icon = iconFromProps ?? iconFromContext ?? 'left-plus';
126
+ const size = sizeFromProps ?? sizeFromContext ?? "m";
127
+ const mode = modeFromProps ?? modeFromContext ?? "classic";
128
+ const icon = iconFromProps ?? iconFromContext ?? "left-plus";
74
129
  const borderBottom = borderBottomFromProps ?? borderBottomFromContext ?? false;
75
130
  const disableLeftPadding = disableLeftPaddingFromProps ?? disableLeftPaddingFromContext ?? false;
76
- const openedClassName = openedClassnameFromProps ?? openedClassNameFromContext; // height calculations
77
-
131
+ const openedClassName = openedClassnameFromProps ?? openedClassNameFromContext;
78
132
  const resizeRef = useRef(null);
79
- const [height, setHeight] = useState('initial');
80
- useResizeObserver(resizeRef, entry => setHeight(entry.target.offsetHeight));
81
- const isHeightCalculated = height !== 'initial'; // this state is ignored in accordion
133
+ const [height, setHeight] = useState("initial");
134
+ let t3;
135
+
136
+ if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
137
+ t3 = entry => setHeight(entry.target.offsetHeight);
138
+
139
+ $[17] = t3;
140
+ } else {
141
+ t3 = $[17];
142
+ }
82
143
 
83
- const [shouldBeOpenedLocal, setShouldBeOpenedLocal] = useState(isDefaultOpened); // boolean state. ignores CLOSING and OPENING states
144
+ useResizeObserver(resizeRef, t3);
145
+ const isHeightCalculated = height !== "initial";
146
+ const [shouldBeOpenedLocal, setShouldBeOpenedLocal] = useState(isDefaultOpened);
147
+ const shouldBeOpened = isInAccordion ? openedKey === key : shouldBeOpenedLocal;
148
+ const t4 = !isHeightCalculated;
149
+ let t5;
84
150
 
85
- const shouldBeOpened = isInAccordion ? openedKey === key : shouldBeOpenedLocal; // add CLOSING and OPENING states.
151
+ if ($[18] !== shouldBeOpened || $[19] !== t4) {
152
+ t5 = {
153
+ shouldBeOpened,
154
+ cancelAnimation: t4
155
+ };
156
+ $[18] = shouldBeOpened;
157
+ $[19] = t4;
158
+ $[20] = t5;
159
+ } else {
160
+ t5 = $[20];
161
+ }
86
162
 
87
163
  const {
164
+ contentRef,
165
+ isStartedClosing,
88
166
  onAnimationEnd: handleTransitionEnd,
89
167
  state: collapseState
90
- } = useCollapseState({
91
- shouldBeOpened,
92
- // because how css transitions work, we shouldn't use OPENING and CLOSING states while height still calculating
93
- // it also allows us to skip animation on the first renders
94
- cancelAnimation: !isHeightCalculated
95
- });
168
+ } = useCollapseState(t5);
96
169
  const isOpening = collapseState === COLLAPSE_STATES.OPENING;
97
170
  const isOpened = collapseState === COLLAPSE_STATES.OPEN;
98
- const isClosing = collapseState === COLLAPSE_STATES.CLOSING;
171
+ const isClosing = collapseState === COLLAPSE_STATES.CLOSING_PREPARE || collapseState === COLLAPSE_STATES.CLOSING;
99
172
  const isClosed = collapseState === COLLAPSE_STATES.CLOSE;
100
- const {
101
- isStartedClosing,
102
- contentRef
103
- } = useStartedClosing(collapseState);
104
- const isRightIcon = icon === 'right-plus';
105
- const Icon = icon === 'arrow' ? RightIcon : PlusIcon;
106
-
107
- const toggleOpened = () => {
108
- if (toggleActiveKey) {
109
- toggleActiveKey(key);
110
- } // this state update does nothing in accordion
111
-
112
-
113
- setShouldBeOpenedLocal(!shouldBeOpened);
114
- };
115
-
116
- useEffect(() => {
117
- // for uncontrolled accordion, tell it that this collapse is opened by default
118
- if (isInAccordion && !isInControlledAccordion && isDefaultOpened && setActiveKey) {
119
- setActiveKey(key);
120
- }
121
- }, []);
122
- return /*#__PURE__*/React.createElement("div", {
123
- "data-test": 'collapse',
124
- ...restProps,
125
- className: cn(className, styles.main, isOpening && styles.opening, isOpened && styles.opened, isClosing && !isStartedClosing && styles.closingTransition, isClosing && styles.closing, isClosed && styles.closed, !isClosed && openedClassName, SIZE_STYLES[size], MODE_STYLES[mode], ICON_STYLES[icon], borderBottom && styles.hasBorderBottom, disableLeftPadding && styles.disableLeftPadding, isRightIcon ? styles.rightIcon : styles.leftIcon, THEME_STYLES[theme]),
126
- "data-rs-internal": "collapse__collapse",
127
- ref: ref
128
- }, /*#__PURE__*/React.createElement("button", {
129
- type: "button",
130
- "data-test": 'collapse__button',
131
- "data-rs-internal": "collapse__button",
132
- className: styles.button,
133
- onClick: toggleOpened
134
- }, /*#__PURE__*/React.createElement(Icon, {
135
- className: styles.icon,
136
- "data-render-all-sizes": true
137
- }), /*#__PURE__*/React.createElement("span", {
138
- className: cn(styles.title),
139
- "data-rs-internal": "collapse__title"
140
- }, title)), /*#__PURE__*/React.createElement("div", {
141
- className: styles.content,
142
- "data-rs-internal": "collapse__content",
143
- style: {
144
- // So, we set the height value only on OPENING stage and just after beginning CLOSING stage
145
- // The reason we don't leave this style for OPEN stage is because some content of the expanded Collapse may change its height dynamically
146
- // This will be processed by resizeObserver, but some devices may lag behind
147
- // And to make collapsing transition work, we need to have a frame with numbered height value before starting the collapse transition
148
- height: isOpening || isStartedClosing ? height : null
149
- },
150
- ref: contentRef,
151
- onTransitionEnd: handleTransitionEnd,
152
- tabIndex: -1
153
- }, /*#__PURE__*/React.createElement("div", {
154
- ref: resizeRef,
155
- className: styles.innerWrapper
156
- }, children)));
173
+ const isRightIcon = icon === "right-plus";
174
+ const Icon = icon === "arrow" ? RightIcon : PlusIcon;
175
+ let t6;
176
+
177
+ if ($[21] !== key || $[22] !== shouldBeOpened || $[23] !== toggleActiveKey) {
178
+ t6 = () => {
179
+ if (toggleActiveKey) {
180
+ toggleActiveKey(key);
181
+ }
182
+
183
+ setShouldBeOpenedLocal(!shouldBeOpened);
184
+ };
185
+
186
+ $[21] = key;
187
+ $[22] = shouldBeOpened;
188
+ $[23] = toggleActiveKey;
189
+ $[24] = t6;
190
+ } else {
191
+ t6 = $[24];
192
+ }
193
+
194
+ const toggleOpened = t6;
195
+ let t7;
196
+
197
+ if ($[25] !== isDefaultOpened || $[26] !== isInAccordion || $[27] !== isInControlledAccordion || $[28] !== key || $[29] !== setActiveKey) {
198
+ t7 = () => {
199
+ if (isInAccordion && !isInControlledAccordion && isDefaultOpened && setActiveKey) {
200
+ setActiveKey(key);
201
+ }
202
+ };
203
+
204
+ $[25] = isDefaultOpened;
205
+ $[26] = isInAccordion;
206
+ $[27] = isInControlledAccordion;
207
+ $[28] = key;
208
+ $[29] = setActiveKey;
209
+ $[30] = t7;
210
+ } else {
211
+ t7 = $[30];
212
+ }
213
+
214
+ let t8;
215
+
216
+ if ($[31] === Symbol.for("react.memo_cache_sentinel")) {
217
+ t8 = [];
218
+ $[31] = t8;
219
+ } else {
220
+ t8 = $[31];
221
+ }
222
+
223
+ useEffect(t7, t8);
224
+ const t9 = isOpening && styles.opening;
225
+ const t10 = isOpened && styles.opened;
226
+ const t11 = isClosing && !isStartedClosing && styles.closingTransition;
227
+ const t12 = isClosing && styles.closing;
228
+ const t13 = isClosed && styles.closed;
229
+ const t14 = !isClosed && openedClassName;
230
+ const t15 = SIZE_STYLES[size];
231
+ const t16 = MODE_STYLES[mode];
232
+ const t17 = ICON_STYLES[icon];
233
+ const t18 = borderBottom && styles.hasBorderBottom;
234
+ const t19 = disableLeftPadding && styles.disableLeftPadding;
235
+ const t20 = isRightIcon ? styles.rightIcon : styles.leftIcon;
236
+ const t21 = THEME_STYLES[theme];
237
+ let t22;
238
+
239
+ if ($[32] !== className || $[33] !== t10 || $[34] !== t11 || $[35] !== t12 || $[36] !== t13 || $[37] !== t14 || $[38] !== t15 || $[39] !== t16 || $[40] !== t17 || $[41] !== t18 || $[42] !== t19 || $[43] !== t20 || $[44] !== t21 || $[45] !== t9) {
240
+ t22 = cn(className, styles.main, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21);
241
+ $[32] = className;
242
+ $[33] = t10;
243
+ $[34] = t11;
244
+ $[35] = t12;
245
+ $[36] = t13;
246
+ $[37] = t14;
247
+ $[38] = t15;
248
+ $[39] = t16;
249
+ $[40] = t17;
250
+ $[41] = t18;
251
+ $[42] = t19;
252
+ $[43] = t20;
253
+ $[44] = t21;
254
+ $[45] = t9;
255
+ $[46] = t22;
256
+ } else {
257
+ t22 = $[46];
258
+ }
259
+
260
+ let t23;
261
+
262
+ if ($[47] !== Icon) {
263
+ t23 = /*#__PURE__*/React.createElement(Icon, {
264
+ className: styles.icon,
265
+ "data-render-all-sizes": true
266
+ });
267
+ $[47] = Icon;
268
+ $[48] = t23;
269
+ } else {
270
+ t23 = $[48];
271
+ }
272
+
273
+ let t24;
274
+
275
+ if ($[49] === Symbol.for("react.memo_cache_sentinel")) {
276
+ t24 = cn(styles.title);
277
+ $[49] = t24;
278
+ } else {
279
+ t24 = $[49];
280
+ }
281
+
282
+ let t25;
283
+
284
+ if ($[50] !== title) {
285
+ t25 = /*#__PURE__*/React.createElement("span", {
286
+ className: t24,
287
+ "data-rs-internal": "collapse__title"
288
+ }, title);
289
+ $[50] = title;
290
+ $[51] = t25;
291
+ } else {
292
+ t25 = $[51];
293
+ }
294
+
295
+ let t26;
296
+
297
+ if ($[52] !== t23 || $[53] !== t25 || $[54] !== toggleOpened) {
298
+ t26 = /*#__PURE__*/React.createElement("button", {
299
+ type: "button",
300
+ "data-test": "collapse__button",
301
+ "data-rs-internal": "collapse__button",
302
+ className: styles.button,
303
+ onClick: toggleOpened
304
+ }, t23, t25);
305
+ $[52] = t23;
306
+ $[53] = t25;
307
+ $[54] = toggleOpened;
308
+ $[55] = t26;
309
+ } else {
310
+ t26 = $[55];
311
+ }
312
+
313
+ const t27 = isOpening || isStartedClosing ? height : null;
314
+ let t28;
315
+
316
+ if ($[56] !== t27) {
317
+ t28 = {
318
+ height: t27
319
+ };
320
+ $[56] = t27;
321
+ $[57] = t28;
322
+ } else {
323
+ t28 = $[57];
324
+ }
325
+
326
+ let t29;
327
+
328
+ if ($[58] !== children) {
329
+ t29 = /*#__PURE__*/React.createElement("div", {
330
+ ref: resizeRef,
331
+ className: styles.innerWrapper
332
+ }, children);
333
+ $[58] = children;
334
+ $[59] = t29;
335
+ } else {
336
+ t29 = $[59];
337
+ }
338
+
339
+ let t30;
340
+
341
+ if ($[60] !== contentRef || $[61] !== handleTransitionEnd || $[62] !== t28 || $[63] !== t29) {
342
+ t30 = /*#__PURE__*/React.createElement("div", {
343
+ className: styles.content,
344
+ "data-rs-internal": "collapse__content",
345
+ style: t28,
346
+ ref: contentRef,
347
+ onTransitionEnd: handleTransitionEnd,
348
+ tabIndex: -1
349
+ }, t29);
350
+ $[60] = contentRef;
351
+ $[61] = handleTransitionEnd;
352
+ $[62] = t28;
353
+ $[63] = t29;
354
+ $[64] = t30;
355
+ } else {
356
+ t30 = $[64];
357
+ }
358
+
359
+ let t31;
360
+
361
+ if ($[65] !== ref || $[66] !== restProps || $[67] !== t22 || $[68] !== t26 || $[69] !== t30) {
362
+ t31 = /*#__PURE__*/React.createElement("div", _extends({
363
+ "data-test": "collapse"
364
+ }, restProps, {
365
+ className: t22,
366
+ "data-rs-internal": "collapse__collapse",
367
+ ref: ref
368
+ }), t26, t30);
369
+ $[65] = ref;
370
+ $[66] = restProps;
371
+ $[67] = t22;
372
+ $[68] = t26;
373
+ $[69] = t30;
374
+ $[70] = t31;
375
+ } else {
376
+ t31 = $[70];
377
+ }
378
+
379
+ return t31;
157
380
  });
158
381
  Collapse.displayName = 'Collapse';
159
382
  Collapse.propTypes = {
@@ -1,35 +1,35 @@
1
1
  var styles = {
2
- "themeLight": "_themeLight_1m6emg9_6",
3
- "themeDark": "_themeDark_1m6emg9_9",
4
- "sizeS": "_sizeS_1m6emg9_13",
5
- "sizeM": "_sizeM_1m6emg9_16",
6
- "sizeL": "_sizeL_1m6emg9_19",
7
- "classic": "_classic_1m6emg9_23",
8
- "rock": "_rock_1m6emg9_26",
9
- "clear": "_clear_1m6emg9_29",
10
- "hasBorderBottom": "_hasBorderBottom_1m6emg9_33",
11
- "leftIcon": "_leftIcon_1m6emg9_37",
12
- "rightIcon": "_rightIcon_1m6emg9_40",
13
- "disableLeftPadding": "_disableLeftPadding_1m6emg9_44",
14
- "main": "_main_1m6emg9_48",
15
- "opening": "_opening_1m6emg9_59",
16
- "opened": "_opened_1m6emg9_60",
17
- "closing": "_closing_1m6emg9_61",
18
- "title": "_title_1m6emg9_95",
19
- "content": "_content_1m6emg9_103",
20
- "closed": "_closed_1m6emg9_111",
21
- "closingTransition": "_closingTransition_1m6emg9_120",
22
- "innerWrapper": "_innerWrapper_1m6emg9_127",
23
- "button": "_button_1m6emg9_133",
24
- "icon": "_icon_1m6emg9_186",
25
- "iconPlus": "_iconPlus_1m6emg9_202",
26
- "iconArrow": "_iconArrow_1m6emg9_207",
27
- "accordion": "_accordion_1m6emg9_213",
28
- "accordionGap0": "_accordionGap0_1m6emg9_218",
29
- "accordionGap8": "_accordionGap8_1m6emg9_221",
30
- "accordionGap12": "_accordionGap12_1m6emg9_224",
31
- "accordionGap16": "_accordionGap16_1m6emg9_227",
32
- "accordionGap24": "_accordionGap24_1m6emg9_230",
33
- "accordionGap32": "_accordionGap32_1m6emg9_233"
2
+ "themeLight": "_themeLight_1t0qfuj_6",
3
+ "themeDark": "_themeDark_1t0qfuj_9",
4
+ "sizeS": "_sizeS_1t0qfuj_13",
5
+ "sizeM": "_sizeM_1t0qfuj_16",
6
+ "sizeL": "_sizeL_1t0qfuj_19",
7
+ "classic": "_classic_1t0qfuj_23",
8
+ "rock": "_rock_1t0qfuj_26",
9
+ "clear": "_clear_1t0qfuj_29",
10
+ "hasBorderBottom": "_hasBorderBottom_1t0qfuj_33",
11
+ "leftIcon": "_leftIcon_1t0qfuj_37",
12
+ "rightIcon": "_rightIcon_1t0qfuj_40",
13
+ "disableLeftPadding": "_disableLeftPadding_1t0qfuj_44",
14
+ "main": "_main_1t0qfuj_48",
15
+ "opening": "_opening_1t0qfuj_59",
16
+ "opened": "_opened_1t0qfuj_60",
17
+ "closing": "_closing_1t0qfuj_61",
18
+ "title": "_title_1t0qfuj_95",
19
+ "content": "_content_1t0qfuj_103",
20
+ "closed": "_closed_1t0qfuj_111",
21
+ "closingTransition": "_closingTransition_1t0qfuj_120",
22
+ "innerWrapper": "_innerWrapper_1t0qfuj_127",
23
+ "button": "_button_1t0qfuj_133",
24
+ "icon": "_icon_1t0qfuj_186",
25
+ "iconPlus": "_iconPlus_1t0qfuj_202",
26
+ "iconArrow": "_iconArrow_1t0qfuj_207",
27
+ "accordion": "_accordion_1t0qfuj_213",
28
+ "accordionGap0": "_accordionGap0_1t0qfuj_218",
29
+ "accordionGap8": "_accordionGap8_1t0qfuj_221",
30
+ "accordionGap12": "_accordionGap12_1t0qfuj_224",
31
+ "accordionGap16": "_accordionGap16_1t0qfuj_227",
32
+ "accordionGap24": "_accordionGap24_1t0qfuj_230",
33
+ "accordionGap32": "_accordionGap32_1t0qfuj_233"
34
34
  };
35
35
  export { styles as default };