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

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,15 +1,14 @@
1
- // 创建一个新的 iframe 加载器:iframeLoaderEnhanced.ts
2
- export var createFixedIframe = function createFixedIframe(widgets) {
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 ");
5
+ return html;
6
+ };
7
+ export default (function () {
3
8
  var iframe = document.createElement('iframe');
4
9
  iframe.width = '100%';
5
10
  iframe.height = '100%';
6
11
  iframe.frameBorder = '0';
7
- var timestamp = Date.now();
8
- var cacheBuster = "?t=".concat(timestamp);
9
-
10
- // 将 widgets 转换为 JSON 字符串用于注入
11
- var widgetsJson = JSON.stringify(widgets || {});
12
- var html = "<!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>XRender</title>\n <link rel=\"icon\" href=\"https://img.alicdn.com/tfs/TB17UtINiLaK1RjSZFxXXamPFXa-606-643.png\">\n \n <!-- \u6837\u5F0F -->\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/variables.css".concat(cacheBuster, "\" rel=\"stylesheet\">\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css").concat(cacheBuster, "\" rel=\"stylesheet\">\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css").concat(cacheBuster, "\">\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css").concat(cacheBuster, "\">\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css").concat(cacheBuster, "\">\n \n <script>\n // \u6838\u5FC3\u4FEE\u590D\uFF1A\u5B8C\u5168\u63A5\u7BA1 polling \u673A\u5236\n (function() {\n // \u5B58\u50A8\u539F\u59CB\u7684 polling \u65B9\u6CD5\n var originalPolling = null;\n \n // \u5B9A\u4E49\u6211\u4EEC\u81EA\u5DF1\u7684 polling \u5B9E\u73B0\n var fixedPolling = function(t) {\n console.log('Fixed polling called with data:', t ? 'has data' : 'no data');\n \n // \u76F4\u63A5\u8BBE\u7F6E getFormRenderMaterial\uFF0C\u4E0D\u4F9D\u8D56\u4E8E\u67E5\u627E iframe\n window.getFormRenderMaterial = function() {\n console.log('Fixed getFormRenderMaterial called');\n // \u8FD4\u56DE\u5B9E\u9645\u7684 widgets \u6570\u636E\n var widgetsData = window.__WIDGETS_DATA__ || t || {};\n return Object.assign({__esModule: true}, widgetsData, {});\n };\n \n // \u786E\u4FDD\u65B9\u6CD5\u5DF2\u8BBE\u7F6E\n console.log('getFormRenderMaterial set:', !!window.getFormRenderMaterial);\n \n // \u5982\u679C\u6709\u539F\u59CB polling\uFF0C\u4E5F\u8C03\u7528\u5B83\uFF08\u5982\u679C\u5B83\u5B58\u5728\uFF09\n if (originalPolling) {\n try {\n originalPolling.call(this, t);\n } catch(e) {\n console.error('Original polling failed:', e);\n }\n }\n \n // \u6807\u8BB0 polling \u5B8C\u6210\n window.__POLLING_COMPLETE__ = true;\n };\n \n // \u62E6\u622A fr-generator \u7684 polling \u65B9\u6CD5\n var interceptPolling = function() {\n if (window.__FR_ENGINE__ && typeof window.__FR_ENGINE__.polling === 'function') {\n originalPolling = window.__FR_ENGINE__.polling;\n window.__FR_ENGINE__.polling = fixedPolling;\n console.log('Successfully intercepted polling method');\n return true;\n }\n return false;\n };\n \n // \u7ACB\u5373\u5C1D\u8BD5\u62E6\u622A\n if (!interceptPolling()) {\n // \u5982\u679C fr-generator \u8FD8\u6CA1\u52A0\u8F7D\uFF0C\u8BBE\u7F6E\u4E00\u4E2A\u76D1\u542C\u5668\n var checkInterval = setInterval(function() {\n if (interceptPolling()) {\n clearInterval(checkInterval);\n console.log('Polling interception complete');\n }\n }, 100);\n \n // \u6700\u591A\u68C0\u67E5 5 \u79D2\n setTimeout(function() {\n clearInterval(checkInterval);\n }, 5000);\n }\n \n // \u6CE8\u5165 widgets \u6570\u636E\n window.__WIDGETS_DATA__ = ").concat(widgetsJson, ";\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 window.PropTypes = window.parent.PropTypes;\n window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__;\n \n // \u9884\u5B9A\u4E49 getFormRenderMaterial \u4F5C\u4E3A\u540E\u5907\n window.getFormRenderMaterial = window.getFormRenderMaterial || function() {\n console.log('Fallback getFormRenderMaterial called');\n return Object.assign({__esModule: true}, window.__WIDGETS_DATA__ || {});\n };\n })();\n </script>\n </head>\n <body>\n <div id=\"lce-container\"></div>\n \n <!-- \u52A0\u8F7D\u6240\u6709\u811A\u672C -->\n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js").concat(cacheBuster, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js").concat(cacheBuster, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js").concat(cacheBuster, "\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js").concat(cacheBuster, "\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js").concat(cacheBuster, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js").concat(cacheBuster, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js").concat(cacheBuster, "\"></script>\n <script type=\"text/javascript\" src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js").concat(cacheBuster, "\"></script>\n \n <script>\n // \u786E\u4FDD\u5728 iframe \u52A0\u8F7D\u5B8C\u6210\u540E\u901A\u77E5\u7236\u7A97\u53E3\n window.addEventListener('load', function() {\n console.log('iframe fully loaded, polling status:', window.__POLLING_COMPLETE__);\n \n // \u518D\u6B21\u786E\u4FDD getFormRenderMaterial \u5B58\u5728\n if (!window.getFormRenderMaterial) {\n console.warn('getFormRenderMaterial still missing, setting emergency fallback');\n window.getFormRenderMaterial = function() {\n return {};\n };\n }\n \n // \u901A\u77E5\u7236\u7A97\u53E3 iframe \u5DF2\u51C6\u5907\u5C31\u7EEA\n setTimeout(function() {\n window.parent.postMessage({ type: 'iframe-ready' }, '*');\n window.parent.postMessage({ type: 'engine-load' }, '*');\n }, 300);\n });\n </script>\n </body>\n </html>");
13
- iframe.srcdoc = html;
12
+ iframe.srcdoc = createIframeContent();
14
13
  return iframe;
15
- };
14
+ });
package/es/main.js CHANGED
@@ -7,15 +7,19 @@ 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
10
11
  import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
