1+ "use strict" ;
2+
3+ Object . defineProperty ( exports , "__esModule" , {
4+ value : true
5+ } ) ;
6+ exports . default = _default ;
7+
8+ require ( "core-js/modules/es6.string.iterator" ) ;
9+
10+ require ( "core-js/modules/es6.array.from" ) ;
11+
12+ require ( "core-js/modules/es6.regexp.to-string" ) ;
13+
14+ require ( "core-js/modules/es7.symbol.async-iterator" ) ;
15+
16+ require ( "core-js/modules/es6.symbol" ) ;
17+
18+ require ( "core-js/modules/web.dom.iterable" ) ;
19+
20+ require ( "core-js/modules/es6.array.iterator" ) ;
21+
22+ require ( "core-js/modules/es6.object.to-string" ) ;
23+
24+ require ( "core-js/modules/es6.object.keys" ) ;
25+
26+ require ( "core-js/modules/es6.object.set-prototype-of" ) ;
27+
28+ require ( "core-js/modules/es6.string.starts-with" ) ;
29+
30+ require ( "core-js/modules/es6.regexp.replace" ) ;
31+
32+ var _react = _interopRequireDefault ( require ( "react" ) ) ;
33+
34+ var _propTypes = _interopRequireDefault ( require ( "prop-types" ) ) ;
35+
36+ var _util = require ( "./util" ) ;
37+
38+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
39+
40+ 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 ) ; }
41+
42+ function _toConsumableArray ( arr ) { return _arrayWithoutHoles ( arr ) || _iterableToArray ( arr ) || _nonIterableSpread ( ) ; }
43+
44+ function _nonIterableSpread ( ) { throw new TypeError ( "Invalid attempt to spread non-iterable instance" ) ; }
45+
46+ function _iterableToArray ( iter ) { if ( Symbol . iterator in Object ( iter ) || Object . prototype . toString . call ( iter ) === "[object Arguments]" ) return Array . from ( iter ) ; }
47+
48+ function _arrayWithoutHoles ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = new Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } }
49+
50+ function _objectWithoutProperties ( source , excluded ) { if ( source == null ) return { } ; var target = _objectWithoutPropertiesLoose ( source , excluded ) ; var key , i ; if ( Object . getOwnPropertySymbols ) { var sourceSymbolKeys = Object . getOwnPropertySymbols ( source ) ; for ( i = 0 ; i < sourceSymbolKeys . length ; i ++ ) { key = sourceSymbolKeys [ i ] ; if ( excluded . indexOf ( key ) >= 0 ) continue ; if ( ! Object . prototype . propertyIsEnumerable . call ( source , key ) ) continue ; target [ key ] = source [ key ] ; } } return target ; }
51+
52+ function _objectWithoutPropertiesLoose ( source , excluded ) { if ( source == null ) return { } ; var target = { } ; var sourceKeys = Object . keys ( source ) ; var key , i ; for ( i = 0 ; i < sourceKeys . length ; i ++ ) { key = sourceKeys [ i ] ; if ( excluded . indexOf ( key ) >= 0 ) continue ; target [ key ] = source [ key ] ; } return target ; }
53+
54+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
55+
56+ 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 ) ; } }
57+
58+ function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
59+
60+ function _possibleConstructorReturn ( self , call ) { if ( call && ( _typeof ( call ) === "object" || typeof call === "function" ) ) { return call ; } return _assertThisInitialized ( self ) ; }
61+
62+ function _assertThisInitialized ( self ) { if ( self === void 0 ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return self ; }
63+
64+ function _getPrototypeOf ( o ) { _getPrototypeOf = Object . setPrototypeOf ? Object . getPrototypeOf : function _getPrototypeOf ( o ) { return o . __proto__ || Object . getPrototypeOf ( o ) ; } ; return _getPrototypeOf ( o ) ; }
65+
66+ 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 ) ; }
67+
68+ function _setPrototypeOf ( o , p ) { _setPrototypeOf = Object . setPrototypeOf || function _setPrototypeOf ( o , p ) { o . __proto__ = p ; return o ; } ; return _setPrototypeOf ( o , p ) ; }
69+
70+ 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 ; }
71+
72+ function guardEvent ( e ) {
73+ // don't redirect with control keys
74+ if ( e . metaKey || e . altKey || e . ctrlKey || e . shiftKey ) return ; // don't redirect when preventDefault called
75+
76+ if ( e . defaultPrevented ) return ; // don't redirect on right click
77+
78+ if ( e . button !== undefined && e . button !== 0 ) return ; // don't redirect if `target="_blank"`
79+
80+ if ( e . currentTarget && e . currentTarget . getAttribute ) {
81+ var target = e . currentTarget . getAttribute ( 'target' ) ;
82+ if ( / \b _ b l a n k \b / i. test ( target ) ) return ;
83+ } // this may be a Weex event which doesn't have this method
84+
85+
86+ if ( e . preventDefault ) {
87+ e . preventDefault ( ) ;
88+ }
89+
90+ return true ;
91+ }
92+
93+ function _default ( router ) {
94+ var _class , _temp ;
95+
96+ return _temp = _class =
97+ /*#__PURE__*/
98+ function ( _React$Component ) {
99+ _inherits ( RouterLink , _React$Component ) ;
100+
101+ function RouterLink ( props ) {
102+ var _this ;
103+
104+ _classCallCheck ( this , RouterLink ) ;
105+
106+ _this = _possibleConstructorReturn ( this , _getPrototypeOf ( RouterLink ) . call ( this , props ) ) ;
107+ _this . state = {
108+ inited : false ,
109+ currentRoute : router . currentRoute ,
110+ parentRoute : null
111+ } ;
112+ return _this ;
113+ }
114+
115+ _createClass ( RouterLink , [ {
116+ key : "componentDidMount" ,
117+ value : function componentDidMount ( ) {
118+ var _this2 = this ;
119+
120+ this . unplugin = router . plugin ( {
121+ name : 'router-link-plugin' ,
122+ onRouteChange : function onRouteChange ( currentRoute ) {
123+ return _this2 . setState ( {
124+ currentRoute : currentRoute
125+ } ) ;
126+ }
127+ } ) ;
128+ var routerView = ( 0 , _util . getParentRouterView ) ( this ) ;
129+ this . setState ( {
130+ inited : true ,
131+ parentRoute : routerView ? routerView . state . currentRoute : null
132+ } ) ;
133+ }
134+ } , {
135+ key : "componentWillUnmount" ,
136+ value : function componentWillUnmount ( ) {
137+ if ( this . unplugin ) this . unplugin ( ) ;
138+ }
139+ } , {
140+ key : "shouldComponentUpdate" ,
141+ value : function shouldComponentUpdate ( nextProps , nextState ) {
142+ if ( this . props . to !== nextProps . to ) return true ;
143+ if ( this . props . replace !== nextProps . replace ) return true ;
144+ if ( this . props . tag !== nextProps . tag ) return true ;
145+ if ( this . props . activeClass !== nextProps . activeClass ) return true ;
146+ if ( this . props . exact !== nextProps . exact ) return true ;
147+ if ( this . props . exactActiveClass !== nextProps . exactActiveClass ) return true ;
148+ if ( this . props . event !== nextProps . event ) return true ;
149+ if ( this . state . inited !== nextState . inited ) return true ;
150+ if ( ( 0 , _util . isRouteChanged ) ( this . state . parentRoute , nextState . parentRoute ) ) return true ;
151+ if ( ( 0 , _util . isRouteChanged ) ( this . state . currentRoute , nextState . currentRoute ) ) return true ;
152+ return false ;
153+ }
154+ } , {
155+ key : "render" ,
156+ value : function render ( ) {
157+ if ( ! this . state . inited ) return null ;
158+
159+ var _this$props = this . props ,
160+ tag = _this$props . tag ,
161+ to = _this$props . to ,
162+ exact = _this$props . exact ,
163+ replace = _this$props . replace ,
164+ append = _this$props . append ,
165+ event = _this$props . event ,
166+ _this$props$children = _this$props . children ,
167+ children = _this$props$children === void 0 ? [ ] : _this$props$children ,
168+ activeClass = _this$props . activeClass ,
169+ exactActiveClass = _this$props . exactActiveClass ,
170+ remainProps = _objectWithoutProperties ( _this$props , [ "tag" , "to" , "exact" , "replace" , "append" , "event" , "children" , "activeClass" , "exactActiveClass" ] ) ;
171+
172+ var current = this . state . currentRoute ;
173+ to = ( 0 , _util . normalizeLocation ) ( to , this . state . parentRoute , append ) ;
174+ if ( router . linkActiveClass ) activeClass = router . linkActiveClass ;
175+ if ( router . linkExactActiveClass ) exactActiveClass = router . linkExactActiveClass ;
176+ var fallbackClass = exact ? to . path === current . path ? exactActiveClass : '' : current . path . startsWith ( to . path ) ? activeClass : '' ;
177+
178+ if ( fallbackClass ) {
179+ if ( remainProps . className ) remainProps . className = "" . concat ( fallbackClass , " " ) . concat ( remainProps . className ) ; else remainProps . className = fallbackClass ;
180+ }
181+
182+ if ( ! Array . isArray ( event ) ) event = [ event ] ;
183+ event . forEach ( function ( evt ) {
184+ remainProps [ ( 0 , _util . camelize ) ( "on-" . concat ( evt ) ) ] = function ( e ) {
185+ guardEvent ( e ) ;
186+ if ( replace ) router . replace ( to ) ; else router . push ( to ) ;
187+ } ;
188+ } ) ;
189+ if ( tag === 'a' ) remainProps . href = to . path ;
190+ return _react . default . createElement . apply ( _react . default , [ tag , remainProps ] . concat ( _toConsumableArray ( children ) ) ) ;
191+ }
192+ } ] ) ;
193+
194+ return RouterLink ;
195+ } ( _react . default . Component ) , _defineProperty ( _class , "propTypes" , {
196+ to : _propTypes . default . oneOfType ( [ _propTypes . default . string , _propTypes . default . object ] ) . isRequired ,
197+ replace : _propTypes . default . bool ,
198+ append : _propTypes . default . bool ,
199+ tag : _propTypes . default . oneOfType ( [ _propTypes . default . string , _propTypes . default . elementType ] ) ,
200+ activeClass : _propTypes . default . string ,
201+ exact : _propTypes . default . bool ,
202+ exactActiveClass : _propTypes . default . string ,
203+ event : _propTypes . default . oneOfType ( [ _propTypes . default . string , _propTypes . default . arrayOf ( _propTypes . default . string ) ] )
204+ } ) , _defineProperty ( _class , "defaultProps" , {
205+ tag : 'a' ,
206+ activeClass : 'router-link-active' ,
207+ exactActiveClass : 'exact-active-class' ,
208+ event : 'click'
209+ } ) , _temp ;
210+ }
0 commit comments