@zzdadelu/schema-builder 1.0.0-alpha.71 → 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.
- package/es/createIframe.js +3 -1
- package/es/main.js +110 -51
- package/lib/createIframe.js +3 -1
- package/lib/main.js +110 -52
- package/package.json +1 -1
package/es/createIframe.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
// 修改 createIframe.ts
|
|
1
2
|
var createIframeContent = function createIframeContent() {
|
|
2
|
-
var
|
|
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 ");
|
|
3
5
|
return html;
|
|
4
6
|
};
|
|
5
7
|
export default (function () {
|
package/es/main.js
CHANGED
|
@@ -7,17 +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';
|
|
11
|
-
import * as defaultSetting from './settings';
|
|
12
12
|
import createIframe from './createIframe';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// 修改 main.ts,在父窗口中直接注入 getFormRenderMaterial
|
|
13
|
+
import * as defaultSetting from './settings';
|
|
14
|
+
var iframe = null;
|
|
16
15
|
var Design = function Design(props, ref) {
|
|
17
16
|
var widgets = props.widgets,
|
|
18
17
|
settings = props.settings,
|
|
19
18
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
20
19
|
var containerRef = useRef();
|
|
20
|
+
var injectionAttemptsRef = useRef(0);
|
|
21
|
+
var maxInjectionAttempts = 50; // 最多尝试50次
|
|
22
|
+
|
|
21
23
|
useImperativeHandle(ref, function () {
|
|
22
24
|
return {
|
|
23
25
|
getValue: function getValue() {
|
|
@@ -34,21 +36,11 @@ var Design = function Design(props, ref) {
|
|
|
34
36
|
initIframe();
|
|
35
37
|
window.addEventListener('message', engineOnLoad);
|
|
36
38
|
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
var _iframe3;
|
|
40
|
-
if (((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow) && !iframe.contentWindow.getFormRenderMaterial) {
|
|
41
|
-
console.log('Manually injecting getFormRenderMaterial from parent');
|
|
42
|
-
iframe.contentWindow.getFormRenderMaterial = function () {
|
|
43
|
-
return Object.assign({
|
|
44
|
-
__esModule: true
|
|
45
|
-
}, widgets || {});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}, 100);
|
|
39
|
+
// 监听来自 iframe 的消息
|
|
40
|
+
window.addEventListener('message', handleIframeMessage);
|
|
49
41
|
return function () {
|
|
50
42
|
window.removeEventListener('message', engineOnLoad);
|
|
51
|
-
|
|
43
|
+
window.removeEventListener('message', handleIframeMessage);
|
|
52
44
|
};
|
|
53
45
|
}, []);
|
|
54
46
|
var initIframe = function initIframe() {
|
|
@@ -58,54 +50,121 @@ var Design = function Design(props, ref) {
|
|
|
58
50
|
// 监听 iframe 的 load 事件
|
|
59
51
|
iframe.onload = function () {
|
|
60
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;
|
|
61
91
|
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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)');
|
|
67
107
|
return Object.assign({
|
|
68
108
|
__esModule: true
|
|
69
109
|
}, widgets || {});
|
|
70
110
|
};
|
|
71
|
-
|
|
72
|
-
// 方法2:模拟 polling 机制
|
|
73
|
-
setTimeout(function () {
|
|
74
|
-
if (iframe.contentWindow && !iframe.contentWindow.getFormRenderMaterial) {
|
|
75
|
-
console.log('Fallback injection after timeout');
|
|
76
|
-
iframe.contentWindow.getFormRenderMaterial = function () {
|
|
77
|
-
return Object.assign({
|
|
78
|
-
__esModule: true
|
|
79
|
-
}, widgets || {});
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}, 500);
|
|
83
111
|
}
|
|
84
|
-
|
|
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
|
+
}
|
|
85
137
|
};
|
|
86
138
|
var engineOnLoad = function engineOnLoad(event) {
|
|
87
|
-
var
|
|
139
|
+
var _iframe7;
|
|
88
140
|
if (event.data.type !== 'engine-load') {
|
|
89
141
|
return;
|
|
90
142
|
}
|
|
91
143
|
|
|
92
144
|
// 在初始化前再次确保 getFormRenderMaterial 存在
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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);
|
|
101
167
|
}
|
|
102
|
-
(_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({
|
|
103
|
-
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
104
|
-
widgets: widgets,
|
|
105
|
-
logo: {
|
|
106
|
-
title: 'XRender'
|
|
107
|
-
}
|
|
108
|
-
}, restProps));
|
|
109
168
|
};
|
|
110
169
|
return /*#__PURE__*/React.createElement("div", {
|
|
111
170
|
ref: containerRef,
|
package/lib/createIframe.js
CHANGED
|
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
// 修改 createIframe.ts
|
|
7
8
|
var createIframeContent = function createIframeContent() {
|
|
8
|
-
var
|
|
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 ");
|
|
9
11
|
return html;
|
|
10
12
|
};
|
|
11
13
|
var _default = exports.default = function _default() {
|
package/lib/main.js
CHANGED
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
var defaultSetting = _interopRequireWildcard(require("./settings"));
|
|
10
9
|
var _createIframe = _interopRequireDefault(require("./createIframe"));
|
|
11
|
-
var
|
|
10
|
+
var defaultSetting = _interopRequireWildcard(require("./settings"));
|
|
11
|
+
var _excluded = ["widgets", "settings"]; // 修改 main.ts
|
|
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,14 +18,15 @@ 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;
|
|
22
|
-
|
|
23
|
-
// 修改 main.ts,在父窗口中直接注入 getFormRenderMaterial
|
|
21
|
+
var iframe = null;
|
|
24
22
|
var Design = function Design(props, ref) {
|
|
25
23
|
var widgets = props.widgets,
|
|
26
24
|
settings = props.settings,
|
|
27
25
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
28
26
|
var containerRef = (0, _react.useRef)();
|
|
27
|
+
var injectionAttemptsRef = (0, _react.useRef)(0);
|
|
28
|
+
var maxInjectionAttempts = 50; // 最多尝试50次
|
|
29
|
+
|
|
29
30
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
30
31
|
return {
|
|
31
32
|
getValue: function getValue() {
|
|
@@ -42,21 +43,11 @@ var Design = function Design(props, ref) {
|
|
|
42
43
|
initIframe();
|
|
43
44
|
window.addEventListener('message', engineOnLoad);
|
|
44
45
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
var _iframe3;
|
|
48
|
-
if (((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow) && !iframe.contentWindow.getFormRenderMaterial) {
|
|
49
|
-
console.log('Manually injecting getFormRenderMaterial from parent');
|
|
50
|
-
iframe.contentWindow.getFormRenderMaterial = function () {
|
|
51
|
-
return Object.assign({
|
|
52
|
-
__esModule: true
|
|
53
|
-
}, widgets || {});
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}, 100);
|
|
46
|
+
// 监听来自 iframe 的消息
|
|
47
|
+
window.addEventListener('message', handleIframeMessage);
|
|
57
48
|
return function () {
|
|
58
49
|
window.removeEventListener('message', engineOnLoad);
|
|
59
|
-
|
|
50
|
+
window.removeEventListener('message', handleIframeMessage);
|
|
60
51
|
};
|
|
61
52
|
}, []);
|
|
62
53
|
var initIframe = function initIframe() {
|
|
@@ -66,54 +57,121 @@ var Design = function Design(props, ref) {
|
|
|
66
57
|
// 监听 iframe 的 load 事件
|
|
67
58
|
iframe.onload = function () {
|
|
68
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;
|
|
69
98
|
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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)');
|
|
75
114
|
return Object.assign({
|
|
76
115
|
__esModule: true
|
|
77
116
|
}, widgets || {});
|
|
78
117
|
};
|
|
79
|
-
|
|
80
|
-
// 方法2:模拟 polling 机制
|
|
81
|
-
setTimeout(function () {
|
|
82
|
-
if (iframe.contentWindow && !iframe.contentWindow.getFormRenderMaterial) {
|
|
83
|
-
console.log('Fallback injection after timeout');
|
|
84
|
-
iframe.contentWindow.getFormRenderMaterial = function () {
|
|
85
|
-
return Object.assign({
|
|
86
|
-
__esModule: true
|
|
87
|
-
}, widgets || {});
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}, 500);
|
|
91
118
|
}
|
|
92
|
-
|
|
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
|
+
}
|
|
93
144
|
};
|
|
94
145
|
var engineOnLoad = function engineOnLoad(event) {
|
|
95
|
-
var
|
|
146
|
+
var _iframe7;
|
|
96
147
|
if (event.data.type !== 'engine-load') {
|
|
97
148
|
return;
|
|
98
149
|
}
|
|
99
150
|
|
|
100
151
|
// 在初始化前再次确保 getFormRenderMaterial 存在
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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);
|
|
109
174
|
}
|
|
110
|
-
(_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({
|
|
111
|
-
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
112
|
-
widgets: widgets,
|
|
113
|
-
logo: {
|
|
114
|
-
title: 'XRender'
|
|
115
|
-
}
|
|
116
|
-
}, restProps));
|
|
117
175
|
};
|
|
118
176
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
119
177
|
ref: containerRef,
|