12
+ import createIframe from './createIframe';
11
13
  import * as defaultSetting from './settings';
12
- import { createFixedIframe } from './createIframe';
13
- var iframe;
14
+ var iframe = null;
14
15
  var Design = function Design(props, ref) {
15
16
  var widgets = props.widgets,
16
17
  settings = props.settings,
17
18
  restProps = _objectWithoutProperties(props, _excluded);
18
19
  var containerRef = useRef();
20
+ var injectionAttemptsRef = useRef(0);
21
+ var maxInjectionAttempts = 50; // 最多尝试50次
22
+
19
23
  useImperativeHandle(ref, function () {
20
24
  return {
21
25
  getValue: function getValue() {
@@ -29,29 +33,138 @@ var Design = function Design(props, ref) {
29
33
  };
30
34
  });
31
35
  useEffect(function () {
32
- window.addEventListener('message', engineOnLoad);
33
36
  initIframe();
37
+ window.addEventListener('message', engineOnLoad);
38
+
39
+ // 监听来自 iframe 的消息
40
+ window.addEventListener('message', handleIframeMessage);
34
41
  return function () {
35
42
  window.removeEventListener('message', engineOnLoad);
43
+ window.removeEventListener('message', handleIframeMessage);
36
44
  };
37
45
  }, []);
38
46
  var initIframe = function initIframe() {
39
- iframe = createFixedIframe;
47
+ iframe = createIframe();
40
48
  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
+ }
41
137
  };
42
138
  var engineOnLoad = function engineOnLoad(event) {
43
- var _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2;
139
+ var _iframe7;
44
140
  if (event.data.type !== 'engine-load') {
45
141
  return;
46
142
  }
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));
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
+ }
55
168
  };
