@widergy/energy-ui 2.10.1 → 3.0.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 (288) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/components/EnergyThemeProvider/index.js +12 -34
  3. package/dist/components/Loading/constants.js +1 -1
  4. package/dist/components/Loading/index.js +12 -10
  5. package/dist/components/Loading/theme.js +6 -3
  6. package/dist/components/UTAlert/AlertHandler.js +74 -99
  7. package/dist/components/UTAlert/index.js +64 -85
  8. package/dist/components/UTAlert/theme.js +34 -32
  9. package/dist/components/UTAttachment/components/Preview/index.js +7 -7
  10. package/dist/components/UTAttachment/constants.js +6 -6
  11. package/dist/components/UTAttachment/index.js +167 -257
  12. package/dist/components/UTAttachment/layout.js +25 -25
  13. package/dist/components/UTAttachment/theme.js +6 -3
  14. package/dist/components/UTAttachment/utils.js +44 -117
  15. package/dist/components/UTAutocomplete/components/ListBox/index.js +12 -19
  16. package/dist/components/UTAutocomplete/components/ListBox/utils.js +11 -12
  17. package/dist/components/UTAutocomplete/constants.js +11 -11
  18. package/dist/components/UTAutocomplete/index.js +53 -92
  19. package/dist/components/UTAutocomplete/theme.js +9 -5
  20. package/dist/components/UTAvatar/constants.js +1 -1
  21. package/dist/components/UTAvatar/index.js +17 -15
  22. package/dist/components/UTBarChart/components/Bars/components/Bar/components/Rect/index.js +21 -20
  23. package/dist/components/UTBarChart/components/Bars/components/Bar/constants.js +2 -1
  24. package/dist/components/UTBarChart/components/Bars/components/Bar/index.js +20 -20
  25. package/dist/components/UTBarChart/components/Bars/constants.js +3 -3
  26. package/dist/components/UTBarChart/components/Bars/index.js +69 -78
  27. package/dist/components/UTBarChart/components/Legend/constants.js +14 -17
  28. package/dist/components/UTBarChart/components/Legend/index.js +74 -91
  29. package/dist/components/UTBarChart/components/Legend/utils.js +2 -5
  30. package/dist/components/UTBarChart/components/Levels/index.js +15 -12
  31. package/dist/components/UTBarChart/components/Levels/utils.js +26 -27
  32. package/dist/components/UTBarChart/components/LinearPlot/constants.js +2 -2
  33. package/dist/components/UTBarChart/components/LinearPlot/index.js +24 -18
  34. package/dist/components/UTBarChart/components/LinearPlot/utils.js +39 -39
  35. package/dist/components/UTBarChart/components/Pagination/constants.js +1 -1
  36. package/dist/components/UTBarChart/components/Pagination/index.js +19 -22
  37. package/dist/components/UTBarChart/components/XAxis/components/AxisElement/index.js +20 -30
  38. package/dist/components/UTBarChart/components/XAxis/components/Decoration/constants.js +2 -2
  39. package/dist/components/UTBarChart/components/XAxis/components/Decoration/index.js +19 -17
  40. package/dist/components/UTBarChart/components/XAxis/constants.js +1 -1
  41. package/dist/components/UTBarChart/components/XAxis/index.js +53 -63
  42. package/dist/components/UTBarChart/components/YAxis/AxisElement/index.js +11 -9
  43. package/dist/components/UTBarChart/components/YAxis/constants.js +1 -1
  44. package/dist/components/UTBarChart/components/YAxis/index.js +29 -35
  45. package/dist/components/UTBarChart/components/YAxis/utils.js +6 -6
  46. package/dist/components/UTBarChart/constants.js +4 -4
  47. package/dist/components/UTBarChart/hooks/use-dynamic-margins.js +22 -38
  48. package/dist/components/UTBarChart/index.js +151 -164
  49. package/dist/components/UTBarChart/theme.js +6 -3
  50. package/dist/components/UTBarChart/types.js +9 -9
  51. package/dist/components/UTBarChart/utils.js +118 -111
  52. package/dist/components/UTBreadcrumbs/constants.js +22 -24
  53. package/dist/components/UTBreadcrumbs/index.js +75 -99
  54. package/dist/components/UTBreadcrumbs/styles.module.scss +1 -0
  55. package/dist/components/UTBreadcrumbs/theme.js +6 -3
  56. package/dist/components/UTButton/constants.js +11 -11
  57. package/dist/components/UTButton/index.js +27 -29
  58. package/dist/components/UTButton/theme.js +26 -24
  59. package/dist/components/UTCBUInput/index.js +35 -38
  60. package/dist/components/UTCBUInput/theme.js +6 -3
  61. package/dist/components/UTCaptcha/index.js +18 -43
  62. package/dist/components/UTCard/components/UTCardFooter/index.js +14 -14
  63. package/dist/components/UTCard/index.js +89 -123
  64. package/dist/components/UTCard/theme.js +13 -13
  65. package/dist/components/UTCard/types.js +1 -1
  66. package/dist/components/UTCarousel/components/Button/index.js +12 -11
  67. package/dist/components/UTCarousel/components/Legend/index.js +12 -13
  68. package/dist/components/UTCarousel/components/Slider/component/Slide/index.js +15 -14
  69. package/dist/components/UTCarousel/components/Slider/constants.js +5 -5
  70. package/dist/components/UTCarousel/components/Slider/index.js +213 -281
  71. package/dist/components/UTCarousel/components/Slider/layout.js +66 -92
  72. package/dist/components/UTCarousel/index.js +13 -13
  73. package/dist/components/UTCarousel/theme.js +6 -3
  74. package/dist/components/UTCheckList/constants.js +1 -1
  75. package/dist/components/UTCheckList/index.js +71 -91
  76. package/dist/components/UTCheckList/theme.js +34 -32
  77. package/dist/components/UTCheckbox/constants.js +2 -4
  78. package/dist/components/UTCheckbox/index.js +32 -43
  79. package/dist/components/UTCheckbox/theme.js +37 -35
  80. package/dist/components/UTConsumptionBar/components/ConsumptionBarIndicator/index.js +8 -7
  81. package/dist/components/UTConsumptionBar/constants.js +3 -3
  82. package/dist/components/UTConsumptionBar/index.js +52 -78
  83. package/dist/components/UTCuit/index.js +114 -137
  84. package/dist/components/UTCuit/theme.js +52 -53
  85. package/dist/components/UTDatePicker/components/Day/constants.js +1 -1
  86. package/dist/components/UTDatePicker/components/Day/index.js +11 -10
  87. package/dist/components/UTDatePicker/constants.js +21 -22
  88. package/dist/components/UTDatePicker/index.js +60 -102
  89. package/dist/components/UTDatePicker/theme.js +8 -4
  90. package/dist/components/UTDatePicker/types.js +1 -1
  91. package/dist/components/UTDatePicker/utils.js +4 -6
  92. package/dist/components/UTDialog/constants.js +2 -2
  93. package/dist/components/UTDialog/index.js +37 -35
  94. package/dist/components/UTDialog/theme.js +6 -3
  95. package/dist/components/UTDialog/types.js +1 -1
  96. package/dist/components/UTDotMenu/index.js +40 -61
  97. package/dist/components/UTEmojiPicker/constants.js +14 -18
  98. package/dist/components/UTEmojiPicker/index.js +46 -64
  99. package/dist/components/UTEmojiPicker/styles.module.scss +1 -1
  100. package/dist/components/UTEmojiPicker/theme.js +6 -3
  101. package/dist/components/UTEmojiPicker/utils.js +24 -52
  102. package/dist/components/UTExternalLink/constants.js +2 -2
  103. package/dist/components/UTExternalLink/index.js +17 -13
  104. package/dist/components/UTExternalLink/theme.js +11 -7
  105. package/dist/components/UTFileInput/constants.js +2 -2
  106. package/dist/components/UTFileInput/index.js +6 -29
  107. package/dist/components/UTFileInput/layout.js +72 -96
  108. package/dist/components/UTIconButton/index.js +48 -70
  109. package/dist/components/UTIconButton/theme.js +6 -3
  110. package/dist/components/UTImageRadio/components/ImageRadioCard/index.js +52 -56
  111. package/dist/components/UTImageRadio/constants.js +3 -3
  112. package/dist/components/UTImageRadio/index.js +38 -45
  113. package/dist/components/UTImageRadio/theme.js +13 -13
  114. package/dist/components/UTImageRadio/types.js +1 -1
  115. package/dist/components/UTImageRadio/utils.js +4 -6
  116. package/dist/components/UTLabel/constants.js +13 -11
  117. package/dist/components/UTLabel/index.js +17 -18
  118. package/dist/components/UTLabel/theme.js +19 -16
  119. package/dist/components/UTList/index.js +14 -16
  120. package/dist/components/UTLoading/index.js +14 -13
  121. package/dist/components/UTMap/components/GoogleMaps/constants.js +9 -10
  122. package/dist/components/UTMap/components/GoogleMaps/index.js +62 -89
  123. package/dist/components/UTMap/constants.js +6 -6
  124. package/dist/components/UTMap/index.js +162 -196
  125. package/dist/components/UTMap/types.js +3 -3
  126. package/dist/components/UTMap/utils.js +35 -46
  127. package/dist/components/UTMap/withGoogleMapScript.js +11 -15
  128. package/dist/components/UTMenu/index.js +51 -67
  129. package/dist/components/UTMenu/styles.module.scss +5 -5
  130. package/dist/components/UTMenu/theme.js +8 -4
  131. package/dist/components/UTMenu/utils.js +10 -12
  132. package/dist/components/UTModal/constants.js +13 -17
  133. package/dist/components/UTModal/index.js +25 -28
  134. package/dist/components/UTModal/styles.module.scss +1 -1
  135. package/dist/components/UTModal/theme.js +6 -3
  136. package/dist/components/UTPagination/components/PageSizeSelector/index.js +10 -8
  137. package/dist/components/UTPagination/components/PageSizeSelector/utils.js +9 -14
  138. package/dist/components/UTPagination/components/Pagination/components/NavigationButton/index.js +11 -10
  139. package/dist/components/UTPagination/components/Pagination/index.js +31 -45
  140. package/dist/components/UTPagination/components/Pagination/utils.js +10 -15
  141. package/dist/components/UTPagination/constants.js +3 -3
  142. package/dist/components/UTPagination/index.js +15 -15
  143. package/dist/components/UTPagination/theme.js +6 -3
  144. package/dist/components/UTPanel/index.js +37 -42
  145. package/dist/components/UTPasswordField/components/PasswordValidations/components/Error/index.js +12 -8
  146. package/dist/components/UTPasswordField/components/PasswordValidations/components/Validation/index.js +21 -17
  147. package/dist/components/UTPasswordField/components/PasswordValidations/index.js +62 -48
  148. package/dist/components/UTPasswordField/components/PasswordWarning/index.js +24 -24
  149. package/dist/components/UTPasswordField/index.js +25 -21
  150. package/dist/components/UTPasswordField/theme.js +6 -3
  151. package/dist/components/UTPhoneInput/constants.js +3 -3
  152. package/dist/components/UTPhoneInput/index.js +185 -209
  153. package/dist/components/UTPhoneInput/theme.js +79 -77
  154. package/dist/components/UTPieChart/components/ArrowLabel/constants.js +4 -4
  155. package/dist/components/UTPieChart/components/ArrowLabel/index.js +23 -21
  156. package/dist/components/UTPieChart/components/Legend/contants.js +3 -3
  157. package/dist/components/UTPieChart/components/Legend/index.js +26 -22
  158. package/dist/components/UTPieChart/constants.js +13 -13
  159. package/dist/components/UTPieChart/hooks/use-animated-value/index.js +14 -31
  160. package/dist/components/UTPieChart/index.js +72 -74
  161. package/dist/components/UTPieChart/theme.js +6 -3
  162. package/dist/components/UTPieChart/utils.js +6 -3
  163. package/dist/components/UTProgressBar/constants.js +2 -2
  164. package/dist/components/UTProgressBar/index.js +14 -15
  165. package/dist/components/UTProgressBar/theme.js +6 -3
  166. package/dist/components/UTProgressBar/types.js +1 -1
  167. package/dist/components/UTRadioGroup/index.js +55 -81
  168. package/dist/components/UTRadioGroup/theme.js +54 -52
  169. package/dist/components/UTRating/components/Circle/index.js +40 -54
  170. package/dist/components/UTRating/components/Faces/assets/mood-confuzed.svg +3 -0
  171. package/dist/components/UTRating/components/Faces/assets/mood-empty.svg +3 -0
  172. package/dist/components/UTRating/components/Faces/assets/mood-happy.svg +3 -0
  173. package/dist/components/UTRating/components/Faces/assets/mood-sad.svg +3 -0
  174. package/dist/components/UTRating/components/Faces/assets/mood-smile.svg +3 -0
  175. package/dist/components/UTRating/components/Faces/constants.js +80 -0
  176. package/dist/components/UTRating/components/Faces/index.js +76 -0
  177. package/dist/components/UTRating/components/Faces/styles.module.scss +78 -0
  178. package/dist/components/UTRating/components/Star/index.js +35 -38
  179. package/dist/components/UTRating/constants.js +5 -4
  180. package/dist/components/UTRating/index.js +35 -46
  181. package/dist/components/UTRating/styles.module.scss +1 -0
  182. package/dist/components/UTRating/theme.js +52 -3
  183. package/dist/components/UTRipple/Ripple.js +21 -37
  184. package/dist/components/UTRipple/index.js +17 -35
  185. package/dist/components/UTSelect/components/Option/index.js +12 -11
  186. package/dist/components/UTSelect/constants.js +4 -4
  187. package/dist/components/UTSelect/index.js +62 -83
  188. package/dist/components/UTSelect/theme.js +9 -5
  189. package/dist/components/UTSelect/utils.js +5 -14
  190. package/dist/components/UTSidebar/components/ListOption/index.js +33 -47
  191. package/dist/components/UTSidebar/components/LogosContainer/components/DynamicIcon/index.js +7 -6
  192. package/dist/components/UTSidebar/components/LogosContainer/index.js +13 -12
  193. package/dist/components/UTSidebar/components/Option/constants.js +1 -1
  194. package/dist/components/UTSidebar/components/Option/index.js +27 -30
  195. package/dist/components/UTSidebar/components/Toggler/index.js +10 -9
  196. package/dist/components/UTSidebar/index.js +41 -51
  197. package/dist/components/UTSidebar/theme.js +6 -3
  198. package/dist/components/UTSidebar/types.js +5 -5
  199. package/dist/components/UTSkeleton/index.js +9 -34
  200. package/dist/components/UTStatus/constants.js +4 -4
  201. package/dist/components/UTStatus/index.js +15 -13
  202. package/dist/components/UTStatus/theme.js +75 -59
  203. package/dist/components/UTSwitch/constants.js +3 -3
  204. package/dist/components/UTSwitch/index.js +41 -55
  205. package/dist/components/UTSwitch/theme.js +6 -3
  206. package/dist/components/UTTable/components/ActionIcons/constants.js +1 -1
  207. package/dist/components/UTTable/components/ActionIcons/index.js +46 -83
  208. package/dist/components/UTTable/components/Cell/components/ActionButton/index.js +9 -10
  209. package/dist/components/UTTable/components/Cell/index.js +17 -21
  210. package/dist/components/UTTable/components/HeaderCell/constants.js +1 -1
  211. package/dist/components/UTTable/components/HeaderCell/index.js +22 -28
  212. package/dist/components/UTTable/components/HeaderCell/utils.js +5 -4
  213. package/dist/components/UTTable/components/PrimaryAction/index.js +11 -9
  214. package/dist/components/UTTable/components/ResponsiveCell/index.js +18 -18
  215. package/dist/components/UTTable/components/Status/index.js +17 -17
  216. package/dist/components/UTTable/components/TableFooter/components/PageSizeSelector/index.js +9 -7
  217. package/dist/components/UTTable/components/TableFooter/components/PageSizeSelector/utils.js +9 -14
  218. package/dist/components/UTTable/components/TableFooter/components/Pagination/components/NavigationButton/index.js +11 -10
  219. package/dist/components/UTTable/components/TableFooter/components/Pagination/index.js +22 -36
  220. package/dist/components/UTTable/components/TableFooter/components/Pagination/utils.js +10 -15
  221. package/dist/components/UTTable/components/TableFooter/constants.js +1 -1
  222. package/dist/components/UTTable/components/TableFooter/index.js +14 -13
  223. package/dist/components/UTTable/components/TableHeader/index.js +10 -10
  224. package/dist/components/UTTable/components/TableRow/constants.js +2 -4
  225. package/dist/components/UTTable/components/TableRow/index.js +79 -93
  226. package/dist/components/UTTable/constants.js +26 -24
  227. package/dist/components/UTTable/hook.js +13 -27
  228. package/dist/components/UTTable/index.js +125 -213
  229. package/dist/components/UTTable/theme.js +19 -18
  230. package/dist/components/UTTable/types.js +4 -4
  231. package/dist/components/UTTable/utils.js +80 -75
  232. package/dist/components/UTTabs/components/TooltipTab/index.js +19 -28
  233. package/dist/components/UTTabs/constants.js +4 -4
  234. package/dist/components/UTTabs/index.js +56 -84
  235. package/dist/components/UTTabs/theme.js +6 -3
  236. package/dist/components/UTTabs/utils.js +3 -2
  237. package/dist/components/UTTextArea/constants.js +2 -4
  238. package/dist/components/UTTextArea/index.js +22 -21
  239. package/dist/components/UTTextArea/theme.js +6 -3
  240. package/dist/components/UTTextInput/constants.js +1 -1
  241. package/dist/components/UTTextInput/index.js +138 -165
  242. package/dist/components/UTTextInput/theme.js +9 -5
  243. package/dist/components/UTThirdPartyCookieChecker/index.js +16 -19
  244. package/dist/components/UTToggle/components/ToggleOption/index.js +15 -15
  245. package/dist/components/UTToggle/index.js +24 -24
  246. package/dist/components/UTToggle/theme.js +6 -3
  247. package/dist/components/UTTooltip/index.js +22 -28
  248. package/dist/components/UTTooltip/theme.js +6 -3
  249. package/dist/components/UTTopbar/components/Notifications/index.js +10 -12
  250. package/dist/components/UTTopbar/components/UserMenu/index.js +18 -17
  251. package/dist/components/UTTopbar/components/UserMenu/styles.module.scss +1 -1
  252. package/dist/components/UTTopbar/index.js +27 -29
  253. package/dist/components/UTTopbar/theme.js +6 -3
  254. package/dist/components/UTTopbar/types.js +4 -4
  255. package/dist/components/UTTouchableWithoutFeedback/index.js +15 -27
  256. package/dist/components/UTVirtualizedList/components/VirtualizedData/components/ListRow/constants.js +2 -2
  257. package/dist/components/UTVirtualizedList/components/VirtualizedData/components/ListRow/index.js +33 -29
  258. package/dist/components/UTVirtualizedList/components/VirtualizedData/components/ListRow/utils.js +6 -5
  259. package/dist/components/UTVirtualizedList/components/VirtualizedData/constants.js +6 -6
  260. package/dist/components/UTVirtualizedList/components/VirtualizedData/hooks/use-ledger.js +7 -16
  261. package/dist/components/UTVirtualizedList/components/VirtualizedData/hooks/use-virtualized-data.js +22 -45
  262. package/dist/components/UTVirtualizedList/components/VirtualizedData/index.js +30 -32
  263. package/dist/components/UTVirtualizedList/components/VirtualizedData/utils.js +89 -94
  264. package/dist/components/UTVirtualizedList/constants.js +4 -4
  265. package/dist/components/UTVirtualizedList/index.js +25 -36
  266. package/dist/components/UTWorkflowContainer/components/ActionButton/index.js +14 -17
  267. package/dist/components/UTWorkflowContainer/constants.js +3 -3
  268. package/dist/components/UTWorkflowContainer/hooks/use-previous.js +5 -4
  269. package/dist/components/UTWorkflowContainer/index.js +31 -49
  270. package/dist/components/UTWorkflowContainer/theme.js +62 -54
  271. package/dist/components/UTWorkflowContainer/types.js +1 -1
  272. package/dist/components/WithLoading/index.js +9 -13
  273. package/dist/components/WithTheme/index.js +9 -15
  274. package/dist/components/WithTheme/layout.js +21 -26
  275. package/dist/components/WithTouch/index.js +11 -17
  276. package/dist/constants/UTTable.js +1 -1
  277. package/dist/index.js +58 -58
  278. package/dist/theme.js +8 -4
  279. package/dist/types/commonTypes.js +2 -2
  280. package/dist/types/consumptionTypes.js +2 -2
  281. package/dist/types/formTypes.js +3 -3
  282. package/dist/types/tableTypes.js +1 -1
  283. package/dist/utils/classesUtils.js +7 -13
  284. package/dist/utils/componentUtils.js +8 -10
  285. package/dist/utils/helperFunctions.js +6 -5
  286. package/dist/utils/shadowUtils.js +15 -12
  287. package/dist/utils/useScreenSize.js +1 -1
  288. package/package.json +29 -70
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.previewPropType = exports.SIZE_ERROR_TEXT = exports.FORMAT_ERROR_TEXT = exports.DEFAULT_UPLOADING_TEXT = exports.DEFAULT_ATTACHMENT_NAME = exports.ASPECT_RATIO_ERROR_TEXT = void 0;
7
7
  var _propTypes = require("prop-types");
