@bigbinary/neeto-image-uploader-frontend 1.5.20 → 1.5.21

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/index.js CHANGED
@@ -3,7 +3,7 @@ import classnames from 'classnames';
3
3
  import { noop as noop$1, keysToCamelCase, findBy } from '@bigbinary/neeto-cist';
4
4
  import { Delete, LeftArrow, MenuHorizontal } from '@bigbinary/neeto-icons';
5
5
  import { Toastr, Typography, Button, Switch, Input, Spinner, Modal as Modal$1, Tab, Dropdown } from '@bigbinary/neetoui';
6
- import { pipe, values, flatten as flatten$1, map, toUpper, join, equals, isNil, isEmpty, mergeRight, mergeLeft, concat, __, inc } from 'ramda';
6
+ import { pipe, values, flatten as flatten$1, map, toUpper, join, equals, isNil, isEmpty, mergeRight, mergeLeft, concat, __, inc, mergeDeepRight } from 'ramda';
7
7
  import { Trans, useTranslation } from 'react-i18next';
8
8
  import { globalProps } from '@bigbinary/neeto-commons-frontend/initializers';
9
9
  import i18next, { t as t$1 } from 'i18next';
@@ -5441,5 +5441,106 @@ var useImageUpload = function useImageUpload() {
5441
5441
  };
5442
5442
  };
5443
5443
 
5444
- export { Modal as AssetLibrary, BasicImageUploader, ImageUploader, useImageUpload };
5444
+ var useProfileImageUpload = function useProfileImageUpload(_ref) {
5445
+ var _ref$uploadConfig = _ref.uploadConfig,
5446
+ uploadConfig = _ref$uploadConfig === void 0 ? {} : _ref$uploadConfig;
5447
+ var _useState = useState(0),
5448
+ _useState2 = _slicedToArray$2(_useState, 2),
5449
+ uploadProgress = _useState2[0],
5450
+ setUploadProgress = _useState2[1];
5451
+ var _useState3 = useState(false),
5452
+ _useState4 = _slicedToArray$2(_useState3, 2),
5453
+ isUploading = _useState4[0],
5454
+ setIsUploading = _useState4[1];
5455
+ var authenticationEndpoint = "".concat(window.location.origin, "/neeto_image_uploader_engine/imagekit/auth");
5456
+ var defaultImageKitConfig = {
5457
+ folder: globalProps.imagekit.folder,
5458
+ customMetadata: {
5459
+ organizationKey: globalProps.organization.publicApiKey,
5460
+ appName: globalProps.appName
5461
+ }
5462
+ };
5463
+ var imagekitConfig = mergeDeepRight(defaultImageKitConfig, uploadConfig);
5464
+ var handleUploadProgress = function handleUploadProgress(e, fileSize) {
5465
+ if (e.loaded <= fileSize) {
5466
+ var percent = Math.round(e.loaded / fileSize * 100);
5467
+ setUploadProgress(percent);
5468
+ }
5469
+ equals(e.loaded, e.total) && setUploadProgress(100);
5470
+ };
5471
+ var uploadToImagekit = /*#__PURE__*/function () {
5472
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file, XHRProgress, onUploadComplete) {
5473
+ var imagekit, image, errorMessage;
5474
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
5475
+ while (1) switch (_context.prev = _context.next) {
5476
+ case 0:
5477
+ _context.prev = 0;
5478
+ imagekit = new ImageKit(mergeRight(globalProps.imagekit, {
5479
+ authenticationEndpoint: authenticationEndpoint
5480
+ }));
5481
+ setIsUploading(true);
5482
+ _context.next = 5;
5483
+ return imagekit.upload({
5484
+ xhr: XHRProgress,
5485
+ file: file,
5486
+ fileName: generateASCIIFileName(file.name),
5487
+ folder: imagekitConfig.folder,
5488
+ customMetadata: imagekitConfig.customMetadata
5489
+ });
5490
+ case 5:
5491
+ image = _context.sent;
5492
+ onUploadComplete(image);
5493
+ _context.next = 13;
5494
+ break;
5495
+ case 9:
5496
+ _context.prev = 9;
5497
+ _context.t0 = _context["catch"](0);
5498
+ errorMessage = equals(_context.t0.message, t$1("neetoImageUploader.errors.sdkKeysMissing")) ? t$1("neetoImageUploader.errors.imagekitKeysMissing") : _context.t0.message;
5499
+ Toastr.error(errorMessage);
5500
+ case 13:
5501
+ _context.prev = 13;
5502
+ setIsUploading(false);
5503
+ return _context.finish(13);
5504
+ case 16:
5505
+ case "end":
5506
+ return _context.stop();
5507
+ }
5508
+ }, _callee, null, [[0, 9, 13, 16]]);
5509
+ }));
5510
+ return function uploadToImagekit(_x, _x2, _x3) {
5511
+ return _ref2.apply(this, arguments);
5512
+ };
5513
+ }();
5514
+ var uploadImage = /*#__PURE__*/function () {
5515
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(file, onUploadComplete) {
5516
+ var fileSize, XHRProgress;
5517
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
5518
+ while (1) switch (_context2.prev = _context2.next) {
5519
+ case 0:
5520
+ setUploadProgress(0);
5521
+ fileSize = file.size;
5522
+ XHRProgress = new XMLHttpRequest();
5523
+ XHRProgress.upload.addEventListener("progress", function (e) {
5524
+ handleUploadProgress(e, fileSize);
5525
+ });
5526
+ _context2.next = 6;
5527
+ return uploadToImagekit(file, XHRProgress, onUploadComplete);
5528
+ case 6:
5529
+ case "end":
5530
+ return _context2.stop();
5531
+ }
5532
+ }, _callee2);
5533
+ }));
5534
+ return function uploadImage(_x4, _x5) {
5535
+ return _ref3.apply(this, arguments);
5536
+ };
5537
+ }();
5538
+ return {
5539
+ uploadImage: uploadImage,
5540
+ uploadProgress: uploadProgress,
5541
+ isUploading: isUploading
5542
+ };
5543
+ };
5544
+
5545
+ export { Modal as AssetLibrary, BasicImageUploader, ImageUploader, useImageUpload, useImageUploader, useProfileImageUpload };
5445
5546
  //# sourceMappingURL=index.js.map