@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.
Files changed (82) hide show
  1. package/dist/{build-BHFGY8eF.js → build-DfUfpeTR.js} +1 -1
  2. package/dist/{check-UEBmDfT_.js → check-CHxiOkQG.js} +3 -3
  3. package/dist/cli/bin.js +20 -33
  4. package/dist/{config-B_pdNbYg.js → config-9IdbhVuT.js} +1402 -675
  5. package/dist/{context-BM9_-u9P.js → context-BLI1-64_.js} +2 -2
  6. package/dist/{dev-DX3QMIRi.js → dev-yNYKv5mm.js} +1 -1
  7. package/dist/{diff-DayvbXfX.js → diff-Bs205mOx.js} +2 -2
  8. package/dist/{export-BPsXj1i6.js → export-tkquS5O5.js} +11 -4
  9. package/dist/{import-71wlAsrd.js → import-D1hIKIr3.js} +3 -2
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.js +63 -28
  12. package/dist/ops/index.d.ts +111 -2
  13. package/dist/ops/index.js +3 -3
  14. package/dist/{ops-BUo67DaP.js → ops-Dgqujq5a.js} +85 -164
  15. package/dist/package-version-C89gtYSk.js +36 -0
  16. package/dist/{preview-D3m1-gUL.js → preview-BImdTH6K.js} +1 -1
  17. package/dist/{sdk-CpDEGRIo.d.ts → sdk-CHEGeINh.d.ts} +46 -1
  18. package/dist/templates-DT5zzqHq.js +34 -0
  19. package/dist/vite/index.js +1 -1
  20. package/package.json +2 -1
  21. package/skills/apply-comments/SKILL.md +3 -1
  22. package/skills/create-doc/SKILL.md +2 -0
  23. package/skills/doc-authoring/SKILL.md +2 -0
  24. package/src/app/components/browser/browser-ui.tsx +21 -0
  25. package/src/app/components/browser/new-document-dialog.tsx +208 -0
  26. package/src/app/components/changes/changes-overlay.tsx +68 -0
  27. package/src/app/components/changes/changes-panel.tsx +341 -0
  28. package/src/app/components/changes/use-changes.ts +85 -0
  29. package/src/app/components/comments/comments-overlay.tsx +50 -0
  30. package/src/app/components/comments/comments-panel.tsx +272 -0
  31. package/src/app/components/comments/use-comments.ts +61 -0
  32. package/src/app/components/doc-sidebar.tsx +32 -2
  33. package/src/app/components/inspector/field-source.tsx +41 -0
  34. package/src/app/components/inspector/inspector.tsx +64 -65
  35. package/src/app/components/overlay-frame.tsx +79 -0
  36. package/src/app/components/page-frame.tsx +4 -0
  37. package/src/app/components/page-placement.ts +68 -0
  38. package/src/app/components/record-picker.tsx +79 -0
  39. package/src/app/components/themes/theme-preview.tsx +5 -4
  40. package/src/app/lib/agent-bridge.ts +29 -1
  41. package/src/app/lib/docx/ooxml.test.ts +24 -1
  42. package/src/app/lib/docx/ooxml.ts +27 -1
  43. package/src/app/lib/export-docx.ts +3 -1
  44. package/src/app/lib/export-dom.ts +2 -1
  45. package/src/app/lib/export-html.ts +4 -2
  46. package/src/app/lib/export-image.ts +2 -1
  47. package/src/app/lib/flow-measure.test.ts +30 -0
  48. package/src/app/lib/flow-measure.ts +35 -10
  49. package/src/app/lib/i18n-ja/browser.ts +10 -0
  50. package/src/app/lib/i18n-ja/doc.ts +4 -0
  51. package/src/app/lib/i18n-ja/panels.ts +40 -0
  52. package/src/app/lib/i18n-ko/browser.ts +10 -0
  53. package/src/app/lib/i18n-ko/doc.ts +4 -0
  54. package/src/app/lib/i18n-ko/panels.ts +39 -0
  55. package/src/app/lib/i18n-zh-cn/browser.ts +10 -0
  56. package/src/app/lib/i18n-zh-cn/doc.ts +4 -0
  57. package/src/app/lib/i18n-zh-cn/panels.ts +38 -0
  58. package/src/app/lib/i18n-zh-tw/browser.ts +10 -0
  59. package/src/app/lib/i18n-zh-tw/doc.ts +4 -0
  60. package/src/app/lib/i18n-zh-tw/panels.ts +38 -0
  61. package/src/app/lib/records.test.ts +38 -0
  62. package/src/app/lib/records.ts +127 -0
  63. package/src/app/lib/sdk.ts +29 -0
  64. package/src/app/lib/use-doc-module.ts +7 -0
  65. package/src/app/lib/use-doc-pages.ts +15 -9
  66. package/src/app/routes/doc.tsx +274 -13
  67. package/src/app/routes/home.tsx +30 -5
  68. package/src/app/styles.css +23 -0
  69. package/templates/blank/index.tsx +63 -0
  70. package/templates/blank/template.json +6 -0
  71. package/templates/certificate/data/recipients.csv +4 -0
  72. package/templates/certificate/index.tsx +128 -0
  73. package/templates/certificate/template.json +6 -0
  74. package/templates/letter/index.tsx +106 -0
  75. package/templates/letter/template.json +5 -0
  76. package/templates/meeting-notes/index.tsx +194 -0
  77. package/templates/meeting-notes/template.json +6 -0
  78. package/templates/proposal/index.tsx +264 -0
  79. package/templates/proposal/template.json +6 -0
  80. package/templates/report/data/metrics.csv +5 -0
  81. package/templates/report/index.tsx +224 -0
  82. package/templates/report/template.json +6 -0
