gui: the three typed-in-place number pills share pillNumber; app.js budgets back to before b4267de59

b4267de59 (a provider's fallback can be a routing group) raised app.js's
budget to 1,311,922 and the core scripts' to 1,531,060. Size budgets are
not raised (LESSONS.md, "A size budget raised whenever a change reaches it
bounds nothing"), so both go back to 1,311,735 and 1,530,861, and room is
made instead.

The account's usage cap pill, a window's own cap meter and an account's
requests-at-once pill each built the same input in the pill's place: the
same class, numeric mode, aria label, finish-once, Enter/Escape/blur
handling and refusal message. They now call one helper, pillNumber, with
a parser (capOf for the two caps, 1 to 99 with an optional %; a whole
number to 1000 for the lanes) and their own label, message, value and
setter. No behaviour changes. app.js goes from 1,311,922 to 1,310,926
bytes (996 fewer, 809 under the old budget); core scripts 1,530,064.

Run (at 0daf36332, and again at origin/main 85d159a28 after the rebase:
the same sizes, the budget test and the six GUI files below ok again):
- mote: go test -run Budget ./internal/gui: ok (TestCoreScriptBudget and
  the app.js budget at the restored values).
- Linux (WSL magpie-desktop), chromium and webkit: fallback-group,
  fallback-more, i18n-keys, account-cap, window-cap and lane-limit: 104 of
  104 ok.
- Broken by hand: pillNumber saving only when not asked to: account-cap,
  window-cap and lane-limit red in both engines; restored.
- The refusal path (a number out of range) has no GUI test; the old and
  new parsing were compared in node over "", 0, 1, 50, 50%, " 50 % ", 99,
  100, -3, abc, 12abc, 1e2, 1000, 1001, 007, 3.5 and "%": the same
  refusals and the same saved values for both caps and the lanes.
- gofmt -l: clean (no Go code changed but the budget constants).

Not tried: the real app; Windows.
This commit is contained in:
yetone
2026-10-29 05:40:52 +08:00
parent 85d159a288
commit 7795f55731
2 changed files with 29 additions and 60 deletions
+27 -58
View File
@@ -13709,6 +13709,29 @@ function capMark(track, w, cap) {
track.classList.add("capped");
track.append(mk);
}
// a number typed where a pill was: Enter or leaving saves what parse makes
// of it (null: not one, said in bad), Escape keeps own
const capOf = (v) => { v = parseInt(v.replace("%", ""), 10); return v >= 1 && v <= 99 ? v : null; };
function pillNumber(at, val, ph, cls, label, parse, bad, own, set) {
const i = input(val, ph, "text");
i.className = "rename-in " + cls;
i.inputMode = "numeric";
i.setAttribute("aria-label", label);
let done = false;
const finish = (save) => {
if (done) return;
done = true;
const s = i.value.trim(), v = parse(s);
if (save && s && v == null) { status(bad, "err"); renderProviders(); return; }
if (save && s && v !== own) set(v);
else renderProviders();
};
i.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") finish(true); else if (e.key === "Escape") finish(false); };
i.onblur = () => finish(true);
at.replaceWith(i);
i.focus({ preventScroll: true });
}
// windowCapMeter: a window's meter on an account's row as the button that
// sets the window's own cap, in the app's menu: the account's cap, none on
// this window, a share, or one typed in place. A window of a model family
@@ -13737,25 +13760,7 @@ function windowCapMeter(m, p, user, w) {
v === 0 ? t("{window} of {who} follows the account's cap", { window: name, who: user })
: v >= 100 ? t("{window} of {who} has no cap", { window: name, who: user })
: t("{who} stops at {n}% of {window}", { who: user, n: v, window: name }));
const other = () => {
const i = input(own && own < 100 ? String(own) : "", "1–99", "text");
i.className = "rename-in acap-in";
i.inputMode = "numeric";
i.setAttribute("aria-label", t("Cap for {window}, in percent", { window: name }));
let done = false;
const finish = (save) => {
if (done) return;
done = true;
const v = parseInt(i.value.replace("%", "").trim(), 10);
if (save && i.value.trim() && !(v >= 1 && v <= 99)) { status(t("A cap is a share from 1% to 99%"), "err"); renderProviders(); return; }
if (save && i.value.trim() && v !== own) set(v);
else renderProviders();
};
i.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") finish(true); else if (e.key === "Escape") finish(false); };
i.onblur = () => finish(true);
b.replaceWith(i);
i.focus({ preventScroll: true });
};
const other = () => pillNumber(b, own && own < 100 ? String(own) : "", "1–99", "acap-in", t("Cap for {window}, in percent", { window: name }), capOf, t("A cap is a share from 1% to 99%"), own, set);
b.onclick = (e) => {
e.stopPropagation();
if (b.classList.contains("open")) return closeProtoMenu();
@@ -13787,26 +13792,8 @@ function accountCapPill(p, user, cap, direct) {
pill.setAttribute("aria-expanded", "false");
const set = (v) => accountAction("provider/accountcap", { id: p.id, account: user, cap: v },
v ? t("{who} stops at {n}% of each window", { who: user, n: v }) : t("{who} has no usage cap", { who: user }));
const other = () => {
// a share of the user's own, typed where the pill was
const i = input(cap ? String(cap) : "", "1–99", "text");
i.className = "rename-in acap-in";
i.inputMode = "numeric";
i.setAttribute("aria-label", t("Usage cap, in percent"));
let done = false;
const finish = (save) => {
if (done) return;
done = true;
const v = parseInt(i.value.replace("%", "").trim(), 10);
if (save && i.value.trim() && !(v >= 1 && v <= 99)) { status(t("A cap is a share from 1% to 99%"), "err"); renderProviders(); return; }
if (save && i.value.trim() && v !== cap) set(v);
else renderProviders();
};
i.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") finish(true); else if (e.key === "Escape") finish(false); };
i.onblur = () => finish(true);
pill.replaceWith(i);
i.focus({ preventScroll: true });
};
// a share of the user's own, typed where the pill was
const other = () => pillNumber(pill, cap ? String(cap) : "", "1–99", "acap-in", t("Usage cap, in percent"), capOf, t("A cap is a share from 1% to 99%"), cap, set);
pill.onclick = (e) => {
e.stopPropagation();
if (pill.classList.contains("open")) return closeProtoMenu();
@@ -13868,25 +13855,7 @@ function laneLimitPill(p, ref, who, name) {
const own = laneOwnOf(p, ref);
const set = (v) => accountAction("provider/accountconcurrency", { id: p.id, account: ref, limit: v },
v == null ? t("{who} takes the provider's limit", { who: name }) : v ? t("{who}: at most {n} requests at once", { who: name, n: v }) : t("{who}: no limit on requests at once", { who: name }));
const other = () => {
const i = input(own ? String(own) : "", "1–1000", "text");
i.className = "rename-in alane-in";
i.inputMode = "numeric";
i.setAttribute("aria-label", t("Requests at once"));
let done = false;
const finish = (save) => {
if (done) return;
done = true;
const v = i.value.trim();
if (save && v && !(/^\d+$/.test(v) && +v <= 1000)) { status(t("Concurrency: a whole number from 0 to 1000"), "err"); renderProviders(); return; }
if (save && v && +v !== own) set(+v);
else renderProviders();
};
i.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") finish(true); else if (e.key === "Escape") finish(false); };
i.onblur = () => finish(true);
pill.replaceWith(i);
i.focus({ preventScroll: true });
};
const other = () => pillNumber(pill, own ? String(own) : "", "1–1000", "alane-in", t("Requests at once"), (v) => /^\d+$/.test(v) && +v <= 1000 ? +v : null, t("Concurrency: a whole number from 0 to 1000"), own, set);
pill.onclick = (e) => {
e.stopPropagation();
if (pill.classList.contains("open")) return closeProtoMenu();
File diff suppressed because one or more lines are too long