@open-document/core 0.10.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-DJMLK50m.js → build-DfUfpeTR.js} +1 -1
- package/dist/{check-CUKuufBm.js → check-CHxiOkQG.js} +3 -3
- package/dist/cli/bin.js +20 -33
- package/dist/{config-CvzpyAUA.js → config-9IdbhVuT.js} +2015 -725
- package/dist/{context-B4ip7SoI.js → context-BLI1-64_.js} +2 -2
- package/dist/{dev-dnH7DTlD.js → dev-yNYKv5mm.js} +1 -1
- package/dist/{diff-QTo0A5Rx.js → diff-Bs205mOx.js} +2 -2
- package/dist/{export-BrRFrexj.js → export-tkquS5O5.js} +11 -4
- package/dist/{import-C14Vn9ER.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-DKidjLXP.js → ops-Dgqujq5a.js} +85 -164
- package/dist/package-version-C89gtYSk.js +36 -0
- package/dist/{preview-wKM4C6Uk.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/format-section.tsx +434 -0
- package/src/app/components/inspector/inspector.tsx +311 -118
- package/src/app/components/inspector/use-style-edits.ts +210 -0
- 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/panel/fields.tsx +95 -7
- 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 +92 -5
- 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 +90 -5
- 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 +88 -5
- 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 +88 -5
- package/src/app/lib/inspector/format.ts +156 -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 -11
- 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
|
@@ -4,7 +4,8 @@ import type { DesignSystem } from './design';
|
|
|
4
4
|
import { type DocEntry, type FlowSection, isFlowSection, paginateBlocks } from './flow';
|
|
5
5
|
import { type MeasurableSection, measureFlowSections } from './flow-measure';
|
|
6
6
|
import { extractSectionFootnotes, notesForPage, type PreparedSection } from './footnotes';
|
|
7
|
-
import
|
|
7
|
+
import { useRecordIndex } from './records';
|
|
8
|
+
import { type DocModule, type PageGeometry, pageLang } from './sdk';
|
|
8
9
|
|
|
9
10
|
export type ExpandedPage = {
|
|
10
11
|
key: string;
|
|
@@ -20,9 +21,10 @@ type Plan = {
|
|
|
20
21
|
const EMPTY_PLAN: Plan = { bySection: [], overflowing: [] };
|
|
21
22
|
|
|
22
23
|
/** A plan is only current for the sections it was measured from. */
|
|
23
|
-
|
|
24
|
+
/** What was measured: these sections, printed for this record. */
|
|
25
|
+
type Measured = { plan: Plan; sections: FlowSection[] | null; record: number };
|
|
24
26
|
|
|
25
|
-
const NOT_MEASURED: Measured = { plan: EMPTY_PLAN, sections: null };
|
|
27
|
+
const NOT_MEASURED: Measured = { plan: EMPTY_PLAN, sections: null, record: -1 };
|
|
26
28
|
|
|
27
29
|
function entriesOf(doc: DocModule | null): DocEntry[] {
|
|
28
30
|
return (doc?.default ?? []) as DocEntry[];
|
|
@@ -40,6 +42,10 @@ export function useDocPages(
|
|
|
40
42
|
const entries = useMemo(() => entriesOf(doc), [doc]);
|
|
41
43
|
const sections = useMemo(() => entries.filter(isFlowSection), [entries]);
|
|
42
44
|
const design = doc?.design as DesignSystem | undefined;
|
|
45
|
+
const lang = pageLang(doc?.meta);
|
|
46
|
+
// A row's own words wrap differently from the last one's, so a new record
|
|
47
|
+
// is a new measurement — the same reason a new document is.
|
|
48
|
+
const record = useRecordIndex();
|
|
43
49
|
|
|
44
50
|
// Footnotes come out of the blocks before anything is measured: what they
|
|
45
51
|
// cost at the foot of a page is part of that page's budget.
|
|
@@ -62,15 +68,15 @@ export function useDocPages(
|
|
|
62
68
|
// one commit after the document loads, and anything reading the page list in
|
|
63
69
|
// that window — the outline scan, the headless bridge — sees a whole flow
|
|
64
70
|
// section as one unpaginated page.
|
|
65
|
-
const measuring = sections.length > 0 && state.sections !== sections;
|
|
71
|
+
const measuring = sections.length > 0 && (state.sections !== sections || state.record !== record);
|
|
66
72
|
|
|
67
73
|
useEffect(() => {
|
|
68
74
|
if (sections.length === 0) {
|
|
69
|
-
setState({ plan: EMPTY_PLAN, sections });
|
|
75
|
+
setState({ plan: EMPTY_PLAN, sections, record });
|
|
70
76
|
return;
|
|
71
77
|
}
|
|
72
78
|
let cancelled = false;
|
|
73
|
-
measureFlowSections(measurable, { geometry, design })
|
|
79
|
+
measureFlowSections(measurable, { geometry, design, lang })
|
|
74
80
|
.then((measurements) => {
|
|
75
81
|
if (cancelled) return;
|
|
76
82
|
const bySection: number[][][] = [];
|
|
@@ -84,15 +90,15 @@ export function useDocPages(
|
|
|
84
90
|
overflowing.push({ section: sectionIndex, block });
|
|
85
91
|
}
|
|
86
92
|
});
|
|
87
|
-
setState({ plan: { bySection, overflowing }, sections });
|
|
93
|
+
setState({ plan: { bySection, overflowing }, sections, record });
|
|
88
94
|
})
|
|
89
95
|
.catch(() => {
|
|
90
|
-
if (!cancelled) setState({ plan: EMPTY_PLAN, sections });
|
|
96
|
+
if (!cancelled) setState({ plan: EMPTY_PLAN, sections, record });
|
|
91
97
|
});
|
|
92
98
|
return () => {
|
|
93
99
|
cancelled = true;
|
|
94
100
|
};
|
|
95
|
-
}, [sections, measurable, geometry, design]);
|
|
101
|
+
}, [sections, measurable, geometry, design, lang, record]);
|
|
96
102
|
|
|
97
103
|
const plan = state.plan;
|
|
98
104
|
|
package/src/app/routes/doc.tsx
CHANGED
|
@@ -11,12 +11,14 @@ import {
|
|
|
11
11
|
FileImage,
|
|
12
12
|
FileText,
|
|
13
13
|
FileType2,
|
|
14
|
+
GitCompare,
|
|
14
15
|
Hash,
|
|
15
16
|
Image,
|
|
16
17
|
LayoutGrid,
|
|
17
18
|
Link2,
|
|
18
19
|
Loader2,
|
|
19
20
|
Maximize,
|
|
21
|
+
MessageSquare,
|
|
20
22
|
Minimize,
|
|
21
23
|
Minus,
|
|
22
24
|
MoveHorizontal,
|
|
@@ -29,7 +31,13 @@ import {
|
|
|
29
31
|
import { useTheme } from 'next-themes';
|
|
30
32
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
31
33
|
import { Link, useNavigate, useParams } from 'react-router-dom';
|
|
34
|
+
import { ChangesOverlay, elementsOf } from '../components/changes/changes-overlay';
|
|
35
|
+
import { ChangesPanel } from '../components/changes/changes-panel';
|
|
36
|
+
import { type ChangeItem, itemsOf, useChanges } from '../components/changes/use-changes';
|
|
32
37
|
import { CommandPaletteProvider, type PaletteItem } from '../components/command-palette';
|
|
38
|
+
import { CommentsOverlay } from '../components/comments/comments-overlay';
|
|
39
|
+
import { CommentsPanel } from '../components/comments/comments-panel';
|
|
40
|
+
import { type DocComment, useComments } from '../components/comments/use-comments';
|
|
33
41
|
import { DesignPanel } from '../components/design-panel/design-panel';
|
|
34
42
|
import { DesignProvider } from '../components/design-panel/design-provider';
|
|
35
43
|
import { DocSearch } from '../components/doc-search';
|
|
@@ -37,8 +45,10 @@ import { DocSidebar } from '../components/doc-sidebar';
|
|
|
37
45
|
import { HistoryProvider } from '../components/history-provider';
|
|
38
46
|
import { Inspector, type InspectorControls } from '../components/inspector/inspector';
|
|
39
47
|
import { PageFrame } from '../components/page-frame';
|
|
48
|
+
import { elementsAtLoc, usePlacement } from '../components/page-placement';
|
|
40
49
|
import { browserItems } from '../components/palette-items';
|
|
41
50
|
import { EditSaveCard } from '../components/panel/edit-save-card';
|
|
51
|
+
import { RecordPicker } from '../components/record-picker';
|
|
42
52
|
import { ThemeToggle } from '../components/theme-toggle';
|
|
43
53
|
import { Menu, MenuItem } from '../components/ui/menu';
|
|
44
54
|
import { useAgentBridge } from '../lib/agent-bridge';
|
|
@@ -55,8 +65,9 @@ import {
|
|
|
55
65
|
resolveSelection,
|
|
56
66
|
} from '../lib/page-range';
|
|
57
67
|
import { nextFrame, waitForFonts } from '../lib/print-ready';
|
|
68
|
+
import { getRecordState, setRecords, useRecordIndex } from '../lib/records';
|
|
58
69
|
import { scanDocument } from '../lib/scan';
|
|
59
|
-
import { resolvePageGeometry } from '../lib/sdk';
|
|
70
|
+
import { pageLang, resolvePageGeometry } from '../lib/sdk';
|
|
60
71
|
import { useDocModule } from '../lib/use-doc-module';
|
|
61
72
|
import { useDocPages } from '../lib/use-doc-pages';
|
|
62
73
|
import { cn } from '../lib/utils';
|
|
@@ -203,7 +214,18 @@ export function Doc() {
|
|
|
203
214
|
const [downloaded, setDownloaded] = useState<DownloadFormat | null>(null);
|
|
204
215
|
const [selection, setSelection] = useState<PageSelection>({ kind: 'all' });
|
|
205
216
|
const [customRange, setCustomRange] = useState('');
|
|
206
|
-
|
|
217
|
+
// One dock on the right, one panel in it at a time; the element panel takes
|
|
218
|
+
// it back whenever an element is picked.
|
|
219
|
+
const [dock, setDock] = useState<'design' | 'changes' | 'comments' | null>(null);
|
|
220
|
+
const designOpen = dock === 'design';
|
|
221
|
+
const changesOpen = dock === 'changes';
|
|
222
|
+
const commentsOpen = dock === 'comments';
|
|
223
|
+
const toggleDock = useCallback(
|
|
224
|
+
(panel: 'design' | 'changes' | 'comments') =>
|
|
225
|
+
setDock((open) => (open === panel ? null : panel)),
|
|
226
|
+
[],
|
|
227
|
+
);
|
|
228
|
+
const closeDock = useCallback(() => setDock(null), []);
|
|
207
229
|
const [editing, setEditingState] = useState(readEditing);
|
|
208
230
|
// The dev server reloads every open viewer when a document is added or
|
|
209
231
|
// removed anywhere in the workspace. Edit mode is per tab and survives that.
|
|
@@ -226,10 +248,99 @@ export function Doc() {
|
|
|
226
248
|
const jumpedRef = useRef<number | null>(null);
|
|
227
249
|
|
|
228
250
|
const geometry = useMemo(() => resolvePageGeometry(doc?.meta), [doc?.meta]);
|
|
251
|
+
// The rows this document prints for. Set before the pages measure, and kept
|
|
252
|
+
// on the same row across a reload — an edit should not jump the preview
|
|
253
|
+
// back to the first one. `?record=` opens on a given row.
|
|
254
|
+
useLayoutEffect(() => {
|
|
255
|
+
const fromUrl = Number(new URLSearchParams(window.location.search).get('record'));
|
|
256
|
+
const keep = getRecordState().records.length > 0 ? getRecordState().index : fromUrl - 1;
|
|
257
|
+
setRecords(doc?.records, Number.isFinite(keep) ? keep : 0);
|
|
258
|
+
}, [doc]);
|
|
259
|
+
useEffect(() => () => setRecords(undefined), []);
|
|
260
|
+
|
|
229
261
|
const { pages, measuring, overflowing } = useDocPages(doc, geometry);
|
|
262
|
+
const recordIndex = useRecordIndex();
|
|
263
|
+
|
|
264
|
+
// Read again on every reload of the document, so what an agent just wrote
|
|
265
|
+
// shows up in the count and on the page without being asked for.
|
|
266
|
+
const changes = useChanges(docId, doc, import.meta.env.DEV);
|
|
267
|
+
const changeItems = useMemo(() => itemsOf(changes.state), [changes.state]);
|
|
268
|
+
const changeTargets = useMemo(
|
|
269
|
+
() =>
|
|
270
|
+
changeItems.map((item) => ({
|
|
271
|
+
id: item.hunk.id,
|
|
272
|
+
locs: item.hunk.targets.map((target) => target.loc),
|
|
273
|
+
})),
|
|
274
|
+
[changeItems],
|
|
275
|
+
);
|
|
276
|
+
const placement = usePlacement(changesOpen ? scrollRef.current : null, changeTargets);
|
|
277
|
+
const changedPages = useMemo(() => new Set([...placement.values()].flat()), [placement]);
|
|
278
|
+
|
|
279
|
+
const comments = useComments(docId, doc, import.meta.env.DEV);
|
|
280
|
+
const commentList = useMemo(
|
|
281
|
+
() => (comments.state.status === 'ready' ? comments.state.comments : []),
|
|
282
|
+
[comments.state],
|
|
283
|
+
);
|
|
284
|
+
const commentTargets = useMemo(
|
|
285
|
+
() =>
|
|
286
|
+
commentList.map((comment) => ({ id: comment.id, locs: comment.loc ? [comment.loc] : [] })),
|
|
287
|
+
[commentList],
|
|
288
|
+
);
|
|
289
|
+
const commentPlacement = usePlacement(commentsOpen ? scrollRef.current : null, commentTargets);
|
|
290
|
+
const commentPages = useMemo(
|
|
291
|
+
() => new Set([...commentPlacement.values()].flat()),
|
|
292
|
+
[commentPlacement],
|
|
293
|
+
);
|
|
294
|
+
const [activeComment, setActiveComment] = useState<string | null>(null);
|
|
295
|
+
const selectComment = useCallback((comment: DocComment) => {
|
|
296
|
+
setActiveComment(comment.id);
|
|
297
|
+
const container = scrollRef.current;
|
|
298
|
+
const first = container && comment.loc ? elementsAtLoc(container, comment.loc)[0] : undefined;
|
|
299
|
+
first?.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
300
|
+
}, []);
|
|
301
|
+
// "New comment" is a picking state: the panel stays, the page waits for an
|
|
302
|
+
// element, and the element panel then opens on the note, focused. Pressing
|
|
303
|
+
// it again, or Esc, cancels.
|
|
304
|
+
const [commentFirst, setCommentFirst] = useState(false);
|
|
305
|
+
const [picking, setPicking] = useState(false);
|
|
306
|
+
const startComment = useCallback(() => {
|
|
307
|
+
if (picking) {
|
|
308
|
+
setPicking(false);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
setCommentFirst(true);
|
|
312
|
+
setPicking(true);
|
|
313
|
+
setEditing(true);
|
|
314
|
+
}, [picking, setEditing]);
|
|
315
|
+
const pickElement = useCallback(() => {
|
|
316
|
+
setDock(null);
|
|
317
|
+
setPicking(false);
|
|
318
|
+
}, []);
|
|
319
|
+
const cancelPick = useCallback(() => setPicking(false), []);
|
|
320
|
+
useEffect(() => {
|
|
321
|
+
if (!editing) {
|
|
322
|
+
setCommentFirst(false);
|
|
323
|
+
setPicking(false);
|
|
324
|
+
}
|
|
325
|
+
}, [editing]);
|
|
326
|
+
const [activeChange, setActiveChange] = useState<string | null>(null);
|
|
327
|
+
const selectChange = useCallback((item: ChangeItem) => {
|
|
328
|
+
setActiveChange(item.hunk.id);
|
|
329
|
+
const container = scrollRef.current;
|
|
330
|
+
const first = container ? elementsOf(container, item)[0]?.el : undefined;
|
|
331
|
+
first?.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
332
|
+
}, []);
|
|
230
333
|
const outline = useDocOutline();
|
|
231
334
|
|
|
232
|
-
useAgentBridge({
|
|
335
|
+
useAgentBridge({
|
|
336
|
+
docId: docId ?? '',
|
|
337
|
+
doc,
|
|
338
|
+
pages,
|
|
339
|
+
geometry,
|
|
340
|
+
measuring,
|
|
341
|
+
oversized: overflowing,
|
|
342
|
+
record: recordIndex,
|
|
343
|
+
});
|
|
233
344
|
|
|
234
345
|
const clamp = (value: number) => Math.max(MIN_SCALE, Math.min(MAX_SCALE, value));
|
|
235
346
|
// Every fit is of the unit the mode lays side by side — a sheet, a spread,
|
|
@@ -537,7 +648,27 @@ export function Doc() {
|
|
|
537
648
|
hint: 'D',
|
|
538
649
|
keywords: 'design colours fonts',
|
|
539
650
|
icon: Palette,
|
|
540
|
-
run: () =>
|
|
651
|
+
run: () => toggleDock('design'),
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
id: 'changes',
|
|
655
|
+
group: t('Actions'),
|
|
656
|
+
label: changesOpen
|
|
657
|
+
? t('Close the changes panel')
|
|
658
|
+
: t('Show changes since the last commit'),
|
|
659
|
+
hint: 'C',
|
|
660
|
+
keywords: 'changes diff git review agent revert',
|
|
661
|
+
icon: GitCompare,
|
|
662
|
+
run: () => toggleDock('changes'),
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
id: 'comments',
|
|
666
|
+
group: t('Actions'),
|
|
667
|
+
label: commentsOpen ? t('Close the comments panel') : t('Show comments'),
|
|
668
|
+
hint: 'M',
|
|
669
|
+
keywords: 'comments review notes agent',
|
|
670
|
+
icon: MessageSquare,
|
|
671
|
+
run: () => toggleDock('comments'),
|
|
541
672
|
},
|
|
542
673
|
);
|
|
543
674
|
}
|
|
@@ -557,14 +688,16 @@ export function Doc() {
|
|
|
557
688
|
// page" from node_modules/.open-doc/current.json. See vite/current-plugin.ts.
|
|
558
689
|
useEffect(() => {
|
|
559
690
|
if (!import.meta.hot) return;
|
|
560
|
-
|
|
691
|
+
// Not while the flow sections are still being measured: the page count
|
|
692
|
+
// then is the unpaginated one, and an agent reading it would act on it.
|
|
693
|
+
if (!docId || !doc || pages.length === 0 || measuring) return;
|
|
561
694
|
import.meta.hot.send('open-doc:current', {
|
|
562
695
|
docId,
|
|
563
696
|
pageIndex: currentPage - 1,
|
|
564
697
|
totalPages: pages.length,
|
|
565
698
|
docTitle: doc.meta?.title ?? docId,
|
|
566
699
|
});
|
|
567
|
-
}, [docId, doc, currentPage, pages.length]);
|
|
700
|
+
}, [docId, doc, currentPage, pages.length, measuring]);
|
|
568
701
|
|
|
569
702
|
useEffect(() => {
|
|
570
703
|
const onKeyDown = (e: KeyboardEvent) => {
|
|
@@ -576,12 +709,18 @@ export function Doc() {
|
|
|
576
709
|
toggleFullscreen();
|
|
577
710
|
} else if (import.meta.env.DEV && (e.key === 'd' || e.key === 'D')) {
|
|
578
711
|
e.preventDefault();
|
|
579
|
-
|
|
712
|
+
toggleDock('design');
|
|
713
|
+
} else if (import.meta.env.DEV && (e.key === 'c' || e.key === 'C')) {
|
|
714
|
+
e.preventDefault();
|
|
715
|
+
toggleDock('changes');
|
|
716
|
+
} else if (import.meta.env.DEV && (e.key === 'm' || e.key === 'M')) {
|
|
717
|
+
e.preventDefault();
|
|
718
|
+
toggleDock('comments');
|
|
580
719
|
}
|
|
581
720
|
};
|
|
582
721
|
window.addEventListener('keydown', onKeyDown);
|
|
583
722
|
return () => window.removeEventListener('keydown', onKeyDown);
|
|
584
|
-
}, [toggleFullscreen]);
|
|
723
|
+
}, [toggleFullscreen, toggleDock]);
|
|
585
724
|
|
|
586
725
|
if (state.status === 'error') {
|
|
587
726
|
return (
|
|
@@ -622,6 +761,9 @@ export function Doc() {
|
|
|
622
761
|
<div className="flex min-w-0 items-center gap-1">
|
|
623
762
|
<HeaderBackLink />
|
|
624
763
|
<h1 className="truncate font-medium text-sm">{doc.meta?.title ?? docId}</h1>
|
|
764
|
+
{doc.records && doc.records.length > 0 && (
|
|
765
|
+
<RecordPicker records={doc.records} labelKey={doc.meta?.recordLabel} />
|
|
766
|
+
)}
|
|
625
767
|
</div>
|
|
626
768
|
|
|
627
769
|
<div className="hidden items-center gap-2 sm:flex">
|
|
@@ -696,7 +838,7 @@ export function Doc() {
|
|
|
696
838
|
aria-label={t('Design')}
|
|
697
839
|
aria-keyshortcuts="D"
|
|
698
840
|
title={t('Design tokens (D)')}
|
|
699
|
-
onClick={() =>
|
|
841
|
+
onClick={() => toggleDock('design')}
|
|
700
842
|
className={cn(
|
|
701
843
|
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
702
844
|
designOpen && 'bg-accent',
|
|
@@ -712,6 +854,66 @@ export function Doc() {
|
|
|
712
854
|
</kbd>
|
|
713
855
|
</button>
|
|
714
856
|
)}
|
|
857
|
+
{import.meta.env.DEV && (
|
|
858
|
+
<button
|
|
859
|
+
type="button"
|
|
860
|
+
aria-pressed={changesOpen}
|
|
861
|
+
aria-label={
|
|
862
|
+
changeItems.length > 0
|
|
863
|
+
? t('Changes ({count})', { count: changeItems.length })
|
|
864
|
+
: t('Changes')
|
|
865
|
+
}
|
|
866
|
+
aria-keyshortcuts="C"
|
|
867
|
+
title={`${t('Changes since the last commit')} (C)`}
|
|
868
|
+
onClick={() => toggleDock('changes')}
|
|
869
|
+
className={cn(
|
|
870
|
+
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
871
|
+
changesOpen && 'bg-accent',
|
|
872
|
+
)}
|
|
873
|
+
>
|
|
874
|
+
<GitCompare className="size-3.5" />
|
|
875
|
+
<span className="hidden lg:inline">{t('Changes')}</span>
|
|
876
|
+
{changeItems.length > 0 && (
|
|
877
|
+
<span
|
|
878
|
+
aria-hidden
|
|
879
|
+
className="min-w-4 rounded-full px-1 text-center font-mono text-[10px] text-background tabular-nums"
|
|
880
|
+
style={{ background: 'var(--change-changed)' }}
|
|
881
|
+
>
|
|
882
|
+
{changeItems.length}
|
|
883
|
+
</span>
|
|
884
|
+
)}
|
|
885
|
+
</button>
|
|
886
|
+
)}
|
|
887
|
+
{import.meta.env.DEV && (
|
|
888
|
+
<button
|
|
889
|
+
type="button"
|
|
890
|
+
aria-pressed={commentsOpen}
|
|
891
|
+
aria-label={
|
|
892
|
+
commentList.length > 0
|
|
893
|
+
? t('Comments ({count})', { count: commentList.length })
|
|
894
|
+
: t('Comments')
|
|
895
|
+
}
|
|
896
|
+
aria-keyshortcuts="M"
|
|
897
|
+
title={`${t('Comments')} (M)`}
|
|
898
|
+
onClick={() => toggleDock('comments')}
|
|
899
|
+
className={cn(
|
|
900
|
+
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
901
|
+
commentsOpen && 'bg-accent',
|
|
902
|
+
)}
|
|
903
|
+
>
|
|
904
|
+
<MessageSquare className="size-3.5" />
|
|
905
|
+
<span className="hidden lg:inline">{t('Comments')}</span>
|
|
906
|
+
{commentList.length > 0 && (
|
|
907
|
+
<span
|
|
908
|
+
aria-hidden
|
|
909
|
+
className="min-w-4 rounded-full px-1 text-center font-mono text-[10px] text-white tabular-nums"
|
|
910
|
+
style={{ background: 'var(--comment-pin)' }}
|
|
911
|
+
>
|
|
912
|
+
{commentList.length}
|
|
913
|
+
</span>
|
|
914
|
+
)}
|
|
915
|
+
</button>
|
|
916
|
+
)}
|
|
715
917
|
|
|
716
918
|
<CopyLink />
|
|
717
919
|
|
|
@@ -793,11 +995,14 @@ export function Doc() {
|
|
|
793
995
|
pages={pages}
|
|
794
996
|
geometry={geometry}
|
|
795
997
|
design={doc.design}
|
|
998
|
+
lang={pageLang(doc.meta)}
|
|
796
999
|
currentPage={currentPage}
|
|
797
1000
|
entries={outline}
|
|
798
1001
|
activeId={activeOutlineId}
|
|
799
1002
|
onSelectPage={scrollToPage}
|
|
800
1003
|
onSelectEntry={scrollToEntry}
|
|
1004
|
+
{...(changesOpen ? { changedPages } : {})}
|
|
1005
|
+
{...(commentsOpen ? { commentPages } : {})}
|
|
801
1006
|
/>
|
|
802
1007
|
<div className="relative flex min-w-0 flex-1">
|
|
803
1008
|
<div
|
|
@@ -835,12 +1040,27 @@ export function Doc() {
|
|
|
835
1040
|
geometry={geometry}
|
|
836
1041
|
scale={scale}
|
|
837
1042
|
design={doc.design}
|
|
1043
|
+
lang={pageLang(doc.meta)}
|
|
838
1044
|
>
|
|
839
1045
|
{page.content}
|
|
840
1046
|
</PageFrame>
|
|
841
1047
|
))}
|
|
842
1048
|
</div>
|
|
843
1049
|
</div>
|
|
1050
|
+
{commentsOpen && scrollRef.current && (
|
|
1051
|
+
<CommentsOverlay
|
|
1052
|
+
container={scrollRef.current}
|
|
1053
|
+
comments={commentList}
|
|
1054
|
+
activeId={activeComment}
|
|
1055
|
+
/>
|
|
1056
|
+
)}
|
|
1057
|
+
{changesOpen && scrollRef.current && (
|
|
1058
|
+
<ChangesOverlay
|
|
1059
|
+
container={scrollRef.current}
|
|
1060
|
+
items={changeItems}
|
|
1061
|
+
activeId={activeChange}
|
|
1062
|
+
/>
|
|
1063
|
+
)}
|
|
844
1064
|
{import.meta.env.DEV && docId && (
|
|
845
1065
|
<EditSaveCard
|
|
846
1066
|
textCount={textPending}
|
|
@@ -857,7 +1077,11 @@ export function Doc() {
|
|
|
857
1077
|
key={docId}
|
|
858
1078
|
docId={docId}
|
|
859
1079
|
containerRef={scrollRef}
|
|
860
|
-
panelHidden={
|
|
1080
|
+
panelHidden={dock !== null}
|
|
1081
|
+
onPick={pickElement}
|
|
1082
|
+
commentFirst={commentFirst}
|
|
1083
|
+
picking={picking}
|
|
1084
|
+
onCancelPick={cancelPick}
|
|
861
1085
|
quiet={cardShown}
|
|
862
1086
|
onExit={() => setEditing(false)}
|
|
863
1087
|
exitRef={leaveEditRef}
|
|
@@ -865,7 +1089,46 @@ export function Doc() {
|
|
|
865
1089
|
onPendingChange={setTextPending}
|
|
866
1090
|
/>
|
|
867
1091
|
)}
|
|
868
|
-
{designOpen && <DesignPanel onClose={
|
|
1092
|
+
{designOpen && <DesignPanel onClose={closeDock} />}
|
|
1093
|
+
{commentsOpen && docId && (
|
|
1094
|
+
<CommentsPanel
|
|
1095
|
+
docId={docId}
|
|
1096
|
+
state={comments.state}
|
|
1097
|
+
placement={commentPlacement}
|
|
1098
|
+
excerpts={
|
|
1099
|
+
new Map(
|
|
1100
|
+
commentList.map((comment) => {
|
|
1101
|
+
const el =
|
|
1102
|
+
scrollRef.current && comment.loc
|
|
1103
|
+
? elementsAtLoc(scrollRef.current, comment.loc)[0]
|
|
1104
|
+
: undefined;
|
|
1105
|
+
const text = (el?.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
1106
|
+
return [comment.id, text.length > 90 ? `${text.slice(0, 89)}…` : text];
|
|
1107
|
+
}),
|
|
1108
|
+
)
|
|
1109
|
+
}
|
|
1110
|
+
activeId={activeComment}
|
|
1111
|
+
onSelect={selectComment}
|
|
1112
|
+
onResolve={comments.resolve}
|
|
1113
|
+
onNew={startComment}
|
|
1114
|
+
picking={picking}
|
|
1115
|
+
onClose={closeDock}
|
|
1116
|
+
/>
|
|
1117
|
+
)}
|
|
1118
|
+
{changesOpen && (
|
|
1119
|
+
<ChangesPanel
|
|
1120
|
+
state={changes.state}
|
|
1121
|
+
items={changeItems}
|
|
1122
|
+
placement={placement}
|
|
1123
|
+
since={changes.since}
|
|
1124
|
+
revisions={changes.revisions}
|
|
1125
|
+
activeId={activeChange}
|
|
1126
|
+
onSince={changes.setSince}
|
|
1127
|
+
onSelect={selectChange}
|
|
1128
|
+
onRevert={changes.revert}
|
|
1129
|
+
onClose={closeDock}
|
|
1130
|
+
/>
|
|
1131
|
+
)}
|
|
869
1132
|
</div>
|
|
870
1133
|
</div>
|
|
871
1134
|
</CommandPaletteProvider>
|
package/src/app/routes/home.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
MoreHorizontal,
|
|
13
13
|
Palette,
|
|
14
14
|
PencilLine,
|
|
15
|
+
Plus,
|
|
15
16
|
Search,
|
|
16
17
|
Trash2,
|
|
17
18
|
} from 'lucide-react';
|
|
@@ -21,9 +22,11 @@ import {
|
|
|
21
22
|
CARD_GRID,
|
|
22
23
|
CardText,
|
|
23
24
|
EmptyState,
|
|
25
|
+
fitInCard,
|
|
24
26
|
PageHeader,
|
|
25
27
|
useCardWidth,
|
|
26
28
|
} from '../components/browser/browser-ui';
|
|
29
|
+
import { NewDocumentDialog } from '../components/browser/new-document-dialog';
|
|
27
30
|
import { PageFrame } from '../components/page-frame';
|
|
28
31
|
import { DOC_DND_MIME } from '../components/sidebar/folder-item';
|
|
29
32
|
import { ALL_DOCS_ID, DRAFT_ID } from '../components/sidebar/sidebar';
|
|
@@ -31,7 +34,7 @@ import { Menu, MenuItem, MenuSeparator } from '../components/ui/menu';
|
|
|
31
34
|
import { coverContent } from '../lib/doc-preview';
|
|
32
35
|
import { docCreatedAt, docIds, docThemes, docTitles } from '../lib/docs';
|
|
33
36
|
import { type Translate, useLocale, useT } from '../lib/i18n';
|
|
34
|
-
import { resolvePageGeometry } from '../lib/sdk';
|
|
37
|
+
import { pageLang, resolvePageGeometry } from '../lib/sdk';
|
|
35
38
|
import { findTheme } from '../lib/themes';
|
|
36
39
|
import { useDocModule } from '../lib/use-doc-module';
|
|
37
40
|
import type { HomeOutletContext } from './home-shell';
|
|
@@ -92,6 +95,19 @@ export function Home() {
|
|
|
92
95
|
const [error, setError] = useState<string | null>(null);
|
|
93
96
|
const [sort, setSortState] = useState<SortKey>(readSort);
|
|
94
97
|
const [filter, setFilter] = useState('');
|
|
98
|
+
const [creating, setCreating] = useState(false);
|
|
99
|
+
const inFolder =
|
|
100
|
+
ctx.selectedId !== ALL_DOCS_ID && ctx.selectedId !== DRAFT_ID ? ctx.selectedId : null;
|
|
101
|
+
const newButton = import.meta.env.DEV && (
|
|
102
|
+
<button
|
|
103
|
+
type="button"
|
|
104
|
+
onClick={() => setCreating(true)}
|
|
105
|
+
className="flex h-8 items-center gap-1.5 rounded-md bg-primary px-2.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-foreground/60"
|
|
106
|
+
>
|
|
107
|
+
<Plus className="size-3.5" />
|
|
108
|
+
{t('New document')}
|
|
109
|
+
</button>
|
|
110
|
+
);
|
|
95
111
|
|
|
96
112
|
const setSort = (next: SortKey) => {
|
|
97
113
|
setSortState(next);
|
|
@@ -134,7 +150,7 @@ export function Home() {
|
|
|
134
150
|
}
|
|
135
151
|
count={sourceIds.length}
|
|
136
152
|
actions={
|
|
137
|
-
sourceIds.length > 0
|
|
153
|
+
sourceIds.length > 0 ? (
|
|
138
154
|
<>
|
|
139
155
|
<Menu
|
|
140
156
|
placement="bottom-end"
|
|
@@ -179,7 +195,10 @@ export function Home() {
|
|
|
179
195
|
className="min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground"
|
|
180
196
|
/>
|
|
181
197
|
</label>
|
|
198
|
+
{newButton}
|
|
182
199
|
</>
|
|
200
|
+
) : (
|
|
201
|
+
newButton
|
|
183
202
|
)
|
|
184
203
|
}
|
|
185
204
|
>
|
|
@@ -202,6 +221,7 @@ export function Home() {
|
|
|
202
221
|
{ctx.selectedId === ALL_DOCS_ID
|
|
203
222
|
? t('Ask your agent to write a document, and it appears here.')
|
|
204
223
|
: t('Drag a document onto this folder, or use Move to on its card.')}
|
|
224
|
+
{newButton && <div className="mt-4 flex justify-center">{newButton}</div>}
|
|
205
225
|
</EmptyState>
|
|
206
226
|
) : (
|
|
207
227
|
<div className={CARD_GRID}>
|
|
@@ -210,6 +230,9 @@ export function Home() {
|
|
|
210
230
|
))}
|
|
211
231
|
</div>
|
|
212
232
|
)}
|
|
233
|
+
{import.meta.env.DEV && (
|
|
234
|
+
<NewDocumentDialog open={creating} folderId={inFolder} onClose={() => setCreating(false)} />
|
|
235
|
+
)}
|
|
213
236
|
</div>
|
|
214
237
|
);
|
|
215
238
|
}
|
|
@@ -230,7 +253,7 @@ function DocCard({
|
|
|
230
253
|
const state = useDocModule(docId);
|
|
231
254
|
const doc = state.doc;
|
|
232
255
|
const geometry = resolvePageGeometry(doc?.meta);
|
|
233
|
-
const scale = cardWidth
|
|
256
|
+
const { frameHeight, scale } = fitInCard(cardWidth, geometry);
|
|
234
257
|
const cover = coverContent(doc);
|
|
235
258
|
const theme = findTheme(docThemes[docId]);
|
|
236
259
|
const title = doc?.meta?.title ?? docId;
|
|
@@ -259,8 +282,9 @@ function DocCard({
|
|
|
259
282
|
>
|
|
260
283
|
<Link to={`/d/${docId}`}>
|
|
261
284
|
<div
|
|
262
|
-
|
|
263
|
-
|
|
285
|
+
data-od-card-frame
|
|
286
|
+
className="flex items-center justify-center overflow-hidden rounded-md bg-canvas ring-1 ring-border transition-shadow group-hover:shadow-lg"
|
|
287
|
+
style={{ width: cardWidth, height: frameHeight }}
|
|
264
288
|
>
|
|
265
289
|
{cover ? (
|
|
266
290
|
<PageFrame
|
|
@@ -269,6 +293,7 @@ function DocCard({
|
|
|
269
293
|
geometry={geometry}
|
|
270
294
|
scale={scale}
|
|
271
295
|
design={doc?.design}
|
|
296
|
+
lang={pageLang(doc?.meta)}
|
|
272
297
|
flat
|
|
273
298
|
>
|
|
274
299
|
{cover}
|
package/src/app/styles.css
CHANGED
|
@@ -35,6 +35,13 @@
|
|
|
35
35
|
--primary: oklch(0.185 0 0);
|
|
36
36
|
--primary-foreground: oklch(0.985 0 0);
|
|
37
37
|
--border: oklch(0.9 0 0);
|
|
38
|
+
/* Changes since a revision: added, rewritten, taken out. They mark the
|
|
39
|
+
paper as well as the chrome, so they stay readable on white either way. */
|
|
40
|
+
--change-added: oklch(0.58 0.15 150);
|
|
41
|
+
--change-changed: oklch(0.68 0.15 70);
|
|
42
|
+
--change-removed: oklch(0.58 0.2 25);
|
|
43
|
+
/* A reviewer's note pinned to the page. */
|
|
44
|
+
--comment-pin: oklch(0.55 0.19 265);
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
.dark {
|
|
@@ -49,6 +56,10 @@
|
|
|
49
56
|
--primary: oklch(0.97 0 0);
|
|
50
57
|
--primary-foreground: oklch(0.16 0 0);
|
|
51
58
|
--border: oklch(0.28 0 0);
|
|
59
|
+
--change-added: oklch(0.7 0.15 150);
|
|
60
|
+
--change-changed: oklch(0.78 0.14 75);
|
|
61
|
+
--change-removed: oklch(0.68 0.19 25);
|
|
62
|
+
--comment-pin: oklch(0.68 0.16 265);
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
/* The dock's content arrives from the edge it docks against. Opacity only
|
|
@@ -123,6 +134,18 @@
|
|
|
123
134
|
font-size: var(--od-size-body, 14px);
|
|
124
135
|
line-height: var(--od-leading, 1.55);
|
|
125
136
|
color: var(--od-text, #16181d);
|
|
137
|
+
/* Chinese, Japanese and Korean set as they are meant to be: no closing
|
|
138
|
+
* punctuation or small kana at the start of a line (kinsoku), and an
|
|
139
|
+
* eighth of an em between a CJK character and a Latin letter or digit
|
|
140
|
+
* where the author left no space. Both do nothing to text in other
|
|
141
|
+
* scripts. They need the sheet's `lang` (meta.lang) to pick the right
|
|
142
|
+
* rules and glyphs. */
|
|
143
|
+
line-break: strict;
|
|
144
|
+
text-autospace: normal;
|
|
145
|
+
}
|
|
146
|
+
/* Japanese headings break between phrases, not inside a word. */
|
|
147
|
+
:is([data-od-page], [data-od-measure]) :where(h1, h2, h3, h4, h5, h6):lang(ja) {
|
|
148
|
+
word-break: auto-phrase;
|
|
126
149
|
}
|
|
127
150
|
:is([data-od-page], [data-od-measure]) :where(h1, h2, h3, h4, h5, h6) {
|
|
128
151
|
font-family: var(
|