@@ -276,35 +276,38 @@ export default class ListItem extends Component {
276276 if ( treeId === this . props . dom . _tree . id ) {
277277 sourceTree = this . props . dom . _tree ;
278278 }
279- else {
279+ else if ( treeId ) {
280280 sourceTree = document . querySelector ( '[data-uid="' + treeId + '"]' ) . inspireTree ;
281281 }
282282
283- const node = sourceTree . node ( nodeId ) ;
284- node . state ( 'drop-target' , true ) ;
283+ // Only source/handle node if it's a node that was dropped
284+ let newNode , newIndex ;
285+ if ( sourceTree ) {
286+ const node = sourceTree . node ( nodeId ) ;
287+ node . state ( 'drop-target' , true ) ;
285288
286- const exported = node . remove ( true ) ;
289+ const exported = node . remove ( true ) ;
287290
288- // Get the index of the target node
289- let targetIndex = targetNode . context ( ) . indexOf ( targetNode ) ;
291+ // Get the index of the target node
292+ let targetIndex = targetNode . context ( ) . indexOf ( targetNode ) ;
290293
291- let newNode , newIndex ;
292- if ( dir === 0 ) {
293- // Add as a child
294- newNode = targetNode . addChild ( exported ) ;
294+ if ( dir === 0 ) {
295+ // Add as a child
296+ newNode = targetNode . addChild ( exported ) ;
295297
296- // Cache the new index
297- newIndex = targetNode . children . indexOf ( newNode ) ;
298+ // Cache the new index
299+ newIndex = targetNode . children . indexOf ( newNode ) ;
298300
299- // Auto-expand
300- targetNode . expand ( ) ;
301- }
302- else {
303- // Determine the new index
304- newIndex = dir === 1 ? ++ targetIndex : targetIndex ;
301+ // Auto-expand
302+ targetNode . expand ( ) ;
303+ }
304+ else {
305+ // Determine the new index
306+ newIndex = dir === 1 ? ++ targetIndex : targetIndex ;
305307
306- // Insert and cache the node
307- newNode = targetNode . context ( ) . insertAt ( newIndex , exported ) ;
308+ // Insert and cache the node
309+ newNode = targetNode . context ( ) . insertAt ( newIndex , exported ) ;
310+ }
308311 }
309312
310313 this . props . dom . _tree . emit ( 'node.drop' , event , newNode , targetNode , newIndex ) ;
0 commit comments