@micro-zoe/micro-app 1.0.0-rc.18 → 1.0.0-rc.19

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/README.md CHANGED
@@ -149,7 +149,7 @@ For more commands, see [DEVELOP](https://github.com/jd-opensource/micro-app/blob
149
149
 
150
150
  # Contributors
151
151
  <a href="https://github.com/jd-opensource/micro-app/graphs/contributors">
152
- <img src="https://contrib.rocks/image?repo=micro-zoe/micro-app" />
152
+ <img src="https://contrib.rocks/image?repo=jd-opensource/micro-app" />
153
153
  </a>
154
154
 
155
155
  # License
package/README.zh-cn.md CHANGED
@@ -148,7 +148,7 @@ yarn start # 访问 http://localhost:3000
148
148
 
149
149
  # 贡献者们
150
150
  <a href="https://github.com/jd-opensource/micro-app/graphs/contributors">
151
- <img src="https://contrib.rocks/image?repo=micro-zoe/micro-app" />
151
+ <img src="https://contrib.rocks/image?repo=jd-opensource/micro-app" />
152
152
  </a>
153
153
 
154
154
 
package/lib/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = '1.0.0-rc.18';
1
+ const version = '1.0.0-rc.19';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -1232,6 +1232,15 @@ function scopedCSS(styleElement, app, linkPath) {
1232
1232
  parser = new CSSParser();
1233
1233
  if (styleElement.textContent) {
1234
1234
  commonAction(styleElement, app.name, prefix, app.url, linkPath);
1235
+ const observer = new MutationObserver(() => {
1236
+ const isPrefixed = styleElement.textContent && new RegExp(prefix).test(styleElement.textContent);
1237
+ observer.disconnect();
1238
+ if (!isPrefixed) {
1239
+ styleElement.__MICRO_APP_HAS_SCOPED__ = false;
1240
+ }
1241
+ scopedCSS(styleElement, app, linkPath);
1242
+ });
1243
+ observer.observe(styleElement, { childList: true, characterData: true });
1235
1244
  }
1236
1245
  else {
1237
1246
  const observer = new MutationObserver(function () {
@@ -6516,7 +6525,7 @@ function patchIframeAttribute(url, microAppWindow) {
6516
6525
  }
6517
6526
 
6518
6527
  class IframeSandbox {
6519
- constructor(appName, url) {
6528
+ constructor(appName, url, options) {
6520
6529
  this.active = false;
6521
6530
  // Properties that can be escape to rawWindow
6522
6531
  this.escapeProperties = [];
@@ -6528,9 +6537,10 @@ class IframeSandbox {
6528
6537
  };
6529
6538
  this.appName = appName;
6530
6539
  this.url = url;
6540
+ this.options = options;
6531
6541
  const rawLocation = globalEnv.rawWindow.location;
6532
6542
  const browserHost = rawLocation.protocol + '//' + rawLocation.host;
6533
- this.deleteIframeElement = this.createIframeElement(appName, browserHost + rawLocation.pathname);
6543
+ this.deleteIframeElement = this.createIframeElement(appName, browserHost + rawLocation.pathname, options);
6534
6544
  this.microAppWindow = this.iframe.contentWindow;
6535
6545
  this.patchIframe(this.microAppWindow, (resolve) => {
6536
6546
  // create new html to iframe
@@ -6561,14 +6571,9 @@ class IframeSandbox {
6561
6571
  * @param browserPath browser origin
6562
6572
  * @returns release callback
6563
6573
  */
6564
- createIframeElement(appName, browserPath) {
6574
+ createIframeElement(appName, browserPath, options) {
6565
6575
  this.iframe = pureCreateElement('iframe');
6566
- const iframeAttrs = {
6567
- id: appName,
6568
- src: microApp.options.iframeSrc || browserPath,
6569
- style: 'display: none',
6570
- 'powered-by': 'micro-app',
6571
- };
6576
+ const iframeAttrs = Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.attrs), { id: appName, src: microApp.options.iframeSrc || browserPath, style: 'display: none', 'powered-by': 'micro-app' });
6572
6577
  Object.keys(iframeAttrs).forEach((key) => this.iframe.setAttribute(key, iframeAttrs[key]));
6573
6578
  // effect action during construct
6574
6579
  globalEnv.rawDocument.body.appendChild(this.iframe);
@@ -6907,7 +6912,7 @@ IframeSandbox.activeCount = 0; // number of active sandbox
6907
6912
  // micro app instances
6908
6913
  const appInstanceMap = new Map();
6909
6914
  class CreateApp {
6910
- constructor({ name, url, container, scopecss, useSandbox, inline, iframe, ssrUrl, isPrefetch, prefetchLevel, routerMode, }) {
6915
+ constructor({ name, url, container, scopecss, useSandbox, inline, iframe, ssrUrl, isPrefetch, prefetchLevel, routerMode, attrs, }) {
6911
6916
  this.state = appStates.CREATED;
6912
6917
  this.keepAliveState = null;
6913
6918
  this.loadSourceLevel = 0;
@@ -6923,6 +6928,7 @@ class CreateApp {
6923
6928
  this.url = url;
6924
6929
  this.useSandbox = useSandbox;
6925
6930
  this.scopecss = this.useSandbox && scopecss;
6931
+ this.attrs = attrs;
6926
6932
  // exec before getInlineModeState
6927
6933
  this.iframe = iframe !== null && iframe !== void 0 ? iframe : false;
6928
6934
  this.inline = this.getInlineModeState(inline);
@@ -7459,7 +7465,7 @@ class CreateApp {
7459
7465
  */
7460
7466
  createSandbox() {
7461
7467
  if (this.useSandbox && !this.sandBox) {
7462
- this.sandBox = this.iframe ? new IframeSandbox(this.name, this.url) : new WithSandBox(this.name, this.url);
7468
+ this.sandBox = this.iframe ? new IframeSandbox(this.name, this.url, { attrs: this.attrs }) : new WithSandBox(this.name, this.url);
7463
7469
  }
7464
7470
  }
7465
7471
  // set app state
@@ -8586,6 +8592,12 @@ function defineElement(tagName) {
8586
8592
  }
8587
8593
  // create app instance
8588
8594
  handleCreateApp() {
8595
+ const attrs = {};
8596
+ Array.prototype.slice.call(this.attributes).forEach(({ name, value }) => {
8597
+ if (name.startsWith('data-')) {
8598
+ attrs[name] = value;
8599
+ }
8600
+ });
8589
8601
  const createAppInstance = () => {
8590
8602
  var _a;
8591
8603
  return new CreateApp({
@@ -8598,6 +8610,7 @@ function defineElement(tagName) {
8598
8610
  iframe: this.getDisposeResult('iframe'),
8599
8611
  ssrUrl: this.ssrUrl,
8600
8612
  routerMode: this.getMemoryRouterMode(),
8613
+ attrs
8601
8614
  });
8602
8615
  };
8603
8616
  /**