@alicloud/alfa-react 1.3.0-alpha.1 → 1.3.0-canary.6
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 +46 -45
- package/es/components/ErrorBoundary/index.js +1 -0
- package/es/context.js +7 -0
- package/es/index.js +2 -2
- package/es/utils/getConsoleConfig.js +3 -1
- 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 +3 -3
- package/es/widget.js +1 -1
- package/lib/app/createIsomorphicMicroApp.d.ts +2 -0
- package/lib/app/createIsomorphicMicroApp.js +55 -0
- package/lib/app/getConsoleConfig.d.ts +2 -0
- package/lib/{utils → app}/getConsoleConfig.js +7 -45
- package/lib/app.d.ts +1 -2
- package/lib/app.js +46 -43
- package/lib/base.d.ts +1 -4
- package/lib/components/ErrorBoundary/index.js +1 -0
- package/lib/components/Loading/Title.d.ts +0 -1
- package/lib/context.d.ts +7 -0
- package/lib/context.js +15 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +4 -6
- package/lib/types.d.ts +7 -5
- 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 +2 -2
- package/lib/widget.d.ts +1 -2
- package/lib/widget.js +2 -2
- package/package.json +6 -10
- package/es/utils/checkOptions.js +0 -13
- package/lib/createAlfaApp.d.ts +0 -4
- package/lib/createAlfaApp.js +0 -135
- package/lib/createAlfaWidget.d.ts +0 -4
- package/lib/createAlfaWidget.js +0 -145
- package/lib/createApplication.d.ts +0 -13
- package/lib/createApplication.js +0 -133
- package/lib/types/base.d.ts +0 -11
- package/lib/types/base.js +0 -37
- package/lib/types/index.d.ts +0 -86
- package/lib/types/index.js +0 -5
- package/lib/utils/checkOptions.d.ts +0 -0
- package/lib/utils/checkOptions.js +0 -14
- package/lib/utils/getConsoleConfig.d.ts +0 -21
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -12
|
@@ -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 createIsomorphicAlfaApp(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,12 +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
|
-
import { AlfaFactoryOption } from './types';
|
|
15
14
|
import ErrorBoundary from './components/ErrorBoundary';
|
|
16
|
-
import { getConsoleConfig } from './
|
|
17
|
-
import {
|
|
15
|
+
import { getConsoleConfig } from './app/getConsoleConfig';
|
|
16
|
+
import { createIsomorphicAlfaApp } from './app/createIsomorphicMicroApp';
|
|
17
|
+
import { normalizeName, isSSR } from './utils';
|
|
18
18
|
|
|
19
19
|
var getProps = function getProps(props) {
|
|
20
20
|
var parcelProps = _objectSpread({}, props);
|
|
@@ -24,8 +24,10 @@ var getProps = function getProps(props) {
|
|
|
24
24
|
delete parcelProps.loading;
|
|
25
25
|
delete parcelProps.entry;
|
|
26
26
|
delete parcelProps.container;
|
|
27
|
-
delete parcelProps.logger;
|
|
28
|
-
|
|
27
|
+
delete parcelProps.logger; // @ts-ignore
|
|
28
|
+
|
|
29
|
+
delete parcelProps.env; // @ts-ignore
|
|
30
|
+
|
|
29
31
|
delete parcelProps.dependencies;
|
|
30
32
|
return parcelProps;
|
|
31
33
|
};
|
|
@@ -36,8 +38,7 @@ var Application = function Application(props) {
|
|
|
36
38
|
loading = props.loading,
|
|
37
39
|
style = props.style,
|
|
38
40
|
className = props.className,
|
|
39
|
-
consoleConfig = props.consoleConfig
|
|
40
|
-
i18nMessages = props.i18nMessages;
|
|
41
|
+
consoleConfig = props.consoleConfig;
|
|
41
42
|
|
|
42
43
|
var _useState = useState(false),
|
|
43
44
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -52,7 +53,7 @@ var Application = function Application(props) {
|
|
|
52
53
|
var appRef = useRef(null);
|
|
53
54
|
useEffect(function () {
|
|
54
55
|
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
55
|
-
var
|
|
56
|
+
var app;
|
|
56
57
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
57
58
|
while (1) {
|
|
58
59
|
switch (_context.prev = _context.next) {
|
|
@@ -66,35 +67,27 @@ var Application = function Application(props) {
|
|
|
66
67
|
});
|
|
67
68
|
|
|
68
69
|
case 2:
|
|
69
|
-
|
|
70
|
+
app = _context.sent;
|
|
70
71
|
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
if (app.context && app.context.baseFrame) {
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
app.context.baseFrame.contentWindow.ALIYUN_CONSOLE_CONFIG = consoleConfig;
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
_context.next = 6;
|
|
77
|
-
return
|
|
78
|
+
return app.load();
|
|
78
79
|
|
|
79
80
|
case 6:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return _context.abrupt("return");
|
|
86
|
-
|
|
87
|
-
case 8:
|
|
88
|
-
_context.next = 10;
|
|
89
|
-
return App.mount(appRef.current, {
|
|
81
|
+
_context.next = 8;
|
|
82
|
+
return app.mount(appRef.current, {
|
|
90
83
|
customProps: getProps(props)
|
|
91
84
|
});
|
|
92
85
|
|
|
93
|
-
case
|
|
86
|
+
case 8:
|
|
94
87
|
setMounted(true);
|
|
95
|
-
setApp(
|
|
88
|
+
setApp(app);
|
|
96
89
|
|
|
97
|
-
case
|
|
90
|
+
case 10:
|
|
98
91
|
case "end":
|
|
99
92
|
return _context.stop();
|
|
100
93
|
}
|
|
@@ -118,17 +111,24 @@ var Application = function Application(props) {
|
|
|
118
111
|
className: className,
|
|
119
112
|
ref: appRef,
|
|
120
113
|
dataId: name
|
|
121
|
-
}) : /*#__PURE__*/React.createElement(name, {
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
}) : /*#__PURE__*/React.createElement(name, {
|
|
115
|
+
children: /*#__PURE__*/React.createElement('div', {
|
|
116
|
+
ref: appRef
|
|
117
|
+
})
|
|
118
|
+
}));
|
|
124
119
|
};
|
|
125
120
|
|
|
126
121
|
export function createAlfaApp(option) {
|
|
127
122
|
var name = option.name,
|
|
128
123
|
loading = option.loading,
|
|
129
124
|
manifest = option.manifest;
|
|
125
|
+
|
|
126
|
+
if (isSSR()) {
|
|
127
|
+
return createIsomorphicAlfaApp(option);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
130
|
var AlfaApp = /*#__PURE__*/lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
131
|
-
var resolvedManifest, consoleConfig,
|
|
131
|
+
var resolvedManifest, consoleConfig, AlfaApp;
|
|
132
132
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
133
133
|
while (1) {
|
|
134
134
|
switch (_context2.prev = _context2.next) {
|
|
@@ -147,34 +147,35 @@ export function createAlfaApp(option) {
|
|
|
147
147
|
resolvedManifest = _context2.sent;
|
|
148
148
|
|
|
149
149
|
case 5:
|
|
150
|
+
// @ts-ignore
|
|
150
151
|
consoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
|
|
151
|
-
|
|
152
|
+
|
|
153
|
+
if (!option.dynamicConfig) {
|
|
154
|
+
_context2.next = 10;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
_context2.next = 9;
|
|
152
159
|
return getConsoleConfig(option, consoleConfig);
|
|
153
160
|
|
|
154
|
-
case
|
|
161
|
+
case 9:
|
|
155
162
|
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);
|
|
162
163
|
|
|
163
|
-
|
|
164
|
+
case 10:
|
|
165
|
+
AlfaApp = function AlfaApp(props) {
|
|
164
166
|
return /*#__PURE__*/React.createElement(Application, _extends({
|
|
165
167
|
manifest: resolvedManifest
|
|
166
168
|
}, props, {
|
|
167
169
|
name: normalizeName(name),
|
|
168
|
-
consoleConfig: consoleConfig
|
|
169
|
-
i18nMessages: i18nMessages
|
|
170
|
+
consoleConfig: consoleConfig
|
|
170
171
|
}));
|
|
171
172
|
};
|
|
172
173
|
|
|
173
174
|
return _context2.abrupt("return", {
|
|
174
|
-
default:
|
|
175
|
+
default: AlfaApp
|
|
175
176
|
});
|
|
176
177
|
|
|
177
|
-
case
|
|
178
|
+
case 12:
|
|
178
179
|
case "end":
|
|
179
180
|
return _context2.stop();
|
|
180
181
|
}
|
|
@@ -191,4 +192,4 @@ export function createAlfaApp(option) {
|
|
|
191
192
|
}, props))));
|
|
192
193
|
};
|
|
193
194
|
}
|
|
194
|
-
export { AlfaFactoryOption };
|
|
195
|
+
export { AlfaFactoryOption } from './types';
|
|
@@ -49,6 +49,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
49
49
|
isFunction((_window = window) === null || _window === void 0 ? void 0 : (_window$__bl = _window.__bl) === null || _window$__bl === void 0 ? void 0 : _window$__bl.error) && window.__bl.error(error, errorInfo);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
console.error(error);
|
|
52
53
|
this.props.appDidCatch && this.props.appDidCatch(error);
|
|
53
54
|
}
|
|
54
55
|
}, {
|
package/es/context.js
ADDED
package/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { createAlfaWidget } from './widget';
|
|
2
|
+
export { createAlfaApp } from './app';
|
|
3
3
|
export { eventEmitter as widgetEventEmitter } from './widget/index'; // todo
|
|
4
4
|
|
|
5
5
|
export { createEventBus, prefetch } from '@alicloud/alfa-core';
|
|
@@ -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,
|
package/es/utils.js
CHANGED
package/es/widget/emitter.js
CHANGED
|
@@ -18,13 +18,13 @@ var WidgetEventEmitter = /*#__PURE__*/function (_EventEmitter) {
|
|
|
18
18
|
function WidgetEventEmitter() {
|
|
19
19
|
_classCallCheck(this, WidgetEventEmitter);
|
|
20
20
|
|
|
21
|
-
return _super.
|
|
22
|
-
}
|
|
21
|
+
return _super.call(this);
|
|
22
|
+
} // Compatible with the old api, this may get removed at sometime later.
|
|
23
|
+
|
|
23
24
|
|
|
24
25
|
_createClass(WidgetEventEmitter, [{
|
|
25
26
|
key: "refersh",
|
|
26
|
-
value:
|
|
27
|
-
function refersh(widgetId) {
|
|
27
|
+
value: function refersh(widgetId) {
|
|
28
28
|
return this.emit("".concat(widgetId, ":REFRESH"));
|
|
29
29
|
}
|
|
30
30
|
}, {
|
|
@@ -12,25 +12,26 @@ export var getWidgetConfigById = /*#__PURE__*/function () {
|
|
|
12
12
|
switch (_context.prev = _context.next) {
|
|
13
13
|
case 0:
|
|
14
14
|
env = ENV[option.env || getConsoleEnv()];
|
|
15
|
+
console.log(env.configUrl);
|
|
15
16
|
|
|
16
17
|
if (cachedConfig[option.name]) {
|
|
17
|
-
_context.next =
|
|
18
|
+
_context.next = 7;
|
|
18
19
|
break;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
_context.next =
|
|
22
|
+
_context.next = 5;
|
|
22
23
|
return axios.get(template(env.configUrl)({
|
|
23
24
|
id: option.name
|
|
24
25
|
}));
|
|
25
26
|
|
|
26
|
-
case
|
|
27
|
+
case 5:
|
|
27
28
|
resp = _context.sent;
|
|
28
29
|
cachedConfig[option.name] = resp.data;
|
|
29
30
|
|
|
30
|
-
case
|
|
31
|
+
case 7:
|
|
31
32
|
return _context.abrupt("return", cachedConfig[option.name]);
|
|
32
33
|
|
|
33
|
-
case
|
|
34
|
+
case 8:
|
|
34
35
|
case "end":
|
|
35
36
|
return _context.stop();
|
|
36
37
|
}
|
|
@@ -12,7 +12,7 @@ import axios from 'axios';
|
|
|
12
12
|
import kebabCase from 'lodash/kebabCase';
|
|
13
13
|
import * as propTypes from 'prop-types';
|
|
14
14
|
import { loadBundle } from '@alicloud/console-os-loader';
|
|
15
|
-
import {
|
|
15
|
+
import { createAlfaWidget } from '../widget';
|
|
16
16
|
import { getWidgetVersionById } from './getWidgetVersionById'; // @ts-ignore
|
|
17
17
|
|
|
18
18
|
import * as widgetUtils from '@alicloud/widget-utils-console';
|
|
@@ -32,7 +32,7 @@ var createWidget = function createWidget(option) {
|
|
|
32
32
|
|
|
33
33
|
var id = _ref.id,
|
|
34
34
|
version = _ref.version;
|
|
35
|
-
return
|
|
35
|
+
return createAlfaWidget({
|
|
36
36
|
name: id,
|
|
37
37
|
version: version,
|
|
38
38
|
dependencies: option === null || option === void 0 ? void 0 : option.dependencies,
|
|
@@ -160,7 +160,7 @@ export var getWidgetDeps = /*#__PURE__*/function () {
|
|
|
160
160
|
react: react,
|
|
161
161
|
'react-dom': reactDom,
|
|
162
162
|
'prop-types': propTypes,
|
|
163
|
-
axios: axios
|
|
163
|
+
'axios': axios
|
|
164
164
|
}, cachedRuntime[version].default), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, WIDGET_UTILS_PKG_NAME, injectedWidgetUtils), _defineProperty(_objectSpread2, '@ali/widget-utils-config', injectedWidgetUtils), _defineProperty(_objectSpread2, '@ali/widget-loader', createWidget), _objectSpread2)));
|
|
165
165
|
|
|
166
166
|
case 31:
|
package/es/widget.js
CHANGED
|
@@ -13,7 +13,7 @@ import { getWidgetVersionById, getWidgetDeps, getWidgetConfigById, eventEmitter
|
|
|
13
13
|
import ErrorBoundary from './components/ErrorBoundary';
|
|
14
14
|
import Loading from './components/Loading';
|
|
15
15
|
import { normalizeName } from './utils';
|
|
16
|
-
export function
|
|
16
|
+
export function createAlfaWidget(option) {
|
|
17
17
|
var AlfaWidget = /*#__PURE__*/lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
18
18
|
var url, config, _yield$getWidgetVersi, version, entryUrl, deps;
|
|
19
19
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.createIsomorphicAlfaApp = createIsomorphicAlfaApp;
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
|
+
var _alfaCore = require("@alicloud/alfa-core");
|
|
15
|
+
|
|
16
|
+
var _context = _interopRequireDefault(require("../context"));
|
|
17
|
+
|
|
18
|
+
var _ErrorBoundary = _interopRequireDefault(require("../components/ErrorBoundary"));
|
|
19
|
+
|
|
20
|
+
var _Loading = _interopRequireDefault(require("../components/Loading"));
|
|
21
|
+
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
+
|
|
24
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
+
|
|
26
|
+
var App = function App(props) {
|
|
27
|
+
var env = (0, _react.useContext)(_context.default); // 如果 env 为空,则返回 loading
|
|
28
|
+
|
|
29
|
+
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)) {
|
|
30
|
+
return /*#__PURE__*/_react.default.createElement(_Loading.default, {
|
|
31
|
+
loading: props.loading
|
|
32
|
+
});
|
|
33
|
+
} // get server render string
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
var renderString = (0, _alfaCore.renderToString)(props, env);
|
|
37
|
+
|
|
38
|
+
if (!renderString) {
|
|
39
|
+
return /*#__PURE__*/_react.default.createElement(_Loading.default, {
|
|
40
|
+
loading: props.loading
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
45
|
+
dangerouslySetInnerHTML: {
|
|
46
|
+
__html: renderString
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function createIsomorphicAlfaApp(option) {
|
|
52
|
+
return function (props) {
|
|
53
|
+
return /*#__PURE__*/_react.default.createElement(_ErrorBoundary.default, props, /*#__PURE__*/_react.default.createElement(App, props));
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -15,70 +15,32 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
15
15
|
|
|
16
16
|
var _alfaCore = require("@alicloud/alfa-core");
|
|
17
17
|
|
|
18
|
-
var _md = _interopRequireDefault(require("crypto-js/md5"));
|
|
19
|
-
|
|
20
18
|
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; }
|
|
21
19
|
|
|
22
20
|
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) { (0, _defineProperty2.default)(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; }
|
|
23
21
|
|
|
24
|
-
/**
|
|
25
|
-
* transform
|
|
26
|
-
* @param features
|
|
27
|
-
*/
|
|
28
|
-
var processFeatures = function processFeatures(features) {
|
|
29
|
-
return Object.keys(features).reduce(function (newFeatures, key) {
|
|
30
|
-
var _ALIYUN_CONSOLE_CONFI;
|
|
31
|
-
|
|
32
|
-
var feature = features[key];
|
|
33
|
-
if (!feature) return newFeatures;
|
|
34
|
-
var uid = ((_ALIYUN_CONSOLE_CONFI = window.ALIYUN_CONSOLE_CONFIG) === null || _ALIYUN_CONSOLE_CONFI === void 0 ? void 0 : _ALIYUN_CONSOLE_CONFI.CURRENT_PK) || '';
|
|
35
|
-
var md5Uid = (0, _md.default)(uid).toString();
|
|
36
|
-
var enableBlockList = feature.enableBlockList,
|
|
37
|
-
enableSampling = feature.enableSampling,
|
|
38
|
-
enableWhiteList = feature.enableWhiteList,
|
|
39
|
-
sampling = feature.sampling,
|
|
40
|
-
blockList = feature.blockList,
|
|
41
|
-
whiteList = feature.whiteList;
|
|
42
|
-
|
|
43
|
-
if (enableBlockList && blockList.includes(md5Uid)) {
|
|
44
|
-
newFeatures[key] = false;
|
|
45
|
-
} else if (enableWhiteList && whiteList.includes(md5Uid)) {
|
|
46
|
-
newFeatures[key] = true;
|
|
47
|
-
} else if (enableSampling) {
|
|
48
|
-
var gray = uid.substring(uid.length - 2);
|
|
49
|
-
if (Number(gray) >= sampling * 100 || sampling === 0) newFeatures[key] = false;
|
|
50
|
-
newFeatures[key] = true;
|
|
51
|
-
} else {
|
|
52
|
-
newFeatures[key] = false;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return newFeatures;
|
|
56
|
-
}, {});
|
|
57
|
-
};
|
|
58
|
-
|
|
59
22
|
var mergeConfigDataWithConsoleConfig = function mergeConfigDataWithConsoleConfig(configData, consoleConfig) {
|
|
60
|
-
var _window, _window$ALIYUN_CONSOL
|
|
23
|
+
var _window, _window$ALIYUN_CONSOL;
|
|
61
24
|
|
|
25
|
+
// @ts-ignore
|
|
62
26
|
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';
|
|
63
|
-
var channelLinks =
|
|
64
|
-
var
|
|
65
|
-
var features = configData.ALL_FEATURE_STATUS || {};
|
|
27
|
+
var channelLinks = configData.ALL_CHANNEL_LINKS ? configData.ALL_CHANNEL_LINKS[channel] : {};
|
|
28
|
+
var features = configData.ALL_CHANNEL_FEATURE_STATUS ? configData.ALL_CHANNEL_FEATURE_STATUS[channel] : {};
|
|
66
29
|
return _objectSpread(_objectSpread({}, consoleConfig), {}, {
|
|
67
30
|
CHANNEL_LINKS: channelLinks,
|
|
68
|
-
CHANNEL_FEATURE_STATUS:
|
|
69
|
-
FEATURE_STATUS: processFeatures(features)
|
|
31
|
+
CHANNEL_FEATURE_STATUS: features
|
|
70
32
|
});
|
|
71
33
|
};
|
|
72
34
|
|
|
73
35
|
var getConsoleConfig = /*#__PURE__*/function () {
|
|
74
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(
|
|
36
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(option, consoleConfig) {
|
|
75
37
|
var configData;
|
|
76
38
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
77
39
|
while (1) {
|
|
78
40
|
switch (_context.prev = _context.next) {
|
|
79
41
|
case 0:
|
|
80
42
|
_context.next = 2;
|
|
81
|
-
return (0, _alfaCore.getConfig)(
|
|
43
|
+
return (0, _alfaCore.getConfig)(option);
|
|
82
44
|
|
|
83
45
|
case 2:
|
|
84
46
|
configData = _context.sent;
|
package/lib/app.d.ts
CHANGED