@@ -203,6 +203,10 @@ export default {
203
203
this . getRoot ( ) . $emit ( 'select' , selectedNodes , event ) ;
204
204
} ,
205
205
206
+ emitBeforeDrop ( draggingNodes , position , cancel ) {
207
+ this . getRoot ( ) . $emit ( 'beforedrop' , draggingNodes , position , cancel ) ;
208
+ } ,
209
+
206
210
emitDrop ( draggingNodes , position , event ) {
207
211
this . getRoot ( ) . $emit ( 'drop' , draggingNodes , position , event ) ;
208
212
} ,
@@ -550,20 +554,35 @@ export default {
550
554
if ( this . checkNodeIsParent ( draggingNode , this . cursorPosition . node ) ) {
551
555
this . stopDrag ( ) ;
552
556
return ;
553
- } ;
557
+ }
554
558
}
555
559
556
560
const newNodes = this . copy ( this . currentValue ) ;
557
- const nodeModelsToInsert = [ ] ;
561
+ const nodeModelsSubjectToInsert = [ ] ;
558
562
559
- // find and mark dragging model to delete
563
+ // find dragging model to delete
560
564
for ( let draggingNode of draggingNodes ) {
561
565
const sourceSiblings = this . getNodeSiblings ( newNodes , draggingNode . path ) ;
562
566
const draggingNodeModel = sourceSiblings [ draggingNode . ind ] ;
563
- nodeModelsToInsert . push ( this . copy ( draggingNodeModel ) ) ;
564
- draggingNodeModel [ '_markToDelete' ] = true ;
567
+ nodeModelsSubjectToInsert . push ( draggingNodeModel ) ;
568
+ }
569
+
570
+ // allow the drop to be cancelled
571
+ let cancelled = false ;
572
+ this . emitBeforeDrop ( draggingNodes , this . cursorPosition , ( ) => cancelled = true ) ;
573
+
574
+ if ( cancelled ) {
575
+ this . stopDrag ( ) ;
576
+ return ;
565
577
}
566
578
579
+ const nodeModelsToInsert = [ ] ;
580
+
581
+ // mark dragging model to delete
582
+ for ( let draggingNodeModel of nodeModelsSubjectToInsert ) {
583
+ nodeModelsToInsert . push ( this . copy ( draggingNodeModel ) ) ;
584
+ draggingNodeModel [ '_markToDelete' ] = true ;
585
+ }
567
586
568
587
// insert dragging nodes to the new place
569
588
const destNode = this . cursorPosition . node ;
0 commit comments