react-form-manage 1.0.6-beta.0 → 1.0.6-beta.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/CHANGELOG.md +44 -0
- package/dist/components/Form/FormCleanUp.js +46 -0
- package/dist/components/Form/FormItem.js +46 -0
- package/dist/components/Form/FormList.js +11 -0
- package/dist/components/Form/InputWrapper.js +7 -0
- package/dist/components/Input.d.ts +4 -5
- package/dist/components/Input.js +8 -0
- package/dist/constants/validation.js +33 -0
- package/dist/contexts/FormContext.js +2 -0
- package/dist/hooks/useFormItemControl.js +390 -0
- package/dist/hooks/useFormListControl.js +280 -0
- package/dist/index.d.ts +8 -185
- package/dist/index.js +9 -0
- package/dist/providers/Form.js +322 -0
- package/dist/stores/formStore.js +304 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/public.d.ts +51 -0
- package/dist/utils/obj.util.js +24 -0
- package/package.json +30 -45
- package/src/App.css +49 -0
- package/src/App.tsx +36 -0
- package/src/assets/react.svg +1 -0
- package/src/components/Form/FormCleanUp.tsx +57 -0
- package/src/components/Form/FormItem.tsx +60 -0
- package/src/components/Form/FormList.tsx +13 -0
- package/src/components/Form/InputWrapper.tsx +17 -0
- package/src/components/Input.jsx +13 -0
- package/src/components/Input.tsx +21 -0
- package/src/constants/validation.ts +63 -0
- package/src/contexts/FormContext.ts +3 -0
- package/src/hooks/useFormItemControl.ts +558 -0
- package/src/hooks/useFormListControl.ts +378 -0
- package/src/index.css +68 -0
- package/src/index.ts +30 -0
- package/src/main.tsx +10 -0
- package/src/providers/Form.tsx +429 -0
- package/src/stores/formStore.ts +477 -0
- package/src/types/index.ts +1 -0
- package/src/types/public.ts +50 -0
- package/src/utils/obj.util.ts +42 -0
- package/dist/App.d.ts +0 -2
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.d.ts +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.esm.d.ts +0 -1
- package/dist/index.esm.js +0 -2
- package/dist/index.esm.js.map +0 -1
- package/src/types/components.d.ts +0 -135
- /package/dist/{main.d.ts → types/public.js} +0 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { cloneDeep, get, isNil } from "lodash";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { v4 } from "uuid";
|
|
4
|
+
import { useShallow } from "zustand/react/shallow";
|
|
5
|
+
import { useFormContext } from "../providers/Form";
|
|
6
|
+
import { useFormCleanUp, useFormStore } from "../stores/formStore";
|
|
7
|
+
export default function useFormListControl({ name, form, initialValues, formName, }) {
|
|
8
|
+
const contextForm = useFormContext();
|
|
9
|
+
const getFormValues = useFormStore((state) => state.getFormValues);
|
|
10
|
+
const [listFormInitValues, setListFormInitValues] = useState(undefined);
|
|
11
|
+
const { clearCacheData, setCacheData } = useFormStore(useShallow((state) => ({
|
|
12
|
+
cacheData: state.cacheData,
|
|
13
|
+
clearCacheData: state.clearCacheData,
|
|
14
|
+
setCacheData: state.setCacheData,
|
|
15
|
+
})));
|
|
16
|
+
const { setCleanUpStack } = useFormCleanUp(useShallow((state) => ({
|
|
17
|
+
setCleanUpStack: state.setCleanUpStack,
|
|
18
|
+
})));
|
|
19
|
+
const { initValue: internalInitValue, formState } = useFormStore(useShallow((state) => {
|
|
20
|
+
// console.log(
|
|
21
|
+
// "Shallow get initValue: ",
|
|
22
|
+
// formName || form?.formName || contextForm?.formName,
|
|
23
|
+
// name,
|
|
24
|
+
// get(
|
|
25
|
+
// state.initialValues,
|
|
26
|
+
// `${formName || form?.formName || contextForm?.formName}.${name}`
|
|
27
|
+
// )
|
|
28
|
+
// );
|
|
29
|
+
return {
|
|
30
|
+
initValue: get(state.initialValues, `${formName || form?.formName || contextForm?.formName}.${name}`),
|
|
31
|
+
formState: get(state.formStates, formName || form?.formName || contextForm?.formName),
|
|
32
|
+
setInitData: state.setInitData,
|
|
33
|
+
getFormState: state.getFormState,
|
|
34
|
+
};
|
|
35
|
+
}));
|
|
36
|
+
const [listFields, setListFields] = useState([]);
|
|
37
|
+
const handleCacheListField = (prev, cur) => {
|
|
38
|
+
const currentFormValues = cloneDeep(getFormValues(formName || form?.formName || contextForm?.formName));
|
|
39
|
+
const formDataBeforeChange = get(currentFormValues, name);
|
|
40
|
+
const mapPrevWithKey = formDataBeforeChange
|
|
41
|
+
.map((d, index) => {
|
|
42
|
+
const findPrev = prev.find((p, pIndex) => pIndex === index);
|
|
43
|
+
if (!findPrev)
|
|
44
|
+
return undefined;
|
|
45
|
+
return {
|
|
46
|
+
key: findPrev.key,
|
|
47
|
+
value: d,
|
|
48
|
+
};
|
|
49
|
+
})
|
|
50
|
+
.filter(Boolean);
|
|
51
|
+
const mapCurWithKey = cur.map((c) => mapPrevWithKey.find((m) => m.key === c.key) || c);
|
|
52
|
+
const getNewValueCache = mapCurWithKey.filter(Boolean).map((c) => c.value);
|
|
53
|
+
const startRemoveIndex = formDataBeforeChange.length - getNewValueCache.length;
|
|
54
|
+
// console.log("Before list fields: ", prev);
|
|
55
|
+
// console.log("After list fields: ", cur);
|
|
56
|
+
// console.log("Before change arr value: ", formDataBeforeChange);
|
|
57
|
+
// console.log("Mapping prev value with prev fields: ", mapPrevWithKey);
|
|
58
|
+
// console.log("Mapping Cur value with prev fields: ", mapCurWithKey);
|
|
59
|
+
// console.log("After change arr value: ", getNewValueCache);
|
|
60
|
+
// Nếu số phần tử trước khi thay đổi mảng lớn hơn thì đẩy 2 phần tử còn lại vào clean up stack để clear
|
|
61
|
+
if (startRemoveIndex > 0) {
|
|
62
|
+
Array.from(Array(startRemoveIndex))
|
|
63
|
+
.map((_, index) => {
|
|
64
|
+
return getNewValueCache.length + index;
|
|
65
|
+
})
|
|
66
|
+
.forEach((index) => {
|
|
67
|
+
// console.log("Data for cleanup arr element: ", {
|
|
68
|
+
// formName: formName || form?.formName || contextForm?.formName,
|
|
69
|
+
// name: `${name}.${index}`,
|
|
70
|
+
// type: "array",
|
|
71
|
+
// });
|
|
72
|
+
setCleanUpStack({
|
|
73
|
+
formName: formName || form?.formName || contextForm?.formName,
|
|
74
|
+
name: `${name}.${index}`,
|
|
75
|
+
type: "array",
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
// console.log({ getNewValueCache });
|
|
80
|
+
setCacheData(formName || form?.formName || contextForm?.formName, name, getNewValueCache);
|
|
81
|
+
};
|
|
82
|
+
const add = (index) => {
|
|
83
|
+
setListFields((prev) => {
|
|
84
|
+
if (index > prev.length)
|
|
85
|
+
return prev;
|
|
86
|
+
if (index < 0)
|
|
87
|
+
return prev;
|
|
88
|
+
if (index === prev.length) {
|
|
89
|
+
const newName = `${name}.${prev.length}`;
|
|
90
|
+
const newKey = v4();
|
|
91
|
+
const result = [
|
|
92
|
+
...prev,
|
|
93
|
+
{
|
|
94
|
+
name: newName,
|
|
95
|
+
key: newKey,
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
const clonePrev = [...prev];
|
|
101
|
+
const result = clonePrev
|
|
102
|
+
.reduce((prev, cur, curIndex) => {
|
|
103
|
+
const newKey = v4();
|
|
104
|
+
if (curIndex === index)
|
|
105
|
+
return [
|
|
106
|
+
...prev,
|
|
107
|
+
{
|
|
108
|
+
key: newKey,
|
|
109
|
+
},
|
|
110
|
+
cur,
|
|
111
|
+
];
|
|
112
|
+
return [...prev, cur];
|
|
113
|
+
}, [])
|
|
114
|
+
.map((r, index) => ({
|
|
115
|
+
name: `${name}.${index}`,
|
|
116
|
+
key: r.key,
|
|
117
|
+
}));
|
|
118
|
+
handleCacheListField(prev, result);
|
|
119
|
+
return result;
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const remove = ({ index, key }) => {
|
|
123
|
+
setListFields((prev) => {
|
|
124
|
+
if (!isNil(key)) {
|
|
125
|
+
const clonePrev = [...prev];
|
|
126
|
+
const removedItem = clonePrev.filter((d) => d.key !== key);
|
|
127
|
+
console.log("Remove data: ", removedItem);
|
|
128
|
+
const result = removedItem.map((r, index) => ({
|
|
129
|
+
name: `${name}.${index}`,
|
|
130
|
+
key: r.key,
|
|
131
|
+
}));
|
|
132
|
+
handleCacheListField(prev, result);
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
if (!isNil(index)) {
|
|
136
|
+
if (index > prev.length - 1 || index < 0)
|
|
137
|
+
return prev;
|
|
138
|
+
const clonePrev = [...prev];
|
|
139
|
+
clonePrev.splice(index, 1);
|
|
140
|
+
const result = clonePrev.map((r, index) => ({
|
|
141
|
+
name: `${name}.${index}`,
|
|
142
|
+
key: r.key,
|
|
143
|
+
}));
|
|
144
|
+
handleCacheListField(prev, result);
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
return prev;
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
const move = ({ from, fromKey, to }) => {
|
|
151
|
+
setListFields((prev) => {
|
|
152
|
+
console.log("move list item: ", { from, to });
|
|
153
|
+
if (from >= listFields.length ||
|
|
154
|
+
from < 0 ||
|
|
155
|
+
to >= listFields.length ||
|
|
156
|
+
to < 0 ||
|
|
157
|
+
from === to)
|
|
158
|
+
return prev;
|
|
159
|
+
console.log("Trigger move item: ");
|
|
160
|
+
if (!isNil(fromKey)) {
|
|
161
|
+
const findItemIndex = prev.findIndex((p) => p.key === fromKey);
|
|
162
|
+
if (findItemIndex < 0)
|
|
163
|
+
return prev;
|
|
164
|
+
const moveItem = cloneDeep(listFields[findItemIndex]);
|
|
165
|
+
const result = prev
|
|
166
|
+
.reduce((prev, cur, curIndex) => {
|
|
167
|
+
if (findItemIndex === curIndex)
|
|
168
|
+
return [...prev];
|
|
169
|
+
if (to === curIndex) {
|
|
170
|
+
if (findItemIndex > to)
|
|
171
|
+
return [...prev, moveItem, cur];
|
|
172
|
+
else
|
|
173
|
+
return [...prev, cur, moveItem];
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
return [...prev, cur];
|
|
177
|
+
}
|
|
178
|
+
}, [])
|
|
179
|
+
.map((i, index) => ({
|
|
180
|
+
key: i.key,
|
|
181
|
+
name: `${name}.${index}`,
|
|
182
|
+
}));
|
|
183
|
+
handleCacheListField(prev, result);
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
else if (!isNil(from)) {
|
|
187
|
+
console.log("Trigger from index: ");
|
|
188
|
+
const moveItem = cloneDeep(listFields[from]);
|
|
189
|
+
const result = prev
|
|
190
|
+
.reduce((prev, cur, curIndex) => {
|
|
191
|
+
if (from === curIndex)
|
|
192
|
+
return [...prev];
|
|
193
|
+
if (to === curIndex) {
|
|
194
|
+
if (from > to)
|
|
195
|
+
return [...prev, moveItem, cur];
|
|
196
|
+
else
|
|
197
|
+
return [...prev, cur, moveItem];
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
return [...prev, cur];
|
|
201
|
+
}
|
|
202
|
+
}, [])
|
|
203
|
+
.map((i, index) => ({
|
|
204
|
+
key: i.key,
|
|
205
|
+
name: `${name}.${index}`,
|
|
206
|
+
}));
|
|
207
|
+
console.log({ result });
|
|
208
|
+
handleCacheListField(prev, result);
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
return prev;
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
console.log("Trigger init", formState?.isInitied, internalInitValue);
|
|
216
|
+
if (formState?.isInitied) {
|
|
217
|
+
if (Array.isArray(listFormInitValues)) {
|
|
218
|
+
const result = listFormInitValues?.map((_, i) => {
|
|
219
|
+
const itemName = `${name}.${i}`;
|
|
220
|
+
const key = v4();
|
|
221
|
+
return {
|
|
222
|
+
key,
|
|
223
|
+
name: itemName,
|
|
224
|
+
};
|
|
225
|
+
});
|
|
226
|
+
console.log("Get local init values: ", listFormInitValues, result);
|
|
227
|
+
setListFields(result);
|
|
228
|
+
setCacheData(formName || form?.formName || contextForm?.formName, name, listFormInitValues);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (Array.isArray(internalInitValue)) {
|
|
232
|
+
const result = internalInitValue.map((_, i) => {
|
|
233
|
+
const itemName = `${name}.${i}`;
|
|
234
|
+
const key = v4();
|
|
235
|
+
return {
|
|
236
|
+
key,
|
|
237
|
+
name: itemName,
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
// console.log("Get form init values: ", internalInitValue, result);
|
|
241
|
+
setListFields(result);
|
|
242
|
+
setListFormInitValues(internalInitValue);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
// console.log({ initialValues });
|
|
246
|
+
// console.log("After init: ", { result: cloneDeep(result) });
|
|
247
|
+
if (Array.isArray(initialValues)) {
|
|
248
|
+
const result = initialValues.map((_, i) => {
|
|
249
|
+
const itemName = `${name}.${i}`;
|
|
250
|
+
const key = v4();
|
|
251
|
+
return {
|
|
252
|
+
key,
|
|
253
|
+
name: itemName,
|
|
254
|
+
};
|
|
255
|
+
});
|
|
256
|
+
if (initialValues) {
|
|
257
|
+
setCacheData(formName || form?.formName || contextForm?.formName, name, initialValues);
|
|
258
|
+
}
|
|
259
|
+
setListFields(result);
|
|
260
|
+
setListFormInitValues(initialValues);
|
|
261
|
+
// console.log("Get form init values: ", internalInitValue, result);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}, [formState?.isInitied]);
|
|
266
|
+
// useEffect(() => {
|
|
267
|
+
// console.log("Show form list init values: ", { internalInitValue });
|
|
268
|
+
// }, [internalInitValue]);
|
|
269
|
+
// useEffect(() => {
|
|
270
|
+
// console.log("List fields update: ", listFields);
|
|
271
|
+
// }, [listFields]);
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
// console.log({ listFields });
|
|
274
|
+
return () => {
|
|
275
|
+
// console.log("Cleanup listfield change");
|
|
276
|
+
clearCacheData();
|
|
277
|
+
};
|
|
278
|
+
}, [listFields]);
|
|
279
|
+
return { listFields, move, add, remove };
|
|
280
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,186 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
setFieldValues?: (values: Partial<T>) => void;
|
|
10
|
-
getFieldValue?: (name: keyof T & string) => any;
|
|
11
|
-
getFieldValues?: () => T;
|
|
12
|
-
getFieldErrors?: () => Record<string, any>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface UseFormItemProps<T = any> {
|
|
16
|
-
formName?: string;
|
|
17
|
-
form?: PublicFormInstance<T>;
|
|
18
|
-
name?: keyof T & string;
|
|
19
|
-
initialValue?: any;
|
|
20
|
-
formItemId?: string;
|
|
21
|
-
rules?: any[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface UseFormItemReturn<T = any> {
|
|
25
|
-
value: T | undefined;
|
|
26
|
-
onChange: (value: T, options?: any) => void;
|
|
27
|
-
state: any;
|
|
28
|
-
errors: any;
|
|
29
|
-
onFocus: () => void;
|
|
30
|
-
isDirty?: boolean;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface UseFormListProps<T = any> {
|
|
34
|
-
name?: string;
|
|
35
|
-
form?: PublicFormInstance<T>;
|
|
36
|
-
initialValues?: T[];
|
|
37
|
-
formName?: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface ListField {
|
|
41
|
-
name: string;
|
|
42
|
-
key: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface UseFormListReturn {
|
|
46
|
-
listFields: ListField[];
|
|
47
|
-
move: (opts: { from?: number; fromKey?: string; to: number }) => void;
|
|
48
|
-
add: (index: number) => void;
|
|
49
|
-
remove: (opts: { index?: number; key?: string }) => void;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
import * as React from "react";
|
|
53
|
-
|
|
54
|
-
// Generic types for top-level Form provider
|
|
55
|
-
export interface FormProps<TValues = Record<string, any>> {
|
|
56
|
-
children?: React.ReactNode;
|
|
57
|
-
formName?: string;
|
|
58
|
-
initialValues?: Partial<TValues>;
|
|
59
|
-
onFinish?: (
|
|
60
|
-
values: Partial<TValues>,
|
|
61
|
-
allValues?: TValues,
|
|
62
|
-
) => void | Promise<void>;
|
|
63
|
-
onReject?: (errors: any) => void | Promise<void>;
|
|
64
|
-
onFinally?: (payload: {
|
|
65
|
-
errorsField: any;
|
|
66
|
-
values: Partial<TValues>;
|
|
67
|
-
withUnRegisteredValues: TValues;
|
|
68
|
-
}) => void | Promise<void>;
|
|
69
|
-
FormElement?: React.ComponentType<any>;
|
|
70
|
-
[key: string]: any;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
declare function Form<TValues = Record<string, any>>(
|
|
74
|
-
props: FormProps<TValues>,
|
|
75
|
-
): JSX.Element;
|
|
76
|
-
|
|
77
|
-
// Standalone generic hooks (also attached to Form as static properties at runtime)
|
|
78
|
-
export function useForm<TValues = Record<string, any>>(
|
|
79
|
-
formNameOrFormInstance?: any,
|
|
80
|
-
): [any];
|
|
81
|
-
|
|
82
|
-
export function useWatch<
|
|
83
|
-
TValues = Record<string, any>,
|
|
84
|
-
K extends keyof TValues = string & keyof TValues,
|
|
85
|
-
>(
|
|
86
|
-
name: K,
|
|
87
|
-
formNameOrFormInstance?: any,
|
|
88
|
-
): K extends keyof TValues ? TValues[K] : any;
|
|
89
|
-
|
|
90
|
-
export function useSubmitDataWatch<TValues = any>(opts: {
|
|
91
|
-
formNameOrFormInstance?: any;
|
|
92
|
-
triggerWhenChange?: boolean;
|
|
93
|
-
mapFn?: (v: any, prev: any) => any;
|
|
94
|
-
}): any;
|
|
95
|
-
|
|
96
|
-
export function useFormStateWatch<TValues = any>(
|
|
97
|
-
formNameOrFormInstance?: any,
|
|
98
|
-
): any;
|
|
99
|
-
|
|
100
|
-
declare namespace Form {
|
|
101
|
-
// expose same hook names on the Form object
|
|
102
|
-
export { useForm, useWatch, useSubmitDataWatch, useFormStateWatch };
|
|
103
|
-
}
|
|
104
|
-
|
|
1
|
+
import Form, { useForm, useWatch, useSubmitDataWatch, useFormStateWatch } from "./providers/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
|
+
export { Form, FormItem, FormList, Input, InputWrapper, useFormItemControl, useFormListControl, useForm, useWatch, useSubmitDataWatch, useFormStateWatch, };
|
|
105
9
|
export default Form;
|
|
106
|
-
export { Form };
|
|
107
|
-
|
|
108
|
-
// FormItem (generic for the field value type)
|
|
109
|
-
export interface FormItemProps<T = any> {
|
|
110
|
-
children: React.ReactElement;
|
|
111
|
-
name: string;
|
|
112
|
-
formName?: string;
|
|
113
|
-
initialValue?: T;
|
|
114
|
-
formItemId?: string;
|
|
115
|
-
rules?: any[];
|
|
116
|
-
valuePropName?: string;
|
|
117
|
-
getValueFromEvent?: (e: any) => T;
|
|
118
|
-
[key: string]: any;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function FormItem<T = any>(props: FormItemProps<T>): JSX.Element;
|
|
122
|
-
|
|
123
|
-
// FormList (generic for item shape)
|
|
124
|
-
export interface FormListProps<TItem = any> {
|
|
125
|
-
name: string;
|
|
126
|
-
initialValues?: TItem[];
|
|
127
|
-
form?: any;
|
|
128
|
-
formName?: string;
|
|
129
|
-
children: (listFields: any[], actions: any) => React.ReactNode;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function FormList<TItem = any>(props: FormListProps<TItem>): JSX.Element;
|
|
133
|
-
|
|
134
|
-
// Input components
|
|
135
|
-
export interface BasicInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
136
|
-
onChange?: (value: any, ...args: any[]) => void;
|
|
137
|
-
isValidating?: boolean;
|
|
138
|
-
[key: string]: any;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// InputWrapper
|
|
142
|
-
export interface InputWrapperProps {
|
|
143
|
-
children: React.ReactElement;
|
|
144
|
-
errors?: Array<{ ruleName?: string; message?: string }>;
|
|
145
|
-
isDirty?: boolean;
|
|
146
|
-
formState?: any;
|
|
147
|
-
name?: string;
|
|
148
|
-
formItemId?: string;
|
|
149
|
-
[key: string]: any;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function InputWrapper(props: InputWrapperProps): JSX.Element;
|
|
153
|
-
|
|
154
|
-
// Cleanup component (internal)
|
|
155
|
-
export function FormCleanUp(): JSX.Element;
|
|
156
|
-
|
|
157
|
-
// Hooks in src/hooks
|
|
158
|
-
export function useFormItemControl<T = any>(opts: {
|
|
159
|
-
formName?: string;
|
|
160
|
-
form?: any;
|
|
161
|
-
name: string;
|
|
162
|
-
initialValue?: T;
|
|
163
|
-
formItemId?: string;
|
|
164
|
-
rules?: any[];
|
|
165
|
-
elementRef?: React.RefObject<any>;
|
|
166
|
-
}): {
|
|
167
|
-
value: T | undefined;
|
|
168
|
-
onChange: (value: any, options?: any) => void;
|
|
169
|
-
state: any;
|
|
170
|
-
errors: any;
|
|
171
|
-
onFocus: () => void;
|
|
172
|
-
isDirty?: boolean;
|
|
173
|
-
onReset?: (value?: any) => void;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
export function useFormListControl<TItem = any>(opts: {
|
|
177
|
-
name: string;
|
|
178
|
-
form?: any;
|
|
179
|
-
initialValues?: TItem[];
|
|
180
|
-
formName?: string;
|
|
181
|
-
}): {
|
|
182
|
-
listFields: Array<{ name: string; key: string }>;
|
|
183
|
-
add: (index?: number) => void;
|
|
184
|
-
remove: (opts: { index?: number; key?: string }) => void;
|
|
185
|
-
move: (opts: { from?: number; fromKey?: string; to: number }) => void;
|
|
186
|
-
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +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";
|
|
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
|
+
export { Form, FormItem, FormList, Input, InputWrapper, useFormItemControl, useFormListControl, useForm, useWatch, useSubmitDataWatch, useFormStateWatch, };
|
|
9
|
+
export default Form;
|