Files
magpie/internal/gui/assets/settingshints.js
T
yetone cec267f902 gui: a field's long explanation shows on asking, in the editor and Routing groups (yujezhang on X)
yujezhang on X (11-10): "现在界面好多描述都太繁琐了 ... 界面只保留完成
操作必需的信息". The longest always-visible lines left were in a
provider's editor (100 to 666 characters a field) and Routing groups'
settings (69 to 318). They now work like Settings' rows since 11-02:
with a mouse, the explanation rests out of sight and the row's hover
(450ms) or keyboard focus shows it in the shared .set-hint card. A touch
screen keeps every line. No layout moves, no new page, no info icon
(the owner chose hover on the row for Settings).

Removed or moved:
- Routing's empty caption ("Every request an agent sends to magpie
  shows up here, routed for real.") is gone from the empty state: the
  mode line above it says the same. The key stays, the panel uses it.
- A provider editor field's explanation (.fld > .hint.expl): Headers,
  Certificate, Compaction, the routing and rate-limit fields and the
  rest: in the card. A line with a link or control in it, a warning and
  an error stay in sight.
- Two fields keep one short line in sight for what turning them on
  costs: Certificate ("Turn it on only on a network you trust.") and
  Compaction ("A conversation compacted this way continues only on
  this provider and account."). New keys in zh, zh-TW, ja and de.
- The editor's own settings rows (.prov-prefs: warm-up, check-in,
  resets) hide their lines as Settings' do; a result line (.say) stays.
- Routing groups: Found, Names and the three defaults' small lines: in
  the card. The no-names line stays.
