@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
@@ -1,6 +1,10 @@
1
- import { Menu as MenuIcon } from 'lucide-react';
1
+ import { Menu as MenuIcon, Search } from 'lucide-react';
2
+ import { useTheme } from 'next-themes';
2
3
  import { useCallback, useMemo } from 'react';
3
4
  import { Outlet, useLocation, useNavigate, useSearchParams } from 'react-router-dom';
5
+ import { CommandPaletteProvider, useCommandPalette } from '../components/command-palette';
6
+ import { LanguageToggle } from '../components/language-toggle';
7
+ import { browserItems } from '../components/palette-items';
4
8
  import {
5
9
  ALL_DOCS_ID,
6
10
  ASSETS_ID,
@@ -13,6 +17,7 @@ import { Menu, MenuItem } from '../components/ui/menu';
13
17
  import { useAssetCount } from '../lib/assets';
14
18
  import { docIds } from '../lib/docs';
15
19
  import { useFolders } from '../lib/folders';
20
+ import { useLocale, useT } from '../lib/i18n';
16
21
  import type { FoldersManifest } from '../lib/sdk';
17
22
  import { themes } from '../lib/themes';
18
23
 
@@ -83,6 +88,13 @@ export function HomeShell() {
83
88
  return { draftDocs: draft, docsByFolder: byFolder };
84
89
  }, [manifest]);
85
90
 
91
+ const { setTheme } = useTheme();
92
+ const { t, setLocale } = useLocale();
93
+ const paletteItems = useCallback(
94
+ () => browserItems({ navigate, manifest, setTheme, t, setLocale }),
95
+ [navigate, manifest, setTheme, t, setLocale],
96
+ );
97
+
86
98
  const countFor = (folderId: string | null) =>
87
99
  folderId === null ? draftDocs.length : (docsByFolder[folderId]?.length ?? 0);
88
100
 
@@ -99,105 +111,120 @@ export function HomeShell() {
99
111
  deleteDoc,
100
112
  };
101
113
 
