react-form-manage 1.0.8-beta.9 → 1.0.8
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 +173 -4
- package/README.md +8 -4
- package/dist/components/Form/FormCleanUp.js +3 -3
- package/dist/components/Form/FormItem.d.ts +10 -4
- package/dist/components/Form/FormItem.js +52 -14
- package/dist/components/Form/FormList.d.ts +2 -2
- package/dist/components/Form/FormList.js +2 -2
- package/dist/constants/form.d.ts +1 -1
- package/dist/hooks/useFormItemControl.d.ts +8 -3
- package/dist/hooks/useFormItemControl.js +64 -28
- package/dist/hooks/useFormListControl.d.ts +2 -1
- package/dist/hooks/useFormListControl.js +85 -19
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.esm.d.ts +1 -0
- package/dist/index.js +4 -2
- package/dist/providers/Form.d.ts +15 -2
- package/dist/providers/Form.js +197 -22
- package/dist/stores/formStore.d.ts +44 -4
- package/dist/stores/formStore.js +42 -7
- package/dist/test/CommonTest.d.ts +3 -0
- package/dist/test/CommonTest.js +49 -0
- package/dist/test/TestDialog.d.ts +3 -0
- package/dist/test/TestDialog.js +21 -0
- package/dist/test/TestListener.d.ts +3 -0
- package/dist/test/TestListener.js +17 -0
- package/dist/test/TestNotFormWrapper.d.ts +3 -0
- package/dist/test/TestNotFormWrapper.js +15 -0
- package/dist/test/TestSelect.d.ts +6 -0
- package/dist/test/TestSelect.js +24 -0
- package/dist/test/TestWatchNormalize.d.ts +3 -0
- package/dist/test/TestWatchNormalize.js +23 -0
- package/dist/test/TestWrapperFormItem.d.ts +3 -0
- package/dist/test/TestWrapperFormItem.js +13 -0
- package/dist/test/testSetValue/TestCase10_SetFieldValues_ComplexNested.d.ts +21 -0
- package/dist/test/testSetValue/TestCase10_SetFieldValues_ComplexNested.js +61 -0
- package/dist/test/testSetValue/TestCase1_PlainObjectToPrimitives.d.ts +16 -0
- package/dist/test/testSetValue/TestCase1_PlainObjectToPrimitives.js +18 -0
- package/dist/test/testSetValue/TestCase2_PlainObjectToFormList.d.ts +21 -0
- package/dist/test/testSetValue/TestCase2_PlainObjectToFormList.js +33 -0
- package/dist/test/testSetValue/TestCase3_ArrayNonListenerToPrimitives.d.ts +21 -0
- package/dist/test/testSetValue/TestCase3_ArrayNonListenerToPrimitives.js +26 -0
- package/dist/test/testSetValue/TestCase4_PlainObjectRemovedFields.d.ts +20 -0
- package/dist/test/testSetValue/TestCase4_PlainObjectRemovedFields.js +32 -0
- package/dist/test/testSetValue/TestCase5_FormListRemovedItems.d.ts +22 -0
- package/dist/test/testSetValue/TestCase5_FormListRemovedItems.js +29 -0
- package/dist/test/testSetValue/TestCase6_NestedFormListRemoved.d.ts +28 -0
- package/dist/test/testSetValue/TestCase6_NestedFormListRemoved.js +36 -0
- package/dist/test/testSetValue/TestCase7_SetFieldValues_MixedStructure.d.ts +17 -0
- package/dist/test/testSetValue/TestCase7_SetFieldValues_MixedStructure.js +33 -0
- package/dist/test/testSetValue/TestCase8_SetFieldValues_NestedObject.d.ts +27 -0
- package/dist/test/testSetValue/TestCase8_SetFieldValues_NestedObject.js +57 -0
- package/dist/test/testSetValue/TestCase9_SetFieldValues_MultipleArrays.d.ts +25 -0
- package/dist/test/testSetValue/TestCase9_SetFieldValues_MultipleArrays.js +46 -0
- package/dist/test/testSetValue/index.d.ts +2 -0
- package/dist/test/testSetValue/index.js +28 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/public.d.ts +1 -1
- package/dist/utils/obj.util.d.ts +29 -1
- package/dist/utils/obj.util.js +59 -5
- package/package.json +2 -1
- package/src/App.tsx +38 -163
- package/src/DEEP_TRIGGER_LOGIC.md +573 -0
- package/src/components/Form/FormCleanUp.tsx +4 -8
- package/src/components/Form/FormItem.tsx +174 -57
- package/src/components/Form/FormList.tsx +17 -4
- package/src/constants/form.ts +1 -1
- package/src/hooks/useFormItemControl.ts +78 -32
- package/src/hooks/useFormListControl.ts +133 -43
- package/src/index.ts +25 -13
- package/src/main.tsx +6 -1
- package/src/providers/Form.tsx +451 -23
- package/src/stores/formStore.ts +363 -283
- package/src/test/CommonTest.tsx +177 -0
- package/src/test/TestDialog.tsx +52 -0
- package/src/test/TestListener.tsx +21 -0
- package/src/test/TestNotFormWrapper.tsx +43 -0
- package/src/test/TestSelect.tsx +38 -0
- package/src/test/TestWatchNormalize.tsx +32 -0
- package/src/test/TestWrapperFormItem.tsx +34 -0
- package/src/test/testSetValue/TestCase10_SetFieldValues_ComplexNested.tsx +203 -0
- package/src/test/testSetValue/TestCase1_PlainObjectToPrimitives.tsx +72 -0
- package/src/test/testSetValue/TestCase2_PlainObjectToFormList.tsx +114 -0
- package/src/test/testSetValue/TestCase3_ArrayNonListenerToPrimitives.tsx +99 -0
- package/src/test/testSetValue/TestCase4_PlainObjectRemovedFields.tsx +112 -0
- package/src/test/testSetValue/TestCase5_FormListRemovedItems.tsx +119 -0
- package/src/test/testSetValue/TestCase6_NestedFormListRemoved.tsx +185 -0
- package/src/test/testSetValue/TestCase7_SetFieldValues_MixedStructure.tsx +110 -0
- package/src/test/testSetValue/TestCase8_SetFieldValues_NestedObject.tsx +162 -0
- package/src/test/testSetValue/TestCase9_SetFieldValues_MultipleArrays.tsx +169 -0
- package/src/test/testSetValue/index.tsx +100 -0
- package/src/types/index.ts +1 -1
- package/src/types/public.ts +1 -1
- package/src/utils/obj.util.ts +153 -13
package/src/App.tsx
CHANGED
|
@@ -1,179 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import FormList from "./components/Form/FormList";
|
|
7
|
-
import InputWrapper from "./components/Form/InputWrapper";
|
|
8
|
-
import Form, { useForm } from "./providers/Form";
|
|
1
|
+
import { Input } from "antd";
|
|
2
|
+
import Form from "./providers/Form";
|
|
3
|
+
import TestDialog from "./test/TestDialog";
|
|
4
|
+
import TestListener from "./test/TestListener";
|
|
5
|
+
import TestWrapperFormItem from "./test/TestWrapperFormItem";
|
|
9
6
|
|
|
10
7
|
import { Form as AntdForm } from "antd";
|
|
8
|
+
import TestWatchNormalize from "./test/TestWatchNormalize";
|
|
9
|
+
import TestSetValueIndex from "./test/testSetValue";
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
const
|
|
11
|
+
function TestFormWatch() {
|
|
12
|
+
const watchValue = Form.useWatch("numericCode");
|
|
13
|
+
|
|
14
|
+
return <div>TestFormWatch</div>;
|
|
15
|
+
}
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
const App = () => {
|
|
18
|
+
const [antdForm] = AntdForm.useForm();
|
|
16
19
|
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
if (form) {
|
|
19
|
-
// setTimeout(() => {
|
|
20
|
-
// form.setFieldValue("TestData", "HelloWorld");
|
|
21
|
-
// }, 500);
|
|
22
|
-
}
|
|
23
|
-
}, [form]);
|
|
24
20
|
return (
|
|
25
21
|
<div>
|
|
26
|
-
<AntdForm>
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
transition={{ duration: 1 }}
|
|
22
|
+
{/* <AntdForm form={antdForm}>
|
|
23
|
+
<AntdForm.Item
|
|
24
|
+
name={"test.testt"}
|
|
25
|
+
initialValue={"số 1"}
|
|
26
|
+
label="Antd Input"
|
|
32
27
|
>
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
</AntdForm.Item>
|
|
36
|
-
</motion.div>
|
|
37
|
-
</AntdForm>
|
|
28
|
+
<Input />
|
|
29
|
+
</AntdForm.Item>
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
numericCode: "",
|
|
44
|
-
arr: [{ el: "Item 1" }, { el: "Item 2" }],
|
|
45
|
-
}}
|
|
46
|
-
onFinish={(values) => {
|
|
47
|
-
console.log(values);
|
|
48
|
-
}}
|
|
49
|
-
formName={"form1"}
|
|
50
|
-
// hidden
|
|
51
|
-
>
|
|
52
|
-
<FormItem
|
|
53
|
-
name={"username"}
|
|
54
|
-
rules={[
|
|
55
|
-
{
|
|
56
|
-
required: true,
|
|
57
|
-
message: "Test",
|
|
58
|
-
},
|
|
59
|
-
]}
|
|
60
|
-
initialValue={"283746"}
|
|
61
|
-
// hidden
|
|
31
|
+
<AntdForm.Item
|
|
32
|
+
name={"test.testt2"}
|
|
33
|
+
initialValue={"số 2"}
|
|
34
|
+
label="Antd Input"
|
|
62
35
|
>
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
</FormItem>
|
|
36
|
+
<Input />
|
|
37
|
+
</AntdForm.Item>
|
|
38
|
+
</AntdForm> */}
|
|
67
39
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
pattern: /^\d+$/,
|
|
75
|
-
message: "Chỉ cho phép chuỗi số",
|
|
76
|
-
},
|
|
77
|
-
]}
|
|
78
|
-
>
|
|
79
|
-
<InputWrapper>
|
|
80
|
-
<Input placeholder="Mã chỉ gồm số" style={{ width: 200 }} />
|
|
81
|
-
</InputWrapper>
|
|
82
|
-
</FormItem>
|
|
40
|
+
{/* Hidden Test */}
|
|
41
|
+
{/* <CommonTest /> */}
|
|
42
|
+
{/* <Form formName="TestDialog">
|
|
43
|
+
<TestDialog />
|
|
44
|
+
</Form> */}
|
|
83
45
|
|
|
84
|
-
|
|
85
|
-
<motion.div
|
|
86
|
-
initial={{ opacity: 0 }}
|
|
87
|
-
animate={{ opacity: 1 }}
|
|
88
|
-
exit={{ opacity: 0 }}
|
|
89
|
-
transition={{ duration: 1 }}
|
|
90
|
-
>
|
|
91
|
-
<FormItem name="motionTest" controlAfterInit initialValue={"1234134"}>
|
|
92
|
-
<InputWrapper>
|
|
93
|
-
<Input placeholder="Motion Test" style={{ width: 200 }} />
|
|
94
|
-
</InputWrapper>
|
|
95
|
-
</FormItem>
|
|
96
|
-
</motion.div>
|
|
97
|
-
<FormList
|
|
98
|
-
initialValues={[
|
|
99
|
-
{
|
|
100
|
-
el: "",
|
|
101
|
-
},
|
|
102
|
-
]}
|
|
103
|
-
name="arr"
|
|
104
|
-
>
|
|
105
|
-
{(fields, { add, remove, move }) => (
|
|
106
|
-
<div>
|
|
107
|
-
{fields.map((field, index) => (
|
|
108
|
-
<div key={field.key} style={{ marginBottom: 8 }}>
|
|
109
|
-
<FormItem name={`${field.name}.el`}>
|
|
110
|
-
<InputWrapper>
|
|
111
|
-
<Input placeholder="Item value" style={{ width: 200 }} />
|
|
112
|
-
</InputWrapper>
|
|
113
|
-
</FormItem>
|
|
114
|
-
<Button
|
|
115
|
-
onClick={() => remove({ index })}
|
|
116
|
-
style={{ marginLeft: 8 }}
|
|
117
|
-
>
|
|
118
|
-
Remove
|
|
119
|
-
</Button>
|
|
120
|
-
{index > 0 && (
|
|
121
|
-
<Button
|
|
122
|
-
onClick={() => move({ from: index, to: index - 1 })}
|
|
123
|
-
style={{ marginLeft: 8 }}
|
|
124
|
-
>
|
|
125
|
-
Move Up
|
|
126
|
-
</Button>
|
|
127
|
-
)}
|
|
128
|
-
{index < fields.length - 1 && (
|
|
129
|
-
<Button
|
|
130
|
-
onClick={() => move({ from: index, to: index + 1 })}
|
|
131
|
-
style={{ marginLeft: 8 }}
|
|
132
|
-
>
|
|
133
|
-
Move Down
|
|
134
|
-
</Button>
|
|
135
|
-
)}
|
|
136
|
-
</div>
|
|
137
|
-
))}
|
|
138
|
-
<Button onClick={() => add(fields.length)}>Add Item</Button>
|
|
139
|
-
</div>
|
|
140
|
-
)}
|
|
141
|
-
</FormList>
|
|
142
|
-
<motion.div
|
|
143
|
-
initial={{ opacity: 0 }}
|
|
144
|
-
animate={{ opacity: 1 }}
|
|
145
|
-
exit={{ opacity: 0 }}
|
|
146
|
-
transition={{ duration: 1.5 }}
|
|
147
|
-
>
|
|
148
|
-
<FormItem
|
|
149
|
-
valuePropName="checked"
|
|
150
|
-
getValueFromEvent={(_, checked) => checked}
|
|
151
|
-
name="checkControlledAfterInit"
|
|
152
|
-
controlAfterInit={true}
|
|
153
|
-
initialValue={true}
|
|
154
|
-
>
|
|
155
|
-
<Checkbox />
|
|
156
|
-
</FormItem>
|
|
157
|
-
</motion.div>
|
|
46
|
+
{/* <TestWatchNormalize />
|
|
158
47
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
form?.setFieldValue("checkControlledAfterInit", !current);
|
|
164
|
-
}}
|
|
165
|
-
>
|
|
166
|
-
Toggle
|
|
167
|
-
</Button>
|
|
168
|
-
<Button htmlType="submit">Submit</Button>
|
|
169
|
-
<Button
|
|
170
|
-
onClick={() => {
|
|
171
|
-
form?.resetFields?.();
|
|
172
|
-
}}
|
|
173
|
-
>
|
|
174
|
-
Reset
|
|
175
|
-
</Button>
|
|
176
|
-
</Form>
|
|
48
|
+
<TestListener />
|
|
49
|
+
<TestWrapperFormItem /> */}
|
|
50
|
+
|
|
51
|
+
<TestSetValueIndex />
|
|
177
52
|
</div>
|
|
178
53
|
);
|
|
179
54
|
};
|