@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/app/javascript/src/translations/en.json +4 -0
- package/dist/index.cjs.js +103 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +103 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/types.d.ts +22 -6
|
@@ -53,6 +53,10 @@
|
|
|
53
53
|
"restrictionMessage": "{{fileTypes, anyCase}}. upto {{size}} MB.",
|
|
54
54
|
"uploadedImage": "Uploaded Image",
|
|
55
55
|
"dragDropOrBrowseOrImageLibrary": "Drag and drop or <span>Browse</span> a file or select from <span>Image Library</span>."
|
|
56
|
+
},
|
|
57
|
+
"errors": {
|
|
58
|
+
"sdkKeysMissing": "Missing urlEndpoint during SDK initialization",
|
|
59
|
+
"imagekitKeysMissing": "ImageKit initialization keys are not provided"
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
62
|
}
|
package/dist/index.cjs.js
CHANGED
|
@@ -5452,8 +5452,111 @@ var useImageUpload = function useImageUpload() {
|
|
|
5452
5452
|
};
|
|
5453
5453
|
};
|
|
5454
5454
|
|
|
5455
|
+
var useProfileImageUpload = function useProfileImageUpload(_ref) {
|
|
5456
|
+
var _ref$uploadConfig = _ref.uploadConfig,
|
|
5457
|
+
uploadConfig = _ref$uploadConfig === void 0 ? {} : _ref$uploadConfig;
|
|
5458
|
+
var _useState = React.useState(0),
|
|
5459
|
+
_useState2 = _slicedToArray$2(_useState, 2),
|
|
5460
|
+
uploadProgress = _useState2[0],
|
|
5461
|
+
setUploadProgress = _useState2[1];
|
|
5462
|
+
var _useState3 = React.useState(false),
|
|
5463
|
+
_useState4 = _slicedToArray$2(_useState3, 2),
|
|
5464
|
+
isUploading = _useState4[0],
|
|
5465
|
+
setIsUploading = _useState4[1];
|
|
5466
|
+
var authenticationEndpoint = "".concat(window.location.origin, "/neeto_image_uploader_engine/imagekit/auth");
|
|
5467
|
+
var defaultImageKitConfig = {
|
|
5468
|
+
folder: initializers.globalProps.imagekit.folder,
|
|
5469
|
+
customMetadata: {
|
|
5470
|
+
organizationKey: initializers.globalProps.organization.publicApiKey,
|
|
5471
|
+
appName: initializers.globalProps.appName
|
|
5472
|
+
}
|
|
5473
|
+
};
|
|
5474
|
+
var imagekitConfig = ramda.mergeDeepRight(defaultImageKitConfig, uploadConfig);
|
|
5475
|
+
var handleUploadProgress = function handleUploadProgress(e, fileSize) {
|
|
5476
|
+
if (e.loaded <= fileSize) {
|
|
5477
|
+
var percent = Math.round(e.loaded / fileSize * 100);
|
|
5478
|
+
setUploadProgress(percent);
|
|
5479
|
+
}
|
|
5480
|
+
ramda.equals(e.loaded, e.total) && setUploadProgress(100);
|
|
5481
|
+
};
|
|
5482
|
+
var uploadToImagekit = /*#__PURE__*/function () {
|
|
5483
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file, XHRProgress, onUploadComplete) {
|
|
5484
|
+
var imagekit, image, errorMessage;
|
|
5485
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
5486
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5487
|
+
case 0:
|
|
5488
|
+
_context.prev = 0;
|
|
5489
|
+
imagekit = new ImageKit(ramda.mergeRight(initializers.globalProps.imagekit, {
|
|
5490
|
+
authenticationEndpoint: authenticationEndpoint
|
|
5491
|
+
}));
|
|
5492
|
+
setIsUploading(true);
|
|
5493
|
+
_context.next = 5;
|
|
5494
|
+
return imagekit.upload({
|
|
5495
|
+
xhr: XHRProgress,
|
|
5496
|
+
file: file,
|
|
5497
|
+
fileName: generateASCIIFileName(file.name),
|
|
5498
|
+
folder: imagekitConfig.folder,
|
|
5499
|
+
customMetadata: imagekitConfig.customMetadata
|
|
5500
|
+
});
|
|
5501
|
+
case 5:
|
|
5502
|
+
image = _context.sent;
|
|
5503
|
+
onUploadComplete(image);
|
|
5504
|
+
_context.next = 13;
|
|
5505
|
+
break;
|
|
5506
|
+
case 9:
|
|
5507
|
+
_context.prev = 9;
|
|
5508
|
+
_context.t0 = _context["catch"](0);
|
|
5509
|
+
errorMessage = ramda.equals(_context.t0.message, i18next.t("neetoImageUploader.errors.sdkKeysMissing")) ? i18next.t("neetoImageUploader.errors.imagekitKeysMissing") : _context.t0.message;
|
|
5510
|
+
neetoui.Toastr.error(errorMessage);
|
|
5511
|
+
case 13:
|
|
5512
|
+
_context.prev = 13;
|
|
5513
|
+
setIsUploading(false);
|
|
5514
|
+
return _context.finish(13);
|
|
5515
|
+
case 16:
|
|
5516
|
+
case "end":
|
|
5517
|
+
return _context.stop();
|
|
5518
|
+
}
|
|
5519
|
+
}, _callee, null, [[0, 9, 13, 16]]);
|
|
5520
|
+
}));
|
|
5521
|
+
return function uploadToImagekit(_x, _x2, _x3) {
|
|
5522
|
+
return _ref2.apply(this, arguments);
|
|
5523
|
+
};
|
|
5524
|
+
}();
|
|
5525
|
+
var uploadImage = /*#__PURE__*/function () {
|
|
5526
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(file, onUploadComplete) {
|
|
5527
|
+
var fileSize, XHRProgress;
|
|
5528
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
5529
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
5530
|
+
case 0:
|
|
5531
|
+
setUploadProgress(0);
|
|
5532
|
+
fileSize = file.size;
|
|
5533
|
+
XHRProgress = new XMLHttpRequest();
|
|
5534
|
+
XHRProgress.upload.addEventListener("progress", function (e) {
|
|
5535
|
+
handleUploadProgress(e, fileSize);
|
|
5536
|
+
});
|
|
5537
|
+
_context2.next = 6;
|
|
5538
|
+
return uploadToImagekit(file, XHRProgress, onUploadComplete);
|
|
5539
|
+
case 6:
|
|
5540
|
+
case "end":
|
|
5541
|
+
return _context2.stop();
|
|
5542
|
+
}
|
|
5543
|
+
}, _callee2);
|
|
5544
|
+
}));
|
|
5545
|
+
return function uploadImage(_x4, _x5) {
|
|
5546
|
+
return _ref3.apply(this, arguments);
|
|
5547
|
+
};
|
|
5548
|
+
}();
|
|
5549
|
+
return {
|
|
5550
|
+
uploadImage: uploadImage,
|
|
5551
|
+
uploadProgress: uploadProgress,
|
|
5552
|
+
isUploading: isUploading
|
|
5553
|
+
};
|
|
5554
|
+
};
|
|
5555
|
+
|
|
5455
5556
|
exports.AssetLibrary = Modal;
|
|
5456
5557
|
exports.BasicImageUploader = BasicImageUploader;
|
|
5457
5558
|
exports.ImageUploader = ImageUploader;
|
|
5458
5559
|
exports.useImageUpload = useImageUpload;
|
|
5560
|
+
exports.useImageUploader = useImageUploader;
|
|
5561
|
+
exports.useProfileImageUpload = useProfileImageUpload;
|
|
5459
5562
|
//# sourceMappingURL=index.cjs.js.map
|