@prenta/admin 2.11.2 → 2.12.1

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 (66) hide show
  1. package/CHANGELOG.md +21 -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/__tests__/views/search-data-card.render.test.d.ts +2 -0
  15. package/dist/__tests__/views/search-data-card.render.test.d.ts.map +1 -0
  16. package/dist/__tests__/views/search-data-card.render.test.js +236 -0
  17. package/dist/__tests__/views/search-data-card.render.test.js.map +1 -0
  18. package/dist/__tests__/views/seo-settings.render.test.js +8 -4
  19. package/dist/__tests__/views/seo-settings.render.test.js.map +1 -1
  20. package/dist/components/MediaLightbox.d.ts +22 -0
  21. package/dist/components/MediaLightbox.d.ts.map +1 -0
  22. package/dist/components/MediaLightbox.js +38 -0
  23. package/dist/components/MediaLightbox.js.map +1 -0
  24. package/dist/components/ui/ConfirmDialog.d.ts +3 -1
  25. package/dist/components/ui/ConfirmDialog.d.ts.map +1 -1
  26. package/dist/components/ui/ConfirmDialog.js +2 -2
  27. package/dist/components/ui/ConfirmDialog.js.map +1 -1
  28. package/dist/components/ui/Modal.d.ts +7 -1
  29. package/dist/components/ui/Modal.d.ts.map +1 -1
  30. package/dist/components/ui/Modal.js +4 -2
  31. package/dist/components/ui/Modal.js.map +1 -1
  32. package/dist/lib/dialog-return-focus.d.ts +10 -0
  33. package/dist/lib/dialog-return-focus.d.ts.map +1 -0
  34. package/dist/lib/dialog-return-focus.js +26 -0
  35. package/dist/lib/dialog-return-focus.js.map +1 -0
  36. package/dist/lib/media-download.d.ts +8 -0
  37. package/dist/lib/media-download.d.ts.map +1 -0
  38. package/dist/lib/media-download.js +21 -0
  39. package/dist/lib/media-download.js.map +1 -0
  40. package/dist/prenta-admin.css +1 -1
  41. package/dist/views/MediaBrowser.d.ts +34 -0
  42. package/dist/views/MediaBrowser.d.ts.map +1 -1
  43. package/dist/views/MediaBrowser.js +190 -51
  44. package/dist/views/MediaBrowser.js.map +1 -1
  45. package/dist/views/MediaSeoAudit.d.ts +6 -0
  46. package/dist/views/MediaSeoAudit.d.ts.map +1 -1
  47. package/dist/views/MediaSeoAudit.js +12 -0
  48. package/dist/views/MediaSeoAudit.js.map +1 -1
  49. package/dist/views/settings/SearchDataCard.d.ts.map +1 -1
  50. package/dist/views/settings/SearchDataCard.js +162 -24
  51. package/dist/views/settings/SearchDataCard.js.map +1 -1
  52. package/package.json +5 -5
  53. package/src/__tests__/components/modal.render.test.tsx +52 -0
  54. package/src/__tests__/lib/media-download.test.ts +23 -0
  55. package/src/__tests__/views/media-browser.render.test.tsx +325 -0
  56. package/src/__tests__/views/media-grid.test.ts +13 -1
  57. package/src/__tests__/views/search-data-card.render.test.tsx +275 -0
  58. package/src/__tests__/views/seo-settings.render.test.tsx +15 -5
  59. package/src/components/MediaLightbox.tsx +127 -0
  60. package/src/components/ui/ConfirmDialog.tsx +4 -0
  61. package/src/components/ui/Modal.tsx +10 -0
  62. package/src/lib/dialog-return-focus.ts +33 -0
  63. package/src/lib/media-download.ts +18 -0
  64. package/src/views/MediaBrowser.tsx +367 -143
  65. package/src/views/MediaSeoAudit.tsx +11 -0
  66. package/src/views/settings/SearchDataCard.tsx +306 -45
@@ -1,3 +1,36 @@
1
+ interface MediaItem {
2
+ id: number | string;
3
+ name: string;
4
+ type: string;
5
+ size: string;
6
+ sizeBytes: number;
7
+ date: string;
8
+ url: string;
9
+ dimensions?: string;
10
+ format?: string;
11
+ altTag?: string;
12
+ /** WCAG decorative image — empty alt is intentional (#714). */
13
+ isDecorative?: boolean;
14
+ /** Pending AI alt suggestion (`aiAltText` column) awaiting editor approval. */
15
+ aiAltSuggestion?: string;
16
+ title?: string;
17
+ caption?: string;
18
+ description?: string;
19
+ focusKeyword?: string;
20
+ /** Derived server-side by cms-core's `calculateMediaSeoScore()`. */
21
+ seoScore?: number;
22
+ seoIssues?: Array<{
23
+ type: string;
24
+ }>;
25
+ usedOn?: {
26
+ page: string;
27
+ path: string;
28
+ }[];
29
+ }
30
+ /** Media.html `.type-pills` kinds, disjoint; `document` (Word, Excel, …) is repo-only. */
31
+ export type MediaKind = 'image' | 'video' | 'pdf' | 'svg' | 'document';
32
+ export type MediaTypeFilter = 'all' | MediaKind;
33
+ export declare function mediaKind(item: Pick<MediaItem, 'type' | 'name' | 'url'>): MediaKind;
1
34
  export interface MediaBrowserProps {
2
35
  onNavigate?: (path: string) => void;
3
36
  /** The signed-in user's role: "Run with AI…" shows to the roles that may queue jobs. */
@@ -12,4 +45,5 @@ export declare const MEDIA_GRID_ROW_HEIGHT: number;
12
45
  /** Columns that fit `auto-fill, minmax(220px, 1fr)` in the grid's content box. */
13
46
  export declare function mediaGridColumns(contentWidth: number): number;
14
47
  export declare function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBrowserProps): import("react/jsx-runtime").JSX.Element;
48
+ export {};
15
49
  //# sourceMappingURL=MediaBrowser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MediaBrowser.d.ts","sourceRoot":"","sources":["../../src/views/MediaBrowser.tsx"],"names":[],"mappings":"AAiHA,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,wFAAwF;IACxF,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;kFAC8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAQD,eAAO,MAAM,qBAAqB,QAAqC,CAAA;AAEvE,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAM7D;AAYD,wBAAgB,YAAY,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,iBAAiB,2CA4yCxF"}
1
+ {"version":3,"file":"MediaBrowser.d.ts","sourceRoot":"","sources":["../../src/views/MediaBrowser.tsx"],"names":[],"mappings":"AAoDA,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,+DAA+D;IAC/D,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,+EAA+E;IAC/E,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACnC,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC1C;AAaD,0FAA0F;AAC1F,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,UAAU,CAAA;AACtE,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,SAAS,CAAA;AAE/C,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,GAAG,SAAS,CAQnF;AAwED,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,wFAAwF;IACxF,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;kFAC8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAQD,eAAO,MAAM,qBAAqB,QAAqC,CAAA;AAIvE,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAM7D;AAYD,wBAAgB,YAAY,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,iBAAiB,2CA+8CxF"}
@@ -1,6 +1,6 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Upload, Grid3x3, List, Search, Trash2, Download, ArrowUpDown, ArrowUp, ArrowDown, X, Bot, Sparkles, Link2, AlertTriangle, Copy, ExternalLink, ImageIcon, FileImage, Loader2, FolderInput, GripVertical, } from 'lucide-react';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { Upload, Grid3x3, List, Search, Trash2, Download, Maximize2, ArrowUpDown, ArrowUp, ArrowDown, X, Bot, Sparkles, Link2, AlertTriangle, Copy, ExternalLink, ImageIcon, FileImage, Loader2, FolderInput, GripVertical, } from 'lucide-react';
4
4
  import { useState, useMemo, useRef, useCallback, useEffect } from 'react';
