@wise/dynamic-flow-client 3.3.2 → 3.4.0-experimental-ed080a1

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 +13 -28
  165. package/build/main.min.js +1 -1
  166. package/build/main.mjs +13 -28
  167. package/build/types/revamp/domain/features/events.d.ts +1 -1
  168. package/package.json +2 -2
@@ -0,0 +1,111 @@
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, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
+ import classNames from 'classnames';
14
+ import { useEffect, useMemo, useState } from 'react';
15
+ import { generateRandomId } from '../../common/utils';
16
+ import { getValidBasicModelOrNull, getValidationFailures, isNull, isUndefined, } from '../../common/validators';
17
+ import { DynamicAlert } from '../../layout';
18
+ import ControlFeedback from '../controlFeedback';
19
+ import Help from '../help';
20
+ import SchemaFormControl from '../schemaFormControl';
21
+ var isNullish = function (value) {
22
+ return isNull(value) || isUndefined(value);
23
+ };
24
+ var getDefaultValue = function (schema) {
25
+ return schema.type === 'boolean' && isNullish(schema["default"]) ? false : schema["default"];
26
+ };
27
+ var BasicTypeSchema = function (props) {
28
+ var _a, _b, _c;
29
+ var onChange = function (newModel, _type, metadata) {
30
+ setChanged(true);
31
+ setModelAndBroadcast(sanitiseModel(newModel), 'user', metadata);
32
+ };
33
+ var getValidationKeys = function (newModel) {
34
+ return getValidationFailures(newModel, props.schema, props.required);
35
+ }; // TODO: LOW avoid type assertion
36
+ var setModelAndBroadcast = function (newModel, type, metadata) {
37
+ setModel(newModel);
38
+ var validationKeys = getValidationKeys(newModel);
39
+ setValidations(validationKeys);
40
+ var broadcastModel = newModel;
41
+ setLastModel(broadcastModel);
42
+ if (broadcastModel !== lastModel) {
43
+ props.onChange({
44
+ model: broadcastModel,
45
+ triggerSchema: props.schema,
46
+ triggerModel: broadcastModel,
47
+ lastTriggerModel: lastModel,
48
+ type: type,
49
+ metadata: metadata
50
+ });
51
+ }
52
+ };
53
+ var sanitiseModel = function (newModel) {
54
+ return getValidBasicModelOrNull(newModel, props.schema);
55
+ };
56
+ var onFocus = function () { return setFocused(true); };
57
+ var onBlur = function () {
58
+ setFocused(false);
59
+ setBlurred(true);
60
+ if (props.onBlur) {
61
+ props.onBlur();
62
+ }
63
+ };
64
+ var _d = useState((_a = props.model) !== null && _a !== void 0 ? _a : null), model = _d[0], setModel = _d[1];
65
+ var _e = useState((_b = props.model) !== null && _b !== void 0 ? _b : null), lastModel = _e[0], setLastModel = _e[1];
66
+ var _f = useState(false), changed = _f[0], setChanged = _f[1];
67
+ var _g = useState(false), focused = _g[0], setFocused = _g[1];
68
+ var _h = useState(false), blurred = _h[0], setBlurred = _h[1];
69
+ var _j = useState([]), validations = _j[0], setValidations = _j[1];
70
+ var id = useMemo(function () { return props.schema.$id || generateRandomId(); }, [props.schema.$id]);
71
+ var onSchemaChange = function () {
72
+ var defaultValue = getDefaultValue(props.schema);
73
+ // if no model, change to the default, only run this when the schema changes
74
+ if (isNullish(model) && !isNullish(defaultValue)) {
75
+ setModelAndBroadcast(defaultValue, 'init');
76
+ }
77
+ if (props.schema["const"]) {
78
+ setModelAndBroadcast(props.schema["const"], 'init');
79
+ }
80
+ };
81
+ var refreshValidations = function () {
82
+ setValidations(getValidationKeys(model));
83
+ };
84
+ var isConst = props.schema["const"];
85
+ var isHidden = props.schema.hidden || isConst;
86
+ useEffect(refreshValidations, [props.model, props.submitted]);
87
+ useEffect(onSchemaChange, [props.schema]);
88
+ useEffect(function () {
89
+ var _a;
90
+ var newModel = (_a = props.model) !== null && _a !== void 0 ? _a : null;
91
+ if (newModel !== model) {
92
+ setModel(newModel);
93
+ }
94
+ }, [props.model]);
95
+ var formGroupClasses = {
96
+ 'form-group': true,
97
+ 'has-error': ((props.submitted || !changed) && !!props.errors) ||
98
+ ((props.submitted || (changed && blurred)) && !!validations.length),
99
+ 'has-info': !!props.schema.description || !!props.infoMessage
100
+ };
101
+ var showLabel = props.schema.format !== 'file' && props.schema.type !== 'boolean';
102
+ var schemaHelp = props.schema.help;
103
+ var feedbackId = "".concat(id, "-feedback");
104
+ return !isHidden ? (_jsxs(_Fragment, { children: [props.schema.alert && _jsx(DynamicAlert, { component: props.schema.alert }), _jsxs("div", __assign({ className: classNames(formGroupClasses) }, { children: [showLabel && (_jsxs("div", __assign({ className: "d-inline-block m-b-1" }, { children: [_jsx("label", __assign({ className: "control-label d-inline", htmlFor: id }, { children: props.schema.title })), !!schemaHelp && _jsx(Help, { help: schemaHelp })] }))), !showLabel && !!schemaHelp && _jsx(Help, { help: schemaHelp }), _jsx(SchemaFormControl, { id: id, schema: props.schema, value: model, disabled: !!props.disabled, onChange: onChange, onFocus: onFocus, onBlur: onBlur, describedBy: feedbackId }), _jsx(ControlFeedback, { id: feedbackId, changed: changed, focused: focused, blurred: blurred, submitted: props.submitted, errors: (_c = props.errors) !== null && _c !== void 0 ? _c : null, schema: props.schema, validations: validations, infoMessage: props.infoMessage })] }))] })) : null;
105
+ };
106
+ BasicTypeSchema.defaultProps = {
107
+ required: false,
108
+ disabled: false,
109
+ onBlur: null
110
+ };
111
+ export default BasicTypeSchema;
@@ -0,0 +1 @@
1
+ export { default } from './BasicTypeSchema';
@@ -0,0 +1,86 @@
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, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { InlineAlert } from '@transferwise/components';
14
+ import { formatDate } from '@transferwise/formatting';
15
+ import { useIntl } from 'react-intl';
16
+ import validationArrayMessages from '../../../common/messages/validation.array.messages';
17
+ import controlFeedbackMessages from '../../../common/messages/validation.messages';
18
+ function ControlFeedback(props) {
19
+ var _a;
20
+ var defaultValidationMessages = useDefaultValidationMessages(props.schema);
21
+ var validationMessages = __assign(__assign(__assign({}, defaultValidationMessages), props.validationMessages), props.schema.validationMessages);
22
+ var isErrorVisible = (props.submitted || !props.changed) && Boolean(props.errors);
23
+ var isValidationVisible = !isErrorVisible &&
24
+ (props.submitted || (props.changed && props.blurred)) &&
25
+ Boolean((_a = props.validations) === null || _a === void 0 ? void 0 : _a.length);
26
+ var isDescriptionVisible = props.schema.description && !isErrorVisible && !isValidationVisible;
27
+ var hasInfoMessage = Boolean(props.infoMessage);
28
+ return (_jsxs("div", __assign({ id: props.id }, { children: [isErrorVisible ? _jsx(InlineAlert, __assign({ type: "error" }, { children: props.errors })) : null, isValidationVisible ? (_jsx(InlineAlert, __assign({ type: "error" }, { children: props.validations.map(function (validation) { return (_jsx("div", { children: validationMessages[validation] }, validation)); }) }))) : null, (isDescriptionVisible || hasInfoMessage) && (_jsxs(InlineAlert, __assign({ type: "info" }, { children: [isDescriptionVisible && _jsx("div", { children: props.schema.description }), hasInfoMessage && _jsx("div", { children: props.infoMessage })] })))] })));
29
+ }
30
+ ControlFeedback.defaultProps = {
31
+ errors: '',
32
+ validations: [],
33
+ validationMessages: {},
34
+ validationAsyncSuccessMessage: null
35
+ };
36
+ // TODO: avoid typre assertions in this function
37
+ function useDefaultValidationMessages(schema) {
38
+ var _a = useIntl(), formatMessage = _a.formatMessage, locale = _a.locale;
39
+ var formattedMessages = {
40
+ type: formatMessage(controlFeedbackMessages.type),
41
+ minimum: formatMessage(controlFeedbackMessages.minimum, {
42
+ minimum: schema.minimum
43
+ }),
44
+ maximum: formatMessage(controlFeedbackMessages.maximum, {
45
+ maximum: schema.maximum
46
+ }),
47
+ minLength: formatMessage(controlFeedbackMessages.minLength, {
48
+ minLength: schema.minLength
49
+ }),
50
+ maxLength: formatMessage(controlFeedbackMessages.maxLength, {
51
+ maxLength: schema.maxLength
52
+ }),
53
+ minItems: formatMessage(validationArrayMessages.minItemsError, {
54
+ minItems: schema.minItems
55
+ }),
56
+ maxItems: formatMessage(validationArrayMessages.maxItemsError, {
57
+ maxItems: schema.maxItems
58
+ }),
59
+ pattern: formatMessage(controlFeedbackMessages.pattern),
60
+ required: formatMessage(controlFeedbackMessages.required)
61
+ };
62
+ if (schema.format === 'date') {
63
+ var dateOverrides = {
64
+ pattern: formatMessage(controlFeedbackMessages.patternDate),
65
+ minimum: schema.minimum
66
+ ? formatMessage(controlFeedbackMessages.minimumDate, {
67
+ minimum: formatDate(new Date(schema.minimum), locale, {
68
+ timeZone: 'UTC',
69
+ dateStyle: 'long'
70
+ })
71
+ })
72
+ : undefined,
73
+ maximum: schema.maximum
74
+ ? formatMessage(controlFeedbackMessages.maximumDate, {
75
+ maximum: formatDate(new Date(schema.maximum), locale, {
76
+ timeZone: 'UTC',
77
+ dateStyle: 'long'
78
+ })
79
+ })
80
+ : undefined
81
+ };
82
+ return __assign(__assign({}, formattedMessages), dateOverrides);
83
+ }
84
+ return formattedMessages;
85
+ }
86
+ export default ControlFeedback;
@@ -0,0 +1 @@
1
+ export { default } from './ControlFeedback';
@@ -0,0 +1,20 @@
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 { Markdown, Info } from '@transferwise/components';
14
+ import { useIntl } from 'react-intl';
15
+ import helpMessages from '../../../common/messages/help.messages';
16
+ function Help(props) {
17
+ var intl = useIntl();
18
+ return (_jsx(Info, { className: "m-l-1", content: _jsx(Markdown, __assign({ config: { link: { target: '_blank' } } }, { children: props.help.markdown })), presentation: "POPOVER", size: "sm", "aria-label": intl.formatMessage(helpMessages.helpAria) }));
19
+ }
20
+ export default Help;
@@ -0,0 +1 @@
1
+ export { default } from './Help';
@@ -0,0 +1,77 @@
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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
22
+ import { Header } from '@transferwise/components';
23
+ import classNames from 'classnames';
24
+ import { useState, useEffect } from 'react';
25
+ import { isEqual } from '../../common/utils';
26
+ import { getValidObjectModelParts } from '../../common/validators';
27
+ import { DynamicAlert } from '../../layout';
28
+ import GenericSchema from '../genericSchema';
29
+ var getSchemaColumnClasses = function (width) { return ({
30
+ 'col-xs-12': true,
31
+ 'col-sm-6': width === 'md',
32
+ 'col-sm-4': width === 'sm'
33
+ }); };
34
+ function ObjectSchema(props) {
35
+ var _a = useState(function () { return (__assign({}, getValidObjectModelParts(props.model, props.schema))); }), model = _a[0], setModel = _a[1];
36
+ var onChangeProperty = function (propertyName, onChangeProps) {
37
+ if (onChangeProps.model !== null) {
38
+ // FIXME we should not mutate the model here
39
+ model[propertyName] = onChangeProps.model;
40
+ }
41
+ else {
42
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
43
+ delete model[propertyName];
44
+ }
45
+ setModel(model);
46
+ props.onChange(__assign(__assign({}, onChangeProps), { model: model }));
47
+ };
48
+ var isRequired = function (propertyName) {
49
+ return props.schema.required && props.schema.required.includes(propertyName);
50
+ };
51
+ useEffect(function () {
52
+ // When the schema changes, only retain valid parts of the model
53
+ var newModel = getValidObjectModelParts(model, props.schema) || {};
54
+ setModel(newModel);
55
+ if (!isEqual(newModel, model)) {
56
+ props.onChange({
57
+ model: newModel,
58
+ triggerSchema: props.schema,
59
+ triggerModel: newModel
60
+ });
61
+ }
62
+ }, [props.schema]);
63
+ var allorderedPropertiesSet = new Set(__spreadArray(__spreadArray([], (props.schema.displayOrder || []), true), Object.keys(props.schema.properties), true));
64
+ var isPropertyDefined = function (propertyName) {
65
+ return typeof props.schema.properties[propertyName] !== 'undefined';
66
+ };
67
+ // eslint-disable-next-line unicorn/prefer-spread
68
+ var orderedPropertyNames = Array.from(allorderedPropertiesSet).filter(isPropertyDefined);
69
+ // TODO: LOW avoid type assertion -- what happens when props.errors is not an object?
70
+ var propsErrors = props.errors;
71
+ return (_jsxs(_Fragment, { children: [props.schema.alert && _jsx(DynamicAlert, { component: props.schema.alert }), _jsxs("fieldset", { children: [props.schema.title && !props.hideTitle && (_jsx(Header, { title: props.schema.title, as: "legend" })), props.schema.description && !props.hideTitle && _jsxs("p", { children: [" ", props.schema.description, " "] }), _jsx("div", __assign({ className: "row" }, { children: orderedPropertyNames.map(function (propertyName) { return (_jsx("div", __assign({ className: classNames(getSchemaColumnClasses(props.schema.properties[propertyName].width)) }, { children: _jsx(GenericSchema, { schema: props.schema.properties[propertyName], model: props.model && props.model[propertyName], errors: propsErrors === null || propsErrors === void 0 ? void 0 : propsErrors[propertyName], submitted: props.submitted, required: isRequired(propertyName), disabled: props.disabled, onChange: function (onChangeProps) { return onChangeProperty(propertyName, onChangeProps); }, onPersistAsync: props.onPersistAsync }) }), propertyName)); }) }))] })] }));
72
+ }
73
+ ObjectSchema.defaultProps = {
74
+ hideTitle: false,
75
+ disabled: false
76
+ };
77
+ export default ObjectSchema;
@@ -0,0 +1 @@
1
+ export { default } from './ObjectSchema';
@@ -0,0 +1,155 @@
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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
22
+ import { Header } from '@transferwise/components';
23
+ import classNames from 'classnames';
24
+ import { useEffect, useMemo, useState } from 'react';
25
+ import { useEventDispatcher } from '../../common/contexts';
26
+ import { useDebouncedFunction } from '../../common/hooks';
27
+ import { generateRandomId, isConstSchema, isNoNConstSchema } from '../../common/utils';
28
+ import { getValidModelParts, getValidationFailures, isArray, isEmpty, } from '../../common/validators';
29
+ import { DynamicAlert } from '../../layout';
30
+ import ControlFeedback from '../controlFeedback';
31
+ import GenericSchema from '../genericSchema';
32
+ import Help from '../help';
33
+ import SchemaFormControl from '../schemaFormControl';
34
+ import { getActiveSchemaIndex, getValidIndexFromValue } from './utils';
35
+ function OneOfSchema(props) {
36
+ var onEvent = useEventDispatcher();
37
+ var _a = useState(false), changed = _a[0], setChanged = _a[1];
38
+ var _b = useState(false), focused = _b[0], setFocused = _b[1];
39
+ var _c = useState(false), blurred = _c[0], setBlurred = _c[1];
40
+ var id = useMemo(function () { return props.schema.$id || generateRandomId(); }, [props.schema.$id]);
41
+ var _d = useState(getActiveSchemaIndex(props.schema, props.model)), schemaIndex = _d[0], setSchemaIndex = _d[1];
42
+ var _e = useState(getModelPartsForSchemas(props.model, props.schema.oneOf)), models = _e[0], setModels = _e[1];
43
+ var debouncedTrackEvent = useDebouncedFunction(onEvent, 200);
44
+ var onSearchChange = function (searchValue) {
45
+ debouncedTrackEvent('Dynamic Flow - OneOf Searched', {
46
+ oneOfId: props.schema.analyticsId,
47
+ searchValueLength: searchValue.length
48
+ });
49
+ };
50
+ // When the schema we receive from parent changes
51
+ useEffect(function () {
52
+ var modelIndex = getValidIndexFromValue(props.schema, props.model);
53
+ var defaultIndex = getValidIndexFromValue(props.schema, props.schema["default"]);
54
+ if (modelIndex === -1 && defaultIndex >= 0) {
55
+ onChooseNewSchema(defaultIndex, 'init');
56
+ }
57
+ }, [props.schema]);
58
+ if (!isArray(props.schema.oneOf)) {
59
+ // eslint-disable-next-line no-console
60
+ console.error('Incorrect format', props.schema);
61
+ return null;
62
+ }
63
+ var onChildModelChange = function (index, onChangeParameters) {
64
+ setModels(__spreadArray(__spreadArray(__spreadArray([], models.slice(0, index), true), [onChangeParameters.model], false), models.slice(index + 1), true));
65
+ setChanged(true);
66
+ props.onChange(onChangeParameters);
67
+ };
68
+ var onFocus = function () {
69
+ setFocused(true);
70
+ };
71
+ var onBlur = function () {
72
+ setFocused(false);
73
+ setBlurred(true);
74
+ };
75
+ // TODO: LOW avoid type assertion
76
+ var onChooseNewSchema = function (index, type, metadata) {
77
+ setSchemaIndex(index);
78
+ var newSchema = props.schema.oneOf[index];
79
+ if (isConstSchema(newSchema)) {
80
+ // If new schema is a const we want to share the parent schema, not the const
81
+ var model = newSchema["const"];
82
+ props.onChange({
83
+ model: model,
84
+ triggerSchema: props.schema,
85
+ triggerModel: model,
86
+ type: type,
87
+ metadata: metadata
88
+ });
89
+ }
90
+ else {
91
+ props.onChange({
92
+ model: models[index],
93
+ triggerSchema: newSchema,
94
+ triggerModel: models[index],
95
+ type: type,
96
+ metadata: metadata
97
+ });
98
+ }
99
+ if (type !== 'init' && props.schema.analyticsId) {
100
+ onEvent('Dynamic Flow - OneOf Selected', {
101
+ oneOfId: props.schema.analyticsId,
102
+ schemaId: newSchema === null || newSchema === void 0 ? void 0 : newSchema.analyticsId
103
+ });
104
+ }
105
+ };
106
+ var schemaForSelect = mapSchemasForSelect(props.schema);
107
+ var validations = getValidations(props, schemaIndex);
108
+ var formGroupClasses = {
109
+ 'form-group': true,
110
+ 'has-error': (!changed && props.errors && !isEmpty(props.errors)) ||
111
+ ((props.submitted || (changed && blurred)) && validations.length)
112
+ };
113
+ var feedbackId = "".concat(id, "-feedback");
114
+ return (_jsxs(_Fragment, { children: [(props.schema.oneOf.length > 1 || isConstSchema(props.schema.oneOf[0])) && (_jsxs(_Fragment, { children: [props.schema.alert && _jsx(DynamicAlert, { component: props.schema.alert }), _jsxs("div", __assign({ className: classNames(formGroupClasses) }, { children: [getTitleAndHelp(props.schema, id), _jsx(SchemaFormControl, { id: id, schema: schemaForSelect, value: schemaIndex, disabled: props.disabled, describedBy: feedbackId, onChange: onChooseNewSchema, onFocus: onFocus, onBlur: onBlur, onSearchChange: onSearchChange }), _jsx(ControlFeedback, { id: feedbackId, changed: changed, focused: focused, blurred: blurred, submitted: props.submitted, errors: errorsToString(props.errors), schema: props.schema, validations: validations, infoMessage: null })] }))] })), isNoNConstSchema(props.schema.oneOf[schemaIndex]) && (_jsx(GenericSchema, { schema: props.schema.oneOf[schemaIndex], model: models[schemaIndex], errors: props.errors, submitted: props.submitted, hideTitle: true, disabled: props.disabled, onChange: function (parameters) { return onChildModelChange(schemaIndex, parameters); }, onPersistAsync: props.onPersistAsync }))] }));
115
+ }
116
+ function getTitleAndHelp(schema, forId) {
117
+ var _a;
118
+ var helpElement = schema.help ? _jsx(Help, { help: schema.help }) : null;
119
+ var titleElement = isConstSchema(schema.oneOf[0]) ? (_jsx("div", __assign({ className: "m-b-1" }, { children: _jsxs("label", __assign({ className: "control-label d-inline", htmlFor: forId }, { children: [schema.title, " ", helpElement] })) }))) : (_jsx(_Fragment, { children: helpElement ? (_jsxs("h4", __assign({ className: "m-b-2" }, { children: [schema.title, " ", helpElement] }))) : (_jsx(Header, { title: (_a = schema.title) !== null && _a !== void 0 ? _a : '' })) }));
120
+ return schema.title ? titleElement : helpElement;
121
+ }
122
+ function getValidations(props, schemaIndex) {
123
+ var selectedSchema = props.schema.oneOf[schemaIndex !== null && schemaIndex !== void 0 ? schemaIndex : -1];
124
+ if (isConstSchema(selectedSchema)) {
125
+ return getValidationFailures(selectedSchema["const"], props.schema, Boolean(props.required));
126
+ }
127
+ if (schemaIndex === null || schemaIndex < 0) {
128
+ return getValidationFailures(null, props.schema, Boolean(props.required));
129
+ }
130
+ return [];
131
+ }
132
+ function errorsToString(errors) {
133
+ // When oneOf represents a select, errors should be of type string
134
+ if (typeof errors === 'string') {
135
+ return errors;
136
+ }
137
+ return null;
138
+ }
139
+ function getModelPartsForSchemas(model, schemas) {
140
+ return schemas.map(function (schema) { return getValidModelParts(model, schema); });
141
+ }
142
+ // We want our model to be the index, so alter the oneOf schemas to be a const
143
+ function mapSchemasForSelect(schema) {
144
+ return __assign(__assign({}, schema), { oneOf: schema.oneOf.map(mapOneOfToConst) });
145
+ }
146
+ function mapOneOfToConst(schema, index) {
147
+ var title = schema.title, description = schema.description, _a = schema.disabled, disabled = _a === void 0 ? false : _a, icon = schema.icon, image = schema.image, keywords = schema.keywords;
148
+ // TODO LOW avoid type assertion below -- consider adding { type: 'integer' }
149
+ return { title: title, description: description, disabled: disabled, icon: icon, image: image, "const": index, keywords: keywords };
150
+ }
151
+ OneOfSchema.defaultProps = {
152
+ required: false,
153
+ disabled: false
154
+ };
155
+ export default OneOfSchema;
@@ -0,0 +1 @@
1
+ export { default } from './OneOfSchema';
@@ -0,0 +1,68 @@
1
+ import { isObjectModel, isOneOfObjectSchema, isConstSchema, isNoNConstSchema, } from '../../common/utils';
2
+ import { isValidSchema, isUndefined } from '../../common/validators';
3
+ export var getActiveSchemaIndex = function (schema, model) {
4
+ var indexFromModel = getValidIndexFromValue(schema, model);
5
+ // If our model satisfies one of the schemas, use that schema.
6
+ if (indexFromModel >= 0) {
7
+ return indexFromModel;
8
+ }
9
+ // If we have a non-const oneOf and there's only one, active index must be the first one
10
+ if (schema.oneOf.length === 1 && isNoNConstSchema(schema.oneOf[0])) {
11
+ return 0;
12
+ }
13
+ if (isConstSchema(schema.oneOf[0])) {
14
+ var indexFromDefault = getValidIndexFromValue(schema, schema["default"]);
15
+ // If the default value satisfies one of the schemas, use that schema.
16
+ if (indexFromDefault >= 0) {
17
+ return indexFromDefault;
18
+ }
19
+ }
20
+ if (isOneOfObjectSchema(schema) && isObjectModel(model) && Object.keys(model).length >= 1) {
21
+ // Even if the model does not satisfy any of the schemas, it may be closer to one of them.
22
+ return getBestMatchingSchemaIndexForValue(schema, model);
23
+ }
24
+ if (isOneOfObjectSchema(schema) &&
25
+ !isUndefined(schema["default"]) &&
26
+ isObjectModel(schema["default"]) &&
27
+ Object.keys(schema["default"]).length >= 1) {
28
+ // Even if the default value does not satisfy any of the schemas, it may be closer to one of them.
29
+ return getBestMatchingSchemaIndexForValue(schema, schema["default"]);
30
+ }
31
+ // Otherwise do not default
32
+ return null;
33
+ };
34
+ export var getValidIndexFromValue = function (schema, value) {
35
+ var predicate = function (childSchema) {
36
+ return !isUndefined(value) && isValidSchema(value, childSchema);
37
+ };
38
+ if (schema.oneOf.filter(predicate).length === 1) {
39
+ return schema.oneOf.findIndex(predicate);
40
+ }
41
+ return -1;
42
+ };
43
+ export function getBestMatchingSchemaIndexForValue(schema, value) {
44
+ if (value === null || value === undefined) {
45
+ return null;
46
+ }
47
+ var schemaPoints = schema.oneOf.map(function (childSchema) {
48
+ return getSchemaProperties(childSchema).reduce(function (total, _a) {
49
+ var key = _a[0], propertySchema = _a[1];
50
+ if (isConstSchema(propertySchema) && propertySchema["const"] === value[key]) {
51
+ return total + 2;
52
+ }
53
+ if (isNoNConstSchema(propertySchema) && typeof value[key] !== 'undefined') {
54
+ return total + 1;
55
+ }
56
+ return total;
57
+ }, 0);
58
+ });
59
+ if (schemaPoints.every(function (p) { return p === schemaPoints[0]; })) {
60
+ return null;
61
+ }
62
+ return schemaPoints.indexOf(Math.max.apply(Math, schemaPoints));
63
+ }
64
+ function getSchemaProperties(childSchema) {
65
+ return childSchema.properties !== null && typeof childSchema.properties === 'object'
66
+ ? Object.entries(childSchema.properties)
67
+ : [];
68
+ }
@@ -0,0 +1,26 @@
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 PersistAsyncBasicSchema from './persistAsyncBasicSchema';
14
+ import PersistAsyncBlobSchema from './persistAsyncBlobSchema';
15
+ function PersistAsyncSchema(props) {
16
+ var schema = props.schema;
17
+ var persistAsyncSchemaType = schema.persistAsync.schema.type;
18
+ if (persistAsyncSchemaType === 'blob') {
19
+ return (_jsx(PersistAsyncBlobSchema, __assign({}, props)));
20
+ }
21
+ return _jsx(PersistAsyncBasicSchema, __assign({}, props));
22
+ }
23
+ PersistAsyncSchema.defaultProps = {
24
+ required: false
25
+ };
26
+ export default PersistAsyncSchema;
@@ -0,0 +1 @@
1
+ export { default } from './PersistAsyncSchema';