@micro-zoe/micro-app 1.0.0-beta.0 → 1.0.0-beta.1
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/lib/index.d.ts +1 -0
- package/lib/index.esm.js +79 -42
- package/lib/index.esm.js.map +1 -1
- package/lib/index.min.js +1 -1
- package/lib/index.min.js.map +1 -1
- package/lib/index.umd.js +1 -1
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/typings/global.d.ts +1 -0
package/lib/index.d.ts
CHANGED
|
@@ -147,6 +147,7 @@ declare module '@micro-zoe/micro-app/libs/utils' {
|
|
|
147
147
|
export function isDivElement(target: unknown): target is HTMLDivElement;
|
|
148
148
|
export function isImageElement(target: unknown): target is HTMLImageElement;
|
|
149
149
|
export function isBaseElement(target: unknown): target is HTMLBaseElement;
|
|
150
|
+
export function isMicroAppBody(target: unknown): target is HTMLElement;
|
|
150
151
|
export function isProxyDocument(target: unknown): target is Document;
|
|
151
152
|
/**
|
|
152
153
|
* format error log
|
package/lib/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const version = '1.0.0-beta.
|
|
1
|
+
const version = '1.0.0-beta.1';
|
|
2
2
|
// do not use isUndefined
|
|
3
3
|
const isBrowser = typeof window !== 'undefined';
|
|
4
4
|
// do not use isUndefined
|
|
@@ -114,6 +114,10 @@ function isBaseElement(target) {
|
|
|
114
114
|
var _a, _b;
|
|
115
115
|
return ((_b = (_a = target) === null || _a === void 0 ? void 0 : _a.tagName) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === 'BASE';
|
|
116
116
|
}
|
|
117
|
+
function isMicroAppBody(target) {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
return ((_b = (_a = target) === null || _a === void 0 ? void 0 : _a.tagName) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === 'MICRO-APP-BODY';
|
|
120
|
+
}
|
|
117
121
|
// is ProxyDocument
|
|
118
122
|
function isProxyDocument(target) {
|
|
119
123
|
return toString.call(target) === '[object ProxyDocument]';
|
|
@@ -1518,22 +1522,30 @@ function updateElementInfo(node, appName) {
|
|
|
1518
1522
|
var _a, _b;
|
|
1519
1523
|
const proxyWindow = (_b = (_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.sandBox) === null || _b === void 0 ? void 0 : _b.proxyWindow;
|
|
1520
1524
|
if (proxyWindow && isNode(node) && !node.__MICRO_APP_NAME__) {
|
|
1521
|
-
|
|
1525
|
+
/**
|
|
1526
|
+
* TODO:
|
|
1527
|
+
* 1. 测试baseURI和ownerDocument在with沙箱中是否正确
|
|
1528
|
+
* 经过验证with沙箱不能重写ownerDocument,否则react点击事件会触发两次
|
|
1529
|
+
* 2. with沙箱所有node设置__MICRO_APP_NAME__都使用updateElementInfo
|
|
1530
|
+
* 3. 性能: defineProperty的性能肯定不如直接设置
|
|
1531
|
+
*/
|
|
1522
1532
|
rawDefineProperties(node, {
|
|
1523
1533
|
baseURI: {
|
|
1524
1534
|
configurable: true,
|
|
1525
1535
|
get: () => proxyWindow.location.href,
|
|
1526
1536
|
},
|
|
1527
|
-
ownerDocument: {
|
|
1528
|
-
configurable: true,
|
|
1529
|
-
get: () => proxyWindow.document,
|
|
1530
|
-
},
|
|
1531
1537
|
__MICRO_APP_NAME__: {
|
|
1532
1538
|
configurable: true,
|
|
1533
1539
|
writable: true,
|
|
1534
1540
|
value: appName,
|
|
1535
1541
|
},
|
|
1536
1542
|
});
|
|
1543
|
+
if (isIframeSandbox(appName)) {
|
|
1544
|
+
rawDefineProperty(node, 'ownerDocument', {
|
|
1545
|
+
configurable: true,
|
|
1546
|
+
get: () => proxyWindow.document,
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1537
1549
|
}
|
|
1538
1550
|
return node;
|
|
1539
1551
|
}
|
|
@@ -1620,25 +1632,39 @@ function invokePrototypeMethod(app, rawMethod, parent, targetChild, passiveChild
|
|
|
1620
1632
|
*/
|
|
1621
1633
|
if (hijackParent) {
|
|
1622
1634
|
/**
|
|
1623
|
-
*
|
|
1635
|
+
* If parentNode is <micro-app-body>, return rawDocument.body
|
|
1636
|
+
* Scenes:
|
|
1637
|
+
* 1. element-ui@2/lib/utils/vue-popper.js
|
|
1638
|
+
* if (this.popperElm.parentNode === document.body) ...
|
|
1624
1639
|
* WARNING:
|
|
1625
|
-
*
|
|
1640
|
+
* 1. When operate child from parentNode async, may have been unmount
|
|
1641
|
+
* e.g. target.parentNode.remove(target)
|
|
1642
|
+
* ISSUE:
|
|
1643
|
+
* 1. https://github.com/micro-zoe/micro-app/issues/739
|
|
1644
|
+
* Solution: Return the true value when node not in document
|
|
1626
1645
|
*/
|
|
1627
1646
|
if (!isIframeSandbox(app.name) &&
|
|
1628
|
-
hijackParent
|
|
1647
|
+
isMicroAppBody(hijackParent) &&
|
|
1629
1648
|
rawMethod !== globalEnv.rawRemoveChild) {
|
|
1630
1649
|
const descriptor = Object.getOwnPropertyDescriptor(targetChild, 'parentNode');
|
|
1631
|
-
if (!descriptor || descriptor.configurable) {
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1650
|
+
if ((!descriptor || descriptor.configurable) && !targetChild.__MICRO_APP_HAS_DPN__) {
|
|
1651
|
+
rawDefineProperties(targetChild, {
|
|
1652
|
+
parentNode: {
|
|
1653
|
+
configurable: true,
|
|
1654
|
+
get() {
|
|
1655
|
+
var _a, _b;
|
|
1656
|
+
const result = globalEnv.rawParentNodeDesc.get.call(this);
|
|
1657
|
+
if (isMicroAppBody(result) && app.container) {
|
|
1658
|
+
// TODO: remove getRootElementParentNode
|
|
1659
|
+
return ((_b = (_a = microApp.options).getRootElementParentNode) === null || _b === void 0 ? void 0 : _b.call(_a, this, app.name)) || document.body;
|
|
1660
|
+
}
|
|
1661
|
+
return result;
|
|
1662
|
+
},
|
|
1641
1663
|
},
|
|
1664
|
+
__MICRO_APP_HAS_DPN__: {
|
|
1665
|
+
configurable: true,
|
|
1666
|
+
get: () => true,
|
|
1667
|
+
}
|
|
1642
1668
|
});
|
|
1643
1669
|
}
|
|
1644
1670
|
}
|
|
@@ -1857,8 +1883,8 @@ function patchElementAndDocument() {
|
|
|
1857
1883
|
// * BUG:
|
|
1858
1884
|
// * 1. vue2 umdMode, throw error when render again (<div id='app'></div> will be deleted when render again )
|
|
1859
1885
|
// */
|
|
1860
|
-
// if (result
|
|
1861
|
-
// return
|
|
1886
|
+
// if (isMicroAppBody(result) && appInstanceMap.get(this.__MICRO_APP_NAME__)?.container) {
|
|
1887
|
+
// return document.body
|
|
1862
1888
|
// }
|
|
1863
1889
|
// return result
|
|
1864
1890
|
// },
|
|
@@ -5121,6 +5147,7 @@ class WithSandBox {
|
|
|
5121
5147
|
microAppWindow.__MICRO_APP_NAME__ = appName;
|
|
5122
5148
|
microAppWindow.__MICRO_APP_URL__ = url;
|
|
5123
5149
|
microAppWindow.__MICRO_APP_PUBLIC_PATH__ = getEffectivePath(url);
|
|
5150
|
+
microAppWindow.__MICRO_APP_BASE_ROUTE__ = '';
|
|
5124
5151
|
microAppWindow.__MICRO_APP_WINDOW__ = microAppWindow;
|
|
5125
5152
|
microAppWindow.__MICRO_APP_PRE_RENDER__ = false;
|
|
5126
5153
|
microAppWindow.__MICRO_APP_UMD_MODE__ = false;
|
|
@@ -5954,7 +5981,7 @@ function patchIframeNode(appName, microAppWindow, iframeSandbox) {
|
|
|
5954
5981
|
configurable: true,
|
|
5955
5982
|
enumerable: true,
|
|
5956
5983
|
get() {
|
|
5957
|
-
var _a;
|
|
5984
|
+
var _a, _b, _c;
|
|
5958
5985
|
// set html.parentNode to microDocument
|
|
5959
5986
|
throttleDeferForParentNode(microDocument);
|
|
5960
5987
|
const result = rawParentNodeLDesc.get.call(this);
|
|
@@ -5967,8 +5994,8 @@ function patchIframeNode(appName, microAppWindow, iframeSandbox) {
|
|
|
5967
5994
|
* Will it cause other problems ?
|
|
5968
5995
|
* e.g. target.parentNode.remove(target)
|
|
5969
5996
|
*/
|
|
5970
|
-
if ((result
|
|
5971
|
-
return rawDocument.body;
|
|
5997
|
+
if (isMicroAppBody(result) && ((_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.container)) {
|
|
5998
|
+
return ((_c = (_b = microApp.options).getRootElementParentNode) === null || _c === void 0 ? void 0 : _c.call(_b, this, appName)) || rawDocument.body;
|
|
5972
5999
|
}
|
|
5973
6000
|
return result;
|
|
5974
6001
|
},
|
|
@@ -6049,14 +6076,14 @@ class IframeSandbox {
|
|
|
6049
6076
|
const childFullPath = childStaticLocation.pathname + childStaticLocation.search + childStaticLocation.hash;
|
|
6050
6077
|
this.deleteIframeElement = this.createIframeElement(appName, browserHost);
|
|
6051
6078
|
this.microAppWindow = this.iframe.contentWindow;
|
|
6052
|
-
// TODO: 优化代码
|
|
6053
|
-
// exec before initStaticGlobalKeys
|
|
6054
|
-
this.createProxyLocation(appName, url, this.microAppWindow, childStaticLocation, browserHost, childHost);
|
|
6055
|
-
this.createProxyWindow(appName, this.microAppWindow);
|
|
6056
|
-
this.initStaticGlobalKeys(appName, url);
|
|
6057
|
-
// get escapeProperties from plugins
|
|
6058
|
-
this.getSpecialProperties(appName);
|
|
6059
6079
|
this.patchIframe(this.microAppWindow, (resolve) => {
|
|
6080
|
+
// TODO: 优化代码
|
|
6081
|
+
// exec before initStaticGlobalKeys
|
|
6082
|
+
this.createProxyLocation(appName, url, this.microAppWindow, childStaticLocation, browserHost, childHost);
|
|
6083
|
+
this.createProxyWindow(this.microAppWindow);
|
|
6084
|
+
this.initStaticGlobalKeys(appName, url);
|
|
6085
|
+
// get escapeProperties from plugins
|
|
6086
|
+
this.getSpecialProperties(appName);
|
|
6060
6087
|
this.createIframeTemplate(this.microAppWindow);
|
|
6061
6088
|
patchIframeRoute(appName, this.microAppWindow, childFullPath);
|
|
6062
6089
|
this.windowEffect = patchIframeWindow(appName, this.microAppWindow);
|
|
@@ -6229,6 +6256,7 @@ class IframeSandbox {
|
|
|
6229
6256
|
this.microAppWindow.__MICRO_APP_NAME__ = appName;
|
|
6230
6257
|
this.microAppWindow.__MICRO_APP_URL__ = url;
|
|
6231
6258
|
this.microAppWindow.__MICRO_APP_PUBLIC_PATH__ = getEffectivePath(url);
|
|
6259
|
+
this.microAppWindow.__MICRO_APP_BASE_ROUTE__ = '';
|
|
6232
6260
|
this.microAppWindow.__MICRO_APP_WINDOW__ = this.microAppWindow;
|
|
6233
6261
|
this.microAppWindow.__MICRO_APP_PRE_RENDER__ = false;
|
|
6234
6262
|
this.microAppWindow.__MICRO_APP_UMD_MODE__ = false;
|
|
@@ -6245,18 +6273,27 @@ class IframeSandbox {
|
|
|
6245
6273
|
}
|
|
6246
6274
|
// TODO: RESTRUCTURE
|
|
6247
6275
|
patchIframe(microAppWindow, cb) {
|
|
6276
|
+
const oldMicroDocument = microAppWindow.document;
|
|
6248
6277
|
this.sandboxReady = new Promise((resolve) => {
|
|
6249
6278
|
(function iframeLocationReady() {
|
|
6250
6279
|
setTimeout(() => {
|
|
6251
|
-
|
|
6252
|
-
|
|
6280
|
+
try {
|
|
6281
|
+
if (microAppWindow.document === oldMicroDocument) {
|
|
6282
|
+
iframeLocationReady();
|
|
6283
|
+
}
|
|
6284
|
+
else {
|
|
6285
|
+
/**
|
|
6286
|
+
* NOTE:
|
|
6287
|
+
* 1. microAppWindow will not be recreated
|
|
6288
|
+
* 2. the properties of microAppWindow may be recreated, such as document
|
|
6289
|
+
* 3. the variables added to microAppWindow may be cleared
|
|
6290
|
+
*/
|
|
6291
|
+
microAppWindow.stop();
|
|
6292
|
+
cb(resolve);
|
|
6293
|
+
}
|
|
6253
6294
|
}
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
* microAppWindow.document rebuild
|
|
6257
|
-
*/
|
|
6258
|
-
microAppWindow.stop();
|
|
6259
|
-
cb(resolve);
|
|
6295
|
+
catch (e) {
|
|
6296
|
+
iframeLocationReady();
|
|
6260
6297
|
}
|
|
6261
6298
|
}, 0);
|
|
6262
6299
|
})();
|
|
@@ -6285,7 +6322,7 @@ class IframeSandbox {
|
|
|
6285
6322
|
createProxyLocation(appName, url, microAppWindow, childStaticLocation, browserHost, childHost) {
|
|
6286
6323
|
this.proxyLocation = createMicroLocation(appName, url, microAppWindow, childStaticLocation, browserHost, childHost);
|
|
6287
6324
|
}
|
|
6288
|
-
createProxyWindow(
|
|
6325
|
+
createProxyWindow(microAppWindow) {
|
|
6289
6326
|
const rawWindow = globalEnv.rawWindow;
|
|
6290
6327
|
this.proxyWindow = new Proxy(microAppWindow, {
|
|
6291
6328
|
get: (target, key) => {
|
|
@@ -6903,8 +6940,8 @@ class CreateApp {
|
|
|
6903
6940
|
return {};
|
|
6904
6941
|
}
|
|
6905
6942
|
getMicroAppGlobalHook(eventName) {
|
|
6906
|
-
var _a;
|
|
6907
|
-
const listener = ((_a = this.sandBox) === null || _a === void 0 ? void 0 : _a.proxyWindow)[eventName];
|
|
6943
|
+
var _a, _b;
|
|
6944
|
+
const listener = (_b = (_a = this.sandBox) === null || _a === void 0 ? void 0 : _a.proxyWindow) === null || _b === void 0 ? void 0 : _b[eventName];
|
|
6908
6945
|
return isFunction(listener) ? listener : null;
|
|
6909
6946
|
}
|
|
6910
6947
|
querySelector(selectors) {
|