@douyinfe/semi-animation-react 2.24.2 → 2.25.0-alpha.0
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/cjs/index.js +0 -7
- package/lib/cjs/src/Animation.js +3 -42
- package/lib/cjs/src/KeyFrames.js +2 -26
- package/lib/cjs/src/StyledAnimation.js +5 -43
- package/lib/cjs/src/StyledTransition.js +5 -42
- package/lib/cjs/src/Transition.js +11 -48
- package/lib/cjs/src/utils/invokeFns.js +0 -2
- package/lib/cjs/src/utils/noop.js +0 -2
- package/lib/cjs/src/utils/string.js +2 -7
- package/lib/es/src/Animation.js +3 -34
- package/lib/es/src/KeyFrames.js +2 -17
- package/lib/es/src/StyledAnimation.js +5 -33
- package/lib/es/src/StyledTransition.js +5 -33
- package/lib/es/src/Transition.js +11 -39
- package/lib/es/src/utils/invokeFns.js +0 -1
- package/lib/es/src/utils/noop.js +0 -1
- package/lib/es/src/utils/string.js +2 -5
- package/package.json +44 -45
package/lib/cjs/index.js
CHANGED
|
@@ -45,17 +45,10 @@ Object.defineProperty(exports, "presets", {
|
|
|
45
45
|
return _semiAnimation.presets;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
|
|
49
48
|
var _StyledAnimation = _interopRequireDefault(require("./src/StyledAnimation"));
|
|
50
|
-
|
|
51
49
|
var _StyledTransition = _interopRequireDefault(require("./src/StyledTransition"));
|
|
52
|
-
|
|
53
50
|
var _Animation = _interopRequireDefault(require("./src/Animation"));
|
|
54
|
-
|
|
55
51
|
var _KeyFrames = _interopRequireDefault(require("./src/KeyFrames"));
|
|
56
|
-
|
|
57
52
|
var _Transition = _interopRequireDefault(require("./src/Transition"));
|
|
58
|
-
|
|
59
53
|
var _semiAnimation = require("@douyinfe/semi-animation");
|
|
60
|
-
|
|
61
54
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/cjs/src/Animation.js
CHANGED
|
@@ -4,48 +4,35 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _semiAnimation = require("@douyinfe/semi-animation");
|
|
13
|
-
|
|
14
10
|
var _noop = _interopRequireDefault(require("./utils/noop"));
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
19
13
|
|
|
20
|
-
/* eslint-disable react/destructuring-assignment */
|
|
21
14
|
class Animation extends _react.PureComponent {
|
|
22
15
|
constructor() {
|
|
23
16
|
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
17
|
super(props);
|
|
25
|
-
|
|
26
18
|
this.initAnimation = props => {
|
|
27
|
-
|
|
28
|
-
props = props == null ? this.props : props; // eslint-disable-next-line prefer-const
|
|
29
|
-
|
|
19
|
+
props = props == null ? this.props : props;
|
|
30
20
|
let {
|
|
31
21
|
from,
|
|
32
22
|
to,
|
|
33
23
|
config,
|
|
34
24
|
reverse
|
|
35
25
|
} = props;
|
|
36
|
-
|
|
37
26
|
if (reverse) {
|
|
38
27
|
[from, to] = [to, from];
|
|
39
28
|
}
|
|
40
|
-
|
|
41
29
|
this.animation = new _semiAnimation.Animation({
|
|
42
30
|
from: Object.assign({}, from),
|
|
43
31
|
to: Object.assign({}, to)
|
|
44
32
|
}, Object.assign({}, config));
|
|
45
|
-
|
|
46
33
|
_semiAnimation.events.forEach(event => {
|
|
47
|
-
const propName =
|
|
48
|
-
|
|
34
|
+
const propName = `on${event[0].toUpperCase() + event.slice(1)}`;
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
49
36
|
this.animation.on(event, props => {
|
|
50
37
|
// avoid memory leak
|
|
51
38
|
if (this._mounted && !this._destroyed) {
|
|
@@ -56,64 +43,52 @@ class Animation extends _react.PureComponent {
|
|
|
56
43
|
}
|
|
57
44
|
});
|
|
58
45
|
});
|
|
59
|
-
|
|
60
46
|
this._destroyed = false;
|
|
61
47
|
};
|
|
62
|
-
|
|
63
48
|
this.bindEvents = () => {
|
|
64
49
|
this.startOrNot = () => {
|
|
65
50
|
const {
|
|
66
51
|
immediate,
|
|
67
52
|
autoStart
|
|
68
53
|
} = this.props;
|
|
69
|
-
|
|
70
54
|
if (immediate) {
|
|
71
55
|
this.end();
|
|
72
56
|
} else if (autoStart) {
|
|
73
57
|
this.start();
|
|
74
58
|
}
|
|
75
59
|
};
|
|
76
|
-
|
|
77
60
|
this.start = () => {
|
|
78
61
|
this.animation && this.animation.start();
|
|
79
62
|
};
|
|
80
|
-
|
|
81
63
|
this.pause = () => {
|
|
82
64
|
this.animation && this.animation.pause();
|
|
83
65
|
};
|
|
84
|
-
|
|
85
66
|
this.stop = () => {
|
|
86
67
|
this.animation && this.animation.stop();
|
|
87
68
|
};
|
|
88
|
-
|
|
89
69
|
this.end = () => {
|
|
90
70
|
this.animation && this.animation.end();
|
|
91
71
|
};
|
|
92
|
-
|
|
93
72
|
this.resume = () => {
|
|
94
73
|
this.animation && this.animation.resume();
|
|
95
74
|
};
|
|
96
|
-
|
|
97
75
|
this.reset = () => {
|
|
98
76
|
if (this.animation) {
|
|
99
77
|
this.animation.reset();
|
|
100
78
|
this.startOrNot();
|
|
101
79
|
}
|
|
102
80
|
};
|
|
103
|
-
|
|
104
81
|
this.reverse = () => {
|
|
105
82
|
if (this.animation) {
|
|
106
83
|
this.animation.reverse();
|
|
107
84
|
this.startOrNot();
|
|
108
85
|
}
|
|
109
86
|
};
|
|
110
|
-
|
|
111
87
|
this.destroy = () => {
|
|
112
88
|
this._destroyed = true;
|
|
113
89
|
this.animation && this.animation.destroy();
|
|
114
90
|
};
|
|
115
91
|
};
|
|
116
|
-
|
|
117
92
|
this.state = {
|
|
118
93
|
currentStyle: {}
|
|
119
94
|
};
|
|
@@ -122,42 +97,33 @@ class Animation extends _react.PureComponent {
|
|
|
122
97
|
this.initAnimation();
|
|
123
98
|
this.bindEvents();
|
|
124
99
|
}
|
|
125
|
-
|
|
126
100
|
startOrNot() {
|
|
127
101
|
throw new Error('Method not implemented.');
|
|
128
102
|
}
|
|
129
|
-
|
|
130
103
|
componentDidMount() {
|
|
131
104
|
this._mounted = true;
|
|
132
105
|
const {
|
|
133
106
|
forwardInstance
|
|
134
107
|
} = this.props;
|
|
135
|
-
|
|
136
108
|
if (this.animation === null) {
|
|
137
109
|
// didmount/willUnmount may be called twice when React.StrictMode is true in React 18, we need to ensure that this.animation is correct
|
|
138
110
|
this.initAnimation();
|
|
139
111
|
this.bindEvents();
|
|
140
112
|
}
|
|
141
|
-
|
|
142
113
|
if (typeof forwardInstance === 'function') {
|
|
143
114
|
forwardInstance(this.animation);
|
|
144
115
|
}
|
|
145
|
-
|
|
146
116
|
this.startOrNot();
|
|
147
117
|
}
|
|
148
|
-
|
|
149
118
|
componentWillUnmount() {
|
|
150
119
|
this._mounted = false;
|
|
151
|
-
|
|
152
120
|
if (this.animation) {
|
|
153
121
|
this.animation.destroy();
|
|
154
122
|
this.animation = null;
|
|
155
123
|
}
|
|
156
124
|
}
|
|
157
|
-
|
|
158
125
|
componentDidUpdate() {
|
|
159
126
|
let prevProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
160
|
-
|
|
161
127
|
if (this.props.reset) {
|
|
162
128
|
if (this.props.from !== prevProps.from || this.props.to !== prevProps.to) {
|
|
163
129
|
this.destroy();
|
|
@@ -165,7 +131,6 @@ class Animation extends _react.PureComponent {
|
|
|
165
131
|
this.startOrNot();
|
|
166
132
|
}
|
|
167
133
|
}
|
|
168
|
-
|
|
169
134
|
if (this.props.force) {
|
|
170
135
|
if (this.props.to !== prevProps.to) {
|
|
171
136
|
this.initAnimation(Object.assign(Object.assign({}, this.props), {
|
|
@@ -175,12 +140,10 @@ class Animation extends _react.PureComponent {
|
|
|
175
140
|
}
|
|
176
141
|
}
|
|
177
142
|
}
|
|
178
|
-
|
|
179
143
|
render() {
|
|
180
144
|
const {
|
|
181
145
|
children
|
|
182
146
|
} = this.props;
|
|
183
|
-
|
|
184
147
|
if (typeof children === 'function') {
|
|
185
148
|
return children(this.animation.getCurrentStates());
|
|
186
149
|
} else if ( /*#__PURE__*/(0, _react.isValidElement)(children)) {
|
|
@@ -189,9 +152,7 @@ class Animation extends _react.PureComponent {
|
|
|
189
152
|
return null;
|
|
190
153
|
}
|
|
191
154
|
}
|
|
192
|
-
|
|
193
155
|
}
|
|
194
|
-
|
|
195
156
|
exports.default = Animation;
|
|
196
157
|
Animation.propTypes = {
|
|
197
158
|
onStart: _propTypes.default.func,
|
package/lib/cjs/src/KeyFrames.js
CHANGED
|
@@ -4,41 +4,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _noop = _interopRequireDefault(require("./utils/noop"));
|
|
13
|
-
|
|
14
10
|
var _Animation = _interopRequireDefault(require("./Animation"));
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
|
-
/* eslint-disable react/destructuring-assignment */
|
|
23
14
|
class KeyFrames extends _react.Component {
|
|
24
15
|
constructor() {
|
|
25
16
|
var _this;
|
|
26
|
-
|
|
27
17
|
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
28
18
|
super(props);
|
|
29
19
|
_this = this;
|
|
30
|
-
|
|
31
20
|
this.onFrame = function () {
|
|
32
21
|
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
33
22
|
const currentStyle = Object.assign({}, props);
|
|
34
|
-
|
|
35
23
|
_this.props.onFrame(currentStyle);
|
|
36
|
-
|
|
37
24
|
_this.setState({
|
|
38
25
|
currentStyle
|
|
39
26
|
});
|
|
40
27
|
};
|
|
41
|
-
|
|
42
28
|
this.next = () => {
|
|
43
29
|
let {
|
|
44
30
|
frameIndex
|
|
@@ -48,7 +34,6 @@ class KeyFrames extends _react.Component {
|
|
|
48
34
|
loop
|
|
49
35
|
} = this.props;
|
|
50
36
|
frameIndex++;
|
|
51
|
-
|
|
52
37
|
if (frameIndex < frames.length - 1) {
|
|
53
38
|
this.setState({
|
|
54
39
|
frameIndex
|
|
@@ -56,38 +41,31 @@ class KeyFrames extends _react.Component {
|
|
|
56
41
|
} else {
|
|
57
42
|
frameIndex = 0;
|
|
58
43
|
this.props.onRest(this.state.currentStyle);
|
|
59
|
-
|
|
60
44
|
if (loop) {
|
|
61
45
|
this.setState({
|
|
62
46
|
frameIndex
|
|
63
47
|
});
|
|
64
48
|
}
|
|
65
49
|
}
|
|
66
|
-
|
|
67
50
|
this.props.onKeyRest(this.state.currentStyle);
|
|
68
51
|
};
|
|
69
|
-
|
|
70
52
|
this.forwardInstance = instance => {
|
|
71
53
|
this.instance = instance;
|
|
72
|
-
|
|
73
54
|
if (typeof this.props.forwardInstance === 'function') {
|
|
74
55
|
this.props.forwardInstance(this.instance);
|
|
75
56
|
}
|
|
76
57
|
};
|
|
77
|
-
|
|
78
58
|
this.state = {
|
|
79
59
|
currentStyle: {},
|
|
80
60
|
frameIndex: 0
|
|
81
61
|
};
|
|
82
62
|
}
|
|
83
|
-
|
|
84
|
-
|
|
63
|
+
componentDidMount() {
|
|
64
|
+
// this.props.forwardInstance(this.instance);
|
|
85
65
|
}
|
|
86
|
-
|
|
87
66
|
componentWillUnmount() {
|
|
88
67
|
this.instance && this.instance.destroy();
|
|
89
68
|
}
|
|
90
|
-
|
|
91
69
|
render() {
|
|
92
70
|
const {
|
|
93
71
|
children,
|
|
@@ -107,9 +85,7 @@ class KeyFrames extends _react.Component {
|
|
|
107
85
|
onRest: this.next
|
|
108
86
|
}), typeof children === 'function' ? children(currentStyle) : children);
|
|
109
87
|
}
|
|
110
|
-
|
|
111
88
|
}
|
|
112
|
-
|
|
113
89
|
exports.default = KeyFrames;
|
|
114
90
|
KeyFrames.propTypes = {
|
|
115
91
|
frames: _propTypes.default.array,
|
|
@@ -4,40 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
-
|
|
14
10
|
var _semiAnimationStyled = require("@douyinfe/semi-animation-styled");
|
|
15
|
-
|
|
16
11
|
var _noop = _interopRequireDefault(require("./utils/noop"));
|
|
17
|
-
|
|
18
12
|
var _invokeFns = _interopRequireDefault(require("./utils/invokeFns"));
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
/* eslint-disable react/destructuring-assignment */
|
|
23
|
-
|
|
24
|
-
/* eslint-disable prefer-const */
|
|
25
|
-
|
|
26
|
-
/* eslint-disable eqeqeq */
|
|
27
|
-
|
|
28
|
-
/* eslint-disable import/no-duplicates */
|
|
29
|
-
|
|
30
|
-
/* eslint-disable no-duplicate-imports */
|
|
31
14
|
const types = Object.values(_semiAnimationStyled.types).reduce((arr, cur) => [...arr, ...cur], []);
|
|
32
|
-
|
|
33
15
|
class StyledAnimation extends _react.PureComponent {
|
|
34
16
|
constructor() {
|
|
35
17
|
var _this;
|
|
36
|
-
|
|
37
18
|
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
38
19
|
super(props);
|
|
39
20
|
_this = this;
|
|
40
|
-
|
|
41
21
|
this._generateAnimateEvents = function (child) {
|
|
42
22
|
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
43
23
|
return {
|
|
@@ -45,47 +25,39 @@ class StyledAnimation extends _react.PureComponent {
|
|
|
45
25
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
46
26
|
args[_key] = arguments[_key];
|
|
47
27
|
}
|
|
48
|
-
|
|
49
28
|
return (0, _invokeFns.default)([child && child.props && child.props.onAnimationIteration, props.onFrame], args);
|
|
50
29
|
},
|
|
51
30
|
onAnimationStart: function () {
|
|
52
31
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
53
32
|
args[_key2] = arguments[_key2];
|
|
54
33
|
}
|
|
55
|
-
|
|
56
34
|
return (0, _invokeFns.default)([child && child.props && child.props.onAnimationStart, props.onStart], args);
|
|
57
35
|
},
|
|
58
36
|
onAnimationEnd: function () {
|
|
59
37
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
60
38
|
args[_key3] = arguments[_key3];
|
|
61
39
|
}
|
|
62
|
-
|
|
63
40
|
return (0, _invokeFns.default)([child && child.props && child.props.onAnimationEnd, props.onRest], args);
|
|
64
41
|
}
|
|
65
42
|
};
|
|
66
43
|
};
|
|
67
|
-
|
|
68
44
|
this._hasSpeedClass = function () {
|
|
69
45
|
let speed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.speed;
|
|
70
46
|
return speed != null && _semiAnimationStyled.speeds.includes(speed);
|
|
71
47
|
};
|
|
72
|
-
|
|
73
48
|
this._hasTypeClass = function () {
|
|
74
49
|
let type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.type;
|
|
75
50
|
return type != null && types.includes(type);
|
|
76
51
|
};
|
|
77
|
-
|
|
78
52
|
this._hasDelayClass = function () {
|
|
79
53
|
let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.delay;
|
|
80
54
|
return delay != null && _semiAnimationStyled.delays.includes(delay);
|
|
81
55
|
};
|
|
82
|
-
|
|
83
56
|
this._hasLoopClass = function () {
|
|
84
57
|
let loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.loop;
|
|
85
58
|
return loop != null && _semiAnimationStyled.loops.includes(loop);
|
|
86
59
|
};
|
|
87
60
|
}
|
|
88
|
-
|
|
89
61
|
render() {
|
|
90
62
|
let {
|
|
91
63
|
type,
|
|
@@ -100,20 +72,15 @@ class StyledAnimation extends _react.PureComponent {
|
|
|
100
72
|
className,
|
|
101
73
|
fillMode
|
|
102
74
|
} = this.props;
|
|
103
|
-
|
|
104
75
|
const hasTypeClass = this._hasTypeClass();
|
|
105
|
-
|
|
106
76
|
const hasSpeedClass = this._hasSpeedClass();
|
|
107
|
-
|
|
108
77
|
const hasDelayClass = this._hasDelayClass();
|
|
109
|
-
|
|
110
78
|
const hasLoopClass = this._hasLoopClass();
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
[
|
|
114
|
-
[
|
|
115
|
-
[
|
|
116
|
-
["".concat(prefixCls, "-loop-").concat(loop)]: hasLoopClass
|
|
79
|
+
const animateCls = className || (0, _classnames.default)(`${prefixCls}-animated`, {
|
|
80
|
+
[`${prefixCls}-${type}`]: Boolean(type),
|
|
81
|
+
[`${prefixCls}-speed-${speed}`]: hasSpeedClass,
|
|
82
|
+
[`${prefixCls}-delay-${delay}`]: hasDelayClass,
|
|
83
|
+
[`${prefixCls}-loop-${loop}`]: hasLoopClass
|
|
117
84
|
});
|
|
118
85
|
const animateStyle = {
|
|
119
86
|
animationTimingFunction: timing,
|
|
@@ -124,27 +91,22 @@ class StyledAnimation extends _react.PureComponent {
|
|
|
124
91
|
animationDirection: reverse ? 'alternate' : 'normal',
|
|
125
92
|
animationFillMode: fillMode
|
|
126
93
|
};
|
|
127
|
-
|
|
128
94
|
if ( /*#__PURE__*/(0, _react.isValidElement)(children)) {
|
|
129
95
|
children = _react.Children.map(children, child => {
|
|
130
96
|
const animateEvents = this._generateAnimateEvents(child, this.props);
|
|
131
|
-
|
|
132
97
|
return /*#__PURE__*/(0, _react.cloneElement)(child, Object.assign({
|
|
133
98
|
className: (0, _classnames.default)(child.props.className, animateCls),
|
|
134
99
|
style: Object.assign(Object.assign({}, child.props.style), this.props.style)
|
|
135
100
|
}, animateEvents));
|
|
136
101
|
});
|
|
137
102
|
}
|
|
138
|
-
|
|
139
103
|
return typeof children === 'function' ? children({
|
|
140
104
|
animateCls,
|
|
141
105
|
animateStyle,
|
|
142
106
|
animateEvents: this._generateAnimateEvents(null, this.props)
|
|
143
107
|
}) : children;
|
|
144
108
|
}
|
|
145
|
-
|
|
146
109
|
}
|
|
147
|
-
|
|
148
110
|
exports.default = StyledAnimation;
|
|
149
111
|
StyledAnimation.propTypes = {
|
|
150
112
|
className: _propTypes.default.string,
|
|
@@ -4,46 +4,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _StyledAnimation = _interopRequireDefault(require("./StyledAnimation"));
|
|
13
|
-
|
|
14
10
|
var _noop = _interopRequireDefault(require("./utils/noop"));
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
14
|
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
23
15
|
var t = {};
|
|
24
|
-
|
|
25
16
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
26
|
-
|
|
27
17
|
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
28
18
|
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
29
19
|
}
|
|
30
20
|
return t;
|
|
31
21
|
};
|
|
32
|
-
/* eslint-disable eqeqeq */
|
|
33
|
-
|
|
34
|
-
|
|
35
22
|
class StyledTransition extends _react.Component {
|
|
36
23
|
constructor() {
|
|
37
24
|
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
38
25
|
super(props);
|
|
39
|
-
|
|
40
26
|
this._isControlled = () => [true, false, 'enter', 'leave'].includes(this.props.state);
|
|
41
|
-
|
|
42
27
|
this.onRest = props => {
|
|
43
28
|
const {
|
|
44
29
|
state
|
|
45
30
|
} = this.state;
|
|
46
|
-
|
|
47
31
|
if (state === 'enter') {
|
|
48
32
|
this.props.didEnter(props);
|
|
49
33
|
} else if (state === 'leave') {
|
|
@@ -53,102 +37,81 @@ class StyledTransition extends _react.Component {
|
|
|
53
37
|
});
|
|
54
38
|
this.props.didLeave(props);
|
|
55
39
|
}
|
|
56
|
-
|
|
57
40
|
this.props.onRest(props);
|
|
58
41
|
};
|
|
59
|
-
|
|
60
42
|
this.onStart = props => {
|
|
61
43
|
const {
|
|
62
44
|
state
|
|
63
45
|
} = this.state;
|
|
64
|
-
|
|
65
46
|
if (state === 'enter') {
|
|
66
47
|
this.props.willEnter(props);
|
|
67
48
|
} else if (state === 'leave') {
|
|
68
49
|
this.props.willLeave(props);
|
|
69
50
|
}
|
|
70
|
-
|
|
71
51
|
this.props.onStart(props);
|
|
72
52
|
};
|
|
73
|
-
|
|
74
53
|
this.state = {
|
|
75
54
|
state: '',
|
|
76
55
|
lastChildren: null,
|
|
77
56
|
currentChildren: null
|
|
78
57
|
};
|
|
79
58
|
}
|
|
80
|
-
|
|
81
59
|
static getDerivedStateFromProps(props, state) {
|
|
82
60
|
const willUpdateStates = {};
|
|
83
|
-
|
|
84
61
|
if (props.children !== state.currentChildren) {
|
|
85
62
|
willUpdateStates.lastChildren = state.currentChildren;
|
|
86
63
|
willUpdateStates.currentChildren = props.children;
|
|
87
|
-
|
|
88
64
|
if (props.children == null) {
|
|
89
65
|
willUpdateStates.state = 'leave';
|
|
90
66
|
} else {
|
|
91
67
|
willUpdateStates.state = 'enter';
|
|
92
68
|
}
|
|
93
69
|
}
|
|
94
|
-
|
|
95
70
|
if (props.state != null && props.state !== state.state) {
|
|
96
71
|
willUpdateStates.state = props.state;
|
|
97
72
|
}
|
|
98
|
-
|
|
99
73
|
return willUpdateStates;
|
|
100
74
|
}
|
|
101
|
-
|
|
102
75
|
render() {
|
|
103
76
|
const _a = this.props,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
77
|
+
{
|
|
78
|
+
enter,
|
|
79
|
+
leave
|
|
80
|
+
} = _a,
|
|
81
|
+
restProps = __rest(_a, ["enter", "leave"]);
|
|
110
82
|
const {
|
|
111
83
|
currentChildren,
|
|
112
84
|
lastChildren
|
|
113
85
|
} = this.state;
|
|
114
|
-
|
|
115
86
|
const isControlled = this._isControlled();
|
|
116
|
-
|
|
117
87
|
let children, type;
|
|
118
88
|
let {
|
|
119
89
|
state
|
|
120
90
|
} = this.state;
|
|
121
|
-
|
|
122
91
|
if (isControlled) {
|
|
123
92
|
children = this.props.children;
|
|
124
93
|
state = this.props.state;
|
|
125
94
|
} else if (currentChildren == null && lastChildren == null) {
|
|
126
95
|
return null;
|
|
127
96
|
}
|
|
128
|
-
|
|
129
97
|
if (state === 'enter') {
|
|
130
98
|
type = enter;
|
|
131
|
-
|
|
132
99
|
if (!isControlled) {
|
|
133
100
|
children = currentChildren;
|
|
134
101
|
}
|
|
135
102
|
} else if (state === 'leave') {
|
|
136
103
|
type = leave;
|
|
137
|
-
|
|
138
104
|
if (!isControlled) {
|
|
139
105
|
children = lastChildren;
|
|
140
106
|
}
|
|
141
107
|
}
|
|
142
|
-
|
|
143
108
|
return /*#__PURE__*/_react.default.createElement(_StyledAnimation.default, Object.assign({}, restProps, {
|
|
144
109
|
type: type,
|
|
145
110
|
onStart: this.onStart,
|
|
146
111
|
onRest: this.onRest
|
|
147
112
|
}), children);
|
|
148
113
|
}
|
|
149
|
-
|
|
150
114
|
}
|
|
151
|
-
|
|
152
115
|
exports.default = StyledTransition;
|
|
153
116
|
StyledTransition.propTypes = {
|
|
154
117
|
state: _propTypes.default.string,
|