Vanessa 2024-04-18 19:48:09 +08:00
parent e4a128123d
commit 3f0c6675a9
3 changed files with 74 additions and 61 deletions

View file

@ -215,16 +215,19 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]
const targetElement = element.querySelector(".dragover__bottom, .dragover__top") as HTMLElement; const targetElement = element.querySelector(".dragover__bottom, .dragover__top") as HTMLElement;
if (targetElement && dragBlockElement) { if (targetElement && dragBlockElement) {
const isBottom = targetElement.classList.contains("dragover__bottom"); const isBottom = targetElement.classList.contains("dragover__bottom");
const previousID = isBottom ? targetElement.dataset.colId : targetElement.previousElementSibling?.getAttribute("data-col-id")
const undoPreviousID = window.siyuan.dragElement.previousElementSibling?.getAttribute("data-col-id")
if (previousID !== undoPreviousID && previousID !== window.siyuan.dragElement.dataset.colId) {
transaction(protyle, [{ transaction(protyle, [{
action: "sortAttrViewCol", action: "sortAttrViewCol",
avID: dragBlockElement.dataset.avId, avID: dragBlockElement.dataset.avId,
previousID: isBottom ? targetElement.dataset.colId : targetElement.previousElementSibling?.getAttribute("data-col-id"), previousID,
id: window.siyuan.dragElement.dataset.colId, id: window.siyuan.dragElement.dataset.colId,
blockID: id blockID: id
}, { }, {
action: "sortAttrViewCol", action: "sortAttrViewCol",
avID: dragBlockElement.dataset.avId, avID: dragBlockElement.dataset.avId,
previousID: window.siyuan.dragElement.previousElementSibling?.getAttribute("data-col-id"), previousID: undoPreviousID,
id, id,
blockID: id blockID: id
}]); }]);
@ -233,6 +236,7 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]
} else { } else {
targetElement.before(window.siyuan.dragElement); targetElement.before(window.siyuan.dragElement);
} }
}
targetElement.classList.remove("dragover__bottom", "dragover__top"); targetElement.classList.remove("dragover__bottom", "dragover__top");
} }
window.siyuan.dragElement = null; window.siyuan.dragElement = null;

View file

@ -389,16 +389,20 @@ export const openMenuPanel = (options: {
return; return;
} }
if (targetElement.getAttribute("data-type") === "editCol") {
const previousID = (targetElement.classList.contains("dragover__top") ? targetElement.previousElementSibling?.getAttribute("data-id") : targetElement.getAttribute("data-id")) || ""
const undoPreviousID = sourceElement.previousElementSibling?.getAttribute("data-id") || "";
if (previousID !== undoPreviousID && previousID !== sourceId) {
transaction(options.protyle, [{ transaction(options.protyle, [{
action: "sortAttrViewCol", action: "sortAttrViewCol",
avID, avID,
previousID: (targetElement.classList.contains("dragover__top") ? targetElement.previousElementSibling?.getAttribute("data-id") : targetElement.getAttribute("data-id")) || "", previousID,
id: sourceId, id: sourceId,
blockID, blockID,
}], [{ }], [{
action: "sortAttrViewCol", action: "sortAttrViewCol",
avID, avID,
previousID: sourceElement.previousElementSibling?.getAttribute("data-id") || "", previousID: undoPreviousID,
id: sourceId, id: sourceId,
blockID blockID
}]); }]);
@ -419,7 +423,10 @@ export const openMenuPanel = (options: {
return true; return true;
} }
}); });
}
menuElement.innerHTML = getPropertiesHTML(data.view); menuElement.innerHTML = getPropertiesHTML(data.view);
return;
}
}); });
let dragoverElement: HTMLElement; let dragoverElement: HTMLElement;
avPanelElement.addEventListener("dragover", (event: DragEvent) => { avPanelElement.addEventListener("dragover", (event: DragEvent) => {

View file

@ -843,6 +843,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
} }
} }
} }
if (previousID !== oldPreviousID && previousID !== gutterTypes[2]) {
transaction(protyle, [{ transaction(protyle, [{
action: "sortAttrViewCol", action: "sortAttrViewCol",
avID, avID,
@ -857,6 +858,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
blockID: blockElement.dataset.nodeId, blockID: blockElement.dataset.nodeId,
}]); }]);
} }
}
} else if (targetElement.classList.contains("av__row")) { } else if (targetElement.classList.contains("av__row")) {
// 拖拽到属性视图内 // 拖拽到属性视图内
const blockElement = hasClosestBlock(targetElement); const blockElement = hasClosestBlock(targetElement);
@ -874,7 +876,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
const undoOperations: IOperation[] = []; const undoOperations: IOperation[] = [];
const undoPreviousId = blockElement.querySelector(`[data-id="${selectedIds[0]}"]`).previousElementSibling.getAttribute("data-id") || ""; const undoPreviousId = blockElement.querySelector(`[data-id="${selectedIds[0]}"]`).previousElementSibling.getAttribute("data-id") || "";
selectedIds.reverse().forEach(item => { selectedIds.reverse().forEach(item => {
if (previousID !== item) { if (previousID !== item && undoPreviousId !== previousID) {
doOperations.push({ doOperations.push({
action: "sortAttrViewRow", action: "sortAttrViewRow",
avID, avID,