@caprionlinesrl/puck-plugin-media 0.1.4 → 0.1.5
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/README.md +51 -0
- package/dist/index.d.mts +4 -349
- package/dist/index.d.ts +4 -349
- package/dist/mocks/index.d.mts +41 -0
- package/dist/mocks/index.d.ts +41 -0
- package/dist/mocks/index.js +557 -0
- package/dist/mocks/index.js.map +1 -0
- package/dist/mocks/index.mjs +533 -0
- package/dist/mocks/index.mjs.map +1 -0
- package/dist/types-DTNDlwYP.d.mts +350 -0
- package/dist/types-DTNDlwYP.d.ts +350 -0
- package/package.json +6 -1
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Language configuration for multilingual fields
|
|
5
|
+
*/
|
|
6
|
+
interface Language {
|
|
7
|
+
code: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Default languages when not specified
|
|
12
|
+
*/
|
|
13
|
+
declare const DEFAULT_LANGUAGES: Language[];
|
|
14
|
+
/**
|
|
15
|
+
* Localized string value (e.g., { en: 'Hello', it: 'Ciao' })
|
|
16
|
+
*/
|
|
17
|
+
type LocalizedString = Record<string, string | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Image item - used both for API responses and stored values in Puck JSON
|
|
20
|
+
*/
|
|
21
|
+
interface ImageItem {
|
|
22
|
+
/** Unique identifier */
|
|
23
|
+
id: string;
|
|
24
|
+
/** Full URL to the image file */
|
|
25
|
+
url: string;
|
|
26
|
+
/** Original filename */
|
|
27
|
+
filename?: string;
|
|
28
|
+
/** Alt text (multilingual) */
|
|
29
|
+
alt?: LocalizedString;
|
|
30
|
+
/** Image width in pixels */
|
|
31
|
+
width?: number;
|
|
32
|
+
/** Image height in pixels */
|
|
33
|
+
height?: number;
|
|
34
|
+
/** File size in bytes */
|
|
35
|
+
size?: number;
|
|
36
|
+
/** Thumbnail URL for faster loading in picker (falls back to url if not provided) */
|
|
37
|
+
thumbnailUrl?: string;
|
|
38
|
+
/** Creation date (useful for cache invalidation) */
|
|
39
|
+
createdAt?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Document item - used both for API responses and stored values in Puck JSON
|
|
43
|
+
*/
|
|
44
|
+
interface DocumentItem {
|
|
45
|
+
/** Unique identifier */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Full URL to the document file */
|
|
48
|
+
url: string;
|
|
49
|
+
/** Original filename */
|
|
50
|
+
filename: string;
|
|
51
|
+
/** Display title (multilingual) */
|
|
52
|
+
title?: LocalizedString;
|
|
53
|
+
/** MIME type (e.g., 'application/pdf') */
|
|
54
|
+
mimeType: string;
|
|
55
|
+
/** File size in bytes */
|
|
56
|
+
size: number;
|
|
57
|
+
/** File extension (e.g., 'pdf', 'docx') */
|
|
58
|
+
extension: string;
|
|
59
|
+
/** Creation date (useful for cache invalidation) */
|
|
60
|
+
createdAt?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gallery item - used both for API responses and stored values in Puck JSON
|
|
64
|
+
*/
|
|
65
|
+
interface GalleryItem {
|
|
66
|
+
/** Unique identifier */
|
|
67
|
+
id: string;
|
|
68
|
+
/** Gallery name */
|
|
69
|
+
name: string;
|
|
70
|
+
/** Cover image for preview */
|
|
71
|
+
coverImage?: ImageItem;
|
|
72
|
+
/** Images in the gallery */
|
|
73
|
+
images: ImageItem[];
|
|
74
|
+
/** Number of images in the gallery (optional, can be calculated from images.length) */
|
|
75
|
+
imageCount?: number;
|
|
76
|
+
/** Creation date (useful for cache invalidation) */
|
|
77
|
+
createdAt?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Parameters passed to fetchList functions
|
|
81
|
+
*/
|
|
82
|
+
interface FetchListParams {
|
|
83
|
+
/** Search query string */
|
|
84
|
+
query?: string;
|
|
85
|
+
/** Page number (1-indexed) */
|
|
86
|
+
page?: number;
|
|
87
|
+
/** Items per page */
|
|
88
|
+
pageSize?: number;
|
|
89
|
+
/** Additional filters */
|
|
90
|
+
filters?: Record<string, unknown>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Result from fetchList - paginated result
|
|
94
|
+
*/
|
|
95
|
+
interface FetchListResult<T> {
|
|
96
|
+
/** Array of items */
|
|
97
|
+
items: T[];
|
|
98
|
+
/** Total number of items (for pagination) */
|
|
99
|
+
total?: number;
|
|
100
|
+
/** Whether there are more items to load */
|
|
101
|
+
hasMore?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Generic fetch list function type
|
|
105
|
+
*/
|
|
106
|
+
type FetchListFn<T> = (params: FetchListParams) => Promise<T[] | FetchListResult<T>>;
|
|
107
|
+
/**
|
|
108
|
+
* Callbacks passed to upload functions
|
|
109
|
+
*/
|
|
110
|
+
interface UploadCallbacks {
|
|
111
|
+
/** Called with upload progress (0-100) */
|
|
112
|
+
onProgress: (percent: number) => void;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Upload function that handles single or multiple files
|
|
116
|
+
*/
|
|
117
|
+
type UploadFn<T> = (files: File | File[], callbacks: UploadCallbacks) => Promise<T | T[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Configuration for file uploads
|
|
120
|
+
*/
|
|
121
|
+
interface UploadConfig {
|
|
122
|
+
/**
|
|
123
|
+
* Accepted file types (MIME types or extensions)
|
|
124
|
+
* @default 'image/*' for images, '*' for documents
|
|
125
|
+
*/
|
|
126
|
+
accept?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Maximum file size in bytes
|
|
129
|
+
* @default 10485760 (10MB)
|
|
130
|
+
*/
|
|
131
|
+
maxSize?: number;
|
|
132
|
+
/**
|
|
133
|
+
* Allow multiple file uploads
|
|
134
|
+
* @default true
|
|
135
|
+
*/
|
|
136
|
+
multiple?: boolean;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Status of a file being uploaded
|
|
140
|
+
*/
|
|
141
|
+
type UploadStatus = 'pending' | 'uploading' | 'completed' | 'error';
|
|
142
|
+
/**
|
|
143
|
+
* State of a file in the upload queue
|
|
144
|
+
*/
|
|
145
|
+
interface UploadingFile {
|
|
146
|
+
/** Unique ID for this upload */
|
|
147
|
+
id: string;
|
|
148
|
+
/** The file being uploaded */
|
|
149
|
+
file: File;
|
|
150
|
+
/** Upload progress (0-100) */
|
|
151
|
+
progress: number;
|
|
152
|
+
/** Current upload status */
|
|
153
|
+
status: UploadStatus;
|
|
154
|
+
/** Error message if status is 'error' */
|
|
155
|
+
error?: string;
|
|
156
|
+
/** Resulting item if status is 'completed' */
|
|
157
|
+
result?: ImageItem | DocumentItem;
|
|
158
|
+
/** Preview URL for the file (blob URL) */
|
|
159
|
+
previewUrl?: string;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Image-related callbacks
|
|
163
|
+
*/
|
|
164
|
+
interface ImageOptions {
|
|
165
|
+
/** Function to fetch image list from your API */
|
|
166
|
+
fetchList: FetchListFn<ImageItem>;
|
|
167
|
+
/** Function to upload images (optional) */
|
|
168
|
+
upload?: UploadFn<ImageItem>;
|
|
169
|
+
/** Function to update image metadata (alt text) */
|
|
170
|
+
update?: (id: string, data: {
|
|
171
|
+
alt?: LocalizedString;
|
|
172
|
+
}) => Promise<ImageItem>;
|
|
173
|
+
/** Function to delete an image (optional) */
|
|
174
|
+
delete?: (id: string) => Promise<void>;
|
|
175
|
+
/** Configuration for file uploads */
|
|
176
|
+
uploadConfig?: UploadConfig;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Gallery-related callbacks
|
|
180
|
+
*/
|
|
181
|
+
interface GalleryOptions {
|
|
182
|
+
/** Function to fetch gallery list from your API (required) */
|
|
183
|
+
fetchList: FetchListFn<GalleryItem>;
|
|
184
|
+
/** Function to fetch a single gallery by ID */
|
|
185
|
+
fetch: (id: string) => Promise<GalleryItem>;
|
|
186
|
+
/** Function to create a new gallery */
|
|
187
|
+
create: (name: string) => Promise<GalleryItem>;
|
|
188
|
+
/** Function to delete a gallery */
|
|
189
|
+
delete: (id: string) => Promise<void>;
|
|
190
|
+
/** Function to upload images to a gallery */
|
|
191
|
+
upload: (galleryId: string, files: File | File[], callbacks: UploadCallbacks) => Promise<ImageItem | ImageItem[]>;
|
|
192
|
+
/** Function to remove an image from a gallery */
|
|
193
|
+
removeImage: (galleryId: string, imageId: string) => Promise<void>;
|
|
194
|
+
/** Function to update image metadata within a gallery (optional - hides alt editing if not provided) */
|
|
195
|
+
updateImage?: (galleryId: string, imageId: string, data: {
|
|
196
|
+
alt?: LocalizedString;
|
|
197
|
+
}) => Promise<ImageItem>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Document-related callbacks
|
|
201
|
+
*/
|
|
202
|
+
interface DocumentOptions {
|
|
203
|
+
/** Function to fetch document list from your API */
|
|
204
|
+
fetchList: FetchListFn<DocumentItem>;
|
|
205
|
+
/** Function to upload documents (optional - hides upload area if not provided) */
|
|
206
|
+
upload?: UploadFn<DocumentItem>;
|
|
207
|
+
/** Function to update document metadata (title) (optional - hides edit icon if not provided) */
|
|
208
|
+
update?: (id: string, data: {
|
|
209
|
+
title?: LocalizedString;
|
|
210
|
+
}) => Promise<DocumentItem>;
|
|
211
|
+
/** Function to delete a document (optional - hides manage button if not provided) */
|
|
212
|
+
delete?: (id: string) => Promise<void>;
|
|
213
|
+
/** Configuration for file uploads */
|
|
214
|
+
uploadConfig?: UploadConfig;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Plugin configuration options
|
|
218
|
+
*/
|
|
219
|
+
interface MediaPluginOptions {
|
|
220
|
+
/**
|
|
221
|
+
* Languages for multilingual fields (alt, title)
|
|
222
|
+
* @default [{ code: 'it', label: 'Italiano' }, { code: 'en', label: 'English' }]
|
|
223
|
+
*/
|
|
224
|
+
languages?: Language[];
|
|
225
|
+
/**
|
|
226
|
+
* Image-related configuration (required)
|
|
227
|
+
*/
|
|
228
|
+
image: ImageOptions;
|
|
229
|
+
/**
|
|
230
|
+
* Gallery-related configuration (optional)
|
|
231
|
+
*/
|
|
232
|
+
gallery?: GalleryOptions;
|
|
233
|
+
/**
|
|
234
|
+
* Document-related configuration (optional)
|
|
235
|
+
*/
|
|
236
|
+
document?: DocumentOptions;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Internal props passed to ImageField component
|
|
240
|
+
*/
|
|
241
|
+
interface ImageFieldProps {
|
|
242
|
+
name: string;
|
|
243
|
+
value: ImageItem | null;
|
|
244
|
+
onChange: (value: ImageItem | null) => void;
|
|
245
|
+
field: {
|
|
246
|
+
label?: string;
|
|
247
|
+
[key: string]: unknown;
|
|
248
|
+
};
|
|
249
|
+
languages: Language[];
|
|
250
|
+
imageOptions: ImageOptions;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Internal props passed to GalleryField component
|
|
254
|
+
*/
|
|
255
|
+
interface GalleryFieldProps {
|
|
256
|
+
name: string;
|
|
257
|
+
value: GalleryItem | null;
|
|
258
|
+
onChange: (value: GalleryItem | null) => void;
|
|
259
|
+
field: {
|
|
260
|
+
label?: string;
|
|
261
|
+
[key: string]: unknown;
|
|
262
|
+
};
|
|
263
|
+
languages: Language[];
|
|
264
|
+
galleryOptions: GalleryOptions;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Internal props passed to DocumentField component
|
|
268
|
+
*/
|
|
269
|
+
interface DocumentFieldProps {
|
|
270
|
+
name: string;
|
|
271
|
+
value: DocumentItem | null;
|
|
272
|
+
onChange: (value: DocumentItem | null) => void;
|
|
273
|
+
field: {
|
|
274
|
+
label?: string;
|
|
275
|
+
[key: string]: unknown;
|
|
276
|
+
};
|
|
277
|
+
languages: Language[];
|
|
278
|
+
documentOptions: DocumentOptions;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Props for ImagePickerModal component
|
|
282
|
+
*/
|
|
283
|
+
interface ImagePickerModalProps {
|
|
284
|
+
languages: Language[];
|
|
285
|
+
imageOptions: ImageOptions;
|
|
286
|
+
title?: string;
|
|
287
|
+
selectedImage?: ImageItem | null;
|
|
288
|
+
onSelect?: (item: ImageItem) => void;
|
|
289
|
+
onClose: () => void;
|
|
290
|
+
/** When false, hides the "Select Image" button. Useful for media library mode. Default: true */
|
|
291
|
+
selectable?: boolean;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Props for GalleryPickerModal component
|
|
295
|
+
*/
|
|
296
|
+
interface GalleryPickerModalProps {
|
|
297
|
+
languages: Language[];
|
|
298
|
+
galleryOptions: GalleryOptions;
|
|
299
|
+
title?: string;
|
|
300
|
+
selectedGallery?: GalleryItem | null;
|
|
301
|
+
onSelect?: (gallery: GalleryItem) => void;
|
|
302
|
+
onClose: () => void;
|
|
303
|
+
/** When false, hides the "Select Gallery" button. Useful for media library mode. Default: true */
|
|
304
|
+
selectable?: boolean;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Props for DocumentPickerModal component
|
|
308
|
+
*/
|
|
309
|
+
interface DocumentPickerModalProps {
|
|
310
|
+
languages: Language[];
|
|
311
|
+
documentOptions: DocumentOptions;
|
|
312
|
+
title?: string;
|
|
313
|
+
selectedDocument?: DocumentItem | null;
|
|
314
|
+
onSelect?: (item: DocumentItem) => void;
|
|
315
|
+
onClose: () => void;
|
|
316
|
+
/** When false, hides the "Select Document" button. Useful for media library mode. Default: true */
|
|
317
|
+
selectable?: boolean;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Props for ImageGrid component
|
|
321
|
+
*/
|
|
322
|
+
interface ImageGridProps {
|
|
323
|
+
items: ImageItem[];
|
|
324
|
+
onSelect: (item: ImageItem) => void;
|
|
325
|
+
selectedId?: string;
|
|
326
|
+
loading?: boolean;
|
|
327
|
+
/** Callback when user clicks edit icon */
|
|
328
|
+
onEditAlt?: (item: ImageItem) => void;
|
|
329
|
+
/** Whether manage mode is active (for bulk delete) */
|
|
330
|
+
manageMode?: boolean;
|
|
331
|
+
/** Set of selected item IDs for bulk operations */
|
|
332
|
+
selectedIds?: Set<string>;
|
|
333
|
+
/** Callback when user toggles selection in manage mode */
|
|
334
|
+
onToggleSelect?: (item: ImageItem) => void;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Puck Plugin type
|
|
338
|
+
*/
|
|
339
|
+
interface PuckPlugin {
|
|
340
|
+
name: string;
|
|
341
|
+
label?: string;
|
|
342
|
+
icon?: ReactNode;
|
|
343
|
+
render?: () => ReactNode;
|
|
344
|
+
overrides?: {
|
|
345
|
+
fieldTypes?: Record<string, (props: unknown) => ReactNode>;
|
|
346
|
+
[key: string]: unknown;
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export { type DocumentFieldProps as D, type FetchListFn as F, type GalleryFieldProps as G, type ImageFieldProps as I, type Language as L, type MediaPluginOptions as M, type PuckPlugin as P, type UploadConfig as U, type ImagePickerModalProps as a, type ImageGridProps as b, type GalleryPickerModalProps as c, type DocumentPickerModalProps as d, type ImageOptions as e, type GalleryOptions as f, type DocumentOptions as g, type UploadingFile as h, type ImageItem as i, type DocumentItem as j, type UploadFn as k, DEFAULT_LANGUAGES as l, type FetchListParams as m, type FetchListResult as n, type GalleryItem as o, type LocalizedString as p, type UploadCallbacks as q, type UploadStatus as r };
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Language configuration for multilingual fields
|
|
5
|
+
*/
|
|
6
|
+
interface Language {
|
|
7
|
+
code: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Default languages when not specified
|
|
12
|
+
*/
|
|
13
|
+
declare const DEFAULT_LANGUAGES: Language[];
|
|
14
|
+
/**
|
|
15
|
+
* Localized string value (e.g., { en: 'Hello', it: 'Ciao' })
|
|
16
|
+
*/
|
|
17
|
+
type LocalizedString = Record<string, string | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Image item - used both for API responses and stored values in Puck JSON
|
|
20
|
+
*/
|
|
21
|
+
interface ImageItem {
|
|
22
|
+
/** Unique identifier */
|
|
23
|
+
id: string;
|
|
24
|
+
/** Full URL to the image file */
|
|
25
|
+
url: string;
|
|
26
|
+
/** Original filename */
|
|
27
|
+
filename?: string;
|
|
28
|
+
/** Alt text (multilingual) */
|
|
29
|
+
alt?: LocalizedString;
|
|
30
|
+
/** Image width in pixels */
|
|
31
|
+
width?: number;
|
|
32
|
+
/** Image height in pixels */
|
|
33
|
+
height?: number;
|
|
34
|
+
/** File size in bytes */
|
|
35
|
+
size?: number;
|
|
36
|
+
/** Thumbnail URL for faster loading in picker (falls back to url if not provided) */
|
|
37
|
+
thumbnailUrl?: string;
|
|
38
|
+
/** Creation date (useful for cache invalidation) */
|
|
39
|
+
createdAt?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Document item - used both for API responses and stored values in Puck JSON
|
|
43
|
+
*/
|
|
44
|
+
interface DocumentItem {
|
|
45
|
+
/** Unique identifier */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Full URL to the document file */
|
|
48
|
+
url: string;
|
|
49
|
+
/** Original filename */
|
|
50
|
+
filename: string;
|
|
51
|
+
/** Display title (multilingual) */
|
|
52
|
+
title?: LocalizedString;
|
|
53
|
+
/** MIME type (e.g., 'application/pdf') */
|
|
54
|
+
mimeType: string;
|
|
55
|
+
/** File size in bytes */
|
|
56
|
+
size: number;
|
|
57
|
+
/** File extension (e.g., 'pdf', 'docx') */
|
|
58
|
+
extension: string;
|
|
59
|
+
/** Creation date (useful for cache invalidation) */
|
|
60
|
+
createdAt?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gallery item - used both for API responses and stored values in Puck JSON
|
|
64
|
+
*/
|
|
65
|
+
interface GalleryItem {
|
|
66
|
+
/** Unique identifier */
|
|
67
|
+
id: string;
|
|
68
|
+
/** Gallery name */
|
|
69
|
+
name: string;
|
|
70
|
+
/** Cover image for preview */
|
|
71
|
+
coverImage?: ImageItem;
|
|
72
|
+
/** Images in the gallery */
|
|
73
|
+
images: ImageItem[];
|
|
74
|
+
/** Number of images in the gallery (optional, can be calculated from images.length) */
|
|
75
|
+
imageCount?: number;
|
|
76
|
+
/** Creation date (useful for cache invalidation) */
|
|
77
|
+
createdAt?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Parameters passed to fetchList functions
|
|
81
|
+
*/
|
|
82
|
+
interface FetchListParams {
|
|
83
|
+
/** Search query string */
|
|
84
|
+
query?: string;
|
|
85
|
+
/** Page number (1-indexed) */
|
|
86
|
+
page?: number;
|
|
87
|
+
/** Items per page */
|
|
88
|
+
pageSize?: number;
|
|
89
|
+
/** Additional filters */
|
|
90
|
+
filters?: Record<string, unknown>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Result from fetchList - paginated result
|
|
94
|
+
*/
|
|
95
|
+
interface FetchListResult<T> {
|
|
96
|
+
/** Array of items */
|
|
97
|
+
items: T[];
|
|
98
|
+
/** Total number of items (for pagination) */
|
|
99
|
+
total?: number;
|
|
100
|
+
/** Whether there are more items to load */
|
|
101
|
+
hasMore?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Generic fetch list function type
|
|
105
|
+
*/
|
|
106
|
+
type FetchListFn<T> = (params: FetchListParams) => Promise<T[] | FetchListResult<T>>;
|
|
107
|
+
/**
|
|
108
|
+
* Callbacks passed to upload functions
|
|
109
|
+
*/
|
|
110
|
+
interface UploadCallbacks {
|
|
111
|
+
/** Called with upload progress (0-100) */
|
|
112
|
+
onProgress: (percent: number) => void;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Upload function that handles single or multiple files
|
|
116
|
+
*/
|
|
117
|
+
type UploadFn<T> = (files: File | File[], callbacks: UploadCallbacks) => Promise<T | T[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Configuration for file uploads
|
|
120
|
+
*/
|
|
121
|
+
interface UploadConfig {
|
|
122
|
+
/**
|
|
123
|
+
* Accepted file types (MIME types or extensions)
|
|
124
|
+
* @default 'image/*' for images, '*' for documents
|
|
125
|
+
*/
|
|
126
|
+
accept?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Maximum file size in bytes
|
|
129
|
+
* @default 10485760 (10MB)
|
|
130
|
+
*/
|
|
131
|
+
maxSize?: number;
|
|
132
|
+
/**
|
|
133
|
+
* Allow multiple file uploads
|
|
134
|
+
* @default true
|
|
135
|
+
*/
|
|
136
|
+
multiple?: boolean;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Status of a file being uploaded
|
|
140
|
+
*/
|
|
141
|
+
type UploadStatus = 'pending' | 'uploading' | 'completed' | 'error';
|
|
142
|
+
/**
|
|
143
|
+
* State of a file in the upload queue
|
|
144
|
+
*/
|
|
145
|
+
interface UploadingFile {
|
|
146
|
+
/** Unique ID for this upload */
|
|
147
|
+
id: string;
|
|
148
|
+
/** The file being uploaded */
|
|
149
|
+
file: File;
|
|
150
|
+
/** Upload progress (0-100) */
|
|
151
|
+
progress: number;
|
|
152
|
+
/** Current upload status */
|
|
153
|
+
status: UploadStatus;
|
|
154
|
+
/** Error message if status is 'error' */
|
|
155
|
+
error?: string;
|
|
156
|
+
/** Resulting item if status is 'completed' */
|
|
157
|
+
result?: ImageItem | DocumentItem;
|
|
158
|
+
/** Preview URL for the file (blob URL) */
|
|
159
|
+
previewUrl?: string;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Image-related callbacks
|
|
163
|
+
*/
|
|
164
|
+
interface ImageOptions {
|
|
165
|
+
/** Function to fetch image list from your API */
|
|
166
|
+
fetchList: FetchListFn<ImageItem>;
|
|
167
|
+
/** Function to upload images (optional) */
|
|
168
|
+
upload?: UploadFn<ImageItem>;
|
|
169
|
+
/** Function to update image metadata (alt text) */
|
|
170
|
+
update?: (id: string, data: {
|
|
171
|
+
alt?: LocalizedString;
|
|
172
|
+
}) => Promise<ImageItem>;
|
|
173
|
+
/** Function to delete an image (optional) */
|
|
174
|
+
delete?: (id: string) => Promise<void>;
|
|
175
|
+
/** Configuration for file uploads */
|
|
176
|
+
uploadConfig?: UploadConfig;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Gallery-related callbacks
|
|
180
|
+
*/
|
|
181
|
+
interface GalleryOptions {
|
|
182
|
+
/** Function to fetch gallery list from your API (required) */
|
|
183
|
+
fetchList: FetchListFn<GalleryItem>;
|
|
184
|
+
/** Function to fetch a single gallery by ID */
|
|
185
|
+
fetch: (id: string) => Promise<GalleryItem>;
|
|
186
|
+
/** Function to create a new gallery */
|
|
187
|
+
create: (name: string) => Promise<GalleryItem>;
|
|
188
|
+
/** Function to delete a gallery */
|
|
189
|
+
delete: (id: string) => Promise<void>;
|
|
190
|
+
/** Function to upload images to a gallery */
|
|
191
|
+
upload: (galleryId: string, files: File | File[], callbacks: UploadCallbacks) => Promise<ImageItem | ImageItem[]>;
|
|
192
|
+
/** Function to remove an image from a gallery */
|
|
193
|
+
removeImage: (galleryId: string, imageId: string) => Promise<void>;
|
|
194
|
+
/** Function to update image metadata within a gallery (optional - hides alt editing if not provided) */
|
|
195
|
+
updateImage?: (galleryId: string, imageId: string, data: {
|
|
196
|
+
alt?: LocalizedString;
|
|
197
|
+
}) => Promise<ImageItem>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Document-related callbacks
|
|
201
|
+
*/
|
|
202
|
+
interface DocumentOptions {
|
|
203
|
+
/** Function to fetch document list from your API */
|
|
204
|
+
fetchList: FetchListFn<DocumentItem>;
|
|
205
|
+
/** Function to upload documents (optional - hides upload area if not provided) */
|
|
206
|
+
upload?: UploadFn<DocumentItem>;
|
|
207
|
+
/** Function to update document metadata (title) (optional - hides edit icon if not provided) */
|
|
208
|
+
update?: (id: string, data: {
|
|
209
|
+
title?: LocalizedString;
|
|
210
|
+
}) => Promise<DocumentItem>;
|
|
211
|
+
/** Function to delete a document (optional - hides manage button if not provided) */
|
|
212
|
+
delete?: (id: string) => Promise<void>;
|
|
213
|
+
/** Configuration for file uploads */
|
|
214
|
+
uploadConfig?: UploadConfig;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Plugin configuration options
|
|
218
|
+
*/
|
|
219
|
+
interface MediaPluginOptions {
|
|
220
|
+
/**
|
|
221
|
+
* Languages for multilingual fields (alt, title)
|
|
222
|
+
* @default [{ code: 'it', label: 'Italiano' }, { code: 'en', label: 'English' }]
|
|
223
|
+
*/
|
|
224
|
+
languages?: Language[];
|
|
225
|
+
/**
|
|
226
|
+
* Image-related configuration (required)
|
|
227
|
+
*/
|
|
228
|
+
image: ImageOptions;
|
|
229
|
+
/**
|
|
230
|
+
* Gallery-related configuration (optional)
|
|
231
|
+
*/
|
|
232
|
+
gallery?: GalleryOptions;
|
|
233
|
+
/**
|
|
234
|
+
* Document-related configuration (optional)
|
|
235
|
+
*/
|
|
236
|
+
document?: DocumentOptions;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Internal props passed to ImageField component
|
|
240
|
+
*/
|
|
241
|
+
interface ImageFieldProps {
|
|
242
|
+
name: string;
|
|
243
|
+
value: ImageItem | null;
|
|
244
|
+
onChange: (value: ImageItem | null) => void;
|
|
245
|
+
field: {
|
|
246
|
+
label?: string;
|
|
247
|
+
[key: string]: unknown;
|
|
248
|
+
};
|
|
249
|
+
languages: Language[];
|
|
250
|
+
imageOptions: ImageOptions;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Internal props passed to GalleryField component
|
|
254
|
+
*/
|
|
255
|
+
interface GalleryFieldProps {
|
|
256
|
+
name: string;
|
|
257
|
+
value: GalleryItem | null;
|
|
258
|
+
onChange: (value: GalleryItem | null) => void;
|
|
259
|
+
field: {
|
|
260
|
+
label?: string;
|
|
261
|
+
[key: string]: unknown;
|
|
262
|
+
};
|
|
263
|
+
languages: Language[];
|
|
264
|
+
galleryOptions: GalleryOptions;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Internal props passed to DocumentField component
|
|
268
|
+
*/
|
|
269
|
+
interface DocumentFieldProps {
|
|
270
|
+
name: string;
|
|
271
|
+
value: DocumentItem | null;
|
|
272
|
+
onChange: (value: DocumentItem | null) => void;
|
|
273
|
+
field: {
|
|
274
|
+
label?: string;
|
|
275
|
+
[key: string]: unknown;
|
|
276
|
+
};
|
|
277
|
+
languages: Language[];
|
|
278
|
+
documentOptions: DocumentOptions;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Props for ImagePickerModal component
|
|
282
|
+
*/
|
|
283
|
+
interface ImagePickerModalProps {
|
|
284
|
+
languages: Language[];
|
|
285
|
+
imageOptions: ImageOptions;
|
|
286
|
+
title?: string;
|
|
287
|
+
selectedImage?: ImageItem | null;
|
|
288
|
+
onSelect?: (item: ImageItem) => void;
|
|
289
|
+
onClose: () => void;
|
|
290
|
+
/** When false, hides the "Select Image" button. Useful for media library mode. Default: true */
|
|
291
|
+
selectable?: boolean;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Props for GalleryPickerModal component
|
|
295
|
+
*/
|
|
296
|
+
interface GalleryPickerModalProps {
|
|
297
|
+
languages: Language[];
|
|
298
|
+
galleryOptions: GalleryOptions;
|
|
299
|
+
title?: string;
|
|
300
|
+
selectedGallery?: GalleryItem | null;
|
|
301
|
+
onSelect?: (gallery: GalleryItem) => void;
|
|
302
|
+
onClose: () => void;
|
|
303
|
+
/** When false, hides the "Select Gallery" button. Useful for media library mode. Default: true */
|
|
304
|
+
selectable?: boolean;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Props for DocumentPickerModal component
|
|
308
|
+
*/
|
|
309
|
+
interface DocumentPickerModalProps {
|
|
310
|
+
languages: Language[];
|
|
311
|
+
documentOptions: DocumentOptions;
|
|
312
|
+
title?: string;
|
|
313
|
+
selectedDocument?: DocumentItem | null;
|
|
314
|
+
onSelect?: (item: DocumentItem) => void;
|
|
315
|
+
onClose: () => void;
|
|
316
|
+
/** When false, hides the "Select Document" button. Useful for media library mode. Default: true */
|
|
317
|
+
selectable?: boolean;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Props for ImageGrid component
|
|
321
|
+
*/
|
|
322
|
+
interface ImageGridProps {
|
|
323
|
+
items: ImageItem[];
|
|
324
|
+
onSelect: (item: ImageItem) => void;
|
|
325
|
+
selectedId?: string;
|
|
326
|
+
loading?: boolean;
|
|
327
|
+
/** Callback when user clicks edit icon */
|
|
328
|
+
onEditAlt?: (item: ImageItem) => void;
|
|
329
|
+
/** Whether manage mode is active (for bulk delete) */
|
|
330
|
+
manageMode?: boolean;
|
|
331
|
+
/** Set of selected item IDs for bulk operations */
|
|
332
|
+
selectedIds?: Set<string>;
|
|
333
|
+
/** Callback when user toggles selection in manage mode */
|
|
334
|
+
onToggleSelect?: (item: ImageItem) => void;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Puck Plugin type
|
|
338
|
+
*/
|
|
339
|
+
interface PuckPlugin {
|
|
340
|
+
name: string;
|
|
341
|
+
label?: string;
|
|
342
|
+
icon?: ReactNode;
|
|
343
|
+
render?: () => ReactNode;
|
|
344
|
+
overrides?: {
|
|
345
|
+
fieldTypes?: Record<string, (props: unknown) => ReactNode>;
|
|
346
|
+
[key: string]: unknown;
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export { type DocumentFieldProps as D, type FetchListFn as F, type GalleryFieldProps as G, type ImageFieldProps as I, type Language as L, type MediaPluginOptions as M, type PuckPlugin as P, type UploadConfig as U, type ImagePickerModalProps as a, type ImageGridProps as b, type GalleryPickerModalProps as c, type DocumentPickerModalProps as d, type ImageOptions as e, type GalleryOptions as f, type DocumentOptions as g, type UploadingFile as h, type ImageItem as i, type DocumentItem as j, type UploadFn as k, DEFAULT_LANGUAGES as l, type FetchListParams as m, type FetchListResult as n, type GalleryItem as o, type LocalizedString as p, type UploadCallbacks as q, type UploadStatus as r };
|