Peach: Local-first video metadata scraper and media manager.
feat(web): 侧栏名单没列完的话,那句话接在名单末尾
longmeidao76b4a478c3c4
diff --git a/frontend/src/sidebar-groups.ts b/frontend/src/sidebar-groups.tsindex 361c6f85f..bb8e29617 100644--- a/frontend/src/sidebar-groups.ts+++ b/frontend/src/sidebar-groups.ts@@ -1,22 +1,22 @@/** 侧栏筛选分组:标题、展开状态与叶项计数各自承担一种含义。 */import { wireCollapse } from '@peach/legacy/ui';const escape=(value:string)=>value.replace(/[&<>"']/g,char=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[char]!));-export function sidebarSectionHtml(title:string,body:string,extra='',kind=''):string {+/** `footer` 接在条目之后,属于这一组的内容;标题那一行只留组名和展开箭头。 */+export function sidebarSectionHtml(title:string,body:string,footer='',kind=''):string {if(!body)return '';const id=`sidebar-group-${encodeURIComponent(title)}`;- return `<details class="sec${kind?' cat-'+escape(kind):''}" data-sidebar-group="${escape(title)}"><summary role="button" class="board-section-toggle"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="#i-chevron-right"/></svg><span>${escape(title)}</span>${extra}</summary><div class="board-sidebar-body" id="${id}">${body}</div></details>`;+ return `<details class="sec${kind?' cat-'+escape(kind):''}" data-sidebar-group="${escape(title)}"><summary role="button" class="board-section-toggle"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="#i-chevron-right"/></svg><span>${escape(title)}</span></summary><div class="board-sidebar-body" id="${id}">${body}${footer}</div></details>`;}export function wireSidebarGroups(root:HTMLElement):void {root.querySelectorAll<HTMLDetailsElement>('[data-sidebar-group]').forEach(group=>{if(group.dataset.sidebarWired)return;group.dataset.sidebarWired='true';- const button=group.querySelector<HTMLElement>('.board-section-toggle')!,body=group.querySelector<HTMLElement>('.board-sidebar-body')!;+ const body=group.querySelector<HTMLElement>('.board-sidebar-body')!;const key=`peach.sidebar.group.${group.dataset.sidebarGroup}`;let saved:string|null=null;try{saved=sessionStorage.getItem(key)}catch{}const active=!!body.querySelector('[aria-pressed=true]');/* 一进来只有正在生效的那几组是展开的。挑两组常驻展开等于替人决定他这次要按哪个维度筛,而侧栏一屏就那么长,展开的部分把别的组挤到看不见的地方去。 */group.open=saved!==null?saved==='open':active;- button.querySelectorAll('button').forEach(control=>control.addEventListener('click',event=>event.stopPropagation()));});wireCollapse(root,'details[data-sidebar-group]','sidebar-collapse');root.querySelectorAll<HTMLElement>('.board-section-toggle').forEach(button=>{diff --git a/frontend/test/sidebar-groups.test.ts b/frontend/test/sidebar-groups.test.tsindex 66f26132a..1a2bcc619 100644--- a/frontend/test/sidebar-groups.test.ts+++ b/frontend/test/sidebar-groups.test.ts@@ -9,6 +9,16 @@ it('opens selected filters and preserves the user disclosure choice after renderrender();expect(document.querySelector<HTMLDetailsElement>('[data-sidebar-group]')!.open).toBe(false);expect(document.querySelector('.board-section-toggle')!.getAttribute('aria-expanded')).toBe('false');});+it('puts the load more control at the end of the list it belongs to',()=>{+ document.body.innerHTML=sidebarSectionHtml('创作者','<div class="chips"><button>条目</button></div>',+ '<button class="sidemore">更多</button>');+ wireSidebarGroups(document.body);+ expect(document.querySelector('summary .sidemore')).toBeNull();+ const body=document.querySelector('.board-sidebar-body')!;+ expect(body.lastElementChild!.className).toBe('sidemore');+ // 收起这一组时它跟名单一起收走:名单都不在了,「还没完」也就无从说起。+ expect(document.querySelector<HTMLDetailsElement>('[data-sidebar-group]')!.open).toBe(false);+});it('escapes titles and retains a valid disclosure target',()=>{document.body.innerHTML=sidebarSectionHtml('<img>', '<button>条目</button>');wireSidebarGroups(document.body);expect(document.querySelector('img')).toBeNull();diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex 275fae4cb..eb3c382aa 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -5873,6 +5873,26 @@ class WebUiSourceTests(unittest.TestCase):self.assertPageContains("const pickedTags=seededSample(topTags,TAGS_FIRST,`tags:${state.seed||''}`);")self.assertPageContains("+sec('内容标签',chips(facetData.tags,'tag',false,30)")+ def test_a_truncated_sidebar_list_says_so_at_its_own_end(self):+ """侧栏名单没列完时,那句话接在名单末尾,不挂到组名那一行。++ 「更多」说的是「这张名单还没完」——它要跟名单断掉的地方在一起。挂在标题上时,+ 人得先把这一列读到底、再抬头回到标题去找它;而标题那一行的职责是开合这一组,+ 旁边多一个按钮,点哪儿会展开就成了两件要分辨的事。+ """+ self.assertPageContains(+ "scopedCreators.length>26?'<button class=\"sidemore\" data-more=\"creator\">更多</button>':''")+ self.assertPageContains(+ "facetData.tags.length>30?'<button class=\"sidemore\" data-more=\"tag\">更多</button>':''")+ # 展开与收起是同一枚按钮的两面,不另开一处入口。+ self.assertPageContains("group.querySelector('.chips').outerHTML=chips(src,k,false,expanded?lim:999);")+ self.assertPageContains("b.textContent=expanded?'更多':'收起';")+ board = (Path(__file__).resolve().parents[1] / "web/board.css").read_text(encoding="utf-8")+ self.assertIn(".drawer .board-sidebar-body .sidemore{", board)+ self.assertNotIn(+ ".drawer .sec:has(.board-section-toggle[aria-expanded=false]) [data-more]", board,+ "它落在组的正文里,折叠时跟正文一起收走,不必单独藏")+def test_the_discovery_tag_row_changes_with_the_batch_seed(self):"""标签条跟着「换一批」的种子换成员,同一批内不动。diff --git a/web/app.js b/web/app.jsindex 33a5e46e9..7938a9cea 100644--- a/web/app.js+++ b/web/app.js@@ -3400,8 +3400,10 @@ async function buildBars(){<input id="durMin" type="range" min="0" max="180" step="5" value="${filterState.dur_min?Math.min(180,+filterState.dur_min/60):0}" aria-label="最短时长(分钟)"><input id="durMax" type="range" min="0" max="180" step="5" value="${filterState.dur_max?Math.min(180,+filterState.dur_max/60):180}" aria-label="最长时长(分钟)"></div></div>`:'','','meta')+sec('画幅',chips(facetData.orientations,'orient'),'','meta')- +sec('创作者',chips(scopedCreators,'creator',false,26),scopedCreators.length>26?'<button data-more="creator">更多</button>':'','artist')- +sec('内容标签',chips(facetData.tags,'tag',false,30),facetData.tags.length>30?'<button data-more="tag">更多</button>':'','general')+ /* 「更多」接在名单末尾,它说的是「这张名单还没完」——那句话要跟名单断掉的地方在+ 一起。挂在组名那一行时,人得先把这一列读到底、再抬头回到标题去找它。 */+ +sec('创作者',chips(scopedCreators,'creator',false,26),scopedCreators.length>26?'<button class="sidemore" data-more="creator">更多</button>':'','artist')+ +sec('内容标签',chips(facetData.tags,'tag',false,30),facetData.tags.length>30?'<button class="sidemore" data-more="tag">更多</button>':'','general')+sec('影片属性',chips(facetData.tech,'tag',false,16),'','meta')+sec('关注标签',followTagRows.length?`<div class="chips">`+followTagRows.map(row=>`<button class="chip online" data-follow-drawer-tag="${esc(row.k)}"><span class="chip-label">${esc(tagLabel(row.k))}</span><span class="n">${row.n.toLocaleString()}</span></button>`@@ -3439,12 +3441,12 @@ async function buildBars(){durMin.oninput=()=>syncDuration(false,'min');durMax.oninput=()=>syncDuration(false,'max');durMin.onchange=()=>syncDuration(true,'min');durMax.onchange=()=>syncDuration(true,'max');syncDuration();}- $('#drawer').querySelectorAll('[data-more]').forEach(b=>b.onclick=e=>{e.stopPropagation();- const sec=b.closest('.sec'), k=b.dataset.more;+ $('#drawer').querySelectorAll('[data-more]').forEach(b=>b.onclick=()=>{+ const group=b.closest('.sec'), k=b.dataset.more;const src=k==='tag'?facetData.tags:scopedCreators;const lim=k==='tag'?30:26;const expanded=b.dataset.on==='1';- sec.querySelector('.chips').outerHTML=chips(src,k,false,expanded?lim:999);+ group.querySelector('.chips').outerHTML=chips(src,k,false,expanded?lim:999);b.dataset.on=expanded?'0':'1';b.textContent=expanded?'更多':'收起';bind();});diff --git a/web/board.css b/web/board.cssindex a8ffa71b3..d50ccc8b9 100644--- a/web/board.css+++ b/web/board.css@@ -651,7 +651,6 @@ button,input,select,textarea{font-family:inherit}.vwrap>.gate{box-sizing:border-box;border-radius:inherit}.stage .vwrap{overflow:hidden;border-radius:var(--surface-radius)}.board-section-toggle svg{order:2;margin-left:auto;width:14px;height:14px;flex:none;fill:none;stroke:currentColor;stroke-width:2;transform:rotate(0deg)}.board-section-toggle[aria-expanded=true] svg{transform:rotate(90deg)}-.drawer .sec:has(.board-section-toggle[aria-expanded=false]) [data-more]{display:none}.drawer .board-sidebar-body[hidden]{display:none}.drawer .board-sidebar-body .chips{display:flex;flex-direction:column;gap:2px;padding-left:8px}.drawer .board-sidebar-body .chip{display:flex;width:100%;min-width:0;min-height:36px;gap:8px;padding:8px;border:0;border-radius:10px;background:transparent;color:var(--muted);font-size:14px;line-height:20px;text-align:left;font-weight:400}@@ -660,6 +659,9 @@ button,input,select,textarea{font-family:inherit}.drawer .board-sidebar-body .chip-label{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.drawer .board-sidebar-body .chip .n{margin-left:auto;flex:none;padding:1px 4px;border-radius:4px;background:var(--surface);color:var(--muted);font-size:12px;line-height:16px}.drawer .board-sidebar-body .chip svg{flex:none;width:16px;height:16px}+/* 名单末尾那一句跟条目左对齐,但比条目轻:它不是名单里的一项,是名单还没完这件事。 */+.drawer .board-sidebar-body .sidemore{display:flex;align-items:center;width:calc(100% - 8px);margin:2px 0 0 8px;min-height:32px;padding:6px 8px;border:0;border-radius:10px;background:transparent;color:var(--muted);font-size:13px;line-height:20px;text-align:left;font-weight:500}+.drawer .board-sidebar-body .sidemore:hover{background:var(--hover);color:var(--ink)}/* 观看进度与动作分别成组,操作按钮保留各自的可访问名称。 */.sidecontent .trace{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;padding:0;margin:8px 0 16px}.sidecontent .trace-metric{min-width:0;padding:14px 12px;background:var(--surface);border-radius:12px}diff --git a/web/dist/peach-ui.js b/web/dist/peach-ui.jsindex af660b177..1c328793c 100644--- a/web/dist/peach-ui.js+++ b/web/dist/peach-ui.js@@ -1670,18 +1670,18 @@ var yn = (e) => e.replace(/[&<>"']/g, (e) => ({function bn(e, t, n = "", r = "") {if (!t) return "";let i = `sidebar-group-${encodeURIComponent(e)}`;- return `<details class="sec${r ? " cat-" + yn(r) : ""}" data-sidebar-group="${yn(e)}"><summary role="button" class="board-section-toggle"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="#i-chevron-right"/></svg><span>${yn(e)}</span>${n}</summary><div class="board-sidebar-body" id="${i}">${t}</div></details>`;+ return `<details class="sec${r ? " cat-" + yn(r) : ""}" data-sidebar-group="${yn(e)}"><summary role="button" class="board-section-toggle"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="#i-chevron-right"/></svg><span>${yn(e)}</span></summary><div class="board-sidebar-body" id="${i}">${t}${n}</div></details>`;}function xn(e) {e.querySelectorAll("[data-sidebar-group]").forEach((e) => {if (e.dataset.sidebarWired) return;e.dataset.sidebarWired = "true";- let t = e.querySelector(".board-section-toggle"), n = e.querySelector(".board-sidebar-body"), r = `peach.sidebar.group.${e.dataset.sidebarGroup}`, i = null;+ let t = e.querySelector(".board-sidebar-body"), n = `peach.sidebar.group.${e.dataset.sidebarGroup}`, r = null;try {- i = sessionStorage.getItem(r);+ r = sessionStorage.getItem(n);} catch {}- let a = !!n.querySelector("[aria-pressed=true]");- e.open = i === null ? a : i === "open", t.querySelectorAll("button").forEach((e) => e.addEventListener("click", (e) => e.stopPropagation()));+ let i = !!t.querySelector("[aria-pressed=true]");+ e.open = r === null ? i : r === "open";}), y(e, "details[data-sidebar-group]", "sidebar-collapse"), e.querySelectorAll(".board-section-toggle").forEach((e) => {e.dataset.persistWired || (e.dataset.persistWired = "true", e.addEventListener("click", () => {let t = `peach.sidebar.group.${e.closest("[data-sidebar-group]").dataset.sidebarGroup}`;