@carbonorm/carbonreact 2.0.1 → 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.
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useState, useEffect } from 'react';
1
+ import React, { lazy, useState, useEffect } from 'react';
2
2
  import { toastOptions, clearCache, isTest, isVerbose } from '@carbonorm/carbonnode';
3
3
  import { useNavigate, BrowserRouter } from 'react-router-dom';
4
4
  import { toast, ToastContainer } from 'react-toastify';
@@ -2779,13 +2779,13 @@ var initialRequiredCarbonORMState = {
2779
2779
  websocketData: [],
2780
2780
  websocketEvents: [],
2781
2781
  };
2782
- var initialCarbonORMState = __assign(__assign({}, initialRequiredCarbonORMState), initialRestfulObjectsState);
2782
+ var initialCarbonReactState = __assign(__assign({}, initialRequiredCarbonORMState), initialRestfulObjectsState);
2783
2783
  var CarbonReact = /** @class */ (function (_super) {
2784
2784
  __extends(CarbonReact, _super);
2785
2785
  function CarbonReact(props) {
2786
2786
  var _this = _super.call(this, props) || this;
2787
2787
  _this.websocketTimeout = 5000;
2788
- _this.state = initialCarbonORMState;
2788
+ _this.state = initialCarbonReactState;
2789
2789
  CarbonReact.instance = _this;
2790
2790
  // This should only ever be done here, when the full state is being trashed.
2791
2791
  clearCache({
@@ -3436,7 +3436,7 @@ var eUpdateInsertMethod;
3436
3436
  * @param callback - if you want to do something with the updated state, you can pass a callback here. Run as the second
3437
3437
  * parameter of setState.
3438
3438
  */
3439
- function updateRestfulObjectArray(dataOrCallback, stateKey, uniqueObjectId, insertUpdateOrder, callback) {
3439
+ function updateRestfulObjectArrays(dataOrCallback, stateKey, uniqueObjectId, insertUpdateOrder, callback) {
3440
3440
  if (insertUpdateOrder === void 0) { insertUpdateOrder = eUpdateInsertMethod.LAST; }
3441
3441
  var bootstrap = CarbonReact.instance;
3442
3442
  return bootstrap.setState(function (previousBootstrapState) {
@@ -3499,35 +3499,77 @@ function toDataURL(src, fileType, callback) {
3499
3499
  });
3500
3500
  }
3501
3501
  function uploadImageChange(event, uploadCallback) {
3502
- if (event.target.files !== null && event.target.files[0]) {
3503
- Object.keys(event.target.files).forEach(function (index) {
3504
- var _a;
3505
- var file = (_a = event.target.files) === null || _a === void 0 ? void 0 : _a[index];
3506
- // loop through all files and create data url then post to postPost
3507
- if (file.type.match('image.*')) {
3508
- // get file extension
3509
- var fileExtension = file.name.split('.').pop();
3510
- // check file extension is valid data uri
3511
- if (fileExtension !== 'jpg' && fileExtension !== 'jpeg' && fileExtension !== 'png' && fileExtension !== 'gif') {
3512
- toast.error('Please upload a valid image file type (jpg, jpeg, png, gif).');
3513
- return;
3514
- }
3515
- // @link https://github.com/palantir/tslint/issues/4653
3516
- // @link https://github.com/Microsoft/TypeScript/issues/13376#issuecomment-273289748
3517
- void toDataURL(URL.createObjectURL(file), file.type, uploadCallback);
3502
+ var _a, _b;
3503
+ return __awaiter(this, void 0, void 0, function () {
3504
+ var _this = this;
3505
+ return __generator(this, function (_c) {
3506
+ 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])) {
3507
+ toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic).');
3508
+ return [2 /*return*/];
3518
3509
  }
3510
+ Object.keys(event.target.files).forEach(function (index) {
3511
+ (function () { return __awaiter(_this, void 0, void 0, function () {
3512
+ var file, fileExtension, isHeic;
3513
+ var _a;
3514
+ return __generator(this, function (_b) {
3515
+ switch (_b.label) {
3516
+ case 0:
3517
+ file = (_a = event.target.files) === null || _a === void 0 ? void 0 : _a[index];
3518
+ // loop through all files and create data url then post to postPost
3519
+ if (false === file.type.match('image.*')) {
3520
+ toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic). (E_IMAGE_*<>' + file.type + ')');
3521
+ return [2 /*return*/];
3522
+ }
3523
+ fileExtension = file.name.split('.').pop();
3524
+ // check file extension is valid data uri
3525
+ if (fileExtension !== 'jpg'
3526
+ && fileExtension !== 'jpeg'
3527
+ && fileExtension !== 'heic'
3528
+ && fileExtension !== 'png'
3529
+ && fileExtension !== 'gif') {
3530
+ toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic). (E_IMAGE_EXT)');
3531
+ return [2 /*return*/];
3532
+ }
3533
+ isHeic = fileExtension === 'heic';
3534
+ if (!isHeic) return [3 /*break*/, 2];
3535
+ return [4 /*yield*/, lazy(function () { return require("heic2any"); })];
3536
+ case 1:
3537
+ // todo - this should be code split and lazy loaded, but doesn't work
3538
+ // look up code splitting, it could be an issue with rewired
3539
+ file = (_b.sent())({
3540
+ blob: file,
3541
+ toType: "image/webp",
3542
+ quality: 1.0, // 0.5 cuts the quality and size by half
3543
+ });
3544
+ _b.label = 2;
3545
+ case 2:
3546
+ // @link https://github.com/palantir/tslint/issues/4653
3547
+ // @link https://github.com/Microsoft/TypeScript/issues/13376#issuecomment-273289748
3548
+ void toDataURL(URL.createObjectURL(file), 'image/webp', uploadCallback);
3549
+ return [2 /*return*/];
3550
+ }
3551
+ });
3552
+ }); })();
3553
+ });
3554
+ return [2 /*return*/];
3519
3555
  });
3520
- }
3556
+ });
3521
3557
  }
3522
3558
  // dataUriEncoded is the base64 encoded string which is posted in column post_content
3523
3559
  function uploadImage(uploadCallback) {
3524
3560
  return function () {
3525
3561
  var input = document.createElement('input');
3526
3562
  input.type = 'file';
3527
- input.accept = 'image/*';
3528
- input.onchange = function (e) {
3529
- uploadImageChange(e, uploadCallback);
3530
- };
3563
+ input.accept = 'image/*, .heic';
3564
+ input.style.display = 'none';
3565
+ // the element must be appended to the document to work on safari
3566
+ // @link https://stackoverflow.com/questions/47664777/javascript-file-input-onchange-not-working-ios-safari-only
3567
+ document.body.appendChild(input);
3568
+ // safari also requires addEventListener rather than .onChange
3569
+ input.addEventListener('change', function (e) {
3570
+ console.log('upload image event', e);
3571
+ void uploadImageChange(e, uploadCallback);
3572
+ });
3531
3573
  input.click();
3532
3574
  };
3533
3575
  }
@@ -3551,5 +3593,5 @@ function useWindowDimensions() {
3551
3593
  return windowDimensions;
3552
3594
  }
3553
3595
 
3554
- export { AccessDenied, Alert, BackendThrowable, C6, COLUMNS, CarbonReact, ErrorHttpCode, GlobalHistory, HandleResponseCodes, Loading, Nest, PageNotFound, Popup, TABLES, addAlert, addValidSQL$1 as addValidSQL, axiosInstance, carbons, changed, comments, deleteRestfulObjectArrays, documentation, eUpdateInsertMethod, feature_group_references, features, getRootStyleValue, getStyles, globalNavigate, group_references, groups, hexToRgb, history_logs, initialCarbonORMState, initialRequiredCarbonORMState, initialRestfulObjectsState, isEdgeBrowser, isProduction, location_references, locations, parseMultipleJson, photos, range, reports, ScrollIntoViewDirective as scrollIntoView, setCookies, setUrl, toDataURL, updateRestfulObjectArray as updateRestfulObjectArrays, uploadImage, uploadImageChange, user_followers, user_groups, user_messages, user_sessions, user_tasks, users, useWindowDimensions as windowDimensions };
3596
+ export { AccessDenied, Alert, BackendThrowable, C6, COLUMNS, CarbonReact, ErrorHttpCode, GlobalHistory, HandleResponseCodes, Loading, Nest, PageNotFound, Popup, TABLES, addAlert, addValidSQL$1 as addValidSQL, axiosInstance, carbons, changed, comments, deleteRestfulObjectArrays, documentation, eUpdateInsertMethod, feature_group_references, features, getRootStyleValue, getStyles, globalNavigate, group_references, groups, hexToRgb, history_logs, initialCarbonReactState, initialRequiredCarbonORMState, initialRestfulObjectsState, isEdgeBrowser, isProduction, location_references, locations, parseMultipleJson, photos, range, reports, ScrollIntoViewDirective as scrollIntoView, setCookies, setUrl, toDataURL, updateRestfulObjectArrays, uploadImage, uploadImageChange, user_followers, user_groups, user_messages, user_sessions, user_tasks, users, useWindowDimensions as windowDimensions };
3555
3597
  //# sourceMappingURL=index.esm.js.map