@zzdadelu/schema-builder 1.0.0-alpha.59 → 1.0.0-alpha.60

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,33 +1,30 @@
1
1
  var createIframeContent = function createIframeContent() {
2
- // 使用时间戳避免缓存
3
2
  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
+ 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 <!-- \u9632\u6B62 getFormRenderMaterial \u9519\u8BEF -->\n <script>\n // \u63D0\u524D\u5B9A\u4E49\u5B89\u5168\u51FD\u6570\n window.getFormRenderMaterial = function() {\n // \u5982\u679C\u5DF2\u7ECF\u6709\u771F\u5B9E\u51FD\u6570\uFF0C\u4F7F\u7528\u5B83\n if (window._realGetFormRenderMaterial) {\n return window._realGetFormRenderMaterial.apply(this, arguments);\n }\n \n console.warn('[XRender] getFormRenderMaterial called before ready');\n \n // \u7279\u6B8A\u5904\u7406 AliFormRenderMaterial \u8C03\u7528\n if (arguments[0] === 'AliFormRenderMaterial' && arguments[1] === '@ali/form-render-material') {\n console.warn('[XRender] Returning placeholder for AliFormRenderMaterial');\n return {};\n }\n \n // \u8FD4\u56DE Promise \u907F\u514D\u540C\u6B65\u9519\u8BEF\n return Promise.resolve({});\n };\n </script>\n\n <script>\n // \u5171\u4EABReact\n try {\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n } catch(e) {\n console.error('[XRender] Error setting React from parent:', e);\n }\n </script>\n \n <!-- \u57FA\u7840\u5E93 -->\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\uFF1Afr-generator -->\n <script src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js?nocache=".concat(timestamp, "\"></script>\n </head>\n\n <body>\n <div id=\"lce-container\"></div>\n \n <!-- \u52A0\u8F7D\u5B8C\u6210\u540E\u901A\u77E5\u7236\u7A97\u53E3 -->\n <script>\n (function() {\n let notified = false;\n \n function notifyParent() {\n if (notified) return;\n \n const checks = {\n React: typeof window.React !== 'undefined',\n ReactDOM: typeof window.ReactDOM !== 'undefined',\n getFormRenderMaterial: typeof window.getFormRenderMaterial === 'function',\n __FR_ENGINE__: typeof window.__FR_ENGINE__ !== 'undefined',\n engineCore: typeof window.AliLowCodeEngine !== 'undefined'\n };\n \n console.log('[XRender] Checks:', checks);\n \n // \u6240\u6709\u68C0\u67E5\u90FD\u901A\u8FC7\u624D\u901A\u77E5\n if (checks.__FR_ENGINE__) {\n notified = true;\n try {\n window.parent.postMessage({\n type: 'engine-load',\n ready: true,\n timestamp: Date.now(),\n checks: checks\n }, '*');\n } catch(e) {\n console.error('[XRender] Failed to post message:', e);\n }\n }\n }\n \n // \u5B9A\u671F\u68C0\u67E5\n const checkInterval = setInterval(() => {\n notifyParent();\n \n // \u5982\u679C\u5DF2\u7ECF\u901A\u77E5\uFF0C\u6E05\u9664\u5B9A\u65F6\u5668\n if (notified) {\n clearInterval(checkInterval);\n }\n }, 500);\n \n // 10\u79D2\u540E\u8D85\u65F6\n setTimeout(() => {\n clearInterval(checkInterval);\n if (!notified) {\n console.error('[XRender] Timeout waiting for resources');\n try {\n window.parent.postMessage({\n type: 'engine-load',\n ready: false,\n timestamp: Date.now()\n }, '*');\n } catch(e) {\n console.error('[XRender] Failed to post timeout message:', e);\n }\n }\n }, 10000);\n \n // \u76D1\u542C\u7A97\u53E3\u52A0\u8F7D\u5B8C\u6210\n window.addEventListener('load', function() {\n console.log('[XRender] Window loaded');\n setTimeout(notifyParent, 1000);\n });\n })();\n </script>\n </body>\n </html>\n ");
5
4
  return html;
6
5
  };
7
6
  export default (function () {
8
7
  var iframe = document.createElement('iframe');
8
+
9
+ // 设置iframe属性
9
10
  iframe.width = '100%';
10
11
  iframe.height = '100%';
11
12
  iframe.frameBorder = '0';
13
+ iframe.style.border = 'none';
14
+ iframe.style.display = 'block';
12
15
 
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;
16
+ // 添加sandbox属性但允许必要权限
17
+ iframe.setAttribute('sandbox', 'allow-same-origin allow-scripts allow-popups allow-forms');
18
+
19
+ // 使用srcdoc
20
+ iframe.srcdoc = createIframeContent();
20
21
 
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
- };
22
+ // 添加加载事件监听
23
+ iframe.addEventListener('load', function () {
24
+ console.log('[createIframe] Iframe loaded successfully');
25
+ });
26
+ iframe.addEventListener('error', function (error) {
27
+ console.error('[createIframe] Iframe error:', error);
28
+ });
32
29
  return iframe;
33
30
  });
package/es/main.js CHANGED
@@ -13,17 +13,17 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
13
13
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
14
14
  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; }
15
15
  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; }
16
- import React, { useEffect, useRef, useImperativeHandle, forwardRef, useState } from 'react';
16
+ import React, { useEffect, useRef, useImperativeHandle, forwardRef, useState, useCallback } from 'react';
17
17
  import createIframe from './createIframe';
18
18
  import * as defaultSetting from './settings';
