@zzdadelu/schema-builder 1.0.0-alpha.77 → 1.0.0-alpha.79

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 +47 -9
  2. package/lib/main.js +47 -9
  3. package/package.json +1 -1
package/es/main.js CHANGED
@@ -16,6 +16,7 @@ var Design = function Design(props, ref) {
16
16
  settings = props.settings,
17
17
  restProps = _objectWithoutProperties(props, _excluded);
18
18
  var containerRef = useRef();
19
+ var pollingTimerRef = useRef(null);
19
20
  useImperativeHandle(ref, function () {
20
21
  return {
21
22
  getValue: function getValue() {
@@ -29,10 +30,15 @@ var Design = function Design(props, ref) {
29
30
  };
30
31
  });
31
32
  useEffect(function () {
32
- window.addEventListener('message', engineOnLoad);
33
33
  initIframe();
34
+ window.addEventListener('message', engineOnLoad);
34
35
  return function () {
35
36
  window.removeEventListener('message', engineOnLoad);
37
+ // 清除轮询定时器
38
+ if (pollingTimerRef.current) {
39
+ clearInterval(pollingTimerRef.current);
40
+ pollingTimerRef.current = null;
41
+ }
36
42
  };
37
43
  }, []);
38
44
  var initIframe = function initIframe() {
@@ -40,18 +46,50 @@ var Design = function Design(props, ref) {
40
46
  containerRef.current.appendChild(iframe);
41
47
  };
42
48
  var engineOnLoad = function engineOnLoad(event) {
43
- var _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2;
49
+ var _iframe3;
44
50
  if (event.data.type !== 'engine-load') {
45
51
  return;
46
52
  }
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
+ var iframeWindow = (_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow;
54
+ if (!iframeWindow) {
55
+ console.error('iframe window not found');
56
+ return;
57
+ }
58
+
59
+ // 清除之前的轮询定时器
60
+ if (pollingTimerRef.current) {
61
+ clearInterval(pollingTimerRef.current);
62
+ pollingTimerRef.current = null;
63
+ }
64
+
65
+ // 设置轮询,等待 getFormRenderMaterial 方法被注入
66
+ var pollInterval = 50; // 每50毫秒检查一次
67
+ var timeout = 10000; // 10秒后超时
68
+ var elapsed = 0;
69
+ pollingTimerRef.current = setInterval(function () {
70
+ // 检查 getFormRenderMaterial 是否存在
71
+ if (iframeWindow.getFormRenderMaterial) {
72
+ var _iframeWindow$__FR_EN;
73
+ clearInterval(pollingTimerRef.current);
74
+ pollingTimerRef.current = null;
75
+ // 初始化引擎
76
+ (_iframeWindow$__FR_EN = iframeWindow.__FR_ENGINE__) === null || _iframeWindow$__FR_EN === void 0 ? void 0 : _iframeWindow$__FR_EN.init(_objectSpread({
77
+ settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
78
+ widgets: widgets,
79
+ // recordEnable: true,
80
+ logo: {
81
+ title: 'XRender'
82
+ }
83
+ }, restProps));
84
+ } else {
85
+ elapsed += pollInterval;
86
+ if (elapsed >= timeout) {
87
+ clearInterval(pollingTimerRef.current);
88
+ pollingTimerRef.current = null;
89
+ console.error('getFormRenderMaterial not found after 10 seconds');
90
+ }
53
91
  }
54
- }, restProps));
92
+ }, pollInterval);
55
93
  };
56
94
  return /*#__PURE__*/React.createElement("div", {
57
95
  ref: containerRef,
package/lib/main.js CHANGED
@@ -24,6 +24,7 @@ var Design = function Design(props, ref) {
24
24
  settings = props.settings,
25
25
  restProps = _objectWithoutProperties(props, _excluded);
26
26
  var containerRef = (0, _react.useRef)();
27
+ var pollingTimerRef = (0, _react.useRef)(null);
27
28
  (0, _react.useImperativeHandle)(ref, function () {
28
29
  return {
29
30
  getValue: function getValue() {
@@ -37,10 +38,15 @@ var Design = function Design(props, ref) {
37
38
  };
38
39
  });
39
40
  (0, _react.useEffect)(function () {
40
- window.addEventListener('message', engineOnLoad);
41
41
  initIframe();
42
+ window.addEventListener('message', engineOnLoad);
42
43
  return function () {
43
44
  window.removeEventListener('message', engineOnLoad);
45
+ // 清除轮询定时器
46
+ if (pollingTimerRef.current) {
47
+ clearInterval(pollingTimerRef.current);
48
+ pollingTimerRef.current = null;
49
+ }
44
50
  };
45
51
  }, []);
46
52
  var initIframe = function initIframe() {
@@ -48,18 +54,50 @@ var Design = function Design(props, ref) {
48
54
  containerRef.current.appendChild(iframe);
49
55
  };
50
56
  var engineOnLoad = function engineOnLoad(event) {
51
- var _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2;
57
+ var _iframe3;
52
58
  if (event.data.type !== 'engine-load') {
53
59
  return;
54
60
  }
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
+ var iframeWindow = (_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow;
62
+ if (!iframeWindow) {
63
+ console.error('iframe window not found');
64
+ return;
65
+ }
66
+
67
+ // 清除之前的轮询定时器
68
+ if (pollingTimerRef.current) {
69
+ clearInterval(pollingTimerRef.current);
70
+ pollingTimerRef.current = null;
71
+ }
72
+
73
+ // 设置轮询,等待 getFormRenderMaterial 方法被注入
74
+ var pollInterval = 50; // 每50毫秒检查一次
75
+ var timeout = 10000; // 10秒后超时
76
+ var elapsed = 0;
77
+ pollingTimerRef.current = setInterval(function () {
78
+ // 检查 getFormRenderMaterial 是否存在
79
+ if (iframeWindow.getFormRenderMaterial) {
80
+ var _iframeWindow$__FR_EN;
81
+ clearInterval(pollingTimerRef.current);
82
+ pollingTimerRef.current = null;
83
+ // 初始化引擎
84
+ (_iframeWindow$__FR_EN = iframeWindow.__FR_ENGINE__) === null || _iframeWindow$__FR_EN === void 0 ? void 0 : _iframeWindow$__FR_EN.init(_objectSpread({
85
+ settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
86
+ widgets: widgets,
87
+ // recordEnable: true,
88
+ logo: {
89
+ title: 'XRender'
90
+ }
91
+ }, restProps));
92
+ } else {
93
+ elapsed += pollInterval;
94
+ if (elapsed >= timeout) {
95
+ clearInterval(pollingTimerRef.current);
96
+ pollingTimerRef.current = null;
97
+ console.error('getFormRenderMaterial not found after 10 seconds');
98
+ }
61
99
  }
62
- }, restProps));
100
+ }, pollInterval);
63
101
  };
64
102
  return /*#__PURE__*/_react.default.createElement("div", {
65
103
  ref: containerRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.77",
3
+ "version": "1.0.0-alpha.79",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",