@xingtukeji/micro 1.1.20 → 1.1.21

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,13 +1,13 @@
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
2
  var $ = Object.defineProperty, x = Object.defineProperties;
3
3
  var X = Object.getOwnPropertyDescriptors;
4
- var E = Object.getOwnPropertySymbols;
4
+ var O = Object.getOwnPropertySymbols;
5
5
  var k = Object.prototype.hasOwnProperty, H = Object.prototype.propertyIsEnumerable;
6
6
  var M = (t, e, n) => e in t ? $(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, m = (t, e) => {
7
7
  for (var n in e || (e = {}))
8
8
  k.call(e, n) && M(t, n, e[n]);
9
- if (E)
10
- for (var n of E(e))
9
+ if (O)
10
+ for (var n of O(e))
11
11
  H.call(e, n) && M(t, n, e[n]);
12
12
  return t;
13
13
  }, R = (t, e) => x(t, X(e));
@@ -15,21 +15,21 @@ var h = (t, e, n) => (M(t, typeof e != "symbol" ? e + "" : e, n), n);
15
15
  var w = (t, e, n) => new Promise((o, r) => {
16
16
  var a = (d) => {
17
17
  try {
18
- s(n.next(d));
18
+ c(n.next(d));
19
19
  } catch (y) {
20
20
  r(y);
21
21
  }
22
22
  }, l = (d) => {
23
23
  try {
24
- s(n.throw(d));
24
+ c(n.throw(d));
25
25
  } catch (y) {
26
26
  r(y);
27
27
  }
28
- }, s = (d) => d.done ? o(d.value) : Promise.resolve(d.value).then(a, l);
29
- s((n = n.apply(t, e)).next());
28
+ }, c = (d) => d.done ? o(d.value) : Promise.resolve(d.value).then(a, l);
29
+ c((n = n.apply(t, e)).next());
30
30
  });
