@alicloud/alfa-react 1.6.1 → 1.6.2-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/es/createApplication.js +27 -25
- package/es/utils/index.js +15 -0
- package/es/version.js +1 -1
- package/lib/createApplication.js +26 -24
- package/lib/utils/index.js +18 -2
- package/lib/version.js +1 -1
- package/package.json +4 -4
- package/types/utils/index.d.ts +8 -0
- package/types/version.d.ts +1 -1
package/es/createApplication.js
CHANGED
|
@@ -10,7 +10,7 @@ import { createEventBus } from '@alicloud/alfa-core';
|
|
|
10
10
|
import { ConsoleRegion, ConsoleResourceGroup, ConsoleContext } from '@alicloud/xconsole-context';
|
|
11
11
|
import { forApp } from '@alicloud/console-base-messenger';
|
|
12
12
|
import Loading from './components/Loading';
|
|
13
|
-
import { normalizeName } from './utils';
|
|
13
|
+
import { normalizeName, setNativeProperty } from './utils';
|
|
14
14
|
import { countRegister } from './utils/counter';
|
|
15
15
|
import { version as loaderVersion } from './version';
|
|
16
16
|
var eventBus = createEventBus();
|
|
@@ -330,33 +330,31 @@ export default function createApplication(loader) {
|
|
|
330
330
|
originalGo = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.go;
|
|
331
331
|
// update context history according to path
|
|
332
332
|
if (path) originalReplaceState(getHistoryState(), '', path.replace(/\/+/g, '/'));
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if ($syncHistory.current) {
|
|
336
|
-
var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
|
|
337
|
-
if ("".concat(nextPath) !== peelPath(window.location)) {
|
|
338
|
-
window.history.pushState(data, unused, nextPath);
|
|
339
|
-
onSyncHistory && onSyncHistory('push', nextPath, data);
|
|
340
|
-
}
|
|
341
|
-
originalReplaceState(data, unused, _url);
|
|
342
|
-
} else {
|
|
343
|
-
originalPushState(data, unused, _url);
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
frameWindow.history.replaceState = function (data, unused, _url) {
|
|
333
|
+
frameWindow.history.pushState = function (data, unused, _url) {
|
|
334
|
+
if ($syncHistory.current) {
|
|
347
335
|
var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
|
|
348
|
-
if (
|
|
349
|
-
window.history.
|
|
350
|
-
onSyncHistory && onSyncHistory('
|
|
336
|
+
if ("".concat(nextPath) !== peelPath(window.location)) {
|
|
337
|
+
window.history.pushState(data, unused, nextPath);
|
|
338
|
+
onSyncHistory && onSyncHistory('push', nextPath, data);
|
|
351
339
|
}
|
|
352
340
|
originalReplaceState(data, unused, _url);
|
|
353
|
-
}
|
|
341
|
+
} else {
|
|
342
|
+
originalPushState(data, unused, _url);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
frameWindow.history.replaceState = function (data, unused, _url) {
|
|
346
|
+
var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
|
|
347
|
+
if ($syncHistory.current) {
|
|
348
|
+
window.history.replaceState(data, unused, nextPath);
|
|
349
|
+
onSyncHistory && onSyncHistory('replace', nextPath, data);
|
|
350
|
+
}
|
|
351
|
+
originalReplaceState(data, unused, _url);
|
|
352
|
+
};
|
|
354
353
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
354
|
+
// 劫持微应用的返回
|
|
355
|
+
setNativeProperty(frameWindow.history, 'go', function (n) {
|
|
356
|
+
window.history.go(n);
|
|
357
|
+
});
|
|
360
358
|
}
|
|
361
359
|
_context.next = 25;
|
|
362
360
|
return app.mount(fakeBody, {
|
|
@@ -390,10 +388,14 @@ export default function createApplication(loader) {
|
|
|
390
388
|
if ($syncHistory.current) window.removeEventListener('popstate', updateAppHistory);
|
|
391
389
|
if (!App) return;
|
|
392
390
|
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;
|
|
391
|
+
|
|
392
|
+
// reset method of frame history
|
|
393
393
|
if (frameHistory) {
|
|
394
394
|
if (originalPushState !== frameHistory.pushState) frameHistory.pushState = originalPushState;
|
|
395
395
|
if (originalReplaceState !== frameHistory.replaceState) frameHistory.replaceState = originalReplaceState;
|
|
396
|
-
if (originalGo !== frameHistory.go)
|
|
396
|
+
if (originalGo !== frameHistory.go) {
|
|
397
|
+
setNativeProperty(frameHistory, 'go', originalGo);
|
|
398
|
+
}
|
|
397
399
|
}
|
|
398
400
|
App.unmount();
|
|
399
401
|
|
package/es/utils/index.js
CHANGED
|
@@ -17,4 +17,19 @@ export var isOsContext = function isOsContext() {
|
|
|
17
17
|
// 降级
|
|
18
18
|
return !!window.__IS_CONSOLE_OS_CONTEXT__;
|
|
19
19
|
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* set native object property
|
|
24
|
+
* @param obj
|
|
25
|
+
* @param propertyName
|
|
26
|
+
* @param value
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
export var setNativeProperty = function setNativeProperty(obj, propertyName, value) {
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(obj, propertyName);
|
|
31
|
+
|
|
32
|
+
// in strict mode, Cannot set property go of [xx] which has only a getter
|
|
33
|
+
if (desc && typeof desc.set === 'undefined') return;
|
|
34
|
+
obj[propertyName] = value;
|
|
20
35
|
};
|
package/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var version = '1.6.
|
|
1
|
+
export var version = '1.6.2-alpha.0';
|
package/lib/createApplication.js
CHANGED
|
@@ -340,33 +340,31 @@ function createApplication(loader) {
|
|
|
340
340
|
originalGo = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.go;
|
|
341
341
|
// update context history according to path
|
|
342
342
|
if (path) originalReplaceState(getHistoryState(), '', path.replace(/\/+/g, '/'));
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if ($syncHistory.current) {
|
|
346
|
-
var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
|
|
347
|
-
if ("".concat(nextPath) !== peelPath(window.location)) {
|
|
348
|
-
window.history.pushState(data, unused, nextPath);
|
|
349
|
-
onSyncHistory && onSyncHistory('push', nextPath, data);
|
|
350
|
-
}
|
|
351
|
-
originalReplaceState(data, unused, _url);
|
|
352
|
-
} else {
|
|
353
|
-
originalPushState(data, unused, _url);
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
frameWindow.history.replaceState = function (data, unused, _url) {
|
|
343
|
+
frameWindow.history.pushState = function (data, unused, _url) {
|
|
344
|
+
if ($syncHistory.current) {
|
|
357
345
|
var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
|
|
358
|
-
if (
|
|
359
|
-
window.history.
|
|
360
|
-
onSyncHistory && onSyncHistory('
|
|
346
|
+
if ("".concat(nextPath) !== peelPath(window.location)) {
|
|
347
|
+
window.history.pushState(data, unused, nextPath);
|
|
348
|
+
onSyncHistory && onSyncHistory('push', nextPath, data);
|
|
361
349
|
}
|
|
362
350
|
originalReplaceState(data, unused, _url);
|
|
363
|
-
}
|
|
351
|
+
} else {
|
|
352
|
+
originalPushState(data, unused, _url);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
frameWindow.history.replaceState = function (data, unused, _url) {
|
|
356
|
+
var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
|
|
357
|
+
if ($syncHistory.current) {
|
|
358
|
+
window.history.replaceState(data, unused, nextPath);
|
|
359
|
+
onSyncHistory && onSyncHistory('replace', nextPath, data);
|
|
360
|
+
}
|
|
361
|
+
originalReplaceState(data, unused, _url);
|
|
362
|
+
};
|
|
364
363
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
364
|
+
// 劫持微应用的返回
|
|
365
|
+
(0, _utils.setNativeProperty)(frameWindow.history, 'go', function (n) {
|
|
366
|
+
window.history.go(n);
|
|
367
|
+
});
|
|
370
368
|
}
|
|
371
369
|
_context.next = 25;
|
|
372
370
|
return app.mount(fakeBody, {
|
|
@@ -400,10 +398,14 @@ function createApplication(loader) {
|
|
|
400
398
|
if ($syncHistory.current) window.removeEventListener('popstate', updateAppHistory);
|
|
401
399
|
if (!App) return;
|
|
402
400
|
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;
|
|
401
|
+
|
|
402
|
+
// reset method of frame history
|
|
403
403
|
if (frameHistory) {
|
|
404
404
|
if (originalPushState !== frameHistory.pushState) frameHistory.pushState = originalPushState;
|
|
405
405
|
if (originalReplaceState !== frameHistory.replaceState) frameHistory.replaceState = originalReplaceState;
|
|
406
|
-
if (originalGo !== frameHistory.go)
|
|
406
|
+
if (originalGo !== frameHistory.go) {
|
|
407
|
+
(0, _utils.setNativeProperty)(frameHistory, 'go', originalGo);
|
|
408
|
+
}
|
|
407
409
|
}
|
|
408
410
|
App.unmount();
|
|
409
411
|
|
package/lib/utils/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.normalizeName = exports.isOsContext = void 0;
|
|
6
|
+
exports.setNativeProperty = exports.normalizeName = exports.isOsContext = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* kernel 会为沙箱 context 注入 __IS_CONSOLE_OS_CONTEXT__
|
|
9
9
|
*/
|
|
@@ -25,4 +25,20 @@ var isOsContext = function isOsContext() {
|
|
|
25
25
|
return !!window.__IS_CONSOLE_OS_CONTEXT__;
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* set native object property
|
|
31
|
+
* @param obj
|
|
32
|
+
* @param propertyName
|
|
33
|
+
* @param value
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
exports.isOsContext = isOsContext;
|
|
37
|
+
var setNativeProperty = function setNativeProperty(obj, propertyName, value) {
|
|
38
|
+
var desc = Object.getOwnPropertyDescriptor(obj, propertyName);
|
|
39
|
+
|
|
40
|
+
// in strict mode, Cannot set property go of [xx] which has only a getter
|
|
41
|
+
if (desc && typeof desc.set === 'undefined') return;
|
|
42
|
+
obj[propertyName] = value;
|
|
43
|
+
};
|
|
44
|
+
exports.setNativeProperty = setNativeProperty;
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alicloud/alfa-react",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2-alpha.0",
|
|
4
4
|
"description": "Alfa Framework (React Version)",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
"classnames": "^2.2.6",
|
|
39
39
|
"crypto-js": "^4.1.1",
|
|
40
40
|
"prop-types": "^15.8.1",
|
|
41
|
-
"@alicloud/
|
|
42
|
-
"@alicloud/
|
|
41
|
+
"@alicloud/console-os-loader": "^1.4.42",
|
|
42
|
+
"@alicloud/alfa-core": "^1.4.37"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": ">=16.0.0"
|
|
46
46
|
},
|
|
47
47
|
"gitHead": "ff9294b1d5e08b14691c8aa2bef098da2857f3df",
|
|
48
48
|
"scripts": {
|
|
49
|
-
"prepublish": "npm run version && npm run
|
|
49
|
+
"prepublish": "npm run version && npm run babel && npm run babel:esm && npm run types",
|
|
50
50
|
"pub": "pnpm publish",
|
|
51
51
|
"build": "breezr build --engine webpack",
|
|
52
52
|
"babel": "breezr build --engine babel",
|
package/types/utils/index.d.ts
CHANGED
|
@@ -3,3 +3,11 @@ export declare const normalizeName: (name: string) => string;
|
|
|
3
3
|
* 判断是否在沙箱环境中运行
|
|
4
4
|
*/
|
|
5
5
|
export declare const isOsContext: () => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* set native object property
|
|
8
|
+
* @param obj
|
|
9
|
+
* @param propertyName
|
|
10
|
+
* @param value
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare const setNativeProperty: (obj: any, propertyName: string, value: any) => void;
|
package/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.6.
|
|
1
|
+
export declare const version = "1.6.2-alpha.0";
|