@zzdadelu/schema-builder 1.0.0-alpha.53 → 1.0.0-alpha.54
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 +90 -112
- package/lib/main.js +89 -111
- package/package.json +1 -1
package/es/main.js
CHANGED
|
@@ -13,85 +13,67 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
13
13
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
14
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; }
|
|
15
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; }
|
|
16
|
-
import React, { useEffect, useRef, useImperativeHandle, forwardRef, useState } from 'react';
|
|
16
|
+
import React, { useEffect, useRef, useImperativeHandle, forwardRef, useState, useCallback } from 'react';
|
|
17
17
|
import createIframe from './createIframe';
|
|
18
18
|
import * as defaultSetting from './settings';
|
|
19
|
-
var iframe;
|
|
20
|
-
var retryCount = 0;
|
|
21
|
-
var MAX_RETRIES = 3;
|
|
22
19
|
var Design = function Design(props, ref) {
|
|
23
20
|
var widgets = props.widgets,
|
|
24
21
|
settings = props.settings,
|
|
25
22
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
26
23
|
var containerRef = useRef(null);
|
|
24
|
+
var iframeRef;
|
|
27
25
|
var _useState = useState(true),
|
|
28
26
|
_useState2 = _slicedToArray(_useState, 2),
|
|
29
27
|
loading = _useState2[0],
|
|
30
28
|
setLoading = _useState2[1];
|
|
31
|
-
var _useState3 = useState(
|
|
29
|
+
var _useState3 = useState(0),
|
|
32
30
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
retryCount = _useState4[0],
|
|
32
|
+
setRetryCount = _useState4[1];
|
|
33
|
+
var MAX_RETRIES = 3;
|
|
35
34
|
useImperativeHandle(ref, function () {
|
|
36
35
|
return {
|
|
37
36
|
getValue: function getValue() {
|
|
38
|
-
var
|
|
39
|
-
return (
|
|
37
|
+
var _iframeRef$current, _iframeRef$current$co, _iframeRef$current$co2, _iframeRef$current$co3;
|
|
38
|
+
return (_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : (_iframeRef$current$co = _iframeRef$current.contentWindow) === null || _iframeRef$current$co === void 0 ? void 0 : (_iframeRef$current$co2 = _iframeRef$current$co.__FR_ENGINE__) === null || _iframeRef$current$co2 === void 0 ? void 0 : (_iframeRef$current$co3 = _iframeRef$current$co2.exportSchema) === null || _iframeRef$current$co3 === void 0 ? void 0 : _iframeRef$current$co3.call(_iframeRef$current$co2);
|
|
40
39
|
},
|
|
41
40
|
setValue: function setValue(schema) {
|
|
42
|
-
var
|
|
43
|
-
return (
|
|
41
|
+
var _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2, _iframeRef$current2$c3;
|
|
42
|
+
return (_iframeRef$current2 = iframeRef.current) === null || _iframeRef$current2 === void 0 ? void 0 : (_iframeRef$current2$c = _iframeRef$current2.contentWindow) === null || _iframeRef$current2$c === void 0 ? void 0 : (_iframeRef$current2$c2 = _iframeRef$current2$c.__FR_ENGINE__) === null || _iframeRef$current2$c2 === void 0 ? void 0 : (_iframeRef$current2$c3 = _iframeRef$current2$c2.importSchema) === null || _iframeRef$current2$c3 === void 0 ? void 0 : _iframeRef$current2$c3.call(_iframeRef$current2$c2, schema);
|
|
44
43
|
},
|
|
45
44
|
reload: function reload() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
retryCount = 0;
|
|
50
|
-
initIframe();
|
|
51
|
-
}
|
|
45
|
+
setRetryCount(0);
|
|
46
|
+
cleanupIframe();
|
|
47
|
+
initIframe();
|
|
52
48
|
}
|
|
53
49
|
};
|
|
54
50
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return function () {
|
|
58
|
-
setIsMounted(false);
|
|
59
|
-
};
|
|
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) {
|
|
51
|
+
var cleanupIframe = useCallback(function () {
|
|
52
|
+
if (iframeRef.current && containerRef.current) {
|
|
73
53
|
try {
|
|
74
|
-
containerRef.current.removeChild(
|
|
54
|
+
containerRef.current.removeChild(iframeRef.current);
|
|
75
55
|
} catch (e) {
|
|
76
|
-
//
|
|
56
|
+
// 忽略错误
|
|
77
57
|
}
|
|
78
|
-
|
|
58
|
+
iframeRef.current = null;
|
|
79
59
|
}
|
|
80
|
-
};
|
|
81
|
-
var initIframe = function
|
|
60
|
+
}, []);
|
|
61
|
+
var initIframe = useCallback(function () {
|
|
82
62
|
console.log('[SchemaBuilder] Initializing iframe, retry:', retryCount);
|
|
83
63
|
|
|
64
|
+
// 清理旧的 iframe
|
|
65
|
+
cleanupIframe();
|
|
66
|
+
|
|
84
67
|
// 确保容器存在
|
|
85
68
|
if (!containerRef.current) {
|
|
86
|
-
console.error('[SchemaBuilder] Container ref is null');
|
|
69
|
+
console.error('[SchemaBuilder] Container ref is null, delaying iframe creation');
|
|
70
|
+
setTimeout(initIframe, 100);
|
|
87
71
|
return;
|
|
88
72
|
}
|
|
89
73
|
|
|
90
|
-
// 清理旧的 iframe
|
|
91
|
-
cleanupIframe();
|
|
92
|
-
|
|
93
74
|
// 创建新的 iframe
|
|
94
|
-
iframe = createIframe();
|
|
75
|
+
var iframe = createIframe();
|
|
76
|
+
iframeRef.current = iframe;
|
|
95
77
|
|
|
96
78
|
// 添加错误处理
|
|
97
79
|
iframe.onerror = function (e) {
|
|
@@ -102,88 +84,84 @@ var Design = function Design(props, ref) {
|
|
|
102
84
|
setLoading(false);
|
|
103
85
|
};
|
|
104
86
|
|
|
105
|
-
//
|
|
106
|
-
|
|
87
|
+
// 添加到容器
|
|
88
|
+
try {
|
|
107
89
|
containerRef.current.appendChild(iframe);
|
|
108
|
-
}
|
|
109
|
-
console.error('[SchemaBuilder]
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error('[SchemaBuilder] Failed to append iframe:', error);
|
|
92
|
+
if (retryCount < MAX_RETRIES) {
|
|
93
|
+
setRetryCount(function (prev) {
|
|
94
|
+
return prev + 1;
|
|
95
|
+
});
|
|
96
|
+
setTimeout(initIframe, 1000);
|
|
97
|
+
}
|
|
110
98
|
return;
|
|
111
99
|
}
|
|
112
100
|
|
|
113
|
-
//
|
|
101
|
+
// 设置超时检查
|
|
114
102
|
var timeoutId = setTimeout(function () {
|
|
115
103
|
if (iframe && (!iframe.contentWindow || !iframe.contentDocument)) {
|
|
116
|
-
console.warn('[SchemaBuilder] Iframe load timeout
|
|
117
|
-
|
|
104
|
+
console.warn('[SchemaBuilder] Iframe load timeout');
|
|
105
|
+
if (retryCount < MAX_RETRIES) {
|
|
106
|
+
setRetryCount(function (prev) {
|
|
107
|
+
return prev + 1;
|
|
108
|
+
});
|
|
109
|
+
cleanupIframe();
|
|
110
|
+
initIframe();
|
|
111
|
+
}
|
|
118
112
|
}
|
|
119
113
|
}, 10000);
|
|
120
|
-
|
|
121
|
-
// 保存 timeoutId 以便清理
|
|
122
114
|
return function () {
|
|
123
115
|
return clearTimeout(timeoutId);
|
|
124
116
|
};
|
|
125
|
-
};
|
|
126
|
-
var
|
|
127
|
-
if (
|
|
128
|
-
console.log('[SchemaBuilder] Component unmounted, skipping retry');
|
|
117
|
+
}, [cleanupIframe, retryCount]);
|
|
118
|
+
var handleMessage = useCallback(function (event) {
|
|
119
|
+
if (event.data.type !== 'engine-load') {
|
|
129
120
|
return;
|
|
130
121
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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();
|
|
122
|
+
console.log('[SchemaBuilder] Engine loaded');
|
|
123
|
+
setTimeout(function () {
|
|
124
|
+
try {
|
|
125
|
+
var _iframeRef$current3, _iframeRef$current3$c;
|
|
126
|
+
if ((_iframeRef$current3 = iframeRef.current) === null || _iframeRef$current3 === void 0 ? void 0 : (_iframeRef$current3$c = _iframeRef$current3.contentWindow) === null || _iframeRef$current3$c === void 0 ? void 0 : _iframeRef$current3$c.__FR_ENGINE__) {
|
|
127
|
+
iframeRef.current.contentWindow.__FR_ENGINE__.init(_objectSpread({
|
|
128
|
+
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
129
|
+
widgets: widgets,
|
|
130
|
+
logo: {
|
|
131
|
+
title: 'XRender'
|
|
171
132
|
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
133
|
+
}, restProps));
|
|
134
|
+
console.log('[SchemaBuilder] Engine initialized successfully');
|
|
135
|
+
} else {
|
|
136
|
+
console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe');
|
|
137
|
+
if (retryCount < MAX_RETRIES) {
|
|
138
|
+
setRetryCount(function (prev) {
|
|
139
|
+
return prev + 1;
|
|
140
|
+
});
|
|
141
|
+
cleanupIframe();
|
|
142
|
+
initIframe();
|
|
175
143
|
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
144
|
+
}
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error('[SchemaBuilder] Error initializing engine:', error);
|
|
147
|
+
if (retryCount < MAX_RETRIES) {
|
|
148
|
+
setRetryCount(function (prev) {
|
|
149
|
+
return prev + 1;
|
|
150
|
+
});
|
|
151
|
+
cleanupIframe();
|
|
152
|
+
initIframe();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}, 500);
|
|
156
|
+
}, [cleanupIframe, initIframe, retryCount, settings, widgets, restProps]);
|
|
157
|
+
useEffect(function () {
|
|
158
|
+
initIframe();
|
|
159
|
+
window.addEventListener('message', handleMessage);
|
|
160
|
+
return function () {
|
|
161
|
+
window.removeEventListener('message', handleMessage);
|
|
162
|
+
cleanupIframe();
|
|
163
|
+
};
|
|
164
|
+
}, [initIframe, handleMessage, cleanupIframe]);
|
|
187
165
|
return /*#__PURE__*/React.createElement(React.Fragment, null, loading && /*#__PURE__*/React.createElement("div", {
|
|
188
166
|
style: {
|
|
189
167
|
position: 'absolute',
|
package/lib/main.js
CHANGED
|
@@ -24,82 +24,64 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
24
24
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
25
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; }
|
|
26
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; }
|
|
27
|
-
var iframe;
|
|
28
|
-
var retryCount = 0;
|
|
29
|
-
var MAX_RETRIES = 3;
|
|
30
27
|
var Design = function Design(props, ref) {
|
|
31
28
|
var widgets = props.widgets,
|
|
32
29
|
settings = props.settings,
|
|
33
30
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
34
31
|
var containerRef = (0, _react.useRef)(null);
|
|
32
|
+
var iframeRef;
|
|
35
33
|
var _useState = (0, _react.useState)(true),
|
|
36
34
|
_useState2 = _slicedToArray(_useState, 2),
|
|
37
35
|
loading = _useState2[0],
|
|
38
36
|
setLoading = _useState2[1];
|
|
39
|
-
var _useState3 = (0, _react.useState)(
|
|
37
|
+
var _useState3 = (0, _react.useState)(0),
|
|
40
38
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
retryCount = _useState4[0],
|
|
40
|
+
setRetryCount = _useState4[1];
|
|
41
|
+
var MAX_RETRIES = 3;
|
|
43
42
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
44
43
|
return {
|
|
45
44
|
getValue: function getValue() {
|
|
46
|
-
var
|
|
47
|
-
return (
|
|
45
|
+
var _iframeRef$current, _iframeRef$current$co, _iframeRef$current$co2, _iframeRef$current$co3;
|
|
46
|
+
return (_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : (_iframeRef$current$co = _iframeRef$current.contentWindow) === null || _iframeRef$current$co === void 0 ? void 0 : (_iframeRef$current$co2 = _iframeRef$current$co.__FR_ENGINE__) === null || _iframeRef$current$co2 === void 0 ? void 0 : (_iframeRef$current$co3 = _iframeRef$current$co2.exportSchema) === null || _iframeRef$current$co3 === void 0 ? void 0 : _iframeRef$current$co3.call(_iframeRef$current$co2);
|
|
48
47
|
},
|
|
49
48
|
setValue: function setValue(schema) {
|
|
50
|
-
var
|
|
51
|
-
return (
|
|
49
|
+
var _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2, _iframeRef$current2$c3;
|
|
50
|
+
return (_iframeRef$current2 = iframeRef.current) === null || _iframeRef$current2 === void 0 ? void 0 : (_iframeRef$current2$c = _iframeRef$current2.contentWindow) === null || _iframeRef$current2$c === void 0 ? void 0 : (_iframeRef$current2$c2 = _iframeRef$current2$c.__FR_ENGINE__) === null || _iframeRef$current2$c2 === void 0 ? void 0 : (_iframeRef$current2$c3 = _iframeRef$current2$c2.importSchema) === null || _iframeRef$current2$c3 === void 0 ? void 0 : _iframeRef$current2$c3.call(_iframeRef$current2$c2, schema);
|
|
52
51
|
},
|
|
53
52
|
reload: function reload() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
retryCount = 0;
|
|
58
|
-
initIframe();
|
|
59
|
-
}
|
|
53
|
+
setRetryCount(0);
|
|
54
|
+
cleanupIframe();
|
|
55
|
+
initIframe();
|
|
60
56
|
}
|
|
61
57
|
};
|
|
62
58
|
});
|
|
63
|
-
(0, _react.
|
|
64
|
-
|
|
65
|
-
return function () {
|
|
66
|
-
setIsMounted(false);
|
|
67
|
-
};
|
|
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) {
|
|
59
|
+
var cleanupIframe = (0, _react.useCallback)(function () {
|
|
60
|
+
if (iframeRef.current && containerRef.current) {
|
|
81
61
|
try {
|
|
82
|
-
containerRef.current.removeChild(
|
|
62
|
+
containerRef.current.removeChild(iframeRef.current);
|
|
83
63
|
} catch (e) {
|
|
84
|
-
//
|
|
64
|
+
// 忽略错误
|
|
85
65
|
}
|
|
86
|
-
|
|
66
|
+
iframeRef.current = null;
|
|
87
67
|
}
|
|
88
|
-
};
|
|
89
|
-
var initIframe = function
|
|
68
|
+
}, []);
|
|
69
|
+
var initIframe = (0, _react.useCallback)(function () {
|
|
90
70
|
console.log('[SchemaBuilder] Initializing iframe, retry:', retryCount);
|
|
91
71
|
|
|
72
|
+
// 清理旧的 iframe
|
|
73
|
+
cleanupIframe();
|
|
74
|
+
|
|
92
75
|
// 确保容器存在
|
|
93
76
|
if (!containerRef.current) {
|
|
94
|
-
console.error('[SchemaBuilder] Container ref is null');
|
|
77
|
+
console.error('[SchemaBuilder] Container ref is null, delaying iframe creation');
|
|
78
|
+
setTimeout(initIframe, 100);
|
|
95
79
|
return;
|
|
96
80
|
}
|
|
97
81
|
|
|
98
|
-
// 清理旧的 iframe
|
|
99
|
-
cleanupIframe();
|
|
100
|
-
|
|
101
82
|
// 创建新的 iframe
|
|
102
|
-
iframe = (0, _createIframe.default)();
|
|
83
|
+
var iframe = (0, _createIframe.default)();
|
|
84
|
+
iframeRef.current = iframe;
|
|
103
85
|
|
|
104
86
|
// 添加错误处理
|
|
105
87
|
iframe.onerror = function (e) {
|
|
@@ -110,88 +92,84 @@ var Design = function Design(props, ref) {
|
|
|
110
92
|
setLoading(false);
|
|
111
93
|
};
|
|
112
94
|
|
|
113
|
-
//
|
|
114
|
-
|
|
95
|
+
// 添加到容器
|
|
96
|
+
try {
|
|
115
97
|
containerRef.current.appendChild(iframe);
|
|
116
|
-
}
|
|
117
|
-
console.error('[SchemaBuilder]
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error('[SchemaBuilder] Failed to append iframe:', error);
|
|
100
|
+
if (retryCount < MAX_RETRIES) {
|
|
101
|
+
setRetryCount(function (prev) {
|
|
102
|
+
return prev + 1;
|
|
103
|
+
});
|
|
104
|
+
setTimeout(initIframe, 1000);
|
|
105
|
+
}
|
|
118
106
|
return;
|
|
119
107
|
}
|
|
120
108
|
|
|
121
|
-
//
|
|
109
|
+
// 设置超时检查
|
|
122
110
|
var timeoutId = setTimeout(function () {
|
|
123
111
|
if (iframe && (!iframe.contentWindow || !iframe.contentDocument)) {
|
|
124
|
-
console.warn('[SchemaBuilder] Iframe load timeout
|
|
125
|
-
|
|
112
|
+
console.warn('[SchemaBuilder] Iframe load timeout');
|
|
113
|
+
if (retryCount < MAX_RETRIES) {
|
|
114
|
+
setRetryCount(function (prev) {
|
|
115
|
+
return prev + 1;
|
|
116
|
+
});
|
|
117
|
+
cleanupIframe();
|
|
118
|
+
initIframe();
|
|
119
|
+
}
|
|
126
120
|
}
|
|
127
121
|
}, 10000);
|
|
128
|
-
|
|
129
|
-
// 保存 timeoutId 以便清理
|
|
130
122
|
return function () {
|
|
131
123
|
return clearTimeout(timeoutId);
|
|
132
124
|
};
|
|
133
|
-
};
|
|
134
|
-
var
|
|
135
|
-
if (
|
|
136
|
-
console.log('[SchemaBuilder] Component unmounted, skipping retry');
|
|
125
|
+
}, [cleanupIframe, retryCount]);
|
|
126
|
+
var handleMessage = (0, _react.useCallback)(function (event) {
|
|
127
|
+
if (event.data.type !== 'engine-load') {
|
|
137
128
|
return;
|
|
138
129
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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();
|
|
130
|
+
console.log('[SchemaBuilder] Engine loaded');
|
|
131
|
+
setTimeout(function () {
|
|
132
|
+
try {
|
|
133
|
+
var _iframeRef$current3, _iframeRef$current3$c;
|
|
134
|
+
if ((_iframeRef$current3 = iframeRef.current) === null || _iframeRef$current3 === void 0 ? void 0 : (_iframeRef$current3$c = _iframeRef$current3.contentWindow) === null || _iframeRef$current3$c === void 0 ? void 0 : _iframeRef$current3$c.__FR_ENGINE__) {
|
|
135
|
+
iframeRef.current.contentWindow.__FR_ENGINE__.init(_objectSpread({
|
|
136
|
+
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
137
|
+
widgets: widgets,
|
|
138
|
+
logo: {
|
|
139
|
+
title: 'XRender'
|
|
179
140
|
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
141
|
+
}, restProps));
|
|
142
|
+
console.log('[SchemaBuilder] Engine initialized successfully');
|
|
143
|
+
} else {
|
|
144
|
+
console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe');
|
|
145
|
+
if (retryCount < MAX_RETRIES) {
|
|
146
|
+
setRetryCount(function (prev) {
|
|
147
|
+
return prev + 1;
|
|
148
|
+
});
|
|
149
|
+
cleanupIframe();
|
|
150
|
+
initIframe();
|
|
183
151
|
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
152
|
+
}
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error('[SchemaBuilder] Error initializing engine:', error);
|
|
155
|
+
if (retryCount < MAX_RETRIES) {
|
|
156
|
+
setRetryCount(function (prev) {
|
|
157
|
+
return prev + 1;
|
|
158
|
+
});
|
|
159
|
+
cleanupIframe();
|
|
160
|
+
initIframe();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}, 500);
|
|
164
|
+
}, [cleanupIframe, initIframe, retryCount, settings, widgets, restProps]);
|
|
165
|
+
(0, _react.useEffect)(function () {
|
|
166
|
+
initIframe();
|
|
167
|
+
window.addEventListener('message', handleMessage);
|
|
168
|
+
return function () {
|
|
169
|
+
window.removeEventListener('message', handleMessage);
|
|
170
|
+
cleanupIframe();
|
|
171
|
+
};
|
|
172
|
+
}, [initIframe, handleMessage, cleanupIframe]);
|
|
195
173
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, loading && /*#__PURE__*/_react.default.createElement("div", {
|
|
196
174
|
style: {
|
|
197
175
|
position: 'absolute',
|