11/*! 
2-  * he-tree-vue v2.0.9  
2+  * he-tree-vue v2.0.10  
33 * (c) phphe <phphe@outlook.com> (https://github.com/phphe) 
44 * Homepage: https://he-tree-vue.phphe.com 
55 * Released under the MIT License. 
66 */ 
77import  _toConsumableArray  from  '@babel/runtime/helpers/toConsumableArray' ; 
88import  _defineProperty  from  '@babel/runtime/helpers/defineProperty' ; 
9- import  {  TreeData ,  randString ,  findParent ,  hasClass ,  createElementFromHTML ,  insertAfter ,  addClass ,  getOffset ,  getBoundingClientRect ,  elementsFromPoint ,  isDescendantOf ,  attachCache ,  removeEl ,  binarySearch ,  findNodeList ,  appendTo ,  insertBefore ,  prependTo ,  waitTime ,  arrayLast , iterateAll ,  resolveValueOrGettter ,  arrayWithoutEnd  }  from  'helper-js' ; 
9+ import  {  TreeData ,  randString ,  findParent ,  hasClass ,  createElementFromHTML ,  insertAfter ,  addClass ,  getOffset ,  getBoundingClientRect ,  elementsFromPoint ,  isDescendantOf ,  attachCache ,  removeEl ,  binarySearch ,  findNodeList ,  appendTo ,  insertBefore ,  prependTo ,  waitTime ,  iterateAll ,  resolveValueOrGettter ,  arrayWithoutEnd , arrayLast  }  from  'helper-js' ; 
1010import  {  updatablePropsEvenUnbound ,  hookHelper  }  from  'vue-functions' ; 
1111import  __vue_normalize__  from  'vue-runtime-helpers/dist/normalize-component.mjs' ; 
1212import  Vue  from  'vue' ; 
@@ -1393,31 +1393,33 @@ function makeTreeDraggable(treeEl) {
13931393 } , 
13941394 beforeDrop : function  ( )  { 
13951395 var  _beforeDrop  =  _asyncToGenerator (  /*#__PURE__*/ _regeneratorRuntime . mark ( function  _callee14 ( store ,  dhOptions )  { 
1396-  var  endEvent ,  movingEl ,  placeholder ,  tempChildren ,  movedCount ,  targetTreeEl ,  startTreeEl ,  maskTree ,  maskTree2 ,  pathChanged ,  isPathChanged , isDownwardsSameLevelMove ; 
1396+  var  endEvent ,  movingEl ,  placeholder ,  tempChildren ,  movedCount ,  targetTreeEl ,  startTreeEl ,  maskTree ,  maskTree2 ,  pathChanged ,  isPathChanged ; 
13971397 return  _regeneratorRuntime . wrap ( function  _callee14$ ( _context14 )  { 
13981398 while  ( 1 )  { 
13991399 switch  ( _context14 . prev  =  _context14 . next )  { 
14001400 case  0 :
1401-  isDownwardsSameLevelMove  =  function  _isDownwardsSameLevel ( )  { 
1402-  var  startTree  =  store . startTree , 
1403-  targetTree  =  store . targetTree , 
1404-  startPath  =  store . startPath , 
1405-  targetPath  =  store . targetPath ; 
1406-  return  startTree  ===  targetTree  &&  startPath . length  ===  targetPath . length  &&  startPath . slice ( 0 ,  startPath . length  -  1 ) . toString ( )  ===  targetPath . slice ( 0 ,  targetPath . length  -  1 ) . toString ( )  &&  arrayLast ( startPath )  <  arrayLast ( targetPath ) ; 
1407-  } ; 
1408- 14091401 isPathChanged  =  function  _isPathChanged ( )  { 
14101402 var  startTree  =  store . startTree , 
14111403 targetTree  =  store . targetTree , 
14121404 startPath  =  store . startPath , 
1413-  targetPath  =  store . targetPath , 
1414-  isDownwardsSameLevelMove  =  store . isDownwardsSameLevelMove ; 
1405+  targetPath  =  store . targetPath ; 
14151406
1416-  if  ( isDownwardsSameLevelMove )  { 
1417-  return  arrayLast ( startPath )  <  arrayLast ( targetPath )  -  1 ;  // if equal, not moved 
1407+  if  ( startTree  ===  targetTree  &&  startPath . length  ===  targetPath . length )  { 
1408+  if  ( startPath . toString ( )  ===  targetPath . toString ( ) )  { 
1409+  return  false ; 
1410+  }  else  { 
1411+  // downward same-level move, the end of targetPath is 1 more than real value  
1412+  // 同级向下移动时, targetPath的末位比真实值大1 
1413+  var  t  =  startPath . slice ( 0 ) ; 
1414+  t [ t . length  -  1 ] ++ ; 
1415+ 1416+  if  ( t . toString ( )  ===  targetPath . toString ( ) )  { 
1417+  return  false ; 
1418+  } 
1419+  } 
14181420 } 
14191421
1420-  return  startTree !== targetTree || startPath . toString ( ) !== targetPath . toString ( ) ; 
1422+  return  true ; 
14211423 } ; 
14221424
14231425 endEvent  =  store . endEvent ; 
@@ -1442,7 +1444,6 @@ function makeTreeDraggable(treeEl) {
14421444
14431445
14441446 store . targetPath  =  options . getPathByBranchEl ( placeholder ) ; 
1445-  store . isDownwardsSameLevelMove  =  isDownwardsSameLevelMove ( ) ; 
14461447 pathChanged  =  isPathChanged ( ) ; 
14471448 store . targetPathNotEqualToStartPath  =  pathChanged ; 
14481449 store . pathChangePrevented  =  false ; 
@@ -1464,19 +1465,19 @@ function makeTreeDraggable(treeEl) {
14641465
14651466 store . updateMovedElementStyle ( ) ;  //  
14661467
1467-  _context14 . next  =  11 ; 
1468+  _context14 . next  =  10 ; 
14681469 return  options . afterDrop ( store ,  dhOptions ) ; 
14691470
1470-  case  11 :
1471+  case  10 :
14711472 if  ( ! maskTree )  { 
1472-  _context14 . next  =  17 ; 
1473+  _context14 . next  =  16 ; 
14731474 break ; 
14741475 } 
14751476
1476-  _context14 . next  =  14 ; 
1477+  _context14 . next  =  13 ; 
14771478 return  waitTime ( 0 ) ; 
14781479
1479-  case  14 :
1480+  case  13 :
14801481 removeEl ( maskTree ) ; 
14811482 targetTreeEl . style . display  =  'block' ; 
14821483
@@ -1485,7 +1486,7 @@ function makeTreeDraggable(treeEl) {
14851486 startTreeEl . style . display  =  'block' ; 
14861487 } 
14871488
1488-  case  17 :
1489+  case  16 :
14891490 case  "end" :
14901491 return  _context14 . stop ( ) ; 
14911492 } 
@@ -1968,12 +1969,33 @@ var script = {
19681969 var  startParent  =  startTree . getNodeByPath ( startParentPath ) ; 
19691970 var  startSiblings  =  startParentPath . length  ===  0  ? startTree . treeData  : startParent . children ; 
19701971 var  startIndex  =  arrayLast ( startPath ) ; 
1971-  startSiblings . splice ( startIndex ,  1 ) ;  // update targetPath if isDownwardsSameLevelMove 
1972- 1973-  if  ( store . isDownwardsSameLevelMove )  { 
1974-  targetPath  =  targetPath . slice ( 0 ) ; 
1975-  var  endIndex  =  startPath . length  -  1 ; 
1976-  targetPath [ endIndex ]  -=  1 ; 
1972+  startSiblings . splice ( startIndex ,  1 ) ;  // remove node from the starting position may affect the target path. 
1973+  // example 
1974+  // startPath targetPath 
1975+  // [0] [1] 
1976+  // [0] [1, 0] 
1977+  // [3, 1] [3, 3] 
1978+  // [3, 1] [3, 3, 5] 
1979+  // above targetPaths should be transformed to [0], [0, 0] [3, 2] [3, 2, 5] 
1980+ 1981+  if  ( startTree  ===  targetTree )  { 
1982+  if  ( startPath . length  <=  targetPath . length )  { 
1983+  var  sw  =  startPath . slice ( 0 ,  startPath . length  -  1 ) ;  // without end 
1984+ 1985+  var  tw  =  targetPath . slice ( 0 ,  sw . length ) ;  // same length with sw 
1986+ 1987+  if  ( sw . toString ( )  ===  tw . toString ( ) )  { 
1988+  var  endIndex  =  sw . length ; 
1989+ 1990+  if  ( startPath [ endIndex ]  <  targetPath [ endIndex ] )  { 
1991+  targetPath  =  targetPath . slice ( 0 ) ;  // create a copy of targetPath 
1992+ 1993+  targetPath [ endIndex ]  -=  1 ; 
1994+  }  else  if  ( startPath [ endIndex ]  ===  targetPath [ endIndex ] )  { 
1995+  console . error ( 'Draggable.afterDrop: That is impossible!' ) ; 
1996+  } 
1997+  } 
1998+  } 
19771999 } 
19782000 }  // insert to target position 
19792001
0 commit comments