@@ -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