@chayns-components/gallery 5.2.0 → 5.2.3

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.
Files changed (28) hide show
  1. package/AGENTS.md +23 -0
  2. package/lib/cjs/components/Gallery.js +32 -14
  3. package/lib/cjs/components/Gallery.js.map +1 -1
  4. package/lib/cjs/components/Gallery.types.js.map +1 -1
  5. package/lib/cjs/components/gallery-editor/GalleryEditor.js +12 -4
  6. package/lib/cjs/components/gallery-editor/GalleryEditor.js.map +1 -1
  7. package/lib/cjs/components/gallery-editor/GalleryEditor.types.js.map +1 -1
  8. package/lib/cjs/components/gallery-editor/add-file/AddFile.js +2 -1
  9. package/lib/cjs/components/gallery-editor/add-file/AddFile.js.map +1 -1
  10. package/lib/cjs/components/gallery-editor/add-file/AddFile.types.js.map +1 -1
  11. package/lib/cjs/index.js.map +1 -1
  12. package/lib/esm/components/Gallery.js +30 -14
  13. package/lib/esm/components/Gallery.js.map +1 -1
  14. package/lib/esm/components/Gallery.types.js.map +1 -1
  15. package/lib/esm/components/gallery-editor/GalleryEditor.js +13 -5
  16. package/lib/esm/components/gallery-editor/GalleryEditor.js.map +1 -1
  17. package/lib/esm/components/gallery-editor/GalleryEditor.types.js.map +1 -1
  18. package/lib/esm/components/gallery-editor/add-file/AddFile.js +2 -1
  19. package/lib/esm/components/gallery-editor/add-file/AddFile.js.map +1 -1
  20. package/lib/esm/components/gallery-editor/add-file/AddFile.types.js.map +1 -1
  21. package/lib/esm/index.js.map +1 -1
  22. package/lib/types/components/Gallery.d.ts +3 -3
  23. package/lib/types/components/Gallery.types.d.ts +18 -0
  24. package/lib/types/components/gallery-editor/GalleryEditor.d.ts +2 -2
  25. package/lib/types/components/gallery-editor/GalleryEditor.types.d.ts +12 -0
  26. package/lib/types/components/gallery-editor/add-file/AddFile.types.d.ts +10 -0
  27. package/lib/types/index.d.ts +2 -2
  28. package/package.json +2 -2
package/AGENTS.md CHANGED
@@ -63,6 +63,17 @@ import { Gallery } from '@chayns-components/gallery';
63
63
  />
64
64
  ```
65
65
 
66
+ #### Edit Mode Custom Add Icon
67
+
68
+ ```tsx
69
+ <Gallery
70
+ files={galleryStoryFiles.slice(0, 3)}
71
+ isEditMode
72
+ maxFiles={6}
73
+ addFileIcon={'fa fa-image-circle-plus'}
74
+ />
75
+ ```
76
+
66
77
  ### Props
67
78
 
68
79
  No prop documentation available.
@@ -113,6 +124,18 @@ import { GalleryEditor } from '@chayns-components/gallery';
113
124
  />
114
125
  ```
115
126
 
127
+ #### Custom Add Icon
128
+
129
+ ```tsx
130
+ <GalleryEditor
131
+ allowDragAndDrop={false}
132
+ fileMinWidth={100}
133
+ files={galleryStoryFiles.slice(0, 3)}
134
+ maxFiles={6}
135
+ addFileIcon={'fa fa-image-circle-plus'}
136
+ />
137
+ ```
138
+
116
139
  ### Props
117
140
 
118
141
  No prop documentation available.
@@ -4,13 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _react = _interopRequireDefault(require("react"));
7
+ var _react = _interopRequireWildcard(require("react"));
8
8
  var _GalleryEditor = _interopRequireDefault(require("./gallery-editor/GalleryEditor"));
9
9
  var _GalleryViewer = _interopRequireDefault(require("./gallery-viewer/GalleryViewer"));
