@open-document/core 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-DJMLK50m.js → build-DfUfpeTR.js} +1 -1
- package/dist/{check-CUKuufBm.js → check-CHxiOkQG.js} +3 -3
- package/dist/cli/bin.js +20 -33
- package/dist/{config-CvzpyAUA.js → config-9IdbhVuT.js} +2015 -725
- package/dist/{context-B4ip7SoI.js → context-BLI1-64_.js} +2 -2
- package/dist/{dev-dnH7DTlD.js → dev-yNYKv5mm.js} +1 -1
- package/dist/{diff-QTo0A5Rx.js → diff-Bs205mOx.js} +2 -2
- package/dist/{export-BrRFrexj.js → export-tkquS5O5.js} +11 -4
- package/dist/{import-C14Vn9ER.js → import-D1hIKIr3.js} +3 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +63 -28
- package/dist/ops/index.d.ts +111 -2
- package/dist/ops/index.js +3 -3
- package/dist/{ops-DKidjLXP.js → ops-Dgqujq5a.js} +85 -164
- package/dist/package-version-C89gtYSk.js +36 -0
- package/dist/{preview-wKM4C6Uk.js → preview-BImdTH6K.js} +1 -1
- package/dist/{sdk-CpDEGRIo.d.ts → sdk-CHEGeINh.d.ts} +46 -1
- package/dist/templates-DT5zzqHq.js +34 -0
- package/dist/vite/index.js +1 -1
- package/package.json +2 -1
- package/skills/apply-comments/SKILL.md +3 -1
- package/skills/create-doc/SKILL.md +2 -0
- package/skills/doc-authoring/SKILL.md +2 -0
- package/src/app/components/browser/browser-ui.tsx +21 -0
- package/src/app/components/browser/new-document-dialog.tsx +208 -0
- package/src/app/components/changes/changes-overlay.tsx +68 -0
- package/src/app/components/changes/changes-panel.tsx +341 -0
- package/src/app/components/changes/use-changes.ts +85 -0
- package/src/app/components/comments/comments-overlay.tsx +50 -0
- package/src/app/components/comments/comments-panel.tsx +272 -0
- package/src/app/components/comments/use-comments.ts +61 -0
- package/src/app/components/doc-sidebar.tsx +32 -2
- package/src/app/components/inspector/field-source.tsx +41 -0
- package/src/app/components/inspector/format-section.tsx +434 -0
- package/src/app/components/inspector/inspector.tsx +311 -118
- package/src/app/components/inspector/use-style-edits.ts +210 -0
- package/src/app/components/overlay-frame.tsx +79 -0
- package/src/app/components/page-frame.tsx +4 -0
- package/src/app/components/page-placement.ts +68 -0
- package/src/app/components/panel/fields.tsx +95 -7
- package/src/app/components/record-picker.tsx +79 -0
- package/src/app/components/themes/theme-preview.tsx +5 -4
- package/src/app/lib/agent-bridge.ts +29 -1
- package/src/app/lib/docx/ooxml.test.ts +24 -1
- package/src/app/lib/docx/ooxml.ts +27 -1
- package/src/app/lib/export-docx.ts +3 -1
- package/src/app/lib/export-dom.ts +2 -1
- package/src/app/lib/export-html.ts +4 -2
- package/src/app/lib/export-image.ts +2 -1
- package/src/app/lib/flow-measure.test.ts +30 -0
- package/src/app/lib/flow-measure.ts +35 -10
- package/src/app/lib/i18n-ja/browser.ts +10 -0
- package/src/app/lib/i18n-ja/doc.ts +4 -0
- package/src/app/lib/i18n-ja/panels.ts +92 -5
- package/src/app/lib/i18n-ko/browser.ts +10 -0
- package/src/app/lib/i18n-ko/doc.ts +4 -0
- package/src/app/lib/i18n-ko/panels.ts +90 -5
- package/src/app/lib/i18n-zh-cn/browser.ts +10 -0
- package/src/app/lib/i18n-zh-cn/doc.ts +4 -0
- package/src/app/lib/i18n-zh-cn/panels.ts +88 -5
- package/src/app/lib/i18n-zh-tw/browser.ts +10 -0
- package/src/app/lib/i18n-zh-tw/doc.ts +4 -0
- package/src/app/lib/i18n-zh-tw/panels.ts +88 -5
- package/src/app/lib/inspector/format.ts +156 -0
- package/src/app/lib/records.test.ts +38 -0
- package/src/app/lib/records.ts +127 -0
- package/src/app/lib/sdk.ts +29 -0
- package/src/app/lib/use-doc-module.ts +7 -0
- package/src/app/lib/use-doc-pages.ts +15 -9
- package/src/app/routes/doc.tsx +274 -11
- package/src/app/routes/home.tsx +30 -5
- package/src/app/styles.css +23 -0
- package/templates/blank/index.tsx +63 -0
- package/templates/blank/template.json +6 -0
- package/templates/certificate/data/recipients.csv +4 -0
- package/templates/certificate/index.tsx +128 -0
- package/templates/certificate/template.json +6 -0
- package/templates/letter/index.tsx +106 -0
- package/templates/letter/template.json +5 -0
- package/templates/meeting-notes/index.tsx +194 -0
- package/templates/meeting-notes/template.json +6 -0
- package/templates/proposal/index.tsx +264 -0
- package/templates/proposal/template.json +6 -0
- package/templates/report/data/metrics.csv +5 -0
- package/templates/report/index.tsx +224 -0
- package/templates/report/template.json +6 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
cssName,
|
|
4
|
+
cssValue,
|
|
5
|
+
type StyleChanges,
|
|
6
|
+
type StyleOrigin,
|
|
7
|
+
type StyleProp,
|
|
8
|
+
type StyleValue,
|
|
9
|
+
} from '../../lib/inspector/format';
|
|
10
|
+
import { PROP_ATTR } from '../../lib/source-loc';
|
|
11
|
+
import { useHistory } from '../history-provider';
|
|
12
|
+
|
|
13
|
+
const LOC_ATTR = 'data-od-loc';
|
|
14
|
+
|
|
15
|
+
export type StyleTarget = { line: number; column: number; tag: string };
|
|
16
|
+
|
|
17
|
+
/** A style edit waiting for Save, plus what the panel was shown when it began. */
|
|
18
|
+
export type PendingStyle = StyleTarget & {
|
|
19
|
+
changes: StyleChanges;
|
|
20
|
+
expected: Partial<Record<StyleProp, StyleOrigin | null>>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type Original = { value: string; priority: string };
|
|
24
|
+
|
|
25
|
+
export const styleKey = (target: StyleTarget) => `${target.line}:${target.column}`;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Every element printed by one source location — a `.map()` or a flow block
|
|
29
|
+
* split across pages prints the same JSX more than once, and a source edit
|
|
30
|
+
* changes them all, so the preview has to as well.
|
|
31
|
+
*/
|
|
32
|
+
export function elementsAt(root: ParentNode, target: StyleTarget): HTMLElement[] {
|
|
33
|
+
return [
|
|
34
|
+
...root.querySelectorAll<HTMLElement>(
|
|
35
|
+
`[${LOC_ATTR}="${styleKey(target)}"]:not([${PROP_ATTR}])`,
|
|
36
|
+
),
|
|
37
|
+
].filter((el) => el.tagName.toLowerCase() === target.tag);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Style changes from the element panel, shown on the page before they are
|
|
42
|
+
* written. A change is set on the elements' inline style, over whatever React
|
|
43
|
+
* rendered there, and every value it covered is kept so Discard can put it
|
|
44
|
+
* back. The edits themselves live in a ref, keyed by source location, so a
|
|
45
|
+
* hot reload that replaces the elements can lay them on the new ones.
|
|
46
|
+
*/
|
|
47
|
+
export function useStyleEdits(container: HTMLElement | null) {
|
|
48
|
+
const history = useHistory();
|
|
49
|
+
const editsRef = useRef(new Map<string, PendingStyle>());
|
|
50
|
+
const originalsRef = useRef(new Map<HTMLElement, Map<string, Original>>());
|
|
51
|
+
const [version, setVersion] = useState(0);
|
|
52
|
+
const bump = useCallback(() => setVersion((v) => v + 1), []);
|
|
53
|
+
|
|
54
|
+
const restore = useCallback((el: HTMLElement, names?: Set<string>) => {
|
|
55
|
+
const saved = originalsRef.current.get(el);
|
|
56
|
+
if (!saved) return;
|
|
57
|
+
for (const [name, original] of saved) {
|
|
58
|
+
if (names && !names.has(name)) continue;
|
|
59
|
+
if (original.value === '') el.style.removeProperty(name);
|
|
60
|
+
else el.style.setProperty(name, original.value, original.priority);
|
|
61
|
+
saved.delete(name);
|
|
62
|
+
}
|
|
63
|
+
if (saved.size === 0) originalsRef.current.delete(el);
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
const paint = useCallback(
|
|
67
|
+
(edit: PendingStyle) => {
|
|
68
|
+
if (!container) return;
|
|
69
|
+
for (const el of elementsAt(container, edit)) {
|
|
70
|
+
let saved = originalsRef.current.get(el);
|
|
71
|
+
if (!saved) {
|
|
72
|
+
saved = new Map();
|
|
73
|
+
originalsRef.current.set(el, saved);
|
|
74
|
+
}
|
|
75
|
+
const wanted = new Set<string>();
|
|
76
|
+
for (const [prop, value] of Object.entries(edit.changes) as Array<
|
|
77
|
+
[StyleProp, StyleValue]
|
|
78
|
+
>) {
|
|
79
|
+
const name = cssName(prop);
|
|
80
|
+
wanted.add(name);
|
|
81
|
+
if (!saved.has(name)) {
|
|
82
|
+
saved.set(name, {
|
|
83
|
+
value: el.style.getPropertyValue(name),
|
|
84
|
+
priority: el.style.getPropertyPriority(name),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (value === null) el.style.removeProperty(name);
|
|
88
|
+
else el.style.setProperty(name, cssValue(prop, value));
|
|
89
|
+
}
|
|
90
|
+
const stale = new Set([...saved.keys()].filter((name) => !wanted.has(name)));
|
|
91
|
+
if (stale.size > 0) restore(el, stale);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
[container, restore],
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
/** Replaces a location's pending changes wholesale — the one way in, for edits and undo alike. */
|
|
98
|
+
const put = useCallback(
|
|
99
|
+
(key: string, next: PendingStyle | null) => {
|
|
100
|
+
const prev = editsRef.current.get(key);
|
|
101
|
+
if (next && Object.keys(next.changes).length > 0) {
|
|
102
|
+
editsRef.current.set(key, next);
|
|
103
|
+
paint(next);
|
|
104
|
+
} else {
|
|
105
|
+
editsRef.current.delete(key);
|
|
106
|
+
if (prev && container) for (const el of elementsAt(container, prev)) restore(el);
|
|
107
|
+
}
|
|
108
|
+
bump();
|
|
109
|
+
},
|
|
110
|
+
[paint, restore, container, bump],
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const change = useCallback(
|
|
114
|
+
/** `undefined` takes back an unsaved change; `null` takes the key off in source. */
|
|
115
|
+
(
|
|
116
|
+
target: StyleTarget,
|
|
117
|
+
prop: StyleProp,
|
|
118
|
+
value: StyleValue | undefined,
|
|
119
|
+
shown: StyleOrigin | null,
|
|
120
|
+
) => {
|
|
121
|
+
const key = styleKey(target);
|
|
122
|
+
const prev = editsRef.current.get(key) ?? null;
|
|
123
|
+
const base: PendingStyle = prev ?? { ...target, changes: {}, expected: {} };
|
|
124
|
+
const changes = { ...base.changes };
|
|
125
|
+
const expected = { ...base.expected };
|
|
126
|
+
if (value === undefined) {
|
|
127
|
+
delete changes[prop];
|
|
128
|
+
delete expected[prop];
|
|
129
|
+
} else {
|
|
130
|
+
changes[prop] = value;
|
|
131
|
+
if (!(prop in expected)) expected[prop] = shown;
|
|
132
|
+
}
|
|
133
|
+
const next: PendingStyle = { ...base, changes, expected };
|
|
134
|
+
put(key, next);
|
|
135
|
+
history.record({
|
|
136
|
+
coalesceKey: `style:${key}:${prop}`,
|
|
137
|
+
undo: () => put(key, prev),
|
|
138
|
+
redo: () => put(key, next),
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
[put, history],
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const pendingFor = useCallback(
|
|
145
|
+
(target: StyleTarget | null): StyleChanges =>
|
|
146
|
+
(target && editsRef.current.get(styleKey(target))?.changes) || {},
|
|
147
|
+
[],
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const discard = useCallback(() => {
|
|
151
|
+
for (const key of [...editsRef.current.keys()]) put(key, null);
|
|
152
|
+
}, [put]);
|
|
153
|
+
|
|
154
|
+
/** Lets go of saved locations; the reload that follows renders them from source. */
|
|
155
|
+
const forget = useCallback(
|
|
156
|
+
(keys: string[]) => {
|
|
157
|
+
for (const key of keys) {
|
|
158
|
+
editsRef.current.delete(key);
|
|
159
|
+
}
|
|
160
|
+
for (const [el] of originalsRef.current) {
|
|
161
|
+
if (keys.includes(el.getAttribute(LOC_ATTR) ?? '')) originalsRef.current.delete(el);
|
|
162
|
+
}
|
|
163
|
+
bump();
|
|
164
|
+
},
|
|
165
|
+
[bump],
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
/** After a reload replaced elements, the unsaved changes go onto the new ones. */
|
|
169
|
+
const repaint = useCallback(() => {
|
|
170
|
+
for (const el of [...originalsRef.current.keys()]) {
|
|
171
|
+
if (!el.isConnected) originalsRef.current.delete(el);
|
|
172
|
+
}
|
|
173
|
+
for (const edit of editsRef.current.values()) paint(edit);
|
|
174
|
+
}, [paint]);
|
|
175
|
+
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
const originals = originalsRef.current;
|
|
178
|
+
return () => {
|
|
179
|
+
for (const el of [...originals.keys()]) {
|
|
180
|
+
const saved = originals.get(el);
|
|
181
|
+
if (!saved) continue;
|
|
182
|
+
for (const [name, original] of saved) {
|
|
183
|
+
if (original.value === '') el.style.removeProperty(name);
|
|
184
|
+
else el.style.setProperty(name, original.value, original.priority);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
originals.clear();
|
|
188
|
+
};
|
|
189
|
+
}, []);
|
|
190
|
+
|
|
191
|
+
const edits = useCallback(() => [...editsRef.current.values()], []);
|
|
192
|
+
const revert = useCallback(
|
|
193
|
+
(keys: string[]) => {
|
|
194
|
+
for (const key of keys) put(key, null);
|
|
195
|
+
},
|
|
196
|
+
[put],
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
version,
|
|
201
|
+
count: editsRef.current.size,
|
|
202
|
+
edits,
|
|
203
|
+
change,
|
|
204
|
+
pendingFor,
|
|
205
|
+
discard,
|
|
206
|
+
forget,
|
|
207
|
+
revert,
|
|
208
|
+
repaint,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,15 +1,74 @@
|
|
|
1
|
+
import { ChevronRight } from 'lucide-react';
|
|
1
2
|
import { type ReactNode, useEffect, useId, useState } from 'react';
|
|
2
3
|
import { useT } from '../../lib/i18n';
|
|
3
4
|
|
|
4
|
-
export function Section({
|
|
5
|
+
export function Section({
|
|
6
|
+
title,
|
|
7
|
+
action,
|
|
8
|
+
children,
|
|
9
|
+
}: {
|
|
10
|
+
title: string;
|
|
11
|
+
/** A small control on the title's row, acting on the section as a whole. */
|
|
12
|
+
action?: ReactNode;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}) {
|
|
5
15
|
return (
|
|
6
16
|
<section className="border-border border-b px-3 py-3 last:border-b-0">
|
|
7
|
-
<
|
|
17
|
+
<div className="mb-2 flex min-h-5 items-center justify-between gap-2">
|
|
18
|
+
<h3 className="text-[10px] text-muted-foreground uppercase tracking-wider">{title}</h3>
|
|
19
|
+
{action}
|
|
20
|
+
</div>
|
|
8
21
|
<div className="flex flex-col gap-2">{children}</div>
|
|
9
22
|
</section>
|
|
10
23
|
);
|
|
11
24
|
}
|
|
12
25
|
|
|
26
|
+
/** A section that starts closed: what is there for a second look, below what is used every time. */
|
|
27
|
+
export function CollapsibleSection({
|
|
28
|
+
title,
|
|
29
|
+
summary,
|
|
30
|
+
defaultOpen = false,
|
|
31
|
+
children,
|
|
32
|
+
}: {
|
|
33
|
+
title: string;
|
|
34
|
+
/** Shown beside the title while closed, so the closed row still says something. */
|
|
35
|
+
summary?: ReactNode;
|
|
36
|
+
defaultOpen?: boolean;
|
|
37
|
+
children: ReactNode;
|
|
38
|
+
}) {
|
|
39
|
+
const [open, setOpen] = useState(defaultOpen);
|
|
40
|
+
const id = useId();
|
|
41
|
+
return (
|
|
42
|
+
<section className="border-border border-b last:border-b-0">
|
|
43
|
+
<button
|
|
44
|
+
type="button"
|
|
45
|
+
aria-expanded={open}
|
|
46
|
+
aria-controls={id}
|
|
47
|
+
onClick={() => setOpen((value) => !value)}
|
|
48
|
+
className="flex h-10 w-full items-center gap-2 px-3 text-left transition-colors hover:bg-accent/60 focus-visible:outline-2 focus-visible:outline-foreground/60 focus-visible:-outline-offset-2"
|
|
49
|
+
>
|
|
50
|
+
<h3 className="flex-none text-[10px] text-muted-foreground uppercase tracking-wider">
|
|
51
|
+
{title}
|
|
52
|
+
</h3>
|
|
53
|
+
<span className="min-w-0 flex-1 truncate text-right font-mono text-[10px] text-muted-foreground/80">
|
|
54
|
+
{!open && summary}
|
|
55
|
+
</span>
|
|
56
|
+
<ChevronRight
|
|
57
|
+
aria-hidden
|
|
58
|
+
className={`size-3.5 flex-none text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none ${
|
|
59
|
+
open ? 'rotate-90' : ''
|
|
60
|
+
}`}
|
|
61
|
+
/>
|
|
62
|
+
</button>
|
|
63
|
+
{open && (
|
|
64
|
+
<div id={id} className="flex flex-col gap-2 px-3 pb-3">
|
|
65
|
+
{children}
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
68
|
+
</section>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
13
72
|
export function Field({
|
|
14
73
|
label,
|
|
15
74
|
htmlFor,
|
|
@@ -43,22 +102,31 @@ const HEX6 = /^#[0-9a-fA-F]{6}$/;
|
|
|
43
102
|
export function ColorField({
|
|
44
103
|
label,
|
|
45
104
|
value,
|
|
105
|
+
placeholder,
|
|
106
|
+
trailing,
|
|
46
107
|
onChange,
|
|
47
108
|
}: {
|
|
48
109
|
label: string;
|
|
49
110
|
value: string;
|
|
111
|
+
/** Sits after the hex, inside the row — the token picker in the element panel. */
|
|
112
|
+
trailing?: ReactNode;
|
|
113
|
+
/** Shown for an empty value, which then reads as unset rather than invalid. */
|
|
114
|
+
placeholder?: string;
|
|
50
115
|
onChange: (value: string) => void;
|
|
51
116
|
}) {
|
|
52
117
|
const t = useT();
|
|
53
118
|
const id = useId();
|
|
54
119
|
const [draft, setDraft] = useState(value);
|
|
55
120
|
useEffect(() => setDraft(value), [value]);
|
|
56
|
-
const invalid = !HEX6.test(draft);
|
|
121
|
+
const invalid = !HEX6.test(draft) && !(placeholder !== undefined && draft === value);
|
|
57
122
|
|
|
58
123
|
return (
|
|
59
124
|
<Field label={label} htmlFor={id}>
|
|
60
125
|
<span className="relative inline-flex size-8 flex-none items-center justify-center rounded border border-border has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-foreground/60">
|
|
61
|
-
<span
|
|
126
|
+
<span
|
|
127
|
+
className="size-5 rounded-sm border border-border"
|
|
128
|
+
style={{ background: value || 'transparent' }}
|
|
129
|
+
/>
|
|
62
130
|
<input
|
|
63
131
|
type="color"
|
|
64
132
|
aria-label={t('{label} swatch', { label })}
|
|
@@ -72,6 +140,7 @@ export function ColorField({
|
|
|
72
140
|
type="text"
|
|
73
141
|
spellCheck={false}
|
|
74
142
|
value={draft}
|
|
143
|
+
placeholder={placeholder}
|
|
75
144
|
aria-invalid={invalid}
|
|
76
145
|
onChange={(e) => {
|
|
77
146
|
const next = e.target.value.trim();
|
|
@@ -81,8 +150,9 @@ export function ColorField({
|
|
|
81
150
|
onBlur={() => {
|
|
82
151
|
if (!HEX6.test(draft)) setDraft(value);
|
|
83
152
|
}}
|
|
84
|
-
className={`${INPUT_CLASS} min-w-0 flex-1 font-mono uppercase tabular-nums`}
|
|
153
|
+
className={`${INPUT_CLASS} min-w-0 flex-1 font-mono uppercase tabular-nums placeholder:normal-case`}
|
|
85
154
|
/>
|
|
155
|
+
{trailing}
|
|
86
156
|
</Field>
|
|
87
157
|
);
|
|
88
158
|
}
|
|
@@ -105,6 +175,8 @@ export function NumberField({
|
|
|
105
175
|
max,
|
|
106
176
|
step = 1,
|
|
107
177
|
suffix,
|
|
178
|
+
prefix,
|
|
179
|
+
bare = false,
|
|
108
180
|
onChange,
|
|
109
181
|
}: {
|
|
110
182
|
label: string;
|
|
@@ -113,6 +185,10 @@ export function NumberField({
|
|
|
113
185
|
max: number;
|
|
114
186
|
step?: number;
|
|
115
187
|
suffix?: string;
|
|
188
|
+
/** An icon in front of the number, standing in for a visible label. */
|
|
189
|
+
prefix?: ReactNode;
|
|
190
|
+
/** No frame of its own: the field sits inside a composite control that draws one. */
|
|
191
|
+
bare?: boolean;
|
|
116
192
|
onChange: (value: number) => void;
|
|
117
193
|
}) {
|
|
118
194
|
const [draft, setDraft] = useState(String(value));
|
|
@@ -134,7 +210,15 @@ export function NumberField({
|
|
|
134
210
|
};
|
|
135
211
|
|
|
136
212
|
return (
|
|
137
|
-
<span className=
|
|
213
|
+
<span className={bare ? 'relative min-w-0 flex-1' : 'relative flex-none'}>
|
|
214
|
+
{prefix && (
|
|
215
|
+
<span
|
|
216
|
+
aria-hidden
|
|
217
|
+
className="pointer-events-none absolute top-1/2 left-2 flex -translate-y-1/2 text-muted-foreground"
|
|
218
|
+
>
|
|
219
|
+
{prefix}
|
|
220
|
+
</span>
|
|
221
|
+
)}
|
|
138
222
|
<input
|
|
139
223
|
type="text"
|
|
140
224
|
inputMode="decimal"
|
|
@@ -154,7 +238,11 @@ export function NumberField({
|
|
|
154
238
|
if (next !== value) onChange(next);
|
|
155
239
|
}
|
|
156
240
|
}}
|
|
157
|
-
className={
|
|
241
|
+
className={
|
|
242
|
+
bare
|
|
243
|
+
? `h-8 w-full bg-transparent text-xs outline-none ${prefix ? 'pl-7' : 'pl-2'} ${suffix ? 'pr-7' : 'pr-1'} font-mono tabular-nums`
|
|
244
|
+
: `${INPUT_CLASS} w-16 ${prefix ? 'pl-7' : ''} pr-6 text-right font-mono tabular-nums`
|
|
245
|
+
}
|
|
158
246
|
/>
|
|
159
247
|
{suffix && (
|
|
160
248
|
<span
|
|
@@ -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}
|