@rainbow-oh/yee-c 0.4.5 → 0.5.1
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/dist/cjs/Descriptions/descriptions.js +8 -1
- package/dist/cjs/Descriptions/interface.d.ts +1 -1
- package/dist/cjs/Dialog/demo/basic.js +1 -1
- package/dist/cjs/Dialog/dialog.js +1 -1
- package/dist/cjs/Field/demo/validation.js +23 -3
- package/dist/cjs/Field/field.js +1 -1
- package/dist/cjs/Form/Field.js +1 -4
- package/dist/cjs/Form/Form.js +1 -1
- package/dist/cjs/Form/Group.js +36 -14
- package/dist/cjs/Form/List.js +23 -3
- package/dist/cjs/Form/demo/async-validate.d.ts +3 -0
- package/dist/cjs/Form/demo/async-validate.js +108 -0
- package/dist/cjs/Form/demo/virtual.js +1 -1
- package/dist/cjs/Form/form-store.d.ts +4 -4
- package/dist/cjs/Form/form-store.js +55 -25
- package/dist/cjs/Form/interface.d.ts +10 -7
- package/dist/cjs/Form/utils/validate.d.ts +23 -2
- package/dist/cjs/Form/utils/validate.js +59 -10
- package/dist/cjs/Select/demo/basic.js +1 -1
- package/dist/cjs/Select/demo/size.js +2 -0
- package/dist/cjs/Select/demo/virtual.d.ts +3 -0
- package/dist/cjs/Select/demo/virtual.js +55 -0
- package/dist/cjs/Select/hooks/useSelectKeyboard.d.ts +7 -1
- package/dist/cjs/Select/hooks/useSelectKeyboard.js +16 -6
- package/dist/cjs/Select/interface.d.ts +46 -1
- package/dist/cjs/Select/option.js +3 -2
- package/dist/cjs/Select/options.js +115 -15
- package/dist/cjs/Select/select.js +20 -4
- package/dist/cjs/Select/style/index.less +17 -0
- package/dist/cjs/Selector/style/index.less +8 -0
- package/dist/cjs/Table/style/index.less +19 -0
- package/dist/cjs/hooks/index.d.ts +2 -1
- package/dist/cjs/hooks/index.js +3 -1
- package/dist/cjs/hooks/useVirtualList.d.ts +71 -0
- package/dist/cjs/hooks/useVirtualList.js +117 -0
- package/dist/cjs/style/size.css +4 -0
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +5 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Descriptions/descriptions.js +2 -1
- package/dist/esm/Descriptions/interface.d.ts +1 -1
- package/dist/esm/Dialog/demo/basic.js +1 -1
- package/dist/esm/Dialog/dialog.js +1 -1
- package/dist/esm/Field/demo/validation.js +30 -9
- package/dist/esm/Field/field.js +2 -1
- package/dist/esm/Form/Field.js +3 -4
- package/dist/esm/Form/Form.js +1 -1
- package/dist/esm/Form/Group.js +142 -53
- package/dist/esm/Form/List.js +61 -42
- package/dist/esm/Form/demo/async-validate.d.ts +3 -0
- package/dist/esm/Form/demo/async-validate.js +95 -0
- package/dist/esm/Form/demo/virtual.js +1 -1
- package/dist/esm/Form/form-store.d.ts +4 -4
- package/dist/esm/Form/form-store.js +187 -93
- package/dist/esm/Form/interface.d.ts +10 -7
- package/dist/esm/Form/utils/validate.d.ts +23 -2
- package/dist/esm/Form/utils/validate.js +122 -17
- package/dist/esm/Select/demo/basic.js +1 -1
- package/dist/esm/Select/demo/size.js +2 -0
- package/dist/esm/Select/demo/virtual.d.ts +3 -0
- package/dist/esm/Select/demo/virtual.js +38 -0
- package/dist/esm/Select/hooks/useSelectKeyboard.d.ts +7 -1
- package/dist/esm/Select/hooks/useSelectKeyboard.js +25 -9
- package/dist/esm/Select/interface.d.ts +46 -1
- package/dist/esm/Select/option.js +4 -2
- package/dist/esm/Select/options.js +132 -13
- package/dist/esm/Select/select.js +19 -4
- package/dist/esm/Select/style/index.less +17 -0
- package/dist/esm/Selector/style/index.less +8 -0
- package/dist/esm/Table/style/index.less +19 -0
- package/dist/esm/hooks/index.d.ts +2 -1
- package/dist/esm/hooks/index.js +2 -1
- package/dist/esm/hooks/useVirtualList.d.ts +71 -0
- package/dist/esm/hooks/useVirtualList.js +129 -0
- package/dist/esm/style/size.css +4 -0
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +5 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +2 -2
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +1 -1
- package/src/Descriptions/descriptions.tsx +4 -1
- package/src/Descriptions/interface.ts +7 -1
- package/src/Dialog/demo/basic.tsx +1 -1
- package/src/Dialog/dialog.tsx +1 -1
- package/src/Field/demo/validation.tsx +2 -2
- package/src/Field/field.tsx +2 -1
- package/src/Field/index.en-US.md +1 -1
- package/src/Field/index.zh-CN.md +1 -1
- package/src/Form/Field.tsx +3 -4
- package/src/Form/Form.tsx +1 -1
- package/src/Form/Group.tsx +15 -12
- package/src/Form/List.tsx +3 -3
- package/src/Form/demo/async-validate.tsx +71 -0
- package/src/Form/demo/virtual.tsx +1 -1
- package/src/Form/form-store.ts +37 -21
- package/src/Form/index.en-US.md +6 -5
- package/src/Form/index.zh-CN.md +6 -5
- package/src/Form/interface.ts +13 -7
- package/src/Form/utils/validate.ts +65 -13
- package/src/Select/demo/basic.tsx +1 -1
- package/src/Select/demo/size.tsx +2 -0
- package/src/Select/demo/virtual.tsx +25 -0
- package/src/Select/hooks/useSelectKeyboard.ts +30 -6
- package/src/Select/index.en-US.md +4 -0
- package/src/Select/index.zh-CN.md +4 -0
- package/src/Select/interface.ts +51 -3
- package/src/Select/option.tsx +2 -1
- package/src/Select/options.tsx +139 -8
- package/src/Select/select.tsx +23 -1
- package/src/Select/style/index.less +17 -0
- package/src/Selector/style/index.less +8 -0
- package/src/Table/style/index.less +19 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useVirtualList.ts +169 -0
- package/src/style/size.css +4 -0
- package/src/version.ts +1 -1
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
2
5
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
6
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -134,9 +137,10 @@ export var FormStore = /*#__PURE__*/function () {
|
|
|
134
137
|
});
|
|
135
138
|
}
|
|
136
139
|
|
|
137
|
-
// Validate on onChange and onBlur
|
|
140
|
+
// Validate on onChange and onBlur (async — fire-and-forget so setFieldsValue
|
|
141
|
+
// stays synchronous for its callers; results surface via onStoreChange).
|
|
138
142
|
if (trigger === 'onChange' || trigger === 'onBlur' || trigger === 'onSubmit') {
|
|
139
|
-
_this.validateFields(Object.keys(newStore), trigger);
|
|
143
|
+
void _this.validateFields(Object.keys(newStore), trigger);
|
|
140
144
|
}
|
|
141
145
|
_this.refreshField(newStore);
|
|
142
146
|
});
|
|
@@ -194,68 +198,130 @@ export var FormStore = /*#__PURE__*/function () {
|
|
|
194
198
|
}, {});
|
|
195
199
|
_this.setFieldsValue(clearStore, 'clear');
|
|
196
200
|
});
|
|
197
|
-
_defineProperty(this, "validateField", function (
|
|
198
|
-
var
|
|
199
|
-
|
|
200
|
-
return
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
201
|
+
_defineProperty(this, "validateField", /*#__PURE__*/function () {
|
|
202
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(name, trigger) {
|
|
203
|
+
var entity, err, _entity$props, rules, required, mergedRules, value, _iterator3, _step3, rule, result, _result$message;
|
|
204
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
205
|
+
while (1) switch (_context.prev = _context.next) {
|
|
206
|
+
case 0:
|
|
207
|
+
entity = _this.fieldMap.get(name);
|
|
208
|
+
if (entity) {
|
|
209
|
+
_context.next = 3;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
return _context.abrupt("return", []);
|
|
213
|
+
case 3:
|
|
214
|
+
err = [];
|
|
215
|
+
_entity$props = entity.props, rules = _entity$props.rules, required = _entity$props.required;
|
|
216
|
+
mergedRules = rules || [];
|
|
217
|
+
if (required) {
|
|
218
|
+
mergedRules.push({
|
|
219
|
+
required: true,
|
|
220
|
+
message: _this.defaultValidateMessage,
|
|
221
|
+
validateTrigger: ['onChange', 'onSubmit']
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (trigger) {
|
|
225
|
+
mergedRules = mergedRules.filter(function (rule) {
|
|
226
|
+
var t = rule.validateTrigger;
|
|
227
|
+
if (!t) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
if (t === trigger || t.includes(trigger)) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
value = _this.getFieldValue(name);
|
|
237
|
+
_iterator3 = _createForOfIteratorHelper(mergedRules);
|
|
238
|
+
_context.prev = 10;
|
|
239
|
+
_iterator3.s();
|
|
240
|
+
case 12:
|
|
241
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
242
|
+
_context.next = 20;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
rule = _step3.value;
|
|
246
|
+
_context.next = 16;
|
|
247
|
+
return validate(rule, value);
|
|
248
|
+
case 16:
|
|
249
|
+
result = _context.sent;
|
|
250
|
+
if (name && !result.passed) {
|
|
251
|
+
err.push(_objectSpread(_objectSpread({}, rule), {}, {
|
|
252
|
+
name: name,
|
|
253
|
+
status: 'error',
|
|
254
|
+
value: value,
|
|
255
|
+
message: (_result$message = result.message) !== null && _result$message !== void 0 ? _result$message : rule.message
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
258
|
+
case 18:
|
|
259
|
+
_context.next = 12;
|
|
260
|
+
break;
|
|
261
|
+
case 20:
|
|
262
|
+
_context.next = 25;
|
|
263
|
+
break;
|
|
264
|
+
case 22:
|
|
265
|
+
_context.prev = 22;
|
|
266
|
+
_context.t0 = _context["catch"](10);
|
|
267
|
+
_iterator3.e(_context.t0);
|
|
268
|
+
case 25:
|
|
269
|
+
_context.prev = 25;
|
|
270
|
+
_iterator3.f();
|
|
271
|
+
return _context.finish(25);
|
|
272
|
+
case 28:
|
|
273
|
+
if (err.length > 0) {
|
|
274
|
+
_this.validateMessages.set(name, err);
|
|
275
|
+
} else if (_this.validateMessages.has(name)) {
|
|
276
|
+
_this.validateMessages.delete(name);
|
|
277
|
+
}
|
|
278
|
+
// Notify the field to re-render so async validation results surface in the UI.
|
|
279
|
+
entity === null || entity === void 0 || entity.onStoreChange();
|
|
280
|
+
return _context.abrupt("return", err);
|
|
281
|
+
case 31:
|
|
282
|
+
case "end":
|
|
283
|
+
return _context.stop();
|
|
222
284
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
285
|
+
}, _callee, null, [[10, 22, 25, 28]]);
|
|
286
|
+
}));
|
|
287
|
+
return function (_x, _x2) {
|
|
288
|
+
return _ref4.apply(this, arguments);
|
|
289
|
+
};
|
|
290
|
+
}());
|
|
291
|
+
_defineProperty(this, "validateFields", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
292
|
+
var names,
|
|
293
|
+
trigger,
|
|
294
|
+
results,
|
|
295
|
+
err,
|
|
296
|
+
_args2 = arguments;
|
|
297
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
298
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
299
|
+
case 0:
|
|
300
|
+
names = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : Array.from(_this.fieldMap.keys());
|
|
301
|
+
trigger = _args2.length > 1 ? _args2[1] : undefined;
|
|
302
|
+
_context2.next = 4;
|
|
303
|
+
return Promise.all(names.map(function (name) {
|
|
304
|
+
return _this.validateField(name, trigger);
|
|
305
|
+
}));
|
|
306
|
+
case 4:
|
|
307
|
+
results = _context2.sent;
|
|
308
|
+
err = [];
|
|
309
|
+
names.forEach(function (name, index) {
|
|
310
|
+
var messages = results[index];
|
|
311
|
+
err = err.concat(messages);
|
|
312
|
+
if (messages.length > 0) {
|
|
313
|
+
_this.validateMessages.set(name, messages);
|
|
314
|
+
} else {
|
|
315
|
+
_this.validateMessages.delete(name);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
return _context2.abrupt("return", err);
|
|
319
|
+
case 8:
|
|
320
|
+
case "end":
|
|
321
|
+
return _context2.stop();
|
|
255
322
|
}
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
});
|
|
323
|
+
}, _callee2);
|
|
324
|
+
})));
|
|
259
325
|
_defineProperty(this, "refreshField", function (newStore) {
|
|
260
326
|
if (newStore) {
|
|
261
327
|
var keys = Object.keys(newStore);
|
|
@@ -308,14 +374,29 @@ export var FormStore = /*#__PURE__*/function () {
|
|
|
308
374
|
_this.groupEntities.delete(id);
|
|
309
375
|
};
|
|
310
376
|
});
|
|
311
|
-
_defineProperty(this, "validateGroups", function () {
|
|
312
|
-
var force
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
377
|
+
_defineProperty(this, "validateGroups", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
378
|
+
var force,
|
|
379
|
+
results,
|
|
380
|
+
_args3 = arguments;
|
|
381
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
382
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
383
|
+
case 0:
|
|
384
|
+
force = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : false;
|
|
385
|
+
_context3.next = 3;
|
|
386
|
+
return Promise.all(Array.from(_this.groupEntities.values()).map(function (entity) {
|
|
387
|
+
return entity.validate(force);
|
|
388
|
+
}));
|
|
389
|
+
case 3:
|
|
390
|
+
results = _context3.sent;
|
|
391
|
+
return _context3.abrupt("return", results.reduce(function (acc, messages) {
|
|
392
|
+
return acc.concat(messages);
|
|
393
|
+
}, []));
|
|
394
|
+
case 5:
|
|
395
|
+
case "end":
|
|
396
|
+
return _context3.stop();
|
|
397
|
+
}
|
|
398
|
+
}, _callee3);
|
|
399
|
+
})));
|
|
319
400
|
_defineProperty(this, "setCallbacks", function (callbacks) {
|
|
320
401
|
_this.callbacks = _objectSpread(_objectSpread({}, _this.callbacks), callbacks);
|
|
321
402
|
});
|
|
@@ -416,30 +497,30 @@ export var FormStore = /*#__PURE__*/function () {
|
|
|
416
497
|
// Check if value already exists (supports nested paths)
|
|
417
498
|
var hasValue = isNested ? _this.getValueByPath(parsedPath) !== undefined : normalizedName in _this.store;
|
|
418
499
|
if (!hasValue) {
|
|
419
|
-
var
|
|
500
|
+
var _ref7;
|
|
420
501
|
var initialValue = entity.props.initialValue;
|
|
421
502
|
// Read from initialValues (supports nested paths)
|
|
422
503
|
var initialFromForm;
|
|
423
504
|
if (isNested) {
|
|
424
505
|
var current = _this.initialValues;
|
|
425
|
-
var
|
|
426
|
-
|
|
506
|
+
var _iterator4 = _createForOfIteratorHelper(parsedPath),
|
|
507
|
+
_step4;
|
|
427
508
|
try {
|
|
428
|
-
for (
|
|
429
|
-
var key =
|
|
509
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
510
|
+
var key = _step4.value;
|
|
430
511
|
if (current == null) break; // eslint-disable-line eqeqeq
|
|
431
512
|
current = current[key];
|
|
432
513
|
}
|
|
433
514
|
} catch (err) {
|
|
434
|
-
|
|
515
|
+
_iterator4.e(err);
|
|
435
516
|
} finally {
|
|
436
|
-
|
|
517
|
+
_iterator4.f();
|
|
437
518
|
}
|
|
438
519
|
initialFromForm = current;
|
|
439
520
|
} else {
|
|
440
521
|
initialFromForm = _this.initialValues[normalizedName];
|
|
441
522
|
}
|
|
442
|
-
var value = (
|
|
523
|
+
var value = (_ref7 = initialValue !== null && initialValue !== void 0 ? initialValue : initialFromForm) !== null && _ref7 !== void 0 ? _ref7 : undefined;
|
|
443
524
|
if (isNested) {
|
|
444
525
|
_this.store = setValueByPath(_this.store, parsedPath, value);
|
|
445
526
|
} else {
|
|
@@ -466,21 +547,34 @@ export var FormStore = /*#__PURE__*/function () {
|
|
|
466
547
|
// }
|
|
467
548
|
};
|
|
468
549
|
});
|
|
469
|
-
_defineProperty(this, "submit", function () {
|
|
470
|
-
var _this$callbacks5
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
550
|
+
_defineProperty(this, "submit", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
551
|
+
var _this$callbacks5, onFinish, onFinishFailed, fieldErrors, groupErrors, allErrors;
|
|
552
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
553
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
554
|
+
case 0:
|
|
555
|
+
_this$callbacks5 = _this.callbacks, onFinish = _this$callbacks5.onFinish, onFinishFailed = _this$callbacks5.onFinishFailed;
|
|
556
|
+
_context4.next = 3;
|
|
557
|
+
return _this.validateFields();
|
|
558
|
+
case 3:
|
|
559
|
+
fieldErrors = _context4.sent;
|
|
560
|
+
_context4.next = 6;
|
|
561
|
+
return _this.validateGroups(true);
|
|
562
|
+
case 6:
|
|
563
|
+
groupErrors = _context4.sent;
|
|
564
|
+
allErrors = [].concat(_toConsumableArray(fieldErrors), _toConsumableArray(groupErrors));
|
|
565
|
+
if (allErrors.length === 0) {
|
|
566
|
+
onFinish === null || onFinish === void 0 || onFinish(_this.getFieldsValue());
|
|
567
|
+
} else {
|
|
568
|
+
onFinishFailed === null || onFinishFailed === void 0 || onFinishFailed(allErrors);
|
|
569
|
+
}
|
|
570
|
+
_this.refreshField();
|
|
571
|
+
return _context4.abrupt("return", allErrors);
|
|
572
|
+
case 11:
|
|
573
|
+
case "end":
|
|
574
|
+
return _context4.stop();
|
|
575
|
+
}
|
|
576
|
+
}, _callee4);
|
|
577
|
+
})));
|
|
484
578
|
}
|
|
485
579
|
_createClass(FormStore, [{
|
|
486
580
|
key: "setDefaultValidateMessage",
|
|
@@ -103,7 +103,7 @@ export interface FormInstance<Values = any> {
|
|
|
103
103
|
/**
|
|
104
104
|
* Submit form
|
|
105
105
|
*/
|
|
106
|
-
submit: () => ValidateMessage[]
|
|
106
|
+
submit: () => Promise<ValidateMessage[]>;
|
|
107
107
|
/**
|
|
108
108
|
* Get all field values
|
|
109
109
|
*/
|
|
@@ -127,7 +127,7 @@ export interface FormInstance<Values = any> {
|
|
|
127
127
|
/**
|
|
128
128
|
* Validate field
|
|
129
129
|
*/
|
|
130
|
-
validateField: (name: Name, trigger?: 'onChange' | 'onBlur') => ValidateMessage[]
|
|
130
|
+
validateField: (name: Name, trigger?: 'onChange' | 'onBlur') => Promise<ValidateMessage[]>;
|
|
131
131
|
/**
|
|
132
132
|
* Get callback functions
|
|
133
133
|
*/
|
|
@@ -139,7 +139,7 @@ export interface FormInstance<Values = any> {
|
|
|
139
139
|
/**
|
|
140
140
|
* Validate fields and get error messages
|
|
141
141
|
*/
|
|
142
|
-
validateFields: (names?: Name[], trigger?: TRIGGER) => ValidateMessage[]
|
|
142
|
+
validateFields: (names?: Name[], trigger?: TRIGGER) => Promise<ValidateMessage[]>;
|
|
143
143
|
/**
|
|
144
144
|
* Initialize form - mainly used to set initial values and callbacks
|
|
145
145
|
*/
|
|
@@ -214,9 +214,12 @@ export type Rule = {
|
|
|
214
214
|
*/
|
|
215
215
|
message?: string;
|
|
216
216
|
/**
|
|
217
|
-
* Custom validation function
|
|
217
|
+
* Custom validation function. Supports sync and async:
|
|
218
|
+
* - sync: return true/undefined to pass, return false or throw to fail
|
|
219
|
+
* - async: return a Promise (resolve to pass, reject/throw to fail)
|
|
220
|
+
* When throwing/rejecting with an Error, its message overrides rule.message.
|
|
218
221
|
*/
|
|
219
|
-
validator?: (value: unknown) => boolean
|
|
222
|
+
validator?: (value: unknown) => boolean | void | Promise<boolean | void>;
|
|
220
223
|
/**
|
|
221
224
|
* Validation trigger timing
|
|
222
225
|
*/
|
|
@@ -314,7 +317,7 @@ export type FormListField<T = any> = {
|
|
|
314
317
|
value: T;
|
|
315
318
|
};
|
|
316
319
|
export type FormListOperation = {
|
|
317
|
-
add: (defaultValue?: any, insertIndex?: number) => void
|
|
320
|
+
add: (defaultValue?: any, insertIndex?: number) => void | Promise<void>;
|
|
318
321
|
remove: (index: number | number[]) => void;
|
|
319
322
|
move: (from: number, to: number) => void;
|
|
320
323
|
};
|
|
@@ -357,6 +360,6 @@ export type FieldGroupProps = {
|
|
|
357
360
|
className?: string;
|
|
358
361
|
};
|
|
359
362
|
export interface GroupEntity {
|
|
360
|
-
validate: (force: boolean) => ValidateMessage[]
|
|
363
|
+
validate: (force: boolean) => Promise<ValidateMessage[]>;
|
|
361
364
|
reset: () => void;
|
|
362
365
|
}
|
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
import { Rule } from '../interface';
|
|
2
|
-
|
|
1
|
+
import type { Rule } from '../interface';
|
|
2
|
+
export interface ValidateResult {
|
|
3
|
+
passed: boolean;
|
|
4
|
+
message?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Run a custom validator, dispatching between sync and async at runtime.
|
|
8
|
+
*
|
|
9
|
+
* Supports all of the following shapes (backwards compatible):
|
|
10
|
+
* - sync `return true` / `return undefined` → pass
|
|
11
|
+
* - sync `return false` → fail (use rule.message)
|
|
12
|
+
* - sync `throw new Error(msg)` → fail (use msg)
|
|
13
|
+
* - async `return Promise.resolve()` → pass
|
|
14
|
+
* - async `return Promise.resolve(false)` → fail (use rule.message)
|
|
15
|
+
* - async `throw` / `return Promise.reject(new Error(msg))` → fail (use msg)
|
|
16
|
+
*/
|
|
17
|
+
export declare function runValidator(validator: NonNullable<Rule['validator']>, value: unknown): Promise<ValidateResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Validate a single rule against a value.
|
|
20
|
+
* Returns { passed, message? }. Sync rules short-circuit; the custom validator
|
|
21
|
+
* is awaited so async validators are supported.
|
|
22
|
+
*/
|
|
23
|
+
declare function validate(rule: Rule, value: unknown): Promise<ValidateResult>;
|
|
3
24
|
export default validate;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
3
5
|
function isEmpty(v) {
|
|
4
6
|
return v === undefined || v === null || v === '' ? true : false;
|
|
5
7
|
}
|
|
@@ -53,17 +55,13 @@ function verifyRuleOfRegexp(regexp, value) {
|
|
|
53
55
|
return true;
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* @returns validated
|
|
59
|
-
* */
|
|
60
|
-
function verifyMain(rule, value) {
|
|
58
|
+
// Check the synchronous built-in rules (min/max/minLength/maxLength/regexp).
|
|
59
|
+
function verifySyncRules(rule, value) {
|
|
61
60
|
var min = rule.min,
|
|
62
61
|
max = rule.max,
|
|
63
62
|
minLength = rule.minLength,
|
|
64
63
|
maxLength = rule.maxLength,
|
|
65
|
-
regexp = rule.regexp
|
|
66
|
-
validator = rule.validator;
|
|
64
|
+
regexp = rule.regexp;
|
|
67
65
|
if (typeof min !== 'undefined' && !verifyRuleOfMin(min, value)) {
|
|
68
66
|
return false;
|
|
69
67
|
}
|
|
@@ -79,15 +77,122 @@ function verifyMain(rule, value) {
|
|
|
79
77
|
if (regexp instanceof RegExp && !verifyRuleOfRegexp(regexp, value)) {
|
|
80
78
|
return false;
|
|
81
79
|
}
|
|
82
|
-
if (typeof validator === 'function' && !validator(value)) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
80
|
return true;
|
|
86
81
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Run a custom validator, dispatching between sync and async at runtime.
|
|
85
|
+
*
|
|
86
|
+
* Supports all of the following shapes (backwards compatible):
|
|
87
|
+
* - sync `return true` / `return undefined` → pass
|
|
88
|
+
* - sync `return false` → fail (use rule.message)
|
|
89
|
+
* - sync `throw new Error(msg)` → fail (use msg)
|
|
90
|
+
* - async `return Promise.resolve()` → pass
|
|
91
|
+
* - async `return Promise.resolve(false)` → fail (use rule.message)
|
|
92
|
+
* - async `throw` / `return Promise.reject(new Error(msg))` → fail (use msg)
|
|
93
|
+
*/
|
|
94
|
+
export function runValidator(_x, _x2) {
|
|
95
|
+
return _runValidator.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Validate a single rule against a value.
|
|
100
|
+
* Returns { passed, message? }. Sync rules short-circuit; the custom validator
|
|
101
|
+
* is awaited so async validators are supported.
|
|
102
|
+
*/
|
|
103
|
+
function _runValidator() {
|
|
104
|
+
_runValidator = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(validator, value) {
|
|
105
|
+
var res, resolved;
|
|
106
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
107
|
+
while (1) switch (_context.prev = _context.next) {
|
|
108
|
+
case 0:
|
|
109
|
+
_context.prev = 0;
|
|
110
|
+
res = validator(value);
|
|
111
|
+
if (!(res instanceof Promise)) {
|
|
112
|
+
_context.next = 9;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
_context.next = 5;
|
|
116
|
+
return res;
|
|
117
|
+
case 5:
|
|
118
|
+
resolved = _context.sent;
|
|
119
|
+
if (!(resolved === false)) {
|
|
120
|
+
_context.next = 8;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
return _context.abrupt("return", {
|
|
124
|
+
passed: false
|
|
125
|
+
});
|
|
126
|
+
case 8:
|
|
127
|
+
return _context.abrupt("return", {
|
|
128
|
+
passed: true
|
|
129
|
+
});
|
|
130
|
+
case 9:
|
|
131
|
+
if (!(res === false)) {
|
|
132
|
+
_context.next = 11;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
return _context.abrupt("return", {
|
|
136
|
+
passed: false
|
|
137
|
+
});
|
|
138
|
+
case 11:
|
|
139
|
+
return _context.abrupt("return", {
|
|
140
|
+
passed: true
|
|
141
|
+
});
|
|
142
|
+
case 14:
|
|
143
|
+
_context.prev = 14;
|
|
144
|
+
_context.t0 = _context["catch"](0);
|
|
145
|
+
return _context.abrupt("return", {
|
|
146
|
+
passed: false,
|
|
147
|
+
message: _context.t0 instanceof Error ? _context.t0.message : String(_context.t0)
|
|
148
|
+
});
|
|
149
|
+
case 17:
|
|
150
|
+
case "end":
|
|
151
|
+
return _context.stop();
|
|
152
|
+
}
|
|
153
|
+
}, _callee, null, [[0, 14]]);
|
|
154
|
+
}));
|
|
155
|
+
return _runValidator.apply(this, arguments);
|
|
156
|
+
}
|
|
157
|
+
function validate(_x3, _x4) {
|
|
158
|
+
return _validate.apply(this, arguments);
|
|
159
|
+
}
|
|
160
|
+
function _validate() {
|
|
161
|
+
_validate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(rule, value) {
|
|
162
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
163
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
164
|
+
case 0:
|
|
165
|
+
if (!(rule.required && isEmpty(value))) {
|
|
166
|
+
_context2.next = 2;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
return _context2.abrupt("return", {
|
|
170
|
+
passed: false
|
|
171
|
+
});
|
|
172
|
+
case 2:
|
|
173
|
+
if (verifySyncRules(rule, value)) {
|
|
174
|
+
_context2.next = 4;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
return _context2.abrupt("return", {
|
|
178
|
+
passed: false
|
|
179
|
+
});
|
|
180
|
+
case 4:
|
|
181
|
+
if (!(typeof rule.validator === 'function')) {
|
|
182
|
+
_context2.next = 6;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
return _context2.abrupt("return", runValidator(rule.validator, value));
|
|
186
|
+
case 6:
|
|
187
|
+
return _context2.abrupt("return", {
|
|
188
|
+
passed: true
|
|
189
|
+
});
|
|
190
|
+
case 7:
|
|
191
|
+
case "end":
|
|
192
|
+
return _context2.stop();
|
|
193
|
+
}
|
|
194
|
+
}, _callee2);
|
|
195
|
+
}));
|
|
196
|
+
return _validate.apply(this, arguments);
|
|
92
197
|
}
|
|
93
198
|
export default validate;
|
|
@@ -29,6 +29,7 @@ export default (function () {
|
|
|
29
29
|
return setValue(val);
|
|
30
30
|
},
|
|
31
31
|
options: options,
|
|
32
|
+
size: "small",
|
|
32
33
|
style: {
|
|
33
34
|
width: 200
|
|
34
35
|
},
|
|
@@ -49,6 +50,7 @@ export default (function () {
|
|
|
49
50
|
return setValue(val);
|
|
50
51
|
},
|
|
51
52
|
options: options,
|
|
53
|
+
size: "large",
|
|
52
54
|
style: {
|
|
53
55
|
width: 200
|
|
54
56
|
},
|