@wastech-mdlint/viewer 0.0.0-stage → 0.4.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/LICENSE +21 -0
- package/README.md +86 -2
- package/assets/favicon.ico +0 -0
- package/assets/viewer.css +4184 -0
- package/dist/asset-routes.d.ts +4 -0
- package/dist/asset-routes.js +107 -0
- package/dist/blame.d.ts +8 -0
- package/dist/blame.js +54 -0
- package/dist/branch-changes.d.ts +8 -0
- package/dist/branch-changes.js +49 -0
- package/dist/candidate-lint-worker.d.ts +1 -0
- package/dist/candidate-lint-worker.js +67 -0
- package/dist/candidate-lint.d.ts +39 -0
- package/dist/candidate-lint.js +115 -0
- package/dist/change-banner.d.ts +38 -0
- package/dist/change-banner.js +108 -0
- package/dist/change-diff.d.ts +23 -0
- package/dist/change-diff.js +140 -0
- package/dist/change-marks.d.ts +32 -0
- package/dist/change-marks.js +363 -0
- package/dist/changes-article.d.ts +15 -0
- package/dist/changes-article.js +244 -0
- package/dist/changes-routes.d.ts +12 -0
- package/dist/changes-routes.js +271 -0
- package/dist/changes.d.ts +113 -0
- package/dist/changes.js +324 -0
- package/dist/cli-args.d.ts +21 -0
- package/dist/cli-args.js +93 -0
- package/dist/client/banner-height.d.ts +1 -0
- package/dist/client/banner-height.js +33 -0
- package/dist/client/change-marks.d.ts +1 -0
- package/dist/client/change-marks.js +56 -0
- package/dist/client/changes.d.ts +1 -0
- package/dist/client/changes.js +183 -0
- package/dist/client/chart-option.d.ts +3 -0
- package/dist/client/chart-option.js +76 -0
- package/dist/client/charts.d.ts +1 -0
- package/dist/client/charts.js +54 -0
- package/dist/client/clipboard.d.ts +1 -0
- package/dist/client/clipboard.js +43 -0
- package/dist/client/code-copy.d.ts +1 -0
- package/dist/client/code-copy.js +29 -0
- package/dist/client/column-resize.d.ts +1 -0
- package/dist/client/column-resize.js +120 -0
- package/dist/client/config-dom.d.ts +13 -0
- package/dist/client/config-dom.js +47 -0
- package/dist/client/config-draft.d.ts +73 -0
- package/dist/client/config-draft.js +218 -0
- package/dist/client/config-editor.d.ts +3 -0
- package/dist/client/config-editor.js +677 -0
- package/dist/client/config-fields.d.ts +35 -0
- package/dist/client/config-fields.js +339 -0
- package/dist/client/config-json.d.ts +18 -0
- package/dist/client/config-json.js +96 -0
- package/dist/client/config-preview.d.ts +9 -0
- package/dist/client/config-preview.js +91 -0
- package/dist/client/config-rules.d.ts +14 -0
- package/dist/client/config-rules.js +202 -0
- package/dist/client/config-types.d.ts +91 -0
- package/dist/client/config-types.js +4 -0
- package/dist/client/copy-path.d.ts +1 -0
- package/dist/client/copy-path.js +32 -0
- package/dist/client/dashboard-requests.d.ts +11 -0
- package/dist/client/dashboard-requests.js +28 -0
- package/dist/client/dashboard.d.ts +1 -0
- package/dist/client/dashboard.js +119 -0
- package/dist/client/diagnostics.d.ts +1 -0
- package/dist/client/diagnostics.js +164 -0
- package/dist/client/diagrams.d.ts +1 -0
- package/dist/client/diagrams.js +81 -0
- package/dist/client/diff-expand.d.ts +1 -0
- package/dist/client/diff-expand.js +42 -0
- package/dist/client/display-settings-model.d.ts +74 -0
- package/dist/client/display-settings-model.js +229 -0
- package/dist/client/display-settings.d.ts +1 -0
- package/dist/client/display-settings.js +411 -0
- package/dist/client/echarts.d.ts +30 -0
- package/dist/client/echarts.js +14 -0
- package/dist/client/graph-layout.d.ts +88 -0
- package/dist/client/graph-layout.js +198 -0
- package/dist/client/graph.d.ts +2 -0
- package/dist/client/graph.js +566 -0
- package/dist/client/history.d.ts +21 -0
- package/dist/client/history.js +86 -0
- package/dist/client/live-reload-model.d.ts +28 -0
- package/dist/client/live-reload-model.js +52 -0
- package/dist/client/live-reload.d.ts +9 -0
- package/dist/client/live-reload.js +138 -0
- package/dist/client/menu.d.ts +14 -0
- package/dist/client/menu.js +176 -0
- package/dist/client/navigation-feedback.d.ts +1 -0
- package/dist/client/navigation-feedback.js +141 -0
- package/dist/client/open-config.d.ts +1 -0
- package/dist/client/open-config.js +48 -0
- package/dist/client/outline-spy.d.ts +1 -0
- package/dist/client/outline-spy.js +60 -0
- package/dist/client/prompts.d.ts +7 -0
- package/dist/client/prompts.js +65 -0
- package/dist/client/review.d.ts +1 -0
- package/dist/client/review.js +379 -0
- package/dist/client/search.d.ts +1 -0
- package/dist/client/search.js +199 -0
- package/dist/client/segmented.d.ts +13 -0
- package/dist/client/segmented.js +70 -0
- package/dist/client/source-lines.d.ts +16 -0
- package/dist/client/source-lines.js +47 -0
- package/dist/client/theme-toggle.d.ts +10 -0
- package/dist/client/theme-toggle.js +100 -0
- package/dist/client/theme.d.ts +0 -0
- package/dist/client/theme.js +50 -0
- package/dist/client/tree-marks.d.ts +31 -0
- package/dist/client/tree-marks.js +102 -0
- package/dist/client/tree-state.d.ts +0 -0
- package/dist/client/tree-state.js +179 -0
- package/dist/client/viewer.d.ts +1 -0
- package/dist/client/viewer.js +53 -0
- package/dist/config-editor.d.ts +166 -0
- package/dist/config-editor.js +378 -0
- package/dist/config-routes.d.ts +18 -0
- package/dist/config-routes.js +213 -0
- package/dist/context-view.d.ts +41 -0
- package/dist/context-view.js +295 -0
- package/dist/corpus-routes.d.ts +31 -0
- package/dist/corpus-routes.js +258 -0
- package/dist/corpus.d.ts +134 -0
- package/dist/corpus.js +653 -0
- package/dist/dashboard-article.d.ts +14 -0
- package/dist/dashboard-article.js +290 -0
- package/dist/dashboard.d.ts +94 -0
- package/dist/dashboard.js +468 -0
- package/dist/diagnostics.d.ts +23 -0
- package/dist/diagnostics.js +44 -0
- package/dist/document-routes.d.ts +39 -0
- package/dist/document-routes.js +396 -0
- package/dist/event-hub.d.ts +39 -0
- package/dist/event-hub.js +120 -0
- package/dist/findings-panel.d.ts +4 -0
- package/dist/findings-panel.js +74 -0
- package/dist/folder-page.d.ts +8 -0
- package/dist/folder-page.js +74 -0
- package/dist/graph-view.d.ts +66 -0
- package/dist/graph-view.js +236 -0
- package/dist/highlight.d.ts +24 -0
- package/dist/highlight.js +100 -0
- package/dist/http-send.d.ts +9 -0
- package/dist/http-send.js +53 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +72 -0
- package/dist/open-file.d.ts +36 -0
- package/dist/open-file.js +87 -0
- package/dist/page-tree.d.ts +3 -0
- package/dist/page-tree.js +105 -0
- package/dist/page.d.ts +73 -0
- package/dist/page.js +478 -0
- package/dist/prompts.d.ts +25 -0
- package/dist/prompts.js +82 -0
- package/dist/render-cache.d.ts +23 -0
- package/dist/render-cache.js +38 -0
- package/dist/render-document.d.ts +60 -0
- package/dist/render-document.js +440 -0
- package/dist/request-path.d.ts +17 -0
- package/dist/request-path.js +51 -0
- package/dist/review-context.d.ts +24 -0
- package/dist/review-context.js +109 -0
- package/dist/review-queries.d.ts +26 -0
- package/dist/review-queries.js +69 -0
- package/dist/review-state.d.ts +106 -0
- package/dist/review-state.js +251 -0
- package/dist/review-store.d.ts +145 -0
- package/dist/review-store.js +530 -0
- package/dist/router.d.ts +28 -0
- package/dist/router.js +294 -0
- package/dist/search.d.ts +22 -0
- package/dist/search.js +164 -0
- package/dist/security.d.ts +95 -0
- package/dist/security.js +196 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.js +224 -0
- package/dist/speculation-rules.d.ts +4 -0
- package/dist/speculation-rules.js +49 -0
- package/dist/state-dir.d.ts +6 -0
- package/dist/state-dir.js +31 -0
- package/dist/tree-marks.d.ts +49 -0
- package/dist/tree-marks.js +108 -0
- package/dist/viewer-context.d.ts +37 -0
- package/dist/viewer-context.js +74 -0
- package/dist/watch.d.ts +41 -0
- package/dist/watch.js +135 -0
- package/package.json +57 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every event name the server's `EventHub` sends: each `broadcast` call's name, and `missed`, which
|
|
3
|
+
* the hub sends itself. The stream listens for all of them only to learn their ids — a page that is
|
|
4
|
+
* hidden closes its stream and reopens it from the last id it holds, so an id it never heard would
|
|
5
|
+
* have the server send that event again, and enough of them would read as more missed than it keeps.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SERVER_EVENTS: readonly ["change", "diagnostics", "git", "missed", "review"];
|
|
8
|
+
/**
|
|
9
|
+
* The last event this page holds, as the id the server gave it. It starts as the id the page was
|
|
10
|
+
* served with and follows every event received, as a browser's own `Last-Event-ID` does.
|
|
11
|
+
*
|
|
12
|
+
* A browser sends `Last-Event-ID` only when it reconnects a stream by itself; a stream this page
|
|
13
|
+
* closed and opens again is a new `EventSource`, which sends none. So the id goes in the address
|
|
14
|
+
* instead, as the `seen` the server already reads from a page's first connection: the server sends
|
|
15
|
+
* every event after it, or `missed` when they are no longer kept or the server is not the run that
|
|
16
|
+
* gave the id, and nothing that happened while the stream was closed is lost.
|
|
17
|
+
*/
|
|
18
|
+
export declare class StreamPosition {
|
|
19
|
+
private seen;
|
|
20
|
+
constructor(served: string | undefined);
|
|
21
|
+
/** Note the id of an event just received; an event without one leaves the position as it was. */
|
|
22
|
+
receive(id: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* The stream's address from here. Without an id — a page served without one, which has
|
|
25
|
+
* received nothing since — the server sends only what happens from now on.
|
|
26
|
+
*/
|
|
27
|
+
get url(): string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// The part of the event stream's bookkeeping that needs no browser: which events the server sends,
|
|
2
|
+
// and where a stream closed by this page resumes from.
|
|
3
|
+
/**
|
|
4
|
+
* Every event name the server's `EventHub` sends: each `broadcast` call's name, and `missed`, which
|
|
5
|
+
* the hub sends itself. The stream listens for all of them only to learn their ids — a page that is
|
|
6
|
+
* hidden closes its stream and reopens it from the last id it holds, so an id it never heard would
|
|
7
|
+
* have the server send that event again, and enough of them would read as more missed than it keeps.
|
|
8
|
+
*/
|
|
9
|
+
export const SERVER_EVENTS = [
|
|
10
|
+
"change",
|
|
11
|
+
"diagnostics",
|
|
12
|
+
"git",
|
|
13
|
+
"missed",
|
|
14
|
+
"review",
|
|
15
|
+
];
|
|
16
|
+
// The form the server accepts as an event number; anything else would be ignored there, so it is
|
|
17
|
+
// not kept here either.
|
|
18
|
+
// The server's event id: its run's tag and the event's number. The tag is what lets a server that
|
|
19
|
+
// restarted while this page's stream was closed see that the page's position is from another run.
|
|
20
|
+
const EVENT_ID = /^[0-9a-f]{8}\.\d{1,15}$/;
|
|
21
|
+
/**
|
|
22
|
+
* The last event this page holds, as the id the server gave it. It starts as the id the page was
|
|
23
|
+
* served with and follows every event received, as a browser's own `Last-Event-ID` does.
|
|
24
|
+
*
|
|
25
|
+
* A browser sends `Last-Event-ID` only when it reconnects a stream by itself; a stream this page
|
|
26
|
+
* closed and opens again is a new `EventSource`, which sends none. So the id goes in the address
|
|
27
|
+
* instead, as the `seen` the server already reads from a page's first connection: the server sends
|
|
28
|
+
* every event after it, or `missed` when they are no longer kept or the server is not the run that
|
|
29
|
+
* gave the id, and nothing that happened while the stream was closed is lost.
|
|
30
|
+
*/
|
|
31
|
+
export class StreamPosition {
|
|
32
|
+
seen;
|
|
33
|
+
constructor(served) {
|
|
34
|
+
this.seen =
|
|
35
|
+
served !== undefined && EVENT_ID.test(served) ? served : undefined;
|
|
36
|
+
}
|
|
37
|
+
/** Note the id of an event just received; an event without one leaves the position as it was. */
|
|
38
|
+
receive(id) {
|
|
39
|
+
if (EVENT_ID.test(id)) {
|
|
40
|
+
this.seen = id;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The stream's address from here. Without an id — a page served without one, which has
|
|
45
|
+
* received nothing since — the server sends only what happens from now on.
|
|
46
|
+
*/
|
|
47
|
+
get url() {
|
|
48
|
+
return this.seen === undefined
|
|
49
|
+
? "/events"
|
|
50
|
+
: `/events?${new URLSearchParams({ seen: this.seen }).toString()}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Listen for a named server event. */
|
|
2
|
+
export declare function onServerEvent(name: string, listener: (data: string) => void): void;
|
|
3
|
+
/**
|
|
4
|
+
* Reload when what this page shows changes on disk, keeping the scroll position.
|
|
5
|
+
*
|
|
6
|
+
* `documentPath` is set on a document page only; every page reloads on a structural change, because
|
|
7
|
+
* every page shows the document tree.
|
|
8
|
+
*/
|
|
9
|
+
export declare function initLiveReload(documentPath: string | undefined): void;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { SERVER_EVENTS, StreamPosition } from "./live-reload-model.js";
|
|
2
|
+
// Every listener the page's modules added, so a stream opened again gets all of them back.
|
|
3
|
+
const listeners = [];
|
|
4
|
+
let position;
|
|
5
|
+
let events;
|
|
6
|
+
// The page is served with the id of the last event its state includes, and connects with it, so
|
|
7
|
+
// the server first sends whatever happened between serving the page and this connection. The
|
|
8
|
+
// listeners are all added in the module scripts' first turn, before any of it can arrive.
|
|
9
|
+
function listen(name, handle) {
|
|
10
|
+
listeners.push({ name, handle });
|
|
11
|
+
events?.addEventListener(name, handle);
|
|
12
|
+
if (position !== undefined) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
position = new StreamPosition(document.querySelector('meta[name="wastech-events"]')
|
|
16
|
+
?.content);
|
|
17
|
+
document.addEventListener("visibilitychange", () => {
|
|
18
|
+
if (document.visibilityState === "visible") {
|
|
19
|
+
connect();
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
disconnect();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
// A page kept in the back-forward cache is hidden without being unloaded, and one restored from it
|
|
26
|
+
// is shown again without loading; an open stream would also keep some browsers from caching it.
|
|
27
|
+
window.addEventListener("pagehide", disconnect);
|
|
28
|
+
window.addEventListener("pageshow", connect);
|
|
29
|
+
connect();
|
|
30
|
+
}
|
|
31
|
+
// A page opened in a background tab connects only once it is first shown, so a burst of tabs opened
|
|
32
|
+
// at once holds no connection until each is read.
|
|
33
|
+
function connect() {
|
|
34
|
+
if (events !== undefined ||
|
|
35
|
+
position === undefined ||
|
|
36
|
+
document.visibilityState !== "visible") {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const from = position;
|
|
40
|
+
const source = new EventSource(from.url);
|
|
41
|
+
for (const name of SERVER_EVENTS) {
|
|
42
|
+
source.addEventListener(name, (event) => {
|
|
43
|
+
from.receive(event.lastEventId);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
for (const { name, handle } of listeners) {
|
|
47
|
+
source.addEventListener(name, handle);
|
|
48
|
+
}
|
|
49
|
+
events = source;
|
|
50
|
+
}
|
|
51
|
+
// Closing a stream fires no `error`, so the reload that reconnecting after a lost connection triggers
|
|
52
|
+
// does not follow a stream this page closed itself.
|
|
53
|
+
function disconnect() {
|
|
54
|
+
events?.close();
|
|
55
|
+
events = undefined;
|
|
56
|
+
}
|
|
57
|
+
/** Listen for a named server event. */
|
|
58
|
+
export function onServerEvent(name, listener) {
|
|
59
|
+
listen(name, (event) => {
|
|
60
|
+
listener(event.data);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const scrollKey = `wastech-mdlint-viewer:scroll:${location.pathname}`;
|
|
64
|
+
/**
|
|
65
|
+
* Reload when what this page shows changes on disk, keeping the scroll position.
|
|
66
|
+
*
|
|
67
|
+
* `documentPath` is set on a document page only; every page reloads on a structural change, because
|
|
68
|
+
* every page shows the document tree.
|
|
69
|
+
*/
|
|
70
|
+
export function initLiveReload(documentPath) {
|
|
71
|
+
restoreScroll();
|
|
72
|
+
let disconnected = false;
|
|
73
|
+
listen("error", () => {
|
|
74
|
+
disconnected = true;
|
|
75
|
+
});
|
|
76
|
+
// Reconnecting after a lost connection means the server restarted, possibly with different files
|
|
77
|
+
// or a different config, so whatever this page shows may be stale. A server that restarted while
|
|
78
|
+
// this page's stream was closed shows instead as `missed`: the id the page reopens with carries
|
|
79
|
+
// the earlier run's tag, which the new server does not have.
|
|
80
|
+
listen("open", () => {
|
|
81
|
+
if (disconnected) {
|
|
82
|
+
reloadKeepingScroll();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
// More happened since the page was served than the server keeps to send again, or the server that
|
|
86
|
+
// served it has restarted: what the page shows cannot be brought up to date piece by piece.
|
|
87
|
+
onServerEvent("missed", () => {
|
|
88
|
+
reloadKeepingScroll();
|
|
89
|
+
});
|
|
90
|
+
onServerEvent("change", (data) => {
|
|
91
|
+
const change = JSON.parse(data);
|
|
92
|
+
if (change.structural ||
|
|
93
|
+
(documentPath !== undefined && change.paths.includes(documentPath))) {
|
|
94
|
+
reloadKeepingScroll();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
// A commit, a checkout or a fetch moved what the branch is compared with. Only the pages that show
|
|
98
|
+
// that comparison reload: the Changes page, a changed document's line and marks, and the graph or
|
|
99
|
+
// dashboard asked to show the branch. The header count and the tree refresh on their own.
|
|
100
|
+
onServerEvent("git", () => {
|
|
101
|
+
const params = new URLSearchParams(location.search);
|
|
102
|
+
if (location.pathname === "/changes" ||
|
|
103
|
+
document.querySelector(".changes-banner") !== null ||
|
|
104
|
+
params.get("changes") === "1" ||
|
|
105
|
+
params.get("changed") === "1") {
|
|
106
|
+
reloadKeepingScroll();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// Storage can be unavailable (private windows, blocked site data), and losing the scroll position
|
|
111
|
+
// is the only consequence, so every access is allowed to fail quietly.
|
|
112
|
+
function restoreScroll() {
|
|
113
|
+
try {
|
|
114
|
+
const saved = sessionStorage.getItem(scrollKey);
|
|
115
|
+
if (saved !== null) {
|
|
116
|
+
sessionStorage.removeItem(scrollKey);
|
|
117
|
+
window.scrollTo(0, Number(saved));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Nothing to restore.
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function reloadKeepingScroll() {
|
|
125
|
+
// A page already leaving for another — a click taken, the next page on its way — is not reloaded:
|
|
126
|
+
// the reload would replace that navigation, and the reader would land back on the page they left.
|
|
127
|
+
// The page they are going to is served fresh anyway.
|
|
128
|
+
if (document.documentElement.dataset.navigating !== undefined) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
sessionStorage.setItem(scrollKey, String(window.scrollY));
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Reload anyway; the page opens at the top.
|
|
136
|
+
}
|
|
137
|
+
location.reload();
|
|
138
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type MenuItem = {
|
|
2
|
+
label: string;
|
|
3
|
+
detail?: string;
|
|
4
|
+
unavailable?: string;
|
|
5
|
+
run(): Promise<boolean>;
|
|
6
|
+
};
|
|
7
|
+
export type MenuOptions = {
|
|
8
|
+
doneLabel?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Open a menu under `trigger` on click. `items` is called on every opening, so the choices reflect
|
|
12
|
+
* the page as it is then; it may be asynchronous, and the menu says so while it waits.
|
|
13
|
+
*/
|
|
14
|
+
export declare function attachMenu(trigger: HTMLButtonElement, items: () => MenuItem[] | Promise<MenuItem[]>, options?: MenuOptions): void;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// A small dropdown of actions under a button: the copy-path choices and the fix-prompt choices. It is
|
|
2
|
+
// placed with fixed positioning on <body> rather than inside the button's container, because some of
|
|
3
|
+
// those containers scroll or clip (the dashboard's table scrolls sideways) and would cut it off.
|
|
4
|
+
let openMenu;
|
|
5
|
+
/**
|
|
6
|
+
* Open a menu under `trigger` on click. `items` is called on every opening, so the choices reflect
|
|
7
|
+
* the page as it is then; it may be asynchronous, and the menu says so while it waits.
|
|
8
|
+
*/
|
|
9
|
+
export function attachMenu(trigger, items, options = {}) {
|
|
10
|
+
trigger.setAttribute("aria-haspopup", "menu");
|
|
11
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
12
|
+
trigger.addEventListener("click", (event) => {
|
|
13
|
+
// A trigger inside a <summary> would otherwise fold its <details>.
|
|
14
|
+
event.preventDefault();
|
|
15
|
+
event.stopPropagation();
|
|
16
|
+
const wasThis = openMenu !== undefined &&
|
|
17
|
+
trigger.getAttribute("aria-expanded") === "true";
|
|
18
|
+
openMenu?.close(false);
|
|
19
|
+
if (!wasThis) {
|
|
20
|
+
void show(trigger, items, options);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function show(trigger, items, options) {
|
|
25
|
+
const menu = waitingMenu();
|
|
26
|
+
document.body.append(menu);
|
|
27
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
28
|
+
place(menu, trigger);
|
|
29
|
+
let closed = false;
|
|
30
|
+
const close = (returnFocus) => {
|
|
31
|
+
if (closed) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
closed = true;
|
|
35
|
+
menu.remove();
|
|
36
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
37
|
+
document.removeEventListener("pointerdown", outside, true);
|
|
38
|
+
document.removeEventListener("keydown", keys, true);
|
|
39
|
+
window.removeEventListener("resize", dismiss);
|
|
40
|
+
window.removeEventListener("scroll", dismiss, true);
|
|
41
|
+
if (openMenu === handle) {
|
|
42
|
+
openMenu = undefined;
|
|
43
|
+
}
|
|
44
|
+
if (returnFocus) {
|
|
45
|
+
trigger.focus();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const handle = { close };
|
|
49
|
+
openMenu = handle;
|
|
50
|
+
const outside = (event) => {
|
|
51
|
+
const target = event.target;
|
|
52
|
+
if (target !== null &&
|
|
53
|
+
!menu.contains(target) &&
|
|
54
|
+
!trigger.contains(target)) {
|
|
55
|
+
close(false);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const dismiss = (event) => {
|
|
59
|
+
// Scrolling inside the menu itself is not leaving it.
|
|
60
|
+
if (!(event.target instanceof Node && menu.contains(event.target))) {
|
|
61
|
+
close(false);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const buttons = () => [
|
|
65
|
+
...menu.querySelectorAll("button:not(:disabled)"),
|
|
66
|
+
];
|
|
67
|
+
const keys = (event) => {
|
|
68
|
+
if (event.key === "Escape") {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
event.stopPropagation();
|
|
71
|
+
close(true);
|
|
72
|
+
}
|
|
73
|
+
else if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
const list = buttons();
|
|
76
|
+
const index = list.indexOf(document.activeElement);
|
|
77
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
78
|
+
list[(index + step + list.length) % list.length]?.focus();
|
|
79
|
+
}
|
|
80
|
+
else if (event.key === "Tab") {
|
|
81
|
+
close(false);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
document.addEventListener("pointerdown", outside, true);
|
|
85
|
+
document.addEventListener("keydown", keys, true);
|
|
86
|
+
window.addEventListener("resize", dismiss);
|
|
87
|
+
window.addEventListener("scroll", dismiss, true);
|
|
88
|
+
let entries;
|
|
89
|
+
try {
|
|
90
|
+
entries = await items();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
entries = [];
|
|
94
|
+
}
|
|
95
|
+
// Closed while the entries loaded: `close` takes the menu out of the page.
|
|
96
|
+
if (!menu.isConnected) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
fill(menu, entries, options, close);
|
|
100
|
+
place(menu, trigger);
|
|
101
|
+
buttons()[0]?.focus();
|
|
102
|
+
}
|
|
103
|
+
// Replaces the waiting note with the entries, or with a note saying there are none, so an empty
|
|
104
|
+
// menu still tells the reader why nothing is offered.
|
|
105
|
+
function fill(menu, entries, options, close) {
|
|
106
|
+
menu.replaceChildren();
|
|
107
|
+
if (entries.length === 0) {
|
|
108
|
+
const empty = document.createElement("p");
|
|
109
|
+
empty.className = "menu-note";
|
|
110
|
+
empty.textContent =
|
|
111
|
+
"Nothing to copy right now. Reload the page and try again.";
|
|
112
|
+
menu.append(empty);
|
|
113
|
+
}
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
menu.append(item(entry, options, close));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// The menu opens at once, saying it is loading, so a slow item list still answers the click.
|
|
119
|
+
function waitingMenu() {
|
|
120
|
+
const menu = document.createElement("div");
|
|
121
|
+
menu.className = "menu";
|
|
122
|
+
menu.setAttribute("role", "menu");
|
|
123
|
+
const waiting = document.createElement("p");
|
|
124
|
+
waiting.className = "menu-note";
|
|
125
|
+
waiting.textContent = "Loading…";
|
|
126
|
+
menu.append(waiting);
|
|
127
|
+
return menu;
|
|
128
|
+
}
|
|
129
|
+
function item(entry, options, close) {
|
|
130
|
+
const button = document.createElement("button");
|
|
131
|
+
button.type = "button";
|
|
132
|
+
button.className = "menu-item";
|
|
133
|
+
button.setAttribute("role", "menuitem");
|
|
134
|
+
const label = document.createElement("span");
|
|
135
|
+
label.className = "menu-label";
|
|
136
|
+
label.textContent = entry.label;
|
|
137
|
+
button.append(label);
|
|
138
|
+
const detailText = entry.unavailable ?? entry.detail;
|
|
139
|
+
if (detailText !== undefined) {
|
|
140
|
+
const detail = document.createElement("span");
|
|
141
|
+
detail.className = "menu-detail";
|
|
142
|
+
detail.textContent = detailText;
|
|
143
|
+
button.append(detail);
|
|
144
|
+
}
|
|
145
|
+
if (entry.unavailable !== undefined) {
|
|
146
|
+
button.disabled = true;
|
|
147
|
+
button.title = entry.unavailable;
|
|
148
|
+
}
|
|
149
|
+
button.addEventListener("click", () => {
|
|
150
|
+
void entry.run().then((worked) => {
|
|
151
|
+
label.textContent = worked
|
|
152
|
+
? (options.doneLabel ?? "Copied")
|
|
153
|
+
: "Could not copy";
|
|
154
|
+
window.setTimeout(() => {
|
|
155
|
+
close(true);
|
|
156
|
+
}, worked ? 600 : 1500);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
return button;
|
|
160
|
+
}
|
|
161
|
+
// Under the trigger, its right edges aligned when the menu would otherwise run off the window, and
|
|
162
|
+
// above it when there is no room below.
|
|
163
|
+
function place(menu, trigger) {
|
|
164
|
+
const anchor = trigger.getBoundingClientRect();
|
|
165
|
+
const width = menu.offsetWidth;
|
|
166
|
+
const height = menu.offsetHeight;
|
|
167
|
+
const left = anchor.left + width > window.innerWidth - 8
|
|
168
|
+
? Math.max(8, anchor.right - width)
|
|
169
|
+
: anchor.left;
|
|
170
|
+
const below = anchor.bottom + 4;
|
|
171
|
+
const top = below + height > window.innerHeight - 8 && anchor.top - 4 - height > 8
|
|
172
|
+
? anchor.top - 4 - height
|
|
173
|
+
: below;
|
|
174
|
+
menu.style.left = `${Math.round(left)}px`;
|
|
175
|
+
menu.style.top = `${Math.round(top)}px`;
|
|
176
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initNavigationFeedback(): void;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// What a page shows between a click that leaves it and the next page appearing. Moving between pages
|
|
2
|
+
// is a full page load, and until the next one can be drawn the old one stays on screen unchanged — on
|
|
3
|
+
// the Changes page or the dashboard for a quarter to half a second — with nothing to say the click
|
|
4
|
+
// was taken.
|
|
5
|
+
//
|
|
6
|
+
// So the click answers at once with where it leads: the header's section the next page belongs to
|
|
7
|
+
// is chosen, and the file it opens is marked in the tree, as the next page will show them. When the
|
|
8
|
+
// server keeps it waiting past a moment, a thin bar under the header grows and the pointer says the
|
|
9
|
+
// page is busy. Nothing covers or replaces the page: an indicator shown for the tenth of a second a
|
|
10
|
+
// document takes would itself be a blink, and a page the reader may still be looking at stays as it
|
|
11
|
+
// is.
|
|
12
|
+
// How long the server may take before the bar shows. This page is gone the moment the next one's
|
|
13
|
+
// answer arrives, its bar with it, and the frame left on screen until the next page is drawn is its
|
|
14
|
+
// last; so the bar is for a server that keeps the reader waiting — a review computed afresh, a large
|
|
15
|
+
// repository — and never for the moment a document, or a section fetched as the pointer rested on
|
|
16
|
+
// it, takes.
|
|
17
|
+
const SLOW_AFTER_MS = 200;
|
|
18
|
+
// A navigation the browser drops without a word — stopped with Esc, or answered with a file to
|
|
19
|
+
// save — leaves this page standing; after this long it stops saying it is leaving.
|
|
20
|
+
const GIVE_UP_AFTER_MS = 15_000;
|
|
21
|
+
export function initNavigationFeedback() {
|
|
22
|
+
let slow;
|
|
23
|
+
let giveUp;
|
|
24
|
+
// Where the page is going, so the same departure reported twice — a link this script followed,
|
|
25
|
+
// and the navigation that following it starts — is shown once.
|
|
26
|
+
let pending;
|
|
27
|
+
const reset = () => {
|
|
28
|
+
window.clearTimeout(slow);
|
|
29
|
+
window.clearTimeout(giveUp);
|
|
30
|
+
pending = undefined;
|
|
31
|
+
delete document.documentElement.dataset.navigating;
|
|
32
|
+
for (const marked of document.querySelectorAll("[data-pending]")) {
|
|
33
|
+
marked.removeAttribute("data-pending");
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const show = (url) => {
|
|
37
|
+
if (!isPage(url) || url.href === pending) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
reset();
|
|
41
|
+
pending = url.href;
|
|
42
|
+
markDestination(url);
|
|
43
|
+
document.documentElement.dataset.navigating = "pending";
|
|
44
|
+
slow = window.setTimeout(() => {
|
|
45
|
+
document.documentElement.dataset.navigating = "slow";
|
|
46
|
+
}, SLOW_AFTER_MS);
|
|
47
|
+
giveUp = window.setTimeout(reset, GIVE_UP_AFTER_MS);
|
|
48
|
+
};
|
|
49
|
+
// A page the back button brings back from the browser's cache is shown as it was left, pending.
|
|
50
|
+
window.addEventListener("pageshow", (event) => {
|
|
51
|
+
if (event.persisted) {
|
|
52
|
+
reset();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
// A link is followed only once the page has drawn where it leads. Followed at once, the next page
|
|
56
|
+
// — often fetched already as the pointer rested on the link — took this page's place before the
|
|
57
|
+
// browser drew another frame of it, and the frame left on screen until the next page appeared was
|
|
58
|
+
// the one from before the click. Listened for on the window, after every other listener, so a link
|
|
59
|
+
// a script handles itself, such as the dashboard's column headers, is left to it.
|
|
60
|
+
window.addEventListener("click", (event) => {
|
|
61
|
+
const url = destinationOf(event);
|
|
62
|
+
if (url === undefined || !isPage(url)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
show(url);
|
|
67
|
+
afterNextPaint(() => {
|
|
68
|
+
location.assign(url.href);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
// Every other way of leaving — a form, a script setting `location` — where the browser reports it.
|
|
72
|
+
const navigation = window
|
|
73
|
+
.navigation;
|
|
74
|
+
navigation?.addEventListener("navigate", (event) => {
|
|
75
|
+
const navigate = event;
|
|
76
|
+
if (!navigate.destination.sameDocument &&
|
|
77
|
+
!navigate.hashChange &&
|
|
78
|
+
navigate.downloadRequest === null) {
|
|
79
|
+
show(new URL(navigate.destination.url));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// Runs `then` once the browser has drawn a frame with what was just changed: a timer set from an
|
|
84
|
+
// animation frame fires after that frame is painted. A tab that draws no frames runs it shortly.
|
|
85
|
+
function afterNextPaint(then) {
|
|
86
|
+
let done = false;
|
|
87
|
+
const once = () => {
|
|
88
|
+
if (!done) {
|
|
89
|
+
done = true;
|
|
90
|
+
then();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
requestAnimationFrame(() => {
|
|
94
|
+
window.setTimeout(once, 0);
|
|
95
|
+
});
|
|
96
|
+
window.setTimeout(once, 100);
|
|
97
|
+
}
|
|
98
|
+
// Where a click goes when it follows a link away from this page in this tab: not one another script
|
|
99
|
+
// took, a click that opens a new tab or window or saves a file, or a jump within the page.
|
|
100
|
+
function destinationOf(event) {
|
|
101
|
+
const link = event.target?.closest("a[href]");
|
|
102
|
+
if (link === null ||
|
|
103
|
+
link === undefined ||
|
|
104
|
+
event.defaultPrevented ||
|
|
105
|
+
opensElsewhere(event, link)) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
const url = new URL(link.href);
|
|
109
|
+
const samePage = url.pathname === location.pathname && url.search === location.search;
|
|
110
|
+
return samePage && url.hash !== "" ? undefined : url;
|
|
111
|
+
}
|
|
112
|
+
// A click that leaves this tab as it is: with a key that opens a new tab or window, another button,
|
|
113
|
+
// a link to a file to save, or one that names another window.
|
|
114
|
+
function opensElsewhere(event, link) {
|
|
115
|
+
return (event.button !== 0 ||
|
|
116
|
+
event.ctrlKey ||
|
|
117
|
+
event.metaKey ||
|
|
118
|
+
event.shiftKey ||
|
|
119
|
+
event.altKey ||
|
|
120
|
+
link.hasAttribute("download") ||
|
|
121
|
+
(link.target !== "" && link.target !== "_self"));
|
|
122
|
+
}
|
|
123
|
+
// A page of this viewer, as opposed to its data, assets or event stream, and anything elsewhere.
|
|
124
|
+
function isPage(url) {
|
|
125
|
+
return (url.origin === location.origin &&
|
|
126
|
+
!/^\/(api|assets|vendor)\//.test(url.pathname) &&
|
|
127
|
+
url.pathname !== "/events");
|
|
128
|
+
}
|
|
129
|
+
// The header's section and the tree's file as the next page will show them: the section it belongs
|
|
130
|
+
// to, or none for a document, and the file it opens, or none for anything else. The stylesheet draws
|
|
131
|
+
// a marked one as chosen and the page's own as not, while the wait lasts.
|
|
132
|
+
function markDestination(url) {
|
|
133
|
+
for (const container of document.querySelectorAll(".section-nav, .sidebar")) {
|
|
134
|
+
container.dataset.pending = "";
|
|
135
|
+
for (const link of container.querySelectorAll("a.segment, .tree a[href]")) {
|
|
136
|
+
if (new URL(link.href).pathname === url.pathname) {
|
|
137
|
+
link.dataset.pending = "";
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initOpenConfig(): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// The config page's "Show in folder" and "Open in default app" buttons. Each asks the server to
|
|
2
|
+
// start the system's own program for the config file; the request carries the page's change token
|
|
3
|
+
// like a preview or a save, because it makes the machine running the viewer do something. The
|
|
4
|
+
// server renders the buttons only where opening is allowed, and hidden, since without this script
|
|
5
|
+
// they could do nothing.
|
|
6
|
+
const DONE = {
|
|
7
|
+
reveal: "Shown in the file manager.",
|
|
8
|
+
open: "Opened in the default application.",
|
|
9
|
+
};
|
|
10
|
+
export function initOpenConfig() {
|
|
11
|
+
const row = document.querySelector(".config-open");
|
|
12
|
+
const token = document.querySelector('meta[name="wastech-change-token"]')?.content;
|
|
13
|
+
if (row === null || token === undefined) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
row.hidden = false;
|
|
17
|
+
const status = row.querySelector(".config-open-status");
|
|
18
|
+
for (const button of row.querySelectorAll("button[data-open]")) {
|
|
19
|
+
const action = button.dataset.open ?? "";
|
|
20
|
+
button.addEventListener("click", () => {
|
|
21
|
+
button.disabled = true;
|
|
22
|
+
if (status !== null) {
|
|
23
|
+
status.textContent = "";
|
|
24
|
+
}
|
|
25
|
+
void fetch("/api/config/open", {
|
|
26
|
+
method: "POST",
|
|
27
|
+
headers: {
|
|
28
|
+
"Content-Type": "application/json",
|
|
29
|
+
"X-Wastech-Viewer-Token": token,
|
|
30
|
+
},
|
|
31
|
+
body: JSON.stringify({ action }),
|
|
32
|
+
})
|
|
33
|
+
.then(async (response) => {
|
|
34
|
+
const result = (await response.json());
|
|
35
|
+
return response.ok
|
|
36
|
+
? (DONE[action] ?? "Done.")
|
|
37
|
+
: (result.error ?? "The config could not be opened.");
|
|
38
|
+
})
|
|
39
|
+
.catch(() => "The viewer did not answer. Is it still running?")
|
|
40
|
+
.then((message) => {
|
|
41
|
+
if (status !== null) {
|
|
42
|
+
status.textContent = message;
|
|
43
|
+
}
|
|
44
|
+
button.disabled = false;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initOutlineSpy(): void;
|