19
- var iframeInstance = null;
20
- var retryCount = 0;
21
- var MAX_RETRIES = 3;
19
+ // 使用模块变量存储iframe实例,但每个组件实例应该有自己独立的iframe
22
20
  var Design = function Design(props, ref) {
23
21
  var widgets = props.widgets,
24
22
  settings = props.settings,
25
23
  restProps = _objectWithoutProperties(props, _excluded);
26
24
  var containerRef = useRef(null);
25
+ var iframeRef = useRef(null);
26
+ var messageHandlerRef = useRef(null);
27
27
  var _useState = useState(true),
28
28
  _useState2 = _slicedToArray(_useState, 2),
29
29
  loading = _useState2[0],
@@ -32,123 +32,145 @@ var Design = function Design(props, ref) {
32
32
  _useState4 = _slicedToArray(_useState3, 2),
33
33
  loadError = _useState4[0],
34
34
  setLoadError = _useState4[1];
35
+ var _useState5 = useState(0),
36
+ _useState6 = _slicedToArray(_useState5, 2),
37
+ retryCount = _useState6[0],
38
+ setRetryCount = _useState6[1];
39
+ var MAX_RETRIES = 3;
40
+
41
+ // 暴露给父组件的方法
35
42
  useImperativeHandle(ref, function () {
36
43
  return {
37
44
  getValue: function getValue() {
38
- var _iframeInstance, _iframeInstance$conte, _iframeInstance$conte2, _iframeInstance$conte3;
39
- return (_iframeInstance = iframeInstance) === null || _iframeInstance === void 0 ? void 0 : (_iframeInstance$conte = _iframeInstance.contentWindow) === null || _iframeInstance$conte === void 0 ? void 0 : (_iframeInstance$conte2 = _iframeInstance$conte.__FR_ENGINE__) === null || _iframeInstance$conte2 === void 0 ? void 0 : (_iframeInstance$conte3 = _iframeInstance$conte2.exportSchema) === null || _iframeInstance$conte3 === void 0 ? void 0 : _iframeInstance$conte3.call(_iframeInstance$conte2);
45
+ var _iframeRef$current, _iframeRef$current$co, _iframeRef$current$co2, _iframeRef$current$co3;
46
+ 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);
40
47
  },
41
48
  setValue: function setValue(schema) {
42
- var _iframeInstance2, _iframeInstance2$cont, _iframeInstance2$cont2, _iframeInstance2$cont3;
43
- return (_iframeInstance2 = iframeInstance) === null || _iframeInstance2 === void 0 ? void 0 : (_iframeInstance2$cont = _iframeInstance2.contentWindow) === null || _iframeInstance2$cont === void 0 ? void 0 : (_iframeInstance2$cont2 = _iframeInstance2$cont.__FR_ENGINE__) === null || _iframeInstance2$cont2 === void 0 ? void 0 : (_iframeInstance2$cont3 = _iframeInstance2$cont2.importSchema) === null || _iframeInstance2$cont3 === void 0 ? void 0 : _iframeInstance2$cont3.call(_iframeInstance2$cont2, schema);
49
+ var _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2, _iframeRef$current2$c3;
50
+ 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);
44
51
  },
45
52
  reload: function reload() {
46
- if (containerRef.current && iframeInstance) {
47
- try {
48
- containerRef.current.removeChild(iframeInstance);
49
- } catch (e) {
50
- // 忽略错误
51
- }
52
- iframeInstance = null;
53
- retryCount = 0;
54
- setLoadError(null);
55
- setLoading(true);
56
- _initIframe();
57
- }
53
+ cleanup();
54
+ setRetryCount(0);
55
+ setLoadError(null);
56
+ setLoading(true);
57
+ setTimeout(initIframe, 100); // 延迟一点确保状态已更新
58
58
  },
59
59
  getStatus: function getStatus() {
60
60
  return {
61
61
  loading: loading,
62
62
  error: loadError,
63
- iframeReady: !!iframeInstance,
63
+ iframeReady: !!iframeRef.current,
64
64
  retryCount: retryCount
65
65
  };
66
66
  }
67
67
  };
68
68
  });
