@lysyi3m/sidecar 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -132,6 +132,10 @@ const BRAND_MARK = raw('<svg viewBox="0 0 18 18" class="brand-mark" aria-hidden=
132
132
  const SIDEBAR_ICON = raw('<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M2.5 3.5h11v9h-11zM6 3.5v9"/></svg>');
133
133
  /** A tray with an arrow into it: save. */
134
134
  const EXPORT_ICON = raw('<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M8 2.5v7.5M5 7l3 3 3-3M2.5 10.5v2.5h11v-2.5"/></svg>');
135
+ /** The sidebar's sections, in the order they appear. */
136
+ export const SECTIONS = ["active", "closed"];
137
+ /** The sections a browser that has never toggled one sees collapsed. */
138
+ export const DEFAULT_COLLAPSED = new Set(["closed"]);
135
139
  /** The page around its content: the sidebar with the case list, and the main column. */
136
140
  function shell(opts) {
137
141
  return html `<!doctype html>
@@ -148,7 +152,7 @@ function shell(opts) {
148
152
  <div class="shell${opts.chrome.collapsed ? " is-collapsed" : ""}">
149
153
  <aside class="sidebar">
150
154
  <div class="sidebar-head"><a class="brand" href="/">${BRAND_MARK}sidecar</a><span class="brand-version">v${SIDECAR_VERSION}</span></div>
151
- ${sideList(opts.cases, opts.activeCase)}
155
+ ${sideList(opts.cases, opts.activeCase, opts.chrome.sections)}
152
156
  </aside>
153
157
  <main class="main"><div class="page">
154
158
  <div class="topbar"><button class="icon-button sidebar-toggle" type="button" aria-label="Toggle the case list" data-toggle-sidebar>${SIDEBAR_ICON}</button><div class="crumbs">${opts.crumbs}</div>${opts.actions ? html `<div class="topbar-actions">${opts.actions}</div>` : ""}</div>
@@ -159,8 +163,11 @@ ${opts.content}
159
163
  </html>`;
160
164
  }
161
165
  const isUnreadable = (c) => c.state === "unreadable";
162
- /** The sidebar's case list. The page refreshes it from /fragments/sidebar. */
163
- export function sideList(cases, activeCase) {
166
+ /**
167
+ * The sidebar's case list. The page refreshes it from /fragments/sidebar. A section in `collapsed`
168
+ * renders closed, unless it holds the open case.
169
+ */
170
+ export function sideList(cases, activeCase, collapsed = DEFAULT_COLLAPSED) {
164
171
  const open = cases.filter((c) => c.state === "open");
165
172
  // An unreadable case is listed with the closed ones, never hidden.
166
173
  const closed = cases.filter((c) => c.state === "closed" || isUnreadable(c));
@@ -168,28 +175,38 @@ export function sideList(cases, activeCase) {
168
175
  const item = (c) => isUnreadable(c)
169
176
  ? html `<a class="side-case" href="/cases/${c.case_id}"${current(c)}>
170
177
  <div class="side-title">${c.case_id}</div>
171
- <div class="side-meta"><span class="mono">${c.case_id}</span><span class="side-tag">unreadable</span></div>
178
+ <div class="side-meta"><span class="side-tag">unreadable</span></div>
172
179
  </a>`
173
180
  : html `<a class="side-case" href="/cases/${c.case_id}"${current(c)}>
174
181
  <div class="side-title">${c.title || c.case_id}</div>
175
- <div class="side-meta"><span class="mono">${c.case_id}</span><span>${ago(c.updated)}</span>${
182
+ <div class="side-meta"><span>${ago(c.updated)}</span>${
176
183
  // The section heading already says active or closed; only a state worth noticing gets a tag.
177
184
  c.in_flight ? html `<span class="side-tag is-accent">asking</span>` : ""}</div>
178
185
  </a>`;
186
+ const section = (name, label, members) => {
187
+ if (!members.length)
188
+ return "";
189
+ const expanded = !collapsed.has(name) || members.some((c) => c.case_id === activeCase) ? "true" : "false";
190
+ return html `<section class="side-group" data-section="${name}">
191
+ <button class="side-section label" type="button" data-section="${name}" aria-expanded="${expanded}" aria-label="${label}, ${String(members.length)} ${members.length === 1 ? "case" : "cases"}"><span class="chevron" aria-hidden="true"></span>${label}<span class="side-count" aria-hidden="true">${String(members.length)}</span></button>
192
+ <div class="side-group-body">${members.map(item)}</div>
193
+ </section>`;
194
+ };
179
195
  const query = activeCase ? `?active=${activeCase}` : "";
180
- return html `<nav class="side-list" id="side-list" aria-label="Cases" data-refresh="/fragments/sidebar${query}">${cases.length === 0 ? html `<div class="side-empty">No cases yet.</div>` : ""}${open.length ? [html `<div class="side-section label">Active</div>`, ...open.map(item)] : ""}${closed.length ? [html `<div class="side-section label">Closed</div>`, ...closed.map(item)] : ""}</nav>`;
196
+ return html `<nav class="side-list" id="side-list" aria-label="Cases" data-refresh="/fragments/sidebar${query}">${cases.length === 0 ? html `<div class="side-empty">No cases yet.</div>` : ""}${section("active", "Active", open)}${section("closed", "Closed", closed)}</nav>`;
181
197
  }
182
198
  /* ---------------------------------------------------------------- index */
183
- const FILTERS = ["all", "open", "closed"];
199
+ /** The index's state filters, by the case state each shows, with the label the sidebar uses. */
200
+ const FILTERS = ["open", "closed"];
201
+ const FILTER_LABELS = { open: "active", closed: "closed" };
184
202
  export function indexPage(cases, query, chrome = { collapsed: false }) {
185
- const filter = FILTERS.find((f) => f === query.state) ?? "all";
186
- const content = html `<h1 class="title">Cases</h1>
187
- <div class="toolbar">
188
- <div class="segmented" role="group" aria-label="Case state">${FILTERS.map((name) => html `<button type="button" class="label" data-filter="${name}" aria-pressed="${String(filter === name)}">${name} <span data-count></span></button>`)}</div>
203
+ const filter = FILTERS.find((f) => f === query.state) ?? "open";
204
+ const content = html `<div class="toolbar">
205
+ <div class="segmented" role="group" aria-label="Case state">${FILTERS.map((name) => html `<button type="button" class="label" data-filter="${name}" aria-pressed="${String(filter === name)}">${FILTER_LABELS[name]} <span data-count></span></button>`)}</div>
189
206
  <div class="search-group"><input type="search" data-search placeholder="Filter by title, id or directory…" aria-label="Filter cases" value="${query.search ?? ""}"><span class="result-count" data-result-count></span></div>
190
207
  </div>
191
208
  <div class="table-scroll"><table data-cases data-filter-state="${filter}">
192
- <thead><tr><th>Case</th><th class="col-state">State</th><th>Driver</th><th>Navigator</th><th>Last activity</th></tr></thead>
209
+ <thead><tr><th>Case</th><th>Driver</th><th>Navigator</th><th>Last activity</th></tr></thead>
193
210
  ${caseRows(cases)}
194
211
  </table></div>
195
212
  <p class="message" data-message hidden></p>`;
@@ -198,7 +215,8 @@ ${caseRows(cases)}
198
215
  cases,
199
216
  activeCase: null,
200
217
  chrome,
201
- crumbs: html `<span class="here label">Cases</span>`,
218
+ // The breadcrumb is the index's only heading.
219
+ crumbs: html `<h1 class="here label">Cases</h1>`,
202
220
  content,
203
221
  });
204
222
  }
@@ -206,15 +224,15 @@ ${caseRows(cases)}
206
224
  export function caseRows(cases) {
207
225
  return html `<tbody id="case-rows" data-refresh="/fragments/cases">${cases.map((c) => {
208
226
  if (isUnreadable(c)) {
209
- return html `<tr data-href="/cases/${c.case_id}" data-state="unreadable" data-haystack="${c.case_id}">
210
- <td><span class="case-title">${c.case_id}</span><div class="case-sub mono">${c.error}</div></td>
211
- <td class="col-state">${stateChip("unreadable")}</td><td></td><td></td><td></td>
227
+ // Listed under the closed filter, as the sidebar lists it with the closed cases.
228
+ return html `<tr data-href="/cases/${c.case_id}" data-state="closed" data-haystack="${c.case_id}">
229
+ <td><span class="case-title">${c.case_id}</span> ${stateChip("unreadable")}<div class="case-sub mono">${c.error}</div></td>
230
+ <td></td><td></td><td></td>
212
231
  </tr>`;
213
232
  }
214
233
  const haystack = [c.title, c.case_id, c.workspace].join(" ").toLowerCase();
215
234
  return html `<tr data-href="/cases/${c.case_id}" data-state="${c.state}" data-haystack="${haystack}">
216
235
  <td><a class="case-title" href="/cases/${c.case_id}">${c.title || c.case_id}</a><div class="case-sub case-where mono"><span>${c.case_id}</span><span>·</span>${pathLine(c.workspace)}</div></td>
217
- <td class="col-state">${stateChip(c.state)}</td>
218
236
  <td>${driverLine(c.driver, c.driver_model, c.driver_effort)}</td>
219
237
  <td>${agentLine(c.navigator, c.model, c.effort)}</td>
220
238
  <td><div>${ago(c.updated)}</div><div class="case-sub mono">${time(c.updated, "stamp")}</div></td>
@@ -253,8 +271,8 @@ function caseHead(model) {
253
271
  const opinions = [...state.asks.values()].filter((a) => a.terminal?.kind === "opinion").length;
254
272
  const fact = (name, value) => html `<div class="fact"><dt class="label">${name}</dt><dd>${value}</dd></div>`;
255
273
  return html `<header class="case-head" id="case-head">
256
- <div class="title-row"><span class="case-id mono">${caseId}</span><h1 class="title">${opened.title}</h1>${stateChip(status)}</div>
257
- <div class="case-path mono">${pathLine(opened.workspace)}</div>
274
+ <h1 class="title">${opened.title}</h1>
275
+ <div class="case-meta">${stateChip(status)}<div class="case-path case-where mono"><span>${caseId}</span><span>·</span>${pathLine(opened.workspace)}</div></div>
258
276
  <dl class="facts">${[
259
277
  fact("Driver", driverLine(opened.driver, state.driverModel, state.driverEffort)),
260
278
  fact("Navigator", agentLine(opened.navigator, opened.model, opened.effort)),
@@ -11,7 +11,7 @@ import { loadConfig } from "../config.js";
11
11
  import { CaseIndex, stampOf, unchanged } from "./cases.js";
12
12
  import { dashboardBase, isLoopbackHost } from "./links.js";
13
13
  import { MARKS } from "./marks.js";
14
- import { caseRows, casePage, caseUnits, indexPage, sideList } from "./pages.js";
14
+ import { caseRows, casePage, caseUnits, DEFAULT_COLLAPSED, indexPage, SECTIONS, sideList, } from "./pages.js";
15
15
  import { caseModel } from "./view.js";
16
16
  // The dashboard: a read-only web UI over the case store. Two pages — the case index at / and one
17
17
  // case at /cases/<id> — rendered on the server (pages.ts) from the view model (view.ts), styled by
@@ -48,7 +48,9 @@ const ASSETS = new Map(readdirSync(STATIC)
48
48
  return [name, { body, type, etag: etagOf(body) }];
49
49
  }));
50
50
  const COOKIE = "sidecar_token";
51
- const SIDEBAR_COOKIE = "sidecar_sidebar";
51
+ /** A cookie that keeps UI state is named `sidecar_ui_<name>`. */
52
+ const SIDEBAR_COOKIE = "sidecar_ui_sidebar";
53
+ const SECTIONS_COOKIE = "sidecar_ui_sections";
52
54
  /** A client's address; a dual-stack listener reports an IPv4 client in its IPv4-mapped form. */
53
55
  const isLoopbackAddress = (address) => isLoopbackHost(address.replace(/^::ffff:(?=[\d.]+$)/i, ""));
54
56
  export async function startDashboard(store, opts = {}) {
@@ -121,15 +123,35 @@ export function authorize(req, port, token) {
121
123
  reason: "access token required: open the dashboard link `sidecar status` prints",
122
124
  };
123
125
  }
124
- const cookieValue = (header, name) => (header ?? "")
125
- .split(";")
126
- .map((c) => c.trim().split("="))
127
- .find(([key]) => key === name)?.[1];
126
+ /** A cookie's value is everything after the first `=`: a value may hold `=` itself. */
127
+ const cookieValue = (header, name) => {
128
+ const prefix = `${name}=`;
129
+ return (header ?? "")
130
+ .split(";")
131
+ .map((c) => c.trim())
132
+ .find((c) => c.startsWith(prefix))
133
+ ?.slice(prefix.length);
134
+ };
128
135
  /**
129
136
  * The sidebar's state, which the browser keeps in a cookie (static/app.js) rather than in storage
130
137
  * only a script can read: the server renders it, so a page never paints the sidebar open first.
131
138
  */
132
139
  const sidebarCollapsed = (header) => cookieValue(header, SIDEBAR_COOKIE) === "collapsed";
140
+ /**
141
+ * The sidebar sections this browser keeps collapsed: their names joined with `|`. An unknown name
142
+ * is skipped. Without the cookie, the default applies; an empty value collapses none.
143
+ */
144
+ const collapsedSections = (header) => {
145
+ const value = cookieValue(header, SECTIONS_COOKIE);
146
+ if (value === undefined)
147
+ return DEFAULT_COLLAPSED;
148
+ const names = new Set(value.split("|"));
149
+ return new Set(SECTIONS.filter((s) => names.has(s)));
150
+ };
151
+ const chromeOf = (header) => ({
152
+ collapsed: sidebarCollapsed(header),
153
+ sections: collapsedSections(header),
154
+ });
133
155
  /** Constant-time comparison, so response timing does not leak the token. */
134
156
  function same(a, b) {
135
157
  const x = Buffer.from(a);
@@ -186,16 +208,16 @@ function app(store, port, token, limits) {
186
208
  // the stream reports that reason as a `problem` event.
187
209
  const exists = (caseId) => isCaseId(caseId) && existsSync(store.logPath(caseId));
188
210
  const NO_CASE = "no such case";
189
- web.get("/", async (c) => htmlResponse(indexPage((await cases.list()).cases, { state: c.req.query("state"), search: c.req.query("search") }, { collapsed: sidebarCollapsed(c.req.header("cookie")) })));
211
+ web.get("/", async (c) => htmlResponse(indexPage((await cases.list()).cases, { state: c.req.query("state"), search: c.req.query("search") }, chromeOf(c.req.header("cookie")))));
190
212
  web.get("/cases/:id", async (c) => {
191
213
  const caseId = c.req.param("id");
192
214
  if (!exists(caseId))
193
215
  return c.text(NO_CASE, 404);
194
- return htmlResponse(casePage(caseModel(caseId, await store.read(caseId), reviewBudget(store)), (await cases.list()).cases, { collapsed: sidebarCollapsed(c.req.header("cookie")) }));
216
+ return htmlResponse(casePage(caseModel(caseId, await store.read(caseId), reviewBudget(store)), (await cases.list()).cases, chromeOf(c.req.header("cookie"))));
195
217
  });
196
218
  web.get("/fragments/sidebar", (c) => {
197
219
  const active = c.req.query("active");
198
- return fragmentResponse(c, (list) => sideList(list.cases, active && isCaseId(active) ? active : null));
220
+ return fragmentResponse(c, (list) => sideList(list.cases, active && isCaseId(active) ? active : null, collapsedSections(c.req.header("cookie"))));
199
221
  });
200
222
  web.get("/fragments/cases", (c) => fragmentResponse(c, (list) => caseRows(list.cases)));
201
223
  web.get("/assets/agents/:name{[a-z0-9-]+\\.svg}", (c) => {
@@ -15,6 +15,7 @@
15
15
  --ink-2: light-dark(#4e5766, #a3adbb);
16
16
  --ink-3: light-dark(#8b94a1, #6e7784);
17
17
  --accent: light-dark(#1f4fd8, #8aa6ff);
18
+ --accent-weak: light-dark(#e8eefc, #16203a);
18
19
  --alert: light-dark(#9a3412, #e0a165);
19
20
  --alert-weak: light-dark(#fdf3ec, #221a12);
20
21
  --ok: light-dark(#2f6b3f, #8cc79c);
@@ -79,7 +80,6 @@ button {
79
80
  display: grid;
80
81
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
81
82
  min-height: 100vh;
82
- transition: grid-template-columns 160ms ease;
83
83
 
84
84
  &.is-collapsed {
85
85
  grid-template-columns: 0 minmax(0, 1fr);
@@ -140,9 +140,51 @@ button {
140
140
  min-width: var(--sidebar);
141
141
  }
142
142
 
143
+ /* A section head is a button that reads like a label: a chevron, the name and the case count. */
143
144
  .side-section {
145
+ display: flex;
146
+ align-items: center;
147
+ gap: 6px;
148
+ width: 100%;
144
149
  padding: 14px 16px 6px;
150
+ border: 0;
151
+ border-radius: 0;
152
+ background: none;
145
153
  color: var(--ink-3);
154
+ text-align: left;
155
+
156
+ &:hover {
157
+ color: var(--ink-2);
158
+ }
159
+
160
+ &:focus-visible {
161
+ outline: 2px solid var(--accent);
162
+ outline-offset: -2px;
163
+ }
164
+
165
+ & .chevron {
166
+ flex: none;
167
+ width: 5px;
168
+ height: 5px;
169
+ margin: 0 3px 2px 1px;
170
+ border-right: 1.5px solid currentColor;
171
+ border-bottom: 1.5px solid currentColor;
172
+ rotate: 45deg;
173
+ }
174
+
175
+ &[aria-expanded="false"] .chevron {
176
+ rotate: -45deg;
177
+ margin-bottom: 0;
178
+ }
179
+
180
+ & .side-count {
181
+ font-weight: 400;
182
+ letter-spacing: 0;
183
+ }
184
+
185
+ &[aria-expanded="false"] + .side-group-body {
186
+ display: none;
187
+ }
146
188
  }
147
189
 
148
190
  .side-case {
@@ -155,12 +197,23 @@ button {
155
197
  background: var(--hair);
156
198
  }
157
199
 
200
+ /* The open case: an accent bar and tint, and its meta line at full ink. */
158
201
  &[aria-current="page"] {
159
- background: var(--bg);
160
- border-left-color: var(--ink);
202
+ background: var(--accent-weak);
203
+ border-left-color: var(--accent);
204
+
205
+ & .side-meta {
206
+ color: var(--ink);
207
+ }
161
208
  }
162
209
  }
163
210
 
211
+ /* A link's text takes the accent on hover. A row that is a link colours its title. */
212
+ .side-case:hover .side-title,
213
+ tbody tr:hover .case-title {
214
+ color: var(--accent);
215
+ }
216
+
164
217
  .side-title {
165
218
  display: -webkit-box;
166
219
  -webkit-line-clamp: 2;
@@ -254,6 +307,7 @@ button {
254
307
  }
255
308
 
256
309
  & .here {
310
+ margin: 0;
257
311
  color: var(--ink-2);
258
312
  overflow: hidden;
259
313
  text-overflow: ellipsis;
@@ -488,10 +542,6 @@ tbody tr {
488
542
  font-weight: 500;
489
543
  letter-spacing: -0.01em;
490
544
  text-decoration: none;
491
-
492
- &:hover {
493
- color: var(--accent);
494
- }
495
545
  }
496
546
 
497
547
  .case-sub {
@@ -500,11 +550,6 @@ tbody tr {
500
550
  color: var(--ink-3);
501
551
  }
502
552
 
503
- /* Under the open or closed filter every row has the same state, so the column says nothing. */
504
- table:not([data-filter-state="all"]) .col-state {
505
- display: none;
506
- }
507
-
508
553
  /* The case column takes the width the other columns leave. */
509
554
  tbody td:first-child {
510
555
  width: 100%;
@@ -585,22 +630,6 @@ tbody td:first-child {
585
630
  gap: 14px;
586
631
  }
587
632
 
588
- .title-row {
589
- display: flex;
590
- align-items: flex-start;
591
- gap: 12px;
592
-
593
- & .chip {
594
- margin-top: 6px;
595
- }
596
- }
597
-
598
- .case-id {
599
- margin-top: 7px;
600
- font-size: 12px;
601
- color: var(--ink-3);
602
- }
603
-
604
633
  /* An agent's mark sits on the text baseline and takes the surrounding ink: its file is a mask over
605
634
  the text colour, so one cached file serves every theme. */
606
635
  .agent-mark {
@@ -620,9 +649,23 @@ tbody td:first-child {
620
649
  white-space: nowrap;
621
650
  }
622
651
 
623
- /* The working directory, under the title, on one line (see .path-line). */
624
- .case-path {
652
+ /* Under the title: the state chip, then the id and the working directory on one line (see
653
+ .case-where). The chip sits here, not beside the title: a balanced title keeps its full width,
654
+ so a chip beside it lands far from the text. */
655
+ .case-meta {
656
+ display: flex;
657
+ align-items: center;
658
+ gap: 10px;
625
659
  margin-top: -6px;
660
+
661
+ & .chip {
662
+ flex: none;
663
+ }
664
+ }
665
+
666
+ .case-path {
667
+ flex: 1;
668
+ min-width: 0;
626
669
  font-size: 12px;
627
670
  color: var(--ink-2);
628
671
  }
@@ -1138,10 +1181,6 @@ tbody td:first-child {
1138
1181
  grid-row: 1;
1139
1182
  }
1140
1183
 
1141
- .title-row {
1142
- flex-wrap: wrap;
1143
- }
1144
-
1145
1184
  h1.title {
1146
1185
  font-size: 20px;
1147
1186
  }
@@ -77,6 +77,7 @@ for (const element of document.querySelectorAll("[data-refresh]")) {
77
77
  // Kept only once the list is applied: a body lost to the timeout must not earn a 304.
78
78
  const next = response.headers.get("etag");
79
79
  apply(await response.text());
80
+ keepSections();
80
81
  filterCases();
81
82
  etag = next;
82
83
  }
@@ -191,31 +192,93 @@ document.querySelector("[data-export]")?.addEventListener("click", (event) => {
191
192
 
192
193
  // Small screens have no sidebar and no toggle (app.css), so the stored state applies to wide ones only.
193
194
  // The state lives in a cookie the server reads, so the page arrives already in it: this script
194
- // runs after the first paint, and applying the state here would animate the sidebar shut.
195
+ // runs after the first paint, and applying the state here would flash the sidebar open.
195
196
  const shell = document.querySelector(".shell");
197
+ const SIDEBAR_COOKIE = "sidecar_ui_sidebar";
198
+ const SECTIONS_COOKIE = "sidecar_ui_sections";
199
+ /** The sections collapsed while the cookie is absent; server.ts has the same default. */
200
+ const DEFAULT_COLLAPSED = ["closed"];
201
+
202
+ const readCookie = (name) => {
203
+ const prefix = `${name}=`;
204
+ return document.cookie
205
+ .split(";")
206
+ .map((c) => c.trim())
207
+ .find((c) => c.startsWith(prefix))
208
+ ?.slice(prefix.length);
209
+ };
210
+ const writeCookie = (name, value) => {
211
+ document.cookie = `${name}=${value}; Path=/; SameSite=Strict; Max-Age=31536000`;
212
+ };
196
213
 
197
214
  document.querySelector("[data-toggle-sidebar]")?.addEventListener("click", () => {
198
215
  const collapsed = shell.classList.toggle("is-collapsed");
199
- document.cookie = `sidecar_sidebar=${collapsed ? "collapsed" : "open"}; Path=/; SameSite=Strict; Max-Age=31536000`;
216
+ writeCookie(SIDEBAR_COOKIE, collapsed ? "collapsed" : "open");
217
+ });
218
+
219
+ const storedSections = () => {
220
+ const value = readCookie(SECTIONS_COOKIE);
221
+ return new Set(value === undefined ? DEFAULT_COLLAPSED : value.split("|").filter(Boolean));
222
+ };
223
+
224
+ /**
225
+ * Each section's state on this page. A refresh renders from the cookie, and the section that holds
226
+ * the open case renders open; the page's own state wins over both, so a refresh never undoes a click.
227
+ */
228
+ const sectionState = new Map();
229
+ const sectionHeads = () => document.querySelectorAll("button[data-section]");
230
+ const keepSections = () => {
231
+ for (const head of sectionHeads()) {
232
+ const expanded = sectionState.get(head.dataset.section);
233
+ if (expanded === undefined)
234
+ sectionState.set(head.dataset.section, head.getAttribute("aria-expanded") === "true");
235
+ else head.setAttribute("aria-expanded", String(expanded));
236
+ }
237
+ };
238
+ keepSections();
239
+
240
+ document.addEventListener("click", (event) => {
241
+ const head = event.target.closest("button[data-section]");
242
+ if (!head) return;
243
+ const name = head.dataset.section;
244
+ const expanded = head.getAttribute("aria-expanded") !== "true";
245
+ head.setAttribute("aria-expanded", String(expanded));
246
+ sectionState.set(name, expanded);
247
+ const collapsed = storedSections();
248
+ if (expanded) collapsed.delete(name);
249
+ else collapsed.add(name);
250
+ writeCookie(SECTIONS_COOKIE, [...collapsed].join("|"));
251
+ });
252
+
253
+ // A page restored from the back/forward cache keeps the state it was left in, though another page
254
+ // may have toggled the sidebar or a section since.
255
+ addEventListener("pageshow", (event) => {
256
+ if (!event.persisted || !shell) return;
257
+ shell.classList.toggle("is-collapsed", readCookie(SIDEBAR_COOKIE) === "collapsed");
258
+ const collapsed = storedSections();
259
+ for (const head of sectionHeads()) {
260
+ const holdsCurrent = head.parentElement.querySelector('[aria-current="page"]') !== null;
261
+ const expanded = holdsCurrent || !collapsed.has(head.dataset.section);
262
+ head.setAttribute("aria-expanded", String(expanded));
263
+ sectionState.set(head.dataset.section, expanded);
264
+ }
200
265
  });
201
266
 
202
267
  /* ---------------------------------------------------------------- case index */
203
268
 
204
269
  const search = document.querySelector("[data-search]");
205
270
  // The server renders the filter the URL asks for, already checked.
206
- let filter = document.querySelector("[data-cases]")?.dataset.filterState ?? "all";
271
+ let filter = document.querySelector("[data-cases]")?.dataset.filterState ?? "open";
207
272
 
208
273
  /** Shows the rows that match the state filter and the search text, and keeps the URL in step. */
209
274
  function filterCases() {
210
275
  if (!search) return;
211
276
  const rows = [...document.querySelectorAll("#case-rows tr")];
277
+ const inState = rows.filter((r) => r.dataset.state === filter);
212
278
  const needle = search.value.trim().toLowerCase();
213
279
  let shown = 0;
214
280
  for (const row of rows) {
215
- row.hidden = !(
216
- (filter === "all" || row.dataset.state === filter) &&
217
- row.dataset.haystack.includes(needle)
218
- );
281
+ row.hidden = !(row.dataset.state === filter && row.dataset.haystack.includes(needle));
219
282
  if (!row.hidden) shown++;
220
283
  }
221
284
  document.querySelector("[data-cases]").dataset.filterState = filter;
@@ -223,16 +286,22 @@ function filterCases() {
223
286
  const name = button.dataset.filter;
224
287
  button.setAttribute("aria-pressed", String(name === filter));
225
288
  button.querySelector("[data-count]").textContent = rows.filter(
226
- (r) => name === "all" || r.dataset.state === name,
289
+ (r) => r.dataset.state === name,
227
290
  ).length;
228
291
  }
229
- document.querySelector("[data-result-count]").textContent = `${shown} / ${rows.length}`;
292
+ document.querySelector("[data-result-count]").textContent = `${shown} / ${inState.length}`;
230
293
  const message = document.querySelector("[data-message]");
231
294
  message.hidden = shown > 0;
232
- message.textContent = rows.length === 0 ? "No cases yet." : "No case matches this filter.";
295
+ message.textContent =
296
+ rows.length === 0
297
+ ? "No cases yet."
298
+ : inState.length === 0
299
+ ? `No ${filter === "open" ? "active" : "closed"} cases.`
300
+ : "No case matches this filter.";
233
301
 
234
302
  const url = new URL(location.href);
235
- if (filter === "all") url.searchParams.delete("state");
303
+ // Active is the default, so its URL names no state.
304
+ if (filter === "open") url.searchParams.delete("state");
236
305
  else url.searchParams.set("state", filter);
237
306
  if (needle) url.searchParams.set("search", search.value.trim());
238
307
  else url.searchParams.delete("search");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lysyi3m/sidecar",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Lets one coding agent consult another mid-task: a driver asks, a read-only navigator answers",
5
5
  "license": "MIT",
6
6
  "repository": {