@chayns-components/gallery 5.0.0-beta.132 → 5.0.0-beta.1320

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 (102) hide show
  1. package/README.md +4 -15
  2. package/lib/cjs/components/Gallery.js +319 -0
  3. package/lib/cjs/components/Gallery.js.map +1 -0
  4. package/lib/cjs/components/Gallery.styles.js +93 -0
  5. package/lib/cjs/components/Gallery.styles.js.map +1 -0
  6. package/lib/cjs/components/add-file/AddFile.js +32 -0
  7. package/lib/cjs/components/add-file/AddFile.js.map +1 -0
  8. package/lib/cjs/components/add-file/AddFile.styles.js +23 -0
  9. package/lib/cjs/components/add-file/AddFile.styles.js.map +1 -0
  10. package/lib/cjs/components/gallery-item/GalleryItem.js +44 -0
  11. package/lib/cjs/components/gallery-item/GalleryItem.js.map +1 -0
  12. package/lib/cjs/components/gallery-item/GalleryItem.styles.js +51 -0
  13. package/lib/cjs/components/gallery-item/GalleryItem.styles.js.map +1 -0
  14. package/lib/cjs/components/gallery-item/media-item/MediaItem.js +52 -0
  15. package/lib/cjs/components/gallery-item/media-item/MediaItem.js.map +1 -0
  16. package/lib/cjs/components/gallery-item/media-item/MediaItem.styles.js +62 -0
  17. package/lib/cjs/components/gallery-item/media-item/MediaItem.styles.js.map +1 -0
  18. package/lib/cjs/components/gallery-item/preview-item/PreviewItem.js +45 -0
  19. package/lib/cjs/components/gallery-item/preview-item/PreviewItem.js.map +1 -0
  20. package/lib/cjs/components/gallery-item/preview-item/PreviewItem.styles.js +43 -0
  21. package/lib/cjs/components/gallery-item/preview-item/PreviewItem.styles.js.map +1 -0
  22. package/lib/cjs/index.js +21 -0
  23. package/lib/cjs/index.js.map +1 -0
  24. package/lib/cjs/types/gallery.js +12 -0
  25. package/lib/cjs/types/gallery.js.map +1 -0
  26. package/lib/cjs/utils/file.js +51 -0
  27. package/lib/cjs/utils/file.js.map +1 -0
  28. package/lib/esm/components/Gallery.js +305 -0
  29. package/lib/esm/components/Gallery.js.map +1 -0
  30. package/lib/esm/components/Gallery.styles.js +86 -0
  31. package/lib/esm/components/Gallery.styles.js.map +1 -0
  32. package/lib/esm/components/add-file/AddFile.js +25 -0
  33. package/lib/esm/components/add-file/AddFile.js.map +1 -0
  34. package/lib/esm/components/add-file/AddFile.styles.js +16 -0
  35. package/lib/esm/components/add-file/AddFile.styles.js.map +1 -0
  36. package/lib/esm/components/gallery-item/GalleryItem.js +36 -0
  37. package/lib/esm/components/gallery-item/GalleryItem.js.map +1 -0
  38. package/lib/esm/components/gallery-item/GalleryItem.styles.js +44 -0
  39. package/lib/esm/components/gallery-item/GalleryItem.styles.js.map +1 -0
  40. package/lib/esm/components/gallery-item/media-item/MediaItem.js +42 -0
  41. package/lib/esm/components/gallery-item/media-item/MediaItem.js.map +1 -0
  42. package/lib/esm/components/gallery-item/media-item/MediaItem.styles.js +55 -0
  43. package/lib/esm/components/gallery-item/media-item/MediaItem.styles.js.map +1 -0
  44. package/lib/esm/components/gallery-item/preview-item/PreviewItem.js +38 -0
  45. package/lib/esm/components/gallery-item/preview-item/PreviewItem.js.map +1 -0
  46. package/lib/esm/components/gallery-item/preview-item/PreviewItem.styles.js +36 -0
  47. package/lib/esm/components/gallery-item/preview-item/PreviewItem.styles.js.map +1 -0
  48. package/lib/esm/index.js +5 -0
  49. package/lib/esm/index.js.map +1 -0
  50. package/lib/esm/types/gallery.js +6 -0
  51. package/lib/esm/types/gallery.js.map +1 -0
  52. package/lib/esm/utils/file.js +41 -0
  53. package/lib/esm/utils/file.js.map +1 -0
  54. package/lib/types/components/Gallery.d.ts +47 -0
  55. package/lib/types/components/Gallery.styles.d.ts +10 -0
  56. package/lib/types/components/add-file/AddFile.d.ts +9 -0
  57. package/lib/types/components/add-file/AddFile.styles.d.ts +4 -0
  58. package/lib/{components → types/components}/gallery-item/GalleryItem.d.ts +10 -6
  59. package/lib/types/components/gallery-item/GalleryItem.styles.d.ts +5 -0
  60. package/lib/types/components/gallery-item/media-item/MediaItem.d.ts +22 -0
  61. package/lib/types/components/gallery-item/media-item/MediaItem.styles.d.ts +16 -0
  62. package/lib/types/components/gallery-item/preview-item/PreviewItem.d.ts +14 -0
  63. package/lib/types/components/gallery-item/preview-item/PreviewItem.styles.d.ts +10 -0
  64. package/lib/types/index.d.ts +2 -0
  65. package/lib/types/types/gallery.d.ts +4 -0
  66. package/lib/types/utils/file.d.ts +17 -0
  67. package/package.json +49 -29
  68. package/lib/api/image/post.d.ts +0 -16
  69. package/lib/api/image/post.js +0 -34
  70. package/lib/api/image/post.js.map +0 -1
  71. package/lib/api/video/post.d.ts +0 -16
  72. package/lib/api/video/post.js +0 -30
  73. package/lib/api/video/post.js.map +0 -1
  74. package/lib/components/Gallery.d.ts +0 -34
  75. package/lib/components/Gallery.js +0 -163
  76. package/lib/components/Gallery.js.map +0 -1
  77. package/lib/components/Gallery.styles.d.ts +0 -6
  78. package/lib/components/Gallery.styles.js +0 -40
  79. package/lib/components/Gallery.styles.js.map +0 -1
  80. package/lib/components/add-file/AddFile.d.ts +0 -26
  81. package/lib/components/add-file/AddFile.js +0 -83
  82. package/lib/components/add-file/AddFile.js.map +0 -1
  83. package/lib/components/add-file/AddFile.styles.d.ts +0 -4
  84. package/lib/components/add-file/AddFile.styles.js +0 -31
  85. package/lib/components/add-file/AddFile.styles.js.map +0 -1
  86. package/lib/components/gallery-item/GalleryItem.js +0 -60
  87. package/lib/components/gallery-item/GalleryItem.js.map +0 -1
  88. package/lib/components/gallery-item/GalleryItem.styles.d.ts +0 -17
  89. package/lib/components/gallery-item/GalleryItem.styles.js +0 -107
  90. package/lib/components/gallery-item/GalleryItem.styles.js.map +0 -1
  91. package/lib/index.d.ts +0 -4
  92. package/lib/index.js +0 -40
  93. package/lib/index.js.map +0 -1
  94. package/lib/types/file.d.ts +0 -20
  95. package/lib/types/file.js +0 -6
  96. package/lib/types/file.js.map +0 -1
  97. package/lib/utils/file.d.ts +0 -17
  98. package/lib/utils/file.js +0 -92
  99. package/lib/utils/file.js.map +0 -1
  100. package/lib/utils/upload.d.ts +0 -8
  101. package/lib/utils/upload.js +0 -56
  102. package/lib/utils/upload.js.map +0 -1
