@alicloud/alfa-react 1.3.0-alpha.1 → 1.3.0-canary.11

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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +6 -6
  3. package/es/app/createIsomorphicMicroApp.js +45 -0
  4. package/es/app/getConsoleConfig.js +49 -0
  5. package/es/app.js +48 -45
  6. package/es/components/ErrorBoundary/index.js +1 -0
  7. package/es/components/Loading/index.js +17 -1
  8. package/es/context.js +7 -0
  9. package/es/index.js +2 -2
  10. package/es/utils/getConsoleConfig.js +3 -1
  11. package/es/utils.js +3 -0
  12. package/es/widget/emitter.js +4 -4
  13. package/es/widget/getWidgetConfigById.js +6 -5
  14. package/es/widget/getWidgetDeps.js +3 -3
  15. package/es/widget.js +1 -1
  16. package/lib/app/createIsomorphicMicroApp.d.ts +2 -0
  17. package/lib/app/createIsomorphicMicroApp.js +65 -0
  18. package/lib/app/getConsoleConfig.d.ts +2 -0
  19. package/lib/{utils → app}/getConsoleConfig.js +7 -45
  20. package/lib/app.d.ts +1 -2
  21. package/lib/app.js +48 -43
  22. package/lib/base.d.ts +1 -4
  23. package/lib/components/ErrorBoundary/index.js +1 -0
  24. package/lib/components/Loading/Title.d.ts +0 -1
  25. package/lib/components/Loading/index.d.ts +5 -2
  26. package/lib/components/Loading/index.js +18 -1
  27. package/lib/context.d.ts +7 -0
  28. package/lib/context.js +15 -0
  29. package/lib/index.d.ts +2 -2
  30. package/lib/index.js +4 -6
  31. package/lib/types.d.ts +7 -5
  32. package/lib/utils.d.ts +1 -0
  33. package/lib/utils.js +8 -2
  34. package/lib/widget/emitter.d.ts +1 -0
  35. package/lib/widget/emitter.js +4 -4
  36. package/lib/widget/getWidgetConfigById.js +6 -5
  37. package/lib/widget/getWidgetDeps.js +2 -2
  38. package/lib/widget.d.ts +1 -2
  39. package/lib/widget.js +2 -2
  40. package/package.json +6 -10
  41. package/es/utils/checkOptions.js +0 -13
  42. package/lib/createAlfaApp.d.ts +0 -4
  43. package/lib/createAlfaApp.js +0 -135
  44. package/lib/createAlfaWidget.d.ts +0 -4
  45. package/lib/createAlfaWidget.js +0 -145
  46. package/lib/createApplication.d.ts +0 -13
  47. package/lib/createApplication.js +0 -133
  48. package/lib/types/base.d.ts +0 -11
  49. package/lib/types/base.js +0 -37
  50. package/lib/types/index.d.ts +0 -86
  51. package/lib/types/index.js +0 -5
  52. package/lib/utils/checkOptions.d.ts +0 -0
  53. package/lib/utils/checkOptions.js +0 -14
  54. package/lib/utils/getConsoleConfig.d.ts +0 -21
  55. package/lib/utils/index.d.ts +0 -1
  56. package/lib/utils/index.js +0 -12
@@ -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,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, getLocale, createMicroApp } from '@alicloud/alfa-core';
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 './utils/getConsoleConfig';
17
- import { normalizeName } from './utils';
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
- delete parcelProps.env;
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 App;
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
- App = _context.sent;
70
+ app = _context.sent;
70
71
 
