11import PropTypes from '../../_util/vue-types'
22import classNames from 'classnames'
33import warning from 'warning'
4- import { initDefaultProps , getOptionProps } from '../../_util/props-util'
4+ import { initDefaultProps , getOptionProps , getSlots } from '../../_util/props-util'
55import { cloneElement } from '../../_util/vnode'
66import BaseMixin from '../../_util/BaseMixin'
77import {
@@ -162,9 +162,10 @@ const Tree = {
162162 }
163163 return {
164164 ...state ,
165- ...( this . getSyncProps ( props ) || { } ) ,
165+ ...this . getSyncProps ( props ) ,
166166 dragOverNodeKey : '' ,
167167 dropPosition : null ,
168+ dragNodesKeys : [ ] ,
168169 }
169170 } ,
170171 provide ( ) {
@@ -203,8 +204,8 @@ const Tree = {
203204 methods : {
204205 onNodeDragStart ( event , node ) {
205206 const { sExpandedKeys } = this
206- const { eventKey, children } = node . props
207-
207+ const { eventKey } = node
208+ const children = getSlots ( node ) . default
208209 this . dragNode = node
209210
210211 this . setState ( {
@@ -223,13 +224,13 @@ const Tree = {
223224 */
224225 onNodeDragEnter ( event , node ) {
225226 const { sExpandedKeys } = this
226- const { pos, eventKey } = node . props
227+ const { pos, eventKey } = node
227228
228229 const dropPosition = calcDropPosition ( event , node )
229230
230231 // Skip if drag node is self
231232 if (
232- this . dragNode . props . eventKey === eventKey &&
233+ this . dragNode . eventKey === eventKey &&
233234 dropPosition === 0
234235 ) {
235236 this . setState ( {
@@ -268,7 +269,7 @@ const Tree = {
268269 } , 0 )
269270 } ,
270271 onNodeDragOver ( event , node ) {
271- const { eventKey } = node . props
272+ const { eventKey } = node
272273
273274 // Update drag position
274275 if ( this . dragNode && eventKey === this . dragOverNodeKey ) {
@@ -297,7 +298,7 @@ const Tree = {
297298 onNodeDrop ( event , node ) {
298299 const { dragNodesKeys, dropPosition } = this
299300
300- const { eventKey, pos } = node . props
301+ const { eventKey, pos } = node
301302
302303 this . setState ( {
303304 dragOverNodeKey : '' ,
@@ -509,46 +510,21 @@ const Tree = {
509510 /**
510511 * Sync state with props if needed
511512 */
512- getSyncProps ( props = { } , prevProps ) {
513- let needSync = false
513+ getSyncProps ( props = { } ) {
514514 const newState = { }
515- const myPrevProps = prevProps || { }
516515 const children = this . $slots . default
517- function checkSync ( name ) {
518- if ( props [ name ] !== myPrevProps [ name ] ) {
519- needSync = true
520- return true
521- }
522- return false
523- }
524-
525- // Children change will affect check box status.
526- // And no need to check when prev props not provided
527- if ( prevProps && checkSync ( 'children' ) ) {
528- const { checkedKeys = [ ] , halfCheckedKeys = [ ] } =
529- calcCheckedKeys ( props . checkedKeys || this . sCheckedKeys , props , children ) || { }
530- newState . sCheckedKeys = checkedKeys
531- newState . sHalfCheckedKeys = halfCheckedKeys
532- }
533-
534- // Re-calculate when autoExpandParent or expandedKeys changed
535- if ( prevProps && ( checkSync ( 'autoExpandParent' ) || checkSync ( 'expandedKeys' ) ) ) {
536- newState . sExpandedKeys = props . autoExpandParent
537- ? calcExpandedKeys ( props . expandedKeys , props , children ) : props . expandedKeys
538- }
539-
540- if ( checkSync ( 'selectedKeys' ) ) {
516+ if ( props . selectedKeys !== undefined ) {
541517 newState . sSelectedKeys = calcSelectedKeys ( props . selectedKeys , props , children )
542518 }
543519
544- if ( checkSync ( ' checkedKeys' ) ) {
520+ if ( props . checkedKeys !== undefined ) {
545521 const { checkedKeys = [ ] , halfCheckedKeys = [ ] } =
546522 calcCheckedKeys ( props . checkedKeys , props , children ) || { }
547523 newState . sCheckedKeys = checkedKeys
548524 newState . sHalfCheckedKeys = halfCheckedKeys
549525 }
550526
551- return needSync ? newState : null
527+ return newState
552528 } ,
553529
554530 /**
0 commit comments