@alicloud/alfa-react 1.4.40-alpha.0 → 1.5.0-alpha.0

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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/es/components/ErrorBoundary/ErrorPanel.js +0 -2
  3. package/es/components/ErrorBoundary/index.js +7 -19
  4. package/es/components/Loading/Paragraph.js +9 -25
  5. package/es/components/Loading/Skeleton.js +14 -46
  6. package/es/components/Loading/Title.js +3 -8
  7. package/es/components/Loading/index.js +0 -2
  8. package/es/createAlfaApp.js +6 -10
  9. package/es/createAlfaWidget.js +16 -28
  10. package/es/createApplication.js +154 -188
  11. package/es/hooks/beforeLoadHook.js +60 -81
  12. package/es/hooks/beforeResolveHook.js +24 -29
  13. package/es/index.js +2 -2
  14. package/es/types/base.js +0 -9
  15. package/es/utils/counter.js +1 -3
  16. package/es/utils/getConsoleConfig.js +13 -32
  17. package/es/utils/getConsoleGlobal.js +6 -13
  18. package/es/utils/index.js +2 -1
  19. package/es/version.js +1 -1
  20. package/es/widget/emitter.js +2 -11
  21. package/es/widget/env.js +2 -4
  22. package/es/widget/getWidgetConfigById.js +19 -27
  23. package/es/widget/getWidgetDeps.js +104 -130
  24. package/es/widget/getWidgetVersionById.js +79 -106
  25. package/es/widget.js +45 -58
  26. package/lib/addGlobalRequestInterceptor.js +0 -2
  27. package/lib/components/ErrorBoundary/ErrorPanel.js +0 -5
  28. package/lib/components/ErrorBoundary/index.js +7 -25
  29. package/lib/components/Loading/Paragraph.js +9 -32
  30. package/lib/components/Loading/Skeleton.js +14 -60
  31. package/lib/components/Loading/Title.js +3 -14
  32. package/lib/components/Loading/index.js +0 -6
  33. package/lib/createAlfaApp.js +6 -24
  34. package/lib/createAlfaWidget.js +16 -45
  35. package/lib/createApplication.js +154 -199
  36. package/lib/hooks/beforeLoadHook.js +60 -88
  37. package/lib/hooks/beforeResolveHook.js +21 -33
  38. package/lib/index.js +0 -9
  39. package/lib/types/base.js +0 -14
  40. package/lib/utils/counter.js +1 -4
  41. package/lib/utils/getConsoleConfig.js +12 -37
  42. package/lib/utils/getConsoleGlobal.js +6 -18
  43. package/lib/utils/index.js +2 -5
  44. package/lib/version.js +1 -1
  45. package/lib/widget/emitter.js +2 -16
  46. package/lib/widget/env.js +2 -6
  47. package/lib/widget/getWidgetConfigById.js +19 -36
  48. package/lib/widget/getWidgetDeps.js +103 -146
  49. package/lib/widget/getWidgetVersionById.js +79 -113
  50. package/lib/widget/index.js +0 -8
  51. package/lib/widget.js +45 -72
  52. package/package.json +22 -19
  53. package/types/components/ErrorBoundary/index.d.ts +1 -1
  54. package/types/components/Loading/Paragraph.d.ts +1 -1
  55. package/types/components/Loading/Skeleton.d.ts +2 -2
  56. package/types/createAlfaApp.d.ts +7 -1
  57. package/types/createAlfaWidget.d.ts +2 -2
  58. package/types/createApplication.d.ts +1 -0
  59. package/types/types/index.d.ts +5 -5
  60. package/types/utils/getConsoleConfig.d.ts +4 -2
  61. package/types/utils/getConsoleGlobal.d.ts +3 -1
  62. package/types/version.d.ts +1 -1
  63. package/types/widget/getWidgetDeps.d.ts +1 -1
  64. package/dist/index.js +0 -21
  65. package/es/app.js +0 -194
  66. package/es/hooks/afterLoadHook.js +0 -69
  67. package/lib/app.d.ts +0 -3
  68. package/lib/app.js +0 -223
  69. package/lib/components/ErrorBoundary/ErrorPanel.d.ts +0 -6
  70. package/lib/components/ErrorBoundary/index.d.ts +0 -17
  71. package/lib/components/Loading/Paragraph.d.ts +0 -14
  72. package/lib/components/Loading/Skeleton.d.ts +0 -19
  73. package/lib/components/Loading/Title.d.ts +0 -8
  74. package/lib/components/Loading/index.d.ts +0 -4
  75. package/lib/components/Loading/style.d.ts +0 -2
  76. package/lib/createAlfaApp.d.ts +0 -7
  77. package/lib/createAlfaWidget.d.ts +0 -4
  78. package/lib/createApplication.d.ts +0 -12
  79. package/lib/hooks/afterLoadHook.d.ts +0 -3
  80. package/lib/hooks/afterLoadHook.js +0 -84
  81. package/lib/hooks/beforeLoadHook.d.ts +0 -3
  82. package/lib/hooks/beforeResolveHook.d.ts +0 -3
  83. package/lib/index.d.ts +0 -4
  84. package/lib/types/base.d.ts +0 -11
  85. package/lib/types/index.d.ts +0 -91
  86. package/lib/utils/getConsoleConfig.d.ts +0 -1
  87. package/lib/utils/getConsoleGlobal.d.ts +0 -1
  88. package/lib/utils/index.d.ts +0 -1
  89. package/lib/version.d.ts +0 -1
  90. package/lib/widget/emitter.d.ts +0 -8
  91. package/lib/widget/env.d.ts +0 -4
  92. package/lib/widget/getWidgetConfigById.d.ts +0 -2
  93. package/lib/widget/getWidgetDeps.d.ts +0 -2
  94. package/lib/widget/getWidgetVersionById.d.ts +0 -6
  95. package/lib/widget/index.d.ts +0 -4
  96. package/lib/widget.d.ts +0 -2
