@lysyi3m/sidecar 1.6.1 → 1.7.1
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.
|
@@ -3,6 +3,7 @@ import { effortLabel, modelLabel } from "../adapters/index.js";
|
|
|
3
3
|
import { html, raw } from "./html.js";
|
|
4
4
|
import { MARKS, markUrl } from "./marks.js";
|
|
5
5
|
import { decisionState, flagsOf, reviewsOf } from "../cases/items.js";
|
|
6
|
+
import { SIDECAR_VERSION } from "../lib/version.js";
|
|
6
7
|
import { foundNothingToReview } from "../turns/prompt.js";
|
|
7
8
|
// The dashboard's markup, rendered on the server from the view model. Every element the live
|
|
8
9
|
// stream may replace carries a stable id: the case header, and one id per timeline entry.
|
|
@@ -143,10 +144,10 @@ function shell(opts) {
|
|
|
143
144
|
<link rel="stylesheet" href="/assets/app.css">
|
|
144
145
|
<script type="module" src="/assets/app.js"></script>
|
|
145
146
|
</head>
|
|
146
|
-
<body>
|
|
147
|
+
<body data-sidecar-version="${SIDECAR_VERSION}">
|
|
147
148
|
<div class="shell${opts.chrome.collapsed ? " is-collapsed" : ""}">
|
|
148
149
|
<aside class="sidebar">
|
|
149
|
-
<div class="sidebar-head"><a class="brand" href="/">${BRAND_MARK}sidecar</a></div>
|
|
150
|
+
<div class="sidebar-head"><a class="brand" href="/">${BRAND_MARK}sidecar</a><span class="brand-version">v${SIDECAR_VERSION}</span></div>
|
|
150
151
|
${sideList(opts.cases, opts.activeCase)}
|
|
151
152
|
</aside>
|
|
152
153
|
<main class="main"><div class="page">
|
|
@@ -182,8 +183,7 @@ export function sideList(cases, activeCase) {
|
|
|
182
183
|
const FILTERS = ["all", "open", "closed"];
|
|
183
184
|
export function indexPage(cases, query, chrome = { collapsed: false }) {
|
|
184
185
|
const filter = FILTERS.find((f) => f === query.state) ?? "all";
|
|
185
|
-
const content = html `<
|
|
186
|
-
<div class="toolbar">
|
|
186
|
+
const content = html `<div class="toolbar">
|
|
187
187
|
<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>
|
|
188
188
|
<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>
|
|
189
189
|
</div>
|
|
@@ -197,7 +197,8 @@ ${caseRows(cases)}
|
|
|
197
197
|
cases,
|
|
198
198
|
activeCase: null,
|
|
199
199
|
chrome,
|
|
200
|
-
|
|
200
|
+
// The breadcrumb is the index's only heading.
|
|
201
|
+
crumbs: html `<h1 class="here label">Cases</h1>`,
|
|
201
202
|
content,
|
|
202
203
|
});
|
|
203
204
|
}
|
|
@@ -227,7 +228,8 @@ export function casePage(model, cases, chrome = { collapsed: false }) {
|
|
|
227
228
|
const content = html `${caseHead(model)}
|
|
228
229
|
${brief(model)}
|
|
229
230
|
<p class="message problem" role="alert" data-problem hidden></p>
|
|
230
|
-
<div class="timeline" id="timeline" data-stream="/api/cases/${model.caseId}/stream?after=${last}">${timelineUnits(model).map((u) => u.html)}</div
|
|
231
|
+
<div class="timeline" id="timeline" data-stream="/api/cases/${model.caseId}/stream?after=${last}">${timelineUnits(model).map((u) => u.html)}</div>
|
|
232
|
+
<div class="to-top" data-to-top><a class="ref" href="#top">↑ Back to top</a></div>`;
|
|
231
233
|
return shell({
|
|
232
234
|
title: `${String(opened.title)} — sidecar`,
|
|
233
235
|
cases,
|
|
@@ -48,7 +48,8 @@ const ASSETS = new Map(readdirSync(STATIC)
|
|
|
48
48
|
return [name, { body, type, etag: etagOf(body) }];
|
|
49
49
|
}));
|
|
50
50
|
const COOKIE = "sidecar_token";
|
|
51
|
-
|
|
51
|
+
/** A cookie that keeps UI state is named `sidecar_ui_<name>`. */
|
|
52
|
+
const SIDEBAR_COOKIE = "sidecar_ui_sidebar";
|
|
52
53
|
/** A client's address; a dual-stack listener reports an IPv4 client in its IPv4-mapped form. */
|
|
53
54
|
const isLoopbackAddress = (address) => isLoopbackHost(address.replace(/^::ffff:(?=[\d.]+$)/i, ""));
|
|
54
55
|
export async function startDashboard(store, opts = {}) {
|
|
@@ -121,10 +122,15 @@ export function authorize(req, port, token) {
|
|
|
121
122
|
reason: "access token required: open the dashboard link `sidecar status` prints",
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
/** A cookie's value is everything after the first `=`: a value may hold `=` itself. */
|
|
126
|
+
const cookieValue = (header, name) => {
|
|
127
|
+
const prefix = `${name}=`;
|
|
128
|
+
return (header ?? "")
|
|
129
|
+
.split(";")
|
|
130
|
+
.map((c) => c.trim())
|
|
131
|
+
.find((c) => c.startsWith(prefix))
|
|
132
|
+
?.slice(prefix.length);
|
|
133
|
+
};
|
|
128
134
|
/**
|
|
129
135
|
* The sidebar's state, which the browser keeps in a cookie (static/app.js) rather than in storage
|
|
130
136
|
* only a script can read: the server renders it, so a page never paints the sidebar open first.
|
|
@@ -79,7 +79,6 @@ button {
|
|
|
79
79
|
display: grid;
|
|
80
80
|
grid-template-columns: var(--sidebar) minmax(0, 1fr);
|
|
81
81
|
min-height: 100vh;
|
|
82
|
-
transition: grid-template-columns 160ms ease;
|
|
83
82
|
|
|
84
83
|
&.is-collapsed {
|
|
85
84
|
grid-template-columns: 0 minmax(0, 1fr);
|
|
@@ -119,6 +118,13 @@ button {
|
|
|
119
118
|
text-decoration: none;
|
|
120
119
|
}
|
|
121
120
|
|
|
121
|
+
.brand-version {
|
|
122
|
+
margin-left: 8px;
|
|
123
|
+
font-family: var(--font-mono);
|
|
124
|
+
font-size: 12px;
|
|
125
|
+
color: var(--ink-3);
|
|
126
|
+
}
|
|
127
|
+
|
|
122
128
|
/* The mark: two linked squares — a driver and its navigator. */
|
|
123
129
|
.brand-mark {
|
|
124
130
|
width: 18px;
|
|
@@ -187,12 +193,39 @@ button {
|
|
|
187
193
|
}
|
|
188
194
|
|
|
189
195
|
.page {
|
|
196
|
+
--page-gap: 22px;
|
|
197
|
+
--page-end: 96px;
|
|
198
|
+
--entry-end: 16px;
|
|
199
|
+
--service-end: 10px;
|
|
190
200
|
max-width: 1080px;
|
|
191
201
|
margin: 0 auto;
|
|
192
|
-
padding: 26px 32px
|
|
202
|
+
padding: 26px 32px var(--page-end);
|
|
193
203
|
display: flex;
|
|
194
204
|
flex-direction: column;
|
|
195
|
-
gap:
|
|
205
|
+
gap: var(--page-gap);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/*
|
|
209
|
+
* A link back to the top of a long case. It fills the empty band between the last entry and the
|
|
210
|
+
* end of the page, centred in it, without making the page taller: the top margin takes back the
|
|
211
|
+
* flex gap and the last entry's bottom padding, the bottom margin the page's end padding. It shows
|
|
212
|
+
* only once the timeline holds more than 10 entries; CSS counts them, so streamed entries count too.
|
|
213
|
+
*/
|
|
214
|
+
.to-top {
|
|
215
|
+
--last-end: var(--entry-end);
|
|
216
|
+
display: none;
|
|
217
|
+
align-items: center;
|
|
218
|
+
justify-content: center;
|
|
219
|
+
height: calc(var(--last-end) + var(--page-end));
|
|
220
|
+
margin: calc(-1 * (var(--page-gap) + var(--last-end))) 0 calc(-1 * var(--page-end));
|
|
221
|
+
|
|
222
|
+
.timeline:has(> .entry.service:last-child) + & {
|
|
223
|
+
--last-end: var(--service-end);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.timeline:has(> .entry:nth-child(11)) + & {
|
|
227
|
+
display: flex;
|
|
228
|
+
}
|
|
196
229
|
}
|
|
197
230
|
|
|
198
231
|
.topbar {
|
|
@@ -220,6 +253,7 @@ button {
|
|
|
220
253
|
}
|
|
221
254
|
|
|
222
255
|
& .here {
|
|
256
|
+
margin: 0;
|
|
223
257
|
color: var(--ink-2);
|
|
224
258
|
overflow: hidden;
|
|
225
259
|
text-overflow: ellipsis;
|
|
@@ -772,7 +806,7 @@ tbody td:first-child {
|
|
|
772
806
|
}
|
|
773
807
|
|
|
774
808
|
.entry-body {
|
|
775
|
-
padding: 6px 0
|
|
809
|
+
padding: 6px 0 var(--entry-end);
|
|
776
810
|
min-width: 0;
|
|
777
811
|
}
|
|
778
812
|
|
|
@@ -993,7 +1027,7 @@ tbody td:first-child {
|
|
|
993
1027
|
}
|
|
994
1028
|
|
|
995
1029
|
.entry.service .entry-body {
|
|
996
|
-
padding: 0 0
|
|
1030
|
+
padding: 0 0 var(--service-end);
|
|
997
1031
|
}
|
|
998
1032
|
|
|
999
1033
|
.entry.service .marker {
|
|
@@ -1053,7 +1087,8 @@ tbody td:first-child {
|
|
|
1053
1087
|
}
|
|
1054
1088
|
|
|
1055
1089
|
.page {
|
|
1056
|
-
|
|
1090
|
+
--page-end: 72px;
|
|
1091
|
+
padding: 18px 16px var(--page-end);
|
|
1057
1092
|
}
|
|
1058
1093
|
|
|
1059
1094
|
/* The time moves from its gutter onto a line of its own above the entry. */
|
|
@@ -118,6 +118,7 @@ async function exportCase(caseId) {
|
|
|
118
118
|
const page = document.querySelector(".page").cloneNode(true);
|
|
119
119
|
page.querySelector(".topbar")?.remove();
|
|
120
120
|
page.querySelector("[data-problem]")?.remove();
|
|
121
|
+
page.querySelector("[data-to-top]")?.remove();
|
|
121
122
|
for (const node of page.querySelectorAll("[data-stream], [data-refresh]")) {
|
|
122
123
|
node.removeAttribute("data-stream");
|
|
123
124
|
node.removeAttribute("data-refresh");
|
|
@@ -136,7 +137,8 @@ async function exportCase(caseId) {
|
|
|
136
137
|
}
|
|
137
138
|
const note = document.createElement("footer");
|
|
138
139
|
note.className = "export-note";
|
|
139
|
-
|
|
140
|
+
const version = document.body.dataset.sidecarVersion;
|
|
141
|
+
note.textContent = `Exported from sidecar v${version} on ${utc(new Date().toISOString())}.`;
|
|
140
142
|
page.append(note);
|
|
141
143
|
|
|
142
144
|
const file = document.implementation.createHTMLDocument(document.title);
|
|
@@ -189,12 +191,26 @@ document.querySelector("[data-export]")?.addEventListener("click", (event) => {
|
|
|
189
191
|
|
|
190
192
|
// Small screens have no sidebar and no toggle (app.css), so the stored state applies to wide ones only.
|
|
191
193
|
// The state lives in a cookie the server reads, so the page arrives already in it: this script
|
|
192
|
-
// runs after the first paint, and applying the state here would
|
|
194
|
+
// runs after the first paint, and applying the state here would flash the sidebar open.
|
|
193
195
|
const shell = document.querySelector(".shell");
|
|
196
|
+
const SIDEBAR_COOKIE = "sidecar_ui_sidebar";
|
|
194
197
|
|
|
195
198
|
document.querySelector("[data-toggle-sidebar]")?.addEventListener("click", () => {
|
|
196
199
|
const collapsed = shell.classList.toggle("is-collapsed");
|
|
197
|
-
document.cookie =
|
|
200
|
+
document.cookie = `${SIDEBAR_COOKIE}=${collapsed ? "collapsed" : "open"}; Path=/; SameSite=Strict; Max-Age=31536000`;
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// A page restored from the back/forward cache keeps the state it was left in, though another page
|
|
204
|
+
// may have toggled the sidebar since.
|
|
205
|
+
addEventListener("pageshow", (event) => {
|
|
206
|
+
if (!event.persisted || !shell) return;
|
|
207
|
+
const prefix = `${SIDEBAR_COOKIE}=`;
|
|
208
|
+
const stored = document.cookie
|
|
209
|
+
.split(";")
|
|
210
|
+
.map((c) => c.trim())
|
|
211
|
+
.find((c) => c.startsWith(prefix))
|
|
212
|
+
?.slice(prefix.length);
|
|
213
|
+
shell.classList.toggle("is-collapsed", stored === "collapsed");
|
|
198
214
|
});
|
|
199
215
|
|
|
200
216
|
/* ---------------------------------------------------------------- case index */
|