envoc-form 4.0.1-11 → 4.0.1-12
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/README.md +5117 -12
- package/es/AddressInput/AddressInput.d.ts +10 -0
- package/es/AddressInput/AddressInput.js +10 -0
- package/es/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
- package/es/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
- package/es/DatePicker/DatePickerGroup.d.ts +5 -0
- package/es/DatePicker/DatePickerGroup.js +5 -0
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/es/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/es/DatePicker/StringDatePickerGroup.d.ts +5 -0
- package/es/DatePicker/StringDatePickerGroup.js +5 -0
- package/es/Field/Field.d.ts +6 -0
- package/es/Field/FieldErrorScrollTarget.d.ts +1 -0
- package/es/Field/FieldErrorScrollTarget.js +1 -0
- package/es/Field/StandAloneInput.d.ts +4 -0
- package/es/Field/StandAloneInput.js +1 -0
- package/es/Field/useStandardField.d.ts +6 -0
- package/es/Field/useStandardField.js +8 -9
- package/es/FieldArray/FieldArray.d.ts +9 -0
- package/es/FieldArray/FieldArray.js +5 -0
- package/es/File/FileGroup.d.ts +2 -0
- package/es/File/FileGroup.js +1 -0
- package/es/Form/FocusError.d.ts +2 -0
- package/es/Form/FocusError.js +1 -0
- package/es/Form/Form.d.ts +6 -0
- package/es/Form/Form.js +1 -0
- package/es/Form/FormBasedPreventNavigation.d.ts +3 -1
- package/es/Form/FormBasedPreventNavigation.js +12 -62
- package/es/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
- package/es/Form/LegacyFormBasedPreventNavigation.js +69 -0
- package/es/Form/NewFormBasedPreventNavigation.d.ts +14 -0
- package/es/Form/NewFormBasedPreventNavigation.js +39 -0
- package/es/Form/ServerErrorContext.d.ts +1 -0
- package/es/Form/ServerErrorContext.js +1 -0
- package/es/FormActions.d.ts +6 -0
- package/es/FormActions.js +1 -0
- package/es/FormDefaults.d.ts +1 -0
- package/es/FormDefaults.js +1 -0
- package/es/Group.d.ts +5 -3
- package/es/Group.js +2 -2
- package/es/Input/IconInputGroup.d.ts +3 -0
- package/es/Input/IconInputGroup.js +1 -0
- package/es/Input/InputGroup.d.ts +1 -1
- package/es/Input/InputGroup.js +2 -2
- package/es/Input/MoneyInputGroup.d.ts +2 -0
- package/es/Input/MoneyInputGroup.js +1 -0
- package/es/Input/NumberInputGroup.d.ts +2 -0
- package/es/Input/NumberInputGroup.js +1 -0
- package/es/Input/StringInputGroup.d.ts +1 -0
- package/es/Input/StringInputGroup.js +1 -0
- package/es/Normalization/normalizers.d.ts +2 -0
- package/es/Normalization/normalizers.js +2 -0
- package/es/Select/BooleanSelectGroup.d.ts +1 -0
- package/es/Select/BooleanSelectGroup.js +1 -0
- package/es/Select/NumberSelectGroup.d.ts +2 -0
- package/es/Select/NumberSelectGroup.js +2 -0
- package/es/Select/SelectGroup.d.ts +6 -0
- package/es/Select/SelectGroup.js +1 -0
- package/es/Select/StringSelectGroup.d.ts +2 -0
- package/es/Select/StringSelectGroup.js +2 -0
- package/es/StandardFormActions.d.ts +5 -0
- package/es/StandardFormActions.js +1 -0
- package/es/SubmitFormButton.d.ts +3 -0
- package/es/SubmitFormButton.js +1 -0
- package/es/TextArea/TextAreaGroup.d.ts +1 -0
- package/es/TextArea/TextAreaGroup.js +1 -1
- package/es/Validation/validators.d.ts +3 -0
- package/es/Validation/validators.js +3 -2
- package/es/setupTests.d.ts +1 -0
- package/es/setupTests.js +1 -0
- package/lib/AddressInput/AddressInput.d.ts +10 -0
- package/lib/AddressInput/AddressInput.js +10 -0
- package/lib/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
- package/lib/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
- package/lib/DatePicker/DatePickerGroup.d.ts +5 -0
- package/lib/DatePicker/DatePickerGroup.js +5 -0
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/lib/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/lib/DatePicker/StringDatePickerGroup.d.ts +5 -0
- package/lib/DatePicker/StringDatePickerGroup.js +5 -0
- package/lib/Field/Field.d.ts +6 -0
- package/lib/Field/FieldErrorScrollTarget.d.ts +1 -0
- package/lib/Field/FieldErrorScrollTarget.js +1 -0
- package/lib/Field/StandAloneInput.d.ts +4 -0
- package/lib/Field/StandAloneInput.js +1 -0
- package/lib/Field/useStandardField.d.ts +6 -0
- package/lib/Field/useStandardField.js +8 -9
- package/lib/FieldArray/FieldArray.d.ts +9 -0
- package/lib/FieldArray/FieldArray.js +5 -0
- package/lib/File/FileGroup.d.ts +2 -0
- package/lib/File/FileGroup.js +1 -0
- package/lib/Form/FocusError.d.ts +2 -0
- package/lib/Form/FocusError.js +1 -0
- package/lib/Form/Form.d.ts +6 -0
- package/lib/Form/Form.js +1 -0
- package/lib/Form/FormBasedPreventNavigation.d.ts +3 -1
- package/lib/Form/FormBasedPreventNavigation.js +13 -60
- package/lib/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
- package/lib/Form/LegacyFormBasedPreventNavigation.js +72 -0
- package/lib/Form/NewFormBasedPreventNavigation.d.ts +14 -0
- package/lib/Form/NewFormBasedPreventNavigation.js +42 -0
- package/lib/Form/ServerErrorContext.d.ts +1 -0
- package/lib/Form/ServerErrorContext.js +1 -0
- package/lib/FormActions.d.ts +6 -0
- package/lib/FormActions.js +1 -0
- package/lib/FormDefaults.d.ts +1 -0
- package/lib/FormDefaults.js +1 -0
- package/lib/Group.d.ts +5 -3
- package/lib/Group.js +2 -2
- package/lib/Input/IconInputGroup.d.ts +3 -0
- package/lib/Input/IconInputGroup.js +1 -0
- package/lib/Input/InputGroup.d.ts +1 -1
- package/lib/Input/InputGroup.js +2 -2
- package/lib/Input/MoneyInputGroup.d.ts +2 -0
- package/lib/Input/MoneyInputGroup.js +1 -0
- package/lib/Input/NumberInputGroup.d.ts +2 -0
- package/lib/Input/NumberInputGroup.js +1 -0
- package/lib/Input/StringInputGroup.d.ts +1 -0
- package/lib/Input/StringInputGroup.js +1 -0
- package/lib/Normalization/normalizers.d.ts +2 -0
- package/lib/Normalization/normalizers.js +2 -0
- package/lib/Select/BooleanSelectGroup.d.ts +1 -0
- package/lib/Select/BooleanSelectGroup.js +1 -0
- package/lib/Select/NumberSelectGroup.d.ts +2 -0
- package/lib/Select/NumberSelectGroup.js +2 -0
- package/lib/Select/SelectGroup.d.ts +6 -0
- package/lib/Select/SelectGroup.js +1 -0
- package/lib/Select/StringSelectGroup.d.ts +2 -0
- package/lib/Select/StringSelectGroup.js +2 -0
- package/lib/StandardFormActions.d.ts +5 -0
- package/lib/StandardFormActions.js +1 -0
- package/lib/SubmitFormButton.d.ts +3 -0
- package/lib/SubmitFormButton.js +1 -0
- package/lib/TextArea/TextAreaGroup.d.ts +1 -0
- package/lib/TextArea/TextAreaGroup.js +1 -1
- package/lib/Validation/validators.d.ts +3 -0
- package/lib/Validation/validators.js +3 -2
- package/lib/setupTests.d.ts +1 -0
- package/lib/setupTests.js +3 -0
- package/package.json +9 -6
- package/src/AddressInput/AddressInput.tsx +10 -0
- package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +4 -0
- package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +14 -0
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +13 -0
- package/src/DatePicker/DatePicker.test.tsx +1 -1
- package/src/DatePicker/DatePickerGroup.tsx +5 -2
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +5 -0
- package/src/DatePicker/StringDatePickerGroup.tsx +6 -0
- package/src/Field/Field.tsx +6 -1
- package/src/Field/FieldErrorScrollTarget.tsx +1 -0
- package/src/Field/StandAloneInput.tsx +4 -0
- package/src/Field/useStandardField.ts +13 -9
- package/src/FieldArray/FieldArray.tsx +9 -0
- package/src/File/FileGroup.tsx +2 -0
- package/src/Form/FocusError.tsx +3 -0
- package/src/Form/Form.tsx +6 -0
- package/src/Form/FormBasedPreventNavigation.tsx +26 -60
- package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -0
- package/src/Form/NewFormBasedPreventNavigation.tsx +59 -0
- package/src/Form/ServerErrorContext.ts +1 -0
- package/src/FormActions.tsx +7 -0
- package/src/FormDefaults.ts +1 -0
- package/src/Group.tsx +8 -4
- package/src/Input/IconInputGroup.tsx +3 -0
- package/src/Input/InputGroup.tsx +3 -1
- package/src/Input/MoneyInputGroup.tsx +2 -0
- package/src/Input/NumberInputGroup.tsx +2 -0
- package/src/Input/StringInputGroup.tsx +1 -0
- package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +1 -0
- package/src/Normalization/normalizers.ts +2 -0
- package/src/Select/BooleanSelectGroup.tsx +1 -0
- package/src/Select/NumberSelectGroup.tsx +2 -0
- package/src/Select/SelectGroup.tsx +6 -0
- package/src/Select/StringSelectGroup.tsx +2 -0
- package/src/StandardFormActions.tsx +5 -0
- package/src/SubmitFormButton.tsx +3 -0
- package/src/TextArea/TextAreaGroup.tsx +1 -1
- package/src/Validation/validators.ts +3 -2
- package/src/__Tests__/FormTestBase.tsx +7 -6
- package/src/__Tests__/RealisticForm.test.tsx +82 -0
- package/src/setupTests.ts +1 -0
- package/es/__Tests__/FormTestBase.d.ts +0 -27
- package/es/__Tests__/FormTestBase.js +0 -83
- package/es/__Tests__/index.d.ts +0 -2
- package/es/__Tests__/index.js +0 -2
- package/lib/__Tests__/FormTestBase.d.ts +0 -27
- package/lib/__Tests__/FormTestBase.js +0 -86
- package/lib/__Tests__/index.d.ts +0 -2
- package/lib/__Tests__/index.js +0 -8
@@ -11,5 +11,15 @@ interface AddressDto {
|
|
11
11
|
city?: string | null;
|
12
12
|
state?: string | null;
|
13
13
|
}
|
14
|
+
/**
|
15
|
+
* Collection of `<Field/>`s for inputting an address. Includes:
|
16
|
+
* ```txt
|
17
|
+
* Address 1
|
18
|
+
* Address 2
|
19
|
+
* City
|
20
|
+
* State
|
21
|
+
* Zip
|
22
|
+
* ```
|
23
|
+
*/
|
14
24
|
export default function AddressInput({ fieldBuilder: { Field }, name, }: AddressInputProps): JSX.Element;
|
15
25
|
export {};
|
@@ -15,6 +15,16 @@ import { SingleStringSelectGroup, StringInputGroup } from '../';
|
|
15
15
|
import FieldSection from '../Field/FieldSection';
|
16
16
|
import { zipCode as zipCodeNormalizer } from '../Normalization/normalizers';
|
17
17
|
import { required, zipCode as zipCodeValidator, } from '../Validation/validators';
|
18
|
+
/**
|
19
|
+
* Collection of `<Field/>`s for inputting an address. Includes:
|
20
|
+
* ```txt
|
21
|
+
* Address 1
|
22
|
+
* Address 2
|
23
|
+
* City
|
24
|
+
* State
|
25
|
+
* Zip
|
26
|
+
* ```
|
27
|
+
*/
|
18
28
|
export default function AddressInput(_a) {
|
19
29
|
var Field = _a.fieldBuilder.Field, name = _a.name;
|
20
30
|
return (_jsx(_Fragment, { children: _jsxs(FieldSection, __assign({ name: name }, { children: [_jsx(Field, { name: "address1", placeholder: "Address, Line 1", label: "Address 1", Component: StringInputGroup, validate: required }), _jsx(Field, { name: "address2", placeholder: "Address, Line 2", label: "Address 2", Component: StringInputGroup }), _jsx(Field, { name: "city", placeholder: "City", label: "City", Component: StringInputGroup, validate: required }), _jsx(Field, { name: "state", placeholder: "State", label: "State", Component: SingleStringSelectGroup, options: UsStates, validate: required }), _jsx(Field, { name: "zipCode", placeholder: "Zip", label: "Zip", Component: StringInputGroup, normalize: zipCodeNormalizer, validate: [required, zipCodeValidator] })] })) }));
|
@@ -1,12 +1,26 @@
|
|
1
1
|
import React, { MouseEventHandler } from 'react';
|
2
2
|
import { useAxiosRequestProps } from 'envoc-request';
|
3
3
|
export interface ConfirmBaseFormProps {
|
4
|
+
/** Function to run when cancel button is clicked. */
|
4
5
|
handleCancel?: MouseEventHandler<HTMLButtonElement>;
|
6
|
+
/** Axios request upon confirmation */
|
5
7
|
request: useAxiosRequestProps;
|
6
8
|
style?: React.CSSProperties;
|
9
|
+
/** `<h3/>` title text on top of the form. */
|
7
10
|
title?: string;
|
11
|
+
/** Custom confirm button text.
|
12
|
+
* @defaultValue `Confirm`
|
13
|
+
*/
|
8
14
|
confirmButtonText?: string;
|
15
|
+
/** CSS class for the buttons. */
|
9
16
|
confirmButtonClass?: string;
|
17
|
+
/** Any components to be rendered in between the title and the buttons. */
|
10
18
|
children?: React.ReactNode;
|
11
19
|
}
|
20
|
+
/**
|
21
|
+
* Confimation dialog. Navigates to a different route to allow the user to either confirm or cancel an action.
|
22
|
+
* Commonly used for confirming delete and archive.
|
23
|
+
*
|
24
|
+
* See `<ConfirmDeleteForm/>` if the confirmation is specifically for deletion.
|
25
|
+
*/
|
12
26
|
export default function ConfirmBaseForm({ handleCancel, request, style, title, confirmButtonText, confirmButtonClass, children, ...props }: ConfirmBaseFormProps): JSX.Element;
|
@@ -25,6 +25,12 @@ import classNames from 'classnames';
|
|
25
25
|
import { useAxiosRequest } from 'envoc-request';
|
26
26
|
import { FormDefaults } from '../FormDefaults';
|
27
27
|
// TODO: ask about how we should use 'children'
|
28
|
+
/**
|
29
|
+
* Confimation dialog. Navigates to a different route to allow the user to either confirm or cancel an action.
|
30
|
+
* Commonly used for confirming delete and archive.
|
31
|
+
*
|
32
|
+
* See `<ConfirmDeleteForm/>` if the confirmation is specifically for deletion.
|
33
|
+
*/
|
28
34
|
export default function ConfirmBaseForm(_a) {
|
29
35
|
var handleCancel = _a.handleCancel, request = _a.request, style = _a.style, title = _a.title, confirmButtonText = _a.confirmButtonText, confirmButtonClass = _a.confirmButtonClass, children = _a.children, props = __rest(_a, ["handleCancel", "request", "style", "title", "confirmButtonText", "confirmButtonClass", "children"]);
|
30
36
|
var webRequest = useAxiosRequest(Object.assign({}, request, { autoExecute: false }));
|
@@ -1,11 +1,24 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { ConfirmBaseFormProps } from '../ConfirmBaseForm/ConfirmBaseForm';
|
3
3
|
export interface ConfirmDeleteFormProps extends Pick<ConfirmBaseFormProps, 'style'> {
|
4
|
+
/** Url to navigate to on success. */
|
4
5
|
successUrl?: string;
|
6
|
+
/** Form name (key) to apply the confirmation on. */
|
5
7
|
form: string;
|
8
|
+
/** Custom message to display.
|
9
|
+
* @defaultValue `Are you sure you want to delete this?`
|
10
|
+
*/
|
6
11
|
title?: string;
|
12
|
+
/** Custom function when the axios request succeeds. */
|
7
13
|
handleComplete?: Function;
|
14
|
+
/** Custom function when the axios request fails. */
|
8
15
|
handleError?: Function;
|
16
|
+
/** Any components to be rendered in between the title and the buttons. */
|
9
17
|
children?: React.ReactNode;
|
10
18
|
}
|
19
|
+
/**
|
20
|
+
* Deletion confirmation. Navigates to a different route to allow the user to either confirm or cancel an action.
|
21
|
+
*
|
22
|
+
* Wraps `<ConfirmBaseForm/>`.
|
23
|
+
*/
|
11
24
|
export default function ConfirmDeleteForm({ successUrl, form, title, handleComplete, handleError, children, ...props }: ConfirmDeleteFormProps): JSX.Element;
|
@@ -25,6 +25,11 @@ import { useNavigate, useParams } from 'react-router-dom';
|
|
25
25
|
import { toast } from 'react-toastify';
|
26
26
|
import ConfirmBaseForm from '../ConfirmBaseForm/ConfirmBaseForm';
|
27
27
|
import { FormDefaults } from '../FormDefaults';
|
28
|
+
/**
|
29
|
+
* Deletion confirmation. Navigates to a different route to allow the user to either confirm or cancel an action.
|
30
|
+
*
|
31
|
+
* Wraps `<ConfirmBaseForm/>`.
|
32
|
+
*/
|
28
33
|
export default function ConfirmDeleteForm(_a) {
|
29
34
|
var successUrl = _a.successUrl, form = _a.form, title = _a.title, handleComplete = _a.handleComplete, handleError = _a.handleError, children = _a.children, props = __rest(_a, ["successUrl", "form", "title", "handleComplete", "handleError", "children"]);
|
30
35
|
var navigate = useNavigate();
|
@@ -5,5 +5,10 @@ import { GroupProps } from '../Group';
|
|
5
5
|
export interface DatePickerGroupProps<T> extends InjectedFieldProps<T | undefined | null>, Omit<DatePickerProps, keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'>, Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
|
6
6
|
convert: (arg: Date) => T;
|
7
7
|
}
|
8
|
+
/**
|
9
|
+
* Field for inputting dates. Uses `<Group/>` and `<DatePicker/>`.
|
10
|
+
*
|
11
|
+
* Uses [react-date-picker](https://www.npmjs.com/package/react-date-picker)
|
12
|
+
*/
|
8
13
|
export default function DatePickerGroup<T>({ input, meta, label, helpText, className, required, disabled, convert, ...rest }: DatePickerGroupProps<T>): JSX.Element;
|
9
14
|
export declare function convertToTimeZoneInsensitiveISOString(date: Date): string;
|
@@ -27,6 +27,11 @@ import classnames from 'classnames';
|
|
27
27
|
import parseISO from 'date-fns/parseISO';
|
28
28
|
import { FormDefaults } from '../FormDefaults';
|
29
29
|
import Group from '../Group';
|
30
|
+
/**
|
31
|
+
* Field for inputting dates. Uses `<Group/>` and `<DatePicker/>`.
|
32
|
+
*
|
33
|
+
* Uses [react-date-picker](https://www.npmjs.com/package/react-date-picker)
|
34
|
+
*/
|
30
35
|
export default function DatePickerGroup(_a) {
|
31
36
|
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, convert = _a.convert, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "convert"]);
|
32
37
|
var _b = useState(null), displayDate = _b[0], setDisplayDate = _b[1];
|
@@ -2,4 +2,9 @@
|
|
2
2
|
import { DatePickerHelper } from './DatePickerHelper';
|
3
3
|
export interface StringDateOnlyPickerGroupProps extends DatePickerHelper<string | undefined | null> {
|
4
4
|
}
|
5
|
+
/**
|
6
|
+
* Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DD`.
|
7
|
+
*
|
8
|
+
* Default display to the user is in `MM/DD/YYYY` format.
|
9
|
+
*/
|
5
10
|
export default function StringDatePickerGroup(props: StringDateOnlyPickerGroupProps): JSX.Element;
|
@@ -11,6 +11,11 @@ var __assign = (this && this.__assign) || function () {
|
|
11
11
|
};
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
13
13
|
import DatePickerGroup from './DatePickerGroup';
|
14
|
+
/**
|
15
|
+
* Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DD`.
|
16
|
+
*
|
17
|
+
* Default display to the user is in `MM/DD/YYYY` format.
|
18
|
+
*/
|
14
19
|
export default function StringDatePickerGroup(props) {
|
15
20
|
return _jsx(DatePickerGroup, __assign({}, props, { convert: convertToDateOnly }));
|
16
21
|
}
|
@@ -2,4 +2,9 @@
|
|
2
2
|
import { DatePickerHelper } from './DatePickerHelper';
|
3
3
|
export interface StringDatePickerGroupProps extends DatePickerHelper<string | undefined | null> {
|
4
4
|
}
|
5
|
+
/**
|
6
|
+
* Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DDTHH:mm:ss.sssZ` or `±YYYYYY-MM-DDTHH:mm:ss.sssZ`
|
7
|
+
*
|
8
|
+
* If you need `YYYY-MM-DD` format use `<StringDateOnlyPickerGroup/>`.
|
9
|
+
*/
|
5
10
|
export default function StringDatePickerGroup(props: StringDatePickerGroupProps): JSX.Element;
|
@@ -11,6 +11,11 @@ var __assign = (this && this.__assign) || function () {
|
|
11
11
|
};
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
13
13
|
import DatePickerGroup from './DatePickerGroup';
|
14
|
+
/**
|
15
|
+
* Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DDTHH:mm:ss.sssZ` or `±YYYYYY-MM-DDTHH:mm:ss.sssZ`
|
16
|
+
*
|
17
|
+
* If you need `YYYY-MM-DD` format use `<StringDateOnlyPickerGroup/>`.
|
18
|
+
*/
|
14
19
|
export default function StringDatePickerGroup(props) {
|
15
20
|
return _jsx(DatePickerGroup, __assign({}, props, { convert: convertToDateOnly }));
|
16
21
|
}
|
package/es/Field/Field.d.ts
CHANGED
@@ -6,11 +6,17 @@ export declare type RenderComponent<TValue, TRenderComponent extends ElementType
|
|
6
6
|
export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined | null>> ? ComponentProps<TRenderComponent> : never;
|
7
7
|
/** A specific Field instance to be rendered by the given TRenderComponent or by whatever default is reasonable */
|
8
8
|
export declare type FieldProps<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType> = {
|
9
|
+
/** Name of the field. Used on submission. */
|
9
10
|
name: TProp;
|
11
|
+
/** Component to be rendered. Usually this is a type of input group e.g. `<StringInputGroup/>` */
|
10
12
|
Component: RenderComponent<TForm[TProp], TRenderComponent>;
|
13
|
+
/** Id of the field. */
|
11
14
|
id?: string;
|
15
|
+
/** Whether the field should be disabled. */
|
12
16
|
disabled?: boolean;
|
17
|
+
/** Client side validation functions */
|
13
18
|
validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
|
19
|
+
/** Function to modify the field value without making the form dirty. (e.g. phone number) */
|
14
20
|
normalize?: NormalizationFunction<TForm[TProp]>;
|
15
21
|
} & Omit<RenderComponentProps<TForm[TProp], TRenderComponent>, keyof InjectedFieldProps<TForm[TProp]>>;
|
16
22
|
/**
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { useContext } from 'react';
|
3
3
|
import { FieldNameContext } from './FieldNameContext';
|
4
|
+
/** Hidden `<div/>` that acts as an anchor to scroll to when a form error occurs. */
|
4
5
|
export default function FieldErrorScrollTarget() {
|
5
6
|
var name = useContext(FieldNameContext);
|
6
7
|
if (!name) {
|
@@ -2,8 +2,12 @@ import { ElementType } from 'react';
|
|
2
2
|
import { RenderComponent, RenderComponentProps } from './Field';
|
3
3
|
import { InjectedFieldProps } from './InjectedFieldProps';
|
4
4
|
export declare type StandAloneInputProps<TValue, TRenderComponent extends ElementType> = {
|
5
|
+
/** Component to render inside of the field. */
|
5
6
|
Component: RenderComponent<TValue, TRenderComponent>;
|
7
|
+
/** Value of the field. */
|
6
8
|
value: TValue;
|
9
|
+
/** Function to change the value of the field. */
|
7
10
|
onChange: (arg: TValue) => void;
|
8
11
|
} & Omit<RenderComponentProps<TValue, TRenderComponent>, keyof InjectedFieldProps<TValue> | 'value' | 'onChange' | 'normalize' | 'validate'>;
|
12
|
+
/** The stand alone version of `<Field/>`. Can use a type of input component outside of a `<Form/>`. */
|
9
13
|
export default function StandAloneInput<TValue, TComponent extends ElementType>(props: StandAloneInputProps<TValue, TComponent>): JSX.Element;
|
@@ -23,6 +23,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
24
24
|
import { useRef } from 'react';
|
25
25
|
import * as uuid from 'uuid';
|
26
|
+
/** The stand alone version of `<Field/>`. Can use a type of input component outside of a `<Form/>`. */
|
26
27
|
export default function StandAloneInput(props) {
|
27
28
|
var Component = props.Component, value = props.value, onChange = props.onChange, disabled = props.disabled, rest = __rest(props, ["Component", "value", "onChange", "disabled"]);
|
28
29
|
var handleChange = function (arg) {
|
@@ -3,12 +3,18 @@ import { CustomFieldMetaProps } from './CustomFieldMetaProps';
|
|
3
3
|
import { NormalizationFunction } from '../Normalization/NormalizationFunction';
|
4
4
|
import { ValidationFunction } from '../Validation/ValidationFunction';
|
5
5
|
export interface useStandardFieldProps<TValue> {
|
6
|
+
/** Id of the field. */
|
6
7
|
id?: string;
|
8
|
+
/** Name of the field. */
|
7
9
|
name: string;
|
10
|
+
/** Whether the field should be disabled. */
|
8
11
|
disabled?: boolean;
|
12
|
+
/** Function to validate the field. */
|
9
13
|
validate?: ValidationFunction<TValue> | ValidationFunction<TValue>[];
|
14
|
+
/** Function to modify the field value without making the form dirty. (e.g. phone number) */
|
10
15
|
normalize?: NormalizationFunction<TValue>;
|
11
16
|
}
|
17
|
+
/** Provides a consistent way to deal with all form fields (non array). */
|
12
18
|
export default function useStandardField<TValue>({ id: providedId, name: providedName, disabled, validate, normalize, }: useStandardFieldProps<TValue>): [
|
13
19
|
CustomFieldInputProps<TValue>,
|
14
20
|
CustomFieldMetaProps<TValue>
|
@@ -13,7 +13,7 @@ import { useContext, useEffect } from 'react';
|
|
13
13
|
import { useField, useFormikContext } from 'formik';
|
14
14
|
import { FieldNameContext } from './FieldNameContext';
|
15
15
|
import { ServerErrorContext } from '../Form/ServerErrorContext';
|
16
|
-
|
16
|
+
/** Provides a consistent way to deal with all form fields (non array). */
|
17
17
|
export default function useStandardField(_a) {
|
18
18
|
var providedId = _a.id, providedName = _a.name, disabled = _a.disabled, validate = _a.validate, normalize = _a.normalize;
|
19
19
|
// because the formik errors are evaluated all at the same time we need to keep server errors separate
|
@@ -37,20 +37,19 @@ export default function useStandardField(_a) {
|
|
37
37
|
disabled: disabled,
|
38
38
|
validate: callAllValidators,
|
39
39
|
}), formikInput = _c[0], formikMeta = _c[1];
|
40
|
-
var _d = useFormikContext(), setFieldValue = _d.setFieldValue, isSubmitting = _d.isSubmitting;
|
40
|
+
var _d = useFormikContext(), setFieldTouched = _d.setFieldTouched, setFieldValue = _d.setFieldValue, isSubmitting = _d.isSubmitting;
|
41
41
|
var touched = formikMeta.touched !== false && formikMeta.touched !== undefined;
|
42
42
|
useEffect(function () {
|
43
43
|
if (!touched && isSubmitting) {
|
44
44
|
// because we do not always register all fields up front.
|
45
45
|
// e.g. formik expects even a 'create' form to have all fields given, at least, blank values
|
46
|
-
//
|
47
|
-
//
|
48
|
-
//
|
49
|
-
//
|
50
|
-
|
51
|
-
handleBlur();
|
46
|
+
// It looks like this was going to be a thing: https://github.com/jaredpalmer/formik/issues/691
|
47
|
+
// Formik appears to not have an active maintainer: https://github.com/jaredpalmer/formik/discussions/3526
|
48
|
+
// We previously had a different fix in place using handleBlur, but it was causing an infinite update cycle.
|
49
|
+
// This was noted as existing, but there was a note about it not working for FieldArray (this does appear to work in my testing with FieldArray)
|
50
|
+
setFieldTouched(name);
|
52
51
|
}
|
53
|
-
});
|
52
|
+
}, [isSubmitting, name, setFieldTouched, touched]);
|
54
53
|
// these are the props we expect consumers of this hook to pass directly to the input (or other control)
|
55
54
|
var resultInput = {
|
56
55
|
name: formikInput.name,
|
@@ -2,9 +2,13 @@ import { ElementType } from 'react';
|
|
2
2
|
import { FieldProps } from '../Field/Field';
|
3
3
|
import { ValidationFunction } from '../Validation/ValidationFunction';
|
4
4
|
export declare type FieldArrayProps<TForm extends object, TProp extends keyof TForm> = TForm[TProp] extends Array<any> | undefined | null ? {
|
5
|
+
/** Name of the field, used on submission. If using codegen this must be the provided dto. */
|
5
6
|
name: TProp;
|
7
|
+
/** Label of the field. */
|
6
8
|
label?: string;
|
9
|
+
/** Whether the field should be disabled. */
|
7
10
|
disabled?: boolean;
|
11
|
+
/** Function to validate the value. */
|
8
12
|
validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
|
9
13
|
children: (formBuilder: ArrayFormBuilderProp<TForm[TProp]>) => JSX.Element;
|
10
14
|
} : never;
|
@@ -12,4 +16,9 @@ export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined |
|
|
12
16
|
Field: <TProp extends keyof TForm, TRenderComponent extends ElementType>(props: FieldProps<TForm, TProp, TRenderComponent>) => JSX.Element;
|
13
17
|
FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
|
14
18
|
} : never : never;
|
19
|
+
/**
|
20
|
+
* An array of fields that allows the user to add multiple instances of the same field.
|
21
|
+
*
|
22
|
+
* Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
|
23
|
+
*/
|
15
24
|
export default function FieldArray<TForm extends object, TProp extends keyof TForm>({ name, label, validate, disabled, children, ...rest }: FieldArrayProps<TForm, TProp>): JSX.Element;
|
@@ -35,6 +35,11 @@ import Field from '../Field/Field';
|
|
35
35
|
import { FieldNameContext } from '../Field/FieldNameContext';
|
36
36
|
import useStandardFormInput from '../Field/useStandardField';
|
37
37
|
import { FormDefaults } from '../FormDefaults';
|
38
|
+
/**
|
39
|
+
* An array of fields that allows the user to add multiple instances of the same field.
|
40
|
+
*
|
41
|
+
* Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
|
42
|
+
*/
|
38
43
|
export default function FieldArray(_a) {
|
39
44
|
var _b;
|
40
45
|
var name = _a.name, label = _a.label, validate = _a.validate, disabled = _a.disabled, children = _a.children, rest = __rest(_a, ["name", "label", "validate", "disabled", "children"]);
|
package/es/File/FileGroup.d.ts
CHANGED
@@ -2,7 +2,9 @@ import React from 'react';
|
|
2
2
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
3
3
|
import { GroupProps } from '../Group';
|
4
4
|
export interface FileGroupProps extends InjectedFieldProps<any | undefined | null>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'> {
|
5
|
+
/** Allow multiple files to be uploaded. */
|
5
6
|
multiple?: boolean | undefined;
|
6
7
|
}
|
8
|
+
/** File upload input group. */
|
7
9
|
declare const FileGroupWithRef: React.ComponentType<FileGroupProps>;
|
8
10
|
export default FileGroupWithRef;
|
package/es/File/FileGroup.js
CHANGED
@@ -48,5 +48,6 @@ function FileGroup(_a, ref) {
|
|
48
48
|
}
|
49
49
|
}, value: undefined, ref: ref, type: "file", className: classNames(className, FormDefaults.cssClassPrefix + 'file-group') })), _jsx(FileList, { files: input.value })] })));
|
50
50
|
}
|
51
|
+
/** File upload input group. */
|
51
52
|
var FileGroupWithRef = React.forwardRef(FileGroup);
|
52
53
|
export default FileGroupWithRef;
|
package/es/Form/FocusError.d.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { ServerErrorContextProps } from './ServerErrorContext';
|
2
2
|
export interface FocusErrorProps {
|
3
|
+
/** Validation errors that have been received from the server. */
|
3
4
|
serverErrors: ServerErrorContextProps;
|
4
5
|
}
|
6
|
+
/** Function to scroll to the field that has an error. */
|
5
7
|
export default function FocusError(props: FocusErrorProps): null;
|
package/es/Form/FocusError.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { useEffect } from 'react';
|
2
2
|
import { useFormikContext } from 'formik';
|
3
3
|
import smoothscroll from 'smoothscroll-polyfill';
|
4
|
+
/** Function to scroll to the field that has an error. */
|
4
5
|
export default function FocusError(props) {
|
5
6
|
var _a = useFormikContext(), errors = _a.errors, isSubmitting = _a.isSubmitting, isValidating = _a.isValidating;
|
6
7
|
smoothscroll.polyfill();
|
package/es/Form/Form.d.ts
CHANGED
@@ -8,18 +8,24 @@ export declare type FormBuilderProp<TForm extends object> = {
|
|
8
8
|
FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
|
9
9
|
};
|
10
10
|
export interface FullFormProps<TForm extends object> {
|
11
|
+
/** The `<Field/>` and `<FieldArray/>` components. */
|
11
12
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
13
|
+
/** Submission handler */
|
12
14
|
onSubmit: (formValues: TForm, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
|
15
|
+
/** Submission handler for forms that use [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData).*/
|
13
16
|
onFormDataSubmit: (formValues: FormData, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
|
14
17
|
className?: string;
|
15
18
|
style?: CSSProperties;
|
19
|
+
/** Prevent the user from leaving the form if they have edited any field. This is presented as a JS `alert()`. */
|
16
20
|
ignoreLostChanges?: boolean;
|
21
|
+
/** The intitial values of the form. */
|
17
22
|
initialValues?: TForm;
|
18
23
|
}
|
19
24
|
declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
20
25
|
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
21
26
|
}[Keys];
|
22
27
|
export declare type FormProps<TForm extends object> = RequireAtLeastOne<FullFormProps<TForm>, 'onSubmit' | 'onFormDataSubmit'>;
|
28
|
+
/** Define a form. Uses [formik](https://formik.org/docs/overview). Usually contains many `<Field/>` components. */
|
23
29
|
declare function Form<TForm extends object>({ children, className, style, ignoreLostChanges, onSubmit, onFormDataSubmit, initialValues, ...props }: FormProps<TForm>): JSX.Element;
|
24
30
|
declare namespace Form {
|
25
31
|
var DisplayFormState: () => JSX.Element;
|
package/es/Form/Form.js
CHANGED
@@ -32,6 +32,7 @@ import FieldArray from '../FieldArray/FieldArray';
|
|
32
32
|
import { FormDefaults } from '../FormDefaults';
|
33
33
|
import objectContainsNonSerializableProperty from '../utils/objectContainsNonSerializableProperty';
|
34
34
|
import objectToFormData from '../utils/objectToFormData';
|
35
|
+
/** Define a form. Uses [formik](https://formik.org/docs/overview). Usually contains many `<Field/>` components. */
|
35
36
|
export default function Form(_a) {
|
36
37
|
var children = _a.children, className = _a.className, style = _a.style, ignoreLostChanges = _a.ignoreLostChanges, onSubmit = _a.onSubmit, onFormDataSubmit = _a.onFormDataSubmit, initialValues = _a.initialValues, props = __rest(_a, ["children", "className", "style", "ignoreLostChanges", "onSubmit", "onFormDataSubmit", "initialValues"]);
|
37
38
|
// formik resets all error on each blur (with our settings)
|
@@ -1,5 +1,7 @@
|
|
1
|
+
/// <reference types="react" />
|
1
2
|
export interface FormBasedPreventNavigationProps {
|
2
3
|
ignoreLostChanges?: boolean;
|
3
4
|
promptMessage?: string;
|
4
5
|
}
|
5
|
-
|
6
|
+
/** Prevent the user from navigating away from a form if there are any changes. */
|
7
|
+
export default function FormBasedPreventNavigation({ ignoreLostChanges, promptMessage, }: FormBasedPreventNavigationProps): JSX.Element;
|
@@ -1,70 +1,20 @@
|
|
1
|
-
|
2
|
-
|
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 { useContext, useEffect } from 'react';
|
13
|
-
// see: https://gist.github.com/rmorse/426ffcc579922a82749934826fa9f743
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { useContext } from 'react';
|
14
3
|
import { UNSAFE_NavigationContext as NavigationContext, } from 'react-router-dom';
|
15
4
|
import { useFormikContext } from 'formik';
|
5
|
+
import LegacyFormBasedPreventNavigation from './LegacyFormBasedPreventNavigation';
|
6
|
+
import NewFormBasedPreventNavigation from './NewFormBasedPreventNavigation';
|
7
|
+
/** Prevent the user from navigating away from a form if there are any changes. */
|
16
8
|
export default function FormBasedPreventNavigation(_a) {
|
17
9
|
var ignoreLostChanges = _a.ignoreLostChanges, _b = _a.promptMessage, promptMessage = _b === void 0 ? 'Changes you made may not be saved.' : _b;
|
18
10
|
var _c = useFormikContext(), dirty = _c.dirty, isSubmitting = _c.isSubmitting;
|
19
11
|
var preventNavigate = !ignoreLostChanges && dirty && !isSubmitting;
|
20
12
|
var navigator = useContext(NavigationContext).navigator;
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
// this is a workaround until we get native support for prompt on navigate
|
29
|
-
if (navigator.block) {
|
30
|
-
var blocker_1 = function (tx) {
|
31
|
-
if (window.confirm(promptMessage)) {
|
32
|
-
tx.retry();
|
33
|
-
}
|
34
|
-
};
|
35
|
-
unblock = navigator.block(function (tx) {
|
36
|
-
var autoUnblockingTx = __assign(__assign({}, tx), { retry: function () {
|
37
|
-
// Automatically unblock the transition so it can play all the way
|
38
|
-
// through before retrying it. TODO: Figure out how to re-enable
|
39
|
-
// this block if the transition is cancelled for some reason.
|
40
|
-
unblock();
|
41
|
-
tx.retry();
|
42
|
-
} });
|
43
|
-
blocker_1(autoUnblockingTx);
|
44
|
-
});
|
45
|
-
}
|
46
|
-
else {
|
47
|
-
//https://gist.github.com/MarksCode/64e438c82b0b2a1161e01c88ca0d0355
|
48
|
-
navigator.push = function () {
|
49
|
-
var args = [];
|
50
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
51
|
-
args[_i] = arguments[_i];
|
52
|
-
}
|
53
|
-
if (window.confirm(promptMessage)) {
|
54
|
-
push.apply(void 0, args);
|
55
|
-
}
|
56
|
-
};
|
57
|
-
}
|
58
|
-
window.addEventListener('beforeunload', beforeUnload);
|
59
|
-
return function () {
|
60
|
-
unblock();
|
61
|
-
navigator.push = push;
|
62
|
-
window.removeEventListener('beforeunload', beforeUnload);
|
63
|
-
};
|
64
|
-
function beforeUnload(e) {
|
65
|
-
e.preventDefault();
|
66
|
-
e.returnValue = promptMessage;
|
67
|
-
}
|
68
|
-
}, [preventNavigate, promptMessage, navigator]);
|
69
|
-
return null;
|
13
|
+
var isUsingDataRouter = navigator.location === undefined;
|
14
|
+
if (isUsingDataRouter) {
|
15
|
+
return (_jsx(NewFormBasedPreventNavigation, { promptMessage: promptMessage, preventNavigate: preventNavigate, navigator: navigator }));
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
return (_jsx(LegacyFormBasedPreventNavigation, { promptMessage: promptMessage, preventNavigate: preventNavigate, navigator: navigator }));
|
19
|
+
}
|
70
20
|
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { History } from 'history';
|
2
|
+
import { Navigator as BaseNavigator } from 'react-router-dom';
|
3
|
+
interface Navigator extends BaseNavigator {
|
4
|
+
block?: History['block'];
|
5
|
+
}
|
6
|
+
export interface FormBasedPreventNavigationProps {
|
7
|
+
promptMessage?: string;
|
8
|
+
preventNavigate: boolean;
|
9
|
+
navigator: Navigator;
|
10
|
+
}
|
11
|
+
/** Only use this if the project uses `<BrowserRouter/>` or any router that does not support the new
|
12
|
+
* [react-router Data API](https://reactrouter.com/en/main/routers/picking-a-router#using-v64-data-apis)
|
13
|
+
*
|
14
|
+
* Legacy function to prevent the user from navigating away from a form if there are any changes.
|
15
|
+
*/
|
16
|
+
export default function LegacyFormBasedPreventNavigation({ promptMessage, preventNavigate, navigator, }: FormBasedPreventNavigationProps): null;
|
17
|
+
export {};
|
@@ -0,0 +1,69 @@
|
|
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 { useEffect } from 'react';
|
13
|
+
/** Only use this if the project uses `<BrowserRouter/>` or any router that does not support the new
|
14
|
+
* [react-router Data API](https://reactrouter.com/en/main/routers/picking-a-router#using-v64-data-apis)
|
15
|
+
*
|
16
|
+
* Legacy function to prevent the user from navigating away from a form if there are any changes.
|
17
|
+
*/
|
18
|
+
export default function LegacyFormBasedPreventNavigation(_a) {
|
19
|
+
var _b = _a.promptMessage, promptMessage = _b === void 0 ? 'Changes you made may not be saved.' : _b, preventNavigate = _a.preventNavigate, navigator = _a.navigator;
|
20
|
+
useEffect(function () {
|
21
|
+
if (!preventNavigate) {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
var unblock = function () { };
|
25
|
+
var push = navigator.push;
|
26
|
+
// TODO: https://reactrouter.com/docs/en/v6/upgrading/v5#prompt-is-not-currently-supported
|
27
|
+
// this is a workaround until we get native support for prompt on navigate
|
28
|
+
if (navigator.block) {
|
29
|
+
var blocker_1 = function (tx) {
|
30
|
+
if (window.confirm(promptMessage)) {
|
31
|
+
tx.retry();
|
32
|
+
}
|
33
|
+
};
|
34
|
+
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();
|
40
|
+
tx.retry();
|
41
|
+
} });
|
42
|
+
blocker_1(autoUnblockingTx);
|
43
|
+
});
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
//https://gist.github.com/MarksCode/64e438c82b0b2a1161e01c88ca0d0355
|
47
|
+
navigator.push = function () {
|
48
|
+
var args = [];
|
49
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
50
|
+
args[_i] = arguments[_i];
|
51
|
+
}
|
52
|
+
if (window.confirm(promptMessage)) {
|
53
|
+
push.apply(void 0, args);
|
54
|
+
}
|
55
|
+
};
|
56
|
+
}
|
57
|
+
window.addEventListener('beforeunload', beforeUnload);
|
58
|
+
return function () {
|
59
|
+
unblock();
|
60
|
+
navigator.push = push;
|
61
|
+
window.removeEventListener('beforeunload', beforeUnload);
|
62
|
+
};
|
63
|
+
function beforeUnload(e) {
|
64
|
+
e.preventDefault();
|
65
|
+
e.returnValue = promptMessage;
|
66
|
+
}
|
67
|
+
}, [preventNavigate, promptMessage, navigator]);
|
68
|
+
return null;
|
69
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { History } from 'history';
|
2
|
+
import { Navigator as BaseNavigator } from 'react-router-dom';
|
3
|
+
interface Navigator extends BaseNavigator {
|
4
|
+
block?: History['block'];
|
5
|
+
location: Location;
|
6
|
+
}
|
7
|
+
interface FormBasedPreventNavigationProps {
|
8
|
+
promptMessage?: string;
|
9
|
+
preventNavigate: boolean;
|
10
|
+
navigator: Navigator;
|
11
|
+
}
|
12
|
+
/** Temporary function to allow backwards compatibility with routers that do not use the new Data API */
|
13
|
+
export default function NewFormBasedPreventNavigation({ promptMessage, preventNavigate, navigator, }: FormBasedPreventNavigationProps): null;
|
14
|
+
export {};
|