Skip to content

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

:art: Unify mobile database panel handle with menu sheet titles https://github.com/siyuan-note/siyuan/issues/19521

Daniel47c535c0714e
diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scss
index fc98b7f968..f7c965fd68 100644
--- a/app/src/assets/scss/main/_mobile.scss
+++ b/app/src/assets/scss/main/_mobile.scss
@@ -1527,18 +1527,6 @@ body.mobile-topbar--merged {
transform: none;
will-change: auto;
- &::before {
- content: "";
- display: block;
- flex-shrink: 0;
- width: 32px;
- height: 4px;
- margin: 5px auto 7px;
- border-radius: 2px;
- background-color: var(--b3-theme-on-surface-light);
- opacity: .45;
- }
-
> .b3-menu__items {
max-height: none;
min-height: 0;
@@ -1614,10 +1602,17 @@ body.mobile-topbar--merged {
background-color: var(--b3-theme-surface);
border: 0 !important;
- &::before {
+ // 内容标题不绘制抓手,抓手统一由顶部的 --root 标题绘制
+ &:not(.b3-menu__title--root)::before {
content: none;
}
+ &--root {
+ height: 16px;
+ min-height: 0;
+ padding: 0;
+ }
+
> .b3-menu__label {
text-align: left;
color: var(--b3-theme-on-surface-light);
diff --git a/app/src/protyle/render/av/fieldVisibility.ts b/app/src/protyle/render/av/fieldVisibility.ts
index 4df7cf20c5..424b54a083 100644
--- a/app/src/protyle/render/av/fieldVisibility.ts
+++ b/app/src/protyle/render/av/fieldVisibility.ts
@@ -267,10 +267,11 @@ export const openFieldVisibilityPanel = async (options: {
const currentViewID = options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW) ||
options.blockElement.querySelector(".layout-tab-bar .item--focus")?.getAttribute("data-id");
const panelRect = options.menuElement.getBoundingClientRect();
- const previousItemsElement = options.menuElement.firstElementChild;
+ // 移动端菜单顶部会插入抓手标题,按 items 容器判断面板内容是否已被替换
+ const previousItemsElement = options.menuElement.querySelector(":scope > .b3-menu__items");
const views = getSupportedFieldViews(await fetchFieldViews(avID, options.colId), options.field.type);
if (!views || !options.menuElement.isConnected ||
- options.menuElement.firstElementChild !== previousItemsElement) {
+ options.menuElement.querySelector(":scope > .b3-menu__items") !== previousItemsElement) {
return;
}
diff --git a/app/src/protyle/render/av/mobilePanel.test.ts b/app/src/protyle/render/av/mobilePanel.test.ts
index 0714678a13..bff9394856 100644
--- a/app/src/protyle/render/av/mobilePanel.test.ts
+++ b/app/src/protyle/render/av/mobilePanel.test.ts
@@ -11,11 +11,18 @@ const compiled = transpileModule(readFileSync("src/protyle/render/av/mobilePanel
const createPanel = () => {
const listeners = new Map<string, (event: unknown) => void>();
const scrim = {style: {opacity: ""}};
+ const observers: Array<() => void> = [];
const menu = {
style: {height: "", transform: "", transition: ""},
classList: {add() {}},
clientHeight: 400,
offsetHeight: 400,
+ firstElementChild: undefined as undefined | {classList: {contains: (name: string) => boolean}},
+ insertedHTML: [] as string[],
+ insertAdjacentHTML(position: string, html: string) {
+ this.insertedHTML.push(`${position}:${html}`);
+ this.firstElementChild = {classList: {contains: (name: string) => html.includes(name)}};
+ },
querySelectorAll: (): Element[] => [],
querySelector: (): Element => null,
addEventListener: (name: string, listener: (event: unknown) => void) => listeners.set(name, listener),
@@ -37,7 +44,13 @@ const createPanel = () => {
},
performance: {now: () => 1000},
MutationObserver: class {
+ constructor(callback: () => void) {
+ observers.push(callback);
+ }
+
observe() {}
+
+ disconnect() {}
},
CustomEvent: class {},
});
@@ -51,9 +64,20 @@ const createPanel = () => {
listeners.get("touchmove")({touches: [{clientX: 80, clientY: 100 + offset}]});
};
const end = () => listeners.get("touchend")({changedTouches: [{clientY: 300}]});
- return {menu, scrim, drag, end, closes: () => closes};
+ // 触发内容观察者,模拟数据库面板内容整体重绘
+ const rerender = () => observers[0]();
+ return {menu, scrim, drag, end, rerender, closes: () => closes};
};
+test("database panel handle is hosted by a root menu title", () => {
+ const panel = createPanel();
+ assert.deepEqual(panel.menu.insertedHTML,
+ ['afterbegin:<div class="b3-menu__title b3-menu__title--root"></div>']);
+ panel.menu.firstElementChild = undefined;
+ panel.rerender();
+ assert.equal(panel.menu.insertedHTML.length, 2);
+});
+
test("sorting the first view downward does not move or dismiss the database panel", () => {
const panel = createPanel();
panel.drag(true, 200);
diff --git a/app/src/protyle/render/av/mobilePanel.ts b/app/src/protyle/render/av/mobilePanel.ts
index bb9ef28a85..d04103cd73 100644
--- a/app/src/protyle/render/av/mobilePanel.ts
+++ b/app/src/protyle/render/av/mobilePanel.ts
@@ -10,6 +10,10 @@ export const bindMobileAVPanel = (panelElement: HTMLElement, menuElement: HTMLEl
menuElement.style.height = Math.max(window.innerHeight, orientation?.height1 || 0) * .56 + "px";
};
const updateContent = () => {
+ // 抓手统一由 b3-menu__title 的伪元素绘制,与其它底部面板保持一致
+ if (!menuElement.firstElementChild?.classList.contains("b3-menu__title")) {
+ menuElement.insertAdjacentHTML("afterbegin", '<div class="b3-menu__title b3-menu__title--root"></div>');
+ }
// 保留原有节点和事件绑定,标题的返回操作仍由数据库面板处理
menuElement.querySelectorAll(".b3-menu__items, .av__select-list").forEach((itemsElement) => {
const titleElement = itemsElement.firstElementChild;
diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts
index edecefb907..ce4365a617 100644
--- a/app/src/protyle/render/av/openMenuPanel.ts
+++ b/app/src/protyle/render/av/openMenuPanel.ts
@@ -1425,8 +1425,10 @@ export const openMenuPanel = (options: {
window.siyuan.menus.menu.remove();
const editMenuElement = hasClosestByClassName(target, "b3-menu");
if (editMenuElement) {
- editMenuElement.firstElementChild.classList.add("fn__none");
- editMenuElement.lastElementChild.classList.remove("fn__none");
+ // 移动端菜单顶部会插入抓手标题,属性列表和类型列表按 items 容器定位
+ const itemsElements = editMenuElement.querySelectorAll(":scope > .b3-menu__items");
+ itemsElements[0]?.classList.add("fn__none");
+ itemsElements[1]?.classList.remove("fn__none");
}
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);
event.preventDefault();
@@ -1567,8 +1569,10 @@ export const openMenuPanel = (options: {
} else if (type === "goEditCol") {
const editMenuElement = hasClosestByClassName(target, "b3-menu");
if (editMenuElement) {
- editMenuElement.firstElementChild.classList.remove("fn__none");
- editMenuElement.lastElementChild.classList.add("fn__none");
+ // 移动端菜单顶部会插入抓手标题,属性列表和类型列表按 items 容器定位
+ const itemsElements = editMenuElement.querySelectorAll(":scope > .b3-menu__items");
+ itemsElements[0]?.classList.remove("fn__none");
+ itemsElements[1]?.classList.add("fn__none");
}
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);
event.preventDefault();
diff --git a/app/src/protyle/render/av/relation.ts b/app/src/protyle/render/av/relation.ts
index fb68a25fbb..c5f4f120a8 100644
--- a/app/src/protyle/render/av/relation.ts
+++ b/app/src/protyle/render/av/relation.ts
@@ -487,6 +487,8 @@ export const bindRelationEvent = (options: {
}) => {
const inputElement = options.menuElement.querySelector("input");
const listElement = options.menuElement.querySelector(".b3-menu__items") as HTMLElement;
+ // 移动端菜单顶部会插入抓手标题,关联面板根节点按类名定位
+ const relationElement = options.menuElement.querySelector(".av__relation") as HTMLElement;
const measureText = getAVColumnTextMeasurer(options.blockElement as HTMLElement);
const state = {
page: 0,
@@ -681,8 +683,8 @@ ${genRelationLoaderHTML(state.loading, state.loaderVisible)}`;
setLoading(true, initialLoad && reset, controller);
let succeeded = false;
fetchPost("/api/av/getAttributeViewRelationCandidates", {
- avID: options.menuElement.firstElementChild.getAttribute("data-source-av-id"),
- keyID: options.menuElement.firstElementChild.getAttribute("data-key-id"),
+ avID: relationElement.getAttribute("data-source-av-id"),
+ keyID: relationElement.getAttribute("data-key-id"),
keyword,
page,
pageSize: RELATION_PAGE_SIZE,
@@ -698,7 +700,6 @@ ${genRelationLoaderHTML(state.loading, state.loaderVisible)}`;
const databaseName = inputElement.parentElement.parentElement.querySelector(".popover__block");
databaseName.textContent = response.data.name;
databaseName.setAttribute("data-id", response.data.blockIDs?.[0] || "");
- const relationElement = options.menuElement.firstElementChild as HTMLElement;
relationElement.dataset.databaseBlockId = response.data.blockIDs?.[0] || "";
relationElement.dataset.notebookId = response.data.notebookID || "";
const columns = response.data.columns as IAVColumn[] || [];
@@ -794,7 +795,6 @@ ${genRelationLoaderHTML(state.loading, state.loaderVisible)}`;
const rowElement = hasClosestByClassName(openElement, "av__relation-table-row") as HTMLElement;
const primaryElement = rowElement?.querySelector(".av__relation-table-primary") as HTMLElement;
const blockElement = primaryElement?.querySelector(".b3-menu__label") as HTMLElement;
- const relationElement = options.menuElement.firstElementChild as HTMLElement;
if (!rowElement || !primaryElement || !blockElement || !relationElement.dataset.databaseBlockId) {
return;
}
@@ -925,6 +925,8 @@ export const setRelationCell = async (protyle: IProtyle, nodeElement: HTMLElemen
if (menuElement.querySelector(".dragover__bottom, .dragover__top")) {
return;
}
+ // 移动端菜单顶部会插入抓手标题,关联面板根节点按类名定位
+ const relationElement = menuElement.querySelector(".av__relation") as HTMLElement;
if (!nodeElement.contains(cellElements[0])) {
const viewType = nodeElement.getAttribute("data-av-type") as TAVView;
@@ -965,7 +967,7 @@ export const setRelationCell = async (protyle: IProtyle, nodeElement: HTMLElemen
const doOperations: IOperation[] = [{
action: "insertAttrViewBlock",
ignoreDefaultFill: true,
- avID: menuElement.firstElementChild.getAttribute("data-av-id"),
+ avID: relationElement.getAttribute("data-av-id"),
srcs: [{
itemID: rowId,
id: Lute.NewNodeID(),