taro-form-react 0.3.0 → 0.4.0

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.
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
- import { useFormContext } from "@/context/FormContext";
2
+ import { useFormContext } from "../context/FormContext";
3
+ import { useInnerFormContext } from "../context/InnerFormContext";
3
4
  export type FormProviderProps = {
4
- children: (context: Omit<ReturnType<typeof useFormContext>, "registerField" | "unregisterField" | "setFieldValue" | "setFields" | "resetFields" | "setFieldError" | "setData">) => React.ReactNode;
5
+ children: (context: Omit<ReturnType<typeof useFormContext>, "registerField" | "unregisterField" | "setFieldValue" | "setFields" | "resetFields" | "setFieldError" | "setData"> & ReturnType<typeof useInnerFormContext>) => React.ReactNode;
5
6
  };
6
7
  declare const FormProvider: React.FC<FormProviderProps>;
7
8
  export default FormProvider;
@@ -1,4 +1,4 @@
1
- import type { NamePath } from "@/types";
1
+ import type { NamePath } from "../types";
2
2
  export type FormSyncProps = {
3
3
  source: NamePath;
4
4
  target: NamePath[];
@@ -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,9 +4,9 @@ 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 FormActions = Pick<FormContextProps, "setData" | "setFieldValue" | "getFieldValue" | "getFieldsValue" | "getFieldsFormattedValue" | "setFields" | "getFields" | "resetFields" | "setFieldError" | "getFieldError" | "validateFields" | "isFieldsTouched"> & {
9
+ export type FormActions = Pick<FormContextProps, "setData" | "setFieldValue" | "getFieldValue" | "getFieldsValue" | "getFieldsFormattedValue" | "setFields" | "getFields" | "resetFields" | "setFieldError" | "getFieldError" | "validateFields" | "isFieldsTouched" | "capture" | "restore"> & {
10
10
  submit: () => Promise<Record<string, any> | undefined>;
11
11
  reset: () => void;
12
12
  };
@@ -35,3 +35,4 @@ interface FormComponent extends React.ForwardRefExoticComponent<FormProps & Reac
35
35
  declare const Form: FormComponent;
36
36
  export default Form;
37
37
  export { useFormContext };
38
+ export type { FormSnapshot };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "taro-form-react",
3
3
  "description": "A form component for Taro 3.x based on React",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "browser": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",
7
7
  "main": "dist/index.js",
@@ -52,6 +52,7 @@
52
52
  "rollup-plugin-copy": "^3.5.0",
53
53
  "rollup-plugin-terser": "^7.0.2",
54
54
  "rollup-plugin-typescript2": "^0.36.0",
55
+ "tsc-alias": "^1.8.16",
55
56
  "typescript": "^5.7.3"
56
57
  },
57
58
  "peerDependencies": {