@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,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Keeps the document tree where the reader left it from one page to the next. Every page is a full
|
|
3
|
+
// load whose server-rendered tree opens only the folders on the way to the page's own document and
|
|
4
|
+
// starts scrolled to the top, so a reader stepping through the files of one folder deep in the tree
|
|
5
|
+
// had to scroll back down to it after every click.
|
|
6
|
+
//
|
|
7
|
+
// A classic, blocking script placed right after the tree, like `theme.ts` in the head: it has to run
|
|
8
|
+
// before the tree is first painted, or the tree would show at the top and then jump. It restores the
|
|
9
|
+
// folders that were open and the tree's scroll position, which together put every row back where it
|
|
10
|
+
// was; the document just opened, already marked by the server, therefore stays under the pointer
|
|
11
|
+
// that clicked it. Kept per tab, since two tabs on two parts of the tree are two places.
|
|
12
|
+
(() => {
|
|
13
|
+
const STORAGE_KEY = "wastech-mdlint-viewer:tree";
|
|
14
|
+
const tree = document.querySelector(".sidebar");
|
|
15
|
+
const list = tree?.querySelector(":scope > .sidebar-disclosure > .tree");
|
|
16
|
+
if (tree === null || list === null || list === undefined) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// On a phone the tree folds behind its "Documents" row, closed on every page so the article is what
|
|
20
|
+
// a page opens on; closed here, before the first paint, it never shows open and then collapses. The
|
|
21
|
+
// width is the stylesheet's narrow-screen breakpoint, where the row is drawn at all. A window
|
|
22
|
+
// widened past it opens the tree again, since there the row that would reopen it is not drawn.
|
|
23
|
+
const disclosure = list.parentElement;
|
|
24
|
+
const narrow = matchMedia("(max-width: 800px)");
|
|
25
|
+
if (narrow.matches) {
|
|
26
|
+
disclosure.open = false;
|
|
27
|
+
}
|
|
28
|
+
narrow.addEventListener("change", () => {
|
|
29
|
+
if (!narrow.matches) {
|
|
30
|
+
disclosure.open = true;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
// The switches above the list — findings only, and changed files only where the repository has a
|
|
34
|
+
// branch to review — are wired by modules that run after this script; shown only then, they would
|
|
35
|
+
// push every row down by their height after the scroll had been restored. Showing them here leaves
|
|
36
|
+
// nothing above the list to change size.
|
|
37
|
+
for (const filter of tree.querySelectorAll(".tree-filter")) {
|
|
38
|
+
filter.hidden = false;
|
|
39
|
+
}
|
|
40
|
+
// A switch the reader left on narrows the tree here, before the first paint, when the server drew
|
|
41
|
+
// the marks it narrows to: narrowed only once its module had run, the whole tree showed first, the
|
|
42
|
+
// switch slid on, and then most rows vanished under the restored scroll position. This repeats
|
|
43
|
+
// what `applyTreeFilter` in `diagnostics.ts` and `applyFilter` in `changes.ts` do for the same
|
|
44
|
+
// switches and storage keys, which a classic script cannot import; those modules take over from
|
|
45
|
+
// here and leave this state as it is, since their data is the same.
|
|
46
|
+
function storedOn(key) {
|
|
47
|
+
try {
|
|
48
|
+
return localStorage.getItem(key) === "1";
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Opens the folders on the way to the rows `attribute` flags, marked as `opener`'s, so turning the
|
|
55
|
+
// switch off closes them again; says so when no row is flagged.
|
|
56
|
+
function openTowardFlagged(scroller, attribute, opener, empty) {
|
|
57
|
+
for (const folder of scroller.querySelectorAll("details")) {
|
|
58
|
+
if (folder.parentElement?.hasAttribute(attribute) === true &&
|
|
59
|
+
!folder.open) {
|
|
60
|
+
folder.open = true;
|
|
61
|
+
folder.dataset[opener] = "";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (empty !== null) {
|
|
65
|
+
empty.hidden = scroller.querySelector(`li[${attribute}]`) !== null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function switchOf(scroller, name) {
|
|
69
|
+
return scroller.querySelector(`.tree-filter-${name} input`);
|
|
70
|
+
}
|
|
71
|
+
function narrowToStoredSwitches(scroller) {
|
|
72
|
+
const marked = (scroller.dataset.marked ?? "").split(" ");
|
|
73
|
+
const findings = switchOf(scroller, "findings");
|
|
74
|
+
if (marked.includes("findings") &&
|
|
75
|
+
findings !== null &&
|
|
76
|
+
storedOn("wastech-mdlint-viewer:tree-findings-only")) {
|
|
77
|
+
findings.checked = true;
|
|
78
|
+
scroller.classList.add("only-findings");
|
|
79
|
+
openTowardFlagged(scroller, "data-findings", "openedByFilter", scroller.querySelector(".tree-filter-findings-empty"));
|
|
80
|
+
}
|
|
81
|
+
const changed = switchOf(scroller, "changes");
|
|
82
|
+
if (!marked.includes("changes") || changed === null) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const unreviewed = switchOf(scroller, "unreviewed");
|
|
86
|
+
changed.checked = storedOn("wastech-mdlint-viewer:tree-changed-only");
|
|
87
|
+
const leftOnly = unreviewed !== null &&
|
|
88
|
+
storedOn("wastech-mdlint-viewer:tree-unreviewed-only");
|
|
89
|
+
if (unreviewed !== null) {
|
|
90
|
+
unreviewed.checked = leftOnly;
|
|
91
|
+
}
|
|
92
|
+
if (!changed.checked && !leftOnly) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
scroller.classList.add(leftOnly ? "only-unreviewed" : "only-changed");
|
|
96
|
+
const empty = scroller.querySelector(".tree-filter-changes-empty");
|
|
97
|
+
if (empty !== null) {
|
|
98
|
+
empty.textContent = leftOnly
|
|
99
|
+
? "Nothing left to review."
|
|
100
|
+
: "No document changed.";
|
|
101
|
+
}
|
|
102
|
+
openTowardFlagged(scroller, leftOnly ? "data-unreviewed" : "data-changed", "openedByChangesFilter", empty);
|
|
103
|
+
}
|
|
104
|
+
// Where the list starts within the tree's scrolled content, measured on screen rather than with
|
|
105
|
+
// `offsetTop`, whose reference is whichever ancestor happens to be positioned.
|
|
106
|
+
const listStart = () => list.getBoundingClientRect().top -
|
|
107
|
+
tree.getBoundingClientRect().top +
|
|
108
|
+
tree.scrollTop;
|
|
109
|
+
// Declared inside the wrapper rather than at the top level: in a classic script a top-level
|
|
110
|
+
// function is a global, shared with every other classic script on the page.
|
|
111
|
+
function readSaved() {
|
|
112
|
+
try {
|
|
113
|
+
const parsed = JSON.parse(sessionStorage.getItem(STORAGE_KEY) ?? "null");
|
|
114
|
+
if (parsed !== null &&
|
|
115
|
+
Array.isArray(parsed.open) &&
|
|
116
|
+
typeof parsed.scrolledIntoList === "number") {
|
|
117
|
+
return parsed;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Storage blocked or unreadable: the tree opens as the server drew it.
|
|
122
|
+
}
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
// Reached some other way — a link in an article, search, the graph — the document may lie outside
|
|
126
|
+
// the restored view; then it is brought to the middle, leaving the tree alone when it is in sight.
|
|
127
|
+
function centerCurrent(scroller) {
|
|
128
|
+
const current = scroller.querySelector('a[aria-current="page"]');
|
|
129
|
+
if (current === null) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const view = scroller.getBoundingClientRect();
|
|
133
|
+
const row = current.getBoundingClientRect();
|
|
134
|
+
if (row.top < view.top || row.bottom > view.bottom) {
|
|
135
|
+
scroller.scrollTop += row.top - view.top - (view.height - row.height) / 2;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Folders a switch opened are that switch's own and are left out, so turning it off still closes
|
|
139
|
+
// them.
|
|
140
|
+
function openFolders(scroller) {
|
|
141
|
+
return [
|
|
142
|
+
...scroller.querySelectorAll("details[data-folder]"),
|
|
143
|
+
]
|
|
144
|
+
.filter((folder) => folder.open &&
|
|
145
|
+
folder.dataset.openedByFilter === undefined &&
|
|
146
|
+
folder.dataset.openedByChangesFilter === undefined)
|
|
147
|
+
.map((folder) => folder.dataset.folder ?? "");
|
|
148
|
+
}
|
|
149
|
+
const saved = readSaved();
|
|
150
|
+
if (saved !== undefined) {
|
|
151
|
+
const open = new Set(saved.open);
|
|
152
|
+
for (const folder of tree.querySelectorAll("details[data-folder]")) {
|
|
153
|
+
if (open.has(folder.dataset.folder ?? "")) {
|
|
154
|
+
folder.open = true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// After the reader's own folders, so a folder they had open is not taken for one a switch opened,
|
|
159
|
+
// and before the scroll, which was saved in the tree as narrowed.
|
|
160
|
+
narrowToStoredSwitches(tree);
|
|
161
|
+
if (saved !== undefined) {
|
|
162
|
+
tree.scrollTop = listStart() + saved.scrolledIntoList;
|
|
163
|
+
}
|
|
164
|
+
centerCurrent(tree);
|
|
165
|
+
// Saved as the page goes, which covers a click in the tree, any other link, a reload and the
|
|
166
|
+
// back button alike.
|
|
167
|
+
window.addEventListener("pagehide", () => {
|
|
168
|
+
const open = openFolders(tree);
|
|
169
|
+
try {
|
|
170
|
+
sessionStorage.setItem(STORAGE_KEY, JSON.stringify({
|
|
171
|
+
open,
|
|
172
|
+
scrolledIntoList: tree.scrollTop - listStart(),
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// Nothing is kept; the next page opens the tree as the server drew it.
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { initBannerHeight } from "./banner-height.js";
|
|
2
|
+
import { initChangeMarks } from "./change-marks.js";
|
|
3
|
+
import { initChanges } from "./changes.js";
|
|
4
|
+
import { initCharts } from "./charts.js";
|
|
5
|
+
import { initCodeCopy } from "./code-copy.js";
|
|
6
|
+
import { initColumnResize } from "./column-resize.js";
|
|
7
|
+
import { initConfigEditor } from "./config-editor.js";
|
|
8
|
+
import { initCopyPath } from "./copy-path.js";
|
|
9
|
+
import { initDashboard } from "./dashboard.js";
|
|
10
|
+
import { initDiagnostics } from "./diagnostics.js";
|
|
11
|
+
import { initDiagrams } from "./diagrams.js";
|
|
12
|
+
import { initDiffExpand } from "./diff-expand.js";
|
|
13
|
+
import { initDisplaySettings } from "./display-settings.js";
|
|
14
|
+
import { initGraph, initLocalGraph } from "./graph.js";
|
|
15
|
+
import { initHistory } from "./history.js";
|
|
16
|
+
import { initLiveReload } from "./live-reload.js";
|
|
17
|
+
import { initNavigationFeedback } from "./navigation-feedback.js";
|
|
18
|
+
import { initOpenConfig } from "./open-config.js";
|
|
19
|
+
import { initOutlineSpy } from "./outline-spy.js";
|
|
20
|
+
import { initReview } from "./review.js";
|
|
21
|
+
import { initSearch } from "./search.js";
|
|
22
|
+
import { initSourceLines } from "./source-lines.js";
|
|
23
|
+
import { initThemeToggle } from "./theme-toggle.js";
|
|
24
|
+
// The page works without these scripts: documents, links, the tree, highlighted code and search
|
|
25
|
+
// (as a results page) are all server-rendered. Each module adds one thing that needs a browser, and
|
|
26
|
+
// nothing on the page depends on any of them having run.
|
|
27
|
+
// Set only on a document page; a source-file page or a results page has no document of its own.
|
|
28
|
+
const documentPath = document.querySelector('meta[name="wastech-doc"]')
|
|
29
|
+
?.content ?? undefined;
|
|
30
|
+
initThemeToggle();
|
|
31
|
+
initDisplaySettings();
|
|
32
|
+
initCopyPath();
|
|
33
|
+
initColumnResize();
|
|
34
|
+
initLiveReload(documentPath);
|
|
35
|
+
initNavigationFeedback();
|
|
36
|
+
initSourceLines();
|
|
37
|
+
initCodeCopy();
|
|
38
|
+
initDiagrams();
|
|
39
|
+
initCharts();
|
|
40
|
+
initGraph();
|
|
41
|
+
initLocalGraph();
|
|
42
|
+
initOutlineSpy();
|
|
43
|
+
initSearch();
|
|
44
|
+
initDiagnostics(documentPath);
|
|
45
|
+
initChanges();
|
|
46
|
+
initChangeMarks();
|
|
47
|
+
initBannerHeight();
|
|
48
|
+
initReview(documentPath);
|
|
49
|
+
initHistory();
|
|
50
|
+
initDiffExpand();
|
|
51
|
+
initDashboard();
|
|
52
|
+
initConfigEditor();
|
|
53
|
+
initOpenConfig();
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { ElementContent } from "hast";
|
|
2
|
+
import { type ConfigEdit, type LintConfig, type LintMessage, type LoadedConfiguration } from "@wastech-mdlint/core";
|
|
3
|
+
import type { Corpus } from "./corpus.js";
|
|
4
|
+
export type ConfigFile = {
|
|
5
|
+
absolutePath: string;
|
|
6
|
+
displayPath: string;
|
|
7
|
+
text: string;
|
|
8
|
+
hash: string;
|
|
9
|
+
};
|
|
10
|
+
export type ChangeRequest = {
|
|
11
|
+
base: string;
|
|
12
|
+
text?: string;
|
|
13
|
+
edits?: ConfigEdit[];
|
|
14
|
+
};
|
|
15
|
+
export type PreviewFinding = Pick<LintMessage, "filePath" | "line" | "ruleId" | "severity" | "message">;
|
|
16
|
+
export type PreviewCounts = {
|
|
17
|
+
errors: number;
|
|
18
|
+
warnings: number;
|
|
19
|
+
};
|
|
20
|
+
export type Preview = {
|
|
21
|
+
status: "invalid";
|
|
22
|
+
errors: string[];
|
|
23
|
+
text?: string;
|
|
24
|
+
} | {
|
|
25
|
+
status: "ok";
|
|
26
|
+
text: string;
|
|
27
|
+
hash: string;
|
|
28
|
+
config: LintConfig;
|
|
29
|
+
ruleIds: (string | null)[];
|
|
30
|
+
documents: {
|
|
31
|
+
before: number;
|
|
32
|
+
after: number;
|
|
33
|
+
};
|
|
34
|
+
findings: {
|
|
35
|
+
before: PreviewCounts;
|
|
36
|
+
after: PreviewCounts;
|
|
37
|
+
};
|
|
38
|
+
byRule: {
|
|
39
|
+
ruleId: string;
|
|
40
|
+
before: number;
|
|
41
|
+
after: number;
|
|
42
|
+
}[];
|
|
43
|
+
added: PreviewFinding[];
|
|
44
|
+
removed: PreviewFinding[];
|
|
45
|
+
addedCount: number;
|
|
46
|
+
removedCount: number;
|
|
47
|
+
};
|
|
48
|
+
export declare function hashText(text: string): string;
|
|
49
|
+
/** The config file the corpus was loaded from, read fresh from disk, or `undefined` when there is none. */
|
|
50
|
+
export declare function readConfigFile(corpus: Corpus): Promise<ConfigFile | undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* Why saving is off, or `undefined` when it is on. Three conditions, each its own reason: the viewer
|
|
53
|
+
* was not started with the flag that allows writing; there is no config file (creating one is
|
|
54
|
+
* `init`'s job, which also wires the schema); or the file is outside the repository, the only tree
|
|
55
|
+
* the viewer is allowed to change.
|
|
56
|
+
*/
|
|
57
|
+
export declare function writeBlockedReason(corpus: Corpus, allowWrites: boolean): Promise<string | undefined>;
|
|
58
|
+
export type ParsedChangeRequest = {
|
|
59
|
+
ok: true;
|
|
60
|
+
request: ChangeRequest;
|
|
61
|
+
} | {
|
|
62
|
+
ok: false;
|
|
63
|
+
message: string;
|
|
64
|
+
};
|
|
65
|
+
/** Check the shape of a change request body; what the edits mean is for core to judge. */
|
|
66
|
+
export declare function parseChangeRequest(body: unknown): ParsedChangeRequest;
|
|
67
|
+
/** The candidate text a request describes, or core's reason it cannot be built. */
|
|
68
|
+
export declare function candidateText(file: ConfigFile, request: ChangeRequest): {
|
|
69
|
+
ok: true;
|
|
70
|
+
text: string;
|
|
71
|
+
} | {
|
|
72
|
+
ok: false;
|
|
73
|
+
errors: string[];
|
|
74
|
+
};
|
|
75
|
+
/** The candidate as core loads it, or core's diagnostics, one per line. */
|
|
76
|
+
export declare function validateCandidate(corpus: Corpus, file: ConfigFile, text: string): {
|
|
77
|
+
ok: true;
|
|
78
|
+
loaded: LoadedConfiguration;
|
|
79
|
+
} | {
|
|
80
|
+
ok: false;
|
|
81
|
+
errors: string[];
|
|
82
|
+
};
|
|
83
|
+
/** The canonical id of each rule entry, `null` for a custom rule or a name the registry does not know. */
|
|
84
|
+
export declare function entryRuleIds(config: LintConfig): (string | null)[];
|
|
85
|
+
/**
|
|
86
|
+
* What the candidate would report, compared with what the current config reports now.
|
|
87
|
+
*
|
|
88
|
+
* Findings are matched by core's `compareFindings` — on file, rule, line, severity and message, as a
|
|
89
|
+
* multiset — the comparison the review of a branch uses too, so a config edit and a branch never
|
|
90
|
+
* disagree about what counts as the same finding.
|
|
91
|
+
*/
|
|
92
|
+
export declare function previewCandidate(params: {
|
|
93
|
+
corpus: Corpus;
|
|
94
|
+
current: readonly LintMessage[];
|
|
95
|
+
candidate: LoadedConfiguration;
|
|
96
|
+
text: string;
|
|
97
|
+
linted: {
|
|
98
|
+
messages: readonly LintMessage[];
|
|
99
|
+
documentCount: number;
|
|
100
|
+
};
|
|
101
|
+
}): Preview;
|
|
102
|
+
export type SaveOutcome = {
|
|
103
|
+
status: "saved";
|
|
104
|
+
hash: string;
|
|
105
|
+
} | {
|
|
106
|
+
status: "conflict";
|
|
107
|
+
message: string;
|
|
108
|
+
} | {
|
|
109
|
+
status: "failed";
|
|
110
|
+
message: string;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Write a validated candidate over the config, atomically, then read it back.
|
|
114
|
+
*
|
|
115
|
+
* `writeFileAtomic` replaces the file in one rename, so a failed write leaves the old file whole. The
|
|
116
|
+
* read-back catches what it cannot: another program writing the file in the same moment. Different
|
|
117
|
+
* text on disk after the rename can only have been written after it, so it is the newest version
|
|
118
|
+
* of the file and stays exactly as it is. Putting the version this page started from back over it
|
|
119
|
+
* would throw away that program's change to undo the reader's, and leave neither; the reader is told
|
|
120
|
+
* instead, and reloads to edit what is there now.
|
|
121
|
+
*
|
|
122
|
+
* `readBack` reads the file after the write; a test replaces it to stand in for the other program.
|
|
123
|
+
*/
|
|
124
|
+
export declare function saveCandidate(params: {
|
|
125
|
+
file: ConfigFile;
|
|
126
|
+
text: string;
|
|
127
|
+
readBack?: (absolutePath: string) => Promise<string>;
|
|
128
|
+
}): Promise<SaveOutcome>;
|
|
129
|
+
export type ConfigApi = {
|
|
130
|
+
file: {
|
|
131
|
+
path: string;
|
|
132
|
+
text: string;
|
|
133
|
+
hash: string;
|
|
134
|
+
} | null;
|
|
135
|
+
config: LintConfig | null;
|
|
136
|
+
ruleIds: (string | null)[];
|
|
137
|
+
errors: string[];
|
|
138
|
+
writeBlocked: string | null;
|
|
139
|
+
schema: unknown;
|
|
140
|
+
rules: {
|
|
141
|
+
id: string;
|
|
142
|
+
alias: string;
|
|
143
|
+
category: string;
|
|
144
|
+
description: string;
|
|
145
|
+
defaultSeverity: string;
|
|
146
|
+
fixable: boolean;
|
|
147
|
+
docsUrl?: string;
|
|
148
|
+
}[];
|
|
149
|
+
};
|
|
150
|
+
/** Everything the page's script needs to build the editor. */
|
|
151
|
+
export declare function configApi(corpus: Corpus, allowWrites: boolean): Promise<ConfigApi>;
|
|
152
|
+
/** The id of the data the editor is built from, which the page's script reads by the same name. */
|
|
153
|
+
export declare const CONFIG_DATA_ID = "viewer.config-data";
|
|
154
|
+
/** What a read-only config page says in place of the editor. */
|
|
155
|
+
export declare const CONFIG_READ_ONLY = "This page is read-only: the viewer is reachable from other machines (--host), so it previews, saves and opens nothing. Copy the file below to change it elsewhere, or start the viewer on a loopback address to edit it here.";
|
|
156
|
+
/**
|
|
157
|
+
* The page without its script: the file as it is, highlighted, and the registry's rules with the
|
|
158
|
+
* ones the config runs marked. Editing needs the script, which builds its form from the schema.
|
|
159
|
+
*/
|
|
160
|
+
export declare function renderConfigArticle(corpus: Corpus, options: {
|
|
161
|
+
allowWrites: boolean;
|
|
162
|
+
showAbsolutePath: boolean;
|
|
163
|
+
canOpen: boolean;
|
|
164
|
+
editor: ConfigApi;
|
|
165
|
+
readOnly: boolean;
|
|
166
|
+
}): Promise<ElementContent[]>;
|