diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index f76a6a0ed..0a6e468e3 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -1,4 +1,5 @@ { + "compare": "Compare", "switchTab": "Switcher", "recentDocs": "Recently opened documents", "autoLaunch": "Automatic launch at boot", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 1601754e4..f304217e7 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -1,4 +1,5 @@ { + "comparar": "Comparar", "switchTab": "Conmutador", "recentDocs": "Documentos abiertos recientemente", "autoLaunch": "Inicio automático al arrancar", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 14b7d4e10..d4ab31f07 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -1,4 +1,5 @@ { + "comparer": "Comparer", "switchTab": "Commutateur", "recentDocs": "Documents récemment ouverts", "autoLaunch": "Lancement automatique au démarrage", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index d2e2394b7..d99d20b7b 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -1,4 +1,5 @@ { + "compare": "比較", "switchTab": "頁簽切換", "recentDocs": "最近打开的文档", "autoLaunch": "開機自動啟動", diff --git a/app/src/assets/scss/_dialog.scss b/app/src/assets/scss/_dialog.scss index 5ff77e6ea..418e0af3e 100644 --- a/app/src/assets/scss/_dialog.scss +++ b/app/src/assets/scss/_dialog.scss @@ -103,4 +103,11 @@ min-height: 18px; } } + + &__diff { + width: 200px; + border-right: 1px solid var(--b3-border-color); + padding: 8px 0; + overflow: auto; + } } diff --git a/app/src/history/diff.ts b/app/src/history/diff.ts index 517a880ac..e653aba5c 100644 --- a/app/src/history/diff.ts +++ b/app/src/history/diff.ts @@ -1,3 +1,83 @@ -export const showDiff = () => { +import {fetchPost} from "../util/fetch"; +import {Dialog} from "../dialog"; +const genItem = (data: [], type: "add" | "update" | "remove") => { + if (!data || data.length === 0) { + return `
  • ${window.siyuan.languages.emptyContent}
  • ` + } + let html = ""; + data.forEach((item: { id: string, path: string }) => { + html += `
  • ${item.path}
  • `; + }) + return html; +} + +const renderCompare = (element: HTMLElement) => { + fetchPost("/api/repo/openRepoSnapshotDoc", {id: element.getAttribute("data-id")}, (response) => { + + }) +} + +export const showDiff = (ids: string) => { + const idArray = ids.split(","); + if (idArray.length !== 2) { + return; + } + fetchPost("/api/repo/diffRepoSnapshots", {left: idArray[0], right: idArray[1]}, (response) => { + const dialog = new Dialog({ + title: window.siyuan.languages.compare, + content: `
    +
    + + + +
    +
    +
    `, + width: "80vw", + height: "80vh", + }); + dialog.element.addEventListener("click", (event) => { + let target = event.target as HTMLElement; + while (target && target !== dialog.element) { + if (target.classList.contains("b3-list-item") && !target.dataset.id) { + target.nextElementSibling.classList.toggle("fn__none"); + target.querySelector("svg").classList.toggle("b3-list-item__arrow--open"); + break; + } else if (target.classList.contains("b3-list-item") && target.dataset.id) { + if (target.classList.contains("b3-list-item--focus")) { + return; + } + 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) + } + target = target.parentElement; + } + }); + }); } diff --git a/app/src/history/history.ts b/app/src/history/history.ts index 06ba0231b..8eecb9370 100644 --- a/app/src/history/history.ts +++ b/app/src/history/history.ts @@ -9,6 +9,7 @@ import * as dayjs from "dayjs"; import {fetchPost} from "../util/fetch"; import {escapeHtml} from "../util/escape"; import {isMobile} from "../util/functions"; +import {showDiff} from "./diff"; let historyEditor: Protyle; const renderDoc = (element: HTMLElement, currentPage: number) => { @@ -596,7 +597,7 @@ export const openHistory = () => { }); break; } else if (type === "compare") { - showDiff() + showDiff(target.getAttribute("data-ids")); break; } target = target.parentElement;