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
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { specEntry } from "astralis-cli/snapshot";
|
|
2
|
+
|
|
3
|
+
/* Every prop a component takes, read from the system spec: its own props
|
|
4
|
+
first, then its style props by group. Pure, so it runs in the overlay and
|
|
5
|
+
in Node tests alike. */
|
|
6
|
+
|
|
7
|
+
const GROUP_LABELS = {
|
|
8
|
+
box: { label: "Box", hint: "spacing, size, paint, border, layout" },
|
|
9
|
+
flex: { label: "Flex", hint: "direction, wrap, alignment, gap" },
|
|
10
|
+
flexItem: { label: "Flex item", hint: "grow, shrink, basis, order" },
|
|
11
|
+
grid: { label: "Grid", hint: "columns, rows, flow, gap" },
|
|
12
|
+
gridItem: { label: "Grid item", hint: "spans and placement" },
|
|
13
|
+
text: { label: "Text", hint: "size, weight, colour, alignment" },
|
|
14
|
+
stack: { label: "Stack", hint: "direction, gap, alignment" },
|
|
15
|
+
placement: { label: "Placement", hint: "size, margin, position, motion" },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The spec lists some components' style props by name instead of by group
|
|
20
|
+
* (List, Code, Separator; Stat, Select and others): when nearly all of a
|
|
21
|
+
* group's names are there, they are shown as that group.
|
|
22
|
+
*/
|
|
23
|
+
const GROUP_COVERAGE = 0.9;
|
|
24
|
+
|
|
25
|
+
const docsOf = (entry, name) => {
|
|
26
|
+
const docs = entry.propDocs?.[name];
|
|
27
|
+
if (!docs || typeof docs !== "object") return {};
|
|
28
|
+
return {
|
|
29
|
+
...(typeof docs.description === "string" && docs.description.trim() ? { description: docs.description.trim() } : {}),
|
|
30
|
+
...(typeof docs.default === "string" && docs.default.trim() ? { default: docs.default.trim() } : {}),
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** The props of one group, long spellings folded into their short name ("padding" into "p"). */
|
|
35
|
+
function groupRows(definitions, names, taken) {
|
|
36
|
+
const rows = new Map();
|
|
37
|
+
for (const name of names) {
|
|
38
|
+
const definition = definitions[name];
|
|
39
|
+
if (!definition || taken.has(name)) continue;
|
|
40
|
+
const short = definition.short && names.includes(definition.short) && !taken.has(definition.short) ? definition.short : null;
|
|
41
|
+
if (short) {
|
|
42
|
+
if (!rows.has(short)) rows.set(short, null);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
rows.set(name, {
|
|
46
|
+
name,
|
|
47
|
+
aliases: [],
|
|
48
|
+
values: Array.isArray(definition.tokens) ? definition.tokens.map(String) : [],
|
|
49
|
+
type: null,
|
|
50
|
+
arbitrary: definition.arbitrary ? definition.valueType ?? "value" : null,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
for (const name of names) {
|
|
54
|
+
const definition = definitions[name];
|
|
55
|
+
if (definition?.short && rows.get(definition.short)) rows.get(definition.short).aliases.push(name);
|
|
56
|
+
}
|
|
57
|
+
for (const [name, row] of rows) {
|
|
58
|
+
if (!row) rows.delete(name);
|
|
59
|
+
}
|
|
60
|
+
for (const row of rows.values()) for (const name of [row.name, ...row.aliases]) taken.add(name);
|
|
61
|
+
return [...rows.values()];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The props `name` takes, as sections of rows. `used` is the props this
|
|
66
|
+
* instance was given; a row it uses carries `used: { as, value }`. Returns
|
|
67
|
+
* null when the spec has no entry for the name.
|
|
68
|
+
*
|
|
69
|
+
* { key, total, sections: [{ id, label, hint, inferred?, rows: [
|
|
70
|
+
* { name, aliases, values, type, arbitrary, required, note?, description?, default?, used } ] }] }
|
|
71
|
+
*/
|
|
72
|
+
export function propsModel(spec, name, used = {}) {
|
|
73
|
+
const found = specEntry(spec, name);
|
|
74
|
+
if (!found) return null;
|
|
75
|
+
const { key, entry } = found;
|
|
76
|
+
const groups = spec.propGroups ?? {};
|
|
77
|
+
const closed = entry.props ?? {};
|
|
78
|
+
const scalars = entry.scalarProps ?? {};
|
|
79
|
+
const required = entry.required ?? {};
|
|
80
|
+
const overrides = entry.overrides ?? [];
|
|
81
|
+
const exclude = new Set(entry.exclude ?? []);
|
|
82
|
+
const inGroups = new Set((entry.groups ?? []).flatMap((group) => Object.keys(groups[group] ?? {})));
|
|
83
|
+
|
|
84
|
+
const ownNames = [...new Set([...Object.keys(closed), ...Object.keys(scalars), ...Object.keys(required), ...overrides])];
|
|
85
|
+
let stray = (entry.ownStyleProps ?? []).filter((prop) => !ownNames.includes(prop) && !inGroups.has(prop) && !exclude.has(prop));
|
|
86
|
+
|
|
87
|
+
const taken = new Set(ownNames);
|
|
88
|
+
const sections = [];
|
|
89
|
+
const groupSection = (group, names, inferred) => {
|
|
90
|
+
const rows = groupRows(groups[group], names, taken);
|
|
91
|
+
if (rows.length) sections.push({ id: `group:${group}`, label: GROUP_LABELS[group]?.label ?? group, hint: GROUP_LABELS[group]?.hint ?? "", ...(inferred ? { inferred: true } : {}), rows });
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
for (const group of entry.groups ?? []) {
|
|
95
|
+
if (groups[group]) groupSection(group, Object.keys(groups[group]).filter((prop) => !exclude.has(prop)), false);
|
|
96
|
+
}
|
|
97
|
+
// Largest first: placement's names include all of flexItem's, and must claim them.
|
|
98
|
+
const bySize = Object.entries(groups).sort(([, a], [, b]) => Object.keys(b).length - Object.keys(a).length);
|
|
99
|
+
for (const [group, definitions] of bySize) {
|
|
100
|
+
const names = Object.keys(definitions);
|
|
101
|
+
const covered = names.filter((prop) => stray.includes(prop));
|
|
102
|
+
if (names.length && covered.length / names.length >= GROUP_COVERAGE) {
|
|
103
|
+
groupSection(group, covered, true);
|
|
104
|
+
stray = stray.filter((prop) => !taken.has(prop));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const own = [
|
|
109
|
+
...ownNames.map((prop) => ({
|
|
110
|
+
name: prop,
|
|
111
|
+
aliases: [],
|
|
112
|
+
values: Array.isArray(closed[prop]) ? closed[prop].map(String) : [],
|
|
113
|
+
type: scalars[prop] ?? required[prop] ?? null,
|
|
114
|
+
arbitrary: null,
|
|
115
|
+
...(overrides.includes(prop) && !closed[prop] && !scalars[prop] && !required[prop] ? { note: "Its own attribute, not the style prop" } : {}),
|
|
116
|
+
})),
|
|
117
|
+
...stray.map((prop) => ({ name: prop, aliases: [], values: [], type: null, arbitrary: null, note: "Values not in the spec" })),
|
|
118
|
+
];
|
|
119
|
+
if (own.length) sections.unshift({ id: "own", label: "Its own props", hint: "", rows: own });
|
|
120
|
+
|
|
121
|
+
for (const section of sections) {
|
|
122
|
+
for (const row of section.rows) {
|
|
123
|
+
row.required = Object.hasOwn(required, row.name);
|
|
124
|
+
Object.assign(row, docsOf(entry, row.name));
|
|
125
|
+
const as = [row.name, ...row.aliases].find((prop) => used && Object.hasOwn(used, prop));
|
|
126
|
+
row.used = as ? { as, value: used[as] } : null;
|
|
127
|
+
}
|
|
128
|
+
// Required props lead their section; the spec's order is kept otherwise.
|
|
129
|
+
section.rows.sort((a, b) => Number(b.required) - Number(a.required));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return { key, total: sections.reduce((n, section) => n + section.rows.length, 0), sections };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The rows matching `query` by prop name (or long spelling) or by a value it
|
|
137
|
+
* takes. A row found by a value is marked `byValue`, so its whole list can be
|
|
138
|
+
* shown. An empty query keeps everything.
|
|
139
|
+
*/
|
|
140
|
+
export function filterProps(model, query) {
|
|
141
|
+
const q = query.trim().toLowerCase();
|
|
142
|
+
if (!model) return { sections: [], count: 0 };
|
|
143
|
+
if (!q) return { sections: model.sections, count: model.total };
|
|
144
|
+
const sections = [];
|
|
145
|
+
for (const section of model.sections) {
|
|
146
|
+
const rows = [];
|
|
147
|
+
for (const row of section.rows) {
|
|
148
|
+
if ([row.name, ...row.aliases].some((name) => name.toLowerCase().includes(q))) rows.push(row);
|
|
149
|
+
else if (row.values.some((value) => value.toLowerCase().includes(q)) || row.type?.toLowerCase() === q) rows.push({ ...row, byValue: true });
|
|
150
|
+
}
|
|
151
|
+
if (rows.length) sections.push({ ...section, rows });
|
|
152
|
+
}
|
|
153
|
+
return { sections, count: sections.reduce((n, section) => n + section.rows.length, 0) };
|
|
154
|
+
}
|
package/src/client/report.mjs
CHANGED
|
@@ -2,8 +2,8 @@ import { LIMITS, cleanConsoleMessage, contentOf, keptText, redactedText } from "
|
|
|
2
2
|
import { IDENTITY_ATTRIBUTE, readIdentity } from "./identity.mjs";
|
|
3
3
|
|
|
4
4
|
/* The page's part of an issue snapshot: the component tree under the
|
|
5
|
-
selected element, the browser's facts
|
|
6
|
-
|
|
5
|
+
selected element, the browser's facts and console errors. Nothing here
|
|
6
|
+
sends anything; the bridge assembles the rest. */
|
|
7
7
|
|
|
8
8
|
const SKIP = new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT"]);
|
|
9
9
|
|
|
@@ -119,43 +119,3 @@ function safeString(value) {
|
|
|
119
119
|
return String(value);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
const MAX_SCREENSHOT_BYTES = 180 * 1024;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* A screenshot of this tab through the browser's own capture prompt, as a
|
|
127
|
-
* JPEG data URL small enough for a snapshot. `hide` and `show` take the
|
|
128
|
-
* overlay out of the picture. Rejects if the reporter declines the prompt.
|
|
129
|
-
*/
|
|
130
|
-
export async function captureScreenshot({ hide = () => {}, show = () => {}, win = globalThis.window } = {}) {
|
|
131
|
-
const stream = await win.navigator.mediaDevices.getDisplayMedia({
|
|
132
|
-
video: { displaySurface: "browser" },
|
|
133
|
-
audio: false,
|
|
134
|
-
preferCurrentTab: true,
|
|
135
|
-
selfBrowserSurface: "include",
|
|
136
|
-
});
|
|
137
|
-
const video = win.document.createElement("video");
|
|
138
|
-
try {
|
|
139
|
-
video.srcObject = stream;
|
|
140
|
-
video.muted = true;
|
|
141
|
-
await video.play();
|
|
142
|
-
hide();
|
|
143
|
-
// Two frames, so the capture shows the page without the overlay.
|
|
144
|
-
await new Promise((done) => win.requestAnimationFrame(() => win.requestAnimationFrame(done)));
|
|
145
|
-
for (const [width, quality] of [[1280, 0.72], [960, 0.6], [720, 0.5]]) {
|
|
146
|
-
const scale = Math.min(1, width / video.videoWidth);
|
|
147
|
-
const canvas = win.document.createElement("canvas");
|
|
148
|
-
canvas.width = Math.round(video.videoWidth * scale);
|
|
149
|
-
canvas.height = Math.round(video.videoHeight * scale);
|
|
150
|
-
canvas.getContext("2d").drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
151
|
-
const url = canvas.toDataURL("image/jpeg", quality);
|
|
152
|
-
if (url.length * 0.75 <= MAX_SCREENSHOT_BYTES) return url;
|
|
153
|
-
}
|
|
154
|
-
throw new Error("The screenshot is too large to include.");
|
|
155
|
-
} finally {
|
|
156
|
-
show();
|
|
157
|
-
for (const track of stream.getTracks()) track.stop();
|
|
158
|
-
video.srcObject = null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
@@ -1,151 +1,158 @@
|
|
|
1
|
-
import { formatValue, h, icon, plural } from "../dom.mjs";
|
|
2
|
-
import { describeComponent, IDENTITY_ATTRIBUTE, readIdentity } from "../identity.mjs";
|
|
3
|
-
import { ICONS } from "../icons.mjs";
|
|
4
|
-
import { findingsFor } from "../page.mjs";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
1
|
+
import { formatValue, h, icon, plural } from "../dom.mjs";
|
|
2
|
+
import { describeComponent, IDENTITY_ATTRIBUTE, readIdentity } from "../identity.mjs";
|
|
3
|
+
import { ICONS } from "../icons.mjs";
|
|
4
|
+
import { findingsFor } from "../page.mjs";
|
|
5
|
+
import { allProps } from "./props.mjs";
|
|
6
|
+
import { findingRow } from "./shared.mjs";
|
|
7
|
+
|
|
8
|
+
/* One component on the page: what it is, the props it was given and every
|
|
9
|
+
prop it takes, how it reaches the browser, where it sits, and the findings
|
|
10
|
+
and recommendations about it. */
|
|
11
|
+
|
|
12
|
+
export function componentScreen(app, element) {
|
|
13
|
+
const root = h("div", {});
|
|
14
|
+
const chain = readIdentity(element);
|
|
15
|
+
const name = chain[0]?.name ?? "Component";
|
|
16
|
+
// Built once: findings and page changes redraw the screen, and must not reset the search.
|
|
17
|
+
const takes = allProps(app, chain);
|
|
18
|
+
|
|
19
|
+
function propsCard(entry) {
|
|
20
|
+
const about = describeComponent(app.state.spec, entry.name, app.framework);
|
|
21
|
+
const props = Object.entries(entry.props);
|
|
22
|
+
return h(
|
|
23
|
+
"div",
|
|
24
|
+
{ class: "card pad" },
|
|
25
|
+
h(
|
|
26
|
+
"div",
|
|
27
|
+
{ class: "row", style: "margin-bottom:10px" },
|
|
28
|
+
h("span", { class: "code grow", style: "font-weight:600" }, entry.name),
|
|
29
|
+
h("a", { class: "link", href: about.docsUrl, target: "_blank", rel: "noreferrer" }, "Docs", icon(ICONS.external)),
|
|
30
|
+
),
|
|
31
|
+
app.state.spec && !about.known
|
|
32
|
+
? h(
|
|
33
|
+
"p",
|
|
34
|
+
{ class: "muted", style: "margin-bottom:8px" },
|
|
35
|
+
about.partOf ? `Part of ${about.partOf}. The spec has no entry of its own for it, so no client tier is shown.` : `${entry.name} is not in the installed spec.`,
|
|
36
|
+
)
|
|
37
|
+
: null,
|
|
38
|
+
props.length
|
|
39
|
+
? h("table", { class: "props" }, h("tbody", {}, props.map(([key, value]) => h("tr", {}, h("td", {}, key), h("td", {}, formatValue(value))))))
|
|
40
|
+
: h("p", { class: "muted" }, "No props beyond its defaults."),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function findingsSection(title, list, tone) {
|
|
45
|
+
return h(
|
|
46
|
+
"section",
|
|
47
|
+
{},
|
|
48
|
+
h("h3", { class: "section-title" }, title, h("span", { class: "n" }, String(list.length))),
|
|
49
|
+
list.length
|
|
50
|
+
? h(
|
|
51
|
+
"div",
|
|
52
|
+
{ class: "file-card" },
|
|
53
|
+
list.map((finding) => findingRow(app, finding, { showFile: true, showComponent: false, exactLabel: finding.exact ? "This one" : null })),
|
|
54
|
+
)
|
|
55
|
+
: h("p", { class: "muted", style: "margin-bottom:4px" }, tone === "error" ? "Nothing broken here." : "Nothing to suggest."),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function update() {
|
|
60
|
+
const { state } = app;
|
|
61
|
+
if (!element.isConnected) {
|
|
62
|
+
root.replaceChildren(
|
|
63
|
+
h("div", { class: "gone" }, icon(ICONS.findings), "This component has left the page."),
|
|
64
|
+
h("button", { class: "btn", type: "button", onclick: () => app.navigate("components") }, icon(ICONS.back), "All components"),
|
|
65
|
+
);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const about = describeComponent(state.spec, name, app.framework);
|
|
69
|
+
const sameKind = state.instances.filter((i) => i.name === name);
|
|
70
|
+
const instance = state.instances.find((i) => i.element === element) ?? { element, chain, name };
|
|
71
|
+
const found = findingsFor(instance, state.findings, { routeFiles: state.routeFiles, alone: sameKind.length === 1 });
|
|
72
|
+
const errors = found.filter((f) => f.kind === "error" && (f.exact || f.onPage));
|
|
73
|
+
const warnings = found.filter((f) => f.kind === "warning" && (f.exact || f.onPage));
|
|
74
|
+
|
|
75
|
+
const ancestors = [];
|
|
76
|
+
for (let node = element.parentElement?.closest(`[${IDENTITY_ATTRIBUTE}]`); node; node = node.parentElement?.closest(`[${IDENTITY_ATTRIBUTE}]`)) {
|
|
77
|
+
ancestors.unshift(node);
|
|
78
|
+
}
|
|
79
|
+
const inside = state.instances.filter((i) => i.element !== element && element.contains(i.element) && i.element.parentElement?.closest(`[${IDENTITY_ATTRIBUTE}]`) === element);
|
|
80
|
+
|
|
81
|
+
const head = h(
|
|
82
|
+
"div",
|
|
83
|
+
{ class: "detail-head" },
|
|
84
|
+
h("span", { class: "detail-icon" }, icon(ICONS.components)),
|
|
85
|
+
h(
|
|
86
|
+
"div",
|
|
87
|
+
{ class: "grow" },
|
|
88
|
+
h("h2", {}, name),
|
|
89
|
+
chain.length > 1 ? h("p", { class: "chain" }, `renders through ${chain.slice(1).map((c) => c.name).join(" → ")}`) : null,
|
|
90
|
+
h(
|
|
91
|
+
"div",
|
|
92
|
+
{ class: "row" },
|
|
93
|
+
about.client ? h("span", { class: `pill ${about.client}`, title: about.clientDetail }, h("i"), about.clientLabel) : null,
|
|
94
|
+
about.category ? h("span", { class: "pill" }, about.category) : null,
|
|
95
|
+
sameKind.length > 1 ? h("span", { class: "pill" }, `${sameKind.indexOf(instance) + 1} of ${sameKind.length} on this page`) : null,
|
|
96
|
+
errors.length ? h("span", { class: "pill error" }, plural(errors.length, "finding")) : null,
|
|
97
|
+
warnings.length ? h("span", { class: "pill advice" }, plural(warnings.length, "recommendation")) : null,
|
|
98
|
+
),
|
|
99
|
+
about.client ? h("p", { class: "muted", style: "margin-top:8px;font-size:12.5px" }, about.clientDetail) : null,
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const actions = h(
|
|
104
|
+
"div",
|
|
105
|
+
{ class: "actions" },
|
|
106
|
+
h("button", { class: "btn", type: "button", onclick: () => app.locate(element) }, icon(ICONS.locate), "Locate on page"),
|
|
107
|
+
h("button", { class: "btn", type: "button", onclick: () => app.navigate("report") }, icon(ICONS.report), "Report a problem"),
|
|
108
|
+
h("a", { class: "btn ghost", href: about.docsUrl, target: "_blank", rel: "noreferrer" }, "Docs", icon(ICONS.external)),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const crumbs = (title, nodes) =>
|
|
112
|
+
nodes.length
|
|
113
|
+
? h(
|
|
114
|
+
"section",
|
|
115
|
+
{},
|
|
116
|
+
h("h3", { class: "section-title" }, title),
|
|
117
|
+
h(
|
|
118
|
+
"div",
|
|
119
|
+
{ class: "tags" },
|
|
120
|
+
nodes.map((node) =>
|
|
121
|
+
h(
|
|
122
|
+
"button",
|
|
123
|
+
{
|
|
124
|
+
class: "chip",
|
|
125
|
+
type: "button",
|
|
126
|
+
onclick: () => app.openComponent(node),
|
|
127
|
+
onpointerenter: () => app.preview(node),
|
|
128
|
+
onpointerleave: () => app.preview(element),
|
|
129
|
+
},
|
|
130
|
+
readIdentity(node)[0]?.name ?? "?",
|
|
131
|
+
),
|
|
132
|
+
),
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
: null;
|
|
136
|
+
|
|
137
|
+
takes.update();
|
|
138
|
+
const searching = takes.input.getRootNode().activeElement === takes.input;
|
|
139
|
+
root.replaceChildren(
|
|
140
|
+
head,
|
|
141
|
+
actions,
|
|
142
|
+
h(
|
|
143
|
+
"div",
|
|
144
|
+
{ class: "stack" },
|
|
145
|
+
findingsSection("Findings", errors, "error"),
|
|
146
|
+
findingsSection("Recommendations", warnings, "advice"),
|
|
147
|
+
h("section", {}, h("h3", { class: "section-title" }, "Props given"), h("div", { class: "stack" }, chain.map((entry) => propsCard(entry)))),
|
|
148
|
+
takes.root,
|
|
149
|
+
crumbs("Inside", ancestors),
|
|
150
|
+
crumbs("Contains", inside.map((i) => i.element)),
|
|
151
|
+
),
|
|
152
|
+
);
|
|
153
|
+
if (searching) takes.input.focus({ preventScroll: true });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
update();
|
|
157
|
+
return { title: [{ label: "Components", screen: "components" }, { label: name, code: true }], root, update, element };
|
|
158
|
+
}
|