@zzdadelu/schema-builder 1.0.0-alpha.41 → 1.0.0-alpha.43

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 CHANGED
@@ -5,16 +5,9 @@ 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
- // main.ts
17
- import React, { useEffect, useRef, useImperativeHandle, forwardRef, useState } from 'react';
10
+ import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
18
11
  import createIframe from './createIframe';
19
12
  import * as defaultSetting from './settings';
20
13
  var iframe;
@@ -23,11 +16,6 @@ var Design = function Design(props, ref) {
23
16
  settings = props.settings,
24
17
  restProps = _objectWithoutProperties(props, _excluded);
25
18
  var containerRef = useRef();
26
- var _useState = useState(0),
27
- _useState2 = _slicedToArray(_useState, 2),
28
- retryCount = _useState2[0],
29
- setRetryCount = _useState2[1];
30
- var maxRetries = 3;
31
19
  useImperativeHandle(ref, function () {
32
20
  return {
33
21
  getValue: function getValue() {
@@ -39,191 +27,36 @@ var Design = function Design(props, ref) {
39
27
  setValue: function setValue(schema) {
40
28
  var _iframe4, _iframe4$contentWindo, _iframe4$contentWindo2, _iframe4$contentWindo3;
41
29
  return (_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : (_iframe4$contentWindo = _iframe4.contentWindow) === null || _iframe4$contentWindo === void 0 ? void 0 : (_iframe4$contentWindo2 = _iframe4$contentWindo.__FR_ENGINE__) === null || _iframe4$contentWindo2 === void 0 ? void 0 : (_iframe4$contentWindo3 = _iframe4$contentWindo2.importSchema) === null || _iframe4$contentWindo3 === void 0 ? void 0 : _iframe4$contentWindo3.call(_iframe4$contentWindo2, schema);
42
- },
43
- // 添加检查方法
44
- checkStatus: function checkStatus() {
45
- var _iframe5, _iframe5$contentWindo, _iframe6, _iframe6$contentWindo;
46
- return {
47
- iframeReady: !!iframe,
48
- hasFormRenderMaterial: typeof ((_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : (_iframe5$contentWindo = _iframe5.contentWindow) === null || _iframe5$contentWindo === void 0 ? void 0 : _iframe5$contentWindo.getFormRenderMaterial) === 'function',
49
- hasEngine: !!((_iframe6 = iframe) === null || _iframe6 === void 0 ? void 0 : (_iframe6$contentWindo = _iframe6.contentWindow) === null || _iframe6$contentWindo === void 0 ? void 0 : _iframe6$contentWindo.__FR_ENGINE__)
50
- };
51
30
  }
52
31
  };
53
32
  });
54
33
  useEffect(function () {
55
34
  initIframe();
56
35
  window.addEventListener('message', engineOnLoad);
57
-
58
- // 添加定时检查
59
- var checkInterval = setInterval(checkIframeStatus, 2000);
60
36
  return function () {
61
37
  window.removeEventListener('message', engineOnLoad);
62
- clearInterval(checkInterval);
63
- // 清理iframe
64
- if (iframe && containerRef.current) {
65
- try {
66
- containerRef.current.removeChild(iframe);
67
- } catch (e) {}
68
- iframe = null;
69
- }
70
38
  };
71
39
  }, []);
72
- var checkIframeStatus = function checkIframeStatus() {
73
- if (!iframe) return;
74
- try {
75
- var _iframe$contentWindow, _iframe$contentWindow2;
76
- var hasFunction = typeof ((_iframe$contentWindow = iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : _iframe$contentWindow.getFormRenderMaterial) === 'function';
77
- var hasEngine = !!((_iframe$contentWindow2 = iframe.contentWindow) === null || _iframe$contentWindow2 === void 0 ? void 0 : _iframe$contentWindow2.__FR_ENGINE__);
78
- if (!hasFunction && retryCount < maxRetries) {
79
- console.warn("getFormRenderMaterial not found, retrying... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
80
- setRetryCount(function (prev) {
81
- var newCount = prev + 1;
82
- if (newCount <= maxRetries) {
83
- setTimeout(function () {
84
- return retryIframe();
85
- }, 500);
86
- }
87
- return newCount;
88
- });
89
- }
90
- } catch (e) {
91
- console.error('Error checking iframe status:', e);
92
- }
93
- };
94
40
  var initIframe = function initIframe() {
95
41
  console.log("开始创建 iframe");
96
-
97
- // 清理旧的iframe
98
- if (containerRef.current && iframe) {
99
- try {
100
- containerRef.current.removeChild(iframe);
101
- } catch (e) {}
102
- iframe = null;
103
- }
104
-
105
- // 创建新的iframe
106
42
  iframe = createIframe();
107
-
108
- // 添加加载错误处理
109
- iframe.onerror = function (e) {
110
- console.error('Iframe loading error:', e);
111
- };
112
-
113
- // 添加加载超时处理
114
- var loadTimeout = setTimeout(function () {
115
- if (iframe && (!iframe.contentWindow || !iframe.contentWindow.document)) {
116
- console.error('Iframe load timeout');
117
- retryIframe();
118
- }
119
- }, 10000);
120
- iframe.onload = function () {
121
- clearTimeout(loadTimeout);
122
- console.log("iframe 加载完成");
123
-
124
- // 等待iframe内部脚本执行
125
- setTimeout(function () {
126
- try {
127
- var _iframe$contentWindow3;
128
- // 检查函数是否存在
129
- var hasFunction = typeof ((_iframe$contentWindow3 = iframe.contentWindow) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.getFormRenderMaterial) === 'function';
130
- if (!hasFunction) {
131
- console.warn('getFormRenderMaterial not found after iframe loaded');
132
- }
133
- } catch (e) {
134
- console.error('Error checking function after iframe load:', e);
135
- }
136
- }, 1000);
137
- };
138
43
  containerRef.current.appendChild(iframe);
139
- console.log("iframe 创建完成");
140
- };
141
- var retryIframe = function retryIframe() {
142
- console.log("Retrying iframe creation (attempt ".concat(retryCount + 1, "/").concat(maxRetries, ")"));
143
- initIframe();
44
+ console.log("iframe 创建完成:", containerRef, iframe);
144
45
  };
145
46
  var engineOnLoad = function engineOnLoad(event) {
146
- console.log("收到消息:", event.data);
147
- if (event.data.type === 'xrender-load-error') {
148
- console.error('XRender load error from iframe:', event.data.message);
149
- if (retryCount < maxRetries) {
150
- setTimeout(function () {
151
- return retryIframe();
152
- }, 1000);
153
- }
154
- return;
155
- }
156
- if (event.data.type === 'xrender-fully-loaded') {
157
- console.log('XRender fully loaded, function available:', event.data.available);
158
- if (!event.data.available && retryCount < maxRetries) {
159
- setTimeout(function () {
160
- return retryIframe();
161
- }, 1000);
162
- }
163
- return;
164
- }
47
+ var _iframe5, _iframe5$contentWindo, _iframe5$contentWindo2;
165
48
  if (event.data.type !== 'engine-load') {
166
49
  return;
167
50
  }
168
- console.log("iframe引擎加载事件:", event);
169
-
170
- // 延迟执行以确保函数已定义
171
- setTimeout(function () {
172
- try {
173
- var _iframe7, _iframe7$contentWindo, _iframe9, _iframe9$contentWindo, _iframe9$contentWindo2;
174
- // 再次检查函数是否存在
175
- if (typeof ((_iframe7 = iframe) === null || _iframe7 === void 0 ? void 0 : (_iframe7$contentWindo = _iframe7.contentWindow) === null || _iframe7$contentWindo === void 0 ? void 0 : _iframe7$contentWindo.getFormRenderMaterial) !== 'function') {
176
- console.error('getFormRenderMaterial is not a function when initializing engine');
177
-
178
- // 尝试从其他位置查找函数
179
- var findFunction = function findFunction() {
180
- var _iframe8, _iframeWindow$window, _iframeWindow$parent;
181
- var iframeWindow = (_iframe8 = iframe) === null || _iframe8 === void 0 ? void 0 : _iframe8.contentWindow;
182
- if (!iframeWindow) return null;
183
-
184
- // 尝试多种方式查找
185
- return iframeWindow.getFormRenderMaterial || ((_iframeWindow$window = iframeWindow.window) === null || _iframeWindow$window === void 0 ? void 0 : _iframeWindow$window.getFormRenderMaterial) || ((_iframeWindow$parent = iframeWindow.parent) === null || _iframeWindow$parent === void 0 ? void 0 : _iframeWindow$parent.getFormRenderMaterial) || iframeWindow._xrenderFunctions && iframeWindow._xrenderFunctions.getFormRenderMaterial;
186
- };
187
- var func = findFunction();
188
- if (func && typeof func === 'function') {
189
- console.log('Found getFormRenderMaterial via alternative method');
190
- // 重新赋值
191
- iframe.contentWindow.getFormRenderMaterial = func;
192
- } else if (retryCount < maxRetries) {
193
- console.log('Will retry iframe creation');
194
- setRetryCount(function (prev) {
195
- var newCount = prev + 1;
196
- if (newCount <= maxRetries) {
197
- setTimeout(function () {
198
- return retryIframe();
199
- }, 500);
200
- }
201
- return newCount;
202
- });
203
- return;
204
- }
205
- }
206
-
207
- // 一切正常,初始化引擎
208
- (_iframe9 = iframe) === null || _iframe9 === void 0 ? void 0 : (_iframe9$contentWindo = _iframe9.contentWindow) === null || _iframe9$contentWindo === void 0 ? void 0 : (_iframe9$contentWindo2 = _iframe9$contentWindo.__FR_ENGINE__) === null || _iframe9$contentWindo2 === void 0 ? void 0 : _iframe9$contentWindo2.init(_objectSpread({
209
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
210
- widgets: widgets,
211
- logo: {
212
- title: 'XRender'
213
- }
214
- }, restProps));
215
-
216
- // 重置重试计数
217
- setRetryCount(0);
218
- } catch (error) {
219
- console.error('Error initializing FR_ENGINE:', error);
220
- if (retryCount < maxRetries) {
221
- setTimeout(function () {
222
- return retryIframe();
223
- }, 1000);
224
- }
51
+ console.log("拿到 iframe props:", event);
52
+ (_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : (_iframe5$contentWindo = _iframe5.contentWindow) === null || _iframe5$contentWindo === void 0 ? void 0 : (_iframe5$contentWindo2 = _iframe5$contentWindo.__FR_ENGINE__) === null || _iframe5$contentWindo2 === void 0 ? void 0 : _iframe5$contentWindo2.init(_objectSpread({
53
+ settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
54
+ widgets: widgets,
55
+ // recordEnable: true,
56
+ logo: {
57
+ title: 'XRender'
225
58
  }
226
- }, 100);
59
+ }, restProps));
227
60
  };
228
61
  return /*#__PURE__*/React.createElement("div", {
229
62
  ref: containerRef,
package/lib/main.js CHANGED
@@ -8,7 +8,7 @@ exports.default = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _createIframe = _interopRequireDefault(require("./createIframe"));
10
10
  var defaultSetting = _interopRequireWildcard(require("./settings"));
11
- var _excluded = ["widgets", "settings"]; // main.ts
11
+ var _excluded = ["widgets", "settings"];
12
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
14
14
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -16,12 +16,6 @@ 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;
@@ -30,11 +24,6 @@ var Design = function Design(props, ref) {
30
24
  settings = props.settings,
31
25
  restProps = _objectWithoutProperties(props, _excluded);
32
26
  var containerRef = (0, _react.useRef)();
33
- var _useState = (0, _react.useState)(0),
34
- _useState2 = _slicedToArray(_useState, 2),
35
- retryCount = _useState2[0],
36
- setRetryCount = _useState2[1];
37
- var maxRetries = 3;
38
27
  (0, _react.useImperativeHandle)(ref, function () {
39
28
  return {
40
29
  getValue: function getValue() {
@@ -46,191 +35,36 @@ var Design = function Design(props, ref) {
46
35
  setValue: function setValue(schema) {
47
36
  var _iframe4, _iframe4$contentWindo, _iframe4$contentWindo2, _iframe4$contentWindo3;
48
37
  return (_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : (_iframe4$contentWindo = _iframe4.contentWindow) === null || _iframe4$contentWindo === void 0 ? void 0 : (_iframe4$contentWindo2 = _iframe4$contentWindo.__FR_ENGINE__) === null || _iframe4$contentWindo2 === void 0 ? void 0 : (_iframe4$contentWindo3 = _iframe4$contentWindo2.importSchema) === null || _iframe4$contentWindo3 === void 0 ? void 0 : _iframe4$contentWindo3.call(_iframe4$contentWindo2, schema);
49
- },
50
- // 添加检查方法
51
- checkStatus: function checkStatus() {
52
- var _iframe5, _iframe5$contentWindo, _iframe6, _iframe6$contentWindo;
53
- return {
54
- iframeReady: !!iframe,
55
- hasFormRenderMaterial: typeof ((_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : (_iframe5$contentWindo = _iframe5.contentWindow) === null || _iframe5$contentWindo === void 0 ? void 0 : _iframe5$contentWindo.getFormRenderMaterial) === 'function',
56
- hasEngine: !!((_iframe6 = iframe) === null || _iframe6 === void 0 ? void 0 : (_iframe6$contentWindo = _iframe6.contentWindow) === null || _iframe6$contentWindo === void 0 ? void 0 : _iframe6$contentWindo.__FR_ENGINE__)
57
- };
58
38
  }
59
39
  };
60
40
  });
61
41
  (0, _react.useEffect)(function () {
62
42
  initIframe();
63
43
  window.addEventListener('message', engineOnLoad);
64
-
65
- // 添加定时检查
66
- var checkInterval = setInterval(checkIframeStatus, 2000);
67
44
  return function () {
68
45
  window.removeEventListener('message', engineOnLoad);
69
- clearInterval(checkInterval);
70
- // 清理iframe
71
- if (iframe && containerRef.current) {
72
- try {
73
- containerRef.current.removeChild(iframe);
74
- } catch (e) {}
75
- iframe = null;
76
- }
77
46
  };
78
47
  }, []);
79
- var checkIframeStatus = function checkIframeStatus() {
80
- if (!iframe) return;
81
- try {
82
- var _iframe$contentWindow, _iframe$contentWindow2;
83
- var hasFunction = typeof ((_iframe$contentWindow = iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : _iframe$contentWindow.getFormRenderMaterial) === 'function';
84
- var hasEngine = !!((_iframe$contentWindow2 = iframe.contentWindow) === null || _iframe$contentWindow2 === void 0 ? void 0 : _iframe$contentWindow2.__FR_ENGINE__);
85
- if (!hasFunction && retryCount < maxRetries) {
86
- console.warn("getFormRenderMaterial not found, retrying... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
87
- setRetryCount(function (prev) {
88
- var newCount = prev + 1;
89
- if (newCount <= maxRetries) {
90
- setTimeout(function () {
91
- return retryIframe();
92
- }, 500);
93
- }
94
- return newCount;
95
- });
96
- }
97
- } catch (e) {
98
- console.error('Error checking iframe status:', e);
99
- }
100
- };
101
48
  var initIframe = function initIframe() {
102
49
  console.log("开始创建 iframe");
103
-
104
- // 清理旧的iframe
105
- if (containerRef.current && iframe) {
106
- try {
107
- containerRef.current.removeChild(iframe);
108
- } catch (e) {}
109
- iframe = null;
110
- }
111
-
112
- // 创建新的iframe
113
50
  iframe = (0, _createIframe.default)();
114
-
115
- // 添加加载错误处理
116
- iframe.onerror = function (e) {
117
- console.error('Iframe loading error:', e);
118
- };
119
-
120
- // 添加加载超时处理
121
- var loadTimeout = setTimeout(function () {
122
- if (iframe && (!iframe.contentWindow || !iframe.contentWindow.document)) {
123
- console.error('Iframe load timeout');
124
- retryIframe();
125
- }
126
- }, 10000);
127
- iframe.onload = function () {
128
- clearTimeout(loadTimeout);
129
- console.log("iframe 加载完成");
130
-
131
- // 等待iframe内部脚本执行
132
- setTimeout(function () {
133
- try {
134
- var _iframe$contentWindow3;
135
- // 检查函数是否存在
136
- var hasFunction = typeof ((_iframe$contentWindow3 = iframe.contentWindow) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.getFormRenderMaterial) === 'function';
137
- if (!hasFunction) {
138
- console.warn('getFormRenderMaterial not found after iframe loaded');
139
- }
140
- } catch (e) {
141
- console.error('Error checking function after iframe load:', e);
142
- }
143
- }, 1000);
144
- };
145
51
  containerRef.current.appendChild(iframe);
146
- console.log("iframe 创建完成");
147
- };
148
- var retryIframe = function retryIframe() {
149
- console.log("Retrying iframe creation (attempt ".concat(retryCount + 1, "/").concat(maxRetries, ")"));
150
- initIframe();
52
+ console.log("iframe 创建完成:", containerRef, iframe);
151
53
  };
152
54
  var engineOnLoad = function engineOnLoad(event) {
153
- console.log("收到消息:", event.data);
154
- if (event.data.type === 'xrender-load-error') {
155
- console.error('XRender load error from iframe:', event.data.message);
156
- if (retryCount < maxRetries) {
157
- setTimeout(function () {
158
- return retryIframe();
159
- }, 1000);
160
- }
161
- return;
162
- }
163
- if (event.data.type === 'xrender-fully-loaded') {
164
- console.log('XRender fully loaded, function available:', event.data.available);
165
- if (!event.data.available && retryCount < maxRetries) {
166
- setTimeout(function () {
167
- return retryIframe();
168
- }, 1000);
169
- }
170
- return;
171
- }
55
+ var _iframe5, _iframe5$contentWindo, _iframe5$contentWindo2;
172
56
  if (event.data.type !== 'engine-load') {
173
57
  return;
174
58
  }
175
- console.log("iframe引擎加载事件:", event);
176
-
177
- // 延迟执行以确保函数已定义
178
- setTimeout(function () {
179
- try {
180
- var _iframe7, _iframe7$contentWindo, _iframe9, _iframe9$contentWindo, _iframe9$contentWindo2;
181
- // 再次检查函数是否存在
182
- if (typeof ((_iframe7 = iframe) === null || _iframe7 === void 0 ? void 0 : (_iframe7$contentWindo = _iframe7.contentWindow) === null || _iframe7$contentWindo === void 0 ? void 0 : _iframe7$contentWindo.getFormRenderMaterial) !== 'function') {
183
- console.error('getFormRenderMaterial is not a function when initializing engine');
184
-
185
- // 尝试从其他位置查找函数
186
- var findFunction = function findFunction() {
187
- var _iframe8, _iframeWindow$window, _iframeWindow$parent;
188
- var iframeWindow = (_iframe8 = iframe) === null || _iframe8 === void 0 ? void 0 : _iframe8.contentWindow;
189
- if (!iframeWindow) return null;
190
-
191
- // 尝试多种方式查找
192
- return iframeWindow.getFormRenderMaterial || ((_iframeWindow$window = iframeWindow.window) === null || _iframeWindow$window === void 0 ? void 0 : _iframeWindow$window.getFormRenderMaterial) || ((_iframeWindow$parent = iframeWindow.parent) === null || _iframeWindow$parent === void 0 ? void 0 : _iframeWindow$parent.getFormRenderMaterial) || iframeWindow._xrenderFunctions && iframeWindow._xrenderFunctions.getFormRenderMaterial;
193
- };
194
- var func = findFunction();
195
- if (func && typeof func === 'function') {
196
- console.log('Found getFormRenderMaterial via alternative method');
197
- // 重新赋值
198
- iframe.contentWindow.getFormRenderMaterial = func;
199
- } else if (retryCount < maxRetries) {
200
- console.log('Will retry iframe creation');
201
- setRetryCount(function (prev) {
202
- var newCount = prev + 1;
203
- if (newCount <= maxRetries) {
204
- setTimeout(function () {
205
- return retryIframe();
206
- }, 500);
207
- }
208
- return newCount;
209
- });
210
- return;
211
- }
212
- }
213
-
214
- // 一切正常,初始化引擎
215
- (_iframe9 = iframe) === null || _iframe9 === void 0 ? void 0 : (_iframe9$contentWindo = _iframe9.contentWindow) === null || _iframe9$contentWindo === void 0 ? void 0 : (_iframe9$contentWindo2 = _iframe9$contentWindo.__FR_ENGINE__) === null || _iframe9$contentWindo2 === void 0 ? void 0 : _iframe9$contentWindo2.init(_objectSpread({
216
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
217
- widgets: widgets,
218
- logo: {
219
- title: 'XRender'
220
- }
221
- }, restProps));
222
-
223
- // 重置重试计数
224
- setRetryCount(0);
225
- } catch (error) {
226
- console.error('Error initializing FR_ENGINE:', error);
227
- if (retryCount < maxRetries) {
228
- setTimeout(function () {
229
- return retryIframe();
230
- }, 1000);
231
- }
59
+ console.log("拿到 iframe props:", event);
60
+ (_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : (_iframe5$contentWindo = _iframe5.contentWindow) === null || _iframe5$contentWindo === void 0 ? void 0 : (_iframe5$contentWindo2 = _iframe5$contentWindo.__FR_ENGINE__) === null || _iframe5$contentWindo2 === void 0 ? void 0 : _iframe5$contentWindo2.init(_objectSpread({
61
+ settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
62
+ widgets: widgets,
63
+ // recordEnable: true,
64
+ logo: {
65
+ title: 'XRender'
232
66
  }
233
- }, 100);
67
+ }, restProps));
234
68
  };
235
69
  return /*#__PURE__*/_react.default.createElement("div", {
236
70
  ref: containerRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.41",
3
+ "version": "1.0.0-alpha.43",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",
@@ -1,12 +0,0 @@
1
- var createIframeContent = function createIframeContent() {
2
- var html = "\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" />\n <title>XRender</title>\n <link rel=\"icon\" href=\"https://img.alicdn.com/tfs/TB17UtINiLaK1RjSZFxXXamPFXa-606-643.png\">\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/variables.css\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css\" />\n\n <script>\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js\"></script>\n\n <body>\n <div id=\"lce-container\"></div>\n <script type=\"text/javascript\" src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js\"></script>\n </body>\n </html>\n ";
3
- return html;
4
- };
5
- export default (function () {
6
- var iframe = document.createElement('iframe');
7
- iframe.width = '100%';
8
- iframe.height = '100%';
9
- iframe.frameBorder = '0';
10
- iframe.srcdoc = createIframeContent();
11
- return iframe;
12
- });
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var createIframeContent = function createIframeContent() {
8
- var html = "\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" />\n <title>XRender</title>\n <link rel=\"icon\" href=\"https://img.alicdn.com/tfs/TB17UtINiLaK1RjSZFxXXamPFXa-606-643.png\">\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/variables.css\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css\" />\n\n <script>\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js\"></script>\n\n <body>\n <div id=\"lce-container\"></div>\n <script type=\"text/javascript\" src=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/js/index.js\"></script>\n </body>\n </html>\n ";
9
- return html;
10
- };
11
- var _default = exports.default = function _default() {
12
- var iframe = document.createElement('iframe');
13
- iframe.width = '100%';
14
- iframe.height = '100%';
15
- iframe.frameBorder = '0';
16
- iframe.srcdoc = createIframeContent();
17
- return iframe;
18
- };