@transferwise/components 46.39.0 → 46.40.0

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.
Files changed (123) hide show
  1. package/build/index.js +176 -419
  2. package/build/index.js.map +1 -1
  3. package/build/index.mjs +176 -419
  4. package/build/index.mjs.map +1 -1
  5. package/build/types/index.d.ts +2 -1
  6. package/build/types/index.d.ts.map +1 -1
  7. package/build/types/processIndicator/ProcessIndicator.d.ts +1 -1
  8. package/build/types/processIndicator/ProcessIndicator.d.ts.map +1 -1
  9. package/build/types/upload/Upload.d.ts +91 -55
  10. package/build/types/upload/Upload.d.ts.map +1 -1
  11. package/build/types/upload/Upload.messages.d.ts +42 -60
  12. package/build/types/upload/Upload.messages.d.ts.map +1 -1
  13. package/build/types/upload/index.d.ts +2 -2
  14. package/build/types/upload/index.d.ts.map +1 -1
  15. package/build/types/upload/steps/completeStep/completeStep.d.ts +11 -18
  16. package/build/types/upload/steps/completeStep/completeStep.d.ts.map +1 -1
  17. package/build/types/upload/steps/completeStep/index.d.ts +2 -1
  18. package/build/types/upload/steps/completeStep/index.d.ts.map +1 -1
  19. package/build/types/upload/steps/index.d.ts +3 -4
  20. package/build/types/upload/steps/index.d.ts.map +1 -1
  21. package/build/types/upload/steps/processingStep/index.d.ts +2 -1
  22. package/build/types/upload/steps/processingStep/index.d.ts.map +1 -1
  23. package/build/types/upload/steps/processingStep/processingStep.d.ts +11 -13
  24. package/build/types/upload/steps/processingStep/processingStep.d.ts.map +1 -1
  25. package/build/types/upload/steps/uploadImageStep/index.d.ts +2 -1
  26. package/build/types/upload/steps/uploadImageStep/index.d.ts.map +1 -1
  27. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts +14 -18
  28. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts.map +1 -1
  29. package/build/types/upload/utils/asyncFileRead/asyncFileRead.d.ts +1 -1
  30. package/build/types/upload/utils/asyncFileRead/asyncFileRead.d.ts.map +1 -1
  31. package/build/types/upload/utils/asyncFileRead/index.d.ts +1 -1
  32. package/build/types/upload/utils/asyncFileRead/index.d.ts.map +1 -1
  33. package/build/types/upload/utils/getFileType/getFileType.d.ts +1 -1
  34. package/build/types/upload/utils/getFileType/getFileType.d.ts.map +1 -1
  35. package/build/types/upload/utils/getFileType/index.d.ts +1 -1
  36. package/build/types/upload/utils/getFileType/index.d.ts.map +1 -1
  37. package/build/types/upload/utils/index.d.ts +5 -7
  38. package/build/types/upload/utils/index.d.ts.map +1 -1
  39. package/build/types/upload/utils/isSizeValid/index.d.ts +1 -1
  40. package/build/types/upload/utils/isSizeValid/index.d.ts.map +1 -1
  41. package/build/types/upload/utils/isSizeValid/isSizeValid.d.ts +1 -1
  42. package/build/types/upload/utils/isSizeValid/isSizeValid.d.ts.map +1 -1
  43. package/build/types/upload/utils/isTypeValid/index.d.ts +1 -1
  44. package/build/types/upload/utils/isTypeValid/index.d.ts.map +1 -1
  45. package/build/types/upload/utils/isTypeValid/isTypeValid.d.ts +1 -1
  46. package/build/types/upload/utils/isTypeValid/isTypeValid.d.ts.map +1 -1
  47. package/build/types/upload/utils/postData/index.d.ts +1 -1
  48. package/build/types/upload/utils/postData/index.d.ts.map +1 -1
  49. package/build/types/upload/utils/postData/postData.d.ts +11 -1
  50. package/build/types/upload/utils/postData/postData.d.ts.map +1 -1
  51. package/package.json +3 -3
  52. package/src/index.ts +2 -1
  53. package/src/processIndicator/ProcessIndicator.tsx +1 -1
  54. package/src/upload/Upload.spec.js +3 -14
  55. package/src/upload/Upload.story.tsx +37 -0
  56. package/src/upload/{Upload.js → Upload.tsx} +164 -169
  57. package/src/upload/index.ts +2 -0
  58. package/src/upload/steps/completeStep/completeStep.spec.js +3 -2
  59. package/src/upload/steps/completeStep/completeStep.tsx +74 -0
  60. package/src/upload/steps/completeStep/index.ts +2 -0
  61. package/src/upload/steps/{index.js → index.ts} +0 -1
  62. package/src/upload/steps/processingStep/index.ts +2 -0
  63. package/src/upload/steps/processingStep/processingStep.tsx +53 -0
  64. package/src/upload/steps/uploadImageStep/index.ts +2 -0
  65. package/src/upload/steps/uploadImageStep/{uploadImageStep.js → uploadImageStep.tsx} +17 -23
  66. package/src/upload/utils/asyncFileRead/asyncFileRead.spec.ts +14 -0
  67. package/src/upload/utils/asyncFileRead/asyncFileRead.ts +12 -0
  68. package/src/upload/utils/getFileType/getFileType.spec.ts +22 -0
  69. package/src/upload/utils/getFileType/getFileType.ts +16 -0
  70. package/src/upload/utils/{index.js → index.ts} +0 -2
  71. package/src/upload/utils/isSizeValid/{isSizeValid.spec.js → isSizeValid.spec.ts} +3 -3
  72. package/src/upload/utils/isSizeValid/isSizeValid.ts +3 -0
  73. package/src/upload/utils/isTypeValid/isTypeValid.spec.ts +62 -0
  74. package/src/upload/utils/isTypeValid/isTypeValid.ts +19 -0
  75. package/src/upload/utils/postData/postData.spec.ts +65 -0
  76. package/src/upload/utils/postData/postData.ts +36 -0
  77. package/src/uploadInput/UploadInput.tsx +1 -1
  78. package/build/types/upload/steps/mediaUploadStep/index.d.ts +0 -2
  79. package/build/types/upload/steps/mediaUploadStep/index.d.ts.map +0 -1
  80. package/build/types/upload/steps/mediaUploadStep/mediaUploadStep.d.ts +0 -24
  81. package/build/types/upload/steps/mediaUploadStep/mediaUploadStep.d.ts.map +0 -1
  82. package/build/types/upload/uploadSteps.d.ts +0 -5
  83. package/build/types/upload/uploadSteps.d.ts.map +0 -1
  84. package/build/types/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.d.ts +0 -2
  85. package/build/types/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.d.ts.map +0 -1
  86. package/build/types/upload/utils/getSupportedSpotMimeTypes/index.d.ts +0 -2
  87. package/build/types/upload/utils/getSupportedSpotMimeTypes/index.d.ts.map +0 -1
  88. package/build/types/upload/utils/requestMedia/index.d.ts +0 -2
  89. package/build/types/upload/utils/requestMedia/index.d.ts.map +0 -1
  90. package/build/types/upload/utils/requestMedia/requestMedia.d.ts +0 -2
  91. package/build/types/upload/utils/requestMedia/requestMedia.d.ts.map +0 -1
  92. package/src/upload/Upload.story.js +0 -36
  93. package/src/upload/index.js +0 -2
  94. package/src/upload/steps/completeStep/completeStep.js +0 -98
  95. package/src/upload/steps/completeStep/index.js +0 -1
  96. package/src/upload/steps/mediaUploadStep/index.js +0 -1
  97. package/src/upload/steps/mediaUploadStep/mediaUploadStep.js +0 -80
  98. package/src/upload/steps/mediaUploadStep/mediaUploadStep.spec.js +0 -77
  99. package/src/upload/steps/processingStep/index.js +0 -1
  100. package/src/upload/steps/processingStep/processingStep.js +0 -73
  101. package/src/upload/steps/uploadImageStep/index.js +0 -1
  102. package/src/upload/uploadSteps.ts +0 -5
  103. package/src/upload/utils/asyncFileRead/asyncFileRead.js +0 -11
  104. package/src/upload/utils/asyncFileRead/asyncFileRead.spec.js +0 -17
  105. package/src/upload/utils/getFileType/getFileType.js +0 -19
  106. package/src/upload/utils/getFileType/getFileType.spec.js +0 -33
  107. package/src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.js +0 -18
  108. package/src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.spec.js +0 -22
  109. package/src/upload/utils/getSupportedSpotMimeTypes/index.js +0 -1
  110. package/src/upload/utils/isSizeValid/isSizeValid.js +0 -1
  111. package/src/upload/utils/isTypeValid/isTypeValid.js +0 -26
  112. package/src/upload/utils/isTypeValid/isTypeValid.spec.js +0 -68
  113. package/src/upload/utils/postData/postData.js +0 -18
  114. package/src/upload/utils/postData/postData.spec.js +0 -109
  115. package/src/upload/utils/requestMedia/index.js +0 -1
  116. package/src/upload/utils/requestMedia/requestMedia.js +0 -26
  117. package/src/upload/utils/requestMedia/requestMedia.spec.js +0 -44
  118. /package/src/upload/{Upload.messages.js → Upload.messages.ts} +0 -0
  119. /package/src/upload/utils/asyncFileRead/{index.js → index.ts} +0 -0
  120. /package/src/upload/utils/getFileType/{index.js → index.ts} +0 -0
  121. /package/src/upload/utils/isSizeValid/{index.js → index.ts} +0 -0
  122. /package/src/upload/utils/isTypeValid/{index.js → index.ts} +0 -0
  123. /package/src/upload/utils/postData/{index.js → index.ts} +0 -0
