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';
|
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;
|
|
|
|
}
|
|
|
|
|
2018-11-12 22:10:49 +08:00
|
|
|
node.setSelected(true);
|
|
|
|
|
2019-06-11 03:47:08 +08:00
|
|
|
const notes = treeService.getSelectedNodes().map(node => { return {
|
2018-11-19 18:19:56 +08:00
|
|
|
noteId: node.data.noteId,
|
|
|
|
title: node.title
|
2019-06-11 03:47:08 +08:00
|
|
|
}});
|
|
|
|
|
|
|
|
data.dataTransfer.setData("text", JSON.stringify(notes));
|
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,
|
2019-08-21 03:40:47 +08:00
|
|
|
dragDrop: async (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-09-03 03:58:03 +08:00
|
|
|
const files = [...dataTransfer.files]; // chrome has issue that dataTransfer.files empties after async operation
|
|
|
|
|
2019-08-21 03:40:47 +08:00
|
|
|
const importDialog = await import('../dialogs/import.js');
|
|
|
|
|
2019-09-03 03:58:03 +08:00
|
|
|
importDialog.uploadFiles(node.data.noteId, files, {
|
2019-02-26 05:28:15 +08:00
|
|
|
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;
|