@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,109 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { computeContextDelta, eagerContextPaths, lineLinkTargets, parseConfiguration, rankByInfluence, replaceDocuments, swapsTowardBase, swapsTowardHead, } from "@wastech-mdlint/core";
|
|
4
|
+
/**
|
|
5
|
+
* The context delta of `review`. `worktree` is the work-tree review of the same merge-base, which
|
|
6
|
+
* `review` is itself in that mode: only it lists every document that differs from the merge-base,
|
|
7
|
+
* so only it can turn the files on disk into the merge-base's version of the corpus.
|
|
8
|
+
*
|
|
9
|
+
* In the work-tree mode the head side is the corpus as read from disk. With commits only, it is the
|
|
10
|
+
* merge-base's version with the branch's commits applied, so uncommitted edits stay out of it just
|
|
11
|
+
* as they stay out of that mode's diffs.
|
|
12
|
+
*/
|
|
13
|
+
export async function computeReviewContext(params) {
|
|
14
|
+
const { review, worktree, rootDir } = params;
|
|
15
|
+
const configProblems = [];
|
|
16
|
+
const disk = worktree.snapshot;
|
|
17
|
+
const configPath = disk.configuration.configPath ??
|
|
18
|
+
path.join(rootDir, ...(disk.membership.configPath ?? "").split("/"));
|
|
19
|
+
const configurationFrom = (text, side) => {
|
|
20
|
+
try {
|
|
21
|
+
// A side without a config file lints as the defaults do: every Markdown file, no rules.
|
|
22
|
+
return parseConfiguration({
|
|
23
|
+
text: text ?? "{}",
|
|
24
|
+
cwd: rootDir,
|
|
25
|
+
configPath,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
configProblems.push(`The config at the ${side} does not load, so the ${side} is linted with the current one: ${error.message}`);
|
|
30
|
+
return disk.configuration;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const baseConfiguration = worktree.config === undefined
|
|
34
|
+
? disk.configuration
|
|
35
|
+
: configurationFrom(worktree.config.baseText, "base");
|
|
36
|
+
const headConfiguration = review.set.worktree
|
|
37
|
+
? disk.configuration
|
|
38
|
+
: review.config === undefined
|
|
39
|
+
? baseConfiguration
|
|
40
|
+
: configurationFrom(review.config.headText, "last commit");
|
|
41
|
+
const baseDocuments = replaceDocuments(disk.documents, swapsTowardBase(worktree.documents.map(changedDocument)));
|
|
42
|
+
const changes = review.documents.map(changedDocument);
|
|
43
|
+
const headDocuments = review.set.worktree
|
|
44
|
+
? new Map(disk.documents)
|
|
45
|
+
: replaceDocuments(baseDocuments, swapsTowardHead(changes));
|
|
46
|
+
const delta = computeContextDelta({
|
|
47
|
+
cwd: rootDir,
|
|
48
|
+
base: { documents: baseDocuments, configuration: baseConfiguration },
|
|
49
|
+
head: {
|
|
50
|
+
documents: headDocuments,
|
|
51
|
+
configuration: headConfiguration,
|
|
52
|
+
...(headConfiguration === disk.configuration && review.set.worktree
|
|
53
|
+
? { graph: disk.graph }
|
|
54
|
+
: {}),
|
|
55
|
+
},
|
|
56
|
+
changes,
|
|
57
|
+
codeFiles: await linkedCodeTexts(params, headDocuments, headConfiguration),
|
|
58
|
+
});
|
|
59
|
+
const order = rankByInfluence(review.documents, {
|
|
60
|
+
graph: review.snapshot.graph,
|
|
61
|
+
eager: eagerContextPaths(review.snapshot.graph, review.snapshot.configuration.config),
|
|
62
|
+
newErrors: new Set(delta.newErrors),
|
|
63
|
+
}).map((change) => change.path);
|
|
64
|
+
return { delta, order, configProblems };
|
|
65
|
+
}
|
|
66
|
+
function changedDocument(review) {
|
|
67
|
+
return {
|
|
68
|
+
path: review.path,
|
|
69
|
+
...(review.oldPath === undefined ? {} : { oldPath: review.oldPath }),
|
|
70
|
+
status: review.status,
|
|
71
|
+
diff: review.diff,
|
|
72
|
+
...(review.baseDocument === undefined ? {} : { base: review.baseDocument }),
|
|
73
|
+
...(review.headDocument === undefined ? {} : { head: review.headDocument }),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Both versions of every changed non-Markdown file a document links into with a line fragment
|
|
78
|
+
* (`file.ts#L12-L20`): the only changed code whose lines a link can pin. Read from git in one process
|
|
79
|
+
* per side, the head side from disk in the work-tree mode, so the comparison sees exactly the files
|
|
80
|
+
* the diff of that mode sees. A file added by the branch is left out: no link written before it
|
|
81
|
+
* existed can point into it.
|
|
82
|
+
*/
|
|
83
|
+
async function linkedCodeTexts(params, documents, configuration) {
|
|
84
|
+
const { repository, review, rootDir } = params;
|
|
85
|
+
const targets = lineLinkTargets(documents.values(), configuration.settings.siteRouter);
|
|
86
|
+
const changed = review.set.otherFiles.filter((change) => change.status !== "A" && targets.has(change.path));
|
|
87
|
+
const texts = new Map();
|
|
88
|
+
if (changed.length === 0) {
|
|
89
|
+
return texts;
|
|
90
|
+
}
|
|
91
|
+
const baseTexts = await repository.readBlobs(review.set.mergeBase, changed.map((change) => change.oldPath ?? change.path));
|
|
92
|
+
const headTexts = review.set.worktree
|
|
93
|
+
? undefined
|
|
94
|
+
: await repository.readBlobs(review.set.head, changed.map((change) => change.path));
|
|
95
|
+
for (const change of changed) {
|
|
96
|
+
const baseText = baseTexts.get(change.oldPath ?? change.path);
|
|
97
|
+
if (baseText === undefined) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const headText = change.status === "D"
|
|
101
|
+
? ""
|
|
102
|
+
: headTexts !== undefined
|
|
103
|
+
? (headTexts.get(change.path) ?? "")
|
|
104
|
+
: // A path git reported under the root, read only to compare it, never served.
|
|
105
|
+
await readFile(path.join(rootDir, ...change.path.split("/")), "utf8").catch(() => "");
|
|
106
|
+
texts.set(change.path, { baseText, headText });
|
|
107
|
+
}
|
|
108
|
+
return texts;
|
|
109
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DocumentReview, Review, ReviewContext, ReviewResult } from "./changes.js";
|
|
2
|
+
import { type ReviewMarksView } from "./review-state.js";
|
|
3
|
+
import type { ViewerContext } from "./viewer-context.js";
|
|
4
|
+
export declare function worktreeOf(params: URLSearchParams): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* The context of a review, or `undefined` when there is none to show. A failure to compute it is
|
|
7
|
+
* reported here and leaves the page with its diffs, which do not depend on it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function contextOf(ctx: ViewerContext, review: ReviewResult): Promise<ReviewContext | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* What the branch did, for the pages that show it beside everything else — the dashboard and the
|
|
12
|
+
* graph. The work-tree review, as both show the files on disk; `undefined` outside a git work tree
|
|
13
|
+
* or while there is nothing to compare.
|
|
14
|
+
*/
|
|
15
|
+
export declare function workTreeChanges(ctx: ViewerContext): Promise<{
|
|
16
|
+
review: Review;
|
|
17
|
+
context: ReviewContext;
|
|
18
|
+
} | undefined>;
|
|
19
|
+
/** The marks of a review's documents, or `undefined` where review marks are off. */
|
|
20
|
+
export declare function marksOf(ctx: ViewerContext, review: ReviewResult): Promise<ReviewMarksView | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Each changed document's review since the reader's last review of it, for a page that compares
|
|
23
|
+
* with that: only documents changed since they were reviewed, and only those whose reviewed text
|
|
24
|
+
* is still kept.
|
|
25
|
+
*/
|
|
26
|
+
export declare function sinceOf(ctx: ViewerContext, review: Review, marks: ReviewMarksView | undefined): Promise<Map<string, DocumentReview>>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { markReview } from "./review-state.js";
|
|
2
|
+
// The questions several pages ask of the branch review — its context, the reader's marks, the
|
|
3
|
+
// review since the last one — answered in one place, so the Changes page, its JSON, the graph and
|
|
4
|
+
// the dashboard all read the same answer.
|
|
5
|
+
// `worktree=0` limits a review to committed changes; anything else, or nothing, includes the work
|
|
6
|
+
// tree, which is what a reader in the middle of an edit wants to see.
|
|
7
|
+
export function worktreeOf(params) {
|
|
8
|
+
return params.get("worktree") !== "0";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The context of a review, or `undefined` when there is none to show. A failure to compute it is
|
|
12
|
+
* reported here and leaves the page with its diffs, which do not depend on it.
|
|
13
|
+
*/
|
|
14
|
+
export async function contextOf(ctx, review) {
|
|
15
|
+
if (ctx.changes === undefined || "available" in review) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return await ctx.changes.context(review);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
process.stderr.write(`wastech-mdlint-viewer: could not compare the context: ${error.message}\n`);
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* What the branch did, for the pages that show it beside everything else — the dashboard and the
|
|
28
|
+
* graph. The work-tree review, as both show the files on disk; `undefined` outside a git work tree
|
|
29
|
+
* or while there is nothing to compare.
|
|
30
|
+
*/
|
|
31
|
+
export async function workTreeChanges(ctx) {
|
|
32
|
+
if (ctx.changes === undefined) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const review = await ctx.changes.review(true);
|
|
36
|
+
if ("available" in review) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const context = await contextOf(ctx, review);
|
|
40
|
+
return context === undefined ? undefined : { review, context };
|
|
41
|
+
}
|
|
42
|
+
/** The marks of a review's documents, or `undefined` where review marks are off. */
|
|
43
|
+
export async function marksOf(ctx, review) {
|
|
44
|
+
if (ctx.reviewStore === undefined || "available" in review) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return markReview(review, await ctx.reviewStore.read());
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Each changed document's review since the reader's last review of it, for a page that compares
|
|
51
|
+
* with that: only documents changed since they were reviewed, and only those whose reviewed text
|
|
52
|
+
* is still kept.
|
|
53
|
+
*/
|
|
54
|
+
export async function sinceOf(ctx, review, marks) {
|
|
55
|
+
const since = new Map();
|
|
56
|
+
if (ctx.sinceReviews === undefined || marks?.ok !== true) {
|
|
57
|
+
return since;
|
|
58
|
+
}
|
|
59
|
+
for (const entry of review.documents) {
|
|
60
|
+
const version = marks.documents.get(entry.path)?.since;
|
|
61
|
+
const rebased = version === undefined
|
|
62
|
+
? undefined
|
|
63
|
+
: await ctx.sinceReviews.of(entry, version);
|
|
64
|
+
if (rebased !== undefined) {
|
|
65
|
+
since.set(entry.path, rebased);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return since;
|
|
69
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Element } from "hast";
|
|
2
|
+
import type { DocumentReview, Review } from "./changes.js";
|
|
3
|
+
import { type ReviewMarks, type ReviewStatus, type SectionHash, type ReviewStore, type StoreRead } from "./review-store.js";
|
|
4
|
+
/** A changed document against the marks: where it stands and the text it would be marked as. */
|
|
5
|
+
export type DocumentMark = {
|
|
6
|
+
status: ReviewStatus;
|
|
7
|
+
hash: string;
|
|
8
|
+
since?: string;
|
|
9
|
+
sections: {
|
|
10
|
+
reviewed: number;
|
|
11
|
+
total: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The marks of a review's documents, or why there are none: the marks file could not be read. Keyed
|
|
16
|
+
* by path. Statuses are computed here on every read and stored nowhere, so a mark follows content
|
|
17
|
+
* whatever branch or rebase brought the content there.
|
|
18
|
+
*/
|
|
19
|
+
export type ReviewMarksView = {
|
|
20
|
+
ok: true;
|
|
21
|
+
documents: ReadonlyMap<string, DocumentMark>;
|
|
22
|
+
left: number;
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function markReview(review: Review, read: StoreRead): ReviewMarksView;
|
|
28
|
+
export declare function markOf(entry: DocumentReview, marks: ReviewMarks): DocumentMark;
|
|
29
|
+
/**
|
|
30
|
+
* The sections of a changed document as the page shows it, each with the hash of its own text: what
|
|
31
|
+
* marking the document records for them, and what a section's mark must name. None for a deleted
|
|
32
|
+
* document, which has no text to cut.
|
|
33
|
+
*/
|
|
34
|
+
export declare function sectionHashes(entry: DocumentReview): SectionHash[];
|
|
35
|
+
/** A section's place in the reader's review, keyed by its heading's slug for the outline. */
|
|
36
|
+
export type SectionMark = SectionHash & {
|
|
37
|
+
status: ReviewStatus;
|
|
38
|
+
};
|
|
39
|
+
export declare function sectionMarksOf(entry: DocumentReview, marks: ReviewMarks): Map<string, SectionMark>;
|
|
40
|
+
/** A request to mark one document reviewed or not, as the "Viewed" checkbox sends it. */
|
|
41
|
+
export type MarkRequest = {
|
|
42
|
+
path: string;
|
|
43
|
+
hash: string;
|
|
44
|
+
reviewed: boolean;
|
|
45
|
+
worktree: boolean;
|
|
46
|
+
};
|
|
47
|
+
/** A request to mark one section of a changed document reviewed or not, from the outline. */
|
|
48
|
+
export type SectionRequest = {
|
|
49
|
+
path: string;
|
|
50
|
+
section: string;
|
|
51
|
+
hash: string;
|
|
52
|
+
reviewed: boolean;
|
|
53
|
+
};
|
|
54
|
+
/** A request to forget the marks of the documents a page listed. */
|
|
55
|
+
export type ResetRequest = {
|
|
56
|
+
worktree: boolean;
|
|
57
|
+
documents: {
|
|
58
|
+
path: string;
|
|
59
|
+
hash: string;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
62
|
+
type Parsed<T> = {
|
|
63
|
+
ok: true;
|
|
64
|
+
request: T;
|
|
65
|
+
} | {
|
|
66
|
+
ok: false;
|
|
67
|
+
message: string;
|
|
68
|
+
};
|
|
69
|
+
/** Check a mark request's shape; whether it names the version on disk is the server's to judge. */
|
|
70
|
+
export declare function parseMarkRequest(body: unknown): Parsed<MarkRequest>;
|
|
71
|
+
export declare function parseSectionRequest(body: unknown): Parsed<SectionRequest>;
|
|
72
|
+
export declare function parseResetRequest(body: unknown): Parsed<ResetRequest>;
|
|
73
|
+
/**
|
|
74
|
+
* A document's review restated against the version the reader last reviewed rather than the base:
|
|
75
|
+
* the same shape, so the Changes page, the Source view and the marks on a rendered page all show it
|
|
76
|
+
* through the code that shows the branch's changes. Kept per review and version, so a rendered page
|
|
77
|
+
* marked from it is cached for as long as the review is.
|
|
78
|
+
*/
|
|
79
|
+
export declare class SinceReview {
|
|
80
|
+
private readonly store;
|
|
81
|
+
private readonly cache;
|
|
82
|
+
constructor(store: ReviewStore);
|
|
83
|
+
/** `undefined` when the reviewed text is no longer kept. */
|
|
84
|
+
of(entry: DocumentReview, since: string): Promise<DocumentReview | undefined>;
|
|
85
|
+
}
|
|
86
|
+
/** What a page compares a changed document with, kept in the address as `?since=review`. */
|
|
87
|
+
export type Baseline = "base" | "review";
|
|
88
|
+
export declare function baselineOf(params: URLSearchParams): Baseline;
|
|
89
|
+
/**
|
|
90
|
+
* How far a document reviewed one section at a time has got, beside its card's status: only while
|
|
91
|
+
* some of its sections are viewed and some are not. None viewed is the common case and says nothing;
|
|
92
|
+
* all viewed makes the document reviewed, which its status already says.
|
|
93
|
+
*/
|
|
94
|
+
export declare function sectionProgress(mark: DocumentMark | undefined): Element | undefined;
|
|
95
|
+
/** The status beside a changed document; nothing for one never reviewed, which is most of them. */
|
|
96
|
+
export declare function reviewChip(mark: DocumentMark | undefined): Element | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* The "Viewed" checkbox, hidden until the page script that sends the mark has run: without script
|
|
99
|
+
* it could only lie about being checkable. It carries what the request names — the path, the
|
|
100
|
+
* hash of the text the page shows, and which comparison the page made — so the server marks exactly
|
|
101
|
+
* the version the reader saw.
|
|
102
|
+
*/
|
|
103
|
+
export declare function reviewToggle(entry: DocumentReview, mark: DocumentMark, worktree: boolean): Element;
|
|
104
|
+
/** The reason review marks are not shown, where they would be. */
|
|
105
|
+
export declare function reviewProblem(message: string): Element;
|
|
106
|
+
export {};
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { h } from "hastscript";
|
|
2
|
+
import { diffText, documentSections, parseDocument, tableRowLines, } from "@wastech-mdlint/core";
|
|
3
|
+
import { contentHash, } from "./review-store.js";
|
|
4
|
+
export function markReview(review, read) {
|
|
5
|
+
if (!read.ok) {
|
|
6
|
+
return read;
|
|
7
|
+
}
|
|
8
|
+
const documents = new Map();
|
|
9
|
+
for (const entry of review.documents) {
|
|
10
|
+
documents.set(entry.path, markOf(entry, read.marks));
|
|
11
|
+
}
|
|
12
|
+
return { ok: true, documents, left: leftOf(documents) };
|
|
13
|
+
}
|
|
14
|
+
export function markOf(entry, marks) {
|
|
15
|
+
const hash = contentHash(entry.headText);
|
|
16
|
+
const sections = sectionHashes(entry);
|
|
17
|
+
const renamed = entry.oldPath === undefined ? {} : { oldPath: entry.oldPath };
|
|
18
|
+
return {
|
|
19
|
+
hash,
|
|
20
|
+
...marks.status({ path: entry.path, ...renamed, hash, sections }),
|
|
21
|
+
sections: {
|
|
22
|
+
reviewed: sections.filter((section) => marks.sectionStatus({ path: entry.path, ...renamed, ...section }) ===
|
|
23
|
+
"reviewed").length,
|
|
24
|
+
total: sections.length,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The sections of a changed document as the page shows it, each with the hash of its own text: what
|
|
30
|
+
* marking the document records for them, and what a section's mark must name. None for a deleted
|
|
31
|
+
* document, which has no text to cut.
|
|
32
|
+
*/
|
|
33
|
+
export function sectionHashes(entry) {
|
|
34
|
+
return entry.headDocument === undefined
|
|
35
|
+
? []
|
|
36
|
+
: documentSections(entry.headDocument).map((section) => ({
|
|
37
|
+
key: section.key,
|
|
38
|
+
hash: contentHash(section.text),
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
export function sectionMarksOf(entry, marks) {
|
|
42
|
+
return new Map(sectionHashes(entry).map((section) => [
|
|
43
|
+
section.key,
|
|
44
|
+
{
|
|
45
|
+
...section,
|
|
46
|
+
status: marks.sectionStatus({
|
|
47
|
+
path: entry.path,
|
|
48
|
+
...(entry.oldPath === undefined ? {} : { oldPath: entry.oldPath }),
|
|
49
|
+
...section,
|
|
50
|
+
}),
|
|
51
|
+
},
|
|
52
|
+
]));
|
|
53
|
+
}
|
|
54
|
+
function leftOf(documents) {
|
|
55
|
+
return [...documents.values()].filter((mark) => mark.status !== "reviewed")
|
|
56
|
+
.length;
|
|
57
|
+
}
|
|
58
|
+
const HASH = /^[0-9a-f]{64}$/;
|
|
59
|
+
/** Check a mark request's shape; whether it names the version on disk is the server's to judge. */
|
|
60
|
+
export function parseMarkRequest(body) {
|
|
61
|
+
const fields = objectOf(body, ["path", "hash", "reviewed", "worktree"]);
|
|
62
|
+
if (!fields.ok) {
|
|
63
|
+
return fields;
|
|
64
|
+
}
|
|
65
|
+
const { path, hash, reviewed, worktree } = fields.value;
|
|
66
|
+
if (typeof path !== "string" || path.length === 0) {
|
|
67
|
+
return { ok: false, message: '"path" must name a changed document.' };
|
|
68
|
+
}
|
|
69
|
+
if (typeof hash !== "string" || !HASH.test(hash)) {
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
message: '"hash" must name the version of the document the page showed.',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (typeof reviewed !== "boolean" || typeof worktree !== "boolean") {
|
|
76
|
+
return {
|
|
77
|
+
ok: false,
|
|
78
|
+
message: '"reviewed" and "worktree" must be true or false.',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return { ok: true, request: { path, hash, reviewed, worktree } };
|
|
82
|
+
}
|
|
83
|
+
export function parseSectionRequest(body) {
|
|
84
|
+
const fields = objectOf(body, ["path", "section", "hash", "reviewed"]);
|
|
85
|
+
if (!fields.ok) {
|
|
86
|
+
return fields;
|
|
87
|
+
}
|
|
88
|
+
const { path, section, hash, reviewed } = fields.value;
|
|
89
|
+
if (typeof path !== "string" || path.length === 0) {
|
|
90
|
+
return { ok: false, message: '"path" must name a changed document.' };
|
|
91
|
+
}
|
|
92
|
+
if (typeof section !== "string") {
|
|
93
|
+
return {
|
|
94
|
+
ok: false,
|
|
95
|
+
message: '"section" must be the slug of a section\'s heading.',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (typeof hash !== "string" || !HASH.test(hash)) {
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
message: '"hash" must name the version of the section the page showed.',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (typeof reviewed !== "boolean") {
|
|
105
|
+
return { ok: false, message: '"reviewed" must be true or false.' };
|
|
106
|
+
}
|
|
107
|
+
return { ok: true, request: { path, section, hash, reviewed } };
|
|
108
|
+
}
|
|
109
|
+
export function parseResetRequest(body) {
|
|
110
|
+
const fields = objectOf(body, ["worktree", "documents"]);
|
|
111
|
+
if (!fields.ok) {
|
|
112
|
+
return fields;
|
|
113
|
+
}
|
|
114
|
+
const { worktree, documents } = fields.value;
|
|
115
|
+
if (typeof worktree !== "boolean") {
|
|
116
|
+
return { ok: false, message: '"worktree" must be true or false.' };
|
|
117
|
+
}
|
|
118
|
+
const listed = [];
|
|
119
|
+
if (!Array.isArray(documents)) {
|
|
120
|
+
return {
|
|
121
|
+
ok: false,
|
|
122
|
+
message: '"documents" must list the documents the page showed.',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
for (const entry of documents) {
|
|
126
|
+
const document = objectOf(entry, ["path", "hash"]);
|
|
127
|
+
if (!document.ok ||
|
|
128
|
+
typeof document.value.path !== "string" ||
|
|
129
|
+
typeof document.value.hash !== "string" ||
|
|
130
|
+
!HASH.test(document.value.hash)) {
|
|
131
|
+
return {
|
|
132
|
+
ok: false,
|
|
133
|
+
message: 'Each of "documents" must be a path and the hash of the version the page showed.',
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
listed.push({ path: document.value.path, hash: document.value.hash });
|
|
137
|
+
}
|
|
138
|
+
return { ok: true, request: { worktree, documents: listed } };
|
|
139
|
+
}
|
|
140
|
+
function objectOf(body, keys) {
|
|
141
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) {
|
|
142
|
+
return { ok: false, message: "The request body must be a JSON object." };
|
|
143
|
+
}
|
|
144
|
+
const unknownKey = Object.keys(body).find((key) => !keys.includes(key));
|
|
145
|
+
if (unknownKey !== undefined) {
|
|
146
|
+
return { ok: false, message: `Unknown field "${unknownKey}".` };
|
|
147
|
+
}
|
|
148
|
+
return { ok: true, value: body };
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A document's review restated against the version the reader last reviewed rather than the base:
|
|
152
|
+
* the same shape, so the Changes page, the Source view and the marks on a rendered page all show it
|
|
153
|
+
* through the code that shows the branch's changes. Kept per review and version, so a rendered page
|
|
154
|
+
* marked from it is cached for as long as the review is.
|
|
155
|
+
*/
|
|
156
|
+
export class SinceReview {
|
|
157
|
+
store;
|
|
158
|
+
cache = new WeakMap();
|
|
159
|
+
constructor(store) {
|
|
160
|
+
this.store = store;
|
|
161
|
+
}
|
|
162
|
+
/** `undefined` when the reviewed text is no longer kept. */
|
|
163
|
+
of(entry, since) {
|
|
164
|
+
let versions = this.cache.get(entry);
|
|
165
|
+
if (versions === undefined) {
|
|
166
|
+
versions = new Map();
|
|
167
|
+
this.cache.set(entry, versions);
|
|
168
|
+
}
|
|
169
|
+
let pending = versions.get(since);
|
|
170
|
+
if (pending === undefined) {
|
|
171
|
+
pending = this.store
|
|
172
|
+
.snapshot(since)
|
|
173
|
+
.then((text) => text === undefined ? undefined : againstText(entry, text));
|
|
174
|
+
versions.set(since, pending);
|
|
175
|
+
}
|
|
176
|
+
return pending;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function againstText(entry, text) {
|
|
180
|
+
const baseDocument = parseDocument({ path: entry.path, content: text });
|
|
181
|
+
const rebased = {
|
|
182
|
+
...entry,
|
|
183
|
+
// Compared with a version of this very path: a rename is behind it, and a deleted document
|
|
184
|
+
// stays deleted.
|
|
185
|
+
status: entry.status === "D" ? "D" : "M",
|
|
186
|
+
baseText: text,
|
|
187
|
+
baseDocument,
|
|
188
|
+
diff: diffText(text, entry.headText, {
|
|
189
|
+
baseTableRows: tableRowLines(baseDocument),
|
|
190
|
+
...(entry.headDocument === undefined
|
|
191
|
+
? {}
|
|
192
|
+
: { headTableRows: tableRowLines(entry.headDocument) }),
|
|
193
|
+
}),
|
|
194
|
+
};
|
|
195
|
+
delete rebased.oldPath;
|
|
196
|
+
return rebased;
|
|
197
|
+
}
|
|
198
|
+
export function baselineOf(params) {
|
|
199
|
+
return params.get("since") === "review" ? "review" : "base";
|
|
200
|
+
}
|
|
201
|
+
const STATUS_TEXT = {
|
|
202
|
+
reviewed: "Reviewed",
|
|
203
|
+
changed: "Changed since review",
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* How far a document reviewed one section at a time has got, beside its card's status: only while
|
|
207
|
+
* some of its sections are viewed and some are not. None viewed is the common case and says nothing;
|
|
208
|
+
* all viewed makes the document reviewed, which its status already says.
|
|
209
|
+
*/
|
|
210
|
+
export function sectionProgress(mark) {
|
|
211
|
+
if (mark === undefined) {
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
const { reviewed, total } = mark.sections;
|
|
215
|
+
return reviewed === 0 || reviewed === total
|
|
216
|
+
? undefined
|
|
217
|
+
: h("span.review-sections", { title: "Sections viewed from the document's outline" }, `${String(reviewed)} of ${String(total)} sections`);
|
|
218
|
+
}
|
|
219
|
+
/** The status beside a changed document; nothing for one never reviewed, which is most of them. */
|
|
220
|
+
export function reviewChip(mark) {
|
|
221
|
+
if (mark === undefined || mark.status === "unreviewed") {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
return h(`span.review-chip.review-chip-${mark.status}`, STATUS_TEXT[mark.status]);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The "Viewed" checkbox, hidden until the page script that sends the mark has run: without script
|
|
228
|
+
* it could only lie about being checkable. It carries what the request names — the path, the
|
|
229
|
+
* hash of the text the page shows, and which comparison the page made — so the server marks exactly
|
|
230
|
+
* the version the reader saw.
|
|
231
|
+
*/
|
|
232
|
+
export function reviewToggle(entry, mark, worktree) {
|
|
233
|
+
return h("label.review-toggle", {
|
|
234
|
+
hidden: true,
|
|
235
|
+
dataPath: entry.path,
|
|
236
|
+
dataOldPath: entry.oldPath,
|
|
237
|
+
dataHash: mark.hash,
|
|
238
|
+
dataWorktree: worktree ? "1" : "0",
|
|
239
|
+
title: "Mark as viewed (v)",
|
|
240
|
+
}, [
|
|
241
|
+
h("input", {
|
|
242
|
+
type: "checkbox",
|
|
243
|
+
checked: mark.status === "reviewed",
|
|
244
|
+
}),
|
|
245
|
+
h("span", "Viewed"),
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
248
|
+
/** The reason review marks are not shown, where they would be. */
|
|
249
|
+
export function reviewProblem(message) {
|
|
250
|
+
return h("p.review-problem", message);
|
|
251
|
+
}
|