2018-03-26 01:41:29 +08:00
|
|
|
import treeService from './tree.js';
|
2018-04-02 08:33:10 +08:00
|
|
|
import treeChangesService from './branches.js';
|
2019-02-26 05:28:15 +08:00
|
|
|
import importDialog from '../dialogs/import.js';
|
2018-03-25 23:09:17 +08:00
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
const dragAndDropSetup = {
|
|
|
|
autoExpandMS: 600,
|
2017-10-10 06:53:11 +08:00
|
|
|
dragStart: (node, data) => {
|
2018-12-10 04:18:53 +08:00
|
|
|
// don't allow dragging root node
|
2018-10-22 04:42:20 +08:00
|
|
|
if (node.data.noteId === 'root') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-09 01:55:24 +08:00
|
|
|
if (!data.originalEvent.shiftKey) {
|
2019-01-24 04:13:04 +08:00
|
|
|
// keep existing selection only if CTRL key is pressed
|
|
|
|
for (const selectedNode of treeService.getSelectedNodes()) {
|
|
|
|
selectedNode.setSelected(false);
|
|
|
|
selectedNode.renderTitle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 22:10:49 +08:00
|
|
|
node.setSelected(true);
|
|
|
|
|
2018-11-12 20:05:09 +08:00
|
|
|
// this is for dragging notes into relation map
|
2018-11-19 18:19:56 +08:00
|
|
|
// we allow to drag only one note at a time because it multi-drag conflicts with multiple single drags
|
|
|
|
// in UX and single drag is probably more useful
|
|
|
|
data.dataTransfer.setData("text", JSON.stringify({
|
|
|
|
noteId: node.data.noteId,
|
|
|
|
title: node.title
|
|
|
|
}));
|
2018-11-12 20:05:09 +08:00
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
// This function MUST be defined to enable dragging for the tree.
|
|
|
|
// Return false to cancel dragging of node.
|
|
|
|
return true;
|
|
|
|
},
|
2018-12-10 04:18:53 +08:00
|
|
|
dragEnter: (node, data) => true, // allow drop on any node
|
2019-02-24 03:33:27 +08:00
|
|
|
dragOver: (node, data) => true,
|
2017-10-10 06:53:11 +08:00
|
|
|
dragDrop: (node, data) => {
|
2019-02-24 03:33:27 +08:00
|
|
|
const dataTransfer = data.dataTransfer;
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2019-02-24 03:33:27 +08:00
|
|
|
if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
|
2019-02-26 05:28:15 +08:00
|
|
|
importDialog.uploadFiles(node.data.noteId, dataTransfer.files, {
|
|
|
|
safeImport: true,
|
|
|
|
shrinkImages: true,
|
|
|
|
textImportedAsText: true,
|
2019-02-26 05:38:48 +08:00
|
|
|
codeImportedAsCode: true,
|
|
|
|
explodeArchives: true
|
2019-02-26 05:28:15 +08:00
|
|
|
});
|
2017-09-10 00:06:15 +08:00
|
|
|
}
|
|
|
|
else {
|
2019-02-24 03:33:27 +08:00
|
|
|
// This function MUST be defined to enable dropping of items on the tree.
|
|
|
|
// data.hitMode is 'before', 'after', or 'over'.
|
|
|
|
|
|
|
|
const selectedNodes = treeService.getSelectedNodes();
|
|
|
|
|
|
|
|
if (data.hitMode === "before") {
|
|
|
|
treeChangesService.moveBeforeNode(selectedNodes, node);
|
|
|
|
} else if (data.hitMode === "after") {
|
|
|
|
treeChangesService.moveAfterNode(selectedNodes, node);
|
|
|
|
} else if (data.hitMode === "over") {
|
|
|
|
treeChangesService.moveToNode(selectedNodes, node);
|
|
|
|
} else {
|
|
|
|
throw new Error("Unknown hitMode=" + data.hitMode);
|
|
|
|
}
|
2017-09-10 00:06:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
export default dragAndDropSetup;
|