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

View file

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

View file

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