@xingtukeji/micro 1.1.16 → 1.1.17
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 +65 -67
- package/dist/types/api.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,20 +12,20 @@ var R = (e, t, n) => t in e ? T(e, t, { enumerable: !0, configurable: !0, writab
|
|
|
12
12
|
return e;
|
|
13
13
|
}, y = (e, t) => A(e, x(t));
|
|
14
14
|
var p = (e, t, n) => (R(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
15
|
-
var h = (e, t, n) => new Promise((
|
|
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
19
|
} catch (_) {
|
|
20
|
-
|
|
20
|
+
r(_);
|
|
21
21
|
}
|
|
22
22
|
}, c = (l) => {
|
|
23
23
|
try {
|
|
24
24
|
i(n.throw(l));
|
|
25
25
|
} catch (_) {
|
|
26
|
-
|
|
26
|
+
r(_);
|
|
27
27
|
}
|
|
28
|
-
}, i = (l) => l.done ?
|
|
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
31
|
import { ref as C, defineComponent as k, watch as H, onMounted as j, onUnmounted as N, openBlock as V, createElementBlock as B, mergeProps as F } from "vue";
|
|
@@ -48,16 +48,16 @@ const s = {
|
|
|
48
48
|
// 微应用在 url 参数中的前缀
|
|
49
49
|
MICRO_VERSION: "__XT_MICRO_VERSION"
|
|
50
50
|
// 微应用版本
|
|
51
|
-
}, u = "1.1.
|
|
51
|
+
}, u = "1.1.17";
|
|
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 + "(=([^&#]*)|&|#|$)"), o = n.exec(t);
|
|
55
|
+
return o ? o[2] ? decodeURIComponent(o[2].replace(/\+/g, " ")).trim() : "" : null;
|
|
56
56
|
}
|
|
57
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 (o) {
|
|
61
61
|
return e;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -67,20 +67,20 @@ function D(e) {
|
|
|
67
67
|
}
|
|
68
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, o) => (n[o[0]] = o[1], n), {});
|
|
71
71
|
}
|
|
72
72
|
function Y(e, t) {
|
|
73
73
|
let n = null;
|
|
74
|
-
return function(...
|
|
75
|
-
const
|
|
74
|
+
return function(...o) {
|
|
75
|
+
const r = this;
|
|
76
76
|
n && clearTimeout(n), n = setTimeout(() => {
|
|
77
|
-
e.apply(
|
|
77
|
+
e.apply(r, o);
|
|
78
78
|
}, t);
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
function U(e, t, n) {
|
|
82
|
-
const [
|
|
83
|
-
return t = s.URL_PARAM_PREFIX + t, c.has(t) ? c.set(t, n) : c.append(t, n),
|
|
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(), a.toString();
|
|
84
84
|
}
|
|
85
85
|
const P = (e) => h(void 0, null, function* () {
|
|
86
86
|
return new Promise((t) => {
|
|
@@ -118,7 +118,7 @@ const I = (e) => `${s.DOM_ID_PREFIX}${e}`, b = (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 o = typeof e.params == "function" ? e.params() : n(e.params) ? e.params : {}, r = 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) {
|
|
@@ -130,9 +130,9 @@ const I = (e) => `${s.DOM_ID_PREFIX}${e}`, b = (e, t = !1) => {
|
|
|
130
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,
|
|
133
|
+
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
|
+
for (let i of Object.keys(o))
|
|
135
|
+
a.searchParams.set(i, o[i]);
|
|
136
136
|
return w(e.name), a.href;
|
|
137
137
|
}, W = () => {
|
|
138
138
|
const e = document.createElement("div");
|
|
@@ -145,19 +145,19 @@ const I = (e) => `${s.DOM_ID_PREFIX}${e}`, b = (e, t = !1) => {
|
|
|
145
145
|
const t = document.createElement("iframe");
|
|
146
146
|
t.id = I(e.app.name);
|
|
147
147
|
const n = b(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", (
|
|
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", (r) => (t.style.visibility = "visible", e.onLoad.call(e, r))), t.addEventListener(
|
|
149
149
|
"error",
|
|
150
|
-
(
|
|
150
|
+
(r) => e.onError.call(e, r)
|
|
151
151
|
), t.addEventListener(
|
|
152
152
|
"unload",
|
|
153
|
-
(
|
|
153
|
+
(r) => e.onUnload.call(e, r)
|
|
154
154
|
);
|
|
155
|
-
const
|
|
156
|
-
console.log("监听 body 中子节点的变化2", e.panel),
|
|
157
|
-
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")),
|
|
155
|
+
const o = new MutationObserver((r) => {
|
|
156
|
+
console.log("监听 body 中子节点的变化2", e.panel), r.forEach((a) => {
|
|
157
|
+
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")), o.disconnect());
|
|
158
158
|
});
|
|
159
159
|
});
|
|
160
|
-
return
|
|
160
|
+
return o.observe(e.panel.parentNode, {
|
|
161
161
|
childList: !0,
|
|
162
162
|
subtree: !1
|
|
163
163
|
}), t;
|
|
@@ -172,15 +172,15 @@ class G {
|
|
|
172
172
|
return this.app = t, this.dom = void 0, this.panel = void 0, t.preload && this.preload(), this;
|
|
173
173
|
}
|
|
174
174
|
mount(t, n = !1) {
|
|
175
|
-
let
|
|
176
|
-
if (t ? (typeof t == "string" ?
|
|
177
|
-
this.panel =
|
|
178
|
-
let
|
|
179
|
-
|
|
175
|
+
let o;
|
|
176
|
+
if (t ? (typeof t == "string" ? o = document.querySelector(t) : o = t, o.innerHTML = "") : o = document.body, o) {
|
|
177
|
+
this.panel = o;
|
|
178
|
+
let r = document.getElementById(I(this.app.name));
|
|
179
|
+
r || (r = z(this), this.dom = r), n ? r.style.display = "none" : r.style.removeProperty("display");
|
|
180
180
|
const a = W();
|
|
181
181
|
this.loadingTimer = setTimeout(() => {
|
|
182
|
-
this.loading = a,
|
|
183
|
-
}, 1e3),
|
|
182
|
+
this.loading = a, o.appendChild(a);
|
|
183
|
+
}, 1e3), o.appendChild(r);
|
|
184
184
|
} else
|
|
185
185
|
throw new Error("el not found");
|
|
186
186
|
}
|
|
@@ -210,8 +210,8 @@ class G {
|
|
|
210
210
|
reload(t = !1) {
|
|
211
211
|
let n = this.dom.src;
|
|
212
212
|
t && (n = b(this.app, !0), console.log("go home", n)), console.log("reload app", this.app, n);
|
|
213
|
-
const
|
|
214
|
-
|
|
213
|
+
const o = new URL(n);
|
|
214
|
+
o.searchParams.set("__t", Date.now().toString()), this.dom.style.visibility = "hidden", this.dom.src = o.toString();
|
|
215
215
|
}
|
|
216
216
|
changeOptions(t) {
|
|
217
217
|
console.log("changeOptions", this.app, t), this.app = d(d({}, this.app), t);
|
|
@@ -255,12 +255,12 @@ const Q = (e) => {
|
|
|
255
255
|
);
|
|
256
256
|
for (let a of t)
|
|
257
257
|
n.searchParams.delete(a);
|
|
258
|
-
const
|
|
259
|
-
|
|
258
|
+
const o = w(e.data.data.name), r = U(
|
|
259
|
+
o,
|
|
260
260
|
e.data.data.name,
|
|
261
261
|
n.href
|
|
262
262
|
);
|
|
263
|
-
window.history.replaceState(null, "",
|
|
263
|
+
window.history.replaceState(null, "", r);
|
|
264
264
|
} else if (e.data.cmd === "$xt/micro/info") {
|
|
265
265
|
console.debug("parent 「$xt/micro/info」 receive message", e.data);
|
|
266
266
|
const t = g(e.data.data);
|
|
@@ -293,13 +293,13 @@ const Q = (e) => {
|
|
|
293
293
|
});
|
|
294
294
|
}, ce = (...t) => h(void 0, [...t], function* (e = {}) {
|
|
295
295
|
window[s.MICRO_TYPE] = "child";
|
|
296
|
-
const n = f(s.IS_MICRO),
|
|
297
|
-
if (console.debug("child microInit", n,
|
|
296
|
+
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 && P(o).then((r) => {
|
|
298
298
|
window[s.MICRO_APP] = d({
|
|
299
299
|
microVersion: u
|
|
300
|
-
},
|
|
300
|
+
}, r);
|
|
301
301
|
}), window[s.IS_MICRO]) {
|
|
302
|
-
let
|
|
302
|
+
let r = function(c) {
|
|
303
303
|
var i = document.styleSheets[0];
|
|
304
304
|
if (!i) {
|
|
305
305
|
var l = document.createElement("style");
|
|
@@ -308,11 +308,11 @@ const Q = (e) => {
|
|
|
308
308
|
i.insertRule(c, i.cssRules.length);
|
|
309
309
|
};
|
|
310
310
|
window[s.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((c) => {
|
|
311
|
-
|
|
312
|
-
}) :
|
|
311
|
+
r(`${c} { display: none !important; }`);
|
|
312
|
+
}) : r(
|
|
313
313
|
`${e.hideHeaderCssSelector} { display: none !important; }`
|
|
314
|
-
)), yield Z(
|
|
315
|
-
c.data.cmd === `$xt/micro/${
|
|
314
|
+
)), yield Z(o, window), window.addEventListener("message", (c) => h(void 0, null, function* () {
|
|
315
|
+
c.data.cmd === `$xt/micro/${o}` && M(o);
|
|
316
316
|
}));
|
|
317
317
|
const a = f(s.MICRO_TOKEN);
|
|
318
318
|
e.authHandler && a && (yield e.authHandler(a));
|
|
@@ -320,21 +320,21 @@ const Q = (e) => {
|
|
|
320
320
|
console.warn("当前环境非微应用环境");
|
|
321
321
|
});
|
|
322
322
|
function Z(e, t) {
|
|
323
|
-
const n = t.history,
|
|
323
|
+
const n = t.history, o = n.pushState, r = n.replaceState;
|
|
324
324
|
n.pushState = function(a, c, i) {
|
|
325
325
|
const l = y(d(d({}, n.state || {}), a), {
|
|
326
326
|
// 添加新数据
|
|
327
327
|
_patchedByParent: !0
|
|
328
328
|
// 可选:标记这是被父窗口修改的状态
|
|
329
329
|
});
|
|
330
|
-
|
|
330
|
+
o.call(n, l, c, i), M(e);
|
|
331
331
|
}, n.replaceState = function(a, c, i) {
|
|
332
332
|
const l = y(d(d({}, n.state || {}), a), {
|
|
333
333
|
// 添加新数据
|
|
334
334
|
_patchedByParent: !0
|
|
335
335
|
// 可选:标记这是被父窗口修改的状态
|
|
336
336
|
});
|
|
337
|
-
|
|
337
|
+
r.call(n, l, c, i), M(e);
|
|
338
338
|
};
|
|
339
339
|
}
|
|
340
340
|
function M(e) {
|
|
@@ -344,16 +344,16 @@ function M(e) {
|
|
|
344
344
|
microVersion: u
|
|
345
345
|
}, a);
|
|
346
346
|
}));
|
|
347
|
-
const { name: t, sync: n, mainLocation:
|
|
347
|
+
const { name: t, sync: n, mainLocation: o } = window[s.MICRO_APP], r = window.location.pathname + window.location.search + window.location.hash;
|
|
348
348
|
window.parent.postMessage(
|
|
349
349
|
{
|
|
350
350
|
cmd: "$xt/micro/sync",
|
|
351
351
|
data: {
|
|
352
352
|
name: t,
|
|
353
|
-
url: window.encodeURIComponent(
|
|
353
|
+
url: window.encodeURIComponent(r)
|
|
354
354
|
}
|
|
355
355
|
},
|
|
356
|
-
|
|
356
|
+
o.origin
|
|
357
357
|
);
|
|
358
358
|
});
|
|
359
359
|
}
|
|
@@ -371,9 +371,9 @@ const ee = {
|
|
|
371
371
|
return n ? m[e.name] = d(d({}, n), t) : m[e.name] = y(d({}, t), {
|
|
372
372
|
instance: new G(e)
|
|
373
373
|
}), m[e.name];
|
|
374
|
-
}, g = (e) => m[e], te = (e, t) => m[e.name] = d(d({}, e), t), ne = (e, t) => new Promise((n,
|
|
375
|
-
let
|
|
376
|
-
|
|
374
|
+
}, g = (e) => m[e], te = (e, t) => m[e.name] = d(d({}, e), t), ne = (e, t) => new Promise((n, o) => {
|
|
375
|
+
let r = g(e);
|
|
376
|
+
r ? (t && (r.instance.changeOptions(t), r = te(r, t)), r.preload ? r.instance.preloadRender(r.el) : r.instance.mount(r.el), n(r)) : o("app not found, please setup app first");
|
|
377
377
|
}), oe = (e) => {
|
|
378
378
|
let t = g(e);
|
|
379
379
|
t && t.instance.unmount();
|
|
@@ -385,37 +385,35 @@ const ee = {
|
|
|
385
385
|
const t = window.location.href.split("#");
|
|
386
386
|
console.log("url", t);
|
|
387
387
|
const n = new URL(t[0]);
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
t.length > 1 ? n.href + "#" + t[1] : n.href
|
|
392
|
-
), n;
|
|
388
|
+
console.log("mainURL", n), n.searchParams.delete(s.URL_PARAM_PREFIX + e);
|
|
389
|
+
const o = t.length > 1 ? n.href + "#" + t[1] : n.href;
|
|
390
|
+
return window.history.replaceState({}, "", o), o;
|
|
393
391
|
}, re = /* @__PURE__ */ k({
|
|
394
392
|
__name: "XTMicroView",
|
|
395
393
|
props: {
|
|
396
394
|
appId: String
|
|
397
395
|
},
|
|
398
396
|
setup(e) {
|
|
399
|
-
const t = e, n = C(),
|
|
397
|
+
const t = e, n = C(), o = () => {
|
|
400
398
|
t.appId && ne(t.appId, {
|
|
401
399
|
el: n.value,
|
|
402
|
-
onUnload(
|
|
400
|
+
onUnload(r, a) {
|
|
403
401
|
console.log("on unload", a.app.name), w(a.app.name);
|
|
404
402
|
}
|
|
405
|
-
}).then((
|
|
403
|
+
}).then((r) => {
|
|
406
404
|
console.debug("app mounted", t.appId);
|
|
407
405
|
});
|
|
408
406
|
};
|
|
409
|
-
return H(() => t.appId, (
|
|
410
|
-
|
|
407
|
+
return H(() => t.appId, (r, a) => {
|
|
408
|
+
r !== a && a && oe(a), o();
|
|
411
409
|
}), j(() => {
|
|
412
|
-
|
|
410
|
+
o();
|
|
413
411
|
}), N(() => {
|
|
414
412
|
console.debug("「micro」", "app unmount", t.appId), w(t.appId);
|
|
415
|
-
}), (
|
|
413
|
+
}), (r, a) => (V(), B("div", F({
|
|
416
414
|
ref_key: "refPanel",
|
|
417
415
|
ref: n
|
|
418
|
-
},
|
|
416
|
+
}, r.$attrs, { class: "xt-micro" }), null, 16));
|
|
419
417
|
}
|
|
420
418
|
});
|
|
421
419
|
window[s.MICRO_VERSION] = u;
|
package/dist/types/api.d.ts
CHANGED
|
@@ -19,5 +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) =>
|
|
22
|
+
export declare const clearParentUrl: (appName: string) => string;
|
|
23
23
|
export { microInit };
|