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.
Files changed (94) hide show
  1. package/CHANGELOG.md +173 -4
  2. package/README.md +8 -4
  3. package/dist/components/Form/FormCleanUp.js +3 -3
  4. package/dist/components/Form/FormItem.d.ts +10 -4
  5. package/dist/components/Form/FormItem.js +52 -14
  6. package/dist/components/Form/FormList.d.ts +2 -2
  7. package/dist/components/Form/FormList.js +2 -2
  8. package/dist/constants/form.d.ts +1 -1
  9. package/dist/hooks/useFormItemControl.d.ts +8 -3
  10. package/dist/hooks/useFormItemControl.js +64 -28
  11. package/dist/hooks/useFormListControl.d.ts +2 -1
  12. package/dist/hooks/useFormListControl.js +85 -19
  13. package/dist/index.cjs.d.ts +1 -0
  14. package/dist/index.d.ts +4 -3
  15. package/dist/index.esm.d.ts +1 -0
  16. package/dist/index.js +4 -2
  17. package/dist/providers/Form.d.ts +15 -2
  18. package/dist/providers/Form.js +197 -22
  19. package/dist/stores/formStore.d.ts +44 -4
  20. package/dist/stores/formStore.js +42 -7
  21. package/dist/test/CommonTest.d.ts +3 -0
  22. package/dist/test/CommonTest.js +49 -0
  23. package/dist/test/TestDialog.d.ts +3 -0
  24. package/dist/test/TestDialog.js +21 -0
  25. package/dist/test/TestListener.d.ts +3 -0
  26. package/dist/test/TestListener.js +17 -0
  27. package/dist/test/TestNotFormWrapper.d.ts +3 -0
  28. package/dist/test/TestNotFormWrapper.js +15 -0
  29. package/dist/test/TestSelect.d.ts +6 -0
  30. package/dist/test/TestSelect.js +24 -0
  31. package/dist/test/TestWatchNormalize.d.ts +3 -0
  32. package/dist/test/TestWatchNormalize.js +23 -0
  33. package/dist/test/TestWrapperFormItem.d.ts +3 -0
  34. package/dist/test/TestWrapperFormItem.js +13 -0
  35. package/dist/test/testSetValue/TestCase10_SetFieldValues_ComplexNested.d.ts +21 -0
  36. package/dist/test/testSetValue/TestCase10_SetFieldValues_ComplexNested.js +61 -0
  37. package/dist/test/testSetValue/TestCase1_PlainObjectToPrimitives.d.ts +16 -0
  38. package/dist/test/testSetValue/TestCase1_PlainObjectToPrimitives.js +18 -0
  39. package/dist/test/testSetValue/TestCase2_PlainObjectToFormList.d.ts +21 -0
  40. package/dist/test/testSetValue/TestCase2_PlainObjectToFormList.js +33 -0
  41. package/dist/test/testSetValue/TestCase3_ArrayNonListenerToPrimitives.d.ts +21 -0
  42. package/dist/test/testSetValue/TestCase3_ArrayNonListenerToPrimitives.js +26 -0
  43. package/dist/test/testSetValue/TestCase4_PlainObjectRemovedFields.d.ts +20 -0
  44. package/dist/test/testSetValue/TestCase4_PlainObjectRemovedFields.js +32 -0
  45. package/dist/test/testSetValue/TestCase5_FormListRemovedItems.d.ts +22 -0
  46. package/dist/test/testSetValue/TestCase5_FormListRemovedItems.js +29 -0
  47. package/dist/test/testSetValue/TestCase6_NestedFormListRemoved.d.ts +28 -0
  48. package/dist/test/testSetValue/TestCase6_NestedFormListRemoved.js +36 -0
  49. package/dist/test/testSetValue/TestCase7_SetFieldValues_MixedStructure.d.ts +17 -0
  50. package/dist/test/testSetValue/TestCase7_SetFieldValues_MixedStructure.js +33 -0
  51. package/dist/test/testSetValue/TestCase8_SetFieldValues_NestedObject.d.ts +27 -0
  52. package/dist/test/testSetValue/TestCase8_SetFieldValues_NestedObject.js +57 -0
  53. package/dist/test/testSetValue/TestCase9_SetFieldValues_MultipleArrays.d.ts +25 -0
  54. package/dist/test/testSetValue/TestCase9_SetFieldValues_MultipleArrays.js +46 -0
  55. package/dist/test/testSetValue/index.d.ts +2 -0
  56. package/dist/test/testSetValue/index.js +28 -0
  57. package/dist/types/index.d.ts +1 -1
  58. package/dist/types/public.d.ts +1 -1
  59. package/dist/utils/obj.util.d.ts +29 -1
  60. package/dist/utils/obj.util.js +59 -5
  61. package/package.json +2 -1
  62. package/src/App.tsx +38 -163
  63. package/src/DEEP_TRIGGER_LOGIC.md +573 -0
  64. package/src/components/Form/FormCleanUp.tsx +4 -8
  65. package/src/components/Form/FormItem.tsx +174 -57
  66. package/src/components/Form/FormList.tsx +17 -4
  67. package/src/constants/form.ts +1 -1
  68. package/src/hooks/useFormItemControl.ts +78 -32
  69. package/src/hooks/useFormListControl.ts +133 -43
  70. package/src/index.ts +25 -13
  71. package/src/main.tsx +6 -1
  72. package/src/providers/Form.tsx +451 -23
  73. package/src/stores/formStore.ts +363 -283
  74. package/src/test/CommonTest.tsx +177 -0
  75. package/src/test/TestDialog.tsx +52 -0
  76. package/src/test/TestListener.tsx +21 -0
  77. package/src/test/TestNotFormWrapper.tsx +43 -0
  78. package/src/test/TestSelect.tsx +38 -0
  79. package/src/test/TestWatchNormalize.tsx +32 -0
  80. package/src/test/TestWrapperFormItem.tsx +34 -0
  81. package/src/test/testSetValue/TestCase10_SetFieldValues_ComplexNested.tsx +203 -0
  82. package/src/test/testSetValue/TestCase1_PlainObjectToPrimitives.tsx +72 -0
  83. package/src/test/testSetValue/TestCase2_PlainObjectToFormList.tsx +114 -0
  84. package/src/test/testSetValue/TestCase3_ArrayNonListenerToPrimitives.tsx +99 -0
  85. package/src/test/testSetValue/TestCase4_PlainObjectRemovedFields.tsx +112 -0
  86. package/src/test/testSetValue/TestCase5_FormListRemovedItems.tsx +119 -0
  87. package/src/test/testSetValue/TestCase6_NestedFormListRemoved.tsx +185 -0
  88. package/src/test/testSetValue/TestCase7_SetFieldValues_MixedStructure.tsx +110 -0
  89. package/src/test/testSetValue/TestCase8_SetFieldValues_NestedObject.tsx +162 -0
  90. package/src/test/testSetValue/TestCase9_SetFieldValues_MultipleArrays.tsx +169 -0
  91. package/src/test/testSetValue/index.tsx +100 -0
  92. package/src/types/index.ts +1 -1
  93. package/src/types/public.ts +1 -1
  94. package/src/utils/obj.util.ts +153 -13