69
- useEffect(function () {
70
- _initIframe();
71
69
 
72
- // 清理函数
73
- return function () {
74
- if (iframeInstance && containerRef.current) {
75
- try {
76
- containerRef.current.removeChild(iframeInstance);
77
- } catch (e) {
78
- // 忽略错误
70
+ // 清理函数
71
+ var cleanup = useCallback(function () {
72
+ // 移除消息监听器
73
+ if (messageHandlerRef.current) {
74
+ window.removeEventListener('message', messageHandlerRef.current);
75
+ messageHandlerRef.current = null;
76
+ }
77
+
78
+ // 移除iframe
79
+ if (iframeRef.current && containerRef.current) {
80
+ try {
81
+ if (containerRef.current.contains(iframeRef.current)) {
82
+ containerRef.current.removeChild(iframeRef.current);
79
83
  }
80
- iframeInstance = null;
84
+ } catch (error) {
85
+ console.warn('[SchemaBuilder] Error removing iframe:', error);
81
86
  }
82
- };
87
+ iframeRef.current = null;
88
+ }
83
89
  }, []);
84
- var _initIframe = function initIframe() {
90
+
91
+ // 初始化iframe
92
+ var initIframe = useCallback(function () {
85
93
  console.log('[SchemaBuilder] Initializing iframe...');
94
+
95
+ // 确保容器存在
86
96
  if (!containerRef.current) {
87
- console.error('[SchemaBuilder] Container ref is null');
88
- setTimeout(function () {
89
- return _initIframe();
90
- }, 100);
97
+ console.error('[SchemaBuilder] Container ref is null, waiting...');
98
+ setTimeout(initIframe, 100);
91
99
  return;
92
100
  }
93
101
 
94
- // 清理旧的 iframe
95
- if (iframeInstance && containerRef.current.contains(iframeInstance)) {
96
- try {
97
- containerRef.current.removeChild(iframeInstance);
98
- } catch (e) {
99
- console.warn('[SchemaBuilder] Error removing old iframe:', e);
100
- }
101
- }
102
-
103
- // 创建新的 iframe
104
- iframeInstance = createIframe();
102
+ // 清理旧的iframe
103
+ cleanup();
105
104
 
106
- // 添加 iframe 到容器
105
+ // 创建新的iframe
107
106
  try {
108
- containerRef.current.appendChild(iframeInstance);
109
- console.log('[SchemaBuilder] Iframe appended to container');
110
- } catch (error) {
111
- console.error('[SchemaBuilder] Error appending iframe:', error);
112
- setLoadError('无法创建表单设计器');
113
- setLoading(false);
114
- return;
115
- }
107
+ var iframe = createIframe();
108
+ iframeRef.current = iframe;
116
109
 
117
- // 设置消息监听
118
- var messageHandler = handleMessage;
119
- window.addEventListener('message', messageHandler);
110
+ // 确保容器可见且已挂载
111
+ if (containerRef.current && containerRef.current.parentNode) {
112
+ containerRef.current.appendChild(iframe);
113
+ console.log('[SchemaBuilder] Iframe appended successfully');
120
114
 
121
- // 设置超时检查
122
- var timeoutId = setTimeout(function () {
123
- console.warn('[SchemaBuilder] Iframe initialization timeout');
124
- if (loading) {
125
- retryIframe();
115
+ // 设置消息监听器
116
+ messageHandlerRef.current = handleMessage;
117
+ window.addEventListener('message', messageHandlerRef.current);
118
+
119
+ // 设置超时检查
120
+ setTimeout(function () {
121
+ if (loading && iframeRef.current) {
122
+ console.warn('[SchemaBuilder] Iframe load timeout');
123
+ handleLoadTimeout();
124
+ }
125
+ }, 15000);
126
+ } else {
127
+ console.error('[SchemaBuilder] Container not mounted in DOM');
128
+ handleLoadError('容器未正确挂载到DOM');
126
129
  }
127
- }, 15000);
130
+ } catch (error) {
131
+ console.error('[SchemaBuilder] Error creating iframe:', error);
132
+ handleLoadError('创建表单设计器失败');
133
+ }
134
+ }, [cleanup, loading]);
128
135
 
129
- // 清理函数
130
- return function () {
131
- window.removeEventListener('message', messageHandler);
132
- clearTimeout(timeoutId);
133
- };
134
- };
135
- var retryIframe = function retryIframe() {
136
+ // 处理加载超时
137
+ var handleLoadTimeout = useCallback(function () {
138
+ console.warn('[SchemaBuilder] Iframe load timeout');
139
+ if (retryCount < MAX_RETRIES) {
140
+ var newRetryCount = retryCount + 1;
141
+ setRetryCount(newRetryCount);
142
+ setLoadError("\u52A0\u8F7D\u8D85\u65F6\uFF0C\u6B63\u5728\u91CD\u8BD5... (".concat(newRetryCount, "/").concat(MAX_RETRIES, ")"));
143
+ setTimeout(function () {
144
+ cleanup();
145
+ initIframe();
146
+ }, 1000);
147
+ } else {
148
+ setLoadError('表单设计器加载超时,请刷新页面重试');
149
+ setLoading(false);
150
+ }
151
+ }, [retryCount, cleanup, initIframe]);
152
+
153
+ // 处理加载错误
154
+ var handleLoadError = useCallback(function (message) {
155
+ console.error('[SchemaBuilder] Load error:', message);
136
156
  if (retryCount < MAX_RETRIES) {
137
- retryCount++;
138
- console.warn("[SchemaBuilder] Retrying iframe initialization (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
139
- setLoadError("\u6B63\u5728\u91CD\u8BD5... (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
157
+ var newRetryCount = retryCount + 1;
158
+ setRetryCount(newRetryCount);
159
+ setLoadError("".concat(message, "\uFF0C\u6B63\u5728\u91CD\u8BD5... (").concat(newRetryCount, "/").concat(MAX_RETRIES, ")"));
140
160
  setTimeout(function () {
141
- _initIframe();
161
+ cleanup();
162
+ initIframe();
142
163
  }, 1000);
143
164
  } else {
144
- console.error('[SchemaBuilder] Max retries reached');
145
- setLoadError('表单设计器加载失败,请刷新页面重试');
165
+ setLoadError("".concat(message, "\uFF0C\u8BF7\u5237\u65B0\u9875\u9762\u91CD\u8BD5"));
146
166
  setLoading(false);
147
167
  }
148
- };
149
- var handleMessage = function handleMessage(event) {
150
- // 只处理来自我们 iframe 的消息
151
- if (!iframeInstance || event.source !== iframeInstance.contentWindow) {
168
+ }, [retryCount, cleanup, initIframe]);
169
+
170
+ // 消息处理器
171
+ var handleMessage = useCallback(function (event) {
172
+ // 检查消息是否来自我们的iframe
173
+ if (!iframeRef.current || event.source !== iframeRef.current.contentWindow) {
152
174
  return;
153
175
  }
154
176
  console.log('[SchemaBuilder] Received message:', event.data.type);
@@ -157,47 +179,48 @@ var Design = function Design(props, ref) {
157
179
  if (event.data.ready) {
158
180
  console.log('[SchemaBuilder] Engine loaded, checks:', event.data.checks);
159
181
 
160
- // 检查关键资源
161
- if (!event.data.checks || !event.data.checks.__FR_ENGINE__) {
162
- console.error('[SchemaBuilder] __FR_ENGINE__ not found in checks');
163
- setTimeout(function () {
164
- var _iframeInstance3, _iframeInstance3$cont;
165
- // 延迟检查,可能 fr-generator 还在初始化
166
- if (!((_iframeInstance3 = iframeInstance) === null || _iframeInstance3 === void 0 ? void 0 : (_iframeInstance3$cont = _iframeInstance3.contentWindow) === null || _iframeInstance3$cont === void 0 ? void 0 : _iframeInstance3$cont.__FR_ENGINE__)) {
167
- console.warn('[SchemaBuilder] __FR_ENGINE__ still not found, retrying...');
168
- retryIframe();
169
- } else {
170
- initializeEngine();
171
- }
172
- }, 1000);
173
- return;
174
- }
175
-
176
- // 一切正常,初始化引擎
177
- initializeEngine();
182
+ // 等待一小段时间确保所有资源就绪
183
+ setTimeout(function () {
184
+ var _iframeRef$current3, _iframeRef$current3$c;
185
+ 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__) {
186
+ initializeEngine();
187
+ } else {
188
+ console.warn('[SchemaBuilder] __FR_ENGINE__ not found, retrying check...');
189
+ // 再等一会重试
190
+ setTimeout(function () {
191
+ var _iframeRef$current4, _iframeRef$current4$c;
192
+ if ((_iframeRef$current4 = iframeRef.current) === null || _iframeRef$current4 === void 0 ? void 0 : (_iframeRef$current4$c = _iframeRef$current4.contentWindow) === null || _iframeRef$current4$c === void 0 ? void 0 : _iframeRef$current4$c.__FR_ENGINE__) {
193
+ initializeEngine();
194
+ } else {
195
+ handleLoadError('表单引擎加载失败');
196
+ }
197
+ }, 1000);
198
+ }
199
+ }, 500);
178
200
  } else {
179
- console.error('[SchemaBuilder] Engine not ready');
180
- retryIframe();
201
+ handleLoadError('引擎未就绪');
181
202
  }
182
203
  break;
183
204
  default:
184
205
  // 忽略其他消息
185
206
  break;
186
207
  }
187
- };
188
- var initializeEngine = function initializeEngine() {
208
+ }, [handleLoadError]);
209
+
210
+ // 初始化引擎
211
+ var initializeEngine = useCallback(function () {
189
212
  console.log('[SchemaBuilder] Initializing engine...');
190
- if (!iframeInstance || !iframeInstance.contentWindow) {
213
+ if (!iframeRef.current || !iframeRef.current.contentWindow) {
191
214
  console.error('[SchemaBuilder] Iframe not ready for engine initialization');
192
- retryIframe();
215
+ handleLoadError('iframe未就绪');
193
216
  return;
194
217
  }
195
- var iframeWindow = iframeInstance.contentWindow;
218
+ var iframeWindow = iframeRef.current.contentWindow;
196
219
 
197
220
  // 再次检查关键对象
198
221
  if (!iframeWindow.__FR_ENGINE__) {
199
222
  console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe window');
200
- retryIframe();
223
+ handleLoadError('表单引擎未找到');
201
224
  return;
202
225
  }
203
226
  try {
@@ -218,10 +241,32 @@ var Design = function Design(props, ref) {
218
241
  }
219
242
  } catch (error) {
220
243
  console.error('[SchemaBuilder] Error initializing engine:', error);
221
- setLoadError('引擎初始化失败');
222
- retryIframe();
244
+ handleLoadError('引擎初始化失败');
223
245
  }
224
- };
246
+ }, [settings, widgets, restProps, props.onMount, handleLoadError]);
247
+
248
+ // 组件挂载时初始化
249
+ useEffect(function () {
250
+ // 延迟初始化,确保容器已渲染
251
+ var timer = setTimeout(function () {
252
+ initIframe();
253
+ }, 100);
254
+
255
+ // 清理函数
256
+ return function () {
257
+ clearTimeout(timer);
258
+ cleanup();
259
+ };
260
+ }, [initIframe, cleanup]);
261
+
262
+ // 处理手动重试
263
+ var handleManualRetry = useCallback(function () {
264
+ setRetryCount(0);
265
+ setLoadError(null);
266
+ setLoading(true);
267
+ cleanup();
268
+ setTimeout(initIframe, 100);
269
+ }, [cleanup, initIframe]);
225
270
  return /*#__PURE__*/React.createElement("div", {
226
271
  style: {
227
272
  width: '100%',
@@ -239,40 +284,76 @@ var Design = function Design(props, ref) {
239
284
  flexDirection: 'column',
240
285
  alignItems: 'center',
241
286
  justifyContent: 'center',
242
- backgroundColor: 'rgba(255, 255, 255, 0.9)',
243
- zIndex: 10
287
+ backgroundColor: 'rgba(255, 255, 255, 0.95)',
288
+ zIndex: 10,
289
+ padding: '20px',
290
+ boxSizing: 'border-box'
244
291
  }
245
292
  }, loadError ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
246
293
  style: {
247
294
  color: '#f5222d',
248
- marginBottom: 16
295
+ marginBottom: 16,
296
+ textAlign: 'center',
297
+ fontSize: '14px'
249
298
  }
250
299
  }, loadError), /*#__PURE__*/React.createElement("button", {
251
- onClick: function onClick() {
252
- retryCount = 0;
253
- setLoadError(null);
254
- _initIframe();
255
- },
300
+ onClick: handleManualRetry,
256
301
  style: {
257
302
  padding: '8px 16px',
258
303
  backgroundColor: '#1890ff',
259
304
  color: 'white',
260
305
  border: 'none',
261
306
  borderRadius: '4px',
262
- cursor: 'pointer'
307
+ cursor: 'pointer',
308
+ fontSize: '14px'
263
309
  }
264
- }, "\u91CD\u8BD5")) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", null, "\u6B63\u5728\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668..."), /*#__PURE__*/React.createElement("div", {
310
+ }, "\u91CD\u65B0\u52A0\u8F7D"), /*#__PURE__*/React.createElement("button", {
311
+ onClick: function onClick() {
312
+ return window.location.reload();
313
+ },
314
+ style: {
315
+ padding: '8px 16px',
316
+ backgroundColor: 'transparent',
317
+ color: '#1890ff',
318
+ border: '1px solid #1890ff',
319
+ borderRadius: '4px',
320
+ cursor: 'pointer',
321
+ marginTop: '8px',
322
+ fontSize: '14px'
323
+ }
324
+ }, "\u5237\u65B0\u9875\u9762")) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
325
+ style: {
326
+ marginBottom: '8px'
327
+ }
328
+ }, "\u6B63\u5728\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668..."), /*#__PURE__*/React.createElement("div", {
265
329
  style: {
266
330
  fontSize: 12,
267
331
  color: '#666',
268
- marginTop: 8
332
+ marginBottom: 16
269
333
  }
270
- }, "\u8BF7\u7A0D\u5019 ", retryCount > 0 && "(\u91CD\u8BD5 ".concat(retryCount, "/").concat(MAX_RETRIES, ")")))), /*#__PURE__*/React.createElement("div", {
334
+ }, "\u8FD9\u53EF\u80FD\u9700\u8981\u51E0\u79D2\u949F\u65F6\u95F4 ", retryCount > 0 && "(\u91CD\u8BD5 ".concat(retryCount, "/").concat(MAX_RETRIES, ")")), /*#__PURE__*/React.createElement("div", {
335
+ style: {
336
+ width: '200px',
337
+ height: '4px',
338
+ backgroundColor: '#f0f0f0',
339
+ borderRadius: '2px'
340
+ }
341
+ }, /*#__PURE__*/React.createElement("div", {
342
+ style: {
343
+ width: '60%',
344
+ height: '100%',
345
+ backgroundColor: '#1890ff',
346
+ borderRadius: '2px',
347
+ animation: 'loading 1.5s ease-in-out infinite'
348
+ }
349
+ })))), /*#__PURE__*/React.createElement("div", {
271
350
  ref: containerRef,
272
351
  style: {
273
352
  width: '100%',
274
- height: '100%'
353
+ height: '100%',
354
+ minHeight: '500px',
355
+ position: 'relative'
275
356
  }
276
- }));
357
+ }), /*#__PURE__*/React.createElement("style", null, "\n @keyframes loading {\n 0% { transform: translateX(-100%); }\n 50% { transform: translateX(100%); }\n 100% { transform: translateX(100%); }\n }\n "));
277
358
  };
