@bigbinary/neeto-image-uploader-frontend 4.0.3 → 4.0.5

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 (101) hide show
  1. package/dist/.ready +1 -1
  2. package/dist/AssetLibrary.js +12 -9
  3. package/dist/AssetLibrary.js.map +1 -1
  4. package/dist/BasicImageUploader.js +4 -2
  5. package/dist/BasicImageUploader.js.map +1 -1
  6. package/dist/ImageForm.js +7 -4
  7. package/dist/ImageForm.js.map +1 -1
  8. package/dist/ImageUploader.js +9 -6
  9. package/dist/ImageUploader.js.map +1 -1
  10. package/dist/ImageWithFallback-BhUgmP7t.js +61 -0
  11. package/dist/ImageWithFallback-BhUgmP7t.js.map +1 -0
  12. package/dist/{ImageWithFallback-Bq5rs1yf.js → ImageWithFallback-D1ClfJLn.js} +4 -4
  13. package/dist/{ImageWithFallback-Bq5rs1yf.js.map → ImageWithFallback-D1ClfJLn.js.map} +1 -1
  14. package/dist/ImageWithFallback-MfA03icL.js +59 -0
  15. package/dist/ImageWithFallback-MfA03icL.js.map +1 -0
  16. package/dist/cjs/AssetLibrary.js +10 -7
  17. package/dist/cjs/AssetLibrary.js.map +1 -1
  18. package/dist/cjs/BasicImageUploader.js +5 -3
  19. package/dist/cjs/BasicImageUploader.js.map +1 -1
  20. package/dist/cjs/ImageForm.js +9 -6
  21. package/dist/cjs/ImageForm.js.map +1 -1
  22. package/dist/cjs/ImageUploader.js +14 -11
  23. package/dist/cjs/ImageUploader.js.map +1 -1
  24. package/dist/cjs/hooks.js +1 -1
  25. package/dist/cjs/index.js +9 -6
  26. package/dist/cjs/index.js.map +1 -1
  27. package/dist/cjs/v2/AssetLibrary.js +40 -0
  28. package/dist/cjs/v2/AssetLibrary.js.map +1 -0
  29. package/dist/cjs/v2/BasicImageUploader.js +71 -0
  30. package/dist/cjs/v2/BasicImageUploader.js.map +1 -0
  31. package/dist/cjs/v2/ImageForm.js +324 -0
  32. package/dist/cjs/v2/ImageForm.js.map +1 -0
  33. package/dist/cjs/v2/ImageUploader.js +246 -0
  34. package/dist/cjs/v2/ImageUploader.js.map +1 -0
  35. package/dist/cjs/v2/hooks.js +27 -0
  36. package/dist/cjs/v2/hooks.js.map +1 -0
  37. package/dist/cjs/v2/index.js +61 -0
  38. package/dist/cjs/v2/index.js.map +1 -0
  39. package/dist/cjs/v2/utils.js +9 -0
  40. package/dist/cjs/v2/utils.js.map +1 -0
  41. package/dist/constants-Csle2bxb.js +56 -0
  42. package/dist/constants-Csle2bxb.js.map +1 -0
  43. package/dist/constants-DI8wBtC-.js +68 -0
  44. package/dist/constants-DI8wBtC-.js.map +1 -0
  45. package/dist/hooks.js +3 -3
  46. package/dist/{imagekit.esm-CXW6c1fP.js → imagekit.esm-IYQEzBnD.js} +2 -2
  47. package/dist/{imagekit.esm-CXW6c1fP.js.map → imagekit.esm-IYQEzBnD.js.map} +1 -1
  48. package/dist/index-CBorETxd.js +972 -0
  49. package/dist/index-CBorETxd.js.map +1 -0
  50. package/dist/index-CiB5LGGR.js +950 -0
  51. package/dist/index-CiB5LGGR.js.map +1 -0
  52. package/dist/index-EgJf9LfL.js +947 -0
  53. package/dist/index-EgJf9LfL.js.map +1 -0
  54. package/dist/index-krkZ4CNS.js +969 -0
  55. package/dist/index-krkZ4CNS.js.map +1 -0
  56. package/dist/index.js +10 -7
  57. package/dist/index.js.map +1 -1
  58. package/dist/{useImageUploader-BLOdyAwv.js → useImageUploader-D8luC4Qw.js} +2 -2
  59. package/dist/{useImageUploader-BLOdyAwv.js.map → useImageUploader-D8luC4Qw.js.map} +1 -1
  60. package/dist/{useProfileImageUpload-CiGxDpEx.js → useProfileImageUpload-CbjVfcfI.js} +3 -3
  61. package/dist/{useProfileImageUpload-CiGxDpEx.js.map → useProfileImageUpload-CbjVfcfI.js.map} +1 -1
  62. package/dist/{useProfileImageUpload-DkmUBjtt.js → useProfileImageUpload-DbanXK57.js} +6 -6
  63. package/dist/useProfileImageUpload-DbanXK57.js.map +1 -0
  64. package/dist/useUnsplashApi-CNeNh58q.js +1065 -0
  65. package/dist/useUnsplashApi-CNeNh58q.js.map +1 -0
  66. package/dist/useUnsplashApi-D_ekWD8p.js +1057 -0
  67. package/dist/useUnsplashApi-D_ekWD8p.js.map +1 -0
  68. package/dist/useUploadDropzone-8Xa8PI-1.js +56 -0
  69. package/dist/useUploadDropzone-8Xa8PI-1.js.map +1 -0
  70. package/dist/useUploadDropzone-DMv8VMRF.js +58 -0
  71. package/dist/useUploadDropzone-DMv8VMRF.js.map +1 -0
  72. package/dist/utils-BTmA9hHb.js +364 -0
  73. package/dist/utils-BTmA9hHb.js.map +1 -0
  74. package/dist/{utils-BYMSmzRM.js → utils-CbaXwRPJ.js} +33 -74
  75. package/dist/utils-CbaXwRPJ.js.map +1 -0
  76. package/dist/{utils-C0TymZ5r.js → utils-DwOJkJSn.js} +41 -83
  77. package/dist/utils-DwOJkJSn.js.map +1 -0
  78. package/dist/utils-DyCNC3w5.js +347 -0
  79. package/dist/utils-DyCNC3w5.js.map +1 -0
  80. package/dist/v2/AssetLibrary.js +34 -0
  81. package/dist/v2/AssetLibrary.js.map +1 -0
  82. package/dist/v2/BasicImageUploader.js +69 -0
  83. package/dist/v2/BasicImageUploader.js.map +1 -0
  84. package/dist/v2/ImageForm.js +322 -0
  85. package/dist/v2/ImageForm.js.map +1 -0
  86. package/dist/v2/ImageUploader.js +244 -0
  87. package/dist/v2/ImageUploader.js.map +1 -0
  88. package/dist/v2/hooks.js +19 -0
  89. package/dist/v2/hooks.js.map +1 -0
  90. package/dist/v2/index.js +48 -0
  91. package/dist/v2/index.js.map +1 -0
  92. package/dist/v2/utils.js +3 -0
  93. package/dist/v2/utils.js.map +1 -0
  94. package/package.json +49 -37
  95. package/dist/index-BuYEdyOT.js +0 -2413
  96. package/dist/index-BuYEdyOT.js.map +0 -1
  97. package/dist/index-Dpyvz0h1.js +0 -2410
  98. package/dist/index-Dpyvz0h1.js.map +0 -1
  99. package/dist/useProfileImageUpload-DkmUBjtt.js.map +0 -1
  100. package/dist/utils-BYMSmzRM.js.map +0 -1
  101. package/dist/utils-C0TymZ5r.js.map +0 -1
