1
+ function _typeof ( obj ) { if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) { _typeof = function _typeof ( obj ) { return typeof obj ; } ; } else { _typeof = function _typeof ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ; } return _typeof ( obj ) ; }
2
+
3
+ function _objectSpread ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] != null ? arguments [ i ] : { } ; var ownKeys = Object . keys ( source ) ; if ( typeof Object . getOwnPropertySymbols === 'function' ) { ownKeys = ownKeys . concat ( Object . getOwnPropertySymbols ( source ) . filter ( function ( sym ) { return Object . getOwnPropertyDescriptor ( source , sym ) . enumerable ; } ) ) ; } ownKeys . forEach ( function ( key ) { _defineProperty ( target , key , source [ key ] ) ; } ) ; } return target ; }
4
+
5
+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
6
+
7
+ function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
8
+
9
+ function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
10
+
11
+ function _possibleConstructorReturn ( self , call ) { if ( call && ( _typeof ( call ) === "object" || typeof call === "function" ) ) { return call ; } return _assertThisInitialized ( self ) ; }
12
+
13
+ function _getPrototypeOf ( o ) { _getPrototypeOf = Object . setPrototypeOf ? Object . getPrototypeOf : function _getPrototypeOf ( o ) { return o . __proto__ || Object . getPrototypeOf ( o ) ; } ; return _getPrototypeOf ( o ) ; }
14
+
15
+ function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function" ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , writable : true , configurable : true } } ) ; if ( superClass ) _setPrototypeOf ( subClass , superClass ) ; }
16
+
17
+ function _setPrototypeOf ( o , p ) { _setPrototypeOf = Object . setPrototypeOf || function _setPrototypeOf ( o , p ) { o . __proto__ = p ; return o ; } ; return _setPrototypeOf ( o , p ) ; }
18
+
19
+ function _assertThisInitialized ( self ) { if ( self === void 0 ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return self ; }
20
+
21
+ 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 ; }
22
+
23
+ /* eslint-disable react/no-did-mount-set-state */
24
+ import React , { Component } from 'react' ;
25
+ import PropTypes from 'prop-types' ;
26
+ import findKey from 'lodash/findKey' ;
27
+ import { connect } from 'react-redux' ;
28
+ import { findDOMNode } from 'react-dom' ;
29
+ import { VictoryAnimation } from 'victory-core' ;
30
+ import { victoryEases } from '../utils/types' ;
31
+
32
+ var Anim =
33
+ /*#__PURE__*/
34
+ function ( _Component ) {
35
+ _inherits ( Anim , _Component ) ;
36
+
37
+ function Anim ( ) {
38
+ var _getPrototypeOf2 ;
39
+
40
+ var _this ;
41
+
42
+ _classCallCheck ( this , Anim ) ;
43
+
44
+ for ( var _len = arguments . length , args = new Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
45
+ args [ _key ] = arguments [ _key ] ;
46
+ }
47
+
48
+ _this = _possibleConstructorReturn ( this , ( _getPrototypeOf2 = _getPrototypeOf ( Anim ) ) . call . apply ( _getPrototypeOf2 , [ this ] . concat ( args ) ) ) ;
49
+
50
+ _defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "state" , {
51
+ activeAnimation : - 1
52
+ } ) ;
53
+
54
+ _defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "disableAnimation" , function ( ) {
55
+ if ( _this . state . activeAnimation !== _this . props . toStyle . length - 1 ) {
56
+ _this . setState ( {
57
+ activeAnimation : _this . props . toStyle . length - 1
58
+ } ) ;
59
+ }
60
+
61
+ return ;
62
+ } ) ;
63
+
64
+ _defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "updateAnimation" , function ( nextAnimation ) {
65
+ if ( _this . state . activeAnimation !== nextAnimation ) {
66
+ _this . setState ( {
67
+ activeAnimation : nextAnimation
68
+ } ) ;
69
+ }
70
+
71
+ return ;
72
+ } ) ;
73
+
74
+ return _this ;
75
+ }
76
+
77
+ _createClass ( Anim , [ {
78
+ key : "componentDidMount" ,
79
+ value : function componentDidMount ( ) {
80
+ var shouldDisableAnimation = this . props . route . params . indexOf ( 'export' ) !== - 1 || this . props . route . params . indexOf ( 'overview' ) !== - 1 || this . props . route . params . indexOf ( 'notes' ) !== - 1 ;
81
+
82
+ if ( shouldDisableAnimation ) {
83
+ this . setState ( {
84
+ activeAnimation : this . props . toStyle . length - 1
85
+ } ) ;
86
+ return ;
87
+ }
88
+
89
+ var order = this . props . order ;
90
+ var node = findDOMNode ( this . fragmentRef ) ;
91
+
92
+ if ( ! node . dataset ) {
93
+ node . dataset = { } ;
94
+ }
95
+
96
+ node . dataset . order = order ;
97
+ node . dataset . animCount = this . props . toStyle . length ;
98
+ }
99
+ } , {
100
+ key : "componentDidUpdate" ,
101
+ value : function componentDidUpdate ( prevProps , prevState ) {
102
+ var shouldDisableAnimation = this . props . route . params . indexOf ( 'export' ) !== - 1 || this . props . route . params . indexOf ( 'overview' ) !== - 1 || this . props . route . params . indexOf ( 'notes' ) !== - 1 ;
103
+
104
+ if ( shouldDisableAnimation ) {
105
+ this . disableAnimation ( ) ;
106
+ }
107
+
108
+ var animationStatus = this . getAnimationStatus ( ) ;
109
+
110
+ if ( animationStatus ) {
111
+ var nextAnimation = animationStatus . every ( function ( a ) {
112
+ return a === true ;
113
+ } ) ? animationStatus . length - 1 : animationStatus . indexOf ( false ) - 1 ;
114
+
115
+ if ( prevState . activeAnimation !== nextAnimation ) {
116
+ var state = this . props . fragment ;
117
+ var slide = prevProps . route . slide ;
118
+ this . context . stepCounter . setFragments ( state . fragments [ slide ] , slide ) ;
119
+
120
+ if ( prevProps . onAnim ) {
121
+ var forward = prevState . activeAnimation < nextAnimation ;
122
+ prevProps . onAnim ( forward , nextAnimation ) ;
123
+ }
124
+
125
+ this . updateAnimation ( nextAnimation ) ;
126
+ }
127
+ }
128
+ }
129
+ } , {
130
+ key : "getAnimationStatus" ,
131
+ value : function getAnimationStatus ( ) {
132
+ var state = this . props . fragment ;
133
+ var slide = this . props . route . slide ;
134
+ var fragment = findDOMNode ( this . fragmentRef ) ;
135
+ var key = findKey ( state . fragments [ slide ] , {
136
+ id : "" . concat ( this . context . slideHash , "-" ) . concat ( parseInt ( fragment . dataset . fid , 10 ) )
137
+ } ) ;
138
+
139
+ if ( slide in state . fragments && state . fragments [ slide ] . hasOwnProperty ( key ) ) {
140
+ return state . fragments [ slide ] [ key ] . animations ;
141
+ }
142
+
143
+ return null ;
144
+ }
145
+ } , {
146
+ key : "render" ,
147
+ value : function render ( ) {
148
+ var _this2 = this ;
149
+
150
+ var _this$props = this . props ,
151
+ children = _this$props . children ,
152
+ fromStyle = _this$props . fromStyle ,
153
+ toStyle = _this$props . toStyle ,
154
+ transitionDuration = _this$props . transitionDuration ,
155
+ easing = _this$props . easing ,
156
+ style = _this$props . style ;
157
+ var child = React . Children . only ( children ) ;
158
+ var tweenData = this . state . activeAnimation === - 1 ? fromStyle : toStyle [ this . state . activeAnimation ] ;
159
+ return React . createElement ( VictoryAnimation , {
160
+ data : tweenData ,
161
+ duration : transitionDuration ,
162
+ easing : easing
163
+ } , function ( tweenStyle ) {
164
+ return React . cloneElement ( child , {
165
+ className : "fragment " . concat ( child . props . className ) . trim ( ) ,
166
+ style : _objectSpread ( { } , child . props . style , style , tweenStyle ) ,
167
+ ref : function ref ( f ) {
168
+ _this2 . fragmentRef = f ;
169
+ }
170
+ } ) ;
171
+ } ) ;
172
+ }
173
+ } ] ) ;
174
+
175
+ return Anim ;
176
+ } ( Component ) ;
177
+
178
+ Anim . defaultProps = {
179
+ order : 0
180
+ } ;
181
+ Anim . propTypes = {
182
+ children : PropTypes . node ,
183
+ easing : PropTypes . oneOf ( victoryEases ) . isRequired ,
184
+ fragment : PropTypes . object ,
185
+ fromStyle : PropTypes . object . isRequired ,
186
+ onAnim : PropTypes . func ,
187
+ order : PropTypes . number ,
188
+ route : PropTypes . object ,
189
+ style : PropTypes . object ,
190
+ toStyle : PropTypes . arrayOf ( PropTypes . object ) . isRequired ,
191
+ transitionDuration : PropTypes . number . isRequired
192
+ } ;
193
+ Anim . contextTypes = {
194
+ export : PropTypes . bool ,
195
+ overview : PropTypes . bool ,
196
+ slide : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ,
197
+ slideHash : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ,
198
+ stepCounter : PropTypes . shape ( {
199
+ setFragments : PropTypes . func
200
+ } )
201
+ } ;
202
+ export default connect ( function ( state ) {
203
+ return state ;
204
+ } ) ( Anim ) ;
0 commit comments