@zzdadelu/schema-builder 1.0.0-alpha.72 → 1.0.0-alpha.74

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.
@@ -1,7 +1,11 @@
1
- // 修改 createIframe.ts
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ 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; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ 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); }
2
7
  var createIframeContent = function createIframeContent() {
3
- var timestamp = new Date().getTime();
4
- 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?t=".concat(timestamp, "\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css?t=").concat(timestamp, "\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css?t=").concat(timestamp, "\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css?t=").concat(timestamp, "\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css?t=").concat(timestamp, "\" />\n\n <script>\n // \u76D1\u542C\u7236\u7A97\u53E3\u7684\u6D88\u606F\n window.addEventListener('message', function(event) {\n // \u786E\u4FDD\u6D88\u606F\u6765\u6E90\u53EF\u4FE1\n if (event.source !== window.parent) return;\n \n if (event.data.type === 'SET_GET_FORM_RENDER_MATERIAL') {\n console.log('Received getFormRenderMaterial from parent');\n \n // \u5C06\u7236\u7A97\u53E3\u4F20\u9012\u7684\u51FD\u6570\u8BBE\u7F6E\u4E3A\u5168\u5C40\u65B9\u6CD5\n window.getFormRenderMaterial = function() {\n console.log('getFormRenderMaterial called (from parent)');\n \n // \u8FD9\u91CC\u53EF\u4EE5\u8C03\u7528\u7236\u7A97\u53E3\u4F20\u9012\u7684\u5B9E\u73B0\uFF0C\u6216\u8005\u4F7F\u7528\u672C\u5730\u5B9E\u73B0\n if (event.data.implementation) {\n try {\n // \u4F7F\u7528\u7236\u7A97\u53E3\u4F20\u9012\u7684\u5B9E\u73B0\n return event.data.implementation.apply(this, arguments);\n } catch(e) {\n console.error('Error calling parent implementation:', e);\n }\n }\n \n // \u540E\u5907\u5B9E\u73B0\n return {};\n };\n \n // \u786E\u8BA4\u8BBE\u7F6E\u5B8C\u6210\n window.parent.postMessage({\n type: 'GET_FORM_RENDER_MATERIAL_SET',\n success: true\n }, '*');\n }\n });\n \n // \u9884\u5B9A\u4E49\u4E00\u4E2A\u5B89\u5168\u7684 getFormRenderMaterial \u51FD\u6570\n window.getFormRenderMaterial = window.getFormRenderMaterial || function() {\n console.warn('getFormRenderMaterial called before initialization');\n return {};\n };\n \n // \u8BBE\u7F6E\u5176\u4ED6\u5FC5\u8981\u7684\u5168\u5C40\u53D8\u91CF\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n window.__is_simulator_env__ = true;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js?t=").concat(timestamp, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js?t=").concat(timestamp, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js?t=").concat(timestamp, "\"></script>\n </head>\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?t=").concat(timestamp, "\"></script>\n </body>\n </html>\n ");
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 </head>\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 ";
5
9
  return html;
6
10
  };
