@wise/dynamic-flow-client 3.5.0-experimental-6654c72 → 3.5.0-experimental-b041af5

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 (130) hide show
  1. package/build/main.js +14 -18
  2. package/build/main.min.js +1 -1
  3. package/build/main.mjs +14 -18
  4. package/package.json +2 -2
  5. package/build/common/errorBoundary/ErrorBoundary.js +0 -44
  6. package/build/common/errorBoundary/ErrorBoundaryAlert.js +0 -12
  7. package/build/common/messages/external-confirmation.messages.js +0 -23
  8. package/build/i18n/index.js +0 -36
  9. package/build/legacy/dynamicFlow/BackButton.js +0 -22
  10. package/build/legacy/dynamicFlow/DynamicFlow.js +0 -346
  11. package/build/legacy/dynamicFlow/DynamicFlowStep.js +0 -37
  12. package/build/legacy/dynamicFlow/DynamicFlowTypes.js +0 -1
  13. package/build/legacy/dynamicFlow/index.js +0 -1
  14. package/build/legacy/dynamicFlow/utils/index.js +0 -5
  15. package/build/legacy/dynamicFlow/utils/responseParsers/response-parsers.js +0 -185
  16. package/build/legacy/dynamicFlow/utils/useDebouncedRefresh/useDebouncedRefresh.js +0 -26
  17. package/build/legacy/dynamicFlow/utils/useDynamicFlowState.js +0 -137
  18. package/build/legacy/dynamicFlow/utils/useLoader.js +0 -22
  19. package/build/legacy/jsonSchemaForm/JsonSchemaForm.js +0 -24
  20. package/build/legacy/jsonSchemaForm/arrayTypeSchema/ArraySchema.js +0 -25
  21. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.js +0 -34
  22. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchema.js +0 -134
  23. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchemaStep.js +0 -85
  24. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/utils/summary-utils.js +0 -135
  25. package/build/legacy/jsonSchemaForm/arrayTypeSchema/index.js +0 -1
  26. package/build/legacy/jsonSchemaForm/genericSchema/GenericSchema.js +0 -85
  27. package/build/legacy/jsonSchemaForm/genericSchema/index.js +0 -1
  28. package/build/legacy/jsonSchemaForm/index.js +0 -1
  29. package/build/legacy/jsonSchemaForm/objectSchema/ObjectSchema.js +0 -77
  30. package/build/legacy/jsonSchemaForm/objectSchema/index.js +0 -1
  31. package/build/legacy/jsonSchemaForm/oneOfSchema/OneOfSchema.js +0 -155
  32. package/build/legacy/jsonSchemaForm/oneOfSchema/index.js +0 -1
  33. package/build/legacy/jsonSchemaForm/oneOfSchema/utils.js +0 -68
  34. package/build/legacy/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.js +0 -26
  35. package/build/legacy/jsonSchemaForm/persistAsyncSchema/index.js +0 -1
  36. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/index.js +0 -1
  37. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/PersistAsyncBlobSchema.js +0 -131
  38. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/UploadInputAdapter.js +0 -31
  39. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/index.js +0 -1
  40. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.js +0 -72
  41. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/index.js +0 -1
  42. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promoted-one-of-utils.js +0 -8
  43. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfCheckboxControl.js +0 -27
  44. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfControl.js +0 -31
  45. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfRadioControl.js +0 -32
  46. package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.js +0 -54
  47. package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.messages.js +0 -13
  48. package/build/legacy/jsonSchemaForm/readOnlySchema/index.js +0 -1
  49. package/build/legacy/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.js +0 -150
  50. package/build/legacy/jsonSchemaForm/validationAsyncSchema/index.js +0 -1
  51. package/build/legacy/step/cameraStep/CameraStep.js +0 -124
  52. package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.js +0 -161
  53. package/build/legacy/step/cameraStep/cameraCapture/hooks/useFullScreenOrientationLock.js +0 -60
  54. package/build/legacy/step/cameraStep/cameraCapture/hooks/useVideoConstraints.js +0 -80
  55. package/build/legacy/step/cameraStep/cameraCapture/index.js +0 -1
  56. package/build/legacy/step/cameraStep/cameraCapture/overlay/Overlay.js +0 -77
  57. package/build/legacy/step/cameraStep/cameraCapture/screens/cameraErrorScreen/CameraErrorScreen.js +0 -18
  58. package/build/legacy/step/cameraStep/cameraCapture/screens/index.js +0 -1
  59. package/build/legacy/step/cameraStep/cameraCapture/tracking/index.js +0 -109
  60. package/build/legacy/step/cameraStep/cameraCapture/utils/index.js +0 -107
  61. package/build/legacy/step/cameraStep/index.js +0 -1
  62. package/build/legacy/step/externalConfirmationStep/ExternalConfirmationStep.js +0 -64
  63. package/build/legacy/step/externalConfirmationStep/index.js +0 -1
  64. package/build/legacy/step/index.js +0 -3
  65. package/build/revamp/domain/components/AlertComponent.js +0 -50
  66. package/build/revamp/domain/components/AllOfComponent.js +0 -72
  67. package/build/revamp/domain/components/BooleanInputComponent.js +0 -108
  68. package/build/revamp/domain/components/BoxComponent.js +0 -65
  69. package/build/revamp/domain/components/ButtonComponent.js +0 -50
  70. package/build/revamp/domain/components/ColumnsComponent.js +0 -74
  71. package/build/revamp/domain/components/ConstComponent.js +0 -50
  72. package/build/revamp/domain/components/ContainerComponent.js +0 -65
  73. package/build/revamp/domain/components/DateInputComponent.js +0 -127
  74. package/build/revamp/domain/components/DecisionComponent.js +0 -50
  75. package/build/revamp/domain/components/DividerComponent.js +0 -50
  76. package/build/revamp/domain/components/FormComponent.js +0 -65
  77. package/build/revamp/domain/components/HeadingComponent.js +0 -50
  78. package/build/revamp/domain/components/ImageComponent.js +0 -50
  79. package/build/revamp/domain/components/InstructionsComponent.js +0 -50
  80. package/build/revamp/domain/components/IntegerInputComponent.js +0 -125
  81. package/build/revamp/domain/components/LoadingIndicatorComponent.js +0 -50
  82. package/build/revamp/domain/components/MarkdownComponent.js +0 -50
  83. package/build/revamp/domain/components/ModalComponent.js +0 -65
  84. package/build/revamp/domain/components/MultiUploadInputComponent.js +0 -190
  85. package/build/revamp/domain/components/NumberInputComponent.js +0 -125
  86. package/build/revamp/domain/components/ObjectComponent.js +0 -104
  87. package/build/revamp/domain/components/ParagraphComponent.js +0 -50
  88. package/build/revamp/domain/components/ReviewComponent.js +0 -50
  89. package/build/revamp/domain/components/SelectInputComponent.js +0 -138
  90. package/build/revamp/domain/components/StatusListComponent.js +0 -50
  91. package/build/revamp/domain/components/StepDomainComponent.js +0 -93
  92. package/build/revamp/domain/components/TextInputComponent.js +0 -125
  93. package/build/revamp/domain/components/UploadInputComponent.js +0 -151
  94. package/build/revamp/domain/components/repeatableComponent/RepeatableComponent.js +0 -148
  95. package/build/revamp/domain/components/searchComponent/SearchComponent.js +0 -108
  96. package/build/revamp/domain/components/utils/component-utils.js +0 -18
  97. package/build/revamp/domain/components/utils/debounce.js +0 -38
  98. package/build/revamp/domain/components/utils/file-utils.js +0 -46
  99. package/build/revamp/domain/components/utils/getComponentForLocalValueKey.js +0 -31
  100. package/build/revamp/domain/components/utils/isPartialLocalValueMatch.js +0 -40
  101. package/build/revamp/domain/features/events.js +0 -1
  102. package/build/revamp/domain/features/persistAsync/getComponentPersistAsync.js +0 -133
  103. package/build/revamp/domain/features/persistAsync/getPerformPersistAsync.js +0 -103
  104. package/build/revamp/domain/features/refresh/getPerformRefresh.js +0 -53
  105. package/build/revamp/domain/features/summary/summary-utils.js +0 -39
  106. package/build/revamp/domain/features/utils/http-utils.js +0 -34
  107. package/build/revamp/domain/features/utils/response-utils.js +0 -9
  108. package/build/revamp/domain/features/validation/validation-functions.js +0 -12
  109. package/build/revamp/domain/features/validation/value-checks.js +0 -111
  110. package/build/revamp/domain/features/validationAsync/getComponentValidationAsync.js +0 -94
  111. package/build/revamp/domain/features/validationAsync/getPerformValidationAsync.js +0 -107
  112. package/build/revamp/domain/mappers/types.js +0 -1
  113. package/build/revamp/domain/types.js +0 -1
  114. package/build/revamp/flow/response-utils.js +0 -88
  115. package/build/revamp/renderers/CoreContainerRenderer.js +0 -8
  116. package/build/revamp/renderers/LoadingContext.js +0 -7
  117. package/build/revamp/renderers/types.js +0 -1
  118. package/build/revamp/types.js +0 -1
  119. package/build/revamp/utils/component-utils.js +0 -86
  120. package/build/revamp/utils/type-utils.js +0 -56
  121. package/build/revamp/utils/type-validators.js +0 -16
  122. package/build/revamp/wise/renderers/AlertRenderer.js +0 -11
  123. package/build/revamp/wise/renderers/BooleanInputRenderer.js +0 -34
  124. package/build/revamp/wise/renderers/BoxRenderer.js +0 -30
  125. package/build/revamp/wise/renderers/ButtonRenderer.js +0 -64
  126. package/build/revamp/wise/renderers/ColumnsRenderer.js +0 -25
  127. package/build/revamp/wise/renderers/components/FieldInput.js +0 -20
  128. package/build/revamp/wise/renderers/components/Help.js +0 -21
  129. package/build/revamp/wise/renderers/components/LabelContentWithHelp.js +0 -6
  130. package/build/revamp/wise/renderers/utils/layout-utils.js +0 -31
