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