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

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
@@ -1481,10 +1481,8 @@ var MicroInstanceModel = class {
1481
1481
  setupContainer() {
1482
1482
  if (this.container) {
1483
1483
  this.container.innerHTML = "";
1484
- if (this.showSourceCode) {
1485
- const instanceWrapper = this.createInstanceWrapper();
1486
- this.container.appendChild(instanceWrapper);
1487
- }
1484
+ const instanceWrapper = this.createInstanceWrapper();
1485
+ this.container.appendChild(instanceWrapper);
1488
1486
  }
1489
1487
  }
1490
1488
  /** 执行样式 */
@@ -1503,7 +1501,7 @@ var MicroInstanceModel = class {
1503
1501
  renderInstance() {
1504
1502
  const scriptInfo = this.getScriptInfo();
1505
1503
  if (scriptInfo?.exportInstance?.render && this.container) {
1506
- const targetContainer = this.showSourceCode ? this.container.querySelector(`#${this.name}${WRAPPER_SUFFIX}`) : this.container;
1504
+ const targetContainer = this.container.querySelector(`#${this.name}${WRAPPER_SUFFIX}`);
1507
1505
  if (targetContainer) {
1508
1506
  scriptInfo.exportInstance.render(targetContainer, this.data);
1509
1507
  }
@@ -1516,7 +1514,7 @@ var MicroInstanceModel = class {
1516
1514
  }
1517
1515
  /** 检查是否需要重新加载 */
1518
1516
  needsReload() {
1519
- return this.status === AppState.ERROR;
1517
+ return this.status === AppState.ERROR || this.status === AppState.UNSET;
1520
1518
  }
1521
1519
  };
1522
1520
 
@@ -1907,16 +1905,21 @@ var MicroAppModel = class {
1907
1905
  this.setupNodeProperties(node);
1908
1906
  fragment.appendChild(node);
1909
1907
  }
1908
+ container.innerHTML = "";
1910
1909
  container.appendChild(fragment);
1911
1910
  }
1912
1911
  /** 设置节点属性 */
1913
1912
  setupNodeProperties(node) {
1913
+ const app = this;
1914
1914
  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;
1915
+ nodeWithProps.__BK_WEWEB_APP_KEY__ = this.appCacheKey;
1916
+ Object.defineProperties(node, {
1917
+ ownerDocument: {
1918
+ get() {
1919
+ return app.sandBox?.rawDocument;
1920
+ }
1921
+ }
1922
+ });
1920
1923
  }
1921
1924
  /** 创建iframe元素 */
1922
1925
  createIframeElement() {
@@ -1928,7 +1931,8 @@ var MicroAppModel = class {
1928
1931
  }
1929
1932
  /** 构建iframe源地址 */
1930
1933
  buildIframeSrc(url) {
1931
- return `${url.protocol}//${url.host}`;
1934
+ const isChrome = this.isChromeUserAgent();
1935
+ return `${isChrome ? IFRAME_CONSTANTS.BLANK_ORIGIN : location.origin}${url.pathname || "/"}${url.search}${url.hash}`;
1932
1936
  }
1933
1937
  /** 检查是否为Chrome浏览器 */
1934
1938
  isChromeUserAgent() {
@@ -1936,24 +1940,30 @@ var MicroAppModel = class {
1936
1940
  }
1937
1941
  /** 处理非Chrome浏览器iframe */
1938
1942
  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
- }
1943
+ const interval = setInterval(() => {
1944
+ if (iframe.contentWindow && iframe.contentWindow.location.href !== IFRAME_CONSTANTS.BLANK_ORIGIN) {
1945
+ iframe.contentWindow.stop();
1946
+ iframe.contentDocument.body.parentElement.innerHTML = IFRAME_CONSTANTS.DEFAULT_HTML;
1947
+ clearInterval(interval);
1948
+ resolve(iframe);
1949
+ }
1950
+ }, IFRAME_CONSTANTS.POLLING_INTERVAL);
1947
1951
  }
1948
1952
  /** 渲染应用内容 */
1949
1953
  renderAppContent() {
1950
- if (this.showSourceCode && this.source) {
1951
- this.container.innerHTML = this.source.rawHtml || IFRAME_CONSTANTS.DEFAULT_HTML;
1954
+ if (!this.source) return;
1955
+ const clonedNode = this.source.html.cloneNode(true);
1956
+ const fragment = document.createDocumentFragment();
1957
+ for (const node of Array.from(clonedNode.childNodes)) {
1958
+ this.setupNodeProperties(node);
1959
+ fragment.appendChild(node);
1952
1960
  }
1961
+ this.container.innerHTML = "";
1962
+ this.container.appendChild(fragment);
1953
1963
  }
1954
1964
  /** 检查是否需要重新加载 */
1955
1965
  needsReload() {
1956
- return this.status === AppState.ERROR;
1966
+ return this.status === AppState.ERROR || this.status === AppState.UNSET;
1957
1967
  }
1958
1968
  };
1959
1969
 
@@ -2181,7 +2191,8 @@ var EntrySource = class {
2181
2191
  * 检查是否应该忽略脚本
2182
2192
  */
2183
2193
  shouldIgnoreScript = (script) => {
2184
- return script.hasAttribute("ignore") || script.type !== "module" && isJsonpUrl(script.getAttribute("src")) || script.hasAttribute("type") && !SCRIPT_TYPE_NAMES.includes(script.type);
2194
+ return script.hasAttribute("ignore") || // (script.type !== 'module' && isJsonpUrl(script.getAttribute('src'))) ||
2195
+ script.hasAttribute("type") && !SCRIPT_TYPE_NAMES.includes(script.type);
2185
2196
  };
2186
2197
  /**
2187
2198
  * 处理被排除的脚本