@wise/dynamic-flow-client 0.2.1 → 0.3.0-beta-ec09e7.2

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 (103) hide show
  1. package/README.md +47 -25
  2. package/build/common/contexts/events/EventsContext.d.ts +15 -0
  3. package/build/common/contexts/events/EventsContext.js +33 -0
  4. package/build/common/contexts/events/index.d.ts +1 -0
  5. package/build/common/contexts/events/index.js +1 -0
  6. package/build/flow/DynamicFlow.d.ts +0 -1
  7. package/build/flow/DynamicFlow.js +21 -22
  8. package/build/flow/DynamicFlowStep.d.ts +0 -1
  9. package/build/flow/errorBoundary/ErrorBoundaryAlert.d.ts +0 -1
  10. package/build/flow/response-parsers/index.d.ts +2 -2
  11. package/build/flow/response-parsers/index.js +16 -3
  12. package/build/flow/stories/DynamicFlow.story.js +1 -1
  13. package/build/flow/stories/EditableDynamicFlow.d.ts +0 -1
  14. package/build/flow/stories/EditableDynamicFlow.js +1 -1
  15. package/build/flow/types.d.ts +6 -31
  16. package/build/i18n/de.json +5 -1
  17. package/build/i18n/es.json +7 -3
  18. package/build/i18n/fr.json +9 -5
  19. package/build/i18n/hu.json +5 -1
  20. package/build/i18n/id.json +7 -3
  21. package/build/i18n/it.json +4 -0
  22. package/build/i18n/ja.json +15 -11
  23. package/build/i18n/pl.json +30 -3
  24. package/build/i18n/pt.json +4 -0
  25. package/build/i18n/ro.json +5 -1
  26. package/build/i18n/ru.json +10 -6
  27. package/build/i18n/th.json +6 -2
  28. package/build/i18n/tr.json +30 -3
  29. package/build/i18n/zh-CN.json +8 -4
  30. package/build/i18n/zh.json +4 -0
  31. package/build/index.d.ts +0 -2
  32. package/build/index.js +0 -2
  33. package/build/jsonSchemaForm/JsonSchemaForm.d.ts +2 -3
  34. package/build/jsonSchemaForm/JsonSchemaForm.js +4 -4
  35. package/build/jsonSchemaForm/allOfSchema/AllOfSchema.d.ts +0 -1
  36. package/build/jsonSchemaForm/arrayTypeSchema/ArraySchema.d.ts +0 -1
  37. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.d.ts +0 -1
  38. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.d.ts +0 -1
  39. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.js +5 -5
  40. package/build/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.d.ts +0 -1
  41. package/build/jsonSchemaForm/controlFeedback/ControlFeedback.d.ts +0 -1
  42. package/build/jsonSchemaForm/genericSchema/GenericSchema.d.ts +0 -1
  43. package/build/jsonSchemaForm/help/Help.d.ts +0 -1
  44. package/build/jsonSchemaForm/objectSchema/ObjectSchema.d.ts +0 -1
  45. package/build/jsonSchemaForm/oneOfSchema/OneOfSchema.d.ts +0 -1
  46. package/build/jsonSchemaForm/oneOfSchema/OneOfSchema.js +4 -4
  47. package/build/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.d.ts +0 -1
  48. package/build/jsonSchemaForm/persistAsyncSchema/basic/PersistAsyncBasicSchema.d.ts +0 -1
  49. package/build/jsonSchemaForm/persistAsyncSchema/basic/PersistAsyncBasicSchema.js +5 -5
  50. package/build/jsonSchemaForm/persistAsyncSchema/blob/PersistAsyncBlobSchema.d.ts +0 -1
  51. package/build/jsonSchemaForm/persistAsyncSchema/blob/PersistAsyncBlobSchema.js +4 -4
  52. package/build/jsonSchemaForm/persistAsyncSchema/blob/UploadInputAdapter.d.ts +0 -1
  53. package/build/jsonSchemaForm/persistAsyncSchema/blob/UploadInputAdapter.js +3 -3
  54. package/build/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.d.ts +0 -1
  55. package/build/jsonSchemaForm/promotedOneOfSchema/control/PromotedOneOfCheckboxControl.d.ts +0 -1
  56. package/build/jsonSchemaForm/promotedOneOfSchema/control/PromotedOneOfRadioControl.d.ts +0 -1
  57. package/build/jsonSchemaForm/readOnlySchema/ReadOnlySchema.d.ts +0 -1
  58. package/build/jsonSchemaForm/schemaFormControl/SchemaFormControl.d.ts +0 -1
  59. package/build/jsonSchemaForm/schemaFormControl/optionMapper.d.ts +0 -1
  60. package/build/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.d.ts +0 -1
  61. package/build/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.js +5 -5
  62. package/build/layout/DynamicLayout.d.ts +0 -1
  63. package/build/layout/alert/index.d.ts +0 -1
  64. package/build/layout/box/index.d.ts +0 -1
  65. package/build/layout/button/index.d.ts +0 -1
  66. package/build/layout/columns/index.d.ts +0 -1
  67. package/build/layout/decision/index.d.ts +0 -1
  68. package/build/layout/divider/index.d.ts +0 -1
  69. package/build/layout/external/DynamicExternal.d.ts +0 -1
  70. package/build/layout/form/index.d.ts +0 -1
  71. package/build/layout/heading/index.d.ts +0 -1
  72. package/build/layout/icon/index.d.ts +1 -2
  73. package/build/layout/icon/index.js +3 -2
  74. package/build/layout/image/index.d.ts +0 -1
  75. package/build/layout/image/index.js +7 -2
  76. package/build/layout/info/index.d.ts +0 -1
  77. package/build/layout/list/index.d.ts +0 -1
  78. package/build/layout/loading-indicator/index.d.ts +0 -1
  79. package/build/layout/paragraph/DynamicParagraph.d.ts +0 -1
  80. package/build/layout/review/index.d.ts +0 -1
  81. package/build/main.css +3 -6
  82. package/build/step/cameraStep/CameraStep.d.ts +0 -1
  83. package/build/step/cameraStep/CameraStep.js +3 -3
  84. package/build/step/cameraStep/cameraCapture/CameraCapture.d.ts +3 -4
  85. package/build/step/cameraStep/cameraCapture/CameraCapture.js +6 -6
  86. package/build/step/cameraStep/cameraCapture/components/index.d.ts +0 -1
  87. package/build/step/cameraStep/cameraCapture/overlay/Overlay.d.ts +0 -1
  88. package/build/step/cameraStep/cameraCapture/screens/CameraNotSupported/CameraNotSupported.d.ts +0 -1
  89. package/build/step/cameraStep/cameraCapture/screens/NoCameraAccess/NoCameraAccess.d.ts +0 -1
  90. package/build/step/cameraStep/cameraCapture/tracking/index.d.ts +4 -4
  91. package/build/step/cameraStep/cameraCapture/tracking/index.js +19 -22
  92. package/build/step/externalConfirmationStep/ExternalConfirmationStep.d.ts +0 -1
  93. package/build/step/layoutStep/LayoutStep.d.ts +0 -1
  94. package/build/step/layoutStep/LayoutStep.js +3 -3
  95. package/package.json +44 -51
  96. package/build/common/requirements.d.ts +0 -10
  97. package/build/common/requirements.js +0 -50
  98. package/build/common/tracking/index.d.ts +0 -15
  99. package/build/common/tracking/index.js +0 -33
  100. package/build/field/Field.d.ts +0 -69
  101. package/build/field/Field.js +0 -311
  102. package/build/field/index.d.ts +0 -2
  103. package/build/field/index.js +0 -2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wise/dynamic-flow-client",
