@open-document/core 0.9.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/{build-B0GJXy8I.js → build-BHFGY8eF.js} +1 -1
  2. package/dist/{check-CuDIWsPT.js → check-UEBmDfT_.js} +3 -3
  3. package/dist/cli/bin.js +10 -6
  4. package/dist/{config-CAZ7Z_va.js → config-B_pdNbYg.js} +1166 -591
  5. package/dist/{context-PWAh9qbf.js → context-BM9_-u9P.js} +1 -1
  6. package/dist/{dev-CYqppXDI.js → dev-DX3QMIRi.js} +1 -1
  7. package/dist/{diagram-CCaUUnRe.js → diagram-BK4jTZr4.js} +146 -146
  8. package/dist/diff-DayvbXfX.js +44 -0
  9. package/dist/{export-1JtO2OMC.js → export-BPsXj1i6.js} +3 -3
  10. package/dist/{import-CsrdBOZ8.js → import-71wlAsrd.js} +2 -2
  11. package/dist/index.d.ts +53 -2
  12. package/dist/index.js +457 -18
  13. package/dist/ops/index.d.ts +72 -17
  14. package/dist/ops/index.js +3 -3
  15. package/dist/{ops-B2y9BMpk.js → ops-BUo67DaP.js} +642 -124
  16. package/dist/{preview-DW3PM-JV.js → preview-D3m1-gUL.js} +1 -1
  17. package/dist/{sdk-BqU6mwD_.d.ts → sdk-CpDEGRIo.d.ts} +2 -0
  18. package/dist/vite/index.js +1 -1
  19. package/package.json +2 -2
  20. package/skills/doc-authoring/SKILL.md +9 -4
  21. package/skills/doc-authoring/references/pagination.md +1 -1
  22. package/skills/doc-authoring/references/tables-and-charts.md +18 -1
  23. package/src/app/components/browser/browser-ui.tsx +105 -0
  24. package/src/app/components/chart.tsx +239 -0
  25. package/src/app/components/command-palette.tsx +284 -0
  26. package/src/app/components/design-panel/design-panel.tsx +22 -20
  27. package/src/app/components/design-panel/design-provider.tsx +4 -2
  28. package/src/app/components/diagram.tsx +11 -1
  29. package/src/app/components/doc-assets.tsx +6 -5
  30. package/src/app/components/doc-search.tsx +12 -10
  31. package/src/app/components/doc-sidebar.tsx +24 -18
  32. package/src/app/components/flow-page.tsx +2 -0
  33. package/src/app/components/inspector/format-section.tsx +434 -0
  34. package/src/app/components/inspector/inspector.tsx +310 -89
  35. package/src/app/components/inspector/use-style-edits.ts +210 -0
  36. package/src/app/components/language-toggle.tsx +38 -0
  37. package/src/app/components/palette-items.ts +128 -0
  38. package/src/app/components/panel/edit-save-card.tsx +4 -2
  39. package/src/app/components/panel/fields.tsx +100 -9
  40. package/src/app/components/panel/save-card.tsx +18 -10
  41. package/src/app/components/sidebar/folder-item.tsx +10 -8
  42. package/src/app/components/sidebar/icon-picker.tsx +3 -1
  43. package/src/app/components/sidebar/sidebar.tsx +44 -13
  44. package/src/app/components/theme-toggle.tsx +5 -3
  45. package/src/app/components/ui/menu.tsx +5 -0
  46. package/src/app/lib/agent-bridge.ts +8 -2
  47. package/src/app/lib/chart.test.ts +108 -0
  48. package/src/app/lib/chart.ts +343 -0
  49. package/src/app/lib/doc-preview.tsx +0 -10
  50. package/src/app/lib/docs.ts +3 -0
  51. package/src/app/lib/docx/from-dom.ts +11 -11
  52. package/src/app/lib/docx/ooxml.test.ts +25 -9
  53. package/src/app/lib/docx/ooxml.ts +58 -37
  54. package/src/app/lib/export-docx.ts +13 -8
  55. package/src/app/lib/flow.ts +1 -1
  56. package/src/app/lib/i18n-ja/browser.ts +88 -0
  57. package/src/app/lib/i18n-ja/doc.ts +65 -0
  58. package/src/app/lib/i18n-ja/index.ts +5 -0
  59. package/src/app/lib/i18n-ja/panels.ts +151 -0
  60. package/src/app/lib/i18n-ko/browser.ts +87 -0
  61. package/src/app/lib/i18n-ko/doc.ts +65 -0
  62. package/src/app/lib/i18n-ko/index.ts +5 -0
  63. package/src/app/lib/i18n-ko/panels.ts +148 -0
  64. package/src/app/lib/i18n-zh-cn/browser.ts +84 -0
  65. package/src/app/lib/i18n-zh-cn/doc.ts +64 -0
  66. package/src/app/lib/i18n-zh-cn/index.ts +5 -0
  67. package/src/app/lib/i18n-zh-cn/panels.ts +143 -0
  68. package/src/app/lib/i18n-zh-tw/browser.ts +84 -0
  69. package/src/app/lib/i18n-zh-tw/doc.ts +64 -0
  70. package/src/app/lib/i18n-zh-tw/index.ts +5 -0
  71. package/src/app/lib/i18n-zh-tw/panels.ts +144 -0
  72. package/src/app/lib/i18n.test.ts +24 -0
  73. package/src/app/lib/i18n.tsx +109 -0
  74. package/src/app/lib/inspector/format.ts +156 -0
  75. package/src/app/lib/outline.ts +23 -0
  76. package/src/app/lib/page-range.test.ts +10 -1
  77. package/src/app/lib/page-range.ts +26 -0
  78. package/src/app/lib/sdk.ts +2 -0
  79. package/src/app/main.tsx +4 -1
  80. package/src/app/routes/assets.tsx +193 -132
  81. package/src/app/routes/doc.tsx +668 -310
  82. package/src/app/routes/home-shell.tsx +115 -88
  83. package/src/app/routes/home.tsx +200 -67
  84. package/src/app/routes/themes.tsx +42 -35
  85. package/src/app/styles.css +84 -5
  86. package/src/app/virtual.d.ts +1 -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
