react-form-manage 1.0.6-beta.1 → 1.0.6-beta.2
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/CHANGELOG.md +8 -0
- package/dist/components/Form/FormItem.d.ts +11 -17
- package/dist/components/Form/FormList.d.ts +23 -7
- package/dist/components/Form/InputWrapper.d.ts +10 -5
- package/dist/index.d.ts +5 -5
- package/dist/providers/Form.d.ts +15 -10
- package/package.json +1 -1
- package/src/components/Form/FormItem.tsx +14 -2
- package/src/components/Form/FormList.tsx +10 -1
- package/src/components/Form/InputWrapper.tsx +8 -1
- package/src/index.ts +8 -3
- package/src/providers/Form.tsx +14 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.0.6-beta.2] - 2026-01-22
|
|
6
|
+
|
|
7
|
+
- Fix TypeScript prop types for all components
|
|
8
|
+
- Add FormProps interface with proper optional fields
|
|
9
|
+
- Add FormItemProps, FormListProps, InputWrapperProps interfaces
|
|
10
|
+
- Export type interfaces from package
|
|
11
|
+
- Fix type error where Form component required all props
|
|
12
|
+
|
|
5
13
|
## [1.0.6-beta.1] - 2026-01-22
|
|
6
14
|
|
|
7
15
|
- Full TypeScript migration: Convert all source files from JS to TS
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
export interface FormItemProps {
|
|
3
|
+
children: ReactElement;
|
|
4
|
+
name: string;
|
|
5
|
+
formName?: string;
|
|
6
|
+
initialValue?: any;
|
|
7
|
+
formItemId?: string;
|
|
8
|
+
rules?: any[];
|
|
8
9
|
valuePropName?: string;
|
|
9
|
-
getValueFromEvent: any;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
onChange: (e: any) => void;
|
|
13
|
-
isDirty: boolean;
|
|
14
|
-
errors: any;
|
|
15
|
-
onFocus: () => void;
|
|
16
|
-
validateState: any;
|
|
17
|
-
ref: import("react").RefObject<any>;
|
|
18
|
-
}, HTMLElement>;
|
|
10
|
+
getValueFromEvent?: (event: any) => any;
|
|
11
|
+
}
|
|
12
|
+
export default function FormItem({ children, name, formName, initialValue, formItemId: externalFormItemId, rules, valuePropName, getValueFromEvent, }: FormItemProps): ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { FormInstance } from "../../stores/formStore";
|
|
2
|
+
export interface FormListProps<T = any> {
|
|
3
|
+
name: string;
|
|
4
|
+
initialValues?: T[];
|
|
5
|
+
form?: FormInstance;
|
|
6
|
+
formName?: string;
|
|
7
|
+
children: (fields: Array<{
|
|
8
|
+
name: string;
|
|
9
|
+
key: string;
|
|
10
|
+
}>, operations: {
|
|
11
|
+
add: (index: number) => void;
|
|
12
|
+
remove: (opts: {
|
|
13
|
+
index?: number;
|
|
14
|
+
key?: string;
|
|
15
|
+
}) => void;
|
|
16
|
+
move: (opts: {
|
|
17
|
+
from?: number;
|
|
18
|
+
fromKey?: string;
|
|
19
|
+
to: number;
|
|
20
|
+
}) => void;
|
|
21
|
+
}) => React.ReactNode;
|
|
22
|
+
}
|
|
23
|
+
declare const FormList: <T = any>({ name, initialValues, form, formName, children }: FormListProps<T>) => import("react").ReactNode;
|
|
8
24
|
export default FormList;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
children:
|
|
4
|
-
errors?:
|
|
5
|
-
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
export interface InputWrapperProps {
|
|
3
|
+
children: ReactElement;
|
|
4
|
+
errors?: Array<{
|
|
5
|
+
ruleName: string;
|
|
6
|
+
message: string;
|
|
7
|
+
}>;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
declare const InputWrapper: ({ children, errors, ...props }: InputWrapperProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
11
|
export default InputWrapper;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Form, { useForm, useWatch, useSubmitDataWatch, useFormStateWatch } from "./providers/Form";
|
|
2
|
-
import FormItem from "./components/Form/FormItem";
|
|
3
|
-
import FormList from "./components/Form/FormList";
|
|
1
|
+
import Form, { useForm, useWatch, useSubmitDataWatch, useFormStateWatch, type FormProps } from "./providers/Form";
|
|
2
|
+
import FormItem, { type FormItemProps } from "./components/Form/FormItem";
|
|
3
|
+
import FormList, { type FormListProps } from "./components/Form/FormList";
|
|
4
4
|
import Input from "./components/Input";
|
|
5
|
-
import InputWrapper from "./components/Form/InputWrapper";
|
|
5
|
+
import InputWrapper, { type InputWrapperProps } from "./components/Form/InputWrapper";
|
|
6
6
|
import useFormItemControl from "./hooks/useFormItemControl";
|
|
7
7
|
import useFormListControl from "./hooks/useFormListControl";
|
|
8
|
-
export { Form, FormItem, FormList, Input, InputWrapper, useFormItemControl, useFormListControl, useForm, useWatch, useSubmitDataWatch, useFormStateWatch, };
|
|
8
|
+
export { Form, FormItem, FormList, Input, InputWrapper, useFormItemControl, useFormListControl, useForm, useWatch, useSubmitDataWatch, useFormStateWatch, type FormProps, type FormItemProps, type FormListProps, type InputWrapperProps, };
|
|
9
9
|
export default Form;
|
package/dist/providers/Form.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import type { ReactNode, ComponentType, FormHTMLAttributes } from "react";
|
|
1
2
|
import type { PublicFormInstance } from "../types/public";
|
|
2
3
|
export declare const FormContext: import("react").Context<any>;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
export interface FormProps<T = any> extends Omit<FormHTMLAttributes<HTMLFormElement>, 'onSubmit'> {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
formName: string;
|
|
7
|
+
initialValues?: T;
|
|
8
|
+
onFinish?: (values: T, allValues?: any) => void | Promise<void>;
|
|
9
|
+
onReject?: (errorFields: any[]) => void | Promise<void>;
|
|
10
|
+
onFinally?: (result: {
|
|
11
|
+
errorsField: any[];
|
|
12
|
+
values: T;
|
|
13
|
+
withUnRegisteredValues: any;
|
|
14
|
+
}) => void | Promise<void>;
|
|
15
|
+
FormElement?: ComponentType<any>;
|
|
16
|
+
}
|
|
17
|
+
declare function Form<T = any>({ children, formName, initialValues, onFinish, onReject, onFinally, FormElement, ...props }: FormProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
13
18
|
declare namespace Form {
|
|
14
19
|
var useForm: typeof import("./Form").useForm;
|
|
15
20
|
var useWatch: typeof import("./Form").useWatch;
|
package/package.json
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { cloneElement, useRef, useState } from "react";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
2
3
|
import { v4 } from "uuid";
|
|
3
4
|
import useFormItemControl from "../../hooks/useFormItemControl";
|
|
4
5
|
|
|
6
|
+
export interface FormItemProps {
|
|
7
|
+
children: ReactElement;
|
|
8
|
+
name: string;
|
|
9
|
+
formName?: string;
|
|
10
|
+
initialValue?: any;
|
|
11
|
+
formItemId?: string;
|
|
12
|
+
rules?: any[];
|
|
13
|
+
valuePropName?: string;
|
|
14
|
+
getValueFromEvent?: (event: any) => any;
|
|
15
|
+
}
|
|
16
|
+
|
|
5
17
|
export default function FormItem({
|
|
6
18
|
children,
|
|
7
19
|
name,
|
|
@@ -11,7 +23,7 @@ export default function FormItem({
|
|
|
11
23
|
rules,
|
|
12
24
|
valuePropName = "value",
|
|
13
25
|
getValueFromEvent,
|
|
14
|
-
}) {
|
|
26
|
+
}: FormItemProps) {
|
|
15
27
|
const elRef = useRef<any>(null);
|
|
16
28
|
|
|
17
29
|
const [formItemId] = useState(externalFormItemId ?? v4());
|
|
@@ -56,5 +68,5 @@ export default function FormItem({
|
|
|
56
68
|
onFocus,
|
|
57
69
|
validateState: state,
|
|
58
70
|
ref: elRef,
|
|
59
|
-
});
|
|
71
|
+
} as any);
|
|
60
72
|
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import useTestRrenderListControl from "../../hooks/useFormListControl";
|
|
2
|
+
import type { FormInstance } from "../../stores/formStore";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
export interface FormListProps<T = any> {
|
|
5
|
+
name: string;
|
|
6
|
+
initialValues?: T[];
|
|
7
|
+
form?: FormInstance;
|
|
8
|
+
formName?: string;
|
|
9
|
+
children: (fields: Array<{ name: string; key: string }>, operations: { add: (index: number) => void; remove: (opts: { index?: number; key?: string }) => void; move: (opts: { from?: number; fromKey?: string; to: number }) => void }) => React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const FormList = <T = any>({ name, initialValues, form, formName, children }: FormListProps<T>) => {
|
|
4
13
|
const { listFields, ...actions } = useTestRrenderListControl({
|
|
5
14
|
name,
|
|
6
15
|
initialValues,
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { cloneElement } from "react";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
export interface InputWrapperProps {
|
|
5
|
+
children: ReactElement;
|
|
6
|
+
errors?: Array<{ ruleName: string; message: string }>;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const InputWrapper = ({ children, errors = [], ...props }: InputWrapperProps) => {
|
|
4
11
|
return (
|
|
5
12
|
<div>
|
|
6
13
|
{cloneElement(children, props)}
|
package/src/index.ts
CHANGED
|
@@ -3,12 +3,13 @@ import Form, {
|
|
|
3
3
|
useWatch,
|
|
4
4
|
useSubmitDataWatch,
|
|
5
5
|
useFormStateWatch,
|
|
6
|
+
type FormProps,
|
|
6
7
|
} from "./providers/Form";
|
|
7
8
|
|
|
8
|
-
import FormItem from "./components/Form/FormItem";
|
|
9
|
-
import FormList from "./components/Form/FormList";
|
|
9
|
+
import FormItem, { type FormItemProps } from "./components/Form/FormItem";
|
|
10
|
+
import FormList, { type FormListProps } from "./components/Form/FormList";
|
|
10
11
|
import Input from "./components/Input";
|
|
11
|
-
import InputWrapper from "./components/Form/InputWrapper";
|
|
12
|
+
import InputWrapper, { type InputWrapperProps } from "./components/Form/InputWrapper";
|
|
12
13
|
|
|
13
14
|
import useFormItemControl from "./hooks/useFormItemControl";
|
|
14
15
|
import useFormListControl from "./hooks/useFormListControl";
|
|
@@ -25,6 +26,10 @@ export {
|
|
|
25
26
|
useWatch,
|
|
26
27
|
useSubmitDataWatch,
|
|
27
28
|
useFormStateWatch,
|
|
29
|
+
type FormProps,
|
|
30
|
+
type FormItemProps,
|
|
31
|
+
type FormListProps,
|
|
32
|
+
type InputWrapperProps,
|
|
28
33
|
};
|
|
29
34
|
|
|
30
35
|
export default Form;
|
package/src/providers/Form.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cloneDeep, get, isEqual, last, set, uniq } from "lodash";
|
|
2
2
|
import { useTask } from "minh-custom-hooks-release";
|
|
3
3
|
import { createContext, useContext, useEffect, useState } from "react";
|
|
4
|
+
import type { ReactNode, ComponentType, FormHTMLAttributes } from "react";
|
|
4
5
|
import { flushSync } from "react-dom";
|
|
5
6
|
import { useShallow } from "zustand/react/shallow"; // Import useShallow
|
|
6
7
|
import FormCleanUp from "../components/Form/FormCleanUp";
|
|
@@ -10,7 +11,17 @@ import { getAllNoneObjStringPath } from "../utils/obj.util";
|
|
|
10
11
|
|
|
11
12
|
export const FormContext = createContext(null);
|
|
12
13
|
|
|
13
|
-
export
|
|
14
|
+
export interface FormProps<T = any> extends Omit<FormHTMLAttributes<HTMLFormElement>, 'onSubmit'> {
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
formName: string;
|
|
17
|
+
initialValues?: T;
|
|
18
|
+
onFinish?: (values: T, allValues?: any) => void | Promise<void>;
|
|
19
|
+
onReject?: (errorFields: any[]) => void | Promise<void>;
|
|
20
|
+
onFinally?: (result: { errorsField: any[]; values: T; withUnRegisteredValues: any }) => void | Promise<void>;
|
|
21
|
+
FormElement?: ComponentType<any>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function Form<T = any>({
|
|
14
25
|
children,
|
|
15
26
|
formName,
|
|
16
27
|
initialValues,
|
|
@@ -19,7 +30,7 @@ export default function Form({
|
|
|
19
30
|
onFinally,
|
|
20
31
|
FormElement,
|
|
21
32
|
...props
|
|
22
|
-
}) {
|
|
33
|
+
}: FormProps<T>) {
|
|
23
34
|
const {
|
|
24
35
|
getFormItemValue,
|
|
25
36
|
setInitData,
|
|
@@ -143,7 +154,7 @@ export default function Form({
|
|
|
143
154
|
const formValues = getFormValues(formName);
|
|
144
155
|
|
|
145
156
|
const resultValues = cloneDeep(formValues);
|
|
146
|
-
const cleanValues = {};
|
|
157
|
+
const cleanValues = {} as T;
|
|
147
158
|
uniq(listeners, (l) => l.name).forEach((l) => {
|
|
148
159
|
set(cleanValues, l.name, get(resultValues, l.name));
|
|
149
160
|
});
|