@chayns-components/gallery 5.2.4 → 5.2.6
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 +132 -13
- package/lib/cjs/components/Gallery.js +4 -1
- package/lib/cjs/components/Gallery.js.map +1 -1
- package/lib/cjs/components/Gallery.types.js.map +1 -1
- package/lib/cjs/components/gallery-editor/GalleryEditor.constants.js +12 -0
- package/lib/cjs/components/gallery-editor/GalleryEditor.constants.js.map +1 -0
- package/lib/cjs/components/gallery-editor/GalleryEditor.js +40 -178
- package/lib/cjs/components/gallery-editor/GalleryEditor.js.map +1 -1
- package/lib/cjs/components/gallery-editor/GalleryEditor.styles.js +3 -1
- package/lib/cjs/components/gallery-editor/GalleryEditor.styles.js.map +1 -1
- package/lib/cjs/components/gallery-editor/GalleryEditor.types.js.map +1 -1
- package/lib/cjs/components/gallery-editor/GalleryEditor.utils.js +27 -0
- package/lib/cjs/components/gallery-editor/GalleryEditor.utils.js.map +1 -0
- package/lib/cjs/components/gallery-editor/add-file/AddFile.js +1 -1
- package/lib/cjs/components/gallery-editor/add-file/AddFile.js.map +1 -1
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.js +48 -19
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.js.map +1 -1
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.js +10 -3
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.js.map +1 -1
- package/lib/cjs/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.js.map +1 -1
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.js +10 -4
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.js.map +1 -1
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.types.js.map +1 -1
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.js +7 -10
- package/lib/cjs/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.js.map +1 -1
- package/lib/cjs/components/gallery-editor/useGalleryEditorState.js +161 -0
- package/lib/cjs/components/gallery-editor/useGalleryEditorState.js.map +1 -0
- package/lib/cjs/components/gallery-viewer/GalleryViewer.constants.js +8 -0
- package/lib/cjs/components/gallery-viewer/GalleryViewer.constants.js.map +1 -0
- package/lib/cjs/components/gallery-viewer/GalleryViewer.js +9 -5
- package/lib/cjs/components/gallery-viewer/GalleryViewer.js.map +1 -1
- package/lib/cjs/components/gallery-viewer/GalleryViewer.types.js.map +1 -1
- package/lib/cjs/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.js +15 -9
- package/lib/cjs/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.js.map +1 -1
- package/lib/cjs/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.types.js.map +1 -1
- package/lib/cjs/components/media-content/MediaContent.constants.js +11 -0
- package/lib/cjs/components/media-content/MediaContent.constants.js.map +1 -0
- package/lib/cjs/components/media-content/MediaContent.js +84 -21
- package/lib/cjs/components/media-content/MediaContent.js.map +1 -1
- package/lib/cjs/components/media-content/MediaContent.styles.js +37 -6
- package/lib/cjs/components/media-content/MediaContent.styles.js.map +1 -1
- package/lib/cjs/components/media-content/MediaContent.types.js.map +1 -1
- package/lib/cjs/components/media-content/MediaContent.utils.js +22 -0
- package/lib/cjs/components/media-content/MediaContent.utils.js.map +1 -0
- package/lib/cjs/utils/gallery.js +2 -2
- package/lib/cjs/utils/gallery.js.map +1 -1
- package/lib/esm/components/Gallery.js +4 -1
- package/lib/esm/components/Gallery.js.map +1 -1
- package/lib/esm/components/Gallery.types.js.map +1 -1
- package/lib/esm/components/gallery-editor/GalleryEditor.constants.js +6 -0
- package/lib/esm/components/gallery-editor/GalleryEditor.constants.js.map +1 -0
- package/lib/esm/components/gallery-editor/GalleryEditor.js +37 -174
- package/lib/esm/components/gallery-editor/GalleryEditor.js.map +1 -1
- package/lib/esm/components/gallery-editor/GalleryEditor.styles.js +3 -1
- package/lib/esm/components/gallery-editor/GalleryEditor.styles.js.map +1 -1
- package/lib/esm/components/gallery-editor/GalleryEditor.types.js.map +1 -1
- package/lib/esm/components/gallery-editor/GalleryEditor.utils.js +17 -0
- package/lib/esm/components/gallery-editor/GalleryEditor.utils.js.map +1 -0
- package/lib/esm/components/gallery-editor/add-file/AddFile.js +2 -2
- package/lib/esm/components/gallery-editor/add-file/AddFile.js.map +1 -1
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.js +47 -19
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.js.map +1 -1
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.js +9 -2
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.js.map +1 -1
- package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.js.map +1 -1
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.js +9 -4
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.js.map +1 -1
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.types.js.map +1 -1
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.js +6 -9
- package/lib/esm/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.js.map +1 -1
- package/lib/esm/components/gallery-editor/useGalleryEditorState.js +150 -0
- package/lib/esm/components/gallery-editor/useGalleryEditorState.js.map +1 -0
- package/lib/esm/components/gallery-viewer/GalleryViewer.constants.js +2 -0
- package/lib/esm/components/gallery-viewer/GalleryViewer.constants.js.map +1 -0
- package/lib/esm/components/gallery-viewer/GalleryViewer.js +10 -6
- package/lib/esm/components/gallery-viewer/GalleryViewer.js.map +1 -1
- package/lib/esm/components/gallery-viewer/GalleryViewer.types.js.map +1 -1
- package/lib/esm/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.js +14 -9
- package/lib/esm/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.js.map +1 -1
- package/lib/esm/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.types.js.map +1 -1
- package/lib/esm/components/media-content/MediaContent.constants.js +5 -0
- package/lib/esm/components/media-content/MediaContent.constants.js.map +1 -0
- package/lib/esm/components/media-content/MediaContent.js +83 -21
- package/lib/esm/components/media-content/MediaContent.js.map +1 -1
- package/lib/esm/components/media-content/MediaContent.styles.js +36 -5
- package/lib/esm/components/media-content/MediaContent.styles.js.map +1 -1
- package/lib/esm/components/media-content/MediaContent.types.js.map +1 -1
- package/lib/esm/components/media-content/MediaContent.utils.js +12 -0
- package/lib/esm/components/media-content/MediaContent.utils.js.map +1 -0
- package/lib/esm/utils/gallery.js +2 -2
- package/lib/esm/utils/gallery.js.map +1 -1
- package/lib/types/components/Gallery.types.d.ts +12 -0
- package/lib/types/components/gallery-editor/GalleryEditor.constants.d.ts +5 -0
- package/lib/types/components/gallery-editor/GalleryEditor.styles.d.ts +7 -3
- package/lib/types/components/gallery-editor/GalleryEditor.types.d.ts +11 -0
- package/lib/types/components/gallery-editor/GalleryEditor.utils.d.ts +5 -0
- package/lib/types/components/gallery-editor/add-file/AddFile.d.ts +3 -3
- package/lib/types/components/gallery-editor/add-file/AddFile.styles.d.ts +5 -3
- package/lib/types/components/gallery-editor/gallery-editor-item/GalleryEditorItem.d.ts +3 -3
- package/lib/types/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.d.ts +13 -3
- package/lib/types/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.d.ts +8 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.d.ts +3 -3
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.styles.d.ts +3 -1
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.types.d.ts +15 -0
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.d.ts +3 -3
- package/lib/types/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.styles.d.ts +12 -6
- package/lib/types/components/gallery-editor/useGalleryEditorState.d.ts +21 -0
- package/lib/types/components/gallery-viewer/GalleryViewer.constants.d.ts +1 -0
- package/lib/types/components/gallery-viewer/GalleryViewer.d.ts +3 -3
- package/lib/types/components/gallery-viewer/GalleryViewer.styles.d.ts +7 -3
- package/lib/types/components/gallery-viewer/GalleryViewer.types.d.ts +11 -0
- package/lib/types/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.d.ts +3 -3
- package/lib/types/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.styles.d.ts +2 -2
- package/lib/types/components/gallery-viewer/gallery-viewer-item/GalleryViewerItem.types.d.ts +8 -0
- package/lib/types/components/media-content/MediaContent.constants.d.ts +4 -0
- package/lib/types/components/media-content/MediaContent.d.ts +3 -3
- package/lib/types/components/media-content/MediaContent.styles.d.ts +50 -9
- package/lib/types/components/media-content/MediaContent.types.d.ts +16 -0
- package/lib/types/components/media-content/MediaContent.utils.d.ts +5 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GalleryEditor.types.js","names":[],"sources":["../../../../src/components/gallery-editor/GalleryEditor.types.ts"],"sourcesContent":["import type { FileItem } from '@chayns-components/core';\nimport type { GalleryRef } from '../Gallery.types';\n\n/**\n * Props for the editable gallery component.\n */\nexport interface GalleryEditorProps {\n /**\n * Enables drag and drop file selection inside the editor grid.\n * @description\n * When enabled, users can drop local image or video files onto the editor grid to start the upload flow.\n * @default false\n * @example\n * <GalleryEditor allowDragAndDrop 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 shown when a newly uploaded file resolves to a URL that already exists in the editor state.\n * @default 'Diese Datei ist bereits vorhanden'\n * @example\n * <GalleryEditor doubleFileDialogMessage=\"This file already exists.\" files={files} />\n * @optional\n */\n doubleFileDialogMessage?: string;\n /**\n * Defines the minimum width of one tile in the editor grid.\n * @description\n * The editor uses this value to size the responsive grid columns that hold uploaded items and the add-tile.\n * @default 100\n * @example\n * <GalleryEditor fileMinWidth={140} files={files} />\n * @optional\n */\n fileMinWidth?: number;\n /**\n * Defines the icon that is shown in the add-file tile.\n * @description\n * The editor renders this icon inside the tile that opens the file picker for adding more items.\n * @default 'fa fa-plus'\n * @example\n * <GalleryEditor addFileIcon=\"fa fa-image-circle-plus\" files={files} />\n * @optional\n */\n addFileIcon?: string;\n /**\n * Provides already uploaded media items that should be merged into the editor state.\n * @description\n * These files represent the externally known uploaded baseline. The editor may additionally hold local pending uploads.\n * @example\n * <GalleryEditor files={files} />\n * @optional\n */\n files?: FileItem[];\n /**\n * Limits how many files can be managed by the editor.\n * @description\n * After the limit is reached, the add-tile is hidden and additional file selection is ignored.\n * @example\n * <GalleryEditor files={files} maxFiles={6} />\n * @optional\n */\n maxFiles?: number;\n /**\n * Is called after a file has been uploaded successfully.\n * @description\n * The callback receives the uploaded file representation so the consuming state can persist it externally.\n * @example\n * <GalleryEditor onAdd={(file) => setFiles((prev) => [...prev, file])} />\n * @optional\n */\n onAdd?: (file: FileItem) => void;\n /**\n * Is called whenever the internal item count changes, including local pending uploads.\n * @description\n * Use this callback when surrounding UI needs to react to the number of currently managed items.\n * @example\n * <GalleryEditor onFileCountChange={(count) => console.log(count)} />\n * @optional\n */\n onFileCountChange?: (fileCount: number) => void;\n /**\n * Is called after an uploaded file has been removed.\n * @description\n * The callback receives the removed uploaded file so the consuming state can remove it from its controlled `files` array.\n * @example\n * <GalleryEditor onRemove={(file) => removeFile(file.id)} />\n * @optional\n */\n onRemove?: (file: FileItem) => void;\n}\n\nexport type GalleryEditorRef = GalleryRef;\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"GalleryEditor.types.js","names":[],"sources":["../../../../src/components/gallery-editor/GalleryEditor.types.ts"],"sourcesContent":["import type { FileItem } from '@chayns-components/core';\nimport type { GalleryRef } from '../Gallery.types';\n\n/**\n * Props for the editable gallery component.\n */\nexport interface GalleryEditorProps {\n /**\n * Enables drag and drop file selection inside the editor grid.\n * @description\n * When enabled, users can drop local image or video files onto the editor grid to start the upload flow.\n * @default false\n * @example\n * <GalleryEditor allowDragAndDrop 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 shown when a newly uploaded file resolves to a URL that already exists in the editor state.\n * @default 'Diese Datei ist bereits vorhanden'\n * @example\n * <GalleryEditor doubleFileDialogMessage=\"This file already exists.\" files={files} />\n * @optional\n */\n doubleFileDialogMessage?: string;\n /**\n * Defines the minimum width of one tile in the editor grid.\n * @description\n * The editor uses this value to size the responsive grid columns that hold uploaded items and the add-tile.\n * @default 100\n * @example\n * <GalleryEditor fileMinWidth={140} files={files} />\n * @optional\n */\n fileMinWidth?: number;\n /**\n * Defines the icon that is shown in the add-file tile.\n * @description\n * The editor renders this icon inside the tile that opens the file picker for adding more items.\n * @default 'fa fa-plus'\n * @example\n * <GalleryEditor addFileIcon=\"fa fa-image-circle-plus\" files={files} />\n * @optional\n */\n addFileIcon?: string;\n /**\n * Provides already uploaded media items that should be merged into the editor state.\n * @description\n * These files represent the externally known uploaded baseline. The editor may additionally hold local pending uploads.\n * @example\n * <GalleryEditor files={files} />\n * @optional\n */\n files?: FileItem[];\n /**\n * Controls whether the editor may load the final media assets immediately.\n * @description\n * When set to `true`, the editor behaves like the current implementation and loads the final media immediately.\n * When set to `false`, uploaded media keeps rendering previews first and delays the final image load until this flag becomes `true`.\n * @default true\n * @example\n * <GalleryEditor files={files} shouldLoadImages={false} />\n * @optional\n */\n shouldLoadImages?: boolean;\n /**\n * Limits how many files can be managed by the editor.\n * @description\n * After the limit is reached, the add-tile is hidden and additional file selection is ignored.\n * @example\n * <GalleryEditor files={files} maxFiles={6} />\n * @optional\n */\n maxFiles?: number;\n /**\n * Is called after a file has been uploaded successfully.\n * @description\n * The callback receives the uploaded file representation so the consuming state can persist it externally.\n * @example\n * <GalleryEditor onAdd={(file) => setFiles((prev) => [...prev, file])} />\n * @optional\n */\n onAdd?: (file: FileItem) => void;\n /**\n * Is called whenever the internal item count changes, including local pending uploads.\n * @description\n * Use this callback when surrounding UI needs to react to the number of currently managed items.\n * @example\n * <GalleryEditor onFileCountChange={(count) => console.log(count)} />\n * @optional\n */\n onFileCountChange?: (fileCount: number) => void;\n /**\n * Is called after an uploaded file has been removed.\n * @description\n * The callback receives the removed uploaded file so the consuming state can remove it from its controlled `files` array.\n * @example\n * <GalleryEditor onRemove={(file) => removeFile(file.id)} />\n * @optional\n */\n onRemove?: (file: FileItem) => void;\n}\n\nexport type GalleryEditorRef = GalleryRef;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const mapExternalFilesIntoInternalItems = files => (files ?? []).map((file, index) => ({
|
|
2
|
+
id: file.id ?? file.file.id ?? file.file.url ?? `gallery-item-${index}`,
|
|
3
|
+
uploadedFile: file.file,
|
|
4
|
+
file: undefined,
|
|
5
|
+
state: 'uploaded',
|
|
6
|
+
previewUrl: undefined
|
|
7
|
+
}));
|
|
8
|
+
export const mergeExternalFilesWithInternalState = (internalItems, externalItems) => {
|
|
9
|
+
const mergedItems = internalItems.map(prevItem => {
|
|
10
|
+
const matchingItem = externalItems.find(item => item.uploadedFile && prevItem.uploadedFile && item.uploadedFile.url === prevItem.uploadedFile.url);
|
|
11
|
+
return matchingItem || prevItem;
|
|
12
|
+
});
|
|
13
|
+
return mergedItems.concat(externalItems.filter(newItem => !internalItems.some(prevItem => prevItem.uploadedFile && newItem.uploadedFile && prevItem.uploadedFile.url === newItem.uploadedFile.url)));
|
|
14
|
+
};
|
|
15
|
+
export const getPendingPreviewFileItems = fileItems => fileItems.filter(file => file.file && !file.previewUrl && (file.state === 'none' || !file.state));
|
|
16
|
+
export const getPendingUploadFileItems = fileItems => fileItems.filter(file => file.file && !file.uploadedFile && file.state !== 'uploading');
|
|
17
|
+
//# sourceMappingURL=GalleryEditor.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GalleryEditor.utils.js","names":["mapExternalFilesIntoInternalItems","files","map","file","index","id","url","uploadedFile","undefined","state","previewUrl","mergeExternalFilesWithInternalState","internalItems","externalItems","mergedItems","prevItem","matchingItem","find","item","concat","filter","newItem","some","getPendingPreviewFileItems","fileItems","getPendingUploadFileItems"],"sources":["../../../../src/components/gallery-editor/GalleryEditor.utils.ts"],"sourcesContent":["import type { FileItem, InternalFileItem } from '@chayns-components/core';\n\nexport const mapExternalFilesIntoInternalItems = (files?: FileItem[]): InternalFileItem[] =>\n (files ?? []).map((file, index) => ({\n id: file.id ?? file.file.id ?? file.file.url ?? `gallery-item-${index}`,\n uploadedFile: file.file,\n file: undefined,\n state: 'uploaded',\n previewUrl: undefined,\n }));\n\nexport const mergeExternalFilesWithInternalState = (\n internalItems: InternalFileItem[],\n externalItems: InternalFileItem[],\n): InternalFileItem[] => {\n const mergedItems = internalItems.map((prevItem) => {\n const matchingItem = externalItems.find(\n (item) =>\n item.uploadedFile &&\n prevItem.uploadedFile &&\n item.uploadedFile.url === prevItem.uploadedFile.url,\n );\n\n return matchingItem || prevItem;\n });\n\n return mergedItems.concat(\n externalItems.filter(\n (newItem) =>\n !internalItems.some(\n (prevItem) =>\n prevItem.uploadedFile &&\n newItem.uploadedFile &&\n prevItem.uploadedFile.url === newItem.uploadedFile.url,\n ),\n ),\n );\n};\n\nexport const getPendingPreviewFileItems = (fileItems: InternalFileItem[]) =>\n fileItems.filter(\n (file) => file.file && !file.previewUrl && (file.state === 'none' || !file.state),\n );\n\nexport const getPendingUploadFileItems = (fileItems: InternalFileItem[]) =>\n fileItems.filter((file) => file.file && !file.uploadedFile && file.state !== 'uploading');\n"],"mappings":"AAEA,OAAO,MAAMA,iCAAiC,GAAIC,KAAkB,IAChE,CAACA,KAAK,IAAI,EAAE,EAAEC,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,MAAM;EAChCC,EAAE,EAAEF,IAAI,CAACE,EAAE,IAAIF,IAAI,CAACA,IAAI,CAACE,EAAE,IAAIF,IAAI,CAACA,IAAI,CAACG,GAAG,IAAI,gBAAgBF,KAAK,EAAE;EACvEG,YAAY,EAAEJ,IAAI,CAACA,IAAI;EACvBA,IAAI,EAAEK,SAAS;EACfC,KAAK,EAAE,UAAU;EACjBC,UAAU,EAAEF;AAChB,CAAC,CAAC,CAAC;AAEP,OAAO,MAAMG,mCAAmC,GAAGA,CAC/CC,aAAiC,EACjCC,aAAiC,KACZ;EACrB,MAAMC,WAAW,GAAGF,aAAa,CAACV,GAAG,CAAEa,QAAQ,IAAK;IAChD,MAAMC,YAAY,GAAGH,aAAa,CAACI,IAAI,CAClCC,IAAI,IACDA,IAAI,CAACX,YAAY,IACjBQ,QAAQ,CAACR,YAAY,IACrBW,IAAI,CAACX,YAAY,CAACD,GAAG,KAAKS,QAAQ,CAACR,YAAY,CAACD,GACxD,CAAC;IAED,OAAOU,YAAY,IAAID,QAAQ;EACnC,CAAC,CAAC;EAEF,OAAOD,WAAW,CAACK,MAAM,CACrBN,aAAa,CAACO,MAAM,CACfC,OAAO,IACJ,CAACT,aAAa,CAACU,IAAI,CACdP,QAAQ,IACLA,QAAQ,CAACR,YAAY,IACrBc,OAAO,CAACd,YAAY,IACpBQ,QAAQ,CAACR,YAAY,CAACD,GAAG,KAAKe,OAAO,CAACd,YAAY,CAACD,GAC3D,CACR,CACJ,CAAC;AACL,CAAC;AAED,OAAO,MAAMiB,0BAA0B,GAAIC,SAA6B,IACpEA,SAAS,CAACJ,MAAM,CACXjB,IAAI,IAAKA,IAAI,CAACA,IAAI,IAAI,CAACA,IAAI,CAACO,UAAU,KAAKP,IAAI,CAACM,KAAK,KAAK,MAAM,IAAI,CAACN,IAAI,CAACM,KAAK,CACpF,CAAC;AAEL,OAAO,MAAMgB,yBAAyB,GAAID,SAA6B,IACnEA,SAAS,CAACJ,MAAM,CAAEjB,IAAI,IAAKA,IAAI,CAACA,IAAI,IAAI,CAACA,IAAI,CAACI,YAAY,IAAIJ,IAAI,CAACM,KAAK,KAAK,WAAW,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Icon, selectFiles } from '@chayns-components/core';
|
|
2
|
-
import React, { useCallback } from 'react';
|
|
2
|
+
import React, { memo, useCallback } from 'react';
|
|
3
3
|
import { StyledAddFile, StyledAddFIleIconWrapper } from './AddFile.styles';
|
|
4
4
|
const AddFile = ({
|
|
5
5
|
addFileIcon = 'fa fa-plus',
|
|
@@ -22,5 +22,5 @@ const AddFile = ({
|
|
|
22
22
|
})));
|
|
23
23
|
};
|
|
24
24
|
AddFile.displayName = 'AddFile';
|
|
25
|
-
export default AddFile;
|
|
25
|
+
export default /*#__PURE__*/memo(AddFile);
|
|
26
26
|
//# sourceMappingURL=AddFile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AddFile.js","names":["Icon","selectFiles","React","useCallback","StyledAddFile","StyledAddFIleIconWrapper","AddFile","addFileIcon","onAdd","openSelectDialog","files","multiple","type","createElement","key","onClick","size","icons","displayName"],"sources":["../../../../../src/components/gallery-editor/add-file/AddFile.tsx"],"sourcesContent":["import { Icon, selectFiles } from '@chayns-components/core';\nimport React, { FC, useCallback } from 'react';\nimport { StyledAddFile, StyledAddFIleIconWrapper } from './AddFile.styles';\nimport type { AddFileProps } from './AddFile.types';\n\nconst AddFile: FC<AddFileProps> = ({ addFileIcon = 'fa fa-plus', onAdd }) => {\n const openSelectDialog = useCallback(async () => {\n const files = await selectFiles({\n multiple: true,\n type: 'image/*, video/*',\n });\n\n onAdd(files);\n }, [onAdd]);\n\n return (\n <StyledAddFile key=\"addButton\">\n <StyledAddFIleIconWrapper onClick={() => void openSelectDialog()}>\n <Icon size={40} icons={[addFileIcon]} />\n </StyledAddFIleIconWrapper>\n </StyledAddFile>\n );\n};\n\nAddFile.displayName = 'AddFile';\n\nexport default AddFile;\n"],"mappings":"AAAA,SAASA,IAAI,EAAEC,WAAW,QAAQ,yBAAyB;AAC3D,OAAOC,KAAK,IAAQC,WAAW,QAAQ,OAAO;
|
|
1
|
+
{"version":3,"file":"AddFile.js","names":["Icon","selectFiles","React","memo","useCallback","StyledAddFile","StyledAddFIleIconWrapper","AddFile","addFileIcon","onAdd","openSelectDialog","files","multiple","type","createElement","key","onClick","size","icons","displayName"],"sources":["../../../../../src/components/gallery-editor/add-file/AddFile.tsx"],"sourcesContent":["import { Icon, selectFiles } from '@chayns-components/core';\nimport React, { FC, memo, useCallback } from 'react';\nimport { StyledAddFile, StyledAddFIleIconWrapper } from './AddFile.styles';\nimport type { AddFileProps } from './AddFile.types';\n\nconst AddFile: FC<AddFileProps> = ({ addFileIcon = 'fa fa-plus', onAdd }) => {\n const openSelectDialog = useCallback(async () => {\n const files = await selectFiles({\n multiple: true,\n type: 'image/*, video/*',\n });\n\n onAdd(files);\n }, [onAdd]);\n\n return (\n <StyledAddFile key=\"addButton\">\n <StyledAddFIleIconWrapper onClick={() => void openSelectDialog()}>\n <Icon size={40} icons={[addFileIcon]} />\n </StyledAddFIleIconWrapper>\n </StyledAddFile>\n );\n};\n\nAddFile.displayName = 'AddFile';\n\nexport default memo(AddFile);\n"],"mappings":"AAAA,SAASA,IAAI,EAAEC,WAAW,QAAQ,yBAAyB;AAC3D,OAAOC,KAAK,IAAQC,IAAI,EAAEC,WAAW,QAAQ,OAAO;AACpD,SAASC,aAAa,EAAEC,wBAAwB,QAAQ,kBAAkB;AAG1E,MAAMC,OAAyB,GAAGA,CAAC;EAAEC,WAAW,GAAG,YAAY;EAAEC;AAAM,CAAC,KAAK;EACzE,MAAMC,gBAAgB,GAAGN,WAAW,CAAC,YAAY;IAC7C,MAAMO,KAAK,GAAG,MAAMV,WAAW,CAAC;MAC5BW,QAAQ,EAAE,IAAI;MACdC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFJ,KAAK,CAACE,KAAK,CAAC;EAChB,CAAC,EAAE,CAACF,KAAK,CAAC,CAAC;EAEX,oBACIP,KAAA,CAAAY,aAAA,CAACT,aAAa;IAACU,GAAG,EAAC;EAAW,gBAC1Bb,KAAA,CAAAY,aAAA,CAACR,wBAAwB;IAACU,OAAO,EAAEA,CAAA,KAAM,KAAKN,gBAAgB,CAAC;EAAE,gBAC7DR,KAAA,CAAAY,aAAA,CAACd,IAAI;IAACiB,IAAI,EAAE,EAAG;IAACC,KAAK,EAAE,CAACV,WAAW;EAAE,CAAE,CACjB,CACf,CAAC;AAExB,CAAC;AAEDD,OAAO,CAACY,WAAW,GAAG,SAAS;AAE/B,4BAAehB,IAAI,CAACI,OAAO,CAAC","ignoreList":[]}
|
|
@@ -1,34 +1,62 @@
|
|
|
1
1
|
import { Icon } from '@chayns-components/core';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { StyledGalleryEditorItem, StyledGalleryEditorItemDeleteButton } from './GalleryEditorItem.styles';
|
|
2
|
+
import React, { memo } from 'react';
|
|
3
|
+
import { StyledMotionGalleryEditorItem, StyledGalleryEditorItemDeleteButton } from './GalleryEditorItem.styles';
|
|
5
4
|
import GalleryEditorMediaItem from './gallery-editor-media-item/GalleryEditorMediaItem';
|
|
6
5
|
import GalleryEditorPreviewItem from './gallery-editor-preview-item/GalleryEditorPreviewItem';
|
|
6
|
+
import { GALLERY_EDITOR_DELETE_BUTTON_Z_INDEX, GALLERY_EDITOR_ITEM_FADE_DURATION_S } from '../GalleryEditor.constants';
|
|
7
7
|
const GalleryEditorItem = ({
|
|
8
8
|
fileItem,
|
|
9
9
|
handleDeleteFile,
|
|
10
|
+
shouldLoadImages = true,
|
|
10
11
|
ratio = 1,
|
|
11
12
|
onClick
|
|
12
13
|
}) => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
const shouldRenderPreview = fileItem.state === 'uploading';
|
|
15
|
+
const shouldRenderMedia = fileItem.state !== 'none' && (Boolean(fileItem.previewUrl) || Boolean(fileItem.uploadedFile));
|
|
16
|
+
let mediaContent = null;
|
|
17
|
+
if (shouldRenderPreview) {
|
|
18
|
+
mediaContent = /*#__PURE__*/React.createElement(GalleryEditorPreviewItem, {
|
|
19
|
+
ratio: ratio,
|
|
20
|
+
fileItem: fileItem
|
|
21
|
+
});
|
|
22
|
+
} else if (shouldRenderMedia) {
|
|
23
|
+
mediaContent = /*#__PURE__*/React.createElement(GalleryEditorMediaItem, {
|
|
24
|
+
fileItem: fileItem,
|
|
25
|
+
ratio: ratio,
|
|
26
|
+
openSelectedFile: onClick,
|
|
27
|
+
previewUrl: fileItem.previewUrl,
|
|
28
|
+
shouldLoadImages: shouldLoadImages
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return /*#__PURE__*/React.createElement(StyledMotionGalleryEditorItem, {
|
|
32
|
+
initial: {
|
|
33
|
+
opacity: 0,
|
|
34
|
+
scale: 0.98
|
|
35
|
+
},
|
|
36
|
+
animate: {
|
|
37
|
+
opacity: 1,
|
|
38
|
+
scale: 1
|
|
39
|
+
},
|
|
40
|
+
exit: {
|
|
41
|
+
opacity: 0,
|
|
42
|
+
scale: 0.98
|
|
43
|
+
},
|
|
44
|
+
transition: {
|
|
45
|
+
duration: GALLERY_EDITOR_ITEM_FADE_DURATION_S
|
|
46
|
+
}
|
|
47
|
+
}, mediaContent, /*#__PURE__*/React.createElement(StyledGalleryEditorItemDeleteButton, {
|
|
48
|
+
type: "button",
|
|
49
|
+
onClick: event => {
|
|
50
|
+
event.stopPropagation();
|
|
51
|
+
handleDeleteFile(fileItem.id);
|
|
52
|
+
},
|
|
53
|
+
$zIndex: GALLERY_EDITOR_DELETE_BUTTON_Z_INDEX,
|
|
54
|
+
"aria-label": "Bild entfernen"
|
|
25
55
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
26
56
|
size: 20,
|
|
27
57
|
icons: ['ts-wrong']
|
|
28
|
-
}))
|
|
29
|
-
initial: false
|
|
30
|
-
}, mediaContent));
|
|
58
|
+
})));
|
|
31
59
|
};
|
|
32
60
|
GalleryEditorItem.displayName = 'GalleryEditorItem';
|
|
33
|
-
export default GalleryEditorItem;
|
|
61
|
+
export default /*#__PURE__*/memo(GalleryEditorItem);
|
|
34
62
|
//# sourceMappingURL=GalleryEditorItem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GalleryEditorItem.js","names":["Icon","
|
|
1
|
+
{"version":3,"file":"GalleryEditorItem.js","names":["Icon","React","memo","StyledMotionGalleryEditorItem","StyledGalleryEditorItemDeleteButton","GalleryEditorMediaItem","GalleryEditorPreviewItem","GALLERY_EDITOR_DELETE_BUTTON_Z_INDEX","GALLERY_EDITOR_ITEM_FADE_DURATION_S","GalleryEditorItem","fileItem","handleDeleteFile","shouldLoadImages","ratio","onClick","shouldRenderPreview","state","shouldRenderMedia","Boolean","previewUrl","uploadedFile","mediaContent","createElement","openSelectedFile","initial","opacity","scale","animate","exit","transition","duration","type","event","stopPropagation","id","$zIndex","size","icons","displayName"],"sources":["../../../../../src/components/gallery-editor/gallery-editor-item/GalleryEditorItem.tsx"],"sourcesContent":["import { Icon } from '@chayns-components/core';\nimport React, { FC, ReactNode, memo } from 'react';\nimport {\n StyledMotionGalleryEditorItem,\n StyledGalleryEditorItemDeleteButton,\n} from './GalleryEditorItem.styles';\nimport GalleryEditorMediaItem from './gallery-editor-media-item/GalleryEditorMediaItem';\nimport GalleryEditorPreviewItem from './gallery-editor-preview-item/GalleryEditorPreviewItem';\nimport type { GalleryEditorItemProps } from './GalleryEditorItem.types';\nimport {\n GALLERY_EDITOR_DELETE_BUTTON_Z_INDEX,\n GALLERY_EDITOR_ITEM_FADE_DURATION_S,\n} from '../GalleryEditor.constants';\n\nconst GalleryEditorItem: FC<GalleryEditorItemProps> = ({\n fileItem,\n handleDeleteFile,\n shouldLoadImages = true,\n ratio = 1,\n onClick,\n}) => {\n const shouldRenderPreview = fileItem.state === 'uploading';\n const shouldRenderMedia =\n fileItem.state !== 'none' &&\n (Boolean(fileItem.previewUrl) || Boolean(fileItem.uploadedFile));\n\n let mediaContent: ReactNode = null;\n\n if (shouldRenderPreview) {\n mediaContent = <GalleryEditorPreviewItem ratio={ratio} fileItem={fileItem} />;\n } else if (shouldRenderMedia) {\n mediaContent = (\n <GalleryEditorMediaItem\n fileItem={fileItem}\n ratio={ratio}\n openSelectedFile={onClick}\n previewUrl={fileItem.previewUrl}\n shouldLoadImages={shouldLoadImages}\n />\n );\n }\n\n return (\n <StyledMotionGalleryEditorItem\n initial={{ opacity: 0, scale: 0.98 }}\n animate={{ opacity: 1, scale: 1 }}\n exit={{ opacity: 0, scale: 0.98 }}\n transition={{ duration: GALLERY_EDITOR_ITEM_FADE_DURATION_S }}\n >\n {mediaContent}\n <StyledGalleryEditorItemDeleteButton\n type=\"button\"\n onClick={(event) => {\n event.stopPropagation();\n handleDeleteFile(fileItem.id);\n }}\n $zIndex={GALLERY_EDITOR_DELETE_BUTTON_Z_INDEX}\n aria-label=\"Bild entfernen\"\n >\n <Icon size={20} icons={['ts-wrong']} />\n </StyledGalleryEditorItemDeleteButton>\n </StyledMotionGalleryEditorItem>\n );\n};\n\nGalleryEditorItem.displayName = 'GalleryEditorItem';\n\nexport default memo(GalleryEditorItem);\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,yBAAyB;AAC9C,OAAOC,KAAK,IAAmBC,IAAI,QAAQ,OAAO;AAClD,SACIC,6BAA6B,EAC7B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AE;IAClCG,UAAU,EAAE;MAAEC,QAAQ,EAAEtB;IAAoC;EAAE,GAE7Da,YAAY,eACbpB,KAAA,CAAAqB,aAAA,CAAClB,mCAAmC;IAChC2B,IAAI,EAAC,QAAQ;IACbjB,OAAO,EAAGkB,KAAK,IAAK;MAChBA,KAAK,CAACC,eAAe,CAAC,CAAC;MACvBtB,gBAAgB,CAACD,QAAQ,CAACwB,EAAE,CAAC;IACjC,CAAE;IACFC,OAAO,EAAE5B,oCAAqC;IAC9C,cAAW;EAAgB,gBAE3BN,KAAA,CAAAqB,aAAA,CAACtB,IAAI;IAACoC,IAAI,EAAE,EAAG;IAACC,KAAK,EAAE,CAAC,UAAU;EAAE,CAAE,CACL,CACV,CAAC;AAExC,CAAC;AAED5B,iBAAiB,CAAC6B,WAAW,GAAG,mBAAmB;AAEnD,4BAAepC,IAAI,CAACO,iBAAiB,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { motion } from 'motion/react';
|
|
1
2
|
import styled from 'styled-components';
|
|
2
|
-
export const
|
|
3
|
+
export const StyledMotionGalleryEditorItem = styled(motion.div)`
|
|
3
4
|
display: flex;
|
|
4
5
|
position: relative;
|
|
5
6
|
height: 100%;
|
|
6
7
|
width: 100%;
|
|
8
|
+
overflow: hidden;
|
|
7
9
|
`;
|
|
8
10
|
export const StyledGalleryEditorItemDeleteButton = styled.button`
|
|
9
11
|
background-color: rgba(
|
|
@@ -20,9 +22,14 @@ export const StyledGalleryEditorItemDeleteButton = styled.button`
|
|
|
20
22
|
position: absolute;
|
|
21
23
|
top: 0;
|
|
22
24
|
right: 0;
|
|
23
|
-
z-index:
|
|
25
|
+
z-index: ${({
|
|
26
|
+
$zIndex
|
|
27
|
+
}) => $zIndex};
|
|
24
28
|
height: 30px;
|
|
25
29
|
width: 30px;
|
|
30
|
+
border: 0;
|
|
31
|
+
padding: 0;
|
|
32
|
+
cursor: pointer;
|
|
26
33
|
display: flex;
|
|
27
34
|
justify-content: center;
|
|
28
35
|
align-items: center;
|
package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GalleryEditorItem.styles.js","names":["styled","
|
|
1
|
+
{"version":3,"file":"GalleryEditorItem.styles.js","names":["motion","styled","StyledMotionGalleryEditorItem","div","StyledGalleryEditorItemDeleteButton","button","theme","$zIndex"],"sources":["../../../../../src/components/gallery-editor/gallery-editor-item/GalleryEditorItem.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport { motion } from 'motion/react';\nimport styled from 'styled-components';\n\nexport const StyledMotionGalleryEditorItem = styled(motion.div)`\n display: flex;\n position: relative;\n height: 100%;\n width: 100%;\n overflow: hidden;\n`;\n\ntype StyledGalleryEditorItemDeleteButtonProps = WithTheme<unknown>;\n\nexport const StyledGalleryEditorItemDeleteButton = styled.button<\n StyledGalleryEditorItemDeleteButtonProps & {\n $zIndex: number;\n }\n>`\n background-color: rgba(\n ${({ theme }: StyledGalleryEditorItemDeleteButtonProps) => theme['000-rgb']},\n 0.75\n );\n box-shadow: 0 0 0 1px\n rgba(${({ theme }: StyledGalleryEditorItemDeleteButtonProps) => theme['009-rgb']}, 0.08)\n inset;\n position: absolute;\n top: 0;\n right: 0;\n z-index: ${({ $zIndex }) => $zIndex};\n height: 30px;\n width: 30px;\n border: 0;\n padding: 0;\n cursor: pointer;\n display: flex;\n justify-content: center;\n align-items: center;\n`;\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,cAAc;AACrC,OAAOC,MAAM,MAAM,mBAAmB;AAEtC,OAAO,MAAMC,6BAA6B,GAAGD,MAAM,CAACD,MAAM,CAACG,GAAG,CAAC;AAC/D;AACA;AACA;AACA;AACA;AACA,CAAC;AAID,OAAO,MAAMC,mCAAmC,GAAGH,MAAM,CAACI,MAIzD;AACD;AACA,UAAU,CAAC;EAAEC;AAAgD,CAAC,KAAKA,KAAK,CAAC,SAAS,CAAC;AACnF;AACA;AACA;AACA,eAAe,CAAC;EAAEA;AAAgD,CAAC,KAAKA,KAAK,CAAC,SAAS,CAAC;AACxF;AACA;AACA;AACA;AACA,eAAe,CAAC;EAAEC;AAAQ,CAAC,KAAKA,OAAO;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
package/lib/esm/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GalleryEditorItem.types.js","names":[],"sources":["../../../../../src/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.ts"],"sourcesContent":["import type { InternalFileItem } from '@chayns-components/core';\n\n/**\n * Props for a single editable gallery tile.\n */\nexport interface GalleryEditorItemProps {\n /**\n * Provides the media item that should be rendered inside the tile.\n * @description\n * The item may represent a pending local upload or an already uploaded media file managed by the editor.\n * @example\n * <GalleryEditorItem fileItem={fileItem} handleDeleteFile={handleDeleteFile} onClick={handleOpen} />\n */\n fileItem: InternalFileItem;\n /**\n * Is called when the delete button is clicked in edit mode.\n * @description\n * The callback receives the internal item identifier so the editor can remove the item from its local state.\n * @example\n * <GalleryEditorItem handleDeleteFile={(id) => console.log(id)} fileItem={fileItem} onClick={handleOpen} />\n */\n handleDeleteFile: (id?: string) => void;\n /**\n * Defines the aspect ratio that should be reserved for the rendered media.\n * @description\n * Use this when the editor item should reserve a fixed tile ratio for uploaded previews.\n * @default 1\n * @example\n * <GalleryEditorItem fileItem={fileItem} handleDeleteFile={handleDeleteFile} onClick={handleOpen} ratio={1.5} />\n * @optional\n */\n ratio?: number;\n /**\n * Is called when the tile is clicked.\n * @description\n * The editor uses this callback to open the currently selected media within the slideshow flow.\n * @example\n * <GalleryEditorItem fileItem={fileItem} handleDeleteFile={handleDeleteFile} onClick={handleOpen} />\n */\n onClick: (file: InternalFileItem) => void;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"GalleryEditorItem.types.js","names":[],"sources":["../../../../../src/components/gallery-editor/gallery-editor-item/GalleryEditorItem.types.ts"],"sourcesContent":["import type { InternalFileItem } from '@chayns-components/core';\n\n/**\n * Props for a single editable gallery tile.\n */\nexport interface GalleryEditorItemProps {\n /**\n * Provides the media item that should be rendered inside the tile.\n * @description\n * The item may represent a pending local upload or an already uploaded media file managed by the editor.\n * @example\n * <GalleryEditorItem fileItem={fileItem} handleDeleteFile={handleDeleteFile} onClick={handleOpen} />\n */\n fileItem: InternalFileItem;\n /**\n * Controls whether the item may load the final media source immediately.\n * @description\n * The item forwards this flag to the shared media renderer so uploaded media can stay on the preview until loading is allowed.\n * @default true\n * @optional\n */\n shouldLoadImages?: boolean;\n /**\n * Is called when the delete button is clicked in edit mode.\n * @description\n * The callback receives the internal item identifier so the editor can remove the item from its local state.\n * @example\n * <GalleryEditorItem handleDeleteFile={(id) => console.log(id)} fileItem={fileItem} onClick={handleOpen} />\n */\n handleDeleteFile: (id?: string) => void;\n /**\n * Defines the aspect ratio that should be reserved for the rendered media.\n * @description\n * Use this when the editor item should reserve a fixed tile ratio for uploaded previews.\n * @default 1\n * @example\n * <GalleryEditorItem fileItem={fileItem} handleDeleteFile={handleDeleteFile} onClick={handleOpen} ratio={1.5} />\n * @optional\n */\n ratio?: number;\n /**\n * Is called when the tile is clicked.\n * @description\n * The editor uses this callback to open the currently selected media within the slideshow flow.\n * @example\n * <GalleryEditorItem fileItem={fileItem} handleDeleteFile={handleDeleteFile} onClick={handleOpen} />\n */\n onClick: (file: InternalFileItem) => void;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { memo } from 'react';
|
|
2
2
|
import MediaContent from '../../../media-content/MediaContent';
|
|
3
3
|
import { StyledMotionGalleryEditorMediaItem } from './GalleryEditorMediaItem.styles';
|
|
4
|
+
import { GALLERY_EDITOR_MEDIA_FADE_DURATION_S } from '../../GalleryEditor.constants';
|
|
4
5
|
const GalleryEditorMediaItem = ({
|
|
5
6
|
fileItem,
|
|
6
7
|
openSelectedFile,
|
|
8
|
+
previewUrl,
|
|
9
|
+
shouldLoadImages = true,
|
|
7
10
|
ratio
|
|
8
11
|
}) => /*#__PURE__*/React.createElement(StyledMotionGalleryEditorMediaItem, {
|
|
9
12
|
animate: {
|
|
@@ -16,14 +19,16 @@ const GalleryEditorMediaItem = ({
|
|
|
16
19
|
opacity: 0
|
|
17
20
|
},
|
|
18
21
|
transition: {
|
|
19
|
-
duration:
|
|
22
|
+
duration: GALLERY_EDITOR_MEDIA_FADE_DURATION_S
|
|
20
23
|
}
|
|
21
24
|
}, fileItem.uploadedFile && /*#__PURE__*/React.createElement(MediaContent, {
|
|
22
25
|
file: fileItem.uploadedFile,
|
|
23
26
|
onClick: () => openSelectedFile(fileItem),
|
|
24
27
|
playIconSize: 30,
|
|
25
|
-
|
|
28
|
+
previewUrl: previewUrl,
|
|
29
|
+
ratio: ratio,
|
|
30
|
+
shouldLoadImages: shouldLoadImages
|
|
26
31
|
}));
|
|
27
32
|
GalleryEditorMediaItem.displayName = 'GalleryEditorMediaItem';
|
|
28
|
-
export default GalleryEditorMediaItem;
|
|
33
|
+
export default /*#__PURE__*/memo(GalleryEditorMediaItem);
|
|
29
34
|
//# sourceMappingURL=GalleryEditorMediaItem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GalleryEditorMediaItem.js","names":["React","MediaContent","StyledMotionGalleryEditorMediaItem","GalleryEditorMediaItem","fileItem","openSelectedFile","ratio","createElement","animate","opacity","initial","exit","transition","duration","uploadedFile","file","onClick","playIconSize","displayName"],"sources":["../../../../../../src/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.tsx"],"sourcesContent":["import React, { FC } from 'react';\nimport MediaContent from '../../../media-content/MediaContent';\nimport { StyledMotionGalleryEditorMediaItem } from './GalleryEditorMediaItem.styles';\nimport type { GalleryEditorMediaItemProps } from './GalleryEditorMediaItem.types';\n\nconst GalleryEditorMediaItem: FC<GalleryEditorMediaItemProps> = ({\n fileItem,\n openSelectedFile,\n ratio,\n}) => (\n <StyledMotionGalleryEditorMediaItem\n animate={{ opacity: 1 }}\n initial={{ opacity: 0 }}\n exit={{ opacity: 0 }}\n transition={{ duration:
|
|
1
|
+
{"version":3,"file":"GalleryEditorMediaItem.js","names":["React","memo","MediaContent","StyledMotionGalleryEditorMediaItem","GALLERY_EDITOR_MEDIA_FADE_DURATION_S","GalleryEditorMediaItem","fileItem","openSelectedFile","previewUrl","shouldLoadImages","ratio","createElement","animate","opacity","initial","exit","transition","duration","uploadedFile","file","onClick","playIconSize","displayName"],"sources":["../../../../../../src/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.tsx"],"sourcesContent":["import React, { FC, memo } from 'react';\nimport MediaContent from '../../../media-content/MediaContent';\nimport { StyledMotionGalleryEditorMediaItem } from './GalleryEditorMediaItem.styles';\nimport type { GalleryEditorMediaItemProps } from './GalleryEditorMediaItem.types';\nimport { GALLERY_EDITOR_MEDIA_FADE_DURATION_S } from '../../GalleryEditor.constants';\n\nconst GalleryEditorMediaItem: FC<GalleryEditorMediaItemProps> = ({\n fileItem,\n openSelectedFile,\n previewUrl,\n shouldLoadImages = true,\n ratio,\n}) => (\n <StyledMotionGalleryEditorMediaItem\n animate={{ opacity: 1 }}\n initial={{ opacity: 0 }}\n exit={{ opacity: 0 }}\n transition={{ duration: GALLERY_EDITOR_MEDIA_FADE_DURATION_S }}\n >\n {fileItem.uploadedFile && (\n <MediaContent\n file={fileItem.uploadedFile}\n onClick={() => openSelectedFile(fileItem)}\n playIconSize={30}\n previewUrl={previewUrl}\n ratio={ratio}\n shouldLoadImages={shouldLoadImages}\n />\n )}\n </StyledMotionGalleryEditorMediaItem>\n);\n\nGalleryEditorMediaItem.displayName = 'GalleryEditorMediaItem';\n\nexport default memo(GalleryEditorMediaItem);\n"],"mappings":"AAAA,OAAOA,KAAK,IAAQC,IAAI,QAAQ,OAAO;AACvC,OAAOC,YAAY,MAAM,qCAAqC;AAC9D,SAASC,kCAAkC,QAAQ,iCAAiC;AAEpF,SAASC,oCAAoC,QAAQ,+BAA+B;AAEpF,MAAMC,sBAAuD,GAAGA,CAAC;EAC7DC,QAAQ;EACRC,gBAAgB;EAChBC,UAAU;EACVC,gBAAgB,GAAG,IAAI;EACvBC;AACJ,CAAC,kBACGV,KAAA,CAAAW,aAAA,CAACR,kCAAkC;EAC/BS,OAAO,EAAE;IAAEC,OAAO,EAAE;EAAE,CAAE;EACxBC,OAAO,EAAE;IAAED,OAAO,EAAE;EAAE,CAAE;EACxBE,IAAI,EAAE;IAAEF,OAAO,EAAE;EAAE,CAAE;EACrBG,UAAU,EAAE;IAAEC,QAAQ,EAAEb;EAAqC;AAAE,GAE9DE,QAAQ,CAACY,YAAY,iBAClBlB,KAAA,CAAAW,aAAA,CAACT,YAAY;EACTiB,IAAI,EAAEb,QAAQ,CAACY,YAAa;EAC5BE,OAAO,EAAEA,CAAA,KAAMb,gBAAgB,CAACD,QAAQ,CAAE;EAC1Ce,YAAY,EAAE,EAAG;EACjBb,UAAU,EAAEA,UAAW;EACvBE,KAAK,EAAEA,KAAM;EACbD,gBAAgB,EAAEA;AAAiB,CACtC,CAE2B,CACvC;AAEDJ,sBAAsB,CAACiB,WAAW,GAAG,wBAAwB;AAE7D,4BAAerB,IAAI,CAACI,sBAAsB,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GalleryEditorMediaItem.types.js","names":[],"sources":["../../../../../../src/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.types.ts"],"sourcesContent":["import type { InternalFileItem } from '@chayns-components/core';\n\n/**\n * Props for a rendered uploaded media item.\n */\nexport interface GalleryEditorMediaItemProps {\n /**\n * Provides the uploaded media item that should be rendered.\n * @description\n * This item is expected to contain an `uploadedFile` because pending uploads are rendered by the preview component instead.\n * @example\n * <GalleryEditorMediaItem fileItem={fileItem} onClick={handleOpen} ratio={1} />\n */\n fileItem: InternalFileItem;\n /**\n * Is called when the media tile is selected.\n * @description\n * The editor uses this callback to open the uploaded media in the slideshow flow.\n * @example\n * <GalleryEditorMediaItem fileItem={fileItem} openSelectedFile={handleOpen} ratio={1} />\n */\n openSelectedFile: (file: InternalFileItem) => void;\n /**\n * Defines the aspect ratio that should be reserved for the media.\n * @description\n * The media tile keeps this ratio reserved so the editor grid remains visually stable.\n * @example\n * <GalleryEditorMediaItem fileItem={fileItem} openSelectedFile={handleOpen} ratio={1.5} />\n */\n ratio: number;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"GalleryEditorMediaItem.types.js","names":[],"sources":["../../../../../../src/components/gallery-editor/gallery-editor-item/gallery-editor-media-item/GalleryEditorMediaItem.types.ts"],"sourcesContent":["import type { InternalFileItem } from '@chayns-components/core';\n\n/**\n * Props for a rendered uploaded media item.\n */\nexport interface GalleryEditorMediaItemProps {\n /**\n * Provides the uploaded media item that should be rendered.\n * @description\n * This item is expected to contain an `uploadedFile` because pending uploads are rendered by the preview component instead.\n * @example\n * <GalleryEditorMediaItem fileItem={fileItem} onClick={handleOpen} ratio={1} />\n */\n fileItem: InternalFileItem;\n /**\n * Controls whether the media renderer may load the final uploaded source immediately.\n * @description\n * When disabled, the shared media renderer keeps showing the preview until the parent gallery allows the final load.\n * @default true\n * @optional\n */\n shouldLoadImages?: boolean;\n /**\n * Is called when the media tile is selected.\n * @description\n * The editor uses this callback to open the uploaded media in the slideshow flow.\n * @example\n * <GalleryEditorMediaItem fileItem={fileItem} openSelectedFile={handleOpen} ratio={1} />\n */\n openSelectedFile: (file: InternalFileItem) => void;\n /**\n * Defines the aspect ratio that should be reserved for the media.\n * @description\n * The media tile keeps this ratio reserved so the editor grid remains visually stable.\n * @example\n * <GalleryEditorMediaItem fileItem={fileItem} openSelectedFile={handleOpen} ratio={1.5} />\n */\n ratio: number;\n /**\n * Provides an optional preview source that can be shown before the final uploaded media loads.\n * @description\n * This is typically the local base64 preview generated while the file is still being uploaded.\n * @optional\n */\n previewUrl?: string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SmallWaitCursor } from '@chayns-components/core';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { memo } from 'react';
|
|
3
3
|
import { StyledGalleryEditorPreviewItemImage, StyledGalleryEditorPreviewItemImageWrapper, StyledGalleryEditorPreviewItemLoadingIcon, StyledMotionGalleryEditorPreviewItem } from './GalleryEditorPreviewItem.styles';
|
|
4
|
+
import { GALLERY_EDITOR_PREVIEW_FADE_DURATION_S } from '../../GalleryEditor.constants';
|
|
4
5
|
const GalleryEditorPreviewItem = ({
|
|
5
6
|
fileItem,
|
|
6
7
|
ratio
|
|
@@ -12,14 +13,10 @@ const GalleryEditorPreviewItem = ({
|
|
|
12
13
|
opacity: 0
|
|
13
14
|
},
|
|
14
15
|
exit: {
|
|
15
|
-
opacity: 0
|
|
16
|
-
transition: {
|
|
17
|
-
duration: 3.2,
|
|
18
|
-
delay: 3.2
|
|
19
|
-
}
|
|
16
|
+
opacity: 0
|
|
20
17
|
},
|
|
21
18
|
transition: {
|
|
22
|
-
duration:
|
|
19
|
+
duration: GALLERY_EDITOR_PREVIEW_FADE_DURATION_S
|
|
23
20
|
},
|
|
24
21
|
style: {
|
|
25
22
|
position: 'absolute'
|
|
@@ -29,10 +26,10 @@ const GalleryEditorPreviewItem = ({
|
|
|
29
26
|
}, /*#__PURE__*/React.createElement(StyledGalleryEditorPreviewItemLoadingIcon, null, /*#__PURE__*/React.createElement(SmallWaitCursor, {
|
|
30
27
|
shouldHideWaitCursor: false,
|
|
31
28
|
shouldHideBackground: true
|
|
32
|
-
})), /*#__PURE__*/React.createElement(StyledGalleryEditorPreviewItemImage, {
|
|
29
|
+
})), fileItem.previewUrl && /*#__PURE__*/React.createElement(StyledGalleryEditorPreviewItemImage, {
|
|
33
30
|
draggable: false,
|
|
34
31
|
src: fileItem.previewUrl
|
|
35
32
|
})));
|
|
36
33
|
GalleryEditorPreviewItem.displayName = 'GalleryEditorPreviewItem';
|
|
37
|
-
export default GalleryEditorPreviewItem;
|
|
34
|
+
export default /*#__PURE__*/memo(GalleryEditorPreviewItem);
|
|
38
35
|
//# sourceMappingURL=GalleryEditorPreviewItem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GalleryEditorPreviewItem.js","names":["SmallWaitCursor","React","StyledGalleryEditorPreviewItemImage","StyledGalleryEditorPreviewItemImageWrapper","StyledGalleryEditorPreviewItemLoadingIcon","StyledMotionGalleryEditorPreviewItem","GalleryEditorPreviewItem","fileItem","ratio","createElement","animate","opacity","initial","exit","transition","duration","
|
|
1
|
+
{"version":3,"file":"GalleryEditorPreviewItem.js","names":["SmallWaitCursor","React","memo","StyledGalleryEditorPreviewItemImage","StyledGalleryEditorPreviewItemImageWrapper","StyledGalleryEditorPreviewItemLoadingIcon","StyledMotionGalleryEditorPreviewItem","GALLERY_EDITOR_PREVIEW_FADE_DURATION_S","GalleryEditorPreviewItem","fileItem","ratio","createElement","animate","opacity","initial","exit","transition","duration","style","position","$ratio","shouldHideWaitCursor","shouldHideBackground","previewUrl","draggable","src","displayName"],"sources":["../../../../../../src/components/gallery-editor/gallery-editor-item/gallery-editor-preview-item/GalleryEditorPreviewItem.tsx"],"sourcesContent":["import { SmallWaitCursor } from '@chayns-components/core';\nimport React, { FC, memo } from 'react';\nimport {\n StyledGalleryEditorPreviewItemImage,\n StyledGalleryEditorPreviewItemImageWrapper,\n StyledGalleryEditorPreviewItemLoadingIcon,\n StyledMotionGalleryEditorPreviewItem,\n} from './GalleryEditorPreviewItem.styles';\nimport type { GalleryEditorPreviewItemProps } from './GalleryEditorPreviewItem.types';\nimport { GALLERY_EDITOR_PREVIEW_FADE_DURATION_S } from '../../GalleryEditor.constants';\n\nconst GalleryEditorPreviewItem: FC<GalleryEditorPreviewItemProps> = ({ fileItem, ratio }) => (\n <StyledMotionGalleryEditorPreviewItem\n animate={{ opacity: 1 }}\n initial={{ opacity: 0 }}\n exit={{ opacity: 0 }}\n transition={{ duration: GALLERY_EDITOR_PREVIEW_FADE_DURATION_S }}\n style={{ position: 'absolute' }}\n >\n <StyledGalleryEditorPreviewItemImageWrapper $ratio={ratio}>\n <StyledGalleryEditorPreviewItemLoadingIcon>\n <SmallWaitCursor shouldHideWaitCursor={false} shouldHideBackground />\n </StyledGalleryEditorPreviewItemLoadingIcon>\n {fileItem.previewUrl && (\n <StyledGalleryEditorPreviewItemImage draggable={false} src={fileItem.previewUrl} />\n )}\n </StyledGalleryEditorPreviewItemImageWrapper>\n </StyledMotionGalleryEditorPreviewItem>\n);\n\nGalleryEditorPreviewItem.displayName = 'GalleryEditorPreviewItem';\n\nexport default memo(GalleryEditorPreviewItem);\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,yBAAyB;AACzD,OAAOC,KAAK,IAAQC,IAAI,QAAQ,OAAO;AACvC,SACIC,mCAAmC,EACnCC,0CAA0C,EAC1CC,yCAAyC,EACzCC,oCAAoC,QACjC,mCAAmC;AAE1C,SAASC,sCAAsC,QAAQ,+BAA+B;AAEtF,MAAMC,wBAA2D,GAAGA,CAAC;EAAEC,QAAQ;EAAEC;AAAM,CAAC,kBACpFT,KAAA,CAAAU,aAAA,CAACL,oCAAoC;EACjCM,OAAO,EAAE;IAAEC,OAAO,EAAE;EAAE,CAAE;EACxBC,OAAO,EAAE;IAAED,OAAO,EAAE;EAAE,CAAE;EACxBE,IAAI,EAAE;IAAEF,OAAO,EAAE;EAAE,CAAE;EACrBG,UAAU,EAAE;IAAEC,QAAQ,EAAEV;EAAuC,CAAE;EACjEW,KAAK,EAAE;IAAEC,QAAQ,EAAE;EAAW;AAAE,gBAEhClB,KAAA,CAAAU,aAAA,CAACP,0CAA0C;EAACgB,MAAM,EAAEV;AAAM,gBACtDT,KAAA,CAAAU,aAAA,CAACN,yCAAyC,qBACtCJ,KAAA,CAAAU,aAAA,CAACX,eAAe;EAACqB,oBAAoB,EAAE,KAAM;EAACC,oBAAoB;AAAA,CAAE,CAC7B,CAAC,EAC3Cb,QAAQ,CAACc,UAAU,iBAChBtB,KAAA,CAAAU,aAAA,CAACR,mCAAmC;EAACqB,SAAS,EAAE,KAAM;EAACC,GAAG,EAAEhB,QAAQ,CAACc;AAAW,CAAE,CAE9C,CACV,CACzC;AAEDf,wBAAwB,CAACkB,WAAW,GAAG,0BAA0B;AAEjE,4BAAexB,IAAI,CAACM,wBAAwB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { uploadFile } from '@chayns-components/core';
|
|
2
|
+
import { createDialog, DialogType } from 'chayns-api';
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
+
import { filterDuplicateFile, generatePreviewUrl, generateVideoThumbnail } from '../../utils/file';
|
|
6
|
+
import { openFiles } from '../../utils/gallery';
|
|
7
|
+
import { getPendingPreviewFileItems, getPendingUploadFileItems, mapExternalFilesIntoInternalItems, mergeExternalFilesWithInternalState } from './GalleryEditor.utils';
|
|
8
|
+
const useGalleryEditorState = ({
|
|
9
|
+
allowDragAndDrop,
|
|
10
|
+
doubleFileDialogMessage,
|
|
11
|
+
files,
|
|
12
|
+
maxFiles,
|
|
13
|
+
onAdd,
|
|
14
|
+
onFileCountChange,
|
|
15
|
+
onRemove
|
|
16
|
+
}) => {
|
|
17
|
+
const [fileItems, setFileItems] = useState(() => mapExternalFilesIntoInternalItems(files));
|
|
18
|
+
const callDuplicateFileDialog = useCallback(() => {
|
|
19
|
+
createDialog({
|
|
20
|
+
type: DialogType.ALERT,
|
|
21
|
+
text: doubleFileDialogMessage
|
|
22
|
+
});
|
|
23
|
+
}, [doubleFileDialogMessage]);
|
|
24
|
+
const handlePreviewUrlCallback = useCallback((previewUrl, file) => {
|
|
25
|
+
setFileItems(prevState => prevState.map(prevFile => prevFile.id === file.id ? {
|
|
26
|
+
...prevFile,
|
|
27
|
+
previewUrl
|
|
28
|
+
} : prevFile));
|
|
29
|
+
}, []);
|
|
30
|
+
const handleUploadFileCallback = useCallback((file, uploadedFile) => {
|
|
31
|
+
setFileItems(prevState => {
|
|
32
|
+
const duplicateItem = prevState.find(prevFile => prevFile.uploadedFile?.url === uploadedFile.url);
|
|
33
|
+
const updatedState = prevState.map(prevFile => {
|
|
34
|
+
if (prevFile.uploadedFile?.url === uploadedFile.url) {
|
|
35
|
+
callDuplicateFileDialog();
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
if (prevFile.id === file.id) {
|
|
39
|
+
if (typeof onAdd === 'function' && !duplicateItem) {
|
|
40
|
+
onAdd({
|
|
41
|
+
file: uploadedFile,
|
|
42
|
+
id: file.id
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
...prevFile,
|
|
47
|
+
uploadedFile,
|
|
48
|
+
state: 'uploaded'
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return prevFile;
|
|
52
|
+
});
|
|
53
|
+
return updatedState.filter(Boolean);
|
|
54
|
+
});
|
|
55
|
+
}, [callDuplicateFileDialog, onAdd]);
|
|
56
|
+
const filesToGeneratePreview = useMemo(() => getPendingPreviewFileItems(fileItems), [fileItems]);
|
|
57
|
+
const filesToUpload = useMemo(() => getPendingUploadFileItems(fileItems), [fileItems]);
|
|
58
|
+
const handleAddFiles = useCallback(filesToAdd => {
|
|
59
|
+
setFileItems(prevState => {
|
|
60
|
+
const newFileItems = [];
|
|
61
|
+
filesToAdd.forEach(file => {
|
|
62
|
+
if (file && !filterDuplicateFile({
|
|
63
|
+
files: prevState,
|
|
64
|
+
newFile: file
|
|
65
|
+
})) {
|
|
66
|
+
newFileItems.push({
|
|
67
|
+
id: uuidv4(),
|
|
68
|
+
file,
|
|
69
|
+
state: 'none'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const limitedFileItems = maxFiles ? newFileItems.slice(0, Math.max(maxFiles - prevState.length, 0)) : newFileItems;
|
|
74
|
+
return [...prevState, ...limitedFileItems];
|
|
75
|
+
});
|
|
76
|
+
}, [maxFiles]);
|
|
77
|
+
const handleDeleteFile = useCallback(id => {
|
|
78
|
+
let uploadedFile;
|
|
79
|
+
setFileItems(prevState => {
|
|
80
|
+
uploadedFile = prevState.find(file => file.id === id)?.uploadedFile;
|
|
81
|
+
return prevState.filter(file => file.id !== id);
|
|
82
|
+
});
|
|
83
|
+
if (uploadedFile && typeof onRemove === 'function') {
|
|
84
|
+
onRemove({
|
|
85
|
+
file: uploadedFile,
|
|
86
|
+
id
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}, [onRemove]);
|
|
90
|
+
const handleDrop = useCallback(event => {
|
|
91
|
+
if (!allowDragAndDrop) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
handleAddFiles(Array.from(event.dataTransfer.files));
|
|
96
|
+
}, [allowDragAndDrop, handleAddFiles]);
|
|
97
|
+
const handleOpenFiles = useCallback(file => {
|
|
98
|
+
openFiles(fileItems, file);
|
|
99
|
+
}, [fileItems]);
|
|
100
|
+
const handleClear = useCallback(() => {
|
|
101
|
+
setFileItems([]);
|
|
102
|
+
}, []);
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (typeof onFileCountChange === 'function') {
|
|
105
|
+
onFileCountChange(fileItems.length);
|
|
106
|
+
}
|
|
107
|
+
}, [fileItems.length, onFileCountChange]);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
filesToGeneratePreview.forEach(file => {
|
|
110
|
+
if (!file.file) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (file.file.type.includes('video/')) {
|
|
114
|
+
generateVideoThumbnail({
|
|
115
|
+
file: file.file,
|
|
116
|
+
callback: previewUrl => handlePreviewUrlCallback(previewUrl, file)
|
|
117
|
+
});
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
generatePreviewUrl({
|
|
121
|
+
file: file.file,
|
|
122
|
+
callback: previewUrl => handlePreviewUrlCallback(previewUrl, file)
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
filesToUpload.forEach(file => {
|
|
126
|
+
setFileItems(prevState => prevState.map(prevFile => prevFile.id === file.id ? {
|
|
127
|
+
...prevFile,
|
|
128
|
+
state: 'uploading'
|
|
129
|
+
} : prevFile));
|
|
130
|
+
void uploadFile({
|
|
131
|
+
fileToUpload: file,
|
|
132
|
+
callback: uploadedFile => handleUploadFileCallback(file, uploadedFile)
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}, [filesToGeneratePreview, filesToUpload, handlePreviewUrlCallback, handleUploadFileCallback]);
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
const externalFileItems = mapExternalFilesIntoInternalItems(files);
|
|
138
|
+
setFileItems(prevState => mergeExternalFilesWithInternalState(prevState, externalFileItems));
|
|
139
|
+
}, [files]);
|
|
140
|
+
return {
|
|
141
|
+
fileItems,
|
|
142
|
+
handleAddFiles,
|
|
143
|
+
handleClear,
|
|
144
|
+
handleDeleteFile,
|
|
145
|
+
handleDrop,
|
|
146
|
+
handleOpenFiles
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
export default useGalleryEditorState;
|
|
150
|
+
//# sourceMappingURL=useGalleryEditorState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGalleryEditorState.js","names":["uploadFile","createDialog","DialogType","useCallback","useEffect","useMemo","useState","v4","uuidv4","filterDuplicateFile","generatePreviewUrl","generateVideoThumbnail","openFiles","getPendingPreviewFileItems","getPendingUploadFileItems","mapExternalFilesIntoInternalItems","mergeExternalFilesWithInternalState","useGalleryEditorState","allowDragAndDrop","doubleFileDialogMessage","files","maxFiles","onAdd","onFileCountChange","onRemove","fileItems","setFileItems","callDuplicateFileDialog","type","ALERT","text","handlePreviewUrlCallback","previewUrl","file","prevState","map","prevFile","id","handleUploadFileCallback","uploadedFile","duplicateItem","find","url","updatedState","undefined","state","filter","Boolean","filesToGeneratePreview","filesToUpload","handleAddFiles","filesToAdd","newFileItems","forEach","newFile","push","limitedFileItems","slice","Math","max","length","handleDeleteFile","handleDrop","event","preventDefault","Array","from","dataTransfer","handleOpenFiles","handleClear","includes","callback","fileToUpload","externalFileItems"],"sources":["../../../../src/components/gallery-editor/useGalleryEditorState.ts"],"sourcesContent":["import {\n Image,\n uploadFile,\n Video,\n type FileItem,\n type InternalFileItem,\n} from '@chayns-components/core';\nimport { createDialog, DialogType } from 'chayns-api';\nimport { type DragEvent, useCallback, useEffect, useMemo, useState } from 'react';\nimport { v4 as uuidv4 } from 'uuid';\nimport { filterDuplicateFile, generatePreviewUrl, generateVideoThumbnail } from '../../utils/file';\nimport { openFiles } from '../../utils/gallery';\nimport {\n getPendingPreviewFileItems,\n getPendingUploadFileItems,\n mapExternalFilesIntoInternalItems,\n mergeExternalFilesWithInternalState,\n} from './GalleryEditor.utils';\n\ntype UseGalleryEditorStateOptions = {\n allowDragAndDrop: boolean;\n doubleFileDialogMessage: string;\n files?: FileItem[];\n maxFiles?: number;\n onAdd?: (file: FileItem) => void;\n onFileCountChange?: (fileCount: number) => void;\n onRemove?: (file: FileItem) => void;\n};\n\ntype GalleryEditorStateResult = {\n fileItems: InternalFileItem[];\n handleAddFiles: (filesToAdd: File[]) => void;\n handleClear: () => void;\n handleDeleteFile: (id?: string) => void;\n handleDrop: (event: DragEvent<HTMLDivElement>) => void;\n handleOpenFiles: (file: InternalFileItem) => void;\n};\n\nconst useGalleryEditorState = ({\n allowDragAndDrop,\n doubleFileDialogMessage,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n}: UseGalleryEditorStateOptions): GalleryEditorStateResult => {\n const [fileItems, setFileItems] = useState<InternalFileItem[]>(() =>\n mapExternalFilesIntoInternalItems(files),\n );\n\n const callDuplicateFileDialog = useCallback(() => {\n createDialog({ type: DialogType.ALERT, text: doubleFileDialogMessage });\n }, [doubleFileDialogMessage]);\n\n const handlePreviewUrlCallback = useCallback((previewUrl: string, file: InternalFileItem) => {\n setFileItems((prevState) =>\n prevState.map((prevFile) =>\n prevFile.id === file.id ? { ...prevFile, previewUrl } : prevFile,\n ),\n );\n }, []);\n\n const handleUploadFileCallback = useCallback(\n (file: InternalFileItem, uploadedFile: Video | Image) => {\n setFileItems((prevState) => {\n const duplicateItem = prevState.find(\n (prevFile) => prevFile.uploadedFile?.url === uploadedFile.url,\n );\n\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' && !duplicateItem) {\n onAdd({ file: uploadedFile, id: file.id });\n }\n\n return {\n ...prevFile,\n uploadedFile,\n state: 'uploaded',\n };\n }\n\n return prevFile;\n });\n\n return updatedState.filter(Boolean) as InternalFileItem[];\n });\n },\n [callDuplicateFileDialog, onAdd],\n );\n\n const filesToGeneratePreview = useMemo(\n () => getPendingPreviewFileItems(fileItems),\n [fileItems],\n );\n const filesToUpload = useMemo(() => getPendingUploadFileItems(fileItems), [fileItems]);\n\n const handleAddFiles = useCallback(\n (filesToAdd: File[]) => {\n setFileItems((prevState) => {\n const newFileItems: InternalFileItem[] = [];\n\n filesToAdd.forEach((file) => {\n if (file && !filterDuplicateFile({ files: prevState, newFile: file })) {\n newFileItems.push({\n id: uuidv4(),\n file,\n state: 'none',\n });\n }\n });\n\n const limitedFileItems = maxFiles\n ? newFileItems.slice(0, Math.max(maxFiles - prevState.length, 0))\n : newFileItems;\n\n return [...prevState, ...limitedFileItems];\n });\n },\n [maxFiles],\n );\n\n const handleDeleteFile = useCallback(\n (id?: string) => {\n let uploadedFile: Image | Video | undefined;\n\n setFileItems((prevState) => {\n uploadedFile = prevState.find((file) => file.id === id)?.uploadedFile;\n\n return prevState.filter((file) => file.id !== id);\n });\n\n if (uploadedFile && typeof onRemove === 'function') {\n onRemove({ file: uploadedFile, id });\n }\n },\n [onRemove],\n );\n\n const handleDrop = useCallback(\n (event: DragEvent<HTMLDivElement>) => {\n if (!allowDragAndDrop) {\n return;\n }\n\n event.preventDefault();\n\n handleAddFiles(Array.from(event.dataTransfer.files));\n },\n [allowDragAndDrop, handleAddFiles],\n );\n\n const handleOpenFiles = useCallback(\n (file: InternalFileItem) => {\n openFiles(fileItems, file);\n },\n [fileItems],\n );\n\n const handleClear = useCallback(() => {\n setFileItems([]);\n }, []);\n\n useEffect(() => {\n if (typeof onFileCountChange === 'function') {\n onFileCountChange(fileItems.length);\n }\n }, [fileItems.length, onFileCountChange]);\n\n useEffect(() => {\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 prevFile.id === file.id ? { ...prevFile, state: 'uploading' } : prevFile,\n ),\n );\n\n void uploadFile({\n fileToUpload: file,\n callback: (uploadedFile) => handleUploadFileCallback(file, uploadedFile),\n });\n });\n }, [filesToGeneratePreview, filesToUpload, handlePreviewUrlCallback, handleUploadFileCallback]);\n\n useEffect(() => {\n const externalFileItems = mapExternalFilesIntoInternalItems(files);\n\n setFileItems((prevState) =>\n mergeExternalFilesWithInternalState(prevState, externalFileItems),\n );\n }, [files]);\n\n return {\n fileItems,\n handleAddFiles,\n handleClear,\n handleDeleteFile,\n handleDrop,\n handleOpenFiles,\n };\n};\n\nexport default useGalleryEditorState;\n"],"mappings":"AAAA,SAEIA,UAAU,QAIP,yBAAyB;AAChC,SAASC,YAAY,EAAEC,UAAU,QAAQ,YAA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;MAAY,CAAC,GAAGT,QACpE,CACJ,CAAC;MAED,KAAKpC,UAAU,CAAC;QACZwE,YAAY,EAAEvC,IAAI;QAClBsC,QAAQ,EAAGhC,YAAY,IAAKD,wBAAwB,CAACL,IAAI,EAAEM,YAAY;MAC3E,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EAAE,CAACS,sBAAsB,EAAEC,aAAa,EAAElB,wBAAwB,EAAEO,wBAAwB,CAAC,CAAC;EAE/FlC,SAAS,CAAC,MAAM;IACZ,MAAMqE,iBAAiB,GAAG1D,iCAAiC,CAACK,KAAK,CAAC;IAElEM,YAAY,CAAEQ,SAAS,IACnBlB,mCAAmC,CAACkB,SAAS,EAAEuC,iBAAiB,CACpE,CAAC;EACL,CAAC,EAAE,CAACrD,KAAK,CAAC,CAAC;EAEX,OAAO;IACHK,SAAS;IACTyB,cAAc;IACdmB,WAAW;IACXR,gBAAgB;IAChBC,UAAU;IACVM;EACJ,CAAC;AACL,CAAC;AAED,eAAenD,qBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GalleryViewer.constants.js","names":["GALLERY_VIEWER_MAX_VISIBLE_ITEMS"],"sources":["../../../../src/components/gallery-viewer/GalleryViewer.constants.ts"],"sourcesContent":["export const GALLERY_VIEWER_MAX_VISIBLE_ITEMS = 4;\n"],"mappings":"AAAA,OAAO,MAAMA,gCAAgC,GAAG,CAAC","ignoreList":[]}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { memo, useCallback } from 'react';
|
|
2
2
|
import GalleryViewerItem from './gallery-viewer-item/GalleryViewerItem';
|
|
3
3
|
import { StyledGalleryViewer, StyledGalleryViewerItemWrapper } from './GalleryViewer.styles';
|
|
4
4
|
import { getGalleryRatio, getGalleryViewerKey, getReadOnlyItemRatio, openKnownFiles } from '../../utils/gallery';
|
|
5
5
|
import { GalleryViewMode } from '../../types/gallery';
|
|
6
|
+
import { GALLERY_VIEWER_MAX_VISIBLE_ITEMS } from './GalleryViewer.constants';
|
|
7
|
+
const EMPTY_FILE_ITEMS = [];
|
|
6
8
|
const GalleryViewer = ({
|
|
7
9
|
files,
|
|
10
|
+
shouldLoadImages = true,
|
|
8
11
|
viewMode = GalleryViewMode.GRID
|
|
9
12
|
}) => {
|
|
10
|
-
const fileItems = files ??
|
|
11
|
-
const ratio =
|
|
13
|
+
const fileItems = files ?? EMPTY_FILE_ITEMS;
|
|
14
|
+
const ratio = getGalleryRatio(fileItems);
|
|
12
15
|
const handleOpenFiles = useCallback(file => {
|
|
13
16
|
openKnownFiles(fileItems, file);
|
|
14
17
|
}, [fileItems]);
|
|
15
|
-
const visibleItems = fileItems.slice(0,
|
|
18
|
+
const visibleItems = fileItems.slice(0, GALLERY_VIEWER_MAX_VISIBLE_ITEMS);
|
|
16
19
|
return /*#__PURE__*/React.createElement(StyledGalleryViewer, null, /*#__PURE__*/React.createElement(StyledGalleryViewerItemWrapper, {
|
|
17
20
|
$ratio: ratio,
|
|
18
21
|
$itemCount: fileItems.length,
|
|
@@ -26,9 +29,10 @@ const GalleryViewer = ({
|
|
|
26
29
|
index,
|
|
27
30
|
viewMode
|
|
28
31
|
}),
|
|
29
|
-
|
|
32
|
+
shouldLoadImages: shouldLoadImages,
|
|
33
|
+
remainingItemsLength: fileItems.length > GALLERY_VIEWER_MAX_VISIBLE_ITEMS && index === 3 ? fileItems.length : undefined
|
|
30
34
|
}))));
|
|
31
35
|
};
|
|
32
36
|
GalleryViewer.displayName = 'GalleryViewer';
|
|
33
|
-
export default GalleryViewer;
|
|
37
|
+
export default /*#__PURE__*/memo(GalleryViewer);
|
|
34
38
|
//# sourceMappingURL=GalleryViewer.js.map
|