@xingtukeji/micro 1.1.17 → 1.1.19
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 +144 -115
- package/dist/types/api.d.ts +9 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
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 R = (e, t, n) => t in e ?
|
|
2
|
+
var x = Object.defineProperty, X = Object.defineProperties;
|
|
3
|
+
var k = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var M = Object.getOwnPropertySymbols;
|
|
5
|
+
var H = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var R = (e, t, n) => t in e ? x(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
|
+
H.call(t, n) && R(e, n, t[n]);
|
|
9
|
+
if (M)
|
|
10
|
+
for (var n of M(t))
|
|
11
|
+
j.call(t, n) && R(e, n, t[n]);
|
|
12
12
|
return e;
|
|
13
|
-
}, y = (e, t) =>
|
|
13
|
+
}, y = (e, t) => X(e, k(t));
|
|
14
14
|
var p = (e, t, n) => (R(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
15
15
|
var h = (e, t, n) => new Promise((o, r) => {
|
|
16
16
|
var a = (l) => {
|
|
17
17
|
try {
|
|
18
18
|
i(n.next(l));
|
|
19
|
-
} catch (
|
|
20
|
-
r(
|
|
19
|
+
} catch (g) {
|
|
20
|
+
r(g);
|
|
21
21
|
}
|
|
22
22
|
}, c = (l) => {
|
|
23
23
|
try {
|
|
24
24
|
i(n.throw(l));
|
|
25
|
-
} catch (
|
|
26
|
-
r(
|
|
25
|
+
} catch (g) {
|
|
26
|
+
r(g);
|
|
27
27
|
}
|
|
28
28
|
}, i = (l) => l.done ? o(l.value) : Promise.resolve(l.value).then(a, c);
|
|
29
29
|
i((n = n.apply(e, t)).next());
|
|
30
30
|
});
|
|
31
|
-
import { ref as
|
|
31
|
+
import { ref as O, defineComponent as N, watch as F, onMounted as B, onUnmounted as V, openBlock as D, createElementBlock as K, mergeProps as Y } from "vue";
|
|
32
32
|
const s = {
|
|
33
33
|
KEY: "$xtm",
|
|
34
34
|
// 父应用注入子应用实例的key
|
|
@@ -48,28 +48,28 @@ const s = {
|
|
|
48
48
|
// 微应用在 url 参数中的前缀
|
|
49
49
|
MICRO_VERSION: "__XT_MICRO_VERSION"
|
|
50
50
|
// 微应用版本
|
|
51
|
-
},
|
|
51
|
+
}, w = "1.1.19";
|
|
52
52
|
function f(e, t = window.location.href) {
|
|
53
53
|
e = e.replace(/[\[\]]/g, "\\$&");
|
|
54
54
|
var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"), o = n.exec(t);
|
|
55
55
|
return o ? o[2] ? decodeURIComponent(o[2].replace(/\+/g, " ")).trim() : "" : null;
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function E(e, t, n) {
|
|
58
58
|
try {
|
|
59
59
|
return e && (n && e.startsWith("#") ? e : new URL(e, t).href);
|
|
60
60
|
} catch (o) {
|
|
61
61
|
return e;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function W(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 z(e) {
|
|
69
69
|
const t = e.search || "";
|
|
70
70
|
return [...new URLSearchParams(t).entries()].reduce((n, o) => (n[o[0]] = o[1], n), {});
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function q(e, t) {
|
|
73
73
|
let n = null;
|
|
74
74
|
return function(...o) {
|
|
75
75
|
const r = this;
|
|
@@ -78,15 +78,15 @@ function Y(e, t) {
|
|
|
78
78
|
}, t);
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
function
|
|
81
|
+
function C(e, t, n) {
|
|
82
82
|
const [o, r] = e.split("#"), a = new URL(o), c = a.searchParams;
|
|
83
|
-
return t = s.URL_PARAM_PREFIX + t, c.has(t) ? c.set(t, n) : c.append(t, n), r && (a.hash = r), a.search = c.toString(),
|
|
83
|
+
return t = s.URL_PARAM_PREFIX + t, c.has(t) ? c.set(t, n) : c.append(t, n), r && (a.hash = r), a.search = c.toString(), console.trace("urlObj", a), a.origin + a.pathname + a.search + a.hash;
|
|
84
84
|
}
|
|
85
|
-
const
|
|
85
|
+
const S = (e) => h(void 0, null, function* () {
|
|
86
86
|
return new Promise((t) => {
|
|
87
87
|
window.addEventListener("message", (n) => {
|
|
88
|
-
console.debug("child ipcSyncAppInfo receive message", n.data), n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !==
|
|
89
|
-
`子应用版本与主应用版本不一致,${e}子应用版本:${
|
|
88
|
+
console.debug("child ipcSyncAppInfo receive message", n.data), n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !== w && console.warn(
|
|
89
|
+
`子应用版本与主应用版本不一致,${e}子应用版本:${w},主应用版本:${n.data.data.mainMicroVersion}`
|
|
90
90
|
), t(n.data.data));
|
|
91
91
|
}), console.debug("child ipcSyncAppInfo send message", e), window.parent.postMessage(
|
|
92
92
|
{
|
|
@@ -96,25 +96,25 @@ const P = (e) => h(void 0, null, function* () {
|
|
|
96
96
|
"*"
|
|
97
97
|
);
|
|
98
98
|
});
|
|
99
|
-
}),
|
|
99
|
+
}), he = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
100
100
|
__proto__: null,
|
|
101
|
-
addOrReplaceUrlParam:
|
|
102
|
-
anchorElementGenerator:
|
|
103
|
-
debounce:
|
|
104
|
-
getAbsolutePath:
|
|
105
|
-
getAnchorElementQueryMap:
|
|
101
|
+
addOrReplaceUrlParam: C,
|
|
102
|
+
anchorElementGenerator: W,
|
|
103
|
+
debounce: q,
|
|
104
|
+
getAbsolutePath: E,
|
|
105
|
+
getAnchorElementQueryMap: z,
|
|
106
106
|
getQueryParameter: f,
|
|
107
|
-
ipcSyncAppInfo:
|
|
108
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
107
|
+
ipcSyncAppInfo: S
|
|
108
|
+
}, Symbol.toStringTag, { value: "Module" })), P = O(!1);
|
|
109
109
|
Object.defineProperty(window, s.IS_MICRO, {
|
|
110
110
|
get: function() {
|
|
111
|
-
return
|
|
111
|
+
return P.value;
|
|
112
112
|
},
|
|
113
113
|
set: function(e) {
|
|
114
|
-
|
|
114
|
+
P.value = e;
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
|
-
const I = (e) => `${s.DOM_ID_PREFIX}${e}`,
|
|
117
|
+
const I = (e) => `${s.DOM_ID_PREFIX}${e}`, U = (e, t = !1) => {
|
|
118
118
|
function n(i) {
|
|
119
119
|
return i !== null && typeof i == "object" && !Array.isArray(i);
|
|
120
120
|
}
|
|
@@ -122,29 +122,30 @@ const I = (e) => `${s.DOM_ID_PREFIX}${e}`, b = (e, t = !1) => {
|
|
|
122
122
|
e.url.indexOf("http") > -1 ? e.url : window.location.origin + e.url
|
|
123
123
|
), c = f(s.URL_PARAM_PREFIX + e.name);
|
|
124
124
|
if (!t && c) {
|
|
125
|
-
const i =
|
|
125
|
+
const i = E(c, e.url, !0);
|
|
126
126
|
if (i) {
|
|
127
|
-
const l = new URL(i);
|
|
128
|
-
l.searchParams.forEach((
|
|
129
|
-
a.searchParams.set(
|
|
127
|
+
const l = new URL(i, e.url);
|
|
128
|
+
l.searchParams.forEach((A, $) => {
|
|
129
|
+
a.searchParams.set($, A);
|
|
130
130
|
}), a.hash = l.hash;
|
|
131
131
|
}
|
|
132
|
+
m(e.name);
|
|
132
133
|
}
|
|
133
134
|
if (a.searchParams.set(s.IS_MICRO, !0 + ""), a.searchParams.set(s.MICRO_NAME, e.name), r && a.searchParams.set(s.MICRO_TOKEN, r), o)
|
|
134
135
|
for (let i of Object.keys(o))
|
|
135
136
|
a.searchParams.set(i, o[i]);
|
|
136
|
-
return
|
|
137
|
-
},
|
|
137
|
+
return m(e.name), a.href;
|
|
138
|
+
}, G = () => {
|
|
138
139
|
const e = document.createElement("div");
|
|
139
140
|
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;
|
|
140
|
-
},
|
|
141
|
+
}, Q = (e) => {
|
|
141
142
|
e.style.opacity = "0", setTimeout(() => {
|
|
142
143
|
e.remove();
|
|
143
144
|
}, 500);
|
|
144
|
-
},
|
|
145
|
+
}, J = (e) => {
|
|
145
146
|
const t = document.createElement("iframe");
|
|
146
147
|
t.id = I(e.app.name);
|
|
147
|
-
const n =
|
|
148
|
+
const n = U(e.app);
|
|
148
149
|
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", (r) => (t.style.visibility = "visible", e.onLoad.call(e, r))), t.addEventListener(
|
|
149
150
|
"error",
|
|
150
151
|
(r) => e.onError.call(e, r)
|
|
@@ -162,7 +163,7 @@ const I = (e) => `${s.DOM_ID_PREFIX}${e}`, b = (e, t = !1) => {
|
|
|
162
163
|
subtree: !1
|
|
163
164
|
}), t;
|
|
164
165
|
};
|
|
165
|
-
class
|
|
166
|
+
class Z {
|
|
166
167
|
constructor(t) {
|
|
167
168
|
p(this, "app");
|
|
168
169
|
p(this, "dom");
|
|
@@ -176,8 +177,8 @@ class G {
|
|
|
176
177
|
if (t ? (typeof t == "string" ? o = document.querySelector(t) : o = t, o.innerHTML = "") : o = document.body, o) {
|
|
177
178
|
this.panel = o;
|
|
178
179
|
let r = document.getElementById(I(this.app.name));
|
|
179
|
-
r || (r =
|
|
180
|
-
const a =
|
|
180
|
+
r || (r = J(this), this.dom = r), n ? r.style.display = "none" : r.style.removeProperty("display");
|
|
181
|
+
const a = G();
|
|
181
182
|
this.loadingTimer = setTimeout(() => {
|
|
182
183
|
this.loading = a, o.appendChild(a);
|
|
183
184
|
}, 1e3), o.appendChild(r);
|
|
@@ -209,7 +210,7 @@ class G {
|
|
|
209
210
|
}
|
|
210
211
|
reload(t = !1) {
|
|
211
212
|
let n = this.dom.src;
|
|
212
|
-
t && (n =
|
|
213
|
+
t && (n = U(this.app, !0), console.log("go home", n)), console.log("reload app", this.app, n);
|
|
213
214
|
const o = new URL(n);
|
|
214
215
|
o.searchParams.set("__t", Date.now().toString()), this.dom.style.visibility = "hidden", this.dom.src = o.toString();
|
|
215
216
|
}
|
|
@@ -217,16 +218,16 @@ class G {
|
|
|
217
218
|
console.log("changeOptions", this.app, t), this.app = d(d({}, this.app), t);
|
|
218
219
|
}
|
|
219
220
|
onLoad(t) {
|
|
220
|
-
console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading &&
|
|
221
|
+
console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && Q(this.loading), ee(this), console.log("this.app.onLoad", this.app.onLoad), this.app.onLoad && this.app.onLoad(t, this);
|
|
221
222
|
}
|
|
222
223
|
onUnload(t) {
|
|
223
|
-
console.debug("app onUnload", this.app.name),
|
|
224
|
+
console.debug("app onUnload", this.app.name), m(this.app.name), this.app.onUnload && this.app.onUnload(t, this);
|
|
224
225
|
}
|
|
225
226
|
onError(t) {
|
|
226
227
|
console.error("app onError", this.app.name), this.app.onError && this.app.onError(t, this);
|
|
227
228
|
}
|
|
228
229
|
}
|
|
229
|
-
const
|
|
230
|
+
const ee = (e) => {
|
|
230
231
|
var t, n;
|
|
231
232
|
(n = (t = e.dom) == null ? void 0 : t.contentWindow) == null || n.postMessage(
|
|
232
233
|
{
|
|
@@ -241,7 +242,7 @@ const Q = (e) => {
|
|
|
241
242
|
},
|
|
242
243
|
"*"
|
|
243
244
|
);
|
|
244
|
-
},
|
|
245
|
+
}, te = () => {
|
|
245
246
|
window[s.MICRO_TYPE] = "parent", window.addEventListener("message", (e) => {
|
|
246
247
|
if (e.data.cmd === "$xt/micro/sync") {
|
|
247
248
|
console.log("父页面接受子应用同步路由信息", e.data);
|
|
@@ -253,17 +254,23 @@ const Q = (e) => {
|
|
|
253
254
|
window.decodeURIComponent(e.data.data.url),
|
|
254
255
|
e.origin
|
|
255
256
|
);
|
|
256
|
-
for (let
|
|
257
|
-
n.searchParams.delete(
|
|
258
|
-
|
|
259
|
-
|
|
257
|
+
for (let c of t)
|
|
258
|
+
n.searchParams.delete(c);
|
|
259
|
+
console.log("tempUrl", n);
|
|
260
|
+
const o = m(e.data.data.name), r = new URL(o);
|
|
261
|
+
r.searchParams.forEach((c, i) => {
|
|
262
|
+
i.startsWith(s.URL_PARAM_PREFIX) && r.searchParams.delete(i);
|
|
263
|
+
}), console.log("mainURL.href", r.href);
|
|
264
|
+
const a = C(
|
|
265
|
+
r.href,
|
|
260
266
|
e.data.data.name,
|
|
261
267
|
n.href
|
|
268
|
+
// tempUrl.pathname + tempUrl.search + tempUrl.hash
|
|
262
269
|
);
|
|
263
|
-
window.history.replaceState(null, "",
|
|
270
|
+
console.log("curUrl", a), window.history.replaceState(null, "", a);
|
|
264
271
|
} else if (e.data.cmd === "$xt/micro/info") {
|
|
265
272
|
console.debug("parent 「$xt/micro/info」 receive message", e.data);
|
|
266
|
-
const t =
|
|
273
|
+
const t = _(e.data.data);
|
|
267
274
|
e.source.postMessage(
|
|
268
275
|
{
|
|
269
276
|
cmd: "$xt/micro/info",
|
|
@@ -279,7 +286,7 @@ const Q = (e) => {
|
|
|
279
286
|
port: window.location.port,
|
|
280
287
|
protocol: window.location.protocol
|
|
281
288
|
},
|
|
282
|
-
mainMicroVersion:
|
|
289
|
+
mainMicroVersion: w,
|
|
283
290
|
name: t.name,
|
|
284
291
|
url: t.url,
|
|
285
292
|
params: t.params,
|
|
@@ -291,12 +298,12 @@ const Q = (e) => {
|
|
|
291
298
|
);
|
|
292
299
|
}
|
|
293
300
|
});
|
|
294
|
-
},
|
|
301
|
+
}, ne = (...t) => h(void 0, [...t], function* (e = {}) {
|
|
295
302
|
window[s.MICRO_TYPE] = "child";
|
|
296
303
|
const n = f(s.IS_MICRO), o = f(s.MICRO_NAME);
|
|
297
|
-
if (console.debug("child microInit", n, o), n && (window[s.IS_MICRO] = n === "true"), o &&
|
|
304
|
+
if (console.debug("child microInit", n, o), n && (window[s.IS_MICRO] = n === "true"), o && S(o).then((r) => {
|
|
298
305
|
window[s.MICRO_APP] = d({
|
|
299
|
-
microVersion:
|
|
306
|
+
microVersion: w
|
|
300
307
|
}, r);
|
|
301
308
|
}), window[s.IS_MICRO]) {
|
|
302
309
|
let r = function(c) {
|
|
@@ -311,15 +318,15 @@ const Q = (e) => {
|
|
|
311
318
|
r(`${c} { display: none !important; }`);
|
|
312
319
|
}) : r(
|
|
313
320
|
`${e.hideHeaderCssSelector} { display: none !important; }`
|
|
314
|
-
)), yield
|
|
315
|
-
c.data.cmd === `$xt/micro/${o}` &&
|
|
321
|
+
)), yield oe(o, window), window.addEventListener("message", (c) => h(void 0, null, function* () {
|
|
322
|
+
c.data.cmd === `$xt/micro/${o}` && L(o);
|
|
316
323
|
}));
|
|
317
324
|
const a = f(s.MICRO_TOKEN);
|
|
318
325
|
e.authHandler && a && (yield e.authHandler(a));
|
|
319
326
|
} else
|
|
320
327
|
console.warn("当前环境非微应用环境");
|
|
321
328
|
});
|
|
322
|
-
function
|
|
329
|
+
function oe(e, t) {
|
|
323
330
|
const n = t.history, o = n.pushState, r = n.replaceState;
|
|
324
331
|
n.pushState = function(a, c, i) {
|
|
325
332
|
const l = y(d(d({}, n.state || {}), a), {
|
|
@@ -327,25 +334,22 @@ function Z(e, t) {
|
|
|
327
334
|
_patchedByParent: !0
|
|
328
335
|
// 可选:标记这是被父窗口修改的状态
|
|
329
336
|
});
|
|
330
|
-
o.call(n, l, c, i),
|
|
337
|
+
o.call(n, l, c, i), L(e);
|
|
331
338
|
}, n.replaceState = function(a, c, i) {
|
|
332
339
|
const l = y(d(d({}, n.state || {}), a), {
|
|
333
340
|
// 添加新数据
|
|
334
341
|
_patchedByParent: !0
|
|
335
342
|
// 可选:标记这是被父窗口修改的状态
|
|
336
343
|
});
|
|
337
|
-
r.call(n, l, c, i)
|
|
344
|
+
r.call(n, l, c, i);
|
|
338
345
|
};
|
|
339
346
|
}
|
|
340
|
-
function
|
|
347
|
+
function L(e) {
|
|
341
348
|
return h(this, null, function* () {
|
|
342
|
-
console.log("syncUrlToWindow", e, window[s.MICRO_APP]), window[s.MICRO_APP]
|
|
343
|
-
|
|
344
|
-
microVersion: u
|
|
345
|
-
}, a);
|
|
346
|
-
}));
|
|
349
|
+
if (console.log("syncUrlToWindow", e, window[s.MICRO_APP]), !window[s.MICRO_APP])
|
|
350
|
+
return;
|
|
347
351
|
const { name: t, sync: n, mainLocation: o } = window[s.MICRO_APP], r = window.location.pathname + window.location.search + window.location.hash;
|
|
348
|
-
window.parent.postMessage(
|
|
352
|
+
console.log("curUrl", r), window.parent.postMessage(
|
|
349
353
|
{
|
|
350
354
|
cmd: "$xt/micro/sync",
|
|
351
355
|
data: {
|
|
@@ -357,80 +361,105 @@ function M(e) {
|
|
|
357
361
|
);
|
|
358
362
|
});
|
|
359
363
|
}
|
|
360
|
-
let
|
|
361
|
-
const
|
|
364
|
+
let u = {};
|
|
365
|
+
const re = {
|
|
362
366
|
url: "",
|
|
363
367
|
name: "",
|
|
364
368
|
sync: !0
|
|
365
|
-
},
|
|
369
|
+
}, ae = (e) => {
|
|
366
370
|
if (!e.url || e.url === "" || e.url === "undefined") {
|
|
367
371
|
console.error("app url is required", e);
|
|
368
372
|
return;
|
|
369
373
|
}
|
|
370
|
-
const t = Object.assign({},
|
|
371
|
-
return n ?
|
|
372
|
-
instance: new
|
|
373
|
-
}),
|
|
374
|
-
},
|
|
375
|
-
let r =
|
|
376
|
-
r ? (t && (r.instance.changeOptions(t), r =
|
|
377
|
-
}),
|
|
378
|
-
let t =
|
|
374
|
+
const t = Object.assign({}, re, e), n = u[e.name];
|
|
375
|
+
return n ? u[e.name] = d(d({}, n), t) : u[e.name] = y(d({}, t), {
|
|
376
|
+
instance: new Z(e)
|
|
377
|
+
}), u[e.name];
|
|
378
|
+
}, _ = (e) => u[e], se = (e, t) => u[e.name] = d(d({}, e), t), b = (e, t) => new Promise((n, o) => {
|
|
379
|
+
let r = _(e);
|
|
380
|
+
r ? (t && (r.instance.changeOptions(t), r = se(r, t)), r.preload ? r.instance.preloadRender(r.el) : r.instance.mount(r.el), n(r)) : o("app not found, please setup app first");
|
|
381
|
+
}), T = (e) => {
|
|
382
|
+
let t = _(e);
|
|
379
383
|
t && t.instance.unmount();
|
|
380
|
-
},
|
|
381
|
-
let n =
|
|
384
|
+
}, ie = (e, t = !1) => {
|
|
385
|
+
let n = _(e);
|
|
382
386
|
n && n.instance.reload(t);
|
|
383
|
-
},
|
|
387
|
+
}, m = (e) => {
|
|
384
388
|
console.log("clearParentUrl", e, s.URL_PARAM_PREFIX + e);
|
|
385
389
|
const t = window.location.href.split("#");
|
|
386
390
|
console.log("url", t);
|
|
387
|
-
|
|
388
|
-
|
|
391
|
+
let n = new URL(t[0]);
|
|
392
|
+
n.searchParams.delete(s.URL_PARAM_PREFIX + e);
|
|
389
393
|
const o = t.length > 1 ? n.href + "#" + t[1] : n.href;
|
|
390
394
|
return window.history.replaceState({}, "", o), o;
|
|
391
|
-
},
|
|
395
|
+
}, v = () => window[s.IS_MICRO] === !0, ce = () => window[s.MICRO_TYPE] === "parent", le = (e, t = ((n) => (n = window.__XT_MICRO_APP) == null ? void 0 : n.name)()) => {
|
|
396
|
+
let o = window.location;
|
|
397
|
+
if (v())
|
|
398
|
+
o = window.__XT_MICRO_APP.mainLocation;
|
|
399
|
+
else if (!t) {
|
|
400
|
+
console.error("在主应用中需要传入应用名称");
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
return `${o.origin}${o.pathname}?__XT_MICRO_${t}=${encodeURIComponent(e)}${o.hash}`;
|
|
404
|
+
}, de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
405
|
+
__proto__: null,
|
|
406
|
+
clearParentUrl: m,
|
|
407
|
+
createAppUrl: le,
|
|
408
|
+
getApp: _,
|
|
409
|
+
isMicro: v,
|
|
410
|
+
isParent: ce,
|
|
411
|
+
microInit: ne,
|
|
412
|
+
reloadApp: ie,
|
|
413
|
+
setupApp: ae,
|
|
414
|
+
startApp: b,
|
|
415
|
+
stopApp: T
|
|
416
|
+
}, Symbol.toStringTag, { value: "Module" })), me = /* @__PURE__ */ N({
|
|
392
417
|
__name: "XTMicroView",
|
|
393
418
|
props: {
|
|
394
419
|
appId: String
|
|
395
420
|
},
|
|
396
421
|
setup(e) {
|
|
397
|
-
const t = e, n =
|
|
398
|
-
t.appId &&
|
|
422
|
+
const t = e, n = O(), o = () => {
|
|
423
|
+
t.appId && b(t.appId, {
|
|
399
424
|
el: n.value,
|
|
400
425
|
onUnload(r, a) {
|
|
401
|
-
console.log("on unload", a.app.name),
|
|
426
|
+
console.log("on unload", a.app.name), m(a.app.name);
|
|
402
427
|
}
|
|
403
428
|
}).then((r) => {
|
|
404
429
|
console.debug("app mounted", t.appId);
|
|
405
430
|
});
|
|
406
431
|
};
|
|
407
|
-
return
|
|
408
|
-
r !== a && a &&
|
|
409
|
-
}),
|
|
432
|
+
return F(() => t.appId, (r, a) => {
|
|
433
|
+
r !== a && a && T(a), o();
|
|
434
|
+
}), B(() => {
|
|
410
435
|
o();
|
|
411
|
-
}),
|
|
412
|
-
console.debug("「micro」", "app unmount", t.appId),
|
|
413
|
-
}), (r, a) => (
|
|
436
|
+
}), V(() => {
|
|
437
|
+
console.debug("「micro」", "app unmount", t.appId), m(t.appId);
|
|
438
|
+
}), (r, a) => (D(), K("div", Y({
|
|
414
439
|
ref_key: "refPanel",
|
|
415
440
|
ref: n
|
|
416
441
|
}, r.$attrs, { class: "xt-micro" }), null, 16));
|
|
417
442
|
}
|
|
418
443
|
});
|
|
419
|
-
window[s.MICRO_VERSION] =
|
|
420
|
-
|
|
444
|
+
window[s.MICRO_VERSION] = w;
|
|
445
|
+
window.api = de;
|
|
446
|
+
const fe = {
|
|
421
447
|
install: (e, t = {}) => {
|
|
422
|
-
e.component("xt-micro-view",
|
|
448
|
+
e.component("xt-micro-view", me), te();
|
|
423
449
|
}
|
|
424
450
|
};
|
|
425
451
|
export {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
ne as
|
|
434
|
-
|
|
435
|
-
|
|
452
|
+
me as XTMicroView,
|
|
453
|
+
m as clearParentUrl,
|
|
454
|
+
le as createAppUrl,
|
|
455
|
+
fe as default,
|
|
456
|
+
_ as getApp,
|
|
457
|
+
v as isMicro,
|
|
458
|
+
ce as isParent,
|
|
459
|
+
ne as microInit,
|
|
460
|
+
ie as reloadApp,
|
|
461
|
+
ae as setupApp,
|
|
462
|
+
b as startApp,
|
|
463
|
+
T as stopApp,
|
|
464
|
+
he as utils
|
|
436
465
|
};
|
package/dist/types/api.d.ts
CHANGED
|
@@ -20,4 +20,13 @@ export declare const startApp: (name: string, options?: Partial<AppOption>) => P
|
|
|
20
20
|
export declare const stopApp: (name: string) => void;
|
|
21
21
|
export declare const reloadApp: (name: string, isGoHome?: boolean) => void;
|
|
22
22
|
export declare const clearParentUrl: (appName: string) => string;
|
|
23
|
+
export declare const isMicro: () => boolean;
|
|
24
|
+
export declare const isParent: () => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 创建基于主应用路由的某个子应用的 url
|
|
27
|
+
* @param appName 应用名称
|
|
28
|
+
* @param targetUrlHash 应用地址
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export declare const createAppUrl: (targetUrlHash: string, appName?: string) => string;
|
|
23
32
|
export { microInit };
|