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,498 @@
|
|
|
1
|
+
import { h, icon, plural } from "../dom.mjs";
|
|
2
|
+
import { readIdentity } from "../identity.mjs";
|
|
3
|
+
import { GITHUB_MARK, ICONS } from "../icons.mjs";
|
|
4
|
+
import { browserEnvironment, captureScreenshot, treeFromElement } from "../report.mjs";
|
|
5
|
+
import { empty } from "./shared.mjs";
|
|
6
|
+
|
|
7
|
+
/* Report: a problem sent to the maintainers as a GitHub issue, opened from
|
|
8
|
+
the reporter's own account, and the issues they have opened so far.
|
|
9
|
+
|
|
10
|
+
A report is an issue snapshot of one component and everything inside it.
|
|
11
|
+
The exact JSON is shown before anything is sent, and nothing is sent until
|
|
12
|
+
the reporter presses Send. The form keeps its input across screens and
|
|
13
|
+
while findings stream in. */
|
|
14
|
+
|
|
15
|
+
/** The form for a new report. */
|
|
16
|
+
function newReport(app) {
|
|
17
|
+
const { state } = app;
|
|
18
|
+
const r = state.report;
|
|
19
|
+
const element = state.selected?.isConnected ? state.selected : null;
|
|
20
|
+
|
|
21
|
+
if (!element) {
|
|
22
|
+
const root = h(
|
|
23
|
+
"div",
|
|
24
|
+
{},
|
|
25
|
+
empty(ICONS.report, "Which component is it?", "Pick the component the problem is in. The report describes it and everything inside it.", { neutral: true }),
|
|
26
|
+
h(
|
|
27
|
+
"div",
|
|
28
|
+
{ class: "row", style: "justify-content:center" },
|
|
29
|
+
h("button", { class: "btn primary", type: "button", onclick: () => app.startPicking("report") }, icon(ICONS.pick), "Pick a component"),
|
|
30
|
+
h("button", { class: "btn", type: "button", onclick: () => app.navigate("components") }, "Choose from the list"),
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
return { root, update() {} };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let timer = null;
|
|
37
|
+
let request = 0;
|
|
38
|
+
|
|
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
|
+
function schedule() {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
timer = setTimeout(assemble, 250);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Ask the bridge to complete the snapshot from the page's part. Nothing leaves the machine. */
|
|
53
|
+
async function assemble() {
|
|
54
|
+
if (!element.isConnected) return;
|
|
55
|
+
const mine = ++request;
|
|
56
|
+
const body = {
|
|
57
|
+
tree: treeFromElement(element, state.spec, { includeText: r.includeText, skip: app.host }),
|
|
58
|
+
route: location.pathname,
|
|
59
|
+
environment: browserEnvironment(window),
|
|
60
|
+
description: { title: r.title, happened: r.happened, expected: r.expected },
|
|
61
|
+
include: { findings: r.includeFindings, console: r.includeConsole, screenshot: Boolean(r.screenshot) },
|
|
62
|
+
console: [...app.consoleErrors.messages],
|
|
63
|
+
...(r.screenshot ? { screenshot: r.screenshot } : {}),
|
|
64
|
+
};
|
|
65
|
+
try {
|
|
66
|
+
const response = await fetch(`${app.base}/snapshot`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
|
|
67
|
+
const result = await response.json();
|
|
68
|
+
if (mine !== request) return; // a newer edit is on its way
|
|
69
|
+
if (!response.ok) throw new Error(result?.error ?? `The bridge answered ${response.status}.`);
|
|
70
|
+
r.snapshot = result.snapshot;
|
|
71
|
+
r.problems = result.problems;
|
|
72
|
+
if (r.status === "notice") r.status = "idle";
|
|
73
|
+
checkSimilar(result.snapshot);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (mine !== request) return;
|
|
76
|
+
r.snapshot = null;
|
|
77
|
+
r.problems = [error.message];
|
|
78
|
+
}
|
|
79
|
+
refresh();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Issues that may already report this. The bridge searches GitHub once per problem, not per keystroke. */
|
|
83
|
+
async function checkSimilar(snapshot) {
|
|
84
|
+
if (!app.state.github?.login) return;
|
|
85
|
+
try {
|
|
86
|
+
const response = await fetch(`${app.base}/github/similar`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(snapshot) });
|
|
87
|
+
if (!response.ok) return;
|
|
88
|
+
r.similar = await response.json();
|
|
89
|
+
} catch {
|
|
90
|
+
return; // no check is no reason to stop a report
|
|
91
|
+
}
|
|
92
|
+
refresh();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Open a new issue, or, with `addTo`, add the report to that existing one. */
|
|
96
|
+
async function send(addTo = null) {
|
|
97
|
+
if (!r.snapshot || r.problems.length) return;
|
|
98
|
+
r.status = "sending";
|
|
99
|
+
r.message = "";
|
|
100
|
+
refresh();
|
|
101
|
+
try {
|
|
102
|
+
const where = addTo ? `submit?addTo=${addTo}` : "submit";
|
|
103
|
+
const response = await fetch(`${app.base}/${where}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(r.snapshot) });
|
|
104
|
+
const result = await response.json();
|
|
105
|
+
if (response.status === 401) app.github.reload();
|
|
106
|
+
if (!response.ok) throw new Error(result?.error ?? `The bridge answered ${response.status}.`);
|
|
107
|
+
r.status = "sent";
|
|
108
|
+
r.url = result.url;
|
|
109
|
+
r.number = result.number;
|
|
110
|
+
r.added = Boolean(addTo);
|
|
111
|
+
r.similar = null;
|
|
112
|
+
window.open(result.url, "_blank", "noopener");
|
|
113
|
+
app.github.loadIssues();
|
|
114
|
+
} catch (error) {
|
|
115
|
+
r.status = "failed";
|
|
116
|
+
r.message = error.message;
|
|
117
|
+
}
|
|
118
|
+
refresh();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function notice(message) {
|
|
122
|
+
r.status = "notice";
|
|
123
|
+
r.message = message;
|
|
124
|
+
refresh();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function copy() {
|
|
128
|
+
try {
|
|
129
|
+
await navigator.clipboard.writeText(JSON.stringify(r.snapshot, null, 2));
|
|
130
|
+
notice("Copied the snapshot's JSON.");
|
|
131
|
+
} catch {
|
|
132
|
+
notice("The browser did not allow copying; use Download instead.");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function download() {
|
|
137
|
+
const blob = new Blob([`${JSON.stringify(r.snapshot, null, 2)}\n`], { type: "application/json" });
|
|
138
|
+
const link = h("a", { href: URL.createObjectURL(blob), download: "astralis-snapshot.json" });
|
|
139
|
+
link.click();
|
|
140
|
+
setTimeout(() => URL.revokeObjectURL(link.href), 1000);
|
|
141
|
+
notice("Saved astralis-snapshot.json.");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Open GitHub's own form, filled in, to submit there: no sign-in. The page asks the bridge to build the link. */
|
|
145
|
+
async function openOnGitHub() {
|
|
146
|
+
try {
|
|
147
|
+
const response = await fetch(`${app.base}/github/link`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(r.snapshot) });
|
|
148
|
+
const result = await response.json();
|
|
149
|
+
if (!response.ok) throw new Error(result?.error ?? `The bridge answered ${response.status}.`);
|
|
150
|
+
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
|
+
);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
notice(`${error.message} Copy JSON or Download keeps the snapshot.`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
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
|
+
const field = (label, key, multiline, placeholder) => {
|
|
180
|
+
const input = h(multiline ? "textarea" : "input", { class: "field", rows: multiline ? 3 : null, maxlength: multiline ? 4000 : 200, "aria-label": label, placeholder });
|
|
181
|
+
input.value = r[key];
|
|
182
|
+
input.addEventListener("input", () => {
|
|
183
|
+
r[key] = input.value;
|
|
184
|
+
schedule();
|
|
185
|
+
});
|
|
186
|
+
return h("label", { class: "field-label" }, label, input);
|
|
187
|
+
};
|
|
188
|
+
const toggle = (label, key, hint) => {
|
|
189
|
+
const box = h("input", { type: "checkbox" });
|
|
190
|
+
box.checked = r[key];
|
|
191
|
+
box.addEventListener("change", () => {
|
|
192
|
+
r[key] = box.checked;
|
|
193
|
+
schedule();
|
|
194
|
+
});
|
|
195
|
+
const text = h("span", {}, label);
|
|
196
|
+
return { row: h("label", { class: "switch-row toggle" }, h("span", {}, text, h("small", {}, hint)), h("span", { class: "switch" }, box, h("span"))), text };
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const textToggle = toggle("Include page text", "includeText", "Off: text is replaced by its length.");
|
|
200
|
+
const findingsToggle = toggle("Include the validator's findings", "includeFindings", "For the files that render this page.");
|
|
201
|
+
const consoleToggle = toggle("Include console errors", "includeConsole", "Paths are trimmed to the app.");
|
|
202
|
+
const shot = h("div", { class: "shot" });
|
|
203
|
+
const preview = h("pre", { class: "json", "aria-label": "Snapshot JSON" });
|
|
204
|
+
const problems = h("ul", { class: "problems" });
|
|
205
|
+
const status = h("p", { class: "report-status" });
|
|
206
|
+
const similar = h("div", {});
|
|
207
|
+
const sendButton = h("button", { class: "btn primary", type: "button", onclick: () => send() }, icon(GITHUB_MARK), h("span", {}, "Open issue on GitHub"));
|
|
208
|
+
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");
|
|
209
|
+
const copyButton = h("button", { class: "btn", type: "button", onclick: copy }, icon(ICONS.copy), "Copy JSON");
|
|
210
|
+
const downloadButton = h("button", { class: "btn", type: "button", onclick: download }, icon(ICONS.download), "Download");
|
|
211
|
+
|
|
212
|
+
const root = h(
|
|
213
|
+
"div",
|
|
214
|
+
{ class: "report stack" },
|
|
215
|
+
h(
|
|
216
|
+
"div",
|
|
217
|
+
{ class: "card target" },
|
|
218
|
+
h("span", { class: "detail-icon" }, icon(ICONS.components)),
|
|
219
|
+
h("div", { class: "grow" }, h("div", { class: "name" }, readIdentity(element)[0]?.name ?? "Component"), h("div", { class: "muted", style: "font-size:12px" }, "and everything inside it. Nothing is sent until you press Send.")),
|
|
220
|
+
h("button", { class: "btn ghost", type: "button", onclick: () => app.startPicking("report") }, icon(ICONS.pick), "Change"),
|
|
221
|
+
),
|
|
222
|
+
field("Title", "title", false, "Card loses its border in dark mode"),
|
|
223
|
+
field("What happened?", "happened", true, "What you saw"),
|
|
224
|
+
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, h("div", { class: "switch-row", style: "cursor:default" }, h("span", {}, "Screenshot", h("small", {}, "Captured only when you ask. You add it to the issue yourself.")), shot)),
|
|
226
|
+
problems,
|
|
227
|
+
similar,
|
|
228
|
+
h("details", { class: "json-box" }, h("summary", {}, icon(ICONS.chevron), "Exactly what will be sent"), preview),
|
|
229
|
+
h("div", { class: "row" }, sendButton, linkButton, copyButton, downloadButton),
|
|
230
|
+
status,
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
/** The issues that may already report this, with a way to add to one instead of opening another. */
|
|
234
|
+
function similarCard() {
|
|
235
|
+
const found = r.similar;
|
|
236
|
+
if (!found || (!found.duplicates.length && !found.related.length)) return null;
|
|
237
|
+
const row = (issue, canAdd) =>
|
|
238
|
+
h(
|
|
239
|
+
"div",
|
|
240
|
+
{ class: "similar-row" },
|
|
241
|
+
icon(issue.state === "closed" ? ICONS.issueClosed : ICONS.issueOpen, `icon state ${issue.state}`),
|
|
242
|
+
h(
|
|
243
|
+
"a",
|
|
244
|
+
{ class: "grow similar-title", href: issue.url, target: "_blank", rel: "noreferrer" },
|
|
245
|
+
h("span", { class: "faint" }, `#${issue.number} `),
|
|
246
|
+
issue.title,
|
|
247
|
+
),
|
|
248
|
+
canAdd
|
|
249
|
+
? h("button", { class: "btn", type: "button", disabled: !r.snapshot || r.problems.length > 0 || r.status === "sending", onclick: () => send(issue.number) }, "Add my report here")
|
|
250
|
+
: null,
|
|
251
|
+
);
|
|
252
|
+
return h(
|
|
253
|
+
"div",
|
|
254
|
+
{ class: `card similar${found.duplicates.length ? " likely" : ""}` },
|
|
255
|
+
found.duplicates.length
|
|
256
|
+
? [
|
|
257
|
+
h("div", { class: "similar-head" }, icon(ICONS.copy), "This may already be reported"),
|
|
258
|
+
h("p", { class: "muted small" }, "Same component, same rule codes, same astralis-ui version. Adding your report to it tells the maintainers it happens to more people."),
|
|
259
|
+
found.duplicates.slice(0, 3).map((issue) => row(issue, true)),
|
|
260
|
+
]
|
|
261
|
+
: null,
|
|
262
|
+
found.related.length
|
|
263
|
+
? [
|
|
264
|
+
h("div", { class: "similar-head quiet" }, `Open issues about ${r.snapshot?.tree?.[0]?.component ?? "this component"}`),
|
|
265
|
+
found.related.map((issue) => row(issue, false)),
|
|
266
|
+
]
|
|
267
|
+
: null,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function refresh() {
|
|
272
|
+
consoleToggle.text.textContent = `Include console errors (${app.consoleErrors.messages.length})`;
|
|
273
|
+
shot.replaceChildren(
|
|
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…";
|
|
284
|
+
problems.replaceChildren(...r.problems.map((p) => h("li", {}, p)));
|
|
285
|
+
const signedIn = Boolean(app.state.github?.login);
|
|
286
|
+
sendButton.disabled = !signedIn || !r.snapshot || r.problems.length > 0 || r.status === "sending";
|
|
287
|
+
sendButton.title = signedIn ? "" : "Sign in with GitHub first";
|
|
288
|
+
linkButton.disabled = !r.snapshot || r.problems.length > 0;
|
|
289
|
+
copyButton.disabled = !r.snapshot;
|
|
290
|
+
downloadButton.disabled = !r.snapshot;
|
|
291
|
+
sendButton.lastChild.textContent = r.status === "sending" ? "Opening…" : "Open issue on GitHub";
|
|
292
|
+
similar.replaceChildren(...[similarCard()].filter(Boolean));
|
|
293
|
+
status.className = `report-status ${r.status}`;
|
|
294
|
+
status.replaceChildren(
|
|
295
|
+
r.status === "sent"
|
|
296
|
+
? h(
|
|
297
|
+
"span",
|
|
298
|
+
{},
|
|
299
|
+
r.added ? `Added your report to #${r.number}. ` : `Opened #${r.number} on GitHub. `,
|
|
300
|
+
h("a", { class: "link", href: r.url, target: "_blank", rel: "noreferrer" }, "View it"),
|
|
301
|
+
r.screenshot
|
|
302
|
+
? h("span", {}, ". GitHub cannot take images by API: ", h("button", { class: "link", type: "button", onclick: downloadScreenshot }, "save the screenshot"), " and drop it into the issue.")
|
|
303
|
+
: ".",
|
|
304
|
+
)
|
|
305
|
+
: r.status === "failed"
|
|
306
|
+
? `${r.message} Nothing was sent; Copy JSON or Download keeps the snapshot.`
|
|
307
|
+
: r.status === "notice"
|
|
308
|
+
? r.message
|
|
309
|
+
: "",
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
refresh();
|
|
314
|
+
schedule();
|
|
315
|
+
return {
|
|
316
|
+
root,
|
|
317
|
+
// Current findings, not the ones from when the form was opened.
|
|
318
|
+
update(reason) {
|
|
319
|
+
refresh();
|
|
320
|
+
if (reason === "findings") schedule();
|
|
321
|
+
},
|
|
322
|
+
dispose: () => clearTimeout(timer),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Who is signed in to GitHub, or how to sign in. */
|
|
327
|
+
function accountCard(app) {
|
|
328
|
+
const gh = app.state.github;
|
|
329
|
+
const repo = gh?.repo ?? "sekiro-9/astralis-ui";
|
|
330
|
+
if (!gh) return h("div", { class: "card account" }, h("div", { class: "skeleton", style: "width:50%" }));
|
|
331
|
+
if (!gh.configured) {
|
|
332
|
+
return h(
|
|
333
|
+
"div",
|
|
334
|
+
{ class: "notice" },
|
|
335
|
+
"GitHub sign-in is not set up in this version of the DevTools. Use Open on GitHub instead below: it fills in GitHub's own form, and you submit it there.",
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
if (gh.login) {
|
|
339
|
+
return h(
|
|
340
|
+
"div",
|
|
341
|
+
{ class: "card account" },
|
|
342
|
+
h("span", { class: "gh-avatar" }, gh.login[0].toUpperCase()),
|
|
343
|
+
h("div", { class: "grow" }, h("div", { class: "account-name" }, gh.login), h("div", { class: "muted small" }, `Reports open issues on ${repo} as you.`)),
|
|
344
|
+
h("button", { class: "btn ghost", type: "button", onclick: () => app.github.signOut() }, icon(ICONS.signOut), "Sign out"),
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
if (gh.pending) {
|
|
348
|
+
const copied = h("span", {}, "Copy code");
|
|
349
|
+
return h(
|
|
350
|
+
"div",
|
|
351
|
+
{ class: "card account pending" },
|
|
352
|
+
h(
|
|
353
|
+
"div",
|
|
354
|
+
{ class: "grow" },
|
|
355
|
+
h("div", { class: "muted small" }, "Enter this code on GitHub"),
|
|
356
|
+
h("div", { class: "device-code", "aria-label": "Sign-in code" }, gh.pending.userCode),
|
|
357
|
+
h("div", { class: "row waiting" }, h("span", { class: "spinner" }), "Waiting for you to enter it…"),
|
|
358
|
+
),
|
|
359
|
+
h(
|
|
360
|
+
"div",
|
|
361
|
+
{ class: "account-actions" },
|
|
362
|
+
h("a", { class: "btn primary", href: gh.pending.verificationUri, target: "_blank", rel: "noreferrer" }, icon(GITHUB_MARK), "Open GitHub"),
|
|
363
|
+
h(
|
|
364
|
+
"button",
|
|
365
|
+
{
|
|
366
|
+
class: "btn",
|
|
367
|
+
type: "button",
|
|
368
|
+
onclick: async () => {
|
|
369
|
+
try {
|
|
370
|
+
await navigator.clipboard.writeText(gh.pending.userCode);
|
|
371
|
+
copied.textContent = "Copied";
|
|
372
|
+
} catch {
|
|
373
|
+
copied.textContent = "Copy it by hand";
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
icon(ICONS.copy),
|
|
378
|
+
copied,
|
|
379
|
+
),
|
|
380
|
+
h("button", { class: "btn ghost", type: "button", onclick: () => app.github.signOut() }, "Cancel"),
|
|
381
|
+
),
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
return h(
|
|
385
|
+
"div",
|
|
386
|
+
{ class: "card account" },
|
|
387
|
+
h("span", { class: "gh-avatar muted-avatar" }, icon(GITHUB_MARK)),
|
|
388
|
+
h(
|
|
389
|
+
"div",
|
|
390
|
+
{ class: "grow" },
|
|
391
|
+
h("div", { class: "account-name" }, "Sign in to report"),
|
|
392
|
+
h("div", { class: "muted small" }, `Issues open on ${repo} from your own account. The app can only read and write issues there. Or use Open on GitHub instead, with no sign-in.`),
|
|
393
|
+
gh.error ? h("div", { class: "account-error" }, gh.error) : null,
|
|
394
|
+
),
|
|
395
|
+
h("button", { class: "btn primary", type: "button", onclick: () => app.github.signIn() }, icon(GITHUB_MARK), "Sign in with GitHub"),
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const ago = (iso) => {
|
|
400
|
+
const seconds = Math.max(0, (Date.now() - Date.parse(iso)) / 1000);
|
|
401
|
+
const units = [["year", 31536000], ["month", 2592000], ["day", 86400], ["hour", 3600], ["minute", 60]];
|
|
402
|
+
for (const [unit, size] of units) if (seconds >= size) return `${plural(Math.floor(seconds / size), unit)} ago`;
|
|
403
|
+
return "just now";
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
/** The issues the reporter has opened, and where each stands. */
|
|
407
|
+
function yourIssues(app) {
|
|
408
|
+
const root = h("div", {});
|
|
409
|
+
function update() {
|
|
410
|
+
const gh = app.state.github;
|
|
411
|
+
const issues = app.state.issues;
|
|
412
|
+
if (!gh?.login) {
|
|
413
|
+
root.replaceChildren(empty(ICONS.report, "Your issues show here", "Sign in with GitHub to see the issues you have opened and where each stands.", { neutral: true }));
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const list = issues.list;
|
|
417
|
+
const head = h(
|
|
418
|
+
"div",
|
|
419
|
+
{ class: "row", style: "margin-bottom:10px" },
|
|
420
|
+
h("span", { class: "muted grow small" }, list ? `${list.filter((i) => i.state === "open").length} open, ${list.filter((i) => i.state === "closed").length} closed` : ""),
|
|
421
|
+
h(
|
|
422
|
+
"button",
|
|
423
|
+
{ class: "icon-button", type: "button", "aria-label": "Refresh", title: "Refresh", onclick: () => app.github.loadIssues() },
|
|
424
|
+
icon(ICONS.refresh, `icon${issues.loading ? " spinning" : ""}`),
|
|
425
|
+
),
|
|
426
|
+
);
|
|
427
|
+
if (issues.error) return root.replaceChildren(head, h("div", { class: "notice" }, issues.error));
|
|
428
|
+
if (!list) return root.replaceChildren(head, h("div", { class: "stack" }, h("div", { class: "skeleton" }), h("div", { class: "skeleton", style: "width:70%" })));
|
|
429
|
+
if (!list.length) return root.replaceChildren(head, empty(ICONS.check, "No issues yet", "Reports you send open here, with their status as the maintainers work on them."));
|
|
430
|
+
root.replaceChildren(
|
|
431
|
+
head,
|
|
432
|
+
h(
|
|
433
|
+
"div",
|
|
434
|
+
{ class: "file-card issue-list" },
|
|
435
|
+
list.map((issue) => {
|
|
436
|
+
const closed = issue.state === "closed";
|
|
437
|
+
const skipped = closed && issue.stateReason === "not_planned";
|
|
438
|
+
const status = closed ? (skipped ? "Closed, not planned" : "Closed, done") : "Open";
|
|
439
|
+
return h(
|
|
440
|
+
"a",
|
|
441
|
+
{ class: `issue-row ${closed ? (skipped ? "skipped" : "done") : "open"}`, href: issue.url, target: "_blank", rel: "noreferrer" },
|
|
442
|
+
icon(closed ? ICONS.issueClosed : ICONS.issueOpen, "icon state"),
|
|
443
|
+
h(
|
|
444
|
+
"div",
|
|
445
|
+
{ class: "grow" },
|
|
446
|
+
h("div", { class: "issue-title" }, issue.title),
|
|
447
|
+
h("div", { class: "issue-meta" }, `#${issue.number} · ${status} · updated ${ago(issue.updatedAt)}`, issue.comments ? ` · ${plural(issue.comments, "comment")}` : ""),
|
|
448
|
+
issue.labels.length ? h("div", { class: "tags", style: "margin-top:6px" }, issue.labels.map((label) => h("span", { class: "pill" }, label))) : null,
|
|
449
|
+
),
|
|
450
|
+
icon(ICONS.external, "icon go"),
|
|
451
|
+
);
|
|
452
|
+
}),
|
|
453
|
+
),
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
update();
|
|
457
|
+
return { root, update };
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export function reportScreen(app) {
|
|
461
|
+
const { state } = app;
|
|
462
|
+
const account = h("div", {});
|
|
463
|
+
const tabs = h("div", { class: "segmented", role: "tablist", style: "margin:0 0 14px" });
|
|
464
|
+
const body = h("div", {});
|
|
465
|
+
let view = null;
|
|
466
|
+
|
|
467
|
+
function drawTabs() {
|
|
468
|
+
const count = state.issues.list?.length;
|
|
469
|
+
const tab = (id, label) =>
|
|
470
|
+
h("button", { type: "button", role: "tab", "data-tab": id, "aria-selected": String(state.reportTab === id), "aria-pressed": String(state.reportTab === id), onclick: () => show(id) }, label);
|
|
471
|
+
tabs.replaceChildren(tab("new", "New report"), tab("issues", count ? `Your issues (${count})` : "Your issues"));
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function show(tab) {
|
|
475
|
+
state.reportTab = tab;
|
|
476
|
+
view?.dispose?.();
|
|
477
|
+
view = tab === "issues" ? yourIssues(app) : newReport(app);
|
|
478
|
+
body.replaceChildren(view.root);
|
|
479
|
+
drawTabs();
|
|
480
|
+
if (tab === "issues" && state.github?.login && !state.issues.list && !state.issues.loading) app.github.loadIssues();
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const root = h("div", { class: "stack" }, account, h("div", {}, tabs, body));
|
|
484
|
+
account.replaceChildren(accountCard(app));
|
|
485
|
+
show(state.reportTab ?? "new");
|
|
486
|
+
return {
|
|
487
|
+
title: [{ label: "Report" }],
|
|
488
|
+
root,
|
|
489
|
+
update(reason) {
|
|
490
|
+
if (reason === "github") {
|
|
491
|
+
account.replaceChildren(accountCard(app));
|
|
492
|
+
drawTabs();
|
|
493
|
+
}
|
|
494
|
+
view.update(reason);
|
|
495
|
+
},
|
|
496
|
+
dispose: () => view?.dispose?.(),
|
|
497
|
+
};
|
|
498
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { filePath, h, icon } from "../dom.mjs";
|
|
2
|
+
import { ICONS } from "../icons.mjs";
|
|
3
|
+
|
|
4
|
+
/* Pieces more than one screen draws. */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One finding: where it is, what is wrong, and the component it is on. The
|
|
8
|
+
* component is a link to that component on the page when the page has it.
|
|
9
|
+
*/
|
|
10
|
+
export function findingRow(app, finding, { showFile = false, exactLabel = null, showComponent = true } = {}) {
|
|
11
|
+
const target = finding.component ? app.instanceFor(finding) : null;
|
|
12
|
+
const component = finding.component && showComponent
|
|
13
|
+
? target
|
|
14
|
+
? h("button", { class: "chip", type: "button", title: "Inspect it on the page", onclick: () => app.openComponent(target.element) }, finding.component, icon(ICONS.chevron))
|
|
15
|
+
: h("span", { class: "chip", title: "Not on this page" }, finding.component)
|
|
16
|
+
: null;
|
|
17
|
+
return h(
|
|
18
|
+
"div",
|
|
19
|
+
{ class: `finding ${finding.kind}` },
|
|
20
|
+
h("span", { class: "at" }, `${finding.line}:${finding.column}`),
|
|
21
|
+
h("span", { class: "message" }, finding.message),
|
|
22
|
+
h(
|
|
23
|
+
"div",
|
|
24
|
+
{ class: "meta" },
|
|
25
|
+
exactLabel ? h("span", { class: "chip exact" }, icon(ICONS.check), exactLabel) : null,
|
|
26
|
+
component,
|
|
27
|
+
showFile ? h("span", { class: "chip" }, filePath(finding.file)) : null,
|
|
28
|
+
h("span", { class: "rule" }, finding.code),
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A friendly empty state. */
|
|
34
|
+
export function empty(iconMarkup, title, text, { neutral = false } = {}) {
|
|
35
|
+
return h("div", { class: `empty${neutral ? " neutral" : ""}` }, icon(iconMarkup), h("h3", {}, title), text ? h("p", {}, text) : null);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The bridge cannot be reached: say what to add, for the framework in use. */
|
|
39
|
+
export function bridgeMissing(app) {
|
|
40
|
+
const { base, framework } = app;
|
|
41
|
+
return h(
|
|
42
|
+
"div",
|
|
43
|
+
{ class: "notice" },
|
|
44
|
+
h("p", { style: "margin-bottom:8px" }, "The DevTools bridge is not answering at ", h("code", {}, base), "."),
|
|
45
|
+
framework === "next"
|
|
46
|
+
? h(
|
|
47
|
+
"p",
|
|
48
|
+
{},
|
|
49
|
+
"Add ",
|
|
50
|
+
h("code", {}, "app/api/astralis-devtools/[...path]/route.ts"),
|
|
51
|
+
" containing ",
|
|
52
|
+
h("code", {}, 'export { GET, POST } from "astralis-devtools/next/route";'),
|
|
53
|
+
", or run ",
|
|
54
|
+
h("code", {}, "astralis init --devtools"),
|
|
55
|
+
".",
|
|
56
|
+
)
|
|
57
|
+
: h("p", {}, "Is the dev server running? The bridge answers this machine only."),
|
|
58
|
+
);
|
|
59
|
+
}
|