@evoke-platform/ui-components 1.0.0-dev.124 → 1.0.0-dev.125

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 (26) hide show
  1. package/dist/published/form-components/Buttons.d.ts +5 -3
  2. package/dist/published/form-components/Buttons.js +21 -10
  3. package/dist/published/form-components/FieldWrapper.js +4 -4
  4. package/dist/published/form-components/FormFieldComponent.d.ts +34 -0
  5. package/dist/published/form-components/FormFieldComponent.js +160 -0
  6. package/dist/published/form-components/index.d.ts +2 -18
  7. package/dist/published/form-components/index.js +2 -18
  8. package/package.json +5 -4
  9. package/dist/published/form-components/Boolean.d.ts +0 -16
  10. package/dist/published/form-components/Boolean.js +0 -22
  11. package/dist/published/form-components/Button.d.ts +0 -8
  12. package/dist/published/form-components/Button.js +0 -30
  13. package/dist/published/form-components/Date.d.ts +0 -17
  14. package/dist/published/form-components/Date.js +0 -44
  15. package/dist/published/form-components/DateTime.d.ts +0 -16
  16. package/dist/published/form-components/DateTime.js +0 -22
  17. package/dist/published/form-components/Decimal.d.ts +0 -16
  18. package/dist/published/form-components/Decimal.js +0 -35
  19. package/dist/published/form-components/Integer.d.ts +0 -16
  20. package/dist/published/form-components/Integer.js +0 -34
  21. package/dist/published/form-components/Select.d.ts +0 -16
  22. package/dist/published/form-components/Select.js +0 -22
  23. package/dist/published/form-components/SharedCustomizations.d.ts +0 -32
  24. package/dist/published/form-components/SharedCustomizations.js +0 -59
  25. package/dist/published/form-components/Text.d.ts +0 -17
  26. package/dist/published/form-components/Text.js +0 -80
