@transferwise/components 46.39.0 → 46.41.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 (146) hide show
  1. package/build/index.js +244 -493
  2. package/build/index.js.map +1 -1
  3. package/build/index.mjs +245 -494
  4. package/build/index.mjs.map +1 -1
  5. package/build/main.css +4 -2
  6. package/build/styles/main.css +4 -2
  7. package/build/styles/statusIcon/StatusIcon.css +4 -2
  8. package/build/types/dateInput/DateInput.d.ts.map +1 -1
  9. package/build/types/field/Field.d.ts +6 -1
  10. package/build/types/field/Field.d.ts.map +1 -1
  11. package/build/types/index.d.ts +2 -1
  12. package/build/types/index.d.ts.map +1 -1
  13. package/build/types/inlineAlert/InlineAlert.d.ts +2 -2
  14. package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
  15. package/build/types/processIndicator/ProcessIndicator.d.ts +1 -1
  16. package/build/types/processIndicator/ProcessIndicator.d.ts.map +1 -1
  17. package/build/types/upload/Upload.d.ts +91 -55
  18. package/build/types/upload/Upload.d.ts.map +1 -1
  19. package/build/types/upload/Upload.messages.d.ts +42 -60
  20. package/build/types/upload/Upload.messages.d.ts.map +1 -1
  21. package/build/types/upload/index.d.ts +2 -2
  22. package/build/types/upload/index.d.ts.map +1 -1
  23. package/build/types/upload/steps/completeStep/completeStep.d.ts +11 -18
  24. package/build/types/upload/steps/completeStep/completeStep.d.ts.map +1 -1
  25. package/build/types/upload/steps/completeStep/index.d.ts +2 -1
  26. package/build/types/upload/steps/completeStep/index.d.ts.map +1 -1
  27. package/build/types/upload/steps/index.d.ts +3 -4
  28. package/build/types/upload/steps/index.d.ts.map +1 -1
  29. package/build/types/upload/steps/processingStep/index.d.ts +2 -1
  30. package/build/types/upload/steps/processingStep/index.d.ts.map +1 -1
  31. package/build/types/upload/steps/processingStep/processingStep.d.ts +11 -13
  32. package/build/types/upload/steps/processingStep/processingStep.d.ts.map +1 -1
  33. package/build/types/upload/steps/uploadImageStep/index.d.ts +2 -1
  34. package/build/types/upload/steps/uploadImageStep/index.d.ts.map +1 -1
  35. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts +14 -18
  36. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts.map +1 -1
  37. package/build/types/upload/utils/asyncFileRead/asyncFileRead.d.ts +1 -1
  38. package/build/types/upload/utils/asyncFileRead/asyncFileRead.d.ts.map +1 -1
  39. package/build/types/upload/utils/asyncFileRead/index.d.ts +1 -1
  40. package/build/types/upload/utils/asyncFileRead/index.d.ts.map +1 -1
  41. package/build/types/upload/utils/getFileType/getFileType.d.ts +1 -1
  42. package/build/types/upload/utils/getFileType/getFileType.d.ts.map +1 -1
  43. package/build/types/upload/utils/getFileType/index.d.ts +1 -1
  44. package/build/types/upload/utils/getFileType/index.d.ts.map +1 -1
  45. package/build/types/upload/utils/index.d.ts +5 -7
  46. package/build/types/upload/utils/index.d.ts.map +1 -1
  47. package/build/types/upload/utils/isSizeValid/index.d.ts +1 -1
  48. package/build/types/upload/utils/isSizeValid/index.d.ts.map +1 -1
  49. package/build/types/upload/utils/isSizeValid/isSizeValid.d.ts +1 -1
  50. package/build/types/upload/utils/isSizeValid/isSizeValid.d.ts.map +1 -1
  51. package/build/types/upload/utils/isTypeValid/index.d.ts +1 -1
  52. package/build/types/upload/utils/isTypeValid/index.d.ts.map +1 -1
  53. package/build/types/upload/utils/isTypeValid/isTypeValid.d.ts +1 -1
  54. package/build/types/upload/utils/isTypeValid/isTypeValid.d.ts.map +1 -1
  55. package/build/types/upload/utils/postData/index.d.ts +1 -1
  56. package/build/types/upload/utils/postData/index.d.ts.map +1 -1
  57. package/build/types/upload/utils/postData/postData.d.ts +11 -1
  58. package/build/types/upload/utils/postData/postData.d.ts.map +1 -1
  59. package/package.json +2 -2
  60. package/src/dateInput/DateInput.spec.tsx +220 -0
  61. package/src/dateInput/DateInput.story.tsx +3 -76
  62. package/src/dateInput/DateInput.tests.story.tsx +238 -0
  63. package/src/dateInput/DateInput.tsx +50 -53
  64. package/src/field/Field.story.tsx +17 -36
  65. package/src/field/Field.tests.story.tsx +33 -0
  66. package/src/field/Field.tsx +23 -13
  67. package/src/index.ts +2 -1
  68. package/src/inlineAlert/InlineAlert.story.tsx +13 -5
  69. package/src/inlineAlert/InlineAlert.tsx +14 -7
  70. package/src/main.css +4 -2
  71. package/src/processIndicator/ProcessIndicator.tsx +1 -1
  72. package/src/statusIcon/StatusIcon.css +4 -2
  73. package/src/statusIcon/StatusIcon.less +4 -2
  74. package/src/statusIcon/StatusIcon.tsx +1 -1
  75. package/src/upload/Upload.spec.js +3 -14
  76. package/src/upload/Upload.story.tsx +37 -0
  77. package/src/upload/{Upload.js → Upload.tsx} +164 -169
  78. package/src/upload/index.ts +2 -0
  79. package/src/upload/steps/completeStep/completeStep.spec.js +3 -2
  80. package/src/upload/steps/completeStep/completeStep.tsx +74 -0
  81. package/src/upload/steps/completeStep/index.ts +2 -0
  82. package/src/upload/steps/{index.js → index.ts} +0 -1
  83. package/src/upload/steps/processingStep/index.ts +2 -0
  84. package/src/upload/steps/processingStep/processingStep.tsx +53 -0
  85. package/src/upload/steps/uploadImageStep/index.ts +2 -0
  86. package/src/upload/steps/uploadImageStep/{uploadImageStep.js → uploadImageStep.tsx} +17 -23
  87. package/src/upload/utils/asyncFileRead/asyncFileRead.spec.ts +14 -0
  88. package/src/upload/utils/asyncFileRead/asyncFileRead.ts +12 -0
  89. package/src/upload/utils/getFileType/getFileType.spec.ts +22 -0
  90. package/src/upload/utils/getFileType/getFileType.ts +16 -0
  91. package/src/upload/utils/{index.js → index.ts} +0 -2
  92. package/src/upload/utils/isSizeValid/{isSizeValid.spec.js → isSizeValid.spec.ts} +3 -3
  93. package/src/upload/utils/isSizeValid/isSizeValid.ts +3 -0
  94. package/src/upload/utils/isTypeValid/isTypeValid.spec.ts +62 -0
  95. package/src/upload/utils/isTypeValid/isTypeValid.ts +19 -0
  96. package/src/upload/utils/postData/postData.spec.ts +65 -0
  97. package/src/upload/utils/postData/postData.ts +36 -0
  98. package/src/uploadInput/UploadInput.tsx +1 -1
  99. package/build/types/upload/steps/mediaUploadStep/index.d.ts +0 -2
  100. package/build/types/upload/steps/mediaUploadStep/index.d.ts.map +0 -1
  101. package/build/types/upload/steps/mediaUploadStep/mediaUploadStep.d.ts +0 -24
  102. package/build/types/upload/steps/mediaUploadStep/mediaUploadStep.d.ts.map +0 -1
  103. package/build/types/upload/uploadSteps.d.ts +0 -5
  104. package/build/types/upload/uploadSteps.d.ts.map +0 -1
  105. package/build/types/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.d.ts +0 -2
  106. package/build/types/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.d.ts.map +0 -1
  107. package/build/types/upload/utils/getSupportedSpotMimeTypes/index.d.ts +0 -2
  108. package/build/types/upload/utils/getSupportedSpotMimeTypes/index.d.ts.map +0 -1
  109. package/build/types/upload/utils/requestMedia/index.d.ts +0 -2
  110. package/build/types/upload/utils/requestMedia/index.d.ts.map +0 -1
  111. package/build/types/upload/utils/requestMedia/requestMedia.d.ts +0 -2
  112. package/build/types/upload/utils/requestMedia/requestMedia.d.ts.map +0 -1
  113. package/src/dateInput/DateInput.rtl.spec.tsx +0 -17
  114. package/src/dateInput/DateInput.spec.js +0 -477
  115. package/src/upload/Upload.story.js +0 -36
  116. package/src/upload/index.js +0 -2
  117. package/src/upload/steps/completeStep/completeStep.js +0 -98
  118. package/src/upload/steps/completeStep/index.js +0 -1
  119. package/src/upload/steps/mediaUploadStep/index.js +0 -1
  120. package/src/upload/steps/mediaUploadStep/mediaUploadStep.js +0 -80
  121. package/src/upload/steps/mediaUploadStep/mediaUploadStep.spec.js +0 -77
  122. package/src/upload/steps/processingStep/index.js +0 -1
  123. package/src/upload/steps/processingStep/processingStep.js +0 -73
  124. package/src/upload/steps/uploadImageStep/index.js +0 -1
  125. package/src/upload/uploadSteps.ts +0 -5
  126. package/src/upload/utils/asyncFileRead/asyncFileRead.js +0 -11
  127. package/src/upload/utils/asyncFileRead/asyncFileRead.spec.js +0 -17
  128. package/src/upload/utils/getFileType/getFileType.js +0 -19
  129. package/src/upload/utils/getFileType/getFileType.spec.js +0 -33
  130. package/src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.js +0 -18
  131. package/src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.spec.js +0 -22
  132. package/src/upload/utils/getSupportedSpotMimeTypes/index.js +0 -1
  133. package/src/upload/utils/isSizeValid/isSizeValid.js +0 -1
  134. package/src/upload/utils/isTypeValid/isTypeValid.js +0 -26
  135. package/src/upload/utils/isTypeValid/isTypeValid.spec.js +0 -68
  136. package/src/upload/utils/postData/postData.js +0 -18
  137. package/src/upload/utils/postData/postData.spec.js +0 -109
  138. package/src/upload/utils/requestMedia/index.js +0 -1
  139. package/src/upload/utils/requestMedia/requestMedia.js +0 -26
  140. package/src/upload/utils/requestMedia/requestMedia.spec.js +0 -44
  141. /package/src/upload/{Upload.messages.js → Upload.messages.ts} +0 -0
  142. /package/src/upload/utils/asyncFileRead/{index.js → index.ts} +0 -0
  143. /package/src/upload/utils/getFileType/{index.js → index.ts} +0 -0
  144. /package/src/upload/utils/isSizeValid/{index.js → index.ts} +0 -0
  145. /package/src/upload/utils/isTypeValid/{index.js → index.ts} +0 -0
  146. /package/src/upload/utils/postData/{index.js → index.ts} +0 -0