7
11
  export default (function () {
@@ -10,5 +14,89 @@ export default (function () {
10
14
  iframe.height = '100%';
11
15
  iframe.frameBorder = '0';
12
16
  iframe.srcdoc = createIframeContent();
17
+
18
+ // 监听iframe加载完成
19
+ iframe.onload = function () {
20
+ var win = iframe.contentWindow;
21
+ if (!win) return;
22
+
23
+ // 拦截低代码引擎的createSimulator函数
24
+ patchCreateSimulatorInIframe(win);
25
+ };
13
26
  return iframe;
14
- });
27
+ });
28
+
29
+ // 在iframe内部修补createSimulator函数
30
+ function patchCreateSimulatorInIframe(iframeWindow) {
31
+ // 保存原始的createSimulator函数
32
+ var originalCreateSimulator = iframeWindow.createSimulator;
33
+ if (originalCreateSimulator) {
34
+ iframeWindow.createSimulator = function (host, iframe, vendors) {
35
+ // 处理vendors,给JS URL添加时间戳
36
+ var processedVendors = addTimestampToVendors(vendors);
37
+ return originalCreateSimulator.call(this, host, iframe, processedVendors);
38
+ };
39
+ }
40
+
41
+ // 工具函数(同上)
42
+ function addTimestampToVendors(vendors) {
43
+ var timestamp = new Date().getTime();
44
+ return vendors.map(function (vendor) {
45
+ if (!vendor) return vendor;
46
+ if (vendor.type === 'bundle' && Array.isArray(vendor.assets)) {
47
+ return _objectSpread(_objectSpread({}, vendor), {}, {
48
+ assets: vendor.assets.map(function (asset) {
49
+ if (!asset) return asset;
50
+
51
+ // 处理字符串URL
52
+ if (typeof asset === 'string') {
53
+ return addTimestampToUrl(asset, timestamp);
54
+ }
55
+
56
+ // 处理数组(可能是URL数组)
57
+ if (Array.isArray(asset)) {
58
+ return asset.map(function (item) {
59
+ if (typeof item === 'string') {
60
+ return addTimestampToUrl(item, timestamp);
61
+ }
62
+ // 处理数组中的数组(嵌套情况)
63
+ if (Array.isArray(item)) {
64
+ return item.map(function (subItem) {
65
+ if (typeof subItem === 'string') {
66
+ return addTimestampToUrl(subItem, timestamp);
67
+ }
68
+ return subItem;
69
+ });
70
+ }
71
+ return item;
72
+ });
73
+ }
74
+
75
+ // 处理对象类型
76
+ if (_typeof(asset) === 'object') {
77
+ if (asset.type === 'jsText' || asset.type === 'cssText') {
78
+ // 内联脚本,不需要加时间戳
79
+ return asset;
80
+ }
81
+ if (asset.content && typeof asset.content === 'string') {
82
+ return _objectSpread(_objectSpread({}, asset), {}, {
83
+ content: addTimestampToUrl(asset.content, timestamp)
84
+ });
85
+ }
86
+ }
87
+ return asset;
88
+ })
89
+ });
90
+ }
91
+ return vendor;
92
+ });
93
+ }
94
+ function addTimestampToUrl(url, timestamp) {
95
+ if (!url || typeof url !== 'string') return url;
96
+
97
+ // 跳过已经有时间戳的URL
98
+ if (url.includes('t=')) return url;
99
+ var separator = url.includes('?') ? '&' : '?';
100
+ return "".concat(url).concat(separator, "t=").concat(timestamp);
101
+ }
102
+ }
package/es/main.js CHANGED
@@ -7,19 +7,15 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
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
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; }
9
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; }
10
- // 修改 main.ts
11
10
  import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
12
11
  import createIframe from './createIframe';
13
12
  import * as defaultSetting from './settings';
