@xingtukeji/micro 1.1.12 → 1.1.14
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 +186 -161
- package/dist/types/api.d.ts +3 -2
- package/dist/types/child.d.ts +1 -1
- package/dist/types/components/XTMicroView.vue.d.ts +1 -1
- package/dist/types/parent.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document!="undefined"){var e=document.createElement("style");e.appendChild(document.createTextNode('.xt-micro{width:100%;height:100%;overflow:hidden;background-color:transparent}.xt-micro:before{content:"加载中";position:absolute;inset:0;display:flex;justify-content:center;align-items:center;z-index:-1}.micro-iframe{width:100%;height:100%;border:none;margin:0;padding:0}.micro-iframe:after{content:"加载中";position:absolute;inset:0;display:flex;justify-content:center;align-items:center;background:#fff}')),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
2
|
+
var A = Object.defineProperty, T = Object.defineProperties;
|
|
3
|
+
var x = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var E = Object.getOwnPropertySymbols;
|
|
5
|
+
var $ = Object.prototype.hasOwnProperty, X = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var R = (e, t, n) => t in e ? A(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, d = (e, t) => {
|
|
7
7
|
for (var n in t || (t = {}))
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
for (var n of
|
|
11
|
-
|
|
8
|
+
$.call(t, n) && R(e, n, t[n]);
|
|
9
|
+
if (E)
|
|
10
|
+
for (var n of E(t))
|
|
11
|
+
X.call(t, n) && R(e, n, t[n]);
|
|
12
12
|
return e;
|
|
13
|
-
},
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var a = (
|
|
13
|
+
}, _ = (e, t) => T(e, x(t));
|
|
14
|
+
var p = (e, t, n) => (R(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
15
|
+
var h = (e, t, n) => new Promise((r, o) => {
|
|
16
|
+
var a = (l) => {
|
|
17
17
|
try {
|
|
18
|
-
|
|
19
|
-
} catch (
|
|
20
|
-
o(
|
|
18
|
+
i(n.next(l));
|
|
19
|
+
} catch (w) {
|
|
20
|
+
o(w);
|
|
21
21
|
}
|
|
22
|
-
}, c = (
|
|
22
|
+
}, c = (l) => {
|
|
23
23
|
try {
|
|
24
|
-
|
|
25
|
-
} catch (
|
|
26
|
-
o(
|
|
24
|
+
i(n.throw(l));
|
|
25
|
+
} catch (w) {
|
|
26
|
+
o(w);
|
|
27
27
|
}
|
|
28
|
-
},
|
|
29
|
-
|
|
28
|
+
}, i = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(a, c);
|
|
29
|
+
i((n = n.apply(e, t)).next());
|
|
30
30
|
});
|
|
31
|
-
import { ref as
|
|
32
|
-
const
|
|
31
|
+
import { ref as C, defineComponent as k, watch as H, onMounted as j, onUnmounted as F, openBlock as N, createElementBlock as V, mergeProps as B } from "vue";
|
|
32
|
+
const s = {
|
|
33
33
|
KEY: "$xtm",
|
|
34
34
|
// 父应用注入子应用实例的key
|
|
35
35
|
IS_MICRO: "__XT_MICRO",
|
|
@@ -48,28 +48,28 @@ const i = {
|
|
|
48
48
|
// 微应用在 url 参数中的前缀
|
|
49
49
|
MICRO_VERSION: "__XT_MICRO_VERSION"
|
|
50
50
|
// 微应用版本
|
|
51
|
-
}, u = "1.1.
|
|
52
|
-
function
|
|
51
|
+
}, u = "1.1.13";
|
|
52
|
+
function f(e, t = window.location.href) {
|
|
53
53
|
e = e.replace(/[\[\]]/g, "\\$&");
|
|
54
54
|
var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"), r = n.exec(t);
|
|
55
55
|
return r ? r[2] ? decodeURIComponent(r[2].replace(/\+/g, " ")).trim() : "" : null;
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function S(e, t, n) {
|
|
58
58
|
try {
|
|
59
59
|
return e && (n && e.startsWith("#") ? e : new URL(e, t).href);
|
|
60
60
|
} catch (r) {
|
|
61
61
|
return e;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function D(e) {
|
|
65
65
|
const t = window.document.createElement("a");
|
|
66
66
|
return t.href = e, t.href = t.href, t;
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function K(e) {
|
|
69
69
|
const t = e.search || "";
|
|
70
70
|
return [...new URLSearchParams(t).entries()].reduce((n, r) => (n[r[0]] = r[1], n), {});
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function W(e, t) {
|
|
73
73
|
let n = null;
|
|
74
74
|
return function(...r) {
|
|
75
75
|
const o = this;
|
|
@@ -78,11 +78,11 @@ function K(e, t) {
|
|
|
78
78
|
}, t);
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
function
|
|
81
|
+
function U(e, t, n) {
|
|
82
82
|
const [r, o] = e.split("#"), a = new URL(r), c = a.searchParams;
|
|
83
|
-
return t =
|
|
83
|
+
return t = s.URL_PARAM_PREFIX + t, c.has(t) ? c.set(t, n) : c.append(t, n), o && (a.hash = o), a.search = c.toString(), a.toString();
|
|
84
84
|
}
|
|
85
|
-
const
|
|
85
|
+
const P = (e) => h(void 0, null, function* () {
|
|
86
86
|
return new Promise((t) => {
|
|
87
87
|
window.addEventListener("message", (n) => {
|
|
88
88
|
console.debug("child ipcSyncAppInfo receive message", n.data), n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !== u && console.warn(
|
|
@@ -96,17 +96,17 @@ const S = (e) => g(void 0, null, function* () {
|
|
|
96
96
|
"*"
|
|
97
97
|
);
|
|
98
98
|
});
|
|
99
|
-
}),
|
|
99
|
+
}), ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
100
100
|
__proto__: null,
|
|
101
|
-
addOrReplaceUrlParam:
|
|
102
|
-
anchorElementGenerator:
|
|
103
|
-
debounce:
|
|
104
|
-
getAbsolutePath:
|
|
105
|
-
getAnchorElementQueryMap:
|
|
106
|
-
getQueryParameter:
|
|
107
|
-
ipcSyncAppInfo:
|
|
108
|
-
}, Symbol.toStringTag, { value: "Module" })), O =
|
|
109
|
-
Object.defineProperty(window,
|
|
101
|
+
addOrReplaceUrlParam: U,
|
|
102
|
+
anchorElementGenerator: D,
|
|
103
|
+
debounce: W,
|
|
104
|
+
getAbsolutePath: S,
|
|
105
|
+
getAnchorElementQueryMap: K,
|
|
106
|
+
getQueryParameter: f,
|
|
107
|
+
ipcSyncAppInfo: P
|
|
108
|
+
}, Symbol.toStringTag, { value: "Module" })), O = C(!1);
|
|
109
|
+
Object.defineProperty(window, s.IS_MICRO, {
|
|
110
110
|
get: function() {
|
|
111
111
|
return O.value;
|
|
112
112
|
},
|
|
@@ -114,38 +114,37 @@ Object.defineProperty(window, i.IS_MICRO, {
|
|
|
114
114
|
O.value = e;
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
|
-
const I = (e) => `${
|
|
118
|
-
function
|
|
119
|
-
return
|
|
117
|
+
const I = (e) => `${s.DOM_ID_PREFIX}${e}`, L = (e, t = !1) => {
|
|
118
|
+
function n(i) {
|
|
119
|
+
return i !== null && typeof i == "object" && !Array.isArray(i);
|
|
120
120
|
}
|
|
121
|
-
const
|
|
121
|
+
const r = typeof e.params == "function" ? e.params() : n(e.params) ? e.params : {}, o = typeof e.token == "function" ? e.token() : n(e.token) ? e.token : "", a = new URL(
|
|
122
122
|
e.url.indexOf("http") > -1 ? e.url : window.location.origin + e.url
|
|
123
|
-
),
|
|
124
|
-
if (
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}),
|
|
123
|
+
), c = f(s.URL_PARAM_PREFIX + e.name);
|
|
124
|
+
if (!t && c) {
|
|
125
|
+
const i = S(c, e.url, !0);
|
|
126
|
+
if (i) {
|
|
127
|
+
const l = new URL(i);
|
|
128
|
+
l.searchParams.forEach((b, v) => {
|
|
129
|
+
a.searchParams.set(v, b);
|
|
130
|
+
}), a.hash = l.hash;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
if (
|
|
134
|
-
for (let
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return c.searchParams.delete(e.name), window.history.replaceState({}, "", c.href), o.href;
|
|
133
|
+
if (a.searchParams.set(s.IS_MICRO, !0 + ""), a.searchParams.set(s.MICRO_NAME, e.name), o && a.searchParams.set(s.MICRO_TOKEN, o), r)
|
|
134
|
+
for (let i of Object.keys(r))
|
|
135
|
+
a.searchParams.set(i, r[i]);
|
|
136
|
+
return g(e.name), a.href;
|
|
138
137
|
}, Y = () => {
|
|
139
138
|
const e = document.createElement("div");
|
|
140
139
|
return e.innerHTML = "应用加载中...", e.style.textAlign = "center", e.style.lineHeight = "100px", e.style.fontSize = "20px", e.style.color = "#999", e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.right = "0", e.style.bottom = "0", e.style.zIndex = "999", e.style.background = "transparent", e.style["mix-blend-mode"] = "difference", e;
|
|
141
|
-
},
|
|
140
|
+
}, q = (e) => {
|
|
142
141
|
e.style.opacity = "0", setTimeout(() => {
|
|
143
142
|
e.remove();
|
|
144
143
|
}, 500);
|
|
145
|
-
},
|
|
144
|
+
}, z = (e) => {
|
|
146
145
|
const t = document.createElement("iframe");
|
|
147
146
|
t.id = I(e.app.name);
|
|
148
|
-
const n =
|
|
147
|
+
const n = L(e.app);
|
|
149
148
|
t.src = n, t.style.width = "100%", t.style.height = "100%", t.style.border = "none", t.style.margin = "0", t.style.padding = "0", t.style.backgroundColor = "transparent", t.style["color-scheme"] = "unset", t.style.visibility = "hidden", t.addEventListener("load", (o) => (t.style.visibility = "visible", e.onLoad.call(e, o))), t.addEventListener(
|
|
150
149
|
"error",
|
|
151
150
|
(o) => e.onError.call(e, o)
|
|
@@ -154,19 +153,22 @@ const I = (e) => `${i.DOM_ID_PREFIX}${e}`, D = (e) => {
|
|
|
154
153
|
(o) => e.onUnload.call(e, o)
|
|
155
154
|
);
|
|
156
155
|
const r = new MutationObserver((o) => {
|
|
157
|
-
o.forEach((a) => {
|
|
156
|
+
console.log("监听 body 中子节点的变化2", e.panel), o.forEach((a) => {
|
|
158
157
|
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")), r.disconnect());
|
|
159
158
|
});
|
|
160
159
|
});
|
|
161
|
-
return r.observe(e.panel, {
|
|
160
|
+
return r.observe(e.panel.parentNode, {
|
|
161
|
+
childList: !0,
|
|
162
|
+
subtree: !1
|
|
163
|
+
}), t;
|
|
162
164
|
};
|
|
163
|
-
class
|
|
165
|
+
class G {
|
|
164
166
|
constructor(t) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
p(this, "app");
|
|
168
|
+
p(this, "dom");
|
|
169
|
+
p(this, "panel");
|
|
170
|
+
p(this, "loading");
|
|
171
|
+
p(this, "loadingTimer");
|
|
170
172
|
return this.app = t, this.dom = void 0, this.panel = void 0, t.preload && this.preload(), this;
|
|
171
173
|
}
|
|
172
174
|
mount(t, n = !1) {
|
|
@@ -174,7 +176,7 @@ class z {
|
|
|
174
176
|
if (t ? (typeof t == "string" ? r = document.querySelector(t) : r = t, r.innerHTML = "") : r = document.body, r) {
|
|
175
177
|
this.panel = r;
|
|
176
178
|
let o = document.getElementById(I(this.app.name));
|
|
177
|
-
o || (o =
|
|
179
|
+
o || (o = z(this), this.dom = o), n ? o.style.display = "none" : o.style.removeProperty("display");
|
|
178
180
|
const a = Y();
|
|
179
181
|
this.loadingTimer = setTimeout(() => {
|
|
180
182
|
this.loading = a, r.appendChild(a);
|
|
@@ -184,6 +186,7 @@ class z {
|
|
|
184
186
|
}
|
|
185
187
|
unmount() {
|
|
186
188
|
var n;
|
|
189
|
+
console.debug("micro unmount app", this.app.name);
|
|
187
190
|
const t = document.getElementById(I(this.app.name));
|
|
188
191
|
if (t)
|
|
189
192
|
this.app.preload ? (t.style.display = "none", document.body.appendChild(t)) : (n = this.panel) == null || n.removeChild(t);
|
|
@@ -204,24 +207,26 @@ class z {
|
|
|
204
207
|
preload() {
|
|
205
208
|
this.mount(void 0, !0);
|
|
206
209
|
}
|
|
207
|
-
reload() {
|
|
208
|
-
|
|
209
|
-
this.
|
|
210
|
+
reload(t = !1) {
|
|
211
|
+
let n = this.dom.src;
|
|
212
|
+
t && (n = L(this.app, !0), console.log("go home", n)), console.log("reload app", this.app, n);
|
|
213
|
+
const r = new URL(n);
|
|
214
|
+
r.searchParams.set("__t", Date.now().toString()), this.dom.src = r.toString();
|
|
210
215
|
}
|
|
211
216
|
changeOptions(t) {
|
|
212
|
-
this.app =
|
|
217
|
+
console.log("changeOptions", this.app, t), this.app = d(d({}, this.app), t);
|
|
213
218
|
}
|
|
214
219
|
onLoad(t) {
|
|
215
|
-
console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading &&
|
|
220
|
+
console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && q(this.loading), Q(this), this.app.onLoad && this.app.onLoad(t, this);
|
|
216
221
|
}
|
|
217
222
|
onUnload(t) {
|
|
218
|
-
console.debug("app onUnload", this.app.name), this.app.onUnload && this.app.onUnload(t, this);
|
|
223
|
+
console.debug("app onUnload", this.app.name), g(this.app.name), this.app.onUnload && this.app.onUnload(t, this);
|
|
219
224
|
}
|
|
220
225
|
onError(t) {
|
|
221
226
|
console.error("app onError", this.app.name), this.app.onError && this.app.onError(t, this);
|
|
222
227
|
}
|
|
223
228
|
}
|
|
224
|
-
const
|
|
229
|
+
const Q = (e) => {
|
|
225
230
|
var t, n;
|
|
226
231
|
(n = (t = e.dom) == null ? void 0 : t.contentWindow) == null || n.postMessage(
|
|
227
232
|
{
|
|
@@ -236,13 +241,14 @@ const G = (e) => {
|
|
|
236
241
|
},
|
|
237
242
|
"*"
|
|
238
243
|
);
|
|
239
|
-
},
|
|
240
|
-
window[
|
|
244
|
+
}, J = () => {
|
|
245
|
+
window[s.MICRO_TYPE] = "parent", window.addEventListener("message", (e) => {
|
|
241
246
|
if (e.data.cmd === "$xt/micro/sync") {
|
|
247
|
+
console.log("父页面接受子应用同步路由信息", e.data);
|
|
242
248
|
const t = [
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
249
|
+
s.IS_MICRO,
|
|
250
|
+
s.MICRO_NAME,
|
|
251
|
+
s.MICRO_TOKEN
|
|
246
252
|
], n = new URL(
|
|
247
253
|
window.decodeURIComponent(e.data.data.url),
|
|
248
254
|
e.origin
|
|
@@ -251,9 +257,9 @@ const G = (e) => {
|
|
|
251
257
|
n.searchParams.delete(a);
|
|
252
258
|
const r = new URL(window.location.href);
|
|
253
259
|
r.searchParams.forEach((a, c) => {
|
|
254
|
-
c.startsWith(
|
|
260
|
+
c.startsWith(s.URL_PARAM_PREFIX) && r.searchParams.delete(c);
|
|
255
261
|
});
|
|
256
|
-
const o =
|
|
262
|
+
const o = U(
|
|
257
263
|
r.href,
|
|
258
264
|
e.data.data.name,
|
|
259
265
|
n.href
|
|
@@ -261,7 +267,7 @@ const G = (e) => {
|
|
|
261
267
|
window.history.replaceState(null, "", o);
|
|
262
268
|
} else if (e.data.cmd === "$xt/micro/info") {
|
|
263
269
|
console.debug("parent 「$xt/micro/info」 receive message", e.data);
|
|
264
|
-
const t =
|
|
270
|
+
const t = y(e.data.data);
|
|
265
271
|
e.source.postMessage(
|
|
266
272
|
{
|
|
267
273
|
cmd: "$xt/micro/info",
|
|
@@ -289,129 +295,148 @@ const G = (e) => {
|
|
|
289
295
|
);
|
|
290
296
|
}
|
|
291
297
|
});
|
|
292
|
-
},
|
|
293
|
-
window[
|
|
294
|
-
const n =
|
|
295
|
-
if (console.debug("child microInit", n, r), n && (window[
|
|
296
|
-
window[
|
|
298
|
+
}, ce = (...t) => h(void 0, [...t], function* (e = {}) {
|
|
299
|
+
window[s.MICRO_TYPE] = "child";
|
|
300
|
+
const n = f(s.IS_MICRO), r = f(s.MICRO_NAME);
|
|
301
|
+
if (console.debug("child microInit", n, r), n && (window[s.IS_MICRO] = n === "true"), r && P(r).then((o) => {
|
|
302
|
+
window[s.MICRO_APP] = d({
|
|
297
303
|
microVersion: u
|
|
298
304
|
}, o);
|
|
299
|
-
}), window[
|
|
305
|
+
}), window[s.IS_MICRO]) {
|
|
300
306
|
let o = function(c) {
|
|
301
|
-
var
|
|
302
|
-
if (!
|
|
303
|
-
var
|
|
304
|
-
document.head.appendChild(
|
|
307
|
+
var i = document.styleSheets[0];
|
|
308
|
+
if (!i) {
|
|
309
|
+
var l = document.createElement("style");
|
|
310
|
+
document.head.appendChild(l), i = l.sheet;
|
|
305
311
|
}
|
|
306
|
-
|
|
312
|
+
i.insertRule(c, i.cssRules.length);
|
|
307
313
|
};
|
|
308
|
-
window[
|
|
314
|
+
window[s.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((c) => {
|
|
309
315
|
o(`${c} { display: none !important; }`);
|
|
310
316
|
}) : o(
|
|
311
317
|
`${e.hideHeaderCssSelector} { display: none !important; }`
|
|
312
|
-
)), window.addEventListener("message", (c) => {
|
|
313
|
-
c.data.cmd === `$xt/micro/${r}` &&
|
|
314
|
-
})
|
|
315
|
-
const a =
|
|
318
|
+
)), yield Z(r, window), window.addEventListener("message", (c) => h(void 0, null, function* () {
|
|
319
|
+
c.data.cmd === `$xt/micro/${r}` && M(r);
|
|
320
|
+
}));
|
|
321
|
+
const a = f(s.MICRO_TOKEN);
|
|
316
322
|
e.authHandler && a && (yield e.authHandler(a));
|
|
317
323
|
} else
|
|
318
324
|
console.warn("当前环境非微应用环境");
|
|
319
325
|
});
|
|
320
|
-
function
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
const
|
|
326
|
+
function Z(e, t) {
|
|
327
|
+
const n = t.history, r = n.pushState, o = n.replaceState;
|
|
328
|
+
n.pushState = function(a, c, i) {
|
|
329
|
+
const l = _(d(d({}, n.state || {}), a), {
|
|
324
330
|
// 添加新数据
|
|
325
331
|
_patchedByParent: !0
|
|
326
332
|
// 可选:标记这是被父窗口修改的状态
|
|
327
333
|
});
|
|
328
|
-
|
|
329
|
-
},
|
|
330
|
-
const
|
|
334
|
+
r.call(n, l, c, i), M(e);
|
|
335
|
+
}, n.replaceState = function(a, c, i) {
|
|
336
|
+
const l = _(d(d({}, n.state || {}), a), {
|
|
331
337
|
// 添加新数据
|
|
332
338
|
_patchedByParent: !0
|
|
333
339
|
// 可选:标记这是被父窗口修改的状态
|
|
334
340
|
});
|
|
335
|
-
|
|
341
|
+
o.call(n, l, c, i), M(e);
|
|
336
342
|
};
|
|
337
343
|
}
|
|
338
|
-
function
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
344
|
+
function M(e) {
|
|
345
|
+
return h(this, null, function* () {
|
|
346
|
+
console.log("syncUrlToWindow", e, window[s.MICRO_APP]), window[s.MICRO_APP] || (yield P(e).then((a) => {
|
|
347
|
+
window[s.MICRO_APP] = d({
|
|
348
|
+
microVersion: u
|
|
349
|
+
}, a);
|
|
350
|
+
}));
|
|
351
|
+
const { name: t, sync: n, mainLocation: r } = window[s.MICRO_APP], o = window.location.pathname + window.location.search + window.location.hash;
|
|
352
|
+
window.parent.postMessage(
|
|
353
|
+
{
|
|
354
|
+
cmd: "$xt/micro/sync",
|
|
355
|
+
data: {
|
|
356
|
+
name: t,
|
|
357
|
+
url: window.encodeURIComponent(o)
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
r.origin
|
|
361
|
+
);
|
|
362
|
+
});
|
|
352
363
|
}
|
|
353
|
-
let
|
|
354
|
-
const
|
|
364
|
+
let m = {};
|
|
365
|
+
const ee = {
|
|
355
366
|
url: "",
|
|
356
367
|
name: "",
|
|
357
368
|
sync: !0
|
|
358
|
-
},
|
|
369
|
+
}, le = (e) => {
|
|
359
370
|
if (!e.url || e.url === "" || e.url === "undefined") {
|
|
360
371
|
console.error("app url is required", e);
|
|
361
372
|
return;
|
|
362
373
|
}
|
|
363
|
-
const t = Object.assign({},
|
|
364
|
-
return
|
|
365
|
-
instance: new
|
|
366
|
-
}),
|
|
367
|
-
},
|
|
368
|
-
let o =
|
|
369
|
-
o ? (t && (o.instance.changeOptions(t), o =
|
|
370
|
-
}),
|
|
371
|
-
let t =
|
|
374
|
+
const t = Object.assign({}, ee, e), n = m[e.name];
|
|
375
|
+
return n ? m[e.name] = d(d({}, n), t) : m[e.name] = _(d({}, t), {
|
|
376
|
+
instance: new G(e)
|
|
377
|
+
}), m[e.name];
|
|
378
|
+
}, y = (e) => m[e], te = (e, t) => m[e.name] = d(d({}, e), t), ne = (e, t) => new Promise((n, r) => {
|
|
379
|
+
let o = y(e);
|
|
380
|
+
o ? (t && (o.instance.changeOptions(t), o = te(o, t)), o.preload ? o.instance.preloadRender(o.el) : o.instance.mount(o.el), n(o)) : r("app not found, please setup app first");
|
|
381
|
+
}), oe = (e) => {
|
|
382
|
+
let t = y(e);
|
|
372
383
|
t && t.instance.unmount();
|
|
373
|
-
}, de = (e) => {
|
|
374
|
-
let
|
|
375
|
-
|
|
376
|
-
},
|
|
384
|
+
}, de = (e, t = !1) => {
|
|
385
|
+
let n = y(e);
|
|
386
|
+
n && n.instance.reload(t);
|
|
387
|
+
}, g = (e) => {
|
|
388
|
+
console.log("clearParentUrl", e, s.URL_PARAM_PREFIX + e);
|
|
389
|
+
const t = window.location.href.split("#");
|
|
390
|
+
console.log("url", t);
|
|
391
|
+
const n = new URL(t[0]);
|
|
392
|
+
console.log("mainURL", n), n.searchParams.delete(s.URL_PARAM_PREFIX + e), window.history.replaceState(
|
|
393
|
+
{},
|
|
394
|
+
"",
|
|
395
|
+
t.length > 1 ? n.href + "#" + t[1] : n.href
|
|
396
|
+
);
|
|
397
|
+
}, re = /* @__PURE__ */ k({
|
|
377
398
|
__name: "XTMicroView",
|
|
378
399
|
props: {
|
|
379
400
|
appId: String
|
|
380
401
|
},
|
|
381
402
|
setup(e) {
|
|
382
|
-
const t = e, n =
|
|
383
|
-
t.appId &&
|
|
384
|
-
el: n.value
|
|
403
|
+
const t = e, n = C(), r = () => {
|
|
404
|
+
t.appId && ne(t.appId, {
|
|
405
|
+
el: n.value,
|
|
406
|
+
onUnload(o, a) {
|
|
407
|
+
console.log("on unload", a.app.name), g(a.app.name);
|
|
408
|
+
}
|
|
385
409
|
}).then((o) => {
|
|
386
410
|
console.debug("app mounted", t.appId);
|
|
387
411
|
});
|
|
388
412
|
};
|
|
389
|
-
return
|
|
390
|
-
o !== a && a &&
|
|
391
|
-
}),
|
|
413
|
+
return H(() => t.appId, (o, a) => {
|
|
414
|
+
o !== a && a && oe(a), r();
|
|
415
|
+
}), j(() => {
|
|
392
416
|
r();
|
|
393
|
-
}),
|
|
394
|
-
console.debug("app unmount", t.appId);
|
|
395
|
-
}), (o, a) => (N(),
|
|
417
|
+
}), F(() => {
|
|
418
|
+
console.debug("「micro」", "app unmount", t.appId), g(t.appId);
|
|
419
|
+
}), (o, a) => (N(), V("div", B({
|
|
396
420
|
ref_key: "refPanel",
|
|
397
421
|
ref: n
|
|
398
422
|
}, o.$attrs, { class: "xt-micro" }), null, 16));
|
|
399
423
|
}
|
|
400
424
|
});
|
|
401
|
-
window[
|
|
402
|
-
const
|
|
425
|
+
window[s.MICRO_VERSION] = u;
|
|
426
|
+
const pe = {
|
|
403
427
|
install: (e, t = {}) => {
|
|
404
|
-
e.component("xt-micro-view",
|
|
428
|
+
e.component("xt-micro-view", re), J();
|
|
405
429
|
}
|
|
406
430
|
};
|
|
407
431
|
export {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
432
|
+
re as XTMicroView,
|
|
433
|
+
g as clearParentUrl,
|
|
434
|
+
pe as default,
|
|
435
|
+
y as getApp,
|
|
436
|
+
ce as microInit,
|
|
412
437
|
de as reloadApp,
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
438
|
+
le as setupApp,
|
|
439
|
+
ne as startApp,
|
|
440
|
+
oe as stopApp,
|
|
441
|
+
ie as utils
|
|
417
442
|
};
|
package/dist/types/api.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { microInit } from './child';
|
|
|
4
4
|
* 安装微应用
|
|
5
5
|
* @param app
|
|
6
6
|
*/
|
|
7
|
-
export declare const setupApp: (
|
|
7
|
+
export declare const setupApp: (AppOption: AppOption) => App | undefined;
|
|
8
8
|
export declare const getApp: (name: string) => App;
|
|
9
9
|
/**
|
|
10
10
|
* 启动微应用
|
|
@@ -18,5 +18,6 @@ export declare const startApp: (name: string, options?: Partial<AppOption>) => P
|
|
|
18
18
|
* @param {string} name - 应用程序的名称
|
|
19
19
|
*/
|
|
20
20
|
export declare const stopApp: (name: string) => void;
|
|
21
|
-
export declare const reloadApp: (name: string) => void;
|
|
21
|
+
export declare const reloadApp: (name: string, isGoHome?: boolean) => void;
|
|
22
|
+
export declare const clearParentUrl: (appName: string) => void;
|
|
22
23
|
export { microInit };
|
package/dist/types/child.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const microInit: (options?: MicroInitOptions) => Promise<void>;
|
|
|
9
9
|
/**
|
|
10
10
|
* 同步子应用路由到主应用路由
|
|
11
11
|
*/
|
|
12
|
-
export declare function syncUrlToWindow(): void
|
|
12
|
+
export declare function syncUrlToWindow(microName: string): Promise<void>;
|
|
13
13
|
/**
|
|
14
14
|
* 同步主应用路由到子应用
|
|
15
15
|
*/
|
|
@@ -4,5 +4,5 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
4
4
|
appId: StringConstructor;
|
|
5
5
|
}>> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {
|
|
6
6
|
refPanel: HTMLDivElement;
|
|
7
|
-
},
|
|
7
|
+
}, HTMLDivElement>;
|
|
8
8
|
export default _default;
|
package/dist/types/parent.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class MicroApp {
|
|
|
19
19
|
* 预加载app,先放到body,待启动时,挪过来
|
|
20
20
|
*/
|
|
21
21
|
preload(): void;
|
|
22
|
-
reload(): void;
|
|
22
|
+
reload(isGoHome?: boolean): void;
|
|
23
23
|
changeOptions(options: Partial<AppOption>): void;
|
|
24
24
|
onLoad(_event: Event): void;
|
|
25
25
|
onUnload(_event: Event): void;
|