1
+ 'use strict' ;
2
+
3
+ Object . defineProperty ( exports , '__esModule' , {
4
+ value : true
5
+ } ) ;
6
+
7
+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { 'default' : obj } ; }
8
+
9
+ function _objectWithoutProperties ( obj , keys ) { var target = { } ; for ( var i in obj ) { if ( keys . indexOf ( i ) >= 0 ) continue ; if ( ! Object . prototype . hasOwnProperty . call ( obj , i ) ) continue ; target [ i ] = obj [ i ] ; } return target ; }
10
+
11
+ var _react = require ( 'react' ) ;
12
+
13
+ var _react2 = _interopRequireDefault ( _react ) ;
14
+
15
+ function isLeftClickEvent ( event ) {
16
+ return event . button === 0 ;
17
+ }
18
+
19
+ function isModifiedEvent ( event ) {
20
+ return ! ! ( event . metaKey || event . altKey || event . ctrlKey || event . shiftKey ) ;
21
+ }
22
+
23
+ exports [ 'default' ] = {
24
+ propTypes : {
25
+ active : _react2 [ 'default' ] . PropTypes . bool ,
26
+ activeClassName : _react2 [ 'default' ] . PropTypes . string . isRequired ,
27
+ disabled : _react2 [ 'default' ] . PropTypes . bool ,
28
+ to : _react2 [ 'default' ] . PropTypes . string . isRequired ,
29
+ params : _react2 [ 'default' ] . PropTypes . object ,
30
+ query : _react2 [ 'default' ] . PropTypes . object ,
31
+ onClick : _react2 [ 'default' ] . PropTypes . func
32
+ } ,
33
+ contextTypes : {
34
+ router : _react2 [ 'default' ] . PropTypes . func . isRequired
35
+ } ,
36
+
37
+ getDefaultProps : function getDefaultProps ( ) {
38
+ return {
39
+ activeClassName : 'active'
40
+ } ;
41
+ } ,
42
+
43
+ /**
44
+ * Returns props except those used by this Mixin
45
+ * Gets "active" from router if needed.
46
+ * Gets the value of the "href" attribute to use on the DOM element.
47
+ * Sets "onClick" to "handleRouteTo".
48
+ */
49
+ getLinkProps : function getLinkProps ( ) {
50
+ var _props = this . props ;
51
+ var to = _props . to ;
52
+ var params = _props . params ;
53
+ var query = _props . query ;
54
+
55
+ var props = _objectWithoutProperties ( _props , [ 'to' , 'params' , 'query' ] ) ;
56
+
57
+ if ( this . props . active === undefined ) {
58
+ props . active = this . context . router . isActive ( to , params , query ) ;
59
+ }
60
+
61
+ props . href = this . context . router . makeHref ( to , params , query ) ;
62
+
63
+ props . onClick = this . handleRouteTo ;
64
+
65
+ return props ;
66
+ } ,
67
+
68
+ handleRouteTo : function handleRouteTo ( event ) {
69
+ var allowTransition = true ;
70
+ var clickResult = undefined ;
71
+
72
+ if ( this . props . disabled ) {
73
+ event . preventDefault ( ) ;
74
+ return ;
75
+ }
76
+
77
+ if ( this . props . onClick ) {
78
+ clickResult = this . props . onClick ( event ) ;
79
+ }
80
+
81
+ if ( isModifiedEvent ( event ) || ! isLeftClickEvent ( event ) ) {
82
+ return ;
83
+ }
84
+
85
+ if ( clickResult === false || event . defaultPrevented === true ) {
86
+ allowTransition = false ;
87
+ }
88
+
89
+ event . preventDefault ( ) ;
90
+
91
+ if ( allowTransition ) {
92
+ this . context . router . transitionTo ( this . props . to , this . props . params , this . props . query ) ;
93
+ }
94
+ }
95
+ } ;
96
+ module . exports = exports [ 'default' ] ;
0 commit comments