Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 21a5bf7

Browse files
committed
fix(draggable plugin): correct the value of store.targetPath
1 parent f9efdee commit 21a5bf7

File tree

2 files changed

+27
-40
lines changed

2 files changed

+27
-40
lines changed

‎src/plugins/draggable/Draggable.vue‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -264,29 +264,6 @@ export default {
264264
const startSiblings = startParentPath.length === 0 ? startTree.treeData : startParent.children
265265
const startIndex = hp.arrayLast(startPath)
266266
startSiblings.splice(startIndex, 1)
267-
// remove node from the starting position may affect the target path.
268-
// example
269-
// startPath targetPath
270-
// [0] [1]
271-
// [0] [1, 0]
272-
// [3, 1] [3, 3]
273-
// [3, 1] [3, 3, 5]
274-
// above targetPaths should be transformed to [0], [0, 0] [3, 2] [3, 2, 5]
275-
if (startTree === targetTree) {
276-
if (startPath.length <= targetPath.length) {
277-
const sw = startPath.slice(0, startPath.length - 1) // without end
278-
const tw = targetPath.slice(0, sw.length) // same length with sw
279-
if (sw.toString() === tw.toString()) {
280-
const endIndex = sw.length
281-
if (startPath[endIndex] < targetPath[endIndex]) {
282-
targetPath = targetPath.slice(0) // create a copy of targetPath
283-
targetPath[endIndex] -= 1
284-
} else if (startPath[endIndex] === targetPath[endIndex]) {
285-
console.error('Draggable.afterDrop: That is impossible!');
286-
}
287-
}
288-
}
289-
}
290267
}
291268
// insert to target position
292269
const targetParentPath = hp.arrayWithoutEnd(targetPath, 1)

‎src/plugins/draggable/draggable.js‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,9 @@ export default function makeTreeDraggable(treeEl, options = {}) {
465465
hp.insertAfter(maskTree2, startTreeEl)
466466
}
467467
//
468-
store.targetPath = options.getPathByBranchEl(placeholder)
469-
letpathChanged=isPathChanged()
470-
store.targetPathNotEqualToStartPath=pathChanged
468+
store.placeholderPath = options.getPathByBranchEl(placeholder)
469+
store.targetPath=getTargetPath()
470+
letpathChanged=targetTreeEl===startTreeEl&&store.targetPath.toString()!==store.startPath.toString()
471471
store.pathChangePrevented = false
472472
if (options.beforeDrop && options.beforeDrop(pathChanged, store, dhOptions) === false) {
473473
pathChanged = false
@@ -493,23 +493,33 @@ export default function makeTreeDraggable(treeEl, options = {}) {
493493
startTreeEl.style.display = 'block'
494494
}
495495
}
496-
//
497-
function isPathChanged() {
498-
const {startTree, targetTree, startPath, targetPath} = store
499-
if (startTree === targetTree && startPath.length === targetPath.length) {
500-
if (startPath.toString() === targetPath.toString()) {
501-
return false
502-
} else {
503-
// downward same-level move, the end of targetPath is 1 more than real value
504-
// 同级向下移动时, targetPath的末位比真实值大1
505-
const t = startPath.slice(0)
506-
t[t.length - 1] ++
507-
if (t.toString() === targetPath.toString()) {
508-
return false
496+
function getTargetPath() {
497+
// example
498+
// startPath placeholderPath
499+
// [0] [1]
500+
// [0] [1, 0]
501+
// [3, 1] [3, 3]
502+
// [3, 1] [3, 3, 5]
503+
// above targetPaths should be [0], [0, 0] [3, 2] [3, 2, 5]
504+
const {startTree, targetTree, startPath, placeholderPath} = store
505+
const targetPath = placeholderPath.slice(0)
506+
if (options.cloneWhenDrag !== true) {
507+
if (startTree === targetTree) {
508+
if (startPath.length <= targetPath.length) {
509+
const sw = startPath.slice(0, startPath.length - 1) // without end
510+
const tw = targetPath.slice(0, sw.length) // same length with sw
511+
if (sw.toString() === tw.toString()) {
512+
const endIndex = sw.length
513+
if (startPath[endIndex] < targetPath[endIndex]) {
514+
targetPath[endIndex] -= 1
515+
} else if (startPath[endIndex] === targetPath[endIndex]) {
516+
// position not changed
517+
}
518+
}
509519
}
510520
}
511521
}
512-
return true
522+
return targetPath
513523
}
514524
},
515525
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /