@zzdadelu/schema-builder 1.0.0-alpha.42 → 1.0.0-alpha.44

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,5 @@
1
1
  var createIframeContent = function createIframeContent() {
2
- var 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 <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 <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 <body>\n <div id=\"lce-container\"></div>\n <script type=\"text/javascript\" src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js\"></script>\n </body>\n </html>\n ";
2
+ var 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 <script>\n // \u5173\u952E\u70B91: \u5728\u811A\u672C\u52A0\u8F7D\u524D\u5C31\u5B9A\u4E49\u51FD\u6570\u5360\u4F4D\u7B26\n window.getFormRenderMaterial = window.getFormRenderMaterial || function() {\n console.warn('getFormRenderMaterial placeholder called, waiting for real function...');\n return null;\n };\n \n // \u5173\u952E\u70B92: \u76D1\u542C\u51FD\u6570\u5B9A\u4E49\n let originalDefineProperty = Object.defineProperty;\n Object.defineProperty = function(obj, prop, descriptor) {\n if (prop === 'getFormRenderMaterial' && obj === window) {\n console.log('getFormRenderMaterial is being defined...');\n \n // \u4FEE\u6539getter/setter\u4EE5\u786E\u4FDD\u51FD\u6570\u53EF\u7528\n if (descriptor.get) {\n const originalGetter = descriptor.get;\n descriptor.get = function() {\n const result = originalGetter.call(this);\n console.log('getFormRenderMaterial getter called, returning:', typeof result);\n return result;\n };\n }\n \n if (descriptor.set) {\n const originalSetter = descriptor.set;\n descriptor.set = function(value) {\n console.log('getFormRenderMaterial setter called with:', typeof value);\n originalSetter.call(this, value);\n \n // \u51FD\u6570\u8BBE\u7F6E\u540E\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 return originalDefineProperty.call(this, obj, prop, descriptor);\n };\n \n // \u5173\u952E\u70B93: \u8BBE\u7F6E\u5171\u4EAB\u5BF9\u8C61\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n \n // \u5173\u952E\u70B94: \u6DFB\u52A0\u91CD\u8BD5\u673A\u5236\n window.retryLoadScript = function(url, maxRetries = 3) {\n return new Promise((resolve, reject) => {\n let retryCount = 0;\n \n const loadScript = () => {\n const script = document.createElement('script');\n script.src = url + (url.includes('?') ? '&' : '?') + 't=' + Date.now();\n script.onload = () => {\n console.log('Script loaded successfully:', url);\n resolve();\n };\n script.onerror = () => {\n retryCount++;\n if (retryCount < maxRetries) {\n console.warn(`Failed to load ${url}, retrying (${retryCount}/${maxRetries})...`);\n setTimeout(loadScript, 1000 * retryCount);\n } else {\n console.error(`Failed to load ${url} after ${maxRetries} attempts`);\n reject(new Error(`Failed to load ${url}`));\n }\n }\n document.head.appendChild(script);\n };\n \n loadScript();\n });\n };\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 <body>\n <div id=\"lce-container\"></div>\n \n <!-- \u5173\u952E\u70B95: \u52A8\u6001\u52A0\u8F7Dfr-generator\u5E76\u6DFB\u52A0\u91CD\u8BD5 -->\n <script>\n (function() {\n const maxRetries = 3;\n let currentRetry = 0;\n \n function loadFrGenerator() {\n currentRetry++;\n const script = document.createElement('script');\n const url = 'https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js';\n script.src = url + '?t=' + Date.now() + '&retry=' + currentRetry;\n script.type = 'text/javascript';\n \n script.onload = function() {\n console.log('fr-generator loaded successfully, attempt', currentRetry);\n \n // \u7B49\u5F85\u4E00\u6BB5\u65F6\u95F4\u540E\u68C0\u67E5\u51FD\u6570\u662F\u5426\u5DF2\u5B9A\u4E49\n setTimeout(() => {\n if (typeof window.getFormRenderMaterial === 'function') {\n console.log('\u2713 getFormRenderMaterial is now available');\n \n // \u901A\u77E5\u7236\u7A97\u53E3\n try {\n window.parent.postMessage({\n type: 'fr-generator-loaded',\n success: true,\n hasFunction: true,\n timestamp: Date.now()\n }, '*');\n } catch(e) {}\n \n // \u68C0\u67E5\u662F\u5426\u8FD8\u6709\u5176\u4ED6\u9700\u8981\u7684\u51FD\u6570\n if (window.__FR_ENGINE__) {\n console.log('\u2713 __FR_ENGINE__ is available');\n }\n } else {\n console.warn('getFormRenderMaterial still not a function after fr-generator loaded');\n \n // \u5982\u679C\u662F\u6700\u540E\u4E00\u6B21\u5C1D\u8BD5\uFF0C\u521B\u5EFA\u5E94\u6025\u51FD\u6570\n if (currentRetry >= maxRetries) {\n console.warn('Creating emergency fallback function');\n window.getFormRenderMaterial = function() {\n console.warn('Using emergency fallback for getFormRenderMaterial');\n return {};\n };\n } else {\n // \u91CD\u8BD5\n console.warn('Retrying fr-generator load...');\n setTimeout(loadFrGenerator, 1000);\n }\n }\n }, 500);\n };\n \n script.onerror = function() {\n console.error('Failed to load fr-generator, attempt', currentRetry);\n \n if (currentRetry < maxRetries) {\n console.warn('Retrying in 1 second...');\n setTimeout(loadFrGenerator, 1000);\n } else {\n console.error('Max retries reached for fr-generator');\n \n // \u521B\u5EFA\u7D27\u6025\u56DE\u9000\u51FD\u6570\n window.getFormRenderMaterial = function() {\n console.error('Using emergency fallback after max retries');\n return {};\n };\n \n // \u901A\u77E5\u7236\u7A97\u53E3\u52A0\u8F7D\u5931\u8D25\n try {\n window.parent.postMessage({\n type: 'fr-generator-error',\n error: 'Max retries reached',\n timestamp: Date.now()\n }, '*');\n } catch(e) {}\n }\n };\n \n document.body.appendChild(script);\n }\n \n // \u5EF6\u8FDF\u52A0\u8F7D\uFF0C\u786E\u4FDD\u5176\u4ED6\u811A\u672C\u5148\u6267\u884C\n setTimeout(loadFrGenerator, 100);\n })();\n </script>\n \n <!-- \u5173\u952E\u70B96: \u6700\u7EC8\u68C0\u67E5 -->\n <script>\n // \u5728\u9875\u9762\u5B8C\u5168\u52A0\u8F7D\u540E\u505A\u6700\u7EC8\u68C0\u67E5\n window.addEventListener('load', function() {\n setTimeout(() => {\n console.log('Final check - getFormRenderMaterial:', typeof window.getFormRenderMaterial);\n console.log('Final check - __FR_ENGINE__:', !!window.__FR_ENGINE__);\n \n if (typeof window.getFormRenderMaterial !== 'function') {\n console.error('FINAL WARNING: getFormRenderMaterial is not a function!');\n \n // \u5C1D\u8BD5\u91CD\u65B0\u52A0\u8F7D\u5173\u952E\u8D44\u6E90\n const scripts = document.querySelectorAll('script[src*=\"fr-generator\"]');\n if (scripts.length > 0) {\n const script = scripts[0];\n const newScript = document.createElement('script');\n newScript.src = script.src.split('?')[0] + '?emergency=' + Date.now();\n newScript.onload = function() {\n console.log('Emergency script loaded');\n };\n document.body.appendChild(newScript);\n }\n }\n }, 2000);\n });\n </script>\n </body>\n </html>\n ";
3
3
  return html;
4
4
  };
