@wise/dynamic-flow-client 3.3.1 → 3.4.0-experimental-9862ccf

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 (168) hide show
  1. package/build/common/httpClientContext/HttpClientContext.js +35 -0
  2. package/build/common/httpClientContext/index.js +1 -0
  3. package/build/common/makeHttpClient/index.js +1 -0
  4. package/build/common/makeHttpClient/makeHttpClient.js +34 -0
  5. package/build/common/messages/generic-error.messages.js +18 -0
  6. package/build/common/messages/help.messages.js +8 -0
  7. package/build/common/messages/multi-file-upload.messages.js +18 -0
  8. package/build/common/messages/paragraph.messages.js +13 -0
  9. package/build/common/messages/repeatable.messages.js +23 -0
  10. package/build/common/messages/validation.array.messages.js +13 -0
  11. package/build/common/messages/validation.messages.js +53 -0
  12. package/build/common/utils/api-utils.js +4 -0
  13. package/build/legacy/common/constants/DateMode.js +4 -0
  14. package/build/legacy/common/constants/FeatureName.js +4 -0
  15. package/build/legacy/common/constants/FormControlType.js +21 -0
  16. package/build/legacy/common/constants/MonthFormat.js +4 -0
  17. package/build/legacy/common/constants/Size.js +7 -0
  18. package/build/legacy/common/constants/index.js +4 -0
  19. package/build/legacy/common/contexts/dynamicFlowContexts/DynamicFlowContexts.js +36 -0
  20. package/build/legacy/common/contexts/dynamicFlowContexts/usePendingPromiseCounter.js +13 -0
  21. package/build/legacy/common/contexts/eventsContext/EventsContext.js +38 -0
  22. package/build/legacy/common/contexts/featureContext/FeatureContext.js +22 -0
  23. package/build/legacy/common/contexts/index.js +3 -0
  24. package/build/legacy/common/contexts/logContext/LogContext.js +44 -0
  25. package/build/legacy/common/hooks/index.js +7 -0
  26. package/build/legacy/common/hooks/useDebouncedFunction/useDebouncedFunction.js +9 -0
  27. package/build/legacy/common/hooks/useExternal/useExternal.js +15 -0
  28. package/build/legacy/common/hooks/useExternalStepPolling/useExternalStepPolling.js +70 -0
  29. package/build/legacy/common/hooks/usePersistAsync/usePersistAsync.js +172 -0
  30. package/build/legacy/common/hooks/usePolling/usePolling.js +51 -0
  31. package/build/legacy/common/hooks/usePrevious/usePrevious.js +8 -0
  32. package/build/legacy/common/hooks/useStepPolling/useStepPolling.js +43 -0
  33. package/build/legacy/common/messages.js +8 -0
  34. package/build/legacy/common/utils/api-utils.js +6 -0
  35. package/build/legacy/common/utils/date-utils.js +22 -0
  36. package/build/legacy/common/utils/debounce.js +38 -0
  37. package/build/legacy/common/utils/file-utils.js +45 -0
  38. package/build/legacy/common/utils/id-utils.js +5 -0
  39. package/build/legacy/common/utils/index.js +11 -0
  40. package/build/legacy/common/utils/is-equal.js +21 -0
  41. package/build/legacy/common/utils/misc-utils.js +4 -0
  42. package/build/legacy/common/utils/mobile-utils.js +23 -0
  43. package/build/legacy/common/utils/model-utils.js +33 -0
  44. package/build/legacy/common/utils/schema-utils.js +97 -0
  45. package/build/legacy/common/utils/step-utils.js +32 -0
  46. package/build/legacy/common/validators/index.js +5 -0
  47. package/build/legacy/common/validators/models/model-utils.js +119 -0
  48. package/build/legacy/common/validators/models/model-validators.js +62 -0
  49. package/build/legacy/common/validators/schemas/schema-validators.js +101 -0
  50. package/build/legacy/common/validators/types/type-validators.js +14 -0
  51. package/build/legacy/common/validators/validationFailures/validation-failures.js +139 -0
  52. package/build/legacy/common/validators/validationFailures/validation-failures.utils.js +40 -0
  53. package/build/legacy/common/validators/values/value-validators.js +6 -0
  54. package/build/legacy/dynamic-flow-types.js +1 -0
  55. package/build/legacy/dynamicFlow/BackButton.js +22 -0
  56. package/build/legacy/dynamicFlow/DynamicFlowStep.js +37 -0
  57. package/build/legacy/formControl/FormControl.js +266 -0
  58. package/build/legacy/formControl/index.js +1 -0
  59. package/build/legacy/formControl/utils/getAutocompleteString.js +80 -0
  60. package/build/legacy/formControl/utils/index.js +2 -0
  61. package/build/legacy/formControl/utils/value-utils.js +108 -0
  62. package/build/legacy/jsonSchemaForm/allOfSchema/AllOfSchema.js +50 -0
  63. package/build/legacy/jsonSchemaForm/allOfSchema/index.js +1 -0
  64. package/build/legacy/jsonSchemaForm/arrayTypeSchema/ArraySchema.js +25 -0
  65. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.js +30 -0
  66. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.js +141 -0
  67. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/index.js +1 -0
  68. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/index.js +2 -0
  69. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/upload-utils.js +79 -0
  70. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/useFormattedDefaultErrorMessages.js +14 -0
  71. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/ItemSummary.js +7 -0
  72. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchema.js +134 -0
  73. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchemaStep.js +85 -0
  74. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/utils/summary-utils.js +135 -0
  75. package/build/legacy/jsonSchemaForm/arrayTypeSchema/index.js +1 -0
  76. package/build/legacy/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.js +111 -0
  77. package/build/legacy/jsonSchemaForm/basicTypeSchema/index.js +1 -0
  78. package/build/legacy/jsonSchemaForm/controlFeedback/ControlFeedback.js +86 -0
  79. package/build/legacy/jsonSchemaForm/controlFeedback/index.js +1 -0
  80. package/build/legacy/jsonSchemaForm/help/Help.js +20 -0
  81. package/build/legacy/jsonSchemaForm/help/index.js +1 -0
  82. package/build/legacy/jsonSchemaForm/objectSchema/ObjectSchema.js +77 -0
  83. package/build/legacy/jsonSchemaForm/objectSchema/index.js +1 -0
  84. package/build/legacy/jsonSchemaForm/oneOfSchema/OneOfSchema.js +155 -0
  85. package/build/legacy/jsonSchemaForm/oneOfSchema/index.js +1 -0
  86. package/build/legacy/jsonSchemaForm/oneOfSchema/utils.js +68 -0
  87. package/build/legacy/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.js +26 -0
  88. package/build/legacy/jsonSchemaForm/persistAsyncSchema/index.js +1 -0
  89. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema.js +165 -0
  90. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/index.js +1 -0
  91. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/PersistAsyncBlobSchema.js +131 -0
  92. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/UploadInputAdapter.js +31 -0
  93. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/index.js +1 -0
  94. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.js +72 -0
  95. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/index.js +1 -0
  96. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promoted-one-of-utils.js +8 -0
  97. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfCheckboxControl.js +27 -0
  98. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfControl.js +31 -0
  99. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfRadioControl.js +32 -0
  100. package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.js +54 -0
  101. package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.messages.js +13 -0
  102. package/build/legacy/jsonSchemaForm/readOnlySchema/index.js +1 -0
  103. package/build/legacy/jsonSchemaForm/schemaFormControl/SchemaFormControl.js +133 -0
  104. package/build/legacy/jsonSchemaForm/schemaFormControl/index.js +1 -0
  105. package/build/legacy/jsonSchemaForm/schemaFormControl/utils/index.js +1 -0
  106. package/build/legacy/jsonSchemaForm/schemaFormControl/utils/mapping-utils.js +107 -0
  107. package/build/legacy/layout/DynamicLayout.js +68 -0
  108. package/build/legacy/layout/alert/DynamicAlert.js +29 -0
  109. package/build/legacy/layout/box/DynamicBox.js +41 -0
  110. package/build/legacy/layout/button/DynamicButton.js +27 -0
  111. package/build/legacy/layout/button/utils.js +45 -0
  112. package/build/legacy/layout/columns/DynamicColumns.js +38 -0
  113. package/build/legacy/layout/decision/DynamicDecision.js +21 -0
  114. package/build/legacy/layout/divider/DynamicDivider.js +9 -0
  115. package/build/legacy/layout/external/DynamicExternal.js +32 -0
  116. package/build/legacy/layout/external/DynamicExternal.messages.js +8 -0
  117. package/build/legacy/layout/form/DynamicForm.js +22 -0
  118. package/build/legacy/layout/heading/DynamicHeading.js +51 -0
  119. package/build/legacy/layout/icon/DynamicIcon.js +17 -0
  120. package/build/legacy/layout/icon/FlagIcon.js +198 -0
  121. package/build/legacy/layout/icon/NamedIcon.js +19 -0
  122. package/build/legacy/layout/image/DynamicImage.js +111 -0
  123. package/build/legacy/layout/index.js +20 -0
  124. package/build/legacy/layout/instructions/DynamicInstructions.js +30 -0
  125. package/build/legacy/layout/list/DynamicStatusList.js +37 -0
  126. package/build/legacy/layout/loadingIndicator/DynamicLoadingIndicator.js +11 -0
  127. package/build/legacy/layout/markdown/DynamicMarkdown.js +23 -0
  128. package/build/legacy/layout/modal/DynamicModal.js +26 -0
  129. package/build/legacy/layout/paragraph/DynamicParagraph.js +46 -0
  130. package/build/legacy/layout/paragraph/useSnackBarIfAvailable.js +9 -0
  131. package/build/legacy/layout/review/DynamicReview.js +58 -0
  132. package/build/legacy/layout/search/DynamicSearch.js +58 -0
  133. package/build/legacy/layout/search/SearchInput.js +17 -0
  134. package/build/legacy/layout/search/SearchResults.js +31 -0
  135. package/build/legacy/layout/search/useSearch.js +137 -0
  136. package/build/legacy/layout/utils/getNavigationOptionMedia.js +28 -0
  137. package/build/legacy/layout/utils/index.js +32 -0
  138. package/build/legacy/step/cameraStep/CameraStep.js +124 -0
  139. package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.js +161 -0
  140. package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.messages.js +58 -0
  141. package/build/legacy/step/cameraStep/cameraCapture/components/bottomBar/BottomBar.js +28 -0
  142. package/build/legacy/step/cameraStep/cameraCapture/components/index.js +3 -0
  143. package/build/legacy/step/cameraStep/cameraCapture/components/orientationLockOverlay/OrientationLockOverlay.js +19 -0
  144. package/build/legacy/step/cameraStep/cameraCapture/components/orientationLockOverlay/OrientationLockOverlay.messages.js +8 -0
  145. package/build/legacy/step/cameraStep/cameraCapture/hooks/useFullScreenOrientationLock.js +60 -0
  146. package/build/legacy/step/cameraStep/cameraCapture/hooks/useVideoConstraints.js +80 -0
  147. package/build/legacy/step/cameraStep/cameraCapture/index.js +1 -0
  148. package/build/legacy/step/cameraStep/cameraCapture/overlay/Overlay.js +77 -0
  149. package/build/legacy/step/cameraStep/cameraCapture/screens/cameraErrorScreen/CameraErrorScreen.js +18 -0
  150. package/build/legacy/step/cameraStep/cameraCapture/screens/index.js +1 -0
  151. package/build/legacy/step/cameraStep/cameraCapture/tracking/index.js +109 -0
  152. package/build/legacy/step/cameraStep/cameraCapture/types/index.js +7 -0
  153. package/build/legacy/step/cameraStep/cameraCapture/utils/index.js +107 -0
  154. package/build/legacy/step/cameraStep/index.js +1 -0
  155. package/build/legacy/step/externalConfirmationStep/ExternalConfirmationStep.js +64 -0
  156. package/build/legacy/step/externalConfirmationStep/ExternalConfirmationStep.messages.js +23 -0
  157. package/build/legacy/step/externalConfirmationStep/index.js +1 -0
  158. package/build/legacy/step/index.js +3 -0
  159. package/build/legacy/step/layoutStep/LayoutStep.js +33 -0
  160. package/build/legacy/step/layoutStep/index.js +1 -0
  161. package/build/legacy/step/layoutStep/utils/index.js +2 -0
  162. package/build/legacy/step/layoutStep/utils/inline-reference-utils.js +105 -0
  163. package/build/legacy/step/layoutStep/utils/layout-utils.js +212 -0
  164. package/build/main.js +14 -29
  165. package/build/main.min.js +1 -1
  166. package/build/main.mjs +14 -29
  167. package/build/types/revamp/domain/features/events.d.ts +1 -1
  168. package/package.json +2 -2
