An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve document version comparison UI https://github.com/siyuan-note/siyuan/issues/11601
Daniel3378f03b601d
diff --git a/app/src/assets/scss/business/_history.scss b/app/src/assets/scss/business/_history.scssindex fa17bc08be..f2bd59efe8 100644--- a/app/src/assets/scss/business/_history.scss+++ b/app/src/assets/scss/business/_history.scss@@ -29,6 +29,14 @@background: var(--b3-theme-background);}+ &__current-version {+ position: sticky;+ z-index: 1;+ top: 0;+ background: var(--b3-theme-background);+ border-bottom: 1px solid var(--b3-border-color);+ }+&__side {width: 256px;padding: 8px 0;@@ -154,7 +162,7 @@&:last-child {[data-history-diff~="only"],[data-history-diff="inline"] {- background-color: color-mix(in srgb, var(--b3-theme-primary) 18%, transparent);+ background-color: color-mix(in srgb, var(--b3-theme-success) 18%, transparent);}}diff --git a/app/src/history/doc.ts b/app/src/history/doc.tsindex 5f8e5cecb1..37f32dd975 100644--- a/app/src/history/doc.ts+++ b/app/src/history/doc.ts@@ -16,6 +16,14 @@ let historyEditor: Protyle;const repoHistoryEditors = new WeakMap<HTMLElement, Protyle>();let isLoading = false;+const genCurrentVersionItem = () => `<li class="b3-list-item history__current-version" data-type="currentVersionItem">+ <span class="b3-list-item__text">${window.siyuan.languages.currentVer}</span>+ <span class="fn__space"></span>+ <span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="selectCurrentVersion" aria-pressed="true" aria-label="${window.siyuan.languages.currentVer}">+ <svg><use xlink:href="#iconCheck"></use></svg>+ </span>+</li>`;+const renderDoc = (element: HTMLElement, currentPage: number, id: string) => {const previousElement = element.querySelector('[data-type="docprevious"]');const nextElement = element.querySelector('[data-type="docnext"]');@@ -52,11 +60,11 @@ const renderDoc = (element: HTMLElement, currentPage: number, id: string) => {pageInfoElement.classList.remove("fn__none");pageInfoElement.textContent = window.siyuan.languages.pageCountAndHistoryCount.replace("${x}", response.data.pageCount).replace("${y}", response.data.totalCount);if (response.data.histories.length === 0) {- listElement.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;+ listElement.innerHTML = `${genCurrentVersionItem()}<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;element.dispatchEvent(new CustomEvent("versionListRendered"));return;}- let logsHTML = "";+ let logsHTML = genCurrentVersionItem();response.data.histories.forEach((item: string) => {logsHTML += `<li class="b3-list-item b3-list-item--hide-action" data-created="${item}"><span class="b3-list-item__text">${dayjs(parseInt(item) * 1000).format("YYYY-MM-DD HH:mm:ss")}</span>@@ -106,12 +114,14 @@ const renderRepo = async (element: HTMLElement, currentPage: number, id: string)} catch (e) {console.warn("get repo doc history failed", e);element.removeAttribute("data-loading");- listElement.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;+ listElement.innerHTML = `${genCurrentVersionItem()}<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;+ element.dispatchEvent(new CustomEvent("versionListRendered"));return;}if (response.code !== 0) {element.removeAttribute("data-loading");- listElement.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;+ listElement.innerHTML = `${genCurrentVersionItem()}<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;+ element.dispatchEvent(new CustomEvent("versionListRendered"));return;}@@ -130,6 +140,7 @@ const renderRepo = async (element: HTMLElement, currentPage: number, id: string).replace("${y}", response.data.totalCount);pageInfoElement.classList.remove("fn__none");renderRepoFileList(response.data.files, listElement, false, true);+ listElement.insertAdjacentHTML("afterbegin", genCurrentVersionItem());element.dispatchEvent(new CustomEvent("versionListRendered"));};@@ -160,6 +171,8 @@ export const openDocHistory = (options: {<span class="fn__space"></span><span class="ft__on-surface fn__flex-shrink ft__selectnone fn__none">${window.siyuan.languages.pageCountAndHistoryCount}</span><span class="fn__space"></span>+ <button class="b3-button b3-button--outline" data-type="compareVersions" disabled>${window.siyuan.languages.compare}</button>+ <span class="fn__space"></span><div class="fn__flex-1"></div><select data-type="opselect" class="b3-select"><option value="all" selected>${window.siyuan.languages.allOp}</option>@@ -169,10 +182,6 @@ export const openDocHistory = (options: {<option value="replace">${window.siyuan.languages.historyReplace}</option><option value="outline">${window.siyuan.languages.historyOutline}</option></select>- <span class="fn__space"></span>- <button class="b3-button b3-button--outline" data-type="selectCurrentVersion" aria-pressed="true"><svg><use xlink:href="#iconCheck"></use></svg>${window.siyuan.languages.currentVer}</button>- <span class="fn__space"></span>- <button class="b3-button b3-button--outline" data-type="compareVersions" disabled>${window.siyuan.languages.compare}</button></div></div><div class="fn__flex fn__flex-1 history__panel">@@ -196,10 +205,9 @@ export const openDocHistory = (options: {<span class="fn__space"></span><span class="ft__on-surface fn__flex-shrink ft__selectnone fn__none">${window.siyuan.languages.pageCountAndSnapshotCount}</span><span class="fn__space"></span>- <div class="fn__flex-1"></div>- <button class="b3-button b3-button--outline" data-type="selectCurrentVersion" aria-pressed="true"><svg><use xlink:href="#iconCheck"></use></svg>${window.siyuan.languages.currentVer}</button>- <span class="fn__space"></span><button class="b3-button b3-button--outline" data-type="compareVersions" disabled>${window.siyuan.languages.compare}</button>+ <span class="fn__space"></span>+ <div class="fn__flex-1"></div></div></div><div class="fn__flex fn__flex-1 history__panel">@@ -300,7 +308,8 @@ export const openDocHistory = (options: {const previewRepoFile = (element: Element) => {repoHistoryEditors.get(repoElement)?.destroy();repoHistoryEditors.delete(repoElement);- repoTitleElement.textContent = element.querySelector(".b3-list-item__text").textContent.trim();+ repoTitleElement.textContent = element.getAttribute("data-title") ||+ element.querySelector(".b3-list-item__text").textContent.trim();repoTitleElement.classList.remove("fn__none");repoPreviewElement.classList.remove("fn__none");renderRepoFile(options.app, element, repoPreviewElement, (editor) => {@@ -383,6 +392,11 @@ export const openDocHistory = (options: {event.stopPropagation();event.preventDefault();break;+ } else if (target.classList.contains("b3-list-item") && type === "currentVersionItem") {+ toggleVersionSelection(currentVersion);+ event.stopPropagation();+ event.preventDefault();+ break;} else if (type === "rollback" && !isLoading) {const historyItemElement = target.parentElement;getHistoryPath(historyItemElement, opElement.value, options.id, (item) => {diff --git a/app/src/history/repoFile.ts b/app/src/history/repoFile.tsindex 119f809231..2ec69db376 100644--- a/app/src/history/repoFile.ts+++ b/app/src/history/repoFile.ts@@ -5,7 +5,7 @@ import type {App} from "../index";import {Protyle} from "../protyle";import {saveExportFile} from "../protyle/util/compatibility";import {disabledProtyle, onGet} from "../protyle/util/onGet";-import {escapeHtml} from "../util/escape";+import {escapeAttr, escapeHtml} from "../util/escape";import {fetchPost} from "../util/fetch";import {pathPosix} from "../util/pathName";import * as dayjs from "dayjs";@@ -29,15 +29,23 @@ export const renderRepoFileList = (files: IRepoFile[], element: Element, showPatlet html = "";files.forEach((item) => {- const pathHTML = showPath && item.hPath ? `${escapeHtml(item.hPath)}<span class="fn__space"></span>` : "";- const compareHTML = showCompare ? `<span class="b3-list-item__action" data-type="selectVersion" aria-pressed="false">- <svg><use xlink:href="#iconUncheck"></use></svg>- <span class="fn__space"></span>${window.siyuan.languages.compare}- </span>- <span class="fn__space"></span>` : "";- const compareIconHTML = showCompare ? `<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="selectVersion" aria-pressed="false" aria-label="${window.siyuan.languages.compare}">+ if (showCompare) {+ html += `<li class="b3-list-item b3-list-item--hide-action" data-type="searchFileItem" data-id="${item.fileID}" data-snapshot="${item.indexID}" data-created="${item.updated}" data-title="${escapeAttr(item.title)}">+ <span class="b3-list-item__text">${dayjs(item.updated).format("YYYY-MM-DD HH:mm:ss")}</span>+ <span class="fn__space"></span>+ <span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="selectVersion" aria-pressed="false" aria-label="${window.siyuan.languages.compare}"><svg><use xlink:href="#iconUncheck"></use></svg>- </span>` : "";+ </span>+ <span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="saveAs" aria-label="${window.siyuan.languages.saveAs}">+ <svg><use xlink:href="#iconDownload"></use></svg>+ </span>+ <span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="rollback" aria-label="${window.siyuan.languages.rollback}">+ <svg><use xlink:href="#iconUndo"></use></svg>+ </span>+</li>`;+ return;+ }+ const pathHTML = showPath && item.hPath ? `${escapeHtml(item.hPath)}<span class="fn__space"></span>` : "";/// #if MOBILEhtml += `<li class="b3-list-item" data-type="searchFileItem" data-id="${item.fileID}" data-snapshot="${item.indexID}" data-created="${item.updated}"><div class="fn__flex-1">@@ -49,7 +57,6 @@ export const renderRepoFileList = (files: IRepoFile[], element: Element, showPat</div><div class="fn__flex" style="height: 26px"><span class="fn__flex-1"></span>- ${compareHTML}<span class="b3-list-item__action" data-type="saveAs"><svg><use xlink:href="#iconDownload"></use></svg><span class="fn__space"></span>${window.siyuan.languages.saveAs}@@ -72,7 +79,6 @@ export const renderRepoFileList = (files: IRepoFile[], element: Element, showPat${dayjs(item.updated).format("YYYY-MM-DD HH:mm:ss")}</div></div>- ${compareIconHTML}<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="saveAs" aria-label="${window.siyuan.languages.saveAs}"><svg><use xlink:href="#iconDownload"></use></svg></span>@@ -90,7 +96,7 @@ export const rollbackRepoFile = (element: Element) => {return;}- const name = element.querySelector(".b3-list-item__text").textContent.trim();+ const name = element.getAttribute("data-title") || element.querySelector(".b3-list-item__text").textContent.trim();const time = dayjs(parseInt(element.getAttribute("data-created"))).format("YYYY-MM-DD HH:mm:ss");confirmDialog("⚠️ " + window.siyuan.languages.rollback,window.siyuan.languages.rollbackConfirm.replace("${name}", name).replace("${time}", time),