@open-document/core 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/{build-BHFGY8eF.js → build-CbgIk6bA.js} +1 -1
  2. package/dist/{check-UEBmDfT_.js → check-BTroj-5Z.js} +3 -3
  3. package/dist/cli/bin.js +58 -34
  4. package/dist/config-BWtOZ1jc.d.ts +45 -0
  5. package/dist/{config-B_pdNbYg.js → config-DKKNIbvO.js} +1458 -983
  6. package/dist/{context-BM9_-u9P.js → context-DXNP8v9I.js} +3 -2
  7. package/dist/deploy-gcp-BUiSuqz7.js +758 -0
  8. package/dist/{dev-DX3QMIRi.js → dev-YXumw5iX.js} +1 -1
  9. package/dist/{diagram-BK4jTZr4.js → diagram-CKf3ptOE.js} +293 -13
  10. package/dist/{diff-DayvbXfX.js → diff-CTFfU4Tz.js} +2 -2
  11. package/dist/{export-BPsXj1i6.js → export-D2QLtF84.js} +11 -4
  12. package/dist/flow-CS5apebG.d.ts +252 -0
  13. package/dist/{import-71wlAsrd.js → import-CcmrFetU.js} +3 -2
  14. package/dist/index.d.ts +155 -59
  15. package/dist/index.js +945 -104
  16. package/dist/open-doc-plugin-DnX5usgI.js +320 -0
  17. package/dist/ops/index.d.ts +112 -3
  18. package/dist/ops/index.js +3 -3
  19. package/dist/{ops-BUo67DaP.js → ops-DmEecq1k.js} +86 -164
  20. package/dist/package-version-C89gtYSk.js +36 -0
  21. package/dist/{preview-D3m1-gUL.js → preview-_mHpBhMk.js} +1 -1
  22. package/dist/templates-MMblHwmT.js +34 -0
  23. package/dist/vite/index.d.ts +1 -1
  24. package/dist/vite/index.js +2 -1
  25. package/package.json +2 -1
  26. package/skills/apply-comments/SKILL.md +3 -1
  27. package/skills/create-doc/SKILL.md +2 -0
  28. package/skills/doc-authoring/SKILL.md +17 -16
  29. package/skills/doc-authoring/references/long-form.md +43 -2
  30. package/skills/doc-authoring/references/pagination.md +14 -2
  31. package/skills/doc-authoring/references/tables-and-charts.md +21 -17
  32. package/src/app/components/browser/browser-ui.tsx +21 -0
  33. package/src/app/components/browser/new-document-dialog.tsx +208 -0
  34. package/src/app/components/callout.tsx +101 -0
  35. package/src/app/components/changes/changes-overlay.tsx +68 -0
  36. package/src/app/components/changes/changes-panel.tsx +341 -0
  37. package/src/app/components/changes/use-changes.ts +85 -0
  38. package/src/app/components/chart.tsx +191 -33
  39. package/src/app/components/code-block.tsx +249 -0
  40. package/src/app/components/comments/comments-overlay.tsx +50 -0
  41. package/src/app/components/comments/comments-panel.tsx +272 -0
  42. package/src/app/components/comments/use-comments.ts +61 -0
  43. package/src/app/components/data-table.tsx +146 -18
  44. package/src/app/components/doc-sidebar.tsx +32 -2
  45. package/src/app/components/flow-page.tsx +57 -8
  46. package/src/app/components/inspector/field-source.tsx +41 -0
  47. package/src/app/components/inspector/inspector.tsx +64 -65
  48. package/src/app/components/numbering.tsx +226 -12
  49. package/src/app/components/overlay-frame.tsx +79 -0
  50. package/src/app/components/page-frame.tsx +46 -0
  51. package/src/app/components/page-placement.ts +68 -0
  52. package/src/app/components/record-picker.tsx +79 -0
  53. package/src/app/components/themes/theme-preview.tsx +5 -4
  54. package/src/app/lib/agent-bridge.ts +29 -1
  55. package/src/app/lib/chart.test.ts +15 -0
  56. package/src/app/lib/chart.ts +134 -9
  57. package/src/app/lib/diagnostics.ts +45 -1
  58. package/src/app/lib/docx/ooxml.test.ts +24 -1
  59. package/src/app/lib/docx/ooxml.ts +27 -1
  60. package/src/app/lib/export-docx.ts +3 -1
  61. package/src/app/lib/export-dom.ts +17 -3
  62. package/src/app/lib/export-html.ts +4 -2
  63. package/src/app/lib/export-image.ts +2 -1
  64. package/src/app/lib/export-pdf.ts +9 -1
  65. package/src/app/lib/flow-measure.test.ts +30 -0
  66. package/src/app/lib/flow-measure.ts +68 -14
  67. package/src/app/lib/flow.test.ts +20 -1
  68. package/src/app/lib/flow.ts +120 -20
  69. package/src/app/lib/i18n-ja/browser.ts +10 -0
  70. package/src/app/lib/i18n-ja/doc.ts +4 -0
  71. package/src/app/lib/i18n-ja/panels.ts +40 -0
  72. package/src/app/lib/i18n-ko/browser.ts +10 -0
  73. package/src/app/lib/i18n-ko/doc.ts +4 -0
  74. package/src/app/lib/i18n-ko/panels.ts +39 -0
  75. package/src/app/lib/i18n-zh-cn/browser.ts +10 -0
  76. package/src/app/lib/i18n-zh-cn/doc.ts +4 -0
  77. package/src/app/lib/i18n-zh-cn/panels.ts +38 -0
  78. package/src/app/lib/i18n-zh-tw/browser.ts +10 -0
  79. package/src/app/lib/i18n-zh-tw/doc.ts +4 -0
  80. package/src/app/lib/i18n-zh-tw/panels.ts +38 -0
  81. package/src/app/lib/labels.ts +29 -10
  82. package/src/app/lib/records.test.ts +38 -0
  83. package/src/app/lib/records.ts +127 -0
  84. package/src/app/lib/sdk.ts +35 -0
  85. package/src/app/lib/use-doc-module.ts +7 -0
  86. package/src/app/lib/use-doc-pages.ts +38 -17
  87. package/src/app/routes/doc.tsx +275 -13
  88. package/src/app/routes/home.tsx +30 -5
  89. package/src/app/styles.css +23 -0
  90. package/templates/blank/index.tsx +63 -0
  91. package/templates/blank/template.json +6 -0
  92. package/templates/certificate/data/recipients.csv +4 -0
  93. package/templates/certificate/index.tsx +128 -0
  94. package/templates/certificate/template.json +6 -0
  95. package/templates/letter/index.tsx +106 -0
  96. package/templates/letter/template.json +5 -0
  97. package/templates/meeting-notes/index.tsx +194 -0
  98. package/templates/meeting-notes/template.json +6 -0
  99. package/templates/proposal/index.tsx +264 -0
  100. package/templates/proposal/template.json +6 -0
  101. package/templates/report/data/metrics.csv +5 -0
  102. package/templates/report/index.tsx +224 -0
  103. package/templates/report/template.json +6 -0
  104. package/dist/config-P61niZMf.d.ts +0 -24
  105. package/dist/sdk-CpDEGRIo.d.ts +0 -138
