@transferwise/components 46.38.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 (202) hide show
  1. package/build/index.js +198 -461
  2. package/build/index.js.map +1 -1
  3. package/build/index.mjs +198 -461
  4. package/build/index.mjs.map +1 -1
  5. package/build/types/flowNavigation/backButton/BackButton.d.ts +5 -17
  6. package/build/types/flowNavigation/backButton/BackButton.d.ts.map +1 -1
  7. package/build/types/flowNavigation/backButton/index.d.ts +2 -2
  8. package/build/types/flowNavigation/backButton/index.d.ts.map +1 -1
  9. package/build/types/index.d.ts +3 -1
  10. package/build/types/index.d.ts.map +1 -1
  11. package/build/types/info/Info.d.ts +2 -2
  12. package/build/types/info/Info.d.ts.map +1 -1
  13. package/build/types/info/index.d.ts +1 -1
  14. package/build/types/info/index.d.ts.map +1 -1
  15. package/build/types/overlayHeader/OverlayHeader.d.ts +9 -18
  16. package/build/types/overlayHeader/OverlayHeader.d.ts.map +1 -1
  17. package/build/types/overlayHeader/index.d.ts +2 -1
  18. package/build/types/overlayHeader/index.d.ts.map +1 -1
  19. package/build/types/processIndicator/ProcessIndicator.d.ts +1 -1
  20. package/build/types/processIndicator/ProcessIndicator.d.ts.map +1 -1
  21. package/build/types/upload/Upload.d.ts +91 -55
  22. package/build/types/upload/Upload.d.ts.map +1 -1
  23. package/build/types/upload/Upload.messages.d.ts +42 -60
  24. package/build/types/upload/Upload.messages.d.ts.map +1 -1
  25. package/build/types/upload/index.d.ts +2 -2
  26. package/build/types/upload/index.d.ts.map +1 -1
  27. package/build/types/upload/steps/completeStep/completeStep.d.ts +11 -18
  28. package/build/types/upload/steps/completeStep/completeStep.d.ts.map +1 -1
  29. package/build/types/upload/steps/completeStep/index.d.ts +2 -1
  30. package/build/types/upload/steps/completeStep/index.d.ts.map +1 -1
  31. package/build/types/upload/steps/index.d.ts +3 -4
  32. package/build/types/upload/steps/index.d.ts.map +1 -1
  33. package/build/types/upload/steps/processingStep/index.d.ts +2 -1
  34. package/build/types/upload/steps/processingStep/index.d.ts.map +1 -1
  35. package/build/types/upload/steps/processingStep/processingStep.d.ts +11 -13
  36. package/build/types/upload/steps/processingStep/processingStep.d.ts.map +1 -1
  37. package/build/types/upload/steps/uploadImageStep/index.d.ts +2 -1
  38. package/build/types/upload/steps/uploadImageStep/index.d.ts.map +1 -1
  39. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts +14 -18
  40. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts.map +1 -1
  41. package/build/types/upload/utils/asyncFileRead/asyncFileRead.d.ts +1 -1
  42. package/build/types/upload/utils/asyncFileRead/asyncFileRead.d.ts.map +1 -1
  43. package/build/types/upload/utils/asyncFileRead/index.d.ts +1 -1
  44. package/build/types/upload/utils/asyncFileRead/index.d.ts.map +1 -1
  45. package/build/types/upload/utils/getFileType/getFileType.d.ts +1 -1
  46. package/build/types/upload/utils/getFileType/getFileType.d.ts.map +1 -1
  47. package/build/types/upload/utils/getFileType/index.d.ts +1 -1
  48. package/build/types/upload/utils/getFileType/index.d.ts.map +1 -1
  49. package/build/types/upload/utils/index.d.ts +5 -7
  50. package/build/types/upload/utils/index.d.ts.map +1 -1
  51. package/build/types/upload/utils/isSizeValid/index.d.ts +1 -1
  52. package/build/types/upload/utils/isSizeValid/index.d.ts.map +1 -1
  53. package/build/types/upload/utils/isSizeValid/isSizeValid.d.ts +1 -1
  54. package/build/types/upload/utils/isSizeValid/isSizeValid.d.ts.map +1 -1
  55. package/build/types/upload/utils/isTypeValid/index.d.ts +1 -1
  56. package/build/types/upload/utils/isTypeValid/index.d.ts.map +1 -1
  57. package/build/types/upload/utils/isTypeValid/isTypeValid.d.ts +1 -1
  58. package/build/types/upload/utils/isTypeValid/isTypeValid.d.ts.map +1 -1
  59. package/build/types/upload/utils/postData/index.d.ts +1 -1
  60. package/build/types/upload/utils/postData/index.d.ts.map +1 -1
  61. package/build/types/upload/utils/postData/postData.d.ts +11 -1
  62. package/build/types/upload/utils/postData/postData.d.ts.map +1 -1
  63. package/package.json +24 -26
  64. package/src/accordion/Accordion.spec.js +5 -5
  65. package/src/accordion/AccordionItem/AccordionItem.spec.js +2 -2
  66. package/src/actionButton/ActionButton.spec.tsx +4 -5
  67. package/src/alert/Alert.spec.tsx +4 -4
  68. package/src/alert/Alert.story.tsx +6 -5
  69. package/src/button/Button.spec.js +4 -5
  70. package/src/card/Card.spec.tsx +4 -4
  71. package/src/carousel/Carousel.spec.tsx +17 -17
  72. package/src/checkbox/Checkbox.spec.tsx +0 -2
  73. package/src/checkboxButton/CheckboxButton.spec.tsx +0 -2
  74. package/src/checkboxOption/CheckboxOption.spec.tsx +0 -2
  75. package/src/chevron/Chevron.spec.tsx +0 -1
  76. package/src/chips/Chips.spec.tsx +0 -1
  77. package/src/chips/Chips.story.tsx +5 -3
  78. package/src/circularButton/CircularButton.spec.tsx +4 -5
  79. package/src/common/RadioButton/RadioButton.spec.tsx +2 -2
  80. package/src/common/card/Card.story.tsx +1 -0
  81. package/src/common/closeButton/CloseButton.spec.tsx +0 -1
  82. package/src/common/flowHeader/FlowHeader.spec.tsx +0 -1
  83. package/src/dateInput/DateInput.story.tsx +21 -16
  84. package/src/dateLookup/DateLookup.rtl.spec.tsx +18 -16
  85. package/src/dateLookup/DateLookup.testingLibrary.spec.js +47 -44
  86. package/src/dateLookup/DateLookup.tests.story.tsx +4 -2
  87. package/src/decision/Decision.spec.js +0 -2
  88. package/src/dimmer/Dimmer.rtl.spec.js +10 -10
  89. package/src/drawer/Drawer.rtl.spec.tsx +2 -2
  90. package/src/emphasis/Emphasis.spec.tsx +0 -1
  91. package/src/field/Field.spec.tsx +2 -2
  92. package/src/flowNavigation/FlowNavigation.spec.js +0 -2
  93. package/src/flowNavigation/animatedLabel/AnimatedLabel.spec.js +0 -1
  94. package/src/flowNavigation/backButton/BackButton.tsx +29 -0
  95. package/src/flowNavigation/backButton/index.ts +2 -0
  96. package/src/header/Header.spec.tsx +6 -6
  97. package/src/image/Image.spec.tsx +0 -1
  98. package/src/index.ts +3 -1
  99. package/src/info/Info.story.tsx +15 -9
  100. package/src/info/Info.tsx +2 -2
  101. package/src/info/index.ts +1 -1
  102. package/src/inlineAlert/InlineAlert.spec.tsx +0 -1
  103. package/src/inputs/SelectInput.spec.tsx +26 -47
  104. package/src/link/Link.spec.tsx +0 -1
  105. package/src/listItem/ListItem.spec.tsx +0 -1
  106. package/src/moneyInput/MoneyInput.rtl.spec.tsx +2 -2
  107. package/src/moneyInput/MoneyInput.story.tsx +1 -4
  108. package/src/overlayHeader/{OverlayHeader.spec.js → OverlayHeader.spec.tsx} +1 -1
  109. package/src/overlayHeader/{OverlayHeader.story.js → OverlayHeader.story.tsx} +10 -2
  110. package/src/overlayHeader/{OverlayHeader.js → OverlayHeader.tsx} +12 -19
  111. package/src/overlayHeader/index.ts +2 -0
  112. package/src/phoneNumberInput/PhoneNumberInput.story.tsx +1 -0
  113. package/src/popover/Popover.spec.tsx +10 -10
  114. package/src/processIndicator/ProcessIndicator.tsx +1 -1
  115. package/src/progress/Progress.spec.tsx +0 -1
  116. package/src/progressBar/ProgressBar.spec.tsx +0 -1
  117. package/src/segmentedControl/SegmentedControl.spec.tsx +10 -11
  118. package/src/select/Select.spec.js +71 -71
  119. package/src/test-utils/index.js +1 -1
  120. package/src/test-utils/jest.setup.js +2 -0
  121. package/src/tooltip/Tooltip.spec.tsx +15 -16
  122. package/src/upload/Upload.spec.js +3 -14
  123. package/src/upload/Upload.story.tsx +37 -0
  124. package/src/upload/{Upload.js → Upload.tsx} +164 -169
  125. package/src/upload/index.ts +2 -0
  126. package/src/upload/steps/completeStep/completeStep.spec.js +3 -2
  127. package/src/upload/steps/completeStep/completeStep.tsx +74 -0
  128. package/src/upload/steps/completeStep/index.ts +2 -0
  129. package/src/upload/steps/{index.js → index.ts} +0 -1
  130. package/src/upload/steps/processingStep/index.ts +2 -0
  131. package/src/upload/steps/processingStep/processingStep.tsx +53 -0
  132. package/src/upload/steps/uploadImageStep/index.ts +2 -0
  133. package/src/upload/steps/uploadImageStep/{uploadImageStep.js → uploadImageStep.tsx} +17 -23
  134. package/src/upload/utils/asyncFileRead/asyncFileRead.spec.ts +14 -0
  135. package/src/upload/utils/asyncFileRead/asyncFileRead.ts +12 -0
  136. package/src/upload/utils/getFileType/getFileType.spec.ts +22 -0
  137. package/src/upload/utils/getFileType/getFileType.ts +16 -0
  138. package/src/upload/utils/{index.js → index.ts} +0 -2
  139. package/src/upload/utils/isSizeValid/{isSizeValid.spec.js → isSizeValid.spec.ts} +3 -3
  140. package/src/upload/utils/isSizeValid/isSizeValid.ts +3 -0
  141. package/src/upload/utils/isTypeValid/isTypeValid.spec.ts +62 -0
  142. package/src/upload/utils/isTypeValid/isTypeValid.ts +19 -0
  143. package/src/upload/utils/postData/postData.spec.ts +65 -0
  144. package/src/upload/utils/postData/postData.ts +36 -0
  145. package/src/uploadInput/UploadInput.spec.tsx +9 -10
  146. package/src/uploadInput/UploadInput.story.tsx +8 -180
  147. package/src/uploadInput/UploadInput.tests.story.tsx +212 -0
  148. package/src/uploadInput/UploadInput.tsx +1 -1
  149. package/src/uploadInput/uploadButton/UploadButton.spec.tsx +4 -4
  150. package/src/uploadInput/uploadItem/UploadItem.spec.tsx +4 -4
  151. package/build/types/upload/steps/mediaUploadStep/index.d.ts +0 -2
  152. package/build/types/upload/steps/mediaUploadStep/index.d.ts.map +0 -1
  153. package/build/types/upload/steps/mediaUploadStep/mediaUploadStep.d.ts +0 -24
  154. package/build/types/upload/steps/mediaUploadStep/mediaUploadStep.d.ts.map +0 -1
  155. package/build/types/upload/uploadSteps.d.ts +0 -5
  156. package/build/types/upload/uploadSteps.d.ts.map +0 -1
  157. package/build/types/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.d.ts +0 -2
  158. package/build/types/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.d.ts.map +0 -1
  159. package/build/types/upload/utils/getSupportedSpotMimeTypes/index.d.ts +0 -2
  160. package/build/types/upload/utils/getSupportedSpotMimeTypes/index.d.ts.map +0 -1
  161. package/build/types/upload/utils/requestMedia/index.d.ts +0 -2
  162. package/build/types/upload/utils/requestMedia/index.d.ts.map +0 -1
  163. package/build/types/upload/utils/requestMedia/requestMedia.d.ts +0 -2
  164. package/build/types/upload/utils/requestMedia/requestMedia.d.ts.map +0 -1
  165. package/src/flowNavigation/backButton/BackButton.js +0 -32
  166. package/src/flowNavigation/backButton/BackButton.spec.js +0 -16
  167. package/src/flowNavigation/backButton/__snapshots__/BackButton.spec.js.snap +0 -37
  168. package/src/flowNavigation/backButton/index.js +0 -3
  169. package/src/overlayHeader/index.js +0 -1
  170. package/src/upload/Upload.story.js +0 -36
  171. package/src/upload/index.js +0 -2
  172. package/src/upload/steps/completeStep/completeStep.js +0 -98
  173. package/src/upload/steps/completeStep/index.js +0 -1
  174. package/src/upload/steps/mediaUploadStep/index.js +0 -1
  175. package/src/upload/steps/mediaUploadStep/mediaUploadStep.js +0 -80
  176. package/src/upload/steps/mediaUploadStep/mediaUploadStep.spec.js +0 -77
  177. package/src/upload/steps/processingStep/index.js +0 -1
  178. package/src/upload/steps/processingStep/processingStep.js +0 -73
  179. package/src/upload/steps/uploadImageStep/index.js +0 -1
  180. package/src/upload/uploadSteps.ts +0 -5
  181. package/src/upload/utils/asyncFileRead/asyncFileRead.js +0 -11
  182. package/src/upload/utils/asyncFileRead/asyncFileRead.spec.js +0 -17
  183. package/src/upload/utils/getFileType/getFileType.js +0 -19
  184. package/src/upload/utils/getFileType/getFileType.spec.js +0 -33
  185. package/src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.js +0 -18
  186. package/src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.spec.js +0 -22
  187. package/src/upload/utils/getSupportedSpotMimeTypes/index.js +0 -1
  188. package/src/upload/utils/isSizeValid/isSizeValid.js +0 -1
  189. package/src/upload/utils/isTypeValid/isTypeValid.js +0 -26
  190. package/src/upload/utils/isTypeValid/isTypeValid.spec.js +0 -68
  191. package/src/upload/utils/postData/postData.js +0 -18
  192. package/src/upload/utils/postData/postData.spec.js +0 -109
  193. package/src/upload/utils/requestMedia/index.js +0 -1
  194. package/src/upload/utils/requestMedia/requestMedia.js +0 -26
  195. package/src/upload/utils/requestMedia/requestMedia.spec.js +0 -44
  196. /package/src/overlayHeader/__snapshots__/{OverlayHeader.spec.js.snap → OverlayHeader.spec.tsx.snap} +0 -0
  197. /package/src/upload/{Upload.messages.js → Upload.messages.ts} +0 -0
  198. /package/src/upload/utils/asyncFileRead/{index.js → index.ts} +0 -0
  199. /package/src/upload/utils/getFileType/{index.js → index.ts} +0 -0
  200. /package/src/upload/utils/isSizeValid/{index.js → index.ts} +0 -0
  201. /package/src/upload/utils/isTypeValid/{index.js → index.ts} +0 -0
  202. /package/src/upload/utils/postData/{index.js → index.ts} +0 -0
