@douyinfe/semi-animation-react 2.1.1 → 2.1.2

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.
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+
5
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
+
7
+ _Object$defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+
11
+ exports.default = void 0;
12
+
13
+ var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
14
+
15
+ var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/values"));
16
+
17
+ var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
18
+
19
+ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
20
+
21
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
22
+
23
+ var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
24
+
25
+ var _react = require("react");
26
+
27
+ var _propTypes = _interopRequireDefault(require("prop-types"));
28
+
29
+ var _classnames = _interopRequireDefault(require("classnames"));
30
+
31
+ var _semiAnimationStyled = require("@douyinfe/semi-animation-styled");
32
+
33
+ var _noop = _interopRequireDefault(require("./utils/noop"));
34
+
35
+ var _invokeFns = _interopRequireDefault(require("./utils/invokeFns"));
36
+
37
+ var _context;
38
+
39
+ const types = (0, _reduce.default)(_context = (0, _values.default)(_semiAnimationStyled.types)).call(_context, (arr, cur) => [...arr, ...cur], []);
40
+
41
+ class StyledAnimation extends _react.PureComponent {
42
+ constructor() {
43
+ var _this;
44
+
45
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
46
+ super(props);
47
+ _this = this;
48
+
49
+ this._generateAnimateEvents = function (child) {
50
+ let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
51
+ return {
52
+ onAnimationIteration: function () {
53
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
54
+ args[_key] = arguments[_key];
55
+ }
56
+
57
+ return (0, _invokeFns.default)([child && child.props && child.props.onAnimationIteration, props.onFrame], args);
58
+ },
59
+ onAnimationStart: function () {
60
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
61
+ args[_key2] = arguments[_key2];
62
+ }
63
+
64
+ return (0, _invokeFns.default)([child && child.props && child.props.onAnimationStart, props.onStart], args);
65
+ },
66
+ onAnimationEnd: function () {
67
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
68
+ args[_key3] = arguments[_key3];
69
+ }
70
+
71
+ return (0, _invokeFns.default)([child && child.props && child.props.onAnimationEnd, props.onRest], args);
72
+ }
73
+ };
74
+ };
75
+
76
+ this._hasSpeedClass = function () {
77
+ let speed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.speed;
78
+ return speed != null && (0, _includes.default)(_semiAnimationStyled.speeds).call(_semiAnimationStyled.speeds, speed);
79
+ };
80
+
81
+ this._hasTypeClass = function () {
82
+ let type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.type;
83
+ return type != null && (0, _includes.default)(types).call(types, type);
84
+ };
85
+
86
+ this._hasDelayClass = function () {
87
+ let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.delay;
88
+ return delay != null && (0, _includes.default)(_semiAnimationStyled.delays).call(_semiAnimationStyled.delays, delay);
89
+ };
90
+
91
+ this._hasLoopClass = function () {
92
+ let loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.loop;
93
+ return loop != null && (0, _includes.default)(_semiAnimationStyled.loops).call(_semiAnimationStyled.loops, loop);
94
+ };
95
+ }
96
+
97
+ render() {
98
+ var _context2, _context3, _context4, _context5;
99
+
100
+ let {
101
+ type,
102
+ speed,
103
+ duration,
104
+ delay,
105
+ loop,
106
+ reverse,
107
+ children,
108
+ prefixCls,
109
+ timing,
110
+ className,
111
+ fillMode
112
+ } = this.props;
113
+
114
+ const hasTypeClass = this._hasTypeClass();
115
+
116
+ const hasSpeedClass = this._hasSpeedClass();
117
+
118
+ const hasDelayClass = this._hasDelayClass();
119
+
120
+ const hasLoopClass = this._hasLoopClass();
121
+
122
+ const animateCls = className || (0, _classnames.default)("".concat(prefixCls, "-animated"), {
123
+ [(0, _concat.default)(_context2 = "".concat(prefixCls, "-")).call(_context2, type)]: Boolean(type),
124
+ [(0, _concat.default)(_context3 = "".concat(prefixCls, "-speed-")).call(_context3, speed)]: hasSpeedClass,
125
+ [(0, _concat.default)(_context4 = "".concat(prefixCls, "-delay-")).call(_context4, delay)]: hasDelayClass,
126
+ [(0, _concat.default)(_context5 = "".concat(prefixCls, "-loop-")).call(_context5, loop)]: hasLoopClass
127
+ });
128
+ const animateStyle = {
129
+ animationTimingFunction: timing,
130
+ animationName: !hasTypeClass && type,
131
+ animationDuration: duration,
132
+ animationDelay: !hasDelayClass && delay,
133
+ animationIterationCount: !hasLoopClass && loop,
134
+ animationDirection: reverse ? 'alternate' : 'normal',
135
+ animationFillMode: fillMode
136
+ };
137
+
138
+ if ( /*#__PURE__*/(0, _react.isValidElement)(children)) {
139
+ children = (0, _map.default)(_react.Children).call(_react.Children, children, child => {
140
+ const animateEvents = this._generateAnimateEvents(child, this.props);
141
+
142
+ return /*#__PURE__*/(0, _react.cloneElement)(child, (0, _assign.default)({
143
+ className: (0, _classnames.default)(child.props.className, animateCls),
144
+ style: (0, _assign.default)((0, _assign.default)({}, child.props.style), this.props.style)
145
+ }, animateEvents));
146
+ });
147
+ }
148
+
149
+ return typeof children === 'function' ? children({
150
+ animateCls,
151
+ animateStyle,
152
+ animateEvents: this._generateAnimateEvents(null, this.props)
153
+ }) : children;
154
+ }
155
+
156
+ }
157
+
158
+ exports.default = StyledAnimation;
159
+ StyledAnimation.propTypes = {
160
+ className: _propTypes.default.string,
161
+ type: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.any]),
162
+ speed: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
163
+ delay: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
164
+ reverse: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.string]),
165
+ loop: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
166
+ children: _propTypes.default.any,
167
+ onStart: _propTypes.default.func,
168
+ onFrame: _propTypes.default.func,
169
+ onRest: _propTypes.default.func,
170
+ prefixCls: _propTypes.default.string,
171
+ timing: _propTypes.default.string,
172
+ duration: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
173
+ fillMode: _propTypes.default.string
174
+ };
175
+ StyledAnimation.defaultProps = {
176
+ prefixCls: 'semi',
177
+ speed: 'faster',
178
+ onFrame: _noop.default,
179
+ onStart: _noop.default,
180
+ onRest: _noop.default
181
+ };
@@ -0,0 +1,49 @@
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { StyledAnimationProps } from './StyledAnimation';
4
+ import noop from './utils/noop';
5
+ export interface StyledTransitionProps extends StyledAnimationProps {
6
+ state?: string | boolean;
7
+ enter?: string;
8
+ leave?: string;
9
+ children?: React.ReactNode;
10
+ willEnter?: (value: any) => void;
11
+ didEnter?: (value: any) => void;
12
+ willLeave?: (value: any) => void;
13
+ didLeave?: (value: any) => void;
14
+ onStart?: (value: any) => void;
15
+ onRest?: (value: any) => void;
16
+ }
17
+ export interface StyledTransitionState {
18
+ state: string | boolean;
19
+ lastChildren: React.ReactNode;
20
+ currentChildren: React.ReactNode;
21
+ }
22
+ export default class StyledTransition extends Component<StyledTransitionProps, StyledTransitionState> {
23
+ static propTypes: {
24
+ state: PropTypes.Requireable<string>;
25
+ enter: PropTypes.Requireable<string>;
26
+ leave: PropTypes.Requireable<string>;
27
+ children: PropTypes.Requireable<any>;
28
+ willEnter: PropTypes.Requireable<(...args: any[]) => any>;
29
+ didEnter: PropTypes.Requireable<(...args: any[]) => any>;
30
+ willLeave: PropTypes.Requireable<(...args: any[]) => any>;
31
+ didLeave: PropTypes.Requireable<(...args: any[]) => any>;
32
+ onStart: PropTypes.Requireable<(...args: any[]) => any>;
33
+ onRest: PropTypes.Requireable<(...args: any[]) => any>;
34
+ };
35
+ static defaultProps: {
36
+ willEnter: typeof noop;
37
+ didEnter: typeof noop;
38
+ willLeave: typeof noop;
39
+ didLeave: typeof noop;
40
+ onStart: typeof noop;
41
+ onRest: typeof noop;
42
+ };
43
+ constructor(props?: {});
44
+ static getDerivedStateFromProps(props: StyledTransitionProps, state: StyledTransitionState): Partial<StyledTransitionState>;
45
+ _isControlled: () => boolean;
46
+ onRest: (props: any) => void;
47
+ onStart: (props: any) => void;
48
+ render(): JSX.Element;
49
+ }
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+
3
+ var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
4
+
5
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
6
+
7
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
8
+
9
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
10
+
11
+ _Object$defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+
15
+ exports.default = void 0;
16
+
17
+ var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
18
+
19
+ var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));
20
+
21
+ var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
22
+
23
+ var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
24
+
25
+ var _react = _interopRequireWildcard(require("react"));
26
+
27
+ var _propTypes = _interopRequireDefault(require("prop-types"));
28
+
29
+ var _StyledAnimation = _interopRequireDefault(require("./StyledAnimation"));
30
+
31
+ var _noop = _interopRequireDefault(require("./utils/noop"));
32
+
33
+ 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); }
34
+
35
+ 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; }
36
+
37
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
38
+ var t = {};
39
+
40
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && (0, _indexOf.default)(e).call(e, p) < 0) t[p] = s[p];
41
+
42
+ if (s != null && typeof _getOwnPropertySymbols.default === "function") for (var i = 0, p = (0, _getOwnPropertySymbols.default)(s); i < p.length; i++) {
43
+ if ((0, _indexOf.default)(e).call(e, p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
44
+ }
45
+ return t;
46
+ };
47
+ /* eslint-disable eqeqeq */
48
+
49
+
50
+ class StyledTransition extends _react.Component {
51
+ constructor() {
52
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
53
+ super(props);
54
+
55
+ this._isControlled = () => {
56
+ var _context;
57
+
58
+ return (0, _includes.default)(_context = [true, false, 'enter', 'leave']).call(_context, this.props.state);
59
+ };
60
+
61
+ this.onRest = props => {
62
+ const {
63
+ state
64
+ } = this.state;
65
+
66
+ if (state === 'enter') {
67
+ this.props.didEnter(props);
68
+ } else if (state === 'leave') {
69
+ this.setState({
70
+ currentChildren: null,
71
+ lastChildren: null
72
+ });
73
+ this.props.didLeave(props);
74
+ }
75
+
76
+ this.props.onRest(props);
77
+ };
78
+
79
+ this.onStart = props => {
80
+ const {
81
+ state
82
+ } = this.state;
83
+
84
+ if (state === 'enter') {
85
+ this.props.willEnter(props);
86
+ } else if (state === 'leave') {
87
+ this.props.willLeave(props);
88
+ }
89
+
90
+ this.props.onStart(props);
91
+ };
92
+
93
+ this.state = {
94
+ state: '',
95
+ lastChildren: null,
96
+ currentChildren: null
97
+ };
98
+ }
99
+
100
+ static getDerivedStateFromProps(props, state) {
101
+ const willUpdateStates = {};
102
+
103
+ if (props.children !== state.currentChildren) {
104
+ willUpdateStates.lastChildren = state.currentChildren;
105
+ willUpdateStates.currentChildren = props.children;
106
+
107
+ if (props.children == null) {
108
+ willUpdateStates.state = 'leave';
109
+ } else {
110
+ willUpdateStates.state = 'enter';
111
+ }
112
+ }
113
+
114
+ if (props.state != null && props.state !== state.state) {
115
+ willUpdateStates.state = props.state;
116
+ }
117
+
118
+ return willUpdateStates;
119
+ }
120
+
121
+ render() {
122
+ const _a = this.props,
123
+ {
124
+ enter,
125
+ leave
126
+ } = _a,
127
+ restProps = __rest(_a, ["enter", "leave"]);
128
+
129
+ const {
130
+ currentChildren,
131
+ lastChildren
132
+ } = this.state;
133
+
134
+ const isControlled = this._isControlled();
135
+
136
+ let children, type;
137
+ let {
138
+ state
139
+ } = this.state;
140
+
141
+ if (isControlled) {
142
+ children = this.props.children;
143
+ state = this.props.state;
144
+ } else if (currentChildren == null && lastChildren == null) {
145
+ return null;
146
+ }
147
+
148
+ if (state === 'enter') {
149
+ type = enter;
150
+
151
+ if (!isControlled) {
152
+ children = currentChildren;
153
+ }
154
+ } else if (state === 'leave') {
155
+ type = leave;
156
+
157
+ if (!isControlled) {
158
+ children = lastChildren;
159
+ }
160
+ }
161
+
162
+ return /*#__PURE__*/_react.default.createElement(_StyledAnimation.default, (0, _assign.default)({}, restProps, {
163
+ type: type,
164
+ onStart: this.onStart,
165
+ onRest: this.onRest
166
+ }), children);
167
+ }
168
+
169
+ }
170
+
171
+ exports.default = StyledTransition;
172
+ StyledTransition.propTypes = {
173
+ state: _propTypes.default.string,
174
+ enter: _propTypes.default.string,
175
+ leave: _propTypes.default.string,
176
+ children: _propTypes.default.any,
177
+ willEnter: _propTypes.default.func,
178
+ didEnter: _propTypes.default.func,
179
+ willLeave: _propTypes.default.func,
180
+ didLeave: _propTypes.default.func,
181
+ onStart: _propTypes.default.func,
182
+ onRest: _propTypes.default.func
183
+ };
184
+ StyledTransition.defaultProps = {
185
+ willEnter: _noop.default,
186
+ didEnter: _noop.default,
187
+ willLeave: _noop.default,
188
+ didLeave: _noop.default,
189
+ onStart: _noop.default,
190
+ onRest: _noop.default
191
+ };
@@ -0,0 +1,52 @@
1
+ import { AnimationProps } from './Animation';
2
+ import PropTypes from 'prop-types';
3
+ import React, { Component } from 'react';
4
+ import noop from './utils/noop';
5
+ export interface TransitionProps extends AnimationProps {
6
+ children?: React.ReactNode;
7
+ from?: Record<string, any>;
8
+ enter?: Record<string, any>;
9
+ leave?: Record<string, any>;
10
+ state?: string | boolean;
11
+ willEnter?: (value: any) => void;
12
+ didEnter?: (value: any) => void;
13
+ willLeave?: (value: any) => void;
14
+ didLeave?: (value: any) => void;
15
+ onRest?: (value: any) => void;
16
+ onStart?: (value: any) => void;
17
+ }
18
+ export interface TransitionState {
19
+ state: string | boolean;
20
+ lastChildren: React.ReactNode;
21
+ currentChildren: React.ReactNode;
22
+ }
23
+ export default class Transition extends Component<TransitionProps, TransitionState> {
24
+ static propTypes: {
25
+ children: PropTypes.Requireable<any>;
26
+ from: PropTypes.Requireable<object>;
27
+ enter: PropTypes.Requireable<object>;
28
+ leave: PropTypes.Requireable<object>;
29
+ willEnter: PropTypes.Requireable<(...args: any[]) => any>;
30
+ didEnter: PropTypes.Requireable<(...args: any[]) => any>;
31
+ willLeave: PropTypes.Requireable<(...args: any[]) => any>;
32
+ didLeave: PropTypes.Requireable<(...args: any[]) => any>;
33
+ state: PropTypes.Requireable<string | boolean>;
34
+ };
35
+ static defaultProps: {
36
+ willEnter: typeof noop;
37
+ didEnter: typeof noop;
38
+ willLeave: typeof noop;
39
+ didLeave: typeof noop;
40
+ onStart: typeof noop;
41
+ onRest: typeof noop;
42
+ };
43
+ instance: any;
44
+ constructor(props?: {});
45
+ static getDerivedStateFromProps(props: TransitionProps, state: TransitionState): Partial<TransitionState>;
46
+ componentWillUnmount(): void;
47
+ _isControlled: () => boolean;
48
+ forwardInstance: (instance: any) => void;
49
+ onRest: (props: any) => void;
50
+ onStart: (props: any) => void;
51
+ render(): JSX.Element;
52
+ }
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+
3
+ var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
4
+
5
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
6
+
7
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
8
+
9
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
10
+
11
+ _Object$defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+
15
+ exports.default = void 0;
16
+
17
+ var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
18
+
19
+ var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));
20
+
21
+ var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
22
+
23
+ var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
24
+
25
+ var _Animation = _interopRequireDefault(require("./Animation"));
26
+
27
+ var _propTypes = _interopRequireDefault(require("prop-types"));
28
+
29
+ var _react = _interopRequireWildcard(require("react"));
30
+
31
+ var _noop = _interopRequireDefault(require("./utils/noop"));
32
+
33
+ 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); }
34
+
35
+ 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; }
36
+
37
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
38
+ var t = {};
39
+
40
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && (0, _indexOf.default)(e).call(e, p) < 0) t[p] = s[p];
41
+
42
+ if (s != null && typeof _getOwnPropertySymbols.default === "function") for (var i = 0, p = (0, _getOwnPropertySymbols.default)(s); i < p.length; i++) {
43
+ if ((0, _indexOf.default)(e).call(e, p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
44
+ }
45
+ return t;
46
+ };
47
+ /* eslint-disable eqeqeq */
48
+
49
+
50
+ class Transition extends _react.Component {
51
+ constructor() {
52
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
53
+ super(props);
54
+
55
+ this._isControlled = () => {
56
+ var _context;
57
+
58
+ return (0, _includes.default)(_context = [true, false, 'enter', 'leave']).call(_context, this.props.state);
59
+ };
60
+
61
+ this.forwardInstance = instance => {
62
+ this.instance = instance;
63
+ };
64
+
65
+ this.onRest = props => {
66
+ const {
67
+ state
68
+ } = this.state;
69
+
70
+ if (state === 'enter') {
71
+ this.props.didEnter(props);
72
+ } else if (state === 'leave') {
73
+ this.setState({
74
+ currentChildren: null,
75
+ lastChildren: null
76
+ });
77
+ this.props.didLeave(props);
78
+ }
79
+
80
+ this.props.onRest(props);
81
+ };
82
+
83
+ this.onStart = props => {
84
+ const {
85
+ state
86
+ } = this.state;
87
+
88
+ if (state === 'enter') {
89
+ this.props.willEnter(props);
90
+ } else if (state === 'leave') {
91
+ this.props.willLeave(props);
92
+ }
93
+
94
+ this.props.onStart(props);
95
+ };
96
+
97
+ this.state = {
98
+ state: '',
99
+ lastChildren: null,
100
+ currentChildren: null
101
+ };
102
+ }
103
+
104
+ static getDerivedStateFromProps(props, state) {
105
+ const willUpdateStates = {};
106
+
107
+ if (props.children !== state.currentChildren // && (props.children == null || state.currentChildren == null)
108
+ ) {
109
+ willUpdateStates.lastChildren = state.currentChildren;
110
+ willUpdateStates.currentChildren = props.children;
111
+
112
+ if (props.children == null) {
113
+ willUpdateStates.state = 'leave';
114
+ } else {
115
+ willUpdateStates.state = 'enter';
116
+ }
117
+ }
118
+
119
+ if (props.state != null) {
120
+ willUpdateStates.state = props.state;
121
+ }
122
+
123
+ return willUpdateStates;
124
+ }
125
+
126
+ componentWillUnmount() {
127
+ if (this.instance) {
128
+ this.instance.destroy();
129
+ this.instance = null;
130
+ }
131
+ }
132
+
133
+ render() {
134
+ const _a = this.props,
135
+ {
136
+ from: propsFrom,
137
+ enter,
138
+ leave
139
+ } = _a,
140
+ restProps = __rest(_a, ["from", "enter", "leave"]);
141
+
142
+ let children; // eslint-disable-next-line prefer-const
143
+
144
+ let {
145
+ currentChildren,
146
+ lastChildren,
147
+ state
148
+ } = this.state;
149
+ let from = {};
150
+ let to = {};
151
+
152
+ const isControlled = this._isControlled();
153
+
154
+ if (isControlled) {
155
+ children = this.props.children;
156
+ state = this.props.state;
157
+ } else if (currentChildren == null && lastChildren == null) {
158
+ return null;
159
+ }
160
+
161
+ if (state === 'enter') {
162
+ from = propsFrom;
163
+ to = enter;
164
+
165
+ if (!isControlled) {
166
+ children = currentChildren;
167
+ }
168
+ } else if (state === 'leave') {
169
+ from = enter;
170
+ to = leave;
171
+
172
+ if (!isControlled) {
173
+ children = lastChildren;
174
+ }
175
+ }
176
+
177
+ return /*#__PURE__*/_react.default.createElement(_Animation.default, (0, _assign.default)({}, restProps, {
178
+ force: true,
179
+ from: from,
180
+ to: to,
181
+ onRest: this.onRest,
182
+ onStart: this.onStart
183
+ }), props => // eslint-disable-next-line no-nested-ternary
184
+ typeof children === 'function' ? children(props) : /*#__PURE__*/(0, _react.isValidElement)(children) ? children : null);
185
+ }
186
+
187
+ }
188
+
189
+ exports.default = Transition;
190
+ Transition.propTypes = {
191
+ children: _propTypes.default.any,
192
+ from: _propTypes.default.object,
193
+ enter: _propTypes.default.object,
194
+ leave: _propTypes.default.object,
195
+ willEnter: _propTypes.default.func,
196
+ didEnter: _propTypes.default.func,
197
+ willLeave: _propTypes.default.func,
198
+ didLeave: _propTypes.default.func,
199
+ state: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool])
200
+ };
201
+ Transition.defaultProps = {
202
+ willEnter: _noop.default,
203
+ didEnter: _noop.default,
204
+ willLeave: _noop.default,
205
+ didLeave: _noop.default,
206
+ onStart: _noop.default,
207
+ onRest: _noop.default
208
+ };
@@ -0,0 +1 @@
1
+ export default function invokeFns(fns: any[], args?: any[]): void;