@akemona-org/strapi-plugin-upload 3.7.0

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 (246) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -0
  3. package/admin/src/assets/images/logo.svg +1 -0
  4. package/admin/src/components/BrowseAssets/Wrapper.js +8 -0
  5. package/admin/src/components/BrowseAssets/index.js +182 -0
  6. package/admin/src/components/Card/index.js +146 -0
  7. package/admin/src/components/CardBorder/index.js +28 -0
  8. package/admin/src/components/CardControl/Wrapper.js +89 -0
  9. package/admin/src/components/CardControl/index.js +61 -0
  10. package/admin/src/components/CardControlsWrapper/index.js +22 -0
  11. package/admin/src/components/CardEmpty/Bar.js +19 -0
  12. package/admin/src/components/CardEmpty/Wrapper.js +7 -0
  13. package/admin/src/components/CardEmpty/index.js +16 -0
  14. package/admin/src/components/CardErrorMessage/index.js +9 -0
  15. package/admin/src/components/CardImgWrapper/index.js +52 -0
  16. package/admin/src/components/CardPreview/Image.js +12 -0
  17. package/admin/src/components/CardPreview/Wrapper.js +25 -0
  18. package/admin/src/components/CardPreview/index.js +66 -0
  19. package/admin/src/components/CardTitle/index.js +14 -0
  20. package/admin/src/components/CardWrapper/index.js +23 -0
  21. package/admin/src/components/CheckControl/Button.js +49 -0
  22. package/admin/src/components/CheckControl/CustomDropdownSection.js +9 -0
  23. package/admin/src/components/CheckControl/Spacer.js +7 -0
  24. package/admin/src/components/CheckControl/index.js +74 -0
  25. package/admin/src/components/Container/index.js +7 -0
  26. package/admin/src/components/ContainerFluid/index.js +12 -0
  27. package/admin/src/components/ControlsWrapper/index.js +9 -0
  28. package/admin/src/components/DragLayer/Wrapper.js +13 -0
  29. package/admin/src/components/DragLayer/index.js +68 -0
  30. package/admin/src/components/DropdownButton/index.js +63 -0
  31. package/admin/src/components/DropdownSection/index.js +27 -0
  32. package/admin/src/components/Duration/index.js +25 -0
  33. package/admin/src/components/Duration/utils/formatDuration.js +13 -0
  34. package/admin/src/components/EditForm/CropWrapper.js +21 -0
  35. package/admin/src/components/EditForm/ErrorMessage.js +10 -0
  36. package/admin/src/components/EditForm/FileDetailsBox.js +95 -0
  37. package/admin/src/components/EditForm/FileDetailsBoxWrapper.js +14 -0
  38. package/admin/src/components/EditForm/FileWrapper.js +41 -0
  39. package/admin/src/components/EditForm/FormWrapper.js +7 -0
  40. package/admin/src/components/EditForm/SizeBox.js +13 -0
  41. package/admin/src/components/EditForm/Wrapper.js +8 -0
  42. package/admin/src/components/EditForm/index.js +425 -0
  43. package/admin/src/components/EditForm/utils/form.js +34 -0
  44. package/admin/src/components/EditForm/utils/isImageType.js +3 -0
  45. package/admin/src/components/EditForm/utils/isVideoType.js +3 -0
  46. package/admin/src/components/FileIcon/Wrapper.js +20 -0
  47. package/admin/src/components/FileIcon/index.js +33 -0
  48. package/admin/src/components/FileIcon/utils/extensions.json +4 -0
  49. package/admin/src/components/FileInfos/index.js +32 -0
  50. package/admin/src/components/Filters/index.js +30 -0
  51. package/admin/src/components/FiltersList/index.js +34 -0
  52. package/admin/src/components/FiltersList/utils/formatFilter.js +36 -0
  53. package/admin/src/components/FiltersPicker/FiltersCard/FilterButton.js +8 -0
  54. package/admin/src/components/FiltersPicker/FiltersCard/FilterInput.js +35 -0
  55. package/admin/src/components/FiltersPicker/FiltersCard/InputWrapper.js +10 -0
  56. package/admin/src/components/FiltersPicker/FiltersCard/SizeInput.js +57 -0
  57. package/admin/src/components/FiltersPicker/FiltersCard/Wrapper.js +8 -0
  58. package/admin/src/components/FiltersPicker/FiltersCard/index.js +97 -0
  59. package/admin/src/components/FiltersPicker/FiltersCard/init.js +21 -0
  60. package/admin/src/components/FiltersPicker/FiltersCard/reducer.js +47 -0
  61. package/admin/src/components/FiltersPicker/FiltersCard/utils/filtersForm.js +27 -0
  62. package/admin/src/components/FiltersPicker/index.js +43 -0
  63. package/admin/src/components/FiltersPicker/utils/formatFilter.js +18 -0
  64. package/admin/src/components/InfiniteLoadingIndicator/Button.js +20 -0
  65. package/admin/src/components/InfiniteLoadingIndicator/Container.js +12 -0
  66. package/admin/src/components/InfiniteLoadingIndicator/Wrapper.js +18 -0
  67. package/admin/src/components/InfiniteLoadingIndicator/index.js +39 -0
  68. package/admin/src/components/Input/index.js +7 -0
  69. package/admin/src/components/InputFileModal/Label.js +47 -0
  70. package/admin/src/components/InputFileModal/P.js +15 -0
  71. package/admin/src/components/InputFileModal/index.js +73 -0
  72. package/admin/src/components/InputMedia/CardControlWrapper.js +12 -0
  73. package/admin/src/components/InputMedia/CardPreviewWrapper.js +13 -0
  74. package/admin/src/components/InputMedia/Chevron/Wrapper.js +10 -0
  75. package/admin/src/components/InputMedia/Chevron/index.js +21 -0
  76. package/admin/src/components/InputMedia/EmptyInputMedia.js +60 -0
  77. package/admin/src/components/InputMedia/EmptyText.js +13 -0
  78. package/admin/src/components/InputMedia/ErrorMessage.js +12 -0
  79. package/admin/src/components/InputMedia/IconUpload.js +48 -0
  80. package/admin/src/components/InputMedia/InputFilePreview.js +37 -0
  81. package/admin/src/components/InputMedia/Name.js +10 -0
  82. package/admin/src/components/InputMedia/Wrapper.js +11 -0
  83. package/admin/src/components/InputMedia/index.js +238 -0
  84. package/admin/src/components/InputUploadURL/Wrapper.js +13 -0
  85. package/admin/src/components/InputUploadURL/index.js +46 -0
  86. package/admin/src/components/IntlText/index.js +26 -0
  87. package/admin/src/components/List/ListCell.js +19 -0
  88. package/admin/src/components/List/ListRow.js +8 -0
  89. package/admin/src/components/List/index.js +114 -0
  90. package/admin/src/components/ListEmpty/Wrapper.js +15 -0
  91. package/admin/src/components/ListEmpty/index.js +70 -0
  92. package/admin/src/components/ListEmpty/utils/generateRows.js +12 -0
  93. package/admin/src/components/ListModal/BaselineAlignmentWrapper.js +12 -0
  94. package/admin/src/components/ListModal/index.js +66 -0
  95. package/admin/src/components/ListWrapper/index.js +16 -0
  96. package/admin/src/components/LoadingIndicator/index.js +44 -0
  97. package/admin/src/components/ModalHeader/BackButton.js +33 -0
  98. package/admin/src/components/ModalHeader/Wrapper.js +24 -0
  99. package/admin/src/components/ModalHeader/index.js +47 -0
  100. package/admin/src/components/ModalNavWrapper/BaselineAlignment.js +12 -0
  101. package/admin/src/components/ModalNavWrapper/Hr.js +14 -0
  102. package/admin/src/components/ModalNavWrapper/Wrapper.js +8 -0
  103. package/admin/src/components/ModalNavWrapper/index.js +70 -0
  104. package/admin/src/components/ModalSection/index.js +20 -0
  105. package/admin/src/components/ModalTab/Count/Wrapper.js +16 -0
  106. package/admin/src/components/ModalTab/Count/index.js +30 -0
  107. package/admin/src/components/ModalTab/Wrapper.js +37 -0
  108. package/admin/src/components/ModalTab/index.js +60 -0
  109. package/admin/src/components/PlayIcon/Play.js +65 -0
  110. package/admin/src/components/PlayIcon/Wrapper.js +24 -0
  111. package/admin/src/components/PlayIcon/index.js +23 -0
  112. package/admin/src/components/SelectAll/Wrapper.js +19 -0
  113. package/admin/src/components/SelectAll/index.js +26 -0
  114. package/admin/src/components/SelectedAssets/DraggableCard.js +149 -0
  115. package/admin/src/components/SelectedAssets/ListTitleWrapper.js +7 -0
  116. package/admin/src/components/SelectedAssets/ListWrapper.js +7 -0
  117. package/admin/src/components/SelectedAssets/SortableList.js +102 -0
  118. package/admin/src/components/SelectedAssets/Wrapper.js +7 -0
  119. package/admin/src/components/SelectedAssets/index.js +56 -0
  120. package/admin/src/components/SortList/Wrapper.js +19 -0
  121. package/admin/src/components/SortList/index.js +37 -0
  122. package/admin/src/components/SortListItem/Wrapper.js +28 -0
  123. package/admin/src/components/SortListItem/index.js +35 -0
  124. package/admin/src/components/SortPicker/index.js +54 -0
  125. package/admin/src/components/Tag/Wrapper.js +16 -0
  126. package/admin/src/components/Tag/index.js +25 -0
  127. package/admin/src/components/UploadForm/index.js +61 -0
  128. package/admin/src/components/UploadList/ButtonWrapper.js +7 -0
  129. package/admin/src/components/UploadList/Container.js +10 -0
  130. package/admin/src/components/UploadList/CustomModalSection.js +9 -0
  131. package/admin/src/components/UploadList/ListTitle.js +10 -0
  132. package/admin/src/components/UploadList/ListTitleWrapper.js +7 -0
  133. package/admin/src/components/UploadList/RowItem.js +98 -0
  134. package/admin/src/components/UploadList/index.js +90 -0
  135. package/admin/src/components/VideoPlayer/Wrapper.js +24 -0
  136. package/admin/src/components/VideoPlayer/index.js +57 -0
  137. package/admin/src/components/VideoPreview/CanvasWrapper.js +22 -0
  138. package/admin/src/components/VideoPreview/Thumbnail.js +12 -0
  139. package/admin/src/components/VideoPreview/Wrapper.js +15 -0
  140. package/admin/src/components/VideoPreview/index.js +165 -0
  141. package/admin/src/components/VideoPreview/reducer.js +33 -0
  142. package/admin/src/containers/App/index.js +31 -0
  143. package/admin/src/containers/HomePage/HomePageContent/HomePageList.js +98 -0
  144. package/admin/src/containers/HomePage/HomePageContent/HomePageSettings.js +103 -0
  145. package/admin/src/containers/HomePage/HomePageContent/index.js +90 -0
  146. package/admin/src/containers/HomePage/components.js +18 -0
  147. package/admin/src/containers/HomePage/index.js +373 -0
  148. package/admin/src/containers/HomePage/init.js +5 -0
  149. package/admin/src/containers/HomePage/reducer.js +88 -0
  150. package/admin/src/containers/HomePage/utils/generateParamsFromQuery.js +14 -0
  151. package/admin/src/containers/HomePage/utils/generateStringFromParams.js +27 -0
  152. package/admin/src/containers/HomePage/utils/getHeaderLabel.js +13 -0
  153. package/admin/src/containers/HomePage/utils/index.js +2 -0
  154. package/admin/src/containers/Initializer/index.js +44 -0
  155. package/admin/src/containers/InputModalStepper/HeaderSearch.js +12 -0
  156. package/admin/src/containers/InputModalStepper/InputModalStepper.js +480 -0
  157. package/admin/src/containers/InputModalStepper/Search.js +48 -0
  158. package/admin/src/containers/InputModalStepper/index.js +86 -0
  159. package/admin/src/containers/InputModalStepper/stepper.js +52 -0
  160. package/admin/src/containers/InputModalStepperProvider/index.js +564 -0
  161. package/admin/src/containers/InputModalStepperProvider/init.js +5 -0
  162. package/admin/src/containers/InputModalStepperProvider/reducer.js +301 -0
  163. package/admin/src/containers/ModalStepper/index.js +629 -0
  164. package/admin/src/containers/ModalStepper/init.js +5 -0
  165. package/admin/src/containers/ModalStepper/reducer.js +132 -0
  166. package/admin/src/containers/ModalStepper/stepper.js +46 -0
  167. package/admin/src/containers/SettingsPage/Divider.js +11 -0
  168. package/admin/src/containers/SettingsPage/SectionTitleWrapper.js +7 -0
  169. package/admin/src/containers/SettingsPage/Wrapper.js +17 -0
  170. package/admin/src/containers/SettingsPage/index.js +198 -0
  171. package/admin/src/containers/SettingsPage/init.js +5 -0
  172. package/admin/src/containers/SettingsPage/reducer.js +38 -0
  173. package/admin/src/contexts/AppContext/index.js +5 -0
  174. package/admin/src/contexts/InputModal/InputModalDataManager.js +5 -0
  175. package/admin/src/contexts/index.js +2 -0
  176. package/admin/src/hooks/index.js +2 -0
  177. package/admin/src/hooks/useAppContext/index.js +6 -0
  178. package/admin/src/hooks/useModalContext.js +6 -0
  179. package/admin/src/icons/BrokenFile/index.js +91 -0
  180. package/admin/src/icons/Cloud/index.js +35 -0
  181. package/admin/src/icons/DoubleFile/index.js +35 -0
  182. package/admin/src/icons/Download/index.js +36 -0
  183. package/admin/src/icons/File/index.js +35 -0
  184. package/admin/src/index.js +85 -0
  185. package/admin/src/lifecycles.js +13 -0
  186. package/admin/src/permissions.js +40 -0
  187. package/admin/src/pluginId.js +5 -0
  188. package/admin/src/translations/de.json +81 -0
  189. package/admin/src/translations/dk.json +81 -0
  190. package/admin/src/translations/en.json +86 -0
  191. package/admin/src/translations/es.json +81 -0
  192. package/admin/src/translations/fr.json +85 -0
  193. package/admin/src/translations/he.json +81 -0
  194. package/admin/src/translations/index.js +39 -0
  195. package/admin/src/translations/it.json +82 -0
  196. package/admin/src/translations/ja.json +81 -0
  197. package/admin/src/translations/ms.json +73 -0
  198. package/admin/src/translations/pl.json +81 -0
  199. package/admin/src/translations/pt-BR.json +81 -0
  200. package/admin/src/translations/ru.json +81 -0
  201. package/admin/src/translations/sk.json +81 -0
  202. package/admin/src/translations/th.json +81 -0
  203. package/admin/src/translations/uk.json +78 -0
  204. package/admin/src/translations/zh-Hans.json +86 -0
  205. package/admin/src/translations/zh.json +81 -0
  206. package/admin/src/utils/ItemTypes.js +3 -0
  207. package/admin/src/utils/canDownloadFile.js +3 -0
  208. package/admin/src/utils/compactParams.js +13 -0
  209. package/admin/src/utils/createFileToDownloadName.js +9 -0
  210. package/admin/src/utils/createMatrix.js +32 -0
  211. package/admin/src/utils/createNewFilesToDownloadArray.js +57 -0
  212. package/admin/src/utils/createNewFilesToUploadArray.js +25 -0
  213. package/admin/src/utils/formatBytes.js +13 -0
  214. package/admin/src/utils/formatFileForEditing.js +20 -0
  215. package/admin/src/utils/formatFilters.js +23 -0
  216. package/admin/src/utils/generatePageFromStart.js +5 -0
  217. package/admin/src/utils/generateStartFromPage.js +5 -0
  218. package/admin/src/utils/getFileModelTimestamps.js +15 -0
  219. package/admin/src/utils/getFilesToDownload.js +5 -0
  220. package/admin/src/utils/getRequestUrl.js +5 -0
  221. package/admin/src/utils/getTrad.js +5 -0
  222. package/admin/src/utils/getType.js +15 -0
  223. package/admin/src/utils/getYupError.js +17 -0
  224. package/admin/src/utils/index.js +20 -0
  225. package/admin/src/utils/unformatBytes.js +16 -0
  226. package/admin/src/utils/urlYupSchema.js +49 -0
  227. package/config/config.json +8 -0
  228. package/config/functions/bootstrap.js +143 -0
  229. package/config/routes.json +98 -0
  230. package/config/schema.graphql.js +96 -0
  231. package/controllers/Upload.js +103 -0
  232. package/controllers/upload/admin.js +213 -0
  233. package/controllers/upload/api.js +125 -0
  234. package/controllers/validation/settings.js +22 -0
  235. package/controllers/validation/upload.js +27 -0
  236. package/documentation/1.0.0/overrides/upload-File.json +263 -0
  237. package/errors.js +48 -0
  238. package/index.js +7 -0
  239. package/middlewares/upload/defaults.json +5 -0
  240. package/middlewares/upload/index.js +35 -0
  241. package/models/File.js +7 -0
  242. package/models/File.settings.json +86 -0
  243. package/package.json +71 -0
  244. package/services/Upload.js +397 -0
  245. package/services/image-manipulation.js +167 -0
  246. package/utils/file.js +23 -0
