@alicloud/alfa-react 1.2.2 → 1.3.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/index.js +7 -7
- package/es/app.js +45 -40
- package/es/components/ErrorBoundary/ErrorPanel.js +2 -2
- package/es/components/ErrorBoundary/index.js +15 -15
- package/es/components/Loading/Skeleton.js +1 -1
- package/es/components/Loading/Title.js +1 -1
- package/es/createAlfaApp.js +31 -0
- package/es/createAlfaWidget.js +73 -0
- package/es/createApplication.js +116 -0
- package/es/hooks/afterLoad.js +60 -0
- package/es/hooks/afterLoadHook.js +69 -0
- package/es/hooks/beforeResolveHook.js +55 -0
- package/es/index.js +2 -2
- package/es/types/base.js +26 -0
- package/es/types/index.js +1 -0
- package/es/types.js +1 -0
- package/es/utils/checkOptions.js +13 -0
- package/es/utils/getConsoleConfig.js +88 -0
- package/es/utils/index.js +3 -0
- package/es/version.js +1 -0
- package/es/widget/emitter.js +4 -4
- package/es/widget/getWidgetConfigById.js +5 -6
- package/es/widget/getWidgetDeps.js +4 -4
- package/es/widget.js +2 -2
- package/lib/app.d.ts +2 -1
- package/lib/app.js +50 -42
- package/lib/base.d.ts +4 -1
- package/lib/components/ErrorBoundary/ErrorPanel.d.ts +1 -1
- package/lib/components/ErrorBoundary/ErrorPanel.js +2 -2
- package/lib/components/ErrorBoundary/index.d.ts +7 -9
- package/lib/components/ErrorBoundary/index.js +15 -15
- package/lib/components/Loading/Paragraph.js +6 -2
- package/lib/components/Loading/Skeleton.js +7 -3
- package/lib/components/Loading/Title.d.ts +1 -0
- package/lib/components/Loading/Title.js +7 -3
- package/lib/createAlfaApp.d.ts +4 -0
- package/lib/createAlfaApp.js +49 -0
- package/lib/createAlfaWidget.d.ts +4 -0
- package/lib/createAlfaWidget.js +94 -0
- package/lib/createApplication.d.ts +13 -0
- package/lib/createApplication.js +136 -0
- package/lib/hooks/afterLoad.d.ts +3 -0
- package/lib/hooks/afterLoad.js +75 -0
- package/lib/hooks/afterLoadHook.d.ts +3 -0
- package/lib/hooks/afterLoadHook.js +84 -0
- package/lib/hooks/beforeResolve.d.ts +1 -0
- package/lib/hooks/beforeResolve.js +73 -0
- package/lib/hooks/beforeResolveHook.d.ts +3 -0
- package/lib/hooks/beforeResolveHook.js +69 -0
- package/lib/hooks/resolveManifest.js +73 -0
- package/lib/hooks/sendRecord.d.ts +3 -0
- package/lib/hooks/sendRecord.js +40 -0
- package/lib/hooks/sls.js +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +13 -11
- package/lib/types/base.d.ts +11 -0
- package/lib/types/base.js +37 -0
- package/lib/types/index.d.ts +86 -0
- package/lib/types/index.js +5 -0
- package/lib/types.d.ts +5 -7
- package/lib/types.js +5 -1
- package/lib/utils/checkOptions.d.ts +0 -0
- package/lib/utils/checkOptions.js +14 -0
- package/lib/utils/getConsoleConfig.d.ts +21 -0
- package/lib/{app → utils}/getConsoleConfig.js +48 -8
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +12 -0
- package/lib/utils/logger.d.ts +15 -0
- package/lib/utils/logger.js +92 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +8 -0
- package/lib/widget/emitter.d.ts +0 -1
- package/lib/widget/emitter.js +4 -4
- package/lib/widget/getWidgetConfigById.js +5 -6
- package/lib/widget/getWidgetDeps.js +9 -5
- package/lib/widget.d.ts +2 -1
- package/lib/widget.js +9 -5
- package/package.json +13 -7
- package/LICENSE +0 -21
- package/es/app/getConsoleConfig.js +0 -49
- package/lib/app/getConsoleConfig.d.ts +0 -2
package/es/app.js
CHANGED
|
@@ -4,15 +4,16 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
4
4
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
5
5
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
6
|
|
|
7
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
8
8
|
|
|
9
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
10
10
|
|
|
11
11
|
import React, { Suspense, lazy, useRef, useEffect, useState } from 'react';
|
|
12
|
-
import { getManifest, createMicroApp } from '@alicloud/alfa-core';
|
|
12
|
+
import { getManifest, getLocale, createMicroApp } from '@alicloud/alfa-core';
|
|
13
13
|
import Loading from './components/Loading';
|
|
14
|
+
import { AlfaFactoryOption } from './types';
|
|
14
15
|
import ErrorBoundary from './components/ErrorBoundary';
|
|
15
|
-
import { getConsoleConfig } from './
|
|
16
|
+
import { getConsoleConfig } from './utils/getConsoleConfig';
|
|
16
17
|
import { normalizeName } from './utils';
|
|
17
18
|
|
|
18
19
|
var getProps = function getProps(props) {
|
|
@@ -23,10 +24,8 @@ var getProps = function getProps(props) {
|
|
|
23
24
|
delete parcelProps.loading;
|
|
24
25
|
delete parcelProps.entry;
|
|
25
26
|
delete parcelProps.container;
|
|
26
|
-
delete parcelProps.logger;
|
|
27
|
-
|
|
28
|
-
delete parcelProps.env; // @ts-ignore
|
|
29
|
-
|
|
27
|
+
delete parcelProps.logger;
|
|
28
|
+
delete parcelProps.env;
|
|
30
29
|
delete parcelProps.dependencies;
|
|
31
30
|
return parcelProps;
|
|
32
31
|
};
|
|
@@ -37,7 +36,8 @@ var Application = function Application(props) {
|
|
|
37
36
|
loading = props.loading,
|
|
38
37
|
style = props.style,
|
|
39
38
|
className = props.className,
|
|
40
|
-
consoleConfig = props.consoleConfig
|
|
39
|
+
consoleConfig = props.consoleConfig,
|
|
40
|
+
i18nMessages = props.i18nMessages;
|
|
41
41
|
|
|
42
42
|
var _useState = useState(false),
|
|
43
43
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -52,7 +52,7 @@ var Application = function Application(props) {
|
|
|
52
52
|
var appRef = useRef(null);
|
|
53
53
|
useEffect(function () {
|
|
54
54
|
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
55
|
-
var
|
|
55
|
+
var App;
|
|
56
56
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
57
57
|
while (1) {
|
|
58
58
|
switch (_context.prev = _context.next) {
|
|
@@ -66,27 +66,35 @@ var Application = function Application(props) {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
case 2:
|
|
69
|
-
|
|
69
|
+
App = _context.sent;
|
|
70
70
|
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
if (App.context && App.context) {
|
|
72
|
+
App.context.window.ALIYUN_CONSOLE_CONFIG = consoleConfig;
|
|
73
|
+
App.context.window.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
_context.next = 6;
|
|
77
|
-
return
|
|
77
|
+
return App.load();
|
|
78
78
|
|
|
79
79
|
case 6:
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
if (appRef.current) {
|
|
81
|
+
_context.next = 8;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return _context.abrupt("return");
|
|
86
|
+
|
|
87
|
+
case 8:
|
|
88
|
+
_context.next = 10;
|
|
89
|
+
return App.mount(appRef.current, {
|
|
82
90
|
customProps: getProps(props)
|
|
83
91
|
});
|
|
84
92
|
|
|
85
|
-
case
|
|
93
|
+
case 10:
|
|
86
94
|
setMounted(true);
|
|
87
|
-
setApp(
|
|
95
|
+
setApp(App);
|
|
88
96
|
|
|
89
|
-
case
|
|
97
|
+
case 12:
|
|
90
98
|
case "end":
|
|
91
99
|
return _context.stop();
|
|
92
100
|
}
|
|
@@ -110,11 +118,9 @@ var Application = function Application(props) {
|
|
|
110
118
|
className: className,
|
|
111
119
|
ref: appRef,
|
|
112
120
|
dataId: name
|
|
113
|
-
}) : /*#__PURE__*/React.createElement(name, {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
})
|
|
117
|
-
}));
|
|
121
|
+
}) : /*#__PURE__*/React.createElement(name, {}, /*#__PURE__*/React.createElement('div', {
|
|
122
|
+
ref: appRef
|
|
123
|
+
})));
|
|
118
124
|
};
|
|
119
125
|
|
|
120
126
|
export function createAlfaApp(option) {
|
|
@@ -122,7 +128,7 @@ export function createAlfaApp(option) {
|
|
|
122
128
|
loading = option.loading,
|
|
123
129
|
manifest = option.manifest;
|
|
124
130
|
var AlfaApp = /*#__PURE__*/lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
125
|
-
var resolvedManifest, consoleConfig,
|
|
131
|
+
var resolvedManifest, consoleConfig, messages, i18nMessages, App;
|
|
126
132
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
127
133
|
while (1) {
|
|
128
134
|
switch (_context2.prev = _context2.next) {
|
|
@@ -141,35 +147,34 @@ export function createAlfaApp(option) {
|
|
|
141
147
|
resolvedManifest = _context2.sent;
|
|
142
148
|
|
|
143
149
|
case 5:
|
|
144
|
-
// @ts-ignore
|
|
145
150
|
consoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
|
|
146
|
-
|
|
147
|
-
if (!option.dynamicConfig) {
|
|
148
|
-
_context2.next = 10;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
_context2.next = 9;
|
|
151
|
+
_context2.next = 8;
|
|
153
152
|
return getConsoleConfig(option, consoleConfig);
|
|
154
153
|
|
|
155
|
-
case
|
|
154
|
+
case 8:
|
|
156
155
|
consoleConfig = _context2.sent;
|
|
156
|
+
_context2.next = 11;
|
|
157
|
+
return getLocale(option);
|
|
158
|
+
|
|
159
|
+
case 11:
|
|
160
|
+
messages = _context2.sent;
|
|
161
|
+
i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages);
|
|
157
162
|
|
|
158
|
-
|
|
159
|
-
AlfaApp = function AlfaApp(props) {
|
|
163
|
+
App = function App(props) {
|
|
160
164
|
return /*#__PURE__*/React.createElement(Application, _extends({
|
|
161
165
|
manifest: resolvedManifest
|
|
162
166
|
}, props, {
|
|
163
167
|
name: normalizeName(name),
|
|
164
|
-
consoleConfig: consoleConfig
|
|
168
|
+
consoleConfig: consoleConfig,
|
|
169
|
+
i18nMessages: i18nMessages
|
|
165
170
|
}));
|
|
166
171
|
};
|
|
167
172
|
|
|
168
173
|
return _context2.abrupt("return", {
|
|
169
|
-
default:
|
|
174
|
+
default: App
|
|
170
175
|
});
|
|
171
176
|
|
|
172
|
-
case
|
|
177
|
+
case 15:
|
|
173
178
|
case "end":
|
|
174
179
|
return _context2.stop();
|
|
175
180
|
}
|
|
@@ -186,4 +191,4 @@ export function createAlfaApp(option) {
|
|
|
186
191
|
}, props))));
|
|
187
192
|
};
|
|
188
193
|
}
|
|
189
|
-
export { AlfaFactoryOption }
|
|
194
|
+
export { AlfaFactoryOption };
|
|
@@ -21,11 +21,11 @@ var ErrorPanel = function ErrorPanel(props) {
|
|
|
21
21
|
style: containerStyle
|
|
22
22
|
}, /*#__PURE__*/React.createElement("div", {
|
|
23
23
|
style: commonErrorStyle
|
|
24
|
-
}, error.message), /*#__PURE__*/React.createElement("pre", {
|
|
24
|
+
}, error === null || error === void 0 ? void 0 : error.message), /*#__PURE__*/React.createElement("pre", {
|
|
25
25
|
style: {
|
|
26
26
|
overflow: 'scroll'
|
|
27
27
|
}
|
|
28
|
-
}, error.stack)) : /*#__PURE__*/React.createElement("div", {
|
|
28
|
+
}, error === null || error === void 0 ? void 0 : error.stack)) : /*#__PURE__*/React.createElement("div", {
|
|
29
29
|
style: commonErrorStyle
|
|
30
30
|
}, "Error"));
|
|
31
31
|
};
|
|
@@ -25,7 +25,6 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
25
25
|
_this = _super.call(this, props);
|
|
26
26
|
_this.state = {
|
|
27
27
|
hasError: false,
|
|
28
|
-
// @ts-ignore
|
|
29
28
|
error: null
|
|
30
29
|
};
|
|
31
30
|
return _this;
|
|
@@ -34,23 +33,24 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
34
33
|
_createClass(ErrorBoundary, [{
|
|
35
34
|
key: "componentDidCatch",
|
|
36
35
|
value: function componentDidCatch(error, errorInfo) {
|
|
37
|
-
|
|
36
|
+
var _window, _window$__bl, _window2, _window2$__bl;
|
|
37
|
+
|
|
38
|
+
var _this$props = this.props,
|
|
39
|
+
appDidCatch = _this$props.appDidCatch,
|
|
40
|
+
logger = _this$props.logger; // Display fallback UI
|
|
41
|
+
|
|
38
42
|
this.setState({
|
|
39
43
|
hasError: true,
|
|
40
44
|
error: error
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
console.error(error);
|
|
53
|
-
this.props.appDidCatch && this.props.appDidCatch(error);
|
|
45
|
+
});
|
|
46
|
+
isFunction((_window = window) === null || _window === void 0 ? void 0 : (_window$__bl = _window.__bl) === null || _window$__bl === void 0 ? void 0 : _window$__bl.error) && ((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$__bl = _window2.__bl) === null || _window2$__bl === void 0 ? void 0 : _window2$__bl.error(error, errorInfo)); // You can also log the error to an error reporting service in appDidCatch
|
|
47
|
+
|
|
48
|
+
appDidCatch && appDidCatch(error, errorInfo);
|
|
49
|
+
logger === null || logger === void 0 ? void 0 : logger.error({
|
|
50
|
+
E_MSG: '',
|
|
51
|
+
E_STACK: error,
|
|
52
|
+
C_STACK: errorInfo
|
|
53
|
+
});
|
|
54
54
|
}
|
|
55
55
|
}, {
|
|
56
56
|
key: "render",
|
|
@@ -6,7 +6,7 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConst
|
|
|
6
6
|
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
7
7
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
8
8
|
|
|
9
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
10
10
|
|
|
11
11
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
12
12
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4
4
|
|
|
5
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
6
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { BaseLoader } from '@alicloud/alfa-core';
|
|
4
|
+
import ErrorBoundary from './components/ErrorBoundary';
|
|
5
|
+
import createApplication from './createApplication';
|
|
6
|
+
import beforeResolveHook from './hooks/beforeResolveHook';
|
|
7
|
+
import afterLoadHook from './hooks/afterLoadHook';
|
|
8
|
+
var loader = BaseLoader.create();
|
|
9
|
+
loader.beforeResolve.use(beforeResolveHook);
|
|
10
|
+
loader.afterLoad.use(afterLoadHook);
|
|
11
|
+
var Application = createApplication(loader);
|
|
12
|
+
|
|
13
|
+
function createAlfaApp(option) {
|
|
14
|
+
var _ref = option || {},
|
|
15
|
+
name = _ref.name,
|
|
16
|
+
dependencies = _ref.dependencies; // check app option
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if (!name) return function () {
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
var passedInOption = option;
|
|
23
|
+
return /*#__PURE__*/React.memo(function (props) {
|
|
24
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, props, /*#__PURE__*/React.createElement(Application, _extends({}, passedInOption, {
|
|
25
|
+
deps: dependencies || {},
|
|
26
|
+
customProps: props
|
|
27
|
+
})));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default createAlfaApp;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { BaseLoader } from '@alicloud/alfa-core';
|
|
6
|
+
import ErrorBoundary from './components/ErrorBoundary';
|
|
7
|
+
import { createCWSWidget } from './widget';
|
|
8
|
+
import createApplication from './createApplication';
|
|
9
|
+
import beforeResolveHook from './hooks/beforeResolveHook';
|
|
10
|
+
import afterLoadHook from './hooks/afterLoadHook';
|
|
11
|
+
var loader = BaseLoader.create();
|
|
12
|
+
loader.beforeResolve.use(beforeResolveHook);
|
|
13
|
+
loader.afterLoad.use(afterLoadHook);
|
|
14
|
+
loader.afterLoad.use( /*#__PURE__*/function () {
|
|
15
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(appConfig) {
|
|
16
|
+
var app;
|
|
17
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
18
|
+
while (1) {
|
|
19
|
+
switch (_context.prev = _context.next) {
|
|
20
|
+
case 0:
|
|
21
|
+
app = appConfig.app;
|
|
22
|
+
|
|
23
|
+
if (app && app.context) {
|
|
24
|
+
// disable history
|
|
25
|
+
app.context.history = {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return _context.abrupt("return", appConfig);
|
|
29
|
+
|
|
30
|
+
case 3:
|
|
31
|
+
case "end":
|
|
32
|
+
return _context.stop();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, _callee);
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
return function (_x) {
|
|
39
|
+
return _ref.apply(this, arguments);
|
|
40
|
+
};
|
|
41
|
+
}());
|
|
42
|
+
var Application = createApplication(loader);
|
|
43
|
+
|
|
44
|
+
function createAlfaApp(option) {
|
|
45
|
+
var _ref2 = option || {},
|
|
46
|
+
name = _ref2.name,
|
|
47
|
+
dependencies = _ref2.dependencies;
|
|
48
|
+
|
|
49
|
+
if (!name.match(/@ali\/widget-/)) {
|
|
50
|
+
// TODO load style
|
|
51
|
+
return createCWSWidget(option);
|
|
52
|
+
} // check app option
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if (!name) return function () {
|
|
56
|
+
return null;
|
|
57
|
+
};
|
|
58
|
+
var passedInOption = option;
|
|
59
|
+
return /*#__PURE__*/React.memo(function (props) {
|
|
60
|
+
return (
|
|
61
|
+
/*#__PURE__*/
|
|
62
|
+
// Compatible with old logic
|
|
63
|
+
// props should not passed in errorBoundary
|
|
64
|
+
React.createElement(ErrorBoundary, props, /*#__PURE__*/React.createElement(Application, _extends({}, passedInOption, {
|
|
65
|
+
// name={name}
|
|
66
|
+
deps: dependencies || {},
|
|
67
|
+
customProps: props
|
|
68
|
+
})))
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default createAlfaApp;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import React, { Suspense, useRef, useEffect, useState } from 'react';
|
|
5
|
+
import Loading from './components/Loading';
|
|
6
|
+
import { normalizeName } from './utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* container for microApp mount
|
|
10
|
+
* @param loader alfa-core loader
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export default function createApplication(loader) {
|
|
14
|
+
return function Application(props) {
|
|
15
|
+
var name = props.name,
|
|
16
|
+
manifest = props.manifest,
|
|
17
|
+
loading = props.loading,
|
|
18
|
+
sandbox = props.sandbox,
|
|
19
|
+
customProps = props.customProps,
|
|
20
|
+
className = props.className,
|
|
21
|
+
style = props.style;
|
|
22
|
+
|
|
23
|
+
var _useState = useState(null),
|
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
25
|
+
app = _useState2[0],
|
|
26
|
+
setApp = _useState2[1];
|
|
27
|
+
|
|
28
|
+
var appRef = useRef(null);
|
|
29
|
+
var tagName = normalizeName(props.name);
|
|
30
|
+
useEffect(function () {
|
|
31
|
+
// eslint-disable-next-line no-useless-catch
|
|
32
|
+
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
33
|
+
var _yield$loader$registe, App, logger;
|
|
34
|
+
|
|
35
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
36
|
+
while (1) {
|
|
37
|
+
switch (_context.prev = _context.next) {
|
|
38
|
+
case 0:
|
|
39
|
+
_context.next = 2;
|
|
40
|
+
return loader.register({
|
|
41
|
+
name: name,
|
|
42
|
+
manifest: manifest,
|
|
43
|
+
container: appRef.current,
|
|
44
|
+
props: customProps,
|
|
45
|
+
sandbox: sandbox
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
case 2:
|
|
49
|
+
_yield$loader$registe = _context.sent;
|
|
50
|
+
App = _yield$loader$registe.app;
|
|
51
|
+
logger = _yield$loader$registe.logger;
|
|
52
|
+
|
|
53
|
+
if (App) {
|
|
54
|
+
_context.next = 7;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return _context.abrupt("return", logger === null || logger === void 0 ? void 0 : logger.error({
|
|
59
|
+
E_MSG: 'load app failed.'
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
case 7:
|
|
63
|
+
_context.next = 9;
|
|
64
|
+
return App.load();
|
|
65
|
+
|
|
66
|
+
case 9:
|
|
67
|
+
if (appRef.current) {
|
|
68
|
+
_context.next = 11;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return _context.abrupt("return", logger === null || logger === void 0 ? void 0 : logger.error({
|
|
73
|
+
E_MSG: 'cannot find container.'
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
case 11:
|
|
77
|
+
_context.next = 13;
|
|
78
|
+
return App.mount(appRef.current, {
|
|
79
|
+
customProps: customProps
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
case 13:
|
|
83
|
+
setApp(App);
|
|
84
|
+
return _context.abrupt("return", function () {
|
|
85
|
+
App && App.unmount();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
case 15:
|
|
89
|
+
case "end":
|
|
90
|
+
return _context.stop();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, _callee);
|
|
94
|
+
}))().catch(function (e) {
|
|
95
|
+
throw e;
|
|
96
|
+
});
|
|
97
|
+
}, [name, manifest, customProps, sandbox]);
|
|
98
|
+
|
|
99
|
+
if (app) {
|
|
100
|
+
app.update(customProps);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return /*#__PURE__*/React.createElement(Suspense, {
|
|
104
|
+
fallback: /*#__PURE__*/React.createElement(Loading, {
|
|
105
|
+
loading: loading
|
|
106
|
+
})
|
|
107
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, sandbox && sandbox !== true && sandbox.disableFakeBody ? /*#__PURE__*/React.createElement(tagName, {
|
|
108
|
+
style: style,
|
|
109
|
+
className: className,
|
|
110
|
+
ref: appRef,
|
|
111
|
+
dataId: name
|
|
112
|
+
}) : /*#__PURE__*/React.createElement(tagName, {}, /*#__PURE__*/React.createElement('div', {
|
|
113
|
+
ref: appRef
|
|
114
|
+
}))));
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
|
|
6
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
+
|
|
8
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
9
|
+
|
|
10
|
+
import { getLocale } from '@alicloud/alfa-core';
|
|
11
|
+
import { getConsoleConfig } from '../utils/getConsoleConfig'; // inject consoleConfig & locales after load
|
|
12
|
+
|
|
13
|
+
function afterLoad(_x) {
|
|
14
|
+
return _afterLoad.apply(this, arguments);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function _afterLoad() {
|
|
18
|
+
_afterLoad = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(appConfig) {
|
|
19
|
+
var app, logger, defaultConsoleConfig, _yield$Promise$all$ca, _yield$Promise$all$ca2, consoleConfig, messages, i18nMessages;
|
|
20
|
+
|
|
21
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
22
|
+
while (1) {
|
|
23
|
+
switch (_context.prev = _context.next) {
|
|
24
|
+
case 0:
|
|
25
|
+
app = appConfig.app, logger = appConfig.logger;
|
|
26
|
+
defaultConsoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
|
|
27
|
+
_context.next = 4;
|
|
28
|
+
return Promise.all([getConsoleConfig(appConfig, defaultConsoleConfig), getLocale(appConfig)]).catch(function (e) {
|
|
29
|
+
logger === null || logger === void 0 ? void 0 : logger.error({
|
|
30
|
+
E_MSG: JSON.stringify(e)
|
|
31
|
+
});
|
|
32
|
+
return [{}, {}];
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
case 4:
|
|
36
|
+
_yield$Promise$all$ca = _context.sent;
|
|
37
|
+
_yield$Promise$all$ca2 = _slicedToArray(_yield$Promise$all$ca, 2);
|
|
38
|
+
consoleConfig = _yield$Promise$all$ca2[0];
|
|
39
|
+
messages = _yield$Promise$all$ca2[1];
|
|
40
|
+
i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages);
|
|
41
|
+
|
|
42
|
+
if (app && app.context) {
|
|
43
|
+
app.context.window.ALIYUN_CONSOLE_CONFIG = consoleConfig;
|
|
44
|
+
app.context.window.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages; // (app.context.history as any) = {};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
logger === null || logger === void 0 ? void 0 : logger.send();
|
|
48
|
+
return _context.abrupt("return", appConfig);
|
|
49
|
+
|
|
50
|
+
case 12:
|
|
51
|
+
case "end":
|
|
52
|
+
return _context.stop();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, _callee);
|
|
56
|
+
}));
|
|
57
|
+
return _afterLoad.apply(this, arguments);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default afterLoad;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
|
|
6
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
+
|
|
8
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
9
|
+
|
|
10
|
+
import { getLocale } from '@alicloud/alfa-core';
|
|
11
|
+
import { getConsoleConfig } from '../utils/getConsoleConfig'; // inject consoleConfig & locales after load
|
|
12
|
+
|
|
13
|
+
function afterLoadHook(_x) {
|
|
14
|
+
return _afterLoadHook.apply(this, arguments);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function _afterLoadHook() {
|
|
18
|
+
_afterLoadHook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(appConfig) {
|
|
19
|
+
var app, logger, defaultConsoleConfig, CONFIG_START_TIME, _yield$Promise$all$ca, _yield$Promise$all$ca2, consoleConfig, messages, CONFIG_END_TIME, i18nMessages, END_TIME;
|
|
20
|
+
|
|
21
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
22
|
+
while (1) {
|
|
23
|
+
switch (_context.prev = _context.next) {
|
|
24
|
+
case 0:
|
|
25
|
+
app = appConfig.app, logger = appConfig.logger;
|
|
26
|
+
defaultConsoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
|
|
27
|
+
CONFIG_START_TIME = Date.now();
|
|
28
|
+
_context.next = 5;
|
|
29
|
+
return Promise.all([getConsoleConfig(appConfig, defaultConsoleConfig), getLocale(appConfig)]).catch(function (e) {
|
|
30
|
+
logger === null || logger === void 0 ? void 0 : logger.error({
|
|
31
|
+
E_MSG: 'fetch config & locale error.',
|
|
32
|
+
E_STACK: e
|
|
33
|
+
});
|
|
34
|
+
return [{}, {}];
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
case 5:
|
|
38
|
+
_yield$Promise$all$ca = _context.sent;
|
|
39
|
+
_yield$Promise$all$ca2 = _slicedToArray(_yield$Promise$all$ca, 2);
|
|
40
|
+
consoleConfig = _yield$Promise$all$ca2[0];
|
|
41
|
+
messages = _yield$Promise$all$ca2[1];
|
|
42
|
+
CONFIG_END_TIME = Date.now();
|
|
43
|
+
i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages);
|
|
44
|
+
|
|
45
|
+
if (app && app.context) {
|
|
46
|
+
app.context.window.ALIYUN_CONSOLE_CONFIG = consoleConfig;
|
|
47
|
+
app.context.window.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages; // (app.context.history as any) = {};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
END_TIME = Date.now();
|
|
51
|
+
logger === null || logger === void 0 ? void 0 : logger.record({
|
|
52
|
+
CONFIG_START_TIME: CONFIG_START_TIME,
|
|
53
|
+
CONFIG_END_TIME: CONFIG_END_TIME,
|
|
54
|
+
END_TIME: END_TIME
|
|
55
|
+
});
|
|
56
|
+
logger === null || logger === void 0 ? void 0 : logger.send();
|
|
57
|
+
return _context.abrupt("return", appConfig);
|
|
58
|
+
|
|
59
|
+
case 16:
|
|
60
|
+
case "end":
|
|
61
|
+
return _context.stop();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}, _callee);
|
|
65
|
+
}));
|
|
66
|
+
return _afterLoadHook.apply(this, arguments);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default afterLoadHook;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { getManifest } from '@alicloud/alfa-core';
|
|
4
|
+
import { version as LOADER_VERSION } from '../version'; // get manifest before resolve
|
|
5
|
+
// normalize name
|
|
6
|
+
|
|
7
|
+
function beforeResolveHook(_x) {
|
|
8
|
+
return _beforeResolveHook.apply(this, arguments);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function _beforeResolveHook() {
|
|
12
|
+
_beforeResolveHook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(appConfig) {
|
|
13
|
+
var resolvedManifest, logger, START_TIME, MANIFEST_START_TIME, MANIFEST_END_TIME;
|
|
14
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
15
|
+
while (1) {
|
|
16
|
+
switch (_context.prev = _context.next) {
|
|
17
|
+
case 0:
|
|
18
|
+
resolvedManifest = appConfig.manifest;
|
|
19
|
+
logger = appConfig.logger;
|
|
20
|
+
START_TIME = Date.now();
|
|
21
|
+
MANIFEST_START_TIME = Date.now();
|
|
22
|
+
|
|
23
|
+
if (resolvedManifest) {
|
|
24
|
+
_context.next = 8;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_context.next = 7;
|
|
29
|
+
return getManifest(appConfig);
|
|
30
|
+
|
|
31
|
+
case 7:
|
|
32
|
+
resolvedManifest = _context.sent;
|
|
33
|
+
|
|
34
|
+
case 8:
|
|
35
|
+
MANIFEST_END_TIME = Date.now();
|
|
36
|
+
logger === null || logger === void 0 ? void 0 : logger.record({
|
|
37
|
+
LOADER_VERSION: LOADER_VERSION,
|
|
38
|
+
START_TIME: START_TIME,
|
|
39
|
+
MANIFEST_START_TIME: MANIFEST_START_TIME,
|
|
40
|
+
MANIFEST_END_TIME: MANIFEST_END_TIME
|
|
41
|
+
});
|
|
42
|
+
appConfig.manifest = resolvedManifest;
|
|
43
|
+
return _context.abrupt("return", appConfig);
|
|
44
|
+
|
|
45
|
+
case 12:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context.stop();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, _callee);
|
|
51
|
+
}));
|
|
52
|
+
return _beforeResolveHook.apply(this, arguments);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default beforeResolveHook;
|