astralis-devtools 0.0.0-stage → 0.1.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 +35 -0
- package/LICENSE +21 -0
- package/README.md +81 -2
- 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 +71 -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 +44 -0
- package/src/client/identity.mjs +117 -0
- package/src/client/launcher.mjs +142 -0
- package/src/client/overlay.d.mts +9 -0
- package/src/client/overlay.mjs +525 -0
- package/src/client/page.mjs +92 -0
- package/src/client/picker.mjs +118 -0
- package/src/client/report.mjs +161 -0
- package/src/client/screens/component.mjs +151 -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/report.mjs +498 -0
- package/src/client/screens/shared.mjs +59 -0
- package/src/client/styles.mjs +512 -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,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 close")),
|
|
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
|
+
}
|