@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.
- package/build/common/httpClientContext/HttpClientContext.js +35 -0
- package/build/common/httpClientContext/index.js +1 -0
- package/build/common/makeHttpClient/index.js +1 -0
- package/build/common/makeHttpClient/makeHttpClient.js +34 -0
- package/build/common/messages/generic-error.messages.js +18 -0
- package/build/common/messages/help.messages.js +8 -0
- package/build/common/messages/multi-file-upload.messages.js +18 -0
- package/build/common/messages/paragraph.messages.js +13 -0
- package/build/common/messages/repeatable.messages.js +23 -0
- package/build/common/messages/validation.array.messages.js +13 -0
- package/build/common/messages/validation.messages.js +53 -0
- package/build/common/utils/api-utils.js +4 -0
- package/build/legacy/common/constants/DateMode.js +4 -0
- package/build/legacy/common/constants/FeatureName.js +4 -0
- package/build/legacy/common/constants/FormControlType.js +21 -0
- package/build/legacy/common/constants/MonthFormat.js +4 -0
- package/build/legacy/common/constants/Size.js +7 -0
- package/build/legacy/common/constants/index.js +4 -0
- package/build/legacy/common/contexts/dynamicFlowContexts/DynamicFlowContexts.js +36 -0
- package/build/legacy/common/contexts/dynamicFlowContexts/usePendingPromiseCounter.js +13 -0
- package/build/legacy/common/contexts/eventsContext/EventsContext.js +38 -0
- package/build/legacy/common/contexts/featureContext/FeatureContext.js +22 -0
- package/build/legacy/common/contexts/index.js +3 -0
- package/build/legacy/common/contexts/logContext/LogContext.js +44 -0
- package/build/legacy/common/hooks/index.js +7 -0
- package/build/legacy/common/hooks/useDebouncedFunction/useDebouncedFunction.js +9 -0
- package/build/legacy/common/hooks/useExternal/useExternal.js +15 -0
- package/build/legacy/common/hooks/useExternalStepPolling/useExternalStepPolling.js +70 -0
- package/build/legacy/common/hooks/usePersistAsync/usePersistAsync.js +172 -0
- package/build/legacy/common/hooks/usePolling/usePolling.js +51 -0
- package/build/legacy/common/hooks/usePrevious/usePrevious.js +8 -0
- package/build/legacy/common/hooks/useStepPolling/useStepPolling.js +43 -0
- package/build/legacy/common/messages.js +8 -0
- package/build/legacy/common/utils/api-utils.js +6 -0
- package/build/legacy/common/utils/date-utils.js +22 -0
- package/build/legacy/common/utils/debounce.js +38 -0
- package/build/legacy/common/utils/file-utils.js +45 -0
- package/build/legacy/common/utils/id-utils.js +5 -0
- package/build/legacy/common/utils/index.js +11 -0
- package/build/legacy/common/utils/is-equal.js +21 -0
- package/build/legacy/common/utils/misc-utils.js +4 -0
- package/build/legacy/common/utils/mobile-utils.js +23 -0
- package/build/legacy/common/utils/model-utils.js +33 -0
- package/build/legacy/common/utils/schema-utils.js +97 -0
- package/build/legacy/common/utils/step-utils.js +32 -0
- package/build/legacy/common/validators/index.js +5 -0
- package/build/legacy/common/validators/models/model-utils.js +119 -0
- package/build/legacy/common/validators/models/model-validators.js +62 -0
- package/build/legacy/common/validators/schemas/schema-validators.js +101 -0
- package/build/legacy/common/validators/types/type-validators.js +14 -0
- package/build/legacy/common/validators/validationFailures/validation-failures.js +139 -0
- package/build/legacy/common/validators/validationFailures/validation-failures.utils.js +40 -0
- package/build/legacy/common/validators/values/value-validators.js +6 -0
- package/build/legacy/dynamic-flow-types.js +1 -0
- package/build/legacy/dynamicFlow/BackButton.js +22 -0
- package/build/legacy/dynamicFlow/DynamicFlowStep.js +37 -0
- package/build/legacy/formControl/FormControl.js +266 -0
- package/build/legacy/formControl/index.js +1 -0
- package/build/legacy/formControl/utils/getAutocompleteString.js +80 -0
- package/build/legacy/formControl/utils/index.js +2 -0
- package/build/legacy/formControl/utils/value-utils.js +108 -0
- package/build/legacy/jsonSchemaForm/allOfSchema/AllOfSchema.js +50 -0
- package/build/legacy/jsonSchemaForm/allOfSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/ArraySchema.js +25 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.js +30 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.js +141 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/index.js +2 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/upload-utils.js +79 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/useFormattedDefaultErrorMessages.js +14 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/ItemSummary.js +7 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchema.js +134 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchemaStep.js +85 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/utils/summary-utils.js +135 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.js +111 -0
- package/build/legacy/jsonSchemaForm/basicTypeSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/controlFeedback/ControlFeedback.js +86 -0
- package/build/legacy/jsonSchemaForm/controlFeedback/index.js +1 -0
- package/build/legacy/jsonSchemaForm/help/Help.js +20 -0
- package/build/legacy/jsonSchemaForm/help/index.js +1 -0
- package/build/legacy/jsonSchemaForm/objectSchema/ObjectSchema.js +77 -0
- package/build/legacy/jsonSchemaForm/objectSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/oneOfSchema/OneOfSchema.js +155 -0
- package/build/legacy/jsonSchemaForm/oneOfSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/oneOfSchema/utils.js +68 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.js +26 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema.js +165 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/PersistAsyncBlobSchema.js +131 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/UploadInputAdapter.js +31 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.js +72 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promoted-one-of-utils.js +8 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfCheckboxControl.js +27 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfControl.js +31 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfRadioControl.js +32 -0
- package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.js +54 -0
- package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.messages.js +13 -0
- package/build/legacy/jsonSchemaForm/readOnlySchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/schemaFormControl/SchemaFormControl.js +133 -0
- package/build/legacy/jsonSchemaForm/schemaFormControl/index.js +1 -0
- package/build/legacy/jsonSchemaForm/schemaFormControl/utils/index.js +1 -0
- package/build/legacy/jsonSchemaForm/schemaFormControl/utils/mapping-utils.js +107 -0
- package/build/legacy/layout/DynamicLayout.js +68 -0
- package/build/legacy/layout/alert/DynamicAlert.js +29 -0
- package/build/legacy/layout/box/DynamicBox.js +41 -0
- package/build/legacy/layout/button/DynamicButton.js +27 -0
- package/build/legacy/layout/button/utils.js +45 -0
- package/build/legacy/layout/columns/DynamicColumns.js +38 -0
- package/build/legacy/layout/decision/DynamicDecision.js +21 -0
- package/build/legacy/layout/divider/DynamicDivider.js +9 -0
- package/build/legacy/layout/external/DynamicExternal.js +32 -0
- package/build/legacy/layout/external/DynamicExternal.messages.js +8 -0
- package/build/legacy/layout/form/DynamicForm.js +22 -0
- package/build/legacy/layout/heading/DynamicHeading.js +51 -0
- package/build/legacy/layout/icon/DynamicIcon.js +17 -0
- package/build/legacy/layout/icon/FlagIcon.js +198 -0
- package/build/legacy/layout/icon/NamedIcon.js +19 -0
- package/build/legacy/layout/image/DynamicImage.js +111 -0
- package/build/legacy/layout/index.js +20 -0
- package/build/legacy/layout/instructions/DynamicInstructions.js +30 -0
- package/build/legacy/layout/list/DynamicStatusList.js +37 -0
- package/build/legacy/layout/loadingIndicator/DynamicLoadingIndicator.js +11 -0
- package/build/legacy/layout/markdown/DynamicMarkdown.js +23 -0
- package/build/legacy/layout/modal/DynamicModal.js +26 -0
- package/build/legacy/layout/paragraph/DynamicParagraph.js +46 -0
- package/build/legacy/layout/paragraph/useSnackBarIfAvailable.js +9 -0
- package/build/legacy/layout/review/DynamicReview.js +58 -0
- package/build/legacy/layout/search/DynamicSearch.js +58 -0
- package/build/legacy/layout/search/SearchInput.js +17 -0
- package/build/legacy/layout/search/SearchResults.js +31 -0
- package/build/legacy/layout/search/useSearch.js +137 -0
- package/build/legacy/layout/utils/getNavigationOptionMedia.js +28 -0
- package/build/legacy/layout/utils/index.js +32 -0
- package/build/legacy/step/cameraStep/CameraStep.js +124 -0
- package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.js +161 -0
- package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.messages.js +58 -0
- package/build/legacy/step/cameraStep/cameraCapture/components/bottomBar/BottomBar.js +28 -0
- package/build/legacy/step/cameraStep/cameraCapture/components/index.js +3 -0
- package/build/legacy/step/cameraStep/cameraCapture/components/orientationLockOverlay/OrientationLockOverlay.js +19 -0
- package/build/legacy/step/cameraStep/cameraCapture/components/orientationLockOverlay/OrientationLockOverlay.messages.js +8 -0
- package/build/legacy/step/cameraStep/cameraCapture/hooks/useFullScreenOrientationLock.js +60 -0
- package/build/legacy/step/cameraStep/cameraCapture/hooks/useVideoConstraints.js +80 -0
- package/build/legacy/step/cameraStep/cameraCapture/index.js +1 -0
- package/build/legacy/step/cameraStep/cameraCapture/overlay/Overlay.js +77 -0
- package/build/legacy/step/cameraStep/cameraCapture/screens/cameraErrorScreen/CameraErrorScreen.js +18 -0
- package/build/legacy/step/cameraStep/cameraCapture/screens/index.js +1 -0
- package/build/legacy/step/cameraStep/cameraCapture/tracking/index.js +109 -0
- package/build/legacy/step/cameraStep/cameraCapture/types/index.js +7 -0
- package/build/legacy/step/cameraStep/cameraCapture/utils/index.js +107 -0
- package/build/legacy/step/cameraStep/index.js +1 -0
- package/build/legacy/step/externalConfirmationStep/ExternalConfirmationStep.js +64 -0
- package/build/legacy/step/externalConfirmationStep/ExternalConfirmationStep.messages.js +23 -0
- package/build/legacy/step/externalConfirmationStep/index.js +1 -0
- package/build/legacy/step/index.js +3 -0
- package/build/legacy/step/layoutStep/LayoutStep.js +33 -0
- package/build/legacy/step/layoutStep/index.js +1 -0
- package/build/legacy/step/layoutStep/utils/index.js +2 -0
- package/build/legacy/step/layoutStep/utils/inline-reference-utils.js +105 -0
- package/build/legacy/step/layoutStep/utils/layout-utils.js +212 -0
- package/build/main.js +13 -28
- package/build/main.min.js +1 -1
- package/build/main.mjs +13 -28
- package/build/types/revamp/domain/features/events.d.ts +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useDynamicFlow, useEventDispatcher } from '../../common/contexts';
|
|
3
|
+
import { useStepPolling } from '../../common/hooks';
|
|
4
|
+
import { isEmpty } from '../../common/validators';
|
|
5
|
+
import { DynamicLayout } from '../../layout';
|
|
6
|
+
import { convertStepToLayout, inlineReferences } from './utils';
|
|
7
|
+
var getComponents = function (step, options) {
|
|
8
|
+
var _a;
|
|
9
|
+
if (isEmpty(step)) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
var layout = convertStepToLayout(step, options);
|
|
13
|
+
return inlineReferences({
|
|
14
|
+
layout: layout,
|
|
15
|
+
schemas: step.schemas || [],
|
|
16
|
+
actions: step.actions || [],
|
|
17
|
+
model: (_a = step.model) !== null && _a !== void 0 ? _a : null
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var LayoutStep = function (props) {
|
|
21
|
+
var stepSpecification = props.stepSpecification, stepLayoutOptions = props.stepLayoutOptions, submitted = props.submitted, model = props.model, formErrors = props.formErrors, onModelChange = props.onModelChange;
|
|
22
|
+
var components = getComponents(stepSpecification, stepLayoutOptions);
|
|
23
|
+
var _a = useDynamicFlow(), loading = _a.loading, registerPersistAsyncPromise = _a.registerPersistAsyncPromise;
|
|
24
|
+
var onEvent = useEventDispatcher();
|
|
25
|
+
var onAction = !loading
|
|
26
|
+
? props.onAction
|
|
27
|
+
: function () {
|
|
28
|
+
onEvent('Dynamic Flow - onAction supressed', { reason: 'LayoutStep - loading state' });
|
|
29
|
+
};
|
|
30
|
+
useStepPolling(stepSpecification.polling, onAction);
|
|
31
|
+
return (_jsx(DynamicLayout, { components: components, submitted: submitted, model: model, errors: formErrors, onAction: onAction, onModelChange: onModelChange, onPersistAsync: registerPersistAsyncPromise }));
|
|
32
|
+
};
|
|
33
|
+
export default LayoutStep;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './LayoutStep';
|
|
@@ -0,0 +1,105 @@
|
|
|
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 { convertStepActionToDynamicAction } from './layout-utils';
|
|
13
|
+
export function inlineReferences(_a) {
|
|
14
|
+
var layout = _a.layout, schemas = _a.schemas, actions = _a.actions, model = _a.model;
|
|
15
|
+
if (!layout) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
if (!schemas) {
|
|
19
|
+
return layout;
|
|
20
|
+
}
|
|
21
|
+
return layout.map(function (component) {
|
|
22
|
+
if (component.type === 'form') {
|
|
23
|
+
return inlineFormSchema({ formComponent: component, schemas: schemas });
|
|
24
|
+
}
|
|
25
|
+
if (component.type === 'decision') {
|
|
26
|
+
return inlineDecisionActions({ decisionComponent: component, actions: actions });
|
|
27
|
+
}
|
|
28
|
+
if (component.type === 'button') {
|
|
29
|
+
return inlineAction({ actionComponent: component, actions: actions });
|
|
30
|
+
}
|
|
31
|
+
if (component.type === 'box') {
|
|
32
|
+
return __assign(__assign({}, component), { components: inlineReferences({ layout: component.components, schemas: schemas, actions: actions, model: model }) });
|
|
33
|
+
}
|
|
34
|
+
if (component.type === 'modal') {
|
|
35
|
+
return __assign(__assign({}, component), { components: inlineReferences({
|
|
36
|
+
layout: component.content.components,
|
|
37
|
+
schemas: schemas,
|
|
38
|
+
actions: actions,
|
|
39
|
+
model: model
|
|
40
|
+
}) });
|
|
41
|
+
}
|
|
42
|
+
if (component.type === 'columns') {
|
|
43
|
+
return __assign(__assign({}, component), { left: inlineReferences({ layout: component.left, schemas: schemas, actions: actions, model: model }), right: inlineReferences({ layout: component.right, schemas: schemas, actions: actions, model: model }) });
|
|
44
|
+
}
|
|
45
|
+
return component;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function inlineFormSchema(_a) {
|
|
49
|
+
var formComponent = _a.formComponent, schemas = _a.schemas;
|
|
50
|
+
if (formComponent.schemaId) {
|
|
51
|
+
return {
|
|
52
|
+
type: 'form',
|
|
53
|
+
margin: formComponent.margin,
|
|
54
|
+
schema: getSchemaById(schemas, formComponent.schemaId)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (formComponent.schema && isReference(formComponent.schema) && formComponent.schema.$ref) {
|
|
58
|
+
return {
|
|
59
|
+
type: 'form',
|
|
60
|
+
margin: formComponent.margin,
|
|
61
|
+
schema: getSchemaById(schemas, formComponent.schema.$ref)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (formComponent.schema && !isReference(formComponent.schema)) {
|
|
65
|
+
return __assign({}, formComponent);
|
|
66
|
+
}
|
|
67
|
+
throw new Error('Invalid form layout component. Missing "schema" or "schemaId" properties.');
|
|
68
|
+
}
|
|
69
|
+
function inlineDecisionActions(_a) {
|
|
70
|
+
var _b;
|
|
71
|
+
var decisionComponent = _a.decisionComponent, actions = _a.actions;
|
|
72
|
+
var newOptions = (_b = decisionComponent === null || decisionComponent === void 0 ? void 0 : decisionComponent.options) === null || _b === void 0 ? void 0 : _b.map(function (option) {
|
|
73
|
+
return option.action && isReference(option.action)
|
|
74
|
+
? __assign(__assign({}, option), { action: getActionById(actions, option.action.$ref) }) : option;
|
|
75
|
+
});
|
|
76
|
+
return __assign(__assign({}, decisionComponent), { options: newOptions });
|
|
77
|
+
}
|
|
78
|
+
function inlineAction(_a) {
|
|
79
|
+
var _b;
|
|
80
|
+
var actionComponent = _a.actionComponent, actions = _a.actions;
|
|
81
|
+
if (actionComponent.action &&
|
|
82
|
+
isReference(actionComponent.action) &&
|
|
83
|
+
((_b = actionComponent.action) === null || _b === void 0 ? void 0 : _b.$ref)) {
|
|
84
|
+
var newAction = getActionById(actions, actionComponent.action.$ref);
|
|
85
|
+
return convertStepActionToDynamicAction(newAction);
|
|
86
|
+
}
|
|
87
|
+
return actionComponent;
|
|
88
|
+
}
|
|
89
|
+
function getSchemaById(schemas, id) {
|
|
90
|
+
var schema = schemas.find(function (schema) { return schema.$id === id; });
|
|
91
|
+
if (!schema) {
|
|
92
|
+
throw new Error("Fatal Error. Schema not found. $id ".concat(id));
|
|
93
|
+
}
|
|
94
|
+
return schema;
|
|
95
|
+
}
|
|
96
|
+
function getActionById(actions, id) {
|
|
97
|
+
var action = actions.find(function (action) { return action.$id === id; });
|
|
98
|
+
if (!action) {
|
|
99
|
+
throw new Error("Fatal Error. Action not found. $id ".concat(id));
|
|
100
|
+
}
|
|
101
|
+
return action;
|
|
102
|
+
}
|
|
103
|
+
function isReference(block) {
|
|
104
|
+
return Object.hasOwnProperty.call(block, '$ref');
|
|
105
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
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
|
+
export function convertStepToLayout(step, _a) {
|
|
22
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.displayStepTitle, displayStepTitle = _c === void 0 ? true : _c;
|
|
23
|
+
// This condition is meant as a temporary hack until mobile platforms will be refactored to fully support the layout property
|
|
24
|
+
if (step.layout) {
|
|
25
|
+
return addMissingTitleAndDescriptionToStep(step, displayStepTitle);
|
|
26
|
+
}
|
|
27
|
+
switch (step.type) {
|
|
28
|
+
case 'final':
|
|
29
|
+
return convertFinalStepToDynamicLayout(step);
|
|
30
|
+
case 'decision':
|
|
31
|
+
return convertDecisionStepToDynamicLayout(step);
|
|
32
|
+
case 'external':
|
|
33
|
+
return convertExternalStepToDynamicLayout(step);
|
|
34
|
+
default:
|
|
35
|
+
return convertFormStepToDynamicLayout(step);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function convertCommonComponents(step) {
|
|
39
|
+
var layout = [];
|
|
40
|
+
if (step.title) {
|
|
41
|
+
layout.push(convertStepTitleToDynamicHeading(step.title));
|
|
42
|
+
}
|
|
43
|
+
if (step.image) {
|
|
44
|
+
var image = convertStepImageToDynamicImage(step.image);
|
|
45
|
+
layout.push(image);
|
|
46
|
+
}
|
|
47
|
+
if (step.description) {
|
|
48
|
+
layout.push(convertStepDescriptionToDynamicParagraph(step.description));
|
|
49
|
+
}
|
|
50
|
+
return layout;
|
|
51
|
+
}
|
|
52
|
+
function convertExternalStepToDynamicLayout(step) {
|
|
53
|
+
return __spreadArray(__spreadArray([], convertCommonComponents(step), true), [convertStepToExternalComponent(step)], false);
|
|
54
|
+
}
|
|
55
|
+
function convertStepToExternalComponent(step) {
|
|
56
|
+
return {
|
|
57
|
+
type: 'external',
|
|
58
|
+
requestUrl: step.requestUrl,
|
|
59
|
+
polling: step.polling,
|
|
60
|
+
responseHandlers: step.responseHandlers,
|
|
61
|
+
retryTitle: step.retryTitle
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function convertFormStepToDynamicLayout(step) {
|
|
65
|
+
var layout = convertCommonComponents(step);
|
|
66
|
+
if (step.reviewFields) {
|
|
67
|
+
layout.push(convertStepReviewToDynamicReview(step.reviewFields));
|
|
68
|
+
}
|
|
69
|
+
if (step.schemas) {
|
|
70
|
+
layout.push.apply(layout, getSchemaLayout(step));
|
|
71
|
+
}
|
|
72
|
+
if (step.actions) {
|
|
73
|
+
var actions = step.actions.map(convertStepActionToDynamicAction);
|
|
74
|
+
layout.push(dynamicBox(actions, 'md'));
|
|
75
|
+
}
|
|
76
|
+
return layout;
|
|
77
|
+
}
|
|
78
|
+
function convertFinalStepToDynamicLayout(step) {
|
|
79
|
+
var layout = [];
|
|
80
|
+
if (step.details) {
|
|
81
|
+
if (step.details.image) {
|
|
82
|
+
var image = convertFinalStepImageToDynamicImage(step.details.image);
|
|
83
|
+
layout.push(image);
|
|
84
|
+
}
|
|
85
|
+
if (step.details.title) {
|
|
86
|
+
layout.push(convertStepTitleToDynamicHeading(step.details.title));
|
|
87
|
+
}
|
|
88
|
+
if (step.details.description) {
|
|
89
|
+
layout.push(convertStepDescriptionToDynamicParagraph(step.details.description));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (step.actions) {
|
|
93
|
+
var actions = step.actions.map(function (action) {
|
|
94
|
+
return convertStepActionToDynamicAction(__assign(__assign({}, action), { type: action.type || 'primary' }));
|
|
95
|
+
});
|
|
96
|
+
layout.push(dynamicBox(actions, 'md'));
|
|
97
|
+
}
|
|
98
|
+
return layout;
|
|
99
|
+
}
|
|
100
|
+
function convertDecisionStepToDynamicLayout(step) {
|
|
101
|
+
var layout = convertCommonComponents(step);
|
|
102
|
+
if (step.options) {
|
|
103
|
+
layout.push(convertStepDecisionToDynamicDecision(step.options));
|
|
104
|
+
}
|
|
105
|
+
return layout;
|
|
106
|
+
}
|
|
107
|
+
function dynamicBox(components, size) {
|
|
108
|
+
return {
|
|
109
|
+
type: 'box',
|
|
110
|
+
width: size || 'md',
|
|
111
|
+
components: components
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function convertStepTitleToDynamicHeading(title) {
|
|
115
|
+
return {
|
|
116
|
+
type: 'heading',
|
|
117
|
+
text: title,
|
|
118
|
+
size: 'lg',
|
|
119
|
+
margin: 'lg',
|
|
120
|
+
align: 'center'
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function convertStepDescriptionToDynamicParagraph(description) {
|
|
124
|
+
return {
|
|
125
|
+
type: 'paragraph',
|
|
126
|
+
text: description,
|
|
127
|
+
align: 'center'
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function convertStepSchemaToDynamicForm(schema) {
|
|
131
|
+
return { type: 'form', schema: schema };
|
|
132
|
+
}
|
|
133
|
+
function convertStepDecisionToDynamicDecision(options) {
|
|
134
|
+
return {
|
|
135
|
+
type: 'decision',
|
|
136
|
+
options: options.map(convertStepDecisionOption)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function convertStepDecisionOption(option) {
|
|
140
|
+
return {
|
|
141
|
+
title: option.title,
|
|
142
|
+
description: option.description,
|
|
143
|
+
action: {
|
|
144
|
+
title: option.title,
|
|
145
|
+
method: 'GET',
|
|
146
|
+
url: option.url,
|
|
147
|
+
disabled: option.disabled
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function convertStepImageToDynamicImage(image) {
|
|
152
|
+
return {
|
|
153
|
+
type: 'image',
|
|
154
|
+
url: image.url,
|
|
155
|
+
text: image.text,
|
|
156
|
+
margin: image.margin || 'lg',
|
|
157
|
+
size: image.size || 'md'
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function convertFinalStepImageToDynamicImage(image) {
|
|
161
|
+
return typeof image === 'string'
|
|
162
|
+
? {
|
|
163
|
+
type: 'image',
|
|
164
|
+
url: image,
|
|
165
|
+
text: undefined,
|
|
166
|
+
margin: 'lg',
|
|
167
|
+
size: 'md'
|
|
168
|
+
}
|
|
169
|
+
: convertStepImageToDynamicImage(image);
|
|
170
|
+
}
|
|
171
|
+
export function convertStepActionToDynamicAction(action) {
|
|
172
|
+
var newAction = __assign(__assign({}, action), { title: action.title });
|
|
173
|
+
return {
|
|
174
|
+
type: 'button',
|
|
175
|
+
action: newAction
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function convertStepReviewToDynamicReview(reviewFields) {
|
|
179
|
+
return {
|
|
180
|
+
type: 'review',
|
|
181
|
+
title: reviewFields.title,
|
|
182
|
+
fields: reviewFields.fields.map(convertReviewFieldToDefinition)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function convertReviewFieldToDefinition(reviewField) {
|
|
186
|
+
return {
|
|
187
|
+
label: reviewField.title,
|
|
188
|
+
value: reviewField.value
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function getSchemaLayout(step) {
|
|
192
|
+
var layout = [];
|
|
193
|
+
if (step.schemas && step.schemas[0]) {
|
|
194
|
+
var schema = step.schemas[0];
|
|
195
|
+
var dynamicForm = convertStepSchemaToDynamicForm(schema);
|
|
196
|
+
if (isWideForm()) {
|
|
197
|
+
layout.push(dynamicForm);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
layout.push(dynamicBox([dynamicForm], 'md'));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return layout;
|
|
204
|
+
}
|
|
205
|
+
function isWideForm() {
|
|
206
|
+
// For the time being we won't support automatically widening forms
|
|
207
|
+
// Unlike it V2, there is no way to easily iterate and identify narrow fields
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
function addMissingTitleAndDescriptionToStep(step, displayStepTitle) {
|
|
211
|
+
return __spreadArray(__spreadArray(__spreadArray([], (displayStepTitle && step.title ? [convertStepTitleToDynamicHeading(step.title)] : []), true), (step.description ? [convertStepDescriptionToDynamicParagraph(step.description)] : []), true), (step.layout || []), true);
|
|
212
|
+
}
|
package/build/main.js
CHANGED
|
@@ -13973,13 +13973,13 @@ function DynamicFlowCore(props) {
|
|
|
13973
13973
|
return abortControllerRef.current.signal;
|
|
13974
13974
|
};
|
|
13975
13975
|
(0, import_react58.useEffect)(() => {
|
|
13976
|
-
trackEvent("
|
|
13976
|
+
trackEvent("Initiated");
|
|
13977
13977
|
if (!initialStep && initialAction) {
|
|
13978
13978
|
void onAction(initialAction);
|
|
13979
13979
|
}
|
|
13980
13980
|
if (initialStep && !initialAction) {
|
|
13981
13981
|
initialiseWithStep(initialStep, null);
|
|
13982
|
-
trackEvent("Step Shown");
|
|
13982
|
+
trackEvent("Step Shown", { isFirstStep: true });
|
|
13983
13983
|
}
|
|
13984
13984
|
}, []);
|
|
13985
13985
|
const initialiseWithStep = (0, import_react58.useCallback)(
|
|
@@ -14051,14 +14051,14 @@ function DynamicFlowCore(props) {
|
|
|
14051
14051
|
);
|
|
14052
14052
|
const closeWithError = (0, import_react58.useCallback)(
|
|
14053
14053
|
(error, analytics) => {
|
|
14054
|
-
trackEvent("
|
|
14054
|
+
trackEvent("Failed", __spreadValues({}, analytics));
|
|
14055
14055
|
onError(error);
|
|
14056
14056
|
},
|
|
14057
14057
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14058
14058
|
[]
|
|
14059
14059
|
);
|
|
14060
14060
|
const onAction = (0, import_react58.useCallback)(async (action) => {
|
|
14061
|
-
var _a2, _b, _c, _d
|
|
14061
|
+
var _a2, _b, _c, _d;
|
|
14062
14062
|
try {
|
|
14063
14063
|
(_a2 = stepComponentRef.current) == null ? void 0 : _a2.setLoadingState("loading");
|
|
14064
14064
|
const model = (_c = await ((_b = stepComponentRef.current) == null ? void 0 : _b.getSubmittableValue())) != null ? _c : null;
|
|
@@ -14073,12 +14073,13 @@ function DynamicFlowCore(props) {
|
|
|
14073
14073
|
switch (command.type) {
|
|
14074
14074
|
case "complete": {
|
|
14075
14075
|
onCompletion(command.result);
|
|
14076
|
-
trackEvent("
|
|
14076
|
+
trackEvent("Succeeded");
|
|
14077
14077
|
break;
|
|
14078
14078
|
}
|
|
14079
14079
|
case "replace-step": {
|
|
14080
|
+
const isFirstStep = stepRef.current === null;
|
|
14080
14081
|
initialiseWithStep(command.step, command.etag);
|
|
14081
|
-
trackEvent("Step Shown");
|
|
14082
|
+
trackEvent("Step Shown", { isFirstStep });
|
|
14082
14083
|
break;
|
|
14083
14084
|
}
|
|
14084
14085
|
case "error": {
|
|
@@ -14093,26 +14094,7 @@ function DynamicFlowCore(props) {
|
|
|
14093
14094
|
}
|
|
14094
14095
|
case "refresh": {
|
|
14095
14096
|
const { refreshUrl, errors = {} } = command.body;
|
|
14096
|
-
|
|
14097
|
-
(_e = stepComponentRef.current) == null ? void 0 : _e.setLoadingState("loading");
|
|
14098
|
-
const refreshCommand = await executeRefresh({
|
|
14099
|
-
abortSignal: abortCurrentAndGetNewAbortSignal(),
|
|
14100
|
-
url: refreshUrl,
|
|
14101
|
-
model,
|
|
14102
|
-
etag: etagRef.current,
|
|
14103
|
-
httpClient,
|
|
14104
|
-
trackEvent
|
|
14105
|
-
});
|
|
14106
|
-
switch (refreshCommand.type) {
|
|
14107
|
-
case "refresh-step":
|
|
14108
|
-
initialiseWithStep(__spreadProps(__spreadValues({}, refreshCommand.step), { errors }), refreshCommand.etag);
|
|
14109
|
-
break;
|
|
14110
|
-
default:
|
|
14111
|
-
throw new Error("Failed to refresh");
|
|
14112
|
-
}
|
|
14113
|
-
} catch (e) {
|
|
14114
|
-
closeWithError(e, {});
|
|
14115
|
-
}
|
|
14097
|
+
void onRefresh(void 0, refreshUrl, errors);
|
|
14116
14098
|
break;
|
|
14117
14099
|
}
|
|
14118
14100
|
}
|
|
@@ -14121,7 +14103,7 @@ function DynamicFlowCore(props) {
|
|
|
14121
14103
|
}
|
|
14122
14104
|
}, []);
|
|
14123
14105
|
const onRefresh = (0, import_react58.useCallback)(
|
|
14124
|
-
async (schemaId, refreshUrl = "") => {
|
|
14106
|
+
async (schemaId, refreshUrl = "", errorsOverride) => {
|
|
14125
14107
|
var _a2, _b, _c, _d;
|
|
14126
14108
|
try {
|
|
14127
14109
|
(_a2 = stepComponentRef.current) == null ? void 0 : _a2.setLoadingState("loading");
|
|
@@ -14137,7 +14119,10 @@ function DynamicFlowCore(props) {
|
|
|
14137
14119
|
});
|
|
14138
14120
|
switch (command.type) {
|
|
14139
14121
|
case "refresh-step":
|
|
14140
|
-
|
|
14122
|
+
{
|
|
14123
|
+
const errors = errorsOverride != null ? errorsOverride : command.step.errors;
|
|
14124
|
+
initialiseWithStep(__spreadProps(__spreadValues({}, command.step), { errors }), command.etag);
|
|
14125
|
+
}
|
|
14141
14126
|
break;
|
|
14142
14127
|
case "error": {
|
|
14143
14128
|
closeWithError(new Error("Failed to refresh"), command.body.analytics);
|