amis-core 3.6.4 → 6.1.0
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/esm/Root.js +1 -1
- package/esm/RootRenderer.js +3 -2
- package/esm/SchemaRenderer.js +4 -1
- package/esm/Scoped.d.ts +6 -0
- package/esm/Scoped.js +45 -7
- package/esm/StatusScoped.js +1 -1
- package/esm/WithRootStore.js +1 -1
- package/esm/WithStore.js +3 -5
- package/esm/actions/Action.js +31 -27
- package/esm/actions/AjaxAction.js +1 -1
- package/esm/actions/BreakAction.js +1 -1
- package/esm/actions/BroadcastAction.js +1 -1
- package/esm/actions/CmptAction.js +65 -26
- package/esm/actions/ContinueAction.js +1 -1
- package/esm/actions/CopyAction.js +1 -1
- package/esm/actions/CustomAction.js +4 -3
- package/esm/actions/DialogAction.js +1 -1
- package/esm/actions/DrawerAction.js +1 -1
- package/esm/actions/EmailAction.js +1 -1
- package/esm/actions/LinkAction.js +9 -4
- package/esm/actions/LoopAction.js +1 -1
- package/esm/actions/PageAction.js +1 -1
- package/esm/actions/ParallelAction.js +1 -1
- package/esm/actions/StatusAction.js +1 -1
- package/esm/actions/SwitchAction.js +1 -1
- package/esm/actions/ToastAction.js +1 -1
- package/esm/components/CustomStyle.d.ts +1 -2
- package/esm/components/CustomStyle.js +19 -6
- package/esm/components/ErrorBoundary.js +1 -1
- package/esm/components/LazyComponent.js +1 -1
- package/esm/components/Overlay.js +12 -9
- package/esm/components/PopOver.js +8 -5
- package/esm/env.d.ts +4 -0
- package/esm/env.js +1 -1
- package/esm/envOverwrite.js +1 -1
- package/esm/factory.js +14 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.js +14 -7
- package/esm/locale.js +1 -1
- package/esm/polyfills.js +1 -1
- package/esm/renderers/Form.d.ts +4 -3
- package/esm/renderers/Form.js +216 -150
- package/esm/renderers/Item.d.ts +1 -0
- package/esm/renderers/Item.js +17 -17
- package/esm/renderers/Options.d.ts +5 -0
- package/esm/renderers/Options.js +188 -57
- package/esm/renderers/Placeholder.js +1 -1
- package/esm/renderers/builtin.js +1 -1
- package/esm/renderers/register.js +1 -1
- package/esm/renderers/wrapControl.js +39 -30
- package/esm/store/app.d.ts +2 -2
- package/esm/store/app.js +4 -3
- package/esm/store/combo.d.ts +79 -55
- package/esm/store/combo.js +1 -1
- package/esm/store/crud.d.ts +3 -2
- package/esm/store/crud.js +18 -4
- package/esm/store/form.d.ts +33 -23
- package/esm/store/form.js +5 -5
- package/esm/store/formItem.d.ts +2 -1
- package/esm/store/formItem.js +3 -2
- package/esm/store/iRenderer.d.ts +1 -1
- package/esm/store/iRenderer.js +10 -3
- package/esm/store/index.js +1 -1
- package/esm/store/list.d.ts +1 -1
- package/esm/store/list.js +18 -13
- package/esm/store/manager.js +1 -1
- package/esm/store/modal.d.ts +2 -2
- package/esm/store/modal.js +1 -1
- package/esm/store/node.js +1 -1
- package/esm/store/pagination.d.ts +2 -1
- package/esm/store/pagination.js +3 -2
- package/esm/store/root.d.ts +2 -2
- package/esm/store/root.js +4 -3
- package/esm/store/service.d.ts +2 -2
- package/esm/store/service.js +11 -7
- package/esm/store/status.js +1 -1
- package/esm/store/table.d.ts +69 -47
- package/esm/store/table.js +54 -25
- package/esm/store/table2.d.ts +14 -3
- package/esm/store/table2.js +22 -9
- package/esm/theme.js +1 -1
- package/esm/types.d.ts +7 -0
- package/esm/utils/Animation.js +1 -1
- package/esm/utils/ColorScale.js +1 -1
- package/esm/utils/DataSchema.js +1 -1
- package/esm/utils/DataScope.js +1 -1
- package/esm/utils/RootClose.js +1 -1
- package/esm/utils/SimpleMap.js +1 -1
- package/esm/utils/api.js +1 -1
- package/esm/utils/arraySlice.js +1 -1
- package/esm/utils/attachmentAdpator.js +1 -1
- package/esm/utils/autobind.js +1 -1
- package/esm/utils/browser.d.ts +1 -0
- package/esm/utils/browser.js +11 -0
- package/esm/utils/columnsSplit.js +1 -1
- package/esm/utils/concatData.d.ts +8 -0
- package/esm/utils/concatData.js +39 -0
- package/esm/utils/dataMapping.js +1 -1
- package/esm/utils/date.js +1 -1
- package/esm/utils/debug.js +1 -1
- package/esm/utils/decodeEntity.js +1 -1
- package/esm/utils/dom.js +1 -1
- package/esm/utils/errors.js +1 -1
- package/esm/utils/escapeHtml.js +1 -1
- package/esm/utils/filter-schema.js +1 -1
- package/esm/utils/filter.js +1 -1
- package/esm/utils/formatDuration.js +1 -1
- package/esm/utils/formula.js +1 -1
- package/esm/utils/getVariable.js +1 -1
- package/esm/utils/grammar.js +1 -1
- package/esm/utils/handleAction.js +1 -1
- package/esm/utils/helper.d.ts +14 -2
- package/esm/utils/helper.js +49 -14
- package/esm/utils/highlight.js +3 -2
- package/esm/utils/icon.js +1 -1
- package/esm/utils/image.js +1 -1
- package/esm/utils/index.d.ts +3 -0
- package/esm/utils/isPureVariable.js +1 -1
- package/esm/utils/json-schema-2-amis-schema.js +1 -1
- package/esm/utils/keyToPath.js +1 -1
- package/esm/utils/labelToString.d.ts +1 -0
- package/esm/utils/labelToString.js +38 -0
- package/esm/utils/makeSorter.js +1 -1
- package/esm/utils/math.js +1 -1
- package/esm/utils/memoryParse.js +1 -1
- package/esm/utils/normalizeLink.js +1 -1
- package/esm/utils/normalizeOptions.js +1 -1
- package/esm/utils/object.js +1 -1
- package/esm/utils/offset.js +1 -1
- package/esm/utils/offsetParent.js +1 -1
- package/esm/utils/optionValueCompare.js +1 -1
- package/esm/utils/position.js +1 -1
- package/esm/utils/prettyBytes.js +1 -1
- package/esm/utils/renderer-event.js +19 -3
- package/esm/utils/replaceText.js +9 -11
- package/esm/utils/resize-sensor.js +1 -1
- package/esm/utils/resolveCondition.js +1 -1
- package/esm/utils/resolveVariable.js +1 -1
- package/esm/utils/resolveVariableAndFilter.js +1 -1
- package/esm/utils/resolveVariableAndFilterForAsync.js +1 -1
- package/esm/utils/scrollPosition.js +1 -1
- package/esm/utils/string2regExp.d.ts +1 -1
- package/esm/utils/string2regExp.js +4 -3
- package/esm/utils/stripNumber.js +1 -1
- package/esm/utils/style-helper.d.ts +24 -5
- package/esm/utils/style-helper.js +49 -21
- package/esm/utils/style.js +1 -1
- package/esm/utils/toNumber.js +1 -1
- package/esm/utils/tokenize.d.ts +1 -0
- package/esm/utils/tokenize.js +10 -3
- package/esm/utils/tpl-builtin.js +1 -1
- package/esm/utils/tpl-lodash.js +1 -1
- package/esm/utils/tpl.js +6 -8
- package/esm/utils/uncontrollable.js +1 -1
- package/esm/utils/validateId.d.ts +16 -0
- package/esm/utils/validateId.js +154 -0
- package/esm/utils/validations.js +16 -8
- package/lib/Root.js +1 -1
- package/lib/RootRenderer.js +3 -2
- package/lib/SchemaRenderer.js +4 -1
- package/lib/Scoped.d.ts +6 -0
- package/lib/Scoped.js +45 -6
- package/lib/StatusScoped.js +1 -1
- package/lib/WithRootStore.js +1 -1
- package/lib/WithStore.js +3 -5
- package/lib/actions/Action.js +31 -27
- package/lib/actions/AjaxAction.js +1 -1
- package/lib/actions/BreakAction.js +1 -1
- package/lib/actions/BroadcastAction.js +1 -1
- package/lib/actions/CmptAction.js +65 -26
- package/lib/actions/ContinueAction.js +1 -1
- package/lib/actions/CopyAction.js +1 -1
- package/lib/actions/CustomAction.js +4 -3
- package/lib/actions/DialogAction.js +1 -1
- package/lib/actions/DrawerAction.js +1 -1
- package/lib/actions/EmailAction.js +1 -1
- package/lib/actions/LinkAction.js +9 -4
- package/lib/actions/LoopAction.js +1 -1
- package/lib/actions/PageAction.js +1 -1
- package/lib/actions/ParallelAction.js +1 -1
- package/lib/actions/StatusAction.js +1 -1
- package/lib/actions/SwitchAction.js +1 -1
- package/lib/actions/ToastAction.js +1 -1
- package/lib/components/CustomStyle.d.ts +1 -2
- package/lib/components/CustomStyle.js +19 -6
- package/lib/components/ErrorBoundary.js +1 -1
- package/lib/components/LazyComponent.js +1 -1
- package/lib/components/Overlay.js +11 -8
- package/lib/components/PopOver.js +8 -5
- package/lib/env.d.ts +4 -0
- package/lib/env.js +1 -1
- package/lib/envOverwrite.js +1 -1
- package/lib/factory.js +14 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +19 -4
- package/lib/locale.js +1 -1
- package/lib/polyfills.js +1 -1
- package/lib/renderers/Form.d.ts +4 -3
- package/lib/renderers/Form.js +216 -150
- package/lib/renderers/Item.d.ts +1 -0
- package/lib/renderers/Item.js +17 -17
- package/lib/renderers/Options.d.ts +5 -0
- package/lib/renderers/Options.js +188 -57
- package/lib/renderers/Placeholder.js +1 -1
- package/lib/renderers/builtin.js +1 -1
- package/lib/renderers/register.js +1 -1
- package/lib/renderers/wrapControl.js +38 -29
- package/lib/store/app.d.ts +2 -2
- package/lib/store/app.js +4 -3
- package/lib/store/combo.d.ts +55 -31
- package/lib/store/combo.js +1 -1
- package/lib/store/crud.d.ts +3 -2
- package/lib/store/crud.js +18 -4
- package/lib/store/form.d.ts +23 -13
- package/lib/store/form.js +5 -5
- package/lib/store/formItem.d.ts +2 -1
- package/lib/store/formItem.js +3 -2
- package/lib/store/iRenderer.d.ts +1 -1
- package/lib/store/iRenderer.js +10 -3
- package/lib/store/index.js +1 -1
- package/lib/store/list.d.ts +1 -1
- package/lib/store/list.js +18 -14
- package/lib/store/manager.js +1 -1
- package/lib/store/modal.d.ts +2 -2
- package/lib/store/modal.js +1 -1
- package/lib/store/node.js +1 -1
- package/lib/store/pagination.d.ts +2 -1
- package/lib/store/pagination.js +3 -2
- package/lib/store/root.d.ts +2 -2
- package/lib/store/root.js +4 -3
- package/lib/store/service.d.ts +2 -2
- package/lib/store/service.js +11 -7
- package/lib/store/status.js +1 -1
- package/lib/store/table.d.ts +49 -27
- package/lib/store/table.js +54 -26
- package/lib/store/table2.d.ts +14 -3
- package/lib/store/table2.js +22 -9
- package/lib/theme.js +1 -1
- package/lib/types.d.ts +7 -0
- package/lib/utils/Animation.js +1 -1
- package/lib/utils/ColorScale.js +1 -1
- package/lib/utils/DataSchema.js +1 -1
- package/lib/utils/DataScope.js +1 -1
- package/lib/utils/RootClose.js +1 -1
- package/lib/utils/SimpleMap.js +1 -1
- package/lib/utils/api.js +1 -1
- package/lib/utils/arraySlice.js +1 -1
- package/lib/utils/attachmentAdpator.js +1 -1
- package/lib/utils/autobind.js +1 -1
- package/lib/utils/browser.d.ts +1 -0
- package/lib/utils/browser.js +15 -0
- package/lib/utils/columnsSplit.js +1 -1
- package/lib/utils/concatData.d.ts +8 -0
- package/lib/utils/concatData.js +43 -0
- package/lib/utils/dataMapping.js +1 -1
- package/lib/utils/date.js +1 -1
- package/lib/utils/debug.js +1 -1
- package/lib/utils/decodeEntity.js +1 -1
- package/lib/utils/dom.js +1 -1
- package/lib/utils/errors.js +1 -1
- package/lib/utils/escapeHtml.js +1 -1
- package/lib/utils/filter-schema.js +1 -1
- package/lib/utils/filter.js +1 -1
- package/lib/utils/formatDuration.js +1 -1
- package/lib/utils/formula.js +1 -1
- package/lib/utils/getVariable.js +1 -1
- package/lib/utils/grammar.js +1 -1
- package/lib/utils/handleAction.js +1 -1
- package/lib/utils/helper.d.ts +14 -2
- package/lib/utils/helper.js +50 -12
- package/lib/utils/highlight.js +3 -2
- package/lib/utils/icon.js +1 -1
- package/lib/utils/image.js +1 -1
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/isPureVariable.js +1 -1
- package/lib/utils/json-schema-2-amis-schema.js +1 -1
- package/lib/utils/keyToPath.js +1 -1
- package/lib/utils/labelToString.d.ts +1 -0
- package/lib/utils/labelToString.js +46 -0
- package/lib/utils/makeSorter.js +1 -1
- package/lib/utils/math.js +1 -1
- package/lib/utils/memoryParse.js +1 -1
- package/lib/utils/normalizeLink.js +1 -1
- package/lib/utils/normalizeOptions.js +1 -1
- package/lib/utils/object.js +1 -1
- package/lib/utils/offset.js +1 -1
- package/lib/utils/offsetParent.js +1 -1
- package/lib/utils/optionValueCompare.js +1 -1
- package/lib/utils/position.js +1 -1
- package/lib/utils/prettyBytes.js +1 -1
- package/lib/utils/renderer-event.js +19 -3
- package/lib/utils/replaceText.js +8 -14
- package/lib/utils/resize-sensor.js +1 -1
- package/lib/utils/resolveCondition.js +1 -1
- package/lib/utils/resolveVariable.js +1 -1
- package/lib/utils/resolveVariableAndFilter.js +1 -1
- package/lib/utils/resolveVariableAndFilterForAsync.js +1 -1
- package/lib/utils/scrollPosition.js +1 -1
- package/lib/utils/string2regExp.d.ts +1 -1
- package/lib/utils/string2regExp.js +4 -3
- package/lib/utils/stripNumber.js +1 -1
- package/lib/utils/style-helper.d.ts +24 -5
- package/lib/utils/style-helper.js +49 -21
- package/lib/utils/style.js +1 -1
- package/lib/utils/toNumber.js +1 -1
- package/lib/utils/tokenize.d.ts +1 -0
- package/lib/utils/tokenize.js +10 -2
- package/lib/utils/tpl-builtin.js +1 -1
- package/lib/utils/tpl-lodash.js +1 -1
- package/lib/utils/tpl.js +5 -7
- package/lib/utils/uncontrollable.js +1 -1
- package/lib/utils/validateId.d.ts +16 -0
- package/lib/utils/validateId.js +160 -0
- package/lib/utils/validations.js +16 -8
- package/package.json +4 -3
- package/LICENSE +0 -201
package/lib/renderers/Form.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core
|
|
2
|
+
* amis-core v6.1.0
|
|
3
3
|
* Copyright 2018-2024 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -26,6 +26,7 @@ require('../utils/filter.js');
|
|
|
26
26
|
var api = require('../utils/api.js');
|
|
27
27
|
var LazyComponent = require('../components/LazyComponent.js');
|
|
28
28
|
var mobxStateTree = require('mobx-state-tree');
|
|
29
|
+
require('../utils/browser.js');
|
|
29
30
|
require('../utils/ColorScale.js');
|
|
30
31
|
require('../utils/columnsSplit.js');
|
|
31
32
|
require('../utils/DataSchema.js');
|
|
@@ -42,13 +43,13 @@ require('../utils/image.js');
|
|
|
42
43
|
require('lodash/isPlainObject');
|
|
43
44
|
require('lodash/isEqual');
|
|
44
45
|
require('../actions/Action.js');
|
|
45
|
-
require('lodash/cloneDeep');
|
|
46
46
|
require('../utils/resize-sensor.js');
|
|
47
47
|
require('react-overlays/useRootClose');
|
|
48
48
|
require('react-dom');
|
|
49
49
|
require('../utils/SimpleMap.js');
|
|
50
50
|
require('lodash/mapValues');
|
|
51
51
|
require('lodash/camelCase');
|
|
52
|
+
require('lodash/cloneDeep');
|
|
52
53
|
require('lodash/map');
|
|
53
54
|
require('lodash/isEmpty');
|
|
54
55
|
require('lodash/kebabCase');
|
|
@@ -80,6 +81,8 @@ var Form = /** @class */ (function (_super) {
|
|
|
80
81
|
trailing: true,
|
|
81
82
|
leading: false
|
|
82
83
|
});
|
|
84
|
+
// 如果开启了 lazyChange,需要一个 flush 方法把队列中值应用上。
|
|
85
|
+
_this.flushing = false;
|
|
83
86
|
_this.onInit = _this.onInit.bind(_this);
|
|
84
87
|
_this.handleAction = _this.handleAction.bind(_this);
|
|
85
88
|
_this.handleQuery = _this.handleQuery.bind(_this);
|
|
@@ -392,22 +395,27 @@ var Form = /** @class */ (function (_super) {
|
|
|
392
395
|
Form.prototype.isValidated = function () {
|
|
393
396
|
return this.props.store.validated;
|
|
394
397
|
};
|
|
395
|
-
Form.prototype.validate = function (forceValidate, throwErrors, toastErrors) {
|
|
398
|
+
Form.prototype.validate = function (forceValidate, throwErrors, toastErrors, skipFlush) {
|
|
396
399
|
if (throwErrors === void 0) { throwErrors = false; }
|
|
397
400
|
if (toastErrors === void 0) { toastErrors = true; }
|
|
401
|
+
if (skipFlush === void 0) { skipFlush = false; }
|
|
398
402
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
399
403
|
var _a, store, dispatchEvent, data, messages, __, result;
|
|
400
404
|
return tslib.__generator(this, function (_b) {
|
|
401
405
|
switch (_b.label) {
|
|
402
406
|
case 0:
|
|
403
407
|
_a = this.props, store = _a.store, dispatchEvent = _a.dispatchEvent, data = _a.data, messages = _a.messages, __ = _a.translate;
|
|
404
|
-
|
|
405
|
-
return [4 /*yield*/,
|
|
406
|
-
? ''
|
|
407
|
-
: typeof (messages === null || messages === void 0 ? void 0 : messages.validateFailed) === 'string'
|
|
408
|
-
? __(tpl.filter(messages.validateFailed, store.data))
|
|
409
|
-
: undefined)];
|
|
408
|
+
if (!!skipFlush) return [3 /*break*/, 2];
|
|
409
|
+
return [4 /*yield*/, this.flush()];
|
|
410
410
|
case 1:
|
|
411
|
+
_b.sent();
|
|
412
|
+
_b.label = 2;
|
|
413
|
+
case 2: return [4 /*yield*/, store.validate(this.hooks['validate'] || [], forceValidate, throwErrors, toastErrors === false
|
|
414
|
+
? ''
|
|
415
|
+
: typeof (messages === null || messages === void 0 ? void 0 : messages.validateFailed) === 'string'
|
|
416
|
+
? __(tpl.filter(messages.validateFailed, store.data))
|
|
417
|
+
: undefined)];
|
|
418
|
+
case 3:
|
|
411
419
|
result = _b.sent();
|
|
412
420
|
dispatchEvent(result ? 'validateSucc' : 'validateError', data);
|
|
413
421
|
return [2 /*return*/, result];
|
|
@@ -434,20 +442,55 @@ var Form = /** @class */ (function (_super) {
|
|
|
434
442
|
this.flush();
|
|
435
443
|
store.setValues(value, undefined, replace);
|
|
436
444
|
};
|
|
437
|
-
Form.prototype.submit = function (fn, throwErrors) {
|
|
445
|
+
Form.prototype.submit = function (fn, throwErrors, skipFlush) {
|
|
438
446
|
if (throwErrors === void 0) { throwErrors = false; }
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
447
|
+
if (skipFlush === void 0) { skipFlush = false; }
|
|
448
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
449
|
+
var _a, store, messages, __, dispatchEvent, data, validateErrCb;
|
|
450
|
+
return tslib.__generator(this, function (_b) {
|
|
451
|
+
switch (_b.label) {
|
|
452
|
+
case 0:
|
|
453
|
+
_a = this.props, store = _a.store, messages = _a.messages, __ = _a.translate, dispatchEvent = _a.dispatchEvent, data = _a.data;
|
|
454
|
+
if (!!skipFlush) return [3 /*break*/, 2];
|
|
455
|
+
return [4 /*yield*/, this.flush()];
|
|
456
|
+
case 1:
|
|
457
|
+
_b.sent();
|
|
458
|
+
_b.label = 2;
|
|
459
|
+
case 2:
|
|
460
|
+
validateErrCb = function () { return dispatchEvent('validateError', data); };
|
|
461
|
+
return [2 /*return*/, store.submit(fn, this.hooks['validate'] || [], typeof (messages === null || messages === void 0 ? void 0 : messages.validateFailed) === 'string'
|
|
462
|
+
? __(tpl.filter(messages.validateFailed, store.data))
|
|
463
|
+
: undefined, validateErrCb, throwErrors)];
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
});
|
|
445
467
|
};
|
|
446
|
-
// 如果开启了 lazyChange,需要一个 flush 方法把队列中值应用上。
|
|
447
468
|
Form.prototype.flush = function () {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
469
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
470
|
+
var hooks;
|
|
471
|
+
return tslib.__generator(this, function (_a) {
|
|
472
|
+
switch (_a.label) {
|
|
473
|
+
case 0:
|
|
474
|
+
_a.trys.push([0, , 3, 4]);
|
|
475
|
+
if (this.flushing) {
|
|
476
|
+
return [2 /*return*/];
|
|
477
|
+
}
|
|
478
|
+
this.flushing = true;
|
|
479
|
+
hooks = this.hooks['flush'] || [];
|
|
480
|
+
return [4 /*yield*/, Promise.all(hooks.map(function (fn) { return fn(); }))];
|
|
481
|
+
case 1:
|
|
482
|
+
_a.sent();
|
|
483
|
+
return [4 /*yield*/, this.lazyEmitChange.flush()];
|
|
484
|
+
case 2:
|
|
485
|
+
_a.sent();
|
|
486
|
+
return [3 /*break*/, 4];
|
|
487
|
+
case 3:
|
|
488
|
+
this.flushing = false;
|
|
489
|
+
return [7 /*endfinally*/];
|
|
490
|
+
case 4: return [2 /*return*/];
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
});
|
|
451
494
|
};
|
|
452
495
|
Form.prototype.reset = function () {
|
|
453
496
|
var _a = this.props, store = _a.store, onReset = _a.onReset;
|
|
@@ -519,11 +562,17 @@ var Form = /** @class */ (function (_super) {
|
|
|
519
562
|
onChange && onChange.apply(null, changeProps);
|
|
520
563
|
}
|
|
521
564
|
store.clearRestError();
|
|
522
|
-
(submit || (submitOnChange && store.inited))
|
|
523
|
-
|
|
524
|
-
type: 'submit'
|
|
525
|
-
|
|
526
|
-
|
|
565
|
+
if (!(submit || (submitOnChange && store.inited))) return [3 /*break*/, 3];
|
|
566
|
+
return [4 /*yield*/, this.handleAction(undefined, {
|
|
567
|
+
type: 'submit',
|
|
568
|
+
// 如果这里不跳过,会相互依赖死循环,flush 会 让 emiteChange 立即执行
|
|
569
|
+
// handleAction 里面又会调用 flush
|
|
570
|
+
skipFormFlush: true
|
|
571
|
+
}, store.data)];
|
|
572
|
+
case 2:
|
|
573
|
+
_b.sent();
|
|
574
|
+
_b.label = 3;
|
|
575
|
+
case 3: return [2 /*return*/];
|
|
527
576
|
}
|
|
528
577
|
});
|
|
529
578
|
});
|
|
@@ -574,8 +623,12 @@ var Form = /** @class */ (function (_super) {
|
|
|
574
623
|
switch (_f.label) {
|
|
575
624
|
case 0:
|
|
576
625
|
_c = this.props, store = _c.store, onSubmit = _c.onSubmit, api$1 = _c.api, asyncApi = _c.asyncApi, finishedField = _c.finishedField, checkInterval = _c.checkInterval, _d = _c.messages, saveSuccess = _d.saveSuccess, saveFailed = _d.saveFailed, resetAfterSubmit = _c.resetAfterSubmit, clearAfterSubmit = _c.clearAfterSubmit, onAction = _c.onAction, onSaved = _c.onSaved, onReset = _c.onReset, onFinished = _c.onFinished, onFailed = _c.onFailed, redirect = _c.redirect, reload = _c.reload, target = _c.target, env = _c.env, onChange = _c.onChange, clearPersistDataAfterSubmit = _c.clearPersistDataAfterSubmit, trimValues = _c.trimValues, dispatchEvent = _c.dispatchEvent, __ = _c.translate;
|
|
577
|
-
|
|
578
|
-
this.flush();
|
|
626
|
+
if (!!action.skipFormFlush) return [3 /*break*/, 2];
|
|
627
|
+
return [4 /*yield*/, this.flush()];
|
|
628
|
+
case 1:
|
|
629
|
+
_f.sent();
|
|
630
|
+
_f.label = 2;
|
|
631
|
+
case 2:
|
|
579
632
|
if (trimValues) {
|
|
580
633
|
store.trimValues();
|
|
581
634
|
}
|
|
@@ -583,7 +636,7 @@ var Form = /** @class */ (function (_super) {
|
|
|
583
636
|
if (data === this.props.data) {
|
|
584
637
|
data = store.data;
|
|
585
638
|
}
|
|
586
|
-
if (!(Array.isArray(action.required) && action.required.length)) return [3 /*break*/,
|
|
639
|
+
if (!(Array.isArray(action.required) && action.required.length)) return [3 /*break*/, 6];
|
|
587
640
|
/** 如果是按钮指定了required,则校验前先清空一下遗留的校验报错 */
|
|
588
641
|
store.clearErrors();
|
|
589
642
|
fields = action.required.map(function (item) { return ({
|
|
@@ -591,31 +644,31 @@ var Form = /** @class */ (function (_super) {
|
|
|
591
644
|
rules: { isRequired: true }
|
|
592
645
|
}); });
|
|
593
646
|
return [4 /*yield*/, store.validateFields(fields)];
|
|
594
|
-
case
|
|
647
|
+
case 3:
|
|
595
648
|
validationRes = _f.sent();
|
|
596
|
-
if (!!validationRes) return [3 /*break*/,
|
|
649
|
+
if (!!validationRes) return [3 /*break*/, 5];
|
|
597
650
|
return [4 /*yield*/, dispatchEvent('validateError', this.props.data)];
|
|
598
|
-
case
|
|
651
|
+
case 4:
|
|
599
652
|
dispatcher = _f.sent();
|
|
600
653
|
if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
|
|
601
654
|
env.notify('error', __('Form.validateFailed'));
|
|
602
655
|
}
|
|
603
656
|
/** 抛异常是为了在dialog中catch这个错误,避免弹窗直接关闭 */
|
|
604
657
|
return [2 /*return*/, Promise.reject(__('Form.validateFailed'))];
|
|
605
|
-
case
|
|
658
|
+
case 5:
|
|
606
659
|
/** 重置validated状态,保证submit时触发表单中的校验项 */
|
|
607
660
|
store.clearErrors();
|
|
608
|
-
_f.label =
|
|
609
|
-
case
|
|
661
|
+
_f.label = 6;
|
|
662
|
+
case 6:
|
|
610
663
|
if (!(action.type === 'submit' ||
|
|
611
664
|
action.actionType === 'submit' ||
|
|
612
665
|
action.actionType === 'confirm' ||
|
|
613
666
|
action.actionType === 'reset-and-submit' ||
|
|
614
|
-
action.actionType === 'clear-and-submit')) return [3 /*break*/,
|
|
667
|
+
action.actionType === 'clear-and-submit')) return [3 /*break*/, 8];
|
|
615
668
|
_e = this.props, dispatchEvent_1 = _e.dispatchEvent, onEvent = _e.onEvent;
|
|
616
669
|
submitEvent = (_b = (_a = onEvent === null || onEvent === void 0 ? void 0 : onEvent.submit) === null || _a === void 0 ? void 0 : _a.actions) === null || _b === void 0 ? void 0 : _b.length;
|
|
617
670
|
return [4 /*yield*/, dispatchEvent_1('submit', this.props.data)];
|
|
618
|
-
case
|
|
671
|
+
case 7:
|
|
619
672
|
dispatcher = _f.sent();
|
|
620
673
|
if ((dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented) || submitEvent) {
|
|
621
674
|
return [2 /*return*/];
|
|
@@ -627,119 +680,132 @@ var Form = /** @class */ (function (_super) {
|
|
|
627
680
|
else if (action.actionType === 'clear-and-submit') {
|
|
628
681
|
store.clear(this.handleReset(action));
|
|
629
682
|
}
|
|
630
|
-
return [2 /*return*/, this.submit(function (values) {
|
|
683
|
+
return [2 /*return*/, this.submit(function (values) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
684
|
+
var result, finnalAsyncApi_1;
|
|
631
685
|
var _a;
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
686
|
+
var _this = this;
|
|
687
|
+
return tslib.__generator(this, function (_b) {
|
|
688
|
+
switch (_b.label) {
|
|
689
|
+
case 0:
|
|
690
|
+
if (!onSubmit) return [3 /*break*/, 2];
|
|
691
|
+
return [4 /*yield*/, onSubmit(values, action)];
|
|
692
|
+
case 1:
|
|
693
|
+
result = _b.sent();
|
|
694
|
+
if (result === false) {
|
|
695
|
+
return [2 /*return*/, Promise.resolve(false)];
|
|
696
|
+
}
|
|
697
|
+
_b.label = 2;
|
|
698
|
+
case 2:
|
|
699
|
+
// 走到这里代表校验成功了
|
|
700
|
+
dispatchEvent_1('validateSucc', this.props.data);
|
|
701
|
+
if (target) {
|
|
702
|
+
this.submitToTarget(Scoped.filterTarget(target, values), values);
|
|
703
|
+
/** 可能配置页面跳转事件,页面路由变化导致persistKey不一致,无法清除持久化数据,所以提交成功事件之前先清理一下 */
|
|
704
|
+
clearPersistDataAfterSubmit && store.clearLocalPersistData();
|
|
705
|
+
dispatchEvent_1('submitSucc', object.createObject(this.props.data, values));
|
|
706
|
+
}
|
|
707
|
+
else if (action.actionType === 'reload') {
|
|
708
|
+
action.target &&
|
|
709
|
+
this.reloadTarget(Scoped.filterTarget(action.target, values), values);
|
|
710
|
+
}
|
|
711
|
+
else if (action.actionType === 'dialog') {
|
|
712
|
+
store.openDialog(data, undefined, action.callback, delegate || this.context);
|
|
713
|
+
}
|
|
714
|
+
else if (action.actionType === 'drawer') {
|
|
715
|
+
store.openDrawer(data);
|
|
716
|
+
}
|
|
717
|
+
else if (api.isEffectiveApi(action.api || api$1, values)) {
|
|
718
|
+
finnalAsyncApi_1 = action.asyncApi || asyncApi;
|
|
719
|
+
api.isEffectiveApi(finnalAsyncApi_1, store.data) &&
|
|
720
|
+
store.updateData((_a = {},
|
|
721
|
+
_a[finishedField || 'finished'] = false,
|
|
722
|
+
_a));
|
|
723
|
+
return [2 /*return*/, store
|
|
724
|
+
.saveRemote(action.api || api$1, values, {
|
|
725
|
+
successMessage: typeof saveSuccess === 'string'
|
|
726
|
+
? tpl.filter(saveSuccess, store.data)
|
|
727
|
+
: undefined,
|
|
728
|
+
errorMessage: typeof saveFailed === 'string'
|
|
729
|
+
? tpl.filter(saveFailed, store.data)
|
|
730
|
+
: undefined,
|
|
731
|
+
onSuccess: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
732
|
+
var dispatcher, cbResult;
|
|
733
|
+
var _this = this;
|
|
734
|
+
return tslib.__generator(this, function (_a) {
|
|
735
|
+
switch (_a.label) {
|
|
736
|
+
case 0:
|
|
737
|
+
clearPersistDataAfterSubmit && store.clearLocalPersistData();
|
|
738
|
+
return [4 /*yield*/, dispatchEvent_1('submitSucc', object.createObject(this.props.data, { result: result }))];
|
|
739
|
+
case 1:
|
|
740
|
+
dispatcher = _a.sent();
|
|
741
|
+
if (!api.isEffectiveApi(finnalAsyncApi_1, store.data) ||
|
|
742
|
+
store.data[finishedField || 'finished']) {
|
|
743
|
+
return [2 /*return*/, {
|
|
744
|
+
cbResult: null,
|
|
745
|
+
dispatcher: dispatcher
|
|
746
|
+
}];
|
|
747
|
+
}
|
|
748
|
+
cbResult = helper.until(function () { return store.checkRemote(finnalAsyncApi_1, store.data); }, function (ret) { return ret && ret[finishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); }, checkInterval).then(function (value) {
|
|
749
|
+
// 派发asyncApiFinished事件
|
|
750
|
+
dispatchEvent_1('asyncApiFinished', store.data);
|
|
751
|
+
});
|
|
752
|
+
return [2 /*return*/, {
|
|
753
|
+
cbResult: cbResult,
|
|
754
|
+
dispatcher: dispatcher
|
|
755
|
+
}];
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
}); },
|
|
759
|
+
onFailed: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
760
|
+
var dispatcher;
|
|
761
|
+
return tslib.__generator(this, function (_a) {
|
|
762
|
+
switch (_a.label) {
|
|
763
|
+
case 0: return [4 /*yield*/, dispatchEvent_1('submitFail', object.createObject(this.props.data, { error: result }))];
|
|
764
|
+
case 1:
|
|
765
|
+
dispatcher = _a.sent();
|
|
766
|
+
return [2 /*return*/, {
|
|
767
|
+
dispatcher: dispatcher
|
|
768
|
+
}];
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
}); }
|
|
772
|
+
})
|
|
773
|
+
.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
774
|
+
var feedback, confirmed;
|
|
775
|
+
return tslib.__generator(this, function (_a) {
|
|
776
|
+
switch (_a.label) {
|
|
777
|
+
case 0:
|
|
778
|
+
onSaved && onSaved(values, response);
|
|
779
|
+
feedback = action.feedback || this.props.feedback;
|
|
780
|
+
if (!(feedback && helper.isVisible(feedback, store.data))) return [3 /*break*/, 2];
|
|
781
|
+
return [4 /*yield*/, this.openFeedback(feedback, store.data)];
|
|
782
|
+
case 1:
|
|
783
|
+
confirmed = _a.sent();
|
|
784
|
+
// 如果 feedback 配置了,取消就跳过原有逻辑。
|
|
785
|
+
if (feedback.skipRestOnCancel && !confirmed) {
|
|
786
|
+
throw new helper.SkipOperation();
|
|
787
|
+
}
|
|
788
|
+
else if (feedback.skipRestOnConfirm && confirmed) {
|
|
789
|
+
throw new helper.SkipOperation();
|
|
790
|
+
}
|
|
791
|
+
_a.label = 2;
|
|
792
|
+
case 2: return [2 /*return*/, object.injectObjectChain(store.data, {
|
|
793
|
+
__payload: values,
|
|
794
|
+
__response: response
|
|
795
|
+
})];
|
|
796
|
+
}
|
|
687
797
|
});
|
|
688
|
-
|
|
689
|
-
cbResult: cbResult,
|
|
690
|
-
dispatcher: dispatcher
|
|
691
|
-
}];
|
|
692
|
-
}
|
|
693
|
-
});
|
|
694
|
-
}); },
|
|
695
|
-
onFailed: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
696
|
-
var dispatcher;
|
|
697
|
-
return tslib.__generator(this, function (_a) {
|
|
698
|
-
switch (_a.label) {
|
|
699
|
-
case 0: return [4 /*yield*/, dispatchEvent_1('submitFail', object.createObject(this.props.data, { error: result }))];
|
|
700
|
-
case 1:
|
|
701
|
-
dispatcher = _a.sent();
|
|
702
|
-
return [2 /*return*/, {
|
|
703
|
-
dispatcher: dispatcher
|
|
704
|
-
}];
|
|
705
|
-
}
|
|
706
|
-
});
|
|
707
|
-
}); }
|
|
708
|
-
})
|
|
709
|
-
.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
710
|
-
var feedback, confirmed;
|
|
711
|
-
return tslib.__generator(this, function (_a) {
|
|
712
|
-
switch (_a.label) {
|
|
713
|
-
case 0:
|
|
714
|
-
onSaved && onSaved(values, response);
|
|
715
|
-
feedback = action.feedback || this.props.feedback;
|
|
716
|
-
if (!(feedback && helper.isVisible(feedback, store.data))) return [3 /*break*/, 2];
|
|
717
|
-
return [4 /*yield*/, this.openFeedback(feedback, store.data)];
|
|
718
|
-
case 1:
|
|
719
|
-
confirmed = _a.sent();
|
|
720
|
-
// 如果 feedback 配置了,取消就跳过原有逻辑。
|
|
721
|
-
if (feedback.skipRestOnCancel && !confirmed) {
|
|
722
|
-
throw new helper.SkipOperation();
|
|
723
|
-
}
|
|
724
|
-
else if (feedback.skipRestOnConfirm && confirmed) {
|
|
725
|
-
throw new helper.SkipOperation();
|
|
726
|
-
}
|
|
727
|
-
_a.label = 2;
|
|
728
|
-
case 2: return [2 /*return*/, object.injectObjectChain(store.data, {
|
|
729
|
-
__payload: values,
|
|
730
|
-
__response: response
|
|
731
|
-
})];
|
|
798
|
+
}); })];
|
|
732
799
|
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
}, throwErrors)
|
|
800
|
+
else {
|
|
801
|
+
clearPersistDataAfterSubmit && store.clearLocalPersistData();
|
|
802
|
+
// type为submit,但是没有配api以及target时,只派发事件
|
|
803
|
+
dispatchEvent_1('submitSucc', object.createObject(this.props.data, values));
|
|
804
|
+
}
|
|
805
|
+
return [2 /*return*/, Promise.resolve(null)];
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
}); }, throwErrors, true)
|
|
743
809
|
.then(function (values) {
|
|
744
810
|
// 有可能 onSubmit return false 了,那么后面的就不应该再执行了。
|
|
745
811
|
if (values === false) {
|
|
@@ -767,7 +833,7 @@ var Form = /** @class */ (function (_super) {
|
|
|
767
833
|
throw reason;
|
|
768
834
|
}
|
|
769
835
|
})];
|
|
770
|
-
case
|
|
836
|
+
case 8:
|
|
771
837
|
if (action.type === 'reset' || action.actionType === 'reset') {
|
|
772
838
|
store.setCurrentAction(action);
|
|
773
839
|
store.reset(onReset);
|
|
@@ -778,7 +844,7 @@ var Form = /** @class */ (function (_super) {
|
|
|
778
844
|
}
|
|
779
845
|
else if (action.actionType === 'validate') {
|
|
780
846
|
store.setCurrentAction(action);
|
|
781
|
-
return [2 /*return*/, this.validate(true, throwErrors)];
|
|
847
|
+
return [2 /*return*/, this.validate(true, throwErrors, true, true)];
|
|
782
848
|
}
|
|
783
849
|
else if (action.actionType === 'dialog') {
|
|
784
850
|
store.setCurrentAction(action);
|
|
@@ -854,8 +920,8 @@ var Form = /** @class */ (function (_super) {
|
|
|
854
920
|
// 不识别的丢给上层去处理。
|
|
855
921
|
return [2 /*return*/, onAction(e, action, data, throwErrors, delegate || this.context)];
|
|
856
922
|
}
|
|
857
|
-
_f.label =
|
|
858
|
-
case
|
|
923
|
+
_f.label = 9;
|
|
924
|
+
case 9: return [2 /*return*/];
|
|
859
925
|
}
|
|
860
926
|
});
|
|
861
927
|
});
|
package/lib/renderers/Item.d.ts
CHANGED