@warlock.js/grimoire 5.55.0 → 5.57.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.
- package/CHANGELOG.md +21 -0
- package/esm/devtools/data.mjs +34 -3
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/index.d.mts +13 -2
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +9 -2
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +14 -10
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +66 -21
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/llms-full.txt +2 -0
- package/package.json +3 -3
- package/skills/use-the-grimoire/SKILL.md +2 -0
- package/ui/grimoire-view.js +1371 -354
- package/ui/grimoire.css +611 -45
package/ui/grimoire-view.js
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
* Keep the last line as it is: the static export swaps it out to inline this file.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/** The tabs: `[route, label]`. */
|
|
11
|
+
const TABS = [
|
|
12
|
+
["", "Overview"],
|
|
13
|
+
["features", "Features"],
|
|
12
14
|
["apps", "Apps"],
|
|
13
15
|
["tasks", "Tasks"],
|
|
14
16
|
["releases", "Releases"],
|
|
@@ -19,6 +21,11 @@ const NAV = [
|
|
|
19
21
|
const SVG_WIDTH = 720;
|
|
20
22
|
const SVG_HEIGHT = 440;
|
|
21
23
|
|
|
24
|
+
/** How long a view may take before the skeleton is shown instead of waiting for it (ms). */
|
|
25
|
+
const SKELETON_AFTER = 150;
|
|
26
|
+
|
|
27
|
+
const BUILD_HINT = "Run warlock grimoire build, then reload.";
|
|
28
|
+
|
|
22
29
|
/** Decode one hash segment; a malformed escape stays as written. */
|
|
23
30
|
function decodeSegment(segment) {
|
|
24
31
|
try {
|
|
@@ -33,6 +40,39 @@ function plain(field) {
|
|
|
33
40
|
return field !== null && typeof field === "object" && "value" in field ? field.value : field;
|
|
34
41
|
}
|
|
35
42
|
|
|
43
|
+
function plural(count, word) {
|
|
44
|
+
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Which tab a hash route belongs to; `null` when it belongs to none. */
|
|
48
|
+
function tabOf(route) {
|
|
49
|
+
const type = route.split("/")[0] ?? "";
|
|
50
|
+
|
|
51
|
+
switch (type) {
|
|
52
|
+
case "features":
|
|
53
|
+
case "feature":
|
|
54
|
+
case "flow":
|
|
55
|
+
return "features";
|
|
56
|
+
case "apps":
|
|
57
|
+
case "page":
|
|
58
|
+
return "apps";
|
|
59
|
+
case "tasks":
|
|
60
|
+
case "task":
|
|
61
|
+
return "tasks";
|
|
62
|
+
case "releases":
|
|
63
|
+
case "release":
|
|
64
|
+
return "releases";
|
|
65
|
+
case "check":
|
|
66
|
+
return "check";
|
|
67
|
+
case "modules":
|
|
68
|
+
case "file":
|
|
69
|
+
case "route":
|
|
70
|
+
return "modules";
|
|
71
|
+
default:
|
|
72
|
+
return "";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
36
76
|
/** The hash route (without `#grimoire/`) of a search hit or graph node id, or `null`. */
|
|
37
77
|
function targetOf(type, id) {
|
|
38
78
|
const encode = encodeURIComponent;
|
|
@@ -92,20 +132,353 @@ function shorten(text, max = 26) {
|
|
|
92
132
|
}
|
|
93
133
|
|
|
94
134
|
const NODE_COLOURS = {
|
|
95
|
-
center: "var(--
|
|
96
|
-
feature: "var(--
|
|
97
|
-
flow: "var(--
|
|
98
|
-
app: "var(--
|
|
99
|
-
block: "var(--
|
|
100
|
-
layout: "var(--muted)",
|
|
101
|
-
module: "var(--
|
|
102
|
-
file: "var(--muted)",
|
|
135
|
+
center: "var(--brand)",
|
|
136
|
+
feature: "var(--chart-2)",
|
|
137
|
+
flow: "var(--chart-1)",
|
|
138
|
+
app: "var(--chart-3)",
|
|
139
|
+
block: "var(--chart-4)",
|
|
140
|
+
layout: "var(--muted-foreground)",
|
|
141
|
+
module: "var(--brand)",
|
|
142
|
+
file: "var(--muted-foreground)",
|
|
103
143
|
};
|
|
104
144
|
|
|
145
|
+
// ── Building blocks ─────────────────────────────────────────────────────────
|
|
146
|
+
|
|
147
|
+
function link(ctx, text, target, attrs = {}) {
|
|
148
|
+
return ctx.el("a", { href: ctx.href(target), text, ...attrs });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The tone (`good`, `info`, `warn`, `bad`, or none) a status word is shown in. */
|
|
152
|
+
function toneOf(status) {
|
|
153
|
+
switch (status) {
|
|
154
|
+
case "shipped":
|
|
155
|
+
case "passing":
|
|
156
|
+
case "pass":
|
|
157
|
+
case "confirmed":
|
|
158
|
+
case "done":
|
|
159
|
+
case "fresh":
|
|
160
|
+
case "cached":
|
|
161
|
+
return "good";
|
|
162
|
+
case "building":
|
|
163
|
+
case "open":
|
|
164
|
+
return "info";
|
|
165
|
+
case "proposed":
|
|
166
|
+
case "inferred":
|
|
167
|
+
case "warning":
|
|
168
|
+
case "waiting":
|
|
169
|
+
case "stale":
|
|
170
|
+
case "missing":
|
|
171
|
+
case "untested":
|
|
172
|
+
return "warn";
|
|
173
|
+
case "failing":
|
|
174
|
+
case "fail":
|
|
175
|
+
case "error":
|
|
176
|
+
return "bad";
|
|
177
|
+
default:
|
|
178
|
+
return "";
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function pill(ctx, text, tone = "") {
|
|
183
|
+
return ctx.el("span", { class: tone ? `grimoire-pill is-${tone}` : "grimoire-pill", text });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function mono(ctx, text) {
|
|
187
|
+
return ctx.el("span", { class: "grimoire-mono", text });
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function muted(ctx, text) {
|
|
191
|
+
return ctx.el("span", { class: "grimoire-muted", text });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function list(ctx, items) {
|
|
195
|
+
return ctx.el(
|
|
196
|
+
"ul",
|
|
197
|
+
{ class: "grimoire-list" },
|
|
198
|
+
items.map((item) => ctx.el("li", {}, item)),
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** A table that scrolls inside its card instead of widening the page. */
|
|
203
|
+
function table(ctx, headings, rows) {
|
|
204
|
+
return ctx.el("div", { class: "grimoire-scroll" }, [
|
|
205
|
+
ctx.el("table", { class: "grimoire-table" }, [
|
|
206
|
+
ctx.el("thead", {}, [
|
|
207
|
+
ctx.el(
|
|
208
|
+
"tr",
|
|
209
|
+
{},
|
|
210
|
+
headings.map((heading) => ctx.el("th", { scope: "col", text: heading })),
|
|
211
|
+
),
|
|
212
|
+
]),
|
|
213
|
+
ctx.el(
|
|
214
|
+
"tbody",
|
|
215
|
+
{},
|
|
216
|
+
rows.map((row) =>
|
|
217
|
+
ctx.el(
|
|
218
|
+
"tr",
|
|
219
|
+
{},
|
|
220
|
+
row.map((cell) => ctx.el("td", {}, cell)),
|
|
221
|
+
),
|
|
222
|
+
),
|
|
223
|
+
),
|
|
224
|
+
]),
|
|
225
|
+
]);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** A card with a heading. */
|
|
229
|
+
function section(ctx, title, children = []) {
|
|
230
|
+
return ctx.el("section", { class: "grimoire-card" }, [
|
|
231
|
+
ctx.el("h3", { text: title }),
|
|
232
|
+
...children,
|
|
233
|
+
]);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Label and value pairs. */
|
|
237
|
+
function facts(ctx, rows) {
|
|
238
|
+
return ctx.el(
|
|
239
|
+
"dl",
|
|
240
|
+
{ class: "grimoire-facts" },
|
|
241
|
+
rows.flatMap(([label, value]) => [
|
|
242
|
+
ctx.el("dt", { text: label }),
|
|
243
|
+
ctx.el("dd", {}, value ?? muted(ctx, "none")),
|
|
244
|
+
]),
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** A trail of links back up the hierarchy; the last crumb is the current view. */
|
|
249
|
+
function crumbs(ctx, trail) {
|
|
250
|
+
return ctx.el("nav", { class: "grimoire-crumbs", "aria-label": "Breadcrumb" }, [
|
|
251
|
+
ctx.el(
|
|
252
|
+
"ol",
|
|
253
|
+
{},
|
|
254
|
+
trail.map(([label, target], index) =>
|
|
255
|
+
ctx.el("li", {}, [
|
|
256
|
+
index < trail.length - 1 && target !== undefined
|
|
257
|
+
? link(ctx, label, target)
|
|
258
|
+
: ctx.el("span", { "aria-current": "page", text: label }),
|
|
259
|
+
]),
|
|
260
|
+
),
|
|
261
|
+
),
|
|
262
|
+
]);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The title block of a detail view. */
|
|
266
|
+
function heading(ctx, title, extras = []) {
|
|
267
|
+
return ctx.el("header", { class: "grimoire-heading" }, [
|
|
268
|
+
ctx.el("h2", { text: title }),
|
|
269
|
+
extras.length ? ctx.el("div", { class: "grimoire-heading-meta" }, extras) : "",
|
|
270
|
+
]);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Items as compact chips; past `limit` the rest sits behind a "+N more" button. */
|
|
274
|
+
function chipList(ctx, items, make, limit = 8) {
|
|
275
|
+
if (!items.length) return muted(ctx, "none");
|
|
276
|
+
|
|
277
|
+
const nodes = items.map(make);
|
|
278
|
+
const holder = ctx.el("div", { class: "grimoire-chips" });
|
|
279
|
+
const more = ctx.el("button", { type: "button", class: "grimoire-more" });
|
|
280
|
+
let open = false;
|
|
281
|
+
|
|
282
|
+
const paint = () => {
|
|
283
|
+
const visible = open ? nodes : nodes.slice(0, limit);
|
|
284
|
+
|
|
285
|
+
more.textContent = open ? "Show fewer" : `+${nodes.length - limit} more`;
|
|
286
|
+
more.setAttribute("aria-expanded", String(open));
|
|
287
|
+
holder.replaceChildren(...visible, ...(nodes.length > limit ? [more] : []));
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
more.addEventListener("click", () => {
|
|
291
|
+
open = !open;
|
|
292
|
+
paint();
|
|
293
|
+
});
|
|
294
|
+
paint();
|
|
295
|
+
return holder;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function fileLink(ctx, file) {
|
|
299
|
+
return link(ctx, file, `file/${encodeURIComponent(file)}`, { class: "grimoire-chip" });
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function fileChips(ctx, files, limit = 8) {
|
|
303
|
+
return chipList(ctx, files, (file) => fileLink(ctx, file), limit);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** `<feature>/<flow>` as a link. */
|
|
307
|
+
function flowLink(ctx, ref) {
|
|
308
|
+
const target = targetOf("flow", ref);
|
|
309
|
+
return target === null ? ref : link(ctx, ref, target);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function routeLink(ctx, method, path) {
|
|
313
|
+
return link(
|
|
314
|
+
ctx,
|
|
315
|
+
`${method} ${path}`,
|
|
316
|
+
`route/${encodeURIComponent(method)}/${encodeURIComponent(path)}`,
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* A filterable, sortable listing: a text box, status buttons with counts, an
|
|
322
|
+
* optional sort menu and an "N of M" line. `render(shown)` returns the one
|
|
323
|
+
* node that fills the body each time the filters change.
|
|
324
|
+
*/
|
|
325
|
+
function listing(ctx, options) {
|
|
326
|
+
const { el } = ctx;
|
|
327
|
+
const { items, noun, render } = options;
|
|
328
|
+
const state = { text: "", status: "", sort: options.sorts?.[0]?.[0] ?? "" };
|
|
329
|
+
const body = el("div", { class: "grimoire-listing-body" });
|
|
330
|
+
const count = el("p", {
|
|
331
|
+
class: "grimoire-listing-count",
|
|
332
|
+
role: "status",
|
|
333
|
+
"aria-live": "polite",
|
|
334
|
+
});
|
|
335
|
+
const buttons = [];
|
|
336
|
+
const bar = el("div", { class: "grimoire-toolbar" });
|
|
337
|
+
|
|
338
|
+
bar.append(
|
|
339
|
+
el("input", {
|
|
340
|
+
type: "search",
|
|
341
|
+
class: "grimoire-filter-input",
|
|
342
|
+
placeholder: `Filter ${noun}`,
|
|
343
|
+
"aria-label": `Filter ${noun}`,
|
|
344
|
+
oninput: (event) => {
|
|
345
|
+
state.text = event.target.value;
|
|
346
|
+
paint();
|
|
347
|
+
},
|
|
348
|
+
}),
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
if (options.statusOf) {
|
|
352
|
+
const found = [...new Set(items.map(options.statusOf))];
|
|
353
|
+
const order = options.statusOrder ?? [];
|
|
354
|
+
const statuses = found.sort(
|
|
355
|
+
(left, right) =>
|
|
356
|
+
(order.indexOf(left) < 0 ? 99 : order.indexOf(left)) -
|
|
357
|
+
(order.indexOf(right) < 0 ? 99 : order.indexOf(right)) || left.localeCompare(right),
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
if (statuses.length > 1) {
|
|
361
|
+
const group = el("div", { class: "grimoire-filters", role: "group", "aria-label": "Status" });
|
|
362
|
+
|
|
363
|
+
for (const status of ["", ...statuses]) {
|
|
364
|
+
const total = status
|
|
365
|
+
? items.filter((item) => options.statusOf(item) === status).length
|
|
366
|
+
: items.length;
|
|
367
|
+
const button = el("button", {
|
|
368
|
+
type: "button",
|
|
369
|
+
class: "grimoire-filter",
|
|
370
|
+
"aria-pressed": "false",
|
|
371
|
+
text: `${status || "all"} ${total}`,
|
|
372
|
+
onclick: () => {
|
|
373
|
+
state.status = status;
|
|
374
|
+
paint();
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
buttons.push([button, status]);
|
|
379
|
+
group.append(button);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
bar.append(group);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (options.sorts && options.sorts.length > 1) {
|
|
387
|
+
bar.append(
|
|
388
|
+
el(
|
|
389
|
+
"select",
|
|
390
|
+
{
|
|
391
|
+
class: "grimoire-sort",
|
|
392
|
+
"aria-label": "Sort",
|
|
393
|
+
onchange: (event) => {
|
|
394
|
+
state.sort = event.target.value;
|
|
395
|
+
paint();
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
options.sorts.map(([key, label]) => el("option", { value: key, text: `Sort: ${label}` })),
|
|
399
|
+
),
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function paint() {
|
|
404
|
+
const query = state.text.trim().toLowerCase();
|
|
405
|
+
let shown = items.filter(
|
|
406
|
+
(item) =>
|
|
407
|
+
(!state.status || options.statusOf(item) === state.status) &&
|
|
408
|
+
(!query || options.textOf(item).toLowerCase().includes(query)),
|
|
409
|
+
);
|
|
410
|
+
const sort = options.sorts?.find(([key]) => key === state.sort);
|
|
411
|
+
|
|
412
|
+
if (sort) shown = [...shown].sort(sort[2]);
|
|
413
|
+
|
|
414
|
+
for (const [button, status] of buttons) {
|
|
415
|
+
button.setAttribute("aria-pressed", String(status === state.status));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
count.textContent = `${shown.length} of ${items.length} ${noun}`;
|
|
419
|
+
body.replaceChildren(
|
|
420
|
+
shown.length
|
|
421
|
+
? render(shown, items)
|
|
422
|
+
: ctx.empty(`No ${noun} match these filters. Clear the filter to see all ${items.length}.`),
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
paint();
|
|
427
|
+
return el("div", { class: "grimoire-listing" }, [bar, count, body]);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** A list of findings: severity, code, message, what to do, and where. */
|
|
431
|
+
function findingList(ctx, findings) {
|
|
432
|
+
return ctx.el(
|
|
433
|
+
"ul",
|
|
434
|
+
{ class: "grimoire-findings" },
|
|
435
|
+
findings.map((finding) => {
|
|
436
|
+
const place = finding.at ? `${finding.at.file}:${finding.at.line}` : null;
|
|
437
|
+
const file = finding.subject.file;
|
|
438
|
+
|
|
439
|
+
return ctx.el("li", { class: "grimoire-finding" }, [
|
|
440
|
+
ctx.el("div", { class: "grimoire-finding-head" }, [
|
|
441
|
+
pill(ctx, finding.severity, toneOf(finding.severity)),
|
|
442
|
+
finding.expected ? pill(ctx, "expected") : "",
|
|
443
|
+
mono(ctx, finding.code),
|
|
444
|
+
]),
|
|
445
|
+
ctx.el("p", { class: "grimoire-finding-message", text: finding.message }),
|
|
446
|
+
finding.hint ? ctx.el("p", { class: "grimoire-muted", text: finding.hint }) : "",
|
|
447
|
+
place || file
|
|
448
|
+
? ctx.el("div", { class: "grimoire-chips" }, [
|
|
449
|
+
place ? mono(ctx, place) : "",
|
|
450
|
+
file && file !== finding.at?.file ? fileLink(ctx, file) : "",
|
|
451
|
+
])
|
|
452
|
+
: "",
|
|
453
|
+
]);
|
|
454
|
+
}),
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function changesView(ctx, changes) {
|
|
459
|
+
if (!changes.length) return ctx.empty("No changelog entries.");
|
|
460
|
+
return list(
|
|
461
|
+
ctx,
|
|
462
|
+
changes.map((change) => [
|
|
463
|
+
pill(ctx, change.word),
|
|
464
|
+
` ${plain(change.version)} `,
|
|
465
|
+
change.flow ? [flowLink(ctx, `${change.feature}/${change.flow}`), " "] : "",
|
|
466
|
+
change.text,
|
|
467
|
+
change.release
|
|
468
|
+
? ` (release ${change.release}${change.date ? `, ${change.date}` : ""})`
|
|
469
|
+
: " (not released)",
|
|
470
|
+
]),
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// ── Graphs ──────────────────────────────────────────────────────────────────
|
|
475
|
+
|
|
105
476
|
/** Plain SVG for a graph answer: the centre node in the middle, the others on one or two rings. */
|
|
106
477
|
function graphView(ctx, graph, title) {
|
|
107
478
|
const { el, svg, empty, href } = ctx;
|
|
108
|
-
const card = el("section", { class: "card grimoire-graph" }, [
|
|
479
|
+
const card = el("section", { class: "grimoire-card grimoire-graph" }, [
|
|
480
|
+
el("h3", { text: title }),
|
|
481
|
+
]);
|
|
109
482
|
|
|
110
483
|
if (!graph.nodes.length) {
|
|
111
484
|
card.append(empty("Nothing to draw."));
|
|
@@ -152,7 +525,7 @@ function graphView(ctx, graph, title) {
|
|
|
152
525
|
y1: from[1].toFixed(1),
|
|
153
526
|
x2: to[0].toFixed(1),
|
|
154
527
|
y2: to[1].toFixed(1),
|
|
155
|
-
stroke: "var(--
|
|
528
|
+
stroke: "var(--input)",
|
|
156
529
|
"stroke-width": edge.weight ? String(Math.min(1 + Math.log2(edge.weight), 5)) : "1.2",
|
|
157
530
|
}),
|
|
158
531
|
);
|
|
@@ -166,13 +539,13 @@ function graphView(ctx, graph, title) {
|
|
|
166
539
|
cx: at[0].toFixed(1),
|
|
167
540
|
cy: at[1].toFixed(1),
|
|
168
541
|
r: node.type === "center" ? "9" : "6",
|
|
169
|
-
fill: NODE_COLOURS[node.type] ?? "var(--muted)",
|
|
542
|
+
fill: NODE_COLOURS[node.type] ?? "var(--muted-foreground)",
|
|
170
543
|
});
|
|
171
544
|
const label = svg("text", {
|
|
172
545
|
x: at[0].toFixed(1),
|
|
173
546
|
y: (at[1] + (node.type === "center" ? 24 : 18)).toFixed(1),
|
|
174
547
|
"text-anchor": "middle",
|
|
175
|
-
fill: "var(--
|
|
548
|
+
fill: "var(--foreground)",
|
|
176
549
|
"font-size": "11",
|
|
177
550
|
text: shorten(node.label),
|
|
178
551
|
});
|
|
@@ -184,145 +557,253 @@ function graphView(ctx, graph, title) {
|
|
|
184
557
|
return card;
|
|
185
558
|
}
|
|
186
559
|
|
|
187
|
-
|
|
188
|
-
function section(ctx, title, children = []) {
|
|
189
|
-
return ctx.el("section", { class: "card detail" }, [ctx.el("h3", { text: title }), ...children]);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function link(ctx, text, target, attrs = {}) {
|
|
193
|
-
return ctx.el("a", { href: ctx.href(target), text, ...attrs });
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function badge(ctx, text, tone = "") {
|
|
197
|
-
return ctx.el("span", { class: tone ? `badge ${tone}` : "badge", text });
|
|
198
|
-
}
|
|
560
|
+
// ── Views ───────────────────────────────────────────────────────────────────
|
|
199
561
|
|
|
200
|
-
|
|
562
|
+
/** One overview card: a number, what it counts, and where it leads. */
|
|
563
|
+
function stat(ctx, { label, value, sub, target, tone = "" }) {
|
|
201
564
|
return ctx.el(
|
|
202
|
-
"
|
|
203
|
-
{ class: "grimoire-
|
|
204
|
-
|
|
565
|
+
"a",
|
|
566
|
+
{ class: tone ? `grimoire-stat is-${tone}` : "grimoire-stat", href: ctx.href(target) },
|
|
567
|
+
[
|
|
568
|
+
ctx.el("span", { class: "grimoire-stat-label", text: label }),
|
|
569
|
+
ctx.el("span", { class: "grimoire-stat-value", text: String(value) }),
|
|
570
|
+
ctx.el("span", { class: "grimoire-stat-sub", text: sub }),
|
|
571
|
+
],
|
|
205
572
|
);
|
|
206
573
|
}
|
|
207
574
|
|
|
208
|
-
|
|
209
|
-
return ctx.el("table", { class: "grimoire-table" }, [
|
|
210
|
-
ctx.el("thead", {}, [
|
|
211
|
-
ctx.el(
|
|
212
|
-
"tr",
|
|
213
|
-
{},
|
|
214
|
-
headings.map((heading) => ctx.el("th", { text: heading })),
|
|
215
|
-
),
|
|
216
|
-
]),
|
|
217
|
-
ctx.el(
|
|
218
|
-
"tbody",
|
|
219
|
-
{},
|
|
220
|
-
rows.map((row) =>
|
|
221
|
-
ctx.el(
|
|
222
|
-
"tr",
|
|
223
|
-
{},
|
|
224
|
-
row.map((cell) => ctx.el("td", {}, cell)),
|
|
225
|
-
),
|
|
226
|
-
),
|
|
227
|
-
),
|
|
228
|
-
]);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function statusTone(status) {
|
|
232
|
-
if (status === "shipped" || status === "passing" || status === "pass") return "good";
|
|
233
|
-
if (status === "retired" || status === "failing" || status === "fail" || status === "error")
|
|
234
|
-
return "bad";
|
|
235
|
-
return "";
|
|
236
|
-
}
|
|
575
|
+
const STATUS_ORDER = ["shipped", "building", "proposed", "retired"];
|
|
237
576
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
function fileLink(ctx, file) {
|
|
245
|
-
return link(ctx, file, `file/${encodeURIComponent(file)}`);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function fileList(ctx, files, limit = 12) {
|
|
249
|
-
if (!files.length) return ctx.el("span", { class: "muted", text: "none" });
|
|
250
|
-
const shown = files.slice(0, limit);
|
|
251
|
-
const items = shown.map((file) => [fileLink(ctx, file)]);
|
|
252
|
-
if (files.length > limit)
|
|
253
|
-
items.push([ctx.el("span", { class: "muted", text: `+${files.length - limit} more` })]);
|
|
254
|
-
return list(ctx, items);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// ── Views ───────────────────────────────────────────────────────────────────
|
|
258
|
-
|
|
259
|
-
async function homeView(ctx) {
|
|
260
|
-
const data = await ctx.api("summary");
|
|
577
|
+
async function overviewView(ctx, summaryRequest) {
|
|
578
|
+
const [data, check, releases] = await Promise.all([
|
|
579
|
+
summaryRequest,
|
|
580
|
+
ctx.api("check").catch(() => null),
|
|
581
|
+
ctx.api("releases").catch(() => null),
|
|
582
|
+
]);
|
|
261
583
|
const { el } = ctx;
|
|
584
|
+
const features = data.features.features;
|
|
585
|
+
const byStatus = new Map();
|
|
586
|
+
|
|
587
|
+
for (const item of features) byStatus.set(item.status, (byStatus.get(item.status) ?? 0) + 1);
|
|
588
|
+
|
|
589
|
+
const flows = features.reduce((total, item) => total + item.flows.length, 0);
|
|
590
|
+
const statusLine = [...byStatus.entries()]
|
|
591
|
+
.sort(([a], [b]) => STATUS_ORDER.indexOf(a) - STATUS_ORDER.indexOf(b))
|
|
592
|
+
.map(([status, total]) => `${total} ${status}`)
|
|
593
|
+
.join(", ");
|
|
594
|
+
const waiting = data.tasks.waiting.length;
|
|
595
|
+
const open = data.tasks.open.length - waiting;
|
|
596
|
+
const stale = data.routes === "stale" || data.routes === "missing";
|
|
262
597
|
const out = el("div", { class: "grimoire-view" });
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
"
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
598
|
+
|
|
599
|
+
out.append(
|
|
600
|
+
el("div", { class: "grimoire-stats" }, [
|
|
601
|
+
stat(ctx, {
|
|
602
|
+
label: "Features",
|
|
603
|
+
value: features.length,
|
|
604
|
+
sub: features.length ? `${statusLine}; ${plural(flows, "flow")}` : "none written yet",
|
|
605
|
+
target: "features",
|
|
606
|
+
}),
|
|
607
|
+
stat(ctx, {
|
|
608
|
+
label: "Apps",
|
|
609
|
+
value: data.apps ? data.apps.apps : "-",
|
|
610
|
+
sub: data.apps
|
|
611
|
+
? `${plural(data.apps.pages, "page")}, ${plural(data.apps.screens, "screen")}`
|
|
612
|
+
: "not counted",
|
|
613
|
+
target: "apps",
|
|
614
|
+
}),
|
|
615
|
+
stat(ctx, {
|
|
616
|
+
label: "Tasks",
|
|
617
|
+
value: open,
|
|
618
|
+
sub: `${open} open, ${waiting} waiting, ${data.tasks.done.length} done`,
|
|
619
|
+
target: "tasks",
|
|
620
|
+
tone: waiting ? "warn" : "",
|
|
621
|
+
}),
|
|
622
|
+
stat(ctx, {
|
|
623
|
+
label: "Check errors",
|
|
624
|
+
value: data.counts.errors,
|
|
625
|
+
sub: `${plural(data.counts.errors, "error")}, ${plural(data.counts.warnings, "warning")}, ${data.counts.expected} expected`,
|
|
626
|
+
target: "check",
|
|
627
|
+
tone: data.counts.errors ? "bad" : data.counts.warnings ? "warn" : "good",
|
|
628
|
+
}),
|
|
629
|
+
stat(ctx, {
|
|
630
|
+
label: "Book",
|
|
631
|
+
value: data.book.files,
|
|
632
|
+
sub: `files in ${plural(data.book.modules, "module")}`,
|
|
633
|
+
target: "modules",
|
|
634
|
+
}),
|
|
635
|
+
stat(ctx, {
|
|
636
|
+
label: "Route facts",
|
|
637
|
+
value: data.routes,
|
|
638
|
+
sub: stale ? "need a refresh" : "up to date",
|
|
639
|
+
target: "check",
|
|
640
|
+
tone: toneOf(data.routes),
|
|
641
|
+
}),
|
|
282
642
|
]),
|
|
283
|
-
|
|
284
|
-
out.append(cards);
|
|
643
|
+
);
|
|
285
644
|
|
|
286
|
-
if (
|
|
645
|
+
if (stale) {
|
|
287
646
|
out.append(
|
|
288
647
|
el("p", {
|
|
289
|
-
class: "
|
|
648
|
+
class: "grimoire-note",
|
|
290
649
|
text: "The route facts are old or missing. Run warlock grimoire build to refresh them.",
|
|
291
650
|
}),
|
|
292
651
|
);
|
|
293
652
|
}
|
|
294
653
|
|
|
295
|
-
const features = data.features.features;
|
|
296
|
-
|
|
297
654
|
if (!features.length) {
|
|
298
655
|
out.append(
|
|
299
656
|
ctx.empty(
|
|
300
657
|
data.book.files
|
|
301
|
-
? `No features are written yet. The book
|
|
658
|
+
? `No features are written yet. The book lists ${data.book.files} files; search it above, or open the module graph. Ask your agent to write the features (skill use-the-grimoire).`
|
|
302
659
|
: "The book is empty. Run warlock grimoire build.",
|
|
303
660
|
),
|
|
304
661
|
);
|
|
305
|
-
return out;
|
|
306
662
|
}
|
|
307
663
|
|
|
664
|
+
const problems = (check?.findings ?? []).filter((finding) => !finding.expected).slice(0, 5);
|
|
665
|
+
const recent = [...(releases?.releases ?? [])]
|
|
666
|
+
.sort((left, right) => right.date.localeCompare(left.date))
|
|
667
|
+
.slice(0, 5);
|
|
668
|
+
|
|
308
669
|
out.append(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
670
|
+
el("div", { class: "grimoire-split" }, [
|
|
671
|
+
section(ctx, "Top problems", [
|
|
672
|
+
check
|
|
673
|
+
? problems.length
|
|
674
|
+
? findingList(ctx, problems)
|
|
675
|
+
: el("p", {}, [pill(ctx, "clean", "good"), " Nothing to fix."])
|
|
676
|
+
: ctx.empty("The check report could not be loaded."),
|
|
677
|
+
check ? el("p", {}, [link(ctx, "Open the check report", "check")]) : "",
|
|
678
|
+
]),
|
|
679
|
+
section(ctx, "Recent releases", [
|
|
680
|
+
recent.length
|
|
681
|
+
? list(
|
|
682
|
+
ctx,
|
|
683
|
+
recent.map((item) => [
|
|
684
|
+
link(ctx, item.release, `release/${encodeURIComponent(item.release)}`),
|
|
685
|
+
" ",
|
|
686
|
+
muted(ctx, item.date),
|
|
687
|
+
]),
|
|
688
|
+
)
|
|
689
|
+
: ctx.empty(
|
|
690
|
+
releases ? "No releases are written yet." : "The releases could not be loaded.",
|
|
691
|
+
),
|
|
692
|
+
recent.length ? el("p", {}, [link(ctx, "All releases", "releases")]) : "",
|
|
693
|
+
]),
|
|
321
694
|
]),
|
|
322
695
|
);
|
|
696
|
+
|
|
697
|
+
if (features.length) {
|
|
698
|
+
const latest = [...features]
|
|
699
|
+
.sort((left, right) => right.updated.localeCompare(left.updated))
|
|
700
|
+
.slice(0, 6);
|
|
701
|
+
|
|
702
|
+
out.append(
|
|
703
|
+
section(ctx, "Recently updated features", [
|
|
704
|
+
list(
|
|
705
|
+
ctx,
|
|
706
|
+
latest.map((item) => [
|
|
707
|
+
link(ctx, item.id, `feature/${encodeURIComponent(item.id)}`),
|
|
708
|
+
" ",
|
|
709
|
+
pill(ctx, item.status, toneOf(item.status)),
|
|
710
|
+
" ",
|
|
711
|
+
muted(ctx, `${item.title}, updated ${item.updated}`),
|
|
712
|
+
]),
|
|
713
|
+
),
|
|
714
|
+
el("p", {}, [link(ctx, `All ${features.length} features`, "features")]),
|
|
715
|
+
]),
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
|
|
323
719
|
return out;
|
|
324
720
|
}
|
|
325
721
|
|
|
722
|
+
const FEATURE_SORTS = [
|
|
723
|
+
["id", "name", (a, b) => a.id.localeCompare(b.id)],
|
|
724
|
+
[
|
|
725
|
+
"status",
|
|
726
|
+
"status",
|
|
727
|
+
(a, b) =>
|
|
728
|
+
STATUS_ORDER.indexOf(a.status) - STATUS_ORDER.indexOf(b.status) || a.id.localeCompare(b.id),
|
|
729
|
+
],
|
|
730
|
+
["flows", "most flows", (a, b) => b.flows.length - a.flows.length || a.id.localeCompare(b.id)],
|
|
731
|
+
[
|
|
732
|
+
"updated",
|
|
733
|
+
"recently updated",
|
|
734
|
+
(a, b) => b.updated.localeCompare(a.updated) || a.id.localeCompare(b.id),
|
|
735
|
+
],
|
|
736
|
+
];
|
|
737
|
+
|
|
738
|
+
async function featuresView(ctx) {
|
|
739
|
+
const data = await ctx.api("features");
|
|
740
|
+
const { el } = ctx;
|
|
741
|
+
const items = data.features;
|
|
742
|
+
|
|
743
|
+
if (!items.length) {
|
|
744
|
+
return ctx.empty(
|
|
745
|
+
"No features are written yet. Ask your agent to write them (skill use-the-grimoire), then run warlock grimoire build.",
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
return el("div", { class: "grimoire-view" }, [
|
|
750
|
+
heading(ctx, "Features"),
|
|
751
|
+
listing(ctx, {
|
|
752
|
+
items,
|
|
753
|
+
noun: "features",
|
|
754
|
+
placeholder: "Filter features",
|
|
755
|
+
textOf: (item) =>
|
|
756
|
+
[item.id, item.title, item.summary ?? "", ...item.flows.map((flow) => flow.id)].join(" "),
|
|
757
|
+
statusOf: (item) => item.status,
|
|
758
|
+
statusOrder: STATUS_ORDER,
|
|
759
|
+
sorts: FEATURE_SORTS,
|
|
760
|
+
render: (shown) =>
|
|
761
|
+
el(
|
|
762
|
+
"div",
|
|
763
|
+
{ class: "grimoire-feature-grid" },
|
|
764
|
+
shown.map((item) => {
|
|
765
|
+
const tone = toneOf(item.status);
|
|
766
|
+
|
|
767
|
+
return el(
|
|
768
|
+
"article",
|
|
769
|
+
{ class: tone ? `grimoire-feature is-${tone}` : "grimoire-feature" },
|
|
770
|
+
[
|
|
771
|
+
el("header", {}, [
|
|
772
|
+
el("h3", {}, [
|
|
773
|
+
link(ctx, item.title || item.id, `feature/${encodeURIComponent(item.id)}`),
|
|
774
|
+
]),
|
|
775
|
+
pill(ctx, item.status, tone),
|
|
776
|
+
]),
|
|
777
|
+
el("p", { class: "grimoire-feature-id" }, [
|
|
778
|
+
mono(ctx, item.id),
|
|
779
|
+
` version ${item.version}, updated ${item.updated}`,
|
|
780
|
+
]),
|
|
781
|
+
item.summary ? el("p", { class: "grimoire-clamp", text: item.summary }) : "",
|
|
782
|
+
el("div", { class: "grimoire-feature-flows" }, [
|
|
783
|
+
muted(ctx, plural(item.flows.length, "flow")),
|
|
784
|
+
item.flows.length
|
|
785
|
+
? chipList(
|
|
786
|
+
ctx,
|
|
787
|
+
item.flows,
|
|
788
|
+
(flow) =>
|
|
789
|
+
link(
|
|
790
|
+
ctx,
|
|
791
|
+
flow.id,
|
|
792
|
+
`flow/${encodeURIComponent(item.id)}/${encodeURIComponent(flow.id)}`,
|
|
793
|
+
{ class: "grimoire-chip", title: flow.heading ?? flow.id },
|
|
794
|
+
),
|
|
795
|
+
6,
|
|
796
|
+
)
|
|
797
|
+
: "",
|
|
798
|
+
]),
|
|
799
|
+
],
|
|
800
|
+
);
|
|
801
|
+
}),
|
|
802
|
+
),
|
|
803
|
+
}),
|
|
804
|
+
]);
|
|
805
|
+
}
|
|
806
|
+
|
|
326
807
|
async function featureView(ctx, id) {
|
|
327
808
|
const [data, graph] = await Promise.all([
|
|
328
809
|
ctx.api(`features/${encodeURIComponent(id)}`),
|
|
@@ -330,15 +811,19 @@ async function featureView(ctx, id) {
|
|
|
330
811
|
]);
|
|
331
812
|
const { el } = ctx;
|
|
332
813
|
const readme = data.readme;
|
|
814
|
+
const status = plain(readme.status);
|
|
333
815
|
const out = el("div", { class: "grimoire-view" }, [
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
816
|
+
crumbs(ctx, [["Features", "features"], [String(plain(readme.id))]]),
|
|
817
|
+
heading(ctx, plain(readme.title), [
|
|
818
|
+
mono(ctx, plain(readme.id)),
|
|
819
|
+
pill(ctx, status, toneOf(status)),
|
|
820
|
+
pill(ctx, `version ${plain(readme.version)}`),
|
|
821
|
+
readme.origin ? pill(ctx, plain(readme.origin), toneOf(plain(readme.origin))) : "",
|
|
822
|
+
muted(ctx, `updated ${plain(readme.updated)}`),
|
|
338
823
|
]),
|
|
339
824
|
]);
|
|
340
825
|
|
|
341
|
-
if (readme.summary) out.append(el("p", { text: readme.summary }));
|
|
826
|
+
if (readme.summary) out.append(el("p", { class: "grimoire-lede", text: readme.summary }));
|
|
342
827
|
|
|
343
828
|
out.append(
|
|
344
829
|
section(ctx, "Flows", [
|
|
@@ -354,7 +839,7 @@ async function featureView(ctx, id) {
|
|
|
354
839
|
`flow/${encodeURIComponent(plain(readme.id))}/${encodeURIComponent(flow.id)}`,
|
|
355
840
|
),
|
|
356
841
|
],
|
|
357
|
-
[
|
|
842
|
+
[pill(ctx, flow.status, toneOf(flow.status))],
|
|
358
843
|
[flow.since],
|
|
359
844
|
[flow.heading ?? ""],
|
|
360
845
|
]),
|
|
@@ -366,24 +851,23 @@ async function featureView(ctx, id) {
|
|
|
366
851
|
const map = data.bookmap;
|
|
367
852
|
out.append(
|
|
368
853
|
section(ctx, "Code", [
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
854
|
+
facts(ctx, [
|
|
855
|
+
["Own files", String(map.own.length)],
|
|
856
|
+
["Borrowed", String(map.borrowed.length)],
|
|
857
|
+
["Routes", String(map.routes.length)],
|
|
858
|
+
["Not reached by a flow", String(map.unreached.length)],
|
|
859
|
+
]),
|
|
372
860
|
el("h4", { text: "Routes" }),
|
|
373
861
|
map.routes.length
|
|
374
862
|
? list(
|
|
375
863
|
ctx,
|
|
376
864
|
map.routes.map((item) => [
|
|
377
|
-
|
|
378
|
-
ctx,
|
|
379
|
-
`${item.method} ${item.path}`,
|
|
380
|
-
`route/${encodeURIComponent(item.method)}/${encodeURIComponent(item.path)}`,
|
|
381
|
-
),
|
|
865
|
+
routeLink(ctx, item.method, item.path),
|
|
382
866
|
" in ",
|
|
383
867
|
fileLink(ctx, item.file),
|
|
384
868
|
]),
|
|
385
869
|
)
|
|
386
|
-
:
|
|
870
|
+
: muted(ctx, "none"),
|
|
387
871
|
el("h4", { text: "Pages and screens" }),
|
|
388
872
|
Object.keys(map.pages).length
|
|
389
873
|
? list(
|
|
@@ -398,9 +882,11 @@ async function featureView(ctx, id) {
|
|
|
398
882
|
]),
|
|
399
883
|
),
|
|
400
884
|
)
|
|
401
|
-
:
|
|
885
|
+
: muted(ctx, "none"),
|
|
886
|
+
el("h4", { text: "Own files" }),
|
|
887
|
+
fileChips(ctx, map.own, 12),
|
|
402
888
|
el("h4", { text: "Files no flow reaches" }),
|
|
403
|
-
|
|
889
|
+
fileChips(ctx, map.unreached, 12),
|
|
404
890
|
]),
|
|
405
891
|
);
|
|
406
892
|
|
|
@@ -412,7 +898,7 @@ async function featureView(ctx, id) {
|
|
|
412
898
|
data.tasks.map((task) => [
|
|
413
899
|
link(ctx, task.id, `task/${encodeURIComponent(task.id)}`),
|
|
414
900
|
` ${task.title} `,
|
|
415
|
-
|
|
901
|
+
pill(ctx, task.status, toneOf(task.status)),
|
|
416
902
|
]),
|
|
417
903
|
),
|
|
418
904
|
]),
|
|
@@ -421,57 +907,27 @@ async function featureView(ctx, id) {
|
|
|
421
907
|
|
|
422
908
|
out.append(section(ctx, "Recent changes", [changesView(ctx, data.changes)]));
|
|
423
909
|
|
|
424
|
-
if (data.findings.length)
|
|
425
|
-
out.append(section(ctx, "Findings", [findingsView(ctx, data.findings)]));
|
|
910
|
+
if (data.findings.length) out.append(section(ctx, "Findings", [findingList(ctx, data.findings)]));
|
|
426
911
|
if (graph) out.append(graphView(ctx, graph, "The feature and its neighbours"));
|
|
427
912
|
return out;
|
|
428
913
|
}
|
|
429
914
|
|
|
430
|
-
function changesView(ctx, changes) {
|
|
431
|
-
if (!changes.length) return ctx.empty("No changelog entries.");
|
|
432
|
-
return list(
|
|
433
|
-
ctx,
|
|
434
|
-
changes.map((change) => [
|
|
435
|
-
badge(ctx, change.word),
|
|
436
|
-
` ${plain(change.version)} `,
|
|
437
|
-
change.flow ? [flowLink(ctx, `${change.feature}/${change.flow}`), " "] : "",
|
|
438
|
-
change.text,
|
|
439
|
-
change.release
|
|
440
|
-
? ` (release ${change.release}${change.date ? `, ${change.date}` : ""})`
|
|
441
|
-
: " (not released)",
|
|
442
|
-
]),
|
|
443
|
-
);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
function findingsView(ctx, findings) {
|
|
447
|
-
return table(
|
|
448
|
-
ctx,
|
|
449
|
-
["Code", "Severity", "Message", "Where"],
|
|
450
|
-
findings.map((finding) => [
|
|
451
|
-
[finding.code],
|
|
452
|
-
[
|
|
453
|
-
badge(
|
|
454
|
-
ctx,
|
|
455
|
-
finding.expected ? `${finding.severity} (expected)` : finding.severity,
|
|
456
|
-
finding.severity === "error" && !finding.expected ? "bad" : "",
|
|
457
|
-
),
|
|
458
|
-
],
|
|
459
|
-
[finding.message],
|
|
460
|
-
[finding.at ? `${finding.at.file}:${finding.at.line}` : (finding.subject.file ?? "")],
|
|
461
|
-
]),
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
915
|
async function flowView(ctx, feature, flowId) {
|
|
466
916
|
const data = await ctx.api(`flows/${encodeURIComponent(feature)}/${encodeURIComponent(flowId)}`);
|
|
467
917
|
const { el } = ctx;
|
|
468
918
|
const flow = data.flow;
|
|
469
919
|
const map = data.bookmap;
|
|
920
|
+
const status = plain(flow.status);
|
|
470
921
|
const out = el("div", { class: "grimoire-view" }, [
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
922
|
+
crumbs(ctx, [
|
|
923
|
+
["Features", "features"],
|
|
924
|
+
[feature, `feature/${encodeURIComponent(feature)}`],
|
|
925
|
+
[`${plain(flow.heading) ?? plain(flow.id)}`],
|
|
926
|
+
]),
|
|
927
|
+
heading(ctx, plain(flow.heading) ?? plain(flow.id), [
|
|
928
|
+
mono(ctx, `${feature}/${flowId}`),
|
|
929
|
+
pill(ctx, status, toneOf(status)),
|
|
930
|
+
muted(ctx, `since ${plain(flow.since)}, for ${plain(flow.who)}`),
|
|
475
931
|
link(ctx, `Back to ${feature}`, `feature/${encodeURIComponent(feature)}`),
|
|
476
932
|
]),
|
|
477
933
|
]);
|
|
@@ -487,15 +943,19 @@ async function flowView(ctx, feature, flowId) {
|
|
|
487
943
|
[step.type],
|
|
488
944
|
[
|
|
489
945
|
step.type === "route" && step.target.includes(" ")
|
|
490
|
-
?
|
|
946
|
+
? routeLink(
|
|
491
947
|
ctx,
|
|
492
|
-
step.target,
|
|
493
|
-
|
|
948
|
+
step.target.split(" ")[0],
|
|
949
|
+
step.target.slice(step.target.indexOf(" ") + 1),
|
|
494
950
|
)
|
|
495
951
|
: step.target,
|
|
496
952
|
],
|
|
497
|
-
[
|
|
498
|
-
|
|
953
|
+
[
|
|
954
|
+
step.found === null
|
|
955
|
+
? ""
|
|
956
|
+
: pill(ctx, step.found ? "yes" : "no", step.found ? "good" : "bad"),
|
|
957
|
+
],
|
|
958
|
+
[step.files.length ? fileChips(ctx, step.files, 6) : ""],
|
|
499
959
|
]),
|
|
500
960
|
)
|
|
501
961
|
: ctx.empty("This flow has no steps."),
|
|
@@ -509,10 +969,10 @@ async function flowView(ctx, feature, flowId) {
|
|
|
509
969
|
ctx,
|
|
510
970
|
["Id", "App", "Criterion", "Result", "Tests"],
|
|
511
971
|
map.criteria.map((criterion) => [
|
|
512
|
-
[criterion.id],
|
|
972
|
+
[mono(ctx, criterion.id)],
|
|
513
973
|
[criterion.app ?? "all"],
|
|
514
974
|
[criterion.text],
|
|
515
|
-
[
|
|
975
|
+
[pill(ctx, criterion.status, toneOf(criterion.status))],
|
|
516
976
|
[
|
|
517
977
|
criterion.tests.length
|
|
518
978
|
? list(
|
|
@@ -522,14 +982,14 @@ async function flowView(ctx, feature, flowId) {
|
|
|
522
982
|
`:${test.line} `,
|
|
523
983
|
test.name ?? "",
|
|
524
984
|
" ",
|
|
525
|
-
|
|
985
|
+
pill(
|
|
526
986
|
ctx,
|
|
527
987
|
test.stale ? `${test.result}, stale` : test.result,
|
|
528
|
-
|
|
988
|
+
test.stale ? "warn" : toneOf(test.result),
|
|
529
989
|
),
|
|
530
990
|
]),
|
|
531
991
|
)
|
|
532
|
-
:
|
|
992
|
+
: muted(ctx, "no test"),
|
|
533
993
|
],
|
|
534
994
|
]),
|
|
535
995
|
)
|
|
@@ -584,8 +1044,7 @@ async function flowView(ctx, feature, flowId) {
|
|
|
584
1044
|
}
|
|
585
1045
|
|
|
586
1046
|
out.append(section(ctx, "History", [changesView(ctx, data.history)]));
|
|
587
|
-
if (data.findings.length)
|
|
588
|
-
out.append(section(ctx, "Findings", [findingsView(ctx, data.findings)]));
|
|
1047
|
+
if (data.findings.length) out.append(section(ctx, "Findings", [findingList(ctx, data.findings)]));
|
|
589
1048
|
return out;
|
|
590
1049
|
}
|
|
591
1050
|
|
|
@@ -599,13 +1058,20 @@ async function pageView(ctx, app, key) {
|
|
|
599
1058
|
]);
|
|
600
1059
|
const { el } = ctx;
|
|
601
1060
|
const page = data.page;
|
|
1061
|
+
const title = plain(page.heading) ?? page.id;
|
|
1062
|
+
const route = plain(page.route) ?? plain(page.screen) ?? page.id;
|
|
1063
|
+
const origin = page.origin ? plain(page.origin) : null;
|
|
602
1064
|
const out = el("div", { class: "grimoire-view" }, [
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
1065
|
+
crumbs(ctx, [["Apps", "apps"], [app, "apps"], [title]]),
|
|
1066
|
+
heading(ctx, title, [
|
|
1067
|
+
pill(ctx, page.type === "screen" ? "screen" : "page"),
|
|
1068
|
+
mono(ctx, route),
|
|
1069
|
+
muted(ctx, app),
|
|
1070
|
+
origin ? pill(ctx, origin, toneOf(origin)) : "",
|
|
1071
|
+
]),
|
|
606
1072
|
]);
|
|
607
1073
|
|
|
608
|
-
if (page.purpose) out.append(el("p", { text: page.purpose }));
|
|
1074
|
+
if (page.purpose) out.append(el("p", { class: "grimoire-lede", text: page.purpose }));
|
|
609
1075
|
|
|
610
1076
|
const rows = [
|
|
611
1077
|
...(data.layout ? data.layout.blocks.map((row) => ({ row, from: "layout" })) : []),
|
|
@@ -619,7 +1085,7 @@ async function pageView(ctx, app, key) {
|
|
|
619
1085
|
["Block", "From", "Flow", "Who", "Changes with"],
|
|
620
1086
|
rows.map(({ row, from }) => [
|
|
621
1087
|
[row.block],
|
|
622
|
-
[from],
|
|
1088
|
+
[pill(ctx, from)],
|
|
623
1089
|
[row.flow ? flowLink(ctx, row.flow) : ""],
|
|
624
1090
|
[row.who.everyone ? "everyone" : row.who.conditions.join(", ")],
|
|
625
1091
|
[
|
|
@@ -656,13 +1122,16 @@ async function pageView(ctx, app, key) {
|
|
|
656
1122
|
if (data.book) {
|
|
657
1123
|
out.append(
|
|
658
1124
|
section(ctx, "In the code", [
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
1125
|
+
facts(ctx, [
|
|
1126
|
+
["File", fileLink(ctx, data.book.file)],
|
|
1127
|
+
["Layouts", data.book.layouts?.length ? fileChips(ctx, data.book.layouts) : null],
|
|
1128
|
+
[
|
|
1129
|
+
"Requires",
|
|
1130
|
+
data.book.requires?.length
|
|
1131
|
+
? chipList(ctx, data.book.requires, (item) => mono(ctx, item))
|
|
1132
|
+
: null,
|
|
1133
|
+
],
|
|
1134
|
+
]),
|
|
666
1135
|
]),
|
|
667
1136
|
);
|
|
668
1137
|
}
|
|
@@ -671,115 +1140,367 @@ async function pageView(ctx, app, key) {
|
|
|
671
1140
|
return out;
|
|
672
1141
|
}
|
|
673
1142
|
|
|
1143
|
+
/** The group a page or screen is listed under: the first segment of its route, or the top level. */
|
|
1144
|
+
function groupOf(row) {
|
|
1145
|
+
const segments = (row.route ?? row.id)
|
|
1146
|
+
.split("/")
|
|
1147
|
+
.filter((segment) => segment && !segment.startsWith(":") && !segment.startsWith("["));
|
|
1148
|
+
const first = segments[0]?.replace(/^\(.*\)$/, "") ?? "";
|
|
1149
|
+
|
|
1150
|
+
return segments.length > 1 && first ? first : "";
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
function appIcon(ctx, type) {
|
|
1154
|
+
const { svg } = ctx;
|
|
1155
|
+
const common = {
|
|
1156
|
+
viewBox: "0 0 24 24",
|
|
1157
|
+
width: "22",
|
|
1158
|
+
height: "22",
|
|
1159
|
+
fill: "none",
|
|
1160
|
+
stroke: "currentColor",
|
|
1161
|
+
"stroke-width": "1.8",
|
|
1162
|
+
"stroke-linecap": "round",
|
|
1163
|
+
"stroke-linejoin": "round",
|
|
1164
|
+
"aria-hidden": "true",
|
|
1165
|
+
class: "grimoire-app-icon",
|
|
1166
|
+
};
|
|
1167
|
+
|
|
1168
|
+
return type === "mobile"
|
|
1169
|
+
? svg("svg", common, [
|
|
1170
|
+
svg("rect", { x: "7", y: "2.5", width: "10", height: "19", rx: "2.2" }),
|
|
1171
|
+
svg("path", { d: "M11 18.5h2" }),
|
|
1172
|
+
])
|
|
1173
|
+
: svg("svg", common, [
|
|
1174
|
+
svg("rect", { x: "3", y: "4", width: "18", height: "12", rx: "2" }),
|
|
1175
|
+
svg("path", { d: "M9 20h6M12 16v4" }),
|
|
1176
|
+
]);
|
|
1177
|
+
}
|
|
1178
|
+
|
|
674
1179
|
async function appsView(ctx) {
|
|
675
1180
|
const data = await ctx.api("apps");
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
1181
|
+
const { el } = ctx;
|
|
1182
|
+
|
|
1183
|
+
if (!data.apps.length)
|
|
1184
|
+
return ctx.empty(
|
|
1185
|
+
"No apps are written in grimoire/apps. Ask your agent to write them (skill use-the-grimoire).",
|
|
1186
|
+
);
|
|
1187
|
+
|
|
1188
|
+
// Older answers list ids only.
|
|
1189
|
+
const rowsOf = (app) =>
|
|
1190
|
+
app.rows ?? [
|
|
1191
|
+
...app.pages.map((id) => ({ id, type: "page" })),
|
|
1192
|
+
...app.screens.map((id) => ({ id, type: "screen" })),
|
|
1193
|
+
];
|
|
1194
|
+
const items = data.apps.flatMap((app) =>
|
|
1195
|
+
rowsOf(app).map((row) => ({
|
|
1196
|
+
route: null,
|
|
1197
|
+
heading: null,
|
|
1198
|
+
origin: null,
|
|
1199
|
+
layout: null,
|
|
1200
|
+
blocks: null,
|
|
1201
|
+
...row,
|
|
1202
|
+
app: app.id,
|
|
1203
|
+
})),
|
|
1204
|
+
);
|
|
1205
|
+
|
|
1206
|
+
const renderApp = (app, rows, filtered) => {
|
|
1207
|
+
const own = items.filter((row) => row.app === app.id);
|
|
1208
|
+
const confirmed = own.filter((row) => row.origin === "confirmed").length;
|
|
1209
|
+
const inferred = own.filter((row) => row.origin === "inferred").length;
|
|
1210
|
+
const groups = new Map();
|
|
1211
|
+
|
|
1212
|
+
for (const row of rows) {
|
|
1213
|
+
const name = groupOf(row);
|
|
1214
|
+
|
|
1215
|
+
groups.set(name, [...(groups.get(name) ?? []), row]);
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
return el("section", { class: "grimoire-card grimoire-app-card" }, [
|
|
1219
|
+
el("header", { class: "grimoire-app-head" }, [
|
|
1220
|
+
appIcon(ctx, app.type),
|
|
1221
|
+
el("h3", { text: app.id }),
|
|
1222
|
+
pill(ctx, app.type === "mobile" ? "mobile app" : "site"),
|
|
1223
|
+
mono(ctx, app.root),
|
|
1224
|
+
]),
|
|
1225
|
+
el("p", { class: "grimoire-muted" }, [
|
|
1226
|
+
`${plural(app.pages.length, "page")}, ${plural(app.screens.length, "screen")}`,
|
|
1227
|
+
confirmed || inferred ? `; ${confirmed} confirmed, ${inferred} inferred` : "",
|
|
1228
|
+
filtered ? `; showing ${rows.length}` : "",
|
|
1229
|
+
]),
|
|
1230
|
+
own.length
|
|
1231
|
+
? [...groups.entries()]
|
|
1232
|
+
.sort(([a], [b]) => (a === "" ? -1 : b === "" ? 1 : a.localeCompare(b)))
|
|
1233
|
+
.map(([name, group]) =>
|
|
1234
|
+
el("div", { class: "grimoire-group" }, [
|
|
1235
|
+
el("h4", { text: `${name ? `/${name}` : "Top level"} (${group.length})` }),
|
|
1236
|
+
table(
|
|
1237
|
+
ctx,
|
|
1238
|
+
["Page", "Route or screen", "Title", "Layout", "Blocks", "Status"],
|
|
1239
|
+
[...group]
|
|
1240
|
+
.sort((a, b) => (a.route ?? a.id).localeCompare(b.route ?? b.id))
|
|
1241
|
+
.map((row) => [
|
|
1242
|
+
[
|
|
1243
|
+
link(
|
|
1244
|
+
ctx,
|
|
1245
|
+
row.id,
|
|
1246
|
+
`page/${encodeURIComponent(app.id)}/${encodeURIComponent(row.id)}`,
|
|
1247
|
+
),
|
|
1248
|
+
row.type === "screen" ? [" ", pill(ctx, "screen")] : "",
|
|
1249
|
+
],
|
|
1250
|
+
[row.route ? mono(ctx, row.route) : ""],
|
|
1251
|
+
[row.heading ?? ""],
|
|
1252
|
+
[row.layout ?? ""],
|
|
1253
|
+
[row.blocks === null ? "" : String(row.blocks)],
|
|
1254
|
+
[
|
|
1255
|
+
row.origin
|
|
1256
|
+
? pill(ctx, row.origin, toneOf(row.origin))
|
|
1257
|
+
: muted(ctx, "unmarked"),
|
|
1258
|
+
],
|
|
1259
|
+
]),
|
|
1260
|
+
),
|
|
688
1261
|
]),
|
|
689
1262
|
)
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
1263
|
+
: ctx.empty("No pages written."),
|
|
1264
|
+
]);
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
return el("div", { class: "grimoire-view" }, [
|
|
1268
|
+
heading(ctx, "Apps"),
|
|
1269
|
+
items.length
|
|
1270
|
+
? listing(ctx, {
|
|
1271
|
+
items,
|
|
1272
|
+
noun: "pages and screens",
|
|
1273
|
+
placeholder: "Filter pages and screens",
|
|
1274
|
+
textOf: (row) => [row.app, row.id, row.route ?? "", row.heading ?? ""].join(" "),
|
|
1275
|
+
statusOf: (row) => row.origin ?? "unmarked",
|
|
1276
|
+
statusOrder: ["confirmed", "inferred", "unmarked"],
|
|
1277
|
+
render: (shown, all) =>
|
|
1278
|
+
el(
|
|
1279
|
+
"div",
|
|
1280
|
+
{ class: "grimoire-app-list" },
|
|
1281
|
+
data.apps
|
|
1282
|
+
.filter(
|
|
1283
|
+
(app) => shown.length === all.length || shown.some((row) => row.app === app.id),
|
|
1284
|
+
)
|
|
1285
|
+
.map((app) =>
|
|
1286
|
+
renderApp(
|
|
1287
|
+
app,
|
|
1288
|
+
shown.filter((row) => row.app === app.id),
|
|
1289
|
+
shown.length !== all.length,
|
|
1290
|
+
),
|
|
1291
|
+
),
|
|
1292
|
+
),
|
|
1293
|
+
})
|
|
1294
|
+
: el(
|
|
1295
|
+
"div",
|
|
1296
|
+
{ class: "grimoire-app-list" },
|
|
1297
|
+
data.apps.map((app) => renderApp(app, [], false)),
|
|
1298
|
+
),
|
|
1299
|
+
]);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
/** One task's header facts. */
|
|
1303
|
+
function taskCard(ctx, task) {
|
|
1304
|
+
return section(ctx, task.id, [
|
|
1305
|
+
facts(ctx, [
|
|
1306
|
+
["Title", task.title],
|
|
1307
|
+
["Type", task.type],
|
|
1308
|
+
["Status", pill(ctx, task.status, toneOf(task.status))],
|
|
1309
|
+
[
|
|
1310
|
+
"Feature",
|
|
1311
|
+
task.feature
|
|
1312
|
+
? link(ctx, task.feature, `feature/${encodeURIComponent(task.feature)}`)
|
|
1313
|
+
: null,
|
|
1314
|
+
],
|
|
1315
|
+
["Flow", task.feature && task.flow ? flowLink(ctx, `${task.feature}/${task.flow}`) : null],
|
|
1316
|
+
["Apps", task.apps?.length ? task.apps.join(", ") : null],
|
|
1317
|
+
["File", mono(ctx, task.file)],
|
|
1318
|
+
["Decision needed", task.decisionNeeded ?? null],
|
|
1319
|
+
["Shipped in", task.shipped ? `${task.shipped.feature} ${task.shipped.version}` : null],
|
|
1320
|
+
]),
|
|
1321
|
+
]);
|
|
694
1322
|
}
|
|
695
1323
|
|
|
696
1324
|
async function tasksView(ctx, only) {
|
|
697
1325
|
const data = await ctx.api("tasks");
|
|
1326
|
+
const { el } = ctx;
|
|
1327
|
+
|
|
1328
|
+
if (only) {
|
|
1329
|
+
const task = [...data.open, ...data.waiting, ...data.done].find((item) => item.id === only);
|
|
1330
|
+
|
|
1331
|
+
return el("div", { class: "grimoire-view" }, [
|
|
1332
|
+
crumbs(ctx, [["Tasks", "tasks"], [only]]),
|
|
1333
|
+
task
|
|
1334
|
+
? taskCard(ctx, task)
|
|
1335
|
+
: ctx.empty(`No task ${only}. Open the task list to see the ids that exist.`),
|
|
1336
|
+
]);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
698
1339
|
// `waiting` is the part of `open` that waits for the owner: each task shows in one group only.
|
|
699
1340
|
const waiting = new Set(data.waiting.map((task) => task.id));
|
|
700
1341
|
const groups = [
|
|
701
|
-
["Open", data.open.filter((task) => !waiting.has(task.id))],
|
|
702
|
-
["Waiting for approval", data.waiting],
|
|
703
|
-
["Done", data.done],
|
|
704
|
-
]
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
[
|
|
724
|
-
[
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
1342
|
+
["open", "Open", data.open.filter((task) => !waiting.has(task.id))],
|
|
1343
|
+
["waiting", "Waiting for approval", data.waiting],
|
|
1344
|
+
["done", "Done", data.done],
|
|
1345
|
+
];
|
|
1346
|
+
const items = groups.flatMap(([group, , tasks]) => tasks.map((task) => ({ ...task, group })));
|
|
1347
|
+
|
|
1348
|
+
if (!items.length) return ctx.empty("No tasks are written in grimoire/tasks.");
|
|
1349
|
+
|
|
1350
|
+
return el("div", { class: "grimoire-view" }, [
|
|
1351
|
+
heading(ctx, "Tasks"),
|
|
1352
|
+
listing(ctx, {
|
|
1353
|
+
items,
|
|
1354
|
+
noun: "tasks",
|
|
1355
|
+
textOf: (task) =>
|
|
1356
|
+
[task.id, task.title, task.type, task.feature ?? "", task.decisionNeeded ?? ""].join(" "),
|
|
1357
|
+
statusOf: (task) => task.group,
|
|
1358
|
+
statusOrder: ["open", "waiting", "done"],
|
|
1359
|
+
render: (shown) =>
|
|
1360
|
+
el(
|
|
1361
|
+
"div",
|
|
1362
|
+
{ class: "grimoire-view-groups" },
|
|
1363
|
+
groups
|
|
1364
|
+
.map(([group, title]) => [title, shown.filter((task) => task.group === group), group])
|
|
1365
|
+
.filter(([, tasks]) => tasks.length)
|
|
1366
|
+
.map(([title, tasks, group]) =>
|
|
1367
|
+
section(ctx, `${title} (${tasks.length})`, [
|
|
1368
|
+
table(
|
|
1369
|
+
ctx,
|
|
1370
|
+
["Task", "Title", "Type", "Status", "Feature", "Decision needed"],
|
|
1371
|
+
tasks.map((task) => [
|
|
1372
|
+
[link(ctx, task.id, `task/${encodeURIComponent(task.id)}`)],
|
|
1373
|
+
[task.title],
|
|
1374
|
+
[task.type],
|
|
1375
|
+
[pill(ctx, task.status, toneOf(group))],
|
|
1376
|
+
[
|
|
1377
|
+
task.feature
|
|
1378
|
+
? link(ctx, task.feature, `feature/${encodeURIComponent(task.feature)}`)
|
|
1379
|
+
: "",
|
|
1380
|
+
],
|
|
1381
|
+
[task.decisionNeeded ?? ""],
|
|
1382
|
+
]),
|
|
1383
|
+
),
|
|
1384
|
+
]),
|
|
1385
|
+
),
|
|
732
1386
|
),
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
);
|
|
1387
|
+
}),
|
|
1388
|
+
]);
|
|
736
1389
|
}
|
|
737
1390
|
|
|
738
1391
|
async function releasesView(ctx) {
|
|
739
1392
|
const data = await ctx.api("releases");
|
|
1393
|
+
const { el } = ctx;
|
|
1394
|
+
|
|
740
1395
|
if (!data.releases.length) return ctx.empty("No releases are written in grimoire/releases.");
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
data.releases
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
1396
|
+
|
|
1397
|
+
return el("div", { class: "grimoire-view" }, [
|
|
1398
|
+
heading(ctx, "Releases"),
|
|
1399
|
+
listing(ctx, {
|
|
1400
|
+
items: data.releases,
|
|
1401
|
+
noun: "releases",
|
|
1402
|
+
textOf: (item) => `${item.release} ${item.date} ${item.file}`,
|
|
1403
|
+
sorts: [
|
|
1404
|
+
["newest", "newest first", (a, b) => b.date.localeCompare(a.date)],
|
|
1405
|
+
["oldest", "oldest first", (a, b) => a.date.localeCompare(b.date)],
|
|
1406
|
+
],
|
|
1407
|
+
render: (shown) =>
|
|
1408
|
+
section(ctx, "Releases", [
|
|
1409
|
+
table(
|
|
1410
|
+
ctx,
|
|
1411
|
+
["Release", "Date", "File"],
|
|
1412
|
+
shown.map((item) => [
|
|
1413
|
+
[link(ctx, item.release, `release/${encodeURIComponent(item.release)}`)],
|
|
1414
|
+
[item.date],
|
|
1415
|
+
[mono(ctx, item.file)],
|
|
1416
|
+
]),
|
|
1417
|
+
),
|
|
1418
|
+
]),
|
|
1419
|
+
}),
|
|
751
1420
|
]);
|
|
752
1421
|
}
|
|
753
1422
|
|
|
754
1423
|
async function releaseView(ctx, id) {
|
|
755
1424
|
const data = await ctx.api(`releases/${encodeURIComponent(id)}`);
|
|
1425
|
+
const { el } = ctx;
|
|
756
1426
|
const entries = data.collected?.entries ?? [];
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
1427
|
+
const byFeature = new Map();
|
|
1428
|
+
|
|
1429
|
+
for (const entry of entries)
|
|
1430
|
+
byFeature.set(entry.feature, [...(byFeature.get(entry.feature) ?? []), entry]);
|
|
1431
|
+
|
|
1432
|
+
return el("div", { class: "grimoire-view" }, [
|
|
1433
|
+
crumbs(ctx, [["Releases", "releases"], [`Release ${plain(data.release)}`]]),
|
|
1434
|
+
heading(ctx, `Release ${plain(data.release)}`, [muted(ctx, plain(data.date))]),
|
|
1435
|
+
data.brief ? el("p", { class: "grimoire-lede", text: data.brief }) : "",
|
|
1436
|
+
entries.length
|
|
1437
|
+
? [...byFeature.entries()].map(([feature, items]) =>
|
|
1438
|
+
section(ctx, `${feature} (${items.length})`, [
|
|
1439
|
+
list(
|
|
1440
|
+
ctx,
|
|
1441
|
+
items.map((entry) => [
|
|
1442
|
+
`${entry.feature} ${entry.version}: ${entry.text ?? JSON.stringify(entry)}`,
|
|
1443
|
+
]),
|
|
1444
|
+
),
|
|
1445
|
+
]),
|
|
1446
|
+
)
|
|
1447
|
+
: section(ctx, "Collected entries", [ctx.empty("Nothing is listed for this release.")]),
|
|
770
1448
|
]);
|
|
771
1449
|
}
|
|
772
1450
|
|
|
773
1451
|
async function checkView(ctx) {
|
|
774
1452
|
const report = await ctx.api("check");
|
|
775
1453
|
const { counts } = report;
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
1454
|
+
const { el } = ctx;
|
|
1455
|
+
const items = report.findings.map((finding) => ({
|
|
1456
|
+
finding,
|
|
1457
|
+
state: finding.expected ? "expected" : finding.severity,
|
|
1458
|
+
}));
|
|
1459
|
+
|
|
1460
|
+
return el("div", { class: "grimoire-view" }, [
|
|
1461
|
+
heading(ctx, report.ok ? "Check: no unexpected errors" : "Check: errors found", [
|
|
1462
|
+
pill(ctx, plural(counts.errors, "error"), counts.errors ? "bad" : "good"),
|
|
1463
|
+
pill(ctx, plural(counts.warnings, "warning"), counts.warnings ? "warn" : ""),
|
|
1464
|
+
pill(ctx, `${counts.expected} expected`),
|
|
1465
|
+
muted(ctx, `routes ${report.routes}`),
|
|
1466
|
+
]),
|
|
1467
|
+
items.length
|
|
1468
|
+
? listing(ctx, {
|
|
1469
|
+
items,
|
|
1470
|
+
noun: "findings",
|
|
1471
|
+
textOf: ({ finding }) =>
|
|
1472
|
+
[
|
|
1473
|
+
finding.code,
|
|
1474
|
+
finding.message,
|
|
1475
|
+
finding.at?.file ?? "",
|
|
1476
|
+
finding.subject.file ?? "",
|
|
1477
|
+
finding.subject.feature ?? "",
|
|
1478
|
+
].join(" "),
|
|
1479
|
+
statusOf: (item) => item.state,
|
|
1480
|
+
statusOrder: ["error", "warning", "expected"],
|
|
1481
|
+
render: (shown) => {
|
|
1482
|
+
const fix = shown
|
|
1483
|
+
.filter((item) => item.state !== "expected")
|
|
1484
|
+
.map((item) => item.finding);
|
|
1485
|
+
const expected = shown
|
|
1486
|
+
.filter((item) => item.state === "expected")
|
|
1487
|
+
.map((item) => item.finding);
|
|
1488
|
+
|
|
1489
|
+
return el("div", { class: "grimoire-view-groups" }, [
|
|
1490
|
+
fix.length ? section(ctx, `To fix (${fix.length})`, [findingList(ctx, fix)]) : "",
|
|
1491
|
+
expected.length
|
|
1492
|
+
? section(ctx, `Expected: proposed work (${expected.length})`, [
|
|
1493
|
+
el("p", {
|
|
1494
|
+
class: "grimoire-muted",
|
|
1495
|
+
text: "These concern features or flows that are still proposed, so the code does not exist yet. They never fail the check.",
|
|
1496
|
+
}),
|
|
1497
|
+
findingList(ctx, expected),
|
|
1498
|
+
])
|
|
1499
|
+
: "",
|
|
1500
|
+
]);
|
|
1501
|
+
},
|
|
1502
|
+
})
|
|
1503
|
+
: ctx.empty("No findings."),
|
|
783
1504
|
]);
|
|
784
1505
|
}
|
|
785
1506
|
|
|
@@ -791,34 +1512,47 @@ async function fileView(ctx, path) {
|
|
|
791
1512
|
const { el } = ctx;
|
|
792
1513
|
const entry = data.entry;
|
|
793
1514
|
const out = el("div", { class: "grimoire-view" }, [
|
|
794
|
-
|
|
795
|
-
|
|
1515
|
+
crumbs(ctx, [["Modules", "modules"], [entry.file]]),
|
|
1516
|
+
heading(ctx, entry.file, [
|
|
1517
|
+
pill(ctx, entry.type),
|
|
1518
|
+
mono(ctx, entry.module),
|
|
1519
|
+
muted(ctx, `${entry.lines} lines`),
|
|
1520
|
+
]),
|
|
796
1521
|
]);
|
|
797
|
-
if (entry.about) out.append(el("p", { text: entry.about }));
|
|
798
|
-
|
|
799
|
-
const owner = [];
|
|
800
|
-
if (entry.feature)
|
|
801
|
-
owner.push(
|
|
802
|
-
"Owned by ",
|
|
803
|
-
link(ctx, entry.feature, `feature/${encodeURIComponent(entry.feature)}`),
|
|
804
|
-
". ",
|
|
805
|
-
);
|
|
806
|
-
if (entry.borrowedBy.length) owner.push("Borrowed by ", entry.borrowedBy.join(", "), ". ");
|
|
807
|
-
if (entry.flows.length)
|
|
808
|
-
owner.push("Used by flows: ", ...entry.flows.flatMap((flow) => [flowLink(ctx, flow), " "]));
|
|
809
|
-
if (owner.length) out.append(el("p", {}, owner));
|
|
1522
|
+
if (entry.about) out.append(el("p", { class: "grimoire-lede", text: entry.about }));
|
|
810
1523
|
|
|
811
1524
|
out.append(
|
|
1525
|
+
section(ctx, "Who uses it", [
|
|
1526
|
+
facts(ctx, [
|
|
1527
|
+
[
|
|
1528
|
+
"Owned by",
|
|
1529
|
+
entry.feature
|
|
1530
|
+
? link(ctx, entry.feature, `feature/${encodeURIComponent(entry.feature)}`)
|
|
1531
|
+
: null,
|
|
1532
|
+
],
|
|
1533
|
+
["Borrowed by", entry.borrowedBy.length ? entry.borrowedBy.join(", ") : null],
|
|
1534
|
+
[
|
|
1535
|
+
"Used by flows",
|
|
1536
|
+
entry.flows.length
|
|
1537
|
+
? el(
|
|
1538
|
+
"span",
|
|
1539
|
+
{},
|
|
1540
|
+
entry.flows.flatMap((flow) => [flowLink(ctx, flow), " "]),
|
|
1541
|
+
)
|
|
1542
|
+
: null,
|
|
1543
|
+
],
|
|
1544
|
+
]),
|
|
1545
|
+
]),
|
|
812
1546
|
section(ctx, "Exports", [
|
|
813
1547
|
entry.exports.length
|
|
814
1548
|
? list(
|
|
815
1549
|
ctx,
|
|
816
|
-
entry.exports.map((item) => [
|
|
1550
|
+
entry.exports.map((item) => [mono(ctx, item.name), item.about ? ` ${item.about}` : ""]),
|
|
817
1551
|
)
|
|
818
|
-
:
|
|
1552
|
+
: muted(ctx, "none"),
|
|
819
1553
|
]),
|
|
820
|
-
section(ctx, "Imports", [
|
|
821
|
-
section(ctx, "Imported by", [
|
|
1554
|
+
section(ctx, "Imports", [fileChips(ctx, entry.imports, 20)]),
|
|
1555
|
+
section(ctx, "Imported by", [fileChips(ctx, entry.importedBy, 20)]),
|
|
822
1556
|
);
|
|
823
1557
|
|
|
824
1558
|
if (entry.routes.length) {
|
|
@@ -826,14 +1560,7 @@ async function fileView(ctx, path) {
|
|
|
826
1560
|
section(ctx, "Routes", [
|
|
827
1561
|
list(
|
|
828
1562
|
ctx,
|
|
829
|
-
entry.routes.map((item) => [
|
|
830
|
-
link(
|
|
831
|
-
ctx,
|
|
832
|
-
`${item.method} ${item.path}`,
|
|
833
|
-
`route/${encodeURIComponent(item.method)}/${encodeURIComponent(item.path)}`,
|
|
834
|
-
),
|
|
835
|
-
` (${item.via})`,
|
|
836
|
-
]),
|
|
1563
|
+
entry.routes.map((item) => [routeLink(ctx, item.method, item.path), ` (${item.via})`]),
|
|
837
1564
|
),
|
|
838
1565
|
]),
|
|
839
1566
|
);
|
|
@@ -850,19 +1577,19 @@ async function routeView(ctx, method, path) {
|
|
|
850
1577
|
const { el } = ctx;
|
|
851
1578
|
const found = data.route;
|
|
852
1579
|
const out = el("div", { class: "grimoire-view" }, [
|
|
853
|
-
|
|
854
|
-
|
|
1580
|
+
crumbs(ctx, [["Modules", "modules"], [`${found.method} ${found.path}`]]),
|
|
1581
|
+
heading(ctx, `${found.method} ${found.path}`, [muted(ctx, found.description ?? found.handler)]),
|
|
855
1582
|
]);
|
|
856
1583
|
if (found.handlerFile) out.append(el("p", {}, ["Handler: ", fileLink(ctx, found.handlerFile)]));
|
|
857
1584
|
out.append(
|
|
858
|
-
section(ctx, "Files behind it", [
|
|
1585
|
+
section(ctx, "Files behind it", [fileChips(ctx, data.files, 20)]),
|
|
859
1586
|
section(ctx, "Flow steps", [
|
|
860
1587
|
data.steps.length
|
|
861
1588
|
? list(
|
|
862
1589
|
ctx,
|
|
863
1590
|
data.steps.map((step) => [flowLink(ctx, step.flow), ` step ${step.index}`]),
|
|
864
1591
|
)
|
|
865
|
-
:
|
|
1592
|
+
: muted(ctx, "none"),
|
|
866
1593
|
]),
|
|
867
1594
|
);
|
|
868
1595
|
return out;
|
|
@@ -870,22 +1597,59 @@ async function routeView(ctx, method, path) {
|
|
|
870
1597
|
|
|
871
1598
|
async function modulesView(ctx) {
|
|
872
1599
|
const graph = await ctx.api("graph/modules");
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1600
|
+
const { el } = ctx;
|
|
1601
|
+
const weight = new Map();
|
|
1602
|
+
|
|
1603
|
+
for (const edge of graph.edges) {
|
|
1604
|
+
for (const end of [edge.from, edge.to])
|
|
1605
|
+
weight.set(end, (weight.get(end) ?? 0) + (edge.weight ?? 1));
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
const items = graph.nodes.map((node) => ({ label: node.label, links: weight.get(node.id) ?? 0 }));
|
|
1609
|
+
|
|
1610
|
+
return el("div", { class: "grimoire-view" }, [
|
|
1611
|
+
heading(ctx, "Module coupling"),
|
|
1612
|
+
el("p", {
|
|
1613
|
+
class: "grimoire-muted",
|
|
877
1614
|
text: "Lines are imports between modules; thicker means more imports. The most connected modules are drawn.",
|
|
878
1615
|
}),
|
|
879
1616
|
graphView(ctx, graph, "Modules"),
|
|
1617
|
+
items.length
|
|
1618
|
+
? listing(ctx, {
|
|
1619
|
+
items,
|
|
1620
|
+
noun: "modules",
|
|
1621
|
+
textOf: (item) => item.label,
|
|
1622
|
+
sorts: [
|
|
1623
|
+
[
|
|
1624
|
+
"links",
|
|
1625
|
+
"most imports",
|
|
1626
|
+
(a, b) => b.links - a.links || a.label.localeCompare(b.label),
|
|
1627
|
+
],
|
|
1628
|
+
["name", "name", (a, b) => a.label.localeCompare(b.label)],
|
|
1629
|
+
],
|
|
1630
|
+
render: (shown) =>
|
|
1631
|
+
section(ctx, "Modules", [
|
|
1632
|
+
table(
|
|
1633
|
+
ctx,
|
|
1634
|
+
["Module", "Imports to and from"],
|
|
1635
|
+
shown.map((item) => [[mono(ctx, item.label)], [String(item.links)]]),
|
|
1636
|
+
),
|
|
1637
|
+
]),
|
|
1638
|
+
})
|
|
1639
|
+
: "",
|
|
880
1640
|
]);
|
|
881
1641
|
}
|
|
882
1642
|
|
|
1643
|
+
// ── Shell ───────────────────────────────────────────────────────────────────
|
|
1644
|
+
|
|
883
1645
|
/** Pick the view for the hash route. */
|
|
884
|
-
async function body(ctx) {
|
|
1646
|
+
async function body(ctx, summaryRequest) {
|
|
885
1647
|
const parts = ctx.route ? ctx.route.split("/").map(decodeSegment) : [];
|
|
886
1648
|
const [type = "", first = "", second = ""] = parts;
|
|
887
1649
|
|
|
888
1650
|
switch (type) {
|
|
1651
|
+
case "features":
|
|
1652
|
+
return featuresView(ctx);
|
|
889
1653
|
case "feature":
|
|
890
1654
|
return featureView(ctx, first);
|
|
891
1655
|
case "flow":
|
|
@@ -911,67 +1675,302 @@ async function body(ctx) {
|
|
|
911
1675
|
case "modules":
|
|
912
1676
|
return modulesView(ctx);
|
|
913
1677
|
default:
|
|
914
|
-
return
|
|
1678
|
+
return overviewView(ctx, summaryRequest);
|
|
915
1679
|
}
|
|
916
1680
|
}
|
|
917
1681
|
|
|
918
|
-
/**
|
|
919
|
-
function
|
|
1682
|
+
/** What the view is about, for error messages, and the list to go back to. */
|
|
1683
|
+
function describe(route) {
|
|
1684
|
+
const type = route.split("/")[0] ?? "";
|
|
1685
|
+
const map = {
|
|
1686
|
+
features: ["the features", null],
|
|
1687
|
+
feature: ["the feature", ["Features", "features"]],
|
|
1688
|
+
flow: ["the flow", ["Features", "features"]],
|
|
1689
|
+
apps: ["the apps", null],
|
|
1690
|
+
page: ["the page", ["Apps", "apps"]],
|
|
1691
|
+
tasks: ["the tasks", null],
|
|
1692
|
+
task: ["the task", ["Tasks", "tasks"]],
|
|
1693
|
+
releases: ["the releases", null],
|
|
1694
|
+
release: ["the release", ["Releases", "releases"]],
|
|
1695
|
+
check: ["the check report", null],
|
|
1696
|
+
modules: ["the module graph", null],
|
|
1697
|
+
file: ["the file", ["Modules", "modules"]],
|
|
1698
|
+
route: ["the route", ["Modules", "modules"]],
|
|
1699
|
+
};
|
|
1700
|
+
|
|
1701
|
+
return map[type] ?? ["the overview", null];
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
/** The loading state: shown at once, so a large book never leaves a blank area. */
|
|
1705
|
+
function skeleton(ctx) {
|
|
1706
|
+
const { el } = ctx;
|
|
1707
|
+
|
|
1708
|
+
return el("div", { class: "grimoire-skeleton", role: "status" }, [
|
|
1709
|
+
el("p", { class: "grimoire-skeleton-title", text: "Opening the book…" }),
|
|
1710
|
+
el("p", {
|
|
1711
|
+
class: "grimoire-muted",
|
|
1712
|
+
text: "A large book can take a few seconds to open the first time.",
|
|
1713
|
+
}),
|
|
1714
|
+
el(
|
|
1715
|
+
"div",
|
|
1716
|
+
{ class: "grimoire-skeleton-grid", "aria-hidden": "true" },
|
|
1717
|
+
[1, 2, 3, 4, 5, 6].map(() => el("div", { class: "grimoire-skeleton-block" })),
|
|
1718
|
+
),
|
|
1719
|
+
]);
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
/** A failed view: what failed, why, what to do, and a way to try again. */
|
|
1723
|
+
function errorBox(ctx, route, error) {
|
|
1724
|
+
const { el } = ctx;
|
|
1725
|
+
const [what, back] = describe(route);
|
|
1726
|
+
const message = error && error.message ? error.message : String(error);
|
|
1727
|
+
const needsApp = message.includes("running app");
|
|
1728
|
+
|
|
1729
|
+
return el("div", { class: "grimoire-error", role: "alert" }, [
|
|
1730
|
+
el("p", { class: "grimoire-error-title", text: `Could not load ${what}: ${message}` }),
|
|
1731
|
+
el("p", {
|
|
1732
|
+
class: "grimoire-muted",
|
|
1733
|
+
text: needsApp
|
|
1734
|
+
? "Open the Grimoire tab in the devtools dashboard to see this answer."
|
|
1735
|
+
: back
|
|
1736
|
+
? `It may have been renamed or removed. Go back to the list, or run warlock grimoire build and reload.`
|
|
1737
|
+
: BUILD_HINT,
|
|
1738
|
+
}),
|
|
1739
|
+
el("p", {}, [
|
|
1740
|
+
el("button", {
|
|
1741
|
+
type: "button",
|
|
1742
|
+
class: "grimoire-filter",
|
|
1743
|
+
text: "Try again",
|
|
1744
|
+
onclick: () => ctx.refresh(),
|
|
1745
|
+
}),
|
|
1746
|
+
back ? [" ", link(ctx, `Back to ${back[0]}`, back[1])] : "",
|
|
1747
|
+
]),
|
|
1748
|
+
]);
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
let shortcutHandler = null;
|
|
1752
|
+
|
|
1753
|
+
/** `/` focuses the search box from anywhere that is not a text field; the newest view owns the key. */
|
|
1754
|
+
function bindShortcut(input) {
|
|
1755
|
+
if (typeof document === "undefined" || typeof document.addEventListener !== "function") return;
|
|
1756
|
+
if (shortcutHandler) document.removeEventListener("keydown", shortcutHandler);
|
|
1757
|
+
|
|
1758
|
+
shortcutHandler = (event) => {
|
|
1759
|
+
if (event.key !== "/" || event.metaKey || event.ctrlKey || event.altKey) return;
|
|
1760
|
+
|
|
1761
|
+
const target = event.target;
|
|
1762
|
+
const tag = target && target.tagName;
|
|
1763
|
+
|
|
1764
|
+
if (
|
|
1765
|
+
tag === "INPUT" ||
|
|
1766
|
+
tag === "TEXTAREA" ||
|
|
1767
|
+
tag === "SELECT" ||
|
|
1768
|
+
(target && target.isContentEditable)
|
|
1769
|
+
)
|
|
1770
|
+
return;
|
|
1771
|
+
if (!input.isConnected) return;
|
|
1772
|
+
|
|
1773
|
+
event.preventDefault();
|
|
1774
|
+
input.focus();
|
|
1775
|
+
};
|
|
1776
|
+
document.addEventListener("keydown", shortcutHandler);
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
/** The header: the tabs and the one search box. Results appear under the box, grouped by type. */
|
|
1780
|
+
function header(ctx, route, summaryRequest) {
|
|
920
1781
|
const { el } = ctx;
|
|
921
1782
|
const results = el("div", { class: "grimoire-results" });
|
|
1783
|
+
const active = tabOf(route);
|
|
1784
|
+
const badges = new Map();
|
|
922
1785
|
let token = 0;
|
|
923
1786
|
let timer = null;
|
|
1787
|
+
let rows = [];
|
|
1788
|
+
let current = -1;
|
|
1789
|
+
|
|
1790
|
+
function highlight(index) {
|
|
1791
|
+
current = index;
|
|
1792
|
+
rows.forEach((row, position) => {
|
|
1793
|
+
row.node.setAttribute(
|
|
1794
|
+
"class",
|
|
1795
|
+
position === index ? "grimoire-hit is-active" : "grimoire-hit",
|
|
1796
|
+
);
|
|
1797
|
+
row.node.setAttribute("aria-selected", String(position === index));
|
|
1798
|
+
});
|
|
1799
|
+
if (rows[index]) {
|
|
1800
|
+
input.setAttribute("aria-activedescendant", `grimoire-hit-${index}`);
|
|
1801
|
+
rows[index].node.scrollIntoView?.({ block: "nearest" });
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
function clear() {
|
|
1806
|
+
token += 1;
|
|
1807
|
+
rows = [];
|
|
1808
|
+
current = -1;
|
|
1809
|
+
results.replaceChildren();
|
|
1810
|
+
input.setAttribute("aria-expanded", "false");
|
|
1811
|
+
input.removeAttribute?.("aria-activedescendant");
|
|
1812
|
+
}
|
|
924
1813
|
|
|
925
1814
|
async function run(text) {
|
|
926
1815
|
const mine = ++token;
|
|
927
|
-
|
|
928
|
-
|
|
1816
|
+
rows = [];
|
|
1817
|
+
current = -1;
|
|
1818
|
+
results.replaceChildren();
|
|
1819
|
+
if (!text.trim()) {
|
|
1820
|
+
input.setAttribute("aria-expanded", "false");
|
|
1821
|
+
return;
|
|
1822
|
+
}
|
|
1823
|
+
input.setAttribute("aria-expanded", "true");
|
|
929
1824
|
try {
|
|
930
1825
|
const answer = await ctx.api(`search?q=${encodeURIComponent(text.trim())}&limit=15`);
|
|
931
1826
|
if (mine !== token) return;
|
|
932
|
-
results.replaceChildren
|
|
1827
|
+
results.replaceChildren();
|
|
933
1828
|
if (!answer.hits.length) {
|
|
934
|
-
results.append(
|
|
1829
|
+
results.append(
|
|
1830
|
+
ctx.empty(
|
|
1831
|
+
`Nothing matches "${text.trim()}". Try a shorter word, or a file or route name.`,
|
|
1832
|
+
),
|
|
1833
|
+
);
|
|
935
1834
|
return;
|
|
936
1835
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1836
|
+
|
|
1837
|
+
const groups = new Map();
|
|
1838
|
+
|
|
1839
|
+
for (const hit of answer.hits) groups.set(hit.type, [...(groups.get(hit.type) ?? []), hit]);
|
|
1840
|
+
|
|
1841
|
+
for (const [type, hits] of groups) {
|
|
1842
|
+
const group = el(
|
|
1843
|
+
"div",
|
|
1844
|
+
{ class: "grimoire-hit-group", role: "group", "aria-label": type },
|
|
1845
|
+
[
|
|
1846
|
+
el("p", {
|
|
1847
|
+
class: "grimoire-hit-title",
|
|
1848
|
+
"aria-hidden": "true",
|
|
1849
|
+
text: `${type} (${hits.length})`,
|
|
1850
|
+
}),
|
|
1851
|
+
],
|
|
1852
|
+
);
|
|
1853
|
+
|
|
1854
|
+
for (const hit of hits) {
|
|
1855
|
+
const target = targetOf(hit.type, hit.id);
|
|
1856
|
+
const inner = [
|
|
1857
|
+
pill(ctx, hit.type),
|
|
1858
|
+
mono(ctx, hit.id),
|
|
1859
|
+
hit.detail ? muted(ctx, hit.detail) : "",
|
|
1860
|
+
];
|
|
1861
|
+
|
|
1862
|
+
if (target === null) {
|
|
1863
|
+
group.append(el("div", { class: "grimoire-hit is-plain" }, inner));
|
|
1864
|
+
continue;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
const node = el(
|
|
1868
|
+
"a",
|
|
1869
|
+
{
|
|
1870
|
+
href: ctx.href(target),
|
|
1871
|
+
class: "grimoire-hit",
|
|
1872
|
+
role: "option",
|
|
1873
|
+
id: `grimoire-hit-${rows.length}`,
|
|
1874
|
+
"aria-selected": "false",
|
|
1875
|
+
},
|
|
1876
|
+
inner,
|
|
1877
|
+
);
|
|
1878
|
+
|
|
1879
|
+
rows.push({ node, target });
|
|
1880
|
+
group.append(node);
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
results.append(group);
|
|
1884
|
+
}
|
|
951
1885
|
} catch (error) {
|
|
952
1886
|
if (mine === token)
|
|
953
|
-
results.append(
|
|
1887
|
+
results.append(
|
|
1888
|
+
el("p", {
|
|
1889
|
+
class: "grimoire-error-title",
|
|
1890
|
+
text: `Search failed: ${error.message}. Run warlock grimoire build, then search again.`,
|
|
1891
|
+
}),
|
|
1892
|
+
);
|
|
954
1893
|
}
|
|
955
1894
|
}
|
|
956
1895
|
|
|
957
1896
|
const input = el("input", {
|
|
958
1897
|
type: "search",
|
|
959
1898
|
class: "grimoire-search",
|
|
960
|
-
|
|
1899
|
+
role: "combobox",
|
|
1900
|
+
placeholder: "Search flows, blocks, routes, files and tasks (press /)",
|
|
961
1901
|
"aria-label": "Search the Grimoire",
|
|
1902
|
+
"aria-autocomplete": "list",
|
|
1903
|
+
"aria-expanded": "false",
|
|
1904
|
+
autocomplete: "off",
|
|
962
1905
|
oninput: (event) => {
|
|
963
1906
|
const text = event.target.value;
|
|
964
1907
|
if (timer !== null) clearTimeout(timer);
|
|
965
1908
|
timer = setTimeout(() => run(text), 150);
|
|
966
1909
|
},
|
|
1910
|
+
onkeydown: (event) => {
|
|
1911
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
1912
|
+
if (!rows.length) return;
|
|
1913
|
+
event.preventDefault?.();
|
|
1914
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
1915
|
+
highlight((current + step + rows.length) % rows.length);
|
|
1916
|
+
} else if (event.key === "Enter") {
|
|
1917
|
+
const row = rows[current] ?? rows[0];
|
|
1918
|
+
if (!row) return;
|
|
1919
|
+
event.preventDefault?.();
|
|
1920
|
+
ctx.navigate(row.target);
|
|
1921
|
+
} else if (event.key === "Escape") {
|
|
1922
|
+
if (timer !== null) clearTimeout(timer);
|
|
1923
|
+
input.value = "";
|
|
1924
|
+
clear();
|
|
1925
|
+
}
|
|
1926
|
+
},
|
|
967
1927
|
});
|
|
1928
|
+
|
|
968
1929
|
const nav = el(
|
|
969
1930
|
"nav",
|
|
970
|
-
{ class: "grimoire-
|
|
971
|
-
|
|
1931
|
+
{ class: "grimoire-tabs", "aria-label": "Grimoire" },
|
|
1932
|
+
TABS.map(([target, label]) => {
|
|
1933
|
+
const badge = el("span", { class: "grimoire-tab-count" });
|
|
1934
|
+
|
|
1935
|
+
badges.set(target, badge);
|
|
1936
|
+
return el(
|
|
1937
|
+
"a",
|
|
1938
|
+
{
|
|
1939
|
+
href: ctx.href(target),
|
|
1940
|
+
class: target === active ? "grimoire-tab is-active" : "grimoire-tab",
|
|
1941
|
+
...(target === active ? { "aria-current": "page" } : {}),
|
|
1942
|
+
},
|
|
1943
|
+
[label, " ", badge],
|
|
1944
|
+
);
|
|
1945
|
+
}),
|
|
1946
|
+
);
|
|
1947
|
+
|
|
1948
|
+
bindShortcut(input);
|
|
1949
|
+
|
|
1950
|
+
// The counts arrive with the summary; a view that does not need it still shows them.
|
|
1951
|
+
summaryRequest.then(
|
|
1952
|
+
(data) => {
|
|
1953
|
+
const set = (key, value) => {
|
|
1954
|
+
const badge = badges.get(key);
|
|
1955
|
+
if (badge && value !== undefined && value !== null) badge.textContent = String(value);
|
|
1956
|
+
};
|
|
1957
|
+
set("features", data.features?.features?.length);
|
|
1958
|
+
set("apps", data.apps?.apps);
|
|
1959
|
+
set("tasks", data.tasks ? data.tasks.open.length : undefined);
|
|
1960
|
+
set("releases", data.releases);
|
|
1961
|
+
set("check", data.counts ? data.counts.errors + data.counts.warnings : undefined);
|
|
1962
|
+
},
|
|
1963
|
+
() => undefined,
|
|
972
1964
|
);
|
|
973
1965
|
|
|
974
|
-
return {
|
|
1966
|
+
return {
|
|
1967
|
+
element: el("div", { class: "grimoire-header" }, [
|
|
1968
|
+
nav,
|
|
1969
|
+
el("div", { class: "grimoire-searchbox" }, [input, results]),
|
|
1970
|
+
]),
|
|
1971
|
+
run,
|
|
1972
|
+
input,
|
|
1973
|
+
};
|
|
975
1974
|
}
|
|
976
1975
|
|
|
977
1976
|
/** The context with `el()` flattening nested child lists and skipping empty ones. */
|
|
@@ -988,17 +1987,35 @@ function withFlatChildren(context) {
|
|
|
988
1987
|
async function renderGrimoire(context) {
|
|
989
1988
|
const ctx = withFlatChildren(context);
|
|
990
1989
|
const { root, el } = ctx;
|
|
1990
|
+
const route = ctx.route ?? "";
|
|
1991
|
+
|
|
991
1992
|
if (typeof ctx.asset === "function")
|
|
992
1993
|
root.append(el("link", { rel: "stylesheet", href: ctx.asset("grimoire.css") }));
|
|
993
|
-
const top = header(ctx);
|
|
994
|
-
const content = el("div", { class: "grimoire-body" });
|
|
995
|
-
root.append(top.element, content);
|
|
996
1994
|
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1995
|
+
// The tab counts and the overview share one summary request.
|
|
1996
|
+
const summaryRequest = Promise.resolve().then(() => ctx.api("summary"));
|
|
1997
|
+
|
|
1998
|
+
summaryRequest.catch(() => undefined);
|
|
1999
|
+
|
|
2000
|
+
const top = header(ctx, route, summaryRequest);
|
|
2001
|
+
const content = el("div", { class: "grimoire-body", "aria-busy": "true" });
|
|
2002
|
+
|
|
2003
|
+
content.append(skeleton(ctx));
|
|
2004
|
+
root.append(el("div", { class: "grimoire-root" }, [top.element, content]));
|
|
2005
|
+
|
|
2006
|
+
const loaded = (async () => {
|
|
2007
|
+
try {
|
|
2008
|
+
content.replaceChildren(await body(ctx, summaryRequest));
|
|
2009
|
+
} catch (error) {
|
|
2010
|
+
content.replaceChildren(errorBox(ctx, route, error));
|
|
2011
|
+
}
|
|
2012
|
+
content.setAttribute("aria-busy", "false");
|
|
2013
|
+
})();
|
|
2014
|
+
|
|
2015
|
+
// A quick answer is shown filled in; a slow one hands back the skeleton at once and fills in later.
|
|
2016
|
+
await (typeof setTimeout === "function"
|
|
2017
|
+
? Promise.race([loaded, new Promise((resolve) => setTimeout(resolve, SKELETON_AFTER))])
|
|
2018
|
+
: loaded);
|
|
1002
2019
|
return root;
|
|
1003
2020
|
}
|
|
1004
2021
|
|