package/build/index.js CHANGED
@@ -12088,13 +12088,6 @@ var Typeahead$1 = withInputAttributes(Typeahead, {
12088
12088
  nonLabelable: true
12089
12089
  });
12090
12090
 
12091
- // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
12092
- exports.UploadStep = void 0;
12093
- (function (UploadStep) {
12094
- UploadStep["UPLOAD_IMAGE_STEP"] = "uploadImageStep";
12095
- UploadStep["MEDIA_UPLOAD_STEP"] = "mediaUploadStep";
12096
- })(exports.UploadStep || (exports.UploadStep = {}));
12097
-
12098
12091
  var messages = reactIntl.defineMessages({
12099
12092
  csButtonText: {
12100
12093
  id: "neptune.Upload.csButtonText"
@@ -12129,16 +12122,13 @@ var messages = reactIntl.defineMessages({
12129
12122
  });
12130
12123
 
12131
12124
  class UploadImageStep extends React.PureComponent {
12132
- constructor() {
12133
- super();
12134
- this.uploadInputRef = /*#__PURE__*/React.createRef();
12135
- }
12125
+ uploadInputRef = /*#__PURE__*/React.createRef();
12136
12126
  onManualUpload = () => {
12137
12127
  const {
12138
12128
  fileDropped
12139
12129
  } = this.props;
12140
- if (this.uploadInputRef && this.uploadInputRef.current) {
12141
- const file = this.uploadInputRef.current.files[0];
12130
+ const file = this.uploadInputRef.current?.files?.[0];
12131
+ if (file != null) {
12142
12132
  fileDropped(file);
12143
12133
  }
12144
12134
  };
@@ -12187,7 +12177,7 @@ class UploadImageStep extends React.PureComponent {
12187
12177
  children: usLabel
12188
12178
  }), usPlaceholder && /*#__PURE__*/jsxRuntime.jsx("p", {
12189
12179
  className: "np-text-body-large m-b-3",
12190
- children: `${usPlaceholder}`
12180
+ children: String(usPlaceholder)
12191
12181
  }), /*#__PURE__*/jsxRuntime.jsxs("label", {
12192
12182
  className: `btn btn-primary btn-md ${usDisabled ? 'disabled' : ''}`,
12193
12183
  children: [usButtonText ? /*#__PURE__*/jsxRuntime.jsx("span", {
@@ -12198,7 +12188,7 @@ class UploadImageStep extends React.PureComponent {
12198
12188
  }), /*#__PURE__*/jsxRuntime.jsx("input", {
12199
12189
  ref: this.uploadInputRef,
12200
12190
  type: "file",
12201
- accept: usAccept === '*' ? null : usAccept,
12191
+ accept: usAccept === '*' ? undefined : usAccept,
12202
12192
  className: "tw-droppable-input hidden",
12203
12193
  disabled: usDisabled,
12204
12194
  name: "file-upload",
@@ -12210,213 +12200,17 @@ class UploadImageStep extends React.PureComponent {
12210
12200
  });
12211
12201
  }
12212
12202
  }
12213
- UploadImageStep.propTypes = {
12214
- fileDropped: PropTypes__default.default.func.isRequired,
12215
- isComplete: PropTypes__default.default.bool.isRequired,
12216
- usAccept: PropTypes__default.default.string.isRequired,
12217
- usButtonText: PropTypes__default.default.string.isRequired,
12218
- usDisabled: PropTypes__default.default.bool.isRequired,
12219
- usHelpImage: PropTypes__default.default.node.isRequired,
12220
- usLabel: PropTypes__default.default.string.isRequired,
12221
- usPlaceholder: PropTypes__default.default.string.isRequired
12222
- };
12223
-
12224
- const postData = (httpOptions, data = {}, fetcher = fetch) => fetcher(`${httpOptions.url}`, {
12225
- method: 'POST',
12226
- body: data,
12227
- ...httpOptions
12228
- }).then(response => {
12229
- if (!response.ok) {
12230
- const error = new Error(response.statusText);
12231
- error.status = response.status;
12232
- error.response = response;
12233
- throw error;
12234
- }
12235
- return response;
12236
- }).catch(error => {
12237
- throw error;
12238
- });
12239
-
12240
- const asyncFileRead = file => new Promise((resolve, reject) => {
12241
- const reader = new FileReader();
12242
- reader.readAsDataURL(file);
12243
- reader.addEventListener('load', event => {
12244
- resolve(event.target.result);
12245
- });
12246
- reader.addEventListener('error', event => {
12247
- reject(event);
12248
- });
12249
- });
12250
-
12251
- const isSizeValid = (file, maxSize) => Number.isInteger(maxSize) && file.size <= maxSize;
12252
-
12253
- const getFileType = (file, file64) => {
12254
- if (!file && !file64) {
12255
- return '';
12256
- }
12257
- if (file && file.type && file.type !== '') {
12258
- return file.type ?? '';
12259
- }
12260
- if (file64) {
12261
- const regex = /^data:([a-z]+\/[a-z]+);/;
12262
- const typeFromEncoded = file64.match(regex);
12263
- if (typeFromEncoded && typeFromEncoded[1]) {
12264
- return typeFromEncoded[1] ?? '';
12265
- }
12266
- }
12267
- return '';
12268
- };
12269
-
12270
- const isTypeValid = (file, rule, file64) => {
12271
- if (!file || !rule) {
12272
- return false;
12273
- }
12274
- const allowedTypes = rule.replace(/\s/g, '').split(',');
12275
- const fileType = getFileType(file, file64);
12276
- if (rule === '*' || allowedTypes.includes(fileType)) {
12277
- return true;
12278
- }
12279
- return allowedTypes.some(type => {
12280
- const splittedRule = type.split('/');
12281
- const typeAllowed = splittedRule[0];
12282
- const extensionAllowed = splittedRule[1];
12283
- if (extensionAllowed !== '*') {
12284
- return false;
12285
- }
12286
- return fileType.includes(typeAllowed);
12287
- });
12288
- };
12289
-
12290
- // Spot Platform's Media API only support these MIME types
12291
- const SUPPORTED_MIME_TYPES = ['image/jpeg', 'video/*', 'application/pdf'];
12292
- const getSupportedSpotMimeTypes = mimeTypes => {
12293
- if (mimeTypes === '*') {
12294
- return SUPPORTED_MIME_TYPES;
12295
- }
12296
- const mimeTypesArray = mimeTypes.split(',');
12297
- const mimeMapping = {
12298
- 'image/*': 'image/jpeg',
12299
- 'application/*': 'application/pdf'
12300
- };
12301
- const mapSupportedMimeTypes = mimeTypesArray.map(type => mimeMapping[type] || type);
12302
- return mapSupportedMimeTypes.filter(type => SUPPORTED_MIME_TYPES.includes(type));
12303
- };
12304
12203
 
12305
- const requestMedia = mediaRequest => new Promise((resolve, reject) => {
12306
- if (typeof window === 'undefined' || typeof window.microapps === 'undefined') {
12307
- reject(`microapps must be available in window to use Spot Platform's Media API`);
12308
- }
12309
- window.microapps.requestMedia(mediaRequest).then(response => {
12310
- const fileByteArray = base64ToByteArray(response.bytes);
12311
- const blob = new Blob([fileByteArray], {
12312
- type: response.mimeType
12313
- });
12314
- resolve(blob);
12315
- }).catch(error => reject(error));
12316
- });
12317
- const base64ToByteArray = base64String => {
12318
- const byteCharacters = atob(base64String);
12319
- const byteCharactersLength = byteCharacters.length;
12320
- const byteArray = new Array(byteCharactersLength);
12321
- for (let i = 0; i < byteCharactersLength; i += 1) {
12322
- byteArray[i] = byteCharacters.charCodeAt(i);
12323
- }
12324
- return new Uint8Array(byteArray);
12325
- };
12326
-
12327
- const MediaUploadStep = ({
12204
+ function ProcessingStep({
12328
12205
  isComplete,
12329
- usAccept,
12330
- usButtonText,
12331
- usDisabled,
12332
- usHelpImage,
12333
- usLabel,
12334
- usPlaceholder,
12335
- fileDropped
12336
- }) => {
12337
- const getMediaFile = () => {
12338
- const allowedMimeTypes = getSupportedSpotMimeTypes(usAccept);
12339
- if (allowedMimeTypes.length === 0) {
12340
- throw new Error('provided mimeTypes not supported');
12341
- }
12342
- const mediaRequest = {
12343
- allowedMimeTypes
12344
- };
12345
- requestMedia(mediaRequest).then(file => fileDropped(file));
12346
- };
12347
- const getImage = () => {
12348
- if (!usHelpImage) {
12349
- return /*#__PURE__*/jsxRuntime.jsx("div", {
12350
- className: "circle circle-sm circle-inverse p-t-1",
12351
- children: /*#__PURE__*/jsxRuntime.jsx(icons.Upload, {
12352
- size: 24
12353
- })
12354
- });
12355
- }
12356
- if (typeof usHelpImage === 'string') {
12357
- return /*#__PURE__*/jsxRuntime.jsx("img", {
12358
- src: usHelpImage,
12359
- alt: usLabel,
12360
- className: "thumbnail text-xs-center"
12361
- });
12362
- }
12363
- return usHelpImage;
12364
- };
12365
- return /*#__PURE__*/jsxRuntime.jsx("div", {
12366
- children: /*#__PURE__*/jsxRuntime.jsx("div", {
12367
- className: "droppable-default-card",
12368
- "aria-hidden": isComplete,
12369
- children: /*#__PURE__*/jsxRuntime.jsxs("div", {
12370
- className: "droppable-card-content",
12371
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
12372
- className: "m-b-3",
12373
- children: getImage()
12374
- }), usLabel && /*#__PURE__*/jsxRuntime.jsx(Title, {
12375
- type: exports.Typography.TITLE_BODY,
12376
- className: "m-b-1",
12377
- children: usLabel
12378
- }), usPlaceholder && /*#__PURE__*/jsxRuntime.jsx(Body, {
12379
- as: "p",
12380
- type: exports.Typography.BODY_LARGE,
12381
- className: "m-b-3",
12382
- children: `${usPlaceholder}`
12383
- }), /*#__PURE__*/jsxRuntime.jsx(Button, {
12384
- disabled: usDisabled,
12385
- onClick: getMediaFile,
12386
- children: usButtonText || /*#__PURE__*/jsxRuntime.jsx(icons.Upload, {
12387
- size: 24,
12388
- className: "m-r-0"
12389
- })
12390
- })]
12391
- })
12392
- })
12393
- });
12394
- };
12395
- MediaUploadStep.propTypes = {
12396
- fileDropped: PropTypes__default.default.func.isRequired,
12397
- isComplete: PropTypes__default.default.bool.isRequired,
12398
- usAccept: PropTypes__default.default.string.isRequired,
12399
- usButtonText: PropTypes__default.default.string.isRequired,
12400
- usDisabled: PropTypes__default.default.bool.isRequired,
12401
- usHelpImage: PropTypes__default.default.node.isRequired,
12402
- usLabel: PropTypes__default.default.string.isRequired,
12403
- usPlaceholder: PropTypes__default.default.string.isRequired
12404
- };
12405
-
12406
- const ProcessingStep = props => {
12407
- const {
12408
- isComplete,
12409
- isError,
12410
- isSuccess,
12411
- onAnimationCompleted,
12412
- onClear,
12413
- psButtonText,
12414
- psProcessingText,
12415
- psButtonDisabled
12416
- } = props;
12417
- const {
12418
- isModern
12419
- } = componentsTheming.useTheme();
12206
+ isError,
12207
+ isSuccess,
12208
+ onAnimationCompleted,
12209
+ onClear,
12210
+ psButtonText,
12211
+ psProcessingText,
12212
+ psButtonDisabled
12213
+ }) {
12420
12214
  let processStatus = exports.Status.PROCESSING;
12421
12215
  if (isError) {
12422
12216
  processStatus = exports.Status.FAILED;
@@ -12430,53 +12224,33 @@ const ProcessingStep = props => {
12430
12224
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
12431
12225
  className: "droppable-card-content",
12432
12226
  children: [/*#__PURE__*/jsxRuntime.jsx(ProcessIndicator, {
12433
- size: exports.Size.Small,
12434
12227
  status: processStatus,
12435
12228
  onAnimationCompleted: status => onAnimationCompleted(status)
12436
12229
  }), /*#__PURE__*/jsxRuntime.jsx(Title, {
12437
- className: classNames__default.default({
12438
- 'm-t-3': !isModern,
12439
- 'm-b-3': !isModern,
12440
- 'm-t-2': isModern,
12441
- 'm-b-2': isModern
12442
- }),
12230
+ className: "m-y-2",
12443
12231
  type: exports.Typography.TITLE_BODY,
12444
12232
  "aria-live": "polite",
12445
12233
  children: psProcessingText
12446
12234
  }), psButtonText && /*#__PURE__*/jsxRuntime.jsx(Button, {
12447
12235
  disabled: psButtonDisabled,
12448
- onClick: event => onClear(event),
12236
+ onClick: onClear,
12449
12237
  children: psButtonText
12450
12238
  })]
12451
12239
  })
12452
12240
  });
12453
- };
12454
- ProcessingStep.propTypes = {
12455
- isComplete: PropTypes__default.default.bool.isRequired,
12456
- isError: PropTypes__default.default.bool.isRequired,
12457
- isSuccess: PropTypes__default.default.bool.isRequired,
12458
- onAnimationCompleted: PropTypes__default.default.func.isRequired,
12459
- onClear: PropTypes__default.default.func.isRequired,
12460
- psButtonText: PropTypes__default.default.string.isRequired,
12461
- psProcessingText: PropTypes__default.default.string.isRequired,
12462
- psButtonDisabled: PropTypes__default.default.bool.isRequired
12463
- };
12241
+ }
12464
12242
 
12465
- const CompleteStep = props => {
12466
- const {
12467
- isModern
12468
- } = componentsTheming.useTheme();
12469
- const {
12470
- csButtonText,
12471
- csFailureText,
12472
- csSuccessText,
12473
- fileName,
12474
- isComplete,
12475
- isError,
12476
- isImage,
12477
- onClear,
12478
- uploadedImage
12479
- } = props;
12243
+ function CompleteStep({
12244
+ csButtonText,
12245
+ csFailureText,
12246
+ csSuccessText,
12247
+ fileName,
12248
+ isComplete,
12249
+ isError,
12250
+ isImage,
12251
+ onClear,
12252
+ uploadedImage
12253
+ }) {
12480
12254
  return /*#__PURE__*/jsxRuntime.jsx("div", {
12481
12255
  className: "droppable-complete-card droppable-card",
12482
12256
  "aria-hidden": !isComplete,
@@ -12486,16 +12260,11 @@ const CompleteStep = props => {
12486
12260
  className: "droppable-card-content d-flex flex-column align-items-center",
12487
12261
  "aria-live": "polite",
12488
12262
  children: isError ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
12489
- children: [isModern ? /*#__PURE__*/jsxRuntime.jsx(StatusIcon, {
12263
+ children: [/*#__PURE__*/jsxRuntime.jsx(StatusIcon, {
12490
12264
  size: exports.Size.LARGE,
12491
12265
  sentiment: exports.Sentiment.NEGATIVE
12492
- }) : /*#__PURE__*/jsxRuntime.jsx(icons.AlertCircle, {
12493
- size: 24,
12494
- className: "text-negative"
12495
12266
  }), csFailureText && /*#__PURE__*/jsxRuntime.jsx("p", {
12496
- className: classNames__default.default('m-t-2', {
12497
- 'm-b-0': isModern
12498
- }),
12267
+ className: "m-t-2 m-b-0",
12499
12268
  children: csFailureText
12500
12269
  })]
12501
12270
  }) : /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
@@ -12514,71 +12283,135 @@ const CompleteStep = props => {
12514
12283
  })]
12515
12284
  })
12516
12285
  }), csButtonText && /*#__PURE__*/jsxRuntime.jsx(Button, {
12517
- priority: isModern ? exports.Priority.PRIMARY : exports.Priority.SECONDARY,
12518
- className: classNames__default.default({
12519
- 'm-t-1': isModern && !isError,
12520
- 'm-t-2': isModern && isError,
12521
- 'm-t-3': !isModern
12522
- }),
12523
- onClick: event => onClear(event),
12286
+ className: isError ? 'm-t-2' : 'm-t-1',
12287
+ onClick: onClear,
12524
12288
  children: csButtonText
12525
12289
  })]
12526
12290
  })
