@blueking/bkui-form 0.0.8 → 0.0.9

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.
@@ -34,6 +34,351 @@
34
34
  return target;
35
35
  }
36
36
 
37
+ function _regeneratorRuntime() {
38
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
39
+
40
+ _regeneratorRuntime = function () {
41
+ return exports;
42
+ };
43
+
44
+ var exports = {},
45
+ Op = Object.prototype,
46
+ hasOwn = Op.hasOwnProperty,
47
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
48
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
49
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
50
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
51
+
52
+ function define(obj, key, value) {
53
+ return Object.defineProperty(obj, key, {
54
+ value: value,
55
+ enumerable: !0,
56
+ configurable: !0,
57
+ writable: !0
58
+ }), obj[key];
59
+ }
60
+
61
+ try {
62
+ define({}, "");
63
+ } catch (err) {
64
+ define = function (obj, key, value) {
65
+ return obj[key] = value;
66
+ };
67
+ }
68
+
69
+ function wrap(innerFn, outerFn, self, tryLocsList) {
70
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
71
+ generator = Object.create(protoGenerator.prototype),
72
+ context = new Context(tryLocsList || []);
73
+ return generator._invoke = function (innerFn, self, context) {
74
+ var state = "suspendedStart";
75
+ return function (method, arg) {
76
+ if ("executing" === state) throw new Error("Generator is already running");
77
+
78
+ if ("completed" === state) {
79
+ if ("throw" === method) throw arg;
80
+ return doneResult();
81
+ }
82
+
83
+ for (context.method = method, context.arg = arg;;) {
84
+ var delegate = context.delegate;
85
+
86
+ if (delegate) {
87
+ var delegateResult = maybeInvokeDelegate(delegate, context);
88
+
89
+ if (delegateResult) {
90
+ if (delegateResult === ContinueSentinel) continue;
91
+ return delegateResult;
92
+ }
93
+ }
94
+
95
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
96
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
97
+ context.dispatchException(context.arg);
98
+ } else "return" === context.method && context.abrupt("return", context.arg);
99
+ state = "executing";
100
+ var record = tryCatch(innerFn, self, context);
101
+
102
+ if ("normal" === record.type) {
103
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
104
+ return {
105
+ value: record.arg,
106
+ done: context.done
107
+ };
108
+ }
109
+
110
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
111
+ }
112
+ };
113
+ }(innerFn, self, context), generator;
114
+ }
115
+
116
+ function tryCatch(fn, obj, arg) {
117
+ try {
118
+ return {
119
+ type: "normal",
120
+ arg: fn.call(obj, arg)
121
+ };
122
+ } catch (err) {
123
+ return {
124
+ type: "throw",
125
+ arg: err
126
+ };
127
+ }
128
+ }
129
+
130
+ exports.wrap = wrap;
131
+ var ContinueSentinel = {};
132
+
133
+ function Generator() {}
134
+
135
+ function GeneratorFunction() {}
136
+
137
+ function GeneratorFunctionPrototype() {}
138
+
139
+ var IteratorPrototype = {};
140
+ define(IteratorPrototype, iteratorSymbol, function () {
141
+ return this;
142
+ });
143
+ var getProto = Object.getPrototypeOf,
144
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
145
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
146
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
147
+
148
+ function defineIteratorMethods(prototype) {
149
+ ["next", "throw", "return"].forEach(function (method) {
150
+ define(prototype, method, function (arg) {
151
+ return this._invoke(method, arg);
152
+ });
153
+ });
154
+ }
155
+
156
+ function AsyncIterator(generator, PromiseImpl) {
157
+ function invoke(method, arg, resolve, reject) {
158
+ var record = tryCatch(generator[method], generator, arg);
159
+
160
+ if ("throw" !== record.type) {
161
+ var result = record.arg,
162
+ value = result.value;
163
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
164
+ invoke("next", value, resolve, reject);
165
+ }, function (err) {
166
+ invoke("throw", err, resolve, reject);
167
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
168
+ result.value = unwrapped, resolve(result);
169
+ }, function (error) {
170
+ return invoke("throw", error, resolve, reject);
171
+ });
172
+ }
173
+
174
+ reject(record.arg);
175
+ }
176
+
177
+ var previousPromise;
178
+
179
+ this._invoke = function (method, arg) {
180
+ function callInvokeWithMethodAndArg() {
181
+ return new PromiseImpl(function (resolve, reject) {
182
+ invoke(method, arg, resolve, reject);
183
+ });
184
+ }
185
+
186
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
187
+ };
188
+ }
189
+
190
+ function maybeInvokeDelegate(delegate, context) {
191
+ var method = delegate.iterator[context.method];
192
+
193
+ if (undefined === method) {
194
+ if (context.delegate = null, "throw" === context.method) {
195
+ if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
196
+ context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
197
+ }
198
+
199
+ return ContinueSentinel;
200
+ }
201
+
202
+ var record = tryCatch(method, delegate.iterator, context.arg);
203
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
204
+ var info = record.arg;
205
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
206
+ }
207
+
208
+ function pushTryEntry(locs) {
209
+ var entry = {
210
+ tryLoc: locs[0]
211
+ };
212
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
213
+ }
214
+
215
+ function resetTryEntry(entry) {
216
+ var record = entry.completion || {};
217
+ record.type = "normal", delete record.arg, entry.completion = record;
218
+ }
219
+
220
+ function Context(tryLocsList) {
221
+ this.tryEntries = [{
222
+ tryLoc: "root"
223
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
224
+ }
225
+
226
+ function values(iterable) {
227
+ if (iterable) {
228
+ var iteratorMethod = iterable[iteratorSymbol];
229
+ if (iteratorMethod) return iteratorMethod.call(iterable);
230
+ if ("function" == typeof iterable.next) return iterable;
231
+
232
+ if (!isNaN(iterable.length)) {
233
+ var i = -1,
234
+ next = function next() {
235
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
236
+
237
+ return next.value = undefined, next.done = !0, next;
238
+ };
239
+
240
+ return next.next = next;
241
+ }
242
+ }
243
+
244
+ return {
245
+ next: doneResult
246
+ };
247
+ }
248
+
249
+ function doneResult() {
250
+ return {
251
+ value: undefined,
252
+ done: !0
253
+ };
254
+ }
255
+
256
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
257
+ var ctor = "function" == typeof genFun && genFun.constructor;
258
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
259
+ }, exports.mark = function (genFun) {
260
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
261
+ }, exports.awrap = function (arg) {
262
+ return {
263
+ __await: arg
264
+ };
265
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
266
+ return this;
267
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
268
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
269
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
270
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
271
+ return result.done ? result.value : iter.next();
272
+ });
273
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
274
+ return this;
275
+ }), define(Gp, "toString", function () {
276
+ return "[object Generator]";
277
+ }), exports.keys = function (object) {
278
+ var keys = [];
279
+
280
+ for (var key in object) keys.push(key);
281
+
282
+ return keys.reverse(), function next() {
283
+ for (; keys.length;) {
284
+ var key = keys.pop();
285
+ if (key in object) return next.value = key, next.done = !1, next;
286
+ }
287
+
288
+ return next.done = !0, next;
289
+ };
290
+ }, exports.values = values, Context.prototype = {
291
+ constructor: Context,
292
+ reset: function (skipTempReset) {
293
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
294
+ },
295
+ stop: function () {
296
+ this.done = !0;
297
+ var rootRecord = this.tryEntries[0].completion;
298
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
299
+ return this.rval;
300
+ },
301
+ dispatchException: function (exception) {
302
+ if (this.done) throw exception;
303
+ var context = this;
304
+
305
+ function handle(loc, caught) {
306
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
307
+ }
308
+
309
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
310
+ var entry = this.tryEntries[i],
311
+ record = entry.completion;
312
+ if ("root" === entry.tryLoc) return handle("end");
313
+
314
+ if (entry.tryLoc <= this.prev) {
315
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
316
+ hasFinally = hasOwn.call(entry, "finallyLoc");
317
+
318
+ if (hasCatch && hasFinally) {
319
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
320
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
321
+ } else if (hasCatch) {
322
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
323
+ } else {
324
+ if (!hasFinally) throw new Error("try statement without catch or finally");
325
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
326
+ }
327
+ }
328
+ }
329
+ },
330
+ abrupt: function (type, arg) {
331
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
332
+ var entry = this.tryEntries[i];
333
+
334
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
335
+ var finallyEntry = entry;
336
+ break;
337
+ }
338
+ }
339
+
340
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
341
+ var record = finallyEntry ? finallyEntry.completion : {};
342
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
343
+ },
344
+ complete: function (record, afterLoc) {
345
+ if ("throw" === record.type) throw record.arg;
346
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
347
+ },
348
+ finish: function (finallyLoc) {
349
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
350
+ var entry = this.tryEntries[i];
351
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
352
+ }
353
+ },
354
+ catch: function (tryLoc) {
355
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
356
+ var entry = this.tryEntries[i];
357
+
358
+ if (entry.tryLoc === tryLoc) {
359
+ var record = entry.completion;
360
+
361
+ if ("throw" === record.type) {
362
+ var thrown = record.arg;
363
+ resetTryEntry(entry);
364
+ }
365
+
366
+ return thrown;
367
+ }
368
+ }
369
+
370
+ throw new Error("illegal catch attempt");
371
+ },
372
+ delegateYield: function (iterable, resultName, nextLoc) {
373
+ return this.delegate = {
374
+ iterator: values(iterable),
375
+ resultName: resultName,
376
+ nextLoc: nextLoc
377
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
378
+ }
379
+ }, exports;
380
+ }
381
+
37
382
  function _typeof(obj) {
38
383
  "@babel/helpers - typeof";
39
384
 
@@ -1317,7 +1662,7 @@
1317
1662
  cache: 'no-cache'
1318
1663
  };
