Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(web): 原地换条后焦点留在浮窗里,揭示中途换条不残留模糊

longmeidaob64ec52c865d
diff --git a/frontend/e2e/follow-detail.test.ts b/frontend/e2e/follow-detail.test.ts
index c46789783..6f5661e28 100644
--- a/frontend/e2e/follow-detail.test.ts
+++ b/frontend/e2e/follow-detail.test.ts
@@ -31,7 +31,7 @@ function watchFollowRequests(page: Page) {
return seen;
}
-/** 换条前记下舞台节点并盯住骨架:原地换条时浮窗还是同一个节点,中途不回骨架。 */
+/** 换条前记下舞台节点并盯住骨架:原地换条时浮窗还是同一个节点,中途不回骨架,焦点留在浮窗里。 */
const watchStage = (page: Page) => page.evaluate(() => {
const watch = { stage: document.getElementById('stage'), skeleton: false };
new MutationObserver(() => { if (document.querySelector('#stage [data-skeleton="detail"]')) watch.skeleton = true })
@@ -40,7 +40,8 @@ const watchStage = (page: Page) => page.evaluate(() => {
});
const stageKept = (page: Page) => page.evaluate(() => {
const watch = (window as unknown as { stageWatch: { stage: Element | null; skeleton: boolean } }).stageWatch;
- return { same: document.getElementById('stage') === watch.stage, skeleton: watch.skeleton };
+ return { same: document.getElementById('stage') === watch.stage, skeleton: watch.skeleton,
+ focused: !!watch.stage?.contains(document.activeElement) };
});
const openDetail = (browser: Browser, id: number, viewport = DESKTOP) =>
@@ -130,13 +131,13 @@ describe('关注详情岛', () => {
await page.locator('#stage .video-js .vjs-control-bar').waitFor({ state: 'attached' });
assert.equal(await page.locator('#stage .video-js').count(), 1, '换一条之后旧播放器没拆');
assert.equal(await page.locator('#stage [data-ambient-canvas]').count(), 1);
- assert.deepEqual(await stageKept(page), { same: true, skeleton: false }, '换一条重开了浮窗');
+ assert.deepEqual(await stageKept(page), { same: true, skeleton: false, focused: true }, '换一条重开了浮窗');
await page.goBack();
await pathIs(page, '/follow/item/5101');
await page.locator('#stage [data-follow-queue-item="5101"][aria-current="true"]').waitFor();
await page.locator('#stage .video-js .vjs-control-bar').waitFor({ state: 'attached' });
assert.equal(await page.locator('#stage .video-js').count(), 1, '后退之后旧播放器没拆');
- assert.deepEqual(await stageKept(page), { same: true, skeleton: false }, '后退到上一条重开了浮窗');
+ assert.deepEqual(await stageKept(page), { same: true, skeleton: false, focused: true }, '后退到上一条重开了浮窗');
await page.locator('#closeStage').click();
await pathIs(page, '/follow');
await page.locator('[data-follow-list] > [data-follow-item]').first().waitFor({ timeout: 15_000 });
diff --git a/frontend/e2e/item-detail.test.ts b/frontend/e2e/item-detail.test.ts
index 76c0a987f..22b910254 100644
--- a/frontend/e2e/item-detail.test.ts
+++ b/frontend/e2e/item-detail.test.ts
@@ -26,7 +26,7 @@ const ids = (page: Page, selector: string, attribute: string) => page.locator(se
(nodes, name) => nodes.map((node) => Number(node.getAttribute(name))), attribute);
-/** 换条前记下舞台节点并盯住骨架:原地换条时浮窗还是同一个节点,中途不回骨架。 */
+/** 换条前记下舞台节点并盯住骨架:原地换条时浮窗还是同一个节点,中途不回骨架,焦点留在浮窗里。 */
const watchStage = (page: Page) => page.evaluate(() => {
const watch = { stage: document.getElementById('stage'), skeleton: false };
new MutationObserver(() => { if (document.querySelector('#stage [data-skeleton="detail"]')) watch.skeleton = true })
@@ -35,7 +35,8 @@ const watchStage = (page: Page) => page.evaluate(() => {
});
const stageKept = (page: Page) => page.evaluate(() => {
const watch = (window as unknown as { stageWatch: { stage: Element | null; skeleton: boolean } }).stageWatch;
- return { same: document.getElementById('stage') === watch.stage, skeleton: watch.skeleton };
+ return { same: document.getElementById('stage') === watch.stage, skeleton: watch.skeleton,
+ focused: !!watch.stage?.contains(document.activeElement) };
});
describe('作品详情岛', () => {
@@ -420,7 +421,7 @@ describe('作品详情岛', () => {
await pathIs(page, wanted);
await page.locator(`#stage [data-queue-item="${next}"][aria-current="true"]`).waitFor();
await page.locator(DETAIL_READY).waitFor();
- assert.deepEqual(await stageKept(page), { same: true, skeleton: false }, `${kind}队列换一条重开了浮窗`);
+ assert.deepEqual(await stageKept(page), { same: true, skeleton: false, focused: true }, `${kind}队列换一条重开了浮窗`);
if (kind === '分卷') assert.match(await page.locator('#stage [data-detail-title]').innerText(), /第 3 卷/);
for (const url of ['/api/parts', '/api/editions', '/api/related']) {
assert.equal(opened.stub.reads.get(url) || 0, reads.get(url) || 0, `同一个${kind}队列里换一条又取了 ${url}`);
diff --git a/frontend/src/react/stage/stage.tsx b/frontend/src/react/stage/stage.tsx
index 3ba501505..321f4f578 100644
--- a/frontend/src/react/stage/stage.tsx
+++ b/frontend/src/react/stage/stage.tsx
@@ -284,8 +284,17 @@ async function swap(request: StageRequest, dialog: HTMLDialogElement): Promise<v
closePlayerMenu();
view = { ...view, request, content, phase: 'content' };
paint();
+ /* 首次揭示还没走完就换了条:淡出那一层已经卸下,等不到它的 transitionend,模糊要当场摘掉。 */
+ dialog.removeAttribute('data-stage-reveal');
+ dialog.removeAttribute('data-stage-revealing');
dialog.querySelector<HTMLElement>(':scope > [data-stage-scroll]')?.scrollTo({ top: 0 });
revealTexts(dialog, ':scope>:not([data-stage-fade]) [data-reveal-line]');
+ /* 点下去的那一行随详情重建卸掉了,焦点落回 body:交给队列里新的当前行,没有队列交给关闭键。 */
+ const active = document.activeElement;
+ if (active === dialog || !dialog.contains(active)) {
+ (dialog.querySelector<HTMLElement>('[data-mix-item][aria-current="true"]')
+ || dialog.querySelector<HTMLElement>('#closeStage'))?.focus({ preventScroll: true });
+ }
}
/* 详情浮窗的退场跟设置弹层同一条:`data-closing` 让 `board-dialog-out` 和遮罩淡出演完,再拆。等待有
diff --git a/web/dist/peach-react.js b/web/dist/peach-react.js
index 7ab2d9298..907c90ae0 100644
--- a/web/dist/peach-react.js
+++ b/web/dist/peach-react.js
@@ -81329,12 +81329,15 @@ async function fJe(e, t) {
} catch {
if (r.signal.aborted) return;
}
- n !== j9 || !A9 || U9(e.kind) !== t || (c9(e.kind, e.id ?? NaN), ie(t), LS(), A9 = {
+ if (n !== j9 || !A9 || U9(e.kind) !== t) return;
+ c9(e.kind, e.id ?? NaN), ie(t), LS(), A9 = {
...A9,
request: e,
content: i,
phase: "content"
- }, L9(), t.querySelector(":scope > [data-stage-scroll]")?.scrollTo({ top: 0 }), Be(t, ":scope>:not([data-stage-fade]) [data-reveal-line]"));
+ }, L9(), t.removeAttribute("data-stage-reveal"), t.removeAttribute("data-stage-revealing"), t.querySelector(":scope > [data-stage-scroll]")?.scrollTo({ top: 0 }), Be(t, ":scope>:not([data-stage-fade]) [data-reveal-line]");
+ let a = document.activeElement;
+ (a === t || !t.contains(a)) && (t.querySelector("[data-mix-item][aria-current=\"true\"]") || t.querySelector("#closeStage"))?.focus({ preventScroll: !0 });
}
function pJe() {
let e = F9();