This commit is contained in:
Vanessa 2022-11-04 20:57:53 +08:00
parent df2d99f152
commit c056d30510
3 changed files with 45 additions and 36 deletions

View file

@ -135,8 +135,7 @@ export class Wnd {
it.style.opacity = ".1";
return;
}
if (!event.dataTransfer.types.includes(Constants.SIYUAN_DROP_TAB) ||
(!window.siyuan.dragElement && event.dataTransfer.types.includes(Constants.SIYUAN_DROP_TAB))) {
if (!event.dataTransfer.types.includes(Constants.SIYUAN_DROP_TAB) || !window.siyuan.dragElement) {
return;
}
event.preventDefault();

View file

@ -290,17 +290,20 @@ export class Files extends Model {
liElement.classList.add("b3-list-item--focus");
selectElements = [liElement];
}
const ids: string[] = []
let ids = ""
selectElements.forEach((item: HTMLElement) => {
item.style.opacity = "0.1";
ids.push(item.getAttribute("data-node-id"))
ids += (item.getAttribute("data-node-id") || "") + ","
})
const img = new Image();
// TODO: drag preview
img.src = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACYAAAAmCAYAAACoPemuAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABklJREFUeNqsmFtwE1UYx/97Tdqkbei91Gk6IFouYjqjBR3aQTstoM40DD4gOIO++sL4pr45+q7iu+OMyJMD1RcZAXGEBxiUm0JrKfQiDoVeSEmv2WSP3znJJpt0d1Mgpz3d3bPJnt/+v8v5TqX9X89HGMNZ6iGGdGOZP9a11Riz3bddm4n4tz991Pg+SthkDmVmoPhE2Q5bLxwruIakRVHiJnMo+9s/SZMULfTW56PRUiuWB8UKjmCrIqNfva+kYPb5vRiYi5/lnuQrsWIOkzyWWixnzjc/K505VUcgN9Ai5qwo1w7duHknFgzoUDU5Ky+z+YrbuW3sajgcjqmsCAnzSBeFLcn06NJSPBoI+CBJMmQZjw1mmmZsbGzsQ3kFUBEopxewbi3DhyujBhYXl8TnJUl67C7Lcoj6F6rb61vD5TrQ3mKiNsiy45fHZIxPSw7fUnBrphwvPJqDrikIBMposidIP5IUUr38qWdTCn2RlICztyiNDU7IO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Tk75gguMLlyNPHmEsht+IhHnuF3B5VQVO4gyIyKCqMA71daCA/W6Ra7buff3NUTmZm0rOitHfXWFjFXkGUQklGizqDT1NxcFdnVrlTF6877CtTy7FCACcQV9N6po/cOa9sByZUGFTZ8mfrVDi+u7sLW9eH8Xb3K3lq8aOyvuuD+7Rp2kkLqh+MQrVIZ/xoOo8z69q0nVudkFVa2jc2GNCoDFKogNTIrG3hZqiZxCrZdi7ibNenIyFRKK1iZ+vse5S9R4YPI4Wom015mb23pwqvbinLLuq0TcsmVAsqeyzVln5n37GorAZPiFKm0LykYF9vFba1V9GuSYVPV0kxWWzt8lTKZP6SgvH2+r7+h5Ksh/KVMhHtrSSoSrHX1AmKl9tuUNaYXNL/trFUP6+5cmteGqojUkmmU0TnvrWanVJJwZhp/JgOBEoLJm2WeyoIqoKUkkXnUGlBmCcUrzZKCna2f3+/aRoxrlRfTxAvbw0Ks/EuZ0prt1RkV5E2yTEVJW6pVKK/r7fivfbNZeQ4JhnWFFGbTKbyo67Ap6zo5FDUX/tfgAEAQ3WUFGFdgUwAAAAASUVORK5CYII=`;
event.dataTransfer.setDragImage(img, 10, 10);
event.dataTransfer.setData(Constants.SIYUAN_DROP_FILE, ids.join(","));
event.dataTransfer.setData(Constants.SIYUAN_DROP_FILE, ids);
event.dataTransfer.dropEffect = "move";
const tempEelement = document.createElement("div")
tempEelement.innerText = ids;
window.siyuan.dragElement = tempEelement;
}
});
this.element.addEventListener("dragend", (event: DragEvent & { target: HTMLElement }) => {
@ -314,7 +317,7 @@ export class Files extends Model {
return;
}
const liElement = hasClosestByTag(event.target, "LI");
if (!liElement || liElement.classList.contains("b3-list-item--focus")) {
if (!liElement || !window.siyuan.dragElement || liElement.classList.contains("b3-list-item--focus")) {
event.preventDefault();
return;
}
@ -395,8 +398,10 @@ export class Files extends Model {
});
}
newElement.classList.remove("dragover", "dragover__bottom", "dragover__top");
window.siyuan.dragElement = undefined;
return;
}
window.siyuan.dragElement = undefined;
if (!event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE)) {
newElement.classList.remove("dragover", "dragover__bottom", "dragover__top");
return;

View file

@ -583,7 +583,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
}
const targetElement = editorElement.querySelector(".dragover__bottom") || editorElement.querySelector(".dragover__top") || editorElement.querySelector(".dragover__left") || editorElement.querySelector(".dragover__right");
if (window.siyuan.dragElement && (
window.siyuan.dragElement.parentElement.classList.contains("protyle-gutters") ||
window.siyuan.dragElement.parentElement?.classList.contains("protyle-gutters") ||
window.siyuan.dragElement.getAttribute("data-type") === "NodeListItem")) {
// gutter 或反链面板拖拽
const sourceElements: Element[] = [];
@ -640,34 +640,38 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
}
}
}
} else if (window.siyuan.dragElement && window.siyuan.dragElement.getAttribute("data-type") === "navigation-file"
} else if (event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE)?.split("-").length > 1
&& targetElement && !protyle.options.backlinkData) {
// 文件树拖拽
fetchPost("/api/filetree/doc2Heading", {
srcID: window.siyuan.dragElement.getAttribute("data-node-id"),
after: targetElement.classList.contains("dragover__bottom"),
targetID: targetElement.getAttribute("data-node-id"),
}, response => {
const scrollTop = protyle.contentElement.scrollTop;
fetchPost("/api/filetree/removeDoc", {
notebook: response.data.srcTreeBox,
path: response.data.srcTreePath,
});
fetchPost("/api/filetree/getDoc", {
id: protyle.block.id,
size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => {
onGet(getResponse, protyle);
/// #if !MOBILE
// 文档标题互转后,需更新大纲
updatePanelByEditor(protyle, false, false, true);
/// #endif
// 文档标题互转后,编辑区会跳转到开头 https://github.com/siyuan-note/siyuan/issues/2939
setTimeout(() => {
protyle.contentElement.scrollTop = scrollTop;
protyle.scroll.lastScrollTop = scrollTop - 1;
}, Constants.TIMEOUT_BLOCKLOAD);
});
const scrollTop = protyle.contentElement.scrollTop;
const ids = event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE).split(",")
for (let i = 0; i < ids.length; i++) {
if (ids[i]) {
const response = await fetchSyncPost("/api/filetree/doc2Heading", {
srcID: ids[i],
after: targetElement.classList.contains("dragover__bottom"),
targetID: targetElement.getAttribute("data-node-id"),
});
fetchPost("/api/filetree/removeDoc", {
notebook: response.data.srcTreeBox,
path: response.data.srcTreePath,
});
}
}
fetchPost("/api/filetree/getDoc", {
id: protyle.block.id,
size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => {
onGet(getResponse, protyle);
/// #if !MOBILE
// 文档标题互转后,需更新大纲
updatePanelByEditor(protyle, false, false, true);
/// #endif
// 文档标题互转后,编辑区会跳转到开头 https://github.com/siyuan-note/siyuan/issues/2939
setTimeout(() => {
protyle.contentElement.scrollTop = scrollTop;
protyle.scroll.lastScrollTop = scrollTop - 1;
}, Constants.TIMEOUT_BLOCKLOAD);
});
targetElement.classList.remove("dragover__bottom", "dragover__top");
} else if (!window.siyuan.dragElement && (event.dataTransfer.types[0] === "Files" || event.dataTransfer.types.includes("text/html"))) {
@ -715,12 +719,13 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
if (!targetElement) {
return;
}
const fileTreeIds = window.siyuan.dragElement.innerText;
if (targetElement && dragoverElement && targetElement.isSameNode(dragoverElement)) {
// 性能优化,目标为同一个元素不再进行校验
const nodeRect = targetElement.getBoundingClientRect();
targetElement.classList.remove("dragover__top", "dragover__bottom", "dragover__left", "dragover__right");
if (targetElement.getAttribute("data-type") === "NodeListItem" || window.siyuan.dragElement.getAttribute("data-type") === "navigation-file") {
if (targetElement.getAttribute("data-type") === "NodeListItem" || fileTreeIds.indexOf("-") > -1) {
if (event.clientY > nodeRect.top + nodeRect.height / 2) {
targetElement.classList.add("dragover__bottom", "protyle-wysiwyg--select");
} else {
@ -742,12 +747,12 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
}
return;
}
if (window.siyuan.dragElement.getAttribute("data-type") === "navigation-file" && window.siyuan.dragElement.getAttribute("data-node-id") !== protyle.block.rootID) {
if (fileTreeIds.indexOf("-") > -1 && !fileTreeIds.split(",").includes(protyle.block.rootID)) {
dragoverElement = targetElement;
return;
}
if (window.siyuan.dragElement.parentElement.classList.contains("protyle-gutters") ||
if (window.siyuan.dragElement.parentElement?.classList.contains("protyle-gutters") ||
// 列表项之前的点
window.siyuan.dragElement.getAttribute("data-type") === "NodeListItem") {
// gutter 文档内拖拽限制