@xingtukeji/micro 1.1.16 → 1.1.18

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,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 T = Object.defineProperty, A = 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 ? T(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, d = (e, t) => {
2
+ var x = Object.defineProperty, X = Object.defineProperties;
3
+ var k = Object.getOwnPropertyDescriptors;
4
+ var M = Object.getOwnPropertySymbols;
5
+ var H = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable;
6
+ var R = (e, t, n) => t in e ? x(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
- $.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]);
8
+ H.call(t, n) && R(e, n, t[n]);
9
+ if (M)
10
+ for (var n of M(t))
11
+ j.call(t, n) && R(e, n, t[n]);
12
12
  return e;
13
- }, y = (e, t) => A(e, x(t));
13
+ }, y = (e, t) => X(e, k(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((r, o) => {
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
- } catch (_) {
20
- o(_);
19
+ } catch (g) {
20
+ r(g);
21
21
  }
22
22
  }, c = (l) => {
23
23
  try {
24
24
  i(n.throw(l));
25
- } catch (_) {
26
- o(_);
25
+ } catch (g) {
26
+ r(g);
27
27
  }
28
- }, i = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(a, c);
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
- 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";
31
+ import { ref as O, defineComponent as N, watch as F, onMounted as B, onUnmounted as V, openBlock as D, createElementBlock as K, mergeProps as Y } from "vue";
32
32
  const s = {
33
33
  KEY: "$xtm",
34
34
  // 父应用注入子应用实例的key
@@ -48,45 +48,45 @@ const s = {
48
48
  // 微应用在 url 参数中的前缀
49
49
  MICRO_VERSION: "__XT_MICRO_VERSION"
50
50
  // 微应用版本
51
- }, u = "1.1.16";
51
+ }, w = "1.1.17";
52
52
  function f(e, t = window.location.href) {
53
53
  e = e.replace(/[\[\]]/g, "\\$&");
54
- var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"), r = n.exec(t);
55
- return r ? r[2] ? decodeURIComponent(r[2].replace(/\+/g, " ")).trim() : "" : null;
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
- function S(e, t, n) {
57
+ function E(e, t, n) {
58
58
  try {
59
59
  return e && (n && e.startsWith("#") ? e : new URL(e, t).href);
60
- } catch (r) {
60
+ } catch (o) {
61
61
  return e;
62
62
  }
63
63
  }
64
- function D(e) {
64
+ function W(e) {
65
65
  const t = window.document.createElement("a");
66
66
  return t.href = e, t.href = t.href, t;
67
67
  }
68
- function K(e) {
68
+ function z(e) {
69
69
  const t = e.search || "";
70
- return [...new URLSearchParams(t).entries()].reduce((n, r) => (n[r[0]] = r[1], n), {});
70
+ return [...new URLSearchParams(t).entries()].reduce((n, o) => (n[o[0]] = o[1], n), {});
71
71
  }
72
- function Y(e, t) {
72
+ function q(e, t) {
73
73
  let n = null;
74
- return function(...r) {
75
- const o = this;
74
+ return function(...o) {
75
+ const r = this;
76
76
  n && clearTimeout(n), n = setTimeout(() => {
77
- e.apply(o, r);
77
+ e.apply(r, o);
78
78
  }, t);
79
79
  };
80
80
  }
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();
81
+ function C(e, 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(), console.trace("urlObj", a), a.origin + a.pathname + a.search + a.hash;
84
84
  }
85
- const P = (e) => h(void 0, null, function* () {
85
+ const S = (e) => h(void 0, null, function* () {
86
86
  return new Promise((t) => {
87
87
  window.addEventListener("message", (n) => {
88
- console.debug("child ipcSyncAppInfo receive message", n.data), n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !== u && console.warn(
89
- `子应用版本与主应用版本不一致,${e}子应用版本:${u},主应用版本:${n.data.data.mainMicroVersion}`
88
+ console.debug("child ipcSyncAppInfo receive message", n.data), n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !== w && console.warn(
89
+ `子应用版本与主应用版本不一致,${e}子应用版本:${w},主应用版本:${n.data.data.mainMicroVersion}`
90
90
  ), t(n.data.data));
91
91
  }), console.debug("child ipcSyncAppInfo send message", e), window.parent.postMessage(
92
92
  {
@@ -96,73 +96,74 @@ const P = (e) => h(void 0, null, function* () {
96
96
  "*"
97
97
  );
98
98
  });
99
- }), ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
99
+ }), he = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
100
100
  __proto__: null,
101
- addOrReplaceUrlParam: U,
102
- anchorElementGenerator: D,
103
- debounce: Y,
104
- getAbsolutePath: S,
105
- getAnchorElementQueryMap: K,
101
+ addOrReplaceUrlParam: C,
102
+ anchorElementGenerator: W,
103
+ debounce: q,
104
+ getAbsolutePath: E,
105
+ getAnchorElementQueryMap: z,
106
106
  getQueryParameter: f,
107
- ipcSyncAppInfo: P
108
- }, Symbol.toStringTag, { value: "Module" })), O = C(!1);
107
+ ipcSyncAppInfo: S
108
+ }, Symbol.toStringTag, { value: "Module" })), P = O(!1);
109
109
  Object.defineProperty(window, s.IS_MICRO, {
110
110
  get: function() {
111
- return O.value;
111
+ return P.value;
112
112
  },
113
113
  set: function(e) {
114
- O.value = e;
114
+ P.value = e;
115
115
  }
116
116
  });
117
- const I = (e) => `${s.DOM_ID_PREFIX}${e}`, b = (e, t = !1) => {
117
+ const I = (e) => `${s.DOM_ID_PREFIX}${e}`, U = (e, t = !1) => {
118
118
  function n(i) {
119
119
  return i !== null && typeof i == "object" && !Array.isArray(i);
120
120
  }
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(
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) {
125
- const i = S(c, e.url, !0);
125
+ const i = E(c, e.url, !0);
126
126
  if (i) {
127
- const l = new URL(i);
128
- l.searchParams.forEach((v, L) => {
129
- a.searchParams.set(L, v);
127
+ const l = new URL(i, e.url);
128
+ l.searchParams.forEach((A, $) => {
129
+ a.searchParams.set($, A);
130
130
  }), a.hash = l.hash;
131
131
  }
132
+ m(e.name);
132
133
  }
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 w(e.name), a.href;
137
- }, W = () => {
134
+ 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)
135
+ for (let i of Object.keys(o))
136
+ a.searchParams.set(i, o[i]);
137
+ return m(e.name), a.href;
138
+ }, G = () => {
138
139
  const e = document.createElement("div");
139
140
  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;
140
- }, q = (e) => {
141
+ }, Q = (e) => {
141
142
  e.style.opacity = "0", setTimeout(() => {
142
143
  e.remove();
143
144
  }, 500);
144
- }, z = (e) => {
145
+ }, J = (e) => {
145
146
  const t = document.createElement("iframe");
146
147
  t.id = I(e.app.name);
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", (o) => (t.style.visibility = "visible", e.onLoad.call(e, o))), t.addEventListener(
148
+ const n = U(e.app);
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", (r) => (t.style.visibility = "visible", e.onLoad.call(e, r))), t.addEventListener(
149
150
  "error",
150
- (o) => e.onError.call(e, o)
151
+ (r) => e.onError.call(e, r)
151
152
  ), t.addEventListener(
152
153
  "unload",
153
- (o) => e.onUnload.call(e, o)
154
+ (r) => e.onUnload.call(e, r)
154
155
  );
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());
156
+ const o = new MutationObserver((r) => {
157
+ console.log("监听 body 中子节点的变化2", e.panel), r.forEach((a) => {
158
+ Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")), o.disconnect());
158
159
  });
159
160
  });
160
- return r.observe(e.panel.parentNode, {
161
+ return o.observe(e.panel.parentNode, {
161
162
  childList: !0,
162
163
  subtree: !1
163
164
  }), t;
164
165
  };
165
- class G {
166
+ class Z {
166
167
  constructor(t) {
167
168
  p(this, "app");
168
169
  p(this, "dom");
@@ -172,15 +173,15 @@ class G {
172
173
  return this.app = t, this.dom = void 0, this.panel = void 0, t.preload && this.preload(), this;
173
174
  }
174
175
  mount(t, n = !1) {
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 = W();
176
+ let o;
177
+ if (t ? (typeof t == "string" ? o = document.querySelector(t) : o = t, o.innerHTML = "") : o = document.body, o) {
178
+ this.panel = o;
179
+ let r = document.getElementById(I(this.app.name));
180
+ r || (r = J(this), this.dom = r), n ? r.style.display = "none" : r.style.removeProperty("display");
181
+ const a = G();
181
182
  this.loadingTimer = setTimeout(() => {
182
- this.loading = a, r.appendChild(a);
183
- }, 1e3), r.appendChild(o);
183
+ this.loading = a, o.appendChild(a);
184
+ }, 1e3), o.appendChild(r);
184
185
  } else
185
186
  throw new Error("el not found");
186
187
  }
@@ -209,24 +210,24 @@ class G {
209
210
  }
210
211
  reload(t = !1) {
211
212
  let n = this.dom.src;
212
- t && (n = b(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();
213
+ t && (n = U(this.app, !0), console.log("go home", n)), console.log("reload app", this.app, n);
214
+ const o = new URL(n);
215
+ o.searchParams.set("__t", Date.now().toString()), this.dom.style.visibility = "hidden", this.dom.src = o.toString();
215
216
  }
216
217
  changeOptions(t) {
217
218
  console.log("changeOptions", this.app, t), this.app = d(d({}, this.app), t);
218
219
  }
219
220
  onLoad(t) {
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);
221
+ console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && Q(this.loading), ee(this), console.log("this.app.onLoad", this.app.onLoad), this.app.onLoad && this.app.onLoad(t, this);
221
222
  }
222
223
  onUnload(t) {
223
- console.debug("app onUnload", this.app.name), w(this.app.name), this.app.onUnload && this.app.onUnload(t, this);
224
+ console.debug("app onUnload", this.app.name), m(this.app.name), this.app.onUnload && this.app.onUnload(t, this);
224
225
  }
225
226
  onError(t) {
226
227
  console.error("app onError", this.app.name), this.app.onError && this.app.onError(t, this);
227
228
  }
228
229
  }
229
- const Q = (e) => {
230
+ const ee = (e) => {
230
231
  var t, n;
231
232
  (n = (t = e.dom) == null ? void 0 : t.contentWindow) == null || n.postMessage(
232
233
  {
@@ -241,7 +242,7 @@ const Q = (e) => {
241
242
  },
242
243
  "*"
243
244
  );
244
- }, J = () => {
245
+ }, te = () => {
245
246
  window[s.MICRO_TYPE] = "parent", window.addEventListener("message", (e) => {
246
247
  if (e.data.cmd === "$xt/micro/sync") {
247
248
  console.log("父页面接受子应用同步路由信息", e.data);
@@ -253,17 +254,23 @@ const Q = (e) => {
253
254
  window.decodeURIComponent(e.data.data.url),
254
255
  e.origin
255
256
  );
256
- for (let a of t)
257
- n.searchParams.delete(a);
258
- const r = w(e.data.data.name), o = U(
257
+ for (let c of t)
258
+ n.searchParams.delete(c);
259
+ console.log("tempUrl", n);
260
+ const o = m(e.data.data.name), r = new URL(o);
261
+ r.searchParams.forEach((c, i) => {
262
+ i.startsWith(s.URL_PARAM_PREFIX) && r.searchParams.delete(i);
263
+ }), console.log("mainURL.href", r.href);
264
+ const a = C(
259
265
  r.href,
260
266
  e.data.data.name,
261
267
  n.href
268
+ // tempUrl.pathname + tempUrl.search + tempUrl.hash
262
269
  );
263
- window.history.replaceState(null, "", o);
270
+ console.log("curUrl", a), window.history.replaceState(null, "", a);
264
271
  } else if (e.data.cmd === "$xt/micro/info") {
265
272
  console.debug("parent 「$xt/micro/info」 receive message", e.data);
266
- const t = g(e.data.data);
273
+ const t = _(e.data.data);
267
274
  e.source.postMessage(
268
275
  {
269
276
  cmd: "$xt/micro/info",
@@ -279,7 +286,7 @@ const Q = (e) => {
279
286
  port: window.location.port,
280
287
  protocol: window.location.protocol
281
288
  },
282
- mainMicroVersion: u,
289
+ mainMicroVersion: w,
283
290
  name: t.name,
284
291
  url: t.url,
285
292
  params: t.params,
@@ -291,15 +298,15 @@ const Q = (e) => {
291
298
  );
292
299
  }
293
300
  });
294
- }, ce = (...t) => h(void 0, [...t], function* (e = {}) {
301
+ }, ne = (...t) => h(void 0, [...t], function* (e = {}) {
295
302
  window[s.MICRO_TYPE] = "child";
296
- const n = f(s.IS_MICRO), r = f(s.MICRO_NAME);
297
- if (console.debug("child microInit", n, r), n && (window[s.IS_MICRO] = n === "true"), r && P(r).then((o) => {
303
+ const n = f(s.IS_MICRO), o = f(s.MICRO_NAME);
304
+ if (console.debug("child microInit", n, o), n && (window[s.IS_MICRO] = n === "true"), o && S(o).then((r) => {
298
305
  window[s.MICRO_APP] = d({
299
- microVersion: u
300
- }, o);
306
+ microVersion: w
307
+ }, r);
301
308
  }), window[s.IS_MICRO]) {
302
- let o = function(c) {
309
+ let r = function(c) {
303
310
  var i = document.styleSheets[0];
304
311
  if (!i) {
305
312
  var l = document.createElement("style");
@@ -308,131 +315,151 @@ const Q = (e) => {
308
315
  i.insertRule(c, i.cssRules.length);
309
316
  };
310
317
  window[s.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((c) => {
311
- o(`${c} { display: none !important; }`);
312
- }) : o(
318
+ r(`${c} { display: none !important; }`);
319
+ }) : r(
313
320
  `${e.hideHeaderCssSelector} { display: none !important; }`
314
- )), yield Z(r, window), window.addEventListener("message", (c) => h(void 0, null, function* () {
315
- c.data.cmd === `$xt/micro/${r}` && M(r);
321
+ )), yield oe(o, window), window.addEventListener("message", (c) => h(void 0, null, function* () {
322
+ c.data.cmd === `$xt/micro/${o}` && L(o);
316
323
  }));
317
324
  const a = f(s.MICRO_TOKEN);
318
325
  e.authHandler && a && (yield e.authHandler(a));
319
326
  } else
320
327
  console.warn("当前环境非微应用环境");
321
328
  });
322
- function Z(e, t) {
323
- const n = t.history, r = n.pushState, o = n.replaceState;
329
+ function oe(e, t) {
330
+ const n = t.history, o = n.pushState, r = n.replaceState;
324
331
  n.pushState = function(a, c, i) {
325
332
  const l = y(d(d({}, n.state || {}), a), {
326
333
  // 添加新数据
327
334
  _patchedByParent: !0
328
335
  // 可选:标记这是被父窗口修改的状态
329
336
  });
330
- r.call(n, l, c, i), M(e);
337
+ o.call(n, l, c, i), L(e);
331
338
  }, n.replaceState = function(a, c, i) {
332
339
  const l = y(d(d({}, n.state || {}), a), {
333
340
  // 添加新数据
334
341
  _patchedByParent: !0
335
342
  // 可选:标记这是被父窗口修改的状态
336
343
  });
337
- o.call(n, l, c, i), M(e);
344
+ r.call(n, l, c, i);
338
345
  };
339
346
  }
340
- function M(e) {
347
+ function L(e) {
341
348
  return h(this, null, function* () {
342
- console.log("syncUrlToWindow", e, window[s.MICRO_APP]), window[s.MICRO_APP] || (yield P(e).then((a) => {
343
- window[s.MICRO_APP] = d({
344
- microVersion: u
345
- }, a);
346
- }));
347
- const { name: t, sync: n, mainLocation: r } = window[s.MICRO_APP], o = window.location.pathname + window.location.search + window.location.hash;
348
- window.parent.postMessage(
349
+ if (console.log("syncUrlToWindow", e, window[s.MICRO_APP]), !window[s.MICRO_APP])
350
+ return;
351
+ const { name: t, sync: n, mainLocation: o } = window[s.MICRO_APP], r = window.location.pathname + window.location.search + window.location.hash;
352
+ console.log("curUrl", r), window.parent.postMessage(
349
353
  {
350
354
  cmd: "$xt/micro/sync",
351
355
  data: {
352
356
  name: t,
353
- url: window.encodeURIComponent(o)
357
+ url: window.encodeURIComponent(r)
354
358
  }
355
359
  },
356
- r.origin
360
+ o.origin
357
361
  );
358
362
  });
359
363
  }
360
- let m = {};
361
- const ee = {
364
+ let u = {};
365
+ const re = {
362
366
  url: "",
363
367
  name: "",
364
368
  sync: !0
365
- }, le = (e) => {
369
+ }, ae = (e) => {
366
370
  if (!e.url || e.url === "" || e.url === "undefined") {
367
371
  console.error("app url is required", e);
368
372
  return;
369
373
  }
370
- const t = Object.assign({}, ee, e), n = m[e.name];
371
- return n ? m[e.name] = d(d({}, n), t) : m[e.name] = y(d({}, t), {
372
- instance: new G(e)
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, r) => {
375
- let o = g(e);
376
- 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");
377
- }), oe = (e) => {
378
- let t = g(e);
374
+ const t = Object.assign({}, re, e), n = u[e.name];
375
+ return n ? u[e.name] = d(d({}, n), t) : u[e.name] = y(d({}, t), {
376
+ instance: new Z(e)
377
+ }), u[e.name];
378
+ }, _ = (e) => u[e], se = (e, t) => u[e.name] = d(d({}, e), t), b = (e, t) => new Promise((n, o) => {
379
+ let r = _(e);
380
+ r ? (t && (r.instance.changeOptions(t), r = se(r, t)), r.preload ? r.instance.preloadRender(r.el) : r.instance.mount(r.el), n(r)) : o("app not found, please setup app first");
381
+ }), T = (e) => {
382
+ let t = _(e);
379
383
  t && t.instance.unmount();
380
- }, de = (e, t = !1) => {
381
- let n = g(e);
384
+ }, ie = (e, t = !1) => {
385
+ let n = _(e);
382
386
  n && n.instance.reload(t);
383
- }, w = (e) => {
387
+ }, m = (e) => {
384
388
  console.log("clearParentUrl", e, s.URL_PARAM_PREFIX + e);
385
389
  const t = window.location.href.split("#");
386
390
  console.log("url", t);
387
- const n = new URL(t[0]);
388
- return console.log("mainURL", n), n.searchParams.delete(s.URL_PARAM_PREFIX + e), window.history.replaceState(
389
- {},
390
- "",
391
- t.length > 1 ? n.href + "#" + t[1] : n.href
392
- ), n;
393
- }, re = /* @__PURE__ */ k({
391
+ let n = new URL(t[0]);
392
+ n.searchParams.delete(s.URL_PARAM_PREFIX + e);
393
+ const o = t.length > 1 ? n.href + "#" + t[1] : n.href;
394
+ return window.history.replaceState({}, "", o), o;
395
+ }, v = () => window[s.IS_MICRO] === !0, ce = () => window[s.MICRO_TYPE] === "parent", le = (e, t = ((n) => (n = window.__XT_MICRO_APP) == null ? void 0 : n.name)()) => {
396
+ let o = window.location;
397
+ if (v())
398
+ o = window.__XT_MICRO_APP.mainLocation;
399
+ else if (!t) {
400
+ console.error("在主应用中需要传入应用名称");
401
+ return;
402
+ }
403
+ return `${o.origin}${o.pathname}?__XT_MICRO_${t}=${encodeURIComponent(e)}${o.hash}`;
404
+ }, de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
405
+ __proto__: null,
406
+ clearParentUrl: m,
407
+ createAppUrl: le,
408
+ getApp: _,
409
+ isMicro: v,
410
+ isParent: ce,
411
+ microInit: ne,
412
+ reloadApp: ie,
413
+ setupApp: ae,
414
+ startApp: b,
415
+ stopApp: T
416
+ }, Symbol.toStringTag, { value: "Module" })), me = /* @__PURE__ */ N({
394
417
  __name: "XTMicroView",
395
418
  props: {
396
419
  appId: String
397
420
  },
398
421
  setup(e) {
399
- const t = e, n = C(), r = () => {
400
- t.appId && ne(t.appId, {
422
+ const t = e, n = O(), o = () => {
423
+ t.appId && b(t.appId, {
401
424
  el: n.value,
402
- onUnload(o, a) {
403
- console.log("on unload", a.app.name), w(a.app.name);
425
+ onUnload(r, a) {
426
+ console.log("on unload", a.app.name), m(a.app.name);
404
427
  }
405
- }).then((o) => {
428
+ }).then((r) => {
406
429
  console.debug("app mounted", t.appId);
407
430
  });
408
431
  };
409
- return H(() => t.appId, (o, a) => {
410
- o !== a && a && oe(a), r();
411
- }), j(() => {
412
- r();
413
- }), N(() => {
414
- console.debug("「micro」", "app unmount", t.appId), w(t.appId);
415
- }), (o, a) => (V(), B("div", F({
432
+ return F(() => t.appId, (r, a) => {
433
+ r !== a && a && T(a), o();
434
+ }), B(() => {
435
+ o();
436
+ }), V(() => {
437
+ console.debug("「micro」", "app unmount", t.appId), m(t.appId);
438
+ }), (r, a) => (D(), K("div", Y({
416
439
  ref_key: "refPanel",
417
440
  ref: n
418
- }, o.$attrs, { class: "xt-micro" }), null, 16));
441
+ }, r.$attrs, { class: "xt-micro" }), null, 16));
419
442
  }
420
443
  });
421
- window[s.MICRO_VERSION] = u;
422
- const pe = {
444
+ window[s.MICRO_VERSION] = w;
445
+ window.api = de;
446
+ const fe = {
423
447
  install: (e, t = {}) => {
424
- e.component("xt-micro-view", re), J();
448
+ e.component("xt-micro-view", me), te();
425
449
  }
426
450
  };
427
451
  export {
428
- re as XTMicroView,
429
- w as clearParentUrl,
430
- pe as default,
431
- g as getApp,
432
- ce as microInit,
433
- de as reloadApp,
434
- le as setupApp,
435
- ne as startApp,
436
- oe as stopApp,
437
- ie as utils
452
+ me as XTMicroView,
453
+ m as clearParentUrl,
454
+ le as createAppUrl,
455
+ fe as default,
456
+ _ as getApp,
457
+ v as isMicro,
458
+ ce as isParent,
459
+ ne as microInit,
460
+ ie as reloadApp,
461
+ ae as setupApp,
462
+ b as startApp,
463
+ T as stopApp,
464
+ he as utils
438
465
  };
@@ -19,5 +19,14 @@ 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) => URL;
22
+ export declare const clearParentUrl: (appName: string) => string;
23
+ export declare const isMicro: () => boolean;
24
+ export declare const isParent: () => boolean;
25
+ /**
26
+ * 创建基于主应用路由的某个子应用的 url
27
+ * @param appName 应用名称
28
+ * @param targetUrlHash 应用地址
29
+ * @returns
30
+ */
31
+ export declare const createAppUrl: (targetUrlHash: string, appName?: string) => string;
23
32
  export { microInit };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@xingtukeji/micro",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "private": false,
5
5
  "description": "",
6
- "main": "dist/index.js",
6
+ "main": "src/index.ts",
7
7
  "types": "dist/types/index.d.ts",
8
8
  "files": [
9
9
  "dist"
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { App } from "vue";
2
+ import XTMicroView from "./components/XTMicroView.vue";
3
+
4
+ import { mainMicroInit } from "./parent";
5
+ export * from "./api";
6
+ import * as utils from "./utils";
7
+
8
+ export { XTMicroView, utils };
9
+ import { version } from "../package.json";
10
+ import { CONSTANT } from "./types";
11
+ window[CONSTANT.MICRO_VERSION] = version;
12
+ //temp test
13
+ import * as api from "./api";
14
+ window["api"] = api;
15
+
16
+ export default {
17
+ install: (app: App, _options: any = {}) => {
18
+ app.component("xt-micro-view", XTMicroView);
19
+ mainMicroInit();
20
+ },
21
+ };