@xingtukeji/micro 1.1.12 → 1.1.14

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 CHANGED
@@ -1,35 +1,35 @@
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 v = Object.defineProperty, L = Object.defineProperties;
3
- var T = Object.getOwnPropertyDescriptors;
4
- var M = Object.getOwnPropertySymbols;
5
- var b = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
6
- var y = (e, t, n) => t in e ? v(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, l = (e, t) => {
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
- b.call(t, n) && y(e, n, t[n]);
9
- if (M)
10
- for (var n of M(t))
11
- x.call(t, n) && y(e, n, t[n]);
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
- }, f = (e, t) => L(e, T(t));
14
- var m = (e, t, n) => (y(e, typeof t != "symbol" ? t + "" : t, n), n);
15
- var g = (e, t, n) => new Promise((r, o) => {
16
- var a = (d) => {
13
+ }, _ = (e, t) => T(e, x(t));
14
+ var p = (e, t, n) => (R(e, typeof t != "symbol" ? t + "" : t, n), n);
15
+ var h = (e, t, n) => new Promise((r, o) => {
16
+ var a = (l) => {
17
17
  try {
18
- s(n.next(d));
19
- } catch (h) {
20
- o(h);
18
+ i(n.next(l));
19
+ } catch (w) {
20
+ o(w);
21
21
  }
22
- }, c = (d) => {
22
+ }, c = (l) => {
23
23
  try {
24
- s(n.throw(d));
25
- } catch (h) {
26
- o(h);
24
+ i(n.throw(l));
25
+ } catch (w) {
26
+ o(w);
27
27
  }
28
- }, s = (d) => d.done ? r(d.value) : Promise.resolve(d.value).then(a, c);
29
- s((n = n.apply(e, t)).next());
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 P, defineComponent as $, watch as X, onMounted as k, onUnmounted as H, openBlock as N, createElementBlock as j, mergeProps as B } from "vue";
32
- const i = {
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
+ const s = {
33
33
  KEY: "$xtm",
34
34
  // 父应用注入子应用实例的key
35
35
  IS_MICRO: "__XT_MICRO",
@@ -48,28 +48,28 @@ const i = {
48
48
  // 微应用在 url 参数中的前缀
49
49
  MICRO_VERSION: "__XT_MICRO_VERSION"
50
50
  // 微应用版本
51
- }, u = "1.1.11";
52
- function p(e, t = window.location.href) {
51
+ }, u = "1.1.13";
52
+ function f(e, t = window.location.href) {
53
53
  e = e.replace(/[\[\]]/g, "\\$&");
54
54
  var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"), r = n.exec(t);
55
55
  return r ? r[2] ? decodeURIComponent(r[2].replace(/\+/g, " ")).trim() : "" : null;
56
56
  }
57
- function E(e, t, n) {
57
+ function S(e, t, n) {
58
58
  try {
59
59
  return e && (n && e.startsWith("#") ? e : new URL(e, t).href);
60
60
  } catch (r) {
61
61
  return e;
62
62
  }
63
63
  }
64
- function V(e) {
64
+ 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 F(e) {
68
+ function K(e) {
69
69
  const t = e.search || "";
70
70
  return [...new URLSearchParams(t).entries()].reduce((n, r) => (n[r[0]] = r[1], n), {});
71
71
  }
72
- function K(e, t) {
72
+ function W(e, t) {
73
73
  let n = null;
74
74
  return function(...r) {
75
75
  const o = this;
@@ -78,11 +78,11 @@ function K(e, t) {
78
78
  }, t);
79
79
  };
80
80
  }
81
- function C(e, t, n) {
81
+ function U(e, t, n) {
82
82
  const [r, o] = e.split("#"), a = new URL(r), c = a.searchParams;
83
- return t = i.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();
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 S = (e) => g(void 0, null, function* () {
85
+ const P = (e) => h(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 !== u && console.warn(
@@ -96,17 +96,17 @@ const S = (e) => g(void 0, null, function* () {
96
96
  "*"
97
97
  );
98
98
  });
99
- }), se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
99
+ }), ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
100
100
  __proto__: null,
101
- addOrReplaceUrlParam: C,
102
- anchorElementGenerator: V,
103
- debounce: K,
104
- getAbsolutePath: E,
105
- getAnchorElementQueryMap: F,
106
- getQueryParameter: p,
107
- ipcSyncAppInfo: S
108
- }, Symbol.toStringTag, { value: "Module" })), O = P(!1);
109
- Object.defineProperty(window, i.IS_MICRO, {
101
+ addOrReplaceUrlParam: U,
102
+ anchorElementGenerator: D,
103
+ debounce: W,
104
+ getAbsolutePath: S,
105
+ getAnchorElementQueryMap: K,
106
+ getQueryParameter: f,
107
+ ipcSyncAppInfo: P
108
+ }, Symbol.toStringTag, { value: "Module" })), O = C(!1);
109
+ Object.defineProperty(window, s.IS_MICRO, {
110
110
  get: function() {
111
111
  return O.value;
112
112
  },
@@ -114,38 +114,37 @@ Object.defineProperty(window, i.IS_MICRO, {
114
114
  O.value = e;
115
115
  }
116
116
  });
117
- const I = (e) => `${i.DOM_ID_PREFIX}${e}`, D = (e) => {
118
- function t(s) {
119
- return s !== null && typeof s == "object" && !Array.isArray(s);
117
+ const I = (e) => `${s.DOM_ID_PREFIX}${e}`, L = (e, t = !1) => {
118
+ function n(i) {
119
+ return i !== null && typeof i == "object" && !Array.isArray(i);
120
120
  }
121
- 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(
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
- ), a = p(i.URL_PARAM_PREFIX + e.name);
124
- if (a) {
125
- const s = E(a, e.url, !0);
126
- if (s) {
127
- const d = new URL(s);
128
- d.searchParams.forEach((A, U) => {
129
- o.searchParams.set(U, A);
130
- }), o.hash = d.hash;
123
+ ), c = f(s.URL_PARAM_PREFIX + e.name);
124
+ if (!t && c) {
125
+ const i = S(c, e.url, !0);
126
+ if (i) {
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 (o.searchParams.set(i.IS_MICRO, !0 + ""), o.searchParams.set(i.MICRO_NAME, e.name), r && o.searchParams.set(i.MICRO_TOKEN, r), n)
134
- for (let s of Object.keys(n))
135
- o.searchParams.set(s, n[s]);
136
- const c = new URL(window.location.href);
137
- return c.searchParams.delete(e.name), window.history.replaceState({}, "", c.href), o.href;
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 g(e.name), a.href;
138
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
- }, W = (e) => {
140
+ }, q = (e) => {
142
141
  e.style.opacity = "0", setTimeout(() => {
143
142
  e.remove();
144
143
  }, 500);
145
- }, q = (e) => {
144
+ }, z = (e) => {
146
145
  const t = document.createElement("iframe");
147
146
  t.id = I(e.app.name);
148
- const n = D(e.app);
147
+ const n = L(e.app);
149
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)
@@ -154,19 +153,22 @@ const I = (e) => `${i.DOM_ID_PREFIX}${e}`, D = (e) => {
154
153
  (o) => e.onUnload.call(e, o)
155
154
  );
156
155
  const r = new MutationObserver((o) => {
157
- o.forEach((a) => {
156
+ console.log("监听 body 中子节点的变化2", e.panel), o.forEach((a) => {
158
157
  Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")), r.disconnect());
159
158
  });
160
159
  });
161
- return r.observe(e.panel, { childList: !0 }), t;
160
+ return r.observe(e.panel.parentNode, {
161
+ childList: !0,
162
+ subtree: !1
163
+ }), t;
162
164
  };
163
- class z {
165
+ class G {
164
166
  constructor(t) {
165
- m(this, "app");
166
- m(this, "dom");
167
- m(this, "panel");
168
- m(this, "loading");
169
- m(this, "loadingTimer");
167
+ p(this, "app");
168
+ p(this, "dom");
169
+ p(this, "panel");
170
+ p(this, "loading");
171
+ p(this, "loadingTimer");
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) {
@@ -174,7 +176,7 @@ class z {
174
176
  if (t ? (typeof t == "string" ? r = document.querySelector(t) : r = t, r.innerHTML = "") : r = document.body, r) {
175
177
  this.panel = r;
176
178
  let o = document.getElementById(I(this.app.name));
177
- o || (o = q(this), this.dom = o), n ? o.style.display = "none" : o.style.removeProperty("display");
179
+ o || (o = z(this), this.dom = o), n ? o.style.display = "none" : o.style.removeProperty("display");
178
180
  const a = Y();
179
181
  this.loadingTimer = setTimeout(() => {
180
182
  this.loading = a, r.appendChild(a);
@@ -184,6 +186,7 @@ class z {
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);
@@ -204,24 +207,26 @@ class z {
204
207
  preload() {
205
208
  this.mount(void 0, !0);
206
209
  }
207
- reload() {
208
- const t = this.dom.src;
209
- this.dom.src = t;
210
+ reload(t = !1) {
211
+ let n = this.dom.src;
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.src = r.toString();
210
215
  }
211
216
  changeOptions(t) {
212
- this.app = l(l({}, this.app), t);
217
+ console.log("changeOptions", this.app, t), this.app = d(d({}, this.app), t);
213
218
  }
214
219
  onLoad(t) {
215
- console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && W(this.loading), G(this), this.app.onLoad && this.app.onLoad(t, this);
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);
216
221
  }
217
222
  onUnload(t) {
218
- console.debug("app onUnload", this.app.name), this.app.onUnload && this.app.onUnload(t, this);
223
+ console.debug("app onUnload", this.app.name), g(this.app.name), this.app.onUnload && this.app.onUnload(t, this);
219
224
  }
220
225
  onError(t) {
221
226
  console.error("app onError", this.app.name), this.app.onError && this.app.onError(t, this);
222
227
  }
223
228
  }
224
- const G = (e) => {
229
+ const Q = (e) => {
225
230
  var t, n;
226
231
  (n = (t = e.dom) == null ? void 0 : t.contentWindow) == null || n.postMessage(
227
232
  {
@@ -236,13 +241,14 @@ const G = (e) => {
236
241
  },
237
242
  "*"
238
243
  );
239
- }, Q = () => {
240
- window[i.MICRO_TYPE] = "parent", window.addEventListener("message", (e) => {
244
+ }, J = () => {
245
+ window[s.MICRO_TYPE] = "parent", window.addEventListener("message", (e) => {
241
246
  if (e.data.cmd === "$xt/micro/sync") {
247
+ console.log("父页面接受子应用同步路由信息", e.data);
242
248
  const t = [
243
- i.IS_MICRO,
244
- i.MICRO_NAME,
245
- i.MICRO_TOKEN
249
+ s.IS_MICRO,
250
+ s.MICRO_NAME,
251
+ s.MICRO_TOKEN
246
252
  ], n = new URL(
247
253
  window.decodeURIComponent(e.data.data.url),
248
254
  e.origin
@@ -251,9 +257,9 @@ const G = (e) => {
251
257
  n.searchParams.delete(a);
252
258
  const r = new URL(window.location.href);
253
259
  r.searchParams.forEach((a, c) => {
254
- c.startsWith(i.URL_PARAM_PREFIX) && r.searchParams.delete(c);
260
+ c.startsWith(s.URL_PARAM_PREFIX) && r.searchParams.delete(c);
255
261
  });
256
- const o = C(
262
+ const o = U(
257
263
  r.href,
258
264
  e.data.data.name,
259
265
  n.href
@@ -261,7 +267,7 @@ const G = (e) => {
261
267
  window.history.replaceState(null, "", o);
262
268
  } else if (e.data.cmd === "$xt/micro/info") {
263
269
  console.debug("parent 「$xt/micro/info」 receive message", e.data);
264
- const t = _(e.data.data);
270
+ const t = y(e.data.data);
265
271
  e.source.postMessage(
266
272
  {
267
273
  cmd: "$xt/micro/info",
@@ -289,129 +295,148 @@ const G = (e) => {
289
295
  );
290
296
  }
291
297
  });
292
- }, ie = (...t) => g(void 0, [...t], function* (e = {}) {
293
- window[i.MICRO_TYPE] = "child";
294
- const n = p(i.IS_MICRO), r = p(i.MICRO_NAME);
295
- if (console.debug("child microInit", n, r), n && (window[i.IS_MICRO] = n === "true"), r && S(r).then((o) => {
296
- window[i.MICRO_APP] = l({
298
+ }, ce = (...t) => h(void 0, [...t], function* (e = {}) {
299
+ window[s.MICRO_TYPE] = "child";
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) => {
302
+ window[s.MICRO_APP] = d({
297
303
  microVersion: u
298
304
  }, o);
299
- }), window[i.IS_MICRO]) {
305
+ }), window[s.IS_MICRO]) {
300
306
  let o = function(c) {
301
- var s = document.styleSheets[0];
302
- if (!s) {
303
- var d = document.createElement("style");
304
- document.head.appendChild(d), s = d.sheet;
307
+ var i = document.styleSheets[0];
308
+ if (!i) {
309
+ var l = document.createElement("style");
310
+ document.head.appendChild(l), i = l.sheet;
305
311
  }
306
- s.insertRule(c, s.cssRules.length);
312
+ i.insertRule(c, i.cssRules.length);
307
313
  };
308
- window[i.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((c) => {
314
+ window[s.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((c) => {
309
315
  o(`${c} { display: none !important; }`);
310
316
  }) : o(
311
317
  `${e.hideHeaderCssSelector} { display: none !important; }`
312
- )), window.addEventListener("message", (c) => {
313
- c.data.cmd === `$xt/micro/${r}` && R();
314
- }), J(window);
315
- const a = p(i.MICRO_TOKEN);
318
+ )), yield Z(r, window), window.addEventListener("message", (c) => h(void 0, null, function* () {
319
+ c.data.cmd === `$xt/micro/${r}` && M(r);
320
+ }));
321
+ const a = f(s.MICRO_TOKEN);
316
322
  e.authHandler && a && (yield e.authHandler(a));
317
323
  } else
318
324
  console.warn("当前环境非微应用环境");
319
325
  });
320
- function J(e) {
321
- const t = e.history, n = t.pushState, r = t.replaceState;
322
- t.pushState = function(o, a, c) {
323
- const s = f(l(l({}, t.state || {}), o), {
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), {
324
330
  // 添加新数据
325
331
  _patchedByParent: !0
326
332
  // 可选:标记这是被父窗口修改的状态
327
333
  });
328
- n.call(t, s, a, c), R();
329
- }, t.replaceState = function(o, a, c) {
330
- const s = f(l(l({}, t.state || {}), o), {
334
+ r.call(n, l, c, i), M(e);
335
+ }, n.replaceState = function(a, c, i) {
336
+ const l = _(d(d({}, n.state || {}), a), {
331
337
  // 添加新数据
332
338
  _patchedByParent: !0
333
339
  // 可选:标记这是被父窗口修改的状态
334
340
  });
335
- r.call(t, s, a, c), R();
341
+ o.call(n, l, c, i), M(e);
336
342
  };
337
343
  }
338
- function R() {
339
- if (!window[i.MICRO_APP])
340
- return;
341
- const { name: e, sync: t, mainBaseURL: n } = window[i.MICRO_APP], r = window.location.pathname + window.location.search + window.location.hash;
342
- window.parent.postMessage(
343
- {
344
- cmd: "$xt/micro/sync",
345
- data: {
346
- name: e,
347
- url: window.encodeURIComponent(r)
348
- }
349
- },
350
- n
351
- );
344
+ function M(e) {
345
+ return h(this, null, function* () {
346
+ console.log("syncUrlToWindow", e, window[s.MICRO_APP]), window[s.MICRO_APP] || (yield P(e).then((a) => {
347
+ window[s.MICRO_APP] = d({
348
+ microVersion: u
349
+ }, a);
350
+ }));
351
+ const { name: t, sync: n, mainLocation: r } = window[s.MICRO_APP], o = window.location.pathname + window.location.search + window.location.hash;
352
+ window.parent.postMessage(
353
+ {
354
+ cmd: "$xt/micro/sync",
355
+ data: {
356
+ name: t,
357
+ url: window.encodeURIComponent(o)
358
+ }
359
+ },
360
+ r.origin
361
+ );
362
+ });
352
363
  }
353
- let w = {};
354
- const Z = {
364
+ let m = {};
365
+ const ee = {
355
366
  url: "",
356
367
  name: "",
357
368
  sync: !0
358
- }, ce = (e) => {
369
+ }, le = (e) => {
359
370
  if (!e.url || e.url === "" || e.url === "undefined") {
360
371
  console.error("app url is required", e);
361
372
  return;
362
373
  }
363
- const t = Object.assign({}, Z, e);
364
- return w[e.name] = f(l({}, t), {
365
- instance: new z(e)
366
- }), w[e.name];
367
- }, _ = (e) => w[e], ee = (e, t) => w[e.name] = l(l({}, e), t), te = (e, t) => new Promise((n, r) => {
368
- let o = _(e);
369
- 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");
370
- }), ne = (e) => {
371
- let t = _(e);
374
+ const t = Object.assign({}, ee, e), n = m[e.name];
375
+ return n ? m[e.name] = d(d({}, n), t) : m[e.name] = _(d({}, t), {
376
+ instance: new G(e)
377
+ }), m[e.name];
378
+ }, y = (e) => m[e], te = (e, t) => m[e.name] = d(d({}, e), t), ne = (e, t) => new Promise((n, r) => {
379
+ let o = y(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 = y(e);
372
383
  t && t.instance.unmount();
373
- }, de = (e) => {
374
- let t = _(e);
375
- t && t.instance.reload();
376
- }, oe = /* @__PURE__ */ $({
384
+ }, de = (e, t = !1) => {
385
+ let n = y(e);
386
+ n && n.instance.reload(t);
387
+ }, g = (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({
377
398
  __name: "XTMicroView",
378
399
  props: {
379
400
  appId: String
380
401
  },
381
402
  setup(e) {
382
- const t = e, n = P(), r = () => {
383
- t.appId && te(t.appId, {
384
- el: n.value
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), g(a.app.name);
408
+ }
385
409
  }).then((o) => {
386
410
  console.debug("app mounted", t.appId);
387
411
  });
388
412
  };
389
- return X(() => t.appId, (o, a) => {
390
- o !== a && a && ne(a), r();
391
- }), k(() => {
413
+ return H(() => t.appId, (o, a) => {
414
+ o !== a && a && oe(a), r();
415
+ }), j(() => {
392
416
  r();
393
- }), H(() => {
394
- console.debug("app unmount", t.appId);
395
- }), (o, a) => (N(), j("div", B({
417
+ }), F(() => {
418
+ console.debug("「micro」", "app unmount", t.appId), g(t.appId);
419
+ }), (o, a) => (N(), V("div", B({
396
420
  ref_key: "refPanel",
397
421
  ref: n
398
422
  }, o.$attrs, { class: "xt-micro" }), null, 16));
399
423
  }
400
424
  });
401
- window[i.MICRO_VERSION] = u;
402
- const le = {
425
+ window[s.MICRO_VERSION] = u;
426
+ const pe = {
403
427
  install: (e, t = {}) => {
404
- e.component("xt-micro-view", oe), Q();
428
+ e.component("xt-micro-view", re), J();
405
429
  }
406
430
  };
407
431
  export {
408
- oe as XTMicroView,
409
- le as default,
410
- _ as getApp,
411
- ie as microInit,
432
+ re as XTMicroView,
433
+ g as clearParentUrl,
434
+ pe as default,
435
+ y as getApp,
436
+ ce as microInit,
412
437
  de as reloadApp,
413
- ce as setupApp,
414
- te as startApp,
415
- ne as stopApp,
416
- se as utils
438
+ le as setupApp,
439
+ ne as startApp,
440
+ oe as stopApp,
441
+ ie as utils
417
442
  };
@@ -4,7 +4,7 @@ import { microInit } from './child';
4
4
  * 安装微应用
5
5
  * @param app
6
6
  */
7
- export declare const setupApp: (app: AppOption) => App | undefined;
7
+ export declare const setupApp: (AppOption: AppOption) => App | undefined;
8
8
  export declare const getApp: (name: string) => App;
9
9
  /**
10
10
  * 启动微应用
@@ -18,5 +18,6 @@ export declare const startApp: (name: string, options?: Partial<AppOption>) => P
18
18
  * @param {string} name - 应用程序的名称
19
19
  */
20
20
  export declare const stopApp: (name: string) => void;
21
- export declare const reloadApp: (name: string) => void;
21
+ export declare const reloadApp: (name: string, isGoHome?: boolean) => void;
22
+ export declare const clearParentUrl: (appName: string) => void;
22
23
  export { microInit };
@@ -9,7 +9,7 @@ export declare const microInit: (options?: MicroInitOptions) => Promise<void>;
9
9
  /**
10
10
  * 同步子应用路由到主应用路由
11
11
  */
12
- export declare function syncUrlToWindow(): void;
12
+ export declare function syncUrlToWindow(microName: string): Promise<void>;
13
13
  /**
14
14
  * 同步主应用路由到子应用
15
15
  */
@@ -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
- }, any>;
7
+ }, HTMLDivElement>;
8
8
  export default _default;
@@ -19,7 +19,7 @@ export declare class MicroApp {
19
19
  * 预加载app,先放到body,待启动时,挪过来
20
20
  */
21
21
  preload(): void;
22
- reload(): void;
22
+ reload(isGoHome?: boolean): void;
23
23
  changeOptions(options: Partial<AppOption>): void;
24
24
  onLoad(_event: Event): void;
25
25
  onUnload(_event: Event): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xingtukeji/micro",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "main": "dist/index.js",