@zzdadelu/schema-builder 1.0.0-alpha.53 → 1.0.0-alpha.55
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 +19 -168
- package/lib/main.js +18 -167
- package/package.json +1 -1
package/es/main.js
CHANGED
|
@@ -5,33 +5,17 @@ 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; }
|
|
14
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; }
|
|
15
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; }
|
|
16
|
-
import React, { useEffect, useRef, useImperativeHandle, forwardRef
|
|
10
|
+
import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
|
|
17
11
|
import createIframe from './createIframe';
|
|
18
12
|
import * as defaultSetting from './settings';
|
|
19
13
|
var iframe;
|
|
20
|
-
var retryCount = 0;
|
|
21
|
-
var MAX_RETRIES = 3;
|
|
22
14
|
var Design = function Design(props, ref) {
|
|
23
15
|
var widgets = props.widgets,
|
|
24
16
|
settings = props.settings,
|
|
25
17
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
26
|
-
var containerRef = useRef(
|
|
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];
|
|
18
|
+
var containerRef = useRef();
|
|
35
19
|
useImperativeHandle(ref, function () {
|
|
36
20
|
return {
|
|
37
21
|
getValue: function getValue() {
|
|
@@ -41,173 +25,40 @@ var Design = function Design(props, ref) {
|
|
|
41
25
|
setValue: function setValue(schema) {
|
|
42
26
|
var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
|
|
43
27
|
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
|
-
}
|
|
52
28
|
}
|
|
53
29
|
};
|
|
54
30
|
});
|
|
55
31
|
useEffect(function () {
|
|
56
|
-
setIsMounted(true);
|
|
57
|
-
return function () {
|
|
58
|
-
setIsMounted(false);
|
|
59
|
-
};
|
|
60
|
-
}, []);
|
|
61
|
-
useEffect(function () {
|
|
62
|
-
if (!isMounted || !containerRef.current) return;
|
|
63
32
|
initIframe();
|
|
64
|
-
|
|
65
|
-
window.addEventListener('message', messageHandler);
|
|
33
|
+
window.addEventListener('message', engineOnLoad);
|
|
66
34
|
return function () {
|
|
67
|
-
window.removeEventListener('message',
|
|
68
|
-
cleanupIframe();
|
|
35
|
+
window.removeEventListener('message', engineOnLoad);
|
|
69
36
|
};
|
|
70
|
-
}, [
|
|
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
|
-
};
|
|
37
|
+
}, []);
|
|
81
38
|
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
|
|
94
39
|
iframe = createIframe();
|
|
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');
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// 设置超时重试
|
|
114
|
-
var timeoutId = setTimeout(function () {
|
|
115
|
-
if (iframe && (!iframe.contentWindow || !iframe.contentDocument)) {
|
|
116
|
-
console.warn('[SchemaBuilder] Iframe load timeout, retrying...');
|
|
117
|
-
retryIframe();
|
|
118
|
-
}
|
|
119
|
-
}, 10000);
|
|
120
|
-
|
|
121
|
-
// 保存 timeoutId 以便清理
|
|
122
|
-
return function () {
|
|
123
|
-
return clearTimeout(timeoutId);
|
|
124
|
-
};
|
|
40
|
+
containerRef.current.appendChild(iframe);
|
|
125
41
|
};
|
|
126
|
-
var
|
|
127
|
-
|
|
128
|
-
|
|
42
|
+
var engineOnLoad = function engineOnLoad(event) {
|
|
43
|
+
var _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2;
|
|
44
|
+
if (event.data.type !== 'engine-load') {
|
|
129
45
|
return;
|
|
130
46
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
}
|
|
47
|
+
(_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : (_iframe3$contentWindo2 = _iframe3$contentWindo.__FR_ENGINE__) === null || _iframe3$contentWindo2 === void 0 ? void 0 : _iframe3$contentWindo2.init(_objectSpread({
|
|
48
|
+
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
49
|
+
widgets: widgets,
|
|
50
|
+
// recordEnable: true,
|
|
51
|
+
logo: {
|
|
52
|
+
title: 'XRender'
|
|
53
|
+
}
|
|
54
|
+
}, restProps));
|
|
186
55
|
};
|
|
187
|
-
return /*#__PURE__*/React.createElement(
|
|
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", {
|
|
56
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
206
57
|
ref: containerRef,
|
|
207
58
|
style: {
|
|
208
59
|
width: '100%',
|
|
209
60
|
height: '100%'
|
|
210
61
|
}
|
|
211
|
-
})
|
|
62
|
+
});
|
|
212
63
|
};
|
|
213
64
|
export default /*#__PURE__*/forwardRef(Design);
|
package/lib/main.js
CHANGED
|
@@ -16,30 +16,14 @@ 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; }
|
|
25
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; }
|
|
26
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; }
|
|
27
21
|
var iframe;
|
|
28
|
-
var retryCount = 0;
|
|
29
|
-
var MAX_RETRIES = 3;
|
|
30
22
|
var Design = function Design(props, ref) {
|
|
31
23
|
var widgets = props.widgets,
|
|
32
24
|
settings = props.settings,
|
|
33
25
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
34
|
-
var containerRef = (0, _react.useRef)(
|
|
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];
|
|
26
|
+
var containerRef = (0, _react.useRef)();
|
|
43
27
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
44
28
|
return {
|
|
45
29
|
getValue: function getValue() {
|
|
@@ -49,173 +33,40 @@ var Design = function Design(props, ref) {
|
|
|
49
33
|
setValue: function setValue(schema) {
|
|
50
34
|
var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
|
|
51
35
|
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
|
-
}
|
|
60
36
|
}
|
|
61
37
|
};
|
|
62
38
|
});
|
|
63
39
|
(0, _react.useEffect)(function () {
|
|
64
|
-
setIsMounted(true);
|
|
65
|
-
return function () {
|
|
66
|
-
setIsMounted(false);
|
|
67
|
-
};
|
|
68
|
-
}, []);
|
|
69
|
-
(0, _react.useEffect)(function () {
|
|
70
|
-
if (!isMounted || !containerRef.current) return;
|
|
71
40
|
initIframe();
|
|
72
|
-
|
|
73
|
-
window.addEventListener('message', messageHandler);
|
|
41
|
+
window.addEventListener('message', engineOnLoad);
|
|
74
42
|
return function () {
|
|
75
|
-
window.removeEventListener('message',
|
|
76
|
-
cleanupIframe();
|
|
43
|
+
window.removeEventListener('message', engineOnLoad);
|
|
77
44
|
};
|
|
78
|
-
}, [
|
|
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
|
-
};
|
|
45
|
+
}, []);
|
|
89
46
|
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
|
|
102
47
|
iframe = (0, _createIframe.default)();
|
|
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');
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 设置超时重试
|
|
122
|
-
var timeoutId = setTimeout(function () {
|
|
123
|
-
if (iframe && (!iframe.contentWindow || !iframe.contentDocument)) {
|
|
124
|
-
console.warn('[SchemaBuilder] Iframe load timeout, retrying...');
|
|
125
|
-
retryIframe();
|
|
126
|
-
}
|
|
127
|
-
}, 10000);
|
|
128
|
-
|
|
129
|
-
// 保存 timeoutId 以便清理
|
|
130
|
-
return function () {
|
|
131
|
-
return clearTimeout(timeoutId);
|
|
132
|
-
};
|
|
48
|
+
containerRef.current.appendChild(iframe);
|
|
133
49
|
};
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
|
|
50
|
+
var engineOnLoad = function engineOnLoad(event) {
|
|
51
|
+
var _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2;
|
|
52
|
+
if (event.data.type !== 'engine-load') {
|
|
137
53
|
return;
|
|
138
54
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
}
|
|
55
|
+
(_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : (_iframe3$contentWindo2 = _iframe3$contentWindo.__FR_ENGINE__) === null || _iframe3$contentWindo2 === void 0 ? void 0 : _iframe3$contentWindo2.init(_objectSpread({
|
|
56
|
+
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
57
|
+
widgets: widgets,
|
|
58
|
+
// recordEnable: true,
|
|
59
|
+
logo: {
|
|
60
|
+
title: 'XRender'
|
|
61
|
+
}
|
|
62
|
+
}, restProps));
|
|
194
63
|
};
|
|
195
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
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", {
|
|
64
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
214
65
|
ref: containerRef,
|
|
215
66
|
style: {
|
|
216
67
|
width: '100%',
|
|
217
68
|
height: '100%'
|
|
218
69
|
}
|
|
219
|
-
})
|
|
70
|
+
});
|
|
220
71
|
};
|
|
221
72
|
var _default = exports.default = /*#__PURE__*/(0, _react.forwardRef)(Design);
|