11/**
2- * Maintained by YMFE Copyright 2018-01-30
2+ * Maintained by YMFE Copyright 2018-02-01
33 * IE9+
44 */
55
@@ -648,6 +648,9 @@ function emptyElement(node) {
648648 var child ;
649649 while ( child = node . firstChild ) {
650650 emptyElement ( child ) ;
651+ if ( child === Refs . focusNode ) {
652+ Refs . focusNode = false ;
653+ }
651654 node . removeChild ( child ) ;
652655 }
653656}
@@ -659,7 +662,6 @@ function removeElement(node) {
659662 if ( ! node ) {
660663 return ;
661664 }
662- Refs . nodeOperate = true ;
663665 if ( node . nodeType === 1 ) {
664666 if ( isStandard ) {
665667 node . textContent = "" ;
@@ -673,9 +675,11 @@ function removeElement(node) {
673675 recyclables [ "#text" ] . push ( node ) ;
674676 }
675677 }
678+ if ( node === Refs . focusNode ) {
679+ Refs . focusNode = false ;
680+ }
676681 fragment . appendChild ( node ) ;
677682 fragment . removeChild ( node ) ;
678- Refs . nodeOperate = false ;
679683}
680684
681685var versions = {
@@ -742,6 +746,17 @@ function createElement$1(vnode, p) {
742746 return document . createElement ( type ) ;
743747}
744748
749+ function contains ( a , b ) {
750+ if ( b ) {
751+ while ( b = b . parentNode ) {
752+ if ( b === a ) {
753+ return true ;
754+ }
755+ }
756+ }
757+ return false ;
758+ }
759+
745760function insertElement ( vnode , insertPoint ) {
746761 if ( vnode . _disposed ) {
747762 return ;
@@ -764,9 +779,22 @@ function insertElement(vnode, insertPoint) {
764779 if ( after === dom ) {
765780 return ;
766781 }
767- Refs . nodeOperate = true ;
782+ if ( after === null && dom === parentNode . lastChild ) {
783+ return ;
784+ }
785+ var isElement = vnode . vtype ;
786+
787+ var prevFocus = isElement && document . activeElement ;
768788 parentNode . insertBefore ( dom , after ) ;
769- Refs . nodeOperate = false ;
789+ if ( isElement && prevFocus !== document . activeElement && contains ( document . body , prevFocus ) ) {
790+ try {
791+ Refs . focusNode = prevFocus ;
792+ prevFocus . __inner__ = true ;
793+ prevFocus . focus ( ) ;
794+ } catch ( e ) {
795+ prevFocus . __inner__ = false ;
796+ }
797+ }
770798}
771799
772800var topVnodes = [ ] ;
@@ -801,6 +829,7 @@ function disposeVnode(vnode, updateQueue, silent) {
801829 }
802830}
803831function remove ( ) {
832+ this . vnode . _disposed = true ;
804833 delete this . vnode . stateNode ;
805834 removeElement ( this . node ) ;
806835}
@@ -988,12 +1017,10 @@ function dispatchEvent(e, type, end) {
9881017 }
9891018 var bubble = e . type ;
9901019 var dom = e . target ;
991- if ( bubble === "blur" ) {
992- if ( Refs . nodeOperate ) {
993- Refs . focusNode = dom ;
994- Refs . type = bubble ;
995- }
996- } else if ( bubble === "focus" ) {
1020+ if ( ( type === "focus" || type === "blur" ) && e . currentTarget !== dom ) {
1021+ return ;
1022+ }
1023+ if ( bubble === "focus" ) {
9971024 if ( dom . __inner__ ) {
9981025 dom . __inner__ = false ;
9991026 return ;
@@ -1099,10 +1126,6 @@ function getBrowserName(onStr) {
10991126 return lower ;
11001127}
11011128
1102- eventPropHooks . click = function ( e ) {
1103- return ! e . target . disabled ;
1104- } ;
1105-
11061129/* IE6-11 chrome mousewheel wheelDetla 下 -120 上 120
11071130 firefox DOMMouseScroll detail 下3 上-3
11081131 firefox wheel detlaY 下3 上-3
@@ -1123,13 +1146,6 @@ eventHooks.wheel = function (dom) {
11231146 } ) ;
11241147} ;
11251148
1126- "blur,focus" . replace ( / \w + / g, function ( type ) {
1127- if ( ! document [ "__" + type ] ) {
1128- document [ "__" + type ] = true ;
1129- addGlobalEvent ( type , true ) ;
1130- }
1131- } ) ;
1132-
11331149/**
11341150 *
11351151DOM通过event对象的relatedTarget属性提供了相关元素的信息。这个属性只对于mouseover和mouseout事件才包含值;
@@ -1145,17 +1161,6 @@ function getRelatedTarget(e) {
11451161 return e . relatedTarget ;
11461162}
11471163
1148- function contains ( a , b ) {
1149- if ( b ) {
1150- while ( b = b . parentNode ) {
1151- if ( b === a ) {
1152- return true ;
1153- }
1154- }
1155- }
1156- return false ;
1157- }
1158-
11591164String ( "mouseenter,mouseleave" ) . replace ( / \w + / g, function ( type ) {
11601165 eventHooks [ type ] = function ( dom , name ) {
11611166 var mark = "__" + name ;
@@ -1208,38 +1213,56 @@ function getLowestCommonAncestor(instA, instB) {
12081213 return null ;
12091214}
12101215
1211- if ( isTouch ) {
1212- eventHooks . click = eventHooks . clickcapture = function ( dom ) {
1213- dom . onclick = dom . onclick || noop ;
1214- } ;
1215- }
1216-
1216+ var specialHandles = { } ;
12171217function createHandle ( name , fn ) {
1218- return function ( e ) {
1218+ specialHandles [ name ] = function ( e ) {
12191219 if ( fn && fn ( e ) === false ) {
12201220 return ;
12211221 }
12221222 dispatchEvent ( e , name ) ;
12231223 } ;
12241224}
12251225
1226- var changeHandle = createHandle ( "change" ) ;
1227- var doubleClickHandle = createHandle ( "doubleclick" ) ;
1228- var scrollHandle = createHandle ( "scroll" ) ;
1226+ createHandle ( "change" ) ;
1227+ createHandle ( "doubleclick" ) ;
1228+ createHandle ( "scroll" ) ;
1229+
1230+ if ( isTouch ) {
1231+ eventHooks . click = eventHooks . clickcapture = function ( dom ) {
1232+ dom . onclick = dom . onclick || noop ;
1233+ } ;
1234+ }
1235+
1236+ eventPropHooks . click = function ( e ) {
1237+ return ! e . target . disabled ;
1238+ } ;
12291239
12301240//react将text,textarea,password元素中的onChange事件当成onInput事件
12311241eventHooks . changecapture = eventHooks . change = function ( dom ) {
12321242 if ( / t e x t | p a s s w o r d / . test ( dom . type ) ) {
1233- addEvent ( document , "input" , changeHandle ) ;
1243+ addEvent ( document , "input" , specialHandles . change ) ;
12341244 }
12351245} ;
12361246
1237- eventHooks . scrollcapture = eventHooks . scroll = function ( dom ) {
1238- addEvent ( dom , "scroll" , scrollHandle ) ;
1247+ //这两个事件不进行全局监听
1248+ "blur,focus" . replace ( / \w + / g, function ( type ) {
1249+ globalEvents [ type ] = true ;
1250+ createHandle ( type ) ;
1251+ eventHooks [ type ] = function ( dom , name ) {
1252+ if ( modern ) {
1253+ addEvent ( dom , name , specialHandles [ name ] , true ) ;
1254+ } else {
1255+ addEvent ( dom , name === "focus" ? "focusin" : "focusout" , specialHandles [ name ] ) ;
1256+ }
1257+ } ;
1258+ } ) ;
1259+
1260+ eventHooks . scroll = function ( dom , name ) {
1261+ addEvent ( dom , name , specialHandles [ name ] ) ;
12391262} ;
12401263
1241- eventHooks . doubleclick = eventHooks . doubleclickcapture = function ( ) {
1242- addEvent ( document , "dblclick" , doubleClickHandle ) ;
1264+ eventHooks . doubleclick = function ( dom , name ) {
1265+ addEvent ( document , "dblclick" , specialHandles [ name ] ) ;
12431266} ;
12441267
12451268function SyntheticEvent ( event ) {
@@ -2523,9 +2546,8 @@ CompositeUpdater.prototype = {
25232546 var nodes = collectComponentNodes ( this . children ) ;
25242547 var queue = this . insertCarrier ;
25252548 nodes . forEach ( function ( el ) {
2526- insertElement ( el , queue ) ;
2549+ insertElement ( el , queue . dom ) ;
25272550 queue . dom = el . stateNode ;
2528- // queue.unshift(el.stateNode);
25292551 } ) ;
25302552 } else {
25312553 captureError ( instance , "componentWillUpdate" , [ props , state , context ] ) ;
@@ -2614,16 +2636,6 @@ CompositeUpdater.prototype = {
26142636 if ( ! hasMounted ) {
26152637 this . isMounted = returnTrue ;
26162638 }
2617- var node = Refs . focusNode ;
2618- if ( node ) {
2619- try {
2620- node . focus ( ) ;
2621- node . __inner__ = true ;
2622- } catch ( e ) {
2623- //hack
2624- }
2625- delete Refs . focusNode ;
2626- }
26272639 if ( this . _hydrating ) {
26282640 var hookName = hasMounted ? "componentDidUpdate" : "componentDidMount" ;
26292641 captureError ( instance , hookName , this . _hookArgs || [ ] ) ;
@@ -2672,7 +2684,7 @@ CompositeUpdater.prototype = {
26722684 captureError ( instance , "componentWillUnmount" , [ ] ) ;
26732685 //在执行componentWillUnmount后才将关联的元素节点解绑,防止用户在钩子里调用 findDOMNode方法
26742686 this . isMounted = returnFalse ;
2675- this . _disposed = true ;
2687+ vnode . _disposed = this . _disposed = true ;
26762688 }
26772689} ;
26782690function transfer ( queue ) {
@@ -2762,7 +2774,9 @@ function unmountComponentAtNode(container) {
27622774 drainQueue ( queue ) ;
27632775 emptyElement ( container ) ;
27642776 container . __component = null ;
2777+ return true ;
27652778 }
2779+ return false ;
27662780}
27672781//[Top API] ReactDOM.findDOMNode
27682782function findDOMNode ( componentOrElement ) {
@@ -2913,8 +2927,7 @@ function updateVnode(lastVnode, nextVnode, context, updateQueue, insertCarrier)
29132927 var dom = nextVnode . stateNode = lastVnode . stateNode ;
29142928 options . beforeUpdate ( nextVnode ) ;
29152929 if ( lastVnode . vtype < 2 ) {
2916- var insertPoint = insertCarrier . dom ;
2917- insertElement ( nextVnode , insertPoint ) ;
2930+ insertElement ( nextVnode , insertCarrier . dom ) ;
29182931 insertCarrier . dom = dom ;
29192932 if ( lastVnode . vtype === 0 ) {
29202933 if ( nextVnode . text !== lastVnode . text ) {
@@ -2973,7 +2986,9 @@ function receiveComponent(lastVnode, nextVnode, parentContext, updateQueue, inse
29732986 if ( ! updater . _dirty ) {
29742987 updater . _receiving = true ;
29752988 updater . updateQueue = updateQueue ;
2976- captureError ( stateNode , "componentWillReceiveProps" , [ nextVnode . props , nextContext ] ) ;
2989+ if ( willReceive ) {
2990+ captureError ( stateNode , "componentWillReceiveProps" , [ nextVnode . props , nextContext ] ) ;
2991+ }
29772992 if ( updater . _hasError ) {
29782993 return ;
29792994 }
@@ -3080,7 +3095,7 @@ if (win.React && win.React.options) {
30803095 React = win . React ; //解决引入多个
30813096} else {
30823097 React = win . React = win . ReactDOM = {
3083- version : "2.0.2 " ,
3098+ version : "2.0.3 " ,
30843099 render : render ,
30853100 hydrate : render ,
30863101 options : options ,
0 commit comments