package/build/index.mjs CHANGED
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import React__default, { forwardRef, useId, cloneElement, useState, useEffect, useRef, useMemo, Component, createContext, useContext, useSyncExternalStore, useCallback, useImperativeHandle, createElement, PureComponent, createRef, isValidElement, Children, Fragment as Fragment$1 } from 'react';
3
3
  import classNames from 'classnames';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
- import { ChevronUp, CrossCircleFill, Cross, Check, Info as Info$1, Alert as Alert$1, ClockBorderless, NavigateAway, Briefcase, Person, ArrowRight, Download, ChevronLeft, ChevronRight, AlertCircleFill, AlertCircle, ArrowLeft, QuestionMarkCircle, Search, CrossCircle, ChevronDown, CheckCircleFill, ClockFill, Upload as Upload$2, Document, Plus, PlusCircle, Bin } from '@transferwise/icons';
5
+ import { ChevronUp, CrossCircleFill, Cross, Check, Info as Info$1, Alert as Alert$1, ClockBorderless, NavigateAway, Briefcase, Person, ArrowRight, Download, ChevronLeft, ChevronRight, AlertCircleFill, ArrowLeft, QuestionMarkCircle, Search, CrossCircle, ChevronDown, CheckCircleFill, ClockFill, Upload as Upload$2, Document, Plus, PlusCircle, Bin } from '@transferwise/icons';
6
6
  import { defineMessages, useIntl, injectIntl, IntlProvider } from 'react-intl';
7
7
  import commonmark from 'commonmark';
8
8
  import { useTheme, ThemeProvider } from '@wise/components-theming';