5
5
  export default (function () {
@@ -7,23 +7,36 @@ export default (function () {
7
7
  iframe.width = '100%';
8
8
  iframe.height = '100%';
9
9
  iframe.frameBorder = '0';
10
- iframe.srcdoc = createIframeContent();
11
- var win = iframe.srcdoc;
12
- var doc = win.contentDocument;
13
- console.warn('createIframeContentwin.contentWindow1', win);
14
- console.warn('createIframeContentwin.contentWindow2', doc);
15
- console.warn('createIframeContentwin.contentWindow3', win.contentWindow);
16
- setTimeout(function () {
17
- try {
18
- var _win$contentWindow;
19
- // 检查函数是否存在
20
- var hasFunction = typeof ((_win$contentWindow = win.contentWindow) === null || _win$contentWindow === void 0 ? void 0 : _win$contentWindow.getFormRenderMaterial) === 'function';
21
- if (!hasFunction) {
22
- console.warn('createIframeContent getFormRenderMaterial not found after iframe loaded');
10
+
11
+ // 使用唯一ID,避免缓存问题
12
+ var iframeId = 'xrender-iframe-' + Date.now() + '-' + Math.random().toString(36).substr(2, 9);
13
+ iframe.id = iframeId;
14
+ iframe.name = iframeId;
15
+
16
+ // 添加加载状态监听
17
+ iframe.onload = function () {
18
+ console.log('Iframe loaded:', iframeId);
19
+
20
+ // 给iframe内部脚本一些时间执行
21
+ setTimeout(function () {
22
+ try {
23
+ // 尝试访问iframe内容
24
+ var iframeWindow = iframe.contentWindow;
25
+ if (iframeWindow) {
26
+ console.log('Iframe contentWindow is accessible', iframeWindow);
27
+ }
28
+ } catch (e) {
29
+ console.error('Error accessing iframe content:', e);
23
30
  }
24
- } catch (e) {
25
- console.error('createIframeContent Error checking function after iframe load:', e);
26
- }
27
- }, 1000);
31
+ }, 1000);
32
+ };
33
+ iframe.onerror = function (error) {
34
+ console.error('Iframe load error:', error);
35
+ };
36
+
37
+ // 使用srcdoc,但添加时间戳避免缓存
38
+ var timestamp = Date.now();
39
+ var htmlContent = createIframeContent();
40
+ iframe.srcdoc = htmlContent;
28
41
  return iframe;
29
42
  });
package/es/main.js CHANGED
@@ -5,16 +5,9 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
5
5
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
6
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
7
7
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
9
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
13
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
14
8
  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
9
  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
- // main.ts
17
- import React, { useEffect, useRef, useImperativeHandle, forwardRef, useState } from 'react';
10
+ import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
18
11
  import createIframe from './createIframe';
19
12
  import * as defaultSetting from './settings';
20
13
  var iframe;
@@ -23,11 +16,6 @@ var Design = function Design(props, ref) {
23
16
  settings = props.settings,
24
17
  restProps = _objectWithoutProperties(props, _excluded);
25
18
  var containerRef = useRef();
26
- var _useState = useState(0),
27
- _useState2 = _slicedToArray(_useState, 2),
28
- retryCount = _useState2[0],
29
- setRetryCount = _useState2[1];
30
- var maxRetries = 3;
31
19
  useImperativeHandle(ref, function () {
32
20
  return {
33
21
  getValue: function getValue() {
@@ -39,191 +27,36 @@ var Design = function Design(props, ref) {
39
27
  setValue: function setValue(schema) {
40
28
  var _iframe4, _iframe4$contentWindo, _iframe4$contentWindo2, _iframe4$contentWindo3;
41
29
  return (_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : (_iframe4$contentWindo = _iframe4.contentWindow) === null || _iframe4$contentWindo === void 0 ? void 0 : (_iframe4$contentWindo2 = _iframe4$contentWindo.__FR_ENGINE__) === null || _iframe4$contentWindo2 === void 0 ? void 0 : (_iframe4$contentWindo3 = _iframe4$contentWindo2.importSchema) === null || _iframe4$contentWindo3 === void 0 ? void 0 : _iframe4$contentWindo3.call(_iframe4$contentWindo2, schema);
42
- },
43
- // 添加检查方法
44
- checkStatus: function checkStatus() {
45
- var _iframe5, _iframe5$contentWindo, _iframe6, _iframe6$contentWindo;
46
- return {
47
- iframeReady: !!iframe,
48
- hasFormRenderMaterial: typeof ((_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : (_iframe5$contentWindo = _iframe5.contentWindow) === null || _iframe5$contentWindo === void 0 ? void 0 : _iframe5$contentWindo.getFormRenderMaterial) === 'function',
49
- hasEngine: !!((_iframe6 = iframe) === null || _iframe6 === void 0 ? void 0 : (_iframe6$contentWindo = _iframe6.contentWindow) === null || _iframe6$contentWindo === void 0 ? void 0 : _iframe6$contentWindo.__FR_ENGINE__)
50
- };
51
30
  }
52
31
  };
53
32
  });
54
33
  useEffect(function () {
55
34
  initIframe();
56
35
  window.addEventListener('message', engineOnLoad);
57
-
58
- // 添加定时检查
59
- var checkInterval = setInterval(checkIframeStatus, 2000);
60
36
  return function () {
61
37
  window.removeEventListener('message', engineOnLoad);
62
- clearInterval(checkInterval);
63
- // 清理iframe
64
- if (iframe && containerRef.current) {
65
- try {
66
- containerRef.current.removeChild(iframe);
67
- } catch (e) {}
68
- iframe = null;
69
- }
70
38
  };
71
39
  }, []);
72
- var checkIframeStatus = function checkIframeStatus() {
73
- if (!iframe) return;
74
- try {
75
- var _iframe$contentWindow, _iframe$contentWindow2;
76
- var hasFunction = typeof ((_iframe$contentWindow = iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : _iframe$contentWindow.getFormRenderMaterial) === 'function';
77
- var hasEngine = !!((_iframe$contentWindow2 = iframe.contentWindow) === null || _iframe$contentWindow2 === void 0 ? void 0 : _iframe$contentWindow2.__FR_ENGINE__);
78
- if (!hasFunction && retryCount < maxRetries) {
79
- console.warn("getFormRenderMaterial not found, retrying... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
80
- setRetryCount(function (prev) {
81
- var newCount = prev + 1;
82
- if (newCount <= maxRetries) {
83
- setTimeout(function () {
84
- return retryIframe();
85
- }, 500);
86
- }
87
- return newCount;
88
- });
89
- }
90
- } catch (e) {
91
- console.error('Error checking iframe status:', e);
92
- }
93
- };
94
40
  var initIframe = function initIframe() {
95
41
  console.log("开始创建 iframe");
96
-
97
- // 清理旧的iframe
98
- if (containerRef.current && iframe) {
99
- try {
100
- containerRef.current.removeChild(iframe);
101
- } catch (e) {}
102
- iframe = null;
103
- }
104
-
105
- // 创建新的iframe
106
42
  iframe = createIframe();
107
-
108
- // 添加加载错误处理
109
- iframe.onerror = function (e) {
110
- console.error('Iframe loading error:', e);
111
- };
112
-
113
- // 添加加载超时处理
114
- var loadTimeout = setTimeout(function () {
115
- if (iframe && (!iframe.contentWindow || !iframe.contentWindow.document)) {
116
- console.error('Iframe load timeout');
117
- retryIframe();
118
- }
119
- }, 10000);
120
- iframe.onload = function () {
121
- clearTimeout(loadTimeout);
122
- console.log("iframe 加载完成");
123
-
124
- // 等待iframe内部脚本执行
125
- setTimeout(function () {
126
- try {
127
- var _iframe$contentWindow3;
128
- // 检查函数是否存在
129
- var hasFunction = typeof ((_iframe$contentWindow3 = iframe.contentWindow) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.getFormRenderMaterial) === 'function';
130
- if (!hasFunction) {
131
- console.warn('getFormRenderMaterial not found after iframe loaded');
132
- }
133
- } catch (e) {
134
- console.error('Error checking function after iframe load:', e);
135
- }
136
- }, 1000);
137
- };
138
43
  containerRef.current.appendChild(iframe);
139
- console.log("iframe 创建完成");
140
- };
141
- var retryIframe = function retryIframe() {
142
- console.log("Retrying iframe creation (attempt ".concat(retryCount + 1, "/").concat(maxRetries, ")"));
143
- initIframe();
44
+ console.log("iframe 创建完成:", containerRef, iframe);
144
45
  };
145
46
  var engineOnLoad = function engineOnLoad(event) {
146
- console.log("收到消息:", event.data);
147
- if (event.data.type === 'xrender-load-error') {
148
- console.error('XRender load error from iframe:', event.data.message);
149
- if (retryCount < maxRetries) {
150
- setTimeout(function () {
151
- return retryIframe();
152
- }, 1000);
153
- }
154
- return;
155
- }
156
- if (event.data.type === 'xrender-fully-loaded') {
157
- console.log('XRender fully loaded, function available:', event.data.available);
158
- if (!event.data.available && retryCount < maxRetries) {
159
- setTimeout(function () {
160
- return retryIframe();
161
- }, 1000);
162
- }
163
- return;
164
- }
47
+ var _iframe5, _iframe5$contentWindo, _iframe5$contentWindo2;
165
48
  if (event.data.type !== 'engine-load') {
166
49
  return;
167
50
  }
168
- console.log("iframe引擎加载事件:", event);
169
-
170
- // 延迟执行以确保函数已定义
171
- setTimeout(function () {
172
- try {
173
- var _iframe7, _iframe7$contentWindo, _iframe9, _iframe9$contentWindo, _iframe9$contentWindo2;
174
- // 再次检查函数是否存在
175
- if (typeof ((_iframe7 = iframe) === null || _iframe7 === void 0 ? void 0 : (_iframe7$contentWindo = _iframe7.contentWindow) === null || _iframe7$contentWindo === void 0 ? void 0 : _iframe7$contentWindo.getFormRenderMaterial) !== 'function') {
176
- console.error('getFormRenderMaterial is not a function when initializing engine');
177
-
178
- // 尝试从其他位置查找函数
179
- var findFunction = function findFunction() {
180
- var _iframe8, _iframeWindow$window, _iframeWindow$parent;
181
- var iframeWindow = (_iframe8 = iframe) === null || _iframe8 === void 0 ? void 0 : _iframe8.contentWindow;
182
- if (!iframeWindow) return null;
183
-
184
- // 尝试多种方式查找
185
- return iframeWindow.getFormRenderMaterial || ((_iframeWindow$window = iframeWindow.window) === null || _iframeWindow$window === void 0 ? void 0 : _iframeWindow$window.getFormRenderMaterial) || ((_iframeWindow$parent = iframeWindow.parent) === null || _iframeWindow$parent === void 0 ? void 0 : _iframeWindow$parent.getFormRenderMaterial) || iframeWindow._xrenderFunctions && iframeWindow._xrenderFunctions.getFormRenderMaterial;
186
- };
187
- var func = findFunction();
188
- if (func && typeof func === 'function') {
189
- console.log('Found getFormRenderMaterial via alternative method');
190
- // 重新赋值
191
- iframe.contentWindow.getFormRenderMaterial = func;
192
- } else if (retryCount < maxRetries) {
193
- console.log('Will retry iframe creation');
194
- setRetryCount(function (prev) {
195
- var newCount = prev + 1;
196
- if (newCount <= maxRetries) {
197
- setTimeout(function () {
198
- return retryIframe();
199
- }, 500);
200
- }
201
- return newCount;
202
- });
203
- return;
204
- }
205
- }
206
-
207
- // 一切正常,初始化引擎
208
- (_iframe9 = iframe) === null || _iframe9 === void 0 ? void 0 : (_iframe9$contentWindo = _iframe9.contentWindow) === null || _iframe9$contentWindo === void 0 ? void 0 : (_iframe9$contentWindo2 = _iframe9$contentWindo.__FR_ENGINE__) === null || _iframe9$contentWindo2 === void 0 ? void 0 : _iframe9$contentWindo2.init(_objectSpread({
209
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
210
- widgets: widgets,
211
- logo: {
212
- title: 'XRender'
213
- }
214
- }, restProps));
215
-
216
- // 重置重试计数
217
- setRetryCount(0);
218
- } catch (error) {
219
- console.error('Error initializing FR_ENGINE:', error);
220
- if (retryCount < maxRetries) {
221
- setTimeout(function () {
222
- return retryIframe();
223
- }, 1000);
224
- }
51
+ console.log("拿到 iframe props:", event);
52
+ (_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : (_iframe5$contentWindo = _iframe5.contentWindow) === null || _iframe5$contentWindo === void 0 ? void 0 : (_iframe5$contentWindo2 = _iframe5$contentWindo.__FR_ENGINE__) === null || _iframe5$contentWindo2 === void 0 ? void 0 : _iframe5$contentWindo2.init(_objectSpread({
53
+ settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
54
+ widgets: widgets,
55
+ // recordEnable: true,
56
+ logo: {
57
+ title: 'XRender'
225
58
  }
226
- }, 100);
59
+ }, restProps));
227
60
  };
228
61
  return /*#__PURE__*/React.createElement("div", {
229
62
  ref: containerRef,
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var createIframeContent = function createIframeContent() {
8
- var 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 <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 <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 <body>\n <div id=\"lce-container\"></div>\n <script type=\"text/javascript\" src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js\"></script>\n </body>\n </html>\n ";
8
+ var 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 <script>\n // \u5173\u952E\u70B91: \u5728\u811A\u672C\u52A0\u8F7D\u524D\u5C31\u5B9A\u4E49\u51FD\u6570\u5360\u4F4D\u7B26\n window.getFormRenderMaterial = window.getFormRenderMaterial || function() {\n console.warn('getFormRenderMaterial placeholder called, waiting for real function...');\n return null;\n };\n \n // \u5173\u952E\u70B92: \u76D1\u542C\u51FD\u6570\u5B9A\u4E49\n let originalDefineProperty = Object.defineProperty;\n Object.defineProperty = function(obj, prop, descriptor) {\n if (prop === 'getFormRenderMaterial' && obj === window) {\n console.log('getFormRenderMaterial is being defined...');\n \n // \u4FEE\u6539getter/setter\u4EE5\u786E\u4FDD\u51FD\u6570\u53EF\u7528\n if (descriptor.get) {\n const originalGetter = descriptor.get;\n descriptor.get = function() {\n const result = originalGetter.call(this);\n console.log('getFormRenderMaterial getter called, returning:', typeof result);\n return result;\n };\n }\n \n if (descriptor.set) {\n const originalSetter = descriptor.set;\n descriptor.set = function(value) {\n console.log('getFormRenderMaterial setter called with:', typeof value);\n originalSetter.call(this, value);\n \n // \u51FD\u6570\u8BBE\u7F6E\u540E\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 return originalDefineProperty.call(this, obj, prop, descriptor);\n };\n \n // \u5173\u952E\u70B93: \u8BBE\u7F6E\u5171\u4EAB\u5BF9\u8C61\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n \n // \u5173\u952E\u70B94: \u6DFB\u52A0\u91CD\u8BD5\u673A\u5236\n window.retryLoadScript = function(url, maxRetries = 3) {\n return new Promise((resolve, reject) => {\n let retryCount = 0;\n \n const loadScript = () => {\n const script = document.createElement('script');\n script.src = url + (url.includes('?') ? '&' : '?') + 't=' + Date.now();\n script.onload = () => {\n console.log('Script loaded successfully:', url);\n resolve();\n };\n script.onerror = () => {\n retryCount++;\n if (retryCount < maxRetries) {\n console.warn(`Failed to load ${url}, retrying (${retryCount}/${maxRetries})...`);\n setTimeout(loadScript, 1000 * retryCount);\n } else {\n console.error(`Failed to load ${url} after ${maxRetries} attempts`);\n reject(new Error(`Failed to load ${url}`));\n }\n }\n document.head.appendChild(script);\n };\n \n loadScript();\n });\n };\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 <body>\n <div id=\"lce-container\"></div>\n \n <!-- \u5173\u952E\u70B95: \u52A8\u6001\u52A0\u8F7Dfr-generator\u5E76\u6DFB\u52A0\u91CD\u8BD5 -->\n <script>\n (function() {\n const maxRetries = 3;\n let currentRetry = 0;\n \n function loadFrGenerator() {\n currentRetry++;\n const script = document.createElement('script');\n const url = 'https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js';\n script.src = url + '?t=' + Date.now() + '&retry=' + currentRetry;\n script.type = 'text/javascript';\n \n script.onload = function() {\n console.log('fr-generator loaded successfully, attempt', currentRetry);\n \n // \u7B49\u5F85\u4E00\u6BB5\u65F6\u95F4\u540E\u68C0\u67E5\u51FD\u6570\u662F\u5426\u5DF2\u5B9A\u4E49\n setTimeout(() => {\n if (typeof window.getFormRenderMaterial === 'function') {\n console.log('\u2713 getFormRenderMaterial is now available');\n \n // \u901A\u77E5\u7236\u7A97\u53E3\n try {\n window.parent.postMessage({\n type: 'fr-generator-loaded',\n success: true,\n hasFunction: true,\n timestamp: Date.now()\n }, '*');\n } catch(e) {}\n \n // \u68C0\u67E5\u662F\u5426\u8FD8\u6709\u5176\u4ED6\u9700\u8981\u7684\u51FD\u6570\n if (window.__FR_ENGINE__) {\n console.log('\u2713 __FR_ENGINE__ is available');\n }\n } else {\n console.warn('getFormRenderMaterial still not a function after fr-generator loaded');\n \n // \u5982\u679C\u662F\u6700\u540E\u4E00\u6B21\u5C1D\u8BD5\uFF0C\u521B\u5EFA\u5E94\u6025\u51FD\u6570\n if (currentRetry >= maxRetries) {\n console.warn('Creating emergency fallback function');\n window.getFormRenderMaterial = function() {\n console.warn('Using emergency fallback for getFormRenderMaterial');\n return {};\n };\n } else {\n // \u91CD\u8BD5\n console.warn('Retrying fr-generator load...');\n setTimeout(loadFrGenerator, 1000);\n }\n }\n }, 500);\n };\n \n script.onerror = function() {\n console.error('Failed to load fr-generator, attempt', currentRetry);\n \n if (currentRetry < maxRetries) {\n console.warn('Retrying in 1 second...');\n setTimeout(loadFrGenerator, 1000);\n } else {\n console.error('Max retries reached for fr-generator');\n \n // \u521B\u5EFA\u7D27\u6025\u56DE\u9000\u51FD\u6570\n window.getFormRenderMaterial = function() {\n console.error('Using emergency fallback after max retries');\n return {};\n };\n \n // \u901A\u77E5\u7236\u7A97\u53E3\u52A0\u8F7D\u5931\u8D25\n try {\n window.parent.postMessage({\n type: 'fr-generator-error',\n error: 'Max retries reached',\n timestamp: Date.now()\n }, '*');\n } catch(e) {}\n }\n };\n \n document.body.appendChild(script);\n }\n \n // \u5EF6\u8FDF\u52A0\u8F7D\uFF0C\u786E\u4FDD\u5176\u4ED6\u811A\u672C\u5148\u6267\u884C\n setTimeout(loadFrGenerator, 100);\n })();\n </script>\n \n <!-- \u5173\u952E\u70B96: \u6700\u7EC8\u68C0\u67E5 -->\n <script>\n // \u5728\u9875\u9762\u5B8C\u5168\u52A0\u8F7D\u540E\u505A\u6700\u7EC8\u68C0\u67E5\n window.addEventListener('load', function() {\n setTimeout(() => {\n console.log('Final check - getFormRenderMaterial:', typeof window.getFormRenderMaterial);\n console.log('Final check - __FR_ENGINE__:', !!window.__FR_ENGINE__);\n \n if (typeof window.getFormRenderMaterial !== 'function') {\n console.error('FINAL WARNING: getFormRenderMaterial is not a function!');\n \n // \u5C1D\u8BD5\u91CD\u65B0\u52A0\u8F7D\u5173\u952E\u8D44\u6E90\n const scripts = document.querySelectorAll('script[src*=\"fr-generator\"]');\n if (scripts.length > 0) {\n const script = scripts[0];\n const newScript = document.createElement('script');\n newScript.src = script.src.split('?')[0] + '?emergency=' + Date.now();\n newScript.onload = function() {\n console.log('Emergency script loaded');\n };\n document.body.appendChild(newScript);\n }\n }\n }, 2000);\n });\n </script>\n </body>\n </html>\n ";
9
9
  return html;
10
10
  };
11
11
  var _default = exports.default = function _default() {
@@ -13,23 +13,36 @@ var _default = exports.default = function _default() {
13
13
  iframe.width = '100%';
14
14
  iframe.height = '100%';
15
15
  iframe.frameBorder = '0';
16
- iframe.srcdoc = createIframeContent();
17
- var win = iframe.srcdoc;
18
- var doc = win.contentDocument;
19
- console.warn('createIframeContentwin.contentWindow1', win);
20
- console.warn('createIframeContentwin.contentWindow2', doc);
21
- console.warn('createIframeContentwin.contentWindow3', win.contentWindow);
22
- setTimeout(function () {
23
- try {
24
- var _win$contentWindow;
25
- // 检查函数是否存在
26
- var hasFunction = typeof ((_win$contentWindow = win.contentWindow) === null || _win$contentWindow === void 0 ? void 0 : _win$contentWindow.getFormRenderMaterial) === 'function';
27
- if (!hasFunction) {
28
- console.warn('createIframeContent getFormRenderMaterial not found after iframe loaded');
16
+
17
+ // 使用唯一ID,避免缓存问题
18
+ var iframeId = 'xrender-iframe-' + Date.now() + '-' + Math.random().toString(36).substr(2, 9);
19
+ iframe.id = iframeId;
20
+ iframe.name = iframeId;
21
+
22
+ // 添加加载状态监听
23
+ iframe.onload = function () {
24
+ console.log('Iframe loaded:', iframeId);
25
+
26
+ // 给iframe内部脚本一些时间执行
27
+ setTimeout(function () {
28
+ try {
29
+ // 尝试访问iframe内容
30
+ var iframeWindow = iframe.contentWindow;
31
+ if (iframeWindow) {
32
+ console.log('Iframe contentWindow is accessible', iframeWindow);
33
+ }
34
+ } catch (e) {
35
+ console.error('Error accessing iframe content:', e);
29
36
  }
30
- } catch (e) {
31
- console.error('createIframeContent Error checking function after iframe load:', e);
32
- }
33
- }, 1000);
37
+ }, 1000);
38
+ };
39
+ iframe.onerror = function (error) {
40
+ console.error('Iframe load error:', error);
41
+ };
42
+
43
+ // 使用srcdoc,但添加时间戳避免缓存
44
+ var timestamp = Date.now();
45
+ var htmlContent = createIframeContent();
46
+ iframe.srcdoc = htmlContent;
34
47
  return iframe;
35
48
  };
package/lib/main.js CHANGED
@@ -8,7 +8,7 @@ exports.default = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _createIframe = _interopRequireDefault(require("./createIframe"));
10
10
  var defaultSetting = _interopRequireWildcard(require("./settings"));
11
- var _excluded = ["widgets", "settings"]; // main.ts
11
+ var _excluded = ["widgets", "settings"];
12
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
14
14
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -16,12 +16,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
16
16
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
17
17
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
18
18
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
20
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
21
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
22
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
23
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
24
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
25
19
  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
20
  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
21
  var iframe;
@@ -30,11 +24,6 @@ var Design = function Design(props, ref) {
30
24
  settings = props.settings,
31
25
  restProps = _objectWithoutProperties(props, _excluded);
32
26
  var containerRef = (0, _react.useRef)();
33
- var _useState = (0, _react.useState)(0),
34
- _useState2 = _slicedToArray(_useState, 2),
35
- retryCount = _useState2[0],
36
- setRetryCount = _useState2[1];
37
- var maxRetries = 3;
38
27
  (0, _react.useImperativeHandle)(ref, function () {
39
28
  return {
40
29
  getValue: function getValue() {
@@ -46,191 +35,36 @@ var Design = function Design(props, ref) {
46
35
  setValue: function setValue(schema) {
47
36
  var _iframe4, _iframe4$contentWindo, _iframe4$contentWindo2, _iframe4$contentWindo3;
48
37
  return (_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : (_iframe4$contentWindo = _iframe4.contentWindow) === null || _iframe4$contentWindo === void 0 ? void 0 : (_iframe4$contentWindo2 = _iframe4$contentWindo.__FR_ENGINE__) === null || _iframe4$contentWindo2 === void 0 ? void 0 : (_iframe4$contentWindo3 = _iframe4$contentWindo2.importSchema) === null || _iframe4$contentWindo3 === void 0 ? void 0 : _iframe4$contentWindo3.call(_iframe4$contentWindo2, schema);
49
- },
50
- // 添加检查方法
51
- checkStatus: function checkStatus() {
52
- var _iframe5, _iframe5$contentWindo, _iframe6, _iframe6$contentWindo;
53
- return {
54
- iframeReady: !!iframe,
55
- hasFormRenderMaterial: typeof ((_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : (_iframe5$contentWindo = _iframe5.contentWindow) === null || _iframe5$contentWindo === void 0 ? void 0 : _iframe5$contentWindo.getFormRenderMaterial) === 'function',
56
- hasEngine: !!((_iframe6 = iframe) === null || _iframe6 === void 0 ? void 0 : (_iframe6$contentWindo = _iframe6.contentWindow) === null || _iframe6$contentWindo === void 0 ? void 0 : _iframe6$contentWindo.__FR_ENGINE__)
57
- };
58
38
  }
59
39
  };
60
40
  });
61
41
  (0, _react.useEffect)(function () {
62
42
  initIframe();
63
43
  window.addEventListener('message', engineOnLoad);
64
-
65
- // 添加定时检查
66
- var checkInterval = setInterval(checkIframeStatus, 2000);
67
44
  return function () {
68
45
  window.removeEventListener('message', engineOnLoad);
69
- clearInterval(checkInterval);
70
- // 清理iframe
71
- if (iframe && containerRef.current) {
72
- try {
73
- containerRef.current.removeChild(iframe);
74
- } catch (e) {}
75
- iframe = null;
76
- }
77
46
  };
78
47
  }, []);
79
- var checkIframeStatus = function checkIframeStatus() {
80
- if (!iframe) return;
81
- try {
82
- var _iframe$contentWindow, _iframe$contentWindow2;
83
- var hasFunction = typeof ((_iframe$contentWindow = iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : _iframe$contentWindow.getFormRenderMaterial) === 'function';
84
- var hasEngine = !!((_iframe$contentWindow2 = iframe.contentWindow) === null || _iframe$contentWindow2 === void 0 ? void 0 : _iframe$contentWindow2.__FR_ENGINE__);
85
- if (!hasFunction && retryCount < maxRetries) {
86
- console.warn("getFormRenderMaterial not found, retrying... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
87
- setRetryCount(function (prev) {
88
- var newCount = prev + 1;
89
- if (newCount <= maxRetries) {
90
- setTimeout(function () {
91
- return retryIframe();
92
- }, 500);
93
- }
94
- return newCount;
95
- });
96
- }
97
- } catch (e) {
98
- console.error('Error checking iframe status:', e);
99
- }
100
- };
101
48
  var initIframe = function initIframe() {
102
49
  console.log("开始创建 iframe");
103
-
104
- // 清理旧的iframe
105
- if (containerRef.current && iframe) {
106
- try {
107
- containerRef.current.removeChild(iframe);
108
- } catch (e) {}
109
- iframe = null;
110
- }
111
-
112
- // 创建新的iframe
113
50
  iframe = (0, _createIframe.default)();
114
-
115
- // 添加加载错误处理
116
- iframe.onerror = function (e) {
117
- console.error('Iframe loading error:', e);
118
- };
119
-
120
- // 添加加载超时处理
121
- var loadTimeout = setTimeout(function () {
122
- if (iframe && (!iframe.contentWindow || !iframe.contentWindow.document)) {
123
- console.error('Iframe load timeout');
124
- retryIframe();
125
- }
126
- }, 10000);
127
- iframe.onload = function () {
128
- clearTimeout(loadTimeout);
129
- console.log("iframe 加载完成");
130
-
131
- // 等待iframe内部脚本执行
132
- setTimeout(function () {
133
- try {
134
- var _iframe$contentWindow3;
135
- // 检查函数是否存在
136
- var hasFunction = typeof ((_iframe$contentWindow3 = iframe.contentWindow) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.getFormRenderMaterial) === 'function';
137
- if (!hasFunction) {
138
- console.warn('getFormRenderMaterial not found after iframe loaded');
139
- }
140
- } catch (e) {
141
- console.error('Error checking function after iframe load:', e);
142
- }
143
- }, 1000);
144
- };
145
51
  containerRef.current.appendChild(iframe);
146
- console.log("iframe 创建完成");
147
- };
148
- var retryIframe = function retryIframe() {
149
- console.log("Retrying iframe creation (attempt ".concat(retryCount + 1, "/").concat(maxRetries, ")"));
150
- initIframe();
52
+ console.log("iframe 创建完成:", containerRef, iframe);
151
53
  };
152
54
  var engineOnLoad = function engineOnLoad(event) {
153
- console.log("收到消息:", event.data);
154
- if (event.data.type === 'xrender-load-error') {
155
- console.error('XRender load error from iframe:', event.data.message);
156
- if (retryCount < maxRetries) {
157
- setTimeout(function () {
158
- return retryIframe();
159
- }, 1000);
160
- }
161
- return;
162
- }
163
- if (event.data.type === 'xrender-fully-loaded') {
164
- console.log('XRender fully loaded, function available:', event.data.available);
165
- if (!event.data.available && retryCount < maxRetries) {
166
- setTimeout(function () {
167
- return retryIframe();
168
- }, 1000);
169
- }
170
- return;
171
- }
55
+ var _iframe5, _iframe5$contentWindo, _iframe5$contentWindo2;
172
56
  if (event.data.type !== 'engine-load') {
173
57
  return;
174
58
  }
175
- console.log("iframe引擎加载事件:", event);
176
-
177
- // 延迟执行以确保函数已定义
178
- setTimeout(function () {
179
- try {
180
- var _iframe7, _iframe7$contentWindo, _iframe9, _iframe9$contentWindo, _iframe9$contentWindo2;
181
- // 再次检查函数是否存在
182
- if (typeof ((_iframe7 = iframe) === null || _iframe7 === void 0 ? void 0 : (_iframe7$contentWindo = _iframe7.contentWindow) === null || _iframe7$contentWindo === void 0 ? void 0 : _iframe7$contentWindo.getFormRenderMaterial) !== 'function') {
183
- console.error('getFormRenderMaterial is not a function when initializing engine');
184
-
185
- // 尝试从其他位置查找函数
186
- var findFunction = function findFunction() {
187
- var _iframe8, _iframeWindow$window, _iframeWindow$parent;
188
- var iframeWindow = (_iframe8 = iframe) === null || _iframe8 === void 0 ? void 0 : _iframe8.contentWindow;
189
- if (!iframeWindow) return null;
190
-
191
- // 尝试多种方式查找
192
- return iframeWindow.getFormRenderMaterial || ((_iframeWindow$window = iframeWindow.window) === null || _iframeWindow$window === void 0 ? void 0 : _iframeWindow$window.getFormRenderMaterial) || ((_iframeWindow$parent = iframeWindow.parent) === null || _iframeWindow$parent === void 0 ? void 0 : _iframeWindow$parent.getFormRenderMaterial) || iframeWindow._xrenderFunctions && iframeWindow._xrenderFunctions.getFormRenderMaterial;
193
- };
194
- var func = findFunction();
195
- if (func && typeof func === 'function') {
196
- console.log('Found getFormRenderMaterial via alternative method');
197
- // 重新赋值
198
- iframe.contentWindow.getFormRenderMaterial = func;
199
- } else if (retryCount < maxRetries) {
200
- console.log('Will retry iframe creation');
201
- setRetryCount(function (prev) {
202
- var newCount = prev + 1;
203
- if (newCount <= maxRetries) {
204
- setTimeout(function () {
205
- return retryIframe();
206
- }, 500);
207
- }
208
- return newCount;
209
- });
210
- return;
211
- }
212
- }
213
-
214
- // 一切正常,初始化引擎
215
- (_iframe9 = iframe) === null || _iframe9 === void 0 ? void 0 : (_iframe9$contentWindo = _iframe9.contentWindow) === null || _iframe9$contentWindo === void 0 ? void 0 : (_iframe9$contentWindo2 = _iframe9$contentWindo.__FR_ENGINE__) === null || _iframe9$contentWindo2 === void 0 ? void 0 : _iframe9$contentWindo2.init(_objectSpread({
216
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
217
- widgets: widgets,
218
- logo: {
219
- title: 'XRender'
220
- }
221
- }, restProps));
222
-
223
- // 重置重试计数
224
- setRetryCount(0);
225
- } catch (error) {
226
- console.error('Error initializing FR_ENGINE:', error);
227
- if (retryCount < maxRetries) {
228
- setTimeout(function () {
229
- return retryIframe();
230
- }, 1000);
231
- }
59
+ console.log("拿到 iframe props:", event);
60
+ (_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : (_iframe5$contentWindo = _iframe5.contentWindow) === null || _iframe5$contentWindo === void 0 ? void 0 : (_iframe5$contentWindo2 = _iframe5$contentWindo.__FR_ENGINE__) === null || _iframe5$contentWindo2 === void 0 ? void 0 : _iframe5$contentWindo2.init(_objectSpread({
61
+ settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
62
+ widgets: widgets,
63
+ // recordEnable: true,
64
+ logo: {
65
+ title: 'XRender'
232
66
  }
233
- }, 100);
67
+ }, restProps));
234
68
  };
235
69
  return /*#__PURE__*/_react.default.createElement("div", {
236
70
  ref: containerRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.42",
3
+ "version": "1.0.0-alpha.44",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",