Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:lipstick: Improve mobile snapshot browsing and comparison https://github.com/siyuan-note/siyuan/issues/19484

Daniel3afe87664489
diff --git a/app/src/assets/scss/business/_history.scss b/app/src/assets/scss/business/_history.scss
index e5950b9d5d..d9f0e268cd 100644
--- a/app/src/assets/scss/business/_history.scss
+++ b/app/src/assets/scss/business/_history.scss
@@ -16,10 +16,23 @@
}
&--narrow {
+ .history__snapshot-toolbar {
+ padding: 4px;
+ gap: 4px;
+ }
+
+ .history__snapshot-heading {
+ min-height: 37px;
+ }
+
.history__snapshot-sources {
display: flex;
}
+ .history__snapshot-label {
+ display: none;
+ }
+
&[data-source="local"] [data-repo-source="cloud"],
&[data-source="cloud"] [data-repo-source="local"] {
display: none;
@@ -36,6 +49,77 @@
}
&__snapshot {
+ &-diff-dialog {
+ border-radius: 0;
+
+ .history__snapshot-diff {
+ min-height: 0;
+ flex-direction: column;
+
+ > .history__side {
+ flex: 1;
+ width: auto;
+ min-height: 0;
+ }
+
+ > .history__resize,
+ > [data-type="editors"],
+ > .history__snapshot-diff-nav {
+ display: none;
+ }
+
+ &--preview {
+ > .history__side {
+ display: none;
+ }
+
+ > [data-type="editors"],
+ > .history__snapshot-diff-nav {
+ display: flex;
+ }
+ }
+
+ &[data-side="left"] > [data-type="editors"] > :last-child,
+ &[data-side="right"] > [data-type="editors"] > :first-child {
+ display: none;
+ }
+
+ > [data-type="editors"] {
+ min-height: 0;
+ min-width: 0;
+
+ > div {
+ min-height: 0;
+ min-width: 0;
+ }
+
+ .protyle-title__input {
+ margin: 0;
+ padding: 4px 8px;
+ font-size: 14px;
+ line-height: 20px;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+ }
+ }
+ }
+
+ &-diff-nav {
+ flex-shrink: 0;
+ align-items: center;
+ flex-wrap: wrap;
+ gap: 4px;
+ padding: 4px;
+ border-bottom: 1px solid var(--b3-border-color);
+
+ [aria-pressed="true"] {
+ background-color: var(--b3-theme-primary-lightest);
+ color: var(--b3-theme-primary);
+ }
+ }
+
&-toolbar,
&-sources {
display: flex;
@@ -54,6 +138,9 @@
&-sources {
display: none;
+ padding: 0;
+ gap: 4px;
+ border: 0;
}
&-heading,
diff --git a/app/src/history/diff.ts b/app/src/history/diff.ts
index 9e170628cb..0c942e8878 100644
--- a/app/src/history/diff.ts
+++ b/app/src/history/diff.ts
@@ -260,6 +260,7 @@ const genSnapshotSide = (state: SnapshotDiffFilterState) => {
};
const resetSnapshotPreview = (dialog: Dialog) => {
+ dialog.element.querySelector(".history__snapshot-diff")?.classList.remove("history__snapshot-diff--preview");
dialog.element.querySelectorAll('[data-type="editors"] > div').forEach((item) => item.classList.add("fn__none"));
};
@@ -306,6 +307,17 @@ const renderCompare = (app: App, element: HTMLElement) => {
}
}
const editorsElement = dialogContainerElement.querySelector('[data-type="editors"]');
+ const panel = dialogContainerElement.querySelector<HTMLElement>(".history__snapshot-diff");
+ panel.classList.add("history__snapshot-diff--preview");
+ panel.dataset.side = "left";
+ panel.querySelectorAll<HTMLElement>('[data-type="snapshotVersion"]').forEach(button => {
+ button.setAttribute("aria-pressed", String(button.dataset.side === "left"));
+ button.classList.toggle("fn__none", button.dataset.side === "right" && !id2);
+ const snapshotIndex = button.dataset.side === "right" || element.parentElement.dataset.type === "update" ? 1 : 0;
+ const snapshot = dialogContainerElement.querySelectorAll<HTMLElement>(".b3-dialog__header [data-snapshot]")[snapshotIndex];
+ button.textContent = dayjs(parseInt(snapshot.dataset.created)).format("MM-DD HH:mm");
+ button.setAttribute("aria-label", dayjs(parseInt(snapshot.dataset.created)).format("YYYY-MM-DD HH:mm"));
+ });
const leftElement = editorsElement.firstElementChild;
const rightElement = editorsElement.lastElementChild;
if (!leftEditor) {
@@ -368,6 +380,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
});
}
titleElement.textContent = response.data.title;
+ titleElement.setAttribute("title", response.data.title);
leftElement.querySelector(".history__date").textContent = dayjs(response.data.updated).format("YYYY-MM-DD HH:mm");
});
if (id2) {
@@ -398,6 +411,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
});
}
titleElement.textContent = response.data.title;
+ titleElement.setAttribute("title", response.data.title);
rightElement.querySelector(".history__date").textContent = dayjs(response.data.updated).format("YYYY-MM-DD HH:mm");
});
} else {
@@ -427,9 +441,9 @@ export const showDiff = (app: App, data: { id: string, time: string }[]) => {
const dialog = new Dialog({
title: window.siyuan.languages.compare,
content: "",
- width: isMobile() ? "92vw" : "90vw",
- height: "80vh",
- containerClassName: "b3-dialog__container--theme",
+ width: isMobile() ? "100vw" : "90vw",
+ height: isMobile() ? "100%" : "80vh",
+ containerClassName: `b3-dialog__container--theme${isMobile() ? " history__snapshot-diff-dialog" : ""}`,
destroyCallback() {
leftEditor = undefined;
rightEditor = undefined;
@@ -445,7 +459,20 @@ export const showDiff = (app: App, data: { id: string, time: string }[]) => {
}
let target = event.target as HTMLElement;
while (target && target !== dialog.element) {
- if (target.dataset.type === "snapshotAggregate") {
+ if (target.dataset.type === "snapshotBack") {
+ dialog.element.querySelector(".history__snapshot-diff").classList.remove("history__snapshot-diff--preview");
+ event.preventDefault();
+ event.stopPropagation();
+ break;
+ } else if (target.dataset.type === "snapshotVersion") {
+ dialog.element.querySelector<HTMLElement>(".history__snapshot-diff").dataset.side = target.dataset.side;
+ dialog.element.querySelectorAll<HTMLElement>('[data-type="snapshotVersion"]').forEach(button => {
+ button.setAttribute("aria-pressed", String(button.dataset.side === target.dataset.side));
+ });
+ event.preventDefault();
+ event.stopPropagation();
+ break;
+ } else if (target.dataset.type === "snapshotAggregate") {
filterState.aggregate = target.dataset.value as SnapshotDiffAggregate;
filterState.kind = "all";
renderSnapshotSide(dialog, filterState);
@@ -472,7 +499,7 @@ export const showDiff = (app: App, data: { id: string, time: string }[]) => {
event.stopPropagation();
break;
} else if (target.classList.contains("b3-list-item") && target.dataset.id) {
- if (target.classList.contains("b3-list-item--focus") &&
+ if (!isMobile() && target.classList.contains("b3-list-item--focus") &&
!(target.dataset.kind === "document" && target.dataset.id2)) {
return;
}
@@ -536,9 +563,14 @@ const genHTML = (app: App, left: string, right: string, dialog: Dialog, direct:
${dayjs(response.data.right.created).format("YYYY-MM-DD HH:mm")}
<span class="fn__flex-1"></span>
</div>`;
- headElement.nextElementSibling.innerHTML = `<div class="fn__flex history__panel" style="height: 100%">
+ headElement.nextElementSibling.innerHTML = `<div class="fn__flex history__panel history__snapshot-diff" style="height: 100%" data-side="left">
<div class="history__side history__side--diff" ${isMobile() ? "" : `style="width: ${window.siyuan.storage[Constants.LOCAL_HISTORY].sideDiffWidth}"`}>${genSnapshotSide(filterState)}</div>
<div class="history__resize"></div>
+ ${isPhone ? `<div class="history__snapshot-diff-nav">
+ <button class="b3-button b3-button--text" data-type="snapshotBack">${window.siyuan.languages.back}</button>
+ <button class="b3-button b3-button--text" data-type="snapshotVersion" data-side="left" aria-pressed="true" aria-label="${dayjs(response.data.left.created).format("YYYY-MM-DD HH:mm")}">${dayjs(response.data.left.created).format("MM-DD HH:mm")}</button>
+ <button class="b3-button b3-button--text" data-type="snapshotVersion" data-side="right" aria-pressed="false" aria-label="${dayjs(response.data.right.created).format("YYYY-MM-DD HH:mm")}">${dayjs(response.data.right.created).format("MM-DD HH:mm")}</button>
+ </div>` : ""}
<div class="fn__flex-1 fn__flex" data-type="editors">
<div class="fn__none fn__flex-1 fn__flex-column">
<div class="history__date">${dayjs(response.data.left.created).format("YYYY-MM-DD HH:mm")}</div>
diff --git a/app/src/history/repoPanel.ts b/app/src/history/repoPanel.ts
index 9ccff38137..db9e72e666 100644
--- a/app/src/history/repoPanel.ts
+++ b/app/src/history/repoPanel.ts
@@ -92,10 +92,6 @@ export const initRepoPanel = (root: HTMLElement, render: (pane: Element, page: n
<button class="b3-button b3-button--outline fn__none" data-action="manage">${lang.repoBatchManage}</button>
<button class="b3-button b3-button--outline" data-type="genRepo">${lang.createSnapshot}</button>
</div>
-<div class="history__snapshot-sources">
- <button class="b3-button b3-button--text" data-action="local" aria-pressed="true">${lang.localSnapshot}</button>
- <button class="b3-button b3-button--text" data-action="cloud" aria-pressed="false">${lang.cloudSnapshot}</button>
-</div>
<div class="history__snapshot-columns"></div>
<div class="history__snapshot-toolbar fn__none" data-role="batch">
<span data-role="selection" aria-live="polite"></span><span class="fn__flex-1"></span>
@@ -109,7 +105,11 @@ export const initRepoPanel = (root: HTMLElement, render: (pane: Element, page: n
pane.className = "history__repo history__snapshot-pane";
pane.dataset.repoSource = source;
pane.innerHTML = `<div class="history__snapshot-toolbar history__snapshot-heading">
- <span>${source === "local" ? lang.localSnapshot : lang.cloudSnapshot}</span><span class="fn__flex-1"></span>
+ <span class="history__snapshot-label">${source === "local" ? lang.localSnapshot : lang.cloudSnapshot}</span>
+ <div class="history__snapshot-sources">
+ <button class="b3-button b3-button--text" data-action="local" aria-pressed="true">${lang.localSnapshot}</button>
+ <button class="b3-button b3-button--text" data-action="cloud" aria-pressed="false">${lang.cloudSnapshot}</button>
+ </div><span class="fn__flex-1"></span>
<button class="b3-button b3-button--text${canPurgeRepo(source, window.siyuan.config.sync.provider) ? "" : " fn__none"}" data-action="purge">${source === "local" ? lang.dataRepoPurge : lang.cloudStoragePurge}</button>
</div>
<label class="history__snapshot-toolbar fn__none"><input type="checkbox" class="history__snapshot-check" data-repo-all> ${lang.selectAll}</label>${template}`;
@@ -184,7 +184,7 @@ export const initRepoPanel = (root: HTMLElement, render: (pane: Element, page: n
refresh();
} else if (action === "local" || action === "cloud") {
root.dataset.source = action;
- root.querySelectorAll("[data-action=local], [data-action=cloud]").forEach(item => item.setAttribute("aria-pressed", String(item === button)));
+ root.querySelectorAll<HTMLElement>("[data-action=local], [data-action=cloud]").forEach(item => item.setAttribute("aria-pressed", String(item.dataset.action === action)));
} else if (action === "manage" || action === "clear") {
if (action === "manage") {
state.managing = !state.managing;