envoc-form 4.0.1-10 → 4.0.1-11
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/es/AddressInput/AddressInput.d.ts +5 -5
- package/es/DatePicker/DatePickerGroup.d.ts +1 -1
- package/es/DatePicker/DatePickerGroup.js +9 -4
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +1 -1
- package/es/DatePicker/StringDatePickerGroup.d.ts +1 -1
- package/es/Field/Field.d.ts +2 -2
- package/es/FieldArray/FieldArray.d.ts +2 -2
- package/es/FieldArray/FieldArray.js +2 -2
- package/es/File/FileGroup.d.ts +1 -1
- package/es/File/FileGroup.js +1 -1
- package/es/File/FileList.d.ts +2 -2
- package/es/Form/FormBasedPreventNavigation.js +31 -14
- package/es/Input/IconInputGroup.d.ts +1 -1
- package/es/Input/IconInputGroup.js +2 -1
- package/es/Input/InputGroup.d.ts +2 -2
- package/es/Input/InputGroup.js +2 -2
- package/es/Input/MoneyInputGroup.d.ts +1 -1
- package/es/Input/NumberInputGroup.d.ts +1 -1
- package/es/Input/StringInputGroup.d.ts +1 -1
- package/es/Input/StringInputGroup.js +2 -1
- package/es/Normalization/normalizers.d.ts +2 -2
- package/es/Select/BooleanSelectGroup.d.ts +1 -1
- package/es/Select/NumberSelectGroup.d.ts +2 -2
- package/es/Select/SelectGroup.d.ts +1 -1
- package/es/Select/SelectGroup.js +1 -1
- package/es/SubmitFormButton.d.ts +1 -1
- package/es/TextArea/TextAreaGroup.d.ts +1 -1
- package/es/TextArea/TextAreaGroup.js +3 -2
- package/es/Validation/validators.d.ts +8 -8
- package/es/Validation/validators.js +3 -0
- package/es/__Tests__/FormTestBase.d.ts +1 -1
- package/es/__Tests__/FormTestBase.js +1 -1
- package/es/index.d.ts +4 -4
- package/lib/AddressInput/AddressInput.d.ts +5 -5
- package/lib/DatePicker/DatePickerGroup.d.ts +1 -1
- package/lib/DatePicker/DatePickerGroup.js +9 -4
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +1 -1
- package/lib/DatePicker/StringDatePickerGroup.d.ts +1 -1
- package/lib/Field/Field.d.ts +2 -2
- package/lib/FieldArray/FieldArray.d.ts +2 -2
- package/lib/FieldArray/FieldArray.js +2 -2
- package/lib/File/FileGroup.d.ts +1 -1
- package/lib/File/FileGroup.js +1 -1
- package/lib/File/FileList.d.ts +2 -2
- package/lib/Form/FormBasedPreventNavigation.js +31 -14
- package/lib/Input/IconInputGroup.d.ts +1 -1
- package/lib/Input/IconInputGroup.js +2 -1
- package/lib/Input/InputGroup.d.ts +2 -2
- package/lib/Input/InputGroup.js +2 -2
- package/lib/Input/MoneyInputGroup.d.ts +1 -1
- package/lib/Input/NumberInputGroup.d.ts +1 -1
- package/lib/Input/StringInputGroup.d.ts +1 -1
- package/lib/Input/StringInputGroup.js +2 -1
- package/lib/Normalization/normalizers.d.ts +2 -2
- package/lib/Select/BooleanSelectGroup.d.ts +1 -1
- package/lib/Select/NumberSelectGroup.d.ts +2 -2
- package/lib/Select/SelectGroup.d.ts +1 -1
- package/lib/Select/SelectGroup.js +1 -1
- package/lib/SubmitFormButton.d.ts +1 -1
- package/lib/TextArea/TextAreaGroup.d.ts +1 -1
- package/lib/TextArea/TextAreaGroup.js +3 -2
- package/lib/Validation/validators.d.ts +8 -8
- package/lib/Validation/validators.js +3 -0
- package/lib/__Tests__/FormTestBase.d.ts +1 -1
- package/lib/__Tests__/FormTestBase.js +2 -2
- package/lib/index.d.ts +4 -4
- package/package.json +2 -2
- package/src/AddressInput/AddressInput.tsx +5 -5
- package/src/DatePicker/DatePickerGroup.tsx +8 -4
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +2 -2
- package/src/DatePicker/StringDatePickerGroup.tsx +1 -1
- package/src/Field/Field.tsx +2 -2
- package/src/FieldArray/FieldArray.tsx +5 -5
- package/src/File/FileGroup.tsx +2 -2
- package/src/File/FileList.tsx +2 -2
- package/src/Form/FormBasedPreventNavigation.tsx +34 -18
- package/src/Input/IconInputGroup.tsx +2 -2
- package/src/Input/InputGroup.tsx +8 -4
- package/src/Input/MoneyInputGroup.tsx +1 -1
- package/src/Input/NumberInputGroup.tsx +1 -1
- package/src/Input/StringInputGroup.tsx +2 -2
- package/src/Normalization/normalizers.ts +2 -2
- package/src/Select/BooleanSelectGroup.tsx +1 -1
- package/src/Select/NumberSelectGroup.tsx +2 -2
- package/src/Select/SelectGroup.tsx +2 -2
- package/src/SubmitFormButton.tsx +2 -1
- package/src/TextArea/TextAreaGroup.tsx +3 -3
- package/src/Validation/validators.ts +16 -12
- package/src/__Tests__/FormTestBase.tsx +2 -2
- package/src/index.ts +4 -4
package/lib/File/FileGroup.js
CHANGED
@@ -29,8 +29,8 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
29
|
var react_1 = __importDefault(require("react"));
|
30
30
|
var classnames_1 = __importDefault(require("classnames"));
|
31
31
|
var FileList_1 = __importDefault(require("./FileList"));
|
32
|
-
var Group_1 = __importDefault(require("../Group"));
|
33
32
|
var FormDefaults_1 = require("../FormDefaults");
|
33
|
+
var Group_1 = __importDefault(require("../Group"));
|
34
34
|
function FileGroup(_a, ref) {
|
35
35
|
var _b;
|
36
36
|
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, multiple = _a.multiple, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "multiple"]);
|
package/lib/File/FileList.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
export interface FileListProps {
|
3
|
-
files?: File | File[] | undefined;
|
4
|
-
rejectedFiles?: File | File[] | undefined;
|
3
|
+
files?: File | File[] | undefined | null;
|
4
|
+
rejectedFiles?: File | File[] | undefined | null;
|
5
5
|
}
|
6
6
|
export default function FileList({ files, rejectedFiles }: FileListProps): JSX.Element;
|
@@ -24,26 +24,43 @@ function FormBasedPreventNavigation(_a) {
|
|
24
24
|
if (!preventNavigate) {
|
25
25
|
return;
|
26
26
|
}
|
27
|
+
var unblock = function () { };
|
28
|
+
var push = navigator.push;
|
27
29
|
// TODO: https://reactrouter.com/docs/en/v6/upgrading/v5#prompt-is-not-currently-supported
|
28
30
|
// this is a workaround until we get native support for prompt on navigate
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
33
|
-
};
|
34
|
-
var unblock = navigator.block(function (tx) {
|
35
|
-
var autoUnblockingTx = __assign(__assign({}, tx), { retry: function () {
|
36
|
-
// Automatically unblock the transition so it can play all the way
|
37
|
-
// through before retrying it. TODO: Figure out how to re-enable
|
38
|
-
// this block if the transition is cancelled for some reason.
|
39
|
-
unblock();
|
31
|
+
if (navigator.block) {
|
32
|
+
var blocker_1 = function (tx) {
|
33
|
+
if (window.confirm(promptMessage)) {
|
40
34
|
tx.retry();
|
41
|
-
}
|
42
|
-
|
43
|
-
|
35
|
+
}
|
36
|
+
};
|
37
|
+
unblock = navigator.block(function (tx) {
|
38
|
+
var autoUnblockingTx = __assign(__assign({}, tx), { retry: function () {
|
39
|
+
// Automatically unblock the transition so it can play all the way
|
40
|
+
// through before retrying it. TODO: Figure out how to re-enable
|
41
|
+
// this block if the transition is cancelled for some reason.
|
42
|
+
unblock();
|
43
|
+
tx.retry();
|
44
|
+
} });
|
45
|
+
blocker_1(autoUnblockingTx);
|
46
|
+
});
|
47
|
+
}
|
48
|
+
else {
|
49
|
+
//https://gist.github.com/MarksCode/64e438c82b0b2a1161e01c88ca0d0355
|
50
|
+
navigator.push = function () {
|
51
|
+
var args = [];
|
52
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
53
|
+
args[_i] = arguments[_i];
|
54
|
+
}
|
55
|
+
if (window.confirm(promptMessage)) {
|
56
|
+
push.apply(void 0, args);
|
57
|
+
}
|
58
|
+
};
|
59
|
+
}
|
44
60
|
window.addEventListener('beforeunload', beforeUnload);
|
45
61
|
return function () {
|
46
62
|
unblock();
|
63
|
+
navigator.push = push;
|
47
64
|
window.removeEventListener('beforeunload', beforeUnload);
|
48
65
|
};
|
49
66
|
function beforeUnload(e) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { InputGroupProps } from './InputGroup';
|
3
|
-
export interface IconInputGroupProps extends Omit<InputGroupProps<string | undefined>, 'onChange' | 'type' | 'value'> {
|
3
|
+
export interface IconInputGroupProps extends Omit<InputGroupProps<string | undefined | null>, 'onChange' | 'type' | 'value'> {
|
4
4
|
type?: 'color' | 'email' | 'search' | 'tel' | 'text' | 'url';
|
5
5
|
icon: React.ReactNode;
|
6
6
|
helpText?: string;
|
@@ -31,9 +31,10 @@ var classnames_1 = __importDefault(require("classnames"));
|
|
31
31
|
var InputGroup_1 = __importDefault(require("./InputGroup"));
|
32
32
|
var FormDefaults_1 = require("../FormDefaults");
|
33
33
|
function IconInputGroup(_a, ref) {
|
34
|
+
var _b;
|
34
35
|
var icon = _a.icon, className = _a.className, rest = __rest(_a, ["icon", "className"]);
|
35
36
|
var input = rest.input;
|
36
|
-
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(InputGroup_1.default, __assign({ icon: icon, ref: ref, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'icon-input-group'), value: input.value
|
37
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(InputGroup_1.default, __assign({ icon: icon, ref: ref, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'icon-input-group'), value: (_b = input.value) !== null && _b !== void 0 ? _b : '', onChange: function (e) {
|
37
38
|
if (!e.target.value) {
|
38
39
|
input.onChange(undefined);
|
39
40
|
}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import React, { ChangeEventHandler, LegacyRef } from 'react';
|
2
2
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
3
3
|
import { GroupProps } from '../Group';
|
4
|
-
export interface InputGroupProps<TValue> extends InjectedFieldProps<TValue>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
|
4
|
+
export interface InputGroupProps<TValue> extends InjectedFieldProps<TValue>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label' | 'value'>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
|
5
5
|
onChange: ChangeEventHandler<HTMLInputElement>;
|
6
|
-
value: string | number;
|
6
|
+
value: string | number | null | undefined;
|
7
7
|
icon?: React.ReactNode;
|
8
8
|
}
|
9
9
|
/** generic controlled <input/> wrapped by a Group */
|
package/lib/Input/InputGroup.js
CHANGED
@@ -28,12 +28,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
29
29
|
var react_1 = __importDefault(require("react"));
|
30
30
|
var classnames_1 = __importDefault(require("classnames"));
|
31
|
-
var Group_1 = __importDefault(require("../Group"));
|
32
31
|
var FormDefaults_1 = require("../FormDefaults");
|
32
|
+
var Group_1 = __importDefault(require("../Group"));
|
33
33
|
/** generic controlled <input/> wrapped by a Group */
|
34
34
|
function InputGroup(_a, ref) {
|
35
35
|
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, onChange = _a.onChange, value = _a.value, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "onChange", "value", "icon"]);
|
36
|
-
return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'input-group') }, { children: [icon, (0, jsx_runtime_1.jsx)("input", __assign({}, input, rest, { value: value, onChange: onChange, ref: ref, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'input-group') }))] })));
|
36
|
+
return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'input-group') }, { children: [icon, (0, jsx_runtime_1.jsx)("input", __assign({}, input, rest, { value: value !== null && value !== void 0 ? value : '', onChange: onChange, ref: ref, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'input-group') }))] })));
|
37
37
|
}
|
38
38
|
var InputGroupWithRef = react_1.default.forwardRef(InputGroup);
|
39
39
|
exports.default = InputGroupWithRef;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { InputGroupProps } from './InputGroup';
|
3
|
-
export interface MoneyInputGroupProps extends Omit<InputGroupProps<number | undefined>, 'onChange' | 'type' | 'value'> {
|
3
|
+
export interface MoneyInputGroupProps extends Omit<InputGroupProps<number | undefined | null>, 'onChange' | 'type' | 'value'> {
|
4
4
|
parseFunc?: typeof parseInt | typeof parseFloat;
|
5
5
|
}
|
6
6
|
declare const MoneyInputGroupWithRef: React.FunctionComponent<MoneyInputGroupProps>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { InputGroupProps } from './InputGroup';
|
3
|
-
export interface NumberInputGroupProps extends Omit<InputGroupProps<number | undefined>, 'onChange' | 'type' | 'value'> {
|
3
|
+
export interface NumberInputGroupProps extends Omit<InputGroupProps<number | undefined | null>, 'onChange' | 'type' | 'value'> {
|
4
4
|
parseFunc?: typeof parseInt | typeof parseFloat;
|
5
5
|
}
|
6
6
|
declare const NumberInputGroupWithRef: React.ComponentType<NumberInputGroupProps>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { InputGroupProps } from './InputGroup';
|
3
|
-
export interface StringInputGroupProps extends Omit<InputGroupProps<string | undefined>, 'onChange' | 'type' | 'value'> {
|
3
|
+
export interface StringInputGroupProps extends Omit<InputGroupProps<string | undefined | null>, 'onChange' | 'type' | 'value'> {
|
4
4
|
type?: 'color' | 'email' | 'search' | 'tel' | 'text' | 'url' | 'password' | 'textarea';
|
5
5
|
}
|
6
6
|
declare const StringInputGroupWithRef: React.ComponentType<StringInputGroupProps>;
|
@@ -31,9 +31,10 @@ var classnames_1 = __importDefault(require("classnames"));
|
|
31
31
|
var InputGroup_1 = __importDefault(require("./InputGroup"));
|
32
32
|
var FormDefaults_1 = require("../FormDefaults");
|
33
33
|
function StringInputGroup(_a, ref) {
|
34
|
+
var _b;
|
34
35
|
var className = _a.className, rest = __rest(_a, ["className"]);
|
35
36
|
var input = rest.input;
|
36
|
-
return ((0, jsx_runtime_1.jsx)(InputGroup_1.default, __assign({ ref: ref }, rest, { className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'string-group'), value: input.value
|
37
|
+
return ((0, jsx_runtime_1.jsx)(InputGroup_1.default, __assign({ ref: ref }, rest, { className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'string-group'), value: (_b = input.value) !== null && _b !== void 0 ? _b : '', onChange: function (e) {
|
37
38
|
if (!e.target.value) {
|
38
39
|
input.onChange(undefined);
|
39
40
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const phoneNumber: (value: string | undefined) => string | undefined;
|
2
|
-
export declare const zipCode: (value: string | undefined) => string | undefined;
|
1
|
+
export declare const phoneNumber: (value: string | undefined | null) => string | undefined;
|
2
|
+
export declare const zipCode: (value: string | undefined | null) => string | undefined;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { SelectOption } from './SelectGroup';
|
3
3
|
import { SelectGroupPropsHelper } from './SelectGroupPropsHelper';
|
4
|
-
export interface BooleanSelectGroupProps extends Omit<SelectGroupPropsHelper<boolean>, 'options'> {
|
4
|
+
export interface BooleanSelectGroupProps extends Omit<SelectGroupPropsHelper<boolean | undefined | null>, 'options'> {
|
5
5
|
options?: SelectOption<boolean>[];
|
6
6
|
}
|
7
7
|
export declare function BooleanSelectGroup(props: BooleanSelectGroupProps): JSX.Element;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { SelectGroupPropsHelper } from './SelectGroupPropsHelper';
|
3
|
-
export interface MultiNumberSelectGroupProps extends SelectGroupPropsHelper<number[]> {
|
3
|
+
export interface MultiNumberSelectGroupProps extends SelectGroupPropsHelper<number[] | undefined | null> {
|
4
4
|
}
|
5
5
|
export declare function MultiNumberSelectGroup(props: MultiNumberSelectGroupProps): JSX.Element;
|
6
|
-
export interface SingleNumberSelectGroupProps extends SelectGroupPropsHelper<number> {
|
6
|
+
export interface SingleNumberSelectGroupProps extends SelectGroupPropsHelper<number | undefined | null> {
|
7
7
|
}
|
8
8
|
export declare function SingleNumberSelectGroup(props: SingleNumberSelectGroupProps): JSX.Element;
|
@@ -13,7 +13,7 @@ interface OptionsUseServiceResult<TValue> {
|
|
13
13
|
resp?: Partial<SelectOption<TValue>>[] | OptionsApiResult<TValue> | null;
|
14
14
|
error?: any;
|
15
15
|
}
|
16
|
-
export interface SelectGroupProps<TValue> extends InjectedFieldProps<TValue | undefined>, Omit<GroupProps, 'input' | 'meta' | 'children'> {
|
16
|
+
export interface SelectGroupProps<TValue> extends InjectedFieldProps<TValue | undefined | null>, Omit<GroupProps, 'input' | 'meta' | 'children'> {
|
17
17
|
options: SelectOption<TValue>[] | OptionsUseServiceResult<TValue>;
|
18
18
|
multiple: TValue extends Array<any> ? true : false;
|
19
19
|
placeholder?: string;
|
@@ -28,8 +28,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
29
29
|
var react_select_1 = __importDefault(require("react-select"));
|
30
30
|
var classnames_1 = __importDefault(require("classnames"));
|
31
|
-
var Group_1 = __importDefault(require("../Group"));
|
32
31
|
var FormDefaults_1 = require("../FormDefaults");
|
32
|
+
var Group_1 = __importDefault(require("../Group"));
|
33
33
|
// TODO: we could also name this "ReactSelectGroup" or similar but the types are strongly defined now so kept the names consistent
|
34
34
|
function SelectGroup(_a) {
|
35
35
|
var _b;
|
@@ -3,5 +3,5 @@ export interface SubmitFormButtonProps extends Omit<React.HTMLProps<HTMLButtonEl
|
|
3
3
|
allowPristineSubmit?: boolean;
|
4
4
|
children?: React.ReactNode;
|
5
5
|
}
|
6
|
-
declare const _default: React.
|
6
|
+
declare const _default: React.FunctionComponent<SubmitFormButtonProps>;
|
7
7
|
export default _default;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
3
3
|
import { GroupProps } from '../Group';
|
4
|
-
export interface TextAreaGroupProps extends InjectedFieldProps<string | undefined>, Omit<React.HTMLProps<HTMLTextAreaElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
|
4
|
+
export interface TextAreaGroupProps extends InjectedFieldProps<string | undefined | null>, Omit<React.HTMLProps<HTMLTextAreaElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
|
5
5
|
icon?: React.ReactNode;
|
6
6
|
}
|
7
7
|
declare const TextAreaGroupWithRef: React.ComponentType<TextAreaGroupProps>;
|
@@ -28,12 +28,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
29
29
|
var react_1 = __importDefault(require("react"));
|
30
30
|
var classnames_1 = __importDefault(require("classnames"));
|
31
|
-
var Group_1 = __importDefault(require("../Group"));
|
32
31
|
var FormDefaults_1 = require("../FormDefaults");
|
32
|
+
var Group_1 = __importDefault(require("../Group"));
|
33
33
|
/** generic controlled <textarea/> wrapped by a Group */
|
34
34
|
function TextAreaGroup(_a, ref) {
|
35
|
+
var _b;
|
35
36
|
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "icon"]);
|
36
|
-
return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'text-area-group') }, { children: [icon, (0, jsx_runtime_1.jsx)("textarea", __assign({}, input, rest, { value: input.value, onChange: function (val) { return input.onChange(val.target.value); }, ref: ref, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'text-area-group') }))] })));
|
37
|
+
return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'text-area-group') }, { children: [icon, (0, jsx_runtime_1.jsx)("textarea", __assign({}, input, rest, { value: (_b = input.value) !== null && _b !== void 0 ? _b : '', onChange: function (val) { return input.onChange(val.target.value); }, ref: ref, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'text-area-group') }))] })));
|
37
38
|
}
|
38
39
|
var TextAreaGroupWithRef = react_1.default.forwardRef(TextAreaGroup);
|
39
40
|
exports.default = TextAreaGroupWithRef;
|
@@ -1,15 +1,15 @@
|
|
1
1
|
import { ValidationFunction } from './ValidationFunction';
|
2
2
|
export declare const required: (value: any) => "Required" | undefined;
|
3
|
-
export declare const length: (len: number) => (value: string | number | undefined) => string | undefined;
|
4
|
-
export declare const integer: (val: string | number | undefined) => "Must be a whole number" | undefined;
|
5
|
-
export declare const maxLength: (len: number) => (value: string | number | undefined) => string | undefined;
|
3
|
+
export declare const length: (len: number) => (value: string | number | undefined | null) => string | undefined;
|
4
|
+
export declare const integer: (val: string | number | undefined | null) => "Must be a whole number" | undefined;
|
5
|
+
export declare const maxLength: (len: number) => (value: string | number | undefined | null) => string | undefined;
|
6
6
|
export declare const maxCount: (count: number) => (value: {
|
7
7
|
isDeleted?: boolean;
|
8
|
-
}[] | undefined) => string | undefined;
|
8
|
+
}[] | undefined | null) => string | undefined;
|
9
9
|
export declare const minCount: (count: number) => (value: {
|
10
10
|
isDeleted?: boolean;
|
11
|
-
}[] | undefined) => string | undefined;
|
12
|
-
export declare const maxValue: (max: number) => (value: number | undefined) => string | undefined;
|
13
|
-
export declare const minValue: (min: number) => (value: number | undefined) => string | undefined;
|
14
|
-
export declare const zipCode: (value: string | undefined) => "Invalid ZIP Code" | undefined;
|
11
|
+
}[] | undefined | null) => string | undefined;
|
12
|
+
export declare const maxValue: (max: number) => (value: number | undefined | null) => string | undefined;
|
13
|
+
export declare const minValue: (min: number) => (value: number | undefined | null) => string | undefined;
|
14
|
+
export declare const zipCode: (value: string | undefined | null) => "Invalid ZIP Code" | undefined;
|
15
15
|
export declare const any: <TValue>(validatorList: ValidationFunction<TValue>[]) => (value: TValue) => string | undefined;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import '@testing-library/jest-dom/extend-expect';
|
3
|
-
import { FormBuilderProp } from '
|
3
|
+
import { FormBuilderProp } from '../';
|
4
4
|
interface FormTestBaseProps<TForm extends object> {
|
5
5
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
6
6
|
initialValues?: TForm;
|
@@ -50,10 +50,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
51
51
|
require("@testing-library/jest-dom/extend-expect");
|
52
52
|
var react_router_dom_1 = require("react-router-dom");
|
53
|
-
var
|
53
|
+
var __1 = require("../");
|
54
54
|
function FormTestBase(_a) {
|
55
55
|
var children = _a.children, initialValues = _a.initialValues;
|
56
|
-
return ((0, jsx_runtime_1.jsx)(react_router_dom_1.HashRouter, { children: (0, jsx_runtime_1.jsx)(
|
56
|
+
return ((0, jsx_runtime_1.jsx)(react_router_dom_1.HashRouter, { children: (0, jsx_runtime_1.jsx)(__1.Form, __assign({ onSubmit: onSubmit, initialValues: initialValues }, { children: children })) }));
|
57
57
|
function onSubmit(data) {
|
58
58
|
return __awaiter(this, void 0, void 0, function () {
|
59
59
|
var isFormData, result, apiResult;
|
package/lib/index.d.ts
CHANGED
@@ -7,7 +7,7 @@ export type { ConfirmBaseFormProps } from './ConfirmBaseForm/ConfirmBaseForm';
|
|
7
7
|
export { default as ConfirmDeleteForm } from './ConfirmDeleteForm/ConfirmDeleteForm';
|
8
8
|
export type { ConfirmDeleteFormProps } from './ConfirmDeleteForm/ConfirmDeleteForm';
|
9
9
|
export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
|
10
|
-
export type { DatePickerGroupProps
|
10
|
+
export type { DatePickerGroupProps } from './DatePicker/DatePickerGroup';
|
11
11
|
export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
|
12
12
|
export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
|
13
13
|
export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
|
@@ -34,12 +34,12 @@ export type { FormBuilderProp, FormProps } from './Form/Form';
|
|
34
34
|
export { ServerErrorContext } from './Form/ServerErrorContext';
|
35
35
|
export type { ServerErrorContextProps, ServerErrors, } from './Form/ServerErrorContext';
|
36
36
|
export { default as FormActions } from './FormActions';
|
37
|
-
export type { FormActionsProps
|
37
|
+
export type { FormActionsProps } from './FormActions';
|
38
38
|
export { default as StandardFormActions } from './StandardFormActions';
|
39
|
-
export type { StandardFormActionsProps
|
39
|
+
export type { StandardFormActionsProps } from './StandardFormActions';
|
40
40
|
export { FormDefaults } from './FormDefaults';
|
41
41
|
export { default as Group } from './Group';
|
42
|
-
export type { GroupProps
|
42
|
+
export type { GroupProps } from './Group';
|
43
43
|
export { default as IconInputGroup } from './Input/IconInputGroup';
|
44
44
|
export type { IconInputGroupProps } from './Input/IconInputGroup';
|
45
45
|
export { default as InputGroup } from './Input/InputGroup';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "envoc-form",
|
3
|
-
"version": "4.0.1-
|
3
|
+
"version": "4.0.1-11",
|
4
4
|
"description": "Envoc form components",
|
5
5
|
"keywords": [
|
6
6
|
"react-component",
|
@@ -37,7 +37,7 @@
|
|
37
37
|
"axios": "^0.21.1",
|
38
38
|
"classnames": "^2.3.1",
|
39
39
|
"date-fns": "^2.22.1",
|
40
|
-
"envoc-request": "^4.0.1-
|
40
|
+
"envoc-request": "^4.0.1-11",
|
41
41
|
"lru-cache": "^6.0.0",
|
42
42
|
"prop-types": "^15.7.2",
|
43
43
|
"react-date-picker": "^8.2.0",
|
@@ -16,11 +16,11 @@ export interface AddressInputProps {
|
|
16
16
|
}
|
17
17
|
|
18
18
|
interface AddressDto {
|
19
|
-
address1?: string;
|
20
|
-
address2?: string;
|
21
|
-
zipCode?: string;
|
22
|
-
city?: string;
|
23
|
-
state?: string;
|
19
|
+
address1?: string | null;
|
20
|
+
address2?: string | null;
|
21
|
+
zipCode?: string | null;
|
22
|
+
city?: string | null;
|
23
|
+
state?: string | null;
|
24
24
|
}
|
25
25
|
|
26
26
|
export default function AddressInput({
|
@@ -11,7 +11,7 @@ import Group, { GroupProps } from '../Group';
|
|
11
11
|
// Docs for react-date-picker https://www.npmjs.com/package/react-date-picker
|
12
12
|
|
13
13
|
export interface DatePickerGroupProps<T>
|
14
|
-
extends InjectedFieldProps<T | undefined>,
|
14
|
+
extends InjectedFieldProps<T | undefined | null>,
|
15
15
|
Omit<
|
16
16
|
DatePickerProps,
|
17
17
|
keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'
|
@@ -34,10 +34,14 @@ export default function DatePickerGroup<T>({
|
|
34
34
|
const [displayDate, setDisplayDate] = useState<Date | null>(null);
|
35
35
|
|
36
36
|
useEffect(() => {
|
37
|
-
if (input.value
|
38
|
-
setDisplayDate(new Date(`${input.value}T00:00:00.000`));
|
39
|
-
} else {
|
37
|
+
if (!input.value) {
|
40
38
|
setDisplayDate(null);
|
39
|
+
} else if (typeof input.value === 'string') {
|
40
|
+
if (input.value.indexOf('T') === -1) {
|
41
|
+
setDisplayDate(new Date(`${input.value}T00:00:00.000`));
|
42
|
+
} else {
|
43
|
+
setDisplayDate(new Date(input.value));
|
44
|
+
}
|
41
45
|
}
|
42
46
|
}, [setDisplayDate, input.value]);
|
43
47
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { DatePickerHelper } from './DatePickerHelper';
|
2
1
|
import DatePickerGroup from './DatePickerGroup';
|
2
|
+
import { DatePickerHelper } from './DatePickerHelper';
|
3
3
|
|
4
4
|
export interface StringDateOnlyPickerGroupProps
|
5
|
-
extends DatePickerHelper<string | undefined> {}
|
5
|
+
extends DatePickerHelper<string | undefined | null> {}
|
6
6
|
|
7
7
|
export default function StringDatePickerGroup(
|
8
8
|
props: StringDateOnlyPickerGroupProps
|
@@ -2,7 +2,7 @@ import DatePickerGroup from './DatePickerGroup';
|
|
2
2
|
import { DatePickerHelper } from './DatePickerHelper';
|
3
3
|
|
4
4
|
export interface StringDatePickerGroupProps
|
5
|
-
extends DatePickerHelper<string | undefined> {}
|
5
|
+
extends DatePickerHelper<string | undefined | null> {}
|
6
6
|
export default function StringDatePickerGroup(
|
7
7
|
props: StringDatePickerGroupProps
|
8
8
|
) {
|
package/src/Field/Field.tsx
CHANGED
@@ -14,7 +14,7 @@ export type RenderComponent<
|
|
14
14
|
TValue,
|
15
15
|
TRenderComponent extends ElementType
|
16
16
|
> = Partial<ComponentProps<TRenderComponent>> extends Partial<
|
17
|
-
InjectedFieldProps<TValue | undefined>
|
17
|
+
InjectedFieldProps<TValue | undefined | null>
|
18
18
|
>
|
19
19
|
? TRenderComponent
|
20
20
|
: never;
|
@@ -23,7 +23,7 @@ export type RenderComponentProps<
|
|
23
23
|
TValue,
|
24
24
|
TRenderComponent extends ElementType
|
25
25
|
> = Partial<ComponentProps<TRenderComponent>> extends Partial<
|
26
|
-
InjectedFieldProps<TValue | undefined>
|
26
|
+
InjectedFieldProps<TValue | undefined | null>
|
27
27
|
>
|
28
28
|
? ComponentProps<TRenderComponent>
|
29
29
|
: never;
|
@@ -3,13 +3,13 @@ import classNames from 'classnames';
|
|
3
3
|
import Field, { FieldProps } from '../Field/Field';
|
4
4
|
import { FieldNameContext } from '../Field/FieldNameContext';
|
5
5
|
import useStandardFormInput from '../Field/useStandardField';
|
6
|
-
import { ValidationFunction } from '../Validation/ValidationFunction';
|
7
6
|
import { FormDefaults } from '../FormDefaults';
|
7
|
+
import { ValidationFunction } from '../Validation/ValidationFunction';
|
8
8
|
|
9
9
|
export type FieldArrayProps<
|
10
10
|
TForm extends object,
|
11
11
|
TProp extends keyof TForm
|
12
|
-
> = TForm[TProp] extends Array<any> | undefined
|
12
|
+
> = TForm[TProp] extends Array<any> | undefined | null
|
13
13
|
? {
|
14
14
|
name: TProp;
|
15
15
|
label?: string;
|
@@ -23,8 +23,8 @@ export type FieldArrayProps<
|
|
23
23
|
}
|
24
24
|
: never;
|
25
25
|
|
26
|
-
export type ArrayFormBuilderProp<TValue extends Array<any> | undefined> =
|
27
|
-
TValue extends Array<infer TForm> | undefined
|
26
|
+
export type ArrayFormBuilderProp<TValue extends Array<any> | undefined | null> =
|
27
|
+
TValue extends Array<infer TForm> | undefined | null
|
28
28
|
? TForm extends object
|
29
29
|
? {
|
30
30
|
Field: <
|
@@ -52,7 +52,7 @@ export default function FieldArray<
|
|
52
52
|
children,
|
53
53
|
...rest
|
54
54
|
}: FieldArrayProps<TForm, TProp>) {
|
55
|
-
const [input
|
55
|
+
const [input] = useStandardFormInput<TForm[TProp]>({
|
56
56
|
name: String(name),
|
57
57
|
validate: validate,
|
58
58
|
disabled: disabled,
|
package/src/File/FileGroup.tsx
CHANGED
@@ -2,12 +2,12 @@ import React, { ComponentType, LegacyRef } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
3
3
|
import FileList from './FileList';
|
4
4
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
5
|
-
import Group, { GroupProps } from '../Group';
|
6
5
|
import { FormDefaults } from '../FormDefaults';
|
6
|
+
import Group, { GroupProps } from '../Group';
|
7
7
|
|
8
8
|
export interface FileGroupProps
|
9
9
|
// note: file props are of type "any" with the current type generation
|
10
|
-
extends InjectedFieldProps<any | undefined>,
|
10
|
+
extends InjectedFieldProps<any | undefined | null>,
|
11
11
|
Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'>,
|
12
12
|
Omit<
|
13
13
|
React.HTMLProps<HTMLInputElement>,
|
package/src/File/FileList.tsx
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { FormDefaults } from '../FormDefaults';
|
2
2
|
|
3
3
|
export interface FileListProps {
|
4
|
-
files?: File | File[] | undefined;
|
5
|
-
rejectedFiles?: File | File[] | undefined;
|
4
|
+
files?: File | File[] | undefined | null;
|
5
|
+
rejectedFiles?: File | File[] | undefined | null;
|
6
6
|
}
|
7
7
|
export default function FileList({ files, rejectedFiles }: FileListProps) {
|
8
8
|
return (
|
@@ -8,8 +8,13 @@ import {
|
|
8
8
|
import { useFormikContext } from 'formik';
|
9
9
|
|
10
10
|
interface Navigator extends BaseNavigator {
|
11
|
-
block
|
11
|
+
block?: History['block'];
|
12
12
|
}
|
13
|
+
|
14
|
+
//The Current state of the world (2023-05-10) is that useBlocker exists in react-router, but is only available for data routers, which we currently don't use
|
15
|
+
// `block` was available on UNSAFE_NavigationContext previously, but was removed
|
16
|
+
// Modifying `push` prevents _most_ but not all navigations with a prompt, long term solution may be to remove FileSystemRoutes and swap to a data router (https://reactrouter.com/en/main/routers/create-browser-router)
|
17
|
+
|
13
18
|
// see: https://github.com/remix-run/react-router/issues/8139#issuecomment-1023105785
|
14
19
|
type NavigationContextWithBlock = ContextType<typeof NavigationContext> & {
|
15
20
|
navigator: Navigator;
|
@@ -34,33 +39,44 @@ export default function FormBasedPreventNavigation({
|
|
34
39
|
if (!preventNavigate) {
|
35
40
|
return;
|
36
41
|
}
|
42
|
+
let unblock = () => {};
|
43
|
+
const push = navigator.push;
|
37
44
|
|
38
45
|
// TODO: https://reactrouter.com/docs/en/v6/upgrading/v5#prompt-is-not-currently-supported
|
39
46
|
// this is a workaround until we get native support for prompt on navigate
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
tx.retry();
|
44
|
-
}
|
45
|
-
};
|
46
|
-
const unblock = navigator.block((tx: Transition) => {
|
47
|
-
const autoUnblockingTx = {
|
48
|
-
...tx,
|
49
|
-
retry() {
|
50
|
-
// Automatically unblock the transition so it can play all the way
|
51
|
-
// through before retrying it. TODO: Figure out how to re-enable
|
52
|
-
// this block if the transition is cancelled for some reason.
|
53
|
-
unblock();
|
47
|
+
if (navigator.block) {
|
48
|
+
const blocker: Blocker = (tx) => {
|
49
|
+
if (window.confirm(promptMessage)) {
|
54
50
|
tx.retry();
|
55
|
-
}
|
51
|
+
}
|
56
52
|
};
|
53
|
+
unblock = navigator.block((tx: Transition) => {
|
54
|
+
const autoUnblockingTx = {
|
55
|
+
...tx,
|
56
|
+
retry() {
|
57
|
+
// Automatically unblock the transition so it can play all the way
|
58
|
+
// through before retrying it. TODO: Figure out how to re-enable
|
59
|
+
// this block if the transition is cancelled for some reason.
|
60
|
+
unblock();
|
61
|
+
tx.retry();
|
62
|
+
},
|
63
|
+
};
|
57
64
|
|
58
|
-
|
59
|
-
|
65
|
+
blocker(autoUnblockingTx);
|
66
|
+
});
|
67
|
+
} else {
|
68
|
+
//https://gist.github.com/MarksCode/64e438c82b0b2a1161e01c88ca0d0355
|
69
|
+
navigator.push = (...args: Parameters<typeof push>) => {
|
70
|
+
if (window.confirm(promptMessage)) {
|
71
|
+
push(...args);
|
72
|
+
}
|
73
|
+
};
|
74
|
+
}
|
60
75
|
|
61
76
|
window.addEventListener('beforeunload', beforeUnload);
|
62
77
|
return () => {
|
63
78
|
unblock();
|
79
|
+
navigator.push = push;
|
64
80
|
window.removeEventListener('beforeunload', beforeUnload);
|
65
81
|
};
|
66
82
|
|
@@ -7,7 +7,7 @@ import { FormDefaults } from '../FormDefaults';
|
|
7
7
|
// or should we just give a div a className and let each project decide? (this seems to be the patern)
|
8
8
|
export interface IconInputGroupProps
|
9
9
|
extends Omit<
|
10
|
-
InputGroupProps<string | undefined>,
|
10
|
+
InputGroupProps<string | undefined | null>,
|
11
11
|
'onChange' | 'type' | 'value'
|
12
12
|
> {
|
13
13
|
type?: 'color' | 'email' | 'search' | 'tel' | 'text' | 'url';
|
@@ -30,7 +30,7 @@ function IconInputGroup(
|
|
30
30
|
className,
|
31
31
|
FormDefaults.cssClassPrefix + 'icon-input-group'
|
32
32
|
)}
|
33
|
-
value={input.value
|
33
|
+
value={input.value ?? ''}
|
34
34
|
onChange={(e) => {
|
35
35
|
if (!e.target.value) {
|
36
36
|
input.onChange(undefined);
|