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