@open-slide/core 1.13.5 → 1.14.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.
@@ -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,97 @@ 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
+ value={usageFilter}
417
+ onValueChange={(next) => setUsageFilter(next as AssetUsageFilter)}
418
+ >
419
+ <SelectTrigger aria-label={t.asset.usageFilterAria} className="h-8 min-w-[112px]">
420
+ <SelectValue />
421
+ </SelectTrigger>
422
+ <SelectContent align="start">
423
+ <SelectItem value="all">{t.asset.usageAll}</SelectItem>
424
+ <SelectItem value="used">{t.asset.usageUsed}</SelectItem>
425
+ <SelectItem value="unused">{t.asset.usageUnused}</SelectItem>
426
+ </SelectContent>
427
+ </Select>
428
+
429
+ <Select value={typeFilter} onValueChange={(next) => setTypeFilter(next as AssetTypeFilter)}>
430
+ <SelectTrigger aria-label={t.asset.typeFilterAria} className="h-8 min-w-[108px]">
431
+ <SelectValue />
432
+ </SelectTrigger>
433
+ <SelectContent align="start">
434
+ <SelectItem value="all">{t.asset.typeAll}</SelectItem>
435
+ <SelectItem value="image">{t.asset.typeImage}</SelectItem>
436
+ <SelectItem value="font">{t.asset.typeFont}</SelectItem>
437
+ <SelectItem value="video">{t.asset.typeVideo}</SelectItem>
438
+ <SelectItem value="other">{t.asset.typeOther}</SelectItem>
439
+ </SelectContent>
440
+ </Select>
441
+
442
+ <AssetSortControl
443
+ sort={sort}
444
+ onKeyChange={changeSortKey}
445
+ onToggleDirection={toggleSortDirection}
446
+ />
447
+
448
+ <div className="ml-auto flex items-center gap-2">
449
+ {viewMode === 'grid' ? (
450
+ <GridColumnsControl value={gridColumns} onChange={setGridColumns} />
451
+ ) : null}
452
+ <ToggleGroup
453
+ type="single"
454
+ value={viewMode}
455
+ onValueChange={(next) => {
456
+ if (next) setViewMode(next as ViewMode);
457
+ }}
458
+ variant="outline"
459
+ >
460
+ <ToggleGroupItem
461
+ value="grid"
462
+ aria-label={t.asset.gridViewAria}
463
+ title={t.asset.gridViewAria}
464
+ className="size-8 px-0"
465
+ >
466
+ <LayoutGrid className="size-3.5" />
467
+ </ToggleGroupItem>
468
+ <ToggleGroupItem
469
+ value="list"
470
+ aria-label={t.asset.listViewAria}
471
+ title={t.asset.listViewAria}
472
+ className="size-8 px-0"
473
+ >
474
+ <List className="size-3.5" />
475
+ </ToggleGroupItem>
476
+ </ToggleGroup>
477
+ </div>
478
+ </div>
479
+
213
480
  <div className="min-h-0 flex-1 overflow-y-auto">
214
481
  {loading ? (
215
482
  <div className="flex h-full items-center justify-center text-sm text-muted-foreground">
@@ -217,45 +484,47 @@ export function AssetView({ slideId }: Props) {
217
484
  </div>
218
485
  ) : assets.length === 0 ? (
219
486
  <EmptyState />
487
+ ) : visibleAssets.length === 0 ? (
488
+ <NoMatchingAssets onClear={clearFilters} />
220
489
  ) : (
221
- <div className="grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-4 p-6">
222
- {assets.map((asset) =>
490
+ <div
491
+ className={cn(
492
+ 'p-4 sm:p-6',
493
+ viewMode === 'grid'
494
+ ? 'grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-4 lg:grid-cols-[repeat(var(--asset-grid-columns),minmax(0,1fr))]'
495
+ : 'flex flex-col gap-1',
496
+ )}
497
+ style={
498
+ viewMode === 'grid'
499
+ ? ({ '--asset-grid-columns': gridColumns } as React.CSSProperties)
500
+ : undefined
501
+ }
502
+ >
503
+ {viewMode === 'list' ? <AssetListHeader sort={sort} onSort={sortByColumn} /> : null}
504
+ {visibleAssets.map((asset) =>
223
505
  renaming === asset.name ? (
224
- <RenameCard
506
+ <RenameAsset
225
507
  key={asset.name}
226
508
  asset={asset}
509
+ viewMode={viewMode}
227
510
  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
- }}
511
+ onSubmit={(next) => handleRename(asset, next)}
245
512
  />
246
- ) : (
513
+ ) : viewMode === 'grid' ? (
247
514
  <AssetCard
248
515
  key={asset.name}
249
516
  asset={asset}
250
517
  onPreview={() => setPreview(asset)}
251
518
  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
- }}
519
+ onDelete={() => prepareDelete(asset)}
520
+ />
521
+ ) : (
522
+ <AssetListItem
523
+ key={asset.name}
524
+ asset={asset}
525
+ onPreview={() => setPreview(asset)}
526
+ onRename={() => setRenaming(asset.name)}
527
+ onDelete={() => prepareDelete(asset)}
259
528
  />
260
529
  ),
261
530
  )}
@@ -364,6 +633,66 @@ function EmptyState() {
364
633
  );
365
634
  }