@@ -1,5 +1,6 @@
1
1
  import type { CSSProperties, ReactNode } from 'react';
2
2
  import { LOC_PROP, sourceAttrs } from '../lib/source-loc';
3
+ import { useTableSlice } from './flow-page';
3
4
  import { Figure } from './numbering';
4
5
 
5
6
  export type DataAlign = 'left' | 'center' | 'right';
@@ -9,8 +10,18 @@ export type DataFormat =
9
10
  | 'number'
10
11
  | 'integer'
11
12
  | 'percent'
13
+ | 'currency'
14
+ | 'delta'
12
15
  | ((value: unknown, row: Record<string, unknown>) => ReactNode);
13
16
 
17
+ export type DataSummaryOp =
18
+ | 'sum'
19
+ | 'avg'
20
+ | 'min'
21
+ | 'max'
22
+ | 'count'
23
+ | ((values: number[]) => ReactNode);
24
+
14
25
  export type DataColumn = {
15
26
  key: string;
16
27
  label?: ReactNode;
@@ -18,6 +29,10 @@ export type DataColumn = {
18
29
  format?: DataFormat;
19
30
  /** Column width. A number is px; `tableLayout: fixed` means these are honoured. */
20
31
  width?: number | string;
32
+ /** Draws a proportional horizontal bar behind numeric cells in this column. */
33
+ dataBar?: boolean;
34
+ /** Aggregation for this column when `summaryRow` is enabled on the table. */
35
+ summary?: DataSummaryOp | ReactNode;
21
36
  };
22
37
 
23
38
  export type DataTableProps = {
@@ -33,6 +48,12 @@ export type DataTableProps = {
33
48
  limit?: number;
34
49
  /** Tighter rows, for a dense appendix table. */
35
50
  compact?: boolean;
51
+ /** Allows `flow()` to split this table across pages and repeat the `<thead>` on each sheet. */
52
+ splittable?: boolean;
53
+ /** Appends a summary footer row. Pass `true` to use column `summary` ops, or a record of values/ops. */
54
+ summaryRow?: boolean | Record<string, DataSummaryOp | ReactNode>;
55
+ /** Label printed in the first column of the summary row when not overridden. Defaults to 'Total'. */
56
+ summaryLabel?: ReactNode;
36
57
  /** What an empty cell prints as. Defaults to an em dash. */
37
58
  emptyValue?: ReactNode;
38
59
  style?: CSSProperties;
@@ -74,6 +95,14 @@ function formatValue(
74
95
  if (format === 'integer') return Math.round(value).toLocaleString();
75
96
  if (format === 'percent')
76
97
  return `${(value * 100).toLocaleString(undefined, { maximumFractionDigits: 1 })}%`;
98
+ if (format === 'currency')
99
+ return `$${value.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}`;
100
+ if (format === 'delta') {
101
+ const sign = value > 0 ? '+' : '';
102
+ const text = `${sign}${value.toLocaleString(undefined, { maximumFractionDigits: 2 })}`;
103
+ const color = value > 0 ? '#15803d' : value < 0 ? '#b91c1c' : 'var(--od-muted)';
104
+ return <span style={{ color, fontWeight: 500 }}>{text}</span>;
105
+ }
77
106
  if (format === 'text') return String(value);
78
107
  // Grouping separators are what make a column of figures readable; the
79
108
  // fraction digits follow the data rather than padding every integer.
@@ -83,6 +112,26 @@ function formatValue(
83
112
  return String(value);
84
113
  }
85
114
 
115
+ function computeSummary(
116
+ op: DataSummaryOp | ReactNode,
117
+ values: number[],
118
+ format: DataFormat | undefined,
119
+ emptyValue: ReactNode,
120
+ ): ReactNode {
121
+ if (typeof op === 'function') return op(values);
122
+ if (op === 'sum' || op === 'avg' || op === 'min' || op === 'max' || op === 'count') {
123
+ if (values.length === 0) return emptyValue;
124
+ let num = 0;
125
+ if (op === 'count') num = values.length;
126
+ else if (op === 'sum') num = values.reduce((a, b) => a + b, 0);
127
+ else if (op === 'avg') num = values.reduce((a, b) => a + b, 0) / values.length;
128
+ else if (op === 'min') num = Math.min(...values);
129
+ else if (op === 'max') num = Math.max(...values);
130
+ return formatValue(num, op === 'count' ? 'integer' : format, {}, emptyValue);
131
+ }
132
+ return op;
133
+ }
134
+
86
135
  /**
87
136
  * A print-shaped table from data, so the numbers in a report come from a file
88
137
  * instead of being retyped into JSX. Alignment and grouping follow the column's
@@ -95,21 +144,42 @@ export function DataTable({
95
144
  id,
96
145
  limit,
97
146
  compact = false,
147
+ splittable = false,
148
+ summaryRow,
149
+ summaryLabel = 'Total',
98
150
  emptyValue = '—',
99
151
  style,
100
152
  className,
101
153
  [LOC_PROP]: loc,
102
154
  }: DataTableProps) {
155
+ const slice = useTableSlice();
103
156
  const resolved: DataColumn[] = (columns ?? Object.keys(rows[0] ?? {})).map(normalizeColumn);
104
157
 
105
- const shown = limit !== undefined ? rows.slice(0, limit) : rows;
106
- const hidden = rows.length - shown.length;
158
+ const limited = limit !== undefined ? rows.slice(0, limit) : rows;
159
+ const hidden = rows.length - limited.length;
160
+
161
+ const isContinued = splittable && slice !== null && slice.rowStart > 0;
162
+ const isLastSlice = !splittable || slice === null || slice.rowEnd >= limited.length;
163
+ const shown =
164
+ splittable && slice !== null ? limited.slice(slice.rowStart, slice.rowEnd) : limited;
165
+
166
+ const maxByCol = new Map<string, number>();
167
+ for (const col of resolved) {
168
+ if (!col.dataBar) continue;
169
+ let max = 0;
170
+ for (const row of limited) {
171
+ const v = row[col.key];
172
+ if (isNumber(v) && Math.abs(v) > max) max = Math.abs(v);
173
+ }
174
+ if (max > 0) maxByCol.set(col.key, max);
175
+ }
107
176
 
108
177
  const cellPadding = compact ? '4px 8px' : '7px 8px';
109
178
 
110
179
  const table = (
111
180
  <table
112
181
  {...(caption ? {} : sourceAttrs(loc))}
182
+ {...(splittable ? { 'data-od-splittable': '' } : {})}
113
183
  className={className}
114
184
  style={{
115
185
  width: '100%',
@@ -158,6 +228,11 @@ export function DataTable({
158
228
  <tr key={rowIndex}>
159
229
  {resolved.map((column) => {
160
230
  const align = column.align ?? inferAlign(rows, column.key);
231
+ const val = row[column.key];
232
+ const maxBar = maxByCol.get(column.key);
233
+ const barRatio =
234
+ maxBar && isNumber(val) ? Math.min(1, Math.max(0, Math.abs(val) / maxBar)) : 0;
235
+
161
236
  return (
162
237
  <td
163
238
  key={column.key}
@@ -168,29 +243,78 @@ export function DataTable({
168
243
  borderBottom: '1px solid var(--od-rule)',
169
244
  fontVariantNumeric: align === 'right' ? 'tabular-nums' : undefined,
170
245
  overflowWrap: 'anywhere',
246
+ ...(barRatio > 0
247
+ ? {
248
+ backgroundImage: `linear-gradient(to right, color-mix(in srgb, var(--od-accent, #2563eb) 14%, transparent) ${(barRatio * 100).toFixed(1)}%, transparent ${(barRatio * 100).toFixed(1)}%)`,
249
+ }
250
+ : {}),
171
251
  }}
172
252
  >
173
- {formatValue(row[column.key], column.format, row, emptyValue)}
253
+ {formatValue(val, column.format, row, emptyValue)}
174
254
  </td>
175
255
  );
176
256
  })}
177
257
  </tr>
178
258
  ))}
179
259
  </tbody>
180
- {hidden > 0 && (
260
+ {isLastSlice && (summaryRow || hidden > 0) && (
181
261
  <tfoot>
182
- <tr>
183
- <td
184
- colSpan={resolved.length}
185
- style={{
186
- fontSize: 'var(--od-size-caption)',
187
- color: 'var(--od-muted)',
188
- padding: '6px 8px 0',
189
- }}
190
- >
191
- {hidden} more row{hidden === 1 ? '' : 's'} not shown
192
- </td>
193
- </tr>
262
+ {summaryRow && (
263
+ <tr>
264
+ {resolved.map((column, colIndex) => {
265
+ const align = column.align ?? inferAlign(rows, column.key);
266
+ const explicit =
267
+ typeof summaryRow === 'object' ? summaryRow[column.key] : column.summary;
268
+ let content: ReactNode = null;
269
+ if (explicit !== undefined) {
270
+ if (explicit === 'count') {
271
+ const nonNull = limited.filter(
272
+ (r) =>
273
+ r[column.key] !== null &&
274
+ r[column.key] !== undefined &&
275
+ r[column.key] !== '',
276
+ ).length;
277
+ content = formatValue(nonNull, 'integer', {}, emptyValue);
278
+ } else {
279
+ const nums = limited.map((r) => r[column.key]).filter(isNumber);
280
+ content = computeSummary(explicit, nums, column.format, emptyValue);
281
+ }
282
+ } else if (colIndex === 0) {
283
+ content = summaryLabel;
284
+ }
285
+ return (
286
+ <td
287
+ key={column.key}
288
+ style={{
289
+ textAlign: align,
290
+ fontSize: compact ? 11 : 12,
291
+ fontWeight: 600,
292
+ padding: cellPadding,
293
+ borderTop: '1.5px solid var(--od-text)',
294
+ borderBottom: '1px solid var(--od-rule)',
295
+ fontVariantNumeric: align === 'right' ? 'tabular-nums' : undefined,
296
+ }}
297
+ >
298
+ {content}
299
+ </td>
300
+ );
301
+ })}
302
+ </tr>
303
+ )}
304
+ {hidden > 0 && (
305
+ <tr>
306
+ <td
307
+ colSpan={resolved.length}
308
+ style={{
309
+ fontSize: 'var(--od-size-caption)',
310
+ color: 'var(--od-muted)',
311
+ padding: '6px 8px 0',
312
+ }}
313
+ >
314
+ {hidden} more row{hidden === 1 ? '' : 's'} not shown
315
+ </td>
316
+ </tr>
317
+ )}
194
318
  </tfoot>
195
319
  )}
196
320
  </table>
@@ -198,11 +322,15 @@ export function DataTable({
198
322
 
199
323
  if (!caption) return table;
200
324
 
325
+ const effectiveCaption =
326
+ isContinued && typeof caption === 'string' ? `${caption} (cont.)` : caption;
327
+
201
328
  return (
202
329
  <Figure
203
330
  kind="table"
204
- caption={caption}
205
- {...(id !== undefined ? { id } : {})}
331
+ caption={effectiveCaption}
332
+ {...(id !== undefined && !isContinued ? { id } : {})}
333
+ {...(isContinued ? { numbered: false } : {})}
206
334
  {...sourceAttrs(loc)}
207
335
  >
208
336
  {table}
@@ -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={t('Page {page}', { page })}
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 text-right font-mono text-[10px] tabular-nums',
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}
@@ -1,11 +1,27 @@
1
- import type { CSSProperties, ReactNode } from 'react';
1
+ import { type CSSProperties, createContext, type ReactNode, useContext } from 'react';
2
2
  import type { DesignSystem } from '../lib/design';
3
- import type { FlowSection } from '../lib/flow';
3
+ import type { BlockSlice, FlowSection } from '../lib/flow';
4
4
  import type { ExtractedNote } from '../lib/footnotes';
5
5
  import { Footnotes } from './footnote';
6
6
 
7
7
  export const FLOW_BLOCK_ATTR = 'data-od-flow-block';
8
8
 
9
+ export type TableSliceRange = { rowStart: number; rowEnd: number };
10
+
11
+ const SLICE_CONTEXT_KEY = '__open_doc_table_slice_context__';
12
+ type GlobalWithSlice = typeof globalThis & {
13
+ [SLICE_CONTEXT_KEY]?: ReturnType<typeof createContext<TableSliceRange | null>>;
14
+ };
15
+ const g = globalThis as GlobalWithSlice;
16
+ if (!g[SLICE_CONTEXT_KEY]) {
17
+ g[SLICE_CONTEXT_KEY] = createContext<TableSliceRange | null>(null);
18
+ }
19
+ const TableSliceContext = g[SLICE_CONTEXT_KEY];
20
+
21
+ export function useTableSlice(): TableSliceRange | null {
22
+ return useContext(TableSliceContext);
23
+ }
24
+
9
25
  /**
10
26
  * The page shell a flow section renders into. The framework owns the margin and
11
27
  * base typography here — that is the trade for not hand-splitting pages — while
@@ -33,20 +49,30 @@ export function flowShellStyle(design: DesignSystem | undefined, padding?: numbe
33
49
  };
34
50
  }
35
51
 
36
- export function FlowBlock({ children }: { children?: ReactNode }) {
37
- return <div {...{ [FLOW_BLOCK_ATTR]: '' }}>{children}</div>;
52
+ export function FlowBlock({
53
+ slice,
54
+ children,
55
+ }: {
56
+ slice?: TableSliceRange | null;
57
+ children?: ReactNode;
58
+ }) {
59
+ const inner = <div {...{ [FLOW_BLOCK_ATTR]: '' }}>{children}</div>;
60
+ if (!slice) return inner;
61
+ return <TableSliceContext.Provider value={slice}>{inner}</TableSliceContext.Provider>;
38
62
  }
39
63
 
40
64
  export function FlowPage({
41
65
  section,
42
66
  design,
43
67
  blockIndices,
68
+ blockSlices,
44
69
  blocks,
45
70
  notes,
46
71
  }: {
47
72
  section: FlowSection;
48
73
  design: DesignSystem | undefined;
49
74
  blockIndices: number[];
75
+ blockSlices?: BlockSlice[];
50
76
  /** Blocks with footnotes already lifted out; falls back to the authored ones. */
51
77
  blocks?: ReactNode[];
52
78
  notes?: ExtractedNote[];
@@ -54,13 +80,36 @@ export function FlowPage({
54
80
  const Header = section.header;
55
81
  const Footer = section.footer;
56
82
  const source = blocks ?? section.blocks;
83
+ const items: BlockSlice[] = blockSlices ?? blockIndices.map((index) => ({ index }));
84
+ const cols = section.columns && section.columns > 1 ? section.columns : 1;
85
+
57
86
  return (
58
87
  <div style={flowShellStyle(design, section.padding)}>
59
88
  {Header && <Header />}
60
- <div style={{ flex: 1, minHeight: 0 }}>
61
- {blockIndices.map((index) => (
62
- <FlowBlock key={index}>{source[index]}</FlowBlock>
63
- ))}
89
+ <div
90
+ style={{
91
+ flex: cols > 1 ? 'none' : 1,
92
+ minHeight: 0,
93
+ ...(cols > 1
94
+ ? {
95
+ columnCount: cols,
96
+ columnGap: section.columnGap ?? 24,
97
+ columnFill: 'balance',
98
+ }
99
+ : {}),
100
+ }}
101
+ >
102
+ {items.map((item) => {
103
+ const slice =
104
+ item.rowStart !== undefined && item.rowEnd !== undefined
105
+ ? { rowStart: item.rowStart, rowEnd: item.rowEnd }
106
+ : null;
107
+ return (
108
+ <FlowBlock key={`${item.index}-${item.rowStart ?? 0}`} slice={slice}>
109
+ {source[item.index]}
110
+ </FlowBlock>
111
+ );
112
+ })}
64
113
  </div>
65
114
  {notes && notes.length > 0 && <Footnotes notes={notes} />}
66
115
  {Footer && <Footer />}
@@ -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
+ }
@@ -66,8 +66,10 @@ import {
66
66
  } from '../../lib/inspector/inline-edit';
67
67
  import { PROP_ATTR } from '../../lib/source-loc';
68
68
  import { useHistory } from '../history-provider';
69
+ import { OverlayFrame } from '../overlay-frame';
69
70
  import { CollapsibleSection, Section } from '../panel/fields';
70
71
  import { PanelIconButton, PanelShell } from '../panel/panel-shell';
72
+ import { FieldSource } from './field-source';
71
73
  import { FormatSection } from './format-section';
72
74
  import { elementsAt, styleKey, useStyleEdits } from './use-style-edits';
73
75
 
@@ -82,6 +84,8 @@ type ResolvedTarget = {
82
84
  text: string;
83
85
  parts: TextPart[];
84
86
  reason?: string;
87
+ /** Values `<Field>` prints from the document's records. */
88
+ fields?: { names: string[]; file: string | null };
85
89
  };
86
90
 
87
91
  export const LOC_ATTR = 'data-od-loc';
@@ -192,73 +196,17 @@ function kindOf(tag: string): { label: string; vars?: Record<string, number>; ic
192
196
  return { label: 'Box', icon: Square };
193
197
  }
194
198
 
195
- type Rect = { left: number; top: number; width: number; height: number };
196
-
197
- function sameRect(a: Rect | null, b: Rect) {
198
- return (
199
- a !== null &&
200
- a.left === b.left &&
201
- a.top === b.top &&
202
- a.width === b.width &&
203
- a.height === b.height
204
- );
205
- }
199
+ type FrameVariant = keyof typeof FRAME_STYLE;
206
200
 
207
201
  function Frame({
208
- anchor,
209
- container,
210
202
  variant,
203
+ ...rest
211
204
  }: {
212
205
  anchor: HTMLElement | null;
213
206
  container: HTMLElement;
214
- variant: 'hover' | 'selected' | 'pending' | 'twin';
207
+ variant: FrameVariant;
215
208
  }) {
216
- const [rect, setRect] = useState<Rect | null>(null);
217
-
218
- // Deliberately no dependency array. Opening a side pane re-zooms and re-centres
219
- // the pages, which moves the anchor without resizing it — ResizeObserver never
220
- // sees that, and the zoom lands a frame after the observer would have fired.
221
- // Measuring after every render is what keeps the frame on its element; the
222
- // value comparison below stops that from looping.
223
- useLayoutEffect(() => {
224
- if (!anchor?.isConnected) {
225
- setRect(null);
226
- return;
227
- }
228
- // The overlay is absolutely positioned inside the scroller, so its origin
229
- // is the content box — frames live in content coordinates and scroll along
230
- // with the pages.
231
- const measure = () => {
232
- const a = anchor.getBoundingClientRect();
233
- const c = container.getBoundingClientRect();
234
- const next = {
235
- left: a.left - c.left + container.scrollLeft,
236
- top: a.top - c.top + container.scrollTop,
237
- width: a.width,
238
- height: a.height,
239
- };
240
- setRect((prev) => (sameRect(prev, next) ? prev : next));
241
- };
242
-
243
- measure();
244
- const ro = new ResizeObserver(measure);
245
- ro.observe(anchor);
246
- ro.observe(container);
247
- container.addEventListener('scroll', measure, { passive: true });
248
- return () => {
249
- ro.disconnect();
250
- container.removeEventListener('scroll', measure);
251
- };
252
- });
253
-
254
- if (!rect) return null;
255
- return (
256
- <div
257
- aria-hidden
258
- className="pointer-events-none absolute rounded-[2px]"
259
- style={{ ...rect, ...FRAME_STYLE[variant] }}
260
- />
261
- );
209
+ return <OverlayFrame {...rest} style={FRAME_STYLE[variant]} />;
262
210
  }
263
211
 
264
212
  const TOOLBAR_GAP = 6;
@@ -569,6 +517,11 @@ type Props = {
569
517
  panelHidden: boolean;
570
518
  /** An element was picked on the page — the dock should show its panel. */
571
519
  onPick: () => void;
520
+ /** The reader came here to leave a comment: the element panel opens on the note. */
521
+ commentFirst?: boolean;
522
+ /** Waiting for the element a new comment is about. */
523
+ picking?: boolean;
524
+ onCancelPick?: () => void;
572
525
  /** The save card is showing, so the hint underneath it steps aside. */
573
526
  quiet: boolean;
574
527
  onExit: () => void;
@@ -583,6 +536,9 @@ export function Inspector({
583
536
  containerRef,
584
537
  panelHidden,
585
538
  onPick,
539
+ commentFirst = false,
540
+ picking = false,
541
+ onCancelPick,
586
542
  quiet,
587
543
  onExit,
588
544
  exitRef,
@@ -1186,6 +1142,10 @@ export function Inspector({
1186
1142
  finish(active, true);
1187
1143
  return;
1188
1144
  }
1145
+ if (picking && onCancelPick) {
1146
+ onCancelPick();
1147
+ return;
1148
+ }
1189
1149
  if (selected) {
1190
1150
  setSelected(null);
1191
1151
  return;
@@ -1216,7 +1176,27 @@ export function Inspector({
1216
1176
  window.removeEventListener('pointerdown', onPointerDown, true);
1217
1177
  window.removeEventListener('keydown', onKey, true);
1218
1178
  };
1219
- }, [container, insideChrome, entryAt, active, selected, begin, finish, leave]);
1179
+ }, [
1180
+ container,
1181
+ insideChrome,
1182
+ entryAt,
1183
+ active,
1184
+ selected,
1185
+ begin,
1186
+ finish,
1187
+ leave,
1188
+ picking,
1189
+ onCancelPick,
1190
+ ]);
1191
+
1192
+ // While a comment waits for its element, the page says so under the pointer.
1193
+ useEffect(() => {
1194
+ if (!container || !picking) return;
1195
+ container.style.cursor = 'crosshair';
1196
+ return () => {
1197
+ container.style.cursor = '';
1198
+ };
1199
+ }, [container, picking]);
1220
1200
 
1221
1201
  // Typing is applied by hand to the run under the caret — see inline-edit.ts
1222
1202
  // for why the browser is not allowed to. IME composition is the exception:
@@ -1491,9 +1471,13 @@ export function Inspector({
1491
1471
  const selectedEl = visible(selected?.anchor);
1492
1472
  const hint = active
1493
1473
  ? t('Enter to keep · Shift+Enter for a new line · Esc to revert')
1494
- : selected
1495
- ? t('Double-click or Enter to edit text · Esc to deselect')
1496
- : t('Click to select · double-click to edit · Esc to leave');
1474
+ : picking
1475
+ ? t('Click the element to comment on · Esc to cancel')
1476
+ : selected && target && !target.editable
1477
+ ? t('Esc to deselect')
1478
+ : selected
1479
+ ? t('Double-click or Enter to edit text · Esc to deselect')
1480
+ : t('Click to select · double-click to edit · Esc to leave');
1497
1481
 
1498
1482
  const overlay = container
1499
1483
  ? createPortal(
@@ -1599,6 +1583,10 @@ export function Inspector({
1599
1583
  <div className="h-0.5 overflow-hidden rounded bg-muted">
1600
1584
  <div className="h-full w-1/3 animate-pulse bg-foreground/20" />
1601
1585
  </div>
1586
+ ) : target.fields && !target.editable ? (
1587
+ // Data, not words in the source: the place to change it is the
1588
+ // cell, so that is what the panel shows.
1589
+ <FieldSource names={target.fields.names} file={target.fields.file} />
1602
1590
  ) : (
1603
1591
  // The words themselves, as the way in: clicking them opens them
1604
1592
  // on the page. Markup the editor leaves alone reads as a chip.
@@ -1641,9 +1629,20 @@ export function Inspector({
1641
1629
  </span>
1642
1630
  </button>
1643
1631
  )}
1632
+ {target?.fields && target.editable && (
1633
+ <FieldSource names={target.fields.names} file={target.fields.file} />
1634
+ )}
1644
1635
  </Section>
1645
- <CollapsibleSection title={t('Comment for the agent')}>
1636
+ <CollapsibleSection
1637
+ // Remounted per element while commenting, so each pick opens on
1638
+ // the note with the caret in it.
1639
+ key={commentFirst ? loc : 'comment'}
1640
+ title={t('Comment for the agent')}
1641
+ defaultOpen={commentFirst}
1642
+ >
1646
1643
  <textarea
1644
+ // biome-ignore lint/a11y/noAutofocus: the reader asked to comment and then picked this element
1645
+ autoFocus={commentFirst}
1647
1646
  aria-label={t('Comment for the agent')}
1648
1647
  value={note}
1649
1648
  onChange={(e) => setNote(e.target.value)}