Skip to content

Commit 4f2eef4

Browse files
committed
Supports drops of non-nodes. Fixes #16
1 parent e32315a commit 4f2eef4

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/dom/list-item.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)