@nutui/nutui-react-taro 3.0.0 → 3.0.2

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 (247) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/hooks/use-client-rect.js +1 -0
  3. package/dist/cjs/packages/actionsheet/style/style.css +12 -0
  4. package/dist/cjs/packages/address/style/style.css +12 -0
  5. package/dist/cjs/packages/calendar/style/style.css +12 -0
  6. package/dist/cjs/packages/cascader/style/style.css +12 -0
  7. package/dist/cjs/packages/configprovider/types.d.ts +1 -1
  8. package/dist/cjs/packages/datepicker/datepicker.js +8 -6
  9. package/dist/cjs/packages/datepicker/style/style.css +82 -0
  10. package/dist/cjs/packages/datepickerview/datepickerview.d.ts +3 -0
  11. package/dist/cjs/packages/datepickerview/datepickerview.js +119 -0
  12. package/dist/cjs/packages/datepickerview/index.d.ts +3 -0
  13. package/dist/cjs/packages/{subsidenavbar → datepickerview}/index.js +2 -2
  14. package/dist/cjs/packages/datepickerview/style/datepickerview.scss +4 -0
  15. package/dist/cjs/packages/datepickerview/style/index.js +2 -0
  16. package/dist/cjs/packages/datepickerview/style/style.css +78 -0
  17. package/dist/cjs/packages/datepickerview/style/style.harmony.css +8 -0
  18. package/dist/cjs/packages/datepickerview/types.d.ts +15 -0
  19. package/dist/cjs/packages/datepickerview/types.js +4 -0
  20. package/dist/cjs/packages/dialog/dialog.js +8 -3
  21. package/dist/cjs/packages/dialog/style/dialog.scss +0 -1
  22. package/dist/cjs/packages/dialog/style/style.css +0 -1
  23. package/dist/cjs/packages/dialog/style/style.harmony.css +0 -1
  24. package/dist/cjs/packages/drag/drag.js +33 -39
  25. package/dist/cjs/packages/drag/style/drag.scss +1 -0
  26. package/dist/cjs/packages/drag/style/style.css +1 -0
  27. package/dist/cjs/packages/drag/style/style.harmony.css +1 -0
  28. package/dist/cjs/packages/fixednav/fixednav.js +20 -14
  29. package/dist/cjs/packages/fixednav/style/fixednav.scss +0 -15
  30. package/dist/cjs/packages/fixednav/style/style.css +0 -14
  31. package/dist/cjs/packages/fixednav/style/style.harmony.css +0 -14
  32. package/dist/cjs/packages/form/form.d.ts +2 -0
  33. package/dist/cjs/packages/form/form.js +11 -2
  34. package/dist/cjs/packages/form/index.d.ts +2 -1
  35. package/dist/cjs/packages/form/index.js +1 -0
  36. package/dist/cjs/packages/form/style/form.scss +0 -66
  37. package/dist/cjs/packages/form/style/style.css +31 -21
  38. package/dist/cjs/packages/form/style/style.harmony.css +1 -67
  39. package/dist/cjs/packages/form/types.d.ts +2 -1
  40. package/dist/cjs/packages/form/useform.d.ts +2 -1
  41. package/dist/cjs/packages/form/useform.js +338 -247
  42. package/dist/cjs/packages/formitem/formitem.d.ts +1 -0
  43. package/dist/cjs/packages/formitem/formitem.js +57 -45
  44. package/dist/cjs/packages/formitem/style/formitem.scss +101 -21
  45. package/dist/cjs/packages/formitem/style/style.css +89 -12
  46. package/dist/cjs/packages/formitem/style/style.harmony.css +89 -12
  47. package/dist/cjs/packages/imagepreview/style/style.css +12 -0
  48. package/dist/cjs/packages/input/input.js +5 -2
  49. package/dist/cjs/packages/input/style/input.scss +6 -4
  50. package/dist/cjs/packages/input/style/style.css +4 -0
  51. package/dist/cjs/packages/input/style/style.harmony.css +8 -0
  52. package/dist/cjs/packages/numberkeyboard/style/style.css +12 -0
  53. package/dist/cjs/packages/nutui.react.build.d.ts +11 -15
  54. package/dist/cjs/packages/nutui.react.build.js +172 -180
  55. package/dist/cjs/packages/nutui.react.d.ts +16 -22
  56. package/dist/cjs/packages/nutui.react.js +177 -187
  57. package/dist/cjs/packages/nutui.react.scss.d.ts +5 -7
  58. package/dist/cjs/packages/nutui.react.scss.js +5 -7
  59. package/dist/cjs/packages/overlay/overlay.js +4 -5
  60. package/dist/cjs/packages/overlay/style/overlay.scss +0 -4
  61. package/dist/cjs/packages/picker/style/index.js +1 -0
  62. package/dist/cjs/packages/picker/style/style.css +82 -0
  63. package/dist/cjs/packages/popover/style/style.css +12 -0
  64. package/dist/cjs/packages/popup/popup.js +17 -11
  65. package/dist/cjs/packages/popup/style/popup.scss +12 -4
  66. package/dist/cjs/packages/popup/style/style.css +12 -0
  67. package/dist/cjs/packages/popup/style/style.harmony.css +12 -0
  68. package/dist/cjs/packages/shortpassword/shortpassword.js +5 -7
  69. package/dist/cjs/packages/shortpassword/style/shortpassword.scss +10 -0
  70. package/dist/cjs/packages/shortpassword/style/style.css +21 -0
  71. package/dist/cjs/packages/shortpassword/style/style.harmony.css +9 -0
  72. package/dist/cjs/packages/signature/signature.js +1 -1
  73. package/dist/cjs/packages/swipe/style/style.css +3 -3
  74. package/dist/cjs/packages/swipe/style/style.harmony.css +3 -3
  75. package/dist/cjs/packages/swipe/style/swipe.scss +7 -3
  76. package/dist/cjs/packages/swipe/swipe.js +14 -15
  77. package/dist/cjs/packages/tabbar/style/style.css +6 -0
  78. package/dist/cjs/packages/tabbaritem/style/style.css +6 -0
  79. package/dist/cjs/packages/tabbaritem/style/style.harmony.css +6 -0
  80. package/dist/cjs/packages/tabbaritem/style/tabbaritem.scss +6 -0
  81. package/dist/cjs/packages/tabs/tabs.js +6 -13
  82. package/dist/cjs/packages/textarea/textarea.js +1 -1
  83. package/dist/cjs/packages/timeselect/style/style.css +12 -0
  84. package/dist/cjs/packages/tour/style/style.css +12 -0
  85. package/dist/cjs/utils/get-rect-by-taro.d.ts +1 -1
  86. package/dist/cjs/utils/get-rect-by-taro.js +4 -1
  87. package/dist/cjs/utils/get-system-info.js +4 -5
  88. package/dist/cjs/utils/merge.d.ts +14 -0
  89. package/dist/cjs/utils/merge.js +98 -0
  90. package/dist/cjs/utils/platform-taro.js +4 -5
  91. package/dist/cjs/utils/to-array.d.ts +1 -0
  92. package/dist/cjs/utils/to-array.js +18 -0
  93. package/dist/es/hooks/use-client-rect.js +1 -0
  94. package/dist/es/packages/actionsheet/style/style.css +12 -0
  95. package/dist/es/packages/address/style/style.css +12 -0
  96. package/dist/es/packages/calendar/style/style.css +12 -0
  97. package/dist/es/packages/cascader/style/style.css +12 -0
  98. package/dist/es/packages/configprovider/types.d.ts +1 -1
  99. package/dist/es/packages/datepicker/datepicker.js +8 -6
  100. package/dist/es/packages/datepicker/style/style.css +82 -0
  101. package/dist/es/packages/datepickerview/datepickerview.d.ts +3 -0
  102. package/dist/es/packages/datepickerview/datepickerview.js +107 -0
  103. package/dist/es/packages/datepickerview/index.d.ts +3 -0
  104. package/dist/es/packages/datepickerview/index.js +2 -0
  105. package/dist/es/packages/datepickerview/style/datepickerview.scss +4 -0
  106. package/dist/es/packages/datepickerview/style/index.js +2 -0
  107. package/dist/es/packages/datepickerview/style/style.css +78 -0
  108. package/dist/es/packages/datepickerview/style/style.harmony.css +8 -0
  109. package/dist/es/packages/datepickerview/types.d.ts +15 -0
  110. package/dist/es/packages/datepickerview/types.js +1 -0
  111. package/dist/es/packages/dialog/dialog.js +8 -3
  112. package/dist/es/packages/dialog/style/dialog.scss +0 -1
  113. package/dist/es/packages/dialog/style/style.css +0 -1
  114. package/dist/es/packages/dialog/style/style.harmony.css +0 -1
  115. package/dist/es/packages/drag/drag.js +33 -39
  116. package/dist/es/packages/drag/style/drag.scss +1 -0
  117. package/dist/es/packages/drag/style/style.css +1 -0
  118. package/dist/es/packages/drag/style/style.harmony.css +1 -0
  119. package/dist/es/packages/fixednav/fixednav.js +20 -14
  120. package/dist/es/packages/fixednav/style/fixednav.scss +0 -15
  121. package/dist/es/packages/fixednav/style/style.css +0 -14
  122. package/dist/es/packages/fixednav/style/style.harmony.css +0 -14
  123. package/dist/es/packages/form/form.d.ts +10 -0
  124. package/dist/es/packages/form/form.js +11 -2
  125. package/dist/es/packages/form/index.d.ts +2 -1
  126. package/dist/es/packages/form/index.js +2 -1
  127. package/dist/es/packages/form/style/form.scss +0 -66
  128. package/dist/es/packages/form/style/style.css +31 -21
  129. package/dist/es/packages/form/style/style.harmony.css +1 -67
  130. package/dist/es/packages/form/types.d.ts +2 -1
  131. package/dist/es/packages/form/useform.d.ts +2 -1
  132. package/dist/es/packages/form/useform.js +336 -248
  133. package/dist/es/packages/formitem/formitem.d.ts +1 -0
  134. package/dist/es/packages/formitem/formitem.js +58 -46
  135. package/dist/es/packages/formitem/style/formitem.scss +101 -21
  136. package/dist/es/packages/formitem/style/style.css +89 -12
  137. package/dist/es/packages/formitem/style/style.harmony.css +89 -12
  138. package/dist/es/packages/imagepreview/style/style.css +12 -0
  139. package/dist/es/packages/input/input.js +5 -2
  140. package/dist/es/packages/input/style/input.scss +6 -4
  141. package/dist/es/packages/input/style/style.css +4 -0
  142. package/dist/es/packages/input/style/style.harmony.css +8 -0
  143. package/dist/es/packages/numberkeyboard/style/style.css +12 -0
  144. package/dist/es/packages/nutui.react.build.d.ts +11 -15
  145. package/dist/es/packages/nutui.react.build.js +11 -15
  146. package/dist/es/packages/overlay/overlay.js +4 -5
  147. package/dist/es/packages/overlay/style/overlay.scss +0 -4
  148. package/dist/es/packages/picker/style/index.js +1 -0
  149. package/dist/es/packages/picker/style/style.css +82 -0
  150. package/dist/es/packages/popover/style/style.css +12 -0
  151. package/dist/es/packages/popup/popup.js +17 -11
  152. package/dist/es/packages/popup/style/popup.scss +12 -4
  153. package/dist/es/packages/popup/style/style.css +12 -0
  154. package/dist/es/packages/popup/style/style.harmony.css +12 -0
  155. package/dist/es/packages/shortpassword/shortpassword.js +5 -7
  156. package/dist/es/packages/shortpassword/style/shortpassword.scss +10 -0
  157. package/dist/es/packages/shortpassword/style/style.css +21 -0
  158. package/dist/es/packages/shortpassword/style/style.harmony.css +9 -0
  159. package/dist/es/packages/signature/signature.js +2 -2
  160. package/dist/es/packages/swipe/style/style.css +3 -3
  161. package/dist/es/packages/swipe/style/style.harmony.css +3 -3
  162. package/dist/es/packages/swipe/style/swipe.scss +7 -3
  163. package/dist/es/packages/swipe/swipe.js +14 -15
  164. package/dist/es/packages/tabbar/style/style.css +6 -0
  165. package/dist/es/packages/tabbaritem/style/style.css +6 -0
  166. package/dist/es/packages/tabbaritem/style/style.harmony.css +6 -0
  167. package/dist/es/packages/tabbaritem/style/tabbaritem.scss +6 -0
  168. package/dist/es/packages/tabs/tabs.js +6 -13
  169. package/dist/es/packages/textarea/textarea.js +2 -2
  170. package/dist/es/packages/timeselect/style/style.css +12 -0
  171. package/dist/es/packages/tour/style/style.css +12 -0
  172. package/dist/es/utils/get-rect-by-taro.d.ts +1 -1
  173. package/dist/es/utils/get-rect-by-taro.js +4 -1
  174. package/dist/es/utils/get-system-info.js +4 -4
  175. package/dist/es/utils/merge.d.ts +14 -0
  176. package/dist/es/utils/merge.js +68 -0
  177. package/dist/es/utils/platform-taro.js +4 -4
  178. package/dist/es/utils/to-array.d.ts +1 -0
  179. package/dist/es/utils/to-array.js +8 -0
  180. package/dist/nutui.react.umd.js +5593 -5442
  181. package/dist/style.css +1 -1
  182. package/dist/style.scss +34 -36
  183. package/dist/styles/variables-jmapp.scss +0 -50
  184. package/dist/styles/variables-jrkf.scss +0 -50
  185. package/dist/styles/variables.scss +0 -49
  186. package/package.json +1 -1
  187. package/dist/cjs/packages/sidenavbar/context.d.ts +0 -1
  188. package/dist/cjs/packages/sidenavbar/context.js +0 -12
  189. package/dist/cjs/packages/sidenavbar/index.d.ts +0 -3
  190. package/dist/cjs/packages/sidenavbar/index.js +0 -12
  191. package/dist/cjs/packages/sidenavbar/sidenavbar.d.ts +0 -14
  192. package/dist/cjs/packages/sidenavbar/sidenavbar.js +0 -75
  193. package/dist/cjs/packages/sidenavbar/style/index.js +0 -2
  194. package/dist/cjs/packages/sidenavbar/style/sidenavbar.scss +0 -89
  195. package/dist/cjs/packages/sidenavbar/style/style.css +0 -443
  196. package/dist/cjs/packages/sidenavbar/style/style.harmony.css +0 -74
  197. package/dist/cjs/packages/sidenavbar/utils.d.ts +0 -3
  198. package/dist/cjs/packages/sidenavbar/utils.js +0 -23
  199. package/dist/cjs/packages/sidenavbaritem/index.d.ts +0 -3
  200. package/dist/cjs/packages/sidenavbaritem/index.js +0 -12
  201. package/dist/cjs/packages/sidenavbaritem/sidenavbaritem.d.ts +0 -11
  202. package/dist/cjs/packages/sidenavbaritem/sidenavbaritem.js +0 -34
  203. package/dist/cjs/packages/sidenavbaritem/style/index.js +0 -1
  204. package/dist/cjs/packages/sidenavbaritem/style/sidenavbaritem.scss +0 -13
  205. package/dist/cjs/packages/sidenavbaritem/style/style.css +0 -14
  206. package/dist/cjs/packages/sidenavbaritem/style/style.harmony.css +0 -14
  207. package/dist/cjs/packages/subsidenavbar/index.d.ts +0 -3
  208. package/dist/cjs/packages/subsidenavbar/style/css.js +0 -1
  209. package/dist/cjs/packages/subsidenavbar/style/index.js +0 -1
  210. package/dist/cjs/packages/subsidenavbar/style/style.css +0 -20
  211. package/dist/cjs/packages/subsidenavbar/style/style.harmony.css +0 -20
  212. package/dist/cjs/packages/subsidenavbar/style/subsidenavbar.scss +0 -26
  213. package/dist/cjs/packages/subsidenavbar/subsidenavbar.d.ts +0 -13
  214. package/dist/cjs/packages/subsidenavbar/subsidenavbar.js +0 -90
  215. package/dist/es/packages/sidenavbar/context.d.ts +0 -1
  216. package/dist/es/packages/sidenavbar/context.js +0 -2
  217. package/dist/es/packages/sidenavbar/index.d.ts +0 -3
  218. package/dist/es/packages/sidenavbar/index.js +0 -2
  219. package/dist/es/packages/sidenavbar/sidenavbar.d.ts +0 -38
  220. package/dist/es/packages/sidenavbar/sidenavbar.js +0 -63
  221. package/dist/es/packages/sidenavbar/style/css.js +0 -1
  222. package/dist/es/packages/sidenavbar/style/index.js +0 -2
  223. package/dist/es/packages/sidenavbar/style/sidenavbar.scss +0 -89
  224. package/dist/es/packages/sidenavbar/style/style.css +0 -443
  225. package/dist/es/packages/sidenavbar/style/style.harmony.css +0 -74
  226. package/dist/es/packages/sidenavbar/utils.d.ts +0 -3
  227. package/dist/es/packages/sidenavbar/utils.js +0 -14
  228. package/dist/es/packages/sidenavbaritem/index.d.ts +0 -3
  229. package/dist/es/packages/sidenavbaritem/index.js +0 -2
  230. package/dist/es/packages/sidenavbaritem/sidenavbaritem.d.ts +0 -11
  231. package/dist/es/packages/sidenavbaritem/sidenavbaritem.js +0 -23
  232. package/dist/es/packages/sidenavbaritem/style/css.js +0 -1
  233. package/dist/es/packages/sidenavbaritem/style/index.js +0 -1
  234. package/dist/es/packages/sidenavbaritem/style/sidenavbaritem.scss +0 -13
  235. package/dist/es/packages/sidenavbaritem/style/style.css +0 -14
  236. package/dist/es/packages/sidenavbaritem/style/style.harmony.css +0 -14
  237. package/dist/es/packages/subsidenavbar/index.d.ts +0 -3
  238. package/dist/es/packages/subsidenavbar/index.js +0 -2
  239. package/dist/es/packages/subsidenavbar/style/css.js +0 -1
  240. package/dist/es/packages/subsidenavbar/style/index.js +0 -1
  241. package/dist/es/packages/subsidenavbar/style/style.css +0 -20
  242. package/dist/es/packages/subsidenavbar/style/style.harmony.css +0 -20
  243. package/dist/es/packages/subsidenavbar/style/subsidenavbar.scss +0 -26
  244. package/dist/es/packages/subsidenavbar/subsidenavbar.d.ts +0 -13
  245. package/dist/es/packages/subsidenavbar/subsidenavbar.js +0 -79
  246. /package/dist/cjs/packages/{sidenavbar → datepickerview}/style/css.js +0 -0
  247. /package/dist/{cjs/packages/sidenavbaritem → es/packages/datepickerview}/style/css.js +0 -0