@@ -1,85 +0,0 @@
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 __rest = (this && this.__rest) || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
- t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
- t[p[i]] = s[p[i]];
20
- }
21
- return t;
22
- };
23
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
24
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
25
- if (ar || !(i in from)) {
26
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
27
- ar[i] = from[i];
28
- }
29
- }
30
- return to.concat(ar || Array.prototype.slice.call(from));
31
- };
32
- import { jsx as _jsx } from "react/jsx-runtime";
33
- import { useState } from 'react';
34
- import { useIntl } from 'react-intl';
35
- import { DynamicFlowStep } from '../../../../dynamicFlow/DynamicFlowStep';
36
- import messages from '../../../../../common/messages/repeatable.messages';
37
- function RepeatableSchemaStep(_a) {
38
- var type = _a.type, schema = _a.schema, model = _a.model, errors = _a.errors, submitted = _a.submitted, onModelChange = _a.onModelChange, onAction = _a.onAction;
39
- var formatMessage = useIntl().formatMessage;
40
- var _b = useState(undefined), filename = _b[0], setFilename = _b[1];
41
- var step = {
42
- layout: __spreadArray([
43
- {
44
- type: 'form',
45
- schema: schema.items
46
- },
47
- {
48
- type: 'button',
49
- control: 'primary',
50
- action: {
51
- url: type,
52
- title: formatMessage(type === 'add' ? messages.addItem : messages.editItem)
53
- }
54
- }
55
- ], (type === 'edit'
56
- ? [
57
- {
58
- type: 'button',
59
- context: 'negative',
60
- action: {
61
- url: 'remove',
62
- title: formatMessage(messages.removeItem)
63
- }
64
- },
65
- ]
66
- : []), true),
67
- title: '',
68
- actions: [],
69
- schemas: []
70
- };
71
- var onChange = function (props) {
72
- var metadata = props.metadata, model = props.model, modelChangeProps = __rest(props, ["metadata", "model"]);
73
- if (schema.items.format === 'base64url' &&
74
- typeof model === 'string' &&
75
- typeof (metadata === null || metadata === void 0 ? void 0 : metadata.filename) === 'string') {
76
- setFilename(metadata.filename);
77
- }
78
- onModelChange(__assign(__assign({}, modelChangeProps), { model: model }));
79
- };
80
- return (_jsx(DynamicFlowStep, { step: step, model: model, stepLayoutOptions: { displayStepTitle: false }, submitted: submitted, formErrors: errors, globalError: null, onAction: function (action) {
81
- onAction(action.url, filename);
82
- setFilename(undefined);
83
- }, onModelChange: onChange }));
84
- }
85
- export default RepeatableSchemaStep;
@@ -1,135 +0,0 @@
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 { getSchemaType, isConstSchema, isNullableStringModel, isObjectModel, isOneOfObjectSchema, } from '../../../../../common/utils';
13
- import { isString } from '../../../../../common/validators';
14
- import { getActiveSchemaIndex, getBestMatchingSchemaIndexForValue, } from '../../../../oneOfSchema/utils';
15
- export var getItemSummaryFromSchema = function (schema, model, defaults, summaryTextOverride) {
16
- if (defaults === void 0) { defaults = {}; }
17
- var _a = defaults.defaultTitle, defaultTitle = _a === void 0 ? '' : _a, _b = defaults.defaultDescription, defaultDescription = _b === void 0 ? '' : _b, defaultIcon = defaults.defaultIcon, defaultImage = defaults.defaultImage;
18
- var title = getSummaryPropFromSchema({
19
- schema: schema,
20
- model: model,
21
- providesProp: 'providesTitle',
22
- getValueFromSchema: function (schema, model) {
23
- return summaryTextOverride !== null && summaryTextOverride !== void 0 ? summaryTextOverride : getStringValueFromSchema(schema, model);
24
- }
25
- });
26
- var description = getSummaryPropFromSchema({
27
- schema: schema,
28
- model: model,
29
- providesProp: 'providesDescription',
30
- getValueFromSchema: function (schema, model) {
31
- return summaryTextOverride !== null && summaryTextOverride !== void 0 ? summaryTextOverride : getStringValueFromSchema(schema, model);
32
- }
33
- });
34
- var icon = getSummaryPropFromSchema({
35
- schema: schema,
36
- model: model,
37
- providesProp: 'providesIcon',
38
- getValueFromSchema: function (schema) { var _a; return (_a = schema.icon) !== null && _a !== void 0 ? _a : null; }
39
- });
40
- var image = getSummaryPropFromSchema({
41
- schema: schema,
42
- model: model,
43
- providesProp: 'providesImage',
44
- getValueFromSchema: function (schema) { var _a; return (_a = schema.image) !== null && _a !== void 0 ? _a : null; }
45
- });
46
- return {
47
- value: model,
48
- title: title || defaultTitle,
49
- description: description || defaultDescription,
50
- icon: icon || defaultIcon,
51
- image: image || defaultImage
52
- };
53
- };
54
- var getSummaryPropFromSchema = function (props) {
55
- var schema = props.schema, model = props.model, providesProp = props.providesProp, getValueFromSchema = props.getValueFromSchema;
56
- var type = getSchemaType(schema);
57
- if (schemaSummaryProvides(schema.summary, providesProp)) {
58
- return getValueFromSchema(schema, model);
59
- }
60
- switch (type) {
61
- case 'object': {
62
- return getObjectValueFromSchema(props);
63
- }
64
- case 'oneOf': {
65
- return getOneOfValueFromSchema(props);
66
- }
67
- case 'allOf': {
68
- return getAllOfValueFromSchema(props);
69
- }
70
- default:
71
- return null;
72
- }
73
- };
74
- var getObjectValueFromSchema = function (props) {
75
- var schema = props.schema, model = props.model;
76
- var objectSchema = schema;
77
- // eslint-disable-next-line guard-for-in, no-restricted-syntax
78
- for (var propertyKey in objectSchema.properties) {
79
- var propertySchema = objectSchema.properties[propertyKey];
80
- var propertyModel = isObjectModel(model) && propertyKey in model ? model[propertyKey] : null;
81
- var result = getSummaryPropFromSchema(__assign(__assign({}, props), { schema: propertySchema, model: propertyModel }));
82
- if (result) {
83
- return result;
84
- }
85
- }
86
- return null;
87
- };
88
- var getOneOfValueFromSchema = function (props) {
89
- var schema = props.schema, model = props.model;
90
- if (isOneOfObjectSchema(schema)) {
91
- if (!isObjectModel(model)) {
92
- return null;
93
- }
94
- var activeSchemaIndex_1 = getBestMatchingSchemaIndexForValue(schema, model);
95
- if (activeSchemaIndex_1 === null || activeSchemaIndex_1 < 0) {
96
- return null;
97
- }
98
- var activeSchema = schema.oneOf[activeSchemaIndex_1];
99
- return getSummaryPropFromSchema(__assign(__assign({}, props), { schema: activeSchema }));
100
- }
101
- var oneOfSchema = schema;
102
- var activeSchemaIndex = getActiveSchemaIndex(oneOfSchema, model);
103
- if (activeSchemaIndex === null || activeSchemaIndex < 0) {
104
- return null;
105
- }
106
- return getSummaryPropFromSchema(__assign(__assign({}, props), { schema: oneOfSchema.oneOf[activeSchemaIndex] }));
107
- };
108
- var getAllOfValueFromSchema = function (props) {
109
- var schema = props.schema;
110
- var allOfSchema = schema;
111
- for (var _i = 0, _a = allOfSchema.allOf; _i < _a.length; _i++) {
112
- var childSchema = _a[_i];
113
- var result = getSummaryPropFromSchema(__assign(__assign({}, props), { schema: childSchema }));
114
- if (result) {
115
- return result;
116
- }
117
- }
118
- return null;
119
- };
120
- var getStringValueFromSchema = function (schema, model) {
121
- if (isConstSchema(schema)) {
122
- if (schema.title) {
123
- return schema.title;
124
- }
125
- if (isString(schema["const"])) {
126
- return schema["const"];
127
- }
128
- return null;
129
- }
130
- return isNullableStringModel(model) ? model : null;
131
- };
132
- var schemaSummaryProvides = function (summary, providesProp) {
133
- // eslint-disable-next-line prefer-object-has-own, no-implicit-coercion
134
- return !!summary && Object.hasOwnProperty.call(summary, providesProp) && Boolean(summary[providesProp]);
135
- };
@@ -1 +0,0 @@
1
- export { default } from './ArraySchema';
@@ -1,85 +0,0 @@
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 { createElement as _createElement } from "react";
13
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
14
- import { useEffect } from 'react';
15
- import { getSchemaType, isBasicError, isNullableBasicModel, isNullableObjectModel, isNullableArrayModel, isNullableStringModel, isObjectModel, isAllOfSchema, isOneOfSchema, isObjectSchema, isArraySchema, isPersistAsyncSchema, isValidationAsyncSchema, isBasicSchema, isOneOfObjectSchema, } from '../../common/utils';
16
- import AllOfSchema from '../allOfSchema';
17
- import ArraySchema from '../arrayTypeSchema';
18
- import BasicTypeSchema from '../basicTypeSchema';
19
- import ObjectSchema from '../objectSchema';
20
- import OneOfSchema from '../oneOfSchema';
21
- import PersistAsyncSchema from '../persistAsyncSchema';
22
- import PromotedOneOfSchema from '../promotedOneOfSchema';
23
- import ReadOnlySchema from '../readOnlySchema';
24
- import ValidationAsyncSchema from '../validationAsyncSchema';
25
- import { useLogger } from '../../common/contexts';
26
- function GenericSchemaForm(props) {
27
- var schema = props.schema, _a = props.model, model = _a === void 0 ? null : _a, _b = props.errors, errors = _b === void 0 ? null : _b, _c = props.hideTitle, hideTitle = _c === void 0 ? false : _c, _d = props.disabled, disabled = _d === void 0 ? false : _d;
28
- var schemaProps = __assign(__assign({}, props), { model: model, errors: errors, hideTitle: hideTitle, disabled: disabled });
29
- var type = getSchemaType(schema);
30
- var log = useLogger();
31
- useEffect(function () {
32
- if (!isValidGenericSchema(schema, model, errors)) {
33
- log.error('Invalid schema or model', "Schema of type ".concat(type || 'undefined', " requested, but schema did not pass validation."));
34
- }
35
- }, [JSON.stringify(schema), JSON.stringify(model), JSON.stringify(errors), type, log]);
36
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
37
- switch (type) {
38
- case 'readOnly':
39
- return _jsx(ReadOnlySchema, __assign({}, schemaProps));
40
- case 'persistAsync':
41
- return _jsx(PersistAsyncSchema, __assign({}, schemaProps));
42
- case 'validationAsync':
43
- return _jsx(ValidationAsyncSchema, __assign({}, schemaProps));
44
- case 'basic': {
45
- var basicTypeProps = __assign({ infoMessage: null }, schemaProps);
46
- return _jsx(BasicTypeSchema, __assign({}, basicTypeProps));
47
- }
48
- case 'object':
49
- return _createElement(ObjectSchema, __assign({}, schemaProps, { key: JSON.stringify(schema) }));
50
- case 'array':
51
- return _jsx(ArraySchema, __assign({}, schemaProps));
52
- case 'promotedOneOf':
53
- return _jsx(PromotedOneOfSchema, __assign({}, schemaProps));
54
- case 'oneOf':
55
- return _jsx(OneOfSchema, __assign({}, schemaProps));
56
- case 'allOf':
57
- return _jsx(AllOfSchema, __assign({}, schemaProps));
58
- }
59
- return _jsx(_Fragment, {});
60
- }
61
- export default GenericSchemaForm;
62
- // TODO: MC-3224 - We want to implement proper schema validation
63
- var isValidGenericSchema = function (schema, model, errors) {
64
- var type = getSchemaType(schema);
65
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
66
- switch (type) {
67
- case 'persistAsync':
68
- return isPersistAsyncSchema(schema) && isNullableStringModel(model) && isBasicError(errors);
69
- case 'validationAsync':
70
- return isValidationAsyncSchema(schema) && isNullableBasicModel(model) && isBasicError(errors);
71
- case 'basic':
72
- return isBasicSchema(schema) && isNullableBasicModel(model) && isBasicError(errors);
73
- case 'object':
74
- return isObjectSchema(schema) && isNullableObjectModel(model);
75
- case 'array':
76
- return isArraySchema(schema) && isNullableArrayModel(model) && isBasicError(errors);
77
- case 'promotedOneOf':
78
- return isOneOfObjectSchema(schema) && isNullableObjectModel(model);
79
- case 'oneOf':
80
- return isOneOfSchema(schema);
81
- case 'allOf':
82
- return isAllOfSchema(schema) && isObjectModel(model);
83
- }
84
- return false;
85
- };
@@ -1 +0,0 @@
1
- export { default } from './GenericSchema';
@@ -1 +0,0 @@
1
- export { default } from './JsonSchemaForm';
@@ -1,77 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export { default } from './ObjectSchema';
@@ -1,155 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export { default } from './OneOfSchema';
@@ -1,68 +0,0 @@
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
- }
@@ -1,26 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export { default } from './PersistAsyncSchema';
@@ -1 +0,0 @@
1
- export { default } from './PersistAsyncBasicSchema';