This commit is contained in:
Vanessa 2022-12-20 20:14:24 +08:00
parent 40c4f5f756
commit 18d82f04fc
2 changed files with 18 additions and 18 deletions

View file

@ -8,7 +8,7 @@ import {escapeHtml} from "../util/escape";
const genItem = (data: [], data2?: { title: string, fileID: string }[]) => {
if (!data || data.length === 0) {
return `<li style="padding-left: 44px;" class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`
return `<li style="padding-left: 44px;" class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
}
let html = "";
data.forEach((item: { title: string, fileID: string }, index) => {
@ -19,14 +19,14 @@ const genItem = (data: [], data2?: { title: string, fileID: string }[]) => {
html += `<li style="padding-left: 44px;" class="b3-list-item" ${id2} data-id="${item.fileID}">
<span class="b3-list-item__text">${escapeHtml(item.title)}</span>
</li>`;
})
});
return html;
}
};
let leftEditor: Protyle;
let rightEditor: Protyle;
const renderCompare = (element: HTMLElement) => {
const listElement = hasClosestByClassName(element, "b3-dialog__diff")
const listElement = hasClosestByClassName(element, "b3-dialog__diff");
if (!listElement) {
return;
}
@ -73,8 +73,8 @@ const renderCompare = (element: HTMLElement) => {
leftElement.lastElementChild.classList.remove("fn__none");
onGet(response, leftEditor.protyle, [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML]);
}
})
const id2 = element.getAttribute("data-id2")
});
const id2 = element.getAttribute("data-id2");
if (id2) {
rightElement.classList.remove("fn__none");
fetchPost("/api/repo/openRepoSnapshotDoc", {id: id2}, (response) => {
@ -87,11 +87,11 @@ const renderCompare = (element: HTMLElement) => {
rightElement.lastElementChild.classList.remove("fn__none");
onGet(response, rightEditor.protyle, [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML]);
}
})
});
} else {
rightElement.classList.add("fn__none");
}
}
};
export const showDiff = (ids: string) => {
const idArray = ids.split(",");
@ -145,8 +145,8 @@ export const showDiff = (ids: string) => {
width: "80vw",
height: "80vh",
destroyCallback() {
leftEditor = undefined
rightEditor = undefined
leftEditor = undefined;
rightEditor = undefined;
}
});
dialog.element.addEventListener("click", (event) => {
@ -162,10 +162,10 @@ export const showDiff = (ids: string) => {
}
dialog.element.querySelector(".b3-dialog__diff .b3-list-item--focus")?.classList.remove("b3-list-item--focus");
target.classList.add("b3-list-item--focus");
renderCompare(target)
renderCompare(target);
}
target = target.parentElement;
}
});
});
}
};

View file

@ -345,7 +345,7 @@ export const openHistory = () => {
} else if (value === "2") {
renderRepo(repoElement, -2);
}
const btnElement = dialog.element.querySelector(".b3-button[data-type='compare']")
const btnElement = dialog.element.querySelector(".b3-button[data-type='compare']");
btnElement.removeAttribute("disabled");
btnElement.removeAttribute("data-ids");
});
@ -438,8 +438,8 @@ export const openHistory = () => {
target.firstElementChild.firstElementChild.classList.toggle("b3-list-item__arrow--open");
break;
} else if (target.classList.contains("b3-list-item") && type === "repoitem") {
const btnElement = dialog.element.querySelector(".b3-button[data-type='compare']")
const idstring = btnElement.getAttribute("data-ids")
const btnElement = dialog.element.querySelector(".b3-button[data-type='compare']");
const idstring = btnElement.getAttribute("data-ids");
const ids = idstring ? idstring.split(",") : [];
const id = target.getAttribute("data-id");
if (target.classList.contains("b3-list-item--focus")) {
@ -448,7 +448,7 @@ export const openHistory = () => {
ids.splice(ids.indexOf(id), 1);
}
} else {
target.classList.add("b3-list-item--focus")
target.classList.add("b3-list-item--focus");
if (!ids.includes(id)) {
while (ids.length > 1) {
const removeId = ids.splice(0, 1)[0];
@ -458,9 +458,9 @@ export const openHistory = () => {
}
}
if (ids.length === 2) {
btnElement.removeAttribute("disabled")
btnElement.removeAttribute("disabled");
} else {
btnElement.setAttribute("disabled", "disabled")
btnElement.setAttribute("disabled", "disabled");
}
btnElement.setAttribute("data-ids", ids.join(","));
break;