@micro-zoe/micro-app 1.0.0-rc.23 → 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.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = '1.0.0-rc.23';
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
@@ -6510,18 +6510,14 @@ function patchIframeAttribute(url, microAppWindow, appName) {
6510
6510
  const microRootElement = microAppWindow.Element;
6511
6511
  const rawMicroSetAttribute = microRootElement.prototype.setAttribute;
6512
6512
  microRootElement.prototype.setAttribute = function setAttribute(key, value) {
6513
- var _a, _b, _c, _d;
6513
+ var _a;
6514
6514
  if (/^micro-app(-\S+)?/i.test(this.tagName) &&
6515
6515
  key === 'data' &&
6516
6516
  this.setAttribute !== microRootElement.prototype.setAttribute) {
6517
6517
  this.setAttribute(key, value);
6518
6518
  }
6519
6519
  else {
6520
- 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];
6521
- if (!isArray(appPlugins)) {
6522
- appPlugins = [];
6523
- }
6524
- 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;
6525
6521
  if (key === 'href' && /^a$/i.test(this.tagName) && typeof aHrefResolver === 'function') {
6526
6522
  // 试验性质:a 标签开放自定义补齐功能
6527
6523
  value = aHrefResolver(value, appName, url);
@@ -7783,6 +7779,7 @@ function isPendMethod(method) {
7783
7779
  * @param newChild target node
7784
7780
  */
7785
7781
  function completePathDynamic(app, newChild) {
7782
+ var _a;
7786
7783
  if (isElement(newChild)) {
7787
7784
  if (/^(img|script)$/i.test(newChild.tagName)) {
7788
7785
  if (newChild.hasAttribute('src')) {
@@ -7795,7 +7792,16 @@ function completePathDynamic(app, newChild) {
7795
7792
  else if ((/^(link|image)$/i.test(newChild.tagName) && newChild.hasAttribute('href')) ||
7796
7793
  // If it is the anchor tag,eg. <a href="#xxx"/>, the path will not be completed
7797
7794
  (/^(a)$/i.test(newChild.tagName) && newChild.hasAttribute('href') && !/^#/.test(newChild.getAttribute('href') || ''))) {
7798
- 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);
7799
7805
  }
7800
7806
  }
7801
7807
  }
@@ -7958,7 +7964,7 @@ function patchElementAndDocument() {
7958
7964
  };
7959
7965
  // rewrite setAttribute, complete resource address
7960
7966
  rawRootElement.prototype.setAttribute = function setAttribute(key, value) {
7961
- var _a;
7967
+ var _a, _b;
7962
7968
  if (/^micro-app(-\S+)?/i.test(this.tagName) &&
7963
7969
  key === 'data' &&
7964
7970
  this.setAttribute !== rawRootElement.prototype.setAttribute) {
@@ -7973,12 +7979,18 @@ function patchElementAndDocument() {
7973
7979
  // If it is the anchor tag,eg. <a href="#xxx"/>, the path will not be completed
7974
7980
  (key === 'href' && /^(a)$/i.test(this.tagName) && !/^#/.test(value)))) {
7975
7981
  const app = appInstanceMap.get(appName);
7976
- 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
+ }
7977
7989
  }
7978
7990
  globalEnv.rawSetAttribute.call(this, key, value);
7979
7991
  if (isImageElement(this) || isVideoElement(this) || isAudioElement(this)) {
7980
7992
  let includeCrossOrigin = false;
7981
- 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)) {
7982
7994
  includeCrossOrigin = microApp.options.includeCrossOrigin(value);
7983
7995
  }
7984
7996
  // @ts-ignore