71
- if (App.context && App.context) {
72
- App.context.window.ALIYUN_CONSOLE_CONFIG = consoleConfig;
73
- App.context.window.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages;
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 App.load();
78
+ return app.load();
78
79
 
79
80
  case 6:
80
- if (appRef.current) {
81
- _context.next = 8;
82
- break;
83
- }
84
-
85
- return _context.abrupt("return");
86
-
87
- case 8:
88
- _context.next = 10;
89
- return App.mount(appRef.current, {
81
+ _context.next = 8;
82
+ return app.mount(appRef.current, {
90
83
  customProps: getProps(props)
91
84
  });
92
85
 
93
- case 10:
86
+ case 8:
94
87
  setMounted(true);
95
- setApp(App);
88
+ setApp(app);
96
89
 
97
- case 12:
90
+ case 10:
98
91
  case "end":
99
92
  return _context.stop();
100
93
  }
@@ -112,23 +105,31 @@ var Application = function Application(props) {
112
105
  }
113
106
 
114
107
  return /*#__PURE__*/React.createElement(React.Fragment, null, !mounted && /*#__PURE__*/React.createElement(Loading, {
108
+ microAppContainer: name,
115
109
  loading: loading
116
110
  }), sandbox && sandbox !== true && sandbox.disableFakeBody ? /*#__PURE__*/React.createElement(name, {
117
111
  style: style,
118
112
  className: className,
119
113
  ref: appRef,
120
114
  dataId: name
121
- }) : /*#__PURE__*/React.createElement(name, {}, /*#__PURE__*/React.createElement('div', {
122
- ref: appRef
123
- })));
115
+ }) : /*#__PURE__*/React.createElement(name, {
116
+ children: /*#__PURE__*/React.createElement('div', {
117
+ ref: appRef
118
+ })
119
+ }));
124
120
  };
125
121
 
