@open-document/core 0.9.1 → 0.10.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 (83) hide show
  1. package/dist/{build-B0GJXy8I.js → build-DJMLK50m.js} +1 -1
  2. package/dist/{check-CuDIWsPT.js → check-CUKuufBm.js} +3 -3
  3. package/dist/cli/bin.js +10 -6
  4. package/dist/{config-CAZ7Z_va.js → config-CvzpyAUA.js} +558 -546
  5. package/dist/{context-PWAh9qbf.js → context-B4ip7SoI.js} +1 -1
  6. package/dist/{dev-CYqppXDI.js → dev-dnH7DTlD.js} +1 -1
  7. package/dist/{diagram-CCaUUnRe.js → diagram-BK4jTZr4.js} +146 -146
  8. package/dist/diff-QTo0A5Rx.js +44 -0
  9. package/dist/{export-1JtO2OMC.js → export-BrRFrexj.js} +3 -3
  10. package/dist/{import-CsrdBOZ8.js → import-C14Vn9ER.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-DKidjLXP.js} +642 -124
  16. package/dist/{preview-DW3PM-JV.js → preview-wKM4C6Uk.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/inspector.tsx +75 -48
  34. package/src/app/components/language-toggle.tsx +38 -0
  35. package/src/app/components/palette-items.ts +128 -0
  36. package/src/app/components/panel/edit-save-card.tsx +4 -2
  37. package/src/app/components/panel/fields.tsx +5 -2
  38. package/src/app/components/panel/save-card.tsx +18 -10
  39. package/src/app/components/sidebar/folder-item.tsx +10 -8
  40. package/src/app/components/sidebar/icon-picker.tsx +3 -1
  41. package/src/app/components/sidebar/sidebar.tsx +44 -13
  42. package/src/app/components/theme-toggle.tsx +5 -3
  43. package/src/app/components/ui/menu.tsx +5 -0
  44. package/src/app/lib/agent-bridge.ts +8 -2
  45. package/src/app/lib/chart.test.ts +108 -0
  46. package/src/app/lib/chart.ts +343 -0
  47. package/src/app/lib/doc-preview.tsx +0 -10
  48. package/src/app/lib/docs.ts +3 -0
  49. package/src/app/lib/docx/from-dom.ts +11 -11
  50. package/src/app/lib/docx/ooxml.test.ts +25 -9
  51. package/src/app/lib/docx/ooxml.ts +58 -37
  52. package/src/app/lib/export-docx.ts +13 -8
  53. package/src/app/lib/flow.ts +1 -1
  54. package/src/app/lib/i18n-ja/browser.ts +88 -0
  55. package/src/app/lib/i18n-ja/doc.ts +65 -0
  56. package/src/app/lib/i18n-ja/index.ts +5 -0
  57. package/src/app/lib/i18n-ja/panels.ts +104 -0
  58. package/src/app/lib/i18n-ko/browser.ts +87 -0
  59. package/src/app/lib/i18n-ko/doc.ts +65 -0
  60. package/src/app/lib/i18n-ko/index.ts +5 -0
  61. package/src/app/lib/i18n-ko/panels.ts +102 -0
  62. package/src/app/lib/i18n-zh-cn/browser.ts +84 -0
  63. package/src/app/lib/i18n-zh-cn/doc.ts +64 -0
  64. package/src/app/lib/i18n-zh-cn/index.ts +5 -0
  65. package/src/app/lib/i18n-zh-cn/panels.ts +98 -0
  66. package/src/app/lib/i18n-zh-tw/browser.ts +84 -0
  67. package/src/app/lib/i18n-zh-tw/doc.ts +64 -0
  68. package/src/app/lib/i18n-zh-tw/index.ts +5 -0
  69. package/src/app/lib/i18n-zh-tw/panels.ts +99 -0
  70. package/src/app/lib/i18n.test.ts +24 -0
  71. package/src/app/lib/i18n.tsx +109 -0
  72. package/src/app/lib/outline.ts +23 -0
  73. package/src/app/lib/page-range.test.ts +10 -1
  74. package/src/app/lib/page-range.ts +26 -0
  75. package/src/app/lib/sdk.ts +2 -0
  76. package/src/app/main.tsx +4 -1
  77. package/src/app/routes/assets.tsx +193 -132
  78. package/src/app/routes/doc.tsx +666 -310
  79. package/src/app/routes/home-shell.tsx +115 -88
  80. package/src/app/routes/home.tsx +200 -67
  81. package/src/app/routes/themes.tsx +42 -35
  82. package/src/app/styles.css +84 -5
  83. package/src/app/virtual.d.ts +1 -0
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import type { DesignSystem } from '../lib/design';
3
+ import { useT } from '../lib/i18n';
3
4
  import type { OutlineEntry } from '../lib/outline';
4
5
  import type { PageGeometry } from '../lib/sdk';
5
6
  import type { ExpandedPage } from '../lib/use-doc-pages';
@@ -7,7 +8,7 @@ import { cn } from '../lib/utils';
7
8
  import { DocAssets } from './doc-assets';
8
9
  import { PageFrame } from './page-frame';
9
10
 
10
- const THUMB_WIDTH = 116;
11
+ const THUMB_WIDTH = 150;
11
12
 
12
13
  type Tab = 'pages' | 'outline' | 'assets';
13
14
 
@@ -34,6 +35,7 @@ export function DocSidebar({
34
35
  onSelectPage,
35
36
  onSelectEntry,
36
37
  }: Props) {
38
+ const t = useT();
37
39
  const [tab, setTab] = useState<Tab>('pages');
38
40
  const railRef = useRef<HTMLDivElement>(null);
39
41
  // The assets panel talks to the dev API, so it has nothing to show in a
@@ -57,7 +59,7 @@ export function DocSidebar({
57
59
  }, [currentPage, tab]);
58
60
 
59
61
  return (
60
- <aside className="hidden w-56 flex-none flex-col border-border border-r bg-background md:flex">
62
+ <aside className="hidden w-56 flex-none flex-col bg-background md:flex">
61
63
  <div className="flex flex-none gap-1 p-2">
62
64
  {tabs.map((value) => (
63
65
  <button
@@ -65,13 +67,13 @@ export function DocSidebar({
65
67
  type="button"
66
68
  onClick={() => setTab(value)}
67
69
  className={cn(
68
- 'flex-1 rounded-md px-2 py-1 text-[11px] capitalize transition-colors',
70
+ 'flex-1 truncate whitespace-nowrap rounded-md px-2 py-1 text-[11px] capitalize transition-colors',
69
71
  tab === value
70
72
  ? 'bg-accent font-medium text-foreground'
71
73
  : 'text-muted-foreground hover:bg-accent/60',
72
74
  )}
73
75
  >
74
- {value}
76
+ {t(value)}
75
77
  </button>
76
78
  ))}
77
79
  </div>
@@ -79,8 +81,8 @@ export function DocSidebar({
79
81
  {tab === 'assets' ? (
80
82
  <DocAssets docId={docId} />
81
83
  ) : tab === 'pages' ? (
82
- <div ref={railRef} className="flex-1 overflow-y-auto px-3 pb-6">
83
- <div className="flex flex-col items-center gap-3">
84
+ <div ref={railRef} className="flex-1 overflow-y-auto px-2 pb-6">
85
+ <div className="flex flex-col gap-1">
84
86
  {pages.map((entry, index) => {
85
87
  const page = index + 1;
86
88
  return (
@@ -89,14 +91,27 @@ export function DocSidebar({
89
91
  type="button"
90
92
  data-thumb-page={page}
91
93
  onClick={() => onSelectPage(page)}
92
- className="flex flex-col items-center gap-1"
94
+ aria-label={t('Page {page}', { page })}
95
+ aria-current={page === currentPage ? 'page' : undefined}
96
+ className={cn(
97
+ 'group flex w-full items-start gap-2 rounded-md p-1.5 transition-colors',
98
+ page === currentPage ? 'bg-accent' : 'hover:bg-accent/60',
99
+ )}
93
100
  >
101
+ <span
102
+ className={cn(
103
+ 'w-5 flex-none pt-0.5 text-right font-mono text-[10px] tabular-nums',
104
+ page === currentPage ? 'text-foreground' : 'text-muted-foreground',
105
+ )}
106
+ >
107
+ {String(page).padStart(2, '0')}
108
+ </span>
94
109
  <div
95
110
  className={cn(
96
111
  'overflow-hidden rounded-sm ring-1 transition-shadow',
97
112
  page === currentPage
98
113
  ? 'ring-2 ring-foreground'
99
- : 'ring-border hover:ring-foreground/40',
114
+ : 'ring-border group-hover:ring-foreground/40',
100
115
  )}
101
116
  style={{
102
117
  width: THUMB_WIDTH,
@@ -114,14 +129,6 @@ export function DocSidebar({
114
129
  {entry.content}
115
130
  </PageFrame>
116
131
  </div>
117
- <span
118
- className={cn(
119
- 'font-mono text-[10px] tabular-nums',
120
- page === currentPage ? 'text-foreground' : 'text-muted-foreground',
121
- )}
122
- >
123
- {page}
124
- </span>
125
132
  </button>
126
133
  );
127
134
  })}
@@ -131,8 +138,7 @@ export function DocSidebar({
131
138
  <nav className="flex-1 overflow-y-auto px-2 pb-6">
132
139
  {entries.length === 0 ? (
133
140
  <p className="px-2 py-1 text-muted-foreground text-xs leading-relaxed">
134
- No headings yet. Add an <code className="font-mono">h1</code>/
135
- <code className="font-mono">h2</code> to a page and it shows up here.
141
+ {t('No headings yet.')}
136
142
  </p>
137
143
  ) : (
138
144
  entries.map((entry) => (
@@ -51,10 +51,12 @@ export function FlowPage({
51
51
  blocks?: ReactNode[];
52
52
  notes?: ExtractedNote[];
53
53
  }) {
54
+ const Header = section.header;
54
55
  const Footer = section.footer;
55
56
  const source = blocks ?? section.blocks;
56
57
  return (
57
58
  <div style={flowShellStyle(design, section.padding)}>
59
+ {Header && <Header />}
58
60
  <div style={{ flex: 1, minHeight: 0 }}>
59
61
  {blockIndices.map((index) => (
60
62
  <FlowBlock key={index}>{source[index]}</FlowBlock>
@@ -21,6 +21,7 @@ import {
21
21
  } from 'react';
22
22
  import { createPortal } from 'react-dom';
23
23
  import { isSafeHref } from '../../lib/href';
24
+ import { useT } from '../../lib/i18n';
24
25
  import { candidateLocs, formatLocs } from '../../lib/inspector/fiber';
25
26
  import {
26
27
  cleanRun,
@@ -267,6 +268,7 @@ function TextToolbar({
267
268
  onLinkCancel: () => void;
268
269
  toolbarRef: React.RefObject<HTMLDivElement>;
269
270
  }) {
271
+ const t = useT();
270
272
  const [position, setPosition] = useState<{ left: number; top: number } | null>(null);
271
273
 
272
274
  // Same measuring contract as Frame: after every render, compared by value.
@@ -290,14 +292,14 @@ function TextToolbar({
290
292
  });
291
293
 
292
294
  const title = (label: string, keys: string) =>
293
- emphasis.canFormat ? `${label} (${keys})` : (emphasis.reason ?? label);
295
+ emphasis.canFormat ? `${label} (${keys})` : emphasis.reason ? t(emphasis.reason) : label;
294
296
  const invalid = link !== null && link.value.trim() !== '' && !isSafeHref(link.value.trim());
295
297
 
296
298
  return (
297
299
  <div
298
300
  ref={toolbarRef}
299
301
  role="toolbar"
300
- aria-label="Text formatting"
302
+ aria-label={t('Text formatting')}
301
303
  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
304
  style={position ?? { visibility: 'hidden' }}
303
305
  // Keep focus, and the selection, in the text being edited — except for
@@ -312,9 +314,9 @@ function TextToolbar({
312
314
  // biome-ignore lint/a11y/noAutofocus: the field opens on an explicit request and is the only thing to do next
313
315
  autoFocus
314
316
  type="url"
315
- aria-label="Link address"
317
+ aria-label={t('Link address')}
316
318
  aria-invalid={invalid}
317
- placeholder="https://… or #section"
319
+ placeholder={t('https://… or #section')}
318
320
  value={link.value}
319
321
  onChange={(e) => onLinkChange(e.target.value)}
320
322
  onKeyDown={(e) => {
@@ -326,13 +328,13 @@ function TextToolbar({
326
328
  onLinkCancel();
327
329
  }
328
330
  }}
329
- title={invalid ? 'Only web, mail, phone, or in-document addresses' : undefined}
331
+ title={invalid ? t('Only web, mail, phone, or in-document addresses') : undefined}
330
332
  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
333
  />
332
334
  <button
333
335
  type="button"
334
- aria-label="Apply link"
335
- title="Apply (Enter)"
336
+ aria-label={t('Apply link')}
337
+ title={`${t('Apply')} (Enter)`}
336
338
  disabled={invalid}
337
339
  onClick={onLinkApply}
338
340
  className={TOOL_CLASS}
@@ -342,8 +344,8 @@ function TextToolbar({
342
344
  {link.existing && (
343
345
  <button
344
346
  type="button"
345
- aria-label="Remove link"
346
- title="Remove link"
347
+ aria-label={t('Remove link')}
348
+ title={t('Remove link')}
347
349
  onClick={() => {
348
350
  onLinkChange('');
349
351
  onLinkApply();
@@ -368,10 +370,12 @@ function TextToolbar({
368
370
  <button
369
371
  key={mark}
370
372
  type="button"
371
- aria-label={label}
373
+ aria-label={t(label)}
372
374
  aria-pressed={emphasis[mark]}
373
375
  title={
374
- styled ? 'Already bold — this element’s own style sets it' : title(label, keys)
376
+ styled
377
+ ? t('Already bold — this element’s own style sets it')
378
+ : title(t(label), keys)
375
379
  }
376
380
  disabled={!emphasis.canFormat || styled}
377
381
  onClick={() => onFormat(mark)}
@@ -384,9 +388,15 @@ function TextToolbar({
384
388
  <span aria-hidden className="mx-0.5 h-4 w-px bg-border" />
385
389
  <button
386
390
  type="button"
387
- aria-label="Link"
391
+ aria-label={t('Link')}
388
392
  aria-pressed={emphasis.href !== null}
389
- title={emphasis.linkable ? 'Link (⌘K)' : (emphasis.reason ?? 'Link')}
393
+ title={
394
+ emphasis.linkable
395
+ ? `${t('Link')} (⌘K)`
396
+ : emphasis.reason
397
+ ? t(emphasis.reason)
398
+ : t('Link')
399
+ }
390
400
  disabled={!emphasis.linkable}
391
401
  onClick={onOpenLink}
392
402
  className={TOOL_CLASS}
@@ -395,8 +405,8 @@ function TextToolbar({
395
405
  </button>
396
406
  <button
397
407
  type="button"
398
- aria-label="Clear formatting"
399
- title={title('Clear formatting', '⌘\\')}
408
+ aria-label={t('Clear formatting')}
409
+ title={title(t('Clear formatting'), '⌘\\')}
400
410
  disabled={!emphasis.canFormat}
401
411
  onClick={onClear}
402
412
  className={TOOL_CLASS}
@@ -544,6 +554,7 @@ export function Inspector({
544
554
  onPendingChange,
545
555
  }: Props) {
546
556
  const history = useHistory();
557
+ const t = useT();
547
558
  const nextIdRef = useRef(1);
548
559
  const [container, setContainer] = useState<HTMLElement | null>(null);
549
560
  const [hover, setHover] = useState<HTMLElement | null>(null);
@@ -612,7 +623,9 @@ export function Inspector({
612
623
  const editor = mountEditor(anchor, runs);
613
624
  if (!editor) {
614
625
  setStatus(
615
- 'The text on the page does not line up with its source, so it cannot be edited here.',
626
+ t(
627
+ 'The text on the page does not line up with its source, so it cannot be edited here.',
628
+ ),
616
629
  );
617
630
  return;
618
631
  }
@@ -639,7 +652,7 @@ export function Inspector({
639
652
  setActive(entry);
640
653
  focusAt(entry.editor.clone, pointIn(entry.editor.clone, at), selectWord);
641
654
  },
642
- [],
655
+ [t],
643
656
  );
644
657
 
645
658
  /** Puts an editor's runs back to a snapshot, wherever a reload has since moved it. */
@@ -687,8 +700,8 @@ export function Inspector({
687
700
  for (const entry of [...entriesRef.current.values()]) drop(entry);
688
701
  setActive(null);
689
702
  refresh();
690
- setStatus('Discarded unsaved edits');
691
- }, [drop, refresh]);
703
+ setStatus(t('Discarded unsaved edits'));
704
+ }, [drop, refresh, t]);
692
705
 
693
706
  /**
694
707
  * Leaves the clone in place until hot reload has replaced what it covers —
@@ -843,7 +856,7 @@ export function Inspector({
843
856
  });
844
857
  const body = (await res.json()) as { results?: Outcome[]; error?: string };
845
858
  if (!res.ok || !body.results) {
846
- const error = body.error ?? 'Save failed';
859
+ const error = body.error ?? t('Save failed');
847
860
  setStatus(error);
848
861
  return { ok: false, error };
849
862
  }
@@ -859,19 +872,23 @@ export function Inspector({
859
872
  refresh();
860
873
  setSelected(null);
861
874
  if (failures.length === 0) {
862
- setStatus('Saved to source');
875
+ setStatus(t('Saved to source'));
863
876
  return { ok: true };
864
877
  }
865
- const error = `${failures.length} of ${edits.length} not saved — ${failures[0]?.error ?? 'refused'}`;
878
+ const error = t('{failed} of {total} not saved — {reason}', {
879
+ failed: failures.length,
880
+ total: edits.length,
881
+ reason: failures[0]?.error ?? t('refused'),
882
+ });
866
883
  setStatus(error);
867
884
  return { ok: false, error };
868
885
  } catch {
869
- setStatus('Save failed');
870
- return { ok: false, error: 'Save failed' };
886
+ setStatus(t('Save failed'));
887
+ return { ok: false, error: t('Save failed') };
871
888
  } finally {
872
889
  setBusy(false);
873
890
  }
874
- }, [active, docId, drop, finish, refresh, settle]);
891
+ }, [active, docId, drop, finish, refresh, settle, t]);
875
892
 
876
893
  const leave = useCallback(async () => {
877
894
  if ((await save()).ok) onExit();
@@ -971,7 +988,13 @@ export function Inspector({
971
988
  if (replaced) refresh();
972
989
  if (lost > 0) {
973
990
  setStatus(
974
- `The document reloaded with new text here — ${lost} unsaved edit${lost > 1 ? 's were' : ' was'} lost`,
991
+ lost > 1
992
+ ? t('The document reloaded with new text here — {count} unsaved edits were lost', {
993
+ count: lost,
994
+ })
995
+ : t('The document reloaded with new text here — {count} unsaved edit was lost', {
996
+ count: lost,
997
+ }),
975
998
  );
976
999
  }
977
1000
 
@@ -996,7 +1019,7 @@ export function Inspector({
996
1019
  });
997
1020
  observer.observe(container, { childList: true, subtree: true });
998
1021
  return () => observer.disconnect();
999
- }, [container, refresh]);
1022
+ }, [container, refresh, t]);
1000
1023
 
1001
1024
  useEffect(() => {
1002
1025
  if (!container) return;
@@ -1215,7 +1238,7 @@ export function Inspector({
1215
1238
  const el = clone.querySelector<HTMLElement>(`[data-od-run="${run.index}"]`);
1216
1239
  if (el) run.el = el;
1217
1240
  }
1218
- setStatus('Type inside one run of text — the markup between runs stays as written.');
1241
+ setStatus(t('Type inside one run of text — the markup between runs stays as written.'));
1219
1242
  refresh();
1220
1243
  };
1221
1244
 
@@ -1229,7 +1252,7 @@ export function Inspector({
1229
1252
  clone.removeEventListener('compositionstart', onCompositionStart);
1230
1253
  clone.removeEventListener('compositionend', onCompositionEnd);
1231
1254
  };
1232
- }, [active, finish, refresh, format, openLink, clear]);
1255
+ }, [active, finish, refresh, format, openLink, clear, t]);
1233
1256
 
1234
1257
  // Report the pick to the dev server so `current.json` can answer "this
1235
1258
  // element" for an agent. Clearing the selection clears it there too.
@@ -1284,22 +1307,22 @@ export function Inspector({
1284
1307
  });
1285
1308
  })
1286
1309
  .catch(() => {
1287
- if (!cancelled) setStatus('could not read source');
1310
+ if (!cancelled) setStatus(t('could not read source'));
1288
1311
  });
1289
1312
  return () => {
1290
1313
  cancelled = true;
1291
1314
  };
1292
- }, [selected, docId]);
1315
+ }, [selected, docId, t]);
1293
1316
 
1294
1317
  useEffect(() => {
1295
1318
  if (!wantEdit || !target || selected?.anchor !== wantEdit.anchor) return;
1296
1319
  setWantEdit(null);
1297
1320
  if (!target.editable) {
1298
- setStatus(target.reason ?? 'This text cannot be edited here.');
1321
+ setStatus(target.reason ? t(target.reason) : t('This text cannot be edited here.'));
1299
1322
  return;
1300
1323
  }
1301
1324
  begin(wantEdit.anchor, wantEdit.at, wantEdit.selectWord, target);
1302
- }, [wantEdit, target, selected, begin]);
1325
+ }, [wantEdit, target, selected, begin, t]);
1303
1326
 
1304
1327
  const saveComment = async () => {
1305
1328
  if (!selected || note.trim() === '' || busy) return;
@@ -1319,9 +1342,9 @@ export function Inspector({
1319
1342
  const body = (await res.json()) as { ok?: boolean; error?: string };
1320
1343
  if (res.ok && body.ok) {
1321
1344
  setNote('');
1322
- setStatus('Marked in source — run /apply-comments');
1345
+ setStatus(t('Marked in source — run /apply-comments'));
1323
1346
  } else {
1324
- setStatus(body.error ?? 'Could not add comment');
1347
+ setStatus(body.error ?? t('Could not add comment'));
1325
1348
  }
1326
1349
  } finally {
1327
1350
  setBusy(false);
@@ -1332,10 +1355,10 @@ export function Inspector({
1332
1355
  anchor ? (entriesRef.current.get(anchor)?.editor.clone ?? anchor) : null;
1333
1356
  const selectedEl = visible(selected?.anchor);
1334
1357
  const hint = active
1335
- ? 'Enter to keep · Shift+Enter for a new line · Esc to revert'
1358
+ ? t('Enter to keep · Shift+Enter for a new line · Esc to revert')
1336
1359
  : selected
1337
- ? 'Double-click or Enter to edit text · Esc to deselect'
1338
- : 'Click to select · double-click to edit · Esc to leave';
1360
+ ? t('Double-click or Enter to edit text · Esc to deselect')
1361
+ : t('Click to select · double-click to edit · Esc to leave');
1339
1362
 
1340
1363
  const overlay = container
1341
1364
  ? createPortal(
@@ -1390,7 +1413,7 @@ export function Inspector({
1390
1413
  {overlay}
1391
1414
  {selected && !panelHidden && (
1392
1415
  <PanelShell
1393
- label="Element"
1416
+ label={t('Element')}
1394
1417
  panelRef={panelRef}
1395
1418
  header={
1396
1419
  <span className="truncate font-mono text-[11px] text-muted-foreground">
@@ -1399,14 +1422,14 @@ export function Inspector({
1399
1422
  </span>
1400
1423
  }
1401
1424
  actions={
1402
- <PanelIconButton label="Close" onClick={() => setSelected(null)}>
1425
+ <PanelIconButton label={t('Close')} onClick={() => setSelected(null)}>
1403
1426
  <X className="size-3.5" />
1404
1427
  </PanelIconButton>
1405
1428
  }
1406
1429
  >
1407
1430
  <div className="min-h-0 flex-1 overflow-y-auto p-3">
1408
1431
  <span className="block text-[10px] text-muted-foreground uppercase tracking-wider">
1409
- Text
1432
+ {t('Text')}
1410
1433
  </span>
1411
1434
  {target === null ? (
1412
1435
  <div className="grid h-16 place-items-center">
@@ -1415,19 +1438,23 @@ export function Inspector({
1415
1438
  ) : target.editable ? (
1416
1439
  <p className="mt-1 text-[11px] text-muted-foreground leading-relaxed">
1417
1440
  {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.'}
1441
+ ? t(
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
+ )}
1420
1447
  {target.parts.some((part) => part.kind === 'markup') &&
1421
- ' Inline markup stays as written.'}
1448
+ ` ${t('Inline markup stays as written.')}`}
1422
1449
  </p>
1423
1450
  ) : (
1424
1451
  <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.'}
1452
+ {target.reason ? t(target.reason) : t('Not editable here.')}
1426
1453
  </p>
1427
1454
  )}
1428
1455
 
1429
1456
  <span className="mt-4 block text-[10px] text-muted-foreground uppercase tracking-wider">
1430
- Comment for the agent
1457
+ {t('Comment for the agent')}
1431
1458
  </span>
1432
1459
  <textarea
1433
1460
  value={note}
@@ -1436,7 +1463,7 @@ export function Inspector({
1436
1463
  if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) void saveComment();
1437
1464
  }}
1438
1465
  rows={3}
1439
- placeholder="make this bold, shorten to one line…"
1466
+ placeholder={t('make this bold, shorten to one line…')}
1440
1467
  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"
1441
1468
  />
1442
1469
  <button
@@ -1446,7 +1473,7 @@ export function Inspector({
1446
1473
  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"
1447
1474
  >
1448
1475
  <MessageSquarePlus className="size-3" />
1449
- Mark comment
1476
+ {t('Mark comment')}
1450
1477
  </button>
1451
1478
 
1452
1479
  {status && <p className="mt-2 text-[11px] text-muted-foreground">{status}</p>}
@@ -0,0 +1,38 @@
1
+ import { Languages } from 'lucide-react';
2
+ import { LOCALES, useLocale } from '../lib/i18n';
3
+ import { Menu, MenuItem } from './ui/menu';
4
+
5
+ export function LanguageToggle() {
6
+ const { locale, setLocale, t } = useLocale();
7
+
8
+ return (
9
+ <Menu
10
+ trigger={(props) => (
11
+ <button
12
+ type="button"
13
+ aria-label={t('Language')}
14
+ title={t('Language')}
15
+ className="relative flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground aria-expanded:bg-accent"
16
+ {...props}
17
+ >
18
+ <Languages className="size-3.5" />
19
+ </button>
20
+ )}
21
+ >
22
+ {(close) =>
23
+ LOCALES.map(({ value, label }) => (
24
+ <MenuItem
25
+ key={value}
26
+ active={locale === value}
27
+ onClick={() => {
28
+ setLocale(value);
29
+ close();
30
+ }}
31
+ >
32
+ {label}
33
+ </MenuItem>
34
+ ))
35
+ }
36
+ </Menu>
37
+ );
38
+ }
@@ -0,0 +1,128 @@
1
+ import { FileText, Folder, Image, Languages, Monitor, Moon, Palette, Sun } from 'lucide-react';
2
+ import { docIds, docTitles } from '../lib/docs';
3
+ import { LOCALES, type Locale, type Translate } from '../lib/i18n';
4
+ import type { FoldersManifest } from '../lib/sdk';
5
+ import { themes } from '../lib/themes';
6
+ import type { PaletteItem } from './command-palette';
7
+
8
+ /** What the palette offers everywhere: every document, folder, theme and page, and the appearance. */
9
+ export function browserItems({
10
+ navigate,
11
+ manifest,
12
+ setTheme,
13
+ t,
14
+ setLocale,
15
+ exclude,
16
+ }: {
17
+ navigate: (to: string) => void;
18
+ manifest: FoldersManifest | null;
19
+ setTheme: (theme: string) => void;
20
+ t: Translate;
21
+ /** Offers the languages too; left out where switching would not be expected. */
22
+ setLocale?: (locale: Locale) => void;
23
+ /** A document not to offer — the one already open. */
24
+ exclude?: string;
25
+ }): PaletteItem[] {
26
+ const documents = docIds
27
+ .filter((id) => id !== exclude)
28
+ .map(
29
+ (id): PaletteItem => ({
30
+ id: `doc:${id}`,
31
+ group: t('Documents'),
32
+ label: docTitles[id] ?? id,
33
+ keywords: id,
34
+ icon: FileText,
35
+ run: () => navigate(`/d/${id}`),
36
+ }),
37
+ )
38
+ .sort((a, b) => a.label.localeCompare(b.label));
39
+
40
+ const folders = (manifest?.folders ?? []).map(
41
+ (folder): PaletteItem => ({
42
+ id: `folder:${folder.id}`,
43
+ group: t('Folders'),
44
+ label: folder.name,
45
+ icon: Folder,
46
+ run: () => navigate(`/?f=${encodeURIComponent(folder.id)}`),
47
+ }),
48
+ );
49
+
50
+ const themeItems = themes.map(
51
+ (theme): PaletteItem => ({
52
+ id: `theme:${theme.id}`,
53
+ group: t('Themes'),
54
+ label: theme.name,
55
+ keywords: `${theme.id} theme`,
56
+ icon: Palette,
57
+ run: () => navigate(`/themes/${theme.id}`),
58
+ }),
59
+ );
60
+
61
+ const pages: PaletteItem[] = [
62
+ {
63
+ id: 'go:docs',
64
+ group: t('Go to'),
65
+ label: t('All documents'),
66
+ icon: FileText,
67
+ run: () => navigate('/'),
68
+ },
69
+ {
70
+ id: 'go:themes',
71
+ group: t('Go to'),
72
+ label: t('Themes'),
73
+ icon: Palette,
74
+ run: () => navigate('/themes'),
75
+ },
76
+ ...(import.meta.env.DEV
77
+ ? [
78
+ {
79
+ id: 'go:assets',
80
+ group: t('Go to'),
81
+ label: t('Assets'),
82
+ icon: Image,
83
+ run: () => navigate('/assets'),
84
+ },
85
+ ]
86
+ : []),
87
+ ];
88
+
89
+ const appearance: PaletteItem[] = [
90
+ {
91
+ id: 'theme:light',
92
+ group: t('Appearance'),
93
+ label: t('Light theme'),
94
+ keywords: 'appearance mode',
95
+ icon: Sun,
96
+ run: () => setTheme('light'),
97
+ },
98
+ {
99
+ id: 'theme:dark',
100
+ group: t('Appearance'),
101
+ label: t('Dark theme'),
102
+ keywords: 'appearance mode',
103
+ icon: Moon,
104
+ run: () => setTheme('dark'),
105
+ },
106
+ {
107
+ id: 'theme:system',
108
+ group: t('Appearance'),
109
+ label: t('System theme'),
110
+ keywords: 'appearance mode auto',
111
+ icon: Monitor,
112
+ run: () => setTheme('system'),
113
+ },
114
+ ];
115
+
116
+ const languages: PaletteItem[] = setLocale
117
+ ? LOCALES.map(({ value, label }) => ({
118
+ id: `locale:${value}`,
119
+ group: t('Language'),
120
+ label,
121
+ keywords: 'language 語言',
122
+ icon: Languages,
123
+ run: () => setLocale(value),
124
+ }))
125
+ : [];
126
+
127
+ return [...documents, ...folders, ...pages, ...themeItems, ...appearance, ...languages];
128
+ }
@@ -1,4 +1,5 @@
1
1
  import { type MutableRefObject, useCallback, useEffect, useState } from 'react';
2
+ import { useT } from '../../lib/i18n';
2
3
  import { useDesignPanelState } from '../design-panel/design-provider';
3
4
  import { useHistory } from '../history-provider';
4
5
  import type { InspectorControls } from '../inspector/inspector';
@@ -32,6 +33,7 @@ export function EditSaveCard({
32
33
  }) {
33
34
  const design = useDesignPanelState();
34
35
  const history = useHistory();
36
+ const t = useT();
35
37
  const [committing, setCommitting] = useState(false);
36
38
  const [error, setError] = useState<string | null>(null);
37
39
  const count = textCount + (design.dirty ? 1 : 0);
@@ -46,7 +48,7 @@ export function EditSaveCard({
46
48
  const tokens = design.dirty ? await design.commit() : { ok: true };
47
49
  const failure = text.ok ? tokens : text;
48
50
  if (!failure.ok) {
49
- setError(failure.error ?? 'Not everything was saved');
51
+ setError(failure.error ?? t('Not everything was saved'));
50
52
  return false;
51
53
  }
52
54
  history.clear();
@@ -54,7 +56,7 @@ export function EditSaveCard({
54
56
  } finally {
55
57
  setCommitting(false);
56
58
  }
57
- }, [committing, textCount, controlsRef, design, history]);
59
+ }, [committing, textCount, controlsRef, design, history, t]);
58
60
 
59
61
  const discard = useCallback(() => {
60
62
  controlsRef.current?.discard();