@open-document/core 0.11.0 → 0.12.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-DfUfpeTR.js} +1 -1
- package/dist/{check-UEBmDfT_.js → check-CHxiOkQG.js} +3 -3
- package/dist/cli/bin.js +20 -33
- package/dist/{config-B_pdNbYg.js → config-9IdbhVuT.js} +1402 -675
- package/dist/{context-BM9_-u9P.js → context-BLI1-64_.js} +2 -2
- package/dist/{dev-DX3QMIRi.js → dev-yNYKv5mm.js} +1 -1
- package/dist/{diff-DayvbXfX.js → diff-Bs205mOx.js} +2 -2
- package/dist/{export-BPsXj1i6.js → export-tkquS5O5.js} +11 -4
- package/dist/{import-71wlAsrd.js → import-D1hIKIr3.js} +3 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +63 -28
- package/dist/ops/index.d.ts +111 -2
- package/dist/ops/index.js +3 -3
- package/dist/{ops-BUo67DaP.js → ops-Dgqujq5a.js} +85 -164
- package/dist/package-version-C89gtYSk.js +36 -0
- package/dist/{preview-D3m1-gUL.js → preview-BImdTH6K.js} +1 -1
- package/dist/{sdk-CpDEGRIo.d.ts → sdk-CHEGeINh.d.ts} +46 -1
- package/dist/templates-DT5zzqHq.js +34 -0
- package/dist/vite/index.js +1 -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 +2 -0
- 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/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/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/doc-sidebar.tsx +32 -2
- package/src/app/components/inspector/field-source.tsx +41 -0
- package/src/app/components/inspector/inspector.tsx +64 -65
- package/src/app/components/overlay-frame.tsx +79 -0
- package/src/app/components/page-frame.tsx +4 -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/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 +2 -1
- package/src/app/lib/export-html.ts +4 -2
- package/src/app/lib/export-image.ts +2 -1
- package/src/app/lib/flow-measure.test.ts +30 -0
- package/src/app/lib/flow-measure.ts +35 -10
- 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/records.test.ts +38 -0
- package/src/app/lib/records.ts +127 -0
- package/src/app/lib/sdk.ts +29 -0
- package/src/app/lib/use-doc-module.ts +7 -0
- package/src/app/lib/use-doc-pages.ts +15 -9
- package/src/app/routes/doc.tsx +274 -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
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { ChangesResult, Revision } from '../../../ops/changes';
|
|
3
|
+
import type { FileChange, Hunk } from '../../../ops/changes-diff';
|
|
4
|
+
|
|
5
|
+
export type { FileChange, Hunk, Revision };
|
|
6
|
+
|
|
7
|
+
export type ChangesState =
|
|
8
|
+
| { status: 'loading' }
|
|
9
|
+
| { status: 'error'; error: string }
|
|
10
|
+
| { status: 'ready'; result: ChangesResult };
|
|
11
|
+
|
|
12
|
+
/** Every hunk, flattened, with the file it belongs to. */
|
|
13
|
+
export type ChangeItem = { file: FileChange; hunk: Hunk };
|
|
14
|
+
|
|
15
|
+
export function itemsOf(state: ChangesState): ChangeItem[] {
|
|
16
|
+
if (state.status !== 'ready' || !state.result.available) return [];
|
|
17
|
+
return state.result.files.flatMap((file) => file.hunks.map((hunk) => ({ file, hunk })));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The document's changes since a revision, read again whenever the document
|
|
22
|
+
* reloads — an agent writing the file, a revert, a save — so the marks follow
|
|
23
|
+
* the source without anyone asking.
|
|
24
|
+
*/
|
|
25
|
+
export function useChanges(docId: string | undefined, reloadKey: unknown, enabled: boolean) {
|
|
26
|
+
const [since, setSince] = useState('HEAD');
|
|
27
|
+
const [state, setState] = useState<ChangesState>({ status: 'loading' });
|
|
28
|
+
const [revisions, setRevisions] = useState<Revision[]>([]);
|
|
29
|
+
const request = useRef(0);
|
|
30
|
+
|
|
31
|
+
const load = useCallback(async () => {
|
|
32
|
+
if (!docId || !enabled) return;
|
|
33
|
+
const id = ++request.current;
|
|
34
|
+
try {
|
|
35
|
+
const params = new URLSearchParams({ docId, since });
|
|
36
|
+
const res = await fetch(`/__changes?${params}`);
|
|
37
|
+
const body = (await res.json()) as ChangesResult & { error?: string };
|
|
38
|
+
if (id !== request.current) return;
|
|
39
|
+
setState(
|
|
40
|
+
res.ok ? { status: 'ready', result: body } : { status: 'error', error: body.error ?? '' },
|
|
41
|
+
);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
if (id === request.current) setState({ status: 'error', error: String(err) });
|
|
44
|
+
}
|
|
45
|
+
}, [docId, since, enabled]);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
void reloadKey;
|
|
49
|
+
void load();
|
|
50
|
+
}, [load, reloadKey]);
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
void reloadKey;
|
|
54
|
+
if (!docId || !enabled) return;
|
|
55
|
+
let cancelled = false;
|
|
56
|
+
fetch(`/__changes/revisions?${new URLSearchParams({ docId })}`)
|
|
57
|
+
.then((res) => res.json())
|
|
58
|
+
.then((body: { revisions?: Revision[] }) => {
|
|
59
|
+
if (!cancelled) setRevisions(body.revisions ?? []);
|
|
60
|
+
})
|
|
61
|
+
.catch(() => {});
|
|
62
|
+
return () => {
|
|
63
|
+
cancelled = true;
|
|
64
|
+
};
|
|
65
|
+
}, [docId, enabled, reloadKey]);
|
|
66
|
+
|
|
67
|
+
const revert = useCallback(
|
|
68
|
+
async (item: ChangeItem): Promise<string | null> => {
|
|
69
|
+
if (!docId) return null;
|
|
70
|
+
const res = await fetch('/__changes/revert', {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: { 'content-type': 'application/json' },
|
|
73
|
+
body: JSON.stringify({ docId, since, file: item.file.path, hunk: item.hunk.id }),
|
|
74
|
+
});
|
|
75
|
+
const body = (await res.json()) as { error?: string };
|
|
76
|
+
// The write reloads the document, which reads the changes again; a
|
|
77
|
+
// revert outside the document's own source reloads nothing, so ask.
|
|
78
|
+
void load();
|
|
79
|
+
return res.ok ? null : (body.error ?? 'revert failed');
|
|
80
|
+
},
|
|
81
|
+
[docId, since, load],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return { since, setSince, state, revisions, revert, reload: load };
|
|
85
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -17,11 +17,17 @@ type Props = {
|
|
|
17
17
|
pages: ExpandedPage[];
|
|
18
18
|
geometry: PageGeometry;
|
|
19
19
|
design?: DesignSystem;
|
|
20
|
+
/** The document's language, for the thumbnails — see `pageLang`. */
|
|
21
|
+
lang?: string;
|
|
20
22
|
currentPage: number;
|
|
21
23
|
entries: OutlineEntry[];
|
|
22
24
|
activeId: string | null;
|
|
23
25
|
onSelectPage: (page: number) => void;
|
|
24
26
|
onSelectEntry: (entry: OutlineEntry) => void;
|
|
27
|
+
/** Pages carrying a change since the compared revision, while the changes panel is open. */
|
|
28
|
+
changedPages?: ReadonlySet<number>;
|
|
29
|
+
/** Pages carrying a review comment, while the comments panel is open. */
|
|
30
|
+
commentPages?: ReadonlySet<number>;
|
|
25
31
|
};
|
|
26
32
|
|
|
27
33
|
export function DocSidebar({
|
|
@@ -29,11 +35,14 @@ export function DocSidebar({
|
|
|
29
35
|
pages,
|
|
30
36
|
geometry,
|
|
31
37
|
design,
|
|
38
|
+
lang,
|
|
32
39
|
currentPage,
|
|
33
40
|
entries,
|
|
34
41
|
activeId,
|
|
35
42
|
onSelectPage,
|
|
36
43
|
onSelectEntry,
|
|
44
|
+
changedPages,
|
|
45
|
+
commentPages,
|
|
37
46
|
}: Props) {
|
|
38
47
|
const t = useT();
|
|
39
48
|
const [tab, setTab] = useState<Tab>('pages');
|
|
@@ -91,7 +100,13 @@ export function DocSidebar({
|
|
|
91
100
|
type="button"
|
|
92
101
|
data-thumb-page={page}
|
|
93
102
|
onClick={() => onSelectPage(page)}
|
|
94
|
-
aria-label={
|
|
103
|
+
aria-label={
|
|
104
|
+
changedPages?.has(page)
|
|
105
|
+
? t('Page {page}, changed', { page })
|
|
106
|
+
: commentPages?.has(page)
|
|
107
|
+
? t('Page {page}, with comments', { page })
|
|
108
|
+
: t('Page {page}', { page })
|
|
109
|
+
}
|
|
95
110
|
aria-current={page === currentPage ? 'page' : undefined}
|
|
96
111
|
className={cn(
|
|
97
112
|
'group flex w-full items-start gap-2 rounded-md p-1.5 transition-colors',
|
|
@@ -100,11 +115,25 @@ export function DocSidebar({
|
|
|
100
115
|
>
|
|
101
116
|
<span
|
|
102
117
|
className={cn(
|
|
103
|
-
'w-5 flex-none pt-0.5
|
|
118
|
+
'flex w-5 flex-none flex-col items-end gap-1 pt-0.5 font-mono text-[10px] tabular-nums',
|
|
104
119
|
page === currentPage ? 'text-foreground' : 'text-muted-foreground',
|
|
105
120
|
)}
|
|
106
121
|
>
|
|
107
122
|
{String(page).padStart(2, '0')}
|
|
123
|
+
{changedPages?.has(page) && (
|
|
124
|
+
<span
|
|
125
|
+
aria-hidden
|
|
126
|
+
className="size-1.5 rounded-full"
|
|
127
|
+
style={{ background: 'var(--change-changed)' }}
|
|
128
|
+
/>
|
|
129
|
+
)}
|
|
130
|
+
{commentPages?.has(page) && (
|
|
131
|
+
<span
|
|
132
|
+
aria-hidden
|
|
133
|
+
className="size-1.5 rounded-full"
|
|
134
|
+
style={{ background: 'var(--comment-pin)' }}
|
|
135
|
+
/>
|
|
136
|
+
)}
|
|
108
137
|
</span>
|
|
109
138
|
<div
|
|
110
139
|
className={cn(
|
|
@@ -124,6 +153,7 @@ export function DocSidebar({
|
|
|
124
153
|
geometry={geometry}
|
|
125
154
|
scale={THUMB_WIDTH / geometry.width}
|
|
126
155
|
design={design}
|
|
156
|
+
lang={lang}
|
|
127
157
|
flat
|
|
128
158
|
>
|
|
129
159
|
{entry.content}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Table2 } from 'lucide-react';
|
|
2
|
+
import { Fragment } from 'react';
|
|
3
|
+
import { useT } from '../../lib/i18n';
|
|
4
|
+
import { getRecordState, useRecordCount, useRecordIndex } from '../../lib/records';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where a value printed by `<Field>` comes from: the data file, the row shown,
|
|
8
|
+
* and each column with what it holds for that row — the cell to edit to
|
|
9
|
+
* change it, since the page prints the same source line for every row.
|
|
10
|
+
*/
|
|
11
|
+
export function FieldSource({ names, file }: { names: string[]; file: string | null }) {
|
|
12
|
+
const t = useT();
|
|
13
|
+
const index = useRecordIndex();
|
|
14
|
+
const count = useRecordCount();
|
|
15
|
+
const row = getRecordState().records[index];
|
|
16
|
+
return (
|
|
17
|
+
<div className="rounded border border-border text-xs">
|
|
18
|
+
<div className="flex min-w-0 items-center gap-1.5 border-border border-b px-2 py-1.5 text-muted-foreground">
|
|
19
|
+
<Table2 aria-hidden className="size-3.5 flex-none" />
|
|
20
|
+
<code className="min-w-0 flex-1 truncate font-mono text-[11px] text-foreground">
|
|
21
|
+
{file ? file.replace(/^\.\//, '') : t('Records')}
|
|
22
|
+
</code>
|
|
23
|
+
{count > 0 && (
|
|
24
|
+
<span className="flex-none font-mono text-[10px] tabular-nums">
|
|
25
|
+
{t('Row {row} of {count}', { row: index + 1, count })}
|
|
26
|
+
</span>
|
|
27
|
+
)}
|
|
28
|
+
</div>
|
|
29
|
+
<dl className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 px-2 py-1.5">
|
|
30
|
+
{names.map((name) => (
|
|
31
|
+
<Fragment key={name}>
|
|
32
|
+
<dt className="font-mono text-[11px] text-muted-foreground">{name}</dt>
|
|
33
|
+
<dd className="m-0 truncate">
|
|
34
|
+
{row?.[name] === undefined || row[name] === '' ? '—' : String(row[name])}
|
|
35
|
+
</dd>
|
|
36
|
+
</Fragment>
|
|
37
|
+
))}
|
|
38
|
+
</dl>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|