@blueking/bk-weweb 0.0.35-beta.3 → 0.0.35-beta.4

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/dist/index.esm.js CHANGED
@@ -1907,16 +1907,21 @@ var MicroAppModel = class {
1907
1907
  this.setupNodeProperties(node);
1908
1908
  fragment.appendChild(node);
1909
1909
  }
1910
+ container.innerHTML = "";
1910
1911
  container.appendChild(fragment);
1911
1912
  }
1912
1913
  /** 设置节点属性 */
1913
1914
  setupNodeProperties(node) {
1915
+ const app = this;
1914
1916
  const nodeWithProps = node;
1915
- if (this.keepAlive) {
1916
- nodeWithProps.__KEEP_ALIVE__ = this.name;
1917
- }
1918
- nodeWithProps.__BK_WEWEB_APP_KEY__ = this.name;
1919
- nodeWithProps.data = this.data;
1917
+ nodeWithProps.__BK_WEWEB_APP_KEY__ = this.appCacheKey;
1918
+ Object.defineProperties(node, {
1919
+ ownerDocument: {
1920
+ get() {
1921
+ return app.sandBox?.rawDocument;
1922
+ }
1923
+ }
1924
+ });
1920
1925
  }
1921
1926
  /** 创建iframe元素 */
1922
1927
  createIframeElement() {
@@ -1928,7 +1933,8 @@ var MicroAppModel = class {
1928
1933
  }
1929
1934
  /** 构建iframe源地址 */
1930
1935
  buildIframeSrc(url) {
1931
- return `${url.protocol}//${url.host}`;
1936
+ const isChrome = this.isChromeUserAgent();
1937
+ return `${isChrome ? IFRAME_CONSTANTS.BLANK_ORIGIN : location.origin}${url.pathname || "/"}${url.search}${url.hash}`;
1932
1938
  }
1933
1939
  /** 检查是否为Chrome浏览器 */
1934
1940
  isChromeUserAgent() {
@@ -1936,24 +1942,30 @@ var MicroAppModel = class {
1936
1942
  }
1937
1943
  /** 处理非Chrome浏览器iframe */
1938
1944
  handleNonChromeIframe(iframe, resolve) {
1939
- const iframeOnload = () => {
1940
- resolve(iframe);
1941
- };
1942
- if (iframe.contentDocument?.readyState === "complete") {
1943
- iframeOnload();
1944
- } else {
1945
- iframe.addEventListener("load", iframeOnload);
1946
- }
1945
+ const interval = setInterval(() => {
1946
+ if (iframe.contentWindow && iframe.contentWindow.location.href !== IFRAME_CONSTANTS.BLANK_ORIGIN) {
1947
+ iframe.contentWindow.stop();
1948
+ iframe.contentDocument.body.parentElement.innerHTML = IFRAME_CONSTANTS.DEFAULT_HTML;
1949
+ clearInterval(interval);
1950
+ resolve(iframe);
1951
+ }
1952
+ }, IFRAME_CONSTANTS.POLLING_INTERVAL);
1947
1953
  }
1948
1954
  /** 渲染应用内容 */
1949
1955
  renderAppContent() {
1950
- if (this.showSourceCode && this.source) {
1951
- this.container.innerHTML = this.source.rawHtml || IFRAME_CONSTANTS.DEFAULT_HTML;
1956
+ if (!this.source) return;
1957
+ const clonedNode = this.source.html.cloneNode(true);
1958
+ const fragment = document.createDocumentFragment();
1959
+ for (const node of Array.from(clonedNode.childNodes)) {
1960
+ this.setupNodeProperties(node);
1961
+ fragment.appendChild(node);
1952
1962
  }
1963
+ this.container.innerHTML = "";
1964
+ this.container.appendChild(fragment);
1953
1965
  }
1954
1966
  /** 检查是否需要重新加载 */
1955
1967
  needsReload() {
1956
- return this.status === AppState.ERROR;
1968
+ return this.status === AppState.ERROR || this.status === AppState.UNSET;
1957
1969
  }
1958
1970
  };
1959
1971