@zzdadelu/schema-builder 1.0.0-alpha.52 → 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.
Files changed (3) hide show
  1. package/es/main.js +105 -88
  2. package/lib/main.js +104 -87
  3. package/package.json +1 -1
package/es/main.js CHANGED
@@ -13,68 +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
- var containerRef = useRef();
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];
29
+ var _useState3 = useState(0),
30
+ _useState4 = _slicedToArray(_useState3, 2),
31
+ retryCount = _useState4[0],
32
+ setRetryCount = _useState4[1];
33
+ var MAX_RETRIES = 3;
31
34
  useImperativeHandle(ref, function () {
32
35
  return {
33
36
  getValue: function getValue() {
34
- var _iframe, _iframe$contentWindow, _iframe$contentWindow2, _iframe$contentWindow3;
35
- 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);
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);
36
39
  },
37
40
  setValue: function setValue(schema) {
38
- var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
39
- 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);
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);
40
43
  },
41
44
  reload: function reload() {
42
- if (containerRef.current && iframe) {
43
- containerRef.current.removeChild(iframe);
44
- iframe = null;
45
- retryCount = 0;
46
- initIframe();
47
- }
45
+ setRetryCount(0);
46
+ cleanupIframe();
47
+ initIframe();
48
48
  }
49
49
  };
50
50
  });