5
5
  import { toast } from 'sonner';
6
6
  import { parseRouteQuery } from '../router/index.js';
@@ -10,11 +10,15 @@ import { cmsApi } from '../lib/api.js';
10
10
  import { useVirtualWindow, VirtualTablePadding } from '../components/virtual-window.js';
11
11
  import { FolderTree } from '../components/FolderTree.js';
12
12
  import { Button } from '../components/ui/Button.js';
13
+ import { ConfirmDialog } from '../components/ui/ConfirmDialog.js';
14
+ import { MediaLightbox } from '../components/MediaLightbox.js';
15
+ import { mediaDownloadUrl } from '../lib/media-download.js';
13
16
  import { TIER_MEDIA } from '../lib/tiers.js';
14
17
  import { useSheetFocus } from '../lib/sheet-focus.js';
15
18
  import { StatusBadge } from '../components/ui/StatusBadge.js';
16
19
  import { CountChip } from '../components/ui/CountChip.js';
17
- import { hasLowQualityAlt, MediaSeoAudit } from './MediaSeoAudit.js';
20
+ import { FilterPill } from '../components/ui/FilterPill.js';
21
+ import { hasLowQualityAlt, MediaSeoAudit, scoreBadgeClass, } from './MediaSeoAudit.js';
18
22
  import { pickedImages } from '../lib/batch-wizard.js';
19
23
  import { RunWithAi } from './Jobs/RunWithAi.js';
20
24
  function hasAccessibleAlt(item) {
@@ -24,17 +28,29 @@ function isImageMedia(item) {
24
28
  return (Boolean(item.url) &&
25
29
  (item.type?.startsWith('image/') || /\.(avif|gif|jpe?g|png|webp|svg)$/i.test(item.url)));
26
30
  }
27
- function matchesMediaType(item, filterType) {
28
- if (filterType === 'all')
29
- return true;
30
- if (filterType === 'image')
31
- return item.type?.startsWith('image/') || isImageMedia(item);
32
- if (filterType === 'video')
33
- return item.type?.startsWith('video/');
34
- if (filterType === 'document')
35
- return !item.type?.startsWith('image/') && !item.type?.startsWith('video/');
36
- return item.type === filterType;
31
+ export function mediaKind(item) {
32
+ const file = `${item.name ?? ''} ${item.url ?? ''}`;
33
+ if (item.type === 'image/svg+xml' || /\.svg(\s|$|\?)/i.test(file))
34
+ return 'svg';
35
+ if (item.type?.startsWith('image/') || /\.(avif|gif|jpe?g|png|webp)(\s|$|\?)/i.test(file))
36
+ return 'image';
37
+ if (item.type?.startsWith('video/'))
38
+ return 'video';
39
+ if (item.type === 'application/pdf' || /\.pdf(\s|$|\?)/i.test(file))
40
+ return 'pdf';
41
+ return 'document';
37
42
  }
43
+ function matchesMediaType(item, filter) {
44
+ return filter === 'all' || mediaKind(item) === filter;
45
+ }
46
+ const TYPE_PILLS = [
47
+ { value: 'all', label: 'All' },
48
+ { value: 'image', label: 'Images' },
49
+ { value: 'video', label: 'Video' },
50
+ { value: 'pdf', label: 'PDF' },
51
+ { value: 'svg', label: 'SVG' },
52
+ { value: 'document', label: 'Documents' },
53
+ ];
38
54
  function formatStorage(bytes) {
39
55
  if (bytes <= 0)
40
56
  return '0 B';
@@ -43,12 +59,43 @@ function formatStorage(bytes) {
43
59
  const value = bytes / 1024 ** i;
44
60
  return `${value >= 100 || i === 0 ? Math.round(value) : value.toFixed(1)} ${units[i]}`;
45
61
  }
46
- function MediaPreview({ item }) {
62
+ function mediaAlt(item) {
63
+ return item.altTag || item.title || item.name || 'Media preview';
64
+ }
65
+ function MediaPreview({ item, fit = 'cover' }) {
47
66
  if (isImageMedia(item)) {
48
- return (_jsx("img", { src: item.url, alt: item.altTag || item.title || item.name || 'Media preview', className: "h-full w-full object-cover", loading: "lazy" }));
67
+ return (_jsx("img", { src: item.url, alt: mediaAlt(item), className: `h-full w-full ${fit === 'contain' ? 'object-contain' : 'object-cover'}`, loading: "lazy" }));
49
68
  }
50
69
  return _jsx(FileImage, { className: "text-muted-foreground h-6 w-6 sm:h-8 sm:w-8" });
51
70
  }
71
+ /** The sort select's presets (Media.html `.sort-sel`); list-column sorts that match none read "custom". */
72
+ function sortPresetOf(sort) {
73
+ if (!sort)
74
+ return 'date';
75
+ if (sort.key === 'name' && sort.direction === 'asc')
76
+ return 'name';
77
+ if (sort.key === 'score' && sort.direction === 'desc')
78
+ return 'score';
79
+ if (sort.key === 'size' && sort.direction === 'desc')
80
+ return 'size';
81
+ return 'custom';
82
+ }
83
+ function sortForPreset(preset) {
84
+ switch (preset) {
85
+ case 'date':
86
+ return null;
87
+ case 'name':
88
+ return { key: 'name', direction: 'asc' };
89
+ case 'score':
90
+ return { key: 'score', direction: 'desc' };
91
+ case 'size':
92
+ return { key: 'size', direction: 'desc' };
93
+ default: {
94
+ const unreachable = preset;
95
+ return unreachable;
96
+ }
97
+ }
98
+ }
52
99
  // Media.html `.media-grid` / `.media-thumb`. Grid rows are virtualised at a
53
100
  // fixed stride, so card height must not depend on card width.
54
101
  const MEDIA_CARD_MIN_WIDTH = 220;
@@ -56,6 +103,8 @@ const MEDIA_GRID_GAP = 14;
56
103
  const MEDIA_GRID_PADDING_X = 28;
57
104
  const MEDIA_CARD_HEIGHT = 172;
58
105
  export const MEDIA_GRID_ROW_HEIGHT = MEDIA_CARD_HEIGHT + MEDIA_GRID_GAP;
106
+ /** `POST /media/bulk-delete` accepts at most this many ids (`BULK_MEDIA_MAX_ITEMS`). */
107
+ const BULK_DELETE_CHUNK = 50;
59
108
  /** Columns that fit `auto-fill, minmax(220px, 1fr)` in the grid's content box. */
60
109
  export function mediaGridColumns(contentWidth) {
61
110
  if (contentWidth <= 0)
@@ -94,6 +143,8 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
94
143
  const [selectedMedia, setSelectedMedia] = useState([]);
95
144
  const [sortConfig, setSortConfig] = useState(null);
96
145
  const [activeItem, setActiveItem] = useState(null);
146
+ const [pendingDelete, setPendingDelete] = useState(null);
147
+ const [lightboxId, setLightboxId] = useState(null);
97
148
  const [editAlt, setEditAlt] = useState('');
98
149
  const [editIsDecorative, setEditIsDecorative] = useState(false);
99
150
  const [editTitle, setEditTitle] = useState('');
@@ -121,6 +172,9 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
121
172
  if (sortConfig.key === 'size') {
122
173
  cmp = a.sizeBytes - b.sizeBytes;
123
174
  }
175
+ else if (sortConfig.key === 'score') {
176
+ cmp = (a.seoScore ?? 0) - (b.seoScore ?? 0);
177
+ }
124
178
  else {
125
179
  cmp = String(a[sortConfig.key]).localeCompare(String(b[sortConfig.key]));
126
180
  }
@@ -129,6 +183,43 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
129
183
  }
130
184
  return results;
131
185
  }, [mediaItems, searchQuery, filterType, sortConfig]);
186
+ const typeCounts = useMemo(() => {
187
+ const counts = {
188
+ all: mediaItems.length,
189
+ image: 0,
190
+ video: 0,
191
+ pdf: 0,
192
+ svg: 0,
193
+ document: 0,
194
+ };
195
+ for (const item of mediaItems)
196
+ counts[mediaKind(item)]++;
197
+ return counts;
198
+ }, [mediaItems]);
199
+ // The viewer steps through the images on screen. If search or a type pill
200
+ // has hidden the open panel's image, it shows that image alone rather than
201
+ // doing nothing.
202
+ const lightboxItems = useMemo(() => {
203
+ const toViewerItem = (item) => ({
204
+ id: item.id,
205
+ url: item.url,
206
+ name: item.name,
207
+ alt: mediaAlt(item),
208
+ dimensions: item.dimensions,
209
+ });
210
+ const onScreen = filteredAndSorted.filter(isImageMedia).map(toViewerItem);
211
+ if (activeItem &&
212
+ isImageMedia(activeItem) &&
213
+ !onScreen.some((item) => item.id === activeItem.id)) {
214
+ return [toViewerItem(activeItem)];
215
+ }
216
+ return onScreen;
217
+ }, [filteredAndSorted, activeItem]);
218
+ useEffect(() => {
219
+ if (lightboxId !== null && !lightboxItems.some((item) => item.id === lightboxId)) {
220
+ setLightboxId(null);
221
+ }
222
+ }, [lightboxId, lightboxItems]);
132
223
  const gridScrollRef = useRef(null);
133
224
  const [gridWidth, setGridWidth] = useState(0);
134
225
  const gridMounted = viewMode === 'grid' && activeTab === 'library' && filteredAndSorted.length > 0;
@@ -146,6 +237,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
146
237
  }, [gridMounted, loading]);
