@open-document/core 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-BHFGY8eF.js → build-DfUfpeTR.js} +1 -1
- package/dist/{check-UEBmDfT_.js → check-CHxiOkQG.js} +3 -3
- package/dist/cli/bin.js +20 -33
- package/dist/{config-B_pdNbYg.js → config-9IdbhVuT.js} +1402 -675
- package/dist/{context-BM9_-u9P.js → context-BLI1-64_.js} +2 -2
- package/dist/{dev-DX3QMIRi.js → dev-yNYKv5mm.js} +1 -1
- package/dist/{diff-DayvbXfX.js → diff-Bs205mOx.js} +2 -2
- package/dist/{export-BPsXj1i6.js → export-tkquS5O5.js} +11 -4
- package/dist/{import-71wlAsrd.js → import-D1hIKIr3.js} +3 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +63 -28
- package/dist/ops/index.d.ts +111 -2
- package/dist/ops/index.js +3 -3
- package/dist/{ops-BUo67DaP.js → ops-Dgqujq5a.js} +85 -164
- package/dist/package-version-C89gtYSk.js +36 -0
- package/dist/{preview-D3m1-gUL.js → preview-BImdTH6K.js} +1 -1
- package/dist/{sdk-CpDEGRIo.d.ts → sdk-CHEGeINh.d.ts} +46 -1
- package/dist/templates-DT5zzqHq.js +34 -0
- package/dist/vite/index.js +1 -1
- package/package.json +2 -1
- package/skills/apply-comments/SKILL.md +3 -1
- package/skills/create-doc/SKILL.md +2 -0
- package/skills/doc-authoring/SKILL.md +2 -0
- package/src/app/components/browser/browser-ui.tsx +21 -0
- package/src/app/components/browser/new-document-dialog.tsx +208 -0
- package/src/app/components/changes/changes-overlay.tsx +68 -0
- package/src/app/components/changes/changes-panel.tsx +341 -0
- package/src/app/components/changes/use-changes.ts +85 -0
- package/src/app/components/comments/comments-overlay.tsx +50 -0
- package/src/app/components/comments/comments-panel.tsx +272 -0
- package/src/app/components/comments/use-comments.ts +61 -0
- package/src/app/components/doc-sidebar.tsx +32 -2
- package/src/app/components/inspector/field-source.tsx +41 -0
- package/src/app/components/inspector/inspector.tsx +64 -65
- package/src/app/components/overlay-frame.tsx +79 -0
- package/src/app/components/page-frame.tsx +4 -0
- package/src/app/components/page-placement.ts +68 -0
- package/src/app/components/record-picker.tsx +79 -0
- package/src/app/components/themes/theme-preview.tsx +5 -4
- package/src/app/lib/agent-bridge.ts +29 -1
- package/src/app/lib/docx/ooxml.test.ts +24 -1
- package/src/app/lib/docx/ooxml.ts +27 -1
- package/src/app/lib/export-docx.ts +3 -1
- package/src/app/lib/export-dom.ts +2 -1
- package/src/app/lib/export-html.ts +4 -2
- package/src/app/lib/export-image.ts +2 -1
- package/src/app/lib/flow-measure.test.ts +30 -0
- package/src/app/lib/flow-measure.ts +35 -10
- package/src/app/lib/i18n-ja/browser.ts +10 -0
- package/src/app/lib/i18n-ja/doc.ts +4 -0
- package/src/app/lib/i18n-ja/panels.ts +40 -0
- package/src/app/lib/i18n-ko/browser.ts +10 -0
- package/src/app/lib/i18n-ko/doc.ts +4 -0
- package/src/app/lib/i18n-ko/panels.ts +39 -0
- package/src/app/lib/i18n-zh-cn/browser.ts +10 -0
- package/src/app/lib/i18n-zh-cn/doc.ts +4 -0
- package/src/app/lib/i18n-zh-cn/panels.ts +38 -0
- package/src/app/lib/i18n-zh-tw/browser.ts +10 -0
- package/src/app/lib/i18n-zh-tw/doc.ts +4 -0
- package/src/app/lib/i18n-zh-tw/panels.ts +38 -0
- package/src/app/lib/records.test.ts +38 -0
- package/src/app/lib/records.ts +127 -0
- package/src/app/lib/sdk.ts +29 -0
- package/src/app/lib/use-doc-module.ts +7 -0
- package/src/app/lib/use-doc-pages.ts +15 -9
- package/src/app/routes/doc.tsx +274 -13
- package/src/app/routes/home.tsx +30 -5
- package/src/app/styles.css +23 -0
- package/templates/blank/index.tsx +63 -0
- package/templates/blank/template.json +6 -0
- package/templates/certificate/data/recipients.csv +4 -0
- package/templates/certificate/index.tsx +128 -0
- package/templates/certificate/template.json +6 -0
- package/templates/letter/index.tsx +106 -0
- package/templates/letter/template.json +5 -0
- package/templates/meeting-notes/index.tsx +194 -0
- package/templates/meeting-notes/template.json +6 -0
- package/templates/proposal/index.tsx +264 -0
- package/templates/proposal/template.json +6 -0
- package/templates/report/data/metrics.csv +5 -0
- package/templates/report/index.tsx +224 -0
- package/templates/report/template.json +6 -0
|
@@ -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
|
|
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:
|
|
207
|
+
variant: FrameVariant;
|
|
215
208
|
}) {
|
|
216
|
-
|
|
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
|
-
}, [
|
|
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
|
-
:
|
|
1495
|
-
? t('
|
|
1496
|
-
:
|
|
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
|
|
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)}
|
|
@@ -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,6 +11,8 @@ type Props = {
|
|
|
11
11
|
geometry: PageGeometry;
|
|
12
12
|
scale: number;
|
|
13
13
|
design?: DesignSystem;
|
|
14
|
+
/** The document's language — see `pageLang`. */
|
|
15
|
+
lang?: string;
|
|
14
16
|
flat?: boolean;
|
|
15
17
|
className?: string;
|
|
16
18
|
children: ReactNode;
|
|
@@ -27,6 +29,7 @@ export function PageFrame({
|
|
|
27
29
|
geometry,
|
|
28
30
|
scale,
|
|
29
31
|
design,
|
|
32
|
+
lang = 'en',
|
|
30
33
|
flat = false,
|
|
31
34
|
className,
|
|
32
35
|
children,
|
|
@@ -44,6 +47,7 @@ export function PageFrame({
|
|
|
44
47
|
>
|
|
45
48
|
<div
|
|
46
49
|
{...{ [PAGE_ATTR]: '', [PAGE_INDEX_ATTR]: index }}
|
|
50
|
+
lang={lang}
|
|
47
51
|
style={
|
|
48
52
|
{
|
|
49
53
|
width: geometry.width,
|
|
@@ -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;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
buildDocxParts,
|
|
4
|
+
type DocxModel,
|
|
5
|
+
escapeXml,
|
|
6
|
+
fontsFor,
|
|
7
|
+
hexColor,
|
|
8
|
+
wordLang,
|
|
9
|
+
} from './ooxml.ts';
|
|
3
10
|
|
|
4
11
|
describe('fontsFor', () => {
|
|
5
12
|
it('skips system aliases for the first real family', () => {
|
|
@@ -313,3 +320,19 @@ describe('buildDocxParts', () => {
|
|
|
313
320
|
expect(numbering).toContain('<w:num w:numId="2"><w:abstractNumId w:val="1"/><w:lvlOverride');
|
|
314
321
|
});
|
|
315
322
|
});
|
|
323
|
+
|
|
324
|
+
describe('wordLang', () => {
|
|
325
|
+
it('files Chinese, Japanese and Korean as the East Asian language', () => {
|
|
326
|
+
expect(wordLang('zh-Hant-TW')).toBe('<w:lang w:val="en-US" w:eastAsia="zh-TW"/>');
|
|
327
|
+
expect(wordLang('zh-Hans')).toBe('<w:lang w:val="en-US" w:eastAsia="zh-CN"/>');
|
|
328
|
+
expect(wordLang('zh-HK')).toBe('<w:lang w:val="en-US" w:eastAsia="zh-HK"/>');
|
|
329
|
+
expect(wordLang('ja')).toBe('<w:lang w:val="en-US" w:eastAsia="ja-JP"/>');
|
|
330
|
+
expect(wordLang('ko-KR')).toBe('<w:lang w:val="en-US" w:eastAsia="ko-KR"/>');
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('files anything else as the Latin language', () => {
|
|
334
|
+
expect(wordLang()).toBe('<w:lang w:val="en-US"/>');
|
|
335
|
+
expect(wordLang('en-GB')).toBe('<w:lang w:val="en-GB"/>');
|
|
336
|
+
expect(wordLang('de"x')).toBe('<w:lang w:val="dex"/>');
|
|
337
|
+
});
|
|
338
|
+
});
|
|
@@ -169,8 +169,34 @@ export type DocxModel = {
|
|
|
169
169
|
images: ImagePart[];
|
|
170
170
|
/** One entry per list; ordered lists restart at 1 each. */
|
|
171
171
|
lists: Array<'bullet' | 'decimal'>;
|
|
172
|
+
/** The document's language as a BCP 47 tag — see `pageLang`. */
|
|
173
|
+
lang?: string;
|
|
172
174
|
};
|
|
173
175
|
|
|
176
|
+
/**
|
|
177
|
+
* The document's language the way Word files it. Word keeps Latin and East
|
|
178
|
+
* Asian text apart: a Chinese document still has Latin runs, and its
|
|
179
|
+
* proofing, line-breaking (kinsoku) and fallback fonts follow the East Asian
|
|
180
|
+
* language, so that one goes in `eastAsia`.
|
|
181
|
+
*/
|
|
182
|
+
export function wordLang(lang = 'en'): string {
|
|
183
|
+
const tag = lang.toLowerCase();
|
|
184
|
+
const eastAsia = tag.startsWith('zh')
|
|
185
|
+
? /hant|-tw|-hk|-mo/.test(tag)
|
|
186
|
+
? tag.includes('-hk')
|
|
187
|
+
? 'zh-HK'
|
|
188
|
+
: 'zh-TW'
|
|
189
|
+
: 'zh-CN'
|
|
190
|
+
: tag.startsWith('ja')
|
|
191
|
+
? 'ja-JP'
|
|
192
|
+
: tag.startsWith('ko')
|
|
193
|
+
? 'ko-KR'
|
|
194
|
+
: null;
|
|
195
|
+
if (eastAsia) return `<w:lang w:val="en-US" w:eastAsia="${eastAsia}"/>`;
|
|
196
|
+
const latin = tag === 'en' ? 'en-US' : lang.replace(/[^A-Za-z0-9-]/g, '');
|
|
197
|
+
return `<w:lang w:val="${latin}"/>`;
|
|
198
|
+
}
|
|
199
|
+
|
|
174
200
|
export const PX_TO_TWIPS = 15;
|
|
175
201
|
export const PX_TO_EMU = 9525;
|
|
176
202
|
export const PX_TO_HALF_POINTS = 1.5;
|
|
@@ -546,7 +572,7 @@ function stylesXml(model: DocxModel): string {
|
|
|
546
572
|
`<w:style w:type="paragraph" w:styleId="TOC${level}"><w:name w:val="toc ${level}"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/><w:uiPriority w:val="39"/><w:pPr><w:tabs><w:tab w:val="right" w:leader="dot" w:pos="${textWidth}"/></w:tabs><w:spacing w:after="60"/><w:ind w:left="${(level - 1) * 240}"/></w:pPr></w:style>`;
|
|
547
573
|
return (
|
|
548
574
|
`${XML_HEAD}<w:styles ${NS}>` +
|
|
549
|
-
`<w:docDefaults><w:rPrDefault><w:rPr>${fontsXml(fonts.body)}<w:color w:val="${colors.text}"/><w:sz w:val="${sizes.body}"/><w:szCs w:val="${sizes.body}"
|
|
575
|
+
`<w:docDefaults><w:rPrDefault><w:rPr>${fontsXml(fonts.body)}<w:color w:val="${colors.text}"/><w:sz w:val="${sizes.body}"/><w:szCs w:val="${sizes.body}"/>${wordLang(model.lang)}</w:rPr></w:rPrDefault>` +
|
|
550
576
|
`<w:pPrDefault><w:pPr><w:spacing w:after="160" w:line="${Math.round(model.line)}" w:lineRule="atLeast"/></w:pPr></w:pPrDefault></w:docDefaults>` +
|
|
551
577
|
'<w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/><w:qFormat/></w:style>' +
|
|
552
578
|
'<w:style w:type="character" w:default="1" w:styleId="DefaultParagraphFont"><w:name w:val="Default Paragraph Font"/><w:uiPriority w:val="1"/><w:semiHidden/></w:style>' +
|
|
@@ -27,7 +27,7 @@ import { downloadBlob, withRenderedPages } from './export-dom';
|
|
|
27
27
|
import { type DocEntry, type FlowSection, isFlowSection } from './flow';
|
|
28
28
|
import { DocPageProvider } from './page-context';
|
|
29
29
|
import { nextFrame, waitForFonts } from './print-ready';
|
|
30
|
-
import { type DocModule, resolvePageGeometry } from './sdk';
|
|
30
|
+
import { type DocModule, pageLang, resolvePageGeometry } from './sdk';
|
|
31
31
|
import type { ExpandedPage } from './use-doc-pages';
|
|
32
32
|
|
|
33
33
|
export type DocxBundle = { filename: string; mimeType: string; bytes: Uint8Array };
|
|
@@ -108,6 +108,7 @@ async function runningLineOf(
|
|
|
108
108
|
host.setAttribute('aria-hidden', 'true');
|
|
109
109
|
// The sheet's base styles (styles.css), so the line reads as it prints.
|
|
110
110
|
host.setAttribute('data-od-measure', '');
|
|
111
|
+
host.setAttribute('lang', pageLang(doc.meta));
|
|
111
112
|
Object.assign(host.style, { position: 'fixed', left: '-99999px', top: '0', width: `${width}px` });
|
|
112
113
|
for (const [name, value] of Object.entries(designToCssVars(design))) {
|
|
113
114
|
host.style.setProperty(name, value);
|
|
@@ -178,6 +179,7 @@ export async function buildDocDocx(
|
|
|
178
179
|
const size = (px: number) => Math.round(px * PX_TO_HALF_POINTS);
|
|
179
180
|
const text = hexColor(design.palette.text) ?? '000000';
|
|
180
181
|
const model: DocxModel = {
|
|
182
|
+
lang: pageLang(doc.meta),
|
|
181
183
|
title: doc.meta?.title ?? docId,
|
|
182
184
|
...(doc.meta?.author ? { author: doc.meta.author } : {}),
|
|
183
185
|
page: {
|