366
635
 
636
+ function NoMatchingAssets({ onClear }: { onClear: () => void }) {
637
+ const t = useLocale();
638
+ return (
639
+ <div className="flex h-full flex-col items-center justify-center gap-4 px-6 py-16 text-center">
640
+ <div className="flex size-12 items-center justify-center rounded-full border border-hairline bg-card text-muted-foreground">
641
+ <SearchX className="size-5" />
642
+ </div>
643
+ <div>
644
+ <p className="font-heading text-[14px] font-semibold tracking-tight">
645
+ {t.asset.noMatchingAssets}
646
+ </p>
647
+ <p className="mt-1 text-[12.5px] text-muted-foreground">{t.asset.noMatchingAssetsHint}</p>
648
+ </div>
649
+ <Button variant="outline" size="sm" onClick={onClear}>
650
+ {t.asset.clearFilters}
651
+ </Button>
652
+ </div>
653
+ );
654
+ }
655
+
656
+ function GridColumnsControl({
657
+ value,
658
+ onChange,
659
+ }: {
660
+ value: number;
661
+ onChange: (value: number) => void;
662
+ }) {
663
+ const t = useLocale();
664
+ const valueLabel = format(t.asset.gridColumnsValue, { count: value });
665
+ const sliderContainerRef = useRef<HTMLDivElement>(null);
666
+
667
+ useEffect(() => {
668
+ const thumb = sliderContainerRef.current?.querySelector<HTMLElement>('[role="slider"]');
669
+ thumb?.setAttribute('aria-label', t.asset.gridColumnsAria);
670
+ thumb?.setAttribute('aria-valuetext', valueLabel);
671
+ }, [t.asset.gridColumnsAria, valueLabel]);
672
+
673
+ return (
674
+ <fieldset
675
+ aria-label={t.asset.gridColumnsAria}
676
+ title={valueLabel}
677
+ 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"
678
+ >
679
+ <Columns3 className="size-3.5 shrink-0 text-muted-foreground" aria-hidden />
680
+ <div ref={sliderContainerRef} className="min-w-0 flex-1">
681
+ <Slider
682
+ min={MIN_GRID_COLUMNS}
683
+ max={MAX_GRID_COLUMNS}
684
+ step={1}
685
+ value={[value]}
686
+ onValueChange={([next]) => onChange(next ?? value)}
687
+ />
688
+ </div>
689
+ <output className="w-4 text-right font-mono text-[10.5px] tabular-nums text-muted-foreground">
690
+ {value}
691
+ </output>
692
+ </fieldset>
693
+ );
694
+ }
695
+
367
696
  function hasFiles(e: React.DragEvent): boolean {
368
697
  const types = e.dataTransfer?.types;
369
698
  if (!types) return false;
@@ -373,6 +702,143 @@ function hasFiles(e: React.DragEvent): boolean {
373
702
  return false;
374
703
  }
375
704
 
705
+ function AssetSortControl({
706
+ sort,
707
+ onKeyChange,
708
+ onToggleDirection,
709
+ }: {
710
+ sort: AssetSortOptions;
711
+ onKeyChange: (key: AssetSortKey) => void;
712
+ onToggleDirection: () => void;
713
+ }) {
714
+ const t = useLocale();
715
+ const labels: Record<AssetSortKey, string> = {
716
+ name: t.asset.nameColumn,
717
+ modified: t.asset.modifiedAt,
718
+ size: t.asset.sizeColumn,
719
+ type: t.asset.typeColumn,
720
+ };
721
+ const directionLabel = sort.direction === 'asc' ? t.asset.sortAscending : t.asset.sortDescending;
722
+ const DirectionIcon = sort.direction === 'asc' ? ArrowUp : ArrowDown;
723
+
724
+ return (
725
+ <div className="flex items-center gap-1">
726
+ <Select value={sort.key} onValueChange={(next) => onKeyChange(next as AssetSortKey)}>
727
+ <SelectTrigger aria-label={t.asset.sortAria} className="h-8 min-w-[116px]">
728
+ <ArrowUpDown className="size-3.5" aria-hidden />
729
+ <SelectValue />
730
+ </SelectTrigger>
731
+ <SelectContent align="start">
732
+ {SORT_KEYS.map((key) => (
733
+ <SelectItem key={key} value={key}>
734
+ {labels[key]}
735
+ </SelectItem>
736
+ ))}
737
+ </SelectContent>
738
+ </Select>
739
+ <Button
740
+ type="button"
741
+ variant="outline"
742
+ size="icon"
743
+ onClick={onToggleDirection}
744
+ aria-label={directionLabel}
745
+ title={directionLabel}
746
+ className="size-8 bg-background"
747
+ >
748
+ <DirectionIcon className="size-3.5 text-muted-foreground" />
749
+ </Button>
750
+ </div>
751
+ );
752
+ }
753
+
754
+ function SortableColumnHeader({
755
+ label,
756
+ sortKey,
757
+ sort,
758
+ onSort,
759
+ className,
760
+ }: {
761
+ label: string;
762
+ sortKey: AssetSortKey;
763
+ sort: AssetSortOptions;
764
+ onSort: (key: AssetSortKey) => void;
765
+ className?: string;
766
+ }) {
767
+ const t = useLocale();
768
+ const active = sort.key === sortKey;
769
+ const directionLabel = sort.direction === 'asc' ? t.asset.sortAscending : t.asset.sortDescending;
770
+ const DirectionIcon = sort.direction === 'asc' ? ArrowUp : ArrowDown;
771
+ const sortLabel = format(t.asset.sortByColumn, { column: label });
772
+
773
+ return (
774
+ <button
775
+ type="button"
776
+ onClick={() => onSort(sortKey)}
777
+ aria-label={active ? `${sortLabel}, ${directionLabel}` : sortLabel}
778
+ title={active ? `${sortLabel} · ${directionLabel}` : sortLabel}
779
+ className={cn(
780
+ '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',
781
+ active && 'text-foreground',
782
+ className,
783
+ )}
784
+ >
785
+ <span className="truncate">{label}</span>
786
+ {active ? (
787
+ <DirectionIcon className="size-2.5 shrink-0" aria-hidden />
788
+ ) : (
789
+ <ArrowUpDown
790
+ className="size-2.5 shrink-0 opacity-0 transition-opacity group-hover:opacity-60 group-focus-visible:opacity-60"
791
+ aria-hidden
792
+ />
793
+ )}
794
+ </button>
795
+ );
796
+ }
797
+
798
+ function AssetListHeader({
799
+ sort,
800
+ onSort,
801
+ }: {
802
+ sort: AssetSortOptions;
803
+ onSort: (key: AssetSortKey) => void;
804
+ }) {
805
+ const t = useLocale();
806
+ return (
807
+ <div className="hidden items-center gap-3 px-2 pb-1 text-[9px] font-semibold uppercase tracking-[0.12em] text-muted-foreground/70 sm:flex">
808
+ <SortableColumnHeader
809
+ label={t.asset.nameColumn}
810
+ sortKey="name"
811
+ sort={sort}
812
+ onSort={onSort}
813
+ className="min-w-0 flex-1"
814
+ />
815
+ <SortableColumnHeader
816
+ label={t.asset.typeColumn}
817
+ sortKey="type"
818
+ sort={sort}
819
+ onSort={onSort}
820
+ className="hidden w-40 shrink-0 md:flex"
821
+ />
822
+ <SortableColumnHeader
823
+ label={t.asset.modifiedAt}
824
+ sortKey="modified"
825
+ sort={sort}
826
+ onSort={onSort}
827
+ className="hidden w-28 shrink-0 lg:flex"
828
+ />
829
+ <SortableColumnHeader
830
+ label={t.asset.sizeColumn}
831
+ sortKey="size"
832
+ sort={sort}
833
+ onSort={onSort}
834
+ className="w-16 shrink-0"
835
+ />
836
+ <span className="w-16 shrink-0 text-right">{t.asset.statusColumn}</span>
837
+ <span className="size-6 shrink-0" aria-hidden />
838
+ </div>
839
+ );
840
+ }
841
+
376
842
  function AssetCard({
377
843
  asset,
378
844
  onPreview,
@@ -416,56 +882,194 @@ function AssetCard({
416
882
  </div>
417
883
  <div className="folio flex items-center gap-1.5">
418
884
  <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}
885
+ <UsageBadge unused={asset.unused} />
424
886
  </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
- )}
887
+ <div
888
+ className="mt-0.5 flex min-w-0 items-center gap-1 text-[10.5px] leading-tight text-muted-foreground"
889
+ title={`${t.asset.modifiedAt}: ${formatAssetDate(asset.mtime, t.id, true)}`}
434
890
  >
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>
891
+ <span className="shrink-0">{t.asset.modifiedAt}</span>
892
+ <span className="opacity-40">·</span>
893
+ <time dateTime={assetDateTime(asset.mtime)} className="truncate font-mono">
894
+ {formatAssetDate(asset.mtime, t.id)}
895
+ </time>
896
+ </div>
897
+ </div>
898
+ <AssetActions asset={asset} onPreview={onPreview} onRename={onRename} onDelete={onDelete} />
899
+ </div>
900
+ </div>
901
+ );
902
+ }
903
+
904
+ function AssetListItem({
905
+ asset,
906
+ onPreview,
907
+ onRename,
908
+ onDelete,
909
+ }: {
910
+ asset: AssetEntry;
911
+ onPreview: () => void;
912
+ onRename: () => void;
913
+ onDelete: () => void;
914
+ }) {
915
+ const isImage = asset.mime.startsWith('image/');
916
+ const t = useLocale();
917
+ return (
918
+ <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">
919
+ <button
920
+ type="button"
921
+ onClick={onPreview}
922
+ aria-label={format(t.asset.previewAria, { name: asset.name })}
923
+ 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]"
924
+ >
925
+ {isImage ? (
926
+ <img
927
+ src={asset.url}
928
+ alt=""
929
+ className="size-full object-contain"
930
+ draggable={false}
931
+ onError={(event) => {
932
+ event.currentTarget.style.display = 'none';
933
+ }}
934
+ />
935
+ ) : (
936
+ <FileIcon className="size-5 text-muted-foreground" />
937
+ )}
938
+ </button>
939
+ <div className="min-w-0 flex-1">
940
+ <div className="truncate text-[12.5px] font-medium" title={asset.name}>
941
+ {asset.name}
942
+ </div>
943
+ <div className="folio mt-0.5 flex min-w-0 items-center gap-1.5 lg:hidden">
944
+ <span className="sm:hidden">{formatSize(asset.size)}</span>
945
+ <span className="opacity-40 sm:hidden">·</span>
946
+ <span className="truncate md:hidden">{asset.mime}</span>
947
+ <span className="opacity-40 md:hidden">·</span>
948
+ <span className="shrink-0">{t.asset.modifiedAt}</span>
949
+ <time dateTime={assetDateTime(asset.mtime)} className="truncate">
950
+ {formatAssetDate(asset.mtime, t.id)}
951
+ </time>
952
+ <span className="sm:hidden">
953
+ <UsageBadge unused={asset.unused} showUsed />
954
+ </span>
955
+ </div>
956
+ </div>
957
+ <span className="hidden w-40 shrink-0 truncate font-mono text-[11px] text-muted-foreground md:block">
958
+ {asset.mime}
959
+ </span>
960
+ <time
961
+ dateTime={assetDateTime(asset.mtime)}
962
+ title={`${t.asset.modifiedAt}: ${formatAssetDate(asset.mtime, t.id, true)}`}
963
+ className="hidden w-28 shrink-0 text-[11.5px] text-muted-foreground lg:block"
964
+ >
965
+ <span className="sr-only">{t.asset.modifiedAt}: </span>
966
+ {formatAssetDate(asset.mtime, t.id)}
967
+ </time>
968
+ <span className="folio hidden w-16 shrink-0 sm:block">{formatSize(asset.size)}</span>
969
+ <div className="hidden w-16 shrink-0 justify-end sm:flex">
970
+ <UsageBadge unused={asset.unused} showUsed />
452
971
  </div>
972
+ <AssetActions asset={asset} onPreview={onPreview} onRename={onRename} onDelete={onDelete} />
453
973
  </div>
454
974
  );
