提交记录修改docs/getting-started.md+1 −1看文件
修改docs/guide/installation.md+1 −1看文件
修改ui/scripts/archive-bulk-smoke.mjs+3 −3看文件
修改ui/scripts/browser-vertical-tabs-smoke.mjs+1 −1看文件
修改ui/scripts/cli-session-management-smoke.mjs+4 −4看文件
修改ui/scripts/exit-policy-region-smoke.mjs+3 −3看文件
修改ui/scripts/guest-install-smoke.mjs+1 −1看文件
修改ui/scripts/guest-system-picker-smoke.mjs+2 −2看文件
修改ui/scripts/host-clone-smoke.mjs+3 −3看文件
修改ui/scripts/initialization-smoke.mjs+49 −4看文件
修改ui/scripts/installation-preview.mjs+1 −1看文件
修改ui/scripts/mobile-inline-select-smoke.mjs+7 −5看文件
修改ui/scripts/proxy-chain-ui-smoke.mjs+2 −2看文件
修改ui/scripts/remote-hosts-smoke.mjs+3 −4看文件
修改ui/scripts/ubuntu-guest-choice-smoke.mjs+1 −1看文件
修改ui/scripts/workbench-fixture.mjs+1 −1看文件
修改ui/src/guest-system-picker.jsx+5 −4看文件
新增ui/src/initialization-storage.jsx+33 −0看文件
修改ui/src/initialization.css+7 −0看文件
修改ui/src/initialization.jsx+25 −3看文件
修改ui/src/inline-select.css+6 −2看文件
修改ui/src/inline-select.jsx+8 −5看文件
修改ui/src/mobile-cli/inline-select.jsx+8 −5看文件
修改ui/src/mobile-cli/mobile.css+1 −1看文件
新增ui/src/select-popup.jsx+31 −0看文件
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | |
| 41 | 41 | ### 选择环境存储位置 |
| 42 | 42 | |
| 43 | 删除:Windows 安装器中选择的是程序目录。如果希望镜像下载和虚拟磁盘都放在 D 盘,首次登录后在独立初始化界面的“系统与存储”中选择专用空文件夹,例如 `D:\CageData`,点击“使用此位置”,再配置代理并开始安装。macOS 和 Linux 使用相同流程。安装、必要授权与网络检查完成后才进入工作台;中断后重新打开仍可继续。Debian 环境默认设置下,虚拟磁盘在用户主目录的 `.claude-cage/state/lima`,镜像下载缓存在系统用户缓存目录下的 `lima`(Windows 为 `%LOCALAPPDATA%\lima`)。 | |
| 43 | 新增:Windows 安装器中选择的是程序目录。如果希望镜像下载和虚拟磁盘都放在 D 盘,首次登录后在独立初始化界面的“系统与存储”中修改已填入默认值的“存储目录”,或选择专用空文件夹,例如 `D:\CageData`,点击“下一步:配置代理”时保存。macOS 和 Linux 使用相同流程。安装、必要授权与网络检查完成后才进入工作台;中断后重新打开仍可继续。Debian 环境默认设置下,虚拟磁盘在用户主目录的 `.claude-cage/state/lima`,镜像下载缓存在系统用户缓存目录下的 `lima`(Windows 为 `%LOCALAPPDATA%\lima`)。 | |
| 44 | 44 | |
| 45 | 45 | 选择支持私有文件权限和稀疏文件的本地磁盘。Windows 可用 NTFS,Linux 可用 ext4、XFS 或 Btrfs。Mac 需要 APFS 卷并启用所有权。使用 Mac 外接盘时,在 Finder 的磁盘“显示简介”中取消“忽略此宗卷的所有权”。 |
| 46 | 46 | |
| @@ -38,7 +38,7 @@ Windows ARM64 和 Linux ARM64 暂不支持。平台依赖详情见 [Windows 指 | ||
| 38 | 38 | |
| 39 | 39 | 首次登录后,Cage 显示独立的初始化界面。先选择适合项目的客机系统,可选择“自动匹配本机系统版本”或具体系统。自动匹配会在代理配置后获取对应的官方镜像,安装干净的独立系统,主机个人文件与登录资料不会复制。以后启动沿用原系统和磁盘,更新 Cage 不会替换客机系统。 |
| 40 | 40 | |
| 41 | 删除:在“本机环境存储”中查看默认位置;需要更换时点击“选择文件夹”,选定本地磁盘上的专用空文件夹,再点击“使用此位置”。Windows 安装器里的程序目录与环境数据目录分开;例如应用装在 C 盘,环境可放在 `D:\CageData`。 | |
| 41 | 新增:“存储目录”已填入默认位置。需要更换时直接编辑,或点击“选择文件夹”选定本地磁盘上的专用空文件夹;点击“下一步:配置代理”时保存,目录无效时留在当前页提示修改。Windows 安装器里的程序目录与环境数据目录分开;例如应用装在 C 盘,环境可放在 `D:\CageData`。 | |
| 42 | 42 | |
| 43 | 43 | 选择支持权限管理与稀疏文件的磁盘:Windows 可用 NTFS,Linux 可用 ext4 / XFS / Btrfs,macOS 使用已启用所有权的 APFS。不要选择磁盘根目录、网络盘、已有项目或应用安装目录。已有环境换盘请按[存储迁移](maintenance.md#迁移环境到另一块磁盘)操作。 |
| 44 | 44 | |
| @@ -61,14 +61,14 @@ try { | ||
| 61 | 61 | await panel.getByRole("status").filter({hasText:"已取消归档 1 个会话"}).waitFor(); |
| 62 | 62 | assert.deepEqual(operations.splice(0),[{id:"a2",operation:"restore"}],"filtered select all affected hidden sessions"); |
| 63 | 63 | await search.fill(""); |
| 64 | 删除: // Changing project filters also clears selection, and the dropdown pushes content down. | |
| 64 | 新增: // Changing filters clears selection; its floating list keeps content in place. | |
| 65 | 65 | await checkbox(panel,allName).check(); |
| 66 | 66 | const filter = panel.getByRole("combobox",{name:"项目筛选"}); |
| 67 | 67 | const toolbar = panel.getByRole("group",{name:"批量处理会话"}); |
| 68 | 68 | const before = await toolbar.boundingBox(); |
| 69 | 69 | await filter.click(); |
| 70 | 删除: const list = await panel.getByRole("listbox",{name:"项目筛选选项"}).boundingBox(); | |
| 71 | 删除: assert.ok((await toolbar.boundingBox()).y >= list.y + list.height); | |
| 70 | 新增: const list = await page.getByRole("listbox",{name:"项目筛选选项"}).boundingBox(); | |
| 71 | 新增: assert.ok(Math.abs((await toolbar.boundingBox()).y-before.y)<1 && list.height>0); | |
| 72 | 72 | await filter.press("Escape"); |
| 73 | 73 | assert.ok(Math.abs((await toolbar.boundingBox()).y-before.y)<2); |
| 74 | 74 | await filter.press("End"); await filter.press("Enter"); |
| @@ -50,7 +50,7 @@ try { | ||
| 50 | 50 | const before = await help.boundingBox(); |
| 51 | 51 | await picker.click(); |
| 52 | 52 | const expanded = await help.boundingBox(); |
| 53 | 删除: assert.ok(expanded.y > before.y + 40, "options must push the following content down"); | |
| 53 | 新增: assert.ok(Math.abs(expanded.y - before.y) < 1, "floating options must not move the following content"); | |
| 54 | 54 | await page.keyboard.press("Escape"); |
| 55 | 55 | assert.ok(Math.abs((await help.boundingBox()).y - before.y) < 1, "closing options restores the layout"); |
| 56 | 56 | await picker.click(); |
| @@ -103,10 +103,10 @@ try { | ||
| 103 | 103 | await group.waitFor(); |
| 104 | 104 | const before = await group.boundingBox(); |
| 105 | 105 | await projectFilter.click(); |
| 106 | 删除: const options = panel.getByRole("listbox",{name:"项目筛选选项"}); | |
| 106 | 新增: const options = page.getByRole("listbox",{name:"项目筛选选项"}); | |
| 107 | 107 | const opened = await options.boundingBox(); |
| 108 | 108 | const shifted = await group.boundingBox(); |
| 109 | 删除: assert.ok(shifted.y > before.y + 20 && opened.y + opened.height <= shifted.y,"project filter covered content"); | |
| 109 | 新增: assert.ok(Math.abs(shifted.y-before.y)<1 && opened.height>0,"floating project filter moved content"); | |
| 110 | 110 | await projectFilter.press("Escape"); |
| 111 | 111 | assert.ok(Math.abs((await group.boundingBox()).y - before.y) < 2,"filter did not restore layout"); |
| 112 | 112 | await projectFilter.press("End"); await projectFilter.press("Enter"); |
| @@ -114,7 +114,7 @@ try { | ||
| 114 | 114 | assert.equal(await panel.getByRole("heading",{name:"电脑保留的历史",exact:true}).count(),0); |
| 115 | 115 | await projectFilter.press("Home"); await projectFilter.press("Enter"); |
| 116 | 116 | const filter = panel.getByRole("combobox",{name:"会话筛选"}); |
| 117 | 删除: await filter.click(); await panel.getByRole("option",{name:"已置顶",exact:true}).click(); | |
| 117 | 新增: await filter.click(); await page.getByRole("option",{name:"已置顶",exact:true}).click(); | |
| 118 | 118 | assert.equal(await panel.getByRole("article").count(),1); |
| 119 | 119 | await filter.press("Home"); await filter.press("Enter"); |
| 120 | 120 | const search = panel.getByRole("searchbox",{name:"搜索已归档的会话"}); |
| @@ -143,7 +143,7 @@ try { | ||
| 143 | 143 | const phoneFilter = phone.getByRole("combobox",{name:"项目筛选"}); |
| 144 | 144 | await phoneFilter.click(); |
| 145 | 145 | const phoneOptions = await phone.getByRole("listbox",{name:"项目筛选选项"}).boundingBox(); |
| 146 | 删除: assert.ok((await phoneGroup.boundingBox()).y >= phoneOptions.y + phoneOptions.height,"phone filter covered content"); | |
| 146 | 新增: assert.ok(Math.abs((await phoneGroup.boundingBox()).y-phoneBefore.y)<1 && phoneOptions.height>0,"floating phone filter moved content"); | |
| 147 | 147 | await phoneFilter.press("Escape"); |
| 148 | 148 | assert.ok(Math.abs((await phoneGroup.boundingBox()).y-phoneBefore.y)<2); |
| 149 | 149 | await phone.getByRole("heading",{name:"已归档会话",exact:true}).click(); |
| @@ -31,12 +31,12 @@ try { | ||
| 31 | 31 | await country.press("Escape"); |
| 32 | 32 | const before = await layoutTop(country); |
| 33 | 33 | await picker.click(); |
| 34 | 删除: const options = picker.locator("..").getByRole("listbox"); | |
| 34 | 新增: const options = page.getByRole("listbox"); | |
| 35 | 35 | await options.waitFor(); |
| 36 | 36 | const expanded = await layoutTop(country); |
| 37 | 37 | const list = await options.boundingBox(); |
| 38 | 删除: assert.ok(expanded > before, "expanded options must move the following fields down"); | |
| 39 | 删除: assert.ok((await layoutTop(options)) + list.height <= expanded, "options must not cover the next control"); | |
| 38 | 新增: assert.ok(Math.abs(expanded - before) < 1, "floating options must not move the following fields"); | |
| 39 | 新增: assert.ok(list.height > 0, "options must remain visible"); | |
| 40 | 40 | await picker.press("ArrowDown"); |
| 41 | 41 | await picker.press("Enter"); |
| 42 | 42 | await page.getByLabel("允许的城市", { exact: true }).waitFor({ state: "hidden" }); |
| @@ -23,7 +23,7 @@ for (const [id, name, platform] of [["macos", "macOS", "darwin"], ["windows-11", | ||
| 23 | 23 | const option = page.getByRole("option", { name, exact: true }); |
| 24 | 24 | await option.waitFor(); |
| 25 | 25 | const row = await option.boundingBox(), below = await storage.boundingBox(); |
| 26 | 删除: assert.ok(below.y > storageBefore.y && row.y + row.height <= below.y); | |
| 26 | 新增: assert.ok(Math.abs(below.y - storageBefore.y) < 1 && row.height > 0); | |
| 27 | 27 | await picker.press("Escape"); |
| 28 | 28 | assert.equal((await storage.boundingBox()).y, storageBefore.y); |
| 29 | 29 | await picker.press("Enter"); await picker.press("End"); await picker.press("Enter"); |
| @@ -22,10 +22,10 @@ for (const [platform, id] of [["darwin","macos"], ["windows","windows-11"], ["li | ||
| 22 | 22 | const storage = page.getByRole("button",{name:"选择环境存储位置"}); |
| 23 | 23 | const initialY = (await storage.boundingBox()).y; |
| 24 | 24 | await picker.click(); |
| 25 | 删除: const option = region.getByRole("option").last(); | |
| 25 | 新增: const option = page.getByRole("option").last(); | |
| 26 | 26 | assert.equal(await option.getAttribute("aria-disabled"),"true"); |
| 27 | 27 | const position = await option.boundingBox(); |
| 28 | 删除: assert.ok((await storage.boundingBox()).y >= position.y + position.height); | |
| 28 | 新增: assert.ok(Math.abs((await storage.boundingBox()).y - initialY) < 1 && position.height > 0); | |
| 29 | 29 | await picker.press("Escape"); |
| 30 | 30 | assert.ok(Math.abs((await storage.boundingBox()).y - initialY) <= 1, "collapsed picker restores the following control"); |
| 31 | 31 | } |
| @@ -53,14 +53,14 @@ for (const [platform, system, version, edition] of [ | ||
| 53 | 53 | const initialHeight = (await region.boundingBox()).height; |
| 54 | 54 | await picker.focus(); |
| 55 | 55 | await picker.press("ArrowDown"); |
| 56 | 删除: const option = region.getByRole("option", { | |
| 56 | 新增: const option = page.getByRole("option", { | |
| 57 | 57 | name: "自动匹配本机系统版本", |
| 58 | 58 | exact: true, |
| 59 | 59 | }); |
| 60 | 60 | await option.waitFor(); |
| 61 | 61 | assert.ok( |
| 62 | 删除: (await region.boundingBox()).height > initialHeight, | |
| 63 | 删除: "options occupy layout space", | |
| 62 | 新增: Math.abs((await region.boundingBox()).height - initialHeight) < 1, | |
| 63 | 新增: "floating options must not change layout height", | |
| 64 | 64 | ); |
| 65 | 65 | await picker.press("Home"); |
| 66 | 66 | await picker.press("Enter"); |
| @@ -13,7 +13,7 @@ for (const [platform, system] of [["darwin", "macos"], ["windows", "windows-11"] | ||
| 13 | 13 | beforeNavigate: async (page, state) => { |
| 14 | 14 | state.status.local_vm_storage = true; |
| 15 | 15 | await page.route("**/api/environment/storage", route => route.fulfill({ json: { directory: "/preview/cage-state", has_environment: false } })); |
| 16 | 删除: await page.route("**/api/environment/guest-systems", route => route.fulfill({ json: { fresh: true, available: true, system } })); | |
| 16 | 新增: await page.route("**/api/environment/guest-systems", route => route.fulfill({ json: { fresh: true, available: true, system, linux_systems: ["ubuntu-22.04"] } })); | |
| 17 | 17 | await page.route("**/api/environment/guest-systems/clone", route => route.fulfill({ json: { key: "matched-image", enough_space: true, minimum_free_gib: 51, free_gib: 120, download_bytes: 19769944180, plan: { host: { system, version: system === "windows-11" ? "25H2" : "26.5", build: "123", edition: "Professional", language: "zh-CN" }, version: "26.5", build: "456", bytes: 19769944180 } } })); |
| 18 | 18 | await page.route("**/api/start", route => { |
| 19 | 19 | starts++; |
| @@ -36,14 +36,21 @@ for (const [platform, system] of [["darwin", "macos"], ["windows", "windows-11"] | ||
| 36 | 36 | try { |
| 37 | 37 | assert.equal(await page.getByRole("complementary", { name: "项目与终端" }).count(), 0); |
| 38 | 38 | const picker = page.getByRole("combobox", { name: "客户机系统" }); |
| 39 | 删除: const storage = page.getByRole("region", { name: "本机环境存储" }); | |
| 40 | 删除: await storage.getByText("/preview/cage-state").waitFor(); | |
| 39 | 新增: const storage = page.getByRole("region", { name: "环境存储目录" }); | |
| 40 | 新增: await storage.getByLabel("存储目录", { exact: true }).waitFor(); | |
| 41 | 新增: assert.equal(await storage.getByLabel("存储目录", { exact: true }).inputValue(), "/preview/cage-state"); | |
| 42 | 新增: assert.equal(await storage.getByText("当前环境目录", { exact: true }).count(), 0); | |
| 43 | 新增: assert.equal(await storage.getByText("新存储位置", { exact: true }).count(), 0); | |
| 41 | 44 | const before = await storage.boundingBox(); |
| 42 | 45 | await picker.click(); |
| 43 | 46 | const option = page.getByRole("option", { name: "自动匹配本机系统版本", exact: true }); |
| 44 | 47 | await option.waitFor(); |
| 48 | 新增: for (const name of [/^Debian/, /^Ubuntu/, /^macOS/, /^Windows/]) assert.equal(await page.getByRole("option", { name }).count(), 1); | |
| 45 | 49 | const expanded = await storage.boundingBox(); |
| 46 | 删除: assert.ok(expanded.y > before.y); | |
| 50 | 新增: assert.ok(Math.abs(expanded.y - before.y) < 1, "floating system choices must not move storage"); | |
| 51 | 新增: const menu = await page.getByRole("listbox").boundingBox(); | |
| 52 | 新增: assert.ok(menu.x >= 0 && menu.y >= 0 && menu.x + menu.width <= 1280 && menu.y + menu.height <= 850, "floating menu must stay inside the viewport"); | |
| 53 | 新增: if (evidence) await page.screenshot({ path: `${evidence}/${platform}-systems-floating.png`, fullPage: true }); | |
| 47 | 54 | await picker.press("Home"); await picker.press("Enter"); |
| 48 | 55 | await page.getByText("Cage 会检测本机系统版本。配置代理后匹配官方镜像,并显示下载量与空间要求。").waitFor(); |
| 49 | 56 | if (system === "windows-11") await page.getByRole("checkbox").check(); |
| @@ -87,6 +94,44 @@ for (const [platform, system] of [["darwin", "macos"], ["windows", "windows-11"] | ||
| 87 | 94 | } finally { await browser.close(); } |
| 88 | 95 | } |
| 89 | 96 | |
| 97 | 新增:{ | |
| 98 | 新增: let location = { directory: "/preview/default-state", has_environment: false }, writes = 0, fail = true; | |
| 99 | 新增: const f = await createWorkbench({ initialization: { required: true, tracked: true }, beforeNavigate: async (page, state) => { | |
| 100 | 新增: state.status.local_vm_storage = true; | |
| 101 | 新增: await page.route("**/api/environment/guest-systems", route => route.fulfill({ json: { fresh: true, available: true, system: "macos", linux_systems: ["ubuntu-22.04"] } })); | |
| 102 | 新增: await page.route("**/api/environment/storage", route => { | |
| 103 | 新增: if (route.request().method() === "GET") return route.fulfill({ json: location }); | |
| 104 | 新增: const body = route.request().postDataJSON(); | |
| 105 | 新增: writes++; | |
| 106 | 新增: assert.equal(body.previous, "/preview/default-state"); | |
| 107 | 新增: assert.equal(body.migrate, false); | |
| 108 | 新增: if (fail) return route.fulfill({ status: 400, contentType: "text/plain; charset=utf-8", body: "请选择专用空文件夹" }); | |
| 109 | 新增: location = { ...location, directory: body.directory }; | |
| 110 | 新增: state.status.job = { id: "save-storage", kind: "storage", running: false }; | |
| 111 | 新增: return route.fulfill({ json: state.status.job }); | |
| 112 | 新增: }); | |
| 113 | 新增: } }); | |
| 114 | 新增: try { | |
| 115 | 新增: const input = f.page.getByLabel("存储目录", { exact: true }); | |
| 116 | 新增: assert.equal(await input.inputValue(), "/preview/default-state"); | |
| 117 | 新增: await input.fill("/preview/chosen-state"); | |
| 118 | 新增: assert.equal(writes, 0, "editing must not save before Next"); | |
| 119 | 新增: await f.page.getByRole("button", { name: "下一步:配置代理" }).click(); | |
| 120 | 新增: await f.page.getByRole("alert").filter({ hasText: "请选择专用空文件夹" }).waitFor(); | |
| 121 | 新增: assert.equal(await input.inputValue(), "/preview/chosen-state"); | |
| 122 | 新增: assert.equal(await f.page.getByRole("heading", { name: "连接你的网络代理" }).count(), 0); | |
| 123 | 新增: fail = false; | |
| 124 | 新增: await f.page.getByRole("button", { name: "下一步:配置代理" }).click(); | |
| 125 | 新增: await f.page.getByRole("heading", { name: "连接你的网络代理" }).waitFor(); | |
| 126 | 新增: assert.equal(location.directory, "/preview/chosen-state"); | |
| 127 | 新增: assert.equal(writes, 2); | |
| 128 | 新增: await f.page.getByRole("button", { name: "上一步", exact: true }).click(); | |
| 129 | 新增: assert.equal(await input.inputValue(), "/preview/chosen-state"); | |
| 130 | 新增: assert.deepEqual(f.errors, []); | |
| 131 | 新增: console.log("PASS storage: one default-filled directory, save on Next, rejected path preserved, retry and back navigation"); | |
| 132 | 新增: } finally { await f.browser.close(); } | |
| 133 | 新增:} | |
| 134 | 新增: | |
| 90 | 135 | { |
| 91 | 136 | let imported = false, applied = false; |
| 92 | 137 | const f = await createWorkbench({ initialization: { required: true, tracked: true }, beforeNavigate: async (page, state) => { |
| @@ -51,7 +51,7 @@ http.createServer(async (req, res) => { | ||
| 51 | 51 | else if (url.pathname === "/api/settings") value = { workspace: "/preview/workspace", browser_home_url: "https://www.bing.com/", timezone: "Asia/Shanghai", locale: "zh_CN.UTF-8", keyboard: status.keyboard }; |
| 52 | 52 | else if (url.pathname === "/api/appearance") value = { ...defaultAppearance, mode: "light" }; |
| 53 | 53 | else if (url.pathname === "/api/proxy") value = { active: true, selected: "preview-node", port: 17896, core_available: true, state: "prepared", sources: [{ id: "preview", name: "预览代理", nodes: [{ id: "preview-node", name: "预览节点", type: "http" }] }] }; |
| 54 | 删除: else if (url.pathname === "/api/environment/guest-systems") value = { fresh: !pending, available: true, system, pending }; | |
| 54 | 新增: else if (url.pathname === "/api/environment/guest-systems") value = { fresh: !pending, available: true, system, pending, linux_systems: ["ubuntu-22.04"] }; | |
| 55 | 55 | else if (url.pathname === "/api/environment/guest-systems/clone") value = { plan, key: "preview-only", enough_space: scenario !== "space", download_bytes: scenario === "cached" ? 0 : scenario === "resume" ? Math.floor(host.bytes / 3) : host.bytes, minimum_free_gib: 32 + Math.ceil(host.bytes / 1073741824), free_gib: scenario === "space" ? 10 : 120, installation_started: Boolean(pending) }; |
| 56 | 56 | else if (url.pathname === "/api/host/git") value = { state: "ok", ready: true, message: "本机 Git 安全保护已启用。" }; |
| 57 | 57 | else if (url.pathname === "/api/terminals") value = []; |
| @@ -6,7 +6,7 @@ import { smokeCaptureDirectory } from "./smoke-captures.mjs"; | ||
| 6 | 6 | const require = createRequire(import.meta.url); |
| 7 | 7 | const engines = require(process.env.CAGE_PLAYWRIGHT_MODULE || "playwright"); |
| 8 | 8 | const engine = process.env.CAGE_TEST_BROWSER || "chromium"; |
| 9 | 删除:const browser = await engines[engine].launch(); | |
| 9 | 新增:const browser = await engines[engine].launch({executablePath:process.env.CAGE_TEST_BROWSER_PATH}); | |
| 10 | 10 | const output = await smokeCaptureDirectory("mobile-inline-select"); |
| 11 | 11 | const origin = process.env.CAGE_UI_URL || "http://127.0.0.1:5399"; |
| 12 | 12 | const errors = []; |
| @@ -38,7 +38,7 @@ try { | ||
| 38 | 38 | const create = page.getByRole("button", { name: "新建会话", exact: true }); |
| 39 | 39 | const collapsed = await create.boundingBox(); |
| 40 | 40 | await picker.press("Enter"); |
| 41 | 删除: assert.ok((await create.boundingBox()).y > collapsed.y); | |
| 41 | 新增: assert.ok(Math.abs((await create.boundingBox()).y-collapsed.y)<1); | |
| 42 | 42 | await picker.press("End"); |
| 43 | 43 | await picker.press("Enter"); |
| 44 | 44 | await picker.getByText("gamma", { exact: true }).waitFor(); |
| @@ -49,9 +49,10 @@ try { | ||
| 49 | 49 | assert.equal(await picker.getAttribute("aria-expanded"), "false"); |
| 50 | 50 | assert.equal((await create.boundingBox()).y, collapsed.y); |
| 51 | 51 | await picker.tap(); |
| 52 | 新增: await picker.tap(); | |
| 52 | 53 | await create.tap(); |
| 53 | 54 | await page.getByRole("textbox", { name: "消息", exact: true }).waitFor(); |
| 54 | 删除: assert.equal(creations, 1, "one tap after an expanded project selector must create exactly one session"); | |
| 55 | 新增: assert.equal(creations, 1, "one tap after closing the project selector must create exactly one session"); | |
| 55 | 56 | assert.equal(sessions[0].workspace, "/work/gamma"); |
| 56 | 57 | await page.screenshot({ path: join(output, `${engine}-new-session.png`) }); |
| 57 | 58 | await page.close(); |
| @@ -86,12 +87,13 @@ try { | ||
| 86 | 87 | await phone.getByRole("button", { name: "收藏夹", exact: true }).tap(); |
| 87 | 88 | await phone.getByRole("button", { name: "收藏此页", exact: true }).tap(); |
| 88 | 89 | await phone.getByRole("combobox", { name: "保存到", exact: true }).tap(); |
| 90 | 新增: await phone.getByRole("combobox", { name: "保存到", exact: true }).tap(); | |
| 89 | 91 | await phone.getByRole("button", { name: "保存收藏", exact: true }).tap(); |
| 90 | 92 | await phone.getByRole("button", { name: "取消此页收藏", exact: true }).waitFor(); |
| 91 | 删除: assert.equal(writes, 1, "one tap after the expanded folder selector must save exactly once"); | |
| 93 | 新增: assert.equal(writes, 1, "one tap after closing the folder selector must save exactly once"); | |
| 92 | 94 | await phone.screenshot({ path: join(output, `${engine}-saved-favorite.png`) }); |
| 93 | 95 | assert.deepEqual(errors, []); |
| 94 | 删除: console.log(`${engine}: inline layout, keyboard selection, Escape, focus restoration and first-tap session/favorite mutations passed.`); | |
| 96 | 新增: console.log(`${engine}: floating layout, keyboard selection, Escape, focus restoration and session/favorite mutations passed.`); | |
| 95 | 97 | } finally { |
| 96 | 98 | await browser.close(); |
| 97 | 99 | } |
| @@ -48,7 +48,7 @@ try { | ||
| 48 | 48 | const before=await relativeExit(); |
| 49 | 49 | await via.click(); |
| 50 | 50 | const after=await relativeExit(); |
| 51 | 删除: assert.ok(after-before>80,'dropdown must push the following exit down'); | |
| 51 | 新增: assert.ok(Math.abs(after-before)<1,'floating dropdown must not move the following exit'); | |
| 52 | 52 | const list=await page.getByRole('listbox',{name:'中转节点选项'}).boundingBox(); |
| 53 | 53 | const container=await page.locator('.proxy-route').boundingBox(); |
| 54 | 54 | assert.ok(list.x>=container.x && list.x+list.width<=container.x+container.width,'dropdown escapes its container'); |
| @@ -131,5 +131,5 @@ try { | ||
| 131 | 131 | await page.evaluate(()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve)))); |
| 132 | 132 | await page.screenshot({path:path.join(output,'dark.png'),animations:'disabled'}); |
| 133 | 133 | assert.deepEqual(errors,[]); |
| 134 | 删除: console.log(JSON.stringify({passed:true,submissions:submissions.length,checks:['network-check exit-rules entry','cross-source route draft','inline layout reflow','keyboard selection and focus','explicit atomic apply','reload persistence','failed apply keeps draft','retry','multiple transit nodes','undo','leave and section-change confirmation','saving DNS preserves route draft','single-node mode','narrow viewport'],browserErrors:errors})); | |
| 134 | 新增: console.log(JSON.stringify({passed:true,submissions:submissions.length,checks:['network-check exit-rules entry','cross-source route draft','floating options keep layout fixed','keyboard selection and focus','explicit atomic apply','reload persistence','failed apply keeps draft','retry','multiple transit nodes','undo','leave and section-change confirmation','saving DNS preserves route draft','single-node mode','narrow viewport'],browserErrors:errors})); | |
| 135 | 135 | } finally {await browser.close();} |
| @@ -43,16 +43,15 @@ try { | ||
| 43 | 43 | await page.getByLabel("SSH 用户名", { exact: true }).fill("cage-test"); |
| 44 | 44 | const auth = page.getByRole("combobox", { name: "SSH 登录方式" }); |
| 45 | 45 | const keyField = page.getByLabel("本机私钥文件", { exact: true }); |
| 46 | 删除: // The centered dialog itself moves when its height changes. Compare gaps | |
| 47 | 删除: // inside the dialog to check whether the list takes up layout space. | |
| 46 | 新增: // Opening the floating list keeps both the dialog and its fields in place. | |
| 48 | 47 | const gap = async () => (await keyField.boundingBox()).y - (await auth.boundingBox()).y; |
| 49 | 48 | const before = await gap(); |
| 50 | 49 | await auth.click(); |
| 51 | 50 | await page.getByRole("option", { name: "本机 SSH agent" }).waitFor(); |
| 52 | 51 | const expanded = await keyField.boundingBox(); |
| 53 | 删除: assert.ok(await gap() > before + 30, "inline choices must push subsequent fields down"); | |
| 52 | 新增: assert.ok(Math.abs(await gap() - before) < 1, "floating choices must not move subsequent fields"); | |
| 54 | 53 | const list = await page.getByRole("listbox").boundingBox(); |
| 55 | 删除: assert.ok(list.y + list.height <= expanded.y, "choices must not cover the next field"); | |
| 54 | 新增: assert.ok(list.height > 0 && Math.abs(expanded.y - (await keyField.boundingBox()).y) < 1); | |
| 56 | 55 | await auth.press("Escape"); |
| 57 | 56 | assert.equal(await auth.getAttribute("aria-expanded"), "false"); |
| 58 | 57 | await page.getByRole("listbox").waitFor({state:"hidden"}); |
| @@ -28,7 +28,7 @@ for (const [platform, system] of [["darwin", "macos"], ["windows", "windows-11"] | ||
| 28 | 28 | await option.waitFor(); |
| 29 | 29 | const box = await option.boundingBox(); |
| 30 | 30 | const expanded = await storage.boundingBox(); |
| 31 | 删除: assert.ok(expanded.y > initial.y && box.y + box.height <= expanded.y, "inline options overlap the next control"); | |
| 31 | 新增: assert.ok(Math.abs(expanded.y - initial.y) < 1 && box.height > 0, "floating options must not move the next control"); | |
| 32 | 32 | await picker.press("Escape"); |
| 33 | 33 | assert.equal((await storage.boundingBox()).y, initial.y); |
| 34 | 34 | await picker.press("Enter"); |
| @@ -385,5 +385,5 @@ export async function createWorkbench({ | ||
| 385 | 385 | |
| 386 | 386 | export async function chooseInline(picker, value) { |
| 387 | 387 | await picker.click(); |
| 388 | 删除: await picker.locator("..").getByRole("option").and(picker.page().locator(`[data-value=${JSON.stringify(String(value))}]`)).click(); | |
| 388 | 新增: await picker.page().getByRole("option").and(picker.page().locator(`[data-value=${JSON.stringify(String(value))}]`)).click(); | |
| 389 | 389 | } |
| @@ -91,13 +91,14 @@ export function GuestSystemPicker({ system, onChange, preserveOnUnmount = false, | ||
| 91 | 91 | return ( |
| 92 | 92 | <div className="guest-system-picker"> |
| 93 | 93 | <span>客户机系统</span> |
| 94 | 删除: {view.system || view.linux_systems?.length ? <InlineSelect aria-label="客户机系统" value={system.clone ? "host" : os} disabled={system.pending} | |
| 94 | 新增: <InlineSelect aria-label="客户机系统" value={system.clone ? "host" : os} disabled={system.pending} | |
| 95 | 95 | onValueChange={(value) => onChange({ guest_system: value === "host" ? view.system : value, clone: value === "host", clone_key: "", clone_ready: false, media: "", sha256: "", editor_terms: false })}> |
| 96 | 96 | {Boolean(view.system) && <option value="host" disabled={!view.available}>自动匹配本机系统版本{view.available ? "" : "(暂不可用)"}</option>} |
| 97 | 97 | <option value="debian-13">Debian 13</option> |
| 98 | 删除: {(view.linux_systems || []).map((id) => <option key={id} value={id}>{names[id]}</option>)} | |
| 99 | 删除: {["macos", "windows-11"].includes(view.system) && <option value={view.system} disabled={!view.available}>{names[view.system]}{view.available ? "" : "(暂不可用)"}</option>} | |
| 100 | 删除: </InlineSelect> : <strong>Debian 13</strong>} | |
| 98 | 新增: <option value="ubuntu-22.04" disabled={!view.linux_systems?.includes("ubuntu-22.04")}>Ubuntu 22.04{view.linux_systems?.includes("ubuntu-22.04") ? "" : "(此构建暂不可用)"}</option> | |
| 99 | 新增: <option value="macos" disabled={view.system !== "macos" || !view.available}>macOS{view.system === "macos" ? view.available ? "" : "(暂不可用)" : "(需要 Apple Silicon Mac)"}</option> | |
| 100 | 新增: <option value="windows-11" disabled={view.system !== "windows-11" || !view.available}>Windows 11{view.system === "windows-11" ? view.available ? "" : "(暂不可用)" : "(需要 Windows 11 与 Hyper-V)"}</option> | |
| 101 | 新增: </InlineSelect> | |
| 101 | 102 | {system.clone && !system.activate && (deferMatch ? <small className="guest-install-fields">Cage 会检测本机系统版本。配置代理后匹配官方镜像,并显示下载量与空间要求。</small> : <HostCloneSummary pending={system.pending} onChange={onChange} />)} |
| 102 | 103 | {!system.clone && os !== "debian-13" && !system.activate && <div className="guest-install-fields"> |
| 103 | 104 | {os === "ubuntu-22.04" ? <> |
| @@ -0,0 +1,33 @@ | ||
| 1 | 新增:import React, { useEffect, useState } from "react"; | |
| 2 | 新增:import { FolderOpen } from "lucide-react"; | |
| 3 | 新增:import { api, native, nativeAvailable } from "./api"; | |
| 4 | 新增: | |
| 5 | 新增:export function InitializationStorage({ value, onChange, disabled }) { | |
| 6 | 新增: const [error, setError] = useState(""); | |
| 7 | 新增: const [attempt, retry] = useState(0); | |
| 8 | 新增: useEffect(() => { | |
| 9 | 新增: if (value) return; | |
| 10 | 新增: let live = true; | |
| 11 | 新增: api("/environment/storage").then(location => { | |
| 12 | 新增: if (live) onChange({ location, directory: location.directory }); | |
| 13 | 新增: }).catch(error => { if (live) setError(error.message); }); | |
| 14 | 新增: return () => { live = false; }; | |
| 15 | 新增: }, [Boolean(value), onChange, attempt]); | |
| 16 | 新增: const locked = disabled || !value || value.location.has_environment; | |
| 17 | 新增: async function choose() { | |
| 18 | 新增: try { | |
| 19 | 新增: const directory = await native("chooseFolder", { purpose: "environmentStorage" }); | |
| 20 | 新增: if (directory) { onChange({ ...value, directory }); setError(""); } | |
| 21 | 新增: } catch (error) { setError(error.message); } | |
| 22 | 新增: } | |
| 23 | 新增: return <section className="initialization-storage" aria-label="环境存储目录"> | |
| 24 | 新增: <label htmlFor="initialization-directory">存储目录</label> | |
| 25 | 新增: <p>系统镜像、下载缓存和虚拟磁盘保存在这里。已填入默认目录,也可以选择其他本地磁盘上的专用空文件夹。</p> | |
| 26 | 新增: <div className="initialization-directory-control"> | |
| 27 | 新增: <input id="initialization-directory" value={value?.directory || ""} disabled={locked} spellCheck={false} placeholder={value ? "请输入存储目录的完整路径" : "正在读取默认目录…"} onChange={event => onChange({ ...value, directory: event.target.value })} /> | |
| 28 | 新增: {nativeAvailable() && <button type="button" disabled={locked} onClick={choose}><FolderOpen size={16} />选择文件夹</button>} | |
| 29 | 新增: </div> | |
| 30 | 新增: {value?.location.has_environment && <p>已有虚拟磁盘,继续使用原存储目录。完成初始化后可在设置中迁移。</p>} | |
| 31 | 新增: {error && <p role="alert">{error}<button onClick={() => { setError(""); retry(value => value + 1); }}>重新读取</button></p>} | |
| 32 | 新增: </section>; | |
| 33 | 新增:} | |
| @@ -17,6 +17,13 @@ | ||
| 17 | 17 | .initialization .guest-install-fields small { font-size: 14px; line-height: 1.65; } |
| 18 | 18 | .initialization .host-clone-summary { padding: 18px; gap: 10px; background: var(--chrome); } |
| 19 | 19 | .initialization .environment-storage { padding-top: 22px; border-top: 1px solid var(--line); } |
| 20 | 新增:.initialization-storage { padding-top: 22px; border-top: 1px solid var(--line); } | |
| 21 | 新增:.initialization-storage > label { font-size: 16px; font-weight: 550; color: var(--strong); } | |
| 22 | 新增:.initialization-storage > p { color: var(--muted); font-size: 14px; margin: 8px 0 16px; } | |
| 23 | 新增:.initialization-directory-control { display: flex; gap: 10px; } | |
| 24 | 新增:.initialization-directory-control input { flex: 1; min-width: 0; min-height: 42px; box-sizing: border-box; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; background: var(--input); color: var(--ink); font: inherit; } | |
| 25 | 新增:.initialization-directory-control button { flex: none; } | |
| 26 | 新增:@media (max-width: 500px) { .initialization-directory-control { flex-wrap: wrap; } .initialization-directory-control input { flex-basis: 100%; } } | |
| 20 | 27 | .initialization .environment-storage > h4 { font-size: 16px; margin: 0 0 8px; } |
| 21 | 28 | .initialization .field-help { color: var(--muted); font-size: 14px; } |
| 22 | 29 | .initialization .environment-storage label { display: grid; gap: 8px; margin: 16px 0 10px; } |
| @@ -4,7 +4,7 @@ import { api, native, nativeAvailable } from "./api"; | ||
| 4 | 4 | import { isRemoteClient } from "./client-context.mjs"; |
| 5 | 5 | import { useAccount } from "./account"; |
| 6 | 6 | import { GuestSystemPicker, HostCloneSummary, validGuestChoice } from "./guest-system-picker"; |
| 7 | 删除:import { EnvironmentStorage } from "./environment-storage"; | |
| 7 | 新增:import { InitializationStorage } from "./initialization-storage"; | |
| 8 | 8 | import { ProxySettings } from "./proxy-settings"; |
| 9 | 9 | import { SetupProgress } from "./setup-progress"; |
| 10 | 10 | import { DiagnosticSettings } from "./diagnostics.jsx"; |
| @@ -54,6 +54,7 @@ function Initialization({ initial, onComplete }) { | ||
| 54 | 54 | const [status, setStatus] = useState(null); |
| 55 | 55 | const [proxy, setProxy] = useState(null); |
| 56 | 56 | const [choice, setChoice] = useState(undefined); |
| 57 | 新增: const [storage, setStorage] = useState(null); | |
| 57 | 58 | const [pending, setPending] = useState(null); |
| 58 | 59 | const [submitting, setSubmitting] = useState(false); |
| 59 | 60 | const [error, setError] = useState(""); |
| @@ -174,6 +175,27 @@ function Initialization({ initial, onComplete }) { | ||
| 174 | 175 | setProxyDirty(false); |
| 175 | 176 | setStep(step === "install" ? "proxy" : pending || account?.guest_system ? "install" : "system"); |
| 176 | 177 | } |
| 178 | 新增: async function nextFromSystem() { | |
| 179 | 新增: await run(async () => { | |
| 180 | 新增: const directory = storage.directory.trim(); | |
| 181 | 新增: if (directory !== storage.location.directory) { | |
| 182 | 新增: const accepted = await api("/environment/storage", { directory, previous: storage.location.directory, migrate: false }); | |
| 183 | 新增: let job; | |
| 184 | 新增: do { | |
| 185 | 新增: await new Promise(resolve => setTimeout(resolve, 300)); | |
| 186 | 新增: if (!alive.current) return; | |
| 187 | 新增: const next = await api("/status"); | |
| 188 | 新增: setStatus(next); job = next.job; | |
| 189 | 新增: if (job.id !== accepted.id) throw new Error("存储操作状态已变化,请核对目录后重试。"); | |
| 190 | 新增: } while (job.running); | |
| 191 | 新增: if (job.error) throw new Error(job.error); | |
| 192 | 新增: const location = await api("/environment/storage"); | |
| 193 | 新增: if (location.directory !== directory) throw new Error("存储目录尚未保存,请重新选择后重试。"); | |
| 194 | 新增: setStorage({ location, directory: location.directory }); | |
| 195 | 新增: } | |
| 196 | 新增: setStep("proxy"); | |
| 197 | 新增: }); | |
| 198 | 新增: } | |
| 177 | 199 | const failed = Boolean(job.error || error); |
| 178 | 200 | const progress = job.setup_progress && { ...job, setup_progress: job.setup_progress }; |
| 179 | 201 | const title = step === "system" ? "为 Cage 准备独立环境" : step === "proxy" ? "连接你的网络代理" : ready ? "Cage 已准备就绪" : failed ? "继续完成环境安装" : busy ? "正在准备你的环境" : "安装并检查客机环境"; |
| @@ -187,7 +209,7 @@ function Initialization({ initial, onComplete }) { | ||
| 187 | 209 | <div className="initialization-stage" key={step}> |
| 188 | 210 | {step === "system" && <> |
| 189 | 211 | <GuestSystemPicker system={choice} onChange={setChoice} preserveOnUnmount deferMatch /> |
| 190 | 删除: <EnvironmentStorage status={status} onConfirm={confirm} /> | |
| 212 | 新增: <InitializationStorage value={storage} onChange={setStorage} disabled={busy} /> | |
| 191 | 213 | </>} |
| 192 | 214 | {step === "proxy" && <><ProxySettings initializing status={status} onConfirm={confirm} onDirty={setProxyDirty} onApplied={async () => { setProxy(await api("/proxy")); pollNow.current?.(); }} />{choice?.clone && !needsProxySetup(null, status, proxy) && <HostCloneSummary pending={choice.pending} onChange={setChoice} />}</>} |
| 193 | 215 | {step === "install" && (ready ? <div className="initialization-ready"><ShieldCheck size={36} /><h2>环境已就绪</h2><p>独立客机已安装,工具、文件和登录状态会持续保存。以后打开 Cage 可直接进入工作台。</p></div> : <> |
| @@ -201,7 +223,7 @@ function Initialization({ initial, onComplete }) { | ||
| 201 | 223 | {error && <p className="initialization-notice" role="alert"><SafetyMessage message={error} /></p>} |
| 202 | 224 | <footer className="initialization-actions"> |
| 203 | 225 | {step === "system" ? <span /> : <button className="text-button" disabled={busy} onClick={back}><ChevronLeft size={16} />上一步</button>} |
| 204 | 删除: {step === "system" && <button className="primary" disabled={busy || choice === undefined || (!choice?.clone && !validGuestChoice(choice)) || choice?.clone && choice.guest_system === "windows-11" && !choice.editor_terms || Boolean(connectionError)} onClick={() => setStep("proxy")}>下一步:配置代理</button>} | |
| 226 | 新增: {step === "system" && <button className="primary" disabled={busy || !storage?.directory.trim() || choice === undefined || (!choice?.clone && !validGuestChoice(choice)) || choice?.clone && choice.guest_system === "windows-11" && !choice.editor_terms || Boolean(connectionError)} onClick={nextFromSystem}>{submitting && <LoaderCircle size={16} className="spin" />}下一步:配置代理</button>} | |
| 205 | 227 | {step === "proxy" && <button className="primary" disabled={busy || proxyDirty || !account?.guest_system && !pending && !validGuestChoice(choice) || needsProxySetup(null, status, proxy) || Boolean(connectionError)} onClick={install}>{submitting ? <LoaderCircle size={16} className="spin" /> : null}开始安装</button>} |
| 206 | 228 | {step === "install" && ready && <button className="primary" disabled={submitting || Boolean(connectionError)} onClick={enter}>进入工作台</button>} |
| 207 | 229 | </footer> |
| @@ -16,9 +16,11 @@ | ||
| 16 | 16 | .inline-select-trigger svg { flex: none; } |
| 17 | 17 | .inline-select-trigger[aria-expanded="true"] svg { transform: rotate(180deg); } |
| 18 | 18 | .inline-select-list { |
| 19 | 删除: position: relative; | |
| 19 | 新增: position: fixed; | |
| 20 | 新增: z-index: 10000; | |
| 20 | 21 | display: grid; |
| 21 | 删除: margin-top: 3px; | |
| 22 | 新增: box-sizing: border-box; | |
| 23 | 新增: margin: 0; | |
| 22 | 24 | padding: 3px; |
| 23 | 25 | max-height: min(14rem, 32vh); |
| 24 | 26 | overflow: auto; |
| @@ -29,6 +31,8 @@ | ||
| 29 | 31 | font-size: inherit; |
| 30 | 32 | font-weight: 400; |
| 31 | 33 | text-align: start; |
| 34 | 新增: box-shadow: 0 8px 24px #00000020, 0 2px 6px #0000000c; | |
| 35 | 新增: overscroll-behavior: contain; | |
| 32 | 36 | } |
| 33 | 37 | .inline-select-list [role="option"] { |
| 34 | 38 | display: flex; |
| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | import React, { Children, useEffect, useId, useRef, useState } from "react"; |
| 2 | 新增:import { createPortal } from "react-dom"; | |
| 3 | 新增:import { useSelectPopup } from "./select-popup"; | |
| 2 | 4 | import { Check, ChevronDown } from "lucide-react"; |
| 3 | 5 | import "./inline-select.css"; |
| 4 | 6 | |
| 5 | 删除:// Keep focus on the control while its list occupies space below it. | |
| 7 | 新增:// Keep keyboard focus on the control; the popup does not change page layout. | |
| 6 | 8 | export function InlineSelect({ |
| 7 | 9 | children, |
| 8 | 10 | value, |
| @@ -43,6 +45,7 @@ export function InlineSelect({ | ||
| 43 | 45 | const active = filtered.findIndex( |
| 44 | 46 | (item) => item.value === cursor && !item.disabled, |
| 45 | 47 | ); |
| 48 | 新增: const position = useSelectPopup(visible, control, list, filtered.length); | |
| 46 | 49 | useEffect(() => { |
| 47 | 50 | if (visible && active >= 0) { |
| 48 | 51 | const row = list.current.querySelector(`[data-index="${active}"]`); |
| @@ -58,9 +61,8 @@ export function InlineSelect({ | ||
| 58 | 61 | }, [visible, active]); |
| 59 | 62 | useEffect(() => { |
| 60 | 63 | if (!open) return; |
| 61 | 删除: // Collapse after the outside click lands so reflow cannot move its target. | |
| 62 | 64 | const outside = (event) => { |
| 63 | 删除: if (!root.current.contains(event.target)) setOpen(false); | |
| 65 | 新增: if (!root.current.contains(event.target) && !list.current?.contains(event.target)) setOpen(false); | |
| 64 | 66 | }; |
| 65 | 67 | document.addEventListener("click", outside, true); |
| 66 | 68 | return () => document.removeEventListener("click", outside, true); |
| @@ -153,13 +155,14 @@ export function InlineSelect({ | ||
| 153 | 155 | <ChevronDown size={14} aria-hidden="true" /> |
| 154 | 156 | </button> |
| 155 | 157 | )} |
| 156 | 删除: {visible && ( | |
| 158 | 新增: {visible && createPortal( | |
| 157 | 159 | <span |
| 158 | 160 | ref={list} |
| 159 | 161 | id={id} |
| 160 | 162 | role="listbox" |
| 161 | 163 | aria-label={(props["aria-label"] || "") + "选项"} |
| 162 | 164 | className="inline-select-list" |
| 165 | 新增: style={position} | |
| 163 | 166 | onMouseDown={(event) => event.preventDefault()} |
| 164 | 167 | onClick={(event) => event.preventDefault()} |
| 165 | 168 | > |
| @@ -190,7 +193,7 @@ export function InlineSelect({ | ||
| 190 | 193 | </span> |
| 191 | 194 | </React.Fragment> |
| 192 | 195 | ))} |
| 193 | 删除: </span> | |
| 196 | 新增: </span>, document.body | |
| 194 | 197 | )} |
| 195 | 198 | </span> |
| 196 | 199 | ); |
| @@ -1,11 +1,14 @@ | ||
| 1 | 1 | import React, { useEffect, useId, useRef, useState } from "react"; |
| 2 | 新增:import { createPortal } from "react-dom"; | |
| 2 | 3 | import { Check, ChevronDown } from "lucide-react"; |
| 4 | 新增:import { useSelectPopup } from "../select-popup"; | |
| 3 | 5 | |
| 4 | 删除:// Options follow the trigger in normal flow and keep the combobox focused. | |
| 6 | 新增:// The floating options keep the combobox focused without shifting the page. | |
| 5 | 7 | export function InlineSelect({ label, value, options, onChange, onLongPress, footer, disabled, icon }) { |
| 6 | 8 | const id = useId(); |
| 7 | 9 | const root = useRef(null); |
| 8 | 10 | const trigger = useRef(null); |
| 11 | 新增: const list = useRef(null); | |
| 9 | 12 | const hold = useRef(null); |
| 10 | 13 | const held = useRef(false); |
| 11 | 14 | const origin = useRef(null); |
| @@ -13,11 +16,11 @@ export function InlineSelect({ label, value, options, onChange, onLongPress, foo | ||
| 13 | 16 | const [cursor, setCursor] = useState(value); |
| 14 | 17 | const selected = options.find(item => item.value === value); |
| 15 | 18 | const visible = open && !disabled; |
| 19 | 新增: const position = useSelectPopup(visible, trigger, list, options.length); | |
| 16 | 20 | const cancelHold = () => { clearTimeout(hold.current); hold.current = null; }; |
| 17 | 21 | useEffect(() => { |
| 18 | 22 | if (!visible) return; |
| 19 | 删除: const outside = event => { if (!root.current.contains(event.target)) setOpen(false); }; | |
| 20 | 删除: // Let the outside click reach its target before the inline list reflows. | |
| 23 | 新增: const outside = event => { if (!root.current.contains(event.target) && !list.current?.contains(event.target)) setOpen(false); }; | |
| 21 | 24 | document.addEventListener("click", outside, true); |
| 22 | 25 | return () => document.removeEventListener("click", outside, true); |
| 23 | 26 | }, [visible]); |
| @@ -80,7 +83,7 @@ export function InlineSelect({ label, value, options, onChange, onLongPress, foo | ||
| 80 | 83 | onClick={() => {if (held.current) {held.current = false; return;} setCursor(value); setOpen(!visible);}}> |
| 81 | 84 | {icon}<span>{selected?.label || label}</span><ChevronDown size={14} aria-hidden="true" /> |
| 82 | 85 | </button> |
| 83 | 删除: {visible && <div className="inline-select-popover"> | |
| 86 | 新增: {visible && createPortal(<div className="inline-select-popover" ref={list} style={position}> | |
| 84 | 87 | <div className="inline-select-options" role="listbox" id={id} aria-label={label + "选项"}> |
| 85 | 88 | {options.map((item, index) => <div key={item.value} role="option" id={id + "-" + index} |
| 86 | 89 | aria-selected={item.value === value} data-active={item.value === cursor || undefined} |
| @@ -90,6 +93,6 @@ export function InlineSelect({ label, value, options, onChange, onLongPress, foo | ||
| 90 | 93 | </div>)} |
| 91 | 94 | </div> |
| 92 | 95 | {footer && <p className="inline-select-hint" id={id + "-hint"}>{footer}</p>} |
| 93 | 删除: </div>} | |
| 96 | 新增: </div>, document.body)} | |
| 94 | 97 | </div>; |
| 95 | 98 | } |
| @@ -67,7 +67,7 @@ h2 { font-size: 17px; line-height: 1.45; font-weight: 620; } | ||
| 67 | 67 | .inline-select-trigger > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; } |
| 68 | 68 | .inline-select-trigger svg { flex: none; } |
| 69 | 69 | .inline-select-trigger[aria-expanded="true"] > svg:last-child { transform: rotate(180deg); } |
| 70 | 删除:.inline-select-popover { width: 100%; margin: 3px 0 5px; border: 1px solid var(--line); border-radius: 10px; padding: 4px; background: var(--paper); } | |
| 70 | 新增:.inline-select-popover { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 4px; background: var(--paper); color: var(--ink); overflow: auto; box-shadow: 0 8px 24px #00000020; overscroll-behavior: contain; } | |
| 71 | 71 | .inline-select-options { max-height: min(280px, 38vh); overflow-y: auto; } |
| 72 | 72 | .inline-select-options [role="option"] { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; padding: 10px 12px; border-radius: 8px; font-size: 14px; overflow-wrap: anywhere; cursor: pointer; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } |
| 73 | 73 | .inline-select-options [role="option"] svg { flex: none; } |
| @@ -0,0 +1,31 @@ | ||
| 1 | 新增:import { useLayoutEffect, useState } from "react"; | |
| 2 | 新增: | |
| 3 | 新增:// Both desktop and mobile mount the list outside scroll/overflow containers. | |
| 4 | 新增:export function useSelectPopup(visible, control, list, count) { | |
| 5 | 新增: const [position, setPosition] = useState(null); | |
| 6 | 新增: useLayoutEffect(() => { | |
| 7 | 新增: if (!visible) return; | |
| 8 | 新增: const place = () => { | |
| 9 | 新增: const rect = control.current.getBoundingClientRect(); | |
| 10 | 新增: const style = getComputedStyle(control.current); | |
| 11 | 新增: const gap = 4, margin = 8; | |
| 12 | 新增: const below = window.innerHeight - rect.bottom - gap - margin; | |
| 13 | 新增: const above = rect.top - gap - margin; | |
| 14 | 新增: const upward = below < Math.min(list.current.scrollHeight + 8, 224) && above > below; | |
| 15 | 新增: const maxHeight = Math.max(40, Math.min(280, upward ? above : below)); | |
| 16 | 新增: const width = Math.min(rect.width, window.innerWidth - margin * 2); | |
| 17 | 新增: const height = Math.min(list.current.scrollHeight + 8, maxHeight); | |
| 18 | 新增: const next = { position: "fixed", zIndex: 10000, boxSizing: "border-box", margin: 0, left: Math.max(margin, Math.min(rect.left, window.innerWidth - width - margin)), top: upward ? Math.max(margin, rect.top - gap - height) : rect.bottom + gap, width, maxHeight, fontFamily: style.fontFamily, fontSize: style.fontSize, lineHeight: style.lineHeight }; | |
| 19 | 新增: for (const key of ["--ink", "--paper", "--line", "--selected", "--focus", "--muted", "--control-cursor"]) next[key] = style.getPropertyValue(key); | |
| 20 | 新增: setPosition(next); | |
| 21 | 新增: }; | |
| 22 | 新增: const scroll = event => { if (!list.current?.contains(event.target)) place(); }; | |
| 23 | 新增: place(); | |
| 24 | 新增: const observer = new ResizeObserver(place); | |
| 25 | 新增: observer.observe(control.current); | |
| 26 | 新增: window.addEventListener("resize", place); | |
| 27 | 新增: document.addEventListener("scroll", scroll, true); | |
| 28 | 新增: return () => { observer.disconnect(); window.removeEventListener("resize", place); document.removeEventListener("scroll", scroll, true); }; | |
| 29 | 新增: }, [visible, control, list, count]); | |
| 30 | 新增: return position || { visibility: "hidden" }; | |
| 31 | 新增:} | |

