diff --git a/.github/release-notes/v0.1.7.md b/.github/release-notes/v0.1.7.md new file mode 100644 index 0000000..801e17c --- /dev/null +++ b/.github/release-notes/v0.1.7.md @@ -0,0 +1,46 @@ +本次更新新增双向亲属称呼查询,修复人物搜索排序与家谱树定位,并将 Android 底部导航改为左侧滑出菜单。 + +## 查称呼 + +- 新增独立“查称呼”页面,选择两个人物后,同时查看双方如何称呼对方,并展示关系路径;支持交换人物。 +- 人物详情和家谱树人物预览增加“查称呼”快捷入口,自动带入当前人物。 +- 支持爸爸、妈妈、爷爷、奶奶等日常称呼,以及较复杂的亲属关系。长幼不明时使用合称,不猜测年龄顺序;收养、继亲、监护、离异等关系保留说明。 +- 人物选择支持姓名和别名搜索、键盘操作及窄屏布局。资料不足、没有关联或选择同一人物时提供明确反馈。 +- 全部称呼计算在本地完成,不写入或修改家谱资料。 + +## 搜索与家谱树 + +- 家谱树和人物档案优先展示姓名最匹配的人物,同等匹配下主姓名优先于别名;排序在分页前完成。 +- 家谱树搜索结果支持点击、方向键和 Enter 定位,并高亮匹配人物;搜索保留当前缩放和平移。 +- 移除遮挡家谱画布的“人物与称呼”浮层,保留人物卡片上的称呼。 +- 修复人物预览区操作按钮的对齐,统一按钮尺寸和间距。 + +## Android 与移动端导航 + +- 移除底部 Tab,改用左侧滑出菜单;Android 横屏同样使用侧边菜单。 +- 支持顶部菜单按钮或左侧边缘右滑打开,点击遮罩、左滑或返回键关闭。 +- 修复菜单操作影响页面返回路径的问题,补充键盘焦点管理、无障碍语义和安全区适配。 + +## 版本与安装 + +- 桌面端、共享核心与 CLI 统一为 `0.1.7`,CLI Contract 保持 `3`;Android APK 的 `versionName` 为 `0.1.7`,`versionCode` 为 `1007`。 +- 本次更新不修改家谱数据格式或数据库 Schema。 +- 发布产物包括已签名的 Android arm64 Release APK,以及 Windows x64、macOS Apple Silicon / Intel、Linux x64 桌面安装包。桌面安装包内置匹配版本的 CLI 与 Skill,可从“AI 工具”页面安装或更新;暂不提供 iOS 安装包。 +- Android 正式版升级使用相同签名密钥。Debug 与 Release 签名不同,同包名时不能互相覆盖安装。 + +### macOS + +macOS 安装包使用 ad-hoc 签名,尚未经过 Apple Developer ID 签名和公证。从本项目官方 Release 下载并将“有谱”拖入“应用程序”后,若系统提示“App 已损坏”或无法验证开发者,可执行: + +```bash +xattr -dr com.apple.quarantine "/Applications/有谱.app" +open "/Applications/有谱.app" +``` + +以上命令仅移除“有谱”的下载隔离标记,不会关闭系统的全局 Gatekeeper。Windows 安装包目前也未进行商业代码签名,安装时可能显示安全提醒。 + +## 已知限制 + +重复人物合并、项目清理和历史快照恢复尚未接入共享 Rust 核心,当前会拒绝这些操作。本版本未改变这一限制。 + +[查看完整改动](https://github.com/tenlee2012/branchloom/compare/v0.1.6...v0.1.7) diff --git a/Cargo.lock b/Cargo.lock index 9dad786..d6f3ce2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,7 +351,7 @@ dependencies = [ [[package]] name = "branchloom" -version = "0.1.6" +version = "0.1.7" dependencies = [ "branchloom-core", "keyring", @@ -369,7 +369,7 @@ dependencies = [ [[package]] name = "branchloom-cli" -version = "0.1.6" +version = "0.1.7" dependencies = [ "branchloom-core", "serde", @@ -382,7 +382,7 @@ dependencies = [ [[package]] name = "branchloom-core" -version = "0.1.6" +version = "0.1.7" dependencies = [ "base64 0.22.1", "dirs", diff --git a/Cargo.toml b/Cargo.toml index c59fd22..0c38b17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,4 @@ members = [ resolver = "2" [workspace.package] -version = "0.1.6" +version = "0.1.7" diff --git a/README.md b/README.md index 927b7f4..efde1a1 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,11 @@ Android 端目前不提供 CLI、Codex Skill 安装或“AI 工具”页面。 - 记录人物的多种姓名、生卒信息、生平、职业、称谓、备注和头像。 - 整理亲生、收养、继亲、监护,以及婚姻、订婚、事实伴侣、分居、离异等关系。 - 从家谱树、人物列表和时间线浏览家庭资料。 +- Android 和窄屏界面通过左侧滑出菜单切换页面:点击顶部菜单按钮或从左边缘右滑打开,点击遮罩、左滑或返回关闭;底部不再显示导航标签栏。 +- 家谱树与人物档案搜索默认优先展示姓名完全匹配的人物,其次为姓名开头、姓名包含匹配,最后为生平、备注等其他资料匹配;同等匹配下主姓名优先于别名。排序在分页前完成,人物档案仍可手动按最近更新或出生时间排序。 +- 桌面家谱树支持部分姓名、字号搜索,高亮匹配人物并点击定位;选中人物后,在家谱卡片上查看其对其他人物的日常称呼,如爸爸、妈妈、爷爷、奶奶、太奶奶。长幼不明时保留“兄弟”“姐妹”等合称;上四代及更远的直系祖辈显示“老祖宗”及代数。称呼仅根据已载入资料的最短关系路径计算,收养、继亲、监护、已结束的伴侣关系及信息不足的情况保留关系说明,不写入家谱资料。 - 管理地点、家庭事件、史料来源、引文与本地附件。 +- 在“查称呼”页面搜索并选择当前项目中的任意两个人物,自动查看双向日常称呼、交换人物及查看最短关系路径;人物详情和家谱树人物预览提供预填当前人物的快捷入口。查询独立于画布显示代数,按当前项目的完整人物与关系资料推算,支持桌面与手机布局;资料缺失或读取失败时明确提示,不将称呼写入家谱资料。 ### 核对、备份与迁移 diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 0af4310..076a1be 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -12,8 +12,33 @@ The desktop application uses: Branchloom does not relicense `elkjs`. Recipients may obtain its source and license from the upstream project above. -## Release requirement +## Kinship calculator + +The family tree's local kinship calculator uses `relationship.js` 1.2.9 +([source](https://github.com/mumuy/relationship)) under the MIT License: + +> Copyright (c) 2016 Haole Zheng +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all +> copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +> SOFTWARE. + +## Release inventory Before publishing a binary release, generate and review a complete third-party license inventory from the exact npm and Cargo lockfiles used for that release. Include all required license texts, copyright notices, attributions, and source-availability statements with the distributed application or installer. -This file highlights a dependency with reciprocal redistribution requirements; it is not a substitute for the complete per-release inventory. +This file highlights selected runtime dependencies; it is not a substitute for the complete per-release inventory. diff --git a/package.json b/package.json index ea99ad7..8780a9b 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "cytoscape-elk": "2.3.0", "elkjs": "0.11.1", "pinia": "4.0.2", + "relationship.js": "1.2.9", "vue": "3.5.40", "vue-router": "5.2.0" }, diff --git a/packages/desktop/e2e/app-smoke.spec.ts b/packages/desktop/e2e/app-smoke.spec.ts index 10c0a11..dbf56c4 100644 --- a/packages/desktop/e2e/app-smoke.spec.ts +++ b/packages/desktop/e2e/app-smoke.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from '@playwright/test' -import { resetDemo } from './helpers/demo' +import { openProjectMenu, resetDemo } from './helpers/demo' test.beforeEach(async ({ page }) => resetDemo(page)) @@ -63,11 +63,16 @@ for (const viewport of [{ width: 1280, height: 900 }, { width: 390, height: 844 test('mobile project navigation reaches sync and switches back after creating a project', async ({ page }, testInfo) => { await page.setViewportSize({ width: 390, height: 844 }) - const mobileNavigation = page.getByRole('navigation', { name: '移动端项目导航' }) + const openOverview = async () => { + const menu = await openProjectMenu(page) + await menu.getByRole('link', { name: '项目管理', exact: true }).click() + await expect(menu).toHaveCount(0) + } const assertShell = async (hasRefresh = true) => { await expect(page.locator('.app-topbar')).toBeVisible() - await expect(mobileNavigation).toBeVisible() - await expect(page.getByRole('navigation', { name: '项目导航', exact: true })).toBeHidden() + await expect(page.getByRole('button', { name: '打开菜单', exact: true })).toBeVisible() + await expect(page.getByRole('dialog', { name: '项目菜单' })).toHaveCount(0) + await expect(page.getByRole('navigation', { name: '项目导航', exact: true })).toHaveCount(0) if (hasRefresh) { await expect(page.getByRole('button', { name: '刷新资料' })).toBeVisible() } else { @@ -76,7 +81,7 @@ test('mobile project navigation reaches sync and switches back after creating a expect(await page.locator('html').evaluate((element) => element.scrollWidth)).toBeLessThanOrEqual(390) } await assertShell() - await mobileNavigation.getByRole('link', { name: '项目', exact: true }).click() + await openOverview() await expect(page).toHaveURL('/project/project-demo-family/manage/overview') await assertShell(false) await page.screenshot({ path: testInfo.outputPath('mobile-project-overview.png') }) @@ -88,14 +93,14 @@ test('mobile project navigation reaches sync and switches back after creating a await expect(page.getByRole('heading', { name: '协作同步', exact: true })).toBeVisible() await assertShell() - await mobileNavigation.getByRole('link', { name: '项目', exact: true }).click() + await openOverview() await page.getByRole('link', { name: '打开项目设置' }).click() await assertShell() - await mobileNavigation.getByRole('link', { name: '项目', exact: true }).click() + await openOverview() await page.locator('.project-overview').getByRole('link', { name: '新建项目', exact: true }).click() await expect(page).toHaveURL('/project/project-demo-family/manage/new') await expect(page.getByRole('button', { name: '刷新资料' })).toHaveCount(0) - await expect(mobileNavigation).toBeVisible() + await expect(page.getByRole('button', { name: '打开菜单', exact: true })).toBeVisible() expect(await page.locator('html').evaluate((element) => element.scrollWidth)).toBeLessThanOrEqual(390) const back = page.locator('.app-topbar').getByRole('link', { name: '返回项目管理' }) await back.focus() @@ -114,7 +119,7 @@ test('mobile project navigation reaches sync and switches back after creating a await expect(page).toHaveURL(/\/project\/(?!project-demo-family)[^/]+\/tree$/) await assertShell() - await mobileNavigation.getByRole('link', { name: '项目', exact: true }).click() + await openOverview() await assertShell(false) const switcher = page.locator('.project-switcher') await switcher.locator('summary').focus() diff --git a/packages/desktop/e2e/helpers/demo.ts b/packages/desktop/e2e/helpers/demo.ts index 36fb491..00e52b4 100644 --- a/packages/desktop/e2e/helpers/demo.ts +++ b/packages/desktop/e2e/helpers/demo.ts @@ -38,6 +38,13 @@ export async function openDemo(page: Page, suffix = '/tree'): Promise { await expect(page.getByRole('navigation', { name: '项目导航' })).toBeVisible() } +export async function openProjectMenu(page: Page) { + await page.getByRole('button', { name: '打开菜单', exact: true }).click() + const menu = page.getByRole('dialog', { name: '项目菜单', exact: true }) + await expect(menu).toBeVisible() + return menu +} + export function watchRuntimeErrors(page: Page): string[] { const errors: string[] = [] page.on('pageerror', (error) => errors.push(`pageerror: ${error.message}`)) diff --git a/packages/desktop/e2e/kinship-query.spec.ts b/packages/desktop/e2e/kinship-query.spec.ts new file mode 100644 index 0000000..8b23e0e --- /dev/null +++ b/packages/desktop/e2e/kinship-query.spec.ts @@ -0,0 +1,77 @@ +import { expect, test } from '@playwright/test' +import { DEMO_PROJECT_PATH, expectNoRuntimeErrors, openProjectMenu, resetDemo, watchRuntimeErrors } from './helpers/demo' + +test.beforeEach(async ({ page }) => resetDemo(page)) + +for (const width of [1440, 900, 390, 320]) { + test(`query from a person, swap, refresh and return with a shared shell at ${width}px`, async ({ page }, testInfo) => { + const errors = watchRuntimeErrors(page) + await page.setViewportSize({ width, height: 1000 }) + const detailPath = `${DEMO_PROJECT_PATH}/people/person-lin-chen` + await page.goto(detailPath) + await page.getByRole('button', { name: '查称呼', exact: true }).click() + await expect(page.getByRole('heading', { name: '查称呼', exact: true })).toBeVisible() + await expect(page.getByRole('button', { name: '谁来称呼:林晨', exact: true })).toBeVisible() + await page.getByRole('button', { name: '称呼谁:选择人物' }).click() + const search = page.getByRole('searchbox', { name: '称呼谁:搜索人物' }) + await search.fill('海叔') + await search.press('ArrowDown') + const result = page.getByRole('region', { name: '称呼谁', exact: true }).getByRole('button', { name: /林海/ }) + await expect(result).toBeFocused() + await page.keyboard.press('Enter') + const forward = page.locator('[data-kinship-direction="forward"]') + const reverse = page.locator('[data-kinship-direction="reverse"]') + await expect(forward).toContainText('爸爸') + await expect(reverse).toContainText('女儿') + await expect(page.locator('.kinship-view__path')).toContainText('林晨 → 爸爸:林海') + await page.screenshot({ path: testInfo.outputPath(`kinship-${width}.png`) }) + + await page.getByRole('button', { name: '交换两个人物' }).click() + await expect(forward).toContainText('女儿') + await expect(reverse).toContainText('爸爸') + await page.getByRole('button', { name: '刷新资料', exact: true }).click() + await expect(forward).toContainText('女儿') + await page.reload() + await expect(forward).toContainText('女儿') + await expect(page.locator('.app-topbar')).toBeVisible() + expect(await page.locator('html').evaluate((element) => element.scrollWidth)).toBeLessThanOrEqual(width) + if (width < 768) { + const menu = await openProjectMenu(page) + const current = menu.getByRole('link', { name: '查称呼', exact: true }) + await expect(current).toHaveAttribute('aria-current', 'page') + expect((await current.boundingBox())!.height).toBeGreaterThanOrEqual(44) + await page.keyboard.press('Escape') + await expect(menu).toHaveCount(0) + } else { + await expect(page.getByRole('navigation', { name: '项目导航', exact: true }).getByRole('link', { name: '查称呼', exact: true })).toHaveAttribute('aria-current', 'page') + } + const back = page.getByRole('link', { name: '返回人物详情', exact: true }) + await back.focus() + await expect(back).toHaveCSS('outline-style', 'solid') + await page.keyboard.press('Enter') + await expect(page).toHaveURL(detailPath) + expectNoRuntimeErrors(errors) + }) +} + +test('standalone entry searches both people and keeps a no-match search distinct from a disconnected pair', async ({ page }) => { + const errors = watchRuntimeErrors(page) + await page.getByRole('navigation', { name: '项目导航', exact: true }).getByRole('link', { name: '查称呼', exact: true }).click() + await expect(page.getByText('从两个人的名字开始', { exact: true })).toBeVisible() + await page.getByRole('button', { name: '谁来称呼:选择人物' }).click() + const fromSearch = page.getByRole('searchbox', { name: '谁来称呼:搜索人物' }) + await fromSearch.fill('晨晨') + await fromSearch.press('Enter') + await page.getByRole('button', { name: '称呼谁:选择人物' }).click() + const toSearch = page.getByRole('searchbox', { name: '称呼谁:搜索人物' }) + await toSearch.fill('查无此人的测试') + await expect(page.getByRole('region', { name: '称呼谁', exact: true })).toContainText('未找到匹配人物') + await toSearch.press('Escape') + await expect(page.getByRole('button', { name: '称呼谁:选择人物' })).toBeFocused() + await page.getByRole('button', { name: '称呼谁:选择人物' }).click() + await page.getByRole('searchbox', { name: '称呼谁:搜索人物' }).fill('小晨') + await page.getByRole('searchbox', { name: '称呼谁:搜索人物' }).press('Enter') + await expect(page.getByText('当前资料中未找到关系路径', { exact: true })).toBeVisible() + await expect(page.locator('[data-kinship-direction]')).toHaveCount(0) + expectNoRuntimeErrors(errors) +}) diff --git a/packages/desktop/e2e/mobile-layout.spec.ts b/packages/desktop/e2e/mobile-layout.spec.ts index 2a33851..39b706b 100644 --- a/packages/desktop/e2e/mobile-layout.spec.ts +++ b/packages/desktop/e2e/mobile-layout.spec.ts @@ -1,5 +1,5 @@ import { expect, test, type Locator } from '@playwright/test' -import { DEMO_PROJECT_PATH, resetDemo } from './helpers/demo' +import { DEMO_PROJECT_PATH, openProjectMenu, resetDemo } from './helpers/demo' test.beforeEach(async ({ page }) => resetDemo(page)) @@ -38,7 +38,8 @@ for (const width of [320, 390]) { const refresh = topbar.getByRole('button', { name: '刷新资料', exact: true }) const addPerson = topbar.getByRole('button', { name: '添加人物', exact: true }) - for (const button of [refresh, addPerson]) { + const menuButton = topbar.getByRole('button', { name: '打开菜单', exact: true }) + for (const button of [menuButton, refresh, addPerson]) { await expect(button).toBeVisible() const bounds = await button.boundingBox() expect(bounds!.width).toBeGreaterThanOrEqual(44) @@ -51,7 +52,7 @@ for (const width of [320, 390]) { const projectName = topbar.locator('.app-topbar__mobile-project') await expect(projectName).toBeVisible() const titleArea = await topbar.locator('.app-topbar__drag-surface').boundingBox() - expect(titleArea!.width).toBeGreaterThan(width * 0.45) + expect(titleArea!.width).toBeGreaterThanOrEqual(120) await expectNoOverflow(topbar) await refresh.click() @@ -82,8 +83,8 @@ for (const width of [320, 390]) { await newPerson.click() await expect(page).toHaveURL(`${DEMO_PROJECT_PATH}/people/new`) - await page.getByRole('navigation', { name: '移动端项目导航' }) - .getByRole('link', { name: '时间', exact: true }).click() + const menu = await openProjectMenu(page) + await menu.getByRole('link', { name: '时间线', exact: true }).click() await expect(page).toHaveURL(`${DEMO_PROJECT_PATH}/timeline`) const timelineHeader = page.locator('.timeline-view__heading') await expect(timelineHeader.locator('.timeline-view__count')).toHaveText(/8\s*件事件/) @@ -105,6 +106,7 @@ for (const width of [320, 390]) { test('desktop keeps text labels on tree actions and readable page headings', async ({ page }) => { await page.setViewportSize({ width: 1280, height: 900 }) const topbar = page.locator('.app-topbar') + await expect(topbar.getByRole('button', { name: '打开菜单' })).toHaveCount(0) await expect(topbar.locator('.data-refresh__label')).toBeVisible() await expect(topbar.locator('.app-topbar__add-person-label')).toBeVisible() await expect(topbar.getByRole('button', { name: '适应画布' })).toBeVisible() diff --git a/packages/desktop/e2e/mobile-navigation.spec.ts b/packages/desktop/e2e/mobile-navigation.spec.ts new file mode 100644 index 0000000..e350cdf --- /dev/null +++ b/packages/desktop/e2e/mobile-navigation.spec.ts @@ -0,0 +1,155 @@ +import { expect, test, type Page } from '@playwright/test' +import { DEMO_PROJECT_PATH, expectNoRuntimeErrors, openProjectMenu, resetDemo, watchRuntimeErrors } from './helpers/demo' + +test.use({ hasTouch: true }) +test.beforeEach(async ({ page }) => resetDemo(page)) + +async function swipe(page: Page, from: [number, number], to: [number, number]) { + const session = await page.context().newCDPSession(page) + try { + await session.send('Input.dispatchTouchEvent', { type: 'touchStart', touchPoints: [{ x: from[0], y: from[1] }] }) + for (let step = 1; step <= 6; step += 1) { + await session.send('Input.dispatchTouchEvent', { + type: 'touchMove', + touchPoints: [{ x: from[0] + (to[0] - from[0]) * step / 6, y: from[1] + (to[1] - from[1]) * step / 6 }], + }) + } + await session.send('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] }) + } finally { + await session.detach() + } +} + +for (const width of [320, 390]) { + test(`left menu keeps full navigation, focus and browser Back at ${width}px`, async ({ page }, testInfo) => { + const errors = watchRuntimeErrors(page) + await page.setViewportSize({ width, height: 844 }) + await expect(page).toHaveURL(`${DEMO_PROJECT_PATH}/tree?personId=person-lin-hai`) + const treeUrl = page.url() + const trigger = page.getByRole('button', { name: '打开菜单', exact: true, includeHidden: true }) + await expect(trigger).toBeVisible() + await expect(trigger).toHaveAttribute('aria-expanded', 'false') + await expect(page.locator('.mobile-project-navigation')).toHaveCount(0) + const workspace = await page.locator('.project-layout__workspace').boundingBox() + expect(workspace!.y + workspace!.height).toBe(844) + + const menu = await openProjectMenu(page) + await expect(menu).toHaveCSS('transform', 'none') + await expect(trigger).toHaveAttribute('aria-expanded', 'true') + await expect(menu).toHaveAttribute('aria-modal', 'true') + await expect(page.locator('#app')).toHaveAttribute('inert', '') + const bounds = await menu.boundingBox() + expect(bounds!.x).toBe(0) + expect(bounds!.width).toBeLessThanOrEqual(width - 44) + expect(await menu.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true) + for (const name of ['家谱树', '人物', '查称呼', '时间线', '资料来源', '项目管理', '协作同步', '数据检查', '设置']) { + const link = menu.getByRole('link', { name, exact: true }) + await expect(link).toBeVisible() + expect((await link.boundingBox())!.height).toBeGreaterThanOrEqual(44) + } + await expect(menu.getByRole('link', { name: '家谱树', exact: true })).toHaveAttribute('aria-current', 'page') + const close = menu.getByRole('button', { name: '关闭菜单' }) + await expect(close).toBeFocused() + await page.keyboard.press('Tab') + await expect(menu.getByRole('link', { name: '返回当前项目家谱树' })).toBeFocused() + await page.keyboard.press('Tab') + await expect(menu.locator('summary[aria-label="切换项目"]')).toBeFocused() + await page.keyboard.press('Tab') + await expect(menu.getByRole('link', { name: '家谱树', exact: true })).toBeFocused() + await close.focus() + await page.keyboard.press('Shift+Tab') + await expect(menu.getByRole('link', { name: '设置', exact: true })).toBeFocused() + await page.keyboard.press('Tab') + await expect(close).toBeFocused() + await expect(close).toHaveCSS('outline-style', 'solid') + await page.screenshot({ path: testInfo.outputPath('left-navigation.png') }) + await page.keyboard.press('Escape') + await expect(menu).toHaveCount(0) + await expect(trigger).toBeFocused() + await expect(page.locator('#app')).not.toHaveAttribute('inert') + + await openProjectMenu(page) + await page.goBack() + await expect(menu).toHaveCount(0) + await expect(page).toHaveURL(treeUrl) + await openProjectMenu(page) + await menu.getByRole('link', { name: '人物', exact: true }).click() + await expect(menu).toHaveCount(0) + await expect(page).toHaveURL(`${DEMO_PROJECT_PATH}/people`) + await expect(page.getByRole('heading', { name: '人物档案' })).toBeVisible() + await page.goBack() + await expect(page).toHaveURL(treeUrl) + await expect(menu).toHaveCount(0) + expectNoRuntimeErrors(errors) + }) +} + +test('edge swipe opens the menu, vertical scrolling keeps it open and left swipe closes it', async ({ page }) => { + const errors = watchRuntimeErrors(page) + await page.setViewportSize({ width: 390, height: 844 }) + await expect(page).toHaveURL(`${DEMO_PROJECT_PATH}/tree?personId=person-lin-hai`) + const treeUrl = page.url() + const menu = page.getByRole('dialog', { name: '项目菜单' }) + await swipe(page, [8, 250], [170, 255]) + await expect(menu).toBeVisible() + await expect(menu).toHaveCSS('transform', 'none') + await swipe(page, [210, 550], [215, 350]) + await expect(menu).toBeVisible() + await swipe(page, [230, 420], [30, 425]) + await expect(menu).toHaveCount(0) + await expect(page).toHaveURL(treeUrl) + await expect(page.locator('#app')).not.toHaveAttribute('inert') + expectNoRuntimeErrors(errors) +}) + +test('backdrop and desktop resize dismiss the menu without leaving hidden focus traps', async ({ page }) => { + await page.setViewportSize({ width: 390, height: 844 }) + const menu = await openProjectMenu(page) + await page.locator('.mobile-navigation__backdrop').click({ position: { x: 380, y: 400 } }) + await expect(menu).toHaveCount(0) + await openProjectMenu(page) + await page.setViewportSize({ width: 1280, height: 900 }) + await expect(menu).toHaveCount(0) + await expect(page.getByRole('navigation', { name: '项目导航', exact: true })).toBeVisible() + await expect(page.getByRole('button', { name: '打开菜单' })).toHaveCount(0) + await expect(page.locator('#app')).not.toHaveAttribute('inert') + await page.setViewportSize({ width: 390, height: 844 }) + await expect(page.getByRole('button', { name: '打开菜单' })).toHaveAttribute('aria-expanded', 'false') + await expect(menu).toHaveCount(0) +}) + +test('native mobile capabilities keep the drawer and full labels in landscape', async ({ page }, testInfo) => { + await page.route('**/src/shared/runtimeCapabilities.ts*', (route) => route.fulfill({ + contentType: 'application/javascript', + body: 'export async function loadRuntimeCapabilities() { return { mobile: true, aiTools: false, scheduledSync: false }; }', + })) + await page.setViewportSize({ width: 900, height: 500 }) + await page.reload() + const menu = await openProjectMenu(page) + await expect(menu.getByRole('link', { name: 'AI 工具', exact: true })).toHaveCount(0) + await expect(menu.locator('.app-sidebar__link-label').first()).toBeVisible() + await expect(menu.getByRole('link', { name: '人物', exact: true })).toBeVisible() + const settings = menu.getByRole('link', { name: '设置', exact: true }) + await settings.focus() + await expect(settings).toBeInViewport() + await page.screenshot({ path: testInfo.outputPath('android-landscape-menu.png') }) + await page.keyboard.press('Escape') + await expect(menu).toHaveCount(0) + await expect(page.getByRole('button', { name: '打开菜单', exact: true })).toBeVisible() + expect(await page.locator('html').evaluate((element) => element.scrollWidth)).toBeLessThanOrEqual(900) +}) + +test('closing the menu preserves the original return location from person details', async ({ page }) => { + await page.setViewportSize({ width: 390, height: 844 }) + await expect(page).toHaveURL(`${DEMO_PROJECT_PATH}/tree?personId=person-lin-hai`) + const origin = page.url() + await page.getByRole('link', { name: '查看档案', exact: true }).click() + const back = page.locator('.app-topbar').getByRole('button', { name: '返回上一页', exact: true }) + await expect(back).toBeVisible() + const menu = await openProjectMenu(page) + await menu.getByRole('button', { name: '关闭菜单' }).click() + await expect(menu).toHaveCount(0) + await expect(back).toBeVisible() + await back.click() + await expect(page).toHaveURL(origin) +}) diff --git a/packages/desktop/e2e/tree-search-kinship.spec.ts b/packages/desktop/e2e/tree-search-kinship.spec.ts new file mode 100644 index 0000000..60bd8f2 --- /dev/null +++ b/packages/desktop/e2e/tree-search-kinship.spec.ts @@ -0,0 +1,82 @@ +import { expect, test } from '@playwright/test' +import { expectNoRuntimeErrors, openDemo, resetDemo, watchRuntimeErrors } from './helpers/demo' + +test.beforeEach(async ({ page }) => resetDemo(page)) + +test('exact-name matches come first in tree search and the people list', async ({ page }) => { + const errors = watchRuntimeErrors(page) + const treeSearch = page.getByRole('searchbox', { name: '搜索跳转人物' }) + await treeSearch.fill('赵雯') + const results = page.getByRole('region', { name: '人物搜索结果' }) + await expect(results).toContainText('找到 2 位人物') + await expect(results.getByRole('button').first()).toHaveAttribute('aria-label', '定位赵雯') + await treeSearch.press('Enter') + await expect(page.locator('.family-graph').getByRole('status')).toHaveText('赵雯对其他人物的称呼') + + await openDemo(page, '/people') + const peopleSearch = page.getByRole('searchbox', { name: '搜索人物', exact: true }) + await peopleSearch.fill('赵雯') + await expect(page.locator('[data-person-name]')).toHaveText(['赵雯', '林晨']) + await expect(page.getByRole('option', { name: '按匹配程度' })).toBeAttached() + await page.reload() + await expect(page.locator('[data-person-name]')).toHaveText(['赵雯', '林晨']) + await peopleSearch.fill('') + await expect(page.locator('[data-person-name]').first()).toHaveText('陈芳') + await expect(page.getByRole('option', { name: '按姓名', exact: true })).toBeAttached() + expectNoRuntimeErrors(errors) +}) + +for (const width of [1440, 900]) { + test(`partial-name search locates a person without a floating directory at ${width}px`, async ({ page }, testInfo) => { + const errors = watchRuntimeErrors(page) + await page.setViewportSize({ width, height: 1000 }) + const search = page.getByRole('searchbox', { name: '搜索跳转人物' }) + await search.fill('梅兰') + const results = page.getByRole('region', { name: '人物搜索结果' }) + await expect(results).toContainText('找到 1 位人物') + await expect(results.getByRole('button', { name: '定位王梅兰' })).toBeVisible() + await search.press('ArrowDown') + await expect(results.getByRole('button', { name: '定位王梅兰' })).toBeFocused() + await page.keyboard.press('Enter') + const selectionStatus = page.locator('.family-graph').getByRole('status') + await expect(selectionStatus).toHaveText('王梅兰对其他人物的称呼') + await expect(page.getByRole('complementary', { name: '为王梅兰添加关系' })).toHaveCount(0) + await expect(page.getByTestId('family-graph').locator('canvas').first()).toBeVisible() + await expect(page.locator('.family-graph details')).toHaveCount(0) + await expect(page.locator('.family-graph button')).toHaveCount(0) + await expect(page.locator('.app-topbar')).toBeVisible() + expect(await page.locator('html').evaluate((element) => element.scrollWidth)).toBeLessThanOrEqual(width) + await page.screenshot({ path: testInfo.outputPath('search-and-kinship.png') }) + + await search.fill('') + await expect(selectionStatus).toHaveText('王梅兰对其他人物的称呼') + await expect(results).toHaveCount(0) + await search.fill('查无此人的测试关键词') + await expect(results).toContainText('未找到匹配人物') + expectNoRuntimeErrors(errors) + }) +} + +test('keyboard search switches the selected person and Escape clears the perspective', async ({ page }, testInfo) => { + const errors = watchRuntimeErrors(page) + await page.setViewportSize({ width: 1440, height: 1000 }) + const search = page.getByRole('searchbox', { name: '搜索跳转人物' }) + const selectionStatus = page.locator('.family-graph').getByRole('status') + await search.fill('晨晨') + await expect(page.getByRole('button', { name: '定位林晨', exact: true })).toBeVisible() + await search.press('Enter') + await expect(selectionStatus).toHaveText('林晨对其他人物的称呼') + await expect(page.getByRole('region', { name: '研究视图:林晨的家庭关系' })).toBeVisible() + await page.screenshot({ path: testInfo.outputPath('everyday-kinship.png') }) + await search.fill('林海') + await expect(page.getByRole('button', { name: '定位林海', exact: true })).toBeVisible() + await search.press('Enter') + await expect(selectionStatus).toHaveText('林海对其他人物的称呼') + const preview = page.getByRole('region', { name: '研究视图:林海的家庭关系' }) + await expect(preview).toBeVisible() + await preview.getByRole('button', { name: '关闭人物预览' }).focus() + await page.keyboard.press('Escape') + await expect(selectionStatus).toHaveCount(0) + await expect(preview).toHaveCount(0) + expectNoRuntimeErrors(errors) +}) diff --git a/packages/desktop/src-tauri/android/MainActivity.kt b/packages/desktop/src-tauri/android/MainActivity.kt index d605707..a429f31 100644 --- a/packages/desktop/src-tauri/android/MainActivity.kt +++ b/packages/desktop/src-tauri/android/MainActivity.kt @@ -9,6 +9,9 @@ import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat class MainActivity : TauriActivity() { + // The navigation drawer adds a same-page entry so Back closes it first. + override val handleBackNavigation: Boolean = true + override fun onCreate(savedInstanceState: Bundle?) { applySystemBarStyle() super.onCreate(savedInstanceState) diff --git a/packages/desktop/src/app/appShell.test.ts b/packages/desktop/src/app/appShell.test.ts index b8706ba..1cf1eeb 100644 --- a/packages/desktop/src/app/appShell.test.ts +++ b/packages/desktop/src/app/appShell.test.ts @@ -1,16 +1,17 @@ -import { mount } from '@vue/test-utils' +import { DOMWrapper, mount } from '@vue/test-utils' import { createPinia, setActivePinia } from 'pinia' import { flushPromises } from '@vue/test-utils' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import App from '../App.vue' import { createAppRouter } from './router' import { useSessionStore } from './stores/session' import { branchloomRepositoryKey } from '../shared/repository/injection' import { BrowserPrototypeRepository } from '../shared/repository/BrowserPrototypeRepository' -import { PROJECT_DATA_CHANGED_EVENT } from '../shared/repository/TauriRepository' +import { NATIVE_STATE_REFRESHED_EVENT, PROJECT_DATA_CHANGED_EVENT } from '../shared/repository/TauriRepository' import type { PrototypeStorage } from '../shared/repository/storage' import type { BranchloomRepository, DataIssue, Project } from '../shared/domain/types' import { BrowserRecentProjectLocations } from '../features/projects/model/recentProjectLocations' +import * as runtimeCapabilities from '../shared/runtimeCapabilities' const tauriWindowMocks = vi.hoisted(() => ({ setTitle: vi.fn(() => Promise.resolve()), @@ -84,6 +85,7 @@ async function mountShell(path: string, repository: BranchloomRepository = makeR const wrapper = mount(App, { attachTo: document.body, global: { + stubs: { transition: false }, plugins: [pinia, router], provide: { [branchloomRepositoryKey as symbol]: repository, @@ -100,6 +102,21 @@ beforeEach(() => { window.localStorage.clear() }) +afterEach(() => { vi.unstubAllGlobals() }) + +function useMobileViewport() { + vi.stubGlobal('matchMedia', vi.fn((query: string) => ({ + matches: query === '(max-width: 48rem)', + media: query, + addEventListener: vi.fn(), + removeEventListener: vi.fn(), + }))) +} + +function mobileMenu() { + return new DOMWrapper(document.body).get('[role="dialog"][aria-label="项目菜单"]') +} + describe('application shell', () => { it('forwards the root experience into the latest project tree', async () => { const { wrapper, router } = await mountShell('/') @@ -160,7 +177,7 @@ describe('application shell', () => { const { wrapper } = await mountShell(`/project/${project!.id}/people`, repository) const navigation = wrapper.get('nav[aria-label="项目导航"]') - for (const label of ['家谱树', '人物', '时间线', '资料来源']) { + for (const label of ['家谱树', '人物', '查称呼', '时间线', '资料来源']) { expect(navigation.get(`a[aria-label="${label}"]`).text()).toContain(label) } expect(wrapper.get('nav[aria-label="项目管理导航"] a[aria-label="项目管理"]').text()) @@ -186,10 +203,8 @@ describe('application shell', () => { .toBe('/github-import') expect(wrapper.find('[aria-label="打开项目菜单"]').exists()).toBe(false) - const mobileNavigation = wrapper.get('nav[aria-label="移动端项目导航"]') - expect(mobileNavigation.findAll('a').map((link) => link.text())) - .toEqual(['家谱', '人物', '时间', '资料', '项目']) - expect(mobileNavigation.get('a[aria-current="page"]').text()).toBe('人物') + expect(wrapper.find('button[aria-label="打开菜单"]').exists()).toBe(false) + expect(wrapper.find('.mobile-project-navigation').exists()).toBe(false) inspectProject.mockResolvedValue([]) window.dispatchEvent(new Event(PROJECT_DATA_CHANGED_EVENT)) @@ -223,13 +238,16 @@ describe('application shell', () => { }) it('reaches collaboration and another project through the mobile project destination', async () => { + useMobileViewport() const repository = makeRepository() const [first] = await repository.listProjects() const second = await repository.createProject({ name: '移动端第二份家谱', description: '' }) const { wrapper, router, session } = await mountShell(`/project/${first!.id}/tree`, repository) const openProjectPage = async () => { - await wrapper.get('nav[aria-label="移动端项目导航"] a[href$="/manage/overview"]').trigger('click') + await wrapper.get('button[aria-label="打开菜单"]').trigger('click') + await flushPromises() + await mobileMenu().get('a[aria-label="项目管理"]').trigger('click') await vi.waitFor(() => expect(router.currentRoute.value.name).toBe('project-overview')) await flushPromises() expect(wrapper.get('.app-topbar').find('button[name="刷新资料"]').exists()).toBe(false) @@ -253,6 +271,83 @@ describe('application shell', () => { wrapper.unmount() }) + it('opens a modal mobile menu, traps keyboard focus and returns focus on Escape', async () => { + useMobileViewport() + const { wrapper, router } = await mountShell('/project/project-demo-family/people') + const trigger = wrapper.get('button[aria-label="打开菜单"]') + trigger.element.focus() + await trigger.trigger('click') + await flushPromises() + const menu = mobileMenu() + expect(trigger.attributes('aria-expanded')).toBe('true') + expect(menu.attributes('aria-modal')).toBe('true') + expect(menu.get('a[aria-label="人物"]').attributes('aria-current')).toBe('page') + expect(wrapper.element.closest('[inert]')).not.toBeNull() + expect(menu.get('[aria-label="关闭菜单"]').element).toBe(document.activeElement) + const settings = menu.get('a[href$="/manage/settings"]') + settings.element.focus() + await settings.trigger('keydown', { key: 'Tab' }) + expect(menu.get('[aria-label="关闭菜单"]').element).toBe(document.activeElement) + await menu.trigger('keydown', { key: 'Escape' }) + await vi.waitFor(() => expect(document.querySelector('[aria-label="项目菜单"]')).toBeNull()) + expect(trigger.element).toBe(document.activeElement) + expect(trigger.attributes('aria-expanded')).toBe('false') + expect(wrapper.element.closest('[inert]')).toBeNull() + expect(router.currentRoute.value.path).toBe('/project/project-demo-family/people') + wrapper.unmount() + }) + + it('uses Back to dismiss the menu and closes it when selecting the current destination', async () => { + useMobileViewport() + const path = '/project/project-demo-family/people' + const { wrapper, router } = await mountShell(path) + const trigger = wrapper.get('button[aria-label="打开菜单"]') + await trigger.trigger('click') + await flushPromises() + expect(mobileMenu().attributes('aria-modal')).toBe('true') + window.history.back() + await vi.waitFor(() => expect(document.querySelector('[aria-label="项目菜单"]')).toBeNull()) + expect(router.currentRoute.value.path).toBe(path) + await trigger.trigger('click') + await flushPromises() + await mobileMenu().get('a[aria-label="人物"]').trigger('click') + await vi.waitFor(() => expect(window.history.state?.branchloomNavigationDrawer).toBeUndefined()) + expect(document.querySelector('[aria-label="项目菜单"]')).toBeNull() + expect(router.currentRoute.value.path).toBe(path) + wrapper.unmount() + }) + + it('keeps native mobile navigation in a drawer on wide screens and hides unavailable AI tools', async () => { + const capabilities = vi.spyOn(runtimeCapabilities, 'loadRuntimeCapabilities').mockResolvedValue({ + mobile: true, aiTools: false, scheduledSync: false, + }) + const { wrapper } = await mountShell('/project/project-demo-family/people') + try { + expect(wrapper.find('.project-layout--compact').exists()).toBe(true) + await wrapper.get('button[aria-label="打开菜单"]').trigger('click') + await flushPromises() + expect(mobileMenu().find('.app-sidebar--mobile').exists()).toBe(true) + expect(mobileMenu().find('a[href$="/ai-tools"]').exists()).toBe(false) + await mobileMenu().get('button[aria-label="关闭菜单"]').trigger('click') + await vi.waitFor(() => expect(window.history.state?.branchloomNavigationDrawer).toBeUndefined()) + } finally { + wrapper.unmount() + capabilities.mockRestore() + } + }) + + it('preserves a detail page return target across same-page navigation entries', async () => { + const origin = '/project/project-demo-family/people?search=林晨' + const { wrapper, router } = await mountShell(origin) + await router.push('/project/project-demo-family/people/person-lin-chen') + const detailPath = router.currentRoute.value.fullPath + await router.push({ path: detailPath, force: true }) + await flushPromises() + expect(router.currentRoute.value.meta.previousFullPath).toBe(origin) + expect(wrapper.find('.app-topbar button[aria-label="返回上一页"]').exists()).toBe(true) + wrapper.unmount() + }) + it('uses the same shell for the global AI tools route', async () => { const repository = makeRepository() const [project] = await repository.listProjects() @@ -377,6 +472,38 @@ describe('application shell', () => { .toBe('management') }) + it('opens the kinship page from a person, preserves its shell and selection on refresh, and returns to that person', async () => { + const detailPath = '/project/project-demo-family/people/person-lin-chen' + const { wrapper, router } = await mountShell(detailPath) + await wrapper.get('button[name="查称呼"]').trigger('click') + await vi.waitFor(() => expect(router.currentRoute.value.name).toBe('project-kinship')) + await flushPromises() + expect(router.currentRoute.value.query.from).toBe('person-lin-chen') + expect(wrapper.get('h1').text()).toBe('查称呼') + expect(wrapper.find('.app-topbar button[name="刷新资料"]').exists()).toBe(true) + expect(wrapper.get('nav[aria-label="项目导航"] a[aria-label="查称呼"]').attributes('aria-current')).toBe('page') + await router.replace({ query: { ...router.currentRoute.value.query, to: 'person-lin-hai' } }) + await flushPromises() + expect(wrapper.get('[data-kinship-direction="forward"]').text()).toContain('爸爸') + window.dispatchEvent(new Event(NATIVE_STATE_REFRESHED_EVENT)) + await flushPromises() + await vi.waitFor(() => expect(wrapper.get('[data-kinship-direction="forward"]').text()).toContain('爸爸')) + const back = wrapper.get('.app-topbar a[aria-label="返回人物详情"]') + expect(back.attributes('href')).toBe(detailPath) + await back.trigger('click') + await vi.waitFor(() => expect(router.currentRoute.value.path).toBe(detailPath)) + wrapper.unmount() + }) + + it.each(['https://example.com', '/project/foreign/people/person-foreign', '/project/project-demo-family/manage/settings'])( + 'ignores an out-of-scope kinship return target: %s', async (returnTo) => { + const { wrapper } = await mountShell(`/project/project-demo-family/kinship?returnTo=${encodeURIComponent(returnTo)}`) + expect(wrapper.get('.app-topbar a[aria-label="返回人物列表"]').attributes('href')).toBe('/project/project-demo-family/people') + expect(wrapper.find('a[aria-label="返回人物详情"]').exists()).toBe(false) + wrapper.unmount() + }, + ) + it('keeps the project shell visible throughout project creation tasks', async () => { const repository = makeRepository() const [project] = await repository.listProjects() @@ -421,6 +548,7 @@ describe('application shell', () => { ['/github-import', 'home', '返回'], ['/project/project-demo-family/people/person-demo-1', 'project-people', '返回人物列表'], ['/project/project-demo-family/people/person-demo-1/edit', 'person-detail', '返回人物详情'], + ['/project/project-demo-family/kinship', 'project-people', '返回人物列表'], ['/project/project-demo-family/manage/new', 'project-overview', '返回项目管理'], ['/project/project-demo-family/manage/exchange', 'project-overview', '返回项目管理'], ['/project/project-demo-family/manage/history', 'project-overview', '返回项目管理'], @@ -443,7 +571,7 @@ describe('application shell', () => { const main = wrapper.get('.project-layout__main') const back = wrapper.get('a[aria-label="返回项目管理"]') - expect(wrapper.get('.app-topbar').element.firstElementChild).toBe(back.element) + expect(wrapper.get('.app-topbar__context').element.firstElementChild).toBe(back.element) expect(main.find('.page-back-link').exists()).toBe(false) expect(wrapper.find('.app-topbar__page-title').exists()).toBe(false) expect(document.title).toBe('项目设置 · 有谱') diff --git a/packages/desktop/src/app/components/AppSidebar.vue b/packages/desktop/src/app/components/AppSidebar.vue index 5425c37..3c52ad1 100644 --- a/packages/desktop/src/app/components/AppSidebar.vue +++ b/packages/desktop/src/app/components/AppSidebar.vue @@ -16,6 +16,7 @@ import { IconSettings, IconShieldCheck, IconUser, + IconUsersGroup, IconFileDescription, } from '@tabler/icons-vue' import BaseButton from '../../design-system/BaseButton.vue' @@ -26,9 +27,10 @@ import { PROJECT_DATA_CHANGED_EVENT, } from '../../shared/repository/TauriRepository' import { useSessionStore } from '../stores/session' +import { loadRuntimeCapabilities } from '../../shared/runtimeCapabilities' import appIcon from '../../../src-tauri/icons/icon.png' -const props = defineProps<{ projectId: string; projectName: string }>() +const props = defineProps<{ projectId: string; projectName: string; mobile?: boolean }>() const route = useRoute() const repository = useBranchloomRepository() const session = useSessionStore() @@ -37,6 +39,7 @@ const projectSwitcher = ref() const projects = ref([]) const projectListError = ref('') const issueCount = ref() +const aiToolsAvailable = ref(false) const projectTreePath = computed(() => props.projectId ? `/project/${encodeURIComponent(props.projectId)}/tree` : '/') @@ -94,6 +97,7 @@ function refreshIssueCount() { } onMounted(() => { + void loadRuntimeCapabilities().then(({ aiTools }) => { aiToolsAvailable.value = aiTools }).catch(() => {}) window.addEventListener(PROJECT_DATA_CHANGED_EVENT, refreshIssueCount) window.addEventListener(NATIVE_STATE_REFRESHED_EVENT, refreshIssueCount) }) @@ -109,6 +113,7 @@ const navigation = computed(() => { return [ { label: '家谱树', icon: IconNetwork, to: `${base}/tree`, segment: '/tree' }, { label: '人物', icon: IconUser, to: `${base}/people`, segment: '/people' }, + { label: '查称呼', icon: IconUsersGroup, to: `${base}/kinship`, segment: '/kinship' }, { label: '时间线', icon: IconClock, to: `${base}/timeline`, segment: '/timeline' }, { label: '资料来源', icon: IconFileDescription, to: `${base}/sources`, segment: '/sources' }, ] @@ -152,7 +157,7 @@ function isExact(to: string) {