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,23 +215,27 @@ 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");
transaction(protyle, [{ const previousID = isBottom ? targetElement.dataset.colId : targetElement.previousElementSibling?.getAttribute("data-col-id")
action: "sortAttrViewCol", const undoPreviousID = window.siyuan.dragElement.previousElementSibling?.getAttribute("data-col-id")
avID: dragBlockElement.dataset.avId, if (previousID !== undoPreviousID && previousID !== window.siyuan.dragElement.dataset.colId) {
previousID: isBottom ? targetElement.dataset.colId : targetElement.previousElementSibling?.getAttribute("data-col-id"), transaction(protyle, [{
id: window.siyuan.dragElement.dataset.colId, action: "sortAttrViewCol",
blockID: id avID: dragBlockElement.dataset.avId,
}, { previousID,
action: "sortAttrViewCol", id: window.siyuan.dragElement.dataset.colId,
avID: dragBlockElement.dataset.avId, blockID: id
previousID: window.siyuan.dragElement.previousElementSibling?.getAttribute("data-col-id"), }, {
id, action: "sortAttrViewCol",
blockID: id avID: dragBlockElement.dataset.avId,
}]); previousID: undoPreviousID,
if (isBottom) { id,
targetElement.after(window.siyuan.dragElement); blockID: id
} else { }]);
targetElement.before(window.siyuan.dragElement); if (isBottom) {
targetElement.after(window.siyuan.dragElement);
} else {
targetElement.before(window.siyuan.dragElement);
}
} }
targetElement.classList.remove("dragover__bottom", "dragover__top"); targetElement.classList.remove("dragover__bottom", "dragover__top");
} }

View file

@ -389,37 +389,44 @@ export const openMenuPanel = (options: {
return; return;
} }
transaction(options.protyle, [{ if (targetElement.getAttribute("data-type") === "editCol") {
action: "sortAttrViewCol", const previousID = (targetElement.classList.contains("dragover__top") ? targetElement.previousElementSibling?.getAttribute("data-id") : targetElement.getAttribute("data-id")) || ""
avID, const undoPreviousID = sourceElement.previousElementSibling?.getAttribute("data-id") || "";
previousID: (targetElement.classList.contains("dragover__top") ? targetElement.previousElementSibling?.getAttribute("data-id") : targetElement.getAttribute("data-id")) || "", if (previousID !== undoPreviousID && previousID !== sourceId) {
id: sourceId, transaction(options.protyle, [{
blockID, action: "sortAttrViewCol",
}], [{ avID,
action: "sortAttrViewCol", previousID,
avID, id: sourceId,
previousID: sourceElement.previousElementSibling?.getAttribute("data-id") || "", blockID,
id: sourceId, }], [{
blockID action: "sortAttrViewCol",
}]); avID,
let column: IAVColumn; previousID: undoPreviousID,
data.view.columns.find((item, index: number) => { id: sourceId,
if (item.id === sourceId) { blockID
column = data.view.columns.splice(index, 1)[0]; }]);
return true; let column: IAVColumn;
data.view.columns.find((item, index: number) => {
if (item.id === sourceId) {
column = data.view.columns.splice(index, 1)[0];
return true;
}
});
data.view.columns.find((item, index: number) => {
if (item.id === targetId) {
if (isTop) {
data.view.columns.splice(index, 0, column);
} else {
data.view.columns.splice(index + 1, 0, column);
}
return true;
}
});
} }
}); menuElement.innerHTML = getPropertiesHTML(data.view);
data.view.columns.find((item, index: number) => { return;
if (item.id === targetId) { }
if (isTop) {
data.view.columns.splice(index, 0, column);
} else {
data.view.columns.splice(index + 1, 0, column);
}
return true;
}
});
menuElement.innerHTML = getPropertiesHTML(data.view);
}); });
let dragoverElement: HTMLElement; let dragoverElement: HTMLElement;
avPanelElement.addEventListener("dragover", (event: DragEvent) => { avPanelElement.addEventListener("dragover", (event: DragEvent) => {

View file

@ -843,19 +843,21 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
} }
} }
} }
transaction(protyle, [{ if (previousID !== oldPreviousID && previousID !== gutterTypes[2]) {
action: "sortAttrViewCol", transaction(protyle, [{
avID, action: "sortAttrViewCol",
previousID, avID,
id: gutterTypes[2], previousID,
blockID: blockElement.dataset.nodeId, id: gutterTypes[2],
}], [{ blockID: blockElement.dataset.nodeId,
action: "sortAttrViewCol", }], [{
avID, action: "sortAttrViewCol",
previousID: oldPreviousID, avID,
id: gutterTypes[2], previousID: oldPreviousID,
blockID: blockElement.dataset.nodeId, id: gutterTypes[2],
}]); blockID: blockElement.dataset.nodeId,
}]);
}
} }
} else if (targetElement.classList.contains("av__row")) { } else if (targetElement.classList.contains("av__row")) {
// 拖拽到属性视图内 // 拖拽到属性视图内
@ -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,