@@ -717,7 +717,7 @@ const StatusIcon = ({
717
717
  const iconColor = sentiment === 'warning' || sentiment === 'pending' ? 'dark' : 'light';
718
718
  return /*#__PURE__*/jsx("span", {
719
719
  "data-testid": "status-icon",
720
- className: classNames('status-circle', 'status-circle-' + size, sentiment),
720
+ className: classNames('status-circle', `status-circle-${size}`, sentiment),
721
721
  children: /*#__PURE__*/jsx(Icon, {
722
722
  className: classNames('status-icon', iconColor)
723
723
  })
@@ -3159,8 +3159,10 @@ const DateInput = ({
3159
3159
  return null;
3160
3160
  };
3161
3161
  const [day, setDay] = useState(() => getInitialDate('day'));
3162
+ const [displayDay, setDisplayDay] = useState(day?.toString());
3162
3163
  const [month, setMonth] = useState(() => getInitialDate('month'));
3163
3164
  const [year, setYear] = useState(() => getInitialDate('year'));
3165
+ const [displayYear, setDisplayYear] = useState(year?.toString());
3164
3166
  const [lastBroadcastedValue, setLastBroadcastedValue] = useState(getDateObject);
3165
3167
  const monthNames = getMonthNames(locale, monthFormat);
3166
3168
  dayLabel ||= formatMessage(messages$9.dayLabel);
@@ -3186,8 +3188,8 @@ const DateInput = ({
3186
3188
  const getSelectElement = () => {
3187
3189
  return /*#__PURE__*/jsxs("label", {
3188
3190
  className: "d-flex flex-column",
3189
- children: [/*#__PURE__*/jsx("span", {
3190
- className: "sr-only",
3191
+ children: [/*#__PURE__*/jsx(Body, {
3192
+ type: Typography.BODY_DEFAULT,
3191
3193
  children: monthLabel
3192
3194
  }), /*#__PURE__*/jsx(SelectInput, {
3193
3195
  name: "month",
@@ -3209,12 +3211,23 @@ const DateInput = ({
3209
3211
  })]
3210
3212
  });
3211
3213
  };
3214
+ const isDayValid = (newDay, newMonth, newYear) => {
3215
+ const maxDay = new Date(newYear, newMonth + 1, 0).getDate();
3216
+ return newDay <= maxDay;
3217
+ };
3212
3218
  const handleInternalValue = (newDay = day, newMonth = month, newYear = year) => {
3213
- if (newDay == null || newMonth == null || newYear == null) {
3219
+ if (newDay == null || newDay === 0 || newMonth == null || newYear == null || newYear === 0) {
3220
+ broadcastNewValue(null);
3221
+ return;
3222
+ }
3223
+ if (!isDayValid(newDay, newMonth, newYear)) {
3214
3224
  broadcastNewValue(null);
3215
3225
  return;
3216
3226
  }
3217
3227
  const dateValue = new Date(newYear, newMonth, newDay);
3228
+ if (newYear < 100) {
3229
+ dateValue.setFullYear(newYear);
3230
+ }
3218
3231
  if (!isDateValid(dateValue)) {
3219
3232
  broadcastNewValue(null);
3220
3233
  return;
@@ -3228,11 +3241,11 @@ const DateInput = ({
3228
3241
  }
3229
3242
  };
3230
3243
  const handleDayChange = event => {
3231
- const {
3232
- checkedDay
3233
- } = checkDate(Number.parseInt(event.target.value, 10), month, year);
3234
- setDay(checkedDay);
3235
- handleInternalValue(checkedDay, month, year);
3244
+ const newDayString = event.target.value.replace(/\D/g, '');
3245
+ const newDayNumber = Number.parseInt(newDayString, 10);
3246
+ setDay(newDayNumber);
3247
+ setDisplayDay(newDayString);
3248
+ handleInternalValue(newDayNumber, month, year);
3236
3249
  };
3237
3250
  const handleMonthChange = selectedMonth => {
3238
3251
  if (selectedMonth === null) {
@@ -3240,30 +3253,19 @@ const DateInput = ({
3240
3253
  handleInternalValue(day, null, year);
3241
3254
  return;
3242
3255
  }
3243
- const {
3244
- checkedDay
3245
- } = checkDate(day, selectedMonth, year);
3246
3256
  setMonth(selectedMonth);
3247
- if (day && checkedDay !== day) {
3248
- setDay(checkedDay);
3249
- }
3250
- handleInternalValue(checkedDay, selectedMonth, year);
3257
+ handleInternalValue(day, selectedMonth, year);
3251
3258
  };
3252
3259
  const handleYearChange = event => {
3253
- const newValue = event.target.value;
3254
- const slicedYear = newValue.length > 4 ? newValue.slice(0, 4) : newValue;
3255
- if (slicedYear.toString().length === 4) {
3256
- // Correct day based on year and month.
3257
- const {
3258
- checkedDay
3259
- } = checkDate(day, month, Number.parseInt(newValue, 10));
3260
- if (day && checkedDay !== day) {
3261
- setDay(checkedDay);
3262
- }
3263
- setYear(Number.parseInt(slicedYear, 10));
3264
- handleInternalValue(checkedDay, month, Number.parseInt(slicedYear, 10));
3260
+ const newYearString = event.target.value.replace(/\D/g, '');
3261
+ const newYearNumber = Number.parseInt(newYearString, 10);
3262
+ if (newYearString.length >= 4 && newYearString.length <= 6) {
3263
+ setYear(newYearNumber);
3264
+ setDisplayYear(newYearString);
3265
+ handleInternalValue(day, month, newYearNumber);
3265
3266
  } else {
3266
- setYear(Number.parseInt(slicedYear, 10));
3267
+ setYear(null);
3268
+ setDisplayYear(newYearString);
3267
3269
  handleInternalValue(day, month, null);
3268
3270
  }
3269
3271
  };
@@ -3273,24 +3275,6 @@ const DateInput = ({
3273
3275
  onChange(newValue != null ? getDateAsString(newValue) : null);
3274
3276
  }
3275
3277
  };
3276
- const checkDate = (newDay = null, newMonth = 0, newYear = null) => {
3277
- let checkedDay = newDay;
3278
- const maxDay = new Date(newYear || 2000, newMonth != null ? newMonth + 1 : 1, 0).getDate();
3279
- if (!newDay) {
3280
- checkedDay = null;
3281
- }
3282
- if (newDay && newDay < 0) {
3283
- checkedDay = 1;
3284
- }
3285
- if (newDay && newMonth || newDay && newDay > 31) {
3286
- checkedDay = newDay > maxDay ? maxDay : newDay;
3287
- }
3288
- return {
3289
- checkedDay,
3290
- checkedMonth: newMonth,
3291
- checkedYear: newYear
3292
- };
3293
- };
3294
3278
  const monthYearOnly = mode === DateMode.MONTH_YEAR;
3295
3279
  const monthWidth = classNames({
3296
3280
  'col-sm-8': monthYearOnly,
@@ -3306,8 +3290,8 @@ const DateInput = ({
3306
3290
  return /*#__PURE__*/jsx("div", {
3307
3291
  className: "col-sm-3",
3308
3292
  children: /*#__PURE__*/jsxs("label", {
3309
- children: [/*#__PURE__*/jsx("span", {
3310
- className: "sr-only",
3293
+ children: [/*#__PURE__*/jsx(Body, {
3294
+ type: Typography.BODY_DEFAULT,
3311
3295
  children: dayLabel
3312
3296
  }), /*#__PURE__*/jsx("div", {
3313
3297
  className: `input-group input-group-${size}`,
@@ -3317,10 +3301,12 @@ const DateInput = ({
3317
3301
  pattern: "[0-9]*",
3318
3302
  name: "day",
3319
3303
  autoComplete: dayAutoComplete,
3320
- value: day || '',
3304
+ value: displayDay || '',
3321
3305
  placeholder: placeholders?.day,
3322
3306
  disabled: disabled,
3323
3307
  min: 1,
3308
+ max: 31,
3309
+ maxLength: 2,
3324
3310
  onChange: event => handleDayChange(event)
3325
3311
  })
3326
3312
  })]
@@ -3331,8 +3317,8 @@ const DateInput = ({
3331
3317
  return /*#__PURE__*/jsx("div", {
3332
3318
  className: "col-sm-4",
3333
3319
  children: /*#__PURE__*/jsxs("label", {
3334
- children: [/*#__PURE__*/jsx("span", {
3335
- className: "sr-only",
3320
+ children: [/*#__PURE__*/jsx(Body, {
3321
+ type: Typography.BODY_DEFAULT,
3336
3322
  children: yearLabel
3337
3323
  }), /*#__PURE__*/jsx("div", {
3338
3324
  className: `input-group input-group-${size}`,
@@ -3343,9 +3329,11 @@ const DateInput = ({
3343
3329
  name: "year",
3344
3330
  autoComplete: yearAutoComplete,
3345
3331
  placeholder: placeholders?.year,
3346
- value: year || '',
3332
+ value: displayYear || '',
3347
3333
  disabled: disabled,
3348
- min: 1,
3334
+ min: 0,
3335
+ max: 9999,
3336
+ maxLength: 6,
3349
3337
  onChange: event => handleYearChange(event)
3350
3338
  })
3351
3339
  })]
@@ -4849,14 +4837,20 @@ function InlineAlert({
4849
4837
  className,
4850
4838
  children
4851
4839
  }) {
4852
- const danger = type === 'negative' || type === 'error';
4853
- return /*#__PURE__*/jsxs("div", {
4840
+ return /*#__PURE__*/jsx("div", {
4854
4841
  role: "alert",
4855
4842
  id: id,
4856
- className: classNames('alert alert-detach', `alert-${danger ? 'danger' : type}`, className),
4857
- children: [danger && /*#__PURE__*/jsx(AlertCircle, {}), /*#__PURE__*/jsx("div", {
4858
- children: children
4859
- })]
4843
+ className: classNames('alert alert-detach', `alert-${type === Sentiment.NEGATIVE || type === Sentiment.ERROR ? 'danger' : type}`, className),
4844
+ children: /*#__PURE__*/jsxs("div", {
4845
+ className: "d-inline-flex",
4846
+ children: [type !== Sentiment.NEUTRAL && type !== Sentiment.PENDING && /*#__PURE__*/jsx(StatusIcon, {
4847
+ sentiment: type,
4848
+ size: Size.SMALL
4849
+ }), /*#__PURE__*/jsx("div", {
4850
+ className: "np-text-body-default",
4851
+ children: children
4852
+ })]
4853
+ })
4860
4854
  });
4861
4855
  }
4862
4856
 
@@ -4877,13 +4871,15 @@ const Label = ({
4877
4871
  const Field = ({
4878
4872
  id,
4879
4873
  label,
4880
- hint,
4881
- error,
4874
+ message: propMessage,
4875
+ sentiment: propType = Sentiment.NEUTRAL,
4882
4876
  className,
4883
- children
4877
+ children,
4878
+ ...props
4884
4879
  }) => {
4885
- const hasError = Boolean(error);
4886
- const hasHint = Boolean(hint) && !hasError;
4880
+ const sentiment = props.error ? Sentiment.NEGATIVE : propType;
4881
+ const message = props.error || props.hint || propMessage;
4882
+ const hasError = sentiment === Sentiment.NEGATIVE;
4887
4883
  const labelId = useId();
4888
4884
  const fallbackInputId = useId();
4889
4885
  const inputId = id !== null ? id ?? fallbackInputId : undefined;
@@ -4893,26 +4889,24 @@ const Field = ({
4893
4889
  children: /*#__PURE__*/jsx(InputIdContextProvider, {
4894
4890
  value: inputId,
4895
4891
  children: /*#__PURE__*/jsx(InputDescribedByProvider, {
4896
- value: hasError || hasHint ? descriptionId : undefined,
4892
+ value: message ? descriptionId : undefined,
4897
4893
  children: /*#__PURE__*/jsx(InputInvalidProvider, {
4898
4894
  value: hasError,
4899
4895
  children: /*#__PURE__*/jsxs("div", {
4900
4896
  className: classNames('form-group d-block', {
4897
+ 'has-success': sentiment === Sentiment.POSITIVE,
4898
+ 'has-warning': sentiment === Sentiment.WARNING,
4901
4899
  'has-error': hasError,
4902
- 'has-info': hasHint
4900
+ 'has-info': sentiment === Sentiment.NEUTRAL
4903
4901
  }, className),
4904
4902
  children: [/*#__PURE__*/jsxs(Label, {
4905
4903
  id: labelId,
4906
4904
  htmlFor: inputId,
4907
4905
  children: [label, children]
4908
- }), hasHint && /*#__PURE__*/jsx(InlineAlert, {
4909
- type: Sentiment.NEUTRAL,
4910
- id: descriptionId,
4911
- children: hint
4912
- }), hasError && /*#__PURE__*/jsx(InlineAlert, {
4913
- type: Sentiment.NEGATIVE,
4906
+ }), message && /*#__PURE__*/jsx(InlineAlert, {
4907
+ type: sentiment,
4914
4908
  id: descriptionId,
4915
- children: error
4909
+ children: message
4916
4910
  })]
4917
4911
  })
4918
4912
  })
@@ -12059,13 +12053,6 @@ var Typeahead$1 = withInputAttributes(Typeahead, {
12059
12053
  nonLabelable: true
12060
12054
  });
12061
12055
 
12062
- // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
12063
- var UploadStep;
12064
- (function (UploadStep) {
12065
- UploadStep["UPLOAD_IMAGE_STEP"] = "uploadImageStep";
12066
- UploadStep["MEDIA_UPLOAD_STEP"] = "mediaUploadStep";
12067
- })(UploadStep || (UploadStep = {}));
12068
-
12069
12056
  var messages = defineMessages({
12070
12057
  csButtonText: {
12071
12058
  id: "neptune.Upload.csButtonText"
@@ -12100,16 +12087,13 @@ var messages = defineMessages({
12100
12087
  });
12101
12088
 
12102
12089
  class UploadImageStep extends PureComponent {
12103
- constructor() {
12104
- super();
12105
- this.uploadInputRef = /*#__PURE__*/createRef();
12106
- }
12090
+ uploadInputRef = /*#__PURE__*/createRef();
12107
12091
  onManualUpload = () => {
12108
12092
  const {
12109
12093
  fileDropped
12110
12094
  } = this.props;
12111
- if (this.uploadInputRef && this.uploadInputRef.current) {
12112
- const file = this.uploadInputRef.current.files[0];
12095
+ const file = this.uploadInputRef.current?.files?.[0];
12096
+ if (file != null) {
12113
12097
  fileDropped(file);
12114
12098
  }
12115
12099
  };
@@ -12158,7 +12142,7 @@ class UploadImageStep extends PureComponent {
12158
12142
  children: usLabel
12159
12143
  }), usPlaceholder && /*#__PURE__*/jsx("p", {
12160
12144
  className: "np-text-body-large m-b-3",
12161
- children: `${usPlaceholder}`
12145
+ children: String(usPlaceholder)
12162
12146
  }), /*#__PURE__*/jsxs("label", {
12163
12147
  className: `btn btn-primary btn-md ${usDisabled ? 'disabled' : ''}`,
12164
12148
  children: [usButtonText ? /*#__PURE__*/jsx("span", {
@@ -12169,7 +12153,7 @@ class UploadImageStep extends PureComponent {
12169
12153
  }), /*#__PURE__*/jsx("input", {
12170
12154
  ref: this.uploadInputRef,
12171
12155
  type: "file",
12172
- accept: usAccept === '*' ? null : usAccept,
12156
+ accept: usAccept === '*' ? undefined : usAccept,
12173
12157
  className: "tw-droppable-input hidden",
12174
12158
  disabled: usDisabled,
12175
12159
  name: "file-upload",
@@ -12181,213 +12165,17 @@ class UploadImageStep extends PureComponent {
12181
12165
  });
12182
12166
  }
12183
12167
  }
12184
- UploadImageStep.propTypes = {
12185
- fileDropped: PropTypes.func.isRequired,
12186
- isComplete: PropTypes.bool.isRequired,
12187
- usAccept: PropTypes.string.isRequired,
12188
- usButtonText: PropTypes.string.isRequired,
12189
- usDisabled: PropTypes.bool.isRequired,
12190
- usHelpImage: PropTypes.node.isRequired,
12191
- usLabel: PropTypes.string.isRequired,
12192
- usPlaceholder: PropTypes.string.isRequired
12193
- };
12194
-
12195
- const postData = (httpOptions, data = {}, fetcher = fetch) => fetcher(`${httpOptions.url}`, {
12196
- method: 'POST',
12197
- body: data,
12198
- ...httpOptions
12199
- }).then(response => {
12200
- if (!response.ok) {
12201
- const error = new Error(response.statusText);
12202
- error.status = response.status;
12203
- error.response = response;
12204
- throw error;
12205
- }
12206
- return response;
12207
- }).catch(error => {
12208
- throw error;
12209
- });
12210
12168
 
12211
- const asyncFileRead = file => new Promise((resolve, reject) => {
12212
- const reader = new FileReader();
12213
- reader.readAsDataURL(file);
12214
- reader.addEventListener('load', event => {
12215
- resolve(event.target.result);
12216
- });
12217
- reader.addEventListener('error', event => {
12218
- reject(event);
12219
- });
12220
- });
12221
-
12222
- const isSizeValid = (file, maxSize) => Number.isInteger(maxSize) && file.size <= maxSize;
12223
-
12224
- const getFileType = (file, file64) => {
12225
- if (!file && !file64) {
12226
- return '';
12227
- }
12228
- if (file && file.type && file.type !== '') {
12229
- return file.type ?? '';
12230
- }
12231
- if (file64) {
12232
- const regex = /^data:([a-z]+\/[a-z]+);/;
12233
- const typeFromEncoded = file64.match(regex);
12234
- if (typeFromEncoded && typeFromEncoded[1]) {
12235
- return typeFromEncoded[1] ?? '';
12236
- }
12237
- }
12238
- return '';
12239
- };
12240
-
12241
- const isTypeValid = (file, rule, file64) => {
12242
- if (!file || !rule) {
12243
- return false;
12244
- }
12245
- const allowedTypes = rule.replace(/\s/g, '').split(',');
12246
- const fileType = getFileType(file, file64);
12247
- if (rule === '*' || allowedTypes.includes(fileType)) {
12248
- return true;
12249
- }
12250
- return allowedTypes.some(type => {
12251
- const splittedRule = type.split('/');
12252
- const typeAllowed = splittedRule[0];
12253
- const extensionAllowed = splittedRule[1];
12254
- if (extensionAllowed !== '*') {
12255
- return false;
12256
- }
12257
- return fileType.includes(typeAllowed);
12258
- });
12259
- };
12260
-
12261
- // Spot Platform's Media API only support these MIME types
12262
- const SUPPORTED_MIME_TYPES = ['image/jpeg', 'video/*', 'application/pdf'];
12263
- const getSupportedSpotMimeTypes = mimeTypes => {
12264
- if (mimeTypes === '*') {
12265
- return SUPPORTED_MIME_TYPES;
12266
- }
12267
- const mimeTypesArray = mimeTypes.split(',');
12268
- const mimeMapping = {
12269
- 'image/*': 'image/jpeg',
12270
- 'application/*': 'application/pdf'
12271
- };
12272
- const mapSupportedMimeTypes = mimeTypesArray.map(type => mimeMapping[type] || type);
12273
- return mapSupportedMimeTypes.filter(type => SUPPORTED_MIME_TYPES.includes(type));
12274
- };
12275
-
12276
- const requestMedia = mediaRequest => new Promise((resolve, reject) => {
12277
- if (typeof window === 'undefined' || typeof window.microapps === 'undefined') {
12278
- reject(`microapps must be available in window to use Spot Platform's Media API`);
12279
- }
12280
- window.microapps.requestMedia(mediaRequest).then(response => {
12281
- const fileByteArray = base64ToByteArray(response.bytes);
12282
- const blob = new Blob([fileByteArray], {
12283
- type: response.mimeType
12284
- });
12285
- resolve(blob);
12286
- }).catch(error => reject(error));
12287
- });
12288
- const base64ToByteArray = base64String => {
12289
- const byteCharacters = atob(base64String);
12290
- const byteCharactersLength = byteCharacters.length;
12291
- const byteArray = new Array(byteCharactersLength);
12292
- for (let i = 0; i < byteCharactersLength; i += 1) {
12293
- byteArray[i] = byteCharacters.charCodeAt(i);
12294
- }
12295
- return new Uint8Array(byteArray);
12296
- };
12297
-
12298
- const MediaUploadStep = ({
12169
+ function ProcessingStep({
12299
12170
  isComplete,
12300
- usAccept,
12301
- usButtonText,
12302
- usDisabled,
12303
- usHelpImage,
12304
- usLabel,
12305
- usPlaceholder,
12306
- fileDropped
12307
- }) => {
12308
- const getMediaFile = () => {
12309
- const allowedMimeTypes = getSupportedSpotMimeTypes(usAccept);
12310
- if (allowedMimeTypes.length === 0) {
12311
- throw new Error('provided mimeTypes not supported');
12312
- }
12313
- const mediaRequest = {
12314
- allowedMimeTypes
12315
- };
12316
- requestMedia(mediaRequest).then(file => fileDropped(file));
12317
- };
12318
- const getImage = () => {
12319
- if (!usHelpImage) {
12320
- return /*#__PURE__*/jsx("div", {
12321
- className: "circle circle-sm circle-inverse p-t-1",
12322
- children: /*#__PURE__*/jsx(Upload$2, {
12323
- size: 24
12324
- })
12325
- });
12326
- }
12327
- if (typeof usHelpImage === 'string') {
12328
- return /*#__PURE__*/jsx("img", {
12329
- src: usHelpImage,
12330
- alt: usLabel,
12331
- className: "thumbnail text-xs-center"
12332
- });
12333
- }
12334
- return usHelpImage;
12335
- };
12336
- return /*#__PURE__*/jsx("div", {
12337
- children: /*#__PURE__*/jsx("div", {
12338
- className: "droppable-default-card",
12339
- "aria-hidden": isComplete,
12340
- children: /*#__PURE__*/jsxs("div", {
12341
- className: "droppable-card-content",
12342
- children: [/*#__PURE__*/jsx("div", {
12343
- className: "m-b-3",
12344
- children: getImage()
12345
- }), usLabel && /*#__PURE__*/jsx(Title, {
12346
- type: Typography.TITLE_BODY,
12347
- className: "m-b-1",
12348
- children: usLabel
12349
- }), usPlaceholder && /*#__PURE__*/jsx(Body, {
12350
- as: "p",
12351
- type: Typography.BODY_LARGE,
12352
- className: "m-b-3",
12353
- children: `${usPlaceholder}`
12354
- }), /*#__PURE__*/jsx(Button, {
12355
- disabled: usDisabled,
12356
- onClick: getMediaFile,
12357
- children: usButtonText || /*#__PURE__*/jsx(Upload$2, {
12358
- size: 24,
12359
- className: "m-r-0"
12360
- })
12361
- })]
12362
- })
12363
- })
12364
- });
12365
- };
12366
- MediaUploadStep.propTypes = {
12367
- fileDropped: PropTypes.func.isRequired,
12368
- isComplete: PropTypes.bool.isRequired,
12369
- usAccept: PropTypes.string.isRequired,
12370
- usButtonText: PropTypes.string.isRequired,
12371
- usDisabled: PropTypes.bool.isRequired,
12372
- usHelpImage: PropTypes.node.isRequired,
12373
- usLabel: PropTypes.string.isRequired,
12374
- usPlaceholder: PropTypes.string.isRequired
12375
- };
12376
-
12377
- const ProcessingStep = props => {
12378
- const {
12379
- isComplete,
12380
- isError,
12381
- isSuccess,
12382
- onAnimationCompleted,
12383
- onClear,
12384
- psButtonText,
12385
- psProcessingText,
12386
- psButtonDisabled
12387
- } = props;
12388
- const {
12389
- isModern
12390
- } = useTheme();
12171
+ isError,
12172
+ isSuccess,
12173
+ onAnimationCompleted,
12174
+ onClear,
12175
+ psButtonText,
12176
+ psProcessingText,
12177
+ psButtonDisabled
12178
+ }) {
12391
12179
  let processStatus = Status.PROCESSING;
12392
12180
  if (isError) {
12393
12181
  processStatus = Status.FAILED;
@@ -12401,53 +12189,33 @@ const ProcessingStep = props => {
12401
12189
  children: /*#__PURE__*/jsxs("div", {
12402
12190
  className: "droppable-card-content",
12403
12191
  children: [/*#__PURE__*/jsx(ProcessIndicator, {
12404
- size: Size.Small,
12405
12192
  status: processStatus,
12406
12193
  onAnimationCompleted: status => onAnimationCompleted(status)
12407
12194
  }), /*#__PURE__*/jsx(Title, {
12408
- className: classNames({
12409
- 'm-t-3': !isModern,
12410
- 'm-b-3': !isModern,
12411
- 'm-t-2': isModern,
12412
- 'm-b-2': isModern
12413
- }),
12195
+ className: "m-y-2",
12414
12196
  type: Typography.TITLE_BODY,
12415
12197
  "aria-live": "polite",
12416
12198
  children: psProcessingText
12417
12199
  }), psButtonText && /*#__PURE__*/jsx(Button, {
12418
12200
  disabled: psButtonDisabled,
12419
- onClick: event => onClear(event),
12201
+ onClick: onClear,
12420
12202
  children: psButtonText
12421
12203
  })]
12422
12204
  })
12423
12205
  });
12424
- };
12425
- ProcessingStep.propTypes = {
12426
- isComplete: PropTypes.bool.isRequired,
12427
- isError: PropTypes.bool.isRequired,
12428
- isSuccess: PropTypes.bool.isRequired,
12429
- onAnimationCompleted: PropTypes.func.isRequired,
12430
- onClear: PropTypes.func.isRequired,
12431
- psButtonText: PropTypes.string.isRequired,
12432
- psProcessingText: PropTypes.string.isRequired,
12433
- psButtonDisabled: PropTypes.bool.isRequired
12434
- };
12206
+ }
12435
12207
 
12436
- const CompleteStep = props => {
12437
- const {
12438
- isModern
12439
- } = useTheme();
12440
- const {
12441
- csButtonText,
12442
- csFailureText,
12443
- csSuccessText,
12444
- fileName,
12445
- isComplete,
12446
- isError,
12447
- isImage,
12448
- onClear,
12449
- uploadedImage
12450
- } = props;
12208
+ function CompleteStep({
12209
+ csButtonText,
12210
+ csFailureText,
12211
+ csSuccessText,
12212
+ fileName,
12213
+ isComplete,
12214
+ isError,
12215
+ isImage,
12216
+ onClear,
12217
+ uploadedImage
12218
+ }) {
12451
12219
  return /*#__PURE__*/jsx("div", {
12452
12220
  className: "droppable-complete-card droppable-card",
12453
12221
  "aria-hidden": !isComplete,
@@ -12457,16 +12225,11 @@ const CompleteStep = props => {
12457
12225
  className: "droppable-card-content d-flex flex-column align-items-center",
12458
12226
  "aria-live": "polite",
12459
12227
  children: isError ? /*#__PURE__*/jsxs(Fragment, {
12460
- children: [isModern ? /*#__PURE__*/jsx(StatusIcon, {
12228
+ children: [/*#__PURE__*/jsx(StatusIcon, {
12461
12229
  size: Size.LARGE,
12462
12230
  sentiment: Sentiment.NEGATIVE
12463
- }) : /*#__PURE__*/jsx(AlertCircle, {
12464
- size: 24,
12465
- className: "text-negative"
12466
12231
  }), csFailureText && /*#__PURE__*/jsx("p", {
12467
- className: classNames('m-t-2', {
12468
- 'm-b-0': isModern
12469
- }),
12232
+ className: "m-t-2 m-b-0",
12470
12233
  children: csFailureText
12471
12234
  })]
12472
12235
  }) : /*#__PURE__*/jsxs(Fragment, {
@@ -12485,71 +12248,135 @@ const CompleteStep = props => {
12485
12248
  })]
12486
12249
  })
12487
12250
  }), csButtonText && /*#__PURE__*/jsx(Button, {
12488
- priority: isModern ? Priority.PRIMARY : Priority.SECONDARY,
12489
- className: classNames({
12490
- 'm-t-1': isModern && !isError,
12491
- 'm-t-2': isModern && isError,
12492
- 'm-t-3': !isModern
12493
- }),
12494
- onClick: event => onClear(event),
12251
+ className: isError ? 'm-t-2' : 'm-t-1',
12252
+ onClick: onClear,
12495
12253
  children: csButtonText
12496
12254
  })]
12497
12255
  })
12498
12256
  });
12499
- };
12500
- CompleteStep.propTypes = {
12501
- csButtonText: PropTypes.string.isRequired,
12502
- csSuccessText: PropTypes.string.isRequired,
12503
- csFailureText: PropTypes.string.isRequired,
12504
- fileName: PropTypes.string.isRequired,
12505
- isComplete: PropTypes.bool.isRequired,
12506
- isError: PropTypes.bool.isRequired,
12507
- isImage: PropTypes.bool.isRequired,
12508
- onClear: PropTypes.func.isRequired,
12509
- uploadedImage: PropTypes.string
12510
- };
12511
- CompleteStep.defaultProps = {
12512
- uploadedImage: null
12513
- };
12257
+ }
12514
12258
 
12515
- const PROCESS_STATE = ['error', 'success'];
12259
+ class ResponseError extends Error {
12260
+ response;
12261
+ status;
12262
+ constructor(response, message) {
12263
+ super(message);
12264
+ this.name = 'ResponseError';
12265
+ this.response = response;
12266
+ this.status = response.status;
12267
+ }
12268
+ }
12269
+ async function postData({
12270
+ url,
12271
+ method = 'POST',
12272
+ ...httpOptions
12273
+ }, data, fetcher = fetch) {
12274
+ const response = await fetcher(url, {
12275
+ method,
12276
+ body: data,
12277
+ ...httpOptions
12278
+ });
12279
+ if (!response.ok) {
12280
+ throw new ResponseError(response, response.statusText);
12281
+ }
12282
+ return response;
12283
+ }
12284
+
12285
+ async function asyncFileRead(file) {
12286
+ return new Promise((resolve, reject) => {
12287
+ const reader = new FileReader();
12288
+ reader.addEventListener('load', () => {
12289
+ resolve(reader.result);
12290
+ });
12291
+ reader.addEventListener('error', () => {
12292
+ reject(reader.error ?? new Error('Cannot read file'));
12293
+ });
12294
+ reader.readAsDataURL(file);
12295
+ });
12296
+ }
12297
+
12298
+ function isSizeValid(file, maxSize) {
12299
+ return Number.isInteger(maxSize) && file.size <= maxSize;
12300
+ }
12301
+
12302
+ function getFileType(file, file64) {
12303
+ if (file.type) {
12304
+ return file.type;
12305
+ }
12306
+ if (file64) {
12307
+ const regex = /^data:([a-z]+\/[a-z]+);/;
12308
+ const typeFromEncoded = regex.exec(file64);
12309
+ if (typeFromEncoded?.[1]) {
12310
+ return typeFromEncoded[1];
12311
+ }
12312
+ }
12313
+ return '';
12314
+ }
12315
+
12316
+ function isTypeValid(file, rule, file64) {
12317
+ if (!rule) {
12318
+ return false;
12319
+ }
12320
+ const allowedTypes = rule.replace(/\s/g, '').split(',');
12321
+ const fileType = getFileType(file, file64);
12322
+ if (rule === '*' || allowedTypes.includes(fileType)) {
12323
+ return true;
12324
+ }
12325
+ return allowedTypes.some(type => {
12326
+ const [typeAllowed, extensionAllowed] = type.split('/');
12327
+ return extensionAllowed === '*' && fileType.includes(typeAllowed);
12328
+ });
12329
+ }
12516
12330
 
12517
- /*
12518
- * This delay is required for the isError/isSuccess to be fired after isProcessing so the processIndicator, will be
12519
- * rendered first and then updated with the right status.
12520
- */
12521
12331
  const ANIMATION_FIX = 10;
12522
12332
  const MAX_SIZE_DEFAULT = 5000000;
12523
- const UPLOAD_STEP_COMPONENTS = {
12524
- [UploadStep.UPLOAD_IMAGE_STEP]: UploadImageStep,
12525
- [UploadStep.MEDIA_UPLOAD_STEP]: MediaUploadStep
12526
- };
12333
+ var UploadStep;
12334
+ (function (UploadStep) {
12335
+ UploadStep["UPLOAD_IMAGE_STEP"] = "uploadImageStep";
12336
+ })(UploadStep || (UploadStep = {}));
12527
12337
  class Upload extends Component {
12338
+ static defaultProps = {
12339
+ animationDelay: 700,
12340
+ maxSize: MAX_SIZE_DEFAULT,
12341
+ psButtonDisabled: false,
12342
+ size: 'md',
12343
+ usAccept: 'image/*',
12344
+ usDisabled: false,
12345
+ usLabel: ''
12346
+ };
12347
+ dragCounter = 0;
12348
+ timeouts = 0;
12528
12349
  constructor(props) {
12529
12350
  super(props);
12530
- this.dragCounter = 0;
12531
- this.timeouts = null;
12532
12351
  this.state = {
12533
12352
  fileName: '',
12353
+ isDroppable: false,
12534
12354
  isComplete: false,
12535
12355
  isError: false,
12536
12356
  isImage: false,
12537
12357
  isProcessing: false,
12538
12358
  isSuccess: false,
12539
- response: null,
12540
- uploadedImage: null
12359
+ response: undefined,
12360
+ uploadedImage: undefined
12541
12361
  };
12542
12362
  }
12543
12363
  getErrorMessage(status) {
12364
+ const {
12365
+ csFailureText,
12366
+ csTooLargeMessage,
12367
+ csWrongTypeMessage,
12368
+ maxSize,
12369
+ intl
12370
+ } = this.props;
12544
12371
  switch (status) {
12545
12372
  case 413:
12546
- return this.props.csTooLargeMessage || this.props.intl.formatMessage(messages.csTooLargeMessage, {
12547
- maxSize: this.props.maxSize / 1000000
12373
+ return csTooLargeMessage || intl.formatMessage(messages.csTooLargeMessage, {
12374
+ maxSize: maxSize / 1000000
12548
12375
  });
12549
12376
  case 415:
12550
- return this.props.csWrongTypeMessage || this.props.intl.formatMessage(messages.csWrongTypeMessage);
12377
+ return csWrongTypeMessage || intl.formatMessage(messages.csWrongTypeMessage);
12551
12378
  default:
12552
- return this.props.csFailureText || this.props.intl.formatMessage(messages.csFailureText);
12379
+ return csFailureText || intl.formatMessage(messages.csFailureText);
12553
12380
  }
12554
12381
  }
12555
12382
  onDragLeave(event) {
@@ -12576,7 +12403,7 @@ class Upload extends Component {
12576
12403
  });
12577
12404
  }
12578
12405
  }
12579
- onDrop(event) {
12406
+ async onDrop(event) {
12580
12407
  const {
12581
12408
  isProcessing
12582
12409
  } = this.state;
@@ -12584,8 +12411,8 @@ class Upload extends Component {
12584
12411
  if (!isProcessing) {
12585
12412
  this.reset();
12586
12413
  }
12587
- if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {
12588
- this.fileDropped(event.dataTransfer.files[0]);
12414
+ if (event.dataTransfer?.files?.[0]) {
12415
+ await this.fileDropped(event.dataTransfer.files[0]);
12589
12416
  }
12590
12417
  }
12591
12418
  onAnimationCompleted = async status => {
@@ -12594,77 +12421,70 @@ class Upload extends Component {
12594
12421
  isProcessing,
12595
12422
  fileName
12596
12423
  } = this.state;
12597
- // Success.
12598
12424
  const {
12599
12425
  animationDelay
12600
12426
  } = this.props;
12601
- if (isProcessing && status === Status.SUCCEEDED) {
12427
+ if (isProcessing && status === 'succeeded') {
12602
12428
  const {
12603
12429
  onSuccess
12604
12430
  } = this.props;
12605
- this.timeouts = setTimeout(() => {
12431
+ this.timeouts = window.setTimeout(() => {
12606
12432
  this.setState({
12607
12433
  isProcessing: false,
12608
12434
  isComplete: true
12609
- }, () => onSuccess ? onSuccess(response, fileName) : {});
12435
+ }, onSuccess ? () => onSuccess(response, fileName) : undefined);
12610
12436
  }, animationDelay);
12611
12437
  }
12612
- // Failure.
12613
- if (isProcessing && status === Status.FAILED) {
12438
+ if (isProcessing && status === 'failed') {
12614
12439
  const {
12615
12440
  onFailure
12616
12441
  } = this.props;
12617
- this.timeouts = setTimeout(() => {
12442
+ this.timeouts = window.setTimeout(() => {
12618
12443
  this.setState({
12619
12444
  isProcessing: false,
12620
12445
  isComplete: true
12621
- }, () => onFailure ? onFailure(response) : {});
12446
+ }, onFailure ? () => onFailure(response) : undefined);
12622
12447
  }, animationDelay);
12623
12448
  }
12624
12449
  };
12625
- asyncPost = file => {
12450
+ asyncPost = async file => {
12626
12451
  const {
12627
12452
  httpOptions,
12628
12453
  fetcher
12629
12454
  } = this.props;
12455
+ if (httpOptions == null) {
12456
+ throw new Error('Cannot find HTTP options');
12457
+ }
12630
12458
  const {
12631
12459
  fileInputName = file.name,
12632
12460
  data = {}
12633
- } = httpOptions || {};
12461
+ } = httpOptions;
12634
12462
  const formData = new FormData();
12635
12463
  formData.append(fileInputName, file);
12636
12464
  Object.keys(data).forEach(key => formData.append(key, data[key]));
12637
- return postData(this.prepareHttpOptions(httpOptions), formData, fetcher);
12465
+ return postData(httpOptions, formData, fetcher);
12638
12466
  };
12639
12467
  asyncResponse = (response, type) => {
12640
12468
  // Gives time to the animation callback to fire.
12641
- this.timeouts = setTimeout(() => {
12469
+ this.timeouts = window.setTimeout(() => {
12642
12470
  this.setState({
12643
12471
  response,
12644
- isError: type === PROCESS_STATE[0],
12645
- isSuccess: type === PROCESS_STATE[1]
12472
+ isError: type === 'error',
12473
+ isSuccess: type === 'success'
12646
12474
  });
12647
12475
  }, ANIMATION_FIX);
12648
12476
  };
12649
- prepareHttpOptions = httpOptions => {
12650
- if (!httpOptions.url) {
12651
- throw new Error('You must supply a URL to post image data asynchronously');
12652
- }
12653
- return httpOptions;
12654
- };
12655
12477
  handleOnClear = event => {
12656
12478
  event.preventDefault();
12657
12479
  const {
12658
12480
  onCancel
12659
12481
  } = this.props;
12660
- if (onCancel) {
12661
- onCancel();
12662
- }
12482
+ onCancel?.();
12663
12483
  this.reset();
12664
12484
  };
12665
12485
  reset = () => {
12666
12486
  this.dragCounter = 0;
12667
- clearTimeout(this.timeouts);
12487
+ window.clearTimeout(this.timeouts);
12668
12488
  this.setState({
12669
12489
  isComplete: false,
12670
12490
  isError: false,
@@ -12704,14 +12524,12 @@ class Upload extends Component {
12704
12524
  isDroppable: false,
12705
12525
  isProcessing: true
12706
12526
  });
12707
- if (onStart) {
12708
- onStart(file);
12709
- }
12527
+ onStart?.(file);
12710
12528
  let file64 = null;
12711
12529
  try {
12712
12530
  file64 = await asyncFileRead(file);
12713
12531
  } catch (error) {
12714
- this.asyncResponse(error, PROCESS_STATE[0]);
12532
+ this.asyncResponse(error, 'error');
12715
12533
  }
12716
12534
  if (!file64) {
12717
12535
  return false;
@@ -12720,30 +12538,31 @@ class Upload extends Component {
12720
12538
  isImage: getFileType(file, file64).includes('image')
12721
12539
  });
12722
12540
  if (!isTypeValid(file, usAccept, file64)) {
12723
- const response = {
12541
+ this.asyncResponse(new ResponseError(new Response(null, {
12724
12542
  status: 415,
12725
12543
  statusText: 'Unsupported Media Type'
12726
- };
12727
- this.asyncResponse(response, PROCESS_STATE[0]);
12544
+ })), 'error');
12728
12545
  return false;
12729
12546
  }
12730
12547
  if (!isSizeValid(file, maxSize)) {
12731
- const response = {
12548
+ this.asyncResponse(new ResponseError(new Response(null, {
12732
12549
  status: 413,
12733
12550
  statusText: 'Request Entity Too Large'
12734
- };
12735
- this.asyncResponse(response, PROCESS_STATE[0]);
12551
+ })), 'error');
12736
12552
  return false;
12737
12553
  }
12738
12554
  if (httpOptions) {
12739
12555
  // Post the file to provided endpoint
12740
- return await this.asyncPost(file).then(response => this.asyncResponse(response, 'success')).then(() => {
12741
- this.showDataImage(file64);
12742
- return true;
12743
- }).catch(error => {
12744
- this.asyncResponse(error, PROCESS_STATE[0]);
12556
+ let response;
12557
+ try {
12558
+ response = await this.asyncPost(file);
12559
+ } catch (error) {
12560
+ this.asyncResponse(error, 'error');
12745
12561
  return false;
12746
- });
12562
+ }
12563
+ this.asyncResponse(response, 'success');
12564
+ this.showDataImage(file64);
12565
+ return true;
12747
12566
  }
12748
12567
  // Post on form submit. And return the encoded image.
12749
12568
  this.showDataImage(file64);
@@ -12752,6 +12571,7 @@ class Upload extends Component {
12752
12571
  };
12753
12572
  render() {
12754
12573
  const {
12574
+ maxSize,
12755
12575
  usDropMessage,
12756
12576
  usAccept,
12757
12577
  usButtonText,
@@ -12765,7 +12585,6 @@ class Upload extends Component {
12765
12585
  csButtonText,
12766
12586
  csSuccessText,
12767
12587
  size,
12768
- uploadStep,
12769
12588
  intl
12770
12589
  } = this.props;
12771
12590
  const {
@@ -12779,7 +12598,6 @@ class Upload extends Component {
12779
12598
  isSuccess,
12780
12599
  uploadedImage
12781
12600
  } = this.state;
12782
- const UploadStepComponent = UPLOAD_STEP_COMPONENTS[uploadStep] || UploadImageStep;
12783
12601
  return /*#__PURE__*/jsxs("div", {
12784
12602
  className: classNames('droppable-area', {
12785
12603
  droppable: true,
@@ -12793,10 +12611,10 @@ class Upload extends Component {
12793
12611
  }),
12794
12612
  onDragEnter: event => this.onDragEnter(event),
12795
12613
  onDragLeave: event => this.onDragLeave(event),
12796
- onDrop: event => this.onDrop(event),
12614
+ onDrop: async event => this.onDrop(event),
12797
12615
  onDragOver: event => event.preventDefault(),
12798
- children: [!isProcessing && !isComplete && /*#__PURE__*/jsx(UploadStepComponent, {
12799
- fileDropped: file => this.fileDropped(file),
12616
+ children: [!isProcessing && !isComplete && /*#__PURE__*/jsx(UploadImageStep, {
12617
+ fileDropped: async file => this.fileDropped(file),
12800
12618
  isComplete: isComplete,
12801
12619
  usAccept: usAccept,
12802
12620
  usButtonText: usButtonText || intl.formatMessage(messages.usButtonText),
@@ -12804,7 +12622,7 @@ class Upload extends Component {
12804
12622
  usHelpImage: usHelpImage,
12805
12623
  usLabel: usLabel,
12806
12624
  usPlaceholder: usPlaceholder || intl.formatMessage(messages.usPlaceholder, {
12807
- maxSize: this.props.maxSize / 1000000
12625
+ maxSize: maxSize / 1000000
12808
12626
  })
12809
12627
  }), isProcessing && /*#__PURE__*/jsx(ProcessingStep, {
12810
12628
  isComplete: isComplete,
@@ -12813,7 +12631,7 @@ class Upload extends Component {
12813
12631
  psButtonText: psButtonText || intl.formatMessage(messages.psButtonText),
12814
12632
  psProcessingText: psProcessingText || intl.formatMessage(messages.psProcessingText),
12815
12633
  psButtonDisabled: psButtonDisabled,
12816
- onAnimationCompleted: status => this.onAnimationCompleted(status),
12634
+ onAnimationCompleted: async status => this.onAnimationCompleted(status),
12817
12635
  onClear: event => this.handleOnClear(event)
12818
12636
  }), (isSuccess || isError || isComplete) && /*#__PURE__*/jsx(CompleteStep, {
12819
12637
  fileName: fileName,
@@ -12821,7 +12639,7 @@ class Upload extends Component {
12821
12639
  isError: isError,
12822
12640
  isImage: isImage,
12823
12641
  csButtonText: csButtonText || intl.formatMessage(messages.csButtonText),
12824
- csFailureText: this.getErrorMessage(response?.status),
12642
+ csFailureText: this.getErrorMessage(response != null && typeof response === 'object' && 'status' in response && typeof response.status === 'number' ? response.status : undefined),
12825
12643
  csSuccessText: csSuccessText || intl.formatMessage(messages.csSuccessText),
12826
12644
  uploadedImage: uploadedImage,
12827
12645
  onClear: event => this.handleOnClear(event)
@@ -12845,73 +12663,6 @@ class Upload extends Component {
12845
12663
  });
12846
12664
  }
12847
12665
  }
12848
- Upload.propTypes = {
12849
- animationDelay: PropTypes.number,
12850
- csButtonText: PropTypes.string,
12851
- csFailureText: PropTypes.string,
12852
- csSuccessText: PropTypes.string,
12853
- csTooLargeMessage: PropTypes.string,
12854
- csWrongTypeMessage: PropTypes.string,
12855
- httpOptions: PropTypes.shape({
12856
- url: PropTypes.string.isRequired,
12857
- method: PropTypes.oneOf(['POST', 'PUT', 'PATCH']),
12858
- fileInputName: PropTypes.string,
12859
- data: PropTypes.object,
12860
- headers: PropTypes.object
12861
- }),
12862
- /**
12863
- * You can provide a fetcher function with the same interface as the global fetch function, which is used by default.
12864
- * function fetcher(input: RequestInfo, init?: RequestInit): Promise<Response>
12865
- */
12866
- fetcher: PropTypes.func,
12867
- maxSize: PropTypes.number,
12868
- onCancel: PropTypes.func,
12869
- onFailure: PropTypes.func,
12870
- onStart: PropTypes.func,
12871
- onSuccess: PropTypes.func,
12872
- psButtonText: PropTypes.string,
12873
- psButtonDisabled: PropTypes.bool,
12874
- psProcessingText: PropTypes.string,
12875
- size: PropTypes.oneOf(['sm', 'md', 'lg']),
12876
- /**
12877
- * You can provide multiple rules separated by comma, e.g.: "application/pdf,image/*".
12878
- * Using "*" will allow every file type to be uploaded.
12879
- */
12880
- usAccept: PropTypes.string,
12881
- usButtonText: PropTypes.string,
12882
- usDisabled: PropTypes.bool,
12883
- usDropMessage: PropTypes.string,
12884
- usHelpImage: PropTypes.node,
12885
- usLabel: PropTypes.string,
12886
- usPlaceholder: PropTypes.string,
12887
- uploadStep: PropTypes.oneOf(['uploadImageStep', 'mediaUploadStep'])
12888
- };
12889
- Upload.defaultProps = {
12890
- animationDelay: 700,
12891
- csButtonText: undefined,
12892
- csFailureText: undefined,
12893
- csSuccessText: undefined,
12894
- csTooLargeMessage: undefined,
12895
- csWrongTypeMessage: undefined,
12896
- httpOptions: null,
12897
- maxSize: MAX_SIZE_DEFAULT,
12898
- onCancel: null,
12899
- onFailure: null,
12900
- onStart: null,
12901
- onSuccess: null,
12902
- psButtonText: undefined,
12903
- psButtonDisabled: false,
12904
- psProcessingText: undefined,
12905
- size: 'md',
12906
- usAccept: 'image/*',
12907
- usButtonText: undefined,
12908
- usDisabled: false,
12909
- usDropMessage: undefined,
12910
- usHelpImage: '',
12911
- usLabel: '',
12912
- usPlaceholder: undefined,
12913
- uploadStep: UploadStep.UPLOAD_IMAGE_STEP
12914
- };
12915
12666
  var Upload$1 = injectIntl(Upload);
12916
12667
 
12917
12668
  var MESSAGES$2 = defineMessages({
@@ -13442,7 +13193,7 @@ const UploadInput = ({
13442
13193
  name
13443
13194
  } = file;
13444
13195
  const id = generateFileId(file);
13445
- const allowedFileTypes = Array.isArray(fileTypes) ? fileTypes.join(',') : fileTypes;
13196
+ const allowedFileTypes = typeof fileTypes === 'string' ? fileTypes : fileTypes.join(',');
13446
13197
  // Check if file type is valid
13447
13198
  if (!isTypeValid(file, allowedFileTypes)) {
13448
13199
  handleFileUploadFailure(file, formatMessage(MESSAGES$2.fileTypeNotSupported));