@carbonorm/carbonreact 2.0.2 → 2.0.3

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.
@@ -15,4 +15,4 @@ export declare enum eUpdateInsertMethod {
15
15
  * @param callback - if you want to do something with the updated state, you can pass a callback here. Run as the second
16
16
  * parameter of setState.
17
17
  */
18
- export default function updateRestfulObjectArray<ObjectType = tRestfulObjectValues, ObjectArrayTypes = iRestfulObjectArrayTypes>(dataOrCallback: ((prev: Readonly<iCarbonReactState>) => ObjectType[]) | ObjectType[], stateKey: keyof ObjectArrayTypes, uniqueObjectId: keyof ObjectType, insertUpdateOrder?: eUpdateInsertMethod, callback?: () => void): void;
18
+ export default function updateRestfulObjectArrays<ObjectType = tRestfulObjectValues, ObjectArrayTypes = iRestfulObjectArrayTypes>(dataOrCallback: ((prev: Readonly<iCarbonReactState>) => ObjectType[]) | ObjectType[], stateKey: keyof ObjectArrayTypes, uniqueObjectId: keyof ObjectType, insertUpdateOrder?: eUpdateInsertMethod, callback?: () => void): void;
@@ -1,4 +1,4 @@
1
1
  import { ChangeEvent } from "react";
2
2
  export declare function toDataURL(src: string, fileType: string, callback: (dataUriEncoded: string) => void): Promise<void>;
3
- export declare function uploadImageChange(event: ChangeEvent<HTMLInputElement>, uploadCallback: ((imageDataUri: string) => void)): void;
3
+ export declare function uploadImageChange(event: ChangeEvent<HTMLInputElement>, uploadCallback: (dataUriBase64: string) => void): Promise<void>;
4
4
  export default function uploadImage(uploadCallback: (dataUriBase64: string) => void): () => void;
package/dist/index.cjs.js CHANGED
@@ -3438,7 +3438,7 @@ exports.eUpdateInsertMethod = void 0;
3438
3438
  * @param callback - if you want to do something with the updated state, you can pass a callback here. Run as the second
3439
3439
  * parameter of setState.
3440
3440
  */
3441
- function updateRestfulObjectArray(dataOrCallback, stateKey, uniqueObjectId, insertUpdateOrder, callback) {
3441
+ function updateRestfulObjectArrays(dataOrCallback, stateKey, uniqueObjectId, insertUpdateOrder, callback) {
3442
3442
  if (insertUpdateOrder === void 0) { insertUpdateOrder = exports.eUpdateInsertMethod.LAST; }
3443
3443
  var bootstrap = CarbonReact.instance;
3444
3444
  return bootstrap.setState(function (previousBootstrapState) {
@@ -3501,25 +3501,61 @@ function toDataURL(src, fileType, callback) {
3501
3501
  });
3502
3502
  }
3503
3503
  function uploadImageChange(event, uploadCallback) {
3504
- if (event.target.files !== null && event.target.files[0]) {
3505
- Object.keys(event.target.files).forEach(function (index) {
3506
- var _a;
3507
- var file = (_a = event.target.files) === null || _a === void 0 ? void 0 : _a[index];
3508
- // loop through all files and create data url then post to postPost
3509
- if (file.type.match('image.*')) {
3510
- // get file extension
3511
- var fileExtension = file.name.split('.').pop();
3512
- // check file extension is valid data uri
3513
- if (fileExtension !== 'jpg' && fileExtension !== 'jpeg' && fileExtension !== 'png' && fileExtension !== 'gif') {
3514
- reactToastify.toast.error('Please upload a valid image file type (jpg, jpeg, png, gif).');
3515
- return;
3516
- }
3517
- // @link https://github.com/palantir/tslint/issues/4653
3518
- // @link https://github.com/Microsoft/TypeScript/issues/13376#issuecomment-273289748
3519
- void toDataURL(URL.createObjectURL(file), file.type, uploadCallback);
3504
+ var _a, _b;
3505
+ return __awaiter(this, void 0, void 0, function () {
3506
+ var _this = this;
3507
+ return __generator(this, function (_c) {
3508
+ if (event.target.files === null || undefined === ((_b = (_a = event.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0])) {
3509
+ reactToastify.toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic).');
3510
+ return [2 /*return*/];
3520
3511
  }
3512
+ Object.keys(event.target.files).forEach(function (index) {
3513
+ (function () { return __awaiter(_this, void 0, void 0, function () {
3514
+ var file, fileExtension, isHeic;
3515
+ var _a;
3516
+ return __generator(this, function (_b) {
3517
+ switch (_b.label) {
3518
+ case 0:
3519
+ file = (_a = event.target.files) === null || _a === void 0 ? void 0 : _a[index];
3520
+ // loop through all files and create data url then post to postPost
3521
+ if (false === file.type.match('image.*')) {
3522
+ reactToastify.toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic). (E_IMAGE_*<>' + file.type + ')');
3523
+ return [2 /*return*/];
3524
+ }
3525
+ fileExtension = file.name.split('.').pop();
3526
+ // check file extension is valid data uri
3527
+ if (fileExtension !== 'jpg'
3528
+ && fileExtension !== 'jpeg'
3529
+ && fileExtension !== 'heic'
3530
+ && fileExtension !== 'png'
3531
+ && fileExtension !== 'gif') {
3532
+ reactToastify.toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic). (E_IMAGE_EXT)');
3533
+ return [2 /*return*/];
3534
+ }
3535
+ isHeic = fileExtension === 'heic';
3536
+ if (!isHeic) return [3 /*break*/, 2];
3537
+ return [4 /*yield*/, React.lazy(function () { return require("heic2any"); })];
3538
+ case 1:
3539
+ // todo - this should be code split and lazy loaded, but doesn't work
3540
+ // look up code splitting, it could be an issue with rewired
3541
+ file = (_b.sent())({
3542
+ blob: file,
3543
+ toType: "image/webp",
3544
+ quality: 1.0, // 0.5 cuts the quality and size by half
3545
+ });
3546
+ _b.label = 2;
3547
+ case 2:
3548
+ // @link https://github.com/palantir/tslint/issues/4653
3549
+ // @link https://github.com/Microsoft/TypeScript/issues/13376#issuecomment-273289748
3550
+ void toDataURL(URL.createObjectURL(file), 'image/webp', uploadCallback);
3551
+ return [2 /*return*/];
3552
+ }
3553
+ });
3554
+ }); })();
3555
+ });
3556
+ return [2 /*return*/];
3521
3557
  });
3522
- }
3558
+ });
3523
3559
  }
3524
3560
  // dataUriEncoded is the base64 encoded string which is posted in column post_content
3525
3561
  function uploadImage(uploadCallback) {
@@ -3534,7 +3570,7 @@ function uploadImage(uploadCallback) {
3534
3570
  // safari also requires addEventListener rather than .onChange
3535
3571
  input.addEventListener('change', function (e) {
3536
3572
  console.log('upload image event', e);
3537
- uploadImageChange(e, uploadCallback);
3573
+ void uploadImageChange(e, uploadCallback);
3538
3574
  });
3539
3575
  input.click();
3540
3576
  };
@@ -3604,7 +3640,7 @@ exports.scrollIntoView = ScrollIntoViewDirective;
3604
3640
  exports.setCookies = setCookies;
3605
3641
  exports.setUrl = setUrl;
3606
3642
  exports.toDataURL = toDataURL;
3607
- exports.updateRestfulObjectArrays = updateRestfulObjectArray;
3643
+ exports.updateRestfulObjectArrays = updateRestfulObjectArrays;
3608
3644
  exports.uploadImage = uploadImage;
3609
3645
  exports.uploadImageChange = uploadImageChange;
3610
3646
  exports.user_followers = user_followers;