@anthusai/papyrus 2.0.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/amplify/plugins/editorial-checks/function/handler.py +11 -0
- package/amplify/plugins/editorial-checks/function/requirements.txt +1 -0
- package/amplify/plugins/editorial-checks/function/resource.js +43 -0
- package/amplify/plugins/editorial-checks/function/resource.ts +60 -0
- package/amplify/plugins/editorial-checks/papyrus.plugin.js +50 -0
- package/amplify/plugins/editorial-checks/papyrus.plugin.ts +63 -0
- package/amplify/plugins/editorial-checks/schema.js +94 -0
- package/amplify/plugins/editorial-checks/schema.ts +96 -0
- package/amplify/plugins/registry.js +2 -0
- package/amplify/plugins/registry.ts +2 -0
- package/components/editorial-checks-admin-panel.tsx +337 -0
- package/components/editorial-finding-card.tsx +162 -0
- package/components/editorial-findings-panel.tsx +91 -0
- package/components/editorial-preview-popover.tsx +103 -0
- package/components/markus-body-editor.tsx +213 -0
- package/components/markus-ir-preview.tsx +147 -6
- package/components/newsroom-article-editor.tsx +138 -11
- package/components/newsroom-board-view.tsx +6 -7
- package/components/newsroom-ops-shell.tsx +7 -3
- package/components/newsroom-organizer.css +57 -61
- package/components/newsroom-theme-fonts/broadsheet-green.css +10 -0
- package/components/newsroom-theme-fonts/broadsheet-green.tsx +6 -0
- package/components/newsroom-theme-fonts/newspaper-gothic.css +9 -0
- package/components/newsroom-theme-fonts/newspaper-gothic.tsx +6 -0
- package/components/newsroom-theme-fonts/night-desk.css +10 -0
- package/components/newsroom-theme-fonts/night-desk.tsx +6 -0
- package/components/newsroom-theme-fonts/refined-newsprint.css +11 -0
- package/components/newsroom-theme-fonts/refined-newsprint.tsx +6 -0
- package/components/newsroom-theme.css +39 -0
- package/components/newsroom-theme.tsx +33 -0
- package/components/topic-steering-workspace.tsx +19 -1
- package/components/use-editorial-checks.ts +131 -0
- package/lib/editorial-checks-backend.ts +16 -0
- package/lib/editorial-checks-client.ts +194 -0
- package/lib/editorial-checks-demo.ts +147 -0
- package/lib/editorial-checks-settings.ts +24 -0
- package/lib/editorial-checks.ts +178 -0
- package/lib/editorial-preview.ts +228 -0
- package/lib/newsroom-board.ts +27 -2
- package/lib/site-brand.ts +17 -0
- package/package.json +34 -2
- package/routes.manifest.json +1 -1
- package/components/newsroom-fonts/playfair-display-700.ttf +0 -0
- package/components/newsroom-fonts/playfair-display-900.ttf +0 -0
- package/components/newsroom-fonts/playfair-display-OFL.txt +0 -93
- package/components/newsroom-fonts/plus-jakarta-sans-400.ttf +0 -0
- package/components/newsroom-fonts/plus-jakarta-sans-600.ttf +0 -0
- package/components/newsroom-fonts/plus-jakarta-sans-OFL.txt +0 -93
- package/components/newsroom-newsprint-board.css +0 -7
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editorial checks: the Limatus result shapes the newsroom uses, and pure helpers
|
|
3
|
+
* over them. Limatus counts offsets in UTF-16 code units, which is exactly how
|
|
4
|
+
* JavaScript indexes strings, so spans apply to the body text as they are.
|
|
5
|
+
*/
|
|
6
|
+
import { pluginSettings, type PluginOutputs } from "./plugin-settings";
|
|
7
|
+
|
|
8
|
+
export const EDITORIAL_CHECKS_PLUGIN = "editorial-checks";
|
|
9
|
+
|
|
10
|
+
export type Span = { start: number; end: number };
|
|
11
|
+
export type Severity = "info" | "warn" | "error";
|
|
12
|
+
|
|
13
|
+
export type EditorialFinding = {
|
|
14
|
+
id: string;
|
|
15
|
+
policyId: string;
|
|
16
|
+
policyVersion: number;
|
|
17
|
+
detectorId: string;
|
|
18
|
+
lane: "rules" | "classifier";
|
|
19
|
+
severity: Severity;
|
|
20
|
+
status: "violation" | "review";
|
|
21
|
+
segmentId: string;
|
|
22
|
+
span: Span;
|
|
23
|
+
excerpt: string;
|
|
24
|
+
/** The excerpt as a reader sees it (inline markup removed). */
|
|
25
|
+
excerptText?: string;
|
|
26
|
+
message: string;
|
|
27
|
+
probability?: number;
|
|
28
|
+
rawProbability?: number;
|
|
29
|
+
replacement?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type EditorialSegment = {
|
|
33
|
+
id: string;
|
|
34
|
+
kind: "document" | "paragraph" | "sentence";
|
|
35
|
+
block?: "paragraph" | "heading" | "listItem";
|
|
36
|
+
parentId?: string;
|
|
37
|
+
start: number;
|
|
38
|
+
end: number;
|
|
39
|
+
textHash: string;
|
|
40
|
+
/** Plain prose of a paragraph or sentence segment. */
|
|
41
|
+
text?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type LaneStatus = { status: "ran" | "disabled" | "unavailable" | "failed" | "partial"; reason?: string; detectors?: number };
|
|
45
|
+
|
|
46
|
+
export type EditorialCheckResult = {
|
|
47
|
+
schemaVersion: 1;
|
|
48
|
+
offsetUnit: "utf16";
|
|
49
|
+
document: { hash: string; length: number };
|
|
50
|
+
pack: { packId: string; version: string };
|
|
51
|
+
segments: EditorialSegment[];
|
|
52
|
+
protected: { kind: string; start: number; end: number }[];
|
|
53
|
+
findings: EditorialFinding[];
|
|
54
|
+
coverage: unknown[];
|
|
55
|
+
lanes: { rules: LaneStatus; classifier: LaneStatus };
|
|
56
|
+
usage?: Record<string, number>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type RewriteOption = {
|
|
60
|
+
id: string;
|
|
61
|
+
span: Span;
|
|
62
|
+
replacement: string;
|
|
63
|
+
rationale: string;
|
|
64
|
+
factVerificationRequired: boolean;
|
|
65
|
+
unresolvedQuestions: string[];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type RewriteResult = {
|
|
69
|
+
target: { findingId?: string; span: Span; excerpt: string };
|
|
70
|
+
model: string;
|
|
71
|
+
options: RewriteOption[];
|
|
72
|
+
dropped?: { replacement: string; reason: string }[];
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type FeedbackDecision = "accepted" | "fixed" | "dismissed";
|
|
76
|
+
|
|
77
|
+
export type EditorialFeedbackInput = {
|
|
78
|
+
itemId: string;
|
|
79
|
+
findingId: string;
|
|
80
|
+
policyId: string;
|
|
81
|
+
detectorId: string;
|
|
82
|
+
lane: EditorialFinding["lane"];
|
|
83
|
+
probability: number | null;
|
|
84
|
+
decision: FeedbackDecision;
|
|
85
|
+
reason: string | null;
|
|
86
|
+
text: string | null;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** Decisions on an article that has never been saved are kept under this id. */
|
|
90
|
+
export const UNSAVED_ITEM_ID = "unsaved";
|
|
91
|
+
|
|
92
|
+
const SEVERITY_ORDER: Record<Severity, number> = { error: 0, warn: 1, info: 2 };
|
|
93
|
+
|
|
94
|
+
export function editorialChecksEnabled(outputs: PluginOutputs | null | undefined): boolean {
|
|
95
|
+
return pluginSettings(outputs, EDITORIAL_CHECKS_PLUGIN) !== null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Findings worth showing: not dismissed, not covering the whole document, most severe first, then in reading order. */
|
|
99
|
+
export function visibleFindings(findings: EditorialFinding[], dismissed: ReadonlySet<string>): EditorialFinding[] {
|
|
100
|
+
return findings
|
|
101
|
+
.filter((finding) => !dismissed.has(finding.id))
|
|
102
|
+
.sort(
|
|
103
|
+
(a, b) =>
|
|
104
|
+
SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity] ||
|
|
105
|
+
a.span.start - b.span.start ||
|
|
106
|
+
a.policyId.localeCompare(b.policyId),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Findings that can be marked in the text (document-level ones have no excerpt). */
|
|
111
|
+
export function inlineFindings(findings: EditorialFinding[]): EditorialFinding[] {
|
|
112
|
+
return findings.filter((finding) => finding.excerpt.length > 0 && finding.span.end > finding.span.start);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type FindingGroup = { policyId: string; severity: Severity; findings: EditorialFinding[] };
|
|
116
|
+
|
|
117
|
+
export function groupByPolicy(findings: EditorialFinding[]): FindingGroup[] {
|
|
118
|
+
const groups = new Map<string, FindingGroup>();
|
|
119
|
+
for (const finding of findings) {
|
|
120
|
+
const group = groups.get(finding.policyId) ?? { policyId: finding.policyId, severity: finding.severity, findings: [] };
|
|
121
|
+
group.findings.push(finding);
|
|
122
|
+
if (SEVERITY_ORDER[finding.severity] < SEVERITY_ORDER[group.severity]) group.severity = finding.severity;
|
|
123
|
+
groups.set(finding.policyId, group);
|
|
124
|
+
}
|
|
125
|
+
return [...groups.values()].sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity] || a.policyId.localeCompare(b.policyId));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Open findings that should make an editor pause before publishing (never a block). */
|
|
129
|
+
export function publishWarnings(findings: EditorialFinding[], dismissed: ReadonlySet<string>): EditorialFinding[] {
|
|
130
|
+
return visibleFindings(findings, dismissed).filter((finding) => finding.severity !== "info" && finding.status === "violation");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** The text of the segment a finding sits in, which becomes a few-shot example for the classifier. */
|
|
134
|
+
export function findingSegmentText(result: EditorialCheckResult, body: string, finding: EditorialFinding): string | null {
|
|
135
|
+
const segment = result.segments.find((candidate) => candidate.id === finding.segmentId);
|
|
136
|
+
if (!segment || segment.kind === "document") return null;
|
|
137
|
+
return body.slice(segment.start, segment.end);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function feedbackFor(
|
|
141
|
+
result: EditorialCheckResult,
|
|
142
|
+
body: string,
|
|
143
|
+
finding: EditorialFinding,
|
|
144
|
+
decision: FeedbackDecision,
|
|
145
|
+
itemId: string | null,
|
|
146
|
+
reason: string | null = null,
|
|
147
|
+
): EditorialFeedbackInput {
|
|
148
|
+
return {
|
|
149
|
+
itemId: itemId ?? UNSAVED_ITEM_ID,
|
|
150
|
+
findingId: finding.id,
|
|
151
|
+
policyId: finding.policyId,
|
|
152
|
+
detectorId: finding.detectorId,
|
|
153
|
+
lane: finding.lane,
|
|
154
|
+
probability: finding.rawProbability ?? finding.probability ?? null,
|
|
155
|
+
decision,
|
|
156
|
+
reason: reason?.trim() ? reason.trim() : null,
|
|
157
|
+
text: finding.lane === "classifier" ? findingSegmentText(result, body, finding) : null,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Replace one span of the body; the span must still hold the text it was computed for. */
|
|
162
|
+
export function applyReplacement(body: string, span: Span, expected: string, replacement: string): string | null {
|
|
163
|
+
if (body.slice(span.start, span.end) !== expected) return null;
|
|
164
|
+
return body.slice(0, span.start) + replacement + body.slice(span.end);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function describeProbability(finding: EditorialFinding): string | null {
|
|
168
|
+
if (finding.probability === undefined) return null;
|
|
169
|
+
return `${Math.round(finding.probability * 100)}% sure`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function laneNotice(result: EditorialCheckResult): string | null {
|
|
173
|
+
const classifier = result.lanes.classifier;
|
|
174
|
+
if (classifier.status === "partial") return `Some sentences were not judged: ${classifier.reason ?? "the check ran out of time"}.`;
|
|
175
|
+
if (classifier.status === "failed") return `The judgment checks failed: ${classifier.reason ?? "unknown error"}. Rule checks still ran.`;
|
|
176
|
+
if (classifier.status === "unavailable" && (classifier.detectors ?? 0) === 0 && classifier.reason) return `Judgment checks are not configured: ${classifier.reason}.`;
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Places Limatus findings on the rendered Markus preview.
|
|
3
|
+
*
|
|
4
|
+
* Limatus reports spans in the markup; the preview renders an IR tree with no
|
|
5
|
+
* character offsets. Both sides agree on the words a reader sees, so findings
|
|
6
|
+
* are placed by text: each Limatus paragraph is matched, in document order, to
|
|
7
|
+
* the rendered prose block with the same words, and each finding's plain
|
|
8
|
+
* excerpt is located inside that block. Whitespace is ignored while matching,
|
|
9
|
+
* because rendering and Limatus collapse it differently (citations, breaks).
|
|
10
|
+
*
|
|
11
|
+
* "Rendered text" is defined by `inlineLeaves`, which the preview renderer also
|
|
12
|
+
* uses, so offsets computed here are offsets the renderer can split on.
|
|
13
|
+
*/
|
|
14
|
+
import type { EditorialCheckResult, EditorialFinding, Severity, Span } from "./editorial-checks";
|
|
15
|
+
import type { MarkusBlock, MarkusDocument, MarkusInline, MarkusNode } from "./markus-ir";
|
|
16
|
+
|
|
17
|
+
export const CITATION_TOKEN = /PAPYRUSMARKUP\d{5}END/g;
|
|
18
|
+
|
|
19
|
+
export type InlineLeaf =
|
|
20
|
+
| { kind: "text"; node: MarkusInline & { type: "text" }; start: number; pieces: { raw: string; start: number; isToken: boolean }[] }
|
|
21
|
+
| { kind: "code"; node: MarkusInline & { type: "code_span" }; start: number; text: string }
|
|
22
|
+
| { kind: "break"; start: number; text: string }
|
|
23
|
+
| { kind: "opaque"; start: number };
|
|
24
|
+
|
|
25
|
+
/** The reader-visible text of a run of inlines; citation tokens and images take no width. */
|
|
26
|
+
export function inlineLeaves(inlines: MarkusInline[], offset = 0): { leaves: InlineLeaf[]; text: string } {
|
|
27
|
+
const leaves: InlineLeaf[] = [];
|
|
28
|
+
let text = "";
|
|
29
|
+
const walk = (nodes: MarkusInline[]) => {
|
|
30
|
+
for (const node of nodes) {
|
|
31
|
+
const start = offset + text.length;
|
|
32
|
+
switch (node.type) {
|
|
33
|
+
case "text": {
|
|
34
|
+
const pieces: { raw: string; start: number; isToken: boolean }[] = [];
|
|
35
|
+
let cursor = 0;
|
|
36
|
+
let plainLength = 0;
|
|
37
|
+
for (const match of node.text.matchAll(CITATION_TOKEN)) {
|
|
38
|
+
const index = match.index ?? 0;
|
|
39
|
+
if (index > cursor) {
|
|
40
|
+
pieces.push({ raw: node.text.slice(cursor, index), start: start + plainLength, isToken: false });
|
|
41
|
+
plainLength += index - cursor;
|
|
42
|
+
}
|
|
43
|
+
pieces.push({ raw: match[0], start: start + plainLength, isToken: true });
|
|
44
|
+
cursor = index + match[0].length;
|
|
45
|
+
}
|
|
46
|
+
if (cursor < node.text.length) {
|
|
47
|
+
pieces.push({ raw: node.text.slice(cursor), start: start + plainLength, isToken: false });
|
|
48
|
+
plainLength += node.text.length - cursor;
|
|
49
|
+
}
|
|
50
|
+
leaves.push({ kind: "text", node, start, pieces });
|
|
51
|
+
text += pieces.filter((piece) => !piece.isToken).map((piece) => piece.raw).join("");
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "code_span":
|
|
55
|
+
leaves.push({ kind: "code", node, start, text: node.code });
|
|
56
|
+
text += node.code;
|
|
57
|
+
break;
|
|
58
|
+
case "soft_break":
|
|
59
|
+
case "hard_break":
|
|
60
|
+
leaves.push({ kind: "break", start, text: " " });
|
|
61
|
+
text += " ";
|
|
62
|
+
break;
|
|
63
|
+
case "emphasis":
|
|
64
|
+
case "strong":
|
|
65
|
+
case "strikethrough":
|
|
66
|
+
case "link":
|
|
67
|
+
walk(node.children);
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
leaves.push({ kind: "opaque", start });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
walk(inlines);
|
|
75
|
+
return { leaves, text };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Prose blocks (paragraphs and headings, including those inside lists, quotes and directives) in reading order. */
|
|
79
|
+
export function proseBlocks(document: MarkusDocument): (MarkusBlock & { inline: MarkusInline[] })[] {
|
|
80
|
+
const blocks: (MarkusBlock & { inline: MarkusInline[] })[] = [];
|
|
81
|
+
const visit = (nodes: MarkusNode[]) => {
|
|
82
|
+
for (const node of nodes) {
|
|
83
|
+
if (node.type === "directive") visit(node.children);
|
|
84
|
+
else if (node.type === "paragraph" || node.type === "heading") blocks.push(node);
|
|
85
|
+
else if (node.type === "list") for (const item of node.items) visit(item.children);
|
|
86
|
+
else if (node.type === "blockquote") visit(node.children);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
visit(document.children);
|
|
90
|
+
return blocks;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type PreviewMark = Span & { findingIds: string[]; severity: Severity; status: EditorialFinding["status"] };
|
|
94
|
+
export type PreviewSentence = Span & { segmentId: string; source: Span };
|
|
95
|
+
|
|
96
|
+
/** What the preview needs for one rendered block, in that block's rendered-text offsets. */
|
|
97
|
+
export type BlockAnnotation = { marks: PreviewMark[]; sentences: PreviewSentence[] };
|
|
98
|
+
|
|
99
|
+
export type PreviewPlan = WeakMap<object, BlockAnnotation>;
|
|
100
|
+
|
|
101
|
+
const SEVERITY_RANK: Record<Severity, number> = { error: 0, warn: 1, info: 2 };
|
|
102
|
+
|
|
103
|
+
/** Text without whitespace, with a map from each kept character back to its index in the original. */
|
|
104
|
+
function compact(text: string): { value: string; index: number[] } {
|
|
105
|
+
let value = "";
|
|
106
|
+
const index: number[] = [];
|
|
107
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
108
|
+
if (!/\s/.test(text[i])) {
|
|
109
|
+
value += text[i];
|
|
110
|
+
index.push(i);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return { value, index };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Locate `needle` in `haystack` ignoring whitespace; the occurrence nearest `near` (a 0..1 position) wins. */
|
|
117
|
+
export function locate(haystack: string, needle: string, near = 0): Span | null {
|
|
118
|
+
const hay = compact(haystack);
|
|
119
|
+
const want = compact(needle).value;
|
|
120
|
+
if (!want) return null;
|
|
121
|
+
let best: number | null = null;
|
|
122
|
+
for (let at = hay.value.indexOf(want); at !== -1; at = hay.value.indexOf(want, at + 1)) {
|
|
123
|
+
if (best === null || Math.abs(at / Math.max(hay.value.length, 1) - near) < Math.abs(best / Math.max(hay.value.length, 1) - near)) best = at;
|
|
124
|
+
}
|
|
125
|
+
if (best === null) return null;
|
|
126
|
+
return { start: hay.index[best], end: hay.index[best + want.length - 1] + 1 };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The identity of a block's words: no whitespace, no stray emphasis or code markers. */
|
|
130
|
+
function blockKey(text: string): string {
|
|
131
|
+
return compact(text).value.replace(/[*_`~]/g, "");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Match every Limatus paragraph to a rendered block and place its findings and sentences there. */
|
|
135
|
+
export function planPreview(
|
|
136
|
+
document: MarkusDocument,
|
|
137
|
+
result: EditorialCheckResult,
|
|
138
|
+
findings: EditorialFinding[],
|
|
139
|
+
): PreviewPlan {
|
|
140
|
+
const plan: PreviewPlan = new WeakMap();
|
|
141
|
+
const blocks = proseBlocks(document).map((block) => ({ block, text: inlineLeaves(block.inline).text }));
|
|
142
|
+
const paragraphs = result.segments.filter((segment) => segment.kind === "paragraph" && segment.text);
|
|
143
|
+
let cursor = 0;
|
|
144
|
+
for (const paragraph of paragraphs) {
|
|
145
|
+
const wanted = blockKey(paragraph.text ?? "");
|
|
146
|
+
let matched = -1;
|
|
147
|
+
for (let candidate = cursor; candidate < blocks.length; candidate += 1) {
|
|
148
|
+
if (blockKey(blocks[candidate].text) === wanted) {
|
|
149
|
+
matched = candidate;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (matched === -1) continue;
|
|
154
|
+
cursor = matched + 1;
|
|
155
|
+
const { block, text } = blocks[matched];
|
|
156
|
+
const sentences: PreviewSentence[] = [];
|
|
157
|
+
for (const sentence of result.segments.filter((s) => s.kind === "sentence" && s.parentId === paragraph.id)) {
|
|
158
|
+
const near = (sentence.start - paragraph.start) / Math.max(paragraph.end - paragraph.start, 1);
|
|
159
|
+
const span = locate(text, sentence.text ?? "", near);
|
|
160
|
+
if (span) sentences.push({ ...span, segmentId: sentence.id, source: { start: sentence.start, end: sentence.end } });
|
|
161
|
+
}
|
|
162
|
+
const ranges: (Span & { finding: EditorialFinding })[] = [];
|
|
163
|
+
for (const finding of findings) {
|
|
164
|
+
const inParagraph =
|
|
165
|
+
finding.segmentId === paragraph.id ||
|
|
166
|
+
result.segments.some((s) => s.id === finding.segmentId && s.parentId === paragraph.id);
|
|
167
|
+
if (!inParagraph || !finding.excerptText) continue;
|
|
168
|
+
const near = (finding.span.start - paragraph.start) / Math.max(paragraph.end - paragraph.start, 1);
|
|
169
|
+
const span = locate(text, finding.excerptText, near);
|
|
170
|
+
if (span) ranges.push({ ...span, finding });
|
|
171
|
+
}
|
|
172
|
+
plan.set(block, { marks: flatten(ranges), sentences });
|
|
173
|
+
}
|
|
174
|
+
return plan;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Overlapping finding ranges become non-overlapping marks, each listing every finding it belongs to. */
|
|
178
|
+
function flatten(ranges: (Span & { finding: EditorialFinding })[]): PreviewMark[] {
|
|
179
|
+
const cuts = [...new Set(ranges.flatMap((range) => [range.start, range.end]))].sort((a, b) => a - b);
|
|
180
|
+
const marks: PreviewMark[] = [];
|
|
181
|
+
for (let i = 0; i < cuts.length - 1; i += 1) {
|
|
182
|
+
const start = cuts[i];
|
|
183
|
+
const end = cuts[i + 1];
|
|
184
|
+
const covering = ranges.filter((range) => range.start <= start && end <= range.end).map((range) => range.finding);
|
|
185
|
+
if (covering.length === 0) continue;
|
|
186
|
+
const strongest = [...covering].sort((a, b) => SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity])[0];
|
|
187
|
+
const previous = marks[marks.length - 1];
|
|
188
|
+
const ids = covering.map((finding) => finding.id).sort();
|
|
189
|
+
if (previous && previous.end === start && previous.findingIds.join() === ids.join()) {
|
|
190
|
+
previous.end = end;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
marks.push({
|
|
194
|
+
start,
|
|
195
|
+
end,
|
|
196
|
+
findingIds: ids,
|
|
197
|
+
severity: strongest.severity,
|
|
198
|
+
status: covering.every((finding) => finding.status === "review") ? "review" : "violation",
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return marks;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** A selection on the preview, as the source span of the whole sentences it touches. */
|
|
205
|
+
export function selectionToSource(annotation: BlockAnnotation | undefined, selection: Span): Span | null {
|
|
206
|
+
if (!annotation) return null;
|
|
207
|
+
const touched = annotation.sentences.filter((sentence) => sentence.start < selection.end && selection.start < sentence.end);
|
|
208
|
+
if (touched.length === 0) return null;
|
|
209
|
+
return {
|
|
210
|
+
start: Math.min(...touched.map((sentence) => sentence.source.start)),
|
|
211
|
+
end: Math.max(...touched.map((sentence) => sentence.source.end)),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Split [start, end) of rendered text at mark boundaries; each piece says which mark (if any) covers it. */
|
|
216
|
+
export function splitByMarks(start: number, end: number, marks: PreviewMark[]): { start: number; end: number; mark: PreviewMark | null }[] {
|
|
217
|
+
const pieces: { start: number; end: number; mark: PreviewMark | null }[] = [];
|
|
218
|
+
let cursor = start;
|
|
219
|
+
for (const mark of marks) {
|
|
220
|
+
if (mark.end <= cursor || mark.start >= end) continue;
|
|
221
|
+
if (mark.start > cursor) pieces.push({ start: cursor, end: mark.start, mark: null });
|
|
222
|
+
const pieceEnd = Math.min(mark.end, end);
|
|
223
|
+
pieces.push({ start: Math.max(mark.start, cursor), end: pieceEnd, mark });
|
|
224
|
+
cursor = pieceEnd;
|
|
225
|
+
}
|
|
226
|
+
if (cursor < end) pieces.push({ start: cursor, end, mark: null });
|
|
227
|
+
return pieces;
|
|
228
|
+
}
|
package/lib/newsroom-board.ts
CHANGED
|
@@ -21,6 +21,31 @@ export interface NativeBoardIssue extends KanbanIssue {
|
|
|
21
21
|
href: string;
|
|
22
22
|
/** A few lines to show under the headline: the blurb, else the subtitle. */
|
|
23
23
|
excerpt?: string;
|
|
24
|
+
/** The quiet path shown where a board would print the ID, e.g. `articles/my-slug` or `assignments/write-it`. */
|
|
25
|
+
displayId: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function slugify(text: string): string {
|
|
29
|
+
return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Section and slug for a content item, falling back to the publication's board path segment. */
|
|
33
|
+
export function contentItemDisplayId(version: { section?: string | null; slug?: string | null; lineageId: string }): string {
|
|
34
|
+
const section = slugify(version.section ?? "") || contentItemBoardPathSegment();
|
|
35
|
+
return `${section}/${slugify(version.slug ?? "") || version.lineageId.slice(0, 8)}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Assignments have no slug: use the title as one, else a short id. */
|
|
39
|
+
export function assignmentDisplayId(assignment: { id: string; title?: string | null }): string {
|
|
40
|
+
const titleSlug = slugify(assignment.title ?? "").slice(0, 48).replace(/-+$/g, "");
|
|
41
|
+
return `assignments/${titleSlug || assignment.id.slice(0, 8)}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** `formatIssueId` for the Kanbus UI: the host-provided path, never the raw `kind:id` prefix. */
|
|
45
|
+
export function formatNativeIssueId(issue: KanbanIssue): string {
|
|
46
|
+
const displayId = (issue as Partial<NativeBoardIssue>).displayId;
|
|
47
|
+
if (displayId) return displayId;
|
|
48
|
+
return issue.id.replace(/^[A-Za-z]+:/, "").slice(0, 12);
|
|
24
49
|
}
|
|
25
50
|
|
|
26
51
|
export function contentItemBoardPathSegment(): string {
|
|
@@ -60,7 +85,7 @@ export function projectContentItemBoard(records: {
|
|
|
60
85
|
title: version.headline || version.title || version.slug, nativeStatus: stage, status: `${contentItemType}/${stage}`,
|
|
61
86
|
priority: 2, description: workCount ? `${workCount} assignment${workCount === 1 ? "" : "s"} on this ${contentItemType}.` : undefined,
|
|
62
87
|
updated_at: version.updatedAt ?? undefined, href: `/newsroom/articles/${encodeURIComponent(version.id)}`,
|
|
63
|
-
excerpt: contentItemExcerpt(version),
|
|
88
|
+
excerpt: contentItemExcerpt(version), displayId: contentItemDisplayId(version),
|
|
64
89
|
};
|
|
65
90
|
});
|
|
66
91
|
}
|
|
@@ -73,7 +98,7 @@ export function projectAssignmentBoard(assignments: readonly AssignmentRecord[])
|
|
|
73
98
|
priority: row.priority ?? 2, assignee: row.assigneeId || undefined,
|
|
74
99
|
description: row.summary || row.brief || undefined,
|
|
75
100
|
created_at: row.createdAt, updated_at: row.updatedAt,
|
|
76
|
-
href: `/newsroom/assignments/${encodeURIComponent(row.id)}`,
|
|
101
|
+
href: `/newsroom/assignments/${encodeURIComponent(row.id)}`, displayId: assignmentDisplayId(row),
|
|
77
102
|
}));
|
|
78
103
|
}
|
|
79
104
|
|
package/lib/site-brand.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { ComponentType } from "react";
|
|
|
3
3
|
import type { EditionPresentationFormat } from "./content-types";
|
|
4
4
|
import type { Article, ArticleVideoAsset } from "./articles";
|
|
5
5
|
import type { BlogPageBackgroundProps } from "../components/blog-page-background";
|
|
6
|
+
import type { KanbusThemeId } from "@kanbus/ui";
|
|
6
7
|
import type { SiteBrandFont } from "./brand-fonts";
|
|
7
8
|
import type { PictogramFigureProps } from "../components/pictogram-figure";
|
|
8
9
|
import papyrusSite from "papyrus-site";
|
|
@@ -118,6 +119,13 @@ export type SiteBrand = {
|
|
|
118
119
|
defaultVideoCredit?: string;
|
|
119
120
|
themePack: ThemePackId;
|
|
120
121
|
themeTokens: ThemePackTokens;
|
|
122
|
+
/**
|
|
123
|
+
* The Kanbus editorial theme the whole newsroom (sidebar, toolbar, boards,
|
|
124
|
+
* detail panel) renders in. Hard-coded per publication: editors cannot
|
|
125
|
+
* change it. Per-publication tweaks are `--kb-theme-*` overrides in the
|
|
126
|
+
* publication's `theme.css`, scoped to `[data-kanbus-theme]`.
|
|
127
|
+
*/
|
|
128
|
+
kanbusTheme: KanbusThemeId;
|
|
121
129
|
renderer: RendererConfig;
|
|
122
130
|
hosting: HostingConfig;
|
|
123
131
|
/** Static reader app when it is not co-hosted with this Papyrus checkout. */
|
|
@@ -182,6 +190,7 @@ const REFERENCE_SITE_BRANDS: Record<SiteBrandId, SiteBrand> = {
|
|
|
182
190
|
sectionLinkStrategy: "route",
|
|
183
191
|
themePack: "papyrus",
|
|
184
192
|
themeTokens: DEFAULT_THEME_PACK_TOKENS,
|
|
193
|
+
kanbusTheme: "broadsheet-green",
|
|
185
194
|
renderer: { kind: "pretext" },
|
|
186
195
|
hosting: { kind: "amplify-ssr" },
|
|
187
196
|
opsChrome: "app",
|
|
@@ -237,6 +246,14 @@ export function getSiteBrand(id: SiteBrandId = resolveSiteBrandId()): SiteBrand
|
|
|
237
246
|
|
|
238
247
|
export const SITE_BRAND = getSiteBrand();
|
|
239
248
|
|
|
249
|
+
/** Mirrors `DEFAULT_KANBUS_THEME` from `@kanbus/ui` (a test keeps the two equal) without a runtime import. */
|
|
250
|
+
export const FALLBACK_KANBUS_THEME: KanbusThemeId = "newspaper-gothic";
|
|
251
|
+
|
|
252
|
+
/** The newsroom theme for a brand; a brand that predates the field falls back to the default theme. */
|
|
253
|
+
export function getKanbusTheme(brand: Pick<SiteBrand, "kanbusTheme"> = SITE_BRAND): KanbusThemeId {
|
|
254
|
+
return brand.kanbusTheme ?? FALLBACK_KANBUS_THEME;
|
|
255
|
+
}
|
|
256
|
+
|
|
240
257
|
export function getContentItemName(brand: SiteBrand = SITE_BRAND): ContentItemName {
|
|
241
258
|
return brand.contentItemName ?? DEFAULT_CONTENT_ITEM_NAME;
|
|
242
259
|
}
|
package/package.json
CHANGED
|
@@ -78,7 +78,12 @@
|
|
|
78
78
|
"./components/blog-page-background": "./components/blog-page-background.tsx",
|
|
79
79
|
"./components/curation-delegation-client": "./components/curation-delegation-client.ts",
|
|
80
80
|
"./components/dev-sandbox-editor-sign-in": "./components/dev-sandbox-editor-sign-in.tsx",
|
|
81
|
+
"./components/editorial-checks-admin-panel": "./components/editorial-checks-admin-panel.tsx",
|
|
82
|
+
"./components/editorial-finding-card": "./components/editorial-finding-card.tsx",
|
|
83
|
+
"./components/editorial-findings-panel": "./components/editorial-findings-panel.tsx",
|
|
84
|
+
"./components/editorial-preview-popover": "./components/editorial-preview-popover.tsx",
|
|
81
85
|
"./components/item-stream-view": "./components/item-stream-view.tsx",
|
|
86
|
+
"./components/markus-body-editor": "./components/markus-body-editor.tsx",
|
|
82
87
|
"./components/markus-ir-preview": "./components/markus-ir-preview.tsx",
|
|
83
88
|
"./components/news-desk-client-provider": "./components/news-desk-client-provider.tsx",
|
|
84
89
|
"./components/news-desk-page": "./components/news-desk-page.tsx",
|
|
@@ -95,6 +100,11 @@
|
|
|
95
100
|
"./components/newsroom-ops-overview": "./components/newsroom-ops-overview.tsx",
|
|
96
101
|
"./components/newsroom-ops-shell": "./components/newsroom-ops-shell.tsx",
|
|
97
102
|
"./components/newsroom-references-view": "./components/newsroom-references-view.tsx",
|
|
103
|
+
"./components/newsroom-theme-fonts/broadsheet-green": "./components/newsroom-theme-fonts/broadsheet-green.tsx",
|
|
104
|
+
"./components/newsroom-theme-fonts/newspaper-gothic": "./components/newsroom-theme-fonts/newspaper-gothic.tsx",
|
|
105
|
+
"./components/newsroom-theme-fonts/night-desk": "./components/newsroom-theme-fonts/night-desk.tsx",
|
|
106
|
+
"./components/newsroom-theme-fonts/refined-newsprint": "./components/newsroom-theme-fonts/refined-newsprint.tsx",
|
|
107
|
+
"./components/newsroom-theme": "./components/newsroom-theme.tsx",
|
|
98
108
|
"./components/newsroom-topics-view": "./components/newsroom-topics-view.tsx",
|
|
99
109
|
"./components/papyrus-console-shell": "./components/papyrus-console-shell.tsx",
|
|
100
110
|
"./components/pictogram-figure": "./components/pictogram-figure.tsx",
|
|
@@ -143,6 +153,7 @@
|
|
|
143
153
|
"./components/ui/tooltip": "./components/ui/tooltip.tsx",
|
|
144
154
|
"./components/use-blog-header-obstacles": "./components/use-blog-header-obstacles.ts",
|
|
145
155
|
"./components/use-brand-fonts-ready": "./components/use-brand-fonts-ready.ts",
|
|
156
|
+
"./components/use-editorial-checks": "./components/use-editorial-checks.ts",
|
|
146
157
|
"./components/use-near-viewport": "./components/use-near-viewport.ts",
|
|
147
158
|
"./components/use-paged-content-item-versions": "./components/use-paged-content-item-versions.ts",
|
|
148
159
|
"./components/use-resolved-papyrus-theme": "./components/use-resolved-papyrus-theme.ts",
|
|
@@ -184,6 +195,12 @@
|
|
|
184
195
|
"./lib/doctrine": "./lib/doctrine.ts",
|
|
185
196
|
"./lib/edition-routes": "./lib/edition-routes.ts",
|
|
186
197
|
"./lib/edition-sections": "./lib/edition-sections.ts",
|
|
198
|
+
"./lib/editorial-checks-backend": "./lib/editorial-checks-backend.ts",
|
|
199
|
+
"./lib/editorial-checks-client": "./lib/editorial-checks-client.ts",
|
|
200
|
+
"./lib/editorial-checks-demo": "./lib/editorial-checks-demo.ts",
|
|
201
|
+
"./lib/editorial-checks-settings": "./lib/editorial-checks-settings.ts",
|
|
202
|
+
"./lib/editorial-checks": "./lib/editorial-checks.ts",
|
|
203
|
+
"./lib/editorial-preview": "./lib/editorial-preview.ts",
|
|
187
204
|
"./lib/empty-edition-layout-plan": "./lib/empty-edition-layout-plan.ts",
|
|
188
205
|
"./lib/excerpts": "./lib/excerpts.ts",
|
|
189
206
|
"./lib/front-matter-fields": "./lib/front-matter-fields.ts",
|
|
@@ -378,7 +395,7 @@
|
|
|
378
395
|
"optional": true
|
|
379
396
|
}
|
|
380
397
|
},
|
|
381
|
-
"version": "
|
|
398
|
+
"version": "3.1.0",
|
|
382
399
|
"dependencies": {
|
|
383
400
|
"@aws-amplify/adapter-nextjs": "^1.7.3",
|
|
384
401
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
@@ -391,7 +408,22 @@
|
|
|
391
408
|
"@aws-sdk/s3-request-presigner": "^3.1045.0",
|
|
392
409
|
"@base-ui/react": "^1.5.0",
|
|
393
410
|
"@chenglou/pretext": "^0.0.7",
|
|
394
|
-
"@
|
|
411
|
+
"@codemirror/commands": "^6.11.1",
|
|
412
|
+
"@codemirror/lang-markdown": "^6.5.2",
|
|
413
|
+
"@codemirror/language": "^6.13.1",
|
|
414
|
+
"@codemirror/state": "^6.7.6",
|
|
415
|
+
"@codemirror/view": "^6.43.15",
|
|
416
|
+
"@fontsource-variable/hanken-grotesk": "5.3.0",
|
|
417
|
+
"@fontsource-variable/jetbrains-mono": "5.3.0",
|
|
418
|
+
"@fontsource-variable/libre-franklin": "5.3.0",
|
|
419
|
+
"@fontsource-variable/literata": "5.3.0",
|
|
420
|
+
"@fontsource-variable/newsreader": "5.3.0",
|
|
421
|
+
"@fontsource-variable/public-sans": "5.3.0",
|
|
422
|
+
"@fontsource-variable/source-serif-4": "5.3.1",
|
|
423
|
+
"@fontsource/ibm-plex-mono": "5.3.0",
|
|
424
|
+
"@fontsource/ibm-plex-sans": "5.3.0",
|
|
425
|
+
"@kanbus/ui": "https://github.com/AnthusAI/Kanbus/releases/download/ui-v0.4.1/kanbus-ui-0.4.1.tgz",
|
|
426
|
+
"@lezer/highlight": "^1.2.5",
|
|
395
427
|
"@radix-ui/colors": "3.0.0",
|
|
396
428
|
"@smithy/protocol-http": "5.4.1",
|
|
397
429
|
"@smithy/signature-v4": "5.7.4",
|
package/routes.manifest.json
CHANGED
|
Binary file
|
|
Binary file
|