@alicloud/alfa-react 1.3.0-canary.1 → 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.
Files changed (43) hide show
  1. package/dist/index.js +6 -6
  2. package/es/app/createIsomorphicMicroApp.js +36 -0
  3. package/es/app/getConsoleConfig.js +1 -1
  4. package/es/app.js +29 -41
  5. package/es/context.js +7 -0
  6. package/es/createAlfaApp.js +116 -0
  7. package/es/createAlfaWidget.js +125 -0
  8. package/es/createApplication.js +113 -0
  9. package/es/types/base.js +26 -0
  10. package/es/types/index.js +1 -0
  11. package/es/utils/getConsoleConfig.js +2 -2
  12. package/es/utils/index.js +3 -0
  13. package/es/widget/emitter.js +4 -4
  14. package/es/widget/getWidgetConfigById.js +6 -5
  15. package/es/widget/getWidgetDeps.js +1 -1
  16. package/es/widget.js +0 -6
  17. package/lib/app/createIsomorphicMicroApp.js +55 -0
  18. package/lib/app/getConsoleConfig.js +1 -1
  19. package/lib/app.js +28 -40
  20. package/lib/base.d.ts +0 -3
  21. package/lib/context.d.ts +7 -0
  22. package/lib/context.js +15 -0
  23. package/lib/createAlfaApp.d.ts +4 -0
  24. package/lib/createAlfaApp.js +135 -0
  25. package/lib/createAlfaWidget.d.ts +4 -0
  26. package/lib/createAlfaWidget.js +145 -0
  27. package/lib/createApplication.d.ts +12 -0
  28. package/lib/createApplication.js +133 -0
  29. package/lib/types/base.d.ts +11 -0
  30. package/lib/types/base.js +37 -0
  31. package/lib/types/index.d.ts +86 -0
  32. package/lib/types/index.js +5 -0
  33. package/lib/types.d.ts +0 -1
  34. package/lib/utils/getConsoleConfig.d.ts +21 -2
  35. package/lib/utils/getConsoleConfig.js +2 -2
  36. package/lib/utils/index.d.ts +1 -0
  37. package/lib/utils/index.js +12 -0
  38. package/lib/widget/emitter.d.ts +1 -0
  39. package/lib/widget/emitter.js +4 -4
  40. package/lib/widget/getWidgetConfigById.js +6 -5
  41. package/lib/widget/getWidgetDeps.js +1 -1
  42. package/lib/widget.js +0 -7
  43. package/package.json +5 -8
@@ -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
+ }
@@ -2,7 +2,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
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; }
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
6
 
7
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
8
 
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, getLocale, createMicroApp } from '@alicloud/alfa-core';
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 './utils/getConsoleConfig';
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
- delete parcelProps.env;
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 App;
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
- App = _context.sent;
69
+ app = _context.sent;
69
70
 
70
- if (App.context && App.context.baseFrame && App.context.baseFrame.contentWindow) {
71
- App.context.baseFrame.contentWindow.ALIYUN_CONSOLE_CONFIG = consoleConfig;
72
- App.context.baseFrame.contentWindow.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages;
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 App.load();
77
+ return app.load();
77
78
 
78
79
  case 6:
79
- if (appRef.current) {
80
- _context.next = 8;
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 10:
85
+ case 8:
93
86
  setMounted(true);
94
- setApp(App);
87
+ setApp(app);
95
88
 
96
- case 12:
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, {}, /*#__PURE__*/React.createElement('div', {
121
- ref: appRef
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, messages, i18nMessages, App;
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
- _context2.next = 12;
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: App
169
+ default: AlfaApp
182
170
  });
183
171
 
184
- case 16:
172
+ case 12:
185
173
  case "end":
186
174
  return _context2.stop();
187
175
  }
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;
@@ -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
+ }
@@ -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 {};
@@ -61,14 +61,14 @@ var mergeConfigDataWithConsoleConfig = function mergeConfigDataWithConsoleConfig
61
61
  };
62
62
 
63
63
  export var getConsoleConfig = /*#__PURE__*/function () {
64
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(option, consoleConfig) {
64
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(config, consoleConfig) {
65
65
  var configData;
66
66
  return _regeneratorRuntime.wrap(function _callee$(_context) {
67
67
  while (1) {
68
68
  switch (_context.prev = _context.next) {
69
69
  case 0:
70
70
  _context.next = 2;
71
- return getConfig(option);
71
+ return getConfig(config);
72
72
 
73
73
  case 2:
74
74
  configData = _context.sent;
@@ -0,0 +1,3 @@
1
+ export var normalizeName = function normalizeName(name) {
2
+ return name.replace(/@/g, '').replace(/\//g, '-');
3
+ };
@@ -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
  }