@@ -1,107 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.StyledGalleryItemVideoWrapper = exports.StyledGalleryItemVideo = exports.StyledGalleryItemPlayIcon = exports.StyledGalleryItemMoreItemsIndicator = exports.StyledGalleryItemImage = exports.StyledGalleryItemDeleteButton = exports.StyledGalleryItem = void 0;
7
- var _styledComponents = _interopRequireDefault(require("styled-components"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const StyledGalleryItem = _styledComponents.default.div`
10
- display: flex;
11
- position: relative;
12
- `;
13
- exports.StyledGalleryItem = StyledGalleryItem;
14
- const StyledGalleryItemDeleteButton = _styledComponents.default.button`
15
- background-color: rgba(
16
- ${_ref => {
17
- let {
18
- theme
19
- } = _ref;
20
- return theme['000-rgb'];
21
- }},
22
- 0.75
23
- );
24
- box-shadow: 0 0 0 1px
25
- rgba(${_ref2 => {
26
- let {
27
- theme
28
- } = _ref2;
29
- return theme['009-rgb'];
30
- }}, 0.08) inset;
31
- position: absolute;
32
- top: 0;
33
- right: 0;
34
- z-index: 2;
35
- height: 30px;
36
- width: 30px;
37
- display: flex;
38
- justify-content: center;
39
- align-items: center;
40
- `;
41
- exports.StyledGalleryItemDeleteButton = StyledGalleryItemDeleteButton;
42
- const StyledGalleryItemVideoWrapper = _styledComponents.default.div``;
43
- exports.StyledGalleryItemVideoWrapper = StyledGalleryItemVideoWrapper;
44
- const StyledGalleryItemImage = _styledComponents.default.img`
45
- background-color: ${_ref3 => {
46
- let {
47
- theme
48
- } = _ref3;
49
- return theme['101'];
50
- }};
51
- box-shadow: 0 0 0 1px
52
- rgba(${_ref4 => {
53
- let {
54
- theme
55
- } = _ref4;
56
- return theme['009-rgb'];
57
- }}, 0.08) inset;
58
- z-index: 1;
59
- width: 100%;
60
- aspect-ratio: ${props => props.ratio};
61
- object-fit: cover;
62
- `;
63
- exports.StyledGalleryItemImage = StyledGalleryItemImage;
64
- const StyledGalleryItemVideo = _styledComponents.default.video`
65
- background-color: ${_ref5 => {
66
- let {
67
- theme
68
- } = _ref5;
69
- return theme['101'];
70
- }};
71
- box-shadow: 0 0 0 1px
72
- rgba(${_ref6 => {
73
- let {
74
- theme
75
- } = _ref6;
76
- return theme['009-rgb'];
77
- }}, 0.08) inset;
78
- width: 100%;
79
- aspect-ratio: ${props => props.ratio};
80
- object-fit: cover;
81
- `;
82
- exports.StyledGalleryItemVideo = StyledGalleryItemVideo;
83
- const StyledGalleryItemPlayIcon = _styledComponents.default.div`
84
- position: absolute;
85
- z-index: 2;
86
- top: 50%;
87
- left: 50%;
88
- transform: translate(-50%, -50%);
89
- `;
90
- exports.StyledGalleryItemPlayIcon = StyledGalleryItemPlayIcon;
91
- const StyledGalleryItemMoreItemsIndicator = _styledComponents.default.div`
92
- position: absolute;
93
- z-index: 2;
94
- height: 100%;
95
- width: 100%;
96
- display: flex;
97
- justify-content: center;
98
- align-items: center;
99
- backdrop-filter: brightness(40%);
100
-
101
- p {
102
- font-size: 40px;
103
- color: white;
104
- }
105
- `;
106
- exports.StyledGalleryItemMoreItemsIndicator = StyledGalleryItemMoreItemsIndicator;
107
- //# sourceMappingURL=GalleryItem.styles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GalleryItem.styles.js","names":["_styledComponents","_interopRequireDefault","require","obj","__esModule","default","StyledGalleryItem","styled","div","exports","StyledGalleryItemDeleteButton","button","_ref","theme","_ref2","StyledGalleryItemVideoWrapper","StyledGalleryItemImage","img","_ref3","_ref4","props","ratio","StyledGalleryItemVideo","video","_ref5","_ref6","StyledGalleryItemPlayIcon","StyledGalleryItemMoreItemsIndicator"],"sources":["../../../src/components/gallery-item/GalleryItem.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled from 'styled-components';\n\nexport const StyledGalleryItem = styled.div`\n display: flex;\n position: relative;\n`;\n\ntype StyledGalleryItemDeleteButtonProps = WithTheme<unknown>;\n\nexport const StyledGalleryItemDeleteButton = styled.button<StyledGalleryItemDeleteButtonProps>`\n background-color: rgba(\n ${({ theme }: StyledGalleryItemDeleteButtonProps) => theme['000-rgb']},\n 0.75\n );\n box-shadow: 0 0 0 1px\n rgba(${({ theme }: StyledGalleryItemDeleteButtonProps) => theme['009-rgb']}, 0.08) inset;\n position: absolute;\n top: 0;\n right: 0;\n z-index: 2;\n height: 30px;\n width: 30px;\n display: flex;\n justify-content: center;\n align-items: center;\n`;\n\nexport const StyledGalleryItemVideoWrapper = styled.div``;\n\ntype StyledGalleryItemVideoProps = WithTheme<{\n ratio: number;\n}>;\n\ntype StyledGalleryItemImageProps = WithTheme<{\n ratio: number;\n}>;\n\nexport const StyledGalleryItemImage = styled.img<StyledGalleryItemImageProps>`\n background-color: ${({ theme }: StyledGalleryItemImageProps) => theme['101']};\n box-shadow: 0 0 0 1px\n rgba(${({ theme }: StyledGalleryItemImageProps) => theme['009-rgb']}, 0.08) inset;\n z-index: 1;\n width: 100%;\n aspect-ratio: ${(props) => props.ratio};\n object-fit: cover;\n`;\n\nexport const StyledGalleryItemVideo = styled.video<StyledGalleryItemVideoProps>`\n background-color: ${({ theme }: StyledGalleryItemVideoProps) => theme['101']};\n box-shadow: 0 0 0 1px\n rgba(${({ theme }: StyledGalleryItemVideoProps) => theme['009-rgb']}, 0.08) inset;\n width: 100%;\n aspect-ratio: ${(props) => props.ratio};\n object-fit: cover;\n`;\n\nexport const StyledGalleryItemPlayIcon = styled.div`\n position: absolute;\n z-index: 2;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n`;\n\nexport const StyledGalleryItemMoreItemsIndicator = styled.div`\n position: absolute;\n z-index: 2;\n height: 100%;\n width: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n backdrop-filter: brightness(40%);\n\n p {\n font-size: 40px;\n color: white;\n }\n`;\n"],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F,wBAAwBC,KAAA;EAAA,IAAC;IAAEX;EAAmC,CAAC,GAAAW,KAAA;EAAA,OAAKX,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AACjF;AACA,eAAeY,KAAA;EAAA,IAAC;IAAEZ;EAAmC,CAAC,GAAAY,KAAA;EAAA,OAAKZ,KAAK,CAAC,SAAS,CAAC;AAAA,CAAC;AAC5E;AACA,oBAAqBO,KAAK,IAAKA,KAAK,CAACC,KAAM;AAC3C;AACA,CAAC;AAACZ,OAAA,CAAAa,sBAAA,GAAAA,sBAAA;AAEK,MAAMI,yBAAyB,GAAGnB,yBAAM,CAACC,GAAI;AACpD;AACA;AACA;AACA;AACA;AACA,CAAC;AAACC,OAAA,CAAAiB,yBAAA,GAAAA,yBAAA;AAEK,MAAMC,mCAAmC,GAAGpB,yBAAM,CAACC,GAAI;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAACC,OAAA,CAAAkB,mCAAA,GAAAA,mCAAA"}
package/lib/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export { default as Gallery } from './components/Gallery';
2
- export type { ExternalFile, Image, Meta, UploadedFile, Video } from './types/file';
3
- export { convertFileListToArray, filterDuplicateFiles, selectFiles } from './utils/file';
4
- export { uploadFiles } from './utils/upload';
package/lib/index.js DELETED
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "Gallery", {
7
- enumerable: true,
8
- get: function () {
9
- return _Gallery.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "convertFileListToArray", {
13
- enumerable: true,
14
- get: function () {
15
- return _file.convertFileListToArray;
16
- }
17
- });
18
- Object.defineProperty(exports, "filterDuplicateFiles", {
19
- enumerable: true,
20
- get: function () {
21
- return _file.filterDuplicateFiles;
22
- }
23
- });
24
- Object.defineProperty(exports, "selectFiles", {
25
- enumerable: true,
26
- get: function () {
27
- return _file.selectFiles;
28
- }
29
- });
30
- Object.defineProperty(exports, "uploadFiles", {
31
- enumerable: true,
32
- get: function () {
33
- return _upload.uploadFiles;
34
- }
35
- });
36
- var _Gallery = _interopRequireDefault(require("./components/Gallery"));
37
- var _file = require("./utils/file");
38
- var _upload = require("./utils/upload");
39
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_Gallery","_interopRequireDefault","require","_file","_upload","obj","__esModule","default"],"sources":["../src/index.ts"],"sourcesContent":["export { default as Gallery } from './components/Gallery';\nexport type { ExternalFile, Image, Meta, UploadedFile, Video } from './types/file';\nexport { convertFileListToArray, filterDuplicateFiles, selectFiles } from './utils/file';\nexport { uploadFiles } from './utils/upload';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAA6C,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA"}
@@ -1,20 +0,0 @@
1
- export interface Video {
2
- id: number;
3
- originalVideoQuality?: string;
4
- thumbnailUrl: string;
5
- url: string;
6
- ratio?: number;
7
- }
8
- export interface Image {
9
- id?: string;
10
- url: string;
11
- meta?: Meta;
12
- ratio?: number;
13
- }
14
- export interface Meta {
15
- preview: string;
16
- width: string;
17
- height: string;
18
- }
19
- export type ExternalFile = Omit<Video, 'originalVideoQuality'> | Image;
20
- export type UploadedFile = Video | Image;
package/lib/types/file.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- //# sourceMappingURL=file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.js","names":[],"sources":["../../src/types/file.ts"],"sourcesContent":["export interface Video {\n id: number;\n originalVideoQuality?: string;\n thumbnailUrl: string;\n url: string;\n ratio?: number;\n}\n\nexport interface Image {\n id?: string;\n url: string;\n meta?: Meta;\n ratio?: number;\n}\n\nexport interface Meta {\n preview: string;\n width: string;\n height: string;\n}\n\nexport type ExternalFile = Omit<Video, 'originalVideoQuality'> | Image;\n\nexport type UploadedFile = Video | Image;\n"],"mappings":""}
@@ -1,17 +0,0 @@
1
- import type { UploadedFile } from '../types/file';
2
- interface SelectFilesOptions {
3
- type: string;
4
- multiple: boolean;
5
- }
6
- export declare const selectFiles: ({ type, multiple }: SelectFilesOptions) => Promise<null | FileList>;
7
- export declare const convertFileListToArray: (fileList: FileList) => File[];
8
- interface FilterDuplicateFilesOptions {
9
- oldFiles: UploadedFile[];
10
- newFiles: UploadedFile[];
11
- }
12
- export declare const filterDuplicateFiles: ({ oldFiles, newFiles }: FilterDuplicateFilesOptions) => {
13
- filteredFiles: UploadedFile[];
14
- newUniqueFiles: UploadedFile[];
15
- };
16
- export declare const getFileAsArrayBuffer: (file: File) => Promise<string | ArrayBuffer>;
17
- export {};
package/lib/utils/file.js DELETED
@@ -1,92 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.selectFiles = exports.getFileAsArrayBuffer = exports.filterDuplicateFiles = exports.convertFileListToArray = void 0;
7
- const selectFiles = _ref => {
8
- let {
9
- type,
10
- multiple
11
- } = _ref;
12
- return new Promise(resolve => {
13
- const input = document.createElement('input');
14
- input.type = 'file';
15
- if (type !== '*/*' && type) {
16
- input.accept = type;
17
- }
18
- if (multiple) {
19
- input.multiple = true;
20
- }
21
- input.style.visibility = 'none';
22
- input.style.width = '0';
23
- input.style.height = '0';
24
- input.style.display = 'none';
25
- document.body.appendChild(input);
26
- input.addEventListener('change', event => {
27
- document.body.removeChild(input);
28
- const target = event.target;
29
- const {
30
- files
31
- } = target;
32
- resolve(files);
33
- });
34
- input.click();
35
- });
36
- };
37
- exports.selectFiles = selectFiles;
38
- const convertFileListToArray = fileList => {
39
- const filesArray = [];
40
- for (let i = 0; i < fileList.length; i++) {
41
- const file = fileList.item(i);
42
- if (file) {
43
- filesArray.push(file);
44
- }
45
- }
46
- return filesArray;
47
- };
48
- exports.convertFileListToArray = convertFileListToArray;
49
- const filterDuplicateFiles = _ref2 => {
50
- let {
51
- oldFiles,
52
- newFiles
53
- } = _ref2;
54
- const seenKeys = new Set();
55
- const filteredFiles = [];
56
- oldFiles.forEach(file => {
57
- var _file$id$toString, _file$id;
58
- seenKeys.add((_file$id$toString = (_file$id = file.id) === null || _file$id === void 0 ? void 0 : _file$id.toString()) !== null && _file$id$toString !== void 0 ? _file$id$toString : file.url);
59
- filteredFiles.push(file);
60
- });
61
- const newUniqueFiles = [];
62
- newFiles.forEach(file => {
63
- var _file$id$toString2, _file$id2;
64
- const key = (_file$id$toString2 = (_file$id2 = file.id) === null || _file$id2 === void 0 ? void 0 : _file$id2.toString()) !== null && _file$id$toString2 !== void 0 ? _file$id$toString2 : file.url;
65
- const oldFile = oldFiles.find(f => f.id === file.id);
66
- const alreadyAdded = newUniqueFiles.find(f => f.id === file.id);
67
- if (!oldFile && !alreadyAdded) {
68
- seenKeys.add(key);
69
- newUniqueFiles.push(file);
70
- }
71
- });
72
- return {
73
- filteredFiles,
74
- newUniqueFiles
75
- };
76
- };
77
- exports.filterDuplicateFiles = filterDuplicateFiles;
78
- const getFileAsArrayBuffer = file => new Promise((resolve, reject) => {
79
- const reader = new FileReader();
80
- reader.onload = e => {
81
- var _e$target;
82
- if ((_e$target = e.target) !== null && _e$target !== void 0 && _e$target.result) {
83
- resolve(e.target.result);
84
- } else {
85
- reject(Error('Could not get array buffer.'));
86
- }
87
- };
88
- reader.onerror = reject;
89
- reader.readAsArrayBuffer(file);
90
- });
91
- exports.getFileAsArrayBuffer = getFileAsArrayBuffer;
92
- //# sourceMappingURL=file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.js","names":["selectFiles","_ref","type","multiple","Promise","resolve","input","document","createElement","accept","style","visibility","width","height","display","body","appendChild","addEventListener","event","removeChild","target","files","click","exports","convertFileListToArray","fileList","filesArray","i","length","file","item","push","filterDuplicateFiles","_ref2","oldFiles","newFiles","seenKeys","Set","filteredFiles","forEach","_file$id$toString","_file$id","add","id","toString","url","newUniqueFiles","_file$id$toString2","_file$id2","key","oldFile","find","f","alreadyAdded","getFileAsArrayBuffer","reject","reader","FileReader","onload","e","_e$target","result","Error","onerror","readAsArrayBuffer"],"sources":["../../src/utils/file.ts"],"sourcesContent":["import type { UploadedFile } from '../types/file';\n\ninterface SelectFilesOptions {\n type: string;\n multiple: boolean;\n}\n\nexport const selectFiles = ({ type, multiple }: SelectFilesOptions): Promise<null | FileList> =>\n new Promise((resolve) => {\n const input = document.createElement('input');\n input.type = 'file';\n\n if (type !== '*/*' && type) {\n input.accept = type;\n }\n\n if (multiple) {\n input.multiple = true;\n }\n\n input.style.visibility = 'none';\n input.style.width = '0';\n input.style.height = '0';\n input.style.display = 'none';\n\n document.body.appendChild(input);\n\n input.addEventListener('change', (event) => {\n document.body.removeChild(input);\n\n const target = event.target as HTMLInputElement;\n const { files } = target;\n\n resolve(files);\n });\n\n input.click();\n });\n\nexport const convertFileListToArray = (fileList: FileList): File[] => {\n const filesArray = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList.item(i);\n\n if (file) {\n filesArray.push(file);\n }\n }\n\n return filesArray;\n};\n\ninterface FilterDuplicateFilesOptions {\n oldFiles: UploadedFile[];\n newFiles: UploadedFile[];\n}\n\nexport const filterDuplicateFiles = ({ oldFiles, newFiles }: FilterDuplicateFilesOptions) => {\n const seenKeys = new Set<string>();\n\n const filteredFiles: UploadedFile[] = [];\n\n oldFiles.forEach((file) => {\n seenKeys.add(file.id?.toString() ?? file.url);\n filteredFiles.push(file);\n });\n\n const newUniqueFiles: UploadedFile[] = [];\n\n newFiles.forEach((file) => {\n const key = file.id?.toString() ?? file.url;\n\n const oldFile = oldFiles.find((f) => f.id === file.id);\n\n const alreadyAdded = newUniqueFiles.find((f) => f.id === file.id);\n\n if (!oldFile && !alreadyAdded) {\n seenKeys.add(key);\n newUniqueFiles.push(file);\n }\n });\n\n return { filteredFiles, newUniqueFiles };\n};\n\nexport const getFileAsArrayBuffer = (file: File): Promise<string | ArrayBuffer> =>\n new Promise((resolve, reject) => {\n const reader = new FileReader();\n\n reader.onload = (e) => {\n if (e.target?.result) {\n resolve(e.target.result);\n } else {\n reject(Error('Could not get array buffer.'));\n }\n };\n\n reader.onerror = reject;\n\n reader.readAsArrayBuffer(file);\n });\n"],"mappings":";;;;;;AAOO,MAAMA,WAAW,GAAGC,IAAA;EAAA,IAAC;IAAEC,IAAI;IAAEC;EAA6B,CAAC,GAAAF,IAAA;EAAA,OAC9D,IAAIG,OAAO,CAAEC,OAAO,IAAK;IACrB,MAAMC,KAAK,GAAGC,QAAQ,CAACC,aAAa,CAAC,OAAO,CAAC;IAC7CF,KAAK,CAACJ,IAAI,GAAG,MAAM;IAEnB,IAAIA,IAAI,KAAK,KAAK,IAAIA,IAAI,EAAE;MACxBI,KAAK,CAACG,MAAM,GAAGP,IAAI;IACvB;IAEA,IAAIC,QAAQ,EAAE;MACVG,KAAK,CAACH,QAAQ,GAAG,IAAI;IACzB;IAEAG,KAAK,CAACI,KAAK,CAACC,UAAU,GAAG,MAAM;IAC/BL,KAAK,CAACI,KAAK,CAACE,KAAK,GAAG,GAAG;IACvBN,KAAK,CAACI,KAAK,CAACG,MAAM,GAAG,GAAG;IACxBP,KAAK,CAACI,KAAK,CAACI,OAAO,GAAG,MAAM;IAE5BP,QAAQ,CAACQ,IAAI,CAACC,WAAW,CAACV,KAAK,CAAC;IAEhCA,KAAK,CAACW,gBAAgB,CAAC,QAAQ,EAAGC,KAAK,IAAK;MACxCX,QAAQ,CAACQ,IAAI,CAACI,WAAW,CAACb,KAAK,CAAC;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AAI,CAAC;AAClC,CAAC,CAAC;AAACN,OAAA,CAAA+B,oBAAA,GAAAA,oBAAA"}
@@ -1,8 +0,0 @@
1
- import type { UploadedFile } from '../types/file';
2
- interface UploadFilesOptions {
3
- filesToUpload: File[];
4
- accessToken: string;
5
- personId: string;
6
- }
7
- export declare const uploadFiles: ({ filesToUpload, personId, accessToken, }: UploadFilesOptions) => Promise<UploadedFile[]>;
8
- export {};
@@ -1,56 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.uploadFiles = void 0;
7
- var _post = require("../api/image/post");
8
- var _post2 = require("../api/video/post");
9
- const uploadFiles = async _ref => {
10
- let {
11
- filesToUpload,
12
- personId,
13
- accessToken
14
- } = _ref;
15
- if (!filesToUpload) {
16
- return [];
17
- }
18
- const videos = filesToUpload.filter(_ref2 => {
19
- let {
20
- type
21
- } = _ref2;
22
- return type.includes('video/');
23
- });
24
- const images = filesToUpload.filter(_ref3 => {
25
- let {
26
- type
27
- } = _ref3;
28
- return type.includes('image/');
29
- });
30
- let newUploadedFiles = [];
31
-
32
- // Upload videos
33
- const videoUploadPromises = videos.map(video => (0, _post2.postVideo)({
34
- accessToken,
35
- file: video
36
- }));
37
- newUploadedFiles = newUploadedFiles.concat(await Promise.all(videoUploadPromises));
38
- newUploadedFiles = newUploadedFiles.flat();
39
-
40
- // Upload images
41
- const imageUploadPromises = images.map(image => (0, _post.postImage)({
42
- accessToken,
43
- file: image,
44
- personId
45
- }));
46
- const uploadedImages = await Promise.all(imageUploadPromises);
47
- const newImages = uploadedImages.map(file => ({
48
- url: `${file.base}/${file.key}`,
49
- id: file.key,
50
- meta: file.meta
51
- }));
52
- newUploadedFiles = newUploadedFiles.concat(newImages);
53
- return newUploadedFiles;
54
- };
55
- exports.uploadFiles = uploadFiles;
56
- //# sourceMappingURL=upload.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"upload.js","names":["_post","require","_post2","uploadFiles","_ref","filesToUpload","personId","accessToken","videos","filter","_ref2","type","includes","images","_ref3","newUploadedFiles","videoUploadPromises","map","video","postVideo","file","concat","Promise","all","flat","imageUploadPromises","image","postImage","uploadedImages","newImages","url","base","key","id","meta","exports"],"sources":["../../src/utils/upload.ts"],"sourcesContent":["import { postImage } from '../api/image/post';\nimport { postVideo } from '../api/video/post';\nimport type { UploadedFile, Video } from '../types/file';\n\ninterface UploadFilesOptions {\n filesToUpload: File[];\n accessToken: string;\n personId: string;\n}\n\nexport const uploadFiles = async ({\n filesToUpload,\n personId,\n accessToken,\n}: UploadFilesOptions): Promise<UploadedFile[]> => {\n if (!filesToUpload) {\n return [];\n }\n\n const videos = filesToUpload.filter(({ type }) => type.includes('video/'));\n const images = filesToUpload.filter(({ type }) => type.includes('image/'));\n\n let newUploadedFiles: UploadedFile[] = [];\n\n // Upload videos\n const videoUploadPromises: Promise<Video>[] = videos.map((video) =>\n postVideo({ accessToken, file: video })\n );\n\n newUploadedFiles = newUploadedFiles.concat(await Promise.all(videoUploadPromises));\n newUploadedFiles = newUploadedFiles.flat();\n\n // Upload images\n const imageUploadPromises = images.map((image) =>\n postImage({\n accessToken,\n file: image,\n personId,\n })\n );\n\n const uploadedImages = await Promise.all(imageUploadPromises);\n\n const newImages: UploadedFile[] = uploadedImages.map((file) => ({\n url: `${file.base}/${file.key}`,\n id: file.key,\n meta: file.meta,\n }));\n\n newUploadedFiles = newUploadedFiles.concat(newImages);\n\n return newUploadedFiles;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AASO,MAAME,WAAW,GAAG,MAAAC,IAAA,IAIwB;EAAA,IAJjB;IAC9BC,aAAa;IACbC,QAAQ;IACRC;EACgB,CAAC,GAAAH,IAAA;EACjB,IAAI,CAACC,aAAa,EAAE;IAChB,OAAO,EAAE;EACb;EAEA,MAAMG,MAAM,GAAGH,aAAa,CAACI,MAAM,CAACC,KAAA;IAAA,IAAC;MAA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