@@ -589,21 +589,7 @@ export default {
589
589
}
590
590
591
591
// insert dragging nodes to the new place
592
- const destNode = this . cursorPosition . node ;
593
- const destSiblings = this . getNodeSiblings ( newNodes , destNode . path ) ;
594
- const destNodeModel = destSiblings [ destNode . ind ] ;
595
-
596
- if ( this . cursorPosition . placement === 'inside' ) {
597
- destNodeModel . children = destNodeModel . children || [ ] ;
598
- destNodeModel . children . unshift ( ...nodeModelsToInsert ) ;
599
- } else {
600
- const insertInd = this . cursorPosition . placement === 'before' ?
601
- destNode . ind :
602
- destNode . ind + 1 ;
603
-
604
- destSiblings . splice ( insertInd , 0 , ...nodeModelsToInsert ) ;
605
- }
606
-
592
+ this . insertModels ( this . cursorPosition , nodeModelsToInsert , newNodes ) ;
607
593
608
594
609
595
// delete dragging node from the old place
@@ -740,6 +726,32 @@ export default {
740
726
this . emitInput ( newNodes ) ;
741
727
} ,
742
728
729
+ insertModels ( cursorPosition , nodeModels , newNodes ) {
730
+ const destNode = cursorPosition . node ;
731
+ const destSiblings = this . getNodeSiblings ( newNodes , destNode . path ) ;
732
+ const destNodeModel = destSiblings [ destNode . ind ] ;
733
+
734
+ if ( cursorPosition . placement === 'inside' ) {
735
+ destNodeModel . children = destNodeModel . children || [ ] ;
736
+ destNodeModel . children . unshift ( ...nodeModels ) ;
737
+ } else {
738
+ const insertInd = cursorPosition . placement === 'before' ?
739
+ destNode . ind :
740
+ destNode . ind + 1 ;
741
+
742
+ destSiblings . splice ( insertInd , 0 , ...nodeModels ) ;
743
+ }
744
+ } ,
745
+
746
+ insert ( cursorPosition , nodeModel ) {
747
+ const nodeModels = Array . isArray ( nodeModel ) ? nodeModel : [ nodeModel ] ;
748
+ const newNodes = this . copy ( this . currentValue ) ;
749
+
750
+ this . insertModels ( cursorPosition , nodeModels , newNodes ) ;
751
+
752
+ this . emitInput ( newNodes ) ;
753
+ } ,
754
+
743
755
checkNodeIsParent ( sourceNode , destNode ) {
744
756
const destPath = destNode . path ;
745
757
return JSON . stringify ( destPath . slice ( 0 , sourceNode . path . length ) ) == sourceNode . pathStr ;
0 commit comments