@lysyi3m/sidecar 1.7.0 → 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.
|
@@ -183,8 +183,7 @@ export function sideList(cases, activeCase) {
|
|
|
183
183
|
const FILTERS = ["all", "open", "closed"];
|
|
184
184
|
export function indexPage(cases, query, chrome = { collapsed: false }) {
|
|
185
185
|
const filter = FILTERS.find((f) => f === query.state) ?? "all";
|
|
186
|
-
const content = html `<
|
|
187
|
-
<div class="toolbar">
|
|
186
|
+
const content = html `<div class="toolbar">
|
|
188
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>
|
|
189
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>
|
|
190
189
|
</div>
|
|
@@ -198,7 +197,8 @@ ${caseRows(cases)}
|
|
|
198
197
|
cases,
|
|
199
198
|
activeCase: null,
|
|
200
199
|
chrome,
|
|
201
|
-
|
|
200
|
+
// The breadcrumb is the index's only heading.
|
|
201
|
+
crumbs: html `<h1 class="here label">Cases</h1>`,
|
|
202
202
|
content,
|
|
203
203
|
});
|
|
204
204
|
}
|
|
@@ -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);
|
|
@@ -254,6 +253,7 @@ button {
|
|
|
254
253
|
}
|
|
255
254
|
|
|
256
255
|
& .here {
|
|
256
|
+
margin: 0;
|
|
257
257
|
color: var(--ink-2);
|
|
258
258
|
overflow: hidden;
|
|
259
259
|
text-overflow: ellipsis;
|
|
@@ -191,12 +191,26 @@ document.querySelector("[data-export]")?.addEventListener("click", (event) => {
|
|
|
191
191
|
|
|
192
192
|
// Small screens have no sidebar and no toggle (app.css), so the stored state applies to wide ones only.
|
|
193
193
|
// 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
|
|
194
|
+
// runs after the first paint, and applying the state here would flash the sidebar open.
|
|
195
195
|
const shell = document.querySelector(".shell");
|
|
196
|
+
const SIDEBAR_COOKIE = "sidecar_ui_sidebar";
|
|
196
197
|
|
|
197
198
|
document.querySelector("[data-toggle-sidebar]")?.addEventListener("click", () => {
|
|
198
199
|
const collapsed = shell.classList.toggle("is-collapsed");
|
|
199
|
-
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");
|
|
200
214
|
});
|
|
201
215
|
|
|
202
216
|
/* ---------------------------------------------------------------- case index */
|