31
- import { ref as C, defineComponent as j, watch as F, onMounted as K, onUnmounted as N, openBlock as Y, createElementBlock as B, mergeProps as V } from "vue";
32
- const c = {
31
+ import { ref as b, defineComponent as j, watch as F, onMounted as K, onUnmounted as Y, 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,13 +48,13 @@ const c = {
48
48
  // 微应用在 url 参数中的前缀
49
49
  MICRO_VERSION: "__XT_MICRO_VERSION"
50
50
  // 微应用版本
51
- }, _ = "1.1.20";
52
- function g(t, e = window.location.href) {
51
+ }, f = "1.1.21";
52
+ function _(t, e = window.location.href) {
53
53
  t = t.replace(/[\[\]]/g, "\\$&");
54
54
  var n = new RegExp("[?&]" + t + "(=([^&#]*)|&|#|$)"), o = n.exec(e);
55
55
  return o ? o[2] ? decodeURIComponent(o[2].replace(/\+/g, " ")).trim() : "" : null;
56
56
  }
57
- function b(t, e, n) {
57
+ function S(t, e, n) {
58
58
  try {
59
59
  return t && (n && t.startsWith("#") ? t : new URL(t, e).href);
60
60
  } catch (o) {
@@ -78,15 +78,15 @@ function W(t, e) {
78
78
  }, e);
79
79
  };
80
80
  }
81
- function S(t, e, n) {
81
+ function U(t, e, n) {
82
82
  const [o, r] = t.split("#"), a = new URL(o), l = a.searchParams;
83
- return e = c.URL_PARAM_PREFIX + e, l.has(e) ? l.set(e, n) : l.append(e, n), r && (a.hash = r), a.search = l.toString(), i.trace("urlObj", a), a.origin + a.pathname + a.search + a.hash;
83
+ return e = s.URL_PARAM_PREFIX + e, l.has(e) ? l.set(e, n) : l.append(e, n), r && (a.hash = r), a.search = l.toString(), i.trace("urlObj", a), a.origin + a.pathname + a.search + a.hash;
84
84
  }
85
- const U = (t) => w(void 0, null, function* () {
85
+ const E = (t) => w(void 0, null, function* () {
86
86
  return new Promise((e) => {
87
87
  window.addEventListener("message", (n) => {
88
- i.debug("child ipcSyncAppInfo receive message", n.data), n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !== _ && i.warn(
89
- `子应用版本与主应用版本不一致,${t}子应用版本:${_},主应用版本:${n.data.data.mainMicroVersion}`
88
+ i.debug("child ipcSyncAppInfo receive message", n.data), n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !== f && i.warn(
89
+ `子应用版本与主应用版本不一致,${t}子应用版本:${f},主应用版本:${n.data.data.mainMicroVersion}`
90
90
  ), e(n.data.data));
91
91
  }), i.debug("child ipcSyncAppInfo send message", t), window.parent.postMessage(
92
92
  {
@@ -131,8 +131,8 @@ const U = (t) => w(void 0, null, function* () {
131
131
  return "unknown location";
132
132
  const r = o[0].trim(), a = r.match(/(?:http[s]?:\/\/.*?\/|)([^:]+):(\d+):(\d+)/);
133
133
  if (a) {
134
- const [, l, s] = a;
135
- return `[${l.split("/").slice(-2).join("/")}:${s}]`;
134
+ const [, l, c] = a;
135
+ return `[${l.split("/").slice(-2).join("/")}:${c}]`;
136
136
  }
137
137
  return `[${r}]`;
138
138
  } catch (e) {
@@ -185,43 +185,43 @@ let i = u;
185
185
  const de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
186
186
  __proto__: null,
187
187
  ConsoleUtil: i,
188
- addOrReplaceUrlParam: S,
188
+ addOrReplaceUrlParam: U,
189
189
  anchorElementGenerator: D,
190
190
  debounce: W,
191
- getAbsolutePath: b,
191
+ getAbsolutePath: S,
192
192
  getAnchorElementQueryMap: G,
193
- getQueryParameter: g,
194
- ipcSyncAppInfo: U
195
- }, Symbol.toStringTag, { value: "Module" })), O = C(!1);
196
- Object.defineProperty(window, c.IS_MICRO, {
193
+ getQueryParameter: _,
194
+ ipcSyncAppInfo: E
195
+ }, Symbol.toStringTag, { value: "Module" })), C = b(!1);
196
+ Object.defineProperty(window, s.IS_MICRO, {
197
197
  get: function() {
198
- return O.value;
198
+ return C.value;
199
199
  },
200
200
  set: function(t) {
201
- O.value = t;
201
+ C.value = t;
202
202
  }
203
203
  });
204
- const P = (t) => `${c.DOM_ID_PREFIX}${t}`, L = (t, e = !1) => {
205
- function n(s) {
206
- return s !== null && typeof s == "object" && !Array.isArray(s);
204
+ const P = (t) => `${s.DOM_ID_PREFIX}${t}`, L = (t, e = !1) => {
205
+ function n(c) {
206
+ return c !== null && typeof c == "object" && !Array.isArray(c);
207
207
  }
208
208
  const o = typeof t.params == "function" ? t.params() : n(t.params) ? t.params : {}, r = typeof t.token == "function" ? t.token() : n(t.token) ? t.token : "", a = new URL(
209
209
  t.url.indexOf("http") > -1 ? t.url : window.location.origin + t.url
210
- ), l = g(c.URL_PARAM_PREFIX + t.name);
210
+ ), l = _(s.URL_PARAM_PREFIX + t.name);
211
211
  if (!e && l) {
212
- const s = b(l, t.url, !0);
213
- if (s) {
214
- const d = new URL(s, t.url);
212
+ const c = S(l, t.url, !0);
213
+ if (c) {
214
+ const d = new URL(c, t.url);
215
215
  d.searchParams.forEach((A, v) => {
216
216
  a.searchParams.set(v, A);
217
217
  }), a.hash = d.hash;
218
218
  }
219
- f(t.name);
219
+ g(t.name);
220
220
  }
221
- if (a.searchParams.set(c.IS_MICRO, !0 + ""), a.searchParams.set(c.MICRO_NAME, t.name), r && a.searchParams.set(c.MICRO_TOKEN, r), o)
222
- for (let s of Object.keys(o))
223
- a.searchParams.set(s, o[s]);
224
- return f(t.name), a.href;
221
+ if (a.searchParams.set(s.IS_MICRO, !0 + ""), a.searchParams.set(s.MICRO_NAME, t.name), r && a.searchParams.set(s.MICRO_TOKEN, r), o)
222
+ for (let c of Object.keys(o))
223
+ a.searchParams.set(c, o[c]);
224
+ return g(t.name), a.href;
225
225
  }, q = () => {
226
226
  const t = document.createElement("div");
227
227
  return t.innerHTML = "应用加载中...", t.style.textAlign = "center", t.style.lineHeight = "100px", t.style.fontSize = "20px", t.style.color = "#999", t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.right = "0", t.style.bottom = "0", t.style.zIndex = "999", t.style.background = "transparent", t.style["mix-blend-mode"] = "difference", t;
@@ -308,7 +308,7 @@ class J {
308
308
  i.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && z(this.loading), Z(this), i.log("this.app.onLoad", this.app.onLoad), this.app.onLoad && this.app.onLoad(e, this);
309
309
  }
310
310
  onUnload(e) {
311
- i.debug("app onUnload", this.app.name), f(this.app.name), this.app.onUnload && this.app.onUnload(e, this);
311
+ i.debug("app onUnload", this.app.name), g(this.app.name), this.app.onUnload && this.app.onUnload(e, this);
312
312
  }
313
313
  onError(e) {
314
314
  i.error("app onError", this.app.name), this.app.onError && this.app.onError(e, this);
@@ -330,13 +330,13 @@ const Z = (t) => {
330
330
  "*"
331
331
  );
332
332
  }, ee = () => {
333
- window[c.MICRO_TYPE] = "parent", window.addEventListener("message", (t) => {
333
+ window[s.MICRO_TYPE] = "parent", window.addEventListener("message", (t) => {
334
334
  if (t.data.cmd === "$xt/micro/sync") {
335
335
  i.log("父页面接受子应用同步路由信息", t.data);
336
336
  const e = [
337
- c.IS_MICRO,
338
- c.MICRO_NAME,
339
- c.MICRO_TOKEN
337
+ s.IS_MICRO,
338
+ s.MICRO_NAME,
339
+ s.MICRO_TOKEN
340
340
  ], n = new URL(
341
341
  window.decodeURIComponent(t.data.data.url),
342
342
  t.origin
@@ -344,11 +344,11 @@ const Z = (t) => {
344
344
  for (let l of e)
345
345
  n.searchParams.delete(l);
346
346
  i.log("tempUrl", n);
347
- const o = f(t.data.data.name), r = new URL(o);
348
- r.searchParams.forEach((l, s) => {
349
- s.startsWith(c.URL_PARAM_PREFIX) && r.searchParams.delete(s);
347
+ const o = g(t.data.data.name), r = new URL(o);
348
+ r.searchParams.forEach((l, c) => {
349
+ c.startsWith(s.URL_PARAM_PREFIX) && r.searchParams.delete(c);
350
350
  }), i.log("mainURL.href", r.href);
351
- const a = S(
351
+ const a = U(
352
352
  r.href,
353
353
  t.data.data.name,
354
354
  n.href
@@ -373,7 +373,7 @@ const Z = (t) => {
373
373
  port: window.location.port,
374
374
  protocol: window.location.protocol
375
375
  },
376
- mainMicroVersion: _,
376
+ mainMicroVersion: f,
377
377
  name: e.name,
378
378
  url: e.url,
379
379
  params: e.params,
@@ -386,56 +386,59 @@ const Z = (t) => {
386
386
  }
387
387
  });
388
388
  }, me = (...e) => w(void 0, [...e], function* (t = {}) {
389
- window[c.MICRO_TYPE] = "child";
390
- const n = g(c.IS_MICRO), o = g(c.MICRO_NAME);
391
- if (i.debug("child microInit", n, o), n && (window[c.IS_MICRO] = n === "true"), o && U(o).then((r) => {
392
- window[c.MICRO_APP] = m({
393
- microVersion: _
389
+ window[s.MICRO_TYPE] = "child";
390
+ const n = _(s.IS_MICRO), o = _(s.MICRO_NAME);
391
+ if (i.debug("child microInit", n, o), n && (window[s.IS_MICRO] = n === "true"), o && E(o).then((r) => {
392
+ window[s.MICRO_APP] = m({
393
+ microVersion: f
394
394
  }, r);
395
- }), window[c.IS_MICRO]) {
395
+ }), window[s.IS_MICRO]) {
396
396
  let r = function(l) {
397
- var s = document.styleSheets[0];
398
- if (!s) {
397
+ var c = document.styleSheets[0];
398
+ if (!c) {
399
399
  var d = document.createElement("style");
400
- document.head.appendChild(d), s = d.sheet;
400
+ document.head.appendChild(d), c = d.sheet;
401
401
  }
402
- s.insertRule(l, s.cssRules.length);
402
+ c.insertRule(l, c.cssRules.length);
403
403
  };
404
- window[c.IS_MICRO] && t.hideHeaderCssSelector && (Array.isArray(t.hideHeaderCssSelector) ? t.hideHeaderCssSelector.forEach((l) => {
404
+ window[s.IS_MICRO] && t.hideHeaderCssSelector && (Array.isArray(t.hideHeaderCssSelector) ? t.hideHeaderCssSelector.forEach((l) => {
405
405
  r(`${l} { display: none !important; }`);
406
406
  }) : r(
407
407
  `${t.hideHeaderCssSelector} { display: none !important; }`
408
408
  )), yield te(o, window), window.addEventListener("message", (l) => w(void 0, null, function* () {
409
409
  l.data.cmd === `$xt/micro/${o}` && T(o);
410
410
  }));
411
- const a = g(c.MICRO_TOKEN);
411
+ const a = _(s.MICRO_TOKEN);
412
412
  t.authHandler && a && (yield t.authHandler(a));
413
413
  } else
414
414
  i.warn("当前环境非微应用环境");
415
415
  });
416
416
  function te(t, e) {
417
417
  const n = e.history, o = n.pushState, r = n.replaceState;
418
- n.pushState = function(a, l, s) {
418
+ n.pushState = function(a, l, c) {
419
419
  const d = R(m(m({}, n.state || {}), a), {
420
420
  // 添加新数据
421
421
  _patchedByParent: !0
422
422
  // 可选:标记这是被父窗口修改的状态
423
423
  });
424
- o.call(n, d, l, s), T(t);
425
- }, n.replaceState = function(a, l, s) {
424
+ o.call(n, d, l, c), T(t);
425
+ }, n.replaceState = function(a, l, c) {
426
426
  const d = R(m(m({}, n.state || {}), a), {
427
427
  // 添加新数据
428
428
  _patchedByParent: !0
429
429
  // 可选:标记这是被父窗口修改的状态
430
430
  });
431
- r.call(n, d, l, s);
431
+ r.call(n, d, l, c);
432
432
  };
433
433
  }
434
434
  function T(t) {
435
435
  return w(this, null, function* () {
436
- if (i.log("syncUrlToWindow", t, window[c.MICRO_APP]), !window[c.MICRO_APP])
437
- return;
438
- const { name: e, sync: n, mainLocation: o } = window[c.MICRO_APP], r = window.location.pathname + window.location.search + window.location.hash;
436
+ i.log("syncUrlToWindow", t, window[s.MICRO_APP]), window[s.MICRO_APP] || (yield E(t).then((a) => {
437
+ window[s.MICRO_APP] = m({
438
+ microVersion: f
439
+ }, a);
440
+ }));
441
+ const { name: e, sync: n, mainLocation: o } = window[s.MICRO_APP], r = window.location.pathname + window.location.search + window.location.hash;
439
442
  i.log("curUrl", r), window.parent.postMessage(
440
443
  {
441
444
  cmd: "$xt/micro/sync",
@@ -471,19 +474,19 @@ const ne = {
471
474
  }, ue = (t, e = !1) => {
472
475
  let n = I(t);
473
476
  n && n.instance.reload(e);
474
- }, f = (t) => {
477
+ }, g = (t) => {
475
478
  i.log(
476
479
  "clearParentUrl",
477
480
  t,
478
- c.URL_PARAM_PREFIX + t
481
+ s.URL_PARAM_PREFIX + t
479
482
  );
480
483
  const e = window.location.href.split("#");
481
484
  i.log("url", e);
482
485
  let n = new URL(e[0]);
483
- n.searchParams.delete(c.URL_PARAM_PREFIX + t);
486
+ n.searchParams.delete(s.URL_PARAM_PREFIX + t);
484
487
  const o = e.length > 1 ? n.href + "#" + e[1] : n.href;
485
488
  return window.history.replaceState({}, "", o), o;
486
- }, ie = () => window[c.IS_MICRO] === !0, pe = () => window[c.MICRO_TYPE] === "parent", fe = (t, e = ((n) => (n = window.__XT_MICRO_APP) == null ? void 0 : n.name)()) => {
489
+ }, ie = () => window[s.IS_MICRO] === !0, pe = () => window[s.MICRO_TYPE] === "parent", fe = (t, e = ((n) => (n = window.__XT_MICRO_APP) == null ? void 0 : n.name)()) => {
487
490
  let o = window.location;
488
491
  if (ie())
489
492
  o = window.__XT_MICRO_APP.mainLocation;
@@ -498,11 +501,11 @@ const ne = {
498
501
  appId: String
499
502
  },
500
503
  setup(t) {
501
- const e = t, n = C(), o = () => {
504
+ const e = t, n = b(), o = () => {
502
505
  e.appId && re(e.appId, {
503
506
  el: n.value,
504
507
  onUnload(r, a) {
505
- i.log("on unload", a.app.name), f(a.app.name);
508
+ i.log("on unload", a.app.name);
506
509
  }
507
510
  }).then((r) => {
508
511
  i.debug("app mounted", e.appId);
@@ -512,15 +515,15 @@ const ne = {
512
515
  r !== a && a && ae(a), o();
513
516
  }), K(() => {
514
517
  o();
515
- }), N(() => {
516
- i.debug("「micro」", "app unmount", e.appId), f(e.appId);
517
- }), (r, a) => (Y(), B("div", V({
518
+ }), Y(() => {
519
+ i.debug("「micro」", "app unmount", e.appId), g(e.appId);
520
+ }), (r, a) => (N(), V("div", B({
518
521
  ref_key: "refPanel",
519
522
  ref: n
520
523
  }, r.$attrs, { class: "xt-micro" }), null, 16));
521
524
  }
522
525
  });
523
- window[c.MICRO_VERSION] = _;
526
+ window[s.MICRO_VERSION] = f;
524
527
  window.micro_api = {
525
528
  debug: i.setEnable
526
529
  };
@@ -531,7 +534,7 @@ const we = {
531
534
  };
532
535
  export {
533
536
  se as XTMicroView,
534
- f as clearParentUrl,
537
+ g as clearParentUrl,
535
538
  fe as createAppUrl,
536
539
  we as default,
537
540
  I as getApp,
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@xingtukeji/micro",
3
- "version": "1.1.20",
3
+ "version": "1.1.21",
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,22 @@
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
+ //开放部分 api 直接在 window 上挂载
13
+ window["micro_api"] = {
14
+ debug: utils.ConsoleUtil.setEnable,
15
+ };
16
+
17
+ export default {
18
+ install: (app: App, _options: any = {}) => {
19
+ app.component("xt-micro-view", XTMicroView);
20
+ mainMicroInit();
21
+ },
22
+ };