@micro-zoe/micro-app 1.0.0-beta.4 → 1.0.0-beta.5
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 +2 -2
- package/lib/index.esm.js +51 -20
- 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 +4 -0
package/lib/index.d.ts
CHANGED
|
@@ -109,7 +109,7 @@ declare module '@micro-zoe/micro-app/prefetch' {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
declare module '@micro-zoe/micro-app/libs/utils' {
|
|
112
|
-
import type { Func, LocationQueryObject, MicroLocation, AttrsType, fiberTasks } from '@micro-app/types';
|
|
112
|
+
import type { Func, LocationQueryObject, MicroLocation, AttrsType, fiberTasks, MicroAppElementTagNameMap } from '@micro-app/types';
|
|
113
113
|
export const version = "__MICRO_APP_VERSION__";
|
|
114
114
|
export const isBrowser: boolean;
|
|
115
115
|
export const globalThis: any;
|
|
@@ -236,7 +236,7 @@ declare module '@micro-zoe/micro-app/libs/utils' {
|
|
|
236
236
|
/**
|
|
237
237
|
* Create pure elements
|
|
238
238
|
*/
|
|
239
|
-
export function pureCreateElement<K extends keyof
|
|
239
|
+
export function pureCreateElement<K extends keyof MicroAppElementTagNameMap>(tagName: K, options?: ElementCreationOptions): MicroAppElementTagNameMap[K];
|
|
240
240
|
/**
|
|
241
241
|
* clone origin elements to target
|
|
242
242
|
* @param origin Cloned element
|
package/lib/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const version = '1.0.0-beta.
|
|
1
|
+
const version = '1.0.0-beta.5';
|
|
2
2
|
// do not use isUndefined
|
|
3
3
|
const isBrowser = typeof window !== 'undefined';
|
|
4
4
|
// do not use isUndefined
|
|
@@ -1668,21 +1668,33 @@ function runDynamicInlineScript(address, app, scriptInfo) {
|
|
|
1668
1668
|
*/
|
|
1669
1669
|
function runCode2InlineScript(address, code, module, scriptElement, attrs, callback) {
|
|
1670
1670
|
if (module) {
|
|
1671
|
-
|
|
1671
|
+
globalEnv.rawSetAttribute.call(scriptElement, 'type', 'module');
|
|
1672
1672
|
if (isInlineScript(address)) {
|
|
1673
|
-
|
|
1674
|
-
|
|
1673
|
+
/**
|
|
1674
|
+
* inline module script cannot convert to blob mode
|
|
1675
|
+
* Issue: https://github.com/micro-zoe/micro-app/issues/805
|
|
1676
|
+
*/
|
|
1677
|
+
scriptElement.textContent = code;
|
|
1675
1678
|
}
|
|
1676
1679
|
else {
|
|
1677
1680
|
scriptElement.src = address;
|
|
1678
1681
|
}
|
|
1679
|
-
globalEnv.rawSetAttribute.call(scriptElement, 'type', 'module');
|
|
1680
1682
|
if (callback) {
|
|
1681
|
-
|
|
1683
|
+
const onloadHandler = () => {
|
|
1684
|
+
callback.moduleCount && callback.moduleCount--;
|
|
1685
|
+
callback(callback.moduleCount === 0);
|
|
1686
|
+
};
|
|
1682
1687
|
/**
|
|
1683
|
-
*
|
|
1688
|
+
* NOTE:
|
|
1689
|
+
* 1. module script will execute onload method only after it insert to document/iframe
|
|
1690
|
+
* 2. we can't know when the inline module script onload, and we use defer to simulate, this maybe cause some problems
|
|
1684
1691
|
*/
|
|
1685
|
-
|
|
1692
|
+
if (isInlineScript(address)) {
|
|
1693
|
+
defer(onloadHandler);
|
|
1694
|
+
}
|
|
1695
|
+
else {
|
|
1696
|
+
scriptElement.onload = onloadHandler;
|
|
1697
|
+
}
|
|
1686
1698
|
}
|
|
1687
1699
|
}
|
|
1688
1700
|
else {
|
|
@@ -2354,6 +2366,10 @@ function patchDocument() {
|
|
|
2354
2366
|
// const element = globalEnv.rawCreateTextNode.call(getBindTarget(this), data)
|
|
2355
2367
|
// return markElement(element)
|
|
2356
2368
|
// }
|
|
2369
|
+
rawRootDocument.prototype.createComment = function createComment(data) {
|
|
2370
|
+
const element = globalEnv.rawCreateComment.call(getBindTarget(this), data);
|
|
2371
|
+
return markElement(element);
|
|
2372
|
+
};
|
|
2357
2373
|
// query element👇
|
|
2358
2374
|
function querySelector(selectors) {
|
|
2359
2375
|
var _a, _b;
|
|
@@ -2478,8 +2494,6 @@ function rejectMicroAppStyle() {
|
|
|
2478
2494
|
}
|
|
2479
2495
|
|
|
2480
2496
|
const globalEnv = {
|
|
2481
|
-
// mark current application as base application
|
|
2482
|
-
__MICRO_APP_BASE_APPLICATION__: true,
|
|
2483
2497
|
// active sandbox count
|
|
2484
2498
|
activeSandbox: 0,
|
|
2485
2499
|
};
|
|
@@ -2514,6 +2528,7 @@ function initGlobalEnv() {
|
|
|
2514
2528
|
const rawCreateElementNS = rawRootDocument.prototype.createElementNS;
|
|
2515
2529
|
const rawCreateDocumentFragment = rawRootDocument.prototype.createDocumentFragment;
|
|
2516
2530
|
const rawCreateTextNode = rawRootDocument.prototype.createTextNode;
|
|
2531
|
+
const rawCreateComment = rawRootDocument.prototype.createComment;
|
|
2517
2532
|
const rawQuerySelector = rawRootDocument.prototype.querySelector;
|
|
2518
2533
|
const rawQuerySelectorAll = rawRootDocument.prototype.querySelectorAll;
|
|
2519
2534
|
const rawGetElementById = rawRootDocument.prototype.getElementById;
|
|
@@ -2541,6 +2556,8 @@ function initGlobalEnv() {
|
|
|
2541
2556
|
const rawReplaceState = rawWindow.history.replaceState;
|
|
2542
2557
|
const rawAddEventListener = rawRootEventTarget.prototype.addEventListener;
|
|
2543
2558
|
const rawRemoveEventListener = rawRootEventTarget.prototype.removeEventListener;
|
|
2559
|
+
// mark current application as base application
|
|
2560
|
+
window.__MICRO_APP_BASE_APPLICATION__ = true;
|
|
2544
2561
|
assign(globalEnv, {
|
|
2545
2562
|
supportModuleScript: isSupportModuleScript(),
|
|
2546
2563
|
// common global vars
|
|
@@ -2567,6 +2584,7 @@ function initGlobalEnv() {
|
|
|
2567
2584
|
rawCreateElementNS,
|
|
2568
2585
|
rawCreateDocumentFragment,
|
|
2569
2586
|
rawCreateTextNode,
|
|
2587
|
+
rawCreateComment,
|
|
2570
2588
|
rawQuerySelector,
|
|
2571
2589
|
rawQuerySelectorAll,
|
|
2572
2590
|
rawGetElementById,
|
|
@@ -5741,6 +5759,7 @@ function patchDocumentPrototype(appName, microAppWindow) {
|
|
|
5741
5759
|
const microDocument = microAppWindow.document;
|
|
5742
5760
|
const rawMicroCreateElement = microRootDocument.prototype.createElement;
|
|
5743
5761
|
const rawMicroCreateTextNode = microRootDocument.prototype.createTextNode;
|
|
5762
|
+
const rawMicroCreateComment = microRootDocument.prototype.createComment;
|
|
5744
5763
|
const rawMicroQuerySelector = microRootDocument.prototype.querySelector;
|
|
5745
5764
|
const rawMicroQuerySelectorAll = microRootDocument.prototype.querySelectorAll;
|
|
5746
5765
|
const rawMicroGetElementById = microRootDocument.prototype.getElementById;
|
|
@@ -5755,6 +5774,10 @@ function patchDocumentPrototype(appName, microAppWindow) {
|
|
|
5755
5774
|
const element = rawMicroCreateTextNode.call(this, data);
|
|
5756
5775
|
return updateElementInfo(element, appName);
|
|
5757
5776
|
};
|
|
5777
|
+
microRootDocument.prototype.createComment = function createComment(data) {
|
|
5778
|
+
const element = rawMicroCreateComment.call(this, data);
|
|
5779
|
+
return updateElementInfo(element, appName);
|
|
5780
|
+
};
|
|
5758
5781
|
function getDefaultRawTarget(target) {
|
|
5759
5782
|
return microDocument !== target ? target : rawDocument;
|
|
5760
5783
|
}
|
|
@@ -6539,6 +6562,7 @@ class IframeSandbox {
|
|
|
6539
6562
|
}
|
|
6540
6563
|
createProxyWindow(microAppWindow) {
|
|
6541
6564
|
const rawWindow = globalEnv.rawWindow;
|
|
6565
|
+
const customProperties = [];
|
|
6542
6566
|
return new Proxy(microAppWindow, {
|
|
6543
6567
|
get: (target, key) => {
|
|
6544
6568
|
if (key === 'location') {
|
|
@@ -6547,6 +6571,9 @@ class IframeSandbox {
|
|
|
6547
6571
|
if (globalPropertyList.includes(key.toString())) {
|
|
6548
6572
|
return this.proxyWindow;
|
|
6549
6573
|
}
|
|
6574
|
+
if (customProperties.includes(key)) {
|
|
6575
|
+
return Reflect.get(target, key);
|
|
6576
|
+
}
|
|
6550
6577
|
return bindFunctionToRawTarget(Reflect.get(target, key), target);
|
|
6551
6578
|
},
|
|
6552
6579
|
set: (target, key, value) => {
|
|
@@ -6558,6 +6585,9 @@ class IframeSandbox {
|
|
|
6558
6585
|
if (key === 'location') {
|
|
6559
6586
|
return Reflect.set(rawWindow, key, value);
|
|
6560
6587
|
}
|
|
6588
|
+
if (!Reflect.has(target, key)) {
|
|
6589
|
+
customProperties.push(key);
|
|
6590
|
+
}
|
|
6561
6591
|
Reflect.set(target, key, value);
|
|
6562
6592
|
if (this.escapeProperties.includes(key)) {
|
|
6563
6593
|
!Reflect.has(rawWindow, key) && this.escapeKeys.add(key);
|
|
@@ -6735,12 +6765,6 @@ class CreateApp {
|
|
|
6735
6765
|
this.source.html = html;
|
|
6736
6766
|
if (!this.isPrefetch && !this.isUnmounted()) {
|
|
6737
6767
|
getRootContainer(this.container).mount(this);
|
|
6738
|
-
// Abandonment plan
|
|
6739
|
-
// if (this.isHidden()) {
|
|
6740
|
-
// getRootContainer(this.container!).unmount()
|
|
6741
|
-
// } else if (!this.isUnmounted()) {
|
|
6742
|
-
// getRootContainer(this.container!).mount(this)
|
|
6743
|
-
// }
|
|
6744
6768
|
}
|
|
6745
6769
|
else if (this.isPrerender) {
|
|
6746
6770
|
/**
|
|
@@ -6808,8 +6832,7 @@ class CreateApp {
|
|
|
6808
6832
|
// mount before prerender exec mount (loading source), set isPrerender to false
|
|
6809
6833
|
this.isPrerender = false;
|
|
6810
6834
|
// reset app state to LOADING
|
|
6811
|
-
this.setAppState(appStates.LOADING);
|
|
6812
|
-
return;
|
|
6835
|
+
return this.setAppState(appStates.LOADING);
|
|
6813
6836
|
}
|
|
6814
6837
|
this.createSandbox();
|
|
6815
6838
|
const nextAction = () => {
|
|
@@ -6856,7 +6879,6 @@ class CreateApp {
|
|
|
6856
6879
|
this.fiber = fiber;
|
|
6857
6880
|
// use in sandbox/effect
|
|
6858
6881
|
this.useMemoryRouter = useMemoryRouter;
|
|
6859
|
-
// this.hiddenRouter = hiddenRouter ?? this.hiddenRouter
|
|
6860
6882
|
const dispatchBeforeMount = () => dispatchLifecyclesEvent(this.container, this.name, lifeCycles.BEFOREMOUNT);
|
|
6861
6883
|
if (this.isPrerender) {
|
|
6862
6884
|
((_d = this.preRenderEvents) !== null && _d !== void 0 ? _d : (this.preRenderEvents = [])).push(dispatchBeforeMount);
|
|
@@ -7093,7 +7115,16 @@ class CreateApp {
|
|
|
7093
7115
|
// called after lifeCyclesEvent
|
|
7094
7116
|
(_a = this.sandBox) === null || _a === void 0 ? void 0 : _a.removeRouteInfoForKeepAliveApp();
|
|
7095
7117
|
}
|
|
7096
|
-
|
|
7118
|
+
/**
|
|
7119
|
+
* Hidden app before the resources are loaded, then unmount the app
|
|
7120
|
+
*/
|
|
7121
|
+
if (this.loadSourceLevel !== 2) {
|
|
7122
|
+
getRootContainer(this.container).unmount();
|
|
7123
|
+
}
|
|
7124
|
+
else {
|
|
7125
|
+
this.container = cloneContainer(pureCreateElement('div'), this.container, false);
|
|
7126
|
+
(_b = this.sandBox) === null || _b === void 0 ? void 0 : _b.recordAndReleaseEffect({ keepAlive: true });
|
|
7127
|
+
}
|
|
7097
7128
|
callback === null || callback === void 0 ? void 0 : callback();
|
|
7098
7129
|
}
|
|
7099
7130
|
// show app when connectedCallback called with keep-alive
|