126
122
  export function createAlfaApp(option) {
127
123
  var name = option.name,
128
124
  loading = option.loading,
129
125
  manifest = option.manifest;
126
+
127
+ if (isSSR()) {
128
+ return createIsomorphicAlfaApp(option);
129
+ }
130
+
130
131
  var AlfaApp = /*#__PURE__*/lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
131
- var resolvedManifest, consoleConfig, messages, i18nMessages, App;
132
+ var resolvedManifest, consoleConfig, AlfaApp;
132
133
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
133
134
  while (1) {
134
135
  switch (_context2.prev = _context2.next) {
@@ -147,34 +148,35 @@ export function createAlfaApp(option) {
147
148
  resolvedManifest = _context2.sent;
148
149
 
149
150
  case 5:
151
+ // @ts-ignore
150
152
  consoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
151
- _context2.next = 8;
153
+
154
+ if (!option.dynamicConfig) {
155
+ _context2.next = 10;
156
+ break;
157
+ }
158
+
159
+ _context2.next = 9;
152
160
  return getConsoleConfig(option, consoleConfig);
153
161
 
154
- case 8:
162
+ case 9:
155
163
  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
164
 
163
- App = function App(props) {
165
+ case 10:
166
+ AlfaApp = function AlfaApp(props) {
164
167
  return /*#__PURE__*/React.createElement(Application, _extends({
165
168
  manifest: resolvedManifest
166
169
  }, props, {
167
170
  name: normalizeName(name),
168
- consoleConfig: consoleConfig,
169
- i18nMessages: i18nMessages
171
+ consoleConfig: consoleConfig
170
172
  }));
171
173
  };
172
174
 
173
175
  return _context2.abrupt("return", {
174
- default: App
176
+ default: AlfaApp
175
177
  });
176
178
 
177
- case 15:
179
+ case 12:
178
180
  case "end":
179
181
  return _context2.stop();
180
182
  }
@@ -184,6 +186,7 @@ export function createAlfaApp(option) {
184
186
  return function (props) {
185
187
  return /*#__PURE__*/React.createElement(ErrorBoundary, props, /*#__PURE__*/React.createElement(Suspense, {
186
188
  fallback: /*#__PURE__*/React.createElement(Loading, {
189
+ microAppContainer: normalizeName(name),
187
190
  loading: loading
188
191
  })
189
192
  }, /*#__PURE__*/React.createElement(AlfaApp, _extends({}, option, {
@@ -191,4 +194,4 @@ export function createAlfaApp(option) {
191
194
  }, props))));
192
195
  };
193
196
  }
194
- export { AlfaFactoryOption };
197
+ 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
  }, {
@@ -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,7 @@
1
+ import { createContext } from 'react';
2
+
3
+ /**
4
+ * 用来提供 ssr 状态下的获取 服务端 manifest & bundle 的实现
5
+ */
6
+ var EnvContext = /*#__PURE__*/createContext({});
7
+ export default EnvContext;
package/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { default as createAlfaApp } from './createAlfaApp';
2
- export { default as createAlfaWidget } from './createAlfaWidget';
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
@@ -1,3 +1,6 @@
1
1
  export var normalizeName = function normalizeName(name) {
2
2
  return name.replace(/@/g, '').replace(/\//g, '-');
3
+ };
4
+ export var isSSR = function isSSR() {
5
+ return typeof document === 'undefined';
3
6
  };
@@ -18,13 +18,13 @@ var WidgetEventEmitter = /*#__PURE__*/function (_EventEmitter) {
18
18
  function WidgetEventEmitter() {
19
19
  _classCallCheck(this, WidgetEventEmitter);
20
20
 
21
- return _super.apply(this, arguments);
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: // Compatible with the old api, this may get removed at sometime later.
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 = 6;
18
+ _context.next = 7;
18
19
  break;
19
20
  }
20
21
 
21
- _context.next = 4;
22
+ _context.next = 5;
22
23
  return axios.get(template(env.configUrl)({
23
24
  id: option.name
24
25
  }));
25
26
 
26
- case 4:
27
+ case 5:
27
28
  resp = _context.sent;
28
29
  cachedConfig[option.name] = resp.data;
29
30
 
30
- case 6:
31
+ case 7:
31
32
  return _context.abrupt("return", cachedConfig[option.name]);
32
33
 
33
- case 7:
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 { createCWSWidget } from '../widget';
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 createCWSWidget({
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 createCWSWidget(option) {
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,2 @@
1
+ import { AlfaFactoryOption } from '../types';
2
+ export declare function createIsomorphicAlfaApp<T = any>(option: AlfaFactoryOption): (props: T) => JSX.Element;
@@ -0,0 +1,65 @@
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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _react = _interopRequireWildcard(require("react"));
15
+
16
+ var _alfaCore = require("@alicloud/alfa-core");
17
+
18
+ var _context = _interopRequireDefault(require("../context"));
19
+
20
+ var _ErrorBoundary = _interopRequireDefault(require("../components/ErrorBoundary"));
21
+
22
+ var _Loading = _interopRequireDefault(require("../components/Loading"));
23
+
24
+ var _utils = require("../utils");
25
+
26
+ 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); }
27
+
28
+ 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; }
29
+
30
+ 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; }
31
+
32
+ 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; }
33
+
34
+ var App = function App(props) {
35
+ var env = (0, _react.useContext)(_context.default); // 如果 env 为空,则返回 loading
36
+
37
+ 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)) {
38
+ return /*#__PURE__*/_react.default.createElement(_Loading.default, {
39
+ loading: props.loading
40
+ });
41
+ } // get server render string
42
+
43
+
44
+ var renderString = (0, _alfaCore.renderToString)(props, env);
45
+
46
+ if (!renderString) {
47
+ return /*#__PURE__*/_react.default.createElement(_Loading.default, {
48
+ loading: props.loading
49
+ });
50
+ }
51
+
52
+ return /*#__PURE__*/_react.default.createElement((0, _utils.normalizeName)(props.name), {
53
+ children: /*#__PURE__*/_react.default.createElement("div", {
54
+ dangerouslySetInnerHTML: {
55
+ __html: renderString
56
+ }
57
+ })
58
+ });
59
+ };
60
+
61
+ function createIsomorphicAlfaApp(option) {
62
+ return function (props) {
63
+ return /*#__PURE__*/_react.default.createElement(_ErrorBoundary.default, props, /*#__PURE__*/_react.default.createElement(App, _objectSpread(_objectSpread({}, props), option)));
64
+ };
65
+ }
@@ -0,0 +1,2 @@
1
+ import { AlfaFactoryOption } from '@alicloud/alfa-core';
2
+ export declare const getConsoleConfig: (option: AlfaFactoryOption, consoleConfig: any) => Promise<any>;
@@ -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, _configData$ALL_CHANN, _configData$ALL_CHANN2;
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 = ((_configData$ALL_CHANN = configData.ALL_CHANNEL_LINKS) === null || _configData$ALL_CHANN === void 0 ? void 0 : _configData$ALL_CHANN[channel]) || {};
64
- var channelFeatures = ((_configData$ALL_CHANN2 = configData.ALL_CHANNEL_FEATURE_STATUS) === null || _configData$ALL_CHANN2 === void 0 ? void 0 : _configData$ALL_CHANN2[channel]) || {};
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: channelFeatures,
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(config, consoleConfig) {
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)(config);
43
+ return (0, _alfaCore.getConfig)(option);
82
44
 
83
45
  case 2:
84
46
  configData = _context.sent;
package/lib/app.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { AlfaFactoryOption } from './types';
3
2
  export declare function createAlfaApp<T = any>(option: AlfaFactoryOption): (props: T) => JSX.Element;
4
- export { AlfaFactoryOption };
3
+ export { AlfaFactoryOption } from './types';