Skip to content

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

:bug: Refine database row touch feedback and mobile preview switching https://github.com/siyuan-note/siyuan/issues/20407

Daniel3789316496d8
diff --git a/app/src/assets/scss/business/_block.scss b/app/src/assets/scss/business/_block.scss
index 083583d358..48317e5d19 100644
--- a/app/src/assets/scss/business/_block.scss
+++ b/app/src/assets/scss/business/_block.scss
@@ -112,6 +112,7 @@
transition: var(--b3-transition), opacity .3s cubic-bezier(0, 0, .2, 1) 0ms;
line-height: 16px;
+ &--tap:active:not([disabled]),
&:hover:not([disabled]):not(.block__icon--text):not(.block__icon--warning):not(.block__icon--subtle),
&--active {
color: var(--b3-theme-on-background);
@@ -149,6 +150,10 @@
}
}
+ &--tap {
+ -webkit-tap-highlight-color: transparent;
+ }
+
&--subtle {
color: var(--b3-border-color);
diff --git a/app/src/editor/databaseRowSwitch.test.ts b/app/src/editor/databaseRowSwitch.test.ts
index 88586ff9e8..5471336c3e 100644
--- a/app/src/editor/databaseRowSwitch.test.ts
+++ b/app/src/editor/databaseRowSwitch.test.ts
@@ -14,6 +14,9 @@ const createPreview = async (mobile: boolean) => {
const title = {textContent: "", style: {}};
const content = {scrollTop: 25};
let body: Body;
+ let hidden = false;
+ let hiddenOnClose = false;
+ const openedBlocks: string[] = [];
class Body {
public isConnected = true;
public style = {};
@@ -30,6 +33,7 @@ const createPreview = async (mobile: boolean) => {
body = new Body();
const listeners = new Map<string, (event: {detail: unknown}) => void>();
const root = {
+ classList: {add: (name: string) => { hidden ||= name === "fn__none"; }},
dataset: {}, clientWidth: 800, isConnected: true, scrollTop: 25,
querySelector: (selector: string): unknown => {
if (selector.includes("__body")) { return body; }
@@ -41,6 +45,7 @@ const createPreview = async (mobile: boolean) => {
addEventListener: (name: string, listener: (event: {detail: unknown}) => void) => listeners.set(name, listener),
};
let closed = 0;
+ const dialogs: {element: typeof root, destroy: () => void}[] = [];
const tab = {updateTitle: (value: string) => { title.textContent = value; }, parent: {removeTab: () => { closed++; }}};
let destroy: () => void;
let loaded: () => void;
@@ -68,9 +73,11 @@ const createPreview = async (mobile: boolean) => {
"../protyle/ui/padding": {getEditorHorizontalPadding: () => ({left: 0, right: 0})},
"../../../dialog": {Dialog: class {
public element = root;
- constructor(options: {destroyCallback: () => void}) { destroy = options.destroyCallback; }
- public destroy() { closed++; destroy(); }
+ constructor(options: {destroyCallback: () => void}) { destroy = options.destroyCallback; dialogs.push(this); }
+ public destroy() { hiddenOnClose = hidden; closed++; destroy(); }
}},
+ "../../../constants": {Constants: {CB_GET_ALL: "all", CB_GET_FOCUS: "focus"}},
+ "../../../mobile/editor": {openMobileFileById: (_app: unknown, id: string) => openedBlocks.push(id)},
"./databaseRowNavigation": {
getDatabaseRowNavigation: (): undefined => undefined,
mountDatabaseRowNavigation: (_root: unknown, row: IDatabaseRowOpenData,
@@ -87,7 +94,7 @@ const createPreview = async (mobile: boolean) => {
compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},
}).outputText, {
exports, document: {createElement: () => new Body()},
- window: {siyuan: {dialogs: [], languages: {untitled: "Untitled"}, config: {editor: {databaseAttrShow: true}}}},
+ window: {siyuan: {dialogs, menus: {menu: {remove() {}}}, languages: {untitled: "Untitled"}, config: {editor: {databaseAttrShow: true}}}},
ResizeObserver: class { observe() {} disconnect() {} },
require: (name: string) => {
if (name === "../protyle" || name === "../../index") {
@@ -139,7 +146,7 @@ const createPreview = async (mobile: boolean) => {
return {data, title, root, content, requests, complete, refresh: () => refresh(),
navigate: (next: IDatabaseRowOpenData) => navigate(next), destroy: () => destroy(),
body: () => body, closed: () => closed, savedRow: () => model?.data.itemID,
- mountedRow: () => mountedRow};
+ mountedRow: () => mountedRow, hiddenOnClose: () => hiddenOnClose, openedBlocks};
};
for (const mobile of [false, true]) {
@@ -177,3 +184,11 @@ for (const mobile of [false, true]) {
assert.equal(preview.body().rowID, "second");
});
}
+
+test("mobile detached-to-bound navigation hides the old preview before its close animation starts", async () => {
+ const preview = await createPreview(true);
+ assert.equal(await preview.navigate({...preview.data, itemID: "bound", isDetached: false, boundBlockID: "block"}), true);
+ assert.equal(preview.closed(), 1);
+ assert.equal(preview.hiddenOnClose(), true);
+ assert.deepEqual(preview.openedBlocks, ["block"]);
+});
diff --git a/app/src/protyle/render/av/databaseRowNavigation.ts b/app/src/protyle/render/av/databaseRowNavigation.ts
index b1c4731eb6..d4a5ca6625 100644
--- a/app/src/protyle/render/av/databaseRowNavigation.ts
+++ b/app/src/protyle/render/av/databaseRowNavigation.ts
@@ -117,7 +117,7 @@ export const mountDatabaseRowNavigation = (container: Element, data: IDatabaseRo
}
toolbar.setAttribute("data-database-row-navigation", data.itemID);
toolbar.innerHTML = ["previous", "next"].map((name, index) =>
- `<button type="button" data-row-navigation="${name}" disabled class="block__icon block__icon--show ariaLabel" data-position="8south" aria-label="${escapeAttr(window.siyuan.languages[name])}"><svg><use xlink:href="#${index ? "iconDown" : "iconUp"}"></use></svg></button>`)
+ `<button type="button" data-row-navigation="${name}" disabled class="block__icon block__icon--show block__icon--tap ariaLabel" data-position="8south" aria-label="${escapeAttr(window.siyuan.languages[name])}"><svg><use xlink:href="#${index ? "iconDown" : "iconUp"}"></use></svg></button>`)
.join(inline ? "" : '<span class="fn__space"></span>') + (inline ? '<span class="fn__space"></span>' : "");
(inline ? breadcrumb : container).prepend(toolbar);
const buttons = Array.from(toolbar.querySelectorAll("button"));
diff --git a/app/src/protyle/render/av/openDatabaseRow.ts b/app/src/protyle/render/av/openDatabaseRow.ts
index 9f2f1eb128..4c02a3ea04 100644
--- a/app/src/protyle/render/av/openDatabaseRow.ts
+++ b/app/src/protyle/render/av/openDatabaseRow.ts
@@ -58,6 +58,8 @@ const highlightDatabaseRow = (protyle: IProtyle, rootElement: HTMLElement, data:
const closeMobileDatabaseRow = () => {
for (let i = window.siyuan.dialogs.length - 1; i >= 0; i--) {
if (window.siyuan.dialogs[i].element.querySelector(".protyle-db-row--mobile")) {
+ // 条目预览直接替换,隐藏旧弹层后继续执行销毁清理。
+ window.siyuan.dialogs[i].element.classList.add("fn__none");
window.siyuan.dialogs[i].destroy();
break;
}