- settingshints.js listens on document, so the editor (in #modal) and
  Routing get the card; the card grows from its row in 150ms, strong
  ease-out, a fade alone under reduced motion.

A line held out of sight is position: absolute in its field's box
(.fld and .hint-row > .txt are position: relative): placed against the
page, deep in the editor's scroll, it grew the page a scrollbar and
made the editor 10px narrower, and account-weight's de 390 in WebKit
ran an account line 3px past its row. Its sr-only -1px margin is
dropped, so it no longer sits 1px left of its row (warm-at-times,
warm-now and checkin-now-account check every .sub is inside its row).

Tests:
- New editor-hints.test.cjs (chromium + webkit, en/zh/zh-TW/ja/de,
  1100 and 420): at rest the explanation is out of sight and still
  described; Certificate's lead is in sight on one line; a hover shows
  the card with the text, inside the window, not over the name, nothing
  moving, taking no pointer; leaving hides it; Tab onto a field shows
  it; every out-of-sight line is placed in its own field; Routing
  groups' lines the same. 42/42 with account-weight on the Linux box.
- Broken by hand: the hide rule replaced and ROWS without the editor
  and groups: 0/20 red. The position: relative rule removed: 20/20 red
  (the placement check), then restored.
- vertex-editor: a hint resting out of sight isn't "cut".
  group-found-off: rows carry hint-row.
- 271 GUI files (every editor/edit= test, hints, visibility, prov-prefs,
  rt-gset/rt-cap, i18n-keys, old-webkit) in both engines on the WSL box
  (magpie-desktop), mine against a copy of 5d9e29814: 5589 pass / 241
  fail mine, 5528 / 262 base. Every file red in mine is red on base too
  except group-morph, provider-image-files and restart-app (one subtest
  each at concurrency 8); alone those three pass 114/114.
- settings-hints ja/de 420 and settings-lines-wrap de 440 fail the same
  on base (#5872).

Not tried: the whole 1343-file GUI suite (mote's suite.lock queue was
hours long); a touch screen; the real Linux app (WebKitGTK); macOS
Playwright.
2026-11-10 16:09:34 +08:00

94 lines
4.6 KiB
JavaScript

// The lines that explain a setting, shown on asking (the owner, 11-02:
// "让整个设计页面看起来很简洁,很有呼吸感"; yujezhang on X, 11-10: "界面只
// 保留完成操作必需的信息"). app.css keeps a row's lines that explain it out
// of sight (--hint: 1 on each); the pointer resting on the row, or a key
// reaching it, shows them here in a card under the row's name, over the
// page, so no row moves. The rows: Settings', a provider editor's fields
// and the Settings rows it holds, and any .hint-row (Routing groups'
// settings). The card takes no pointer: a click goes to what is under it.
// It goes when the pointer or focus leaves the row, the page scrolls, a key
// is pressed or the row is drawn again. Imported by app.js at start.
const ROWS = "#view-settings .row.pref, .editor.roomy .row.pref, .editor.roomy .fld, .hint-row";
const LINES = ":scope > .who > .sub, :scope > .hint, :scope > .txt > .expl";
const card = el("div", "set-hint");
card.setAttribute("aria-hidden", "true"); // a screen reader reads the lines in the row
document.body.append(card);
let row = null, wait = 0;
// a line holding a link or a control is one to use, so it stays in sight
const acts = (root) => {
for (const s of root.querySelectorAll(".row.pref > .who > .sub, .fld > .hint.expl")) s.classList.toggle("acts", !!s.querySelector("a, button, input, select, code, .searcher-failed"));
};
// before the page is painted again: no frame shows such a line hidden
// (Settings and the editor's dialog; Routing groups' lines hold none, and
// its page is drawn again as each request plays)
for (const root of [document.getElementById("view-settings"), document.getElementById("modal")]) {
if (!root) continue;
new MutationObserver(() => acts(root)).observe(root, { childList: true, subtree: true });
acts(root);
}
const hints = (r) => [...r.querySelectorAll(LINES)]
.filter((s) => !s.hidden && getComputedStyle(s).getPropertyValue("--hint").trim() === "1" && s.textContent.trim());
function hide() {
clearTimeout(wait);
row = null;
card.classList.remove("on");
card.hidden = true;
}
function show(r) {
const subs = r.isConnected && !r.closest("[hidden]") ? hints(r) : [];
if (!subs.length) return hide();
card.replaceChildren(...subs.map((s) => el("p", "", s.textContent.trim())));
card.hidden = false;
const who = (r.querySelector(":scope > .who, :scope > .txt") || r).getBoundingClientRect(), box = r.getBoundingClientRect();
const w = card.offsetWidth, h = card.offsetHeight;
const left = Math.max(16, Math.min(who.left, innerWidth - 16 - w));
// under the row, or over it where the window ends first
const top = box.bottom + 4 + h <= innerHeight - 8 ? box.bottom + 4 : Math.max(8, box.top - 4 - h);
card.style.left = left + "px";
card.style.top = top + "px";
card.style.transformOrigin = (top < box.top ? "bottom " : "top ") + Math.round(Math.min(Math.max(who.left - left, 0), w)) + "px";
requestAnimationFrame(() => row === r && card.classList.add("on"));
}
function point(r, now) {
if (r === row) return;
hide();
if (!r) return;
row = r;
// a pointer passing over rows on its way shows nothing; resting does
wait = setTimeout(() => show(r), now ? 0 : 450);
}
// rowOf: the row a node is in; an editor field's name, beside it in the
// grid, is the field's too
function rowOf(n) {
if (!(n instanceof Element)) return null;
const l = n.closest(".editor.roomy label");
if (l?.nextElementSibling?.matches(".fld")) return l.nextElementSibling;
return n.closest(ROWS);
}
document.addEventListener("pointerover", (e) => e.pointerType !== "touch" && point(rowOf(e.target)));
// the pointer gone from the window
document.addEventListener("pointerout", (e) => !e.relatedTarget && hide());
document.addEventListener("pointerdown", () => hide(), true);
document.addEventListener("focusin", (e) => {
let key = true;
try { key = e.target.matches(":focus-visible"); } catch {} // Safari before 15.4
if (key) point(rowOf(e.target), true);
});
document.addEventListener("focusout", (e) => {
if (!rowOf(e.relatedTarget) || rowOf(e.relatedTarget) !== row) hide();
});
// a scroll takes the pointer's card away; focus's follows its row, which
// a key moving focus scrolls into sight
document.addEventListener("scroll", () => row?.contains(document.activeElement) ? show(row) : hide(), { passive: true, capture: true });
addEventListener("keydown", (e) => !/^(Tab|Shift|Alt|Meta|Control)$/.test(e.key) && hide(), true);
addEventListener("resize", hide);
hide();
// the pointer already on a row, or focus, as the import came
{
const on = [...document.querySelectorAll(ROWS)].findLast?.((r) => r.matches(":hover")) || rowOf(document.activeElement);
if (on) point(on);
}