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

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