147
238
  const gridColumns = mediaGridColumns(gridWidth);
148
239
  const listScrollRef = useRef(null);
240
+ const focusLibrary = useCallback(() => gridScrollRef.current ?? listScrollRef.current, []);
149
241
  /** The grid's or list's scroll position when a card opened the detail panel. */
150
242
  const savedListScroll = useRef(0);
151
243
  const gridRowCount = gridColumns > 0 ? Math.ceil(filteredAndSorted.length / gridColumns) : 0;
@@ -256,17 +348,48 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
256
348
  refetch();
257
349
  }
258
350
  };
259
- const deleteMedia = async (id) => {
260
- const res = await cmsApi(`/media/${id}`, { method: 'DELETE' });
261
- if (res.error) {
262
- toast.error(res.error);
351
+ const deleteMedia = async (ids) => {
352
+ let deleted = [];
353
+ let failed = 0;
354
+ if (ids.length === 1) {
355
+ const res = await cmsApi(`/media/${ids[0]}`, { method: 'DELETE' });
356
+ if (res.error) {
357
+ toast.error(res.error);
358
+ return;
359
+ }
360
+ deleted = ids;
263
361
  }
264
362
  else {
265
- toast.success('Media deleted');
266
- if (activeItem?.id === id)
267
- closeDetail();
268
- refetch();
363
+ for (let i = 0; i < ids.length; i += BULK_DELETE_CHUNK) {
364
+ const chunk = ids.slice(i, i + BULK_DELETE_CHUNK);
365
+ const res = await cmsApi('/media/bulk-delete', { method: 'POST', body: JSON.stringify({ ids: chunk.map(String), confirm: true }) });
366
+ if (res.error || !res.data) {
367
+ failed += chunk.length;
368
+ continue;
369
+ }
370
+ const ok = new Set(res.data.results.filter((r) => r.ok).map((r) => r.id));
371
+ deleted.push(...chunk.filter((id) => ok.has(String(id))));
372
+ failed += chunk.length - ok.size;
373
+ }
374
+ }
375
+ if (deleted.length > 0) {
376
+ toast.success(deleted.length === 1 ? 'Media deleted' : `${deleted.length} files deleted`);
269
377
  }
378
+ if (failed > 0)
379
+ toast.error(`${failed} file${failed === 1 ? '' : 's'} couldn't be deleted`);
380
+ const gone = new Set(deleted.map(String));
381
+ if (activeItem && gone.has(String(activeItem.id))) {
382
+ closeDetail();
383
+ // The confirm dialog returned focus to the panel's Delete, which this removes.
384
+ requestAnimationFrame(() => {
385
+ const focused = document.activeElement;
386
+ if (!focused || focused === document.body || !focused.isConnected)
387
+ focusLibrary()?.focus();
388
+ });
389
+ }
390
+ setSelectedMedia((prev) => prev.filter((id) => !gone.has(String(id))));
391
+ if (deleted.length > 0)
392
+ refetch();
270
393
  };
271
394
  const handleAiGenerate = async (field) => {
272
395
  setAiGenerating(field);
@@ -300,7 +423,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
300
423
  .replace(/[-_]/g, ' ')
301
424
  .trim();
302
425
  if (field === 'alt') {
303
- setEditAlt(base ? `Image of ${base}` : '');
426
+ setEditAlt(base);
304
427
  }
305
428
  else {
306
429
  setEditTitle(base.replace(/\b\w/g, (c) => c.toUpperCase()));
@@ -407,8 +530,8 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
407
530
  // header), so the card that opened it leaves the screen. Focus moves into
408
531
  // the panel and back when it closes. The hidden scroll box comes back at the
409
532
  // top, and the virtualised window wouldn't follow (no scroll event), so its
410
- // position, saved when a card opens the panel, goes back first. Grid cards
411
- // aren't focusable, so focus lands on the list itself.
533
+ // position, saved when a card opens the panel, goes back first. If the
534
+ // opener is gone (virtualised out), focus lands on the list itself.
412
535
  useSheetFocus(panelOpen, detailPanelRef, {
413
536
  restore: () => {
414
537
  const scroller = gridScrollRef.current ?? listScrollRef.current;
@@ -442,20 +565,27 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
442
565
  : 'bg-[var(--err-l)] text-[var(--err)]'}`, "aria-label": `${auditAttentionCount} items need attention`, children: auditAttentionCount })] })] }), activeTab === 'audit' ? (_jsx(MediaSeoAudit, { items: mediaItems, onEdit: handleAuditEdit, error: error, onRetry: refetch })) : (_jsxs("div", { className: "mobile:flex-col flex min-h-0 flex-1 gap-4 overflow-hidden", children: [sidebarOpen && (_jsx("div", { className: "border-border bg-card mobile:max-h-[40vh] mobile:w-full flex w-56 shrink-0 flex-col overflow-hidden rounded-lg border", children: _jsx(FolderTree, { scope: "media", selected: folderSel, onSelect: (sel) => {
443
566
  setFolderSel(sel);
444
567
  setSelectedMedia([]);
445
- }, totalCount: allData.data?.total, uncategorizedCount: uncatData.data?.total, onDropItem: handleDropItem }) })), _jsxs("div", { className: "mobile:min-h-0 flex min-w-0 flex-1 flex-col", children: [_jsx("div", { className: "border-border bg-card mb-4 rounded-lg border", children: _jsxs("div", { className: "flex items-center justify-between p-3", children: [_jsxs("div", { className: "flex flex-1 items-center gap-3", children: [_jsxs("div", { className: "relative max-w-md flex-1", children: [_jsx(Search, { className: "text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2", "aria-hidden": true }), _jsx("input", { type: "search", placeholder: "Search media...", "aria-label": "Search media", value: searchQuery, onChange: (e) => setSearchQuery(e.target.value), 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" })] }), _jsxs("select", { value: filterType, onChange: (e) => setFilterType(e.target.value), "aria-label": "Filter by type", className: "border-input focus:ring-ring rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none", children: [_jsx("option", { value: "all", children: "All Types" }), _jsx("option", { value: "image", children: "Images" }), _jsx("option", { value: "video", children: "Videos" }), _jsx("option", { value: "document", children: "Documents" })] })] }), _jsxs("div", { className: "bg-muted flex items-center gap-1 rounded-lg p-1", role: "group", "aria-label": "Media view", children: [_jsx("button", { type: "button", onClick: () => setViewMode('grid'), "aria-label": "Grid view", "aria-pressed": viewMode === 'grid', className: `rounded p-1.5 transition-colors ${viewMode === 'grid' ? 'bg-card text-foreground shadow-sm' : 'text-muted-foreground hover:text-foreground'}`, children: _jsx(Grid3x3, { className: "h-4 w-4", "aria-hidden": true }) }), _jsx("button", { type: "button", onClick: () => setViewMode('list'), "aria-label": "List view", "aria-pressed": viewMode === 'list', className: `rounded p-1.5 transition-colors ${viewMode === 'list' ? 'bg-card text-foreground shadow-sm' : 'text-muted-foreground hover:text-foreground'}`, children: _jsx(List, { className: "h-4 w-4", "aria-hidden": true }) })] })] }) }), selectedMedia.length > 0 && (_jsx("div", { className: "border-primary/30 bg-primary/10 mb-4 rounded-lg border p-4", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("span", { className: "text-primary text-sm", children: [selectedMedia.length, " file", selectedMedia.length !== 1 ? 's' : '', " selected"] }), _jsxs("div", { className: "flex items-center gap-2", children: [onNavigate ? (_jsx(RunWithAi, { pick: pickedImages(mediaItems
568
+ }, totalCount: allData.data?.total, uncategorizedCount: uncatData.data?.total, onDropItem: handleDropItem }) })), _jsxs("div", { className: "mobile:min-h-0 flex min-w-0 flex-1 flex-col", children: [_jsx("div", { className: "border-border bg-card mb-4 rounded-lg border", children: _jsxs("div", { className: "flex flex-wrap items-center gap-2 px-3 py-3", children: [_jsxs("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)]", children: [_jsx(Search, { size: 13, "aria-hidden": true }), _jsx("input", { type: "search", placeholder: "Search files\u2026", "aria-label": "Search files", value: searchQuery, onChange: (e) => setSearchQuery(e.target.value), className: "w-full bg-transparent text-[13px] text-[var(--txt)] outline-none placeholder:text-[var(--muted)]" }), searchQuery && (_jsx("button", { type: "button", onClick: () => setSearchQuery(''), "aria-label": "Clear search", className: "shrink-0 leading-none text-[var(--muted)] hover:text-[var(--txt)]", children: _jsx(X, { size: 12, "aria-hidden": true }) }))] }), _jsx("div", { className: "flex flex-wrap gap-[3px]", role: "group", "aria-label": "Filter by type", children: TYPE_PILLS.filter((pill) => pill.value !== 'document' ||
569
+ typeCounts.document > 0 ||
570
+ filterType === 'document').map((pill) => (_jsx(FilterPill, { active: filterType === pill.value, count: typeCounts[pill.value], onClick: () => setFilterType(pill.value), children: pill.label }, pill.value))) }), _jsxs("select", { "aria-label": "Sort media", value: sortPresetOf(sortConfig), onChange: (e) => {
571
+ const preset = e.target.value;
572
+ if (preset === 'custom')
573
+ return;
574
+ setSortConfig(sortForPreset(preset));
575
+ }, 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", children: [_jsx("option", { value: "date", children: "Recent first" }), _jsx("option", { value: "name", children: "Name A\u2013Z" }), _jsx("option", { value: "score", children: "SEO score" }), _jsx("option", { value: "size", children: "File size" }), sortPresetOf(sortConfig) === 'custom' && (_jsx("option", { value: "custom", disabled: true, children: "List column" }))] }), _jsx("div", { className: "flex overflow-hidden rounded-[7px] border border-[var(--bdr)]", role: "group", "aria-label": "Media view", children: [
576
+ ['grid', 'Grid view', Grid3x3],
577
+ ['list', 'List view', List],
578
+ ].map(([mode, label, Icon]) => (_jsx("button", { type: "button", onClick: () => setViewMode(mode), "aria-label": label, "aria-pressed": viewMode === mode, 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 ${viewMode === mode
579
+ ? 'bg-[var(--acc-l)] text-[var(--acc)]'
580
+ : 'text-[var(--muted)] hover:bg-[var(--bg)] hover:text-[var(--sub)]'}`, children: _jsx(Icon, { size: 14, "aria-hidden": true }) }, mode))) }), _jsxs("span", { className: "ml-auto shrink-0 text-[12px] whitespace-nowrap text-[var(--muted)]", "aria-live": "polite", children: [filteredAndSorted.length, " file", filteredAndSorted.length === 1 ? '' : 's'] })] }) }), selectedMedia.length > 0 && (_jsx("div", { className: "border-primary/30 bg-primary/10 mb-4 rounded-lg border p-4", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("span", { className: "text-primary text-sm", children: [selectedMedia.length, " file", selectedMedia.length !== 1 ? 's' : '', " selected"] }), _jsxs("div", { className: "flex items-center gap-2", children: [onNavigate ? (_jsx(RunWithAi, { pick: pickedImages(mediaItems
446
581
  .filter((item) => selectedMedia.includes(item.id) && isImageMedia(item))
447
- .map((item) => String(item.id))), role: role, config: config, onNavigate: onNavigate, className: "border-input bg-card hover:bg-muted rounded-lg border px-3 py-1.5 text-sm transition-colors" })) : null, _jsx("button", { onClick: async () => {
448
- for (const id of selectedMedia)
449
- await deleteMedia(id);
450
- setSelectedMedia([]);
451
- }, className: "bg-destructive text-destructive-foreground hover:bg-destructive/90 rounded-lg px-3 py-1.5 text-sm transition-colors", children: "Delete Selected" }), _jsx("button", { onClick: () => setSelectedMedia([]), className: "border-input bg-card hover:bg-muted rounded-lg border px-3 py-1.5 text-sm transition-colors", children: "Cancel" })] })] }) })), filteredAndSorted.length === 0 && !loading ? (_jsxs("div", { className: "flex flex-col items-center justify-center py-16 text-center", children: [_jsx("div", { className: "bg-muted mb-4 flex h-12 w-12 items-center justify-center rounded-full", children: _jsx(ImageIcon, { className: "text-muted-foreground h-6 w-6" }) }), _jsx("h3", { className: "text-foreground mb-1 text-sm font-medium", children: folderSel.type === 'smart' && folderSel.smart === 'uncategorized'
582
+ .map((item) => String(item.id))), role: role, config: config, onNavigate: onNavigate, className: "border-input bg-card hover:bg-muted rounded-lg border px-3 py-1.5 text-sm transition-colors" })) : null, _jsx("button", { onClick: () => setPendingDelete(selectedMedia), className: "bg-destructive text-destructive-foreground hover:bg-destructive/90 rounded-lg px-3 py-1.5 text-sm transition-colors", children: "Delete Selected" }), _jsx("button", { onClick: () => setSelectedMedia([]), className: "border-input bg-card hover:bg-muted rounded-lg border px-3 py-1.5 text-sm transition-colors", children: "Cancel" })] })] }) })), filteredAndSorted.length === 0 && !loading ? (_jsxs("div", { className: "flex flex-col items-center justify-center py-16 text-center", children: [_jsx("div", { className: "bg-muted mb-4 flex h-12 w-12 items-center justify-center rounded-full", children: _jsx(ImageIcon, { className: "text-muted-foreground h-6 w-6" }) }), _jsx("h3", { className: "text-foreground mb-1 text-sm font-medium", children: folderSel.type === 'smart' && folderSel.smart === 'uncategorized'
452
583
  ? 'No uncategorized media'
453
584
  : folderSel.type === 'folder'
454
585
  ? 'No media in this folder'
455
586
  : 'No media yet' }), _jsx("p", { className: "text-muted-foreground text-sm", children: "Upload your first file to get started." })] })) : (_jsxs("div", { className: "flex min-h-0 flex-1 gap-4 overflow-hidden", children: [_jsx("div", { className: `border-border bg-card overflow-hidden rounded-lg border transition-all duration-200 ${panelOpen ? 'min-w-0 flex-1' : 'w-full'}`, children: viewMode === 'grid' ? (_jsx("div", { ref: gridScrollRef,
456
- // The grid's cards aren't focusable yet, so the scroller
457
- // itself takes Tab and arrow-key scrolling (Media.html
458
- // `.mc-grid-area`; axe scrollable-region-focusable).
587
+ // Media.html `.mc-grid-area`: the scroller takes arrow-key
588
+ // scrolling (axe scrollable-region-focusable).
459
589
  tabIndex: 0, role: "region", "aria-label": "Media library", className: "h-full overflow-y-auto px-[28px] py-[20px]", children: _jsx("div", { className: "relative", style: { height: gridRowCount * MEDIA_GRID_ROW_HEIGHT }, children: gridWindow.rows.map((virtualRow) => (_jsx("div", { className: "grid gap-[14px]", style: {
460
590
  position: 'absolute',
461
591
  top: 0,
@@ -467,21 +597,23 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
467
597
  .slice(virtualRow.index * gridColumns, virtualRow.index * gridColumns + gridColumns)
468
598
  .map((item) => {
469
599
  const isActive = activeItem?.id === item.id;
470
- const hasIssues = !hasAccessibleAlt(item) ||
471
- !item.title ||
472
- item.usedOn?.length === 0;
473
- const typeLabel = (item.name.includes('.')
474
- ? item.name.split('.').pop()
475
- : item.format || item.type || '')
476
- .replace(/^.*\//, '')
477
- .toUpperCase();
478
- return (_jsxs("div", { "data-media-card": "", className: `group relative flex h-[172px] cursor-pointer flex-col overflow-hidden rounded-lg border-2 transition-all ${isActive
479
- ? 'border-primary ring-primary/30 ring-2'
480
- : selectedMedia.includes(item.id)
481
- ? 'border-primary/60 ring-primary/20 ring-1'
482
- : 'border-border hover:border-input'}`, onClick: () => openDetail(item), draggable: true, onDragStart: (e) => handleDragStart(e, item.id), children: [_jsxs("div", { className: "relative h-[118px] w-full shrink-0 overflow-hidden", children: [_jsx("div", { className: "bg-muted flex h-full w-full items-center justify-center", children: _jsx(MediaPreview, { item: item }) }), hasIssues && (_jsx("div", { className: "bg-warning absolute top-1.5 left-1.5 flex h-5 w-5 items-center justify-center rounded-full", title: "Needs attention", children: _jsx(AlertTriangle, { className: "text-warning-foreground h-3 w-3" }) })), _jsx("div", { className: "absolute top-1.5 right-1.5 opacity-0 transition-opacity group-hover:opacity-100", onClick: (e) => handleCheckbox(e, item.id), children: _jsx("div", { className: `flex h-5 w-5 items-center justify-center rounded border-2 transition-colors ${selectedMedia.includes(item.id)
600
+ const isSelected = selectedMedia.includes(item.id);
601
+ // Media.html `hasMissing`: the card's "SEO" tag.
602
+ const missingSeo = !hasAccessibleAlt(item) || !item.title?.trim();
603
+ const score = item.seoScore;
604
+ return (_jsxs("div", { "data-media-card": "", 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)] ${isActive || isSelected
605
+ ? 'border-[var(--acc)] shadow-[0_0_0_2px_var(--acc-m)]'
606
+ : 'border-[var(--bdr)] hover:border-[var(--acc-m)] hover:shadow-[var(--shd2)]'}`, draggable: true, onDragStart: (e) => handleDragStart(e, item.id), children: [_jsx("button", { type: "button", onClick: () => openDetail(item), "aria-label": [
607
+ `Open ${item.name}`,
608
+ score !== undefined ? `SEO score ${score}` : '',
609
+ missingSeo ? 'missing SEO' : '',
610
+ ]
611
+ .filter(Boolean)
612
+ .join(', '), "aria-current": isActive ? 'true' : undefined, className: "absolute inset-0 z-[1] cursor-pointer focus:outline-none" }), _jsxs("div", { className: "relative h-[118px] w-full shrink-0 overflow-hidden", children: [_jsx("div", { className: "bg-muted flex h-full w-full items-center justify-center", children: _jsx(MediaPreview, { item: item }) }), score !== undefined && (_jsx("span", { "aria-hidden": true, 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)}`, children: score })), _jsx("span", { "aria-hidden": true, 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]", children: mediaKind(item) }), _jsx("button", { type: "button", role: "checkbox", "aria-checked": isSelected, "aria-label": `Select ${item.name}`, 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 ${isSelected || selectedMedia.length > 0
613
+ ? 'opacity-100'
614
+ : 'opacity-0'}`, onClick: (e) => handleCheckbox(e, item.id), children: _jsx("span", { className: `flex h-5 w-5 items-center justify-center rounded border-2 transition-colors ${isSelected
483
615
  ? 'border-primary bg-primary'
484
- : 'border-input bg-card/80'}`, children: selectedMedia.includes(item.id) && (_jsx("svg", { className: "text-primary-foreground h-3 w-3", fill: "none", viewBox: "0 0 12 12", children: _jsx("path", { d: "M10 3L4.5 8.5L2 6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })) }) })] }), _jsxs("div", { className: "border-border bg-card flex min-h-0 flex-1 items-center gap-2 border-t px-2 py-1.5", children: [_jsx("span", { className: `mt-0.5 h-2 w-2 shrink-0 self-start rounded-full ${hasIssues ? 'bg-warning' : 'bg-success'}`, title: hasIssues ? 'Needs attention' : 'SEO complete' }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("p", { className: "text-foreground truncate text-xs font-medium", children: item.name }), _jsx("p", { className: "text-muted-foreground truncate text-xs", children: [typeLabel, item.size].filter(Boolean).join(' · ') })] })] })] }, item.id));
616
+ : 'border-input bg-card/80'}`, children: isSelected && (_jsx("svg", { className: "text-primary-foreground h-3 w-3", fill: "none", viewBox: "0 0 12 12", children: _jsx("path", { d: "M10 3L4.5 8.5L2 6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })) }) })] }), _jsxs("div", { className: "min-h-0 flex-1 px-[10px] pt-[8px] pb-[10px]", children: [_jsx("p", { className: "truncate text-[12px] font-medium text-[var(--txt)]", children: item.name }), _jsxs("div", { className: "mt-[3px] flex items-center gap-[5px]", children: [_jsx("span", { className: "text-[11px] text-[var(--muted)]", children: item.size }), missingSeo && (_jsxs("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)]", children: [_jsx(AlertTriangle, { size: 9, "aria-hidden": true }), "SEO"] }))] })] })] }, item.id));
485
617
  }) }, virtualRow.key))) }) })) : (_jsx("div", { ref: listScrollRef, tabIndex: -1, className: "h-full overflow-auto outline-none", children: _jsxs("table", { className: "w-full min-w-[640px]", children: [_jsx("thead", { className: "border-border bg-muted sticky top-0 border-b", children: _jsxs("tr", { children: [_jsx("th", { className: "w-8 px-3 py-2 text-left", children: _jsx("input", { type: "checkbox", checked: selectedMedia.length === filteredAndSorted.length &&
486
618
  filteredAndSorted.length > 0, onChange: handleSelectAll, className: "border-input rounded" }) }), _jsx("th", { className: "w-6 px-1 py-2" }), _jsx("th", { className: "px-3 py-2 text-left", "aria-sort": ariaSortFor('name'), children: _jsx(SortHeader, { label: "Name", sortKey: "name" }) }), _jsx("th", { className: "px-3 py-2 text-left", "aria-sort": ariaSortFor('type'), children: _jsx(SortHeader, { label: "Type", sortKey: "type" }) }), _jsx("th", { className: "px-3 py-2 text-left", "aria-sort": ariaSortFor('size'), children: _jsx(SortHeader, { label: "Size", sortKey: "size" }) }), _jsx("th", { className: "px-3 py-2 text-left", "aria-sort": ariaSortFor('date'), children: _jsx(SortHeader, { label: "Uploaded", sortKey: "date" }) }), _jsx("th", { className: "text-foreground px-3 py-2 text-left text-xs font-medium", children: "Status" })] }) }), _jsxs("tbody", { className: "divide-border divide-y", children: [_jsx(VirtualTablePadding, { height: listWindow.paddingTop, columns: 7 }), listWindow.rows.map((row) => {
487
619
  const item = filteredAndSorted[row.index];
@@ -490,7 +622,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
490
622
  const isActive = activeItem?.id === item.id;
491
623
  const hasIssues = !hasAccessibleAlt(item) || !item.title || item.usedOn?.length === 0;
492
624
  return (_jsxs("tr", { className: `cursor-pointer transition-colors ${isActive ? 'bg-primary/10' : 'hover:bg-muted'}`, onClick: () => openDetail(item), draggable: true, onDragStart: (e) => handleDragStart(e, item.id), children: [_jsx("td", { className: "px-3 py-2", onClick: (e) => e.stopPropagation(), children: _jsx("input", { type: "checkbox", checked: selectedMedia.includes(item.id), onChange: () => handleCheckbox({ stopPropagation: () => { } }, item.id), className: "border-input rounded" }) }), _jsx("td", { className: "cursor-grab px-1 py-2", children: _jsx(GripVertical, { className: "text-muted-foreground h-4 w-4" }) }), _jsx("td", { className: "px-3 py-2", children: _jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "bg-muted flex h-10 w-10 items-center justify-center overflow-hidden rounded", children: _jsx(MediaPreview, { item: item }) }), _jsx("span", { className: "text-foreground text-sm font-medium", children: item.name })] }) }), _jsx("td", { className: "text-muted-foreground px-3 py-2 text-sm", children: item.format ?? item.type }), _jsx("td", { className: "text-muted-foreground px-3 py-2 text-sm", children: item.size }), _jsx("td", { className: "text-muted-foreground px-3 py-2 text-sm", children: item.date }), _jsx("td", { className: "px-3 py-2", children: hasIssues ? (_jsx(StatusBadge, { tone: "warning", children: "Needs attention" })) : (_jsx(StatusBadge, { tone: "success", children: "Complete" })) })] }, item.id));
493
- }), _jsx(VirtualTablePadding, { height: listWindow.paddingBottom, columns: 7 })] })] }) })) }), panelOpen && activeItem && (_jsxs("div", { ref: detailPanelRef, "data-inspector-open": "", tabIndex: -1, role: "region", "aria-label": `${activeItem.name} details`, className: "border-border bg-card mobile:w-full flex w-80 shrink-0 flex-col overflow-y-auto rounded-lg border lg:w-96", children: [_jsxs("div", { className: "border-border bg-card sticky top-0 z-10 flex items-center justify-between border-b p-4", children: [_jsx("h3", { className: "text-foreground truncate text-sm font-medium", children: activeItem.name }), _jsx("button", { type: "button", onClick: closeDetail, className: "hover:bg-muted prenta-touch-target mobile:-my-2.5 mobile:-mr-2.5 mobile:h-11 mobile:w-11 flex items-center justify-center rounded p-1 transition-colors", "aria-label": "Close panel", children: _jsx(X, { className: "text-muted-foreground h-4 w-4", "aria-hidden": true }) })] }), _jsxs("div", { className: "flex-1 overflow-y-auto", children: [_jsx("div", { className: "border-border border-b p-4", children: _jsx("div", { className: "bg-muted flex aspect-video items-center justify-center overflow-hidden rounded-lg", children: isImageMedia(activeItem) ? (_jsx(MediaPreview, { item: activeItem })) : (_jsx(ImageIcon, { className: "text-muted-foreground h-12 w-12" })) }) }), issues.length > 0 && (_jsxs("div", { className: "border-warning/30 bg-warn-l mx-4 mt-4 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-start gap-2", children: [_jsx(AlertTriangle, { className: "text-warning mt-0.5 h-4 w-4 shrink-0" }), _jsxs("div", { children: [_jsxs("p", { className: "text-warning mb-1 text-xs font-medium", children: [issues.length, " issue", issues.length !== 1 ? 's' : '', " found"] }), _jsx("ul", { className: "space-y-0.5", children: issues.map((issue, i) => (_jsxs("li", { className: "text-warning text-xs", children: ["\u2022 ", issue] }, i))) })] })] }), _jsxs("button", { type: "button", onClick: async () => {
625
+ }), _jsx(VirtualTablePadding, { height: listWindow.paddingBottom, columns: 7 })] })] }) })) }), panelOpen && activeItem && (_jsxs("div", { ref: detailPanelRef, "data-inspector-open": "", tabIndex: -1, role: "region", "aria-label": `${activeItem.name} details`, className: "border-border bg-card mobile:w-full flex w-80 shrink-0 flex-col overflow-y-auto rounded-lg border lg:w-96", children: [_jsxs("div", { className: "border-border bg-card sticky top-0 z-10 flex items-center justify-between border-b p-4", children: [_jsx("h3", { className: "text-foreground truncate text-sm font-medium", children: activeItem.name }), _jsx("button", { type: "button", onClick: closeDetail, className: "hover:bg-muted prenta-touch-target mobile:-my-2.5 mobile:-mr-2.5 mobile:h-11 mobile:w-11 flex items-center justify-center rounded p-1 transition-colors", "aria-label": "Close panel", children: _jsx(X, { className: "text-muted-foreground h-4 w-4", "aria-hidden": true }) })] }), _jsxs("div", { className: "flex-1 overflow-y-auto", children: [_jsx("div", { className: "border-border border-b p-4", children: _jsx("div", { className: "bg-muted relative flex aspect-video items-center justify-center overflow-hidden rounded-lg", children: isImageMedia(activeItem) ? (_jsxs(_Fragment, { children: [_jsx(MediaPreview, { item: activeItem, fit: "contain" }), _jsx("button", { type: "button", onClick: () => setLightboxId(activeItem.id), "aria-label": "View full size", title: "View full size", 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", children: _jsx(Maximize2, { size: 14, "aria-hidden": true }) })] })) : (_jsx(ImageIcon, { className: "text-muted-foreground h-12 w-12" })) }) }), issues.length > 0 && (_jsxs("div", { className: "border-warning/30 bg-warn-l mx-4 mt-4 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-start gap-2", children: [_jsx(AlertTriangle, { className: "text-warning mt-0.5 h-4 w-4 shrink-0" }), _jsxs("div", { children: [_jsxs("p", { className: "text-warning mb-1 text-xs font-medium", children: [issues.length, " issue", issues.length !== 1 ? 's' : '', " found"] }), _jsx("ul", { className: "space-y-0.5", children: issues.map((issue, i) => (_jsxs("li", { className: "text-warning text-xs", children: ["\u2022 ", issue] }, i))) })] })] }), _jsxs("button", { type: "button", onClick: async () => {
494
626
  if (!hasAccessibleAlt(activeItem))
495
627
  await handleAiGenerate('alt');
496
628
  if (!activeItem.title)
@@ -515,6 +647,13 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
515
647
  const suggestion = activeItem.aiAltSuggestion ?? '';
516
648
  setEditAlt(suggestion);
517
649
  setEditIsDecorative(!suggestion.trim());
518
- }, className: "text-primary shrink-0 font-medium hover:opacity-80", children: "Apply" })] })), !editIsDecorative && !editAlt && (_jsx("p", { className: "text-destructive mt-1 text-xs", children: "Required for accessibility and SEO" }))] }), _jsxs("div", { children: [_jsxs("div", { className: "mb-1 flex items-center justify-between", children: [_jsx("label", { className: "text-foreground text-sm font-medium", children: "Title" }), _jsxs("button", { type: "button", onClick: () => handleAiGenerate('title'), disabled: aiGenerating === 'title', className: "text-primary hover:text-primary/80 flex items-center gap-1 text-xs transition-colors disabled:opacity-50", children: [_jsx(Bot, { className: "h-3.5 w-3.5" }), aiGenerating === 'title' ? 'Generating...' : 'AI Generate'] })] }), _jsx("input", { type: "text", value: editTitle, onChange: (e) => setEditTitle(e.target.value), placeholder: "Image title...", className: "border-input focus:ring-ring w-full rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none" })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "media-detail-caption", className: "text-foreground mb-1 block text-sm font-medium", children: "Caption" }), _jsx("input", { id: "media-detail-caption", type: "text", value: editCaption, onChange: (e) => setEditCaption(e.target.value), placeholder: "Short caption shown alongside the asset...", className: "border-input focus:ring-ring w-full rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none" })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "media-detail-description", className: "text-foreground mb-1 block text-sm font-medium", children: "Description" }), _jsx("textarea", { id: "media-detail-description", value: editDescription, onChange: (e) => setEditDescription(e.target.value), placeholder: "Longer description for search and reuse...", rows: 2, className: "border-input focus:ring-ring w-full resize-none rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none" })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "media-detail-focus-keyword", className: "text-foreground mb-1 block text-sm font-medium", children: "Focus Keyword" }), _jsx("input", { id: "media-detail-focus-keyword", type: "text", value: editFocusKeyword, onChange: (e) => setEditFocusKeyword(e.target.value), placeholder: "Primary keyword this asset targets...", className: "border-input focus:ring-ring w-full rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none" })] }), _jsxs("div", { children: [_jsx("label", { className: "text-foreground mb-1 block text-sm font-medium", children: "File Name" }), _jsx("input", { type: "text", value: editFilename, onChange: (e) => setEditFilename(e.target.value), className: "border-input focus:ring-ring w-full rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none" })] })] }), _jsxs("div", { className: "border-border border-b p-4", children: [_jsxs("h4", { className: "text-muted-foreground mb-3 text-xs font-medium tracking-wide uppercase", children: ["Used On ", activeItem.usedOn && `(${activeItem.usedOn.length})`] }), activeItem.usedOn && activeItem.usedOn.length > 0 ? (_jsx("div", { className: "space-y-2", children: activeItem.usedOn.map((usage, i) => (_jsxs("button", { type: "button", onClick: () => onNavigate?.(usage.path), className: "border-border hover:bg-muted flex w-full items-center gap-2 rounded-lg border p-2 text-left transition-colors", children: [_jsx(Link2, { className: "text-muted-foreground h-4 w-4 shrink-0" }), _jsx("span", { className: "text-foreground flex-1 truncate text-sm", children: usage.page }), _jsx(ExternalLink, { className: "text-muted-foreground h-3.5 w-3.5 shrink-0" })] }, i))) })) : (_jsx("div", { className: "border-warning/30 bg-warn-l rounded-lg border p-4", children: _jsxs("div", { className: "flex items-start gap-2", children: [_jsx(AlertTriangle, { className: "text-warning mt-0.5 h-4 w-4 shrink-0" }), _jsxs("div", { children: [_jsx("p", { className: "text-warning text-xs font-medium", children: "Orphaned media" }), _jsx("p", { className: "text-warning mt-0.5 text-xs", children: "This file isn't used on any page. Consider deleting it to save storage." })] })] }) }))] }), _jsxs("div", { className: "space-y-3 p-4", children: [_jsx("h4", { className: "text-muted-foreground text-xs font-medium tracking-wide uppercase", children: "AI Optimization" }), _jsxs("button", { type: "button", onClick: () => handleAiGenerate('optimize'), disabled: aiGenerating === 'optimize', className: "border-primary/30 bg-primary/10 hover:bg-primary/15 flex w-full items-center gap-2 rounded-lg border p-4 text-left transition-colors disabled:opacity-50", children: [_jsx(Sparkles, { className: `text-primary h-5 w-5 shrink-0 ${aiGenerating === 'optimize' ? 'animate-spin' : ''}` }), _jsxs("div", { className: "flex-1", children: [_jsx("div", { className: "text-primary text-sm font-medium", children: aiGenerating === 'optimize' ? 'Optimizing...' : 'Optimize Image' }), _jsx("div", { className: "text-primary mt-0.5 text-xs", children: "Compress and convert to modern format (WebP/AVIF)" })] })] }), _jsxs("button", { type: "button", className: "border-border hover:bg-muted flex w-full items-center gap-2 rounded-lg border p-4 text-left transition-colors", children: [_jsx(Bot, { className: "text-muted-foreground h-5 w-5 shrink-0" }), _jsxs("div", { className: "flex-1", children: [_jsx("div", { className: "text-foreground text-sm font-medium", children: "AI Content Analysis" }), _jsx("div", { className: "text-muted-foreground mt-0.5 text-xs", children: "Detect objects, faces, text, and suggest categories" })] })] })] })] }), _jsxs("div", { className: "border-border bg-card sticky bottom-0 flex items-center gap-2 border-t p-4", children: [_jsxs("button", { type: "button", onClick: handleSaveDetails, disabled: saving, className: "bg-primary text-primary-foreground hover:bg-primary/90 flex flex-1 items-center justify-center gap-2 rounded-lg px-4 py-2 text-sm transition-colors disabled:opacity-50", children: [saving && _jsx(Loader2, { className: "h-4 w-4 animate-spin" }), saving ? 'Saving...' : 'Save Changes'] }), _jsx("button", { type: "button", className: "hover:bg-muted rounded-lg p-2 transition-colors", title: "Download", "aria-label": "Download", children: _jsx(Download, { className: "text-muted-foreground h-4 w-4", "aria-hidden": true }) }), _jsx("button", { type: "button", onClick: () => deleteMedia(activeItem.id), className: "hover:bg-muted rounded-lg p-2 transition-colors", title: "Delete", "aria-label": "Delete", children: _jsx(Trash2, { className: "text-destructive h-4 w-4", "aria-hidden": true }) })] })] }))] }))] })] }))] }));
650
+ }, className: "text-primary shrink-0 font-medium hover:opacity-80", children: "Apply" })] })), !editIsDecorative && !editAlt && (_jsx("p", { className: "text-destructive mt-1 text-xs", children: "Required for accessibility and SEO" }))] }), _jsxs("div", { children: [_jsxs("div", { className: "mb-1 flex items-center justify-between", children: [_jsx("label", { className: "text-foreground text-sm font-medium", children: "Title" }), _jsxs("button", { type: "button", onClick: () => handleAiGenerate('title'), disabled: aiGenerating === 'title', className: "text-primary hover:text-primary/80 flex items-center gap-1 text-xs transition-colors disabled:opacity-50", children: [_jsx(Bot, { className: "h-3.5 w-3.5" }), aiGenerating === 'title' ? 'Generating...' : 'AI Generate'] })] }), _jsx("input", { type: "text", value: editTitle, onChange: (e) => setEditTitle(e.target.value), placeholder: "Image title...", className: "border-input focus:ring-ring w-full rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none" })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "media-detail-caption", className: "text-foreground mb-1 block text-sm font-medium", children: "Caption" }), _jsx("input", { id: "media-detail-caption", type: "text", value: editCaption, onChange: (e) => setEditCaption(e.target.value), placeholder: "Short caption shown alongside the asset...", className: "border-input focus:ring-ring w-full rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none" })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "media-detail-description", className: "text-foreground mb-1 block text-sm font-medium", children: "Description" }), _jsx("textarea", { id: "media-detail-description", value: editDescription, onChange: (e) => setEditDescription(e.target.value), placeholder: "Longer description for search and reuse...", rows: 2, className: "border-input focus:ring-ring w-full resize-none rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none" })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "media-detail-focus-keyword", className: "text-foreground mb-1 block text-sm font-medium", children: "Focus Keyword" }), _jsx("input", { id: "media-detail-focus-keyword", type: "text", value: editFocusKeyword, onChange: (e) => setEditFocusKeyword(e.target.value), placeholder: "Primary keyword this asset targets...", className: "border-input focus:ring-ring w-full rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none" })] }), _jsxs("div", { children: [_jsx("label", { className: "text-foreground mb-1 block text-sm font-medium", children: "File Name" }), _jsx("input", { type: "text", value: editFilename, onChange: (e) => setEditFilename(e.target.value), className: "border-input focus:ring-ring w-full rounded-lg border px-3 py-2 text-sm focus:ring-2 focus:outline-none" })] })] }), _jsxs("div", { className: "border-border border-b p-4", children: [_jsxs("h4", { className: "text-muted-foreground mb-3 text-xs font-medium tracking-wide uppercase", children: ["Used On ", activeItem.usedOn && `(${activeItem.usedOn.length})`] }), activeItem.usedOn && activeItem.usedOn.length > 0 ? (_jsx("div", { className: "space-y-2", children: activeItem.usedOn.map((usage, i) => (_jsxs("button", { type: "button", onClick: () => onNavigate?.(usage.path), className: "border-border hover:bg-muted flex w-full items-center gap-2 rounded-lg border p-2 text-left transition-colors", children: [_jsx(Link2, { className: "text-muted-foreground h-4 w-4 shrink-0" }), _jsx("span", { className: "text-foreground flex-1 truncate text-sm", children: usage.page }), _jsx(ExternalLink, { className: "text-muted-foreground h-3.5 w-3.5 shrink-0" })] }, i))) })) : (_jsx("div", { className: "border-warning/30 bg-warn-l rounded-lg border p-4", children: _jsxs("div", { className: "flex items-start gap-2", children: [_jsx(AlertTriangle, { className: "text-warning mt-0.5 h-4 w-4 shrink-0" }), _jsxs("div", { children: [_jsx("p", { className: "text-warning text-xs font-medium", children: "Orphaned media" }), _jsx("p", { className: "text-warning mt-0.5 text-xs", children: "This file isn't used on any page. Consider deleting it to save storage." })] })] }) }))] }), _jsxs("div", { className: "space-y-3 p-4", children: [_jsx("h4", { className: "text-muted-foreground text-xs font-medium tracking-wide uppercase", children: "AI Optimization" }), _jsxs("button", { type: "button", onClick: () => handleAiGenerate('optimize'), disabled: aiGenerating === 'optimize', className: "border-primary/30 bg-primary/10 hover:bg-primary/15 flex w-full items-center gap-2 rounded-lg border p-4 text-left transition-colors disabled:opacity-50", children: [_jsx(Sparkles, { className: `text-primary h-5 w-5 shrink-0 ${aiGenerating === 'optimize' ? 'animate-spin' : ''}` }), _jsxs("div", { className: "flex-1", children: [_jsx("div", { className: "text-primary text-sm font-medium", children: aiGenerating === 'optimize' ? 'Optimizing...' : 'Optimize Image' }), _jsx("div", { className: "text-primary mt-0.5 text-xs", children: "Compress and convert to modern format (WebP/AVIF)" })] })] })] })] }), _jsxs("div", { className: "border-border bg-card sticky bottom-0 flex items-center gap-2 border-t p-4", children: [_jsxs("button", { type: "button", onClick: handleSaveDetails, disabled: saving, className: "bg-primary text-primary-foreground hover:bg-primary/90 flex flex-1 items-center justify-center gap-2 rounded-lg px-4 py-2 text-sm transition-colors disabled:opacity-50", children: [saving && _jsx(Loader2, { className: "h-4 w-4 animate-spin" }), saving ? 'Saving...' : 'Save Changes'] }), _jsx("a", { href: mediaDownloadUrl(activeItem.url), download: activeItem.name, target: "_blank", rel: "noopener noreferrer", className: "hover:bg-muted focus-visible:ring-ring rounded-lg p-2 transition-colors focus-visible:ring-2 focus-visible:outline-none", title: "Download", "aria-label": "Download", children: _jsx(Download, { className: "text-muted-foreground h-4 w-4", "aria-hidden": true }) }), _jsx("button", { type: "button", onClick: () => setPendingDelete([activeItem.id]), className: "hover:bg-muted rounded-lg p-2 transition-colors", title: "Delete", "aria-label": "Delete", children: _jsx(Trash2, { className: "text-destructive h-4 w-4", "aria-hidden": true }) })] })] }))] }))] })] })), _jsx(ConfirmDialog, { open: pendingDelete !== null, onClose: () => setPendingDelete(null), onConfirm: () => {
651
+ if (pendingDelete)
652
+ void deleteMedia(pendingDelete);
653
+ }, returnFocusFallback: focusLibrary, title: pendingDelete?.length === 1
654
+ ? 'Delete file?'
655
+ : `Delete ${pendingDelete?.length ?? 0} files?`, description: pendingDelete?.length === 1
656
+ ? 'This permanently deletes the file from storage. Pages that use it will show a broken image.'
657
+ : 'This permanently deletes these files from storage. Pages that use them will show broken images.', confirmLabel: "Delete", destructive: true }), _jsx(MediaLightbox, { items: lightboxItems, activeId: lightboxId, onActiveChange: setLightboxId, onClose: () => setLightboxId(null) })] }));
519
658
  }
520
659
  //# sourceMappingURL=MediaBrowser.js.map