102
- const isAssetsRoute = location.pathname === '/assets';
103
-
104
114
  return (
105
- <div className="flex h-dvh overflow-hidden bg-background text-foreground">
106
- <div className="hidden md:block">
107
- <Sidebar
108
- folders={manifest.folders}
109
- countFor={countFor}
110
- allCount={docIds.length}
111
- themesCount={themes.length}
112
- assetsCount={assetCount}
113
- selectedId={selectedId}
114
- onSelect={selectFolder}
115
- onCreate={create}
116
- onRename={(id, name) => update(id, { name })}
117
- onChangeIcon={(id, icon) => update(id, { icon })}
118
- onDelete={async (id) => {
119
- if (selectedId === id) selectFolder(ALL_DOCS_ID);
120
- await remove(id).catch(() => {});
121
- }}
122
- onDropToFolder={(folderId, docId) => void assign(docId, folderId)}
123
- onDropToDraft={(docId) => void assign(docId, null)}
124
- onReorder={(ids) => void reorder(ids).catch(() => {})}
125
- />
126
- </div>
115
+ <CommandPaletteProvider items={paletteItems}>
116
+ <div className="flex h-dvh overflow-hidden bg-background text-foreground">
117
+ <div className="hidden md:block">
118
+ <Sidebar
119
+ folders={manifest.folders}
120
+ countFor={countFor}
121
+ allCount={docIds.length}
122
+ themesCount={themes.length}
123
+ assetsCount={assetCount}
124
+ selectedId={selectedId}
125
+ onSelect={selectFolder}
126
+ onCreate={create}
127
+ onRename={(id, name) => update(id, { name })}
128
+ onChangeIcon={(id, icon) => update(id, { icon })}
129
+ onDelete={async (id) => {
130
+ if (selectedId === id) selectFolder(ALL_DOCS_ID);
131
+ await remove(id).catch(() => {});
132
+ }}
133
+ onDropToFolder={(folderId, docId) => void assign(docId, folderId)}
134
+ onDropToDraft={(docId) => void assign(docId, null)}
135
+ onReorder={(ids) => void reorder(ids).catch(() => {})}
136
+ />
137
+ </div>
127
138
 
128
- <div className="relative flex min-w-0 flex-1 flex-col overflow-y-auto bg-canvas">
129
- <div className="flex items-center justify-between border-border border-b bg-background px-4 py-3 md:hidden">
130
- <h1 className="font-semibold text-base tracking-tight">open-doc</h1>
131
- <div className="-mr-1 flex items-center gap-0.5">
132
- <ThemeToggle />
133
- <Menu
134
- trigger={(props) => (
135
- <button
136
- type="button"
137
- aria-label="Menu"
138
- className="flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground aria-expanded:bg-accent"
139
- {...props}
140
- >
141
- <MenuIcon className="size-4" />
142
- </button>
143
- )}
144
- >
145
- {(close) => (
146
- <>
147
- <MenuItem
148
- active={selectedId !== THEMES_ID && selectedId !== ASSETS_ID}
149
- onClick={() => {
150
- selectFolder(ALL_DOCS_ID);
151
- close();
152
- }}
153
- >
154
- Documents
155
- </MenuItem>
156
- <MenuItem
157
- active={selectedId === DRAFT_ID}
158
- onClick={() => {
159
- selectFolder(DRAFT_ID);
160
- close();
161
- }}
162
- >
163
- Unfiled
164
- </MenuItem>
165
- <MenuItem
166
- active={selectedId === THEMES_ID}
167
- onClick={() => {
168
- selectFolder(THEMES_ID);
169
- close();
170
- }}
139
+ {/* The content sits on its own inset panel, so the sidebar reads as the
140
+ frame around it rather than a column beside it. */}
141
+ <div className="relative flex min-w-0 flex-1 flex-col overflow-y-auto bg-canvas md:my-2 md:mr-2 md:rounded-xl md:border md:border-border">
142
+ <div className="flex items-center justify-between border-border border-b bg-background px-4 py-3 md:hidden">
143
+ <h1 className="font-semibold text-base tracking-tight">open-doc</h1>
144
+ <div className="-mr-1 flex items-center gap-0.5">
145
+ <MobileSearch />
146
+ <LanguageToggle />
147
+ <ThemeToggle />
148
+ <Menu
149
+ trigger={(props) => (
150
+ <button
151
+ type="button"
152
+ aria-label={t('Menu')}
153
+ className="flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground aria-expanded:bg-accent"
154
+ {...props}
171
155
  >
172
- Themes
173
- </MenuItem>
174
- {import.meta.env.DEV && (
156
+ <MenuIcon className="size-4" />
157
+ </button>
158
+ )}
159
+ >
160
+ {(close) => (
161
+ <>
162
+ <MenuItem
163
+ active={selectedId !== THEMES_ID && selectedId !== ASSETS_ID}
164
+ onClick={() => {
165
+ selectFolder(ALL_DOCS_ID);
166
+ close();
167
+ }}
168
+ >
169
+ {t('Documents')}
170
+ </MenuItem>
175
171
  <MenuItem
176
- active={selectedId === ASSETS_ID}
172
+ active={selectedId === DRAFT_ID}
177
173
  onClick={() => {
178
- selectFolder(ASSETS_ID);
174
+ selectFolder(DRAFT_ID);
179
175
  close();
180
176
  }}
181
177
  >
182
- Assets
178
+ {t('Unfiled')}
183
179
  </MenuItem>
184
- )}
185
- </>
186
- )}
187
- </Menu>
180
+ <MenuItem
181
+ active={selectedId === THEMES_ID}
182
+ onClick={() => {
183
+ selectFolder(THEMES_ID);
184
+ close();
185
+ }}
186
+ >
187
+ {t('Themes')}
188
+ </MenuItem>
189
+ {import.meta.env.DEV && (
190
+ <MenuItem
191
+ active={selectedId === ASSETS_ID}
192
+ onClick={() => {
193
+ selectFolder(ASSETS_ID);
194
+ close();
195
+ }}
196
+ >
197
+ {t('Assets')}
198
+ </MenuItem>
199
+ )}
200
+ </>
201
+ )}
202
+ </Menu>
203
+ </div>
188
204
  </div>
189
- </div>
190
205
 
191
- <div
192
- className={
193
- isAssetsRoute
194
- ? 'flex min-h-0 flex-1 flex-col'
195
- : 'mx-auto w-full max-w-[1180px] px-5 py-8 md:px-10 md:py-10'
196
- }
197
- >
198
- <Outlet context={ctx} />
206
+ {/* One frame for every page of the browser, so Documents, Themes and
207
+ Assets share their edges; the pages add no padding of their own. */}
208
+ <div className="mx-auto w-full max-w-[1180px] px-5 py-8 md:px-10 md:py-10">
209
+ <Outlet context={ctx} />
210
+ </div>
199
211
  </div>
200
212
  </div>
201
- </div>
213
+ </CommandPaletteProvider>
214
+ );
215
+ }
216
+
217
+ function MobileSearch() {
218
+ const t = useT();
219
+ const palette = useCommandPalette();
220
+ return (
221
+ <button
222
+ type="button"
223
+ aria-label={t('Search')}
224
+ onClick={palette.open}
225
+ className="flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground"
226
+ >
227
+ <Search className="size-4" />
228
+ </button>
202
229
  );
203
230
  }
