@prenta/admin 2.11.1 → 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.
- package/CHANGELOG.md +17 -0
- package/dist/__tests__/components/modal.render.test.js +30 -1
- package/dist/__tests__/components/modal.render.test.js.map +1 -1
- package/dist/__tests__/lib/media-download.test.d.ts +2 -0
- package/dist/__tests__/lib/media-download.test.d.ts.map +1 -0
- package/dist/__tests__/lib/media-download.test.js +14 -0
- package/dist/__tests__/lib/media-download.test.js.map +1 -0
- package/dist/__tests__/views/media-browser.render.test.d.ts +2 -0
- package/dist/__tests__/views/media-browser.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/media-browser.render.test.js +270 -0
- package/dist/__tests__/views/media-browser.render.test.js.map +1 -0
- package/dist/__tests__/views/media-grid.test.d.ts +2 -0
- package/dist/__tests__/views/media-grid.test.d.ts.map +1 -0
- package/dist/__tests__/views/media-grid.test.js +31 -0
- package/dist/__tests__/views/media-grid.test.js.map +1 -0
- package/dist/components/MediaLightbox.d.ts +22 -0
- package/dist/components/MediaLightbox.d.ts.map +1 -0
- package/dist/components/MediaLightbox.js +38 -0
- package/dist/components/MediaLightbox.js.map +1 -0
- package/dist/components/ui/ConfirmDialog.d.ts +3 -1
- package/dist/components/ui/ConfirmDialog.d.ts.map +1 -1
- package/dist/components/ui/ConfirmDialog.js +2 -2
- package/dist/components/ui/ConfirmDialog.js.map +1 -1
- package/dist/components/ui/Modal.d.ts +7 -1
- package/dist/components/ui/Modal.d.ts.map +1 -1
- package/dist/components/ui/Modal.js +4 -2
- package/dist/components/ui/Modal.js.map +1 -1
- package/dist/lib/dialog-return-focus.d.ts +10 -0
- package/dist/lib/dialog-return-focus.d.ts.map +1 -0
- package/dist/lib/dialog-return-focus.js +26 -0
- package/dist/lib/dialog-return-focus.js.map +1 -0
- package/dist/lib/media-download.d.ts +8 -0
- package/dist/lib/media-download.d.ts.map +1 -0
- package/dist/lib/media-download.js +21 -0
- package/dist/lib/media-download.js.map +1 -0
- package/dist/prenta-admin.css +1 -1
- package/dist/views/MediaBrowser.d.ts +37 -0
- package/dist/views/MediaBrowser.d.ts.map +1 -1
- package/dist/views/MediaBrowser.js +217 -80
- package/dist/views/MediaBrowser.js.map +1 -1
- package/dist/views/MediaSeoAudit.d.ts +6 -0
- package/dist/views/MediaSeoAudit.d.ts.map +1 -1
- package/dist/views/MediaSeoAudit.js +12 -0
- package/dist/views/MediaSeoAudit.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/components/modal.render.test.tsx +52 -0
- package/src/__tests__/lib/media-download.test.ts +23 -0
- package/src/__tests__/views/media-browser.render.test.tsx +325 -0
- package/src/__tests__/views/media-grid.test.ts +34 -0
- package/src/components/MediaLightbox.tsx +127 -0
- package/src/components/ui/ConfirmDialog.tsx +4 -0
- package/src/components/ui/Modal.tsx +10 -0
- package/src/lib/dialog-return-focus.ts +33 -0
- package/src/lib/media-download.ts +18 -0
- package/src/views/MediaBrowser.tsx +403 -172
- package/src/views/MediaSeoAudit.tsx +11 -0
|
@@ -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. */
|
|
@@ -8,5 +41,9 @@ export interface MediaBrowserProps {
|
|
|
8
41
|
* the command palette) opens that item's detail panel once the list loads. */
|
|
9
42
|
currentPath?: string;
|
|
10
43
|
}
|
|
44
|
+
export declare const MEDIA_GRID_ROW_HEIGHT: number;
|
|
45
|
+
/** Columns that fit `auto-fill, minmax(220px, 1fr)` in the grid's content box. */
|
|
46
|
+
export declare function mediaGridColumns(contentWidth: number): number;
|
|
11
47
|
export declare function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBrowserProps): import("react/jsx-runtime").JSX.Element;
|
|
48
|
+
export {};
|
|
12
49
|
//# sourceMappingURL=MediaBrowser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaBrowser.d.ts","sourceRoot":"","sources":["../../src/views/MediaBrowser.tsx"],"names":[],"mappings":"
|
|
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 {
|
|
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
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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,40 +59,57 @@ 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
|
|
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
|
|
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
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
+
}
|
|
59
97
|
}
|
|
60
|
-
if (width >= 1536)
|
|
61
|
-
return 8;
|
|
62
|
-
if (width >= 1280)
|
|
63
|
-
return 6;
|
|
64
|
-
if (width >= 1024)
|
|
65
|
-
return 5;
|
|
66
|
-
if (width >= 768)
|
|
67
|
-
return 4;
|
|
68
|
-
if (width >= 640)
|
|
69
|
-
return 3;
|
|
70
|
-
return 2;
|
|
71
98
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
99
|
+
// Media.html `.media-grid` / `.media-thumb`. Grid rows are virtualised at a
|
|
100
|
+
// fixed stride, so card height must not depend on card width.
|
|
101
|
+
const MEDIA_CARD_MIN_WIDTH = 220;
|
|
102
|
+
const MEDIA_GRID_GAP = 14;
|
|
103
|
+
const MEDIA_GRID_PADDING_X = 28;
|
|
104
|
+
const MEDIA_CARD_HEIGHT = 172;
|
|
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;
|
|
108
|
+
/** Columns that fit `auto-fill, minmax(220px, 1fr)` in the grid's content box. */
|
|
109
|
+
export function mediaGridColumns(contentWidth) {
|
|
110
|
+
if (contentWidth <= 0)
|
|
111
|
+
return 4;
|
|
112
|
+
return Math.max(1, Math.floor((contentWidth + MEDIA_GRID_GAP) / (MEDIA_CARD_MIN_WIDTH + MEDIA_GRID_GAP)));
|
|
80
113
|
}
|
|
81
114
|
function buildMediaApiUrl(folderSel) {
|
|
82
115
|
const base = '/media?pageSize=100';
|
|
@@ -110,6 +143,8 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
|
|
|
110
143
|
const [selectedMedia, setSelectedMedia] = useState([]);
|
|
111
144
|
const [sortConfig, setSortConfig] = useState(null);
|
|
112
145
|
const [activeItem, setActiveItem] = useState(null);
|
|
146
|
+
const [pendingDelete, setPendingDelete] = useState(null);
|
|
147
|
+
const [lightboxId, setLightboxId] = useState(null);
|
|
113
148
|
const [editAlt, setEditAlt] = useState('');
|
|
114
149
|
const [editIsDecorative, setEditIsDecorative] = useState(false);
|
|
115
150
|
const [editTitle, setEditTitle] = useState('');
|
|
@@ -137,6 +172,9 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
|
|
|
137
172
|
if (sortConfig.key === 'size') {
|
|
138
173
|
cmp = a.sizeBytes - b.sizeBytes;
|
|
139
174
|
}
|
|
175
|
+
else if (sortConfig.key === 'score') {
|
|
176
|
+
cmp = (a.seoScore ?? 0) - (b.seoScore ?? 0);
|
|
177
|
+
}
|
|
140
178
|
else {
|
|
141
179
|
cmp = String(a[sortConfig.key]).localeCompare(String(b[sortConfig.key]));
|
|
142
180
|
}
|
|
@@ -145,16 +183,68 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
|
|
|
145
183
|
}
|
|
146
184
|
return results;
|
|
147
185
|
}, [mediaItems, searchQuery, filterType, sortConfig]);
|
|
148
|
-
const
|
|
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]);
|
|
149
223
|
const gridScrollRef = useRef(null);
|
|
224
|
+
const [gridWidth, setGridWidth] = useState(0);
|
|
225
|
+
const gridMounted = viewMode === 'grid' && activeTab === 'library' && filteredAndSorted.length > 0;
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
const el = gridScrollRef.current;
|
|
228
|
+
if (!gridMounted || !el)
|
|
229
|
+
return;
|
|
230
|
+
const measure = () => setGridWidth(el.clientWidth - MEDIA_GRID_PADDING_X * 2);
|
|
231
|
+
measure();
|
|
232
|
+
if (typeof ResizeObserver === 'undefined')
|
|
233
|
+
return;
|
|
234
|
+
const observer = new ResizeObserver(measure);
|
|
235
|
+
observer.observe(el);
|
|
236
|
+
return () => observer.disconnect();
|
|
237
|
+
}, [gridMounted, loading]);
|
|
238
|
+
const gridColumns = mediaGridColumns(gridWidth);
|
|
150
239
|
const listScrollRef = useRef(null);
|
|
240
|
+
const focusLibrary = useCallback(() => gridScrollRef.current ?? listScrollRef.current, []);
|
|
151
241
|
/** The grid's or list's scroll position when a card opened the detail panel. */
|
|
152
242
|
const savedListScroll = useRef(0);
|
|
153
243
|
const gridRowCount = gridColumns > 0 ? Math.ceil(filteredAndSorted.length / gridColumns) : 0;
|
|
154
244
|
const gridWindow = useVirtualWindow({
|
|
155
245
|
count: gridRowCount,
|
|
156
246
|
scrollRef: gridScrollRef,
|
|
157
|
-
estimateSize:
|
|
247
|
+
estimateSize: MEDIA_GRID_ROW_HEIGHT,
|
|
158
248
|
overscan: 3,
|
|
159
249
|
});
|
|
160
250
|
const listWindow = useVirtualWindow({
|
|
@@ -258,17 +348,48 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
|
|
|
258
348
|
refetch();
|
|
259
349
|
}
|
|
260
350
|
};
|
|
261
|
-
const deleteMedia = async (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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;
|
|
265
361
|
}
|
|
266
362
|
else {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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`);
|
|
271
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();
|
|
272
393
|
};
|
|
273
394
|
const handleAiGenerate = async (field) => {
|
|
274
395
|
setAiGenerating(field);
|
|
@@ -302,7 +423,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
|
|
|
302
423
|
.replace(/[-_]/g, ' ')
|
|
303
424
|
.trim();
|
|
304
425
|
if (field === 'alt') {
|
|
305
|
-
setEditAlt(base
|
|
426
|
+
setEditAlt(base);
|
|
306
427
|
}
|
|
307
428
|
else {
|
|
308
429
|
setEditTitle(base.replace(/\b\w/g, (c) => c.toUpperCase()));
|
|
@@ -409,8 +530,8 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
|
|
|
409
530
|
// header), so the card that opened it leaves the screen. Focus moves into
|
|
410
531
|
// the panel and back when it closes. The hidden scroll box comes back at the
|
|
411
532
|
// top, and the virtualised window wouldn't follow (no scroll event), so its
|
|
412
|
-
// position, saved when a card opens the panel, goes back first.
|
|
413
|
-
//
|
|
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.
|
|
414
535
|
useSheetFocus(panelOpen, detailPanelRef, {
|
|
415
536
|
restore: () => {
|
|
416
537
|
const scroller = gridScrollRef.current ?? listScrollRef.current;
|
|
@@ -444,21 +565,28 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
|
|
|
444
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) => {
|
|
445
566
|
setFolderSel(sel);
|
|
446
567
|
setSelectedMedia([]);
|
|
447
|
-
}, 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
|
|
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
|
|
448
581
|
.filter((item) => selectedMedia.includes(item.id) && isImageMedia(item))
|
|
449
|
-
.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:
|
|
450
|
-
for (const id of selectedMedia)
|
|
451
|
-
await deleteMedia(id);
|
|
452
|
-
setSelectedMedia([]);
|
|
453
|
-
}, 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'
|
|
454
583
|
? 'No uncategorized media'
|
|
455
584
|
: folderSel.type === 'folder'
|
|
456
585
|
? 'No media in this folder'
|
|
457
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,
|
|
458
|
-
//
|
|
459
|
-
//
|
|
460
|
-
|
|
461
|
-
tabIndex: 0, role: "region", "aria-label": "Media library", className: "h-full overflow-y-auto p-2 sm:p-3", children: _jsx("div", { className: "relative", style: { height: gridRowCount * 220 }, children: gridWindow.rows.map((virtualRow) => (_jsx("div", { className: "grid gap-3 sm:gap-4", style: {
|
|
587
|
+
// Media.html `.mc-grid-area`: the scroller takes arrow-key
|
|
588
|
+
// scrolling (axe scrollable-region-focusable).
|
|
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: {
|
|
462
590
|
position: 'absolute',
|
|
463
591
|
top: 0,
|
|
464
592
|
left: 0,
|
|
@@ -469,21 +597,23 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
|
|
|
469
597
|
.slice(virtualRow.index * gridColumns, virtualRow.index * gridColumns + gridColumns)
|
|
470
598
|
.map((item) => {
|
|
471
599
|
const isActive = activeItem?.id === item.id;
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
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
|
|
485
615
|
? 'border-primary bg-primary'
|
|
486
|
-
: 'border-input bg-card/80'}`, children:
|
|
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));
|
|
487
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 &&
|
|
488
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) => {
|
|
489
619
|
const item = filteredAndSorted[row.index];
|
|
@@ -492,7 +622,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
|
|
|
492
622
|
const isActive = activeItem?.id === item.id;
|
|
493
623
|
const hasIssues = !hasAccessibleAlt(item) || !item.title || item.usedOn?.length === 0;
|
|
494
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));
|
|
495
|
-
}), _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 () => {
|
|
496
626
|
if (!hasAccessibleAlt(activeItem))
|
|
497
627
|
await handleAiGenerate('alt');
|
|
498
628
|
if (!activeItem.title)
|
|
@@ -517,6 +647,13 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }) {
|
|
|
517
647
|
const suggestion = activeItem.aiAltSuggestion ?? '';
|
|
518
648
|
setEditAlt(suggestion);
|
|
519
649
|
setEditIsDecorative(!suggestion.trim());
|
|
520
|
-
}, 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)" })] })] })
|
|
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) })] }));
|
|
521
658
|
}
|
|
522
659
|
//# sourceMappingURL=MediaBrowser.js.map
|