@@ -1,8 +1,10 @@
1
- declare const ButtonComponent: any;
2
- declare class Buttons extends ButtonComponent {
1
+ import { ReactComponent } from '@formio/react';
2
+ declare class Buttons extends ReactComponent {
3
+ [x: string]: any;
3
4
  constructor(component: any, options: any, data: any);
5
+ init(): void;
4
6
  handleCancel: (event: any) => void;
5
7
  handleSubmit: (event: any) => void;
6
- attach(element: any): void;
8
+ attachReact(element: any): void;
7
9
  }
8
10
  export default Buttons;
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import { Components } from 'formiojs';
3
- import ReactDOMClient from 'react-dom/client';
4
2
  import { Button as EvokeButton } from '../components/core';
5
- const ButtonComponent = Components.components.button;
6
- class Buttons extends ButtonComponent {
3
+ import { ReactComponent } from '@formio/react';
4
+ import ReactDOM from 'react-dom';
5
+ import { cloneDeep, isEmpty, isEqual } from 'lodash';
6
+ class Buttons extends ReactComponent {
7
7
  constructor(component, options, data) {
8
8
  super(component, options, data);
9
9
  this.handleCancel = (event) => {
@@ -11,16 +11,27 @@ class Buttons extends ButtonComponent {
11
11
  };
12
12
  this.handleSubmit = (event) => {
13
13
  const submission = this.root.getValue();
14
- this.component.components[1].onSubmit(submission);
15
- this.onSubmit();
14
+ this.emit('submitButton', submission);
15
+ if (isEmpty([...this.root.errors, ...this.root.customErrors])) {
16
+ this.component.components[1].onSubmit(submission);
17
+ }
16
18
  };
17
19
  this.handleCancel = this.handleCancel.bind(this);
18
20
  this.handleSubmit = this.handleSubmit.bind(this);
19
21
  }
20
- attach(element) {
21
- ReactDOMClient.createRoot(element).render(React.createElement("div", { style: { width: '100%', display: 'flex', justifyContent: 'flex-end' } },
22
- React.createElement(EvokeButton, { sx: { margin: '5px' }, variant: this.component.components[0].variant, onClick: this.handleCancel }, this.component.components[0].label),
23
- React.createElement(EvokeButton, { sx: { margin: '5px' }, variant: this.component.components[1].variant, onClick: this.handleSubmit }, this.component.components[1].label)));
22
+ init() {
23
+ const originalData = cloneDeep(this.root.data);
24
+ this.on('change', () => {
25
+ if (!isEqual(originalData, this.root.data)) {
26
+ this.root.formEdited = true;
27
+ this.attachReact(this.element);
28
+ }
29
+ });
30
+ }
31
+ attachReact(element) {
32
+ return ReactDOM.render(React.createElement("div", { style: { width: '100%', display: 'flex', justifyContent: 'flex-end' } },
33
+ React.createElement(EvokeButton, { sx: { margin: '5px' }, variant: this.component.components[0].variant, onClick: this.handleCancel, disabled: !this.root.formEdited }, this.component.components[0].label),
34
+ React.createElement(EvokeButton, { sx: { margin: '5px' }, variant: this.component.components[1].variant, onClick: this.handleSubmit, disabled: !this.root.formEdited }, this.component.components[1].label)), element);
24
35
  }
25
36
  }
26
37
  export default Buttons;
@@ -1,7 +1,7 @@
1
- import React, { useEffect, useRef } from 'react';
1
+ import { Typography, Tooltip, IconButton } from '../components/core';
2
2
  import { Box } from '../components/layout';
3
- import { IconButton, Tooltip, Typography } from '../components/core';
4
3
  import { Help } from '../icons';
4
+ import React, { useEffect, useRef } from 'react';
5
5
  const PrefixSuffix = (props) => {
6
6
  const { prefix, suffix, height } = props;
7
7
  const text = prefix || suffix;
@@ -52,10 +52,10 @@ const FieldWrapper = (props) => {
52
52
  if (maxLength)
53
53
  charCount = maxLength - charCount;
54
54
  const handleChange = (key, value) => {
55
- onChange(key, value);
55
+ onChange(key, value, new Event('keydown'));
56
56
  setFieldValue(value);
57
57
  };
58
- return (React.createElement(Box, { sx: { margin: '10px' } },
58
+ return (React.createElement(Box, null,
59
59
  React.createElement(Box, null,
60
60
  React.createElement(Typography, { sx: { fontWeight: 600 }, variant: "subtitle2" },
61
61
  label,
@@ -0,0 +1,34 @@
1
+ import { ReactComponent } from '@formio/react';
2
+ declare class FormFieldComponent extends ReactComponent {
3
+ [x: string]: any;
4
+ static schema: any;
5
+ errorDetails: any;
6
+ /**
7
+ * Called when the component has been instantiated. This is useful to define
8
+ * default instance variable values.
9
+ *
10
+ * @param component - The JSON representation of the component created.
11
+ * @param options - The global options for the renderer
12
+ * @param data - The contextual data object (model) used for this component.
13
+ */
14
+ constructor(component: any, options: any, data: any);
15
+ init(): void;
16
+ handleValidation(value: string): void;
17
+ hasCustomErrors(): boolean;
18
+ manageFormErrors(): void;
19
+ beforeSubmit(): void;
20
+ /**
21
+ * Checks for errors in the data value.
22
+ * @param {any} data - The data value to check.
23
+ * @param {boolean} dirty - Whether the data value has been modified.
24
+ * @param {any} rowData - The row data.
25
+ * @returns {{ hasErrors: boolean, fieldErrorMessages: string[] }} An object containing whether the data value has errors and an array of error messages.
26
+ */
27
+ errorCheck(data: any, dirty: any, rowData: any): {
28
+ hasErrors: boolean;
29
+ fieldErrorMessages: any[];
30
+ };
31
+ handleChange: (key: string, value: any, event: Event) => void;
32
+ attachReact(element: any): void;
33
+ }
34
+ export default FormFieldComponent;
@@ -0,0 +1,160 @@
1
+ import React from 'react';
2
+ import { FormField } from '../components/custom';
3
+ import FieldWrapper from './FieldWrapper';
4
+ import { isEmpty } from 'lodash';
5
+ import ReactDOM from 'react-dom';
6
+ import { ReactComponent } from '@formio/react';
7
+ class FormFieldComponent extends ReactComponent {
8
+ /**
9
+ * Called when the component has been instantiated. This is useful to define
10
+ * default instance variable values.
11
+ *
12
+ * @param component - The JSON representation of the component created.
13
+ * @param options - The global options for the renderer
14
+ * @param data - The contextual data object (model) used for this component.
15
+ */
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ constructor(component, options, data) {
18
+ const { property } = component;
19
+ component.property = Object.assign(Object.assign({}, component.property), { type: property.type === 'string' && property.enum ? 'choices' : property.type });
20
+ let selectOptions = [];
21
+ if (!isEmpty(component.data)) {
22
+ selectOptions = component.data.values;
23
+ }
24
+ else if (property.enum) {
25
+ selectOptions = property.enum.map((val) => ({ label: val, value: val }));
26
+ }
27
+ super(Object.assign(Object.assign({}, component), { hideLabel: true, readOnly: component.readOnlyValue || !!property.formula, selectOptions }), options, data);
28
+ this.handleChange = (key, value, event) => {
29
+ event.stopPropagation();
30
+ const val = typeof value === 'object' && value.hasOwnProperty('value') ? value.value : value;
31
+ this.updateValue(val, { modified: true });
32
+ this.emit('changed-' + this.component.key, val);
33
+ this.handleValidation(val);
34
+ this.attachReact(this.element);
35
+ };
36
+ this.errorDetails = {};
37
+ this.handleChange = this.handleChange.bind(this);
38
+ }
39
+ init() {
40
+ const { conditional: { when, eq }, } = this.component;
41
+ //listens for the this.emit('changed-'... event on the 'when' component
42
+ this.on('changed-' + when, (value) => {
43
+ if (when && eq && value === eq) {
44
+ this.component.hidden = false;
45
+ this.attachReact(this.element);
46
+ }
47
+ });
48
+ }
49
+ handleValidation(value) {
50
+ const { validate } = this.component;
51
+ if ((value === undefined || value === null || value === '') && !validate.required) {
52
+ return;
53
+ }
54
+ if (!isEmpty(validate.regexes)) {
55
+ const regexes = validate.regexes;
56
+ const failedRules = validate.regexes.filter((rule) => {
57
+ if (!RegExp(rule.regex).test(value)) {
58
+ return true;
59
+ }
60
+ return false;
61
+ });
62
+ if (failedRules.length === 0) {
63
+ delete this.errorDetails['regexes'];
64
+ }
65
+ else {
66
+ if (validate.operator === 'all') {
67
+ this.errorDetails['regexes'] = failedRules.map((rule) => rule.errorMessage).join(' and ');
68
+ }
69
+ else if (validate.operator === 'any') {
70
+ if (regexes.length > failedRules.length) {
71
+ delete this.errorDetails['regexes'];
72
+ }
73
+ else {
74
+ this.errorDetails['regexes'] = failedRules.map((rule) => rule.errorMessage).join(' or ');
75
+ }
76
+ }
77
+ }
78
+ }
79
+ if (this.component.validate.minDate) {
80
+ if (value < this.component.validate.minDate || value > this.component.validate.maxDate) {
81
+ this.errorDetails['date'] = this.component.validate.customMessage;
82
+ }
83
+ else {
84
+ delete this.errorDetails['date'];
85
+ }
86
+ }
87
+ if (this.component.validate.min && value < this.component.validate.min) {
88
+ this.errorDetails['min-max'] = this.component.validate.customMessage;
89
+ }
90
+ else if (this.component.validate.max && value > this.component.validate.max) {
91
+ this.errorDetails['min-max'] = this.component.validate.customMessage;
92
+ }
93
+ else {
94
+ delete this.errorDetails['min-max'];
95
+ }
96
+ this.manageFormErrors();
97
+ }
98
+ hasCustomErrors() {
99
+ return !isEmpty(this.errorDetails);
100
+ }
101
+ manageFormErrors() {
102
+ if (!isEmpty(this.errorDetails)) {
103
+ const fieldError = {
104
+ component: this.component,
105
+ external: false,
106
+ formattedKeyOrPath: this.component.key,
107
+ message: this.component.label + ': ' + Object.values(this.errorDetails).join(', '),
108
+ };
109
+ const rootHasErrorData = this.root.customErrors.some((error) => {
110
+ return error.formattedKeyOrPath === this.component.key;
111
+ });
112
+ if (!rootHasErrorData) {
113
+ this.root.customErrors = [...this.root.customErrors, fieldError];
114
+ }
115
+ }
116
+ else {
117
+ this.root.customErrors = this.root.customErrors.filter((error) => {
118
+ return error.formattedKeyOrPath !== this.component.key;
119
+ });
120
+ }
121
+ }
122
+ beforeSubmit() {
123
+ this.handleValidation(this.dataValue);
124
+ this.attachReact(this.element);
125
+ }
126
+ /**
127
+ * Checks for errors in the data value.
128
+ * @param {any} data - The data value to check.
129
+ * @param {boolean} dirty - Whether the data value has been modified.
130
+ * @param {any} rowData - The row data.
131
+ * @returns {{ hasErrors: boolean, fieldErrorMessages: string[] }} An object containing whether the data value has errors and an array of error messages.
132
+ */
133
+ errorCheck(data, dirty, rowData) {
134
+ //after changes, check for both custom errors and formio errors
135
+ if (this.dataValue !== this.defaultValue && !this.component.readOnlyValue) {
136
+ return {
137
+ hasErrors: this.hasCustomErrors() || !super.checkValidity(data, dirty, rowData),
138
+ fieldErrorMessages: [...this.root.errors, ...this.root.customErrors]
139
+ .filter((error) => error.component.key === this.component.key)
140
+ .map((error) => error.message),
141
+ };
142
+ }
143
+ return {
144
+ hasErrors: false,
145
+ fieldErrorMessages: [],
146
+ };
147
+ }
148
+ attachReact(element) {
149
+ var _a;
150
+ const { inputMask, hidden } = this.component;
151
+ const { hasErrors, fieldErrorMessages } = this.errorCheck(this.dataValue, false, this.data);
152
+ let root = ReactDOM.findDOMNode(element);
153
+ if (!root) {
154
+ root = element;
155
+ }
156
+ return ReactDOM.render(React.createElement("div", null, !hidden ? (React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, error: hasErrors, errorMessage: fieldErrorMessages.join(', ') }),
157
+ React.createElement(FormField, Object.assign({}, this.component, { defaultValue: (_a = this.dataValue) !== null && _a !== void 0 ? _a : this.component.defaultValue, mask: inputMask, error: hasErrors })))) : null), root);
158
+ }
159
+ }
160
+ export default FormFieldComponent;
@@ -1,23 +1,8 @@
1
1
  /// <reference types="react" />
2
- import Boolean from './Boolean';
3
- import DateTime from './DateTime';
4
- import DateField from './Date';
5
- import Select from './Select';
6
- import Text from './Text';
7
- import Decimal from './Decimal';
8
- import Integer from './Integer';
2
+ import FormFieldComponent from './FormFieldComponent';
9
3
  import Buttons from './Buttons';
10
- import Button from './Button';
11
- import { addSharedCustomizations } from './SharedCustomizations';
12
4
  export declare const FormComponents: {
13
- Boolean: typeof Boolean;
14
- DateTime: typeof DateTime;
15
- DateField: typeof DateField;
16
- Select: typeof Select;
17
- Text: typeof Text;
18
- Decimal: typeof Decimal;
19
- Integer: typeof Integer;
20
- Button: typeof Button;
5
+ FormFieldComponent: typeof FormFieldComponent;
21
6
  Buttons: typeof Buttons;
22
7
  FieldWrapper: (props: {
23
8
  label: string;
@@ -33,5 +18,4 @@ export declare const FormComponents: {
33
18
  onChange: Function;
34
19
  children: any;
35
20
  }) => JSX.Element;
36
- addSharedCustomizations: typeof addSharedCustomizations;
37
21
  };
@@ -1,24 +1,8 @@
1
- import Boolean from './Boolean';
2
- import DateTime from './DateTime';
3
- import DateField from './Date';
4
- import Select from './Select';
5
- import Text from './Text';
6
- import Decimal from './Decimal';
7
- import Integer from './Integer';
1
+ import FormFieldComponent from './FormFieldComponent';
8
2
  import Buttons from './Buttons';
9
- import Button from './Button';
10
- import { addSharedCustomizations } from './SharedCustomizations';
11
3
  import FieldWrapper from './FieldWrapper';
12
4
  export const FormComponents = {
13
- Boolean,
14
- DateTime,
15
- DateField,
16
- Select,
17
- Text,
18
- Decimal,
19
- Integer,
20
- Button,
5
+ FormFieldComponent,
21
6
  Buttons,
22
7
  FieldWrapper,
23
- addSharedCustomizations,
24
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.0.0-dev.124",
3
+ "version": "1.0.0-dev.125",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",
@@ -63,6 +63,7 @@
63
63
  "@dnd-kit/sortable": "^7.0.1",
64
64
  "@emotion/react": "^11.9.0",
65
65
  "@emotion/styled": "^11.8.1",
66
+ "@formio/react": "^5.2.4-rc.1",
66
67
  "@js-joda/core": "^3.2.0",
67
68
  "@js-joda/locale_en-us": "^3.2.2",
68
69
  "@mui/icons-material": "^5.8.4",
@@ -72,13 +73,13 @@
72
73
  "@mui/x-date-pickers": "^5.0.13",
73
74
  "@react-querybuilder/dnd": "^5.4.1",
74
75
  "@react-querybuilder/material": "^5.4.1",
76
+ "@types/react-input-mask": "^3.0.2",
75
77
  "formiojs": "^4.15.0-rc.23",
76
78
  "lodash-es": "^4.17.21",
77
79
  "react-dropzone": "^14.2.2",
78
80
  "react-input-mask": "^2.0.4",
79
- "@types/react-input-mask": "^3.0.2",
80
- "react-querybuilder": "^6.0.2",
81
- "react-number-format": "^4.9.3"
81
+ "react-number-format": "^4.9.3",
82
+ "react-querybuilder": "^6.0.2"
82
83
  },
83
84
  "lint-staged": {
84
85
  "*": "prettier --write"
@@ -1,16 +0,0 @@
1
- declare const Select: {
2
- new (component: any, options: any, data: any): {
3
- [x: string]: any;
4
- errorDetails: any;
5
- conditionallyHidden(): any;
6
- validateRequired(value: any): void;
7
- renderComponentToElement(component: any, element: any): void;
8
- };
9
- [x: string]: any;
10
- };
11
- declare class Boolean extends Select {
12
- constructor(component: any, options: any, data: any);
13
- handleChange: (key: string, value: string) => void;
14
- attach(element: Element): void;
15
- }
16
- export default Boolean;
@@ -1,22 +0,0 @@
1
- import React from 'react';
2
- import { Components } from 'formiojs';
3
- import FieldWrapper from './FieldWrapper';
4
- import { FormField } from '../components/custom';
5
- import { addSharedCustomizations } from './SharedCustomizations';
6
- const Select = addSharedCustomizations(Components.components.select);
7
- class Boolean extends Select {
8
- constructor(component, options, data) {
9
- super(component, options, data);
10
- this.handleChange = (key, value) => {
11
- this.validateRequired(value);
12
- super.setValue(value, {});
13
- };
14
- this.handleChange = this.handleChange.bind(this);
15
- }
16
- attach(element) {
17
- this.renderComponentToElement(React.createElement("div", null, !this.conditionallyHidden() && (React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorDetails: this.errorDetails }),
18
- React.createElement(FormField, Object.assign({}, this.component, { errorMessage: Object.values(this.errorDetails).join(', '), min: this.component.validate.min, max: this.component.validate.max }))))), element);
19
- super.attach(element);
20
- }
21
- }
22
- export default Boolean;
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- declare const FormIOButton: import("formiojs").ClassWithEditForm<typeof import("formiojs/types/components/_classes/field/field").Field>;
3
- declare class CustomButton extends FormIOButton {
4
- constructor(component: any, options: any, data: any);
5
- render(): JSX.Element;
6
- attach(element: Element): void;
7
- }
8
- export default CustomButton;
@@ -1,30 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import React from 'react';
13
- import { Components } from 'formiojs';
14
- import ReactDOMClient from 'react-dom/client';
15
- import { Button } from '../components/core';
16
- const FormIOButton = Components.components.button;
17
- class CustomButton extends FormIOButton {
18
- constructor(component, options, data) {
19
- super(component, options, data);
20
- }
21
- render() {
22
- const _a = this.component, { label } = _a, rest = __rest(_a, ["label"]);
23
- return (React.createElement("div", null,
24
- React.createElement(Button, Object.assign({}, rest), label)));
25
- }
26
- attach(element) {
27
- ReactDOMClient.createRoot(element).render(this.render());
28
- }
29
- }
30
- export default CustomButton;
@@ -1,17 +0,0 @@
1
- declare const DateTime: {
2
- new (component: any, options: any, data: any): {
3
- [x: string]: any;
4
- errorDetails: any;
5
- conditionallyHidden(): any;
6
- validateRequired(value: any): void;
7
- renderComponentToElement(component: any, element: any): void;
8
- };
9
- [x: string]: any;
10
- };
11
- declare class DateField extends DateTime {
12
- constructor(component: any, options: any, data: any);
13
- handleValidation: (value: string) => void;
14
- handleChange: (key: string, value: string) => void;
15
- attach(element: Element): void;
16
- }
17
- export default DateField;
@@ -1,44 +0,0 @@
1
- import React from 'react';
2
- import { Components } from 'formiojs';
3
- import FieldWrapper from './FieldWrapper';
4
- import { FormField } from '../components/custom';
5
- import { addSharedCustomizations } from './SharedCustomizations';
6
- const DateTime = addSharedCustomizations(Components.components.datetime);
7
- class DateField extends DateTime {
8
- constructor(component, options, data) {
9
- super(component, options, data);
10
- this.handleValidation = (value) => {
11
- if (this.component.validate.minDate) {
12
- if (value < this.component.validate.minDate) {
13
- this.errorDetails['minDate'] =
14
- 'Date must be after ' + new Date(this.component.validate.minDate).toLocaleDateString();
15
- }
16
- else {
17
- delete this.errorDetails['minDate'];
18
- }
19
- }
20
- if (this.component.validate.maxDate) {
21
- if (value > this.component.validate.maxDate) {
22
- this.errorDetails['maxDate'] =
23
- 'Date must be before ' + new Date(this.component.validate.maxDate).toLocaleDateString();
24
- }
25
- else {
26
- delete this.errorDetails['maxDate'];
27
- }
28
- }
29
- this.validateRequired(value);
30
- };
31
- this.handleChange = (key, value) => {
32
- super.setValue(value, {});
33
- this.handleValidation(value);
34
- this.attach(this.element);
35
- };
36
- this.handleChange = this.handleChange.bind(this);
37
- }
38
- attach(element) {
39
- this.renderComponentToElement(React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorMessage: Object.values(this.errorDetails).join(', ') }),
40
- React.createElement(FormField, Object.assign({}, this.component))), element);
41
- super.attach(element);
42
- }
43
- }
44
- export default DateField;
@@ -1,16 +0,0 @@
1
- declare const DateTimeFormIO: {
2
- new (component: any, options: any, data: any): {
3
- [x: string]: any;
4
- errorDetails: any;
5
- conditionallyHidden(): any;
6
- validateRequired(value: any): void;
7
- renderComponentToElement(component: any, element: any): void;
8
- };
9
- [x: string]: any;
10
- };
11
- declare class DateTime extends DateTimeFormIO {
12
- constructor(component: any, options: any, data: any);
13
- handleChange: (key: string, value: string) => void;
14
- attach(element: Element): void;
15
- }
16
- export default DateTime;
@@ -1,22 +0,0 @@
1
- import React from 'react';
2
- import { Components } from 'formiojs';
3
- import { FormField } from '../components/custom';
4
- import { addSharedCustomizations } from './SharedCustomizations';
5
- import FieldWrapper from './FieldWrapper';
6
- const DateTimeFormIO = addSharedCustomizations(Components.components.datetime);
7
- class DateTime extends DateTimeFormIO {
8
- constructor(component, options, data) {
9
- super(component, options, data);
10
- this.handleChange = (key, value) => {
11
- this.validateRequired(value);
12
- super.setValue(value, {});
13
- };
14
- this.handleChange = this.handleChange.bind(this);
15
- }
16
- attach(element) {
17
- this.renderComponentToElement(React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorMessage: Object.values(this.errorDetails).join(', ') }),
18
- React.createElement(FormField, Object.assign({}, this.component))), element);
19
- super.attach(element);
20
- }
21
- }
22
- export default DateTime;
@@ -1,16 +0,0 @@
1
- declare const Number: {
2
- new (component: any, options: any, data: any): {
3
- [x: string]: any;
4
- errorDetails: any;
5
- conditionallyHidden(): any;
6
- validateRequired(value: any): void;
7
- renderComponentToElement(component: any, element: any): void;
8
- };
9
- [x: string]: any;
10
- };
11
- declare class Decimal extends Number {
12
- constructor(component: any, options: any, data: any);
13
- handleChange: (key: string, value: string) => void;
14
- attach(element: Element): void;
15
- }
16
- export default Decimal;
@@ -1,35 +0,0 @@
1
- import React from 'react';
2
- import { Components } from 'formiojs';
3
- import FieldWrapper from './FieldWrapper';
4
- import { FormField } from '../components/custom';
5
- import { addSharedCustomizations } from './SharedCustomizations';
6
- const Number = addSharedCustomizations(Components.components.number);
7
- class Decimal extends Number {
8
- constructor(component, options, data) {
9
- super(component, options, data);
10
- this.handleChange = (key, value) => {
11
- super.setValue(value, {});
12
- if (this.component.validate.min && value < this.component.validate.min) {
13
- this.errorDetails['min'] = `Min value is ${this.component.validate.min}`;
14
- }
15
- else {
16
- delete this.errorDetails['min'];
17
- }
18
- if (this.component.validate.max && value > this.component.validate.max) {
19
- this.errorDetails['max'] = `Max value is ${this.component.validate.max}`;
20
- }
21
- else {
22
- delete this.errorDetails['max'];
23
- }
24
- this.validateRequired(value);
25
- this.attach(this.element);
26
- };
27
- this.handleChange = this.handleChange.bind(this);
28
- }
29
- attach(element) {
30
- this.renderComponentToElement(React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorDetails: this.errorDetails }),
31
- React.createElement(FormField, Object.assign({}, this.component, { errorMessage: Object.values(this.errorDetails).join(', ') }))), element);
32
- super.attach(element);
33
- }
34
- }
35
- export default Decimal;
@@ -1,16 +0,0 @@
1
- declare const Number: {
2
- new (component: any, options: any, data: any): {
3
- [x: string]: any;
4
- errorDetails: any;
5
- conditionallyHidden(): any;
6
- validateRequired(value: any): void;
7
- renderComponentToElement(component: any, element: any): void;
8
- };
9
- [x: string]: any;
10
- };
11
- declare class Integer extends Number {
12
- constructor(component: any, options: any, data: any);
13
- handleChange: (key: string, value: string) => void;
14
- attach(element: Element): void;
15
- }
16
- export default Integer;
@@ -1,34 +0,0 @@
1
- import React from 'react';
2
- import { Components } from 'formiojs';
3
- import FieldWrapper from './FieldWrapper';
4
- import { FormField } from '../components/custom';
5
- import { addSharedCustomizations } from './SharedCustomizations';
6
- const Number = addSharedCustomizations(Components.components.number);
7
- class Integer extends Number {
8
- constructor(component, options, data) {
9
- super(component, options, data);
10
- this.handleChange = (key, value) => {
11
- super.setValue(value, {});
12
- if (this.component.validate.min && value < this.component.validate.min) {
13
- this.errorDetails['min'] = `Min value is ${this.component.validate.min}`;
14
- }
15
- else {
16
- delete this.errorDetails['min'];
17
- }
18
- if (this.component.validate.max && value > this.component.validate.max) {
19
- this.errorDetails['max'] = `Max value is ${this.component.validate.max}`;
20
- }
21
- else {
22
- delete this.errorDetails['max'];
23
- }
24
- this.validateRequired(value);
25
- this.attach(this.element);
26
- };
27
- }
28
- attach(element) {
29
- this.renderComponentToElement(React.createElement("div", null, !this.conditionallyHidden() && (React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorDetails: this.errorDetails }),
30
- React.createElement(FormField, Object.assign({}, this.component, { errorMessage: Object.values(this.errorDetails).join(', ') }))))), element);
31
- super.attach(element);
32
- }
33
- }
34
- export default Integer;
@@ -1,16 +0,0 @@
1
- declare const SelectFormIOComponent: {
2
- new (component: any, options: any, data: any): {
3
- [x: string]: any;
4
- errorDetails: any;
5
- conditionallyHidden(): any;
6
- validateRequired(value: any): void;
7
- renderComponentToElement(component: any, element: any): void;
8
- };
9
- [x: string]: any;
10
- };
11
- declare class Select extends SelectFormIOComponent {
12
- constructor(component: any, options: any, data: any);
13
- handleChange: (key: string, value: string) => void;
14
- attach(element: Element): void;
15
- }
16
- export default Select;
@@ -1,22 +0,0 @@
1
- import React from 'react';
2
- import { Components } from 'formiojs';
3
- import FieldWrapper from './FieldWrapper';
4
- import { FormField } from '../components/custom';
5
- import { addSharedCustomizations } from './SharedCustomizations';
6
- const SelectFormIOComponent = addSharedCustomizations(Components.components.select);
7
- class Select extends SelectFormIOComponent {
8
- constructor(component, options, data) {
9
- super(component, options, data);
10
- this.handleChange = (key, value) => {
11
- this.validateRequired(value);
12
- super.setValue(value, {});
13
- };
14
- this.handleChange = this.handleChange.bind(this);
15
- }
16
- attach(element) {
17
- this.renderComponentToElement(React.createElement("div", null, !this.conditionallyHidden() && (React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorMessage: Object.values(this.errorDetails).join(', ') }),
18
- React.createElement(FormField, Object.assign({}, this.component))))), element);
19
- super.attach(element);
20
- }
21
- }
22
- export default Select;
@@ -1,32 +0,0 @@
1
- /**
2
- * Adds shared customizations such as errorDetails, validateRequired() and
3
- * conditionallyHidden() to a component class.
4
- * @param {any} superClass - The component class to extend.
5
- * @returns {any} - The extended component class with shared customizations.
6
- */
7
- export declare function addSharedCustomizations(superClass: any): {
8
- new (component: any, options: any, data: any): {
9
- [x: string]: any;
10
- errorDetails: any;
11
- /**
12
- * Checks if the component should be conditionally hidden based on its
13
- * configuration and the values within of other fields
14
- * @returns {boolean}
15
- */
16
- conditionallyHidden(): any;
17
- /**
18
- * Checks if a value is required and adds an error message if it is empty.
19
- * @param {any} value - The value to check.
20
- * @returns {void}
21
- */
22
- validateRequired(value: any): void;
23
- /**
24
- * Renders a React component to a DOM element.
25
- * @param {any} component - The React component to render.
26
- * @param {any} element - The DOM element to render the component to.
27
- * @returns {void}
28
- */
29
- renderComponentToElement(component: any, element: any): void;
30
- };
31
- [x: string]: any;
32
- };
@@ -1,59 +0,0 @@
1
- import { isEmpty } from 'lodash';
2
- import ReactDOM from 'react-dom';
3
- /**
4
- * Adds shared customizations such as errorDetails, validateRequired() and
5
- * conditionallyHidden() to a component class.
6
- * @param {any} superClass - The component class to extend.
7
- * @returns {any} - The extended component class with shared customizations.
8
- */
9
- export function addSharedCustomizations(superClass) {
10
- return class extends superClass {
11
- constructor(component, options, data) {
12
- super(component, options, data);
13
- this.errorDetails = {};
14
- }
15
- /**
16
- * Checks if the component should be conditionally hidden based on its
17
- * configuration and the values within of other fields
18
- * @returns {boolean}
19
- */
20
- conditionallyHidden() {
21
- const { conditional } = this.component;
22
- const prerequisiteField = conditional.when;
23
- const prerequisiteValue = conditional.eq;
24
- const prerequisiteFieldValue = this.root.getValue().data[prerequisiteField];
25
- prerequisiteField && prerequisiteFieldValue !== prerequisiteValue
26
- ? (this.component.hidden = true)
27
- : (this.component.hidden = false);
28
- return this.component.hidden;
29
- }
30
- /**
31
- * Checks if a value is required and adds an error message if it is empty.
32
- * @param {any} value - The value to check.
33
- * @returns {void}
34
- */
35
- validateRequired(value) {
36
- if (this.component.validate.required) {
37
- if (isEmpty(value)) {
38
- this.errorDetails['required'] = 'This field is required';
39
- }
40
- else {
41
- delete this.errorDetails['required'];
42
- }
43
- }
44
- }
45
- /**
46
- * Renders a React component to a DOM element.
47
- * @param {any} component - The React component to render.
48
- * @param {any} element - The DOM element to render the component to.
49
- * @returns {void}
50
- */
51
- renderComponentToElement(component, element) {
52
- let root = ReactDOM.findDOMNode(element);
53
- if (!root) {
54
- root = element;
55
- }
56
- ReactDOM.render(!this.conditionallyHidden() && component, root);
57
- }
58
- };
59
- }
@@ -1,17 +0,0 @@
1
- declare const TextField: {
2
- new (component: any, options: any, data: any): {
3
- [x: string]: any;
4
- errorDetails: any;
5
- conditionallyHidden(): any;
6
- validateRequired(value: any): void;
7
- renderComponentToElement(component: any, element: any): void;
8
- };
9
- [x: string]: any;
10
- };
11
- declare class Text extends TextField {
12
- constructor(component: any, options: any, data: any);
13
- handleValidation(value: string): void;
14
- handleChange: (key: string, value: string) => void;
15
- attach(element: Element): void;
16
- }
17
- export default Text;
@@ -1,80 +0,0 @@
1
- import React from 'react';
2
- import { Components } from 'formiojs';
3
- import FieldWrapper from './FieldWrapper';
4
- import { isEmpty } from 'lodash';
5
- import { FormField } from '../components/custom';
6
- import { addSharedCustomizations } from './SharedCustomizations';
7
- const TextField = addSharedCustomizations(Components.components.textfield);
8
- class Text extends TextField {
9
- constructor(component, options, data) {
10
- super(component, options, data);
11
- this.handleChange = (key, value) => {
12
- super.setValue(value, {});
13
- this.handleValidation(value);
14
- this.attach(this.element);
15
- };
16
- this.handleChange = this.handleChange.bind(this);
17
- }
18
- handleValidation(value) {
19
- const { inputMask, validate } = this.component;
20
- const mask = inputMask;
21
- if (mask) {
22
- const maskRegex = mask === null || mask === void 0 ? void 0 : mask.replace(/[\\^$.+?()[\]{}|]/g, '\\$&').replaceAll('9', '\\d').replaceAll('a', '[a-zA-Z]').replaceAll('*', '[a-zA-Z0-9]');
23
- if (maskRegex) {
24
- const regex = new RegExp(maskRegex);
25
- if (!regex.test(value)) {
26
- this.errorDetails['inputMask'] = 'Value must match the format ' + mask;
27
- }
28
- else {
29
- delete this.errorDetails['inputMask'];
30
- }
31
- }
32
- }
33
- if (!isEmpty(validate.regexes)) {
34
- const regexes = validate.regexes;
35
- const failedRules = validate.regexes.filter((rule) => {
36
- if (!RegExp(rule.regex).test(value)) {
37
- return true;
38
- }
39
- return false;
40
- });
41
- if (failedRules.length === 0) {
42
- delete this.errorDetails['regexes'];
43
- }
44
- else {
45
- if (validate.operator === 'all') {
46
- this.errorDetails['regexes'] = failedRules.map((rule) => rule.errorMessage).join(' and ');
47
- }
48
- else if (validate.operator === 'any') {
49
- if (regexes.length > failedRules.length) {
50
- delete this.errorDetails['regexes'];
51
- }
52
- else {
53
- this.errorDetails['regexes'] = failedRules.map((rule) => rule.errorMessage).join(' or ');
54
- }
55
- }
56
- }
57
- }
58
- if (validate.maxLength && value.length > validate.maxLength) {
59
- this.errorDetails['maxLength'] = `Max length is ${validate.maxLength}`;
60
- }
61
- else {
62
- delete this.errorDetails['maxLength'];
63
- }
64
- if (validate.minLength && value.length < validate.minLength) {
65
- this.errorDetails['minLength'] = `Min length is ${validate.minLength}`;
66
- }
67
- else {
68
- delete this.errorDetails['minLength'];
69
- }
70
- this.validateRequired(value);
71
- }
72
- attach(element) {
73
- const { inputMask } = this.component;
74
- this.renderComponentToElement(React.createElement("div", null,
75
- React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorMessage: Object.values(this.errorDetails).join(', ') }),
76
- React.createElement(FormField, Object.assign({}, this.component, { mask: inputMask })))), element);
77
- super.attach(element);
78
- }
79
- }
80
- export default Text;