1319
1664
  var request = /*#__PURE__*/(function () {
1320
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(url) {
1665
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
1321
1666
  var config,
1322
1667
  _mergeDeep,
1323
1668
  params,
@@ -1340,7 +1685,7 @@
1340
1685
  data,
1341
1686
  _args = arguments;
1342
1687
 
1343
- return regeneratorRuntime.wrap(function _callee$(_context) {
1688
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1344
1689
  while (1) {
1345
1690
  switch (_context.prev = _context.next) {
1346
1691
  case 0:
@@ -9318,21 +9663,62 @@
9318
9663
  valid: valid,
9319
9664
  message: message
9320
9665
  };
9666
+ }; // 设置表单项校验状态
9667
+
9668
+
9669
+ var setWidgetErrorTips = function setWidgetErrorTips(path, isError, errorMsg) {
9670
+ var formItem = widgetTree.widgetMap[path];
9671
+ var instance = formItem.instance;
9672
+
9673
+ if (formItem.type === 'node') {
9674
+ instance === null || instance === void 0 ? void 0 : instance.setState('error', true);
9675
+ instance === null || instance === void 0 ? void 0 : instance.setErrorTips(errorMsg);
9676
+ } // 如果实例属于某个组,则沿着 path 向上查找,如果找到组且组的 verifiable 设置为 true,则通过实例的校验状态改变组的校验状态
9677
+ // TODO submit 时校验,change 时去掉错误
9678
+
9679
+
9680
+ var widgetPaths = path.split('.');
9681
+ var fieldTitleBreadcrumb = [];
9682
+ widgetPaths.forEach(function (thePath, thePathIndex) {
9683
+ var currentPaths = widgetPaths.slice(0, widgetPaths.length - thePathIndex);
9684
+ var widgetPath = currentPaths.join('.');
9685
+ var theWidget = widgetTree.widgetMap[widgetPath]; // todo(判断path是否是数组索引)
9686
+
9687
+ var isIndex = theWidget.instance.schema.type === 'array' || !theWidget.instance.schema.title;
9688
+ fieldTitleBreadcrumb.push(isIndex ? currentPaths.pop() : theWidget.instance.schema.title);
9689
+
9690
+ if (theWidget.instance.verifiable && theWidget.type === 'group') {
9691
+ if (isError) {
9692
+ var groupErrors = "".concat(fieldTitleBreadcrumb.reverse().join('-'), ": ").concat(errorMsg);
9693
+ theWidget.instance.setGroupErrorTips(path, groupErrors);
9694
+ } else {
9695
+ theWidget.instance.removeGroupErrorTips(path);
9696
+ }
9697
+ }
9698
+ });
9321
9699
  };
9322
9700
  /**
9323
9701
  * 校验单个表单项
9324
9702
  * @param path 字段路径
9325
9703
  */
9326
9704
 
9327
-
9328
9705
  var validateFormItem = function validateFormItem(path) {
9329
9706
  var _instance$schema;
9330
9707
 
9708
+ // TODO 校验逻辑梳理
9331
9709
  var formItem = widgetTree.widgetMap[path];
9332
9710
  if (!formItem) return true;
9333
- var instance = formItem.instance;
9334
- var ownSchema = instance.schema; // json schema 规则校验
9711
+ var instance = formItem.instance; // 清空上一次状态
9335
9712
 
9713
+ if (formItem.type === 'group') {
9714
+ instance === null || instance === void 0 ? void 0 : instance.clearGroupErrorTips();
9715
+ } else {
9716
+ instance === null || instance === void 0 ? void 0 : instance.setState('error', false);
9717
+ instance === null || instance === void 0 ? void 0 : instance.setErrorTips('');
9718
+ } // json schema 规则校验
9719
+
9720
+
9721
+ var ownSchema = instance.schema;
9336
9722
  var schemaValidate = ajv.compile(ownSchema);
9337
9723
  var value = instance.value === undefined ? initializationValue(ownSchema.type, {
9338
9724
  integer: 0,
@@ -9343,19 +9729,14 @@
9343
9729
  if (!schemaValid) {
9344
9730
  var _schemaValidate$error;
9345
9731
 
9346
- instance === null || instance === void 0 ? void 0 : instance.setState('error', true);
9347
- instance === null || instance === void 0 ? void 0 : instance.setErrorTips((_schemaValidate$error = schemaValidate.errors) === null || _schemaValidate$error === void 0 ? void 0 : _schemaValidate$error.map(function (err) {
9732
+ setWidgetErrorTips(path, true, (_schemaValidate$error = schemaValidate.errors) === null || _schemaValidate$error === void 0 ? void 0 : _schemaValidate$error.map(function (err) {
9348
9733
  return err.message;
9349
9734
  }));
9350
9735
  return false;
9351
- }
9736
+ } // 自定义规则校验
9352
9737
 
9353
- var customRules = (_instance$schema = instance.schema) === null || _instance$schema === void 0 ? void 0 : _instance$schema[OWN_RULE_PROPERTY]; // 如果不存在自定义规则校验,不进行校验
9354
-
9355
- if (!customRules) {
9356
- return true;
9357
- }
9358
9738
 
9739
+ var customRules = ((_instance$schema = instance.schema) === null || _instance$schema === void 0 ? void 0 : _instance$schema[OWN_RULE_PROPERTY]) || [];
9359
9740
  var isError = false;
9360
9741
  var errorMsg = '';
9361
9742
 
@@ -9379,28 +9760,12 @@
9379
9760
  _iterator.f();
9380
9761
  }
9381
9762
 
9382
- instance === null || instance === void 0 ? void 0 : instance.setState('error', isError);
9383
- instance === null || instance === void 0 ? void 0 : instance.setErrorTips(errorMsg); // 如果实例属于某个组,则沿着 path 向上查找,如果找到组且组的 verifiable 设置为 true,则通过实例的校验状态改变组的校验状态
9384
- // TODO submit 时校验,change 时去掉错误
9385
-
9386
- var widgetPaths = path.split('.');
9387
- var fieldTitleBreadcrumb = [];
9388
- widgetPaths.forEach(function (thePath, thePathIndex) {
9389
- var currentPaths = widgetPaths.slice(0, widgetPaths.length - thePathIndex);
9390
- var widgetPath = currentPaths.join('.');
9391
- var theWidget = widgetTree.widgetMap[widgetPath];
9392
- fieldTitleBreadcrumb.push(theWidget.instance.schema.title || currentPaths.pop());
9763
+ if (isError) {
9764
+ setWidgetErrorTips(path, true, errorMsg);
9765
+ return false;
9766
+ }
9393
9767
 
9394
- if (theWidget.instance.verifiable && theWidget.type === 'group') {
9395
- if (isError) {
9396
- var groupErrors = "".concat(fieldTitleBreadcrumb.reverse().join('-'), ": ").concat(errorMsg);
9397
- theWidget.instance.setGroupErrorTips(path, groupErrors);
9398
- } else {
9399
- theWidget.instance.removeGroupErrorTips(path);
9400
- }
9401
- }
9402
- });
9403
- return !isError;
9768
+ return true;
9404
9769
  };
9405
9770
  /**
9406
9771
  * 校验整个表单
@@ -9605,12 +9970,12 @@
9605
9970
  loadDataSource: function loadDataSource() {
9606
9971
  var _this3 = this;
9607
9972
 
9608
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
9973
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
9609
9974
  var _this3$schema, _this3$schema$uiComp, _this3$schema$uiComp$;
9610
9975
 
9611
9976
  var xhrConfig, url, params, reset, _this3$httpAdapter, _this3$httpAdapter$re, http, responseParse, remoteURL, requestParams;
9612
9977
 
9613
- return regeneratorRuntime.wrap(function _callee$(_context) {
9978
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
9614
9979
  while (1) {
9615
9980
  switch (_context.prev = _context.next) {
9616
9981
  case 0:
@@ -10198,6 +10563,9 @@
10198
10563
  },
10199
10564
  removeGroupErrorTips: function removeGroupErrorTips(widgetPath) {
10200
10565
  this.$delete(this.groupErrorTips, widgetPath);
10566
+ },
10567
+ clearGroupErrorTips: function clearGroupErrorTips() {
10568
+ this.groupErrorTips = {};
10201
10569
  }
10202
10570
  },
10203
10571
  render: function render(h) {