@zzdadelu/schema-builder 1.0.0-alpha.72 → 1.0.0-alpha.73

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,7 +1,5 @@
1
- // 修改 createIframe.ts
2
- var createIframeContent = function createIframeContent() {
3
- var timestamp = new Date().getTime();
4
- 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?t=".concat(timestamp, "\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css?t=").concat(timestamp, "\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css?t=").concat(timestamp, "\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css?t=").concat(timestamp, "\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css?t=").concat(timestamp, "\" />\n\n <script>\n // \u76D1\u542C\u7236\u7A97\u53E3\u7684\u6D88\u606F\n window.addEventListener('message', function(event) {\n // \u786E\u4FDD\u6D88\u606F\u6765\u6E90\u53EF\u4FE1\n if (event.source !== window.parent) return;\n \n if (event.data.type === 'SET_GET_FORM_RENDER_MATERIAL') {\n console.log('Received getFormRenderMaterial from parent');\n \n // \u5C06\u7236\u7A97\u53E3\u4F20\u9012\u7684\u51FD\u6570\u8BBE\u7F6E\u4E3A\u5168\u5C40\u65B9\u6CD5\n window.getFormRenderMaterial = function() {\n console.log('getFormRenderMaterial called (from parent)');\n \n // \u8FD9\u91CC\u53EF\u4EE5\u8C03\u7528\u7236\u7A97\u53E3\u4F20\u9012\u7684\u5B9E\u73B0\uFF0C\u6216\u8005\u4F7F\u7528\u672C\u5730\u5B9E\u73B0\n if (event.data.implementation) {\n try {\n // \u4F7F\u7528\u7236\u7A97\u53E3\u4F20\u9012\u7684\u5B9E\u73B0\n return event.data.implementation.apply(this, arguments);\n } catch(e) {\n console.error('Error calling parent implementation:', e);\n }\n }\n \n // \u540E\u5907\u5B9E\u73B0\n return {};\n };\n \n // \u786E\u8BA4\u8BBE\u7F6E\u5B8C\u6210\n window.parent.postMessage({\n type: 'GET_FORM_RENDER_MATERIAL_SET',\n success: true\n }, '*');\n }\n });\n \n // \u9884\u5B9A\u4E49\u4E00\u4E2A\u5B89\u5168\u7684 getFormRenderMaterial \u51FD\u6570\n window.getFormRenderMaterial = window.getFormRenderMaterial || function() {\n console.warn('getFormRenderMaterial called before initialization');\n return {};\n };\n \n // \u8BBE\u7F6E\u5176\u4ED6\u5FC5\u8981\u7684\u5168\u5C40\u53D8\u91CF\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n window.__is_simulator_env__ = true;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js?t=").concat(timestamp, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js?t=").concat(timestamp, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js?t=").concat(timestamp, "\"></script>\n </head>\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?t=").concat(timestamp, "\"></script>\n </body>\n </html>\n ");
1
+ var createIframeContent = function createIframeContent(timestamp) {
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 <!-- Shim: \u5728\u5916\u5C42 iframe \u5185\u63D0\u4F9B\u4E00\u4E2A\u4E34\u65F6\u5B89\u5168\u5B9E\u73B0\uFF0C\u907F\u514D\u7B2C\u4E09\u65B9\u5185\u8054\u811A\u672C\u7ACB\u5373\u62A5\u9519 -->\n <script>\n (function() {\n try {\n if (typeof window.getFormRenderMaterial !== 'function') {\n var __fr_q = [];\n var __fr_shim = function() {\n __fr_q.push({ args: Array.prototype.slice.call(arguments) });\n return { __esModule: true };\n };\n window.getFormRenderMaterial = __fr_shim;\n var __fr_iv = setInterval(function() {\n try {\n if (typeof window.getFormRenderMaterial === 'function' && window.getFormRenderMaterial !== __fr_shim) {\n var __real = window.getFormRenderMaterial;\n clearInterval(__fr_iv);\n setTimeout(function() {\n try {\n __fr_q.forEach(function(item) {\n try { __real.apply(null, item.args); } catch (e) {}\n });\n } catch (e) {}\n __fr_q = null;\n }, 0);\n }\n } catch (e) {}\n }, 50);\n }\n } catch (e) {}\n })();\n </script>\n\n <!-- Observer: \u76D1\u63A7\u672C iframe \u6587\u6863\u4E2D\u65B0\u589E\u7684\u5B50 iframe\uFF08\u7B2C\u4E09\u65B9 create-simulator \u53EF\u80FD\u521B\u5EFA\u7684\u5D4C\u5957 iframe\uFF09\u5E76\u5C3D\u5FEB\u4FEE\u8865 -->\n <script>\n (function() {\n var ts = ".concat(timestamp, ";\n function tryPatchChildIframe(iframeEl) {\n try {\n // \u82E5 contentWindow \u53EF\u7528\uFF0C\u7ACB\u5373\u5728\u5B50 iframe \u7684 window \u4E0A\u653E\u4E2A\u5B89\u5168\u5360\u4F4D\u51FD\u6570\n var cw = iframeEl.contentWindow;\n if (cw) {\n if (typeof cw.getFormRenderMaterial !== 'function') {\n try {\n cw.getFormRenderMaterial = function() {\n return { __esModule: true };\n };\n } catch (e) {}\n }\n }\n } catch (e) {}\n }\n\n // \u5F53\u5B50 iframe \u52A0\u8F7D\u5B8C\u6210\u540E\uFF0C\u5C1D\u8BD5\u4FEE\u8865\u5176\u5185\u90E8 script \u7684 src\uFF0C\u52A0\u65F6\u95F4\u6233\u4EE5\u907F\u514D\u7F13\u5B58\u5BFC\u81F4\u65E7\u7248\u95EE\u9898\uFF1B\u5E76\u786E\u4FDD child window \u6709 getFormRenderMaterial\n function onChildFrameLoad(iframeEl) {\n try {\n var doc = iframeEl.contentDocument || iframeEl.contentWindow && iframeEl.contentWindow.document;\n if (!doc) return;\n // \u4FEE\u8865\u53EF\u80FD\u7684\u5916\u90E8\u811A\u672C url\uFF08\u793A\u4F8B\uFF1Afr-generator / react-simulator-renderer \u7B49\uFF09\n var scripts = Array.prototype.slice.call(doc.getElementsByTagName('script'));\n scripts.forEach(function(s) {\n if (s.src && /fr-generator\\/.*index\\.js|react-simulator-renderer\\.js/.test(s.src)) {\n if (s.src.indexOf('?t=') === -1) {\n try {\n s.src = s.src + (s.src.indexOf('?') === -1 ? '?t=' + ts : '&t=' + ts);\n } catch (e) {}\n }\n }\n });\n // \u6700\u7EC8\u786E\u4FDD child window \u6709 getFormRenderMaterial\n try {\n var cw = iframeEl.contentWindow;\n if (cw && typeof cw.getFormRenderMaterial !== 'function') {\n cw.getFormRenderMaterial = function() { return { __esModule: true }; };\n }\n } catch (e) {}\n } catch (e) {}\n }\n\n var mo = new MutationObserver(function(muts) {\n muts.forEach(function(mut) {\n Array.prototype.forEach.call(mut.addedNodes || [], function(node) {\n try {\n if (node && node.tagName === 'IFRAME') {\n tryPatchChildIframe(node);\n // attach load to do more thorough patch after content is written\n node.addEventListener && node.addEventListener('load', function() {\n onChildFrameLoad(node);\n }, { once: true });\n }\n } catch (e) {}\n });\n });\n });\n\n try {\n mo.observe(document.documentElement || document.body, { childList: true, subtree: true });\n // \u5DF2\u5B58\u5728\u7684 iframe \u7ACB\u5373\u5C1D\u8BD5\u4FEE\u8865\n Array.prototype.forEach.call(document.getElementsByTagName('iframe'), function(f) {\n tryPatchChildIframe(f);\n f.addEventListener && f.addEventListener('load', function() { onChildFrameLoad(f); }, { once: true });\n });\n } catch (e) {}\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 </head>\n\n <body>\n <div id=\"lce-container\"></div>\n <!-- \u7ED9 fr-generator \u52A0\u65F6\u95F4\u6233\uFF0C\u5E2E\u52A9\u89C4\u907F\u7F13\u5B58\u5BFC\u81F4\u7684\u65E7\u7248/\u65F6\u5E8F\u95EE\u9898 -->\n <script type=\"text/javascript\" src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js?t=").concat(timestamp, "\"></script>\n </body>\n </html>\n ");
5
3
  return html;
6
4
  };
7
5
  export default (function () {
@@ -9,6 +7,7 @@ export default (function () {
9
7
  iframe.width = '100%';
10
8
  iframe.height = '100%';
11
9
  iframe.frameBorder = '0';
12
- iframe.srcdoc = createIframeContent();
10
+ var ts = Date.now();
11
+ iframe.srcdoc = createIframeContent(ts);
13
12
  return iframe;
14
13
  });
package/es/main.js CHANGED
@@ -7,19 +7,15 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
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
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; }
9
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; }
10
- // 修改 main.ts
11
10
  import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
12
11
  import createIframe from './createIframe';
13
12
  import * as defaultSetting from './settings';
14
- var iframe = null;
13
+ var iframe;
15
14
  var Design = function Design(props, ref) {
16
15
  var widgets = props.widgets,
17
16
  settings = props.settings,
18
17
  restProps = _objectWithoutProperties(props, _excluded);
19
18
  var containerRef = useRef();
20
- var injectionAttemptsRef = useRef(0);
21
- var maxInjectionAttempts = 50; // 最多尝试50次
22
-
23
19
  useImperativeHandle(ref, function () {
24
20
  return {
25
21
  getValue: function getValue() {
@@ -33,138 +29,29 @@ var Design = function Design(props, ref) {
33
29
  };
34
30
  });
35
31
  useEffect(function () {
36
- initIframe();
37
32
  window.addEventListener('message', engineOnLoad);
38
-
39
- // 监听来自 iframe 的消息
40
- window.addEventListener('message', handleIframeMessage);
33
+ initIframe();
41
34
  return function () {
42
35
  window.removeEventListener('message', engineOnLoad);
43
- window.removeEventListener('message', handleIframeMessage);
44
36
  };
45
37
  }, []);
46
38
  var initIframe = function initIframe() {
47
39
  iframe = createIframe();
48
40
  containerRef.current.appendChild(iframe);
49
-
50
- // 监听 iframe 的 load 事件
51
- iframe.onload = function () {
52
- console.log('iframe loaded, injecting getFormRenderMaterial');
53
- injectGetFormRenderMaterial();
54
-
55
- // 启动一个定时器,持续检查并注入
56
- var checkInterval = setInterval(function () {
57
- var _iframe3;
58
- injectionAttemptsRef.current++;
59
- if (injectionAttemptsRef.current > maxInjectionAttempts) {
60
- clearInterval(checkInterval);
61
- console.error("Failed to inject getFormRenderMaterial after ".concat(maxInjectionAttempts, " attempts"));
62
- return;
63
- }
64
- if (((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow) && !isFunctionProperlyInjected()) {
65
- console.log("Attempt ".concat(injectionAttemptsRef.current, ": Injecting getFormRenderMaterial"));
66
- injectGetFormRenderMaterial();
67
- } else if (isFunctionProperlyInjected()) {
68
- clearInterval(checkInterval);
69
- console.log('getFormRenderMaterial successfully injected and verified');
70
- }
71
- }, 100);
72
- };
73
- };
74
- var handleIframeMessage = function handleIframeMessage(event) {
75
- var _iframe4;
76
- // 确保消息来自我们的 iframe
77
- if (event.source !== ((_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : _iframe4.contentWindow)) return;
78
- if (event.data.type === 'GET_FORM_RENDER_MATERIAL_SET') {
79
- console.log('iframe confirmed getFormRenderMaterial was set');
80
- }
81
- };
82
- var injectGetFormRenderMaterial = function injectGetFormRenderMaterial() {
83
- var _iframe5;
84
- if (!((_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : _iframe5.contentWindow)) {
85
- console.error('Cannot inject: iframe or contentWindow not available');
86
- return false;
87
- }
88
- try {
89
- // 方法1:直接注入(可能受同源策略限制)
90
- var iframeWin = iframe.contentWindow;
91
-
92
- // 创建一个函数字符串,然后通过 eval 在 iframe 上下文中执行
93
- var functionString = "\n (function() {\n window.getFormRenderMaterial = function() {\n console.log('getFormRenderMaterial called (injected from parent)');\n return ".concat(JSON.stringify(Object.assign({
94
- __esModule: true
95
- }, widgets || {})), ";\n };\n return true;\n })()\n ");
96
-
97
- // 尝试通过 eval 执行
98
- try {
99
- iframeWin.eval(functionString);
100
- console.log('getFormRenderMaterial injected via eval');
101
- } catch (evalError) {
102
- console.warn('eval failed, trying direct assignment:', evalError);
103
-
104
- // 回退到直接赋值
105
- iframeWin.getFormRenderMaterial = function () {
106
- console.log('getFormRenderMaterial called (direct assignment)');
107
- return Object.assign({
108
- __esModule: true
109
- }, widgets || {});
110
- };
111
- }
112
-
113
- // 方法2:使用 postMessage 发送函数实现
114
- iframeWin.postMessage({
115
- type: 'SET_GET_FORM_RENDER_MATERIAL',
116
- implementation: function implementation() {
117
- return Object.assign({
118
- __esModule: true
119
- }, widgets || {});
120
- }
121
- }, '*');
122
- return true;
123
- } catch (error) {
124
- console.error('Error injecting getFormRenderMaterial:', error);
125
- return false;
126
- }
127
- };
128
- var isFunctionProperlyInjected = function isFunctionProperlyInjected() {
129
- try {
130
- var _iframe6;
131
- var iframeWin = (_iframe6 = iframe) === null || _iframe6 === void 0 ? void 0 : _iframe6.contentWindow;
132
- return iframeWin && typeof iframeWin.getFormRenderMaterial === 'function' && iframeWin.getFormRenderMaterial.toString().includes('getFormRenderMaterial');
133
- } catch (error) {
134
- // 可能由于同源策略无法访问
135
- return false;
136
- }
137
41
  };
138
42
  var engineOnLoad = function engineOnLoad(event) {
139
- var _iframe7;
43
+ var _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2;
140
44
  if (event.data.type !== 'engine-load') {
141
45
  return;
142
46
  }
143
-
144
- // 在初始化前再次确保 getFormRenderMaterial 存在
145
- console.log('Engine loading, verifying getFormRenderMaterial');
146
-
147
- // 尝试通过 postMessage 与 iframe 通信来验证
148
- if ((_iframe7 = iframe) === null || _iframe7 === void 0 ? void 0 : _iframe7.contentWindow) {
149
- iframe.contentWindow.postMessage({
150
- type: 'VERIFY_GET_FORM_RENDER_MATERIAL'
151
- }, '*');
152
-
153
- // 设置一个超时,以防验证失败
154
- setTimeout(function () {
155
- var _iframe8, _iframe8$contentWindo;
156
- if ((_iframe8 = iframe) === null || _iframe8 === void 0 ? void 0 : (_iframe8$contentWindo = _iframe8.contentWindow) === null || _iframe8$contentWindo === void 0 ? void 0 : _iframe8$contentWindo.__FR_ENGINE__) {
157
- console.log('Initializing FR_ENGINE');
158
- iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
159
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
160
- widgets: widgets,
161
- logo: {
162
- title: 'XRender'
163
- }
164
- }, restProps));
165
- }
166
- }, 500);
167
- }
47
+ (_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : (_iframe3$contentWindo2 = _iframe3$contentWindo.__FR_ENGINE__) === null || _iframe3$contentWindo2 === void 0 ? void 0 : _iframe3$contentWindo2.init(_objectSpread({
48
+ settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
49
+ widgets: widgets,
50
+ // recordEnable: true,
51
+ logo: {
52
+ title: 'XRender'
53
+ }
54
+ }, restProps));
168
55
  };
169
56
  return /*#__PURE__*/React.createElement("div", {
170
57
  ref: containerRef,
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- // 修改 createIframe.ts
8
- var createIframeContent = function createIframeContent() {
9
- var timestamp = new Date().getTime();
10
- 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?t=".concat(timestamp, "\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css?t=").concat(timestamp, "\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css?t=").concat(timestamp, "\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css?t=").concat(timestamp, "\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css?t=").concat(timestamp, "\" />\n\n <script>\n // \u76D1\u542C\u7236\u7A97\u53E3\u7684\u6D88\u606F\n window.addEventListener('message', function(event) {\n // \u786E\u4FDD\u6D88\u606F\u6765\u6E90\u53EF\u4FE1\n if (event.source !== window.parent) return;\n \n if (event.data.type === 'SET_GET_FORM_RENDER_MATERIAL') {\n console.log('Received getFormRenderMaterial from parent');\n \n // \u5C06\u7236\u7A97\u53E3\u4F20\u9012\u7684\u51FD\u6570\u8BBE\u7F6E\u4E3A\u5168\u5C40\u65B9\u6CD5\n window.getFormRenderMaterial = function() {\n console.log('getFormRenderMaterial called (from parent)');\n \n // \u8FD9\u91CC\u53EF\u4EE5\u8C03\u7528\u7236\u7A97\u53E3\u4F20\u9012\u7684\u5B9E\u73B0\uFF0C\u6216\u8005\u4F7F\u7528\u672C\u5730\u5B9E\u73B0\n if (event.data.implementation) {\n try {\n // \u4F7F\u7528\u7236\u7A97\u53E3\u4F20\u9012\u7684\u5B9E\u73B0\n return event.data.implementation.apply(this, arguments);\n } catch(e) {\n console.error('Error calling parent implementation:', e);\n }\n }\n \n // \u540E\u5907\u5B9E\u73B0\n return {};\n };\n \n // \u786E\u8BA4\u8BBE\u7F6E\u5B8C\u6210\n window.parent.postMessage({\n type: 'GET_FORM_RENDER_MATERIAL_SET',\n success: true\n }, '*');\n }\n });\n \n // \u9884\u5B9A\u4E49\u4E00\u4E2A\u5B89\u5168\u7684 getFormRenderMaterial \u51FD\u6570\n window.getFormRenderMaterial = window.getFormRenderMaterial || function() {\n console.warn('getFormRenderMaterial called before initialization');\n return {};\n };\n \n // \u8BBE\u7F6E\u5176\u4ED6\u5FC5\u8981\u7684\u5168\u5C40\u53D8\u91CF\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n window.__is_simulator_env__ = true;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js?t=").concat(timestamp, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js?t=").concat(timestamp, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js?t=").concat(timestamp, "\"></script>\n </head>\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?t=").concat(timestamp, "\"></script>\n </body>\n </html>\n ");
7
+ var createIframeContent = function createIframeContent(timestamp) {
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 <!-- Shim: \u5728\u5916\u5C42 iframe \u5185\u63D0\u4F9B\u4E00\u4E2A\u4E34\u65F6\u5B89\u5168\u5B9E\u73B0\uFF0C\u907F\u514D\u7B2C\u4E09\u65B9\u5185\u8054\u811A\u672C\u7ACB\u5373\u62A5\u9519 -->\n <script>\n (function() {\n try {\n if (typeof window.getFormRenderMaterial !== 'function') {\n var __fr_q = [];\n var __fr_shim = function() {\n __fr_q.push({ args: Array.prototype.slice.call(arguments) });\n return { __esModule: true };\n };\n window.getFormRenderMaterial = __fr_shim;\n var __fr_iv = setInterval(function() {\n try {\n if (typeof window.getFormRenderMaterial === 'function' && window.getFormRenderMaterial !== __fr_shim) {\n var __real = window.getFormRenderMaterial;\n clearInterval(__fr_iv);\n setTimeout(function() {\n try {\n __fr_q.forEach(function(item) {\n try { __real.apply(null, item.args); } catch (e) {}\n });\n } catch (e) {}\n __fr_q = null;\n }, 0);\n }\n } catch (e) {}\n }, 50);\n }\n } catch (e) {}\n })();\n </script>\n\n <!-- Observer: \u76D1\u63A7\u672C iframe \u6587\u6863\u4E2D\u65B0\u589E\u7684\u5B50 iframe\uFF08\u7B2C\u4E09\u65B9 create-simulator \u53EF\u80FD\u521B\u5EFA\u7684\u5D4C\u5957 iframe\uFF09\u5E76\u5C3D\u5FEB\u4FEE\u8865 -->\n <script>\n (function() {\n var ts = ".concat(timestamp, ";\n function tryPatchChildIframe(iframeEl) {\n try {\n // \u82E5 contentWindow \u53EF\u7528\uFF0C\u7ACB\u5373\u5728\u5B50 iframe \u7684 window \u4E0A\u653E\u4E2A\u5B89\u5168\u5360\u4F4D\u51FD\u6570\n var cw = iframeEl.contentWindow;\n if (cw) {\n if (typeof cw.getFormRenderMaterial !== 'function') {\n try {\n cw.getFormRenderMaterial = function() {\n return { __esModule: true };\n };\n } catch (e) {}\n }\n }\n } catch (e) {}\n }\n\n // \u5F53\u5B50 iframe \u52A0\u8F7D\u5B8C\u6210\u540E\uFF0C\u5C1D\u8BD5\u4FEE\u8865\u5176\u5185\u90E8 script \u7684 src\uFF0C\u52A0\u65F6\u95F4\u6233\u4EE5\u907F\u514D\u7F13\u5B58\u5BFC\u81F4\u65E7\u7248\u95EE\u9898\uFF1B\u5E76\u786E\u4FDD child window \u6709 getFormRenderMaterial\n function onChildFrameLoad(iframeEl) {\n try {\n var doc = iframeEl.contentDocument || iframeEl.contentWindow && iframeEl.contentWindow.document;\n if (!doc) return;\n // \u4FEE\u8865\u53EF\u80FD\u7684\u5916\u90E8\u811A\u672C url\uFF08\u793A\u4F8B\uFF1Afr-generator / react-simulator-renderer \u7B49\uFF09\n var scripts = Array.prototype.slice.call(doc.getElementsByTagName('script'));\n scripts.forEach(function(s) {\n if (s.src && /fr-generator\\/.*index\\.js|react-simulator-renderer\\.js/.test(s.src)) {\n if (s.src.indexOf('?t=') === -1) {\n try {\n s.src = s.src + (s.src.indexOf('?') === -1 ? '?t=' + ts : '&t=' + ts);\n } catch (e) {}\n }\n }\n });\n // \u6700\u7EC8\u786E\u4FDD child window \u6709 getFormRenderMaterial\n try {\n var cw = iframeEl.contentWindow;\n if (cw && typeof cw.getFormRenderMaterial !== 'function') {\n cw.getFormRenderMaterial = function() { return { __esModule: true }; };\n }\n } catch (e) {}\n } catch (e) {}\n }\n\n var mo = new MutationObserver(function(muts) {\n muts.forEach(function(mut) {\n Array.prototype.forEach.call(mut.addedNodes || [], function(node) {\n try {\n if (node && node.tagName === 'IFRAME') {\n tryPatchChildIframe(node);\n // attach load to do more thorough patch after content is written\n node.addEventListener && node.addEventListener('load', function() {\n onChildFrameLoad(node);\n }, { once: true });\n }\n } catch (e) {}\n });\n });\n });\n\n try {\n mo.observe(document.documentElement || document.body, { childList: true, subtree: true });\n // \u5DF2\u5B58\u5728\u7684 iframe \u7ACB\u5373\u5C1D\u8BD5\u4FEE\u8865\n Array.prototype.forEach.call(document.getElementsByTagName('iframe'), function(f) {\n tryPatchChildIframe(f);\n f.addEventListener && f.addEventListener('load', function() { onChildFrameLoad(f); }, { once: true });\n });\n } catch (e) {}\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 </head>\n\n <body>\n <div id=\"lce-container\"></div>\n <!-- \u7ED9 fr-generator \u52A0\u65F6\u95F4\u6233\uFF0C\u5E2E\u52A9\u89C4\u907F\u7F13\u5B58\u5BFC\u81F4\u7684\u65E7\u7248/\u65F6\u5E8F\u95EE\u9898 -->\n <script type=\"text/javascript\" src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js?t=").concat(timestamp, "\"></script>\n </body>\n </html>\n ");
11
9
  return html;
12
10
  };
13
11
  var _default = exports.default = function _default() {
@@ -15,6 +13,7 @@ var _default = exports.default = function _default() {
15
13
  iframe.width = '100%';
16
14
  iframe.height = '100%';
17
15
  iframe.frameBorder = '0';
18
- iframe.srcdoc = createIframeContent();
16
+ var ts = Date.now();
17
+ iframe.srcdoc = createIframeContent(ts);
19
18
  return iframe;
20
19
  };
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; }
@@ -18,15 +18,12 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
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
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; }
20
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; }
21
- var iframe = null;
21
+ var iframe;
22
22
  var Design = function Design(props, ref) {
23
23
  var widgets = props.widgets,
24
24
  settings = props.settings,
25
25
  restProps = _objectWithoutProperties(props, _excluded);
26
26
  var containerRef = (0, _react.useRef)();
27
- var injectionAttemptsRef = (0, _react.useRef)(0);
28
- var maxInjectionAttempts = 50; // 最多尝试50次
29
-
30
27
  (0, _react.useImperativeHandle)(ref, function () {
31
28
  return {
32
29
  getValue: function getValue() {
@@ -40,138 +37,29 @@ var Design = function Design(props, ref) {
40
37
  };
41
38
  });
42
39
  (0, _react.useEffect)(function () {
43
- initIframe();
44
40
  window.addEventListener('message', engineOnLoad);
45
-
46
- // 监听来自 iframe 的消息
47
- window.addEventListener('message', handleIframeMessage);
41
+ initIframe();
48
42
  return function () {
49
43
  window.removeEventListener('message', engineOnLoad);
50
- window.removeEventListener('message', handleIframeMessage);
51
44
  };
52
45
  }, []);
53
46
  var initIframe = function initIframe() {
54
47
  iframe = (0, _createIframe.default)();
55
48
  containerRef.current.appendChild(iframe);
56
-
57
- // 监听 iframe 的 load 事件
58
- iframe.onload = function () {
59
- console.log('iframe loaded, injecting getFormRenderMaterial');
60
- injectGetFormRenderMaterial();
61
-
62
- // 启动一个定时器,持续检查并注入
63
- var checkInterval = setInterval(function () {
64
- var _iframe3;
65
- injectionAttemptsRef.current++;
66
- if (injectionAttemptsRef.current > maxInjectionAttempts) {
67
- clearInterval(checkInterval);
68
- console.error("Failed to inject getFormRenderMaterial after ".concat(maxInjectionAttempts, " attempts"));
69
- return;
70
- }
71
- if (((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow) && !isFunctionProperlyInjected()) {
72
- console.log("Attempt ".concat(injectionAttemptsRef.current, ": Injecting getFormRenderMaterial"));
73
- injectGetFormRenderMaterial();
74
- } else if (isFunctionProperlyInjected()) {
75
- clearInterval(checkInterval);
76
- console.log('getFormRenderMaterial successfully injected and verified');
77
- }
78
- }, 100);
79
- };
80
- };
81
- var handleIframeMessage = function handleIframeMessage(event) {
82
- var _iframe4;
83
- // 确保消息来自我们的 iframe
84
- if (event.source !== ((_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : _iframe4.contentWindow)) return;
85
- if (event.data.type === 'GET_FORM_RENDER_MATERIAL_SET') {
86
- console.log('iframe confirmed getFormRenderMaterial was set');
87
- }
88
- };
89
- var injectGetFormRenderMaterial = function injectGetFormRenderMaterial() {
90
- var _iframe5;
91
- if (!((_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : _iframe5.contentWindow)) {
92
- console.error('Cannot inject: iframe or contentWindow not available');
93
- return false;
94
- }
95
- try {
96
- // 方法1:直接注入(可能受同源策略限制)
97
- var iframeWin = iframe.contentWindow;
98
-
99
- // 创建一个函数字符串,然后通过 eval 在 iframe 上下文中执行
100
- var functionString = "\n (function() {\n window.getFormRenderMaterial = function() {\n console.log('getFormRenderMaterial called (injected from parent)');\n return ".concat(JSON.stringify(Object.assign({
101
- __esModule: true
102
- }, widgets || {})), ";\n };\n return true;\n })()\n ");
103
-
104
- // 尝试通过 eval 执行
105
- try {
106
- iframeWin.eval(functionString);
107
- console.log('getFormRenderMaterial injected via eval');
108
- } catch (evalError) {
109
- console.warn('eval failed, trying direct assignment:', evalError);
110
-
111
- // 回退到直接赋值
112
- iframeWin.getFormRenderMaterial = function () {
113
- console.log('getFormRenderMaterial called (direct assignment)');
114
- return Object.assign({
115
- __esModule: true
116
- }, widgets || {});
117
- };
118
- }
119
-
120
- // 方法2:使用 postMessage 发送函数实现
121
- iframeWin.postMessage({
122
- type: 'SET_GET_FORM_RENDER_MATERIAL',
123
- implementation: function implementation() {
124
- return Object.assign({
125
- __esModule: true
126
- }, widgets || {});
127
- }
128
- }, '*');
129
- return true;
130
- } catch (error) {
131
- console.error('Error injecting getFormRenderMaterial:', error);
132
- return false;
133
- }
134
- };
135
- var isFunctionProperlyInjected = function isFunctionProperlyInjected() {
136
- try {
137
- var _iframe6;
138
- var iframeWin = (_iframe6 = iframe) === null || _iframe6 === void 0 ? void 0 : _iframe6.contentWindow;
139
- return iframeWin && typeof iframeWin.getFormRenderMaterial === 'function' && iframeWin.getFormRenderMaterial.toString().includes('getFormRenderMaterial');
140
- } catch (error) {
141
- // 可能由于同源策略无法访问
142
- return false;
143
- }
144
49
  };
145
50
  var engineOnLoad = function engineOnLoad(event) {
146
- var _iframe7;
51
+ var _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2;
147
52
  if (event.data.type !== 'engine-load') {
148
53
  return;
149
54
  }
150
-
151
- // 在初始化前再次确保 getFormRenderMaterial 存在
152
- console.log('Engine loading, verifying getFormRenderMaterial');
153
-
154
- // 尝试通过 postMessage 与 iframe 通信来验证
155
- if ((_iframe7 = iframe) === null || _iframe7 === void 0 ? void 0 : _iframe7.contentWindow) {
156
- iframe.contentWindow.postMessage({
157
- type: 'VERIFY_GET_FORM_RENDER_MATERIAL'
158
- }, '*');
159
-
160
- // 设置一个超时,以防验证失败
161
- setTimeout(function () {
162
- var _iframe8, _iframe8$contentWindo;
163
- if ((_iframe8 = iframe) === null || _iframe8 === void 0 ? void 0 : (_iframe8$contentWindo = _iframe8.contentWindow) === null || _iframe8$contentWindo === void 0 ? void 0 : _iframe8$contentWindo.__FR_ENGINE__) {
164
- console.log('Initializing FR_ENGINE');
165
- iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
166
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
167
- widgets: widgets,
168
- logo: {
169
- title: 'XRender'
170
- }
171
- }, restProps));
172
- }
173
- }, 500);
174
- }
55
+ (_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : (_iframe3$contentWindo2 = _iframe3$contentWindo.__FR_ENGINE__) === null || _iframe3$contentWindo2 === void 0 ? void 0 : _iframe3$contentWindo2.init(_objectSpread({
56
+ settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
57
+ widgets: widgets,
58
+ // recordEnable: true,
59
+ logo: {
60
+ title: 'XRender'
61
+ }
62
+ }, restProps));
175
63
  };
176
64
  return /*#__PURE__*/_react.default.createElement("div", {
177
65
  ref: containerRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.72",
3
+ "version": "1.0.0-alpha.73",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",