8
- var FORMAT_ERROR_TEXT = exports.FORMAT_ERROR_TEXT = 'El formato de archivo es inválido';
9
- var SIZE_ERROR_TEXT = exports.SIZE_ERROR_TEXT = 'El archivo excede el tamaño máximo de ';
10
- var ASPECT_RATIO_ERROR_TEXT = exports.ASPECT_RATIO_ERROR_TEXT = 'El formato de archivo es inválido. (Válidos:';
11
- var DEFAULT_UPLOADING_TEXT = exports.DEFAULT_UPLOADING_TEXT = 'Cargando';
12
- var DEFAULT_ATTACHMENT_NAME = exports.DEFAULT_ATTACHMENT_NAME = 'Adjunto';
13
- var previewPropType = exports.previewPropType = (0, _propTypes.shape)({
8
+ const FORMAT_ERROR_TEXT = exports.FORMAT_ERROR_TEXT = 'El formato de archivo es inválido';
9
+ const SIZE_ERROR_TEXT = exports.SIZE_ERROR_TEXT = 'El archivo excede el tamaño máximo de ';
10
+ const ASPECT_RATIO_ERROR_TEXT = exports.ASPECT_RATIO_ERROR_TEXT = 'El formato de archivo es inválido. (Válidos:';
11
+ const DEFAULT_UPLOADING_TEXT = exports.DEFAULT_UPLOADING_TEXT = 'Cargando';
12
+ const DEFAULT_ATTACHMENT_NAME = exports.DEFAULT_ATTACHMENT_NAME = 'Adjunto';
13
+ const previewPropType = exports.previewPropType = (0, _propTypes.shape)({
14
14
  audio: _propTypes.object,
15
15
  image: _propTypes.object,
16
16
  video: _propTypes.object
@@ -16,283 +16,193 @@ var _constants = require("./constants");
16
16
  var _layout = _interopRequireDefault(require("./layout"));
17
17
  var _utils = require("./utils");
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
20
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
21
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
22
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
23
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
24
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
25
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
26
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
27
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
28
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
30
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
31
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
32
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
33
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
34
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
19
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
35
21
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
36
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
37
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
38
- var AttachmentContainer = /*#__PURE__*/function (_Component) {
39
- _inherits(AttachmentContainer, _Component);
40
- var _super = _createSuper(AttachmentContainer);
41
- function AttachmentContainer() {
42
- var _this;
43
- _classCallCheck(this, AttachmentContainer);
44
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
45
- args[_key] = arguments[_key];
46
- }
47
- _this = _super.call.apply(_super, [this].concat(args));
48
- _defineProperty(_assertThisInitialized(_this), "state", {
49
- loading: false,
50
- name: '',
51
- preview: {},
52
- error: false,
53
- errorText: _constants.FORMAT_ERROR_TEXT
54
- });
55
- _defineProperty(_assertThisInitialized(_this), "loadElement", function () {
56
- var _this$props = _this.props,
57
- input = _this$props.input,
58
- onLoaded = _this$props.onLoaded;
59
- (0, _utils.getBlobFromUrl)(input.value, function (response) {
22
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
23
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
24
+ class AttachmentContainer extends _react.Component {
25
+ constructor(props) {
26
+ super(props);
27
+ _defineProperty(this, "loadElement", () => {
28
+ const {
29
+ input,
30
+ onLoaded
31
+ } = this.props;
32
+ (0, _utils.getBlobFromUrl)(input.value, response => {
60
33
  if (response !== null && response !== void 0 && response.type) {
61
- var fileType = response.type.substring(response.type.indexOf('/') + 1);
62
- _this.setState({
63
- name: _this.getDefaultAttachment(input.value, fileType)
34
+ const fileType = response.type.substring(response.type.indexOf('/') + 1);
35
+ this.setState({
36
+ name: this.getDefaultAttachment(input.value, fileType)
64
37
  });
65
- if ((0, _utils.hasPreview)(response)) _this.buildPreview(response);
66
- } else _this.setState({
67
- name: _this.getDefaultAttachment(input.value)
38
+ if ((0, _utils.hasPreview)(response)) this.buildPreview(response);
39
+ } else this.setState({
40
+ name: this.getDefaultAttachment(input.value)
68
41
  });
69
42
  if (onLoaded) onLoaded();
70
43
  });
71
44
  });
72
- _defineProperty(_assertThisInitialized(_this), "loadDefaultValues", function () {
73
- var input = _this.props.input;
74
- if (_this.hasDefaultValueToLoad()) _this.loadElement();else if (_this.hasDefaultFileObjectToLoad()) _this.setFile(input.value.file);
75
- });
76
- _defineProperty(_assertThisInitialized(_this), "componentDidMount", function () {
77
- _this.loadDefaultValues();
78
- });
79
- _defineProperty(_assertThisInitialized(_this), "componentDidUpdate", function (prevProps) {
80
- var _prevProps$fieldTypes;
81
- var _this$props2 = _this.props,
82
- fieldTypes = _this$props2.fieldTypes,
83
- input = _this$props2.input;
84
- if (((_prevProps$fieldTypes = prevProps.fieldTypes) === null || _prevProps$fieldTypes === void 0 ? void 0 : _prevProps$fieldTypes[0]) !== (fieldTypes === null || fieldTypes === void 0 ? void 0 : fieldTypes[0])) _this.removeValue();else if ((0, _utils.isNewFile)(prevProps.input.value, input.value)) _this.loadDefaultValues();
45
+ _defineProperty(this, "loadDefaultValues", () => {
46
+ const {
47
+ input
48
+ } = this.props;
49
+ if (this.hasDefaultValueToLoad()) this.loadElement();else if (this.hasDefaultFileObjectToLoad()) this.setFile(input.value.file);
85
50
  });
86
- _defineProperty(_assertThisInitialized(_this), "getDefaultAttachment", function (url, fileType) {
87
- return url && typeof url === 'string' && /*#__PURE__*/_react.default.createElement("a", {
88
- href: url,
89
- target: "_blank",
90
- rel: "noopener noreferrer"
91
- }, _constants.DEFAULT_ATTACHMENT_NAME, fileType && ".".concat(fileType)) || '';
51
+ _defineProperty(this, "getDefaultAttachment", (url, fileType) => url && typeof url === 'string' && /*#__PURE__*/_react.default.createElement("a", {
52
+ href: url,
53
+ target: "_blank",
54
+ rel: "noopener noreferrer"
55
+ }, _constants.DEFAULT_ATTACHMENT_NAME, fileType && ".".concat(fileType)) || '');
56
+ _defineProperty(this, "hasDefaultValueToLoad", () => this.props.input.value && typeof this.props.input.value === 'string');
57
+ _defineProperty(this, "hasDefaultFileObjectToLoad", () => {
58
+ const {
59
+ input
60
+ } = this.props;
61
+ return input.value && typeof input.value === 'object' && (0, _utils.isValidFile)(input.value.file);
92
62
  });
93
- _defineProperty(_assertThisInitialized(_this), "hasDefaultValueToLoad", function () {
94
- return _this.props.input.value && typeof _this.props.input.value === 'string';
95
- });
96
- _defineProperty(_assertThisInitialized(_this), "hasDefaultFileObjectToLoad", function () {
97
- var input = _this.props.input;
98
- return input.value && _typeof(input.value) === 'object' && (0, _utils.isValidFile)(input.value.file);
99
- });
100
- _defineProperty(_assertThisInitialized(_this), "onChange", /*#__PURE__*/function () {
101
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ev) {
102
- var _this$props$allowedPD;
103
- var file, _this$props3, resizeConfig, disableResize, fileErrorTexts, validation;
104
- return _regeneratorRuntime().wrap(function _callee$(_context) {
105
- while (1) switch (_context.prev = _context.next) {
106
- case 0:
107
- file = ev.target.files[0];
108
- _this$props3 = _this.props, resizeConfig = _this$props3.resizeConfig, disableResize = _this$props3.disableResize;
109
- fileErrorTexts = {
110
- formatError: _constants.FORMAT_ERROR_TEXT,
111
- sizeError: "".concat(_constants.SIZE_ERROR_TEXT, " ").concat(Math.round(_this.props.maxFileSize / 1048576), "MB."),
112
- aspectRatioError: "".concat(_constants.ASPECT_RATIO_ERROR_TEXT, " ").concat((_this$props$allowedPD = _this.props.allowedPDFUploadSizes) === null || _this$props$allowedPD === void 0 ? void 0 : _this$props$allowedPD.map(function (aspectRatio) {
113
- return aspectRatio.name;
114
- }).join(' - '), ")")
115
- };
116
- _this.setState({
117
- error: false
118
- });
119
- if (!file) {
120
- _context.next = 33;
121
- break;
122
- }
123
- _context.t0 = !_this.props.customValidation;
124
- if (_context.t0) {
125
- _context.next = 10;
126
- break;
127
- }
128
- _context.next = 9;
129
- return _this.props.customValidation(file, _this.onFailValidation);
130
- case 9:
131
- _context.t0 = _context.sent;
132
- case 10:
133
- validation = _context.t0;
134
- if (!validation) {
135
- _context.next = 33;
136
- break;
137
- }
138
- _context.next = 14;
139
- return (0, _validate.fileSignatureValidation)(file, _this.props.fieldTypes, file.type);
140
- case 14:
141
- validation = _context.sent;
142
- if (!validation) {
143
- _context.next = 32;
144
- break;
145
- }
146
- if (!_this.props.sanitize) {
147
- _context.next = 20;
148
- break;
149
- }
150
- _context.next = 19;
151
- return _this.props.sanitize(file);
152
- case 19:
153
- file = _context.sent;
154
- case 20:
155
- validation = (0, _validate.fileSizeValidation)(file, _this.props.maxFileSize);
156
- if (!(validation && (0, _utils.isPDF)(file) && !(0, _array.isEmpty)(_this.props.allowedPDFUploadSizes))) {
157
- _context.next = 26;
158
- break;
159
- }
160
- _context.next = 24;
161
- return (0, _utils.pdfAspectRatioValidation)(file, _this.props.allowedPDFUploadSizes);
162
- case 24:
163
- validation = _context.sent;
164
- return _context.abrupt("return", validation ? _this.setFile(file) : _this.onFailValidation(fileErrorTexts.aspectRatioError));
165
- case 26:
166
- if (!(!validation && !disableResize && (0, _utils.isImage)(file) && !(0, _browser.isIE)())) {
167
- _context.next = 31;
168
- break;
169
- }
170
- _context.next = 29;
171
- return (0, _image.resizeImage)(file, resizeConfig);
172
- case 29:
173
- file = _context.sent;
174
- validation = (0, _validate.fileSizeValidation)(file, _this.props.maxFileSize);
175
- case 31:
176
- return _context.abrupt("return", validation ? _this.setFile(file) : _this.onFailValidation(fileErrorTexts.sizeError));
177
- case 32:
178
- _this.onFailValidation(fileErrorTexts.formatError);
179
- case 33:
180
- case "end":
181
- return _context.stop();
182
- }
183
- }, _callee);
184
- }));
185
- return function (_x) {
186
- return _ref.apply(this, arguments);
63
+ _defineProperty(this, "onChange", async ev => {
64
+ var _this$props$allowedPD;
65
+ let file = ev.target.files[0];
66
+ const {
67
+ resizeConfig,
68
+ disableResize
69
+ } = this.props;
70
+ const fileErrorTexts = {
71
+ formatError: _constants.FORMAT_ERROR_TEXT,
72
+ sizeError: "".concat(_constants.SIZE_ERROR_TEXT, " ").concat(Math.round(this.props.maxFileSize / 1048576), "MB."),
73
+ aspectRatioError: "".concat(_constants.ASPECT_RATIO_ERROR_TEXT, " ").concat((_this$props$allowedPD = this.props.allowedPDFUploadSizes) === null || _this$props$allowedPD === void 0 ? void 0 : _this$props$allowedPD.map(aspectRatio => aspectRatio.name).join(' - '), ")")
187
74
  };
188
- }());
189
- _defineProperty(_assertThisInitialized(_this), "onFailValidation", function (errorMessage) {
190
- return _this.setState({
191
- error: true,
192
- errorText: errorMessage
75
+ this.setState({
76
+ error: false
193
77
  });
194
- });
195
- _defineProperty(_assertThisInitialized(_this), "setFile", /*#__PURE__*/function () {
196
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(file) {
197
- var _this$props4, onChange, onLoaded;
198
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
199
- while (1) switch (_context2.prev = _context2.next) {
200
- case 0:
201
- _this$props4 = _this.props, onChange = _this$props4.onChange, onLoaded = _this$props4.onLoaded;
202
- _this.setState({
203
- loading: true,
204
- name: file.name
205
- });
206
- if ((0, _utils.hasPreview)(file)) _this.buildPreview(file);
207
- if (onChange) onChange({
208
- file: file
209
- });
210
- _this.setState({
211
- loading: false
212
- });
213
- if (onLoaded) onLoaded();
214
- case 6:
215
- case "end":
216
- return _context2.stop();
78
+ if (file) {
79
+ let validation = !this.props.customValidation || (await this.props.customValidation(file, this.onFailValidation));
80
+ if (validation) {
81
+ validation = await (0, _validate.fileSignatureValidation)(file, this.props.fieldTypes, file.type);
82
+ if (validation) {
83
+ if (this.props.sanitize) file = await this.props.sanitize(file);
84
+ validation = (0, _validate.fileSizeValidation)(file, this.props.maxFileSize);
85
+ if (validation && (0, _utils.isPDF)(file) && !(0, _array.isEmpty)(this.props.allowedPDFUploadSizes)) {
86
+ validation = await (0, _utils.pdfAspectRatioValidation)(file, this.props.allowedPDFUploadSizes);
87
+ return validation ? this.setFile(file) : this.onFailValidation(fileErrorTexts.aspectRatioError);
88
+ }
89
+ if (!validation && !disableResize && (0, _utils.isImage)(file) && !(0, _browser.isIE)()) {
90
+ file = await (0, _image.resizeImage)(file, resizeConfig);
91
+ validation = (0, _validate.fileSizeValidation)(file, this.props.maxFileSize);
92
+ }
93
+ return validation ? this.setFile(file) : this.onFailValidation(fileErrorTexts.sizeError);
217
94
  }
218
- }, _callee2);
219
- }));
220
- return function (_x2) {
221
- return _ref2.apply(this, arguments);
222
- };
223
- }());
224
- _defineProperty(_assertThisInitialized(_this), "buildPreview", function (file) {
225
- var reader = new FileReader();
226
- reader.onload = function (e) {
227
- return _this.setState({
228
- preview: {
229
- src: e.target.result,
230
- type: file.type
231
- }
232
- });
233
- };
95
+ this.onFailValidation(fileErrorTexts.formatError);
96
+ }
97
+ }
98
+ });
99
+ _defineProperty(this, "onFailValidation", errorMessage => this.setState({
100
+ error: true,
101
+ errorText: errorMessage
102
+ }));
103
+ _defineProperty(this, "setFile", async file => {
104
+ const {
105
+ onChange,
106
+ onLoaded
107
+ } = this.props;
108
+ this.setState({
109
+ loading: true,
110
+ name: file.name
111
+ });
112
+ if ((0, _utils.hasPreview)(file)) this.buildPreview(file);
113
+ if (onChange) onChange({
114
+ file
115
+ });
116
+ this.setState({
117
+ loading: false
118
+ });
119
+ if (onLoaded) onLoaded();
120
+ });
121
+ _defineProperty(this, "buildPreview", file => {
122
+ const reader = new FileReader();
123
+ reader.onload = e => this.setState({
124
+ preview: {
125
+ src: e.target.result,
126
+ type: file.type
127
+ }
128
+ });
234
129
  reader.readAsDataURL(file);
235
130
  });
236
- _defineProperty(_assertThisInitialized(_this), "removeValue", function () {
237
- _this.setState({
131
+ _defineProperty(this, "removeValue", () => {
132
+ this.setState({
238
133
  loading: false,
239
134
  name: '',
240
135
  preview: {}
241
136
  });
242
- if (_this.props.onChange) _this.props.onChange('');
137
+ if (this.props.onChange) this.props.onChange('');
138
+ });
139
+ this.state = {
140
+ loading: false,
141
+ name: '',
142
+ preview: {},
143
+ error: false,
144
+ errorText: _constants.FORMAT_ERROR_TEXT
145
+ };
146
+ }
147
+ componentDidMount() {
148
+ this.loadDefaultValues();
149
+ }
150
+ componentDidUpdate(prevProps) {
151
+ var _prevProps$fieldTypes;
152
+ const {
153
+ fieldTypes,
154
+ input
155
+ } = this.props;
156
+ if (((_prevProps$fieldTypes = prevProps.fieldTypes) === null || _prevProps$fieldTypes === void 0 ? void 0 : _prevProps$fieldTypes[0]) !== (fieldTypes === null || fieldTypes === void 0 ? void 0 : fieldTypes[0])) this.removeValue();else if ((0, _utils.isNewFile)(prevProps.input.value, input.value)) this.loadDefaultValues();
157
+ }
158
+ render() {
159
+ const {
160
+ acceptedFileTypes,
161
+ classes,
162
+ containerClassname,
163
+ disabled,
164
+ errorClassname,
165
+ fieldTypes,
166
+ icon,
167
+ input,
168
+ loadingTextClassname,
169
+ previewClassname,
170
+ previewProps,
171
+ RemoveIcon,
172
+ removeFileClassname
173
+ } = this.props;
174
+ const {
175
+ name,
176
+ preview,
177
+ loading,
178
+ error,
179
+ errorText
180
+ } = this.state;
181
+ const loadingDefaultValue = this.hasDefaultValueToLoad() && !name;
182
+ return /*#__PURE__*/_react.default.createElement(_layout.default, {
183
+ acceptedFileTypes: acceptedFileTypes,
184
+ classes: classes,
185
+ containerClassname: containerClassname,
186
+ disabled: disabled,
187
+ error: error,
188
+ errorClassname: errorClassname,
189
+ errorText: errorText,
190
+ fieldTypes: fieldTypes,
191
+ icon: icon,
192
+ loading: loading || loadingDefaultValue,
193
+ loadingTextClassname: loadingTextClassname,
194
+ name: name || this.getDefaultAttachment(input.value),
195
+ preview: preview,
196
+ previewClassname: previewClassname,
197
+ previewProps: previewProps,
198
+ onChange: this.onChange,
199
+ onClick: this.removeValue,
200
+ removeFileClassname: removeFileClassname,
201
+ RemoveIcon: RemoveIcon,
202
+ uploadingText: loadingDefaultValue ? _constants.DEFAULT_UPLOADING_TEXT : ''
243
203
  });
244
- return _this;
245
204
  }
246
- _createClass(AttachmentContainer, [{
247
- key: "render",
248
- value: function render() {
249
- var _this$props5 = this.props,
250
- acceptedFileTypes = _this$props5.acceptedFileTypes,
251
- classes = _this$props5.classes,
252
- containerClassname = _this$props5.containerClassname,
253
- disabled = _this$props5.disabled,
254
- errorClassname = _this$props5.errorClassname,
255
- fieldTypes = _this$props5.fieldTypes,
256
- icon = _this$props5.icon,
257
- input = _this$props5.input,
258
- loadingTextClassname = _this$props5.loadingTextClassname,
259
- previewClassname = _this$props5.previewClassname,
260
- previewProps = _this$props5.previewProps,
261
- RemoveIcon = _this$props5.RemoveIcon,
262
- removeFileClassname = _this$props5.removeFileClassname;
263
- var _this$state = this.state,
264
- name = _this$state.name,
265
- preview = _this$state.preview,
266
- loading = _this$state.loading,
267
- error = _this$state.error,
268
- errorText = _this$state.errorText;
269
- var loadingDefaultValue = this.hasDefaultValueToLoad() && !name;
270
- return /*#__PURE__*/_react.default.createElement(_layout.default, {
271
- acceptedFileTypes: acceptedFileTypes,
272
- classes: classes,
273
- containerClassname: containerClassname,
274
- disabled: disabled,
275
- error: error,
276
- errorClassname: errorClassname,
277
- errorText: errorText,
278
- fieldTypes: fieldTypes,
279
- icon: icon,
280
- loading: loading || loadingDefaultValue,
281
- loadingTextClassname: loadingTextClassname,
282
- name: name || this.getDefaultAttachment(input.value),
283
- preview: preview,
284
- previewClassname: previewClassname,
285
- previewProps: previewProps,
286
- onChange: this.onChange,
287
- onClick: this.removeValue,
288
- removeFileClassname: removeFileClassname,
289
- RemoveIcon: RemoveIcon,
290
- uploadingText: loadingDefaultValue ? _constants.DEFAULT_UPLOADING_TEXT : ''
291
- });
292
- }
293
- }]);
294
- return AttachmentContainer;
295
- }(_react.Component);
205
+ }
296
206
  AttachmentContainer.propTypes = {
297
207
  acceptedFileTypes: _propTypes.string,
298
208
  allowedPDFUploadSizes: (0, _propTypes.arrayOf)((0, _propTypes.shape)({
@@ -15,31 +15,31 @@ var _Preview = _interopRequireDefault(require("./components/Preview"));
15
15
  var _constants = require("./constants");
16
16
  var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
- var Attachment = function Attachment(_ref) {
19
- var acceptedFileTypes = _ref.acceptedFileTypes,
20
- name = _ref.name,
21
- preview = _ref.preview,
22
- loading = _ref.loading,
23
- containerClassname = _ref.containerClassname,
24
- previewClassname = _ref.previewClassname,
25
- removeFileClassname = _ref.removeFileClassname,
26
- onClick = _ref.onClick,
27
- onChange = _ref.onChange,
28
- error = _ref.error,
29
- errorText = _ref.errorText,
30
- fieldTypes = _ref.fieldTypes,
31
- loadingTextClassname = _ref.loadingTextClassname,
32
- classes = _ref.classes,
33
- errorClassname = _ref.errorClassname,
34
- icon = _ref.icon,
35
- disabled = _ref.disabled,
36
- uploadingText = _ref.uploadingText,
37
- RemoveIcon = _ref.RemoveIcon,
38
- previewProps = _ref.previewProps;
39
- var fieldType = acceptedFileTypes || fieldTypes.map(function (type) {
40
- return _files.inputFiles[type].inputType;
41
- }).join();
42
- var Icon = RemoveIcon || _DeleteForever.default;
18
+ const Attachment = _ref => {
19
+ let {
20
+ acceptedFileTypes,
21
+ name,
22
+ preview,
23
+ loading,
24
+ containerClassname,
25
+ previewClassname,
26
+ removeFileClassname,
27
+ onClick,
28
+ onChange,
29
+ error,
30
+ errorText,
31
+ fieldTypes,
32
+ loadingTextClassname,
33
+ classes,
34
+ errorClassname,
35
+ icon,
36
+ disabled,
37
+ uploadingText,
38
+ RemoveIcon,
39
+ previewProps
40
+ } = _ref;
41
+ const fieldType = acceptedFileTypes || fieldTypes.map(type => _files.inputFiles[type].inputType).join();
42
+ const Icon = RemoveIcon || _DeleteForever.default;
43
43
  return name && !loading ? /*#__PURE__*/_react.default.createElement("div", {
44
44
  className: "".concat(_stylesModule.default.previewContainer, " ").concat(previewClassname)
45
45
  }, /*#__PURE__*/_react.default.createElement(_Preview.default, {
@@ -5,8 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.retrieveStyle = void 0;
7
7
  var _seamlessImmutable = require("seamless-immutable");
8
- var retrieveStyle = exports.retrieveStyle = function retrieveStyle(_ref) {
9
- var theme = _ref.theme;
8
+ const retrieveStyle = _ref => {
9
+ let {
10
+ theme
11
+ } = _ref;
10
12
  return {
11
13
  container: {
12
14
  border: (0, _seamlessImmutable.getIn)(theme, ['UTAttachment', 'container', 'border'])
@@ -20,4 +22,5 @@ var retrieveStyle = exports.retrieveStyle = function retrieveStyle(_ref) {
20
22
  }
21
23
  }
22
24
  };
23
- };
25
+ };
26
+ exports.retrieveStyle = retrieveStyle;