@wise/dynamic-flow-client 3.4.1 → 3.5.0-experimental-6654c72
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/errorBoundary/ErrorBoundary.js +44 -0
- package/build/common/errorBoundary/ErrorBoundaryAlert.js +12 -0
- 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/external-confirmation.messages.js +23 -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/multi-select.messages.js +8 -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/i18n/index.js +36 -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 +113 -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/DynamicFlow.js +346 -0
- package/build/legacy/dynamicFlow/DynamicFlowStep.js +37 -0
- package/build/legacy/dynamicFlow/DynamicFlowTypes.js +1 -0
- package/build/legacy/dynamicFlow/index.js +1 -0
- package/build/legacy/dynamicFlow/utils/index.js +5 -0
- package/build/legacy/dynamicFlow/utils/responseParsers/response-parsers.js +185 -0
- package/build/legacy/dynamicFlow/utils/useDebouncedRefresh/useDebouncedRefresh.js +26 -0
- package/build/legacy/dynamicFlow/utils/useDynamicFlowState.js +137 -0
- package/build/legacy/dynamicFlow/utils/useLoader.js +22 -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/JsonSchemaForm.js +24 -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 +34 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multiSelectSchema/MultiSelectSchema.js +84 -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/genericSchema/GenericSchema.js +85 -0
- package/build/legacy/jsonSchemaForm/genericSchema/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/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/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.js +150 -0
- package/build/legacy/jsonSchemaForm/validationAsyncSchema/index.js +1 -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/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 +4775 -225
- package/build/main.min.js +1 -1
- package/build/main.mjs +4776 -226
- package/build/revamp/domain/components/AlertComponent.js +50 -0
- package/build/revamp/domain/components/AllOfComponent.js +72 -0
- package/build/revamp/domain/components/BooleanInputComponent.js +108 -0
- package/build/revamp/domain/components/BoxComponent.js +65 -0
- package/build/revamp/domain/components/ButtonComponent.js +50 -0
- package/build/revamp/domain/components/ColumnsComponent.js +74 -0
- package/build/revamp/domain/components/ConstComponent.js +50 -0
- package/build/revamp/domain/components/ContainerComponent.js +65 -0
- package/build/revamp/domain/components/DateInputComponent.js +127 -0
- package/build/revamp/domain/components/DecisionComponent.js +50 -0
- package/build/revamp/domain/components/DividerComponent.js +50 -0
- package/build/revamp/domain/components/FormComponent.js +65 -0
- package/build/revamp/domain/components/HeadingComponent.js +50 -0
- package/build/revamp/domain/components/ImageComponent.js +50 -0
- package/build/revamp/domain/components/InstructionsComponent.js +50 -0
- package/build/revamp/domain/components/IntegerInputComponent.js +125 -0
- package/build/revamp/domain/components/LoadingIndicatorComponent.js +50 -0
- package/build/revamp/domain/components/MarkdownComponent.js +50 -0
- package/build/revamp/domain/components/ModalComponent.js +65 -0
- package/build/revamp/domain/components/MultiUploadInputComponent.js +190 -0
- package/build/revamp/domain/components/NumberInputComponent.js +125 -0
- package/build/revamp/domain/components/ObjectComponent.js +104 -0
- package/build/revamp/domain/components/ParagraphComponent.js +50 -0
- package/build/revamp/domain/components/ReviewComponent.js +50 -0
- package/build/revamp/domain/components/SelectInputComponent.js +138 -0
- package/build/revamp/domain/components/StatusListComponent.js +50 -0
- package/build/revamp/domain/components/StepDomainComponent.js +93 -0
- package/build/revamp/domain/components/TextInputComponent.js +125 -0
- package/build/revamp/domain/components/UploadInputComponent.js +151 -0
- package/build/revamp/domain/components/repeatableComponent/RepeatableComponent.js +148 -0
- package/build/revamp/domain/components/searchComponent/SearchComponent.js +108 -0
- package/build/revamp/domain/components/utils/component-utils.js +18 -0
- package/build/revamp/domain/components/utils/debounce.js +38 -0
- package/build/revamp/domain/components/utils/file-utils.js +46 -0
- package/build/revamp/domain/components/utils/getComponentForLocalValueKey.js +31 -0
- package/build/revamp/domain/components/utils/isPartialLocalValueMatch.js +40 -0
- package/build/revamp/domain/features/events.js +1 -0
- package/build/revamp/domain/features/persistAsync/getComponentPersistAsync.js +133 -0
- package/build/revamp/domain/features/persistAsync/getPerformPersistAsync.js +103 -0
- package/build/revamp/domain/features/refresh/getPerformRefresh.js +53 -0
- package/build/revamp/domain/features/summary/summary-utils.js +39 -0
- package/build/revamp/domain/features/utils/http-utils.js +34 -0
- package/build/revamp/domain/features/utils/response-utils.js +9 -0
- package/build/revamp/domain/features/validation/validation-functions.js +12 -0
- package/build/revamp/domain/features/validation/value-checks.js +111 -0
- package/build/revamp/domain/features/validationAsync/getComponentValidationAsync.js +94 -0
- package/build/revamp/domain/features/validationAsync/getPerformValidationAsync.js +107 -0
- package/build/revamp/domain/mappers/types.js +1 -0
- package/build/revamp/domain/types.js +1 -0
- package/build/revamp/flow/response-utils.js +88 -0
- package/build/revamp/renderers/CoreContainerRenderer.js +8 -0
- package/build/revamp/renderers/LoadingContext.js +7 -0
- package/build/revamp/renderers/types.js +1 -0
- package/build/revamp/types.js +1 -0
- package/build/revamp/utils/component-utils.js +86 -0
- package/build/revamp/utils/type-utils.js +56 -0
- package/build/revamp/utils/type-validators.js +16 -0
- package/build/revamp/wise/renderers/AlertRenderer.js +11 -0
- package/build/revamp/wise/renderers/BooleanInputRenderer.js +34 -0
- package/build/revamp/wise/renderers/BoxRenderer.js +30 -0
- package/build/revamp/wise/renderers/ButtonRenderer.js +64 -0
- package/build/revamp/wise/renderers/ColumnsRenderer.js +25 -0
- package/build/revamp/wise/renderers/components/FieldInput.js +20 -0
- package/build/revamp/wise/renderers/components/Help.js +21 -0
- package/build/revamp/wise/renderers/components/LabelContentWithHelp.js +6 -0
- package/build/revamp/wise/renderers/utils/layout-utils.js +31 -0
- package/build/types/legacy/step/externalConfirmationStep/ExternalConfirmationStep.d.ts +1 -1
- package/build/types/revamp/domain/components/StepDomainComponent.d.ts +4 -2
- package/build/types/revamp/renderers/step/ExternalConfirmationDialog.d.ts +6 -0
- package/build/types/revamp/renderers/{StepRenderer.d.ts → step/StepRenderer.d.ts} +1 -1
- package/build/types/revamp/renderers/step/useExternal.d.ts +4 -0
- package/build/types/revamp/renderers/stepComponentToProps.d.ts +1 -1
- package/build/types/revamp/renderers/types.d.ts +3 -0
- package/package.json +13 -13
- /package/build/types/{legacy/step/externalConfirmationStep/ExternalConfirmationStep.messages.d.ts → common/messages/external-confirmation.messages.d.ts} +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
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 { useMemo, useState } from 'react';
|
|
22
|
+
import { isValidSchema, getValidObjectModelParts } from '../../common/validators';
|
|
23
|
+
export var useDynamicFlowState = function (initialStep) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
var _c = useState((_a = initialStep === null || initialStep === void 0 ? void 0 : initialStep.errors) === null || _a === void 0 ? void 0 : _a.validation), formErrors = _c[0], setFormErrors = _c[1];
|
|
26
|
+
var _d = useState((_b = initialStep === null || initialStep === void 0 ? void 0 : initialStep.errors) === null || _b === void 0 ? void 0 : _b.error), globalError = _d[0], setGlobalError = _d[1];
|
|
27
|
+
var _e = useState({
|
|
28
|
+
step: initialStep || undefined,
|
|
29
|
+
models: (initialStep === null || initialStep === void 0 ? void 0 : initialStep.model)
|
|
30
|
+
? buildInitialModels(initialStep.model, getAllSchemas(initialStep))
|
|
31
|
+
: {},
|
|
32
|
+
etag: undefined
|
|
33
|
+
}), stepAndModels = _e[0], setStepAndModels = _e[1];
|
|
34
|
+
var step = stepAndModels.step, models = stepAndModels.models, etag = stepAndModels.etag;
|
|
35
|
+
var setStepAndEtag = function (step, etag) {
|
|
36
|
+
var _a, _b, _c, _d;
|
|
37
|
+
setStepAndModels({
|
|
38
|
+
step: step,
|
|
39
|
+
models: step.model ? buildInitialModels(step.model, getAllSchemas(step)) : {},
|
|
40
|
+
etag: etag
|
|
41
|
+
});
|
|
42
|
+
setFormErrors((_b = (_a = step === null || step === void 0 ? void 0 : step.errors) === null || _a === void 0 ? void 0 : _a.validation) !== null && _b !== void 0 ? _b : null);
|
|
43
|
+
setGlobalError((_d = (_c = step === null || step === void 0 ? void 0 : step.errors) === null || _c === void 0 ? void 0 : _c.error) !== null && _d !== void 0 ? _d : null);
|
|
44
|
+
};
|
|
45
|
+
var setSchemaModel = function (schemaId, objectModel, onModelsUpdated) {
|
|
46
|
+
setStepAndModels(function (previous) {
|
|
47
|
+
var _a;
|
|
48
|
+
var updatedModels = __assign(__assign({}, previous.models), (_a = {}, _a[schemaId] = objectModel, _a));
|
|
49
|
+
var updatedState = {
|
|
50
|
+
step: previous.step,
|
|
51
|
+
models: updatedModels,
|
|
52
|
+
etag: previous.etag
|
|
53
|
+
};
|
|
54
|
+
onModelsUpdated(updatedModels);
|
|
55
|
+
return updatedState;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
var modelIsValid = useMemo(function () { return areModelsValid(models, getAllValidatableSchemas(step)); }, [models, step]);
|
|
59
|
+
return {
|
|
60
|
+
formErrors: formErrors,
|
|
61
|
+
globalError: globalError,
|
|
62
|
+
step: step,
|
|
63
|
+
models: models,
|
|
64
|
+
etag: etag,
|
|
65
|
+
modelIsValid: modelIsValid,
|
|
66
|
+
setFormErrors: setFormErrors,
|
|
67
|
+
setGlobalError: setGlobalError,
|
|
68
|
+
setStepAndEtag: setStepAndEtag,
|
|
69
|
+
setSchemaModel: setSchemaModel
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
var buildInitialModels = function (model, schemas) {
|
|
73
|
+
if (schemas === void 0) { schemas = []; }
|
|
74
|
+
return schemas.reduce(function (acc, schema) {
|
|
75
|
+
var _a;
|
|
76
|
+
if (!schema.$id) {
|
|
77
|
+
// TODO: DF-473 - Remove type assertions once we're confident people have had time to fix any errors
|
|
78
|
+
// eslint-disable-next-line no-console
|
|
79
|
+
console.warn('Schema without $id property found.');
|
|
80
|
+
}
|
|
81
|
+
return __assign(__assign({}, acc), (_a = {}, _a[schema.$id || ''] = getValidObjectModelParts(model, schema) || {}, _a));
|
|
82
|
+
}, {});
|
|
83
|
+
};
|
|
84
|
+
var getAllSchemas = function (step) { return __spreadArray(__spreadArray([], getAllSchemasInLayout((step === null || step === void 0 ? void 0 : step.layout) || []), true), ((step === null || step === void 0 ? void 0 : step.schemas) || []), true); };
|
|
85
|
+
var getAllSchemasInLayout = function (components) {
|
|
86
|
+
return components.flatMap(function (component) {
|
|
87
|
+
switch (component.type) {
|
|
88
|
+
case 'columns':
|
|
89
|
+
return __spreadArray([], getAllSchemasInLayout(__spreadArray(__spreadArray([], component.left, true), component.right, true)), true);
|
|
90
|
+
case 'box':
|
|
91
|
+
return getAllSchemasInLayout(component.components);
|
|
92
|
+
case 'form':
|
|
93
|
+
return isInlineSchema(component.schema) ? [component.schema] : [];
|
|
94
|
+
default:
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
var getAllValidatableSchemas = function (step) { return __spreadArray(__spreadArray([], getAllReferencedSchemaIds((step === null || step === void 0 ? void 0 : step.layout) || [])
|
|
100
|
+
.map(function (id) { return ((step === null || step === void 0 ? void 0 : step.schemas) || []).find(function (schema) { return schema.$id === id; }); })
|
|
101
|
+
.filter(Boolean), true), getAllSchemasInLayout((step === null || step === void 0 ? void 0 : step.layout) || []), true); };
|
|
102
|
+
var getAllReferencedSchemaIds = function (components) {
|
|
103
|
+
return components
|
|
104
|
+
.flatMap(function (component) {
|
|
105
|
+
switch (component.type) {
|
|
106
|
+
case 'columns':
|
|
107
|
+
return __spreadArray([], getAllReferencedSchemaIds(__spreadArray(__spreadArray([], component.left, true), component.right, true)), true);
|
|
108
|
+
case 'box':
|
|
109
|
+
return getAllReferencedSchemaIds(component.components);
|
|
110
|
+
case 'form':
|
|
111
|
+
return [getSchemaReference(component)];
|
|
112
|
+
default:
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
.filter(Boolean);
|
|
117
|
+
};
|
|
118
|
+
var areModelsValid = function (formModels, schemas) {
|
|
119
|
+
if (schemas === void 0) { schemas = []; }
|
|
120
|
+
return !(schemas === null || schemas === void 0 ? void 0 : schemas.some(function (schema) {
|
|
121
|
+
if (!schema.$id) {
|
|
122
|
+
// TODO: DF-473
|
|
123
|
+
// eslint-disable-next-line no-console
|
|
124
|
+
console.warn('Schema without $id property found.');
|
|
125
|
+
}
|
|
126
|
+
return !isValidSchema(formModels[schema.$id || ''] || {}, schema);
|
|
127
|
+
}));
|
|
128
|
+
};
|
|
129
|
+
var getSchemaReference = function (component) {
|
|
130
|
+
if (component.schema && !isInlineSchema(component.schema)) {
|
|
131
|
+
return component.schema.$ref;
|
|
132
|
+
}
|
|
133
|
+
return component.schemaId;
|
|
134
|
+
};
|
|
135
|
+
var isInlineSchema = function (schema) {
|
|
136
|
+
return schema !== undefined && typeof schema === 'object' && !Object.hasOwnProperty.call(schema, '$ref');
|
|
137
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { Loader, Size } from '@transferwise/components';
|
|
14
|
+
import { useState } from 'react';
|
|
15
|
+
export function useLoader(loaderConfig, initialState) {
|
|
16
|
+
var config = __assign({ size: Size.EXTRA_LARGE, initial: true, submission: false }, loaderConfig);
|
|
17
|
+
var _a = useState(initialState), loadingState = _a[0], setLoadingState = _a[1];
|
|
18
|
+
var shouldDisplayLoader = (config.initial && loadingState === 'initial') ||
|
|
19
|
+
(config.submission && loadingState === 'submission');
|
|
20
|
+
var loader = shouldDisplayLoader ? (_jsx(Loader, { size: config.size, classNames: { 'tw-loader': 'tw-loader m-x-auto' }, "data-testid": "loader" })) : null;
|
|
21
|
+
return { isLoading: loadingState !== 'idle', setLoadingState: setLoadingState, loader: loader };
|
|
22
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
28
|
+
import { Checkbox, DateInput, DateLookup, InputWithDisplayFormat, PhoneNumberInput, RadioGroup, SelectInput, SelectInputOptionContent, Tabs, TextareaWithDisplayFormat, Upload, } from '@transferwise/components';
|
|
29
|
+
import { PureComponent } from 'react';
|
|
30
|
+
import { DateMode, FormControlType, MonthFormat, Size } from '../common/constants';
|
|
31
|
+
import { dateToDateString } from '../common/utils';
|
|
32
|
+
import { isArray, isNumber, isString } from '../common/validators';
|
|
33
|
+
import { getSafeStringOrNumberValue, getSafeDateOrStringValue, getSafeDateStringValue, getSafeStringValue, getSafeBooleanValue, getAutocompleteString, } from './utils';
|
|
34
|
+
var FormControl = /** @class */ (function (_super) {
|
|
35
|
+
__extends(FormControl, _super);
|
|
36
|
+
function FormControl(props) {
|
|
37
|
+
var _this = _super.call(this, props) || this;
|
|
38
|
+
_this.getAutocompleteValue = function (_a) {
|
|
39
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.prefix, prefix = _c === void 0 ? '' : _c, _d = _b.suffix, suffix = _d === void 0 ? '' : _d;
|
|
40
|
+
var _e = _this.props, autoComplete = _e.autoComplete, autocompleteHint = _e.autocompleteHint;
|
|
41
|
+
if (isArray(autocompleteHint)) {
|
|
42
|
+
return getAutocompleteString(autocompleteHint, { prefix: prefix, suffix: suffix });
|
|
43
|
+
}
|
|
44
|
+
return autoComplete ? 'on' : 'off';
|
|
45
|
+
};
|
|
46
|
+
_this.handleOnChange = function (value, metadata) {
|
|
47
|
+
_this.props.onChange(value, undefined, metadata);
|
|
48
|
+
};
|
|
49
|
+
_this.handleInputOnChange = function (event) {
|
|
50
|
+
_this.props.onChange(event.target.value);
|
|
51
|
+
};
|
|
52
|
+
_this.handleOnFocus = function () {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
(_b = (_a = _this.props).onFocus) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
55
|
+
};
|
|
56
|
+
_this.handleOnBlur = function () {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
(_b = (_a = _this.props).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
59
|
+
};
|
|
60
|
+
_this.getSelectedOption = function (options) {
|
|
61
|
+
if (_this.state.selectedOption !== null && typeof _this.state.selectedOption !== 'undefined') {
|
|
62
|
+
return options.find(function (option) { var _a; return ((_a = _this.state.selectedOption) === null || _a === void 0 ? void 0 : _a.value) === option.value; });
|
|
63
|
+
}
|
|
64
|
+
if (_this.props.value !== null && typeof _this.props.value !== 'undefined') {
|
|
65
|
+
return options.find(function (option) { return _this.props.value === option.value; });
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
};
|
|
69
|
+
_this.mapOption = function (option) { return (__assign(__assign({}, option), { value: isNumber(option.value) || isString(option.value) ? option.value : undefined, secondary: option.note, disabled: option.disabled || _this.props.disabled, readOnly: _this.props.readOnly })); };
|
|
70
|
+
_this.state = {
|
|
71
|
+
selectedOption: props.selectedOption,
|
|
72
|
+
touched: false,
|
|
73
|
+
prevValue: props.value
|
|
74
|
+
};
|
|
75
|
+
return _this;
|
|
76
|
+
}
|
|
77
|
+
FormControl.getDerivedStateFromProps = function (nextProps, previousState) {
|
|
78
|
+
if (previousState.prevValue !== nextProps.value) {
|
|
79
|
+
return { prevValue: nextProps.value, value: nextProps.value };
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
};
|
|
83
|
+
FormControl.prototype.render = function () {
|
|
84
|
+
var _this = this;
|
|
85
|
+
var _a, _b;
|
|
86
|
+
var _c = this.props, name = _c.name, placeholder = _c.placeholder, step = _c.step, countryCode = _c.countryCode, type = _c.type, options = _c.options, disabled = _c.disabled, readOnly = _c.readOnly, required = _c.required, minLength = _c.minLength, maxLength = _c.maxLength, min = _c.min, max = _c.max, searchPlaceholder = _c.searchPlaceholder, onSearchChange = _c.onSearchChange, size = _c.size, uploadProps = _c.uploadProps, label = _c.label, monthFormat = _c.monthFormat,
|
|
87
|
+
// FIXME pass id to all components that accept it
|
|
88
|
+
id = _c.id, minDate = _c.minDate, maxDate = _c.maxDate, value = _c.value, mode = _c.mode, describedBy = _c.describedBy;
|
|
89
|
+
switch (type) {
|
|
90
|
+
case FormControlType.RADIO:
|
|
91
|
+
return (_jsx(RadioGroup, { radios: options.map(this.mapOption), name: name, selectedValue: getSafeStringOrNumberValue(value, { coerceValue: true }), onChange: this.handleOnChange }));
|
|
92
|
+
case FormControlType.CHECKBOX:
|
|
93
|
+
return (_jsx(Checkbox, { checked: getSafeBooleanValue(value, { coerceValue: true }), disabled: disabled, label: label, required: required, readOnly: readOnly, onChange: this.handleOnChange, onBlur: this.handleOnBlur, onFocus: this.handleOnFocus }));
|
|
94
|
+
case FormControlType.SELECT: {
|
|
95
|
+
var search = options.length >= 8;
|
|
96
|
+
var items = options;
|
|
97
|
+
var selected = this.getSelectedOption(options);
|
|
98
|
+
return (_jsx("div", __assign({ className: "d-flex flex-column" }, { children: _jsx(SelectInput, { id: id, items: items.map(function (value) { return ({
|
|
99
|
+
type: 'option',
|
|
100
|
+
value: value,
|
|
101
|
+
disabled: value.disabled
|
|
102
|
+
}); }), value: (_a = selected) !== null && _a !== void 0 ? _a : null, renderValue: function (_a, withinTrigger) {
|
|
103
|
+
var hideIconInTrigger = _a.hideIconInTrigger, icon = _a.icon, label = _a.label, note = _a.note, secondary = _a.secondary;
|
|
104
|
+
return (_jsx(SelectInputOptionContent, { title: label, note: note !== null && note !== void 0 ? note : secondary, icon: withinTrigger && hideIconInTrigger ? undefined : icon }));
|
|
105
|
+
}, filterable: search, disabled: disabled, placeholder: placeholder, filterPlaceholder: searchPlaceholder, onChange: function (option) {
|
|
106
|
+
var _a;
|
|
107
|
+
_this.setState({ selectedOption: option });
|
|
108
|
+
_this.props.onChange((_a = option === null || option === void 0 ? void 0 : option.value) !== null && _a !== void 0 ? _a : null);
|
|
109
|
+
}, onFilterChange: search && onSearchChange
|
|
110
|
+
? function (_a) {
|
|
111
|
+
var query = _a.query;
|
|
112
|
+
onSearchChange(query);
|
|
113
|
+
}
|
|
114
|
+
: undefined, onClear: function () {
|
|
115
|
+
_this.setState({ selectedOption: null });
|
|
116
|
+
_this.props.onChange(null);
|
|
117
|
+
} }) })));
|
|
118
|
+
}
|
|
119
|
+
case FormControlType.TAB:
|
|
120
|
+
return (_jsx(Tabs, { selected: (((_b = this.getSelectedOption(options)) === null || _b === void 0 ? void 0 : _b.value) || 0), tabs: options.map(function (option) { return ({
|
|
121
|
+
title: option.label,
|
|
122
|
+
content: _jsx(_Fragment, {}),
|
|
123
|
+
disabled: option.disabled || false
|
|
124
|
+
}); }), name: id, onTabSelect: function (index) {
|
|
125
|
+
var hasSelectedOption = !!_this.state.selectedOption;
|
|
126
|
+
_this.setState({
|
|
127
|
+
selectedOption: options.find(function (option) { return option.value === index; })
|
|
128
|
+
});
|
|
129
|
+
_this.props.onChange(index, hasSelectedOption ? 'user' : 'init');
|
|
130
|
+
} }));
|
|
131
|
+
case FormControlType.NUMERIC:
|
|
132
|
+
case FormControlType.NUMBER: {
|
|
133
|
+
return (_jsx("input", { autoComplete: this.getAutocompleteValue(), className: "form-control", disabled: disabled, id: id, max: max, min: min, placeholder: placeholder, readOnly: readOnly, required: required, step: step, type: "number", value: getSafeStringOrNumberValue(value, { coerceValue: true }), "aria-describedby": describedBy, onBlur: this.handleOnBlur, onChange: function (event) {
|
|
134
|
+
if (type === FormControlType.NUMERIC) {
|
|
135
|
+
_this.props.onChange(event.target.value);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// Input type number target value is a string and needs to be a number
|
|
139
|
+
_this.props.onChange(parseFloat(event.target.value));
|
|
140
|
+
// FIXME: maybe this parsing should be done outside of this component in SchemaFormControl,
|
|
141
|
+
// where we know what schema we're working with?
|
|
142
|
+
}
|
|
143
|
+
}, onFocus: this.handleOnFocus, onWheel: function (event) {
|
|
144
|
+
if (event.target instanceof HTMLElement) {
|
|
145
|
+
// To prevent values being changed when input is focussed and user scrolls
|
|
146
|
+
event.target.blur();
|
|
147
|
+
}
|
|
148
|
+
} }));
|
|
149
|
+
}
|
|
150
|
+
case FormControlType.HIDDEN:
|
|
151
|
+
return (_jsx("input", { type: "hidden", name: name, value: getSafeStringValue(value, { coerceValue: true }), id: id }));
|
|
152
|
+
case FormControlType.PASSWORD:
|
|
153
|
+
return (_jsx("input", { autoComplete: this.getAutocompleteValue(), className: "form-control", disabled: disabled, id: id, placeholder: placeholder, readOnly: readOnly, required: required, type: "password", value: getSafeStringValue(value, { coerceValue: true }), "aria-describedby": describedBy, onBlur: this.handleOnBlur, onChange: this.handleInputOnChange, onFocus: this.handleOnFocus }));
|
|
154
|
+
case FormControlType.DATE:
|
|
155
|
+
case FormControlType.DATETIME:
|
|
156
|
+
return (_jsx(DateInput, { dayAutoComplete: this.getAutocompleteValue({ suffix: '-day' }), yearAutoComplete: this.getAutocompleteValue({ suffix: '-year' }), disabled: disabled, size: size, value: getSafeDateOrStringValue(value), mode: mode, monthFormat: monthFormat, onBlur: this.handleOnBlur, onChange: this.handleOnChange, onFocus: this.handleOnFocus }));
|
|
157
|
+
case FormControlType.DATELOOKUP: {
|
|
158
|
+
return (_jsx(DateLookup
|
|
159
|
+
// DateLookup handles null values perfectly well, it's just typed incorrectly
|
|
160
|
+
, {
|
|
161
|
+
// DateLookup handles null values perfectly well, it's just typed incorrectly
|
|
162
|
+
value: getSafeDateStringValue(value), min: minDate, max: maxDate, placeholder: placeholder, monthFormat: monthFormat, disabled: disabled, onChange: function (date) {
|
|
163
|
+
// FIXME We need types for DateLookup
|
|
164
|
+
_this.handleOnChange(dateToDateString(date));
|
|
165
|
+
}, onBlur: this.handleOnBlur, onFocus: this.handleOnFocus }));
|
|
166
|
+
}
|
|
167
|
+
case FormControlType.TEL:
|
|
168
|
+
return (_jsx(PhoneNumberInput, { disabled: disabled, countryCode: countryCode, placeholder: placeholder, required: required, searchPlaceholder: searchPlaceholder, size: size, initialValue: getSafeStringValue(value), onBlur: this.handleOnBlur, onChange: function (value) { return _this.handleOnChange(value); }, onFocus: this.handleOnFocus }));
|
|
169
|
+
case FormControlType.TEXTAREA: {
|
|
170
|
+
var textareaProps = {
|
|
171
|
+
className: 'form-control tw-form-control',
|
|
172
|
+
id: id,
|
|
173
|
+
name: name,
|
|
174
|
+
placeholder: placeholder,
|
|
175
|
+
value: getSafeStringValue(value, { coerceValue: true }),
|
|
176
|
+
readOnly: readOnly,
|
|
177
|
+
required: required,
|
|
178
|
+
minLength: minLength,
|
|
179
|
+
maxLength: maxLength,
|
|
180
|
+
onFocus: this.handleOnFocus,
|
|
181
|
+
onBlur: this.handleOnBlur,
|
|
182
|
+
disabled: disabled,
|
|
183
|
+
autoComplete: this.getAutocompleteValue()
|
|
184
|
+
};
|
|
185
|
+
if (this.props.displayPattern) {
|
|
186
|
+
return (_jsx(TextareaWithDisplayFormat, __assign({ displayPattern: this.props.displayPattern }, textareaProps, { onChange: this.handleOnChange })));
|
|
187
|
+
}
|
|
188
|
+
return (_jsx("textarea", __assign({}, textareaProps, { "aria-describedby": describedBy, onChange: this.handleInputOnChange })));
|
|
189
|
+
}
|
|
190
|
+
case FormControlType.FILE:
|
|
191
|
+
case FormControlType.UPLOAD: {
|
|
192
|
+
return (
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
194
|
+
// @ts-expect-error - TODO: Remove this once Upload is migrated to TypeScript
|
|
195
|
+
_jsx(Upload, __assign({}, uploadProps, { usAccept: uploadProps.usAccept || '*', usDisabled: uploadProps.usDisabled || disabled, onSuccess: function (base64url, filename) {
|
|
196
|
+
_this.handleOnChange(base64url, { filename: filename });
|
|
197
|
+
}, onFailure: function () {
|
|
198
|
+
_this.handleOnChange(null);
|
|
199
|
+
}, onCancel: function () {
|
|
200
|
+
_this.handleOnChange(null);
|
|
201
|
+
} })));
|
|
202
|
+
}
|
|
203
|
+
case FormControlType.TEXT:
|
|
204
|
+
case FormControlType.EMAIL:
|
|
205
|
+
default: {
|
|
206
|
+
var inputProps = {
|
|
207
|
+
type: type === FormControlType.EMAIL ? 'email' : 'text',
|
|
208
|
+
className: 'form-control',
|
|
209
|
+
id: id,
|
|
210
|
+
name: name,
|
|
211
|
+
placeholder: placeholder,
|
|
212
|
+
value: getSafeStringValue(value, { coerceValue: true }),
|
|
213
|
+
readOnly: readOnly,
|
|
214
|
+
required: required,
|
|
215
|
+
minLength: minLength,
|
|
216
|
+
maxLength: maxLength,
|
|
217
|
+
onFocus: this.handleOnFocus,
|
|
218
|
+
onBlur: this.handleOnBlur,
|
|
219
|
+
disabled: disabled,
|
|
220
|
+
autoComplete: this.getAutocompleteValue()
|
|
221
|
+
};
|
|
222
|
+
if (this.props.displayPattern) {
|
|
223
|
+
return (_jsx(InputWithDisplayFormat, __assign({ displayPattern: this.props.displayPattern }, inputProps, { onChange: this.handleOnChange })));
|
|
224
|
+
}
|
|
225
|
+
return (_jsx("input", __assign({}, inputProps, { "aria-describedby": describedBy, onChange: this.handleInputOnChange })));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
FormControl.Type = FormControlType;
|
|
230
|
+
FormControl.Size = Size;
|
|
231
|
+
FormControl.MonthFormat = MonthFormat;
|
|
232
|
+
FormControl.DateMode = DateMode;
|
|
233
|
+
FormControl.defaultProps = {
|
|
234
|
+
autoComplete: true,
|
|
235
|
+
countryCode: null,
|
|
236
|
+
disabled: false,
|
|
237
|
+
displayPattern: null,
|
|
238
|
+
id: null,
|
|
239
|
+
label: '',
|
|
240
|
+
max: null,
|
|
241
|
+
maxDate: null,
|
|
242
|
+
maxLength: null,
|
|
243
|
+
min: null,
|
|
244
|
+
minDate: null,
|
|
245
|
+
minLength: null,
|
|
246
|
+
mode: FormControl.DateMode.DAY_MONTH_YEAR,
|
|
247
|
+
monthFormat: FormControl.MonthFormat.LONG,
|
|
248
|
+
onBlur: null,
|
|
249
|
+
onFocus: null,
|
|
250
|
+
onSearchChange: null,
|
|
251
|
+
options: [],
|
|
252
|
+
placeholder: null,
|
|
253
|
+
readOnly: false,
|
|
254
|
+
required: false,
|
|
255
|
+
searchPlaceholder: null,
|
|
256
|
+
searchValue: '',
|
|
257
|
+
selectedOption: null,
|
|
258
|
+
size: FormControl.Size.MEDIUM,
|
|
259
|
+
step: 1,
|
|
260
|
+
type: FormControl.Type.TEXT,
|
|
261
|
+
uploadProps: {},
|
|
262
|
+
value: null
|
|
263
|
+
};
|
|
264
|
+
return FormControl;
|
|
265
|
+
}(PureComponent));
|
|
266
|
+
export default FormControl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './FormControl';
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export var getAutocompleteString = function (hints, _a) {
|
|
2
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.prefix, prefix = _c === void 0 ? '' : _c, _d = _b.suffix, suffix = _d === void 0 ? '' : _d;
|
|
3
|
+
var autoCompleteString = hints
|
|
4
|
+
.map(function (hint) {
|
|
5
|
+
var builtHint = "".concat(prefix).concat(hint).concat(suffix);
|
|
6
|
+
return isAutocompleteToken(builtHint) ? autocompleteTokenMap[builtHint] : undefined;
|
|
7
|
+
})
|
|
8
|
+
.filter(function (str) { return str; })
|
|
9
|
+
.join(' ');
|
|
10
|
+
return autoCompleteString || 'off';
|
|
11
|
+
};
|
|
12
|
+
var isAutocompleteToken = function (str) {
|
|
13
|
+
return Object.keys(autocompleteTokenMap).some(function (hint) { return hint === str; });
|
|
14
|
+
};
|
|
15
|
+
var autocompleteTokenMap = {
|
|
16
|
+
on: 'on',
|
|
17
|
+
name: 'name',
|
|
18
|
+
'name-prefix': 'honorific-prefix',
|
|
19
|
+
'given-name': 'given-name',
|
|
20
|
+
'additional-name': 'additional-name',
|
|
21
|
+
'family-name': 'family-name',
|
|
22
|
+
'name-suffix': 'honorific-suffix',
|
|
23
|
+
nickname: 'nickname',
|
|
24
|
+
email: 'email',
|
|
25
|
+
// Web doesn't have a specific mapping for new username, but this is semantically close enough
|
|
26
|
+
'new-username': 'username',
|
|
27
|
+
username: 'username',
|
|
28
|
+
'new-password': 'new-password',
|
|
29
|
+
password: 'current-password',
|
|
30
|
+
'one-time-code': 'one-time-code',
|
|
31
|
+
'job-title': 'organization-title',
|
|
32
|
+
'organization-name': 'organization',
|
|
33
|
+
'full-street-address': 'street-address',
|
|
34
|
+
'street-address-line-1': 'address-line1',
|
|
35
|
+
'street-address-line-2': 'address-line2',
|
|
36
|
+
'street-address-line-3': 'address-line3',
|
|
37
|
+
'address-level-1': 'address-level1',
|
|
38
|
+
'address-level-2': 'address-level2',
|
|
39
|
+
'address-level-3': 'address-level3',
|
|
40
|
+
'address-level-4': 'address-level4',
|
|
41
|
+
'country-code': 'country',
|
|
42
|
+
'country-name': 'country-name',
|
|
43
|
+
'postal-code': 'postal-code',
|
|
44
|
+
'credit-card-name': 'cc-name',
|
|
45
|
+
'credit-card-given-name': 'cc-given-name',
|
|
46
|
+
'credit-card-middle-name': 'cc-additional-name',
|
|
47
|
+
'credit-card-family-name': 'cc-family-name',
|
|
48
|
+
'credit-card-number': 'cc-number',
|
|
49
|
+
'credit-card-expiration': 'cc-exp',
|
|
50
|
+
'credit-card-expiration-month': 'cc-exp-month',
|
|
51
|
+
'credit-card-expiration-year': 'cc-exp-year',
|
|
52
|
+
'credit-card-security-code': 'cc-csc',
|
|
53
|
+
'credit-card-type': 'cc-type',
|
|
54
|
+
'transaction-currency': 'transaction-currency',
|
|
55
|
+
'transaction-amount': 'transaction-amount',
|
|
56
|
+
language: 'language',
|
|
57
|
+
birthdate: 'bday',
|
|
58
|
+
'birthdate-day': 'bday-day',
|
|
59
|
+
'birthdate-month': 'bday-month',
|
|
60
|
+
'birthdate-year': 'bday-year',
|
|
61
|
+
gender: 'sex',
|
|
62
|
+
'phone-number': 'tel',
|
|
63
|
+
'phone-country-code': 'tel-country-code',
|
|
64
|
+
'phone-national': 'tel-national',
|
|
65
|
+
'phone-area-code': 'tel-area-code',
|
|
66
|
+
'phone-local': 'tel-local',
|
|
67
|
+
'phone-local-prefix': 'tel-local-prefix',
|
|
68
|
+
'phone-local-suffix': 'tel-local-suffix',
|
|
69
|
+
'phone-extension': 'tel-extension',
|
|
70
|
+
url: 'url',
|
|
71
|
+
photo: 'photo',
|
|
72
|
+
impp: 'impp',
|
|
73
|
+
shipping: 'shipping',
|
|
74
|
+
billing: 'billing',
|
|
75
|
+
home: 'home',
|
|
76
|
+
work: 'work',
|
|
77
|
+
mobile: 'mobile',
|
|
78
|
+
fax: 'fax',
|
|
79
|
+
pager: 'pager'
|
|
80
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { dateStringToDate } from '../../common/utils';
|
|
3
|
+
import { isBoolean, isNull, isNumber, isObject, isString } from '../../common/validators';
|
|
4
|
+
export var getSafeStringValue = function (value, options) {
|
|
5
|
+
if (options === void 0) { options = {}; }
|
|
6
|
+
var _a = options.coerceValue, coerceValue = _a === void 0 ? false : _a;
|
|
7
|
+
if (isNull(value)) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
if (isObject(value)) {
|
|
11
|
+
logInvalidTypeFallbackWarning({ received: 'object', expected: 'string' });
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (!isString(value)) {
|
|
15
|
+
if (coerceValue) {
|
|
16
|
+
// TODO: Remove this coercion once we're sure everyone has had a chance to address warnings
|
|
17
|
+
logInvalidTypeCoercedWarning({ received: typeof value, expected: 'string' });
|
|
18
|
+
return String(value);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
logInvalidTypeFallbackWarning({ received: typeof value, expected: 'string' });
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
};
|
|
27
|
+
export var getSafeStringOrNumberValue = function (value, options) {
|
|
28
|
+
if (options === void 0) { options = {}; }
|
|
29
|
+
var _a = options.coerceValue, coerceValue = _a === void 0 ? false : _a;
|
|
30
|
+
if (isNull(value)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (isNumber(value)) {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
var logProps = { received: typeof value, expected: 'string or number' };
|
|
37
|
+
if (isObject(value)) {
|
|
38
|
+
logInvalidTypeFallbackWarning(logProps);
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
if (!isString(value)) {
|
|
42
|
+
if (coerceValue) {
|
|
43
|
+
// TODO: Remove this coercion once we're sure everyone has had a chance to address warnings
|
|
44
|
+
logInvalidTypeCoercedWarning(logProps);
|
|
45
|
+
return String(value);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
logInvalidTypeFallbackWarning(logProps);
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
};
|
|
54
|
+
export var getSafeBooleanValue = function (value, options) {
|
|
55
|
+
if (options === void 0) { options = {}; }
|
|
56
|
+
var _a = options.coerceValue, coerceValue = _a === void 0 ? false : _a;
|
|
57
|
+
if (isNull(value)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (!isBoolean(value)) {
|
|
61
|
+
if (coerceValue) {
|
|
62
|
+
// TODO: Remove this coercion once we're sure everyone has had a chance to address warnings
|
|
63
|
+
logInvalidTypeCoercedWarning({ received: typeof value, expected: 'boolean' });
|
|
64
|
+
return Boolean(value);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
logInvalidTypeFallbackWarning({ received: typeof value, expected: 'boolean' });
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
};
|
|
73
|
+
export var getSafeDateOrStringValue = function (value) {
|
|
74
|
+
if (isNull(value)) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
if (!(value instanceof Date) && !isString(value)) {
|
|
78
|
+
logInvalidTypeFallbackWarning({ received: typeof value, expected: 'string or Date' });
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
};
|
|
83
|
+
export var getSafeDateStringValue = function (value) {
|
|
84
|
+
if (isNull(value)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (!isString(value)) {
|
|
88
|
+
logInvalidTypeFallbackWarning({
|
|
89
|
+
received: typeof value,
|
|
90
|
+
expected: 'string',
|
|
91
|
+
fallback: 'null'
|
|
92
|
+
});
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
var date = dateStringToDate(value);
|
|
96
|
+
if (date === null) {
|
|
97
|
+
console.warn('Incorrectly formatted date string. Falling back to null.');
|
|
98
|
+
}
|
|
99
|
+
return date;
|
|
100
|
+
};
|
|
101
|
+
var logInvalidTypeCoercedWarning = function (_a) {
|
|
102
|
+
var received = _a.received, expected = _a.expected;
|
|
103
|
+
console.warn("Value with type ".concat(received, " passed to control that only accepts type ").concat(expected, ". Type will be coerced, but this behaviour will change in the future, so please fix your code."));
|
|
104
|
+
};
|
|
105
|
+
var logInvalidTypeFallbackWarning = function (_a) {
|
|
106
|
+
var received = _a.received, expected = _a.expected, _b = _a.fallback, fallback = _b === void 0 ? 'undefined' : _b;
|
|
107
|
+
console.warn("Value with type ".concat(received, " passed to control that only accepts type ").concat(expected, ". Falling back to ").concat(fallback));
|
|
108
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { LogProvider, EventsContextProvider } from '../common/contexts';
|
|
14
|
+
import GenericSchema from './genericSchema';
|
|
15
|
+
import { HttpClientProviderFromBaseUrl } from '../../common/httpClientContext';
|
|
16
|
+
function JsonSchemaForm(props) {
|
|
17
|
+
var schemaProps = __assign({ model: null, errors: null }, props);
|
|
18
|
+
var _a = props.baseUrl, baseUrl = _a === void 0 ? '' : _a, _b = props.onEvent, onEvent = _b === void 0 ? noop : _b, _c = props.onLog, onLog = _c === void 0 ? noop : _c;
|
|
19
|
+
return (_jsx(LogProvider, __assign({ flowId: "JsonSchemaForm", stepId: "JsonSchemaForm", onLog: onLog }, { children: _jsx(EventsContextProvider, __assign({ metadata: { flowId: 'JsonSchemaForm', stepId: 'JsonSchemaForm' }, onEvent: onEvent }, { children: _jsx(HttpClientProviderFromBaseUrl, __assign({ baseUrl: baseUrl }, { children: _jsx(GenericSchema, __assign({}, schemaProps)) })) })) })));
|
|
20
|
+
}
|
|
21
|
+
export default JsonSchemaForm;
|
|
22
|
+
var noop = function () {
|
|
23
|
+
// noop
|
|
24
|
+
};
|