@alicloud/alfa-react 1.3.0-alpha.0 → 1.3.0-canary.5
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 +36 -0
- package/es/app/getConsoleConfig.js +49 -0
- package/es/app.js +29 -41
- 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/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.js +55 -0
- package/lib/app/getConsoleConfig.d.ts +2 -0
- package/lib/app/getConsoleConfig.js +62 -0
- package/lib/app.d.ts +1 -2
- package/lib/app.js +28 -40
- package/lib/base.d.ts +0 -3
- package/lib/components/Loading/Title.d.ts +0 -1
- package/lib/context.d.ts +7 -0
- package/lib/context.js +15 -0
- package/lib/createAlfaApp.d.ts +4 -0
- package/lib/createAlfaApp.js +135 -0
- package/lib/createAlfaWidget.d.ts +4 -0
- package/lib/createAlfaWidget.js +145 -0
- package/lib/createApplication.d.ts +12 -0
- package/lib/createApplication.js +133 -0
- 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 +0 -1
- package/lib/utils/getConsoleConfig.d.ts +9 -21
- package/lib/utils/getConsoleConfig.js +5 -3
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +12 -0
- 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 +5 -9
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { renderToString } from '@alicloud/alfa-core';
|
|
3
|
+
import EnvContext from '../context';
|
|
4
|
+
import ErrorBoundary from '../components/ErrorBoundary';
|
|
5
|
+
import Loading from '../components/Loading';
|
|
6
|
+
|
|
7
|
+
var App = function App(props) {
|
|
8
|
+
var env = useContext(EnvContext); // 如果 env 为空,则返回 loading
|
|
9
|
+
|
|
10
|
+
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)) {
|
|
11
|
+
return /*#__PURE__*/React.createElement(Loading, {
|
|
12
|
+
loading: props.loading
|
|
13
|
+
});
|
|
14
|
+
} // get server render string
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var renderString = renderToString(props, env);
|
|
18
|
+
|
|
19
|
+
if (!renderString) {
|
|
20
|
+
return /*#__PURE__*/React.createElement(Loading, {
|
|
21
|
+
loading: props.loading
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
26
|
+
dangerouslySetInnerHTML: {
|
|
27
|
+
__html: renderString
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function createAlfaApp(option) {
|
|
33
|
+
return function (props) {
|
|
34
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, props, /*#__PURE__*/React.createElement(App, props));
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -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,10 +9,10 @@ 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 './
|
|
15
|
+
import { getConsoleConfig } from './app/getConsoleConfig';
|
|
16
16
|
import { normalizeName } from './utils';
|
|
17
17
|
|
|
18
18
|
var getProps = function getProps(props) {
|
|
@@ -23,8 +23,10 @@ var getProps = function getProps(props) {
|
|
|
23
23
|
delete parcelProps.loading;
|
|
24
24
|
delete parcelProps.entry;
|
|
25
25
|
delete parcelProps.container;
|
|
26
|
-
delete parcelProps.logger;
|
|
27
|
-
|
|
26
|
+
delete parcelProps.logger; // @ts-ignore
|
|
27
|
+
|
|
28
|
+
delete parcelProps.env; // @ts-ignore
|
|
29
|
+
|
|
28
30
|
delete parcelProps.dependencies;
|
|
29
31
|
return parcelProps;
|
|
30
32
|
};
|
|
@@ -35,8 +37,7 @@ var Application = function Application(props) {
|
|
|
35
37
|
loading = props.loading,
|
|
36
38
|
style = props.style,
|
|
37
39
|
className = props.className,
|
|
38
|
-
consoleConfig = props.consoleConfig
|
|
39
|
-
i18nMessages = props.i18nMessages;
|
|
40
|
+
consoleConfig = props.consoleConfig;
|
|
40
41
|
|
|
41
42
|
var _useState = useState(false),
|
|
42
43
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -51,7 +52,7 @@ var Application = function Application(props) {
|
|
|
51
52
|
var appRef = useRef(null);
|
|
52
53
|
useEffect(function () {
|
|
53
54
|
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
54
|
-
var
|
|
55
|
+
var app;
|
|
55
56
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
56
57
|
while (1) {
|
|
57
58
|
switch (_context.prev = _context.next) {
|
|
@@ -65,35 +66,27 @@ var Application = function Application(props) {
|
|
|
65
66
|
});
|
|
66
67
|
|
|
67
68
|
case 2:
|
|
68
|
-
|
|
69
|
+
app = _context.sent;
|
|
69
70
|
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
if (app.context && app.context.baseFrame) {
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
app.context.baseFrame.contentWindow.ALIYUN_CONSOLE_CONFIG = consoleConfig;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
_context.next = 6;
|
|
76
|
-
return
|
|
77
|
+
return app.load();
|
|
77
78
|
|
|
78
79
|
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, {
|
|
80
|
+
_context.next = 8;
|
|
81
|
+
return app.mount(appRef.current, {
|
|
89
82
|
customProps: getProps(props)
|
|
90
83
|
});
|
|
91
84
|
|
|
92
|
-
case
|
|
85
|
+
case 8:
|
|
93
86
|
setMounted(true);
|
|
94
|
-
setApp(
|
|
87
|
+
setApp(app);
|
|
95
88
|
|
|
96
|
-
case
|
|
89
|
+
case 10:
|
|
97
90
|
case "end":
|
|
98
91
|
return _context.stop();
|
|
99
92
|
}
|
|
@@ -117,9 +110,11 @@ var Application = function Application(props) {
|
|
|
117
110
|
className: className,
|
|
118
111
|
ref: appRef,
|
|
119
112
|
dataId: name
|
|
120
|
-
}) : /*#__PURE__*/React.createElement(name, {
|
|
121
|
-
|
|
122
|
-
|
|
113
|
+
}) : /*#__PURE__*/React.createElement(name, {
|
|
114
|
+
children: /*#__PURE__*/React.createElement('div', {
|
|
115
|
+
ref: appRef
|
|
116
|
+
})
|
|
117
|
+
}));
|
|
123
118
|
};
|
|
124
119
|
|
|
125
120
|
export function createAlfaApp(option) {
|
|
@@ -127,7 +122,7 @@ export function createAlfaApp(option) {
|
|
|
127
122
|
loading = option.loading,
|
|
128
123
|
manifest = option.manifest;
|
|
129
124
|
var AlfaApp = /*#__PURE__*/lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
130
|
-
var resolvedManifest, consoleConfig,
|
|
125
|
+
var resolvedManifest, consoleConfig, AlfaApp;
|
|
131
126
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
132
127
|
while (1) {
|
|
133
128
|
switch (_context2.prev = _context2.next) {
|
|
@@ -146,6 +141,7 @@ export function createAlfaApp(option) {
|
|
|
146
141
|
resolvedManifest = _context2.sent;
|
|
147
142
|
|
|
148
143
|
case 5:
|
|
144
|
+
// @ts-ignore
|
|
149
145
|
consoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
|
|
150
146
|
|
|
151
147
|
if (!option.dynamicConfig) {
|
|
@@ -160,28 +156,20 @@ export function createAlfaApp(option) {
|
|
|
160
156
|
consoleConfig = _context2.sent;
|
|
161
157
|
|
|
162
158
|
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) {
|
|
159
|
+
AlfaApp = function AlfaApp(props) {
|
|
171
160
|
return /*#__PURE__*/React.createElement(Application, _extends({
|
|
172
161
|
manifest: resolvedManifest
|
|
173
162
|
}, props, {
|
|
174
163
|
name: normalizeName(name),
|
|
175
|
-
consoleConfig: consoleConfig
|
|
176
|
-
i18nMessages: i18nMessages
|
|
164
|
+
consoleConfig: consoleConfig
|
|
177
165
|
}));
|
|
178
166
|
};
|
|
179
167
|
|
|
180
168
|
return _context2.abrupt("return", {
|
|
181
|
-
default:
|
|
169
|
+
default: AlfaApp
|
|
182
170
|
});
|
|
183
171
|
|
|
184
|
-
case
|
|
172
|
+
case 12:
|
|
185
173
|
case "end":
|
|
186
174
|
return _context2.stop();
|
|
187
175
|
}
|
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 {};
|
|
@@ -12,6 +12,7 @@ import md5 from 'crypto-js/md5';
|
|
|
12
12
|
* transform
|
|
13
13
|
* @param features
|
|
14
14
|
*/
|
|
15
|
+
//@ts-ignore
|
|
15
16
|
|
|
16
17
|
var processFeatures = function processFeatures(features) {
|
|
17
18
|
return Object.keys(features).reduce(function (newFeatures, key) {
|
|
@@ -49,7 +50,8 @@ var mergeConfigDataWithConsoleConfig = function mergeConfigDataWithConsoleConfig
|
|
|
49
50
|
|
|
50
51
|
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';
|
|
51
52
|
var channelLinks = ((_configData$ALL_CHANN = configData.ALL_CHANNEL_LINKS) === null || _configData$ALL_CHANN === void 0 ? void 0 : _configData$ALL_CHANN[channel]) || {};
|
|
52
|
-
var channelFeatures = ((_configData$ALL_CHANN2 = configData.ALL_CHANNEL_FEATURE_STATUS) === null || _configData$ALL_CHANN2 === void 0 ? void 0 : _configData$ALL_CHANN2[channel]) || {};
|
|
53
|
+
var channelFeatures = ((_configData$ALL_CHANN2 = configData.ALL_CHANNEL_FEATURE_STATUS) === null || _configData$ALL_CHANN2 === void 0 ? void 0 : _configData$ALL_CHANN2[channel]) || {}; //@ts-ignore
|
|
54
|
+
|
|
53
55
|
var features = configData.ALL_FEATURE_STATUS || {};
|
|
54
56
|
return _objectSpread(_objectSpread({}, consoleConfig), {}, {
|
|
55
57
|
CHANNEL_LINKS: channelLinks,
|
|
@@ -59,14 +61,14 @@ var mergeConfigDataWithConsoleConfig = function mergeConfigDataWithConsoleConfig
|
|
|
59
61
|
};
|
|
60
62
|
|
|
61
63
|
export var getConsoleConfig = /*#__PURE__*/function () {
|
|
62
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(
|
|
64
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(config, consoleConfig) {
|
|
63
65
|
var configData;
|
|
64
66
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
65
67
|
while (1) {
|
|
66
68
|
switch (_context.prev = _context.next) {
|
|
67
69
|
case 0:
|
|
68
70
|
_context.next = 2;
|
|
69
|
-
return getConfig(
|
|
71
|
+
return getConfig(config);
|
|
70
72
|
|
|
71
73
|
case 2:
|
|
72
74
|
configData = _context.sent;
|