11<script >
22import  *  as  hp  from  ' helper-js' 
3+ import  *  as  ut  from  ' ../../utils' 
34import  makeTreeDraggable  from  ' ./draggable.js' 
45
56const  treesStore  =  {}
@@ -118,6 +119,7 @@ export default {
118119      indent:  this .indent , 
119120      triggerClass:  this .triggerClass , 
120121      unfoldWhenDragover:  this .unfoldWhenDragover , 
122+       cloneWhenDrag:  this .cloneWhenDrag , 
121123      treeClass:  ' he-tree'  , 
122124      rootClass:  ' tree-root'  , 
123125      childrenClass:  ' tree-children'  , 
@@ -187,6 +189,9 @@ export default {
187189        const  {startTree , dragBranchEl , startPath } =  store 
188190        const  path  =  startTree .getPathByBranchEl (dragBranchEl) 
189191        store .dragNode  =  startTree .getNodeByPath (path) 
192+         if  (this .cloneWhenDrag ) { 
193+           store .dragNode  =  ut .cloneTreeData (store .dragNode ) 
194+         } 
190195        if  (! startTree .isNodeDraggable (store .dragNode , path)) { 
191196          return  false  
192197        } 
@@ -201,7 +206,9 @@ export default {
201206        const  {startTree } =  store 
202207        if  (startTree !==  targetTree) { 
203208          if  (this ._internal_hook_filterTargetTree ) { 
204-             return  this ._internal_hook_filterTargetTree (store) 
209+             if  (this ._internal_hook_filterTargetTree (targetTree, store) ===  false ) { 
210+               return  false  
211+             } 
205212          } else  { 
206213            console .log (' he-tree: The plugin DraggablePro is required for `crossTree` feature.'  ) 
207214            return  false  
@@ -227,29 +234,31 @@ export default {
227234      ondrop :  (store , t ) =>  { 
228235        if  (store .pathChanged ) { 
229236          const  {startTree , targetTree , startPath , targetPath , dragNode } =  store 
230-           //  remove from start position 
231-           const  startParentPath  =  hp .arrayWithoutEnd (startPath, 1 ) 
232-           const  startParent  =  startTree .getNodeByPath (startParentPath) 
233-           const  startSiblings  =  startParent ?  startParent .children  :  startTree .treeData  
234-           const  startIndex  =  hp .arrayLast (startPath) 
235-           startSiblings .splice (startIndex, 1 ) 
236-           //  update targetPath 
237-           if  (startTree ===  targetTree) { 
238-             if  (startPath .length  <=  targetPath .length ) { 
239-               const  lenNoEnd  =  startPath .length  -  1  
240-               let  same =  true  
241-               for  (let  i =  0 ; i <  lenNoEnd; i++ ) { 
242-                 const  s  =  startPath[i] 
243-                 const  t  =  targetPath[i] 
244-                 if  (s !==  t) { 
245-                   same =  false  
246-                   break  
237+           if  (this .cloneWhenDrag  !==  true ) { 
238+             //  remove from start position 
239+             const  startParentPath  =  hp .arrayWithoutEnd (startPath, 1 ) 
240+             const  startParent  =  startTree .getNodeByPath (startParentPath) 
241+             const  startSiblings  =  startParentPath .length  ===  0  ?  startTree .treeData  :  startParent .children  
242+             const  startIndex  =  hp .arrayLast (startPath) 
243+             startSiblings .splice (startIndex, 1 ) 
244+             //  update targetPath 
245+             if  (startTree ===  targetTree) { 
246+               if  (startPath .length  <=  targetPath .length ) { 
247+                 const  lenNoEnd  =  startPath .length  -  1  
248+                 let  same =  true  
249+                 for  (let  i =  0 ; i <  lenNoEnd; i++ ) { 
250+                   const  s  =  startPath[i] 
251+                   const  t  =  targetPath[i] 
252+                   if  (s !==  t) { 
253+                     same =  false  
254+                     break  
255+                   } 
247256                } 
248-               }  
249-               if  (same) {  
250-                 const   endIndex   =   startPath . length   -   1  
251-                 if  (startPath[endIndex]  <   targetPath[endIndex]) {  
252-                   targetPath[endIndex]  -=   1  
257+                  if  (same) {  
258+                    const   endIndex   =   startPath . length   -   1  
259+                    if  ( startPath[endIndex]  <  targetPath[endIndex]) {  
260+                      targetPath[endIndex]  -=   1  
261+                   }  
253262                } 
254263              } 
255264            } 
@@ -258,13 +267,13 @@ export default {
258267          const  targetParentPath  =  hp .arrayWithoutEnd (targetPath, 1 ) 
259268          const  targetParent  =  targetTree .getNodeByPath (targetParentPath) 
260269          let  targetSiblings 
261-           if  (targetParent) { 
270+           if  (targetParentPath .length  ===  0 ) { 
271+             targetSiblings =  targetTree .treeData  
272+           } else  { 
262273            if  (! targetParent .children ) { 
263274              this .$set (targetParent, ' children'  , []) 
264275            } 
265276            targetSiblings =  targetParent .children  
266-           } else  { 
267-             targetSiblings =  targetTree .treeData  
268277          } 
269278          const  targetIndex  =  hp .arrayLast (targetPath) 
270279          targetSiblings .splice (targetIndex, 0 , dragNode) 
@@ -285,8 +294,11 @@ export default {
285294    } 
286295    const  _makeTreeDraggable_obj  =  this ._makeTreeDraggable_obj  =  makeTreeDraggable (this .$el , options); 
287296    //  watch props and update options 
288-     [' indent'  , ' triggerClass'  , ' unfoldWhenDragover'  ].forEach (name  =>  { 
289-       this .$watch (name, (value ) =>  { _makeTreeDraggable_obj .options [name] =  value }) 
297+     [' indent'  , ' triggerClass'  , ' unfoldWhenDragover'  , ' cloneWhenDrag'  ].forEach (name  =>  { 
298+       this .$watch (name, (value ) =>  { 
299+         _makeTreeDraggable_obj .options [name] =  value 
300+         _makeTreeDraggable_obj .optionsUpdated () 
301+       }) 
290302    }) 
291303  }, 
292304} 
0 commit comments