@@ -0,0 +1,969 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
+ import { useState, useRef, useCallback, createElement, useEffect } from 'react';
4
+ import { isPresent, noop } from '@bigbinary/neeto-cist';
5
+ import { globalProps } from '@bigbinary/neeto-commons-frontend/initializers';
6
+ import NeetoUIModal from '@bigbinary/neetoui/Modal';
7
+ import Tab from '@bigbinary/neetoui/Tab';
8
+ import Spinner from '@bigbinary/neetoui/Spinner';
9
+ import Toastr from '@bigbinary/neetoui/Toastr';
10
+ import Typography from '@bigbinary/neetoui/Typography';
11
+ import { mergeRight, isEmpty, equals } from 'ramda';
12
+ import { useTranslation, Trans } from 'react-i18next';
13
+ import { a as isNilOrEmpty, g as getAspectRatio, b as getPixels, c as getHeightFromAspectRatio, d as getWidthFromAspectRatio, e as getInitialCropSize, f as getPercentage, h as getWrapperRefStyles, j as isItemsCenter, k as getCloudFlareCroppedURL, l as getImageKitCroppedURL, m as getCropValues, D as DEFAULT_UPLOAD_CONFIG, I as ImageDirectUpload } from './utils-DyCNC3w5.js';
14
+ import { u as useImageUploader, a as useCreateBlob, i as isGif, g as generateASCIIFileName } from './useImageUploader-D8luC4Qw.js';
15
+ import { u as useUploadDropzone } from './useUploadDropzone-8Xa8PI-1.js';
16
+ import { I as IS_DEVELOPMENT_OR_HEROKU_ENV, C as CLOUD_FLARE } from './imagekit.esm-IYQEzBnD.js';
17
+ import { R as ReactCrop_minExports, u as useCropImage, a as ReactCrop, b as useBulkDestroyAssets, _ as _default, c as useFetchAssets, d as useFetchUnsplashImages, e as unsplashApi } from './useUnsplashApi-D_ekWD8p.js';
18
+ import { D as DEFAULT_CROP_CONFIG, a as INFINITE_SCROLLER_STYLE, b as INFINITE_SCROLLER_SIZES, T as TABS, A as ASSETS_DESTROY_URL, c as IMAGES_PER_PAGE, d as ASSETS_FETCH_URL, U as UNSPLASH_DEFAULT_NAME, e as UNSPLASH_DEFAULT_REQUEST_CONFIG, f as UNSPLASH_URL } from './constants-Csle2bxb.js';
19
+ import classnames from 'classnames';
20
+ import LeftArrow from '@bigbinary/neeto-icons/LeftArrow';
21
+ import Button from '@bigbinary/neetoui/Button';
22
+ import { withT, useFuncDebounce, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
23
+ import { withEventTargetValue, hasPermission } from '@bigbinary/neeto-commons-frontend/utils';
24
+ import Input from '@bigbinary/neetoui/Input';
25
+ import Switch from '@bigbinary/neetoui/Switch';
26
+ import Label from '@bigbinary/neetoui/Label';
27
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
28
+ import NoData from '@bigbinary/neetoui/NoData';
29
+ import MenuHorizontal from '@bigbinary/neeto-icons/MenuHorizontal';
30
+ import { VIEW_ROLES_PERMISSION } from '@bigbinary/neeto-team-members-frontend/constants';
31
+ import Alert from '@bigbinary/neetoui/Alert';
32
+ import Dropdown from '@bigbinary/neetoui/Dropdown';
33
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
34
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
35
+
36
+ var constructCloudflareImageURL = function constructCloudflareImageURL(url) {
37
+ var domain = window.location.host.split(".").slice(-2).join(".");
38
+ return url.replace("https://imagedelivery.net", "https://images.".concat(domain, "/cdn-cgi/imagedelivery"));
39
+ };
40
+
41
+ var Controls = withT(function (_ref) {
42
+ var _imageRef$current, _imageRef$current2;
43
+ var t = _ref.t,
44
+ crop = _ref.crop,
45
+ handleSubmit = _ref.handleSubmit,
46
+ imageRef = _ref.imageRef,
47
+ isFullImage = _ref.isFullImage,
48
+ setIsFullImage = _ref.setIsFullImage,
49
+ _ref$hideControls = _ref.hideControls,
50
+ hideControls = _ref$hideControls === void 0 ? false : _ref$hideControls,
51
+ handleWidthChange = _ref.handleWidthChange,
52
+ handleHeightChange = _ref.handleHeightChange,
53
+ width = _ref.width,
54
+ height = _ref.height;
55
+ return /*#__PURE__*/jsxs("div", {
56
+ className: "flex flex-col space-y-6 p-4 md:w-2/6",
57
+ children: [!hideControls && /*#__PURE__*/jsx(Switch, {
58
+ checked: isFullImage,
59
+ className: "w-full",
60
+ label: t("neetoImageUploader.labels.selectOriginalImage"),
61
+ onChange: function onChange() {
62
+ return setIsFullImage(function (isFullImage) {
63
+ return !isFullImage;
64
+ });
65
+ }
66
+ }), /*#__PURE__*/jsxs("div", {
67
+ className: "flex w-full items-start gap-2",
68
+ children: [/*#__PURE__*/jsx(Label, {
69
+ className: "w-24 pt-2",
70
+ children: t("neetoImageUploader.labels.width")
71
+ }), /*#__PURE__*/jsx(Input, {
72
+ className: "w-32 grow-0",
73
+ disabled: isFullImage,
74
+ max: (_imageRef$current = imageRef.current) === null || _imageRef$current === void 0 ? void 0 : _imageRef$current.naturalWidth,
75
+ type: "number",
76
+ value: width,
77
+ onChange: withEventTargetValue(handleWidthChange)
78
+ })]
79
+ }), /*#__PURE__*/jsxs("div", {
80
+ className: "flex w-full items-start gap-2",
81
+ children: [/*#__PURE__*/jsx(Label, {
82
+ className: "w-24 pt-2",
83
+ children: t("neetoImageUploader.labels.height")
84
+ }), /*#__PURE__*/jsx(Input, {
85
+ className: "w-32 grow-0",
86
+ disabled: isFullImage,
87
+ max: (_imageRef$current2 = imageRef.current) === null || _imageRef$current2 === void 0 ? void 0 : _imageRef$current2.naturalHeight,
88
+ type: "number",
89
+ value: height,
90
+ onChange: withEventTargetValue(handleHeightChange)
91
+ })]
92
+ }), /*#__PURE__*/jsx(Button, {
93
+ className: "mt-6 self-start",
94
+ "data-testid": "neeto-image-uploader-crop-submit-button",
95
+ label: t("neetoImageUploader.labels.done"),
96
+ disabled: isNilOrEmpty(imageRef.current) && (crop.width <= 0 || crop.height <= 0),
97
+ onClick: handleSubmit
98
+ })]
99
+ });
100
+ });
101
+
102
+ var useImageControls = function useImageControls(_ref) {
103
+ var _imageRef$current;
104
+ var imageRef = _ref.imageRef,
105
+ fixedAspectRatio = _ref.fixedAspectRatio,
106
+ defaultImageSize = _ref.defaultImageSize;
107
+ var _ref2 = (_imageRef$current = imageRef.current) !== null && _imageRef$current !== void 0 ? _imageRef$current : {},
108
+ imageWidth = _ref2.naturalWidth,
109
+ imageHeight = _ref2.naturalHeight;
110
+ var _useState = useState(isPresent(fixedAspectRatio)),
111
+ _useState2 = _slicedToArray(_useState, 2),
112
+ isAspectRatioLocked = _useState2[0],
113
+ setIsAspectRatioLocked = _useState2[1];
114
+ var _useState3 = useState(DEFAULT_CROP_CONFIG),
115
+ _useState4 = _slicedToArray(_useState3, 2),
116
+ crop = _useState4[0],
117
+ setCrop = _useState4[1];
118
+ var _useState5 = useState(getAspectRatio({
119
+ fixedAspectRatio: fixedAspectRatio,
120
+ imageSize: defaultImageSize
121
+ })),
122
+ _useState6 = _slicedToArray(_useState5, 2),
123
+ aspectRatio = _useState6[0],
124
+ setAspectRatio = _useState6[1];
125
+ var _useState7 = useState(getPixels(crop.height, imageHeight)),
126
+ _useState8 = _slicedToArray(_useState7, 2),
127
+ height = _useState8[0],
128
+ setHeight = _useState8[1];
129
+ var _useState9 = useState(getPixels(crop.width, imageWidth)),
130
+ _useState10 = _slicedToArray(_useState9, 2),
131
+ width = _useState10[0],
132
+ setWidth = _useState10[1];
133
+ var aspectRatioFactor = aspectRatio.width / aspectRatio.height;
134
+ var buildCropValues = function buildCropValues(_ref3) {
135
+ var cropWidth = _ref3.cropWidth,
136
+ cropHeight = _ref3.cropHeight,
137
+ _ref3$width = _ref3.width,
138
+ width = _ref3$width === void 0 ? imageWidth : _ref3$width,
139
+ _ref3$height = _ref3.height,
140
+ height = _ref3$height === void 0 ? imageHeight : _ref3$height,
141
+ _ref3$aspectRatio = _ref3.aspectRatio,
142
+ aspectRatio = _ref3$aspectRatio === void 0 ? aspectRatioFactor : _ref3$aspectRatio;
143
+ var aspectCrop = ReactCrop_minExports.makeAspectCrop({
144
+ unit: "%",
145
+ width: getPercentage(cropWidth, width),
146
+ height: getPercentage(cropHeight, height)
147
+ }, aspectRatio, width, height);
148
+ return ReactCrop_minExports.centerCrop(aspectCrop, width, height);
149
+ };
150
+ var onToggleAspectRatioLock = function onToggleAspectRatioLock() {
151
+ setIsAspectRatioLocked(function (isAspectRatioLocked) {
152
+ return !isAspectRatioLocked;
153
+ });
154
+ };
155
+ var handleWidthChange = function handleWidthChange(width) {
156
+ var adjustedWidth = Math.min(width, imageWidth);
157
+ setWidth(adjustedWidth);
158
+ handleWidthResize(adjustedWidth);
159
+ };
160
+ var handleHeightChange = function handleHeightChange(height) {
161
+ var adjustedHeight = Math.min(height, imageHeight);
162
+ setHeight(adjustedHeight);
163
+ handleHeighthResize(height);
164
+ };
165
+ var handleResize = function handleResize(cropWidth, cropHeight) {
166
+ var aspectRatio = aspectRatioFactor;
167
+ if (!isAspectRatioLocked) {
168
+ var imageSize = {
169
+ width: cropWidth,
170
+ height: cropHeight
171
+ };
172
+ var newAspectRatio = getAspectRatio({
173
+ imageSize: imageSize
174
+ });
175
+ aspectRatio = newAspectRatio.width / newAspectRatio.height;
176
+ setAspectRatio(newAspectRatio);
177
+ }
178
+ var newCrop = buildCropValues({
179
+ cropWidth: cropWidth,
180
+ cropHeight: cropHeight,
181
+ aspectRatio: aspectRatio
182
+ });
183
+ setCrop(newCrop);
184
+ setWidth(cropWidth);
185
+ setHeight(cropHeight);
186
+ };
187
+ var handleWidthResize = useFuncDebounce(function (width) {
188
+ var cropWidth = Number(width);
189
+ var cropHeight = Number(height);
190
+ if (isAspectRatioLocked) {
191
+ cropHeight = getHeightFromAspectRatio(cropWidth, aspectRatio);
192
+ if (cropHeight > imageHeight) {
193
+ cropHeight = imageHeight;
194
+ cropWidth = getWidthFromAspectRatio(cropHeight, aspectRatio);
195
+ }
196
+ }
197
+ handleResize(cropWidth, cropHeight);
198
+ }, 300);
199
+ var handleHeighthResize = useFuncDebounce(function (height) {
200
+ var cropWidth = Number(width);
201
+ var cropHeight = Number(height);
202
+ if (isAspectRatioLocked) {
203
+ cropWidth = getWidthFromAspectRatio(cropHeight, aspectRatio);
204
+ if (cropWidth > imageWidth) {
205
+ cropWidth = imageWidth;
206
+ cropHeight = getHeightFromAspectRatio(cropWidth, aspectRatio);
207
+ }
208
+ }
209
+ handleResize(cropWidth, cropHeight);
210
+ }, 300);
211
+ var handleAspectWidthChange = function handleAspectWidthChange(aspectWidth) {
212
+ if (aspectWidth <= 0) return;
213
+ var newWidth = crop.width * (aspectWidth / aspectRatio.width);
214
+ var updatedAspectWidth = aspectWidth;
215
+ if (newWidth > 100) {
216
+ newWidth = 100;
217
+ updatedAspectWidth = Math.round(newWidth / crop.width * aspectRatio.width);
218
+ }
219
+ var newWidthInPixels = getPixels(newWidth, imageWidth);
220
+ var newCrop = buildCropValues({
221
+ cropWidth: newWidthInPixels,
222
+ cropHeight: height,
223
+ aspectRatio: updatedAspectWidth / aspectRatio.height
224
+ });
225
+ setCrop(newCrop);
226
+ setAspectRatio(mergeRight(aspectRatio, {
227
+ width: updatedAspectWidth
228
+ }));
229
+ setWidth(newWidthInPixels);
230
+ };
231
+ var handleAspectHeightChange = function handleAspectHeightChange(aspectHeight) {
232
+ if (aspectHeight <= 0) return;
233
+ var newHeight = crop.height * (aspectHeight / aspectRatio.height);
234
+ var updatedAspectHeight = aspectHeight;
235
+ if (newHeight > 100) {
236
+ newHeight = 100;
237
+ updatedAspectHeight = Math.round(newHeight / crop.height * aspectRatio.height);
238
+ }
239
+ var newHeightInPixels = getPixels(newHeight, imageHeight);
240
+ var newCrop = buildCropValues({
241
+ cropWidth: width,
242
+ cropHeight: newHeightInPixels,
243
+ aspectRatio: aspectRatio.width / updatedAspectHeight
244
+ });
245
+ setCrop(newCrop);
246
+ setAspectRatio(mergeRight(aspectRatio, {
247
+ height: updatedAspectHeight
248
+ }));
249
+ setHeight(newHeightInPixels);
250
+ };
251
+ var handleCropChange = function handleCropChange(pixelCrop, percentageCrop) {
252
+ if (!isAspectRatioLocked) {
253
+ var _aspectRatio = getAspectRatio({
254
+ imageSize: {
255
+ width: Math.round(pixelCrop.width),
256
+ height: Math.round(pixelCrop.height)
257
+ }
258
+ });
259
+ setAspectRatio(_aspectRatio);
260
+ }
261
+ setHeight(getPixels(percentageCrop.height, imageHeight));
262
+ setWidth(getPixels(percentageCrop.width, imageWidth));
263
+ setCrop(percentageCrop);
264
+ };
265
+ var handleImageLoad = function handleImageLoad(_ref4) {
266
+ var _defaultImageSize$wid;
267
+ var image = _ref4.target;
268
+ var imageWidth = image.naturalWidth,
269
+ imageHeight = image.naturalHeight;
270
+ var maxCropWidth = (_defaultImageSize$wid = defaultImageSize.width) !== null && _defaultImageSize$wid !== void 0 ? _defaultImageSize$wid : imageWidth;
271
+ var aspectRatio = getAspectRatio({
272
+ fixedAspectRatio: fixedAspectRatio,
273
+ imageSize: {
274
+ width: imageWidth,
275
+ height: imageHeight
276
+ }
277
+ });
278
+ var aspectRatioFactor = aspectRatio.width / aspectRatio.height;
279
+ var _getInitialCropSize = getInitialCropSize({
280
+ image: image,
281
+ aspectRatioFactor: aspectRatioFactor,
282
+ maxCropWidth: maxCropWidth
283
+ }),
284
+ cropWidth = _getInitialCropSize.cropWidth,
285
+ cropHeight = _getInitialCropSize.cropHeight;
286
+ var crop = buildCropValues({
287
+ cropWidth: cropWidth,
288
+ cropHeight: cropHeight,
289
+ width: imageWidth,
290
+ height: imageHeight,
291
+ aspectRatio: aspectRatioFactor
292
+ });
293
+ setAspectRatio(aspectRatio);
294
+ setCrop(crop);
295
+ setHeight(getPixels(crop.height, imageHeight));
296
+ setWidth(getPixels(crop.width, imageWidth));
297
+ };
298
+ return {
299
+ onToggleAspectRatioLock: onToggleAspectRatioLock,
300
+ handleWidthChange: handleWidthChange,
301
+ handleHeightChange: handleHeightChange,
302
+ handleAspectWidthChange: handleAspectWidthChange,
303
+ handleAspectHeightChange: handleAspectHeightChange,
304
+ aspectRatio: aspectRatio,
305
+ width: width,
306
+ crop: crop,
307
+ height: height,
308
+ handleImageLoad: handleImageLoad,
309
+ handleCropChange: handleCropChange,
310
+ isAspectRatioLocked: isAspectRatioLocked
311
+ };
312
+ };
313
+
314
+ var ImageEditor = function ImageEditor(_ref) {
315
+ var _imageRef$current;
316
+ var image = _ref.image,
317
+ handleReset = _ref.handleReset,
318
+ _ref$handleImageEditC = _ref.handleImageEditComplete,
319
+ handleImageEditComplete = _ref$handleImageEditC === void 0 ? noop : _ref$handleImageEditC,
320
+ _ref$signedId = _ref.signedId,
321
+ signedId = _ref$signedId === void 0 ? "" : _ref$signedId,
322
+ _ref$fixedAspectRatio = _ref.fixedAspectRatio,
323
+ fixedAspectRatio = _ref$fixedAspectRatio === void 0 ? {} : _ref$fixedAspectRatio,
324
+ _ref$defaultImageSize = _ref.defaultImageSize,
325
+ defaultImageSize = _ref$defaultImageSize === void 0 ? {} : _ref$defaultImageSize;
326
+ var imageRef = useRef(null);
327
+ var wrapperRef = useRef(null);
328
+ var _ref2 = (_imageRef$current = imageRef.current) !== null && _imageRef$current !== void 0 ? _imageRef$current : {},
329
+ imageWidth = _ref2.naturalWidth,
330
+ imageHeight = _ref2.naturalHeight;
331
+ var _useState = useState(false),
332
+ _useState2 = _slicedToArray(_useState, 2),
333
+ isFullImage = _useState2[0],
334
+ setIsFullImage = _useState2[1];
335
+ var _useTranslation = useTranslation(),
336
+ t = _useTranslation.t;
337
+ var _useCropImage = useCropImage(),
338
+ cropImage = _useCropImage.mutate;
339
+ var _useImageControls = useImageControls({
340
+ fixedAspectRatio: fixedAspectRatio,
341
+ defaultImageSize: defaultImageSize,
342
+ imageRef: imageRef
343
+ }),
344
+ onToggleAspectRatioLock = _useImageControls.onToggleAspectRatioLock,
345
+ handleWidthChange = _useImageControls.handleWidthChange,
346
+ handleHeightChange = _useImageControls.handleHeightChange,
347
+ handleAspectWidthChange = _useImageControls.handleAspectWidthChange,
348
+ handleAspectHeightChange = _useImageControls.handleAspectHeightChange,
349
+ aspectRatio = _useImageControls.aspectRatio,
350
+ width = _useImageControls.width,
351
+ height = _useImageControls.height,
352
+ handleImageLoad = _useImageControls.handleImageLoad,
353
+ handleCropChange = _useImageControls.handleCropChange,
354
+ crop = _useImageControls.crop,
355
+ isAspectRatioLocked = _useImageControls.isAspectRatioLocked;
356
+ var processCrop = function processCrop() {
357
+ if (isFullImage) {
358
+ handleImageEditComplete(image);
359
+ return;
360
+ }
361
+ cropImage({
362
+ crop: getCropValues({
363
+ crop: crop,
364
+ imageRef: imageRef
365
+ }),
366
+ signedId: signedId
367
+ }, {
368
+ onSuccess: handleImageEditComplete
369
+ });
370
+ };
371
+ var handleSubmit = function handleSubmit() {
372
+ if (IS_DEVELOPMENT_OR_HEROKU_ENV) {
373
+ processCrop();
374
+ return;
375
+ }
376
+ if (isFullImage) {
377
+ handleImageEditComplete(image);
378
+ return;
379
+ }
380
+ var newURL = globalProps.assetsUploaderService === CLOUD_FLARE ? getCloudFlareCroppedURL({
381
+ image: image,
382
+ crop: crop
383
+ }) : getImageKitCroppedURL({
384
+ crop: crop,
385
+ imageURL: image.url,
386
+ imageRef: imageRef
387
+ });
388
+ handleImageEditComplete(mergeRight(image, {
389
+ url: newURL
390
+ }));
391
+ };
392
+ return /*#__PURE__*/jsxs("div", {
393
+ className: "flex h-full flex-col gap-4 px-8 py-12",
394
+ children: [/*#__PURE__*/jsx(Button, {
395
+ className: "self-start",
396
+ "data-testid": "image-editor-back-button",
397
+ icon: LeftArrow,
398
+ iconPosition: "left",
399
+ style: "text",
400
+ onClick: handleReset
401
+ }), /*#__PURE__*/jsxs("div", {
402
+ className: "flex h-full w-full flex-col gap-2 overflow-y-scroll md:flex-row md:overflow-y-auto",
403
+ children: [/*#__PURE__*/jsx("div", {
404
+ id: "imageEditor",
405
+ ref: wrapperRef,
406
+ className: classnames("flex", "h-full w-full md:w-4/6", "justify-around", "neeto-ui-bg-gray-200", "relative", {
407
+ "items-center": isItemsCenter({
408
+ wrapperRef: wrapperRef,
409
+ imageRef: imageRef
410
+ })
411
+ }),
412
+ children: /*#__PURE__*/jsxs(ReactCrop, {
413
+ crop: isFullImage ? null : crop,
414
+ src: image === null || image === void 0 ? void 0 : image.url,
415
+ style: getWrapperRefStyles(wrapperRef, imageRef),
416
+ aspect: isAspectRatioLocked ? aspectRatio.width / aspectRatio.height : 0,
417
+ onChange: handleCropChange,
418
+ onComplete: handleCropChange,
419
+ children: [/*#__PURE__*/jsx("img", {
420
+ alt: t("neetoImageUploader.common.image"),
421
+ "data-testid": "image-editor-uploaded-image",
422
+ ref: imageRef,
423
+ src: image === null || image === void 0 ? void 0 : image.url,
424
+ onLoad: handleImageLoad
425
+ }), /*#__PURE__*/jsxs(Typography, {
426
+ className: "neeto-ui-typography neeto-ui-text-nano neeto-ui-bg-gray-500 absolute bottom-0 end-0 z-10",
427
+ style: "nano",
428
+ children: [imageWidth, "x", imageHeight]
429
+ })]
430
+ })
431
+ }), /*#__PURE__*/jsx(Controls, {
432
+ aspectRatio: aspectRatio,
433
+ crop: crop,
434
+ handleAspectHeightChange: handleAspectHeightChange,
435
+ handleAspectWidthChange: handleAspectWidthChange,
436
+ handleHeightChange: handleHeightChange,
437
+ handleSubmit: handleSubmit,
438
+ handleWidthChange: handleWidthChange,
439
+ height: height,
440
+ imageRef: imageRef,
441
+ isAspectRatioLocked: isAspectRatioLocked,
442
+ isFullImage: isFullImage,
443
+ onToggleAspectRatioLock: onToggleAspectRatioLock,
444
+ setIsFullImage: setIsFullImage,
445
+ width: width,
446
+ hideControls: isPresent(fixedAspectRatio)
447
+ })]
448
+ })]
449
+ });
450
+ };
451
+
452
+ var Menu = Dropdown.Menu,
453
+ MenuItem = Dropdown.MenuItem;
454
+ var InfiniteScroller = function InfiniteScroller(_ref) {
455
+ var _ref$hasMore = _ref.hasMore,
456
+ hasMore = _ref$hasMore === void 0 ? false : _ref$hasMore,
457
+ _ref$loadMore = _ref.loadMore,
458
+ loadMore = _ref$loadMore === void 0 ? noop : _ref$loadMore,
459
+ tab = _ref.tab,
460
+ images = _ref.images,
461
+ _ref$setSelectedImage = _ref.setSelectedImage,
462
+ setSelectedImage = _ref$setSelectedImage === void 0 ? noop : _ref$setSelectedImage,
463
+ _ref$handleUnsplashIm = _ref.handleUnsplashImageSelect,
464
+ handleUnsplashImageSelect = _ref$handleUnsplashIm === void 0 ? noop : _ref$handleUnsplashIm;
465
+ var _useTranslation = useTranslation(),
466
+ t = _useTranslation.t;
467
+ var _useState = useState({
468
+ isOpen: false,
469
+ imageIds: []
470
+ }),
471
+ _useState2 = _slicedToArray(_useState, 2),
472
+ deleteConfirmation = _useState2[0],
473
+ setDeleteConfirmation = _useState2[1];
474
+ var isMenuButtonEnabled = globalProps.assetsUploaderService !== CLOUD_FLARE;
475
+ var _useBulkDestroyAssets = useBulkDestroyAssets(ASSETS_DESTROY_URL),
476
+ isPending = _useBulkDestroyAssets.isPending,
477
+ bulkDelete = _useBulkDestroyAssets.mutate;
478
+ var handleDelete = useCallback(function () {
479
+ bulkDelete(deleteConfirmation.imageIds, {
480
+ onSuccess: function onSuccess() {
481
+ return setDeleteConfirmation({
482
+ isOpen: false,
483
+ imageIds: []
484
+ });
485
+ }
486
+ });
487
+ }, [deleteConfirmation.imageIds]);
488
+ var Loader = /*#__PURE__*/jsx("div", {
489
+ className: "flex justify-center",
490
+ children: /*#__PURE__*/jsx(Spinner, {})
491
+ });
492
+ return /*#__PURE__*/jsxs("div", {
493
+ className: "niu-unsplash-container grow max-w-full overflow-x-hidden overflow-y-scroll",
494
+ children: [/*#__PURE__*/jsx(_default, {
495
+ hasMore: hasMore,
496
+ loadMore: loadMore,
497
+ pack: true,
498
+ position: true,
499
+ className: "w-full",
500
+ loader: Loader,
501
+ sizes: INFINITE_SCROLLER_SIZES,
502
+ style: INFINITE_SCROLLER_STYLE,
503
+ useWindow: false,
504
+ children: images.map(function (image, index) {
505
+ var _image$urls, _image$user, _image$user2;
506
+ return /*#__PURE__*/jsx("div", {
507
+ className: "float-start w-1/2 pb-4 pe-4 md:w-1/4",
508
+ children: /*#__PURE__*/jsx("div", {
509
+ className: "relative w-full",
510
+ style: {
511
+ paddingBottom: "".concat(image.height / image.width * 100, "%")
512
+ },
513
+ children: /*#__PURE__*/jsxs("div", {
514
+ className: "neeto-ui-rounded-sm neeto-ui-bg-gray-100 group absolute h-full w-full",
515
+ "data-testid": "library-image-card",
516
+ id: "unsplashImage".concat(image.id),
517
+ children: [tab === TABS[2].key && /*#__PURE__*/jsxs(Fragment, {
518
+ children: [/*#__PURE__*/jsx("img", {
519
+ "data-testid": "niu-unsplash-image-".concat(index),
520
+ src: image === null || image === void 0 || (_image$urls = image.urls) === null || _image$urls === void 0 ? void 0 : _image$urls.regular,
521
+ onClick: function onClick() {
522
+ return handleUnsplashImageSelect(image);
523
+ }
524
+ }), /*#__PURE__*/jsxs("a", {
525
+ className: "neeto-ui-text-gray-100 absolute bottom-2 start-2 m-auto text-xs underline opacity-0 group-hover:opacity-100",
526
+ href: "https://unsplash.com/@".concat(image === null || image === void 0 || (_image$user = image.user) === null || _image$user === void 0 ? void 0 : _image$user.username),
527
+ rel: "noreferrer",
528
+ target: "_blank",
529
+ children: [image === null || image === void 0 || (_image$user2 = image.user) === null || _image$user2 === void 0 ? void 0 : _image$user2.name, " | ", " ", t("neetoImageUploader.labels.unsplash")]
530
+ })]
531
+ }), tab === TABS[1].key && /*#__PURE__*/jsxs(Fragment, {
532
+ children: [hasPermission(VIEW_ROLES_PERMISSION) && isMenuButtonEnabled && /*#__PURE__*/jsx(Dropdown, {
533
+ buttonSize: "small",
534
+ buttonStyle: "tertiary",
535
+ "data-testid": "image-library-image-options-".concat(index),
536
+ icon: MenuHorizontal,
537
+ buttonProps: {
538
+ className:
539
+ // eslint-disable-next-line @bigbinary/neeto/use-neetoui-classes
540
+ "absolute end-2 top-2 z-1 rounded-full"
541
+ },
542
+ children: /*#__PURE__*/jsx(Menu, {
543
+ children: /*#__PURE__*/jsx(MenuItem.Button, {
544
+ "data-testid": "image-library-image-delete",
545
+ onClick: function onClick() {
546
+ return setDeleteConfirmation({
547
+ isOpen: true,
548
+ imageIds: [(image === null || image === void 0 ? void 0 : image.fileId) || image.id]
549
+ });
550
+ },
551
+ children: t("neetoImageUploader.deleteConfirmation.delete")
552
+ })
553
+ })
554
+ }), /*#__PURE__*/jsx("img", {
555
+ "data-testid": "niu-library-image-".concat(index),
556
+ src: image === null || image === void 0 ? void 0 : image.url,
557
+ onClick: function onClick() {
558
+ return setSelectedImage(image);
559
+ }
560
+ })]
561
+ })]
562
+ })
563
+ })
564
+ }, image.id);
565
+ })
566
+ }), /*#__PURE__*/jsx(Alert, {
567
+ isOpen: deleteConfirmation.isOpen,
568
+ isSubmitting: isPending,
569
+ message: t("neetoImageUploader.deleteConfirmation.message"),
570
+ submitButtonLabel: t("neetoImageUploader.deleteConfirmation.delete"),
571
+ title: t("neetoImageUploader.deleteConfirmation.title"),
572
+ onClose: function onClose() {
573
+ return setDeleteConfirmation({
574
+ isOpen: false,
575
+ imageIds: []
576
+ });
577
+ },
578
+ onSubmit: handleDelete
579
+ })]
580
+ });
581
+ };
582
+
583
+ var Images = function Images(_ref) {
584
+ var debouncedQuery = _ref.debouncedQuery,
585
+ setSelectedImage = _ref.setSelectedImage;
586
+ var _useTranslation = useTranslation(),
587
+ t = _useTranslation.t;
588
+ var _useFetchAssets = useFetchAssets({
589
+ searchTerm: debouncedQuery,
590
+ per: IMAGES_PER_PAGE,
591
+ url: ASSETS_FETCH_URL
592
+ }),
593
+ fetchNextPage = _useFetchAssets.fetchNextPage,
594
+ hasNextPage = _useFetchAssets.hasNextPage,
595
+ _useFetchAssets$data = _useFetchAssets.data,
596
+ _useFetchAssets$data2 = _useFetchAssets$data === void 0 ? {} : _useFetchAssets$data,
597
+ _useFetchAssets$data3 = _useFetchAssets$data2.results,
598
+ results = _useFetchAssets$data3 === void 0 ? [] : _useFetchAssets$data3,
599
+ isLoading = _useFetchAssets.isLoading,
600
+ isError = _useFetchAssets.isError;
601
+ if (isError) {
602
+ return /*#__PURE__*/jsx("div", {
603
+ className: "grow flex justify-center items-center",
604
+ children: /*#__PURE__*/jsx(Typography, {
605
+ style: "body2",
606
+ children: t("neetoImageUploader.unsplash.errorMessage")
607
+ })
608
+ });
609
+ }
610
+ if (isLoading) {
611
+ return /*#__PURE__*/jsx("div", {
612
+ className: "grow flex justify-center items-center",
613
+ children: /*#__PURE__*/jsx(Spinner, {})
614
+ });
615
+ }
616
+ if (isEmpty(results)) {
617
+ return /*#__PURE__*/jsx("div", {
618
+ className: "grow flex justify-center items-center",
619
+ children: /*#__PURE__*/jsx(NoData, {
620
+ title: t("neetoImageUploader.common.noImagesToShow")
621
+ })
622
+ });
623
+ }
624
+ return /*#__PURE__*/createElement(InfiniteScroller, {
625
+ setSelectedImage: setSelectedImage,
626
+ hasMore: hasNextPage,
627
+ images: results,
628
+ key: debouncedQuery,
629
+ loadMore: fetchNextPage,
630
+ tab: TABS[1].key
631
+ });
632
+ };
633
+
634
+ var UnsplashLibrary = function UnsplashLibrary(_ref) {
635
+ var debouncedQuery = _ref.debouncedQuery,
636
+ setSelectedImage = _ref.setSelectedImage,
637
+ setIsUploading = _ref.setIsUploading,
638
+ setActiveTab = _ref.setActiveTab;
639
+ var _useImageUploader = useImageUploader({
640
+ onUploadComplete: setSelectedImage,
641
+ setIsUploading: setIsUploading
642
+ }),
643
+ uploadFile = _useImageUploader.uploadFile;
644
+ var handleUnsplashImageSelect = /*#__PURE__*/function () {
645
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(image) {
646
+ var _image$urls, response, file;
647
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
648
+ while (1) switch (_context.prev = _context.next) {
649
+ case 0:
650
+ _context.prev = 0;
651
+ setIsUploading(true);
652
+ _context.next = 4;
653
+ return unsplashApi.getUnsplashImage((_image$urls = image.urls) === null || _image$urls === void 0 ? void 0 : _image$urls.regular, UNSPLASH_DEFAULT_REQUEST_CONFIG);
654
+ case 4:
655
+ response = _context.sent;
656
+ file = new File([response.data], UNSPLASH_DEFAULT_NAME, {
657
+ type: response.data.type
658
+ });
659
+ uploadFile(file);
660
+ _context.next = 14;
661
+ break;
662
+ case 9:
663
+ _context.prev = 9;
664
+ _context.t0 = _context["catch"](0);
665
+ Toastr.error(_context.t0);
666
+ setActiveTab(TABS[1].key);
667
+ setIsUploading(false);
668
+ case 14:
669
+ case "end":
670
+ return _context.stop();
671
+ }
672
+ }, _callee, null, [[0, 9]]);
673
+ }));
674
+ return function handleUnsplashImageSelect(_x) {
675
+ return _ref2.apply(this, arguments);
676
+ };
677
+ }();
678
+ var _useTranslation = useTranslation(),
679
+ t = _useTranslation.t;
680
+ var _useFetchUnsplashImag = useFetchUnsplashImages({
681
+ query: debouncedQuery
682
+ }),
683
+ fetchNextPage = _useFetchUnsplashImag.fetchNextPage,
684
+ hasNextPage = _useFetchUnsplashImag.hasNextPage,
685
+ _useFetchUnsplashImag2 = _useFetchUnsplashImag.data,
686
+ _useFetchUnsplashImag3 = _useFetchUnsplashImag2 === void 0 ? {} : _useFetchUnsplashImag2,
687
+ _useFetchUnsplashImag4 = _useFetchUnsplashImag3.results,
688
+ results = _useFetchUnsplashImag4 === void 0 ? [] : _useFetchUnsplashImag4,
689
+ isError = _useFetchUnsplashImag.isError,
690
+ isLoading = _useFetchUnsplashImag.isLoading;
691
+ if (isError) {
692
+ return /*#__PURE__*/jsx("div", {
693
+ className: "grow flex justify-center items-center",
694
+ children: /*#__PURE__*/jsx(Typography, {
695
+ style: "body2",
696
+ children: t("neetoImageUploader.unsplash.errorMessage")
697
+ })
698
+ });
699
+ }
700
+ if (isLoading) {
701
+ return /*#__PURE__*/jsx("div", {
702
+ className: "grow flex justify-center items-center",
703
+ children: /*#__PURE__*/jsx(Spinner, {})
704
+ });
705
+ }
706
+ if (isEmpty(results)) {
707
+ return /*#__PURE__*/jsx("div", {
708
+ className: "grow flex justify-center items-center",
709
+ children: /*#__PURE__*/jsx(NoData, {
710
+ title: t("neetoImageUploader.common.noImagesToShow")
711
+ })
712
+ });
713
+ }
714
+ return /*#__PURE__*/createElement(InfiniteScroller, {
715
+ debouncedQuery: debouncedQuery,
716
+ handleUnsplashImageSelect: handleUnsplashImageSelect,
717
+ hasMore: hasNextPage,
718
+ images: results,
719
+ key: debouncedQuery,
720
+ loadMore: fetchNextPage,
721
+ tab: TABS[2].key
722
+ });
723
+ };
724
+
725
+ var ImageLibrary = function ImageLibrary(_ref) {
726
+ var setSelectedImage = _ref.setSelectedImage,
727
+ tab = _ref.tab,
728
+ setIsUploading = _ref.setIsUploading,
729
+ setActiveTab = _ref.setActiveTab;
730
+ var _useState = useState(""),
731
+ _useState2 = _slicedToArray(_useState, 2),
732
+ query = _useState2[0],
733
+ setQuery = _useState2[1];
734
+ var _useTranslation = useTranslation(),
735
+ t = _useTranslation.t;
736
+ var debouncedQuery = useDebounce(query, 400);
737
+ var inputPlaceHolder = equals(tab, TABS[2].key) ? t("neetoImageUploader.placeholders.searchImageFromWeb") : t("neetoImageUploader.placeholders.searchImage");
738
+ useEffect(function () {
739
+ setQuery("");
740
+ }, [tab]);
741
+ return /*#__PURE__*/jsxs("div", {
742
+ className: "w-full px-6 py-4 grow flex flex-col",
743
+ children: [/*#__PURE__*/jsx("div", {
744
+ className: "mb-4 shrink-0",
745
+ children: /*#__PURE__*/jsx(Input, {
746
+ autoFocus: true,
747
+ "data-testid": "niu-unsplash-image-picker-search-input",
748
+ name: "text",
749
+ placeholder: inputPlaceHolder,
750
+ value: query,
751
+ onChange: function onChange(_ref2) {
752
+ var value = _ref2.target.value;
753
+ return setQuery(value);
754
+ }
755
+ })
756
+ }), tab === TABS[1].key ? /*#__PURE__*/jsx(Images, {
757
+ debouncedQuery: debouncedQuery,
758
+ query: query,
759
+ setSelectedImage: setSelectedImage
760
+ }) : /*#__PURE__*/jsx(UnsplashLibrary, {
761
+ debouncedQuery: debouncedQuery,
762
+ query: query,
763
+ setActiveTab: setActiveTab,
764
+ setIsUploading: setIsUploading,
765
+ setSelectedImage: setSelectedImage
766
+ })]
767
+ });
768
+ };
769
+
770
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
771
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
772
+ var Modal = function Modal(_ref) {
773
+ var isOpen = _ref.isOpen,
774
+ _ref$onClose = _ref.onClose,
775
+ onClose = _ref$onClose === void 0 ? noop : _ref$onClose,
776
+ _ref$onUploadComplete = _ref.onUploadComplete,
777
+ onUploadComplete = _ref$onUploadComplete === void 0 ? noop : _ref$onUploadComplete,
778
+ _ref$uploadConfig = _ref.uploadConfig,
779
+ uploadConfig = _ref$uploadConfig === void 0 ? {} : _ref$uploadConfig,
780
+ _ref$fixedAspectRatio = _ref.fixedAspectRatio,
781
+ fixedAspectRatio = _ref$fixedAspectRatio === void 0 ? {} : _ref$fixedAspectRatio,
782
+ _ref$defaultImageSize = _ref.defaultImageSize,
783
+ defaultImageSize = _ref$defaultImageSize === void 0 ? {} : _ref$defaultImageSize;
784
+ var _useState = useState(TABS[0].key),
785
+ _useState2 = _slicedToArray(_useState, 2),
786
+ activeTab = _useState2[0],
787
+ setActiveTab = _useState2[1];
788
+ var _useState3 = useState({}),
789
+ _useState4 = _slicedToArray(_useState3, 2),
790
+ selectedImage = _useState4[0],
791
+ setSelectedImage = _useState4[1];
792
+ var _useState5 = useState(false),
793
+ _useState6 = _slicedToArray(_useState5, 2),
794
+ isUploading = _useState6[0],
795
+ setIsUploading = _useState6[1];
796
+ var _useTranslation = useTranslation(),
797
+ t = _useTranslation.t;
798
+ var _useCreateBlob = useCreateBlob(),
799
+ createBlob = _useCreateBlob.mutate;
800
+ var uploadConfigWithDefaults = mergeRight(DEFAULT_UPLOAD_CONFIG, uploadConfig);
801
+ var isCloudFlareImageUploader = globalProps.assetsUploaderService === CLOUD_FLARE;
802
+ var handleCloseModal = function handleCloseModal() {
803
+ onClose();
804
+ setSelectedImage({});
805
+ };
806
+ var handleImageEditComplete = function handleImageEditComplete(editedImage) {
807
+ handleCreateBlob(editedImage, true);
808
+ handleCloseModal();
809
+ };
810
+ var handleUploadComplete = function handleUploadComplete(image) {
811
+ if (isGif(image)) {
812
+ handleCreateBlob(image);
813
+ handleCloseModal();
814
+ return;
815
+ }
816
+ isCloudFlareImageUploader && handleCreateBlob(image);
817
+ setSelectedImage(image);
818
+ };
819
+ var handleCreateBlob = function handleCreateBlob(editedImage) {
820
+ var isCropped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
821
+ if (IS_DEVELOPMENT_OR_HEROKU_ENV || isGif(editedImage)) {
822
+ onUploadComplete({
823
+ url: editedImage.url,
824
+ signedId: editedImage.signedId
825
+ });
826
+ } else {
827
+ var imageKitPayload = function imageKitPayload() {
828
+ return {
829
+ filename: generateASCIIFileName(editedImage.name),
830
+ byte_size: editedImage.size,
831
+ content_type: editedImage.fileType,
832
+ checksum: editedImage.fileId,
833
+ metadata: editedImage,
834
+ service_name: "imagekitio"
835
+ };
836
+ };
837
+ var cloudFlarePayload = function cloudFlarePayload() {
838
+ return {
839
+ filename: generateASCIIFileName(editedImage.filename),
840
+ content_type: editedImage.contentType,
841
+ byte_size: editedImage.byteSize,
842
+ checksum: editedImage.checksum,
843
+ metadata: _objectSpread(_objectSpread({}, editedImage.metadata), {}, {
844
+ url: constructCloudflareImageURL(editedImage.url),
845
+ isCropped: isCropped
846
+ }),
847
+ service_name: "cloudflare_image"
848
+ };
849
+ };
850
+ var payload = isCloudFlareImageUploader ? cloudFlarePayload() : imageKitPayload();
851
+ createBlob(payload, {
852
+ onSuccess: function onSuccess(image) {
853
+ onUploadComplete({
854
+ url: image.blobUrl,
855
+ signedId: image.signedId
856
+ });
857
+ },
858
+ onError: Toastr.error
859
+ });
860
+ }
861
+ };
862
+ var _useImageUploader = useImageUploader({
863
+ onUploadComplete: handleUploadComplete,
864
+ setIsUploading: setIsUploading
865
+ }),
866
+ uploadFile = _useImageUploader.uploadFile;
867
+ var _useUploadDropzone = useUploadDropzone({
868
+ uploadConfig: uploadConfigWithDefaults,
869
+ onDrop: uploadFile
870
+ }),
871
+ getRootProps = _useUploadDropzone.getRootProps,
872
+ getInputProps = _useUploadDropzone.getInputProps,
873
+ isDragActive = _useUploadDropzone.isDragActive;
874
+ useEffect(function () {
875
+ setActiveTab(TABS[0].key);
876
+ }, [isOpen]);
877
+ var renderContent = function renderContent() {
878
+ if (activeTab === "upload") {
879
+ return /*#__PURE__*/jsx("div", {
880
+ className: "grow px-6 pb-6 pt-4",
881
+ children: /*#__PURE__*/jsx("div", {
882
+ className: "h-full w-full overflow-y-auto",
883
+ children: /*#__PURE__*/jsx(ImageDirectUpload, {
884
+ uploadConfig: uploadConfigWithDefaults,
885
+ onDrop: uploadFile
886
+ })
887
+ })
888
+ });
889
+ }
890
+ return /*#__PURE__*/jsx(ImageLibrary, {
891
+ setActiveTab: setActiveTab,
892
+ setIsUploading: setIsUploading,
893
+ setSelectedImage: setSelectedImage,
894
+ tab: activeTab
895
+ });
896
+ };
897
+ return /*#__PURE__*/jsxs(NeetoUIModal, {
898
+ isOpen: isOpen,
899
+ className: "niu-modal",
900
+ size: "large",
901
+ onClose: handleCloseModal,
902
+ children: [isUploading && /*#__PURE__*/jsx("div", {
903
+ className: "neeto-ui-bg-gray-400 absolute inset-0 z-50 flex h-full items-center justify-center opacity-50",
904
+ children: /*#__PURE__*/jsx(Spinner, {})
905
+ }), isNilOrEmpty(selectedImage) && isDragActive && /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
906
+ className: "neeto-ui-rounded-xl neeto-ui-bg-gray-400 absolute flex h-full w-full flex-col items-center justify-around border-4 border-dashed border-gray-900 opacity-40"
907
+ }, getRootProps()), {}, {
908
+ children: /*#__PURE__*/jsx(Typography, {
909
+ children: t("neetoImageUploader.common.dropHere")
910
+ })
911
+ })), !isNilOrEmpty(selectedImage) ? /*#__PURE__*/jsx(ImageEditor, {
912
+ defaultImageSize: defaultImageSize,
913
+ fixedAspectRatio: fixedAspectRatio,
914
+ handleImageEditComplete: handleImageEditComplete,
915
+ handleReset: function handleReset() {
916
+ return setSelectedImage({});
917
+ },
918
+ image: selectedImage,
919
+ signedId: selectedImage === null || selectedImage === void 0 ? void 0 : selectedImage.signedId
920
+ }) : /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
921
+ className: "flex h-full flex-col"
922
+ }, getRootProps({
923
+ onClick: function onClick(event) {
924
+ return event.stopPropagation();
925
+ }
926
+ })), {}, {
927
+ children: [/*#__PURE__*/jsx(NeetoUIModal.Header, {
928
+ children: /*#__PURE__*/jsx(Typography, {
929
+ style: "h2",
930
+ children: t("neetoImageUploader.common.imageLibrary")
931
+ })
932
+ }), /*#__PURE__*/jsx("div", {
933
+ className: "flex gap-2 px-6",
934
+ children: /*#__PURE__*/jsx(Tab, {
935
+ size: "small",
936
+ children: TABS.map(function (tab) {
937
+ return /*#__PURE__*/jsx(Tab.Item, {
938
+ active: activeTab === tab.key,
939
+ "data-testid": tab.dataTestid,
940
+ onClick: function onClick() {
941
+ return setActiveTab(tab.key);
942
+ },
943
+ children: tab.label
944
+ }, tab.key);
945
+ })
946
+ })
947
+ }), renderContent(), equals(activeTab, TABS[2].key) && /*#__PURE__*/jsx(NeetoUIModal.Footer, {
948
+ className: "flex items-center justify-center gap-2",
949
+ children: /*#__PURE__*/jsx(Typography, {
950
+ lineHeight: "none",
951
+ style: "body2",
952
+ children: /*#__PURE__*/jsx(Trans, {
953
+ i18nKey: "neetoImageUploader.unsplash.poweredByUnsplash",
954
+ components: {
955
+ a: /*#__PURE__*/jsx("a", {
956
+ href: UNSPLASH_URL,
957
+ rel: "noreferrer",
958
+ target: "_blank"
959
+ })
960
+ }
961
+ })
962
+ })
963
+ })]
964
+ })), /*#__PURE__*/jsx("input", _objectSpread({}, getInputProps()))]
965
+ });
966
+ };
967
+
968
+ export { Modal as M, constructCloudflareImageURL as c };
969
+ //# sourceMappingURL=index-krkZ4CNS.js.map