@open-document/core 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-BHFGY8eF.js → build-CbgIk6bA.js} +1 -1
- package/dist/{check-UEBmDfT_.js → check-BTroj-5Z.js} +3 -3
- package/dist/cli/bin.js +58 -34
- package/dist/config-BWtOZ1jc.d.ts +45 -0
- package/dist/{config-B_pdNbYg.js → config-DKKNIbvO.js} +1458 -983
- package/dist/{context-BM9_-u9P.js → context-DXNP8v9I.js} +3 -2
- package/dist/deploy-gcp-BUiSuqz7.js +758 -0
- package/dist/{dev-DX3QMIRi.js → dev-YXumw5iX.js} +1 -1
- package/dist/{diagram-BK4jTZr4.js → diagram-CKf3ptOE.js} +293 -13
- package/dist/{diff-DayvbXfX.js → diff-CTFfU4Tz.js} +2 -2
- package/dist/{export-BPsXj1i6.js → export-D2QLtF84.js} +11 -4
- package/dist/flow-CS5apebG.d.ts +252 -0
- package/dist/{import-71wlAsrd.js → import-CcmrFetU.js} +3 -2
- package/dist/index.d.ts +155 -59
- package/dist/index.js +945 -104
- package/dist/open-doc-plugin-DnX5usgI.js +320 -0
- package/dist/ops/index.d.ts +112 -3
- package/dist/ops/index.js +3 -3
- package/dist/{ops-BUo67DaP.js → ops-DmEecq1k.js} +86 -164
- package/dist/package-version-C89gtYSk.js +36 -0
- package/dist/{preview-D3m1-gUL.js → preview-_mHpBhMk.js} +1 -1
- package/dist/templates-MMblHwmT.js +34 -0
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +2 -1
- package/package.json +2 -1
- package/skills/apply-comments/SKILL.md +3 -1
- package/skills/create-doc/SKILL.md +2 -0
- package/skills/doc-authoring/SKILL.md +17 -16
- package/skills/doc-authoring/references/long-form.md +43 -2
- package/skills/doc-authoring/references/pagination.md +14 -2
- package/skills/doc-authoring/references/tables-and-charts.md +21 -17
- package/src/app/components/browser/browser-ui.tsx +21 -0
- package/src/app/components/browser/new-document-dialog.tsx +208 -0
- package/src/app/components/callout.tsx +101 -0
- package/src/app/components/changes/changes-overlay.tsx +68 -0
- package/src/app/components/changes/changes-panel.tsx +341 -0
- package/src/app/components/changes/use-changes.ts +85 -0
- package/src/app/components/chart.tsx +191 -33
- package/src/app/components/code-block.tsx +249 -0
- package/src/app/components/comments/comments-overlay.tsx +50 -0
- package/src/app/components/comments/comments-panel.tsx +272 -0
- package/src/app/components/comments/use-comments.ts +61 -0
- package/src/app/components/data-table.tsx +146 -18
- package/src/app/components/doc-sidebar.tsx +32 -2
- package/src/app/components/flow-page.tsx +57 -8
- package/src/app/components/inspector/field-source.tsx +41 -0
- package/src/app/components/inspector/inspector.tsx +64 -65
- package/src/app/components/numbering.tsx +226 -12
- package/src/app/components/overlay-frame.tsx +79 -0
- package/src/app/components/page-frame.tsx +46 -0
- package/src/app/components/page-placement.ts +68 -0
- package/src/app/components/record-picker.tsx +79 -0
- package/src/app/components/themes/theme-preview.tsx +5 -4
- package/src/app/lib/agent-bridge.ts +29 -1
- package/src/app/lib/chart.test.ts +15 -0
- package/src/app/lib/chart.ts +134 -9
- package/src/app/lib/diagnostics.ts +45 -1
- package/src/app/lib/docx/ooxml.test.ts +24 -1
- package/src/app/lib/docx/ooxml.ts +27 -1
- package/src/app/lib/export-docx.ts +3 -1
- package/src/app/lib/export-dom.ts +17 -3
- package/src/app/lib/export-html.ts +4 -2
- package/src/app/lib/export-image.ts +2 -1
- package/src/app/lib/export-pdf.ts +9 -1
- package/src/app/lib/flow-measure.test.ts +30 -0
- package/src/app/lib/flow-measure.ts +68 -14
- package/src/app/lib/flow.test.ts +20 -1
- package/src/app/lib/flow.ts +120 -20
- package/src/app/lib/i18n-ja/browser.ts +10 -0
- package/src/app/lib/i18n-ja/doc.ts +4 -0
- package/src/app/lib/i18n-ja/panels.ts +40 -0
- package/src/app/lib/i18n-ko/browser.ts +10 -0
- package/src/app/lib/i18n-ko/doc.ts +4 -0
- package/src/app/lib/i18n-ko/panels.ts +39 -0
- package/src/app/lib/i18n-zh-cn/browser.ts +10 -0
- package/src/app/lib/i18n-zh-cn/doc.ts +4 -0
- package/src/app/lib/i18n-zh-cn/panels.ts +38 -0
- package/src/app/lib/i18n-zh-tw/browser.ts +10 -0
- package/src/app/lib/i18n-zh-tw/doc.ts +4 -0
- package/src/app/lib/i18n-zh-tw/panels.ts +38 -0
- package/src/app/lib/labels.ts +29 -10
- package/src/app/lib/records.test.ts +38 -0
- package/src/app/lib/records.ts +127 -0
- package/src/app/lib/sdk.ts +35 -0
- package/src/app/lib/use-doc-module.ts +7 -0
- package/src/app/lib/use-doc-pages.ts +38 -17
- package/src/app/routes/doc.tsx +275 -13
- package/src/app/routes/home.tsx +30 -5
- package/src/app/styles.css +23 -0
- package/templates/blank/index.tsx +63 -0
- package/templates/blank/template.json +6 -0
- package/templates/certificate/data/recipients.csv +4 -0
- package/templates/certificate/index.tsx +128 -0
- package/templates/certificate/template.json +6 -0
- package/templates/letter/index.tsx +106 -0
- package/templates/letter/template.json +5 -0
- package/templates/meeting-notes/index.tsx +194 -0
- package/templates/meeting-notes/template.json +6 -0
- package/templates/proposal/index.tsx +264 -0
- package/templates/proposal/template.json +6 -0
- package/templates/report/data/metrics.csv +5 -0
- package/templates/report/index.tsx +224 -0
- package/templates/report/template.json +6 -0
- package/dist/config-P61niZMf.d.ts +0 -24
- package/dist/sdk-CpDEGRIo.d.ts +0 -138
|
@@ -27,6 +27,8 @@ export type FigureProps = {
|
|
|
27
27
|
captionPosition?: 'above' | 'below';
|
|
28
28
|
/** Plain-text caption for the list of figures, when `caption` carries markup. */
|
|
29
29
|
captionText?: string;
|
|
30
|
+
/** When false, prints the caption without registering a new label number (e.g. continued table slices). */
|
|
31
|
+
numbered?: boolean;
|
|
30
32
|
style?: CSSProperties;
|
|
31
33
|
captionStyle?: CSSProperties;
|
|
32
34
|
className?: string;
|
|
@@ -49,6 +51,7 @@ export function Figure({
|
|
|
49
51
|
kind = 'figure',
|
|
50
52
|
captionPosition,
|
|
51
53
|
captionText,
|
|
54
|
+
numbered = true,
|
|
52
55
|
style,
|
|
53
56
|
captionStyle,
|
|
54
57
|
className,
|
|
@@ -75,28 +78,35 @@ export function Figure({
|
|
|
75
78
|
...captionStyle,
|
|
76
79
|
}}
|
|
77
80
|
>
|
|
78
|
-
|
|
79
|
-
{
|
|
80
|
-
|
|
81
|
+
{numbered && (
|
|
82
|
+
<span style={{ fontWeight: 600, color: 'var(--od-text)' }}>
|
|
83
|
+
{nameFor(kind, vocabulary)} {entry?.number ?? ''}
|
|
84
|
+
</span>
|
|
85
|
+
)}
|
|
81
86
|
{typeof caption === 'string' || typeof caption === 'number' ? (
|
|
82
87
|
<span>
|
|
83
|
-
{' — '}
|
|
88
|
+
{numbered ? ' — ' : ''}
|
|
84
89
|
<span {...sourceAttrs(loc, 'caption')}>{caption}</span>
|
|
85
90
|
</span>
|
|
86
91
|
) : caption ? (
|
|
87
|
-
<span>
|
|
92
|
+
<span>
|
|
93
|
+
{numbered ? ' — ' : ''}
|
|
94
|
+
{caption}
|
|
95
|
+
</span>
|
|
88
96
|
) : null}
|
|
89
97
|
</figcaption>
|
|
90
98
|
) : null;
|
|
91
99
|
|
|
92
100
|
return (
|
|
93
101
|
<figure
|
|
94
|
-
{...
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
{...(numbered
|
|
103
|
+
? {
|
|
104
|
+
[LABEL_ATTR]: kind,
|
|
105
|
+
[LABEL_ID_ATTR]: labelId,
|
|
106
|
+
[LABEL_TEXT_ATTR]: text,
|
|
107
|
+
...sourceAttrs(loc),
|
|
108
|
+
}
|
|
109
|
+
: sourceAttrs(loc))}
|
|
100
110
|
className={className}
|
|
101
111
|
style={{ margin: '0 0 16px', ...style }}
|
|
102
112
|
>
|
|
@@ -143,7 +153,10 @@ export function Ref({ to, showPage = 'auto', style, className }: RefProps) {
|
|
|
143
153
|
);
|
|
144
154
|
}
|
|
145
155
|
|
|
146
|
-
const name =
|
|
156
|
+
const name =
|
|
157
|
+
entry.kind === 'footnote' || entry.kind === 'citation'
|
|
158
|
+
? ''
|
|
159
|
+
: `${nameFor(entry.kind, vocabulary)} `;
|
|
147
160
|
const withPage = showPage === 'auto' ? entry.page !== here : showPage;
|
|
148
161
|
|
|
149
162
|
return (
|
|
@@ -219,3 +232,204 @@ export function ListOfFigures(props: Omit<ListOfProps, 'kind'>) {
|
|
|
219
232
|
export function ListOfTables(props: Omit<ListOfProps, 'kind'>) {
|
|
220
233
|
return <ListOf {...props} kind="table" />;
|
|
221
234
|
}
|
|
235
|
+
|
|
236
|
+
export type CiteProps = {
|
|
237
|
+
/** Stable citation key (e.g. 'rfc9110' or 'q3-audit'). */
|
|
238
|
+
id: string;
|
|
239
|
+
/** Citation details printed in `<Bibliography />`. Needs only to be supplied on one `<Cite>` for that id, or in `<Bibliography items={...} />`. */
|
|
240
|
+
source?: string;
|
|
241
|
+
style?: CSSProperties;
|
|
242
|
+
className?: string;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* An inline bibliographic citation (`[1]`), numbered in order of first
|
|
247
|
+
* appearance across the rendered pages. Multiple `<Cite id="x" />` calls share
|
|
248
|
+
* the same number.
|
|
249
|
+
*/
|
|
250
|
+
export function Cite({ id, source, style, className }: CiteProps) {
|
|
251
|
+
const entry = useDocLabel(id, 'citation');
|
|
252
|
+
return (
|
|
253
|
+
<span
|
|
254
|
+
{...{
|
|
255
|
+
[LABEL_ATTR]: 'citation',
|
|
256
|
+
[LABEL_ID_ATTR]: id,
|
|
257
|
+
...(source ? { [LABEL_TEXT_ATTR]: source } : {}),
|
|
258
|
+
}}
|
|
259
|
+
data-od-cite={id}
|
|
260
|
+
className={className}
|
|
261
|
+
style={{
|
|
262
|
+
fontSize: '0.82em',
|
|
263
|
+
verticalAlign: 'super',
|
|
264
|
+
lineHeight: 0,
|
|
265
|
+
fontWeight: 600,
|
|
266
|
+
color: 'var(--od-accent)',
|
|
267
|
+
fontVariantNumeric: 'tabular-nums',
|
|
268
|
+
...style,
|
|
269
|
+
}}
|
|
270
|
+
>
|
|
271
|
+
[{entry?.number ?? '·'}]
|
|
272
|
+
</span>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export type BibliographyItem = {
|
|
277
|
+
id?: string;
|
|
278
|
+
title?: ReactNode;
|
|
279
|
+
source?: ReactNode;
|
|
280
|
+
author?: string;
|
|
281
|
+
year?: string | number;
|
|
282
|
+
url?: string;
|
|
283
|
+
note?: string;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export type BibliographyProps = {
|
|
287
|
+
/** Optional catalog of reference details keyed by citation `id` (or an array with `id`). Merged with inline `<Cite source="..." />` texts. */
|
|
288
|
+
items?: Record<string, string | BibliographyItem> | BibliographyItem[];
|
|
289
|
+
/** Optional heading text above the reference list. Pass `""` to omit. */
|
|
290
|
+
title?: ReactNode;
|
|
291
|
+
/** Show page numbers where each citation first appeared. */
|
|
292
|
+
showPageNumbers?: boolean;
|
|
293
|
+
style?: CSSProperties;
|
|
294
|
+
className?: string;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
function renderBibItem(spec: string | BibliographyItem | undefined, fallback: string): ReactNode {
|
|
298
|
+
if (!spec) return fallback;
|
|
299
|
+
if (typeof spec === 'string') return spec;
|
|
300
|
+
if (spec.source && !spec.title) return spec.source;
|
|
301
|
+
return (
|
|
302
|
+
<span>
|
|
303
|
+
{spec.author ? `${spec.author}. ` : ''}
|
|
304
|
+
<strong style={{ fontWeight: 600, color: 'var(--od-text)' }}>{spec.title}</strong>
|
|
305
|
+
{spec.year ? ` (${spec.year}).` : '.'}
|
|
306
|
+
{spec.note ? ` ${spec.note}` : ''}
|
|
307
|
+
{spec.url ? (
|
|
308
|
+
<>
|
|
309
|
+
{' '}
|
|
310
|
+
<span
|
|
311
|
+
style={{
|
|
312
|
+
fontFamily: 'var(--od-font-mono)',
|
|
313
|
+
fontSize: '0.92em',
|
|
314
|
+
color: 'var(--od-muted)',
|
|
315
|
+
}}
|
|
316
|
+
>
|
|
317
|
+
{spec.url}
|
|
318
|
+
</span>
|
|
319
|
+
</>
|
|
320
|
+
) : null}
|
|
321
|
+
</span>
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Renders the numbered list of all `<Cite>` references in order of appearance,
|
|
327
|
+
* plus any additional uncited entries passed in `items`.
|
|
328
|
+
*/
|
|
329
|
+
export function Bibliography({
|
|
330
|
+
items,
|
|
331
|
+
title,
|
|
332
|
+
showPageNumbers = false,
|
|
333
|
+
style,
|
|
334
|
+
className,
|
|
335
|
+
}: BibliographyProps) {
|
|
336
|
+
const cited = useDocLabels('citation');
|
|
337
|
+
const vocabulary = useLabelVocabulary();
|
|
338
|
+
|
|
339
|
+
const map = new Map<string, string | BibliographyItem>();
|
|
340
|
+
if (Array.isArray(items)) {
|
|
341
|
+
items.forEach((item, idx) => {
|
|
342
|
+
map.set(item.id ?? `bib-${idx + 1}`, item);
|
|
343
|
+
});
|
|
344
|
+
} else if (items) {
|
|
345
|
+
for (const [k, v] of Object.entries(items)) map.set(k, v);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const rows: Array<{ id: string; number: number; content: ReactNode; page?: number }> = cited.map(
|
|
349
|
+
(entry) => ({
|
|
350
|
+
id: entry.id,
|
|
351
|
+
number: entry.number,
|
|
352
|
+
content: renderBibItem(map.get(entry.id), entry.text || entry.id),
|
|
353
|
+
page: entry.page,
|
|
354
|
+
}),
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
for (const [id, spec] of map.entries()) {
|
|
358
|
+
if (!rows.some((r) => r.id === id)) {
|
|
359
|
+
rows.push({
|
|
360
|
+
id,
|
|
361
|
+
number: rows.length + 1,
|
|
362
|
+
content: renderBibItem(spec, id),
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const heading = title !== undefined ? title : vocabulary.bibliography;
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<div
|
|
371
|
+
data-od-bibliography=""
|
|
372
|
+
className={className}
|
|
373
|
+
style={{
|
|
374
|
+
fontFamily: 'var(--od-font-body)',
|
|
375
|
+
fontSize: 'var(--od-size-caption, 11px)',
|
|
376
|
+
lineHeight: 1.55,
|
|
377
|
+
color: 'var(--od-text)',
|
|
378
|
+
margin: '8px 0 14px',
|
|
379
|
+
...style,
|
|
380
|
+
}}
|
|
381
|
+
>
|
|
382
|
+
{heading ? (
|
|
383
|
+
<div
|
|
384
|
+
style={{
|
|
385
|
+
fontFamily: 'var(--od-font-heading)',
|
|
386
|
+
fontSize: 'var(--od-size-h3, 14px)',
|
|
387
|
+
fontWeight: 600,
|
|
388
|
+
marginBottom: 8,
|
|
389
|
+
color: 'var(--od-text)',
|
|
390
|
+
}}
|
|
391
|
+
>
|
|
392
|
+
{heading}
|
|
393
|
+
</div>
|
|
394
|
+
) : null}
|
|
395
|
+
<ol style={{ listStyle: 'none', padding: 0, margin: 0 }}>
|
|
396
|
+
{rows.map((row) => (
|
|
397
|
+
<li
|
|
398
|
+
key={row.id}
|
|
399
|
+
data-od-bib-entry={row.id}
|
|
400
|
+
style={{
|
|
401
|
+
display: 'flex',
|
|
402
|
+
alignItems: 'baseline',
|
|
403
|
+
gap: 8,
|
|
404
|
+
marginBottom: 5,
|
|
405
|
+
}}
|
|
406
|
+
>
|
|
407
|
+
<span
|
|
408
|
+
style={{
|
|
409
|
+
flex: 'none',
|
|
410
|
+
minWidth: 24,
|
|
411
|
+
fontWeight: 600,
|
|
412
|
+
color: 'var(--od-accent)',
|
|
413
|
+
fontVariantNumeric: 'tabular-nums',
|
|
414
|
+
}}
|
|
415
|
+
>
|
|
416
|
+
[{row.number}]
|
|
417
|
+
</span>
|
|
418
|
+
<span style={{ flex: 1, color: 'var(--od-text)' }}>{row.content}</span>
|
|
419
|
+
{showPageNumbers && row.page !== undefined && (
|
|
420
|
+
<span
|
|
421
|
+
style={{
|
|
422
|
+
flex: 'none',
|
|
423
|
+
color: 'var(--od-muted)',
|
|
424
|
+
fontVariantNumeric: 'tabular-nums',
|
|
425
|
+
}}
|
|
426
|
+
>
|
|
427
|
+
p. {row.page}
|
|
428
|
+
</span>
|
|
429
|
+
)}
|
|
430
|
+
</li>
|
|
431
|
+
))}
|
|
432
|
+
</ol>
|
|
433
|
+
</div>
|
|
434
|
+
);
|
|
435
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode, useLayoutEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
type Rect = { left: number; top: number; width: number; height: number };
|
|
4
|
+
|
|
5
|
+
function sameRect(a: Rect | null, b: Rect) {
|
|
6
|
+
return (
|
|
7
|
+
a !== null &&
|
|
8
|
+
a.left === b.left &&
|
|
9
|
+
a.top === b.top &&
|
|
10
|
+
a.width === b.width &&
|
|
11
|
+
a.height === b.height
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A box drawn over an element on the page, in the scroller's content
|
|
17
|
+
* coordinates so it scrolls with the sheets. The inspector's frames and the
|
|
18
|
+
* changes view's marks are both this.
|
|
19
|
+
*/
|
|
20
|
+
export function OverlayFrame({
|
|
21
|
+
anchor,
|
|
22
|
+
container,
|
|
23
|
+
style,
|
|
24
|
+
children,
|
|
25
|
+
}: {
|
|
26
|
+
anchor: HTMLElement | null;
|
|
27
|
+
container: HTMLElement;
|
|
28
|
+
style: CSSProperties;
|
|
29
|
+
children?: ReactNode;
|
|
30
|
+
}) {
|
|
31
|
+
const [rect, setRect] = useState<Rect | null>(null);
|
|
32
|
+
|
|
33
|
+
// Deliberately no dependency array. Opening a side pane re-zooms and re-centres
|
|
34
|
+
// the pages, which moves the anchor without resizing it — ResizeObserver never
|
|
35
|
+
// sees that, and the zoom lands a frame after the observer would have fired.
|
|
36
|
+
// Measuring after every render is what keeps the frame on its element; the
|
|
37
|
+
// value comparison below stops that from looping.
|
|
38
|
+
useLayoutEffect(() => {
|
|
39
|
+
if (!anchor?.isConnected) {
|
|
40
|
+
setRect(null);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// The overlay is absolutely positioned inside the scroller, so its origin
|
|
44
|
+
// is the content box — frames live in content coordinates and scroll along
|
|
45
|
+
// with the pages.
|
|
46
|
+
const measure = () => {
|
|
47
|
+
const a = anchor.getBoundingClientRect();
|
|
48
|
+
const c = container.getBoundingClientRect();
|
|
49
|
+
const next = {
|
|
50
|
+
left: a.left - c.left + container.scrollLeft,
|
|
51
|
+
top: a.top - c.top + container.scrollTop,
|
|
52
|
+
width: a.width,
|
|
53
|
+
height: a.height,
|
|
54
|
+
};
|
|
55
|
+
setRect((prev) => (sameRect(prev, next) ? prev : next));
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
measure();
|
|
59
|
+
const ro = new ResizeObserver(measure);
|
|
60
|
+
ro.observe(anchor);
|
|
61
|
+
ro.observe(container);
|
|
62
|
+
container.addEventListener('scroll', measure, { passive: true });
|
|
63
|
+
return () => {
|
|
64
|
+
ro.disconnect();
|
|
65
|
+
container.removeEventListener('scroll', measure);
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!rect) return null;
|
|
70
|
+
return (
|
|
71
|
+
<div
|
|
72
|
+
aria-hidden
|
|
73
|
+
className="pointer-events-none absolute rounded-[2px]"
|
|
74
|
+
style={{ ...rect, ...style }}
|
|
75
|
+
>
|
|
76
|
+
{children}
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -11,11 +11,53 @@ type Props = {
|
|
|
11
11
|
geometry: PageGeometry;
|
|
12
12
|
scale: number;
|
|
13
13
|
design?: DesignSystem;
|
|
14
|
+
/** The document's language — see `pageLang`. */
|
|
15
|
+
lang?: string;
|
|
16
|
+
/** Optional diagonal watermark stamped across the sheet. */
|
|
17
|
+
watermark?: string;
|
|
14
18
|
flat?: boolean;
|
|
15
19
|
className?: string;
|
|
16
20
|
children: ReactNode;
|
|
17
21
|
};
|
|
18
22
|
|
|
23
|
+
export function SheetWatermark({ text }: { text?: string }) {
|
|
24
|
+
const clean = text?.trim();
|
|
25
|
+
if (!clean) return null;
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
aria-hidden="true"
|
|
29
|
+
data-od-watermark=""
|
|
30
|
+
style={{
|
|
31
|
+
position: 'absolute',
|
|
32
|
+
inset: 0,
|
|
33
|
+
display: 'flex',
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
pointerEvents: 'none',
|
|
37
|
+
userSelect: 'none',
|
|
38
|
+
zIndex: 40,
|
|
39
|
+
overflow: 'hidden',
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
<span
|
|
43
|
+
style={{
|
|
44
|
+
transform: 'rotate(-34deg)',
|
|
45
|
+
fontFamily: 'var(--od-font-heading, sans-serif)',
|
|
46
|
+
fontSize: 68,
|
|
47
|
+
fontWeight: 800,
|
|
48
|
+
letterSpacing: '0.18em',
|
|
49
|
+
textTransform: 'uppercase',
|
|
50
|
+
color: 'var(--od-text, #16181d)',
|
|
51
|
+
opacity: 0.055,
|
|
52
|
+
whiteSpace: 'nowrap',
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{clean}
|
|
56
|
+
</span>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
19
61
|
/**
|
|
20
62
|
* One sheet of paper. The inner node always lays out at the page's true pixel
|
|
21
63
|
* size — authors write absolute px against A4 — and only the wrapper shrinks,
|
|
@@ -27,6 +69,8 @@ export function PageFrame({
|
|
|
27
69
|
geometry,
|
|
28
70
|
scale,
|
|
29
71
|
design,
|
|
72
|
+
lang = 'en',
|
|
73
|
+
watermark,
|
|
30
74
|
flat = false,
|
|
31
75
|
className,
|
|
32
76
|
children,
|
|
@@ -44,6 +88,7 @@ export function PageFrame({
|
|
|
44
88
|
>
|
|
45
89
|
<div
|
|
46
90
|
{...{ [PAGE_ATTR]: '', [PAGE_INDEX_ATTR]: index }}
|
|
91
|
+
lang={lang}
|
|
47
92
|
style={
|
|
48
93
|
{
|
|
49
94
|
width: geometry.width,
|
|
@@ -63,6 +108,7 @@ export function PageFrame({
|
|
|
63
108
|
>
|
|
64
109
|
<DocPageProvider index={index} total={total}>
|
|
65
110
|
{children}
|
|
111
|
+
<SheetWatermark text={watermark} />
|
|
66
112
|
</DocPageProvider>
|
|
67
113
|
</div>
|
|
68
114
|
</div>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { EDITING_ATTR } from '../lib/inspector/inline-edit';
|
|
3
|
+
import { PAGE_INDEX_ATTR } from '../lib/outline';
|
|
4
|
+
import { PROP_ATTR } from '../lib/source-loc';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The elements on the sheets printed from one source location. Thumbnails,
|
|
8
|
+
* the inspector's editing clone and words a component prints from a prop all
|
|
9
|
+
* carry a loc too, and none of them is the element itself.
|
|
10
|
+
*/
|
|
11
|
+
export function elementsAtLoc(container: ParentNode, loc: string): HTMLElement[] {
|
|
12
|
+
return [
|
|
13
|
+
...container.querySelectorAll<HTMLElement>(
|
|
14
|
+
`[data-od-loc="${loc}"]:not([${PROP_ATTR}]):not([${EDITING_ATTR}])`,
|
|
15
|
+
),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function pageOf(el: HTMLElement): number | null {
|
|
20
|
+
const raw = el.closest(`[${PAGE_INDEX_ATTR}]`)?.getAttribute(PAGE_INDEX_ATTR);
|
|
21
|
+
return raw == null ? null : Number(raw) + 1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Placeable = { id: string; locs: string[] };
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Which pages each thing lands on, read from the rendered sheets — a change,
|
|
28
|
+
* a comment. It is read again whenever the sheets change: a flow section
|
|
29
|
+
* repaginating moves it to another page without anything else telling us.
|
|
30
|
+
*/
|
|
31
|
+
export function usePlacement(
|
|
32
|
+
container: HTMLElement | null,
|
|
33
|
+
targets: Placeable[],
|
|
34
|
+
): Map<string, number[]> {
|
|
35
|
+
const [placement, setPlacement] = useState<Map<string, number[]>>(new Map());
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!container) return;
|
|
38
|
+
let frame = 0;
|
|
39
|
+
const read = () => {
|
|
40
|
+
cancelAnimationFrame(frame);
|
|
41
|
+
frame = requestAnimationFrame(() => {
|
|
42
|
+
const next = new Map<string, number[]>();
|
|
43
|
+
for (const target of targets) {
|
|
44
|
+
const pages = [
|
|
45
|
+
...new Set(
|
|
46
|
+
target.locs
|
|
47
|
+
.flatMap((loc) => elementsAtLoc(container, loc))
|
|
48
|
+
.map(pageOf)
|
|
49
|
+
.filter((page): page is number => page !== null),
|
|
50
|
+
),
|
|
51
|
+
].sort((a, b) => a - b);
|
|
52
|
+
next.set(target.id, pages);
|
|
53
|
+
}
|
|
54
|
+
setPlacement((prev) =>
|
|
55
|
+
JSON.stringify([...prev]) === JSON.stringify([...next]) ? prev : next,
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
read();
|
|
60
|
+
const observer = new MutationObserver(read);
|
|
61
|
+
observer.observe(container, { childList: true, subtree: true });
|
|
62
|
+
return () => {
|
|
63
|
+
observer.disconnect();
|
|
64
|
+
cancelAnimationFrame(frame);
|
|
65
|
+
};
|
|
66
|
+
}, [container, targets]);
|
|
67
|
+
return placement;
|
|
68
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ChevronDown, ChevronLeft, ChevronRight, Table2 } from 'lucide-react';
|
|
2
|
+
import { useT } from '../lib/i18n';
|
|
3
|
+
import {
|
|
4
|
+
type DataRecord,
|
|
5
|
+
recordLabel,
|
|
6
|
+
setRecordIndex,
|
|
7
|
+
useRecordCount,
|
|
8
|
+
useRecordIndex,
|
|
9
|
+
} from '../lib/records';
|
|
10
|
+
|
|
11
|
+
const STEP_CLASS =
|
|
12
|
+
'flex size-7 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-foreground/60 disabled:opacity-40 disabled:hover:bg-transparent';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Which row the document is shown for, when it prints one copy per row. The
|
|
16
|
+
* pages, the thumbnails and the Download menu all follow it.
|
|
17
|
+
*/
|
|
18
|
+
export function RecordPicker({
|
|
19
|
+
records,
|
|
20
|
+
labelKey,
|
|
21
|
+
}: {
|
|
22
|
+
records: DataRecord[];
|
|
23
|
+
/** `meta.recordLabel` — the column that names a row. */
|
|
24
|
+
labelKey?: string;
|
|
25
|
+
}) {
|
|
26
|
+
const t = useT();
|
|
27
|
+
const index = useRecordIndex();
|
|
28
|
+
const count = useRecordCount();
|
|
29
|
+
if (count === 0) return null;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<fieldset className="m-0 flex min-w-0 flex-none items-center gap-0.5 rounded-md border border-border p-0.5">
|
|
33
|
+
<legend className="sr-only">{t('Record')}</legend>
|
|
34
|
+
<button
|
|
35
|
+
type="button"
|
|
36
|
+
aria-label={t('Previous record')}
|
|
37
|
+
title={t('Previous record')}
|
|
38
|
+
disabled={index === 0}
|
|
39
|
+
onClick={() => setRecordIndex(index - 1)}
|
|
40
|
+
className={STEP_CLASS}
|
|
41
|
+
>
|
|
42
|
+
<ChevronLeft className="size-3.5" />
|
|
43
|
+
</button>
|
|
44
|
+
<label className="relative flex h-7 min-w-0 items-center gap-1.5 rounded px-1.5 transition-colors hover:bg-accent has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-foreground/60">
|
|
45
|
+
<Table2 aria-hidden className="size-3.5 flex-none text-muted-foreground" />
|
|
46
|
+
<span className="font-mono text-[11px] text-muted-foreground tabular-nums">
|
|
47
|
+
{index + 1}/{count}
|
|
48
|
+
</span>
|
|
49
|
+
<span className="max-w-40 truncate text-xs">
|
|
50
|
+
{recordLabel(records[index], index, labelKey)}
|
|
51
|
+
</span>
|
|
52
|
+
<ChevronDown aria-hidden className="size-3 flex-none text-muted-foreground" />
|
|
53
|
+
<select
|
|
54
|
+
aria-label={t('Record')}
|
|
55
|
+
value={index}
|
|
56
|
+
onChange={(event) => setRecordIndex(Number(event.target.value))}
|
|
57
|
+
className="absolute inset-0 cursor-pointer opacity-0"
|
|
58
|
+
>
|
|
59
|
+
{records.map((record, at) => (
|
|
60
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: rows are positional
|
|
61
|
+
<option key={at} value={at}>
|
|
62
|
+
{`${at + 1}. ${recordLabel(record, at, labelKey)}`}
|
|
63
|
+
</option>
|
|
64
|
+
))}
|
|
65
|
+
</select>
|
|
66
|
+
</label>
|
|
67
|
+
<button
|
|
68
|
+
type="button"
|
|
69
|
+
aria-label={t('Next record')}
|
|
70
|
+
title={t('Next record')}
|
|
71
|
+
disabled={index >= count - 1}
|
|
72
|
+
onClick={() => setRecordIndex(index + 1)}
|
|
73
|
+
className={STEP_CLASS}
|
|
74
|
+
>
|
|
75
|
+
<ChevronRight className="size-3.5" />
|
|
76
|
+
</button>
|
|
77
|
+
</fieldset>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { type DocPage, isPageSizeName, resolvePageGeometry } from '../../lib/sdk';
|
|
3
3
|
import { loadThemeDemo, type ThemeDemoModule, type ThemeMeta } from '../../lib/themes';
|
|
4
|
+
import { fitInCard } from '../browser/browser-ui';
|
|
4
5
|
import { PageFrame } from '../page-frame';
|
|
5
6
|
|
|
6
7
|
type Props = {
|
|
@@ -31,7 +32,7 @@ export function ThemePreview({ theme, width, all = false }: Props) {
|
|
|
31
32
|
const geometry = resolvePageGeometry(
|
|
32
33
|
isPageSizeName(theme.pageSize) ? { pageSize: theme.pageSize } : undefined,
|
|
33
34
|
);
|
|
34
|
-
const scale = width
|
|
35
|
+
const { frameHeight, scale } = fitInCard(width, geometry);
|
|
35
36
|
const pages = (demo?.default ?? []).filter(
|
|
36
37
|
(entry): entry is DocPage => typeof entry === 'function',
|
|
37
38
|
);
|
|
@@ -41,7 +42,7 @@ export function ThemePreview({ theme, width, all = false }: Props) {
|
|
|
41
42
|
return (
|
|
42
43
|
<div
|
|
43
44
|
className="grid place-items-center rounded-md border border-border border-dashed bg-muted text-[11px] text-muted-foreground"
|
|
44
|
-
style={{ width, height:
|
|
45
|
+
style={{ width, height: frameHeight }}
|
|
45
46
|
>
|
|
46
47
|
{theme.hasDemo ? 'Loading…' : 'No demo'}
|
|
47
48
|
</div>
|
|
@@ -54,8 +55,8 @@ export function ThemePreview({ theme, width, all = false }: Props) {
|
|
|
54
55
|
<div
|
|
55
56
|
// biome-ignore lint/suspicious/noArrayIndexKey: page order is the identity
|
|
56
57
|
key={index}
|
|
57
|
-
className="overflow-hidden rounded-md ring-1 ring-border"
|
|
58
|
-
style={{ width, height:
|
|
58
|
+
className="flex items-center justify-center overflow-hidden rounded-md bg-canvas ring-1 ring-border"
|
|
59
|
+
style={{ width, height: frameHeight }}
|
|
59
60
|
>
|
|
60
61
|
<PageFrame
|
|
61
62
|
index={index}
|
|
@@ -4,6 +4,7 @@ import { buildDocDocx } from './export-docx';
|
|
|
4
4
|
import { buildDocHtmlBundle } from './export-html';
|
|
5
5
|
import { mountPrintCopy, type PrintCopy } from './export-pdf';
|
|
6
6
|
import { exposeOutline } from './outline';
|
|
7
|
+
import { recordFileName, setRecordIndex } from './records';
|
|
7
8
|
import type { DocModule, PageGeometry } from './sdk';
|
|
8
9
|
import type { ExpandedPage } from './use-doc-pages';
|
|
9
10
|
|
|
@@ -16,6 +17,10 @@ export type BridgeStatus = {
|
|
|
16
17
|
ready: boolean;
|
|
17
18
|
pageCount: number;
|
|
18
19
|
geometry: PageGeometry;
|
|
20
|
+
/** Rows the document prints one copy for (`records`); 0 when it has none. */
|
|
21
|
+
records: number;
|
|
22
|
+
/** The row the pages are laid out for right now, 0-based. */
|
|
23
|
+
record: number;
|
|
19
24
|
};
|
|
20
25
|
|
|
21
26
|
export type BridgeReport = BridgeStatus & { findings: LayoutFinding[] };
|
|
@@ -32,6 +37,12 @@ export type OpenDocBridge = {
|
|
|
32
37
|
releasePrint(): void;
|
|
33
38
|
htmlBundle(): Promise<BridgeBundle | null>;
|
|
34
39
|
docxBundle(): Promise<BridgeBundle | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Lays the document out for one row and names its file — from `pattern`,
|
|
42
|
+
* else `meta.recordName`, else `<id>-{#}`. Wait for `status()` to report
|
|
43
|
+
* that row and `ready` before printing.
|
|
44
|
+
*/
|
|
45
|
+
setRecord(index: number, pattern?: string): { name: string };
|
|
35
46
|
};
|
|
36
47
|
|
|
37
48
|
type BridgeInput = {
|
|
@@ -41,6 +52,8 @@ type BridgeInput = {
|
|
|
41
52
|
geometry: PageGeometry;
|
|
42
53
|
measuring: boolean;
|
|
43
54
|
oversized: Array<{ section: number; block: number }>;
|
|
55
|
+
/** The row this render is laid out for — read from the render, never the store, so `ready` and the row agree. */
|
|
56
|
+
record: number;
|
|
44
57
|
};
|
|
45
58
|
|
|
46
59
|
type GlobalWithBridge = typeof globalThis & { [BRIDGE_KEY]?: OpenDocBridge };
|
|
@@ -70,13 +83,15 @@ export function useAgentBridge(input: BridgeInput): void {
|
|
|
70
83
|
let held: PrintCopy | null = null;
|
|
71
84
|
|
|
72
85
|
const status = (): BridgeStatus => {
|
|
73
|
-
const { docId, doc, pages, geometry, measuring } = latest.current;
|
|
86
|
+
const { docId, doc, pages, geometry, measuring, record } = latest.current;
|
|
74
87
|
return {
|
|
75
88
|
docId,
|
|
76
89
|
title: doc?.meta?.title ?? docId,
|
|
77
90
|
ready: doc !== null && !measuring && pages.length > 0,
|
|
78
91
|
pageCount: pages.length,
|
|
79
92
|
geometry,
|
|
93
|
+
records: doc?.records?.length ?? 0,
|
|
94
|
+
record,
|
|
80
95
|
};
|
|
81
96
|
};
|
|
82
97
|
|
|
@@ -126,6 +141,19 @@ export function useAgentBridge(input: BridgeInput): void {
|
|
|
126
141
|
base64: toBase64(bundle.bytes),
|
|
127
142
|
};
|
|
128
143
|
},
|
|
144
|
+
setRecord(index, pattern) {
|
|
145
|
+
const { docId, doc } = latest.current;
|
|
146
|
+
const records = doc?.records ?? [];
|
|
147
|
+
setRecordIndex(index);
|
|
148
|
+
return {
|
|
149
|
+
name: recordFileName(
|
|
150
|
+
pattern ?? doc?.meta?.recordName ?? `${docId}-{#}`,
|
|
151
|
+
records[index],
|
|
152
|
+
index,
|
|
153
|
+
records.length,
|
|
154
|
+
),
|
|
155
|
+
};
|
|
156
|
+
},
|
|
129
157
|
async docxBundle() {
|
|
130
158
|
const { docId, doc, pages } = latest.current;
|
|
131
159
|
if (!doc || pages.length === 0) return null;
|