@@ -1,166 +1,134 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports.default = createApplication;
11
-
12
9
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
-
14
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
-
16
11
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
17
-
18
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
-
20
13
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
21
-
22
14
  var _react = _interopRequireWildcard(require("react"));
23
-
15
+ var _alfaCore = require("@alicloud/alfa-core");
24
16
  var _Loading = _interopRequireDefault(require("./components/Loading"));
25
-
26
17
  var _utils = require("./utils");
27
-
28
18
  var _counter = require("./utils/counter");
29
-
30
19
  var _version = require("./version");
31
-
32
20
  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); }
33
-
34
21
  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; }
35
-
36
22
  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; }
37
-
38
23
  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; }
39
-
24
+ var eventBus = (0, _alfaCore.createEventBus)();
40
25
  var resolvePath = function resolvePath() {
41
26
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
42
27
  args[_key] = arguments[_key];
43
28
  }
44
-
45
29
  return "/".concat(args.join('/')).replace(/\/+/g, '/');
46
30
  };
31
+
47
32
  /**
48
33
  * 去掉 location.origin 的路径
49
34
  */
50
-
51
-
52
35
  var peelPath = function peelPath(location) {
53
36
  return location.pathname + location.search + location.hash;
54
37
  };
55
-
56
38
  var addBasename = function addBasename(path, basename) {
57
39
  if (!basename) return path;
58
40
  return resolvePath(basename, path);
59
41
  };
60
-
61
42
  var addLeftSlash = function addLeftSlash(path) {
62
43
  return path.charAt(0) === '/' ? path : "/".concat(path);
63
44
  };
45
+
64
46
  /**
65
47
  * 从 path 移除 basename 部分
66
48
  * @param path
67
49
  * @param basename
68
50
  * @returns string
69
51
  */