10
10
  var _gallery = require("../types/gallery");
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- const Gallery = ({
12
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
+ const Gallery = /*#__PURE__*/(0, _react.forwardRef)(({
13
14
  allowDragAndDrop = false,
15
+ addFileIcon = 'fa fa-plus',
14
16
  doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',
15
17
  isEditMode = false,
16
18
  fileMinWidth = 100,
@@ -20,18 +22,34 @@ const Gallery = ({
20
22
  onFileCountChange,
21
23
  onRemove,
22
24
  viewMode = _gallery.GalleryViewMode.GRID
23
- }) => isEditMode ? /*#__PURE__*/_react.default.createElement(_GalleryEditor.default, {
24
- allowDragAndDrop: allowDragAndDrop,
25
- doubleFileDialogMessage: doubleFileDialogMessage,
26
- fileMinWidth: fileMinWidth,
27
- files: files,
28
- maxFiles: maxFiles,
29
- onAdd: onAdd,
30
- onFileCountChange: onFileCountChange,
31
- onRemove: onRemove
32
- }) : /*#__PURE__*/_react.default.createElement(_GalleryViewer.default, {
33
- files: files,
34
- viewMode: viewMode
25
+ }, ref) => {
26
+ const editorRef = (0, _react.useRef)(null);
27
+ const handleClear = (0, _react.useCallback)(() => {
28
+ var _editorRef$current;
29
+ if (!isEditMode) {
30
+ console.warn('Gallery.clear() can only be used in edit mode.');
31
+ return;
32
+ }
33
+ (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || _editorRef$current.clear();
34
+ }, [isEditMode]);
35
+ (0, _react.useImperativeHandle)(ref, () => ({
36
+ clear: handleClear
37
+ }), [handleClear]);
38
+ return isEditMode ? /*#__PURE__*/_react.default.createElement(_GalleryEditor.default, {
39
+ ref: editorRef,
40
+ allowDragAndDrop: allowDragAndDrop,
41
+ addFileIcon: addFileIcon,
42
+ doubleFileDialogMessage: doubleFileDialogMessage,
43
+ fileMinWidth: fileMinWidth,
44
+ files: files,
45
+ maxFiles: maxFiles,
46
+ onAdd: onAdd,
47
+ onFileCountChange: onFileCountChange,
48
+ onRemove: onRemove
49
+ }) : /*#__PURE__*/_react.default.createElement(_GalleryViewer.default, {
50
+ files: files,
51
+ viewMode: viewMode
52
+ });
35
53
  });
36
54
  Gallery.displayName = 'Gallery';
37
55
  var _default = exports.default = Gallery;
@@ -1 +1 @@
1
- {"version":3,"file":"Gallery.js","names":["_react","_interopRequireDefault","require","_GalleryEditor","_GalleryViewer","_gallery","e","__esModule","default","Gallery","allowDragAndDrop","doubleFileDialogMessage","isEditMode","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","viewMode","GalleryViewMode","GRID","createElement","displayName","_default","exports"],"sources":["../../../src/components/Gallery.tsx"],"sourcesContent":["import React, { FC } from 'react';\nimport GalleryEditor from './gallery-editor/GalleryEditor';\nimport GalleryViewer from './gallery-viewer/GalleryViewer';\nimport type { GalleryProps } from './Gallery.types';\nimport { GalleryViewMode } from '../types/gallery';\n\nconst Gallery: FC<GalleryProps> = ({\n allowDragAndDrop = false,\n doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',\n isEditMode = false,\n fileMinWidth = 100,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n viewMode = GalleryViewMode.GRID,\n}) =>\n isEditMode ? (\n <GalleryEditor\n allowDragAndDrop={allowDragAndDrop}\n doubleFileDialogMessage={doubleFileDialogMessage}\n fileMinWidth={fileMinWidth}\n files={files}\n maxFiles={maxFiles}\n onAdd={onAdd}\n onFileCountChange={onFileCountChange}\n onRemove={onRemove}\n />\n ) : (\n <GalleryViewer files={files} viewMode={viewMode} />\n );\n\nGallery.displayName = 'Gallery';\n\nexport default Gallery;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,QAAA,GAAAH,OAAA;AAAmD,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEnD,MAAMG,OAAyB,GAAGA,CAAC;EAC/BC,gBAAgB,GAAG,KAAK;EACxBC,uBAAuB,GAAG,mCAAmC;EAC7DC,UAAU,GAAG,KAAK;EAClBC,YAAY,GAAG,GAAG;EAClBC,KAAK;EACLC,QAAQ;EACRC,KAAK;EACLC,iBAAiB;EACjBC,QAAQ;EACRC,QAAQ,GAAGC,wBAAe,CAACC;AAC/B,CAAC,KACGT,UAAU,gBACNZ,MAAA,CAAAQ,OAAA,CAAAc,aAAA,CAACnB,cAAA,CAAAK,OAAa;EACVE,gBAAgB,EAAEA,gBAAiB;EACnCC,uBAAuB,EAAEA,uBAAwB;EACjDE,YAAY,EAAEA,YAAa;EAC3BC,KAAK,EAAEA,KAAM;EACbC,QAAQ,EAAEA,QAAS;EACnBC,KAAK,EAAEA,KAAM;EACbC,iBAAiB,EAAEA,iBAAkB;EACrCC,QAAQ,EAAEA;AAAS,CACtB,CAAC,gBAEFlB,MAAA,CAAAQ,OAAA,CAAAc,aAAA,CAAClB,cAAA,CAAAI,OAAa;EAACM,KAAK,EAAEA,KAAM;EAACK,QAAQ,EAAEA;AAAS,CAAE,CACrD;AAELV,OAAO,CAACc,WAAW,GAAG,SAAS;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAjB,OAAA,GAEjBC,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"Gallery.js","names":["_react","_interopRequireWildcard","require","_GalleryEditor","_interopRequireDefault","_GalleryViewer","_gallery","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","Gallery","forwardRef","allowDragAndDrop","addFileIcon","doubleFileDialogMessage","isEditMode","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","viewMode","GalleryViewMode","GRID","ref","editorRef","useRef","handleClear","useCallback","_editorRef$current","console","warn","current","clear","useImperativeHandle","createElement","displayName","_default","exports"],"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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,cAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA,IAAAI,QAAA,GAAAJ,OAAA;AAAmD,SAAAE,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAN,wBAAAM,CA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C,GAAG,KACF;EACD,MAAMC,SAAS,GAAG,IAAAC,aAAM,EAAmB,IAAI,CAAC;EAEhD,MAAMC,WAAW,GAAG,IAAAC,kBAAW,EAAC,MAAM;IAAA,IAAAC,kBAAA;IAClC,IAAI,CAACf,UAAU,EAAE;MACbgB,OAAO,CAACC,IAAI,CAAC,gDAAgD,CAAC;MAC9D;IACJ;IAEA,CAAAF,kBAAA,GAAAJ,SAAS,CAACO,OAAO,cAAAH,kBAAA,eAAjBA,kBAAA,CAAmBI,KAAK,CAAC,CAAC;EAC9B,CAAC,EAAE,CAACnB,UAAU,CAAC,CAAC;EAEhB,IAAAoB,0BAAmB,EACfV,GAAG,EACH,OAAO;IACHS,KAAK,EAAEN;EACX,CAAC,CAAC,EACF,CAACA,WAAW,CAChB,CAAC;EAED,OAAOb,UAAU,gBACb/B,MAAA,CAAAS,OAAA,CAAA2C,aAAA,CAACjD,cAAA,CAAAM,OAAa;IACVgC,GAAG,EAAEC,SAAU;IACfd,gBAAgB,EAAEA,gBAAiB;IACnCC,WAAW,EAAEA,WAAY;IACzBC,uBAAuB,EAAEA,uBAAwB;IACjDE,YAAY,EAAEA,YAAa;IAC3BC,KAAK,EAAEA,KAAM;IACbC,QAAQ,EAAEA,QAAS;IACnBC,KAAK,EAAEA,KAAM;IACbC,iBAAiB,EAAEA,iBAAkB;IACrCC,QAAQ,EAAEA;EAAS,CACtB,CAAC,gBAEFrC,MAAA,CAAAS,OAAA,CAAA2C,aAAA,CAAC/C,cAAA,CAAAI,OAAa;IAACwB,KAAK,EAAEA,KAAM;IAACK,QAAQ,EAAEA;EAAS,CAAE,CACrD;AACL,CACJ,CAAC;AAEDZ,OAAO,CAAC2B,WAAW,GAAG,SAAS;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA9C,OAAA,GAEjBiB,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 interface GalleryProps {\n /**\n * Enables drag and drop while the component is used in edit mode.\n * @description\n * This prop only affects the editor path. In read-only mode, drag and drop stays disabled regardless of this value.\n * @default false\n * @example\n * <Gallery allowDragAndDrop isEditMode files={files} />\n * @optional\n */\n allowDragAndDrop?: boolean;\n /**\n * Defines the dialog message that is shown when a duplicate upload is detected.\n * @description\n * The message is used by the editor when a locally added file resolves to an already known uploaded file.\n * @default 'Diese Datei ist bereits vorhanden'\n * @example\n * <Gallery doubleFileDialogMessage=\"This file already exists.\" isEditMode files={files} />\n * @optional\n */\n doubleFileDialogMessage?: string;\n /**\n * Defines the minimum width of one tile in edit mode.\n * @description\n * The editor uses this value to build its responsive grid. It has no effect in the read-only viewer.\n * @default 100\n * @example\n * <Gallery fileMinWidth={140} isEditMode files={files} />\n * @optional\n */\n fileMinWidth?: number;\n /**\n * Provides already known media items that should be rendered by the gallery.\n * @description\n * In read-only mode, these files are rendered directly from props. In edit mode, they are used as the external baseline\n * for already uploaded media while local uploads are managed internally.\n * @example\n * <Gallery files={files} />\n * @optional\n */\n files?: FileItem[];\n /**\n * Enables the editable upload mode instead of the read-only viewer mode.\n * @description\n * When set to `true`, the public wrapper renders `GalleryEditor`. Otherwise it renders `GalleryViewer`.\n * @default false\n * @example\n * <Gallery isEditMode files={files} />\n * @optional\n */\n isEditMode?: boolean;\n /**\n * Limits how many files can be managed in edit mode.\n * @description\n * Once the limit is reached, the editor hides the add-tile and does not accept more files.\n * This prop has no effect in read-only mode.\n * @example\n * <Gallery isEditMode maxFiles={6} files={files} />\n * @optional\n */\n maxFiles?: number;\n /**\n * Is called after a file has been uploaded successfully in edit mode.\n * @description\n * The callback receives the uploaded file representation that should be merged into the consuming state.\n * It is never called by the read-only viewer.\n * @example\n * <Gallery isEditMode onAdd={(file) => setFiles((prev) => [...prev, file])} />\n * @optional\n */\n onAdd?: (file: FileItem) => void;\n /**\n * Is called whenever the internal item count changes in edit mode.\n * @description\n * This includes already uploaded files and locally pending uploads that are currently managed by the editor.\n * It is useful when surrounding UI needs to know whether uploads are still in progress.\n * @example\n * <Gallery isEditMode onFileCountChange={(count) => console.log(count)} />\n * @optional\n */\n onFileCountChange?: (fileCount: number) => void;\n /**\n * Is called after an uploaded file has been removed in edit mode.\n * @description\n * The callback receives the removed uploaded file so the consuming state can remove it as well.\n * It is never called by the read-only viewer.\n * @example\n * <Gallery isEditMode onRemove={(file) => removeFile(file.id)} />\n * @optional\n */\n onRemove?: (file: FileItem) => void;\n /**\n * Defines how known media items are arranged in read-only mode.\n * @description\n * This prop only affects the viewer path. The editor always uses its dedicated editable grid layout.\n * @default GalleryViewMode.GRID\n * @example\n * <Gallery files={files} viewMode={GalleryViewMode.SQUARE} />\n * @optional\n */\n viewMode?: GalleryViewMode;\n}\n"],"mappings":"","ignoreList":[]}
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":[]}
@@ -15,8 +15,9 @@ var _GalleryEditorItem = _interopRequireDefault(require("./gallery-editor-item/G
15
15
  var _GalleryEditor = require("./GalleryEditor.styles");
16
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
17
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
18
- const GalleryEditor = ({
18
+ const GalleryEditor = /*#__PURE__*/(0, _react.forwardRef)(({
19
19
  allowDragAndDrop = false,
20
+ addFileIcon = 'fa fa-plus',
20
21
  doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',
21
22
  fileMinWidth = 100,
22
23
  files,
@@ -24,8 +25,11 @@ const GalleryEditor = ({
24
25
  onAdd,
25
26
  onFileCountChange,
26
27
  onRemove
27
- }) => {
28
+ }, ref) => {
28
29
  const [fileItems, setFileItems] = (0, _react.useState)(() => (0, _gallery.mapFilesToInternalItems)(files));
30
+ const handleClear = (0, _react.useCallback)(() => {
31
+ setFileItems([]);
32
+ }, []);
29
33
  const handlePreviewUrlCallback = (0, _react.useCallback)((previewUrl, file) => {
30
34
  setFileItems(prevState => prevState.map(prevFile => {
31
35
  if (prevFile.id === file.id) {
@@ -121,6 +125,9 @@ const GalleryEditor = ({
121
125
  const handleOpenFiles = (0, _react.useCallback)(file => {
122
126
  (0, _gallery.openFiles)(fileItems, file);
123
127
  }, [fileItems]);
128
+ (0, _react.useImperativeHandle)(ref, () => ({
129
+ clear: handleClear
130
+ }), [handleClear]);
124
131
  (0, _react.useEffect)(() => {
125
132
  if (typeof onFileCountChange === 'function') {
126
133
  onFileCountChange(fileItems.length);
@@ -184,15 +191,16 @@ const GalleryEditor = ({
184
191
  }
185
192
  return [...items, /*#__PURE__*/_react.default.createElement(_AddFile.default, {
186
193
  key: "add_file",
194
+ addFileIcon: addFileIcon,
187
195
  onAdd: handleAddFiles
188
196
  })];
189
- }, [fileItems, handleAddFiles, handleDeleteFile, handleOpenFiles, maxFiles]);
197
+ }, [addFileIcon, fileItems, handleAddFiles, handleDeleteFile, handleOpenFiles, maxFiles]);
190
198
  return /*#__PURE__*/_react.default.createElement(_GalleryEditor.StyledGalleryEditor, null, /*#__PURE__*/_react.default.createElement(_GalleryEditor.StyledGalleryEditorGrid, {
191
199
  $fileMinWidth: fileMinWidth,
192
200
  onDragOver: event => event.preventDefault(),
193
201
  onDrop: event => void handleDrop(event)
194
202
  }, galleryItems));
195
- };
203
+ });
196
204
  GalleryEditor.displayName = 'GalleryEditor';
197
205
  var _default = exports.default = GalleryEditor;
198
206
  //# sourceMappingURL=GalleryEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GalleryEditor.js","names":["_core","require","_chaynsApi","_react","_interopRequireWildcard","_uuid","_file","_gallery","_AddFile","_interopRequireDefault","_GalleryEditorItem","_GalleryEditor","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","GalleryEditor","allowDragAndDrop","doubleFileDialogMessage","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","fileItems","setFileItems","useState","mapFilesToInternalItems","handlePreviewUrlCallback","useCallback","previewUrl","file","prevState","map","prevFile","id","callDuplicateFileDialog","createDialog","type","DialogType","ALERT","text","handleUploadFileCallback","uploadedFile","updatedState","_prevFile$uploadedFil","url","undefined","prevElement","find","nextUploadedFile","state","filter","Boolean","handleAddFiles","filesToAdd","newFileItems","forEach","filterDuplicateFile","newFile","push","uuidv4","limitedFileItems","slice","Math","max","length","handleDeleteFile","fileToDelete","filteredFiles","handleDrop","event","preventDefault","Array","from","dataTransfer","handleOpenFiles","openFiles","useEffect","filesToGeneratePreview","filesToUpload","includes","generateVideoThumbnail","callback","generatePreviewUrl","uploadFile","fileToUpload","externalFileItems","updatedItems","prevItem","matchingItem","item","concat","newItem","some","galleryItems","useMemo","items","createElement","key","fileItem","onClick","StyledGalleryEditor","StyledGalleryEditorGrid","$fileMinWidth","onDragOver","onDrop","displayName","_default","exports"],"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, { DragEvent, FC, useCallback, useEffect, useMemo, useState } 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 } from './GalleryEditor.types';\n\nconst GalleryEditor: FC<GalleryEditorProps> = ({\n allowDragAndDrop = false,\n doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',\n fileMinWidth = 100,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n}) => {\n const [fileItems, setFileItems] = useState<InternalFileItem[]>(() =>\n mapFilesToInternalItems(files),\n );\n\n const handlePreviewUrlCallback = useCallback((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 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(0, Math.max(maxFiles - fileItems.length, 0));\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 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 [...items, <AddFile key=\"add_file\" onAdd={handleAddFiles} />];\n }, [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\nGalleryEditor.displayName = 'GalleryEditor';\n\nexport default GalleryEditor;\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAOA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAC,sBAAA,CAAAR,OAAA;AACA,IAAAS,kBAAA,GAAAD,sBAAA,CAAAR,OAAA;AACA,IAAAU,cAAA,GAAAV,OAAA;AAAsF,SAAAQ,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAR,wBAAAQ,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC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CAACI,EAAG;MACbiE,QAAQ,EAAErE,IAAK;MACfsE,OAAO,EAAEzB,eAAgB;MACzBT,gBAAgB,EAAEA;IAAiB,CACtC,CACJ,CAAC;IAEF,IAAI/C,QAAQ,IAAIA,QAAQ,IAAII,SAAS,CAAC0C,MAAM,EAAE;MAC1C,OAAO+B,KAAK;IAChB;IAEA,OAAO,CAAC,GAAGA,KAAK,eAAE9G,MAAA,CAAAW,OAAA,CAAAoG,aAAA,CAAC1G,QAAA,CAAAM,OAAO;MAACqG,GAAG,EAAC,UAAU;MAAC9E,KAAK,EAAEiC;IAAe,CAAE,CAAC,CAAC;EACxE,CAAC,EAAE,CAAC9B,SAAS,EAAE8B,cAAc,EAAEa,gBAAgB,EAAES,eAAe,EAAExD,QAAQ,CAAC,CAAC;EAE5E,oBACIjC,MAAA,CAAAW,OAAA,CAAAoG,aAAA,CAACvG,cAAA,CAAA2G,mBAAmB,qBAChBnH,MAAA,CAAAW,OAAA,CAAAoG,aAAA,CAACvG,cAAA,CAAA4G,uBAAuB;IACpBC,aAAa,EAAEtF,YAAa;IAC5BuF,UAAU,EAAGlC,KAAK,IAAKA,KAAK,CAACC,cAAc,CAAC,CAAE;IAC9CkC,MAAM,EAAGnC,KAAK,IAAK,KAAKD,UAAU,CAACC,KAAK;EAAE,GAEzCwB,YACoB,CACR,CAAC;AAE9B,CAAC;AAEDhF,aAAa,CAAC4F,WAAW,GAAG,eAAe;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA/G,OAAA,GAE7BiB,aAAa","ignoreList":[]}
1
+ {"version":3,"file":"GalleryEditor.js","names":["_core","require","_chaynsApi","_react","_interopRequireWildcard","_uuid","_file","_gallery","_AddFile","_interopRequireDefault","_GalleryEditorItem","_GalleryEditor","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","GalleryEditor","forwardRef","allowDragAndDrop","addFileIcon","doubleFileDialogMessage","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","ref","fileItems","setFileItems","useState","mapFilesToInternalItems","handleClear","useCallback","handlePreviewUrlCallback","previewUrl","file","prevState","map","prevFile","id","callDuplicateFileDialog","createDialog","type","DialogType","ALERT","text","handleUploadFileCallback","uploadedFile","updatedState","_prevFile$uploadedFil","url","undefined","prevElement","find","nextUploadedFile","state","filter","Boolean","handleAddFiles","filesToAdd","newFileItems","forEach","filterDuplicateFile","newFile","push","uuidv4","limitedFileItems","slice","Math","max","length","handleDeleteFile","fileToDelete","filteredFiles","handleDrop","event","preventDefault","Array","from","dataTransfer","handleOpenFiles","openFiles","useImperativeHandle","clear","useEffect","filesToGeneratePreview","filesToUpload","includes","generateVideoThumbnail","callback","generatePreviewUrl","uploadFile","fileToUpload","externalFileItems","updatedItems","prevItem","matchingItem","item","concat","newItem","some","galleryItems","useMemo","items","createElement","key","fileItem","onClick","StyledGalleryEditor","StyledGalleryEditorGrid","$fileMinWidth","onDragOver","onDrop","displayName","_default","exports"],"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,IAAAA,KAAA,GAAAC,OAAA;AAOA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,uBAAA,CAAAH,OAAA;AASA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM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AA,CAAA0G,aAAA,CAAC7G,cAAA,CAAAkH,uBAAuB;IACpBC,aAAa,EAAE1F,YAAa;IAC5B2F,UAAU,EAAGpC,KAAK,IAAKA,KAAK,CAACC,cAAc,CAAC,CAAE;IAC9CoC,MAAM,EAAGrC,KAAK,IAAK,KAAKD,UAAU,CAACC,KAAK;EAAE,GAEzC0B,YACoB,CACR,CAAC;AAE9B,CACJ,CAAC;AAEDtF,aAAa,CAACkG,WAAW,GAAG,eAAe;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAArH,OAAA,GAE7BiB,aAAa","ignoreList":[]}
@@ -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';\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 * 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"],"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 * 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":[]}
@@ -9,6 +9,7 @@ var _react = _interopRequireWildcard(require("react"));
9
9
  var _AddFile = require("./AddFile.styles");
10
10
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
11
  const AddFile = ({
12
+ addFileIcon = 'fa fa-plus',
12
13
  onAdd
13
14
  }) => {
14
15
  const openSelectDialog = (0, _react.useCallback)(async () => {
@@ -24,7 +25,7 @@ const AddFile = ({
24
25
  onClick: () => void openSelectDialog()
25
26
  }, /*#__PURE__*/_react.default.createElement(_core.Icon, {
26
27
  size: 40,
27
- icons: ['fa fa-plus']
28
+ icons: [addFileIcon]
28
29
  })));
29
30
  };
30
31
  AddFile.displayName = 'AddFile';
@@ -1 +1 @@
1
- {"version":3,"file":"AddFile.js","names":["_core","require","_react","_interopRequireWildcard","_AddFile","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","AddFile","onAdd","openSelectDialog","useCallback","files","selectFiles","multiple","type","createElement","StyledAddFile","key","StyledAddFIleIconWrapper","onClick","Icon","size","icons","displayName","_default","exports"],"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> = ({ 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={['fa fa-plus']} />\n </StyledAddFIleIconWrapper>\n </StyledAddFile>\n );\n};\n\nAddFile.displayName = 'AddFile';\n\nexport default AddFile;\n"],"mappings":";;;;;;AA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5BC,QAAQ,EAAE,IAAI;MACdC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFN,KAAK,CAACG,KAAK,CAAC;EAChB,CAAC,EAAE,CAACH,KAAK,CAAC,CAAC;EAEX,oBACIvB,MAAA,CAAAa,OAAA,CAAAiB,aAAA,CAAC5B,QAAA,CAAA6B,aAAa;IAACC,GAAG,EAAC;EAAW,gBAC1BhC,MAAA,CAAAa,OAAA,CAAAiB,aAAA,CAAC5B,QAAA,CAAA+B,wBAAwB;IAACC,OAAO,EAAEA,CAAA,KAAM,KAAKV,gBAAgB,CAAC;EAAE,gBAC7DxB,MAAA,CAAAa,OAAA,CAAAiB,aAAA,CAAChC,KAAA,CAAAqC,IAAI;IAACC,IAAI,EAAE,EAAG;IAACC,KAAK,EAAE,CAAC,YAAY;EAAE,CAAE,CAClB,CACf,CAAC;AAExB,CAAC;AAEDf,OAAO,CAACgB,WAAW,GAAG,SAAS;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA3B,OAAA,GAEjBS,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"AddFile.js","names":["_core","require","_react","_interopRequireWildcard","_AddFile","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","AddFile","addFileIcon","onAdd","openSelectDialog","useCallback","files","selectFiles","multiple","type","createElement","StyledAddFile","key","StyledAddFIleIconWrapper","onClick","Icon","size","icons","displayName","_default","exports"],"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,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAA2E,SAAAE,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAG3E,MAAMkB,OAAyB,GAAGA,CAAC;EAAEC,WAAW,GAAG,YAAY;EAAEC;AAAM,CAAC,KAAK;EACzE,MAAMC,gBAAgB,GAAG,IAAAC,kBAAW,EAAC,YAAY;IAC7C,MAAMC,KAAK,GAAG,MAAM,IAAAC,iBAAW,EAAC;MAC5BC,QAAQ,EAAE,IAAI;MACdC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFN,KAAK,CAACG,KAAK,CAAC;EAChB,CAAC,EAAE,CAACH,KAAK,CAAC,CAAC;EAEX,oBACIxB,MAAA,CAAAa,OAAA,CAAAkB,aAAA,CAAC7B,QAAA,CAAA8B,aAAa;IAACC,GAAG,EAAC;EAAW,gBAC1BjC,MAAA,CAAAa,OAAA,CAAAkB,aAAA,CAAC7B,QAAA,CAAAgC,wBAAwB;IAACC,OAAO,EAAEA,CAAA,KAAM,KAAKV,gBAAgB,CAAC;EAAE,gBAC7DzB,MAAA,CAAAa,OAAA,CAAAkB,aAAA,CAACjC,KAAA,CAAAsC,IAAI;IAACC,IAAI,EAAE,EAAG;IAACC,KAAK,EAAE,CAACf,WAAW;EAAE,CAAE,CACjB,CACf,CAAC;AAExB,CAAC;AAEDD,OAAO,CAACiB,WAAW,GAAG,SAAS;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA5B,OAAA,GAEjBS,OAAO","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"AddFile.types.js","names":[],"sources":["../../../../../src/components/gallery-editor/add-file/AddFile.types.ts"],"sourcesContent":["/**\n * Props for the add-file tile inside the gallery editor.\n */\nexport interface AddFileProps {\n /**\n * Is called with the selected local files.\n * @description\n * The editor add-tile uses this callback after the file picker resolves with the selected local image or video files.\n * @example\n * <AddFile onAdd={(files) => console.log(files)} />\n */\n onAdd: (files: File[]) => void;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"AddFile.types.js","names":[],"sources":["../../../../../src/components/gallery-editor/add-file/AddFile.types.ts"],"sourcesContent":["/**\n * Props for the add-file tile inside the gallery editor.\n */\nexport interface AddFileProps {\n /**\n * Defines the icon that is displayed inside the add-file tile.\n * @description\n * This icon is shown in the tile that opens the file picker for adding new items to the gallery.\n * @default 'fa fa-plus'\n * @example\n * <AddFile addFileIcon=\"fa fa-image-circle-plus\" onAdd={(files) => console.log(files)} />\n * @optional\n */\n addFileIcon?: string;\n /**\n * Is called with the selected local files.\n * @description\n * The editor add-tile uses this callback after the file picker resolves with the selected local image or video files.\n * @example\n * <AddFile onAdd={(files) => console.log(files)} />\n */\n onAdd: (files: File[]) => void;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_Gallery","_interopRequireDefault","require","_GalleryEditor","_GalleryViewer","_gallery","e","__esModule","default"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as Gallery } from './components/Gallery';\nexport { default as GalleryEditor } from './components/gallery-editor/GalleryEditor';\nexport { default as GalleryViewer } from './components/gallery-viewer/GalleryViewer';\nexport type { GalleryProps } from './components/Gallery.types';\nexport type { GalleryEditorProps } from './components/gallery-editor/GalleryEditor.types';\nexport type { GalleryViewerProps } from './components/gallery-viewer/GalleryViewer.types';\nexport { GalleryViewMode } from './types/gallery';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AAIA,IAAAG,QAAA,GAAAH,OAAA;AAAkD,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_Gallery","_interopRequireDefault","require","_GalleryEditor","_GalleryViewer","_gallery","e","__esModule","default"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as Gallery } from './components/Gallery';\nexport { default as GalleryEditor } from './components/gallery-editor/GalleryEditor';\nexport { default as GalleryViewer } from './components/gallery-viewer/GalleryViewer';\nexport type { GalleryProps, GalleryRef } from './components/Gallery.types';\nexport type {\n GalleryEditorProps,\n GalleryEditorRef,\n} from './components/gallery-editor/GalleryEditor.types';\nexport type { GalleryViewerProps } from './components/gallery-viewer/GalleryViewer.types';\nexport { GalleryViewMode } from './types/gallery';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AAOA,IAAAG,QAAA,GAAAH,OAAA;AAAkD,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
@@ -1,9 +1,10 @@
1
- import React from 'react';
1
+ import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
2
2
  import GalleryEditor from './gallery-editor/GalleryEditor';
3
3
  import GalleryViewer from './gallery-viewer/GalleryViewer';
4
4
  import { GalleryViewMode } from '../types/gallery';
5
- const Gallery = ({
5
+ const Gallery = /*#__PURE__*/forwardRef(({
6
6
  allowDragAndDrop = false,
7
+ addFileIcon = 'fa fa-plus',
7
8
  doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',
8
9
  isEditMode = false,
9
10
  fileMinWidth = 100,
@@ -13,18 +14,33 @@ const Gallery = ({
13
14
  onFileCountChange,
14
15
  onRemove,
15
16
  viewMode = GalleryViewMode.GRID
16
- }) => isEditMode ? /*#__PURE__*/React.createElement(GalleryEditor, {
17
- allowDragAndDrop: allowDragAndDrop,
18
- doubleFileDialogMessage: doubleFileDialogMessage,
19
- fileMinWidth: fileMinWidth,
20
- files: files,
21
- maxFiles: maxFiles,
22
- onAdd: onAdd,
23
- onFileCountChange: onFileCountChange,
24
- onRemove: onRemove
25
- }) : /*#__PURE__*/React.createElement(GalleryViewer, {
26
- files: files,
27
- viewMode: viewMode
17
+ }, ref) => {
18
+ const editorRef = useRef(null);
19
+ const handleClear = useCallback(() => {
20
+ if (!isEditMode) {
21
+ console.warn('Gallery.clear() can only be used in edit mode.');
22
+ return;
23
+ }
24
+ editorRef.current?.clear();
25
+ }, [isEditMode]);
26
+ useImperativeHandle(ref, () => ({
27
+ clear: handleClear
28
+ }), [handleClear]);
29
+ return isEditMode ? /*#__PURE__*/React.createElement(GalleryEditor, {
30
+ ref: editorRef,
31
+ allowDragAndDrop: allowDragAndDrop,
32
+ addFileIcon: addFileIcon,
33
+ doubleFileDialogMessage: doubleFileDialogMessage,
34
+ fileMinWidth: fileMinWidth,
35
+ files: files,
36
+ maxFiles: maxFiles,
37
+ onAdd: onAdd,
38
+ onFileCountChange: onFileCountChange,
39
+ onRemove: onRemove
40
+ }) : /*#__PURE__*/React.createElement(GalleryViewer, {
41
+ files: files,
42
+ viewMode: viewMode
43
+ });
28
44
  });
29
45
  Gallery.displayName = 'Gallery';
30
46
  export default Gallery;
@@ -1 +1 @@
1
- {"version":3,"file":"Gallery.js","names":["React","GalleryEditor","GalleryViewer","GalleryViewMode","Gallery","allowDragAndDrop","doubleFileDialogMessage","isEditMode","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","viewMode","GRID","createElement","displayName"],"sources":["../../../src/components/Gallery.tsx"],"sourcesContent":["import React, { FC } from 'react';\nimport GalleryEditor from './gallery-editor/GalleryEditor';\nimport GalleryViewer from './gallery-viewer/GalleryViewer';\nimport type { GalleryProps } from './Gallery.types';\nimport { GalleryViewMode } from '../types/gallery';\n\nconst Gallery: FC<GalleryProps> = ({\n allowDragAndDrop = false,\n doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',\n isEditMode = false,\n fileMinWidth = 100,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n viewMode = GalleryViewMode.GRID,\n}) =>\n isEditMode ? (\n <GalleryEditor\n allowDragAndDrop={allowDragAndDrop}\n doubleFileDialogMessage={doubleFileDialogMessage}\n fileMinWidth={fileMinWidth}\n files={files}\n maxFiles={maxFiles}\n onAdd={onAdd}\n onFileCountChange={onFileCountChange}\n onRemove={onRemove}\n />\n ) : (\n <GalleryViewer files={files} viewMode={viewMode} />\n );\n\nGallery.displayName = 'Gallery';\n\nexport default Gallery;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAc,OAAO;AACjC,OAAOC,aAAa,MAAM,gCAAgC;AAC1D,OAAOC,aAAa,MAAM,gCAAgC;AAE1D,SAASC,eAAe,QAAQ,kBAAkB;AAElD,MAAMC,OAAyB,GAAGA,CAAC;EAC/BC,gBAAgB,GAAG,KAAK;EACxBC,uBAAuB,GAAG,mCAAmC;EAC7DC,UAAU,GAAG,KAAK;EAClBC,YAAY,GAAG,GAAG;EAClBC,KAAK;EACLC,QAAQ;EACRC,KAAK;EACLC,iBAAiB;EACjBC,QAAQ;EACRC,QAAQ,GAAGX,eAAe,CAACY;AAC/B,CAAC,KACGR,UAAU,gBACNP,KAAA,CAAAgB,aAAA,CAACf,aAAa;EACVI,gBAAgB,EAAEA,gBAAiB;EACnCC,uBAAuB,EAAEA,uBAAwB;EACjDE,YAAY,EAAEA,YAAa;EAC3BC,KAAK,EAAEA,KAAM;EACbC,QAAQ,EAAEA,QAAS;EACnBC,KAAK,EAAEA,KAAM;EACbC,iBAAiB,EAAEA,iBAAkB;EACrCC,QAAQ,EAAEA;AAAS,CACtB,CAAC,gBAEFb,KAAA,CAAAgB,aAAA,CAACd,aAAa;EAACO,KAAK,EAAEA,KAAM;EAACK,QAAQ,EAAEA;AAAS,CAAE,CACrD;AAELV,OAAO,CAACa,WAAW,GAAG,SAAS;AAE/B,eAAeb,OAAO","ignoreList":[]}
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"],"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AAS,CACtB,CAAC,gBAEFlB,KAAA,CAAA4B,aAAA,CAACtB,aAAa;IAACQ,KAAK,EAAEA,KAAM;IAACK,QAAQ,EAAEA;EAAS,CAAE,CACrD;AACL,CACJ,CAAC;AAEDX,OAAO,CAACqB,WAAW,GAAG,SAAS;AAE/B,eAAerB,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 interface GalleryProps {\n /**\n * Enables drag and drop while the component is used in edit mode.\n * @description\n * This prop only affects the editor path. In read-only mode, drag and drop stays disabled regardless of this value.\n * @default false\n * @example\n * <Gallery allowDragAndDrop isEditMode files={files} />\n * @optional\n */\n allowDragAndDrop?: boolean;\n /**\n * Defines the dialog message that is shown when a duplicate upload is detected.\n * @description\n * The message is used by the editor when a locally added file resolves to an already known uploaded file.\n * @default 'Diese Datei ist bereits vorhanden'\n * @example\n * <Gallery doubleFileDialogMessage=\"This file already exists.\" isEditMode files={files} />\n * @optional\n */\n doubleFileDialogMessage?: string;\n /**\n * Defines the minimum width of one tile in edit mode.\n * @description\n * The editor uses this value to build its responsive grid. It has no effect in the read-only viewer.\n * @default 100\n * @example\n * <Gallery fileMinWidth={140} isEditMode files={files} />\n * @optional\n */\n fileMinWidth?: number;\n /**\n * Provides already known media items that should be rendered by the gallery.\n * @description\n * In read-only mode, these files are rendered directly from props. In edit mode, they are used as the external baseline\n * for already uploaded media while local uploads are managed internally.\n * @example\n * <Gallery files={files} />\n * @optional\n */\n files?: FileItem[];\n /**\n * Enables the editable upload mode instead of the read-only viewer mode.\n * @description\n * When set to `true`, the public wrapper renders `GalleryEditor`. Otherwise it renders `GalleryViewer`.\n * @default false\n * @example\n * <Gallery isEditMode files={files} />\n * @optional\n */\n isEditMode?: boolean;\n /**\n * Limits how many files can be managed in edit mode.\n * @description\n * Once the limit is reached, the editor hides the add-tile and does not accept more files.\n * This prop has no effect in read-only mode.\n * @example\n * <Gallery isEditMode maxFiles={6} files={files} />\n * @optional\n */\n maxFiles?: number;\n /**\n * Is called after a file has been uploaded successfully in edit mode.\n * @description\n * The callback receives the uploaded file representation that should be merged into the consuming state.\n * It is never called by the read-only viewer.\n * @example\n * <Gallery isEditMode onAdd={(file) => setFiles((prev) => [...prev, file])} />\n * @optional\n */\n onAdd?: (file: FileItem) => void;\n /**\n * Is called whenever the internal item count changes in edit mode.\n * @description\n * This includes already uploaded files and locally pending uploads that are currently managed by the editor.\n * It is useful when surrounding UI needs to know whether uploads are still in progress.\n * @example\n * <Gallery isEditMode onFileCountChange={(count) => console.log(count)} />\n * @optional\n */\n onFileCountChange?: (fileCount: number) => void;\n /**\n * Is called after an uploaded file has been removed in edit mode.\n * @description\n * The callback receives the removed uploaded file so the consuming state can remove it as well.\n * It is never called by the read-only viewer.\n * @example\n * <Gallery isEditMode onRemove={(file) => removeFile(file.id)} />\n * @optional\n */\n onRemove?: (file: FileItem) => void;\n /**\n * Defines how known media items are arranged in read-only mode.\n * @description\n * This prop only affects the viewer path. The editor always uses its dedicated editable grid layout.\n * @default GalleryViewMode.GRID\n * @example\n * <Gallery files={files} viewMode={GalleryViewMode.SQUARE} />\n * @optional\n */\n viewMode?: GalleryViewMode;\n}\n"],"mappings":"","ignoreList":[]}
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,14 +1,15 @@
1
1
  import { uploadFile } from '@chayns-components/core';
2
2
  import { createDialog, DialogType } from 'chayns-api';
3
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
3
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useState } from 'react';
4
4
  import { v4 as uuidv4 } from 'uuid';
5
5
  import { filterDuplicateFile, generatePreviewUrl, generateVideoThumbnail } from '../../utils/file';
6
6
  import { openFiles, mapFilesToInternalItems } from '../../utils/gallery';
7
7
  import AddFile from './add-file/AddFile';
8
8
  import GalleryEditorItem from './gallery-editor-item/GalleryEditorItem';
9
9
  import { StyledGalleryEditor, StyledGalleryEditorGrid } from './GalleryEditor.styles';
10
- const GalleryEditor = ({
10
+ const GalleryEditor = /*#__PURE__*/forwardRef(({
11
11
  allowDragAndDrop = false,
12
+ addFileIcon = 'fa fa-plus',
12
13
  doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',
13
14
  fileMinWidth = 100,
14
15
  files,
@@ -16,8 +17,11 @@ const GalleryEditor = ({
16
17
  onAdd,
17
18
  onFileCountChange,
18
19
  onRemove
19
- }) => {
20
+ }, ref) => {
20
21
  const [fileItems, setFileItems] = useState(() => mapFilesToInternalItems(files));
22
+ const handleClear = useCallback(() => {
23
+ setFileItems([]);
24
+ }, []);
21
25
  const handlePreviewUrlCallback = useCallback((previewUrl, file) => {
22
26
  setFileItems(prevState => prevState.map(prevFile => {
23
27
  if (prevFile.id === file.id) {
@@ -112,6 +116,9 @@ const GalleryEditor = ({
112
116
  const handleOpenFiles = useCallback(file => {
113
117
  openFiles(fileItems, file);
114
118
  }, [fileItems]);
119
+ useImperativeHandle(ref, () => ({
120
+ clear: handleClear
121
+ }), [handleClear]);
115
122
  useEffect(() => {
116
123
  if (typeof onFileCountChange === 'function') {
117
124
  onFileCountChange(fileItems.length);
@@ -175,15 +182,16 @@ const GalleryEditor = ({
175
182
  }
176
183
  return [...items, /*#__PURE__*/React.createElement(AddFile, {
177
184
  key: "add_file",
185
+ addFileIcon: addFileIcon,
178
186
  onAdd: handleAddFiles
179
187
  })];
180
- }, [fileItems, handleAddFiles, handleDeleteFile, handleOpenFiles, maxFiles]);
188
+ }, [addFileIcon, fileItems, handleAddFiles, handleDeleteFile, handleOpenFiles, maxFiles]);
181
189
  return /*#__PURE__*/React.createElement(StyledGalleryEditor, null, /*#__PURE__*/React.createElement(StyledGalleryEditorGrid, {
182
190
  $fileMinWidth: fileMinWidth,
183
191
  onDragOver: event => event.preventDefault(),
184
192
  onDrop: event => void handleDrop(event)
185
193
  }, galleryItems));
186
- };
194
+ });
187
195
  GalleryEditor.displayName = 'GalleryEditor';
188
196
  export default GalleryEditor;
189
197
  //# sourceMappingURL=GalleryEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GalleryEditor.js","names":["uploadFile","createDialog","DialogType","React","useCallback","useEffect","useMemo","useState","v4","uuidv4","filterDuplicateFile","generatePreviewUrl","generateVideoThumbnail","openFiles","mapFilesToInternalItems","AddFile","GalleryEditorItem","StyledGalleryEditor","StyledGalleryEditorGrid","GalleryEditor","allowDragAndDrop","doubleFileDialogMessage","fileMinWidth","files","maxFiles","onAdd","onFileCountChange","onRemove","fileItems","setFileItems","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","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, { DragEvent, FC, useCallback, useEffect, useMemo, useState } 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 } from './GalleryEditor.types';\n\nconst GalleryEditor: FC<GalleryEditorProps> = ({\n allowDragAndDrop = false,\n doubleFileDialogMessage = 'Diese Datei ist bereits vorhanden',\n fileMinWidth = 100,\n files,\n maxFiles,\n onAdd,\n onFileCountChange,\n onRemove,\n}) => {\n const [fileItems, setFileItems] = useState<InternalFileItem[]>(() =>\n mapFilesToInternalItems(files),\n );\n\n const handlePreviewUrlCallback = useCallback((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 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(0, Math.max(maxFiles - fileItems.length, 0));\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 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 [...items, <AddFile key=\"add_file\" onAdd={handleAddFiles} />];\n }, [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\nGalleryEditor.displayName = 'GalleryEditor';\n\nexport default GalleryEditor;\n"],"mappings":"AAAA,SAEIA,UAAU,QAIP,yBAAyB;AAChC,SAASC,YAAY,EAAEC,UAAU,QAAQ,YAAY;AACrD,OAAOC,KAAK,IAAmBC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACvF,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AACnC,SAASC,mBAAmB,EAAEC,kBAAkB,EAAEC,sBAAsB,QAAQ,kBAAkB;AAClG,SAASC,SAAS,EAAEC,uBAAuB,QAAQ,qBAAqB;AACxE,OAAOC,OAAO,MAAM,oBAAoB;AACxC,OAAOC,iBAAiB,MAAM,yCAAyC;AACvE,SAASC,mBAAmB,EAAEC,uBAAuB,QAAQ,wBAAwB;AAGrF,MAAMC,aAAqC,GAAGA,CAAC;EAC3CC,gBAAgB,GAAG,KAAK;EACxBC,uBAAuB,GAAG,mCAAmC;EAC7DC,YAAY,GAAG,GAAG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iB,CACtC,CACJ,CAAC;IAEF,IAAIvC,QAAQ,IAAIA,QAAQ,IAAII,SAAS,CAACkC,MAAM,EAAE;MAC1C,OAAOyB,KAAK;IAChB;IAEA,OAAO,CAAC,GAAGA,KAAK,eAAEpF,KAAA,CAAAqF,aAAA,CAACzE,OAAO;MAAC0E,GAAG,EAAC,UAAU;MAAChE,KAAK,EAAE2B;IAAe,CAAE,CAAC,CAAC;EACxE,CAAC,EAAE,CAACxB,SAAS,EAAEwB,cAAc,EAAEW,gBAAgB,EAAES,eAAe,EAAEhD,QAAQ,CAAC,CAAC;EAE5E,oBACIrB,KAAA,CAAAqF,aAAA,CAACvE,mBAAmB,qBAChBd,KAAA,CAAAqF,aAAA,CAACtE,uBAAuB;IACpB0E,aAAa,EAAEtE,YAAa;IAC5BuE,UAAU,EAAG1B,KAAK,IAAKA,KAAK,CAACC,cAAc,CAAC,CAAE;IAC9C0B,MAAM,EAAG3B,KAAK,IAAK,KAAKD,UAAU,CAACC,KAAK;EAAE,GAEzCmB,YACoB,CACR,CAAC;AAE9B,CAAC;AAEDnE,aAAa,CAAC4E,WAAW,GAAG,eAAe;AAE3C,eAAe5E,aAAa","ignoreList":[]}
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,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,QAAQ,QACL,OAAO;AACd,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AACnC,SAASC,mBAAmB,EAAEC,kBAAkB,EAAEC,sBAAsB,QAAQ,kBAAkB;AAClG,SAASC,SAAS,EAAEC,uBAAuB,QAAQ,qBAAqB;AACxE,OAAOC,OAAO,MAAM,oBAAoB;AACxC,OAAOC,iBAAiB,MAAM,yCAAyC;AACvE,SAASC,mBAAmB,EAAEC,uBAAuB,QAAQ,wBAAwB;AAGrF,MAAMC,aAAa,gBAAGjB,UAAU,CAC5B,CACI;EACIkB,gBAAgB,GAAG,KAAK;EACxBC,WAAW,GAAG,YAAY;EAC1BC,uBAAuB,GAA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GAAGpF,OAAO,CAAC,MAAM;IAC/B,MAAMqF,KAAK,GAAG7D,SAAS,CAACO,GAAG,CAAEF,IAAI,iBAC7BlC,KAAA,CAAA2F,aAAA,CAAC5E,iBAAiB;MACd6E,GAAG,EAAE1D,IAAI,CAACI,EAAG;MACbuD,QAAQ,EAAE3D,IAAK;MACf4D,OAAO,EAAEpB,eAAgB;MACzBT,gBAAgB,EAAEA;IAAiB,CACtC,CACJ,CAAC;IAEF,IAAIzC,QAAQ,IAAIA,QAAQ,IAAIK,SAAS,CAACmC,MAAM,EAAE;MAC1C,OAAO0B,KAAK;IAChB;IAEA,OAAO,CACH,GAAGA,KAAK,eACR1F,KAAA,CAAA2F,aAAA,CAAC7E,OAAO;MAAC8E,GAAG,EAAC,UAAU;MAACxE,WAAW,EAAEA,WAAY;MAACK,KAAK,EAAE6B;IAAe,CAAE,CAAC,CAC9E;EACL,CAAC,EAAE,CAAClC,WAAW,EAAES,SAAS,EAAEyB,cAAc,EAAEW,gBAAgB,EAAES,eAAe,EAAElD,QAAQ,CAAC,CAAC;EAEzF,oBACIxB,KAAA,CAAA2F,aAAA,CAAC3E,mBAAmB,qBAChBhB,KAAA,CAAA2F,aAAA,CAAC1E,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 +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';\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 * 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"],"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 * 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":[]}
@@ -2,6 +2,7 @@ import { Icon, selectFiles } from '@chayns-components/core';
2
2
  import React, { useCallback } from 'react';
3
3
  import { StyledAddFile, StyledAddFIleIconWrapper } from './AddFile.styles';
4
4
  const AddFile = ({
5
+ addFileIcon = 'fa fa-plus',
5
6
  onAdd
6
7
  }) => {
7
8
  const openSelectDialog = useCallback(async () => {
@@ -17,7 +18,7 @@ const AddFile = ({
17
18
  onClick: () => void openSelectDialog()
18
19
  }, /*#__PURE__*/React.createElement(Icon, {
19
20
  size: 40,
20
- icons: ['fa fa-plus']
21
+ icons: [addFileIcon]
21
22
  })));
22
23
  };
23
24
  AddFile.displayName = 'AddFile';
@@ -1 +1 @@
1
- {"version":3,"file":"AddFile.js","names":["Icon","selectFiles","React","useCallback","StyledAddFile","StyledAddFIleIconWrapper","AddFile","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> = ({ 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={['fa fa-plus']} />\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;AAC9C,SAASC,aAAa,EAAEC,wBAAwB,QAAQ,kBAAkB;AAG1E,MAAMC,OAAyB,GAAGA,CAAC;EAAEC;AAAM,CAAC,KAAK;EAC7C,MAAMC,gBAAgB,GAAGL,WAAW,CAAC,YAAY;IAC7C,MAAMM,KAAK,GAAG,MAAMR,WAAW,CAAC;MAC5BS,QAAQ,EAAE,IAAI;MACdC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFJ,KAAK,CAACE,KAAK,CAAC;EAChB,CAAC,EAAE,CAACF,KAAK,CAAC,CAAC;EAEX,oBACIL,KAAA,CAAAU,aAAA,CAACR,aAAa;IAACS,GAAG,EAAC;EAAW,gBAC1BX,KAAA,CAAAU,aAAA,CAACP,wBAAwB;IAACS,OAAO,EAAEA,CAAA,KAAM,KAAKN,gBAAgB,CAAC;EAAE,gBAC7DN,KAAA,CAAAU,aAAA,CAACZ,IAAI;IAACe,IAAI,EAAE,EAAG;IAACC,KAAK,EAAE,CAAC,YAAY;EAAE,CAAE,CAClB,CACf,CAAC;AAExB,CAAC;AAEDV,OAAO,CAACW,WAAW,GAAG,SAAS;AAE/B,eAAeX,OAAO","ignoreList":[]}
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;AAC9C,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,MAAMT,WAAW,CAAC;MAC5BU,QAAQ,EAAE,IAAI;MACdC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFJ,KAAK,CAACE,KAAK,CAAC;EAChB,CAAC,EAAE,CAACF,KAAK,CAAC,CAAC;EAEX,oBACIN,KAAA,CAAAW,aAAA,CAACT,aAAa;IAACU,GAAG,EAAC;EAAW,gBAC1BZ,KAAA,CAAAW,aAAA,CAACR,wBAAwB;IAACU,OAAO,EAAEA,CAAA,KAAM,KAAKN,gBAAgB,CAAC;EAAE,gBAC7DP,KAAA,CAAAW,aAAA,CAACb,IAAI;IAACgB,IAAI,EAAE,EAAG;IAACC,KAAK,EAAE,CAACV,WAAW;EAAE,CAAE,CACjB,CACf,CAAC;AAExB,CAAC;AAEDD,OAAO,CAACY,WAAW,GAAG,SAAS;AAE/B,eAAeZ,OAAO","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"AddFile.types.js","names":[],"sources":["../../../../../src/components/gallery-editor/add-file/AddFile.types.ts"],"sourcesContent":["/**\n * Props for the add-file tile inside the gallery editor.\n */\nexport interface AddFileProps {\n /**\n * Is called with the selected local files.\n * @description\n * The editor add-tile uses this callback after the file picker resolves with the selected local image or video files.\n * @example\n * <AddFile onAdd={(files) => console.log(files)} />\n */\n onAdd: (files: File[]) => void;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"AddFile.types.js","names":[],"sources":["../../../../../src/components/gallery-editor/add-file/AddFile.types.ts"],"sourcesContent":["/**\n * Props for the add-file tile inside the gallery editor.\n */\nexport interface AddFileProps {\n /**\n * Defines the icon that is displayed inside the add-file tile.\n * @description\n * This icon is shown in the tile that opens the file picker for adding new items to the gallery.\n * @default 'fa fa-plus'\n * @example\n * <AddFile addFileIcon=\"fa fa-image-circle-plus\" onAdd={(files) => console.log(files)} />\n * @optional\n */\n addFileIcon?: string;\n /**\n * Is called with the selected local files.\n * @description\n * The editor add-tile uses this callback after the file picker resolves with the selected local image or video files.\n * @example\n * <AddFile onAdd={(files) => console.log(files)} />\n */\n onAdd: (files: File[]) => void;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default","Gallery","GalleryEditor","GalleryViewer","GalleryViewMode"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as Gallery } from './components/Gallery';\nexport { default as GalleryEditor } from './components/gallery-editor/GalleryEditor';\nexport { default as GalleryViewer } from './components/gallery-viewer/GalleryViewer';\nexport type { GalleryProps } from './components/Gallery.types';\nexport type { GalleryEditorProps } from './components/gallery-editor/GalleryEditor.types';\nexport type { GalleryViewerProps } from './components/gallery-viewer/GalleryViewer.types';\nexport { GalleryViewMode } from './types/gallery';\n"],"mappings":"AAAA;;AAEA,SAASA,OAAO,IAAIC,OAAO,QAAQ,sBAAsB;AACzD,SAASD,OAAO,IAAIE,aAAa,QAAQ,2CAA2C;AACpF,SAASF,OAAO,IAAIG,aAAa,QAAQ,2CAA2C;AAIpF,SAASC,eAAe,QAAQ,iBAAiB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["default","Gallery","GalleryEditor","GalleryViewer","GalleryViewMode"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as Gallery } from './components/Gallery';\nexport { default as GalleryEditor } from './components/gallery-editor/GalleryEditor';\nexport { default as GalleryViewer } from './components/gallery-viewer/GalleryViewer';\nexport type { GalleryProps, GalleryRef } from './components/Gallery.types';\nexport type {\n GalleryEditorProps,\n GalleryEditorRef,\n} from './components/gallery-editor/GalleryEditor.types';\nexport type { GalleryViewerProps } from './components/gallery-viewer/GalleryViewer.types';\nexport { GalleryViewMode } from './types/gallery';\n"],"mappings":"AAAA;;AAEA,SAASA,OAAO,IAAIC,OAAO,QAAQ,sBAAsB;AACzD,SAASD,OAAO,IAAIE,aAAa,QAAQ,2CAA2C;AACpF,SAASF,OAAO,IAAIG,aAAa,QAAQ,2CAA2C;AAOpF,SAASC,eAAe,QAAQ,iBAAiB","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { FC } from 'react';
2
- import type { GalleryProps } from './Gallery.types';
3
- declare const Gallery: FC<GalleryProps>;
1
+ import React from 'react';
2
+ import type { GalleryProps, GalleryRef } from './Gallery.types';
3
+ declare const Gallery: React.ForwardRefExoticComponent<GalleryProps & React.RefAttributes<GalleryRef>>;
4
4
  export default Gallery;
@@ -3,6 +3,14 @@ import type { GalleryViewMode } from '../types/gallery';
3
3
  /**
4
4
  * Props for the public Gallery wrapper component.
5
5
  */
6
+ export type GalleryRef = {
7
+ /**
8
+ * Clears all locally managed gallery items in edit mode.
9
+ * @description
10
+ * When the gallery is rendered in read-only mode, calling this method only emits a console warning.
11
+ */
12
+ clear: () => void;
13
+ };
6
14
  export interface GalleryProps {
7
15
  /**
8
16
  * Enables drag and drop while the component is used in edit mode.
@@ -34,6 +42,16 @@ export interface GalleryProps {
34
42
  * @optional
35
43
  */
36
44
  fileMinWidth?: number;
45
+ /**
46
+ * Defines the icon that is shown in the add-file tile in edit mode.
47
+ * @description
48
+ * The icon is forwarded to the editor and replaces the default plus icon on the add-tile.
49
+ * @default 'fa fa-plus'
50
+ * @example
51
+ * <Gallery addFileIcon="fa fa-image-circle-plus" isEditMode files={files} />
52
+ * @optional
53
+ */
54
+ addFileIcon?: string;
37
55
  /**
38
56
  * Provides already known media items that should be rendered by the gallery.
39
57
  * @description
@@ -1,4 +1,4 @@
1
- import { FC } from 'react';
1
+ import React from 'react';
2
2
  import type { GalleryEditorProps } from './GalleryEditor.types';
3
- declare const GalleryEditor: FC<GalleryEditorProps>;
3
+ declare const GalleryEditor: React.ForwardRefExoticComponent<GalleryEditorProps & React.RefAttributes<import("../Gallery.types").GalleryRef>>;
4
4
  export default GalleryEditor;
@@ -1,4 +1,5 @@
1
1
  import type { FileItem } from '@chayns-components/core';
2
+ import type { GalleryRef } from '../Gallery.types';
2
3
  /**
3
4
  * Props for the editable gallery component.
4
5
  */
@@ -33,6 +34,16 @@ export interface GalleryEditorProps {
33
34
  * @optional
34
35
  */
35
36
  fileMinWidth?: number;
37
+ /**
38
+ * Defines the icon that is shown in the add-file tile.
39
+ * @description
40
+ * The editor renders this icon inside the tile that opens the file picker for adding more items.
41
+ * @default 'fa fa-plus'
42
+ * @example
43
+ * <GalleryEditor addFileIcon="fa fa-image-circle-plus" files={files} />
44
+ * @optional
45
+ */
46
+ addFileIcon?: string;
36
47
  /**
37
48
  * Provides already uploaded media items that should be merged into the editor state.
38
49
  * @description
@@ -79,3 +90,4 @@ export interface GalleryEditorProps {
79
90
  */
80
91
  onRemove?: (file: FileItem) => void;
81
92
  }
93
+ export type GalleryEditorRef = GalleryRef;
@@ -2,6 +2,16 @@
2
2
  * Props for the add-file tile inside the gallery editor.
3
3
  */
4
4
  export interface AddFileProps {
5
+ /**
6
+ * Defines the icon that is displayed inside the add-file tile.
7
+ * @description
8
+ * This icon is shown in the tile that opens the file picker for adding new items to the gallery.
9
+ * @default 'fa fa-plus'
10
+ * @example
11
+ * <AddFile addFileIcon="fa fa-image-circle-plus" onAdd={(files) => console.log(files)} />
12
+ * @optional
13
+ */
14
+ addFileIcon?: string;
5
15
  /**
6
16
  * Is called with the selected local files.
7
17
  * @description
@@ -1,7 +1,7 @@
1
1
  export { default as Gallery } from './components/Gallery';
2
2
  export { default as GalleryEditor } from './components/gallery-editor/GalleryEditor';
3
3
  export { default as GalleryViewer } from './components/gallery-viewer/GalleryViewer';
4
- export type { GalleryProps } from './components/Gallery.types';
5
- export type { GalleryEditorProps } from './components/gallery-editor/GalleryEditor.types';
4
+ export type { GalleryProps, GalleryRef } from './components/Gallery.types';
5
+ export type { GalleryEditorProps, GalleryEditorRef, } from './components/gallery-editor/GalleryEditor.types';
6
6
  export type { GalleryViewerProps } from './components/gallery-viewer/GalleryViewer.types';
7
7
  export { GalleryViewMode } from './types/gallery';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/gallery",
3
- "version": "5.2.0",
3
+ "version": "5.2.3",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -84,5 +84,5 @@
84
84
  "publishConfig": {
85
85
  "access": "public"
86
86
  },
87
- "gitHead": "82de2d58db2a74db0a79e51bf153e49da5061fd4"
87
+ "gitHead": "b66e2010d0ae820378ceb6ac043abe04d5ced46e"
88
88
  }