51
- useEffect(function () {
52
- initIframe();
53
- var messageHandler = handleMessage;
54
- window.addEventListener('message', messageHandler);
55
- return function () {
56
- window.removeEventListener('message', messageHandler);
57
- if (iframe && containerRef.current) {
58
- try {
59
- containerRef.current.removeChild(iframe);
60
- } catch (e) {}
61
- iframe = null;
51
+ var cleanupIframe = useCallback(function () {
52
+ if (iframeRef.current && containerRef.current) {
53
+ try {
54
+ containerRef.current.removeChild(iframeRef.current);
55
+ } catch (e) {
56
+ // 忽略错误
62
57
  }
63
- };
58
+ iframeRef.current = null;
59
+ }
64
60
  }, []);
65
- var initIframe = function initIframe() {
61
+ var initIframe = useCallback(function () {
66
62
  console.log('[SchemaBuilder] Initializing iframe, retry:', retryCount);
67
63
 
68
64
  // 清理旧的 iframe
69
- if (containerRef.current && iframe) {
70
- try {
71
- containerRef.current.removeChild(iframe);
72
- } catch (e) {}
73
- iframe = null;
65
+ cleanupIframe();
66
+
67
+ // 确保容器存在
68
+ if (!containerRef.current) {
69
+ console.error('[SchemaBuilder] Container ref is null, delaying iframe creation');
70
+ setTimeout(initIframe, 100);
71
+ return;
74
72
  }
75
73
 
76
74
  // 创建新的 iframe
77
- iframe = createIframe();
75
+ var iframe = createIframe();
76
+ iframeRef.current = iframe;
78
77
 
79
78
  // 添加错误处理
80
79
  iframe.onerror = function (e) {
@@ -84,67 +83,85 @@ var Design = function Design(props, ref) {
84
83
  console.log('[SchemaBuilder] Iframe loaded');
85
84
  setLoading(false);
86
85
  };
87
- containerRef.current.appendChild(iframe);
88
86
 
89
- // 设置超时重试
90
- setTimeout(function () {
87
+ // 添加到容器
88
+ try {
89
+ containerRef.current.appendChild(iframe);
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
+ }
98
+ return;
99
+ }
100
+
101
+ // 设置超时检查
102
+ var timeoutId = setTimeout(function () {
91
103
  if (iframe && (!iframe.contentWindow || !iframe.contentDocument)) {
92
- console.warn('[SchemaBuilder] Iframe load timeout, retrying...');
93
- retryIframe();
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
+ }
94
112
  }
95
113
  }, 10000);
96
- };
97
- var retryIframe = function retryIframe() {
98
- if (retryCount < MAX_RETRIES) {
99
- retryCount++;
100
- console.warn("[SchemaBuilder] Retrying iframe creation (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
101
- initIframe();
102
- } else {
103
- console.error('[SchemaBuilder] Max retries reached');
114
+ return function () {
115
+ return clearTimeout(timeoutId);
116
+ };
117
+ }, [cleanupIframe, retryCount]);
118
+ var handleMessage = useCallback(function (event) {
119
+ if (event.data.type !== 'engine-load') {
120
+ return;
104
121
  }
105
- };
106
- var handleMessage = function handleMessage(event) {
107
- // 处理来自 iframe 的各种消息
108
- switch (event.data.type) {
109
- case 'getFormRenderMaterial-ready':
110
- console.log('[SchemaBuilder] getFormRenderMaterial is ready in iframe');
111
- break;
112
- case 'engine-load':
113
- console.log('[SchemaBuilder] Engine loaded, checks:', event.data.checks);
114
- if (event.data.checks && !event.data.checks.getFormRenderMaterial) {
115
- console.error('[SchemaBuilder] getFormRenderMaterial check failed, retrying...');
116
- setTimeout(retryIframe, 500);
117
- return;
118
- }
119
-
120
- // 延迟初始化以确保所有资源就绪
121
- setTimeout(function () {
122
- try {
123
- var _iframe3, _iframe3$contentWindo;
124
- if ((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : _iframe3$contentWindo.__FR_ENGINE__) {
125
- iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
126
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
127
- widgets: widgets,
128
- logo: {
129
- title: 'XRender'
130
- }
131
- }, restProps));
132
- console.log('[SchemaBuilder] Engine initialized successfully');
133
- } else {
134
- console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe');
135
- 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'
136
132
  }
137
- } catch (error) {
138
- console.error('[SchemaBuilder] Error initializing engine:', error);
139
- retryIframe();
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();
140
143
  }
141
- }, 500);
142
- break;
143
- default:
144
- // 其他消息可以忽略
145
- break;
146
- }
147
- };
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]);
148
165
  return /*#__PURE__*/React.createElement(React.Fragment, null, loading && /*#__PURE__*/React.createElement("div", {
149
166
  style: {
150
167
  position: 'absolute',
package/lib/main.js CHANGED
@@ -24,65 +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
- var containerRef = (0, _react.useRef)();
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];
37
+ var _useState3 = (0, _react.useState)(0),
38
+ _useState4 = _slicedToArray(_useState3, 2),
39
+ retryCount = _useState4[0],
40
+ setRetryCount = _useState4[1];
41
+ var MAX_RETRIES = 3;
39
42
  (0, _react.useImperativeHandle)(ref, function () {
40
43
  return {
41
44
  getValue: function getValue() {
42
- var _iframe, _iframe$contentWindow, _iframe$contentWindow2, _iframe$contentWindow3;
43
- 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);
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);
44
47
  },
45
48
  setValue: function setValue(schema) {
46
- var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
47
- 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);
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);
48
51
  },
49
52
  reload: function reload() {
50
- if (containerRef.current && iframe) {
51
- containerRef.current.removeChild(iframe);
52
- iframe = null;
53
- retryCount = 0;
54
- initIframe();
55
- }
53
+ setRetryCount(0);
54
+ cleanupIframe();
55
+ initIframe();
56
56
  }
57
57
  };
58
58
  });
59
- (0, _react.useEffect)(function () {
60
- initIframe();
61
- var messageHandler = handleMessage;
62
- window.addEventListener('message', messageHandler);
63
- return function () {
64
- window.removeEventListener('message', messageHandler);
65
- if (iframe && containerRef.current) {
66
- try {
67
- containerRef.current.removeChild(iframe);
68
- } catch (e) {}
69
- iframe = null;
59
+ var cleanupIframe = (0, _react.useCallback)(function () {
60
+ if (iframeRef.current && containerRef.current) {
61
+ try {
62
+ containerRef.current.removeChild(iframeRef.current);
63
+ } catch (e) {
64
+ // 忽略错误
70
65
  }
71
- };
66
+ iframeRef.current = null;
67
+ }
72
68
  }, []);
73
- var initIframe = function initIframe() {
69
+ var initIframe = (0, _react.useCallback)(function () {
74
70
  console.log('[SchemaBuilder] Initializing iframe, retry:', retryCount);
75
71
 
76
72
  // 清理旧的 iframe
77
- if (containerRef.current && iframe) {
78
- try {
79
- containerRef.current.removeChild(iframe);
80
- } catch (e) {}
81
- iframe = null;
73
+ cleanupIframe();
74
+
75
+ // 确保容器存在
76
+ if (!containerRef.current) {
77
+ console.error('[SchemaBuilder] Container ref is null, delaying iframe creation');
78
+ setTimeout(initIframe, 100);
79
+ return;
82
80
  }
83
81
 
84
82
  // 创建新的 iframe
85
- iframe = (0, _createIframe.default)();
83
+ var iframe = (0, _createIframe.default)();
84
+ iframeRef.current = iframe;
86
85
 
87
86
  // 添加错误处理
88
87
  iframe.onerror = function (e) {
@@ -92,67 +91,85 @@ var Design = function Design(props, ref) {
92
91
  console.log('[SchemaBuilder] Iframe loaded');
93
92
  setLoading(false);
94
93
  };
95
- containerRef.current.appendChild(iframe);
96
94
 
97
- // 设置超时重试
98
- setTimeout(function () {
95
+ // 添加到容器
96
+ try {
97
+ containerRef.current.appendChild(iframe);
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
+ }
106
+ return;
107
+ }
108
+
109
+ // 设置超时检查
110
+ var timeoutId = setTimeout(function () {
99
111
  if (iframe && (!iframe.contentWindow || !iframe.contentDocument)) {
100
- console.warn('[SchemaBuilder] Iframe load timeout, retrying...');
101
- retryIframe();
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
+ }
102
120
  }
103
121
  }, 10000);
104
- };
105
- var retryIframe = function retryIframe() {
106
- if (retryCount < MAX_RETRIES) {
107
- retryCount++;
108
- console.warn("[SchemaBuilder] Retrying iframe creation (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
109
- initIframe();
110
- } else {
111
- console.error('[SchemaBuilder] Max retries reached');
122
+ return function () {
123
+ return clearTimeout(timeoutId);
124
+ };
125
+ }, [cleanupIframe, retryCount]);
126
+ var handleMessage = (0, _react.useCallback)(function (event) {
127
+ if (event.data.type !== 'engine-load') {
128
+ return;
112
129
  }
113
- };
114
- var handleMessage = function handleMessage(event) {
115
- // 处理来自 iframe 的各种消息
116
- switch (event.data.type) {
117
- case 'getFormRenderMaterial-ready':
118
- console.log('[SchemaBuilder] getFormRenderMaterial is ready in iframe');
119
- break;
120
- case 'engine-load':
121
- console.log('[SchemaBuilder] Engine loaded, checks:', event.data.checks);
122
- if (event.data.checks && !event.data.checks.getFormRenderMaterial) {
123
- console.error('[SchemaBuilder] getFormRenderMaterial check failed, retrying...');
124
- setTimeout(retryIframe, 500);
125
- return;
126
- }
127
-
128
- // 延迟初始化以确保所有资源就绪
129
- setTimeout(function () {
130
- try {
131
- var _iframe3, _iframe3$contentWindo;
132
- if ((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : _iframe3$contentWindo.__FR_ENGINE__) {
133
- iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
134
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
135
- widgets: widgets,
136
- logo: {
137
- title: 'XRender'
138
- }
139
- }, restProps));
140
- console.log('[SchemaBuilder] Engine initialized successfully');
141
- } else {
142
- console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe');
143
- 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'
144
140
  }
145
- } catch (error) {
146
- console.error('[SchemaBuilder] Error initializing engine:', error);
147
- retryIframe();
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();
148
151
  }
149
- }, 500);
150
- break;
151
- default:
152
- // 其他消息可以忽略
153
- break;
154
- }
155
- };
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]);
156
173
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, loading && /*#__PURE__*/_react.default.createElement("div", {
157
174
  style: {
158
175
  position: 'absolute',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.52",
3
+ "version": "1.0.0-alpha.54",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",