An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Respect overlay stacking for menu scrolling https://github.com/siyuan-note/siyuan/issues/19481
Danielae226f6ad632
diff --git a/app/src/block/popover.ts b/app/src/block/popover.tsindex 3d14a1237b..f3b9d855d4 100644--- a/app/src/block/popover.ts+++ b/app/src/block/popover.ts@@ -1,4 +1,5 @@import {BlockPanel} from "./Panel";+import {isAbove} from "../util/zIndex";import {hasClosestByAttribute, hasClosestByClassName,} from "../protyle/util/hasClosest";import {fetchPost, fetchSyncPost} from "../util/fetch";import {hideTooltip, showTooltip} from "../dialog/tooltip";@@ -417,7 +418,7 @@ const hidePopover = (event: MouseEvent & { path: HTMLElement[] }) => {if (avPanelElement) {// 浮窗上点击 av 操作,浮窗不能消失const blockPanel = window.siyuan.blockPanels.find((item) => {- if (item.element.style.zIndex < avPanelElement.style.zIndex) {+ if (isAbove(avPanelElement, item.element)) {return true;}});@@ -429,7 +430,7 @@ const hidePopover = (event: MouseEvent & { path: HTMLElement[] }) => {const menuElement = hasClosestByClassName(target, "b3-menu");if (menuElement && menuElement.getAttribute("data-name") !== Constants.MENU_DOC_TREE_MORE) {const blockPanel = window.siyuan.blockPanels.find((item) => {- if (item.element.style.zIndex < menuElement.style.zIndex) {+ if (isAbove(menuElement, item.element)) {return true;}});diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.tsindex 6c23e6db63..76716f6f88 100644--- a/app/src/boot/globalEvent/keydown.ts+++ b/app/src/boot/globalEvent/keydown.ts@@ -1,4 +1,5 @@import type {BlockQueryRequestInput} from "../../types/api";+import {isAbove} from "../../util/zIndex";import {copyPlainText,isMac,@@ -1601,7 +1602,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {if (!window.siyuan.menus.menu.element.classList.contains("fn__none")) {if (window.siyuan.dialogs.length > 0 &&- window.siyuan.menus.menu.element.style.zIndex < (window.siyuan.dialogs[0].element.querySelector(".b3-dialog") as HTMLElement).style.zIndex) {+ isAbove(window.siyuan.dialogs[0].element.querySelector(".b3-dialog"), window.siyuan.menus.menu.element)) {// 窗口高于菜单时,先关闭窗口,如 av 修改列 icon 时} else {window.siyuan.menus.menu.remove(true);diff --git a/app/src/dialog/index.ts b/app/src/dialog/index.tsindex 5db92a7d0f..2348bd9cb2 100644--- a/app/src/dialog/index.ts+++ b/app/src/dialog/index.ts@@ -1,4 +1,5 @@import {genUUID} from "../util/genID";+import {isAbove} from "../util/zIndex";import {moveResize} from "./moveResize";import {isMobile} from "../util/functions";import {isNotCtrl} from "../protyle/util/compatibility";@@ -96,7 +97,7 @@ left:${left || "auto"};top:${top || "auto"}">this.element.classList.remove("b3-dialog--open");setTimeout(() => {// av 修改列头emoji后点击关闭emoji图标- if ((this.element.querySelector(".b3-dialog") as HTMLElement).style.zIndex < window.siyuan.menus.menu.element.style.zIndex) {+ if (isAbove(window.siyuan.menus.menu.element, this.element.querySelector(".b3-dialog"))) {// https://github.com/siyuan-note/siyuan/issues/6783window.siyuan.menus.menu.remove();}diff --git a/app/src/emoji/index.ts b/app/src/emoji/index.tsindex fc5479a523..061ebb7433 100644--- a/app/src/emoji/index.ts+++ b/app/src/emoji/index.ts@@ -840,8 +840,6 @@ export const openEmojiPanel = (}) => {if (type !== "av") {window.siyuan.menus.menu.remove();- } else {- window.siyuan.menus.menu.removeScrollEvent();}const popoverElement = options?.ownerElement?.closest<HTMLElement>(".block__popover");diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.tsindex 28eea2a602..1dde899341 100644--- a/app/src/layout/dock/index.ts+++ b/app/src/layout/dock/index.ts@@ -1,5 +1,6 @@import {setStorageVal, updateHotkeyTip} from "../../protyle/util/compatibility";import {Layout} from "../index";+import {isAbove} from "../../util/zIndex";import {Wnd} from "../Wnd";import {Tab} from "../Tab";import {Files} from "./Files";@@ -639,9 +640,9 @@ export class Dock {const dialogElement = document.querySelector(".b3-dialog") as HTMLElement;const blockElement = document.querySelector(".block__popover") as HTMLElement;const menuElement = document.querySelector("#commonMenu:not(.fn__none)") as HTMLElement;- if (!reset && ((dialogElement && dialogElement.style.zIndex > this.layout.element.style.zIndex) || // 文档树上修改 emoji 时- (blockElement && blockElement.style.zIndex > this.layout.element.style.zIndex) || // 文档树上弹出悬浮层- (menuElement && menuElement.style.zIndex > this.layout.element.style.zIndex)) // 面板上弹出菜单时+ if (!reset && ((dialogElement && isAbove(dialogElement, this.layout.element)) || // 文档树上修改 emoji 时+ (blockElement && isAbove(blockElement, this.layout.element)) || // 文档树上弹出悬浮层+ (menuElement && isAbove(menuElement, this.layout.element))) // 面板上弹出菜单时) {return;}diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.tsindex cbe32f3412..47ddf1e27f 100644--- a/app/src/menus/Menu.ts+++ b/app/src/menus/Menu.ts@@ -1,5 +1,6 @@import {getEventName, updateHotkeyTip} from "../protyle/util/compatibility";import {setPosition} from "../util/setPosition";+import {isScrollAboveMenu} from "../util/zIndex";import {getAnchoredMenuPosition} from "./menuPosition";import {updateMenuGroupsOnMutation, updateMenuItemGroupClasses} from "./menuGroup";import {waitForSheetViewport} from "./sheetOpen";@@ -424,11 +425,8 @@ export class Menu {itemsMenuElement.style.maxHeight = Math.max(window.innerHeight - menuElement.getBoundingClientRect().top - 18 + 1, 30) + "px";}- private preventDefault(event: KeyboardEvent) {- if (!hasClosestByClassName(event.target as Element, "b3-menu") &&- !hasClosestByClassName(event.target as Element, "tooltip") &&- // 移动端底部键盘菜单- !hasClosestByClassName(event.target as Element, "keyboard__bar")) {+ private preventDefault(event: Event) {+ if (!isScrollAboveMenu(event.target as Element, this.element)) {event.preventDefault();}}@@ -441,7 +439,7 @@ export class Menu {}}- public removeScrollEvent() {+ private removeScrollEvent() {window.removeEventListener(isMobile() ? "touchmove" : this.wheelEvent, this.preventDefault, false);}diff --git a/app/src/util/zIndex.test.ts b/app/src/util/zIndex.test.tsnew file mode 100644index 0000000000..79379ad517--- /dev/null+++ b/app/src/util/zIndex.test.ts@@ -0,0 +1,39 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {getZIndex, isAbove, isScrollAboveMenu} from "./zIndex";++const element = (zIndex = "", parentElement: HTMLElement = null, classes: string[] = []): HTMLElement => ({+ style: {zIndex},+ parentElement,+ classList: {contains: (name: string) => classes.includes(name)},+} as HTMLElement);++describe("overlay stacking and menu scrolling", () => {+ it("compares layers numerically across digit boundaries", () => {+ for (const [lower, upper] of [[9, 10], [99, 100], [999, 1000]]) {+ assert.equal(isAbove(element(String(upper)), element(String(lower))), true);+ assert.equal(isAbove(element(String(lower)), element(String(upper))), false);+ }+ assert.equal(isAbove(element("100"), element("100")), false);+ assert.equal(getZIndex(element("auto")), 0);+ assert.equal(getZIndex(element()), 0);+ });++ it("allows menu contents and higher overlays while keeping the background locked", () => {+ const menu = element("99");+ const overlay = element("100");+ assert.equal(isScrollAboveMenu(element("", element("", menu)), menu), true);+ assert.equal(isScrollAboveMenu(element("", element("", overlay)), menu), true);+ assert.equal(isScrollAboveMenu(element(), menu), false);+ assert.equal(isScrollAboveMenu(element("", element("98")), menu), false);+ assert.equal(isScrollAboveMenu(element("99"), menu), false);+ overlay.style.zIndex = "98";+ assert.equal(isScrollAboveMenu(element("", overlay), menu), false);+ });++ it("preserves stylesheet-based tooltip and mobile keyboard scrolling", () => {+ for (const name of ["tooltip", "keyboard__bar"]) {+ assert.equal(isScrollAboveMenu(element("", element("", null, [name])), element("100")), true);+ }+ });+});diff --git a/app/src/util/zIndex.ts b/app/src/util/zIndex.tsnew file mode 100644index 0000000000..d0a8c1799d--- /dev/null+++ b/app/src/util/zIndex.ts@@ -0,0 +1,21 @@+export const getZIndex = (element: HTMLElement): number => {+ const value = Number(element.style.zIndex);+ return Number.isFinite(value) ? value : 0;+};++export const isAbove = (element: HTMLElement, reference: HTMLElement): boolean => {+ return getZIndex(element) > getZIndex(reference);+};++export const isScrollAboveMenu = (target: Element, menu: HTMLElement): boolean => {+ for (let element = target; element; element = element.parentElement) {+ if (element === menu || isAbove(element as HTMLElement, menu)) {+ return true;+ }+ // 提示层和移动端键盘栏使用样式表层级,保留其滚动能力。+ if (element.classList.contains("tooltip") || element.classList.contains("keyboard__bar")) {+ return true;+ }+ }+ return false;+};