@@ -1,6 +1,7 @@
1
1
  import type { ComponentType, ReactNode } from 'react';
2
2
  import type { DesignSystem } from './design.ts';
3
3
  import type { LabelVocabulary } from './labels.ts';
4
+ import type { DataRecord } from './records.ts';
4
5
 
5
6
  /** The only sheets a document may be laid out on. */
6
7
  export const PAGE_SIZE_NAMES = ['A4', 'B4', 'A3'] as const;
@@ -86,8 +87,31 @@ export type DocMeta = {
86
87
  createdAt?: string;
87
88
  /** What numbered items are called — `圖`/`表` instead of `Figure`/`Table`. */
88
89
  labels?: Partial<LabelVocabulary>;
90
+ /**
91
+ * The language the document is written in, as a BCP 47 tag — `zh-Hant-TW`,
92
+ * `ja`, `ko`, `en-GB`. It decides glyph shapes for shared Han characters,
93
+ * which line-breaking rules apply, and the language an exported file
94
+ * declares. English when unset.
95
+ */
96
+ lang?: string;
97
+ /**
98
+ * With `records`: the file name for each row's copy — `{column}` takes the
99
+ * row's value, `{#}` its number. `<id>-{#}` when unset.
100
+ */
101
+ recordName?: string;
102
+ /** With `records`: the column that names a row in the viewer's picker. */
103
+ recordLabel?: string;
89
104
  };
90
105
 
106
+ /**
107
+ * The `lang` every sheet carries. Always set, never inherited: a sheet that
108
+ * took its language from the viewer would break lines and pick glyphs by the
109
+ * reader's interface language, and print differently for each reader.
110
+ */
111
+ export function pageLang(meta?: DocMeta): string {
112
+ return meta?.lang?.trim() || 'en';
113
+ }
114
+
91
115
  export type FolderIcon = { type: 'emoji'; value: string } | { type: 'color'; value: string };
92
116
 