278
359
  export default /*#__PURE__*/forwardRef(Design);
@@ -5,35 +5,32 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var createIframeContent = function createIframeContent() {
8
- // 使用时间戳避免缓存
9
8
  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
+ 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 <!-- \u9632\u6B62 getFormRenderMaterial \u9519\u8BEF -->\n <script>\n // \u63D0\u524D\u5B9A\u4E49\u5B89\u5168\u51FD\u6570\n window.getFormRenderMaterial = function() {\n // \u5982\u679C\u5DF2\u7ECF\u6709\u771F\u5B9E\u51FD\u6570\uFF0C\u4F7F\u7528\u5B83\n if (window._realGetFormRenderMaterial) {\n return window._realGetFormRenderMaterial.apply(this, arguments);\n }\n \n console.warn('[XRender] getFormRenderMaterial called before ready');\n \n // \u7279\u6B8A\u5904\u7406 AliFormRenderMaterial \u8C03\u7528\n if (arguments[0] === 'AliFormRenderMaterial' && arguments[1] === '@ali/form-render-material') {\n console.warn('[XRender] Returning placeholder for AliFormRenderMaterial');\n return {};\n }\n \n // \u8FD4\u56DE Promise \u907F\u514D\u540C\u6B65\u9519\u8BEF\n return Promise.resolve({});\n };\n </script>\n\n <script>\n // \u5171\u4EABReact\n try {\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n } catch(e) {\n console.error('[XRender] Error setting React from parent:', e);\n }\n </script>\n \n <!-- \u57FA\u7840\u5E93 -->\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\uFF1Afr-generator -->\n <script src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js?nocache=".concat(timestamp, "\"></script>\n </head>\n\n <body>\n <div id=\"lce-container\"></div>\n \n <!-- \u52A0\u8F7D\u5B8C\u6210\u540E\u901A\u77E5\u7236\u7A97\u53E3 -->\n <script>\n (function() {\n let notified = false;\n \n function notifyParent() {\n if (notified) return;\n \n const checks = {\n React: typeof window.React !== 'undefined',\n ReactDOM: typeof window.ReactDOM !== 'undefined',\n getFormRenderMaterial: typeof window.getFormRenderMaterial === 'function',\n __FR_ENGINE__: typeof window.__FR_ENGINE__ !== 'undefined',\n engineCore: typeof window.AliLowCodeEngine !== 'undefined'\n };\n \n console.log('[XRender] Checks:', checks);\n \n // \u6240\u6709\u68C0\u67E5\u90FD\u901A\u8FC7\u624D\u901A\u77E5\n if (checks.__FR_ENGINE__) {\n notified = true;\n try {\n window.parent.postMessage({\n type: 'engine-load',\n ready: true,\n timestamp: Date.now(),\n checks: checks\n }, '*');\n } catch(e) {\n console.error('[XRender] Failed to post message:', e);\n }\n }\n }\n \n // \u5B9A\u671F\u68C0\u67E5\n const checkInterval = setInterval(() => {\n notifyParent();\n \n // \u5982\u679C\u5DF2\u7ECF\u901A\u77E5\uFF0C\u6E05\u9664\u5B9A\u65F6\u5668\n if (notified) {\n clearInterval(checkInterval);\n }\n }, 500);\n \n // 10\u79D2\u540E\u8D85\u65F6\n setTimeout(() => {\n clearInterval(checkInterval);\n if (!notified) {\n console.error('[XRender] Timeout waiting for resources');\n try {\n window.parent.postMessage({\n type: 'engine-load',\n ready: false,\n timestamp: Date.now()\n }, '*');\n } catch(e) {\n console.error('[XRender] Failed to post timeout message:', e);\n }\n }\n }, 10000);\n \n // \u76D1\u542C\u7A97\u53E3\u52A0\u8F7D\u5B8C\u6210\n window.addEventListener('load', function() {\n console.log('[XRender] Window loaded');\n setTimeout(notifyParent, 1000);\n });\n })();\n </script>\n </body>\n </html>\n ");
11
10
  return html;
12
11
  };
