@arco-design/mobile-react 2.31.1 → 2.31.3

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/index.js CHANGED
@@ -63,44 +63,6 @@
63
63
  return t;
64
64
  }
65
65
 
66
- function __awaiter(thisArg, _arguments, P, generator) {
67
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
68
- return new (P || (P = Promise))(function (resolve, reject) {
69
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
70
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
71
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
72
- step((generator = generator.apply(thisArg, _arguments || [])).next());
73
- });
74
- }
75
-
76
- function __generator(thisArg, body) {
77
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
78
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
79
- function verb(n) { return function (v) { return step([n, v]); }; }
80
- function step(op) {
81
- if (f) throw new TypeError("Generator is already executing.");
82
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
83
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
84
- if (y = 0, t) op = [op[0] & 2, t.value];
85
- switch (op[0]) {
86
- case 0: case 1: t = op; break;
87
- case 4: _.label++; return { value: op[1], done: false };
88
- case 5: _.label++; y = op[1]; op = [0]; continue;
89
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
90
- default:
91
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
92
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
93
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
94
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
95
- if (t[2]) _.ops.pop();
96
- _.trys.pop(); continue;
97
- }
98
- op = body.call(thisArg, _);
99
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
100
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
101
- }
102
- }
103
-
104
66
  /** @deprecated */
105
67
  function __spreadArrays$1() {
106
68
  for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
@@ -1844,6 +1806,9 @@
1844
1806
 
1845
1807
  return DateWithUTC;
1846
1808
  }();
1809
+ function formatDateNumber(value) {
1810
+ return value < 10 ? "0" + value : String(value);
1811
+ }
1847
1812
 
1848
1813
  var ValidatorType;
1849
1814
 
@@ -13470,7 +13435,7 @@
13470
13435
  nextTick(function () {
13471
13436
  setLinkArgs(getCurrentValueData());
13472
13437
  });
13473
- }, []);
13438
+ }, [value]);
13474
13439
 
13475
13440
  function hidePicker(scene) {
13476
13441
  setLinkVisible(false);
@@ -13642,11 +13607,7 @@
13642
13607
  }
13643
13608
 
13644
13609
  var allTypes = ['year', 'month', 'date', 'hour', 'minute', 'second'];
13645
-
13646
- var defaultFormatter = function defaultFormatter(value) {
13647
- return value < 10 ? "0" + value : String(value);
13648
- };
13649
-
13610
+ var defaultFormatter = formatDateNumber;
13650
13611
  var YEAR = 12 * 30 * 24 * 60 * 60 * 1000;
13651
13612
  var initMinDate = Date.now() - 10 * YEAR;
13652
13613
  var initMaxDate = Date.now() + 10 * YEAR;
@@ -13679,7 +13640,8 @@
13679
13640
  touchToStop = props.touchToStop,
13680
13641
  _k = props.useUTC,
13681
13642
  useUTC = _k === void 0 ? false : _k,
13682
- otherProps = __rest$1(props, ["currentTs", "className", "visible", "onOk", "onChange", "onValueChange", "mode", "typeArr", "minTs", "maxTs", "formatter", "valueFilter", "columnsProcessor", "touchToStop", "useUTC"]);
13643
+ renderLinkedContainer = props.renderLinkedContainer,
13644
+ otherProps = __rest$1(props, ["currentTs", "className", "visible", "onOk", "onChange", "onValueChange", "mode", "typeArr", "minTs", "maxTs", "formatter", "valueFilter", "columnsProcessor", "touchToStop", "useUTC", "renderLinkedContainer"]);
13683
13645
 
13684
13646
  var currentTs = Math.min(maxTs, Math.max(minTs, userSetCurrentTs));
13685
13647
 
@@ -13949,7 +13911,10 @@
13949
13911
  value: value,
13950
13912
  onPickerChange: _handlePickerChange,
13951
13913
  onOk: _handlePickerConfirm,
13952
- touchToStop: touchToStop
13914
+ touchToStop: touchToStop,
13915
+ renderLinkedContainer: renderLinkedContainer ? function () {
13916
+ return renderLinkedContainer(currentTs, keyOptions);
13917
+ } : undefined
13953
13918
  }));
13954
13919
  });
13955
13920
  });
@@ -16319,2133 +16284,2165 @@
16319
16284
  });
16320
16285
  });
16321
16286
 
