@jhits/plugin-images 0.0.11 → 0.0.12
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/package.json +3 -2
- package/src/api/fallback/route.ts +69 -0
- package/src/api/index.ts +10 -0
- package/src/api/list/index.ts +96 -0
- package/src/api/resolve/route.ts +241 -0
- package/src/api/router.ts +85 -0
- package/src/api/upload/index.ts +88 -0
- package/src/api/uploads/[filename]/route.ts +93 -0
- package/src/api-server.ts +11 -0
- package/src/assets/noimagefound.jpg +0 -0
- package/src/components/BackgroundImage.d.ts +11 -0
- package/src/components/BackgroundImage.d.ts.map +1 -0
- package/src/components/BackgroundImage.tsx +92 -0
- package/src/components/GlobalImageEditor/config.d.ts +9 -0
- package/src/components/GlobalImageEditor/config.d.ts.map +1 -0
- package/src/components/GlobalImageEditor/config.ts +21 -0
- package/src/components/GlobalImageEditor/eventHandlers.d.ts +20 -0
- package/src/components/GlobalImageEditor/eventHandlers.d.ts.map +1 -0
- package/src/components/GlobalImageEditor/eventHandlers.ts +267 -0
- package/src/components/GlobalImageEditor/imageDetection.d.ts +16 -0
- package/src/components/GlobalImageEditor/imageDetection.d.ts.map +1 -0
- package/src/components/GlobalImageEditor/imageDetection.ts +160 -0
- package/src/components/GlobalImageEditor/imageSetup.d.ts +9 -0
- package/src/components/GlobalImageEditor/imageSetup.d.ts.map +1 -0
- package/src/components/GlobalImageEditor/imageSetup.ts +306 -0
- package/src/components/GlobalImageEditor/saveLogic.d.ts +26 -0
- package/src/components/GlobalImageEditor/saveLogic.d.ts.map +1 -0
- package/src/components/GlobalImageEditor/saveLogic.ts +133 -0
- package/src/components/GlobalImageEditor/stylingDetection.d.ts +9 -0
- package/src/components/GlobalImageEditor/stylingDetection.d.ts.map +1 -0
- package/src/components/GlobalImageEditor/stylingDetection.ts +122 -0
- package/src/components/GlobalImageEditor/transformParsing.d.ts +16 -0
- package/src/components/GlobalImageEditor/transformParsing.d.ts.map +1 -0
- package/src/components/GlobalImageEditor/transformParsing.ts +83 -0
- package/src/components/GlobalImageEditor/types.d.ts +36 -0
- package/src/components/GlobalImageEditor/types.d.ts.map +1 -0
- package/src/components/GlobalImageEditor/types.ts +39 -0
- package/src/components/GlobalImageEditor.d.ts +8 -0
- package/src/components/GlobalImageEditor.d.ts.map +1 -0
- package/src/components/GlobalImageEditor.tsx +327 -0
- package/src/components/Image.d.ts +22 -0
- package/src/components/Image.d.ts.map +1 -0
- package/src/components/Image.tsx +343 -0
- package/src/components/ImageBrowserModal.d.ts +13 -0
- package/src/components/ImageBrowserModal.d.ts.map +1 -0
- package/src/components/ImageBrowserModal.tsx +837 -0
- package/src/components/ImageEditor.d.ts +27 -0
- package/src/components/ImageEditor.d.ts.map +1 -0
- package/src/components/ImageEditor.tsx +323 -0
- package/src/components/ImageEffectsPanel.tsx +116 -0
- package/src/components/ImagePicker.d.ts +3 -0
- package/src/components/ImagePicker.d.ts.map +1 -0
- package/src/components/ImagePicker.tsx +265 -0
- package/src/components/ImagesPluginInit.d.ts +24 -0
- package/src/components/ImagesPluginInit.d.ts.map +1 -0
- package/src/components/ImagesPluginInit.tsx +31 -0
- package/src/components/index.ts +10 -0
- package/src/config.ts +179 -0
- package/src/hooks/useImagePicker.d.ts +20 -0
- package/src/hooks/useImagePicker.d.ts.map +1 -0
- package/src/hooks/useImagePicker.ts +344 -0
- package/src/index.server.ts +12 -0
- package/src/index.tsx +56 -0
- package/src/init.tsx +58 -0
- package/src/types/index.d.ts +80 -0
- package/src/types/index.d.ts.map +1 -0
- package/src/types/index.ts +84 -0
- package/src/utils/fallback.d.ts +27 -0
- package/src/utils/fallback.d.ts.map +1 -0
- package/src/utils/fallback.ts +73 -0
- package/src/utils/transforms.d.ts +26 -0
- package/src/utils/transforms.d.ts.map +1 -0
- package/src/utils/transforms.ts +54 -0
- package/src/views/ImageManager.d.ts +10 -0
- package/src/views/ImageManager.d.ts.map +1 -0
- package/src/views/ImageManager.tsx +30 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for Image Picker Logic
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { useState, useEffect, useRef } from 'react';
|
|
6
|
+
import type { ImageMetadata } from '../types';
|
|
7
|
+
|
|
8
|
+
export interface UseImagePickerOptions {
|
|
9
|
+
value?: string;
|
|
10
|
+
images: ImageMetadata[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useImagePicker({ value, images }: UseImagePickerOptions) {
|
|
14
|
+
const [selectedImage, setSelectedImage] = useState<ImageMetadata | null>(null);
|
|
15
|
+
const [uploading, setUploading] = useState(false);
|
|
16
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
17
|
+
const lastResolvedValueRef = useRef<string | undefined>(undefined);
|
|
18
|
+
const isResolvingRef = useRef(false);
|
|
19
|
+
const lastImagesRef = useRef<string>('');
|
|
20
|
+
|
|
21
|
+
// Find selected image from value (can be ID or URL)
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
// Create a stable reference for images array to detect actual changes
|
|
24
|
+
const imagesKey = JSON.stringify(images.map(img => ({ id: img.id, url: img.url })));
|
|
25
|
+
|
|
26
|
+
// Prevent infinite loops by checking if we're already resolving or if value and images haven't changed
|
|
27
|
+
if (isResolvingRef.current || (lastResolvedValueRef.current === value && lastImagesRef.current === imagesKey)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
lastImagesRef.current = imagesKey;
|
|
32
|
+
|
|
33
|
+
if (!value) {
|
|
34
|
+
if (selectedImage !== null) {
|
|
35
|
+
setSelectedImage(null);
|
|
36
|
+
}
|
|
37
|
+
lastResolvedValueRef.current = value;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
isResolvingRef.current = true;
|
|
42
|
+
const resolveImage = async () => {
|
|
43
|
+
// Normalize the value - extract filename if it's a URL
|
|
44
|
+
const isFullUrl = value.startsWith('http://') || value.startsWith('https://');
|
|
45
|
+
const isRelativeUrl = value.startsWith('/');
|
|
46
|
+
const isUrl = isFullUrl || isRelativeUrl;
|
|
47
|
+
|
|
48
|
+
// Extract filename from URL if it's a URL
|
|
49
|
+
let filenameFromUrl: string | null = null;
|
|
50
|
+
let imageIdToResolve = value;
|
|
51
|
+
|
|
52
|
+
if (isUrl) {
|
|
53
|
+
const urlParts = value.split('/');
|
|
54
|
+
filenameFromUrl = urlParts[urlParts.length - 1]?.split('?')[0] || null;
|
|
55
|
+
// If it's a full URL, try to resolve using the filename instead
|
|
56
|
+
if (isFullUrl && filenameFromUrl) {
|
|
57
|
+
imageIdToResolve = filenameFromUrl;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// First, try to find by ID (preferred method)
|
|
62
|
+
let found = images.find(img => img.id === value || img.id === imageIdToResolve);
|
|
63
|
+
|
|
64
|
+
// If not found by ID, try to find by URL
|
|
65
|
+
if (!found) {
|
|
66
|
+
found = images.find(img => img.url === value);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// If still not found, try to match by filename extracted from URL
|
|
70
|
+
if (!found && filenameFromUrl) {
|
|
71
|
+
found = images.find(img => img.id === filenameFromUrl || img.filename === filenameFromUrl);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (found) {
|
|
75
|
+
// Only update if the image is actually different
|
|
76
|
+
setSelectedImage(prev => {
|
|
77
|
+
if (prev?.id === found.id && prev?.url === found.url) {
|
|
78
|
+
return prev;
|
|
79
|
+
}
|
|
80
|
+
return found;
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
// If value is already a full URL, use it directly
|
|
84
|
+
if (isFullUrl) {
|
|
85
|
+
const newImage = {
|
|
86
|
+
id: value,
|
|
87
|
+
filename: filenameFromUrl || value,
|
|
88
|
+
url: value, // Use the full URL as-is
|
|
89
|
+
size: 0,
|
|
90
|
+
mimeType: 'image/jpeg',
|
|
91
|
+
uploadedAt: new Date().toISOString(),
|
|
92
|
+
};
|
|
93
|
+
setSelectedImage(prev => {
|
|
94
|
+
if (prev?.id === newImage.id && prev?.url === newImage.url) {
|
|
95
|
+
return prev;
|
|
96
|
+
}
|
|
97
|
+
return newImage;
|
|
98
|
+
});
|
|
99
|
+
lastResolvedValueRef.current = value;
|
|
100
|
+
isResolvingRef.current = false;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// If value is a relative URL, use it directly
|
|
105
|
+
if (isRelativeUrl) {
|
|
106
|
+
const newImage = {
|
|
107
|
+
id: value,
|
|
108
|
+
filename: filenameFromUrl || value,
|
|
109
|
+
url: value, // Use the relative URL as-is
|
|
110
|
+
size: 0,
|
|
111
|
+
mimeType: 'image/jpeg',
|
|
112
|
+
uploadedAt: new Date().toISOString(),
|
|
113
|
+
};
|
|
114
|
+
setSelectedImage(prev => {
|
|
115
|
+
if (prev?.id === newImage.id && prev?.url === newImage.url) {
|
|
116
|
+
return prev;
|
|
117
|
+
}
|
|
118
|
+
return newImage;
|
|
119
|
+
});
|
|
120
|
+
lastResolvedValueRef.current = value;
|
|
121
|
+
isResolvingRef.current = false;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Check if value looks like a filename (has extension or starts with digits)
|
|
126
|
+
const isLikelyPath = /\.(jpg|jpeg|png|webp|gif|svg)$/i.test(value) || /^\d+-/.test(value);
|
|
127
|
+
|
|
128
|
+
if (isLikelyPath) {
|
|
129
|
+
// It's likely a filename, create image object directly
|
|
130
|
+
const newImage = {
|
|
131
|
+
id: value,
|
|
132
|
+
filename: value,
|
|
133
|
+
url: `/api/uploads/${value}`,
|
|
134
|
+
size: 0,
|
|
135
|
+
mimeType: 'image/jpeg',
|
|
136
|
+
uploadedAt: new Date().toISOString(),
|
|
137
|
+
};
|
|
138
|
+
setSelectedImage(prev => {
|
|
139
|
+
if (prev?.id === newImage.id && prev?.url === newImage.url) {
|
|
140
|
+
return prev;
|
|
141
|
+
}
|
|
142
|
+
return newImage;
|
|
143
|
+
});
|
|
144
|
+
lastResolvedValueRef.current = value;
|
|
145
|
+
isResolvingRef.current = false;
|
|
146
|
+
} else {
|
|
147
|
+
// It might be a semantic ID, try to resolve via API
|
|
148
|
+
// Use the extracted ID (filename) if value was a URL, otherwise use value
|
|
149
|
+
try {
|
|
150
|
+
const response = await fetch(`/api/plugin-images/resolve?id=${encodeURIComponent(imageIdToResolve)}`);
|
|
151
|
+
if (response.ok) {
|
|
152
|
+
const data = await response.json();
|
|
153
|
+
// Normalize the URL - ensure it's a proper URL
|
|
154
|
+
let imageUrl: string;
|
|
155
|
+
if (data.url) {
|
|
156
|
+
// If API returns a URL, use it (but check if it's already a full URL)
|
|
157
|
+
if (data.url.startsWith('http://') || data.url.startsWith('https://')) {
|
|
158
|
+
imageUrl = data.url;
|
|
159
|
+
} else if (data.url.startsWith('/')) {
|
|
160
|
+
imageUrl = data.url;
|
|
161
|
+
} else {
|
|
162
|
+
// Relative path without leading slash
|
|
163
|
+
imageUrl = `/api/uploads/${data.url}`;
|
|
164
|
+
}
|
|
165
|
+
} else if (data.filename) {
|
|
166
|
+
// Use filename to construct URL
|
|
167
|
+
imageUrl = `/api/uploads/${data.filename}`;
|
|
168
|
+
} else {
|
|
169
|
+
// Fallback: if original value was a URL, use it; otherwise construct
|
|
170
|
+
imageUrl = isFullUrl ? value : (isRelativeUrl ? value : `/api/uploads/${value}`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const newImage = {
|
|
174
|
+
id: value,
|
|
175
|
+
filename: data.filename || filenameFromUrl || value,
|
|
176
|
+
url: imageUrl,
|
|
177
|
+
size: 0,
|
|
178
|
+
mimeType: 'image/jpeg',
|
|
179
|
+
uploadedAt: new Date().toISOString(),
|
|
180
|
+
};
|
|
181
|
+
setSelectedImage(prev => {
|
|
182
|
+
if (prev?.id === newImage.id && prev?.url === newImage.url) {
|
|
183
|
+
return prev;
|
|
184
|
+
}
|
|
185
|
+
return newImage;
|
|
186
|
+
});
|
|
187
|
+
lastResolvedValueRef.current = value;
|
|
188
|
+
isResolvingRef.current = false;
|
|
189
|
+
} else {
|
|
190
|
+
// API resolution failed - check if it's a semantic ID or actual filename
|
|
191
|
+
const isLikelyFilename = /\.(jpg|jpeg|png|webp|gif|svg)$/i.test(imageIdToResolve) || /^\d+-/.test(imageIdToResolve);
|
|
192
|
+
|
|
193
|
+
if (!isLikelyFilename) {
|
|
194
|
+
// It's a semantic ID that couldn't be resolved - clear selection
|
|
195
|
+
// This prevents showing broken URLs like /api/uploads/blog-featured-...
|
|
196
|
+
setSelectedImage(null);
|
|
197
|
+
lastResolvedValueRef.current = value;
|
|
198
|
+
isResolvingRef.current = false;
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// It's a filename, create fallback object
|
|
203
|
+
const isFullUrl = value.startsWith('http://') || value.startsWith('https://');
|
|
204
|
+
const isRelativeUrl = value.startsWith('/');
|
|
205
|
+
|
|
206
|
+
let imageUrl: string;
|
|
207
|
+
if (isFullUrl) {
|
|
208
|
+
// Already a full URL, use as-is
|
|
209
|
+
imageUrl = value;
|
|
210
|
+
} else if (isRelativeUrl) {
|
|
211
|
+
// Already a relative URL starting with /, use as-is
|
|
212
|
+
imageUrl = value;
|
|
213
|
+
} else {
|
|
214
|
+
// It's a filename, construct the URL
|
|
215
|
+
imageUrl = `/api/uploads/${value}`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const urlParts = value.split('/');
|
|
219
|
+
const filename = urlParts[urlParts.length - 1]?.split('?')[0] || value;
|
|
220
|
+
|
|
221
|
+
const newImage = {
|
|
222
|
+
id: value,
|
|
223
|
+
filename: filename,
|
|
224
|
+
url: imageUrl,
|
|
225
|
+
size: 0,
|
|
226
|
+
mimeType: 'image/jpeg',
|
|
227
|
+
uploadedAt: new Date().toISOString(),
|
|
228
|
+
};
|
|
229
|
+
setSelectedImage(prev => {
|
|
230
|
+
if (prev?.id === newImage.id && prev?.url === newImage.url) {
|
|
231
|
+
return prev;
|
|
232
|
+
}
|
|
233
|
+
return newImage;
|
|
234
|
+
});
|
|
235
|
+
lastResolvedValueRef.current = value;
|
|
236
|
+
isResolvingRef.current = false;
|
|
237
|
+
}
|
|
238
|
+
} catch (error) {
|
|
239
|
+
// API call failed - check if it's a semantic ID or actual filename
|
|
240
|
+
const isLikelyFilename = /\.(jpg|jpeg|png|webp|gif|svg)$/i.test(imageIdToResolve) || /^\d+-/.test(imageIdToResolve);
|
|
241
|
+
|
|
242
|
+
if (!isLikelyFilename) {
|
|
243
|
+
// It's a semantic ID that couldn't be resolved - clear selection
|
|
244
|
+
// This prevents showing broken URLs like /api/uploads/blog-featured-...
|
|
245
|
+
setSelectedImage(null);
|
|
246
|
+
lastResolvedValueRef.current = value;
|
|
247
|
+
isResolvingRef.current = false;
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// It's a filename, create fallback object
|
|
252
|
+
const isFullUrl = value.startsWith('http://') || value.startsWith('https://');
|
|
253
|
+
const isRelativeUrl = value.startsWith('/');
|
|
254
|
+
|
|
255
|
+
let imageUrl: string;
|
|
256
|
+
if (isFullUrl) {
|
|
257
|
+
// Already a full URL, use as-is
|
|
258
|
+
imageUrl = value;
|
|
259
|
+
} else if (isRelativeUrl) {
|
|
260
|
+
// Already a relative URL starting with /, use as-is
|
|
261
|
+
imageUrl = value;
|
|
262
|
+
} else {
|
|
263
|
+
// It's a filename, construct the URL
|
|
264
|
+
imageUrl = `/api/uploads/${value}`;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const urlParts = value.split('/');
|
|
268
|
+
const filename = urlParts[urlParts.length - 1]?.split('?')[0] || value;
|
|
269
|
+
|
|
270
|
+
const newImage = {
|
|
271
|
+
id: value,
|
|
272
|
+
filename: filename,
|
|
273
|
+
url: imageUrl,
|
|
274
|
+
size: 0,
|
|
275
|
+
mimeType: 'image/jpeg',
|
|
276
|
+
uploadedAt: new Date().toISOString(),
|
|
277
|
+
};
|
|
278
|
+
setSelectedImage(prev => {
|
|
279
|
+
if (prev?.id === newImage.id && prev?.url === newImage.url) {
|
|
280
|
+
return prev;
|
|
281
|
+
}
|
|
282
|
+
return newImage;
|
|
283
|
+
});
|
|
284
|
+
lastResolvedValueRef.current = value;
|
|
285
|
+
isResolvingRef.current = false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
resolveImage().catch(() => {
|
|
292
|
+
// Error already handled in catch block
|
|
293
|
+
isResolvingRef.current = false;
|
|
294
|
+
});
|
|
295
|
+
}, [value, images]);
|
|
296
|
+
|
|
297
|
+
// Handle file upload
|
|
298
|
+
const handleFileSelect = async (e?: React.ChangeEvent<HTMLInputElement> | { target: { files: File[] | null } }) => {
|
|
299
|
+
const file = e?.target?.files?.[0];
|
|
300
|
+
if (!file) return null;
|
|
301
|
+
|
|
302
|
+
setUploading(true);
|
|
303
|
+
try {
|
|
304
|
+
const formData = new FormData();
|
|
305
|
+
formData.append('file', file);
|
|
306
|
+
|
|
307
|
+
const response = await fetch('/api/plugin-images/upload', {
|
|
308
|
+
method: 'POST',
|
|
309
|
+
body: formData,
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
const data = await response.json();
|
|
313
|
+
|
|
314
|
+
if (data.success && data.image) {
|
|
315
|
+
// Select the newly uploaded image
|
|
316
|
+
setSelectedImage(data.image);
|
|
317
|
+
if (fileInputRef.current) {
|
|
318
|
+
fileInputRef.current.value = '';
|
|
319
|
+
}
|
|
320
|
+
return data.image;
|
|
321
|
+
} else {
|
|
322
|
+
alert(data.error || 'Failed to upload image');
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error('Upload error:', error);
|
|
327
|
+
alert('Failed to upload image');
|
|
328
|
+
return null;
|
|
329
|
+
} finally {
|
|
330
|
+
setUploading(false);
|
|
331
|
+
if (fileInputRef.current) {
|
|
332
|
+
fileInputRef.current.value = '';
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
return {
|
|
338
|
+
selectedImage,
|
|
339
|
+
setSelectedImage,
|
|
340
|
+
uploading,
|
|
341
|
+
fileInputRef,
|
|
342
|
+
handleFileSelect,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
/**
|
|
3
|
+
* Plugin Images - Server-Only Entry Point
|
|
4
|
+
* This file exports only server-side API handlers
|
|
5
|
+
* Used by the dynamic plugin router via @jhits/plugin-images/server
|
|
6
|
+
*
|
|
7
|
+
* Note: This file is server-only (no 'use server' needed - that's only for Server Actions)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { handleImagesApi as handleApi } from './api/router';
|
|
11
|
+
export { handleImagesApi } from './api/router'; // Keep original export for backward compatibility
|
|
12
|
+
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Images - Main Entry Point
|
|
3
|
+
* Image management plugin for uploading, searching, and managing images
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use client';
|
|
7
|
+
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { ImageManagerView } from './views/ImageManager';
|
|
10
|
+
|
|
11
|
+
export interface PluginProps {
|
|
12
|
+
subPath: string[];
|
|
13
|
+
siteId: string;
|
|
14
|
+
locale: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default function ImagesPlugin({ subPath, siteId, locale }: PluginProps) {
|
|
18
|
+
const route = subPath[0] || 'manager';
|
|
19
|
+
|
|
20
|
+
switch (route) {
|
|
21
|
+
case 'manager':
|
|
22
|
+
return <ImageManagerView siteId={siteId} locale={locale} />;
|
|
23
|
+
|
|
24
|
+
default:
|
|
25
|
+
return <ImageManagerView siteId={siteId} locale={locale} />;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Export for use as default
|
|
30
|
+
export { ImagesPlugin as Index };
|
|
31
|
+
|
|
32
|
+
// Export components for use in other plugins
|
|
33
|
+
export { ImagePicker } from './components/ImagePicker';
|
|
34
|
+
export { GlobalImageEditor } from './components/GlobalImageEditor';
|
|
35
|
+
export { ImagesPluginInit } from './components/ImagesPluginInit';
|
|
36
|
+
export { Image } from './components/Image';
|
|
37
|
+
export { BackgroundImage } from './components/BackgroundImage';
|
|
38
|
+
export type { ImagePickerProps, ImageMetadata } from './types';
|
|
39
|
+
export type { PluginImageProps } from './components/Image';
|
|
40
|
+
export type { BackgroundImageProps } from './components/BackgroundImage';
|
|
41
|
+
|
|
42
|
+
// Export initialization utility
|
|
43
|
+
export { initImagesPlugin } from './init';
|
|
44
|
+
export type { ImagesPluginConfig } from './init';
|
|
45
|
+
|
|
46
|
+
// Export utility functions
|
|
47
|
+
export {
|
|
48
|
+
getFallbackImageUrl,
|
|
49
|
+
isValidImageUrl,
|
|
50
|
+
getSafeImageUrl,
|
|
51
|
+
constructImageUrl
|
|
52
|
+
} from './utils/fallback';
|
|
53
|
+
|
|
54
|
+
// Note: API handlers are server-only and exported from ./index.ts (server entry point)
|
|
55
|
+
// They are NOT exported here to prevent client/server context mixing
|
|
56
|
+
|
package/src/init.tsx
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Images Plugin Initialization Utility
|
|
3
|
+
*
|
|
4
|
+
* Simple function to initialize the images plugin with client configuration.
|
|
5
|
+
* Call this once in your app (e.g., in root layout) to enable global image editing.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { initImagesPlugin } from '@jhits/plugin-images/init';
|
|
10
|
+
* import { imagesConfig } from '@/plugins/images-config';
|
|
11
|
+
*
|
|
12
|
+
* // Call once when your app loads
|
|
13
|
+
* initImagesPlugin(imagesConfig);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
'use client';
|
|
18
|
+
|
|
19
|
+
export interface ImagesPluginConfig {
|
|
20
|
+
/** Enable global image editor (default: true) */
|
|
21
|
+
enabled?: boolean;
|
|
22
|
+
/** Custom styling for the editor modal */
|
|
23
|
+
className?: string;
|
|
24
|
+
/** Custom styling for the modal overlay */
|
|
25
|
+
overlayClassName?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Initialize the images plugin with client configuration
|
|
30
|
+
*
|
|
31
|
+
* This function sets up the window global that the plugin reads from automatically.
|
|
32
|
+
* Call this once when your app loads, before the plugin component is rendered.
|
|
33
|
+
*
|
|
34
|
+
* @param config - Images plugin configuration (enabled, styling, etc.)
|
|
35
|
+
*/
|
|
36
|
+
export function initImagesPlugin(config?: ImagesPluginConfig): void {
|
|
37
|
+
if (typeof window === 'undefined') {
|
|
38
|
+
// Server-side: no-op
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Initialize the global plugin props object if it doesn't exist
|
|
43
|
+
if (!(window as any).__JHITS_PLUGIN_PROPS__) {
|
|
44
|
+
(window as any).__JHITS_PLUGIN_PROPS__ = {};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Set images plugin configuration
|
|
48
|
+
(window as any).__JHITS_PLUGIN_PROPS__['plugin-images'] = {
|
|
49
|
+
enabled: config?.enabled !== undefined ? config.enabled : true,
|
|
50
|
+
className: config?.className,
|
|
51
|
+
overlayClassName: config?.overlayClassName,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
console.log('[ImagesPlugin] Initialized with config:', {
|
|
55
|
+
enabled: config?.enabled !== undefined ? config.enabled : true,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Plugin Types
|
|
3
|
+
*/
|
|
4
|
+
export interface ImageMetadata {
|
|
5
|
+
/** Unique image ID */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Original filename */
|
|
8
|
+
filename: string;
|
|
9
|
+
/** File path/URL */
|
|
10
|
+
url: string;
|
|
11
|
+
/** File size in bytes */
|
|
12
|
+
size: number;
|
|
13
|
+
/** MIME type */
|
|
14
|
+
mimeType: string;
|
|
15
|
+
/** Image dimensions */
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
/** Alt text */
|
|
19
|
+
alt?: string;
|
|
20
|
+
/** Upload timestamp */
|
|
21
|
+
uploadedAt: string;
|
|
22
|
+
/** Uploaded by user ID */
|
|
23
|
+
uploadedBy?: string;
|
|
24
|
+
/** Tags for searching */
|
|
25
|
+
tags?: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface ImageUploadResponse {
|
|
28
|
+
success: boolean;
|
|
29
|
+
image?: ImageMetadata;
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ImageListResponse {
|
|
33
|
+
images: ImageMetadata[];
|
|
34
|
+
total: number;
|
|
35
|
+
page: number;
|
|
36
|
+
limit: number;
|
|
37
|
+
}
|
|
38
|
+
export interface ImagePickerProps {
|
|
39
|
+
/** Current selected image URL */
|
|
40
|
+
value?: string;
|
|
41
|
+
/** Callback when image is selected */
|
|
42
|
+
onChange: (image: ImageMetadata | null) => void;
|
|
43
|
+
/** Whether dark mode is enabled */
|
|
44
|
+
darkMode?: boolean;
|
|
45
|
+
/** Show brightness and blur controls */
|
|
46
|
+
showEffects?: boolean;
|
|
47
|
+
/** Current brightness value (0-200, 100 = normal) */
|
|
48
|
+
brightness?: number;
|
|
49
|
+
/** Current blur value (0-20) */
|
|
50
|
+
blur?: number;
|
|
51
|
+
/** Current scale value (0.1-3.0, 1.0 = normal) */
|
|
52
|
+
scale?: number;
|
|
53
|
+
/** Current X position offset (-100 to 100, 0 = center) */
|
|
54
|
+
positionX?: number;
|
|
55
|
+
/** Current Y position offset (-100 to 100, 0 = center) */
|
|
56
|
+
positionY?: number;
|
|
57
|
+
/** Aspect ratio for preview/editor (e.g., "4/5", "3/4", "16/9", "1/1") */
|
|
58
|
+
aspectRatio?: string;
|
|
59
|
+
/** Border radius class (e.g., "rounded-xl", "rounded-3xl") */
|
|
60
|
+
borderRadius?: string;
|
|
61
|
+
/** Object fit style (e.g., "cover", "contain") */
|
|
62
|
+
objectFit?: 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
|
|
63
|
+
/** Object position (e.g., "center", "top", "bottom") */
|
|
64
|
+
objectPosition?: string;
|
|
65
|
+
/** Callback when brightness changes */
|
|
66
|
+
onBrightnessChange?: (brightness: number) => void;
|
|
67
|
+
/** Callback when blur changes */
|
|
68
|
+
onBlurChange?: (blur: number) => void;
|
|
69
|
+
/** Callback when scale changes */
|
|
70
|
+
onScaleChange?: (scale: number) => void;
|
|
71
|
+
/** Callback when X position changes */
|
|
72
|
+
onPositionXChange?: (positionX: number) => void;
|
|
73
|
+
/** Callback when Y position changes */
|
|
74
|
+
onPositionYChange?: (positionY: number) => void;
|
|
75
|
+
/** Callback when editor "Done" button is clicked - triggers immediate save */
|
|
76
|
+
onEditorSave?: (scale: number, positionX: number, positionY: number, brightness?: number, blur?: number) => void;
|
|
77
|
+
/** Automatically open the editor when component mounts (useful for modal scenarios) */
|
|
78
|
+
autoOpenEditor?: boolean;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,aAAa;IAC1B,sBAAsB;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,wBAAwB;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,uBAAuB;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yBAAyB;IACzB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC7B,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,mCAAmC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;IACjE,wDAAwD;IACxD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,iCAAiC;IACjC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,kCAAkC;IAClC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,uCAAuC;IACvC,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,uCAAuC;IACvC,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,8EAA8E;IAC9E,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjH,uFAAuF;IACvF,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Plugin Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface ImageMetadata {
|
|
6
|
+
/** Unique image ID */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Original filename */
|
|
9
|
+
filename: string;
|
|
10
|
+
/** File path/URL */
|
|
11
|
+
url: string;
|
|
12
|
+
/** File size in bytes */
|
|
13
|
+
size: number;
|
|
14
|
+
/** MIME type */
|
|
15
|
+
mimeType: string;
|
|
16
|
+
/** Image dimensions */
|
|
17
|
+
width?: number;
|
|
18
|
+
height?: number;
|
|
19
|
+
/** Alt text */
|
|
20
|
+
alt?: string;
|
|
21
|
+
/** Upload timestamp */
|
|
22
|
+
uploadedAt: string;
|
|
23
|
+
/** Uploaded by user ID */
|
|
24
|
+
uploadedBy?: string;
|
|
25
|
+
/** Tags for searching */
|
|
26
|
+
tags?: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ImageUploadResponse {
|
|
30
|
+
success: boolean;
|
|
31
|
+
image?: ImageMetadata;
|
|
32
|
+
error?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ImageListResponse {
|
|
36
|
+
images: ImageMetadata[];
|
|
37
|
+
total: number;
|
|
38
|
+
page: number;
|
|
39
|
+
limit: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ImagePickerProps {
|
|
43
|
+
/** Current selected image URL */
|
|
44
|
+
value?: string;
|
|
45
|
+
/** Callback when image is selected */
|
|
46
|
+
onChange: (image: ImageMetadata | null) => void;
|
|
47
|
+
/** Whether dark mode is enabled */
|
|
48
|
+
darkMode?: boolean;
|
|
49
|
+
/** Show brightness and blur controls */
|
|
50
|
+
showEffects?: boolean;
|
|
51
|
+
/** Current brightness value (0-200, 100 = normal) */
|
|
52
|
+
brightness?: number;
|
|
53
|
+
/** Current blur value (0-20) */
|
|
54
|
+
blur?: number;
|
|
55
|
+
/** Current scale value (0.1-3.0, 1.0 = normal) */
|
|
56
|
+
scale?: number;
|
|
57
|
+
/** Current X position offset (-100 to 100, 0 = center) */
|
|
58
|
+
positionX?: number;
|
|
59
|
+
/** Current Y position offset (-100 to 100, 0 = center) */
|
|
60
|
+
positionY?: number;
|
|
61
|
+
/** Aspect ratio for preview/editor (e.g., "4/5", "3/4", "16/9", "1/1") */
|
|
62
|
+
aspectRatio?: string;
|
|
63
|
+
/** Border radius class (e.g., "rounded-xl", "rounded-3xl") */
|
|
64
|
+
borderRadius?: string;
|
|
65
|
+
/** Object fit style (e.g., "cover", "contain") */
|
|
66
|
+
objectFit?: 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
|
|
67
|
+
/** Object position (e.g., "center", "top", "bottom") */
|
|
68
|
+
objectPosition?: string;
|
|
69
|
+
/** Callback when brightness changes */
|
|
70
|
+
onBrightnessChange?: (brightness: number) => void;
|
|
71
|
+
/** Callback when blur changes */
|
|
72
|
+
onBlurChange?: (blur: number) => void;
|
|
73
|
+
/** Callback when scale changes */
|
|
74
|
+
onScaleChange?: (scale: number) => void;
|
|
75
|
+
/** Callback when X position changes */
|
|
76
|
+
onPositionXChange?: (positionX: number) => void;
|
|
77
|
+
/** Callback when Y position changes */
|
|
78
|
+
onPositionYChange?: (positionY: number) => void;
|
|
79
|
+
/** Callback when editor "Done" button is clicked - triggers immediate save */
|
|
80
|
+
onEditorSave?: (scale: number, positionX: number, positionY: number, brightness?: number, blur?: number) => void;
|
|
81
|
+
/** Automatically open the editor when component mounts (useful for modal scenarios) */
|
|
82
|
+
autoOpenEditor?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fallback image utility
|
|
3
|
+
* Provides a default fallback image URL when images fail to load or are invalid
|
|
4
|
+
* Also handles URL construction for image filenames
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Returns the URL for the fallback "image not found" image
|
|
8
|
+
* Served from the plugin's API route
|
|
9
|
+
*/
|
|
10
|
+
export declare function getFallbackImageUrl(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Constructs the full image URL from a filename or URL
|
|
13
|
+
* - If it's already a full URL (http://, https://, or starts with /), returns as-is
|
|
14
|
+
* - If it's a filename, constructs `/api/uploads/${filename}`
|
|
15
|
+
*/
|
|
16
|
+
export declare function constructImageUrl(src: string | null | undefined): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Validates if a URL is valid and can be used with Next.js Image component
|
|
19
|
+
*/
|
|
20
|
+
export declare function isValidImageUrl(url: string | null | undefined): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Gets a safe image URL with automatic URL construction and fallback
|
|
23
|
+
* - Constructs the full URL if src is a filename
|
|
24
|
+
* - Falls back to the plugin's fallback image if invalid or missing
|
|
25
|
+
*/
|
|
26
|
+
export declare function getSafeImageUrl(src: string | null | undefined): string;
|
|
27
|
+
//# sourceMappingURL=fallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback.d.ts","sourceRoot":"","sources":["fallback.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAY/E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAkBvE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAUtE"}
|