93
117
  export type Folder = {
@@ -105,6 +129,11 @@ export type DocModule = {
105
129
  default: DocEntry[];
106
130
  meta?: DocMeta;
107
131
  design?: DesignSystem;
132
+ /**
133
+ * Rows to print the document for, one copy each — usually an imported
134
+ * `.csv`. Pages read the current row with `useRecord()` or `<Field>`.
135
+ */
136
+ records?: DataRecord[];
108
137
  };
109
138
 
110
139
  export function resolvePageGeometry(meta?: DocMeta): PageGeometry {
@@ -15,6 +15,7 @@ export function useDocModule(docId: string | undefined): DocState {
15
15
  useEffect(() => {
16
16
  if (!docId) return;
17
17
  let cancelled = false;
18
+ let rescanned = false;
18
19
 
19
20
  const read = () => {
20
21
  loadDoc(docId)
@@ -23,6 +24,12 @@ export function useDocModule(docId: string | undefined): DocState {
23
24
  })
24
25
  .catch((err: unknown) => {
25
26
  if (cancelled) return;
27
+ // A document created a moment ago may not be in the list yet; the
28
+ // dev server rescans and reloads the page if it is on disk.
29
+ if (import.meta.env.DEV && !rescanned) {
30
+ rescanned = true;
31
+ void fetch('/__docs-rescan').catch(() => {});
32
+ }
26
33
  setState({
27
34
  status: 'error',
28
35
  doc: null,
@@ -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 type { DocModule, PageGeometry } from './sdk';
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
- type Measured = { plan: Plan; sections: FlowSection[] | null };
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
 
@@ -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,8 +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
- const [designOpen, setDesignOpen] = useState(false);
207
- const closeDesign = useCallback(() => setDesignOpen(false), []);
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), []);
208
229
  const [editing, setEditingState] = useState(readEditing);
209
230
  // The dev server reloads every open viewer when a document is added or
210
231
  // removed anywhere in the workspace. Edit mode is per tab and survives that.
@@ -227,10 +248,99 @@ export function Doc() {
227
248
  const jumpedRef = useRef<number | null>(null);
228
249
 
229
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
+
230
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
+ }, []);
231
333
  const outline = useDocOutline();
232
334
 
233
- useAgentBridge({ docId: docId ?? '', doc, pages, geometry, measuring, oversized: overflowing });
335
+ useAgentBridge({
336
+ docId: docId ?? '',
337
+ doc,
338
+ pages,
339
+ geometry,
340
+ measuring,
341
+ oversized: overflowing,
342
+ record: recordIndex,
343
+ });
234
344
 
235
345
  const clamp = (value: number) => Math.max(MIN_SCALE, Math.min(MAX_SCALE, value));
236
346
  // Every fit is of the unit the mode lays side by side — a sheet, a spread,
@@ -538,7 +648,27 @@ export function Doc() {
538
648
  hint: 'D',
539
649
  keywords: 'design colours fonts',
540
650
  icon: Palette,
541
- run: () => setDesignOpen((open) => !open),
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'),
542
672
  },
543
673
  );
544
674
  }
@@ -558,14 +688,16 @@ export function Doc() {
558
688
  // page" from node_modules/.open-doc/current.json. See vite/current-plugin.ts.
559
689
  useEffect(() => {
560
690
  if (!import.meta.hot) return;
561
- if (!docId || !doc || pages.length === 0) return;
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;
562
694
  import.meta.hot.send('open-doc:current', {
563
695
  docId,
564
696
  pageIndex: currentPage - 1,
565
697
  totalPages: pages.length,
566
698
  docTitle: doc.meta?.title ?? docId,
567
699
  });
568
- }, [docId, doc, currentPage, pages.length]);
700
+ }, [docId, doc, currentPage, pages.length, measuring]);
569
701
 
570
702
  useEffect(() => {
571
703
  const onKeyDown = (e: KeyboardEvent) => {
@@ -577,12 +709,18 @@ export function Doc() {
577
709
  toggleFullscreen();
578
710
  } else if (import.meta.env.DEV && (e.key === 'd' || e.key === 'D')) {
579
711
  e.preventDefault();
580
- setDesignOpen((open) => !open);
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');
581
719
  }
582
720
  };
583
721
  window.addEventListener('keydown', onKeyDown);
584
722
  return () => window.removeEventListener('keydown', onKeyDown);
585
- }, [toggleFullscreen]);
723
+ }, [toggleFullscreen, toggleDock]);
586
724
 
587
725
  if (state.status === 'error') {
588
726
  return (
@@ -623,6 +761,9 @@ export function Doc() {
623
761
  <div className="flex min-w-0 items-center gap-1">
624
762
  <HeaderBackLink />
625
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
+ )}
626
767
  </div>
627
768
 
628
769
  <div className="hidden items-center gap-2 sm:flex">
@@ -697,7 +838,7 @@ export function Doc() {
697
838
  aria-label={t('Design')}
698
839
  aria-keyshortcuts="D"
699
840
  title={t('Design tokens (D)')}
700
- onClick={() => setDesignOpen((open) => !open)}
841
+ onClick={() => toggleDock('design')}
701
842
  className={cn(
702
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',
703
844
  designOpen && 'bg-accent',
@@ -713,6 +854,66 @@ export function Doc() {
713
854
  </kbd>
714
855
  </button>
715
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
+ )}
716
917
 
717
918
  <CopyLink />
718
919
 
@@ -794,11 +995,14 @@ export function Doc() {
794
995
  pages={pages}
795
996
  geometry={geometry}
796
997
  design={doc.design}
998
+ lang={pageLang(doc.meta)}
797
999
  currentPage={currentPage}
798
1000
  entries={outline}
799
1001
  activeId={activeOutlineId}
800
1002
  onSelectPage={scrollToPage}
801
1003
  onSelectEntry={scrollToEntry}
1004
+ {...(changesOpen ? { changedPages } : {})}
1005
+ {...(commentsOpen ? { commentPages } : {})}
802
1006
  />
803
1007
  <div className="relative flex min-w-0 flex-1">
804
1008
  <div
@@ -836,12 +1040,27 @@ export function Doc() {
836
1040
  geometry={geometry}
837
1041
  scale={scale}
838
1042
  design={doc.design}
1043
+ lang={pageLang(doc.meta)}
839
1044
  >
840
1045
  {page.content}
841
1046
  </PageFrame>
842
1047
  ))}
843
1048
  </div>
844
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
+ )}
845
1064
  {import.meta.env.DEV && docId && (
846
1065
  <EditSaveCard
847
1066
  textCount={textPending}
@@ -858,8 +1077,11 @@ export function Doc() {
858
1077
  key={docId}
859
1078
  docId={docId}
860
1079
  containerRef={scrollRef}
861
- panelHidden={designOpen}
862
- onPick={closeDesign}
1080
+ panelHidden={dock !== null}
1081
+ onPick={pickElement}
1082
+ commentFirst={commentFirst}
1083
+ picking={picking}
1084
+ onCancelPick={cancelPick}
863
1085
  quiet={cardShown}
864
1086
  onExit={() => setEditing(false)}
865
1087
  exitRef={leaveEditRef}
@@ -867,7 +1089,46 @@ export function Doc() {
867
1089
  onPendingChange={setTextPending}
868
1090
  />
869
1091
  )}
870
- {designOpen && <DesignPanel onClose={() => setDesignOpen(false)} />}
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
+ )}
871
1132
  </div>
872
1133
  </div>
873
1134
  </CommandPaletteProvider>
@@ -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 / geometry.width;
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
- className="overflow-hidden rounded-md ring-1 ring-border transition-shadow group-hover:shadow-lg"
263
- style={{ width: cardWidth, height: geometry.height * scale }}
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}