@nutui/nutui-react 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.
- package/CHANGELOG.md +24 -0
- package/dist/cjs/hooks/use-client-rect.js +1 -0
- package/dist/cjs/packages/actionsheet/style/style.css +12 -0
- package/dist/cjs/packages/address/style/style.css +12 -0
- package/dist/cjs/packages/calendar/style/style.css +12 -0
- package/dist/cjs/packages/cascader/style/style.css +12 -0
- package/dist/cjs/packages/configprovider/types.d.ts +1 -1
- package/dist/cjs/packages/datepicker/datepicker.js +8 -6
- package/dist/cjs/packages/datepicker/style/style.css +82 -0
- package/dist/cjs/packages/datepickerview/datepickerview.d.ts +3 -0
- package/dist/cjs/packages/datepickerview/datepickerview.js +118 -0
- package/dist/cjs/packages/datepickerview/index.d.ts +3 -0
- package/dist/cjs/packages/{subsidenavbar → datepickerview}/index.js +2 -2
- package/dist/cjs/packages/datepickerview/style/datepickerview.scss +4 -0
- package/dist/cjs/packages/datepickerview/style/index.js +2 -0
- package/dist/cjs/packages/datepickerview/style/style.css +78 -0
- package/dist/cjs/packages/datepickerview/types.d.ts +15 -0
- package/dist/cjs/packages/datepickerview/types.js +4 -0
- package/dist/cjs/packages/dialog/dialogwrap.js +3 -0
- package/dist/cjs/packages/dialog/style/dialog.scss +0 -1
- package/dist/cjs/packages/dialog/style/style.css +0 -1
- package/dist/cjs/packages/drag/style/drag.scss +1 -0
- package/dist/cjs/packages/drag/style/style.css +1 -0
- package/dist/cjs/packages/fixednav/fixednav.js +20 -14
- package/dist/cjs/packages/fixednav/style/fixednav.scss +0 -15
- package/dist/cjs/packages/fixednav/style/style.css +0 -14
- package/dist/cjs/packages/form/__tests__/merge.spec.d.ts +1 -0
- package/dist/cjs/packages/form/__tests__/merge.spec.js +545 -0
- package/dist/cjs/packages/form/form.d.ts +2 -0
- package/dist/cjs/packages/form/form.js +9 -2
- package/dist/cjs/packages/form/index.d.ts +2 -1
- package/dist/cjs/packages/form/index.js +1 -0
- package/dist/cjs/packages/form/style/form.scss +0 -66
- package/dist/cjs/packages/form/style/style.css +31 -21
- package/dist/cjs/packages/form/types.d.ts +2 -1
- package/dist/cjs/packages/form/useform.d.ts +2 -1
- package/dist/cjs/packages/form/useform.js +342 -278
- package/dist/cjs/packages/formitem/formitem.d.ts +1 -0
- package/dist/cjs/packages/formitem/formitem.js +55 -44
- package/dist/cjs/packages/formitem/style/formitem.scss +101 -21
- package/dist/cjs/packages/formitem/style/style.css +89 -12
- package/dist/cjs/packages/imagepreview/style/style.css +12 -0
- package/dist/cjs/packages/input/style/input.scss +6 -4
- package/dist/cjs/packages/input/style/style.css +4 -0
- package/dist/cjs/packages/numberkeyboard/style/style.css +12 -0
- package/dist/cjs/packages/nutui.react.build.d.ts +11 -15
- package/dist/cjs/packages/nutui.react.build.js +8 -16
- package/dist/cjs/packages/nutui.react.d.ts +16 -22
- package/dist/cjs/packages/nutui.react.js +13 -23
- package/dist/cjs/packages/nutui.react.scss.d.ts +5 -7
- package/dist/cjs/packages/nutui.react.scss.js +5 -7
- package/dist/cjs/packages/overlay/style/overlay.scss +0 -4
- package/dist/cjs/packages/picker/style/index.js +1 -0
- package/dist/cjs/packages/picker/style/style.css +82 -0
- package/dist/cjs/packages/popover/style/style.css +12 -0
- package/dist/cjs/packages/popup/style/popup.scss +12 -4
- package/dist/cjs/packages/popup/style/style.css +12 -0
- package/dist/cjs/packages/shortpassword/shortpassword.js +5 -7
- package/dist/cjs/packages/shortpassword/style/shortpassword.scss +10 -0
- package/dist/cjs/packages/shortpassword/style/style.css +21 -0
- package/dist/cjs/packages/swipe/style/style.css +3 -3
- package/dist/cjs/packages/swipe/style/swipe.scss +7 -3
- package/dist/cjs/packages/tabbar/style/style.css +6 -0
- package/dist/cjs/packages/tabbaritem/style/style.css +6 -0
- package/dist/cjs/packages/tabbaritem/style/tabbaritem.scss +6 -0
- package/dist/cjs/packages/timeselect/style/style.css +12 -0
- package/dist/cjs/packages/tour/style/style.css +12 -0
- package/dist/cjs/utils/get-rect-by-taro.d.ts +1 -1
- package/dist/cjs/utils/get-rect-by-taro.js +4 -1
- package/dist/cjs/utils/get-system-info.js +4 -5
- package/dist/cjs/utils/merge.d.ts +14 -0
- package/dist/cjs/utils/merge.js +98 -0
- package/dist/cjs/utils/platform-taro.js +4 -5
- package/dist/cjs/utils/to-array.d.ts +1 -0
- package/dist/cjs/utils/to-array.js +18 -0
- package/dist/es/hooks/use-client-rect.js +1 -0
- package/dist/es/packages/actionsheet/style/style.css +12 -0
- package/dist/es/packages/address/style/style.css +12 -0
- package/dist/es/packages/calendar/style/style.css +12 -0
- package/dist/es/packages/cascader/style/style.css +12 -0
- package/dist/es/packages/configprovider/types.d.ts +1 -1
- package/dist/es/packages/datepicker/datepicker.js +8 -6
- package/dist/es/packages/datepicker/style/style.css +82 -0
- package/dist/es/packages/datepickerview/datepickerview.d.ts +3 -0
- package/dist/es/packages/datepickerview/datepickerview.js +106 -0
- package/dist/es/packages/datepickerview/index.d.ts +3 -0
- package/dist/es/packages/datepickerview/index.js +2 -0
- package/dist/es/packages/datepickerview/style/datepickerview.scss +4 -0
- package/dist/es/packages/datepickerview/style/index.js +2 -0
- package/dist/es/packages/datepickerview/style/style.css +78 -0
- package/dist/es/packages/datepickerview/types.d.ts +15 -0
- package/dist/es/packages/datepickerview/types.js +1 -0
- package/dist/es/packages/dialog/dialogwrap.js +3 -0
- package/dist/es/packages/dialog/style/dialog.scss +0 -1
- package/dist/es/packages/dialog/style/style.css +0 -1
- package/dist/es/packages/drag/style/drag.scss +1 -0
- package/dist/es/packages/drag/style/style.css +1 -0
- package/dist/es/packages/fixednav/fixednav.js +20 -14
- package/dist/es/packages/fixednav/style/fixednav.scss +0 -15
- package/dist/es/packages/fixednav/style/style.css +0 -14
- package/dist/es/packages/form/__tests__/merge.spec.d.ts +1 -0
- package/dist/es/packages/form/__tests__/merge.spec.js +541 -0
- package/dist/es/packages/form/form.d.ts +10 -0
- package/dist/es/packages/form/form.js +9 -2
- package/dist/es/packages/form/index.d.ts +2 -1
- package/dist/es/packages/form/index.js +2 -1
- package/dist/es/packages/form/style/form.scss +0 -66
- package/dist/es/packages/form/style/style.css +31 -21
- package/dist/es/packages/form/types.d.ts +2 -1
- package/dist/es/packages/form/useform.d.ts +2 -1
- package/dist/es/packages/form/useform.js +340 -279
- package/dist/es/packages/formitem/formitem.d.ts +1 -0
- package/dist/es/packages/formitem/formitem.js +55 -44
- package/dist/es/packages/formitem/style/formitem.scss +101 -21
- package/dist/es/packages/formitem/style/style.css +89 -12
- package/dist/es/packages/imagepreview/style/style.css +12 -0
- package/dist/es/packages/input/style/input.scss +6 -4
- package/dist/es/packages/input/style/style.css +4 -0
- package/dist/es/packages/numberkeyboard/style/style.css +12 -0
- package/dist/es/packages/nutui.react.build.d.ts +11 -15
- package/dist/es/packages/nutui.react.build.js +11 -15
- package/dist/es/packages/overlay/style/overlay.scss +0 -4
- package/dist/es/packages/picker/style/index.js +1 -0
- package/dist/es/packages/picker/style/style.css +82 -0
- package/dist/es/packages/popover/style/style.css +12 -0
- package/dist/es/packages/popup/style/popup.scss +12 -4
- package/dist/es/packages/popup/style/style.css +12 -0
- package/dist/es/packages/shortpassword/shortpassword.js +5 -7
- package/dist/es/packages/shortpassword/style/shortpassword.scss +10 -0
- package/dist/es/packages/shortpassword/style/style.css +21 -0
- package/dist/es/packages/swipe/style/style.css +3 -3
- package/dist/es/packages/swipe/style/swipe.scss +7 -3
- package/dist/es/packages/tabbar/style/style.css +6 -0
- package/dist/es/packages/tabbaritem/style/style.css +6 -0
- package/dist/es/packages/tabbaritem/style/tabbaritem.scss +6 -0
- package/dist/es/packages/timeselect/style/style.css +12 -0
- package/dist/es/packages/tour/style/style.css +12 -0
- package/dist/es/utils/get-rect-by-taro.d.ts +1 -1
- package/dist/es/utils/get-rect-by-taro.js +4 -1
- package/dist/es/utils/get-system-info.js +4 -4
- package/dist/es/utils/merge.d.ts +14 -0
- package/dist/es/utils/merge.js +68 -0
- package/dist/es/utils/platform-taro.js +4 -4
- package/dist/es/utils/to-array.d.ts +1 -0
- package/dist/es/utils/to-array.js +8 -0
- package/dist/nutui.react.umd.js +1483 -1416
- package/dist/style.css +1 -1
- package/dist/style.scss +33 -35
- package/dist/styles/variables-jmapp.scss +0 -50
- package/dist/styles/variables-jrkf.scss +0 -50
- package/dist/styles/variables.scss +0 -49
- package/package.json +1 -1
- package/dist/cjs/packages/sidenavbar/context.d.ts +0 -1
- package/dist/cjs/packages/sidenavbar/context.js +0 -12
- package/dist/cjs/packages/sidenavbar/index.d.ts +0 -3
- package/dist/cjs/packages/sidenavbar/index.js +0 -12
- package/dist/cjs/packages/sidenavbar/sidenavbar.d.ts +0 -14
- package/dist/cjs/packages/sidenavbar/sidenavbar.js +0 -70
- package/dist/cjs/packages/sidenavbar/style/index.js +0 -2
- package/dist/cjs/packages/sidenavbar/style/sidenavbar.scss +0 -89
- package/dist/cjs/packages/sidenavbar/style/style.css +0 -443
- package/dist/cjs/packages/sidenavbar/utils.d.ts +0 -3
- package/dist/cjs/packages/sidenavbar/utils.js +0 -23
- package/dist/cjs/packages/sidenavbaritem/index.d.ts +0 -3
- package/dist/cjs/packages/sidenavbaritem/index.js +0 -12
- package/dist/cjs/packages/sidenavbaritem/sidenavbaritem.d.ts +0 -11
- package/dist/cjs/packages/sidenavbaritem/sidenavbaritem.js +0 -34
- package/dist/cjs/packages/sidenavbaritem/style/index.js +0 -1
- package/dist/cjs/packages/sidenavbaritem/style/sidenavbaritem.scss +0 -13
- package/dist/cjs/packages/sidenavbaritem/style/style.css +0 -14
- package/dist/cjs/packages/subsidenavbar/index.d.ts +0 -3
- package/dist/cjs/packages/subsidenavbar/style/css.js +0 -1
- package/dist/cjs/packages/subsidenavbar/style/index.js +0 -1
- package/dist/cjs/packages/subsidenavbar/style/style.css +0 -20
- package/dist/cjs/packages/subsidenavbar/style/subsidenavbar.scss +0 -26
- package/dist/cjs/packages/subsidenavbar/subsidenavbar.d.ts +0 -13
- package/dist/cjs/packages/subsidenavbar/subsidenavbar.js +0 -88
- package/dist/es/packages/sidenavbar/context.d.ts +0 -1
- package/dist/es/packages/sidenavbar/context.js +0 -2
- package/dist/es/packages/sidenavbar/index.d.ts +0 -3
- package/dist/es/packages/sidenavbar/index.js +0 -2
- package/dist/es/packages/sidenavbar/sidenavbar.d.ts +0 -38
- package/dist/es/packages/sidenavbar/sidenavbar.js +0 -58
- package/dist/es/packages/sidenavbar/style/css.js +0 -1
- package/dist/es/packages/sidenavbar/style/index.js +0 -2
- package/dist/es/packages/sidenavbar/style/sidenavbar.scss +0 -89
- package/dist/es/packages/sidenavbar/style/style.css +0 -443
- package/dist/es/packages/sidenavbar/utils.d.ts +0 -3
- package/dist/es/packages/sidenavbar/utils.js +0 -14
- package/dist/es/packages/sidenavbaritem/index.d.ts +0 -3
- package/dist/es/packages/sidenavbaritem/index.js +0 -2
- package/dist/es/packages/sidenavbaritem/sidenavbaritem.d.ts +0 -11
- package/dist/es/packages/sidenavbaritem/sidenavbaritem.js +0 -23
- package/dist/es/packages/sidenavbaritem/style/css.js +0 -1
- package/dist/es/packages/sidenavbaritem/style/index.js +0 -1
- package/dist/es/packages/sidenavbaritem/style/sidenavbaritem.scss +0 -13
- package/dist/es/packages/sidenavbaritem/style/style.css +0 -14
- package/dist/es/packages/subsidenavbar/index.d.ts +0 -3
- package/dist/es/packages/subsidenavbar/index.js +0 -2
- package/dist/es/packages/subsidenavbar/style/css.js +0 -1
- package/dist/es/packages/subsidenavbar/style/index.js +0 -1
- package/dist/es/packages/subsidenavbar/style/style.css +0 -20
- package/dist/es/packages/subsidenavbar/style/subsidenavbar.scss +0 -26
- package/dist/es/packages/subsidenavbar/subsidenavbar.d.ts +0 -13
- package/dist/es/packages/subsidenavbar/subsidenavbar.js +0 -77
- /package/dist/cjs/packages/{sidenavbar → datepickerview}/style/css.js +0 -0
- /package/dist/{cjs/packages/sidenavbaritem → es/packages/datepickerview}/style/css.js +0 -0
|
@@ -14,336 +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
|
-
var _ts_values = require("@swc/helpers/_/_ts_values");
|
|
27
31
|
var _react = require("react");
|
|
28
32
|
var _asyncvalidator = /*#__PURE__*/ _interop_require_default._(require("async-validator"));
|
|
33
|
+
var _merge = require("../../utils/merge");
|
|
29
34
|
var SECRET = 'NUT_FORM_INTERNAL';
|
|
30
35
|
/**
|
|
31
36
|
* 用于存储表单的数据
|
|
32
|
-
*/ var FormStore = function
|
|
37
|
+
*/ var FormStore = /*#__PURE__*/ function() {
|
|
33
38
|
"use strict";
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
/**
|
|
49
55
|
* 注册组件实例
|
|
50
56
|
* @param field
|
|
51
57
|
*/ (0, _define_property._)(this, "registerField", function(field) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
/**
|
|
58
|
+
_this.fieldEntities.push(field);
|
|
59
|
+
return function() {
|
|
60
|
+
_this.fieldEntities = _this.fieldEntities.filter(function(item) {
|
|
61
|
+
return item !== field;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
63
66
|
* 获取 formItem 的值
|
|
64
67
|
* @param name
|
|
65
68
|
*/ (0, _define_property._)(this, "getFieldValue", function(name) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
var _this_store;
|
|
70
|
+
return (_this_store = _this.store) === null || _this_store === void 0 ? void 0 : _this_store[name];
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
70
73
|
* 获取全部字段
|
|
71
74
|
*/ (0, _define_property._)(this, "getFieldsValue", function(nameList) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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;
|
|
78
83
|
});
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
/**
|
|
84
|
+
/**
|
|
82
85
|
* 设置 form 的初始值,之后在 reset 的时候使用
|
|
83
86
|
* @param values
|
|
84
87
|
* @param init
|
|
85
|
-
*/ (0, _define_property._)(this, "setInitialValues", function(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
/**
|
|
92
97
|
* 存储组件数据
|
|
93
98
|
* @param newStore { [name]: newValue }
|
|
94
99
|
*/ (0, _define_property._)(this, "setFieldsValue", function(newStore) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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');
|
|
102
117
|
}
|
|
103
118
|
});
|
|
119
|
+
_this.notifyWatch();
|
|
104
120
|
});
|
|
105
|
-
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
item.entity.onStoreChange('update');
|
|
112
|
-
}
|
|
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
|
+
]);
|
|
113
127
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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;
|
|
122
262
|
return (0, _ts_generator._)(this, function(_state) {
|
|
123
263
|
switch(_state.label){
|
|
124
264
|
case 0:
|
|
125
|
-
filterEntitys = [];
|
|
126
|
-
errs = [];
|
|
127
|
-
_this2.errors.length = 0;
|
|
128
|
-
if (!nameList || nameList.length === 0) {
|
|
129
|
-
filterEntitys = _this2.fieldEntities;
|
|
130
|
-
} else {
|
|
131
|
-
filterEntitys = _this2.fieldEntities.filter(function(param) {
|
|
132
|
-
var name = param.props.name;
|
|
133
|
-
return nameList.includes(name);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
137
|
-
_state.label = 1;
|
|
138
|
-
case 1:
|
|
139
|
-
_state.trys.push([
|
|
140
|
-
1,
|
|
141
|
-
6,
|
|
142
|
-
7,
|
|
143
|
-
8
|
|
144
|
-
]);
|
|
145
|
-
_loop = function _loop() {
|
|
146
|
-
var entity, _entity_props, name, _entity_props_rules, rules, descriptor, validator, _this_store, param, errors, _errs;
|
|
147
|
-
return (0, _ts_generator._)(this, function(_state) {
|
|
148
|
-
switch(_state.label){
|
|
149
|
-
case 0:
|
|
150
|
-
entity = _step.value;
|
|
151
|
-
_entity_props = entity.props, name = _entity_props.name, _entity_props_rules = _entity_props.rules, rules = _entity_props_rules === void 0 ? [] : _entity_props_rules;
|
|
152
|
-
descriptor = {};
|
|
153
|
-
if (rules.length) {
|
|
154
|
-
// 多条校验规则
|
|
155
|
-
if (rules.length > 1) {
|
|
156
|
-
descriptor[name] = [];
|
|
157
|
-
rules.forEach(function(v) {
|
|
158
|
-
descriptor[name].push(v);
|
|
159
|
-
});
|
|
160
|
-
} else {
|
|
161
|
-
descriptor[name] = rules[0];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
validator = new _asyncvalidator.default(descriptor);
|
|
165
|
-
_state.label = 1;
|
|
166
|
-
case 1:
|
|
167
|
-
_state.trys.push([
|
|
168
|
-
1,
|
|
169
|
-
3,
|
|
170
|
-
4,
|
|
171
|
-
5
|
|
172
|
-
]);
|
|
173
|
-
return [
|
|
174
|
-
4,
|
|
175
|
-
validator.validate((0, _define_property._)({}, name, (_this_store = _this2.store) === null || _this_store === void 0 ? void 0 : _this_store[name]))
|
|
176
|
-
];
|
|
177
|
-
case 2:
|
|
178
|
-
_state.sent();
|
|
179
|
-
return [
|
|
180
|
-
3,
|
|
181
|
-
5
|
|
182
|
-
];
|
|
183
|
-
case 3:
|
|
184
|
-
param = _state.sent();
|
|
185
|
-
errors = param.errors;
|
|
186
|
-
if (errors) {
|
|
187
|
-
;
|
|
188
|
-
(_errs = errs).push.apply(_errs, (0, _to_consumable_array._)(errors));
|
|
189
|
-
_this2.errors[name] = errors;
|
|
190
|
-
}
|
|
191
|
-
return [
|
|
192
|
-
3,
|
|
193
|
-
5
|
|
194
|
-
];
|
|
195
|
-
case 4:
|
|
196
|
-
if (!errs || errs.length === 0) {
|
|
197
|
-
_this2.errors[name] = [];
|
|
198
|
-
}
|
|
199
|
-
return [
|
|
200
|
-
7
|
|
201
|
-
];
|
|
202
|
-
case 5:
|
|
203
|
-
entity.onStoreChange('validate');
|
|
204
|
-
return [
|
|
205
|
-
2
|
|
206
|
-
];
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
};
|
|
210
|
-
_iterator = filterEntitys[Symbol.iterator]();
|
|
211
|
-
_state.label = 2;
|
|
212
|
-
case 2:
|
|
213
|
-
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
214
|
-
3,
|
|
215
|
-
5
|
|
216
|
-
];
|
|
217
265
|
return [
|
|
218
|
-
|
|
219
|
-
|
|
266
|
+
4,
|
|
267
|
+
_this2.validateFields()
|
|
220
268
|
];
|
|
221
|
-
case
|
|
222
|
-
_state.sent();
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
269
|
+
case 1:
|
|
270
|
+
errors = _state.sent();
|
|
271
|
+
if (errors.length === 0) {
|
|
272
|
+
;
|
|
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);
|
|
277
|
+
}
|
|
226
278
|
return [
|
|
227
|
-
3,
|
|
228
279
|
2
|
|
229
280
|
];
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
try {
|
|
245
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
246
|
-
_iterator.return();
|
|
247
|
-
}
|
|
248
|
-
} finally{
|
|
249
|
-
if (_didIteratorError) {
|
|
250
|
-
throw _iteratorError;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
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];
|
|
251
295
|
}
|
|
296
|
+
entity.onStoreChange('reset');
|
|
252
297
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
|
262
313
|
});
|
|
314
|
+
return function() {
|
|
315
|
+
_this.updateList = _this.updateList.filter(function(i) {
|
|
316
|
+
return i.entity !== field;
|
|
317
|
+
});
|
|
318
|
+
};
|
|
263
319
|
});
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
} else if (errors.length > 0) {
|
|
283
|
-
;
|
|
284
|
-
(_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);
|
|
285
|
-
}
|
|
286
|
-
return [
|
|
287
|
-
2
|
|
288
|
-
];
|
|
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
|
+
};
|
|
289
338
|
}
|
|
290
339
|
});
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
+
};
|
|
352
|
+
});
|
|
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
|
+
};
|
|
297
361
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
+
}
|
|
304
375
|
});
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
});
|
|
376
|
+
this.callbacks = {
|
|
377
|
+
onFinish: function onFinish() {},
|
|
378
|
+
onFinishFailed: function onFinishFailed() {}
|
|
309
379
|
};
|
|
310
|
-
}
|
|
311
|
-
(0,
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
(0, _define_property._)(this, "getInternal", function(key) {
|
|
318
|
-
if (key === SECRET) {
|
|
319
|
-
return {
|
|
320
|
-
registerField: _this.registerField,
|
|
321
|
-
setCallback: _this.setCallback,
|
|
322
|
-
setInitialValues: _this.setInitialValues,
|
|
323
|
-
dispatch: _this.dispatch,
|
|
324
|
-
store: _this.store,
|
|
325
|
-
fieldEntities: _this.fieldEntities,
|
|
326
|
-
registerUpdate: _this.registerUpdate
|
|
327
|
-
};
|
|
380
|
+
}
|
|
381
|
+
(0, _create_class._)(FormStore, [
|
|
382
|
+
{
|
|
383
|
+
key: "updateStore",
|
|
384
|
+
value: function updateStore(nextStore) {
|
|
385
|
+
this.store = nextStore;
|
|
386
|
+
}
|
|
328
387
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
getFieldValue: _this.getFieldValue,
|
|
333
|
-
getFieldsValue: _this.getFieldsValue,
|
|
334
|
-
setFieldsValue: _this.setFieldsValue,
|
|
335
|
-
resetFields: _this.resetFields,
|
|
336
|
-
validateFields: _this.validateFields,
|
|
337
|
-
submit: _this.submit,
|
|
338
|
-
errors: _this.errors,
|
|
339
|
-
getInternal: _this.getInternal
|
|
340
|
-
};
|
|
341
|
-
});
|
|
342
|
-
this.callbacks = {
|
|
343
|
-
onFinish: function onFinish() {},
|
|
344
|
-
onFinishFailed: function onFinishFailed() {}
|
|
345
|
-
};
|
|
346
|
-
};
|
|
388
|
+
]);
|
|
389
|
+
return FormStore;
|
|
390
|
+
}();
|
|
347
391
|
var useForm = function useForm(form) {
|
|
348
392
|
var formRef = (0, _react.useRef)();
|
|
349
393
|
if (!formRef.current) {
|
|
@@ -358,3 +402,23 @@ var useForm = function useForm(form) {
|
|
|
358
402
|
formRef.current
|
|
359
403
|
];
|
|
360
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
|
+
};
|