@alicloud/alfa-react 1.3.4 → 1.4.0-alpha.2

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.
@@ -25,7 +25,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
25
25
  _this = _super.call(this, props);
26
26
  _this.state = {
27
27
  hasError: false,
28
- error: null
28
+ error: undefined
29
29
  };
30
30
  return _this;
31
31
  }
@@ -46,8 +46,9 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
46
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
47
 
48
48
  appDidCatch && appDidCatch(error, errorInfo);
49
- logger === null || logger === void 0 ? void 0 : logger.error({
50
- E_MSG: '',
49
+ (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
50
+ E_CODE: 'RuntimeError',
51
+ E_MSG: error.message,
51
52
  E_STACK: error,
52
53
  C_STACK: errorInfo
53
54
  });
@@ -58,7 +59,8 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
58
59
  var error = this.state.error;
59
60
 
60
61
  if (this.state.hasError) {
61
- // You can render any custom fallback UI
62
+ if (this.props.fallbackRender) return this.props.fallbackRender(error); // You can render any custom fallback UI
63
+
62
64
  return /*#__PURE__*/React.createElement(ErrorPanel, {
63
65
  error: error
64
66
  });
@@ -45,7 +45,11 @@ export default function createApplication(loader) {
45
45
  app = _useState2[0],
46
46
  setApp = _useState2[1];
47
47
 
48
- var appRef = useRef(null);
48
+ var _useState3 = useState(null),
49
+ _useState4 = _slicedToArray(_useState3, 2),
50
+ setError = _useState4[1];
51
+
52
+ var appRef = useRef(undefined);
49
53
  var tagName = normalizeName(props.name);
50
54
  var sandbox = useMemo(function () {
51
55
  return _objectSpread(_objectSpread({}, customSandbox), {}, {
@@ -95,7 +99,8 @@ export default function createApplication(loader) {
95
99
  break;
96
100
  }
97
101
 
98
- return _context.abrupt("return", logger === null || logger === void 0 ? void 0 : logger.error({
102
+ return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
103
+ E_CODE: 'RuntimeError',
99
104
  E_MSG: 'load app failed.'
100
105
  }));
101
106
 
@@ -105,7 +110,8 @@ export default function createApplication(loader) {
105
110
  break;
106
111
  }
107
112
 
108
- return _context.abrupt("return", logger === null || logger === void 0 ? void 0 : logger.error({
113
+ return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
114
+ E_CODE: 'RuntimeError',
109
115
  E_MSG: 'cannot find container.'
110
116
  }));
111
117
 
@@ -125,7 +131,9 @@ export default function createApplication(loader) {
125
131
  }
126
132
  }, _callee);
127
133
  }))().catch(function (e) {
128
- throw e;
134
+ setError(function () {
135
+ throw e;
136
+ });
129
137
  });
130
138
 
131
139
  return function () {
@@ -138,9 +146,9 @@ export default function createApplication(loader) {
138
146
  }
139
147
 
140
148
  var dataAttrs = {
141
- dataId: version,
142
- dataVersion: version,
143
- dataLoader: loaderVersion
149
+ 'data-id': version,
150
+ 'data-version': version,
151
+ 'data-loader': loaderVersion
144
152
  };
145
153
  return /*#__PURE__*/React.createElement(React.Fragment, null, !app ? /*#__PURE__*/React.createElement(Loading, {
146
154
  loading: loading
@@ -148,9 +156,7 @@ export default function createApplication(loader) {
148
156
  style: style,
149
157
  className: className,
150
158
  ref: appRef
151
- }, dataAttrs)) : /*#__PURE__*/React.createElement(tagName, {
152
- dataAttrs: dataAttrs
153
- }, /*#__PURE__*/React.createElement('div', {
159
+ }, dataAttrs)) : /*#__PURE__*/React.createElement(tagName, _objectSpread({}, dataAttrs), /*#__PURE__*/React.createElement('div', {
154
160
  ref: appRef,
155
161
  style: style,
156
162
  className: className
@@ -7,8 +7,9 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
7
7
 
8
8
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
9
 
10
- import { getLocale } from '@alicloud/alfa-core';
11
- import { getConsoleConfig } from '../utils/getConsoleConfig'; // inject consoleConfig & locales after load
10
+ import { getConfig, getI18nMessages } from '@alicloud/alfa-core';
11
+ import { getConsoleConfig } from '../utils/getConsoleConfig';
12
+ import { getConsoleGlobal } from '../utils/getConsoleGlobal'; // inject consoleConfig & locales after load
12
13
 
13
14
  function afterLoadHook(_x) {
14
15
  return _afterLoadHook.apply(this, arguments);
@@ -16,7 +17,7 @@ function afterLoadHook(_x) {
16
17
 
17
18
  function _afterLoadHook() {
18
19
  _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
+ var app, logger, defaultConsoleConfig, defaultConsoleGlobal, CONFIG_START_TIME, configData, _yield$Promise$all, _yield$Promise$all2, consoleConfig, consoleGlobal, messages, CONFIG_END_TIME, i18nMessages, END_TIME;
20
21
 
21
22
  return _regeneratorRuntime.wrap(function _callee$(_context) {
22
23
  while (1) {
@@ -24,39 +25,41 @@ function _afterLoadHook() {
24
25
  case 0:
25
26
  app = appConfig.app, logger = appConfig.logger;
26
27
  defaultConsoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
28
+ defaultConsoleGlobal = window.ALIYUN_CONSOLE_GLOBAL || {};
27
29
  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
- });
30
+ _context.next = 6;
31
+ return getConfig(appConfig);
32
+
33
+ case 6:
34
+ configData = _context.sent;
35
+ _context.next = 9;
36
+ return Promise.all([getConsoleConfig(configData, defaultConsoleConfig), getConsoleGlobal(configData, defaultConsoleGlobal), getI18nMessages(appConfig)]);
36
37
 
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];
38
+ case 9:
39
+ _yield$Promise$all = _context.sent;
40
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
41
+ consoleConfig = _yield$Promise$all2[0];
42
+ consoleGlobal = _yield$Promise$all2[1];
43
+ messages = _yield$Promise$all2[2];
42
44
  CONFIG_END_TIME = Date.now();
43
- i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages);
45
+ i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages); // inject global variables
44
46
 
45
47
  if (app && app.context) {
46
48
  app.context.window.ALIYUN_CONSOLE_CONFIG = consoleConfig;
47
- app.context.window.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages; // (app.context.history as any) = {};
49
+ app.context.window.ALIYUN_CONSOLE_GLOBAL = consoleGlobal;
50
+ app.context.window.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages;
48
51
  }
49
52
 
50
53
  END_TIME = Date.now();
51
- logger === null || logger === void 0 ? void 0 : logger.record({
54
+ (logger === null || logger === void 0 ? void 0 : logger.record) && logger.record({
52
55
  CONFIG_START_TIME: CONFIG_START_TIME,
53
56
  CONFIG_END_TIME: CONFIG_END_TIME,
54
57
  END_TIME: END_TIME
55
58
  });
56
- logger === null || logger === void 0 ? void 0 : logger.send();
59
+ (logger === null || logger === void 0 ? void 0 : logger.send) && logger.send();
57
60
  return _context.abrupt("return", appConfig);
58
61
 
59
- case 16:
62
+ case 21:
60
63
  case "end":
61
64
  return _context.stop();
62
65
  }
@@ -10,30 +10,21 @@ function beforeResolveHook(_x) {
10
10
 
11
11
  function _beforeResolveHook() {
12
12
  _beforeResolveHook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(appConfig) {
13
- var resolvedManifest, logger, START_TIME, MANIFEST_START_TIME, MANIFEST_END_TIME;
13
+ var logger, START_TIME, MANIFEST_START_TIME, resolvedManifest, MANIFEST_END_TIME;
14
14
  return _regeneratorRuntime.wrap(function _callee$(_context) {
15
15
  while (1) {
16
16
  switch (_context.prev = _context.next) {
17
17
  case 0:
18
- resolvedManifest = appConfig.manifest;
19
18
  logger = appConfig.logger;
20
19
  START_TIME = Date.now();
21
20
  MANIFEST_START_TIME = Date.now();
22
-
23
- if (resolvedManifest) {
24
- _context.next = 8;
25
- break;
26
- }
27
-
28
- _context.next = 7;
21
+ _context.next = 5;
29
22
  return getManifest(appConfig);
30
23
 
31
- case 7:
24
+ case 5:
32
25
  resolvedManifest = _context.sent;
33
-
34
- case 8:
35
26
  MANIFEST_END_TIME = Date.now();
36
- logger === null || logger === void 0 ? void 0 : logger.record({
27
+ (logger === null || logger === void 0 ? void 0 : logger.record) && logger.record({
37
28
  LOADER_VERSION: LOADER_VERSION,
38
29
  START_TIME: START_TIME,
39
30
  MANIFEST_START_TIME: MANIFEST_START_TIME,
@@ -42,7 +33,7 @@ function _beforeResolveHook() {
42
33
  appConfig.manifest = resolvedManifest;
43
34
  return _context.abrupt("return", appConfig);
44
35
 
45
- case 12:
36
+ case 10:
46
37
  case "end":
47
38
  return _context.stop();
48
39
  }
@@ -6,7 +6,6 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
6
6
 
7
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
8
 
9
- import { getConfig } from '@alicloud/alfa-core';
10
9
  import md5 from 'crypto-js/md5';
11
10
  /**
12
11
  * transform
@@ -14,12 +13,13 @@ import md5 from 'crypto-js/md5';
14
13
  */
15
14
 
16
15
  var processFeatures = function processFeatures(features) {
16
+ if (!features) return {};
17
17
  return Object.keys(features).reduce(function (newFeatures, key) {
18
18
  var _ALIYUN_CONSOLE_CONFI;
19
19
 
20
- var feature = features[key];
20
+ var feature = features === null || features === void 0 ? void 0 : features[key];
21
21
  if (!feature) return newFeatures;
22
- var uid = ((_ALIYUN_CONSOLE_CONFI = window.ALIYUN_CONSOLE_CONFIG) === null || _ALIYUN_CONSOLE_CONFI === void 0 ? void 0 : _ALIYUN_CONSOLE_CONFI.CURRENT_PK) || '';
22
+ var uid = ((_ALIYUN_CONSOLE_CONFI = window.ALIYUN_CONSOLE_CONFIG) === null || _ALIYUN_CONSOLE_CONFI === void 0 ? void 0 : _ALIYUN_CONSOLE_CONFI.MAIN_ACCOUNT_PK) || '';
23
23
  var md5Uid = md5(uid).toString();
24
24
  var enableBlockList = feature.enableBlockList,
25
25
  enableSampling = feature.enableSampling,
@@ -44,35 +44,59 @@ var processFeatures = function processFeatures(features) {
44
44
  }, {});
45
45
  };
46
46
 
47
+ var getRegions = function getRegions(regions) {
48
+ if (!Array.isArray(regions) && regions.region) {
49
+ return regions.region || [];
50
+ }
51
+
52
+ return [];
53
+ };
54
+
55
+ var processChannelFeatures = function processChannelFeatures(allChannelFeatures, channel) {
56
+ var channelFeatures = allChannelFeatures === null || allChannelFeatures === void 0 ? void 0 : allChannelFeatures[channel];
57
+ if (!channelFeatures) return {};
58
+ return Object.keys(channelFeatures).reduce(function (newChannelFeatures, key) {
59
+ var channelFeature = channelFeatures[key];
60
+ if (!channelFeature) return newChannelFeatures;
61
+
62
+ if (newChannelFeatures) {
63
+ var status = channelFeature.status,
64
+ attribute = channelFeature.attribute;
65
+ newChannelFeatures[key] = {
66
+ status: status,
67
+ attribute: _objectSpread(_objectSpread({}, attribute), {}, {
68
+ regions: getRegions(channelFeature.attribute.regions)
69
+ })
70
+ };
71
+ }
72
+
73
+ return newChannelFeatures;
74
+ }, {});
75
+ };
76
+
47
77
  var mergeConfigDataWithConsoleConfig = function mergeConfigDataWithConsoleConfig(configData, consoleConfig) {
48
- var _window, _window$ALIYUN_CONSOL, _configData$ALL_CHANN, _configData$ALL_CHANN2;
78
+ var _window, _window$ALIYUN_CONSOL, _configData$ALL_CHANN;
49
79
 
50
80
  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
81
  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]) || {};
82
+ var channelFeatures = configData.ALL_CHANNEL_FEATURE_STATUS || {};
53
83
  var features = configData.ALL_FEATURE_STATUS || {};
54
84
  return _objectSpread(_objectSpread({}, consoleConfig), {}, {
55
85
  CHANNEL_LINKS: channelLinks,
56
- CHANNEL_FEATURE_STATUS: channelFeatures,
86
+ CHANNEL_FEATURE_STATUS: processChannelFeatures(channelFeatures, channel),
57
87
  FEATURE_STATUS: processFeatures(features)
58
88
  });
59
89
  };
60
90
 
61
91
  export var getConsoleConfig = /*#__PURE__*/function () {
62
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(config, consoleConfig) {
63
- var configData;
92
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(configData, consoleConfig) {
64
93
  return _regeneratorRuntime.wrap(function _callee$(_context) {
65
94
  while (1) {
66
95
  switch (_context.prev = _context.next) {
67
96
  case 0:
68
- _context.next = 2;
69
- return getConfig(config);
70
-
71
- case 2:
72
- configData = _context.sent;
73
97
  return _context.abrupt("return", mergeConfigDataWithConsoleConfig(configData, consoleConfig));
74
98
 
75
- case 4:
99
+ case 1:
76
100
  case "end":
77
101
  return _context.stop();
78
102
  }
@@ -0,0 +1,28 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
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); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
+
9
+ export var getConsoleGlobal = /*#__PURE__*/function () {
10
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(configData, global) {
11
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
12
+ while (1) {
13
+ switch (_context.prev = _context.next) {
14
+ case 0:
15
+ return _context.abrupt("return", _objectSpread(_objectSpread({}, global), configData === null || configData === void 0 ? void 0 : configData.GLOBAL_DATA));
16
+
17
+ case 1:
18
+ case "end":
19
+ return _context.stop();
20
+ }
21
+ }
22
+ }, _callee);
23
+ }));
24
+
25
+ return function getConsoleGlobal(_x, _x2) {
26
+ return _ref.apply(this, arguments);
27
+ };
28
+ }();
package/es/version.js CHANGED
@@ -1 +1 @@
1
- export var version = '1.3.4';
1
+ export var version = '1.4.0-alpha.2';
package/lib/app.js CHANGED
@@ -80,7 +80,7 @@ var Application = function Application(props) {
80
80
  app = _useState4[0],
81
81
  setApp = _useState4[1];
82
82
 
83
- var appRef = (0, _react.useRef)(null);
83
+ var appRef = (0, _react.useRef)(undefined);
84
84
  (0, _react.useEffect)(function () {
85
85
  (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
86
86
  var App;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  interface IProps {
3
- error: Error | null;
3
+ error?: Error;
4
4
  }
5
5
  declare const ErrorPanel: React.FC<IProps>;
6
6
  export default ErrorPanel;
@@ -1,12 +1,13 @@
1
1
  import React, { ErrorInfo } from 'react';
2
2
  import { AlfaLogger } from '@alicloud/alfa-core';
3
3
  interface IProps {
4
+ fallbackRender?: (error?: Error) => Element;
4
5
  appDidCatch?: (error?: Error, info?: ErrorInfo) => void;
5
6
  logger?: AlfaLogger;
6
7
  }
7
8
  interface State {
8
9
  hasError: boolean;
9
- error: Error | null;
10
+ error?: Error;
10
11
  }
11
12
  declare class ErrorBoundary extends React.Component<IProps, State> {
12
13
  constructor(props: IProps);
@@ -39,7 +39,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
39
39
  _this = _super.call(this, props);
40
40
  _this.state = {
41
41
  hasError: false,
42
- error: null
42
+ error: undefined
43
43
  };
44
44
  return _this;
45
45
  }
@@ -60,8 +60,9 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
60
60
  (0, _isFunction.default)((_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
61
61
 
62
62
  appDidCatch && appDidCatch(error, errorInfo);
63
- logger === null || logger === void 0 ? void 0 : logger.error({
64
- E_MSG: '',
63
+ (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
64
+ E_CODE: 'RuntimeError',
65
+ E_MSG: error.message,
65
66
  E_STACK: error,
66
67
  C_STACK: errorInfo
67
68
  });
@@ -72,7 +73,8 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
72
73
  var error = this.state.error;
73
74
 
74
75
  if (this.state.hasError) {
75
- // You can render any custom fallback UI
76
+ if (this.props.fallbackRender) return this.props.fallbackRender(error); // You can render any custom fallback UI
77
+
76
78
  return /*#__PURE__*/_react.default.createElement(_ErrorPanel.default, {
77
79
  error: error
78
80
  });
@@ -67,7 +67,11 @@ function createApplication(loader) {
67
67
  app = _useState2[0],
68
68
  setApp = _useState2[1];
69
69
 
70
- var appRef = (0, _react.useRef)(null);
70
+ var _useState3 = (0, _react.useState)(null),
71
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
72
+ setError = _useState4[1];
73
+
74
+ var appRef = (0, _react.useRef)(undefined);
71
75
  var tagName = (0, _utils.normalizeName)(props.name);
72
76
  var sandbox = (0, _react.useMemo)(function () {
73
77
  return _objectSpread(_objectSpread({}, customSandbox), {}, {
@@ -117,7 +121,8 @@ function createApplication(loader) {
117
121
  break;
118
122
  }
119
123
 
120
- return _context.abrupt("return", logger === null || logger === void 0 ? void 0 : logger.error({
124
+ return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
125
+ E_CODE: 'RuntimeError',
121
126
  E_MSG: 'load app failed.'
122
127
  }));
123
128
 
@@ -127,7 +132,8 @@ function createApplication(loader) {
127
132
  break;
128
133
  }
129
134
 
130
- return _context.abrupt("return", logger === null || logger === void 0 ? void 0 : logger.error({
135
+ return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
136
+ E_CODE: 'RuntimeError',
131
137
  E_MSG: 'cannot find container.'
132
138
  }));
133
139
 
@@ -147,7 +153,9 @@ function createApplication(loader) {
147
153
  }
148
154
  }, _callee);
149
155
  }))().catch(function (e) {
150
- throw e;
156
+ setError(function () {
157
+ throw e;
158
+ });
151
159
  });
152
160
  return function () {
153
161
  app && app.unmount();
@@ -159,9 +167,9 @@ function createApplication(loader) {
159
167
  }
160
168
 
161
169
  var dataAttrs = {
162
- dataId: version,
163
- dataVersion: version,
164
- dataLoader: _version.version
170
+ 'data-id': version,
171
+ 'data-version': version,
172
+ 'data-loader': _version.version
165
173
  };
166
174
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, !app ? /*#__PURE__*/_react.default.createElement(_Loading.default, {
167
175
  loading: loading
@@ -169,9 +177,7 @@ function createApplication(loader) {
169
177
  style: style,
170
178
  className: className,
171
179
  ref: appRef
172
- }, dataAttrs)) : /*#__PURE__*/_react.default.createElement(tagName, {
173
- dataAttrs: dataAttrs
174
- }, /*#__PURE__*/_react.default.createElement('div', {
180
+ }, dataAttrs)) : /*#__PURE__*/_react.default.createElement(tagName, _objectSpread({}, dataAttrs), /*#__PURE__*/_react.default.createElement('div', {
175
181
  ref: appRef,
176
182
  style: style,
177
183
  className: className
@@ -19,6 +19,8 @@ var _alfaCore = require("@alicloud/alfa-core");
19
19
 
20
20
  var _getConsoleConfig = require("../utils/getConsoleConfig");
21
21
 
22
+ var _getConsoleGlobal = require("../utils/getConsoleGlobal");
23
+
22
24
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
23
25
 
24
26
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -30,7 +32,7 @@ function afterLoadHook(_x) {
30
32
 
31
33
  function _afterLoadHook() {
32
34
  _afterLoadHook = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(appConfig) {
33
- var app, logger, defaultConsoleConfig, CONFIG_START_TIME, _yield$Promise$all$ca, _yield$Promise$all$ca2, consoleConfig, messages, CONFIG_END_TIME, i18nMessages, END_TIME;
35
+ var app, logger, defaultConsoleConfig, defaultConsoleGlobal, CONFIG_START_TIME, configData, _yield$Promise$all, _yield$Promise$all2, consoleConfig, consoleGlobal, messages, CONFIG_END_TIME, i18nMessages, END_TIME;
34
36
 
35
37
  return _regenerator.default.wrap(function _callee$(_context) {
36
38
  while (1) {
@@ -38,39 +40,41 @@ function _afterLoadHook() {
38
40
  case 0:
39
41
  app = appConfig.app, logger = appConfig.logger;
40
42
  defaultConsoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
43
+ defaultConsoleGlobal = window.ALIYUN_CONSOLE_GLOBAL || {};
41
44
  CONFIG_START_TIME = Date.now();
42
- _context.next = 5;
43
- return Promise.all([(0, _getConsoleConfig.getConsoleConfig)(appConfig, defaultConsoleConfig), (0, _alfaCore.getLocale)(appConfig)]).catch(function (e) {
44
- logger === null || logger === void 0 ? void 0 : logger.error({
45
- E_MSG: 'fetch config & locale error.',
46
- E_STACK: e
47
- });
48
- return [{}, {}];
49
- });
50
-
51
- case 5:
52
- _yield$Promise$all$ca = _context.sent;
53
- _yield$Promise$all$ca2 = (0, _slicedToArray2.default)(_yield$Promise$all$ca, 2);
54
- consoleConfig = _yield$Promise$all$ca2[0];
55
- messages = _yield$Promise$all$ca2[1];
45
+ _context.next = 6;
46
+ return (0, _alfaCore.getConfig)(appConfig);
47
+
48
+ case 6:
49
+ configData = _context.sent;
50
+ _context.next = 9;
51
+ return Promise.all([(0, _getConsoleConfig.getConsoleConfig)(configData, defaultConsoleConfig), (0, _getConsoleGlobal.getConsoleGlobal)(configData, defaultConsoleGlobal), (0, _alfaCore.getI18nMessages)(appConfig)]);
52
+
53
+ case 9:
54
+ _yield$Promise$all = _context.sent;
55
+ _yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 3);
56
+ consoleConfig = _yield$Promise$all2[0];
57
+ consoleGlobal = _yield$Promise$all2[1];
58
+ messages = _yield$Promise$all2[2];
56
59
  CONFIG_END_TIME = Date.now();
57
- i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages);
60
+ i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages); // inject global variables
58
61
 
59
62
  if (app && app.context) {
60
63
  app.context.window.ALIYUN_CONSOLE_CONFIG = consoleConfig;
61
- app.context.window.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages; // (app.context.history as any) = {};
64
+ app.context.window.ALIYUN_CONSOLE_GLOBAL = consoleGlobal;
65
+ app.context.window.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages;
62
66
  }
63
67
 
64
68
  END_TIME = Date.now();
65
- logger === null || logger === void 0 ? void 0 : logger.record({
69
+ (logger === null || logger === void 0 ? void 0 : logger.record) && logger.record({
66
70
  CONFIG_START_TIME: CONFIG_START_TIME,
67
71
  CONFIG_END_TIME: CONFIG_END_TIME,
68
72
  END_TIME: END_TIME
69
73
  });
70
- logger === null || logger === void 0 ? void 0 : logger.send();
74
+ (logger === null || logger === void 0 ? void 0 : logger.send) && logger.send();
71
75
  return _context.abrupt("return", appConfig);
72
76
 
73
- case 16:
77
+ case 21:
74
78
  case "end":
75
79
  return _context.stop();
76
80
  }
@@ -23,30 +23,21 @@ function beforeResolveHook(_x) {
23
23
 
24
24
  function _beforeResolveHook() {
25
25
  _beforeResolveHook = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(appConfig) {
26
- var resolvedManifest, logger, START_TIME, MANIFEST_START_TIME, MANIFEST_END_TIME;
26
+ var logger, START_TIME, MANIFEST_START_TIME, resolvedManifest, MANIFEST_END_TIME;
27
27
  return _regenerator.default.wrap(function _callee$(_context) {
28
28
  while (1) {
29
29
  switch (_context.prev = _context.next) {
30
30
  case 0:
31
- resolvedManifest = appConfig.manifest;
32
31
  logger = appConfig.logger;
33
32
  START_TIME = Date.now();
34
33
  MANIFEST_START_TIME = Date.now();
35
-
36
- if (resolvedManifest) {
37
- _context.next = 8;
38
- break;
39
- }
40
-
41
- _context.next = 7;
34
+ _context.next = 5;
42
35
  return (0, _alfaCore.getManifest)(appConfig);
43
36
 
44
- case 7:
37
+ case 5:
45
38
  resolvedManifest = _context.sent;
46
-
47
- case 8:
48
39
  MANIFEST_END_TIME = Date.now();
49
- logger === null || logger === void 0 ? void 0 : logger.record({
40
+ (logger === null || logger === void 0 ? void 0 : logger.record) && logger.record({
50
41
  LOADER_VERSION: _version.version,
51
42
  START_TIME: START_TIME,
52
43
  MANIFEST_START_TIME: MANIFEST_START_TIME,
@@ -55,7 +46,7 @@ function _beforeResolveHook() {
55
46
  appConfig.manifest = resolvedManifest;
56
47
  return _context.abrupt("return", appConfig);
57
48
 
58
- case 12:
49
+ case 10:
59
50
  case "end":
60
51
  return _context.stop();
61
52
  }
@@ -20,6 +20,7 @@ export interface AlfaFactoryOption extends IAppConfig {
20
20
  js?: Record<string, string>;
21
21
  };
22
22
  runtimeVersion?: string;
23
+ fallbackRender?: (error: Error) => Element;
23
24
  }
24
25
  declare type OmitKeys = 'manifest';
25
26
  export interface WidgetFactoryOption extends Omit<AlfaFactoryOption, OmitKeys> {
@@ -1,17 +1,17 @@
1
- import { IAppConfig } from '@alicloud/alfa-core';
2
- export declare const getConsoleConfig: (config: IAppConfig, consoleConfig: any) => Promise<{
1
+ import { AlfaConfig } from '@alicloud/alfa-core';
2
+ export declare const getConsoleConfig: (configData: AlfaConfig, consoleConfig: any) => Promise<{
3
3
  CHANNEL_LINKS: Partial<Record<string, string>>;
4
- CHANNEL_FEATURE_STATUS: Partial<Record<string, {
4
+ CHANNEL_FEATURE_STATUS: Record<string, {
5
5
  status: boolean;
6
6
  attribute: {
7
7
  customAttrs: Record<string, unknown>;
8
- regions: {
8
+ regions: string[] | {
9
9
  region: string[];
10
10
  };
11
11
  };
12
- }>>;
12
+ }>;
13
13
  FEATURE_STATUS: Partial<Record<string, boolean>>;
14
- fEnv?: "prod" | "local" | "pre" | "daily" | undefined;
14
+ fEnv?: "pre" | "local" | "prod" | "daily" | undefined;
15
15
  LOCALE?: string | undefined;
16
16
  CHANNEL?: string | undefined;
17
17
  SEC_TOKEN?: string | undefined;