14
- var iframe = null;
13
+ var iframe;
15
14
  var Design = function Design(props, ref) {
16
15
  var widgets = props.widgets,
17
16
  settings = props.settings,
18
17
  restProps = _objectWithoutProperties(props, _excluded);
19
18
  var containerRef = useRef();
20
- var injectionAttemptsRef = useRef(0);
21
- var maxInjectionAttempts = 50; // 最多尝试50次
22
-
23
19
  useImperativeHandle(ref, function () {
24
20
  return {
25
21
  getValue: function getValue() {
@@ -33,138 +29,29 @@ var Design = function Design(props, ref) {
33
29
  };
34
30
  });
35
31
  useEffect(function () {
36
- initIframe();
37
32
  window.addEventListener('message', engineOnLoad);
38
-
39
- // 监听来自 iframe 的消息
40
- window.addEventListener('message', handleIframeMessage);
33
+ initIframe();
41
34
  return function () {
42
35
  window.removeEventListener('message', engineOnLoad);
43
- window.removeEventListener('message', handleIframeMessage);
44
36
  };
45
37
  }, []);
46
38
  var initIframe = function initIframe() {
47
39
  iframe = createIframe();
48
40
  containerRef.current.appendChild(iframe);
49
-
50
- // 监听 iframe 的 load 事件
51
- iframe.onload = function () {
52
- console.log('iframe loaded, injecting getFormRenderMaterial');
53
- injectGetFormRenderMaterial();
54
-
55
- // 启动一个定时器,持续检查并注入
56
- var checkInterval = setInterval(function () {
57
- var _iframe3;
58
- injectionAttemptsRef.current++;
59
- if (injectionAttemptsRef.current > maxInjectionAttempts) {
60
- clearInterval(checkInterval);
61
- console.error("Failed to inject getFormRenderMaterial after ".concat(maxInjectionAttempts, " attempts"));
62
- return;
63
- }
64
- if (((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow) && !isFunctionProperlyInjected()) {
65
- console.log("Attempt ".concat(injectionAttemptsRef.current, ": Injecting getFormRenderMaterial"));
66
- injectGetFormRenderMaterial();
67
- } else if (isFunctionProperlyInjected()) {
68
- clearInterval(checkInterval);
69
- console.log('getFormRenderMaterial successfully injected and verified');
70
- }
71
- }, 100);
72
- };
73
- };
74
- var handleIframeMessage = function handleIframeMessage(event) {
75
- var _iframe4;
76
- // 确保消息来自我们的 iframe
77
- if (event.source !== ((_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : _iframe4.contentWindow)) return;
78
- if (event.data.type === 'GET_FORM_RENDER_MATERIAL_SET') {
79
- console.log('iframe confirmed getFormRenderMaterial was set');
80
- }
81
- };
82
- var injectGetFormRenderMaterial = function injectGetFormRenderMaterial() {
83
- var _iframe5;
84
- if (!((_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : _iframe5.contentWindow)) {
85
- console.error('Cannot inject: iframe or contentWindow not available');
86
- return false;
87
- }
88
- try {
89
- // 方法1:直接注入(可能受同源策略限制)
90
- var iframeWin = iframe.contentWindow;
91
-
92
- // 创建一个函数字符串,然后通过 eval 在 iframe 上下文中执行
93
- var functionString = "\n (function() {\n window.getFormRenderMaterial = function() {\n console.log('getFormRenderMaterial called (injected from parent)');\n return ".concat(JSON.stringify(Object.assign({
94
- __esModule: true
95
- }, widgets || {})), ";\n };\n return true;\n })()\n ");
96
-
97
- // 尝试通过 eval 执行
98
- try {
99
- iframeWin.eval(functionString);
100
- console.log('getFormRenderMaterial injected via eval');
101
- } catch (evalError) {
102
- console.warn('eval failed, trying direct assignment:', evalError);
103
-
104
- // 回退到直接赋值
105
- iframeWin.getFormRenderMaterial = function () {
106
- console.log('getFormRenderMaterial called (direct assignment)');
107
- return Object.assign({
108
- __esModule: true
109
- }, widgets || {});
110
- };
111
- }
112
-
113
- // 方法2:使用 postMessage 发送函数实现
114
- iframeWin.postMessage({
115
- type: 'SET_GET_FORM_RENDER_MATERIAL',
116
- implementation: function implementation() {
117
- return Object.assign({
118
- __esModule: true
119
- }, widgets || {});
120
- }
121
- }, '*');
122
- return true;
123
- } catch (error) {
124
- console.error('Error injecting getFormRenderMaterial:', error);
125
- return false;
126
- }
127
- };
128
- var isFunctionProperlyInjected = function isFunctionProperlyInjected() {
129
- try {
130
- var _iframe6;
131
- var iframeWin = (_iframe6 = iframe) === null || _iframe6 === void 0 ? void 0 : _iframe6.contentWindow;
132
- return iframeWin && typeof iframeWin.getFormRenderMaterial === 'function' && iframeWin.getFormRenderMaterial.toString().includes('getFormRenderMaterial');
133
- } catch (error) {
134
- // 可能由于同源策略无法访问
135
- return false;
136
- }
137
41
  };
138
42
  var engineOnLoad = function engineOnLoad(event) {
139
- var _iframe7;
43
+ var _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2;
140
44
  if (event.data.type !== 'engine-load') {
141
45
  return;
142
46
  }
143
-
144
- // 在初始化前再次确保 getFormRenderMaterial 存在
145
- console.log('Engine loading, verifying getFormRenderMaterial');
146
-
147
- // 尝试通过 postMessage 与 iframe 通信来验证
148
- if ((_iframe7 = iframe) === null || _iframe7 === void 0 ? void 0 : _iframe7.contentWindow) {
149
- iframe.contentWindow.postMessage({
150
- type: 'VERIFY_GET_FORM_RENDER_MATERIAL'
151
- }, '*');
152
-
153
- // 设置一个超时,以防验证失败
154
- setTimeout(function () {
155
- var _iframe8, _iframe8$contentWindo;
156
- if ((_iframe8 = iframe) === null || _iframe8 === void 0 ? void 0 : (_iframe8$contentWindo = _iframe8.contentWindow) === null || _iframe8$contentWindo === void 0 ? void 0 : _iframe8$contentWindo.__FR_ENGINE__) {
157
- console.log('Initializing FR_ENGINE');
158
- iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
159
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
160
- widgets: widgets,
161
- logo: {
162
- title: 'XRender'
163
- }
164
- }, restProps));
165
- }
166
- }, 500);
167
- }
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
+ }
54
+ }, restProps));
168
55
  };
