@rescui/collapse 0.8.4-RUI-297-Add-react-compiler-to-the-packages-build-dbbefd7b8.10 → 0.8.4-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,192 +1,138 @@
1
1
  "use client";
2
2
  import { c } from 'react-compiler-runtime';
3
- import { useReducer, useRef, useLayoutEffect } from 'react';
3
+ import { useState, useEffect, useLayoutEffect } from 'react';
4
+ const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
5
+
6
+ const getCollapseTransition = element => element.getAnimations().find(animation => animation.transitionProperty === 'grid-template-rows');
7
+
4
8
  var COLLAPSE_STATES;
5
9
 
6
10
  (function (COLLAPSE_STATES) {
7
11
  COLLAPSE_STATES["OPENING"] = "OPENING";
8
12
  COLLAPSE_STATES["OPEN"] = "OPEN";
9
- COLLAPSE_STATES["CLOSING_PREPARE"] = "CLOSING_PREPARE";
10
13
  COLLAPSE_STATES["CLOSING"] = "CLOSING";
11
14
  COLLAPSE_STATES["CLOSE"] = "CLOSE";
12
15
  })(COLLAPSE_STATES || (COLLAPSE_STATES = {}));
13
16
 
14
- function forceLayoutRecalculation(element) {
15
- 'use no memo'; // eslint-disable-next-line no-unused-expressions
16
-
17
- element.offsetHeight;
18
- }
19
-
20
- function getInitialState(_ref) {
21
- let {
22
- shouldBeOpened,
23
- cancelAnimation
24
- } = _ref;
25
-
26
- if (!shouldBeOpened) {
27
- return COLLAPSE_STATES.CLOSE;
28
- }
29
-
30
- return cancelAnimation ? COLLAPSE_STATES.OPEN : COLLAPSE_STATES.OPENING;
31
- }
32
-
33
- function getStateForTarget(state, shouldBeOpened, cancelAnimation) {
34
- if (cancelAnimation) {
35
- return shouldBeOpened ? COLLAPSE_STATES.OPEN : COLLAPSE_STATES.CLOSE;
36
- }
37
-
17
+ function getStateForTarget(state, shouldBeOpened) {
38
18
  if (shouldBeOpened) {
39
- // Closing has not started visually yet, so there is nothing to animate back.
40
- if (state === COLLAPSE_STATES.CLOSING_PREPARE) {
41
- return COLLAPSE_STATES.OPEN;
42
- }
43
-
44
19
  return state === COLLAPSE_STATES.OPEN || state === COLLAPSE_STATES.OPENING ? state : COLLAPSE_STATES.OPENING;
45
20
  }
46
21
 
47
- if (state === COLLAPSE_STATES.CLOSE || state === COLLAPSE_STATES.CLOSING_PREPARE || state === COLLAPSE_STATES.CLOSING) {
22
+ if (state === COLLAPSE_STATES.CLOSE || state === COLLAPSE_STATES.CLOSING) {
48
23
  return state;
49
24
  }
50
25
 
51
- return state === COLLAPSE_STATES.OPEN ? COLLAPSE_STATES.CLOSING_PREPARE : COLLAPSE_STATES.CLOSING;
52
- }
53
-
54
- function collapseReducer(state, action) {
55
- switch (action.type) {
56
- case 'TARGET_CHANGED':
57
- return getStateForTarget(state, action.shouldBeOpened, action.cancelAnimation);
58
-
59
- case 'CLOSING_READY':
60
- return state === COLLAPSE_STATES.CLOSING_PREPARE ? COLLAPSE_STATES.CLOSING : state;
61
-
62
- case 'TRANSITION_END':
63
- if (action.shouldBeOpened && state === COLLAPSE_STATES.OPENING) {
64
- return COLLAPSE_STATES.OPEN;
65
- }
66
-
67
- if (!action.shouldBeOpened && state === COLLAPSE_STATES.CLOSING) {
68
- return COLLAPSE_STATES.CLOSE;
69
- }
70
-
71
- return state;
72
-
73
- default:
74
- return state;
75
- }
26
+ return COLLAPSE_STATES.CLOSING;
76
27
  }
77
28
 
78
29
  function useCollapseState(t0) {
79
- const $ = c(16);
30
+ const $ = c(5);
80
31
  const {
81
32
  shouldBeOpened,
82
- cancelAnimation
33
+ contentRef
83
34
  } = t0;
35
+ const [state, setState] = useState(shouldBeOpened ? COLLAPSE_STATES.OPEN : COLLAPSE_STATES.CLOSE);
84
36
  let t1;
85
37
 
86
- if ($[0] !== cancelAnimation || $[1] !== shouldBeOpened) {
87
- t1 = {
88
- shouldBeOpened,
89
- cancelAnimation
38
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
39
+ t1 = expectedState => {
40
+ setState(currentState => {
41
+ if (currentState !== expectedState) {
42
+ return currentState;
43
+ }
44
+
45
+ if (expectedState === COLLAPSE_STATES.OPENING) {
46
+ return COLLAPSE_STATES.OPEN;
47
+ }
48
+
49
+ if (expectedState === COLLAPSE_STATES.CLOSING) {
50
+ return COLLAPSE_STATES.CLOSE;
51
+ }
52
+
53
+ return currentState;
54
+ });
90
55
  };
91
- $[0] = cancelAnimation;
92
- $[1] = shouldBeOpened;
93
- $[2] = t1;
56
+
57
+ $[0] = t1;
94
58
  } else {
95
- t1 = $[2];
59
+ t1 = $[0];
96
60
  }
97
61
 
98
- const [state, dispatch] = useReducer(collapseReducer, t1, getInitialState);
99
- const contentRef = useRef(null);
62
+ const completeTransition = t1;
100
63
  let t2;
101
64
  let t3;
102
65
 
103
- if ($[3] !== cancelAnimation || $[4] !== shouldBeOpened) {
66
+ if ($[1] !== contentRef || $[2] !== state) {
104
67
  t2 = () => {
105
- dispatch({
106
- type: "TARGET_CHANGED",
107
- shouldBeOpened,
108
- cancelAnimation
109
- });
110
- };
111
-
112
- t3 = [shouldBeOpened, cancelAnimation];
113
- $[3] = cancelAnimation;
114
- $[4] = shouldBeOpened;
115
- $[5] = t2;
116
- $[6] = t3;
117
- } else {
118
- t2 = $[5];
119
- t3 = $[6];
120
- }
68
+ if (state !== COLLAPSE_STATES.OPENING && state !== COLLAPSE_STATES.CLOSING) {
69
+ return;
70
+ }
121
71
 
122
- useLayoutEffect(t2, t3);
123
- let t4;
124
- let t5;
72
+ const contentElement = contentRef.current;
125
73
 
126
- if ($[7] !== state) {
127
- t4 = () => {
128
- if (state !== COLLAPSE_STATES.CLOSING_PREPARE) {
74
+ if (!contentElement) {
129
75
  return;
130
76
  }
131
77
 
132
- const frame = requestAnimationFrame(() => {
133
- if (contentRef.current) {
134
- forceLayoutRecalculation(contentRef.current);
78
+ let isCurrentPhase = true;
79
+
80
+ const completeCurrentPhase = () => {
81
+ if (isCurrentPhase) {
82
+ completeTransition(state);
135
83
  }
84
+ };
136
85
 
137
- dispatch({
138
- type: "CLOSING_READY"
139
- });
140
- });
141
- return () => cancelAnimationFrame(frame);
142
- };
86
+ const waitForCurrentTransition = previousTransition => {
87
+ if (!isCurrentPhase) {
88
+ return Promise.resolve();
89
+ }
143
90
 
144
- t5 = [state];
145
- $[7] = state;
146
- $[8] = t4;
147
- $[9] = t5;
148
- } else {
149
- t4 = $[8];
150
- t5 = $[9];
151
- }
91
+ const transition = getCollapseTransition(contentElement);
152
92
 
153
- useLayoutEffect(t4, t5);
154
- let t6;
93
+ if (!transition || transition === previousTransition) {
94
+ return Promise.resolve();
95
+ }
155
96
 
156
- if ($[10] !== shouldBeOpened) {
157
- t6 = () => {
158
- dispatch({
159
- type: "TRANSITION_END",
160
- shouldBeOpened
161
- });
97
+ return transition.finished.then(() => {
98
+ if (!isCurrentPhase) {
99
+ return Promise.resolve();
100
+ }
101
+
102
+ const replacementTransition = getCollapseTransition(contentElement);
103
+
104
+ if (replacementTransition && replacementTransition !== transition) {
105
+ return waitForCurrentTransition(transition);
106
+ }
107
+
108
+ return Promise.resolve();
109
+ }, () => waitForCurrentTransition(transition));
110
+ };
111
+
112
+ waitForCurrentTransition().then(completeCurrentPhase);
113
+ return () => {
114
+ isCurrentPhase = false;
115
+ };
162
116
  };
163
117
 
164
- $[10] = shouldBeOpened;
165
- $[11] = t6;
118
+ t3 = [completeTransition, contentRef, state];
119
+ $[1] = contentRef;
120
+ $[2] = state;
121
+ $[3] = t2;
122
+ $[4] = t3;
166
123
  } else {
167
- t6 = $[11];
124
+ t2 = $[3];
125
+ t3 = $[4];
168
126
  }
169
127
 
170
- const onAnimationEnd = t6;
171
- const t7 = state === COLLAPSE_STATES.CLOSING_PREPARE;
172
- let t8;
128
+ useIsomorphicLayoutEffect(t2, t3);
129
+ const stateForTarget = getStateForTarget(state, shouldBeOpened);
173
130
 
174
- if ($[12] !== onAnimationEnd || $[13] !== state || $[14] !== t7) {
175
- t8 = {
176
- contentRef,
177
- isStartedClosing: t7,
178
- onAnimationEnd,
179
- state
180
- };
181
- $[12] = onAnimationEnd;
182
- $[13] = state;
183
- $[14] = t7;
184
- $[15] = t8;
185
- } else {
186
- t8 = $[15];
131
+ if (stateForTarget !== state) {
132
+ setState(stateForTarget);
187
133
  }
188
134
 
189
- return t8;
135
+ return state;
190
136
  }
191
137
 
192
138
  export { COLLAPSE_STATES, useCollapseState };
@@ -1,3 +1,4 @@
1
1
  import React from 'react';
2
- export declare function useFallbackId(): number;
2
+ declare function useFallbackId(): number;
3
3
  export declare const useSafeId: typeof React.useId | typeof useFallbackId;
4
+ export {};
@@ -7,4 +7,4 @@ function useFallbackId() {
7
7
  }
8
8
 
9
9
  const useSafeId = React.useId ?? useFallbackId;
10
- export { useFallbackId, useSafeId };
10
+ export { useSafeId };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescui/collapse",
3
- "version": "0.8.4-RUI-297-Add-react-compiler-to-the-packages-build-dbbefd7b8.10+dbbefd7b8",
3
+ "version": "0.8.4-RUI-297-Add-react-compiler-to-the-packages-build-8aaaed4be.39+8aaaed4be",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
@@ -17,7 +17,6 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/runtime-corejs3": "^7.26.0",
20
- "@rescui/use-resize-observer": "0.3.4-RUI-297-Add-react-compiler-to-the-packages-build-dbbefd7b8.10+dbbefd7b8",
21
20
  "classnames": "^2.2.6",
22
21
  "react-compiler-runtime": "^1.0.0"
23
22
  },
@@ -27,16 +26,16 @@
27
26
  "react": ">=17.0.0 <20"
28
27
  },
29
28
  "devDependencies": {
30
- "@rescui/colors": "0.3.3-RUI-297-Add-react-compiler-to-the-packages-build-dbbefd7b8.14+dbbefd7b8",
29
+ "@rescui/colors": "0.3.3-RUI-297-Add-react-compiler-to-the-packages-build-8aaaed4be.43+8aaaed4be",
31
30
  "@rescui/scripts": "0.5.2",
32
- "@rescui/typography": "0.27.3-RUI-297-Add-react-compiler-to-the-packages-build-dbbefd7b8.14+dbbefd7b8",
31
+ "@rescui/typography": "0.27.3-RUI-297-Add-react-compiler-to-the-packages-build-8aaaed4be.43+8aaaed4be",
33
32
  "@rescui/visual-regression": "0.1.4",
34
33
  "@types/classnames": "^2.2.11"
35
34
  },
36
35
  "scripts": {
37
- "build": "rescui-scripts build --react-compiler-target 17 && yarn run build-pcss-api",
36
+ "build": "rescui-scripts build && yarn run build-pcss-api",
38
37
  "build-pcss-api": "rescui-scripts build-pcss-api --file public-api.p.css"
39
38
  },
40
39
  "nx": {},
41
- "gitHead": "dbbefd7b8e24da18262edf3baffa35039ae01af3"
40
+ "gitHead": "8aaaed4bee650c002b7f195438380b70c31cc5a4"
42
41
  }