1
1
/*!
2
- * he-tree-vue v2.0.8
2
+ * he-tree-vue v2.0.9
3
3
* (c) phphe <phphe@outlook.com> (https://github.com/phphe)
4
4
* Homepage: https://he-tree-vue.phphe.com
5
5
* Released under the MIT License.
6
6
*/
7
7
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray' ;
8
8
import _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 , iterateAll , resolveValueOrGettter , arrayWithoutEnd , arrayLast } from 'helper-js' ;
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' ;
10
10
import { updatablePropsEvenUnbound , hookHelper } from 'vue-functions' ;
11
11
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.mjs' ;
12
12
import Vue from 'vue' ;
@@ -1393,16 +1393,30 @@ function makeTreeDraggable(treeEl) {
1393
1393
} ,
1394
1394
beforeDrop : function ( ) {
1395
1395
var _beforeDrop = _asyncToGenerator ( /*#__PURE__*/ _regeneratorRuntime . mark ( function _callee14 ( store , dhOptions ) {
1396
- var endEvent , movingEl , placeholder , tempChildren , movedCount , targetTreeEl , startTreeEl , maskTree , maskTree2 , pathChanged , isPathChanged ;
1396
+ var endEvent , movingEl , placeholder , tempChildren , movedCount , targetTreeEl , startTreeEl , maskTree , maskTree2 , pathChanged , isPathChanged , isDownwardsSameLevelMove ;
1397
1397
return _regeneratorRuntime . wrap ( function _callee14$ ( _context14 ) {
1398
1398
while ( 1 ) {
1399
1399
switch ( _context14 . prev = _context14 . next ) {
1400
1400
case 0 :
1401
- isPathChanged = function _isPathChanged ( ) {
1401
+ isDownwardsSameLevelMove = function _isDownwardsSameLevel ( ) {
1402
1402
var startTree = store . startTree ,
1403
1403
targetTree = store . targetTree ,
1404
1404
startPath = store . startPath ,
1405
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
+
1409
+ isPathChanged = function _isPathChanged ( ) {
1410
+ var startTree = store . startTree ,
1411
+ targetTree = store . targetTree ,
1412
+ startPath = store . startPath ,
1413
+ targetPath = store . targetPath ,
1414
+ isDownwardsSameLevelMove = store . isDownwardsSameLevelMove ;
1415
+
1416
+ if ( isDownwardsSameLevelMove ) {
1417
+ return arrayLast ( startPath ) < arrayLast ( targetPath ) - 1 ; // if equal, not moved
1418
+ }
1419
+
1406
1420
return startTree !== targetTree || startPath . toString ( ) !== targetPath . toString ( ) ;
1407
1421
} ;
1408
1422
@@ -1428,6 +1442,7 @@ function makeTreeDraggable(treeEl) {
1428
1442
1429
1443
1430
1444
store . targetPath = options . getPathByBranchEl ( placeholder ) ;
1445
+ store . isDownwardsSameLevelMove = isDownwardsSameLevelMove ( ) ;
1431
1446
pathChanged = isPathChanged ( ) ;
1432
1447
store . targetPathNotEqualToStartPath = pathChanged ;
1433
1448
store . pathChangePrevented = false ;
@@ -1449,19 +1464,19 @@ function makeTreeDraggable(treeEl) {
1449
1464
1450
1465
store . updateMovedElementStyle ( ) ; //
1451
1466
1452
- _context14 . next = 10 ;
1467
+ _context14 . next = 11 ;
1453
1468
return options . afterDrop ( store , dhOptions ) ;
1454
1469
1455
- case 10 :
1470
+ case 11 :
1456
1471
if ( ! maskTree ) {
1457
- _context14 . next = 16 ;
1472
+ _context14 . next = 17 ;
1458
1473
break ;
1459
1474
}
1460
1475
1461
- _context14 . next = 13 ;
1476
+ _context14 . next = 14 ;
1462
1477
return waitTime ( 0 ) ;
1463
1478
1464
- case 13 :
1479
+ case 14 :
1465
1480
removeEl ( maskTree ) ;
1466
1481
targetTreeEl . style . display = 'block' ;
1467
1482
@@ -1470,7 +1485,7 @@ function makeTreeDraggable(treeEl) {
1470
1485
startTreeEl . style . display = 'block' ;
1471
1486
}
1472
1487
1473
- case 16 :
1488
+ case 17 :
1474
1489
case "end" :
1475
1490
return _context14 . stop ( ) ;
1476
1491
}
@@ -1749,10 +1764,6 @@ var script = {
1749
1764
index2 = _step3$value . index ;
1750
1765
1751
1766
if ( hasClass ( el , 'tree-branch' ) || hasClass ( el , 'tree-placeholder' ) ) {
1752
- if ( el === store . dragBranchEl ) {
1753
- continue ;
1754
- }
1755
-
1756
1767
if ( el === branchEl ) {
1757
1768
break ;
1758
1769
}
@@ -1948,40 +1959,21 @@ var script = {
1948
1959
var startTree = store . startTree ,
1949
1960
targetTree = store . targetTree ,
1950
1961
startPath = store . startPath ,
1951
- targetPath = store . targetPath ,
1952
1962
dragNode = store . dragNode ;
1963
+ var targetPath = store . targetPath ;
1953
1964
1954
1965
if ( _this . cloneWhenDrag !== true ) {
1955
1966
// remove from start position
1956
1967
var startParentPath = arrayWithoutEnd ( startPath , 1 ) ;
1957
1968
var startParent = startTree . getNodeByPath ( startParentPath ) ;
1958
1969
var startSiblings = startParentPath . length === 0 ? startTree . treeData : startParent . children ;
1959
1970
var startIndex = arrayLast ( startPath ) ;
1960
- startSiblings . splice ( startIndex , 1 ) ; // update targetPath
1961
-
1962
- if ( startTree === targetTree ) {
1963
- if ( startPath . length <= targetPath . length ) {
1964
- var lenNoEnd = startPath . length - 1 ;
1965
- var same = true ;
1966
-
1967
- for ( var i = 0 ; i < lenNoEnd ; i ++ ) {
1968
- var s = startPath [ i ] ;
1969
- var _t = targetPath [ i ] ;
1971
+ startSiblings . splice ( startIndex , 1 ) ; // update targetPath if isDownwardsSameLevelMove
1970
1972
1971
- if ( s !== _t ) {
1972
- same = false ;
1973
- break ;
1974
- }
1975
- }
1976
-
1977
- if ( same ) {
1978
- var endIndex = startPath . length - 1 ;
1979
-
1980
- if ( startPath [ endIndex ] < targetPath [ endIndex ] ) {
1981
- targetPath [ endIndex ] -= 1 ;
1982
- }
1983
- }
1984
- }
1973
+ if ( store . isDownwardsSameLevelMove ) {
1974
+ targetPath = targetPath . slice ( 0 ) ;
1975
+ var endIndex = startPath . length - 1 ;
1976
+ targetPath [ endIndex ] -= 1 ;
1985
1977
}
1986
1978
} // insert to target position
1987
1979
0 commit comments