@zzdadelu/schema-builder 1.0.0-alpha.56 → 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.
Files changed (3) hide show
  1. package/es/main.js +143 -78
  2. package/lib/main.js +143 -78
  3. package/package.json +1 -1
package/es/main.js CHANGED
@@ -16,132 +16,197 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
16
16
  import React, { useEffect, useRef, useImperativeHandle, forwardRef, useState } 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;
19
22
  var Design = function Design(props, ref) {
20
23
  var widgets = props.widgets,
21
24
  settings = props.settings,
22
25
  restProps = _objectWithoutProperties(props, _excluded);
23
26
  var containerRef = useRef(null);
24
- var iframeRef = useRef(null);
25
27
  var _useState = useState(true),
26
28
  _useState2 = _slicedToArray(_useState, 2),
27
29
  loading = _useState2[0],
28
30
  setLoading = _useState2[1];
29
- var retryCountRef = useRef(0);
30
- var MAX_RETRIES = 3;
31
+ var _useState3 = useState(false),
32
+ _useState4 = _slicedToArray(_useState3, 2),
33
+ isMounted = _useState4[0],
34
+ setIsMounted = _useState4[1];
31
35
  useImperativeHandle(ref, function () {
32
36
  return {
33
37
  getValue: function getValue() {
34
- var _iframeRef$current, _iframeRef$current$co, _iframeRef$current$co2, _iframeRef$current$co3;
35
- 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);
38
+ var _iframe, _iframe$contentWindow, _iframe$contentWindow2, _iframe$contentWindow3;
39
+ return (_iframe = iframe) === null || _iframe === void 0 ? void 0 : (_iframe$contentWindow = _iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : (_iframe$contentWindow2 = _iframe$contentWindow.__FR_ENGINE__) === null || _iframe$contentWindow2 === void 0 ? void 0 : (_iframe$contentWindow3 = _iframe$contentWindow2.exportSchema) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.call(_iframe$contentWindow2);
36
40
  },
37
41
  setValue: function setValue(schema) {
38
- var _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2, _iframeRef$current2$c3;
39
- 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);
42
+ var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
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
+ }
40
52
  }
41
53
  };
42
54
  });
43
- var _initIframe = function initIframe() {
44
- console.log('[SchemaBuilder] Initializing iframe');
55
+ useEffect(function () {
56
+ setIsMounted(true);
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) {
73
+ // try {
74
+ // containerRef.current.removeChild(iframe);
75
+ // } catch (e) {
76
+ // // 忽略移除错误
77
+ // }
78
+ // iframe = null;
79
+ // }
80
+ };
81
+ var initIframe = function initIframe() {
82
+ console.log('[SchemaBuilder] Initializing iframe, retry:', retryCount);
45
83
 
46
84
  // 确保容器存在
47
85
  if (!containerRef.current) {
48
- console.error('[SchemaBuilder] Container not ready');
49
- setTimeout(_initIframe, 100);
86
+ console.error('[SchemaBuilder] Container ref is null');
50
87
  return;
51
88
  }
52
89
 
53
90
  // 清理旧的 iframe
54
- if (iframeRef.current && containerRef.current.contains(iframeRef.current)) {
55
- containerRef.current.removeChild(iframeRef.current);
56
- }
91
+ // cleanupIframe();
57
92
 
58
93
  // 创建新的 iframe
59
- var iframe = createIframe();
60
- iframeRef.current = iframe;
94
+ iframe = createIframe();
95
+
96
+ // 添加错误处理
97
+ iframe.onerror = function (e) {
98
+ console.error('[SchemaBuilder] Iframe error:', e);
99
+ };
61
100
  iframe.onload = function () {
62
101
  console.log('[SchemaBuilder] Iframe loaded');
63
102
  setLoading(false);
64
103
  };
65
- iframe.onerror = function () {
66
- console.error('[SchemaBuilder] Iframe load error');
67
- retryIframe();
68
- };
69
104
 
70
- // 添加到 DOM
71
- containerRef.current.appendChild(iframe);
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
+ };
72
125
  };
73
126
  var retryIframe = function retryIframe() {
74
- if (retryCountRef.current < MAX_RETRIES) {
75
- retryCountRef.current++;
76
- console.log("[SchemaBuilder] Retrying iframe (".concat(retryCountRef.current, "/").concat(MAX_RETRIES, ")"));
77
- setTimeout(_initIframe, 1000);
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();
78
135
  } else {
79
136
  console.error('[SchemaBuilder] Max retries reached');
80
- setLoading(false);
81
137
  }
82
138
  };
83
- var engineOnLoad = function engineOnLoad(event) {
84
- if (event.data.type !== 'engine-load') {
85
- return;
86
- }
87
- console.log('[SchemaBuilder] Engine load event received');
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
+ }
88
154
 
89
- // 延迟执行以确保 iframe 完全加载
90
- setTimeout(function () {
91
- var _iframeRef$current3, _iframeRef$current3$c;
92
- 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__) {
93
- iframeRef.current.contentWindow.__FR_ENGINE__.init(_objectSpread({
94
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
95
- widgets: widgets,
96
- logo: {
97
- title: 'XRender'
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();
98
175
  }
99
- }, restProps));
100
- console.log('[SchemaBuilder] Engine initialized');
101
- } else {
102
- console.error('[SchemaBuilder] Engine not found in iframe');
103
- retryIframe();
104
- }
105
- }, 300);
106
- };
107
- useEffect(function () {
108
- // 等待容器渲染完成
109
- var timer = setTimeout(function () {
110
- _initIframe();
111
- }, 100);
112
- window.addEventListener('message', engineOnLoad);
113
- return function () {
114
- clearTimeout(timer);
115
- window.removeEventListener('message', engineOnLoad);
176
+ }, 500);
116
177
 
117
- // 清理 iframe
118
- if (iframeRef.current && containerRef.current) {
119
- try {
120
- containerRef.current.removeChild(iframeRef.current);
121
- } catch (e) {
122
- // 忽略错误
123
- }
124
- }
125
- };
126
- }, []);
178
+ // 清理 timeout
179
+ return function () {
180
+ return clearTimeout(initTimeout);
181
+ };
182
+ default:
183
+ // 其他消息可以忽略
184
+ break;
185
+ }
186
+ };
127
187
  return /*#__PURE__*/React.createElement(React.Fragment, null, loading && /*#__PURE__*/React.createElement("div", {
128
188
  style: {
129
189
  position: 'absolute',
130
- top: '50%',
131
- left: '50%',
132
- transform: 'translate(-50%, -50%)',
133
- padding: '20px',
134
- backgroundColor: 'rgba(255, 255, 255, 0.9)',
135
- borderRadius: '4px',
136
- boxShadow: '0 2px 8px rgba(0,0,0,0.1)',
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)',
137
198
  zIndex: 10
138
199
  }
139
- }, "\u6B63\u5728\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668..."), /*#__PURE__*/React.createElement("div", {
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", {
140
206
  ref: containerRef,
141
207
  style: {
142
208
  width: '100%',
143
- height: '100%',
144
- minHeight: '500px'
209
+ height: '100%'
145
210
  }
146
211
  }));
