@alicloud/alfa-react 1.4.31 → 1.4.33-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/dist/index.js +3 -3
- package/es/createApplication.js +27 -13
- package/es/version.js +1 -1
- package/lib/createApplication.js +27 -13
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/types/createApplication.d.ts +5 -1
- package/types/version.d.ts +1 -1
package/es/createApplication.js
CHANGED
|
@@ -34,6 +34,17 @@ var addBasename = function addBasename(path, basename) {
|
|
|
34
34
|
return resolvePath(basename, path);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
var addLeftSlash = function addLeftSlash(path) {
|
|
38
|
+
return path.charAt(0) === '/' ? path : "/".concat(path);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* 从 path 移除 basename 部分
|
|
42
|
+
* @param path
|
|
43
|
+
* @param basename
|
|
44
|
+
* @returns string
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
|
|
37
48
|
var stripBasename = function stripBasename(path, basename) {
|
|
38
49
|
if (!basename) return path;
|
|
39
50
|
|
|
@@ -92,7 +103,8 @@ export default function createApplication(loader) {
|
|
|
92
103
|
var $basename = useRef(basename);
|
|
93
104
|
var tagName = normalizeName(props.name);
|
|
94
105
|
$syncHistory.current = syncHistory;
|
|
95
|
-
$basename.current = basename;
|
|
106
|
+
$basename.current = basename;
|
|
107
|
+
if (customProps.path) customProps.path = addLeftSlash(customProps.path); // 受控模式锁定一些参数
|
|
96
108
|
|
|
97
109
|
if ($syncHistory.current) {
|
|
98
110
|
// 禁止子应用和 consoleBase 通信
|
|
@@ -166,24 +178,25 @@ export default function createApplication(loader) {
|
|
|
166
178
|
var popstateEvent = new Event('popstate');
|
|
167
179
|
popstateEvent.state = 'mock';
|
|
168
180
|
(_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);
|
|
169
|
-
};
|
|
170
|
-
|
|
181
|
+
};
|
|
171
182
|
|
|
172
183
|
var updateAppHistory = function updateAppHistory() {
|
|
173
184
|
if (App) {
|
|
174
|
-
//
|
|
175
|
-
|
|
185
|
+
var nextPath = peelPath(App.context.location); // 路由同步只应该在相同 basename 下生效
|
|
186
|
+
|
|
187
|
+
if (!peelPath(window.location).startsWith($basename.current || '')) return; // 如果主子应用路径不同,主动通知子应用 popstate 事件
|
|
176
188
|
|
|
177
189
|
if (nextPath !== stripBasename(peelPath(window.location), $basename.current)) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
190
|
+
if (originalReplaceState) {
|
|
191
|
+
originalReplaceState(null, '', stripBasename(peelPath(window.location), $basename.current));
|
|
192
|
+
dispatchFramePopstate();
|
|
193
|
+
}
|
|
182
194
|
}
|
|
183
195
|
}
|
|
184
|
-
};
|
|
196
|
+
}; // 受控模式下,返回不会触发子应用内的路由更新,需要主动通知
|
|
197
|
+
|
|
185
198
|
|
|
186
|
-
window.addEventListener('popstate', updateAppHistory);
|
|
199
|
+
if ($syncHistory.current) window.addEventListener('popstate', updateAppHistory);
|
|
187
200
|
|
|
188
201
|
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
189
202
|
var _app$context$updateBo, _app$context, _app$context$baseFram;
|
|
@@ -309,7 +322,7 @@ export default function createApplication(loader) {
|
|
|
309
322
|
var _App$context$baseFram3, _App$context$baseFram4;
|
|
310
323
|
|
|
311
324
|
isUnmounted = true;
|
|
312
|
-
window.removeEventListener('popstate', updateAppHistory);
|
|
325
|
+
if ($syncHistory.current) window.removeEventListener('popstate', updateAppHistory);
|
|
313
326
|
if (!App) return;
|
|
314
327
|
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;
|
|
315
328
|
|
|
@@ -319,7 +332,8 @@ export default function createApplication(loader) {
|
|
|
319
332
|
if (originalGo !== frameHistory.go) frameHistory.go = originalGo;
|
|
320
333
|
}
|
|
321
334
|
|
|
322
|
-
App.unmount();
|
|
335
|
+
App.unmount(); // TODO: 在沙箱中嵌套时,unmount 必须销毁沙箱实例,避免在其它微应用中复用该沙箱,导致环境变量污染
|
|
336
|
+
// if (isOsContext()) App.destroy();
|
|
323
337
|
};
|
|
324
338
|
}, [memoOptions]);
|
|
325
339
|
|
package/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var version = '1.4.
|
|
1
|
+
export var version = '1.4.33-alpha.0';
|
package/lib/createApplication.js
CHANGED
|
@@ -56,6 +56,17 @@ var addBasename = function addBasename(path, basename) {
|
|
|
56
56
|
return resolvePath(basename, path);
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
var addLeftSlash = function addLeftSlash(path) {
|
|
60
|
+
return path.charAt(0) === '/' ? path : "/".concat(path);
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* 从 path 移除 basename 部分
|
|
64
|
+
* @param path
|
|
65
|
+
* @param basename
|
|
66
|
+
* @returns string
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
|
|
59
70
|
var stripBasename = function stripBasename(path, basename) {
|
|
60
71
|
if (!basename) return path;
|
|
61
72
|
|
|
@@ -114,7 +125,8 @@ function createApplication(loader) {
|
|
|
114
125
|
var $basename = (0, _react.useRef)(basename);
|
|
115
126
|
var tagName = (0, _utils.normalizeName)(props.name);
|
|
116
127
|
$syncHistory.current = syncHistory;
|
|
117
|
-
$basename.current = basename;
|
|
128
|
+
$basename.current = basename;
|
|
129
|
+
if (customProps.path) customProps.path = addLeftSlash(customProps.path); // 受控模式锁定一些参数
|
|
118
130
|
|
|
119
131
|
if ($syncHistory.current) {
|
|
120
132
|
// 禁止子应用和 consoleBase 通信
|
|
@@ -188,24 +200,25 @@ function createApplication(loader) {
|
|
|
188
200
|
var popstateEvent = new Event('popstate');
|
|
189
201
|
popstateEvent.state = 'mock';
|
|
190
202
|
(_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);
|
|
191
|
-
};
|
|
192
|
-
|
|
203
|
+
};
|
|
193
204
|
|
|
194
205
|
var updateAppHistory = function updateAppHistory() {
|
|
195
206
|
if (App) {
|
|
196
|
-
//
|
|
197
|
-
|
|
207
|
+
var nextPath = peelPath(App.context.location); // 路由同步只应该在相同 basename 下生效
|
|
208
|
+
|
|
209
|
+
if (!peelPath(window.location).startsWith($basename.current || '')) return; // 如果主子应用路径不同,主动通知子应用 popstate 事件
|
|
198
210
|
|
|
199
211
|
if (nextPath !== stripBasename(peelPath(window.location), $basename.current)) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
212
|
+
if (originalReplaceState) {
|
|
213
|
+
originalReplaceState(null, '', stripBasename(peelPath(window.location), $basename.current));
|
|
214
|
+
dispatchFramePopstate();
|
|
215
|
+
}
|
|
204
216
|
}
|
|
205
217
|
}
|
|
206
|
-
};
|
|
218
|
+
}; // 受控模式下,返回不会触发子应用内的路由更新,需要主动通知
|
|
219
|
+
|
|
207
220
|
|
|
208
|
-
window.addEventListener('popstate', updateAppHistory);
|
|
221
|
+
if ($syncHistory.current) window.addEventListener('popstate', updateAppHistory);
|
|
209
222
|
(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
210
223
|
var _app$context$updateBo, _app$context, _app$context$baseFram;
|
|
211
224
|
|
|
@@ -329,7 +342,7 @@ function createApplication(loader) {
|
|
|
329
342
|
var _App$context$baseFram3, _App$context$baseFram4;
|
|
330
343
|
|
|
331
344
|
isUnmounted = true;
|
|
332
|
-
window.removeEventListener('popstate', updateAppHistory);
|
|
345
|
+
if ($syncHistory.current) window.removeEventListener('popstate', updateAppHistory);
|
|
333
346
|
if (!App) return;
|
|
334
347
|
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;
|
|
335
348
|
|
|
@@ -339,7 +352,8 @@ function createApplication(loader) {
|
|
|
339
352
|
if (originalGo !== frameHistory.go) frameHistory.go = originalGo;
|
|
340
353
|
}
|
|
341
354
|
|
|
342
|
-
App.unmount();
|
|
355
|
+
App.unmount(); // TODO: 在沙箱中嵌套时,unmount 必须销毁沙箱实例,避免在其它微应用中复用该沙箱,导致环境变量污染
|
|
356
|
+
// if (isOsContext()) App.destroy();
|
|
343
357
|
};
|
|
344
358
|
}, [memoOptions]);
|
|
345
359
|
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
import { BaseLoader } from '@alicloud/alfa-core';
|
|
3
3
|
import { AlfaFactoryOption } from './types';
|
|
4
4
|
interface IProps<C = any> extends AlfaFactoryOption {
|
|
5
|
-
customProps: C
|
|
5
|
+
customProps: C & {
|
|
6
|
+
consoleBase?: any;
|
|
7
|
+
path?: string;
|
|
8
|
+
__injectHistory?: any;
|
|
9
|
+
};
|
|
6
10
|
syncHistory?: boolean;
|
|
7
11
|
basename?: string;
|
|
8
12
|
}
|
package/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.4.
|
|
1
|
+
export declare const version = "1.4.33-alpha.0";
|