@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
@@ -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
  }