169
56
  return /*#__PURE__*/React.createElement("div", {
170
57
  ref: containerRef,
@@ -4,10 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- // 修改 createIframe.ts
7
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
+ 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; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ 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; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
+ 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
13
  var createIframeContent = function createIframeContent() {
9
- var timestamp = new Date().getTime();
10
- 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?t=".concat(timestamp, "\" rel=\"stylesheet\" />\n <link href=\"https://alifd.alicdn.com/npm/@alifd/theme-lowcode-light@0.2.1/dist/next.var.min.css?t=").concat(timestamp, "\" rel=\"stylesheet\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/css/engine-core.css?t=").concat(timestamp, "\" />\n <link rel=\"stylesheet\" href=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/css/engine-ext.css?t=").concat(timestamp, "\" />\n <link rel=\"stylesheet\" href=\"https://g.alicdn.com/fone-lowcode/fr-generator/1.1.0/css/index.css?t=").concat(timestamp, "\" />\n\n <script>\n // \u76D1\u542C\u7236\u7A97\u53E3\u7684\u6D88\u606F\n window.addEventListener('message', function(event) {\n // \u786E\u4FDD\u6D88\u606F\u6765\u6E90\u53EF\u4FE1\n if (event.source !== window.parent) return;\n \n if (event.data.type === 'SET_GET_FORM_RENDER_MATERIAL') {\n console.log('Received getFormRenderMaterial from parent');\n \n // \u5C06\u7236\u7A97\u53E3\u4F20\u9012\u7684\u51FD\u6570\u8BBE\u7F6E\u4E3A\u5168\u5C40\u65B9\u6CD5\n window.getFormRenderMaterial = function() {\n console.log('getFormRenderMaterial called (from parent)');\n \n // \u8FD9\u91CC\u53EF\u4EE5\u8C03\u7528\u7236\u7A97\u53E3\u4F20\u9012\u7684\u5B9E\u73B0\uFF0C\u6216\u8005\u4F7F\u7528\u672C\u5730\u5B9E\u73B0\n if (event.data.implementation) {\n try {\n // \u4F7F\u7528\u7236\u7A97\u53E3\u4F20\u9012\u7684\u5B9E\u73B0\n return event.data.implementation.apply(this, arguments);\n } catch(e) {\n console.error('Error calling parent implementation:', e);\n }\n }\n \n // \u540E\u5907\u5B9E\u73B0\n return {};\n };\n \n // \u786E\u8BA4\u8BBE\u7F6E\u5B8C\u6210\n window.parent.postMessage({\n type: 'GET_FORM_RENDER_MATERIAL_SET',\n success: true\n }, '*');\n }\n });\n \n // \u9884\u5B9A\u4E49\u4E00\u4E2A\u5B89\u5168\u7684 getFormRenderMaterial \u51FD\u6570\n window.getFormRenderMaterial = window.getFormRenderMaterial || function() {\n console.warn('getFormRenderMaterial called before initialization');\n return {};\n };\n \n // \u8BBE\u7F6E\u5176\u4ED6\u5FC5\u8981\u7684\u5168\u5C40\u53D8\u91CF\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n window.__is_simulator_env__ = true;\n </script>\n \n <script src=\"https://g.alicdn.com/code/lib/prop-types/15.7.2/prop-types.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/react15-polyfill/0.0.1/dist/index.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js?t=").concat(timestamp, "\"></script>\n <script src=\"https://g.alicdn.com/code/lib/alifd__next/1.23.24/next.min.js?t=").concat(timestamp, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine/1.2.3/dist/js/engine-core.js?t=").concat(timestamp, "\"></script>\n <script crossorigin=\"anonymous\" src=\"https://uipaas-assets.com/prod/npm/@alilc/lowcode-engine-ext/1.0.6/dist/js/engine-ext.js?t=").concat(timestamp, "\"></script>\n </head>\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?t=").concat(timestamp, "\"></script>\n </body>\n </html>\n ");
14
+ 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 </head>\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 ";
11
15
  return html;
12
16
  };
13
17
  var _default = exports.default = function _default() {
@@ -16,5 +20,87 @@ var _default = exports.default = function _default() {
16
20
  iframe.height = '100%';
17
21
  iframe.frameBorder = '0';
18
22
  iframe.srcdoc = createIframeContent();
23
+
24
+ // 监听iframe加载完成
25
+ iframe.onload = function () {
26
+ var win = iframe.contentWindow;
27
+ if (!win) return;
28
+
29
+ // 拦截低代码引擎的createSimulator函数
30
+ patchCreateSimulatorInIframe(win);
31
+ };
19
32
  return iframe;
20
- };
33
+ }; // 在iframe内部修补createSimulator函数
34
+ function patchCreateSimulatorInIframe(iframeWindow) {
35
+ // 保存原始的createSimulator函数
36
+ var originalCreateSimulator = iframeWindow.createSimulator;
37
+ if (originalCreateSimulator) {
38
+ iframeWindow.createSimulator = function (host, iframe, vendors) {
39
+ // 处理vendors,给JS URL添加时间戳
40
+ var processedVendors = addTimestampToVendors(vendors);
41
+ return originalCreateSimulator.call(this, host, iframe, processedVendors);
42
+ };
43
+ }
44
+
45
+ // 工具函数(同上)
46
+ function addTimestampToVendors(vendors) {
47
+ var timestamp = new Date().getTime();
48
+ return vendors.map(function (vendor) {
49
+ if (!vendor) return vendor;
50
+ if (vendor.type === 'bundle' && Array.isArray(vendor.assets)) {
51
+ return _objectSpread(_objectSpread({}, vendor), {}, {
52
+ assets: vendor.assets.map(function (asset) {
53
+ if (!asset) return asset;
54
+
55
+ // 处理字符串URL
56
+ if (typeof asset === 'string') {
57
+ return addTimestampToUrl(asset, timestamp);
58
+ }
59
+
60
+ // 处理数组(可能是URL数组)
61
+ if (Array.isArray(asset)) {
62
+ return asset.map(function (item) {
63
+ if (typeof item === 'string') {
64
+ return addTimestampToUrl(item, timestamp);
65
+ }
66
+ // 处理数组中的数组(嵌套情况)
67
+ if (Array.isArray(item)) {
68
+ return item.map(function (subItem) {
69
+ if (typeof subItem === 'string') {
70
+ return addTimestampToUrl(subItem, timestamp);
71
+ }
72
+ return subItem;
73
+ });
74
+ }
75
+ return item;
76
+ });
77
+ }
78
+
79
+ // 处理对象类型
80
+ if (_typeof(asset) === 'object') {
81
+ if (asset.type === 'jsText' || asset.type === 'cssText') {
82
+ // 内联脚本,不需要加时间戳
83
+ return asset;
84
+ }
85
+ if (asset.content && typeof asset.content === 'string') {
86
+ return _objectSpread(_objectSpread({}, asset), {}, {
87
+ content: addTimestampToUrl(asset.content, timestamp)
88
+ });
89
+ }
90
+ }
91
+ return asset;
92
+ })
93
+ });
94
+ }
95
+ return vendor;
96
+ });
97
+ }
98
+ function addTimestampToUrl(url, timestamp) {
99
+ if (!url || typeof url !== 'string') return url;
100
+
101
+ // 跳过已经有时间戳的URL
102
+ if (url.includes('t=')) return url;
103
+ var separator = url.includes('?') ? '&' : '?';
104
+ return "".concat(url).concat(separator, "t=").concat(timestamp);
105
+ }
106
+ }
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; }
@@ -18,15 +18,12 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
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
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; }
20
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; }
21
- var iframe = null;
21
+ var iframe;
22
22
  var Design = function Design(props, ref) {
23
23
  var widgets = props.widgets,
24
24
  settings = props.settings,
25
25
  restProps = _objectWithoutProperties(props, _excluded);
26
26
  var containerRef = (0, _react.useRef)();
27
- var injectionAttemptsRef = (0, _react.useRef)(0);
28
- var maxInjectionAttempts = 50; // 最多尝试50次
29
-
30
27
  (0, _react.useImperativeHandle)(ref, function () {
31
28
  return {
32
29
  getValue: function getValue() {
@@ -40,138 +37,29 @@ var Design = function Design(props, ref) {
40
37
  };
41
38
  });
42
39
  (0, _react.useEffect)(function () {
43
- initIframe();
44
40
  window.addEventListener('message', engineOnLoad);
45
-
46
- // 监听来自 iframe 的消息
47
- window.addEventListener('message', handleIframeMessage);
41
+ initIframe();
48
42
  return function () {
49
43
  window.removeEventListener('message', engineOnLoad);
50
- window.removeEventListener('message', handleIframeMessage);
51
44
  };
52
45
  }, []);
53
46
  var initIframe = function initIframe() {
54
47
  iframe = (0, _createIframe.default)();
55
48
  containerRef.current.appendChild(iframe);
56
-
57
- // 监听 iframe 的 load 事件
58
- iframe.onload = function () {
59
- console.log('iframe loaded, injecting getFormRenderMaterial');
60
- injectGetFormRenderMaterial();
61
-
62
- // 启动一个定时器,持续检查并注入
63
- var checkInterval = setInterval(function () {
64
- var _iframe3;
65
- injectionAttemptsRef.current++;
66
- if (injectionAttemptsRef.current > maxInjectionAttempts) {
67
- clearInterval(checkInterval);
68
- console.error("Failed to inject getFormRenderMaterial after ".concat(maxInjectionAttempts, " attempts"));
69
- return;
70
- }
71
- if (((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow) && !isFunctionProperlyInjected()) {
72
- console.log("Attempt ".concat(injectionAttemptsRef.current, ": Injecting getFormRenderMaterial"));
73
- injectGetFormRenderMaterial();
74
- } else if (isFunctionProperlyInjected()) {
75
- clearInterval(checkInterval);
76
- console.log('getFormRenderMaterial successfully injected and verified');
77
- }
78
- }, 100);
79
- };
80
- };
81
- var handleIframeMessage = function handleIframeMessage(event) {
82
- var _iframe4;
83
- // 确保消息来自我们的 iframe
84
- if (event.source !== ((_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : _iframe4.contentWindow)) return;
85
- if (event.data.type === 'GET_FORM_RENDER_MATERIAL_SET') {
86
- console.log('iframe confirmed getFormRenderMaterial was set');
87
- }
88
- };
89
- var injectGetFormRenderMaterial = function injectGetFormRenderMaterial() {
90
- var _iframe5;
91
- if (!((_iframe5 = iframe) === null || _iframe5 === void 0 ? void 0 : _iframe5.contentWindow)) {
92
- console.error('Cannot inject: iframe or contentWindow not available');
93
- return false;
94
- }
95
- try {
96
- // 方法1:直接注入(可能受同源策略限制)
97
- var iframeWin = iframe.contentWindow;
98
-
99
- // 创建一个函数字符串,然后通过 eval 在 iframe 上下文中执行
100
- var functionString = "\n (function() {\n window.getFormRenderMaterial = function() {\n console.log('getFormRenderMaterial called (injected from parent)');\n return ".concat(JSON.stringify(Object.assign({
101
- __esModule: true
102
- }, widgets || {})), ";\n };\n return true;\n })()\n ");
103
-
104
- // 尝试通过 eval 执行
105
- try {
106
- iframeWin.eval(functionString);
107
- console.log('getFormRenderMaterial injected via eval');
108
- } catch (evalError) {
109
- console.warn('eval failed, trying direct assignment:', evalError);
110
-
111
- // 回退到直接赋值
112
- iframeWin.getFormRenderMaterial = function () {
113
- console.log('getFormRenderMaterial called (direct assignment)');
114
- return Object.assign({
115
- __esModule: true
116
- }, widgets || {});
117
- };
118
- }
119
-
120
- // 方法2:使用 postMessage 发送函数实现
121
- iframeWin.postMessage({
122
- type: 'SET_GET_FORM_RENDER_MATERIAL',
123
- implementation: function implementation() {
124
- return Object.assign({
125
- __esModule: true
126
- }, widgets || {});
127
- }
128
- }, '*');
129
- return true;
130
- } catch (error) {
131
- console.error('Error injecting getFormRenderMaterial:', error);
132
- return false;
133
- }
134
- };
135
- var isFunctionProperlyInjected = function isFunctionProperlyInjected() {
136
- try {
137
- var _iframe6;
138
- var iframeWin = (_iframe6 = iframe) === null || _iframe6 === void 0 ? void 0 : _iframe6.contentWindow;
139
- return iframeWin && typeof iframeWin.getFormRenderMaterial === 'function' && iframeWin.getFormRenderMaterial.toString().includes('getFormRenderMaterial');
140
- } catch (error) {
141
- // 可能由于同源策略无法访问
142
- return false;
143
- }
144
49
  };
145
50
  var engineOnLoad = function engineOnLoad(event) {
146
- var _iframe7;
51
+ var _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2;
147
52
  if (event.data.type !== 'engine-load') {
148
53
  return;
149
54
  }
150
-
151
- // 在初始化前再次确保 getFormRenderMaterial 存在
152
- console.log('Engine loading, verifying getFormRenderMaterial');
153
-
154
- // 尝试通过 postMessage 与 iframe 通信来验证
155
- if ((_iframe7 = iframe) === null || _iframe7 === void 0 ? void 0 : _iframe7.contentWindow) {
156
- iframe.contentWindow.postMessage({
157
- type: 'VERIFY_GET_FORM_RENDER_MATERIAL'
158
- }, '*');
159
-
160
- // 设置一个超时,以防验证失败
161
- setTimeout(function () {
162
- var _iframe8, _iframe8$contentWindo;
163
- if ((_iframe8 = iframe) === null || _iframe8 === void 0 ? void 0 : (_iframe8$contentWindo = _iframe8.contentWindow) === null || _iframe8$contentWindo === void 0 ? void 0 : _iframe8$contentWindo.__FR_ENGINE__) {
164
- console.log('Initializing FR_ENGINE');
165
- iframe.contentWindow.__FR_ENGINE__.init(_objectSpread({
166
- settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
167
- widgets: widgets,
168
- logo: {
169
- title: 'XRender'
170
- }
171
- }, restProps));
172
- }
173
- }, 500);
174
- }
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
+ }
62
+ }, restProps));
175
63
  };
176
64
  return /*#__PURE__*/_react.default.createElement("div", {
177
65
  ref: containerRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.72",
3
+ "version": "1.0.0-alpha.74",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",