- Loader2,
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';
@@ -21,11 +30,14 @@ import {
21
30
  } from 'react';
22
31
  import { createPortal } from 'react-dom';
23
32
  import { isSafeHref } from '../../lib/href';
33
+ import { useT } from '../../lib/i18n';
24
34
  import { candidateLocs, formatLocs } from '../../lib/inspector/fiber';
35
+ import type { StyleInfo } from '../../lib/inspector/format';
25
36
  import {
26
37
  cleanRun,
27
38
  cleanSegments,
28
39
  clearFormatting,
40
+ EDITING_ATTR,
29
41
  focusAt,
30
42
  hasMark,
31
43
  hrefOf,
@@ -54,7 +66,10 @@ import {
54
66
  } from '../../lib/inspector/inline-edit';
55
67
  import { PROP_ATTR } from '../../lib/source-loc';
56
68
  import { useHistory } from '../history-provider';
69
+ import { CollapsibleSection, Section } from '../panel/fields';
57
70
  import { PanelIconButton, PanelShell } from '../panel/panel-shell';
71
+ import { FormatSection } from './format-section';
72
+ import { elementsAt, styleKey, useStyleEdits } from './use-style-edits';
58
73
 
59
74
  type TextPart =
60
75
  | { kind: 'text'; index: number; value: string; formattable?: true; segments?: Segment[] }
@@ -132,10 +147,11 @@ const DOUBLE_CLICK_MS = 600;
132
147
  // Same visual language as open-slide's inspector: dashed on hover, solid on
133
148
  // selection, both in the same blue. Unsaved text keeps a dashed frame after the
134
149
  // cursor leaves it, so a change that exists only on screen never looks saved.
135
- const FRAME_STYLE: Record<'hover' | 'selected' | 'pending', CSSProperties> = {
150
+ const FRAME_STYLE: Record<'hover' | 'selected' | 'pending' | 'twin', CSSProperties> = {
136
151
  hover: { outline: '1.5px dashed #3b82f6', background: 'rgba(59,130,246,0.05)' },
137
152
  selected: { outline: '2px solid #3b82f6', background: 'rgba(59,130,246,0.1)' },
138
153
  pending: { outline: '1.5px dashed #3b82f6', outlineOffset: 2 },
154
+ twin: { outline: '1px solid rgba(59,130,246,0.55)', background: 'rgba(59,130,246,0.05)' },
139
155
  };
140
156
 
141
157
  // Past this, a reload that should have replaced a saved element is not coming
@@ -158,6 +174,24 @@ function targetFrom(el: Element | null): InspectorTarget | null {
158
174
  return { line, column, anchor: host, tag: host.tagName.toLowerCase(), ...(prop ? { prop } : {}) };
159
175
  }
160
176
 
177
+ /** What the panel's header calls the selected element — by role, not by tag. */
178
+ function kindOf(tag: string): { label: string; vars?: Record<string, number>; icon: typeof Type } {
179
+ const level = /^h([1-6])$/.exec(tag)?.[1];
180
+ if (level) return { label: 'Heading {level}', vars: { level: Number(level) }, icon: Heading };
181
+ if (tag === 'p' || tag === 'blockquote') return { label: 'Paragraph', icon: Pilcrow };
182
+ if (tag === 'li' || tag === 'ul' || tag === 'ol') return { label: 'List', icon: List };
183
+ if (tag === 'td' || tag === 'th' || tag === 'table' || tag === 'tr') {
184
+ return { label: 'Table', icon: Table };
185
+ }
186
+ if (tag === 'img' || tag === 'svg' || tag === 'figure') return { label: 'Image', icon: Image };
187
+ if (
188
+ ['span', 'strong', 'em', 'b', 'i', 'a', 'code', 'small', 'figcaption', 'label'].includes(tag)
189
+ ) {
190
+ return { label: 'Text', icon: Type };
191
+ }
192
+ return { label: 'Box', icon: Square };
193
+ }
194
+
161
195
  type Rect = { left: number; top: number; width: number; height: number };
162
196
 
163
197
  function sameRect(a: Rect | null, b: Rect) {
@@ -177,7 +211,7 @@ function Frame({
177
211
  }: {
178
212
  anchor: HTMLElement | null;
179
213
  container: HTMLElement;
180
- variant: 'hover' | 'selected' | 'pending';
214
+ variant: 'hover' | 'selected' | 'pending' | 'twin';
181
215
  }) {
182
216
  const [rect, setRect] = useState<Rect | null>(null);
183
217
 
@@ -238,9 +272,9 @@ const TOOL_CLASS =
238
272
 
239
273
  /**
240
274
  * Inline formatting, floating over the text being edited: emphasis, code,
241
- * links, and a way to take them off. Size, colour and alignment are not here
242
- * on purpose — they belong to the document's design system, and a one-off
243
- * inline style would quietly fork it.
275
+ * links, and a way to take them off. Size, colour and alignment are the
276
+ * element panel's, which offers the document's design tokens before a
277
+ * one-off value — here they would style a few words and quietly fork it.
244
278
  */
245
279
  function TextToolbar({
246
280
  anchor,
@@ -267,6 +301,7 @@ function TextToolbar({
267
301
  onLinkCancel: () => void;
268
302
  toolbarRef: React.RefObject<HTMLDivElement>;
269
303
  }) {
304
+ const t = useT();
270
305
  const [position, setPosition] = useState<{ left: number; top: number } | null>(null);
271
306
 
272
307
  // Same measuring contract as Frame: after every render, compared by value.
@@ -290,14 +325,14 @@ function TextToolbar({
290
325
  });
291
326
 
292
327
  const title = (label: string, keys: string) =>
293
- emphasis.canFormat ? `${label} (${keys})` : (emphasis.reason ?? label);
328
+ emphasis.canFormat ? `${label} (${keys})` : emphasis.reason ? t(emphasis.reason) : label;
294
329
  const invalid = link !== null && link.value.trim() !== '' && !isSafeHref(link.value.trim());
295
330
 
296
331
  return (
297
332
  <div
298
333
  ref={toolbarRef}
299
334
  role="toolbar"
300
- aria-label="Text formatting"
335
+ aria-label={t('Text formatting')}
301
336
  className="pointer-events-auto absolute z-40 flex items-center gap-0.5 rounded-md border border-border bg-background p-0.5 shadow-md"
302
337
  style={position ?? { visibility: 'hidden' }}
303
338
  // Keep focus, and the selection, in the text being edited — except for
@@ -312,9 +347,9 @@ function TextToolbar({
312
347
  // biome-ignore lint/a11y/noAutofocus: the field opens on an explicit request and is the only thing to do next
313
348
  autoFocus
314
349
  type="url"
315
- aria-label="Link address"
350
+ aria-label={t('Link address')}
316
351
  aria-invalid={invalid}
317
- placeholder="https://… or #section"
352
+ placeholder={t('https://… or #section')}
318
353
  value={link.value}
319
354
  onChange={(e) => onLinkChange(e.target.value)}
320
355
  onKeyDown={(e) => {
@@ -326,13 +361,13 @@ function TextToolbar({
326
361
  onLinkCancel();
327
362
  }
328
363
  }}
329
- title={invalid ? 'Only web, mail, phone, or in-document addresses' : undefined}
364
+ title={invalid ? t('Only web, mail, phone, or in-document addresses') : undefined}
330
365
  className="h-8 w-64 rounded border border-border bg-transparent px-2 text-xs outline-none focus:border-foreground/40 aria-invalid:border-destructive"
331
366
  />
332
367
  <button
333
368
  type="button"
334
- aria-label="Apply link"
335
- title="Apply (Enter)"
369
+ aria-label={t('Apply link')}
370
+ title={`${t('Apply')} (Enter)`}
336
371
  disabled={invalid}
337
372
  onClick={onLinkApply}
338
373
  className={TOOL_CLASS}
@@ -342,8 +377,8 @@ function TextToolbar({
342
377
  {link.existing && (
343
378
  <button
344
379
  type="button"
345
- aria-label="Remove link"
346
- title="Remove link"
380
+ aria-label={t('Remove link')}
381
+ title={t('Remove link')}
347
382
  onClick={() => {
348
383
  onLinkChange('');
349
384
  onLinkApply();
@@ -368,10 +403,12 @@ function TextToolbar({
368
403
  <button
369
404
  key={mark}
370
405
  type="button"
371
- aria-label={label}
406
+ aria-label={t(label)}
372
407
  aria-pressed={emphasis[mark]}
373
408
  title={
374
- styled ? 'Already bold — this element’s own style sets it' : title(label, keys)
409
+ styled
410
+ ? t('Already bold — this element’s own style sets it')
411
+ : title(t(label), keys)
375
412
  }
376
413
  disabled={!emphasis.canFormat || styled}
377
414
  onClick={() => onFormat(mark)}
@@ -384,9 +421,15 @@ function TextToolbar({
384
421
  <span aria-hidden className="mx-0.5 h-4 w-px bg-border" />
385
422
  <button
386
423
  type="button"
387
- aria-label="Link"
424
+ aria-label={t('Link')}
388
425
  aria-pressed={emphasis.href !== null}
389
- title={emphasis.linkable ? 'Link (⌘K)' : (emphasis.reason ?? 'Link')}
426
+ title={
427
+ emphasis.linkable
428
+ ? `${t('Link')} (⌘K)`
429
+ : emphasis.reason
430
+ ? t(emphasis.reason)
431
+ : t('Link')
432
+ }
390
433
  disabled={!emphasis.linkable}
391
434
  onClick={onOpenLink}
392
435
  className={TOOL_CLASS}
@@ -395,8 +438,8 @@ function TextToolbar({
395
438
  </button>
396
439
  <button
397
440
  type="button"
398
- aria-label="Clear formatting"
399
- title={title('Clear formatting', '⌘\\')}
441
+ aria-label={t('Clear formatting')}
442
+ title={title(t('Clear formatting'), '⌘\\')}
400
443
  disabled={!emphasis.canFormat}
401
444
  onClick={onClear}
402
445
  className={TOOL_CLASS}
@@ -522,8 +565,10 @@ type Props = {
522
565
  docId: string;
523
566
  /** The scroll container the pages live in. */
524
567
  containerRef: React.RefObject<HTMLDivElement | null>;
525
- /** The design panel shares the right dock and wins it while open. */
568
+ /** The design panel shares the right dock; the panel opened last holds it. */
526
569
  panelHidden: boolean;
570
+ /** An element was picked on the page — the dock should show its panel. */
571
+ onPick: () => void;
527
572
  /** The save card is showing, so the hint underneath it steps aside. */
528
573
  quiet: boolean;
529
574
  onExit: () => void;
@@ -537,6 +582,7 @@ export function Inspector({
537
582
  docId,
538
583
  containerRef,
539
584
  panelHidden,
585
+ onPick,
540
586
  quiet,
541
587
  onExit,
542
588
  exitRef,
@@ -544,6 +590,7 @@ export function Inspector({
544
590
  onPendingChange,
545
591
  }: Props) {
546
592
  const history = useHistory();
593
+ const t = useT();
547
594
  const nextIdRef = useRef(1);
548
595
  const [container, setContainer] = useState<HTMLElement | null>(null);
549
596
  const [hover, setHover] = useState<HTMLElement | null>(null);
@@ -574,9 +621,25 @@ export function Inspector({
574
621
  const entriesRef = useRef(new Map<HTMLElement, Entry>());
575
622
  const sessionStartRef = useRef<Segment[][]>([]);
576
623
  const firstClickRef = useRef<{ anchor: HTMLElement; at: At; time: number } | null>(null);
624
+ const onPickRef = useRef(onPick);
625
+ onPickRef.current = onPick;
577
626
 
578
627
  useLayoutEffect(() => setContainer(containerRef.current), [containerRef]);
579
628
 
629
+ const {
630
+ count: styleCount,
631
+ edits: styleEdits,
632
+ change: changeStyle,
633
+ pendingFor,
634
+ discard: discardStyles,
635
+ forget: forgetStyles,
636
+ revert: revertStyles,
637
+ repaint: repaintStyles,
638
+ } = useStyleEdits(container);
639
+ const [styleInfo, setStyleInfo] = useState<{ anchor: HTMLElement; value: StyleInfo } | null>(
640
+ null,
641
+ );
642
+
580
643
  const insideChrome = useCallback(
581
644
  (node: EventTarget | null) =>
582
645
  (panelRef.current?.contains(node as Node) ?? false) ||
@@ -612,7 +675,9 @@ export function Inspector({
612
675
  const editor = mountEditor(anchor, runs);
613
676
  if (!editor) {
614
677
  setStatus(
615
- 'The text on the page does not line up with its source, so it cannot be edited here.',
678
+ t(
679
+ 'The text on the page does not line up with its source, so it cannot be edited here.',
680
+ ),
616
681
  );
617
682
  return;
618
683
  }
@@ -639,7 +704,7 @@ export function Inspector({
639
704
  setActive(entry);
640
705
  focusAt(entry.editor.clone, pointIn(entry.editor.clone, at), selectWord);
641
706
  },
642
- [],
707
+ [t],
643
708
  );
644
709
 
645
710
  /** Puts an editor's runs back to a snapshot, wherever a reload has since moved it. */
@@ -685,10 +750,11 @@ export function Inspector({
685
750
 
686
751
  const discard = useCallback(() => {
687
752
  for (const entry of [...entriesRef.current.values()]) drop(entry);
753
+ discardStyles();
688
754
  setActive(null);
689
755
  refresh();
690
- setStatus('Discarded unsaved edits');
691
- }, [drop, refresh]);
756
+ setStatus(t('Discarded unsaved edits'));
757
+ }, [drop, refresh, discardStyles, t]);
692
758
 
693
759
  /**
694
760
  * Leaves the clone in place until hot reload has replaced what it covers —
@@ -832,23 +898,42 @@ export function Inspector({
832
898
  owners.push(entry);
833
899
  }
834
900
  }
835
- if (edits.length === 0) return { ok: true };
901
+ const styles = styleEdits();
902
+ if (edits.length === 0 && styles.length === 0) return { ok: true };
836
903
 
837
904
  setBusy(true);
838
905
  try {
839
- const res = await fetch('/__edit/texts', {
906
+ // Text and style go in one request, so the file is read, spliced and
907
+ // written once — two requests would each start from the file before
908
+ // the other, and the second would put back what the first changed.
909
+ const res = await fetch('/__edit/batch', {
840
910
  method: 'PUT',
841
911
  headers: { 'content-type': 'application/json' },
842
- body: JSON.stringify({ docId, edits }),
912
+ body: JSON.stringify({
913
+ docId,
914
+ texts: edits,
915
+ styles: styles.map(({ line, column, tag, changes, expected }) => ({
916
+ line,
917
+ column,
918
+ tag,
919
+ changes,
920
+ expected,
921
+ })),
922
+ }),
843
923
  });
844
- const body = (await res.json()) as { results?: Outcome[]; error?: string };
845
- if (!res.ok || !body.results) {
846
- const error = body.error ?? 'Save failed';
924
+ const body = (await res.json()) as {
925
+ texts?: Outcome[];
926
+ styles?: Outcome[];
927
+ error?: string;
928
+ };
929
+ if (!res.ok || !body.texts || !body.styles) {
930
+ const error = body.error ?? t('Save failed');
847
931
  setStatus(error);
848
932
  return { ok: false, error };
849
933
  }
850
- const results = body.results;
851
- const failures = results.filter(
934
+ const results = body.texts;
935
+ const styleResults = body.styles;
936
+ const failures = [...results, ...styleResults].filter(
852
937
  (result): result is Extract<Outcome, { ok: false }> => !result.ok,
853
938
  );
854
939
  for (const entry of new Set(owners)) {
@@ -856,22 +941,29 @@ export function Inspector({
856
941
  if (wrote) settle(entry);
857
942
  else drop(entry);
858
943
  }
944
+ const keys = styles.map(styleKey);
945
+ forgetStyles(keys.filter((_, at) => styleResults[at]?.ok));
946
+ revertStyles(keys.filter((_, at) => !styleResults[at]?.ok));
859
947
  refresh();
860
948
  setSelected(null);
861
949
  if (failures.length === 0) {
862
- setStatus('Saved to source');
950
+ setStatus(t('Saved to source'));
863
951
  return { ok: true };
864
952
  }
865
- const error = `${failures.length} of ${edits.length} not saved — ${failures[0]?.error ?? 'refused'}`;
953
+ const error = t('{failed} of {total} not saved — {reason}', {
954
+ failed: failures.length,
955
+ total: edits.length + styles.length,
956
+ reason: failures[0]?.error ?? t('refused'),
957
+ });
866
958
  setStatus(error);
867
959
  return { ok: false, error };
868
960
  } catch {
869
- setStatus('Save failed');
870
- return { ok: false, error: 'Save failed' };
961
+ setStatus(t('Save failed'));
962
+ return { ok: false, error: t('Save failed') };
871
963
  } finally {
872
964
  setBusy(false);
873
965
  }
874
- }, [active, docId, drop, finish, refresh, settle]);
966
+ }, [active, docId, drop, finish, refresh, settle, styleEdits, forgetStyles, revertStyles, t]);
875
967
 
876
968
  const leave = useCallback(async () => {
877
969
  if ((await save()).ok) onExit();
@@ -886,9 +978,10 @@ export function Inspector({
886
978
  };
887
979
  }, [exitRef, leave, controlsRef, save, discard]);
888
980
 
981
+ const pendingCount = pending.length + styleCount;
889
982
  useEffect(() => {
890
- onPendingChange(pending.length);
891
- }, [pending.length, onPendingChange]);
983
+ onPendingChange(pendingCount);
984
+ }, [pendingCount, onPendingChange]);
892
985
  useEffect(() => () => onPendingChange(0), [onPendingChange]);
893
986
 
894
987
  // Leaving edit mode any other way — a route change, closing the tab — drops
@@ -902,11 +995,11 @@ export function Inspector({
902
995
  }, []);
903
996
 
904
997
  useEffect(() => {
905
- if (pending.length === 0) return;
998
+ if (pendingCount === 0) return;
906
999
  const onBeforeUnload = (e: BeforeUnloadEvent) => e.preventDefault();
907
1000
  window.addEventListener('beforeunload', onBeforeUnload);
908
1001
  return () => window.removeEventListener('beforeunload', onBeforeUnload);
909
- }, [pending.length]);
1002
+ }, [pendingCount]);
910
1003
 
911
1004
  // An external write — an agent, the design panel, another save — reloads the
912
1005
  // document and replaces elements, clones and all. When the element at the
@@ -969,9 +1062,16 @@ export function Inspector({
969
1062
  }
970
1063
  }
971
1064
  if (replaced) refresh();
1065
+ repaintStyles();
972
1066
  if (lost > 0) {
973
1067
  setStatus(
974
- `The document reloaded with new text here — ${lost} unsaved edit${lost > 1 ? 's were' : ' was'} lost`,
1068
+ lost > 1
1069
+ ? t('The document reloaded with new text here — {count} unsaved edits were lost', {
1070
+ count: lost,
1071
+ })
1072
+ : t('The document reloaded with new text here — {count} unsaved edit was lost', {
1073
+ count: lost,
1074
+ }),
975
1075
  );
976
1076
  }
977
1077
 
@@ -996,7 +1096,7 @@ export function Inspector({
996
1096
  });
997
1097
  observer.observe(container, { childList: true, subtree: true });
998
1098
  return () => observer.disconnect();
999
- }, [container, refresh]);
1099
+ }, [container, refresh, repaintStyles, t]);
1000
1100
 
1001
1101
  useEffect(() => {
1002
1102
  if (!container) return;
@@ -1013,6 +1113,7 @@ export function Inspector({
1013
1113
  if (entry) {
1014
1114
  const owner = targetFrom(entry.anchor);
1015
1115
  if (owner) setSelected((prev) => (prev?.anchor === owner.anchor ? prev : owner));
1116
+ onPickRef.current();
1016
1117
  if (active !== entry) {
1017
1118
  begin(entry.anchor, atIn(entry.editor.clone, e.clientX, e.clientY), false);
1018
1119
  }
@@ -1040,6 +1141,7 @@ export function Inspector({
1040
1141
  target.anchor.scrollIntoView({ block: 'center', behavior: 'smooth' });
1041
1142
  }
1042
1143
  setSelected((prev) => (prev?.anchor === target.anchor ? prev : target));
1144
+ onPickRef.current();
1043
1145
  setStatus(null);
1044
1146
  setNote('');
1045
1147
  };
@@ -1061,6 +1163,7 @@ export function Inspector({
1061
1163
  if (!target?.anchor.contains(e.target as Node)) return;
1062
1164
  e.preventDefault();
1063
1165
  setSelected((prev) => (prev?.anchor === target.anchor ? prev : target));
1166
+ onPickRef.current();
1064
1167
  setWantEdit({
1065
1168
  anchor: target.anchor,
1066
1169
  at: atIn(target.anchor, e.clientX, e.clientY),
@@ -1215,7 +1318,7 @@ export function Inspector({
1215
1318
  const el = clone.querySelector<HTMLElement>(`[data-od-run="${run.index}"]`);
1216
1319
  if (el) run.el = el;
1217
1320
  }
1218
- setStatus('Type inside one run of text — the markup between runs stays as written.');
1321
+ setStatus(t('Type inside one run of text — the markup between runs stays as written.'));
1219
1322
  refresh();
1220
1323
  };
1221
1324
 
@@ -1229,7 +1332,7 @@ export function Inspector({
1229
1332
  clone.removeEventListener('compositionstart', onCompositionStart);
1230
1333
  clone.removeEventListener('compositionend', onCompositionEnd);
1231
1334
  };
1232
- }, [active, finish, refresh, format, openLink, clear]);
1335
+ }, [active, finish, refresh, format, openLink, clear, t]);
1233
1336
 
1234
1337
  // Report the pick to the dev server so `current.json` can answer "this
1235
1338
  // element" for an agent. Clearing the selection clears it there too.
@@ -1284,7 +1387,41 @@ export function Inspector({
1284
1387
  });
1285
1388
  })
1286
1389
  .catch(() => {
1287
- if (!cancelled) setStatus('could not read source');
1390
+ if (!cancelled) setStatus(t('could not read source'));
1391
+ });
1392
+ return () => {
1393
+ cancelled = true;
1394
+ };
1395
+ }, [selected, docId, t]);
1396
+
1397
+ // The Format section reads the element's own `style` from source: the page
1398
+ // shows the value, only source can say whether it is a token, a shared
1399
+ // style object's, or code.
1400
+ useEffect(() => {
1401
+ if (!selected) return;
1402
+ let cancelled = false;
1403
+ const params = new URLSearchParams({
1404
+ docId,
1405
+ line: String(selected.line),
1406
+ column: String(selected.column),
1407
+ tag: selected.tag,
1408
+ });
1409
+ fetch(`/__edit/style?${params}`)
1410
+ .then((res) => res.json())
1411
+ .then((body: StyleInfo & { error?: string }) => {
1412
+ if (cancelled) return;
1413
+ setStyleInfo({
1414
+ anchor: selected.anchor,
1415
+ value: body.error ? { editable: false, reason: body.error } : body,
1416
+ });
1417
+ })
1418
+ .catch(() => {
1419
+ if (!cancelled) {
1420
+ setStyleInfo({
1421
+ anchor: selected.anchor,
1422
+ value: { editable: false, reason: 'could not read source' },
1423
+ });
1424
+ }
1288
1425
  });
1289
1426
  return () => {
1290
1427
  cancelled = true;
@@ -1295,11 +1432,11 @@ export function Inspector({
1295
1432
  if (!wantEdit || !target || selected?.anchor !== wantEdit.anchor) return;
1296
1433
  setWantEdit(null);
1297
1434
  if (!target.editable) {
1298
- setStatus(target.reason ?? 'This text cannot be edited here.');
1435
+ setStatus(target.reason ? t(target.reason) : t('This text cannot be edited here.'));
1299
1436
  return;
1300
1437
  }
1301
1438
  begin(wantEdit.anchor, wantEdit.at, wantEdit.selectWord, target);
1302
- }, [wantEdit, target, selected, begin]);
1439
+ }, [wantEdit, target, selected, begin, t]);
1303
1440
 
1304
1441
  const saveComment = async () => {
1305
1442
  if (!selected || note.trim() === '' || busy) return;
@@ -1319,23 +1456,44 @@ export function Inspector({
1319
1456
  const body = (await res.json()) as { ok?: boolean; error?: string };
1320
1457
  if (res.ok && body.ok) {
1321
1458
  setNote('');
1322
- setStatus('Marked in source — run /apply-comments');
1459
+ setStatus(t('Marked in source — run /apply-comments'));
1323
1460
  } else {
1324
- setStatus(body.error ?? 'Could not add comment');
1461
+ setStatus(body.error ?? t('Could not add comment'));
1325
1462
  }
1326
1463
  } finally {
1327
1464
  setBusy(false);
1328
1465
  }
1329
1466
  };
1330
1467
 
1468
+ const kind = kindOf(selected?.tag ?? '');
1469
+ const editingHere = active !== null && active.anchor === selected?.anchor;
1470
+ const startEdit = () => {
1471
+ if (!selected) return;
1472
+ if (entriesRef.current.has(selected.anchor)) begin(selected.anchor, null, false);
1473
+ else setWantEdit({ anchor: selected.anchor, at: null, selectWord: false });
1474
+ };
1475
+ // Every other element the selected one's source prints — a `.map()` row, a
1476
+ // block split across pages. A style change lands on all of them, so the
1477
+ // page shows them before it happens rather than the panel saying so.
1478
+ const twins =
1479
+ container && selected
1480
+ ? elementsAt(container, selected).filter(
1481
+ (el) => el !== selected.anchor && !el.hasAttribute(EDITING_ATTR),
1482
+ )
1483
+ : [];
1484
+ const KindIcon = kind.icon;
1485
+ const loc = selected
1486
+ ? `${target?.line ?? selected.line}:${target?.column ?? selected.column}`
1487
+ : '';
1488
+
1331
1489
  const visible = (anchor: HTMLElement | null | undefined) =>
1332
1490
  anchor ? (entriesRef.current.get(anchor)?.editor.clone ?? anchor) : null;
1333
1491
  const selectedEl = visible(selected?.anchor);
1334
1492
  const hint = active
1335
- ? 'Enter to keep · Shift+Enter for a new line · Esc to revert'
1493
+ ? t('Enter to keep · Shift+Enter for a new line · Esc to revert')
1336
1494
  : selected
1337
- ? 'Double-click or Enter to edit text · Esc to deselect'
1338
- : 'Click to select · double-click to edit · Esc to leave';
1495
+ ? t('Double-click or Enter to edit text · Esc to deselect')
1496
+ : t('Click to select · double-click to edit · Esc to leave');
1339
1497
 
1340
1498
  const overlay = container
1341
1499
  ? createPortal(
@@ -1356,6 +1514,10 @@ export function Inspector({
1356
1514
  container={container}
1357
1515
  variant="hover"
1358
1516
  />
1517
+ {twins.map((twin, at) => (
1518
+ // biome-ignore lint/suspicious/noArrayIndexKey: twins share one loc; order is stable
1519
+ <Frame key={at} anchor={twin} container={container} variant="twin" />
1520
+ ))}
1359
1521
  <Frame anchor={selectedEl} container={container} variant="selected" />
1360
1522
  </div>
1361
1523
  {/* Only while there is something to act on: a row of disabled
@@ -1390,67 +1552,126 @@ export function Inspector({
1390
1552
  {overlay}
1391
1553
  {selected && !panelHidden && (
1392
1554
  <PanelShell
1393
- label="Element"
1555
+ label={t('Element')}
1394
1556
  panelRef={panelRef}
1395
1557
  header={
1396
- <span className="truncate font-mono text-[11px] text-muted-foreground">
1397
- &lt;{selected.tag}&gt; · {target?.line ?? selected.line}:
1398
- {target?.column ?? selected.column}
1399
- </span>
1558
+ <>
1559
+ <KindIcon aria-hidden className="size-3.5 flex-none text-muted-foreground" />
1560
+ <span className="truncate font-medium text-xs">{t(kind.label, kind.vars)}</span>
1561
+ {twins.length > 0 && (
1562
+ <span
1563
+ title={t('{count} elements print from this line of source', {
1564
+ count: twins.length + 1,
1565
+ })}
1566
+ className="flex flex-none items-center gap-1 rounded bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground"
1567
+ >
1568
+ <Copy aria-hidden className="size-3" />×{twins.length + 1}
1569
+ </span>
1570
+ )}
1571
+ </>
1400
1572
  }
1401
1573
  actions={
1402
- <PanelIconButton label="Close" onClick={() => setSelected(null)}>
1574
+ <PanelIconButton label={t('Close')} onClick={() => setSelected(null)}>
1403
1575
  <X className="size-3.5" />
1404
1576
  </PanelIconButton>
1405
1577
  }
1406
1578
  >
1407
- <div className="min-h-0 flex-1 overflow-y-auto p-3">
1408
- <span className="block text-[10px] text-muted-foreground uppercase tracking-wider">
1409
- Text
1410
- </span>
1579
+ <FormatSection
1580
+ // A new element is a new set of fields: a half-typed number must
1581
+ // not commit onto whatever is selected next.
1582
+ key={`${selected.line}:${selected.column}`}
1583
+ anchor={selected.anchor}
1584
+ info={styleInfo?.anchor === selected.anchor ? styleInfo.value : null}
1585
+ pending={pendingFor(selected)}
1586
+ onChange={(prop, value, shown) => changeStyle(selected, prop, value, shown)}
1587
+ />
1588
+ <Section
1589
+ title={t('Text')}
1590
+ action={
1591
+ editingHere ? (
1592
+ <PanelIconButton label={t('Done')} onClick={() => active && finish(active, false)}>
1593
+ <Check className="size-3.5" />
1594
+ </PanelIconButton>
1595
+ ) : null
1596
+ }
1597
+ >
1411
1598
  {target === null ? (
1412
- <div className="grid h-16 place-items-center">
1413
- <Loader2 className="size-3.5 animate-spin text-muted-foreground" />
1599
+ <div className="h-0.5 overflow-hidden rounded bg-muted">
1600
+ <div className="h-full w-1/3 animate-pulse bg-foreground/20" />
1414
1601
  </div>
1415
- ) : target.editable ? (
1416
- <p className="mt-1 text-[11px] text-muted-foreground leading-relaxed">
1417
- {active?.anchor === selected.anchor
1418
- ? 'Editing on the page. Enter keeps the change, Shift+Enter starts a new line, Esc reverts it.'
1419
- : 'Double-click the text on the page, or press Enter, to edit it where it is printed.'}
1420
- {target.parts.some((part) => part.kind === 'markup') &&
1421
- ' Inline markup stays as written.'}
1422
- </p>
1423
1602
  ) : (
1424
- <p className="mt-1 rounded border border-border bg-muted px-2 py-1.5 text-[11px] text-muted-foreground">
1425
- {target.reason ?? 'Not editable here.'}
1426
- </p>
1603
+ // The words themselves, as the way in: clicking them opens them
1604
+ // on the page. Markup the editor leaves alone reads as a chip.
1605
+ <button
1606
+ type="button"
1607
+ disabled={!target.editable}
1608
+ aria-pressed={editingHere}
1609
+ aria-label={target.editable ? t('Edit on page') : undefined}
1610
+ title={
1611
+ target.editable
1612
+ ? `${t('Edit on page')} (Enter)`
1613
+ : target.reason
1614
+ ? t(target.reason)
1615
+ : t('Not editable here.')
1616
+ }
1617
+ onClick={startEdit}
1618
+ 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"
1619
+ >
1620
+ {editingHere && active
1621
+ ? shownText(active.editor.clone)
1622
+ : target.parts.map((part, at) =>
1623
+ part.kind === 'text' ? (
1624
+ // biome-ignore lint/suspicious/noArrayIndexKey: parts are positional
1625
+ <span key={at}>{part.value}</span>
1626
+ ) : (
1627
+ <span
1628
+ // biome-ignore lint/suspicious/noArrayIndexKey: parts are positional
1629
+ key={at}
1630
+ className="mx-0.5 rounded bg-muted px-1 font-mono text-[10px] text-muted-foreground"
1631
+ >
1632
+ {part.label}
1633
+ </span>
1634
+ ),
1635
+ )}
1636
+ <span
1637
+ aria-hidden
1638
+ className="absolute top-1.5 right-1.5 flex text-muted-foreground opacity-60 transition-opacity group-hover:opacity-100 group-disabled:opacity-60"
1639
+ >
1640
+ {target.editable ? <Pencil className="size-3" /> : <Lock className="size-3" />}
1641
+ </span>
1642
+ </button>
1427
1643
  )}
1428
-
1429
- <span className="mt-4 block text-[10px] text-muted-foreground uppercase tracking-wider">
1430
- Comment for the agent
1431
- </span>
1644
+ </Section>
1645
+ <CollapsibleSection title={t('Comment for the agent')}>
1432
1646
  <textarea
1647
+ aria-label={t('Comment for the agent')}
1433
1648
  value={note}
1434
1649
  onChange={(e) => setNote(e.target.value)}
1435
1650
  onKeyDown={(e) => {
1436
1651
  if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) void saveComment();
1437
1652
  }}
1438
1653
  rows={3}
1439
- placeholder="make this bold, shorten to one line…"
1440
- className="mt-1 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"
1654
+ placeholder={t('make this bold, shorten to one line…')}
1655
+ 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"
1441
1656
  />
1442
1657
  <button
1443
1658
  type="button"
1444
1659
  onClick={saveComment}
1445
1660
  disabled={busy || note.trim() === ''}
1446
- className="mt-1.5 flex w-full items-center justify-center gap-1.5 rounded border border-border px-2 py-1.5 text-xs transition-colors hover:bg-accent disabled:opacity-50"
1661
+ 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"
1447
1662
  >
1448
1663
  <MessageSquarePlus className="size-3" />
1449
- Mark comment
1664
+ {t('Mark comment')}
1450
1665
  </button>
1451
-
1452
- {status && <p className="mt-2 text-[11px] text-muted-foreground">{status}</p>}
1453
- </div>
1666
+ </CollapsibleSection>
1667
+ <CollapsibleSection title={t('Source')} summary={loc}>
1668
+ <dl className="grid grid-cols-[64px_1fr] gap-x-2 gap-y-1.5 text-[11px]">
1669
+ <dt className="text-muted-foreground">{t('Element')}</dt>
1670
+ <dd className="font-mono">&lt;{selected.tag}&gt;</dd>
1671
+ <dt className="text-muted-foreground">{t('Location')}</dt>
1672
+ <dd className="font-mono">{loc}</dd>
1673
+ </dl>
1674
+ </CollapsibleSection>
1454
1675
  </PanelShell>
1455
1676
  )}
1456
1677
  </>