@zzdadelu/schema-builder 1.0.0-alpha.55 → 1.0.0-alpha.57
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/main.js +168 -19
- package/lib/main.js +167 -18
- package/package.json +1 -1
package/es/main.js
CHANGED
|
@@ -5,17 +5,33 @@ 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
|
-
import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
|
|
16
|
+
import React, { useEffect, useRef, useImperativeHandle, forwardRef, useState } from 'react';
|
|
11
17
|
import createIframe from './createIframe';
|
|
12
18
|
import * as defaultSetting from './settings';
|
|
13
19
|
var iframe;
|
|
20
|
+
var retryCount = 0;
|
|
21
|
+
var MAX_RETRIES = 3;
|
|
14
22
|
var Design = function Design(props, ref) {
|
|
15
23
|
var widgets = props.widgets,
|
|
16
24
|
settings = props.settings,
|
|
17
25
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
18
|
-
var containerRef = useRef();
|
|
26
|
+
var containerRef = useRef(null);
|
|
27
|
+
var _useState = useState(true),
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
29
|
+
loading = _useState2[0],
|
|
30
|
+
setLoading = _useState2[1];
|
|
31
|
+
var _useState3 = useState(false),
|
|
32
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
33
|
+
isMounted = _useState4[0],
|
|
34
|
+
setIsMounted = _useState4[1];
|
|
19
35
|
useImperativeHandle(ref, function () {
|
|
20
36
|
return {
|
|
21
37
|
getValue: function getValue() {
|
|
@@ -25,40 +41,173 @@ var Design = function Design(props, ref) {
|
|
|
25
41
|
setValue: function setValue(schema) {
|
|
26
42
|
var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
|
|
27
43
|
return (_iframe2 = iframe) === null || _iframe2 === void 0 ? void 0 : (_iframe2$contentWindo = _iframe2.contentWindow) === null || _iframe2$contentWindo === void 0 ? void 0 : (_iframe2$contentWindo2 = _iframe2$contentWindo.__FR_ENGINE__) === null || _iframe2$contentWindo2 === void 0 ? void 0 : (_iframe2$contentWindo3 = _iframe2$contentWindo2.importSchema) === null || _iframe2$contentWindo3 === void 0 ? void 0 : _iframe2$contentWindo3.call(_iframe2$contentWindo2, schema);
|
|
44
|
+
},
|
|
45
|
+
reload: function reload() {
|
|
46
|
+
if (containerRef.current && iframe) {
|
|
47
|
+
containerRef.current.removeChild(iframe);
|
|
48
|
+
iframe = null;
|
|
49
|
+
retryCount = 0;
|
|
50
|
+
initIframe();
|
|
51
|
+
}
|
|
28
52
|
}
|
|
29
53
|
};
|
|
30
54
|
});
|
|
31
55
|
useEffect(function () {
|
|
32
|
-
|
|
33
|
-
window.addEventListener('message', engineOnLoad);
|
|
56
|
+
setIsMounted(true);
|
|
34
57
|
return function () {
|
|
35
|
-
|
|
58
|
+
setIsMounted(false);
|
|
36
59
|
};
|
|
37
60
|
}, []);
|
|
61
|
+
useEffect(function () {
|
|
62
|
+
if (!isMounted || !containerRef.current) return;
|
|
63
|
+
initIframe();
|
|
64
|
+
var messageHandler = handleMessage;
|
|
65
|
+
window.addEventListener('message', messageHandler);
|
|
66
|
+
return function () {
|
|
67
|
+
window.removeEventListener('message', messageHandler);
|
|
68
|
+
cleanupIframe();
|
|
69
|
+
};
|
|
70
|
+
}, [isMounted]);
|
|
71
|
+
var cleanupIframe = function cleanupIframe() {
|
|
72
|
+
// if (iframe && containerRef.current) {
|
|
73
|
+
// try {
|
|
74
|
+
// containerRef.current.removeChild(iframe);
|
|
75
|
+
// } catch (e) {
|
|
76
|
+
// // 忽略移除错误
|
|
77
|
+
// }
|
|
78
|
+
// iframe = null;
|
|
79
|
+
// }
|
|
80
|
+
};
|
|
38
81
|
var initIframe = function initIframe() {
|
|
82
|
+
console.log('[SchemaBuilder] Initializing iframe, retry:', retryCount);
|
|
83
|
+
|
|
84
|
+
// 确保容器存在
|
|
85
|
+
if (!containerRef.current) {
|
|
86
|
+
console.error('[SchemaBuilder] Container ref is null');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 清理旧的 iframe
|
|
91
|
+
// cleanupIframe();
|
|
92
|
+
|
|
93
|
+
// 创建新的 iframe
|
|
39
94
|
iframe = createIframe();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
95
|
+
|
|
96
|
+
// 添加错误处理
|
|
97
|
+
iframe.onerror = function (e) {
|
|
98
|
+
console.error('[SchemaBuilder] Iframe error:', e);
|
|
99
|
+
};
|
|
100
|
+
iframe.onload = function () {
|
|
101
|
+
console.log('[SchemaBuilder] Iframe loaded');
|
|
102
|
+
setLoading(false);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// 确保容器存在再添加 iframe
|
|
106
|
+
if (containerRef.current) {
|
|
107
|
+
containerRef.current.appendChild(iframe);
|
|
108
|
+
} else {
|
|
109
|
+
console.error('[SchemaBuilder] Cannot append iframe, container is null');
|
|
45
110
|
return;
|
|
46
111
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
112
|
+
|
|
113
|
+
// 设置超时重试
|
|
114
|
+
var timeoutId = setTimeout(function () {
|
|
115
|
+
if (iframe && (!iframe.contentWindow || !iframe.contentDocument)) {
|
|
116
|
+
console.warn('[SchemaBuilder] Iframe load timeout, retrying...');
|
|
117
|
+
retryIframe();
|
|
53
118
|
}
|
|
54
|
-
},
|
|
119
|
+
}, 10000);
|
|
120
|
+
|
|
121
|
+
// 保存 timeoutId 以便清理
|
|
122
|
+
return function () {
|
|
123
|
+
return clearTimeout(timeoutId);
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
var retryIframe = function retryIframe() {
|
|
127
|
+
if (!isMounted || !containerRef.current) {
|
|
128
|
+
console.log('[SchemaBuilder] Component unmounted, skipping retry');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (retryCount < MAX_RETRIES) {
|
|
132
|
+
retryCount++;
|
|
133
|
+
console.warn("[SchemaBuilder] Retrying iframe creation (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
|
|
134
|
+
initIframe();
|
|
135
|
+
} else {
|
|
136
|
+
console.error('[SchemaBuilder] Max retries reached');
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var handleMessage = function handleMessage(event) {
|
|
140
|
+
// 处理来自 iframe 的各种消息
|
|
141
|
+
switch (event.data.type) {
|
|
142
|
+
case 'getFormRenderMaterial-ready':
|
|
143
|
+
console.log('[SchemaBuilder] getFormRenderMaterial is ready in iframe');
|
|
144
|
+
break;
|
|
145
|
+
case 'engine-load':
|
|
146
|
+
console.log('[SchemaBuilder] Engine loaded, checks:', event.data.checks);
|
|
147
|
+
if (event.data.checks && !event.data.checks.getFormRenderMaterial) {
|
|
148
|
+
console.error('[SchemaBuilder] getFormRenderMaterial check failed, retrying...');
|
|
149
|
+
setTimeout(function () {
|
|
150
|
+
if (isMounted) retryIframe();
|
|
151
|
+
}, 500);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 延迟初始化以确保所有资源就绪
|
|
156
|
+
var initTimeout = setTimeout(function () {
|
|
157
|
+
try {
|
|
158
|
+
var _iframe3, _iframe3$contentWindo;
|
|
159
|
+
if ((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : _iframe3$contentWindo.__FR_ENGINE__) {
|
|
160
|
+
iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
|
|
161
|
+
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
162
|
+
widgets: widgets,
|
|
163
|
+
logo: {
|
|
164
|
+
title: 'XRender'
|
|
165
|
+
}
|
|
166
|
+
}, restProps));
|
|
167
|
+
console.log('[SchemaBuilder] Engine initialized successfully');
|
|
168
|
+
} else {
|
|
169
|
+
console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe');
|
|
170
|
+
if (isMounted) retryIframe();
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.error('[SchemaBuilder] Error initializing engine:', error);
|
|
174
|
+
if (isMounted) retryIframe();
|
|
175
|
+
}
|
|
176
|
+
}, 500);
|
|
177
|
+
|
|
178
|
+
// 清理 timeout
|
|
179
|
+
return function () {
|
|
180
|
+
return clearTimeout(initTimeout);
|
|
181
|
+
};
|
|
182
|
+
default:
|
|
183
|
+
// 其他消息可以忽略
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
55
186
|
};
|
|
56
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
187
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, loading && /*#__PURE__*/React.createElement("div", {
|
|
188
|
+
style: {
|
|
189
|
+
position: 'absolute',
|
|
190
|
+
top: 0,
|
|
191
|
+
left: 0,
|
|
192
|
+
right: 0,
|
|
193
|
+
bottom: 0,
|
|
194
|
+
display: 'flex',
|
|
195
|
+
alignItems: 'center',
|
|
196
|
+
justifyContent: 'center',
|
|
197
|
+
backgroundColor: 'rgba(255, 255, 255, 0.8)',
|
|
198
|
+
zIndex: 10
|
|
199
|
+
}
|
|
200
|
+
}, /*#__PURE__*/React.createElement("div", null, "\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668...", retryCount > 0 && /*#__PURE__*/React.createElement("div", {
|
|
201
|
+
style: {
|
|
202
|
+
fontSize: '12px',
|
|
203
|
+
color: '#666'
|
|
204
|
+
}
|
|
205
|
+
}, "\u91CD\u8BD5 ", retryCount, "/", MAX_RETRIES))), /*#__PURE__*/React.createElement("div", {
|
|
57
206
|
ref: containerRef,
|
|
58
207
|
style: {
|
|
59
208
|
width: '100%',
|
|
60
209
|
height: '100%'
|
|
61
210
|
}
|
|
62
|
-
});
|
|
211
|
+
}));
|
|
63
212
|
};
|
|
64
213
|
export default /*#__PURE__*/forwardRef(Design);
|
package/lib/main.js
CHANGED
|
@@ -16,14 +16,30 @@ 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;
|
|
28
|
+
var retryCount = 0;
|
|
29
|
+
var MAX_RETRIES = 3;
|
|
22
30
|
var Design = function Design(props, ref) {
|
|
23
31
|
var widgets = props.widgets,
|
|
24
32
|
settings = props.settings,
|
|
25
33
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
26
|
-
var containerRef = (0, _react.useRef)();
|
|
34
|
+
var containerRef = (0, _react.useRef)(null);
|
|
35
|
+
var _useState = (0, _react.useState)(true),
|
|
36
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
37
|
+
loading = _useState2[0],
|
|
38
|
+
setLoading = _useState2[1];
|
|
39
|
+
var _useState3 = (0, _react.useState)(false),
|
|
40
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
41
|
+
isMounted = _useState4[0],
|
|
42
|
+
setIsMounted = _useState4[1];
|
|
27
43
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
28
44
|
return {
|
|
29
45
|
getValue: function getValue() {
|
|
@@ -33,40 +49,173 @@ var Design = function Design(props, ref) {
|
|
|
33
49
|
setValue: function setValue(schema) {
|
|
34
50
|
var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
|
|
35
51
|
return (_iframe2 = iframe) === null || _iframe2 === void 0 ? void 0 : (_iframe2$contentWindo = _iframe2.contentWindow) === null || _iframe2$contentWindo === void 0 ? void 0 : (_iframe2$contentWindo2 = _iframe2$contentWindo.__FR_ENGINE__) === null || _iframe2$contentWindo2 === void 0 ? void 0 : (_iframe2$contentWindo3 = _iframe2$contentWindo2.importSchema) === null || _iframe2$contentWindo3 === void 0 ? void 0 : _iframe2$contentWindo3.call(_iframe2$contentWindo2, schema);
|
|
52
|
+
},
|
|
53
|
+
reload: function reload() {
|
|
54
|
+
if (containerRef.current && iframe) {
|
|
55
|
+
containerRef.current.removeChild(iframe);
|
|
56
|
+
iframe = null;
|
|
57
|
+
retryCount = 0;
|
|
58
|
+
initIframe();
|
|
59
|
+
}
|
|
36
60
|
}
|
|
37
61
|
};
|
|
38
62
|
});
|
|
39
63
|
(0, _react.useEffect)(function () {
|
|
40
|
-
|
|
41
|
-
window.addEventListener('message', engineOnLoad);
|
|
64
|
+
setIsMounted(true);
|
|
42
65
|
return function () {
|
|
43
|
-
|
|
66
|
+
setIsMounted(false);
|
|
44
67
|
};
|
|
45
68
|
}, []);
|
|
69
|
+
(0, _react.useEffect)(function () {
|
|
70
|
+
if (!isMounted || !containerRef.current) return;
|
|
71
|
+
initIframe();
|
|
72
|
+
var messageHandler = handleMessage;
|
|
73
|
+
window.addEventListener('message', messageHandler);
|
|
74
|
+
return function () {
|
|
75
|
+
window.removeEventListener('message', messageHandler);
|
|
76
|
+
cleanupIframe();
|
|
77
|
+
};
|
|
78
|
+
}, [isMounted]);
|
|
79
|
+
var cleanupIframe = function cleanupIframe() {
|
|
80
|
+
// if (iframe && containerRef.current) {
|
|
81
|
+
// try {
|
|
82
|
+
// containerRef.current.removeChild(iframe);
|
|
83
|
+
// } catch (e) {
|
|
84
|
+
// // 忽略移除错误
|
|
85
|
+
// }
|
|
86
|
+
// iframe = null;
|
|
87
|
+
// }
|
|
88
|
+
};
|
|
46
89
|
var initIframe = function initIframe() {
|
|
90
|
+
console.log('[SchemaBuilder] Initializing iframe, retry:', retryCount);
|
|
91
|
+
|
|
92
|
+
// 确保容器存在
|
|
93
|
+
if (!containerRef.current) {
|
|
94
|
+
console.error('[SchemaBuilder] Container ref is null');
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 清理旧的 iframe
|
|
99
|
+
// cleanupIframe();
|
|
100
|
+
|
|
101
|
+
// 创建新的 iframe
|
|
47
102
|
iframe = (0, _createIframe.default)();
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
103
|
+
|
|
104
|
+
// 添加错误处理
|
|
105
|
+
iframe.onerror = function (e) {
|
|
106
|
+
console.error('[SchemaBuilder] Iframe error:', e);
|
|
107
|
+
};
|
|
108
|
+
iframe.onload = function () {
|
|
109
|
+
console.log('[SchemaBuilder] Iframe loaded');
|
|
110
|
+
setLoading(false);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// 确保容器存在再添加 iframe
|
|
114
|
+
if (containerRef.current) {
|
|
115
|
+
containerRef.current.appendChild(iframe);
|
|
116
|
+
} else {
|
|
117
|
+
console.error('[SchemaBuilder] Cannot append iframe, container is null');
|
|
53
118
|
return;
|
|
54
119
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
120
|
+
|
|
121
|
+
// 设置超时重试
|
|
122
|
+
var timeoutId = setTimeout(function () {
|
|
123
|
+
if (iframe && (!iframe.contentWindow || !iframe.contentDocument)) {
|
|
124
|
+
console.warn('[SchemaBuilder] Iframe load timeout, retrying...');
|
|
125
|
+
retryIframe();
|
|
61
126
|
}
|
|
62
|
-
},
|
|
127
|
+
}, 10000);
|
|
128
|
+
|
|
129
|
+
// 保存 timeoutId 以便清理
|
|
130
|
+
return function () {
|
|
131
|
+
return clearTimeout(timeoutId);
|
|
132
|
+
};
|
|
63
133
|
};
|
|
64
|
-
|
|
134
|
+
var retryIframe = function retryIframe() {
|
|
135
|
+
if (!isMounted || !containerRef.current) {
|
|
136
|
+
console.log('[SchemaBuilder] Component unmounted, skipping retry');
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (retryCount < MAX_RETRIES) {
|
|
140
|
+
retryCount++;
|
|
141
|
+
console.warn("[SchemaBuilder] Retrying iframe creation (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
|
|
142
|
+
initIframe();
|
|
143
|
+
} else {
|
|
144
|
+
console.error('[SchemaBuilder] Max retries reached');
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var handleMessage = function handleMessage(event) {
|
|
148
|
+
// 处理来自 iframe 的各种消息
|
|
149
|
+
switch (event.data.type) {
|
|
150
|
+
case 'getFormRenderMaterial-ready':
|
|
151
|
+
console.log('[SchemaBuilder] getFormRenderMaterial is ready in iframe');
|
|
152
|
+
break;
|
|
153
|
+
case 'engine-load':
|
|
154
|
+
console.log('[SchemaBuilder] Engine loaded, checks:', event.data.checks);
|
|
155
|
+
if (event.data.checks && !event.data.checks.getFormRenderMaterial) {
|
|
156
|
+
console.error('[SchemaBuilder] getFormRenderMaterial check failed, retrying...');
|
|
157
|
+
setTimeout(function () {
|
|
158
|
+
if (isMounted) retryIframe();
|
|
159
|
+
}, 500);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 延迟初始化以确保所有资源就绪
|
|
164
|
+
var initTimeout = setTimeout(function () {
|
|
165
|
+
try {
|
|
166
|
+
var _iframe3, _iframe3$contentWindo;
|
|
167
|
+
if ((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : _iframe3$contentWindo.__FR_ENGINE__) {
|
|
168
|
+
iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
|
|
169
|
+
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
170
|
+
widgets: widgets,
|
|
171
|
+
logo: {
|
|
172
|
+
title: 'XRender'
|
|
173
|
+
}
|
|
174
|
+
}, restProps));
|
|
175
|
+
console.log('[SchemaBuilder] Engine initialized successfully');
|
|
176
|
+
} else {
|
|
177
|
+
console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe');
|
|
178
|
+
if (isMounted) retryIframe();
|
|
179
|
+
}
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.error('[SchemaBuilder] Error initializing engine:', error);
|
|
182
|
+
if (isMounted) retryIframe();
|
|
183
|
+
}
|
|
184
|
+
}, 500);
|
|
185
|
+
|
|
186
|
+
// 清理 timeout
|
|
187
|
+
return function () {
|
|
188
|
+
return clearTimeout(initTimeout);
|
|
189
|
+
};
|
|
190
|
+
default:
|
|
191
|
+
// 其他消息可以忽略
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, loading && /*#__PURE__*/_react.default.createElement("div", {
|
|
196
|
+
style: {
|
|
197
|
+
position: 'absolute',
|
|
198
|
+
top: 0,
|
|
199
|
+
left: 0,
|
|
200
|
+
right: 0,
|
|
201
|
+
bottom: 0,
|
|
202
|
+
display: 'flex',
|
|
203
|
+
alignItems: 'center',
|
|
204
|
+
justifyContent: 'center',
|
|
205
|
+
backgroundColor: 'rgba(255, 255, 255, 0.8)',
|
|
206
|
+
zIndex: 10
|
|
207
|
+
}
|
|
208
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, "\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668...", retryCount > 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
209
|
+
style: {
|
|
210
|
+
fontSize: '12px',
|
|
211
|
+
color: '#666'
|
|
212
|
+
}
|
|
213
|
+
}, "\u91CD\u8BD5 ", retryCount, "/", MAX_RETRIES))), /*#__PURE__*/_react.default.createElement("div", {
|
|
65
214
|
ref: containerRef,
|
|
66
215
|
style: {
|
|
67
216
|
width: '100%',
|
|
68
217
|
height: '100%'
|
|
69
218
|
}
|
|
70
|
-
});
|
|
219
|
+
}));
|
|
71
220
|
};
|
|
72
221
|
var _default = exports.default = /*#__PURE__*/(0, _react.forwardRef)(Design);
|