12527
12291
  });
12528
- };
12529
- CompleteStep.propTypes = {
12530
- csButtonText: PropTypes__default.default.string.isRequired,
12531
- csSuccessText: PropTypes__default.default.string.isRequired,
12532
- csFailureText: PropTypes__default.default.string.isRequired,
12533
- fileName: PropTypes__default.default.string.isRequired,
12534
- isComplete: PropTypes__default.default.bool.isRequired,
12535
- isError: PropTypes__default.default.bool.isRequired,
12536
- isImage: PropTypes__default.default.bool.isRequired,
12537
- onClear: PropTypes__default.default.func.isRequired,
12538
- uploadedImage: PropTypes__default.default.string
12539
- };
12540
- CompleteStep.defaultProps = {
12541
- uploadedImage: null
12542
- };
12292
+ }
12543
12293
 
12544
- const PROCESS_STATE = ['error', 'success'];
12294
+ class ResponseError extends Error {
12295
+ response;
12296
+ status;
12297
+ constructor(response, message) {
12298
+ super(message);
12299
+ this.name = 'ResponseError';
12300
+ this.response = response;
12301
+ this.status = response.status;
12302
+ }
12303
+ }
12304
+ async function postData({
12305
+ url,
12306
+ method = 'POST',
12307
+ ...httpOptions
12308
+ }, data, fetcher = fetch) {
12309
+ const response = await fetcher(url, {
12310
+ method,
12311
+ body: data,
12312
+ ...httpOptions
12313
+ });
12314
+ if (!response.ok) {
12315
+ throw new ResponseError(response, response.statusText);
12316
+ }
12317
+ return response;
12318
+ }
12319
+
12320
+ async function asyncFileRead(file) {
12321
+ return new Promise((resolve, reject) => {
12322
+ const reader = new FileReader();
12323
+ reader.addEventListener('load', () => {
12324
+ resolve(reader.result);
12325
+ });
12326
+ reader.addEventListener('error', () => {
12327
+ reject(reader.error ?? new Error('Cannot read file'));
12328
+ });
12329
+ reader.readAsDataURL(file);
12330
+ });
12331
+ }
12332
+
12333
+ function isSizeValid(file, maxSize) {
12334
+ return Number.isInteger(maxSize) && file.size <= maxSize;
12335
+ }
12336
+
12337
+ function getFileType(file, file64) {
12338
+ if (file.type) {
12339
+ return file.type;
12340
+ }
12341
+ if (file64) {
12342
+ const regex = /^data:([a-z]+\/[a-z]+);/;
12343
+ const typeFromEncoded = regex.exec(file64);
12344
+ if (typeFromEncoded?.[1]) {
12345
+ return typeFromEncoded[1];
12346
+ }
12347
+ }
12348
+ return '';
12349
+ }
12350
+
12351
+ function isTypeValid(file, rule, file64) {
12352
+ if (!rule) {
12353
+ return false;
12354
+ }
12355
+ const allowedTypes = rule.replace(/\s/g, '').split(',');
12356
+ const fileType = getFileType(file, file64);
12357
+ if (rule === '*' || allowedTypes.includes(fileType)) {
12358
+ return true;
12359
+ }
12360
+ return allowedTypes.some(type => {
12361
+ const [typeAllowed, extensionAllowed] = type.split('/');
12362
+ return extensionAllowed === '*' && fileType.includes(typeAllowed);
12363
+ });
12364
+ }
12545
12365
 