@@ -14,309 +14,380 @@ _export(exports, {
14
14
  },
15
15
  useForm: function() {
16
16
  return useForm;
17
+ },
18
+ useWatch: function() {
19
+ return useWatch;
17
20
  }
18
21
  });
19
22
  var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
20
23
  var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
21
24
  var _class_call_check = require("@swc/helpers/_/_class_call_check");
25
+ var _create_class = require("@swc/helpers/_/_create_class");
22
26
  var _define_property = require("@swc/helpers/_/_define_property");
23
27
  var _object_spread = require("@swc/helpers/_/_object_spread");
28
+ var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
24
29
  var _to_consumable_array = require("@swc/helpers/_/_to_consumable_array");
25
30
  var _ts_generator = require("@swc/helpers/_/_ts_generator");
26
31
  var _react = require("react");
27
32
  var _asyncvalidator = /*#__PURE__*/ _interop_require_default._(require("async-validator"));
33
+ var _merge = require("../../utils/merge");
28
34
  var SECRET = 'NUT_FORM_INTERNAL';
29
35
  /**
30
36
  * 用于存储表单的数据
31
- */ var FormStore = function FormStore() {
37
+ */ var FormStore = /*#__PURE__*/ function() {
32
38
  "use strict";
33
- var _this = this;
34
- var _this1 = this;
35
- (0, _class_call_check._)(this, FormStore);
36
- var _this2 = this;
37
- // 初始化数据
38
- (0, _define_property._)(this, "initialValues", {});
39
- (0, _define_property._)(this, "updateList", []);
40
- // 存放表单中所有的数据 eg. {password: "ddd",username: "123"}
41
- (0, _define_property._)(this, "store", {});
42
- // 所有的组件实例
43
- (0, _define_property._)(this, "fieldEntities", []);
44
- // 校验成功或失败的回调,onFinish、onFinishFailed
45
- (0, _define_property._)(this, "callbacks", {});
46
- (0, _define_property._)(this, "errors", {});
47
- /**
39
+ function FormStore() {
40
+ var _this = this;
41
+ var _this1 = this;
42
+ (0, _class_call_check._)(this, FormStore);
43
+ var _this2 = this;
44
+ // 初始化数据
45
+ (0, _define_property._)(this, "initialValues", {});
46
+ (0, _define_property._)(this, "updateList", []);
47
+ // 存放表单中所有的数据 eg. {password: "ddd",username: "123"}
48
+ (0, _define_property._)(this, "store", {});
49
+ // 所有的组件实例
50
+ (0, _define_property._)(this, "fieldEntities", []);
51
+ // 校验成功或失败的回调,onFinish、onFinishFailed
52
+ (0, _define_property._)(this, "callbacks", {});
53
+ (0, _define_property._)(this, "errors", {});
54
+ /**
48
55
  * 注册组件实例
49
56
  * @param field
50
57
  */ (0, _define_property._)(this, "registerField", function(field) {
51
- _this.fieldEntities.push(field);
52
- return function() {
53
- _this.fieldEntities = _this.fieldEntities.filter(function(item) {
54
- return item !== field;
55
- });
56
- if (_this.store) {
57
- delete _this.store[field.props.name];
58
- }
59
- };
60
- });
61
- /**
58
+ _this.fieldEntities.push(field);
59
+ return function() {
60
+ _this.fieldEntities = _this.fieldEntities.filter(function(item) {
61
+ return item !== field;
62
+ });
63
+ };
64
+ });
65
+ /**
62
66
  * 获取 formItem 的值
63
67
  * @param name
64
68
  */ (0, _define_property._)(this, "getFieldValue", function(name) {
65
- var _this_store;
66
- return (_this_store = _this.store) === null || _this_store === void 0 ? void 0 : _this_store[name];
67
- });
68
- /**
69
+ var _this_store;
70
+ return (_this_store = _this.store) === null || _this_store === void 0 ? void 0 : _this_store[name];
71
+ });
72
+ /**
69
73
  * 获取全部字段
70
74
  */ (0, _define_property._)(this, "getFieldsValue", function(nameList) {
71
- if (typeof nameList === 'boolean') {
72
- return JSON.parse(JSON.stringify(_this.store));
73
- }
74
- var fieldsValue = {};
75
- nameList.forEach(function(field) {
76
- fieldsValue[field] = _this.getFieldValue(field);
75
+ if (typeof nameList === 'boolean') {
76
+ return JSON.parse(JSON.stringify(_this.store));
77
+ }
78
+ var fieldsValue = {};
79
+ nameList.forEach(function(field) {
80
+ fieldsValue[field] = _this.getFieldValue(field);
81
+ });
82
+ return fieldsValue;
77
83
  });
78
- return fieldsValue;
79
- });
80
- /**
84
+ /**
81
85
  * 设置 form 的初始值,之后在 reset 的时候使用
82
86
  * @param values
83
87
  * @param init
84
- */ (0, _define_property._)(this, "setInitialValues", function(values, init) {
85
- if (init) {
86
- _this.initialValues = values;
87
- _this.store = values;
88
- }
89
- });
90
- /**
88
+ */ (0, _define_property._)(this, "setInitialValues", function(initialValues, init) {
89
+ _this.initialValues = initialValues || {};
90
+ if (init) {
91
+ var nextStore = (0, _merge.merge)(initialValues, _this.store);
92
+ _this.updateStore(nextStore);
93
+ _this.notifyWatch();
94
+ }
95
+ });
96
+ /**
91
97
  * 存储组件数据
92
98
  * @param newStore { [name]: newValue }
93
99
  */ (0, _define_property._)(this, "setFieldsValue", function(newStore) {
94
- var needValidate = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
95
- _this1.store = (0, _object_spread._)({}, _this1.store, newStore);
96
- _this1.fieldEntities.forEach(function(entity) {
97
- var name = entity.props.name;
98
- Object.keys(newStore).forEach(function(key) {
99
- if (key === name) {
100
- entity.onStoreChange('update');
100
+ var nextStore = (0, _merge.recursive)(true, _this.store, newStore);
101
+ _this.updateStore(nextStore);
102
+ _this.fieldEntities.forEach(function(entity) {
103
+ var name = entity.props.name;
104
+ Object.keys(newStore).forEach(function(key) {
105
+ if (key === name) {
106
+ entity.onStoreChange('update');
107
+ }
108
+ });
109
+ });
110
+ _this.updateList.forEach(function(item) {
111
+ var shouldUpdate = item.condition;
112
+ if (typeof item.condition === 'function') {
113
+ shouldUpdate = item.condition();
114
+ }
115
+ if (shouldUpdate) {
116
+ item.entity.onStoreChange('update');
101
117
  }
102
118
  });
119
+ _this.notifyWatch();
103
120
  });
104
- _this1.updateList.forEach(function(item) {
105
- var shouldUpdate = item.condition;
106
- if (typeof item.condition === 'function') {
107
- shouldUpdate = item.condition();
108
- }
109
- if (shouldUpdate) {
110
- item.entity.onStoreChange('update');
111
- }
121
+ (0, _define_property._)(this, "setFieldValue", function(name, value) {
122
+ var store = (0, _define_property._)({}, name, value);
123
+ _this.setFieldsValue(store);
124
+ _this.notifyWatch([
125
+ name
126
+ ]);
112
127
  });
113
- needValidate && _this1.validateFields();
114
- });
115
- (0, _define_property._)(this, "setCallback", function(callback) {
116
- _this.callbacks = (0, _object_spread._)({}, _this.callbacks, callback);
117
- });
118
- (0, _define_property._)(this, "validateEntities", /*#__PURE__*/ function() {
119
- var _ref = (0, _async_to_generator._)(function(entity, errs) {
120
- var _entity_props, name, _entity_props_rules, rules, descriptor, validator, _this_store, param, errors, _errs;
128
+ (0, _define_property._)(this, "setCallback", function(callback) {
129
+ _this.callbacks = (0, _object_spread._)({}, _this.callbacks, callback);
130
+ });
131
+ (0, _define_property._)(this, "validateEntities", /*#__PURE__*/ function() {
132
+ var _ref = (0, _async_to_generator._)(function(entity, errs) {
133
+ var _entity_props, name, _entity_props_rules, rules, descriptor, validator, _this_store, param, errors, _errs;
134
+ return (0, _ts_generator._)(this, function(_state) {
135
+ switch(_state.label){
136
+ case 0:
137
+ _entity_props = entity.props, name = _entity_props.name, _entity_props_rules = _entity_props.rules, rules = _entity_props_rules === void 0 ? [] : _entity_props_rules;
138
+ if (!name) {
139
+ console.warn('Form field missing name property');
140
+ return [
141
+ 2
142
+ ];
143
+ }
144
+ descriptor = {};
145
+ if (rules.length) {
146
+ // 多条校验规则
147
+ if (rules.length > 1) {
148
+ descriptor[name] = [];
149
+ rules.forEach(function(v) {
150
+ descriptor[name].push(v);
151
+ });
152
+ } else {
153
+ descriptor[name] = rules[0];
154
+ }
155
+ }
156
+ validator = new _asyncvalidator.default(descriptor);
157
+ _state.label = 1;
158
+ case 1:
159
+ _state.trys.push([
160
+ 1,
161
+ 3,
162
+ 4,
163
+ 5
164
+ ]);
165
+ return [
166
+ 4,
167
+ validator.validate((0, _define_property._)({}, name, (_this_store = _this2.store) === null || _this_store === void 0 ? void 0 : _this_store[name]))
168
+ ];
169
+ case 2:
170
+ _state.sent();
171
+ return [
172
+ 3,
173
+ 5
174
+ ];
175
+ case 3:
176
+ param = _state.sent();
177
+ errors = param.errors;
178
+ if (errors) {
179
+ ;
180
+ (_errs = errs).push.apply(_errs, (0, _to_consumable_array._)(errors));
181
+ _this2.errors[name] = errors;
182
+ }
183
+ return [
184
+ 3,
185
+ 5
186
+ ];
187
+ case 4:
188
+ if (!errs || errs.length === 0) {
189
+ _this2.errors[name] = [];
190
+ }
191
+ return [
192
+ 7
193
+ ];
194
+ case 5:
195
+ entity.onStoreChange('validate');
196
+ return [
197
+ 2
198
+ ];
199
+ }
200
+ });
201
+ });
202
+ return function(entity, errs) {
203
+ return _ref.apply(this, arguments);
204
+ };
205
+ }());
206
+ (0, _define_property._)(this, "validateFields", /*#__PURE__*/ function() {
207
+ var _ref = (0, _async_to_generator._)(function(nameList) {
208
+ var filterEntities, errs;
209
+ return (0, _ts_generator._)(this, function(_state) {
210
+ switch(_state.label){
211
+ case 0:
212
+ filterEntities = [];
213
+ // this.errors.length = 0
214
+ if (!nameList || nameList.length === 0) {
215
+ filterEntities = _this2.fieldEntities;
216
+ } else {
217
+ filterEntities = _this2.fieldEntities.filter(function(param) {
218
+ var name = param.props.name;
219
+ return nameList.includes(name);
220
+ });
221
+ }
222
+ errs = [];
223
+ return [
224
+ 4,
225
+ Promise.all(filterEntities.map(/*#__PURE__*/ function() {
226
+ var _ref = (0, _async_to_generator._)(function(entity) {
227
+ return (0, _ts_generator._)(this, function(_state) {
228
+ switch(_state.label){
229
+ case 0:
230
+ return [
231
+ 4,
232
+ _this2.validateEntities(entity, errs)
233
+ ];
234
+ case 1:
235
+ _state.sent();
236
+ return [
237
+ 2
238
+ ];
239
+ }
240
+ });
241
+ });
242
+ return function(entity) {
243
+ return _ref.apply(this, arguments);
244
+ };
245
+ }()))
246
+ ];
247
+ case 1:
248
+ _state.sent();
249
+ return [
250
+ 2,
251
+ errs
252
+ ];
253
+ }
254
+ });
255
+ });
256
+ return function(nameList) {
257
+ return _ref.apply(this, arguments);
258
+ };
259
+ }());
260
+ (0, _define_property._)(this, "submit", /*#__PURE__*/ (0, _async_to_generator._)(function() {
261
+ var errors, _this_callbacks_onFinish, _this_callbacks, _this_callbacks_onFinishFailed, _this_callbacks1;
121
262
  return (0, _ts_generator._)(this, function(_state) {
122
263
  switch(_state.label){
123
264
  case 0:
124
- _entity_props = entity.props, name = _entity_props.name, _entity_props_rules = _entity_props.rules, rules = _entity_props_rules === void 0 ? [] : _entity_props_rules;
125
- descriptor = {};
126
- if (rules.length) {
127
- // 多条校验规则
128
- if (rules.length > 1) {
129
- descriptor[name] = [];
130
- rules.forEach(function(v) {
131
- descriptor[name].push(v);
132
- });
133
- } else {
134
- descriptor[name] = rules[0];
135
- }
136
- }
137
- validator = new _asyncvalidator.default(descriptor);
138
- _state.label = 1;
139
- case 1:
140
- _state.trys.push([
141
- 1,
142
- 3,
143
- 4,
144
- 5
145
- ]);
146
265
  return [
147
266
  4,
148
- validator.validate((0, _define_property._)({}, name, (_this_store = _this2.store) === null || _this_store === void 0 ? void 0 : _this_store[name]))
149
- ];
150
- case 2:
151
- _state.sent();
152
- return [
153
- 3,
154
- 5
267
+ _this2.validateFields()
155
268
  ];
156
- case 3:
157
- param = _state.sent();
158
- errors = param.errors;
159
- if (errors) {
269
+ case 1:
270
+ errors = _state.sent();
271
+ if (errors.length === 0) {
160
272
  ;
161
- (_errs = errs).push.apply(_errs, (0, _to_consumable_array._)(errors));
162
- _this2.errors[name] = errors;
163
- }
164
- return [
165
- 3,
166
- 5
167
- ];
168
- case 4:
169
- if (!errs || errs.length === 0) {
170
- _this2.errors[name] = [];
273
+ (_this_callbacks_onFinish = (_this_callbacks = _this2.callbacks).onFinish) === null || _this_callbacks_onFinish === void 0 ? void 0 : _this_callbacks_onFinish.call(_this_callbacks, _this2.store);
274
+ } else if (errors.length > 0) {
275
+ ;
276
+ (_this_callbacks_onFinishFailed = (_this_callbacks1 = _this2.callbacks).onFinishFailed) === null || _this_callbacks_onFinishFailed === void 0 ? void 0 : _this_callbacks_onFinishFailed.call(_this_callbacks1, _this2.store, errors);
171
277
  }
172
- return [
173
- 7
174
- ];
175
- case 5:
176
- entity.onStoreChange('validate');
177
278
  return [
178
279
  2
179
280
  ];
180
281
  }
181
282
  });
182
- });
183
- return function(entity, errs) {
184
- return _ref.apply(this, arguments);
185
- };
186
- }());
187
- (0, _define_property._)(this, "validateFields", /*#__PURE__*/ function() {
188
- var _ref = (0, _async_to_generator._)(function(nameList) {
189
- var filterEntities, errs;
190
- return (0, _ts_generator._)(this, function(_state) {
191
- switch(_state.label){
192
- case 0:
193
- filterEntities = [];
194
- _this2.errors.length = 0;
195
- if (!nameList || nameList.length === 0) {
196
- filterEntities = _this2.fieldEntities;
197
- } else {
198
- filterEntities = _this2.fieldEntities.filter(function(param) {
199
- var name = param.props.name;
200
- return nameList.includes(name);
201
- });
283
+ }));
284
+ (0, _define_property._)(this, "resetFields", function(namePaths) {
285
+ if (namePaths && namePaths.length) {
286
+ namePaths.forEach(function(path) {
287
+ _this.errors[path] = null;
288
+ _this.fieldEntities.forEach(function(entity) {
289
+ var name = entity.props.name;
290
+ if (name === path) {
291
+ if (path in _this.initialValues) {
292
+ _this.updateStore((0, _define_property._)({}, path, _this.initialValues[path]));
293
+ } else {
294
+ delete _this.store[path];
295
+ }
296
+ entity.onStoreChange('reset');
202
297
  }
203
- errs = [];
204
- return [
205
- 4,
206
- Promise.all(filterEntities.map(/*#__PURE__*/ function() {
207
- var _ref = (0, _async_to_generator._)(function(entity) {
208
- return (0, _ts_generator._)(this, function(_state) {
209
- switch(_state.label){
210
- case 0:
211
- return [
212
- 4,
213
- _this2.validateEntities(entity, errs)
214
- ];
215
- case 1:
216
- _state.sent();
217
- return [
218
- 2
219
- ];
220
- }
221
- });
222
- });
223
- return function(entity) {
224
- return _ref.apply(this, arguments);
225
- };
226
- }()))
227
- ];
228
- case 1:
229
- _state.sent();
230
- return [
231
- 2,
232
- errs
233
- ];
234
- }
298
+ });
299
+ });
300
+ } else {
301
+ var nextStore = (0, _merge.merge)({}, _this.initialValues);
302
+ _this.updateStore(nextStore);
303
+ _this.fieldEntities.forEach(function(entity) {
304
+ entity.onStoreChange('reset');
305
+ });
306
+ }
307
+ });
308
+ // 监听事件
309
+ (0, _define_property._)(this, "registerUpdate", function(field, shouldUpdate) {
310
+ _this.updateList.push({
311
+ entity: field,
312
+ condition: shouldUpdate
235
313
  });
314
+ return function() {
315
+ _this.updateList = _this.updateList.filter(function(i) {
316
+ return i.entity !== field;
317
+ });
318
+ };
236
319
  });
237
- return function(nameList) {
238
- return _ref.apply(this, arguments);
239
- };
240
- }());
241
- (0, _define_property._)(this, "submit", /*#__PURE__*/ (0, _async_to_generator._)(function() {
242
- var errors, _this_callbacks_onFinish, _this_callbacks, _this_callbacks_onFinishFailed, _this_callbacks1;
243
- return (0, _ts_generator._)(this, function(_state) {
244
- switch(_state.label){
245
- case 0:
246
- return [
247
- 4,
248
- _this2.validateFields()
249
- ];
250
- case 1:
251
- errors = _state.sent();
252
- if (errors.length === 0) {
253
- ;
254
- (_this_callbacks_onFinish = (_this_callbacks = _this2.callbacks).onFinish) === null || _this_callbacks_onFinish === void 0 ? void 0 : _this_callbacks_onFinish.call(_this_callbacks, _this2.store);
255
- } else if (errors.length > 0) {
256
- ;
257
- (_this_callbacks_onFinishFailed = (_this_callbacks1 = _this2.callbacks).onFinishFailed) === null || _this_callbacks_onFinishFailed === void 0 ? void 0 : _this_callbacks_onFinishFailed.call(_this_callbacks1, _this2.store, errors);
258
- }
259
- return [
260
- 2
261
- ];
320
+ (0, _define_property._)(this, "dispatch", function(param) {
321
+ var name = param.name;
322
+ _this.validateFields([
323
+ name
324
+ ]);
325
+ });
326
+ (0, _define_property._)(this, "getInternal", function(key) {
327
+ if (key === SECRET) {
328
+ return {
329
+ registerField: _this.registerField,
330
+ setCallback: _this.setCallback,
331
+ setInitialValues: _this.setInitialValues,
332
+ dispatch: _this.dispatch,
333
+ store: _this.store,
334
+ fieldEntities: _this.fieldEntities,
335
+ registerUpdate: _this.registerUpdate,
336
+ registerWatch: _this.registerWatch
337
+ };
262
338
  }
263
339
  });
264
- }));
265
- (0, _define_property._)(this, "resetFields", function() {
266
- _this.errors.length = 0;
267
- _this.store = _this.initialValues;
268
- _this.fieldEntities.forEach(function(entity) {
269
- entity.onStoreChange('reset');
340
+ (0, _define_property._)(this, "getForm", function() {
341
+ return {
342
+ getFieldValue: _this.getFieldValue,
343
+ getFieldsValue: _this.getFieldsValue,
344
+ setFieldsValue: _this.setFieldsValue,
345
+ setFieldValue: _this.setFieldValue,
346
+ resetFields: _this.resetFields,
347
+ validateFields: _this.validateFields,
348
+ submit: _this.submit,
349
+ errors: _this.errors,
350
+ getInternal: _this.getInternal
351
+ };
270
352
  });
271
- });
272
- // 监听事件
273
- (0, _define_property._)(this, "registerUpdate", function(field, shouldUpdate) {
274
- _this.updateList.push({
275
- entity: field,
276
- condition: shouldUpdate
353
+ (0, _define_property._)(this, "watchList", []);
354
+ (0, _define_property._)(this, "registerWatch", function(callback) {
355
+ _this.watchList.push(callback);
356
+ return function() {
357
+ _this.watchList = _this.watchList.filter(function(fn) {
358
+ return fn !== callback;
359
+ });
360
+ };
277
361
  });
278
- return function() {
279
- _this.updateList = _this.updateList.filter(function(i) {
280
- return i.entity !== field;
281
- });
362
+ (0, _define_property._)(this, "notifyWatch", function() {
363
+ var namePath = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
364
+ if (_this1.watchList.length) {
365
+ var allValues;
366
+ if (!namePath || namePath.length === 0) {
367
+ allValues = _this1.getFieldsValue(true);
368
+ } else {
369
+ allValues = _this1.getFieldsValue(namePath);
370
+ }
371
+ _this1.watchList.forEach(function(callback) {
372
+ callback(allValues, namePath);
373
+ });
374
+ }
375
+ });
376
+ this.callbacks = {
377
+ onFinish: function onFinish() {},
378
+ onFinishFailed: function onFinishFailed() {}
282
379
  };
283
- });
284
- (0, _define_property._)(this, "dispatch", function(param) {
285
- var name = param.name;
286
- _this.validateFields([
287
- name
288
- ]);
289
- });
290
- (0, _define_property._)(this, "getInternal", function(key) {
291
- if (key === SECRET) {
292
- return {
293
- registerField: _this.registerField,
294
- setCallback: _this.setCallback,
295
- setInitialValues: _this.setInitialValues,
296
- dispatch: _this.dispatch,
297
- store: _this.store,
298
- fieldEntities: _this.fieldEntities,
299
- registerUpdate: _this.registerUpdate
300
- };
380
+ }
381
+ (0, _create_class._)(FormStore, [
382
+ {
383
+ key: "updateStore",
384
+ value: function updateStore(nextStore) {
385
+ this.store = nextStore;
386
+ }
301
387
  }
302
- });
303
- (0, _define_property._)(this, "getForm", function() {
304
- return {
305
- getFieldValue: _this.getFieldValue,
306
- getFieldsValue: _this.getFieldsValue,
307
- setFieldsValue: _this.setFieldsValue,
308
- resetFields: _this.resetFields,
309
- validateFields: _this.validateFields,
310
- submit: _this.submit,
311
- errors: _this.errors,
312
- getInternal: _this.getInternal
313
- };
314
- });
315
- this.callbacks = {
316
- onFinish: function onFinish() {},
317
- onFinishFailed: function onFinishFailed() {}
318
- };
319
- };
388
+ ]);
389
+ return FormStore;
390
+ }();
320
391
  var useForm = function useForm(form) {
321
392
  var formRef = (0, _react.useRef)();
322
393
  if (!formRef.current) {
@@ -331,3 +402,23 @@ var useForm = function useForm(form) {
331
402
  formRef.current
332
403
  ];
333
404
  };
405
+ var useWatch = function useWatch(path, form) {
406
+ var formInstance = form.getInternal(SECRET);
407
+ var _useState = (0, _sliced_to_array._)((0, _react.useState)(), 2), value = _useState[0], setValue = _useState[1];
408
+ (0, _react.useEffect)(function() {
409
+ var unsubscribe = formInstance.registerWatch(function(data, namePath) {
410
+ var value = data[path];
411
+ setValue(value);
412
+ });
413
+ var initialValue = form.getFieldsValue(true);
414
+ if (value !== initialValue[path]) {
415
+ setValue(initialValue[path]);
416
+ }
417
+ return function() {
418
+ return unsubscribe();
419
+ };
420
+ }, [
421
+ form
422
+ ]);
423
+ return value;
424
+ };
@@ -32,6 +32,7 @@ export declare class FormItem extends React.Component<Partial<FormItemProps>, {
32
32
  getControlled: (children: React.ReactElement) => any;
33
33
  refresh: () => void;
34
34
  onStoreChange: (type?: string) => void;
35
+ getClassNameWithDirection(className: string): string;
35
36
  renderLayout: (childNode: React.ReactNode) => React.JSX.Element;
36
37
  render(): React.JSX.Element;
37
38
  }