Skip to content

Commit 9b1aa2d

Browse files
committed
issue fixed: flick ondrop
1 parent bb07116 commit 9b1aa2d

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/plugins/draggable/Draggable.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default {
4343
}
4444
const dropChildren = dropParent === this.root ? this.root.nodes : dropParent.children
4545
dropChildren.splice(store.dropPath.index, 0, dragNode)
46+
return hp.waitTime(60)
4647
},
4748
})
4849
}

src/plugins/draggable/draggable.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ export default function makeTreeDraggable(treeEl, options = {}) {
288288
doImmediately()
289289
}
290290
}
291-
// todo remove?
292291
const unfoldAndGetChildrenEl = async (branch) => {
293292
if (options.unfoldNodeByID) {
294293
await options.unfoldNodeByID(branch.getAttribute('id'))
@@ -324,15 +323,39 @@ export default function makeTreeDraggable(treeEl, options = {}) {
324323
const movingEl = store.el // branch
325324
store.dropPath = resolveBranchPath(store.placeholder, el => el !== movingEl)
326325
//
327-
const pathChanged = comparePath(store.dragPath, store.dropPath)
326+
// todo if placeholder not mounted
327+
const pathChanged = !comparePath(store.dragPath, store.dropPath)
328+
let clonedTreeEl
328329
if (pathChanged) {
329-
// DOMUtils.insertBefore(movingEl, store.placeholder)
330+
// todo cross tree
331+
if (store.placeholder) {
332+
store.placeholder.setAttribute('draggable-temp', 'placeholder')
333+
}
334+
if (store.tempChildren) {
335+
store.tempChildren.setAttribute('draggable-temp', 'tempChildren')
336+
}
337+
clonedTreeEl = treeEl.cloneNode(true)
338+
hp.backupAttr(treeEl, 'style')
339+
const movingEl2 = clonedTreeEl.querySelector(`[id=${movingEl.getAttribute('id')}]`)
340+
const placeholder2 = clonedTreeEl.querySelector(`[draggable-temp=placeholder]`)
341+
const tempChildren2 = clonedTreeEl.querySelector(`[draggable-temp=tempChildren]`)
342+
DOMUtils.insertBefore(movingEl2, placeholder2)
343+
DOMUtils.removeEl(placeholder2)
344+
if (tempChildren2 && !tempChildren2.querySelector(`.${options.branchClass}`)) {
345+
DOMUtils.removeEl(tempChildren2)
346+
}
347+
treeEl.style.display = 'none'
348+
DOMUtils.insertAfter(clonedTreeEl, treeEl)
330349
}
331350
DOMUtils.removeEl(store.placeholder)
332351
try {
333352
DOMUtils.removeEl(store.tempChildren)
334353
} catch (e) {}
335354
await options.ondrop(pathChanged, store, opt)
355+
if (pathChanged) {
356+
hp.restoreAttr(treeEl, 'style')
357+
DOMUtils.removeEl(clonedTreeEl)
358+
}
336359
},
337360
})
338361
return destroy

0 commit comments

Comments
 (0)