astralis-devtools 0.0.0-stage → 0.2.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 +71 -0
- package/LICENSE +21 -0
- package/README.md +86 -3
- package/package.json +66 -3
- package/src/bridge/bridge.mjs +169 -0
- package/src/bridge/github.mjs +139 -0
- package/src/bridge/http.mjs +194 -0
- package/src/bridge/node-adapter.mjs +68 -0
- package/src/bridge/project.mjs +103 -0
- package/src/bridge/snapshot.mjs +70 -0
- package/src/client/dom.mjs +82 -0
- package/src/client/fonts/OFL.txt +94 -0
- package/src/client/fonts.mjs +22 -0
- package/src/client/icons.mjs +43 -0
- package/src/client/identity.mjs +117 -0
- package/src/client/launcher.mjs +143 -0
- package/src/client/overlay.d.mts +9 -0
- package/src/client/overlay.mjs +529 -0
- package/src/client/page.mjs +92 -0
- package/src/client/picker.mjs +118 -0
- package/src/client/props.mjs +154 -0
- package/src/client/report.mjs +121 -0
- package/src/client/screens/component.mjs +158 -0
- package/src/client/screens/components.mjs +117 -0
- package/src/client/screens/findings.mjs +92 -0
- package/src/client/screens/home.mjs +100 -0
- package/src/client/screens/props.mjs +192 -0
- package/src/client/screens/report.mjs +459 -0
- package/src/client/screens/shared.mjs +59 -0
- package/src/client/styles.mjs +541 -0
- package/src/next/devtools.d.mts +6 -0
- package/src/next/devtools.mjs +32 -0
- package/src/next/route.d.mts +10 -0
- package/src/next/route.mjs +17 -0
- package/src/vite.d.mts +12 -0
- package/src/vite.mjs +59 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { h, icon, plural } from "../dom.mjs";
|
|
2
|
+
import { describeComponent } from "../identity.mjs";
|
|
3
|
+
import { ICONS } from "../icons.mjs";
|
|
4
|
+
import { findingsForGroup, groupByComponent, instanceLabel } from "../page.mjs";
|
|
5
|
+
import { empty } from "./shared.mjs";
|
|
6
|
+
|
|
7
|
+
/* Components: every astralis-ui component on the page, grouped by what it is.
|
|
8
|
+
Hovering an instance outlines it on the page; choosing one opens its page. */
|
|
9
|
+
|
|
10
|
+
export function componentsScreen(app) {
|
|
11
|
+
const input = h("input", { type: "search", placeholder: "Filter components", "aria-label": "Filter components", autocomplete: "off", spellcheck: "false" });
|
|
12
|
+
const list = h("div", { class: "list", role: "list" });
|
|
13
|
+
const open = new Set(); // groups the reader expanded
|
|
14
|
+
let query = "";
|
|
15
|
+
|
|
16
|
+
input.addEventListener("input", () => {
|
|
17
|
+
query = input.value.trim().toLowerCase();
|
|
18
|
+
update();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
function groupView(group) {
|
|
22
|
+
const { state } = app;
|
|
23
|
+
const about = describeComponent(state.spec, group.name, app.framework);
|
|
24
|
+
const counts = findingsForGroup(group, state.findings, state.routeFiles);
|
|
25
|
+
const single = group.instances.length === 1;
|
|
26
|
+
const expanded = open.has(group.name) || (query && group.instances.length <= 6);
|
|
27
|
+
|
|
28
|
+
const row = h(
|
|
29
|
+
"button",
|
|
30
|
+
{
|
|
31
|
+
class: "group-row",
|
|
32
|
+
type: "button",
|
|
33
|
+
"aria-expanded": single ? null : String(Boolean(expanded)),
|
|
34
|
+
onclick: (event) => {
|
|
35
|
+
if (single) return app.openComponent(group.instances[0].element);
|
|
36
|
+
// Toggled in place, so the instances slide open rather than appear.
|
|
37
|
+
const now = !open.has(group.name);
|
|
38
|
+
if (now) open.add(group.name);
|
|
39
|
+
else open.delete(group.name);
|
|
40
|
+
event.currentTarget.setAttribute("aria-expanded", String(now));
|
|
41
|
+
event.currentTarget.parentElement.dataset.open = String(now);
|
|
42
|
+
},
|
|
43
|
+
onpointerenter: () => single && app.preview(group.instances[0].element),
|
|
44
|
+
onpointerleave: () => single && app.preview(null),
|
|
45
|
+
},
|
|
46
|
+
icon(ICONS.chevron, "icon chev"),
|
|
47
|
+
h("span", { class: `tier-dot ${about.client ?? ""}`, title: about.clientLabel ?? "" }),
|
|
48
|
+
h("span", { class: "name grow" }, group.name),
|
|
49
|
+
counts.errors ? h("span", { class: "mini error", title: plural(counts.errors, "finding") }, h("i"), String(counts.errors)) : null,
|
|
50
|
+
counts.warnings ? h("span", { class: "mini advice", title: plural(counts.warnings, "recommendation") }, h("i"), String(counts.warnings)) : null,
|
|
51
|
+
h("span", { class: "n-pill" }, String(group.instances.length)),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const instances = single
|
|
55
|
+
? null
|
|
56
|
+
: h(
|
|
57
|
+
"div",
|
|
58
|
+
{ class: "instances" },
|
|
59
|
+
h(
|
|
60
|
+
"div",
|
|
61
|
+
{},
|
|
62
|
+
h(
|
|
63
|
+
"div",
|
|
64
|
+
{ class: "list" },
|
|
65
|
+
group.instances.map((instance, index) => {
|
|
66
|
+
const { text, props } = instanceLabel(instance);
|
|
67
|
+
return h(
|
|
68
|
+
"button",
|
|
69
|
+
{
|
|
70
|
+
class: "instance-row",
|
|
71
|
+
type: "button",
|
|
72
|
+
onclick: () => app.openComponent(instance.element),
|
|
73
|
+
onpointerenter: () => app.preview(instance.element),
|
|
74
|
+
onpointerleave: () => app.preview(null),
|
|
75
|
+
},
|
|
76
|
+
h("span", { class: "idx" }, `#${index + 1}`),
|
|
77
|
+
text ? h("span", { class: "text" }, text) : null,
|
|
78
|
+
h("span", { class: "props grow" }, props),
|
|
79
|
+
icon(ICONS.arrow, "icon go"),
|
|
80
|
+
);
|
|
81
|
+
}),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
);
|
|
85
|
+
return h("div", { class: "group", role: "listitem", "data-open": String(Boolean(expanded) && !single) }, row, instances);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function update() {
|
|
89
|
+
const { state } = app;
|
|
90
|
+
if (!state.instances.length) {
|
|
91
|
+
list.replaceChildren(
|
|
92
|
+
empty(ICONS.components, "No components on this page", "Components from astralis-ui show up here as they render, Server Components included.", { neutral: true }),
|
|
93
|
+
);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const groups = groupByComponent(state.instances).filter((g) => !query || g.name.toLowerCase().includes(query));
|
|
97
|
+
list.replaceChildren(
|
|
98
|
+
...(groups.length ? groups.map(groupView) : [empty(ICONS.search, "No matches", `Nothing on this page is called “${input.value}”.`, { neutral: true })]),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const root = h(
|
|
103
|
+
"div",
|
|
104
|
+
{},
|
|
105
|
+
h("label", { class: "search" }, icon(ICONS.search), input),
|
|
106
|
+
list,
|
|
107
|
+
h(
|
|
108
|
+
"div",
|
|
109
|
+
{ class: "legend" },
|
|
110
|
+
h("span", {}, h("span", { class: "tier-dot none" }), "Server Component"),
|
|
111
|
+
h("span", {}, h("span", { class: "tier-dot leaf" }), "Server shell, client island"),
|
|
112
|
+
h("span", {}, h("span", { class: "tier-dot required" }), "Client Component"),
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
update();
|
|
116
|
+
return { title: [{ label: "Components" }], root, update, focus: () => input.focus({ preventScroll: true }) };
|
|
117
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { filePath, h, icon, plural } from "../dom.mjs";
|
|
2
|
+
import { ICONS } from "../icons.mjs";
|
|
3
|
+
import { bridgeMissing, empty, findingRow } from "./shared.mjs";
|
|
4
|
+
|
|
5
|
+
/* Findings and Recommendations: the validator's results for the project,
|
|
6
|
+
live, with the files that render the current page first. Findings are its
|
|
7
|
+
errors, the things that render wrong or not at all; Recommendations are its
|
|
8
|
+
warnings, the things that work but could be better. */
|
|
9
|
+
|
|
10
|
+
const KINDS = {
|
|
11
|
+
findings: {
|
|
12
|
+
title: "Findings",
|
|
13
|
+
key: "errors",
|
|
14
|
+
tone: "error",
|
|
15
|
+
one: "error",
|
|
16
|
+
icon: ICONS.findings,
|
|
17
|
+
clean: ["Nothing broken", "Every file renders the way it is written."],
|
|
18
|
+
cleanPage: (n) => (n === 1 ? "Nothing broken in the file that renders this page." : `Nothing broken in the ${n} files that render this page.`),
|
|
19
|
+
},
|
|
20
|
+
recommendations: {
|
|
21
|
+
title: "Recommendations",
|
|
22
|
+
key: "warnings",
|
|
23
|
+
tone: "advice",
|
|
24
|
+
one: "recommendation",
|
|
25
|
+
icon: ICONS.recommendations,
|
|
26
|
+
clean: ["Nothing to suggest", "The validator has no advice for this project."],
|
|
27
|
+
cleanPage: (n) => (n === 1 ? "Nothing to suggest in the file that renders this page." : `Nothing to suggest in the ${n} files that render this page.`),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function findingsScreen(app, which) {
|
|
32
|
+
const kind = KINDS[which];
|
|
33
|
+
const root = h("div", {});
|
|
34
|
+
|
|
35
|
+
function fileCard(result) {
|
|
36
|
+
const list = result[kind.key].map((finding) => ({ ...finding, file: result.file, kind: kind.key === "errors" ? "error" : "warning" }));
|
|
37
|
+
return h(
|
|
38
|
+
"div",
|
|
39
|
+
{ class: "file-card" },
|
|
40
|
+
h("div", { class: "file-head" }, icon(ICONS.file), h("span", { class: "grow" }, filePath(result.file)), h("span", { class: "n-pill" }, String(list.length))),
|
|
41
|
+
list.map((finding) => findingRow(app, finding)),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function update() {
|
|
46
|
+
const { state } = app;
|
|
47
|
+
const findings = state.findings;
|
|
48
|
+
if (state.bridge === "unreachable" && !findings) return root.replaceChildren(bridgeMissing(app));
|
|
49
|
+
if (!findings) {
|
|
50
|
+
return root.replaceChildren(h("div", { class: "stack" }, h("div", { class: "skeleton", style: "width:40%" }), h("div", { class: "skeleton" }), h("div", { class: "skeleton", style: "width:70%" })));
|
|
51
|
+
}
|
|
52
|
+
if (findings.problem) return root.replaceChildren(h("div", { class: "notice" }, findings.problem));
|
|
53
|
+
|
|
54
|
+
const count = findings[kind.key];
|
|
55
|
+
const withAny = findings.results.filter((r) => r[kind.key].length);
|
|
56
|
+
const summary = h(
|
|
57
|
+
"div",
|
|
58
|
+
{ class: `summary ${count ? kind.tone : ""}` },
|
|
59
|
+
h("div", { class: "summary-value" }, String(count)),
|
|
60
|
+
h(
|
|
61
|
+
"div",
|
|
62
|
+
{ class: "summary-text grow" },
|
|
63
|
+
h("strong", {}, count === 1 ? kind.one[0].toUpperCase() + kind.one.slice(1) : `${kind.one[0].toUpperCase() + kind.one.slice(1)}s`),
|
|
64
|
+
`in ${withAny.length} of ${plural(findings.files, "file")} checked`,
|
|
65
|
+
state.bridge === "unreachable" ? " · reconnecting…" : "",
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
if (!count) {
|
|
69
|
+
return root.replaceChildren(summary, empty(ICONS.check, kind.clean[0], kind.clean[1]));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const onPage = state.routeFiles;
|
|
73
|
+
const byFile = new Map(withAny.map((result) => [result.file, result]));
|
|
74
|
+
const pageFiles = onPage.filter((file) => byFile.has(file));
|
|
75
|
+
const pageSection = onPage.length
|
|
76
|
+
? h(
|
|
77
|
+
"section",
|
|
78
|
+
{},
|
|
79
|
+
h("h3", { class: "section-title" }, "This page"),
|
|
80
|
+
pageFiles.length ? pageFiles.map((file) => fileCard(byFile.get(file))) : h("p", { class: "muted", style: "margin-bottom:16px" }, kind.cleanPage(onPage.length)),
|
|
81
|
+
)
|
|
82
|
+
: null;
|
|
83
|
+
const rest = withAny.filter((result) => !onPage.includes(result.file));
|
|
84
|
+
const restSection = rest.length
|
|
85
|
+
? h("section", {}, onPage.length ? h("h3", { class: "section-title" }, "Elsewhere in the project") : null, rest.map(fileCard))
|
|
86
|
+
: null;
|
|
87
|
+
root.replaceChildren(...[summary, pageSection, restSection].filter(Boolean));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
update();
|
|
91
|
+
return { title: [{ label: kind.title }], root, update };
|
|
92
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { countUp, h, icon, plural } from "../dom.mjs";
|
|
2
|
+
import { ICONS, MARK } from "../icons.mjs";
|
|
3
|
+
|
|
4
|
+
/* Home: what the DevTools sees on this page, at a glance, with a way into
|
|
5
|
+
each of the other screens. */
|
|
6
|
+
|
|
7
|
+
const FRAMEWORKS = { next: "Next.js", vite: "Vite" };
|
|
8
|
+
|
|
9
|
+
export function homeScreen(app) {
|
|
10
|
+
const meta = h("p", {});
|
|
11
|
+
const tiles = h("div", { class: "tiles" });
|
|
12
|
+
|
|
13
|
+
const tile = (screen, iconMarkup, label, withValue) => {
|
|
14
|
+
const value = withValue ? h("div", { class: "tile-value" }, "–") : null;
|
|
15
|
+
const sub = h("div", { class: "tile-sub" });
|
|
16
|
+
const element = h(
|
|
17
|
+
"button",
|
|
18
|
+
{ class: "tile", type: "button", "data-screen": screen, onclick: () => app.navigate(screen) },
|
|
19
|
+
h("div", { class: "tile-head" }, h("span", { class: "tile-icon" }, icon(iconMarkup)), icon(ICONS.arrow, "icon tile-arrow")),
|
|
20
|
+
h("div", {}, value, h("div", { class: "tile-label" }, label), sub),
|
|
21
|
+
);
|
|
22
|
+
// The card's glow follows the pointer.
|
|
23
|
+
element.addEventListener("pointermove", (event) => {
|
|
24
|
+
const rect = element.getBoundingClientRect();
|
|
25
|
+
element.style.setProperty("--mx", `${event.clientX - rect.left}px`);
|
|
26
|
+
element.style.setProperty("--my", `${event.clientY - rect.top}px`);
|
|
27
|
+
});
|
|
28
|
+
tiles.append(element);
|
|
29
|
+
let shown = null;
|
|
30
|
+
return {
|
|
31
|
+
set(number, text, tone = "") {
|
|
32
|
+
element.className = `tile ${tone}`.trim();
|
|
33
|
+
sub.textContent = text;
|
|
34
|
+
if (!value) return;
|
|
35
|
+
value.hidden = number === undefined;
|
|
36
|
+
if (typeof number !== "number") value.textContent = "–";
|
|
37
|
+
else if (shown === null) countUp(value, number);
|
|
38
|
+
else value.textContent = String(number);
|
|
39
|
+
shown = typeof number === "number" ? number : null;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const components = tile("components", ICONS.components, "Components", true);
|
|
44
|
+
const errorsTile = tile("findings", ICONS.findings, "Findings", true);
|
|
45
|
+
const warningsTile = tile("recommendations", ICONS.recommendations, "Recommendations", true);
|
|
46
|
+
const reportTile = tile("report", ICONS.report, "Report a problem", true);
|
|
47
|
+
|
|
48
|
+
function update() {
|
|
49
|
+
const { state } = app;
|
|
50
|
+
const info = state.info;
|
|
51
|
+
const framework = info?.framework?.name ?? app.framework;
|
|
52
|
+
meta.textContent = [
|
|
53
|
+
info?.library ? `astralis-ui ${info.library.version}` : "astralis-ui",
|
|
54
|
+
framework ? `${FRAMEWORKS[framework] ?? framework}${info?.framework?.version ? ` ${info.framework.version}` : ""}` : null,
|
|
55
|
+
info?.react ? `React ${info.react}` : null,
|
|
56
|
+
]
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.join(" · ");
|
|
59
|
+
|
|
60
|
+
const issues = state.issues.list;
|
|
61
|
+
if (state.github?.login && issues) {
|
|
62
|
+
const open = issues.filter((i) => i.state === "open").length;
|
|
63
|
+
reportTile.set(open, `Your issues: ${open} open, ${issues.length - open} closed`);
|
|
64
|
+
} else {
|
|
65
|
+
reportTile.set(undefined, state.github?.login ? `Signed in as ${state.github.login}` : "Open a GitHub issue with the evidence");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const kinds = new Set(state.instances.map((i) => i.name)).size;
|
|
69
|
+
components.set(state.instances.length, state.instances.length ? `${plural(kinds, "kind")} on this page` : "None on this page yet");
|
|
70
|
+
|
|
71
|
+
const findings = state.findings;
|
|
72
|
+
if (!findings || findings.problem) {
|
|
73
|
+
const text = findings?.problem ? "Unavailable" : state.bridge === "unreachable" ? "Bridge not answering" : "Validating…";
|
|
74
|
+
errorsTile.set(null, text);
|
|
75
|
+
warningsTile.set(null, text);
|
|
76
|
+
} else {
|
|
77
|
+
const withErrors = findings.results.filter((r) => r.errors.length).length;
|
|
78
|
+
const withWarnings = findings.results.filter((r) => r.warnings.length).length;
|
|
79
|
+
errorsTile.set(findings.errors, findings.errors ? `in ${withErrors} of ${plural(findings.files, "file")}` : "Nothing broken", findings.errors ? "error" : "clean");
|
|
80
|
+
warningsTile.set(findings.warnings, findings.warnings ? `in ${withWarnings} of ${plural(findings.files, "file")}` : "Nothing to suggest", findings.warnings ? "advice" : "clean");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const mark = h("div", { class: "hero-mark" });
|
|
85
|
+
mark.innerHTML = MARK;
|
|
86
|
+
const root = h(
|
|
87
|
+
"div",
|
|
88
|
+
{},
|
|
89
|
+
h("div", { class: "hero" }, mark, h("div", {}, h("h1", {}, "Astralis ", h("span", {}, "DevTools")), meta)),
|
|
90
|
+
tiles,
|
|
91
|
+
h(
|
|
92
|
+
"div",
|
|
93
|
+
{ class: "shortcuts" },
|
|
94
|
+
h("span", { class: "shortcut" }, h("span", { class: "kbd" }, "Shift"), h("span", { class: "kbd" }, "Alt"), h("span", { class: "kbd" }, "A"), h("span", {}, "Open or minimize")),
|
|
95
|
+
h("span", { class: "shortcut" }, h("span", { class: "kbd" }, "Shift"), h("span", { class: "kbd" }, "Alt"), h("span", { class: "kbd" }, "C"), h("span", {}, "Pick a component")),
|
|
96
|
+
),
|
|
97
|
+
);
|
|
98
|
+
update();
|
|
99
|
+
return { title: [{ label: "Home" }], root, update };
|
|
100
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { contentOf } from "astralis-cli/snapshot";
|
|
2
|
+
import { formatValue, h, icon } from "../dom.mjs";
|
|
3
|
+
import { ICONS } from "../icons.mjs";
|
|
4
|
+
import { filterProps, propsModel } from "../props.mjs";
|
|
5
|
+
|
|
6
|
+
/* Every prop a component takes, from the spec, with a search over names and
|
|
7
|
+
values. The first section is open; each other group opens on demand and is
|
|
8
|
+
drawn only then, so a Box's hundred props cost nothing until asked for. */
|
|
9
|
+
|
|
10
|
+
/** How many values a row shows before "+N more". */
|
|
11
|
+
const SHOWN_VALUES = 8;
|
|
12
|
+
|
|
13
|
+
const ARBITRARY = { length: "any length", color: "any colour", shadow: "any shadow", number: "any number", integer: "any whole number" };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The components on the element the page itself wrote: "Modal.Trigger Button"
|
|
17
|
+
* is both (a Trigger takes one element), "Heading Text" is only the Heading.
|
|
18
|
+
*/
|
|
19
|
+
function written(spec, chain) {
|
|
20
|
+
let end = 1;
|
|
21
|
+
while (end < chain.length && contentOf(spec, chain[end - 1].name) === "element") end++;
|
|
22
|
+
return chain.slice(0, end);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function allProps(app, chain) {
|
|
26
|
+
const input = h("input", { type: "search", placeholder: "Search props or values", "aria-label": "Search props or values", autocomplete: "off", spellcheck: "false" });
|
|
27
|
+
const search = h("label", { class: "search" }, icon(ICONS.search), input);
|
|
28
|
+
const which = h("div", { class: "segmented", role: "group", "aria-label": "Component", style: "margin:0 0 10px" });
|
|
29
|
+
const body = h("div", { class: "prop-groups" });
|
|
30
|
+
const count = h("span", { class: "n" });
|
|
31
|
+
const root = h("section", {}, h("h3", { class: "section-title" }, "Props it takes", count), which, search, body);
|
|
32
|
+
|
|
33
|
+
const opened = new Map(); // section id -> open, once the reader has toggled it
|
|
34
|
+
const moreShown = new Set(); // rows whose whole value list the reader opened, by section and name
|
|
35
|
+
let chosen = 0;
|
|
36
|
+
let spec = null;
|
|
37
|
+
let mine = chain.slice(0, 1);
|
|
38
|
+
let model = null;
|
|
39
|
+
let query = "";
|
|
40
|
+
|
|
41
|
+
input.addEventListener("input", () => {
|
|
42
|
+
query = input.value;
|
|
43
|
+
draw();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
function valueList(section, row) {
|
|
47
|
+
const id = `${section.id}/${row.name}`;
|
|
48
|
+
const all = row.byValue || moreShown.has(id) || row.values.length <= SHOWN_VALUES + 1;
|
|
49
|
+
const shown = all ? row.values : row.values.slice(0, SHOWN_VALUES);
|
|
50
|
+
const usedValue = row.used && typeof row.used.value !== "object" ? String(row.used.value) : null;
|
|
51
|
+
const q = query.trim().toLowerCase();
|
|
52
|
+
const parts = shown.map((value) =>
|
|
53
|
+
h("span", { class: `val${value === usedValue ? " on" : ""}${row.byValue && q && value.toLowerCase().includes(q) ? " hit" : ""}` }, value),
|
|
54
|
+
);
|
|
55
|
+
if (!all) {
|
|
56
|
+
parts.push(
|
|
57
|
+
h(
|
|
58
|
+
"button",
|
|
59
|
+
{
|
|
60
|
+
class: "val more",
|
|
61
|
+
type: "button",
|
|
62
|
+
"aria-label": `Show all ${row.values.length} values of ${row.name}`,
|
|
63
|
+
onclick: (event) => {
|
|
64
|
+
moreShown.add(id);
|
|
65
|
+
const list = valueList(section, row);
|
|
66
|
+
list.tabIndex = -1;
|
|
67
|
+
event.currentTarget.closest(".prop-values").replaceWith(list);
|
|
68
|
+
list.focus();
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
`+${row.values.length - SHOWN_VALUES} more`,
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (row.arbitrary) parts.push(h("span", { class: "faint" }, `or ${ARBITRARY[row.arbitrary] ?? `any ${row.arbitrary}`}`));
|
|
76
|
+
return h("div", { class: "prop-values" }, parts);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function rowView(section, row) {
|
|
80
|
+
return h(
|
|
81
|
+
"div",
|
|
82
|
+
{ class: `prop-row${row.used ? " used" : ""}`, role: "listitem" },
|
|
83
|
+
h(
|
|
84
|
+
"div",
|
|
85
|
+
{ class: "prop-head" },
|
|
86
|
+
h("span", { class: "prop-name" }, row.name),
|
|
87
|
+
row.aliases.length ? h("span", { class: "prop-alias" }, row.aliases.join(", ")) : null,
|
|
88
|
+
row.type && !row.values.length ? h("span", { class: "prop-type" }, row.type) : null,
|
|
89
|
+
row.required ? h("span", { class: "pill error" }, "Required") : null,
|
|
90
|
+
row.used ? h("span", { class: "pill in-use", title: `This one has ${row.used.as}=${formatValue(row.used.value)}` }, `In use: ${formatValue(row.used.value)}`) : null,
|
|
91
|
+
),
|
|
92
|
+
row.description ? h("p", { class: "prop-doc" }, row.description) : null,
|
|
93
|
+
row.default ? h("p", { class: "prop-default" }, "Default: ", h("span", { class: "code" }, row.default)) : null,
|
|
94
|
+
row.note ? h("p", { class: "prop-doc faint" }, row.note) : null,
|
|
95
|
+
row.values.length || row.arbitrary ? valueList(section, row) : null,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The first section starts open (its own props, or its first group); the rest wait to be asked for. */
|
|
100
|
+
function sectionView(section, first, searching) {
|
|
101
|
+
const expanded = searching || (opened.get(section.id) ?? first);
|
|
102
|
+
const used = section.rows.filter((row) => row.used).length;
|
|
103
|
+
const rows = h("div", { class: "prop-rows", role: "list" });
|
|
104
|
+
const fill = () => rows.childElementCount || rows.append(...section.rows.map((row) => rowView(section, row)));
|
|
105
|
+
if (expanded) fill();
|
|
106
|
+
const wrap = h("div", { class: "group prop-group", "data-open": String(expanded) });
|
|
107
|
+
// A closed group only looks empty: inert keeps its rows out of the tab order too.
|
|
108
|
+
const body = h("div", { class: "instances", inert: !expanded }, h("div", {}, rows));
|
|
109
|
+
const head = h(
|
|
110
|
+
"button",
|
|
111
|
+
{
|
|
112
|
+
class: "group-row",
|
|
113
|
+
type: "button",
|
|
114
|
+
"aria-expanded": String(expanded),
|
|
115
|
+
onclick: () => {
|
|
116
|
+
const now = wrap.dataset.open !== "true";
|
|
117
|
+
opened.set(section.id, now);
|
|
118
|
+
if (now) fill();
|
|
119
|
+
head.setAttribute("aria-expanded", String(now));
|
|
120
|
+
wrap.dataset.open = String(now);
|
|
121
|
+
body.inert = !now;
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
icon(ICONS.chevron, "icon chev"),
|
|
125
|
+
h("span", { class: "group-label" }, section.label),
|
|
126
|
+
h("span", { class: "group-hint grow" }, section.inferred ? "listed by the spec outside its groups" : section.hint),
|
|
127
|
+
used ? h("span", { class: "mini in-use", title: `${used} in use here` }, h("i"), `${used} in use`) : null,
|
|
128
|
+
h("span", { class: "n-pill" }, String(section.rows.length)),
|
|
129
|
+
);
|
|
130
|
+
wrap.append(head, body);
|
|
131
|
+
return wrap;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function draw() {
|
|
135
|
+
which.hidden = mine.length < 2;
|
|
136
|
+
which.replaceChildren(
|
|
137
|
+
...mine.map(({ name }, index) =>
|
|
138
|
+
h(
|
|
139
|
+
"button",
|
|
140
|
+
{
|
|
141
|
+
type: "button",
|
|
142
|
+
"aria-pressed": String(index === chosen),
|
|
143
|
+
onclick: () => {
|
|
144
|
+
if (index === chosen) return;
|
|
145
|
+
chosen = index;
|
|
146
|
+
model = null;
|
|
147
|
+
draw();
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
name,
|
|
151
|
+
),
|
|
152
|
+
),
|
|
153
|
+
);
|
|
154
|
+
if (!spec) {
|
|
155
|
+
count.textContent = "";
|
|
156
|
+
search.hidden = true;
|
|
157
|
+
body.replaceChildren(h("div", { class: "skeleton", style: "width:60%" }));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
model ??= propsModel(spec, mine[chosen].name, mine[chosen].props);
|
|
161
|
+
if (!model) {
|
|
162
|
+
count.textContent = "";
|
|
163
|
+
search.hidden = true;
|
|
164
|
+
body.replaceChildren(h("p", { class: "muted" }, `${mine[chosen].name} is not in the installed spec, so its props cannot be listed.`));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
search.hidden = false;
|
|
168
|
+
const searching = Boolean(query.trim());
|
|
169
|
+
const found = filterProps(model, query);
|
|
170
|
+
count.textContent = searching ? `${found.count} of ${model.total}` : String(model.total);
|
|
171
|
+
body.replaceChildren(
|
|
172
|
+
...(found.sections.length
|
|
173
|
+
? found.sections.map((section, index) => sectionView(section, index === 0, searching))
|
|
174
|
+
: [h("p", { class: "muted" }, model.total ? `No prop or value matches "${query.trim()}".` : "It takes no props the spec describes.")]),
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
draw();
|
|
179
|
+
return {
|
|
180
|
+
root,
|
|
181
|
+
/** Redraw when the spec arrives or changes; the search and what is open are kept. */
|
|
182
|
+
update() {
|
|
183
|
+
if (app.state.spec === spec) return;
|
|
184
|
+
spec = app.state.spec;
|
|
185
|
+
mine = spec ? written(spec, chain) : chain.slice(0, 1);
|
|
186
|
+
chosen = Math.min(chosen, mine.length - 1);
|
|
187
|
+
model = null;
|
|
188
|
+
draw();
|
|
189
|
+
},
|
|
190
|
+
input,
|
|
191
|
+
};
|
|
192
|
+
}
|