This commit is contained in:
Vanessa 2023-09-28 14:09:39 +08:00
parent 89902a9fd9
commit 0184fb55f5

View File

@ -820,16 +820,18 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
}); });
hideElements(["gutter"], protyle); hideElements(["gutter"], protyle);
const targetClass = targetElement.className.split(" ");
targetElement.classList.remove("dragover__bottom", "dragover__top", "dragover__left", "dragover__right", "protyle-wysiwyg--select");
if (targetElement.classList.contains("av__cell")) { if (targetElement.classList.contains("av__cell")) {
const blockElement = hasClosestBlock(targetElement); const blockElement = hasClosestBlock(targetElement);
if (!blockElement) { if (blockElement) {
return;
}
const avID = blockElement.getAttribute("data-av-id"); const avID = blockElement.getAttribute("data-av-id");
transaction(protyle, [{ transaction(protyle, [{
action: "sortAttrViewCol", action: "sortAttrViewCol",
avID, avID,
previousID: (targetElement.classList.contains("dragover__left") ? targetElement.previousElementSibling?.getAttribute("data-col-id") : targetElement.getAttribute("data-col-id")) || "", previousID: (targetClass.includes("dragover__left") ? targetElement.previousElementSibling?.getAttribute("data-col-id") : targetElement.getAttribute("data-col-id")) || "",
id: gutterTypes[2], id: gutterTypes[2],
}], [{ }], [{
action: "sortAttrViewCol", action: "sortAttrViewCol",
@ -837,16 +839,13 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
previousID: targetElement.parentElement.querySelector(`[data-col-id="${gutterTypes[2]}"`).previousElementSibling?.getAttribute("data-col-id") || "", previousID: targetElement.parentElement.querySelector(`[data-col-id="${gutterTypes[2]}"`).previousElementSibling?.getAttribute("data-col-id") || "",
id: gutterTypes[2], id: gutterTypes[2],
}]); }]);
return;
} }
if (targetElement.classList.contains("av__row")) { } else if (targetElement.classList.contains("av__row")) {
// 拖拽到属性视图内 // 拖拽到属性视图内
const blockElement = hasClosestBlock(targetElement); const blockElement = hasClosestBlock(targetElement);
if (!blockElement) { if (blockElement) {
return;
}
let previousID = ""; let previousID = "";
if (targetElement.classList.contains("dragover__bottom")) { if (targetClass.includes("dragover__bottom")) {
previousID = targetElement.getAttribute("data-id") || ""; previousID = targetElement.getAttribute("data-id") || "";
} else { } else {
previousID = targetElement.previousElementSibling?.getAttribute("data-id") || ""; previousID = targetElement.previousElementSibling?.getAttribute("data-id") || "";
@ -885,10 +884,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
}]); }]);
insertAttrViewBlockAnimation(blockElement, sourceIds.length, previousID); insertAttrViewBlockAnimation(blockElement, sourceIds.length, previousID);
} }
return;
} }
const targetClass = targetElement.className.split(" "); } else {
targetElement.classList.remove("dragover__bottom", "dragover__top", "dragover__left", "dragover__right", "protyle-wysiwyg--select");
if (targetElement.parentElement.getAttribute("data-type") === "NodeSuperBlock" && if (targetElement.parentElement.getAttribute("data-type") === "NodeSuperBlock" &&
targetElement.parentElement.getAttribute("data-sb-layout") === "col") { targetElement.parentElement.getAttribute("data-sb-layout") === "col") {
if (targetClass.includes("dragover__left") || targetClass.includes("dragover__right")) { if (targetClass.includes("dragover__left") || targetClass.includes("dragover__right")) {
@ -915,17 +912,16 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
blockRender(protyle, targetElement); blockRender(protyle, targetElement);
} }
} }
}
} else if (event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE)?.split("-").length > 1 } else if (event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE)?.split("-").length > 1
&& targetElement && !protyle.options.backlinkData) { && targetElement && !protyle.options.backlinkData && targetElement.className.indexOf("dragover__") > -1) {
// 文件树拖拽 // 文件树拖拽
const scrollTop = protyle.contentElement.scrollTop; const scrollTop = protyle.contentElement.scrollTop;
const ids = event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE).split(","); const ids = event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE).split(",");
if (targetElement.classList.contains("av__row")) { if (targetElement.classList.contains("av__row")) {
// 拖拽到属性视图内 // 拖拽到属性视图内
const blockElement = hasClosestBlock(targetElement); const blockElement = hasClosestBlock(targetElement);
if (!blockElement) { if (blockElement) {
return;
}
let previousID = ""; let previousID = "";
if (targetElement.classList.contains("dragover__bottom")) { if (targetElement.classList.contains("dragover__bottom")) {
previousID = targetElement.getAttribute("data-id") || ""; previousID = targetElement.getAttribute("data-id") || "";
@ -944,8 +940,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
avID, avID,
}]); }]);
insertAttrViewBlockAnimation(blockElement, ids.length, previousID); insertAttrViewBlockAnimation(blockElement, ids.length, previousID);
return;
} }
} else {
for (let i = 0; i < ids.length; i++) { for (let i = 0; i < ids.length; i++) {
if (ids[i]) { if (ids[i]) {
await fetchSyncPost("/api/filetree/doc2Heading", { await fetchSyncPost("/api/filetree/doc2Heading", {
@ -976,7 +972,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
protyle.scroll.lastScrollTop = scrollTop - 1; protyle.scroll.lastScrollTop = scrollTop - 1;
}, Constants.TIMEOUT_LOAD); }, Constants.TIMEOUT_LOAD);
}); });
targetElement.classList.remove("dragover__bottom", "dragover__top"); }
targetElement.classList.remove("dragover__bottom", "dragover__top", "dragover__left", "dragover__right", "protyle-wysiwyg--select");
} else if (!window.siyuan.dragElement && (event.dataTransfer.types[0] === "Files" || event.dataTransfer.types.includes("text/html"))) { } else if (!window.siyuan.dragElement && (event.dataTransfer.types[0] === "Files" || event.dataTransfer.types.includes("text/html"))) {
// 外部文件拖入编辑器中或者编辑器内选中文字拖拽 // 外部文件拖入编辑器中或者编辑器内选中文字拖拽
focusByRange(getRangeByPoint(event.clientX, event.clientY)); focusByRange(getRangeByPoint(event.clientX, event.clientY));