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