455
975
  }
456
976
 
457
- function RenameCard({
977
+ function AssetActions({
458
978
  asset,
979
+ onPreview,
980
+ onRename,
981
+ onDelete,
982
+ }: {
983
+ asset: AssetEntry;
984
+ onPreview: () => void;
985
+ onRename: () => void;
986
+ onDelete: () => void;
987
+ }) {
988
+ const t = useLocale();
989
+ return (
990
+ <DropdownMenu>
991
+ <DropdownMenuTrigger
992
+ type="button"
993
+ aria-label={format(t.asset.actionsAria, { name: asset.name })}
994
+ className={cn(
995
+ buttonVariants({ variant: 'ghost', size: 'icon-xs' }),
996
+ 'opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100 aria-expanded:opacity-100',
997
+ )}
998
+ >
999
+ <MoreVertical />
1000
+ </DropdownMenuTrigger>
1001
+ <DropdownMenuContent align="end" className="min-w-[160px]">
1002
+ <DropdownMenuItem onSelect={onPreview}>
1003
+ <ImageIcon />
1004
+ {t.asset.previewMenuItem}
1005
+ </DropdownMenuItem>
1006
+ <DropdownMenuItem onSelect={onRename}>
1007
+ <Pencil />
1008
+ {t.asset.renameMenuItem}
1009
+ </DropdownMenuItem>
1010
+ <DropdownMenuItem onSelect={onDelete}>
1011
+ <Trash2 />
1012
+ {t.asset.deleteMenuItem}
1013
+ </DropdownMenuItem>
1014
+ </DropdownMenuContent>
1015
+ </DropdownMenu>
1016
+ );
1017
+ }
1018
+
1019
+ function UsageBadge({ unused, showUsed = false }: { unused: boolean; showUsed?: boolean }) {
1020
+ const t = useLocale();
1021
+ if (!unused && !showUsed) return null;
1022
+ return (
1023
+ <span
1024
+ className={cn(
1025
+ 'shrink-0 rounded-sm px-1 py-px text-[10px] font-medium leading-none',
1026
+ unused
1027
+ ? 'bg-muted text-muted-foreground'
1028
+ : 'bg-emerald-500/15 text-emerald-700 dark:text-emerald-400',
1029
+ )}
1030
+ >
1031
+ {unused ? t.asset.usageUnused : t.asset.usageUsed}
1032
+ </span>
1033
+ );
1034
+ }
1035
+
1036
+ function AssetTimestamp({
1037
+ label,
1038
+ timestamp,
1039
+ locale,
1040
+ }: {
1041
+ label: string;
1042
+ timestamp: number;
1043
+ locale: string;
1044
+ }) {
1045
+ return (
1046
+ <div className="bg-card px-3 py-2.5">
1047
+ <span className="eyebrow block text-[9px]">{label}</span>
1048
+ <time
1049
+ dateTime={assetDateTime(timestamp)}
1050
+ className="mt-1 block text-[12px] font-medium tabular-nums"
1051
+ >
1052
+ {formatAssetDate(timestamp, locale, true)}
1053
+ </time>
1054
+ </div>
1055
+ );
1056
+ }
1057
+
1058
+ function RenameAsset({
1059
+ asset,
1060
+ viewMode,
459
1061
  onCancel,
460
1062
  onSubmit,
461
1063
  }: {
462
1064
  asset: AssetEntry;
1065
+ viewMode: ViewMode;
463
1066
  onCancel: () => void;
464
1067
  onSubmit: (next: string) => Promise<void> | void;
465
1068
  }) {
466
1069
  const [value, setValue] = useState(asset.name);
467
1070
  const [saving, setSaving] = useState(false);
468
1071
  const inputRef = useRef<HTMLInputElement | null>(null);
1072
+ const t = useLocale();
469
1073
 
470
1074
  useEffect(() => {
471
1075
  queueMicrotask(() => {
@@ -491,8 +1095,58 @@ function RenameCard({
491
1095
  };
492
1096
 
493
1097
  const isImage = asset.mime.startsWith('image/');
1098
+ if (viewMode === 'list') {
1099
+ return (
1100
+ <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">
1101
+ <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]">
1102
+ {isImage ? (
1103
+ <img src={asset.url} alt="" className="size-full object-contain" draggable={false} />
1104
+ ) : (
1105
+ <FileIcon className="size-5 text-muted-foreground" />
1106
+ )}
1107
+ </div>
1108
+ <input
1109
+ ref={inputRef}
1110
+ value={value}
1111
+ disabled={saving}
1112
+ onChange={(event) => setValue(event.target.value)}
1113
+ onBlur={() => {
1114
+ if (!saving) commit();
1115
+ }}
1116
+ onKeyDown={(event) => {
1117
+ if (event.nativeEvent.isComposing) return;
1118
+ if (event.key === 'Enter') {
1119
+ event.preventDefault();
1120
+ commit();
1121
+ } else if (event.key === 'Escape') {
1122
+ event.preventDefault();
1123
+ onCancel();
1124
+ }
1125
+ }}
1126
+ maxLength={120}
1127
+ 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"
1128
+ />
1129
+ <span className="hidden w-40 shrink-0 truncate font-mono text-[11px] text-muted-foreground md:block">
1130
+ {asset.mime}
1131
+ </span>
1132
+ <time
1133
+ dateTime={assetDateTime(asset.mtime)}
1134
+ className="hidden w-28 shrink-0 text-[11.5px] text-muted-foreground lg:block"
1135
+ >
1136
+ <span className="sr-only">{t.asset.modifiedAt}: </span>
1137
+ {formatAssetDate(asset.mtime, t.id)}
1138
+ </time>
1139
+ <span className="folio hidden w-16 shrink-0 sm:block">{formatSize(asset.size)}</span>
1140
+ <div className="hidden w-16 shrink-0 justify-end sm:flex">
1141
+ <UsageBadge unused={asset.unused} showUsed />
1142
+ </div>
1143
+ <div className="size-6 shrink-0" />
1144
+ </div>
1145
+ );
1146
+ }
1147
+
494
1148
  return (
495
- <div className="relative flex flex-col overflow-hidden rounded-xl border-2 border-primary bg-card shadow-sm">
1149
+ <div className="relative flex flex-col overflow-hidden rounded-[6px] border border-primary bg-card shadow-edge ring-2 ring-primary/15">
496
1150
  <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
1151
  {isImage ? (
498
1152
  <img src={asset.url} alt="" className="size-full object-contain" draggable={false} />
@@ -670,6 +1324,10 @@ function PreviewDialog({
670
1324
  <span className="text-sm">{t.asset.noPreview}</span>
671
1325
  </div>
672
1326
  )}
1327
+ <div className="grid grid-cols-2 gap-px overflow-hidden rounded-[6px] border border-hairline bg-hairline">
1328
+ <AssetTimestamp label={t.asset.createdAt} timestamp={asset.createdAt} locale={t.id} />
1329
+ <AssetTimestamp label={t.asset.modifiedAt} timestamp={asset.mtime} locale={t.id} />
1330
+ </div>
673
1331
  <div className="rounded-[5px] border border-hairline bg-muted/50 px-3 py-2 font-mono text-[11.5px] leading-relaxed">
674
1332
  <span className="text-muted-foreground">{t.asset.importHintComment}</span>
675
1333
  <span className="text-brand">'{importPath}'</span>
@@ -959,6 +1617,28 @@ function slugify(s: string): string {
959
1617
  .replace(/^-|-$/g, '');
960
1618
  }
961
1619
 
1620
+ const ASSET_DATE_FORMATTERS = new Map<string, Intl.DateTimeFormat>();
1621
+
1622
+ function formatAssetDate(timestamp: number, locale: string, includeTime = false): string {
1623
+ const date = new Date(timestamp);
1624
+ if (Number.isNaN(date.getTime())) return '—';
1625
+ const key = `${locale}:${includeTime ? 'date-time' : 'date'}`;
1626
+ let formatter = ASSET_DATE_FORMATTERS.get(key);
1627
+ if (!formatter) {
1628
+ formatter = new Intl.DateTimeFormat(
1629
+ locale,
1630
+ includeTime ? { dateStyle: 'medium', timeStyle: 'short' } : { dateStyle: 'medium' },
1631
+ );
1632
+ ASSET_DATE_FORMATTERS.set(key, formatter);
1633
+ }
1634
+ return formatter.format(date);
1635
+ }
1636
+
1637
+ function assetDateTime(timestamp: number): string | undefined {
1638
+ const date = new Date(timestamp);
1639
+ return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
1640
+ }
1641
+
962
1642
  function formatSize(bytes: number): string {
963
1643
  if (bytes < 1024) return `${bytes} B`;
964
1644
  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;