The owner, 11-12, on the Providers page's Add sheet: 向上滑动,然后这些区域 不在可视区域的时候,这些区域应该自动浮现在Header处. Beside the sidebar (side-nav, a window 1024px wide or more), the sheet's search, Custom provider and Import… now show in the title bar's empty right, left of its buttons, once the sheet's head row has scrolled out of sight. They are put there the way Library's, Plugins' and Settings' tools are: position: fixed inside --tools-l/--tools-r/--top-h, which app.js tools() keeps out of the crumb's way (its head query now includes #addSheet .add-tools.afloat). Scrolled back up, they are in their row again. Close stays in the sheet; the screenshot's box didn't cover it. The group is pinned, never copied, so there is one search: the words typed and the focus stay with it both ways. Each change is a 180ms fade in going into the bar and 140ms coming back, cubic-bezier(.23, 1, .32, 1), opacity only, so reduced motion keeps it. Nothing moves in the sheet: the head row keeps its height while its tools are up. Narrow (no sidebar, which covers 420px and the panel): the bar has no free room, so the sheet's whole head (label, tools, Close) is held at the top of the page while the sheet is under it, the way Settings' head is in a narrow window. It has the same blur strip and a hairline once stuck. At 760px and under, the tools take a line of their own under the label. The code is in a new addfloat.js, which renderAdd imports the first time the sheet opens. In app.js it took TestCoreScriptBudget 487 bytes over (1266031 > 1265544); with the move the budget passes and isn't raised. old-webkit's list of scripts loaded on demand names it. Run at 39ac4fafe (on origin/main2d2333cfa), then again after rebasing onbe8e352a2: - New add-sheet-float.test.cjs: 22/22 (chromium and webkit; en, zh, zh-TW, ja, de; 1100px and 420px). It scrolls with the real wheel. In the bar, it checks the search is in the title bar left of its buttons and right of the crumb, with Custom provider and Import… there too; narrow, that the head is held at the top. Then: the search is clear to press, a click scrolls nothing and takes the focus, typing "Relay 2" filters the tiles with one search kept, and scrolling back puts it in its row with the words and focus. - Red on the old code (git archive of the base's internal/gui): 0/22, on "in the bar once out of sight" (wide) and "the head held at the page's top" (narrow). - go test ./internal/gui -run Budget: ok (mica). - Related GUI files on mote, both engines, 380 tests, 376 pass: add-sheet, add-sheet-custom, add-button, add-partners-shine, add-sponsor-me, the six providers-*, i18n-keys, provider-detect-draft, provider-env-paste, provider-add-gemini, provider-retrieval-only, provider-url-each-api, modal-title-drag, model-id-space, builtins, old-webkit. The four reds are filed and come from other changes: - add-sheet "quiet rows" chromium en: tlscerts.js reads a null draft's serverPin (#6216). It was red in en, and in zh after the rebase, both times beside other files. Alone, chromium, 2/2 green on origin/main and 2/2 here; - old-webkit: headerpresets.js isn't in its list (#6030); - old-webkit: .side-foot:has() in app.css (#5919). - After rebasing onbe8e352a2: Budget ok; add-sheet-float, add-sheet, old-webkit and i18n-keys 34/38, the same three filed reds. - i18n-keys first ran out of memory under mote-run -C internal/gui: it walks ../../.., which there is all of ~/runs. Run from the tree's root: 4/4. Not tried: the real app (Wails on macOS, WebKitGTK on Linux, WebView2 on Windows). Only Playwright's engines were run, so the title bar's dragging around the pinned tools (--wails-draggable) wasn't checked in a real window.
164 lines
9.8 KiB
JavaScript
164 lines
9.8 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// The add sheet's tools follow the reader down (the owner, 11-12: 向上滑动,
|
|
// 然后这些区域不在可视区域的时候,这些区域应该自动浮现在Header处). Beside
|
|
// the sidebar, the sheet's search, Custom provider and Import… scrolled out
|
|
// of sight show in the title bar's empty right, left of its buttons, where
|
|
// Settings' search is; scrolled back they are in their row again. They are
|
|
// the same nodes, so there is one search: what was typed and the focus go
|
|
// with it. A narrow window has no room in its bar, so the sheet's head is
|
|
// held at the top of the page while the sheet is under it. The page is
|
|
// scrolled with the wheel, as a reader does (the app puts back any other
|
|
// scroll), and nothing scrolls on a click. Every language, both engines,
|
|
// wide and narrow; no backend, the API is faked here.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
|
|
const preset = (id, name, kind) => ({ id, name, icon: "openai", kind, chat: `https://api.${id}.example.com/v1`, added: false });
|
|
// enough rows that the sheet runs far past the window
|
|
const presets = [
|
|
...Array.from({ length: 90 }, (_, i) => preset("vendor-" + i, "Vendor " + i, "vendor")),
|
|
...Array.from({ length: 30 }, (_, i) => preset("relay-" + i, "Relay " + i, "relay")),
|
|
];
|
|
const providers = [{ id: "openai", name: "OpenAI", icon: "openai", preset: "", models: [], agents: [], key: { set: true, masked: "sk-…ab12" } }];
|
|
|
|
function server(lang) {
|
|
return async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/providers") return json({ providers, presets, excluded: [], gateway: { running: true, window: true } });
|
|
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
|
if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
// a wheel step over the view, landed before the next look
|
|
async function wheel(page, dy) {
|
|
const was = await page.evaluate(() => document.getElementById("view-providers").scrollTop);
|
|
const v = await page.locator("#view-providers").boundingBox();
|
|
await page.mouse.move(v.x + v.width / 2, v.y + v.height / 2);
|
|
await page.mouse.wheel(0, dy);
|
|
return page.waitForFunction((was) => document.getElementById("view-providers").scrollTop !== was, was, { timeout: 1000 }).then(() => true, () => false);
|
|
}
|
|
|
|
// where the tools are: in the title bar, or in the sheet's head
|
|
const where = (page) => page.evaluate(() => {
|
|
const r = (e) => e.getBoundingClientRect();
|
|
const head = document.querySelector("#addSheet > .row-head"), find = document.querySelector("#addSheet .find");
|
|
const g = find?.parentElement, view = document.getElementById("view-providers"), bar = r(document.querySelector(".top"));
|
|
const f = find && r(find), hit = f && document.elementFromPoint(f.left + f.width / 2, f.top + f.height / 2);
|
|
return {
|
|
// in the bar: drawn over the title bar, wholly
|
|
afloat: !!f && f.top >= bar.top - 1 && f.bottom <= bar.bottom + 1, finds: document.querySelectorAll("#addSheet .find").length,
|
|
tools: g && r(g), find: f, head: head && r(head), view: r(view), top: r(document.querySelector(".top")),
|
|
actions: r(document.querySelector(".actions")), crumb: r(document.getElementById("crumb")),
|
|
clear: !!hit && (hit === find || find.contains(hit)), scroll: view.scrollTop,
|
|
focused: document.activeElement === find, value: find?.value,
|
|
};
|
|
});
|
|
|
|
const shown = (page) => page.locator("#addSheet .tile .n").evaluateAll((ns) => ns.filter((n) => n.getClientRects().length).map((n) => n.textContent));
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": the add sheet's tools follow the reader down", async (t) => {
|
|
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
|
for (const width of [1100, 420]) {
|
|
await t.test(`${lang} ${width}px`, async () => {
|
|
const context = await browser.newContext({ viewport: { width, height: 700 } });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(8000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", server(lang));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
await page.locator("#addProvider").click();
|
|
const sheet = page.locator("#addSheet");
|
|
await sheet.locator(".tile").first().waitFor();
|
|
await sheet.evaluate((el) => Promise.all(el.getAnimations({ subtree: true }).map((a) => a.finished)));
|
|
const side = await page.evaluate(() => document.body.classList.contains("side-nav"));
|
|
assert.equal(side, width >= 1024, "the layout");
|
|
|
|
// in sight: in their row, not in the bar
|
|
let w = await where(page);
|
|
assert(!w.afloat, "in their row while in sight");
|
|
assert(w.find.top >= w.head.top - 1 && w.find.bottom <= w.head.bottom + 1, "in the sheet's head: " + JSON.stringify([w.find, w.head]));
|
|
|
|
// a little down, the head still in sight: still in their row
|
|
await wheel(page, 40);
|
|
w = await where(page);
|
|
if (w.head.bottom > w.view.top + 2) assert(!w.afloat, "not in the bar while the row shows");
|
|
|
|
// down with the wheel till the head's row is out of sight
|
|
for (let i = 0; i < 60; i++) {
|
|
const h = await page.evaluate(() => {
|
|
const s = document.querySelector("#addSheet"), v = document.getElementById("view-providers");
|
|
return s.getBoundingClientRect().top + 60 - v.getBoundingClientRect().top;
|
|
});
|
|
if (h < 0) break;
|
|
if (!(await wheel(page, 100))) break;
|
|
}
|
|
await page.waitForTimeout(250);
|
|
w = await where(page);
|
|
assert.equal(w.finds, 1, "one search");
|
|
if (side) {
|
|
assert(w.afloat, "in the bar once out of sight");
|
|
assert(w.find.top >= w.top.top - 1 && w.find.bottom <= w.top.bottom + 1, "in the title bar: " + JSON.stringify([w.find, w.top]));
|
|
assert(w.tools.right <= w.actions.left + 0.5, "left of the bar's buttons: " + JSON.stringify([w.tools, w.actions]));
|
|
assert(w.tools.left >= w.crumb.left, "right of where the reader is");
|
|
// Custom provider and Import… with it (the two with a title);
|
|
// Close stays in the sheet
|
|
const bs = await page.locator("#addSheet .row-head button[title]").evaluateAll((es) => es.map((e) => e.getBoundingClientRect().toJSON()));
|
|
assert.equal(bs.length, 2);
|
|
for (const b of bs) assert(b.top >= w.top.top - 1 && b.bottom <= w.top.bottom + 1, "Custom provider and Import… in the bar too: " + JSON.stringify(b));
|
|
} else {
|
|
assert(!w.afloat, "no room in a narrow bar");
|
|
assert(Math.abs(w.head.top - w.view.top) <= 4, "the head held at the page's top: " + JSON.stringify([w.head, w.view]));
|
|
}
|
|
assert(w.clear, "the search is clear to press");
|
|
|
|
// a click on it moves nothing, and typing there finds
|
|
const before = w.scroll;
|
|
await sheet.locator(".find").click();
|
|
await page.waitForTimeout(150);
|
|
w = await where(page);
|
|
assert.equal(w.scroll, before, "nothing scrolled on the click");
|
|
assert(w.focused, "the search has the focus");
|
|
await page.keyboard.type("Relay 2");
|
|
await page.waitForTimeout(250);
|
|
const names = await shown(page);
|
|
assert(names.length > 0 && names.every((n) => n.includes("Relay 2")), "the list found: " + names.join(", "));
|
|
w = await where(page);
|
|
assert.equal(w.finds, 1, "still one search");
|
|
assert(w.focused && w.value === "Relay 2", "the focus and the words kept: " + JSON.stringify([w.focused, w.value]));
|
|
|
|
// back up: in their row again, the words and the focus with them
|
|
for (let i = 0; i < 80 && (await page.evaluate(() => document.getElementById("view-providers").scrollTop)) > 0; i++) {
|
|
if (!(await wheel(page, -200))) break;
|
|
}
|
|
await page.waitForTimeout(250);
|
|
w = await where(page);
|
|
assert(!w.afloat, "in their row once scrolled back");
|
|
assert(w.find.top >= w.head.top - 1 && w.find.bottom <= w.head.bottom + 1, "back in the sheet's head");
|
|
assert(w.focused && w.value === "Relay 2", "the words and focus kept going back");
|
|
assert.deepEqual(errors, []);
|
|
await context.close();
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|