@prenta/admin 2.11.2 → 2.12.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 (54) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/__tests__/components/modal.render.test.js +30 -1
  3. package/dist/__tests__/components/modal.render.test.js.map +1 -1
  4. package/dist/__tests__/lib/media-download.test.d.ts +2 -0
  5. package/dist/__tests__/lib/media-download.test.d.ts.map +1 -0
  6. package/dist/__tests__/lib/media-download.test.js +14 -0
  7. package/dist/__tests__/lib/media-download.test.js.map +1 -0
  8. package/dist/__tests__/views/media-browser.render.test.d.ts +2 -0
  9. package/dist/__tests__/views/media-browser.render.test.d.ts.map +1 -0
  10. package/dist/__tests__/views/media-browser.render.test.js +270 -0
  11. package/dist/__tests__/views/media-browser.render.test.js.map +1 -0
  12. package/dist/__tests__/views/media-grid.test.js +12 -1
  13. package/dist/__tests__/views/media-grid.test.js.map +1 -1
  14. package/dist/components/MediaLightbox.d.ts +22 -0
  15. package/dist/components/MediaLightbox.d.ts.map +1 -0
  16. package/dist/components/MediaLightbox.js +38 -0
  17. package/dist/components/MediaLightbox.js.map +1 -0
  18. package/dist/components/ui/ConfirmDialog.d.ts +3 -1
  19. package/dist/components/ui/ConfirmDialog.d.ts.map +1 -1
  20. package/dist/components/ui/ConfirmDialog.js +2 -2
  21. package/dist/components/ui/ConfirmDialog.js.map +1 -1
  22. package/dist/components/ui/Modal.d.ts +7 -1
  23. package/dist/components/ui/Modal.d.ts.map +1 -1
  24. package/dist/components/ui/Modal.js +4 -2
  25. package/dist/components/ui/Modal.js.map +1 -1
  26. package/dist/lib/dialog-return-focus.d.ts +10 -0
  27. package/dist/lib/dialog-return-focus.d.ts.map +1 -0
  28. package/dist/lib/dialog-return-focus.js +26 -0
  29. package/dist/lib/dialog-return-focus.js.map +1 -0
  30. package/dist/lib/media-download.d.ts +8 -0
  31. package/dist/lib/media-download.d.ts.map +1 -0
  32. package/dist/lib/media-download.js +21 -0
  33. package/dist/lib/media-download.js.map +1 -0
  34. package/dist/prenta-admin.css +1 -1
  35. package/dist/views/MediaBrowser.d.ts +34 -0
  36. package/dist/views/MediaBrowser.d.ts.map +1 -1
  37. package/dist/views/MediaBrowser.js +190 -51
  38. package/dist/views/MediaBrowser.js.map +1 -1
  39. package/dist/views/MediaSeoAudit.d.ts +6 -0
  40. package/dist/views/MediaSeoAudit.d.ts.map +1 -1
  41. package/dist/views/MediaSeoAudit.js +12 -0
  42. package/dist/views/MediaSeoAudit.js.map +1 -1
  43. package/package.json +5 -5
  44. package/src/__tests__/components/modal.render.test.tsx +52 -0
  45. package/src/__tests__/lib/media-download.test.ts +23 -0
  46. package/src/__tests__/views/media-browser.render.test.tsx +325 -0
  47. package/src/__tests__/views/media-grid.test.ts +13 -1
  48. package/src/components/MediaLightbox.tsx +127 -0
  49. package/src/components/ui/ConfirmDialog.tsx +4 -0
  50. package/src/components/ui/Modal.tsx +10 -0
  51. package/src/lib/dialog-return-focus.ts +33 -0
  52. package/src/lib/media-download.ts +18 -0
  53. package/src/views/MediaBrowser.tsx +367 -143
  54. package/src/views/MediaSeoAudit.tsx +11 -0
@@ -7,7 +7,7 @@ import {
7
7
  Search,
8
8
  Trash2,
9
9
  Download,
10
- FileText,
10
+ Maximize2,
11
11
  ArrowUpDown,
12
12
  ArrowUp,
13
13
  ArrowDown,
@@ -33,11 +33,20 @@ import { cmsApi } from '../lib/api.js'
33
33
  import { useVirtualWindow, VirtualTablePadding } from '../components/virtual-window.js'
34
34
  import { FolderTree, type FolderSelection } from '../components/FolderTree.js'
35
35
  import { Button } from '../components/ui/Button.js'
36
+ import { ConfirmDialog } from '../components/ui/ConfirmDialog.js'
37
+ import { MediaLightbox } from '../components/MediaLightbox.js'
38
+ import { mediaDownloadUrl } from '../lib/media-download.js'
36
39
  import { TIER_MEDIA } from '../lib/tiers.js'
37
40
  import { useSheetFocus } from '../lib/sheet-focus.js'
38
41
  import { StatusBadge } from '../components/ui/StatusBadge.js'
39
42
  import { CountChip } from '../components/ui/CountChip.js'
40
- import { hasLowQualityAlt, MediaSeoAudit, type MediaSeoAuditItem } from './MediaSeoAudit.js'
43
+ import { FilterPill } from '../components/ui/FilterPill.js'
44
+ import {
45
+ hasLowQualityAlt,
46
+ MediaSeoAudit,
47
+ scoreBadgeClass,
48
+ type MediaSeoAuditItem,
49
+ } from './MediaSeoAudit.js'
41
50
  import { pickedImages } from '../lib/batch-wizard.js'
42
51
  import { RunWithAi } from './Jobs/RunWithAi.js'
43
52
 
@@ -77,15 +86,35 @@ function isImageMedia(item: MediaItem): boolean {
77
86
  )
78
87
  }