13
12
  var _default = exports.default = function _default() {
14
13
  var iframe = document.createElement('iframe');
14
+
15
+ // 设置iframe属性
15
16
  iframe.width = '100%';
16
17
  iframe.height = '100%';
17
18
  iframe.frameBorder = '0';
19
+ iframe.style.border = 'none';
20
+ iframe.style.display = 'block';
18
21
 
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;
22
+ // 添加sandbox属性但允许必要权限
23
+ iframe.setAttribute('sandbox', 'allow-same-origin allow-scripts allow-popups allow-forms');
24
+
25
+ // 使用srcdoc
26
+ iframe.srcdoc = createIframeContent();
26
27
 
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
- };
28
+ // 添加加载事件监听
29
+ iframe.addEventListener('load', function () {
30
+ console.log('[createIframe] Iframe loaded successfully');
31
+ });
32
+ iframe.addEventListener('error', function (error) {
33
+ console.error('[createIframe] Iframe error:', error);
34
+ });
38
35
  return iframe;
39
36
  };
package/lib/main.js CHANGED
@@ -24,14 +24,14 @@ 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 iframeInstance = null;
28
- var retryCount = 0;
29
- var MAX_RETRIES = 3;
27
+ // 使用模块变量存储iframe实例,但每个组件实例应该有自己独立的iframe
30
28
  var Design = function Design(props, ref) {
31
29
  var widgets = props.widgets,
32
30
  settings = props.settings,
33
31
  restProps = _objectWithoutProperties(props, _excluded);
34
32
  var containerRef = (0, _react.useRef)(null);
33
+ var iframeRef = (0, _react.useRef)(null);
34
+ var messageHandlerRef = (0, _react.useRef)(null);
35
35
  var _useState = (0, _react.useState)(true),
36
36
  _useState2 = _slicedToArray(_useState, 2),
37
37
  loading = _useState2[0],
@@ -40,123 +40,145 @@ var Design = function Design(props, ref) {
40
40
  _useState4 = _slicedToArray(_useState3, 2),
41
41
  loadError = _useState4[0],
42
42
  setLoadError = _useState4[1];
43
+ var _useState5 = (0, _react.useState)(0),
44
+ _useState6 = _slicedToArray(_useState5, 2),
45
+ retryCount = _useState6[0],
46
+ setRetryCount = _useState6[1];
47
+ var MAX_RETRIES = 3;
48
+
49
+ // 暴露给父组件的方法
43
50
  (0, _react.useImperativeHandle)(ref, function () {
44
51
  return {
45
52
  getValue: function getValue() {
46
- var _iframeInstance, _iframeInstance$conte, _iframeInstance$conte2, _iframeInstance$conte3;
47
- return (_iframeInstance = iframeInstance) === null || _iframeInstance === void 0 ? void 0 : (_iframeInstance$conte = _iframeInstance.contentWindow) === null || _iframeInstance$conte === void 0 ? void 0 : (_iframeInstance$conte2 = _iframeInstance$conte.__FR_ENGINE__) === null || _iframeInstance$conte2 === void 0 ? void 0 : (_iframeInstance$conte3 = _iframeInstance$conte2.exportSchema) === null || _iframeInstance$conte3 === void 0 ? void 0 : _iframeInstance$conte3.call(_iframeInstance$conte2);
53
+ var _iframeRef$current, _iframeRef$current$co, _iframeRef$current$co2, _iframeRef$current$co3;
54
+ 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);
48
55
  },
49
56
  setValue: function setValue(schema) {
50
- var _iframeInstance2, _iframeInstance2$cont, _iframeInstance2$cont2, _iframeInstance2$cont3;
51
- return (_iframeInstance2 = iframeInstance) === null || _iframeInstance2 === void 0 ? void 0 : (_iframeInstance2$cont = _iframeInstance2.contentWindow) === null || _iframeInstance2$cont === void 0 ? void 0 : (_iframeInstance2$cont2 = _iframeInstance2$cont.__FR_ENGINE__) === null || _iframeInstance2$cont2 === void 0 ? void 0 : (_iframeInstance2$cont3 = _iframeInstance2$cont2.importSchema) === null || _iframeInstance2$cont3 === void 0 ? void 0 : _iframeInstance2$cont3.call(_iframeInstance2$cont2, schema);
57
+ var _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2, _iframeRef$current2$c3;
58
+ 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);
52
59
  },
53
60
  reload: function reload() {
54
- if (containerRef.current && iframeInstance) {
55
- try {
56
- containerRef.current.removeChild(iframeInstance);
57
- } catch (e) {
58
- // 忽略错误
59
- }
60
- iframeInstance = null;
61
- retryCount = 0;
62
- setLoadError(null);
63
- setLoading(true);
64
- _initIframe();
65
- }
61
+ cleanup();
62
+ setRetryCount(0);
63
+ setLoadError(null);
64
+ setLoading(true);
65
+ setTimeout(initIframe, 100); // 延迟一点确保状态已更新
66
66
  },
67
67
  getStatus: function getStatus() {
68
68
  return {
69
69
  loading: loading,
70
70
  error: loadError,
71
- iframeReady: !!iframeInstance,
71
+ iframeReady: !!iframeRef.current,
72
72
  retryCount: retryCount
73
73
  };
74
74
  }
75
75
  };
76
76
  });
