@alicloud/alfa-react 1.3.0-alpha.0 → 1.3.0-canary.10
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/LICENSE +21 -0
- package/dist/index.js +6 -6
- package/es/app/createIsomorphicMicroApp.js +45 -0
- package/es/app/getConsoleConfig.js +49 -0
- package/es/app.js +36 -42
- package/es/components/Loading/index.js +17 -1
- package/es/context.js +7 -0
- package/es/createAlfaApp.js +116 -0
- package/es/createAlfaWidget.js +125 -0
- package/es/createApplication.js +113 -0
- package/es/types/base.js +26 -0
- package/es/types/index.js +1 -0
- package/es/utils/getConsoleConfig.js +5 -3
- package/es/utils/index.js +3 -0
- package/es/utils.js +3 -0
- package/es/widget/emitter.js +4 -4
- package/es/widget/getWidgetConfigById.js +6 -5
- package/es/widget/getWidgetDeps.js +1 -1
- package/es/widget.js +0 -6
- package/lib/app/createIsomorphicMicroApp.d.ts +2 -0
- package/lib/app/createIsomorphicMicroApp.js +65 -0
- package/lib/app/getConsoleConfig.d.ts +2 -0
- package/lib/{utils → app}/getConsoleConfig.js +5 -43
- package/lib/app.d.ts +1 -2
- package/lib/app.js +35 -40
- package/lib/base.d.ts +0 -3
- package/lib/components/Loading/Title.d.ts +0 -1
- package/lib/components/Loading/index.d.ts +5 -2
- package/lib/components/Loading/index.js +18 -1
- package/lib/context.d.ts +7 -0
- package/lib/context.js +15 -0
- package/lib/types.d.ts +0 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +8 -2
- package/lib/widget/emitter.d.ts +1 -0
- package/lib/widget/emitter.js +4 -4
- package/lib/widget/getWidgetConfigById.js +6 -5
- package/lib/widget/getWidgetDeps.js +1 -1
- package/lib/widget.d.ts +0 -1
- package/lib/widget.js +0 -7
- package/package.json +6 -10
- package/lib/utils/getConsoleConfig.d.ts +0 -33
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
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; }
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
import React, { useContext } from 'react';
|
|
8
|
+
import { renderToString } from '@alicloud/alfa-core';
|
|
9
|
+
import EnvContext from '../context';
|
|
10
|
+
import ErrorBoundary from '../components/ErrorBoundary';
|
|
11
|
+
import Loading from '../components/Loading';
|
|
12
|
+
import { normalizeName } from '../utils';
|
|
13
|
+
|
|
14
|
+
var App = function App(props) {
|
|
15
|
+
var env = useContext(EnvContext); // 如果 env 为空,则返回 loading
|
|
16
|
+
|
|
17
|
+
if (!(env !== null && env !== void 0 && env.getJson) || !(env !== null && env !== void 0 && env.fetchBundle) || !(env !== null && env !== void 0 && env.getBundle) || !(env !== null && env !== void 0 && env.fetchJsonResource)) {
|
|
18
|
+
return /*#__PURE__*/React.createElement(Loading, {
|
|
19
|
+
loading: props.loading
|
|
20
|
+
});
|
|
21
|
+
} // get server render string
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var renderString = renderToString(props, env);
|
|
25
|
+
|
|
26
|
+
if (!renderString) {
|
|
27
|
+
return /*#__PURE__*/React.createElement(Loading, {
|
|
28
|
+
loading: props.loading
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return /*#__PURE__*/React.createElement(normalizeName(props.name), {
|
|
33
|
+
children: /*#__PURE__*/React.createElement("div", {
|
|
34
|
+
dangerouslySetInnerHTML: {
|
|
35
|
+
__html: renderString
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export function createIsomorphicAlfaApp(option) {
|
|
42
|
+
return function (props) {
|
|
43
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, props, /*#__PURE__*/React.createElement(App, _objectSpread(_objectSpread({}, props), option)));
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
import { getConfig } from '@alicloud/alfa-core';
|
|
10
|
+
|
|
11
|
+
var mergeConfigDataWithConsoleConfig = function mergeConfigDataWithConsoleConfig(configData, consoleConfig) {
|
|
12
|
+
var _window, _window$ALIYUN_CONSOL;
|
|
13
|
+
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
var channel = ((_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.CHANNEL) || 'OFFICIAL';
|
|
16
|
+
var channelLinks = configData.ALL_CHANNEL_LINKS ? configData.ALL_CHANNEL_LINKS[channel] : {};
|
|
17
|
+
var features = configData.ALL_CHANNEL_FEATURE_STATUS ? configData.ALL_CHANNEL_FEATURE_STATUS[channel] : {};
|
|
18
|
+
return _objectSpread(_objectSpread({}, consoleConfig), {}, {
|
|
19
|
+
CHANNEL_LINKS: channelLinks,
|
|
20
|
+
CHANNEL_FEATURE_STATUS: features
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export var getConsoleConfig = /*#__PURE__*/function () {
|
|
25
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(option, consoleConfig) {
|
|
26
|
+
var configData;
|
|
27
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
28
|
+
while (1) {
|
|
29
|
+
switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
_context.next = 2;
|
|
32
|
+
return getConfig(option);
|
|
33
|
+
|
|
34
|
+
case 2:
|
|
35
|
+
configData = _context.sent;
|
|
36
|
+
return _context.abrupt("return", mergeConfigDataWithConsoleConfig(configData, consoleConfig));
|
|
37
|
+
|
|
38
|
+
case 4:
|
|
39
|
+
case "end":
|
|
40
|
+
return _context.stop();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, _callee);
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
return function getConsoleConfig(_x, _x2) {
|
|
47
|
+
return _ref.apply(this, arguments);
|
|
48
|
+
};
|
|
49
|
+
}();
|
package/es/app.js
CHANGED
|
@@ -9,11 +9,12 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
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,
|
|
12
|
+
import { getManifest, createMicroApp } from '@alicloud/alfa-core';
|
|
13
13
|
import Loading from './components/Loading';
|
|
14
14
|
import ErrorBoundary from './components/ErrorBoundary';
|
|
15
|
-
import { getConsoleConfig } from './
|
|
16
|
-
import {
|
|
15
|
+
import { getConsoleConfig } from './app/getConsoleConfig';
|
|
16
|
+
import { createIsomorphicAlfaApp } from './app/createIsomorphicMicroApp';
|
|
17
|
+
import { normalizeName, isSSR } from './utils';
|
|
17
18
|
|
|
18
19
|
var getProps = function getProps(props) {
|
|
19
20
|
var parcelProps = _objectSpread({}, props);
|
|
@@ -23,8 +24,10 @@ 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
|
-
|
|
27
|
+
delete parcelProps.logger; // @ts-ignore
|
|
28
|
+
|
|
29
|
+
delete parcelProps.env; // @ts-ignore
|
|
30
|
+
|
|
28
31
|
delete parcelProps.dependencies;
|
|
29
32
|
return parcelProps;
|
|
30
33
|
};
|
|
@@ -35,8 +38,7 @@ var Application = function Application(props) {
|
|
|
35
38
|
loading = props.loading,
|
|
36
39
|
style = props.style,
|
|
37
40
|
className = props.className,
|
|
38
|
-
consoleConfig = props.consoleConfig
|
|
39
|
-
i18nMessages = props.i18nMessages;
|
|
41
|
+
consoleConfig = props.consoleConfig;
|
|
40
42
|
|
|
41
43
|
var _useState = useState(false),
|
|
42
44
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -51,7 +53,7 @@ var Application = function Application(props) {
|
|
|
51
53
|
var appRef = useRef(null);
|
|
52
54
|
useEffect(function () {
|
|
53
55
|
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
54
|
-
var
|
|
56
|
+
var app;
|
|
55
57
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
56
58
|
while (1) {
|
|
57
59
|
switch (_context.prev = _context.next) {
|
|
@@ -65,35 +67,27 @@ var Application = function Application(props) {
|
|
|
65
67
|
});
|
|
66
68
|
|
|
67
69
|
case 2:
|
|
68
|
-
|
|
70
|
+
app = _context.sent;
|
|
69
71
|
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
if (app.context && app.context.baseFrame) {
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
app.context.baseFrame.contentWindow.ALIYUN_CONSOLE_CONFIG = consoleConfig;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
_context.next = 6;
|
|
76
|
-
return
|
|
78
|
+
return app.load();
|
|
77
79
|
|
|
78
80
|
case 6:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return _context.abrupt("return");
|
|
85
|
-
|
|
86
|
-
case 8:
|
|
87
|
-
_context.next = 10;
|
|
88
|
-
return App.mount(appRef.current, {
|
|
81
|
+
_context.next = 8;
|
|
82
|
+
return app.mount(appRef.current, {
|
|
89
83
|
customProps: getProps(props)
|
|
90
84
|
});
|
|
91
85
|
|
|
92
|
-
case
|
|
86
|
+
case 8:
|
|
93
87
|
setMounted(true);
|
|
94
|
-
setApp(
|
|
88
|
+
setApp(app);
|
|
95
89
|
|
|
96
|
-
case
|
|
90
|
+
case 10:
|
|
97
91
|
case "end":
|
|
98
92
|
return _context.stop();
|
|
99
93
|
}
|
|
@@ -117,17 +111,24 @@ var Application = function Application(props) {
|
|
|
117
111
|
className: className,
|
|
118
112
|
ref: appRef,
|
|
119
113
|
dataId: name
|
|
120
|
-
}) : /*#__PURE__*/React.createElement(name, {
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
}) : /*#__PURE__*/React.createElement(name, {
|
|
115
|
+
children: /*#__PURE__*/React.createElement('div', {
|
|
116
|
+
ref: appRef
|
|
117
|
+
})
|
|
118
|
+
}));
|
|
123
119
|
};
|
|
124
120
|
|
|
125
121
|
export function createAlfaApp(option) {
|
|
126
122
|
var name = option.name,
|
|
127
123
|
loading = option.loading,
|
|
128
124
|
manifest = option.manifest;
|
|
125
|
+
|
|
126
|
+
if (isSSR()) {
|
|
127
|
+
return createIsomorphicAlfaApp(option);
|
|
128
|
+
}
|
|
129
|
+
|
|
129
130
|
var AlfaApp = /*#__PURE__*/lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
130
|
-
var resolvedManifest, consoleConfig,
|
|
131
|
+
var resolvedManifest, consoleConfig, AlfaApp;
|
|
131
132
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
132
133
|
while (1) {
|
|
133
134
|
switch (_context2.prev = _context2.next) {
|
|
@@ -146,6 +147,7 @@ export function createAlfaApp(option) {
|
|
|
146
147
|
resolvedManifest = _context2.sent;
|
|
147
148
|
|
|
148
149
|
case 5:
|
|
150
|
+
// @ts-ignore
|
|
149
151
|
consoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
|
|
150
152
|
|
|
151
153
|
if (!option.dynamicConfig) {
|
|
@@ -160,28 +162,20 @@ export function createAlfaApp(option) {
|
|
|
160
162
|
consoleConfig = _context2.sent;
|
|
161
163
|
|
|
162
164
|
case 10:
|
|
163
|
-
|
|
164
|
-
return getLocale(option);
|
|
165
|
-
|
|
166
|
-
case 12:
|
|
167
|
-
messages = _context2.sent;
|
|
168
|
-
i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages);
|
|
169
|
-
|
|
170
|
-
App = function App(props) {
|
|
165
|
+
AlfaApp = function AlfaApp(props) {
|
|
171
166
|
return /*#__PURE__*/React.createElement(Application, _extends({
|
|
172
167
|
manifest: resolvedManifest
|
|
173
168
|
}, props, {
|
|
174
169
|
name: normalizeName(name),
|
|
175
|
-
consoleConfig: consoleConfig
|
|
176
|
-
i18nMessages: i18nMessages
|
|
170
|
+
consoleConfig: consoleConfig
|
|
177
171
|
}));
|
|
178
172
|
};
|
|
179
173
|
|
|
180
174
|
return _context2.abrupt("return", {
|
|
181
|
-
default:
|
|
175
|
+
default: AlfaApp
|
|
182
176
|
});
|
|
183
177
|
|
|
184
|
-
case
|
|
178
|
+
case 12:
|
|
185
179
|
case "end":
|
|
186
180
|
return _context2.stop();
|
|
187
181
|
}
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Skeleton from './Skeleton';
|
|
3
|
+
var initialPath = window.location.pathname;
|
|
3
4
|
export default function getLoading(_ref) {
|
|
4
|
-
var loading = _ref.loading
|
|
5
|
+
var loading = _ref.loading,
|
|
6
|
+
microAppContainer = _ref.microAppContainer;
|
|
7
|
+
|
|
8
|
+
// 第一次如果是 ssr 出来的内容直接拿 ssr 的内容作为骨架做展示
|
|
9
|
+
// 防止出现首屏抖动
|
|
10
|
+
if (microAppContainer) {
|
|
11
|
+
var node = document.querySelector(microAppContainer); //@ts-ignore
|
|
12
|
+
|
|
13
|
+
if (initialPath === window.location.pathname && window.__isSSR) {
|
|
14
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
15
|
+
dangerouslySetInnerHTML: {
|
|
16
|
+
__html: node ? node.innerHTML : ''
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
5
21
|
|
|
6
22
|
if (loading === false) {
|
|
7
23
|
return null;
|
package/es/context.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
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 React from 'react';
|
|
11
|
+
import { BaseLoader, getManifest, getLocale } from '@alicloud/alfa-core';
|
|
12
|
+
import ErrorBoundary from './components/ErrorBoundary';
|
|
13
|
+
import { getConsoleConfig } from './utils/getConsoleConfig';
|
|
14
|
+
import createApplication from './createApplication';
|
|
15
|
+
var loader = BaseLoader.create(); // get manifest before resolve
|
|
16
|
+
// normalize name
|
|
17
|
+
|
|
18
|
+
loader.beforeResolve.use( /*#__PURE__*/function () {
|
|
19
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(appConfig) {
|
|
20
|
+
var resolvedManifest;
|
|
21
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
22
|
+
while (1) {
|
|
23
|
+
switch (_context.prev = _context.next) {
|
|
24
|
+
case 0:
|
|
25
|
+
resolvedManifest = appConfig.manifest;
|
|
26
|
+
|
|
27
|
+
if (resolvedManifest) {
|
|
28
|
+
_context.next = 5;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_context.next = 4;
|
|
33
|
+
return getManifest(appConfig);
|
|
34
|
+
|
|
35
|
+
case 4:
|
|
36
|
+
resolvedManifest = _context.sent;
|
|
37
|
+
|
|
38
|
+
case 5:
|
|
39
|
+
return _context.abrupt("return", _objectSpread(_objectSpread({}, appConfig), {}, {
|
|
40
|
+
manifest: resolvedManifest
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
case 6:
|
|
44
|
+
case "end":
|
|
45
|
+
return _context.stop();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, _callee);
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
return function (_x) {
|
|
52
|
+
return _ref.apply(this, arguments);
|
|
53
|
+
};
|
|
54
|
+
}(), undefined); // inject consoleConfig & locales after load
|
|
55
|
+
|
|
56
|
+
loader.afterLoad.use( /*#__PURE__*/function () {
|
|
57
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(appConfig) {
|
|
58
|
+
var app, defaultConsoleConfig, consoleConfig, messages, i18nMessages;
|
|
59
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
60
|
+
while (1) {
|
|
61
|
+
switch (_context2.prev = _context2.next) {
|
|
62
|
+
case 0:
|
|
63
|
+
app = appConfig.app;
|
|
64
|
+
defaultConsoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
|
|
65
|
+
_context2.next = 4;
|
|
66
|
+
return getConsoleConfig(appConfig, defaultConsoleConfig);
|
|
67
|
+
|
|
68
|
+
case 4:
|
|
69
|
+
consoleConfig = _context2.sent;
|
|
70
|
+
_context2.next = 7;
|
|
71
|
+
return getLocale(appConfig);
|
|
72
|
+
|
|
73
|
+
case 7:
|
|
74
|
+
messages = _context2.sent;
|
|
75
|
+
i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages);
|
|
76
|
+
|
|
77
|
+
if (app && app.context) {
|
|
78
|
+
app.context.window.ALIYUN_CONSOLE_CONFIG = consoleConfig;
|
|
79
|
+
app.context.window.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return _context2.abrupt("return", appConfig);
|
|
83
|
+
|
|
84
|
+
case 11:
|
|
85
|
+
case "end":
|
|
86
|
+
return _context2.stop();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, _callee2);
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
return function (_x2) {
|
|
93
|
+
return _ref2.apply(this, arguments);
|
|
94
|
+
};
|
|
95
|
+
}(), undefined);
|
|
96
|
+
var Application = createApplication(loader);
|
|
97
|
+
|
|
98
|
+
function createAlfaApp(option) {
|
|
99
|
+
var _ref3 = option || {},
|
|
100
|
+
name = _ref3.name,
|
|
101
|
+
dependencies = _ref3.dependencies; // check app option
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if (!name) return function () {
|
|
105
|
+
return null;
|
|
106
|
+
};
|
|
107
|
+
var passedInOption = option;
|
|
108
|
+
return /*#__PURE__*/React.memo(function (props) {
|
|
109
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Application, _extends({}, passedInOption, {
|
|
110
|
+
deps: dependencies || {},
|
|
111
|
+
customProps: props
|
|
112
|
+
})));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export default createAlfaApp;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
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 React from 'react';
|
|
11
|
+
import { BaseLoader, getManifest, getLocale } from '@alicloud/alfa-core';
|
|
12
|
+
import ErrorBoundary from './components/ErrorBoundary';
|
|
13
|
+
import { getConsoleConfig } from './utils/getConsoleConfig';
|
|
14
|
+
import { createCWSWidget } from './widget';
|
|
15
|
+
import createApplication from './createApplication';
|
|
16
|
+
var loader = BaseLoader.create(); // get manifest before resolve
|
|
17
|
+
// normalize name
|
|
18
|
+
|
|
19
|
+
loader.beforeResolve.use( /*#__PURE__*/function () {
|
|
20
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(appConfig) {
|
|
21
|
+
var resolvedManifest;
|
|
22
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
23
|
+
while (1) {
|
|
24
|
+
switch (_context.prev = _context.next) {
|
|
25
|
+
case 0:
|
|
26
|
+
resolvedManifest = appConfig.manifest;
|
|
27
|
+
|
|
28
|
+
if (resolvedManifest) {
|
|
29
|
+
_context.next = 5;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_context.next = 4;
|
|
34
|
+
return getManifest(appConfig);
|
|
35
|
+
|
|
36
|
+
case 4:
|
|
37
|
+
resolvedManifest = _context.sent;
|
|
38
|
+
|
|
39
|
+
case 5:
|
|
40
|
+
return _context.abrupt("return", _objectSpread(_objectSpread({}, appConfig), {}, {
|
|
41
|
+
manifest: resolvedManifest
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
case 6:
|
|
45
|
+
case "end":
|
|
46
|
+
return _context.stop();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, _callee);
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
return function (_x) {
|
|
53
|
+
return _ref.apply(this, arguments);
|
|
54
|
+
};
|
|
55
|
+
}(), undefined); // inject consoleConfig & locales after load
|
|
56
|
+
// remove history in vm context
|
|
57
|
+
|
|
58
|
+
loader.afterLoad.use( /*#__PURE__*/function () {
|
|
59
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(appConfig) {
|
|
60
|
+
var app, defaultConsoleConfig, consoleConfig, messages, i18nMessages;
|
|
61
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
62
|
+
while (1) {
|
|
63
|
+
switch (_context2.prev = _context2.next) {
|
|
64
|
+
case 0:
|
|
65
|
+
app = appConfig.app;
|
|
66
|
+
defaultConsoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
|
|
67
|
+
_context2.next = 4;
|
|
68
|
+
return getConsoleConfig(appConfig, defaultConsoleConfig);
|
|
69
|
+
|
|
70
|
+
case 4:
|
|
71
|
+
consoleConfig = _context2.sent;
|
|
72
|
+
_context2.next = 7;
|
|
73
|
+
return getLocale(appConfig);
|
|
74
|
+
|
|
75
|
+
case 7:
|
|
76
|
+
messages = _context2.sent;
|
|
77
|
+
i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages);
|
|
78
|
+
|
|
79
|
+
if (app && app.context) {
|
|
80
|
+
app.context.window.ALIYUN_CONSOLE_CONFIG = consoleConfig;
|
|
81
|
+
app.context.window.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages;
|
|
82
|
+
app.context.history = {};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return _context2.abrupt("return", appConfig);
|
|
86
|
+
|
|
87
|
+
case 11:
|
|
88
|
+
case "end":
|
|
89
|
+
return _context2.stop();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, _callee2);
|
|
93
|
+
}));
|
|
94
|
+
|
|
95
|
+
return function (_x2) {
|
|
96
|
+
return _ref2.apply(this, arguments);
|
|
97
|
+
};
|
|
98
|
+
}(), undefined);
|
|
99
|
+
var Application = createApplication(loader);
|
|
100
|
+
|
|
101
|
+
function createAlfaApp(option) {
|
|
102
|
+
var _ref3 = option || {},
|
|
103
|
+
name = _ref3.name,
|
|
104
|
+
dependencies = _ref3.dependencies;
|
|
105
|
+
|
|
106
|
+
if (!name.match(/@ali\/widget-/)) {
|
|
107
|
+
// TODO load style
|
|
108
|
+
return createCWSWidget(option);
|
|
109
|
+
} // check app option
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
if (!name) return function () {
|
|
113
|
+
return null;
|
|
114
|
+
};
|
|
115
|
+
var passedInOption = option;
|
|
116
|
+
return /*#__PURE__*/React.memo(function (props) {
|
|
117
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Application, _extends({}, passedInOption, {
|
|
118
|
+
// name={name}
|
|
119
|
+
deps: dependencies || {},
|
|
120
|
+
customProps: props
|
|
121
|
+
})));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export default createAlfaApp;
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
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;
|
|
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
|
+
|
|
52
|
+
if (App) {
|
|
53
|
+
_context.next = 6;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw new Error('[alfa-react] load app failed.');
|
|
58
|
+
|
|
59
|
+
case 6:
|
|
60
|
+
_context.next = 8;
|
|
61
|
+
return App.load();
|
|
62
|
+
|
|
63
|
+
case 8:
|
|
64
|
+
if (appRef.current) {
|
|
65
|
+
_context.next = 10;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
throw new Error('[alfa-react] container not found');
|
|
70
|
+
|
|
71
|
+
case 10:
|
|
72
|
+
_context.next = 12;
|
|
73
|
+
return App.mount(appRef.current, {
|
|
74
|
+
customProps: customProps
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
case 12:
|
|
78
|
+
setApp(App);
|
|
79
|
+
return _context.abrupt("return", function () {
|
|
80
|
+
App && App.unmount();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
case 14:
|
|
84
|
+
case "end":
|
|
85
|
+
return _context.stop();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, _callee);
|
|
89
|
+
}))().catch(function (e) {
|
|
90
|
+
throw e;
|
|
91
|
+
});
|
|
92
|
+
}, [name, manifest, customProps, sandbox]);
|
|
93
|
+
|
|
94
|
+
if (app) {
|
|
95
|
+
app.update(customProps);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return /*#__PURE__*/React.createElement(Suspense, {
|
|
99
|
+
fallback: /*#__PURE__*/React.createElement(Loading, {
|
|
100
|
+
loading: loading
|
|
101
|
+
})
|
|
102
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, sandbox && sandbox !== true && sandbox.disableFakeBody ? /*#__PURE__*/React.createElement(tagName, {
|
|
103
|
+
style: style,
|
|
104
|
+
className: className,
|
|
105
|
+
ref: appRef,
|
|
106
|
+
dataId: name
|
|
107
|
+
}) : /*#__PURE__*/React.createElement(tagName, {}, /*#__PURE__*/React.createElement('div', {
|
|
108
|
+
ref: appRef
|
|
109
|
+
}))));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return Application;
|
|
113
|
+
}
|
package/es/types/base.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
3
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
|
4
|
+
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
5
|
+
|
|
6
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
7
|
+
|
|
8
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
9
|
+
|
|
10
|
+
import React from 'react';
|
|
11
|
+
|
|
12
|
+
var MicroAppBase = /*#__PURE__*/function (_React$Component) {
|
|
13
|
+
_inherits(MicroAppBase, _React$Component);
|
|
14
|
+
|
|
15
|
+
var _super = _createSuper(MicroAppBase);
|
|
16
|
+
|
|
17
|
+
function MicroAppBase() {
|
|
18
|
+
_classCallCheck(this, MicroAppBase);
|
|
19
|
+
|
|
20
|
+
return _super.apply(this, arguments);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return MicroAppBase;
|
|
24
|
+
}(React.Component);
|
|
25
|
+
|
|
26
|
+
export { MicroAppBase as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|