@xingtukeji/micro 1.1.6 → 1.1.7
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 +49 -49
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,32 +3,32 @@ var U = Object.defineProperty, A = Object.defineProperties;
|
|
|
3
3
|
var L = Object.getOwnPropertyDescriptors;
|
|
4
4
|
var g = Object.getOwnPropertySymbols;
|
|
5
5
|
var T = Object.prototype.hasOwnProperty, b = Object.prototype.propertyIsEnumerable;
|
|
6
|
-
var
|
|
6
|
+
var y = (e, t, n) => t in e ? U(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
|
-
T.call(t, n) &&
|
|
8
|
+
T.call(t, n) && y(e, n, t[n]);
|
|
9
9
|
if (g)
|
|
10
10
|
for (var n of g(t))
|
|
11
|
-
b.call(t, n) &&
|
|
11
|
+
b.call(t, n) && y(e, n, t[n]);
|
|
12
12
|
return e;
|
|
13
13
|
}, m = (e, t) => A(e, L(t));
|
|
14
|
-
var u = (e, t, n) => (
|
|
14
|
+
var u = (e, t, n) => (y(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
15
15
|
var I = (e, t, n) => new Promise((r, o) => {
|
|
16
|
-
var
|
|
16
|
+
var a = (l) => {
|
|
17
17
|
try {
|
|
18
18
|
i(n.next(l));
|
|
19
19
|
} catch (h) {
|
|
20
20
|
o(h);
|
|
21
21
|
}
|
|
22
|
-
},
|
|
22
|
+
}, s = (l) => {
|
|
23
23
|
try {
|
|
24
24
|
i(n.throw(l));
|
|
25
25
|
} catch (h) {
|
|
26
26
|
o(h);
|
|
27
27
|
}
|
|
28
|
-
}, i = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(
|
|
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 v, watch as x, onMounted as
|
|
31
|
+
import { ref as P, defineComponent as v, watch as x, onMounted as k, onUnmounted as X, openBlock as $, createElementBlock as H, mergeProps as N } from "vue";
|
|
32
32
|
const c = {
|
|
33
33
|
KEY: "$xtm",
|
|
34
34
|
// 父应用注入子应用实例的key
|
|
@@ -75,8 +75,8 @@ function F(e, t) {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
function E(e, t, n) {
|
|
78
|
-
const [r, o] = e.split("#"),
|
|
79
|
-
return t = c.URL_PARAM_PREFIX + t,
|
|
78
|
+
const [r, o] = e.split("#"), a = new URL(r), s = a.searchParams;
|
|
79
|
+
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();
|
|
80
80
|
}
|
|
81
81
|
const re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
82
82
|
__proto__: null,
|
|
@@ -95,15 +95,15 @@ Object.defineProperty(window, c.IS_MICRO, {
|
|
|
95
95
|
M.value = e;
|
|
96
96
|
}
|
|
97
97
|
});
|
|
98
|
-
const
|
|
98
|
+
const w = (e) => `${c.DOM_ID_PREFIX}${e}`, K = (e) => {
|
|
99
99
|
function t(i) {
|
|
100
100
|
return i !== null && typeof i == "object" && !Array.isArray(i);
|
|
101
101
|
}
|
|
102
102
|
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(
|
|
103
103
|
e.url.indexOf("http") > -1 ? e.url : window.location.origin + e.url
|
|
104
|
-
),
|
|
105
|
-
if (
|
|
106
|
-
const i = O(
|
|
104
|
+
), a = p(c.URL_PARAM_PREFIX + e.name);
|
|
105
|
+
if (a) {
|
|
106
|
+
const i = O(a, e.url, !0);
|
|
107
107
|
if (i) {
|
|
108
108
|
const l = new URL(i);
|
|
109
109
|
l.searchParams.forEach((C, S) => {
|
|
@@ -114,8 +114,8 @@ const y = (e) => `${c.DOM_ID_PREFIX}${e}`, K = (e) => {
|
|
|
114
114
|
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)
|
|
115
115
|
for (let i of Object.keys(n))
|
|
116
116
|
o.searchParams.set(i, n[i]);
|
|
117
|
-
const
|
|
118
|
-
return
|
|
117
|
+
const s = new URL(window.location.href);
|
|
118
|
+
return s.searchParams.delete(e.name), window.history.replaceState({}, "", s.href), o.href;
|
|
119
119
|
}, D = () => {
|
|
120
120
|
const e = document.createElement("div");
|
|
121
121
|
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;
|
|
@@ -125,9 +125,9 @@ const y = (e) => `${c.DOM_ID_PREFIX}${e}`, K = (e) => {
|
|
|
125
125
|
}, 500);
|
|
126
126
|
}, q = (e) => {
|
|
127
127
|
const t = document.createElement("iframe");
|
|
128
|
-
t.id =
|
|
128
|
+
t.id = w(e.app.name);
|
|
129
129
|
const n = K(e.app);
|
|
130
|
-
t.src = n, t.style.width = "100%", t.style.height = "100%", t.style.border = "none", t.style.margin = "0", t.style.padding = "0", t.addEventListener(
|
|
130
|
+
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.addEventListener(
|
|
131
131
|
"load",
|
|
132
132
|
(o) => e.onLoad.call(e, o)
|
|
133
133
|
), t.addEventListener(
|
|
@@ -138,8 +138,8 @@ const y = (e) => `${c.DOM_ID_PREFIX}${e}`, K = (e) => {
|
|
|
138
138
|
(o) => e.onUnload.call(e, o)
|
|
139
139
|
);
|
|
140
140
|
const r = new MutationObserver((o) => {
|
|
141
|
-
o.forEach((
|
|
142
|
-
Array.from(
|
|
141
|
+
o.forEach((a) => {
|
|
142
|
+
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")), r.disconnect());
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
145
|
return r.observe(e.panel, { childList: !0 }), t;
|
|
@@ -157,18 +157,18 @@ class z {
|
|
|
157
157
|
let r;
|
|
158
158
|
if (t ? (typeof t == "string" ? r = document.querySelector(t) : r = t, r.innerHTML = "") : r = document.body, r) {
|
|
159
159
|
this.panel = r;
|
|
160
|
-
let o = document.getElementById(
|
|
160
|
+
let o = document.getElementById(w(this.app.name));
|
|
161
161
|
o || (o = q(this), this.dom = o), n ? o.style.display = "none" : o.style.removeProperty("display");
|
|
162
|
-
const
|
|
162
|
+
const a = D();
|
|
163
163
|
this.loadingTimer = setTimeout(() => {
|
|
164
|
-
this.loading =
|
|
164
|
+
this.loading = a, r.appendChild(a);
|
|
165
165
|
}, 1e3), r.appendChild(o);
|
|
166
166
|
} else
|
|
167
167
|
throw new Error("el not found");
|
|
168
168
|
}
|
|
169
169
|
unmount() {
|
|
170
170
|
var n;
|
|
171
|
-
const t = document.getElementById(
|
|
171
|
+
const t = document.getElementById(w(this.app.name));
|
|
172
172
|
if (t)
|
|
173
173
|
this.app.preload ? (t.style.display = "none", document.body.appendChild(t)) : (n = this.panel) == null || n.removeChild(t);
|
|
174
174
|
else
|
|
@@ -231,11 +231,11 @@ const G = (e) => {
|
|
|
231
231
|
window.decodeURIComponent(e.data.data.url),
|
|
232
232
|
e.origin
|
|
233
233
|
);
|
|
234
|
-
for (let
|
|
235
|
-
n.searchParams.delete(
|
|
234
|
+
for (let a of t)
|
|
235
|
+
n.searchParams.delete(a);
|
|
236
236
|
const r = new URL(window.location.href);
|
|
237
|
-
r.searchParams.forEach((
|
|
238
|
-
|
|
237
|
+
r.searchParams.forEach((a, s) => {
|
|
238
|
+
s.startsWith(c.URL_PARAM_PREFIX) && r.searchParams.delete(s);
|
|
239
239
|
});
|
|
240
240
|
const o = E(
|
|
241
241
|
r.href,
|
|
@@ -245,41 +245,41 @@ const G = (e) => {
|
|
|
245
245
|
window.history.replaceState(null, "", o);
|
|
246
246
|
}
|
|
247
247
|
});
|
|
248
|
-
},
|
|
248
|
+
}, ae = (...t) => I(void 0, [...t], function* (e = {}) {
|
|
249
249
|
const n = p(c.IS_MICRO), r = p(c.MICRO_NAME);
|
|
250
250
|
n && (window[c.IS_MICRO] = !0);
|
|
251
|
-
function o(
|
|
251
|
+
function o(s) {
|
|
252
252
|
var i = document.styleSheets[0];
|
|
253
253
|
if (!i) {
|
|
254
254
|
var l = document.createElement("style");
|
|
255
255
|
document.head.appendChild(l), i = l.sheet;
|
|
256
256
|
}
|
|
257
|
-
i.insertRule(
|
|
257
|
+
i.insertRule(s, i.cssRules.length);
|
|
258
258
|
}
|
|
259
|
-
window[c.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((
|
|
260
|
-
o(`${
|
|
261
|
-
}) : o(`${e.hideHeaderCssSelector} { display: none !important; }`)), window.addEventListener("message", (
|
|
262
|
-
|
|
259
|
+
window[c.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((s) => {
|
|
260
|
+
o(`${s} { display: none !important; }`);
|
|
261
|
+
}) : o(`${e.hideHeaderCssSelector} { display: none !important; }`)), window.addEventListener("message", (s) => {
|
|
262
|
+
s.data.cmd === `$xt/micro/${r}` && (window[c.MICRO_APP] = m(d({}, s.data.data), { mainBaseURL: s.origin }), _());
|
|
263
263
|
}), Y(window);
|
|
264
|
-
const
|
|
265
|
-
e.authHandler &&
|
|
264
|
+
const a = p(c.MICRO_TOKEN);
|
|
265
|
+
e.authHandler && a && (yield e.authHandler(a));
|
|
266
266
|
});
|
|
267
267
|
function Y(e) {
|
|
268
268
|
const t = e.history, n = t.pushState, r = t.replaceState;
|
|
269
|
-
t.pushState = function(o,
|
|
269
|
+
t.pushState = function(o, a, s) {
|
|
270
270
|
const i = m(d(d({}, t.state || {}), o), {
|
|
271
271
|
// 添加新数据
|
|
272
272
|
_patchedByParent: !0
|
|
273
273
|
// 可选:标记这是被父窗口修改的状态
|
|
274
274
|
});
|
|
275
|
-
n.call(t, i,
|
|
276
|
-
}, t.replaceState = function(o,
|
|
275
|
+
n.call(t, i, a, s), _();
|
|
276
|
+
}, t.replaceState = function(o, a, s) {
|
|
277
277
|
const i = m(d(d({}, t.state || {}), o), {
|
|
278
278
|
// 添加新数据
|
|
279
279
|
_patchedByParent: !0
|
|
280
280
|
// 可选:标记这是被父窗口修改的状态
|
|
281
281
|
});
|
|
282
|
-
r.call(t, i,
|
|
282
|
+
r.call(t, i, a, s), _();
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
285
|
function _() {
|
|
@@ -299,7 +299,7 @@ const J = {
|
|
|
299
299
|
url: "",
|
|
300
300
|
name: "",
|
|
301
301
|
sync: !0
|
|
302
|
-
},
|
|
302
|
+
}, se = (e) => {
|
|
303
303
|
if (!e.url || e.url === "" || e.url === "undefined") {
|
|
304
304
|
console.error("app url is required", e);
|
|
305
305
|
return;
|
|
@@ -330,13 +330,13 @@ const J = {
|
|
|
330
330
|
console.debug("app mounted", t.appId);
|
|
331
331
|
});
|
|
332
332
|
};
|
|
333
|
-
return x(() => t.appId, (o,
|
|
334
|
-
o !==
|
|
335
|
-
}),
|
|
333
|
+
return x(() => t.appId, (o, a) => {
|
|
334
|
+
o !== a && a && ee(a), r();
|
|
335
|
+
}), k(() => {
|
|
336
336
|
r();
|
|
337
|
-
}),
|
|
337
|
+
}), X(() => {
|
|
338
338
|
console.debug("app unmount", t.appId);
|
|
339
|
-
}), (o,
|
|
339
|
+
}), (o, a) => ($(), H("div", N({
|
|
340
340
|
ref_key: "refPanel",
|
|
341
341
|
ref: n
|
|
342
342
|
}, o.$attrs, { class: "xt-micro" }), null, 16));
|
|
@@ -351,9 +351,9 @@ export {
|
|
|
351
351
|
te as XTMicroView,
|
|
352
352
|
ce as default,
|
|
353
353
|
R as getApp,
|
|
354
|
-
|
|
354
|
+
ae as microInit,
|
|
355
355
|
ie as reloadApp,
|
|
356
|
-
|
|
356
|
+
se as setupApp,
|
|
357
357
|
Z as startApp,
|
|
358
358
|
ee as stopApp,
|
|
359
359
|
re as utils
|