@@ -1,94 +1,210 @@
1
1
  import {
2
+ ArrowDownAZ,
3
+ ArrowUpAZ,
4
+ Check,
5
+ ChevronDown,
6
+ Clock,
2
7
  Copy,
3
8
  FileText,
9
+ Folder,
4
10
  FolderInput,
11
+ Inbox,
5
12
  MoreHorizontal,
6
13
  Palette,
7
14
  PencilLine,
15
+ Search,
8
16
  Trash2,
9
17
  } from 'lucide-react';
10
18
  import { useMemo, useState } from 'react';
11
19
  import { Link, useNavigate, useOutletContext } from 'react-router-dom';
20
+ import {
21
+ CARD_GRID,
22
+ CardText,
23
+ EmptyState,
24
+ PageHeader,
25
+ useCardWidth,
26
+ } from '../components/browser/browser-ui';
12
27
  import { PageFrame } from '../components/page-frame';
13
28
  import { DOC_DND_MIME } from '../components/sidebar/folder-item';
14
29
  import { ALL_DOCS_ID, DRAFT_ID } from '../components/sidebar/sidebar';
15
30
  import { Menu, MenuItem, MenuSeparator } from '../components/ui/menu';
16
- import { coverContent, pageCountLabel } from '../lib/doc-preview';
17
- import { docCreatedAt, docIds, docThemes } from '../lib/docs';
31
+ import { coverContent } from '../lib/doc-preview';
32
+ import { docCreatedAt, docIds, docThemes, docTitles } from '../lib/docs';
33
+ import { type Translate, useLocale, useT } from '../lib/i18n';
18
34
  import { resolvePageGeometry } from '../lib/sdk';
19
35
  import { findTheme } from '../lib/themes';
20
36
  import { useDocModule } from '../lib/use-doc-module';
21
37
  import type { HomeOutletContext } from './home-shell';
22
38
 
23
- const THUMB_WIDTH = 190;
39
+ /** Sheet and date, the two facts that tell documents apart at a glance. */
40
+ function cardMeta(
41
+ t: Translate,
42
+ locale: string,
43
+ pageSize: string,
44
+ landscape: boolean,
45
+ createdAt: number | undefined,
46
+ ): string {
47
+ const sheet = landscape ? t('{size} landscape', { size: pageSize }) : pageSize;
48
+ if (!createdAt) return sheet;
49
+ const date = new Date(createdAt).toLocaleDateString(locale, {
50
+ year: 'numeric',
51
+ month: 'short',
52
+ day: 'numeric',
53
+ });
54
+ return `${sheet} · ${date}`;
55
+ }
56
+
57
+ const SORTS = [
58
+ { key: 'newest', label: 'Newest', icon: Clock },
59
+ { key: 'oldest', label: 'Oldest', icon: Clock },
60
+ { key: 'az', label: 'A–Z', icon: ArrowDownAZ },
61
+ { key: 'za', label: 'Z–A', icon: ArrowUpAZ },
62
+ ] as const;
63
+ type SortKey = (typeof SORTS)[number]['key'];
64
+
65
+ const SORT_STORAGE = 'open-doc:sort';
66
+
67
+ function readSort(): SortKey {
68
+ try {
69
+ const stored = localStorage.getItem(SORT_STORAGE);
70
+ return SORTS.some((sort) => sort.key === stored) ? (stored as SortKey) : 'newest';
71
+ } catch {
72
+ return 'newest';
73
+ }
74
+ }
75
+
76
+ const titleOf = (id: string) => docTitles[id] ?? id;
77
+
78
+ function compare(sort: SortKey) {
79
+ return (a: string, b: string): number => {
80
+ if (sort === 'az') return titleOf(a).localeCompare(titleOf(b));
81
+ if (sort === 'za') return titleOf(b).localeCompare(titleOf(a));
82
+ const at = docCreatedAt[a] ?? 0;
83
+ const bt = docCreatedAt[b] ?? 0;
84
+ if (at !== bt) return sort === 'newest' ? bt - at : at - bt;
85
+ return a.localeCompare(b);
86
+ };
87
+ }
24
88
 
