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