@micro-zoe/micro-app 1.0.0-rc.22 → 1.0.0-rc.24

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/lib/index.d.ts CHANGED
@@ -422,6 +422,7 @@ declare module '@micro-zoe/micro-app/interact' {
422
422
  * @param appName app.name
423
423
  */
424
424
  clearDataListener(appName: string): void;
425
+ changeEventAppName(newAppName: string, oldAppName: string): void;
425
426
  }
426
427
  export class EventCenterForMicroApp extends EventCenterForGlobal {
427
428
  appName: string;
package/lib/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = '1.0.0-rc.22';
1
+ const version = '1.0.0-rc.24';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -2713,6 +2713,14 @@ class EventCenterForBaseApp extends EventCenterForGlobal {
2713
2713
  clearDataListener(appName) {
2714
2714
  eventCenter.off(createEventName(formatAppName(appName), false));
2715
2715
  }
2716
+ changeEventAppName(newAppName, oldAppName) {
2717
+ const newEventName = createEventName(formatAppName(newAppName), true);
2718
+ const oldEventName = createEventName(formatAppName(oldAppName), true);
2719
+ if (eventCenter.eventList.has(oldEventName)) {
2720
+ eventCenter.eventList.set(newEventName, eventCenter.eventList.get(oldEventName));
2721
+ eventCenter.eventList.delete(oldEventName);
2722
+ }
2723
+ }
2716
2724
  }
2717
2725
  // Event center for sub app
2718
2726
  class EventCenterForMicroApp extends EventCenterForGlobal {
@@ -6502,18 +6510,14 @@ function patchIframeAttribute(url, microAppWindow, appName) {
6502
6510
  const microRootElement = microAppWindow.Element;
6503
6511
  const rawMicroSetAttribute = microRootElement.prototype.setAttribute;
6504
6512
  microRootElement.prototype.setAttribute = function setAttribute(key, value) {
6505
- var _a, _b, _c, _d;
6513
+ var _a;
6506
6514
  if (/^micro-app(-\S+)?/i.test(this.tagName) &&
6507
6515
  key === 'data' &&
6508
6516
  this.setAttribute !== microRootElement.prototype.setAttribute) {
6509
6517
  this.setAttribute(key, value);
6510
6518
  }
6511
6519
  else {
6512
- let appPlugins = (_c = (_b = (_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.modules) === null || _c === void 0 ? void 0 : _c[appName];
6513
- if (!isArray(appPlugins)) {
6514
- appPlugins = [];
6515
- }
6516
- const aHrefResolver = (_d = appPlugins[0]) === null || _d === void 0 ? void 0 : _d.aHrefResolver;
6520
+ const aHrefResolver = (_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.aHrefResolver;
6517
6521
  if (key === 'href' && /^a$/i.test(this.tagName) && typeof aHrefResolver === 'function') {
6518
6522
  // 试验性质:a 标签开放自定义补齐功能
6519
6523
  value = aHrefResolver(value, appName, url);
@@ -6580,6 +6584,8 @@ class IframeSandbox {
6580
6584
  this.deleteIframeElement = this.createIframeElement(appName, browserHost + rawLocation.pathname, options);
6581
6585
  this.microAppWindow = this.iframe.contentWindow;
6582
6586
  this.patchIframe(this.microAppWindow, (resolve) => {
6587
+ // refresh
6588
+ this.microAppWindow = this.iframe.contentWindow;
6583
6589
  // create new html to iframe
6584
6590
  this.createIframeTemplate(this.microAppWindow);
6585
6591
  // get escapeProperties from plugins
@@ -7081,10 +7087,10 @@ class CreateApp {
7081
7087
  return this.setAppState(appStates.LOADING);
7082
7088
  }
7083
7089
  this.createSandbox();
7084
- // place outside of nextAction, as nextAction may execute async
7085
- this.setAppState(appStates.BEFORE_MOUNT);
7086
7090
  const nextAction = () => {
7087
7091
  var _a, _b, _c, _d, _e, _f, _g;
7092
+ // place inside of nextAction, make sure iframe ready
7093
+ this.setAppState(appStates.BEFORE_MOUNT);
7088
7094
  /**
7089
7095
  * Special scenes:
7090
7096
  * 1. mount before prerender exec mount (loading source)
@@ -7773,6 +7779,7 @@ function isPendMethod(method) {
7773
7779
  * @param newChild target node
7774
7780
  */
7775
7781
  function completePathDynamic(app, newChild) {
7782
+ var _a;
7776
7783
  if (isElement(newChild)) {
7777
7784
  if (/^(img|script)$/i.test(newChild.tagName)) {
7778
7785
  if (newChild.hasAttribute('src')) {
@@ -7785,7 +7792,16 @@ function completePathDynamic(app, newChild) {
7785
7792
  else if ((/^(link|image)$/i.test(newChild.tagName) && newChild.hasAttribute('href')) ||
7786
7793
  // If it is the anchor tag,eg. <a href="#xxx"/>, the path will not be completed
7787
7794
  (/^(a)$/i.test(newChild.tagName) && newChild.hasAttribute('href') && !/^#/.test(newChild.getAttribute('href') || ''))) {
7788
- globalEnv.rawSetAttribute.call(newChild, 'href', CompletionPath(newChild.getAttribute('href'), app.url));
7795
+ const aHrefResolver = (_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.aHrefResolver;
7796
+ const hrefValue = newChild.getAttribute('href');
7797
+ let nextHrefValue;
7798
+ if ((/^(a)$/i.test(newChild.tagName) && typeof aHrefResolver === 'function')) {
7799
+ nextHrefValue = aHrefResolver(hrefValue, app.name, app.url);
7800
+ }
7801
+ else {
7802
+ nextHrefValue = CompletionPath(hrefValue, app.url);
7803
+ }
7804
+ globalEnv.rawSetAttribute.call(newChild, 'href', nextHrefValue);
7789
7805
  }
7790
7806
  }
7791
7807
  }
@@ -7948,7 +7964,7 @@ function patchElementAndDocument() {
7948
7964
  };
7949
7965
  // rewrite setAttribute, complete resource address
7950
7966
  rawRootElement.prototype.setAttribute = function setAttribute(key, value) {
7951
- var _a;
7967
+ var _a, _b;
7952
7968
  if (/^micro-app(-\S+)?/i.test(this.tagName) &&
7953
7969
  key === 'data' &&
7954
7970
  this.setAttribute !== rawRootElement.prototype.setAttribute) {
@@ -7963,12 +7979,18 @@ function patchElementAndDocument() {
7963
7979
  // If it is the anchor tag,eg. <a href="#xxx"/>, the path will not be completed
7964
7980
  (key === 'href' && /^(a)$/i.test(this.tagName) && !/^#/.test(value)))) {
7965
7981
  const app = appInstanceMap.get(appName);
7966
- value = CompletionPath(value, app.url);
7982
+ const aHrefResolver = (_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.aHrefResolver;
7983
+ if (key === 'href' && /^a$/i.test(this.tagName) && typeof aHrefResolver === 'function') {
7984
+ value = aHrefResolver(value, appName, app.url);
7985
+ }
7986
+ else {
7987
+ value = CompletionPath(value, app.url);
7988
+ }
7967
7989
  }
7968
7990
  globalEnv.rawSetAttribute.call(this, key, value);
7969
7991
  if (isImageElement(this) || isVideoElement(this) || isAudioElement(this)) {
7970
7992
  let includeCrossOrigin = false;
7971
- if (((_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.includeCrossOrigin) && isFunction(microApp.options.includeCrossOrigin)) {
7993
+ if (((_b = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _b === void 0 ? void 0 : _b.includeCrossOrigin) && isFunction(microApp.options.includeCrossOrigin)) {
7972
7994
  includeCrossOrigin = microApp.options.includeCrossOrigin(value);
7973
7995
  }
7974
7996
  // @ts-ignore
@@ -8361,7 +8383,7 @@ function defineElement(tagName) {
8361
8383
  this.cacheData = null;
8362
8384
  this.connectedCount = 0;
8363
8385
  this.connectStateMap = new Map();
8364
- this.appName = ''; // app name
8386
+ this._appName = ''; // app name
8365
8387
  this.appUrl = ''; // app url
8366
8388
  this.ssrUrl = ''; // html path in ssr mode
8367
8389
  this.version = version;
@@ -8725,6 +8747,7 @@ function defineElement(tagName) {
8725
8747
  unmountcb,
8726
8748
  });
8727
8749
  }
8750
+ delete this.__MICRO_APP_NAME__;
8728
8751
  }
8729
8752
  // hidden app when disconnectedCallback called with keep-alive
8730
8753
  handleHiddenKeepAliveApp(callback) {
@@ -8902,6 +8925,15 @@ function defineElement(tagName) {
8902
8925
  }
8903
8926
  return null;
8904
8927
  }
8928
+ set appName(value) {
8929
+ if (value !== this._appName) {
8930
+ microApp.changeEventAppName(value, this._appName);
8931
+ this._appName = value;
8932
+ }
8933
+ }
8934
+ get appName() {
8935
+ return this._appName;
8936
+ }
8905
8937
  /**
8906
8938
  * get publicPath from a valid address,it can used in micro-app-devtools
8907
8939
  */