25
89
  export function Home() {
90
+ const t = useT();
26
91
  const ctx = useOutletContext<HomeOutletContext>();
27
92
  const [error, setError] = useState<string | null>(null);
93
+ const [sort, setSortState] = useState<SortKey>(readSort);
94
+ const [filter, setFilter] = useState('');
95
+
96
+ const setSort = (next: SortKey) => {
97
+ setSortState(next);
98
+ try {
99
+ localStorage.setItem(SORT_STORAGE, next);
100
+ } catch {}
101
+ };
28
102
 
29
103
  const folder = ctx.manifest.folders.find((f) => f.id === ctx.selectedId);
104
+ const sourceIds =
105
+ ctx.selectedId === ALL_DOCS_ID
106
+ ? docIds
107
+ : ctx.selectedId === DRAFT_ID
108
+ ? ctx.draftDocs
109
+ : (ctx.docsByFolder[ctx.selectedId] ?? []);
30
110
  const visibleIds = useMemo(() => {
31
- const source =
32
- ctx.selectedId === ALL_DOCS_ID
33
- ? [...docIds]
34
- : ctx.selectedId === DRAFT_ID
35
- ? [...ctx.draftDocs]
36
- : [...(ctx.docsByFolder[ctx.selectedId] ?? [])];
37
- return source.sort((a, b) => {
38
- const at = docCreatedAt[a] ?? 0;
39
- const bt = docCreatedAt[b] ?? 0;
40
- if (at !== bt) return bt - at;
41
- return a.localeCompare(b);
42
- });
43
- }, [ctx.selectedId, ctx.draftDocs, ctx.docsByFolder]);
111
+ const words = filter.trim().toLowerCase().split(/\s+/).filter(Boolean);
112
+ return sourceIds
113
+ .filter((id) => {
114
+ const haystack = `${titleOf(id)} ${id}`.toLowerCase();
115
+ return words.every((word) => haystack.includes(word));
116
+ })
117
+ .sort(compare(sort));
118
+ }, [sourceIds, filter, sort]);
119
+ const currentSort = SORTS.find((entry) => entry.key === sort) ?? SORTS[0];
44
120
 
45
121
  const heading =
46
122
  ctx.selectedId === ALL_DOCS_ID
47
- ? 'Documents'
123
+ ? t('Documents')
48
124
  : ctx.selectedId === DRAFT_ID
49
- ? 'Unfiled'
50
- : (folder?.name ?? 'Documents');
125
+ ? t('Unfiled')
126
+ : (folder?.name ?? t('Documents'));
51
127
 
