@zzdadelu/schema-builder 1.0.0-alpha.56 → 1.0.0-alpha.58

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.
@@ -1,5 +1,7 @@
1
1
  var createIframeContent = function createIframeContent() {
2
- var html = "\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" />\n <meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\">\n <meta http-equiv=\"Pragma\" content=\"no-cache\">\n <meta http-equiv=\"Expires\" content=\"0\">\n <title>XRender</title>\n <link rel=\"icon\" href=\"https://img.alicdn.com/tfs/TB17UtINiLaK1RjSZFxXXamPFXa-606-643.png\">\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/variables.css\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css\" />\n\n <!-- \u5173\u952E\u4FEE\u590D1\uFF1A\u63D0\u524D\u5B9A\u4E49 getFormRenderMaterial \u5360\u4F4D\u7B26 -->\n <script>\n \n\n (function() {\n // \u4FDD\u5B58\u771F\u6B63\u7684\u51FD\u6570\u5F15\u7528\n let __realGetFormRenderMaterial = null;\n let __isGetFormRenderMaterialReady = false;\n let __pendingCalls = [];\n \n // \u521B\u5EFA\u5B89\u5168\u7684\u4EE3\u7406\u51FD\u6570\n function __safeGetFormRenderMaterialWrapper(...args) {\n if (__isGetFormRenderMaterialReady && __realGetFormRenderMaterial) {\n return __realGetFormRenderMaterial.apply(this, args);\n }\n \n console.warn('[XRender] getFormRenderMaterial not ready yet, queuing call');\n \n // \u5982\u679C\u662F\u7B2C\u4E09\u65B9\u5E93\u7684\u8C03\u7528\uFF0C\u76F4\u63A5\u8FD4\u56DE\u7A7A\u5BF9\u8C61\u907F\u514D\u9519\u8BEF\n if (args[0] === 'AliFormRenderMaterial' && args[1] === '@ali/form-render-material') {\n console.warn('[XRender] Returning empty object for AliFormRenderMaterial');\n return {};\n }\n \n // \u5176\u4ED6\u8C03\u7528\u6392\u961F\u5904\u7406\n return new Promise((resolve, reject) => {\n __pendingCalls.push({\n args: args,\n resolve: resolve,\n reject: reject\n });\n });\n }\n \n // \u5B9A\u4E49 window.getFormRenderMaterial \u5C5E\u6027\n Object.defineProperty(window, 'getFormRenderMaterial', {\n configurable: true,\n enumerable: true,\n get: function() {\n return __safeGetFormRenderMaterialWrapper;\n },\n set: function(value) {\n console.log('[XRender] Setting getFormRenderMaterial to:', typeof value);\n __realGetFormRenderMaterial = value;\n __isGetFormRenderMaterialReady = true;\n \n // \u6267\u884C\u6392\u961F\u7684\u8C03\u7528\n __pendingCalls.forEach(call => {\n try {\n const result = value.apply(window, call.args);\n call.resolve(result);\n } catch (error) {\n call.reject(error);\n }\n });\n __pendingCalls = [];\n \n // \u901A\u77E5\u7236\u7A97\u53E3\n try {\n window.parent.postMessage({\n type: 'getFormRenderMaterial-ready',\n ready: true,\n timestamp: Date.now()\n }, '*');\n } catch(e) {}\n }\n });\n \n // \u62E6\u622A\u5371\u9669\u8C03\u7528\n const originalDefineProperty = Object.defineProperty;\n Object.defineProperty = function(obj, prop, descriptor) {\n if (prop === 'AliFormRenderMaterial' && obj === window) {\n console.warn('[XRender] Intercepted AliFormRenderMaterial definition');\n \n // \u5EF6\u8FDF\u8BBE\u7F6E AliFormRenderMaterial\n if (descriptor.value !== undefined) {\n const originalValue = descriptor.value;\n descriptor.value = undefined;\n \n setTimeout(() => {\n if (typeof window.getFormRenderMaterial === 'function') {\n try {\n const material = window.getFormRenderMaterial('AliFormRenderMaterial', '@ali/form-render-material');\n window.AliFormRenderMaterial = material || originalValue;\n console.log('[XRender] AliFormRenderMaterial set successfully');\n } catch (e) {\n console.error('[XRender] Error setting AliFormRenderMaterial:', e);\n window.AliFormRenderMaterial = originalValue;\n }\n } else {\n console.warn('[XRender] getFormRenderMaterial not available for AliFormRenderMaterial');\n window.AliFormRenderMaterial = originalValue;\n }\n }, 0);\n }\n }\n return originalDefineProperty.call(this, obj, prop, descriptor);\n };\n })();\n </script>\n\n <script>\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js\"></script>\n\n <!-- \u5173\u952E\u4FEE\u590D2\uFF1A\u4F7F\u7528\u540C\u6B65\u65B9\u5F0F\u52A0\u8F7D fr-generator -->\n <script>\n (function() {\n const maxRetries = 3;\n let retryCount = 0;\n \n function loadFrGenerator() {\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n const url = 'https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js?t=' + Date.now() + '&retry=' + retryCount;\n script.src = url;\n script.type = 'text/javascript';\n \n script.onload = function() {\n console.log('[XRender] fr-generator loaded successfully, attempt', retryCount + 1);\n \n // \u7B49\u5F85\u51FD\u6570\u88AB\u5B9A\u4E49\n let checkCount = 0;\n const maxChecks = 50; // \u6700\u591A\u68C0\u67E55\u79D2\n const checkInterval = setInterval(() => {\n checkCount++;\n if (typeof window.getFormRenderMaterial === 'function') {\n clearInterval(checkInterval);\n console.log('[XRender] \u2713 getFormRenderMaterial is now a function');\n resolve();\n } else if (checkCount >= maxChecks) {\n clearInterval(checkInterval);\n console.warn('[XRender] getFormRenderMaterial not defined after fr-generator load');\n reject(new Error('getFormRenderMaterial not defined'));\n }\n }, 100);\n };\n \n script.onerror = function() {\n console.error('[XRender] Failed to load fr-generator, attempt', retryCount + 1);\n \n if (retryCount < maxRetries - 1) {\n retryCount++;\n setTimeout(() => loadFrGenerator().then(resolve).catch(reject), 1000 * retryCount);\n } else {\n console.error('[XRender] Max retries reached, creating emergency function');\n \n // \u521B\u5EFA\u5E94\u6025\u51FD\u6570\n window.getFormRenderMaterial = function() {\n console.error('[XRender] Using emergency fallback for getFormRenderMaterial');\n return {};\n };\n \n reject(new Error('Failed to load fr-generator after max retries'));\n }\n };\n \n // \u4F7F\u7528 document.write \u786E\u4FDD\u540C\u6B65\u6267\u884C\n document.write(script.outerHTML);\n });\n }\n \n // \u7ACB\u5373\u5F00\u59CB\u52A0\u8F7D\n loadFrGenerator().catch(error => {\n console.error('[XRender] fr-generator load failed:', error);\n });\n })();\n </script>\n </head>\n\n <body>\n <div id=\"lce-container\"></div>\n \n <!-- \u5173\u952E\u4FEE\u590D3\uFF1A\u6700\u7EC8\u68C0\u67E5 -->\n <script>\n window.addEventListener('load', function() {\n console.log('[XRender] Iframe fully loaded');\n \n // \u68C0\u67E5\u5173\u952E\u51FD\u6570\n setTimeout(() => {\n const checks = {\n getFormRenderMaterial: typeof window.getFormRenderMaterial === 'function',\n AliFormRenderMaterial: typeof window.AliFormRenderMaterial !== 'undefined',\n React: typeof window.React !== 'undefined',\n ReactDOM: typeof window.ReactDOM !== 'undefined'\n };\n \n console.log('[XRender] Final checks:', checks);\n \n if (!checks.getFormRenderMaterial) {\n console.error('[XRender] CRITICAL: getFormRenderMaterial is not a function!');\n \n // \u6700\u540E\u5C1D\u8BD5\uFF1A\u4ECE\u7236\u7A97\u53E3\u83B7\u53D6\n try {\n if (window.parent && typeof window.parent.getFormRenderMaterial === 'function') {\n window.getFormRenderMaterial = window.parent.getFormRenderMaterial;\n console.warn('[XRender] Copied getFormRenderMaterial from parent window');\n }\n } catch(e) {}\n }\n \n // \u901A\u77E5\u5F15\u64CE\u5DF2\u52A0\u8F7D\n try {\n window.parent.postMessage({\n type: 'engine-load',\n ready: true,\n checks: checks,\n timestamp: Date.now()\n }, '*');\n } catch(e) {\n console.error('[XRender] Failed to post message to parent:', e);\n }\n }, 1000);\n });\n </script>\n </body>\n </html>\n ";
2
+ // 使用时间戳避免缓存
3
+ var timestamp = Date.now();
4
+ var html = "\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" />\n <meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\">\n <meta http-equiv=\"Pragma\" content=\"no-cache\">\n <meta http-equiv=\"Expires\" content=\"0\">\n <title>XRender</title>\n <link rel=\"icon\" href=\"https://img.alicdn.com/tfs/TB17UtINiLaK1RjSZFxXXamPFXa-606-643.png\">\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/variables.css\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css\" />\n\n <!-- \u5173\u952E\u4FEE\u590D1\uFF1A\u63D0\u524D\u5B9A\u4E49 getFormRenderMaterial \u5360\u4F4D\u7B26 -->\n <script>\n (function() {\n // \u4FDD\u5B58\u771F\u6B63\u7684\u51FD\u6570\u5F15\u7528\n let __realGetFormRenderMaterial = null;\n let __isGetFormRenderMaterialReady = false;\n let __pendingCalls = [];\n \n // \u521B\u5EFA\u5B89\u5168\u7684\u4EE3\u7406\u51FD\u6570\n function __safeGetFormRenderMaterialWrapper(...args) {\n if (__isGetFormRenderMaterialReady && __realGetFormRenderMaterial) {\n return __realGetFormRenderMaterial.apply(this, args);\n }\n \n console.warn('[XRender] getFormRenderMaterial not ready yet, queuing call');\n \n // \u5982\u679C\u662F\u7B2C\u4E09\u65B9\u5E93\u7684\u8C03\u7528\uFF0C\u76F4\u63A5\u8FD4\u56DE\u7A7A\u5BF9\u8C61\u907F\u514D\u9519\u8BEF\n if (args[0] === 'AliFormRenderMaterial' && args[1] === '@ali/form-render-material') {\n console.warn('[XRender] Returning empty object for AliFormRenderMaterial');\n return {};\n }\n \n // \u5176\u4ED6\u8C03\u7528\u6392\u961F\u5904\u7406\n return new Promise((resolve, reject) => {\n __pendingCalls.push({\n args: args,\n resolve: resolve,\n reject: reject\n });\n });\n }\n \n // \u5B9A\u4E49 window.getFormRenderMaterial \u5C5E\u6027\n Object.defineProperty(window, 'getFormRenderMaterial', {\n configurable: true,\n enumerable: true,\n get: function() {\n return __safeGetFormRenderMaterialWrapper;\n },\n set: function(value) {\n console.log('[XRender] Setting getFormRenderMaterial to:', typeof value);\n __realGetFormRenderMaterial = value;\n __isGetFormRenderMaterialReady = true;\n \n // \u6267\u884C\u6392\u961F\u7684\u8C03\u7528\n __pendingCalls.forEach(call => {\n try {\n const result = value.apply(window, call.args);\n call.resolve(result);\n } catch (error) {\n call.reject(error);\n }\n });\n __pendingCalls = [];\n \n // \u901A\u77E5\u7236\u7A97\u53E3\n try {\n window.parent.postMessage({\n type: 'getFormRenderMaterial-ready',\n ready: true,\n timestamp: Date.now()\n }, '*');\n } catch(e) {}\n }\n });\n \n // \u62E6\u622A\u5371\u9669\u8C03\u7528\n const originalDefineProperty = Object.defineProperty;\n Object.defineProperty = function(obj, prop, descriptor) {\n if (prop === 'AliFormRenderMaterial' && obj === window) {\n console.warn('[XRender] Intercepted AliFormRenderMaterial definition');\n \n // \u5EF6\u8FDF\u8BBE\u7F6E AliFormRenderMaterial\n if (descriptor.value !== undefined) {\n const originalValue = descriptor.value;\n descriptor.value = undefined;\n \n setTimeout(() => {\n if (typeof window.getFormRenderMaterial === 'function') {\n try {\n const material = window.getFormRenderMaterial('AliFormRenderMaterial', '@ali/form-render-material');\n window.AliFormRenderMaterial = material || originalValue;\n console.log('[XRender] AliFormRenderMaterial set successfully');\n } catch (e) {\n console.error('[XRender] Error setting AliFormRenderMaterial:', e);\n window.AliFormRenderMaterial = originalValue;\n }\n } else {\n console.warn('[XRender] getFormRenderMaterial not available for AliFormRenderMaterial');\n window.AliFormRenderMaterial = originalValue;\n }\n }, 0);\n }\n }\n return originalDefineProperty.call(this, obj, prop, descriptor);\n };\n })();\n </script>\n\n <script>\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js\"></script>\n\n <!-- \u5173\u952E\u4FEE\u590D2\uFF1A\u4F7F\u7528\u540C\u6B65\u65B9\u5F0F\u52A0\u8F7D fr-generator -->\n <script>\n (function() {\n const maxRetries = 3;\n let retryCount = 0;\n \n function loadFrGenerator() {\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n const url = 'https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js?t=' + ".concat(timestamp, " + '&retry=' + retryCount;\n script.src = url;\n script.type = 'text/javascript';\n \n script.onload = function() {\n console.log('[XRender] fr-generator loaded successfully, attempt', retryCount + 1);\n \n // \u7B49\u5F85\u51FD\u6570\u88AB\u5B9A\u4E49\n let checkCount = 0;\n const maxChecks = 50; // \u6700\u591A\u68C0\u67E55\u79D2\n const checkInterval = setInterval(() => {\n checkCount++;\n if (typeof window.getFormRenderMaterial === 'function') {\n clearInterval(checkInterval);\n console.log('[XRender] \u2713 getFormRenderMaterial is now a function');\n resolve();\n } else if (checkCount >= maxChecks) {\n clearInterval(checkInterval);\n console.warn('[XRender] getFormRenderMaterial not defined after fr-generator load');\n reject(new Error('getFormRenderMaterial not defined'));\n }\n }, 100);\n };\n \n script.onerror = function() {\n console.error('[XRender] Failed to load fr-generator, attempt', retryCount + 1);\n \n if (retryCount < maxRetries - 1) {\n retryCount++;\n setTimeout(() => loadFrGenerator().then(resolve).catch(reject), 1000 * retryCount);\n } else {\n console.error('[XRender] Max retries reached, creating emergency function');\n \n // \u521B\u5EFA\u5E94\u6025\u51FD\u6570\n window.getFormRenderMaterial = function() {\n console.error('[XRender] Using emergency fallback for getFormRenderMaterial');\n return {};\n };\n \n reject(new Error('Failed to load fr-generator after max retries'));\n }\n };\n \n // \u4F7F\u7528 document.write \u786E\u4FDD\u540C\u6B65\u6267\u884C\n document.write(script.outerHTML);\n });\n }\n \n // \u7ACB\u5373\u5F00\u59CB\u52A0\u8F7D\n loadFrGenerator().catch(error => {\n console.error('[XRender] fr-generator load failed:', error);\n });\n })();\n </script>\n </head>\n\n <body>\n <div id=\"lce-container\"></div>\n \n <!-- \u5173\u952E\u4FEE\u590D3\uFF1A\u6700\u7EC8\u68C0\u67E5 -->\n <script>\n window.addEventListener('load', function() {\n console.log('[XRender] Iframe fully loaded');\n \n // \u68C0\u67E5\u5173\u952E\u51FD\u6570\n setTimeout(() => {\n const checks = {\n getFormRenderMaterial: typeof window.getFormRenderMaterial === 'function',\n AliFormRenderMaterial: typeof window.AliFormRenderMaterial !== 'undefined',\n React: typeof window.React !== 'undefined',\n ReactDOM: typeof window.ReactDOM !== 'undefined'\n };\n \n console.log('[XRender] Final checks:', checks);\n \n if (!checks.getFormRenderMaterial) {\n console.error('[XRender] CRITICAL: getFormRenderMaterial is not a function!');\n \n // \u6700\u540E\u5C1D\u8BD5\uFF1A\u4ECE\u7236\u7A97\u53E3\u83B7\u53D6\n try {\n if (window.parent && typeof window.parent.getFormRenderMaterial === 'function') {\n window.getFormRenderMaterial = window.parent.getFormRenderMaterial;\n console.warn('[XRender] Copied getFormRenderMaterial from parent window');\n }\n } catch(e) {}\n }\n \n // \u901A\u77E5\u5F15\u64CE\u5DF2\u52A0\u8F7D\n try {\n window.parent.postMessage({\n type: 'engine-load',\n ready: true,\n checks: checks,\n timestamp: Date.now()\n }, '*');\n } catch(e) {\n console.error('[XRender] Failed to post message to parent:', e);\n }\n }, 1000);\n });\n </script>\n </body>\n </html>\n ");
3
5
  return html;
4
6
  };
