@alicloud/alfa-react 1.3.0-canary.1 → 1.3.0-canary.8

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.
@@ -0,0 +1,44 @@
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
+
13
+ var App = function App(props) {
14
+ var env = useContext(EnvContext); // 如果 env 为空,则返回 loading
15
+
16
+ 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)) {
17
+ return /*#__PURE__*/React.createElement(Loading, {
18
+ loading: props.loading
19
+ });
20
+ } // get server render string
21
+
22
+
23
+ var renderString = renderToString(props, env);
24
+
25
+ if (!renderString) {
26
+ return /*#__PURE__*/React.createElement(Loading, {
27
+ loading: props.loading
28
+ });
29
+ }
30
+
31
+ return /*#__PURE__*/React.createElement(props.name, {
32
+ children: /*#__PURE__*/React.createElement("div", {
33
+ dangerouslySetInnerHTML: {
34
+ __html: renderString
35
+ }
36
+ })
37
+ });
38
+ };
39
+
40
+ export function createIsomorphicAlfaApp(option) {
41
+ return function (props) {
42
+ return /*#__PURE__*/React.createElement(ErrorBoundary, props, /*#__PURE__*/React.createElement(App, _objectSpread(_objectSpread({}, props), option)));
43
+ };
44
+ }
@@ -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,11 +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
14
  import ErrorBoundary from './components/ErrorBoundary';
15
- import { getConsoleConfig } from './utils/getConsoleConfig';
16
- import { normalizeName } from './utils';
15
+ import { getConsoleConfig } from './app/getConsoleConfig';
16
+ import { createIsomorphicAlfaApp } from './app/createIsomorphicMicroApp';
17
+ import { normalizeName, isSSR } from './utils';
17
18
 
18
19
  var getProps = function getProps(props) {
19
20
  var parcelProps = _objectSpread({}, props);
@@ -23,8 +24,10 @@ var getProps = function getProps(props) {
23
24
  delete parcelProps.loading;
24
25
  delete parcelProps.entry;
25
26
  delete parcelProps.container;
26
- delete parcelProps.logger;
27
- delete parcelProps.env;
27
+ delete parcelProps.logger; // @ts-ignore
28
+
29
+ delete parcelProps.env; // @ts-ignore
30
+
28
31
  delete parcelProps.dependencies;
29
32
  return parcelProps;
30
33
  };
@@ -35,8 +38,7 @@ var Application = function Application(props) {
35
38
  loading = props.loading,
36
39
  style = props.style,
37
40
  className = props.className,
38
- consoleConfig = props.consoleConfig,
39
- i18nMessages = props.i18nMessages;
41
+ consoleConfig = props.consoleConfig;
40
42
 
41
43
  var _useState = useState(false),
42
44
  _useState2 = _slicedToArray(_useState, 2),
@@ -51,7 +53,7 @@ var Application = function Application(props) {
51
53
  var appRef = useRef(null);
52
54
  useEffect(function () {
53
55
  _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
54
- var App;
56
+ var app;
55
57
  return _regeneratorRuntime.wrap(function _callee$(_context) {
56
58
  while (1) {
57
59
  switch (_context.prev = _context.next) {
@@ -65,35 +67,27 @@ var Application = function Application(props) {
65
67
  });
66
68
 
67
69
  case 2:
68
- App = _context.sent;
70
+ app = _context.sent;
69
71
 
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;
72
+ if (app.context && app.context.baseFrame) {
73
+ // @ts-ignore
74
+ app.context.baseFrame.contentWindow.ALIYUN_CONSOLE_CONFIG = consoleConfig;
73
75
  }
74
76
 
75
77
  _context.next = 6;
76
- return App.load();
78
+ return app.load();
77
79
 
78
80
  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, {
81
+ _context.next = 8;
82
+ return app.mount(appRef.current, {
89
83
  customProps: getProps(props)
90
84
  });
91
85
 
92
- case 10:
86
+ case 8:
93
87
  setMounted(true);
94
- setApp(App);
88
+ setApp(app);
95
89
 
96
- case 12:
90
+ case 10:
97
91
  case "end":
98
92
  return _context.stop();
99
93
  }
@@ -117,17 +111,24 @@ var Application = function Application(props) {
117
111
  className: className,
118
112
  ref: appRef,
119
113
  dataId: name
120
- }) : /*#__PURE__*/React.createElement(name, {}, /*#__PURE__*/React.createElement('div', {
121
- ref: appRef
122
- })));
114
+ }) : /*#__PURE__*/React.createElement(name, {
115
+ children: /*#__PURE__*/React.createElement('div', {
116
+ ref: appRef
117
+ })
118
+ }));
123
119
  };
124
120
 
125
121
  export function createAlfaApp(option) {
126
122
  var name = option.name,
127
123
  loading = option.loading,
128
124
  manifest = option.manifest;
125
+
126
+ if (isSSR()) {
127
+ return createIsomorphicAlfaApp(option);
128
+ }
129
+
129
130
  var AlfaApp = /*#__PURE__*/lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
130
- var resolvedManifest, consoleConfig, messages, i18nMessages, App;
131
+ var resolvedManifest, consoleConfig, AlfaApp;
131
132
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
132
133
  while (1) {
133
134
  switch (_context2.prev = _context2.next) {
@@ -146,6 +147,7 @@ export function createAlfaApp(option) {
146
147
  resolvedManifest = _context2.sent;
147
148
 
148
149
  case 5:
150
+ // @ts-ignore
149
151
  consoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
150
152
 
151
153
  if (!option.dynamicConfig) {
@@ -160,28 +162,20 @@ export function createAlfaApp(option) {
160
162
  consoleConfig = _context2.sent;
161
163
 
162
164
  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) {
165
+ AlfaApp = function AlfaApp(props) {
171
166
  return /*#__PURE__*/React.createElement(Application, _extends({
172
167
  manifest: resolvedManifest
173
168
  }, props, {
174
169
  name: normalizeName(name),
175
- consoleConfig: consoleConfig,
176
- i18nMessages: i18nMessages
170
+ consoleConfig: consoleConfig
177
171
  }));
178
172
  };
179
173
 
180
174
  return _context2.abrupt("return", {
181
- default: App
175
+ default: AlfaApp
182
176
  });
183
177
 
184
- case 16:
178
+ case 12:
185
179
  case "end":
186
180
  return _context2.stop();
187
181
  }
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
+ };
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
  }, {