3
- "version": "0.2.1",
4
- "description": "Wise Dynamic Flow web client",
3
+ "version": "0.3.0-beta-ec09e7.2",
4
+ "description": "Dynamic Flow web client",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
7
7
  "style": "./build/main.css",
@@ -13,8 +13,25 @@
13
13
  ],
14
14
  "repository": {
15
15
  "type": "git",
16
- "fullname": "transferwise/neptune-web",
17
- "url": "git+https://github.com/transferwise/neptune-web.git"
16
+ "fullname": "transferwise/dynamic-flow",
17
+ "url": "git+https://github.com/transferwise/dynamic-flow.git"
18
+ },
19
+ "scripts": {
20
+ "dev": "storybook dev -p 3003",
21
+ "build": "npm-run-all build:*",
22
+ "build:ts": "tsc --build ./tsconfig.build.json",
23
+ "build:css": "postcss src/main.css -o build/main.css",
24
+ "build:messages-source": "formatjs extract 'src/**/*.messages.{js,ts}' --out-file src/i18n/en.json --format simple && prettier --find-config-path --write src/i18n/*.json",
25
+ "build:compiled-messages": "mkdir -p build/i18n && cp src/i18n/*.json build/i18n",
26
+ "test": "npm-run-all test:once test:tz",
27
+ "test:once": "jest --config jest.config.js --env=jsdom",
28
+ "test:coverage": "jest --config jest.config.js --env=jsdom --coverage",
29
+ "test:tz": "TZ=US/Pacific jest ./src/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.errors.spec.js ./src/formControl/FormControl.spec.js",
30
+ "test:watch": "pnpm test:once --watch",
31
+ "lint": "npm-run-all lint:ts lint:css",
32
+ "lint:ts": "eslint 'src/**/*.{js,jsx,ts,tsx}' --quiet",
33
+ "lint:css": "stylelint './src/**/*.css'",
34
+ "build-storybook": "storybook build -c .storybook"
18
35
  },