@@ -0,0 +1,266 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
28
+ import { Checkbox, DateInput, DateLookup, InputWithDisplayFormat, PhoneNumberInput, RadioGroup, SelectInput, SelectInputOptionContent, Tabs, TextareaWithDisplayFormat, Upload, } from '@transferwise/components';
29
+ import { PureComponent } from 'react';
30
+ import { DateMode, FormControlType, MonthFormat, Size } from '../common/constants';
31
+ import { dateToDateString } from '../common/utils';
32
+ import { isArray, isNumber, isString } from '../common/validators';
33
+ import { getSafeStringOrNumberValue, getSafeDateOrStringValue, getSafeDateStringValue, getSafeStringValue, getSafeBooleanValue, getAutocompleteString, } from './utils';
34
+ var FormControl = /** @class */ (function (_super) {
35
+ __extends(FormControl, _super);
36
+ function FormControl(props) {
37
+ var _this = _super.call(this, props) || this;
38
+ _this.getAutocompleteValue = function (_a) {
39
+ var _b = _a === void 0 ? {} : _a, _c = _b.prefix, prefix = _c === void 0 ? '' : _c, _d = _b.suffix, suffix = _d === void 0 ? '' : _d;
40
+ var _e = _this.props, autoComplete = _e.autoComplete, autocompleteHint = _e.autocompleteHint;
41
+ if (isArray(autocompleteHint)) {
42
+ return getAutocompleteString(autocompleteHint, { prefix: prefix, suffix: suffix });
43
+ }
44
+ return autoComplete ? 'on' : 'off';
45
+ };
46
+ _this.handleOnChange = function (value, metadata) {
47
+ _this.props.onChange(value, undefined, metadata);
48
+ };
49
+ _this.handleInputOnChange = function (event) {
50
+ _this.props.onChange(event.target.value);
51
+ };
52
+ _this.handleOnFocus = function () {
53
+ var _a, _b;
54
+ (_b = (_a = _this.props).onFocus) === null || _b === void 0 ? void 0 : _b.call(_a);
55
+ };
56
+ _this.handleOnBlur = function () {
57
+ var _a, _b;
58
+ (_b = (_a = _this.props).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a);
59
+ };
60
+ _this.getSelectedOption = function (options) {
61
+ if (_this.state.selectedOption !== null && typeof _this.state.selectedOption !== 'undefined') {
62
+ return options.find(function (option) { var _a; return ((_a = _this.state.selectedOption) === null || _a === void 0 ? void 0 : _a.value) === option.value; });
63
+ }
64
+ if (_this.props.value !== null && typeof _this.props.value !== 'undefined') {
65
+ return options.find(function (option) { return _this.props.value === option.value; });
66
+ }
67
+ return undefined;
68
+ };
69
+ _this.mapOption = function (option) { return (__assign(__assign({}, option), { value: isNumber(option.value) || isString(option.value) ? option.value : undefined, secondary: option.note, disabled: option.disabled || _this.props.disabled, readOnly: _this.props.readOnly })); };
70
+ _this.state = {
71
+ selectedOption: props.selectedOption,
72
+ touched: false,
73
+ prevValue: props.value
74
+ };
75
+ return _this;
76
+ }
77
+ FormControl.getDerivedStateFromProps = function (nextProps, previousState) {
78
+ if (previousState.prevValue !== nextProps.value) {
79
+ return { prevValue: nextProps.value, value: nextProps.value };
80
+ }
81
+ return null;
82
+ };
83
+ FormControl.prototype.render = function () {
84
+ var _this = this;
85
+ var _a, _b;
86
+ var _c = this.props, name = _c.name, placeholder = _c.placeholder, step = _c.step, countryCode = _c.countryCode, type = _c.type, options = _c.options, disabled = _c.disabled, readOnly = _c.readOnly, required = _c.required, minLength = _c.minLength, maxLength = _c.maxLength, min = _c.min, max = _c.max, searchPlaceholder = _c.searchPlaceholder, onSearchChange = _c.onSearchChange, size = _c.size, uploadProps = _c.uploadProps, label = _c.label, monthFormat = _c.monthFormat,
87
+ // FIXME pass id to all components that accept it
88
+ id = _c.id, minDate = _c.minDate, maxDate = _c.maxDate, value = _c.value, mode = _c.mode, describedBy = _c.describedBy;
89
+ switch (type) {
90
+ case FormControlType.RADIO:
91
+ return (_jsx(RadioGroup, { radios: options.map(this.mapOption), name: name, selectedValue: getSafeStringOrNumberValue(value, { coerceValue: true }), onChange: this.handleOnChange }));
92
+ case FormControlType.CHECKBOX:
93
+ return (_jsx(Checkbox, { checked: getSafeBooleanValue(value, { coerceValue: true }), disabled: disabled, label: label, required: required, readOnly: readOnly, onChange: this.handleOnChange, onBlur: this.handleOnBlur, onFocus: this.handleOnFocus }));
94
+ case FormControlType.SELECT: {
95
+ var search = options.length >= 8;
96
+ var items = options;
97
+ var selected = this.getSelectedOption(options);
98
+ return (_jsx("div", __assign({ className: "d-flex flex-column" }, { children: _jsx(SelectInput, { id: id, items: items.map(function (value) { return ({
99
+ type: 'option',
100
+ value: value,
101
+ disabled: value.disabled
102
+ }); }), value: (_a = selected) !== null && _a !== void 0 ? _a : null, renderValue: function (_a, withinTrigger) {
103
+ var hideIconInTrigger = _a.hideIconInTrigger, icon = _a.icon, label = _a.label, note = _a.note, secondary = _a.secondary;
104
+ return (_jsx(SelectInputOptionContent, { title: label, note: note !== null && note !== void 0 ? note : secondary, icon: withinTrigger && hideIconInTrigger ? undefined : icon }));
105
+ }, filterable: search, disabled: disabled, placeholder: placeholder, filterPlaceholder: searchPlaceholder, onChange: function (option) {
106
+ var _a;
107
+ _this.setState({ selectedOption: option });
108
+ _this.props.onChange((_a = option === null || option === void 0 ? void 0 : option.value) !== null && _a !== void 0 ? _a : null);
109
+ }, onFilterChange: search && onSearchChange
110
+ ? function (_a) {
111
+ var query = _a.query;
112
+ onSearchChange(query);
113
+ }
114
+ : undefined, onClear: function () {
115
+ _this.setState({ selectedOption: null });
116
+ _this.props.onChange(null);
117
+ } }) })));
118
+ }
119
+ case FormControlType.TAB:
120
+ return (_jsx(Tabs, { selected: (((_b = this.getSelectedOption(options)) === null || _b === void 0 ? void 0 : _b.value) || 0), tabs: options.map(function (option) { return ({
121
+ title: option.label,
122
+ content: _jsx(_Fragment, {}),
123
+ disabled: option.disabled || false
124
+ }); }), name: id, onTabSelect: function (index) {
125
+ var hasSelectedOption = !!_this.state.selectedOption;
126
+ _this.setState({
127
+ selectedOption: options.find(function (option) { return option.value === index; })
128
+ });
129
+ _this.props.onChange(index, hasSelectedOption ? 'user' : 'init');
130
+ } }));
131
+ case FormControlType.NUMERIC:
132
+ case FormControlType.NUMBER: {
133
+ return (_jsx("input", { autoComplete: this.getAutocompleteValue(), className: "form-control", disabled: disabled, id: id, max: max, min: min, placeholder: placeholder, readOnly: readOnly, required: required, step: step, type: "number", value: getSafeStringOrNumberValue(value, { coerceValue: true }), "aria-describedby": describedBy, onBlur: this.handleOnBlur, onChange: function (event) {
134
+ if (type === FormControlType.NUMERIC) {
135
+ _this.props.onChange(event.target.value);
136
+ }
137
+ else {
138
+ // Input type number target value is a string and needs to be a number
139
+ _this.props.onChange(parseFloat(event.target.value));
140
+ // FIXME: maybe this parsing should be done outside of this component in SchemaFormControl,
141
+ // where we know what schema we're working with?
142
+ }
143
+ }, onFocus: this.handleOnFocus, onWheel: function (event) {
144
+ if (event.target instanceof HTMLElement) {
145
+ // To prevent values being changed when input is focussed and user scrolls
146
+ event.target.blur();
147
+ }
148
+ } }));
149
+ }
150
+ case FormControlType.HIDDEN:
151
+ return (_jsx("input", { type: "hidden", name: name, value: getSafeStringValue(value, { coerceValue: true }), id: id }));
152
+ case FormControlType.PASSWORD:
153
+ return (_jsx("input", { autoComplete: this.getAutocompleteValue(), className: "form-control", disabled: disabled, id: id, placeholder: placeholder, readOnly: readOnly, required: required, type: "password", value: getSafeStringValue(value, { coerceValue: true }), "aria-describedby": describedBy, onBlur: this.handleOnBlur, onChange: this.handleInputOnChange, onFocus: this.handleOnFocus }));
154
+ case FormControlType.DATE:
155
+ case FormControlType.DATETIME:
156
+ return (_jsx(DateInput, { dayAutoComplete: this.getAutocompleteValue({ suffix: '-day' }), yearAutoComplete: this.getAutocompleteValue({ suffix: '-year' }), disabled: disabled, size: size, value: getSafeDateOrStringValue(value), mode: mode, monthFormat: monthFormat, onBlur: this.handleOnBlur, onChange: this.handleOnChange, onFocus: this.handleOnFocus }));
157
+ case FormControlType.DATELOOKUP: {
158
+ return (_jsx(DateLookup
159
+ // DateLookup handles null values perfectly well, it's just typed incorrectly
160
+ , {
161
+ // DateLookup handles null values perfectly well, it's just typed incorrectly
162
+ value: getSafeDateStringValue(value), min: minDate, max: maxDate, placeholder: placeholder, monthFormat: monthFormat, disabled: disabled, onChange: function (date) {
163
+ // FIXME We need types for DateLookup
164
+ _this.handleOnChange(dateToDateString(date));
165
+ }, onBlur: this.handleOnBlur, onFocus: this.handleOnFocus }));
166
+ }
167
+ case FormControlType.TEL:
168
+ return (_jsx(PhoneNumberInput, { disabled: disabled, countryCode: countryCode, placeholder: placeholder, required: required, searchPlaceholder: searchPlaceholder, size: size, initialValue: getSafeStringValue(value), onBlur: this.handleOnBlur, onChange: function (value) { return _this.handleOnChange(value); }, onFocus: this.handleOnFocus }));
169
+ case FormControlType.TEXTAREA: {
170
+ var textareaProps = {
171
+ className: 'form-control tw-form-control',
172
+ id: id,
173
+ name: name,
174
+ placeholder: placeholder,
175
+ value: getSafeStringValue(value, { coerceValue: true }),
176
+ readOnly: readOnly,
177
+ required: required,
178
+ minLength: minLength,
179
+ maxLength: maxLength,
180
+ onFocus: this.handleOnFocus,
181
+ onBlur: this.handleOnBlur,
182
+ disabled: disabled,
183
+ autoComplete: this.getAutocompleteValue()
184
+ };
185
+ if (this.props.displayPattern) {
186
+ return (_jsx(TextareaWithDisplayFormat, __assign({ displayPattern: this.props.displayPattern }, textareaProps, { onChange: this.handleOnChange })));
187
+ }
188
+ return (_jsx("textarea", __assign({}, textareaProps, { "aria-describedby": describedBy, onChange: this.handleInputOnChange })));
189
+ }
190
+ case FormControlType.FILE:
191
+ case FormControlType.UPLOAD: {
192
+ return (
193
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
194
+ // @ts-expect-error - TODO: Remove this once Upload is migrated to TypeScript
195
+ _jsx(Upload, __assign({}, uploadProps, { usAccept: uploadProps.usAccept || '*', usDisabled: uploadProps.usDisabled || disabled, onSuccess: function (base64url, filename) {
196
+ _this.handleOnChange(base64url, { filename: filename });
197
+ }, onFailure: function () {
198
+ _this.handleOnChange(null);
199
+ }, onCancel: function () {
200
+ _this.handleOnChange(null);
201
+ } })));
202
+ }
203
+ case FormControlType.TEXT:
204
+ case FormControlType.EMAIL:
205
+ default: {
206
+ var inputProps = {
207
+ type: type === FormControlType.EMAIL ? 'email' : 'text',
208
+ className: 'form-control',
209
+ id: id,
210
+ name: name,
211
+ placeholder: placeholder,
212
+ value: getSafeStringValue(value, { coerceValue: true }),
213
+ readOnly: readOnly,
214
+ required: required,
215
+ minLength: minLength,
216
+ maxLength: maxLength,
217
+ onFocus: this.handleOnFocus,
218
+ onBlur: this.handleOnBlur,
219
+ disabled: disabled,
220
+ autoComplete: this.getAutocompleteValue()
221
+ };
222
+ if (this.props.displayPattern) {
223
+ return (_jsx(InputWithDisplayFormat, __assign({ displayPattern: this.props.displayPattern }, inputProps, { onChange: this.handleOnChange })));
224
+ }
225
+ return (_jsx("input", __assign({}, inputProps, { "aria-describedby": describedBy, onChange: this.handleInputOnChange })));
226
+ }
227
+ }
228
+ };
229
+ FormControl.Type = FormControlType;
230
+ FormControl.Size = Size;
231
+ FormControl.MonthFormat = MonthFormat;
232
+ FormControl.DateMode = DateMode;
233
+ FormControl.defaultProps = {
234
+ autoComplete: true,
235
+ countryCode: null,
236
+ disabled: false,
237
+ displayPattern: null,
238
+ id: null,
239
+ label: '',
240
+ max: null,
241
+ maxDate: null,
242
+ maxLength: null,
243
+ min: null,
244
+ minDate: null,
245
+ minLength: null,
246
+ mode: FormControl.DateMode.DAY_MONTH_YEAR,
247
+ monthFormat: FormControl.MonthFormat.LONG,
248
+ onBlur: null,
249
+ onFocus: null,
250
+ onSearchChange: null,
251
+ options: [],
252
+ placeholder: null,
253
+ readOnly: false,
254
+ required: false,
255
+ searchPlaceholder: null,
256
+ searchValue: '',
257
+ selectedOption: null,
258
+ size: FormControl.Size.MEDIUM,
259
+ step: 1,
260
+ type: FormControl.Type.TEXT,
261
+ uploadProps: {},
262
+ value: null
263
+ };
264
+ return FormControl;
265
+ }(PureComponent));
266
+ export default FormControl;
@@ -0,0 +1 @@
1
+ export { default } from './FormControl';
@@ -0,0 +1,80 @@
1
+ export var getAutocompleteString = function (hints, _a) {
2
+ var _b = _a === void 0 ? {} : _a, _c = _b.prefix, prefix = _c === void 0 ? '' : _c, _d = _b.suffix, suffix = _d === void 0 ? '' : _d;
3
+ var autoCompleteString = hints
4
+ .map(function (hint) {
5
+ var builtHint = "".concat(prefix).concat(hint).concat(suffix);
6
+ return isAutocompleteToken(builtHint) ? autocompleteTokenMap[builtHint] : undefined;
7
+ })
8
+ .filter(function (str) { return str; })
9
+ .join(' ');
10
+ return autoCompleteString || 'off';
11
+ };
12
+ var isAutocompleteToken = function (str) {
13
+ return Object.keys(autocompleteTokenMap).some(function (hint) { return hint === str; });
14
+ };
15
+ var autocompleteTokenMap = {
16
+ on: 'on',
17
+ name: 'name',
18
+ 'name-prefix': 'honorific-prefix',
19
+ 'given-name': 'given-name',
20
+ 'additional-name': 'additional-name',
21
+ 'family-name': 'family-name',
22
+ 'name-suffix': 'honorific-suffix',
23
+ nickname: 'nickname',
24
+ email: 'email',
25
+ // Web doesn't have a specific mapping for new username, but this is semantically close enough
26
+ 'new-username': 'username',
27
+ username: 'username',
28
+ 'new-password': 'new-password',
29
+ password: 'current-password',
30
+ 'one-time-code': 'one-time-code',
31
+ 'job-title': 'organization-title',
32
+ 'organization-name': 'organization',
33
+ 'full-street-address': 'street-address',
34
+ 'street-address-line-1': 'address-line1',
35
+ 'street-address-line-2': 'address-line2',
36
+ 'street-address-line-3': 'address-line3',
37
+ 'address-level-1': 'address-level1',
38
+ 'address-level-2': 'address-level2',
39
+ 'address-level-3': 'address-level3',
40
+ 'address-level-4': 'address-level4',
41
+ 'country-code': 'country',
42
+ 'country-name': 'country-name',
43
+ 'postal-code': 'postal-code',
44
+ 'credit-card-name': 'cc-name',
45
+ 'credit-card-given-name': 'cc-given-name',
46
+ 'credit-card-middle-name': 'cc-additional-name',
47
+ 'credit-card-family-name': 'cc-family-name',
48
+ 'credit-card-number': 'cc-number',
49
+ 'credit-card-expiration': 'cc-exp',
50
+ 'credit-card-expiration-month': 'cc-exp-month',
51
+ 'credit-card-expiration-year': 'cc-exp-year',
52
+ 'credit-card-security-code': 'cc-csc',
53
+ 'credit-card-type': 'cc-type',
54
+ 'transaction-currency': 'transaction-currency',
55
+ 'transaction-amount': 'transaction-amount',
56
+ language: 'language',
57
+ birthdate: 'bday',
58
+ 'birthdate-day': 'bday-day',
59
+ 'birthdate-month': 'bday-month',
60
+ 'birthdate-year': 'bday-year',
61
+ gender: 'sex',
62
+ 'phone-number': 'tel',
63
+ 'phone-country-code': 'tel-country-code',
64
+ 'phone-national': 'tel-national',
65
+ 'phone-area-code': 'tel-area-code',
66
+ 'phone-local': 'tel-local',
67
+ 'phone-local-prefix': 'tel-local-prefix',
68
+ 'phone-local-suffix': 'tel-local-suffix',
69
+ 'phone-extension': 'tel-extension',
70
+ url: 'url',
71
+ photo: 'photo',
72
+ impp: 'impp',
73
+ shipping: 'shipping',
74
+ billing: 'billing',
75
+ home: 'home',
76
+ work: 'work',
77
+ mobile: 'mobile',
78
+ fax: 'fax',
79
+ pager: 'pager'
80
+ };
@@ -0,0 +1,2 @@
1
+ export * from './value-utils';
2
+ export { getAutocompleteString } from './getAutocompleteString';
@@ -0,0 +1,108 @@
1
+ /* eslint-disable no-console */
2
+ import { dateStringToDate } from '../../common/utils';
3
+ import { isBoolean, isNull, isNumber, isObject, isString } from '../../common/validators';
4
+ export var getSafeStringValue = function (value, options) {
5
+ if (options === void 0) { options = {}; }
6
+ var _a = options.coerceValue, coerceValue = _a === void 0 ? false : _a;
7
+ if (isNull(value)) {
8
+ return undefined;
9
+ }
10
+ if (isObject(value)) {
11
+ logInvalidTypeFallbackWarning({ received: 'object', expected: 'string' });
12
+ return undefined;
13
+ }
14
+ if (!isString(value)) {
15
+ if (coerceValue) {
16
+ // TODO: Remove this coercion once we're sure everyone has had a chance to address warnings
17
+ logInvalidTypeCoercedWarning({ received: typeof value, expected: 'string' });
18
+ return String(value);
19
+ }
20
+ else {
21
+ logInvalidTypeFallbackWarning({ received: typeof value, expected: 'string' });
22
+ return undefined;
23
+ }
24
+ }
25
+ return value;
26
+ };
27
+ export var getSafeStringOrNumberValue = function (value, options) {
28
+ if (options === void 0) { options = {}; }
29
+ var _a = options.coerceValue, coerceValue = _a === void 0 ? false : _a;
30
+ if (isNull(value)) {
31
+ return undefined;
32
+ }
33
+ if (isNumber(value)) {
34
+ return value;
35
+ }
36
+ var logProps = { received: typeof value, expected: 'string or number' };
37
+ if (isObject(value)) {
38
+ logInvalidTypeFallbackWarning(logProps);
39
+ return undefined;
40
+ }
41
+ if (!isString(value)) {
42
+ if (coerceValue) {
43
+ // TODO: Remove this coercion once we're sure everyone has had a chance to address warnings
44
+ logInvalidTypeCoercedWarning(logProps);
45
+ return String(value);
46
+ }
47
+ else {
48
+ logInvalidTypeFallbackWarning(logProps);
49
+ return undefined;
50
+ }
51
+ }
52
+ return value;
53
+ };
54
+ export var getSafeBooleanValue = function (value, options) {
55
+ if (options === void 0) { options = {}; }
56
+ var _a = options.coerceValue, coerceValue = _a === void 0 ? false : _a;
57
+ if (isNull(value)) {
58
+ return false;
59
+ }
60
+ if (!isBoolean(value)) {
61
+ if (coerceValue) {
62
+ // TODO: Remove this coercion once we're sure everyone has had a chance to address warnings
63
+ logInvalidTypeCoercedWarning({ received: typeof value, expected: 'boolean' });
64
+ return Boolean(value);
65
+ }
66
+ else {
67
+ logInvalidTypeFallbackWarning({ received: typeof value, expected: 'boolean' });
68
+ return undefined;
69
+ }
70
+ }
71
+ return value;
72
+ };
73
+ export var getSafeDateOrStringValue = function (value) {
74
+ if (isNull(value)) {
75
+ return undefined;
76
+ }
77
+ if (!(value instanceof Date) && !isString(value)) {
78
+ logInvalidTypeFallbackWarning({ received: typeof value, expected: 'string or Date' });
79
+ return undefined;
80
+ }
81
+ return value;
82
+ };
83
+ export var getSafeDateStringValue = function (value) {
84
+ if (isNull(value)) {
85
+ return null;
86
+ }
87
+ if (!isString(value)) {
88
+ logInvalidTypeFallbackWarning({
89
+ received: typeof value,
90
+ expected: 'string',
91
+ fallback: 'null'
92
+ });
93
+ return null;
94
+ }
95
+ var date = dateStringToDate(value);
96
+ if (date === null) {
97
+ console.warn('Incorrectly formatted date string. Falling back to null.');
98
+ }
99
+ return date;
100
+ };
101
+ var logInvalidTypeCoercedWarning = function (_a) {
102
+ var received = _a.received, expected = _a.expected;
103
+ console.warn("Value with type ".concat(received, " passed to control that only accepts type ").concat(expected, ". Type will be coerced, but this behaviour will change in the future, so please fix your code."));
104
+ };
105
+ var logInvalidTypeFallbackWarning = function (_a) {
106
+ var received = _a.received, expected = _a.expected, _b = _a.fallback, fallback = _b === void 0 ? 'undefined' : _b;
107
+ console.warn("Value with type ".concat(received, " passed to control that only accepts type ").concat(expected, ". Falling back to ").concat(fallback));
108
+ };
@@ -0,0 +1,50 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { Header } from '@transferwise/components';
14
+ import classNames from 'classnames';
15
+ import { useState } from 'react';
16
+ import { getValidObjectModelParts } from '../../common/validators';
17
+ import GenericSchema from '../genericSchema';
18
+ // If wew receive a model, break it down to parts valid for each schema
19
+ var splitModel = function (model, schemas) {
20
+ return schemas.map(function (schema) { return getValidObjectModelParts(model, schema) || {}; });
21
+ };
22
+ var combineModels = function (models) {
23
+ return models.reduce(function (current, combined) { return (__assign(__assign({}, combined), current)); }, {});
24
+ };
25
+ var getSchemaColumnClasses = function (width) { return ({
26
+ 'col-xs-12': true,
27
+ 'col-sm-6': width === 'md',
28
+ 'col-sm-4': width === 'sm'
29
+ }); };
30
+ function AllOfSchema(props) {
31
+ var onChangeModelIndex = function (index, onChangeProps) {
32
+ var modelSchema = props.schema.allOf[index];
33
+ // FIXME we should not mutate models here
34
+ models[index] = getValidObjectModelParts(onChangeProps.model, modelSchema) || {};
35
+ setModels(models);
36
+ props.onChange(__assign(__assign({}, onChangeProps), { model: combineModels(models) }));
37
+ };
38
+ var _a = useState(splitModel(props.model, props.schema.allOf)), models = _a[0], setModels = _a[1];
39
+ return (_jsxs(_Fragment, { children: [props.schema.title && _jsx(Header, { title: props.schema.title }), props.schema.description && _jsx("p", { children: props.schema.description }), _jsx("div", __assign({ className: "row" }, { children: props.schema.allOf.map(function (schema, index) { return (
40
+ // eslint-disable-next-line react/no-array-index-key
41
+ _jsx("div", __assign({ className: classNames(getSchemaColumnClasses(schema.width)) }, { children: _jsx(GenericSchema, { schema: schema, model: models[index], errors: props.errors, submitted: props.submitted, disabled: props.disabled, onChange: function (onChangeProps) {
42
+ return onChangeModelIndex(index, __assign(__assign({}, onChangeProps), {
43
+ // We can safely assume that the model here is going to be of the same type as the model prop
44
+ model: onChangeProps.model }));
45
+ }, onPersistAsync: props.onPersistAsync }) }), index)); }) }))] }));
46
+ }
47
+ AllOfSchema.defaultProps = {
48
+ disabled: false
49
+ };
50
+ export default AllOfSchema;
@@ -0,0 +1 @@
1
+ export { default } from './AllOfSchema';
@@ -0,0 +1,25 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { isListArraySchema } from '../../common/utils';
14
+ import ArrayListSchema from './arrayListSchema/ArrayListSchema';
15
+ var ArraySchema = function (props) {
16
+ var schema = props.schema;
17
+ if (isListArraySchema(schema)) {
18
+ return _jsx(ArrayListSchema, __assign({}, props));
19
+ }
20
+ throw new Error('Not implemented'); // Tuple not implemented
21
+ };
22
+ ArraySchema.defaultProps = {
23
+ required: false
24
+ };
25
+ export default ArraySchema;
@@ -0,0 +1,30 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { isListArraySchema, isMultipleFileUploadSchema } from '../../../common/utils';
14
+ import MultipleFileUploadSchema from './multipleFileUploadSchema';
15
+ import RepeatableSchema from './repeatableSchema/RepeatableSchema';
16
+ var ArrayListSchema = function (props) {
17
+ var schema = props.schema;
18
+ if (isMultipleFileUploadSchema(schema)) {
19
+ return _jsx(MultipleFileUploadSchema, __assign({}, props, { schema: schema }));
20
+ }
21
+ if (isListArraySchema(schema)) {
22
+ return _jsx(RepeatableSchema, __assign({}, props, { schema: schema }));
23
+ }
24
+ throw new Error('Invalid array list schema');
25
+ };
26
+ ArrayListSchema.defaultProps = {
27
+ errors: null,
28
+ required: false
29
+ };
30
+ export default ArrayListSchema;