12546
- /*
12547
- * This delay is required for the isError/isSuccess to be fired after isProcessing so the processIndicator, will be
12548
- * rendered first and then updated with the right status.
12549
- */
12550
12366
  const ANIMATION_FIX = 10;
12551
12367
  const MAX_SIZE_DEFAULT = 5000000;
12552
- const UPLOAD_STEP_COMPONENTS = {
12553
- [exports.UploadStep.UPLOAD_IMAGE_STEP]: UploadImageStep,
12554
- [exports.UploadStep.MEDIA_UPLOAD_STEP]: MediaUploadStep
12555
- };
12368
+ exports.UploadStep = void 0;
12369
+ (function (UploadStep) {
12370
+ UploadStep["UPLOAD_IMAGE_STEP"] = "uploadImageStep";
12371
+ })(exports.UploadStep || (exports.UploadStep = {}));
12556
12372
  class Upload extends React.Component {
12373
+ static defaultProps = {
12374
+ animationDelay: 700,
12375
+ maxSize: MAX_SIZE_DEFAULT,
12376
+ psButtonDisabled: false,
12377
+ size: 'md',
12378
+ usAccept: 'image/*',
12379
+ usDisabled: false,
12380
+ usLabel: ''
12381
+ };
12382
+ dragCounter = 0;
12383
+ timeouts = 0;
12557
12384
  constructor(props) {
12558
12385
  super(props);
12559
- this.dragCounter = 0;
12560
- this.timeouts = null;
12561
12386
  this.state = {
12562
12387
  fileName: '',
12388
+ isDroppable: false,
12563
12389
  isComplete: false,
12564
12390
  isError: false,
12565
12391
  isImage: false,
12566
12392
  isProcessing: false,
12567
12393
  isSuccess: false,
12568
- response: null,
12569
- uploadedImage: null
12394
+ response: undefined,
12395
+ uploadedImage: undefined
12570
12396
  };
12571
12397
  }
12572
12398
  getErrorMessage(status) {
12399
+ const {
12400
+ csFailureText,
12401
+ csTooLargeMessage,
12402
+ csWrongTypeMessage,
12403
+ maxSize,
12404
+ intl
12405
+ } = this.props;
12573
12406
  switch (status) {
12574
12407
  case 413:
12575
- return this.props.csTooLargeMessage || this.props.intl.formatMessage(messages.csTooLargeMessage, {
12576
- maxSize: this.props.maxSize / 1000000
12408
+ return csTooLargeMessage || intl.formatMessage(messages.csTooLargeMessage, {
12409
+ maxSize: maxSize / 1000000
12577
12410
  });
12578
12411
  case 415:
12579
- return this.props.csWrongTypeMessage || this.props.intl.formatMessage(messages.csWrongTypeMessage);
12412
+ return csWrongTypeMessage || intl.formatMessage(messages.csWrongTypeMessage);
12580
12413
  default:
12581
- return this.props.csFailureText || this.props.intl.formatMessage(messages.csFailureText);
12414
+ return csFailureText || intl.formatMessage(messages.csFailureText);
12582
12415
  }
12583
12416
  }
12584
12417
  onDragLeave(event) {
@@ -12605,7 +12438,7 @@ class Upload extends React.Component {
12605
12438
  });
12606
12439
  }
12607
12440
  }
12608
- onDrop(event) {
12441
+ async onDrop(event) {
12609
12442
  const {
12610
12443
  isProcessing
12611
12444
  } = this.state;
@@ -12613,8 +12446,8 @@ class Upload extends React.Component {
12613
12446
  if (!isProcessing) {
12614
12447
  this.reset();
12615
12448
  }
12616
- if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {
12617
- this.fileDropped(event.dataTransfer.files[0]);
12449
+ if (event.dataTransfer?.files?.[0]) {
12450
+ await this.fileDropped(event.dataTransfer.files[0]);
12618
12451
  }
12619
12452
  }
12620
12453
  onAnimationCompleted = async status => {
@@ -12623,77 +12456,70 @@ class Upload extends React.Component {
12623
12456
  isProcessing,
12624
12457
  fileName
12625
12458
  } = this.state;
12626
- // Success.
12627
12459
  const {
12628
12460
  animationDelay
12629
12461
  } = this.props;
12630
- if (isProcessing && status === exports.Status.SUCCEEDED) {
12462
+ if (isProcessing && status === 'succeeded') {
12631
12463
  const {
12632
12464
  onSuccess
12633
12465
  } = this.props;
12634
- this.timeouts = setTimeout(() => {
12466
+ this.timeouts = window.setTimeout(() => {
12635
12467
  this.setState({
12636
12468
  isProcessing: false,
12637
12469
  isComplete: true
12638
- }, () => onSuccess ? onSuccess(response, fileName) : {});
12470
+ }, onSuccess ? () => onSuccess(response, fileName) : undefined);
12639
12471
  }, animationDelay);
12640
12472
  }
12641
- // Failure.
12642
- if (isProcessing && status === exports.Status.FAILED) {
12473
+ if (isProcessing && status === 'failed') {
12643
12474
  const {
12644
12475
  onFailure
12645
12476
  } = this.props;
12646
- this.timeouts = setTimeout(() => {
12477
+ this.timeouts = window.setTimeout(() => {
12647
12478
  this.setState({
12648
12479
  isProcessing: false,
12649
12480
  isComplete: true
12650
- }, () => onFailure ? onFailure(response) : {});
12481
+ }, onFailure ? () => onFailure(response) : undefined);
12651
12482
  }, animationDelay);
12652
12483
  }
12653
12484
  };
12654
- asyncPost = file => {
12485
+ asyncPost = async file => {
12655
12486
  const {
12656
12487
  httpOptions,
12657
12488
  fetcher
12658
12489
  } = this.props;
12490
+ if (httpOptions == null) {
12491
+ throw new Error('Cannot find HTTP options');
12492
+ }
12659
12493
  const {
12660
12494
  fileInputName = file.name,
12661
12495
  data = {}
12662
- } = httpOptions || {};
12496
+ } = httpOptions;
12663
12497
  const formData = new FormData();
12664
12498
  formData.append(fileInputName, file);
12665
12499
  Object.keys(data).forEach(key => formData.append(key, data[key]));
12666
- return postData(this.prepareHttpOptions(httpOptions), formData, fetcher);
12500
+ return postData(httpOptions, formData, fetcher);
12667
12501
  };
12668
12502
  asyncResponse = (response, type) => {
12669
12503
  // Gives time to the animation callback to fire.
12670
- this.timeouts = setTimeout(() => {
12504
+ this.timeouts = window.setTimeout(() => {
12671
12505
  this.setState({
12672
12506
  response,
12673
- isError: type === PROCESS_STATE[0],
12674
- isSuccess: type === PROCESS_STATE[1]
12507
+ isError: type === 'error',
12508
+ isSuccess: type === 'success'
12675
12509
  });
12676
12510
  }, ANIMATION_FIX);
12677
12511
  };
12678
- prepareHttpOptions = httpOptions => {
12679
- if (!httpOptions.url) {
12680
- throw new Error('You must supply a URL to post image data asynchronously');
12681
- }
12682
- return httpOptions;
12683
- };
12684
12512
  handleOnClear = event => {
12685
12513
  event.preventDefault();
12686
12514
  const {
12687
12515
  onCancel
12688
12516
  } = this.props;
12689
- if (onCancel) {
12690
- onCancel();
12691
- }
12517
+ onCancel?.();
12692
12518
  this.reset();
12693
12519
  };
12694
12520
  reset = () => {
12695
12521
  this.dragCounter = 0;
12696
- clearTimeout(this.timeouts);
12522
+ window.clearTimeout(this.timeouts);
12697
12523
  this.setState({
12698
12524
  isComplete: false,
12699
12525
  isError: false,
@@ -12733,14 +12559,12 @@ class Upload extends React.Component {
12733
12559
  isDroppable: false,
12734
12560
  isProcessing: true
12735
12561
  });
12736
- if (onStart) {
12737
- onStart(file);
12738
- }
12562
+ onStart?.(file);
12739
12563
  let file64 = null;
12740
12564
  try {
12741
12565
  file64 = await asyncFileRead(file);
12742
12566
  } catch (error) {
12743
- this.asyncResponse(error, PROCESS_STATE[0]);
12567
+ this.asyncResponse(error, 'error');
12744
12568
  }
12745
12569
  if (!file64) {
12746
12570
  return false;
@@ -12749,30 +12573,31 @@ class Upload extends React.Component {
12749
12573
  isImage: getFileType(file, file64).includes('image')
12750
12574
  });
12751
12575
  if (!isTypeValid(file, usAccept, file64)) {
12752
- const response = {
12576
+ this.asyncResponse(new ResponseError(new Response(null, {
12753
12577
  status: 415,
12754
12578
  statusText: 'Unsupported Media Type'
12755
- };
12756
- this.asyncResponse(response, PROCESS_STATE[0]);
12579
+ })), 'error');
12757
12580
  return false;
12758
12581
  }
12759
12582
  if (!isSizeValid(file, maxSize)) {
12760
- const response = {
12583
+ this.asyncResponse(new ResponseError(new Response(null, {
12761
12584
  status: 413,
12762
12585
  statusText: 'Request Entity Too Large'
12763
- };
12764
- this.asyncResponse(response, PROCESS_STATE[0]);
12586
+ })), 'error');
12765
12587
  return false;
12766
12588
  }
12767
12589
  if (httpOptions) {
12768
12590
  // Post the file to provided endpoint
12769
- return await this.asyncPost(file).then(response => this.asyncResponse(response, 'success')).then(() => {
12770
- this.showDataImage(file64);
12771
- return true;
12772
- }).catch(error => {
12773
- this.asyncResponse(error, PROCESS_STATE[0]);
12591
+ let response;
12592
+ try {
12593
+ response = await this.asyncPost(file);
12594
+ } catch (error) {
12595
+ this.asyncResponse(error, 'error');
12774
12596
  return false;
12775
- });
12597
+ }
12598
+ this.asyncResponse(response, 'success');
12599
+ this.showDataImage(file64);
12600
+ return true;
12776
12601
  }
12777
12602
  // Post on form submit. And return the encoded image.
12778
12603
  this.showDataImage(file64);
@@ -12781,6 +12606,7 @@ class Upload extends React.Component {
12781
12606
  };
12782
12607
  render() {
12783
12608
  const {
12609
+ maxSize,
12784
12610
  usDropMessage,
12785
12611
  usAccept,
12786
12612
  usButtonText,
@@ -12794,7 +12620,6 @@ class Upload extends React.Component {
12794
12620
  csButtonText,
12795
12621
  csSuccessText,
12796
12622
  size,
12797
- uploadStep,
12798
12623
  intl
12799
12624
  } = this.props;
12800
12625
  const {
@@ -12808,7 +12633,6 @@ class Upload extends React.Component {
12808
12633
  isSuccess,
12809
12634
  uploadedImage
12810
12635
  } = this.state;
12811
- const UploadStepComponent = UPLOAD_STEP_COMPONENTS[uploadStep] || UploadImageStep;
12812
12636
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
12813
12637
  className: classNames__default.default('droppable-area', {
12814
12638
  droppable: true,
@@ -12822,10 +12646,10 @@ class Upload extends React.Component {
12822
12646
  }),
12823
12647
  onDragEnter: event => this.onDragEnter(event),
12824
12648
  onDragLeave: event => this.onDragLeave(event),
12825
- onDrop: event => this.onDrop(event),
12649
+ onDrop: async event => this.onDrop(event),
12826
12650
  onDragOver: event => event.preventDefault(),
12827
- children: [!isProcessing && !isComplete && /*#__PURE__*/jsxRuntime.jsx(UploadStepComponent, {
12828
- fileDropped: file => this.fileDropped(file),
12651
+ children: [!isProcessing && !isComplete && /*#__PURE__*/jsxRuntime.jsx(UploadImageStep, {
12652
+ fileDropped: async file => this.fileDropped(file),
12829
12653
  isComplete: isComplete,
12830
12654
  usAccept: usAccept,
12831
12655
  usButtonText: usButtonText || intl.formatMessage(messages.usButtonText),
@@ -12833,7 +12657,7 @@ class Upload extends React.Component {
12833
12657
  usHelpImage: usHelpImage,
12834
12658
  usLabel: usLabel,
12835
12659
  usPlaceholder: usPlaceholder || intl.formatMessage(messages.usPlaceholder, {
12836
- maxSize: this.props.maxSize / 1000000
12660
+ maxSize: maxSize / 1000000
12837
12661
  })
12838
12662
  }), isProcessing && /*#__PURE__*/jsxRuntime.jsx(ProcessingStep, {
12839
12663
  isComplete: isComplete,
@@ -12842,7 +12666,7 @@ class Upload extends React.Component {
12842
12666
  psButtonText: psButtonText || intl.formatMessage(messages.psButtonText),
12843
12667
  psProcessingText: psProcessingText || intl.formatMessage(messages.psProcessingText),
12844
12668
  psButtonDisabled: psButtonDisabled,
12845
- onAnimationCompleted: status => this.onAnimationCompleted(status),
12669
+ onAnimationCompleted: async status => this.onAnimationCompleted(status),
12846
12670
  onClear: event => this.handleOnClear(event)
12847
12671
  }), (isSuccess || isError || isComplete) && /*#__PURE__*/jsxRuntime.jsx(CompleteStep, {
12848
12672
  fileName: fileName,
@@ -12850,7 +12674,7 @@ class Upload extends React.Component {
12850
12674
  isError: isError,
12851
12675
  isImage: isImage,
12852
12676
  csButtonText: csButtonText || intl.formatMessage(messages.csButtonText),
12853
- csFailureText: this.getErrorMessage(response?.status),
12677
+ csFailureText: this.getErrorMessage(response != null && typeof response === 'object' && 'status' in response && typeof response.status === 'number' ? response.status : undefined),
12854
12678
  csSuccessText: csSuccessText || intl.formatMessage(messages.csSuccessText),
12855
12679
  uploadedImage: uploadedImage,
12856
12680
  onClear: event => this.handleOnClear(event)
@@ -12874,73 +12698,6 @@ class Upload extends React.Component {
12874
12698
  });
12875
12699
  }
12876
12700
  }
12877
- Upload.propTypes = {
12878
- animationDelay: PropTypes__default.default.number,
12879
- csButtonText: PropTypes__default.default.string,
12880
- csFailureText: PropTypes__default.default.string,
12881
- csSuccessText: PropTypes__default.default.string,
12882
- csTooLargeMessage: PropTypes__default.default.string,
12883
- csWrongTypeMessage: PropTypes__default.default.string,
12884
- httpOptions: PropTypes__default.default.shape({
12885
- url: PropTypes__default.default.string.isRequired,
12886
- method: PropTypes__default.default.oneOf(['POST', 'PUT', 'PATCH']),
12887
- fileInputName: PropTypes__default.default.string,
12888
- data: PropTypes__default.default.object,
12889
- headers: PropTypes__default.default.object
12890
- }),
12891
- /**
12892
- * You can provide a fetcher function with the same interface as the global fetch function, which is used by default.
12893
- * function fetcher(input: RequestInfo, init?: RequestInit): Promise<Response>
12894
- */
12895
- fetcher: PropTypes__default.default.func,
12896
- maxSize: PropTypes__default.default.number,
12897
- onCancel: PropTypes__default.default.func,
12898
- onFailure: PropTypes__default.default.func,
12899
- onStart: PropTypes__default.default.func,
12900
- onSuccess: PropTypes__default.default.func,
12901
- psButtonText: PropTypes__default.default.string,
12902
- psButtonDisabled: PropTypes__default.default.bool,
12903
- psProcessingText: PropTypes__default.default.string,
12904
- size: PropTypes__default.default.oneOf(['sm', 'md', 'lg']),
12905
- /**
12906
- * You can provide multiple rules separated by comma, e.g.: "application/pdf,image/*".
12907
- * Using "*" will allow every file type to be uploaded.
12908
- */
12909
- usAccept: PropTypes__default.default.string,
12910
- usButtonText: PropTypes__default.default.string,
12911
- usDisabled: PropTypes__default.default.bool,
12912
- usDropMessage: PropTypes__default.default.string,
12913
- usHelpImage: PropTypes__default.default.node,
12914
- usLabel: PropTypes__default.default.string,
12915
- usPlaceholder: PropTypes__default.default.string,
12916
- uploadStep: PropTypes__default.default.oneOf(['uploadImageStep', 'mediaUploadStep'])
12917
- };
12918
- Upload.defaultProps = {
12919
- animationDelay: 700,
12920
- csButtonText: undefined,
12921
- csFailureText: undefined,
12922
- csSuccessText: undefined,
12923
- csTooLargeMessage: undefined,
12924
- csWrongTypeMessage: undefined,
12925
- httpOptions: null,
12926
- maxSize: MAX_SIZE_DEFAULT,
12927
- onCancel: null,
12928
- onFailure: null,
12929
- onStart: null,
12930
- onSuccess: null,
12931
- psButtonText: undefined,
12932
- psButtonDisabled: false,
12933
- psProcessingText: undefined,
12934
- size: 'md',
12935
- usAccept: 'image/*',
12936
- usButtonText: undefined,
12937
- usDisabled: false,
12938
- usDropMessage: undefined,
12939
- usHelpImage: '',
12940
- usLabel: '',
12941
- usPlaceholder: undefined,
12942
- uploadStep: exports.UploadStep.UPLOAD_IMAGE_STEP
12943
- };
12944
12701
  var Upload$1 = reactIntl.injectIntl(Upload);
12945
12702
 
12946
12703
  var MESSAGES$2 = reactIntl.defineMessages({
@@ -13471,7 +13228,7 @@ const UploadInput = ({
13471
13228
  name
13472
13229
  } = file;
13473
13230
  const id = generateFileId(file);
13474
- const allowedFileTypes = Array.isArray(fileTypes) ? fileTypes.join(',') : fileTypes;
13231
+ const allowedFileTypes = typeof fileTypes === 'string' ? fileTypes : fileTypes.join(',');
13475
13232
  // Check if file type is valid
13476
13233
  if (!isTypeValid(file, allowedFileTypes)) {
13477
13234
  handleFileUploadFailure(file, formatMessage(MESSAGES$2.fileTypeNotSupported));