@open-document/core 0.11.0 → 0.13.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/dist/{build-BHFGY8eF.js → build-CbgIk6bA.js} +1 -1
- package/dist/{check-UEBmDfT_.js → check-BTroj-5Z.js} +3 -3
- package/dist/cli/bin.js +58 -34
- package/dist/config-BWtOZ1jc.d.ts +45 -0
- package/dist/{config-B_pdNbYg.js → config-DKKNIbvO.js} +1458 -983
- package/dist/{context-BM9_-u9P.js → context-DXNP8v9I.js} +3 -2
- package/dist/deploy-gcp-BUiSuqz7.js +758 -0
- package/dist/{dev-DX3QMIRi.js → dev-YXumw5iX.js} +1 -1
- package/dist/{diagram-BK4jTZr4.js → diagram-CKf3ptOE.js} +293 -13
- package/dist/{diff-DayvbXfX.js → diff-CTFfU4Tz.js} +2 -2
- package/dist/{export-BPsXj1i6.js → export-D2QLtF84.js} +11 -4
- package/dist/flow-CS5apebG.d.ts +252 -0
- package/dist/{import-71wlAsrd.js → import-CcmrFetU.js} +3 -2
- package/dist/index.d.ts +155 -59
- package/dist/index.js +945 -104
- package/dist/open-doc-plugin-DnX5usgI.js +320 -0
- package/dist/ops/index.d.ts +112 -3
- package/dist/ops/index.js +3 -3
- package/dist/{ops-BUo67DaP.js → ops-DmEecq1k.js} +86 -164
- package/dist/package-version-C89gtYSk.js +36 -0
- package/dist/{preview-D3m1-gUL.js → preview-_mHpBhMk.js} +1 -1
- package/dist/templates-MMblHwmT.js +34 -0
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +2 -1
- package/package.json +2 -1
- package/skills/apply-comments/SKILL.md +3 -1
- package/skills/create-doc/SKILL.md +2 -0
- package/skills/doc-authoring/SKILL.md +17 -16
- package/skills/doc-authoring/references/long-form.md +43 -2
- package/skills/doc-authoring/references/pagination.md +14 -2
- package/skills/doc-authoring/references/tables-and-charts.md +21 -17
- package/src/app/components/browser/browser-ui.tsx +21 -0
- package/src/app/components/browser/new-document-dialog.tsx +208 -0
- package/src/app/components/callout.tsx +101 -0
- package/src/app/components/changes/changes-overlay.tsx +68 -0
- package/src/app/components/changes/changes-panel.tsx +341 -0
- package/src/app/components/changes/use-changes.ts +85 -0
- package/src/app/components/chart.tsx +191 -33
- package/src/app/components/code-block.tsx +249 -0
- package/src/app/components/comments/comments-overlay.tsx +50 -0
- package/src/app/components/comments/comments-panel.tsx +272 -0
- package/src/app/components/comments/use-comments.ts +61 -0
- package/src/app/components/data-table.tsx +146 -18
- package/src/app/components/doc-sidebar.tsx +32 -2
- package/src/app/components/flow-page.tsx +57 -8
- package/src/app/components/inspector/field-source.tsx +41 -0
- package/src/app/components/inspector/inspector.tsx +64 -65
- package/src/app/components/numbering.tsx +226 -12
- package/src/app/components/overlay-frame.tsx +79 -0
- package/src/app/components/page-frame.tsx +46 -0
- package/src/app/components/page-placement.ts +68 -0
- package/src/app/components/record-picker.tsx +79 -0
- package/src/app/components/themes/theme-preview.tsx +5 -4
- package/src/app/lib/agent-bridge.ts +29 -1
- package/src/app/lib/chart.test.ts +15 -0
- package/src/app/lib/chart.ts +134 -9
- package/src/app/lib/diagnostics.ts +45 -1
- package/src/app/lib/docx/ooxml.test.ts +24 -1
- package/src/app/lib/docx/ooxml.ts +27 -1
- package/src/app/lib/export-docx.ts +3 -1
- package/src/app/lib/export-dom.ts +17 -3
- package/src/app/lib/export-html.ts +4 -2
- package/src/app/lib/export-image.ts +2 -1
- package/src/app/lib/export-pdf.ts +9 -1
- package/src/app/lib/flow-measure.test.ts +30 -0
- package/src/app/lib/flow-measure.ts +68 -14
- package/src/app/lib/flow.test.ts +20 -1
- package/src/app/lib/flow.ts +120 -20
- package/src/app/lib/i18n-ja/browser.ts +10 -0
- package/src/app/lib/i18n-ja/doc.ts +4 -0
- package/src/app/lib/i18n-ja/panels.ts +40 -0
- package/src/app/lib/i18n-ko/browser.ts +10 -0
- package/src/app/lib/i18n-ko/doc.ts +4 -0
- package/src/app/lib/i18n-ko/panels.ts +39 -0
- package/src/app/lib/i18n-zh-cn/browser.ts +10 -0
- package/src/app/lib/i18n-zh-cn/doc.ts +4 -0
- package/src/app/lib/i18n-zh-cn/panels.ts +38 -0
- package/src/app/lib/i18n-zh-tw/browser.ts +10 -0
- package/src/app/lib/i18n-zh-tw/doc.ts +4 -0
- package/src/app/lib/i18n-zh-tw/panels.ts +38 -0
- package/src/app/lib/labels.ts +29 -10
- package/src/app/lib/records.test.ts +38 -0
- package/src/app/lib/records.ts +127 -0
- package/src/app/lib/sdk.ts +35 -0
- package/src/app/lib/use-doc-module.ts +7 -0
- package/src/app/lib/use-doc-pages.ts +38 -17
- package/src/app/routes/doc.tsx +275 -13
- package/src/app/routes/home.tsx +30 -5
- package/src/app/styles.css +23 -0
- package/templates/blank/index.tsx +63 -0
- package/templates/blank/template.json +6 -0
- package/templates/certificate/data/recipients.csv +4 -0
- package/templates/certificate/index.tsx +128 -0
- package/templates/certificate/template.json +6 -0
- package/templates/letter/index.tsx +106 -0
- package/templates/letter/template.json +5 -0
- package/templates/meeting-notes/index.tsx +194 -0
- package/templates/meeting-notes/template.json +6 -0
- package/templates/proposal/index.tsx +264 -0
- package/templates/proposal/template.json +6 -0
- package/templates/report/data/metrics.csv +5 -0
- package/templates/report/index.tsx +224 -0
- package/templates/report/template.json +6 -0
- package/dist/config-P61niZMf.d.ts +0 -24
- package/dist/sdk-CpDEGRIo.d.ts +0 -138
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import { LOC_PROP, sourceAttrs } from '../lib/source-loc';
|
|
3
|
+
|
|
4
|
+
export type CodeBlockProps = {
|
|
5
|
+
code?: string;
|
|
6
|
+
children?: string;
|
|
7
|
+
lang?: string;
|
|
8
|
+
title?: ReactNode;
|
|
9
|
+
lineNumbers?: boolean;
|
|
10
|
+
/** 1-based line numbers to highlight. */
|
|
11
|
+
highlightLines?: number[];
|
|
12
|
+
style?: CSSProperties;
|
|
13
|
+
className?: string;
|
|
14
|
+
[LOC_PROP]?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type TokenKind = 'plain' | 'keyword' | 'string' | 'comment' | 'number' | 'type';
|
|
18
|
+
|
|
19
|
+
type Token = { kind: TokenKind; text: string };
|
|
20
|
+
|
|
21
|
+
const KEYWORDS = new Set([
|
|
22
|
+
'import',
|
|
23
|
+
'from',
|
|
24
|
+
'export',
|
|
25
|
+
'default',
|
|
26
|
+
'const',
|
|
27
|
+
'let',
|
|
28
|
+
'var',
|
|
29
|
+
'function',
|
|
30
|
+
'return',
|
|
31
|
+
'if',
|
|
32
|
+
'else',
|
|
33
|
+
'for',
|
|
34
|
+
'while',
|
|
35
|
+
'switch',
|
|
36
|
+
'case',
|
|
37
|
+
'break',
|
|
38
|
+
'continue',
|
|
39
|
+
'async',
|
|
40
|
+
'await',
|
|
41
|
+
'try',
|
|
42
|
+
'catch',
|
|
43
|
+
'finally',
|
|
44
|
+
'throw',
|
|
45
|
+
'new',
|
|
46
|
+
'class',
|
|
47
|
+
'extends',
|
|
48
|
+
'implements',
|
|
49
|
+
'interface',
|
|
50
|
+
'type',
|
|
51
|
+
'satisfies',
|
|
52
|
+
'as',
|
|
53
|
+
'true',
|
|
54
|
+
'false',
|
|
55
|
+
'null',
|
|
56
|
+
'undefined',
|
|
57
|
+
'def',
|
|
58
|
+
'elif',
|
|
59
|
+
'in',
|
|
60
|
+
'and',
|
|
61
|
+
'or',
|
|
62
|
+
'not',
|
|
63
|
+
'SELECT',
|
|
64
|
+
'FROM',
|
|
65
|
+
'WHERE',
|
|
66
|
+
'GROUP',
|
|
67
|
+
'BY',
|
|
68
|
+
'ORDER',
|
|
69
|
+
'LIMIT',
|
|
70
|
+
'JOIN',
|
|
71
|
+
'ON',
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
const TOKEN_RE =
|
|
75
|
+
/(\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\/)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)|\b(\d+(?:\.\d+)?)\b|\b([A-Za-z_][A-Za-z0-9_]*)\b/g;
|
|
76
|
+
|
|
77
|
+
function tokenizeLine(line: string): Token[] {
|
|
78
|
+
const out: Token[] = [];
|
|
79
|
+
let cursor = 0;
|
|
80
|
+
for (const match of line.matchAll(TOKEN_RE)) {
|
|
81
|
+
const idx = match.index ?? 0;
|
|
82
|
+
if (idx > cursor) {
|
|
83
|
+
out.push({ kind: 'plain', text: line.slice(cursor, idx) });
|
|
84
|
+
}
|
|
85
|
+
const [full, comment, str, num, ident] = match;
|
|
86
|
+
if (comment !== undefined) {
|
|
87
|
+
out.push({ kind: 'comment', text: full });
|
|
88
|
+
} else if (str !== undefined) {
|
|
89
|
+
out.push({ kind: 'string', text: full });
|
|
90
|
+
} else if (num !== undefined) {
|
|
91
|
+
out.push({ kind: 'number', text: full });
|
|
92
|
+
} else if (ident !== undefined) {
|
|
93
|
+
if (KEYWORDS.has(ident)) {
|
|
94
|
+
out.push({ kind: 'keyword', text: full });
|
|
95
|
+
} else if (/^[A-Z]/.test(ident)) {
|
|
96
|
+
out.push({ kind: 'type', text: full });
|
|
97
|
+
} else {
|
|
98
|
+
out.push({ kind: 'plain', text: full });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
cursor = idx + full.length;
|
|
102
|
+
}
|
|
103
|
+
if (cursor < line.length) {
|
|
104
|
+
out.push({ kind: 'plain', text: line.slice(cursor) });
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function tokenStyle(kind: TokenKind): CSSProperties | undefined {
|
|
110
|
+
switch (kind) {
|
|
111
|
+
case 'keyword':
|
|
112
|
+
return { color: 'var(--od-accent, #2563eb)', fontWeight: 600 };
|
|
113
|
+
case 'string':
|
|
114
|
+
return { color: '#0f766e' };
|
|
115
|
+
case 'comment':
|
|
116
|
+
return { color: 'var(--od-muted, #6b7280)', fontStyle: 'italic' };
|
|
117
|
+
case 'number':
|
|
118
|
+
return { color: '#b45309' };
|
|
119
|
+
case 'type':
|
|
120
|
+
return {
|
|
121
|
+
color: 'color-mix(in srgb, var(--od-accent, #2563eb) 75%, var(--od-text, #16181d))',
|
|
122
|
+
fontWeight: 500,
|
|
123
|
+
};
|
|
124
|
+
default:
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Print-ready syntax-highlighted code block with optional header bar, line
|
|
131
|
+
* numbers, and highlighted lines. Uses `--od-*` variables so it harmonizes with
|
|
132
|
+
* the document's design system and exports cleanly to PDF, HTML, and Word.
|
|
133
|
+
*/
|
|
134
|
+
export function CodeBlock({
|
|
135
|
+
code,
|
|
136
|
+
children,
|
|
137
|
+
lang,
|
|
138
|
+
title,
|
|
139
|
+
lineNumbers = false,
|
|
140
|
+
highlightLines,
|
|
141
|
+
style,
|
|
142
|
+
className,
|
|
143
|
+
[LOC_PROP]: loc,
|
|
144
|
+
}: CodeBlockProps) {
|
|
145
|
+
const raw = (code ?? children ?? '').replace(/^\n+|\s+$/g, '');
|
|
146
|
+
const lines = raw.split('\n');
|
|
147
|
+
const highlighted = new Set(highlightLines ?? []);
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div
|
|
151
|
+
{...sourceAttrs(loc)}
|
|
152
|
+
className={className}
|
|
153
|
+
style={{
|
|
154
|
+
border: '1px solid var(--od-rule, #e5e7eb)',
|
|
155
|
+
borderRadius: 'var(--od-radius, 6px)',
|
|
156
|
+
background: 'color-mix(in srgb, var(--od-text, #16181d) 3%, var(--od-bg, #ffffff))',
|
|
157
|
+
overflow: 'hidden',
|
|
158
|
+
margin: '0 0 12px',
|
|
159
|
+
...style,
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
{(title || lang) && (
|
|
163
|
+
<div
|
|
164
|
+
style={{
|
|
165
|
+
display: 'flex',
|
|
166
|
+
alignItems: 'center',
|
|
167
|
+
justifyContent: 'space-between',
|
|
168
|
+
padding: '5px 12px',
|
|
169
|
+
borderBottom: '1px solid var(--od-rule, #e5e7eb)',
|
|
170
|
+
background: 'color-mix(in srgb, var(--od-text, #16181d) 5%, var(--od-bg, #ffffff))',
|
|
171
|
+
fontFamily: 'var(--od-font-mono, monospace)',
|
|
172
|
+
fontSize: 10.5,
|
|
173
|
+
color: 'var(--od-muted, #6b7280)',
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
<span style={{ fontWeight: 600, color: 'var(--od-text, #16181d)' }}>{title ?? ''}</span>
|
|
177
|
+
{lang && (
|
|
178
|
+
<span style={{ textTransform: 'uppercase', letterSpacing: '0.05em', fontSize: 9.5 }}>
|
|
179
|
+
{lang}
|
|
180
|
+
</span>
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
)}
|
|
184
|
+
<pre
|
|
185
|
+
style={{
|
|
186
|
+
margin: 0,
|
|
187
|
+
padding: '10px 12px',
|
|
188
|
+
fontFamily: 'var(--od-font-mono, monospace)',
|
|
189
|
+
fontSize: 11,
|
|
190
|
+
lineHeight: 1.55,
|
|
191
|
+
color: 'var(--od-text, #16181d)',
|
|
192
|
+
whiteSpace: 'pre-wrap',
|
|
193
|
+
overflowWrap: 'anywhere',
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
{lines.map((line, index) => {
|
|
197
|
+
const lineNo = index + 1;
|
|
198
|
+
const isHighlighted = highlighted.has(lineNo);
|
|
199
|
+
const tokens = tokenizeLine(line);
|
|
200
|
+
return (
|
|
201
|
+
<div
|
|
202
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: source line order
|
|
203
|
+
key={index}
|
|
204
|
+
style={{
|
|
205
|
+
display: 'flex',
|
|
206
|
+
...(isHighlighted
|
|
207
|
+
? {
|
|
208
|
+
background: 'color-mix(in srgb, var(--od-accent, #2563eb) 10%, transparent)',
|
|
209
|
+
margin: '0 -12px',
|
|
210
|
+
padding: '0 12px',
|
|
211
|
+
borderLeft: '2.5px solid var(--od-accent, #2563eb)',
|
|
212
|
+
}
|
|
213
|
+
: {}),
|
|
214
|
+
}}
|
|
215
|
+
>
|
|
216
|
+
{lineNumbers && (
|
|
217
|
+
<span
|
|
218
|
+
aria-hidden="true"
|
|
219
|
+
style={{
|
|
220
|
+
flex: 'none',
|
|
221
|
+
width: 24,
|
|
222
|
+
paddingRight: 8,
|
|
223
|
+
textAlign: 'right',
|
|
224
|
+
color: 'var(--od-muted, #6b7280)',
|
|
225
|
+
userSelect: 'none',
|
|
226
|
+
fontVariantNumeric: 'tabular-nums',
|
|
227
|
+
opacity: 0.65,
|
|
228
|
+
}}
|
|
229
|
+
>
|
|
230
|
+
{lineNo}
|
|
231
|
+
</span>
|
|
232
|
+
)}
|
|
233
|
+
<span style={{ flex: 1 }}>
|
|
234
|
+
{tokens.length === 0
|
|
235
|
+
? '\u00a0'
|
|
236
|
+
: tokens.map((tok, ti) => (
|
|
237
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: token sequence
|
|
238
|
+
<span key={ti} style={tokenStyle(tok.kind)}>
|
|
239
|
+
{tok.text}
|
|
240
|
+
</span>
|
|
241
|
+
))}
|
|
242
|
+
</span>
|
|
243
|
+
</div>
|
|
244
|
+
);
|
|
245
|
+
})}
|
|
246
|
+
</pre>
|
|
247
|
+
</div>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createPortal } from 'react-dom';
|
|
2
|
+
import { OverlayFrame } from '../overlay-frame';
|
|
3
|
+
import { elementsAtLoc } from '../page-placement';
|
|
4
|
+
import { Pin } from './comments-panel';
|
|
5
|
+
import type { DocComment } from './use-comments';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Each comment's number pinned at the top right of the element it is about,
|
|
9
|
+
* and the element outlined while its comment is the one selected.
|
|
10
|
+
*/
|
|
11
|
+
export function CommentsOverlay({
|
|
12
|
+
container,
|
|
13
|
+
comments,
|
|
14
|
+
activeId,
|
|
15
|
+
}: {
|
|
16
|
+
container: HTMLElement;
|
|
17
|
+
comments: DocComment[];
|
|
18
|
+
activeId: string | null;
|
|
19
|
+
}) {
|
|
20
|
+
return createPortal(
|
|
21
|
+
<div aria-hidden className="pointer-events-none absolute inset-0 z-20">
|
|
22
|
+
{comments.flatMap((comment, at) =>
|
|
23
|
+
comment.loc
|
|
24
|
+
? elementsAtLoc(container, comment.loc).map((el, copy) => (
|
|
25
|
+
<OverlayFrame
|
|
26
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: one loc can print more than once
|
|
27
|
+
key={`${comment.id}:${copy}`}
|
|
28
|
+
anchor={el}
|
|
29
|
+
container={container}
|
|
30
|
+
style={
|
|
31
|
+
comment.id === activeId
|
|
32
|
+
? {
|
|
33
|
+
outline: '2px solid var(--comment-pin)',
|
|
34
|
+
outlineOffset: 3,
|
|
35
|
+
background: 'color-mix(in oklch, var(--comment-pin) 8%, transparent)',
|
|
36
|
+
}
|
|
37
|
+
: {}
|
|
38
|
+
}
|
|
39
|
+
>
|
|
40
|
+
<span className="absolute -top-2.5 -right-2.5">
|
|
41
|
+
<Pin n={at + 1} active={comment.id === activeId} />
|
|
42
|
+
</span>
|
|
43
|
+
</OverlayFrame>
|
|
44
|
+
))
|
|
45
|
+
: [],
|
|
46
|
+
)}
|
|
47
|
+
</div>,
|
|
48
|
+
container,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { Check, ClipboardCopy, Crosshair, MessageSquare, MessageSquarePlus, X } from 'lucide-react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useLocale, useT } from '../../lib/i18n';
|
|
4
|
+
import { PanelIconButton, PanelShell } from '../panel/panel-shell';
|
|
5
|
+
import type { CommentsState, DocComment } from './use-comments';
|
|
6
|
+
|
|
7
|
+
/** The number a comment wears on the page and in the list, so the two can be matched by eye. */
|
|
8
|
+
export function Pin({ n, active = false }: { n: number; active?: boolean }) {
|
|
9
|
+
return (
|
|
10
|
+
<span
|
|
11
|
+
className={`flex size-5 flex-none items-center justify-center rounded-full font-mono font-semibold text-[10px] text-white tabular-nums ${
|
|
12
|
+
active ? 'ring-2 ring-offset-1 ring-offset-background' : ''
|
|
13
|
+
}`}
|
|
14
|
+
style={{
|
|
15
|
+
background: 'var(--comment-pin)',
|
|
16
|
+
['--tw-ring-color' as string]: 'var(--comment-pin)',
|
|
17
|
+
}}
|
|
18
|
+
>
|
|
19
|
+
{n}
|
|
20
|
+
</span>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function Card({
|
|
25
|
+
comment,
|
|
26
|
+
n,
|
|
27
|
+
page,
|
|
28
|
+
excerpt,
|
|
29
|
+
active,
|
|
30
|
+
onSelect,
|
|
31
|
+
onResolve,
|
|
32
|
+
}: {
|
|
33
|
+
comment: DocComment;
|
|
34
|
+
n: number;
|
|
35
|
+
page: number | undefined;
|
|
36
|
+
excerpt: string;
|
|
37
|
+
active: boolean;
|
|
38
|
+
onSelect: () => void;
|
|
39
|
+
onResolve: () => Promise<string | null>;
|
|
40
|
+
}) {
|
|
41
|
+
const t = useT();
|
|
42
|
+
const { locale } = useLocale();
|
|
43
|
+
const [busy, setBusy] = useState(false);
|
|
44
|
+
const [error, setError] = useState<string | null>(null);
|
|
45
|
+
const when = new Date(comment.ts);
|
|
46
|
+
return (
|
|
47
|
+
<li className="relative">
|
|
48
|
+
<button
|
|
49
|
+
type="button"
|
|
50
|
+
aria-current={active || undefined}
|
|
51
|
+
onClick={onSelect}
|
|
52
|
+
className="flex w-full gap-2.5 rounded-md py-2.5 pr-10 pl-2 text-left transition-colors hover:bg-accent/60 focus-visible:outline-2 focus-visible:outline-foreground/60 aria-[current]:bg-accent"
|
|
53
|
+
>
|
|
54
|
+
<Pin n={n} />
|
|
55
|
+
<span className="flex min-w-0 flex-1 flex-col gap-1">
|
|
56
|
+
<span className="whitespace-pre-wrap break-words text-xs leading-snug">
|
|
57
|
+
{comment.note}
|
|
58
|
+
</span>
|
|
59
|
+
{excerpt && (
|
|
60
|
+
<span className="truncate border-border border-l-2 pl-1.5 text-[11px] text-muted-foreground">
|
|
61
|
+
{excerpt}
|
|
62
|
+
</span>
|
|
63
|
+
)}
|
|
64
|
+
<span className="font-mono text-[10px] text-muted-foreground/80 tabular-nums">
|
|
65
|
+
{[
|
|
66
|
+
page ? t('p.{page}', { page }) : null,
|
|
67
|
+
Number.isNaN(when.getTime())
|
|
68
|
+
? null
|
|
69
|
+
: when.toLocaleString(locale, {
|
|
70
|
+
month: 'short',
|
|
71
|
+
day: 'numeric',
|
|
72
|
+
hour: '2-digit',
|
|
73
|
+
minute: '2-digit',
|
|
74
|
+
}),
|
|
75
|
+
]
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
.join(' · ')}
|
|
78
|
+
</span>
|
|
79
|
+
</span>
|
|
80
|
+
</button>
|
|
81
|
+
<button
|
|
82
|
+
type="button"
|
|
83
|
+
aria-label={t('Resolve')}
|
|
84
|
+
title={t('Resolve')}
|
|
85
|
+
disabled={busy}
|
|
86
|
+
onClick={async () => {
|
|
87
|
+
setBusy(true);
|
|
88
|
+
setError(await onResolve());
|
|
89
|
+
setBusy(false);
|
|
90
|
+
}}
|
|
91
|
+
className="absolute top-1.5 right-1 flex size-8 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-foreground/60 disabled:opacity-50"
|
|
92
|
+
>
|
|
93
|
+
<Check className="size-3.5" />
|
|
94
|
+
</button>
|
|
95
|
+
{error && (
|
|
96
|
+
<p
|
|
97
|
+
role="alert"
|
|
98
|
+
className="px-3 pb-2 text-[11px]"
|
|
99
|
+
style={{ color: 'var(--change-removed)' }}
|
|
100
|
+
>
|
|
101
|
+
{t(error)}
|
|
102
|
+
</p>
|
|
103
|
+
)}
|
|
104
|
+
</li>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Starting a comment, and the state it leaves the page in: pressed while the
|
|
110
|
+
* page waits for an element, pressed again to stop.
|
|
111
|
+
*/
|
|
112
|
+
function PickButton({ picking, onClick }: { picking: boolean; onClick: () => void }) {
|
|
113
|
+
const t = useT();
|
|
114
|
+
return (
|
|
115
|
+
<button
|
|
116
|
+
type="button"
|
|
117
|
+
aria-pressed={picking}
|
|
118
|
+
onClick={onClick}
|
|
119
|
+
className="flex h-8 w-full items-center justify-center gap-1.5 rounded border border-border px-3 text-foreground text-xs transition-colors hover:bg-accent focus-visible:outline-2 focus-visible:outline-foreground/60 aria-pressed:border-[var(--comment-pin)] aria-pressed:bg-accent"
|
|
120
|
+
>
|
|
121
|
+
{picking ? (
|
|
122
|
+
<>
|
|
123
|
+
<Crosshair className="size-3.5" style={{ color: 'var(--comment-pin)' }} />
|
|
124
|
+
{t('Pick an element on the page')}
|
|
125
|
+
<kbd className="ml-1 rounded bg-foreground/10 px-1 font-mono text-[10px] text-muted-foreground">
|
|
126
|
+
Esc
|
|
127
|
+
</kbd>
|
|
128
|
+
</>
|
|
129
|
+
) : (
|
|
130
|
+
<>
|
|
131
|
+
<MessageSquarePlus className="size-3.5" />
|
|
132
|
+
{t('New comment')}
|
|
133
|
+
</>
|
|
134
|
+
)}
|
|
135
|
+
</button>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type CommentsPanelProps = {
|
|
140
|
+
docId: string;
|
|
141
|
+
state: CommentsState;
|
|
142
|
+
placement: Map<string, number[]>;
|
|
143
|
+
/** The words of the element each comment is about, by comment id. */
|
|
144
|
+
excerpts: Map<string, string>;
|
|
145
|
+
activeId: string | null;
|
|
146
|
+
onSelect: (comment: DocComment) => void;
|
|
147
|
+
onResolve: (comment: DocComment) => Promise<string | null>;
|
|
148
|
+
/** Pick an element on the page to comment on; again to stop. */
|
|
149
|
+
onNew: () => void;
|
|
150
|
+
/** Waiting for that element. */
|
|
151
|
+
picking: boolean;
|
|
152
|
+
onClose: () => void;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The review notes on this document, numbered as they are pinned on the
|
|
157
|
+
* page. Resolving one takes its marker out of the source; handing them to the
|
|
158
|
+
* agent is one copied request, and what the agent changes shows up under
|
|
159
|
+
* Changes.
|
|
160
|
+
*/
|
|
161
|
+
export function CommentsPanel({
|
|
162
|
+
docId,
|
|
163
|
+
state,
|
|
164
|
+
placement,
|
|
165
|
+
excerpts,
|
|
166
|
+
activeId,
|
|
167
|
+
onSelect,
|
|
168
|
+
onResolve,
|
|
169
|
+
onNew,
|
|
170
|
+
picking,
|
|
171
|
+
onClose,
|
|
172
|
+
}: CommentsPanelProps) {
|
|
173
|
+
const t = useT();
|
|
174
|
+
const [copied, setCopied] = useState(false);
|
|
175
|
+
const comments = state.status === 'ready' ? state.comments : [];
|
|
176
|
+
|
|
177
|
+
const copy = async () => {
|
|
178
|
+
try {
|
|
179
|
+
await navigator.clipboard.writeText(`/apply-comments docs/${docId}`);
|
|
180
|
+
setCopied(true);
|
|
181
|
+
window.setTimeout(() => setCopied(false), 1600);
|
|
182
|
+
} catch {}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<PanelShell
|
|
187
|
+
label={t('Comments')}
|
|
188
|
+
header={
|
|
189
|
+
<>
|
|
190
|
+
<MessageSquare aria-hidden className="size-3.5 flex-none text-muted-foreground" />
|
|
191
|
+
<span className="truncate font-medium text-xs">{t('Comments')}</span>
|
|
192
|
+
{comments.length > 0 && (
|
|
193
|
+
<span className="rounded bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground tabular-nums">
|
|
194
|
+
{comments.length}
|
|
195
|
+
</span>
|
|
196
|
+
)}
|
|
197
|
+
</>
|
|
198
|
+
}
|
|
199
|
+
actions={
|
|
200
|
+
<>
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
aria-label={t('New comment')}
|
|
204
|
+
title={t('New comment')}
|
|
205
|
+
aria-pressed={picking}
|
|
206
|
+
onClick={onNew}
|
|
207
|
+
className="flex size-8 items-center justify-center rounded text-foreground/70 transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-foreground/60 aria-pressed:bg-accent aria-pressed:text-foreground"
|
|
208
|
+
>
|
|
209
|
+
<MessageSquarePlus className="size-3.5" />
|
|
210
|
+
</button>
|
|
211
|
+
<PanelIconButton label={t('Close')} onClick={onClose}>
|
|
212
|
+
<X className="size-3.5" />
|
|
213
|
+
</PanelIconButton>
|
|
214
|
+
</>
|
|
215
|
+
}
|
|
216
|
+
banner={
|
|
217
|
+
picking ? (
|
|
218
|
+
<div className="border-border border-b px-3 py-2">
|
|
219
|
+
<PickButton picking onClick={onNew} />
|
|
220
|
+
</div>
|
|
221
|
+
) : (
|
|
222
|
+
comments.length > 0 && (
|
|
223
|
+
<div className="border-border border-b px-3 py-2">
|
|
224
|
+
<button
|
|
225
|
+
type="button"
|
|
226
|
+
onClick={copy}
|
|
227
|
+
title="/apply-comments"
|
|
228
|
+
className="flex h-8 w-full items-center justify-center gap-1.5 rounded border border-border text-xs transition-colors hover:bg-accent focus-visible:outline-2 focus-visible:outline-foreground/60"
|
|
229
|
+
>
|
|
230
|
+
{copied ? (
|
|
231
|
+
<Check className="size-3.5" style={{ color: 'var(--change-added)' }} />
|
|
232
|
+
) : (
|
|
233
|
+
<ClipboardCopy className="size-3.5" />
|
|
234
|
+
)}
|
|
235
|
+
{copied ? t('Copied') : t('Copy request for the agent')}
|
|
236
|
+
</button>
|
|
237
|
+
</div>
|
|
238
|
+
)
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
>
|
|
242
|
+
{state.status === 'loading' ? (
|
|
243
|
+
<div className="m-3 h-0.5 overflow-hidden rounded bg-muted">
|
|
244
|
+
<div className="h-full w-1/3 animate-pulse bg-foreground/20" />
|
|
245
|
+
</div>
|
|
246
|
+
) : state.status === 'error' ? (
|
|
247
|
+
<p className="px-6 py-12 text-center text-muted-foreground text-xs">{state.error}</p>
|
|
248
|
+
) : comments.length === 0 ? (
|
|
249
|
+
<div className="flex flex-col items-center gap-3 px-6 py-12 text-center text-muted-foreground text-xs">
|
|
250
|
+
<MessageSquare className="size-5" />
|
|
251
|
+
{t('No comments')}
|
|
252
|
+
{!picking && <PickButton picking={false} onClick={onNew} />}
|
|
253
|
+
</div>
|
|
254
|
+
) : (
|
|
255
|
+
<ul className="flex flex-col p-2">
|
|
256
|
+
{comments.map((comment, at) => (
|
|
257
|
+
<Card
|
|
258
|
+
key={comment.id}
|
|
259
|
+
comment={comment}
|
|
260
|
+
n={at + 1}
|
|
261
|
+
page={placement.get(comment.id)?.[0]}
|
|
262
|
+
excerpt={excerpts.get(comment.id) ?? ''}
|
|
263
|
+
active={comment.id === activeId}
|
|
264
|
+
onSelect={() => onSelect(comment)}
|
|
265
|
+
onResolve={() => onResolve(comment)}
|
|
266
|
+
/>
|
|
267
|
+
))}
|
|
268
|
+
</ul>
|
|
269
|
+
)}
|
|
270
|
+
</PanelShell>
|
|
271
|
+
);
|
|
272
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { DocComment } from '../../../editing/comments';
|
|
3
|
+
|
|
4
|
+
export type { DocComment };
|
|
5
|
+
|
|
6
|
+
export type CommentsState =
|
|
7
|
+
| { status: 'loading' }
|
|
8
|
+
| { status: 'error'; error: string }
|
|
9
|
+
| { status: 'ready'; comments: DocComment[] };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The document's pending comments, oldest first — the order the agent works
|
|
13
|
+
* through them. Read again on every reload, so a note the agent applied and
|
|
14
|
+
* removed leaves the list on its own.
|
|
15
|
+
*/
|
|
16
|
+
export function useComments(docId: string | undefined, reloadKey: unknown, enabled: boolean) {
|
|
17
|
+
const [state, setState] = useState<CommentsState>({ status: 'loading' });
|
|
18
|
+
const request = useRef(0);
|
|
19
|
+
|
|
20
|
+
const load = useCallback(async () => {
|
|
21
|
+
if (!docId || !enabled) return;
|
|
22
|
+
const id = ++request.current;
|
|
23
|
+
try {
|
|
24
|
+
const res = await fetch(`/__comments?${new URLSearchParams({ docId })}`);
|
|
25
|
+
const body = (await res.json()) as { comments?: DocComment[]; error?: string };
|
|
26
|
+
if (id !== request.current) return;
|
|
27
|
+
setState(
|
|
28
|
+
res.ok
|
|
29
|
+
? {
|
|
30
|
+
status: 'ready',
|
|
31
|
+
comments: [...(body.comments ?? [])].sort((a, b) => a.ts.localeCompare(b.ts)),
|
|
32
|
+
}
|
|
33
|
+
: { status: 'error', error: body.error ?? '' },
|
|
34
|
+
);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
if (id === request.current) setState({ status: 'error', error: String(err) });
|
|
37
|
+
}
|
|
38
|
+
}, [docId, enabled]);
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
void reloadKey;
|
|
42
|
+
void load();
|
|
43
|
+
}, [load, reloadKey]);
|
|
44
|
+
|
|
45
|
+
/** Done with a note: its marker comes out of the source. */
|
|
46
|
+
const resolve = useCallback(
|
|
47
|
+
async (comment: DocComment): Promise<string | null> => {
|
|
48
|
+
if (!docId) return null;
|
|
49
|
+
const res = await fetch(`/__comments?${new URLSearchParams({ docId, id: comment.id })}`, {
|
|
50
|
+
method: 'DELETE',
|
|
51
|
+
});
|
|
52
|
+
void load();
|
|
53
|
+
if (res.ok) return null;
|
|
54
|
+
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
|
55
|
+
return body.error ?? 'Could not resolve the comment';
|
|
56
|
+
},
|
|
57
|
+
[docId, load],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return { state, resolve, reload: load };
|
|
61
|
+
}
|