astralis-devtools 0.1.0 → 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 +37 -1
- package/README.md +86 -82
- package/package.json +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 +529 -525
- 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 +18 -57
- 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
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { h, icon, plural } from "../dom.mjs";
|
|
2
2
|
import { readIdentity } from "../identity.mjs";
|
|
3
3
|
import { GITHUB_MARK, ICONS } from "../icons.mjs";
|
|
4
|
-
import { browserEnvironment,
|
|
4
|
+
import { browserEnvironment, treeFromElement } from "../report.mjs";
|
|
5
5
|
import { empty } from "./shared.mjs";
|
|
6
6
|
|
|
7
7
|
/* Report: a problem sent to the maintainers as a GitHub issue, opened from
|
|
@@ -10,7 +10,8 @@ import { empty } from "./shared.mjs";
|
|
|
10
10
|
A report is an issue snapshot of one component and everything inside it.
|
|
11
11
|
The exact JSON is shown before anything is sent, and nothing is sent until
|
|
12
12
|
the reporter presses Send. The form keeps its input across screens and
|
|
13
|
-
while findings stream in.
|
|
13
|
+
while findings stream in. Pictures and files are added on GitHub, in the
|
|
14
|
+
issue itself: its API cannot attach them. */
|
|
14
15
|
|
|
15
16
|
/** The form for a new report. */
|
|
16
17
|
function newReport(app) {
|
|
@@ -36,14 +37,6 @@ function newReport(app) {
|
|
|
36
37
|
let timer = null;
|
|
37
38
|
let request = 0;
|
|
38
39
|
|
|
39
|
-
/** The JSON as shown: exact, except that a screenshot's data is summarised (it is shown as an image). */
|
|
40
|
-
function previewText(snapshot) {
|
|
41
|
-
const shown = snapshot.screenshot
|
|
42
|
-
? { ...snapshot, screenshot: `data:image/jpeg;base64,… (${Math.round((snapshot.screenshot.length * 0.75) / 1024)} kB, shown above)` }
|
|
43
|
-
: snapshot;
|
|
44
|
-
return JSON.stringify(shown, null, 2);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
40
|
function schedule() {
|
|
48
41
|
clearTimeout(timer);
|
|
49
42
|
timer = setTimeout(assemble, 250);
|
|
@@ -58,9 +51,8 @@ function newReport(app) {
|
|
|
58
51
|
route: location.pathname,
|
|
59
52
|
environment: browserEnvironment(window),
|
|
60
53
|
description: { title: r.title, happened: r.happened, expected: r.expected },
|
|
61
|
-
include: { findings: r.includeFindings, console: r.includeConsole
|
|
54
|
+
include: { findings: r.includeFindings, console: r.includeConsole },
|
|
62
55
|
console: [...app.consoleErrors.messages],
|
|
63
|
-
...(r.screenshot ? { screenshot: r.screenshot } : {}),
|
|
64
56
|
};
|
|
65
57
|
try {
|
|
66
58
|
const response = await fetch(`${app.base}/snapshot`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
|
|
@@ -109,7 +101,6 @@ function newReport(app) {
|
|
|
109
101
|
r.number = result.number;
|
|
110
102
|
r.added = Boolean(addTo);
|
|
111
103
|
r.similar = null;
|
|
112
|
-
window.open(result.url, "_blank", "noopener");
|
|
113
104
|
app.github.loadIssues();
|
|
114
105
|
} catch (error) {
|
|
115
106
|
r.status = "failed";
|
|
@@ -148,34 +139,12 @@ function newReport(app) {
|
|
|
148
139
|
const result = await response.json();
|
|
149
140
|
if (!response.ok) throw new Error(result?.error ?? `The bridge answered ${response.status}.`);
|
|
150
141
|
window.open(result.url, "_blank", "noopener");
|
|
151
|
-
notice(
|
|
152
|
-
r.screenshot
|
|
153
|
-
? "GitHub's form is open in a new tab: check it, drop the screenshot in, and press Create."
|
|
154
|
-
: "GitHub's form is open in a new tab: check it and press Create.",
|
|
155
|
-
);
|
|
142
|
+
notice("GitHub's form is open in a new tab: check it, add any picture or file there, and press Create.");
|
|
156
143
|
} catch (error) {
|
|
157
144
|
notice(`${error.message} Copy JSON or Download keeps the snapshot.`);
|
|
158
145
|
}
|
|
159
146
|
}
|
|
160
147
|
|
|
161
|
-
/** GitHub's API cannot attach images, so a screenshot is saved for the reporter to drop into the issue. */
|
|
162
|
-
function downloadScreenshot() {
|
|
163
|
-
h("a", { href: r.screenshot, download: "astralis-screenshot.jpg" }).click();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async function addScreenshot() {
|
|
167
|
-
try {
|
|
168
|
-
r.screenshot = await captureScreenshot({
|
|
169
|
-
hide: () => (app.host.style.visibility = "hidden"),
|
|
170
|
-
show: () => (app.host.style.visibility = ""),
|
|
171
|
-
});
|
|
172
|
-
schedule();
|
|
173
|
-
} catch (error) {
|
|
174
|
-
notice(error?.name === "NotAllowedError" ? "No screenshot: the capture was declined." : `No screenshot: ${error.message}`);
|
|
175
|
-
}
|
|
176
|
-
refresh();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
148
|
const field = (label, key, multiline, placeholder) => {
|
|
180
149
|
const input = h(multiline ? "textarea" : "input", { class: "field", rows: multiline ? 3 : null, maxlength: multiline ? 4000 : 200, "aria-label": label, placeholder });
|
|
181
150
|
input.value = r[key];
|
|
@@ -199,10 +168,9 @@ function newReport(app) {
|
|
|
199
168
|
const textToggle = toggle("Include page text", "includeText", "Off: text is replaced by its length.");
|
|
200
169
|
const findingsToggle = toggle("Include the validator's findings", "includeFindings", "For the files that render this page.");
|
|
201
170
|
const consoleToggle = toggle("Include console errors", "includeConsole", "Paths are trimmed to the app.");
|
|
202
|
-
const shot = h("div", { class: "shot" });
|
|
203
171
|
const preview = h("pre", { class: "json", "aria-label": "Snapshot JSON" });
|
|
204
172
|
const problems = h("ul", { class: "problems" });
|
|
205
|
-
const status = h("
|
|
173
|
+
const status = h("div", { class: "report-status", role: "status" });
|
|
206
174
|
const similar = h("div", {});
|
|
207
175
|
const sendButton = h("button", { class: "btn primary", type: "button", onclick: () => send() }, icon(GITHUB_MARK), h("span", {}, "Open issue on GitHub"));
|
|
208
176
|
const linkButton = h("button", { class: "btn", type: "button", title: "Opens GitHub's own form, filled in; you submit it there. No sign-in.", onclick: openOnGitHub }, icon(ICONS.external), "Open on GitHub instead");
|
|
@@ -222,7 +190,7 @@ function newReport(app) {
|
|
|
222
190
|
field("Title", "title", false, "Card loses its border in dark mode"),
|
|
223
191
|
field("What happened?", "happened", true, "What you saw"),
|
|
224
192
|
field("What did you expect?", "expected", true, "What should have happened"),
|
|
225
|
-
h("div", { class: "card", style: "padding:2px 14px" }, textToggle.row, findingsToggle.row, consoleToggle.row
|
|
193
|
+
h("div", { class: "card", style: "padding:2px 14px" }, textToggle.row, findingsToggle.row, consoleToggle.row),
|
|
226
194
|
problems,
|
|
227
195
|
similar,
|
|
228
196
|
h("details", { class: "json-box" }, h("summary", {}, icon(ICONS.chevron), "Exactly what will be sent"), preview),
|
|
@@ -270,17 +238,7 @@ function newReport(app) {
|
|
|
270
238
|
|
|
271
239
|
function refresh() {
|
|
272
240
|
consoleToggle.text.textContent = `Include console errors (${app.consoleErrors.messages.length})`;
|
|
273
|
-
|
|
274
|
-
r.screenshot
|
|
275
|
-
? h(
|
|
276
|
-
"div",
|
|
277
|
-
{ class: "row" },
|
|
278
|
-
h("img", { class: "thumb", src: r.screenshot, alt: "Screenshot to be sent" }),
|
|
279
|
-
h("button", { class: "btn ghost", type: "button", onclick: () => { r.screenshot = null; schedule(); refresh(); } }, "Remove"),
|
|
280
|
-
)
|
|
281
|
-
: h("button", { class: "btn", type: "button", onclick: addScreenshot }, icon(ICONS.camera), "Add…"),
|
|
282
|
-
);
|
|
283
|
-
preview.textContent = r.snapshot ? previewText(r.snapshot) : "Assembling…";
|
|
241
|
+
preview.textContent = r.snapshot ? JSON.stringify(r.snapshot, null, 2) : "Assembling…";
|
|
284
242
|
problems.replaceChildren(...r.problems.map((p) => h("li", {}, p)));
|
|
285
243
|
const signedIn = Boolean(app.state.github?.login);
|
|
286
244
|
sendButton.disabled = !signedIn || !r.snapshot || r.problems.length > 0 || r.status === "sending";
|
|
@@ -294,13 +252,16 @@ function newReport(app) {
|
|
|
294
252
|
status.replaceChildren(
|
|
295
253
|
r.status === "sent"
|
|
296
254
|
? h(
|
|
297
|
-
"
|
|
298
|
-
{},
|
|
299
|
-
|
|
300
|
-
h(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
: "
|
|
255
|
+
"div",
|
|
256
|
+
{ class: "card sent-card" },
|
|
257
|
+
h("span", { class: "sent-icon" }, icon(ICONS.check)),
|
|
258
|
+
h(
|
|
259
|
+
"div",
|
|
260
|
+
{ class: "grow" },
|
|
261
|
+
h("div", { class: "sent-title" }, r.added ? `Added your report to #${r.number}` : `Opened #${r.number} on GitHub`),
|
|
262
|
+
h("p", { class: "muted small" }, "To add a screenshot or a file, open the issue and drop it into a comment there."),
|
|
263
|
+
h("a", { class: "btn primary", href: r.url, target: "_blank", rel: "noreferrer" }, icon(GITHUB_MARK), "Open the issue on GitHub", icon(ICONS.external)),
|
|
264
|
+
),
|
|
304
265
|
)
|
|
305
266
|
: r.status === "failed"
|
|
306
267
|
? `${r.message} Nothing was sent; Copy JSON or Download keeps the snapshot.`
|
package/src/client/styles.mjs
CHANGED
|
@@ -193,7 +193,7 @@ h1, h2, h3, h4, p { margin: 0; }
|
|
|
193
193
|
.pad { padding: 14px; }
|
|
194
194
|
.btn {
|
|
195
195
|
display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 32px; padding: 0 12px;
|
|
196
|
-
border-radius: 10px; font: 500 12.5px/1 var(--sans); white-space: nowrap;
|
|
196
|
+
border-radius: 10px; font: 500 12.5px/1 var(--sans); white-space: nowrap; text-decoration: none;
|
|
197
197
|
background: rgb(255 255 255 / 0.05); border: 1px solid var(--line-2); color: var(--text);
|
|
198
198
|
transition: background 140ms var(--ease), border-color 140ms var(--ease), transform 140ms var(--ease), box-shadow 200ms var(--ease);
|
|
199
199
|
}
|
|
@@ -321,7 +321,7 @@ h1, h2, h3, h4, p { margin: 0; }
|
|
|
321
321
|
.tier-dot.leaf { background: var(--brand); }
|
|
322
322
|
.tier-dot.required { background: var(--advice); }
|
|
323
323
|
.n-pill { min-width: 22px; padding: 2px 7px; border-radius: 999px; font: 500 11px/1.3 var(--sans); text-align: center; color: var(--muted); background: rgb(255 255 255 / 0.06); }
|
|
324
|
-
.mini { display: inline-flex; align-items: center; gap: 4px; font: 600 11px/1 var(--sans); }
|
|
324
|
+
.mini { display: inline-flex; align-items: center; gap: 4px; font: 600 11px/1 var(--sans); white-space: nowrap; }
|
|
325
325
|
.mini.error { color: var(--error); }
|
|
326
326
|
.mini.advice { color: var(--advice); }
|
|
327
327
|
.mini i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
|
|
@@ -384,6 +384,33 @@ button.chip:hover { border-color: var(--brand-line); color: var(--brand-2); }
|
|
|
384
384
|
.props td:first-child { width: 1%; padding-right: 16px; white-space: nowrap; color: var(--muted); }
|
|
385
385
|
.props td:last-child { color: var(--brand-2); word-break: break-word; }
|
|
386
386
|
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
387
|
+
.prop-groups { display: flex; flex-direction: column; gap: 2px; }
|
|
388
|
+
.prop-group .group-label { font-weight: 600; white-space: nowrap; }
|
|
389
|
+
.prop-group .group-hint { font-size: 12px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
390
|
+
.mini.in-use { color: var(--brand-2); }
|
|
391
|
+
.prop-rows { padding: 0 10px 6px 34px; }
|
|
392
|
+
.prop-row { display: flex; flex-direction: column; gap: 5px; padding: 9px 0; }
|
|
393
|
+
.prop-row + .prop-row { border-top: 1px solid var(--line); }
|
|
394
|
+
.prop-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; min-height: 22px; }
|
|
395
|
+
.prop-name { font: 600 12.5px/1.3 var(--mono); color: var(--text); }
|
|
396
|
+
.prop-row.used .prop-name { color: var(--brand-2); }
|
|
397
|
+
.prop-alias { font: 11.5px/1.3 var(--mono); color: var(--faint); }
|
|
398
|
+
.prop-type { font: 11.5px/1.3 var(--mono); color: var(--advice); }
|
|
399
|
+
.prop-head .pill { flex: none; max-width: 100%; height: 20px; padding: 0 8px; font-size: 10.5px; }
|
|
400
|
+
.prop-head .pill.in-use { display: block; color: var(--brand-2); background: var(--brand-soft); border-color: transparent; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); line-height: 18px; }
|
|
401
|
+
.prop-doc { font-size: 12.5px; line-height: 1.45; color: var(--muted); }
|
|
402
|
+
.prop-default { font-size: 12px; color: var(--faint); }
|
|
403
|
+
.prop-default .code { color: var(--text); }
|
|
404
|
+
.prop-values { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 11.5px; }
|
|
405
|
+
.prop-values:focus { outline: none; }
|
|
406
|
+
.val {
|
|
407
|
+
display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: 6px;
|
|
408
|
+
font: 500 11px/1 var(--mono); color: var(--muted); background: rgb(255 255 255 / 0.04); border: 1px solid var(--line);
|
|
409
|
+
}
|
|
410
|
+
.val.on { color: var(--brand-2); background: var(--brand-soft); border-color: var(--brand-line); }
|
|
411
|
+
.val.hit { color: var(--text); border-color: var(--line-2); background: rgb(255 255 255 / 0.09); }
|
|
412
|
+
button.val.more { color: var(--brand-2); border-style: dashed; border-color: var(--brand-line); background: none; transition: background 140ms var(--ease); }
|
|
413
|
+
button.val.more:hover { background: var(--brand-soft); }
|
|
387
414
|
.gone { display: flex; gap: 10px; align-items: center; padding: 10px 12px; margin-bottom: 14px; border-radius: 11px; background: var(--error-soft); color: var(--error); font-size: 12.5px; }
|
|
388
415
|
|
|
389
416
|
/* ---- report ------------------------------------------------------------------ */
|
|
@@ -410,8 +437,6 @@ button.chip:hover { border-color: var(--brand-line); color: var(--brand-2); }
|
|
|
410
437
|
.switch input:checked + span { background: var(--brand); border-color: transparent; }
|
|
411
438
|
.switch input:checked + span::after { transform: translateX(14px); background: var(--brand-ink); }
|
|
412
439
|
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
|
|
413
|
-
.shot { display: flex; align-items: center; gap: 10px; }
|
|
414
|
-
.thumb { max-width: 120px; max-height: 72px; border-radius: 8px; border: 1px solid var(--line-2); }
|
|
415
440
|
details.json-box { border-radius: 12px; background: var(--bg-1); border: 1px solid var(--line); }
|
|
416
441
|
details.json-box summary { display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; list-style: none; font-weight: 500; }
|
|
417
442
|
details.json-box summary::-webkit-details-marker { display: none; }
|
|
@@ -425,7 +450,11 @@ details.json-box[open] summary .icon { transform: rotate(90deg); }
|
|
|
425
450
|
.problems:empty { display: none; }
|
|
426
451
|
.report-status { font-size: 12.5px; min-height: 18px; }
|
|
427
452
|
.report-status.failed { color: var(--error); }
|
|
428
|
-
.
|
|
453
|
+
.sent-card { display: flex; align-items: flex-start; gap: 12px; padding: 14px; color: var(--text); border-color: rgb(74 222 128 / 0.28); background: linear-gradient(180deg, var(--ok-soft), transparent 75%), var(--bg-1); }
|
|
454
|
+
.sent-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; flex: none; background: var(--ok-soft); color: var(--ok); }
|
|
455
|
+
.sent-icon .icon { width: 17px; height: 17px; }
|
|
456
|
+
.sent-title { font: 600 14px/1.3 var(--display); }
|
|
457
|
+
.sent-card p { margin: 3px 0 12px; }
|
|
429
458
|
|
|
430
459
|
/* ---- GitHub ------------------------------------------------------------------- */
|
|
431
460
|
|