taro-form-react 0.3.1 → 0.4.1
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 +529 -126
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/types/src/components/Provider.d.ts +1 -1
- package/dist/types/src/context/FormContext.d.ts +10 -0
- package/dist/types/src/index.d.ts +4 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { useFormContext } from "../context/FormContext";
|
|
3
3
|
import { useInnerFormContext } from "../context/InnerFormContext";
|
|
4
4
|
export type FormProviderProps = {
|
|
5
|
-
children: (context: Omit<ReturnType<typeof useFormContext>, "registerField" | "unregisterField" | "setFieldValue" | "setFields" | "resetFields" | "setFieldError" | "setData"> & ReturnType<typeof useInnerFormContext>) => React.ReactNode;
|
|
5
|
+
children: (context: Omit<ReturnType<typeof useFormContext>, "registerField" | "unregisterField" | "setFieldValue" | "setFields" | "resetFields" | "setFieldError" | "setData" | "capture" | "restore"> & ReturnType<typeof useInnerFormContext>) => React.ReactNode;
|
|
6
6
|
};
|
|
7
7
|
declare const FormProvider: React.FC<FormProviderProps>;
|
|
8
8
|
export default FormProvider;
|
|
@@ -18,6 +18,14 @@ export type Field = {
|
|
|
18
18
|
initialValue?: any;
|
|
19
19
|
count: number;
|
|
20
20
|
};
|
|
21
|
+
export type FormSnapshotField = {
|
|
22
|
+
touched: boolean;
|
|
23
|
+
errors: string[];
|
|
24
|
+
};
|
|
25
|
+
export type FormSnapshot = {
|
|
26
|
+
data: Record<string, unknown>;
|
|
27
|
+
fields: Record<string, FormSnapshotField>;
|
|
28
|
+
};
|
|
21
29
|
export type FormContextProps = {
|
|
22
30
|
initialValues?: Record<string, any>;
|
|
23
31
|
showError?: boolean;
|
|
@@ -54,6 +62,8 @@ export type FormContextProps = {
|
|
|
54
62
|
isFieldsTouched: (nameList?: NamePath[], options?: {
|
|
55
63
|
allTouched?: boolean;
|
|
56
64
|
}) => boolean;
|
|
65
|
+
capture: () => FormSnapshot;
|
|
66
|
+
restore: (snapshot: FormSnapshot) => void;
|
|
57
67
|
};
|
|
58
68
|
export declare const useFormContext: () => FormContextProps;
|
|
59
69
|
export type FormProviderConfiguration = Pick<FormContextProps, "colon" | "labelProps" | "layout" | "validateFirst" | "showErrors" | "passthroughErrors" | "transformBehavior" | "updateTickLimit" | "getRequiredMessage">;
|
|
@@ -4,11 +4,13 @@ import FormKeep from "./components/Keep";
|
|
|
4
4
|
import FormLabel from "./components/Label";
|
|
5
5
|
import FormProvider from "./components/Provider";
|
|
6
6
|
import FormSync from "./components/Sync";
|
|
7
|
-
import type { Field, FormContextProps, FormProviderConfiguration } from "./context/FormContext";
|
|
7
|
+
import type { Field, FormContextProps, FormProviderConfiguration, FormSnapshot } from "./context/FormContext";
|
|
8
8
|
import { useFormContext } from "./context/FormContext";
|
|
9
|
+
export type FormSnapshotActions = Pick<FormContextProps, "capture" | "restore">;
|
|
9
10
|
export type FormActions = Pick<FormContextProps, "setData" | "setFieldValue" | "getFieldValue" | "getFieldsValue" | "getFieldsFormattedValue" | "setFields" | "getFields" | "resetFields" | "setFieldError" | "getFieldError" | "validateFields" | "isFieldsTouched"> & {
|
|
10
11
|
submit: () => Promise<Record<string, any> | undefined>;
|
|
11
12
|
reset: () => void;
|
|
13
|
+
snapshot: FormSnapshotActions;
|
|
12
14
|
};
|
|
13
15
|
export type FormProps = FormProviderConfiguration & {
|
|
14
16
|
initialValues?: Record<string, any>;
|
|
@@ -35,3 +37,4 @@ interface FormComponent extends React.ForwardRefExoticComponent<FormProps & Reac
|
|
|
35
37
|
declare const Form: FormComponent;
|
|
36
38
|
export default Form;
|
|
37
39
|
export { useFormContext };
|
|
40
|
+
export type { FormSnapshot };
|