@open-document/core 0.9.0 → 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 (88) hide show
  1. package/dist/{build-CFL7nhz0.js → build-DJMLK50m.js} +1 -1
  2. package/dist/{check-CL0-0eB8.js → check-CUKuufBm.js} +3 -3
  3. package/dist/cli/bin.js +10 -6
  4. package/dist/{config-4nz5NnxW.js → config-CvzpyAUA.js} +558 -546
  5. package/dist/{context-BH8C-dSW.js → context-B4ip7SoI.js} +1 -1
  6. package/dist/{dev-BCSUczXW.js → dev-dnH7DTlD.js} +1 -1
  7. package/dist/{diagram-xlVDekYk.js → diagram-BK4jTZr4.js} +231 -158
  8. package/dist/diff-QTo0A5Rx.js +44 -0
  9. package/dist/{export-CmVJdl9a.js → export-BrRFrexj.js} +3 -3
  10. package/dist/{import-E6vRo7xm.js → import-C14Vn9ER.js} +2 -2
  11. package/dist/index.d.ts +54 -3
  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-OZZVBgsM.js → ops-DKidjLXP.js} +642 -124
  16. package/dist/{preview-CwCrw-i3.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 +13 -6
  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/export-dom.ts +4 -0
  54. package/src/app/lib/export-image.ts +2 -0
  55. package/src/app/lib/export-pdf.ts +6 -0
  56. package/src/app/lib/flow-measure.ts +3 -0
  57. package/src/app/lib/flow.ts +1 -1
  58. package/src/app/lib/i18n-ja/browser.ts +88 -0
  59. package/src/app/lib/i18n-ja/doc.ts +65 -0
  60. package/src/app/lib/i18n-ja/index.ts +5 -0
  61. package/src/app/lib/i18n-ja/panels.ts +104 -0
  62. package/src/app/lib/i18n-ko/browser.ts +87 -0
  63. package/src/app/lib/i18n-ko/doc.ts +65 -0
  64. package/src/app/lib/i18n-ko/index.ts +5 -0
  65. package/src/app/lib/i18n-ko/panels.ts +102 -0
  66. package/src/app/lib/i18n-zh-cn/browser.ts +84 -0
  67. package/src/app/lib/i18n-zh-cn/doc.ts +64 -0
  68. package/src/app/lib/i18n-zh-cn/index.ts +5 -0
  69. package/src/app/lib/i18n-zh-cn/panels.ts +98 -0
  70. package/src/app/lib/i18n-zh-tw/browser.ts +84 -0
  71. package/src/app/lib/i18n-zh-tw/doc.ts +64 -0
  72. package/src/app/lib/i18n-zh-tw/index.ts +5 -0
  73. package/src/app/lib/i18n-zh-tw/panels.ts +99 -0
  74. package/src/app/lib/i18n.test.ts +24 -0
  75. package/src/app/lib/i18n.tsx +109 -0
  76. package/src/app/lib/outline.ts +23 -0
  77. package/src/app/lib/page-range.test.ts +10 -1
  78. package/src/app/lib/page-range.ts +26 -0
  79. package/src/app/lib/sdk.ts +2 -0
  80. package/src/app/lib/svg-ids.ts +37 -0
  81. package/src/app/main.tsx +4 -1
  82. package/src/app/routes/assets.tsx +193 -132
  83. package/src/app/routes/doc.tsx +666 -310
  84. package/src/app/routes/home-shell.tsx +115 -88
  85. package/src/app/routes/home.tsx +200 -67
  86. package/src/app/routes/themes.tsx +42 -35
  87. package/src/app/styles.css +99 -0
  88. package/src/app/virtual.d.ts +1 -0
@@ -0,0 +1,109 @@
1
+ import {
2
+ createContext,
3
+ type ReactNode,
4
+ useCallback,
5
+ useContext,
6
+ useEffect,
7
+ useMemo,
8
+ useRef,
9
+ useState,
10
+ } from 'react';
11
+ import { JA } from './i18n-ja';
12
+ import { KO } from './i18n-ko';
13
+ import { ZH_CN } from './i18n-zh-cn';
14
+ import { ZH_TW } from './i18n-zh-tw';
15
+
16
+ /**
17
+ * The viewer chrome in English, Chinese, Japanese or Korean. The English text is the
18
+ * key, so a string with no translation yet still reads — in English — instead
19
+ * of showing a key. Only the chrome is translated: what prints on the page is
20
+ * the document's, and `meta.labels` already decides what a figure is called.
21
+ */
22
+ export const LOCALES = [
23
+ { value: 'en', label: 'English' },
24
+ { value: 'zh-TW', label: '繁體中文' },
25
+ { value: 'zh-CN', label: '简体中文' },
26
+ { value: 'ja', label: '日本語' },
27
+ { value: 'ko', label: '한국어' },
28
+ ] as const;
29
+ export type Locale = (typeof LOCALES)[number]['value'];
30
+
31
+ const STORAGE = 'open-doc:locale';
32
+ export const DICTIONARIES: Record<Locale, Record<string, string>> = {
33
+ en: {},
34
+ 'zh-TW': ZH_TW,
35
+ 'zh-CN': ZH_CN,
36
+ ja: JA,
37
+ ko: KO,
38
+ };
39
+
40
+ const isLocale = (value: string | null): value is Locale =>
41
+ LOCALES.some((entry) => entry.value === value);
42
+
43
+ /** The reader's browser language, mapped onto a locale we have; Chinese splits by script. */
44
+ function browserLocale(language: string): Locale {
45
+ if (/^zh-(TW|HK|MO)\b|^zh-Hant/i.test(language)) return 'zh-TW';
46
+ if (/^zh/i.test(language)) return 'zh-CN';
47
+ if (/^ja/i.test(language)) return 'ja';
48
+ if (/^ko/i.test(language)) return 'ko';
49
+ return 'en';
50
+ }
51
+
52
+ function initialLocale(): Locale {
53
+ try {
54
+ const stored = localStorage.getItem(STORAGE);
55
+ if (isLocale(stored)) return stored;
56
+ } catch {}
57
+ return typeof navigator === 'undefined' ? 'en' : browserLocale(navigator.language);
58
+ }
59
+
60
+ export type Translate = (text: string, vars?: Record<string, string | number>) => string;
61
+
62
+ function translate(locale: Locale, text: string, vars?: Record<string, string | number>): string {
63
+ const template = DICTIONARIES[locale][text] ?? text;
64
+ if (!vars) return template;
65
+ return template.replace(/\{(\w+)\}/g, (whole, name: string) =>
66
+ name in vars ? String(vars[name]) : whole,
67
+ );
68
+ }
69
+
70
+ type LocaleState = { locale: Locale; setLocale: (locale: Locale) => void; t: Translate };
71
+
72
+ const LocaleContext = createContext<LocaleState>({
73
+ locale: 'en',
74
+ setLocale: () => {},
75
+ t: (text, vars) => translate('en', text, vars),
76
+ });
77
+
78
+ export function LocaleProvider({ children }: { children: ReactNode }) {
79
+ const [locale, setLocaleState] = useState<Locale>(initialLocale);
80
+
81
+ useEffect(() => {
82
+ document.documentElement.lang = locale;
83
+ }, [locale]);
84
+
85
+ const setLocale = useCallback((next: Locale) => {
86
+ setLocaleState(next);
87
+ try {
88
+ localStorage.setItem(STORAGE, next);
89
+ } catch {}
90
+ }, []);
91
+
92
+ // `t` keeps one identity for the app's lifetime and reads the locale when
93
+ // called. Components still re-render on a switch — the context value changes —
94
+ // but an effect that lists `t` does not re-run, so switching language never
95
+ // tears down an edit in progress or refetches what the inspector holds.
96
+ const localeRef = useRef(locale);
97
+ localeRef.current = locale;
98
+ const t = useCallback<Translate>((text, vars) => translate(localeRef.current, text, vars), []);
99
+ const value = useMemo(() => ({ locale, setLocale, t }), [locale, setLocale, t]);
100
+ return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>;
101
+ }
102
+
103
+ export function useLocale(): LocaleState {
104
+ return useContext(LocaleContext);
105
+ }
106
+
107
+ export function useT(): Translate {
108
+ return useContext(LocaleContext).t;
109
+ }
@@ -58,6 +58,29 @@ export function collectOutline(root: ParentNode): OutlineEntry[] {
58
58
  return entries;
59
59
  }
60
60
 
61
+ /**
62
+ * A PDF's bookmarks and heading tags are built from the accessibility tree,
63
+ * which knows nothing of the outline's rules: it would list the cover title,
64
+ * "Contents", every h4, and the long text of a heading the author shortened.
65
+ * This marks the copy so the tree says what the outline says — every listed
66
+ * heading as a heading at its outline level and with its outline text, every
67
+ * other heading as plain text.
68
+ */
69
+ export function exposeOutline(root: ParentNode): void {
70
+ const listed = new Set(collectOutline(root).map((entry) => entry.id));
71
+ for (const el of Array.from(
72
+ root.querySelectorAll<HTMLElement>('h1, h2, h3, h4, h5, h6, [data-od-heading]'),
73
+ )) {
74
+ if (el.id && listed.has(el.id)) {
75
+ el.setAttribute('role', 'heading');
76
+ el.setAttribute('aria-level', String(levelOf(el)));
77
+ el.setAttribute('aria-label', textOf(el));
78
+ } else {
79
+ el.setAttribute('role', 'none');
80
+ }
81
+ }
82
+ }
83
+
61
84
  // Shared through globalThis for the same reason as the page context: the
62
85
  // viewer writes the outline from the source copy of this module, while a
63
86
  // document's `<TableOfContents>` reads it from the published bundle.
@@ -9,7 +9,7 @@
9
9
  */
10
10
 
11
11
  import { describe, expect, it } from 'vitest';
12
- import { describeSelection, parseRange, resolveSelection } from './page-range';
12
+ import { describeSelection, formatPages, parseRange, resolveSelection } from './page-range';
13
13
 
14
14
  describe('parseRange', () => {
15
15
  it('reads single pages, one-based', () => {
@@ -93,3 +93,12 @@ describe('describeSelection', () => {
93
93
  });
94
94
  });
95
95
  });
96
+
97
+ describe('formatPages', () => {
98
+ it('writes runs back the way a reader types them', () => {
99
+ expect(formatPages([0, 1, 2, 5])).toBe('1–3, 6');
100
+ expect(formatPages([4])).toBe('5');
101
+ expect(formatPages([0, 2, 4])).toBe('1, 3, 5');
102
+ expect(formatPages([])).toBe('');
103
+ });
104
+ });
@@ -85,6 +85,32 @@ export function describeSelection(
85
85
  return { count: pages?.length ?? 0, valid: pages !== null };
86
86
  }
87
87
 
88
+ /**
89
+ * Zero-based indices as the reader would write them back: `[0,1,2,5]` →
90
+ * `1–3, 6`. Shown under the range field so a typo is caught before the
91
+ * download, not after.
92
+ */
93
+ export function formatPages(indices: number[]): string {
94
+ const runs: string[] = [];
95
+ let start: number | undefined;
96
+ let prev: number | undefined;
97
+ const flush = () => {
98
+ if (start === undefined || prev === undefined) return;
99
+ runs.push(start === prev ? `${start + 1}` : `${start + 1}–${prev + 1}`);
100
+ };
101
+ for (const index of indices) {
102
+ if (prev !== undefined && index === prev + 1) {
103
+ prev = index;
104
+ continue;
105
+ }
106
+ flush();
107
+ start = index;
108
+ prev = index;
109
+ }
110
+ flush();
111
+ return runs.join(', ');
112
+ }
113
+
88
114
  function clamp(value: number, min: number, max: number): number {
89
115
  return Math.min(max, Math.max(min, value));
90
116
  }
@@ -55,6 +55,8 @@ export type DocPage = ComponentType;
55
55
  export type FlowSection = {
56
56
  readonly __odFlow: true;
57
57
  blocks: ReactNode[];
58
+ /** Rendered on every page the section expands into, in the top margin band. */
59
+ header?: ComponentType;
58
60
  /** Rendered on every page the section expands into. */
59
61
  footer?: ComponentType;
60
62
  /** Page padding override in px; defaults to the design's `margin`. */
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A page is drawn more than once — the thumbnail rail, the viewer, the print
3
+ * copy, an export's offscreen copy — and an inline SVG's `id` comes along each
4
+ * time. `url(#glow)` resolves to the *first* element in the document with that
5
+ * id, which is the thumbnail's. When printing hides the rail, the print copy's
6
+ * gradients, clip paths and markers point into a subtree that is not drawn,
7
+ * and they vanish from the PDF. Renaming the ids inside a copy, and every
8
+ * reference to them inside the same copy, keeps each copy pointing at itself.
9
+ */
10
+
11
+ const URL_REF = /url\(\s*(['"]?)#([^'")\s]+)\1\s*\)/g;
12
+
13
+ export function scopeSvgIds(root: Element, suffix: string): void {
14
+ const renamed = new Map<string, string>();
15
+ for (const el of Array.from(root.querySelectorAll('svg [id]'))) {
16
+ const next = `${el.id}--${suffix}`;
17
+ renamed.set(el.id, next);
18
+ el.id = next;
19
+ }
20
+ if (renamed.size === 0) return;
21
+
22
+ for (const el of Array.from(root.querySelectorAll('svg, svg *'))) {
23
+ for (const attr of Array.from(el.attributes)) {
24
+ let value = attr.value;
25
+ if ((attr.localName === 'href' || attr.name === 'xlink:href') && value.startsWith('#')) {
26
+ const target = renamed.get(value.slice(1));
27
+ if (target) value = `#${target}`;
28
+ } else if (value.includes('url(')) {
29
+ value = value.replace(URL_REF, (whole, quote: string, id: string) => {
30
+ const target = renamed.get(id);
31
+ return target ? `url(${quote}#${target}${quote})` : whole;
32
+ });
33
+ }
34
+ if (value !== attr.value) el.setAttributeNS(attr.namespaceURI, attr.name, value);
35
+ }
36
+ }
37
+ }
package/src/app/main.tsx CHANGED
@@ -2,13 +2,16 @@ import { ThemeProvider } from 'next-themes';
2
2
  import { StrictMode } from 'react';
3
3
  import { createRoot } from 'react-dom/client';
4
4
  import { App } from './app';
5
+ import { LocaleProvider } from './lib/i18n';
5
6
  import './styles.css';
6
7
 
7
8
  // biome-ignore lint/style/noNonNullAssertion: #root is guaranteed by index.html
8
9
  createRoot(document.getElementById('root')!).render(
9
10
  <StrictMode>
10
11
  <ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
11
- <App />
12
+ <LocaleProvider>
13
+ <App />
14
+ </LocaleProvider>
12
15
  </ThemeProvider>
13
16
  </StrictMode>,
14
17
  );
@@ -1,5 +1,17 @@
1
- import { Check, Copy, FileIcon, Loader2, Trash2, Upload } from 'lucide-react';
1
+ import {
2
+ Check,
3
+ Copy,
4
+ FileIcon,
5
+ Image as ImageIcon,
6
+ Loader2,
7
+ MoreHorizontal,
8
+ PencilLine,
9
+ Trash2,
10
+ Upload,
11
+ } from 'lucide-react';
2
12
  import { type DragEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react';
13
+ import { CARD_GRID, EmptyState, PageHeader } from '../components/browser/browser-ui';
14
+ import { Menu, MenuItem, MenuSeparator } from '../components/ui/menu';
3
15
  import {
4
16
  type Asset,
5
17
  deleteAsset,
@@ -12,9 +24,11 @@ import {
12
24
  uploadAsset,
13
25
  } from '../lib/assets';
14
26
  import { docIds } from '../lib/docs';
27
+ import { useT } from '../lib/i18n';
15
28
  import { cn } from '../lib/utils';
16
29
 
17
30
  export function AssetsPage() {
31
+ const t = useT();
18
32
  const scopes = useMemo(() => [GLOBAL_SCOPE, ...[...docIds].sort()], []);
19
33
  const [scope, setScope] = useState<string>(GLOBAL_SCOPE);
20
34
  const [assets, setAssets] = useState<Asset[] | null>(null);
@@ -46,7 +60,9 @@ export function AssetsPage() {
46
60
  for (const file of Array.from(files)) {
47
61
  let result = await uploadAsset(scope, file);
48
62
  if (!result.ok && result.error === 'asset exists') {
49
- const replace = window.confirm(`"${file.name}" already exists in ${scope}. Replace it?`);
63
+ const replace = window.confirm(
64
+ t('"{name}" already exists in {scope}. Replace it?', { name: file.name, scope }),
65
+ );
50
66
  if (!replace) continue;
51
67
  result = await uploadAsset(scope, file, { overwrite: true });
52
68
  }
@@ -55,7 +71,7 @@ export function AssetsPage() {
55
71
  await refresh(scope);
56
72
  setBusy(false);
57
73
  },
58
- [scope, refresh],
74
+ [scope, refresh, t],
59
75
  );
60
76
 
61
77
  const onDrop = (e: DragEvent<HTMLDivElement>) => {
@@ -65,101 +81,105 @@ export function AssetsPage() {
65
81
  };
66
82
 
67
83
  return (
68
- <div>
69
- <header className="border-border border-b px-8 py-6">
70
- <h1 className="font-medium text-lg tracking-tight">Assets</h1>
71
- <p className="mt-1 text-muted-foreground text-sm">
72
- Images and fonts documents can import. Global files live in{' '}
73
- <code className="font-mono">assets/</code>; per-document files in{' '}
74
- <code className="font-mono">docs/&lt;id&gt;/assets/</code>.
75
- </p>
76
- </header>
77
-
78
- <div className="flex flex-wrap items-center gap-2 px-8 pt-6">
79
- {scopes.map((s) => (
80
- <button
81
- key={s}
82
- type="button"
83
- onClick={() => setScope(s)}
84
- className={cn(
85
- 'rounded-full border px-3 py-1 text-xs transition-colors',
86
- s === scope
87
- ? 'border-transparent bg-primary text-primary-foreground'
88
- : 'border-border text-muted-foreground hover:bg-accent hover:text-foreground',
89
- )}
90
- >
91
- {s === GLOBAL_SCOPE ? 'Global' : s}
92
- </button>
93
- ))}
94
- </div>
95
-
96
- <div className="px-8 py-6">
97
- {/* biome-ignore lint/a11y/noStaticElementInteractions: drop target is an enhancement — the "Choose files" button is the keyboard path */}
98
- <div
99
- onDragOver={(e) => {
100
- e.preventDefault();
101
- setDragging(true);
102
- }}
103
- onDragLeave={() => setDragging(false)}
104
- onDrop={onDrop}
105
- className={cn(
106
- 'flex items-center justify-between gap-4 rounded-lg border border-dashed px-5 py-4 transition-colors',
107
- dragging ? 'border-primary bg-accent' : 'border-border',
108
- )}
109
- >
110
- <div className="text-sm">
111
- <p className="font-medium">Drop files to upload</p>
112
- <p className="mt-0.5 text-muted-foreground text-xs">
113
- Up to 25 MB each · png, jpg, svg, webp, pdf, woff2, csv…
114
- </p>
84
+ // biome-ignore lint/a11y/noStaticElementInteractions: dropping files is an enhancement — "Choose files" is the keyboard path
85
+ <div
86
+ onDragOver={(e) => {
87
+ e.preventDefault();
88
+ setDragging(true);
89
+ }}
90
+ onDragLeave={(e) => {
91
+ if (e.currentTarget.contains(e.relatedTarget as Node | null)) return;
92
+ setDragging(false);
93
+ }}
94
+ onDrop={onDrop}
95
+ className={cn(
96
+ 'min-h-[60vh] rounded-lg outline-2 outline-offset-8 transition-colors',
97
+ dragging ? 'outline-dashed outline-primary/50' : 'outline-transparent',
98
+ )}
99
+ >
100
+ <PageHeader
101
+ title={t('Assets')}
102
+ icon={ImageIcon}
103
+ count={assets?.length}
104
+ actions={
105
+ <>
106
+ <button
107
+ type="button"
108
+ onClick={() => inputRef.current?.click()}
109
+ disabled={busy}
110
+ className="flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 disabled:opacity-60"
111
+ >
112
+ {busy ? (
113
+ <Loader2 className="size-3.5 animate-spin" />
114
+ ) : (
115
+ <Upload className="size-3.5" />
116
+ )}
117
+ {t('Upload')}
118
+ </button>
119
+ <input
120
+ ref={inputRef}
121
+ type="file"
122
+ multiple
123
+ hidden
124
+ onChange={(e) => {
125
+ if (e.target.files?.length) void upload(e.target.files);
126
+ e.target.value = '';
127
+ }}
128
+ />
129
+ </>
130
+ }
131
+ >
132
+ <fieldset className="flex flex-wrap items-center gap-3">
133
+ <legend className="sr-only">{t('Folder')}</legend>
134
+ <div className="flex max-w-full gap-0.5 overflow-x-auto rounded-md bg-muted p-0.5">
135
+ {scopes.map((s) => (
136
+ <button
137
+ key={s}
138
+ type="button"
139
+ aria-pressed={s === scope}
140
+ onClick={() => setScope(s)}
141
+ className={cn(
142
+ 'h-7 flex-none whitespace-nowrap rounded px-3 text-xs text-muted-foreground transition-colors hover:text-foreground',
143
+ s === scope && 'bg-background text-foreground shadow-sm',
144
+ )}
145
+ >
146
+ {s === GLOBAL_SCOPE ? t('Project') : s}
147
+ </button>
148
+ ))}
115
149
  </div>
116
- <button
117
- type="button"
118
- onClick={() => inputRef.current?.click()}
119
- disabled={busy}
120
- className="flex flex-none items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 disabled:opacity-60"
121
- >
122
- {busy ? <Loader2 className="size-3.5 animate-spin" /> : <Upload className="size-3.5" />}
123
- Choose files
124
- </button>
125
- <input
126
- ref={inputRef}
127
- type="file"
128
- multiple
129
- hidden
130
- onChange={(e) => {
131
- if (e.target.files?.length) void upload(e.target.files);
132
- e.target.value = '';
133
- }}
134
- />
135
- </div>
136
-
150
+ <p className="text-muted-foreground text-xs">{t('Drop files here to upload')}</p>
151
+ </fieldset>
137
152
  {error && (
138
- <p className="mt-3 rounded-md border border-border bg-muted px-3 py-2 text-xs">{error}</p>
139
- )}
140
-
141
- {assets === null ? (
142
- <div className="grid place-items-center py-16">
143
- <Loader2 className="size-4 animate-spin text-muted-foreground" />
144
- </div>
145
- ) : assets.length === 0 ? (
146
- <p className="py-16 text-center text-muted-foreground text-sm">
147
- No assets in {scope === GLOBAL_SCOPE ? 'the global folder' : scope} yet.
153
+ <p
154
+ role="alert"
155
+ className="mt-3 rounded-md border border-border bg-muted px-3 py-2 text-xs"
156
+ >
157
+ {error}
148
158
  </p>
149
- ) : (
150
- <div className="mt-6 grid gap-5 [grid-template-columns:repeat(auto-fill,minmax(180px,1fr))]">
151
- {assets.map((asset) => (
152
- <AssetCard
153
- key={asset.name}
154
- asset={asset}
155
- scope={scope}
156
- onChanged={() => refresh(scope)}
157
- onError={setError}
158
- />
159
- ))}
160
- </div>
161
159
  )}
162
- </div>
160
+ </PageHeader>
161
+
162
+ {assets === null ? (
163
+ <div className="grid place-items-center py-16">
164
+ <Loader2 className="size-4 animate-spin text-muted-foreground" />
165
+ </div>
166
+ ) : assets.length === 0 ? (
167
+ <EmptyState icon={ImageIcon} title={t('No assets yet')}>
168
+ {t('Drop images here or choose Upload.')}
169
+ </EmptyState>
170
+ ) : (
171
+ <div className={CARD_GRID}>
172
+ {assets.map((asset) => (
173
+ <AssetCard
174
+ key={asset.name}
175
+ asset={asset}
176
+ scope={scope}
177
+ onChanged={() => refresh(scope)}
178
+ onError={setError}
179
+ />
180
+ ))}
181
+ </div>
182
+ )}
163
183
  </div>
164
184
  );
165
185
  }
@@ -175,6 +195,7 @@ function AssetCard({
175
195
  onChanged: () => void;
176
196
  onError: (message: string) => void;
177
197
  }) {
198
+ const t = useT();
178
199
  const [copied, setCopied] = useState(false);
179
200
 
180
201
  const copyImport = async () => {
@@ -188,7 +209,7 @@ function AssetCard({
188
209
  };
189
210
 
190
211
  const rename = async () => {
191
- const next = window.prompt('New file name', asset.name);
212
+ const next = window.prompt(t('New file name'), asset.name);
192
213
  if (!next || next === asset.name) return;
193
214
  const result = await renameAsset(scope, asset.name, next);
194
215
  if (!result.ok) onError(`${asset.name}: ${result.error}`);
@@ -196,61 +217,101 @@ function AssetCard({
196
217
  };
197
218
 
198
219
  const remove = async () => {
199
- if (!window.confirm(`Delete "${asset.name}"? This removes the file from disk.`)) return;
220
+ if (
221
+ !window.confirm(t('Delete "{name}"? This removes the file from disk.', { name: asset.name }))
222
+ )
223
+ return;
200
224
  const result = await deleteAsset(scope, asset.name);
201
225
  if (!result.ok) onError(`${asset.name}: ${result.error}`);
202
226
  onChanged();
203
227
  };
204
228
 
205
229
  return (
206
- <div className="flex flex-col gap-2">
207
- <div className="relative grid h-32 place-items-center overflow-hidden rounded-md border border-border bg-muted">
230
+ <div className="group flex flex-col gap-2.5">
231
+ <div
232
+ className={cn(
233
+ 'grid aspect-[4/3] place-items-center overflow-hidden rounded-md ring-1 ring-border',
234
+ isPreviewable(asset.mime) ? 'bg-paper' : 'bg-muted',
235
+ )}
236
+ >
208
237
  {isPreviewable(asset.mime) ? (
209
238
  <img
210
239
  src={asset.url}
211
240
  alt={asset.name}
212
- className="max-h-full max-w-full object-contain p-2"
241
+ className="max-h-full max-w-full object-contain p-3"
213
242
  />
214
243
  ) : (
215
244
  <FileIcon className="size-6 text-muted-foreground" />
216
245
  )}
217
- {asset.unused && (
218
- <span className="absolute top-1.5 left-1.5 rounded-full bg-background/90 px-1.5 py-0.5 text-[10px] text-muted-foreground">
219
- unused
220
- </span>
221
- )}
222
246
  </div>
223
247
 
248
+ {/* The name gets the full width — a file name broken mid-extension
249
+ reads as a different file — and the actions sit beside the facts. */}
224
250
  <div className="min-w-0">
225
- <button
226
- type="button"
227
- onClick={rename}
228
- title="Rename"
229
- className="block w-full truncate text-left text-xs hover:underline"
230
- >
251
+ <p className="line-clamp-2 font-medium text-sm leading-snug [overflow-wrap:anywhere]">
231
252
  {asset.name}
232
- </button>
233
- <p className="mt-0.5 text-[11px] text-muted-foreground">{formatBytes(asset.size)}</p>
234
- </div>
235
-
236
- <div className="flex items-center gap-1">
237
- <button
238
- type="button"
239
- onClick={copyImport}
240
- title={importSnippet(asset)}
241
- className="flex flex-1 items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] transition-colors hover:bg-accent"
242
- >
243
- {copied ? <Check className="size-3" /> : <Copy className="size-3" />}
244
- {copied ? 'Copied' : 'Import'}
245
- </button>
246
- <button
247
- type="button"
248
- onClick={remove}
249
- aria-label={`Delete ${asset.name}`}
250
- className="flex size-6 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
251
- >
252
- <Trash2 className="size-3" />
253
- </button>
253
+ </p>
254
+ <div className="mt-0.5 flex items-center gap-1">
255
+ <p className="min-w-0 flex-1 truncate text-muted-foreground text-xs">
256
+ {formatBytes(asset.size)}
257
+ {asset.unused ? t(' · unused') : ''}
258
+ </p>
259
+ <button
260
+ type="button"
261
+ onClick={copyImport}
262
+ aria-label={t('Copy the import line for {name}', { name: asset.name })}
263
+ title={importSnippet(asset)}
264
+ className="flex size-7 flex-none items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
265
+ >
266
+ {copied ? <Check className="size-3.5" /> : <Copy className="size-3.5" />}
267
+ </button>
268
+ <Menu
269
+ trigger={(props) => (
270
+ <button
271
+ type="button"
272
+ aria-label={t('{name} options', { name: asset.name })}
273
+ className="flex size-7 flex-none items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground aria-expanded:bg-accent"
274
+ {...props}
275
+ >
276
+ <MoreHorizontal className="size-3.5" />
277
+ </button>
278
+ )}
279
+ >
280
+ {(close) => (
281
+ <>
282
+ <MenuItem
283
+ onClick={() => {
284
+ close();
285
+ void copyImport();
286
+ }}
287
+ >
288
+ <Copy className="size-3.5" />
289
+ {t('Copy import line')}
290
+ </MenuItem>
291
+ <MenuItem
292
+ onClick={() => {
293
+ close();
294
+ void rename();
295
+ }}
296
+ >
297
+ <PencilLine className="size-3.5" />
298
+ {t('Rename')}
299
+ </MenuItem>
300
+ <MenuSeparator />
301
+ <MenuItem
302
+ destructive
303
+ onClick={() => {
304
+ close();
305
+ void remove();
306
+ }}
307
+ >
308
+ <Trash2 className="size-3.5" />
309
+ {t('Delete')}
310
+ </MenuItem>
311
+ </>
312
+ )}
313
+ </Menu>
314
+ </div>
254
315
  </div>
255
316
  </div>
256
317
  );