@@ -0,0 +1,41 @@
1
+ import styled from 'styled-components';
2
+ import PropTypes from 'prop-types';
3
+ import { themePropTypes } from 'strapi-helper-plugin';
4
+
5
+ import CardImgWrapper from '../CardImgWrapper';
6
+
7
+ const FileWrapper = styled(CardImgWrapper)`
8
+ height: 401px;
9
+ width: 100%;
10
+ display: flex;
11
+ position: relative;
12
+ background-color: ${({ theme }) => theme.main.colors.black};
13
+ ${({ hasError, theme }) => hasError && `border: 2px solid ${theme.main.colors.orange};`}
14
+
15
+ .cropper-view-box {
16
+ outline-color: ${({ theme }) => theme.main.colors.white};
17
+ }
18
+ .cropper-point {
19
+ background-color: ${({ theme }) => theme.main.colors.white};
20
+ border-radius: 50%;
21
+ }
22
+
23
+ .point-se {
24
+ &:before {
25
+ display: none;
26
+ }
27
+ height: 5px;
28
+ width: 5px;
29
+ }
30
+ `;
31
+
32
+ FileWrapper.defaultProps = {
33
+ hasError: false,
34
+ };
35
+
36
+ FileWrapper.propTypes = {
37
+ hasError: PropTypes.bool,
38
+ ...themePropTypes,
39
+ };
40
+
41
+ export default FileWrapper;
@@ -0,0 +1,7 @@
1
+ import styled from 'styled-components';
2
+
3
+ const FormWrapper = styled.div`
4
+ margin-top: 19px;
5
+ `;
6
+
7
+ export default FormWrapper;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { Text } from '@buffetjs/core';
4
+
5
+ const SizeBox = styled(props => <Text {...props} fontSize="md" color="white" as="div" />)`
6
+ position: absolute;
7
+ bottom: 0;
8
+ right: 0;
9
+ background: #000000;
10
+ border-radius: ${({ theme }) => theme.main.sizes.borderRadius};
11
+ `;
12
+
13
+ export default SizeBox;
@@ -0,0 +1,8 @@
1
+ import styled from 'styled-components';
2
+ import ContainerFluid from '../ContainerFluid';
3
+
4
+ const Wrapper = styled(ContainerFluid)`
5
+ padding-top: 18px;
6
+ `;
7
+
8
+ export default Wrapper;
@@ -0,0 +1,425 @@
1
+ /* eslint-disable jsx-a11y/anchor-is-valid */
2
+ /* eslint-disable react/jsx-fragments */
3
+ import React, {
4
+ Fragment,
5
+ forwardRef,
6
+ useState,
7
+ useEffect,
8
+ useRef,
9
+ useImperativeHandle,
10
+ } from 'react';
11
+ import { CopyToClipboard } from 'react-copy-to-clipboard';
12
+ import axios from 'axios';
13
+ import { get } from 'lodash';
14
+ import PropTypes from 'prop-types';
15
+ import { Row } from 'reactstrap';
16
+ import { Inputs } from '@buffetjs/custom';
17
+ import { useGlobalContext, prefixFileUrlWithBackendUrl } from 'strapi-helper-plugin';
18
+ import Cropper from 'cropperjs';
19
+ import 'cropperjs/dist/cropper.css';
20
+ import { createFileToDownloadName } from '../../utils';
21
+ import CardControl from '../CardControl';
22
+ import CardControlsWrapper from '../CardControlsWrapper';
23
+ import CardPreview from '../CardPreview';
24
+ import InfiniteLoadingIndicator from '../InfiniteLoadingIndicator';
25
+ import ModalSection from '../ModalSection';
26
+ import VideoPlayer from '../VideoPlayer';
27
+ import CropWrapper from './CropWrapper';
28
+ import FileDetailsBox from './FileDetailsBox';
29
+ import FileWrapper from './FileWrapper';
30
+ import FormWrapper from './FormWrapper';
31
+ import SizeBox from './SizeBox';
32
+ import Wrapper from './Wrapper';
33
+ import ErrorMessage from './ErrorMessage';
34
+ import form from './utils/form';
35
+ import isImageType from './utils/isImageType';
36
+ import isVideoType from './utils/isVideoType';
37
+
38
+ const EditForm = forwardRef(
39
+ (
40
+ {
41
+ canCopyLink,
42
+ canDownload,
43
+ components,
44
+ fileToEdit,
45
+ isEditingUploadedFile,
46
+ isFormDisabled,
47
+ onAbortUpload,
48
+ onChange,
49
+ onClickDeleteFileToUpload,
50
+ onSubmitEdit,
51
+ setCropResult,
52
+ toggleDisableForm,
53
+ },
54
+ ref
55
+ ) => {
56
+ const { formatMessage } = useGlobalContext();
57
+ const [isCropping, setIsCropping] = useState(false);
58
+ const [infos, setInfos] = useState({ width: null, height: null });
59
+ const [src, setSrc] = useState(null);
60
+ const cacheRef = useRef(performance.now());
61
+
62
+ const fileURL = get(fileToEdit, ['file', 'url'], null);
63
+ const prefixedFileURL = fileURL
64
+ ? prefixFileUrlWithBackendUrl(`${fileURL}?${cacheRef.current}`)
65
+ : null;
66
+ const downloadFileName = createFileToDownloadName(fileToEdit);
67
+ const mimeType =
68
+ get(fileToEdit, ['file', 'type'], null) || get(fileToEdit, ['file', 'mime'], '');
69
+ const isImg = isImageType(mimeType);
70
+ const isVideo = isVideoType(mimeType);
71
+ const canCrop = isImg && !mimeType.includes('svg') && !mimeType.includes('gif');
72
+ const aRef = useRef();
73
+ const imgRef = useRef();
74
+ const inputRef = useRef();
75
+ const cropper = useRef();
76
+
77
+ useImperativeHandle(ref, () => ({
78
+ click: () => {
79
+ inputRef.current.click();
80
+ setIsCropping(false);
81
+ },
82
+ }));
83
+
84
+ useEffect(() => {
85
+ if (isImg || isVideo) {
86
+ if (prefixedFileURL) {
87
+ setSrc(prefixedFileURL);
88
+ } else {
89
+ setSrc(URL.createObjectURL(fileToEdit.file));
90
+ }
91
+ }
92
+ }, [isImg, isVideo, fileToEdit, prefixedFileURL]);
93
+
94
+ useEffect(() => {
95
+ if (isCropping) {
96
+ cropper.current = new Cropper(imgRef.current, {
97
+ modal: true,
98
+ initialAspectRatio: 16 / 9,
99
+ movable: true,
100
+ zoomable: false,
101
+ cropBoxResizable: true,
102
+ background: false,
103
+ crop: handleResize,
104
+ });
105
+ } else if (cropper.current) {
106
+ cropper.current.destroy();
107
+
108
+ setInfos({ width: null, height: null });
109
+ toggleDisableForm(false);
110
+ }
111
+
112
+ return () => {
113
+ if (cropper.current) {
114
+ cropper.current.destroy();
115
+ }
116
+ };
117
+ // eslint-disable-next-line react-hooks/exhaustive-deps
118
+ }, [cropper, isCropping]);
119
+
120
+ const handleResize = ({ detail: { height, width } }) => {
121
+ const roundedDataHeight = Math.round(height);
122
+ const roundedDataWidth = Math.round(width);
123
+
124
+ setInfos({ width: roundedDataWidth, height: roundedDataHeight });
125
+ };
126
+
127
+ const handleToggleCropMode = () => {
128
+ setIsCropping(prev => {
129
+ if (!prev && isEditingUploadedFile) {
130
+ toggleDisableForm(true);
131
+ }
132
+
133
+ return !prev;
134
+ });
135
+ };
136
+
137
+ const handleChange = ({ target: { files } }) => {
138
+ if (files[0]) {
139
+ onChange({ target: { name: 'file', value: files[0] } });
140
+ }
141
+ };
142
+
143
+ const handleClick = async () => {
144
+ const cropResult = await getCroppedResult();
145
+
146
+ setCropResult(cropResult);
147
+
148
+ setIsCropping(false);
149
+ };
150
+
151
+ const getCroppedResult = () => {
152
+ return new Promise((resolve, reject) => {
153
+ try {
154
+ const canvas = cropper.current.getCroppedCanvas();
155
+
156
+ canvas.toBlob(
157
+ async blob => {
158
+ const {
159
+ file: { lastModifiedDate, lastModified, name },
160
+ } = fileToEdit;
161
+
162
+ resolve(
163
+ new File([blob], name, {
164
+ type: mimeType,
165
+ lastModified,
166
+ lastModifiedDate,
167
+ })
168
+ );
169
+ },
170
+ mimeType,
171
+ 1
172
+ );
173
+ } catch (err) {
174
+ reject();
175
+ }
176
+ });
177
+ };
178
+
179
+ const handleClickEditCroppedFile = async (e, shouldDuplicate = false) => {
180
+ try {
181
+ const file = await getCroppedResult();
182
+
183
+ onSubmitEdit(e, shouldDuplicate, file, true);
184
+ } catch (err) {
185
+ // Silent
186
+ } finally {
187
+ setIsCropping(false);
188
+ }
189
+ };
190
+
191
+ const handleClickDelete = () => {
192
+ onClickDeleteFileToUpload(fileToEdit.originalIndex);
193
+ };
194
+
195
+ const handleCopy = () => {
196
+ strapi.notification.toggle({
197
+ type: 'info',
198
+ message: { id: 'notification.link-copied' },
199
+ });
200
+ };
201
+
202
+ const handleClickDownload = () => {
203
+ axios
204
+ .get(prefixFileUrlWithBackendUrl(fileURL), {
205
+ responseType: 'blob',
206
+ })
207
+ .then(({ data }) => {
208
+ const blobUrl = URL.createObjectURL(data);
209
+
210
+ aRef.current.download = downloadFileName;
211
+ aRef.current.href = blobUrl;
212
+
213
+ aRef.current.click();
214
+ })
215
+ .catch(err => {
216
+ console.error(err);
217
+ });
218
+ };
219
+
220
+ const handleSubmit = e => {
221
+ e.preventDefault();
222
+
223
+ onSubmitEdit(e);
224
+ };
225
+
226
+ const CheckButton = components.CheckControl;
227
+
228
+ return (
229
+ <form onSubmit={handleSubmit}>
230
+ <ModalSection>
231
+ <Wrapper>
232
+ <div className="row">
233
+ <div className="col-6">
234
+ <FileWrapper hasError={fileToEdit.hasError}>
235
+ {fileToEdit.isUploading ? (
236
+ <InfiniteLoadingIndicator onClick={onAbortUpload} />
237
+ ) : (
238
+ <Fragment>
239
+ <CardControlsWrapper className="card-control-wrapper-displayed">
240
+ {!isCropping ? (
241
+ <>
242
+ <CardControl
243
+ color="#9EA7B8"
244
+ type="trash-alt"
245
+ onClick={handleClickDelete}
246
+ title="delete"
247
+ />
248
+ {fileURL && (
249
+ <>
250
+ {canDownload && (
251
+ <CardControl
252
+ color="#9EA7B8"
253
+ onClick={handleClickDownload}
254
+ type="download"
255
+ title="download"
256
+ />
257
+ )}
258
+ <a
259
+ title={fileToEdit.fileInfo.name}
260
+ style={{ display: 'none' }}
261
+ ref={aRef}
262
+ >
263
+ hidden
264
+ </a>
265
+ {canCopyLink && (
266
+ <CopyToClipboard
267
+ onCopy={handleCopy}
268
+ text={prefixFileUrlWithBackendUrl(fileURL)}
269
+ >
270
+ <CardControl color="#9EA7B8" type="link" title="copy-link" />
271
+ </CopyToClipboard>
272
+ )}
273
+ </>
274
+ )}
275
+ {canCrop && (
276
+ <CardControl
277
+ color="#9EA7B8"
278
+ onClick={handleToggleCropMode}
279
+ type="crop"
280
+ title="crop"
281
+ />
282
+ )}
283
+ </>
284
+ ) : (
285
+ <>
286
+ <CardControl
287
+ color="#F64D0A"
288
+ onClick={handleToggleCropMode}
289
+ type="times"
290
+ title="cancel"
291
+ iconStyle={{ height: '1.6rem', width: '1.6rem' }}
292
+ />
293
+ <CheckButton
294
+ color="#6DBB1A"
295
+ onClick={handleClick}
296
+ onSubmitEdit={handleClickEditCroppedFile}
297
+ type="check"
298
+ title="save"
299
+ />
300
+ </>
301
+ )}
302
+ </CardControlsWrapper>
303
+ {isImg ? (
304
+ <CropWrapper>
305
+ <img
306
+ src={src}
307
+ alt={get(fileToEdit, ['file', 'name'], '')}
308
+ ref={isCropping ? imgRef : null}
309
+ />
310
+ </CropWrapper>
311
+ ) : (
312
+ <>
313
+ {isVideo ? (
314
+ <VideoPlayer src={src} />
315
+ ) : (
316
+ <CardPreview type={mimeType} url={src} />
317
+ )}
318
+ </>
319
+ )}
320
+
321
+ {isCropping && infos.width !== null && (
322
+ <SizeBox>
323
+ &nbsp;
324
+ {infos.width} x {infos.height}
325
+ &nbsp;
326
+ </SizeBox>
327
+ )}
328
+ </Fragment>
329
+ )}
330
+ </FileWrapper>
331
+ {fileToEdit.hasError && (
332
+ <ErrorMessage title={fileToEdit.errorMessage}>
333
+ {fileToEdit.errorMessage}
334
+ </ErrorMessage>
335
+ )}
336
+ </div>
337
+ <div className="col-6">
338
+ <FileDetailsBox file={fileToEdit.file} />
339
+ <FormWrapper>
340
+ {form.map(({ key, inputs }) => {
341
+ return (
342
+ <Row key={key}>
343
+ {inputs.map(input => {
344
+ return (
345
+ <div className="col-12" key={input.name}>
346
+ <Inputs
347
+ {...input}
348
+ disabled={isFormDisabled}
349
+ description={
350
+ input.description ? formatMessage(input.description) : null
351
+ }
352
+ label={formatMessage(input.label)}
353
+ onChange={onChange}
354
+ type="text"
355
+ value={get(fileToEdit, input.name, '')}
356
+ />
357
+ </div>
358
+ );
359
+ })}
360
+ </Row>
361
+ );
362
+ })}
363
+ </FormWrapper>
364
+ </div>
365
+ </div>
366
+ </Wrapper>
367
+ <input
368
+ ref={inputRef}
369
+ type="file"
370
+ multiple={false}
371
+ onChange={handleChange}
372
+ style={{ display: 'none' }}
373
+ accept={mimeType
374
+ .split('/')
375
+ .map((v, i) => {
376
+ if (i === 1) {
377
+ return '*';
378
+ }
379
+
380
+ return v;
381
+ })
382
+ .join('/')}
383
+ />
384
+ <button type="submit" style={{ display: 'none' }}>
385
+ hidden button to make to get the native form event
386
+ </button>
387
+ </ModalSection>
388
+ </form>
389
+ );
390
+ }
391
+ );
392
+
393
+ EditForm.defaultProps = {
394
+ canCopyLink: true,
395
+ canDownload: true,
396
+ components: {
397
+ CheckControl: CardControl,
398
+ },
399
+ fileToEdit: null,
400
+ isEditingUploadedFile: false,
401
+ isFormDisabled: false,
402
+ onAbortUpload: () => {},
403
+ onChange: () => {},
404
+ onClickDeleteFileToUpload: () => {},
405
+ onSubmitEdit: e => e.preventDefault(),
406
+ setCropResult: () => {},
407
+ toggleDisableForm: () => {},
408
+ };
409
+
410
+ EditForm.propTypes = {
411
+ canCopyLink: PropTypes.bool,
412
+ canDownload: PropTypes.bool,
413
+ onAbortUpload: PropTypes.func,
414
+ components: PropTypes.object,
415
+ fileToEdit: PropTypes.object,
416
+ isEditingUploadedFile: PropTypes.bool,
417
+ isFormDisabled: PropTypes.bool,
418
+ onChange: PropTypes.func,
419
+ onClickDeleteFileToUpload: PropTypes.func,
420
+ onSubmitEdit: PropTypes.func,
421
+ setCropResult: PropTypes.func,
422
+ toggleDisableForm: PropTypes.func,
423
+ };
424
+
425
+ export default EditForm;
@@ -0,0 +1,34 @@
1
+ import { getTrad } from '../../../utils';
2
+
3
+ const form = [
4
+ {
5
+ key: 1,
6
+ inputs: [
7
+ {
8
+ label: { id: getTrad('form.input.label.file-name') },
9
+ name: 'fileInfo.name',
10
+ },
11
+ ],
12
+ },
13
+ {
14
+ key: 2,
15
+ inputs: [
16
+ {
17
+ description: { id: getTrad('form.input.description.file-alt') },
18
+ label: { id: getTrad('form.input.label.file-alt') },
19
+ name: 'fileInfo.alternativeText',
20
+ },
21
+ ],
22
+ },
23
+ {
24
+ key: 3,
25
+ inputs: [
26
+ {
27
+ label: { id: getTrad('form.input.label.file-caption') },
28
+ name: 'fileInfo.caption',
29
+ },
30
+ ],
31
+ },
32
+ ];
33
+
34
+ export default form;
@@ -0,0 +1,3 @@
1
+ const isImageType = mimeType => mimeType.includes('image');
2
+
3
+ export default isImageType;
@@ -0,0 +1,3 @@
1
+ const isVideoType = mimeType => mimeType.includes('video');
2
+
3
+ export default isVideoType;
@@ -0,0 +1,20 @@
1
+ import styled from 'styled-components';
2
+ import PropTypes from 'prop-types';
3
+ import { themePropTypes } from 'strapi-helper-plugin';
4
+
5
+ const Wrapper = styled.div`
6
+ font-size: 54px;
7
+ color: ${({ theme, colored }) =>
8
+ colored ? theme.main.colors.lightOrange : theme.main.colors.grey};
9
+ `;
10
+
11
+ Wrapper.defaultProps = {
12
+ colored: false,
13
+ };
14
+
15
+ Wrapper.propTypes = {
16
+ colored: PropTypes.bool,
17
+ ...themePropTypes,
18
+ };
19
+
20
+ export default Wrapper;
@@ -0,0 +1,33 @@
1
+ /**
2
+ *
3
+ *
4
+ * FileIcon
5
+ */
6
+
7
+ import React from 'react';
8
+ import PropTypes from 'prop-types';
9
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
10
+
11
+ import extensions from './utils/extensions.json';
12
+
13
+ import Wrapper from './Wrapper';
14
+
15
+ const FileIcon = ({ ext }) => {
16
+ const iconName = Object.keys(extensions).find(key => extensions[key].includes(ext)) || 'alt';
17
+
18
+ return (
19
+ <Wrapper type="file" colored={iconName === 'pdf'}>
20
+ <FontAwesomeIcon icon={['far', `file-${iconName}`]} />
21
+ </Wrapper>
22
+ );
23
+ };
24
+
25
+ FileIcon.defaultProps = {
26
+ ext: 'alt',
27
+ };
28
+
29
+ FileIcon.propTypes = {
30
+ ext: PropTypes.string,
31
+ };
32
+
33
+ export default FileIcon;
@@ -0,0 +1,4 @@
1
+ {
2
+ "archive": ["rar", "tar", "zip"],
3
+ "pdf": ["pdf"]
4
+ }
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { upperCase } from 'lodash';
4
+
5
+ import { Text } from '@buffetjs/core';
6
+
7
+ const FileInfos = ({ extension, height, size, width }) => {
8
+ return (
9
+ <Text color="grey" fontSize="xs" ellipsis>
10
+ {upperCase(extension)}
11
+ &nbsp;&mdash;&nbsp;
12
+ {width && height && `${width}×${height}\u00A0\u2014\u00A0`}
13
+ {size}
14
+ </Text>
15
+ );
16
+ };
17
+
18
+ FileInfos.defaultProps = {
19
+ height: null,
20
+ extension: null,
21
+ width: null,
22
+ size: null,
23
+ };
24
+
25
+ FileInfos.propTypes = {
26
+ height: PropTypes.number,
27
+ extension: PropTypes.string,
28
+ size: PropTypes.string,
29
+ width: PropTypes.number,
30
+ };
31
+
32
+ export default FileInfos;
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Padded } from '@buffetjs/core';
4
+
5
+ import FiltersList from '../FiltersList';
6
+ import FiltersPicker from '../FiltersPicker';
7
+
8
+ const Filters = ({ onChange, onClick, filters }) => {
9
+ return (
10
+ <>
11
+ <FiltersPicker onChange={onChange} />
12
+ <Padded left size="sm" />
13
+ <FiltersList filters={filters} onClick={onClick} />
14
+ </>
15
+ );
16
+ };
17
+
18
+ Filters.defaultProps = {
19
+ filters: [],
20
+ onChange: () => {},
21
+ onClick: () => {},
22
+ };
23
+
24
+ Filters.propTypes = {
25
+ filters: PropTypes.arrayOf(PropTypes.object),
26
+ onChange: PropTypes.func,
27
+ onClick: PropTypes.func,
28
+ };
29
+
30
+ export default Filters;