@xingtukeji/micro 1.1.13 → 1.1.15
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 +168 -151
- package/dist/types/api.d.ts +2 -1
- package/dist/types/components/XTMicroView.vue.d.ts +1 -1
- 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
|
|
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 m = (e, t, n) => (
|
|
15
|
-
var u = (e, t, n) => new Promise((
|
|
16
|
-
var a = (
|
|
13
|
+
}, _ = (e, t) => T(e, x(t));
|
|
14
|
+
var m = (e, t, n) => (R(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
15
|
+
var u = (e, t, n) => new Promise((r, o) => {
|
|
16
|
+
var a = (l) => {
|
|
17
17
|
try {
|
|
18
|
-
|
|
19
|
-
} catch (
|
|
20
|
-
|
|
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
|
-
|
|
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
|
|
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
32
|
const s = {
|
|
33
33
|
KEY: "$xtm",
|
|
34
34
|
// 父应用注入子应用实例的key
|
|
@@ -48,16 +48,16 @@ const s = {
|
|
|
48
48
|
// 微应用在 url 参数中的前缀
|
|
49
49
|
MICRO_VERSION: "__XT_MICRO_VERSION"
|
|
50
50
|
// 微应用版本
|
|
51
|
-
}, h = "1.1.
|
|
51
|
+
}, h = "1.1.14";
|
|
52
52
|
function f(e, t = window.location.href) {
|
|
53
53
|
e = e.replace(/[\[\]]/g, "\\$&");
|
|
54
|
-
var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"),
|
|
55
|
-
return
|
|
54
|
+
var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"), r = n.exec(t);
|
|
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
|
-
} catch (
|
|
60
|
+
} catch (r) {
|
|
61
61
|
return e;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -65,24 +65,24 @@ 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
|
-
return [...new URLSearchParams(t).entries()].reduce((n,
|
|
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
|
-
return function(...
|
|
75
|
-
const
|
|
74
|
+
return function(...r) {
|
|
75
|
+
const o = this;
|
|
76
76
|
n && clearTimeout(n), n = setTimeout(() => {
|
|
77
|
-
e.apply(
|
|
77
|
+
e.apply(o, r);
|
|
78
78
|
}, t);
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
const [
|
|
83
|
-
return t = s.URL_PARAM_PREFIX + t, c.has(t) ? c.set(t, n) : c.append(t, n),
|
|
81
|
+
function U(e, t, n) {
|
|
82
|
+
const [r, o] = e.split("#"), a = new URL(r), c = a.searchParams;
|
|
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) => u(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 !== h && console.warn(
|
|
@@ -98,69 +98,71 @@ const M = (e) => u(void 0, null, function* () {
|
|
|
98
98
|
});
|
|
99
99
|
}), ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
100
100
|
__proto__: null,
|
|
101
|
-
addOrReplaceUrlParam:
|
|
101
|
+
addOrReplaceUrlParam: U,
|
|
102
102
|
anchorElementGenerator: D,
|
|
103
|
-
debounce:
|
|
104
|
-
getAbsolutePath:
|
|
105
|
-
getAnchorElementQueryMap:
|
|
103
|
+
debounce: W,
|
|
104
|
+
getAbsolutePath: S,
|
|
105
|
+
getAnchorElementQueryMap: K,
|
|
106
106
|
getQueryParameter: f,
|
|
107
|
-
ipcSyncAppInfo:
|
|
108
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
107
|
+
ipcSyncAppInfo: P
|
|
108
|
+
}, Symbol.toStringTag, { value: "Module" })), O = C(!1);
|
|
109
109
|
Object.defineProperty(window, s.IS_MICRO, {
|
|
110
110
|
get: function() {
|
|
111
|
-
return
|
|
111
|
+
return O.value;
|
|
112
112
|
},
|
|
113
113
|
set: function(e) {
|
|
114
|
-
|
|
114
|
+
O.value = e;
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
|
-
const I = (e) => `${s.DOM_ID_PREFIX}${e}`,
|
|
117
|
+
const I = (e) => `${s.DOM_ID_PREFIX}${e}`, L = (e, t = !1) => {
|
|
118
118
|
function n(i) {
|
|
119
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
123
|
), c = f(s.URL_PARAM_PREFIX + e.name);
|
|
124
124
|
if (!t && c) {
|
|
125
|
-
const i =
|
|
125
|
+
const i = S(c, e.url, !0);
|
|
126
126
|
if (i) {
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
a.searchParams.set(
|
|
130
|
-
}), a.hash =
|
|
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 (a.searchParams.set(s.IS_MICRO, !0 + ""), a.searchParams.set(s.MICRO_NAME, e.name),
|
|
134
|
-
for (let i of Object.keys(
|
|
135
|
-
a.searchParams.set(i,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}, W = () => {
|
|
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 y(e.name), a.href;
|
|
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 =
|
|
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", (
|
|
147
|
+
const n = L(e.app);
|
|
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)
|
|
152
151
|
), t.addEventListener(
|
|
153
152
|
"unload",
|
|
154
|
-
(
|
|
153
|
+
(o) => e.onUnload.call(e, o)
|
|
155
154
|
);
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")),
|
|
155
|
+
const r = new MutationObserver((o) => {
|
|
156
|
+
console.log("监听 body 中子节点的变化2", e.panel), o.forEach((a) => {
|
|
157
|
+
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")), r.disconnect());
|
|
159
158
|
});
|
|
160
159
|
});
|
|
161
|
-
return
|
|
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
167
|
m(this, "app");
|
|
166
168
|
m(this, "dom");
|
|
@@ -170,20 +172,21 @@ class z {
|
|
|
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) {
|
|
173
|
-
let
|
|
174
|
-
if (t ? (typeof t == "string" ?
|
|
175
|
-
this.panel =
|
|
176
|
-
let
|
|
177
|
-
|
|
178
|
-
const a =
|
|
175
|
+
let r;
|
|
176
|
+
if (t ? (typeof t == "string" ? r = document.querySelector(t) : r = t, r.innerHTML = "") : r = document.body, r) {
|
|
177
|
+
this.panel = r;
|
|
178
|
+
let o = document.getElementById(I(this.app.name));
|
|
179
|
+
o || (o = z(this), this.dom = o), n ? o.style.display = "none" : o.style.removeProperty("display");
|
|
180
|
+
const a = Y();
|
|
179
181
|
this.loadingTimer = setTimeout(() => {
|
|
180
|
-
this.loading = a,
|
|
181
|
-
}, 1e3),
|
|
182
|
+
this.loading = a, r.appendChild(a);
|
|
183
|
+
}, 1e3), r.appendChild(o);
|
|
182
184
|
} else
|
|
183
185
|
throw new Error("el not found");
|
|
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);
|
|
@@ -206,24 +209,24 @@ class z {
|
|
|
206
209
|
}
|
|
207
210
|
reload(t = !1) {
|
|
208
211
|
let n = this.dom.src;
|
|
209
|
-
t && (n =
|
|
210
|
-
const
|
|
211
|
-
|
|
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.style.visibility = "hidden", this.dom.src = r.toString();
|
|
212
215
|
}
|
|
213
216
|
changeOptions(t) {
|
|
214
|
-
this.app = d(d({}, this.app), t);
|
|
217
|
+
console.log("changeOptions", this.app, t), this.app = d(d({}, this.app), t);
|
|
215
218
|
}
|
|
216
219
|
onLoad(t) {
|
|
217
|
-
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);
|
|
218
221
|
}
|
|
219
222
|
onUnload(t) {
|
|
220
|
-
console.debug("app onUnload", this.app.name), this.app.onUnload && this.app.onUnload(t, this);
|
|
223
|
+
console.debug("app onUnload", this.app.name), y(this.app.name), this.app.onUnload && this.app.onUnload(t, this);
|
|
221
224
|
}
|
|
222
225
|
onError(t) {
|
|
223
226
|
console.error("app onError", this.app.name), this.app.onError && this.app.onError(t, this);
|
|
224
227
|
}
|
|
225
228
|
}
|
|
226
|
-
const
|
|
229
|
+
const Q = (e) => {
|
|
227
230
|
var t, n;
|
|
228
231
|
(n = (t = e.dom) == null ? void 0 : t.contentWindow) == null || n.postMessage(
|
|
229
232
|
{
|
|
@@ -238,7 +241,7 @@ const G = (e) => {
|
|
|
238
241
|
},
|
|
239
242
|
"*"
|
|
240
243
|
);
|
|
241
|
-
},
|
|
244
|
+
}, J = () => {
|
|
242
245
|
window[s.MICRO_TYPE] = "parent", window.addEventListener("message", (e) => {
|
|
243
246
|
if (e.data.cmd === "$xt/micro/sync") {
|
|
244
247
|
console.log("父页面接受子应用同步路由信息", e.data);
|
|
@@ -252,19 +255,19 @@ const G = (e) => {
|
|
|
252
255
|
);
|
|
253
256
|
for (let a of t)
|
|
254
257
|
n.searchParams.delete(a);
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
c.startsWith(s.URL_PARAM_PREFIX) &&
|
|
258
|
+
const r = new URL(window.location.href);
|
|
259
|
+
r.searchParams.forEach((a, c) => {
|
|
260
|
+
c.startsWith(s.URL_PARAM_PREFIX) && r.searchParams.delete(c);
|
|
258
261
|
});
|
|
259
|
-
const
|
|
260
|
-
|
|
262
|
+
const o = U(
|
|
263
|
+
r.href,
|
|
261
264
|
e.data.data.name,
|
|
262
265
|
n.href
|
|
263
266
|
);
|
|
264
|
-
window.history.replaceState(null, "",
|
|
267
|
+
window.history.replaceState(null, "", o);
|
|
265
268
|
} else if (e.data.cmd === "$xt/micro/info") {
|
|
266
269
|
console.debug("parent 「$xt/micro/info」 receive message", e.data);
|
|
267
|
-
const t =
|
|
270
|
+
const t = g(e.data.data);
|
|
268
271
|
e.source.postMessage(
|
|
269
272
|
{
|
|
270
273
|
cmd: "$xt/micro/info",
|
|
@@ -294,72 +297,72 @@ const G = (e) => {
|
|
|
294
297
|
});
|
|
295
298
|
}, ce = (...t) => u(void 0, [...t], function* (e = {}) {
|
|
296
299
|
window[s.MICRO_TYPE] = "child";
|
|
297
|
-
const n = f(s.IS_MICRO),
|
|
298
|
-
if (console.debug("child microInit", n,
|
|
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) => {
|
|
299
302
|
window[s.MICRO_APP] = d({
|
|
300
303
|
microVersion: h
|
|
301
|
-
},
|
|
304
|
+
}, o);
|
|
302
305
|
}), window[s.IS_MICRO]) {
|
|
303
|
-
let
|
|
304
|
-
var
|
|
305
|
-
if (!
|
|
306
|
-
var
|
|
307
|
-
document.head.appendChild(
|
|
306
|
+
let o = function(c) {
|
|
307
|
+
var i = document.styleSheets[0];
|
|
308
|
+
if (!i) {
|
|
309
|
+
var l = document.createElement("style");
|
|
310
|
+
document.head.appendChild(l), i = l.sheet;
|
|
308
311
|
}
|
|
309
|
-
|
|
312
|
+
i.insertRule(c, i.cssRules.length);
|
|
310
313
|
};
|
|
311
314
|
window[s.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((c) => {
|
|
312
|
-
|
|
313
|
-
}) :
|
|
315
|
+
o(`${c} { display: none !important; }`);
|
|
316
|
+
}) : o(
|
|
314
317
|
`${e.hideHeaderCssSelector} { display: none !important; }`
|
|
315
|
-
)), yield
|
|
316
|
-
c.data.cmd === `$xt/micro/${
|
|
318
|
+
)), yield Z(r, window), window.addEventListener("message", (c) => u(void 0, null, function* () {
|
|
319
|
+
c.data.cmd === `$xt/micro/${r}` && M(r);
|
|
317
320
|
}));
|
|
318
321
|
const a = f(s.MICRO_TOKEN);
|
|
319
322
|
e.authHandler && a && (yield e.authHandler(a));
|
|
320
323
|
} else
|
|
321
324
|
console.warn("当前环境非微应用环境");
|
|
322
325
|
});
|
|
323
|
-
function
|
|
324
|
-
const n = t.history,
|
|
325
|
-
n.pushState = function(a, c,
|
|
326
|
-
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), {
|
|
327
330
|
// 添加新数据
|
|
328
331
|
_patchedByParent: !0
|
|
329
332
|
// 可选:标记这是被父窗口修改的状态
|
|
330
333
|
});
|
|
331
|
-
|
|
332
|
-
}, n.replaceState = function(a, c,
|
|
333
|
-
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), {
|
|
334
337
|
// 添加新数据
|
|
335
338
|
_patchedByParent: !0
|
|
336
339
|
// 可选:标记这是被父窗口修改的状态
|
|
337
340
|
});
|
|
338
|
-
|
|
341
|
+
o.call(n, l, c, i), M(e);
|
|
339
342
|
};
|
|
340
343
|
}
|
|
341
|
-
function
|
|
344
|
+
function M(e) {
|
|
342
345
|
return u(this, null, function* () {
|
|
343
|
-
console.log("syncUrlToWindow", e, window[s.MICRO_APP]), window[s.MICRO_APP] || (yield
|
|
346
|
+
console.log("syncUrlToWindow", e, window[s.MICRO_APP]), window[s.MICRO_APP] || (yield P(e).then((a) => {
|
|
344
347
|
window[s.MICRO_APP] = d({
|
|
345
348
|
microVersion: h
|
|
346
349
|
}, a);
|
|
347
350
|
}));
|
|
348
|
-
const { name: t, sync: n, mainLocation:
|
|
351
|
+
const { name: t, sync: n, mainLocation: r } = window[s.MICRO_APP], o = window.location.pathname + window.location.search + window.location.hash;
|
|
349
352
|
window.parent.postMessage(
|
|
350
353
|
{
|
|
351
354
|
cmd: "$xt/micro/sync",
|
|
352
355
|
data: {
|
|
353
356
|
name: t,
|
|
354
|
-
url: window.encodeURIComponent(
|
|
357
|
+
url: window.encodeURIComponent(o)
|
|
355
358
|
}
|
|
356
359
|
},
|
|
357
|
-
|
|
360
|
+
r.origin
|
|
358
361
|
);
|
|
359
362
|
});
|
|
360
363
|
}
|
|
361
|
-
let
|
|
362
|
-
const
|
|
364
|
+
let p = {};
|
|
365
|
+
const ee = {
|
|
363
366
|
url: "",
|
|
364
367
|
name: "",
|
|
365
368
|
sync: !0
|
|
@@ -368,58 +371,72 @@ const Z = {
|
|
|
368
371
|
console.error("app url is required", e);
|
|
369
372
|
return;
|
|
370
373
|
}
|
|
371
|
-
const t = Object.assign({},
|
|
372
|
-
return
|
|
373
|
-
instance: new
|
|
374
|
-
}),
|
|
375
|
-
},
|
|
376
|
-
let
|
|
377
|
-
|
|
378
|
-
}),
|
|
379
|
-
let t =
|
|
374
|
+
const t = Object.assign({}, ee, e), n = p[e.name];
|
|
375
|
+
return n ? p[e.name] = d(d({}, n), t) : p[e.name] = _(d({}, t), {
|
|
376
|
+
instance: new G(e)
|
|
377
|
+
}), p[e.name];
|
|
378
|
+
}, g = (e) => p[e], te = (e, t) => p[e.name] = d(d({}, e), t), ne = (e, t) => new Promise((n, r) => {
|
|
379
|
+
let o = g(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 = g(e);
|
|
380
383
|
t && t.instance.unmount();
|
|
381
384
|
}, de = (e, t = !1) => {
|
|
382
|
-
let n =
|
|
385
|
+
let n = g(e);
|
|
383
386
|
n && n.instance.reload(t);
|
|
384
|
-
},
|
|
387
|
+
}, y = (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({
|
|
385
398
|
__name: "XTMicroView",
|
|
386
399
|
props: {
|
|
387
400
|
appId: String
|
|
388
401
|
},
|
|
389
402
|
setup(e) {
|
|
390
|
-
const t = e, n =
|
|
391
|
-
t.appId &&
|
|
392
|
-
el: n.value
|
|
393
|
-
|
|
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), y(a.app.name);
|
|
408
|
+
}
|
|
409
|
+
}).then((o) => {
|
|
394
410
|
console.debug("app mounted", t.appId);
|
|
395
411
|
});
|
|
396
412
|
};
|
|
397
|
-
return
|
|
398
|
-
|
|
399
|
-
}),
|
|
400
|
-
|
|
401
|
-
}),
|
|
402
|
-
console.debug("app unmount", t.appId);
|
|
403
|
-
}), (
|
|
413
|
+
return H(() => t.appId, (o, a) => {
|
|
414
|
+
o !== a && a && oe(a), r();
|
|
415
|
+
}), j(() => {
|
|
416
|
+
r();
|
|
417
|
+
}), F(() => {
|
|
418
|
+
console.debug("「micro」", "app unmount", t.appId), y(t.appId);
|
|
419
|
+
}), (o, a) => (N(), V("div", B({
|
|
404
420
|
ref_key: "refPanel",
|
|
405
421
|
ref: n
|
|
406
|
-
},
|
|
422
|
+
}, o.$attrs, { class: "xt-micro" }), null, 16));
|
|
407
423
|
}
|
|
408
424
|
});
|
|
409
425
|
window[s.MICRO_VERSION] = h;
|
|
410
|
-
const
|
|
426
|
+
const me = {
|
|
411
427
|
install: (e, t = {}) => {
|
|
412
|
-
e.component("xt-micro-view",
|
|
428
|
+
e.component("xt-micro-view", re), J();
|
|
413
429
|
}
|
|
414
430
|
};
|
|
415
431
|
export {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
432
|
+
re as XTMicroView,
|
|
433
|
+
y as clearParentUrl,
|
|
434
|
+
me as default,
|
|
435
|
+
g as getApp,
|
|
419
436
|
ce as microInit,
|
|
420
437
|
de as reloadApp,
|
|
421
438
|
le as setupApp,
|
|
422
|
-
|
|
423
|
-
|
|
439
|
+
ne as startApp,
|
|
440
|
+
oe as stopApp,
|
|
424
441
|
ie as utils
|
|
425
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
|
* 启动微应用
|
|
@@ -19,4 +19,5 @@ export declare const startApp: (name: string, options?: Partial<AppOption>) => P
|
|
|
19
19
|
*/
|
|
20
20
|
export declare const stopApp: (name: string) => void;
|
|
21
21
|
export declare const reloadApp: (name: string, isGoHome?: boolean) => void;
|
|
22
|
+
export declare const clearParentUrl: (appName: string) => void;
|
|
22
23
|
export { microInit };
|
|
@@ -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;
|