@rescui/collapse 0.8.4-RUI-297-Add-react-compiler-to-the-packages-build-f15074a13.11 → 0.8.5
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/_virtual/index.css.js +12 -12
- package/lib/accordion.js +34 -155
- package/lib/collapse.js +89 -322
- package/lib/collapse.p.module.css.js +32 -32
- package/lib/index.css +104 -82
- package/lib/public-api.p.css +5 -0
- package/lib/public-api.pcss +5 -0
- package/lib/use-collapse-state.d.ts +4 -9
- package/lib/use-collapse-state.js +70 -145
- package/lib/use-safe-id.d.ts +2 -1
- package/lib/use-safe-id.js +1 -1
- package/package.json +9 -11
|
@@ -1,192 +1,117 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { useState, useCallback, useEffect, useLayoutEffect } from 'react';
|
|
3
|
+
const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
4
|
+
|
|
5
|
+
const getCollapseTransition = element => element.getAnimations().find(animation => animation.transitionProperty === 'grid-template-rows');
|
|
6
|
+
|
|
4
7
|
var COLLAPSE_STATES;
|
|
5
8
|
|
|
6
9
|
(function (COLLAPSE_STATES) {
|
|
7
10
|
COLLAPSE_STATES["OPENING"] = "OPENING";
|
|
8
11
|
COLLAPSE_STATES["OPEN"] = "OPEN";
|
|
9
|
-
COLLAPSE_STATES["CLOSING_PREPARE"] = "CLOSING_PREPARE";
|
|
10
12
|
COLLAPSE_STATES["CLOSING"] = "CLOSING";
|
|
11
13
|
COLLAPSE_STATES["CLOSE"] = "CLOSE";
|
|
12
14
|
})(COLLAPSE_STATES || (COLLAPSE_STATES = {}));
|
|
13
15
|
|
|
14
|
-
function
|
|
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
|
-
|
|
16
|
+
function getStateForTarget(state, shouldBeOpened) {
|
|
38
17
|
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
18
|
return state === COLLAPSE_STATES.OPEN || state === COLLAPSE_STATES.OPENING ? state : COLLAPSE_STATES.OPENING;
|
|
45
19
|
}
|
|
46
20
|
|
|
47
|
-
if (state === COLLAPSE_STATES.CLOSE || state === COLLAPSE_STATES.
|
|
21
|
+
if (state === COLLAPSE_STATES.CLOSE || state === COLLAPSE_STATES.CLOSING) {
|
|
48
22
|
return state;
|
|
49
23
|
}
|
|
50
24
|
|
|
51
|
-
return
|
|
25
|
+
return COLLAPSE_STATES.CLOSING;
|
|
52
26
|
}
|
|
53
27
|
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
28
|
+
function useCollapseState(_ref) {
|
|
29
|
+
let {
|
|
30
|
+
shouldBeOpened,
|
|
31
|
+
contentRef
|
|
32
|
+
} = _ref;
|
|
33
|
+
const [state, setState] = useState(shouldBeOpened ? COLLAPSE_STATES.OPEN : COLLAPSE_STATES.CLOSE);
|
|
34
|
+
const completeTransition = useCallback(expectedState => {
|
|
35
|
+
setState(currentState => {
|
|
36
|
+
if (currentState !== expectedState) {
|
|
37
|
+
return currentState;
|
|
38
|
+
}
|
|
61
39
|
|
|
62
|
-
|
|
63
|
-
if (action.shouldBeOpened && state === COLLAPSE_STATES.OPENING) {
|
|
40
|
+
if (expectedState === COLLAPSE_STATES.OPENING) {
|
|
64
41
|
return COLLAPSE_STATES.OPEN;
|
|
65
42
|
}
|
|
66
43
|
|
|
67
|
-
if (
|
|
44
|
+
if (expectedState === COLLAPSE_STATES.CLOSING) {
|
|
68
45
|
return COLLAPSE_STATES.CLOSE;
|
|
69
46
|
}
|
|
70
47
|
|
|
71
|
-
return
|
|
48
|
+
return currentState;
|
|
49
|
+
});
|
|
50
|
+
}, []); // Track the grid track transition that currently belongs to OPENING/CLOSING:
|
|
51
|
+
// - normally, complete the phase after the track reaches its target;
|
|
52
|
+
// - a direction change can replace the transition, so follow the latest one;
|
|
53
|
+
// - if the phase changes, cleanup invalidates its waiter, so an old
|
|
54
|
+
// transition cannot complete a newer phase;
|
|
55
|
+
// - if no transition is created (for example, its duration is 0s), complete
|
|
56
|
+
// the phase immediately.
|
|
57
|
+
|
|
58
|
+
useIsomorphicLayoutEffect(() => {
|
|
59
|
+
if (state !== COLLAPSE_STATES.OPENING && state !== COLLAPSE_STATES.CLOSING) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
72
62
|
|
|
73
|
-
|
|
74
|
-
return state;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
63
|
+
const contentElement = contentRef.current;
|
|
77
64
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
shouldBeOpened,
|
|
82
|
-
cancelAnimation
|
|
83
|
-
} = t0;
|
|
84
|
-
let t1;
|
|
85
|
-
|
|
86
|
-
if ($[0] !== cancelAnimation || $[1] !== shouldBeOpened) {
|
|
87
|
-
t1 = {
|
|
88
|
-
shouldBeOpened,
|
|
89
|
-
cancelAnimation
|
|
90
|
-
};
|
|
91
|
-
$[0] = cancelAnimation;
|
|
92
|
-
$[1] = shouldBeOpened;
|
|
93
|
-
$[2] = t1;
|
|
94
|
-
} else {
|
|
95
|
-
t1 = $[2];
|
|
96
|
-
}
|
|
65
|
+
if (!contentElement) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
97
68
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
t2 = () => {
|
|
105
|
-
dispatch({
|
|
106
|
-
type: "TARGET_CHANGED",
|
|
107
|
-
shouldBeOpened,
|
|
108
|
-
cancelAnimation
|
|
109
|
-
});
|
|
69
|
+
let isCurrentPhase = true;
|
|
70
|
+
|
|
71
|
+
const completeCurrentPhase = () => {
|
|
72
|
+
if (isCurrentPhase) {
|
|
73
|
+
completeTransition(state);
|
|
74
|
+
}
|
|
110
75
|
};
|
|
111
76
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
$[6] = t3;
|
|
117
|
-
} else {
|
|
118
|
-
t2 = $[5];
|
|
119
|
-
t3 = $[6];
|
|
120
|
-
}
|
|
77
|
+
const waitForCurrentTransition = previousTransition => {
|
|
78
|
+
if (!isCurrentPhase) {
|
|
79
|
+
return Promise.resolve();
|
|
80
|
+
}
|
|
121
81
|
|
|
122
|
-
|
|
123
|
-
let t4;
|
|
124
|
-
let t5;
|
|
82
|
+
const transition = getCollapseTransition(contentElement);
|
|
125
83
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (state !== COLLAPSE_STATES.CLOSING_PREPARE) {
|
|
129
|
-
return;
|
|
84
|
+
if (!transition || transition === previousTransition) {
|
|
85
|
+
return Promise.resolve();
|
|
130
86
|
}
|
|
131
87
|
|
|
132
|
-
|
|
133
|
-
if (
|
|
134
|
-
|
|
88
|
+
return transition.finished.then(() => {
|
|
89
|
+
if (!isCurrentPhase) {
|
|
90
|
+
return Promise.resolve();
|
|
135
91
|
}
|
|
136
92
|
|
|
137
|
-
|
|
138
|
-
type: "CLOSING_READY"
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
return () => cancelAnimationFrame(frame);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
t5 = [state];
|
|
145
|
-
$[7] = state;
|
|
146
|
-
$[8] = t4;
|
|
147
|
-
$[9] = t5;
|
|
148
|
-
} else {
|
|
149
|
-
t4 = $[8];
|
|
150
|
-
t5 = $[9];
|
|
151
|
-
}
|
|
93
|
+
const replacementTransition = getCollapseTransition(contentElement);
|
|
152
94
|
|
|
153
|
-
|
|
154
|
-
|
|
95
|
+
if (replacementTransition && replacementTransition !== transition) {
|
|
96
|
+
return waitForCurrentTransition(transition);
|
|
97
|
+
}
|
|
155
98
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
dispatch({
|
|
159
|
-
type: "TRANSITION_END",
|
|
160
|
-
shouldBeOpened
|
|
161
|
-
});
|
|
99
|
+
return Promise.resolve();
|
|
100
|
+
}, () => waitForCurrentTransition(transition));
|
|
162
101
|
};
|
|
163
102
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
t6 = $[11];
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const onAnimationEnd = t6;
|
|
171
|
-
const t7 = state === COLLAPSE_STATES.CLOSING_PREPARE;
|
|
172
|
-
let t8;
|
|
173
|
-
|
|
174
|
-
if ($[12] !== onAnimationEnd || $[13] !== state || $[14] !== t7) {
|
|
175
|
-
t8 = {
|
|
176
|
-
contentRef,
|
|
177
|
-
isStartedClosing: t7,
|
|
178
|
-
onAnimationEnd,
|
|
179
|
-
state
|
|
103
|
+
waitForCurrentTransition().then(completeCurrentPhase);
|
|
104
|
+
return () => {
|
|
105
|
+
isCurrentPhase = false;
|
|
180
106
|
};
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
t8 = $[15];
|
|
107
|
+
}, [completeTransition, contentRef, state]);
|
|
108
|
+
const stateForTarget = getStateForTarget(state, shouldBeOpened); // React retries this component before rendering its children when the phase changes.
|
|
109
|
+
|
|
110
|
+
if (stateForTarget !== state) {
|
|
111
|
+
setState(stateForTarget);
|
|
187
112
|
}
|
|
188
113
|
|
|
189
|
-
return
|
|
114
|
+
return state;
|
|
190
115
|
}
|
|
191
116
|
|
|
192
117
|
export { COLLAPSE_STATES, useCollapseState };
|
package/lib/use-safe-id.d.ts
CHANGED
package/lib/use-safe-id.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/collapse",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
@@ -17,26 +17,24 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/runtime-corejs3": "^7.26.0",
|
|
20
|
-
"
|
|
21
|
-
"classnames": "^2.2.6",
|
|
22
|
-
"react-compiler-runtime": "^1.0.0"
|
|
20
|
+
"classnames": "^2.2.6"
|
|
23
21
|
},
|
|
24
22
|
"peerDependencies": {
|
|
25
23
|
"@rescui/ui-contexts": "^0.6.0",
|
|
26
24
|
"prop-types": "^15",
|
|
27
|
-
"react": ">=
|
|
25
|
+
"react": ">=16.8.0 <20"
|
|
28
26
|
},
|
|
29
27
|
"devDependencies": {
|
|
30
|
-
"@rescui/colors": "0.3.3
|
|
31
|
-
"@rescui/scripts": "0.5.2",
|
|
32
|
-
"@rescui/typography": "0.27.
|
|
33
|
-
"@rescui/visual-regression": "0.1.4",
|
|
28
|
+
"@rescui/colors": "^0.3.3",
|
|
29
|
+
"@rescui/scripts": "^0.5.2",
|
|
30
|
+
"@rescui/typography": "^0.27.4",
|
|
31
|
+
"@rescui/visual-regression": "^0.1.4",
|
|
34
32
|
"@types/classnames": "^2.2.11"
|
|
35
33
|
},
|
|
36
34
|
"scripts": {
|
|
37
|
-
"build": "rescui-scripts build
|
|
35
|
+
"build": "rescui-scripts build && yarn run build-pcss-api",
|
|
38
36
|
"build-pcss-api": "rescui-scripts build-pcss-api --file public-api.p.css"
|
|
39
37
|
},
|
|
40
38
|
"nx": {},
|
|
41
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "3711cbfc0c797014395421b008aa5331d6d47c6e"
|
|
42
40
|
}
|