package/src/App.tsx CHANGED
@@ -1,179 +1,54 @@
1
- import { Checkbox } from "@mui/material";
2
- import { Button, Input } from "antd";
3
- import { motion } from "framer-motion";
4
- import { useEffect } from "react";
5
- import FormItem from "./components/Form/FormItem";
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
- const App = () => {
13
- const [form] = useForm("form1");
11
+ function TestFormWatch() {
12
+ const watchValue = Form.useWatch("numericCode");
13
+
14
+ return <div>TestFormWatch</div>;
15
+ }
14
16
 
15
- const watchCheckBox = Form.useWatch("checkControlledAfterInit", "form1");
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
- <motion.div
28
- initial={{ opacity: 0 }}
29
- animate={{ opacity: 1 }}
30
- exit={{ opacity: 0 }}
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
- <AntdForm.Item name={"234"} initialValue={"23432"} label="Antd Input">
34
- <Input />
35
- </AntdForm.Item>
36
- </motion.div>
37
- </AntdForm>
28
+ <Input />
29
+ </AntdForm.Item>
38
30
 
39
- {/* Hidden Test */}
40
- <Form
41
- initialValues={{
42
- TestData: "",
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
- <InputWrapper>
64
- <Input />
65
- </InputWrapper>
66
- </FormItem>
36
+ <Input />
37
+ </AntdForm.Item>
38
+ </AntdForm> */}
67
39
 
68
- {/* Numberic test */}
69
- <FormItem
70
- name={"numericCode"}
71
- rules={[
72
- { required: true, message: "Vui lòng nhập mã" },
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
- {/* Motion Test */}
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
- <Button
160
- onClick={() => {
161
- const current = form?.getFieldValue("checkControlledAfterInit");
162
- console.log("Toggle controlled after init: ", current);
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
  };