amis-core 1.0.0-beta.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/dist/Root.js +94 -0
- package/dist/RootRenderer.js +288 -0
- package/dist/SchemaRenderer.js +323 -0
- package/dist/Scoped.js +252 -0
- package/dist/WithRootStore.js +44 -0
- package/dist/WithStore.js +179 -0
- package/dist/__tests__/compat.test.d.ts +1 -0
- package/dist/__tests__/factory.test.d.ts +1 -0
- package/dist/__tests__/filter.test.d.ts +1 -0
- package/dist/__tests__/helper.d.ts +13 -0
- package/dist/__tests__/tokenize.test.d.ts +1 -0
- package/dist/actions/Action.js +119 -0
- package/dist/actions/AjaxAction.js +96 -0
- package/dist/actions/BreakAction.js +35 -0
- package/dist/actions/BroadcastAction.js +49 -0
- package/dist/actions/CmptAction.js +60 -0
- package/dist/actions/ContinueAction.js +35 -0
- package/dist/actions/CopyAction.js +43 -0
- package/dist/actions/CustomAction.js +49 -0
- package/dist/actions/DialogAction.js +104 -0
- package/dist/actions/DrawerAction.js +66 -0
- package/dist/actions/EmailAction.js +48 -0
- package/dist/actions/LinkAction.js +52 -0
- package/dist/actions/LoopAction.js +107 -0
- package/dist/actions/PageAction.js +80 -0
- package/dist/actions/ParallelAction.js +40 -0
- package/dist/actions/SwitchAction.js +52 -0
- package/dist/actions/ToastAction.js +35 -0
- package/dist/components/LazyComponent.js +99 -0
- package/dist/env.js +20 -0
- package/dist/envOverwrite.js +43 -0
- package/dist/factory.js +308 -0
- package/dist/index.js +218 -0
- package/dist/index2.js +255 -0
- package/dist/locale.js +114 -0
- package/dist/renderers/Form.js +1162 -0
- package/dist/renderers/Item.js +636 -0
- package/dist/renderers/Options.js +881 -0
- package/dist/renderers/Placeholder.js +31 -0
- package/dist/renderers/builtin.js +27 -0
- package/dist/renderers/wrapControl.js +507 -0
- package/dist/src/Root.d.ts +37 -0
- package/dist/src/RootRenderer.d.ts +27 -0
- package/dist/src/SchemaRenderer.d.ts +37 -0
- package/dist/src/Scoped.d.ts +38 -0
- package/dist/src/WithRootStore.d.ts +737 -0
- package/dist/src/WithStore.d.ts +5 -0
- package/dist/src/actions/Action.d.ts +38 -0
- package/dist/src/actions/AjaxAction.d.ts +25 -0
- package/dist/src/actions/BreakAction.d.ts +15 -0
- package/dist/src/actions/BroadcastAction.d.ts +16 -0
- package/dist/src/actions/CmptAction.d.ts +20 -0
- package/dist/src/actions/ContinueAction.d.ts +15 -0
- package/dist/src/actions/CopyAction.d.ts +20 -0
- package/dist/src/actions/CustomAction.d.ts +17 -0
- package/dist/src/actions/Decorators.d.ts +25 -0
- package/dist/src/actions/DialogAction.d.ts +57 -0
- package/dist/src/actions/DrawerAction.d.ts +30 -0
- package/dist/src/actions/EmailAction.d.ts +23 -0
- package/dist/src/actions/LinkAction.d.ts +24 -0
- package/dist/src/actions/LoopAction.d.ts +19 -0
- package/dist/src/actions/PageAction.d.ts +39 -0
- package/dist/src/actions/ParallelAction.d.ts +8 -0
- package/dist/src/actions/SwitchAction.d.ts +11 -0
- package/dist/src/actions/ToastAction.d.ts +19 -0
- package/dist/src/actions/index.d.ts +21 -0
- package/dist/src/components/LazyComponent.d.ts +32 -0
- package/dist/src/env.d.ts +172 -0
- package/dist/src/envOverwrite.d.ts +4 -0
- package/dist/src/factory.d.ts +78 -0
- package/dist/src/index.d.ts +25 -0
- package/dist/src/locale.d.ts +82 -0
- package/dist/src/renderers/Form.d.ts +352 -0
- package/dist/src/renderers/Item.d.ts +795 -0
- package/dist/src/renderers/Options.d.ts +150 -0
- package/dist/src/renderers/Placeholder.d.ts +6 -0
- package/dist/src/renderers/builtin.d.ts +1 -0
- package/dist/src/renderers/wrapControl.d.ts +446 -0
- package/dist/src/schema.d.ts +369 -0
- package/dist/src/store/app.d.ts +89 -0
- package/dist/src/store/combo.d.ts +8504 -0
- package/dist/src/store/crud.d.ts +124 -0
- package/dist/src/store/form.d.ts +3394 -0
- package/dist/src/store/formItem.d.ts +130 -0
- package/dist/src/store/iRenderer.d.ts +46 -0
- package/dist/src/store/index.d.ts +105 -0
- package/dist/src/store/list.d.ts +270 -0
- package/dist/src/store/manager.d.ts +115 -0
- package/dist/src/store/modal.d.ts +84 -0
- package/dist/src/store/node.d.ts +22 -0
- package/dist/src/store/pagination.d.ts +58 -0
- package/dist/src/store/root.d.ts +79 -0
- package/dist/src/store/service.d.ts +71 -0
- package/dist/src/store/table-v2.d.ts +309 -0
- package/dist/src/store/table.d.ts +8334 -0
- package/dist/src/theme.d.ts +83 -0
- package/dist/src/types.d.ts +217 -0
- package/dist/src/utils/Animation.d.ts +22 -0
- package/dist/src/utils/ColorScale.d.ts +19 -0
- package/dist/src/utils/DataSchema.d.ts +25 -0
- package/dist/src/utils/DataScope.d.ts +23 -0
- package/dist/src/utils/RootClose.d.ts +4 -0
- package/dist/src/utils/SimpleMap.d.ts +8 -0
- package/dist/src/utils/api.d.ts +27 -0
- package/dist/src/utils/attachmentAdpator.d.ts +7 -0
- package/dist/src/utils/autobind.d.ts +7 -0
- package/dist/src/utils/columnsSplit.d.ts +1 -0
- package/dist/src/utils/dataMapping.d.ts +3 -0
- package/dist/src/utils/date.d.ts +4 -0
- package/dist/src/utils/debug.d.ts +26 -0
- package/dist/src/utils/dom.d.ts +13 -0
- package/dist/src/utils/errors.d.ts +6 -0
- package/dist/src/utils/escapeHtml.d.ts +1 -0
- package/dist/src/utils/filter-schema.d.ts +12 -0
- package/dist/src/utils/filter.d.ts +1 -0
- package/dist/src/utils/formatDuration.d.ts +1 -0
- package/dist/src/utils/formula.d.ts +16 -0
- package/dist/src/utils/getVariable.d.ts +3 -0
- package/dist/src/utils/grammar.d.ts +4 -0
- package/dist/src/utils/handleAction.d.ts +6 -0
- package/dist/src/utils/helper.d.ts +286 -0
- package/dist/src/utils/icon.d.ts +12 -0
- package/dist/src/utils/image.d.ts +17 -0
- package/dist/src/utils/index.d.ts +12 -0
- package/dist/src/utils/isPureVariable.d.ts +1 -0
- package/dist/src/utils/json-schema-2-amis-schema.d.ts +6 -0
- package/dist/src/utils/keyToPath.d.ts +6 -0
- package/dist/src/utils/makeSorter.d.ts +1 -0
- package/dist/src/utils/markdown.d.ts +5 -0
- package/dist/src/utils/normalizeLink.d.ts +1 -0
- package/dist/src/utils/normalizeOptions.d.ts +7 -0
- package/dist/src/utils/object.d.ts +15 -0
- package/dist/src/utils/offset.d.ts +14 -0
- package/dist/src/utils/offsetParent.d.ts +4 -0
- package/dist/src/utils/optionValueCompare.d.ts +3 -0
- package/dist/src/utils/position.d.ts +15 -0
- package/dist/src/utils/prettyBytes.d.ts +1 -0
- package/dist/src/utils/renderer-event.d.ts +44 -0
- package/dist/src/utils/replaceText.d.ts +6 -0
- package/dist/src/utils/resize-sensor.d.ts +6 -0
- package/dist/src/utils/resolveVariable.d.ts +1 -0
- package/dist/src/utils/resolveVariableAndFilter.d.ts +1 -0
- package/dist/src/utils/scrollPosition.d.ts +6 -0
- package/dist/src/utils/string2regExp.d.ts +1 -0
- package/dist/src/utils/stripNumber.d.ts +1 -0
- package/dist/src/utils/style.d.ts +10 -0
- package/dist/src/utils/tokenize.d.ts +1 -0
- package/dist/src/utils/tpl-builtin.d.ts +18 -0
- package/dist/src/utils/tpl-lodash.d.ts +4 -0
- package/dist/src/utils/tpl.d.ts +11 -0
- package/dist/src/utils/validations.d.ts +39 -0
- package/dist/store/app.js +190 -0
- package/dist/store/combo.js +154 -0
- package/dist/store/crud.js +413 -0
- package/dist/store/form.js +579 -0
- package/dist/store/formItem.js +846 -0
- package/dist/store/iRenderer.js +189 -0
- package/dist/store/index.js +103 -0
- package/dist/store/list.js +248 -0
- package/dist/store/manager.js +56 -0
- package/dist/store/modal.js +54 -0
- package/dist/store/node.js +93 -0
- package/dist/store/pagination.js +60 -0
- package/dist/store/root.js +45 -0
- package/dist/store/service.js +415 -0
- package/dist/store/table-v2.js +471 -0
- package/dist/store/table.js +1105 -0
- package/dist/theme.js +93 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/Animation.js +290 -0
- package/dist/utils/DataSchema.js +120 -0
- package/dist/utils/DataScope.js +151 -0
- package/dist/utils/SimpleMap.js +46 -0
- package/dist/utils/api.js +555 -0
- package/dist/utils/autobind.js +94 -0
- package/dist/utils/dataMapping.js +136 -0
- package/dist/utils/date.js +90 -0
- package/dist/utils/debug.js +343 -0
- package/dist/utils/errors.js +23 -0
- package/dist/utils/escapeHtml.js +24 -0
- package/dist/utils/filter-schema.js +75 -0
- package/dist/utils/filter.js +481 -0
- package/dist/utils/formatDuration.js +27 -0
- package/dist/utils/formula.js +165 -0
- package/dist/utils/getVariable.js +29 -0
- package/dist/utils/grammar.js +54 -0
- package/dist/utils/helper.js +1283 -0
- package/dist/utils/isPureVariable.js +16 -0
- package/dist/utils/keyToPath.js +34 -0
- package/dist/utils/makeSorter.js +30 -0
- package/dist/utils/normalizeLink.js +47 -0
- package/dist/utils/normalizeOptions.js +92 -0
- package/dist/utils/object.js +156 -0
- package/dist/utils/offset.js +36 -0
- package/dist/utils/offsetParent.js +27 -0
- package/dist/utils/optionValueCompare.js +25 -0
- package/dist/utils/position.js +50 -0
- package/dist/utils/prettyBytes.js +28 -0
- package/dist/utils/renderer-event.js +131 -0
- package/dist/utils/replaceText.js +35 -0
- package/dist/utils/resize-sensor.js +177 -0
- package/dist/utils/resolveVariable.js +39 -0
- package/dist/utils/resolveVariableAndFilter.js +37 -0
- package/dist/utils/string2regExp.js +18 -0
- package/dist/utils/stripNumber.js +20 -0
- package/dist/utils/tokenize.js +33 -0
- package/dist/utils/tpl-builtin.js +71 -0
- package/dist/utils/tpl-lodash.js +71 -0
- package/dist/utils/tpl.js +140 -0
- package/dist/utils/validations.js +377 -0
- package/package.json +121 -0
package/dist/Root.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* amis-core v1.0.0-beta.0
|
|
3
|
+
* Copyright 2018-2022 fex
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var tslib = require('tslib');
|
|
11
|
+
var isPlainObject = require('lodash/isPlainObject');
|
|
12
|
+
var React = require('react');
|
|
13
|
+
var locale = require('./locale.js');
|
|
14
|
+
var RootRenderer = require('./RootRenderer.js');
|
|
15
|
+
var SchemaRenderer = require('./SchemaRenderer.js');
|
|
16
|
+
var Scoped = require('./Scoped.js');
|
|
17
|
+
var theme = require('./theme.js');
|
|
18
|
+
var helper = require('./utils/helper.js');
|
|
19
|
+
var WithRootStore = require('./WithRootStore.js');
|
|
20
|
+
|
|
21
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
|
+
|
|
23
|
+
var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);
|
|
24
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
25
|
+
|
|
26
|
+
var Root = /** @class */ (function (_super) {
|
|
27
|
+
tslib.__extends(Root, _super);
|
|
28
|
+
function Root() {
|
|
29
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
30
|
+
}
|
|
31
|
+
Root.prototype.resolveDefinitions = function (name) {
|
|
32
|
+
var definitions = this.props.schema.definitions;
|
|
33
|
+
if (!name || helper.isEmpty(definitions)) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
return definitions && definitions[name];
|
|
37
|
+
};
|
|
38
|
+
Root.prototype.render = function () {
|
|
39
|
+
var _a = this.props, schema = _a.schema, rootStore = _a.rootStore, env = _a.env, pathPrefix = _a.pathPrefix, location = _a.location, data = _a.data, locale$1 = _a.locale, translate = _a.translate, rest = tslib.__rest(_a, ["schema", "rootStore", "env", "pathPrefix", "location", "data", "locale", "translate"]);
|
|
40
|
+
var theme$1 = env.theme;
|
|
41
|
+
var themeName = this.props.theme || 'cxd';
|
|
42
|
+
if (themeName === 'default') {
|
|
43
|
+
themeName = 'cxd';
|
|
44
|
+
}
|
|
45
|
+
return (React__default["default"].createElement(WithRootStore.RootStoreContext.Provider, { value: rootStore },
|
|
46
|
+
React__default["default"].createElement(theme.ThemeContext.Provider, { value: themeName },
|
|
47
|
+
React__default["default"].createElement(locale.LocaleContext.Provider, { value: this.props.locale },
|
|
48
|
+
React__default["default"].createElement(RootRenderer.RootRenderer, tslib.__assign({ pathPrefix: pathPrefix || '', schema: isPlainObject__default["default"](schema)
|
|
49
|
+
? tslib.__assign({ type: 'page' }, schema) : schema }, rest, { render: renderChild, rootStore: rootStore, resolveDefinitions: this.resolveDefinitions, location: location, data: data, env: env, classnames: theme$1.classnames, classPrefix: theme$1.classPrefix, locale: locale$1, translate: translate }))))));
|
|
50
|
+
};
|
|
51
|
+
tslib.__decorate([
|
|
52
|
+
helper.autobind,
|
|
53
|
+
tslib.__metadata("design:type", Function),
|
|
54
|
+
tslib.__metadata("design:paramtypes", [String]),
|
|
55
|
+
tslib.__metadata("design:returntype", void 0)
|
|
56
|
+
], Root.prototype, "resolveDefinitions", null);
|
|
57
|
+
return Root;
|
|
58
|
+
}(React__default["default"].Component));
|
|
59
|
+
function renderChildren(prefix, node, props) {
|
|
60
|
+
if (Array.isArray(node)) {
|
|
61
|
+
return node.map(function (node, index) {
|
|
62
|
+
return renderChild("".concat(prefix, "/").concat(index), node, tslib.__assign(tslib.__assign({}, props), { key: "".concat(props.key ? "".concat(props.key, "-") : '').concat(index) }));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return renderChild(prefix, node, props);
|
|
66
|
+
}
|
|
67
|
+
function renderChild(prefix, node, props) {
|
|
68
|
+
if (Array.isArray(node)) {
|
|
69
|
+
return renderChildren(prefix, node, props);
|
|
70
|
+
}
|
|
71
|
+
var typeofnode = typeof node;
|
|
72
|
+
if (typeofnode === 'undefined' || node === null) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
else if (React__default["default"].isValidElement(node)) {
|
|
76
|
+
return node;
|
|
77
|
+
}
|
|
78
|
+
var schema = typeofnode === 'string' || typeofnode === 'number'
|
|
79
|
+
? { type: 'tpl', tpl: String(node) }
|
|
80
|
+
: node;
|
|
81
|
+
var transform = props.propsTransform;
|
|
82
|
+
if (transform) {
|
|
83
|
+
props = tslib.__assign({}, props);
|
|
84
|
+
delete props.propsTransform;
|
|
85
|
+
props = transform(props);
|
|
86
|
+
}
|
|
87
|
+
return (React__default["default"].createElement(SchemaRenderer.SchemaRenderer, tslib.__assign({}, props, { schema: schema, propKey: schema.key, "$path": "".concat(prefix ? "".concat(prefix, "/") : '').concat((schema && schema.type) || '') })));
|
|
88
|
+
}
|
|
89
|
+
var ScopedRootRenderer = Scoped.HocScoped(Root);
|
|
90
|
+
|
|
91
|
+
exports.Root = Root;
|
|
92
|
+
exports["default"] = ScopedRootRenderer;
|
|
93
|
+
exports.renderChild = renderChild;
|
|
94
|
+
exports.renderChildren = renderChildren;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* amis-core v1.0.0-beta.0
|
|
3
|
+
* Copyright 2018-2022 fex
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var tslib = require('tslib');
|
|
11
|
+
var mobxReact = require('mobx-react');
|
|
12
|
+
var React = require('react');
|
|
13
|
+
var Scoped = require('./Scoped.js');
|
|
14
|
+
var root = require('./store/root.js');
|
|
15
|
+
var helper = require('./utils/helper.js');
|
|
16
|
+
var tpl = require('./utils/tpl.js');
|
|
17
|
+
var qs = require('qs');
|
|
18
|
+
var pick = require('lodash/pick');
|
|
19
|
+
var mapValues = require('lodash/mapValues');
|
|
20
|
+
var fileSaver = require('file-saver');
|
|
21
|
+
var api = require('./utils/api.js');
|
|
22
|
+
|
|
23
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
24
|
+
|
|
25
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
26
|
+
var qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
|
|
27
|
+
var pick__default = /*#__PURE__*/_interopDefaultLegacy(pick);
|
|
28
|
+
var mapValues__default = /*#__PURE__*/_interopDefaultLegacy(mapValues);
|
|
29
|
+
|
|
30
|
+
var RootRenderer = /** @class */ (function (_super) {
|
|
31
|
+
tslib.__extends(RootRenderer, _super);
|
|
32
|
+
function RootRenderer(props) {
|
|
33
|
+
var _this = _super.call(this, props) || this;
|
|
34
|
+
_this.store = props.rootStore.addStore({
|
|
35
|
+
id: helper.guid(),
|
|
36
|
+
path: _this.props.$path,
|
|
37
|
+
storeType: root.RootStore.name,
|
|
38
|
+
parentId: ''
|
|
39
|
+
});
|
|
40
|
+
_this.store.initData(props.data);
|
|
41
|
+
_this.store.updateLocation(props.location);
|
|
42
|
+
helper.bulkBindFunctions(_this, [
|
|
43
|
+
'handleAction',
|
|
44
|
+
'handleDialogConfirm',
|
|
45
|
+
'handleDialogClose',
|
|
46
|
+
'handleDrawerConfirm',
|
|
47
|
+
'handleDrawerClose',
|
|
48
|
+
'handlePageVisibilityChange'
|
|
49
|
+
]);
|
|
50
|
+
return _this;
|
|
51
|
+
}
|
|
52
|
+
RootRenderer.prototype.componentDidMount = function () {
|
|
53
|
+
document.addEventListener('visibilitychange', this.handlePageVisibilityChange);
|
|
54
|
+
};
|
|
55
|
+
RootRenderer.prototype.componentDidUpdate = function (prevProps) {
|
|
56
|
+
var props = this.props;
|
|
57
|
+
if (props.data !== prevProps.data) {
|
|
58
|
+
this.store.initData(props.data);
|
|
59
|
+
}
|
|
60
|
+
if (props.location !== prevProps.location) {
|
|
61
|
+
this.store.updateLocation(props.location);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
RootRenderer.prototype.componentDidCatch = function (error, errorInfo) {
|
|
65
|
+
this.store.setRuntimeError(error, errorInfo);
|
|
66
|
+
};
|
|
67
|
+
RootRenderer.prototype.componentWillUnmount = function () {
|
|
68
|
+
this.props.rootStore.removeStore(this.store);
|
|
69
|
+
document.removeEventListener('visibilitychange', this.handlePageVisibilityChange);
|
|
70
|
+
};
|
|
71
|
+
RootRenderer.prototype.handlePageVisibilityChange = function () {
|
|
72
|
+
var env = this.props.env;
|
|
73
|
+
if (document.visibilityState === 'hidden') {
|
|
74
|
+
env === null || env === void 0 ? void 0 : env.tracker({
|
|
75
|
+
eventType: 'pageHidden'
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else if (document.visibilityState === 'visible') {
|
|
79
|
+
env === null || env === void 0 ? void 0 : env.tracker({
|
|
80
|
+
eventType: 'pageVisible'
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
RootRenderer.prototype.handleAction = function (e, action, ctx, throwErrors, delegate) {
|
|
85
|
+
var _this = this;
|
|
86
|
+
var _a, _b;
|
|
87
|
+
if (throwErrors === void 0) { throwErrors = false; }
|
|
88
|
+
var _c = this.props, env = _c.env, messages = _c.messages, onAction = _c.onAction, render = _c.render;
|
|
89
|
+
var store = this.store;
|
|
90
|
+
if ((onAction === null || onAction === void 0 ? void 0 : onAction(e, action, ctx, throwErrors, delegate || this.context)) ===
|
|
91
|
+
false) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
var scoped = delegate || this.context;
|
|
95
|
+
if (action.actionType === 'reload') {
|
|
96
|
+
action.target && scoped.reload(action.target, ctx);
|
|
97
|
+
}
|
|
98
|
+
else if (action.target) {
|
|
99
|
+
action.target.split(',').forEach(function (name) {
|
|
100
|
+
var target = scoped.getComponentByName(name);
|
|
101
|
+
target &&
|
|
102
|
+
target.doAction &&
|
|
103
|
+
target.doAction(tslib.__assign(tslib.__assign({}, action), { target: undefined }), ctx);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else if (action.actionType === 'url' ||
|
|
107
|
+
action.actionType === 'link' ||
|
|
108
|
+
action.actionType === 'jump') {
|
|
109
|
+
if (!env || !env.jumpTo) {
|
|
110
|
+
throw new Error('env.jumpTo is required!');
|
|
111
|
+
}
|
|
112
|
+
env.jumpTo(tpl.filter((action.to || action.url || action.link), ctx, '| raw'), action, ctx);
|
|
113
|
+
}
|
|
114
|
+
else if (action.actionType === 'email') {
|
|
115
|
+
var mailTo = tpl.filter(action.to, ctx);
|
|
116
|
+
var mailInfo = mapValues__default["default"](pick__default["default"](action, 'to', 'cc', 'bcc', 'subject', 'body'), function (val) { return tpl.filter(val, ctx); });
|
|
117
|
+
var mailStr = qs__default["default"].stringify(mailInfo);
|
|
118
|
+
var mailto = "mailto:".concat(mailTo, "?").concat(mailStr);
|
|
119
|
+
window.open(mailto);
|
|
120
|
+
}
|
|
121
|
+
else if (action.actionType === 'dialog') {
|
|
122
|
+
store.setCurrentAction(action);
|
|
123
|
+
store.openDialog(ctx);
|
|
124
|
+
}
|
|
125
|
+
else if (action.actionType === 'drawer') {
|
|
126
|
+
store.setCurrentAction(action);
|
|
127
|
+
store.openDrawer(ctx);
|
|
128
|
+
}
|
|
129
|
+
else if (action.actionType === 'toast') {
|
|
130
|
+
(_b = (_a = action.toast) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.forEach(function (item) {
|
|
131
|
+
env.notify(item.level || 'info', item.body
|
|
132
|
+
? render('body', item.body, tslib.__assign(tslib.__assign({}, _this.props), { data: ctx }))
|
|
133
|
+
: '', tslib.__assign(tslib.__assign(tslib.__assign({}, action.toast), item), { title: item.title
|
|
134
|
+
? render('title', item.title, tslib.__assign(tslib.__assign({}, _this.props), { data: ctx }))
|
|
135
|
+
: null, useMobileUI: env.useMobileUI }));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else if (action.actionType === 'ajax') {
|
|
139
|
+
store.setCurrentAction(action);
|
|
140
|
+
store
|
|
141
|
+
.saveRemote(action.api, ctx, {
|
|
142
|
+
successMessage: (action.messages && action.messages.success) ||
|
|
143
|
+
(messages && messages.saveSuccess),
|
|
144
|
+
errorMessage: (action.messages && action.messages.failed) ||
|
|
145
|
+
(messages && messages.saveSuccess)
|
|
146
|
+
})
|
|
147
|
+
.then(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
148
|
+
var redirect;
|
|
149
|
+
return tslib.__generator(this, function (_a) {
|
|
150
|
+
switch (_a.label) {
|
|
151
|
+
case 0:
|
|
152
|
+
if (!(action.feedback && helper.isVisible(action.feedback, store.data))) return [3 /*break*/, 2];
|
|
153
|
+
return [4 /*yield*/, this.openFeedback(action.feedback, store.data)];
|
|
154
|
+
case 1:
|
|
155
|
+
_a.sent();
|
|
156
|
+
_a.label = 2;
|
|
157
|
+
case 2:
|
|
158
|
+
redirect = action.redirect && tpl.filter(action.redirect, store.data);
|
|
159
|
+
redirect && env.jumpTo(redirect, action);
|
|
160
|
+
action.reload &&
|
|
161
|
+
this.reloadTarget(delegate || this.context, action.reload, store.data);
|
|
162
|
+
return [2 /*return*/];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}); })
|
|
166
|
+
.catch(function (e) {
|
|
167
|
+
if (throwErrors || action.countDown) {
|
|
168
|
+
throw e;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
else if (action.actionType === 'copy' &&
|
|
173
|
+
(action.content || action.copy)) {
|
|
174
|
+
env.copy &&
|
|
175
|
+
env.copy(tpl.filter(action.content || action.copy, ctx, '| raw'), {
|
|
176
|
+
format: action.copyFormat
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else if (action.actionType === 'saveAs') {
|
|
180
|
+
// 使用 saveAs 实现下载
|
|
181
|
+
// 不支持 env,除非以后将 saveAs 代码拷过来改
|
|
182
|
+
var api$1 = api.normalizeApi(action.api);
|
|
183
|
+
if (typeof api$1.url === 'string') {
|
|
184
|
+
var fileName = action.fileName || 'data.txt';
|
|
185
|
+
if (api$1.url.indexOf('.') !== -1) {
|
|
186
|
+
fileName = api$1.url.split('/').pop();
|
|
187
|
+
}
|
|
188
|
+
fileSaver.saveAs(api$1.url, fileName);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
RootRenderer.prototype.handleDialogConfirm = function (values, action) {
|
|
193
|
+
var args = [];
|
|
194
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
195
|
+
args[_i - 2] = arguments[_i];
|
|
196
|
+
}
|
|
197
|
+
var store = this.store;
|
|
198
|
+
if (action.mergeData && values.length === 1 && values[0]) {
|
|
199
|
+
store.updateData(values[0]);
|
|
200
|
+
}
|
|
201
|
+
var dialog = store.action.dialog;
|
|
202
|
+
if (dialog &&
|
|
203
|
+
dialog.onConfirm &&
|
|
204
|
+
dialog.onConfirm.apply(dialog, tslib.__spreadArray([values, action], args, false)) === false) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
store.closeDialog(true);
|
|
208
|
+
};
|
|
209
|
+
RootRenderer.prototype.handleDialogClose = function (confirmed) {
|
|
210
|
+
if (confirmed === void 0) { confirmed = false; }
|
|
211
|
+
var store = this.store;
|
|
212
|
+
store.closeDialog(confirmed);
|
|
213
|
+
};
|
|
214
|
+
RootRenderer.prototype.handleDrawerConfirm = function (values, action) {
|
|
215
|
+
var args = [];
|
|
216
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
217
|
+
args[_i - 2] = arguments[_i];
|
|
218
|
+
}
|
|
219
|
+
var store = this.store;
|
|
220
|
+
if (action.mergeData && values.length === 1 && values[0]) {
|
|
221
|
+
store.updateData(values[0]);
|
|
222
|
+
}
|
|
223
|
+
var drawer = store.action.drawer;
|
|
224
|
+
if (drawer &&
|
|
225
|
+
drawer.onConfirm &&
|
|
226
|
+
drawer.onConfirm.apply(drawer, tslib.__spreadArray([values, action], args, false)) === false) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
store.closeDrawer();
|
|
230
|
+
};
|
|
231
|
+
RootRenderer.prototype.handleDrawerClose = function () {
|
|
232
|
+
var store = this.store;
|
|
233
|
+
store.closeDrawer();
|
|
234
|
+
};
|
|
235
|
+
RootRenderer.prototype.openFeedback = function (dialog, ctx) {
|
|
236
|
+
var _this = this;
|
|
237
|
+
return new Promise(function (resolve) {
|
|
238
|
+
var store = _this.store;
|
|
239
|
+
store.setCurrentAction({
|
|
240
|
+
type: 'button',
|
|
241
|
+
actionType: 'dialog',
|
|
242
|
+
dialog: dialog
|
|
243
|
+
});
|
|
244
|
+
store.openDialog(ctx, undefined, function (confirmed) {
|
|
245
|
+
resolve(confirmed);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
RootRenderer.prototype.reloadTarget = function (scoped, target, data) {
|
|
250
|
+
scoped.reload(target, data);
|
|
251
|
+
};
|
|
252
|
+
RootRenderer.prototype.render = function () {
|
|
253
|
+
var _a;
|
|
254
|
+
var _b = this.props, pathPrefix = _b.pathPrefix, schema = _b.schema, render = _b.render, rest = tslib.__rest(_b, ["pathPrefix", "schema", "render"]);
|
|
255
|
+
var store = this.store;
|
|
256
|
+
if (store.runtimeError) {
|
|
257
|
+
return render('error', {
|
|
258
|
+
type: 'alert',
|
|
259
|
+
level: 'danger'
|
|
260
|
+
}, tslib.__assign(tslib.__assign({}, rest), { body: (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
261
|
+
React__default["default"].createElement("h3", null, (_a = this.store.runtimeError) === null || _a === void 0 ? void 0 : _a.toString()),
|
|
262
|
+
React__default["default"].createElement("pre", null,
|
|
263
|
+
React__default["default"].createElement("code", null, this.store.runtimeErrorStack.componentStack)))) }));
|
|
264
|
+
}
|
|
265
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
266
|
+
render(pathPrefix, schema, tslib.__assign(tslib.__assign({}, rest), { data: this.store.downStream, onAction: this.handleAction })),
|
|
267
|
+
render('spinner', {
|
|
268
|
+
type: 'spinner'
|
|
269
|
+
}, tslib.__assign(tslib.__assign({}, rest), { show: store.loading })),
|
|
270
|
+
store.error
|
|
271
|
+
? render('error', {
|
|
272
|
+
type: 'alert'
|
|
273
|
+
}, tslib.__assign(tslib.__assign({}, rest), { body: store.msg, showCloseButton: true, onClose: store.clearMessage }))
|
|
274
|
+
: null,
|
|
275
|
+
render('dialog', tslib.__assign(tslib.__assign({}, (store.action &&
|
|
276
|
+
store.action.dialog)), { type: 'dialog' }), tslib.__assign(tslib.__assign({}, rest), { key: 'dialog', data: store.dialogData, onConfirm: this.handleDialogConfirm, onClose: this.handleDialogClose, show: store.dialogOpen, onAction: this.handleAction })),
|
|
277
|
+
render('drawer', tslib.__assign(tslib.__assign({}, (store.action &&
|
|
278
|
+
store.action.drawer)), { type: 'drawer' }), tslib.__assign(tslib.__assign({}, rest), { key: 'drawer', data: store.drawerData, onConfirm: this.handleDrawerConfirm, onClose: this.handleDrawerClose, show: store.drawerOpen, onAction: this.handleAction }))));
|
|
279
|
+
};
|
|
280
|
+
RootRenderer.contextType = Scoped.ScopedContext;
|
|
281
|
+
RootRenderer = tslib.__decorate([
|
|
282
|
+
mobxReact.observer,
|
|
283
|
+
tslib.__metadata("design:paramtypes", [Object])
|
|
284
|
+
], RootRenderer);
|
|
285
|
+
return RootRenderer;
|
|
286
|
+
}(React__default["default"].Component));
|
|
287
|
+
|
|
288
|
+
exports.RootRenderer = RootRenderer;
|