@zzdadelu/schema-builder 1.0.0-alpha.40 → 1.0.0-alpha.41
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 +2 -22
- package/es/main.js +178 -11
- package/lib/createIframe.js +2 -22
- package/lib/main.js +177 -11
- package/package.json +1 -1
package/es/createIframe.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// createIframe.ts
|
|
2
1
|
var createIframeContent = function createIframeContent() {
|
|
3
|
-
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 <
|
|
2
|
+
var html = "\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" />\n <title>XRender</title>\n <link rel=\"icon\" href=\"https://img.alicdn.com/tfs/TB17UtINiLaK1RjSZFxXXamPFXa-606-643.png\">\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/variables.css\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css\" />\n\n <script>\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js\"></script>\n\n <body>\n <div id=\"lce-container\"></div>\n <script type=\"text/javascript\" src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js\"></script>\n </body>\n </html>\n ";
|
|
4
3
|
return html;
|
|
5
4
|
};
|
|
6
5
|
export default (function () {
|
|
@@ -8,25 +7,6 @@ export default (function () {
|
|
|
8
7
|
iframe.width = '100%';
|
|
9
8
|
iframe.height = '100%';
|
|
10
9
|
iframe.frameBorder = '0';
|
|
11
|
-
|
|
12
|
-
// 使用唯一ID来避免缓存
|
|
13
|
-
var iframeId = 'xrender-iframe-' + Date.now();
|
|
14
|
-
iframe.id = iframeId;
|
|
15
|
-
iframe.name = iframeId;
|
|
16
|
-
|
|
17
|
-
// 添加防缓存参数
|
|
18
|
-
var htmlContent = createIframeContent();
|
|
19
|
-
var blob = new Blob([htmlContent], {
|
|
20
|
-
type: 'text/html'
|
|
21
|
-
});
|
|
22
|
-
var url = URL.createObjectURL(blob);
|
|
23
|
-
iframe.src = url;
|
|
24
|
-
|
|
25
|
-
// 清理URL对象
|
|
26
|
-
iframe.onload = function () {
|
|
27
|
-
setTimeout(function () {
|
|
28
|
-
return URL.revokeObjectURL(url);
|
|
29
|
-
}, 1000);
|
|
30
|
-
};
|
|
10
|
+
iframe.srcdoc = createIframeContent();
|
|
31
11
|
return iframe;
|
|
32
12
|
});
|
package/es/main.js
CHANGED
|
@@ -5,9 +5,16 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
5
5
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
9
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
11
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
12
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
8
14
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
9
15
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
10
|
-
|
|
16
|
+
// main.ts
|
|
17
|
+
import React, { useEffect, useRef, useImperativeHandle, forwardRef, useState } from 'react';
|
|
11
18
|
import createIframe from './createIframe';
|
|
12
19
|
import * as defaultSetting from './settings';
|
|
13
20
|
var iframe;
|
|
@@ -16,6 +23,11 @@ var Design = function Design(props, ref) {
|
|
|
16
23
|
settings = props.settings,
|
|
17
24
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
18
25
|
var containerRef = useRef();
|
|
26
|
+
var _useState = useState(0),
|
|
27
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
+
retryCount = _useState2[0],
|
|
29
|
+
setRetryCount = _useState2[1];
|
|
30
|
+
var maxRetries = 3;
|
|
19
31
|
useImperativeHandle(ref, function () {
|
|
20
32
|
return {
|
|
21
33
|
getValue: function getValue() {
|
|
@@ -27,36 +39,191 @@ var Design = function Design(props, ref) {
|
|
|
27
39
|
setValue: function setValue(schema) {
|
|
28
40
|
var _iframe4, _iframe4$contentWindo, _iframe4$contentWindo2, _iframe4$contentWindo3;
|
|
29
41
|
return (_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : (_iframe4$contentWindo = _iframe4.contentWindow) === null || _iframe4$contentWindo === void 0 ? void 0 : (_iframe4$contentWindo2 = _iframe4$contentWindo.__FR_ENGINE__) === null || _iframe4$contentWindo2 === void 0 ? void 0 : (_iframe4$contentWindo3 = _iframe4$contentWindo2.importSchema) === null || _iframe4$contentWindo3 === void 0 ? void 0 : _iframe4$contentWindo3.call(_iframe4$contentWindo2, schema);
|
|
42
|
+
},
|
|
43
|
+
// 添加检查方法
|
|
44
|
+
checkStatus: function checkStatus() {
|
|
45
|
+
var _iframe5, _iframe5$contentWindo, _iframe6, _iframe6$contentWindo;
|
|
46
|
+
return {
|
|
47
|
+
iframeReady: !!iframe,
|
|
48
|
+
hasFormRenderMaterial: typeof ((_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : (_iframe5$contentWindo = _iframe5.contentWindow) === null || _iframe5$contentWindo === void 0 ? void 0 : _iframe5$contentWindo.getFormRenderMaterial) === 'function',
|
|
49
|
+
hasEngine: !!((_iframe6 = iframe) === null || _iframe6 === void 0 ? void 0 : (_iframe6$contentWindo = _iframe6.contentWindow) === null || _iframe6$contentWindo === void 0 ? void 0 : _iframe6$contentWindo.__FR_ENGINE__)
|
|
50
|
+
};
|
|
30
51
|
}
|
|
31
52
|
};
|
|
32
53
|
});
|
|
33
54
|
useEffect(function () {
|
|
34
55
|
initIframe();
|
|
35
56
|
window.addEventListener('message', engineOnLoad);
|
|
57
|
+
|
|
58
|
+
// 添加定时检查
|
|
59
|
+
var checkInterval = setInterval(checkIframeStatus, 2000);
|
|
36
60
|
return function () {
|
|
37
61
|
window.removeEventListener('message', engineOnLoad);
|
|
62
|
+
clearInterval(checkInterval);
|
|
63
|
+
// 清理iframe
|
|
64
|
+
if (iframe && containerRef.current) {
|
|
65
|
+
try {
|
|
66
|
+
containerRef.current.removeChild(iframe);
|
|
67
|
+
} catch (e) {}
|
|
68
|
+
iframe = null;
|
|
69
|
+
}
|
|
38
70
|
};
|
|
39
71
|
}, []);
|
|
72
|
+
var checkIframeStatus = function checkIframeStatus() {
|
|
73
|
+
if (!iframe) return;
|
|
74
|
+
try {
|
|
75
|
+
var _iframe$contentWindow, _iframe$contentWindow2;
|
|
76
|
+
var hasFunction = typeof ((_iframe$contentWindow = iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : _iframe$contentWindow.getFormRenderMaterial) === 'function';
|
|
77
|
+
var hasEngine = !!((_iframe$contentWindow2 = iframe.contentWindow) === null || _iframe$contentWindow2 === void 0 ? void 0 : _iframe$contentWindow2.__FR_ENGINE__);
|
|
78
|
+
if (!hasFunction && retryCount < maxRetries) {
|
|
79
|
+
console.warn("getFormRenderMaterial not found, retrying... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
|
|
80
|
+
setRetryCount(function (prev) {
|
|
81
|
+
var newCount = prev + 1;
|
|
82
|
+
if (newCount <= maxRetries) {
|
|
83
|
+
setTimeout(function () {
|
|
84
|
+
return retryIframe();
|
|
85
|
+
}, 500);
|
|
86
|
+
}
|
|
87
|
+
return newCount;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
} catch (e) {
|
|
91
|
+
console.error('Error checking iframe status:', e);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
40
94
|
var initIframe = function initIframe() {
|
|
41
95
|
console.log("开始创建 iframe");
|
|
96
|
+
|
|
97
|
+
// 清理旧的iframe
|
|
98
|
+
if (containerRef.current && iframe) {
|
|
99
|
+
try {
|
|
100
|
+
containerRef.current.removeChild(iframe);
|
|
101
|
+
} catch (e) {}
|
|
102
|
+
iframe = null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 创建新的iframe
|
|
42
106
|
iframe = createIframe();
|
|
107
|
+
|
|
108
|
+
// 添加加载错误处理
|
|
109
|
+
iframe.onerror = function (e) {
|
|
110
|
+
console.error('Iframe loading error:', e);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// 添加加载超时处理
|
|
114
|
+
var loadTimeout = setTimeout(function () {
|
|
115
|
+
if (iframe && (!iframe.contentWindow || !iframe.contentWindow.document)) {
|
|
116
|
+
console.error('Iframe load timeout');
|
|
117
|
+
retryIframe();
|
|
118
|
+
}
|
|
119
|
+
}, 10000);
|
|
120
|
+
iframe.onload = function () {
|
|
121
|
+
clearTimeout(loadTimeout);
|
|
122
|
+
console.log("iframe 加载完成");
|
|
123
|
+
|
|
124
|
+
// 等待iframe内部脚本执行
|
|
125
|
+
setTimeout(function () {
|
|
126
|
+
try {
|
|
127
|
+
var _iframe$contentWindow3;
|
|
128
|
+
// 检查函数是否存在
|
|
129
|
+
var hasFunction = typeof ((_iframe$contentWindow3 = iframe.contentWindow) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.getFormRenderMaterial) === 'function';
|
|
130
|
+
if (!hasFunction) {
|
|
131
|
+
console.warn('getFormRenderMaterial not found after iframe loaded');
|
|
132
|
+
}
|
|
133
|
+
} catch (e) {
|
|
134
|
+
console.error('Error checking function after iframe load:', e);
|
|
135
|
+
}
|
|
136
|
+
}, 1000);
|
|
137
|
+
};
|
|
43
138
|
containerRef.current.appendChild(iframe);
|
|
44
|
-
console.log("iframe
|
|
139
|
+
console.log("iframe 创建完成");
|
|
140
|
+
};
|
|
141
|
+
var retryIframe = function retryIframe() {
|
|
142
|
+
console.log("Retrying iframe creation (attempt ".concat(retryCount + 1, "/").concat(maxRetries, ")"));
|
|
143
|
+
initIframe();
|
|
45
144
|
};
|
|
46
145
|
var engineOnLoad = function engineOnLoad(event) {
|
|
47
|
-
|
|
146
|
+
console.log("收到消息:", event.data);
|
|
147
|
+
if (event.data.type === 'xrender-load-error') {
|
|
148
|
+
console.error('XRender load error from iframe:', event.data.message);
|
|
149
|
+
if (retryCount < maxRetries) {
|
|
150
|
+
setTimeout(function () {
|
|
151
|
+
return retryIframe();
|
|
152
|
+
}, 1000);
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (event.data.type === 'xrender-fully-loaded') {
|
|
157
|
+
console.log('XRender fully loaded, function available:', event.data.available);
|
|
158
|
+
if (!event.data.available && retryCount < maxRetries) {
|
|
159
|
+
setTimeout(function () {
|
|
160
|
+
return retryIframe();
|
|
161
|
+
}, 1000);
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
48
165
|
if (event.data.type !== 'engine-load') {
|
|
49
166
|
return;
|
|
50
167
|
}
|
|
51
|
-
console.log("
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
168
|
+
console.log("iframe引擎加载事件:", event);
|
|
169
|
+
|
|
170
|
+
// 延迟执行以确保函数已定义
|
|
171
|
+
setTimeout(function () {
|
|
172
|
+
try {
|
|
173
|
+
var _iframe7, _iframe7$contentWindo, _iframe9, _iframe9$contentWindo, _iframe9$contentWindo2;
|
|
174
|
+
// 再次检查函数是否存在
|
|
175
|
+
if (typeof ((_iframe7 = iframe) === null || _iframe7 === void 0 ? void 0 : (_iframe7$contentWindo = _iframe7.contentWindow) === null || _iframe7$contentWindo === void 0 ? void 0 : _iframe7$contentWindo.getFormRenderMaterial) !== 'function') {
|
|
176
|
+
console.error('getFormRenderMaterial is not a function when initializing engine');
|
|
177
|
+
|
|
178
|
+
// 尝试从其他位置查找函数
|
|
179
|
+
var findFunction = function findFunction() {
|
|
180
|
+
var _iframe8, _iframeWindow$window, _iframeWindow$parent;
|
|
181
|
+
var iframeWindow = (_iframe8 = iframe) === null || _iframe8 === void 0 ? void 0 : _iframe8.contentWindow;
|
|
182
|
+
if (!iframeWindow) return null;
|
|
183
|
+
|
|
184
|
+
// 尝试多种方式查找
|
|
185
|
+
return iframeWindow.getFormRenderMaterial || ((_iframeWindow$window = iframeWindow.window) === null || _iframeWindow$window === void 0 ? void 0 : _iframeWindow$window.getFormRenderMaterial) || ((_iframeWindow$parent = iframeWindow.parent) === null || _iframeWindow$parent === void 0 ? void 0 : _iframeWindow$parent.getFormRenderMaterial) || iframeWindow._xrenderFunctions && iframeWindow._xrenderFunctions.getFormRenderMaterial;
|
|
186
|
+
};
|
|
187
|
+
var func = findFunction();
|
|
188
|
+
if (func && typeof func === 'function') {
|
|
189
|
+
console.log('Found getFormRenderMaterial via alternative method');
|
|
190
|
+
// 重新赋值
|
|
191
|
+
iframe.contentWindow.getFormRenderMaterial = func;
|
|
192
|
+
} else if (retryCount < maxRetries) {
|
|
193
|
+
console.log('Will retry iframe creation');
|
|
194
|
+
setRetryCount(function (prev) {
|
|
195
|
+
var newCount = prev + 1;
|
|
196
|
+
if (newCount <= maxRetries) {
|
|
197
|
+
setTimeout(function () {
|
|
198
|
+
return retryIframe();
|
|
199
|
+
}, 500);
|
|
200
|
+
}
|
|
201
|
+
return newCount;
|
|
202
|
+
});
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// 一切正常,初始化引擎
|
|
208
|
+
(_iframe9 = iframe) === null || _iframe9 === void 0 ? void 0 : (_iframe9$contentWindo = _iframe9.contentWindow) === null || _iframe9$contentWindo === void 0 ? void 0 : (_iframe9$contentWindo2 = _iframe9$contentWindo.__FR_ENGINE__) === null || _iframe9$contentWindo2 === void 0 ? void 0 : _iframe9$contentWindo2.init(_objectSpread({
|
|
209
|
+
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
210
|
+
widgets: widgets,
|
|
211
|
+
logo: {
|
|
212
|
+
title: 'XRender'
|
|
213
|
+
}
|
|
214
|
+
}, restProps));
|
|
215
|
+
|
|
216
|
+
// 重置重试计数
|
|
217
|
+
setRetryCount(0);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error('Error initializing FR_ENGINE:', error);
|
|
220
|
+
if (retryCount < maxRetries) {
|
|
221
|
+
setTimeout(function () {
|
|
222
|
+
return retryIframe();
|
|
223
|
+
}, 1000);
|
|
224
|
+
}
|
|
58
225
|
}
|
|
59
|
-
},
|
|
226
|
+
}, 100);
|
|
60
227
|
};
|
|
61
228
|
return /*#__PURE__*/React.createElement("div", {
|
|
62
229
|
ref: containerRef,
|
package/lib/createIframe.js
CHANGED
|
@@ -4,9 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
// createIframe.ts
|
|
8
7
|
var createIframeContent = function createIframeContent() {
|
|
9
|
-
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 <
|
|
8
|
+
var html = "\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" />\n <title>XRender</title>\n <link rel=\"icon\" href=\"https://img.alicdn.com/tfs/TB17UtINiLaK1RjSZFxXXamPFXa-606-643.png\">\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/variables.css\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css\" />\n\n <script>\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js\"></script>\n\n <body>\n <div id=\"lce-container\"></div>\n <script type=\"text/javascript\" src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js\"></script>\n </body>\n </html>\n ";
|
|
10
9
|
return html;
|
|
11
10
|
};
|
|
12
11
|
var _default = exports.default = function _default() {
|
|
@@ -14,25 +13,6 @@ var _default = exports.default = function _default() {
|
|
|
14
13
|
iframe.width = '100%';
|
|
15
14
|
iframe.height = '100%';
|
|
16
15
|
iframe.frameBorder = '0';
|
|
17
|
-
|
|
18
|
-
// 使用唯一ID来避免缓存
|
|
19
|
-
var iframeId = 'xrender-iframe-' + Date.now();
|
|
20
|
-
iframe.id = iframeId;
|
|
21
|
-
iframe.name = iframeId;
|
|
22
|
-
|
|
23
|
-
// 添加防缓存参数
|
|
24
|
-
var htmlContent = createIframeContent();
|
|
25
|
-
var blob = new Blob([htmlContent], {
|
|
26
|
-
type: 'text/html'
|
|
27
|
-
});
|
|
28
|
-
var url = URL.createObjectURL(blob);
|
|
29
|
-
iframe.src = url;
|
|
30
|
-
|
|
31
|
-
// 清理URL对象
|
|
32
|
-
iframe.onload = function () {
|
|
33
|
-
setTimeout(function () {
|
|
34
|
-
return URL.revokeObjectURL(url);
|
|
35
|
-
}, 1000);
|
|
36
|
-
};
|
|
16
|
+
iframe.srcdoc = createIframeContent();
|
|
37
17
|
return iframe;
|
|
38
18
|
};
|
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"];
|
|
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; }
|
|
@@ -16,6 +16,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
16
16
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
17
17
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
18
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
20
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
22
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
23
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
24
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
19
25
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
20
26
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
21
27
|
var iframe;
|
|
@@ -24,6 +30,11 @@ var Design = function Design(props, ref) {
|
|
|
24
30
|
settings = props.settings,
|
|
25
31
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
26
32
|
var containerRef = (0, _react.useRef)();
|
|
33
|
+
var _useState = (0, _react.useState)(0),
|
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
35
|
+
retryCount = _useState2[0],
|
|
36
|
+
setRetryCount = _useState2[1];
|
|
37
|
+
var maxRetries = 3;
|
|
27
38
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
28
39
|
return {
|
|
29
40
|
getValue: function getValue() {
|
|
@@ -35,36 +46,191 @@ var Design = function Design(props, ref) {
|
|
|
35
46
|
setValue: function setValue(schema) {
|
|
36
47
|
var _iframe4, _iframe4$contentWindo, _iframe4$contentWindo2, _iframe4$contentWindo3;
|
|
37
48
|
return (_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : (_iframe4$contentWindo = _iframe4.contentWindow) === null || _iframe4$contentWindo === void 0 ? void 0 : (_iframe4$contentWindo2 = _iframe4$contentWindo.__FR_ENGINE__) === null || _iframe4$contentWindo2 === void 0 ? void 0 : (_iframe4$contentWindo3 = _iframe4$contentWindo2.importSchema) === null || _iframe4$contentWindo3 === void 0 ? void 0 : _iframe4$contentWindo3.call(_iframe4$contentWindo2, schema);
|
|
49
|
+
},
|
|
50
|
+
// 添加检查方法
|
|
51
|
+
checkStatus: function checkStatus() {
|
|
52
|
+
var _iframe5, _iframe5$contentWindo, _iframe6, _iframe6$contentWindo;
|
|
53
|
+
return {
|
|
54
|
+
iframeReady: !!iframe,
|
|
55
|
+
hasFormRenderMaterial: typeof ((_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : (_iframe5$contentWindo = _iframe5.contentWindow) === null || _iframe5$contentWindo === void 0 ? void 0 : _iframe5$contentWindo.getFormRenderMaterial) === 'function',
|
|
56
|
+
hasEngine: !!((_iframe6 = iframe) === null || _iframe6 === void 0 ? void 0 : (_iframe6$contentWindo = _iframe6.contentWindow) === null || _iframe6$contentWindo === void 0 ? void 0 : _iframe6$contentWindo.__FR_ENGINE__)
|
|
57
|
+
};
|
|
38
58
|
}
|
|
39
59
|
};
|
|
40
60
|
});
|
|
41
61
|
(0, _react.useEffect)(function () {
|
|
42
62
|
initIframe();
|
|
43
63
|
window.addEventListener('message', engineOnLoad);
|
|
64
|
+
|
|
65
|
+
// 添加定时检查
|
|
66
|
+
var checkInterval = setInterval(checkIframeStatus, 2000);
|
|
44
67
|
return function () {
|
|
45
68
|
window.removeEventListener('message', engineOnLoad);
|
|
69
|
+
clearInterval(checkInterval);
|
|
70
|
+
// 清理iframe
|
|
71
|
+
if (iframe && containerRef.current) {
|
|
72
|
+
try {
|
|
73
|
+
containerRef.current.removeChild(iframe);
|
|
74
|
+
} catch (e) {}
|
|
75
|
+
iframe = null;
|
|
76
|
+
}
|
|
46
77
|
};
|
|
47
78
|
}, []);
|
|
79
|
+
var checkIframeStatus = function checkIframeStatus() {
|
|
80
|
+
if (!iframe) return;
|
|
81
|
+
try {
|
|
82
|
+
var _iframe$contentWindow, _iframe$contentWindow2;
|
|
83
|
+
var hasFunction = typeof ((_iframe$contentWindow = iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : _iframe$contentWindow.getFormRenderMaterial) === 'function';
|
|
84
|
+
var hasEngine = !!((_iframe$contentWindow2 = iframe.contentWindow) === null || _iframe$contentWindow2 === void 0 ? void 0 : _iframe$contentWindow2.__FR_ENGINE__);
|
|
85
|
+
if (!hasFunction && retryCount < maxRetries) {
|
|
86
|
+
console.warn("getFormRenderMaterial not found, retrying... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
|
|
87
|
+
setRetryCount(function (prev) {
|
|
88
|
+
var newCount = prev + 1;
|
|
89
|
+
if (newCount <= maxRetries) {
|
|
90
|
+
setTimeout(function () {
|
|
91
|
+
return retryIframe();
|
|
92
|
+
}, 500);
|
|
93
|
+
}
|
|
94
|
+
return newCount;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error('Error checking iframe status:', e);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
48
101
|
var initIframe = function initIframe() {
|
|
49
102
|
console.log("开始创建 iframe");
|
|
103
|
+
|
|
104
|
+
// 清理旧的iframe
|
|
105
|
+
if (containerRef.current && iframe) {
|
|
106
|
+
try {
|
|
107
|
+
containerRef.current.removeChild(iframe);
|
|
108
|
+
} catch (e) {}
|
|
109
|
+
iframe = null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 创建新的iframe
|
|
50
113
|
iframe = (0, _createIframe.default)();
|
|
114
|
+
|
|
115
|
+
// 添加加载错误处理
|
|
116
|
+
iframe.onerror = function (e) {
|
|
117
|
+
console.error('Iframe loading error:', e);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// 添加加载超时处理
|
|
121
|
+
var loadTimeout = setTimeout(function () {
|
|
122
|
+
if (iframe && (!iframe.contentWindow || !iframe.contentWindow.document)) {
|
|
123
|
+
console.error('Iframe load timeout');
|
|
124
|
+
retryIframe();
|
|
125
|
+
}
|
|
126
|
+
}, 10000);
|
|
127
|
+
iframe.onload = function () {
|
|
128
|
+
clearTimeout(loadTimeout);
|
|
129
|
+
console.log("iframe 加载完成");
|
|
130
|
+
|
|
131
|
+
// 等待iframe内部脚本执行
|
|
132
|
+
setTimeout(function () {
|
|
133
|
+
try {
|
|
134
|
+
var _iframe$contentWindow3;
|
|
135
|
+
// 检查函数是否存在
|
|
136
|
+
var hasFunction = typeof ((_iframe$contentWindow3 = iframe.contentWindow) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.getFormRenderMaterial) === 'function';
|
|
137
|
+
if (!hasFunction) {
|
|
138
|
+
console.warn('getFormRenderMaterial not found after iframe loaded');
|
|
139
|
+
}
|
|
140
|
+
} catch (e) {
|
|
141
|
+
console.error('Error checking function after iframe load:', e);
|
|
142
|
+
}
|
|
143
|
+
}, 1000);
|
|
144
|
+
};
|
|
51
145
|
containerRef.current.appendChild(iframe);
|
|
52
|
-
console.log("iframe
|
|
146
|
+
console.log("iframe 创建完成");
|
|
147
|
+
};
|
|
148
|
+
var retryIframe = function retryIframe() {
|
|
149
|
+
console.log("Retrying iframe creation (attempt ".concat(retryCount + 1, "/").concat(maxRetries, ")"));
|
|
150
|
+
initIframe();
|
|
53
151
|
};
|
|
54
152
|
var engineOnLoad = function engineOnLoad(event) {
|
|
55
|
-
|
|
153
|
+
console.log("收到消息:", event.data);
|
|
154
|
+
if (event.data.type === 'xrender-load-error') {
|
|
155
|
+
console.error('XRender load error from iframe:', event.data.message);
|
|
156
|
+
if (retryCount < maxRetries) {
|
|
157
|
+
setTimeout(function () {
|
|
158
|
+
return retryIframe();
|
|
159
|
+
}, 1000);
|
|
160
|
+
}
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (event.data.type === 'xrender-fully-loaded') {
|
|
164
|
+
console.log('XRender fully loaded, function available:', event.data.available);
|
|
165
|
+
if (!event.data.available && retryCount < maxRetries) {
|
|
166
|
+
setTimeout(function () {
|
|
167
|
+
return retryIframe();
|
|
168
|
+
}, 1000);
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
56
172
|
if (event.data.type !== 'engine-load') {
|
|
57
173
|
return;
|
|
58
174
|
}
|
|
59
|
-
console.log("
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
175
|
+
console.log("iframe引擎加载事件:", event);
|
|
176
|
+
|
|
177
|
+
// 延迟执行以确保函数已定义
|
|
178
|
+
setTimeout(function () {
|
|
179
|
+
try {
|
|
180
|
+
var _iframe7, _iframe7$contentWindo, _iframe9, _iframe9$contentWindo, _iframe9$contentWindo2;
|
|
181
|
+
// 再次检查函数是否存在
|
|
182
|
+
if (typeof ((_iframe7 = iframe) === null || _iframe7 === void 0 ? void 0 : (_iframe7$contentWindo = _iframe7.contentWindow) === null || _iframe7$contentWindo === void 0 ? void 0 : _iframe7$contentWindo.getFormRenderMaterial) !== 'function') {
|
|
183
|
+
console.error('getFormRenderMaterial is not a function when initializing engine');
|
|
184
|
+
|
|
185
|
+
// 尝试从其他位置查找函数
|
|
186
|
+
var findFunction = function findFunction() {
|
|
187
|
+
var _iframe8, _iframeWindow$window, _iframeWindow$parent;
|
|
188
|
+
var iframeWindow = (_iframe8 = iframe) === null || _iframe8 === void 0 ? void 0 : _iframe8.contentWindow;
|
|
189
|
+
if (!iframeWindow) return null;
|
|
190
|
+
|
|
191
|
+
// 尝试多种方式查找
|
|
192
|
+
return iframeWindow.getFormRenderMaterial || ((_iframeWindow$window = iframeWindow.window) === null || _iframeWindow$window === void 0 ? void 0 : _iframeWindow$window.getFormRenderMaterial) || ((_iframeWindow$parent = iframeWindow.parent) === null || _iframeWindow$parent === void 0 ? void 0 : _iframeWindow$parent.getFormRenderMaterial) || iframeWindow._xrenderFunctions && iframeWindow._xrenderFunctions.getFormRenderMaterial;
|
|
193
|
+
};
|
|
194
|
+
var func = findFunction();
|
|
195
|
+
if (func && typeof func === 'function') {
|
|
196
|
+
console.log('Found getFormRenderMaterial via alternative method');
|
|
197
|
+
// 重新赋值
|
|
198
|
+
iframe.contentWindow.getFormRenderMaterial = func;
|
|
199
|
+
} else if (retryCount < maxRetries) {
|
|
200
|
+
console.log('Will retry iframe creation');
|
|
201
|
+
setRetryCount(function (prev) {
|
|
202
|
+
var newCount = prev + 1;
|
|
203
|
+
if (newCount <= maxRetries) {
|
|
204
|
+
setTimeout(function () {
|
|
205
|
+
return retryIframe();
|
|
206
|
+
}, 500);
|
|
207
|
+
}
|
|
208
|
+
return newCount;
|
|
209
|
+
});
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 一切正常,初始化引擎
|
|
215
|
+
(_iframe9 = iframe) === null || _iframe9 === void 0 ? void 0 : (_iframe9$contentWindo = _iframe9.contentWindow) === null || _iframe9$contentWindo === void 0 ? void 0 : (_iframe9$contentWindo2 = _iframe9$contentWindo.__FR_ENGINE__) === null || _iframe9$contentWindo2 === void 0 ? void 0 : _iframe9$contentWindo2.init(_objectSpread({
|
|
216
|
+
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
217
|
+
widgets: widgets,
|
|
218
|
+
logo: {
|
|
219
|
+
title: 'XRender'
|
|
220
|
+
}
|
|
221
|
+
}, restProps));
|
|
222
|
+
|
|
223
|
+
// 重置重试计数
|
|
224
|
+
setRetryCount(0);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
console.error('Error initializing FR_ENGINE:', error);
|
|
227
|
+
if (retryCount < maxRetries) {
|
|
228
|
+
setTimeout(function () {
|
|
229
|
+
return retryIframe();
|
|
230
|
+
}, 1000);
|
|
231
|
+
}
|
|
66
232
|
}
|
|
67
|
-
},
|
|
233
|
+
}, 100);
|
|
68
234
|
};
|
|
69
235
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
70
236
|
ref: containerRef,
|