@jhits/plugin-images 0.0.14 → 0.0.15
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/dist/components/Image.d.ts +1 -6
- package/dist/components/Image.d.ts.map +1 -1
- package/dist/components/Image.js +86 -202
- package/dist/components/ImageEditor.d.ts.map +1 -1
- package/dist/components/ImageEditor.js +21 -125
- package/dist/components/ImagePicker.d.ts.map +1 -1
- package/dist/components/ImagePicker.js +6 -59
- package/dist/utils/fallback.d.ts +9 -4
- package/dist/utils/fallback.d.ts.map +1 -1
- package/dist/utils/fallback.js +40 -12
- package/dist/utils/transforms.d.ts.map +1 -1
- package/dist/utils/transforms.js +7 -10
- package/dist/views/ImageManager/components/CleanupLibraryModal.d.ts +12 -0
- package/dist/views/ImageManager/components/CleanupLibraryModal.d.ts.map +1 -0
- package/dist/views/ImageManager/components/CleanupLibraryModal.js +7 -0
- package/dist/views/ImageManager/components/DeleteImageModal.d.ts +15 -0
- package/dist/views/ImageManager/components/DeleteImageModal.d.ts.map +1 -0
- package/dist/views/ImageManager/components/DeleteImageModal.js +8 -0
- package/dist/views/ImageManager/components/ImageGrid.d.ts +12 -0
- package/dist/views/ImageManager/components/ImageGrid.d.ts.map +1 -0
- package/dist/views/ImageManager/components/ImageGrid.js +15 -0
- package/dist/views/ImageManager/components/ImageManagerHeader.d.ts +11 -0
- package/dist/views/ImageManager/components/ImageManagerHeader.d.ts.map +1 -0
- package/dist/views/ImageManager/components/ImageManagerHeader.js +6 -0
- package/dist/views/ImageManager/components/ImageManagerStats.d.ts +8 -0
- package/dist/views/ImageManager/components/ImageManagerStats.d.ts.map +1 -0
- package/dist/views/ImageManager/components/ImageManagerStats.js +6 -0
- package/dist/views/ImageManager/components/ImageManagerToolbar.d.ts +9 -0
- package/dist/views/ImageManager/components/ImageManagerToolbar.d.ts.map +1 -0
- package/dist/views/ImageManager/components/ImageManagerToolbar.js +10 -0
- package/dist/views/ImageManager/components/ImageTable.d.ts +13 -0
- package/dist/views/ImageManager/components/ImageTable.d.ts.map +1 -0
- package/dist/views/ImageManager/components/ImageTable.js +13 -0
- package/dist/views/ImageManager/types.d.ts +26 -0
- package/dist/views/ImageManager/types.d.ts.map +1 -0
- package/dist/views/ImageManager/types.js +1 -0
- package/dist/views/ImageManager.d.ts +1 -1
- package/dist/views/ImageManager.d.ts.map +1 -1
- package/dist/views/ImageManager.js +28 -52
- package/package.json +10 -9
- package/src/components/Image.tsx +107 -262
- package/src/components/ImageEditor.tsx +31 -193
- package/src/components/ImagePicker.tsx +22 -107
- package/src/utils/fallback.ts +46 -13
- package/src/utils/transforms.ts +9 -12
- package/src/views/ImageManager/components/CleanupLibraryModal.tsx +96 -0
- package/src/views/ImageManager/components/DeleteImageModal.tsx +144 -0
- package/src/views/ImageManager/components/ImageGrid.tsx +119 -0
- package/src/views/ImageManager/components/ImageManagerHeader.tsx +72 -0
- package/src/views/ImageManager/components/ImageManagerStats.tsx +60 -0
- package/src/views/ImageManager/components/ImageManagerToolbar.tsx +60 -0
- package/src/views/ImageManager/components/ImageTable.tsx +120 -0
- package/src/views/ImageManager/types.ts +27 -0
- package/src/views/ImageManager.tsx +103 -571
- package/src/components/BackgroundImage.d.ts +0 -11
- package/src/components/BackgroundImage.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/config.d.ts +0 -9
- package/src/components/GlobalImageEditor/config.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/eventHandlers.d.ts +0 -20
- package/src/components/GlobalImageEditor/eventHandlers.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/imageDetection.d.ts +0 -16
- package/src/components/GlobalImageEditor/imageDetection.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/imageSetup.d.ts +0 -9
- package/src/components/GlobalImageEditor/imageSetup.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/saveLogic.d.ts +0 -26
- package/src/components/GlobalImageEditor/saveLogic.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/stylingDetection.d.ts +0 -9
- package/src/components/GlobalImageEditor/stylingDetection.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/transformParsing.d.ts +0 -16
- package/src/components/GlobalImageEditor/transformParsing.d.ts.map +0 -1
- package/src/components/GlobalImageEditor/types.d.ts +0 -36
- package/src/components/GlobalImageEditor/types.d.ts.map +0 -1
- package/src/components/GlobalImageEditor.d.ts +0 -8
- package/src/components/GlobalImageEditor.d.ts.map +0 -1
- package/src/components/Image.d.ts +0 -22
- package/src/components/Image.d.ts.map +0 -1
- package/src/components/ImageBrowserModal.d.ts +0 -13
- package/src/components/ImageBrowserModal.d.ts.map +0 -1
- package/src/components/ImageEditor.d.ts +0 -27
- package/src/components/ImageEditor.d.ts.map +0 -1
- package/src/components/ImagePicker.d.ts +0 -3
- package/src/components/ImagePicker.d.ts.map +0 -1
- package/src/components/ImagesPluginInit.d.ts +0 -24
- package/src/components/ImagesPluginInit.d.ts.map +0 -1
- package/src/hooks/useImagePicker.d.ts +0 -20
- package/src/hooks/useImagePicker.d.ts.map +0 -1
- package/src/types/index.d.ts +0 -80
- package/src/types/index.d.ts.map +0 -1
- package/src/utils/fallback.d.ts +0 -27
- package/src/utils/fallback.d.ts.map +0 -1
- package/src/utils/transforms.d.ts +0 -26
- package/src/utils/transforms.d.ts.map +0 -1
- package/src/views/ImageManager.d.ts +0 -10
- package/src/views/ImageManager.d.ts.map +0 -1
package/src/components/Image.tsx
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import NextImage from 'next/image';
|
|
4
|
-
import React, { useState, useEffect, useCallback
|
|
4
|
+
import React, { useState, useEffect, useCallback } from 'react';
|
|
5
5
|
import { Edit2, Loader2 } from 'lucide-react';
|
|
6
|
-
import { getImageTransform, getImageFilter } from '../utils/transforms';
|
|
7
|
-
import { getFallbackImageUrl } from '../utils/fallback';
|
|
8
6
|
|
|
9
7
|
export let authCache: boolean | null = null;
|
|
10
8
|
let authFetching: Promise<boolean> | null = null;
|
|
@@ -41,12 +39,6 @@ export interface PluginImageProps {
|
|
|
41
39
|
objectPosition?: string;
|
|
42
40
|
style?: React.CSSProperties;
|
|
43
41
|
editable?: boolean;
|
|
44
|
-
// Props take precedence over API-fetched values
|
|
45
|
-
scale?: number;
|
|
46
|
-
positionX?: number;
|
|
47
|
-
positionY?: number;
|
|
48
|
-
brightness?: number;
|
|
49
|
-
blur?: number;
|
|
50
42
|
}
|
|
51
43
|
|
|
52
44
|
export function Image({
|
|
@@ -62,296 +54,149 @@ export function Image({
|
|
|
62
54
|
objectPosition = 'center',
|
|
63
55
|
style,
|
|
64
56
|
editable = true,
|
|
65
|
-
...props // Using rest for override props
|
|
66
57
|
}: PluginImageProps) {
|
|
67
|
-
|
|
68
|
-
const [apiData, setApiData] = useState({
|
|
69
|
-
filename: null as string | null,
|
|
70
|
-
brightness: 100,
|
|
71
|
-
blur: 0,
|
|
72
|
-
scale: 1.0,
|
|
73
|
-
positionX: 0,
|
|
74
|
-
positionY: 0,
|
|
75
|
-
});
|
|
76
|
-
|
|
58
|
+
const [resolvedFilename, setResolvedFilename] = useState<string | null>(null);
|
|
77
59
|
const [isResolving, setIsResolving] = useState(true);
|
|
78
|
-
const [
|
|
79
|
-
const [
|
|
80
|
-
const [
|
|
81
|
-
|
|
82
|
-
const imageRef = useRef<HTMLImageElement | null>(null);
|
|
83
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
60
|
+
const [brightness, setBrightness] = useState<number>(100);
|
|
61
|
+
const [blur, setBlur] = useState<number>(0);
|
|
62
|
+
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);
|
|
63
|
+
const [authChecked, setAuthChecked] = useState<boolean>(false);
|
|
84
64
|
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
65
|
+
// Check authentication status if editable is true (default)
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (editable && !authChecked) {
|
|
68
|
+
const checkAuth = async () => {
|
|
69
|
+
try {
|
|
70
|
+
const res = await fetch('/api/me');
|
|
71
|
+
const data = await res.json();
|
|
72
|
+
if (data.loggedIn && (data.user?.role === 'admin' || data.user?.role === 'dev')) {
|
|
73
|
+
setIsAuthenticated(true);
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
// User is not authenticated or API call failed
|
|
77
|
+
setIsAuthenticated(false);
|
|
78
|
+
} finally {
|
|
79
|
+
setAuthChecked(true);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
checkAuth();
|
|
83
|
+
} else if (!editable) {
|
|
84
|
+
// If explicitly set to false, skip auth check
|
|
85
|
+
setAuthChecked(true);
|
|
86
|
+
}
|
|
87
|
+
}, [editable, authChecked]);
|
|
94
88
|
|
|
95
|
-
//
|
|
96
|
-
const
|
|
97
|
-
const isLikelyPath = /\.(jpg|jpeg|png|webp|gif|svg)$/i.test(targetId) || /^\d+-/.test(targetId);
|
|
89
|
+
// Only allow editing if editable is true AND user is authenticated
|
|
90
|
+
const canEdit = editable && isAuthenticated;
|
|
98
91
|
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
const resolveImage = useCallback(() => {
|
|
93
|
+
const looksLikeFilename = /\.(jpg|jpeg|png|webp|gif|svg)$/i.test(id) || /^\d+-/.test(id);
|
|
94
|
+
if (looksLikeFilename) {
|
|
95
|
+
setResolvedFilename(id);
|
|
101
96
|
setIsResolving(false);
|
|
102
97
|
return;
|
|
103
98
|
}
|
|
104
99
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
positionY: apiPositionY,
|
|
100
|
+
fetch(`/api/plugin-images/resolve?id=${encodeURIComponent(id)}`)
|
|
101
|
+
.then(res => res.ok ? res.json() : { filename: id, brightness: 100, blur: 0 })
|
|
102
|
+
.then(data => {
|
|
103
|
+
setResolvedFilename(data.filename || id);
|
|
104
|
+
setBrightness(data.brightness ?? 100);
|
|
105
|
+
setBlur(data.blur ?? 0);
|
|
106
|
+
setIsResolving(false);
|
|
107
|
+
})
|
|
108
|
+
.catch(() => {
|
|
109
|
+
setResolvedFilename(id);
|
|
110
|
+
setBrightness(100);
|
|
111
|
+
setBlur(0);
|
|
112
|
+
setIsResolving(false);
|
|
119
113
|
});
|
|
120
|
-
|
|
121
|
-
setImageError(false);
|
|
122
|
-
} catch {
|
|
123
|
-
setApiData(prev => ({ ...prev, filename: targetId }));
|
|
124
|
-
} finally {
|
|
125
|
-
setIsResolving(false);
|
|
126
|
-
}
|
|
127
|
-
}, []);
|
|
128
|
-
|
|
129
|
-
// 4. Auth Check (Cached - only fetches once)
|
|
130
|
-
useEffect(() => {
|
|
131
|
-
if (!editable) return;
|
|
132
|
-
checkAuthOnce().then(setIsAuthenticated);
|
|
133
|
-
}, [editable]);
|
|
114
|
+
}, [id]);
|
|
134
115
|
|
|
135
|
-
// 5. Stable Event Listener (Prevents closure staleness)
|
|
136
|
-
// Only fetch from API if props are not provided (parent controls the values)
|
|
137
|
-
const hasProps = props.scale !== undefined || props.positionX !== undefined || props.positionY !== undefined || props.brightness !== undefined || props.blur !== undefined;
|
|
138
|
-
|
|
139
116
|
useEffect(() => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
// Only listen to events if props are not provided
|
|
143
|
-
if (hasProps) return;
|
|
144
|
-
|
|
145
|
-
const handleUpdate = (e: any) => {
|
|
117
|
+
resolveImage();
|
|
118
|
+
const handleMappingUpdate = (e: any) => {
|
|
146
119
|
if (e.detail?.id === id) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
setApiData(prev => ({
|
|
152
|
-
...prev,
|
|
153
|
-
brightness: eventData.brightness ?? prev.brightness,
|
|
154
|
-
blur: eventData.blur ?? prev.blur,
|
|
155
|
-
scale: eventData.scale ?? prev.scale,
|
|
156
|
-
positionX: eventData.positionX ?? prev.positionX,
|
|
157
|
-
positionY: eventData.positionY ?? prev.positionY,
|
|
158
|
-
}));
|
|
159
|
-
}
|
|
120
|
+
setIsResolving(true);
|
|
121
|
+
if (e.detail.brightness !== undefined) setBrightness(e.detail.brightness);
|
|
122
|
+
if (e.detail.blur !== undefined) setBlur(e.detail.blur);
|
|
123
|
+
setTimeout(() => resolveImage(), 100);
|
|
160
124
|
}
|
|
161
125
|
};
|
|
126
|
+
window.addEventListener('image-mapping-updated', handleMappingUpdate as EventListener);
|
|
127
|
+
return () => window.removeEventListener('image-mapping-updated', handleMappingUpdate as EventListener);
|
|
128
|
+
}, [id, resolveImage]);
|
|
162
129
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
130
|
+
const src = resolvedFilename
|
|
131
|
+
? `/api/uploads/${encodeURIComponent(resolvedFilename)}`
|
|
132
|
+
: `/api/uploads/${encodeURIComponent(id)}`;
|
|
166
133
|
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
if (!imageRef.current || !containerRef.current) return;
|
|
170
|
-
const containerWidth = containerRef.current.offsetWidth;
|
|
171
|
-
const containerHeight = containerRef.current.offsetHeight;
|
|
172
|
-
|
|
173
|
-
// Ensure container has dimensions before calculating
|
|
174
|
-
if (containerWidth === 0 || containerHeight === 0) {
|
|
175
|
-
// Try to get dimensions from computed styles or parent
|
|
176
|
-
const parentWidth = containerRef.current.parentElement?.clientWidth;
|
|
177
|
-
const parentHeight = containerRef.current.parentElement?.clientHeight;
|
|
178
|
-
|
|
179
|
-
if (parentWidth && parentHeight && imageRef.current.naturalWidth > 0) {
|
|
180
|
-
const widthRatio = parentWidth / imageRef.current.naturalWidth;
|
|
181
|
-
const heightRatio = parentHeight / imageRef.current.naturalHeight;
|
|
182
|
-
const calculatedBaseScale = Math.max(widthRatio, heightRatio);
|
|
183
|
-
setBaseScale(calculatedBaseScale);
|
|
184
|
-
}
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (imageRef.current.naturalWidth === 0 || imageRef.current.naturalHeight === 0) return;
|
|
189
|
-
|
|
190
|
-
const widthRatio = containerWidth / imageRef.current.naturalWidth;
|
|
191
|
-
const heightRatio = containerHeight / imageRef.current.naturalHeight;
|
|
192
|
-
const calculatedBaseScale = Math.max(widthRatio, heightRatio);
|
|
193
|
-
setBaseScale(calculatedBaseScale);
|
|
194
|
-
}, []);
|
|
195
|
-
|
|
196
|
-
// Only construct image URL if we have a valid filename (not a semantic ID)
|
|
197
|
-
// Check if filename looks like an actual file (has extension or starts with timestamp)
|
|
198
|
-
const filename = effective.filename;
|
|
199
|
-
const hasFileExtension = /\.(jpg|jpeg|png|webp|gif|svg)$/i.test(filename);
|
|
200
|
-
const looksLikeTimestamp = /^\d+-/.test(filename);
|
|
201
|
-
const isValidFilename = hasFileExtension || looksLikeTimestamp;
|
|
202
|
-
|
|
203
|
-
// Don't construct URL until resolution is complete AND we have a valid filename
|
|
204
|
-
const shouldConstructUrl = !isResolving && isValidFilename;
|
|
205
|
-
const baseSrc = shouldConstructUrl ? `/api/uploads/${encodeURIComponent(filename)}` : null;
|
|
206
|
-
const src = imageError ? getFallbackImageUrl() : (baseSrc || getFallbackImageUrl());
|
|
134
|
+
// Logic: If the user passes 'w-full' or 'h-full', or explicit 'fill',
|
|
135
|
+
// we must use Next.js fill mode to make object-fit work.
|
|
207
136
|
const shouldFill = fill || className.includes('w-full') || className.includes('h-full');
|
|
208
|
-
const hasTransforms = effective.scale !== 1 || effective.positionX !== 0 || effective.positionY !== 0;
|
|
209
137
|
|
|
210
|
-
//
|
|
211
|
-
|
|
212
|
-
// Don't check if:
|
|
213
|
-
// 1. Already in error state
|
|
214
|
-
// 2. Still resolving
|
|
215
|
-
// 3. No valid base src
|
|
216
|
-
// 4. Base src is the fallback URL
|
|
217
|
-
if (imageError || isResolving || !baseSrc || baseSrc === getFallbackImageUrl() || !isValidFilename) return;
|
|
218
|
-
|
|
219
|
-
const testImg = document.createElement('img');
|
|
220
|
-
const handleError = () => {
|
|
221
|
-
setImageError(true);
|
|
222
|
-
};
|
|
223
|
-
const handleLoad = () => {
|
|
224
|
-
setImageError(false);
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
testImg.onerror = handleError;
|
|
228
|
-
testImg.onload = handleLoad;
|
|
229
|
-
testImg.src = baseSrc;
|
|
230
|
-
|
|
231
|
-
return () => {
|
|
232
|
-
testImg.onerror = null;
|
|
233
|
-
testImg.onload = null;
|
|
234
|
-
};
|
|
235
|
-
}, [baseSrc, imageError, isResolving, isValidFilename]);
|
|
138
|
+
// Default sizes for fill images when not provided - use unoptimized since these are API routes
|
|
139
|
+
const imageSizes = shouldFill ? (sizes || undefined) : sizes;
|
|
236
140
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const resizeObserver = new ResizeObserver(() => {
|
|
242
|
-
calculateBaseScale();
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
resizeObserver.observe(containerRef.current);
|
|
246
|
-
return () => resizeObserver.disconnect();
|
|
247
|
-
}, [hasTransforms, shouldFill, calculateBaseScale]);
|
|
141
|
+
const filterStyle = brightness !== 100 || blur !== 0
|
|
142
|
+
? `brightness(${brightness}%) blur(${blur}px)`
|
|
143
|
+
: undefined;
|
|
248
144
|
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
})() : undefined;
|
|
257
|
-
|
|
258
|
-
const filterStyle = getImageFilter(effective.brightness, effective.blur);
|
|
145
|
+
const handleEditClick = (e: React.MouseEvent) => {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
e.stopPropagation();
|
|
148
|
+
window.dispatchEvent(new CustomEvent('open-image-editor', {
|
|
149
|
+
detail: { id, currentBrightness: brightness, currentBlur: blur }
|
|
150
|
+
}));
|
|
151
|
+
};
|
|
259
152
|
|
|
260
153
|
return (
|
|
261
154
|
<div
|
|
262
|
-
ref={containerRef}
|
|
263
155
|
className={`group/image relative overflow-hidden transition-all duration-300 ${className}`}
|
|
264
|
-
style={{
|
|
265
|
-
...style,
|
|
266
|
-
filter: filterStyle || style?.filter,
|
|
267
|
-
// Ensure container has explicit positioning context
|
|
156
|
+
style={{
|
|
157
|
+
...style,
|
|
268
158
|
position: 'relative',
|
|
159
|
+
filter: filterStyle || style?.filter,
|
|
269
160
|
}}
|
|
270
161
|
data-image-id={id}
|
|
271
162
|
>
|
|
163
|
+
{/* RESOLVING STATE */}
|
|
272
164
|
{isResolving && (
|
|
273
165
|
<div className="absolute inset-0 z-20 flex items-center justify-center bg-neutral-100 dark:bg-neutral-800 animate-pulse">
|
|
274
166
|
<Loader2 className="w-5 h-5 animate-spin text-neutral-400" />
|
|
275
167
|
</div>
|
|
276
168
|
)}
|
|
277
169
|
|
|
278
|
-
{
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}}
|
|
301
|
-
draggable={false}
|
|
302
|
-
/>
|
|
303
|
-
) : null
|
|
304
|
-
) : imageError || !baseSrc ? (
|
|
305
|
-
// Fallback to regular img tag when error occurs or no valid filename yet
|
|
306
|
-
<img
|
|
307
|
-
src={getFallbackImageUrl()}
|
|
308
|
-
alt={alt}
|
|
309
|
-
loading={priority ? 'eager' : 'lazy'}
|
|
310
|
-
className={`transition-all duration-500 ${editable ? 'group-hover/image:scale-105' : ''}`}
|
|
311
|
-
style={{
|
|
312
|
-
objectFit,
|
|
313
|
-
objectPosition,
|
|
314
|
-
width: shouldFill ? '100%' : width,
|
|
315
|
-
height: shouldFill ? '100%' : height,
|
|
316
|
-
...(transformStyle ? { transform: transformStyle } : {}),
|
|
317
|
-
...style,
|
|
318
|
-
}}
|
|
319
|
-
/>
|
|
320
|
-
) : (
|
|
321
|
-
<NextImage
|
|
322
|
-
src={src}
|
|
323
|
-
alt={alt}
|
|
324
|
-
width={!shouldFill ? width : undefined}
|
|
325
|
-
height={!shouldFill ? height : undefined}
|
|
326
|
-
fill={shouldFill}
|
|
327
|
-
sizes={sizes || (shouldFill ? "(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw" : undefined)}
|
|
328
|
-
priority={priority}
|
|
329
|
-
loading={priority ? 'eager' : undefined}
|
|
330
|
-
className={`transition-all duration-500 ${editable ? 'group-hover/image:scale-105' : ''}`}
|
|
331
|
-
style={{
|
|
332
|
-
objectFit,
|
|
333
|
-
objectPosition,
|
|
334
|
-
...(transformStyle ? { transform: transformStyle } : {}),
|
|
335
|
-
...style,
|
|
336
|
-
}}
|
|
337
|
-
/>
|
|
338
|
-
)}
|
|
339
|
-
|
|
340
|
-
{editable && isAuthenticated && (
|
|
341
|
-
<button
|
|
342
|
-
onClick={(e) => {
|
|
343
|
-
e.preventDefault();
|
|
344
|
-
window.dispatchEvent(new CustomEvent('open-image-editor', {
|
|
345
|
-
detail: { id, currentBrightness: effective.brightness, currentBlur: effective.blur }
|
|
346
|
-
}));
|
|
347
|
-
}}
|
|
348
|
-
className="absolute inset-0 z-30 flex items-center justify-center opacity-0 group-hover/image:opacity-100 transition-all duration-300 bg-neutral-900/40 backdrop-blur-[2px]"
|
|
170
|
+
{/* THE IMAGE */}
|
|
171
|
+
<NextImage
|
|
172
|
+
src={src}
|
|
173
|
+
alt={alt}
|
|
174
|
+
width={!shouldFill ? width : undefined}
|
|
175
|
+
height={!shouldFill ? height : undefined}
|
|
176
|
+
fill={shouldFill}
|
|
177
|
+
sizes={imageSizes}
|
|
178
|
+
unoptimized
|
|
179
|
+
priority={priority}
|
|
180
|
+
className={`transition-all duration-500 ease-in-out ${editable ? 'group-hover/image:scale-105' : ''}`}
|
|
181
|
+
style={{
|
|
182
|
+
objectFit: objectFit,
|
|
183
|
+
objectPosition: objectPosition,
|
|
184
|
+
}}
|
|
185
|
+
/>
|
|
186
|
+
|
|
187
|
+
{/* EDIT OVERLAY - Dashboard Theme */}
|
|
188
|
+
{canEdit && (
|
|
189
|
+
<div
|
|
190
|
+
onClick={handleEditClick}
|
|
191
|
+
className="absolute inset-0 z-30 flex items-center justify-center opacity-0 group-hover/image:opacity-100 transition-all duration-300 cursor-pointer"
|
|
349
192
|
>
|
|
350
|
-
<div className="
|
|
351
|
-
|
|
352
|
-
|
|
193
|
+
<div className="absolute inset-0 bg-neutral-900/40 dark:bg-neutral-900/60 backdrop-blur-[2px]" />
|
|
194
|
+
|
|
195
|
+
<div className="relative flex items-center gap-2 px-4 py-2.5 bg-neutral-100 dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 rounded-full shadow-2xl scale-90 group-hover/image:scale-100 transition-all duration-300 border border-neutral-300 dark:border-neutral-700">
|
|
196
|
+
<Edit2 size={14} strokeWidth={2.5} className="text-primary" />
|
|
197
|
+
<span className="text-[10px] font-black uppercase tracking-widest">Edit</span>
|
|
353
198
|
</div>
|
|
354
|
-
</
|
|
199
|
+
</div>
|
|
355
200
|
)}
|
|
356
201
|
</div>
|
|
357
202
|
);
|