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

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.24';
1
+ const version = '1.0.0-rc.26';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -919,8 +919,8 @@ class CSSParser {
919
919
  * should be ==> micro-app[name=xxx] :where(.a, .b, .c) a {}
920
920
  */
921
921
  const attributeValues = {};
922
- const matchRes = m[0].replace(/\[([^\]=]+)(?:=([^\]]+))?\]/g, (match, p1, p2) => {
923
- const mock = `__mock_${p1}Value__`;
922
+ const matchRes = m[0].replace(/\[([^\]=]+)(?:=([^\]]+))?\]/g, (match, p1, p2, offset) => {
923
+ const mock = `__mock_${p1}_${offset}Value__`;
924
924
  attributeValues[mock] = p2;
925
925
  return match.replace(p2, mock);
926
926
  });
@@ -3118,7 +3118,7 @@ function getIframeParentNodeDesc(appName, parentNodeDesc) {
3118
3118
  configurable: true,
3119
3119
  enumerable: true,
3120
3120
  get() {
3121
- var _a, _b, _c, _d;
3121
+ var _a, _b, _c, _d, _e, _f, _g;
3122
3122
  throttleDeferForIframeAppName(appName);
3123
3123
  const result = (_a = parentNodeDesc.get) === null || _a === void 0 ? void 0 : _a.call(this);
3124
3124
  /**
@@ -3133,7 +3133,14 @@ function getIframeParentNodeDesc(appName, parentNodeDesc) {
3133
3133
  * e.g. target.parentNode.remove(target)
3134
3134
  */
3135
3135
  if (isMicroAppBody(result) && ((_b = appInstanceMap.get(appName)) === null || _b === void 0 ? void 0 : _b.container)) {
3136
- return ((_d = (_c = microApp.options).getRootElementParentNode) === null || _d === void 0 ? void 0 : _d.call(_c, this, appName)) || globalEnv.rawDocument.body;
3136
+ const customParent = (_d = (_c = microApp.options).getRootElementParentNode) === null || _d === void 0 ? void 0 : _d.call(_c, this, appName);
3137
+ if (customParent) {
3138
+ return customParent;
3139
+ }
3140
+ if (((_e = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _e === void 0 ? void 0 : _e.inheritBaseBody) !== true) {
3141
+ return ((_g = (_f = appInstanceMap.get(appName)) === null || _f === void 0 ? void 0 : _f.container) === null || _g === void 0 ? void 0 : _g.querySelector('micro-app-body')) || globalEnv.rawDocument.body;
3142
+ }
3143
+ return globalEnv.rawDocument.body;
3137
3144
  }
3138
3145
  return result;
3139
3146
  }
@@ -5867,11 +5874,17 @@ function patchWindowEffect$1(microAppWindow) {
5867
5874
  const eventListenerMap = new Map();
5868
5875
  const sstEventListenerMap = new Map();
5869
5876
  function getEventTarget(type) {
5877
+ var _a;
5870
5878
  /**
5871
5879
  * TODO: SCOPE_WINDOW_EVENT_OF_IFRAME的事件非常少,有可能导致问题
5872
5880
  * 1、一些未知的需要绑定到iframe的事件被错误的绑定到原生window上
5873
5881
  */
5874
- return SCOPE_WINDOW_EVENT_OF_IFRAME.includes(type) ? microAppWindow : rawWindow;
5882
+ let escapeSandboxEvent = [];
5883
+ if (Array.isArray((_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.escapeIframeWindowEvents)) {
5884
+ escapeSandboxEvent = microApp.options.escapeIframeWindowEvents;
5885
+ }
5886
+ const scopeWindowEvent = SCOPE_WINDOW_EVENT_OF_IFRAME.filter(item => !escapeSandboxEvent.includes(item));
5887
+ return scopeWindowEvent.includes(type) ? microAppWindow : rawWindow;
5875
5888
  }
5876
5889
  // TODO: listener 是否需要绑定microAppWindow,否则函数中的this指向原生window
5877
5890
  microAppWindow.addEventListener = function (type, listener, options) {
@@ -5962,6 +5975,13 @@ function patchDocument$1(appName, microAppWindow, sandbox) {
5962
5975
  patchDocumentProperty(appName, microAppWindow, sandbox);
5963
5976
  return patchDocumentEffect(appName, microAppWindow);
5964
5977
  }
5978
+ function getElementDocument(microDocument, rawDocument) {
5979
+ var _a;
5980
+ if ((_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.disableIframeRootDocument) {
5981
+ return rawDocument;
5982
+ }
5983
+ return microDocument;
5984
+ }
5965
5985
  function patchDocumentPrototype(appName, microAppWindow) {
5966
5986
  const rawDocument = globalEnv.rawDocument;
5967
5987
  const microRootDocument = microAppWindow.Document;
@@ -5987,26 +6007,26 @@ function patchDocumentPrototype(appName, microAppWindow) {
5987
6007
  return range;
5988
6008
  };
5989
6009
  microRootDocument.prototype.createElement = function createElement(tagName, options) {
5990
- let element = rawMicroCreateElement.call(this, tagName, options);
6010
+ let element = rawMicroCreateElement.call(getElementDocument(this, rawDocument), tagName, options);
5991
6011
  if (isWebComponentElement(element)) {
5992
6012
  element = rawMicroCreateElement.call(rawDocument, tagName, options);
5993
6013
  }
5994
6014
  return updateElementInfo(element, appName);
5995
6015
  };
5996
6016
  microRootDocument.prototype.createElementNS = function createElementNS(namespaceURI, name, options) {
5997
- const element = rawMicroCreateElementNS.call(this, namespaceURI, name, options);
6017
+ const element = rawMicroCreateElementNS.call(getElementDocument(this, rawDocument), namespaceURI, name, options);
5998
6018
  return updateElementInfo(element, appName);
5999
6019
  };
6000
6020
  microRootDocument.prototype.createTextNode = function createTextNode(data) {
6001
- const element = rawMicroCreateTextNode.call(this, data);
6021
+ const element = rawMicroCreateTextNode.call(getElementDocument(this, rawDocument), data);
6002
6022
  return updateElementInfo(element, appName);
6003
6023
  };
6004
6024
  microRootDocument.prototype.createDocumentFragment = function createDocumentFragment() {
6005
- const element = rawMicroCreateDocumentFragment.call(this);
6025
+ const element = rawMicroCreateDocumentFragment.call(getElementDocument(this, rawDocument));
6006
6026
  return updateElementInfo(element, appName);
6007
6027
  };
6008
6028
  microRootDocument.prototype.createComment = function createComment(data) {
6009
- const element = rawMicroCreateComment.call(this, data);
6029
+ const element = rawMicroCreateComment.call(getElementDocument(this, rawDocument), data);
6010
6030
  return updateElementInfo(element, appName);
6011
6031
  };
6012
6032
  function getBindTarget(target) {
@@ -6065,7 +6085,7 @@ function patchDocumentPrototype(appName, microAppWindow) {
6065
6085
  return rawMicroGetElementById.call(_this, key);
6066
6086
  }
6067
6087
  try {
6068
- return querySelector.call(this, `#${key}`);
6088
+ return querySelector.call(getElementDocument(this, rawDocument), `#${key}`);
6069
6089
  }
6070
6090
  catch (_a) {
6071
6091
  return rawMicroGetElementById.call(_this, key);
@@ -6077,14 +6097,14 @@ function patchDocumentPrototype(appName, microAppWindow) {
6077
6097
  return rawMicroGetElementsByClassName.call(_this, key);
6078
6098
  }
6079
6099
  try {
6080
- return querySelectorAll.call(this, `.${key}`);
6100
+ return querySelectorAll.call(getElementDocument(this, rawDocument), `.${key}`);
6081
6101
  }
6082
6102
  catch (_a) {
6083
6103
  return rawMicroGetElementsByClassName.call(_this, key);
6084
6104
  }
6085
6105
  };
6086
6106
  microRootDocument.prototype.getElementsByTagName = function getElementsByTagName(key) {
6087
- const _this = getBindTarget(this);
6107
+ const _this = getBindTarget(getElementDocument(this, rawDocument));
6088
6108
  if (isUniqueElement(key) ||
6089
6109
  isInvalidQuerySelectorKey(key)) {
6090
6110
  return rawMicroGetElementsByTagName.call(_this, key);
@@ -6094,19 +6114,19 @@ function patchDocumentPrototype(appName, microAppWindow) {
6094
6114
  return rawMicroGetElementsByTagName.call(microDocument, key);
6095
6115
  }
6096
6116
  try {
6097
- return querySelectorAll.call(this, key);
6117
+ return querySelectorAll.call(getElementDocument(this, rawDocument), key);
6098
6118
  }
6099
6119
  catch (_a) {
6100
6120
  return rawMicroGetElementsByTagName.call(_this, key);
6101
6121
  }
6102
6122
  };
6103
6123
  microRootDocument.prototype.getElementsByName = function getElementsByName(key) {
6104
- const _this = getBindTarget(this);
6124
+ const _this = getBindTarget(getElementDocument(this, rawDocument));
6105
6125
  if (isInvalidQuerySelectorKey(key)) {
6106
6126
  return rawMicroGetElementsByName.call(_this, key);
6107
6127
  }
6108
6128
  try {
6109
- return querySelectorAll.call(this, `[name=${key}]`);
6129
+ return querySelectorAll.call(getElementDocument(this, rawDocument), `[name=${key}]`);
6110
6130
  }
6111
6131
  catch (_a) {
6112
6132
  return rawMicroGetElementsByName.call(_this, key);