@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.
Files changed (3) hide show
  1. package/es/main.js +90 -112
  2. package/lib/main.js +89 -111
  3. 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(false),
29
+ var _useState3 = useState(0),
32
30
  _useState4 = _slicedToArray(_useState3, 2),
33
- isMounted = _useState4[0],
34
- setIsMounted = _useState4[1];
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 _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);
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 _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);
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
- if (containerRef.current && iframe) {
47
- containerRef.current.removeChild(iframe);
48
- iframe = null;
49
- retryCount = 0;
50
- initIframe();
51
- }
45
+ setRetryCount(0);
46
+ cleanupIframe();
47
+ initIframe();
52
48
  }
53
49
  };
54
50
  });
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) {
51
+ var cleanupIframe = useCallback(function () {
52
+ if (iframeRef.current && containerRef.current) {
73
53
  try {
74
- containerRef.current.removeChild(iframe);
54
+ containerRef.current.removeChild(iframeRef.current);
75
55
  } catch (e) {
76
- // 忽略移除错误
56
+ // 忽略错误
77
57
  }
78
- iframe = null;
58
+ iframeRef.current = null;
79
59
  }
80
- };
81
- var initIframe = function initIframe() {
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
- // 确保容器存在再添加 iframe
106
- if (containerRef.current) {
87
+ // 添加到容器
88
+ try {
107
89
  containerRef.current.appendChild(iframe);
108
- } else {
109
- console.error('[SchemaBuilder] Cannot append iframe, container is null');
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, retrying...');
117
- 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
+ }
118
112
  }
119
113
  }, 10000);
120
-
121
- // 保存 timeoutId 以便清理
122
114
  return function () {
123
115
  return clearTimeout(timeoutId);
124
116
  };
125
- };
126
- var retryIframe = function retryIframe() {
127
- if (!isMounted || !containerRef.current) {
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
- if (retryCount < MAX_RETRIES) {
132
- retryCount++;
133
- console.warn("[SchemaBuilder] Retrying iframe creation (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
134
- initIframe();
135
- } else {
136
- console.error('[SchemaBuilder] Max retries reached');
137
- }
138
- };
139
- var handleMessage = function handleMessage(event) {
140
- // 处理来自 iframe 的各种消息
141
- switch (event.data.type) {
142
- case 'getFormRenderMaterial-ready':
143
- console.log('[SchemaBuilder] getFormRenderMaterial is ready in iframe');
144
- break;
145
- case 'engine-load':
146
- console.log('[SchemaBuilder] Engine loaded, checks:', event.data.checks);
147
- if (event.data.checks && !event.data.checks.getFormRenderMaterial) {
148
- console.error('[SchemaBuilder] getFormRenderMaterial check failed, retrying...');
149
- setTimeout(function () {
150
- if (isMounted) retryIframe();
151
- }, 500);
152
- return;
153
- }
154
-
155
- // 延迟初始化以确保所有资源就绪
156
- var initTimeout = setTimeout(function () {
157
- try {
158
- var _iframe3, _iframe3$contentWindo;
159
- if ((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : _iframe3$contentWindo.__FR_ENGINE__) {
160
- iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
161
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
162
- widgets: widgets,
163
- logo: {
164
- title: 'XRender'
165
- }
166
- }, restProps));
167
- console.log('[SchemaBuilder] Engine initialized successfully');
168
- } else {
169
- console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe');
170
- if (isMounted) retryIframe();
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
- } catch (error) {
173
- console.error('[SchemaBuilder] Error initializing engine:', error);
174
- if (isMounted) 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();
175
143
  }
176
- }, 500);
177
-
178
- // 清理 timeout
179
- return function () {
180
- return clearTimeout(initTimeout);
181
- };
182
- default:
183
- // 其他消息可以忽略
184
- break;
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)(false),
37
+ var _useState3 = (0, _react.useState)(0),
40
38
  _useState4 = _slicedToArray(_useState3, 2),
41
- isMounted = _useState4[0],
42
- setIsMounted = _useState4[1];
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 _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);
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 _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);
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
- if (containerRef.current && iframe) {
55
- containerRef.current.removeChild(iframe);
56
- iframe = null;
57
- retryCount = 0;
58
- initIframe();
59
- }
53
+ setRetryCount(0);
54
+ cleanupIframe();
55
+ initIframe();
60
56
  }
