@chayns-components/gallery 5.0.53 → 5.0.56
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/AGENTS.md +135 -72
- package/lib/cjs/components/Gallery.js +16 -329
- package/lib/cjs/components/Gallery.js.map +1 -1
- package/lib/cjs/components/Gallery.types.js +6 -0
- package/lib/cjs/components/Gallery.types.js.map +1 -0
- package/lib/cjs/components/gallery-editor/GalleryEditor.js +198 -0
- package/lib/cjs/components/gallery-editor/GalleryEditor.js.map +1 -0
- package/lib/cjs/components/gallery-editor/GalleryEditor.styles.js +20 -0
- package/lib/cjs/components/gallery-editor/GalleryEditor.styles.js.map +1 -0
- package/lib/cjs/components/gallery-editor/GalleryEditor.types.js +6 -0
- package/lib/cjs/components/gallery-editor/GalleryEditor.types.js.map +1 -0
- package/lib/cjs/components/gallery-editor/add-file/AddFile.js.map +1 -0
- package/lib/cjs/components/gallery-editor/add-file/AddFile.styles.js.map +1 -0
- package/lib/cjs/components/gallery-editor/add-file/AddFile.types.js +6 -0
- package/lib/cjs/components/gallery-editor/add-file/AddFile.types.js.map +1 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.js +41 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.js.map +1 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.js +37 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.js.map +1 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.js +6 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.js.map +1 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.js +36 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.js.map +1 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.styles.js +15 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.styles.js.map +1 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.types.js +6 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.types.js.map +1 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.js +45 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.js.map +1 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.styles.js +44 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.styles.js.map +1 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.types.js +6 -0
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.types.js.map +1 -0
- package/lib/cjs/components/gallery-viewer/GalleryViewer.js +42 -0
- package/lib/cjs/components/gallery-viewer/GalleryViewer.js.map +1 -0
- package/lib/cjs/components/{Gallery.styles.js → gallery-viewer/GalleryViewer.styles.js} +13 -18
- package/lib/cjs/components/gallery-viewer/GalleryViewer.styles.js.map +1 -0
- package/lib/cjs/components/gallery-viewer/GalleryViewer.types.js +6 -0
- package/lib/cjs/components/gallery-viewer/GalleryViewer.types.js.map +1 -0
- package/lib/cjs/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.js +25 -0
- package/lib/cjs/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.js.map +1 -0
- package/lib/cjs/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.styles.js +30 -0
- package/lib/cjs/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.styles.js.map +1 -0
- package/lib/cjs/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.types.js +6 -0
- package/lib/cjs/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.types.js.map +1 -0
- package/lib/cjs/components/media-content/MediaContent.js +36 -0
- package/lib/cjs/components/media-content/MediaContent.js.map +1 -0
- package/lib/cjs/components/media-content/MediaContent.styles.js +56 -0
- package/lib/cjs/components/media-content/MediaContent.styles.js.map +1 -0
- package/lib/cjs/components/media-content/MediaContent.types.js +6 -0
- package/lib/cjs/components/media-content/MediaContent.types.js.map +1 -0
- package/lib/cjs/index.js +14 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types/gallery.js +9 -0
- package/lib/cjs/types/gallery.js.map +1 -1
- package/lib/cjs/utils/gallery.js +152 -0
- package/lib/cjs/utils/gallery.js.map +1 -0
- package/lib/esm/components/Gallery.js +16 -319
- package/lib/esm/components/Gallery.js.map +1 -1
- package/lib/esm/components/Gallery.types.js +2 -0
- package/lib/esm/components/Gallery.types.js.map +1 -0
- package/lib/esm/components/gallery-editor/GalleryEditor.js +189 -0
- package/lib/esm/components/gallery-editor/GalleryEditor.js.map +1 -0
- package/lib/esm/components/gallery-editor/GalleryEditor.styles.js +13 -0
- package/lib/esm/components/gallery-editor/GalleryEditor.styles.js.map +1 -0
- package/lib/esm/components/gallery-editor/GalleryEditor.types.js +2 -0
- package/lib/esm/components/gallery-editor/GalleryEditor.types.js.map +1 -0
- package/lib/esm/components/gallery-editor/add-file/AddFile.js.map +1 -0
- package/lib/esm/components/gallery-editor/add-file/AddFile.styles.js.map +1 -0
- package/lib/esm/components/gallery-editor/add-file/AddFile.types.js +2 -0
- package/lib/esm/components/gallery-editor/add-file/AddFile.types.js.map +1 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.js +34 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.js.map +1 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.js +30 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.js.map +1 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.js +2 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.js.map +1 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.js +29 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.js.map +1 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.styles.js +8 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.styles.js.map +1 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.types.js +2 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.types.js.map +1 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.js +38 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.js.map +1 -0
- package/lib/esm/components/{gallery-item/preview-item/PreviewItem.styles.js → gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.styles.js} +7 -6
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.styles.js.map +1 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.types.js +2 -0
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.types.js.map +1 -0
- package/lib/esm/components/gallery-viewer/GalleryViewer.js +34 -0
- package/lib/esm/components/gallery-viewer/GalleryViewer.js.map +1 -0
- package/lib/esm/components/{Gallery.styles.js → gallery-viewer/GalleryViewer.styles.js} +12 -17
- package/lib/esm/components/gallery-viewer/GalleryViewer.styles.js.map +1 -0
- package/lib/esm/components/gallery-viewer/GalleryViewer.types.js +2 -0
- package/lib/esm/components/gallery-viewer/GalleryViewer.types.js.map +1 -0
- package/lib/esm/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.js +18 -0
- package/lib/esm/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.js.map +1 -0
- package/lib/esm/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.styles.js +23 -0
- package/lib/esm/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.styles.js.map +1 -0
- package/lib/esm/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.types.js +2 -0
- package/lib/esm/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.types.js.map +1 -0
- package/lib/esm/components/media-content/MediaContent.js +29 -0
- package/lib/esm/components/media-content/MediaContent.js.map +1 -0
- package/lib/esm/components/media-content/MediaContent.styles.js +49 -0
- package/lib/esm/components/media-content/MediaContent.styles.js.map +1 -0
- package/lib/esm/components/media-content/MediaContent.types.js +2 -0
- package/lib/esm/components/media-content/MediaContent.types.js.map +1 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types/gallery.js +9 -0
- package/lib/esm/types/gallery.js.map +1 -1
- package/lib/esm/utils/gallery.js +132 -0
- package/lib/esm/utils/gallery.js.map +1 -0
- package/lib/types/components/Gallery.d.ts +1 -44
- package/lib/types/components/Gallery.types.d.ts +107 -0
- package/lib/types/components/gallery-editor/GalleryEditor.d.ts +4 -0
- package/lib/types/components/gallery-editor/GalleryEditor.styles.d.ts +4 -0
- package/lib/types/components/gallery-editor/GalleryEditor.types.d.ts +81 -0
- package/lib/types/components/gallery-editor/add-file/AddFile.d.ts +4 -0
- package/lib/types/components/gallery-editor/add-file/AddFile.types.d.ts +13 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/GalleryEditorItem.d.ts +4 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.d.ts +4 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.d.ts +40 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.d.ts +4 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.styles.d.ts +3 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.types.d.ts +30 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.d.ts +4 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.styles.d.ts +10 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.types.d.ts +22 -0
- package/lib/types/components/gallery-viewer/GalleryViewer.d.ts +4 -0
- package/lib/types/components/gallery-viewer/GalleryViewer.styles.d.ts +7 -0
- package/lib/types/components/gallery-viewer/GalleryViewer.types.d.ts +26 -0
- package/lib/types/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.d.ts +4 -0
- package/lib/types/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.styles.d.ts +2 -0
- package/lib/types/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.types.d.ts +41 -0
- package/lib/types/components/media-content/MediaContent.d.ts +4 -0
- package/lib/types/components/media-content/MediaContent.styles.d.ts +13 -0
- package/lib/types/components/media-content/MediaContent.types.d.ts +40 -0
- package/lib/types/index.d.ts +5 -0
- package/lib/types/types/gallery.d.ts +9 -0
- package/lib/types/utils/gallery.d.ts +12 -0
- package/package.json +3 -3
- package/lib/cjs/components/Gallery.styles.js.map +0 -1
- package/lib/cjs/components/add-file/AddFile.js.map +0 -1
- package/lib/cjs/components/add-file/AddFile.styles.js.map +0 -1
- package/lib/cjs/components/gallery-item/GalleryItem.js +0 -44
- package/lib/cjs/components/gallery-item/GalleryItem.js.map +0 -1
- package/lib/cjs/components/gallery-item/GalleryItem.styles.js +0 -51
- package/lib/cjs/components/gallery-item/GalleryItem.styles.js.map +0 -1
- package/lib/cjs/components/gallery-item/media-item/MediaItem.js +0 -52
- package/lib/cjs/components/gallery-item/media-item/MediaItem.js.map +0 -1
- package/lib/cjs/components/gallery-item/media-item/MediaItem.styles.js +0 -62
- package/lib/cjs/components/gallery-item/media-item/MediaItem.styles.js.map +0 -1
- package/lib/cjs/components/gallery-item/preview-item/PreviewItem.js +0 -45
- package/lib/cjs/components/gallery-item/preview-item/PreviewItem.js.map +0 -1
- package/lib/cjs/components/gallery-item/preview-item/PreviewItem.styles.js +0 -43
- package/lib/cjs/components/gallery-item/preview-item/PreviewItem.styles.js.map +0 -1
- package/lib/esm/components/Gallery.styles.js.map +0 -1
- package/lib/esm/components/add-file/AddFile.js.map +0 -1
- package/lib/esm/components/add-file/AddFile.styles.js.map +0 -1
- package/lib/esm/components/gallery-item/GalleryItem.js +0 -36
- package/lib/esm/components/gallery-item/GalleryItem.js.map +0 -1
- package/lib/esm/components/gallery-item/GalleryItem.styles.js +0 -44
- package/lib/esm/components/gallery-item/GalleryItem.styles.js.map +0 -1
- package/lib/esm/components/gallery-item/media-item/MediaItem.js +0 -42
- package/lib/esm/components/gallery-item/media-item/MediaItem.js.map +0 -1
- package/lib/esm/components/gallery-item/media-item/MediaItem.styles.js +0 -55
- package/lib/esm/components/gallery-item/media-item/MediaItem.styles.js.map +0 -1
- package/lib/esm/components/gallery-item/preview-item/PreviewItem.js +0 -38
- package/lib/esm/components/gallery-item/preview-item/PreviewItem.js.map +0 -1
- package/lib/esm/components/gallery-item/preview-item/PreviewItem.styles.js.map +0 -1
- package/lib/types/components/Gallery.styles.d.ts +0 -10
- package/lib/types/components/add-file/AddFile.d.ts +0 -9
- package/lib/types/components/gallery-item/GalleryItem.d.ts +0 -30
- package/lib/types/components/gallery-item/GalleryItem.styles.d.ts +0 -5
- package/lib/types/components/gallery-item/media-item/MediaItem.d.ts +0 -22
- package/lib/types/components/gallery-item/media-item/MediaItem.styles.d.ts +0 -16
- package/lib/types/components/gallery-item/preview-item/PreviewItem.d.ts +0 -14
- package/lib/types/components/gallery-item/preview-item/PreviewItem.styles.d.ts +0 -10
- /package/lib/cjs/components/{add-file → gallery-editor/add-file}/AddFile.js +0 -0
- /package/lib/cjs/components/{add-file → gallery-editor/add-file}/AddFile.styles.js +0 -0
- /package/lib/esm/components/{add-file → gallery-editor/add-file}/AddFile.js +0 -0
- /package/lib/esm/components/{add-file → gallery-editor/add-file}/AddFile.styles.js +0 -0
- /package/lib/types/components/{add-file → gallery-editor/add-file}/AddFile.styles.d.ts +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.openKnownFiles = exports.openFiles = exports.mapFilesToInternalItems = exports.getReadOnlyItemRatio = exports.getGalleryViewerKey = exports.getGalleryRatio = void 0;
|
|
7
|
+
var _chaynsApi = require("chayns-api");
|
|
8
|
+
var _gallery = require("../types/gallery");
|
|
9
|
+
const DEFAULT_MEDIA_RATIO = 1;
|
|
10
|
+
const mapFilesToInternalItems = files => (files ?? []).map((file, index) => ({
|
|
11
|
+
id: getGalleryViewerKey(file, index),
|
|
12
|
+
uploadedFile: file.file,
|
|
13
|
+
file: undefined,
|
|
14
|
+
state: 'uploaded',
|
|
15
|
+
previewUrl: undefined
|
|
16
|
+
}));
|
|
17
|
+
exports.mapFilesToInternalItems = mapFilesToInternalItems;
|
|
18
|
+
const getGalleryViewerKey = (fileItem, index) => fileItem.id ?? fileItem.file.id ?? fileItem.file.url ?? `gallery-item-${index}`;
|
|
19
|
+
exports.getGalleryViewerKey = getGalleryViewerKey;
|
|
20
|
+
const getGalleryRatio = fileItems => {
|
|
21
|
+
var _fileItems$;
|
|
22
|
+
switch (fileItems.length) {
|
|
23
|
+
case 0:
|
|
24
|
+
return DEFAULT_MEDIA_RATIO;
|
|
25
|
+
case 1:
|
|
26
|
+
return Math.max(((_fileItems$ = fileItems[0]) === null || _fileItems$ === void 0 ? void 0 : _fileItems$.file.ratio) ?? DEFAULT_MEDIA_RATIO, 1);
|
|
27
|
+
case 2:
|
|
28
|
+
return 2;
|
|
29
|
+
case 3:
|
|
30
|
+
return 3;
|
|
31
|
+
default:
|
|
32
|
+
return DEFAULT_MEDIA_RATIO;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.getGalleryRatio = getGalleryRatio;
|
|
36
|
+
const getReadOnlyItemRatio = ({
|
|
37
|
+
fileItems,
|
|
38
|
+
index,
|
|
39
|
+
viewMode
|
|
40
|
+
}) => {
|
|
41
|
+
const itemCount = fileItems.length;
|
|
42
|
+
if (viewMode !== _gallery.GalleryViewMode.GRID) {
|
|
43
|
+
return DEFAULT_MEDIA_RATIO;
|
|
44
|
+
}
|
|
45
|
+
if (itemCount === 1) {
|
|
46
|
+
var _fileItems$2;
|
|
47
|
+
// A square fallback keeps virtualization stable when upstream data does not provide a ratio.
|
|
48
|
+
return Math.max(((_fileItems$2 = fileItems[0]) === null || _fileItems$2 === void 0 ? void 0 : _fileItems$2.file.ratio) ?? DEFAULT_MEDIA_RATIO, DEFAULT_MEDIA_RATIO);
|
|
49
|
+
}
|
|
50
|
+
if (itemCount === 2 && (index === 0 || index === 1)) {
|
|
51
|
+
return 0.5;
|
|
52
|
+
}
|
|
53
|
+
if (index === 0 && itemCount > 2 || itemCount === 3 && (index === 1 || index === 2)) {
|
|
54
|
+
return 1.5;
|
|
55
|
+
}
|
|
56
|
+
return DEFAULT_MEDIA_RATIO;
|
|
57
|
+
};
|
|
58
|
+
exports.getReadOnlyItemRatio = getReadOnlyItemRatio;
|
|
59
|
+
const openFiles = (fileItems, file) => {
|
|
60
|
+
let startIndex = 0;
|
|
61
|
+
try {
|
|
62
|
+
startIndex = fileItems.findIndex(item => item.id === file.id);
|
|
63
|
+
const items = fileItems.map(item => {
|
|
64
|
+
var _item$uploadedFile;
|
|
65
|
+
return {
|
|
66
|
+
url: ((_item$uploadedFile = item.uploadedFile) === null || _item$uploadedFile === void 0 ? void 0 : _item$uploadedFile.url.replace('_0.mp4', '.mp4')) ?? '',
|
|
67
|
+
mediaType: item.uploadedFile && 'thumbnailUrl' in item.uploadedFile ? _chaynsApi.MediaType.VIDEO : _chaynsApi.MediaType.IMAGE
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
void (0, _chaynsApi.openMedia)({
|
|
74
|
+
items,
|
|
75
|
+
startIndex
|
|
76
|
+
});
|
|
77
|
+
} catch (_) {
|
|
78
|
+
if (file.uploadedFile && 'thumbnailUrl' in file.uploadedFile) {
|
|
79
|
+
void (0, _chaynsApi.openVideo)({
|
|
80
|
+
url: file.uploadedFile.url
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const imageFiles = [];
|
|
85
|
+
fileItems.forEach(({
|
|
86
|
+
uploadedFile
|
|
87
|
+
}) => {
|
|
88
|
+
if (uploadedFile && !('thumbnailUrl' in uploadedFile)) {
|
|
89
|
+
imageFiles.push({
|
|
90
|
+
url: uploadedFile.url
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
startIndex = imageFiles.findIndex(item => {
|
|
95
|
+
var _file$uploadedFile;
|
|
96
|
+
return item.url === ((_file$uploadedFile = file.uploadedFile) === null || _file$uploadedFile === void 0 ? void 0 : _file$uploadedFile.url);
|
|
97
|
+
});
|
|
98
|
+
const startFile = imageFiles.shift();
|
|
99
|
+
if (!startFile) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
void (0, _chaynsApi.openImage)({
|
|
103
|
+
items: [startFile, ...imageFiles],
|
|
104
|
+
startIndex
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
exports.openFiles = openFiles;
|
|
109
|
+
const openKnownFiles = (fileItems, file) => {
|
|
110
|
+
const activeFileKey = getGalleryViewerKey(file, fileItems.indexOf(file));
|
|
111
|
+
let startIndex = 0;
|
|
112
|
+
try {
|
|
113
|
+
startIndex = fileItems.findIndex((item, index) => getGalleryViewerKey(item, index) === activeFileKey);
|
|
114
|
+
const items = fileItems.map(item => ({
|
|
115
|
+
url: item.file.url.replace('_0.mp4', '.mp4'),
|
|
116
|
+
mediaType: 'thumbnailUrl' in item.file ? _chaynsApi.MediaType.VIDEO : _chaynsApi.MediaType.IMAGE
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
void (0, _chaynsApi.openMedia)({
|
|
122
|
+
items,
|
|
123
|
+
startIndex
|
|
124
|
+
});
|
|
125
|
+
} catch (_) {
|
|
126
|
+
if ('thumbnailUrl' in file.file) {
|
|
127
|
+
void (0, _chaynsApi.openVideo)({
|
|
128
|
+
url: file.file.url
|
|
129
|
+
});
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const imageFiles = [];
|
|
133
|
+
fileItems.forEach(item => {
|
|
134
|
+
if (!('thumbnailUrl' in item.file)) {
|
|
135
|
+
imageFiles.push({
|
|
136
|
+
url: item.file.url
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
startIndex = imageFiles.findIndex(item => item.url === file.file.url);
|
|
141
|
+
const startFile = imageFiles.shift();
|
|
142
|
+
if (!startFile) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
void (0, _chaynsApi.openImage)({
|
|
146
|
+
items: [startFile, ...imageFiles],
|
|
147
|
+
startIndex
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
exports.openKnownFiles = openKnownFiles;
|
|
152
|
+
//# sourceMappingURL=gallery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gallery.js","names":["_chaynsApi","require","_gallery","DEFAULT_MEDIA_RATIO","mapFilesToInternalItems","files","map","file","index","id","getGalleryViewerKey","uploadedFile","undefined","state","previewUrl","exports","fileItem","url","getGalleryRatio","fileItems","_fileItems$","length","Math","max","ratio","getReadOnlyItemRatio","viewMode","itemCount","GalleryViewMode","GRID","_fileItems$2","openFiles","startIndex","findIndex","item","items","_item$uploadedFile","replace","mediaType","MediaType","VIDEO","IMAGE","openMedia","_","openVideo","imageFiles","forEach","push","_file$uploadedFile","startFile","shift","openImage","openKnownFiles","activeFileKey","indexOf"],"sources":["../../../src/utils/gallery.ts"],"sourcesContent":["import type { FileItem, InternalFileItem } from '@chayns-components/core';\nimport {\n MediaType,\n openImage,\n openMedia,\n type OpenImageItem,\n type OpenMediaItem,\n openVideo,\n} from 'chayns-api';\nimport { GalleryViewMode } from '../types/gallery';\n\nconst DEFAULT_MEDIA_RATIO = 1;\n\nexport const mapFilesToInternalItems = (files?: FileItem[]): InternalFileItem[] =>\n (files ?? []).map((file, index) => ({\n id: getGalleryViewerKey(file, index),\n uploadedFile: file.file,\n file: undefined,\n state: 'uploaded',\n previewUrl: undefined,\n }));\n\nexport const getGalleryViewerKey = (fileItem: FileItem, index: number): string =>\n fileItem.id ?? fileItem.file.id ?? fileItem.file.url ?? `gallery-item-${index}`;\n\nexport const getGalleryRatio = (fileItems: FileItem[]): number => {\n switch (fileItems.length) {\n case 0:\n return DEFAULT_MEDIA_RATIO;\n case 1:\n return Math.max(fileItems[0]?.file.ratio ?? DEFAULT_MEDIA_RATIO, 1);\n case 2:\n return 2;\n case 3:\n return 3;\n default:\n return DEFAULT_MEDIA_RATIO;\n }\n};\n\nexport const getReadOnlyItemRatio = ({\n fileItems,\n index,\n viewMode,\n}: {\n fileItems: FileItem[];\n index: number;\n viewMode: GalleryViewMode;\n}): number => {\n const itemCount = fileItems.length;\n\n if (viewMode !== GalleryViewMode.GRID) {\n return DEFAULT_MEDIA_RATIO;\n }\n\n if (itemCount === 1) {\n // A square fallback keeps virtualization stable when upstream data does not provide a ratio.\n return Math.max(fileItems[0]?.file.ratio ?? DEFAULT_MEDIA_RATIO, DEFAULT_MEDIA_RATIO);\n }\n\n if (itemCount === 2 && (index === 0 || index === 1)) {\n return 0.5;\n }\n\n if ((index === 0 && itemCount > 2) || (itemCount === 3 && (index === 1 || index === 2))) {\n return 1.5;\n }\n\n return DEFAULT_MEDIA_RATIO;\n};\n\nexport const openFiles = (fileItems: InternalFileItem[], file: InternalFileItem) => {\n let startIndex = 0;\n\n try {\n startIndex = fileItems.findIndex((item) => item.id === file.id);\n\n const items: OpenMediaItem[] = fileItems.map((item) => ({\n url: item.uploadedFile?.url.replace('_0.mp4', '.mp4') ?? '',\n mediaType:\n item.uploadedFile && 'thumbnailUrl' in item.uploadedFile\n ? MediaType.VIDEO\n : MediaType.IMAGE,\n }));\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n void openMedia({ items, startIndex });\n } catch (_) {\n if (file.uploadedFile && 'thumbnailUrl' in file.uploadedFile) {\n void openVideo({ url: file.uploadedFile.url });\n\n return;\n }\n\n const imageFiles: OpenImageItem[] = [];\n\n fileItems.forEach(({ uploadedFile }) => {\n if (uploadedFile && !('thumbnailUrl' in uploadedFile)) {\n imageFiles.push({ url: uploadedFile.url });\n }\n });\n\n startIndex = imageFiles.findIndex((item) => item.url === file.uploadedFile?.url);\n\n const startFile = imageFiles.shift();\n\n if (!startFile) {\n return;\n }\n\n void openImage({ items: [startFile, ...imageFiles], startIndex });\n }\n};\n\nexport const openKnownFiles = (fileItems: FileItem[], file: FileItem) => {\n const activeFileKey = getGalleryViewerKey(file, fileItems.indexOf(file));\n let startIndex = 0;\n\n try {\n startIndex = fileItems.findIndex(\n (item, index) => getGalleryViewerKey(item, index) === activeFileKey,\n );\n\n const items: OpenMediaItem[] = fileItems.map((item) => ({\n url: item.file.url.replace('_0.mp4', '.mp4'),\n mediaType: 'thumbnailUrl' in item.file ? MediaType.VIDEO : MediaType.IMAGE,\n }));\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n void openMedia({ items, startIndex });\n } catch (_) {\n if ('thumbnailUrl' in file.file) {\n void openVideo({ url: file.file.url });\n\n return;\n }\n\n const imageFiles: OpenImageItem[] = [];\n\n fileItems.forEach((item) => {\n if (!('thumbnailUrl' in item.file)) {\n imageFiles.push({ url: item.file.url });\n }\n });\n\n startIndex = imageFiles.findIndex((item) => item.url === file.file.url);\n\n const startFile = imageFiles.shift();\n\n if (!startFile) {\n return;\n }\n\n void openImage({ items: [startFile, ...imageFiles], startIndex });\n }\n};\n"],"mappings":";;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AAEA,MAAME,mBAAmB,GAAG,CAAC;AAEtB,MAAMC,uBAAuB,GAAIC,KAAkB,IACtD,CAACA,KAAK,IAAI,EAAE,EAAEC,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,MAAM;EAChCC,EAAE,EAAEC,mBAAmB,CAACH,IAAI,EAAEC,KAAK,CAAC;EACpCG,YAAY,EAAEJ,IAAI,CAACA,IAAI;EACvBA,IAAI,EAAEK,SAAS;EACfC,KAAK,EAAE,UAAU;EACjBC,UAAU,EAAEF;AAChB,CAAC,CAAC,CAAC;AAACG,OAAA,CAAAX,uBAAA,GAAAA,uBAAA;AAED,MAAMM,mBAAmB,GAAGA,CAACM,QAAkB,EAAER,KAAa,KACjEQ,QAAQ,CAACP,EAAE,IAAIO,QAAQ,CAACT,IAAI,CAACE,EAAE,IAAIO,QAAQ,CAACT,IAAI,CAACU,GAAG,IAAI,gBAAgBT,KAAK,EAAE;AAACO,OAAA,CAAAL,mBAAA,GAAAA,mBAAA;AAE7E,MAAMQ,eAAe,GAAIC,SAAqB,IAAa;EAAA,IAAAC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AOW,CAAC,EAAE;IACR,IAAI,cAAc,IAAIpC,IAAI,CAACA,IAAI,EAAE;MAC7B,KAAK,IAAAqC,oBAAS,EAAC;QAAE3B,GAAG,EAAEV,IAAI,CAACA,IAAI,CAACU;MAAI,CAAC,CAAC;MAEtC;IACJ;IAEA,MAAM4B,UAA2B,GAAG,EAAE;IAEtC1B,SAAS,CAAC2B,OAAO,CAAEZ,IAAI,IAAK;MACxB,IAAI,EAAE,cAAc,IAAIA,IAAI,CAAC3B,IAAI,CAAC,EAAE;QAChCsC,UAAU,CAACE,IAAI,CAAC;UAAE9B,GAAG,EAAEiB,IAAI,CAAC3B,IAAI,CAACU;QAAI,CAAC,CAAC;MAC3C;IACJ,CAAC,CAAC;IAEFe,UAAU,GAAGa,UAAU,CAACZ,SAAS,CAAEC,IAAI,IAAKA,IAAI,CAACjB,GAAG,KAAKV,IAAI,CAACA,IAAI,CAACU,GAAG,CAAC;IAEvE,MAAMgC,SAAS,GAAGJ,UAAU,CAACK,KAAK,CAAC,CAAC;IAEpC,IAAI,CAACD,SAAS,EAAE;MACZ;IACJ;IAEA,KAAK,IAAAE,oBAAS,EAAC;MAAEhB,KAAK,EAAE,CAACc,SAAS,EAAE,GAAGJ,UAAU,CAAC;MAAEb;IAAW,CAAC,CAAC;EACrE;AACJ,CAAC;AAACjB,OAAA,CAAAqC,cAAA,GAAAA,cAAA","ignoreList":[]}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import GalleryEditor from './gallery-editor/GalleryEditor';
|
|
3
|
+
import GalleryViewer from './gallery-viewer/GalleryViewer';
|
|
5
4
|
import { GalleryViewMode } from '../types/gallery';
|
|
6
|
-
import { filterDuplicateFile, generatePreviewUrl, generateVideoThumbnail } from '../utils/file';
|
|
7
|
-
import AddFile from './add-file/AddFile';
|
|
8
|
-
import GalleryItem from './gallery-item/GalleryItem';
|
|
9
|
-
import { StyledGallery, StyledGalleryEditModeWrapper, StyledGalleryItemWrapper } from './Gallery.styles';
|
|
10
5
|
const Gallery = ({
|
|
11
6
|
allowDragAndDrop = false,
|
|
12
7
|
doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',
|
|
@@ -18,317 +13,19 @@ const Gallery = ({
|
|
|
18
13
|
onFileCountChange,
|
|
19
14
|
onRemove,
|
|
20
15
|
viewMode = GalleryViewMode.GRID
|
|
21
|
-
}) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
return prevFile;
|
|
36
|
-
}));
|
|
37
|
-
};
|
|
38
|
-
const callDuplicateFileDialog = useCallback(() => {
|
|
39
|
-
createDialog({
|
|
40
|
-
type: DialogType.ALERT,
|
|
41
|
-
text: doubleFileDialogMessage
|
|
42
|
-
});
|
|
43
|
-
}, [doubleFileDialogMessage]);
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* This function adds uploaded files to fileItems
|
|
47
|
-
*/
|
|
48
|
-
const handleUploadFileCallback = useCallback((file, uploadedFile) => {
|
|
49
|
-
setFileItems(prevState => {
|
|
50
|
-
const updatedState = prevState.map(prevFile => {
|
|
51
|
-
if (prevFile.uploadedFile?.url === uploadedFile.url) {
|
|
52
|
-
callDuplicateFileDialog();
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
if (prevFile.id === file.id) {
|
|
56
|
-
if (typeof onAdd === 'function') {
|
|
57
|
-
const prevElement = prevState.find(({
|
|
58
|
-
uploadedFile: newUploadedFile
|
|
59
|
-
}) => newUploadedFile?.url === uploadedFile?.url);
|
|
60
|
-
if (!prevElement) {
|
|
61
|
-
onAdd({
|
|
62
|
-
file: uploadedFile,
|
|
63
|
-
id: file.id
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
...prevFile,
|
|
69
|
-
uploadedFile,
|
|
70
|
-
state: 'uploaded'
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return prevFile;
|
|
74
|
-
});
|
|
75
|
-
const tmp = [];
|
|
76
|
-
updatedState.forEach(updatedFile => {
|
|
77
|
-
if (updatedFile !== undefined) {
|
|
78
|
-
tmp.push(updatedFile);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return tmp ?? [];
|
|
82
|
-
});
|
|
83
|
-
}, [callDuplicateFileDialog, onAdd]);
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Returns the current count to check if all files are uploaded
|
|
87
|
-
*/
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
if (typeof onFileCountChange === 'function') {
|
|
90
|
-
onFileCountChange(fileItems.length);
|
|
91
|
-
}
|
|
92
|
-
}, [fileItems.length, onFileCountChange]);
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Prepares files for previewUrl and upload
|
|
96
|
-
*/
|
|
97
|
-
useEffect(() => {
|
|
98
|
-
const filesToGeneratePreview = fileItems.filter(file => file.file && !file.previewUrl && (file.state === 'none' || !file.state));
|
|
99
|
-
const filesToUpload = fileItems.filter(file => !file.uploadedFile && file.state !== 'uploading');
|
|
100
|
-
filesToGeneratePreview.forEach(file => {
|
|
101
|
-
if (!file.file) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (file.file.type.includes('video/')) {
|
|
105
|
-
generateVideoThumbnail({
|
|
106
|
-
file: file.file,
|
|
107
|
-
callback: previewUrl => handlePreviewUrlCallback(previewUrl, file)
|
|
108
|
-
});
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
generatePreviewUrl({
|
|
112
|
-
file: file.file,
|
|
113
|
-
callback: previewUrl => handlePreviewUrlCallback(previewUrl, file)
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
filesToUpload.forEach(file => {
|
|
117
|
-
setFileItems(prevState => prevState.map(prevFile => {
|
|
118
|
-
if (prevFile.id === file.id) {
|
|
119
|
-
return {
|
|
120
|
-
...prevFile,
|
|
121
|
-
state: 'uploading'
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
return prevFile;
|
|
125
|
-
}));
|
|
126
|
-
void uploadFile({
|
|
127
|
-
fileToUpload: file,
|
|
128
|
-
callback: UploadedFile => handleUploadFileCallback(file, UploadedFile)
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
}, [fileItems, handleUploadFileCallback]);
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* This function formats and adds files to fileItems
|
|
135
|
-
*/
|
|
136
|
-
const handleAddFiles = useCallback(filesToAdd => {
|
|
137
|
-
const newFileItems = [];
|
|
138
|
-
filesToAdd.forEach(file => {
|
|
139
|
-
if (file && !filterDuplicateFile({
|
|
140
|
-
files: fileItems,
|
|
141
|
-
newFile: file
|
|
142
|
-
})) {
|
|
143
|
-
newFileItems.push({
|
|
144
|
-
id: uuidv4(),
|
|
145
|
-
file,
|
|
146
|
-
state: 'none'
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
let tmp = newFileItems;
|
|
151
|
-
if (maxFiles) {
|
|
152
|
-
tmp = newFileItems.slice(0, maxFiles - (fileItems.length + filesToAdd.length - 1));
|
|
153
|
-
}
|
|
154
|
-
setFileItems(prevState => [...prevState, ...tmp]);
|
|
155
|
-
}, [fileItems, maxFiles]);
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* This function adds external files to fileItems
|
|
159
|
-
*/
|
|
160
|
-
useEffect(() => {
|
|
161
|
-
if (files) {
|
|
162
|
-
const newFileItems = [];
|
|
163
|
-
files.forEach(file => {
|
|
164
|
-
newFileItems.push({
|
|
165
|
-
id: file.id ?? uuidv4(),
|
|
166
|
-
uploadedFile: file.file,
|
|
167
|
-
file: undefined,
|
|
168
|
-
state: 'uploaded',
|
|
169
|
-
previewUrl: undefined
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
setFileItems(prevState => {
|
|
173
|
-
const updatedItems = prevState.map(prevItem => {
|
|
174
|
-
const newItem = newFileItems.find(item => item.uploadedFile && item.uploadedFile.url === (prevItem.uploadedFile && prevItem.uploadedFile.url));
|
|
175
|
-
return newItem || prevItem;
|
|
176
|
-
});
|
|
177
|
-
return updatedItems.concat(newFileItems.filter(newItem => !prevState.some(prevItem => prevItem.uploadedFile && newItem.uploadedFile && prevItem.uploadedFile.url === newItem.uploadedFile.url)));
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}, [files]);
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* This function deletes a selected file from the file list
|
|
184
|
-
*/
|
|
185
|
-
const handleDeleteFile = useCallback(id => {
|
|
186
|
-
let fileToDelete;
|
|
187
|
-
const filteredFiles = fileItems.filter(file => {
|
|
188
|
-
const fileId = file.id;
|
|
189
|
-
if (fileId === id && file.uploadedFile) {
|
|
190
|
-
fileToDelete = {
|
|
191
|
-
file: file.uploadedFile,
|
|
192
|
-
id
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
return fileId !== id;
|
|
196
|
-
});
|
|
197
|
-
setFileItems(filteredFiles);
|
|
198
|
-
if (!fileToDelete || typeof onRemove !== 'function') {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
onRemove(fileToDelete);
|
|
202
|
-
}, [fileItems, onRemove]);
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* This function handles the drag and drop
|
|
206
|
-
*/
|
|
207
|
-
const handleDrop = useCallback(e => {
|
|
208
|
-
if (!allowDragAndDrop) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
e.preventDefault();
|
|
212
|
-
const draggedFiles = Array.from(e.dataTransfer.files);
|
|
213
|
-
handleAddFiles(draggedFiles);
|
|
214
|
-
}, [allowDragAndDrop, handleAddFiles]);
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Opens the files in a slideShow
|
|
218
|
-
*/
|
|
219
|
-
const openFiles = useCallback(file => {
|
|
220
|
-
let startIndex = 0;
|
|
221
|
-
try {
|
|
222
|
-
startIndex = fileItems.findIndex(item => item.id === file.id);
|
|
223
|
-
const items = fileItems.map(item => ({
|
|
224
|
-
url: item.uploadedFile?.url.replace('_0.mp4', '.mp4') ?? '',
|
|
225
|
-
mediaType: item.uploadedFile && 'thumbnailUrl' in item.uploadedFile ? MediaType.VIDEO : MediaType.IMAGE
|
|
226
|
-
}));
|
|
227
|
-
|
|
228
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
229
|
-
// @ts-ignore
|
|
230
|
-
void openMedia({
|
|
231
|
-
items,
|
|
232
|
-
startIndex
|
|
233
|
-
});
|
|
234
|
-
} catch (_) {
|
|
235
|
-
if (file.uploadedFile && 'thumbnailUrl' in file.uploadedFile) {
|
|
236
|
-
void openVideo({
|
|
237
|
-
url: file.uploadedFile.url
|
|
238
|
-
});
|
|
239
|
-
} else {
|
|
240
|
-
const imageFiles = [];
|
|
241
|
-
fileItems.forEach(({
|
|
242
|
-
uploadedFile
|
|
243
|
-
}) => {
|
|
244
|
-
if (uploadedFile && !('thumbnailUrl' in uploadedFile)) {
|
|
245
|
-
imageFiles.push({
|
|
246
|
-
url: uploadedFile.url
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
startIndex = imageFiles.findIndex(item => item.url === file.uploadedFile?.url);
|
|
251
|
-
const startFile = imageFiles.shift();
|
|
252
|
-
if (!startFile) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
void openImage({
|
|
256
|
-
items: [startFile, ...imageFiles],
|
|
257
|
-
startIndex
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}, [fileItems]);
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Returns the ratio of the single file
|
|
265
|
-
*/
|
|
266
|
-
const ratio = useMemo(() => {
|
|
267
|
-
switch (fileItems.length) {
|
|
268
|
-
case 0:
|
|
269
|
-
return 0;
|
|
270
|
-
case 1:
|
|
271
|
-
return Math.max(fileItems[0]?.uploadedFile?.ratio ?? 1, 1);
|
|
272
|
-
case 2:
|
|
273
|
-
return 2;
|
|
274
|
-
case 3:
|
|
275
|
-
return 3;
|
|
276
|
-
default:
|
|
277
|
-
return 1;
|
|
278
|
-
}
|
|
279
|
-
}, [fileItems]);
|
|
280
|
-
const galleryContent = useMemo(() => {
|
|
281
|
-
const combinedFilesLength = fileItems.length;
|
|
282
|
-
if (isEditMode) {
|
|
283
|
-
const items = fileItems.map(file => /*#__PURE__*/React.createElement(GalleryItem, {
|
|
284
|
-
key: file.id,
|
|
285
|
-
fileItem: file,
|
|
286
|
-
isEditMode: true,
|
|
287
|
-
onClick: openFiles,
|
|
288
|
-
handleDeleteFile: handleDeleteFile
|
|
289
|
-
}));
|
|
290
|
-
if (maxFiles && maxFiles <= combinedFilesLength) {
|
|
291
|
-
return items;
|
|
292
|
-
}
|
|
293
|
-
items.push(/*#__PURE__*/React.createElement(AddFile, {
|
|
294
|
-
key: "add_file",
|
|
295
|
-
onAdd: handleAddFiles
|
|
296
|
-
}));
|
|
297
|
-
return items;
|
|
298
|
-
}
|
|
299
|
-
const shortedFiles = fileItems.slice(0, 4);
|
|
300
|
-
return shortedFiles.map((file, index) => {
|
|
301
|
-
let imageRatio = 1;
|
|
302
|
-
if (viewMode === GalleryViewMode.GRID) {
|
|
303
|
-
if (combinedFilesLength === 1) {
|
|
304
|
-
imageRatio = fileItems[0]?.uploadedFile?.ratio ?? 1;
|
|
305
|
-
} else if (combinedFilesLength === 2 && (index === 0 || index === 1)) {
|
|
306
|
-
imageRatio = 0.5;
|
|
307
|
-
} else if (index === 0 && combinedFilesLength > 2 || combinedFilesLength === 3 && (index === 1 || index === 2)) {
|
|
308
|
-
imageRatio = 1.5;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return /*#__PURE__*/React.createElement(GalleryItem, {
|
|
312
|
-
key: file.id,
|
|
313
|
-
fileItem: file,
|
|
314
|
-
isEditMode: false,
|
|
315
|
-
handleDeleteFile: handleDeleteFile,
|
|
316
|
-
onClick: openFiles,
|
|
317
|
-
ratio: imageRatio,
|
|
318
|
-
remainingItemsLength: combinedFilesLength > 4 && index === 3 ? combinedFilesLength : undefined
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
}, [fileItems, isEditMode, maxFiles, handleAddFiles, openFiles, handleDeleteFile, viewMode]);
|
|
322
|
-
return useMemo(() => /*#__PURE__*/React.createElement(StyledGallery, null, isEditMode ? /*#__PURE__*/React.createElement(StyledGalleryEditModeWrapper, {
|
|
323
|
-
$fileMinWidth: fileMinWidth,
|
|
324
|
-
onDragOver: e => e.preventDefault(),
|
|
325
|
-
onDrop: e => void handleDrop(e)
|
|
326
|
-
}, galleryContent) : /*#__PURE__*/React.createElement(StyledGalleryItemWrapper, {
|
|
327
|
-
$ratio: ratio,
|
|
328
|
-
$uploadedFileLength: fileItems.length,
|
|
329
|
-
$viewMode: viewMode
|
|
330
|
-
}, galleryContent)), [isEditMode, fileMinWidth, galleryContent, ratio, fileItems.length, viewMode, handleDrop]);
|
|
331
|
-
};
|
|
16
|
+
}) => isEditMode ? /*#__PURE__*/React.createElement(GalleryEditor, {
|
|
17
|
+
allowDragAndDrop: allowDragAndDrop,
|
|
18
|
+
doubleFileDialogMessage: doubleFileDialogMessage,
|
|
19
|
+
fileMinWidth: fileMinWidth,
|
|
20
|
+
files: files,
|
|
21
|
+
maxFiles: maxFiles,
|
|
22
|
+
onAdd: onAdd,
|
|
23
|
+
onFileCountChange: onFileCountChange,
|
|
24
|
+
onRemove: onRemove
|
|
25
|
+
}) : /*#__PURE__*/React.createElement(GalleryViewer, {
|
|
26
|
+
files: files,
|
|
27
|
+
viewMode: viewMode
|
|
28
|
+
});
|
|
332
29
|
Gallery.displayName = 'Gallery';
|
|
333
30
|
export default Gallery;
|
|
334
31
|
//# sourceMappingURL=Gallery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Gallery.js","names":["uploadFile","createDialog","DialogType","MediaType","openImage","openMedia","openVideo","React","useCallback","useEffect","useMemo","useState","v4","uuidv4","GalleryViewMode","filterDuplicateFile","generatePreviewUrl","generateVideoThumbnail","AddFile","GalleryItem","StyledGallery","StyledGalleryEditModeWrapper","StyledGalleryItemWrapper","Gallery","allowDragAndDrop","doubleFileDialogMessage","isEditMode","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","viewMode","GRID","fileItems","setFileItems","handlePreviewUrlCallback","previewUrl","file","prevState","map","prevFile","id","callDuplicateFileDialog","type","ALERT","text","handleUploadFileCallback","uploadedFile","updatedState","url","undefined","prevElement","find","newUploadedFile","state","tmp","forEach","updatedFile","push","length","filesToGeneratePreview","filter","filesToUpload","includes","callback","fileToUpload","UploadedFile","handleAddFiles","filesToAdd","newFileItems","newFile","slice","updatedItems","prevItem","newItem","item","concat","some","handleDeleteFile","fileToDelete","filteredFiles","fileId","handleDrop","e","preventDefault","draggedFiles","Array","from","dataTransfer","openFiles","startIndex","findIndex","items","replace","mediaType","VIDEO","IMAGE","_","imageFiles","startFile","shift","ratio","Math","max","galleryContent","combinedFilesLength","createElement","key","fileItem","onClick","shortedFiles","index","imageRatio","remainingItemsLength","$fileMinWidth","onDragOver","onDrop","$ratio","$uploadedFileLength","$viewMode","displayName"],"sources":["../../../src/components/Gallery.tsx"],"sourcesContent":["import {\n Image,\n uploadFile,\n Video,\n type FileItem,\n type InternalFileItem,\n} from '@chayns-components/core';\nimport {\n createDialog,\n DialogType,\n MediaType,\n openImage,\n OpenImageItem,\n openMedia,\n OpenMediaItem,\n openVideo,\n} from 'chayns-api';\nimport React, { DragEvent, FC, useCallback, useEffect, useMemo, useState } from 'react';\nimport { v4 as uuidv4 } from 'uuid';\nimport { GalleryViewMode } from '../types/gallery';\nimport { filterDuplicateFile, generatePreviewUrl, generateVideoThumbnail } from '../utils/file';\nimport AddFile from './add-file/AddFile';\nimport GalleryItem from './gallery-item/GalleryItem';\nimport {\n StyledGallery,\n StyledGalleryEditModeWrapper,\n StyledGalleryItemWrapper,\n} from './Gallery.styles';\n\nexport type GalleryProps = {\n /**\n * Whether drag and drop is allowed or not\n */\n allowDragAndDrop?: boolean;\n /**\n * The message that should be displayed if a File is already given.\n */\n doubleFileDialogMessage?: string;\n /**\n * The minimum width of a file in the edit mode\n */\n fileMinWidth?: number;\n /**\n * Images and videos which should be displayed\n */\n files?: FileItem[];\n /**\n * Whether images and videos can be edited\n */\n isEditMode?: boolean;\n /**\n * The maximum amount of images and videos that can be uploaded.\n */\n maxFiles?: number;\n /**\n * Function to be executed when files are added and uploaded\n */\n onAdd?: (file: FileItem) => void;\n /**\n * Function to be executed when the count of files are changed. Needed to check if all files are uploaded\n */\n onFileCountChange?: (fileCount: number) => void;\n /**\n * Function to be executed when a file is removed\n */\n onRemove?: (file: FileItem) => void;\n /**\n * The mode how the images should be displayed.\n */\n viewMode?: GalleryViewMode;\n};\n\nconst Gallery: FC<GalleryProps> = ({\n allowDragAndDrop = false,\n doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',\n isEditMode = false,\n fileMinWidth = 100,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n viewMode = GalleryViewMode.GRID,\n}) => {\n const [fileItems, setFileItems] = useState<InternalFileItem[]>([]);\n\n /**\n * This function adds a previewUrl to fileItems\n */\n const handlePreviewUrlCallback = (previewUrl: string, file: InternalFileItem) => {\n setFileItems((prevState) =>\n prevState.map((prevFile) => {\n if (prevFile.id === file.id) {\n return { ...prevFile, previewUrl };\n }\n return prevFile;\n }),\n );\n };\n\n const callDuplicateFileDialog = useCallback(() => {\n createDialog({ type: DialogType.ALERT, text: doubleFileDialogMessage });\n }, [doubleFileDialogMessage]);\n\n /**\n * This function adds uploaded files to fileItems\n */\n const handleUploadFileCallback = useCallback(\n (file: InternalFileItem, uploadedFile: Video | Image) => {\n setFileItems((prevState) => {\n const updatedState = prevState.map((prevFile) => {\n if (prevFile.uploadedFile?.url === uploadedFile.url) {\n callDuplicateFileDialog();\n\n return undefined;\n }\n\n if (prevFile.id === file.id) {\n if (typeof onAdd === 'function') {\n const prevElement = prevState.find(\n ({ uploadedFile: newUploadedFile }) =>\n newUploadedFile?.url === uploadedFile?.url,\n );\n\n if (!prevElement) {\n onAdd({\n file: uploadedFile,\n id: file.id,\n });\n }\n }\n\n return {\n ...prevFile,\n uploadedFile,\n state: 'uploaded',\n };\n }\n\n return prevFile;\n });\n\n const tmp: InternalFileItem[] = [];\n\n updatedState.forEach((updatedFile) => {\n if (updatedFile !== undefined) {\n tmp.push(updatedFile as InternalFileItem);\n }\n });\n\n return tmp ?? [];\n });\n },\n [callDuplicateFileDialog, onAdd],\n );\n\n /**\n * Returns the current count to check if all files are uploaded\n */\n useEffect(() => {\n if (typeof onFileCountChange === 'function') {\n onFileCountChange(fileItems.length);\n }\n }, [fileItems.length, onFileCountChange]);\n\n /**\n * Prepares files for previewUrl and upload\n */\n useEffect(() => {\n const filesToGeneratePreview = fileItems.filter(\n (file) => file.file && !file.previewUrl && (file.state === 'none' || !file.state),\n );\n\n const filesToUpload = fileItems.filter(\n (file) => !file.uploadedFile && file.state !== 'uploading',\n );\n\n filesToGeneratePreview.forEach((file) => {\n if (!file.file) {\n return;\n }\n\n if (file.file.type.includes('video/')) {\n generateVideoThumbnail({\n file: file.file,\n callback: (previewUrl) => handlePreviewUrlCallback(previewUrl, file),\n });\n\n return;\n }\n\n generatePreviewUrl({\n file: file.file,\n callback: (previewUrl) => handlePreviewUrlCallback(previewUrl, file),\n });\n });\n\n filesToUpload.forEach((file) => {\n setFileItems((prevState) =>\n prevState.map((prevFile) => {\n if (prevFile.id === file.id) {\n return { ...prevFile, state: 'uploading' };\n }\n return prevFile;\n }),\n );\n\n void uploadFile({\n fileToUpload: file,\n callback: (UploadedFile) => handleUploadFileCallback(file, UploadedFile),\n });\n });\n }, [fileItems, handleUploadFileCallback]);\n\n /**\n * This function formats and adds files to fileItems\n */\n const handleAddFiles = useCallback(\n (filesToAdd: File[]) => {\n const newFileItems: InternalFileItem[] = [];\n\n filesToAdd.forEach((file) => {\n if (file && !filterDuplicateFile({ files: fileItems, newFile: file })) {\n newFileItems.push({\n id: uuidv4(),\n file,\n state: 'none',\n });\n }\n });\n\n let tmp = newFileItems;\n\n if (maxFiles) {\n tmp = newFileItems.slice(0, maxFiles - (fileItems.length + filesToAdd.length - 1));\n }\n\n setFileItems((prevState) => [...prevState, ...tmp]);\n },\n [fileItems, maxFiles],\n );\n\n /**\n * This function adds external files to fileItems\n */\n useEffect(() => {\n if (files) {\n const newFileItems: InternalFileItem[] = [];\n\n files.forEach((file) => {\n newFileItems.push({\n id: file.id ?? uuidv4(),\n uploadedFile: file.file,\n file: undefined,\n state: 'uploaded',\n previewUrl: undefined,\n });\n });\n\n setFileItems((prevState) => {\n const updatedItems = prevState.map((prevItem) => {\n const newItem = newFileItems.find(\n (item) =>\n item.uploadedFile &&\n item.uploadedFile.url ===\n (prevItem.uploadedFile && prevItem.uploadedFile.url),\n );\n return newItem || prevItem;\n });\n\n return updatedItems.concat(\n newFileItems.filter(\n (newItem) =>\n !prevState.some(\n (prevItem) =>\n prevItem.uploadedFile &&\n newItem.uploadedFile &&\n prevItem.uploadedFile.url === newItem.uploadedFile.url,\n ),\n ),\n );\n });\n }\n }, [files]);\n\n /**\n * This function deletes a selected file from the file list\n */\n const handleDeleteFile = useCallback(\n (id?: string) => {\n let fileToDelete: FileItem | undefined;\n\n const filteredFiles = fileItems.filter((file) => {\n const fileId = file.id;\n\n if (fileId === id && file.uploadedFile) {\n fileToDelete = { file: file.uploadedFile, id };\n }\n\n return fileId !== id;\n });\n\n setFileItems(filteredFiles);\n\n if (!fileToDelete || typeof onRemove !== 'function') {\n return;\n }\n\n onRemove(fileToDelete);\n },\n [fileItems, onRemove],\n );\n\n /**\n * This function handles the drag and drop\n */\n const handleDrop = useCallback(\n (e: DragEvent<HTMLDivElement>) => {\n if (!allowDragAndDrop) {\n return;\n }\n\n e.preventDefault();\n const draggedFiles = Array.from(e.dataTransfer.files);\n\n handleAddFiles(draggedFiles);\n },\n [allowDragAndDrop, handleAddFiles],\n );\n\n /**\n * Opens the files in a slideShow\n */\n const openFiles = useCallback(\n (file: InternalFileItem) => {\n let startIndex = 0;\n\n try {\n startIndex = fileItems.findIndex((item) => item.id === file.id);\n\n const items: OpenMediaItem[] = fileItems.map((item) => ({\n url: item.uploadedFile?.url.replace('_0.mp4', '.mp4') ?? '',\n mediaType:\n item.uploadedFile && 'thumbnailUrl' in item.uploadedFile\n ? MediaType.VIDEO\n : MediaType.IMAGE,\n }));\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n void openMedia({ items, startIndex });\n } catch (_) {\n if (file.uploadedFile && 'thumbnailUrl' in file.uploadedFile) {\n void openVideo({ url: file.uploadedFile.url });\n } else {\n const imageFiles: OpenImageItem[] = [];\n\n fileItems.forEach(({ uploadedFile }) => {\n if (uploadedFile && !('thumbnailUrl' in uploadedFile)) {\n imageFiles.push({ url: uploadedFile.url });\n }\n });\n\n startIndex = imageFiles.findIndex(\n (item) => item.url === file.uploadedFile?.url,\n );\n\n const startFile = imageFiles.shift();\n\n if (!startFile) {\n return;\n }\n\n void openImage({ items: [startFile, ...imageFiles], startIndex });\n }\n }\n },\n [fileItems],\n );\n\n /**\n * Returns the ratio of the single file\n */\n const ratio = useMemo(() => {\n switch (fileItems.length) {\n case 0:\n return 0;\n case 1:\n return Math.max(fileItems[0]?.uploadedFile?.ratio ?? 1, 1);\n case 2:\n return 2;\n case 3:\n return 3;\n default:\n return 1;\n }\n }, [fileItems]);\n\n const galleryContent = useMemo(() => {\n const combinedFilesLength = fileItems.length;\n\n if (isEditMode) {\n const items = fileItems.map((file) => (\n <GalleryItem\n key={file.id}\n fileItem={file}\n isEditMode\n onClick={openFiles}\n handleDeleteFile={handleDeleteFile}\n />\n ));\n\n if (maxFiles && maxFiles <= combinedFilesLength) {\n return items;\n }\n\n items.push(<AddFile key=\"add_file\" onAdd={handleAddFiles} />);\n\n return items;\n }\n\n const shortedFiles = fileItems.slice(0, 4);\n\n return shortedFiles.map((file, index) => {\n let imageRatio = 1;\n\n if (viewMode === GalleryViewMode.GRID) {\n if (combinedFilesLength === 1) {\n imageRatio = fileItems[0]?.uploadedFile?.ratio ?? 1;\n } else if (combinedFilesLength === 2 && (index === 0 || index === 1)) {\n imageRatio = 0.5;\n } else if (\n (index === 0 && combinedFilesLength > 2) ||\n (combinedFilesLength === 3 && (index === 1 || index === 2))\n ) {\n imageRatio = 1.5;\n }\n }\n\n return (\n <GalleryItem\n key={file.id}\n fileItem={file}\n isEditMode={false}\n handleDeleteFile={handleDeleteFile}\n onClick={openFiles}\n ratio={imageRatio}\n remainingItemsLength={\n combinedFilesLength > 4 && index === 3 ? combinedFilesLength : undefined\n }\n />\n );\n });\n }, [fileItems, isEditMode, maxFiles, handleAddFiles, openFiles, handleDeleteFile, viewMode]);\n\n return useMemo(\n () => (\n <StyledGallery>\n {isEditMode ? (\n <StyledGalleryEditModeWrapper\n $fileMinWidth={fileMinWidth}\n onDragOver={(e) => e.preventDefault()}\n onDrop={(e) => void handleDrop(e)}\n >\n {galleryContent}\n </StyledGalleryEditModeWrapper>\n ) : (\n <StyledGalleryItemWrapper\n $ratio={ratio}\n $uploadedFileLength={fileItems.length}\n $viewMode={viewMode}\n >\n {galleryContent}\n </StyledGalleryItemWrapper>\n )}\n </StyledGallery>\n ),\n [isEditMode, fileMinWidth, galleryContent, ratio, fileItems.length, viewMode, handleDrop],\n );\n};\n\nGallery.displayName = 'Gallery';\n\nexport default Gallery;\n"],"mappings":"AAAA,SAEIA,UAAU,QAIP,yBAAyB;AAChC,SACIC,YAAY,EACZC,UAAU,EACVC,SAAS,EACTC,SAAS,EAETC,SAAS,EAETC,SAAS,QAC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nByE,cACqB,CAEnB,CAClB,EACD,CAAChF,UAAU,EAAEC,YAAY,EAAE+E,cAAc,EAAEH,KAAK,EAAEpE,SAAS,CAAC0B,MAAM,EAAE5B,QAAQ,EAAEmD,UAAU,CAC5F,CAAC;AACL,CAAC;AAED7D,OAAO,CAACmG,WAAW,GAAG,SAAS;AAE/B,eAAenG,OAAO","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Gallery.js","names":["React","GalleryEditor","GalleryViewer","GalleryViewMode","Gallery","allowDragAndDrop","doubleFileDialogMessage","isEditMode","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","viewMode","GRID","createElement","displayName"],"sources":["../../../src/components/Gallery.tsx"],"sourcesContent":["import React, { FC } from 'react';\nimport GalleryEditor from './gallery-editor/GalleryEditor';\nimport GalleryViewer from './gallery-viewer/GalleryViewer';\nimport type { GalleryProps } from './Gallery.types';\nimport { GalleryViewMode } from '../types/gallery';\n\nconst Gallery: FC<GalleryProps> = ({\n allowDragAndDrop = false,\n doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',\n isEditMode = false,\n fileMinWidth = 100,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n viewMode = GalleryViewMode.GRID,\n}) =>\n isEditMode ? (\n <GalleryEditor\n allowDragAndDrop={allowDragAndDrop}\n doubleFileDialogMessage={doubleFileDialogMessage}\n fileMinWidth={fileMinWidth}\n files={files}\n maxFiles={maxFiles}\n onAdd={onAdd}\n onFileCountChange={onFileCountChange}\n onRemove={onRemove}\n />\n ) : (\n <GalleryViewer files={files} viewMode={viewMode} />\n );\n\nGallery.displayName = 'Gallery';\n\nexport default Gallery;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAc,OAAO;AACjC,OAAOC,aAAa,MAAM,gCAAgC;AAC1D,OAAOC,aAAa,MAAM,gCAAgC;AAE1D,SAASC,eAAe,QAAQ,kBAAkB;AAElD,MAAMC,OAAyB,GAAGA,CAAC;EAC/BC,gBAAgB,GAAG,KAAK;EACxBC,uBAAuB,GAAG,mCAAmC;EAC7DC,UAAU,GAAG,KAAK;EAClBC,YAAY,GAAG,GAAG;EAClBC,KAAK;EACLC,QAAQ;EACRC,KAAK;EACLC,iBAAiB;EACjBC,QAAQ;EACRC,QAAQ,GAAGX,eAAe,CAACY;AAC/B,CAAC,KACGR,UAAU,gBACNP,KAAA,CAAAgB,aAAA,CAACf,aAAa;EACVI,gBAAgB,EAAEA,gBAAiB;EACnCC,uBAAuB,EAAEA,uBAAwB;EACjDE,YAAY,EAAEA,YAAa;EAC3BC,KAAK,EAAEA,KAAM;EACbC,QAAQ,EAAEA,QAAS;EACnBC,KAAK,EAAEA,KAAM;EACbC,iBAAiB,EAAEA,iBAAkB;EACrCC,QAAQ,EAAEA;AAAS,CACtB,CAAC,gBAEFb,KAAA,CAAAgB,aAAA,CAACd,aAAa;EAACO,KAAK,EAAEA,KAAM;EAACK,QAAQ,EAAEA;AAAS,CAAE,CACrD;AAELV,OAAO,CAACa,WAAW,GAAG,SAAS;AAE/B,eAAeb,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Gallery.types.js","names":[],"sources":["../../../src/components/Gallery.types.ts"],"sourcesContent":["import type { FileItem } from '@chayns-components/core';\nimport type { GalleryViewMode } from '../types/gallery';\n\n/**\n * Props for the public Gallery wrapper component.\n */\nexport interface GalleryProps {\n /**\n * Enables drag and drop while the component is used in edit mode.\n * @description\n * This prop only affects the editor path. In read-only mode, drag and drop stays disabled regardless of this value.\n * @default false\n * @example\n * <Gallery allowDragAndDrop isEditMode files={files} />\n * @optional\n */\n allowDragAndDrop?: boolean;\n /**\n * Defines the dialog message that is shown when a duplicate upload is detected.\n * @description\n * The message is used by the editor when a locally added file resolves to an already known uploaded file.\n * @default 'Diese Datei ist bereits vorhanden'\n * @example\n * <Gallery doubleFileDialogMessage=\"This file already exists.\" isEditMode files={files} />\n * @optional\n */\n doubleFileDialogMessage?: string;\n /**\n * Defines the minimum width of one tile in edit mode.\n * @description\n * The editor uses this value to build its responsive grid. It has no effect in the read-only viewer.\n * @default 100\n * @example\n * <Gallery fileMinWidth={140} isEditMode files={files} />\n * @optional\n */\n fileMinWidth?: number;\n /**\n * Provides already known media items that should be rendered by the gallery.\n * @description\n * In read-only mode, these files are rendered directly from props. In edit mode, they are used as the external baseline\n * for already uploaded media while local uploads are managed internally.\n * @example\n * <Gallery files={files} />\n * @optional\n */\n files?: FileItem[];\n /**\n * Enables the editable upload mode instead of the read-only viewer mode.\n * @description\n * When set to `true`, the public wrapper renders `GalleryEditor`. Otherwise it renders `GalleryViewer`.\n * @default false\n * @example\n * <Gallery isEditMode files={files} />\n * @optional\n */\n isEditMode?: boolean;\n /**\n * Limits how many files can be managed in edit mode.\n * @description\n * Once the limit is reached, the editor hides the add-tile and does not accept more files.\n * This prop has no effect in read-only mode.\n * @example\n * <Gallery isEditMode maxFiles={6} files={files} />\n * @optional\n */\n maxFiles?: number;\n /**\n * Is called after a file has been uploaded successfully in edit mode.\n * @description\n * The callback receives the uploaded file representation that should be merged into the consuming state.\n * It is never called by the read-only viewer.\n * @example\n * <Gallery isEditMode onAdd={(file) => setFiles((prev) => [...prev, file])} />\n * @optional\n */\n onAdd?: (file: FileItem) => void;\n /**\n * Is called whenever the internal item count changes in edit mode.\n * @description\n * This includes already uploaded files and locally pending uploads that are currently managed by the editor.\n * It is useful when surrounding UI needs to know whether uploads are still in progress.\n * @example\n * <Gallery isEditMode onFileCountChange={(count) => console.log(count)} />\n * @optional\n */\n onFileCountChange?: (fileCount: number) => void;\n /**\n * Is called after an uploaded file has been removed in edit mode.\n * @description\n * The callback receives the removed uploaded file so the consuming state can remove it as well.\n * It is never called by the read-only viewer.\n * @example\n * <Gallery isEditMode onRemove={(file) => removeFile(file.id)} />\n * @optional\n */\n onRemove?: (file: FileItem) => void;\n /**\n * Defines how known media items are arranged in read-only mode.\n * @description\n * This prop only affects the viewer path. The editor always uses its dedicated editable grid layout.\n * @default GalleryViewMode.GRID\n * @example\n * <Gallery files={files} viewMode={GalleryViewMode.SQUARE} />\n * @optional\n */\n viewMode?: GalleryViewMode;\n}\n"],"mappings":"","ignoreList":[]}
|