rc-animate
Advanced tools
Comparing version 2.3.6 to 2.4.0
@@ -7,4 +7,26 @@ 'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _defineProperty2 = require('babel-runtime/helpers/defineProperty'); | ||
var _defineProperty3 = _interopRequireDefault(_defineProperty2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _react = require('react'); | ||
@@ -28,14 +50,4 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
var defaultKey = 'rc_animate_' + Date.now(); | ||
@@ -46,5 +58,5 @@ | ||
var children = props.children; | ||
if (_react2["default"].isValidElement(children)) { | ||
if (_react2['default'].isValidElement(children)) { | ||
if (!children.key) { | ||
return _react2["default"].cloneElement(children, { | ||
return _react2['default'].cloneElement(children, { | ||
key: defaultKey | ||
@@ -60,8 +72,8 @@ }); | ||
var Animate = function (_React$Component) { | ||
_inherits(Animate, _React$Component); | ||
(0, _inherits3['default'])(Animate, _React$Component); | ||
function Animate(props) { | ||
_classCallCheck(this, Animate); | ||
(0, _classCallCheck3['default'])(this, Animate); | ||
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); | ||
var _this = (0, _possibleConstructorReturn3['default'])(this, (Animate.__proto__ || Object.getPrototypeOf(Animate)).call(this, props)); | ||
@@ -77,198 +89,211 @@ _initialiseProps.call(_this); | ||
}; | ||
_this.childrenRefs = {}; | ||
return _this; | ||
} | ||
Animate.prototype.componentDidMount = function componentDidMount() { | ||
var _this2 = this; | ||
(0, _createClass3['default'])(Animate, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
var _this2 = this; | ||
var showProp = this.props.showProp; | ||
var children = this.state.children; | ||
if (showProp) { | ||
children = children.filter(function (child) { | ||
return !!child.props[showProp]; | ||
}); | ||
} | ||
children.forEach(function (child) { | ||
if (child) { | ||
_this2.performAppear(child.key); | ||
var showProp = this.props.showProp; | ||
var children = this.state.children; | ||
if (showProp) { | ||
children = children.filter(function (child) { | ||
return !!child.props[showProp]; | ||
}); | ||
} | ||
}); | ||
}; | ||
Animate.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
var _this3 = this; | ||
this.nextProps = nextProps; | ||
var nextChildren = (0, _ChildrenUtils.toArrayChildren)(getChildrenFromProps(nextProps)); | ||
var props = this.props; | ||
// exclusive needs immediate response | ||
if (props.exclusive) { | ||
Object.keys(this.currentlyAnimatingKeys).forEach(function (key) { | ||
_this3.stop(key); | ||
}); | ||
} | ||
var showProp = props.showProp; | ||
var currentlyAnimatingKeys = this.currentlyAnimatingKeys; | ||
// last props children if exclusive | ||
var currentChildren = props.exclusive ? (0, _ChildrenUtils.toArrayChildren)(getChildrenFromProps(props)) : this.state.children; | ||
// in case destroy in showProp mode | ||
var newChildren = []; | ||
if (showProp) { | ||
currentChildren.forEach(function (currentChild) { | ||
var nextChild = currentChild && (0, _ChildrenUtils.findChildInChildrenByKey)(nextChildren, currentChild.key); | ||
var newChild = void 0; | ||
if ((!nextChild || !nextChild.props[showProp]) && currentChild.props[showProp]) { | ||
newChild = _react2["default"].cloneElement(nextChild || currentChild, _defineProperty({}, showProp, true)); | ||
} else { | ||
newChild = nextChild; | ||
children.forEach(function (child) { | ||
if (child) { | ||
_this2.performAppear(child.key); | ||
} | ||
if (newChild) { | ||
newChildren.push(newChild); | ||
} | ||
}); | ||
nextChildren.forEach(function (nextChild) { | ||
if (!nextChild || !(0, _ChildrenUtils.findChildInChildrenByKey)(currentChildren, nextChild.key)) { | ||
newChildren.push(nextChild); | ||
} | ||
}); | ||
} else { | ||
newChildren = (0, _ChildrenUtils.mergeChildren)(currentChildren, nextChildren); | ||
} | ||
}, { | ||
key: 'componentWillReceiveProps', | ||
value: function componentWillReceiveProps(nextProps) { | ||
var _this3 = this; | ||
// need render to avoid update | ||
this.setState({ | ||
children: newChildren | ||
}); | ||
nextChildren.forEach(function (child) { | ||
var key = child && child.key; | ||
if (child && currentlyAnimatingKeys[key]) { | ||
return; | ||
this.nextProps = nextProps; | ||
var nextChildren = (0, _ChildrenUtils.toArrayChildren)(getChildrenFromProps(nextProps)); | ||
var props = this.props; | ||
// exclusive needs immediate response | ||
if (props.exclusive) { | ||
Object.keys(this.currentlyAnimatingKeys).forEach(function (key) { | ||
_this3.stop(key); | ||
}); | ||
} | ||
var hasPrev = child && (0, _ChildrenUtils.findChildInChildrenByKey)(currentChildren, key); | ||
var showProp = props.showProp; | ||
var currentlyAnimatingKeys = this.currentlyAnimatingKeys; | ||
// last props children if exclusive | ||
var currentChildren = props.exclusive ? (0, _ChildrenUtils.toArrayChildren)(getChildrenFromProps(props)) : this.state.children; | ||
// in case destroy in showProp mode | ||
var newChildren = []; | ||
if (showProp) { | ||
var showInNext = child.props[showProp]; | ||
if (hasPrev) { | ||
var showInNow = (0, _ChildrenUtils.findShownChildInChildrenByKey)(currentChildren, key, showProp); | ||
if (!showInNow && showInNext) { | ||
currentChildren.forEach(function (currentChild) { | ||
var nextChild = currentChild && (0, _ChildrenUtils.findChildInChildrenByKey)(nextChildren, currentChild.key); | ||
var newChild = void 0; | ||
if ((!nextChild || !nextChild.props[showProp]) && currentChild.props[showProp]) { | ||
newChild = _react2['default'].cloneElement(nextChild || currentChild, (0, _defineProperty3['default'])({}, showProp, true)); | ||
} else { | ||
newChild = nextChild; | ||
} | ||
if (newChild) { | ||
newChildren.push(newChild); | ||
} | ||
}); | ||
nextChildren.forEach(function (nextChild) { | ||
if (!nextChild || !(0, _ChildrenUtils.findChildInChildrenByKey)(currentChildren, nextChild.key)) { | ||
newChildren.push(nextChild); | ||
} | ||
}); | ||
} else { | ||
newChildren = (0, _ChildrenUtils.mergeChildren)(currentChildren, nextChildren); | ||
} | ||
// need render to avoid update | ||
this.setState({ | ||
children: newChildren | ||
}); | ||
nextChildren.forEach(function (child) { | ||
var key = child && child.key; | ||
if (child && currentlyAnimatingKeys[key]) { | ||
return; | ||
} | ||
var hasPrev = child && (0, _ChildrenUtils.findChildInChildrenByKey)(currentChildren, key); | ||
if (showProp) { | ||
var showInNext = child.props[showProp]; | ||
if (hasPrev) { | ||
var showInNow = (0, _ChildrenUtils.findShownChildInChildrenByKey)(currentChildren, key, showProp); | ||
if (!showInNow && showInNext) { | ||
_this3.keysToEnter.push(key); | ||
} | ||
} else if (showInNext) { | ||
_this3.keysToEnter.push(key); | ||
} | ||
} else if (showInNext) { | ||
} else if (!hasPrev) { | ||
_this3.keysToEnter.push(key); | ||
} | ||
} else if (!hasPrev) { | ||
_this3.keysToEnter.push(key); | ||
} | ||
}); | ||
}); | ||
currentChildren.forEach(function (child) { | ||
var key = child && child.key; | ||
if (child && currentlyAnimatingKeys[key]) { | ||
return; | ||
} | ||
var hasNext = child && (0, _ChildrenUtils.findChildInChildrenByKey)(nextChildren, key); | ||
if (showProp) { | ||
var showInNow = child.props[showProp]; | ||
if (hasNext) { | ||
var showInNext = (0, _ChildrenUtils.findShownChildInChildrenByKey)(nextChildren, key, showProp); | ||
if (!showInNext && showInNow) { | ||
currentChildren.forEach(function (child) { | ||
var key = child && child.key; | ||
if (child && currentlyAnimatingKeys[key]) { | ||
return; | ||
} | ||
var hasNext = child && (0, _ChildrenUtils.findChildInChildrenByKey)(nextChildren, key); | ||
if (showProp) { | ||
var showInNow = child.props[showProp]; | ||
if (hasNext) { | ||
var showInNext = (0, _ChildrenUtils.findShownChildInChildrenByKey)(nextChildren, key, showProp); | ||
if (!showInNext && showInNow) { | ||
_this3.keysToLeave.push(key); | ||
} | ||
} else if (showInNow) { | ||
_this3.keysToLeave.push(key); | ||
} | ||
} else if (showInNow) { | ||
} else if (!hasNext) { | ||
_this3.keysToLeave.push(key); | ||
} | ||
} else if (!hasNext) { | ||
_this3.keysToLeave.push(key); | ||
}); | ||
} | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate() { | ||
var keysToEnter = this.keysToEnter; | ||
this.keysToEnter = []; | ||
keysToEnter.forEach(this.performEnter); | ||
var keysToLeave = this.keysToLeave; | ||
this.keysToLeave = []; | ||
keysToLeave.forEach(this.performLeave); | ||
} | ||
}, { | ||
key: 'isValidChildByKey', | ||
value: function isValidChildByKey(currentChildren, key) { | ||
var showProp = this.props.showProp; | ||
if (showProp) { | ||
return (0, _ChildrenUtils.findShownChildInChildrenByKey)(currentChildren, key, showProp); | ||
} | ||
}); | ||
}; | ||
Animate.prototype.componentDidUpdate = function componentDidUpdate() { | ||
var keysToEnter = this.keysToEnter; | ||
this.keysToEnter = []; | ||
keysToEnter.forEach(this.performEnter); | ||
var keysToLeave = this.keysToLeave; | ||
this.keysToLeave = []; | ||
keysToLeave.forEach(this.performLeave); | ||
}; | ||
Animate.prototype.isValidChildByKey = function isValidChildByKey(currentChildren, key) { | ||
var showProp = this.props.showProp; | ||
if (showProp) { | ||
return (0, _ChildrenUtils.findShownChildInChildrenByKey)(currentChildren, key, showProp); | ||
return (0, _ChildrenUtils.findChildInChildrenByKey)(currentChildren, key); | ||
} | ||
return (0, _ChildrenUtils.findChildInChildrenByKey)(currentChildren, key); | ||
}; | ||
Animate.prototype.stop = function stop(key) { | ||
delete this.currentlyAnimatingKeys[key]; | ||
var component = this.refs[key]; | ||
if (component) { | ||
component.stop(); | ||
}, { | ||
key: 'stop', | ||
value: function stop(key) { | ||
delete this.currentlyAnimatingKeys[key]; | ||
var component = this.childrenRefs[key]; | ||
if (component) { | ||
component.stop(); | ||
} | ||
} | ||
}; | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _this4 = this; | ||
Animate.prototype.render = function render() { | ||
var props = this.props; | ||
this.nextProps = props; | ||
var stateChildren = this.state.children; | ||
var children = null; | ||
if (stateChildren) { | ||
children = stateChildren.map(function (child) { | ||
if (child === null || child === undefined) { | ||
return child; | ||
var props = this.props; | ||
this.nextProps = props; | ||
var stateChildren = this.state.children; | ||
var children = null; | ||
if (stateChildren) { | ||
children = stateChildren.map(function (child) { | ||
if (child === null || child === undefined) { | ||
return child; | ||
} | ||
if (!child.key) { | ||
throw new Error('must set key for <rc-animate> children'); | ||
} | ||
return _react2['default'].createElement( | ||
_AnimateChild2['default'], | ||
{ | ||
key: child.key, | ||
ref: function ref(node) { | ||
return _this4.childrenRefs[child.key] = node; | ||
}, | ||
animation: props.animation, | ||
transitionName: props.transitionName, | ||
transitionEnter: props.transitionEnter, | ||
transitionAppear: props.transitionAppear, | ||
transitionLeave: props.transitionLeave | ||
}, | ||
child | ||
); | ||
}); | ||
} | ||
var Component = props.component; | ||
if (Component) { | ||
var passedProps = props; | ||
if (typeof Component === 'string') { | ||
passedProps = (0, _extends3['default'])({ | ||
className: props.className, | ||
style: props.style | ||
}, props.componentProps); | ||
} | ||
if (!child.key) { | ||
throw new Error('must set key for <rc-animate> children'); | ||
} | ||
return _react2["default"].createElement( | ||
_AnimateChild2["default"], | ||
{ | ||
key: child.key, | ||
ref: child.key, | ||
animation: props.animation, | ||
transitionName: props.transitionName, | ||
transitionEnter: props.transitionEnter, | ||
transitionAppear: props.transitionAppear, | ||
transitionLeave: props.transitionLeave | ||
}, | ||
child | ||
return _react2['default'].createElement( | ||
Component, | ||
passedProps, | ||
children | ||
); | ||
}); | ||
} | ||
var Component = props.component; | ||
if (Component) { | ||
var passedProps = props; | ||
if (typeof Component === 'string') { | ||
passedProps = _extends({ | ||
className: props.className, | ||
style: props.style | ||
}, props.componentProps); | ||
} | ||
return _react2["default"].createElement( | ||
Component, | ||
passedProps, | ||
children | ||
); | ||
return children[0] || null; | ||
} | ||
return children[0] || null; | ||
}; | ||
}]); | ||
return Animate; | ||
}(_react2["default"].Component); | ||
}(_react2['default'].Component); | ||
Animate.propTypes = { | ||
component: _propTypes2["default"].any, | ||
componentProps: _propTypes2["default"].object, | ||
animation: _propTypes2["default"].object, | ||
transitionName: _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].object]), | ||
transitionEnter: _propTypes2["default"].bool, | ||
transitionAppear: _propTypes2["default"].bool, | ||
exclusive: _propTypes2["default"].bool, | ||
transitionLeave: _propTypes2["default"].bool, | ||
onEnd: _propTypes2["default"].func, | ||
onEnter: _propTypes2["default"].func, | ||
onLeave: _propTypes2["default"].func, | ||
onAppear: _propTypes2["default"].func, | ||
showProp: _propTypes2["default"].string | ||
component: _propTypes2['default'].any, | ||
componentProps: _propTypes2['default'].object, | ||
animation: _propTypes2['default'].object, | ||
transitionName: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].object]), | ||
transitionEnter: _propTypes2['default'].bool, | ||
transitionAppear: _propTypes2['default'].bool, | ||
exclusive: _propTypes2['default'].bool, | ||
transitionLeave: _propTypes2['default'].bool, | ||
onEnd: _propTypes2['default'].func, | ||
onEnter: _propTypes2['default'].func, | ||
onLeave: _propTypes2['default'].func, | ||
onAppear: _propTypes2['default'].func, | ||
showProp: _propTypes2['default'].string | ||
}; | ||
@@ -289,9 +314,9 @@ Animate.defaultProps = { | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this4 = this; | ||
var _this5 = this; | ||
this.performEnter = function (key) { | ||
// may already remove by exclusive | ||
if (_this4.refs[key]) { | ||
_this4.currentlyAnimatingKeys[key] = true; | ||
_this4.refs[key].componentWillEnter(_this4.handleDoneAdding.bind(_this4, key, 'enter')); | ||
if (_this5.childrenRefs[key]) { | ||
_this5.currentlyAnimatingKeys[key] = true; | ||
_this5.childrenRefs[key].componentWillEnter(_this5.handleDoneAdding.bind(_this5, key, 'enter')); | ||
} | ||
@@ -301,5 +326,5 @@ }; | ||
this.performAppear = function (key) { | ||
if (_this4.refs[key]) { | ||
_this4.currentlyAnimatingKeys[key] = true; | ||
_this4.refs[key].componentWillAppear(_this4.handleDoneAdding.bind(_this4, key, 'appear')); | ||
if (_this5.childrenRefs[key]) { | ||
_this5.currentlyAnimatingKeys[key] = true; | ||
_this5.childrenRefs[key].componentWillAppear(_this5.handleDoneAdding.bind(_this5, key, 'appear')); | ||
} | ||
@@ -309,15 +334,15 @@ }; | ||
this.handleDoneAdding = function (key, type) { | ||
var props = _this4.props; | ||
delete _this4.currentlyAnimatingKeys[key]; | ||
var props = _this5.props; | ||
delete _this5.currentlyAnimatingKeys[key]; | ||
// if update on exclusive mode, skip check | ||
if (props.exclusive && props !== _this4.nextProps) { | ||
if (props.exclusive && props !== _this5.nextProps) { | ||
return; | ||
} | ||
var currentChildren = (0, _ChildrenUtils.toArrayChildren)(getChildrenFromProps(props)); | ||
if (!_this4.isValidChildByKey(currentChildren, key)) { | ||
if (!_this5.isValidChildByKey(currentChildren, key)) { | ||
// exclusive will not need this | ||
_this4.performLeave(key); | ||
_this5.performLeave(key); | ||
} else { | ||
if (type === 'appear') { | ||
if (_util2["default"].allowAppearCallback(props)) { | ||
if (_util2['default'].allowAppearCallback(props)) { | ||
props.onAppear(key); | ||
@@ -327,3 +352,3 @@ props.onEnd(key, true); | ||
} else { | ||
if (_util2["default"].allowEnterCallback(props)) { | ||
if (_util2['default'].allowEnterCallback(props)) { | ||
props.onEnter(key); | ||
@@ -338,5 +363,5 @@ props.onEnd(key, true); | ||
// may already remove by exclusive | ||
if (_this4.refs[key]) { | ||
_this4.currentlyAnimatingKeys[key] = true; | ||
_this4.refs[key].componentWillLeave(_this4.handleDoneLeaving.bind(_this4, key)); | ||
if (_this5.childrenRefs[key]) { | ||
_this5.currentlyAnimatingKeys[key] = true; | ||
_this5.childrenRefs[key].componentWillLeave(_this5.handleDoneLeaving.bind(_this5, key)); | ||
} | ||
@@ -346,6 +371,6 @@ }; | ||
this.handleDoneLeaving = function (key) { | ||
var props = _this4.props; | ||
delete _this4.currentlyAnimatingKeys[key]; | ||
var props = _this5.props; | ||
delete _this5.currentlyAnimatingKeys[key]; | ||
// if update on exclusive mode, skip check | ||
if (props.exclusive && props !== _this4.nextProps) { | ||
if (props.exclusive && props !== _this5.nextProps) { | ||
return; | ||
@@ -355,7 +380,7 @@ } | ||
// in case state change is too fast | ||
if (_this4.isValidChildByKey(currentChildren, key)) { | ||
_this4.performEnter(key); | ||
if (_this5.isValidChildByKey(currentChildren, key)) { | ||
_this5.performEnter(key); | ||
} else { | ||
var end = function end() { | ||
if (_util2["default"].allowLeaveCallback(props)) { | ||
if (_util2['default'].allowLeaveCallback(props)) { | ||
props.onLeave(key); | ||
@@ -365,4 +390,4 @@ props.onEnd(key, false); | ||
}; | ||
if (!(0, _ChildrenUtils.isSameChildren)(_this4.state.children, currentChildren, props.showProp)) { | ||
_this4.setState({ | ||
if (!(0, _ChildrenUtils.isSameChildren)(_this5.state.children, currentChildren, props.showProp)) { | ||
_this5.setState({ | ||
children: currentChildren | ||
@@ -377,3 +402,3 @@ }, end); | ||
exports["default"] = Animate; | ||
exports['default'] = Animate; | ||
module.exports = exports['default']; |
@@ -7,4 +7,22 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _react = require('react'); | ||
@@ -30,12 +48,4 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
var transitionMap = { | ||
@@ -48,87 +58,94 @@ enter: 'transitionEnter', | ||
var AnimateChild = function (_React$Component) { | ||
_inherits(AnimateChild, _React$Component); | ||
(0, _inherits3['default'])(AnimateChild, _React$Component); | ||
function AnimateChild() { | ||
_classCallCheck(this, AnimateChild); | ||
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments)); | ||
(0, _classCallCheck3['default'])(this, AnimateChild); | ||
return (0, _possibleConstructorReturn3['default'])(this, (AnimateChild.__proto__ || Object.getPrototypeOf(AnimateChild)).apply(this, arguments)); | ||
} | ||
AnimateChild.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this.stop(); | ||
}; | ||
AnimateChild.prototype.componentWillEnter = function componentWillEnter(done) { | ||
if (_util2["default"].isEnterSupported(this.props)) { | ||
this.transition('enter', done); | ||
} else { | ||
done(); | ||
(0, _createClass3['default'])(AnimateChild, [{ | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this.stop(); | ||
} | ||
}; | ||
AnimateChild.prototype.componentWillAppear = function componentWillAppear(done) { | ||
if (_util2["default"].isAppearSupported(this.props)) { | ||
this.transition('appear', done); | ||
} else { | ||
done(); | ||
}, { | ||
key: 'componentWillEnter', | ||
value: function componentWillEnter(done) { | ||
if (_util2['default'].isEnterSupported(this.props)) { | ||
this.transition('enter', done); | ||
} else { | ||
done(); | ||
} | ||
} | ||
}; | ||
AnimateChild.prototype.componentWillLeave = function componentWillLeave(done) { | ||
if (_util2["default"].isLeaveSupported(this.props)) { | ||
this.transition('leave', done); | ||
} else { | ||
// always sync, do not interupt with react component life cycle | ||
// update hidden -> animate hidden -> | ||
// didUpdate -> animate leave -> unmount (if animate is none) | ||
done(); | ||
}, { | ||
key: 'componentWillAppear', | ||
value: function componentWillAppear(done) { | ||
if (_util2['default'].isAppearSupported(this.props)) { | ||
this.transition('appear', done); | ||
} else { | ||
done(); | ||
} | ||
} | ||
}; | ||
AnimateChild.prototype.transition = function transition(animationType, finishCallback) { | ||
var _this2 = this; | ||
var node = _reactDom2["default"].findDOMNode(this); | ||
var props = this.props; | ||
var transitionName = props.transitionName; | ||
var nameIsObj = (typeof transitionName === 'undefined' ? 'undefined' : _typeof(transitionName)) === 'object'; | ||
this.stop(); | ||
var end = function end() { | ||
_this2.stopper = null; | ||
finishCallback(); | ||
}; | ||
if ((_cssAnimation.isCssAnimationSupported || !props.animation[animationType]) && transitionName && props[transitionMap[animationType]]) { | ||
var name = nameIsObj ? transitionName[animationType] : transitionName + '-' + animationType; | ||
var activeName = name + '-active'; | ||
if (nameIsObj && transitionName[animationType + 'Active']) { | ||
activeName = transitionName[animationType + 'Active']; | ||
}, { | ||
key: 'componentWillLeave', | ||
value: function componentWillLeave(done) { | ||
if (_util2['default'].isLeaveSupported(this.props)) { | ||
this.transition('leave', done); | ||
} else { | ||
// always sync, do not interupt with react component life cycle | ||
// update hidden -> animate hidden -> | ||
// didUpdate -> animate leave -> unmount (if animate is none) | ||
done(); | ||
} | ||
this.stopper = (0, _cssAnimation2["default"])(node, { | ||
name: name, | ||
active: activeName | ||
}, end); | ||
} else { | ||
this.stopper = props.animation[animationType](node, end); | ||
} | ||
}; | ||
}, { | ||
key: 'transition', | ||
value: function transition(animationType, finishCallback) { | ||
var _this2 = this; | ||
AnimateChild.prototype.stop = function stop() { | ||
var stopper = this.stopper; | ||
if (stopper) { | ||
this.stopper = null; | ||
stopper.stop(); | ||
var node = _reactDom2['default'].findDOMNode(this); | ||
var props = this.props; | ||
var transitionName = props.transitionName; | ||
var nameIsObj = (typeof transitionName === 'undefined' ? 'undefined' : (0, _typeof3['default'])(transitionName)) === 'object'; | ||
this.stop(); | ||
var end = function end() { | ||
_this2.stopper = null; | ||
finishCallback(); | ||
}; | ||
if ((_cssAnimation.isCssAnimationSupported || !props.animation[animationType]) && transitionName && props[transitionMap[animationType]]) { | ||
var name = nameIsObj ? transitionName[animationType] : transitionName + '-' + animationType; | ||
var activeName = name + '-active'; | ||
if (nameIsObj && transitionName[animationType + 'Active']) { | ||
activeName = transitionName[animationType + 'Active']; | ||
} | ||
this.stopper = (0, _cssAnimation2['default'])(node, { | ||
name: name, | ||
active: activeName | ||
}, end); | ||
} else { | ||
this.stopper = props.animation[animationType](node, end); | ||
} | ||
} | ||
}; | ||
AnimateChild.prototype.render = function render() { | ||
return this.props.children; | ||
}; | ||
}, { | ||
key: 'stop', | ||
value: function stop() { | ||
var stopper = this.stopper; | ||
if (stopper) { | ||
this.stopper = null; | ||
stopper.stop(); | ||
} | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
return this.props.children; | ||
} | ||
}]); | ||
return AnimateChild; | ||
}(_react2["default"].Component); | ||
}(_react2['default'].Component); | ||
AnimateChild.propTypes = { | ||
children: _propTypes2["default"].any | ||
children: _propTypes2['default'].any | ||
}; | ||
exports["default"] = AnimateChild; | ||
exports['default'] = AnimateChild; | ||
module.exports = exports['default']; |
@@ -17,7 +17,7 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function toArrayChildren(children) { | ||
var ret = []; | ||
_react2["default"].Children.forEach(children, function (child) { | ||
_react2['default'].Children.forEach(children, function (child) { | ||
ret.push(child); | ||
@@ -24,0 +24,0 @@ }); |
{ | ||
"name": "rc-animate", | ||
"version": "2.3.6", | ||
"version": "2.4.0", | ||
"description": "css-transition ui component for react", | ||
@@ -12,2 +12,3 @@ "keywords": [ | ||
"files": [ | ||
"es", | ||
"lib" | ||
@@ -25,3 +26,4 @@ ], | ||
"licenses": "MIT", | ||
"main": "./lib/index", | ||
"main": "./lib/Animate", | ||
"module": "./es/Animate", | ||
"config": { | ||
@@ -34,9 +36,9 @@ "port": 8200 | ||
"start": "rc-tools run server", | ||
"pub": "rc-tools run pub", | ||
"pub": "rc-tools run pub --babel-runtime", | ||
"lint": "rc-tools run lint", | ||
"karma": "rc-tools run karma", | ||
"saucelabs": "rc-tools run saucelabs", | ||
"test": "rc-tools run test", | ||
"chrome-test": "rc-tools run chrome-test", | ||
"coverage": "rc-tools run coverage" | ||
"karma": "rc-test run karma", | ||
"saucelabs": "rc-test run saucelabs", | ||
"test": "rc-test run test", | ||
"chrome-test": "rc-test run chrome-test", | ||
"coverage": "rc-test run coverage" | ||
}, | ||
@@ -48,5 +50,5 @@ "devDependencies": { | ||
"pre-commit": "1.x", | ||
"rc-tools": "5.x", | ||
"rc-test": "6.x", | ||
"rc-tools": "6.x", | ||
"react": "15.x", | ||
"react-addons-test-utils": "15.x", | ||
"react-dom": "15.x", | ||
@@ -59,5 +61,6 @@ "velocity-animate": "~1.2.2" | ||
"dependencies": { | ||
"css-animation": "^1.3.0", | ||
"prop-types": "^15.5.6" | ||
"babel-runtime": "6.x", | ||
"css-animation": "1.x", | ||
"prop-types": "15.x" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45540
12
1123
3
+ Addedbabel-runtime@6.x
Updatedcss-animation@1.x
Updatedprop-types@15.x