package/build/index.mjs CHANGED
@@ -16,8 +16,8 @@ import mergeProps from 'merge-props';
16
16
  import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager, offset, flip, shift, size, autoUpdate } from '@floating-ui/react';
17
17
  import { usePreventScroll } from '@react-aria/overlays';
18
18
  import { usePopper } from 'react-popper';
19
- import PropTypes from 'prop-types';
20
19
  import { Flag, Illustration } from '@wise/art';
20
+ import PropTypes from 'prop-types';
21
21
  import clamp$2 from 'lodash.clamp';
22
22
  import debounce from 'lodash.debounce';
23
23
  import { Spring, animated } from '@react-spring/web';
@@ -5301,33 +5301,25 @@ const AnimatedLabel = ({
5301
5301
  });
5302
5302
  };
5303
5303
 
5304
- const BackButton = ({
5304
+ function BackButton({
5305
5305
  className,
5306
5306
  onClick,
5307
5307
  'aria-label': ariaLabel
5308
- }) => /*#__PURE__*/jsx(Avatar, {
5309
- type: AvatarType.ICON,
5310
- size: 40,
5311
- children: /*#__PURE__*/jsx("button", {
5312
- type: "button",
5313
- "aria-label": ariaLabel,
5314
- className: classNames('np-back-button', 'btn-unstyled', className),
5315
- onClick: onClick,
5316
- children: /*#__PURE__*/jsx(ArrowLeft, {
5317
- size: 24
5308
+ }) {
5309
+ return /*#__PURE__*/jsx(Avatar, {
5310
+ type: AvatarType.ICON,
5311
+ size: 40,
5312
+ children: /*#__PURE__*/jsx("button", {
5313
+ type: "button",
5314
+ "aria-label": ariaLabel,
5315
+ className: classNames('np-back-button', 'btn-unstyled', className),
5316
+ onClick: onClick,
5317
+ children: /*#__PURE__*/jsx(ArrowLeft, {
5318
+ size: 24
5319
+ })
5318
5320
  })
5319
- })
5320
- });
5321
- BackButton.propTypes = {
5322
- 'aria-label': PropTypes.string.isRequired,
5323
- className: PropTypes.string,
5324
- label: PropTypes.element,
5325
- onClick: PropTypes.func
5326
- };
5327
- BackButton.defaultProps = {
5328
- className: undefined,
5329
- label: undefined
5330
- };
5321
+ });
5322
+ }
5331
5323
 
5332
5324
  const FlowNavigation = ({
5333
5325
  activeStep = 0,
@@ -7734,11 +7726,12 @@ const Nudge = ({
7734
7726
  });
7735
7727
  };
7736
7728
 
7737
- const OverlayHeader = ({
7729
+ const defaultLogo = /*#__PURE__*/jsx(Logo, {});
7730
+ function OverlayHeader({
7738
7731
  avatar,
7739
7732
  onClose,
7740
- logo
7741
- }) => {
7733
+ logo = defaultLogo
7734
+ }) {
7742
7735
  const closeButton = onClose && /*#__PURE__*/jsx(CloseButton, {
7743
7736
  size: Size.LARGE,
7744
7737
  onClick: onClose
@@ -7756,20 +7749,7 @@ const OverlayHeader = ({
7756
7749
  })
7757
7750
  })
7758
7751
  });
7759
- };
7760
- OverlayHeader.defaultProps = {
7761
- avatar: null,
7762
- logo: /*#__PURE__*/jsx(Logo, {}),
7763
- onClose: null
7764
- };
7765
- OverlayHeader.propTypes = {
7766
- /** An Avatar */
7767
- avatar: PropTypes.element,
7768
- logo: PropTypes.node,
7769
- /** Function called when the close is clicked */
7770
- onClose: PropTypes.func
7771
- };
7772
- var OverlayHeader$1 = OverlayHeader;
7752
+ }
7773
7753
 
7774
7754
  var messages$3 = defineMessages({
7775
7755
  selectInputPlaceholder: {
@@ -12079,13 +12059,6 @@ var Typeahead$1 = withInputAttributes(Typeahead, {
12079
12059
  nonLabelable: true
12080
12060
  });
12081
12061
 
12082
- // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
12083
- var UploadStep;
12084
- (function (UploadStep) {
12085
- UploadStep["UPLOAD_IMAGE_STEP"] = "uploadImageStep";
12086
- UploadStep["MEDIA_UPLOAD_STEP"] = "mediaUploadStep";
12087
- })(UploadStep || (UploadStep = {}));
12088
-
12089
12062
  var messages = defineMessages({
12090
12063
  csButtonText: {
12091
12064
  id: "neptune.Upload.csButtonText"
@@ -12120,16 +12093,13 @@ var messages = defineMessages({
12120
12093
  });
12121
12094
 
12122
12095
  class UploadImageStep extends PureComponent {
12123
- constructor() {
12124
- super();
12125
- this.uploadInputRef = /*#__PURE__*/createRef();
12126
- }
12096
+ uploadInputRef = /*#__PURE__*/createRef();
12127
12097
  onManualUpload = () => {
12128
12098
  const {
12129
12099
  fileDropped
12130
12100
  } = this.props;
12131
- if (this.uploadInputRef && this.uploadInputRef.current) {
12132
- const file = this.uploadInputRef.current.files[0];
12101
+ const file = this.uploadInputRef.current?.files?.[0];
12102
+ if (file != null) {
12133
12103
  fileDropped(file);
12134
12104
  }
12135
12105
  };
@@ -12178,7 +12148,7 @@ class UploadImageStep extends PureComponent {
12178
12148
  children: usLabel
12179
12149
  }), usPlaceholder && /*#__PURE__*/jsx("p", {
12180
12150
  className: "np-text-body-large m-b-3",
12181
- children: `${usPlaceholder}`
12151
+ children: String(usPlaceholder)
12182
12152
  }), /*#__PURE__*/jsxs("label", {
12183
12153
  className: `btn btn-primary btn-md ${usDisabled ? 'disabled' : ''}`,
12184
12154
  children: [usButtonText ? /*#__PURE__*/jsx("span", {
@@ -12189,7 +12159,7 @@ class UploadImageStep extends PureComponent {
12189
12159
  }), /*#__PURE__*/jsx("input", {
12190
12160
  ref: this.uploadInputRef,
12191
12161
  type: "file",
12192
- accept: usAccept === '*' ? null : usAccept,
12162
+ accept: usAccept === '*' ? undefined : usAccept,
12193
12163
  className: "tw-droppable-input hidden",
12194
12164
  disabled: usDisabled,
12195
12165
  name: "file-upload",
@@ -12201,213 +12171,17 @@ class UploadImageStep extends PureComponent {
12201
12171
  });
12202
12172
  }
12203
12173
  }
12204
- UploadImageStep.propTypes = {
12205
- fileDropped: PropTypes.func.isRequired,
12206
- isComplete: PropTypes.bool.isRequired,
12207
- usAccept: PropTypes.string.isRequired,
12208
- usButtonText: PropTypes.string.isRequired,
12209
- usDisabled: PropTypes.bool.isRequired,
12210
- usHelpImage: PropTypes.node.isRequired,
12211
- usLabel: PropTypes.string.isRequired,
12212
- usPlaceholder: PropTypes.string.isRequired
12213
- };
12214
-
12215
- const postData = (httpOptions, data = {}, fetcher = fetch) => fetcher(`${httpOptions.url}`, {
12216
- method: 'POST',
12217
- body: data,
12218
- ...httpOptions
12219
- }).then(response => {
12220
- if (!response.ok) {
12221
- const error = new Error(response.statusText);
12222
- error.status = response.status;
12223
- error.response = response;
12224
- throw error;
12225
- }
12226
- return response;
12227
- }).catch(error => {
12228
- throw error;
12229
- });
12230
-
12231
- const asyncFileRead = file => new Promise((resolve, reject) => {
12232
- const reader = new FileReader();
12233
- reader.readAsDataURL(file);
12234
- reader.addEventListener('load', event => {
12235
- resolve(event.target.result);
12236
- });
12237
- reader.addEventListener('error', event => {
12238
- reject(event);
12239
- });
12240
- });
12241
-
12242
- const isSizeValid = (file, maxSize) => Number.isInteger(maxSize) && file.size <= maxSize;
12243
-
12244
- const getFileType = (file, file64) => {
12245
- if (!file && !file64) {
12246
- return '';
12247
- }
12248
- if (file && file.type && file.type !== '') {
12249
- return file.type ?? '';
12250
- }
12251
- if (file64) {
12252
- const regex = /^data:([a-z]+\/[a-z]+);/;
12253
- const typeFromEncoded = file64.match(regex);
12254
- if (typeFromEncoded && typeFromEncoded[1]) {
12255
- return typeFromEncoded[1] ?? '';
12256
- }
12257
- }
12258
- return '';
12259
- };
12260
12174
 
12261
- const isTypeValid = (file, rule, file64) => {
12262
- if (!file || !rule) {
12263
- return false;
12264
- }
12265
- const allowedTypes = rule.replace(/\s/g, '').split(',');
12266
- const fileType = getFileType(file, file64);
12267
- if (rule === '*' || allowedTypes.includes(fileType)) {
12268
- return true;
12269
- }
12270
- return allowedTypes.some(type => {
12271
- const splittedRule = type.split('/');
12272
- const typeAllowed = splittedRule[0];
12273
- const extensionAllowed = splittedRule[1];
12274
- if (extensionAllowed !== '*') {
12275
- return false;
12276
- }
12277
- return fileType.includes(typeAllowed);
12278
- });
12279
- };
12280
-
12281
- // Spot Platform's Media API only support these MIME types
12282
- const SUPPORTED_MIME_TYPES = ['image/jpeg', 'video/*', 'application/pdf'];
12283
- const getSupportedSpotMimeTypes = mimeTypes => {
12284
- if (mimeTypes === '*') {
12285
- return SUPPORTED_MIME_TYPES;
12286
- }
12287
- const mimeTypesArray = mimeTypes.split(',');
12288
- const mimeMapping = {
12289
- 'image/*': 'image/jpeg',
12290
- 'application/*': 'application/pdf'
12291
- };
12292
- const mapSupportedMimeTypes = mimeTypesArray.map(type => mimeMapping[type] || type);
12293
- return mapSupportedMimeTypes.filter(type => SUPPORTED_MIME_TYPES.includes(type));
12294
- };
12295
-
12296
- const requestMedia = mediaRequest => new Promise((resolve, reject) => {
12297
- if (typeof window === 'undefined' || typeof window.microapps === 'undefined') {
12298
- reject(`microapps must be available in window to use Spot Platform's Media API`);
12299
- }
12300
- window.microapps.requestMedia(mediaRequest).then(response => {
12301
- const fileByteArray = base64ToByteArray(response.bytes);
12302
- const blob = new Blob([fileByteArray], {
12303
- type: response.mimeType
12304
- });
12305
- resolve(blob);
12306
- }).catch(error => reject(error));
12307
- });
12308
- const base64ToByteArray = base64String => {
12309
- const byteCharacters = atob(base64String);
12310
- const byteCharactersLength = byteCharacters.length;
12311
- const byteArray = new Array(byteCharactersLength);
12312
- for (let i = 0; i < byteCharactersLength; i += 1) {
12313
- byteArray[i] = byteCharacters.charCodeAt(i);
12314
- }
12315
- return new Uint8Array(byteArray);
12316
- };
12317
-
12318
- const MediaUploadStep = ({
12175
+ function ProcessingStep({
12319
12176
  isComplete,
12320
- usAccept,
12321
- usButtonText,
12322
- usDisabled,
12323
- usHelpImage,
12324
- usLabel,
12325
- usPlaceholder,
12326
- fileDropped
12327
- }) => {
12328
- const getMediaFile = () => {
12329
- const allowedMimeTypes = getSupportedSpotMimeTypes(usAccept);
12330
- if (allowedMimeTypes.length === 0) {
12331
- throw new Error('provided mimeTypes not supported');
12332
- }
12333
- const mediaRequest = {
12334
- allowedMimeTypes
12335
- };
12336
- requestMedia(mediaRequest).then(file => fileDropped(file));
12337
- };
12338
- const getImage = () => {
12339
- if (!usHelpImage) {
12340
- return /*#__PURE__*/jsx("div", {
12341
- className: "circle circle-sm circle-inverse p-t-1",
12342
- children: /*#__PURE__*/jsx(Upload$2, {
12343
- size: 24
12344
- })
12345
- });
12346
- }
12347
- if (typeof usHelpImage === 'string') {
12348
- return /*#__PURE__*/jsx("img", {
12349
- src: usHelpImage,
12350
- alt: usLabel,
12351
- className: "thumbnail text-xs-center"
12352
- });
12353
- }
12354
- return usHelpImage;
12355
- };
12356
- return /*#__PURE__*/jsx("div", {
12357
- children: /*#__PURE__*/jsx("div", {
12358
- className: "droppable-default-card",
12359
- "aria-hidden": isComplete,
12360
- children: /*#__PURE__*/jsxs("div", {
12361
- className: "droppable-card-content",
12362
- children: [/*#__PURE__*/jsx("div", {
12363
- className: "m-b-3",
12364
- children: getImage()
12365
- }), usLabel && /*#__PURE__*/jsx(Title, {
12366
- type: Typography.TITLE_BODY,
12367
- className: "m-b-1",
12368
- children: usLabel
12369
- }), usPlaceholder && /*#__PURE__*/jsx(Body, {
12370
- as: "p",
12371
- type: Typography.BODY_LARGE,
12372
- className: "m-b-3",
12373
- children: `${usPlaceholder}`
12374
- }), /*#__PURE__*/jsx(Button, {
12375
- disabled: usDisabled,
12376
- onClick: getMediaFile,
12377
- children: usButtonText || /*#__PURE__*/jsx(Upload$2, {
12378
- size: 24,
12379
- className: "m-r-0"
12380
- })
12381
- })]
12382
- })
12383
- })
12384
- });
12385
- };
12386
- MediaUploadStep.propTypes = {
12387
- fileDropped: PropTypes.func.isRequired,
12388
- isComplete: PropTypes.bool.isRequired,
12389
- usAccept: PropTypes.string.isRequired,
12390
- usButtonText: PropTypes.string.isRequired,
12391
- usDisabled: PropTypes.bool.isRequired,
12392
- usHelpImage: PropTypes.node.isRequired,
12393
- usLabel: PropTypes.string.isRequired,
12394
- usPlaceholder: PropTypes.string.isRequired
12395
- };
12396
-
12397
- const ProcessingStep = props => {
12398
- const {
12399
- isComplete,
12400
- isError,
12401
- isSuccess,
12402
- onAnimationCompleted,
12403
- onClear,
12404
- psButtonText,
12405
- psProcessingText,
12406
- psButtonDisabled
12407
- } = props;
12408
- const {
12409
- isModern
12410
- } = useTheme();
12177
+ isError,
12178
+ isSuccess,
12179
+ onAnimationCompleted,
12180
+ onClear,
12181
+ psButtonText,
12182
+ psProcessingText,
12183
+ psButtonDisabled
12184
+ }) {
12411
12185
  let processStatus = Status.PROCESSING;
12412
12186
  if (isError) {
12413
12187
  processStatus = Status.FAILED;
@@ -12421,53 +12195,33 @@ const ProcessingStep = props => {
12421
12195
  children: /*#__PURE__*/jsxs("div", {
12422
12196
  className: "droppable-card-content",
12423
12197
  children: [/*#__PURE__*/jsx(ProcessIndicator, {
12424
- size: Size.Small,
12425
12198
  status: processStatus,
12426
12199
  onAnimationCompleted: status => onAnimationCompleted(status)
12427
12200
  }), /*#__PURE__*/jsx(Title, {
12428
- className: classNames({
12429
- 'm-t-3': !isModern,
12430
- 'm-b-3': !isModern,
12431
- 'm-t-2': isModern,
12432
- 'm-b-2': isModern
12433
- }),
12201
+ className: "m-y-2",
12434
12202
  type: Typography.TITLE_BODY,
12435
12203
  "aria-live": "polite",
12436
12204
  children: psProcessingText
12437
12205
  }), psButtonText && /*#__PURE__*/jsx(Button, {
12438
12206
  disabled: psButtonDisabled,
12439
- onClick: event => onClear(event),
12207
+ onClick: onClear,
12440
12208
  children: psButtonText
12441
12209
  })]
12442
12210
  })
12443
12211
  });
12444
- };
12445
- ProcessingStep.propTypes = {
12446
- isComplete: PropTypes.bool.isRequired,
12447
- isError: PropTypes.bool.isRequired,
12448
- isSuccess: PropTypes.bool.isRequired,
12449
- onAnimationCompleted: PropTypes.func.isRequired,
12450
- onClear: PropTypes.func.isRequired,
12451
- psButtonText: PropTypes.string.isRequired,
12452
- psProcessingText: PropTypes.string.isRequired,
12453
- psButtonDisabled: PropTypes.bool.isRequired
12454
- };
12212
+ }
12455
12213
 
12456
- const CompleteStep = props => {
12457
- const {
12458
- isModern
12459
- } = useTheme();
12460
- const {
12461
- csButtonText,
12462
- csFailureText,
12463
- csSuccessText,
12464
- fileName,
12465
- isComplete,
12466
- isError,
12467
- isImage,
12468
- onClear,
12469
- uploadedImage
12470
- } = props;
12214
+ function CompleteStep({
12215
+ csButtonText,
12216
+ csFailureText,
12217
+ csSuccessText,
12218
+ fileName,
12219
+ isComplete,
12220
+ isError,
12221
+ isImage,
12222
+ onClear,
12223
+ uploadedImage
12224
+ }) {
12471
12225
  return /*#__PURE__*/jsx("div", {
12472
12226
  className: "droppable-complete-card droppable-card",
12473
12227
  "aria-hidden": !isComplete,
@@ -12477,16 +12231,11 @@ const CompleteStep = props => {
12477
12231
  className: "droppable-card-content d-flex flex-column align-items-center",
12478
12232
  "aria-live": "polite",
12479
12233
  children: isError ? /*#__PURE__*/jsxs(Fragment, {
12480
- children: [isModern ? /*#__PURE__*/jsx(StatusIcon, {
12234
+ children: [/*#__PURE__*/jsx(StatusIcon, {
12481
12235
  size: Size.LARGE,
12482
12236
  sentiment: Sentiment.NEGATIVE
12483
- }) : /*#__PURE__*/jsx(AlertCircle, {
12484
- size: 24,
12485
- className: "text-negative"
12486
12237
  }), csFailureText && /*#__PURE__*/jsx("p", {
12487
- className: classNames('m-t-2', {
12488
- 'm-b-0': isModern
12489
- }),
12238
+ className: "m-t-2 m-b-0",
12490
12239
  children: csFailureText
12491
12240
  })]
12492
12241
  }) : /*#__PURE__*/jsxs(Fragment, {
@@ -12505,71 +12254,135 @@ const CompleteStep = props => {
12505
12254
  })]
12506
12255
  })
12507
12256
  }), csButtonText && /*#__PURE__*/jsx(Button, {
12508
- priority: isModern ? Priority.PRIMARY : Priority.SECONDARY,
12509
- className: classNames({
12510
- 'm-t-1': isModern && !isError,
12511
- 'm-t-2': isModern && isError,
12512
- 'm-t-3': !isModern
12513
- }),
12514
- onClick: event => onClear(event),
12257
+ className: isError ? 'm-t-2' : 'm-t-1',
12258
+ onClick: onClear,
12515
12259
  children: csButtonText
12516
12260
  })]
12517
12261
  })
12518
12262
  });
12519
- };
12520
- CompleteStep.propTypes = {
12521
- csButtonText: PropTypes.string.isRequired,
12522
- csSuccessText: PropTypes.string.isRequired,
12523
- csFailureText: PropTypes.string.isRequired,
12524
- fileName: PropTypes.string.isRequired,
12525
- isComplete: PropTypes.bool.isRequired,
12526
- isError: PropTypes.bool.isRequired,
12527
- isImage: PropTypes.bool.isRequired,
12528
- onClear: PropTypes.func.isRequired,
12529
- uploadedImage: PropTypes.string
12530
- };
12531
- CompleteStep.defaultProps = {
12532
- uploadedImage: null
12533
- };
12263
+ }
12264
+
12265
+ class ResponseError extends Error {
12266
+ response;
12267
+ status;
12268
+ constructor(response, message) {
12269
+ super(message);
12270
+ this.name = 'ResponseError';
12271
+ this.response = response;
12272
+ this.status = response.status;
12273
+ }
12274
+ }
12275
+ async function postData({
12276
+ url,
12277
+ method = 'POST',
12278
+ ...httpOptions
12279
+ }, data, fetcher = fetch) {
12280
+ const response = await fetcher(url, {
12281
+ method,
12282
+ body: data,
12283
+ ...httpOptions
12284
+ });
12285
+ if (!response.ok) {
12286
+ throw new ResponseError(response, response.statusText);
12287
+ }
12288
+ return response;
12289
+ }
12534
12290
 
12535
- const PROCESS_STATE = ['error', 'success'];
12291
+ async function asyncFileRead(file) {
12292
+ return new Promise((resolve, reject) => {
12293
+ const reader = new FileReader();
12294
+ reader.addEventListener('load', () => {
12295
+ resolve(reader.result);
12296
+ });
12297
+ reader.addEventListener('error', () => {
12298
+ reject(reader.error ?? new Error('Cannot read file'));
12299
+ });
12300
+ reader.readAsDataURL(file);
12301
+ });
12302
+ }
12303
+
12304
+ function isSizeValid(file, maxSize) {
12305
+ return Number.isInteger(maxSize) && file.size <= maxSize;
12306
+ }
12307
+
12308
+ function getFileType(file, file64) {
12309
+ if (file.type) {
12310
+ return file.type;
12311
+ }
12312
+ if (file64) {
12313
+ const regex = /^data:([a-z]+\/[a-z]+);/;
12314
+ const typeFromEncoded = regex.exec(file64);
12315
+ if (typeFromEncoded?.[1]) {
12316
+ return typeFromEncoded[1];
12317
+ }
12318
+ }
12319
+ return '';
12320
+ }
12321
+
12322
+ function isTypeValid(file, rule, file64) {
12323
+ if (!rule) {
12324
+ return false;
12325
+ }
12326
+ const allowedTypes = rule.replace(/\s/g, '').split(',');
12327
+ const fileType = getFileType(file, file64);
12328
+ if (rule === '*' || allowedTypes.includes(fileType)) {
12329
+ return true;
12330
+ }
12331
+ return allowedTypes.some(type => {
12332
+ const [typeAllowed, extensionAllowed] = type.split('/');
12333
+ return extensionAllowed === '*' && fileType.includes(typeAllowed);
12334
+ });
12335
+ }
12536
12336
 
12537
- /*
12538
- * This delay is required for the isError/isSuccess to be fired after isProcessing so the processIndicator, will be
12539
- * rendered first and then updated with the right status.
12540
- */
12541
12337
  const ANIMATION_FIX = 10;
12542
12338
  const MAX_SIZE_DEFAULT = 5000000;
12543
- const UPLOAD_STEP_COMPONENTS = {
12544
- [UploadStep.UPLOAD_IMAGE_STEP]: UploadImageStep,
12545
- [UploadStep.MEDIA_UPLOAD_STEP]: MediaUploadStep
12546
- };
12339
+ var UploadStep;
12340
+ (function (UploadStep) {
12341
+ UploadStep["UPLOAD_IMAGE_STEP"] = "uploadImageStep";
12342
+ })(UploadStep || (UploadStep = {}));
12547
12343
  class Upload extends Component {
12344
+ static defaultProps = {
12345
+ animationDelay: 700,
12346
+ maxSize: MAX_SIZE_DEFAULT,
12347
+ psButtonDisabled: false,
12348
+ size: 'md',
12349
+ usAccept: 'image/*',
12350
+ usDisabled: false,
12351
+ usLabel: ''
12352
+ };
12353
+ dragCounter = 0;
12354
+ timeouts = 0;
12548
12355
  constructor(props) {
12549
12356
  super(props);
12550
- this.dragCounter = 0;
12551
- this.timeouts = null;
12552
12357
  this.state = {
12553
12358
  fileName: '',
12359
+ isDroppable: false,
12554
12360
  isComplete: false,
12555
12361
  isError: false,
12556
12362
  isImage: false,
12557
12363
  isProcessing: false,
12558
12364
  isSuccess: false,
12559
- response: null,
12560
- uploadedImage: null
12365
+ response: undefined,
12366
+ uploadedImage: undefined
12561
12367
  };
12562
12368
  }
12563
12369
  getErrorMessage(status) {
12370
+ const {
12371
+ csFailureText,
12372
+ csTooLargeMessage,
12373
+ csWrongTypeMessage,
12374
+ maxSize,
12375
+ intl
12376
+ } = this.props;
12564
12377
  switch (status) {
12565
12378
  case 413:
12566
- return this.props.csTooLargeMessage || this.props.intl.formatMessage(messages.csTooLargeMessage, {
12567
- maxSize: this.props.maxSize / 1000000
12379
+ return csTooLargeMessage || intl.formatMessage(messages.csTooLargeMessage, {
12380
+ maxSize: maxSize / 1000000
12568
12381
  });
12569
12382
  case 415:
12570
- return this.props.csWrongTypeMessage || this.props.intl.formatMessage(messages.csWrongTypeMessage);
12383
+ return csWrongTypeMessage || intl.formatMessage(messages.csWrongTypeMessage);
12571
12384
  default:
12572
- return this.props.csFailureText || this.props.intl.formatMessage(messages.csFailureText);
12385
+ return csFailureText || intl.formatMessage(messages.csFailureText);
12573
12386
  }
12574
12387
  }
12575
12388
  onDragLeave(event) {
@@ -12596,7 +12409,7 @@ class Upload extends Component {
12596
12409
  });
12597
12410
  }
12598
12411
  }
12599
- onDrop(event) {
12412
+ async onDrop(event) {
12600
12413
  const {
12601
12414
  isProcessing
12602
12415
  } = this.state;
@@ -12604,8 +12417,8 @@ class Upload extends Component {
12604
12417
  if (!isProcessing) {
12605
12418
  this.reset();
12606
12419
  }
12607
- if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {
12608
- this.fileDropped(event.dataTransfer.files[0]);
12420
+ if (event.dataTransfer?.files?.[0]) {
12421
+ await this.fileDropped(event.dataTransfer.files[0]);
12609
12422
  }
12610
12423
  }
12611
12424
  onAnimationCompleted = async status => {
@@ -12614,77 +12427,70 @@ class Upload extends Component {
12614
12427
  isProcessing,
12615
12428
  fileName
12616
12429
  } = this.state;
12617
- // Success.
12618
12430
  const {
12619
12431
  animationDelay
12620
12432
  } = this.props;
12621
- if (isProcessing && status === Status.SUCCEEDED) {
12433
+ if (isProcessing && status === 'succeeded') {
12622
12434
  const {
12623
12435
  onSuccess
12624
12436
  } = this.props;
12625
- this.timeouts = setTimeout(() => {
12437
+ this.timeouts = window.setTimeout(() => {
12626
12438
  this.setState({
12627
12439
  isProcessing: false,
12628
12440
  isComplete: true
12629
- }, () => onSuccess ? onSuccess(response, fileName) : {});
12441
+ }, onSuccess ? () => onSuccess(response, fileName) : undefined);
12630
12442
  }, animationDelay);
12631
12443
  }
12632
- // Failure.
12633
- if (isProcessing && status === Status.FAILED) {
12444
+ if (isProcessing && status === 'failed') {
12634
12445
  const {
12635
12446
  onFailure
12636
12447
  } = this.props;
12637
- this.timeouts = setTimeout(() => {
12448
+ this.timeouts = window.setTimeout(() => {
12638
12449
  this.setState({
12639
12450
  isProcessing: false,
12640
12451
  isComplete: true
12641
- }, () => onFailure ? onFailure(response) : {});
12452
+ }, onFailure ? () => onFailure(response) : undefined);
12642
12453
  }, animationDelay);
12643
12454
  }
12644
12455
  };
12645
- asyncPost = file => {
12456
+ asyncPost = async file => {
12646
12457
  const {
12647
12458
  httpOptions,
12648
12459
  fetcher
12649
12460
  } = this.props;
12461
+ if (httpOptions == null) {
12462
+ throw new Error('Cannot find HTTP options');
12463
+ }
12650
12464
  const {
12651
12465
  fileInputName = file.name,
12652
12466
  data = {}
12653
- } = httpOptions || {};
12467
+ } = httpOptions;
12654
12468
  const formData = new FormData();
12655
12469
  formData.append(fileInputName, file);
12656
12470
  Object.keys(data).forEach(key => formData.append(key, data[key]));
12657
- return postData(this.prepareHttpOptions(httpOptions), formData, fetcher);
12471
+ return postData(httpOptions, formData, fetcher);
12658
12472
  };
12659
12473
  asyncResponse = (response, type) => {
12660
12474
  // Gives time to the animation callback to fire.
12661
- this.timeouts = setTimeout(() => {
12475
+ this.timeouts = window.setTimeout(() => {
12662
12476
  this.setState({
12663
12477
  response,
12664
- isError: type === PROCESS_STATE[0],
12665
- isSuccess: type === PROCESS_STATE[1]
12478
+ isError: type === 'error',
12479
+ isSuccess: type === 'success'
12666
12480
  });
12667
12481
  }, ANIMATION_FIX);
12668
12482
  };
12669
- prepareHttpOptions = httpOptions => {
12670
- if (!httpOptions.url) {
12671
- throw new Error('You must supply a URL to post image data asynchronously');
12672
- }
12673
- return httpOptions;
12674
- };
12675
12483
  handleOnClear = event => {
12676
12484
  event.preventDefault();
12677
12485
  const {
12678
12486
  onCancel
12679
12487
  } = this.props;
12680
- if (onCancel) {
12681
- onCancel();
12682
- }
12488
+ onCancel?.();
12683
12489
  this.reset();
12684
12490
  };
12685
12491
  reset = () => {
12686
12492
  this.dragCounter = 0;
12687
- clearTimeout(this.timeouts);
12493
+ window.clearTimeout(this.timeouts);
12688
12494
  this.setState({
12689
12495
  isComplete: false,
12690
12496
  isError: false,
@@ -12724,14 +12530,12 @@ class Upload extends Component {
12724
12530
  isDroppable: false,
12725
12531
  isProcessing: true
12726
12532
  });
12727
- if (onStart) {
12728
- onStart(file);
12729
- }
12533
+ onStart?.(file);
12730
12534
  let file64 = null;
12731
12535
  try {
12732
12536
  file64 = await asyncFileRead(file);
12733
12537
  } catch (error) {
12734
- this.asyncResponse(error, PROCESS_STATE[0]);
12538
+ this.asyncResponse(error, 'error');
12735
12539
  }
12736
12540
  if (!file64) {
12737
12541
  return false;
@@ -12740,30 +12544,31 @@ class Upload extends Component {
12740
12544
  isImage: getFileType(file, file64).includes('image')
12741
12545
  });
12742
12546
  if (!isTypeValid(file, usAccept, file64)) {
12743
- const response = {
12547
+ this.asyncResponse(new ResponseError(new Response(null, {
12744
12548
  status: 415,
12745
12549
  statusText: 'Unsupported Media Type'
12746
- };
12747
- this.asyncResponse(response, PROCESS_STATE[0]);
12550
+ })), 'error');
12748
12551
  return false;
12749
12552
  }
12750
12553
  if (!isSizeValid(file, maxSize)) {
12751
- const response = {
12554
+ this.asyncResponse(new ResponseError(new Response(null, {
12752
12555
  status: 413,
12753
12556
  statusText: 'Request Entity Too Large'
12754
- };
12755
- this.asyncResponse(response, PROCESS_STATE[0]);
12557
+ })), 'error');
12756
12558
  return false;
12757
12559
  }
12758
12560
  if (httpOptions) {
12759
12561
  // Post the file to provided endpoint
12760
- return await this.asyncPost(file).then(response => this.asyncResponse(response, 'success')).then(() => {
12761
- this.showDataImage(file64);
12762
- return true;
12763
- }).catch(error => {
12764
- this.asyncResponse(error, PROCESS_STATE[0]);
12562
+ let response;
12563
+ try {
12564
+ response = await this.asyncPost(file);
12565
+ } catch (error) {
12566
+ this.asyncResponse(error, 'error');
12765
12567
  return false;
12766
- });
12568
+ }
12569
+ this.asyncResponse(response, 'success');
12570
+ this.showDataImage(file64);
12571
+ return true;
12767
12572
  }
12768
12573
  // Post on form submit. And return the encoded image.
12769
12574
  this.showDataImage(file64);
@@ -12772,6 +12577,7 @@ class Upload extends Component {
12772
12577
  };
12773
12578
  render() {
12774
12579
  const {
12580
+ maxSize,
12775
12581
  usDropMessage,
12776
12582
  usAccept,
12777
12583
  usButtonText,
@@ -12785,7 +12591,6 @@ class Upload extends Component {
12785
12591
  csButtonText,
12786
12592
  csSuccessText,
12787
12593
  size,
12788
- uploadStep,
12789
12594
  intl
12790
12595
  } = this.props;
12791
12596
  const {
@@ -12799,7 +12604,6 @@ class Upload extends Component {
12799
12604
  isSuccess,
12800
12605
  uploadedImage
12801
12606
  } = this.state;
12802
- const UploadStepComponent = UPLOAD_STEP_COMPONENTS[uploadStep] || UploadImageStep;
12803
12607
  return /*#__PURE__*/jsxs("div", {
12804
12608
  className: classNames('droppable-area', {
12805
12609
  droppable: true,
@@ -12813,10 +12617,10 @@ class Upload extends Component {
12813
12617
  }),
12814
12618
  onDragEnter: event => this.onDragEnter(event),
12815
12619
  onDragLeave: event => this.onDragLeave(event),
12816
- onDrop: event => this.onDrop(event),
12620
+ onDrop: async event => this.onDrop(event),
12817
12621
  onDragOver: event => event.preventDefault(),
12818
- children: [!isProcessing && !isComplete && /*#__PURE__*/jsx(UploadStepComponent, {
12819
- fileDropped: file => this.fileDropped(file),
12622
+ children: [!isProcessing && !isComplete && /*#__PURE__*/jsx(UploadImageStep, {
12623
+ fileDropped: async file => this.fileDropped(file),
12820
12624
  isComplete: isComplete,
12821
12625
  usAccept: usAccept,
12822
12626
  usButtonText: usButtonText || intl.formatMessage(messages.usButtonText),
@@ -12824,7 +12628,7 @@ class Upload extends Component {
12824
12628
  usHelpImage: usHelpImage,
12825
12629
  usLabel: usLabel,
12826
12630
  usPlaceholder: usPlaceholder || intl.formatMessage(messages.usPlaceholder, {
12827
- maxSize: this.props.maxSize / 1000000
12631
+ maxSize: maxSize / 1000000
12828
12632
  })
12829
12633
  }), isProcessing && /*#__PURE__*/jsx(ProcessingStep, {
12830
12634
  isComplete: isComplete,
@@ -12833,7 +12637,7 @@ class Upload extends Component {
12833
12637
  psButtonText: psButtonText || intl.formatMessage(messages.psButtonText),
12834
12638
  psProcessingText: psProcessingText || intl.formatMessage(messages.psProcessingText),
12835
12639
  psButtonDisabled: psButtonDisabled,
12836
- onAnimationCompleted: status => this.onAnimationCompleted(status),
12640
+ onAnimationCompleted: async status => this.onAnimationCompleted(status),
12837
12641
  onClear: event => this.handleOnClear(event)
12838
12642
  }), (isSuccess || isError || isComplete) && /*#__PURE__*/jsx(CompleteStep, {
12839
12643
  fileName: fileName,
@@ -12841,7 +12645,7 @@ class Upload extends Component {
12841
12645
  isError: isError,
12842
12646
  isImage: isImage,
12843
12647
  csButtonText: csButtonText || intl.formatMessage(messages.csButtonText),
12844
- csFailureText: this.getErrorMessage(response?.status),
12648
+ csFailureText: this.getErrorMessage(response != null && typeof response === 'object' && 'status' in response && typeof response.status === 'number' ? response.status : undefined),
12845
12649
  csSuccessText: csSuccessText || intl.formatMessage(messages.csSuccessText),
12846
12650
  uploadedImage: uploadedImage,
12847
12651
  onClear: event => this.handleOnClear(event)
@@ -12865,73 +12669,6 @@ class Upload extends Component {
12865
12669
  });
12866
12670
  }
12867
12671
  }
12868
- Upload.propTypes = {
12869
- animationDelay: PropTypes.number,
12870
- csButtonText: PropTypes.string,
12871
- csFailureText: PropTypes.string,
12872
- csSuccessText: PropTypes.string,
12873
- csTooLargeMessage: PropTypes.string,
12874
- csWrongTypeMessage: PropTypes.string,
12875
- httpOptions: PropTypes.shape({
12876
- url: PropTypes.string.isRequired,
12877
- method: PropTypes.oneOf(['POST', 'PUT', 'PATCH']),
12878
- fileInputName: PropTypes.string,
12879
- data: PropTypes.object,
12880
- headers: PropTypes.object
12881
- }),
12882
- /**
12883
- * You can provide a fetcher function with the same interface as the global fetch function, which is used by default.
12884
- * function fetcher(input: RequestInfo, init?: RequestInit): Promise<Response>
12885
- */
12886
- fetcher: PropTypes.func,
12887
- maxSize: PropTypes.number,
12888
- onCancel: PropTypes.func,
12889
- onFailure: PropTypes.func,
12890
- onStart: PropTypes.func,
12891
- onSuccess: PropTypes.func,
12892
- psButtonText: PropTypes.string,
12893
- psButtonDisabled: PropTypes.bool,
12894
- psProcessingText: PropTypes.string,
12895
- size: PropTypes.oneOf(['sm', 'md', 'lg']),
12896
- /**
12897
- * You can provide multiple rules separated by comma, e.g.: "application/pdf,image/*".
12898
- * Using "*" will allow every file type to be uploaded.
12899
- */
12900
- usAccept: PropTypes.string,
12901
- usButtonText: PropTypes.string,
12902
- usDisabled: PropTypes.bool,
12903
- usDropMessage: PropTypes.string,
12904
- usHelpImage: PropTypes.node,
12905
- usLabel: PropTypes.string,
12906
- usPlaceholder: PropTypes.string,
12907
- uploadStep: PropTypes.oneOf(['uploadImageStep', 'mediaUploadStep'])
12908
- };
12909
- Upload.defaultProps = {
12910
- animationDelay: 700,
12911
- csButtonText: undefined,
12912
- csFailureText: undefined,
12913
- csSuccessText: undefined,
12914
- csTooLargeMessage: undefined,
12915
- csWrongTypeMessage: undefined,
12916
- httpOptions: null,
12917
- maxSize: MAX_SIZE_DEFAULT,
12918
- onCancel: null,
12919
- onFailure: null,
12920
- onStart: null,
12921
- onSuccess: null,
12922
- psButtonText: undefined,
12923
- psButtonDisabled: false,
12924
- psProcessingText: undefined,
12925
- size: 'md',
12926
- usAccept: 'image/*',
12927
- usButtonText: undefined,
12928
- usDisabled: false,
12929
- usDropMessage: undefined,
12930
- usHelpImage: '',
12931
- usLabel: '',
12932
- usPlaceholder: undefined,
12933
- uploadStep: UploadStep.UPLOAD_IMAGE_STEP
12934
- };
12935
12672
  var Upload$1 = injectIntl(Upload);
12936
12673
 
12937
12674
  var MESSAGES$2 = defineMessages({
@@ -13462,7 +13199,7 @@ const UploadInput = ({
13462
13199
  name
13463
13200
  } = file;
13464
13201
  const id = generateFileId(file);
13465
- const allowedFileTypes = Array.isArray(fileTypes) ? fileTypes.join(',') : fileTypes;
13202
+ const allowedFileTypes = typeof fileTypes === 'string' ? fileTypes : fileTypes.join(',');
13466
13203
  // Check if file type is valid
13467
13204
  if (!isTypeValid(file, allowedFileTypes)) {
13468
13205
  handleFileUploadFailure(file, formatMessage(MESSAGES$2.fileTypeNotSupported));
@@ -14589,5 +14326,5 @@ const translations = {
14589
14326
  'zh-HK': zhHK
14590
14327
  };
14591
14328
 
14592
- export { Accordion, ActionButton, ActionOption, Alert, AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card$1 as BaseCard, Body, BottomSheet$1 as BottomSheet, Breakpoint, Button, Card, Carousel, Checkbox, CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput, DateLookup$1 as DateLookup, DateMode, Decision, DecisionPresentation, DecisionType, DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer, DropFade, Emphasis, Field, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList, Label, LanguageProvider, Layout, Link, ListItem$1 as ListItem, Loader, Logo, LogoType, Markdown, MarkdownNodeType, Modal, Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput, Popover$1 as Popover, Position, Priority, ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCardGroup$1 as PromoCardGroup, Provider, RTL_LANGUAGES, Radio, RadioGroup, RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, SegmentedControl, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider, Status, StatusIcon, Stepper, Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip, Type, Typeahead$1 as Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
14329
+ export { Accordion, ActionButton, ActionOption, Alert, AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card$1 as BaseCard, Body, BottomSheet$1 as BottomSheet, Breakpoint, Button, Card, Carousel, Checkbox, CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput, DateLookup$1 as DateLookup, DateMode, Decision, DecisionPresentation, DecisionType, DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer, DropFade, Emphasis, Field, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList, Label, LanguageProvider, Layout, Link, ListItem$1 as ListItem, Loader, Logo, LogoType, Markdown, MarkdownNodeType, Modal, Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader, PhoneNumberInput, Popover$1 as Popover, Position, Priority, ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCardGroup$1 as PromoCardGroup, Provider, RTL_LANGUAGES, Radio, RadioGroup, RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, SegmentedControl, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider, Status, StatusIcon, Stepper, Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip, Type, Typeahead$1 as Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
14593
14330
  //# sourceMappingURL=index.mjs.map