70
-
71
-
72
52
  var stripBasename = function stripBasename(path, basename) {
73
53
  if (!basename) return path;
74
-
75
54
  var _path = resolvePath(path);
76
-
77
55
  var _basename = resolvePath(basename);
78
-
79
- if (_path === _basename) return '/'; // escape all possible regex special characters
80
-
56
+ if (_path === _basename) return '/';
57
+ // escape all possible regex special characters
81
58
  return _path.replace(new RegExp("^".concat(_basename.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1')), 'ig'), '');
82
59
  };
60
+
83
61
  /**
84
62
  * container for microApp mount
85
63
  * @param loader alfa-core loader
86
64
  * @returns
87
65
  */
88
-
89
-
90
66
  function createApplication(loader) {
91
67
  return function Application(props) {
92
68
  var name = props.name,
93
- version = props.version,
94
- manifest = props.manifest,
95
- loading = props.loading,
96
- customProps = props.customProps,
97
- className = props.className,
98
- style = props.style,
99
- container = props.container,
100
- entry = props.entry,
101
- url = props.url,
102
- customLogger = props.logger,
103
- deps = props.deps,
104
- env = props.env,
105
- beforeMount = props.beforeMount,
106
- afterMount = props.afterMount,
107
- beforeUnmount = props.beforeUnmount,
108
- afterUnmount = props.afterUnmount,
109
- beforeUpdate = props.beforeUpdate,
110
- customSandbox = props.sandbox,
111
- locale = props.locale,
112
- dynamicConfig = props.dynamicConfig,
113
- noCache = props.noCache,
114
- syncHistory = props.syncHistory,
115
- basename = props.basename;
116
-
69
+ version = props.version,
70
+ manifest = props.manifest,
71
+ loading = props.loading,
72
+ customProps = props.customProps,
73
+ className = props.className,
74
+ style = props.style,
75
+ container = props.container,
76
+ entry = props.entry,
77
+ url = props.url,
78
+ customLogger = props.logger,
79
+ deps = props.deps,
80
+ env = props.env,
81
+ beforeMount = props.beforeMount,
82
+ afterMount = props.afterMount,
83
+ beforeUnmount = props.beforeUnmount,
84
+ afterUnmount = props.afterUnmount,
85
+ beforeUpdate = props.beforeUpdate,
86
+ customSandbox = props.sandbox,
87
+ locale = props.locale,
88
+ dynamicConfig = props.dynamicConfig,
89
+ noCache = props.noCache,
90
+ syncHistory = props.syncHistory,
91
+ basename = props.basename;
92
+ var handleExternalLink = customProps.handleExternalLink;
117
93
  var _useState = (0, _react.useState)(null),
118
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
119
- appInstance = _useState2[0],
120
- setAppInstance = _useState2[1];
121
-
94
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
95
+ appInstance = _useState2[0],
96
+ setAppInstance = _useState2[1];
122
97
  var _useState3 = (0, _react.useState)(null),
123
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
124
- setError = _useState4[1];
125
-
98
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
99
+ setError = _useState4[1];
126
100
  var appRef = (0, _react.useRef)(undefined);
127
101
  var $syncHistory = (0, _react.useRef)(syncHistory);
128
102
  var $basename = (0, _react.useRef)(basename);
129
103
  var tagName = (0, _utils.normalizeName)(props.name);
130
-
131
104
  var _useState5 = (0, _react.useState)(''),
132
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
133
- releaseVersion = _useState6[0],
134
- setReleaseVersion = _useState6[1];
135
-
105
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
106
+ releaseVersion = _useState6[0],
107
+ setReleaseVersion = _useState6[1];
136
108
  $syncHistory.current = syncHistory;
137
109
  $basename.current = basename;
138
- if (customProps.__innerStamp) console.warn('Please do not use __innerStamp which used in internal.'); // 更新标记,保证每次更新都会更新
139
-
110
+ if (customProps.__innerStamp) console.warn('Please do not use __innerStamp which used in internal.');
111
+ // 更新标记,保证每次更新都会更新
140
112
  customProps.__innerStamp = (+new Date()).toString(36);
141
- if (customProps.path) customProps.path = addLeftSlash(customProps.path); // 受控模式锁定一些参数
113
+ if (customProps.path) customProps.path = addLeftSlash(customProps.path);
142
114
 
115
+ // 受控模式锁定一些参数
143
116
  if ($syncHistory.current) {
144
117
  // 禁止子应用和 consoleBase 通信
145
- customProps.consoleBase = null; // 覆写 path 参数,用于通知子应用更新路由
146
-
147
- customProps.path = stripBasename(peelPath(window.location), $basename.current); // 禁止注入 history
148
-
118
+ customProps.consoleBase = null;
119
+ // 覆写 path 参数,用于通知子应用更新路由
120
+ customProps.path = addLeftSlash(stripBasename(peelPath(window.location), $basename.current));
121
+ // 禁止注入 history
149
122
  customProps.__injectHistory = null;
150
123
  }
151
-
152
124
  var sandbox = (0, _react.useMemo)(function () {
153
125
  var _UA_Opt, _RISK_INFO, _um;
154
-
155
126
  var aliyunExternalsVars = [];
156
-
157
127
  if ((_UA_Opt = window.UA_Opt) !== null && _UA_Opt !== void 0 && _UA_Opt.LogVal) {
158
128
  var _UA_Opt2;
159
-
160
129
  aliyunExternalsVars.push('UA_Opt');
161
130
  aliyunExternalsVars.push((_UA_Opt2 = window.UA_Opt) === null || _UA_Opt2 === void 0 ? void 0 : _UA_Opt2.LogVal);
162
131
  }
163
-
164
132
  if ((_RISK_INFO = window.RISK_INFO) !== null && _RISK_INFO !== void 0 && _RISK_INFO.UMID) aliyunExternalsVars.push('RISK_INFO');
165
133
  if ((_um = window.um) !== null && _um !== void 0 && _um.getToken) aliyunExternalsVars.push('um');
166
134
  return _objectSpread(_objectSpread({}, customSandbox), {}, {
@@ -168,14 +136,16 @@ function createApplication(loader) {
168
136
  // ...(customSandbox?.allowResources || []),
169
137
  // /^https?:\/\/at\.alicdn\.com\//,
170
138
  // ],
171
- externalsVars: [].concat((0, _toConsumableArray2.default)((customSandbox === null || customSandbox === void 0 ? void 0 : customSandbox.externalsVars) || []), [// global vars used in ConsoleBase.forApp
139
+ externalsVars: [].concat((0, _toConsumableArray2.default)((customSandbox === null || customSandbox === void 0 ? void 0 : customSandbox.externalsVars) || []), [
140
+ // global vars used in ConsoleBase.forApp
172
141
  '_console_base_ready_'], aliyunExternalsVars),
173
142
  // 配置沙箱初始化 path
174
143
  initialPath: (customSandbox === null || customSandbox === void 0 ? void 0 : customSandbox.initialPath) || customProps.path,
175
144
  syncInitHref: !!$syncHistory.current
176
145
  });
177
- }, [customSandbox, customProps.path]); // 固化第一次的配置
146
+ }, [customSandbox, customProps.path]);
178
147
 
148
+ // 固化第一次的配置
179
149
  var memoOptions = (0, _react.useMemo)(function () {
180
150
  return {
181
151
  entry: entry,
@@ -208,21 +178,20 @@ function createApplication(loader) {
208
178
  var originalPushState;
209
179
  var originalReplaceState;
210
180
  var originalGo;
211
-
212
181
  var dispatchFramePopstate = function dispatchFramePopstate() {
213
182
  var _App, _App$context$baseFram, _App$context$baseFram2;
214
-
215
183
  var popstateEvent = new Event('popstate');
216
184
  popstateEvent.state = 'mock';
217
185
  (_App = App) === null || _App === void 0 ? void 0 : (_App$context$baseFram = _App.context.baseFrame) === null || _App$context$baseFram === void 0 ? void 0 : (_App$context$baseFram2 = _App$context$baseFram.contentWindow) === null || _App$context$baseFram2 === void 0 ? void 0 : _App$context$baseFram2.dispatchEvent(popstateEvent);
218
186
  };
219
-
220
187
  var updateAppHistory = function updateAppHistory() {
221
188
  if (App) {
222
- var nextPath = peelPath(App.context.location); // 路由同步只应该在相同 basename 下生效
189
+ var nextPath = peelPath(App.context.location);
223
190
 
224
- if (!peelPath(window.location).startsWith($basename.current || '')) return; // 如果主子应用路径不同,主动通知子应用 popstate 事件
191
+ // 路由同步只应该在相同 basename 下生效
192
+ if (!peelPath(window.location).startsWith($basename.current || '')) return;
225
193
 
194
+ // 如果主子应用路径不同,主动通知子应用 popstate 事件
226
195
  if (nextPath !== stripBasename(peelPath(window.location), $basename.current)) {
227
196
  if (originalReplaceState) {
228
197
  originalReplaceState(history.state, '', stripBasename(peelPath(window.location), $basename.current));
@@ -230,125 +199,105 @@ function createApplication(loader) {
230
199
  }
231
200
  }
232
201
  }
233
- }; // 受控模式下,返回不会触发子应用内的路由更新,需要主动通知
234
-
202
+ };
235
203
 
204
+ // 受控模式下,返回不会触发子应用内的路由更新,需要主动通知
236
205
  if ($syncHistory.current) window.addEventListener('popstate', updateAppHistory);
237
206
  (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
238
207
  var _app$context$updateBo, _app$context, _app$context$baseFram;
239
-
240
208
  var _yield$loader$registe, app, logger, realVersion, _ref2, path, frameWindow;
241
-
242
209
  return _regenerator.default.wrap(function _callee$(_context) {
243
- while (1) {
244
- switch (_context.prev = _context.next) {
245
- case 0:
246
- (0, _counter.countRegister)(memoOptions.name);
247
- _context.next = 3;
248
- return loader.register(_objectSpread(_objectSpread({}, memoOptions), {}, {
249
- container: memoOptions.container || appRef.current
250
- }));
251
-
252
- case 3:
253
- _yield$loader$registe = _context.sent;
254
- app = _yield$loader$registe.app;
255
- logger = _yield$loader$registe.logger;
256
- realVersion = _yield$loader$registe.version;
257
- setReleaseVersion(realVersion || 'unknown');
258
- App = app; // container has been unmounted
259
-
260
- if (!isUnmounted) {
261
- _context.next = 11;
262
- break;
263
- }
264
-
265
- return _context.abrupt("return");
266
-
267
- case 11:
268
- if (app) {
269
- _context.next = 13;
270
- break;
271
- }
272
-
273
- return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
274
- E_CODE: 'RuntimeError',
275
- E_MSG: 'load app failed.'
276
- }));
277
-
278
- case 13:
279
- if (appRef.current) {
280
- _context.next = 15;
281
- break;
282
- }
283
-
284
- return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
285
- E_CODE: 'RuntimeError',
286
- E_MSG: 'cannot find container.'
287
- }));
288
-
289
- case 15:
290
- // update body in sandbox context
291
- (_app$context$updateBo = (_app$context = app.context).updateBody) === null || _app$context$updateBo === void 0 ? void 0 : _app$context$updateBo.call(_app$context, memoOptions.sandbox.disableFakeBody ? document.body : appRef.current);
292
- _ref2 = memoOptions.props, path = _ref2.path;
293
- frameWindow = (_app$context$baseFram = app.context.baseFrame) === null || _app$context$baseFram === void 0 ? void 0 : _app$context$baseFram.contentWindow;
294
-
210
+ while (1) switch (_context.prev = _context.next) {
211
+ case 0:
212
+ (0, _counter.countRegister)(memoOptions.name);
213
+ _context.next = 3;
214
+ return loader.register(_objectSpread(_objectSpread({}, memoOptions), {}, {
215
+ container: memoOptions.container || appRef.current
216
+ }));
217
+ case 3:
218
+ _yield$loader$registe = _context.sent;
219
+ app = _yield$loader$registe.app;
220
+ logger = _yield$loader$registe.logger;
221
+ realVersion = _yield$loader$registe.version;
222
+ setReleaseVersion(realVersion || 'unknown');
223
+ App = app;
224
+
225
+ // container has been unmounted
226
+ if (!isUnmounted) {
227
+ _context.next = 11;
228
+ break;
229
+ }
230
+ return _context.abrupt("return");
231
+ case 11:
232
+ if (app) {
233
+ _context.next = 13;
234
+ break;
235
+ }
236
+ return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
237
+ E_CODE: 'RuntimeError',
238
+ E_MSG: 'load app failed.'
239
+ }));
240
+ case 13:
241
+ if (appRef.current) {
242
+ _context.next = 15;
243
+ break;
244
+ }
245
+ return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
246
+ E_CODE: 'RuntimeError',
247
+ E_MSG: 'cannot find container.'
248
+ }));
249
+ case 15:
250
+ // update body in sandbox context
251
+ (_app$context$updateBo = (_app$context = app.context).updateBody) === null || _app$context$updateBo === void 0 ? void 0 : _app$context$updateBo.call(_app$context, memoOptions.sandbox.disableFakeBody ? document.body : appRef.current);
252
+ _ref2 = memoOptions.props, path = _ref2.path;
253
+ frameWindow = (_app$context$baseFram = app.context.baseFrame) === null || _app$context$baseFram === void 0 ? void 0 : _app$context$baseFram.contentWindow;
254
+ if (frameWindow) {
255
+ originalPushState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.pushState;
256
+ originalReplaceState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.replaceState;
257
+ originalGo = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.go;
258
+ // update context history according to path
259
+ if (path) originalReplaceState(history.state, '', path.replace(/\/+/g, '/'));
295
260
  if (frameWindow) {
296
- originalPushState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.pushState;
297
- originalReplaceState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.replaceState;
298
- originalGo = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.go; // update context history according to path
299
-
300
- if (path) originalReplaceState(history.state, '', path.replace(/\/+/g, '/'));
301
-
302
- if (frameWindow) {
303
- frameWindow.history.pushState = function (data, unused, _url) {
304
- if ($syncHistory.current) {
305
- var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
306
-
307
- if ("".concat(nextPath) !== peelPath(window.location)) {
308
- window.history.pushState(data, unused, nextPath);
309
- }
310
-
311
- originalReplaceState(data, unused, _url);
312
- } else {
313
- originalPushState(data, unused, _url);
314
- }
315
- };
316
-
317
- frameWindow.history.replaceState = function (data, unused, _url) {
261
+ frameWindow.history.pushState = function (data, unused, _url) {
262
+ if ($syncHistory.current) {
318
263
  var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
319
-
320
- if ($syncHistory.current) {
321
- window.history.replaceState(data, unused, nextPath);
264
+ if ("".concat(nextPath) !== peelPath(window.location)) {
265
+ window.history.pushState(data, unused, nextPath);
322
266
  }
323
-
324
267
  originalReplaceState(data, unused, _url);
325
- }; // 劫持微应用的返回
326
-
327
-
328
- frameWindow.history.go = function (n) {
329
- window.history.go(n);
330
- };
331
- }
268
+ } else {
269
+ originalPushState(data, unused, _url);
270
+ }
271
+ };
272
+ frameWindow.history.replaceState = function (data, unused, _url) {
273
+ var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
274
+ if ($syncHistory.current) {
275
+ window.history.replaceState(data, unused, nextPath);
276
+ }
277
+ originalReplaceState(data, unused, _url);
278
+ };
279
+
280
+ // 劫持微应用的返回
281
+ frameWindow.history.go = function (n) {
282
+ window.history.go(n);
283
+ };
332
284
  }
333
-
334
- _context.next = 21;
335
- return app.mount(appRef.current, {
336
- customProps: customProps
337
- });
338
-
339
- case 21:
340
- if (frameWindow) {
341
- // 每次挂载后主动触发子应用内的 popstate 事件,借此触发 react-router history 的检查逻辑
342
- dispatchFramePopstate();
343
- } // just run once
344
-
345
-
346
- setAppInstance(app);
347
-
348
- case 23:
349
- case "end":
350
- return _context.stop();
351
- }
285
+ }
286
+ _context.next = 21;
287
+ return app.mount(appRef.current, {
288
+ customProps: customProps
289
+ });
290
+ case 21:
291
+ if (frameWindow) {
292
+ // 每次挂载后主动触发子应用内的 popstate 事件,借此触发 react-router history 的检查逻辑
293
+ dispatchFramePopstate();
294
+ }
295
+
296
+ // just run once
297
+ setAppInstance(app);
298
+ case 23:
299
+ case "end":
300
+ return _context.stop();
352
301
  }
353
302
  }, _callee);
354
303
  }))().catch(function (e) {
@@ -358,27 +307,33 @@ function createApplication(loader) {
358
307
  });
359
308
  return function () {
360
309
  var _App$context$baseFram3, _App$context$baseFram4;
361
-
362
310
  isUnmounted = true;
363
311
  if ($syncHistory.current) window.removeEventListener('popstate', updateAppHistory);
364
312
  if (!App) return;
365
313
  var frameHistory = (_App$context$baseFram3 = App.context.baseFrame) === null || _App$context$baseFram3 === void 0 ? void 0 : (_App$context$baseFram4 = _App$context$baseFram3.contentWindow) === null || _App$context$baseFram4 === void 0 ? void 0 : _App$context$baseFram4.history;
366
-
367
314
  if (frameHistory) {
368
315
  if (originalPushState !== frameHistory.pushState) frameHistory.pushState = originalPushState;
369
316
  if (originalReplaceState !== frameHistory.replaceState) frameHistory.replaceState = originalReplaceState;
370
317
  if (originalGo !== frameHistory.go) frameHistory.go = originalGo;
371
318
  }
319
+ App.unmount();
372
320
 
373
- App.unmount(); // TODO: 在沙箱中嵌套时,unmount 必须销毁沙箱实例,避免在其它微应用中复用该沙箱,导致环境变量污染
321
+ // TODO: 在沙箱中嵌套时,unmount 必须销毁沙箱实例,避免在其它微应用中复用该沙箱,导致环境变量污染
374
322
  // if (isOsContext()) App.destroy();
375
323
  };
376
324
  }, [memoOptions]);
377
-
325
+ (0, _react.useEffect)(function () {
326
+ var _handleExternalLink = function _handleExternalLink(href) {
327
+ handleExternalLink === null || handleExternalLink === void 0 ? void 0 : handleExternalLink(href);
328
+ };
329
+ eventBus.on("".concat((0, _utils.normalizeName)(name), ":external-router"), _handleExternalLink);
330
+ return function () {
331
+ eventBus.removeListener("".concat((0, _utils.normalizeName)(name), ":external-router"), _handleExternalLink);
332
+ };
333
+ }, [handleExternalLink, name]);
378
334
  if (appInstance) {
379
335
  appInstance.update(customProps);
380
336
  }
381
-
382
337
  var dataAttrs = {
383
338
  'data-id': name,
384
339
  // 加载器版本