Skip to content

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

:bug: Preserve content while switching bound database rows https://github.com/siyuan-note/siyuan/issues/20407

Daniel9e63399e48c8
diff --git a/app/src/editor/databaseRowSwitch.test.ts b/app/src/editor/databaseRowSwitch.test.ts
index 5471336c3e..5f2ff09543 100644
--- a/app/src/editor/databaseRowSwitch.test.ts
+++ b/app/src/editor/databaseRowSwitch.test.ts
@@ -17,6 +17,9 @@ const createPreview = async (mobile: boolean) => {
let hidden = false;
let hiddenOnClose = false;
const openedBlocks: string[] = [];
+ let openBound: () => void;
+ let failBound: () => void;
+ let attributesReady: () => void;
class Body {
public isConnected = true;
public style = {};
@@ -77,7 +80,23 @@ const createPreview = async (mobile: boolean) => {
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)},
+ "../../../mobile/editor": {openMobileFileById: (_app: unknown, id: string, _action: unknown,
+ _scroll: unknown, _notebook: unknown,
+ afterOpen: (protyle: unknown) => void,
+ forceReload: boolean, waitForAttributes: boolean) => {
+ assert.equal(forceReload, true);
+ assert.equal(waitForAttributes, true);
+ openedBlocks.push(id);
+ return new Promise<boolean>(resolve => {
+ failBound = () => resolve(false);
+ openBound = () => {
+ afterOpen({element: root, contentElement: content, databaseAttributePanel: {
+ expand() {}, afterRender(callback: () => void) { attributesReady = callback; },
+ }});
+ resolve(true);
+ };
+ });
+ }},
"./databaseRowNavigation": {
getDatabaseRowNavigation: (): undefined => undefined,
mountDatabaseRowNavigation: (_root: unknown, row: IDatabaseRowOpenData,
@@ -146,7 +165,8 @@ 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, hiddenOnClose: () => hiddenOnClose, openedBlocks};
+ mountedRow: () => mountedRow, hiddenOnClose: () => hiddenOnClose, openedBlocks,
+ openBound: () => openBound(), failBound: () => failBound(), attributesReady: () => attributesReady()};
};
for (const mobile of [false, true]) {
@@ -185,10 +205,24 @@ for (const mobile of [false, true]) {
});
}
-test("mobile detached-to-bound navigation hides the old preview before its close animation starts", async () => {
+test("mobile detached-to-bound navigation keeps the preview until the target attributes are ready", async () => {
const preview = await createPreview(true);
- assert.equal(await preview.navigate({...preview.data, itemID: "bound", isDetached: false, boundBlockID: "block"}), true);
+ const switching = preview.navigate({...preview.data, itemID: "bound", isDetached: false, boundBlockID: "block"});
+ assert.equal(preview.closed(), 0);
+ preview.openBound();
+ assert.equal(preview.closed(), 0);
+ preview.attributesReady();
+ assert.equal(await switching, true);
assert.equal(preview.closed(), 1);
assert.equal(preview.hiddenOnClose(), true);
assert.deepEqual(preview.openedBlocks, ["block"]);
});
+
+test("mobile failed bound navigation retains the detached preview", async () => {
+ const preview = await createPreview(true);
+ const switching = preview.navigate({...preview.data, itemID: "bound", isDetached: false, boundBlockID: "block"});
+ preview.failBound();
+ assert.equal(await switching, false);
+ assert.equal(preview.closed(), 0);
+ assert.equal(preview.body().rowID, "first");
+});
diff --git a/app/src/mobile/editor.scroll.test.ts b/app/src/mobile/editor.scroll.test.ts
index 8f7e64b9b5..9046876f0a 100644
--- a/app/src/mobile/editor.scroll.test.ts
+++ b/app/src/mobile/editor.scroll.test.ts
@@ -51,10 +51,12 @@ const setup = (legacy?: IScrollAttr, encrypted = false) => {
const requests: Array<{url: string, data: any}> = [];
const rendered: Array<{scrollAttr?: IScrollAttr}> = [];
const constructed: IProtyleOptions[] = [];
+ const presentation: string[] = [];
+ const attributes: Array<(ready: boolean) => void> = [];
const toolbar = {value: "Document"};
const window: any = {siyuan: {
storage: {positions: {root: clone(legacy)}},
- config: {editor: {dynamicLoadBlocks: 128}, fileTree: {}}, mobile: {},
+ config: {editor: {dynamicLoadBlocks: 128, databaseAttrShow: true}, fileTree: {}}, mobile: {},
}};
const document = {querySelector: (): null => null,
getElementById: (id: string) => id === "toolbarName" ? toolbar : {}};
@@ -63,10 +65,11 @@ const setup = (legacy?: IScrollAttr, encrypted = false) => {
element: {querySelector: (): null => null, classList: {remove: noop}},
options: {mode: "wysiwyg"}, notebookId: options.notebookId, path: "/root.sy",
block: {id: options.blockId, rootID: options.rootId},
- title: {element: {removeAttribute: noop}},
+ title: {element: {removeAttribute: () => presentation.push("title")}},
+ databaseAttributePanel: {},
contentElement: {scrollTop: 0, classList: {contains: () => false}},
wysiwyg: {element: {querySelectorAll: (): Element[] => [], childElementCount: 1}},
- undo: {clear: noop},
+ undo: {clear: () => presentation.push("undo")},
});
const fetchPost = (url: string, data: any, callback?: (response: any) => void) => {
requests.push({url, data: clone(data)});
@@ -74,6 +77,7 @@ const setup = (legacy?: IScrollAttr, encrypted = false) => {
return Promise.resolve();
};
const onGet = (options: any) => {
+ presentation.push("document");
rendered.push({scrollAttr: clone(options.scrollAttr)});
options.protyle.contentElement.scrollTop = options.scrollAttr?.scrollTop ?? 0;
options.afterCB?.();
@@ -116,15 +120,19 @@ const setup = (legacy?: IScrollAttr, encrypted = false) => {
"../protyle": {Protyle},
"../util/fetch": {fetchPost},
"../util/pathName": {isEncryptedBox: (id: string) => id === "encrypted-box"},
+ "../protyle/util/onGet": {onGet},
"../protyle/scroll/saveScroll": {getDocByScroll: scroll.getDocByScroll, saveScroll: noop},
"../protyle/ui/hideElements": {hideElements: noop},
- "../protyle/ui/initUI": {addLoading: noop},
+ "../protyle/ui/initUI": {addLoading: () => presentation.push("loading")},
+ "../protyle/render/av/attributePanel": {prepareDatabaseAttributePanel: () => new Promise(resolve => {
+ attributes.push(ready => resolve(ready ? () => presentation.push("attributes") : undefined));
+ })},
"../protyle/util/trackedRange": {invalidateTrackedRanges: noop},
"../protyle/undo/globalUndo": {initMirror: noop},
"../protyle/render/av/cellEditor": {closeAVCellEditor: noop},
"../protyle/render/av/databaseRowNavigation": execute(compile(read("../protyle/render/av/databaseRowNavigation.ts")), {}),
"../plugin/EventBusCore": {forEachPluginSubscriber: noop},
- "./util/setEmpty": {setEditor: noop},
+ "./util/setEmpty": {setEditor: (visible = true) => presentation.push(visible ? "show" : "hide")},
"./util/closePanel": {closePanel: noop},
"./util/mobileBars": {bindMobileBarsScroll: noop},
"./util/mobileTopBar": {restoreMobileTopBarLayout: noop},
@@ -135,7 +143,15 @@ const setup = (legacy?: IScrollAttr, encrypted = false) => {
loader.loadMobileFileById({}, "root", [constants.CB_GET_SCROLL], undefined, notebookID, resolve,
true, () => true, undefined, scrollAttr, false, () => reject(new Error("Loading failed")));
});
- return {load, requests, rendered, constructed, window,
+ const switchRow = (id: string, isValid = () => true) => new Promise<boolean>(resolve => {
+ loader.loadMobileFileById({}, id, [constants.CB_GET_ALL, constants.CB_GET_FOCUS], undefined, notebookID,
+ () => resolve(true), true, isValid, undefined, undefined, false,
+ (_invalid: boolean, unchanged: boolean) => {
+ assert.equal(unchanged, true);
+ resolve(false);
+ }, false, true);
+ });
+ return {load, switchRow, requests, rendered, constructed, window, presentation, attributes,
get docRequest() { return requests.filter(item => item.url === "/api/filetree/getDoc").at(-1)?.data; }};
};
@@ -204,3 +220,37 @@ test("explicit mobile scroll restoration retains encrypted notebook request scop
assert.equal(state.docRequest.notebook, "encrypted-box");
assert.deepEqual(state.rendered[0].scrollAttr, scroll);
});
+
+test("mobile bound navigation preserves the visible document until attributes are ready", async () => {
+ const state = setup(undefined, true);
+ const protyle = await state.load();
+ protyle.contentElement.scrollTop = 456;
+ state.presentation.length = 0;
+ const switching = state.switchRow("bound");
+ assert.deepEqual(state.presentation, []);
+ assert.equal(protyle.contentElement.scrollTop, 456);
+ assert.equal(state.docRequest.notebook, "encrypted-box");
+ state.attributes[0](true);
+ assert.equal(await switching, true);
+ assert.deepEqual(state.presentation, ["attributes", "title", "undo", "document", "show"]);
+});
+
+test("mobile failed or superseded attribute preparation cannot replace the current document", async () => {
+ const state = setup();
+ await state.load();
+ state.presentation.length = 0;
+ const failed = state.switchRow("missing");
+ state.attributes[0](false);
+ assert.equal(await failed, false);
+ assert.deepEqual(state.presentation, []);
+ let valid = true;
+ const stale = state.switchRow("stale", () => valid);
+ valid = false;
+ const latest = state.switchRow("latest");
+ state.attributes[2](true);
+ assert.equal(await latest, true);
+ const committed = [...state.presentation];
+ state.attributes[1](true);
+ assert.equal(await stale, false);
+ assert.deepEqual(state.presentation, committed);
+});
diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts
index 7643f9449d..b611eeb0f0 100644
--- a/app/src/mobile/editor.ts
+++ b/app/src/mobile/editor.ts
@@ -27,6 +27,7 @@ import {closeMobileEditorSheets} from "./util/MobileEditorDialog";
import {invalidateMobileReferenceOpen} from "./util/openReference";
import {closeAVCellEditor} from "../protyle/render/av/cellEditor";
import {clearDatabaseRowNavigation} from "../protyle/render/av/databaseRowNavigation";
+import {prepareDatabaseAttributePanel} from "../protyle/render/av/attributePanel";
export const getCurrentEditor = () => {
return getActiveMobileSecondaryEditor() || window.siyuan.mobile.popEditor || window.siyuan.mobile.editor;
@@ -71,14 +72,15 @@ export const loadMobileFileById = (app: App, id: string, action: TProtyleAction[
afterOpen?: (protyle: IProtyle) => void, forceReload = false,
isValid: () => boolean = () => true, signal?: AbortSignal,
scrollAttr?: IScrollAttr, updateRecent = true,
- onFailure?: (invalid?: boolean, editorUnchanged?: boolean) => void, keepPanels = false) => {
+ onFailure?: (invalid?: boolean, editorUnchanged?: boolean) => void, keepPanels = false,
+ waitForDatabaseAttributes = false) => {
invalidateMobileReferenceOpen();
const closing = closeMobileEditorSheets();
if (closing) {
void closing.then(() => {
if (isValid() && !signal?.aborted) {
loadMobileFileById(app, id, action, scrollPosition, notebookId, afterOpen, forceReload,
- isValid, signal, scrollAttr, updateRecent, onFailure, keepPanels);
+ isValid, signal, scrollAttr, updateRecent, onFailure, keepPanels, waitForDatabaseAttributes);
} else {
onFailure?.(undefined, true);
}
@@ -237,13 +239,23 @@ export const loadMobileFileById = (app: App, id: string, action: TProtyleAction[
complete(editor.protyle);
},
};
- setEditor(false);
- titleHidden = true;
+ const preserveContent = waitForDatabaseAttributes && window.siyuan.config.editor.databaseAttrShow &&
+ !!window.siyuan.mobile.editor?.protyle.databaseAttributePanel && !actionList.includes(Constants.CB_GET_SCROLL);
+ if (!preserveContent) {
+ setEditor(false);
+ titleHidden = true;
+ }
if (window.siyuan.mobile.editor) {
- invalidateTrackedRanges(window.siyuan.mobile.editor.protyle);
- window.siyuan.mobile.editor.protyle.notebookId = data.data.box;
- window.siyuan.mobile.editor.protyle.title.element.removeAttribute("data-render");
- addLoading(window.siyuan.mobile.editor.protyle);
+ const editor = window.siyuan.mobile.editor;
+ const prepareEditor = () => {
+ invalidateTrackedRanges(editor.protyle);
+ editor.protyle.notebookId = data.data.box;
+ editor.protyle.title.element.removeAttribute("data-render");
+ };
+ if (!preserveContent) {
+ prepareEditor();
+ addLoading(editor.protyle);
+ }
// 保留正文直到新文档返回,跨文档切换时显式更新只读状态
const updateReadonly = previousRootID !== data.data.rootID ? true : undefined;
const targetScrollAttr = scrollAttr || window.siyuan.storage[Constants.LOCAL_FILEPOSITION][data.data.rootID];
@@ -277,11 +289,11 @@ export const loadMobileFileById = (app: App, id: string, action: TProtyleAction[
size: actionList.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
mode: actionList.includes(Constants.CB_GET_CONTEXT) ? 3 : 0,
};
- if (isEncryptedBox(window.siyuan.mobile.editor.protyle.notebookId)) {
- getDocParam.notebook = window.siyuan.mobile.editor.protyle.notebookId;
+ if (isEncryptedBox(data.data.box)) {
+ getDocParam.notebook = data.data.box;
}
let getDocHandled = false;
- void fetchPost("/api/filetree/getDoc", getDocParam, getResponse => {
+ void fetchPost("/api/filetree/getDoc", getDocParam, async getResponse => {
getDocHandled = true;
if (!isValid()) {
fail();
@@ -292,6 +304,17 @@ export const loadMobileFileById = (app: App, id: string, action: TProtyleAction[
return;
}
try {
+ if (preserveContent) {
+ const prepared = await prepareDatabaseAttributePanel(editor.protyle, id);
+ if (!prepared || !isValid() || window.siyuan.mobile.editor !== editor) {
+ fail();
+ return;
+ }
+ prepared();
+ prepareEditor();
+ editor.protyle.undo.clear();
+ titleHidden = true;
+ }
onGet({
data: getResponse,
protyle: window.siyuan.mobile.editor.protyle,
@@ -323,7 +346,9 @@ export const loadMobileFileById = (app: App, id: string, action: TProtyleAction[
}
});
}
- window.siyuan.mobile.editor.protyle.undo.clear();
+ if (!preserveContent) {
+ editor.protyle.undo.clear();
+ }
// 切换文档后校准新文档的撤销镜像(语义 B:各文档栈隔离)
if (window.siyuan.mobile.editor.protyle.block?.rootID) {
initMirror(window.siyuan.mobile.editor.protyle.block.rootID);
@@ -350,33 +375,35 @@ export const loadMobileFileById = (app: App, id: string, action: TProtyleAction[
export const openMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL],
scrollPosition?: ScrollLogicalPosition, notebookId?: string,
- afterOpen?: (protyle: IProtyle) => void, forceReload = false) => {
+ afterOpen?: (protyle: IProtyle) => void, forceReload = false,
+ waitForDatabaseAttributes = false): Promise<boolean> => {
const closing = closeMobileEditorSheets();
if (closing) {
- void closing.then(() => openMobileFileById(app, id, action, scrollPosition, notebookId, afterOpen, forceReload))
- .catch(error => console.error(error));
- return;
+ return closing.then(() => openMobileFileById(app, id, action, scrollPosition, notebookId, afterOpen,
+ forceReload, waitForDatabaseAttributes)).catch(error => {
+ console.error(error);
+ return false;
+ });
}
if (window.siyuan.mobile.tabs) {
- const options = {action, scrollPosition, notebookId, afterOpen, forceReload};
- if (action.includes(Constants.CB_GET_OPENNEW)) {
- void window.siyuan.mobile.tabs.openInNewTab(id, options).then((result) => {
- if (result === "invalid" || result === "failed") {
- void window.siyuan.mobile.tabs.restore();
- }
- });
- } else {
- void window.siyuan.mobile.tabs.open(id, options).then((result) => {
- if (result === "invalid" || result === "failed") {
- void window.siyuan.mobile.tabs.restore();
- }
- });
- }
- return;
+ const options = {action, scrollPosition, notebookId, afterOpen, forceReload, waitForDatabaseAttributes};
+ const opening = action.includes(Constants.CB_GET_OPENNEW) ?
+ window.siyuan.mobile.tabs.openInNewTab(id, options) : window.siyuan.mobile.tabs.open(id, options);
+ return opening.then(result => {
+ if ((result === "invalid" || result === "failed") && !waitForDatabaseAttributes) {
+ void window.siyuan.mobile.tabs.restore();
+ }
+ return result === "success";
+ });
}
window.siyuan.storage[Constants.LOCAL_DOCINFO] = isEncryptedBox(notebookId) ? {id: ""} : {id};
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
- loadMobileFileById(app, id, action, scrollPosition, notebookId, afterOpen, forceReload);
+ return new Promise<boolean>(resolve => {
+ loadMobileFileById(app, id, action, scrollPosition, notebookId, protyle => {
+ afterOpen?.(protyle);
+ resolve(true);
+ }, forceReload, undefined, undefined, undefined, true, () => resolve(false), false, waitForDatabaseAttributes);
+ });
};
export const openMobileFileByIdInNewTab = (app: App, id: string,
diff --git a/app/src/mobile/tabs/MobileTabs.ts b/app/src/mobile/tabs/MobileTabs.ts
index f4431dbc3b..df1748dfd8 100644
--- a/app/src/mobile/tabs/MobileTabs.ts
+++ b/app/src/mobile/tabs/MobileTabs.ts
@@ -63,6 +63,7 @@ type OpenOptions = {
recentPreviousRootID?: string;
recordActivation?: boolean;
keepPanels?: boolean;
+ waitForDatabaseAttributes?: boolean;
};
type MobileTabOpenResult = "success" | "cancelled" | "invalid" | "failed";
@@ -478,7 +479,7 @@ export class MobileTabs {
this.renderedEntry = renderedEntry;
}
finish(abortController.signal.aborted ? "cancelled" : (invalid ? "invalid" : "failed"));
- }, options.keepPanels);
+ }, options.keepPanels, options.waitForDatabaseAttributes);
});
}
diff --git a/app/src/protyle/render/av/attributePanel.ts b/app/src/protyle/render/av/attributePanel.ts
index fbbb1ebf8f..f685115e19 100644
--- a/app/src/protyle/render/av/attributePanel.ts
+++ b/app/src/protyle/render/av/attributePanel.ts
@@ -12,6 +12,29 @@ const updateEmptyState = (element: HTMLElement, hideEmpty: boolean) => {
element.classList.toggle("protyle-db-attr--hide-empty", hideEmpty);
};
+const preparedBodies = new WeakMap<IProtyle, {id: string, element: HTMLElement}>();
+
+// 在替换正文前准备属性,提交时由同一个编辑器接管事件和只读状态。
+export const prepareDatabaseAttributePanel = (protyle: IProtyle, id: string) => {
+ return new Promise<(() => void) | undefined>(resolve => {
+ const element = document.createElement("div");
+ element.className = "custom-attr protyle-db-attr__body";
+ let finished = false;
+ const timeout = window.setTimeout(() => {
+ finished = true;
+ resolve(undefined);
+ }, 60000);
+ renderAVAttribute(element, id, protyle, rendered => {
+ if (finished) {
+ return;
+ }
+ finished = true;
+ window.clearTimeout(timeout);
+ resolve(() => preparedBodies.set(protyle, {id, element: rendered}));
+ });
+ });
+};
+
const refreshActions = new Set<TOperation>([
"addAttrViewCol",
"removeAttrViewCol",
@@ -90,7 +113,9 @@ export class AVAttributePanel {
return;
}
const targetID = this.protyle.block.showAll ? this.protyle.block.id : this.protyle.block.rootID;
- if (!targetID || (!force && targetID === this.targetID &&
+ const prepared = preparedBodies.get(this.protyle);
+ preparedBodies.delete(this.protyle);
+ if (!targetID || (!force && prepared?.id !== targetID && targetID === this.targetID &&
(this.element.dataset.rendered === "true" || this.renderingTargetID === targetID))) {
return;
}
@@ -113,14 +138,14 @@ export class AVAttributePanel {
currentBodyElement.replaceWith(bodyElement);
this.bodyElement = bodyElement;
}
- renderAVAttribute(bodyElement, targetID, this.protyle, (renderedElement) => {
+ const rendered = (renderedElement: HTMLElement) => {
if (token !== this.renderToken) {
return;
}
this.renderingTargetID = "";
- if (keepCurrentBody) {
+ if (keepCurrentBody || renderedElement !== bodyElement) {
this.updateCollapsedState();
- currentBodyElement.replaceWith(renderedElement);
+ this.bodyElement.replaceWith(renderedElement);
this.bodyElement = renderedElement;
}
this.element.dataset.rendered = "true";
@@ -129,7 +154,12 @@ export class AVAttributePanel {
this.element.classList.toggle("fn__none", !renderedElement.querySelector("[data-av-id], .custom-attr__avbacklinks"));
const callbacks = this.renderCallbacks.splice(0);
callbacks.forEach(callback => callback(this.bodyElement));
- });
+ };
+ if (prepared?.id === targetID) {
+ rendered(prepared.element);
+ } else {
+ renderAVAttribute(bodyElement, targetID, this.protyle, rendered);
+ }
}
public afterRender(callback: (element: HTMLElement) => void) {
@@ -172,6 +202,10 @@ export class AVAttributePanel {
this.bodyElement.querySelectorAll<HTMLInputElement | HTMLTextAreaElement>("input, textarea").forEach(item => {
item.readOnly = Boolean(this.protyle.disabled);
});
+ this.bodyElement.querySelectorAll<HTMLButtonElement>('[data-type="av-bind-document"]').forEach(item => {
+ item.disabled = Boolean(this.protyle.disabled || window.siyuan.isPublish ||
+ this.protyle.options.history?.created || this.protyle.options.history?.snapshot);
+ });
this.element.querySelectorAll<HTMLElement>('[data-type="av-tab"]').forEach(item => {
item.draggable = !this.protyle.disabled;
});
diff --git a/app/src/protyle/render/av/attributePanelVisibility.test.ts b/app/src/protyle/render/av/attributePanelVisibility.test.ts
index 3e9836993c..107c34e414 100644
--- a/app/src/protyle/render/av/attributePanelVisibility.test.ts
+++ b/app/src/protyle/render/av/attributePanelVisibility.test.ts
@@ -8,7 +8,7 @@ import {promisify} from "node:util";
import {ScriptTarget, transpileModule} from "typescript";
import {compileString} from "sass";
-const browserCases = (source: string, css: string, columnSource: string, blockSource: string, menuSource: string, calendarSource: string) => {
+const browserCases = async (source: string, css: string, columnSource: string, blockSource: string, menuSource: string, calendarSource: string) => {
const check: typeof assert = require("node:assert/strict");
const config = {editor: {databaseAttrShow: true, databaseAttrHideEmpty: false, databaseAttrViewMode: 0, databaseAttrUseTabs: false}};
Object.assign(window, {siyuan: {config, languages: {
@@ -63,6 +63,46 @@ const browserCases = (source: string, css: string, columnSource: string, blockSo
check.equal(visible("hidden"), true, "readonly panels can reveal fields");
panel.element.remove();
}
+ const pending: Array<() => void> = [];
+ const preparedAPI = new Function("cancelHeightAnimation", "renderAVAttribute", source +
+ "\nreturn {AVAttributePanel, prepareDatabaseAttributePanel};")(() => {},
+ (element: HTMLElement, id: string, _protyle: unknown, callback: (element: HTMLElement) => void) => {
+ pending.push(() => {
+ element.innerHTML = `<div data-av-id="database">${id}<button data-type="av-bind-document"></button></div>`;
+ callback(element);
+ });
+ });
+ const bound = {disabled: false, options: {}, block: {showAll: true, id: "first"}};
+ const boundPanel = new preparedAPI.AVAttributePanel(bound);
+ document.body.append(boundPanel.element);
+ boundPanel.render();
+ pending.shift()();
+ const firstBody = boundPanel.element.querySelector(".protyle-db-attr__body");
+ const preparing = preparedAPI.prepareDatabaseAttributePanel(bound, "second");
+ check.equal(boundPanel.element.querySelector(".protyle-db-attr__body"), firstBody);
+ check.equal(firstBody.textContent, "first");
+ pending.shift()();
+ const commit = await preparing;
+ check.equal(firstBody.isConnected, true, "preparation does not remove the visible body");
+ commit();
+ bound.block.id = "second";
+ boundPanel.render();
+ check.equal(pending.length, 0, "committing must not start another asynchronous attribute request");
+ check.equal(firstBody.isConnected, false);
+ check.equal(boundPanel.element.querySelector(".protyle-db-attr__body").textContent, "second");
+ let ready = false;
+ boundPanel.afterRender(() => { ready = true; });
+ check.equal(ready, true, "the new body is ready in the same turn as the document");
+ bound.disabled = true;
+ boundPanel.updateReadonly();
+ check.equal(boundPanel.element.querySelector('[data-type="av-bind-document"]').disabled, true);
+ bound.disabled = false;
+ boundPanel.updateReadonly();
+ check.equal(boundPanel.element.querySelector('[data-type="av-bind-document"]').disabled, false);
+ boundPanel.render(true);
+ check.equal(pending.length, 1, "subsequent refreshes request fresh attributes");
+ pending.shift()();
+ boundPanel.element.remove();
const transactions: unknown[][] = [];
const escape = (value: string) => value || "";
let mobile = false;
diff --git a/app/src/protyle/render/av/openDatabaseRow.ts b/app/src/protyle/render/av/openDatabaseRow.ts
index 4c02a3ea04..36f617ce57 100644
--- a/app/src/protyle/render/av/openDatabaseRow.ts
+++ b/app/src/protyle/render/av/openDatabaseRow.ts
@@ -369,9 +369,8 @@ export const openDatabaseRowByData = async (protyle: Pick<IProtyle, "app">, data
if (!data.boundBlockID) {
return false;
}
- closeMobileDatabaseRow();
window.siyuan.menus.menu.remove();
- openMobileFileById(protyle.app, data.boundBlockID, [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS],
+ return openMobileFileById(protyle.app, data.boundBlockID, [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS],
undefined, undefined, (editorProtyle) => {
inheritDatabaseRowReadonly(editorProtyle, protyle);
editorProtyle.element.dataset.databaseRowId = data.boundBlockID;
@@ -380,11 +379,11 @@ export const openDatabaseRowByData = async (protyle: Pick<IProtyle, "app">, data
editorProtyle.databaseAttributePanel?.expand(data.avID);
editorProtyle.contentElement.scrollTop = 0;
editorProtyle.databaseAttributePanel?.afterRender(() => {
+ closeMobileDatabaseRow();
highlightDatabaseRow(editorProtyle, editorProtyle.contentElement, data);
focusDatabasePrimary(editorProtyle.contentElement, editorProtyle, data);
});
- }, true);
- return true;
+ }, true, true);
/// #else
if (openStandalone) {
if (!data.databaseBlockID) {