56
169
  return /*#__PURE__*/React.createElement("div", {
57
170
  ref: containerRef,
@@ -3,19 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createFixedIframe = void 0;
7
- // 创建一个新的 iframe 加载器:iframeLoaderEnhanced.ts
8
- var createFixedIframe = exports.createFixedIframe = function createFixedIframe(widgets) {
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 ");
11
+ return html;
12
+ };
13
+ var _default = exports.default = function _default() {
9
14
  var iframe = document.createElement('iframe');
10
15
  iframe.width = '100%';
11
16
  iframe.height = '100%';
12
17
  iframe.frameBorder = '0';
13
- var timestamp = Date.now();
14
- var cacheBuster = "?t=".concat(timestamp);
15
-
16
- // 将 widgets 转换为 JSON 字符串用于注入
17
- var widgetsJson = JSON.stringify(widgets || {});
18
- var html = "<!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>XRender</title>\n <link rel=\"icon\" href=\"https://img.alicdn.com/tfs/TB17UtINiLaK1RjSZFxXXamPFXa-606-643.png\">\n \n <!-- \u6837\u5F0F -->\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/variables.css".concat(cacheBuster, "\" rel=\"stylesheet\">\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css").concat(cacheBuster, "\" rel=\"stylesheet\">\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css").concat(cacheBuster, "\">\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css").concat(cacheBuster, "\">\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css").concat(cacheBuster, "\">\n \n <script>\n // \u6838\u5FC3\u4FEE\u590D\uFF1A\u5B8C\u5168\u63A5\u7BA1 polling \u673A\u5236\n (function() {\n // \u5B58\u50A8\u539F\u59CB\u7684 polling \u65B9\u6CD5\n var originalPolling = null;\n \n // \u5B9A\u4E49\u6211\u4EEC\u81EA\u5DF1\u7684 polling \u5B9E\u73B0\n var fixedPolling = function(t) {\n console.log('Fixed polling called with data:', t ? 'has data' : 'no data');\n \n // \u76F4\u63A5\u8BBE\u7F6E getFormRenderMaterial\uFF0C\u4E0D\u4F9D\u8D56\u4E8E\u67E5\u627E iframe\n window.getFormRenderMaterial = function() {\n console.log('Fixed getFormRenderMaterial called');\n // \u8FD4\u56DE\u5B9E\u9645\u7684 widgets \u6570\u636E\n var widgetsData = window.__WIDGETS_DATA__ || t || {};\n return Object.assign({__esModule: true}, widgetsData, {});\n };\n \n // \u786E\u4FDD\u65B9\u6CD5\u5DF2\u8BBE\u7F6E\n console.log('getFormRenderMaterial set:', !!window.getFormRenderMaterial);\n \n // \u5982\u679C\u6709\u539F\u59CB polling\uFF0C\u4E5F\u8C03\u7528\u5B83\uFF08\u5982\u679C\u5B83\u5B58\u5728\uFF09\n if (originalPolling) {\n try {\n originalPolling.call(this, t);\n } catch(e) {\n console.error('Original polling failed:', e);\n }\n }\n \n // \u6807\u8BB0 polling \u5B8C\u6210\n window.__POLLING_COMPLETE__ = true;\n };\n \n // \u62E6\u622A fr-generator \u7684 polling \u65B9\u6CD5\n var interceptPolling = function() {\n if (window.__FR_ENGINE__ && typeof window.__FR_ENGINE__.polling === 'function') {\n originalPolling = window.__FR_ENGINE__.polling;\n window.__FR_ENGINE__.polling = fixedPolling;\n console.log('Successfully intercepted polling method');\n return true;\n }\n return false;\n };\n \n // \u7ACB\u5373\u5C1D\u8BD5\u62E6\u622A\n if (!interceptPolling()) {\n // \u5982\u679C fr-generator \u8FD8\u6CA1\u52A0\u8F7D\uFF0C\u8BBE\u7F6E\u4E00\u4E2A\u76D1\u542C\u5668\n var checkInterval = setInterval(function() {\n if (interceptPolling()) {\n clearInterval(checkInterval);\n console.log('Polling interception complete');\n }\n }, 100);\n \n // \u6700\u591A\u68C0\u67E5 5 \u79D2\n setTimeout(function() {\n clearInterval(checkInterval);\n }, 5000);\n }\n \n // \u6CE8\u5165 widgets \u6570\u636E\n window.__WIDGETS_DATA__ = ").concat(widgetsJson, ";\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 window.PropTypes = window.parent.PropTypes;\n window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__;\n \n // \u9884\u5B9A\u4E49 getFormRenderMaterial \u4F5C\u4E3A\u540E\u5907\n window.getFormRenderMaterial = window.getFormRenderMaterial || function() {\n console.log('Fallback getFormRenderMaterial called');\n return Object.assign({__esModule: true}, window.__WIDGETS_DATA__ || {});\n };\n })();\n </script>\n </head>\n <body>\n <div id=\"lce-container\"></div>\n \n <!-- \u52A0\u8F7D\u6240\u6709\u811A\u672C -->\n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js").concat(cacheBuster, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js").concat(cacheBuster, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js").concat(cacheBuster, "\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js").concat(cacheBuster, "\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js").concat(cacheBuster, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js").concat(cacheBuster, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js").concat(cacheBuster, "\"></script>\n <script type=\"text/javascript\" src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js").concat(cacheBuster, "\"></script>\n \n <script>\n // \u786E\u4FDD\u5728 iframe \u52A0\u8F7D\u5B8C\u6210\u540E\u901A\u77E5\u7236\u7A97\u53E3\n window.addEventListener('load', function() {\n console.log('iframe fully loaded, polling status:', window.__POLLING_COMPLETE__);\n \n // \u518D\u6B21\u786E\u4FDD getFormRenderMaterial \u5B58\u5728\n if (!window.getFormRenderMaterial) {\n console.warn('getFormRenderMaterial still missing, setting emergency fallback');\n window.getFormRenderMaterial = function() {\n return {};\n };\n }\n \n // \u901A\u77E5\u7236\u7A97\u53E3 iframe \u5DF2\u51C6\u5907\u5C31\u7EEA\n setTimeout(function() {\n window.parent.postMessage({ type: 'iframe-ready' }, '*');\n window.parent.postMessage({ type: 'engine-load' }, '*');\n }, 300);\n });\n </script>\n </body>\n </html>");
19
- iframe.srcdoc = html;
18
+ iframe.srcdoc = createIframeContent();
20
19
  return iframe;
21
20
  };
package/lib/main.js CHANGED
@@ -6,9 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
+ var _createIframe = _interopRequireDefault(require("./createIframe"));
9
10
  var defaultSetting = _interopRequireWildcard(require("./settings"));
10
- var _createIframe = require("./createIframe");
11
- var _excluded = ["widgets", "settings"];
11
+ var _excluded = ["widgets", "settings"]; // 修改 main.ts
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
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); }
13
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; }
14
15
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -17,12 +18,15 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
17
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); }
18
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; }
19
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; }
20
- var iframe;
21
+ var iframe = null;
21
22
  var Design = function Design(props, ref) {
22
23
  var widgets = props.widgets,
23
24
  settings = props.settings,
24
25
  restProps = _objectWithoutProperties(props, _excluded);
25
26
  var containerRef = (0, _react.useRef)();
27
+ var injectionAttemptsRef = (0, _react.useRef)(0);
28
+ var maxInjectionAttempts = 50; // 最多尝试50次
29
+
26
30
  (0, _react.useImperativeHandle)(ref, function () {
27
31
  return {
28
32
  getValue: function getValue() {
@@ -36,29 +40,138 @@ var Design = function Design(props, ref) {
36
40
  };
37
41
  });
38
42
  (0, _react.useEffect)(function () {
39
- window.addEventListener('message', engineOnLoad);
40
43
  initIframe();
44
+ window.addEventListener('message', engineOnLoad);
45
+
46
+ // 监听来自 iframe 的消息
47
+ window.addEventListener('message', handleIframeMessage);
41
48
  return function () {
42
49
  window.removeEventListener('message', engineOnLoad);
50
+ window.removeEventListener('message', handleIframeMessage);
43
51
  };
44
52
  }, []);
45
53
  var initIframe = function initIframe() {
46
- iframe = _createIframe.createFixedIframe;
54
+ iframe = (0, _createIframe.default)();
47
55
  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
+ }
48
144
  };
49
145
  var engineOnLoad = function engineOnLoad(event) {
50
- var _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2;
146
+ var _iframe7;
51
147
  if (event.data.type !== 'engine-load') {
52
148
  return;
53
149
  }
54
- (_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({
55
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
56
- widgets: widgets,
57
- // recordEnable: true,
58
- logo: {
59
- title: 'XRender'
60
- }
61
- }, restProps));
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
+ }
62
175
  };
63
176
  return /*#__PURE__*/_react.default.createElement("div", {
64
177
  ref: containerRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.70",
3
+ "version": "1.0.0-alpha.72",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",