@nutui/nutui-react 2.3.11 → 2.3.12
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 +18 -0
- package/dist/esm/ActionSheet.js +30 -86
- package/dist/esm/Address.js +80 -184
- package/dist/esm/Animate.js +21 -49
- package/dist/esm/AnimatingNumbers.js +47 -136
- package/dist/esm/Audio.js +88 -159
- package/dist/esm/Avatar.js +44 -91
- package/dist/esm/AvatarCropper.js +149 -268
- package/dist/esm/AvatarGroup.js +13 -44
- package/dist/esm/BackTop.js +34 -75
- package/dist/esm/Badge.js +0 -3
- package/dist/esm/Barrage.js +49 -83
- package/dist/esm/Button.js +0 -4
- package/dist/esm/Calendar.js +27 -119
- package/dist/esm/CalendarCard.js +180 -291
- package/dist/esm/CalendarItem.js +253 -314
- package/dist/esm/Card.js +38 -72
- package/dist/esm/Cascader.js +0 -17
- package/dist/esm/Cell.js +27 -62
- package/dist/esm/CellGroup.js +16 -45
- package/dist/esm/Checkbox.js +0 -6
- package/dist/esm/CheckboxGroup.js +49 -88
- package/dist/esm/CircleProgress.js +42 -93
- package/dist/esm/Col.js +17 -48
- package/dist/esm/Collapse.js +18 -49
- package/dist/esm/CollapseItem.js +0 -3
- package/dist/esm/ConfigProvider.js +3 -4
- package/dist/esm/CountDown.js +62 -101
- package/dist/esm/DatePicker.js +87 -127
- package/dist/esm/Dialog.js +117 -203
- package/dist/esm/Divider.js +16 -36
- package/dist/esm/Drag.js +32 -76
- package/dist/esm/Elevator.js +94 -133
- package/dist/esm/Ellipsis.js +71 -92
- package/dist/esm/Empty.js +31 -71
- package/dist/esm/FixedNav.js +32 -81
- package/dist/esm/Form.js +28 -61
- package/dist/esm/FormItem.js +0 -3
- package/dist/esm/Grid.js +27 -52
- package/dist/esm/GridItem.js +0 -4
- package/dist/esm/Image.js +47 -102
- package/dist/esm/ImagePreview.js +82 -135
- package/dist/esm/Indicator.js +0 -2
- package/dist/esm/InfiniteLoading.js +77 -159
- package/dist/esm/Input.js +57 -125
- package/dist/esm/InputNumber.js +66 -96
- package/dist/esm/Layout.js +4 -28
- package/dist/esm/Loading.js +13 -40
- package/dist/esm/Menu.js +51 -114
- package/dist/esm/MenuItem.js +0 -13
- package/dist/esm/NavBar.js +46 -85
- package/dist/esm/NoticeBar.js +153 -226
- package/dist/esm/Notify.js +87 -195
- package/dist/esm/NumberKeyboard.js +84 -150
- package/dist/esm/Overlay.js +0 -8
- package/dist/esm/Pagination.js +58 -97
- package/dist/esm/Picker.js +215 -283
- package/dist/esm/Popover.js +111 -160
- package/dist/esm/Popup.js +0 -12
- package/dist/esm/Price.js +23 -60
- package/dist/esm/Progress.js +47 -77
- package/dist/esm/PullToRefresh.js +94 -202
- package/dist/esm/Radio.js +0 -6
- package/dist/esm/RadioGroup.js +23 -56
- package/dist/esm/Range.js +113 -177
- package/dist/esm/Rate.js +48 -95
- package/dist/esm/Row.js +19 -43
- package/dist/esm/SafeArea.js +0 -2
- package/dist/esm/SearchBar.js +52 -119
- package/dist/esm/ShortPassword.js +58 -106
- package/dist/esm/SideNavBar.js +34 -59
- package/dist/esm/SideNavBarItem.js +7 -36
- package/dist/esm/Signature.js +49 -84
- package/dist/esm/Skeleton.js +31 -68
- package/dist/esm/Space.js +7 -34
- package/dist/esm/Step.js +35 -64
- package/dist/esm/Steps.js +16 -40
- package/dist/esm/Sticky.js +64 -109
- package/dist/esm/SubSideNavBar.js +42 -71
- package/dist/esm/Swipe.js +79 -143
- package/dist/esm/Swiper.js +136 -183
- package/dist/esm/SwiperItem.js +13 -38
- package/dist/esm/Switch.js +20 -53
- package/dist/esm/TabPane.js +6 -30
- package/dist/esm/Tabbar.js +29 -60
- package/dist/esm/TabbarItem.js +0 -4
- package/dist/esm/Table.js +92 -141
- package/dist/esm/Tabs.js +0 -7
- package/dist/esm/Tag.js +30 -74
- package/dist/esm/TextArea.js +37 -82
- package/dist/esm/TimeDetail.js +20 -58
- package/dist/esm/TimeSelect.js +57 -95
- package/dist/esm/Toast.js +110 -219
- package/dist/esm/Tour.js +88 -132
- package/dist/esm/TrendArrow.js +32 -74
- package/dist/esm/Uploader.js +226 -346
- package/dist/esm/UserContext.js +1 -1
- package/dist/esm/Video.js +34 -67
- package/dist/esm/VirtualList.js +127 -160
- package/dist/esm/WaterMark.js +24 -68
- package/dist/esm/badge2.js +23 -53
- package/dist/esm/button2.js +30 -63
- package/dist/esm/can-use-dom.js +1 -1
- package/dist/esm/cascader2.js +308 -538
- package/dist/esm/checkbox2.js +59 -96
- package/dist/esm/collapseitem2.js +48 -86
- package/dist/esm/configprovider2.js +43 -1003
- package/dist/esm/context.js +1 -1
- package/dist/esm/context2.js +1 -1
- package/dist/esm/context3.js +1 -1
- package/dist/esm/context4.js +1 -1
- package/dist/esm/context5.js +8 -8
- package/dist/esm/date.js +88 -66
- package/dist/esm/formitem2.js +236 -1526
- package/dist/esm/get-scroll-parent.js +8 -10
- package/dist/esm/griditem2.js +34 -52
- package/dist/esm/index.js +5 -12
- package/dist/esm/indicator2.js +13 -42
- package/dist/esm/menuitem2.js +81 -124
- package/dist/esm/overlay2.js +39 -78
- package/dist/esm/pad-zero.js +3 -4
- package/dist/esm/popup2.js +79 -124
- package/dist/esm/px-check.js +2 -2
- package/dist/esm/radio2.js +48 -79
- package/dist/esm/raf.js +5 -3
- package/dist/esm/render.js +17 -54
- package/dist/esm/safearea2.js +3 -5
- package/dist/esm/supports-passive.js +3 -3
- package/dist/esm/tabbaritem2.js +42 -58
- package/dist/esm/tabs2.js +82 -120
- package/dist/esm/tslib.es6.js +47 -0
- package/dist/esm/types/src/packages/button/demos/h5/demo1.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/h5/demo2.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/h5/demo3.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/h5/demo4.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/h5/demo5.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/h5/demo6.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/h5/demo7.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/h5/demo8.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/h5/demo9.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/taro/demo1.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/taro/demo10.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/taro/demo2.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/taro/demo3.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/taro/demo4.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/taro/demo5.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/taro/demo6.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/taro/demo7.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/taro/demo8.d.ts +3 -0
- package/dist/esm/types/src/packages/button/demos/taro/demo9.d.ts +3 -0
- package/dist/esm/types/src/packages/configprovider/configprovider.d.ts +1 -0
- package/dist/esm/types/src/packages/configprovider/configprovider.taro.d.ts +1 -0
- package/dist/esm/types/src/packages/configprovider/index.d.ts +2 -2
- package/dist/esm/types/src/packages/configprovider/index.taro.d.ts +2 -2
- package/dist/esm/types/src/packages/inputnumber/inputnumber.taro.d.ts +2 -0
- package/dist/esm/typings.js +1 -1
- package/dist/esm/use-click-away.js +9 -13
- package/dist/esm/use-client-rect.js +4 -4
- package/dist/esm/use-props-value.js +10 -15
- package/dist/esm/use-refs.js +5 -7
- package/dist/esm/use-touch.js +16 -20
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/tr-TR.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.es.js +465 -485
- package/dist/nutui.react.umd.js +462 -482
- package/dist/style.mjs +1 -1
- package/dist/styles/variables-jmapp.scss +4 -0
- package/dist/types/index.d.ts +98 -98
- package/dist/types/packages/actionsheet/actionsheet.d.ts +1 -1
- package/dist/types/packages/actionsheet/actionsheet.taro.d.ts +1 -1
- package/dist/types/packages/address/address.d.ts +1 -1
- package/dist/types/packages/address/address.taro.d.ts +1 -1
- package/dist/types/packages/address/customRender.d.ts +1 -1
- package/dist/types/packages/address/customRender.taro.d.ts +1 -1
- package/dist/types/packages/avatar/avatar.d.ts +1 -1
- package/dist/types/packages/avatar/avatar.taro.d.ts +1 -1
- package/dist/types/packages/button/demos/h5/demo1.d.ts +3 -0
- package/dist/types/packages/button/demos/h5/demo2.d.ts +3 -0
- package/dist/types/packages/button/demos/h5/demo3.d.ts +3 -0
- package/dist/types/packages/button/demos/h5/demo4.d.ts +3 -0
- package/dist/types/packages/button/demos/h5/demo5.d.ts +3 -0
- package/dist/types/packages/button/demos/h5/demo6.d.ts +3 -0
- package/dist/types/packages/button/demos/h5/demo7.d.ts +3 -0
- package/dist/types/packages/button/demos/h5/demo8.d.ts +3 -0
- package/dist/types/packages/button/demos/h5/demo9.d.ts +3 -0
- package/dist/types/packages/button/demos/taro/demo1.d.ts +3 -0
- package/dist/types/packages/button/demos/taro/demo10.d.ts +3 -0
- package/dist/types/packages/button/demos/taro/demo2.d.ts +3 -0
- package/dist/types/packages/button/demos/taro/demo3.d.ts +3 -0
- package/dist/types/packages/button/demos/taro/demo4.d.ts +3 -0
- package/dist/types/packages/button/demos/taro/demo5.d.ts +3 -0
- package/dist/types/packages/button/demos/taro/demo6.d.ts +3 -0
- package/dist/types/packages/button/demos/taro/demo7.d.ts +3 -0
- package/dist/types/packages/button/demos/taro/demo8.d.ts +3 -0
- package/dist/types/packages/button/demos/taro/demo9.d.ts +3 -0
- package/dist/types/packages/calendaritem/calendaritem.d.ts +1 -1
- package/dist/types/packages/calendaritem/calendaritem.taro.d.ts +1 -1
- package/dist/types/packages/cascader/cascader.d.ts +1 -1
- package/dist/types/packages/cascader/cascader.taro.d.ts +1 -1
- package/dist/types/packages/cell/cell.d.ts +1 -1
- package/dist/types/packages/cell/cell.taro.d.ts +1 -1
- package/dist/types/packages/checkbox/checkbox.d.ts +2 -2
- package/dist/types/packages/checkbox/checkbox.taro.d.ts +2 -2
- package/dist/types/packages/checkboxgroup/checkboxgroup.d.ts +2 -2
- package/dist/types/packages/checkboxgroup/checkboxgroup.taro.d.ts +2 -2
- package/dist/types/packages/configprovider/configprovider.d.ts +1 -0
- package/dist/types/packages/configprovider/configprovider.taro.d.ts +1 -0
- package/dist/types/packages/configprovider/index.d.ts +2 -2
- package/dist/types/packages/configprovider/index.taro.d.ts +2 -2
- package/dist/types/packages/datepicker/datepicker.d.ts +1 -1
- package/dist/types/packages/datepicker/datepicker.taro.d.ts +1 -1
- package/dist/types/packages/dialog/dialogwrap.d.ts +1 -1
- package/dist/types/packages/empty/empty.d.ts +16 -4
- package/dist/types/packages/fixednav/fixednav.d.ts +1 -1
- package/dist/types/packages/fixednav/fixednav.taro.d.ts +1 -1
- package/dist/types/packages/form/form.d.ts +1 -1
- package/dist/types/packages/form/form.taro.d.ts +1 -1
- package/dist/types/packages/form/index.d.ts +1 -1
- package/dist/types/packages/form/index.taro.d.ts +1 -1
- package/dist/types/packages/inputnumber/inputnumber.taro.d.ts +2 -0
- package/dist/types/packages/menu/menu.d.ts +1 -1
- package/dist/types/packages/menu/menu.taro.d.ts +1 -1
- package/dist/types/packages/numberkeyboard/numberkeyboard.d.ts +1 -1
- package/dist/types/packages/numberkeyboard/numberkeyboard.taro.d.ts +1 -1
- package/dist/types/packages/nutui.react.d.ts +98 -98
- package/dist/types/packages/nutui.react.taro.d.ts +98 -98
- package/dist/types/packages/nutui.taro.react.build.d.ts +98 -98
- package/dist/types/packages/picker/picker.d.ts +1 -1
- package/dist/types/packages/picker/picker.taro.d.ts +1 -1
- package/dist/types/packages/popover/popover.d.ts +1 -1
- package/dist/types/packages/popover/popover.taro.d.ts +1 -1
- package/dist/types/packages/popup/popup.d.ts +1 -1
- package/dist/types/packages/popup/popup.taro.d.ts +1 -1
- package/dist/types/packages/radio/radio.d.ts +2 -2
- package/dist/types/packages/radio/radio.taro.d.ts +2 -2
- package/dist/types/packages/rate/rate.d.ts +1 -1
- package/dist/types/packages/shortpassword/shortpassword.d.ts +1 -1
- package/dist/types/packages/shortpassword/shortpassword.taro.d.ts +1 -1
- package/dist/types/packages/swiper/index.d.ts +1 -1
- package/dist/types/packages/swiper/index.taro.d.ts +1 -1
- package/dist/types/packages/tabs/tabs.d.ts +1 -1
- package/dist/types/packages/tabs/tabs.taro.d.ts +1 -1
- package/dist/types/packages/timedetail/timedetail.d.ts +1 -1
- package/dist/types/packages/timedetail/timedetail.taro.d.ts +1 -1
- package/dist/types/packages/tour/tour.d.ts +1 -1
- package/dist/types/packages/tour/tour.taro.d.ts +1 -1
- package/package.json +5 -1
package/dist/esm/formitem2.js
CHANGED
|
@@ -1,1426 +1,178 @@
|
|
|
1
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
2
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
3
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
4
|
-
import _getPrototypeOf2 from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
6
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
7
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
8
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
9
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
10
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
11
|
-
function _createSuper(Derived) {
|
|
12
|
-
var hasNativeReflectConstruct = _isNativeReflectConstruct2();
|
|
13
|
-
return function _createSuperInternal() {
|
|
14
|
-
var Super = _getPrototypeOf2(Derived), result;
|
|
15
|
-
if (hasNativeReflectConstruct) {
|
|
16
|
-
var NewTarget = _getPrototypeOf2(this).constructor;
|
|
17
|
-
result = Reflect.construct(Super, arguments, NewTarget);
|
|
18
|
-
} else {
|
|
19
|
-
result = Super.apply(this, arguments);
|
|
20
|
-
}
|
|
21
|
-
return _possibleConstructorReturn(this, result);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function _isNativeReflectConstruct2() {
|
|
25
|
-
if (typeof Reflect === "undefined" || !Reflect.construct)
|
|
26
|
-
return false;
|
|
27
|
-
if (Reflect.construct.sham)
|
|
28
|
-
return false;
|
|
29
|
-
if (typeof Proxy === "function")
|
|
30
|
-
return true;
|
|
31
|
-
try {
|
|
32
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
|
|
33
|
-
}));
|
|
34
|
-
return true;
|
|
35
|
-
} catch (e) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
40
|
-
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
41
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
42
|
-
if (!it) {
|
|
43
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
44
|
-
if (it)
|
|
45
|
-
o = it;
|
|
46
|
-
var i = 0;
|
|
47
|
-
var F = function F2() {
|
|
48
|
-
};
|
|
49
|
-
return { s: F, n: function n() {
|
|
50
|
-
if (i >= o.length)
|
|
51
|
-
return { done: true };
|
|
52
|
-
return { done: false, value: o[i++] };
|
|
53
|
-
}, e: function e(_e) {
|
|
54
|
-
throw _e;
|
|
55
|
-
}, f: F };
|
|
56
|
-
}
|
|
57
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
58
|
-
}
|
|
59
|
-
var normalCompletion = true, didErr = false, err;
|
|
60
|
-
return { s: function s() {
|
|
61
|
-
it = it.call(o);
|
|
62
|
-
}, n: function n() {
|
|
63
|
-
var step = it.next();
|
|
64
|
-
normalCompletion = step.done;
|
|
65
|
-
return step;
|
|
66
|
-
}, e: function e(_e2) {
|
|
67
|
-
didErr = true;
|
|
68
|
-
err = _e2;
|
|
69
|
-
}, f: function f() {
|
|
70
|
-
try {
|
|
71
|
-
if (!normalCompletion && it["return"] != null)
|
|
72
|
-
it["return"]();
|
|
73
|
-
} finally {
|
|
74
|
-
if (didErr)
|
|
75
|
-
throw err;
|
|
76
|
-
}
|
|
77
|
-
} };
|
|
78
|
-
}
|
|
79
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
80
|
-
if (!o)
|
|
81
|
-
return;
|
|
82
|
-
if (typeof o === "string")
|
|
83
|
-
return _arrayLikeToArray(o, minLen);
|
|
84
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
85
|
-
if (n === "Object" && o.constructor)
|
|
86
|
-
n = o.constructor.name;
|
|
87
|
-
if (n === "Map" || n === "Set")
|
|
88
|
-
return Array.from(o);
|
|
89
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
90
|
-
return _arrayLikeToArray(o, minLen);
|
|
91
|
-
}
|
|
92
|
-
function _arrayLikeToArray(arr, len) {
|
|
93
|
-
if (len == null || len > arr.length)
|
|
94
|
-
len = arr.length;
|
|
95
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
96
|
-
arr2[i] = arr[i];
|
|
97
|
-
return arr2;
|
|
98
|
-
}
|
|
99
|
-
function ownKeys(e, r) {
|
|
100
|
-
var t = Object.keys(e);
|
|
101
|
-
if (Object.getOwnPropertySymbols) {
|
|
102
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
103
|
-
r && (o = o.filter(function(r2) {
|
|
104
|
-
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
|
|
105
|
-
})), t.push.apply(t, o);
|
|
106
|
-
}
|
|
107
|
-
return t;
|
|
108
|
-
}
|
|
109
|
-
function _objectSpread(e) {
|
|
110
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
111
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
112
|
-
r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
|
|
113
|
-
_defineProperty(e, r2, t[r2]);
|
|
114
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
|
|
115
|
-
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return e;
|
|
119
|
-
}
|
|
120
1
|
import React__default, { createContext, useRef } from "react";
|
|
121
2
|
import Cell from "./Cell.js";
|
|
122
3
|
import { C as ComponentDefaults } from "./typings.js";
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
4
|
+
import { a as __awaiter } from "./tslib.es6.js";
|
|
5
|
+
import Schema from "async-validator";
|
|
6
|
+
const Context = createContext({});
|
|
7
|
+
const SECRET = "NUT_FORM_INTERNAL";
|
|
8
|
+
class FormStore {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.initialValues = {};
|
|
11
|
+
this.updateList = [];
|
|
12
|
+
this.store = {};
|
|
13
|
+
this.fieldEntities = [];
|
|
14
|
+
this.callbacks = {};
|
|
15
|
+
this.errors = {};
|
|
16
|
+
this.registerField = (field) => {
|
|
17
|
+
this.fieldEntities.push(field);
|
|
18
|
+
return () => {
|
|
19
|
+
this.fieldEntities = this.fieldEntities.filter((item) => item !== field);
|
|
20
|
+
if (this.store) {
|
|
21
|
+
delete this.store[field.props.name];
|
|
131
22
|
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return target;
|
|
135
|
-
};
|
|
136
|
-
return _extends.apply(this, arguments);
|
|
137
|
-
}
|
|
138
|
-
function _inheritsLoose(subClass, superClass) {
|
|
139
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
140
|
-
subClass.prototype.constructor = subClass;
|
|
141
|
-
_setPrototypeOf(subClass, superClass);
|
|
142
|
-
}
|
|
143
|
-
function _getPrototypeOf(o) {
|
|
144
|
-
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf3(o2) {
|
|
145
|
-
return o2.__proto__ || Object.getPrototypeOf(o2);
|
|
146
|
-
};
|
|
147
|
-
return _getPrototypeOf(o);
|
|
148
|
-
}
|
|
149
|
-
function _setPrototypeOf(o, p) {
|
|
150
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf2(o2, p2) {
|
|
151
|
-
o2.__proto__ = p2;
|
|
152
|
-
return o2;
|
|
153
|
-
};
|
|
154
|
-
return _setPrototypeOf(o, p);
|
|
155
|
-
}
|
|
156
|
-
function _isNativeReflectConstruct() {
|
|
157
|
-
if (typeof Reflect === "undefined" || !Reflect.construct)
|
|
158
|
-
return false;
|
|
159
|
-
if (Reflect.construct.sham)
|
|
160
|
-
return false;
|
|
161
|
-
if (typeof Proxy === "function")
|
|
162
|
-
return true;
|
|
163
|
-
try {
|
|
164
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
|
|
165
|
-
}));
|
|
166
|
-
return true;
|
|
167
|
-
} catch (e) {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
function _construct(Parent, args, Class) {
|
|
172
|
-
if (_isNativeReflectConstruct()) {
|
|
173
|
-
_construct = Reflect.construct.bind();
|
|
174
|
-
} else {
|
|
175
|
-
_construct = function _construct2(Parent2, args2, Class2) {
|
|
176
|
-
var a = [null];
|
|
177
|
-
a.push.apply(a, args2);
|
|
178
|
-
var Constructor = Function.bind.apply(Parent2, a);
|
|
179
|
-
var instance = new Constructor();
|
|
180
|
-
if (Class2)
|
|
181
|
-
_setPrototypeOf(instance, Class2.prototype);
|
|
182
|
-
return instance;
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
return _construct.apply(null, arguments);
|
|
186
|
-
}
|
|
187
|
-
function _isNativeFunction(fn) {
|
|
188
|
-
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
189
|
-
}
|
|
190
|
-
function _wrapNativeSuper(Class) {
|
|
191
|
-
var _cache = typeof Map === "function" ? /* @__PURE__ */ new Map() : void 0;
|
|
192
|
-
_wrapNativeSuper = function _wrapNativeSuper2(Class2) {
|
|
193
|
-
if (Class2 === null || !_isNativeFunction(Class2))
|
|
194
|
-
return Class2;
|
|
195
|
-
if (typeof Class2 !== "function") {
|
|
196
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
197
|
-
}
|
|
198
|
-
if (typeof _cache !== "undefined") {
|
|
199
|
-
if (_cache.has(Class2))
|
|
200
|
-
return _cache.get(Class2);
|
|
201
|
-
_cache.set(Class2, Wrapper);
|
|
202
|
-
}
|
|
203
|
-
function Wrapper() {
|
|
204
|
-
return _construct(Class2, arguments, _getPrototypeOf(this).constructor);
|
|
205
|
-
}
|
|
206
|
-
Wrapper.prototype = Object.create(Class2.prototype, {
|
|
207
|
-
constructor: {
|
|
208
|
-
value: Wrapper,
|
|
209
|
-
enumerable: false,
|
|
210
|
-
writable: true,
|
|
211
|
-
configurable: true
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
return _setPrototypeOf(Wrapper, Class2);
|
|
215
|
-
};
|
|
216
|
-
return _wrapNativeSuper(Class);
|
|
217
|
-
}
|
|
218
|
-
var formatRegExp = /%[sdj%]/g;
|
|
219
|
-
var warning = function warning2() {
|
|
220
|
-
};
|
|
221
|
-
if (typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production" && typeof window !== "undefined" && typeof document !== "undefined") {
|
|
222
|
-
warning = function warning3(type4, errors) {
|
|
223
|
-
if (typeof console !== "undefined" && console.warn && typeof ASYNC_VALIDATOR_NO_WARNING === "undefined") {
|
|
224
|
-
if (errors.every(function(e) {
|
|
225
|
-
return typeof e === "string";
|
|
226
|
-
})) {
|
|
227
|
-
console.warn(type4, errors);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
function convertFieldsError(errors) {
|
|
233
|
-
if (!errors || !errors.length)
|
|
234
|
-
return null;
|
|
235
|
-
var fields = {};
|
|
236
|
-
errors.forEach(function(error) {
|
|
237
|
-
var field = error.field;
|
|
238
|
-
fields[field] = fields[field] || [];
|
|
239
|
-
fields[field].push(error);
|
|
240
|
-
});
|
|
241
|
-
return fields;
|
|
242
|
-
}
|
|
243
|
-
function format(template) {
|
|
244
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
245
|
-
args[_key - 1] = arguments[_key];
|
|
246
|
-
}
|
|
247
|
-
var i = 0;
|
|
248
|
-
var len = args.length;
|
|
249
|
-
if (typeof template === "function") {
|
|
250
|
-
return template.apply(null, args);
|
|
251
|
-
}
|
|
252
|
-
if (typeof template === "string") {
|
|
253
|
-
var str = template.replace(formatRegExp, function(x) {
|
|
254
|
-
if (x === "%%") {
|
|
255
|
-
return "%";
|
|
256
|
-
}
|
|
257
|
-
if (i >= len) {
|
|
258
|
-
return x;
|
|
259
|
-
}
|
|
260
|
-
switch (x) {
|
|
261
|
-
case "%s":
|
|
262
|
-
return String(args[i++]);
|
|
263
|
-
case "%d":
|
|
264
|
-
return Number(args[i++]);
|
|
265
|
-
case "%j":
|
|
266
|
-
try {
|
|
267
|
-
return JSON.stringify(args[i++]);
|
|
268
|
-
} catch (_) {
|
|
269
|
-
return "[Circular]";
|
|
270
|
-
}
|
|
271
|
-
break;
|
|
272
|
-
default:
|
|
273
|
-
return x;
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
return str;
|
|
277
|
-
}
|
|
278
|
-
return template;
|
|
279
|
-
}
|
|
280
|
-
function isNativeStringType(type4) {
|
|
281
|
-
return type4 === "string" || type4 === "url" || type4 === "hex" || type4 === "email" || type4 === "date" || type4 === "pattern";
|
|
282
|
-
}
|
|
283
|
-
function isEmptyValue(value, type4) {
|
|
284
|
-
if (value === void 0 || value === null) {
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
if (type4 === "array" && Array.isArray(value) && !value.length) {
|
|
288
|
-
return true;
|
|
289
|
-
}
|
|
290
|
-
if (isNativeStringType(type4) && typeof value === "string" && !value) {
|
|
291
|
-
return true;
|
|
292
|
-
}
|
|
293
|
-
return false;
|
|
294
|
-
}
|
|
295
|
-
function asyncParallelArray(arr, func, callback) {
|
|
296
|
-
var results = [];
|
|
297
|
-
var total = 0;
|
|
298
|
-
var arrLength = arr.length;
|
|
299
|
-
function count(errors) {
|
|
300
|
-
results.push.apply(results, errors || []);
|
|
301
|
-
total++;
|
|
302
|
-
if (total === arrLength) {
|
|
303
|
-
callback(results);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
arr.forEach(function(a) {
|
|
307
|
-
func(a, count);
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
function asyncSerialArray(arr, func, callback) {
|
|
311
|
-
var index = 0;
|
|
312
|
-
var arrLength = arr.length;
|
|
313
|
-
function next(errors) {
|
|
314
|
-
if (errors && errors.length) {
|
|
315
|
-
callback(errors);
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
var original = index;
|
|
319
|
-
index = index + 1;
|
|
320
|
-
if (original < arrLength) {
|
|
321
|
-
func(arr[original], next);
|
|
322
|
-
} else {
|
|
323
|
-
callback([]);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
next([]);
|
|
327
|
-
}
|
|
328
|
-
function flattenObjArr(objArr) {
|
|
329
|
-
var ret = [];
|
|
330
|
-
Object.keys(objArr).forEach(function(k) {
|
|
331
|
-
ret.push.apply(ret, objArr[k] || []);
|
|
332
|
-
});
|
|
333
|
-
return ret;
|
|
334
|
-
}
|
|
335
|
-
var AsyncValidationError = /* @__PURE__ */ function(_Error) {
|
|
336
|
-
_inheritsLoose(AsyncValidationError2, _Error);
|
|
337
|
-
function AsyncValidationError2(errors, fields) {
|
|
338
|
-
var _this;
|
|
339
|
-
_this = _Error.call(this, "Async Validation Error") || this;
|
|
340
|
-
_this.errors = errors;
|
|
341
|
-
_this.fields = fields;
|
|
342
|
-
return _this;
|
|
343
|
-
}
|
|
344
|
-
return AsyncValidationError2;
|
|
345
|
-
}(/* @__PURE__ */ _wrapNativeSuper(Error));
|
|
346
|
-
function asyncMap(objArr, option, func, callback, source) {
|
|
347
|
-
if (option.first) {
|
|
348
|
-
var _pending = new Promise(function(resolve, reject) {
|
|
349
|
-
var next = function next2(errors) {
|
|
350
|
-
callback(errors);
|
|
351
|
-
return errors.length ? reject(new AsyncValidationError(errors, convertFieldsError(errors))) : resolve(source);
|
|
352
23
|
};
|
|
353
|
-
var flattenArr = flattenObjArr(objArr);
|
|
354
|
-
asyncSerialArray(flattenArr, func, next);
|
|
355
|
-
});
|
|
356
|
-
_pending["catch"](function(e) {
|
|
357
|
-
return e;
|
|
358
|
-
});
|
|
359
|
-
return _pending;
|
|
360
|
-
}
|
|
361
|
-
var firstFields = option.firstFields === true ? Object.keys(objArr) : option.firstFields || [];
|
|
362
|
-
var objArrKeys = Object.keys(objArr);
|
|
363
|
-
var objArrLength = objArrKeys.length;
|
|
364
|
-
var total = 0;
|
|
365
|
-
var results = [];
|
|
366
|
-
var pending = new Promise(function(resolve, reject) {
|
|
367
|
-
var next = function next2(errors) {
|
|
368
|
-
results.push.apply(results, errors);
|
|
369
|
-
total++;
|
|
370
|
-
if (total === objArrLength) {
|
|
371
|
-
callback(results);
|
|
372
|
-
return results.length ? reject(new AsyncValidationError(results, convertFieldsError(results))) : resolve(source);
|
|
373
|
-
}
|
|
374
24
|
};
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
objArrKeys.forEach(function(key) {
|
|
380
|
-
var arr = objArr[key];
|
|
381
|
-
if (firstFields.indexOf(key) !== -1) {
|
|
382
|
-
asyncSerialArray(arr, func, next);
|
|
383
|
-
} else {
|
|
384
|
-
asyncParallelArray(arr, func, next);
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
pending["catch"](function(e) {
|
|
389
|
-
return e;
|
|
390
|
-
});
|
|
391
|
-
return pending;
|
|
392
|
-
}
|
|
393
|
-
function isErrorObj(obj) {
|
|
394
|
-
return !!(obj && obj.message !== void 0);
|
|
395
|
-
}
|
|
396
|
-
function getValue(value, path) {
|
|
397
|
-
var v = value;
|
|
398
|
-
for (var i = 0; i < path.length; i++) {
|
|
399
|
-
if (v == void 0) {
|
|
400
|
-
return v;
|
|
401
|
-
}
|
|
402
|
-
v = v[path[i]];
|
|
403
|
-
}
|
|
404
|
-
return v;
|
|
405
|
-
}
|
|
406
|
-
function complementError(rule, source) {
|
|
407
|
-
return function(oe) {
|
|
408
|
-
var fieldValue;
|
|
409
|
-
if (rule.fullFields) {
|
|
410
|
-
fieldValue = getValue(source, rule.fullFields);
|
|
411
|
-
} else {
|
|
412
|
-
fieldValue = source[oe.field || rule.fullField];
|
|
413
|
-
}
|
|
414
|
-
if (isErrorObj(oe)) {
|
|
415
|
-
oe.field = oe.field || rule.fullField;
|
|
416
|
-
oe.fieldValue = fieldValue;
|
|
417
|
-
return oe;
|
|
418
|
-
}
|
|
419
|
-
return {
|
|
420
|
-
message: typeof oe === "function" ? oe() : oe,
|
|
421
|
-
fieldValue,
|
|
422
|
-
field: oe.field || rule.fullField
|
|
25
|
+
this.getFieldValue = (name) => {
|
|
26
|
+
var _a;
|
|
27
|
+
return (_a = this.store) === null || _a === void 0 ? void 0 : _a[name];
|
|
423
28
|
};
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (source) {
|
|
428
|
-
for (var s in source) {
|
|
429
|
-
if (source.hasOwnProperty(s)) {
|
|
430
|
-
var value = source[s];
|
|
431
|
-
if (_typeof(value) === "object" && _typeof(target[s]) === "object") {
|
|
432
|
-
target[s] = _extends({}, target[s], value);
|
|
433
|
-
} else {
|
|
434
|
-
target[s] = value;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
return target;
|
|
440
|
-
}
|
|
441
|
-
var required$1 = function required(rule, value, source, errors, options, type4) {
|
|
442
|
-
if (rule.required && (!source.hasOwnProperty(rule.field) || isEmptyValue(value, type4 || rule.type))) {
|
|
443
|
-
errors.push(format(options.messages.required, rule.fullField));
|
|
444
|
-
}
|
|
445
|
-
};
|
|
446
|
-
var whitespace = function whitespace2(rule, value, source, errors, options) {
|
|
447
|
-
if (/^\s+$/.test(value) || value === "") {
|
|
448
|
-
errors.push(format(options.messages.whitespace, rule.fullField));
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
var urlReg;
|
|
452
|
-
var getUrlRegex = function getUrlRegex2() {
|
|
453
|
-
if (urlReg) {
|
|
454
|
-
return urlReg;
|
|
455
|
-
}
|
|
456
|
-
var word = "[a-fA-F\\d:]";
|
|
457
|
-
var b = function b2(options) {
|
|
458
|
-
return options && options.includeBoundaries ? "(?:(?<=\\s|^)(?=" + word + ")|(?<=" + word + ")(?=\\s|$))" : "";
|
|
459
|
-
};
|
|
460
|
-
var v4 = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}";
|
|
461
|
-
var v6seg = "[a-fA-F\\d]{1,4}";
|
|
462
|
-
var v6 = ("\n(?:\n(?:" + v6seg + ":){7}(?:" + v6seg + "|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8\n(?:" + v6seg + ":){6}(?:" + v4 + "|:" + v6seg + "|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4\n(?:" + v6seg + ":){5}(?::" + v4 + "|(?::" + v6seg + "){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4\n(?:" + v6seg + ":){4}(?:(?::" + v6seg + "){0,1}:" + v4 + "|(?::" + v6seg + "){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4\n(?:" + v6seg + ":){3}(?:(?::" + v6seg + "){0,2}:" + v4 + "|(?::" + v6seg + "){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4\n(?:" + v6seg + ":){2}(?:(?::" + v6seg + "){0,3}:" + v4 + "|(?::" + v6seg + "){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4\n(?:" + v6seg + ":){1}(?:(?::" + v6seg + "){0,4}:" + v4 + "|(?::" + v6seg + "){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4\n(?::(?:(?::" + v6seg + "){0,5}:" + v4 + "|(?::" + v6seg + "){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4\n)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1\n").replace(/\s*\/\/.*$/gm, "").replace(/\n/g, "").trim();
|
|
463
|
-
var v46Exact = new RegExp("(?:^" + v4 + "$)|(?:^" + v6 + "$)");
|
|
464
|
-
var v4exact = new RegExp("^" + v4 + "$");
|
|
465
|
-
var v6exact = new RegExp("^" + v6 + "$");
|
|
466
|
-
var ip = function ip2(options) {
|
|
467
|
-
return options && options.exact ? v46Exact : new RegExp("(?:" + b(options) + v4 + b(options) + ")|(?:" + b(options) + v6 + b(options) + ")", "g");
|
|
468
|
-
};
|
|
469
|
-
ip.v4 = function(options) {
|
|
470
|
-
return options && options.exact ? v4exact : new RegExp("" + b(options) + v4 + b(options), "g");
|
|
471
|
-
};
|
|
472
|
-
ip.v6 = function(options) {
|
|
473
|
-
return options && options.exact ? v6exact : new RegExp("" + b(options) + v6 + b(options), "g");
|
|
474
|
-
};
|
|
475
|
-
var protocol = "(?:(?:[a-z]+:)?//)";
|
|
476
|
-
var auth = "(?:\\S+(?::\\S*)?@)?";
|
|
477
|
-
var ipv4 = ip.v4().source;
|
|
478
|
-
var ipv6 = ip.v6().source;
|
|
479
|
-
var host = "(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)";
|
|
480
|
-
var domain = "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*";
|
|
481
|
-
var tld = "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";
|
|
482
|
-
var port = "(?::\\d{2,5})?";
|
|
483
|
-
var path = '(?:[/?#][^\\s"]*)?';
|
|
484
|
-
var regex = "(?:" + protocol + "|www\\.)" + auth + "(?:localhost|" + ipv4 + "|" + ipv6 + "|" + host + domain + tld + ")" + port + path;
|
|
485
|
-
urlReg = new RegExp("(?:^" + regex + "$)", "i");
|
|
486
|
-
return urlReg;
|
|
487
|
-
};
|
|
488
|
-
var pattern$2 = {
|
|
489
|
-
// http://emailregex.com/
|
|
490
|
-
email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,
|
|
491
|
-
// url: new RegExp(
|
|
492
|
-
// '^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
|
|
493
|
-
// 'i',
|
|
494
|
-
// ),
|
|
495
|
-
hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
|
|
496
|
-
};
|
|
497
|
-
var types = {
|
|
498
|
-
integer: function integer(value) {
|
|
499
|
-
return types.number(value) && parseInt(value, 10) === value;
|
|
500
|
-
},
|
|
501
|
-
"float": function _float(value) {
|
|
502
|
-
return types.number(value) && !types.integer(value);
|
|
503
|
-
},
|
|
504
|
-
array: function array(value) {
|
|
505
|
-
return Array.isArray(value);
|
|
506
|
-
},
|
|
507
|
-
regexp: function regexp(value) {
|
|
508
|
-
if (value instanceof RegExp) {
|
|
509
|
-
return true;
|
|
510
|
-
}
|
|
511
|
-
try {
|
|
512
|
-
return !!new RegExp(value);
|
|
513
|
-
} catch (e) {
|
|
514
|
-
return false;
|
|
515
|
-
}
|
|
516
|
-
},
|
|
517
|
-
date: function date(value) {
|
|
518
|
-
return typeof value.getTime === "function" && typeof value.getMonth === "function" && typeof value.getYear === "function" && !isNaN(value.getTime());
|
|
519
|
-
},
|
|
520
|
-
number: function number(value) {
|
|
521
|
-
if (isNaN(value)) {
|
|
522
|
-
return false;
|
|
523
|
-
}
|
|
524
|
-
return typeof value === "number";
|
|
525
|
-
},
|
|
526
|
-
object: function object(value) {
|
|
527
|
-
return _typeof(value) === "object" && !types.array(value);
|
|
528
|
-
},
|
|
529
|
-
method: function method(value) {
|
|
530
|
-
return typeof value === "function";
|
|
531
|
-
},
|
|
532
|
-
email: function email(value) {
|
|
533
|
-
return typeof value === "string" && value.length <= 320 && !!value.match(pattern$2.email);
|
|
534
|
-
},
|
|
535
|
-
url: function url(value) {
|
|
536
|
-
return typeof value === "string" && value.length <= 2048 && !!value.match(getUrlRegex());
|
|
537
|
-
},
|
|
538
|
-
hex: function hex(value) {
|
|
539
|
-
return typeof value === "string" && !!value.match(pattern$2.hex);
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
var type$1 = function type(rule, value, source, errors, options) {
|
|
543
|
-
if (rule.required && value === void 0) {
|
|
544
|
-
required$1(rule, value, source, errors, options);
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
var custom = ["integer", "float", "array", "regexp", "object", "method", "email", "number", "date", "url", "hex"];
|
|
548
|
-
var ruleType = rule.type;
|
|
549
|
-
if (custom.indexOf(ruleType) > -1) {
|
|
550
|
-
if (!types[ruleType](value)) {
|
|
551
|
-
errors.push(format(options.messages.types[ruleType], rule.fullField, rule.type));
|
|
552
|
-
}
|
|
553
|
-
} else if (ruleType && _typeof(value) !== rule.type) {
|
|
554
|
-
errors.push(format(options.messages.types[ruleType], rule.fullField, rule.type));
|
|
555
|
-
}
|
|
556
|
-
};
|
|
557
|
-
var range = function range2(rule, value, source, errors, options) {
|
|
558
|
-
var len = typeof rule.len === "number";
|
|
559
|
-
var min = typeof rule.min === "number";
|
|
560
|
-
var max = typeof rule.max === "number";
|
|
561
|
-
var spRegexp = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
562
|
-
var val = value;
|
|
563
|
-
var key = null;
|
|
564
|
-
var num = typeof value === "number";
|
|
565
|
-
var str = typeof value === "string";
|
|
566
|
-
var arr = Array.isArray(value);
|
|
567
|
-
if (num) {
|
|
568
|
-
key = "number";
|
|
569
|
-
} else if (str) {
|
|
570
|
-
key = "string";
|
|
571
|
-
} else if (arr) {
|
|
572
|
-
key = "array";
|
|
573
|
-
}
|
|
574
|
-
if (!key) {
|
|
575
|
-
return false;
|
|
576
|
-
}
|
|
577
|
-
if (arr) {
|
|
578
|
-
val = value.length;
|
|
579
|
-
}
|
|
580
|
-
if (str) {
|
|
581
|
-
val = value.replace(spRegexp, "_").length;
|
|
582
|
-
}
|
|
583
|
-
if (len) {
|
|
584
|
-
if (val !== rule.len) {
|
|
585
|
-
errors.push(format(options.messages[key].len, rule.fullField, rule.len));
|
|
586
|
-
}
|
|
587
|
-
} else if (min && !max && val < rule.min) {
|
|
588
|
-
errors.push(format(options.messages[key].min, rule.fullField, rule.min));
|
|
589
|
-
} else if (max && !min && val > rule.max) {
|
|
590
|
-
errors.push(format(options.messages[key].max, rule.fullField, rule.max));
|
|
591
|
-
} else if (min && max && (val < rule.min || val > rule.max)) {
|
|
592
|
-
errors.push(format(options.messages[key].range, rule.fullField, rule.min, rule.max));
|
|
593
|
-
}
|
|
594
|
-
};
|
|
595
|
-
var ENUM$1 = "enum";
|
|
596
|
-
var enumerable$1 = function enumerable(rule, value, source, errors, options) {
|
|
597
|
-
rule[ENUM$1] = Array.isArray(rule[ENUM$1]) ? rule[ENUM$1] : [];
|
|
598
|
-
if (rule[ENUM$1].indexOf(value) === -1) {
|
|
599
|
-
errors.push(format(options.messages[ENUM$1], rule.fullField, rule[ENUM$1].join(", ")));
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
var pattern$1 = function pattern(rule, value, source, errors, options) {
|
|
603
|
-
if (rule.pattern) {
|
|
604
|
-
if (rule.pattern instanceof RegExp) {
|
|
605
|
-
rule.pattern.lastIndex = 0;
|
|
606
|
-
if (!rule.pattern.test(value)) {
|
|
607
|
-
errors.push(format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
|
608
|
-
}
|
|
609
|
-
} else if (typeof rule.pattern === "string") {
|
|
610
|
-
var _pattern = new RegExp(rule.pattern);
|
|
611
|
-
if (!_pattern.test(value)) {
|
|
612
|
-
errors.push(format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
};
|
|
617
|
-
var rules = {
|
|
618
|
-
required: required$1,
|
|
619
|
-
whitespace,
|
|
620
|
-
type: type$1,
|
|
621
|
-
range,
|
|
622
|
-
"enum": enumerable$1,
|
|
623
|
-
pattern: pattern$1
|
|
624
|
-
};
|
|
625
|
-
var string = function string2(rule, value, callback, source, options) {
|
|
626
|
-
var errors = [];
|
|
627
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
628
|
-
if (validate) {
|
|
629
|
-
if (isEmptyValue(value, "string") && !rule.required) {
|
|
630
|
-
return callback();
|
|
631
|
-
}
|
|
632
|
-
rules.required(rule, value, source, errors, options, "string");
|
|
633
|
-
if (!isEmptyValue(value, "string")) {
|
|
634
|
-
rules.type(rule, value, source, errors, options);
|
|
635
|
-
rules.range(rule, value, source, errors, options);
|
|
636
|
-
rules.pattern(rule, value, source, errors, options);
|
|
637
|
-
if (rule.whitespace === true) {
|
|
638
|
-
rules.whitespace(rule, value, source, errors, options);
|
|
29
|
+
this.getFieldsValue = (nameList) => {
|
|
30
|
+
if (typeof nameList === "boolean") {
|
|
31
|
+
return JSON.parse(JSON.stringify(this.store));
|
|
639
32
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
}
|
|
651
|
-
rules.required(rule, value, source, errors, options);
|
|
652
|
-
if (value !== void 0) {
|
|
653
|
-
rules.type(rule, value, source, errors, options);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
callback(errors);
|
|
657
|
-
};
|
|
658
|
-
var number2 = function number3(rule, value, callback, source, options) {
|
|
659
|
-
var errors = [];
|
|
660
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
661
|
-
if (validate) {
|
|
662
|
-
if (value === "") {
|
|
663
|
-
value = void 0;
|
|
664
|
-
}
|
|
665
|
-
if (isEmptyValue(value) && !rule.required) {
|
|
666
|
-
return callback();
|
|
667
|
-
}
|
|
668
|
-
rules.required(rule, value, source, errors, options);
|
|
669
|
-
if (value !== void 0) {
|
|
670
|
-
rules.type(rule, value, source, errors, options);
|
|
671
|
-
rules.range(rule, value, source, errors, options);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
callback(errors);
|
|
675
|
-
};
|
|
676
|
-
var _boolean = function _boolean2(rule, value, callback, source, options) {
|
|
677
|
-
var errors = [];
|
|
678
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
679
|
-
if (validate) {
|
|
680
|
-
if (isEmptyValue(value) && !rule.required) {
|
|
681
|
-
return callback();
|
|
682
|
-
}
|
|
683
|
-
rules.required(rule, value, source, errors, options);
|
|
684
|
-
if (value !== void 0) {
|
|
685
|
-
rules.type(rule, value, source, errors, options);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
callback(errors);
|
|
689
|
-
};
|
|
690
|
-
var regexp2 = function regexp3(rule, value, callback, source, options) {
|
|
691
|
-
var errors = [];
|
|
692
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
693
|
-
if (validate) {
|
|
694
|
-
if (isEmptyValue(value) && !rule.required) {
|
|
695
|
-
return callback();
|
|
696
|
-
}
|
|
697
|
-
rules.required(rule, value, source, errors, options);
|
|
698
|
-
if (!isEmptyValue(value)) {
|
|
699
|
-
rules.type(rule, value, source, errors, options);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
callback(errors);
|
|
703
|
-
};
|
|
704
|
-
var integer2 = function integer3(rule, value, callback, source, options) {
|
|
705
|
-
var errors = [];
|
|
706
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
707
|
-
if (validate) {
|
|
708
|
-
if (isEmptyValue(value) && !rule.required) {
|
|
709
|
-
return callback();
|
|
710
|
-
}
|
|
711
|
-
rules.required(rule, value, source, errors, options);
|
|
712
|
-
if (value !== void 0) {
|
|
713
|
-
rules.type(rule, value, source, errors, options);
|
|
714
|
-
rules.range(rule, value, source, errors, options);
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
callback(errors);
|
|
718
|
-
};
|
|
719
|
-
var floatFn = function floatFn2(rule, value, callback, source, options) {
|
|
720
|
-
var errors = [];
|
|
721
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
722
|
-
if (validate) {
|
|
723
|
-
if (isEmptyValue(value) && !rule.required) {
|
|
724
|
-
return callback();
|
|
725
|
-
}
|
|
726
|
-
rules.required(rule, value, source, errors, options);
|
|
727
|
-
if (value !== void 0) {
|
|
728
|
-
rules.type(rule, value, source, errors, options);
|
|
729
|
-
rules.range(rule, value, source, errors, options);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
callback(errors);
|
|
733
|
-
};
|
|
734
|
-
var array2 = function array3(rule, value, callback, source, options) {
|
|
735
|
-
var errors = [];
|
|
736
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
737
|
-
if (validate) {
|
|
738
|
-
if ((value === void 0 || value === null) && !rule.required) {
|
|
739
|
-
return callback();
|
|
740
|
-
}
|
|
741
|
-
rules.required(rule, value, source, errors, options, "array");
|
|
742
|
-
if (value !== void 0 && value !== null) {
|
|
743
|
-
rules.type(rule, value, source, errors, options);
|
|
744
|
-
rules.range(rule, value, source, errors, options);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
callback(errors);
|
|
748
|
-
};
|
|
749
|
-
var object2 = function object3(rule, value, callback, source, options) {
|
|
750
|
-
var errors = [];
|
|
751
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
752
|
-
if (validate) {
|
|
753
|
-
if (isEmptyValue(value) && !rule.required) {
|
|
754
|
-
return callback();
|
|
755
|
-
}
|
|
756
|
-
rules.required(rule, value, source, errors, options);
|
|
757
|
-
if (value !== void 0) {
|
|
758
|
-
rules.type(rule, value, source, errors, options);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
callback(errors);
|
|
762
|
-
};
|
|
763
|
-
var ENUM = "enum";
|
|
764
|
-
var enumerable2 = function enumerable3(rule, value, callback, source, options) {
|
|
765
|
-
var errors = [];
|
|
766
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
767
|
-
if (validate) {
|
|
768
|
-
if (isEmptyValue(value) && !rule.required) {
|
|
769
|
-
return callback();
|
|
770
|
-
}
|
|
771
|
-
rules.required(rule, value, source, errors, options);
|
|
772
|
-
if (value !== void 0) {
|
|
773
|
-
rules[ENUM](rule, value, source, errors, options);
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
callback(errors);
|
|
777
|
-
};
|
|
778
|
-
var pattern2 = function pattern3(rule, value, callback, source, options) {
|
|
779
|
-
var errors = [];
|
|
780
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
781
|
-
if (validate) {
|
|
782
|
-
if (isEmptyValue(value, "string") && !rule.required) {
|
|
783
|
-
return callback();
|
|
784
|
-
}
|
|
785
|
-
rules.required(rule, value, source, errors, options);
|
|
786
|
-
if (!isEmptyValue(value, "string")) {
|
|
787
|
-
rules.pattern(rule, value, source, errors, options);
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
callback(errors);
|
|
791
|
-
};
|
|
792
|
-
var date2 = function date3(rule, value, callback, source, options) {
|
|
793
|
-
var errors = [];
|
|
794
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
795
|
-
if (validate) {
|
|
796
|
-
if (isEmptyValue(value, "date") && !rule.required) {
|
|
797
|
-
return callback();
|
|
798
|
-
}
|
|
799
|
-
rules.required(rule, value, source, errors, options);
|
|
800
|
-
if (!isEmptyValue(value, "date")) {
|
|
801
|
-
var dateObject;
|
|
802
|
-
if (value instanceof Date) {
|
|
803
|
-
dateObject = value;
|
|
804
|
-
} else {
|
|
805
|
-
dateObject = new Date(value);
|
|
806
|
-
}
|
|
807
|
-
rules.type(rule, dateObject, source, errors, options);
|
|
808
|
-
if (dateObject) {
|
|
809
|
-
rules.range(rule, dateObject.getTime(), source, errors, options);
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
callback(errors);
|
|
814
|
-
};
|
|
815
|
-
var required2 = function required3(rule, value, callback, source, options) {
|
|
816
|
-
var errors = [];
|
|
817
|
-
var type4 = Array.isArray(value) ? "array" : _typeof(value);
|
|
818
|
-
rules.required(rule, value, source, errors, options, type4);
|
|
819
|
-
callback(errors);
|
|
820
|
-
};
|
|
821
|
-
var type2 = function type3(rule, value, callback, source, options) {
|
|
822
|
-
var ruleType = rule.type;
|
|
823
|
-
var errors = [];
|
|
824
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
825
|
-
if (validate) {
|
|
826
|
-
if (isEmptyValue(value, ruleType) && !rule.required) {
|
|
827
|
-
return callback();
|
|
828
|
-
}
|
|
829
|
-
rules.required(rule, value, source, errors, options, ruleType);
|
|
830
|
-
if (!isEmptyValue(value, ruleType)) {
|
|
831
|
-
rules.type(rule, value, source, errors, options);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
callback(errors);
|
|
835
|
-
};
|
|
836
|
-
var any = function any2(rule, value, callback, source, options) {
|
|
837
|
-
var errors = [];
|
|
838
|
-
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
839
|
-
if (validate) {
|
|
840
|
-
if (isEmptyValue(value) && !rule.required) {
|
|
841
|
-
return callback();
|
|
842
|
-
}
|
|
843
|
-
rules.required(rule, value, source, errors, options);
|
|
844
|
-
}
|
|
845
|
-
callback(errors);
|
|
846
|
-
};
|
|
847
|
-
var validators = {
|
|
848
|
-
string,
|
|
849
|
-
method: method2,
|
|
850
|
-
number: number2,
|
|
851
|
-
"boolean": _boolean,
|
|
852
|
-
regexp: regexp2,
|
|
853
|
-
integer: integer2,
|
|
854
|
-
"float": floatFn,
|
|
855
|
-
array: array2,
|
|
856
|
-
object: object2,
|
|
857
|
-
"enum": enumerable2,
|
|
858
|
-
pattern: pattern2,
|
|
859
|
-
date: date2,
|
|
860
|
-
url: type2,
|
|
861
|
-
hex: type2,
|
|
862
|
-
email: type2,
|
|
863
|
-
required: required2,
|
|
864
|
-
any
|
|
865
|
-
};
|
|
866
|
-
function newMessages() {
|
|
867
|
-
return {
|
|
868
|
-
"default": "Validation error on field %s",
|
|
869
|
-
required: "%s is required",
|
|
870
|
-
"enum": "%s must be one of %s",
|
|
871
|
-
whitespace: "%s cannot be empty",
|
|
872
|
-
date: {
|
|
873
|
-
format: "%s date %s is invalid for format %s",
|
|
874
|
-
parse: "%s date could not be parsed, %s is invalid ",
|
|
875
|
-
invalid: "%s date %s is invalid"
|
|
876
|
-
},
|
|
877
|
-
types: {
|
|
878
|
-
string: "%s is not a %s",
|
|
879
|
-
method: "%s is not a %s (function)",
|
|
880
|
-
array: "%s is not an %s",
|
|
881
|
-
object: "%s is not an %s",
|
|
882
|
-
number: "%s is not a %s",
|
|
883
|
-
date: "%s is not a %s",
|
|
884
|
-
"boolean": "%s is not a %s",
|
|
885
|
-
integer: "%s is not an %s",
|
|
886
|
-
"float": "%s is not a %s",
|
|
887
|
-
regexp: "%s is not a valid %s",
|
|
888
|
-
email: "%s is not a valid %s",
|
|
889
|
-
url: "%s is not a valid %s",
|
|
890
|
-
hex: "%s is not a valid %s"
|
|
891
|
-
},
|
|
892
|
-
string: {
|
|
893
|
-
len: "%s must be exactly %s characters",
|
|
894
|
-
min: "%s must be at least %s characters",
|
|
895
|
-
max: "%s cannot be longer than %s characters",
|
|
896
|
-
range: "%s must be between %s and %s characters"
|
|
897
|
-
},
|
|
898
|
-
number: {
|
|
899
|
-
len: "%s must equal %s",
|
|
900
|
-
min: "%s cannot be less than %s",
|
|
901
|
-
max: "%s cannot be greater than %s",
|
|
902
|
-
range: "%s must be between %s and %s"
|
|
903
|
-
},
|
|
904
|
-
array: {
|
|
905
|
-
len: "%s must be exactly %s in length",
|
|
906
|
-
min: "%s cannot be less than %s in length",
|
|
907
|
-
max: "%s cannot be greater than %s in length",
|
|
908
|
-
range: "%s must be between %s and %s in length"
|
|
909
|
-
},
|
|
910
|
-
pattern: {
|
|
911
|
-
mismatch: "%s value %s does not match pattern %s"
|
|
912
|
-
},
|
|
913
|
-
clone: function clone() {
|
|
914
|
-
var cloned = JSON.parse(JSON.stringify(this));
|
|
915
|
-
cloned.clone = this.clone;
|
|
916
|
-
return cloned;
|
|
917
|
-
}
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
var messages = newMessages();
|
|
921
|
-
var Schema = /* @__PURE__ */ function() {
|
|
922
|
-
function Schema2(descriptor) {
|
|
923
|
-
this.rules = null;
|
|
924
|
-
this._messages = messages;
|
|
925
|
-
this.define(descriptor);
|
|
926
|
-
}
|
|
927
|
-
var _proto = Schema2.prototype;
|
|
928
|
-
_proto.define = function define(rules2) {
|
|
929
|
-
var _this = this;
|
|
930
|
-
if (!rules2) {
|
|
931
|
-
throw new Error("Cannot configure a schema with no rules");
|
|
932
|
-
}
|
|
933
|
-
if (_typeof(rules2) !== "object" || Array.isArray(rules2)) {
|
|
934
|
-
throw new Error("Rules must be an object");
|
|
935
|
-
}
|
|
936
|
-
this.rules = {};
|
|
937
|
-
Object.keys(rules2).forEach(function(name) {
|
|
938
|
-
var item = rules2[name];
|
|
939
|
-
_this.rules[name] = Array.isArray(item) ? item : [item];
|
|
940
|
-
});
|
|
941
|
-
};
|
|
942
|
-
_proto.messages = function messages2(_messages) {
|
|
943
|
-
if (_messages) {
|
|
944
|
-
this._messages = deepMerge(newMessages(), _messages);
|
|
945
|
-
}
|
|
946
|
-
return this._messages;
|
|
947
|
-
};
|
|
948
|
-
_proto.validate = function validate(source_, o, oc) {
|
|
949
|
-
var _this2 = this;
|
|
950
|
-
if (o === void 0) {
|
|
951
|
-
o = {};
|
|
952
|
-
}
|
|
953
|
-
if (oc === void 0) {
|
|
954
|
-
oc = function oc2() {
|
|
955
|
-
};
|
|
956
|
-
}
|
|
957
|
-
var source = source_;
|
|
958
|
-
var options = o;
|
|
959
|
-
var callback = oc;
|
|
960
|
-
if (typeof options === "function") {
|
|
961
|
-
callback = options;
|
|
962
|
-
options = {};
|
|
963
|
-
}
|
|
964
|
-
if (!this.rules || Object.keys(this.rules).length === 0) {
|
|
965
|
-
if (callback) {
|
|
966
|
-
callback(null, source);
|
|
967
|
-
}
|
|
968
|
-
return Promise.resolve(source);
|
|
969
|
-
}
|
|
970
|
-
function complete(results) {
|
|
971
|
-
var errors = [];
|
|
972
|
-
var fields = {};
|
|
973
|
-
function add(e) {
|
|
974
|
-
if (Array.isArray(e)) {
|
|
975
|
-
var _errors;
|
|
976
|
-
errors = (_errors = errors).concat.apply(_errors, e);
|
|
977
|
-
} else {
|
|
978
|
-
errors.push(e);
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
for (var i = 0; i < results.length; i++) {
|
|
982
|
-
add(results[i]);
|
|
983
|
-
}
|
|
984
|
-
if (!errors.length) {
|
|
985
|
-
callback(null, source);
|
|
986
|
-
} else {
|
|
987
|
-
fields = convertFieldsError(errors);
|
|
988
|
-
callback(errors, fields);
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
if (options.messages) {
|
|
992
|
-
var messages$1 = this.messages();
|
|
993
|
-
if (messages$1 === messages) {
|
|
994
|
-
messages$1 = newMessages();
|
|
33
|
+
const fieldsValue = {};
|
|
34
|
+
nameList.forEach((field) => {
|
|
35
|
+
fieldsValue[field] = this.getFieldValue(field);
|
|
36
|
+
});
|
|
37
|
+
return fieldsValue;
|
|
38
|
+
};
|
|
39
|
+
this.setInitialValues = (values, init) => {
|
|
40
|
+
if (init) {
|
|
41
|
+
this.initialValues = values;
|
|
42
|
+
this.store = values;
|
|
995
43
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
var arr = _this2.rules[z];
|
|
1005
|
-
var value = source[z];
|
|
1006
|
-
arr.forEach(function(r) {
|
|
1007
|
-
var rule = r;
|
|
1008
|
-
if (typeof rule.transform === "function") {
|
|
1009
|
-
if (source === source_) {
|
|
1010
|
-
source = _extends({}, source);
|
|
44
|
+
};
|
|
45
|
+
this.setFieldsValue = (newStore) => {
|
|
46
|
+
this.store = Object.assign(Object.assign({}, this.store), newStore);
|
|
47
|
+
this.fieldEntities.forEach((entity) => {
|
|
48
|
+
const { name } = entity.props;
|
|
49
|
+
Object.keys(newStore).forEach((key) => {
|
|
50
|
+
if (key === name) {
|
|
51
|
+
entity.onStoreChange("update");
|
|
1011
52
|
}
|
|
1012
|
-
value = source[z] = rule.transform(value);
|
|
1013
|
-
}
|
|
1014
|
-
if (typeof rule === "function") {
|
|
1015
|
-
rule = {
|
|
1016
|
-
validator: rule
|
|
1017
|
-
};
|
|
1018
|
-
} else {
|
|
1019
|
-
rule = _extends({}, rule);
|
|
1020
|
-
}
|
|
1021
|
-
rule.validator = _this2.getValidationMethod(rule);
|
|
1022
|
-
if (!rule.validator) {
|
|
1023
|
-
return;
|
|
1024
|
-
}
|
|
1025
|
-
rule.field = z;
|
|
1026
|
-
rule.fullField = rule.fullField || z;
|
|
1027
|
-
rule.type = _this2.getType(rule);
|
|
1028
|
-
series[z] = series[z] || [];
|
|
1029
|
-
series[z].push({
|
|
1030
|
-
rule,
|
|
1031
|
-
value,
|
|
1032
|
-
source,
|
|
1033
|
-
field: z
|
|
1034
53
|
});
|
|
1035
54
|
});
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
var deep = (rule.type === "object" || rule.type === "array") && (_typeof(rule.fields) === "object" || _typeof(rule.defaultField) === "object");
|
|
1041
|
-
deep = deep && (rule.required || !rule.required && data.value);
|
|
1042
|
-
rule.field = data.field;
|
|
1043
|
-
function addFullField(key, schema) {
|
|
1044
|
-
return _extends({}, schema, {
|
|
1045
|
-
fullField: rule.fullField + "." + key,
|
|
1046
|
-
fullFields: rule.fullFields ? [].concat(rule.fullFields, [key]) : [key]
|
|
1047
|
-
});
|
|
1048
|
-
}
|
|
1049
|
-
function cb(e) {
|
|
1050
|
-
if (e === void 0) {
|
|
1051
|
-
e = [];
|
|
1052
|
-
}
|
|
1053
|
-
var errorList = Array.isArray(e) ? e : [e];
|
|
1054
|
-
if (!options.suppressWarning && errorList.length) {
|
|
1055
|
-
Schema2.warning("async-validator:", errorList);
|
|
55
|
+
this.updateList.forEach((item) => {
|
|
56
|
+
let shouldUpdate = item.condition;
|
|
57
|
+
if (typeof item.condition === "function") {
|
|
58
|
+
shouldUpdate = item.condition();
|
|
1056
59
|
}
|
|
1057
|
-
if (
|
|
1058
|
-
|
|
60
|
+
if (shouldUpdate) {
|
|
61
|
+
item.entity.onStoreChange("update");
|
|
1059
62
|
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
this.setCallback = (callback) => {
|
|
66
|
+
this.callbacks = Object.assign(Object.assign({}, this.callbacks), callback);
|
|
67
|
+
};
|
|
68
|
+
this.validateFields = (nameList) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
var _a;
|
|
70
|
+
let filterEntitys = [];
|
|
71
|
+
const errs = [];
|
|
72
|
+
this.errors.length = 0;
|
|
73
|
+
if (!nameList || nameList.length === 0) {
|
|
74
|
+
filterEntitys = this.fieldEntities;
|
|
75
|
+
} else {
|
|
76
|
+
filterEntitys = this.fieldEntities.filter(({ props: { name } }) => nameList.includes(name));
|
|
77
|
+
}
|
|
78
|
+
for (const entity of filterEntitys) {
|
|
79
|
+
const { name, rules = [] } = entity.props;
|
|
80
|
+
const descriptor = {};
|
|
81
|
+
if (rules.length) {
|
|
82
|
+
if (rules.length > 1) {
|
|
83
|
+
descriptor[name] = [];
|
|
84
|
+
rules.forEach((v) => {
|
|
85
|
+
descriptor[name].push(v);
|
|
1080
86
|
});
|
|
87
|
+
} else {
|
|
88
|
+
descriptor[name] = rules[0];
|
|
1081
89
|
}
|
|
1082
|
-
fieldsSchema = _extends({}, fieldsSchema, data.rule.fields);
|
|
1083
|
-
var paredFieldsSchema = {};
|
|
1084
|
-
Object.keys(fieldsSchema).forEach(function(field) {
|
|
1085
|
-
var fieldSchema = fieldsSchema[field];
|
|
1086
|
-
var fieldSchemaList = Array.isArray(fieldSchema) ? fieldSchema : [fieldSchema];
|
|
1087
|
-
paredFieldsSchema[field] = fieldSchemaList.map(addFullField.bind(null, field));
|
|
1088
|
-
});
|
|
1089
|
-
var schema = new Schema2(paredFieldsSchema);
|
|
1090
|
-
schema.messages(options.messages);
|
|
1091
|
-
if (data.rule.options) {
|
|
1092
|
-
data.rule.options.messages = options.messages;
|
|
1093
|
-
data.rule.options.error = options.error;
|
|
1094
|
-
}
|
|
1095
|
-
schema.validate(data.value, data.rule.options || options, function(errs) {
|
|
1096
|
-
var finalErrors = [];
|
|
1097
|
-
if (filledErrors && filledErrors.length) {
|
|
1098
|
-
finalErrors.push.apply(finalErrors, filledErrors);
|
|
1099
|
-
}
|
|
1100
|
-
if (errs && errs.length) {
|
|
1101
|
-
finalErrors.push.apply(finalErrors, errs);
|
|
1102
|
-
}
|
|
1103
|
-
doIt(finalErrors.length ? finalErrors : null);
|
|
1104
|
-
});
|
|
1105
90
|
}
|
|
1106
|
-
|
|
1107
|
-
var res;
|
|
1108
|
-
if (rule.asyncValidator) {
|
|
1109
|
-
res = rule.asyncValidator(rule, data.value, cb, data.source, options);
|
|
1110
|
-
} else if (rule.validator) {
|
|
91
|
+
const validator = new Schema(descriptor);
|
|
1111
92
|
try {
|
|
1112
|
-
|
|
1113
|
-
} catch (
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
93
|
+
yield validator.validate({ [name]: (_a = this.store) === null || _a === void 0 ? void 0 : _a[name] });
|
|
94
|
+
} catch ({ errors }) {
|
|
95
|
+
if (errors) {
|
|
96
|
+
errs.push(...errors);
|
|
97
|
+
this.errors[name] = errors;
|
|
98
|
+
}
|
|
99
|
+
} finally {
|
|
100
|
+
if (!errs || errs.length === 0) {
|
|
101
|
+
this.errors[name] = [];
|
|
1119
102
|
}
|
|
1120
|
-
cb(error.message);
|
|
1121
|
-
}
|
|
1122
|
-
if (res === true) {
|
|
1123
|
-
cb();
|
|
1124
|
-
} else if (res === false) {
|
|
1125
|
-
cb(typeof rule.message === "function" ? rule.message(rule.fullField || rule.field) : rule.message || (rule.fullField || rule.field) + " fails");
|
|
1126
|
-
} else if (res instanceof Array) {
|
|
1127
|
-
cb(res);
|
|
1128
|
-
} else if (res instanceof Error) {
|
|
1129
|
-
cb(res.message);
|
|
1130
103
|
}
|
|
104
|
+
entity.onStoreChange("validate");
|
|
1131
105
|
}
|
|
1132
|
-
|
|
1133
|
-
res.then(function() {
|
|
1134
|
-
return cb();
|
|
1135
|
-
}, function(e) {
|
|
1136
|
-
return cb(e);
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
}, function(results) {
|
|
1140
|
-
complete(results);
|
|
1141
|
-
}, source);
|
|
1142
|
-
};
|
|
1143
|
-
_proto.getType = function getType(rule) {
|
|
1144
|
-
if (rule.type === void 0 && rule.pattern instanceof RegExp) {
|
|
1145
|
-
rule.type = "pattern";
|
|
1146
|
-
}
|
|
1147
|
-
if (typeof rule.validator !== "function" && rule.type && !validators.hasOwnProperty(rule.type)) {
|
|
1148
|
-
throw new Error(format("Unknown rule type %s", rule.type));
|
|
1149
|
-
}
|
|
1150
|
-
return rule.type || "string";
|
|
1151
|
-
};
|
|
1152
|
-
_proto.getValidationMethod = function getValidationMethod(rule) {
|
|
1153
|
-
if (typeof rule.validator === "function") {
|
|
1154
|
-
return rule.validator;
|
|
1155
|
-
}
|
|
1156
|
-
var keys = Object.keys(rule);
|
|
1157
|
-
var messageIndex = keys.indexOf("message");
|
|
1158
|
-
if (messageIndex !== -1) {
|
|
1159
|
-
keys.splice(messageIndex, 1);
|
|
1160
|
-
}
|
|
1161
|
-
if (keys.length === 1 && keys[0] === "required") {
|
|
1162
|
-
return validators.required;
|
|
1163
|
-
}
|
|
1164
|
-
return validators[this.getType(rule)] || void 0;
|
|
1165
|
-
};
|
|
1166
|
-
return Schema2;
|
|
1167
|
-
}();
|
|
1168
|
-
Schema.register = function register(type4, validator) {
|
|
1169
|
-
if (typeof validator !== "function") {
|
|
1170
|
-
throw new Error("Cannot register a validator by type, validator is not a function");
|
|
1171
|
-
}
|
|
1172
|
-
validators[type4] = validator;
|
|
1173
|
-
};
|
|
1174
|
-
Schema.warning = warning;
|
|
1175
|
-
Schema.messages = messages;
|
|
1176
|
-
Schema.validators = validators;
|
|
1177
|
-
var SECRET = "NUT_FORM_INTERNAL";
|
|
1178
|
-
var FormStore = /* @__PURE__ */ _createClass(function FormStore2() {
|
|
1179
|
-
var _this3 = this;
|
|
1180
|
-
_classCallCheck(this, FormStore2);
|
|
1181
|
-
_defineProperty(this, "initialValues", {});
|
|
1182
|
-
_defineProperty(this, "updateList", []);
|
|
1183
|
-
_defineProperty(this, "store", {});
|
|
1184
|
-
_defineProperty(this, "fieldEntities", []);
|
|
1185
|
-
_defineProperty(this, "callbacks", {});
|
|
1186
|
-
_defineProperty(this, "errors", {});
|
|
1187
|
-
_defineProperty(this, "registerField", function(field) {
|
|
1188
|
-
_this3.fieldEntities.push(field);
|
|
1189
|
-
return function() {
|
|
1190
|
-
_this3.fieldEntities = _this3.fieldEntities.filter(function(item) {
|
|
1191
|
-
return item !== field;
|
|
1192
|
-
});
|
|
1193
|
-
if (_this3.store) {
|
|
1194
|
-
delete _this3.store[field.props.name];
|
|
1195
|
-
}
|
|
1196
|
-
};
|
|
1197
|
-
});
|
|
1198
|
-
_defineProperty(this, "getFieldValue", function(name) {
|
|
1199
|
-
var _this3$store;
|
|
1200
|
-
return (_this3$store = _this3.store) === null || _this3$store === void 0 ? void 0 : _this3$store[name];
|
|
1201
|
-
});
|
|
1202
|
-
_defineProperty(this, "getFieldsValue", function(nameList) {
|
|
1203
|
-
if (typeof nameList === "boolean") {
|
|
1204
|
-
return JSON.parse(JSON.stringify(_this3.store));
|
|
1205
|
-
}
|
|
1206
|
-
var fieldsValue = {};
|
|
1207
|
-
nameList.forEach(function(field) {
|
|
1208
|
-
fieldsValue[field] = _this3.getFieldValue(field);
|
|
106
|
+
return errs;
|
|
1209
107
|
});
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
});
|
|
1218
|
-
_defineProperty(this, "setFieldsValue", function(newStore) {
|
|
1219
|
-
_this3.store = _objectSpread(_objectSpread({}, _this3.store), newStore);
|
|
1220
|
-
_this3.fieldEntities.forEach(function(entity) {
|
|
1221
|
-
var name = entity.props.name;
|
|
1222
|
-
Object.keys(newStore).forEach(function(key) {
|
|
1223
|
-
if (key === name) {
|
|
1224
|
-
entity.onStoreChange("update");
|
|
1225
|
-
}
|
|
1226
|
-
});
|
|
1227
|
-
});
|
|
1228
|
-
_this3.updateList.forEach(function(item) {
|
|
1229
|
-
var shouldUpdate = item.condition;
|
|
1230
|
-
if (typeof item.condition === "function") {
|
|
1231
|
-
shouldUpdate = item.condition();
|
|
1232
|
-
}
|
|
1233
|
-
if (shouldUpdate) {
|
|
1234
|
-
item.entity.onStoreChange("update");
|
|
108
|
+
this.submit = () => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
var _b, _c, _d, _e;
|
|
110
|
+
const errors = yield this.validateFields();
|
|
111
|
+
if (errors.length === 0) {
|
|
112
|
+
(_c = (_b = this.callbacks).onFinish) === null || _c === void 0 ? void 0 : _c.call(_b, this.store);
|
|
113
|
+
} else if (errors.length > 0) {
|
|
114
|
+
(_e = (_d = this.callbacks).onFinishFailed) === null || _e === void 0 ? void 0 : _e.call(_d, this.store, errors);
|
|
1235
115
|
}
|
|
1236
116
|
});
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
var filterEntitys, errs, _iterator, _step, _loop;
|
|
1244
|
-
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
|
1245
|
-
while (1)
|
|
1246
|
-
switch (_context2.prev = _context2.next) {
|
|
1247
|
-
case 0:
|
|
1248
|
-
filterEntitys = [];
|
|
1249
|
-
errs = [];
|
|
1250
|
-
_this3.errors.length = 0;
|
|
1251
|
-
if (!nameList || nameList.length === 0) {
|
|
1252
|
-
filterEntitys = _this3.fieldEntities;
|
|
1253
|
-
} else {
|
|
1254
|
-
filterEntitys = _this3.fieldEntities.filter(function(_ref2) {
|
|
1255
|
-
var name = _ref2.props.name;
|
|
1256
|
-
return nameList.includes(name);
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
_iterator = _createForOfIteratorHelper(filterEntitys);
|
|
1260
|
-
_context2.prev = 5;
|
|
1261
|
-
_loop = /* @__PURE__ */ _regeneratorRuntime.mark(function _loop2() {
|
|
1262
|
-
var entity, _entity$props, name, _entity$props$rules, rules2, descriptor, validator, _this3$store2, errors;
|
|
1263
|
-
return _regeneratorRuntime.wrap(function _loop$(_context) {
|
|
1264
|
-
while (1)
|
|
1265
|
-
switch (_context.prev = _context.next) {
|
|
1266
|
-
case 0:
|
|
1267
|
-
entity = _step.value;
|
|
1268
|
-
_entity$props = entity.props, name = _entity$props.name, _entity$props$rules = _entity$props.rules, rules2 = _entity$props$rules === void 0 ? [] : _entity$props$rules;
|
|
1269
|
-
descriptor = {};
|
|
1270
|
-
if (rules2.length) {
|
|
1271
|
-
if (rules2.length > 1) {
|
|
1272
|
-
descriptor[name] = [];
|
|
1273
|
-
rules2.forEach(function(v) {
|
|
1274
|
-
descriptor[name].push(v);
|
|
1275
|
-
});
|
|
1276
|
-
} else {
|
|
1277
|
-
descriptor[name] = rules2[0];
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
validator = new Schema(descriptor);
|
|
1281
|
-
_context.prev = 5;
|
|
1282
|
-
_context.next = 8;
|
|
1283
|
-
return validator.validate(_defineProperty({}, name, (_this3$store2 = _this3.store) === null || _this3$store2 === void 0 ? void 0 : _this3$store2[name]));
|
|
1284
|
-
case 8:
|
|
1285
|
-
_context.next = 14;
|
|
1286
|
-
break;
|
|
1287
|
-
case 10:
|
|
1288
|
-
_context.prev = 10;
|
|
1289
|
-
_context.t0 = _context["catch"](5);
|
|
1290
|
-
errors = _context.t0.errors;
|
|
1291
|
-
if (errors) {
|
|
1292
|
-
errs.push.apply(errs, _toConsumableArray(errors));
|
|
1293
|
-
_this3.errors[name] = errors;
|
|
1294
|
-
}
|
|
1295
|
-
case 14:
|
|
1296
|
-
_context.prev = 14;
|
|
1297
|
-
if (!errs || errs.length === 0) {
|
|
1298
|
-
_this3.errors[name] = [];
|
|
1299
|
-
}
|
|
1300
|
-
return _context.finish(14);
|
|
1301
|
-
case 17:
|
|
1302
|
-
entity.onStoreChange("validate");
|
|
1303
|
-
case 18:
|
|
1304
|
-
case "end":
|
|
1305
|
-
return _context.stop();
|
|
1306
|
-
}
|
|
1307
|
-
}, _loop2, null, [[5, 10, 14, 17]]);
|
|
1308
|
-
});
|
|
1309
|
-
_iterator.s();
|
|
1310
|
-
case 8:
|
|
1311
|
-
if ((_step = _iterator.n()).done) {
|
|
1312
|
-
_context2.next = 12;
|
|
1313
|
-
break;
|
|
1314
|
-
}
|
|
1315
|
-
return _context2.delegateYield(_loop(), "t0", 10);
|
|
1316
|
-
case 10:
|
|
1317
|
-
_context2.next = 8;
|
|
1318
|
-
break;
|
|
1319
|
-
case 12:
|
|
1320
|
-
_context2.next = 17;
|
|
1321
|
-
break;
|
|
1322
|
-
case 14:
|
|
1323
|
-
_context2.prev = 14;
|
|
1324
|
-
_context2.t1 = _context2["catch"](5);
|
|
1325
|
-
_iterator.e(_context2.t1);
|
|
1326
|
-
case 17:
|
|
1327
|
-
_context2.prev = 17;
|
|
1328
|
-
_iterator.f();
|
|
1329
|
-
return _context2.finish(17);
|
|
1330
|
-
case 20:
|
|
1331
|
-
return _context2.abrupt("return", errs);
|
|
1332
|
-
case 21:
|
|
1333
|
-
case "end":
|
|
1334
|
-
return _context2.stop();
|
|
1335
|
-
}
|
|
1336
|
-
}, _callee, null, [[5, 14, 17, 20]]);
|
|
1337
|
-
}));
|
|
1338
|
-
return function(_x) {
|
|
1339
|
-
return _ref.apply(this, arguments);
|
|
117
|
+
this.resetFields = () => {
|
|
118
|
+
this.errors.length = 0;
|
|
119
|
+
this.store = this.initialValues;
|
|
120
|
+
this.fieldEntities.forEach((entity) => {
|
|
121
|
+
entity.onStoreChange("reset");
|
|
122
|
+
});
|
|
1340
123
|
};
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
while (1)
|
|
1346
|
-
switch (_context3.prev = _context3.next) {
|
|
1347
|
-
case 0:
|
|
1348
|
-
_context3.next = 2;
|
|
1349
|
-
return _this3.validateFields();
|
|
1350
|
-
case 2:
|
|
1351
|
-
errors = _context3.sent;
|
|
1352
|
-
if (errors.length === 0) {
|
|
1353
|
-
(_this3$callbacks$onFi = (_this3$callbacks = _this3.callbacks).onFinish) === null || _this3$callbacks$onFi === void 0 || _this3$callbacks$onFi.call(_this3$callbacks, _this3.store);
|
|
1354
|
-
} else if (errors.length > 0) {
|
|
1355
|
-
(_this3$callbacks$onFi2 = (_this3$callbacks2 = _this3.callbacks).onFinishFailed) === null || _this3$callbacks$onFi2 === void 0 || _this3$callbacks$onFi2.call(_this3$callbacks2, _this3.store, errors);
|
|
1356
|
-
}
|
|
1357
|
-
case 4:
|
|
1358
|
-
case "end":
|
|
1359
|
-
return _context3.stop();
|
|
1360
|
-
}
|
|
1361
|
-
}, _callee2);
|
|
1362
|
-
})));
|
|
1363
|
-
_defineProperty(this, "resetFields", function() {
|
|
1364
|
-
_this3.errors.length = 0;
|
|
1365
|
-
_this3.store = _this3.initialValues;
|
|
1366
|
-
_this3.fieldEntities.forEach(function(entity) {
|
|
1367
|
-
entity.onStoreChange("reset");
|
|
1368
|
-
});
|
|
1369
|
-
});
|
|
1370
|
-
_defineProperty(this, "registerUpdate", function(field, shouldUpdate) {
|
|
1371
|
-
_this3.updateList.push({
|
|
1372
|
-
entity: field,
|
|
1373
|
-
condition: shouldUpdate
|
|
1374
|
-
});
|
|
1375
|
-
return function() {
|
|
1376
|
-
_this3.updateList = _this3.updateList.filter(function(i) {
|
|
1377
|
-
return i.entity !== field;
|
|
124
|
+
this.registerUpdate = (field, shouldUpdate) => {
|
|
125
|
+
this.updateList.push({
|
|
126
|
+
entity: field,
|
|
127
|
+
condition: shouldUpdate
|
|
1378
128
|
});
|
|
129
|
+
return () => {
|
|
130
|
+
this.updateList = this.updateList.filter((i) => i.entity !== field);
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
this.dispatch = ({ name }) => {
|
|
134
|
+
this.validateFields([name]);
|
|
1379
135
|
};
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
136
|
+
this.getInternal = (key) => {
|
|
137
|
+
if (key === SECRET) {
|
|
138
|
+
return {
|
|
139
|
+
registerField: this.registerField,
|
|
140
|
+
setCallback: this.setCallback,
|
|
141
|
+
setInitialValues: this.setInitialValues,
|
|
142
|
+
dispatch: this.dispatch,
|
|
143
|
+
store: this.store,
|
|
144
|
+
fieldEntities: this.fieldEntities,
|
|
145
|
+
registerUpdate: this.registerUpdate
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
this.getForm = () => {
|
|
1387
150
|
return {
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
151
|
+
getFieldValue: this.getFieldValue,
|
|
152
|
+
getFieldsValue: this.getFieldsValue,
|
|
153
|
+
setFieldsValue: this.setFieldsValue,
|
|
154
|
+
resetFields: this.resetFields,
|
|
155
|
+
validateFields: this.validateFields,
|
|
156
|
+
submit: this.submit,
|
|
157
|
+
errors: this.errors,
|
|
158
|
+
getInternal: this.getInternal
|
|
1395
159
|
};
|
|
1396
|
-
}
|
|
1397
|
-
});
|
|
1398
|
-
_defineProperty(this, "getForm", function() {
|
|
1399
|
-
return {
|
|
1400
|
-
getFieldValue: _this3.getFieldValue,
|
|
1401
|
-
getFieldsValue: _this3.getFieldsValue,
|
|
1402
|
-
setFieldsValue: _this3.setFieldsValue,
|
|
1403
|
-
resetFields: _this3.resetFields,
|
|
1404
|
-
validateFields: _this3.validateFields,
|
|
1405
|
-
submit: _this3.submit,
|
|
1406
|
-
errors: _this3.errors,
|
|
1407
|
-
getInternal: _this3.getInternal
|
|
1408
160
|
};
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
|
-
|
|
161
|
+
this.callbacks = {
|
|
162
|
+
onFinish: () => {
|
|
163
|
+
},
|
|
164
|
+
onFinishFailed: () => {
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const useForm = (form) => {
|
|
170
|
+
const formRef = useRef();
|
|
1419
171
|
if (!formRef.current) {
|
|
1420
172
|
if (form) {
|
|
1421
173
|
formRef.current = form;
|
|
1422
174
|
} else {
|
|
1423
|
-
|
|
175
|
+
const formStore = new FormStore();
|
|
1424
176
|
formRef.current = formStore.getForm();
|
|
1425
177
|
}
|
|
1426
178
|
}
|
|
@@ -1431,78 +183,55 @@ function isForwardRefComponent(component) {
|
|
|
1431
183
|
React__default.forwardRef(
|
|
1432
184
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1433
185
|
// @ts-ignore
|
|
1434
|
-
|
|
186
|
+
() => {
|
|
1435
187
|
}
|
|
1436
188
|
).$$typeof === component.type.$$typeof;
|
|
1437
189
|
}
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
shouldUpdate: false,
|
|
1449
|
-
noStyle: false
|
|
1450
|
-
});
|
|
1451
|
-
var FormItem = /* @__PURE__ */ function(_React__default$Compo) {
|
|
1452
|
-
_inherits(FormItem2, _React__default$Compo);
|
|
1453
|
-
var _super = _createSuper(FormItem2);
|
|
1454
|
-
function FormItem2(props) {
|
|
1455
|
-
var _this4;
|
|
1456
|
-
_classCallCheck(this, FormItem2);
|
|
1457
|
-
_this4 = _super.call(this, props);
|
|
1458
|
-
_defineProperty(_assertThisInitialized(_this4), "cancelRegister", void 0);
|
|
1459
|
-
_defineProperty(_assertThisInitialized(_this4), "componentRef", void 0);
|
|
1460
|
-
_defineProperty(_assertThisInitialized(_this4), "eventOff", void 0);
|
|
1461
|
-
_defineProperty(_assertThisInitialized(_this4), "getControlled", function(children) {
|
|
1462
|
-
var _children$props;
|
|
1463
|
-
var _this4$context = _this4.context, setFieldsValue = _this4$context.setFieldsValue, getFieldValue = _this4$context.getFieldValue;
|
|
1464
|
-
var _this4$context$getInt = _this4.context.getInternal(SECRET), dispatch = _this4$context$getInt.dispatch;
|
|
1465
|
-
var _this4$props$name = _this4.props.name, name = _this4$props$name === void 0 ? "" : _this4$props$name;
|
|
1466
|
-
if (children !== null && children !== void 0 && (_children$props = children.props) !== null && _children$props !== void 0 && _children$props.defaultValue) {
|
|
190
|
+
const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { required: false, name: "", label: "", rules: [{ required: false, message: "" }], errorMessageAlign: "left", validateTrigger: "onChange", shouldUpdate: false, noStyle: false });
|
|
191
|
+
class FormItem extends React__default.Component {
|
|
192
|
+
constructor(props) {
|
|
193
|
+
super(props);
|
|
194
|
+
this.getControlled = (children) => {
|
|
195
|
+
var _a;
|
|
196
|
+
const { setFieldsValue, getFieldValue } = this.context;
|
|
197
|
+
const { dispatch } = this.context.getInternal(SECRET);
|
|
198
|
+
const { name = "" } = this.props;
|
|
199
|
+
if ((_a = children === null || children === void 0 ? void 0 : children.props) === null || _a === void 0 ? void 0 : _a.defaultValue) {
|
|
1467
200
|
console.warn("通过 initialValue 设置初始值");
|
|
1468
201
|
}
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1473
|
-
args[_key2] = arguments[_key2];
|
|
1474
|
-
}
|
|
202
|
+
const fieldValue = getFieldValue(name);
|
|
203
|
+
const controlled = Object.assign(Object.assign({}, children.props), { [this.props.valuePropName || "value"]: fieldValue !== void 0 ? fieldValue : this.props.initialValue, [this.props.trigger || "onChange"]: (...args) => {
|
|
204
|
+
const originOnChange = children.props[this.props.trigger || "onChange"];
|
|
1475
205
|
if (originOnChange) {
|
|
1476
|
-
originOnChange
|
|
206
|
+
originOnChange(...args);
|
|
1477
207
|
}
|
|
1478
|
-
|
|
1479
|
-
if (
|
|
1480
|
-
|
|
1481
|
-
next = (_this4$props = _this4.props).getValueFromEvent.apply(_this4$props, args);
|
|
208
|
+
let [next] = args;
|
|
209
|
+
if (this.props.getValueFromEvent) {
|
|
210
|
+
next = this.props.getValueFromEvent(...args);
|
|
1482
211
|
}
|
|
1483
|
-
setFieldsValue(
|
|
1484
|
-
})
|
|
1485
|
-
|
|
1486
|
-
|
|
212
|
+
setFieldsValue({ [name]: next });
|
|
213
|
+
} });
|
|
214
|
+
const { validateTrigger } = this.props;
|
|
215
|
+
let validateTriggers = [this.props.trigger || "onChange"];
|
|
1487
216
|
if (validateTrigger) {
|
|
1488
|
-
validateTriggers = typeof validateTrigger === "string" ? [
|
|
1489
|
-
validateTriggers.forEach(
|
|
1490
|
-
|
|
1491
|
-
controlled[trigger] =
|
|
217
|
+
validateTriggers = typeof validateTrigger === "string" ? [validateTrigger] : [...validateTrigger];
|
|
218
|
+
validateTriggers.forEach((trigger) => {
|
|
219
|
+
const originTrigger = controlled[trigger];
|
|
220
|
+
controlled[trigger] = (...args) => {
|
|
1492
221
|
if (originTrigger) {
|
|
1493
|
-
originTrigger
|
|
222
|
+
originTrigger(...args);
|
|
1494
223
|
}
|
|
1495
|
-
if (
|
|
224
|
+
if (this.props.rules && this.props.rules.length) {
|
|
1496
225
|
dispatch({
|
|
1497
|
-
name:
|
|
226
|
+
name: this.props.name
|
|
1498
227
|
});
|
|
1499
228
|
}
|
|
1500
229
|
};
|
|
1501
230
|
});
|
|
1502
231
|
}
|
|
1503
232
|
if (isForwardRefComponent(children)) {
|
|
1504
|
-
controlled.ref =
|
|
1505
|
-
|
|
233
|
+
controlled.ref = (componentInstance) => {
|
|
234
|
+
const originRef = children.ref;
|
|
1506
235
|
if (originRef) {
|
|
1507
236
|
if (typeof originRef === "function") {
|
|
1508
237
|
originRef(componentInstance);
|
|
@@ -1511,100 +240,81 @@ var FormItem = /* @__PURE__ */ function(_React__default$Compo) {
|
|
|
1511
240
|
originRef.current = componentInstance;
|
|
1512
241
|
}
|
|
1513
242
|
}
|
|
1514
|
-
|
|
243
|
+
this.componentRef = componentInstance;
|
|
1515
244
|
};
|
|
1516
245
|
}
|
|
1517
246
|
return controlled;
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
if (type4 === "reset") {
|
|
1529
|
-
_this4.context.errors[_this4.props.name] = [];
|
|
1530
|
-
_this4.refresh();
|
|
247
|
+
};
|
|
248
|
+
this.refresh = () => {
|
|
249
|
+
this.setState(({ resetCount }) => ({
|
|
250
|
+
resetCount: resetCount + 1
|
|
251
|
+
}));
|
|
252
|
+
};
|
|
253
|
+
this.onStoreChange = (type) => {
|
|
254
|
+
if (type === "reset") {
|
|
255
|
+
this.context.errors[this.props.name] = [];
|
|
256
|
+
this.refresh();
|
|
1531
257
|
} else {
|
|
1532
|
-
|
|
258
|
+
this.forceUpdate();
|
|
1533
259
|
}
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
}
|
|
1563
|
-
}, item[0].message)));
|
|
1564
|
-
});
|
|
1565
|
-
_this4.componentRef = React__default.createRef();
|
|
1566
|
-
_this4.state = {
|
|
260
|
+
};
|
|
261
|
+
this.renderLayout = (childNode) => {
|
|
262
|
+
const { label, name, required, rules, className, style, errorMessageAlign } = Object.assign(Object.assign({}, defaultProps), this.props);
|
|
263
|
+
const requiredInRules = rules === null || rules === void 0 ? void 0 : rules.some((rule) => rule.required);
|
|
264
|
+
const item = name ? this.context.errors[name] : [];
|
|
265
|
+
const { starPosition } = this.context;
|
|
266
|
+
const renderStar = (required || requiredInRules) && React__default.createElement("i", { className: "required" });
|
|
267
|
+
const renderLabel = React__default.createElement(
|
|
268
|
+
React__default.Fragment,
|
|
269
|
+
null,
|
|
270
|
+
starPosition === "left" ? renderStar : null,
|
|
271
|
+
label,
|
|
272
|
+
starPosition === "right" ? renderStar : null
|
|
273
|
+
);
|
|
274
|
+
return React__default.createElement(
|
|
275
|
+
Cell,
|
|
276
|
+
{ className: `nut-form-item ${className}`, style, onClick: (e) => this.props.onClick && this.props.onClick(e, this.componentRef) },
|
|
277
|
+
label ? React__default.createElement("div", { className: "nut-cell-title nut-form-item-label" }, renderLabel) : null,
|
|
278
|
+
React__default.createElement(
|
|
279
|
+
"div",
|
|
280
|
+
{ className: "nut-cell-value nut-form-item-body" },
|
|
281
|
+
React__default.createElement("div", { className: "nut-form-item-body-slots" }, childNode),
|
|
282
|
+
item && item.length > 0 && React__default.createElement("div", { className: "nut-form-item-body-tips", style: { textAlign: errorMessageAlign } }, item[0].message)
|
|
283
|
+
)
|
|
284
|
+
);
|
|
285
|
+
};
|
|
286
|
+
this.componentRef = React__default.createRef();
|
|
287
|
+
this.state = {
|
|
1567
288
|
resetCount: 1
|
|
1568
289
|
};
|
|
1569
|
-
return _this4;
|
|
1570
290
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
291
|
+
componentDidMount() {
|
|
292
|
+
const { registerField, registerUpdate } = this.context.getInternal(SECRET);
|
|
293
|
+
this.cancelRegister = registerField(this);
|
|
294
|
+
this.eventOff = registerUpdate(this, this.props.shouldUpdate);
|
|
295
|
+
}
|
|
296
|
+
componentWillUnmount() {
|
|
297
|
+
if (this.cancelRegister) {
|
|
298
|
+
this.cancelRegister();
|
|
1577
299
|
}
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
value: function componentWillUnmount() {
|
|
1581
|
-
if (this.cancelRegister) {
|
|
1582
|
-
this.cancelRegister();
|
|
1583
|
-
}
|
|
1584
|
-
if (this.eventOff) {
|
|
1585
|
-
this.eventOff();
|
|
1586
|
-
}
|
|
300
|
+
if (this.eventOff) {
|
|
301
|
+
this.eventOff();
|
|
1587
302
|
}
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
returnChildNode = child(this.context);
|
|
1598
|
-
}
|
|
1599
|
-
return React__default.createElement(React__default.Fragment, {
|
|
1600
|
-
key: this.state.resetCount
|
|
1601
|
-
}, this.props.noStyle ? returnChildNode : this.renderLayout(returnChildNode));
|
|
303
|
+
}
|
|
304
|
+
render() {
|
|
305
|
+
const { children } = this.props;
|
|
306
|
+
const child = Array.isArray(children) ? children[0] : children;
|
|
307
|
+
let returnChildNode;
|
|
308
|
+
if (!this.props.shouldUpdate) {
|
|
309
|
+
returnChildNode = React__default.cloneElement(child, this.getControlled(child));
|
|
310
|
+
} else {
|
|
311
|
+
returnChildNode = child(this.context);
|
|
1602
312
|
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
|
|
313
|
+
return React__default.createElement(React__default.Fragment, { key: this.state.resetCount }, this.props.noStyle ? returnChildNode : this.renderLayout(returnChildNode));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
FormItem.defaultProps = defaultProps;
|
|
317
|
+
FormItem.contextType = Context;
|
|
1608
318
|
export {
|
|
1609
319
|
Context as C,
|
|
1610
320
|
FormItem as F,
|