5
7
  export default (function () {
@@ -7,6 +9,25 @@ export default (function () {
7
9
  iframe.width = '100%';
8
10
  iframe.height = '100%';
9
11
  iframe.frameBorder = '0';
10
- iframe.srcdoc = createIframeContent();
12
+
13
+ // 使用 Blob URL 避免缓存问题
14
+ var htmlContent = createIframeContent();
15
+ var blob = new Blob([htmlContent], {
16
+ type: 'text/html'
17
+ });
18
+ var url = URL.createObjectURL(blob);
19
+ iframe.src = url;
20
+
21
+ // 清理 Blob URL
22
+ iframe.onload = function () {
23
+ setTimeout(function () {
24
+ return URL.revokeObjectURL(url);
25
+ }, 1000);
26
+ console.log('[XRender] Iframe loaded with Blob URL');
27
+ };
28
+ iframe.onerror = function (error) {
29
+ console.error('[XRender] Iframe load error:', error);
30
+ URL.revokeObjectURL(url);
31
+ };
11
32
  return iframe;
12
33
  });
package/es/main.js CHANGED
@@ -16,132 +16,158 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
16
16
  import React, { useEffect, useRef, useImperativeHandle, forwardRef, useState } from 'react';
17
17
  import createIframe from './createIframe';
18
18
  import * as defaultSetting from './settings';
19
+ var iframe = null;
20
+ var retryCount = 0;
21
+ var MAX_RETRIES = 3;
19
22
  var Design = function Design(props, ref) {
20
23
  var widgets = props.widgets,
21
24
  settings = props.settings,
22
25
  restProps = _objectWithoutProperties(props, _excluded);
23
- var containerRef = useRef(null);
24
- var iframeRef = useRef(null);
26
+ var containerRef = useRef();
25
27
  var _useState = useState(true),
26
28
  _useState2 = _slicedToArray(_useState, 2),
27
29
  loading = _useState2[0],
28
30
  setLoading = _useState2[1];
29
- var retryCountRef = useRef(0);
30
- var MAX_RETRIES = 3;
31
31
  useImperativeHandle(ref, function () {
32
32
  return {
33
33
  getValue: function getValue() {
34
- var _iframeRef$current, _iframeRef$current$co, _iframeRef$current$co2, _iframeRef$current$co3;
35
- return (_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : (_iframeRef$current$co = _iframeRef$current.contentWindow) === null || _iframeRef$current$co === void 0 ? void 0 : (_iframeRef$current$co2 = _iframeRef$current$co.__FR_ENGINE__) === null || _iframeRef$current$co2 === void 0 ? void 0 : (_iframeRef$current$co3 = _iframeRef$current$co2.exportSchema) === null || _iframeRef$current$co3 === void 0 ? void 0 : _iframeRef$current$co3.call(_iframeRef$current$co2);
34
+ var _iframe, _iframe$contentWindow, _iframe$contentWindow2, _iframe$contentWindow3;
35
+ return (_iframe = iframe) === null || _iframe === void 0 ? void 0 : (_iframe$contentWindow = _iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : (_iframe$contentWindow2 = _iframe$contentWindow.__FR_ENGINE__) === null || _iframe$contentWindow2 === void 0 ? void 0 : (_iframe$contentWindow3 = _iframe$contentWindow2.exportSchema) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.call(_iframe$contentWindow2);
36
36
  },
37
37
  setValue: function setValue(schema) {
38
- var _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2, _iframeRef$current2$c3;
39
- return (_iframeRef$current2 = iframeRef.current) === null || _iframeRef$current2 === void 0 ? void 0 : (_iframeRef$current2$c = _iframeRef$current2.contentWindow) === null || _iframeRef$current2$c === void 0 ? void 0 : (_iframeRef$current2$c2 = _iframeRef$current2$c.__FR_ENGINE__) === null || _iframeRef$current2$c2 === void 0 ? void 0 : (_iframeRef$current2$c3 = _iframeRef$current2$c2.importSchema) === null || _iframeRef$current2$c3 === void 0 ? void 0 : _iframeRef$current2$c3.call(_iframeRef$current2$c2, schema);
38
+ var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
39
+ return (_iframe2 = iframe) === null || _iframe2 === void 0 ? void 0 : (_iframe2$contentWindo = _iframe2.contentWindow) === null || _iframe2$contentWindo === void 0 ? void 0 : (_iframe2$contentWindo2 = _iframe2$contentWindo.__FR_ENGINE__) === null || _iframe2$contentWindo2 === void 0 ? void 0 : (_iframe2$contentWindo3 = _iframe2$contentWindo2.importSchema) === null || _iframe2$contentWindo3 === void 0 ? void 0 : _iframe2$contentWindo3.call(_iframe2$contentWindo2, schema);
40
+ },
41
+ reload: function reload() {
42
+ if (containerRef.current && iframe) {
43
+ containerRef.current.removeChild(iframe);
44
+ iframe = null;
45
+ retryCount = 0;
46
+ initIframe();
47
+ }
40
48
  }
41
49
  };
42
50
  });
43
- var _initIframe = function initIframe() {
44
- console.log('[SchemaBuilder] Initializing iframe');
45
-
46
- // 确保容器存在
47
- if (!containerRef.current) {
48
- console.error('[SchemaBuilder] Container not ready');
49
- setTimeout(_initIframe, 100);
50
- return;
51
- }
51
+ useEffect(function () {
52
+ initIframe();
53
+ var messageHandler = handleMessage;
54
+ window.addEventListener('message', messageHandler);
55
+ return function () {
56
+ window.removeEventListener('message', messageHandler);
57
+ if (iframe && containerRef.current) {
58
+ try {
59
+ containerRef.current.removeChild(iframe);
60
+ } catch (e) {}
61
+ iframe = null;
62
+ }
63
+ };
64
+ }, []);
65
+ var initIframe = function initIframe() {
66
+ console.log('[SchemaBuilder] Initializing iframe, retry:', retryCount);
52
67
 
53
68
  // 清理旧的 iframe
54
- if (iframeRef.current && containerRef.current.contains(iframeRef.current)) {
55
- containerRef.current.removeChild(iframeRef.current);
69
+ if (containerRef.current && iframe) {
70
+ try {
71
+ containerRef.current.removeChild(iframe);
72
+ } catch (e) {}
73
+ iframe = null;
56
74
  }
57
75
 
58
76
  // 创建新的 iframe
59
- var iframe = createIframe();
60
- iframeRef.current = iframe;
77
+ iframe = createIframe();
78
+
79
+ // 添加错误处理
80
+ iframe.onerror = function (e) {
81
+ console.error('[SchemaBuilder] Iframe error:', e);
82
+ };
61
83
  iframe.onload = function () {
62
84
  console.log('[SchemaBuilder] Iframe loaded');
63
85
  setLoading(false);
64
86
  };
65
- iframe.onerror = function () {
66
- console.error('[SchemaBuilder] Iframe load error');
67
- retryIframe();
68
- };
69
-
70
- // 添加到 DOM
71
87
  containerRef.current.appendChild(iframe);
88
+
89
+ // 设置超时重试
90
+ setTimeout(function () {
91
+ if (iframe && (!iframe.contentWindow || !iframe.contentDocument)) {
92
+ console.warn('[SchemaBuilder] Iframe load timeout, retrying...');
93
+ retryIframe();
94
+ }
95
+ }, 10000);
72
96
  };
73
97
  var retryIframe = function retryIframe() {
74
- if (retryCountRef.current < MAX_RETRIES) {
75
- retryCountRef.current++;
76
- console.log("[SchemaBuilder] Retrying iframe (".concat(retryCountRef.current, "/").concat(MAX_RETRIES, ")"));
77
- setTimeout(_initIframe, 1000);
98
+ if (retryCount < MAX_RETRIES) {
99
+ retryCount++;
100
+ console.warn("[SchemaBuilder] Retrying iframe creation (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
101
+ initIframe();
78
102
  } else {
79
103
  console.error('[SchemaBuilder] Max retries reached');
80
- setLoading(false);
81
104
  }
82
105
  };
83
- var engineOnLoad = function engineOnLoad(event) {
84
- if (event.data.type !== 'engine-load') {
85
- return;
86
- }
87
- console.log('[SchemaBuilder] Engine load event received');
106
+ var handleMessage = function handleMessage(event) {
107
+ // 处理来自 iframe 的各种消息
108
+ switch (event.data.type) {
109
+ case 'getFormRenderMaterial-ready':
110
+ console.log('[SchemaBuilder] getFormRenderMaterial is ready in iframe');
111
+ break;
112
+ case 'engine-load':
113
+ console.log('[SchemaBuilder] Engine loaded, checks:', event.data.checks);
114
+ if (event.data.checks && !event.data.checks.getFormRenderMaterial) {
115
+ console.error('[SchemaBuilder] getFormRenderMaterial check failed, retrying...');
116
+ setTimeout(retryIframe, 500);
117
+ return;
118
+ }
88
119
 
89
- // 延迟执行以确保 iframe 完全加载
90
- setTimeout(function () {
91
- var _iframeRef$current3, _iframeRef$current3$c;
92
- if ((_iframeRef$current3 = iframeRef.current) === null || _iframeRef$current3 === void 0 ? void 0 : (_iframeRef$current3$c = _iframeRef$current3.contentWindow) === null || _iframeRef$current3$c === void 0 ? void 0 : _iframeRef$current3$c.__FR_ENGINE__) {
93
- iframeRef.current.contentWindow.__FR_ENGINE__.init(_objectSpread({
94
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
95
- widgets: widgets,
96
- logo: {
97
- title: 'XRender'
120
+ // 延迟初始化以确保所有资源就绪
121
+ setTimeout(function () {
122
+ try {
123
+ var _iframe3, _iframe3$contentWindo;
124
+ if ((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : _iframe3$contentWindo.__FR_ENGINE__) {
125
+ iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
126
+ settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
127
+ widgets: widgets,
128
+ logo: {
129
+ title: 'XRender'
130
+ }
131
+ }, restProps));
132
+ console.log('[SchemaBuilder] Engine initialized successfully');
133
+ } else {
134
+ console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe');
135
+ retryIframe();
136
+ }
137
+ } catch (error) {
138
+ console.error('[SchemaBuilder] Error initializing engine:', error);
139
+ retryIframe();
98
140
  }
99
- }, restProps));
100
- console.log('[SchemaBuilder] Engine initialized');
101
- } else {
102
- console.error('[SchemaBuilder] Engine not found in iframe');
103
- retryIframe();
104
- }
105
- }, 300);
141
+ }, 500);
142
+ break;
143
+ default:
144
+ // 其他消息可以忽略
145
+ break;
146
+ }
106
147
  };
107
- useEffect(function () {
108
- // 等待容器渲染完成
109
- var timer = setTimeout(function () {
110
- _initIframe();
111
- }, 100);
112
- window.addEventListener('message', engineOnLoad);
113
- return function () {
114
- clearTimeout(timer);
115
- window.removeEventListener('message', engineOnLoad);
116
-
117
- // 清理 iframe
118
- if (iframeRef.current && containerRef.current) {
119
- try {
120
- containerRef.current.removeChild(iframeRef.current);
121
- } catch (e) {
122
- // 忽略错误
123
- }
124
- }
125
- };
126
- }, []);
127
148
  return /*#__PURE__*/React.createElement(React.Fragment, null, loading && /*#__PURE__*/React.createElement("div", {
128
149
  style: {
129
150
  position: 'absolute',
130
- top: '50%',
131
- left: '50%',
132
- transform: 'translate(-50%, -50%)',
133
- padding: '20px',
134
- backgroundColor: 'rgba(255, 255, 255, 0.9)',
135
- borderRadius: '4px',
136
- boxShadow: '0 2px 8px rgba(0,0,0,0.1)',
151
+ top: 0,
152
+ left: 0,
153
+ right: 0,
154
+ bottom: 0,
155
+ display: 'flex',
156
+ alignItems: 'center',
157
+ justifyContent: 'center',
158
+ backgroundColor: 'rgba(255, 255, 255, 0.8)',
137
159
  zIndex: 10
138
160
  }
139
- }, "\u6B63\u5728\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668..."), /*#__PURE__*/React.createElement("div", {
161
+ }, /*#__PURE__*/React.createElement("div", null, "\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668...", retryCount > 0 && /*#__PURE__*/React.createElement("div", {
162
+ style: {
163
+ fontSize: '12px',
164
+ color: '#666'
165
+ }
166
+ }, "\u91CD\u8BD5 ", retryCount, "/", MAX_RETRIES))), /*#__PURE__*/React.createElement("div", {
140
167
  ref: containerRef,
141
168
  style: {
142
169
  width: '100%',
143
- height: '100%',
144
- minHeight: '500px'
170
+ height: '100%'
145
171
  }
146
172
  }));
147
173
  };
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var createIframeContent = function createIframeContent() {
8
- var html = "\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" />\n <meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\">\n <meta http-equiv=\"Pragma\" content=\"no-cache\">\n <meta http-equiv=\"Expires\" content=\"0\">\n <title>XRender</title>\n <link rel=\"icon\" href=\"https://img.alicdn.com/tfs/TB17UtINiLaK1RjSZFxXXamPFXa-606-643.png\">\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/variables.css\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css\" />\n\n <!-- \u5173\u952E\u4FEE\u590D1\uFF1A\u63D0\u524D\u5B9A\u4E49 getFormRenderMaterial \u5360\u4F4D\u7B26 -->\n <script>\n \n\n (function() {\n // \u4FDD\u5B58\u771F\u6B63\u7684\u51FD\u6570\u5F15\u7528\n let __realGetFormRenderMaterial = null;\n let __isGetFormRenderMaterialReady = false;\n let __pendingCalls = [];\n \n // \u521B\u5EFA\u5B89\u5168\u7684\u4EE3\u7406\u51FD\u6570\n function __safeGetFormRenderMaterialWrapper(...args) {\n if (__isGetFormRenderMaterialReady && __realGetFormRenderMaterial) {\n return __realGetFormRenderMaterial.apply(this, args);\n }\n \n console.warn('[XRender] getFormRenderMaterial not ready yet, queuing call');\n \n // \u5982\u679C\u662F\u7B2C\u4E09\u65B9\u5E93\u7684\u8C03\u7528\uFF0C\u76F4\u63A5\u8FD4\u56DE\u7A7A\u5BF9\u8C61\u907F\u514D\u9519\u8BEF\n if (args[0] === 'AliFormRenderMaterial' && args[1] === '@ali/form-render-material') {\n console.warn('[XRender] Returning empty object for AliFormRenderMaterial');\n return {};\n }\n \n // \u5176\u4ED6\u8C03\u7528\u6392\u961F\u5904\u7406\n return new Promise((resolve, reject) => {\n __pendingCalls.push({\n args: args,\n resolve: resolve,\n reject: reject\n });\n });\n }\n \n // \u5B9A\u4E49 window.getFormRenderMaterial \u5C5E\u6027\n Object.defineProperty(window, 'getFormRenderMaterial', {\n configurable: true,\n enumerable: true,\n get: function() {\n return __safeGetFormRenderMaterialWrapper;\n },\n set: function(value) {\n console.log('[XRender] Setting getFormRenderMaterial to:', typeof value);\n __realGetFormRenderMaterial = value;\n __isGetFormRenderMaterialReady = true;\n \n // \u6267\u884C\u6392\u961F\u7684\u8C03\u7528\n __pendingCalls.forEach(call => {\n try {\n const result = value.apply(window, call.args);\n call.resolve(result);\n } catch (error) {\n call.reject(error);\n }\n });\n __pendingCalls = [];\n \n // \u901A\u77E5\u7236\u7A97\u53E3\n try {\n window.parent.postMessage({\n type: 'getFormRenderMaterial-ready',\n ready: true,\n timestamp: Date.now()\n }, '*');\n } catch(e) {}\n }\n });\n \n // \u62E6\u622A\u5371\u9669\u8C03\u7528\n const originalDefineProperty = Object.defineProperty;\n Object.defineProperty = function(obj, prop, descriptor) {\n if (prop === 'AliFormRenderMaterial' && obj === window) {\n console.warn('[XRender] Intercepted AliFormRenderMaterial definition');\n \n // \u5EF6\u8FDF\u8BBE\u7F6E AliFormRenderMaterial\n if (descriptor.value !== undefined) {\n const originalValue = descriptor.value;\n descriptor.value = undefined;\n \n setTimeout(() => {\n if (typeof window.getFormRenderMaterial === 'function') {\n try {\n const material = window.getFormRenderMaterial('AliFormRenderMaterial', '@ali/form-render-material');\n window.AliFormRenderMaterial = material || originalValue;\n console.log('[XRender] AliFormRenderMaterial set successfully');\n } catch (e) {\n console.error('[XRender] Error setting AliFormRenderMaterial:', e);\n window.AliFormRenderMaterial = originalValue;\n }\n } else {\n console.warn('[XRender] getFormRenderMaterial not available for AliFormRenderMaterial');\n window.AliFormRenderMaterial = originalValue;\n }\n }, 0);\n }\n }\n return originalDefineProperty.call(this, obj, prop, descriptor);\n };\n })();\n </script>\n\n <script>\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js\"></script>\n\n <!-- \u5173\u952E\u4FEE\u590D2\uFF1A\u4F7F\u7528\u540C\u6B65\u65B9\u5F0F\u52A0\u8F7D fr-generator -->\n <script>\n (function() {\n const maxRetries = 3;\n let retryCount = 0;\n \n function loadFrGenerator() {\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n const url = 'https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js?t=' + Date.now() + '&retry=' + retryCount;\n script.src = url;\n script.type = 'text/javascript';\n \n script.onload = function() {\n console.log('[XRender] fr-generator loaded successfully, attempt', retryCount + 1);\n \n // \u7B49\u5F85\u51FD\u6570\u88AB\u5B9A\u4E49\n let checkCount = 0;\n const maxChecks = 50; // \u6700\u591A\u68C0\u67E55\u79D2\n const checkInterval = setInterval(() => {\n checkCount++;\n if (typeof window.getFormRenderMaterial === 'function') {\n clearInterval(checkInterval);\n console.log('[XRender] \u2713 getFormRenderMaterial is now a function');\n resolve();\n } else if (checkCount >= maxChecks) {\n clearInterval(checkInterval);\n console.warn('[XRender] getFormRenderMaterial not defined after fr-generator load');\n reject(new Error('getFormRenderMaterial not defined'));\n }\n }, 100);\n };\n \n script.onerror = function() {\n console.error('[XRender] Failed to load fr-generator, attempt', retryCount + 1);\n \n if (retryCount < maxRetries - 1) {\n retryCount++;\n setTimeout(() => loadFrGenerator().then(resolve).catch(reject), 1000 * retryCount);\n } else {\n console.error('[XRender] Max retries reached, creating emergency function');\n \n // \u521B\u5EFA\u5E94\u6025\u51FD\u6570\n window.getFormRenderMaterial = function() {\n console.error('[XRender] Using emergency fallback for getFormRenderMaterial');\n return {};\n };\n \n reject(new Error('Failed to load fr-generator after max retries'));\n }\n };\n \n // \u4F7F\u7528 document.write \u786E\u4FDD\u540C\u6B65\u6267\u884C\n document.write(script.outerHTML);\n });\n }\n \n // \u7ACB\u5373\u5F00\u59CB\u52A0\u8F7D\n loadFrGenerator().catch(error => {\n console.error('[XRender] fr-generator load failed:', error);\n });\n })();\n </script>\n </head>\n\n <body>\n <div id=\"lce-container\"></div>\n \n <!-- \u5173\u952E\u4FEE\u590D3\uFF1A\u6700\u7EC8\u68C0\u67E5 -->\n <script>\n window.addEventListener('load', function() {\n console.log('[XRender] Iframe fully loaded');\n \n // \u68C0\u67E5\u5173\u952E\u51FD\u6570\n setTimeout(() => {\n const checks = {\n getFormRenderMaterial: typeof window.getFormRenderMaterial === 'function',\n AliFormRenderMaterial: typeof window.AliFormRenderMaterial !== 'undefined',\n React: typeof window.React !== 'undefined',\n ReactDOM: typeof window.ReactDOM !== 'undefined'\n };\n \n console.log('[XRender] Final checks:', checks);\n \n if (!checks.getFormRenderMaterial) {\n console.error('[XRender] CRITICAL: getFormRenderMaterial is not a function!');\n \n // \u6700\u540E\u5C1D\u8BD5\uFF1A\u4ECE\u7236\u7A97\u53E3\u83B7\u53D6\n try {\n if (window.parent && typeof window.parent.getFormRenderMaterial === 'function') {\n window.getFormRenderMaterial = window.parent.getFormRenderMaterial;\n console.warn('[XRender] Copied getFormRenderMaterial from parent window');\n }\n } catch(e) {}\n }\n \n // \u901A\u77E5\u5F15\u64CE\u5DF2\u52A0\u8F7D\n try {\n window.parent.postMessage({\n type: 'engine-load',\n ready: true,\n checks: checks,\n timestamp: Date.now()\n }, '*');\n } catch(e) {\n console.error('[XRender] Failed to post message to parent:', e);\n }\n }, 1000);\n });\n </script>\n </body>\n </html>\n ";
8
+ // 使用时间戳避免缓存
9
+ var timestamp = Date.now();
10
+ var html = "\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" />\n <meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\">\n <meta http-equiv=\"Pragma\" content=\"no-cache\">\n <meta http-equiv=\"Expires\" content=\"0\">\n <title>XRender</title>\n <link rel=\"icon\" href=\"https://img.alicdn.com/tfs/TB17UtINiLaK1RjSZFxXXamPFXa-606-643.png\">\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/variables.css\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css\" />\n\n <!-- \u5173\u952E\u4FEE\u590D1\uFF1A\u63D0\u524D\u5B9A\u4E49 getFormRenderMaterial \u5360\u4F4D\u7B26 -->\n <script>\n (function() {\n // \u4FDD\u5B58\u771F\u6B63\u7684\u51FD\u6570\u5F15\u7528\n let __realGetFormRenderMaterial = null;\n let __isGetFormRenderMaterialReady = false;\n let __pendingCalls = [];\n \n // \u521B\u5EFA\u5B89\u5168\u7684\u4EE3\u7406\u51FD\u6570\n function __safeGetFormRenderMaterialWrapper(...args) {\n if (__isGetFormRenderMaterialReady && __realGetFormRenderMaterial) {\n return __realGetFormRenderMaterial.apply(this, args);\n }\n \n console.warn('[XRender] getFormRenderMaterial not ready yet, queuing call');\n \n // \u5982\u679C\u662F\u7B2C\u4E09\u65B9\u5E93\u7684\u8C03\u7528\uFF0C\u76F4\u63A5\u8FD4\u56DE\u7A7A\u5BF9\u8C61\u907F\u514D\u9519\u8BEF\n if (args[0] === 'AliFormRenderMaterial' && args[1] === '@ali/form-render-material') {\n console.warn('[XRender] Returning empty object for AliFormRenderMaterial');\n return {};\n }\n \n // \u5176\u4ED6\u8C03\u7528\u6392\u961F\u5904\u7406\n return new Promise((resolve, reject) => {\n __pendingCalls.push({\n args: args,\n resolve: resolve,\n reject: reject\n });\n });\n }\n \n // \u5B9A\u4E49 window.getFormRenderMaterial \u5C5E\u6027\n Object.defineProperty(window, 'getFormRenderMaterial', {\n configurable: true,\n enumerable: true,\n get: function() {\n return __safeGetFormRenderMaterialWrapper;\n },\n set: function(value) {\n console.log('[XRender] Setting getFormRenderMaterial to:', typeof value);\n __realGetFormRenderMaterial = value;\n __isGetFormRenderMaterialReady = true;\n \n // \u6267\u884C\u6392\u961F\u7684\u8C03\u7528\n __pendingCalls.forEach(call => {\n try {\n const result = value.apply(window, call.args);\n call.resolve(result);\n } catch (error) {\n call.reject(error);\n }\n });\n __pendingCalls = [];\n \n // \u901A\u77E5\u7236\u7A97\u53E3\n try {\n window.parent.postMessage({\n type: 'getFormRenderMaterial-ready',\n ready: true,\n timestamp: Date.now()\n }, '*');\n } catch(e) {}\n }\n });\n \n // \u62E6\u622A\u5371\u9669\u8C03\u7528\n const originalDefineProperty = Object.defineProperty;\n Object.defineProperty = function(obj, prop, descriptor) {\n if (prop === 'AliFormRenderMaterial' && obj === window) {\n console.warn('[XRender] Intercepted AliFormRenderMaterial definition');\n \n // \u5EF6\u8FDF\u8BBE\u7F6E AliFormRenderMaterial\n if (descriptor.value !== undefined) {\n const originalValue = descriptor.value;\n descriptor.value = undefined;\n \n setTimeout(() => {\n if (typeof window.getFormRenderMaterial === 'function') {\n try {\n const material = window.getFormRenderMaterial('AliFormRenderMaterial', '@ali/form-render-material');\n window.AliFormRenderMaterial = material || originalValue;\n console.log('[XRender] AliFormRenderMaterial set successfully');\n } catch (e) {\n console.error('[XRender] Error setting AliFormRenderMaterial:', e);\n window.AliFormRenderMaterial = originalValue;\n }\n } else {\n console.warn('[XRender] getFormRenderMaterial not available for AliFormRenderMaterial');\n window.AliFormRenderMaterial = originalValue;\n }\n }, 0);\n }\n }\n return originalDefineProperty.call(this, obj, prop, descriptor);\n };\n })();\n </script>\n\n <script>\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js\"></script>\n\n <!-- \u5173\u952E\u4FEE\u590D2\uFF1A\u4F7F\u7528\u540C\u6B65\u65B9\u5F0F\u52A0\u8F7D fr-generator -->\n <script>\n (function() {\n const maxRetries = 3;\n let retryCount = 0;\n \n function loadFrGenerator() {\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n const url = 'https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js?t=' + ".concat(timestamp, " + '&retry=' + retryCount;\n script.src = url;\n script.type = 'text/javascript';\n \n script.onload = function() {\n console.log('[XRender] fr-generator loaded successfully, attempt', retryCount + 1);\n \n // \u7B49\u5F85\u51FD\u6570\u88AB\u5B9A\u4E49\n let checkCount = 0;\n const maxChecks = 50; // \u6700\u591A\u68C0\u67E55\u79D2\n const checkInterval = setInterval(() => {\n checkCount++;\n if (typeof window.getFormRenderMaterial === 'function') {\n clearInterval(checkInterval);\n console.log('[XRender] \u2713 getFormRenderMaterial is now a function');\n resolve();\n } else if (checkCount >= maxChecks) {\n clearInterval(checkInterval);\n console.warn('[XRender] getFormRenderMaterial not defined after fr-generator load');\n reject(new Error('getFormRenderMaterial not defined'));\n }\n }, 100);\n };\n \n script.onerror = function() {\n console.error('[XRender] Failed to load fr-generator, attempt', retryCount + 1);\n \n if (retryCount < maxRetries - 1) {\n retryCount++;\n setTimeout(() => loadFrGenerator().then(resolve).catch(reject), 1000 * retryCount);\n } else {\n console.error('[XRender] Max retries reached, creating emergency function');\n \n // \u521B\u5EFA\u5E94\u6025\u51FD\u6570\n window.getFormRenderMaterial = function() {\n console.error('[XRender] Using emergency fallback for getFormRenderMaterial');\n return {};\n };\n \n reject(new Error('Failed to load fr-generator after max retries'));\n }\n };\n \n // \u4F7F\u7528 document.write \u786E\u4FDD\u540C\u6B65\u6267\u884C\n document.write(script.outerHTML);\n });\n }\n \n // \u7ACB\u5373\u5F00\u59CB\u52A0\u8F7D\n loadFrGenerator().catch(error => {\n console.error('[XRender] fr-generator load failed:', error);\n });\n })();\n </script>\n </head>\n\n <body>\n <div id=\"lce-container\"></div>\n \n <!-- \u5173\u952E\u4FEE\u590D3\uFF1A\u6700\u7EC8\u68C0\u67E5 -->\n <script>\n window.addEventListener('load', function() {\n console.log('[XRender] Iframe fully loaded');\n \n // \u68C0\u67E5\u5173\u952E\u51FD\u6570\n setTimeout(() => {\n const checks = {\n getFormRenderMaterial: typeof window.getFormRenderMaterial === 'function',\n AliFormRenderMaterial: typeof window.AliFormRenderMaterial !== 'undefined',\n React: typeof window.React !== 'undefined',\n ReactDOM: typeof window.ReactDOM !== 'undefined'\n };\n \n console.log('[XRender] Final checks:', checks);\n \n if (!checks.getFormRenderMaterial) {\n console.error('[XRender] CRITICAL: getFormRenderMaterial is not a function!');\n \n // \u6700\u540E\u5C1D\u8BD5\uFF1A\u4ECE\u7236\u7A97\u53E3\u83B7\u53D6\n try {\n if (window.parent && typeof window.parent.getFormRenderMaterial === 'function') {\n window.getFormRenderMaterial = window.parent.getFormRenderMaterial;\n console.warn('[XRender] Copied getFormRenderMaterial from parent window');\n }\n } catch(e) {}\n }\n \n // \u901A\u77E5\u5F15\u64CE\u5DF2\u52A0\u8F7D\n try {\n window.parent.postMessage({\n type: 'engine-load',\n ready: true,\n checks: checks,\n timestamp: Date.now()\n }, '*');\n } catch(e) {\n console.error('[XRender] Failed to post message to parent:', e);\n }\n }, 1000);\n });\n </script>\n </body>\n </html>\n ");
9
11
  return html;
10
12
  };
11
13
  var _default = exports.default = function _default() {
@@ -13,6 +15,25 @@ var _default = exports.default = function _default() {
13
15
  iframe.width = '100%';
14
16
  iframe.height = '100%';
15
17
  iframe.frameBorder = '0';
16
- iframe.srcdoc = createIframeContent();
18
+
19
+ // 使用 Blob URL 避免缓存问题
20
+ var htmlContent = createIframeContent();
21
+ var blob = new Blob([htmlContent], {
22
+ type: 'text/html'
23
+ });
24
+ var url = URL.createObjectURL(blob);
25
+ iframe.src = url;
26
+
27
+ // 清理 Blob URL
28
+ iframe.onload = function () {
29
+ setTimeout(function () {
30
+ return URL.revokeObjectURL(url);
31
+ }, 1000);
32
+ console.log('[XRender] Iframe loaded with Blob URL');
33
+ };
34
+ iframe.onerror = function (error) {
35
+ console.error('[XRender] Iframe load error:', error);
36
+ URL.revokeObjectURL(url);
37
+ };
17
38
  return iframe;
18
39
  };
package/lib/main.js CHANGED
@@ -24,132 +24,158 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
24
24
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
25
25
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
26
26
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
27
+ var iframe = null;
28
+ var retryCount = 0;
29
+ var MAX_RETRIES = 3;
27
30
  var Design = function Design(props, ref) {
28
31
  var widgets = props.widgets,
29
32
  settings = props.settings,
30
33
  restProps = _objectWithoutProperties(props, _excluded);
31
- var containerRef = (0, _react.useRef)(null);
32
- var iframeRef = (0, _react.useRef)(null);
34
+ var containerRef = (0, _react.useRef)();
33
35
  var _useState = (0, _react.useState)(true),
34
36
  _useState2 = _slicedToArray(_useState, 2),
35
37
  loading = _useState2[0],
36
38
  setLoading = _useState2[1];
37
- var retryCountRef = (0, _react.useRef)(0);
38
- var MAX_RETRIES = 3;
39
39
  (0, _react.useImperativeHandle)(ref, function () {
40
40
  return {
41
41
  getValue: function getValue() {
42
- var _iframeRef$current, _iframeRef$current$co, _iframeRef$current$co2, _iframeRef$current$co3;
43
- return (_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : (_iframeRef$current$co = _iframeRef$current.contentWindow) === null || _iframeRef$current$co === void 0 ? void 0 : (_iframeRef$current$co2 = _iframeRef$current$co.__FR_ENGINE__) === null || _iframeRef$current$co2 === void 0 ? void 0 : (_iframeRef$current$co3 = _iframeRef$current$co2.exportSchema) === null || _iframeRef$current$co3 === void 0 ? void 0 : _iframeRef$current$co3.call(_iframeRef$current$co2);
42
+ var _iframe, _iframe$contentWindow, _iframe$contentWindow2, _iframe$contentWindow3;
43
+ return (_iframe = iframe) === null || _iframe === void 0 ? void 0 : (_iframe$contentWindow = _iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : (_iframe$contentWindow2 = _iframe$contentWindow.__FR_ENGINE__) === null || _iframe$contentWindow2 === void 0 ? void 0 : (_iframe$contentWindow3 = _iframe$contentWindow2.exportSchema) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.call(_iframe$contentWindow2);
44
44
  },
45
45
  setValue: function setValue(schema) {
46
- var _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2, _iframeRef$current2$c3;
47
- return (_iframeRef$current2 = iframeRef.current) === null || _iframeRef$current2 === void 0 ? void 0 : (_iframeRef$current2$c = _iframeRef$current2.contentWindow) === null || _iframeRef$current2$c === void 0 ? void 0 : (_iframeRef$current2$c2 = _iframeRef$current2$c.__FR_ENGINE__) === null || _iframeRef$current2$c2 === void 0 ? void 0 : (_iframeRef$current2$c3 = _iframeRef$current2$c2.importSchema) === null || _iframeRef$current2$c3 === void 0 ? void 0 : _iframeRef$current2$c3.call(_iframeRef$current2$c2, schema);
46
+ var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
47
+ return (_iframe2 = iframe) === null || _iframe2 === void 0 ? void 0 : (_iframe2$contentWindo = _iframe2.contentWindow) === null || _iframe2$contentWindo === void 0 ? void 0 : (_iframe2$contentWindo2 = _iframe2$contentWindo.__FR_ENGINE__) === null || _iframe2$contentWindo2 === void 0 ? void 0 : (_iframe2$contentWindo3 = _iframe2$contentWindo2.importSchema) === null || _iframe2$contentWindo3 === void 0 ? void 0 : _iframe2$contentWindo3.call(_iframe2$contentWindo2, schema);
48
+ },
49
+ reload: function reload() {
50
+ if (containerRef.current && iframe) {
51
+ containerRef.current.removeChild(iframe);
52
+ iframe = null;
53
+ retryCount = 0;
54
+ initIframe();
55
+ }
48
56
  }
49
57
  };
50
58
  });
51
- var _initIframe = function initIframe() {
52
- console.log('[SchemaBuilder] Initializing iframe');
53
-
54
- // 确保容器存在
55
- if (!containerRef.current) {
56
- console.error('[SchemaBuilder] Container not ready');
57
- setTimeout(_initIframe, 100);
58
- return;
59
- }
59
+ (0, _react.useEffect)(function () {
60
+ initIframe();
61
+ var messageHandler = handleMessage;
62
+ window.addEventListener('message', messageHandler);
63
+ return function () {
64
+ window.removeEventListener('message', messageHandler);
65
+ if (iframe && containerRef.current) {
66
+ try {
67
+ containerRef.current.removeChild(iframe);
68
+ } catch (e) {}
69
+ iframe = null;
70
+ }
71
+ };
72
+ }, []);
73
+ var initIframe = function initIframe() {
74
+ console.log('[SchemaBuilder] Initializing iframe, retry:', retryCount);
60
75
 
61
76
  // 清理旧的 iframe
62
- if (iframeRef.current && containerRef.current.contains(iframeRef.current)) {
63
- containerRef.current.removeChild(iframeRef.current);
77
+ if (containerRef.current && iframe) {
78
+ try {
79
+ containerRef.current.removeChild(iframe);
80
+ } catch (e) {}
81
+ iframe = null;
64
82
  }
65
83
 
66
84
  // 创建新的 iframe
67
- var iframe = (0, _createIframe.default)();
68
- iframeRef.current = iframe;
85
+ iframe = (0, _createIframe.default)();
86
+
87
+ // 添加错误处理
88
+ iframe.onerror = function (e) {
89
+ console.error('[SchemaBuilder] Iframe error:', e);
90
+ };
69
91
  iframe.onload = function () {
70
92
  console.log('[SchemaBuilder] Iframe loaded');
71
93
  setLoading(false);
72
94
  };
73
- iframe.onerror = function () {
74
- console.error('[SchemaBuilder] Iframe load error');
75
- retryIframe();
76
- };
77
-
78
- // 添加到 DOM
79
95
  containerRef.current.appendChild(iframe);
96
+
97
+ // 设置超时重试
98
+ setTimeout(function () {
99
+ if (iframe && (!iframe.contentWindow || !iframe.contentDocument)) {
100
+ console.warn('[SchemaBuilder] Iframe load timeout, retrying...');
101
+ retryIframe();
102
+ }
103
+ }, 10000);
80
104
  };
81
105
  var retryIframe = function retryIframe() {
82
- if (retryCountRef.current < MAX_RETRIES) {
83
- retryCountRef.current++;
84
- console.log("[SchemaBuilder] Retrying iframe (".concat(retryCountRef.current, "/").concat(MAX_RETRIES, ")"));
85
- setTimeout(_initIframe, 1000);
106
+ if (retryCount < MAX_RETRIES) {
107
+ retryCount++;
108
+ console.warn("[SchemaBuilder] Retrying iframe creation (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
109
+ initIframe();
86
110
  } else {
87
111
  console.error('[SchemaBuilder] Max retries reached');
88
- setLoading(false);
89
112
  }
90
113
  };
91
- var engineOnLoad = function engineOnLoad(event) {
92
- if (event.data.type !== 'engine-load') {
93
- return;
94
- }
95
- console.log('[SchemaBuilder] Engine load event received');
114
+ var handleMessage = function handleMessage(event) {
115
+ // 处理来自 iframe 的各种消息
116
+ switch (event.data.type) {
117
+ case 'getFormRenderMaterial-ready':
118
+ console.log('[SchemaBuilder] getFormRenderMaterial is ready in iframe');
119
+ break;
120
+ case 'engine-load':
121
+ console.log('[SchemaBuilder] Engine loaded, checks:', event.data.checks);
122
+ if (event.data.checks && !event.data.checks.getFormRenderMaterial) {
123
+ console.error('[SchemaBuilder] getFormRenderMaterial check failed, retrying...');
124
+ setTimeout(retryIframe, 500);
125
+ return;
126
+ }
96
127
 
97
- // 延迟执行以确保 iframe 完全加载
98
- setTimeout(function () {
99
- var _iframeRef$current3, _iframeRef$current3$c;
100
- if ((_iframeRef$current3 = iframeRef.current) === null || _iframeRef$current3 === void 0 ? void 0 : (_iframeRef$current3$c = _iframeRef$current3.contentWindow) === null || _iframeRef$current3$c === void 0 ? void 0 : _iframeRef$current3$c.__FR_ENGINE__) {
101
- iframeRef.current.contentWindow.__FR_ENGINE__.init(_objectSpread({
102
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
103
- widgets: widgets,
104
- logo: {
105
- title: 'XRender'
128
+ // 延迟初始化以确保所有资源就绪
129
+ setTimeout(function () {
130
+ try {
131
+ var _iframe3, _iframe3$contentWindo;
132
+ if ((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : _iframe3$contentWindo.__FR_ENGINE__) {
133
+ iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
134
+ settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
135
+ widgets: widgets,
136
+ logo: {
137
+ title: 'XRender'
138
+ }
139
+ }, restProps));
140
+ console.log('[SchemaBuilder] Engine initialized successfully');
141
+ } else {
142
+ console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe');
143
+ retryIframe();
144
+ }
145
+ } catch (error) {
146
+ console.error('[SchemaBuilder] Error initializing engine:', error);
147
+ retryIframe();
106
148
  }
107
- }, restProps));
108
- console.log('[SchemaBuilder] Engine initialized');
109
- } else {
110
- console.error('[SchemaBuilder] Engine not found in iframe');
111
- retryIframe();
112
- }
113
- }, 300);
149
+ }, 500);
150
+ break;
151
+ default:
152
+ // 其他消息可以忽略
153
+ break;
154
+ }
114
155
  };
115
- (0, _react.useEffect)(function () {
116
- // 等待容器渲染完成
117
- var timer = setTimeout(function () {
118
- _initIframe();
119
- }, 100);
120
- window.addEventListener('message', engineOnLoad);
121
- return function () {
122
- clearTimeout(timer);
123
- window.removeEventListener('message', engineOnLoad);
124
-
125
- // 清理 iframe
126
- if (iframeRef.current && containerRef.current) {
127
- try {
128
- containerRef.current.removeChild(iframeRef.current);
129
- } catch (e) {
130
- // 忽略错误
131
- }
132
- }
133
- };
134
- }, []);
135
156
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, loading && /*#__PURE__*/_react.default.createElement("div", {
136
157
  style: {
137
158
  position: 'absolute',
138
- top: '50%',
139
- left: '50%',
140
- transform: 'translate(-50%, -50%)',
141
- padding: '20px',
142
- backgroundColor: 'rgba(255, 255, 255, 0.9)',
143
- borderRadius: '4px',
144
- boxShadow: '0 2px 8px rgba(0,0,0,0.1)',
159
+ top: 0,
160
+ left: 0,
161
+ right: 0,
162
+ bottom: 0,
163
+ display: 'flex',
164
+ alignItems: 'center',
165
+ justifyContent: 'center',
166
+ backgroundColor: 'rgba(255, 255, 255, 0.8)',
145
167
  zIndex: 10
146
168
  }
147
- }, "\u6B63\u5728\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668..."), /*#__PURE__*/_react.default.createElement("div", {
169
+ }, /*#__PURE__*/_react.default.createElement("div", null, "\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668...", retryCount > 0 && /*#__PURE__*/_react.default.createElement("div", {
170
+ style: {
171
+ fontSize: '12px',
172
+ color: '#666'
173
+ }
174
+ }, "\u91CD\u8BD5 ", retryCount, "/", MAX_RETRIES))), /*#__PURE__*/_react.default.createElement("div", {
148
175
  ref: containerRef,
149
176
  style: {
150
177
  width: '100%',
151
- height: '100%',
152
- minHeight: '500px'
178
+ height: '100%'
153
179
  }
154
180
  }));
155
181
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.56",
3
+ "version": "1.0.0-alpha.58",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",