@open-slide/core 1.13.6 → 1.15.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 (64) hide show
  1. package/dist/{build-OAZ8maw5.js → build-BsaslS8C.js} +1 -1
  2. package/dist/cli/bin.js +3 -3
  3. package/dist/{config-CU_NISD6.js → config-BOc3-oDV.js} +38 -3
  4. package/dist/{config-CvzwK0tq.d.ts → config-CE2sKgqH.d.ts} +1 -1
  5. package/dist/dev-BU7OY0ai.js +94 -0
  6. package/dist/{format-CXtO6ORA.js → format-afijk371.js} +140 -8
  7. package/dist/index.d.ts +7 -7
  8. package/dist/index.js +4 -2
  9. package/dist/locale/index.d.ts +1 -1
  10. package/dist/locale/index.js +1 -1
  11. package/dist/{preview-DZLZ3L9v.js → preview-DbL7Wt77.js} +1 -1
  12. package/dist/{types-DucrShh9.d.ts → types-GA4ekcYB.d.ts} +37 -0
  13. package/dist/vite/index.d.ts +2 -2
  14. package/dist/vite/index.js +1 -1
  15. package/package.json +2 -2
  16. package/src/app/components/asset-view.tsx +762 -63
  17. package/src/app/components/inspector/image-crop-dialog.tsx +3 -3
  18. package/src/app/components/inspector/inspect-overlay.tsx +44 -32
  19. package/src/app/components/inspector/inspector-panel.tsx +31 -26
  20. package/src/app/components/language-toggle.tsx +1 -1
  21. package/src/app/components/overview-grid.tsx +14 -12
  22. package/src/app/components/present/control-bar.tsx +24 -21
  23. package/src/app/components/present/progress-bar.tsx +1 -1
  24. package/src/app/components/sidebar/folder-item.tsx +26 -22
  25. package/src/app/components/sidebar/icon-picker.tsx +8 -8
  26. package/src/app/components/sidebar/sidebar-footer.tsx +100 -31
  27. package/src/app/components/sidebar/sidebar.tsx +22 -18
  28. package/src/app/components/style-panel/style-panel.tsx +8 -4
  29. package/src/app/components/theme-toggle.tsx +3 -3
  30. package/src/app/components/themes/theme-detail.tsx +2 -2
  31. package/src/app/components/themes/themes-gallery.tsx +1 -1
  32. package/src/app/components/thumbnail-rail-scroll.test.ts +60 -0
  33. package/src/app/components/thumbnail-rail-scroll.ts +33 -0
  34. package/src/app/components/thumbnail-rail.tsx +235 -66
  35. package/src/app/components/ui/badge.tsx +16 -13
  36. package/src/app/components/ui/button.tsx +4 -10
  37. package/src/app/components/ui/context-menu.tsx +46 -36
  38. package/src/app/components/ui/dialog.tsx +11 -13
  39. package/src/app/components/ui/dropdown-menu.tsx +59 -37
  40. package/src/app/components/ui/label.tsx +2 -5
  41. package/src/app/components/ui/popover.tsx +25 -18
  42. package/src/app/components/ui/progress.tsx +8 -6
  43. package/src/app/components/ui/scroll-area.tsx +5 -5
  44. package/src/app/components/ui/select.tsx +40 -41
  45. package/src/app/components/ui/separator.tsx +3 -5
  46. package/src/app/components/ui/slider.tsx +25 -18
  47. package/src/app/components/ui/tabs.tsx +8 -8
  48. package/src/app/components/ui/toggle-group.tsx +8 -7
  49. package/src/app/components/ui/toggle.tsx +5 -5
  50. package/src/app/components/ui/tooltip.tsx +39 -22
  51. package/src/app/lib/asset-filter.test.ts +176 -0
  52. package/src/app/lib/asset-filter.ts +80 -0
  53. package/src/app/lib/assets.ts +19 -4
  54. package/src/app/routes/home-shell.tsx +24 -20
  55. package/src/app/routes/home.tsx +48 -42
  56. package/src/app/routes/presenter.tsx +1 -1
  57. package/src/app/routes/slide.tsx +54 -47
  58. package/src/app/styles.css +86 -110
  59. package/src/locale/en.ts +34 -1
  60. package/src/locale/ja.ts +34 -2
  61. package/src/locale/types.ts +37 -0
  62. package/src/locale/zh-cn.ts +34 -1
  63. package/src/locale/zh-tw.ts +34 -1
  64. package/dist/dev-C78J1TLR.js +0 -20