147
212
  };
package/lib/main.js CHANGED
@@ -24,132 +24,197 @@ 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;
27
30
  var Design = function Design(props, ref) {
28
31
  var widgets = props.widgets,
29
32
  settings = props.settings,
30
33
  restProps = _objectWithoutProperties(props, _excluded);
31
34
  var containerRef = (0, _react.useRef)(null);
32
- var iframeRef = (0, _react.useRef)(null);
33
35
  var _useState = (0, _react.useState)(true),
34
36
  _useState2 = _slicedToArray(_useState, 2),
35
37
  loading = _useState2[0],
36
38
  setLoading = _useState2[1];
37
- var retryCountRef = (0, _react.useRef)(0);
38
- var MAX_RETRIES = 3;
39
+ var _useState3 = (0, _react.useState)(false),
40
+ _useState4 = _slicedToArray(_useState3, 2),
41
+ isMounted = _useState4[0],
42
+ setIsMounted = _useState4[1];
39
43
  (0, _react.useImperativeHandle)(ref, function () {
40
44
  return {
41
45
  getValue: function getValue() {
42
- var _iframeRef$current, _iframeRef$current$co, _iframeRef$current$co2, _iframeRef$current$co3;
43
- 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);
46
+ var _iframe, _iframe$contentWindow, _iframe$contentWindow2, _iframe$contentWindow3;
47
+ return (_iframe = iframe) === null || _iframe === void 0 ? void 0 : (_iframe$contentWindow = _iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : (_iframe$contentWindow2 = _iframe$contentWindow.__FR_ENGINE__) === null || _iframe$contentWindow2 === void 0 ? void 0 : (_iframe$contentWindow3 = _iframe$contentWindow2.exportSchema) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.call(_iframe$contentWindow2);
44
48
  },
45
49
  setValue: function setValue(schema) {
46
- var _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2, _iframeRef$current2$c3;
47
- 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);
50
+ var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
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
+ }
48
60
  }
49
61
  };
50
62
  });
