Peach: Local-first video metadata scraper and media manager.
fix(setup): 400 写回的字段错误由读屏播报
longmeidao705f69cdd686
diff --git a/docs/BOARD_UI.md b/docs/BOARD_UI.mdindex eb3874bb0..9e11a23dd 100644--- a/docs/BOARD_UI.md+++ b/docs/BOARD_UI.md@@ -394,7 +394,9 @@ Auth Card 是注册表里没有的组合:页面底色 `background-full` 上居媒体库、访问密码、高级设置、完成设置后四组之间是 24px 留白加一条 `separator-border` 横线,第一组紧跟卡头不画线;浏览器历史记录是「完成设置后」里的子组,同样以横线分隔。一级分组标题用 `body-semibold`、主文字色;字段标签用 BoardUI `Label`;说明用 `body-2-regular`、次级文字色,-错误用同一字号的 `text-error-primary`,框体线条随 `aria-invalid` 转 danger 色。+整表一句与提交失败用 `ErrorText`(同一字号的 `text-error-primary`、`role="alert"`);字段错误+替换框下的提示,包在 `role="alert"` 里由 `aria-describedby` 挂在框上,页面上只有一份,框体随+`aria-invalid` 转 danger 色。## 安装后教程diff --git a/frontend/src/react/pages/setup/setup-form.tsx b/frontend/src/react/pages/setup/setup-form.tsxindex 9a62ab82a..243d5b6e6 100644--- a/frontend/src/react/pages/setup/setup-form.tsx+++ b/frontend/src/react/pages/setup/setup-form.tsx@@ -74,6 +74,11 @@ export function SetupForm({ setup, onDone }: { setup: SetupQuestions; onDone: (duseEffect(() => {if (errorRound) form.current?.querySelector<HTMLElement>('input[aria-invalid="true"]')?.focus();}, [errorRound]);+ // 写回的错误放进框下的提示:`role="alert"` 让读屏在它出现时播报一次,提示本身仍由+ // `aria-describedby` 挂在框上,文字在页面上只有这一份。`key` 跟着提交轮次换,同一句错误+ // 再提交一次也会重新播报。+ const announce = (message: string | undefined) =>+ message ? <span key={errorRound} role="alert">{message}</span> : undefined;const visible = (question: SetupQuestion) =>!question.visible_when || Object.entries(question.visible_when).every(([key, value]) => values[key] === value);@@ -125,7 +130,7 @@ export function SetupForm({ setup, onDone }: { setup: SetupQuestions; onDone: (d))}</SegmentedRadioGroup>{help ? <Help>{help}</Help> : null}- {error ? <ErrorText>{error}</ErrorText> : null}+ {error ? <ErrorText key={errorRound}>{error}</ErrorText> : null}</div>);}@@ -138,7 +143,7 @@ export function SetupForm({ setup, onDone }: { setup: SetupQuestions; onDone: (d? <span className="shrink-0 pl-1 text-body-regular text-text-secondary">{question.prefix}</span>: undefined}trailingIcon={question.suffix ? Suffix : undefined}- validationBehavior="aria" isInvalid={Boolean(error)} hint={error || help || undefined} />+ validationBehavior="aria" isInvalid={Boolean(error)} hint={announce(error) ?? (help || undefined)} />);};@@ -152,11 +157,11 @@ export function SetupForm({ setup, onDone }: { setup: SetupQuestions; onDone: (d<GroupTitle id="setup-media-title">{media.label}<span aria-hidden className="ml-0.5 text-text-error-primary">*</span></GroupTitle>- {tableError ? <ErrorText>{tableError}</ErrorText> : null}+ {tableError ? <ErrorText key={errorRound}>{tableError}</ErrorText> : null}<div role="group" aria-labelledby="setup-media-title" className="flex flex-col gap-3">{folders.rows.map((row, index) => (<FolderRow key={index} label={`${media.label} ${index + 1}`} path={row.path}- onPath={(path) => folders.edit(index, { path })} error={folders.errors[index]}+ onPath={(path) => folders.edit(index, { path })} error={announce(folders.errors[index])}inputRef={folders.inputRef(index)} picking={folders.picking === index}onPick={() => void folders.pick(index)}onRemove={folders.rows.length > 1 ? () => { folders.remove(index); addButton.current?.focus(); } : undefined}>@@ -199,7 +204,7 @@ export function SetupForm({ setup, onDone }: { setup: SetupQuestions; onDone: (d{accessOn? <PasswordPair label="访问密码" password={password} confirmation={confirmation}onPassword={setPassword} onConfirmation={setConfirmation}- passwordError={text(errors.access_password) || undefined} passwordHint="请输入 8–256 个字符。"+ passwordError={announce(text(errors.access_password))} passwordHint="请输入 8–256 个字符。"confirmationInvalid={Boolean(errors.access_password)} />: null}</CardGroup>diff --git a/frontend/src/react/settings/folder-rows.tsx b/frontend/src/react/settings/folder-rows.tsxindex 254dbd941..0fe19c413 100644--- a/frontend/src/react/settings/folder-rows.tsx+++ b/frontend/src/react/settings/folder-rows.tsx@@ -102,12 +102,13 @@ export function useFolderRows<T extends FolderRowValue>({ initial, blank, pickForeturn { rows, edit, add, remove, errors, setErrors, picking, pick, inputRef };}-/** 一行描边卡。`label` 是路径框的无障碍名,`children` 排进路径下面那一格。 */+/** 一行描边卡。`label` 是路径框的无障碍名,`children` 排进路径下面那一格。`error` 原样放进路径框+ * 下的提示,调用方可以传一段带 `role="alert"` 的节点让读屏播报。 */export function FolderRow({ label, path, onPath, error, inputRef, picking, onPick, onRemove, children }: {label: string;path: string;onPath: (path: string) => void;- error?: string;+ error?: ReactNode;inputRef: (element: HTMLInputElement | null) => void;picking: boolean;onPick: () => void;diff --git a/frontend/src/react/settings/password-pair.tsx b/frontend/src/react/settings/password-pair.tsxindex 48fbb7741..64064fed1 100644--- a/frontend/src/react/settings/password-pair.tsx+++ b/frontend/src/react/settings/password-pair.tsx@@ -2,7 +2,10 @@** 两框都是 BoardUI `Input`,`id` 固定为 `access-password`、`access-confirm`,浏览器的密码管理器按* `new-password` 认它们。关掉时两框置灰、不必填也不标错;错误写在各自框下,`confirmationInvalid`- * 让只有一句错误的调用方(首启页的 `access_password`)把确认框一起标红。 */+ * 让只有一句错误的调用方(首启页的 `access_password`)把确认框一起标红。错误原样放进框下的提示,+ * 调用方可以传一段带 `role="alert"` 的节点让读屏播报。 */+import type { ReactNode } from 'react';+import { Input } from '@/components/base/input/input';export function PasswordPair({@@ -15,9 +18,9 @@ export function PasswordPair({onPassword: (value: string) => void;onConfirmation: (value: string) => void;disabled?: boolean;- passwordError?: string;+ passwordError?: ReactNode;passwordHint?: string;- confirmationError?: string;+ confirmationError?: ReactNode;confirmationInvalid?: boolean;}) {return (diff --git a/frontend/test/react/setup-page.test.tsx b/frontend/test/react/setup-page.test.tsxindex a78ea6ee9..e03d8ef02 100644--- a/frontend/test/react/setup-page.test.tsx+++ b/frontend/test/react/setup-page.test.tsx@@ -70,6 +70,19 @@ const radio = (root: ParentNode, label: string) =>[...root.querySelectorAll('label')].find((node) => node.textContent?.trim() === label);const advanced = (root: ParentNode) => [...root.querySelectorAll('summary')].find((node) => node.textContent === '高级设置');const submitForm = async (root: ParentNode) => { await click(buttonNamed('完成设置', root)); await settle(); };+const alertsWith = (root: ParentNode, message: string) =>+ [...root.querySelectorAll('[role="alert"]')].filter((node) => node.textContent?.includes(message));+const occurrences = (root: HTMLElement, message: string) => (root.textContent ?? '').split(message).length - 1;++/** 这句错误在页面上只有一份,落在一个 `role="alert"` 里,并由框的 `aria-describedby` 指到。 */+function expectAnnounced(root: HTMLElement, input: Element | null | undefined, message: string) {+ const alerts = alertsWith(root, message);+ expect(alerts).toHaveLength(1);+ expect(occurrences(root, message)).toBe(1);+ const described = (input?.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean);+ expect(described.some((id) => document.getElementById(id)?.contains(alerts[0]!))).toBe(true);+ return alerts[0]!;+}it('题目、默认值与题面来自读题接口:媒体库一行在外面,其余折进高级设置', async () => {const { host } = await open();@@ -174,7 +187,8 @@ describe('填错时原位标错', () => {expect(advanced(host)?.getAttribute('aria-expanded')).toBe('true');expect(field(host, 'port')?.value).toBe('70000');expect(field(host, 'port')?.getAttribute('aria-invalid')).toBe('true');- expect(host.textContent).toContain('端口要是 1 到 65535 之间的整数');+ expectAnnounced(host, paths(host)[0], '目录不存在:D:\\Nope');+ expectAnnounced(host, field(host, 'port'), '端口要是 1 到 65535 之间的整数');expect(document.activeElement).toBe(paths(host)[0]);});@@ -183,8 +197,10 @@ describe('填错时原位标错', () => {error: '有几项需要修改', errors: { media_dir: ['请添加 1 到 100 个媒体文件夹'] } } } });await click(buttonNamed('添加媒体库', host));await submitForm(host);- const alert = [...host.querySelectorAll('[role="alert"]')].find((node) => node.textContent?.includes('请添加'));+ const [alert, ...more] = alertsWith(host, '请添加 1 到 100 个媒体文件夹');expect(alert).toBeDefined();+ expect(more).toHaveLength(0);+ expect(occurrences(host, '请添加 1 到 100 个媒体文件夹')).toBe(1);expect(rows(host).some((row) => row.contains(alert!))).toBe(false);expect(alert!.compareDocumentPosition(rows(host)[0]!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();expect(advanced(host)?.getAttribute('aria-expanded')).toBe('false');@@ -198,7 +214,11 @@ describe('填错时原位标错', () => {expect(switches(host)[0]!.checked).toBe(true);expect(host.querySelector('#access-password')?.getAttribute('aria-invalid')).toBe('true');expect(host.querySelector<HTMLInputElement>('#access-password')?.value).toBe('first-password');- expect(host.textContent).toContain('两次输入的访问密码不一致');+ const first = expectAnnounced(host, host.querySelector('#access-password'), '两次输入的访问密码不一致');+ // 同一句错误再提交一次:提示换成新节点,读屏重新播报,页面上仍只有一份。+ await submitForm(host);+ const second = expectAnnounced(host, host.querySelector('#access-password'), '两次输入的访问密码不一致');+ expect(second).not.toBe(first);});});diff --git a/web/dist/peach-pages.js b/web/dist/peach-pages.jsindex 6cf1656a8..1419436e0 100644--- a/web/dist/peach-pages.js+++ b/web/dist/peach-pages.js@@ -20590,10 +20590,13 @@ function Sh({ setup: e, onDone: t }) {(0, v.useEffect)(() => {M && A.current?.querySelector("input[aria-invalid=\"true\"]")?.focus();}, [M]);- let te = (e) => !e.visible_when || Object.entries(e.visible_when).every(([e, t]) => s[e] === t), N = (e, t) => c((n) => ({+ let te = (e) => e ? /* @__PURE__ */ (0, B.jsx)("span", {+ role: "alert",+ children: e+ }, M) : void 0, N = (e) => !e.visible_when || Object.entries(e.visible_when).every(([e, t]) => s[e] === t), P = (e, t) => c((n) => ({...n,[e]: t- })), P = async (e) => {+ })), ne = async (e) => {if (e.preventDefault(), E) return;D(!0), T("");let n = {@@ -20602,7 +20605,7 @@ function Sh({ setup: e, onDone: t }) {scan_now: h,history_guide: _};- for (let e of r) te(e) && (n[e.key] = s[e.key] ?? "");+ for (let e of r) N(e) && (n[e.key] = s[e.key] ?? "");l && Object.assign(n, {access_password: d,access_confirm: p@@ -20617,7 +20620,7 @@ function Sh({ setup: e, onDone: t }) {} finally {D(!1);}- }, ne = (e) => {+ }, re = (e) => {let t = xh(b[e.key]), n = e.help.join("");if (e.input === "choice") {let r = `setup-${e.key}-label`;@@ -20634,7 +20637,7 @@ function Sh({ setup: e, onDone: t }) {orientation: "horizontal",className: Jm,value: s[e.key] ?? e.default,- onChange: (t) => N(e.key, t),+ onChange: (t) => P(e.key, t),children: (e.options ?? []).map((e) => /* @__PURE__ */ (0, B.jsx)(cp, {value: e.value,className: Ym,@@ -20642,7 +20645,7 @@ function Sh({ setup: e, onDone: t }) {}, e.value))}),n ? /* @__PURE__ */ (0, B.jsx)(Kt, { children: n }) : null,- t ? /* @__PURE__ */ (0, B.jsx)(qt, { children: t }) : null+ t ? /* @__PURE__ */ (0, B.jsx)(qt, { children: t }, M) : null]}, e.key);}@@ -20654,7 +20657,7 @@ function Sh({ setup: e, onDone: t }) {autoComplete: "off",spellCheck: "false",value: s[e.key] ?? "",- onChange: (t) => N(e.key, t),+ onChange: (t) => P(e.key, t),leadingAddon: e.prefix ? /* @__PURE__ */ (0, B.jsx)("span", {className: "shrink-0 pl-1 text-body-regular text-text-secondary",children: e.prefix@@ -20665,13 +20668,13 @@ function Sh({ setup: e, onDone: t }) {}) : void 0,validationBehavior: "aria",isInvalid: !!t,- hint: t || n || void 0+ hint: te(t) ?? (n || void 0)}, e.key);- }, re = o.rows.map((e) => e.path.trim()).filter(Boolean), ie = o.rows.some((e) => fh(e.location));+ }, ie = o.rows.map((e) => e.path.trim()).filter(Boolean), ae = o.rows.some((e) => fh(e.location));return /* @__PURE__ */ (0, B.jsxs)("form", {ref: A,noValidate: !0,- onSubmit: (e) => void P(e),+ onSubmit: (e) => void ne(e),"aria-labelledby": "auth-card-title",className: "flex flex-col gap-6",children: [@@ -20687,7 +20690,7 @@ function Sh({ setup: e, onDone: t }) {children: "*"})]}),- S ? /* @__PURE__ */ (0, B.jsx)(qt, { children: S }) : null,+ S ? /* @__PURE__ */ (0, B.jsx)(qt, { children: S }, M) : null,/* @__PURE__ */ (0, B.jsx)("div", {role: "group","aria-labelledby": "setup-media-title",@@ -20696,7 +20699,7 @@ function Sh({ setup: e, onDone: t }) {label: `${n.label} ${r + 1}`,path: t.path,onPath: (e) => o.edit(r, { path: e }),- error: o.errors[r],+ error: te(o.errors[r]),inputRef: o.inputRef(r),picking: o.picking === r,onPick: () => void o.pick(r),@@ -20724,7 +20727,7 @@ function Sh({ setup: e, onDone: t }) {onClick: o.add,children: "添加媒体库"}),- ie ? /* @__PURE__ */ (0, B.jsxs)(B.Fragment, { children: [/* @__PURE__ */ (0, B.jsxs)(Kt, { children: [e.cloud.help, /* @__PURE__ */ (0, B.jsx)(Yt, {+ ae ? /* @__PURE__ */ (0, B.jsxs)(B.Fragment, { children: [/* @__PURE__ */ (0, B.jsxs)(Kt, { children: [e.cloud.help, /* @__PURE__ */ (0, B.jsx)(Yt, {href: e.cloud.link.url,children: e.cloud.link.label})] }), e.cloud.dependencies.map((e) => /* @__PURE__ */ (0, B.jsxs)(Kt, { children: [e.message, /* @__PURE__ */ (0, B.jsx)(Yt, {@@ -20763,7 +20766,7 @@ function Sh({ setup: e, onDone: t }) {confirmation: p,onPassword: f,onConfirmation: m,- passwordError: xh(b.access_password) || void 0,+ passwordError: te(xh(b.access_password)),passwordHint: "请输入 8–256 个字符。",confirmationInvalid: !!b.access_password}) : null@@ -20774,7 +20777,7 @@ function Sh({ setup: e, onDone: t }) {defaultOpen: O > 0,children: /* @__PURE__ */ (0, B.jsx)("div", {className: "flex flex-col gap-4",- children: r.filter(te).map(ne)+ children: r.filter(N).map(re)})}, O) }),/* @__PURE__ */ (0, B.jsxs)(Ct, {@@ -20789,7 +20792,7 @@ function Sh({ setup: e, onDone: t }) {children: [/* @__PURE__ */ (0, B.jsx)(Ip, {isSelected: h,onChange: g,- children: bh(re)+ children: bh(ie)}), /* @__PURE__ */ (0, B.jsx)(Kt, { children: "读取已有 NFO 和封面,采集缺失资料。符合自动规则的资料会在处理完成后落库,其余候选留在复核。" })]}),/* @__PURE__ */ (0, B.jsxs)("section", {