@@ -1,9 +1,15 @@
1
1
  import {
2
+ ArrowDown,
2
3
  ArrowDownToLine,
4
+ ArrowUp,
5
+ ArrowUpDown,
3
6
  CloudOff,
7
+ Columns3,
4
8
  File as FileIcon,
5
9
  FileImage,
6
10
  ImageIcon,
11
+ LayoutGrid,
12
+ List,
7
13
  Loader2,
8
14
  MoreVertical,
9
15
  Pencil,
@@ -12,8 +18,9 @@ import {
12
18
  SearchX,
13
19
  Trash2,
14
20
  Upload,
21
+ X,
15
22
  } from 'lucide-react';
16
- import { useEffect, useId, useMemo, useRef, useState } from 'react';
23
+ import { useDeferredValue, useEffect, useId, useMemo, useRef, useState } from 'react';
17
24
  import { toast } from 'sonner';
18
25
  import { Button, buttonVariants } from '@/components/ui/button';
19
26
  import {
@@ -30,7 +37,25 @@ import {
30
37
  DropdownMenuItem,
31
38
  DropdownMenuTrigger,
32
39
  } from '@/components/ui/dropdown-menu';
40
+ import {
41
+ Select,
42
+ SelectContent,
43
+ SelectItem,
44
+ SelectTrigger,
45
+ SelectValue,
46
+ } from '@/components/ui/select';
47
+ import { Slider } from '@/components/ui/slider';
33
48
  import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
49
+ import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';
50
+ import {
51
+ type AssetSortDirection,
52
+ type AssetSortKey,
53
+ type AssetSortOptions,
54
+ type AssetTypeFilter,
55
+ type AssetUsageFilter,
56
+ filterAssets,
57
+ sortAssets,
58
+ } from '@/lib/asset-filter';
34
59
  import {
35
60
  type AssetEntry,
36
61
  type AssetUsage,
@@ -48,8 +73,88 @@ import { cn } from '@/lib/utils';
48
73
  type Props = { slideId: string | null };
49
74
 
50
75
  type Scope = 'slide' | 'global';
76
+ type ViewMode = 'grid' | 'list';
51
77
 
52
78
  const GLOBAL_SLIDE_ID = '@global';
79
+ const VIEW_MODE_STORAGE_KEY = 'open-slide:asset-view-mode';
80
+ const SORT_STORAGE_KEY = 'open-slide:asset-sort-v1';
81
+ const GRID_COLUMNS_STORAGE_KEY = 'open-slide:asset-grid-columns-v1';
82
+ const MIN_GRID_COLUMNS = 2;
83
+ const MAX_GRID_COLUMNS = 10;
84
+ const DEFAULT_GRID_COLUMNS = 4;
85
+ const SORT_KEYS: readonly AssetSortKey[] = ['name', 'modified', 'size', 'type'];
86
+ const DEFAULT_SORT: AssetSortOptions = { key: 'name', direction: 'asc' };
87
+ const DEFAULT_SORT_DIRECTIONS: Record<AssetSortKey, AssetSortDirection> = {
88
+ name: 'asc',
89
+ modified: 'desc',
90
+ size: 'desc',
91
+ type: 'asc',
92
+ };
93
+
94
+ function readViewMode(): ViewMode {
95
+ if (typeof window === 'undefined') return 'grid';
96
+ try {
97
+ return window.localStorage.getItem(VIEW_MODE_STORAGE_KEY) === 'list' ? 'list' : 'grid';
98
+ } catch {
99
+ return 'grid';
100
+ }
101
+ }
102
+
103
+ function useViewMode(): [ViewMode, (next: ViewMode) => void] {
104
+ const [viewMode, setViewMode] = useState<ViewMode>(readViewMode);
105
+ const update = (next: ViewMode) => {
106
+ setViewMode(next);
107
+ try {
108
+ window.localStorage.setItem(VIEW_MODE_STORAGE_KEY, next);
109
+ } catch {}
110
+ };
111
+ return [viewMode, update];
112
+ }
113
+
114
+ function readSortPreference(): AssetSortOptions {
115
+ if (typeof window === 'undefined') return DEFAULT_SORT;
116
+ try {
117
+ const [key, direction] = window.localStorage.getItem(SORT_STORAGE_KEY)?.split(':') ?? [];
118
+ if (SORT_KEYS.includes(key as AssetSortKey) && (direction === 'asc' || direction === 'desc')) {
119
+ return { key: key as AssetSortKey, direction };
120
+ }
121
+ } catch {}
122
+ return DEFAULT_SORT;
123
+ }
124
+
125
+ function useSortPreference(): [AssetSortOptions, (next: AssetSortOptions) => void] {
126
+ const [sort, setSort] = useState<AssetSortOptions>(readSortPreference);
127
+ const update = (next: AssetSortOptions) => {
128
+ setSort(next);
129
+ try {
130
+ window.localStorage.setItem(SORT_STORAGE_KEY, `${next.key}:${next.direction}`);
131
+ } catch {}
132
+ };
133
+ return [sort, update];
134
+ }
135
+
136
+ function readGridColumns(): number {
137
+ if (typeof window === 'undefined') return DEFAULT_GRID_COLUMNS;
138
+ try {
139
+ const value = Number(window.localStorage.getItem(GRID_COLUMNS_STORAGE_KEY));
140
+ if (Number.isInteger(value) && value >= MIN_GRID_COLUMNS && value <= MAX_GRID_COLUMNS) {
141
+ return value;
142
+ }
143
+ } catch {}
144
+ return DEFAULT_GRID_COLUMNS;
145
+ }
146
+
147
+ function useGridColumns(): [number, (next: number) => void] {
148
+ const [gridColumns, setGridColumns] = useState(readGridColumns);
149
+ const update = (next: number) => {
150
+ const value = Math.min(MAX_GRID_COLUMNS, Math.max(MIN_GRID_COLUMNS, Math.round(next)));
151
+ setGridColumns(value);
152
+ try {
153
+ window.localStorage.setItem(GRID_COLUMNS_STORAGE_KEY, String(value));
154
+ } catch {}
155
+ };
156
+ return [gridColumns, update];
157
+ }
53
158
 
54
159
  type ConflictState = {
55
160
  file: File;
@@ -68,11 +173,56 @@ export function AssetView({ slideId }: Props) {
68
173
  const [confirmDeleteUsages, setConfirmDeleteUsages] = useState<AssetUsage[] | null>(null);
69
174
  const [renaming, setRenaming] = useState<string | null>(null);
70
175
  const [logoSearchOpen, setLogoSearchOpen] = useState(false);
176
+ const [query, setQuery] = useState('');
177
+ const [usageFilter, setUsageFilter] = useState<AssetUsageFilter>('all');
178
+ const [typeFilter, setTypeFilter] = useState<AssetTypeFilter>('all');
179
+ const [viewMode, setViewMode] = useViewMode();
180
+ const [sort, setSort] = useSortPreference();
181
+ const [gridColumns, setGridColumns] = useGridColumns();
71
182
  const dragDepth = useRef(0);
72
183
  const inputId = useId();
73
184
  const t = useLocale();
74
185
 
75
- const existingNames = new Set(assets.map((a) => a.name));
186
+ const deferredQuery = useDeferredValue(query);
187
+ const visibleAssets = useMemo(
188
+ () =>
189
+ sortAssets(
190
+ filterAssets(assets, {
191
+ usage: usageFilter,
192
+ type: typeFilter,
193
+ search: deferredQuery,
194
+ }),
195
+ { key: sort.key, direction: sort.direction },
196
+ ),
197
+ [assets, deferredQuery, sort.direction, sort.key, typeFilter, usageFilter],
198
+ );
199
+ const existingNames = useMemo(() => new Set(assets.map((asset) => asset.name)), [assets]);
200
+
201
+ const clearFilters = () => {
202
+ setQuery('');
203
+ setUsageFilter('all');
204
+ setTypeFilter('all');
205
+ };
206
+
207
+ const changeSortKey = (key: AssetSortKey) => {
208
+ setSort({ key, direction: DEFAULT_SORT_DIRECTIONS[key] });
209
+ };
210
+
211
+ const toggleSortDirection = () => {
212
+ setSort({ key: sort.key, direction: sort.direction === 'asc' ? 'desc' : 'asc' });
213
+ };
214
+
215
+ const sortByColumn = (key: AssetSortKey) => {
216
+ setSort({
217
+ key,
218
+ direction:
219
+ sort.key === key
220
+ ? sort.direction === 'asc'
221
+ ? 'desc'
222
+ : 'asc'
223
+ : DEFAULT_SORT_DIRECTIONS[key],
224
+ });
225
+ };
76
226
 
77
227
  async function handleFile(file: File) {
78
228
  if (!available) return;
@@ -107,6 +257,32 @@ export function AssetView({ slideId }: Props) {
107
257
  }
108
258
  }
109
259
 
260
+ async function handleRename(asset: AssetEntry, next: string) {
261
+ if (next === asset.name) {
262
+ setRenaming(null);
263
+ return;
264
+ }
265
+ if (existingNames.has(next)) {
266
+ toast.error(t.asset.nameAlreadyExists);
267
+ return;
268
+ }
269
+ const res = await rename(asset.name, next);
270
+ if (!res.ok) {
271
+ toast.error(format(t.asset.toastRenameFailed, { status: res.status }));
272
+ return;
273
+ }
274
+ toast.success(format(t.asset.toastRenamed, { name: next }));
275
+ setRenaming(null);
276
+ }
277
+
278
+ function prepareDelete(asset: AssetEntry) {
279
+ setConfirmDelete(asset);
280
+ setConfirmDeleteUsages(null);
281
+ listAssetUsages(effectiveSlideId, asset.name)
282
+ .then((usages) => setConfirmDeleteUsages(usages))
283
+ .catch(() => setConfirmDeleteUsages([]));
284
+ }
285
+
110
286
  if (!available) {
111
287
  return (
112
288
  <div className="flex h-full items-center justify-center px-4 text-center text-sm text-muted-foreground">
@@ -210,6 +386,112 @@ export function AssetView({ slideId }: Props) {
210
386
  </div>
211
387
  </div>
212
388
 
389
+ <div className="flex shrink-0 flex-wrap items-center gap-2 border-b border-hairline bg-background px-4 py-2.5 sm:px-6">
390
+ <div className="relative min-w-[180px] flex-1 md:max-w-[280px]">
391
+ <Search
392
+ className="pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"
393
+ aria-hidden
394
+ />
395
+ <input
396
+ type="text"
397
+ value={query}
398
+ onChange={(event) => setQuery(event.target.value)}
399
+ aria-label={t.asset.assetSearchPlaceholder}
400
+ placeholder={t.asset.assetSearchPlaceholder}
401
+ className="h-8 w-full rounded-[6px] border border-border bg-background pl-8 pr-7 text-[12.5px] outline-none placeholder:text-muted-foreground/70 focus-visible:border-foreground/40 focus-visible:ring-2 focus-visible:ring-ring/30"
402
+ />
403
+ {query ? (
404
+ <button
405
+ type="button"
406
+ onClick={() => setQuery('')}
407
+ aria-label={t.asset.clearAssetSearch}
408
+ className="absolute right-1.5 top-1/2 flex size-5 -translate-y-1/2 items-center justify-center rounded-[4px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
409
+ >
410
+ <X className="size-3" />
411
+ </button>
412
+ ) : null}
413
+ </div>
414
+
415
+ <Select
416
+ items={{
417
+ all: t.asset.usageAll,
418
+ used: t.asset.usageUsed,
419
+ unused: t.asset.usageUnused,
420
+ }}
421
+ value={usageFilter}
422
+ onValueChange={(next) => setUsageFilter(next as AssetUsageFilter)}
423
+ >
424
+ <SelectTrigger aria-label={t.asset.usageFilterAria} className="h-8 min-w-[112px]">
425
+ <SelectValue />
426
+ </SelectTrigger>
427
+ <SelectContent align="start">
428
+ <SelectItem value="all">{t.asset.usageAll}</SelectItem>
429
+ <SelectItem value="used">{t.asset.usageUsed}</SelectItem>
430
+ <SelectItem value="unused">{t.asset.usageUnused}</SelectItem>
431
+ </SelectContent>
432
+ </Select>
433
+
434
+ <Select
435
+ items={{
436
+ all: t.asset.typeAll,
437
+ image: t.asset.typeImage,
438
+ font: t.asset.typeFont,
439
+ video: t.asset.typeVideo,
440
+ other: t.asset.typeOther,
441
+ }}
442
+ value={typeFilter}
443
+ onValueChange={(next) => setTypeFilter(next as AssetTypeFilter)}
444
+ >
445
+ <SelectTrigger aria-label={t.asset.typeFilterAria} className="h-8 min-w-[108px]">
446
+ <SelectValue />
447
+ </SelectTrigger>
448
+ <SelectContent align="start">
449
+ <SelectItem value="all">{t.asset.typeAll}</SelectItem>
450
+ <SelectItem value="image">{t.asset.typeImage}</SelectItem>
451
+ <SelectItem value="font">{t.asset.typeFont}</SelectItem>
452
+ <SelectItem value="video">{t.asset.typeVideo}</SelectItem>
453
+ <SelectItem value="other">{t.asset.typeOther}</SelectItem>
454
+ </SelectContent>
455
+ </Select>
456
+
457
+ <AssetSortControl
458
+ sort={sort}
459
+ onKeyChange={changeSortKey}
460
+ onToggleDirection={toggleSortDirection}
461
+ />
462
+
463
+ <div className="ml-auto flex items-center gap-2">
464
+ {viewMode === 'grid' ? (
465
+ <GridColumnsControl value={gridColumns} onChange={setGridColumns} />
466
+ ) : null}
467
+ <ToggleGroup
468
+ value={[viewMode]}
469
+ onValueChange={(value) => {
470
+ const next = value[0];
471
+ if (next) setViewMode(next as ViewMode);
472
+ }}
473
+ variant="outline"
474
+ >
475
+ <ToggleGroupItem
476
+ value="grid"
477
+ aria-label={t.asset.gridViewAria}
478
+ title={t.asset.gridViewAria}
479
+ className="size-8 px-0"
480
+ >
481
+ <LayoutGrid className="size-3.5" />
482
+ </ToggleGroupItem>
483
+ <ToggleGroupItem
484
+ value="list"
485
+ aria-label={t.asset.listViewAria}
486
+ title={t.asset.listViewAria}
487
+ className="size-8 px-0"
488
+ >
489
+ <List className="size-3.5" />
490
+ </ToggleGroupItem>
491
+ </ToggleGroup>
492
+ </div>
493
+ </div>
494
+
213
495
  <div className="min-h-0 flex-1 overflow-y-auto">
214
496
  {loading ? (
215
497
  <div className="flex h-full items-center justify-center text-sm text-muted-foreground">
@@ -217,45 +499,47 @@ export function AssetView({ slideId }: Props) {
217
499
  </div>
218
500
  ) : assets.length === 0 ? (
219
501
  <EmptyState />
502
+ ) : visibleAssets.length === 0 ? (
503
+ <NoMatchingAssets onClear={clearFilters} />
220
504
  ) : (
221
- <div className="grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-4 p-6">
222
- {assets.map((asset) =>
505
+ <div
506
+ className={cn(
507
+ 'p-4 sm:p-6',
508
+ viewMode === 'grid'
509
+ ? 'grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-4 lg:grid-cols-[repeat(var(--asset-grid-columns),minmax(0,1fr))]'
510
+ : 'flex flex-col gap-1',
511
+ )}
512
+ style={
513
+ viewMode === 'grid'
514
+ ? ({ '--asset-grid-columns': gridColumns } as React.CSSProperties)
515
+ : undefined
516
+ }
517
+ >
518
+ {viewMode === 'list' ? <AssetListHeader sort={sort} onSort={sortByColumn} /> : null}
519
+ {visibleAssets.map((asset) =>
223
520
  renaming === asset.name ? (
224
- <RenameCard
521
+ <RenameAsset
225
522
  key={asset.name}
226
523
  asset={asset}
524
+ viewMode={viewMode}
227
525
  onCancel={() => setRenaming(null)}
228
- onSubmit={async (next) => {
229
- if (next === asset.name) {
230
- setRenaming(null);
231
- return;
232
- }
233
- if (existingNames.has(next)) {
234
- toast.error(t.asset.nameAlreadyExists);
235
- return;
236
- }
237
- const res = await rename(asset.name, next);
238
- if (!res.ok) {
239
- toast.error(format(t.asset.toastRenameFailed, { status: res.status }));
240
- return;
241
- }
242
- toast.success(format(t.asset.toastRenamed, { name: next }));
243
- setRenaming(null);
244
- }}
526
+ onSubmit={(next) => handleRename(asset, next)}
245
527
  />
246
- ) : (
528
+ ) : viewMode === 'grid' ? (
247
529
  <AssetCard
248
530
  key={asset.name}
249
531
  asset={asset}
250
532
  onPreview={() => setPreview(asset)}
251
533
  onRename={() => setRenaming(asset.name)}
252
- onDelete={() => {
253
- setConfirmDelete(asset);
254
- setConfirmDeleteUsages(null);
255
- listAssetUsages(effectiveSlideId, asset.name)
256
- .then((u) => setConfirmDeleteUsages(u))
257
- .catch(() => setConfirmDeleteUsages([]));
258
- }}
534
+ onDelete={() => prepareDelete(asset)}
535
+ />
536
+ ) : (
537
+ <AssetListItem
538
+ key={asset.name}
539
+ asset={asset}
540
+ onPreview={() => setPreview(asset)}
541
+ onRename={() => setRenaming(asset.name)}
542
+ onDelete={() => prepareDelete(asset)}
259
543
  />
260
544
  ),
261
545
  )}
@@ -364,6 +648,66 @@ function EmptyState() {
364
648
  );
365
649
  }
366
650
 
651
+ function NoMatchingAssets({ onClear }: { onClear: () => void }) {
652
+ const t = useLocale();
653
+ return (
654
+ <div className="flex h-full flex-col items-center justify-center gap-4 px-6 py-16 text-center">
655
+ <div className="flex size-12 items-center justify-center rounded-full border border-hairline bg-card text-muted-foreground">
656
+ <SearchX className="size-5" />
657
+ </div>
658
+ <div>
659
+ <p className="font-heading text-[14px] font-semibold tracking-tight">
660
+ {t.asset.noMatchingAssets}
661
+ </p>
662
+ <p className="mt-1 text-[12.5px] text-muted-foreground">{t.asset.noMatchingAssetsHint}</p>
663
+ </div>
664
+ <Button variant="outline" size="sm" onClick={onClear}>
665
+ {t.asset.clearFilters}
666
+ </Button>
667
+ </div>
668
+ );
669
+ }
670
+
671
+ function GridColumnsControl({
672
+ value,
673
+ onChange,
674
+ }: {
675
+ value: number;
676
+ onChange: (value: number) => void;
677
+ }) {
678
+ const t = useLocale();
679
+ const valueLabel = format(t.asset.gridColumnsValue, { count: value });
680
+ const sliderContainerRef = useRef<HTMLDivElement>(null);
681
+
682
+ useEffect(() => {
683
+ const thumb = sliderContainerRef.current?.querySelector<HTMLElement>('[role="slider"]');
684
+ thumb?.setAttribute('aria-label', t.asset.gridColumnsAria);
685
+ thumb?.setAttribute('aria-valuetext', valueLabel);
686
+ }, [t.asset.gridColumnsAria, valueLabel]);
687
+
688
+ return (
689
+ <fieldset
690
+ aria-label={t.asset.gridColumnsAria}
691
+ title={valueLabel}
692
+ className="m-0 hidden h-8 w-[176px] min-w-0 items-center gap-2 rounded-[6px] border border-border bg-background px-2.5 py-0 lg:flex"
693
+ >
694
+ <Columns3 className="size-3.5 shrink-0 text-muted-foreground" aria-hidden />
695
+ <div ref={sliderContainerRef} className="min-w-0 flex-1">
696
+ <Slider
697
+ min={MIN_GRID_COLUMNS}
698
+ max={MAX_GRID_COLUMNS}
699
+ step={1}
700
+ value={[value]}
701
+ onValueChange={(v) => onChange((Array.isArray(v) ? v[0] : v) ?? value)}
702
+ />
703
+ </div>
704
+ <output className="w-4 text-right font-mono text-[10.5px] tabular-nums text-muted-foreground">
705
+ {value}
706
+ </output>
707
+ </fieldset>
708
+ );
709
+ }
710
+
367
711
  function hasFiles(e: React.DragEvent): boolean {
368
712
  const types = e.dataTransfer?.types;
369
713
  if (!types) return false;
@@ -373,6 +717,147 @@ function hasFiles(e: React.DragEvent): boolean {
373
717
  return false;
374
718
  }
375
719
 
720
+ function AssetSortControl({
721
+ sort,
722
+ onKeyChange,
723
+ onToggleDirection,
724
+ }: {
725
+ sort: AssetSortOptions;
726
+ onKeyChange: (key: AssetSortKey) => void;
727
+ onToggleDirection: () => void;
728
+ }) {
729
+ const t = useLocale();
730
+ const labels: Record<AssetSortKey, string> = {
731
+ name: t.asset.nameColumn,
732
+ modified: t.asset.modifiedAt,
733
+ size: t.asset.sizeColumn,
734
+ type: t.asset.typeColumn,
735
+ };
736
+ const directionLabel = sort.direction === 'asc' ? t.asset.sortAscending : t.asset.sortDescending;
737
+ const DirectionIcon = sort.direction === 'asc' ? ArrowUp : ArrowDown;
738
+
739
+ return (
740
+ <div className="flex items-center gap-1">
741
+ <Select
742
+ items={labels}
743
+ value={sort.key}
744
+ onValueChange={(next) => onKeyChange(next as AssetSortKey)}
745
+ >
746
+ <SelectTrigger aria-label={t.asset.sortAria} className="h-8 min-w-[116px]">
747
+ <ArrowUpDown className="size-3.5" aria-hidden />
748
+ <SelectValue />
749
+ </SelectTrigger>
750
+ <SelectContent align="start">
751
+ {SORT_KEYS.map((key) => (
752
+ <SelectItem key={key} value={key}>
753
+ {labels[key]}
754
+ </SelectItem>
755
+ ))}
756
+ </SelectContent>
757
+ </Select>
758
+ <Button
759
+ type="button"
760
+ variant="outline"
761
+ size="icon"
762
+ onClick={onToggleDirection}
763
+ aria-label={directionLabel}
764
+ title={directionLabel}
765
+ className="size-8 bg-background"
766
+ >
767
+ <DirectionIcon className="size-3.5 text-muted-foreground" />
768
+ </Button>
769
+ </div>
770
+ );
771
+ }
772
+
773
+ function SortableColumnHeader({
774
+ label,
775
+ sortKey,
776
+ sort,
777
+ onSort,
778
+ className,
779
+ }: {
780
+ label: string;
781
+ sortKey: AssetSortKey;
782
+ sort: AssetSortOptions;
783
+ onSort: (key: AssetSortKey) => void;
784
+ className?: string;
785
+ }) {
786
+ const t = useLocale();
787
+ const active = sort.key === sortKey;
788
+ const directionLabel = sort.direction === 'asc' ? t.asset.sortAscending : t.asset.sortDescending;
789
+ const DirectionIcon = sort.direction === 'asc' ? ArrowUp : ArrowDown;
790
+ const sortLabel = format(t.asset.sortByColumn, { column: label });
791
+
792
+ return (
793
+ <button
794
+ type="button"
795
+ onClick={() => onSort(sortKey)}
796
+ aria-label={active ? `${sortLabel}, ${directionLabel}` : sortLabel}
797
+ title={active ? `${sortLabel} · ${directionLabel}` : sortLabel}
798
+ className={cn(
799
+ 'group flex h-5 items-center gap-1 rounded-[4px] text-left outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/30',
800
+ active && 'text-foreground',
801
+ className,
802
+ )}
803
+ >
804
+ <span className="truncate">{label}</span>
805
+ {active ? (
806
+ <DirectionIcon className="size-2.5 shrink-0" aria-hidden />
807
+ ) : (
808
+ <ArrowUpDown
809
+ className="size-2.5 shrink-0 opacity-0 transition-opacity group-hover:opacity-60 group-focus-visible:opacity-60"
810
+ aria-hidden
811
+ />
812
+ )}
813
+ </button>
814
+ );
815
+ }
816
+
817
+ function AssetListHeader({
818
+ sort,
819
+ onSort,
820
+ }: {
821
+ sort: AssetSortOptions;
822
+ onSort: (key: AssetSortKey) => void;
823
+ }) {
824
+ const t = useLocale();
825
+ return (
826
+ <div className="hidden items-center gap-3 px-2 pb-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground/70 sm:flex">
827
+ <SortableColumnHeader
828
+ label={t.asset.nameColumn}
829
+ sortKey="name"
830
+ sort={sort}
831
+ onSort={onSort}
832
+ className="min-w-0 flex-1"
833
+ />
834
+ <SortableColumnHeader
835
+ label={t.asset.typeColumn}
836
+ sortKey="type"
837
+ sort={sort}
838
+ onSort={onSort}
839
+ className="hidden w-40 shrink-0 md:flex"
840
+ />
841
+ <SortableColumnHeader
842
+ label={t.asset.modifiedAt}
843
+ sortKey="modified"
844
+ sort={sort}
845
+ onSort={onSort}
846
+ className="hidden w-28 shrink-0 lg:flex"
847
+ />
848
+ <SortableColumnHeader
849
+ label={t.asset.sizeColumn}
850
+ sortKey="size"
851
+ sort={sort}
852
+ onSort={onSort}
853
+ className="w-16 shrink-0"
854
+ />
855
+ <span className="w-16 shrink-0 text-right">{t.asset.statusColumn}</span>
856
+ <span className="size-6 shrink-0" aria-hidden />
857
+ </div>
858
+ );
859
+ }
860
+
376
861
  function AssetCard({
377
862
  asset,
378
863
  onPreview,
@@ -416,56 +901,194 @@ function AssetCard({
416
901
  </div>
417
902
  <div className="folio flex items-center gap-1.5">
418
903
  <span className="truncate">{formatSize(asset.size)}</span>
419
- {asset.unused ? (
420
- <span className="shrink-0 rounded-sm bg-muted px-1 py-px text-[10px] font-medium text-muted-foreground leading-none">
421
- {t.asset.usageUnused}
422
- </span>
423
- ) : null}
904
+ <UsageBadge unused={asset.unused} />
424
905
  </div>
425
- </div>
426
- <DropdownMenu>
427
- <DropdownMenuTrigger
428
- type="button"
429
- aria-label={format(t.asset.actionsAria, { name: asset.name })}
430
- className={cn(
431
- buttonVariants({ variant: 'ghost', size: 'icon-xs' }),
432
- 'opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100 aria-expanded:opacity-100',
433
- )}
906
+ <div
907
+ className="mt-0.5 flex min-w-0 items-center gap-1 text-[10.5px] leading-tight text-muted-foreground"
908
+ title={`${t.asset.modifiedAt}: ${formatAssetDate(asset.mtime, t.id, true)}`}
434
909
  >
435
- <MoreVertical />
436
- </DropdownMenuTrigger>
437
- <DropdownMenuContent align="end" className="min-w-[160px]">
438
- <DropdownMenuItem onSelect={onPreview}>
439
- <ImageIcon />
440
- {t.asset.previewMenuItem}
441
- </DropdownMenuItem>
442
- <DropdownMenuItem onSelect={onRename}>
443
- <Pencil />
444
- {t.asset.renameMenuItem}
445
- </DropdownMenuItem>
446
- <DropdownMenuItem onSelect={onDelete}>
447
- <Trash2 />
448
- {t.asset.deleteMenuItem}
449
- </DropdownMenuItem>
450
- </DropdownMenuContent>
451
- </DropdownMenu>
910
+ <span className="shrink-0">{t.asset.modifiedAt}</span>
911
+ <span className="opacity-40">·</span>
912
+ <time dateTime={assetDateTime(asset.mtime)} className="truncate font-mono">
913
+ {formatAssetDate(asset.mtime, t.id)}
914
+ </time>
915
+ </div>
916
+ </div>
917
+ <AssetActions asset={asset} onPreview={onPreview} onRename={onRename} onDelete={onDelete} />
452
918
  </div>
453
919
  </div>
454
920
  );
455
921
  }
456
922
 
457
- function RenameCard({
923
+ function AssetListItem({
458
924
  asset,
925
+ onPreview,
926
+ onRename,
927
+ onDelete,
928
+ }: {
929
+ asset: AssetEntry;
930
+ onPreview: () => void;
931
+ onRename: () => void;
932
+ onDelete: () => void;
933
+ }) {
934
+ const isImage = asset.mime.startsWith('image/');
935
+ const t = useLocale();
936
+ return (
937
+ <div className="group flex min-h-14 items-center gap-3 rounded-[6px] border border-border bg-card p-2 shadow-edge transition-shadow hover:shadow-floating focus-within:ring-2 focus-within:ring-ring/30">
938
+ <button
939
+ type="button"
940
+ onClick={onPreview}
941
+ aria-label={format(t.asset.previewAria, { name: asset.name })}
942
+ className="relative flex size-11 shrink-0 items-center justify-center overflow-hidden rounded-[4px] border border-hairline bg-[repeating-conic-gradient(theme(colors.muted)_0_25%,transparent_0_50%)] bg-[length:10px_10px]"
943
+ >
944
+ {isImage ? (
945
+ <img
946
+ src={asset.url}
947
+ alt=""
948
+ className="size-full object-contain"
949
+ draggable={false}
950
+ onError={(event) => {
951
+ event.currentTarget.style.display = 'none';
952
+ }}
953
+ />
954
+ ) : (
955
+ <FileIcon className="size-5 text-muted-foreground" />
956
+ )}
957
+ </button>
958
+ <div className="min-w-0 flex-1">
959
+ <div className="truncate text-[12.5px] font-medium" title={asset.name}>
960
+ {asset.name}
961
+ </div>
962
+ <div className="folio mt-0.5 flex min-w-0 items-center gap-1.5 lg:hidden">
963
+ <span className="sm:hidden">{formatSize(asset.size)}</span>
964
+ <span className="opacity-40 sm:hidden">·</span>
965
+ <span className="truncate md:hidden">{asset.mime}</span>
966
+ <span className="opacity-40 md:hidden">·</span>
967
+ <span className="shrink-0">{t.asset.modifiedAt}</span>
968
+ <time dateTime={assetDateTime(asset.mtime)} className="truncate">
969
+ {formatAssetDate(asset.mtime, t.id)}
970
+ </time>
971
+ <span className="sm:hidden">
972
+ <UsageBadge unused={asset.unused} showUsed />
973
+ </span>
974
+ </div>
975
+ </div>
976
+ <span className="hidden w-40 shrink-0 truncate font-mono text-[11px] text-muted-foreground md:block">
977
+ {asset.mime}
978
+ </span>
979
+ <time
980
+ dateTime={assetDateTime(asset.mtime)}
981
+ title={`${t.asset.modifiedAt}: ${formatAssetDate(asset.mtime, t.id, true)}`}
982
+ className="hidden w-28 shrink-0 text-[11.5px] text-muted-foreground lg:block"
983
+ >
984
+ <span className="sr-only">{t.asset.modifiedAt}: </span>
985
+ {formatAssetDate(asset.mtime, t.id)}
986
+ </time>
987
+ <span className="folio hidden w-16 shrink-0 sm:block">{formatSize(asset.size)}</span>
988
+ <div className="hidden w-16 shrink-0 justify-end sm:flex">
989
+ <UsageBadge unused={asset.unused} showUsed />
990
+ </div>
991
+ <AssetActions asset={asset} onPreview={onPreview} onRename={onRename} onDelete={onDelete} />
992
+ </div>
993
+ );
994
+ }
995
+
996
+ function AssetActions({
997
+ asset,
998
+ onPreview,
999
+ onRename,
1000
+ onDelete,
1001
+ }: {
1002
+ asset: AssetEntry;
1003
+ onPreview: () => void;
1004
+ onRename: () => void;
1005
+ onDelete: () => void;
1006
+ }) {
1007
+ const t = useLocale();
1008
+ return (
1009
+ <DropdownMenu>
1010
+ <DropdownMenuTrigger
1011
+ type="button"
1012
+ aria-label={format(t.asset.actionsAria, { name: asset.name })}
1013
+ className={cn(
1014
+ buttonVariants({ variant: 'ghost', size: 'icon-xs' }),
1015
+ 'opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100 aria-expanded:opacity-100',
1016
+ )}
1017
+ >
1018
+ <MoreVertical />
1019
+ </DropdownMenuTrigger>
1020
+ <DropdownMenuContent align="end" className="min-w-[160px]">
1021
+ <DropdownMenuItem onClick={onPreview}>
1022
+ <ImageIcon />
1023
+ {t.asset.previewMenuItem}
1024
+ </DropdownMenuItem>
1025
+ <DropdownMenuItem onClick={onRename}>
1026
+ <Pencil />
1027
+ {t.asset.renameMenuItem}
1028
+ </DropdownMenuItem>
1029
+ <DropdownMenuItem onClick={onDelete}>
1030
+ <Trash2 />
1031
+ {t.asset.deleteMenuItem}
1032
+ </DropdownMenuItem>
1033
+ </DropdownMenuContent>
1034
+ </DropdownMenu>
1035
+ );
1036
+ }
1037
+
1038
+ function UsageBadge({ unused, showUsed = false }: { unused: boolean; showUsed?: boolean }) {
1039
+ const t = useLocale();
1040
+ if (!unused && !showUsed) return null;
1041
+ return (
1042
+ <span
1043
+ className={cn(
1044
+ 'shrink-0 rounded-sm px-1 py-px text-[10px] font-medium leading-none',
1045
+ unused
1046
+ ? 'bg-muted text-muted-foreground'
1047
+ : 'bg-emerald-500/15 text-emerald-700 dark:text-emerald-400',
1048
+ )}
1049
+ >
1050
+ {unused ? t.asset.usageUnused : t.asset.usageUsed}
1051
+ </span>
1052
+ );
1053
+ }
1054
+
1055
+ function AssetTimestamp({
1056
+ label,
1057
+ timestamp,
1058
+ locale,
1059
+ }: {
1060
+ label: string;
1061
+ timestamp: number;
1062
+ locale: string;
1063
+ }) {
1064
+ return (
1065
+ <div className="bg-card px-3 py-2.5">
1066
+ <span className="eyebrow block text-[9px]">{label}</span>
1067
+ <time
1068
+ dateTime={assetDateTime(timestamp)}
1069
+ className="mt-1 block text-[12px] font-medium tabular-nums"
1070
+ >
1071
+ {formatAssetDate(timestamp, locale, true)}
1072
+ </time>
1073
+ </div>
1074
+ );
1075
+ }
1076
+
1077
+ function RenameAsset({
1078
+ asset,
1079
+ viewMode,
459
1080
  onCancel,
460
1081
  onSubmit,
461
1082
  }: {
462
1083
  asset: AssetEntry;
1084
+ viewMode: ViewMode;
463
1085
  onCancel: () => void;
464
1086
  onSubmit: (next: string) => Promise<void> | void;
465
1087
  }) {
466
1088
  const [value, setValue] = useState(asset.name);
467
1089
  const [saving, setSaving] = useState(false);
468
1090
  const inputRef = useRef<HTMLInputElement | null>(null);
1091
+ const t = useLocale();
469
1092
 
470
1093
  useEffect(() => {
471
1094
  queueMicrotask(() => {
@@ -491,8 +1114,58 @@ function RenameCard({
491
1114
  };
492
1115
 
493
1116
  const isImage = asset.mime.startsWith('image/');
1117
+ if (viewMode === 'list') {
1118
+ return (
1119
+ <div className="flex min-h-14 items-center gap-3 rounded-[6px] border border-primary bg-card p-2 shadow-edge ring-2 ring-primary/15">
1120
+ <div className="relative flex size-11 shrink-0 items-center justify-center overflow-hidden rounded-[4px] border border-hairline bg-[repeating-conic-gradient(theme(colors.muted)_0_25%,transparent_0_50%)] bg-[length:10px_10px]">
1121
+ {isImage ? (
1122
+ <img src={asset.url} alt="" className="size-full object-contain" draggable={false} />
1123
+ ) : (
1124
+ <FileIcon className="size-5 text-muted-foreground" />
1125
+ )}
1126
+ </div>
1127
+ <input
1128
+ ref={inputRef}
1129
+ value={value}
1130
+ disabled={saving}
1131
+ onChange={(event) => setValue(event.target.value)}
1132
+ onBlur={() => {
1133
+ if (!saving) commit();
1134
+ }}
1135
+ onKeyDown={(event) => {
1136
+ if (event.nativeEvent.isComposing) return;
1137
+ if (event.key === 'Enter') {
1138
+ event.preventDefault();
1139
+ commit();
1140
+ } else if (event.key === 'Escape') {
1141
+ event.preventDefault();
1142
+ onCancel();
1143
+ }
1144
+ }}
1145
+ maxLength={120}
1146
+ className="h-8 min-w-0 flex-1 rounded-[5px] border bg-background px-2.5 text-[12.5px] outline-none ring-ring/40 focus:ring-2"
1147
+ />
1148
+ <span className="hidden w-40 shrink-0 truncate font-mono text-[11px] text-muted-foreground md:block">
1149
+ {asset.mime}
1150
+ </span>
1151
+ <time
1152
+ dateTime={assetDateTime(asset.mtime)}
1153
+ className="hidden w-28 shrink-0 text-[11.5px] text-muted-foreground lg:block"
1154
+ >
1155
+ <span className="sr-only">{t.asset.modifiedAt}: </span>
1156
+ {formatAssetDate(asset.mtime, t.id)}
1157
+ </time>
1158
+ <span className="folio hidden w-16 shrink-0 sm:block">{formatSize(asset.size)}</span>
1159
+ <div className="hidden w-16 shrink-0 justify-end sm:flex">
1160
+ <UsageBadge unused={asset.unused} showUsed />
1161
+ </div>
1162
+ <div className="size-6 shrink-0" />
1163
+ </div>
1164
+ );
1165
+ }
1166
+
494
1167
  return (
495
- <div className="relative flex flex-col overflow-hidden rounded-xl border-2 border-primary bg-card shadow-sm">
1168
+ <div className="relative flex flex-col overflow-hidden rounded-[6px] border border-primary bg-card shadow-edge ring-2 ring-primary/15">
496
1169
  <div className="relative flex aspect-square w-full items-center justify-center overflow-hidden bg-[repeating-conic-gradient(theme(colors.muted)_0_25%,transparent_0_50%)] bg-[length:16px_16px]">
497
1170
  {isImage ? (
498
1171
  <img src={asset.url} alt="" className="size-full object-contain" draggable={false} />
@@ -670,6 +1343,10 @@ function PreviewDialog({
670
1343
  <span className="text-sm">{t.asset.noPreview}</span>
671
1344
  </div>
672
1345
  )}
1346
+ <div className="grid grid-cols-2 gap-px overflow-hidden rounded-[6px] border border-hairline bg-hairline">
1347
+ <AssetTimestamp label={t.asset.createdAt} timestamp={asset.createdAt} locale={t.id} />
1348
+ <AssetTimestamp label={t.asset.modifiedAt} timestamp={asset.mtime} locale={t.id} />
1349
+ </div>
673
1350
  <div className="rounded-[5px] border border-hairline bg-muted/50 px-3 py-2 font-mono text-[11.5px] leading-relaxed">
674
1351
  <span className="text-muted-foreground">{t.asset.importHintComment}</span>
675
1352
  <span className="text-brand">'{importPath}'</span>
@@ -959,6 +1636,28 @@ function slugify(s: string): string {
959
1636
  .replace(/^-|-$/g, '');
960
1637
  }
961
1638
 
1639
+ const ASSET_DATE_FORMATTERS = new Map<string, Intl.DateTimeFormat>();
1640
+
1641
+ function formatAssetDate(timestamp: number, locale: string, includeTime = false): string {
1642
+ const date = new Date(timestamp);
1643
+ if (Number.isNaN(date.getTime())) return '—';
1644
+ const key = `${locale}:${includeTime ? 'date-time' : 'date'}`;
1645
+ let formatter = ASSET_DATE_FORMATTERS.get(key);
1646
+ if (!formatter) {
1647
+ formatter = new Intl.DateTimeFormat(
1648
+ locale,
1649
+ includeTime ? { dateStyle: 'medium', timeStyle: 'short' } : { dateStyle: 'medium' },
1650
+ );
1651
+ ASSET_DATE_FORMATTERS.set(key, formatter);
1652
+ }
1653
+ return formatter.format(date);
1654
+ }
1655
+
1656
+ function assetDateTime(timestamp: number): string | undefined {
1657
+ const date = new Date(timestamp);
1658
+ return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
1659
+ }
1660
+
962
1661
  function formatSize(bytes: number): string {
963
1662
  if (bytes < 1024) return `${bytes} B`;
964
1663
  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;