1
1
/*!
2
- * he-tree-vue v3.0.1
2
+ * he-tree-vue v3.0.2
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 { createVNode } from 'vue' ;
8
8
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray' ;
9
9
import _defineProperty from '@babel/runtime/helpers/defineProperty' ;
10
- 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' ;
10
+ 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' ;
11
11
import { updatablePropsEvenUnbound , hookHelper } from 'vue-functions' ;
12
12
import _regeneratorRuntime from '@babel/runtime/regenerator' ;
13
13
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator' ;
@@ -1364,16 +1364,30 @@ function makeTreeDraggable(treeEl) {
1364
1364
} ,
1365
1365
beforeDrop : function ( ) {
1366
1366
var _beforeDrop = _asyncToGenerator ( /*#__PURE__*/ _regeneratorRuntime . mark ( function _callee14 ( store , dhOptions ) {
1367
- var endEvent , movingEl , placeholder , tempChildren , movedCount , targetTreeEl , startTreeEl , maskTree , maskTree2 , pathChanged , isPathChanged ;
1367
+ var endEvent , movingEl , placeholder , tempChildren , movedCount , targetTreeEl , startTreeEl , maskTree , maskTree2 , pathChanged , isPathChanged , isDownwardsSameLevelMove ;
1368
1368
return _regeneratorRuntime . wrap ( function _callee14$ ( _context14 ) {
1369
1369
while ( 1 ) {
1370
1370
switch ( _context14 . prev = _context14 . next ) {
1371
1371
case 0 :
1372
- isPathChanged = function _isPathChanged ( ) {
1372
+ isDownwardsSameLevelMove = function _isDownwardsSameLevel ( ) {
1373
1373
var startTree = store . startTree ,
1374
1374
targetTree = store . targetTree ,
1375
1375
startPath = store . startPath ,
1376
1376
targetPath = store . targetPath ;
1377
+ 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 ) ;
1378
+ } ;
1379
+
1380
+ isPathChanged = function _isPathChanged ( ) {
1381
+ var startTree = store . startTree ,
1382
+ targetTree = store . targetTree ,
1383
+ startPath = store . startPath ,
1384
+ targetPath = store . targetPath ,
1385
+ isDownwardsSameLevelMove = store . isDownwardsSameLevelMove ;
1386
+
1387
+ if ( isDownwardsSameLevelMove ) {
1388
+ return arrayLast ( startPath ) < arrayLast ( targetPath ) - 1 ; // if equal, not moved
1389
+ }
1390
+
1377
1391
return startTree !== targetTree || startPath . toString ( ) !== targetPath . toString ( ) ;
1378
1392
} ;
1379
1393
@@ -1399,6 +1413,7 @@ function makeTreeDraggable(treeEl) {
1399
1413
1400
1414
1401
1415
store . targetPath = options . getPathByBranchEl ( placeholder ) ;
1416
+ store . isDownwardsSameLevelMove = isDownwardsSameLevelMove ( ) ;
1402
1417
pathChanged = isPathChanged ( ) ;
1403
1418
store . targetPathNotEqualToStartPath = pathChanged ;
1404
1419
store . pathChangePrevented = false ;
@@ -1420,19 +1435,19 @@ function makeTreeDraggable(treeEl) {
1420
1435
1421
1436
store . updateMovedElementStyle ( ) ; //
1422
1437
1423
- _context14 . next = 10 ;
1438
+ _context14 . next = 11 ;
1424
1439
return options . afterDrop ( store , dhOptions ) ;
1425
1440
1426
- case 10 :
1441
+ case 11 :
1427
1442
if ( ! maskTree ) {
1428
- _context14 . next = 16 ;
1443
+ _context14 . next = 17 ;
1429
1444
break ;
1430
1445
}
1431
1446
1432
- _context14 . next = 13 ;
1447
+ _context14 . next = 14 ;
1433
1448
return waitTime ( 30 ) ;
1434
1449
1435
- case 13 :
1450
+ case 14 :
1436
1451
removeEl ( maskTree ) ;
1437
1452
targetTreeEl . style . display = 'block' ;
1438
1453
@@ -1441,7 +1456,7 @@ function makeTreeDraggable(treeEl) {
1441
1456
startTreeEl . style . display = 'block' ;
1442
1457
}
1443
1458
1444
- case 16 :
1459
+ case 17 :
1445
1460
case "end" :
1446
1461
return _context14 . stop ( ) ;
1447
1462
}
@@ -1721,10 +1736,6 @@ var Draggable_vue = {
1721
1736
index2 = _step3$value . index ;
1722
1737
1723
1738
if ( hasClass ( el , 'tree-branch' ) || hasClass ( el , 'tree-placeholder' ) ) {
1724
- if ( el === store . dragBranchEl ) {
1725
- continue ;
1726
- }
1727
-
1728
1739
if ( el === branchEl ) {
1729
1740
break ;
1730
1741
}
@@ -1920,40 +1931,21 @@ var Draggable_vue = {
1920
1931
var startTree = store . startTree ,
1921
1932
targetTree = store . targetTree ,
1922
1933
startPath = store . startPath ,
1923
- targetPath = store . targetPath ,
1924
1934
dragNode = store . dragNode ;
1935
+ var targetPath = store . targetPath ;
1925
1936
1926
1937
if ( _this . cloneWhenDrag !== true ) {
1927
1938
// remove from start position
1928
1939
var startParentPath = arrayWithoutEnd ( startPath , 1 ) ;
1929
1940
var startParent = startTree . getNodeByPath ( startParentPath ) ;
1930
1941
var startSiblings = startParentPath . length === 0 ? startTree . treeData : startParent . children ;
1931
1942
var startIndex = arrayLast ( startPath ) ;
1932
- startSiblings . splice ( startIndex , 1 ) ; // update targetPath
1933
-
1934
- if ( startTree === targetTree ) {
1935
- if ( startPath . length <= targetPath . length ) {
1936
- var lenNoEnd = startPath . length - 1 ;
1937
- var same = true ;
1938
-
1939
- for ( var i = 0 ; i < lenNoEnd ; i ++ ) {
1940
- var s = startPath [ i ] ;
1941
- var _t = targetPath [ i ] ;
1943
+ startSiblings . splice ( startIndex , 1 ) ; // update targetPath if isDownwardsSameLevelMove
1942
1944
1943
- if ( s !== _t ) {
1944
- same = false ;
1945
- break ;
1946
- }
1947
- }
1948
-
1949
- if ( same ) {
1950
- var endIndex = startPath . length - 1 ;
1951
-
1952
- if ( startPath [ endIndex ] < targetPath [ endIndex ] ) {
1953
- targetPath [ endIndex ] -= 1 ;
1954
- }
1955
- }
1956
- }
1945
+ if ( store . isDownwardsSameLevelMove ) {
1946
+ targetPath = targetPath . slice ( 0 ) ;
1947
+ var endIndex = startPath . length - 1 ;
1948
+ targetPath [ endIndex ] -= 1 ;
1957
1949
}
1958
1950
} // insert to target position
1959
1951
0 commit comments