79
88
 
80
- function matchesMediaType(item: MediaItem, filterType: string): boolean {
81
- if (filterType === 'all') return true
82
- if (filterType === 'image') return item.type?.startsWith('image/') || isImageMedia(item)
83
- if (filterType === 'video') return item.type?.startsWith('video/')
84
- if (filterType === 'document')
85
- return !item.type?.startsWith('image/') && !item.type?.startsWith('video/')
86
- return item.type === filterType
89
+ /** Media.html `.type-pills` kinds, disjoint; `document` (Word, Excel, …) is repo-only. */
90
+ export type MediaKind = 'image' | 'video' | 'pdf' | 'svg' | 'document'
91
+ export type MediaTypeFilter = 'all' | MediaKind
92
+
93
+ export function mediaKind(item: Pick<MediaItem, 'type' | 'name' | 'url'>): MediaKind {
94
+ const file = `${item.name ?? ''} ${item.url ?? ''}`
95
+ if (item.type === 'image/svg+xml' || /\.svg(\s|$|\?)/i.test(file)) return 'svg'
96
+ if (item.type?.startsWith('image/') || /\.(avif|gif|jpe?g|png|webp)(\s|$|\?)/i.test(file))
97
+ return 'image'
98
+ if (item.type?.startsWith('video/')) return 'video'
99
+ if (item.type === 'application/pdf' || /\.pdf(\s|$|\?)/i.test(file)) return 'pdf'
100
+ return 'document'
101
+ }
102
+
103
+ function matchesMediaType(item: MediaItem, filter: MediaTypeFilter): boolean {
104
+ return filter === 'all' || mediaKind(item) === filter
87
105
  }
88
106
 
107
+ const TYPE_PILLS: ReadonlyArray<{ value: MediaTypeFilter; label: string }> = [
108
+ { value: 'all', label: 'All' },
109
+ { value: 'image', label: 'Images' },
110
+ { value: 'video', label: 'Video' },
111
+ { value: 'pdf', label: 'PDF' },
112
+ { value: 'svg', label: 'SVG' },
113
+ { value: 'document', label: 'Documents' },
114
+ ]
115
+
116
+ type SortPreset = 'date' | 'name' | 'score' | 'size'
117
+
89
118
  function formatStorage(bytes: number): string {
90
119
  if (bytes <= 0) return '0 B'
91
120
  const units = ['B', 'KB', 'MB', 'GB', 'TB']
@@ -94,13 +123,17 @@ function formatStorage(bytes: number): string {
94
123
  return `${value >= 100 || i === 0 ? Math.round(value) : value.toFixed(1)} ${units[i]}`
95
124
  }
96
125
 
97
- function MediaPreview({ item }: { item: MediaItem }) {
126
+ function mediaAlt(item: MediaItem): string {
127
+ return item.altTag || item.title || item.name || 'Media preview'
128
+ }
129
+
130
+ function MediaPreview({ item, fit = 'cover' }: { item: MediaItem; fit?: 'cover' | 'contain' }) {
98
131
  if (isImageMedia(item)) {
99
132
  return (
100
133
  <img
101
134
  src={item.url}
102
- alt={item.altTag || item.title || item.name || 'Media preview'}
103
- className="h-full w-full object-cover"
135
+ alt={mediaAlt(item)}
136
+ className={`h-full w-full ${fit === 'contain' ? 'object-contain' : 'object-cover'}`}
104
137
  loading="lazy"
105
138
  />
106
139
  )
@@ -109,7 +142,33 @@ function MediaPreview({ item }: { item: MediaItem }) {
109
142
  return <FileImage className="text-muted-foreground h-6 w-6 sm:h-8 sm:w-8" />
110
143
  }
111
144
 
112
- type MediaSortKey = 'name' | 'type' | 'size' | 'date'
145
+ type MediaSortKey = 'name' | 'type' | 'size' | 'date' | 'score'
146
+
147
+ /** The sort select's presets (Media.html `.sort-sel`); list-column sorts that match none read "custom". */
148
+ function sortPresetOf(sort: SortConfig<MediaSortKey> | null): SortPreset | 'custom' {
149
+ if (!sort) return 'date'
150
+ if (sort.key === 'name' && sort.direction === 'asc') return 'name'
151
+ if (sort.key === 'score' && sort.direction === 'desc') return 'score'
152
+ if (sort.key === 'size' && sort.direction === 'desc') return 'size'
153
+ return 'custom'
154
+ }
155
+
156
+ function sortForPreset(preset: SortPreset): SortConfig<MediaSortKey> | null {
157
+ switch (preset) {
158
+ case 'date':
159
+ return null
160
+ case 'name':
161
+ return { key: 'name', direction: 'asc' }
162
+ case 'score':
163
+ return { key: 'score', direction: 'desc' }
164
+ case 'size':
165
+ return { key: 'size', direction: 'desc' }
166
+ default: {
167
+ const unreachable: never = preset
168
+ return unreachable
169
+ }
170
+ }
171
+ }
113
172
 
114
173
  export interface MediaBrowserProps {
115
174
  onNavigate?: (path: string) => void
@@ -129,6 +188,8 @@ const MEDIA_GRID_GAP = 14
129
188
  const MEDIA_GRID_PADDING_X = 28
130
189
  const MEDIA_CARD_HEIGHT = 172
131
190
  export const MEDIA_GRID_ROW_HEIGHT = MEDIA_CARD_HEIGHT + MEDIA_GRID_GAP
191
+ /** `POST /media/bulk-delete` accepts at most this many ids (`BULK_MEDIA_MAX_ITEMS`). */
192
+ const BULK_DELETE_CHUNK = 50
132
193
 
133
194
  /** Columns that fit `auto-fill, minmax(220px, 1fr)` in the grid's content box. */
134
195
  export function mediaGridColumns(contentWidth: number): number {
@@ -174,10 +235,12 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
174
235
  const [activeTab, setActiveTab] = useState<'library' | 'audit'>('library')
175
236
  const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid')
176
237
  const [searchQuery, setSearchQuery] = useState('')
177
- const [filterType, setFilterType] = useState('all')
238
+ const [filterType, setFilterType] = useState<MediaTypeFilter>('all')
178
239
  const [selectedMedia, setSelectedMedia] = useState<Array<number | string>>([])
179
240
  const [sortConfig, setSortConfig] = useState<SortConfig<MediaSortKey> | null>(null)
180
241
  const [activeItem, setActiveItem] = useState<MediaItem | null>(null)
242
+ const [pendingDelete, setPendingDelete] = useState<Array<number | string> | null>(null)
243
+ const [lightboxId, setLightboxId] = useState<number | string | null>(null)
181
244
 
182
245
  const [editAlt, setEditAlt] = useState('')
183
246
  const [editIsDecorative, setEditIsDecorative] = useState(false)
@@ -207,6 +270,8 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
207
270
  let cmp: number
208
271
  if (sortConfig.key === 'size') {
209
272
  cmp = a.sizeBytes - b.sizeBytes
273
+ } else if (sortConfig.key === 'score') {
274
+ cmp = (a.seoScore ?? 0) - (b.seoScore ?? 0)
210
275
  } else {
211
276
  cmp = String(a[sortConfig.key]).localeCompare(String(b[sortConfig.key]))
212
277
  }
@@ -216,6 +281,47 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
216
281
  return results
217
282
  }, [mediaItems, searchQuery, filterType, sortConfig])
218
283
 
284
+ const typeCounts = useMemo(() => {
285
+ const counts: Record<MediaTypeFilter, number> = {
286
+ all: mediaItems.length,
287
+ image: 0,
288
+ video: 0,
289
+ pdf: 0,
290
+ svg: 0,
291
+ document: 0,
292
+ }
293
+ for (const item of mediaItems) counts[mediaKind(item)]++
294
+ return counts
295
+ }, [mediaItems])
296
+
297
+ // The viewer steps through the images on screen. If search or a type pill
298
+ // has hidden the open panel's image, it shows that image alone rather than
299
+ // doing nothing.
300
+ const lightboxItems = useMemo(() => {
301
+ const toViewerItem = (item: MediaItem) => ({
302
+ id: item.id,
303
+ url: item.url,
304
+ name: item.name,
305
+ alt: mediaAlt(item),
306
+ dimensions: item.dimensions,
307
+ })
308
+ const onScreen = filteredAndSorted.filter(isImageMedia).map(toViewerItem)
309
+ if (
310
+ activeItem &&
311
+ isImageMedia(activeItem) &&
312
+ !onScreen.some((item) => item.id === activeItem.id)
313
+ ) {
314
+ return [toViewerItem(activeItem)]
315
+ }
316
+ return onScreen
317
+ }, [filteredAndSorted, activeItem])
318
+
319
+ useEffect(() => {
320
+ if (lightboxId !== null && !lightboxItems.some((item) => item.id === lightboxId)) {
321
+ setLightboxId(null)
322
+ }
323
+ }, [lightboxId, lightboxItems])
324
+
219
325
  const gridScrollRef = useRef<HTMLDivElement>(null)
220
326
  const [gridWidth, setGridWidth] = useState(0)
221
327
  const gridMounted = viewMode === 'grid' && activeTab === 'library' && filteredAndSorted.length > 0
@@ -231,6 +337,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
231
337
  }, [gridMounted, loading])
232
338
  const gridColumns = mediaGridColumns(gridWidth)
233
339
  const listScrollRef = useRef<HTMLDivElement>(null)
340
+ const focusLibrary = useCallback(() => gridScrollRef.current ?? listScrollRef.current, [])
234
341
  /** The grid's or list's scroll position when a card opened the detail panel. */
235
342
  const savedListScroll = useRef(0)
236
343
  const gridRowCount = gridColumns > 0 ? Math.ceil(filteredAndSorted.length / gridColumns) : 0
@@ -352,15 +459,48 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
352
459
  }
353
460
  }
354
461
 
355
- const deleteMedia = async (id: number | string) => {
356
- const res = await cmsApi(`/media/${id}`, { method: 'DELETE' })
357
- if (res.error) {
358
- toast.error(res.error)
462
+ const deleteMedia = async (ids: Array<number | string>) => {
463
+ let deleted: Array<number | string> = []
464
+ let failed = 0
465
+ if (ids.length === 1) {
466
+ const res = await cmsApi(`/media/${ids[0]}`, { method: 'DELETE' })
467
+ if (res.error) {
468
+ toast.error(res.error)
469
+ return
470
+ }
471
+ deleted = ids
359
472
  } else {
360
- toast.success('Media deleted')
361
- if (activeItem?.id === id) closeDetail()
362
- refetch()
473
+ for (let i = 0; i < ids.length; i += BULK_DELETE_CHUNK) {
474
+ const chunk = ids.slice(i, i + BULK_DELETE_CHUNK)
475
+ const res = await cmsApi<{ results: Array<{ id: string; ok: boolean }> }>(
476
+ '/media/bulk-delete',
477
+ { method: 'POST', body: JSON.stringify({ ids: chunk.map(String), confirm: true }) },
478
+ )
479
+ if (res.error || !res.data) {
480
+ failed += chunk.length
481
+ continue
482
+ }
483
+ const ok = new Set(res.data.results.filter((r) => r.ok).map((r) => r.id))
484
+ deleted.push(...chunk.filter((id) => ok.has(String(id))))
485
+ failed += chunk.length - ok.size
486
+ }
487
+ }
488
+
489
+ if (deleted.length > 0) {
490
+ toast.success(deleted.length === 1 ? 'Media deleted' : `${deleted.length} files deleted`)
491
+ }
492
+ if (failed > 0) toast.error(`${failed} file${failed === 1 ? '' : 's'} couldn't be deleted`)
493
+ const gone = new Set(deleted.map(String))
494
+ if (activeItem && gone.has(String(activeItem.id))) {
495
+ closeDetail()
496
+ // The confirm dialog returned focus to the panel's Delete, which this removes.
497
+ requestAnimationFrame(() => {
498
+ const focused = document.activeElement
499
+ if (!focused || focused === document.body || !focused.isConnected) focusLibrary()?.focus()
500
+ })
363
501
  }
502
+ setSelectedMedia((prev) => prev.filter((id) => !gone.has(String(id))))
503
+ if (deleted.length > 0) refetch()
364
504
  }
365
505
 
366
506
  const handleAiGenerate = async (field: 'alt' | 'title' | 'optimize') => {
@@ -418,7 +558,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
418
558
  .replace(/[-_]/g, ' ')
419
559
  .trim()
420
560
  if (field === 'alt') {
421
- setEditAlt(base ? `Image of ${base}` : '')
561
+ setEditAlt(base)
422
562
  } else {
423
563
  setEditTitle(base.replace(/\b\w/g, (c) => c.toUpperCase()))
424
564
  }
@@ -544,8 +684,8 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
544
684
  // header), so the card that opened it leaves the screen. Focus moves into
545
685
  // the panel and back when it closes. The hidden scroll box comes back at the
546
686
  // top, and the virtualised window wouldn't follow (no scroll event), so its
547
- // position, saved when a card opens the panel, goes back first. Grid cards
548
- // aren't focusable, so focus lands on the list itself.
687
+ // position, saved when a card opens the panel, goes back first. If the
688
+ // opener is gone (virtualised out), focus lands on the list itself.
549
689
  useSheetFocus(panelOpen, detailPanelRef, {
550
690
  restore: () => {
551
691
  const scroller = gridScrollRef.current ?? listScrollRef.current
@@ -733,58 +873,99 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
733
873
 
734
874
  <div className="mobile:min-h-0 flex min-w-0 flex-1 flex-col">
735
875
  <div className="border-border bg-card mb-4 rounded-lg border">
736
- <div className="flex items-center justify-between p-3">
737
- <div className="flex flex-1 items-center gap-3">
738
- <div className="relative max-w-md flex-1">
739
- <Search
740
- className="text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2"
741
- aria-hidden
742
- />
743
- <input
744
- type="search"
745
- placeholder="Search media..."
746
- aria-label="Search media"
747
- value={searchQuery}
748
- onChange={(e) => setSearchQuery(e.target.value)}
749
- className="border-input focus:ring-ring w-full rounded-lg border py-2 pr-3 pl-9 text-sm focus:ring-2 focus:outline-none"
750
- />
751
- </div>
752
- <select
753
- value={filterType}
754
- onChange={(e) => setFilterType(e.target.value)}
755
- aria-label="Filter by type"
756
- className="border-input focus:ring-ring rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none"
757
- >
758
- <option value="all">All Types</option>
759
- <option value="image">Images</option>
760
- <option value="video">Videos</option>
761
- <option value="document">Documents</option>
762
- </select>
876
+ {/* Media.html `.mc-toolbar`. */}
877
+ <div className="flex flex-wrap items-center gap-2 px-3 py-3">
878
+ <label className="flex max-w-[280px] min-w-[180px] flex-1 items-center gap-[7px] rounded-[8px] border border-[var(--bdr)] bg-[var(--bg)] px-[11px] py-[6px] text-[var(--muted)] transition-colors focus-within:border-[var(--acc-m)]">
879
+ <Search size={13} aria-hidden />
880
+ <input
881
+ type="search"
882
+ placeholder="Search files…"
883
+ aria-label="Search files"
884
+ value={searchQuery}
885
+ onChange={(e) => setSearchQuery(e.target.value)}
886
+ className="w-full bg-transparent text-[13px] text-[var(--txt)] outline-none placeholder:text-[var(--muted)]"
887
+ />
888
+ {searchQuery && (
889
+ <button
890
+ type="button"
891
+ onClick={() => setSearchQuery('')}
892
+ aria-label="Clear search"
893
+ className="shrink-0 leading-none text-[var(--muted)] hover:text-[var(--txt)]"
894
+ >
895
+ <X size={12} aria-hidden />
896
+ </button>
897
+ )}
898
+ </label>
899
+ <div className="flex flex-wrap gap-[3px]" role="group" aria-label="Filter by type">
900
+ {TYPE_PILLS.filter(
901
+ (pill) =>
902
+ pill.value !== 'document' ||
903
+ typeCounts.document > 0 ||
904
+ filterType === 'document',
905
+ ).map((pill) => (
906
+ <FilterPill
907
+ key={pill.value}
908
+ active={filterType === pill.value}
909
+ count={typeCounts[pill.value]}
910
+ onClick={() => setFilterType(pill.value)}
911
+ >
912
+ {pill.label}
913
+ </FilterPill>
914
+ ))}
763
915
  </div>
916
+ <select
917
+ aria-label="Sort media"
918
+ value={sortPresetOf(sortConfig)}
919
+ onChange={(e) => {
920
+ const preset = e.target.value
921
+ if (preset === 'custom') return
922
+ setSortConfig(sortForPreset(preset as SortPreset))
923
+ }}
924
+ className="cursor-pointer rounded-[7px] border border-[var(--bdr)] bg-[var(--bg)] px-2 py-[5px] text-[12px] text-[var(--sub)] focus-visible:ring-2 focus-visible:ring-[var(--ring)] focus-visible:outline-none"
925
+ >
926
+ <option value="date">Recent first</option>
927
+ <option value="name">Name A–Z</option>
928
+ <option value="score">SEO score</option>
929
+ <option value="size">File size</option>
930
+ {sortPresetOf(sortConfig) === 'custom' && (
931
+ <option value="custom" disabled>
932
+ List column
933
+ </option>
934
+ )}
935
+ </select>
764
936
  <div
765
- className="bg-muted flex items-center gap-1 rounded-lg p-1"
937
+ className="flex overflow-hidden rounded-[7px] border border-[var(--bdr)]"
766
938
  role="group"
767
939
  aria-label="Media view"
768
940
  >
769
- <button
770
- type="button"
771
- onClick={() => setViewMode('grid')}
772
- aria-label="Grid view"
773
- aria-pressed={viewMode === 'grid'}
774
- className={`rounded p-1.5 transition-colors ${viewMode === 'grid' ? 'bg-card text-foreground shadow-sm' : 'text-muted-foreground hover:text-foreground'}`}
775
- >
776
- <Grid3x3 className="h-4 w-4" aria-hidden />
777
- </button>
778
- <button
779
- type="button"
780
- onClick={() => setViewMode('list')}
781
- aria-label="List view"
782
- aria-pressed={viewMode === 'list'}
783
- className={`rounded p-1.5 transition-colors ${viewMode === 'list' ? 'bg-card text-foreground shadow-sm' : 'text-muted-foreground hover:text-foreground'}`}
784
- >
785
- <List className="h-4 w-4" aria-hidden />
786
- </button>
941
+ {(
942
+ [
943
+ ['grid', 'Grid view', Grid3x3],
944
+ ['list', 'List view', List],
945
+ ] as const
946
+ ).map(([mode, label, Icon]) => (
947
+ <button
948
+ key={mode}
949
+ type="button"
950
+ onClick={() => setViewMode(mode)}
951
+ aria-label={label}
952
+ aria-pressed={viewMode === mode}
953
+ className={`flex h-[30px] w-[30px] items-center justify-center transition-colors focus-visible:ring-2 focus-visible:ring-[var(--ring)] focus-visible:outline-none focus-visible:ring-inset ${
954
+ viewMode === mode
955
+ ? 'bg-[var(--acc-l)] text-[var(--acc)]'
956
+ : 'text-[var(--muted)] hover:bg-[var(--bg)] hover:text-[var(--sub)]'
957
+ }`}
958
+ >
959
+ <Icon size={14} aria-hidden />
960
+ </button>
961
+ ))}
787
962
  </div>
963
+ <span
964
+ className="ml-auto shrink-0 text-[12px] whitespace-nowrap text-[var(--muted)]"
965
+ aria-live="polite"
966
+ >
967
+ {filteredAndSorted.length} file{filteredAndSorted.length === 1 ? '' : 's'}
968
+ </span>
788
969
  </div>
789
970
  </div>
790
971
 
@@ -809,10 +990,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
809
990
  />
810
991
  ) : null}
811
992
  <button
812
- onClick={async () => {
813
- for (const id of selectedMedia) await deleteMedia(id)
814
- setSelectedMedia([])
815
- }}
993
+ onClick={() => setPendingDelete(selectedMedia)}
816
994
  className="bg-destructive text-destructive-foreground hover:bg-destructive/90 rounded-lg px-3 py-1.5 text-sm transition-colors"
817
995
  >
818
996
  Delete Selected
@@ -852,9 +1030,8 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
852
1030
  {viewMode === 'grid' ? (
853
1031
  <div
854
1032
  ref={gridScrollRef}
855
- // The grid's cards aren't focusable yet, so the scroller
856
- // itself takes Tab and arrow-key scrolling (Media.html
857
- // `.mc-grid-area`; axe scrollable-region-focusable).
1033
+ // Media.html `.mc-grid-area`: the scroller takes arrow-key
1034
+ // scrolling (axe scrollable-region-focusable).
858
1035
  tabIndex={0}
859
1036
  role="region"
860
1037
  aria-label="Media library"
@@ -884,56 +1061,75 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
884
1061
  )
885
1062
  .map((item) => {
886
1063
  const isActive = activeItem?.id === item.id
887
- const hasIssues =
888
- !hasAccessibleAlt(item) ||
889
- !item.title ||
890
- item.usedOn?.length === 0
891
- const typeLabel = (
892
- item.name.includes('.')
893
- ? item.name.split('.').pop()!
894
- : item.format || item.type || ''
895
- )
896
- .replace(/^.*\//, '')
897
- .toUpperCase()
1064
+ const isSelected = selectedMedia.includes(item.id)
1065
+ // Media.html `hasMissing`: the card's "SEO" tag.
1066
+ const missingSeo = !hasAccessibleAlt(item) || !item.title?.trim()
1067
+ const score = item.seoScore
898
1068
  return (
899
1069
  <div
900
1070
  key={item.id}
901
1071
  data-media-card=""
902
- className={`group relative flex h-[172px] cursor-pointer flex-col overflow-hidden rounded-lg border-2 transition-all ${
903
- isActive
904
- ? 'border-primary ring-primary/30 ring-2'
905
- : selectedMedia.includes(item.id)
906
- ? 'border-primary/60 ring-primary/20 ring-1'
907
- : 'border-border hover:border-input'
1072
+ className={`group relative flex h-[172px] flex-col overflow-hidden rounded-[9px] border bg-[var(--card)] transition-[border-color,box-shadow] has-[button:focus-visible]:ring-2 has-[button:focus-visible]:ring-[var(--ring)] ${
1073
+ isActive || isSelected
1074
+ ? 'border-[var(--acc)] shadow-[0_0_0_2px_var(--acc-m)]'
1075
+ : 'border-[var(--bdr)] hover:border-[var(--acc-m)] hover:shadow-[var(--shd2)]'
908
1076
  }`}
909
- onClick={() => openDetail(item)}
910
1077
  draggable
911
1078
  onDragStart={(e) => handleDragStart(e, item.id)}
912
1079
  >
1080
+ {/* Stretched over the card so the whole tile opens it; the
1081
+ select control sits above it. */}
1082
+ <button
1083
+ type="button"
1084
+ onClick={() => openDetail(item)}
1085
+ aria-label={[
1086
+ `Open ${item.name}`,
1087
+ score !== undefined ? `SEO score ${score}` : '',
1088
+ missingSeo ? 'missing SEO' : '',
1089
+ ]
1090
+ .filter(Boolean)
1091
+ .join(', ')}
1092
+ aria-current={isActive ? 'true' : undefined}
1093
+ className="absolute inset-0 z-[1] cursor-pointer focus:outline-none"
1094
+ />
913
1095
  <div className="relative h-[118px] w-full shrink-0 overflow-hidden">
914
1096
  <div className="bg-muted flex h-full w-full items-center justify-center">
915
1097
  <MediaPreview item={item} />
916
1098
  </div>
917
- {hasIssues && (
918
- <div
919
- className="bg-warning absolute top-1.5 left-1.5 flex h-5 w-5 items-center justify-center rounded-full"
920
- title="Needs attention"
1099
+ {score !== undefined && (
1100
+ <span
1101
+ aria-hidden
1102
+ className={`absolute top-[7px] right-[7px] flex h-[22px] min-w-[22px] items-center justify-center rounded-[11px] px-[5px] text-[9.5px] font-bold tracking-[.2px] tabular-nums shadow-[var(--shd)] ${scoreBadgeClass(score)}`}
921
1103
  >
922
- <AlertTriangle className="text-warning-foreground h-3 w-3" />
923
- </div>
1104
+ {score}
1105
+ </span>
924
1106
  )}
925
- <div
926
- className="absolute top-1.5 right-1.5 opacity-0 transition-opacity group-hover:opacity-100"
1107
+ <span
1108
+ aria-hidden
1109
+ className="absolute bottom-[7px] left-[7px] rounded-[4px] bg-[var(--card)]/85 px-[6px] py-[2px] text-[9.5px] font-semibold tracking-[.3px] text-[var(--txt)] uppercase backdrop-blur-[4px]"
1110
+ >
1111
+ {mediaKind(item)}
1112
+ </span>
1113
+ <button
1114
+ type="button"
1115
+ role="checkbox"
1116
+ aria-checked={isSelected}
1117
+ aria-label={`Select ${item.name}`}
1118
+ className={`focus-visible:ring-ring absolute top-[7px] left-[7px] z-[2] rounded transition-opacity group-hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:outline-none [@media(hover:none)]:opacity-100 ${
1119
+ isSelected || selectedMedia.length > 0
1120
+ ? 'opacity-100'
1121
+ : 'opacity-0'
1122
+ }`}
927
1123
  onClick={(e) => handleCheckbox(e, item.id)}
928
1124
  >
929
- <div
1125
+ <span
930
1126
  className={`flex h-5 w-5 items-center justify-center rounded border-2 transition-colors ${
931
- selectedMedia.includes(item.id)
1127
+ isSelected
932
1128
  ? 'border-primary bg-primary'
933
1129
  : 'border-input bg-card/80'
934
1130
  }`}
935
1131
  >
936
- {selectedMedia.includes(item.id) && (
1132
+ {isSelected && (
937
1133
  <svg
938
1134
  className="text-primary-foreground h-3 w-3"
939
1135
  fill="none"
@@ -948,23 +1144,23 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
948
1144
  />
949
1145
  </svg>
950
1146
  )}
951
- </div>
952
- </div>
1147
+ </span>
1148
+ </button>
953
1149
  </div>
954
- <div className="border-border bg-card flex min-h-0 flex-1 items-center gap-2 border-t px-2 py-1.5">
955
- <span
956
- className={`mt-0.5 h-2 w-2 shrink-0 self-start rounded-full ${
957
- hasIssues ? 'bg-warning' : 'bg-success'
958
- }`}
959
- title={hasIssues ? 'Needs attention' : 'SEO complete'}
960
- />
961
- <div className="min-w-0 flex-1">
962
- <p className="text-foreground truncate text-xs font-medium">
963
- {item.name}
964
- </p>
965
- <p className="text-muted-foreground truncate text-xs">
966
- {[typeLabel, item.size].filter(Boolean).join(' · ')}
967
- </p>
1150
+ <div className="min-h-0 flex-1 px-[10px] pt-[8px] pb-[10px]">
1151
+ <p className="truncate text-[12px] font-medium text-[var(--txt)]">
1152
+ {item.name}
1153
+ </p>
1154
+ <div className="mt-[3px] flex items-center gap-[5px]">
1155
+ <span className="text-[11px] text-[var(--muted)]">
1156
+ {item.size}
1157
+ </span>
1158
+ {missingSeo && (
1159
+ <span className="ml-auto inline-flex items-center gap-[3px] rounded-[3px] bg-[var(--err-l)] px-[5px] py-px text-[10px] font-medium text-[var(--err)]">
1160
+ <AlertTriangle size={9} aria-hidden />
1161
+ SEO
1162
+ </span>
1163
+ )}
968
1164
  </div>
969
1165
  </div>
970
1166
  </div>
@@ -1106,9 +1302,20 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
1106
1302
 
1107
1303
  <div className="flex-1 overflow-y-auto">
1108
1304
  <div className="border-border border-b p-4">
1109
- <div className="bg-muted flex aspect-video items-center justify-center overflow-hidden rounded-lg">
1305
+ <div className="bg-muted relative flex aspect-video items-center justify-center overflow-hidden rounded-lg">
1110
1306
  {isImageMedia(activeItem) ? (
1111
- <MediaPreview item={activeItem} />
1307
+ <>
1308
+ <MediaPreview item={activeItem} fit="contain" />
1309
+ <button
1310
+ type="button"
1311
+ onClick={() => setLightboxId(activeItem.id)}
1312
+ aria-label="View full size"
1313
+ title="View full size"
1314
+ className="border-border bg-card/90 text-foreground hover:bg-card focus-visible:ring-ring prenta-touch-target absolute top-2 right-2 flex h-8 w-8 items-center justify-center rounded-md border shadow-sm transition-colors focus-visible:ring-2 focus-visible:outline-none"
1315
+ >
1316
+ <Maximize2 size={14} aria-hidden />
1317
+ </button>
1318
+ </>
1112
1319
  ) : (
1113
1320
  <ImageIcon className="text-muted-foreground h-12 w-12" />
1114
1321
  )}
@@ -1419,20 +1626,6 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
1419
1626
  </div>
1420
1627
  </div>
1421
1628
  </button>
1422
- <button
1423
- type="button"
1424
- className="border-border hover:bg-muted flex w-full items-center gap-2 rounded-lg border p-4 text-left transition-colors"
1425
- >
1426
- <Bot className="text-muted-foreground h-5 w-5 shrink-0" />
1427
- <div className="flex-1">
1428
- <div className="text-foreground text-sm font-medium">
1429
- AI Content Analysis
1430
- </div>
1431
- <div className="text-muted-foreground mt-0.5 text-xs">
1432
- Detect objects, faces, text, and suggest categories
1433
- </div>
1434
- </div>
1435
- </button>
1436
1629
  </div>
1437
1630
  </div>
1438
1631
 
@@ -1446,17 +1639,20 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
1446
1639
  {saving && <Loader2 className="h-4 w-4 animate-spin" />}
1447
1640
  {saving ? 'Saving...' : 'Save Changes'}
1448
1641
  </button>
1449
- <button
1450
- type="button"
1451
- className="hover:bg-muted rounded-lg p-2 transition-colors"
1642
+ <a
1643
+ href={mediaDownloadUrl(activeItem.url)}
1644
+ download={activeItem.name}
1645
+ target="_blank"
1646
+ rel="noopener noreferrer"
1647
+ className="hover:bg-muted focus-visible:ring-ring rounded-lg p-2 transition-colors focus-visible:ring-2 focus-visible:outline-none"
1452
1648
  title="Download"
1453
1649
  aria-label="Download"
1454
1650
  >
1455
1651
  <Download className="text-muted-foreground h-4 w-4" aria-hidden />
1456
- </button>
1652
+ </a>
1457
1653
  <button
1458
1654
  type="button"
1459
- onClick={() => deleteMedia(activeItem.id)}
1655
+ onClick={() => setPendingDelete([activeItem.id])}
1460
1656
  className="hover:bg-muted rounded-lg p-2 transition-colors"
1461
1657
  title="Delete"
1462
1658
  aria-label="Delete"
@@ -1471,6 +1667,34 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
1471
1667
  </div>
1472
1668
  </div>
1473
1669
  )}
1670
+
1671
+ <ConfirmDialog
1672
+ open={pendingDelete !== null}
1673
+ onClose={() => setPendingDelete(null)}
1674
+ onConfirm={() => {
1675
+ if (pendingDelete) void deleteMedia(pendingDelete)
1676
+ }}
1677
+ returnFocusFallback={focusLibrary}
1678
+ title={
1679
+ pendingDelete?.length === 1
1680
+ ? 'Delete file?'
1681
+ : `Delete ${pendingDelete?.length ?? 0} files?`
1682
+ }
1683
+ description={
1684
+ pendingDelete?.length === 1
1685
+ ? 'This permanently deletes the file from storage. Pages that use it will show a broken image.'
1686
+ : 'This permanently deletes these files from storage. Pages that use them will show broken images.'
1687
+ }
1688
+ confirmLabel="Delete"
1689
+ destructive
1690
+ />
1691
+
1692
+ <MediaLightbox
1693
+ items={lightboxItems}
1694
+ activeId={lightboxId}
1695
+ onActiveChange={setLightboxId}
1696
+ onClose={() => setLightboxId(null)}
1697
+ />
1474
1698
  </div>
1475
1699
  )
1476
1700
  }