19
36
  "devDependencies": {
20
37
  "@babel/core": "7.20.12",
@@ -23,20 +40,20 @@
23
40
  "@babel/preset-env": "7.20.2",
24
41
  "@babel/preset-react": "7.18.6",
25
42
  "@babel/preset-typescript": "7.21.0",
43
+ "@cfaester/enzyme-adapter-react-18": "0.7.0",
26
44
  "@formatjs/cli": "^4.8.3",
27
- "@storybook/addon-a11y": "6.5.16",
28
- "@storybook/addon-actions": "6.5.16",
29
- "@storybook/addon-essentials": "6.5.16",
30
- "@storybook/addon-interactions": "6.5.16",
31
- "@storybook/addon-links": "6.5.16",
32
- "@storybook/builder-webpack5": "6.5.16",
33
- "@storybook/manager-webpack5": "6.5.16",
34
- "@storybook/react": "6.5.16",
35
- "@storybook/testing-library": "0.0.13",
45
+ "@storybook/addon-a11y": "7.0.9",
46
+ "@storybook/addon-actions": "7.0.9",
47
+ "@storybook/addon-essentials": "7.0.9",
48
+ "@storybook/addon-interactions": "7.0.9",
49
+ "@storybook/addon-links": "7.0.9",
50
+ "@storybook/react": "7.0.9",
51
+ "@storybook/react-webpack5": "7.0.9",
52
+ "@storybook/testing-library": "0.1.0",
36
53
  "@testing-library/dom": "9.2.0",
37
54
  "@testing-library/jest-dom": "5.16.5",
38
- "@testing-library/react-hooks": "8.0.1",
39
55
  "@testing-library/react": "14.0.0",
56
+ "@testing-library/react-hooks": "8.0.1",
40
57
  "@testing-library/user-event": "13.2.1",
41
58
  "@transferwise/components": "43.13.49",
42
59
  "@transferwise/eslint-config": "8.0.1",
@@ -46,38 +63,37 @@
46
63
  "@transferwise/neptune-tokens": "8.4.0",
47
64
  "@types/enzyme": "^3.10.12",
48
65
  "@types/jest": "29.4.0",
49
- "@types/lodash.debounce": "^4.0.7",
50
66
  "@types/lodash": "^4.14.167",
51
- "@types/react-dom": "18",
67
+ "@types/lodash.debounce": "^4.0.7",
52
68
  "@types/react": "18",
69
+ "@types/react-dom": "18",
53
70
  "@types/testing-library__jest-dom": "5.9.5",
54
71
  "@wise/art": "2.0.1",
55
72
  "@wise/components-theming": "^0.7.4",
56
- "@cfaester/enzyme-adapter-react-18": "0.7.0",
57
73
  "babel-jest": "29.5.0",
58
- "cpx": "1.5.0",
59
74
  "currency-flags": "4.0.7",
60
75
  "enzyme": "^3.11.0",
61
76
  "eslint": "8.36.0",
77
+ "eslint-plugin-storybook": "0.6.12",
78
+ "jest": "29.5.0",
62
79
  "jest-environment-jsdom": "29.5.0",
63
80
  "jest-fetch-mock": "^3.0.3",
64
81
  "jest-watch-typeahead": "^2.2.2",
65
- "jest": "29.5.0",
66
82
  "npm-run-all": "4.1.5",
83
+ "postcss": "^8.4.21",
67
84
  "postcss-cli": "^10.1.0",
68
85
  "postcss-import": "^15.1.0",
69
- "postcss": "^8.4.21",
70
86
  "prettier": "2.8.4",
87
+ "react": "18.2.0",
71
88
  "react-dom": "18.2.0",
72
89
  "react-intl": "6.2.1",
73
- "react": "18.2.0",
74
- "require-from-string": "2.0.2",
90
+ "storybook": "7.0.9",
91
+ "stylelint": "14.16.1",
75
92
  "stylelint-config-standard": "25.0.0",
76
93
  "stylelint-no-unsupported-browser-features": "5.0.4",
77
94
  "stylelint-value-no-unknown-custom-properties": "4.0.0",
78
- "stylelint": "14.16.1",
79
95
  "typescript": "4.9.5",
80
- "webpack": "5.75.0"
96
+ "webpack": "5.76.0"
81
97
  },
