react-form-manage 1.0.8-beta.2 → 1.0.8-beta.3
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 +5 -0
- package/dist/index.d.ts +2 -2
- package/dist/providers/Form.d.ts +4 -2
- package/dist/providers/Form.js +13 -0
- package/dist/types/public.d.ts +5 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/providers/Form.tsx +33 -2
- package/src/types/public.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.0.8-beta.3] - 2026-01-22
|
|
6
|
+
|
|
7
|
+
- Add `UseFormItemStateWatchReturn` type export for `useFormItemStateWatch` hook
|
|
8
|
+
- Explicit return typing with `FormFieldError[]` for better TypeScript support
|
|
9
|
+
|
|
5
10
|
## [1.0.8-beta.2] - 2026-01-22
|
|
6
11
|
|
|
7
12
|
- Add isTouched field to FormItem for tracking user interaction state
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Form, { useForm, useWatch, useSubmitDataWatch, useFormStateWatch, type FormProps, type ValidationRule, type FormFieldError, type SubmitState } from "./providers/Form";
|
|
1
|
+
import Form, { useForm, useWatch, useSubmitDataWatch, useFormStateWatch, type FormProps, type ValidationRule, type FormFieldError, type SubmitState, type UseFormItemStateWatchReturn } from "./providers/Form";
|
|
2
2
|
import { SUBMIT_STATE } from "./constants/form";
|
|
3
3
|
import FormItem, { type FormItemProps } from "./components/Form/FormItem";
|
|
4
4
|
import FormList, { type FormListProps } from "./components/Form/FormList";
|
|
@@ -6,5 +6,5 @@ import Input from "./components/Input";
|
|
|
6
6
|
import InputWrapper, { type InputWrapperProps } from "./components/Form/InputWrapper";
|
|
7
7
|
import useFormItemControl from "./hooks/useFormItemControl";
|
|
8
8
|
import useFormListControl from "./hooks/useFormListControl";
|
|
9
|
-
export { Form, FormItem, FormList, Input, InputWrapper, useFormItemControl, useFormListControl, useForm, useWatch, useSubmitDataWatch, useFormStateWatch, type FormProps, type FormItemProps, type FormListProps, type InputWrapperProps, type ValidationRule, type FormFieldError, type SubmitState, SUBMIT_STATE, };
|
|
9
|
+
export { Form, FormItem, FormList, Input, InputWrapper, useFormItemControl, useFormListControl, useForm, useWatch, useSubmitDataWatch, useFormStateWatch, type FormProps, type FormItemProps, type FormListProps, type InputWrapperProps, type ValidationRule, type FormFieldError, type SubmitState, type UseFormItemStateWatchReturn, SUBMIT_STATE, };
|
|
10
10
|
export default Form;
|
package/dist/providers/Form.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComponentType, FormHTMLAttributes, ReactNode } from "react";
|
|
2
|
-
import type { PublicFormInstance } from "../types/public";
|
|
3
|
-
export type { ValidationRule,
|
|
2
|
+
import type { PublicFormInstance, UseFormItemStateWatchReturn } from "../types/public";
|
|
3
|
+
export type { FormFieldError, SubmitState, ValidationRule, UseFormItemStateWatchReturn, } from "../types/public";
|
|
4
4
|
export declare const FormContext: import("react").Context<any>;
|
|
5
5
|
export interface FormProps<T = any> extends Omit<FormHTMLAttributes<HTMLFormElement>, "onSubmit"> {
|
|
6
6
|
children: ReactNode;
|
|
@@ -21,6 +21,7 @@ declare namespace Form {
|
|
|
21
21
|
var useWatch: typeof import("./Form").useWatch;
|
|
22
22
|
var useSubmitDataWatch: typeof import("./Form").useSubmitDataWatch;
|
|
23
23
|
var useFormStateWatch: <T = any>(formNameOrFormInstance?: string | PublicFormInstance<T>) => any;
|
|
24
|
+
var useFormItemStateWatch: <T = any>(nameOrFormItemId: string, formNameOrFormInstance?: string | PublicFormInstance<T>) => UseFormItemStateWatchReturn;
|
|
24
25
|
}
|
|
25
26
|
export default Form;
|
|
26
27
|
export declare function useFormContext(): any;
|
|
@@ -32,3 +33,4 @@ export declare function useSubmitDataWatch<T = any>({ formNameOrFormInstance, tr
|
|
|
32
33
|
mapFn?: (v: any, prev: any) => any;
|
|
33
34
|
}): T | undefined;
|
|
34
35
|
export declare const useFormStateWatch: <T = any>(formNameOrFormInstance?: string | PublicFormInstance<T>) => any;
|
|
36
|
+
export declare const useFormItemStateWatch: <T = any>(nameOrFormItemId: string, formNameOrFormInstance?: string | PublicFormInstance<T>) => UseFormItemStateWatchReturn;
|
package/dist/providers/Form.js
CHANGED
|
@@ -287,15 +287,28 @@ const useFormStateWatch = (formNameOrFormInstance) => {
|
|
|
287
287
|
});
|
|
288
288
|
return formState;
|
|
289
289
|
};
|
|
290
|
+
const useFormItemStateWatch = (nameOrFormItemId, formNameOrFormInstance) => {
|
|
291
|
+
const [formInstance] = useForm(formNameOrFormInstance);
|
|
292
|
+
const listener = useFormStore((state) => {
|
|
293
|
+
return state.getListeners().find((l) => l.formName === (formInstance == null ? void 0 : formInstance.formName) && (l.name === nameOrFormItemId || l.formItemId === nameOrFormItemId));
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
isTouched: listener == null ? void 0 : listener.isTouched,
|
|
297
|
+
isDirty: listener == null ? void 0 : listener.isDirty,
|
|
298
|
+
errors: (listener == null ? void 0 : listener.internalErrors) || []
|
|
299
|
+
};
|
|
300
|
+
};
|
|
290
301
|
Form.useForm = useForm;
|
|
291
302
|
Form.useWatch = useWatch;
|
|
292
303
|
Form.useSubmitDataWatch = useSubmitDataWatch;
|
|
293
304
|
Form.useFormStateWatch = useFormStateWatch;
|
|
305
|
+
Form.useFormItemStateWatch = useFormItemStateWatch;
|
|
294
306
|
export {
|
|
295
307
|
FormContext,
|
|
296
308
|
Form as default,
|
|
297
309
|
useForm,
|
|
298
310
|
useFormContext,
|
|
311
|
+
useFormItemStateWatch,
|
|
299
312
|
useFormStateWatch,
|
|
300
313
|
useSubmitDataWatch,
|
|
301
314
|
useWatch
|
package/dist/types/public.d.ts
CHANGED
|
@@ -61,6 +61,11 @@ export interface UseFormItemReturn<T = any> {
|
|
|
61
61
|
isDirty?: boolean;
|
|
62
62
|
submitState?: SubmitState;
|
|
63
63
|
}
|
|
64
|
+
export interface UseFormItemStateWatchReturn {
|
|
65
|
+
isTouched?: boolean;
|
|
66
|
+
isDirty?: boolean;
|
|
67
|
+
errors: FormFieldError[];
|
|
68
|
+
}
|
|
64
69
|
export interface UseFormListProps<T = any> {
|
|
65
70
|
name?: string;
|
|
66
71
|
form?: PublicFormInstance<T>;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import Form, {
|
|
|
7
7
|
type ValidationRule,
|
|
8
8
|
type FormFieldError,
|
|
9
9
|
type SubmitState,
|
|
10
|
+
type UseFormItemStateWatchReturn,
|
|
10
11
|
} from "./providers/Form";
|
|
11
12
|
import { SUBMIT_STATE } from "./constants/form";
|
|
12
13
|
|
|
@@ -37,6 +38,7 @@ export {
|
|
|
37
38
|
type ValidationRule,
|
|
38
39
|
type FormFieldError,
|
|
39
40
|
type SubmitState,
|
|
41
|
+
type UseFormItemStateWatchReturn,
|
|
40
42
|
SUBMIT_STATE,
|
|
41
43
|
};
|
|
42
44
|
|
package/src/providers/Form.tsx
CHANGED
|
@@ -6,9 +6,14 @@ import { flushSync } from "react-dom";
|
|
|
6
6
|
import { useShallow } from "zustand/react/shallow"; // Import useShallow
|
|
7
7
|
import FormCleanUp from "../components/Form/FormCleanUp";
|
|
8
8
|
import { useFormListeners, useFormStore } from "../stores/formStore";
|
|
9
|
-
import type { PublicFormInstance } from "../types/public";
|
|
9
|
+
import type { PublicFormInstance, UseFormItemStateWatchReturn } from "../types/public";
|
|
10
10
|
import { getAllNoneObjStringPath } from "../utils/obj.util";
|
|
11
|
-
export type {
|
|
11
|
+
export type {
|
|
12
|
+
FormFieldError,
|
|
13
|
+
SubmitState,
|
|
14
|
+
ValidationRule,
|
|
15
|
+
UseFormItemStateWatchReturn,
|
|
16
|
+
} from "../types/public";
|
|
12
17
|
|
|
13
18
|
export const FormContext = createContext(null);
|
|
14
19
|
|
|
@@ -472,7 +477,33 @@ export const useFormStateWatch = <T = any,>(
|
|
|
472
477
|
return formState as any;
|
|
473
478
|
};
|
|
474
479
|
|
|
480
|
+
// Get Form Item State Using name (make sure no same name listener before using this) or formItemId, formNameOrFormInstance
|
|
481
|
+
// reutrn formItem state like isTouched, isDirty, errors
|
|
482
|
+
export const useFormItemStateWatch = <T = any,>(
|
|
483
|
+
nameOrFormItemId: string,
|
|
484
|
+
formNameOrFormInstance?: string | PublicFormInstance<T>,
|
|
485
|
+
): UseFormItemStateWatchReturn => {
|
|
486
|
+
const [formInstance] = useForm<T>(formNameOrFormInstance as any);
|
|
487
|
+
|
|
488
|
+
const listener = useFormStore((state) => {
|
|
489
|
+
return state
|
|
490
|
+
.getListeners()
|
|
491
|
+
.find(
|
|
492
|
+
(l) =>
|
|
493
|
+
l.formName === formInstance?.formName &&
|
|
494
|
+
(l.name === nameOrFormItemId || l.formItemId === nameOrFormItemId),
|
|
495
|
+
);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
return {
|
|
499
|
+
isTouched: listener?.isTouched,
|
|
500
|
+
isDirty: listener?.isDirty,
|
|
501
|
+
errors: listener?.internalErrors || [],
|
|
502
|
+
};
|
|
503
|
+
};
|
|
504
|
+
|
|
475
505
|
Form.useForm = useForm;
|
|
476
506
|
Form.useWatch = useWatch;
|
|
477
507
|
Form.useSubmitDataWatch = useSubmitDataWatch;
|
|
478
508
|
Form.useFormStateWatch = useFormStateWatch;
|
|
509
|
+
Form.useFormItemStateWatch = useFormItemStateWatch;
|
package/src/types/public.ts
CHANGED
|
@@ -67,6 +67,12 @@ export interface UseFormItemReturn<T = any> {
|
|
|
67
67
|
submitState?: SubmitState;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
export interface UseFormItemStateWatchReturn {
|
|
71
|
+
isTouched?: boolean;
|
|
72
|
+
isDirty?: boolean;
|
|
73
|
+
errors: FormFieldError[];
|
|
74
|
+
}
|
|
75
|
+
|
|
70
76
|
export interface UseFormListProps<T = any> {
|
|
71
77
|
name?: string;
|
|
72
78
|
form?: PublicFormInstance<T>;
|