Skip to content

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

:sparkles: Support database row attributes on mobile https://github.com/siyuan-note/siyuan/issues/11371

Daniel61872c8f8f57
diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scss
index 62a4a3e419..e771c09ecd 100644
--- a/app/src/assets/scss/main/_mobile.scss
+++ b/app/src/assets/scss/main/_mobile.scss
@@ -460,3 +460,60 @@
}
}
}
+
+.protyle-db-attr__header {
+ min-height: 40px;
+}
+
+.av__row-actions {
+ .av__row-action {
+ height: 28px;
+ width: 28px;
+
+ svg {
+ height: 16px;
+ width: 16px;
+ }
+ }
+}
+
+.av__cell[data-dtype="block"]:not(.av__cell--header) {
+ padding-right: 68px;
+
+ & > .av__row-actions {
+ opacity: 1;
+ pointer-events: auto;
+ }
+
+ &[data-align="center"] {
+ padding-left: 68px;
+ }
+
+ &[data-align="right"] {
+ padding-left: 68px;
+ padding-right: 8px;
+ }
+}
+
+.av__cell:not([data-dtype="block"]) .av__row-actions {
+ display: none;
+}
+
+.b3-dialog__container--database-row {
+ background-color: var(--b3-theme-background);
+ border: 0;
+ border-radius: 0;
+ max-width: none;
+}
+
+.protyle-db-row--mobile {
+ min-height: 100%;
+
+ .protyle-db-row__title {
+ padding: 24px 48px 8px 16px;
+ }
+
+ .protyle-db-row__body {
+ margin: 8px;
+ }
+}
diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts
index b6dd12a9a3..4e8e18e031 100644
--- a/app/src/mobile/editor.ts
+++ b/app/src/mobile/editor.ts
@@ -23,7 +23,7 @@ export const getCurrentEditor = () => {
export const openMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL],
scrollPosition?: ScrollLogicalPosition, notebookId?: string,
- afterOpen?: (protyle: IProtyle) => void) => {
+ afterOpen?: (protyle: IProtyle) => void, forceReload = false) => {
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id};
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
const avPanelElement = document.querySelector(".av__panel");
@@ -43,7 +43,7 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[
return true;
}
});
- if (blockElement) {
+ if (blockElement && !forceReload) {
pushBack();
if (action.includes(Constants.CB_GET_HL)) {
highlightById(window.siyuan.mobile.editor.protyle, id, scrollPosition);
@@ -69,6 +69,7 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[
return;
}
const protyleOptions: IProtyleOptions = {
+ databaseAttr: true,
blockId: id,
rootId: data.data.rootID,
notebookId: data.data.box,
diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.ts
index 0c04314629..8d36f181db 100644
--- a/app/src/mobile/util/MobileBackFoward.ts
+++ b/app/src/mobile/util/MobileBackFoward.ts
@@ -116,6 +116,7 @@ const focusStack = (backStack: IBackStack) => {
highlightRender(protyle.wysiwyg.element);
avRender(protyle.wysiwyg.element, protyle);
blockRender(protyle, protyle.wysiwyg.element, backStack.scrollTop);
+ protyle.databaseAttributePanel?.render();
if (getResponse.data.isSyncing) {
disabledForeverProtyle(protyle);
} else {
diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts
index 902620f029..155ca4d135 100644
--- a/app/src/protyle/render/av/action.ts
+++ b/app/src/protyle/render/av/action.ts
@@ -41,7 +41,6 @@ import {clearSelect} from "../../util/clear";
import {removeCompressURL} from "../../../util/image";
import {callMobileAppShowKeyboard} from "../../../mobile/util/mobileAppUtil";
import {createAttributeViewItem, openNewItemTemplateMenu} from "./newItemTemplate";
-/// #if !MOBILE
import {openDatabaseRowByData} from "./openDatabaseRow";
const isDetachedDatabaseCell = (cellElement: HTMLElement) => {
@@ -86,10 +85,13 @@ const openDatabaseRowMore = (protyle: IProtyle, target: HTMLElement) => {
hintRef(textElement.textContent.trim(), protyle, "av");
},
});
+ /// #if MOBILE
+ menu.fullscreen("bottom");
+ /// #else
const rect = target.getBoundingClientRect();
menu.open({x: rect.left, y: rect.bottom, h: rect.height});
+ /// #endif
};
-/// #endif
let foldTimeout: number;
export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => {
@@ -167,7 +169,6 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.preventDefault();
event.stopPropagation();
return true;
- /// #if !MOBILE
} else if (type === "av-row-open") {
openDatabaseRow(protyle, target, blockElement);
event.preventDefault();
@@ -178,18 +179,6 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.preventDefault();
event.stopPropagation();
return true;
- /// #endif
- /// #if MOBILE
- } else if (type === "block-more" && !protyle.disabled) {
- window.siyuan.menus.menu.remove();
- protyle.toolbar.range = document.createRange();
- protyle.toolbar.range.selectNodeContents(target);
- focusByRange(protyle.toolbar.range);
- hintRef(target.previousElementSibling.textContent.trim(), protyle, "av");
- event.preventDefault();
- event.stopPropagation();
- return true;
- /// #endif
} else if (type === "set-page-size" && !protyle.disabled) {
setPageSize({
target,
diff --git a/app/src/protyle/render/av/blockAttr.ts b/app/src/protyle/render/av/blockAttr.ts
index f535ce2a72..ee8f766d54 100644
--- a/app/src/protyle/render/av/blockAttr.ts
+++ b/app/src/protyle/render/av/blockAttr.ts
@@ -17,9 +17,7 @@ import {webUtils} from "electron";
import {isBrowser} from "../../../util/functions";
import {Constants} from "../../../constants";
import {getCompressURL, removeCompressURL} from "../../../util/image";
-/// #if !MOBILE
import {openDatabaseRowByData} from "./openDatabaseRow";
-/// #endif
export const getAVTemplateHTML = (content: string) => {
if (window.siyuan.config.editor.allowHTMLBLockScript) {
@@ -404,7 +402,6 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]
}
const backlinkOpenElement = hasClosestByAttribute(event.target as HTMLElement, "data-type", "av-backlink-open");
if (backlinkOpenElement) {
- /// #if !MOBILE
openDatabaseRowByData(protyle, {
avID: backlinkOpenElement.dataset.avId,
databaseBlockID: backlinkOpenElement.dataset.databaseBlockId,
@@ -415,7 +412,6 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]
boundBlockID: backlinkOpenElement.dataset.boundBlockId,
isDetached: backlinkOpenElement.dataset.detached === "true",
});
- /// #endif
event.stopPropagation();
return;
}
diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts
index 6154601bd1..23401ca07e 100644
--- a/app/src/protyle/render/av/cell.ts
+++ b/app/src/protyle/render/av/cell.ts
@@ -972,12 +972,7 @@ export const renderCell = (cellValue: IAVCellValue, rowIndex = 0, showIcon = tru
} else {
text = `<span class="b3-menu__avemoji${showIcon ? "" : " fn__none"}" data-unicode="${cellValue.block.icon || ""}">${unicode2Emoji(cellValue.block.icon || window.siyuan.storage[Constants.LOCAL_IMAGES].file)}</span><span data-type="block-ref" data-id="${cellValue.block.id}" data-subtype="s" class="av__celltext av__celltext--ref">${Lute.EscapeHTMLStr(cellValue.block.content)}</span>`;
}
- /// #if !MOBILE
text += `<span class="av__row-actions"><button class="av__row-action ariaLabel" type="button" data-position="4north" aria-label="${window.siyuan.languages.openBy}" data-type="av-row-open"><svg><use xlink:href="#iconOpen"></use></svg></button><button class="av__row-action ariaLabel" type="button" data-position="4north" aria-label="${window.siyuan.languages.more}" data-type="av-row-more"><svg><use xlink:href="#iconMore"></use></svg></button></span>`;
- /// #endif
- /// #if MOBILE
- text += `<span class="b3-chip b3-chip--info b3-chip--small" data-type="block-more">${cellValue?.isDetached ? window.siyuan.languages.more : window.siyuan.languages.update}</span>`;
- /// #endif
} else if (cellValue.type === "number") {
text = `<span class="av__celltext" data-content="${cellValue?.number.isNotEmpty ? cellValue?.number.content : ""}">${cellValue?.number.formattedContent || cellValue?.number.content || ""}</span>`;
} else if (cellValue.type === "mSelect" || cellValue.type === "select") {
diff --git a/app/src/protyle/render/av/openDatabaseRow.ts b/app/src/protyle/render/av/openDatabaseRow.ts
index acfa6294aa..68a2b6d315 100644
--- a/app/src/protyle/render/av/openDatabaseRow.ts
+++ b/app/src/protyle/render/av/openDatabaseRow.ts
@@ -1,6 +1,13 @@
+/// #if MOBILE
+import {openMobileFileById} from "../../../mobile/editor";
+import {Dialog} from "../../../dialog";
+import {renderAVAttribute} from "./blockAttr";
+import {Constants} from "../../../constants";
+/// #else
import {openFile, openFileById} from "../../../editor/util";
import {Editor} from "../../../editor";
import {getAllTabs} from "../../../layout/getAll";
+/// #endif
export interface IDatabaseRowOpenData {
avID: string;
@@ -13,6 +20,37 @@ export interface IDatabaseRowOpenData {
isDetached: boolean;
}
+/// #if MOBILE
+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].destroy();
+ break;
+ }
+ }
+};
+
+const openMobileDetachedDatabaseRow = (protyle: IProtyle, data: IDatabaseRowOpenData, title: string) => {
+ closeMobileDatabaseRow();
+ const dialog = new Dialog({
+ content: `<div class="protyle-db-row protyle-db-row--mobile">
+ <div class="protyle-db-row__title"><svg><use xlink:href="#iconDatabase"></use></svg><span></span></div>
+ <div class="custom-attr protyle-db-row__body"></div>
+</div>`,
+ width: "100vw",
+ height: "100dvh",
+ containerClassName: "b3-dialog__container--database-row",
+ disableAnimation: true,
+ });
+ const rowElement = dialog.element.querySelector<HTMLElement>(".protyle-db-row");
+ rowElement.querySelector(".protyle-db-row__title span").textContent = title;
+ renderAVAttribute(rowElement.querySelector<HTMLElement>(".protyle-db-row__body"), data.itemID, protyle, undefined, {
+ avID: data.avID,
+ itemID: data.itemID,
+ valueID: data.valueID,
+ });
+};
+/// #else
const showDatabaseRowPreview = (model: Editor, blockID: string) => {
if (!model?.editor?.protyle) {
return;
@@ -40,9 +78,27 @@ const getDatabaseRowPreviewTab = (blockID: string) => {
}
});
};
+/// #endif
export const openDatabaseRowByData = (protyle: IProtyle, data: IDatabaseRowOpenData) => {
const title = data.title || window.siyuan.languages.untitled;
+ /// #if MOBILE
+ if (data.isDetached) {
+ openMobileDetachedDatabaseRow(protyle, data, title);
+ return;
+ }
+ if (!data.boundBlockID) {
+ return;
+ }
+ closeMobileDatabaseRow();
+ window.siyuan.menus.menu.remove();
+ openMobileFileById(protyle.app, data.boundBlockID, [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS],
+ undefined, undefined, (editorProtyle) => {
+ editorProtyle.element.dataset.databaseRowId = data.boundBlockID;
+ editorProtyle.databaseAttributePanel?.expand();
+ editorProtyle.contentElement.scrollTop = 0;
+ }, true);
+ /// #else
if (data.isDetached) {
if (!data.databaseBlockID) {
return;
@@ -91,4 +147,5 @@ export const openDatabaseRowByData = (protyle: IProtyle, data: IDatabaseRowOpenD
showDatabaseRowPreview(model, data.boundBlockID);
},
});
+ /// #endif
};
diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts
index 6c5b112aa0..76b202d9a1 100644
--- a/app/src/protyle/ui/initUI.ts
+++ b/app/src/protyle/ui/initUI.ts
@@ -23,9 +23,7 @@ import {
isInEmbedBlock
} from "../util/hasClosest";
import {hideElements} from "./hideElements";
-/// #if !MOBILE
import {AVAttributePanel} from "../render/av/attributePanel";
-/// #endif
export const initUI = (protyle: IProtyle) => {
protyle.contentElement = document.createElement("div");
@@ -41,7 +39,6 @@ export const initUI = (protyle: IProtyle) => {
}
}
- /// #if !MOBILE
if (protyle.options.databaseAttr && !protyle.options.action.includes(Constants.CB_GET_HISTORY) && !protyle.options.backlinkData) {
let topElement = protyle.contentElement.querySelector(".protyle-top");
if (!topElement) {
@@ -52,7 +49,6 @@ export const initUI = (protyle: IProtyle) => {
protyle.databaseAttributePanel = new AVAttributePanel(protyle);
topElement.appendChild(protyle.databaseAttributePanel.element);
}
- /// #endif
protyle.contentElement.appendChild(protyle.wysiwyg.element);
if (!protyle.options.action.includes(Constants.CB_GET_HISTORY)) {
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts
index ba71af902d..b564ff431e 100644
--- a/app/src/protyle/util/onGet.ts
+++ b/app/src/protyle/util/onGet.ts
@@ -244,9 +244,7 @@ const setHTML = (options: {
highlightRender(protyle.wysiwyg.element);
avRender(protyle.wysiwyg.element, protyle);
blockRender(protyle, protyle.wysiwyg.element);
- /// #if !MOBILE
protyle.databaseAttributePanel?.render();
- /// #endif
if (options.action.includes(Constants.CB_GET_HISTORY)) {
return;
}