@micro-zoe/micro-app 1.0.0-rc.21 → 1.0.0-rc.23

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.21';
1
+ const version = '1.0.0-rc.23';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -1682,6 +1682,8 @@ const BASE_SCOPE_WINDOW_EVENT = [
1682
1682
  'appstate-change',
1683
1683
  'statechange',
1684
1684
  'mounted',
1685
+ 'error'
1686
+ // 'beforeunload', // remove at 2024.5.30 by cangdu
1685
1687
  ];
1686
1688
  // bind event of with sandbox
1687
1689
  const SCOPE_WINDOW_EVENT_OF_WITH = BASE_SCOPE_WINDOW_EVENT;
@@ -2711,6 +2713,14 @@ class EventCenterForBaseApp extends EventCenterForGlobal {
2711
2713
  clearDataListener(appName) {
2712
2714
  eventCenter.off(createEventName(formatAppName(appName), false));
2713
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
+ }
2714
2724
  }
2715
2725
  // Event center for sub app
2716
2726
  class EventCenterForMicroApp extends EventCenterForGlobal {
@@ -6012,9 +6022,9 @@ function patchDocumentPrototype(appName, microAppWindow) {
6012
6022
  }
6013
6023
  // query element👇
6014
6024
  function querySelector(selectors) {
6015
- var _a;
6025
+ var _a, _b;
6016
6026
  const _this = getBindTarget(this);
6017
- if (selectors === 'body') {
6027
+ if (selectors === 'body' && ((_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.inheritBaseBody) !== true) {
6018
6028
  return this.body;
6019
6029
  }
6020
6030
  if (!selectors ||
@@ -6033,7 +6043,7 @@ function patchDocumentPrototype(appName, microAppWindow) {
6033
6043
  *
6034
6044
  * Issue: https://github.com/jd-opensource/micro-app/issues/1335
6035
6045
  */
6036
- const result = (_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.querySelector(selectors);
6046
+ const result = (_b = appInstanceMap.get(appName)) === null || _b === void 0 ? void 0 : _b.querySelector(selectors);
6037
6047
  return result || selectors === 'base' ? result : rawMicroQuerySelector.call(microDocument, selectors);
6038
6048
  }
6039
6049
  function querySelectorAll(selectors) {
@@ -6158,10 +6168,10 @@ function patchDocumentProperty(appName, microAppWindow, sandbox) {
6158
6168
  enumerable: true,
6159
6169
  configurable: true,
6160
6170
  get: () => {
6161
- var _a;
6171
+ var _a, _b;
6162
6172
  throttleDeferForIframeAppName(appName);
6163
- if (tagName === 'body') {
6164
- return ((_a = sandbox.options.container) === null || _a === void 0 ? void 0 : _a.querySelector('micro-app-body')) || rawDocument[tagName];
6173
+ if (tagName === 'body' && ((_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.inheritBaseBody) !== true) {
6174
+ return ((_b = sandbox.options.container) === null || _b === void 0 ? void 0 : _b.querySelector('micro-app-body')) || rawDocument[tagName];
6165
6175
  }
6166
6176
  return rawDocument[tagName];
6167
6177
  },
@@ -6578,6 +6588,8 @@ class IframeSandbox {
6578
6588
  this.deleteIframeElement = this.createIframeElement(appName, browserHost + rawLocation.pathname, options);
6579
6589
  this.microAppWindow = this.iframe.contentWindow;
6580
6590
  this.patchIframe(this.microAppWindow, (resolve) => {
6591
+ // refresh
6592
+ this.microAppWindow = this.iframe.contentWindow;
6581
6593
  // create new html to iframe
6582
6594
  this.createIframeTemplate(this.microAppWindow);
6583
6595
  // get escapeProperties from plugins
@@ -7079,10 +7091,10 @@ class CreateApp {
7079
7091
  return this.setAppState(appStates.LOADING);
7080
7092
  }
7081
7093
  this.createSandbox();
7082
- // place outside of nextAction, as nextAction may execute async
7083
- this.setAppState(appStates.BEFORE_MOUNT);
7084
7094
  const nextAction = () => {
7085
7095
  var _a, _b, _c, _d, _e, _f, _g;
7096
+ // place inside of nextAction, make sure iframe ready
7097
+ this.setAppState(appStates.BEFORE_MOUNT);
7086
7098
  /**
7087
7099
  * Special scenes:
7088
7100
  * 1. mount before prerender exec mount (loading source)
@@ -8359,7 +8371,7 @@ function defineElement(tagName) {
8359
8371
  this.cacheData = null;
8360
8372
  this.connectedCount = 0;
8361
8373
  this.connectStateMap = new Map();
8362
- this.appName = ''; // app name
8374
+ this._appName = ''; // app name
8363
8375
  this.appUrl = ''; // app url
8364
8376
  this.ssrUrl = ''; // html path in ssr mode
8365
8377
  this.version = version;
@@ -8723,6 +8735,7 @@ function defineElement(tagName) {
8723
8735
  unmountcb,
8724
8736
  });
8725
8737
  }
8738
+ delete this.__MICRO_APP_NAME__;
8726
8739
  }
8727
8740
  // hidden app when disconnectedCallback called with keep-alive
8728
8741
  handleHiddenKeepAliveApp(callback) {
@@ -8900,6 +8913,15 @@ function defineElement(tagName) {
8900
8913
  }
8901
8914
  return null;
8902
8915
  }
8916
+ set appName(value) {
8917
+ if (value !== this._appName) {
8918
+ microApp.changeEventAppName(value, this._appName);
8919
+ this._appName = value;
8920
+ }
8921
+ }
8922
+ get appName() {
8923
+ return this._appName;
8924
+ }
8903
8925
  /**
8904
8926
  * get publicPath from a valid address,it can used in micro-app-devtools
8905
8927
  */