@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
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.StyledMediaContentVideoWrapper = exports.StyledMediaContentVideo = exports.StyledMediaContentPlayIcon = exports.StyledMediaContentImageWrapper = exports.StyledMediaContentImage = void 0;
|
|
6
|
+
exports.StyledMediaContentVideoWrapper = exports.StyledMediaContentVideo = exports.StyledMediaContentPreviewImage = exports.StyledMediaContentPlayIcon = exports.StyledMediaContentImageWrapper = exports.StyledMediaContentImage = void 0;
|
|
7
7
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
|
+
var _MediaContent = require("./MediaContent.constants");
|
|
8
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
10
|
const StyledMediaContentVideoWrapper = exports.StyledMediaContentVideoWrapper = _styledComponents.default.div`
|
|
10
11
|
display: flex;
|
|
12
|
+
position: relative;
|
|
13
|
+
overflow: hidden;
|
|
11
14
|
width: 100%;
|
|
12
15
|
height: 100%;
|
|
13
16
|
aspect-ratio: ${({
|
|
@@ -16,13 +19,38 @@ const StyledMediaContentVideoWrapper = exports.StyledMediaContentVideoWrapper =
|
|
|
16
19
|
`;
|
|
17
20
|
const StyledMediaContentImageWrapper = exports.StyledMediaContentImageWrapper = _styledComponents.default.div`
|
|
18
21
|
display: flex;
|
|
22
|
+
position: relative;
|
|
23
|
+
overflow: hidden;
|
|
19
24
|
width: 100%;
|
|
20
25
|
height: 100%;
|
|
21
26
|
aspect-ratio: ${({
|
|
22
27
|
$ratio
|
|
23
28
|
}) => $ratio};
|
|
24
29
|
`;
|
|
25
|
-
const
|
|
30
|
+
const StyledMediaContentLayer = _styledComponents.default.img`
|
|
31
|
+
position: absolute;
|
|
32
|
+
inset: 0;
|
|
33
|
+
width: 100%;
|
|
34
|
+
height: 100%;
|
|
35
|
+
object-fit: cover;
|
|
36
|
+
pointer-events: none;
|
|
37
|
+
`;
|
|
38
|
+
const StyledMediaContentPreviewImage = exports.StyledMediaContentPreviewImage = (0, _styledComponents.default)(StyledMediaContentLayer)`
|
|
39
|
+
background-color: ${({
|
|
40
|
+
theme
|
|
41
|
+
}) => theme['101']};
|
|
42
|
+
box-shadow: 0 0 0 1px
|
|
43
|
+
rgba(${({
|
|
44
|
+
theme
|
|
45
|
+
}) => theme['009-rgb']}, 0.08) inset;
|
|
46
|
+
z-index: 2;
|
|
47
|
+
filter: ${_MediaContent.MEDIA_CONTENT_PREVIEW_BLUR};
|
|
48
|
+
transition:
|
|
49
|
+
opacity ${_MediaContent.MEDIA_CONTENT_IMAGE_FADE_DURATION_MS}ms ease,
|
|
50
|
+
filter ${_MediaContent.MEDIA_CONTENT_PREVIEW_BLUR_REMOVE_DURATION_MS}ms ease
|
|
51
|
+
${_MediaContent.MEDIA_CONTENT_PREVIEW_BLUR_REMOVE_DELAY_MS}ms;
|
|
52
|
+
`;
|
|
53
|
+
const StyledMediaContentImage = exports.StyledMediaContentImage = (0, _styledComponents.default)(StyledMediaContentLayer)`
|
|
26
54
|
background-color: ${({
|
|
27
55
|
theme
|
|
28
56
|
}) => theme['101']};
|
|
@@ -31,9 +59,7 @@ const StyledMediaContentImage = exports.StyledMediaContentImage = _styledCompone
|
|
|
31
59
|
theme
|
|
32
60
|
}) => theme['009-rgb']}, 0.08) inset;
|
|
33
61
|
z-index: 1;
|
|
34
|
-
|
|
35
|
-
height: 100%;
|
|
36
|
-
object-fit: cover;
|
|
62
|
+
transition: opacity ${_MediaContent.MEDIA_CONTENT_IMAGE_FADE_DURATION_MS}ms ease;
|
|
37
63
|
`;
|
|
38
64
|
const StyledMediaContentVideo = exports.StyledMediaContentVideo = _styledComponents.default.video`
|
|
39
65
|
background-color: ${({
|
|
@@ -43,12 +69,17 @@ const StyledMediaContentVideo = exports.StyledMediaContentVideo = _styledCompone
|
|
|
43
69
|
rgba(${({
|
|
44
70
|
theme
|
|
45
71
|
}) => theme['009-rgb']}, 0.08) inset;
|
|
72
|
+
position: absolute;
|
|
73
|
+
inset: 0;
|
|
46
74
|
width: 100%;
|
|
75
|
+
height: 100%;
|
|
47
76
|
object-fit: cover;
|
|
77
|
+
pointer-events: none;
|
|
78
|
+
z-index: 1;
|
|
48
79
|
`;
|
|
49
80
|
const StyledMediaContentPlayIcon = exports.StyledMediaContentPlayIcon = _styledComponents.default.div`
|
|
50
81
|
position: absolute;
|
|
51
|
-
z-index:
|
|
82
|
+
z-index: 3;
|
|
52
83
|
top: 50%;
|
|
53
84
|
left: 50%;
|
|
54
85
|
transform: translate(-50%, -50%);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaContent.styles.js","names":["_styledComponents","_interopRequireDefault","require","e","__esModule","default","StyledMediaContentVideoWrapper","exports","styled","div","$ratio","StyledMediaContentImageWrapper","
|
|
1
|
+
{"version":3,"file":"MediaContent.styles.js","names":["_styledComponents","_interopRequireDefault","require","_MediaContent","e","__esModule","default","StyledMediaContentVideoWrapper","exports","styled","div","$ratio","StyledMediaContentImageWrapper","StyledMediaContentLayer","img","StyledMediaContentPreviewImage","theme","MEDIA_CONTENT_PREVIEW_BLUR","MEDIA_CONTENT_IMAGE_FADE_DURATION_MS","MEDIA_CONTENT_PREVIEW_BLUR_REMOVE_DURATION_MS","MEDIA_CONTENT_PREVIEW_BLUR_REMOVE_DELAY_MS","StyledMediaContentImage","StyledMediaContentVideo","video","StyledMediaContentPlayIcon"],"sources":["../../../../src/components/media-content/MediaContent.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled from 'styled-components';\nimport {\n MEDIA_CONTENT_IMAGE_FADE_DURATION_MS,\n MEDIA_CONTENT_PREVIEW_BLUR,\n MEDIA_CONTENT_PREVIEW_BLUR_REMOVE_DELAY_MS,\n MEDIA_CONTENT_PREVIEW_BLUR_REMOVE_DURATION_MS,\n} from './MediaContent.constants';\n\nexport const StyledMediaContentVideoWrapper = styled.div<{ $ratio: number }>`\n display: flex;\n position: relative;\n overflow: hidden;\n width: 100%;\n height: 100%;\n aspect-ratio: ${({ $ratio }) => $ratio};\n`;\n\nexport const StyledMediaContentImageWrapper = styled.div<{ $ratio: number }>`\n display: flex;\n position: relative;\n overflow: hidden;\n width: 100%;\n height: 100%;\n aspect-ratio: ${({ $ratio }) => $ratio};\n`;\n\ntype StyledMediaContentVideoProps = WithTheme<unknown>;\n\ntype StyledMediaContentImageProps = WithTheme<unknown>;\n\nconst StyledMediaContentLayer = styled.img<StyledMediaContentImageProps>`\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n object-fit: cover;\n pointer-events: none;\n`;\n\nexport const StyledMediaContentPreviewImage = styled(StyledMediaContentLayer)`\n background-color: ${({ theme }: StyledMediaContentImageProps) => theme['101']};\n box-shadow: 0 0 0 1px\n rgba(${({ theme }: StyledMediaContentImageProps) => theme['009-rgb']}, 0.08) inset;\n z-index: 2;\n filter: ${MEDIA_CONTENT_PREVIEW_BLUR};\n transition:\n opacity ${MEDIA_CONTENT_IMAGE_FADE_DURATION_MS}ms ease,\n filter ${MEDIA_CONTENT_PREVIEW_BLUR_REMOVE_DURATION_MS}ms ease\n ${MEDIA_CONTENT_PREVIEW_BLUR_REMOVE_DELAY_MS}ms;\n`;\n\nexport const StyledMediaContentImage = styled(StyledMediaContentLayer)`\n background-color: ${({ theme }: StyledMediaContentImageProps) => theme['101']};\n box-shadow: 0 0 0 1px\n rgba(${({ theme }: StyledMediaContentImageProps) => theme['009-rgb']}, 0.08) inset;\n z-index: 1;\n transition: opacity ${MEDIA_CONTENT_IMAGE_FADE_DURATION_MS}ms ease;\n`;\n\nexport const StyledMediaContentVideo = styled.video<StyledMediaContentVideoProps>`\n background-color: ${({ theme }: StyledMediaContentVideoProps) => theme['101']};\n box-shadow: 0 0 0 1px\n rgba(${({ theme }: StyledMediaContentVideoProps) => theme['009-rgb']}, 0.08) inset;\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n object-fit: cover;\n pointer-events: none;\n z-index: 1;\n`;\n\nexport const StyledMediaContentPlayIcon = styled.div`\n position: absolute;\n z-index: 3;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n`;\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAKkC,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE3B,MAAMG,8BAA8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AAC,KAAKA,KAAK,CAAC,SAAS,CAAC;AAC5E;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAEM,MAAMQ,0BAA0B,GAAAhB,OAAA,CAAAgB,0BAAA,GAAGf,yBAAM,CAACC,GAAG;AACpD;AACA;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaContent.types.js","names":[],"sources":["../../../../src/components/media-content/MediaContent.types.ts"],"sourcesContent":["import type { FileItem } from '@chayns-components/core';\n\n/**\n * Props for the low-level uploaded media renderer shared by viewer and editor.\n */\nexport interface MediaContentProps {\n /**\n * Provides the uploaded media item that should be rendered.\n * @description\n * This low-level renderer accepts already known image or video data and does not handle upload-specific state.\n * @example\n * <MediaContent file={file.file} onClick={handleOpen} ratio={1} />\n */\n file: FileItem['file'];\n /**\n * Defines the aspect ratio that should be reserved for the media.\n * @description\n * The surrounding tile uses this value to reserve a deterministic media height before the asset finishes loading.\n * @example\n * <MediaContent file={file.file} onClick={handleOpen} ratio={1.5} />\n */\n ratio: number;\n /**\n * Is called when the media tile is selected.\n * @description\n * Use this callback to react to clicks on the rendered image or video tile.\n * @example\n * <MediaContent file={file.file} onClick={() => console.log('open')} ratio={1} />\n */\n onClick: () => void;\n /**\n * Defines the size of the video play icon.\n * @description\n * This prop only affects rendered videos. Image tiles ignore it.\n * @default 50\n * @example\n * <MediaContent file={file.file} onClick={handleOpen} playIconSize={30} ratio={1} />\n * @optional\n */\n playIconSize?: number;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"MediaContent.types.js","names":[],"sources":["../../../../src/components/media-content/MediaContent.types.ts"],"sourcesContent":["import type { FileItem } from '@chayns-components/core';\n\n/**\n * Props for the low-level uploaded media renderer shared by viewer and editor.\n */\nexport interface MediaContentProps {\n /**\n * Provides the uploaded media item that should be rendered.\n * @description\n * This low-level renderer accepts already known image or video data and does not handle upload-specific state.\n * @example\n * <MediaContent file={file.file} onClick={handleOpen} ratio={1} />\n */\n file: FileItem['file'];\n /**\n * Provides an optional preview source that can be displayed while the final media is still loading.\n * @description\n * This preview can be a base64 data URL or any low-resolution fallback image.\n * When provided, the component shows the preview first and swaps to the final image once it has finished loading.\n * @optional\n */\n previewUrl?: string;\n /**\n * Defines the aspect ratio that should be reserved for the media.\n * @description\n * The surrounding tile uses this value to reserve a deterministic media height before the asset finishes loading.\n * @example\n * <MediaContent file={file.file} onClick={handleOpen} ratio={1.5} />\n */\n ratio: number;\n /**\n * Controls whether the final media source may be loaded immediately.\n * @description\n * When set to `false`, only the preview source is rendered until this flag becomes `true`.\n * @default true\n * @optional\n */\n shouldLoadImages?: boolean;\n /**\n * Is called when the media tile is selected.\n * @description\n * Use this callback to react to clicks on the rendered image or video tile.\n * @example\n * <MediaContent file={file.file} onClick={() => console.log('open')} ratio={1} />\n */\n onClick: () => void;\n /**\n * Defines the size of the video play icon.\n * @description\n * This prop only affects rendered videos. Image tiles ignore it.\n * @default 50\n * @example\n * <MediaContent file={file.file} onClick={handleOpen} playIconSize={30} ratio={1} />\n * @optional\n */\n playIconSize?: number;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isVideoFile = exports.getMediaSourceUrl = exports.getMediaPreviewUrl = void 0;
|
|
7
|
+
const isVideoFile = file => 'thumbnailUrl' in file;
|
|
8
|
+
exports.isVideoFile = isVideoFile;
|
|
9
|
+
const getMediaSourceUrl = file => file.url.replace('_0.mp4', '.mp4');
|
|
10
|
+
exports.getMediaSourceUrl = getMediaSourceUrl;
|
|
11
|
+
const getMediaPreviewUrl = (file, previewUrl) => {
|
|
12
|
+
var _file$meta;
|
|
13
|
+
if (previewUrl) {
|
|
14
|
+
return previewUrl;
|
|
15
|
+
}
|
|
16
|
+
if (isVideoFile(file)) {
|
|
17
|
+
return file.thumbnailUrl;
|
|
18
|
+
}
|
|
19
|
+
return (_file$meta = file.meta) === null || _file$meta === void 0 ? void 0 : _file$meta.preview;
|
|
20
|
+
};
|
|
21
|
+
exports.getMediaPreviewUrl = getMediaPreviewUrl;
|
|
22
|
+
//# sourceMappingURL=MediaContent.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MediaContent.utils.js","names":["isVideoFile","file","exports","getMediaSourceUrl","url","replace","getMediaPreviewUrl","previewUrl","_file$meta","thumbnailUrl","meta","preview"],"sources":["../../../../src/components/media-content/MediaContent.utils.ts"],"sourcesContent":["import type { FileItem, Video } from '@chayns-components/core';\n\nexport type GalleryMediaFile = FileItem['file'];\n\nexport const isVideoFile = (file: GalleryMediaFile): file is Video => 'thumbnailUrl' in file;\n\nexport const getMediaSourceUrl = (file: GalleryMediaFile): string =>\n file.url.replace('_0.mp4', '.mp4');\n\nexport const getMediaPreviewUrl = (\n file: GalleryMediaFile,\n previewUrl?: string,\n): string | undefined => {\n if (previewUrl) {\n return previewUrl;\n }\n\n if (isVideoFile(file)) {\n return file.thumbnailUrl;\n }\n\n return file.meta?.preview;\n};\n"],"mappings":";;;;;;AAIO,MAAMA,WAAW,GAAIC,IAAsB,IAAoB,cAAc,IAAIA,IAAI;AAACC,OAAA,CAAAF,WAAA,GAAAA,WAAA;AAEtF,MAAMG,iBAAiB,GAAIF,IAAsB,IACpDA,IAAI,CAACG,GAAG,CAACC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC;AAACH,OAAA,CAAAC,iBAAA,GAAAA,iBAAA;AAEhC,MAAMG,kBAAkB,GAAGA,CAC9BL,IAAsB,EACtBM,UAAmB,KACE;EAAA,IAAAC,UAAA;EACrB,IAAID,UAAU,EAAE;IACZ,OAAOA,UAAU;EACrB;EAEA,IAAIP,WAAW,CAACC,IAAI,CAAC,EAAE;IACnB,OAAOA,IAAI,CAACQ,YAAY;EAC5B;EAEA,QAAAD,UAAA,GAAOP,IAAI,CAACS,IAAI,cAAAF,UAAA,uBAATA,UAAA,CAAWG,OAAO;AAC7B,CAAC;AAACT,OAAA,CAAAI,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
package/lib/cjs/utils/gallery.js
CHANGED
|
@@ -63,7 +63,7 @@ const openFiles = (fileItems, file) => {
|
|
|
63
63
|
const items = fileItems.map(item => {
|
|
64
64
|
var _item$uploadedFile;
|
|
65
65
|
return {
|
|
66
|
-
url: ((_item$uploadedFile = item.uploadedFile) === null || _item$uploadedFile === void 0 ? void 0 : _item$uploadedFile.url
|
|
66
|
+
url: ((_item$uploadedFile = item.uploadedFile) === null || _item$uploadedFile === void 0 ? void 0 : _item$uploadedFile.url) ?? '',
|
|
67
67
|
mediaType: item.uploadedFile && 'thumbnailUrl' in item.uploadedFile ? _chaynsApi.MediaType.VIDEO : _chaynsApi.MediaType.IMAGE
|
|
68
68
|
};
|
|
69
69
|
});
|
|
@@ -112,7 +112,7 @@ const openKnownFiles = (fileItems, file) => {
|
|
|
112
112
|
try {
|
|
113
113
|
startIndex = fileItems.findIndex((item, index) => getGalleryViewerKey(item, index) === activeFileKey);
|
|
114
114
|
const items = fileItems.map(item => ({
|
|
115
|
-
url: item.file.url
|
|
115
|
+
url: item.file.url,
|
|
116
116
|
mediaType: 'thumbnailUrl' in item.file ? _chaynsApi.MediaType.VIDEO : _chaynsApi.MediaType.IMAGE
|
|
117
117
|
}));
|
|
118
118
|
|
|
@@ -1 +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,WAAA;EAC9D,QAAQD,SAAS,CAACE,MAAM;IACpB,KAAK,CAAC;MACF,OAAOlB,mBAAmB;IAC9B,KAAK,CAAC;MACF,OAAOmB,IAAI,CAACC,GAAG,CAAC,EAAAH,WAAA,GAAAD,SAAS,CAAC,CAAC,CAAC,cAAAC,WAAA,uBAAZA,WAAA,CAAcb,IAAI,CAACiB,KAAK,KAAIrB,mBAAmB,EAAE,CAAC,CAAC;IACvE,KAAK,CAAC;MACF,OAAO,CAAC;IACZ,KAAK,CAAC;MACF,OAAO,CAAC;IACZ;MACI,OAAOA,mBAA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E9B,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
|
+
{"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","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 ?? '',\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,\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;EAC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
14
14
|
onFileCountChange,
|
|
15
15
|
onRemove,
|
|
16
|
+
shouldLoadImages = true,
|
|
16
17
|
viewMode = GalleryViewMode.GRID
|
|
17
18
|
}, ref) => {
|
|
18
19
|
const editorRef = useRef(null);
|
|
@@ -36,9 +37,11 @@ const Gallery = /*#__PURE__*/forwardRef(({
|
|
|
36
37
|
maxFiles: maxFiles,
|
|
37
38
|
onAdd: onAdd,
|
|
38
39
|
onFileCountChange: onFileCountChange,
|
|
39
|
-
onRemove: onRemove
|
|
40
|
+
onRemove: onRemove,
|
|
41
|
+
shouldLoadImages: shouldLoadImages
|
|
40
42
|
}) : /*#__PURE__*/React.createElement(GalleryViewer, {
|
|
41
43
|
files: files,
|
|
44
|
+
shouldLoadImages: shouldLoadImages,
|
|
42
45
|
viewMode: viewMode
|
|
43
46
|
});
|
|
44
47
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Gallery.js","names":["React","forwardRef","useCallback","useImperativeHandle","useRef","GalleryEditor","GalleryViewer","GalleryViewMode","Gallery","allowDragAndDrop","addFileIcon","doubleFileDialogMessage","isEditMode","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","viewMode","GRID","ref","editorRef","handleClear","console","warn","current","clear","createElement","displayName"],"sources":["../../../src/components/Gallery.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';\nimport GalleryEditor from './gallery-editor/GalleryEditor';\nimport type { GalleryEditorRef } from './gallery-editor/GalleryEditor.types';\nimport GalleryViewer from './gallery-viewer/GalleryViewer';\nimport type { GalleryProps, GalleryRef } from './Gallery.types';\nimport { GalleryViewMode } from '../types/gallery';\n\nconst Gallery = forwardRef<GalleryRef, GalleryProps>(\n (\n {\n allowDragAndDrop = false,\n addFileIcon = 'fa fa-plus',\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 ref,\n ) => {\n const editorRef = useRef<GalleryEditorRef>(null);\n\n const handleClear = useCallback(() => {\n if (!isEditMode) {\n console.warn('Gallery.clear() can only be used in edit mode.');\n return;\n }\n\n editorRef.current?.clear();\n }, [isEditMode]);\n\n useImperativeHandle(\n ref,\n () => ({\n clear: handleClear,\n }),\n [handleClear],\n );\n\n return isEditMode ? (\n <GalleryEditor\n ref={editorRef}\n allowDragAndDrop={allowDragAndDrop}\n addFileIcon={addFileIcon}\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 },\n);\n\nGallery.displayName = 'Gallery';\n\nexport default Gallery;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,mBAAmB,EAAEC,MAAM,QAAQ,OAAO;AACnF,OAAOC,aAAa,MAAM,gCAAgC;AAE1D,OAAOC,aAAa,MAAM,gCAAgC;AAE1D,SAASC,eAAe,QAAQ,kBAAkB;AAElD,MAAMC,OAAO,gBAAGP,UAAU,CACtB,CACI;EACIQ,gBAAgB,GAAG,KAAK;EACxBC,WAAW,GAAG,YAAY;EAC1BC,uBAAuB,GAAG,mCAAmC;EAC7DC,UAAU,GAAG,KAAK;EAClBC,YAAY,GAAG,GAAG;EAClBC,KAAK;EACLC,QAAQ;EACRC,KAAK;EACLC,iBAAiB;EACjBC,QAAQ;EACRC,QAAQ,
|
|
1
|
+
{"version":3,"file":"Gallery.js","names":["React","forwardRef","useCallback","useImperativeHandle","useRef","GalleryEditor","GalleryViewer","GalleryViewMode","Gallery","allowDragAndDrop","addFileIcon","doubleFileDialogMessage","isEditMode","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","shouldLoadImages","viewMode","GRID","ref","editorRef","handleClear","console","warn","current","clear","createElement","displayName"],"sources":["../../../src/components/Gallery.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';\nimport GalleryEditor from './gallery-editor/GalleryEditor';\nimport type { GalleryEditorRef } from './gallery-editor/GalleryEditor.types';\nimport GalleryViewer from './gallery-viewer/GalleryViewer';\nimport type { GalleryProps, GalleryRef } from './Gallery.types';\nimport { GalleryViewMode } from '../types/gallery';\n\nconst Gallery = forwardRef<GalleryRef, GalleryProps>(\n (\n {\n allowDragAndDrop = false,\n addFileIcon = 'fa fa-plus',\n doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',\n isEditMode = false,\n fileMinWidth = 100,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n shouldLoadImages = true,\n viewMode = GalleryViewMode.GRID,\n },\n ref,\n ) => {\n const editorRef = useRef<GalleryEditorRef>(null);\n\n const handleClear = useCallback(() => {\n if (!isEditMode) {\n console.warn('Gallery.clear() can only be used in edit mode.');\n return;\n }\n\n editorRef.current?.clear();\n }, [isEditMode]);\n\n useImperativeHandle(\n ref,\n () => ({\n clear: handleClear,\n }),\n [handleClear],\n );\n\n return isEditMode ? (\n <GalleryEditor\n ref={editorRef}\n allowDragAndDrop={allowDragAndDrop}\n addFileIcon={addFileIcon}\n doubleFileDialogMessage={doubleFileDialogMessage}\n fileMinWidth={fileMinWidth}\n files={files}\n maxFiles={maxFiles}\n onAdd={onAdd}\n onFileCountChange={onFileCountChange}\n onRemove={onRemove}\n shouldLoadImages={shouldLoadImages}\n />\n ) : (\n <GalleryViewer files={files} shouldLoadImages={shouldLoadImages} viewMode={viewMode} />\n );\n },\n);\n\nGallery.displayName = 'Gallery';\n\nexport default Gallery;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,mBAAmB,EAAEC,MAAM,QAAQ,OAAO;AACnF,OAAOC,aAAa,MAAM,gCAAgC;AAE1D,OAAOC,aAAa,MAAM,gCAAgC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EA,gBAAiB;IAACC,QAAQ,EAAEA;EAAS,CAAE,CACzF;AACL,CACJ,CAAC;AAEDZ,OAAO,CAACsB,WAAW,GAAG,SAAS;AAE/B,eAAetB,OAAO","ignoreList":[]}
|
|
@@ -1 +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 type GalleryRef = {\n /**\n * Clears all locally managed gallery items in edit mode.\n * @description\n * When the gallery is rendered in read-only mode, calling this method only emits a console warning.\n */\n clear: () => void;\n};\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 * Defines the icon that is shown in the add-file tile in edit mode.\n * @description\n * The icon is forwarded to the editor and replaces the default plus icon on the add-tile.\n * @default 'fa fa-plus'\n * @example\n * <Gallery addFileIcon=\"fa fa-image-circle-plus\" isEditMode files={files} />\n * @optional\n */\n addFileIcon?: string;\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":[]}
|
|
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 type GalleryRef = {\n /**\n * Clears all locally managed gallery items in edit mode.\n * @description\n * When the gallery is rendered in read-only mode, calling this method only emits a console warning.\n */\n clear: () => void;\n};\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 * Defines the icon that is shown in the add-file tile in edit mode.\n * @description\n * The icon is forwarded to the editor and replaces the default plus icon on the add-tile.\n * @default 'fa fa-plus'\n * @example\n * <Gallery addFileIcon=\"fa fa-image-circle-plus\" isEditMode files={files} />\n * @optional\n */\n addFileIcon?: string;\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 * Controls when the gallery is allowed to load the final media assets.\n * @description\n * When set to `true`, the gallery loads the actual images immediately as before.\n * When set to `false`, the gallery keeps rendering previews first and delays the final media load until this flag becomes `true`.\n * This setting applies to the whole gallery wrapper and is intended for external loading control such as virtualized message lists.\n * @default true\n * @example\n * <Gallery files={files} shouldLoadImages={false} />\n * @optional\n */\n shouldLoadImages?: boolean;\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":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const GALLERY_EDITOR_GRID_GAP_PX = 6;
|
|
2
|
+
export const GALLERY_EDITOR_ITEM_FADE_DURATION_S = 0.18;
|
|
3
|
+
export const GALLERY_EDITOR_PREVIEW_FADE_DURATION_S = 0.16;
|
|
4
|
+
export const GALLERY_EDITOR_MEDIA_FADE_DURATION_S = 0.2;
|
|
5
|
+
export const GALLERY_EDITOR_DELETE_BUTTON_Z_INDEX = 3;
|
|
6
|
+
//# sourceMappingURL=GalleryEditor.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GalleryEditor.constants.js","names":["GALLERY_EDITOR_GRID_GAP_PX","GALLERY_EDITOR_ITEM_FADE_DURATION_S","GALLERY_EDITOR_PREVIEW_FADE_DURATION_S","GALLERY_EDITOR_MEDIA_FADE_DURATION_S","GALLERY_EDITOR_DELETE_BUTTON_Z_INDEX"],"sources":["../../../../src/components/gallery-editor/GalleryEditor.constants.ts"],"sourcesContent":["export const GALLERY_EDITOR_GRID_GAP_PX = 6;\nexport const GALLERY_EDITOR_ITEM_FADE_DURATION_S = 0.18;\nexport const GALLERY_EDITOR_PREVIEW_FADE_DURATION_S = 0.16;\nexport const GALLERY_EDITOR_MEDIA_FADE_DURATION_S = 0.2;\nexport const GALLERY_EDITOR_DELETE_BUTTON_Z_INDEX = 3;\n"],"mappings":"AAAA,OAAO,MAAMA,0BAA0B,GAAG,CAAC;AAC3C,OAAO,MAAMC,mCAAmC,GAAG,IAAI;AACvD,OAAO,MAAMC,sCAAsC,GAAG,IAAI;AAC1D,OAAO,MAAMC,oCAAoC,GAAG,GAAG;AACvD,OAAO,MAAMC,oCAAoC,GAAG,CAAC","ignoreList":[]}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useState } from 'react';
|
|
4
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
-
import { filterDuplicateFile, generatePreviewUrl, generateVideoThumbnail } from '../../utils/file';
|
|
6
|
-
import { openFiles, mapFilesToInternalItems } from '../../utils/gallery';
|
|
1
|
+
import { AnimatePresence } from 'motion/react';
|
|
2
|
+
import React, { forwardRef, useImperativeHandle } from 'react';
|
|
7
3
|
import AddFile from './add-file/AddFile';
|
|
8
|
-
import GalleryEditorItem from './gallery-editor-item/GalleryEditorItem';
|
|
9
4
|
import { StyledGalleryEditor, StyledGalleryEditorGrid } from './GalleryEditor.styles';
|
|
5
|
+
import GalleryEditorItem from './gallery-editor-item/GalleryEditorItem';
|
|
6
|
+
import { GALLERY_EDITOR_GRID_GAP_PX } from './GalleryEditor.constants';
|
|
7
|
+
import useGalleryEditorState from './useGalleryEditorState';
|
|
10
8
|
const GalleryEditor = /*#__PURE__*/forwardRef(({
|
|
11
9
|
allowDragAndDrop = false,
|
|
12
10
|
addFileIcon = 'fa fa-plus',
|
|
@@ -16,181 +14,46 @@ const GalleryEditor = /*#__PURE__*/forwardRef(({
|
|
|
16
14
|
maxFiles,
|
|
17
15
|
onAdd,
|
|
18
16
|
onFileCountChange,
|
|
19
|
-
onRemove
|
|
17
|
+
onRemove,
|
|
18
|
+
shouldLoadImages = true
|
|
20
19
|
}, ref) => {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
createDialog({
|
|
38
|
-
type: DialogType.ALERT,
|
|
39
|
-
text: doubleFileDialogMessage
|
|
40
|
-
});
|
|
41
|
-
}, [doubleFileDialogMessage]);
|
|
42
|
-
const handleUploadFileCallback = useCallback((file, uploadedFile) => {
|
|
43
|
-
setFileItems(prevState => {
|
|
44
|
-
const updatedState = prevState.map(prevFile => {
|
|
45
|
-
if (prevFile.uploadedFile?.url === uploadedFile.url) {
|
|
46
|
-
callDuplicateFileDialog();
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
if (prevFile.id === file.id) {
|
|
50
|
-
if (typeof onAdd === 'function') {
|
|
51
|
-
const prevElement = prevState.find(({
|
|
52
|
-
uploadedFile: nextUploadedFile
|
|
53
|
-
}) => nextUploadedFile?.url === uploadedFile?.url);
|
|
54
|
-
if (!prevElement) {
|
|
55
|
-
onAdd({
|
|
56
|
-
file: uploadedFile,
|
|
57
|
-
id: file.id
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
...prevFile,
|
|
63
|
-
uploadedFile,
|
|
64
|
-
state: 'uploaded'
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return prevFile;
|
|
68
|
-
});
|
|
69
|
-
return updatedState.filter(Boolean);
|
|
70
|
-
});
|
|
71
|
-
}, [callDuplicateFileDialog, onAdd]);
|
|
72
|
-
const handleAddFiles = useCallback(filesToAdd => {
|
|
73
|
-
const newFileItems = [];
|
|
74
|
-
filesToAdd.forEach(file => {
|
|
75
|
-
if (file && !filterDuplicateFile({
|
|
76
|
-
files: fileItems,
|
|
77
|
-
newFile: file
|
|
78
|
-
})) {
|
|
79
|
-
newFileItems.push({
|
|
80
|
-
id: uuidv4(),
|
|
81
|
-
file,
|
|
82
|
-
state: 'none'
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
let limitedFileItems = newFileItems;
|
|
87
|
-
if (maxFiles) {
|
|
88
|
-
limitedFileItems = newFileItems.slice(0, Math.max(maxFiles - fileItems.length, 0));
|
|
89
|
-
}
|
|
90
|
-
setFileItems(prevState => [...prevState, ...limitedFileItems]);
|
|
91
|
-
}, [fileItems, maxFiles]);
|
|
92
|
-
const handleDeleteFile = useCallback(id => {
|
|
93
|
-
let fileToDelete;
|
|
94
|
-
const filteredFiles = fileItems.filter(file => {
|
|
95
|
-
if (file.id === id && file.uploadedFile) {
|
|
96
|
-
fileToDelete = {
|
|
97
|
-
file: file.uploadedFile,
|
|
98
|
-
id
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return file.id !== id;
|
|
102
|
-
});
|
|
103
|
-
setFileItems(filteredFiles);
|
|
104
|
-
if (!fileToDelete || typeof onRemove !== 'function') {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
onRemove(fileToDelete);
|
|
108
|
-
}, [fileItems, onRemove]);
|
|
109
|
-
const handleDrop = useCallback(event => {
|
|
110
|
-
if (!allowDragAndDrop) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
event.preventDefault();
|
|
114
|
-
handleAddFiles(Array.from(event.dataTransfer.files));
|
|
115
|
-
}, [allowDragAndDrop, handleAddFiles]);
|
|
116
|
-
const handleOpenFiles = useCallback(file => {
|
|
117
|
-
openFiles(fileItems, file);
|
|
118
|
-
}, [fileItems]);
|
|
20
|
+
const {
|
|
21
|
+
fileItems,
|
|
22
|
+
handleAddFiles,
|
|
23
|
+
handleClear,
|
|
24
|
+
handleDeleteFile,
|
|
25
|
+
handleDrop,
|
|
26
|
+
handleOpenFiles
|
|
27
|
+
} = useGalleryEditorState({
|
|
28
|
+
allowDragAndDrop,
|
|
29
|
+
doubleFileDialogMessage,
|
|
30
|
+
files,
|
|
31
|
+
maxFiles,
|
|
32
|
+
onAdd,
|
|
33
|
+
onFileCountChange,
|
|
34
|
+
onRemove
|
|
35
|
+
});
|
|
119
36
|
useImperativeHandle(ref, () => ({
|
|
120
37
|
clear: handleClear
|
|
121
38
|
}), [handleClear]);
|
|
122
|
-
|
|
123
|
-
if (typeof onFileCountChange === 'function') {
|
|
124
|
-
onFileCountChange(fileItems.length);
|
|
125
|
-
}
|
|
126
|
-
}, [fileItems.length, onFileCountChange]);
|
|
127
|
-
useEffect(() => {
|
|
128
|
-
const filesToGeneratePreview = fileItems.filter(file => file.file && !file.previewUrl && (file.state === 'none' || !file.state));
|
|
129
|
-
const filesToUpload = fileItems.filter(file => file.file && !file.uploadedFile && file.state !== 'uploading');
|
|
130
|
-
filesToGeneratePreview.forEach(file => {
|
|
131
|
-
if (!file.file) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
if (file.file.type.includes('video/')) {
|
|
135
|
-
generateVideoThumbnail({
|
|
136
|
-
file: file.file,
|
|
137
|
-
callback: previewUrl => handlePreviewUrlCallback(previewUrl, file)
|
|
138
|
-
});
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
generatePreviewUrl({
|
|
142
|
-
file: file.file,
|
|
143
|
-
callback: previewUrl => handlePreviewUrlCallback(previewUrl, file)
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
filesToUpload.forEach(file => {
|
|
147
|
-
setFileItems(prevState => prevState.map(prevFile => {
|
|
148
|
-
if (prevFile.id === file.id) {
|
|
149
|
-
return {
|
|
150
|
-
...prevFile,
|
|
151
|
-
state: 'uploading'
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
return prevFile;
|
|
155
|
-
}));
|
|
156
|
-
void uploadFile({
|
|
157
|
-
fileToUpload: file,
|
|
158
|
-
callback: uploadedFile => handleUploadFileCallback(file, uploadedFile)
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
}, [fileItems, handlePreviewUrlCallback, handleUploadFileCallback]);
|
|
162
|
-
useEffect(() => {
|
|
163
|
-
const externalFileItems = mapFilesToInternalItems(files);
|
|
164
|
-
setFileItems(prevState => {
|
|
165
|
-
// Keep local-only items such as pending uploads while refreshing known external media.
|
|
166
|
-
const updatedItems = prevState.map(prevItem => {
|
|
167
|
-
const matchingItem = externalFileItems.find(item => item.uploadedFile && item.uploadedFile.url === (prevItem.uploadedFile && prevItem.uploadedFile.url));
|
|
168
|
-
return matchingItem || prevItem;
|
|
169
|
-
});
|
|
170
|
-
return updatedItems.concat(externalFileItems.filter(newItem => !prevState.some(prevItem => prevItem.uploadedFile && newItem.uploadedFile && prevItem.uploadedFile.url === newItem.uploadedFile.url)));
|
|
171
|
-
});
|
|
172
|
-
}, [files]);
|
|
173
|
-
const galleryItems = useMemo(() => {
|
|
174
|
-
const items = fileItems.map(file => /*#__PURE__*/React.createElement(GalleryEditorItem, {
|
|
175
|
-
key: file.id,
|
|
176
|
-
fileItem: file,
|
|
177
|
-
onClick: handleOpenFiles,
|
|
178
|
-
handleDeleteFile: handleDeleteFile
|
|
179
|
-
}));
|
|
180
|
-
if (maxFiles && maxFiles <= fileItems.length) {
|
|
181
|
-
return items;
|
|
182
|
-
}
|
|
183
|
-
return [...items, /*#__PURE__*/React.createElement(AddFile, {
|
|
184
|
-
key: "add_file",
|
|
185
|
-
addFileIcon: addFileIcon,
|
|
186
|
-
onAdd: handleAddFiles
|
|
187
|
-
})];
|
|
188
|
-
}, [addFileIcon, fileItems, handleAddFiles, handleDeleteFile, handleOpenFiles, maxFiles]);
|
|
39
|
+
const shouldShowAddFileTile = !maxFiles || maxFiles > fileItems.length;
|
|
189
40
|
return /*#__PURE__*/React.createElement(StyledGalleryEditor, null, /*#__PURE__*/React.createElement(StyledGalleryEditorGrid, {
|
|
190
41
|
$fileMinWidth: fileMinWidth,
|
|
42
|
+
$gap: GALLERY_EDITOR_GRID_GAP_PX,
|
|
191
43
|
onDragOver: event => event.preventDefault(),
|
|
192
44
|
onDrop: event => void handleDrop(event)
|
|
193
|
-
},
|
|
45
|
+
}, /*#__PURE__*/React.createElement(AnimatePresence, {
|
|
46
|
+
initial: false
|
|
47
|
+
}, fileItems.map(file => /*#__PURE__*/React.createElement(GalleryEditorItem, {
|
|
48
|
+
key: file.id,
|
|
49
|
+
fileItem: file,
|
|
50
|
+
handleDeleteFile: handleDeleteFile,
|
|
51
|
+
onClick: handleOpenFiles,
|
|
52
|
+
shouldLoadImages: shouldLoadImages
|
|
53
|
+
}))), shouldShowAddFileTile && /*#__PURE__*/React.createElement(AddFile, {
|
|
54
|
+
addFileIcon: addFileIcon,
|
|
55
|
+
onAdd: handleAddFiles
|
|
56
|
+
})));
|
|
194
57
|
});
|
|
195
58
|
GalleryEditor.displayName = 'GalleryEditor';
|
|
196
59
|
export default GalleryEditor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GalleryEditor.js","names":["uploadFile","createDialog","DialogType","React","forwardRef","useCallback","useEffect","useImperativeHandle","useMemo","useState","v4","uuidv4","filterDuplicateFile","generatePreviewUrl","generateVideoThumbnail","openFiles","mapFilesToInternalItems","AddFile","GalleryEditorItem","StyledGalleryEditor","StyledGalleryEditorGrid","GalleryEditor","allowDragAndDrop","addFileIcon","doubleFileDialogMessage","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","ref","fileItems","setFileItems","handleClear","handlePreviewUrlCallback","previewUrl","file","prevState","map","prevFile","id","callDuplicateFileDialog","type","ALERT","text","handleUploadFileCallback","uploadedFile","updatedState","url","undefined","prevElement","find","nextUploadedFile","state","filter","Boolean","handleAddFiles","filesToAdd","newFileItems","forEach","newFile","push","limitedFileItems","slice","Math","max","length","handleDeleteFile","fileToDelete","filteredFiles","handleDrop","event","preventDefault","Array","from","dataTransfer","handleOpenFiles","clear","filesToGeneratePreview","filesToUpload","includes","callback","fileToUpload","externalFileItems","updatedItems","prevItem","matchingItem","item","concat","newItem","some","galleryItems","items","createElement","key","fileItem","onClick","$fileMinWidth","onDragOver","onDrop","displayName"],"sources":["../../../../src/components/gallery-editor/GalleryEditor.tsx"],"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 React, {\n DragEvent,\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react';\nimport { v4 as uuidv4 } from 'uuid';\nimport { filterDuplicateFile, generatePreviewUrl, generateVideoThumbnail } from '../../utils/file';\nimport { openFiles, mapFilesToInternalItems } from '../../utils/gallery';\nimport AddFile from './add-file/AddFile';\nimport GalleryEditorItem from './gallery-editor-item/GalleryEditorItem';\nimport { StyledGalleryEditor, StyledGalleryEditorGrid } from './GalleryEditor.styles';\nimport type { GalleryEditorProps, GalleryEditorRef } from './GalleryEditor.types';\n\nconst GalleryEditor = forwardRef<GalleryEditorRef, GalleryEditorProps>(\n (\n {\n allowDragAndDrop = false,\n addFileIcon = 'fa fa-plus',\n doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',\n fileMinWidth = 100,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n },\n ref,\n ) => {\n const [fileItems, setFileItems] = useState<InternalFileItem[]>(() =>\n mapFilesToInternalItems(files),\n );\n\n const handleClear = useCallback(() => {\n setFileItems([]);\n }, []);\n\n const handlePreviewUrlCallback = useCallback(\n (previewUrl: string, file: InternalFileItem) => {\n setFileItems((prevState) =>\n prevState.map((prevFile) => {\n if (prevFile.id === file.id) {\n return { ...prevFile, previewUrl };\n }\n\n return prevFile;\n }),\n );\n },\n [],\n );\n\n const callDuplicateFileDialog = useCallback(() => {\n createDialog({ type: DialogType.ALERT, text: doubleFileDialogMessage });\n }, [doubleFileDialogMessage]);\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: nextUploadedFile }) =>\n nextUploadedFile?.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 return updatedState.filter(Boolean) as InternalFileItem[];\n });\n },\n [callDuplicateFileDialog, onAdd],\n );\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 limitedFileItems = newFileItems;\n\n if (maxFiles) {\n limitedFileItems = newFileItems.slice(\n 0,\n Math.max(maxFiles - fileItems.length, 0),\n );\n }\n\n setFileItems((prevState) => [...prevState, ...limitedFileItems]);\n },\n [fileItems, maxFiles],\n );\n\n const handleDeleteFile = useCallback(\n (id?: string) => {\n let fileToDelete: FileItem | undefined;\n\n const filteredFiles = fileItems.filter((file) => {\n if (file.id === id && file.uploadedFile) {\n fileToDelete = { file: file.uploadedFile, id };\n }\n\n return file.id !== 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 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 useImperativeHandle(\n ref,\n () => ({\n clear: handleClear,\n }),\n [handleClear],\n );\n\n useEffect(() => {\n if (typeof onFileCountChange === 'function') {\n onFileCountChange(fileItems.length);\n }\n }, [fileItems.length, onFileCountChange]);\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.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\n return prevFile;\n }),\n );\n\n void uploadFile({\n fileToUpload: file,\n callback: (uploadedFile) => handleUploadFileCallback(file, uploadedFile),\n });\n });\n }, [fileItems, handlePreviewUrlCallback, handleUploadFileCallback]);\n\n useEffect(() => {\n const externalFileItems = mapFilesToInternalItems(files);\n\n setFileItems((prevState) => {\n // Keep local-only items such as pending uploads while refreshing known external media.\n const updatedItems = prevState.map((prevItem) => {\n const matchingItem = externalFileItems.find(\n (item) =>\n item.uploadedFile &&\n item.uploadedFile.url ===\n (prevItem.uploadedFile && prevItem.uploadedFile.url),\n );\n\n return matchingItem || prevItem;\n });\n\n return updatedItems.concat(\n externalFileItems.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 }, [files]);\n\n const galleryItems = useMemo(() => {\n const items = fileItems.map((file) => (\n <GalleryEditorItem\n key={file.id}\n fileItem={file}\n onClick={handleOpenFiles}\n handleDeleteFile={handleDeleteFile}\n />\n ));\n\n if (maxFiles && maxFiles <= fileItems.length) {\n return items;\n }\n\n return [\n ...items,\n <AddFile key=\"add_file\" addFileIcon={addFileIcon} onAdd={handleAddFiles} />,\n ];\n }, [addFileIcon, fileItems, handleAddFiles, handleDeleteFile, handleOpenFiles, maxFiles]);\n\n return (\n <StyledGalleryEditor>\n <StyledGalleryEditorGrid\n $fileMinWidth={fileMinWidth}\n onDragOver={(event) => event.preventDefault()}\n onDrop={(event) => void handleDrop(event)}\n >\n {galleryItems}\n </StyledGalleryEditorGrid>\n </StyledGalleryEditor>\n );\n },\n);\n\nGalleryEditor.displayName = 'GalleryEditor';\n\nexport default GalleryEditor;\n"],"mappings":"AAAA,SAEIA,UAAU,QAIP,yBAAyB;AAChC,SAASC,YAAY,EAAEC,UAAU,QAAQ,YAAY;AACrD,OAAOC,KAAK,IAERC,UAA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uBAAuB;IACpB8E,aAAa,EAAEzE,YAAa;IAC5B0E,UAAU,EAAG3B,KAAK,IAAKA,KAAK,CAACC,cAAc,CAAC,CAAE;IAC9C2B,MAAM,EAAG5B,KAAK,IAAK,KAAKD,UAAU,CAACC,KAAK;EAAE,GAEzCoB,YACoB,CACR,CAAC;AAE9B,CACJ,CAAC;AAEDvE,aAAa,CAACgF,WAAW,GAAG,eAAe;AAE3C,eAAehF,aAAa","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"GalleryEditor.js","names":["AnimatePresence","React","forwardRef","useImperativeHandle","AddFile","StyledGalleryEditor","StyledGalleryEditorGrid","GalleryEditorItem","GALLERY_EDITOR_GRID_GAP_PX","useGalleryEditorState","GalleryEditor","allowDragAndDrop","addFileIcon","doubleFileDialogMessage","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","shouldLoadImages","ref","fileItems","handleAddFiles","handleClear","handleDeleteFile","handleDrop","handleOpenFiles","clear","shouldShowAddFileTile","length","createElement","$fileMinWidth","$gap","onDragOver","event","preventDefault","onDrop","initial","map","file","key","id","fileItem","onClick","displayName"],"sources":["../../../../src/components/gallery-editor/GalleryEditor.tsx"],"sourcesContent":["import { AnimatePresence } from 'motion/react';\nimport React, { forwardRef, useImperativeHandle } from 'react';\nimport AddFile from './add-file/AddFile';\nimport { StyledGalleryEditor, StyledGalleryEditorGrid } from './GalleryEditor.styles';\nimport type { GalleryEditorProps, GalleryEditorRef } from './GalleryEditor.types';\nimport GalleryEditorItem from './gallery-editor-item/GalleryEditorItem';\nimport { GALLERY_EDITOR_GRID_GAP_PX } from './GalleryEditor.constants';\nimport useGalleryEditorState from './useGalleryEditorState';\n\nconst GalleryEditor = forwardRef<GalleryEditorRef, GalleryEditorProps>(\n (\n {\n allowDragAndDrop = false,\n addFileIcon = 'fa fa-plus',\n doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',\n fileMinWidth = 100,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n shouldLoadImages = true,\n },\n ref,\n ) => {\n const {\n fileItems,\n handleAddFiles,\n handleClear,\n handleDeleteFile,\n handleDrop,\n handleOpenFiles,\n } = useGalleryEditorState({\n allowDragAndDrop,\n doubleFileDialogMessage,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n });\n\n useImperativeHandle(\n ref,\n () => ({\n clear: handleClear,\n }),\n [handleClear],\n );\n\n const shouldShowAddFileTile = !maxFiles || maxFiles > fileItems.length;\n\n return (\n <StyledGalleryEditor>\n <StyledGalleryEditorGrid\n $fileMinWidth={fileMinWidth}\n $gap={GALLERY_EDITOR_GRID_GAP_PX}\n onDragOver={(event) => event.preventDefault()}\n onDrop={(event) => void handleDrop(event)}\n >\n <AnimatePresence initial={false}>\n {fileItems.map((file) => (\n <GalleryEditorItem\n key={file.id}\n fileItem={file}\n handleDeleteFile={handleDeleteFile}\n onClick={handleOpenFiles}\n shouldLoadImages={shouldLoadImages}\n />\n ))}\n </AnimatePresence>\n\n {shouldShowAddFileTile && (\n <AddFile addFileIcon={addFileIcon} onAdd={handleAddFiles} />\n )}\n </StyledGalleryEditorGrid>\n </StyledGalleryEditor>\n );\n },\n);\n\nGalleryEditor.displayName = 'GalleryEditor';\n\nexport default GalleryEditor;\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,cAAc;AAC9C,OAAOC,KAAK,IAAIC,UAAU,EAAEC,mBAAmB,QAAQ,OAAO;AAC9D,OAAOC,OAAO,MAAM,oBAAoB;AACxC,SAASC,mBAAmB,EAAEC,uBAAuB,QAAQ,wBAAwB;AAErF,OAAOC,iBAAiB,MAAM,yCAAyC;AACvE,SAASC,0BAA0B,QAAQ,2BAA2B;AACtE,OAAOC,qBAAqB,MAAM,yBAAyB;AAE3D,MAAMC,aAAa,gBAAGR,UAAU,CAC5B,CACI;EACIS,gBAAgB,GAAG,KAAK;EACxBC,WAAW,GAAG,YAAY;EAC1BC,uBAAuB,GAAG,mCAAmC;EAC7DC,YAAY,GAAG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W,EAAEA,WAAY;IAACK,KAAK,EAAEM;EAAe,CAAE,CAE1C,CACR,CAAC;AAE9B,CACJ,CAAC;AAEDb,aAAa,CAACmC,WAAW,GAAG,eAAe;AAE3C,eAAenC,aAAa","ignoreList":[]}
|
|
@@ -8,6 +8,8 @@ export const StyledGalleryEditorGrid = styled.div`
|
|
|
8
8
|
$fileMinWidth
|
|
9
9
|
}) => `repeat(auto-fill, minmax(${$fileMinWidth}px, 1fr))`};
|
|
10
10
|
grid-auto-rows: 1fr;
|
|
11
|
-
gap:
|
|
11
|
+
gap: ${({
|
|
12
|
+
$gap
|
|
13
|
+
}) => `${$gap}px`};
|
|
12
14
|
`;
|
|
13
15
|
//# sourceMappingURL=GalleryEditor.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GalleryEditor.styles.js","names":["styled","StyledGalleryEditor","div","StyledGalleryEditorGrid","$fileMinWidth"],"sources":["../../../../src/components/gallery-editor/GalleryEditor.styles.ts"],"sourcesContent":["import styled from 'styled-components';\n\nexport const StyledGalleryEditor = styled.div`\n width: 100%;\n`;\n\nexport const StyledGalleryEditorGrid = styled.div<{\n $fileMinWidth: number;\n}>`\n display: grid;\n grid-template-columns: ${({ $fileMinWidth }) =>\n `repeat(auto-fill, minmax(${$fileMinWidth}px, 1fr))`};\n grid-auto-rows: 1fr;\n gap:
|
|
1
|
+
{"version":3,"file":"GalleryEditor.styles.js","names":["styled","StyledGalleryEditor","div","StyledGalleryEditorGrid","$fileMinWidth","$gap"],"sources":["../../../../src/components/gallery-editor/GalleryEditor.styles.ts"],"sourcesContent":["import styled from 'styled-components';\n\nexport const StyledGalleryEditor = styled.div`\n width: 100%;\n`;\n\nexport const StyledGalleryEditorGrid = styled.div<{\n $gap: number;\n $fileMinWidth: number;\n}>`\n display: grid;\n grid-template-columns: ${({ $fileMinWidth }) =>\n `repeat(auto-fill, minmax(${$fileMinWidth}px, 1fr))`};\n grid-auto-rows: 1fr;\n gap: ${({ $gap }) => `${$gap}px`};\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,mBAAmB;AAEtC,OAAO,MAAMC,mBAAmB,GAAGD,MAAM,CAACE,GAAG;AAC7C;AACA,CAAC;AAED,OAAO,MAAMC,uBAAuB,GAAGH,MAAM,CAACE,GAG5C;AACF;AACA,6BAA6B,CAAC;EAAEE;AAAc,CAAC,KACvC,4BAA4BA,aAAa,WAAW;AAC5D;AACA,WAAW,CAAC;EAAEC;AAAK,CAAC,KAAK,GAAGA,IAAI,IAAI;AACpC,CAAC","ignoreList":[]}
|