51
- var _initIframe = function initIframe() {
52
- console.log('[SchemaBuilder] Initializing iframe');
63
+ (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
+ 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
+ };
89
+ var initIframe = function initIframe() {
90
+ console.log('[SchemaBuilder] Initializing iframe, retry:', retryCount);
53
91
 
54
92
  // 确保容器存在
55
93
  if (!containerRef.current) {
56
- console.error('[SchemaBuilder] Container not ready');
57
- setTimeout(_initIframe, 100);
94
+ console.error('[SchemaBuilder] Container ref is null');
58
95
  return;
59
96
  }
60
97
 
61
98
  // 清理旧的 iframe
62
- if (iframeRef.current && containerRef.current.contains(iframeRef.current)) {
63
- containerRef.current.removeChild(iframeRef.current);
64
- }
99
+ // cleanupIframe();
65
100
 
66
101
  // 创建新的 iframe
67
- var iframe = (0, _createIframe.default)();
68
- iframeRef.current = iframe;
102
+ iframe = (0, _createIframe.default)();
103
+
104
+ // 添加错误处理
105
+ iframe.onerror = function (e) {
106
+ console.error('[SchemaBuilder] Iframe error:', e);
107
+ };
69
108
  iframe.onload = function () {
70
109
  console.log('[SchemaBuilder] Iframe loaded');
71
110
  setLoading(false);
72
111
  };
73
- iframe.onerror = function () {
74
- console.error('[SchemaBuilder] Iframe load error');
75
- retryIframe();
76
- };
77
112
 
78
- // 添加到 DOM
79
- containerRef.current.appendChild(iframe);
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
+ };
80
133
  };
81
134
  var retryIframe = function retryIframe() {
82
- if (retryCountRef.current < MAX_RETRIES) {
83
- retryCountRef.current++;
84
- console.log("[SchemaBuilder] Retrying iframe (".concat(retryCountRef.current, "/").concat(MAX_RETRIES, ")"));
85
- setTimeout(_initIframe, 1000);
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();
86
143
  } else {
87
144
  console.error('[SchemaBuilder] Max retries reached');
88
- setLoading(false);
89
145
  }
90
146
  };
91
- var engineOnLoad = function engineOnLoad(event) {
92
- if (event.data.type !== 'engine-load') {
93
- return;
94
- }
95
- console.log('[SchemaBuilder] Engine load event received');
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
+ }
96
162
 
97
- // 延迟执行以确保 iframe 完全加载
98
- setTimeout(function () {
99
- var _iframeRef$current3, _iframeRef$current3$c;
100
- 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__) {
101
- iframeRef.current.contentWindow.__FR_ENGINE__.init(_objectSpread({
102
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
103
- widgets: widgets,
104
- logo: {
105
- title: 'XRender'
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();
106
183
  }
107
- }, restProps));
108
- console.log('[SchemaBuilder] Engine initialized');
109
- } else {
110
- console.error('[SchemaBuilder] Engine not found in iframe');
111
- retryIframe();
112
- }
113
- }, 300);
114
- };
115
- (0, _react.useEffect)(function () {
116
- // 等待容器渲染完成
117
- var timer = setTimeout(function () {
118
- _initIframe();
119
- }, 100);
120
- window.addEventListener('message', engineOnLoad);
121
- return function () {
122
- clearTimeout(timer);
123
- window.removeEventListener('message', engineOnLoad);
184
+ }, 500);
124
185
 
125
- // 清理 iframe
126
- if (iframeRef.current && containerRef.current) {
127
- try {
128
- containerRef.current.removeChild(iframeRef.current);
129
- } catch (e) {
130
- // 忽略错误
131
- }
132
- }
133
- };
134
- }, []);
186
+ // 清理 timeout
187
+ return function () {
188
+ return clearTimeout(initTimeout);
189
+ };
190
+ default:
191
+ // 其他消息可以忽略
192
+ break;
193
+ }
194
+ };
135
195
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, loading && /*#__PURE__*/_react.default.createElement("div", {
136
196
  style: {
137
197
  position: 'absolute',
138
- top: '50%',
139
- left: '50%',
140
- transform: 'translate(-50%, -50%)',
141
- padding: '20px',
142
- backgroundColor: 'rgba(255, 255, 255, 0.9)',
143
- borderRadius: '4px',
144
- boxShadow: '0 2px 8px rgba(0,0,0,0.1)',
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)',
145
206
  zIndex: 10
146
207
  }
147
- }, "\u6B63\u5728\u52A0\u8F7D\u8868\u5355\u8BBE\u8BA1\u5668..."), /*#__PURE__*/_react.default.createElement("div", {
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", {
148
214
  ref: containerRef,
149
215
  style: {
150
216
  width: '100%',
151
- height: '100%',
152
- minHeight: '500px'
217
+ height: '100%'
153
218
  }
154
219
  }));
155
220
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.56",
3
+ "version": "1.0.0-alpha.57",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",