astralis-devtools 0.1.0 → 0.3.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 +52 -1
- package/README.md +88 -82
- package/package.json +2 -2
- package/src/bridge/github.mjs +2 -2
- package/src/bridge/http.mjs +194 -194
- package/src/bridge/snapshot.mjs +70 -71
- package/src/client/icons.mjs +43 -44
- package/src/client/launcher.mjs +143 -142
- package/src/client/overlay.mjs +583 -525
- package/src/client/page.mjs +7 -0
- package/src/client/props.mjs +154 -0
- package/src/client/report.mjs +2 -42
- package/src/client/screens/component.mjs +158 -151
- package/src/client/screens/home.mjs +100 -100
- package/src/client/screens/props.mjs +192 -0
- package/src/client/screens/report.mjs +97 -85
- package/src/client/screens/shared.mjs +1 -1
- package/src/client/styles.mjs +34 -5
|
@@ -1,100 +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
|
|
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
|
-
}
|
|
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
|
+
}
|