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