react-form-manage 1.0.2 → 1.0.4

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.
@@ -0,0 +1 @@
1
+ export * from './index';
package/dist/index.d.ts CHANGED
@@ -1,13 +1,134 @@
1
- export default Form;
2
- import FormItem from "./components/Form/FormItem";
3
- import FormList from "./components/Form/FormList";
4
- import Input from "./components/Input";
5
- import InputWrapper from "./components/Form/InputWrapper";
6
- import useFormItemControl from "./hooks/useFormItemControl";
7
- import useFormListControl from "./hooks/useFormListControl";
8
- import { useForm } from "./providers/Form";
9
- import { useWatch } from "./providers/Form";
10
- import { useSubmitDataWatch } from "./providers/Form";
11
- import { useFormStateWatch } from "./providers/Form";
12
- import Form from "./providers/Form";
13
- export { FormItem, FormList, Input, InputWrapper, useFormItemControl, useFormListControl, useForm, useWatch, useSubmitDataWatch, useFormStateWatch };
1
+ import * as React from "react";
2
+
3
+ // Generic types for top-level Form provider
4
+ export interface FormProps<TValues = Record<string, any>> {
5
+ children?: React.ReactNode;
6
+ formName?: string;
7
+ initialValues?: Partial<TValues>;
8
+ onFinish?: (
9
+ values: Partial<TValues>,
10
+ allValues?: TValues,
11
+ ) => void | Promise<void>;
12
+ onReject?: (errors: any) => void | Promise<void>;
13
+ onFinally?: (payload: {
14
+ errorsField: any;
15
+ values: Partial<TValues>;
16
+ withUnRegisteredValues: TValues;
17
+ }) => void | Promise<void>;
18
+ FormElement?: React.ComponentType<any>;
19
+ [key: string]: any;
20
+ }
21
+
22
+ declare function Form<TValues = Record<string, any>>(
23
+ props: FormProps<TValues>,
24
+ ): JSX.Element;
25
+
26
+ // Standalone generic hooks (also attached to Form as static properties at runtime)
27
+ export function useForm<TValues = Record<string, any>>(
28
+ formNameOrFormInstance?: any,
29
+ ): [any];
30
+
31
+ export function useWatch<
32
+ TValues = Record<string, any>,
33
+ K extends keyof TValues = string & keyof TValues,
34
+ >(
35
+ name: K,
36
+ formNameOrFormInstance?: any,
37
+ ): K extends keyof TValues ? TValues[K] : any;
38
+
39
+ export function useSubmitDataWatch<TValues = any>(opts: {
40
+ formNameOrFormInstance?: any;
41
+ triggerWhenChange?: boolean;
42
+ mapFn?: (v: any, prev: any) => any;
43
+ }): any;
44
+
45
+ export function useFormStateWatch<TValues = any>(
46
+ formNameOrFormInstance?: any,
47
+ ): any;
48
+
49
+ declare namespace Form {
50
+ // expose same hook names on the Form object
51
+ export { useForm, useWatch, useSubmitDataWatch, useFormStateWatch };
52
+ }
53
+
54
+ export default Form;
55
+
56
+ // FormItem (generic for the field value type)
57
+ export interface FormItemProps<T = any> {
58
+ children: React.ReactElement;
59
+ name: string;
60
+ formName?: string;
61
+ initialValue?: T;
62
+ formItemId?: string;
63
+ rules?: any[];
64
+ valuePropName?: string;
65
+ getValueFromEvent?: (e: any) => T;
66
+ [key: string]: any;
67
+ }
68
+
69
+ export function FormItem<T = any>(props: FormItemProps<T>): JSX.Element;
70
+
71
+ // FormList (generic for item shape)
72
+ export interface FormListProps<TItem = any> {
73
+ name: string;
74
+ initialValues?: TItem[];
75
+ form?: any;
76
+ formName?: string;
77
+ children: (listFields: any[], actions: any) => React.ReactNode;
78
+ }
79
+
80
+ export function FormList<TItem = any>(props: FormListProps<TItem>): JSX.Element;
81
+
82
+ // Input components
83
+ export interface BasicInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
84
+ onChange?: (value: any, ...args: any[]) => void;
85
+ isValidating?: boolean;
86
+ [key: string]: any;
87
+ }
88
+
89
+ // InputWrapper
90
+ export interface InputWrapperProps {
91
+ children: React.ReactElement;
92
+ errors?: Array<{ ruleName?: string; message?: string }>;
93
+ isDirty?: boolean;
94
+ formState?: any;
95
+ name?: string;
96
+ formItemId?: string;
97
+ [key: string]: any;
98
+ }
99
+
100
+ export function InputWrapper(props: InputWrapperProps): JSX.Element;
101
+
102
+ // Cleanup component (internal)
103
+ export function FormCleanUp(): JSX.Element;
104
+
105
+ // Hooks in src/hooks
106
+ export function useFormItemControl<T = any>(opts: {
107
+ formName?: string;
108
+ form?: any;
109
+ name: string;
110
+ initialValue?: T;
111
+ formItemId?: string;
112
+ rules?: any[];
113
+ elementRef?: React.RefObject<any>;
114
+ }): {
115
+ value: T | undefined;
116
+ onChange: (value: any, options?: any) => void;
117
+ state: any;
118
+ errors: any;
119
+ onFocus: () => void;
120
+ isDirty?: boolean;
121
+ onReset?: (value?: any) => void;
122
+ };
123
+
124
+ export function useFormListControl<TItem = any>(opts: {
125
+ name: string;
126
+ form?: any;
127
+ initialValues?: TItem[];
128
+ formName?: string;
129
+ }): {
130
+ listFields: Array<{ name: string; key: string }>;
131
+ add: (index?: number) => void;
132
+ remove: (opts: { index?: number; key?: string }) => void;
133
+ move: (opts: { from?: number; fromKey?: string; to: number }) => void;
134
+ };
@@ -0,0 +1 @@
1
+ export * from './index';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-form-manage",
3
3
  "private": false,
4
- "version": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -10,8 +10,10 @@
10
10
  "build:dev": "vite build",
11
11
  "lint": "eslint .",
12
12
  "preview": "vite preview",
13
- "prepublishOnly": "npm run build"
13
+ "build:types": "node ./scripts/copy-types.cjs",
14
+ "prepublishOnly": "npm run build && npm run build:types"
14
15
  },
16
+
15
17
  "dependencies": {
16
18
  "immer": "^11.1.3",
17
19
  "lodash": "^4.17.21",