An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Align mobile database panels with menu sheet styles and gestures https://github.com/siyuan-note/siyuan/issues/19207
Danielfeb740f56419
diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scssindex c13d6002f5..bd6a3aed81 100644--- a/app/src/assets/scss/main/_mobile.scss+++ b/app/src/assets/scss/main/_mobile.scss@@ -1463,21 +1463,60 @@ body.mobile-topbar--merged {width: auto !important;min-width: 0 !important;max-width: none !important;- height: 56vh;max-height: 90vh !important;max-height: 90dvh !important;box-sizing: border-box;border: 0;border-radius: var(--b3-border-radius-b) var(--b3-border-radius-b) 0 0;- padding: 16px 8px max(16px, env(safe-area-inset-bottom));- overflow: auto;- overscroll-behavior: contain;- animation: bottom2Top .15s cubic-bezier(0, 0, .2, 1);+ padding: 0;+ background-color: var(--b3-theme-surface);+ // 固定定位的下拉列表仍以视口为参照,滚动和裁剪仅作用于内容区域+ overflow: visible;+ 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;}++ .b3-menu__title {+ flex-shrink: 0;+ height: auto;+ min-height: 40px;+ padding: 0 8px;+ background-color: var(--b3-theme-surface);+ border: 0 !important;++ &::before {+ content: none;+ }++ > .b3-menu__label {+ text-align: left;+ color: var(--b3-theme-on-surface-light);+ }++ > .block__icon {+ color: var(--b3-theme-on-surface-light);+ }++ + .b3-menu__separator {+ height: 8px;+ }+ }}}diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.tsindex c6991d02ee..bd1eba45a0 100644--- a/app/src/menus/Menu.ts+++ b/app/src/menus/Menu.ts@@ -1,6 +1,7 @@import {getEventName, updateHotkeyTip} from "../protyle/util/compatibility";import {setPosition} from "../util/setPosition";import {getAnchoredMenuPosition} from "./menuPosition";+import {updateMenuItemGroupClasses} from "./menuGroup";import {hasClosestByClassName} from "../protyle/util/hasClosest";import {isMobile} from "../util/functions";import {Constants} from "../constants";@@ -17,39 +18,6 @@ const CUSTOM_EVENT_LOAD_SUBMENU = "load-submenu";let fullscreenCloseTimeout: number;let fullscreenScrimHideTimeout: number;-const updateMenuItemGroupClasses = (itemsElement: Element) => {- const itemElements = Array.from(itemsElement.children).filter((element) =>- element.classList.contains("b3-menu__item")) as HTMLElement[];- itemElements.forEach((element) => {- element.classList.remove("b3-menu__item--group-first", "b3-menu__item--group-last");- });- if (itemElements.length === 0) {- itemsElement.classList.remove("b3-menu__items--menu");- return;- }- itemsElement.classList.add("b3-menu__items--menu");- let groupElements: HTMLElement[] = [];- const updateGroup = () => {- if (groupElements.length === 0) {- return;- }- groupElements[0].classList.add("b3-menu__item--group-first");- groupElements[groupElements.length - 1].classList.add("b3-menu__item--group-last");- groupElements = [];- };- Array.from(itemsElement.children).forEach((element: HTMLElement) => {- if (element.classList.contains("fn__none")) {- return;- }- if (element.classList.contains("b3-menu__separator")) {- updateGroup();- } else if (element.classList.contains("b3-menu__item")) {- groupElements.push(element);- }- });- updateGroup();-};-const applyMenuConfig = (menuElement: HTMLElement) => {/// #if !MOBILEapplyMenuEntryVisibility(menuElement);diff --git a/app/src/menus/menuGroup.test.ts b/app/src/menus/menuGroup.test.tsnew file mode 100644index 0000000000..0db23b2c89--- /dev/null+++ b/app/src/menus/menuGroup.test.ts@@ -0,0 +1,53 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {updateMenuItemGroupClasses} from "./menuGroup";++const element = (...classes: string[]) => {+ const values = new Set(classes);+ return {+ classList: {+ add: (...names: string[]) => names.forEach(name => values.add(name)),+ remove: (...names: string[]) => names.forEach(name => values.delete(name)),+ contains: (name: string) => values.has(name),+ },+ } as unknown as HTMLElement;+};++const items = (...children: HTMLElement[]) => Object.assign(element(), {children});++describe("menu groups", () => {+ it("keeps database navigation titles outside rounded action groups", () => {+ const title = element("b3-menu__item", "b3-menu__title");+ const first = element("b3-menu__item");+ const last = element("b3-menu__item");+ updateMenuItemGroupClasses(items(title, first, last));+ assert.equal(title.classList.contains("b3-menu__item--group-first"), false);+ assert.equal(first.classList.contains("b3-menu__item--group-first"), true);+ assert.equal(last.classList.contains("b3-menu__item--group-last"), true);+ });++ it("moves rounded edges when the final action is hidden and restored", () => {+ const first = element("b3-menu__item");+ const last = element("b3-menu__item");+ const container = items(first, last);+ updateMenuItemGroupClasses(container);+ last.classList.add("fn__none");+ updateMenuItemGroupClasses(container);+ assert.equal(first.classList.contains("b3-menu__item--group-last"), true);+ assert.equal(last.classList.contains("b3-menu__item--group-last"), false);+ last.classList.remove("fn__none");+ updateMenuItemGroupClasses(container);+ assert.equal(first.classList.contains("b3-menu__item--group-last"), false);+ assert.equal(last.classList.contains("b3-menu__item--group-last"), true);+ });++ it("preserves separate action groups across separators", () => {+ const first = element("b3-menu__item");+ const second = element("b3-menu__item");+ updateMenuItemGroupClasses(items(first, element("b3-menu__separator"), second));+ for (const item of [first, second]) {+ assert.equal(item.classList.contains("b3-menu__item--group-first"), true);+ assert.equal(item.classList.contains("b3-menu__item--group-last"), true);+ }+ });+});diff --git a/app/src/menus/menuGroup.ts b/app/src/menus/menuGroup.tsnew file mode 100644index 0000000000..ca538b9ee9--- /dev/null+++ b/app/src/menus/menuGroup.ts@@ -0,0 +1,32 @@+export const updateMenuItemGroupClasses = (itemsElement: Element) => {+ const itemElements = Array.from(itemsElement.children).filter((element) =>+ element.classList.contains("b3-menu__item")) as HTMLElement[];+ itemElements.forEach((element) => {+ element.classList.remove("b3-menu__item--group-first", "b3-menu__item--group-last");+ });+ if (itemElements.length === 0) {+ itemsElement.classList.remove("b3-menu__items--menu");+ return;+ }+ itemsElement.classList.add("b3-menu__items--menu");+ let groupElements: HTMLElement[] = [];+ const updateGroup = () => {+ if (groupElements.length === 0) {+ return;+ }+ groupElements[0].classList.add("b3-menu__item--group-first");+ groupElements[groupElements.length - 1].classList.add("b3-menu__item--group-last");+ groupElements = [];+ };+ Array.from(itemsElement.children).forEach((element: HTMLElement) => {+ if (element.classList.contains("fn__none")) {+ return;+ }+ if (element.classList.contains("b3-menu__separator") || element.classList.contains("b3-menu__title")) {+ updateGroup();+ } else if (element.classList.contains("b3-menu__item")) {+ groupElements.push(element);+ }+ });+ updateGroup();+};diff --git a/app/src/protyle/render/av/mobilePanel.ts b/app/src/protyle/render/av/mobilePanel.tsnew file mode 100644index 0000000000..51a017d8a1--- /dev/null+++ b/app/src/protyle/render/av/mobilePanel.ts@@ -0,0 +1,118 @@+import {updateMenuItemGroupClasses} from "../../../menus/menuGroup";++export const bindMobileAVPanel = (panelElement: HTMLElement, menuElement: HTMLElement) => {+ menuElement.classList.add("b3-menu--fullscreen", "b3-menu--sheet");+ const scrimElement = panelElement.querySelector<HTMLElement>(".b3-dialog__scrim");+ const updateHeight = () => {+ const size = window.siyuan.mobile.size;+ const orientation = size.isLandscape ? size.landscape : size.portrait;+ menuElement.style.height = Math.max(window.innerHeight, orientation?.height1 || 0) * .56 + "px";+ };+ const updateContent = () => {+ // 保留原有节点和事件绑定,标题的返回操作仍由数据库面板处理+ menuElement.querySelectorAll(".b3-menu__items").forEach((itemsElement) => {+ const titleElement = itemsElement.firstElementChild;+ if (titleElement?.matches('[data-type="nobg"]') &&+ titleElement.querySelector(":scope > .b3-menu__label.ft__center")) {+ titleElement.classList.add("b3-menu__title");+ }+ updateMenuItemGroupClasses(itemsElement);+ });+ };+ const contentObserver = new MutationObserver(() => {+ // 分组类更新不再次触发自身,页面替换和显隐切换都需要重新分组+ contentObserver.disconnect();+ updateContent();+ observeContent();+ });+ const observeContent = () => contentObserver.observe(menuElement, {+ childList: true,+ subtree: true,+ attributes: true,+ attributeFilter: ["class"],+ });+ updateHeight();+ updateContent();+ observeContent();+ window.addEventListener("resize", updateHeight);++ let start: {x: number, y: number, time: number};+ let dragging = false;+ let suppressClickUntil = 0;+ const reset = () => {+ start = undefined;+ dragging = false;+ menuElement.style.transform = "";+ menuElement.style.transition = "";+ scrimElement.style.opacity = "";+ };+ menuElement.addEventListener("touchstart", (event) => {+ reset();+ const target = event.target as HTMLElement;+ if (event.touches.length !== 1 ||+ target.closest('input, textarea, select, [contenteditable="true"], .av__select-dropdown') ||+ menuElement.querySelector(".av__select-dropdown")) {+ return;+ }+ let element = target;+ while (element && element !== menuElement) {+ if (element.scrollHeight > element.clientHeight + 1 && element.scrollTop > 0 &&+ ["auto", "scroll", "overlay"].includes(getComputedStyle(element).overflowY)) {+ return;+ }+ element = element.parentElement;+ }+ const touch = event.touches[0];+ start = {x: touch.clientX, y: touch.clientY, time: performance.now()};+ }, {passive: true});+ menuElement.addEventListener("touchmove", (event) => {+ if (!start || event.touches.length !== 1) {+ return;+ }+ const touch = event.touches[0];+ const offset = touch.clientY - start.y;+ if (!dragging && (offset <= 0 || Math.abs(touch.clientX - start.x) > offset)) {+ start = undefined;+ return;+ }+ dragging = true;+ menuElement.style.transition = "none";+ menuElement.style.transform = `translateY(${Math.max(0, offset)}px)`;+ scrimElement.style.opacity = Math.max(0, 1 - offset / menuElement.clientHeight).toString();+ if (event.cancelable) {+ event.preventDefault();+ }+ }, {passive: false});+ menuElement.addEventListener("touchend", (event) => {+ if (!start || !dragging) {+ reset();+ return;+ }+ const offset = Math.max(0, event.changedTouches[0].clientY - start.y);+ const velocity = offset / Math.max(1, performance.now() - start.time);+ const shouldClose = offset > Math.min(120, menuElement.clientHeight * .25) ||+ (offset > 20 && velocity > .6);+ suppressClickUntil = performance.now() + 300;+ reset();+ if (shouldClose) {+ // 复用关闭入口,确保日期、关联等编辑值提交及嵌套菜单关闭顺序一致+ panelElement.dispatchEvent(new CustomEvent("click", {detail: "close"}));+ }+ });+ menuElement.addEventListener("touchcancel", reset);+ menuElement.addEventListener("click", (event) => {+ if (performance.now() < suppressClickUntil && typeof event.detail === "number") {+ event.preventDefault();+ event.stopImmediatePropagation();+ }+ }, true);++ const removalObserver = new MutationObserver(() => {+ if (!panelElement.isConnected) {+ contentObserver.disconnect();+ removalObserver.disconnect();+ window.removeEventListener("resize", updateHeight);+ }+ });+ removalObserver.observe(panelElement.parentElement, {childList: true});+};diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.tsindex 47c2fe614e..e33b96a6f3 100644--- a/app/src/protyle/render/av/openMenuPanel.ts+++ b/app/src/protyle/render/av/openMenuPanel.ts@@ -42,6 +42,7 @@ import {getAssetExtension} from "../../../util/pathName";import {isBrowserRenderableImagePath} from "../../../util/imageURL";import {openEmojiPanel, unicode2Emoji} from "../../../emoji";import {isMobile} from "../../../util/functions";+import {bindMobileAVPanel} from "./mobilePanel";import {openLink} from "../../../editor/openLink";import {previewAttrViewImages} from "../../preview/image";import {assetMenu} from "../../../menus/protyle";@@ -242,6 +243,9 @@ export const openMenuPanel = (options: {}let closeCB: () => void;const menuElement = avPanelElement.lastElementChild as HTMLElement;+ if (isMobile()) {+ bindMobileAVPanel(avPanelElement as HTMLElement, menuElement);+ }const rerenderSwitcher = () => {const keyword = (menuElement.querySelector(".b3-text-field") as HTMLInputElement)?.value || "";menuElement.innerHTML = getSwitcherHTML(data.views, data.viewID, options.blockElement);