@xingtukeji/micro 1.1.10 → 1.1.11
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 +54 -44
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var L = Object.defineProperty, v = Object.defineProperties;
|
|
|
3
3
|
var b = Object.getOwnPropertyDescriptors;
|
|
4
4
|
var M = Object.getOwnPropertySymbols;
|
|
5
5
|
var T = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
|
|
6
|
-
var _ = (e, t, n) => t in e ? L(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n,
|
|
6
|
+
var _ = (e, t, n) => t in e ? L(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
8
|
T.call(t, n) && _(e, n, t[n]);
|
|
9
9
|
if (M)
|
|
@@ -12,23 +12,23 @@ var _ = (e, t, n) => t in e ? L(e, t, { enumerable: !0, configurable: !0, writab
|
|
|
12
12
|
return e;
|
|
13
13
|
}, f = (e, t) => v(e, b(t));
|
|
14
14
|
var m = (e, t, n) => (_(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
15
|
-
var
|
|
16
|
-
var a = (
|
|
15
|
+
var g = (e, t, n) => new Promise((r, o) => {
|
|
16
|
+
var a = (l) => {
|
|
17
17
|
try {
|
|
18
|
-
i(n.next(
|
|
18
|
+
i(n.next(l));
|
|
19
19
|
} catch (h) {
|
|
20
20
|
o(h);
|
|
21
21
|
}
|
|
22
|
-
}, s = (
|
|
22
|
+
}, s = (l) => {
|
|
23
23
|
try {
|
|
24
|
-
i(n.throw(
|
|
24
|
+
i(n.throw(l));
|
|
25
25
|
} catch (h) {
|
|
26
26
|
o(h);
|
|
27
27
|
}
|
|
28
|
-
}, i = (
|
|
28
|
+
}, i = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(a, s);
|
|
29
29
|
i((n = n.apply(e, t)).next());
|
|
30
30
|
});
|
|
31
|
-
import { ref as P, defineComponent as $, watch as X, onMounted as k, onUnmounted as H, openBlock as N, createElementBlock as
|
|
31
|
+
import { ref as P, defineComponent as $, watch as X, onMounted as k, onUnmounted as H, openBlock as N, createElementBlock as j, mergeProps as B } from "vue";
|
|
32
32
|
const c = {
|
|
33
33
|
KEY: "$xtm",
|
|
34
34
|
// 父应用注入子应用实例的key
|
|
@@ -46,8 +46,8 @@ const c = {
|
|
|
46
46
|
// 微应用在 url 参数中的前缀
|
|
47
47
|
MICRO_VERSION: "__XT_MICRO_VERSION"
|
|
48
48
|
// 微应用版本
|
|
49
|
-
},
|
|
50
|
-
function
|
|
49
|
+
}, u = "1.1.11";
|
|
50
|
+
function p(e, t = window.location.href) {
|
|
51
51
|
e = e.replace(/[\[\]]/g, "\\$&");
|
|
52
52
|
var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"), r = n.exec(t);
|
|
53
53
|
return r ? r[2] ? decodeURIComponent(r[2].replace(/\+/g, " ")).trim() : "" : null;
|
|
@@ -80,11 +80,11 @@ function C(e, t, n) {
|
|
|
80
80
|
const [r, o] = e.split("#"), a = new URL(r), s = a.searchParams;
|
|
81
81
|
return t = c.URL_PARAM_PREFIX + t, s.has(t) ? s.set(t, n) : s.append(t, n), o && (a.hash = o), a.search = s.toString(), a.toString();
|
|
82
82
|
}
|
|
83
|
-
const S = (e) =>
|
|
83
|
+
const S = (e) => g(void 0, null, function* () {
|
|
84
84
|
return new Promise((t) => {
|
|
85
85
|
window.addEventListener("message", (n) => {
|
|
86
|
-
n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !==
|
|
87
|
-
`子应用版本与主应用版本不一致,${e}子应用版本:${
|
|
86
|
+
n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !== u && console.warn(
|
|
87
|
+
`子应用版本与主应用版本不一致,${e}子应用版本:${u},主应用版本:${n.data.data.mainMicroVersion}`
|
|
88
88
|
), t(n.data.data));
|
|
89
89
|
}), window.parent.postMessage(
|
|
90
90
|
{
|
|
@@ -101,7 +101,7 @@ const S = (e) => R(void 0, null, function* () {
|
|
|
101
101
|
debounce: K,
|
|
102
102
|
getAbsolutePath: E,
|
|
103
103
|
getAnchorElementQueryMap: F,
|
|
104
|
-
getQueryParameter:
|
|
104
|
+
getQueryParameter: p,
|
|
105
105
|
ipcSyncAppInfo: S
|
|
106
106
|
}, Symbol.toStringTag, { value: "Module" })), O = P(!1);
|
|
107
107
|
Object.defineProperty(window, c.IS_MICRO, {
|
|
@@ -112,20 +112,20 @@ Object.defineProperty(window, c.IS_MICRO, {
|
|
|
112
112
|
O.value = e;
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
|
-
const
|
|
115
|
+
const R = (e) => `${c.DOM_ID_PREFIX}${e}`, D = (e) => {
|
|
116
116
|
function t(i) {
|
|
117
117
|
return i !== null && typeof i == "object" && !Array.isArray(i);
|
|
118
118
|
}
|
|
119
119
|
const n = typeof e.params == "function" ? e.params() : t(e.params) ? e.params : {}, r = typeof e.token == "function" ? e.token() : t(e.token) ? e.token : "", o = new URL(
|
|
120
120
|
e.url.indexOf("http") > -1 ? e.url : window.location.origin + e.url
|
|
121
|
-
), a =
|
|
121
|
+
), a = p(c.URL_PARAM_PREFIX + e.name);
|
|
122
122
|
if (a) {
|
|
123
123
|
const i = E(a, e.url, !0);
|
|
124
124
|
if (i) {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
o.searchParams.set(
|
|
128
|
-
}), o.hash =
|
|
125
|
+
const l = new URL(i);
|
|
126
|
+
l.searchParams.forEach((A, U) => {
|
|
127
|
+
o.searchParams.set(U, A);
|
|
128
|
+
}), o.hash = l.hash;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
if (o.searchParams.set(c.IS_MICRO, !0 + ""), o.searchParams.set(c.MICRO_NAME, e.name), r && o.searchParams.set(c.MICRO_TOKEN, r), n)
|
|
@@ -142,9 +142,9 @@ const g = (e) => `${c.DOM_ID_PREFIX}${e}`, D = (e) => {
|
|
|
142
142
|
}, 500);
|
|
143
143
|
}, z = (e) => {
|
|
144
144
|
const t = document.createElement("iframe");
|
|
145
|
-
t.id =
|
|
145
|
+
t.id = R(e.app.name);
|
|
146
146
|
const n = D(e.app);
|
|
147
|
-
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"] = "
|
|
147
|
+
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(
|
|
148
148
|
"error",
|
|
149
149
|
(o) => e.onError.call(e, o)
|
|
150
150
|
), t.addEventListener(
|
|
@@ -171,7 +171,7 @@ class G {
|
|
|
171
171
|
let r;
|
|
172
172
|
if (t ? (typeof t == "string" ? r = document.querySelector(t) : r = t, r.innerHTML = "") : r = document.body, r) {
|
|
173
173
|
this.panel = r;
|
|
174
|
-
let o = document.getElementById(
|
|
174
|
+
let o = document.getElementById(R(this.app.name));
|
|
175
175
|
o || (o = z(this), this.dom = o), n ? o.style.display = "none" : o.style.removeProperty("display");
|
|
176
176
|
const a = W();
|
|
177
177
|
this.loadingTimer = setTimeout(() => {
|
|
@@ -182,7 +182,7 @@ class G {
|
|
|
182
182
|
}
|
|
183
183
|
unmount() {
|
|
184
184
|
var n;
|
|
185
|
-
const t = document.getElementById(
|
|
185
|
+
const t = document.getElementById(R(this.app.name));
|
|
186
186
|
if (t)
|
|
187
187
|
this.app.preload ? (t.style.display = "none", document.body.appendChild(t)) : (n = this.panel) == null || n.removeChild(t);
|
|
188
188
|
else
|
|
@@ -207,7 +207,7 @@ class G {
|
|
|
207
207
|
this.dom.src = t;
|
|
208
208
|
}
|
|
209
209
|
changeOptions(t) {
|
|
210
|
-
this.app =
|
|
210
|
+
this.app = d(d({}, this.app), t);
|
|
211
211
|
}
|
|
212
212
|
onLoad(t) {
|
|
213
213
|
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);
|
|
@@ -263,8 +263,18 @@ const Q = (e) => {
|
|
|
263
263
|
{
|
|
264
264
|
cmd: "$xt/micro/info",
|
|
265
265
|
data: {
|
|
266
|
-
|
|
267
|
-
|
|
266
|
+
mainLocation: {
|
|
267
|
+
origin: window.location.origin,
|
|
268
|
+
href: window.location.href,
|
|
269
|
+
pathname: window.location.pathname,
|
|
270
|
+
search: window.location.search,
|
|
271
|
+
hash: window.location.hash,
|
|
272
|
+
host: window.location.host,
|
|
273
|
+
hostname: window.location.hostname,
|
|
274
|
+
port: window.location.port,
|
|
275
|
+
protocol: window.location.protocol
|
|
276
|
+
},
|
|
277
|
+
mainMicroVersion: u,
|
|
268
278
|
name: t.name,
|
|
269
279
|
url: t.url,
|
|
270
280
|
params: t.params,
|
|
@@ -276,18 +286,18 @@ const Q = (e) => {
|
|
|
276
286
|
);
|
|
277
287
|
}
|
|
278
288
|
});
|
|
279
|
-
}, ie = (...t) =>
|
|
280
|
-
const n =
|
|
289
|
+
}, ie = (...t) => g(void 0, [...t], function* (e = {}) {
|
|
290
|
+
const n = p(c.IS_MICRO), r = p(c.MICRO_NAME);
|
|
281
291
|
n && (window[c.IS_MICRO] = !0), r && S(r).then((s) => {
|
|
282
|
-
window[c.MICRO_APP] =
|
|
283
|
-
microVersion:
|
|
292
|
+
window[c.MICRO_APP] = d({
|
|
293
|
+
microVersion: u
|
|
284
294
|
}, s);
|
|
285
295
|
});
|
|
286
296
|
function o(s) {
|
|
287
297
|
var i = document.styleSheets[0];
|
|
288
298
|
if (!i) {
|
|
289
|
-
var
|
|
290
|
-
document.head.appendChild(
|
|
299
|
+
var l = document.createElement("style");
|
|
300
|
+
document.head.appendChild(l), i = l.sheet;
|
|
291
301
|
}
|
|
292
302
|
i.insertRule(s, i.cssRules.length);
|
|
293
303
|
}
|
|
@@ -298,20 +308,20 @@ const Q = (e) => {
|
|
|
298
308
|
)), window.addEventListener("message", (s) => {
|
|
299
309
|
s.data.cmd === `$xt/micro/${r}` && I();
|
|
300
310
|
}), J(window);
|
|
301
|
-
const a =
|
|
311
|
+
const a = p(c.MICRO_TOKEN);
|
|
302
312
|
e.authHandler && a && (yield e.authHandler(a));
|
|
303
313
|
});
|
|
304
314
|
function J(e) {
|
|
305
315
|
const t = e.history, n = t.pushState, r = t.replaceState;
|
|
306
316
|
t.pushState = function(o, a, s) {
|
|
307
|
-
const i = f(
|
|
317
|
+
const i = f(d(d({}, t.state || {}), o), {
|
|
308
318
|
// 添加新数据
|
|
309
319
|
_patchedByParent: !0
|
|
310
320
|
// 可选:标记这是被父窗口修改的状态
|
|
311
321
|
});
|
|
312
322
|
n.call(t, i, a, s), I();
|
|
313
323
|
}, t.replaceState = function(o, a, s) {
|
|
314
|
-
const i = f(
|
|
324
|
+
const i = f(d(d({}, t.state || {}), o), {
|
|
315
325
|
// 添加新数据
|
|
316
326
|
_patchedByParent: !0
|
|
317
327
|
// 可选:标记这是被父窗口修改的状态
|
|
@@ -345,16 +355,16 @@ const Z = {
|
|
|
345
355
|
return;
|
|
346
356
|
}
|
|
347
357
|
const t = Object.assign({}, Z, e);
|
|
348
|
-
return w[e.name] = f(
|
|
358
|
+
return w[e.name] = f(d({}, t), {
|
|
349
359
|
instance: new G(e)
|
|
350
360
|
}), w[e.name];
|
|
351
|
-
}, y = (e) => w[e], ee = (e, t) => w[e.name] =
|
|
361
|
+
}, y = (e) => w[e], ee = (e, t) => w[e.name] = d(d({}, e), t), te = (e, t) => new Promise((n, r) => {
|
|
352
362
|
let o = y(e);
|
|
353
363
|
o ? (t && (o.instance.changeOptions(t), o = ee(o, t)), o.preload ? o.instance.preloadRender(o.el) : o.instance.mount(o.el), n(o)) : r("app not found");
|
|
354
364
|
}), ne = (e) => {
|
|
355
365
|
let t = y(e);
|
|
356
366
|
t && t.instance.unmount();
|
|
357
|
-
},
|
|
367
|
+
}, le = (e) => {
|
|
358
368
|
let t = y(e);
|
|
359
369
|
t && t.instance.reload();
|
|
360
370
|
}, oe = /* @__PURE__ */ $({
|
|
@@ -376,24 +386,24 @@ const Z = {
|
|
|
376
386
|
r();
|
|
377
387
|
}), H(() => {
|
|
378
388
|
console.debug("app unmount", t.appId);
|
|
379
|
-
}), (o, a) => (N(),
|
|
389
|
+
}), (o, a) => (N(), j("div", B({
|
|
380
390
|
ref_key: "refPanel",
|
|
381
391
|
ref: n
|
|
382
392
|
}, o.$attrs, { class: "xt-micro" }), null, 16));
|
|
383
393
|
}
|
|
384
394
|
});
|
|
385
|
-
window[c.MICRO_VERSION] =
|
|
386
|
-
const
|
|
395
|
+
window[c.MICRO_VERSION] = u;
|
|
396
|
+
const de = {
|
|
387
397
|
install: (e, t = {}) => {
|
|
388
398
|
e.component("xt-micro-view", oe), Y();
|
|
389
399
|
}
|
|
390
400
|
};
|
|
391
401
|
export {
|
|
392
402
|
oe as XTMicroView,
|
|
393
|
-
|
|
403
|
+
de as default,
|
|
394
404
|
y as getApp,
|
|
395
405
|
ie as microInit,
|
|
396
|
-
|
|
406
|
+
le as reloadApp,
|
|
397
407
|
ce as setupApp,
|
|
398
408
|
te as startApp,
|
|
399
409
|
ne as stopApp,
|