77
- (0, _react.useEffect)(function () {
78
- _initIframe();
79
77
 
80
- // 清理函数
81
- return function () {
82
- if (iframeInstance && containerRef.current) {
83
- try {
84
- containerRef.current.removeChild(iframeInstance);
85
- } catch (e) {
86
- // 忽略错误
78
+ // 清理函数
79
+ var cleanup = (0, _react.useCallback)(function () {
80
+ // 移除消息监听器
81
+ if (messageHandlerRef.current) {
82
+ window.removeEventListener('message', messageHandlerRef.current);
83
+ messageHandlerRef.current = null;
84
+ }
85
+
86
+ // 移除iframe
87
+ if (iframeRef.current && containerRef.current) {
88
+ try {
89
+ if (containerRef.current.contains(iframeRef.current)) {
90
+ containerRef.current.removeChild(iframeRef.current);
87
91
  }
88
- iframeInstance = null;
92
+ } catch (error) {
93
+ console.warn('[SchemaBuilder] Error removing iframe:', error);
89
94
  }
90
- };
95
+ iframeRef.current = null;
96
+ }
91
97
  }, []);
92
- var _initIframe = function initIframe() {
98
+
99
+ // 初始化iframe
100
+ var initIframe = (0, _react.useCallback)(function () {
93
101
  console.log('[SchemaBuilder] Initializing iframe...');
102
+
103
+ // 确保容器存在
94
104
  if (!containerRef.current) {
95
- console.error('[SchemaBuilder] Container ref is null');
96
- setTimeout(function () {
97
- return _initIframe();
98
- }, 100);
105
+ console.error('[SchemaBuilder] Container ref is null, waiting...');
106
+ setTimeout(initIframe, 100);
99
107
  return;
100
108
  }
101
109
 
102
- // 清理旧的 iframe
103
- if (iframeInstance && containerRef.current.contains(iframeInstance)) {
104
- try {
105
- containerRef.current.removeChild(iframeInstance);
106
- } catch (e) {
107
- console.warn('[SchemaBuilder] Error removing old iframe:', e);
108
- }
109
- }
110
-
111
- // 创建新的 iframe
112
- iframeInstance = (0, _createIframe.default)();
110
+ // 清理旧的iframe
111
+ cleanup();
113
112
 
114
- // 添加 iframe 到容器
113
+ // 创建新的iframe
115
114
  try {
116
- containerRef.current.appendChild(iframeInstance);
117
- console.log('[SchemaBuilder] Iframe appended to container');
118
- } catch (error) {
119
- console.error('[SchemaBuilder] Error appending iframe:', error);
120
- setLoadError('无法创建表单设计器');
121
- setLoading(false);
122
- return;
123
- }
115
+ var iframe = (0, _createIframe.default)();
116
+ iframeRef.current = iframe;
124
117
 
125
- // 设置消息监听
126
- var messageHandler = handleMessage;
127
- window.addEventListener('message', messageHandler);
118
+ // 确保容器可见且已挂载
119
+ if (containerRef.current && containerRef.current.parentNode) {
120
+ containerRef.current.appendChild(iframe);
121
+ console.log('[SchemaBuilder] Iframe appended successfully');
128
122
 
129
- // 设置超时检查
130
- var timeoutId = setTimeout(function () {
131
- console.warn('[SchemaBuilder] Iframe initialization timeout');
132
- if (loading) {
133
- retryIframe();
123
+ // 设置消息监听器
124
+ messageHandlerRef.current = handleMessage;
125
+ window.addEventListener('message', messageHandlerRef.current);
126
+
127
+ // 设置超时检查
128
+ setTimeout(function () {
129
+ if (loading && iframeRef.current) {
130
+ console.warn('[SchemaBuilder] Iframe load timeout');
131
+ handleLoadTimeout();
132
+ }
133
+ }, 15000);
134
+ } else {
135
+ console.error('[SchemaBuilder] Container not mounted in DOM');
136
+ handleLoadError('容器未正确挂载到DOM');
134
137
  }
135
- }, 15000);
138
+ } catch (error) {
139
+ console.error('[SchemaBuilder] Error creating iframe:', error);
140
+ handleLoadError('创建表单设计器失败');
141
+ }
142
+ }, [cleanup, loading]);
136
143
 
137
- // 清理函数
138
- return function () {
139
- window.removeEventListener('message', messageHandler);
140
- clearTimeout(timeoutId);
141
- };
142
- };
143
- var retryIframe = function retryIframe() {
144
+ // 处理加载超时
145
+ var handleLoadTimeout = (0, _react.useCallback)(function () {
146
+ console.warn('[SchemaBuilder] Iframe load timeout');
147
+ if (retryCount < MAX_RETRIES) {
148
+ var newRetryCount = retryCount + 1;
149
+ setRetryCount(newRetryCount);
150
+ setLoadError("\u52A0\u8F7D\u8D85\u65F6\uFF0C\u6B63\u5728\u91CD\u8BD5... (".concat(newRetryCount, "/").concat(MAX_RETRIES, ")"));
151
+ setTimeout(function () {
152
+ cleanup();
153
+ initIframe();
154
+ }, 1000);
155
+ } else {
156
+ setLoadError('表单设计器加载超时,请刷新页面重试');
157
+ setLoading(false);
158
+ }
159
+ }, [retryCount, cleanup, initIframe]);
160
+
161
+ // 处理加载错误
162
+ var handleLoadError = (0, _react.useCallback)(function (message) {
163
+ console.error('[SchemaBuilder] Load error:', message);
144
164
  if (retryCount < MAX_RETRIES) {
145
- retryCount++;
146
- console.warn("[SchemaBuilder] Retrying iframe initialization (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
147
- setLoadError("\u6B63\u5728\u91CD\u8BD5... (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
165
+ var newRetryCount = retryCount + 1;
166
+ setRetryCount(newRetryCount);
167
+ setLoadError("".concat(message, "\uFF0C\u6B63\u5728\u91CD\u8BD5... (").concat(newRetryCount, "/").concat(MAX_RETRIES, ")"));
148
168
  setTimeout(function () {
149
- _initIframe();
169
+ cleanup();
170
+ initIframe();
150
171
  }, 1000);
151
172
  } else {
152
- console.error('[SchemaBuilder] Max retries reached');
153
- setLoadError('表单设计器加载失败,请刷新页面重试');
173
+ setLoadError("".concat(message, "\uFF0C\u8BF7\u5237\u65B0\u9875\u9762\u91CD\u8BD5"));
154
174
  setLoading(false);
155
175
  }
156
- };
157
- var handleMessage = function handleMessage(event) {
158
- // 只处理来自我们 iframe 的消息
159
- if (!iframeInstance || event.source !== iframeInstance.contentWindow) {
176
+ }, [retryCount, cleanup, initIframe]);
177
+
178
+ // 消息处理器
179
+ var handleMessage = (0, _react.useCallback)(function (event) {
180
+ // 检查消息是否来自我们的iframe
181
+ if (!iframeRef.current || event.source !== iframeRef.current.contentWindow) {
160
182
  return;
161
183
  }
162
184
  console.log('[SchemaBuilder] Received message:', event.data.type);
@@ -165,47 +187,48 @@ var Design = function Design(props, ref) {
165
187
  if (event.data.ready) {
166
188
  console.log('[SchemaBuilder] Engine loaded, checks:', event.data.checks);
167
189
 
168
- // 检查关键资源
169
- if (!event.data.checks || !event.data.checks.__FR_ENGINE__) {
170
- console.error('[SchemaBuilder] __FR_ENGINE__ not found in checks');
171
- setTimeout(function () {
172
- var _iframeInstance3, _iframeInstance3$cont;
173
- // 延迟检查,可能 fr-generator 还在初始化
174
- if (!((_iframeInstance3 = iframeInstance) === null || _iframeInstance3 === void 0 ? void 0 : (_iframeInstance3$cont = _iframeInstance3.contentWindow) === null || _iframeInstance3$cont === void 0 ? void 0 : _iframeInstance3$cont.__FR_ENGINE__)) {
175
- console.warn('[SchemaBuilder] __FR_ENGINE__ still not found, retrying...');
176
- retryIframe();
177
- } else {
178
- initializeEngine();
179
- }
180
- }, 1000);
181
- return;
182
- }
183
-
184
- // 一切正常,初始化引擎
185
- initializeEngine();
190
+ // 等待一小段时间确保所有资源就绪
191
+ setTimeout(function () {
192
+ var _iframeRef$current3, _iframeRef$current3$c;
193
+ 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__) {
194
+ initializeEngine();
195
+ } else {
196
+ console.warn('[SchemaBuilder] __FR_ENGINE__ not found, retrying check...');
197
+ // 再等一会重试
198
+ setTimeout(function () {
199
+ var _iframeRef$current4, _iframeRef$current4$c;
200
+ if ((_iframeRef$current4 = iframeRef.current) === null || _iframeRef$current4 === void 0 ? void 0 : (_iframeRef$current4$c = _iframeRef$current4.contentWindow) === null || _iframeRef$current4$c === void 0 ? void 0 : _iframeRef$current4$c.__FR_ENGINE__) {
201
+ initializeEngine();
202
+ } else {
203
+ handleLoadError('表单引擎加载失败');
204
+ }
205
+ }, 1000);
206
+ }
207
+ }, 500);
186
208
  } else {
187
- console.error('[SchemaBuilder] Engine not ready');
188
- retryIframe();
209
+ handleLoadError('引擎未就绪');
189
210
  }
190
211
  break;
191
212
  default:
192
213
  // 忽略其他消息
193
214
  break;
194
215
  }
195
- };
196
- var initializeEngine = function initializeEngine() {
216
+ }, [handleLoadError]);
217
+
218
+ // 初始化引擎
219
+ var initializeEngine = (0, _react.useCallback)(function () {
197
220
  console.log('[SchemaBuilder] Initializing engine...');
198
- if (!iframeInstance || !iframeInstance.contentWindow) {
221
+ if (!iframeRef.current || !iframeRef.current.contentWindow) {
199
222
  console.error('[SchemaBuilder] Iframe not ready for engine initialization');
200
- retryIframe();
223
+ handleLoadError('iframe未就绪');
201
224
  return;
202
225
  }
203
- var iframeWindow = iframeInstance.contentWindow;
226
+ var iframeWindow = iframeRef.current.contentWindow;
204
227
 
205
228
  // 再次检查关键对象
206
229
  if (!iframeWindow.__FR_ENGINE__) {
207
230
  console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe window');
208
- retryIframe();
231
+ handleLoadError('表单引擎未找到');
209
232
  return;
210
233
  }
211
234
  try {
@@ -226,10 +249,32 @@ var Design = function Design(props, ref) {
226
249
  }
227
250
  } catch (error) {
228
251
  console.error('[SchemaBuilder] Error initializing engine:', error);
229
- setLoadError('引擎初始化失败');
230
- retryIframe();
252
+ handleLoadError('引擎初始化失败');
231
253
  }
232
- };
254
+ }, [settings, widgets, restProps, props.onMount, handleLoadError]);
255
+
256
+ // 组件挂载时初始化
257
+ (0, _react.useEffect)(function () {
258
+ // 延迟初始化,确保容器已渲染
259
+ var timer = setTimeout(function () {
260
+ initIframe();
261
+ }, 100);
262
+
263
+ // 清理函数
264
+ return function () {
265
+ clearTimeout(timer);
266
+ cleanup();
267
+ };
268
+ }, [initIframe, cleanup]);
269
+
270
+ // 处理手动重试
271
+ var handleManualRetry = (0, _react.useCallback)(function () {
272
+ setRetryCount(0);
273
+ setLoadError(null);
274
+ setLoading(true);
275
+ cleanup();
276
+ setTimeout(initIframe, 100);
277
+ }, [cleanup, initIframe]);
233
278
  return /*#__PURE__*/_react.default.createElement("div", {
234
279
  style: {
235
280
  width: '100%',
@@ -247,40 +292,76 @@ var Design = function Design(props, ref) {
247
292
  flexDirection: 'column',
248
293
  alignItems: 'center',
249
294
  justifyContent: 'center',
250
- backgroundColor: 'rgba(255, 255, 255, 0.9)',
251
- zIndex: 10
295
+ backgroundColor: 'rgba(255, 255, 255, 0.95)',
296
+ zIndex: 10,
297
+ padding: '20px',
298
+ boxSizing: 'border-box'
252
299
  }
253
300
  }, loadError ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
254
301
  style: {
255
302
  color: '#f5222d',
256
- marginBottom: 16
303
+ marginBottom: 16,
304
+ textAlign: 'center',
305
+ fontSize: '14px'
257
306
  }
258
307
  }, loadError), /*#__PURE__*/_react.default.createElement("button", {
259
- onClick: function onClick() {
260
- retryCount = 0;
261
- setLoadError(null);
262
- _initIframe();
263
- },
308
+ onClick: handleManualRetry,
264
309
  style: {
265
310
  padding: '8px 16px',
266
311
  backgroundColor: '#1890ff',
267
312
  color: 'white',
268
313
  border: 'none',
269
314
  borderRadius: '4px',
270
- cursor: 'pointer'
315
+ cursor: 'pointer',
316
+ fontSize: '14px'
271
317
  }
272
- }, "\u91CD\u8BD5")) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", null, "\u6B63\u5728\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668..."), /*#__PURE__*/_react.default.createElement("div", {
318
+ }, "\u91CD\u65B0\u52A0\u8F7D"), /*#__PURE__*/_react.default.createElement("button", {
319
+ onClick: function onClick() {
320
+ return window.location.reload();
321
+ },
322
+ style: {
323
+ padding: '8px 16px',
324
+ backgroundColor: 'transparent',
325
+ color: '#1890ff',
326
+ border: '1px solid #1890ff',
327
+ borderRadius: '4px',
328
+ cursor: 'pointer',
329
+ marginTop: '8px',
330
+ fontSize: '14px'
331
+ }
332
+ }, "\u5237\u65B0\u9875\u9762")) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
333
+ style: {
334
+ marginBottom: '8px'
335
+ }
336
+ }, "\u6B63\u5728\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668..."), /*#__PURE__*/_react.default.createElement("div", {
273
337
  style: {
274
338
  fontSize: 12,
275
339
  color: '#666',
276
- marginTop: 8
340
+ marginBottom: 16
277
341
  }
278
- }, "\u8BF7\u7A0D\u5019 ", retryCount > 0 && "(\u91CD\u8BD5 ".concat(retryCount, "/").concat(MAX_RETRIES, ")")))), /*#__PURE__*/_react.default.createElement("div", {
342
+ }, "\u8FD9\u53EF\u80FD\u9700\u8981\u51E0\u79D2\u949F\u65F6\u95F4 ", retryCount > 0 && "(\u91CD\u8BD5 ".concat(retryCount, "/").concat(MAX_RETRIES, ")")), /*#__PURE__*/_react.default.createElement("div", {
343
+ style: {
344
+ width: '200px',
345
+ height: '4px',
346
+ backgroundColor: '#f0f0f0',
347
+ borderRadius: '2px'
348
+ }
349
+ }, /*#__PURE__*/_react.default.createElement("div", {
350
+ style: {
351
+ width: '60%',
352
+ height: '100%',
353
+ backgroundColor: '#1890ff',
354
+ borderRadius: '2px',
355
+ animation: 'loading 1.5s ease-in-out infinite'
356
+ }
357
+ })))), /*#__PURE__*/_react.default.createElement("div", {
279
358
  ref: containerRef,
280
359
  style: {
281
360
  width: '100%',
282
- height: '100%'
361
+ height: '100%',
362
+ minHeight: '500px',
363
+ position: 'relative'
283
364
  }
284
- }));
365
+ }), /*#__PURE__*/_react.default.createElement("style", null, "\n @keyframes loading {\n 0% { transform: translateX(-100%); }\n 50% { transform: translateX(100%); }\n 100% { transform: translateX(100%); }\n }\n "));
285
366
  };
286
367
  var _default = exports.default = /*#__PURE__*/(0, _react.forwardRef)(Design);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.59",
3
+ "version": "1.0.0-alpha.60",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",