52
128
  return (
53
129
  <div>
54
- <header className="mb-8">
55
- <h1 className="font-medium text-lg tracking-tight">{heading}</h1>
56
- <p className="mt-1 text-muted-foreground text-sm">
57
- {ctx.selectedId === ALL_DOCS_ID ? (
130
+ <PageHeader
131
+ title={heading}
132
+ icon={
133
+ ctx.selectedId === ALL_DOCS_ID ? FileText : ctx.selectedId === DRAFT_ID ? Inbox : Folder
134
+ }
135
+ count={sourceIds.length}
136
+ actions={
137
+ sourceIds.length > 0 && (
58
138
  <>
59
- Every folder under <code className="font-mono">docs/</code> with an{' '}
60
- <code className="font-mono">index.tsx</code>.
139
+ <Menu
140
+ placement="bottom-end"
141
+ trigger={(props) => (
142
+ <button
143
+ type="button"
144
+ aria-label={t('Sort: {label}', { label: t(currentSort.label) })}
145
+ className="flex h-8 items-center gap-1.5 rounded-md border border-border bg-background px-2.5 text-xs transition-colors hover:bg-accent aria-expanded:bg-accent"
146
+ {...props}
147
+ >
148
+ <currentSort.icon className="size-3.5 text-muted-foreground" />
149
+ {t(currentSort.label)}
150
+ <ChevronDown className="size-3 text-muted-foreground" />
151
+ </button>
152
+ )}
153
+ >
154
+ {(close) =>
155
+ SORTS.map((entry) => (
156
+ <MenuItem
157
+ key={entry.key}
158
+ active={entry.key === sort}
159
+ onClick={() => {
160
+ setSort(entry.key);
161
+ close();
162
+ }}
163
+ >
164
+ <entry.icon className="size-3.5" />
165
+ <span className="flex-1">{t(entry.label)}</span>
166
+ {entry.key === sort && <Check className="size-3.5" />}
167
+ </MenuItem>
168
+ ))
169
+ }
170
+ </Menu>
171
+ <label className="flex h-8 w-56 items-center gap-2 rounded-md border border-border bg-background px-2.5 text-xs focus-within:border-foreground focus-within:ring-2 focus-within:ring-primary/30">
172
+ <Search className="size-3.5 flex-none text-muted-foreground" />
173
+ <input
174
+ type="search"
175
+ value={filter}
176
+ onChange={(event) => setFilter(event.target.value)}
177
+ placeholder={t('Filter documents')}
178
+ aria-label={t('Filter documents')}
179
+ className="min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground"
180
+ />
181
+ </label>
61
182
  </>
62
- ) : ctx.selectedId === DRAFT_ID ? (
63
- 'Documents that have not been filed into a folder yet.'
64
- ) : (
65
- `${visibleIds.length} document${visibleIds.length === 1 ? '' : 's'} in this folder.`
66
- )}
67
- </p>
183
+ )
184
+ }
185
+ >
68
186
  {error && (
69
- <p className="mt-3 rounded-md border border-border bg-background px-3 py-2 text-xs">
187
+ <p
188
+ role="alert"
189
+ className="rounded-md border border-border bg-background px-3 py-2 text-xs"
190
+ >
70
191
  {error}
71
192
  </p>
72
193
  )}
73
- </header>
194
+ </PageHeader>
74
195
 
75
- {visibleIds.length === 0 ? (
76
- <div className="py-16 text-center">
77
- <FileText className="mx-auto size-6 text-muted-foreground" />
78
- <p className="mt-3 font-medium text-sm">Nothing here yet</p>
79
- <p className="mt-1 text-muted-foreground text-xs">
80
- {ctx.selectedId === ALL_DOCS_ID ? (
81
- <>
82
- Create <code className="font-mono">docs/&lt;id&gt;/index.tsx</code> and it appears
83
- here.
84
- </>
85
- ) : (
86
- 'Drag a document onto this folder in the sidebar to file it here.'
87
- )}
88
- </p>
89
- </div>
196
+ {visibleIds.length === 0 && sourceIds.length > 0 ? (
197
+ <EmptyState icon={Search} title={t('Nothing matches “{query}”', { query: filter.trim() })}>
198
+ {t('Try another word from the title.')}
199
+ </EmptyState>
200
+ ) : visibleIds.length === 0 ? (
201
+ <EmptyState icon={FileText} title={t('Nothing here yet')}>
202
+ {ctx.selectedId === ALL_DOCS_ID
203
+ ? t('Ask your agent to write a document, and it appears here.')
204
+ : t('Drag a document onto this folder, or use Move to on its card.')}
205
+ </EmptyState>
90
206
  ) : (
91
- <div className="grid gap-7 [grid-template-columns:repeat(auto-fill,minmax(190px,1fr))]">
207
+ <div className={CARD_GRID}>
92
208
  {visibleIds.map((id) => (
93
209
  <DocCard key={id} docId={id} ctx={ctx} onError={setError} />
94
210
  ))}
@@ -107,11 +223,14 @@ function DocCard({
107
223
  ctx: HomeOutletContext;
108
224
  onError: (message: string | null) => void;
109
225
  }) {
226
+ const t = useT();
227
+ const { locale } = useLocale();
110
228
  const navigate = useNavigate();
229
+ const [cardRef, cardWidth] = useCardWidth<HTMLDivElement>();
111
230
  const state = useDocModule(docId);
112
231
  const doc = state.doc;
113
232
  const geometry = resolvePageGeometry(doc?.meta);
114
- const scale = THUMB_WIDTH / geometry.width;
233
+ const scale = cardWidth / geometry.width;
115
234
  const cover = coverContent(doc);
116
235
  const theme = findTheme(docThemes[docId]);
117
236
  const title = doc?.meta?.title ?? docId;
@@ -129,7 +248,8 @@ function DocCard({
129
248
  return (
130
249
  // biome-ignore lint/a11y/noStaticElementInteractions: dragging files a document — the card menu's "Move to" is the keyboard path
131
250
  <div
132
- className="group flex flex-col gap-2.5"
251
+ ref={cardRef}
252
+ className="group flex min-w-0 flex-col gap-2.5"
133
253
  draggable={import.meta.env.DEV}
134
254
  onDragStart={(e) => {
135
255
  if (!import.meta.env.DEV) return;
@@ -140,7 +260,7 @@ function DocCard({
140
260
  <Link to={`/d/${docId}`}>
141
261
  <div
142
262
  className="overflow-hidden rounded-md ring-1 ring-border transition-shadow group-hover:shadow-lg"
143
- style={{ width: THUMB_WIDTH, height: geometry.height * scale }}
263
+ style={{ width: cardWidth, height: geometry.height * scale }}
144
264
  >
145
265
  {cover ? (
146
266
  <PageFrame
@@ -161,12 +281,20 @@ function DocCard({
161
281
 
162
282
  <div className="flex min-w-0 items-start gap-1">
163
283
  <div className="min-w-0 flex-1">
164
- <Link to={`/d/${docId}`} className="block truncate font-medium text-sm hover:underline">
165
- {title}
166
- </Link>
167
- <p className="mt-0.5 truncate text-muted-foreground text-xs">
168
- {pageCountLabel(doc)} · {doc?.meta?.pageSize ?? 'A4'}
169
- </p>
284
+ <CardText
285
+ title={
286
+ <Link to={`/d/${docId}`} className="hover:underline">
287
+ {title}
288
+ </Link>
289
+ }
290
+ meta={cardMeta(
291
+ t,
292
+ locale,
293
+ doc?.meta?.pageSize ?? 'A4',
294
+ doc?.meta?.orientation === 'landscape',
295
+ docCreatedAt[docId],
296
+ )}
297
+ />
170
298
  {theme && (
171
299
  <Link
172
300
  to={`/themes/${theme.id}`}
@@ -183,8 +311,8 @@ function DocCard({
183
311
  trigger={(props) => (
184
312
  <button
185
313
  type="button"
186
- aria-label={`${title} options`}
187
- className="flex size-6 flex-none items-center justify-center rounded text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100 aria-expanded:opacity-100"
314
+ aria-label={t('{name} options', { name: title })}
315
+ className="flex size-7 flex-none items-center justify-center rounded text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100 aria-expanded:opacity-100"
188
316
  {...props}
189
317
  >
190
318
  <MoreHorizontal className="size-3.5" />
@@ -196,12 +324,12 @@ function DocCard({
196
324
  <MenuItem
197
325
  onClick={() => {
198
326
  close();
199
- const next = window.prompt('Document title', title);
327
+ const next = window.prompt(t('Document title'), title);
200
328
  if (next && next !== title) void run(() => ctx.renameDoc(docId, next));
201
329
  }}
202
330
  >
203
331
  <PencilLine className="size-3.5" />
204
- Rename
332
+ {t('Rename')}
205
333
  </MenuItem>
206
334
  <MenuItem
207
335
  onClick={() => {
@@ -213,12 +341,12 @@ function DocCard({
213
341
  }}
214
342
  >
215
343
  <Copy className="size-3.5" />
216
- Duplicate
344
+ {t('Duplicate')}
217
345
  </MenuItem>
218
346
 
219
347
  <MenuSeparator />
220
348
  <p className="px-2 py-1 text-[10px] text-muted-foreground uppercase tracking-wider">
221
- Move to
349
+ {t('Move to')}
222
350
  </p>
223
351
  <MenuItem
224
352
  active={!currentFolder}
@@ -228,7 +356,7 @@ function DocCard({
228
356
  }}
229
357
  >
230
358
  <FolderInput className="size-3.5" />
231
- Unfiled
359
+ {t('Unfiled')}
232
360
  </MenuItem>
233
361
  {ctx.manifest.folders.map((folder) => (
234
362
  <MenuItem
@@ -250,14 +378,19 @@ function DocCard({
250
378
  onClick={() => {
251
379
  close();
252
380
  if (
253
- !window.confirm(`Delete "${title}"? This removes docs/${docId}/ from disk.`)
381
+ !window.confirm(
382
+ t('Delete "{title}"? This removes docs/{id}/ from disk.', {
383
+ title,
384
+ id: docId,
385
+ }),
386
+ )
254
387
  )
255
388
  return;
256
389
  void run(() => ctx.deleteDoc(docId));
257
390
  }}
258
391
  >
259
392
  <Trash2 className="size-3.5" />
260
- Delete document
393
+ {t('Delete document')}
261
394
  </MenuItem>
262
395
  </>
263
396
  )}