From a9c2ff0fce14be0c6bf9a7ad5e9d5a8dfa4d762e Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Thu, 5 Nov 2026 12:46:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(floating):=20=E4=BF=AE=E6=AD=A3=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E5=B8=A6=E9=80=9A=E7=9F=A5=E4=B8=8E=E6=97=A0=E5=B8=A6?= =?UTF-8?q?=E5=AD=90=E6=97=B6=E7=9A=84=E5=B8=83=E5=B1=80=E5=81=8F=E5=B7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit viewport-inset 的快照原本是 { top } 对象,重读时每次新建,引用比较永远不等: 带子存在时每次 resize / geometrychange 都会广播,三个浮层各重渲染一次。改为 直接存数字,值不变就不通知。 AnchoredPopover 新增的让位原本无条件执行,普通浏览器里锚点贴到视口最顶时 弹层会从 6px 变 8px,与「无带子时逐字等价」的承诺不符。改为只在带子存在时 才抬高。 顺带删除 mermaid 工具栏里恒被内联样式覆盖的 CSS top(不跑 JS 时该弹层不存在, 不是降级),并补上测试:同值不广播、resize 兜底、visible 运行时翻转、浮窗 高度让位、AnchoredPopover 三个位置用例。 文档:接入指南的 WCO 例外改标「尚未发布」(v0.29.0 从未发布到 npm),计划 文档修正 #430 对照表与测试清单。 --- CHANGELOG.md | 2 +- CHANGELOG_EN.md | 2 +- docs/external-plugin-guide.md | 2 +- ...04-floating-window-native-titlebar-band.md | 11 +-- src/client/AnchoredPopover.tsx | 3 +- src/client/sidebar.module.css | 6 +- src/client/viewport-inset.ts | 44 ++++------ tests/anchored-popover.spec.tsx | 82 +++++++++++++++++++ tests/floating-window.spec.tsx | 14 ++++ tests/viewport-inset.spec.ts | 55 +++++++++---- 10 files changed, 164 insertions(+), 57 deletions(-) create mode 100644 tests/anchored-popover.spec.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ee4cb93..01966e5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ - 🧪 测试:`tests/settings-nav-icon.spec.tsx` 钉住图标按宿主给的 `size` 缩放、只用 `currentColor`;真实宿主上用无头浏览器确认导航行只剩一个 `svg`、无残留标记。 - 🪟 **浮层不再把自己的标题栏摆进桌面壳的原生窗口控件带**([#805](https://github.com/omdsh-dev/DSH-better-sidebar/issues/805) 同根因):Windows 桌面壳用 `titleBarOverlay` 在视口顶部画原生「最小化/最大化/关闭」,那条带子里的指针事件到不了网页。任务详情浮窗(`FloatingWindow`)的最小顶部距离写死 8px、自身标题栏 34px,× 正好落在带子里点不动;节点详情弹层(`AnchoredPopover`)与 mermaid 放大图工具栏同理。新增 `src/client/viewport-inset.ts` 读标准 `navigator.windowControlsOverlay`(`visible` + `getTitlebarAreaRect()`,订阅 `geometrychange`,`resize` 兜底)求出带高,三处消费者把可交互区压在带子下方;拖拽/重排的纵向下限同步,带子出现时把已摆好的浮层抬起、消失时不主动下拉(用户摆的位置不被最大化/还原弹走)。**只读探测、零配置**:不写 CSS 变量、不写 DOM 属性、不加偏好键、不复活 #430 删掉的 `--dsh-title-bar-strip`;API 缺失 / `visible:false` / 读取抛错一律退化为 0,普通浏览器与网页版的位置与今天逐字一致。 - - 🧪 测试:新增 `tests/viewport-inset.spec.ts`(9 例:API 缺失 / 高度 0 / `visible:false` / 抛错 / 小数取整 / `y+height` 取值 / `geometrychange` 增删 / 换源清理监听);`tests/floating-window.spec.tsx` 新增 5 例(锚点在带内抬起 / 拖拽不越界 / 带子出现抬起 / 带子消失不下拉 / 幽灵接口保持原 8px);挂载 lane 注入假 WCO 断言放大图工具栏 16→52→16 的真实布局。 + - 🧪 测试:新增 `tests/viewport-inset.spec.ts`(11 例:API 缺失 / 读到带高 / 高度 0 / `visible:false` / 抛错 / 小数取整 / `y+height` 取值 / 只在值真变时通知 / `resize` 兜底 / `visible` 运行时翻转 / 换源清理监听);`tests/floating-window.spec.tsx` 新增 6 例(锚点在带内抬起 / 拖拽不越界 / 带子出现抬起 / 带子消失不下拉 / 高度上限让出带子 / 幽灵接口保持原 8px);新增 `tests/anchored-popover.spec.tsx`(3 例:带内抬起 / 无带子保持原位 / 视口最顶保持历史位置);挂载 lane 注入假 WCO 断言放大图工具栏 16→52→16 的真实布局。 ### v0.30.0 diff --git a/CHANGELOG_EN.md b/CHANGELOG_EN.md index e1c65be1..c5dd2dbf 100644 --- a/CHANGELOG_EN.md +++ b/CHANGELOG_EN.md @@ -10,7 +10,7 @@ - 🧪 `tests/settings-nav-icon.spec.tsx` pins the glyph to the slot-provided `size` and `currentColor`; a headless pass against a real host confirms one `svg` in the row and no leftover marker. - 🪟 **Floating layers no longer place their own title bar under the desktop shell's native window-control band** (same root cause as [#805](https://github.com/omdsh-dev/DSH-better-sidebar/issues/805)): on Windows the shell paints its native minimize/maximize/close buttons over the top band of the viewport with `titleBarOverlay`, and pointer events in that band never reach the page. The task-detail window (`FloatingWindow`) had a hard-coded 8px top floor with a 34px title bar, so its × landed inside the band and could not be clicked; the node-detail popover (`AnchoredPopover`) and the mermaid zoom toolbar had the same problem. New `src/client/viewport-inset.ts` reads the standard `navigator.windowControlsOverlay` (`visible` + `getTitlebarAreaRect()`, `geometrychange` with a `resize` fallback) and all three consumers keep their interactive area below the band; vertical drag/re-layout floors follow it, an appearing band lifts an already-placed layer, and a disappearing band never pulls it back up (maximize/restore does not move what the reader placed). **Read-only probe, zero configuration**: no CSS variable, no DOM attribute, no preference key, no revival of the `--dsh-title-bar-strip` mechanism removed in #430; a missing API, `visible:false`, or a throwing read degrade to 0, so plain browsers and the web build behave exactly as before. - - 🧪 Tests: new `tests/viewport-inset.spec.ts` (9 cases); 5 new cases in `tests/floating-window.spec.tsx`; the mount lane injects a fake WCO and asserts the zoom toolbar's real layout moves 16→52→16. + - 🧪 Tests: new `tests/viewport-inset.spec.ts` (11 cases); 6 new cases in `tests/floating-window.spec.tsx`; new `tests/anchored-popover.spec.tsx` (3 cases); the mount lane injects a fake WCO and asserts the zoom toolbar's real layout moves 16→52→16. ### v0.30.0 diff --git a/docs/external-plugin-guide.md b/docs/external-plugin-guide.md index f11e7642..40c4ea59 100644 --- a/docs/external-plugin-guide.md +++ b/docs/external-plugin-guide.md @@ -1248,7 +1248,7 @@ interface SettingsDescriptor { - **用户空间 CSS(v0.14.1+;titleBar 让位机制移除后只剩它)**:`SidebarPrefs.customCss`(设置页「自定义 CSS」分组)注入 `