61
57
  };
62
58
  });
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) {
59
+ var cleanupIframe = (0, _react.useCallback)(function () {
60
+ if (iframeRef.current && containerRef.current) {
81
61
  try {
82
- containerRef.current.removeChild(iframe);
62
+ containerRef.current.removeChild(iframeRef.current);
83
63
  } catch (e) {
84
- // 忽略移除错误
64
+ // 忽略错误
85
65
  }
86
- iframe = null;
66
+ iframeRef.current = null;
87
67
  }
88
- };
89
- var initIframe = function initIframe() {
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
- // 确保容器存在再添加 iframe
114
- if (containerRef.current) {
95
+ // 添加到容器
96
+ try {
115
97
  containerRef.current.appendChild(iframe);
116
- } else {
117
- console.error('[SchemaBuilder] Cannot append iframe, container is null');
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, retrying...');
125
- 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
+ }
126
120
  }
127
121
  }, 10000);
128
-
129
- // 保存 timeoutId 以便清理
130
122
  return function () {
131
123
  return clearTimeout(timeoutId);
132
124
  };
133
- };
134
- var retryIframe = function retryIframe() {
135
- if (!isMounted || !containerRef.current) {
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
- if (retryCount < MAX_RETRIES) {
140
- retryCount++;
141
- console.warn("[SchemaBuilder] Retrying iframe creation (".concat(retryCount, "/").concat(MAX_RETRIES, ")"));
142
- initIframe();
143
- } else {
144
- console.error('[SchemaBuilder] Max retries reached');
145
- }
146
- };
147
- var handleMessage = function handleMessage(event) {
148
- // 处理来自 iframe 的各种消息
149
- switch (event.data.type) {
150
- case 'getFormRenderMaterial-ready':
151
- console.log('[SchemaBuilder] getFormRenderMaterial is ready in iframe');
152
- break;
153
- case 'engine-load':
154
- console.log('[SchemaBuilder] Engine loaded, checks:', event.data.checks);
155
- if (event.data.checks && !event.data.checks.getFormRenderMaterial) {
156
- console.error('[SchemaBuilder] getFormRenderMaterial check failed, retrying...');
157
- setTimeout(function () {
158
- if (isMounted) retryIframe();
159
- }, 500);
160
- return;
161
- }
162
-
163
- // 延迟初始化以确保所有资源就绪
164
- var initTimeout = setTimeout(function () {
165
- try {
166
- var _iframe3, _iframe3$contentWindo;
167
- if ((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : (_iframe3$contentWindo = _iframe3.contentWindow) === null || _iframe3$contentWindo === void 0 ? void 0 : _iframe3$contentWindo.__FR_ENGINE__) {
168
- iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
169
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
170
- widgets: widgets,
171
- logo: {
172
- title: 'XRender'
173
- }
174
- }, restProps));
175
- console.log('[SchemaBuilder] Engine initialized successfully');
176
- } else {
177
- console.error('[SchemaBuilder] __FR_ENGINE__ not found in iframe');
178
- if (isMounted) retryIframe();
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
- } catch (error) {
181
- console.error('[SchemaBuilder] Error initializing engine:', error);
182
- if (isMounted) 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();
183
151
  }
184
- }, 500);
185
-
186
- // 清理 timeout
187
- return function () {
188
- return clearTimeout(initTimeout);
189
- };
190
- default:
191
- // 其他消息可以忽略
192
- break;
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',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.53",
3
+ "version": "1.0.0-alpha.54",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",