82
98
  "peerDependencies": {
83
99
  "@transferwise/components": "^43",
@@ -85,15 +101,9 @@
85
101
  "@transferwise/icons": "^3",
86
102
  "@transferwise/neptune-css": "^14",
87
103
  "@transferwise/neptune-validation": "^3",
88
- "prop-types": "^15",
104
+ "react": "^18",
89
105
  "react-dom": "^18",
90
- "react-intl": "^6",
91
- "react": "^18"
92
- },
93
- "peerDependenciesMeta": {
94
- "prop-types": {
95
- "optional": true
96
- }
106
+ "react-intl": "^6"
97
107
  },
98
108
  "dependencies": {
99
109
  "classnames": "2.3.2",
@@ -103,22 +113,5 @@
103
113
  "react-webcam": "^7.0.1",
104
114
  "screenfull": "^5.0.2"
105
115
  },
106
- "prettier": "@transferwise/eslint-config/.prettierrc.js",
107
- "scripts": {
108
- "dev": "start-storybook -p 3003",
109
- "build": "npm-run-all build:*",
110
- "build:ts": "tsc --build ./tsconfig.build.json",
111
- "build:css": "postcss src/main.css -o build/main.css",
112
- "build:messages-source": "formatjs extract 'src/**/*.messages.{js,ts}' --out-file src/i18n/en.json --format simple && prettier --find-config-path --write src/i18n/*.json",
113
- "build:compiled-messages": "cpx 'src/i18n/*.json' build/i18n",
114
- "test": "npm-run-all test:once test:tz",
115
- "test:once": "jest --config jest.config.js --env=jsdom",
116
- "test:coverage": "jest --config jest.config.js --env=jsdom --coverage",
117
- "test:tz": "TZ=US/Pacific jest ./src/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.errors.spec.js ./src/formControl/FormControl.spec.js",
118
- "test:watch": "pnpm test:once --watch",
119
- "lint": "npm-run-all lint:ts lint:css",
120
- "lint:ts": "eslint 'src/**/*.{js,jsx,ts,tsx}' --quiet",
121
- "lint:css": "stylelint --allow-empty-input './src/**/*.less'",
122
- "build-storybook": "build-storybook -c .storybook"
123
- }
124
- }
116
+ "prettier": "@transferwise/eslint-config/.prettierrc.js"
117
+ }
@@ -1,10 +0,0 @@
1
- import { FormControlType } from './propsValues/formControlType';
2
- type Field = {
3
- hidden?: boolean;
4
- control?: (typeof FormControlType)[keyof typeof FormControlType];
5
- type: 'string' | 'number' | 'integer' | 'boolean' | 'blob';
6
- options: any[];
7
- format: 'date' | 'phone' | 'base64url' | 'password' | 'email' | 'uri';
8
- };
9
- declare const getControlType_Legacy: (field: Field) => string;
10
- export { getControlType_Legacy };
@@ -1,50 +0,0 @@
1
- var getControlType_Legacy = function (field) {
2
- if (field.control) {
3
- return field.control.toLowerCase();
4
- }
5
- if (field.hidden) {
6
- return 'hidden';
7
- }
8
- if (field.options && field.options.length > 0) {
9
- return getSelectionType(field);
10
- }
11
- switch (field.type) {
12
- case 'string':
13
- return getControlForStringFormat(field.format);
14
- case 'number':
15
- case 'integer':
16
- return 'number';
17
- case 'boolean':
18
- return 'checkbox';
19
- default:
20
- return 'text';
21
- }
22
- };
23
- var getControlForStringFormat = function (format) {
24
- switch (format) {
25
- case 'date':
26
- return 'date';
27
- case 'base64url':
28
- return 'file';
29
- case 'password':
30
- return 'password';
31
- case 'uri':
32
- return 'text'; // 'url'; - not implemented
33
- case 'email':
34
- return 'text'; // 'email'; - not implemented
35
- case 'phone':
36
- return 'tel';
37
- default:
38
- return 'text';
39
- }
40
- };
41
- var getSelectionType = function (field) {
42
- if (field.control) {
43
- return field.control;
44
- }
45
- if (field.options) {
46
- return field.options.length > 3 ? 'select' : 'radio';
47
- }
48
- return 'select';
49
- };
50
- export { getControlType_Legacy };
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- export type TrackableEventName = 'Dynamic Flow - Flow Started' | 'Dynamic Flow - Flow Finished' | 'Dynamic Flow - Step Started' | 'Dynamic Flow - Step Submitted' | 'Dynamic Flow - Step Refreshed' | 'Dynamic Flow - OneOf Selected' | 'Dynamic Flow - PersistAsync' | 'Dynamic Flow - ValidationAsync' | 'Dynamic Flow - Camera Permission Denied' | 'Dynamic Flow - Camera Feed Started' | 'Dynamic Flow - Camera Not Supported' | 'Dynamic Flow - invalid submission response' | 'Dynamic Flow - onAction supressed' | 'Dynamic Flow - OneOf Searched';
3
- export type TrackableEventHandler = (eventName: TrackableEventName, properties: Record<string, unknown>) => void;
4
- type Props = {
5
- metadata?: Record<string, unknown> & {
6
- flowId?: string;
7
- stepId?: string;
8
- };
9
- children: React.ReactNode;
10
- onTrackableEvent: TrackableEventHandler;
11
- };
12
- export declare const TrackingContextProvider: ({ metadata, children, onTrackableEvent }: Props) => JSX.Element;
13
- export declare function useTracking(): TrackableEventHandler;
14
- export declare const getTracker: (onTrackableEvent: TrackableEventHandler, metadata?: Record<string, unknown>) => TrackableEventHandler;
15
- export {};
@@ -1,33 +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 { createContext, useContext, useMemo } from 'react';
14
- var TrackingContext = createContext({
15
- trackEvent: function () {
16
- // noop
17
- }
18
- });
19
- export var TrackingContextProvider = function (_a) {
20
- var metadata = _a.metadata, children = _a.children, onTrackableEvent = _a.onTrackableEvent;
21
- var value = useMemo(function () { return ({ trackEvent: getTracker(onTrackableEvent, metadata) }); }, [onTrackableEvent, metadata]);
22
- return _jsx(TrackingContext.Provider, __assign({ value: value }, { children: children }));
23
- };
24
- export function useTracking() {
25
- var trackEvent = useContext(TrackingContext).trackEvent;
26
- return trackEvent;
27
- }
28
- export var getTracker = function (onTrackableEvent, metadata) {
29
- return function (eventName, properties) {
30
- if (properties === void 0) { properties = {}; }
31
- return onTrackableEvent(eventName, __assign(__assign({}, metadata), properties));
32
- };
33
- };
@@ -1,69 +0,0 @@
1
- export namespace FieldTypes {
2
- const STRING: string;
3
- const NUMBER: string;
4
- const INTEGER: string;
5
- const BOOLEAN: string;
6
- const BLOB: string;
7
- }
8
- export namespace FieldFormats {
9
- const DATE: string;
10
- const PHONE: string;
11
- const BASE_64_URL: string;
12
- const PASSWORD: string;
13
- const EMAIL: string;
14
- const URI: string;
15
- }
16
- declare class Field extends Component<any, any, any> {
17
- constructor(props: any);
18
- state: {
19
- focused: boolean;
20
- changed: boolean;
21
- error: any;
22
- };
23
- UNSAFE_componentWillReceiveProps(nextProps: any): void;
24
- onFocus(value: any): void;
25
- onBlur(value: any): void;
26
- onChange(value: any): void;
27
- validateValue(newValue: any): {};
28
- objectSizeOf: (object: any) => number;
29
- updateAlert(control: any): {
30
- type: string;
31
- content: any;
32
- } | {
33
- type: null;
34
- content: null;
35
- };
36
- render(): JSX.Element;
37
- }
38
- declare namespace Field {
39
- namespace propTypes {
40
- const name: any;
41
- const value: any;
42
- const field: any;
43
- const countryCode: any;
44
- const onChange: any;
45
- const onFocus: any;
46
- const onBlur: any;
47
- const errorMessage: any;
48
- const warningMessage: any;
49
- const label: any;
50
- }
51
- namespace defaultProps {
52
- const countryCode_1: null;
53
- export { countryCode_1 as countryCode };
54
- const value_1: null;
55
- export { value_1 as value };
56
- const errorMessage_1: null;
57
- export { errorMessage_1 as errorMessage };
58
- const warningMessage_1: null;
59
- export { warningMessage_1 as warningMessage };
60
- const onFocus_1: null;
61
- export { onFocus_1 as onFocus };
62
- const onBlur_1: null;
63
- export { onBlur_1 as onBlur };
64
- const label_1: null;
65
- export { label_1 as label };
66
- }
67
- }
68
- export default Field;
69
- import { Component } from "react";
@@ -1,311 +0,0 @@
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, jsxs as _jsxs } from "react/jsx-runtime";
28
- import { InlineAlert, InstructionsList } from '@transferwise/components';
29
- import classNames from 'classnames';
30
- import PropTypes from 'prop-types';
31
- import { Component } from 'react';
32
- import { FormControlType } from '../common';
33
- import { getControlType_Legacy } from '../common/requirements';
34
- import { getValidationFailures } from '../common/validation/validation-failures';
35
- import FormControl from '../formControl';
36
- export var FieldTypes = {
37
- STRING: 'string',
38
- NUMBER: 'number',
39
- INTEGER: 'integer',
40
- BOOLEAN: 'boolean',
41
- BLOB: 'blob'
42
- };
43
- export var FieldFormats = {
44
- DATE: 'date',
45
- PHONE: 'phone',
46
- BASE_64_URL: 'base64url',
47
- PASSWORD: 'password',
48
- EMAIL: 'email',
49
- URI: 'uri'
50
- };
51
- var DefaultValidationMessages = {
52
- REQUIRED: 'Required',
53
- PATTERN: 'Incorrect format',
54
- MINLENGTH: 'The value is too short',
55
- MAXLENGTH: 'The value is too long',
56
- MIN: 'The value is too low',
57
- MAX: 'The value is too high'
58
- };
59
- var Field = /** @class */ (function (_super) {
60
- __extends(Field, _super);
61
- function Field(props) {
62
- var _this = _super.call(this, props) || this;
63
- _this.objectSizeOf = function (object) { return (object ? Object.keys(object).length : 0); };
64
- _this.state = {
65
- focused: false,
66
- changed: false,
67
- error: props.errorMessage
68
- };
69
- return _this;
70
- }
71
- Field.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
72
- if (nextProps.errorMessage !== this.props.errorMessage) {
73
- this.setState({ error: nextProps.errorMessage });
74
- }
75
- };
76
- Field.prototype.onFocus = function (value) {
77
- var onFocus = this.props.onFocus;
78
- if (onFocus) {
79
- onFocus(value);
80
- }
81
- this.setState({ focused: true });
82
- };
83
- Field.prototype.onBlur = function (value) {
84
- var onBlur = this.props.onBlur;
85
- if (onBlur) {
86
- onBlur(value);
87
- }
88
- this.setState({ focused: false });
89
- };
90
- Field.prototype.onChange = function (value) {
91
- this.props.onChange(value);
92
- this.setState({ changed: true, focused: true });
93
- };
94
- Field.prototype.validateValue = function (newValue) {
95
- var field = this.props.field;
96
- var validationFailuresKeys = getValidationFailures(newValue, field);
97
- return validationFailuresKeys.reduce(function (acc, failure) {
98
- var _a;
99
- var messageKey = failure.toLowerCase();
100
- var message = (field.validationMessages && field.validationMessages[messageKey]) ||
101
- DefaultValidationMessages[messageKey.toUpperCase()];
102
- return message
103
- ? __assign(__assign({}, acc), (_a = {}, _a[messageKey] = message, _a)) : acc;
104
- }, {});
105
- };
106
- Field.prototype.updateAlert = function (control) {
107
- var _a = this.props, value = _a.value, field = _a.field, errorMessage = _a.errorMessage, warningMessage = _a.warningMessage;
108
- var _b = this.state, focused = _b.focused, changed = _b.changed, error = _b.error;
109
- var validationFailures = changed && !focused ? this.validateValue(value) : {};
110
- if (this.objectSizeOf(validationFailures) > 0) {
111
- return {
112
- type: 'error',
113
- content: Object.keys(validationFailures).map(function (key) { return (_jsx("div", { children: validationFailures[key] }, key)); })
114
- };
115
- }
116
- if (error && errorMessage) {
117
- return {
118
- type: 'error',
119
- content: _jsx(_Fragment, { children: errorMessage })
120
- };
121
- }
122
- if (warningMessage) {
123
- return {
124
- type: 'warning',
125
- content: _jsx(_Fragment, { children: warningMessage })
126
- };
127
- }
128
- if (focused && field.help && field.help.message) {
129
- return {
130
- type: 'info',
131
- content: _jsx(_Fragment, { children: field.help.message })
132
- };
133
- }
134
- if (focused && field.help && field.help.list && field.help.list.length > 0) {
135
- return {
136
- type: 'info',
137
- // eslint-disable-next-line react/no-array-index-key
138
- content: field.help.list.map(function (item, index) { return _jsx("div", { children: item }, index); })
139
- };
140
- }
141
- if (focused &&
142
- field.help &&
143
- field.help["do"] &&
144
- field.help["do"].length > 0 &&
145
- field.help.dont &&
146
- field.help.dont.length > 0) {
147
- return {
148
- type: 'info',
149
- content: (_jsx("div", __assign({ className: "m-b-1" }, { children: _jsx(InstructionsList, { dos: field.help["do"], donts: field.help.dont }) })))
150
- };
151
- }
152
- if (focused && control !== FormControlType.FILE && field.help && field.help.image) {
153
- return {
154
- type: 'info',
155
- content: _jsx("img", { className: "thumbnail m-y-2", src: "".concat(field.help.image), alt: field.label })
156
- };
157
- }
158
- return {
159
- type: null,
160
- content: null
161
- };
162
- };
163
- Field.prototype.render = function () {
164
- var _this = this;
165
- var _a = this.props, name = _a.name, field = _a.field, value = _a.value, label = _a.label;
166
- var control = field.control || getControlType_Legacy(field);
167
- var alert = this.updateAlert(control);
168
- var showAlert = !!alert.content;
169
- var showLabel = control !== FormControlType.FILE &&
170
- control !== FormControlType.UPLOAD &&
171
- control !== FormControlType.CHECKBOX;
172
- return (_jsxs("div", __assign({ className: classNames('form-group', "tw-field-".concat(name), {
173
- 'has-info': alert.type === 'info' && showAlert,
174
- 'has-error': alert.type === 'error' && showAlert,
175
- 'has-warning': alert.type === 'warning' && showAlert,
176
- hidden: field.hidden
177
- }) }, { children: [showLabel && (_jsx("label", __assign({ htmlFor: field === null || field === void 0 ? void 0 : field.id, className: "control-label" }, { children: label }))), _jsx(FormControl, __assign({}, field, { type: control, name: name, value: value, onChange: function (event) { return _this.onChange(event); }, onFocus: function (event) { return _this.onFocus(event); }, onBlur: function (event) { return _this.onBlur(event); } })), showAlert && _jsx(InlineAlert, __assign({ type: alert.type }, { children: alert.content }))] })));
178
- };
179
- return Field;
180
- }(Component));
181
- export default Field;
182
- Field.propTypes = {
183
- name: PropTypes.string.isRequired,
184
- value: PropTypes.oneOfType([
185
- PropTypes.string,
186
- PropTypes.number,
187
- PropTypes.bool,
188
- PropTypes.object,
189
- PropTypes.shape({
190
- // eslint-disable-next-line react/forbid-prop-types
191
- value: PropTypes.any.isRequired,
192
- label: PropTypes.node,
193
- icon: PropTypes.string,
194
- currency: PropTypes.string,
195
- note: PropTypes.node,
196
- secondary: PropTypes.node
197
- }),
198
- ]),
199
- field: PropTypes.shape({
200
- type: PropTypes.oneOf(['string', 'number', 'integer', 'boolean', 'blob']).isRequired,
201
- label: PropTypes.string,
202
- id: PropTypes.string,
203
- required: PropTypes.bool,
204
- disabled: PropTypes.bool,
205
- hidden: PropTypes.bool,
206
- readOnly: PropTypes.bool,
207
- autoComplete: PropTypes.bool,
208
- placeholder: PropTypes.string,
209
- searchPlaceholder: PropTypes.string,
210
- control: PropTypes.oneOf([
211
- 'radio',
212
- 'checkbox',
213
- 'select',
214
- 'file',
215
- 'date',
216
- 'date-time',
217
- 'date-lookup',
218
- 'tel',
219
- 'number',
220
- 'hidden',
221
- 'password',
222
- 'text',
223
- 'textarea',
224
- 'upload',
225
- 'tab',
226
- ]),
227
- format: PropTypes.oneOf(['date', 'phone', 'base64url', 'password', 'email', 'uri']),
228
- displayPattern: PropTypes.string,
229
- help: PropTypes.shape({
230
- message: PropTypes.string,
231
- image: PropTypes.string,
232
- list: PropTypes.arrayOf(PropTypes.string),
233
- "do": PropTypes.arrayOf(PropTypes.string),
234
- dont: PropTypes.arrayOf(PropTypes.string)
235
- }),
236
- pattern: PropTypes.string,
237
- minLength: PropTypes.number,
238
- maxLength: PropTypes.number,
239
- minDate: PropTypes.instanceOf(Date),
240
- maxDate: PropTypes.instanceOf(Date),
241
- min: PropTypes.number,
242
- max: PropTypes.number,
243
- uploadProps: PropTypes.shape({
244
- animationDelay: PropTypes.number,
245
- csButtonText: PropTypes.string,
246
- csFailureText: PropTypes.string,
247
- csSuccessText: PropTypes.string,
248
- csTooLargeMessage: PropTypes.string,
249
- csWrongTypeMessage: PropTypes.string,
250
- httpOptions: PropTypes.shape({}),
251
- maxSize: PropTypes.number,
252
- onCancel: PropTypes.func,
253
- onFailure: PropTypes.func,
254
- onStart: PropTypes.func,
255
- onSuccess: PropTypes.func,
256
- psButtonText: PropTypes.string,
257
- psProcessingText: PropTypes.string,
258
- size: PropTypes.string,
259
- usAccept: PropTypes.oneOf(['*', 'image/*', 'application/*']),
260
- usButtonText: PropTypes.string,
261
- usDisabled: PropTypes.bool,
262
- usDropMessage: PropTypes.string,
263
- usHelpImage: PropTypes.string,
264
- usLabel: PropTypes.string,
265
- usPlaceholder: PropTypes.string
266
- }),
267
- options: PropTypes.arrayOf(PropTypes.shape({
268
- id: PropTypes.string,
269
- label: PropTypes.oneOfType([PropTypes.node, PropTypes.string]).isRequired,
270
- value: PropTypes.oneOfType([
271
- PropTypes.number,
272
- PropTypes.string,
273
- PropTypes.bool,
274
- PropTypes.object,
275
- PropTypes.instanceOf(Date),
276
- ]).isRequired,
277
- header: PropTypes.node,
278
- icon: PropTypes.string,
279
- currency: PropTypes.string,
280
- note: PropTypes.node,
281
- secondary: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
282
- separator: PropTypes.bool,
283
- disabled: PropTypes.bool
284
- })),
285
- size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
286
- validationMessages: PropTypes.shape({
287
- required: PropTypes.string,
288
- pattern: PropTypes.string,
289
- minlength: PropTypes.string,
290
- maxlength: PropTypes.string,
291
- min: PropTypes.string,
292
- max: PropTypes.string
293
- })
294
- }).isRequired,
295
- countryCode: PropTypes.string,
296
- onChange: PropTypes.func.isRequired,
297
- onFocus: PropTypes.func,
298
- onBlur: PropTypes.func,
299
- errorMessage: PropTypes.string,
300
- warningMessage: PropTypes.string,
301
- label: PropTypes.oneOfType([PropTypes.string, PropTypes.node])
302
- };
303
- Field.defaultProps = {
304
- countryCode: null,
305
- value: null,
306
- errorMessage: null,
307
- warningMessage: null,
308
- onFocus: null,
309
- onBlur: null,
310
- label: null
311
- };
@@ -1,2 +0,0 @@
1
- import Field from './Field';
2
- export default Field;
@@ -1,2 +0,0 @@
1
- import Field from './Field';
2
- export default Field;