@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
|
@@ -2,11 +2,20 @@ import {
|
|
|
2
2
|
Bold,
|
|
3
3
|
Check,
|
|
4
4
|
Code,
|
|
5
|
+
Copy,
|
|
6
|
+
Heading,
|
|
7
|
+
Image,
|
|
5
8
|
Italic,
|
|
6
9
|
Link2,
|
|
7
|
-
|
|
10
|
+
List,
|
|
11
|
+
Lock,
|
|
8
12
|
MessageSquarePlus,
|
|
13
|
+
Pencil,
|
|
14
|
+
Pilcrow,
|
|
9
15
|
RemoveFormatting,
|
|
16
|
+
Square,
|
|
17
|
+
Table,
|
|
18
|
+
Type,
|
|
10
19
|
Unlink,
|
|
11
20
|
X,
|
|
12
21
|
} from 'lucide-react';
|
|
@@ -23,10 +32,12 @@ import { createPortal } from 'react-dom';
|
|
|
23
32
|
import { isSafeHref } from '../../lib/href';
|
|
24
33
|
import { useT } from '../../lib/i18n';
|
|
25
34
|
import { candidateLocs, formatLocs } from '../../lib/inspector/fiber';
|
|
35
|
+
import type { StyleInfo } from '../../lib/inspector/format';
|
|
26
36
|
import {
|
|
27
37
|
cleanRun,
|
|
28
38
|
cleanSegments,
|
|
29
39
|
clearFormatting,
|
|
40
|
+
EDITING_ATTR,
|
|
30
41
|
focusAt,
|
|
31
42
|
hasMark,
|
|
32
43
|
hrefOf,
|
|
@@ -55,7 +66,12 @@ import {
|
|
|
55
66
|
} from '../../lib/inspector/inline-edit';
|
|
56
67
|
import { PROP_ATTR } from '../../lib/source-loc';
|
|
57
68
|
import { useHistory } from '../history-provider';
|
|
69
|
+
import { OverlayFrame } from '../overlay-frame';
|
|
70
|
+
import { CollapsibleSection, Section } from '../panel/fields';
|
|
58
71
|
import { PanelIconButton, PanelShell } from '../panel/panel-shell';
|
|
72
|
+
import { FieldSource } from './field-source';
|
|
73
|
+
import { FormatSection } from './format-section';
|
|
74
|
+
import { elementsAt, styleKey, useStyleEdits } from './use-style-edits';
|
|
59
75
|
|
|
60
76
|
type TextPart =
|
|
61
77
|
| { kind: 'text'; index: number; value: string; formattable?: true; segments?: Segment[] }
|
|
@@ -68,6 +84,8 @@ type ResolvedTarget = {
|
|
|
68
84
|
text: string;
|
|
69
85
|
parts: TextPart[];
|
|
70
86
|
reason?: string;
|
|
87
|
+
/** Values `<Field>` prints from the document's records. */
|
|
88
|
+
fields?: { names: string[]; file: string | null };
|
|
71
89
|
};
|
|
72
90
|
|
|
73
91
|
export const LOC_ATTR = 'data-od-loc';
|
|
@@ -133,10 +151,11 @@ const DOUBLE_CLICK_MS = 600;
|
|
|
133
151
|
// Same visual language as open-slide's inspector: dashed on hover, solid on
|
|
134
152
|
// selection, both in the same blue. Unsaved text keeps a dashed frame after the
|
|
135
153
|
// cursor leaves it, so a change that exists only on screen never looks saved.
|
|
136
|
-
const FRAME_STYLE: Record<'hover' | 'selected' | 'pending', CSSProperties> = {
|
|
154
|
+
const FRAME_STYLE: Record<'hover' | 'selected' | 'pending' | 'twin', CSSProperties> = {
|
|
137
155
|
hover: { outline: '1.5px dashed #3b82f6', background: 'rgba(59,130,246,0.05)' },
|
|
138
156
|
selected: { outline: '2px solid #3b82f6', background: 'rgba(59,130,246,0.1)' },
|
|
139
157
|
pending: { outline: '1.5px dashed #3b82f6', outlineOffset: 2 },
|
|
158
|
+
twin: { outline: '1px solid rgba(59,130,246,0.55)', background: 'rgba(59,130,246,0.05)' },
|
|
140
159
|
};
|
|
141
160
|
|
|
142
161
|
// Past this, a reload that should have replaced a saved element is not coming
|
|
@@ -159,73 +178,35 @@ function targetFrom(el: Element | null): InspectorTarget | null {
|
|
|
159
178
|
return { line, column, anchor: host, tag: host.tagName.toLowerCase(), ...(prop ? { prop } : {}) };
|
|
160
179
|
}
|
|
161
180
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
);
|
|
181
|
+
/** What the panel's header calls the selected element — by role, not by tag. */
|
|
182
|
+
function kindOf(tag: string): { label: string; vars?: Record<string, number>; icon: typeof Type } {
|
|
183
|
+
const level = /^h([1-6])$/.exec(tag)?.[1];
|
|
184
|
+
if (level) return { label: 'Heading {level}', vars: { level: Number(level) }, icon: Heading };
|
|
185
|
+
if (tag === 'p' || tag === 'blockquote') return { label: 'Paragraph', icon: Pilcrow };
|
|
186
|
+
if (tag === 'li' || tag === 'ul' || tag === 'ol') return { label: 'List', icon: List };
|
|
187
|
+
if (tag === 'td' || tag === 'th' || tag === 'table' || tag === 'tr') {
|
|
188
|
+
return { label: 'Table', icon: Table };
|
|
189
|
+
}
|
|
190
|
+
if (tag === 'img' || tag === 'svg' || tag === 'figure') return { label: 'Image', icon: Image };
|
|
191
|
+
if (
|
|
192
|
+
['span', 'strong', 'em', 'b', 'i', 'a', 'code', 'small', 'figcaption', 'label'].includes(tag)
|
|
193
|
+
) {
|
|
194
|
+
return { label: 'Text', icon: Type };
|
|
195
|
+
}
|
|
196
|
+
return { label: 'Box', icon: Square };
|
|
172
197
|
}
|
|
173
198
|
|
|
199
|
+
type FrameVariant = keyof typeof FRAME_STYLE;
|
|
200
|
+
|
|
174
201
|
function Frame({
|
|
175
|
-
anchor,
|
|
176
|
-
container,
|
|
177
202
|
variant,
|
|
203
|
+
...rest
|
|
178
204
|
}: {
|
|
179
205
|
anchor: HTMLElement | null;
|
|
180
206
|
container: HTMLElement;
|
|
181
|
-
variant:
|
|
207
|
+
variant: FrameVariant;
|
|
182
208
|
}) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
// Deliberately no dependency array. Opening a side pane re-zooms and re-centres
|
|
186
|
-
// the pages, which moves the anchor without resizing it — ResizeObserver never
|
|
187
|
-
// sees that, and the zoom lands a frame after the observer would have fired.
|
|
188
|
-
// Measuring after every render is what keeps the frame on its element; the
|
|
189
|
-
// value comparison below stops that from looping.
|
|
190
|
-
useLayoutEffect(() => {
|
|
191
|
-
if (!anchor?.isConnected) {
|
|
192
|
-
setRect(null);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
// The overlay is absolutely positioned inside the scroller, so its origin
|
|
196
|
-
// is the content box — frames live in content coordinates and scroll along
|
|
197
|
-
// with the pages.
|
|
198
|
-
const measure = () => {
|
|
199
|
-
const a = anchor.getBoundingClientRect();
|
|
200
|
-
const c = container.getBoundingClientRect();
|
|
201
|
-
const next = {
|
|
202
|
-
left: a.left - c.left + container.scrollLeft,
|
|
203
|
-
top: a.top - c.top + container.scrollTop,
|
|
204
|
-
width: a.width,
|
|
205
|
-
height: a.height,
|
|
206
|
-
};
|
|
207
|
-
setRect((prev) => (sameRect(prev, next) ? prev : next));
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
measure();
|
|
211
|
-
const ro = new ResizeObserver(measure);
|
|
212
|
-
ro.observe(anchor);
|
|
213
|
-
ro.observe(container);
|
|
214
|
-
container.addEventListener('scroll', measure, { passive: true });
|
|
215
|
-
return () => {
|
|
216
|
-
ro.disconnect();
|
|
217
|
-
container.removeEventListener('scroll', measure);
|
|
218
|
-
};
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
if (!rect) return null;
|
|
222
|
-
return (
|
|
223
|
-
<div
|
|
224
|
-
aria-hidden
|
|
225
|
-
className="pointer-events-none absolute rounded-[2px]"
|
|
226
|
-
style={{ ...rect, ...FRAME_STYLE[variant] }}
|
|
227
|
-
/>
|
|
228
|
-
);
|
|
209
|
+
return <OverlayFrame {...rest} style={FRAME_STYLE[variant]} />;
|
|
229
210
|
}
|
|
230
211
|
|
|
231
212
|
const TOOLBAR_GAP = 6;
|
|
@@ -239,9 +220,9 @@ const TOOL_CLASS =
|
|
|
239
220
|
|
|
240
221
|
/**
|
|
241
222
|
* Inline formatting, floating over the text being edited: emphasis, code,
|
|
242
|
-
* links, and a way to take them off. Size, colour and alignment are
|
|
243
|
-
*
|
|
244
|
-
*
|
|
223
|
+
* links, and a way to take them off. Size, colour and alignment are the
|
|
224
|
+
* element panel's, which offers the document's design tokens before a
|
|
225
|
+
* one-off value — here they would style a few words and quietly fork it.
|
|
245
226
|
*/
|
|
246
227
|
function TextToolbar({
|
|
247
228
|
anchor,
|
|
@@ -532,8 +513,15 @@ type Props = {
|
|
|
532
513
|
docId: string;
|
|
533
514
|
/** The scroll container the pages live in. */
|
|
534
515
|
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
535
|
-
/** The design panel shares the right dock
|
|
516
|
+
/** The design panel shares the right dock; the panel opened last holds it. */
|
|
536
517
|
panelHidden: boolean;
|
|
518
|
+
/** An element was picked on the page — the dock should show its panel. */
|
|
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;
|
|
537
525
|
/** The save card is showing, so the hint underneath it steps aside. */
|
|
538
526
|
quiet: boolean;
|
|
539
527
|
onExit: () => void;
|
|
@@ -547,6 +535,10 @@ export function Inspector({
|
|
|
547
535
|
docId,
|
|
548
536
|
containerRef,
|
|
549
537
|
panelHidden,
|
|
538
|
+
onPick,
|
|
539
|
+
commentFirst = false,
|
|
540
|
+
picking = false,
|
|
541
|
+
onCancelPick,
|
|
550
542
|
quiet,
|
|
551
543
|
onExit,
|
|
552
544
|
exitRef,
|
|
@@ -585,9 +577,25 @@ export function Inspector({
|
|
|
585
577
|
const entriesRef = useRef(new Map<HTMLElement, Entry>());
|
|
586
578
|
const sessionStartRef = useRef<Segment[][]>([]);
|
|
587
579
|
const firstClickRef = useRef<{ anchor: HTMLElement; at: At; time: number } | null>(null);
|
|
580
|
+
const onPickRef = useRef(onPick);
|
|
581
|
+
onPickRef.current = onPick;
|
|
588
582
|
|
|
589
583
|
useLayoutEffect(() => setContainer(containerRef.current), [containerRef]);
|
|
590
584
|
|
|
585
|
+
const {
|
|
586
|
+
count: styleCount,
|
|
587
|
+
edits: styleEdits,
|
|
588
|
+
change: changeStyle,
|
|
589
|
+
pendingFor,
|
|
590
|
+
discard: discardStyles,
|
|
591
|
+
forget: forgetStyles,
|
|
592
|
+
revert: revertStyles,
|
|
593
|
+
repaint: repaintStyles,
|
|
594
|
+
} = useStyleEdits(container);
|
|
595
|
+
const [styleInfo, setStyleInfo] = useState<{ anchor: HTMLElement; value: StyleInfo } | null>(
|
|
596
|
+
null,
|
|
597
|
+
);
|
|
598
|
+
|
|
591
599
|
const insideChrome = useCallback(
|
|
592
600
|
(node: EventTarget | null) =>
|
|
593
601
|
(panelRef.current?.contains(node as Node) ?? false) ||
|
|
@@ -698,10 +706,11 @@ export function Inspector({
|
|
|
698
706
|
|
|
699
707
|
const discard = useCallback(() => {
|
|
700
708
|
for (const entry of [...entriesRef.current.values()]) drop(entry);
|
|
709
|
+
discardStyles();
|
|
701
710
|
setActive(null);
|
|
702
711
|
refresh();
|
|
703
712
|
setStatus(t('Discarded unsaved edits'));
|
|
704
|
-
}, [drop, refresh, t]);
|
|
713
|
+
}, [drop, refresh, discardStyles, t]);
|
|
705
714
|
|
|
706
715
|
/**
|
|
707
716
|
* Leaves the clone in place until hot reload has replaced what it covers —
|
|
@@ -845,23 +854,42 @@ export function Inspector({
|
|
|
845
854
|
owners.push(entry);
|
|
846
855
|
}
|
|
847
856
|
}
|
|
848
|
-
|
|
857
|
+
const styles = styleEdits();
|
|
858
|
+
if (edits.length === 0 && styles.length === 0) return { ok: true };
|
|
849
859
|
|
|
850
860
|
setBusy(true);
|
|
851
861
|
try {
|
|
852
|
-
|
|
862
|
+
// Text and style go in one request, so the file is read, spliced and
|
|
863
|
+
// written once — two requests would each start from the file before
|
|
864
|
+
// the other, and the second would put back what the first changed.
|
|
865
|
+
const res = await fetch('/__edit/batch', {
|
|
853
866
|
method: 'PUT',
|
|
854
867
|
headers: { 'content-type': 'application/json' },
|
|
855
|
-
body: JSON.stringify({
|
|
868
|
+
body: JSON.stringify({
|
|
869
|
+
docId,
|
|
870
|
+
texts: edits,
|
|
871
|
+
styles: styles.map(({ line, column, tag, changes, expected }) => ({
|
|
872
|
+
line,
|
|
873
|
+
column,
|
|
874
|
+
tag,
|
|
875
|
+
changes,
|
|
876
|
+
expected,
|
|
877
|
+
})),
|
|
878
|
+
}),
|
|
856
879
|
});
|
|
857
|
-
const body = (await res.json()) as {
|
|
858
|
-
|
|
880
|
+
const body = (await res.json()) as {
|
|
881
|
+
texts?: Outcome[];
|
|
882
|
+
styles?: Outcome[];
|
|
883
|
+
error?: string;
|
|
884
|
+
};
|
|
885
|
+
if (!res.ok || !body.texts || !body.styles) {
|
|
859
886
|
const error = body.error ?? t('Save failed');
|
|
860
887
|
setStatus(error);
|
|
861
888
|
return { ok: false, error };
|
|
862
889
|
}
|
|
863
|
-
const results = body.
|
|
864
|
-
const
|
|
890
|
+
const results = body.texts;
|
|
891
|
+
const styleResults = body.styles;
|
|
892
|
+
const failures = [...results, ...styleResults].filter(
|
|
865
893
|
(result): result is Extract<Outcome, { ok: false }> => !result.ok,
|
|
866
894
|
);
|
|
867
895
|
for (const entry of new Set(owners)) {
|
|
@@ -869,6 +897,9 @@ export function Inspector({
|
|
|
869
897
|
if (wrote) settle(entry);
|
|
870
898
|
else drop(entry);
|
|
871
899
|
}
|
|
900
|
+
const keys = styles.map(styleKey);
|
|
901
|
+
forgetStyles(keys.filter((_, at) => styleResults[at]?.ok));
|
|
902
|
+
revertStyles(keys.filter((_, at) => !styleResults[at]?.ok));
|
|
872
903
|
refresh();
|
|
873
904
|
setSelected(null);
|
|
874
905
|
if (failures.length === 0) {
|
|
@@ -877,7 +908,7 @@ export function Inspector({
|
|
|
877
908
|
}
|
|
878
909
|
const error = t('{failed} of {total} not saved — {reason}', {
|
|
879
910
|
failed: failures.length,
|
|
880
|
-
total: edits.length,
|
|
911
|
+
total: edits.length + styles.length,
|
|
881
912
|
reason: failures[0]?.error ?? t('refused'),
|
|
882
913
|
});
|
|
883
914
|
setStatus(error);
|
|
@@ -888,7 +919,7 @@ export function Inspector({
|
|
|
888
919
|
} finally {
|
|
889
920
|
setBusy(false);
|
|
890
921
|
}
|
|
891
|
-
}, [active, docId, drop, finish, refresh, settle, t]);
|
|
922
|
+
}, [active, docId, drop, finish, refresh, settle, styleEdits, forgetStyles, revertStyles, t]);
|
|
892
923
|
|
|
893
924
|
const leave = useCallback(async () => {
|
|
894
925
|
if ((await save()).ok) onExit();
|
|
@@ -903,9 +934,10 @@ export function Inspector({
|
|
|
903
934
|
};
|
|
904
935
|
}, [exitRef, leave, controlsRef, save, discard]);
|
|
905
936
|
|
|
937
|
+
const pendingCount = pending.length + styleCount;
|
|
906
938
|
useEffect(() => {
|
|
907
|
-
onPendingChange(
|
|
908
|
-
}, [
|
|
939
|
+
onPendingChange(pendingCount);
|
|
940
|
+
}, [pendingCount, onPendingChange]);
|
|
909
941
|
useEffect(() => () => onPendingChange(0), [onPendingChange]);
|
|
910
942
|
|
|
911
943
|
// Leaving edit mode any other way — a route change, closing the tab — drops
|
|
@@ -919,11 +951,11 @@ export function Inspector({
|
|
|
919
951
|
}, []);
|
|
920
952
|
|
|
921
953
|
useEffect(() => {
|
|
922
|
-
if (
|
|
954
|
+
if (pendingCount === 0) return;
|
|
923
955
|
const onBeforeUnload = (e: BeforeUnloadEvent) => e.preventDefault();
|
|
924
956
|
window.addEventListener('beforeunload', onBeforeUnload);
|
|
925
957
|
return () => window.removeEventListener('beforeunload', onBeforeUnload);
|
|
926
|
-
}, [
|
|
958
|
+
}, [pendingCount]);
|
|
927
959
|
|
|
928
960
|
// An external write — an agent, the design panel, another save — reloads the
|
|
929
961
|
// document and replaces elements, clones and all. When the element at the
|
|
@@ -986,6 +1018,7 @@ export function Inspector({
|
|
|
986
1018
|
}
|
|
987
1019
|
}
|
|
988
1020
|
if (replaced) refresh();
|
|
1021
|
+
repaintStyles();
|
|
989
1022
|
if (lost > 0) {
|
|
990
1023
|
setStatus(
|
|
991
1024
|
lost > 1
|
|
@@ -1019,7 +1052,7 @@ export function Inspector({
|
|
|
1019
1052
|
});
|
|
1020
1053
|
observer.observe(container, { childList: true, subtree: true });
|
|
1021
1054
|
return () => observer.disconnect();
|
|
1022
|
-
}, [container, refresh, t]);
|
|
1055
|
+
}, [container, refresh, repaintStyles, t]);
|
|
1023
1056
|
|
|
1024
1057
|
useEffect(() => {
|
|
1025
1058
|
if (!container) return;
|
|
@@ -1036,6 +1069,7 @@ export function Inspector({
|
|
|
1036
1069
|
if (entry) {
|
|
1037
1070
|
const owner = targetFrom(entry.anchor);
|
|
1038
1071
|
if (owner) setSelected((prev) => (prev?.anchor === owner.anchor ? prev : owner));
|
|
1072
|
+
onPickRef.current();
|
|
1039
1073
|
if (active !== entry) {
|
|
1040
1074
|
begin(entry.anchor, atIn(entry.editor.clone, e.clientX, e.clientY), false);
|
|
1041
1075
|
}
|
|
@@ -1063,6 +1097,7 @@ export function Inspector({
|
|
|
1063
1097
|
target.anchor.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
1064
1098
|
}
|
|
1065
1099
|
setSelected((prev) => (prev?.anchor === target.anchor ? prev : target));
|
|
1100
|
+
onPickRef.current();
|
|
1066
1101
|
setStatus(null);
|
|
1067
1102
|
setNote('');
|
|
1068
1103
|
};
|
|
@@ -1084,6 +1119,7 @@ export function Inspector({
|
|
|
1084
1119
|
if (!target?.anchor.contains(e.target as Node)) return;
|
|
1085
1120
|
e.preventDefault();
|
|
1086
1121
|
setSelected((prev) => (prev?.anchor === target.anchor ? prev : target));
|
|
1122
|
+
onPickRef.current();
|
|
1087
1123
|
setWantEdit({
|
|
1088
1124
|
anchor: target.anchor,
|
|
1089
1125
|
at: atIn(target.anchor, e.clientX, e.clientY),
|
|
@@ -1106,6 +1142,10 @@ export function Inspector({
|
|
|
1106
1142
|
finish(active, true);
|
|
1107
1143
|
return;
|
|
1108
1144
|
}
|
|
1145
|
+
if (picking && onCancelPick) {
|
|
1146
|
+
onCancelPick();
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1109
1149
|
if (selected) {
|
|
1110
1150
|
setSelected(null);
|
|
1111
1151
|
return;
|
|
@@ -1136,7 +1176,27 @@ export function Inspector({
|
|
|
1136
1176
|
window.removeEventListener('pointerdown', onPointerDown, true);
|
|
1137
1177
|
window.removeEventListener('keydown', onKey, true);
|
|
1138
1178
|
};
|
|
1139
|
-
}, [
|
|
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]);
|
|
1140
1200
|
|
|
1141
1201
|
// Typing is applied by hand to the run under the caret — see inline-edit.ts
|
|
1142
1202
|
// for why the browser is not allowed to. IME composition is the exception:
|
|
@@ -1314,6 +1374,40 @@ export function Inspector({
|
|
|
1314
1374
|
};
|
|
1315
1375
|
}, [selected, docId, t]);
|
|
1316
1376
|
|
|
1377
|
+
// The Format section reads the element's own `style` from source: the page
|
|
1378
|
+
// shows the value, only source can say whether it is a token, a shared
|
|
1379
|
+
// style object's, or code.
|
|
1380
|
+
useEffect(() => {
|
|
1381
|
+
if (!selected) return;
|
|
1382
|
+
let cancelled = false;
|
|
1383
|
+
const params = new URLSearchParams({
|
|
1384
|
+
docId,
|
|
1385
|
+
line: String(selected.line),
|
|
1386
|
+
column: String(selected.column),
|
|
1387
|
+
tag: selected.tag,
|
|
1388
|
+
});
|
|
1389
|
+
fetch(`/__edit/style?${params}`)
|
|
1390
|
+
.then((res) => res.json())
|
|
1391
|
+
.then((body: StyleInfo & { error?: string }) => {
|
|
1392
|
+
if (cancelled) return;
|
|
1393
|
+
setStyleInfo({
|
|
1394
|
+
anchor: selected.anchor,
|
|
1395
|
+
value: body.error ? { editable: false, reason: body.error } : body,
|
|
1396
|
+
});
|
|
1397
|
+
})
|
|
1398
|
+
.catch(() => {
|
|
1399
|
+
if (!cancelled) {
|
|
1400
|
+
setStyleInfo({
|
|
1401
|
+
anchor: selected.anchor,
|
|
1402
|
+
value: { editable: false, reason: 'could not read source' },
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
return () => {
|
|
1407
|
+
cancelled = true;
|
|
1408
|
+
};
|
|
1409
|
+
}, [selected, docId]);
|
|
1410
|
+
|
|
1317
1411
|
useEffect(() => {
|
|
1318
1412
|
if (!wantEdit || !target || selected?.anchor !== wantEdit.anchor) return;
|
|
1319
1413
|
setWantEdit(null);
|
|
@@ -1351,14 +1445,39 @@ export function Inspector({
|
|
|
1351
1445
|
}
|
|
1352
1446
|
};
|
|
1353
1447
|
|
|
1448
|
+
const kind = kindOf(selected?.tag ?? '');
|
|
1449
|
+
const editingHere = active !== null && active.anchor === selected?.anchor;
|
|
1450
|
+
const startEdit = () => {
|
|
1451
|
+
if (!selected) return;
|
|
1452
|
+
if (entriesRef.current.has(selected.anchor)) begin(selected.anchor, null, false);
|
|
1453
|
+
else setWantEdit({ anchor: selected.anchor, at: null, selectWord: false });
|
|
1454
|
+
};
|
|
1455
|
+
// Every other element the selected one's source prints — a `.map()` row, a
|
|
1456
|
+
// block split across pages. A style change lands on all of them, so the
|
|
1457
|
+
// page shows them before it happens rather than the panel saying so.
|
|
1458
|
+
const twins =
|
|
1459
|
+
container && selected
|
|
1460
|
+
? elementsAt(container, selected).filter(
|
|
1461
|
+
(el) => el !== selected.anchor && !el.hasAttribute(EDITING_ATTR),
|
|
1462
|
+
)
|
|
1463
|
+
: [];
|
|
1464
|
+
const KindIcon = kind.icon;
|
|
1465
|
+
const loc = selected
|
|
1466
|
+
? `${target?.line ?? selected.line}:${target?.column ?? selected.column}`
|
|
1467
|
+
: '';
|
|
1468
|
+
|
|
1354
1469
|
const visible = (anchor: HTMLElement | null | undefined) =>
|
|
1355
1470
|
anchor ? (entriesRef.current.get(anchor)?.editor.clone ?? anchor) : null;
|
|
1356
1471
|
const selectedEl = visible(selected?.anchor);
|
|
1357
1472
|
const hint = active
|
|
1358
1473
|
? t('Enter to keep · Shift+Enter for a new line · Esc to revert')
|
|
1359
|
-
:
|
|
1360
|
-
? t('
|
|
1361
|
-
:
|
|
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');
|
|
1362
1481
|
|
|
1363
1482
|
const overlay = container
|
|
1364
1483
|
? createPortal(
|
|
@@ -1379,6 +1498,10 @@ export function Inspector({
|
|
|
1379
1498
|
container={container}
|
|
1380
1499
|
variant="hover"
|
|
1381
1500
|
/>
|
|
1501
|
+
{twins.map((twin, at) => (
|
|
1502
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: twins share one loc; order is stable
|
|
1503
|
+
<Frame key={at} anchor={twin} container={container} variant="twin" />
|
|
1504
|
+
))}
|
|
1382
1505
|
<Frame anchor={selectedEl} container={container} variant="selected" />
|
|
1383
1506
|
</div>
|
|
1384
1507
|
{/* Only while there is something to act on: a row of disabled
|
|
@@ -1416,10 +1539,20 @@ export function Inspector({
|
|
|
1416
1539
|
label={t('Element')}
|
|
1417
1540
|
panelRef={panelRef}
|
|
1418
1541
|
header={
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1542
|
+
<>
|
|
1543
|
+
<KindIcon aria-hidden className="size-3.5 flex-none text-muted-foreground" />
|
|
1544
|
+
<span className="truncate font-medium text-xs">{t(kind.label, kind.vars)}</span>
|
|
1545
|
+
{twins.length > 0 && (
|
|
1546
|
+
<span
|
|
1547
|
+
title={t('{count} elements print from this line of source', {
|
|
1548
|
+
count: twins.length + 1,
|
|
1549
|
+
})}
|
|
1550
|
+
className="flex flex-none items-center gap-1 rounded bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground"
|
|
1551
|
+
>
|
|
1552
|
+
<Copy aria-hidden className="size-3" />×{twins.length + 1}
|
|
1553
|
+
</span>
|
|
1554
|
+
)}
|
|
1555
|
+
</>
|
|
1423
1556
|
}
|
|
1424
1557
|
actions={
|
|
1425
1558
|
<PanelIconButton label={t('Close')} onClick={() => setSelected(null)}>
|
|
@@ -1427,36 +1560,90 @@ export function Inspector({
|
|
|
1427
1560
|
</PanelIconButton>
|
|
1428
1561
|
}
|
|
1429
1562
|
>
|
|
1430
|
-
<
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1563
|
+
<FormatSection
|
|
1564
|
+
// A new element is a new set of fields: a half-typed number must
|
|
1565
|
+
// not commit onto whatever is selected next.
|
|
1566
|
+
key={`${selected.line}:${selected.column}`}
|
|
1567
|
+
anchor={selected.anchor}
|
|
1568
|
+
info={styleInfo?.anchor === selected.anchor ? styleInfo.value : null}
|
|
1569
|
+
pending={pendingFor(selected)}
|
|
1570
|
+
onChange={(prop, value, shown) => changeStyle(selected, prop, value, shown)}
|
|
1571
|
+
/>
|
|
1572
|
+
<Section
|
|
1573
|
+
title={t('Text')}
|
|
1574
|
+
action={
|
|
1575
|
+
editingHere ? (
|
|
1576
|
+
<PanelIconButton label={t('Done')} onClick={() => active && finish(active, false)}>
|
|
1577
|
+
<Check className="size-3.5" />
|
|
1578
|
+
</PanelIconButton>
|
|
1579
|
+
) : null
|
|
1580
|
+
}
|
|
1581
|
+
>
|
|
1434
1582
|
{target === null ? (
|
|
1435
|
-
<div className="
|
|
1436
|
-
<
|
|
1583
|
+
<div className="h-0.5 overflow-hidden rounded bg-muted">
|
|
1584
|
+
<div className="h-full w-1/3 animate-pulse bg-foreground/20" />
|
|
1437
1585
|
</div>
|
|
1438
|
-
) : target.editable ? (
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
'Editing on the page. Enter keeps the change, Shift+Enter starts a new line, Esc reverts it.',
|
|
1443
|
-
)
|
|
1444
|
-
: t(
|
|
1445
|
-
'Double-click the text on the page, or press Enter, to edit it where it is printed.',
|
|
1446
|
-
)}
|
|
1447
|
-
{target.parts.some((part) => part.kind === 'markup') &&
|
|
1448
|
-
` ${t('Inline markup stays as written.')}`}
|
|
1449
|
-
</p>
|
|
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} />
|
|
1450
1590
|
) : (
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1591
|
+
// The words themselves, as the way in: clicking them opens them
|
|
1592
|
+
// on the page. Markup the editor leaves alone reads as a chip.
|
|
1593
|
+
<button
|
|
1594
|
+
type="button"
|
|
1595
|
+
disabled={!target.editable}
|
|
1596
|
+
aria-pressed={editingHere}
|
|
1597
|
+
aria-label={target.editable ? t('Edit on page') : undefined}
|
|
1598
|
+
title={
|
|
1599
|
+
target.editable
|
|
1600
|
+
? `${t('Edit on page')} (Enter)`
|
|
1601
|
+
: target.reason
|
|
1602
|
+
? t(target.reason)
|
|
1603
|
+
: t('Not editable here.')
|
|
1604
|
+
}
|
|
1605
|
+
onClick={startEdit}
|
|
1606
|
+
className="group relative block max-h-28 w-full overflow-hidden rounded border border-border px-2 py-1.5 pr-7 text-left text-xs leading-relaxed transition-colors hover:border-foreground/40 focus-visible:outline-2 focus-visible:outline-foreground/60 disabled:cursor-not-allowed disabled:text-muted-foreground disabled:hover:border-border aria-pressed:border-foreground/60 aria-pressed:bg-accent/50"
|
|
1607
|
+
>
|
|
1608
|
+
{editingHere && active
|
|
1609
|
+
? shownText(active.editor.clone)
|
|
1610
|
+
: target.parts.map((part, at) =>
|
|
1611
|
+
part.kind === 'text' ? (
|
|
1612
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: parts are positional
|
|
1613
|
+
<span key={at}>{part.value}</span>
|
|
1614
|
+
) : (
|
|
1615
|
+
<span
|
|
1616
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: parts are positional
|
|
1617
|
+
key={at}
|
|
1618
|
+
className="mx-0.5 rounded bg-muted px-1 font-mono text-[10px] text-muted-foreground"
|
|
1619
|
+
>
|
|
1620
|
+
{part.label}
|
|
1621
|
+
</span>
|
|
1622
|
+
),
|
|
1623
|
+
)}
|
|
1624
|
+
<span
|
|
1625
|
+
aria-hidden
|
|
1626
|
+
className="absolute top-1.5 right-1.5 flex text-muted-foreground opacity-60 transition-opacity group-hover:opacity-100 group-disabled:opacity-60"
|
|
1627
|
+
>
|
|
1628
|
+
{target.editable ? <Pencil className="size-3" /> : <Lock className="size-3" />}
|
|
1629
|
+
</span>
|
|
1630
|
+
</button>
|
|
1454
1631
|
)}
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1632
|
+
{target?.fields && target.editable && (
|
|
1633
|
+
<FieldSource names={target.fields.names} file={target.fields.file} />
|
|
1634
|
+
)}
|
|
1635
|
+
</Section>
|
|
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
|
+
>
|
|
1459
1643
|
<textarea
|
|
1644
|
+
// biome-ignore lint/a11y/noAutofocus: the reader asked to comment and then picked this element
|
|
1645
|
+
autoFocus={commentFirst}
|
|
1646
|
+
aria-label={t('Comment for the agent')}
|
|
1460
1647
|
value={note}
|
|
1461
1648
|
onChange={(e) => setNote(e.target.value)}
|
|
1462
1649
|
onKeyDown={(e) => {
|
|
@@ -1464,20 +1651,26 @@ export function Inspector({
|
|
|
1464
1651
|
}}
|
|
1465
1652
|
rows={3}
|
|
1466
1653
|
placeholder={t('make this bold, shorten to one line…')}
|
|
1467
|
-
className="
|
|
1654
|
+
className="w-full resize-y rounded border border-border bg-transparent px-2 py-1.5 text-xs outline-none placeholder:text-muted-foreground/60 focus:border-foreground/40"
|
|
1468
1655
|
/>
|
|
1469
1656
|
<button
|
|
1470
1657
|
type="button"
|
|
1471
1658
|
onClick={saveComment}
|
|
1472
1659
|
disabled={busy || note.trim() === ''}
|
|
1473
|
-
className="
|
|
1660
|
+
className="flex h-8 w-full items-center justify-center gap-1.5 rounded border border-border px-2 text-xs transition-colors hover:bg-accent disabled:opacity-50"
|
|
1474
1661
|
>
|
|
1475
1662
|
<MessageSquarePlus className="size-3" />
|
|
1476
1663
|
{t('Mark comment')}
|
|
1477
1664
|
</button>
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1665
|
+
</CollapsibleSection>
|
|
1666
|
+
<CollapsibleSection title={t('Source')} summary={loc}>
|
|
1667
|
+
<dl className="grid grid-cols-[64px_1fr] gap-x-2 gap-y-1.5 text-[11px]">
|
|
1668
|
+
<dt className="text-muted-foreground">{t('Element')}</dt>
|
|
1669
|
+
<dd className="font-mono"><{selected.tag}></dd>
|
|
1670
|
+
<dt className="text-muted-foreground">{t('Location')}</dt>
|
|
1671
|
+
<dd className="font-mono">{loc}</dd>
|
|
1672
|
+
</dl>
|
|
1673
|
+
</CollapsibleSection>
|
|
1481
1674
|
</PanelShell>
|
|
1482
1675
|
)}
|
|
1483
1676
|
</>
|