@nutui/nutui-react-taro 3.0.1 → 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 (82) hide show
  1. package/dist/cjs/hooks/use-client-rect.js +1 -0
  2. package/dist/cjs/packages/datepicker/style/style.css +70 -0
  3. package/dist/cjs/packages/datepickerview/style/index.js +1 -0
  4. package/dist/cjs/packages/datepickerview/style/style.css +70 -0
  5. package/dist/cjs/packages/fixednav/fixednav.js +20 -14
  6. package/dist/cjs/packages/fixednav/style/fixednav.scss +0 -15
  7. package/dist/cjs/packages/fixednav/style/style.css +0 -14
  8. package/dist/cjs/packages/fixednav/style/style.harmony.css +0 -14
  9. package/dist/cjs/packages/form/form.d.ts +2 -0
  10. package/dist/cjs/packages/form/form.js +11 -2
  11. package/dist/cjs/packages/form/index.d.ts +2 -1
  12. package/dist/cjs/packages/form/index.js +1 -0
  13. package/dist/cjs/packages/form/style/form.scss +0 -66
  14. package/dist/cjs/packages/form/style/style.css +31 -21
  15. package/dist/cjs/packages/form/style/style.harmony.css +1 -67
  16. package/dist/cjs/packages/form/types.d.ts +2 -1
  17. package/dist/cjs/packages/form/useform.d.ts +2 -1
  18. package/dist/cjs/packages/form/useform.js +338 -247
  19. package/dist/cjs/packages/formitem/formitem.d.ts +1 -0
  20. package/dist/cjs/packages/formitem/formitem.js +57 -45
  21. package/dist/cjs/packages/formitem/style/formitem.scss +101 -21
  22. package/dist/cjs/packages/formitem/style/style.css +89 -12
  23. package/dist/cjs/packages/formitem/style/style.harmony.css +89 -12
  24. package/dist/cjs/packages/input/input.js +3 -1
  25. package/dist/cjs/packages/picker/style/index.js +1 -0
  26. package/dist/cjs/packages/picker/style/style.css +70 -0
  27. package/dist/cjs/packages/signature/signature.js +1 -1
  28. package/dist/cjs/packages/swipe/style/style.css +3 -3
  29. package/dist/cjs/packages/swipe/style/style.harmony.css +3 -3
  30. package/dist/cjs/packages/swipe/style/swipe.scss +7 -3
  31. package/dist/cjs/packages/swipe/swipe.js +14 -15
  32. package/dist/cjs/utils/get-rect-by-taro.d.ts +1 -1
  33. package/dist/cjs/utils/get-rect-by-taro.js +4 -1
  34. package/dist/cjs/utils/get-system-info.js +4 -5
  35. package/dist/cjs/utils/merge.d.ts +14 -0
  36. package/dist/cjs/utils/merge.js +98 -0
  37. package/dist/cjs/utils/platform-taro.js +4 -5
  38. package/dist/cjs/utils/to-array.d.ts +1 -0
  39. package/dist/cjs/utils/to-array.js +18 -0
  40. package/dist/es/hooks/use-client-rect.js +1 -0
  41. package/dist/es/packages/datepicker/style/style.css +70 -0
  42. package/dist/es/packages/datepickerview/style/index.js +1 -0
  43. package/dist/es/packages/datepickerview/style/style.css +70 -0
  44. package/dist/es/packages/fixednav/fixednav.js +20 -14
  45. package/dist/es/packages/fixednav/style/fixednav.scss +0 -15
  46. package/dist/es/packages/fixednav/style/style.css +0 -14
  47. package/dist/es/packages/fixednav/style/style.harmony.css +0 -14
  48. package/dist/es/packages/form/form.d.ts +10 -0
  49. package/dist/es/packages/form/form.js +11 -2
  50. package/dist/es/packages/form/index.d.ts +2 -1
  51. package/dist/es/packages/form/index.js +2 -1
  52. package/dist/es/packages/form/style/form.scss +0 -66
  53. package/dist/es/packages/form/style/style.css +31 -21
  54. package/dist/es/packages/form/style/style.harmony.css +1 -67
  55. package/dist/es/packages/form/types.d.ts +2 -1
  56. package/dist/es/packages/form/useform.d.ts +2 -1
  57. package/dist/es/packages/form/useform.js +336 -248
  58. package/dist/es/packages/formitem/formitem.d.ts +1 -0
  59. package/dist/es/packages/formitem/formitem.js +58 -46
  60. package/dist/es/packages/formitem/style/formitem.scss +101 -21
  61. package/dist/es/packages/formitem/style/style.css +89 -12
  62. package/dist/es/packages/formitem/style/style.harmony.css +89 -12
  63. package/dist/es/packages/input/input.js +3 -1
  64. package/dist/es/packages/picker/style/index.js +1 -0
  65. package/dist/es/packages/picker/style/style.css +70 -0
  66. package/dist/es/packages/signature/signature.js +2 -2
  67. package/dist/es/packages/swipe/style/style.css +3 -3
  68. package/dist/es/packages/swipe/style/style.harmony.css +3 -3
  69. package/dist/es/packages/swipe/style/swipe.scss +7 -3
  70. package/dist/es/packages/swipe/swipe.js +14 -15
  71. package/dist/es/utils/get-rect-by-taro.d.ts +1 -1
  72. package/dist/es/utils/get-rect-by-taro.js +4 -1
  73. package/dist/es/utils/get-system-info.js +4 -4
  74. package/dist/es/utils/merge.d.ts +14 -0
  75. package/dist/es/utils/merge.js +68 -0
  76. package/dist/es/utils/platform-taro.js +4 -4
  77. package/dist/es/utils/to-array.d.ts +1 -0
  78. package/dist/es/utils/to-array.js +8 -0
  79. package/dist/nutui.react.umd.js +4301 -4084
  80. package/dist/style.css +1 -1
  81. package/dist/style.scss +34 -34
  82. package/package.json +1 -1
@@ -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
  }