16322
- var defaultFunc = function defaultFunc() {};
16287
+ var es6Promise = createCommonjsModule(function (module, exports) {
16288
+ /*!
16289
+ * @overview es6-promise - a tiny implementation of Promises/A+.
16290
+ * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
16291
+ * @license Licensed under MIT license
16292
+ * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
16293
+ * @version v4.2.8+1e68dce6
16294
+ */
16323
16295
 
16324
- var defaultFormDataMethods = {
16325
- getFieldValue: function getFieldValue(name) {
16326
- return name;
16327
- },
16328
- getFieldsValue: function getFieldsValue(_names) {
16329
- return {};
16330
- },
16331
- getFieldError: function getFieldError(_name) {
16332
- return [];
16333
- },
16334
- setFieldValue: function setFieldValue(_name, _value) {
16335
- return true;
16336
- },
16337
- setFieldsValue: function setFieldsValue(_values) {
16338
- return true;
16339
- },
16340
- registerField: function registerField(_name, _self) {
16341
- return function () {};
16342
- },
16343
- resetFields: defaultFunc,
16344
- validateFields: defaultFunc,
16345
- submit: defaultFunc,
16346
- getInternalHooks: function getInternalHooks() {
16347
- return {
16348
- registerField: defaultFunc,
16349
- setInitialValues: defaultFunc,
16350
- setCallbacks: defaultFunc
16351
- };
16352
- }
16353
- }; // 在field的静态的状态下设置
16296
+ (function (global, factory) {
16297
+ module.exports = factory() ;
16298
+ }(commonjsGlobal, (function () {
16299
+ function objectOrFunction(x) {
16300
+ var type = typeof x;
16301
+ return x !== null && (type === 'object' || type === 'function');
16302
+ }
16354
16303
 
16355
- var FormData =
16356
- /** @class */
16357
- function () {
16358
- function FormData() {
16359
- var _this = this;
16304
+ function isFunction(x) {
16305
+ return typeof x === 'function';
16306
+ }
16360
16307
 
16361
- this._formData = {}; // 数据源
16362
16308
 
16363
- this._fieldsList = {}; // 字段列表
16364
16309
 
16365
- this._initialValues = {}; // 初始值
16310
+ var _isArray = void 0;
16311
+ if (Array.isArray) {
16312
+ _isArray = Array.isArray;
16313
+ } else {
16314
+ _isArray = function (x) {
16315
+ return Object.prototype.toString.call(x) === '[object Array]';
16316
+ };
16317
+ }
16366
16318
 
16367
- this._callbacks = {};
16319
+ var isArray = _isArray;
16368
16320
 
16369
- this.setFieldsValue = function (values) {
16370
- _this._formData = __assign$3(__assign$3({}, _this._formData), values);
16321
+ var len = 0;
16322
+ var vertxNext = void 0;
16323
+ var customSchedulerFn = void 0;
16371
16324
 
16372
- _this.notifyField(values);
16325
+ var asap = function asap(callback, arg) {
16326
+ queue[len] = callback;
16327
+ queue[len + 1] = arg;
16328
+ len += 2;
16329
+ if (len === 2) {
16330
+ // If len is 2, that means that we need to schedule an async flush.
16331
+ // If additional callbacks are queued before the queue is flushed, they
16332
+ // will be processed by this flush that we are scheduling.
16333
+ if (customSchedulerFn) {
16334
+ customSchedulerFn(flush);
16335
+ } else {
16336
+ scheduleFlush();
16337
+ }
16338
+ }
16339
+ };
16373
16340
 
16374
- Object.keys(values).forEach(function (key) {
16375
- var _a;
16341
+ function setScheduler(scheduleFn) {
16342
+ customSchedulerFn = scheduleFn;
16343
+ }
16376
16344
 
16377
- if (key in _this._fieldsList) {
16378
- (_a = _this._fieldsList[key]) === null || _a === void 0 ? void 0 : _a.onValueChange();
16379
- }
16380
- });
16381
- return true;
16382
- };
16345
+ function setAsap(asapFn) {
16346
+ asap = asapFn;
16347
+ }
16383
16348
 
16384
- this.setFieldValue = function (name, value) {
16385
- var _a, _b, _c;
16349
+ var browserWindow = typeof window !== 'undefined' ? window : undefined;
16350
+ var browserGlobal = browserWindow || {};
16351
+ var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
16352
+ var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
16386
16353
 
16387
- _this._formData = __assign$3(__assign$3({}, _this._formData), (_a = {}, _a[name] = value, _a));
16388
- var onValuesChange = _this._callbacks.onValuesChange;
16389
- onValuesChange && onValuesChange((_b = {}, _b[name] = value, _b), _this._formData);
16354
+ // test for web worker but not in IE10
16355
+ var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
16390
16356
 
16391
- _this.notifyField((_c = {}, _c[name] = value, _c));
16357
+ // node
16358
+ function useNextTick() {
16359
+ // node version 0.10.x displays a deprecation warning when nextTick is used recursively
16360
+ // see https://github.com/cujojs/when/issues/410 for details
16361
+ return function () {
16362
+ return process.nextTick(flush);
16363
+ };
16364
+ }
16392
16365
 
16393
- return true;
16366
+ // vertx
16367
+ function useVertxTimer() {
16368
+ if (typeof vertxNext !== 'undefined') {
16369
+ return function () {
16370
+ vertxNext(flush);
16394
16371
  };
16372
+ }
16395
16373
 
16396
- this.notifyField = function (values) {
16397
- Object.keys(values).map(function (fieldName) {
16398
- var _a;
16374
+ return useSetTimeout();
16375
+ }
16399
16376
 
16400
- var fieldObj = ((_a = _this._fieldsList) === null || _a === void 0 ? void 0 : _a[fieldName]) || null;
16377
+ function useMutationObserver() {
16378
+ var iterations = 0;
16379
+ var observer = new BrowserMutationObserver(flush);
16380
+ var node = document.createTextNode('');
16381
+ observer.observe(node, { characterData: true });
16401
16382
 
16402
- if (fieldObj) {
16403
- fieldObj.onValueChange(values[fieldName]);
16404
- }
16405
- });
16406
- };
16383
+ return function () {
16384
+ node.data = iterations = ++iterations % 2;
16385
+ };
16386
+ }
16407
16387
 
16408
- this.getFieldsValue = function (names) {
16409
- if (names) {
16410
- return names.map(function (name) {
16411
- return _this.getFieldValue(name);
16412
- });
16413
- }
16388
+ // web worker
16389
+ function useMessageChannel() {
16390
+ var channel = new MessageChannel();
16391
+ channel.port1.onmessage = flush;
16392
+ return function () {
16393
+ return channel.port2.postMessage(0);
16394
+ };
16395
+ }
16414
16396
 
16415
- return _this._formData;
16416
- };
16397
+ function useSetTimeout() {
16398
+ // Store setTimeout reference so es6-promise will be unaffected by
16399
+ // other code modifying setTimeout (like sinon.useFakeTimers())
16400
+ var globalSetTimeout = setTimeout;
16401
+ return function () {
16402
+ return globalSetTimeout(flush, 1);
16403
+ };
16404
+ }
16417
16405
 
16418
- this.getFieldValue = function (name) {
16419
- var _a;
16406
+ var queue = new Array(1000);
16407
+ function flush() {
16408
+ for (var i = 0; i < len; i += 2) {
16409
+ var callback = queue[i];
16410
+ var arg = queue[i + 1];
16420
16411
 
16421
- return (_a = _this._formData) === null || _a === void 0 ? void 0 : _a[name];
16422
- };
16412
+ callback(arg);
16423
16413
 
16424
- this.getFieldError = function (name) {
16425
- var _a;
16414
+ queue[i] = undefined;
16415
+ queue[i + 1] = undefined;
16416
+ }
16426
16417
 
16427
- var field = ((_a = _this._fieldsList) === null || _a === void 0 ? void 0 : _a[name]) || null;
16418
+ len = 0;
16419
+ }
16428
16420
 
16429
- if (field) {
16430
- return field.getFieldError();
16431
- }
16421
+ function attemptVertx() {
16422
+ try {
16423
+ var vertx = Function('return this')().require('vertx');
16424
+ vertxNext = vertx.runOnLoop || vertx.runOnContext;
16425
+ return useVertxTimer();
16426
+ } catch (e) {
16427
+ return useSetTimeout();
16428
+ }
16429
+ }
16432
16430
 
16433
- return [];
16434
- };
16431
+ var scheduleFlush = void 0;
16432
+ // Decide what async method to use to triggering processing of queued callbacks:
16433
+ if (isNode) {
16434
+ scheduleFlush = useNextTick();
16435
+ } else if (BrowserMutationObserver) {
16436
+ scheduleFlush = useMutationObserver();
16437
+ } else if (isWorker) {
16438
+ scheduleFlush = useMessageChannel();
16439
+ } else if (browserWindow === undefined && typeof commonjsRequire === 'function') {
16440
+ scheduleFlush = attemptVertx();
16441
+ } else {
16442
+ scheduleFlush = useSetTimeout();
16443
+ }
16435
16444
 
16436
- this.getFieldsError = function (names) {
16437
- var fields = names || Object.keys(_this._fieldsList);
16438
- return fields.reduce(function (pre, name) {
16439
- var _a;
16445
+ function then(onFulfillment, onRejection) {
16446
+ var parent = this;
16440
16447
 
16441
- var theField = (_a = _this._fieldsList) === null || _a === void 0 ? void 0 : _a[name];
16448
+ var child = new this.constructor(noop);
16442
16449
 
16443
- if (theField) {
16444
- pre[name] = theField === null || theField === void 0 ? void 0 : theField.getFieldError();
16445
- }
16450
+ if (child[PROMISE_ID] === undefined) {
16451
+ makePromise(child);
16452
+ }
16446
16453
 
16447
- return pre;
16448
- }, {});
16449
- };
16454
+ var _state = parent._state;
16450
16455
 
16451
- this.isFieldTouched = function (name) {
16452
- var _a;
16453
16456
 
16454
- var field = ((_a = _this._fieldsList) === null || _a === void 0 ? void 0 : _a[name]) || null;
16457
+ if (_state) {
16458
+ var callback = arguments[_state - 1];
16459
+ asap(function () {
16460
+ return invokeCallback(_state, child, callback, parent._result);
16461
+ });
16462
+ } else {
16463
+ subscribe(parent, child, onFulfillment, onRejection);
16464
+ }
16455
16465
 
16456
- if (field) {
16457
- return field.isFieldTouched();
16458
- }
16466
+ return child;
16467
+ }
16459
16468
 
16460
- return false;
16461
- };
16469
+ /**
16470
+ `Promise.resolve` returns a promise that will become resolved with the
16471
+ passed `value`. It is shorthand for the following:
16462
16472
 
16463
- this.registerField = function (name, self) {
16464
- var _a, _b;
16473
+ ```javascript
16474
+ let promise = new Promise(function(resolve, reject){
16475
+ resolve(1);
16476
+ });
16465
16477
 
16466
- _this._fieldsList[name] = self;
16467
- var initialValue = self.props.initialValue;
16478
+ promise.then(function(value){
16479
+ // value === 1
16480
+ });
16481
+ ```
16468
16482
 
16469
- if (initialValue !== undefined && name) {
16470
- _this._initialValues = __assign$3(__assign$3({}, _this._initialValues), (_a = {}, _a[name] = initialValue, _a));
16483
+ Instead of writing the above, your code now simply becomes the following:
16471
16484
 
16472
- _this.setFieldsValue(__assign$3(__assign$3({}, _this._formData), (_b = {}, _b[name] = initialValue, _b)));
16473
- }
16485
+ ```javascript
16486
+ let promise = Promise.resolve(1);
16474
16487
 
16475
- return function () {
16476
- if (name in _this._fieldsList) {
16477
- delete _this._fieldsList[name];
16478
- delete _this._formData[name];
16479
- }
16480
- };
16481
- };
16488
+ promise.then(function(value){
16489
+ // value === 1
16490
+ });
16491
+ ```
16482
16492
 
16483
- this.setInitialValues = function (initVal) {
16484
- _this._initialValues = __assign$3({}, initVal || {});
16493
+ @method resolve
16494
+ @static
16495
+ @param {Any} value value that the returned promise will be resolved with
16496
+ Useful for tooling.
16497
+ @return {Promise} a promise that will become fulfilled with the given
16498
+ `value`
16499
+ */
16500
+ function resolve$1(object) {
16501
+ /*jshint validthis:true */
16502
+ var Constructor = this;
16485
16503
 
16486
- _this.setFieldsValue(initVal);
16487
- };
16504
+ if (object && typeof object === 'object' && object.constructor === Constructor) {
16505
+ return object;
16506
+ }
16488
16507
 
16489
- this.resetFields = function () {
16490
- _this.setFieldsValue(_this._initialValues);
16491
- };
16508
+ var promise = new Constructor(noop);
16509
+ resolve(promise, object);
16510
+ return promise;
16511
+ }
16492
16512
 
16493
- this.validateFields = function () {
16494
- var promiseList = [];
16495
- Object.values(_this._fieldsList).forEach(function (entity) {
16496
- var promise = entity.validateField();
16497
- promiseList.push(promise.then(function (errors) {
16498
- return errors;
16499
- }));
16500
- });
16501
- var summaryPromise = new Promise(function (resolve, reject) {
16502
- Promise.all(promiseList).then(function (res) {
16503
- var errorResults = res.filter(function (item) {
16504
- var _a;
16513
+ var PROMISE_ID = Math.random().toString(36).substring(2);
16505
16514
 
16506
- return (_a = item === null || item === void 0 ? void 0 : item.errors) === null || _a === void 0 ? void 0 : _a.length;
16507
- });
16515
+ function noop() {}
16508
16516
 
16509
- if (errorResults.length) {
16510
- reject(errorResults);
16511
- } else {
16512
- resolve(res);
16513
- }
16514
- });
16515
- });
16516
- return summaryPromise;
16517
- };
16517
+ var PENDING = void 0;
16518
+ var FULFILLED = 1;
16519
+ var REJECTED = 2;
16518
16520
 
16519
- this.submit = function () {
16520
- return __awaiter(_this, void 0, void 0, function () {
16521
- var _this = this;
16522
-
16523
- return __generator(this, function (_a) {
16524
- this.validateFields().then(function (result) {
16525
- var onSubmit = _this._callbacks.onSubmit;
16526
- onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(_this._formData, result);
16527
- }).catch(function (e) {
16528
- var onSubmitFailed = _this._callbacks.onSubmitFailed;
16529
-
16530
- if (!onSubmitFailed) {
16531
- return;
16532
- }
16521
+ function selfFulfillment() {
16522
+ return new TypeError("You cannot resolve a promise with itself");
16523
+ }
16533
16524
 
16534
- onSubmitFailed(_this._formData, e);
16535
- });
16536
- return [2
16537
- /*return*/
16538
- ];
16539
- });
16540
- });
16541
- };
16525
+ function cannotReturnOwn() {
16526
+ return new TypeError('A promises callback cannot return that same promise.');
16527
+ }
16542
16528
 
16543
- this.setCallbacks = function (callbacks) {
16544
- _this._callbacks = callbacks;
16545
- };
16529
+ function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) {
16530
+ try {
16531
+ then$$1.call(value, fulfillmentHandler, rejectionHandler);
16532
+ } catch (e) {
16533
+ return e;
16534
+ }
16535
+ }
16546
16536
 
16547
- this.getMethods = function () {
16548
- return {
16549
- setFieldsValue: _this.setFieldsValue,
16550
- setFieldValue: _this.setFieldValue,
16551
- getFieldsValue: _this.getFieldsValue,
16552
- getFieldValue: _this.getFieldValue,
16553
- getFieldError: _this.getFieldError,
16554
- getFieldsError: _this.getFieldsError,
16555
- isFieldTouched: _this.isFieldTouched,
16556
- registerField: _this.registerField,
16557
- resetFields: _this.resetFields,
16558
- submit: _this.submit,
16559
- getInternalHooks: _this.getInternalHooks,
16560
- validateFields: _this.validateFields
16561
- };
16562
- };
16537
+ function handleForeignThenable(promise, thenable, then$$1) {
16538
+ asap(function (promise) {
16539
+ var sealed = false;
16540
+ var error = tryThen(then$$1, thenable, function (value) {
16541
+ if (sealed) {
16542
+ return;
16543
+ }
16544
+ sealed = true;
16545
+ if (thenable !== value) {
16546
+ resolve(promise, value);
16547
+ } else {
16548
+ fulfill(promise, value);
16549
+ }
16550
+ }, function (reason) {
16551
+ if (sealed) {
16552
+ return;
16553
+ }
16554
+ sealed = true;
16563
16555
 
16564
- this.getInternalHooks = function () {
16565
- return {
16566
- registerField: _this.registerField,
16567
- setInitialValues: _this.setInitialValues,
16568
- setCallbacks: _this.setCallbacks
16569
- };
16570
- };
16571
- }
16556
+ reject(promise, reason);
16557
+ }, 'Settle: ' + (promise._label || ' unknown promise'));
16572
16558
 
16573
- return FormData;
16574
- }();
16559
+ if (!sealed && error) {
16560
+ sealed = true;
16561
+ reject(promise, error);
16562
+ }
16563
+ }, promise);
16564
+ }
16575
16565
 
16576
- function useForm(form) {
16577
- var formInstanceRef = React.useRef(defaultFormDataMethods);
16578
- var isSingletonRef = React.useRef(false);
16566
+ function handleOwnThenable(promise, thenable) {
16567
+ if (thenable._state === FULFILLED) {
16568
+ fulfill(promise, thenable._result);
16569
+ } else if (thenable._state === REJECTED) {
16570
+ reject(promise, thenable._result);
16571
+ } else {
16572
+ subscribe(thenable, undefined, function (value) {
16573
+ return resolve(promise, value);
16574
+ }, function (reason) {
16575
+ return reject(promise, reason);
16576
+ });
16577
+ }
16578
+ }
16579
16579
 
16580
- if (!isSingletonRef.current) {
16581
- if (form) {
16582
- formInstanceRef.current = form;
16580
+ function handleMaybeThenable(promise, maybeThenable, then$$1) {
16581
+ if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) {
16582
+ handleOwnThenable(promise, maybeThenable);
16583
+ } else {
16584
+ if (then$$1 === undefined) {
16585
+ fulfill(promise, maybeThenable);
16586
+ } else if (isFunction(then$$1)) {
16587
+ handleForeignThenable(promise, maybeThenable, then$$1);
16583
16588
  } else {
16584
- var formIns = new FormData();
16585
- formInstanceRef.current = formIns.getMethods();
16589
+ fulfill(promise, maybeThenable);
16586
16590
  }
16591
+ }
16592
+ }
16587
16593
 
16588
- isSingletonRef.current = true;
16594
+ function resolve(promise, value) {
16595
+ if (promise === value) {
16596
+ reject(promise, selfFulfillment());
16597
+ } else if (objectOrFunction(value)) {
16598
+ var then$$1 = void 0;
16599
+ try {
16600
+ then$$1 = value.then;
16601
+ } catch (error) {
16602
+ reject(promise, error);
16603
+ return;
16604
+ }
16605
+ handleMaybeThenable(promise, value, then$$1);
16606
+ } else {
16607
+ fulfill(promise, value);
16589
16608
  }
16609
+ }
16590
16610
 
16591
- return [formInstanceRef.current];
16611
+ function publishRejection(promise) {
16612
+ if (promise._onerror) {
16613
+ promise._onerror(promise._result);
16614
+ }
16615
+
16616
+ publish(promise);
16592
16617
  }
16593
16618
 
16594
- var FormItemContext = /*#__PURE__*/React__default["default"].createContext({
16595
- form: defaultFormDataMethods,
16596
- layout: 'horizontal'
16597
- });
16619
+ function fulfill(promise, value) {
16620
+ if (promise._state !== PENDING) {
16621
+ return;
16622
+ }
16598
16623
 
16599
- // 注意:自动识别form关联组件的依据,请勿轻易改变代码结构
16600
- // Notice: Automatically identify the basis of the associated component of the form, DO NOT change the code structure.
16601
- var FormInternalComponentType;
16624
+ promise._result = value;
16625
+ promise._state = FULFILLED;
16602
16626
 
16603
- (function (FormInternalComponentType) {
16604
- FormInternalComponentType["Input"] = "Input";
16605
- FormInternalComponentType["Textarea"] = "Textarea";
16606
- FormInternalComponentType["Checkbox"] = "Checkbox";
16607
- FormInternalComponentType["CheckboxGroup"] = "CheckboxGroup";
16608
- FormInternalComponentType["DatePicker"] = "DatePicker";
16609
- FormInternalComponentType["Picker"] = "Picker";
16610
- FormInternalComponentType["Radio"] = "Radio";
16611
- FormInternalComponentType["RadioGroup"] = "RadioGroup";
16612
- FormInternalComponentType["Slider"] = "Slider";
16613
- FormInternalComponentType["Switch"] = "Switch";
16614
- FormInternalComponentType["ImagePicker"] = "ImagePicker";
16615
- FormInternalComponentType["Rate"] = "Rate";
16616
- FormInternalComponentType["Stepper"] = "Stepper";
16617
- })(FormInternalComponentType || (FormInternalComponentType = {}));
16627
+ if (promise._subscribers.length !== 0) {
16628
+ asap(publish, promise);
16629
+ }
16630
+ }
16618
16631
 
16619
- var ValidateStatus;
16632
+ function reject(promise, reason) {
16633
+ if (promise._state !== PENDING) {
16634
+ return;
16635
+ }
16636
+ promise._state = REJECTED;
16637
+ promise._result = reason;
16620
16638
 
16621
- (function (ValidateStatus) {
16622
- ValidateStatus["Init"] = "init";
16623
- ValidateStatus["Error"] = "error";
16624
- ValidateStatus["Warning"] = "warning";
16625
- ValidateStatus["Validating"] = "validating";
16626
- ValidateStatus["Success"] = "success";
16627
- })(ValidateStatus || (ValidateStatus = {}));
16628
-
16629
- var isFieldRequired = function isFieldRequired(rules) {
16630
- if (rules === void 0) {
16631
- rules = [];
16632
- }
16633
-
16634
- return (rules || []).some(function (rule) {
16635
- return rule === null || rule === void 0 ? void 0 : rule.required;
16636
- });
16637
- };
16638
- var getErrorAndWarnings = function getErrorAndWarnings(result) {
16639
- var errors = [];
16640
- var warnings = [];
16641
- var errorTypes = [];
16642
- result.map(function (_a) {
16643
- var _b = _a.message,
16644
- message = _b === void 0 ? [] : _b,
16645
- _c = _a.validateLevel,
16646
- validateLevel = _c === void 0 ? 'error' : _c,
16647
- resultErrorTypes = _a.errorTypes;
16639
+ asap(publishRejection, promise);
16640
+ }
16648
16641
 
16649
- if (!(message === null || message === void 0 ? void 0 : message.length)) {
16650
- return;
16651
- }
16642
+ function subscribe(parent, child, onFulfillment, onRejection) {
16643
+ var _subscribers = parent._subscribers;
16644
+ var length = _subscribers.length;
16652
16645
 
16653
- if (validateLevel === 'warning') {
16654
- warnings = __spreadArrays$1(warnings, message);
16655
- } else {
16656
- errors = __spreadArrays$1(errors, message);
16657
- errorTypes = __spreadArrays$1(errorTypes, resultErrorTypes);
16658
- }
16659
- });
16660
- return {
16661
- warnings: warnings,
16662
- errors: errors,
16663
- errorTypes: errorTypes
16664
- };
16665
- };
16666
16646
 
16667
- function DefaultPickerLinkedContainer(_a) {
16668
- var value = _a.value;
16647
+ parent._onerror = null;
16669
16648
 
16670
- var _b = React.useContext(GlobalContext),
16671
- prefixCls = _b.prefixCls,
16672
- locale = _b.locale;
16649
+ _subscribers[length] = child;
16650
+ _subscribers[length + FULFILLED] = onFulfillment;
16651
+ _subscribers[length + REJECTED] = onRejection;
16673
16652
 
16674
- var className = prefixCls + "-form-picker-link-container";
16675
- return /*#__PURE__*/React__default["default"].createElement("div", {
16676
- className: className
16677
- }, value && value.length ? value.join('-') : /*#__PURE__*/React__default["default"].createElement("span", {
16678
- className: className + "-placeholder"
16679
- }, locale === null || locale === void 0 ? void 0 : locale.Form.pickerDefaultHint));
16653
+ if (length === 0 && parent._state) {
16654
+ asap(publish, parent);
16655
+ }
16680
16656
  }
16681
16657
 
16682
- var FormItemInner =
16683
- /** @class */
16684
- function (_super) {
16685
- __extends$1(FormItemInner, _super);
16686
-
16687
- function FormItemInner(props, context) {
16688
- var _a;
16689
-
16690
- var _this = _super.call(this, props) || this;
16658
+ function publish(promise) {
16659
+ var subscribers = promise._subscribers;
16660
+ var settled = promise._state;
16691
16661
 
16692
- _this._errors = [];
16693
- _this._touched = false;
16662
+ if (subscribers.length === 0) {
16663
+ return;
16664
+ }
16694
16665
 
16695
- _this.onValueChange = function (preStore, curStore) {
16696
- _this._touched = true;
16697
- var shouldUpdate = _this.props.shouldUpdate;
16666
+ var child = void 0,
16667
+ callback = void 0,
16668
+ detail = promise._result;
16698
16669
 
16699
- if (typeof shouldUpdate === 'function') {
16700
- shouldUpdate({
16701
- preStore: preStore,
16702
- curStore: curStore
16703
- }) && _this.forceUpdate();
16704
- return;
16705
- }
16670
+ for (var i = 0; i < subscribers.length; i += 3) {
16671
+ child = subscribers[i];
16672
+ callback = subscribers[i + settled];
16706
16673
 
16707
- _this.forceUpdate();
16708
- };
16674
+ if (child) {
16675
+ invokeCallback(settled, child, callback, detail);
16676
+ } else {
16677
+ callback(detail);
16678
+ }
16679
+ }
16709
16680
 
16710
- _this.getFieldError = function () {
16711
- return _this._errors;
16712
- };
16681
+ promise._subscribers.length = 0;
16682
+ }
16713
16683
 
16714
- _this.isFieldTouched = function () {
16715
- return _this._touched;
16716
- };
16684
+ function invokeCallback(settled, promise, callback, detail) {
16685
+ var hasCallback = isFunction(callback),
16686
+ value = void 0,
16687
+ error = void 0,
16688
+ succeeded = true;
16717
16689
 
16718
- _this.validateField = function () {
16719
- var _a;
16690
+ if (hasCallback) {
16691
+ try {
16692
+ value = callback(detail);
16693
+ } catch (e) {
16694
+ succeeded = false;
16695
+ error = e;
16696
+ }
16720
16697
 
16721
- var validateMessages = _this.context.validateMessages;
16722
- var getFieldValue = _this.context.form.getFieldValue;
16723
- var _b = _this.props,
16724
- field = _b.field,
16725
- rules = _b.rules,
16726
- onValidateStatusChange = _b.onValidateStatusChange;
16727
- var value = getFieldValue(field);
16698
+ if (promise === value) {
16699
+ reject(promise, cannotReturnOwn());
16700
+ return;
16701
+ }
16702
+ } else {
16703
+ value = detail;
16704
+ }
16728
16705
 
16729
- if ((rules === null || rules === void 0 ? void 0 : rules.length) && field) {
16730
- var fieldDom_1 = _this.props.getFormItemRef();
16706
+ if (promise._state !== PENDING) ; else if (hasCallback && succeeded) {
16707
+ resolve(promise, value);
16708
+ } else if (succeeded === false) {
16709
+ reject(promise, error);
16710
+ } else if (settled === FULFILLED) {
16711
+ fulfill(promise, value);
16712
+ } else if (settled === REJECTED) {
16713
+ reject(promise, value);
16714
+ }
16715
+ }
16731
16716
 
16732
- var fieldValidator_1 = new Validator((_a = {}, _a[field] = rules, _a), {
16733
- validateMessages: validateMessages
16734
- });
16735
- return new Promise(function (resolve) {
16736
- var _a;
16717
+ function initializePromise(promise, resolver) {
16718
+ try {
16719
+ resolver(function resolvePromise(value) {
16720
+ resolve(promise, value);
16721
+ }, function rejectPromise(reason) {
16722
+ reject(promise, reason);
16723
+ });
16724
+ } catch (e) {
16725
+ reject(promise, e);
16726
+ }
16727
+ }
16737
16728
 
16738
- fieldValidator_1.validate((_a = {}, _a[field] = value, _a), function (errorsMap) {
16739
- var _a = getErrorAndWarnings((errorsMap === null || errorsMap === void 0 ? void 0 : errorsMap[field]) || []),
16740
- errors = _a.errors,
16741
- warnings = _a.warnings,
16742
- errorTypes = _a.errorTypes;
16729
+ var id = 0;
16730
+ function nextId() {
16731
+ return id++;
16732
+ }
16743
16733
 
16744
- _this._errors = errors;
16745
- onValidateStatusChange({
16746
- errors: _this._errors,
16747
- warnings: warnings,
16748
- errorTypes: errorTypes
16749
- });
16750
- return resolve({
16751
- errors: _this._errors,
16752
- warnings: warnings,
16753
- value: value,
16754
- field: field,
16755
- dom: fieldDom_1
16756
- });
16757
- });
16758
- });
16759
- }
16734
+ function makePromise(promise) {
16735
+ promise[PROMISE_ID] = id++;
16736
+ promise._state = undefined;
16737
+ promise._result = undefined;
16738
+ promise._subscribers = [];
16739
+ }
16760
16740
 
16761
- return Promise.resolve({
16762
- errors: [],
16763
- warnings: [],
16764
- value: value,
16765
- field: field,
16766
- dom: null
16767
- });
16768
- };
16741
+ function validationError() {
16742
+ return new Error('Array Methods must be provided an Array');
16743
+ }
16769
16744
 
16770
- _this.setFieldData = function (value) {
16771
- var field = _this.props.field;
16772
- var setFieldValue = _this.context.form.setFieldValue;
16773
- setFieldValue(field, value);
16745
+ var Enumerator = function () {
16746
+ function Enumerator(Constructor, input) {
16747
+ this._instanceConstructor = Constructor;
16748
+ this.promise = new Constructor(noop);
16774
16749
 
16775
- _this.validateField();
16776
- };
16750
+ if (!this.promise[PROMISE_ID]) {
16751
+ makePromise(this.promise);
16752
+ }
16777
16753
 
16778
- _this.innerTriggerFunction = function (_, value) {
16779
- var _a, _b;
16754
+ if (isArray(input)) {
16755
+ this.length = input.length;
16756
+ this._remaining = input.length;
16780
16757
 
16781
- var args = [];
16758
+ this._result = new Array(this.length);
16782
16759
 
16783
- for (var _i = 2; _i < arguments.length; _i++) {
16784
- args[_i - 2] = arguments[_i];
16760
+ if (this.length === 0) {
16761
+ fulfill(this.promise, this._result);
16762
+ } else {
16763
+ this.length = this.length || 0;
16764
+ this._enumerate(input);
16765
+ if (this._remaining === 0) {
16766
+ fulfill(this.promise, this._result);
16767
+ }
16785
16768
  }
16769
+ } else {
16770
+ reject(this.promise, validationError());
16771
+ }
16772
+ }
16786
16773
 
16787
- _this.setFieldData(value);
16774
+ Enumerator.prototype._enumerate = function _enumerate(input) {
16775
+ for (var i = 0; this._state === PENDING && i < input.length; i++) {
16776
+ this._eachEntry(input[i], i);
16777
+ }
16778
+ };
16788
16779
 
16789
- var _c = _this.props,
16790
- children = _c.children,
16791
- _d = _c.trigger,
16792
- trigger = _d === void 0 ? 'onChange' : _d;
16780
+ Enumerator.prototype._eachEntry = function _eachEntry(entry, i) {
16781
+ var c = this._instanceConstructor;
16782
+ var resolve$$1 = c.resolve;
16793
16783
 
16794
- if (trigger && ((_a = children.props) === null || _a === void 0 ? void 0 : _a[trigger])) {
16795
- (_b = children.props) === null || _b === void 0 ? void 0 : _b[trigger].apply(_b, __spreadArrays$1([_, value], args));
16796
- }
16797
- };
16798
-
16799
- _this.innerTriggerFunctionWithValueFirst = function (value) {
16800
- var _a, _b;
16801
-
16802
- var args = [];
16803
16784
 
16804
- for (var _i = 1; _i < arguments.length; _i++) {
16805
- args[_i - 1] = arguments[_i];
16785
+ if (resolve$$1 === resolve$1) {
16786
+ var _then = void 0;
16787
+ var error = void 0;
16788
+ var didError = false;
16789
+ try {
16790
+ _then = entry.then;
16791
+ } catch (e) {
16792
+ didError = true;
16793
+ error = e;
16806
16794
  }
16807
16795
 
16808
- _this.setFieldData(value);
16809
-
16810
- var _c = _this.props,
16811
- children = _c.children,
16812
- _d = _c.trigger,
16813
- trigger = _d === void 0 ? 'onChange' : _d;
16814
-
16815
- if (trigger && ((_a = children.props) === null || _a === void 0 ? void 0 : _a[trigger])) {
16816
- (_b = children.props) === null || _b === void 0 ? void 0 : _b[trigger].apply(_b, __spreadArrays$1([value], args));
16796
+ if (_then === then && entry._state !== PENDING) {
16797
+ this._settledAt(entry._state, i, entry._result);
16798
+ } else if (typeof _then !== 'function') {
16799
+ this._remaining--;
16800
+ this._result[i] = entry;
16801
+ } else if (c === Promise$1) {
16802
+ var promise = new c(noop);
16803
+ if (didError) {
16804
+ reject(promise, error);
16805
+ } else {
16806
+ handleMaybeThenable(promise, entry, _then);
16807
+ }
16808
+ this._willSettleAt(promise, i);
16809
+ } else {
16810
+ this._willSettleAt(new c(function (resolve$$1) {
16811
+ return resolve$$1(entry);
16812
+ }), i);
16817
16813
  }
16818
- };
16819
-
16820
- _this.innerClearFunction = function () {
16821
- var _a, _b;
16822
-
16823
- var args = [];
16814
+ } else {
16815
+ this._willSettleAt(resolve$$1(entry), i);
16816
+ }
16817
+ };
16824
16818
 
16825
- for (var _i = 0; _i < arguments.length; _i++) {
16826
- args[_i] = arguments[_i];
16827
- }
16819
+ Enumerator.prototype._settledAt = function _settledAt(state, i, value) {
16820
+ var promise = this.promise;
16828
16821
 
16829
- var children = _this.props.children;
16830
16822
 
16831
- _this.setFieldData('');
16823
+ if (promise._state === PENDING) {
16824
+ this._remaining--;
16832
16825
 
16833
- if ((_a = children.props) === null || _a === void 0 ? void 0 : _a.onClear) {
16834
- (_b = children.props) === null || _b === void 0 ? void 0 : _b.onClear.apply(_b, args);
16826
+ if (state === REJECTED) {
16827
+ reject(promise, value);
16828
+ } else {
16829
+ this._result[i] = value;
16835
16830
  }
16836
- };
16837
-
16838
- _this.destroyField = function () {};
16839
-
16840
- if ((props === null || props === void 0 ? void 0 : props.initialValue) && props.field) {
16841
- var setInitialValues = context.form.getInternalHooks().setInitialValues;
16842
- setInitialValues((_a = {}, _a[props.field] = props.initialValue, _a));
16843
16831
  }
16844
16832
 
16845
- return _this;
16846
- }
16847
-
16848
- FormItemInner.prototype.componentDidMount = function () {
16849
- var registerField = this.context.form.getInternalHooks().registerField;
16850
- this.destroyField = registerField(this.props.field, this);
16833
+ if (this._remaining === 0) {
16834
+ fulfill(promise, this._result);
16835
+ }
16851
16836
  };
16852
16837
 
16853
- FormItemInner.prototype.componentWillUnmount = function () {
16854
- this.destroyField();
16838
+ Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) {
16839
+ var enumerator = this;
16840
+
16841
+ subscribe(promise, undefined, function (value) {
16842
+ return enumerator._settledAt(FULFILLED, i, value);
16843
+ }, function (reason) {
16844
+ return enumerator._settledAt(REJECTED, i, reason);
16845
+ });
16855
16846
  };
16856
16847
 
16857
- FormItemInner.prototype.renderChildren = function () {
16858
- var _a;
16848
+ return Enumerator;
16849
+ }();
16859
16850
 
16860
- var _this = this;
16851
+ /**
16852
+ `Promise.all` accepts an array of promises, and returns a new promise which
16853
+ is fulfilled with an array of fulfillment values for the passed promises, or
16854
+ rejected with the reason of the first passed promise to be rejected. It casts all
16855
+ elements of the passed iterable to promises as it runs this algorithm.
16861
16856
 
16862
- var _b, _c, _d;
16857
+ Example:
16863
16858
 
16864
- var _e = this.props,
16865
- children = _e.children,
16866
- field = _e.field,
16867
- _f = _e.trigger,
16868
- trigger = _f === void 0 ? 'onChange' : _f,
16869
- _g = _e.triggerPropsField,
16870
- triggerPropsField = _g === void 0 ? 'value' : _g,
16871
- displayType = _e.displayType;
16872
- var getFieldValue = this.context.form.getFieldValue;
16873
- var props = (_a = {}, _a[triggerPropsField] = getFieldValue(field), _a.disabled = this.props.disabled, _a);
16874
- var childrenType = displayType || ((_b = children.type) === null || _b === void 0 ? void 0 : _b.displayName);
16859
+ ```javascript
16860
+ let promise1 = resolve(1);
16861
+ let promise2 = resolve(2);
16862
+ let promise3 = resolve(3);
16863
+ let promises = [ promise1, promise2, promise3 ];
16875
16864
 
16876
- switch (childrenType) {
16877
- case FormInternalComponentType.Input:
16878
- case FormInternalComponentType.Textarea:
16879
- props = {
16880
- value: getFieldValue(field) || '',
16881
- onInput: this.innerTriggerFunction,
16882
- onClear: this.innerClearFunction,
16883
- disabled: this.props.disabled
16884
- };
16885
- break;
16865
+ Promise.all(promises).then(function(array){
16866
+ // The array here would be [ 1, 2, 3 ];
16867
+ });
16868
+ ```
16886
16869
 
16887
- case FormInternalComponentType.Checkbox:
16888
- case FormInternalComponentType.Radio:
16889
- case FormInternalComponentType.Slider:
16890
- case FormInternalComponentType.RadioGroup:
16891
- case FormInternalComponentType.CheckboxGroup:
16892
- props = {
16893
- value: getFieldValue(field),
16894
- onChange: this.innerTriggerFunctionWithValueFirst,
16895
- disabled: this.props.disabled
16896
- };
16897
- break;
16870
+ If any of the `promises` given to `all` are rejected, the first promise
16871
+ that is rejected will be given as an argument to the returned promises's
16872
+ rejection handler. For example:
16898
16873
 
16899
- case FormInternalComponentType.DatePicker:
16900
- props = {
16901
- currentTs: getFieldValue(field),
16902
- onChange: this.innerTriggerFunctionWithValueFirst,
16903
- disabled: this.props.disabled,
16904
- renderLinkedContainer: ((_c = children.props) === null || _c === void 0 ? void 0 : _c.renderLinkedContainer) || function (val) {
16905
- return /*#__PURE__*/React__default["default"].createElement(DefaultPickerLinkedContainer, {
16906
- value: val
16907
- });
16908
- }
16909
- };
16910
- break;
16874
+ Example:
16911
16875
 
16912
- case FormInternalComponentType.Picker:
16913
- props = {
16914
- value: getFieldValue(field),
16915
- onChange: this.innerTriggerFunctionWithValueFirst,
16916
- disabled: this.props.disabled,
16917
- renderLinkedContainer: ((_d = children.props) === null || _d === void 0 ? void 0 : _d.renderLinkedContainer) || function (val) {
16918
- return /*#__PURE__*/React__default["default"].createElement(DefaultPickerLinkedContainer, {
16919
- value: val
16920
- });
16921
- }
16922
- };
16923
- break;
16876
+ ```javascript
16877
+ let promise1 = resolve(1);
16878
+ let promise2 = reject(new Error("2"));
16879
+ let promise3 = reject(new Error("3"));
16880
+ let promises = [ promise1, promise2, promise3 ];
16924
16881
 
16925
- case FormInternalComponentType.Switch:
16926
- props = {
16927
- checked: Boolean(getFieldValue(field)),
16928
- onChange: this.innerTriggerFunctionWithValueFirst,
16929
- disabled: this.props.disabled
16930
- };
16931
- break;
16882
+ Promise.all(promises).then(function(array){
16883
+ // Code here never runs because there are rejected promises!
16884
+ }, function(error) {
16885
+ // error.message === "2"
16886
+ });
16887
+ ```
16932
16888
 
16933
- case FormInternalComponentType.ImagePicker:
16934
- props = {
16935
- images: getFieldValue(field),
16936
- onChange: this.innerTriggerFunctionWithValueFirst,
16937
- disabled: this.props.disabled
16938
- };
16939
- break;
16889
+ @method all
16890
+ @static
16891
+ @param {Array} entries array of promises
16892
+ @param {String} label optional string for labeling the promise.
16893
+ Useful for tooling.
16894
+ @return {Promise} promise that is fulfilled when all `promises` have been
16895
+ fulfilled, or rejected if any of them become rejected.
16896
+ @static
16897
+ */
16898
+ function all(entries) {
16899
+ return new Enumerator(this, entries).promise;
16900
+ }
16940
16901
 
16941
- default:
16942
- var originTrigger_1 = children.props[trigger]; // inject the validated result
16902
+ /**
16903
+ `Promise.race` returns a new promise which is settled in the same way as the
16904
+ first passed promise to settle.
16943
16905
 
16944
- props.error = this._errors;
16906
+ Example:
16945
16907
 
16946
- props[trigger] = function (newValue) {
16947
- var args = [];
16908
+ ```javascript
16909
+ let promise1 = new Promise(function(resolve, reject){
16910
+ setTimeout(function(){
16911
+ resolve('promise 1');
16912
+ }, 200);
16913
+ });
16948
16914
 
16949
- for (var _i = 1; _i < arguments.length; _i++) {
16950
- args[_i - 1] = arguments[_i];
16951
- }
16915
+ let promise2 = new Promise(function(resolve, reject){
16916
+ setTimeout(function(){
16917
+ resolve('promise 2');
16918
+ }, 100);
16919
+ });
16952
16920
 
16953
- _this.setFieldData(newValue);
16921
+ Promise.race([promise1, promise2]).then(function(result){
16922
+ // result === 'promise 2' because it was resolved before promise1
16923
+ // was resolved.
16924
+ });
16925
+ ```
16954
16926
 
16955
- originTrigger_1 && originTrigger_1.apply(void 0, __spreadArrays$1([newValue], args));
16956
- };
16927
+ `Promise.race` is deterministic in that only the state of the first
16928
+ settled promise matters. For example, even if other promises given to the
16929
+ `promises` array argument are resolved, but the first settled promise has
16930
+ become rejected before the other promises became fulfilled, the returned
16931
+ promise will become rejected:
16957
16932
 
16958
- }
16933
+ ```javascript
16934
+ let promise1 = new Promise(function(resolve, reject){
16935
+ setTimeout(function(){
16936
+ resolve('promise 1');
16937
+ }, 200);
16938
+ });
16959
16939
 
16960
- return /*#__PURE__*/React__default["default"].cloneElement(children, props);
16961
- };
16962
-
16963
- FormItemInner.prototype.render = function () {
16964
- return this.renderChildren();
16965
- };
16966
-
16967
- return FormItemInner;
16968
- }(React.PureComponent);
16940
+ let promise2 = new Promise(function(resolve, reject){
16941
+ setTimeout(function(){
16942
+ reject(new Error('promise 2'));
16943
+ }, 100);
16944
+ });
16969
16945
 
16970
- FormItemInner.contextType = FormItemContext;
16971
- var Item$1 = /*#__PURE__*/React.forwardRef(function (props, ref) {
16972
- var _a;
16946
+ Promise.race([promise1, promise2]).then(function(result){
16947
+ // Code here never runs
16948
+ }, function(reason){
16949
+ // reason.message === 'promise 2' because promise 2 became rejected before
16950
+ // promise 1 became fulfilled
16951
+ });
16952
+ ```
16973
16953
 
16974
- var label = props.label,
16975
- field = props.field,
16976
- _b = props.disabled,
16977
- disabled = _b === void 0 ? false : _b,
16978
- itemLayout = props.layout,
16979
- style = props.style,
16980
- extra = props.extra,
16981
- requiredIcon = props.requiredIcon,
16982
- rules = props.rules,
16983
- _c = props.className,
16984
- className = _c === void 0 ? '' : _c,
16985
- rest = __rest$1(props, ["label", "field", "disabled", "layout", "style", "extra", "requiredIcon", "rules", "className"]);
16954
+ An example real-world use case is implementing timeouts:
16986
16955
 
16987
- var prefixCls = React.useContext(GlobalContext).prefixCls;
16956
+ ```javascript
16957
+ Promise.race([ajax('foo.json'), timeout(5000)])
16958
+ ```
16988
16959
 
16989
- var _d = React.useContext(FormItemContext),
16990
- layout = _d.layout,
16991
- propsDisabled = _d.disabled;
16960
+ @method race
16961
+ @static
16962
+ @param {Array} promises array of promises to observe
16963
+ Useful for tooling.
16964
+ @return {Promise} a promise which settles in the same way as the first passed
16965
+ promise to settle.
16966
+ */
16967
+ function race(entries) {
16968
+ /*jshint validthis:true */
16969
+ var Constructor = this;
16992
16970
 
16993
- var _e = React.useState(null),
16994
- errors = _e[0],
16995
- setErrors = _e[1];
16971
+ if (!isArray(entries)) {
16972
+ return new Constructor(function (_, reject) {
16973
+ return reject(new TypeError('You must pass an array to race.'));
16974
+ });
16975
+ } else {
16976
+ return new Constructor(function (resolve, reject) {
16977
+ var length = entries.length;
16978
+ for (var i = 0; i < length; i++) {
16979
+ Constructor.resolve(entries[i]).then(resolve, reject);
16980
+ }
16981
+ });
16982
+ }
16983
+ }
16996
16984
 
16997
- var _f = React.useState(null),
16998
- errorTypes = _f[0],
16999
- setErrorTypes = _f[1];
16985
+ /**
16986
+ `Promise.reject` returns a promise rejected with the passed `reason`.
16987
+ It is shorthand for the following:
17000
16988
 
17001
- var _g = React.useState([]),
17002
- warnings = _g[0],
17003
- setWarnings = _g[1];
16989
+ ```javascript
16990
+ let promise = new Promise(function(resolve, reject){
16991
+ reject(new Error('WHOOPS'));
16992
+ });
17004
16993
 
17005
- var formItemRef = React.useRef(null);
16994
+ promise.then(function(value){
16995
+ // Code here doesn't run because the promise is rejected!
16996
+ }, function(reason){
16997
+ // reason.message === 'WHOOPS'
16998
+ });
16999
+ ```
17006
17000
 
17007
- var onValidateStatusChange = function onValidateStatusChange(validateResult) {
17008
- var _errors = validateResult.errors,
17009
- _warnings = validateResult.warnings,
17010
- _errorTypes = validateResult.errorTypes;
17011
- setErrors(_errors.length ? _errors[0] : null);
17012
- setErrorTypes(_errorTypes.length ? _errorTypes[0] : null);
17013
- setWarnings(_warnings);
17014
- };
17001
+ Instead of writing the above, your code now simply becomes the following:
17015
17002
 
17016
- var getFormItemRef = function getFormItemRef() {
17017
- return formItemRef.current;
17018
- };
17003
+ ```javascript
17004
+ let promise = Promise.reject(new Error('WHOOPS'));
17019
17005
 
17020
- var fieldDisabled = disabled || propsDisabled;
17021
- var fieldRules = (rest === null || rest === void 0 ? void 0 : rest.required) ? __spreadArrays$1([{
17022
- type: ValidatorType.String,
17023
- required: true
17024
- }], rules || []) : rules;
17025
- var isRequired = isFieldRequired(rules) || (rest === null || rest === void 0 ? void 0 : rest.required);
17026
- React.useImperativeHandle(ref, function () {
17027
- return {
17028
- dom: formItemRef.current
17029
- };
17006
+ promise.then(function(value){
17007
+ // Code here doesn't run because the promise is rejected!
17008
+ }, function(reason){
17009
+ // reason.message === 'WHOOPS'
17030
17010
  });
17031
- return /*#__PURE__*/React__default["default"].createElement("div", {
17032
- className: cls(prefixCls + "-form-item", prefixCls + "-form-item-" + (itemLayout || layout), className, (_a = {
17033
- disabled: fieldDisabled
17034
- }, _a[prefixCls + "-form-item-error"] = !!errors, _a[prefixCls + "-form-item-warning"] = Boolean(!errors && warnings), _a[prefixCls + "-form-item-error-" + errorTypes] = errorTypes, _a)),
17035
- style: style,
17036
- ref: formItemRef
17037
- }, /*#__PURE__*/React__default["default"].createElement("div", {
17038
- className: cls(prefixCls + "-form-label-item")
17039
- }, isRequired ? requiredIcon || /*#__PURE__*/React__default["default"].createElement("span", {
17040
- className: cls(prefixCls + "-form-label-item-required-asterisk")
17041
- }, "*") : null, label), /*#__PURE__*/React__default["default"].createElement("div", {
17042
- className: cls(prefixCls + "-form-item-control-wrapper")
17043
- }, /*#__PURE__*/React__default["default"].createElement("div", {
17044
- className: cls(prefixCls + "-form-item-control")
17045
- }, /*#__PURE__*/React__default["default"].createElement(FormItemInner, __assign$3({}, rest, {
17046
- rules: fieldRules,
17047
- disabled: fieldDisabled,
17048
- field: field,
17049
- onValidateStatusChange: onValidateStatusChange,
17050
- getFormItemRef: getFormItemRef
17051
- }))), errors && /*#__PURE__*/React__default["default"].createElement("div", {
17052
- className: cls(prefixCls + "-form-item-message " + prefixCls + "-form-item-error-message")
17053
- }, errors), (warnings || []).map(function (node, key) {
17054
- return typeof node === 'string' ? /*#__PURE__*/React__default["default"].createElement("div", {
17055
- className: cls(prefixCls + "-form-item-message " + prefixCls + "-form-item-warning-message"),
17056
- key: key
17057
- }, node) : node;
17058
- })), extra);
17059
- });
17011
+ ```
17060
17012
 
17061
- var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
17062
- var _a = props.className,
17063
- className = _a === void 0 ? '' : _a,
17064
- style = props.style,
17065
- _b = props.layout,
17066
- layout = _b === void 0 ? 'horizontal' : _b,
17067
- initialValues = props.initialValues,
17068
- formInstance = props.form,
17069
- children = props.children,
17070
- onValuesChange = props.onValuesChange,
17071
- onSubmit = props.onSubmit,
17072
- onSubmitFailed = props.onSubmitFailed,
17073
- disabled = props.disabled;
17074
- var domRef = React.useRef(null);
17075
- var form = useForm(formInstance)[0];
17013
+ @method reject
17014
+ @static
17015
+ @param {Any} reason value that the returned promise will be rejected with.
17016
+ Useful for tooling.
17017
+ @return {Promise} a promise rejected with the given `reason`.
17018
+ */
17019
+ function reject$1(reason) {
17020
+ /*jshint validthis:true */
17021
+ var Constructor = this;
17022
+ var promise = new Constructor(noop);
17023
+ reject(promise, reason);
17024
+ return promise;
17025
+ }
17076
17026
 
17077
- var _c = form.getInternalHooks(),
17078
- setCallbacks = _c.setCallbacks,
17079
- setInitialValues = _c.setInitialValues;
17027
+ function needsResolver() {
17028
+ throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
17029
+ }
17030
+
17031
+ function needsNew() {
17032
+ throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
17033
+ }
17080
17034
 
17081
- setCallbacks({
17082
- onValuesChange: onValuesChange,
17083
- onSubmit: onSubmit,
17084
- onSubmitFailed: onSubmitFailed
17085
- });
17086
- React.useEffect(function () {
17087
- setInitialValues(initialValues || {});
17088
- }, []);
17089
- React.useImperativeHandle(ref, function () {
17090
- return {
17091
- dom: domRef.current,
17092
- form: form
17093
- };
17094
- });
17095
- var contextValue = {
17096
- form: form,
17097
- layout: layout,
17098
- disabled: disabled
17099
- };
17100
- return /*#__PURE__*/React__default["default"].createElement(ContextLayout, null, function (_a) {
17101
- var prefixCls = _a.prefixCls,
17102
- _b = _a.locale,
17103
- locale = _b === void 0 ? defaultLocale : _b;
17104
- return /*#__PURE__*/React__default["default"].createElement("form", {
17105
- className: prefixCls + "-form " + className,
17106
- style: style,
17107
- ref: domRef,
17108
- onSubmit: function onSubmit(e) {
17109
- e.preventDefault();
17110
- e.stopPropagation();
17111
- form.submit();
17112
- }
17113
- }, /*#__PURE__*/React__default["default"].createElement(FormItemContext.Provider, {
17114
- value: __assign$3(__assign$3({}, contextValue), {
17115
- validateMessages: (locale === null || locale === void 0 ? void 0 : locale.Form) || {}
17116
- })
17117
- }, children));
17118
- });
17119
- });
17120
17035
  /**
17121
- * 表单组件用于集合数据录入
17122
- * @en Form, Form for collecting data input
17123
- * @type 数据录入
17124
- * @type_en Data Entry
17125
- * @name 表单
17126
- * @name_en Form
17127
- */
17036
+ Promise objects represent the eventual result of an asynchronous operation. The
17037
+ primary way of interacting with a promise is through its `then` method, which
17038
+ registers callbacks to receive either a promise's eventual value or the reason
17039
+ why the promise cannot be fulfilled.
17128
17040
 
17129
- var index$i = componentWrapper(Form, {
17130
- Item: Item$1
17131
- });
17041
+ Terminology
17042
+ -----------
17132
17043
 
17133
- /**
17134
- * 宫格可以在水平方向上把页面分隔成等宽度的区块,用于展示内容或进行页面导航。
17135
- * @en The grid can divide the page into equal-width blocks in the horizontal direction for displaying content or for page navigation.
17136
- * @type 布局
17137
- * @type_en Layout
17138
- * @name 宫格
17139
- * @name_en Grid
17140
- */
17044
+ - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
17045
+ - `thenable` is an object or function that defines a `then` method.
17046
+ - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
17047
+ - `exception` is a value that is thrown using the throw statement.
17048
+ - `reason` is a value that indicates why a promise was rejected.
17049
+ - `settled` the final resting state of a promise, fulfilled or rejected.
17141
17050
 
17142
- var Grid = /*#__PURE__*/React.forwardRef(function (props, ref) {
17143
- var _a = props.className,
17144
- className = _a === void 0 ? '' : _a,
17145
- style = props.style,
17146
- data = props.data,
17147
- _b = props.columns,
17148
- columns = _b === void 0 ? 3 : _b,
17149
- _c = props.border,
17150
- border = _c === void 0 ? false : _c,
17151
- _d = props.gutter,
17152
- gutter = _d === void 0 ? 0 : _d,
17153
- _e = props.shape,
17154
- shape = _e === void 0 ? 'square' : _e,
17155
- _f = props.direction,
17156
- direction = _f === void 0 ? 'vertical' : _f,
17157
- _g = props.isSliding,
17158
- isSliding = _g === void 0 ? false : _g;
17159
- var useRtl = React.useContext(GlobalContext).useRtl;
17160
- var domRef = React.useRef(null);
17161
- React.useImperativeHandle(ref, function () {
17162
- return {
17163
- dom: domRef.current
17164
- };
17165
- });
17166
-
17167
- var getRows = function getRows(prefix, rowsData, rows, row) {
17168
- var placeholders = !isSliding && rowsData.length % columns;
17169
- var renderData = rowsData;
17170
-
17171
- if (placeholders) {
17172
- var fakeGrids = new Array(columns - placeholders).fill({
17173
- img: null,
17174
- title: ''
17175
- });
17176
- renderData = rowsData.concat(fakeGrids);
17177
- }
17178
-
17179
- return /*#__PURE__*/React__default["default"].createElement("div", {
17180
- className: prefix + "-rows",
17181
- key: row
17182
- }, renderData.map(function (item, index) {
17183
- var _a;
17184
-
17185
- var img = item.img,
17186
- title = item.title,
17187
- content = item.content,
17188
- itemClassName = item.className,
17189
- _onClick = item.onClick,
17190
- itemStyle = item.itemStyle,
17191
- renderGrid = item.renderGrid;
17051
+ A promise can be in one of three states: pending, fulfilled, or rejected.
17192
17052
 
17193
- if (renderGrid) {
17194
- return renderGrid(item, index, row);
17195
- }
17053
+ Promises that are fulfilled have a fulfillment value and are in the fulfilled
17054
+ state. Promises that are rejected have a rejection reason and are in the
17055
+ rejected state. A fulfillment value is never a thenable.
17196
17056
 
17197
- var marginBottom = row + 1 === rows ? 0 : typeof gutter === 'number' ? gutter : (gutter === null || gutter === void 0 ? void 0 : gutter.y) || 0;
17198
- var rowLen = renderData.length;
17199
- var marginValue = index + 1 === rowLen ? 0 : typeof gutter === 'number' ? gutter : (gutter === null || gutter === void 0 ? void 0 : gutter.x) || 0;
17200
- var marginStyle = (_a = {}, _a[useRtl ? 'marginLeft' : 'marginRight'] = marginValue, _a);
17201
- return /*#__PURE__*/React__default["default"].createElement("div", {
17202
- key: index,
17203
- style: __assign$3(__assign$3({
17204
- marginBottom: marginBottom
17205
- }, marginStyle), itemStyle),
17206
- onClick: function onClick() {
17207
- _onClick && _onClick(item);
17208
- },
17209
- className: cls(prefix + "-rows-item", {
17210
- horizontal: direction === 'horizontal',
17211
- border: border && gutter === 0
17212
- }, itemClassName)
17213
- }, typeof img === 'string' ? /*#__PURE__*/React__default["default"].createElement("img", {
17214
- src: img,
17215
- className: prefix + "-rows-item-icon " + (shape === 'circle' ? 'circle' : '')
17216
- }) : img, title || content ? /*#__PURE__*/React__default["default"].createElement("div", {
17217
- className: prefix + "-rows-item-text"
17218
- }, title ? /*#__PURE__*/React__default["default"].createElement("span", {
17219
- className: prefix + "-rows-item-title"
17220
- }, title) : null, content ? /*#__PURE__*/React__default["default"].createElement("span", {
17221
- className: prefix + "-rows-item-content"
17222
- }, content) : null) : null, (index + 1) % columns !== 0 ? /*#__PURE__*/React__default["default"].createElement("i", {
17223
- className: "vertical-border"
17224
- }) : null, (row + 1) % rows !== 0 ? /*#__PURE__*/React__default["default"].createElement("i", {
17225
- className: "horizontal-border"
17226
- }) : null);
17227
- }));
17228
- };
17057
+ Promises can also be said to *resolve* a value. If this value is also a
17058
+ promise, then the original promise's settled state will match the value's
17059
+ settled state. So a promise that *resolves* a promise that rejects will
17060
+ itself reject, and a promise that *resolves* a promise that fulfills will
17061
+ itself fulfill.
17229
17062
 
17230
- var getGrid = function getGrid(prefix, dataArr) {
17231
- var rows = dataArr.length || 1;
17232
- return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, dataArr.map(function (item, index) {
17233
- return getRows(prefix, item, rows, index);
17234
- }));
17235
- };
17236
17063
 
17237
- var renderEl = function renderEl(_a) {
17238
- var prefixCls = _a.prefixCls;
17239
- var prefix = prefixCls + "-grid";
17240
- var dataLength = (data === null || data === void 0 ? void 0 : data.length) || 0;
17064
+ Basic Usage:
17065
+ ------------
17241
17066
 
17242
- if (dataLength === 0) {
17243
- return null;
17244
- }
17067
+ ```js
17068
+ let promise = new Promise(function(resolve, reject) {
17069
+ // on success
17070
+ resolve(value);
17245
17071
 
17246
- var index = 0;
17247
- var newArr = [];
17072
+ // on failure
17073
+ reject(reason);
17074
+ });
17248
17075
 
17249
- while (index < dataLength) {
17250
- newArr.push(data.slice(index, isSliding ? index += dataLength : index += columns));
17251
- }
17076
+ promise.then(function(value) {
17077
+ // on fulfillment
17078
+ }, function(reason) {
17079
+ // on rejection
17080
+ });
17081
+ ```
17252
17082
 
17253
- return /*#__PURE__*/React__default["default"].createElement("div", {
17254
- className: cls(prefix, className, isSliding ? 'sliding' : ''),
17255
- style: style,
17256
- ref: domRef
17257
- }, getGrid(prefix, newArr));
17258
- };
17083
+ Advanced Usage:
17084
+ ---------------
17259
17085
 
17260
- return /*#__PURE__*/React__default["default"].createElement(ContextLayout, null, renderEl);
17261
- });
17086
+ Promises shine when abstracting away asynchronous interactions such as
17087
+ `XMLHttpRequest`s.
17262
17088
 
17263
- function AddIcon() {
17264
- return /*#__PURE__*/React__default["default"].createElement("svg", {
17265
- width: "30",
17266
- height: "30",
17267
- viewBox: "0 0 30 30",
17268
- fill: "none"
17269
- }, /*#__PURE__*/React__default["default"].createElement("path", {
17270
- fillRule: "evenodd",
17271
- clipRule: "evenodd",
17272
- d: "M14.5 0C14.2239 0 14 0.223857 14 0.5V14H0.5C0.223858 14 0 14.2239 0 14.5V15.5C0 15.7761 0.223857 16 0.5 16H14V29.5C14 29.7761 14.2239 30 14.5 30H15.5C15.7761 30 16 29.7761 16 29.5V16H29.5C29.7761 16 30 15.7761 30 15.5V14.5C30 14.2239 29.7761 14 29.5 14H16V0.5C16 0.223858 15.7761 0 15.5 0H14.5Z",
17273
- fill: "#C9CDD4"
17274
- }));
17275
- }
17089
+ ```js
17090
+ function getJSON(url) {
17091
+ return new Promise(function(resolve, reject){
17092
+ let xhr = new XMLHttpRequest();
17276
17093
 
17277
- var es6Promise = createCommonjsModule(function (module, exports) {
17278
- /*!
17279
- * @overview es6-promise - a tiny implementation of Promises/A+.
17280
- * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
17281
- * @license Licensed under MIT license
17282
- * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
17283
- * @version v4.2.8+1e68dce6
17284
- */
17094
+ xhr.open('GET', url);
17095
+ xhr.onreadystatechange = handler;
17096
+ xhr.responseType = 'json';
17097
+ xhr.setRequestHeader('Accept', 'application/json');
17098
+ xhr.send();
17285
17099
 
17286
- (function (global, factory) {
17287
- module.exports = factory() ;
17288
- }(commonjsGlobal, (function () {
17289
- function objectOrFunction(x) {
17290
- var type = typeof x;
17291
- return x !== null && (type === 'object' || type === 'function');
17292
- }
17100
+ function handler() {
17101
+ if (this.readyState === this.DONE) {
17102
+ if (this.status === 200) {
17103
+ resolve(this.response);
17104
+ } else {
17105
+ reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
17106
+ }
17107
+ }
17108
+ };
17109
+ });
17110
+ }
17293
17111
 
17294
- function isFunction(x) {
17295
- return typeof x === 'function';
17296
- }
17112
+ getJSON('/posts.json').then(function(json) {
17113
+ // on fulfillment
17114
+ }, function(reason) {
17115
+ // on rejection
17116
+ });
17117
+ ```
17297
17118
 
17119
+ Unlike callbacks, promises are great composable primitives.
17298
17120
 
17121
+ ```js
17122
+ Promise.all([
17123
+ getJSON('/posts'),
17124
+ getJSON('/comments')
17125
+ ]).then(function(values){
17126
+ values[0] // => postsJSON
17127
+ values[1] // => commentsJSON
17299
17128
 
17300
- var _isArray = void 0;
17301
- if (Array.isArray) {
17302
- _isArray = Array.isArray;
17303
- } else {
17304
- _isArray = function (x) {
17305
- return Object.prototype.toString.call(x) === '[object Array]';
17306
- };
17307
- }
17129
+ return values;
17130
+ });
17131
+ ```
17308
17132
 
17309
- var isArray = _isArray;
17133
+ @class Promise
17134
+ @param {Function} resolver
17135
+ Useful for tooling.
17136
+ @constructor
17137
+ */
17310
17138
 
17311
- var len = 0;
17312
- var vertxNext = void 0;
17313
- var customSchedulerFn = void 0;
17139
+ var Promise$1 = function () {
17140
+ function Promise(resolver) {
17141
+ this[PROMISE_ID] = nextId();
17142
+ this._result = this._state = undefined;
17143
+ this._subscribers = [];
17314
17144
 
17315
- var asap = function asap(callback, arg) {
17316
- queue[len] = callback;
17317
- queue[len + 1] = arg;
17318
- len += 2;
17319
- if (len === 2) {
17320
- // If len is 2, that means that we need to schedule an async flush.
17321
- // If additional callbacks are queued before the queue is flushed, they
17322
- // will be processed by this flush that we are scheduling.
17323
- if (customSchedulerFn) {
17324
- customSchedulerFn(flush);
17325
- } else {
17326
- scheduleFlush();
17145
+ if (noop !== resolver) {
17146
+ typeof resolver !== 'function' && needsResolver();
17147
+ this instanceof Promise ? initializePromise(this, resolver) : needsNew();
17327
17148
  }
17328
17149
  }
17329
- };
17330
-
17331
- function setScheduler(scheduleFn) {
17332
- customSchedulerFn = scheduleFn;
17333
- }
17334
17150
 
17335
- function setAsap(asapFn) {
17336
- asap = asapFn;
17337
- }
17338
-
17339
- var browserWindow = typeof window !== 'undefined' ? window : undefined;
17340
- var browserGlobal = browserWindow || {};
17341
- var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
17342
- var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
17151
+ /**
17152
+ The primary way of interacting with a promise is through its `then` method,
17153
+ which registers callbacks to receive either a promise's eventual value or the
17154
+ reason why the promise cannot be fulfilled.
17155
+ ```js
17156
+ findUser().then(function(user){
17157
+ // user is available
17158
+ }, function(reason){
17159
+ // user is unavailable, and you are given the reason why
17160
+ });
17161
+ ```
17162
+ Chaining
17163
+ --------
17164
+ The return value of `then` is itself a promise. This second, 'downstream'
17165
+ promise is resolved with the return value of the first promise's fulfillment
17166
+ or rejection handler, or rejected if the handler throws an exception.
17167
+ ```js
17168
+ findUser().then(function (user) {
17169
+ return user.name;
17170
+ }, function (reason) {
17171
+ return 'default name';
17172
+ }).then(function (userName) {
17173
+ // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
17174
+ // will be `'default name'`
17175
+ });
17176
+ findUser().then(function (user) {
17177
+ throw new Error('Found user, but still unhappy');
17178
+ }, function (reason) {
17179
+ throw new Error('`findUser` rejected and we're unhappy');
17180
+ }).then(function (value) {
17181
+ // never reached
17182
+ }, function (reason) {
17183
+ // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
17184
+ // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
17185
+ });
17186
+ ```
17187
+ If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
17188
+ ```js
17189
+ findUser().then(function (user) {
17190
+ throw new PedagogicalException('Upstream error');
17191
+ }).then(function (value) {
17192
+ // never reached
17193
+ }).then(function (value) {
17194
+ // never reached
17195
+ }, function (reason) {
17196
+ // The `PedgagocialException` is propagated all the way down to here
17197
+ });
17198
+ ```
17199
+ Assimilation
17200
+ ------------
17201
+ Sometimes the value you want to propagate to a downstream promise can only be
17202
+ retrieved asynchronously. This can be achieved by returning a promise in the
17203
+ fulfillment or rejection handler. The downstream promise will then be pending
17204
+ until the returned promise is settled. This is called *assimilation*.
17205
+ ```js
17206
+ findUser().then(function (user) {
17207
+ return findCommentsByAuthor(user);
17208
+ }).then(function (comments) {
17209
+ // The user's comments are now available
17210
+ });
17211
+ ```
17212
+ If the assimliated promise rejects, then the downstream promise will also reject.
17213
+ ```js
17214
+ findUser().then(function (user) {
17215
+ return findCommentsByAuthor(user);
17216
+ }).then(function (comments) {
17217
+ // If `findCommentsByAuthor` fulfills, we'll have the value here
17218
+ }, function (reason) {
17219
+ // If `findCommentsByAuthor` rejects, we'll have the reason here
17220
+ });
17221
+ ```
17222
+ Simple Example
17223
+ --------------
17224
+ Synchronous Example
17225
+ ```javascript
17226
+ let result;
17227
+ try {
17228
+ result = findResult();
17229
+ // success
17230
+ } catch(reason) {
17231
+ // failure
17232
+ }
17233
+ ```
17234
+ Errback Example
17235
+ ```js
17236
+ findResult(function(result, err){
17237
+ if (err) {
17238
+ // failure
17239
+ } else {
17240
+ // success
17241
+ }
17242
+ });
17243
+ ```
17244
+ Promise Example;
17245
+ ```javascript
17246
+ findResult().then(function(result){
17247
+ // success
17248
+ }, function(reason){
17249
+ // failure
17250
+ });
17251
+ ```
17252
+ Advanced Example
17253
+ --------------
17254
+ Synchronous Example
17255
+ ```javascript
17256
+ let author, books;
17257
+ try {
17258
+ author = findAuthor();
17259
+ books = findBooksByAuthor(author);
17260
+ // success
17261
+ } catch(reason) {
17262
+ // failure
17263
+ }
17264
+ ```
17265
+ Errback Example
17266
+ ```js
17267
+ function foundBooks(books) {
17268
+ }
17269
+ function failure(reason) {
17270
+ }
17271
+ findAuthor(function(author, err){
17272
+ if (err) {
17273
+ failure(err);
17274
+ // failure
17275
+ } else {
17276
+ try {
17277
+ findBoooksByAuthor(author, function(books, err) {
17278
+ if (err) {
17279
+ failure(err);
17280
+ } else {
17281
+ try {
17282
+ foundBooks(books);
17283
+ } catch(reason) {
17284
+ failure(reason);
17285
+ }
17286
+ }
17287
+ });
17288
+ } catch(error) {
17289
+ failure(err);
17290
+ }
17291
+ // success
17292
+ }
17293
+ });
17294
+ ```
17295
+ Promise Example;
17296
+ ```javascript
17297
+ findAuthor().
17298
+ then(findBooksByAuthor).
17299
+ then(function(books){
17300
+ // found books
17301
+ }).catch(function(reason){
17302
+ // something went wrong
17303
+ });
17304
+ ```
17305
+ @method then
17306
+ @param {Function} onFulfilled
17307
+ @param {Function} onRejected
17308
+ Useful for tooling.
17309
+ @return {Promise}
17310
+ */
17343
17311
 
17344
- // test for web worker but not in IE10
17345
- var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
17312
+ /**
17313
+ `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
17314
+ as the catch block of a try/catch statement.
17315
+ ```js
17316
+ function findAuthor(){
17317
+ throw new Error('couldn't find that author');
17318
+ }
17319
+ // synchronous
17320
+ try {
17321
+ findAuthor();
17322
+ } catch(reason) {
17323
+ // something went wrong
17324
+ }
17325
+ // async with promises
17326
+ findAuthor().catch(function(reason){
17327
+ // something went wrong
17328
+ });
17329
+ ```
17330
+ @method catch
17331
+ @param {Function} onRejection
17332
+ Useful for tooling.
17333
+ @return {Promise}
17334
+ */
17346
17335
 
17347
- // node
17348
- function useNextTick() {
17349
- // node version 0.10.x displays a deprecation warning when nextTick is used recursively
17350
- // see https://github.com/cujojs/when/issues/410 for details
17351
- return function () {
17352
- return process.nextTick(flush);
17336
+
17337
+ Promise.prototype.catch = function _catch(onRejection) {
17338
+ return this.then(null, onRejection);
17353
17339
  };
17354
- }
17355
17340
 
17356
- // vertx
17357
- function useVertxTimer() {
17358
- if (typeof vertxNext !== 'undefined') {
17359
- return function () {
17360
- vertxNext(flush);
17361
- };
17362
- }
17341
+ /**
17342
+ `finally` will be invoked regardless of the promise's fate just as native
17343
+ try/catch/finally behaves
17344
+
17345
+ Synchronous example:
17346
+
17347
+ ```js
17348
+ findAuthor() {
17349
+ if (Math.random() > 0.5) {
17350
+ throw new Error();
17351
+ }
17352
+ return new Author();
17353
+ }
17354
+
17355
+ try {
17356
+ return findAuthor(); // succeed or fail
17357
+ } catch(error) {
17358
+ return findOtherAuther();
17359
+ } finally {
17360
+ // always runs
17361
+ // doesn't affect the return value
17362
+ }
17363
+ ```
17364
+
17365
+ Asynchronous example:
17366
+
17367
+ ```js
17368
+ findAuthor().catch(function(reason){
17369
+ return findOtherAuther();
17370
+ }).finally(function(){
17371
+ // author was either found, or not
17372
+ });
17373
+ ```
17374
+
17375
+ @method finally
17376
+ @param {Function} callback
17377
+ @return {Promise}
17378
+ */
17363
17379
 
17364
- return useSetTimeout();
17365
- }
17366
17380
 
17367
- function useMutationObserver() {
17368
- var iterations = 0;
17369
- var observer = new BrowserMutationObserver(flush);
17370
- var node = document.createTextNode('');
17371
- observer.observe(node, { characterData: true });
17381
+ Promise.prototype.finally = function _finally(callback) {
17382
+ var promise = this;
17383
+ var constructor = promise.constructor;
17372
17384
 
17373
- return function () {
17374
- node.data = iterations = ++iterations % 2;
17375
- };
17376
- }
17385
+ if (isFunction(callback)) {
17386
+ return promise.then(function (value) {
17387
+ return constructor.resolve(callback()).then(function () {
17388
+ return value;
17389
+ });
17390
+ }, function (reason) {
17391
+ return constructor.resolve(callback()).then(function () {
17392
+ throw reason;
17393
+ });
17394
+ });
17395
+ }
17377
17396
 
17378
- // web worker
17379
- function useMessageChannel() {
17380
- var channel = new MessageChannel();
17381
- channel.port1.onmessage = flush;
17382
- return function () {
17383
- return channel.port2.postMessage(0);
17397
+ return promise.then(callback, callback);
17384
17398
  };
17385
- }
17386
17399
 
17387
- function useSetTimeout() {
17388
- // Store setTimeout reference so es6-promise will be unaffected by
17389
- // other code modifying setTimeout (like sinon.useFakeTimers())
17390
- var globalSetTimeout = setTimeout;
17391
- return function () {
17392
- return globalSetTimeout(flush, 1);
17393
- };
17394
- }
17400
+ return Promise;
17401
+ }();
17395
17402
 
17396
- var queue = new Array(1000);
17397
- function flush() {
17398
- for (var i = 0; i < len; i += 2) {
17399
- var callback = queue[i];
17400
- var arg = queue[i + 1];
17403
+ Promise$1.prototype.then = then;
17404
+ Promise$1.all = all;
17405
+ Promise$1.race = race;
17406
+ Promise$1.resolve = resolve$1;
17407
+ Promise$1.reject = reject$1;
17408
+ Promise$1._setScheduler = setScheduler;
17409
+ Promise$1._setAsap = setAsap;
17410
+ Promise$1._asap = asap;
17401
17411
 
17402
- callback(arg);
17412
+ /*global self*/
17413
+ function polyfill() {
17414
+ var local = void 0;
17403
17415
 
17404
- queue[i] = undefined;
17405
- queue[i + 1] = undefined;
17416
+ if (typeof commonjsGlobal !== 'undefined') {
17417
+ local = commonjsGlobal;
17418
+ } else if (typeof self !== 'undefined') {
17419
+ local = self;
17420
+ } else {
17421
+ try {
17422
+ local = Function('return this')();
17423
+ } catch (e) {
17424
+ throw new Error('polyfill failed because global object is unavailable in this environment');
17425
+ }
17406
17426
  }
17407
17427
 
17408
- len = 0;
17409
- }
17428
+ var P = local.Promise;
17410
17429
 
17411
- function attemptVertx() {
17412
- try {
17413
- var vertx = Function('return this')().require('vertx');
17414
- vertxNext = vertx.runOnLoop || vertx.runOnContext;
17415
- return useVertxTimer();
17416
- } catch (e) {
17417
- return useSetTimeout();
17430
+ if (P) {
17431
+ var promiseToString = null;
17432
+ try {
17433
+ promiseToString = Object.prototype.toString.call(P.resolve());
17434
+ } catch (e) {
17435
+ // silently ignored
17436
+ }
17437
+
17438
+ if (promiseToString === '[object Promise]' && !P.cast) {
17439
+ return;
17440
+ }
17418
17441
  }
17419
- }
17420
17442
 
17421
- var scheduleFlush = void 0;
17422
- // Decide what async method to use to triggering processing of queued callbacks:
17423
- if (isNode) {
17424
- scheduleFlush = useNextTick();
17425
- } else if (BrowserMutationObserver) {
17426
- scheduleFlush = useMutationObserver();
17427
- } else if (isWorker) {
17428
- scheduleFlush = useMessageChannel();
17429
- } else if (browserWindow === undefined && typeof commonjsRequire === 'function') {
17430
- scheduleFlush = attemptVertx();
17431
- } else {
17432
- scheduleFlush = useSetTimeout();
17443
+ local.Promise = Promise$1;
17433
17444
  }
17434
17445
 
17435
- function then(onFulfillment, onRejection) {
17436
- var parent = this;
17446
+ // Strange compat..
17447
+ Promise$1.polyfill = polyfill;
17448
+ Promise$1.Promise = Promise$1;
17437
17449
 
17438
- var child = new this.constructor(noop);
17450
+ return Promise$1;
17439
17451
 
17440
- if (child[PROMISE_ID] === undefined) {
17441
- makePromise(child);
17442
- }
17452
+ })));
17443
17453
 
17444
- var _state = parent._state;
17445
17454
 
17446
17455
 
17447
- if (_state) {
17448
- var callback = arguments[_state - 1];
17449
- asap(function () {
17450
- return invokeCallback(_state, child, callback, parent._result);
17451
- });
17452
- } else {
17453
- subscribe(parent, child, onFulfillment, onRejection);
17456
+
17457
+ });
17458
+
17459
+ var defaultFunc = function defaultFunc() {};
17460
+
17461
+ var defaultFormDataMethods = {
17462
+ getFieldValue: function getFieldValue(name) {
17463
+ return name;
17464
+ },
17465
+ getFieldsValue: function getFieldsValue(_names) {
17466
+ return {};
17467
+ },
17468
+ getFieldError: function getFieldError(_name) {
17469
+ return [];
17470
+ },
17471
+ setFieldValue: function setFieldValue(_name, _value) {
17472
+ return true;
17473
+ },
17474
+ setFieldsValue: function setFieldsValue(_values) {
17475
+ return true;
17476
+ },
17477
+ registerField: function registerField(_name, _self) {
17478
+ return function () {};
17479
+ },
17480
+ resetFields: defaultFunc,
17481
+ validateFields: defaultFunc,
17482
+ submit: defaultFunc,
17483
+ getInternalHooks: function getInternalHooks() {
17484
+ return {
17485
+ registerField: defaultFunc,
17486
+ setInitialValues: defaultFunc,
17487
+ setCallbacks: defaultFunc
17488
+ };
17454
17489
  }
17490
+ }; // 在field的静态的状态下设置
17455
17491
 
17456
- return child;
17457
- }
17492
+ var FormData =
17493
+ /** @class */
17494
+ function () {
17495
+ function FormData() {
17496
+ var _this = this;
17458
17497
 
17459
- /**
17460
- `Promise.resolve` returns a promise that will become resolved with the
17461
- passed `value`. It is shorthand for the following:
17498
+ this._formData = {}; // 数据源
17462
17499
 
17463
- ```javascript
17464
- let promise = new Promise(function(resolve, reject){
17465
- resolve(1);
17466
- });
17500
+ this._fieldsList = {}; // 字段列表
17467
17501
 
17468
- promise.then(function(value){
17469
- // value === 1
17470
- });
17471
- ```
17502
+ this._initialValues = {}; // 初始值
17472
17503
 
17473
- Instead of writing the above, your code now simply becomes the following:
17504
+ this._callbacks = {};
17474
17505
 
17475
- ```javascript
17476
- let promise = Promise.resolve(1);
17506
+ this.setFieldsValue = function (values) {
17507
+ var oldValues = Object.keys(values).reduce(function (acc, key) {
17508
+ var _a;
17477
17509
 
17478
- promise.then(function(value){
17479
- // value === 1
17480
- });
17481
- ```
17510
+ return __assign$3(__assign$3({}, acc), (_a = {}, _a[key] = _this.getFieldValue(key), _a));
17511
+ }, {});
17512
+ _this._formData = __assign$3(__assign$3({}, _this._formData), values);
17513
+ var onValuesChange = _this._callbacks.onValuesChange;
17514
+ onValuesChange && onValuesChange(values, _this._formData);
17482
17515
 
17483
- @method resolve
17484
- @static
17485
- @param {Any} value value that the returned promise will be resolved with
17486
- Useful for tooling.
17487
- @return {Promise} a promise that will become fulfilled with the given
17488
- `value`
17489
- */
17490
- function resolve$1(object) {
17491
- /*jshint validthis:true */
17492
- var Constructor = this;
17516
+ _this.notifyField(values, oldValues);
17493
17517
 
17494
- if (object && typeof object === 'object' && object.constructor === Constructor) {
17495
- return object;
17496
- }
17518
+ return true;
17519
+ };
17497
17520
 
17498
- var promise = new Constructor(noop);
17499
- resolve(promise, object);
17500
- return promise;
17501
- }
17521
+ this.setFieldValue = function (name, value) {
17522
+ var _a, _b, _c, _d;
17502
17523
 
17503
- var PROMISE_ID = Math.random().toString(36).substring(2);
17524
+ var oldValues = (_a = {}, _a[name] = _this.getFieldValue(name), _a);
17525
+ _this._formData = __assign$3(__assign$3({}, _this._formData), (_b = {}, _b[name] = value, _b));
17526
+ var onValuesChange = _this._callbacks.onValuesChange;
17527
+ onValuesChange && onValuesChange((_c = {}, _c[name] = value, _c), _this._formData);
17504
17528
 
17505
- function noop() {}
17529
+ _this.notifyField((_d = {}, _d[name] = value, _d), oldValues);
17506
17530
 
17507
- var PENDING = void 0;
17508
- var FULFILLED = 1;
17509
- var REJECTED = 2;
17531
+ return true;
17532
+ };
17510
17533
 
17511
- function selfFulfillment() {
17512
- return new TypeError("You cannot resolve a promise with itself");
17513
- }
17534
+ this.notifyField = function (values, oldValues) {
17535
+ Object.keys(values).map(function (fieldName) {
17536
+ var _a;
17514
17537
 
17515
- function cannotReturnOwn() {
17516
- return new TypeError('A promises callback cannot return that same promise.');
17517
- }
17538
+ var fieldObj = ((_a = _this._fieldsList) === null || _a === void 0 ? void 0 : _a[fieldName]) || null;
17518
17539
 
17519
- function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) {
17520
- try {
17521
- then$$1.call(value, fulfillmentHandler, rejectionHandler);
17522
- } catch (e) {
17523
- return e;
17524
- }
17525
- }
17540
+ if (fieldObj) {
17541
+ fieldObj.onValueChange(values[fieldName], oldValues[fieldName]);
17542
+ }
17543
+ });
17544
+ };
17526
17545
 
17527
- function handleForeignThenable(promise, thenable, then$$1) {
17528
- asap(function (promise) {
17529
- var sealed = false;
17530
- var error = tryThen(then$$1, thenable, function (value) {
17531
- if (sealed) {
17532
- return;
17533
- }
17534
- sealed = true;
17535
- if (thenable !== value) {
17536
- resolve(promise, value);
17537
- } else {
17538
- fulfill(promise, value);
17539
- }
17540
- }, function (reason) {
17541
- if (sealed) {
17542
- return;
17546
+ this.getFieldsValue = function (names) {
17547
+ if (names) {
17548
+ return names.map(function (name) {
17549
+ return _this.getFieldValue(name);
17550
+ });
17543
17551
  }
17544
- sealed = true;
17545
-
17546
- reject(promise, reason);
17547
- }, 'Settle: ' + (promise._label || ' unknown promise'));
17548
17552
 
17549
- if (!sealed && error) {
17550
- sealed = true;
17551
- reject(promise, error);
17552
- }
17553
- }, promise);
17554
- }
17553
+ return _this._formData;
17554
+ };
17555
17555
 
17556
- function handleOwnThenable(promise, thenable) {
17557
- if (thenable._state === FULFILLED) {
17558
- fulfill(promise, thenable._result);
17559
- } else if (thenable._state === REJECTED) {
17560
- reject(promise, thenable._result);
17561
- } else {
17562
- subscribe(thenable, undefined, function (value) {
17563
- return resolve(promise, value);
17564
- }, function (reason) {
17565
- return reject(promise, reason);
17566
- });
17567
- }
17568
- }
17556
+ this.getFieldValue = function (name) {
17557
+ var _a;
17569
17558
 
17570
- function handleMaybeThenable(promise, maybeThenable, then$$1) {
17571
- if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) {
17572
- handleOwnThenable(promise, maybeThenable);
17573
- } else {
17574
- if (then$$1 === undefined) {
17575
- fulfill(promise, maybeThenable);
17576
- } else if (isFunction(then$$1)) {
17577
- handleForeignThenable(promise, maybeThenable, then$$1);
17578
- } else {
17579
- fulfill(promise, maybeThenable);
17580
- }
17581
- }
17582
- }
17559
+ return (_a = _this._formData) === null || _a === void 0 ? void 0 : _a[name];
17560
+ };
17583
17561
 
17584
- function resolve(promise, value) {
17585
- if (promise === value) {
17586
- reject(promise, selfFulfillment());
17587
- } else if (objectOrFunction(value)) {
17588
- var then$$1 = void 0;
17589
- try {
17590
- then$$1 = value.then;
17591
- } catch (error) {
17592
- reject(promise, error);
17593
- return;
17594
- }
17595
- handleMaybeThenable(promise, value, then$$1);
17596
- } else {
17597
- fulfill(promise, value);
17598
- }
17599
- }
17562
+ this.getFieldError = function (name) {
17563
+ var _a;
17600
17564
 
17601
- function publishRejection(promise) {
17602
- if (promise._onerror) {
17603
- promise._onerror(promise._result);
17604
- }
17565
+ var field = ((_a = _this._fieldsList) === null || _a === void 0 ? void 0 : _a[name]) || null;
17605
17566
 
17606
- publish(promise);
17607
- }
17567
+ if (field) {
17568
+ return field.getFieldError();
17569
+ }
17608
17570
 
17609
- function fulfill(promise, value) {
17610
- if (promise._state !== PENDING) {
17611
- return;
17612
- }
17571
+ return [];
17572
+ };
17613
17573
 
17614
- promise._result = value;
17615
- promise._state = FULFILLED;
17574
+ this.getFieldsError = function (names) {
17575
+ var fields = names || Object.keys(_this._fieldsList);
17576
+ return fields.reduce(function (pre, name) {
17577
+ var _a;
17616
17578
 
17617
- if (promise._subscribers.length !== 0) {
17618
- asap(publish, promise);
17619
- }
17620
- }
17579
+ var theField = (_a = _this._fieldsList) === null || _a === void 0 ? void 0 : _a[name];
17621
17580
 
17622
- function reject(promise, reason) {
17623
- if (promise._state !== PENDING) {
17624
- return;
17625
- }
17626
- promise._state = REJECTED;
17627
- promise._result = reason;
17581
+ if (theField) {
17582
+ pre[name] = theField === null || theField === void 0 ? void 0 : theField.getFieldError();
17583
+ }
17628
17584
 
17629
- asap(publishRejection, promise);
17630
- }
17585
+ return pre;
17586
+ }, {});
17587
+ };
17631
17588
 
17632
- function subscribe(parent, child, onFulfillment, onRejection) {
17633
- var _subscribers = parent._subscribers;
17634
- var length = _subscribers.length;
17589
+ this.isFieldTouched = function (name) {
17590
+ var _a;
17635
17591
 
17592
+ var field = ((_a = _this._fieldsList) === null || _a === void 0 ? void 0 : _a[name]) || null;
17636
17593
 
17637
- parent._onerror = null;
17594
+ if (field) {
17595
+ return field.isFieldTouched();
17596
+ }
17638
17597
 
17639
- _subscribers[length] = child;
17640
- _subscribers[length + FULFILLED] = onFulfillment;
17641
- _subscribers[length + REJECTED] = onRejection;
17598
+ return false;
17599
+ };
17642
17600
 
17643
- if (length === 0 && parent._state) {
17644
- asap(publish, parent);
17645
- }
17646
- }
17601
+ this.registerField = function (name, self) {
17602
+ var _a, _b;
17647
17603
 
17648
- function publish(promise) {
17649
- var subscribers = promise._subscribers;
17650
- var settled = promise._state;
17604
+ _this._fieldsList[name] = self;
17605
+ var initialValue = self.props.initialValue;
17651
17606
 
17652
- if (subscribers.length === 0) {
17653
- return;
17654
- }
17607
+ if (initialValue !== undefined && name) {
17608
+ _this._initialValues = __assign$3(__assign$3({}, _this._initialValues), (_a = {}, _a[name] = initialValue, _a));
17655
17609
 
17656
- var child = void 0,
17657
- callback = void 0,
17658
- detail = promise._result;
17610
+ _this.setFieldsValue(__assign$3(__assign$3({}, _this._formData), (_b = {}, _b[name] = initialValue, _b)));
17611
+ }
17659
17612
 
17660
- for (var i = 0; i < subscribers.length; i += 3) {
17661
- child = subscribers[i];
17662
- callback = subscribers[i + settled];
17613
+ return function () {
17614
+ if (name in _this._fieldsList) {
17615
+ delete _this._fieldsList[name];
17616
+ delete _this._formData[name];
17617
+ }
17618
+ };
17619
+ };
17663
17620
 
17664
- if (child) {
17665
- invokeCallback(settled, child, callback, detail);
17666
- } else {
17667
- callback(detail);
17668
- }
17669
- }
17621
+ this.setInitialValues = function (initVal) {
17622
+ _this._initialValues = __assign$3({}, initVal || {});
17670
17623
 
17671
- promise._subscribers.length = 0;
17672
- }
17624
+ _this.setFieldsValue(initVal);
17625
+ };
17673
17626
 
17674
- function invokeCallback(settled, promise, callback, detail) {
17675
- var hasCallback = isFunction(callback),
17676
- value = void 0,
17677
- error = void 0,
17678
- succeeded = true;
17627
+ this.resetFields = function () {
17628
+ _this.setFieldsValue(_this._initialValues);
17629
+ };
17679
17630
 
17680
- if (hasCallback) {
17681
- try {
17682
- value = callback(detail);
17683
- } catch (e) {
17684
- succeeded = false;
17685
- error = e;
17686
- }
17631
+ this.validateFields = function () {
17632
+ var promiseList = [];
17633
+ Object.values(_this._fieldsList).forEach(function (entity) {
17634
+ var promise = entity.validateField();
17635
+ promiseList.push(promise.then(function (errors) {
17636
+ return errors;
17637
+ }));
17638
+ });
17639
+ var summaryPromise = new es6Promise.Promise(function (resolve, reject) {
17640
+ es6Promise.Promise.all(promiseList).then(function (res) {
17641
+ var errorResults = res.filter(function (item) {
17642
+ var _a;
17687
17643
 
17688
- if (promise === value) {
17689
- reject(promise, cannotReturnOwn());
17690
- return;
17691
- }
17692
- } else {
17693
- value = detail;
17694
- }
17644
+ return (_a = item === null || item === void 0 ? void 0 : item.errors) === null || _a === void 0 ? void 0 : _a.length;
17645
+ });
17695
17646
 
17696
- if (promise._state !== PENDING) ; else if (hasCallback && succeeded) {
17697
- resolve(promise, value);
17698
- } else if (succeeded === false) {
17699
- reject(promise, error);
17700
- } else if (settled === FULFILLED) {
17701
- fulfill(promise, value);
17702
- } else if (settled === REJECTED) {
17703
- reject(promise, value);
17704
- }
17705
- }
17647
+ if (errorResults.length) {
17648
+ reject(errorResults);
17649
+ } else {
17650
+ resolve(res);
17651
+ }
17652
+ });
17653
+ });
17654
+ return summaryPromise;
17655
+ };
17706
17656
 
17707
- function initializePromise(promise, resolver) {
17708
- try {
17709
- resolver(function resolvePromise(value) {
17710
- resolve(promise, value);
17711
- }, function rejectPromise(reason) {
17712
- reject(promise, reason);
17713
- });
17714
- } catch (e) {
17715
- reject(promise, e);
17716
- }
17717
- }
17657
+ this.submit = function () {
17658
+ _this.validateFields().then(function (result) {
17659
+ var onSubmit = _this._callbacks.onSubmit;
17660
+ onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(_this._formData, result);
17661
+ }).catch(function (e) {
17662
+ var onSubmitFailed = _this._callbacks.onSubmitFailed;
17718
17663
 
17719
- var id = 0;
17720
- function nextId() {
17721
- return id++;
17722
- }
17664
+ if (!onSubmitFailed) {
17665
+ return;
17666
+ }
17723
17667
 
17724
- function makePromise(promise) {
17725
- promise[PROMISE_ID] = id++;
17726
- promise._state = undefined;
17727
- promise._result = undefined;
17728
- promise._subscribers = [];
17729
- }
17668
+ onSubmitFailed(_this._formData, e);
17669
+ });
17670
+ };
17730
17671
 
17731
- function validationError() {
17732
- return new Error('Array Methods must be provided an Array');
17733
- }
17672
+ this.setCallbacks = function (callbacks) {
17673
+ _this._callbacks = callbacks;
17674
+ };
17734
17675
 
17735
- var Enumerator = function () {
17736
- function Enumerator(Constructor, input) {
17737
- this._instanceConstructor = Constructor;
17738
- this.promise = new Constructor(noop);
17676
+ this.getMethods = function () {
17677
+ return {
17678
+ setFieldsValue: _this.setFieldsValue,
17679
+ setFieldValue: _this.setFieldValue,
17680
+ getFieldsValue: _this.getFieldsValue,
17681
+ getFieldValue: _this.getFieldValue,
17682
+ getFieldError: _this.getFieldError,
17683
+ getFieldsError: _this.getFieldsError,
17684
+ isFieldTouched: _this.isFieldTouched,
17685
+ registerField: _this.registerField,
17686
+ resetFields: _this.resetFields,
17687
+ submit: _this.submit,
17688
+ getInternalHooks: _this.getInternalHooks,
17689
+ validateFields: _this.validateFields
17690
+ };
17691
+ };
17739
17692
 
17740
- if (!this.promise[PROMISE_ID]) {
17741
- makePromise(this.promise);
17742
- }
17693
+ this.getInternalHooks = function () {
17694
+ return {
17695
+ registerField: _this.registerField,
17696
+ setInitialValues: _this.setInitialValues,
17697
+ setCallbacks: _this.setCallbacks
17698
+ };
17699
+ };
17700
+ }
17743
17701
 
17744
- if (isArray(input)) {
17745
- this.length = input.length;
17746
- this._remaining = input.length;
17702
+ return FormData;
17703
+ }();
17747
17704
 
17748
- this._result = new Array(this.length);
17705
+ function useForm(form) {
17706
+ var formInstanceRef = React.useRef(defaultFormDataMethods);
17707
+ var isSingletonRef = React.useRef(false);
17749
17708
 
17750
- if (this.length === 0) {
17751
- fulfill(this.promise, this._result);
17752
- } else {
17753
- this.length = this.length || 0;
17754
- this._enumerate(input);
17755
- if (this._remaining === 0) {
17756
- fulfill(this.promise, this._result);
17757
- }
17758
- }
17709
+ if (!isSingletonRef.current) {
17710
+ if (form) {
17711
+ formInstanceRef.current = form;
17759
17712
  } else {
17760
- reject(this.promise, validationError());
17713
+ var formIns = new FormData();
17714
+ formInstanceRef.current = formIns.getMethods();
17761
17715
  }
17716
+
17717
+ isSingletonRef.current = true;
17762
17718
  }
17763
17719
 
17764
- Enumerator.prototype._enumerate = function _enumerate(input) {
17765
- for (var i = 0; this._state === PENDING && i < input.length; i++) {
17766
- this._eachEntry(input[i], i);
17767
- }
17768
- };
17720
+ return [formInstanceRef.current];
17721
+ }
17769
17722
 
17770
- Enumerator.prototype._eachEntry = function _eachEntry(entry, i) {
17771
- var c = this._instanceConstructor;
17772
- var resolve$$1 = c.resolve;
17723
+ var FormItemContext = /*#__PURE__*/React__default["default"].createContext({
17724
+ form: defaultFormDataMethods,
17725
+ layout: 'horizontal'
17726
+ });
17773
17727
 
17728
+ // 注意:自动识别form关联组件的依据,请勿轻易改变代码结构
17729
+ // Notice: Automatically identify the basis of the associated component of the form, DO NOT change the code structure.
17730
+ var FormInternalComponentType;
17774
17731
 
17775
- if (resolve$$1 === resolve$1) {
17776
- var _then = void 0;
17777
- var error = void 0;
17778
- var didError = false;
17779
- try {
17780
- _then = entry.then;
17781
- } catch (e) {
17782
- didError = true;
17783
- error = e;
17784
- }
17732
+ (function (FormInternalComponentType) {
17733
+ FormInternalComponentType["Input"] = "Input";
17734
+ FormInternalComponentType["Textarea"] = "Textarea";
17735
+ FormInternalComponentType["Checkbox"] = "Checkbox";
17736
+ FormInternalComponentType["CheckboxGroup"] = "CheckboxGroup";
17737
+ FormInternalComponentType["DatePicker"] = "DatePicker";
17738
+ FormInternalComponentType["Picker"] = "Picker";
17739
+ FormInternalComponentType["Radio"] = "Radio";
17740
+ FormInternalComponentType["RadioGroup"] = "RadioGroup";
17741
+ FormInternalComponentType["Slider"] = "Slider";
17742
+ FormInternalComponentType["Switch"] = "Switch";
17743
+ FormInternalComponentType["ImagePicker"] = "ImagePicker";
17744
+ FormInternalComponentType["Rate"] = "Rate";
17745
+ FormInternalComponentType["Stepper"] = "Stepper";
17746
+ })(FormInternalComponentType || (FormInternalComponentType = {}));
17785
17747
 
17786
- if (_then === then && entry._state !== PENDING) {
17787
- this._settledAt(entry._state, i, entry._result);
17788
- } else if (typeof _then !== 'function') {
17789
- this._remaining--;
17790
- this._result[i] = entry;
17791
- } else if (c === Promise$1) {
17792
- var promise = new c(noop);
17793
- if (didError) {
17794
- reject(promise, error);
17795
- } else {
17796
- handleMaybeThenable(promise, entry, _then);
17797
- }
17798
- this._willSettleAt(promise, i);
17799
- } else {
17800
- this._willSettleAt(new c(function (resolve$$1) {
17801
- return resolve$$1(entry);
17802
- }), i);
17803
- }
17804
- } else {
17805
- this._willSettleAt(resolve$$1(entry), i);
17806
- }
17807
- };
17748
+ var ValidateStatus;
17808
17749
 
17809
- Enumerator.prototype._settledAt = function _settledAt(state, i, value) {
17810
- var promise = this.promise;
17750
+ (function (ValidateStatus) {
17751
+ ValidateStatus["Init"] = "init";
17752
+ ValidateStatus["Error"] = "error";
17753
+ ValidateStatus["Warning"] = "warning";
17754
+ ValidateStatus["Validating"] = "validating";
17755
+ ValidateStatus["Success"] = "success";
17756
+ })(ValidateStatus || (ValidateStatus = {}));
17811
17757
 
17758
+ var isFieldRequired = function isFieldRequired(rules) {
17759
+ if (rules === void 0) {
17760
+ rules = [];
17761
+ }
17812
17762
 
17813
- if (promise._state === PENDING) {
17814
- this._remaining--;
17763
+ return (rules || []).some(function (rule) {
17764
+ return rule === null || rule === void 0 ? void 0 : rule.required;
17765
+ });
17766
+ };
17767
+ var getErrorAndWarnings = function getErrorAndWarnings(result) {
17768
+ var errors = [];
17769
+ var warnings = [];
17770
+ var errorTypes = [];
17771
+ result.map(function (_a) {
17772
+ var _b = _a.message,
17773
+ message = _b === void 0 ? [] : _b,
17774
+ _c = _a.validateLevel,
17775
+ validateLevel = _c === void 0 ? 'error' : _c,
17776
+ resultErrorTypes = _a.errorTypes;
17815
17777
 
17816
- if (state === REJECTED) {
17817
- reject(promise, value);
17818
- } else {
17819
- this._result[i] = value;
17820
- }
17778
+ if (!(message === null || message === void 0 ? void 0 : message.length)) {
17779
+ return;
17821
17780
  }
17822
17781
 
17823
- if (this._remaining === 0) {
17824
- fulfill(promise, this._result);
17782
+ if (validateLevel === 'warning') {
17783
+ warnings = __spreadArrays$1(warnings, message);
17784
+ } else {
17785
+ errors = __spreadArrays$1(errors, message);
17786
+ errorTypes = __spreadArrays$1(errorTypes, resultErrorTypes);
17825
17787
  }
17788
+ });
17789
+ return {
17790
+ warnings: warnings,
17791
+ errors: errors,
17792
+ errorTypes: errorTypes
17826
17793
  };
17794
+ };
17827
17795
 
17828
- Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) {
17829
- var enumerator = this;
17830
-
17831
- subscribe(promise, undefined, function (value) {
17832
- return enumerator._settledAt(FULFILLED, i, value);
17833
- }, function (reason) {
17834
- return enumerator._settledAt(REJECTED, i, reason);
17835
- });
17836
- };
17837
-
17838
- return Enumerator;
17839
- }();
17840
-
17841
- /**
17842
- `Promise.all` accepts an array of promises, and returns a new promise which
17843
- is fulfilled with an array of fulfillment values for the passed promises, or
17844
- rejected with the reason of the first passed promise to be rejected. It casts all
17845
- elements of the passed iterable to promises as it runs this algorithm.
17846
-
17847
- Example:
17796
+ function DefaultPickerLinkedContainer(_a) {
17797
+ var value = _a.value;
17848
17798
 
17849
- ```javascript
17850
- let promise1 = resolve(1);
17851
- let promise2 = resolve(2);
17852
- let promise3 = resolve(3);
17853
- let promises = [ promise1, promise2, promise3 ];
17799
+ var _b = React.useContext(GlobalContext),
17800
+ prefixCls = _b.prefixCls,
17801
+ locale = _b.locale;
17854
17802
 
17855
- Promise.all(promises).then(function(array){
17856
- // The array here would be [ 1, 2, 3 ];
17857
- });
17858
- ```
17803
+ var className = prefixCls + "-form-picker-link-container";
17804
+ return /*#__PURE__*/React__default["default"].createElement("div", {
17805
+ className: className
17806
+ }, value && value.length ? value.join('-') : /*#__PURE__*/React__default["default"].createElement("span", {
17807
+ className: className + "-placeholder"
17808
+ }, locale === null || locale === void 0 ? void 0 : locale.Form.pickerDefaultHint));
17809
+ }
17810
+ function DefaultDatePickerLinkedContainer(_a) {
17811
+ var ts = _a.ts,
17812
+ types = _a.types;
17859
17813
 
17860
- If any of the `promises` given to `all` are rejected, the first promise
17861
- that is rejected will be given as an argument to the returned promises's
17862
- rejection handler. For example:
17814
+ var _b = React.useContext(GlobalContext),
17815
+ prefixCls = _b.prefixCls,
17816
+ locale = _b.locale;
17863
17817
 
17864
- Example:
17818
+ var className = prefixCls + "-form-picker-link-container";
17819
+ var dateTimeStr = React.useMemo(function () {
17820
+ return formatDateTimeStr(ts, types);
17821
+ }, [ts, types]);
17865
17822
 
17866
- ```javascript
17867
- let promise1 = resolve(1);
17868
- let promise2 = reject(new Error("2"));
17869
- let promise3 = reject(new Error("3"));
17870
- let promises = [ promise1, promise2, promise3 ];
17823
+ function formatDateTimeStr(timestamp, itemTypes) {
17824
+ var dateObj = convertTsToDateObj(timestamp);
17825
+ var validDateObj = Object.keys(dateObj).reduce(function (acc, key) {
17826
+ var _a;
17871
17827
 
17872
- Promise.all(promises).then(function(array){
17873
- // Code here never runs because there are rejected promises!
17874
- }, function(error) {
17875
- // error.message === "2"
17876
- });
17877
- ```
17828
+ return __assign$3(__assign$3({}, acc), itemTypes.includes(key) ? (_a = {}, _a[key] = formatDateNumber(dateObj[key]), _a) : {});
17829
+ }, {});
17830
+ var dateStr = [validDateObj.year, validDateObj.month, validDateObj.date].filter(function (v) {
17831
+ return v;
17832
+ }).join('-');
17833
+ var timeStr = [validDateObj.hour, validDateObj.minute, validDateObj.second].filter(function (v) {
17834
+ return v;
17835
+ }).join(':');
17836
+ return dateStr + " " + timeStr;
17837
+ }
17878
17838
 
17879
- @method all
17880
- @static
17881
- @param {Array} entries array of promises
17882
- @param {String} label optional string for labeling the promise.
17883
- Useful for tooling.
17884
- @return {Promise} promise that is fulfilled when all `promises` have been
17885
- fulfilled, or rejected if any of them become rejected.
17886
- @static
17887
- */
17888
- function all(entries) {
17889
- return new Enumerator(this, entries).promise;
17839
+ return /*#__PURE__*/React__default["default"].createElement("div", {
17840
+ className: className
17841
+ }, ts ? dateTimeStr : /*#__PURE__*/React__default["default"].createElement("span", {
17842
+ className: className + "-placeholder"
17843
+ }, locale === null || locale === void 0 ? void 0 : locale.Form.pickerDefaultHint));
17890
17844
  }
17891
17845
 
17892
- /**
17893
- `Promise.race` returns a new promise which is settled in the same way as the
17894
- first passed promise to settle.
17846
+ var FormItemInner =
17847
+ /** @class */
17848
+ function (_super) {
17849
+ __extends$1(FormItemInner, _super);
17895
17850
 
17896
- Example:
17851
+ function FormItemInner(props, context) {
17852
+ var _a;
17897
17853
 
17898
- ```javascript
17899
- let promise1 = new Promise(function(resolve, reject){
17900
- setTimeout(function(){
17901
- resolve('promise 1');
17902
- }, 200);
17903
- });
17854
+ var _this = _super.call(this, props) || this;
17904
17855
 
17905
- let promise2 = new Promise(function(resolve, reject){
17906
- setTimeout(function(){
17907
- resolve('promise 2');
17908
- }, 100);
17909
- });
17856
+ _this._errors = [];
17857
+ _this._touched = false;
17910
17858
 
17911
- Promise.race([promise1, promise2]).then(function(result){
17912
- // result === 'promise 2' because it was resolved before promise1
17913
- // was resolved.
17914
- });
17915
- ```
17859
+ _this.onValueChange = function (curValue, preValue) {
17860
+ _this._touched = true;
17861
+ var shouldUpdate = _this.props.shouldUpdate;
17916
17862
 
17917
- `Promise.race` is deterministic in that only the state of the first
17918
- settled promise matters. For example, even if other promises given to the
17919
- `promises` array argument are resolved, but the first settled promise has
17920
- become rejected before the other promises became fulfilled, the returned
17921
- promise will become rejected:
17863
+ if (typeof shouldUpdate === 'function') {
17864
+ shouldUpdate({
17865
+ preValue: preValue,
17866
+ curValue: curValue
17867
+ }) && _this.forceUpdate();
17868
+ return;
17869
+ }
17922
17870
 
17923
- ```javascript
17924
- let promise1 = new Promise(function(resolve, reject){
17925
- setTimeout(function(){
17926
- resolve('promise 1');
17927
- }, 200);
17928
- });
17871
+ _this.forceUpdate();
17872
+ };
17929
17873
 
17930
- let promise2 = new Promise(function(resolve, reject){
17931
- setTimeout(function(){
17932
- reject(new Error('promise 2'));
17933
- }, 100);
17934
- });
17874
+ _this.getFieldError = function () {
17875
+ return _this._errors;
17876
+ };
17935
17877
 
17936
- Promise.race([promise1, promise2]).then(function(result){
17937
- // Code here never runs
17938
- }, function(reason){
17939
- // reason.message === 'promise 2' because promise 2 became rejected before
17940
- // promise 1 became fulfilled
17941
- });
17942
- ```
17878
+ _this.isFieldTouched = function () {
17879
+ return _this._touched;
17880
+ };
17943
17881
 
17944
- An example real-world use case is implementing timeouts:
17882
+ _this.validateField = function () {
17883
+ var _a;
17945
17884
 
17946
- ```javascript
17947
- Promise.race([ajax('foo.json'), timeout(5000)])
17948
- ```
17885
+ var validateMessages = _this.context.validateMessages;
17886
+ var getFieldValue = _this.context.form.getFieldValue;
17887
+ var _b = _this.props,
17888
+ field = _b.field,
17889
+ rules = _b.rules,
17890
+ onValidateStatusChange = _b.onValidateStatusChange;
17891
+ var value = getFieldValue(field);
17949
17892
 
17950
- @method race
17951
- @static
17952
- @param {Array} promises array of promises to observe
17953
- Useful for tooling.
17954
- @return {Promise} a promise which settles in the same way as the first passed
17955
- promise to settle.
17956
- */
17957
- function race(entries) {
17958
- /*jshint validthis:true */
17959
- var Constructor = this;
17893
+ if ((rules === null || rules === void 0 ? void 0 : rules.length) && field) {
17894
+ var fieldDom_1 = _this.props.getFormItemRef();
17960
17895
 
17961
- if (!isArray(entries)) {
17962
- return new Constructor(function (_, reject) {
17963
- return reject(new TypeError('You must pass an array to race.'));
17964
- });
17965
- } else {
17966
- return new Constructor(function (resolve, reject) {
17967
- var length = entries.length;
17968
- for (var i = 0; i < length; i++) {
17969
- Constructor.resolve(entries[i]).then(resolve, reject);
17970
- }
17971
- });
17972
- }
17973
- }
17896
+ var fieldValidator_1 = new Validator((_a = {}, _a[field] = rules, _a), {
17897
+ validateMessages: validateMessages
17898
+ });
17899
+ return new es6Promise.Promise(function (resolve) {
17900
+ var _a;
17974
17901
 
17975
- /**
17976
- `Promise.reject` returns a promise rejected with the passed `reason`.
17977
- It is shorthand for the following:
17902
+ fieldValidator_1.validate((_a = {}, _a[field] = value, _a), function (errorsMap) {
17903
+ var _a = getErrorAndWarnings((errorsMap === null || errorsMap === void 0 ? void 0 : errorsMap[field]) || []),
17904
+ errors = _a.errors,
17905
+ warnings = _a.warnings,
17906
+ errorTypes = _a.errorTypes;
17978
17907
 
17979
- ```javascript
17980
- let promise = new Promise(function(resolve, reject){
17981
- reject(new Error('WHOOPS'));
17982
- });
17908
+ _this._errors = errors;
17909
+ onValidateStatusChange({
17910
+ errors: _this._errors,
17911
+ warnings: warnings,
17912
+ errorTypes: errorTypes
17913
+ });
17914
+ return resolve({
17915
+ errors: _this._errors,
17916
+ warnings: warnings,
17917
+ value: value,
17918
+ field: field,
17919
+ dom: fieldDom_1
17920
+ });
17921
+ });
17922
+ });
17923
+ }
17983
17924
 
17984
- promise.then(function(value){
17985
- // Code here doesn't run because the promise is rejected!
17986
- }, function(reason){
17987
- // reason.message === 'WHOOPS'
17988
- });
17989
- ```
17925
+ return es6Promise.Promise.resolve({
17926
+ errors: [],
17927
+ warnings: [],
17928
+ value: value,
17929
+ field: field,
17930
+ dom: null
17931
+ });
17932
+ };
17990
17933
 
17991
- Instead of writing the above, your code now simply becomes the following:
17934
+ _this.setFieldData = function (value) {
17935
+ var field = _this.props.field;
17936
+ var setFieldValue = _this.context.form.setFieldValue;
17937
+ setFieldValue(field, value);
17992
17938
 
17993
- ```javascript
17994
- let promise = Promise.reject(new Error('WHOOPS'));
17939
+ _this.validateField();
17940
+ };
17995
17941
 
17996
- promise.then(function(value){
17997
- // Code here doesn't run because the promise is rejected!
17998
- }, function(reason){
17999
- // reason.message === 'WHOOPS'
18000
- });
18001
- ```
17942
+ _this.innerTriggerFunction = function (_, value) {
17943
+ var _a, _b;
18002
17944
 
18003
- @method reject
18004
- @static
18005
- @param {Any} reason value that the returned promise will be rejected with.
18006
- Useful for tooling.
18007
- @return {Promise} a promise rejected with the given `reason`.
18008
- */
18009
- function reject$1(reason) {
18010
- /*jshint validthis:true */
18011
- var Constructor = this;
18012
- var promise = new Constructor(noop);
18013
- reject(promise, reason);
18014
- return promise;
18015
- }
17945
+ var args = [];
18016
17946
 
18017
- function needsResolver() {
18018
- throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
18019
- }
17947
+ for (var _i = 2; _i < arguments.length; _i++) {
17948
+ args[_i - 2] = arguments[_i];
17949
+ }
18020
17950
 
18021
- function needsNew() {
18022
- throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
18023
- }
17951
+ _this.setFieldData(value);
18024
17952
 
18025
- /**
18026
- Promise objects represent the eventual result of an asynchronous operation. The
18027
- primary way of interacting with a promise is through its `then` method, which
18028
- registers callbacks to receive either a promise's eventual value or the reason
18029
- why the promise cannot be fulfilled.
17953
+ var _c = _this.props,
17954
+ children = _c.children,
17955
+ _d = _c.trigger,
17956
+ trigger = _d === void 0 ? 'onChange' : _d;
18030
17957
 
18031
- Terminology
18032
- -----------
17958
+ if (trigger && ((_a = children.props) === null || _a === void 0 ? void 0 : _a[trigger])) {
17959
+ (_b = children.props) === null || _b === void 0 ? void 0 : _b[trigger].apply(_b, __spreadArrays$1([_, value], args));
17960
+ }
17961
+ };
18033
17962
 
18034
- - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
18035
- - `thenable` is an object or function that defines a `then` method.
18036
- - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
18037
- - `exception` is a value that is thrown using the throw statement.
18038
- - `reason` is a value that indicates why a promise was rejected.
18039
- - `settled` the final resting state of a promise, fulfilled or rejected.
17963
+ _this.innerTriggerFunctionWithValueFirst = function (value) {
17964
+ var _a, _b;
18040
17965
 
18041
- A promise can be in one of three states: pending, fulfilled, or rejected.
17966
+ var args = [];
18042
17967
 
18043
- Promises that are fulfilled have a fulfillment value and are in the fulfilled
18044
- state. Promises that are rejected have a rejection reason and are in the
18045
- rejected state. A fulfillment value is never a thenable.
17968
+ for (var _i = 1; _i < arguments.length; _i++) {
17969
+ args[_i - 1] = arguments[_i];
17970
+ }
18046
17971
 
18047
- Promises can also be said to *resolve* a value. If this value is also a
18048
- promise, then the original promise's settled state will match the value's
18049
- settled state. So a promise that *resolves* a promise that rejects will
18050
- itself reject, and a promise that *resolves* a promise that fulfills will
18051
- itself fulfill.
17972
+ _this.setFieldData(value);
18052
17973
 
17974
+ var _c = _this.props,
17975
+ children = _c.children,
17976
+ _d = _c.trigger,
17977
+ trigger = _d === void 0 ? 'onChange' : _d;
18053
17978
 
18054
- Basic Usage:
18055
- ------------
17979
+ if (trigger && ((_a = children.props) === null || _a === void 0 ? void 0 : _a[trigger])) {
17980
+ (_b = children.props) === null || _b === void 0 ? void 0 : _b[trigger].apply(_b, __spreadArrays$1([value], args));
17981
+ }
17982
+ };
18056
17983
 
18057
- ```js
18058
- let promise = new Promise(function(resolve, reject) {
18059
- // on success
18060
- resolve(value);
17984
+ _this.innerClearFunction = function () {
17985
+ var _a, _b;
18061
17986
 
18062
- // on failure
18063
- reject(reason);
18064
- });
17987
+ var args = [];
18065
17988
 
18066
- promise.then(function(value) {
18067
- // on fulfillment
18068
- }, function(reason) {
18069
- // on rejection
18070
- });
18071
- ```
17989
+ for (var _i = 0; _i < arguments.length; _i++) {
17990
+ args[_i] = arguments[_i];
17991
+ }
18072
17992
 
18073
- Advanced Usage:
18074
- ---------------
17993
+ var children = _this.props.children;
18075
17994
 
18076
- Promises shine when abstracting away asynchronous interactions such as
18077
- `XMLHttpRequest`s.
17995
+ _this.setFieldData('');
18078
17996
 
18079
- ```js
18080
- function getJSON(url) {
18081
- return new Promise(function(resolve, reject){
18082
- let xhr = new XMLHttpRequest();
17997
+ if ((_a = children.props) === null || _a === void 0 ? void 0 : _a.onClear) {
17998
+ (_b = children.props) === null || _b === void 0 ? void 0 : _b.onClear.apply(_b, args);
17999
+ }
18000
+ };
18083
18001
 
18084
- xhr.open('GET', url);
18085
- xhr.onreadystatechange = handler;
18086
- xhr.responseType = 'json';
18087
- xhr.setRequestHeader('Accept', 'application/json');
18088
- xhr.send();
18002
+ _this.destroyField = function () {};
18089
18003
 
18090
- function handler() {
18091
- if (this.readyState === this.DONE) {
18092
- if (this.status === 200) {
18093
- resolve(this.response);
18094
- } else {
18095
- reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
18096
- }
18097
- }
18098
- };
18099
- });
18100
- }
18004
+ if ((props === null || props === void 0 ? void 0 : props.initialValue) && props.field) {
18005
+ var setInitialValues = context.form.getInternalHooks().setInitialValues;
18006
+ setInitialValues((_a = {}, _a[props.field] = props.initialValue, _a));
18007
+ }
18101
18008
 
18102
- getJSON('/posts.json').then(function(json) {
18103
- // on fulfillment
18104
- }, function(reason) {
18105
- // on rejection
18106
- });
18107
- ```
18009
+ return _this;
18010
+ }
18108
18011
 
18109
- Unlike callbacks, promises are great composable primitives.
18012
+ FormItemInner.prototype.componentDidMount = function () {
18013
+ var registerField = this.context.form.getInternalHooks().registerField;
18014
+ this.destroyField = registerField(this.props.field, this);
18015
+ };
18110
18016
 
18111
- ```js
18112
- Promise.all([
18113
- getJSON('/posts'),
18114
- getJSON('/comments')
18115
- ]).then(function(values){
18116
- values[0] // => postsJSON
18117
- values[1] // => commentsJSON
18017
+ FormItemInner.prototype.componentWillUnmount = function () {
18018
+ this.destroyField();
18019
+ };
18118
18020
 
18119
- return values;
18120
- });
18121
- ```
18021
+ FormItemInner.prototype.renderChildren = function () {
18022
+ var _a;
18122
18023
 
18123
- @class Promise
18124
- @param {Function} resolver
18125
- Useful for tooling.
18126
- @constructor
18127
- */
18024
+ var _this = this;
18128
18025
 
18129
- var Promise$1 = function () {
18130
- function Promise(resolver) {
18131
- this[PROMISE_ID] = nextId();
18132
- this._result = this._state = undefined;
18133
- this._subscribers = [];
18026
+ var _b, _c, _d;
18134
18027
 
18135
- if (noop !== resolver) {
18136
- typeof resolver !== 'function' && needsResolver();
18137
- this instanceof Promise ? initializePromise(this, resolver) : needsNew();
18138
- }
18139
- }
18028
+ var _e = this.props,
18029
+ children = _e.children,
18030
+ field = _e.field,
18031
+ _f = _e.trigger,
18032
+ trigger = _f === void 0 ? 'onChange' : _f,
18033
+ _g = _e.triggerPropsField,
18034
+ triggerPropsField = _g === void 0 ? 'value' : _g,
18035
+ displayType = _e.displayType;
18036
+ var getFieldValue = this.context.form.getFieldValue;
18037
+ var props = (_a = {}, _a[triggerPropsField] = getFieldValue(field), _a.disabled = this.props.disabled, _a);
18038
+ var childrenType = displayType || ((_b = children.type) === null || _b === void 0 ? void 0 : _b.displayName);
18140
18039
 
18141
- /**
18142
- The primary way of interacting with a promise is through its `then` method,
18143
- which registers callbacks to receive either a promise's eventual value or the
18144
- reason why the promise cannot be fulfilled.
18145
- ```js
18146
- findUser().then(function(user){
18147
- // user is available
18148
- }, function(reason){
18149
- // user is unavailable, and you are given the reason why
18150
- });
18151
- ```
18152
- Chaining
18153
- --------
18154
- The return value of `then` is itself a promise. This second, 'downstream'
18155
- promise is resolved with the return value of the first promise's fulfillment
18156
- or rejection handler, or rejected if the handler throws an exception.
18157
- ```js
18158
- findUser().then(function (user) {
18159
- return user.name;
18160
- }, function (reason) {
18161
- return 'default name';
18162
- }).then(function (userName) {
18163
- // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
18164
- // will be `'default name'`
18165
- });
18166
- findUser().then(function (user) {
18167
- throw new Error('Found user, but still unhappy');
18168
- }, function (reason) {
18169
- throw new Error('`findUser` rejected and we're unhappy');
18170
- }).then(function (value) {
18171
- // never reached
18172
- }, function (reason) {
18173
- // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
18174
- // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
18175
- });
18176
- ```
18177
- If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
18178
- ```js
18179
- findUser().then(function (user) {
18180
- throw new PedagogicalException('Upstream error');
18181
- }).then(function (value) {
18182
- // never reached
18183
- }).then(function (value) {
18184
- // never reached
18185
- }, function (reason) {
18186
- // The `PedgagocialException` is propagated all the way down to here
18187
- });
18188
- ```
18189
- Assimilation
18190
- ------------
18191
- Sometimes the value you want to propagate to a downstream promise can only be
18192
- retrieved asynchronously. This can be achieved by returning a promise in the
18193
- fulfillment or rejection handler. The downstream promise will then be pending
18194
- until the returned promise is settled. This is called *assimilation*.
18195
- ```js
18196
- findUser().then(function (user) {
18197
- return findCommentsByAuthor(user);
18198
- }).then(function (comments) {
18199
- // The user's comments are now available
18200
- });
18201
- ```
18202
- If the assimliated promise rejects, then the downstream promise will also reject.
18203
- ```js
18204
- findUser().then(function (user) {
18205
- return findCommentsByAuthor(user);
18206
- }).then(function (comments) {
18207
- // If `findCommentsByAuthor` fulfills, we'll have the value here
18208
- }, function (reason) {
18209
- // If `findCommentsByAuthor` rejects, we'll have the reason here
18210
- });
18211
- ```
18212
- Simple Example
18213
- --------------
18214
- Synchronous Example
18215
- ```javascript
18216
- let result;
18217
- try {
18218
- result = findResult();
18219
- // success
18220
- } catch(reason) {
18221
- // failure
18222
- }
18223
- ```
18224
- Errback Example
18225
- ```js
18226
- findResult(function(result, err){
18227
- if (err) {
18228
- // failure
18229
- } else {
18230
- // success
18231
- }
18232
- });
18233
- ```
18234
- Promise Example;
18235
- ```javascript
18236
- findResult().then(function(result){
18237
- // success
18238
- }, function(reason){
18239
- // failure
18240
- });
18241
- ```
18242
- Advanced Example
18243
- --------------
18244
- Synchronous Example
18245
- ```javascript
18246
- let author, books;
18247
- try {
18248
- author = findAuthor();
18249
- books = findBooksByAuthor(author);
18250
- // success
18251
- } catch(reason) {
18252
- // failure
18253
- }
18254
- ```
18255
- Errback Example
18256
- ```js
18257
- function foundBooks(books) {
18258
- }
18259
- function failure(reason) {
18260
- }
18261
- findAuthor(function(author, err){
18262
- if (err) {
18263
- failure(err);
18264
- // failure
18265
- } else {
18266
- try {
18267
- findBoooksByAuthor(author, function(books, err) {
18268
- if (err) {
18269
- failure(err);
18270
- } else {
18271
- try {
18272
- foundBooks(books);
18273
- } catch(reason) {
18274
- failure(reason);
18275
- }
18040
+ switch (childrenType) {
18041
+ case FormInternalComponentType.Input:
18042
+ case FormInternalComponentType.Textarea:
18043
+ props = {
18044
+ value: getFieldValue(field) || '',
18045
+ onInput: this.innerTriggerFunction,
18046
+ onClear: this.innerClearFunction,
18047
+ disabled: this.props.disabled
18048
+ };
18049
+ break;
18050
+
18051
+ case FormInternalComponentType.Checkbox:
18052
+ case FormInternalComponentType.Radio:
18053
+ case FormInternalComponentType.Slider:
18054
+ case FormInternalComponentType.RadioGroup:
18055
+ case FormInternalComponentType.CheckboxGroup:
18056
+ props = {
18057
+ value: getFieldValue(field),
18058
+ onChange: this.innerTriggerFunctionWithValueFirst,
18059
+ disabled: this.props.disabled
18060
+ };
18061
+ break;
18062
+
18063
+ case FormInternalComponentType.DatePicker:
18064
+ props = {
18065
+ currentTs: getFieldValue(field),
18066
+ onChange: this.innerTriggerFunctionWithValueFirst,
18067
+ disabled: this.props.disabled,
18068
+ renderLinkedContainer: ((_c = children.props) === null || _c === void 0 ? void 0 : _c.renderLinkedContainer) || function (ts, types) {
18069
+ return /*#__PURE__*/React__default["default"].createElement(DefaultDatePickerLinkedContainer, {
18070
+ ts: ts,
18071
+ types: types
18072
+ });
18276
18073
  }
18277
- });
18278
- } catch(error) {
18279
- failure(err);
18280
- }
18281
- // success
18074
+ };
18075
+ break;
18076
+
18077
+ case FormInternalComponentType.Picker:
18078
+ props = {
18079
+ value: getFieldValue(field),
18080
+ onChange: this.innerTriggerFunctionWithValueFirst,
18081
+ disabled: this.props.disabled,
18082
+ renderLinkedContainer: ((_d = children.props) === null || _d === void 0 ? void 0 : _d.renderLinkedContainer) || function (val) {
18083
+ return /*#__PURE__*/React__default["default"].createElement(DefaultPickerLinkedContainer, {
18084
+ value: val
18085
+ });
18086
+ }
18087
+ };
18088
+ break;
18089
+
18090
+ case FormInternalComponentType.Switch:
18091
+ props = {
18092
+ checked: Boolean(getFieldValue(field)),
18093
+ onChange: this.innerTriggerFunctionWithValueFirst,
18094
+ disabled: this.props.disabled
18095
+ };
18096
+ break;
18097
+
18098
+ case FormInternalComponentType.ImagePicker:
18099
+ props = {
18100
+ images: getFieldValue(field),
18101
+ onChange: this.innerTriggerFunctionWithValueFirst,
18102
+ disabled: this.props.disabled
18103
+ };
18104
+ break;
18105
+
18106
+ default:
18107
+ var originTrigger_1 = children.props[trigger]; // inject the validated result
18108
+
18109
+ props.error = this._errors;
18110
+
18111
+ props[trigger] = function (newValue) {
18112
+ var args = [];
18113
+
18114
+ for (var _i = 1; _i < arguments.length; _i++) {
18115
+ args[_i - 1] = arguments[_i];
18116
+ }
18117
+
18118
+ _this.setFieldData(newValue);
18119
+
18120
+ originTrigger_1 && originTrigger_1.apply(void 0, __spreadArrays$1([newValue], args));
18121
+ };
18122
+
18282
18123
  }
18283
- });
18284
- ```
18285
- Promise Example;
18286
- ```javascript
18287
- findAuthor().
18288
- then(findBooksByAuthor).
18289
- then(function(books){
18290
- // found books
18291
- }).catch(function(reason){
18292
- // something went wrong
18293
- });
18294
- ```
18295
- @method then
18296
- @param {Function} onFulfilled
18297
- @param {Function} onRejected
18298
- Useful for tooling.
18299
- @return {Promise}
18300
- */
18301
18124
 
18302
- /**
18303
- `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
18304
- as the catch block of a try/catch statement.
18305
- ```js
18306
- function findAuthor(){
18307
- throw new Error('couldn't find that author');
18308
- }
18309
- // synchronous
18310
- try {
18311
- findAuthor();
18312
- } catch(reason) {
18313
- // something went wrong
18314
- }
18315
- // async with promises
18316
- findAuthor().catch(function(reason){
18317
- // something went wrong
18318
- });
18319
- ```
18320
- @method catch
18321
- @param {Function} onRejection
18322
- Useful for tooling.
18323
- @return {Promise}
18324
- */
18125
+ return /*#__PURE__*/React__default["default"].cloneElement(children, props);
18126
+ };
18127
+
18128
+ FormItemInner.prototype.render = function () {
18129
+ return this.renderChildren();
18130
+ };
18325
18131
 
18132
+ return FormItemInner;
18133
+ }(React.PureComponent);
18326
18134
 
18327
- Promise.prototype.catch = function _catch(onRejection) {
18328
- return this.then(null, onRejection);
18135
+ FormItemInner.contextType = FormItemContext;
18136
+ var Item$1 = /*#__PURE__*/React.forwardRef(function (props, ref) {
18137
+ var _a;
18138
+
18139
+ var label = props.label,
18140
+ field = props.field,
18141
+ _b = props.disabled,
18142
+ disabled = _b === void 0 ? false : _b,
18143
+ itemLayout = props.layout,
18144
+ style = props.style,
18145
+ extra = props.extra,
18146
+ requiredIcon = props.requiredIcon,
18147
+ rules = props.rules,
18148
+ _c = props.className,
18149
+ className = _c === void 0 ? '' : _c,
18150
+ rest = __rest$1(props, ["label", "field", "disabled", "layout", "style", "extra", "requiredIcon", "rules", "className"]);
18151
+
18152
+ var prefixCls = React.useContext(GlobalContext).prefixCls;
18153
+
18154
+ var _d = React.useContext(FormItemContext),
18155
+ layout = _d.layout,
18156
+ propsDisabled = _d.disabled;
18157
+
18158
+ var _e = React.useState(null),
18159
+ errors = _e[0],
18160
+ setErrors = _e[1];
18161
+
18162
+ var _f = React.useState(null),
18163
+ errorTypes = _f[0],
18164
+ setErrorTypes = _f[1];
18165
+
18166
+ var _g = React.useState([]),
18167
+ warnings = _g[0],
18168
+ setWarnings = _g[1];
18169
+
18170
+ var formItemRef = React.useRef(null);
18171
+
18172
+ var onValidateStatusChange = function onValidateStatusChange(validateResult) {
18173
+ var _errors = validateResult.errors,
18174
+ _warnings = validateResult.warnings,
18175
+ _errorTypes = validateResult.errorTypes;
18176
+ setErrors(_errors.length ? _errors[0] : null);
18177
+ setErrorTypes(_errorTypes.length ? _errorTypes[0] : null);
18178
+ setWarnings(_warnings);
18329
18179
  };
18330
18180
 
18331
- /**
18332
- `finally` will be invoked regardless of the promise's fate just as native
18333
- try/catch/finally behaves
18334
-
18335
- Synchronous example:
18336
-
18337
- ```js
18338
- findAuthor() {
18339
- if (Math.random() > 0.5) {
18340
- throw new Error();
18341
- }
18342
- return new Author();
18343
- }
18344
-
18345
- try {
18346
- return findAuthor(); // succeed or fail
18347
- } catch(error) {
18348
- return findOtherAuther();
18349
- } finally {
18350
- // always runs
18351
- // doesn't affect the return value
18352
- }
18353
- ```
18354
-
18355
- Asynchronous example:
18356
-
18357
- ```js
18358
- findAuthor().catch(function(reason){
18359
- return findOtherAuther();
18360
- }).finally(function(){
18361
- // author was either found, or not
18362
- });
18363
- ```
18364
-
18365
- @method finally
18366
- @param {Function} callback
18367
- @return {Promise}
18368
- */
18181
+ var getFormItemRef = function getFormItemRef() {
18182
+ return formItemRef.current;
18183
+ };
18184
+
18185
+ var fieldDisabled = disabled || propsDisabled;
18186
+ var fieldRules = (rest === null || rest === void 0 ? void 0 : rest.required) ? __spreadArrays$1([{
18187
+ type: ValidatorType.String,
18188
+ required: true
18189
+ }], rules || []) : rules;
18190
+ var isRequired = isFieldRequired(rules) || (rest === null || rest === void 0 ? void 0 : rest.required);
18191
+ React.useImperativeHandle(ref, function () {
18192
+ return {
18193
+ dom: formItemRef.current
18194
+ };
18195
+ });
18196
+ return /*#__PURE__*/React__default["default"].createElement("div", {
18197
+ className: cls(prefixCls + "-form-item", prefixCls + "-form-item-" + (itemLayout || layout), className, (_a = {
18198
+ disabled: fieldDisabled
18199
+ }, _a[prefixCls + "-form-item-error"] = !!errors, _a[prefixCls + "-form-item-warning"] = Boolean(!errors && warnings), _a[prefixCls + "-form-item-error-" + errorTypes] = errorTypes, _a)),
18200
+ style: style,
18201
+ ref: formItemRef
18202
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
18203
+ className: cls(prefixCls + "-form-label-item")
18204
+ }, isRequired ? requiredIcon || /*#__PURE__*/React__default["default"].createElement("span", {
18205
+ className: cls(prefixCls + "-form-label-item-required-asterisk")
18206
+ }, "*") : null, label), /*#__PURE__*/React__default["default"].createElement("div", {
18207
+ className: cls(prefixCls + "-form-item-control-wrapper")
18208
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
18209
+ className: cls(prefixCls + "-form-item-control")
18210
+ }, /*#__PURE__*/React__default["default"].createElement(FormItemInner, __assign$3({}, rest, {
18211
+ rules: fieldRules,
18212
+ disabled: fieldDisabled,
18213
+ field: field,
18214
+ onValidateStatusChange: onValidateStatusChange,
18215
+ getFormItemRef: getFormItemRef
18216
+ }))), errors && /*#__PURE__*/React__default["default"].createElement("div", {
18217
+ className: cls(prefixCls + "-form-item-message " + prefixCls + "-form-item-error-message")
18218
+ }, errors), (warnings || []).map(function (node, key) {
18219
+ return typeof node === 'string' ? /*#__PURE__*/React__default["default"].createElement("div", {
18220
+ className: cls(prefixCls + "-form-item-message " + prefixCls + "-form-item-warning-message"),
18221
+ key: key
18222
+ }, node) : node;
18223
+ })), extra);
18224
+ });
18369
18225
 
18226
+ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
18227
+ var _a = props.className,
18228
+ className = _a === void 0 ? '' : _a,
18229
+ style = props.style,
18230
+ _b = props.layout,
18231
+ layout = _b === void 0 ? 'horizontal' : _b,
18232
+ initialValues = props.initialValues,
18233
+ formInstance = props.form,
18234
+ children = props.children,
18235
+ onValuesChange = props.onValuesChange,
18236
+ onSubmit = props.onSubmit,
18237
+ onSubmitFailed = props.onSubmitFailed,
18238
+ disabled = props.disabled;
18239
+ var domRef = React.useRef(null);
18240
+ var initRef = React.useRef(false);
18241
+ var form = useForm(formInstance)[0];
18370
18242
 
18371
- Promise.prototype.finally = function _finally(callback) {
18372
- var promise = this;
18373
- var constructor = promise.constructor;
18243
+ var _c = form.getInternalHooks(),
18244
+ setCallbacks = _c.setCallbacks,
18245
+ setInitialValues = _c.setInitialValues;
18374
18246
 
18375
- if (isFunction(callback)) {
18376
- return promise.then(function (value) {
18377
- return constructor.resolve(callback()).then(function () {
18378
- return value;
18379
- });
18380
- }, function (reason) {
18381
- return constructor.resolve(callback()).then(function () {
18382
- throw reason;
18383
- });
18384
- });
18385
- }
18247
+ setCallbacks({
18248
+ onValuesChange: onValuesChange,
18249
+ onSubmit: onSubmit,
18250
+ onSubmitFailed: onSubmitFailed
18251
+ });
18386
18252
 
18387
- return promise.then(callback, callback);
18253
+ if (!initRef.current) {
18254
+ setInitialValues(initialValues || {});
18255
+ initRef.current = true;
18256
+ }
18257
+
18258
+ React.useImperativeHandle(ref, function () {
18259
+ return {
18260
+ dom: domRef.current,
18261
+ form: form
18262
+ };
18263
+ });
18264
+ var contextValue = {
18265
+ form: form,
18266
+ layout: layout,
18267
+ disabled: disabled
18388
18268
  };
18269
+ return /*#__PURE__*/React__default["default"].createElement(ContextLayout, null, function (_a) {
18270
+ var prefixCls = _a.prefixCls,
18271
+ _b = _a.locale,
18272
+ locale = _b === void 0 ? defaultLocale : _b;
18273
+ return /*#__PURE__*/React__default["default"].createElement("form", {
18274
+ className: prefixCls + "-form " + className,
18275
+ style: style,
18276
+ ref: domRef,
18277
+ onSubmit: function onSubmit(e) {
18278
+ e.preventDefault();
18279
+ e.stopPropagation();
18280
+ form.submit();
18281
+ }
18282
+ }, /*#__PURE__*/React__default["default"].createElement(FormItemContext.Provider, {
18283
+ value: __assign$3(__assign$3({}, contextValue), {
18284
+ validateMessages: (locale === null || locale === void 0 ? void 0 : locale.Form) || {}
18285
+ })
18286
+ }, children));
18287
+ });
18288
+ });
18289
+ /**
18290
+ * 表单组件用于集合数据录入
18291
+ * @en Form, Form for collecting data input
18292
+ * @type 数据录入
18293
+ * @type_en Data Entry
18294
+ * @name 表单
18295
+ * @name_en Form
18296
+ */
18389
18297
 
18390
- return Promise;
18391
- }();
18298
+ var index$i = componentWrapper(Form, {
18299
+ Item: Item$1
18300
+ });
18392
18301
 
18393
- Promise$1.prototype.then = then;
18394
- Promise$1.all = all;
18395
- Promise$1.race = race;
18396
- Promise$1.resolve = resolve$1;
18397
- Promise$1.reject = reject$1;
18398
- Promise$1._setScheduler = setScheduler;
18399
- Promise$1._setAsap = setAsap;
18400
- Promise$1._asap = asap;
18302
+ /**
18303
+ * 宫格可以在水平方向上把页面分隔成等宽度的区块,用于展示内容或进行页面导航。
18304
+ * @en The grid can divide the page into equal-width blocks in the horizontal direction for displaying content or for page navigation.
18305
+ * @type 布局
18306
+ * @type_en Layout
18307
+ * @name 宫格
18308
+ * @name_en Grid
18309
+ */
18401
18310
 
18402
- /*global self*/
18403
- function polyfill() {
18404
- var local = void 0;
18311
+ var Grid = /*#__PURE__*/React.forwardRef(function (props, ref) {
18312
+ var _a = props.className,
18313
+ className = _a === void 0 ? '' : _a,
18314
+ style = props.style,
18315
+ data = props.data,
18316
+ _b = props.columns,
18317
+ columns = _b === void 0 ? 3 : _b,
18318
+ _c = props.border,
18319
+ border = _c === void 0 ? false : _c,
18320
+ _d = props.gutter,
18321
+ gutter = _d === void 0 ? 0 : _d,
18322
+ _e = props.shape,
18323
+ shape = _e === void 0 ? 'square' : _e,
18324
+ _f = props.direction,
18325
+ direction = _f === void 0 ? 'vertical' : _f,
18326
+ _g = props.isSliding,
18327
+ isSliding = _g === void 0 ? false : _g;
18328
+ var useRtl = React.useContext(GlobalContext).useRtl;
18329
+ var domRef = React.useRef(null);
18330
+ React.useImperativeHandle(ref, function () {
18331
+ return {
18332
+ dom: domRef.current
18333
+ };
18334
+ });
18405
18335
 
18406
- if (typeof commonjsGlobal !== 'undefined') {
18407
- local = commonjsGlobal;
18408
- } else if (typeof self !== 'undefined') {
18409
- local = self;
18410
- } else {
18411
- try {
18412
- local = Function('return this')();
18413
- } catch (e) {
18414
- throw new Error('polyfill failed because global object is unavailable in this environment');
18336
+ var getRows = function getRows(prefix, rowsData, rows, row) {
18337
+ var placeholders = !isSliding && rowsData.length % columns;
18338
+ var renderData = rowsData;
18339
+
18340
+ if (placeholders) {
18341
+ var fakeGrids = new Array(columns - placeholders).fill({
18342
+ img: null,
18343
+ title: ''
18344
+ });
18345
+ renderData = rowsData.concat(fakeGrids);
18415
18346
  }
18416
- }
18417
18347
 
18418
- var P = local.Promise;
18348
+ return /*#__PURE__*/React__default["default"].createElement("div", {
18349
+ className: prefix + "-rows",
18350
+ key: row
18351
+ }, renderData.map(function (item, index) {
18352
+ var _a;
18419
18353
 
18420
- if (P) {
18421
- var promiseToString = null;
18422
- try {
18423
- promiseToString = Object.prototype.toString.call(P.resolve());
18424
- } catch (e) {
18425
- // silently ignored
18426
- }
18354
+ var img = item.img,
18355
+ title = item.title,
18356
+ content = item.content,
18357
+ itemClassName = item.className,
18358
+ _onClick = item.onClick,
18359
+ itemStyle = item.itemStyle,
18360
+ renderGrid = item.renderGrid;
18427
18361
 
18428
- if (promiseToString === '[object Promise]' && !P.cast) {
18429
- return;
18430
- }
18431
- }
18362
+ if (renderGrid) {
18363
+ return renderGrid(item, index, row);
18364
+ }
18432
18365
 
18433
- local.Promise = Promise$1;
18434
- }
18366
+ var marginBottom = row + 1 === rows ? 0 : typeof gutter === 'number' ? gutter : (gutter === null || gutter === void 0 ? void 0 : gutter.y) || 0;
18367
+ var rowLen = renderData.length;
18368
+ var marginValue = index + 1 === rowLen ? 0 : typeof gutter === 'number' ? gutter : (gutter === null || gutter === void 0 ? void 0 : gutter.x) || 0;
18369
+ var marginStyle = (_a = {}, _a[useRtl ? 'marginLeft' : 'marginRight'] = marginValue, _a);
18370
+ return /*#__PURE__*/React__default["default"].createElement("div", {
18371
+ key: index,
18372
+ style: __assign$3(__assign$3({
18373
+ marginBottom: marginBottom
18374
+ }, marginStyle), itemStyle),
18375
+ onClick: function onClick() {
18376
+ _onClick && _onClick(item);
18377
+ },
18378
+ className: cls(prefix + "-rows-item", {
18379
+ horizontal: direction === 'horizontal',
18380
+ border: border && gutter === 0
18381
+ }, itemClassName)
18382
+ }, typeof img === 'string' ? /*#__PURE__*/React__default["default"].createElement("img", {
18383
+ src: img,
18384
+ className: prefix + "-rows-item-icon " + (shape === 'circle' ? 'circle' : '')
18385
+ }) : img, title || content ? /*#__PURE__*/React__default["default"].createElement("div", {
18386
+ className: prefix + "-rows-item-text"
18387
+ }, title ? /*#__PURE__*/React__default["default"].createElement("span", {
18388
+ className: prefix + "-rows-item-title"
18389
+ }, title) : null, content ? /*#__PURE__*/React__default["default"].createElement("span", {
18390
+ className: prefix + "-rows-item-content"
18391
+ }, content) : null) : null, (index + 1) % columns !== 0 ? /*#__PURE__*/React__default["default"].createElement("i", {
18392
+ className: "vertical-border"
18393
+ }) : null, (row + 1) % rows !== 0 ? /*#__PURE__*/React__default["default"].createElement("i", {
18394
+ className: "horizontal-border"
18395
+ }) : null);
18396
+ }));
18397
+ };
18435
18398
 
18436
- // Strange compat..
18437
- Promise$1.polyfill = polyfill;
18438
- Promise$1.Promise = Promise$1;
18399
+ var getGrid = function getGrid(prefix, dataArr) {
18400
+ var rows = dataArr.length || 1;
18401
+ return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, dataArr.map(function (item, index) {
18402
+ return getRows(prefix, item, rows, index);
18403
+ }));
18404
+ };
18439
18405
 
18440
- return Promise$1;
18406
+ var renderEl = function renderEl(_a) {
18407
+ var prefixCls = _a.prefixCls;
18408
+ var prefix = prefixCls + "-grid";
18409
+ var dataLength = (data === null || data === void 0 ? void 0 : data.length) || 0;
18441
18410
 
18442
- })));
18411
+ if (dataLength === 0) {
18412
+ return null;
18413
+ }
18443
18414
 
18415
+ var index = 0;
18416
+ var newArr = [];
18444
18417
 
18418
+ while (index < dataLength) {
18419
+ newArr.push(data.slice(index, isSliding ? index += dataLength : index += columns));
18420
+ }
18445
18421
 
18422
+ return /*#__PURE__*/React__default["default"].createElement("div", {
18423
+ className: cls(prefix, className, isSliding ? 'sliding' : ''),
18424
+ style: style,
18425
+ ref: domRef
18426
+ }, getGrid(prefix, newArr));
18427
+ };
18446
18428
 
18429
+ return /*#__PURE__*/React__default["default"].createElement(ContextLayout, null, renderEl);
18447
18430
  });
18448
18431
 
18432
+ function AddIcon() {
18433
+ return /*#__PURE__*/React__default["default"].createElement("svg", {
18434
+ width: "30",
18435
+ height: "30",
18436
+ viewBox: "0 0 30 30",
18437
+ fill: "none"
18438
+ }, /*#__PURE__*/React__default["default"].createElement("path", {
18439
+ fillRule: "evenodd",
18440
+ clipRule: "evenodd",
18441
+ d: "M14.5 0C14.2239 0 14 0.223857 14 0.5V14H0.5C0.223858 14 0 14.2239 0 14.5V15.5C0 15.7761 0.223857 16 0.5 16H14V29.5C14 29.7761 14.2239 30 14.5 30H15.5C15.7761 30 16 29.7761 16 29.5V16H29.5C29.7761 16 30 15.7761 30 15.5V14.5C30 14.2239 29.7761 14 29.5 14H16V0.5C16 0.223858 15.7761 0 15.5 0H14.5Z",
18442
+ fill: "#C9CDD4"
18443
+ }));
18444
+ }
18445
+
18449
18446
  var Upload =
18450
18447
  /** @class */
18451
18448
  function () {