@zzdadelu/schema-builder 1.0.0-alpha.103 → 1.0.0-alpha.104
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/createIframe.js +1 -1
- package/es/main.js +62 -6
- package/lib/createIframe.js +1 -1
- package/lib/main.js +62 -6
- package/package.json +1 -1
package/es/createIframe.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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 </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 ";
|
|
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 // \u8BBE\u7F6E\u5168\u5C40\u53D8\u91CF\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n window.__is_simulator_env__ = true;\n window.PropTypes = window.parent.PropTypes;\n React.PropTypes = window.parent.PropTypes;\n window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__;\n \n // \u9884\u5B9A\u4E49 getFormRenderMaterial \u51FD\u6570\n (function() {\n // \u5B58\u50A8\u5B9E\u9645\u7684\u7269\u6599\u6570\u636E\n window.__FR_MATERIAL_DATA__ = {};\n window.__FR_MATERIAL_FUNCTION = null;\n \n // \u5B9A\u4E49 getFormRenderMaterial \u51FD\u6570\n window.getFormRenderMaterial = function(name, packageName) {\n // \u5982\u679C\u5DF2\u7ECF\u8BBE\u7F6E\u4E86\u5B9E\u9645\u7684\u51FD\u6570\uFF0C\u5C31\u8C03\u7528\u5B83\n if (window.__FR_MATERIAL_FUNCTION) {\n return window.__FR_MATERIAL_FUNCTION(name, packageName);\n }\n \n // \u5426\u5219\u8FD4\u56DE\u4E00\u4E2A\u5DE5\u5382\u51FD\u6570\uFF0C\u8FD9\u4E2A\u5DE5\u5382\u51FD\u6570\u8FD4\u56DE\u5B9E\u9645\u7684\u7269\u6599\u6570\u636E\n return function() {\n // \u68C0\u67E5\u662F\u5426\u5DF2\u7ECF\u6709\u7269\u6599\u6570\u636E\n var materialKey = name + '_' + packageName;\n if (window.__FR_MATERIAL_DATA__[materialKey]) {\n return window.__FR_MATERIAL_DATA__[materialKey];\n }\n \n // \u8FD4\u56DE\u4E00\u4E2A\u7A7A\u5BF9\u8C61\uFF0C\u907F\u514D\u62A5\u9519\n console.warn('FormRender material not ready yet for:', name, packageName);\n return {};\n };\n };\n \n // \u63D0\u4F9B\u4E00\u4E2A\u65B9\u6CD5\u8BA9\u5916\u90E8\u8BBE\u7F6E\u7269\u6599\u6570\u636E\n window.__setFormRenderMaterial = function(data) {\n if (typeof data === 'function') {\n window.__FR_MATERIAL_FUNCTION = data;\n } else if (typeof data === 'object') {\n window.__FR_MATERIAL_DATA__ = Object.assign({}, window.__FR_MATERIAL_DATA__, data);\n }\n };\n \n // \u76D1\u542C\u6765\u81EA\u7236\u7A97\u53E3\u7684\u6D88\u606F\uFF0C\u8BBE\u7F6E\u7269\u6599\u6570\u636E\n window.addEventListener('message', function(event) {\n if (event.data && event.data.type === 'SET_FORM_RENDER_MATERIAL') {\n window.__setFormRenderMaterial(event.data.materialData);\n }\n });\n })();\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 ";
|
|
3
3
|
return html;
|
|
4
4
|
};
|
|
5
5
|
export default (function () {
|
package/es/main.js
CHANGED
|
@@ -10,8 +10,8 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
|
|
|
10
10
|
import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
|
|
11
11
|
import createIframe from './createIframe';
|
|
12
12
|
import * as defaultSetting from './settings';
|
|
13
|
-
import { log } from 'console';
|
|
14
13
|
var iframe;
|
|
14
|
+
var materialData = null;
|
|
15
15
|
var Design = function Design(props, ref) {
|
|
16
16
|
var widgets = props.widgets,
|
|
17
17
|
settings = props.settings,
|
|
@@ -38,18 +38,74 @@ var Design = function Design(props, ref) {
|
|
|
38
38
|
}, []);
|
|
39
39
|
var initIframe = function initIframe() {
|
|
40
40
|
iframe = createIframe();
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
// 监听 iframe 加载完成
|
|
43
|
+
iframe.onload = function () {
|
|
44
|
+
// 立即设置 getFormRenderMaterial 函数,防止 create-simulator 调用时报错
|
|
45
|
+
if (iframe.contentWindow) {
|
|
46
|
+
// 创建一个临时的 getFormRenderMaterial 函数
|
|
47
|
+
iframe.contentWindow.getFormRenderMaterial = function (name, packageName) {
|
|
48
|
+
console.log('getFormRenderMaterial called with:', name, packageName);
|
|
49
|
+
|
|
50
|
+
// 返回一个工厂函数
|
|
51
|
+
return function () {
|
|
52
|
+
console.log('Material factory called for:', name, packageName);
|
|
53
|
+
|
|
54
|
+
// 检查是否有缓存的物料
|
|
55
|
+
if (materialData) {
|
|
56
|
+
return materialData;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 返回一个模拟的物料,包含必要的属性
|
|
60
|
+
return {
|
|
61
|
+
__esModule: true,
|
|
62
|
+
// 添加一些默认的组件配置
|
|
63
|
+
components: {},
|
|
64
|
+
snippets: [],
|
|
65
|
+
componentList: []
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// 发送物料数据到 iframe
|
|
71
|
+
if (widgets) {
|
|
72
|
+
materialData = widgets;
|
|
73
|
+
iframe.contentWindow.postMessage({
|
|
74
|
+
type: 'SET_FORM_RENDER_MATERIAL',
|
|
75
|
+
materialData: widgets
|
|
76
|
+
}, '*');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
setTimeout(function () {
|
|
81
|
+
// 延迟设置物料
|
|
82
|
+
iframe.contentWindow.AliFormRenderMaterial = materialData;
|
|
83
|
+
}, 100);
|
|
42
84
|
containerRef.current.appendChild(iframe);
|
|
43
85
|
};
|
|
44
86
|
var engineOnLoad = function engineOnLoad(event) {
|
|
45
|
-
var _iframe3,
|
|
87
|
+
var _iframe3, _iframe4, _iframe4$contentWindo, _iframe4$contentWindo2;
|
|
46
88
|
if (event.data.type !== 'engine-load') {
|
|
47
89
|
return;
|
|
48
90
|
}
|
|
49
|
-
|
|
91
|
+
|
|
92
|
+
// 确保物料数据已经准备好
|
|
93
|
+
if (!materialData && widgets) {
|
|
94
|
+
materialData = widgets;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 再次发送物料数据,确保 fr-generator 能够收到
|
|
98
|
+
if (((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow) && materialData) {
|
|
99
|
+
iframe.contentWindow.postMessage({
|
|
100
|
+
type: 'SET_FORM_RENDER_MATERIAL',
|
|
101
|
+
materialData: materialData
|
|
102
|
+
}, '*');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 初始化引擎
|
|
106
|
+
(_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$contentWindo2.init(_objectSpread({
|
|
50
107
|
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
51
|
-
widgets: widgets,
|
|
52
|
-
// recordEnable: true,
|
|
108
|
+
widgets: materialData || widgets,
|
|
53
109
|
logo: {
|
|
54
110
|
title: 'XRender'
|
|
55
111
|
}
|
package/lib/createIframe.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
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 </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 ";
|
|
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 // \u8BBE\u7F6E\u5168\u5C40\u53D8\u91CF\n window.React = window.parent.React;\n window.ReactDOM = window.parent.ReactDOM;\n window.__is_simulator_env__ = true;\n window.PropTypes = window.parent.PropTypes;\n React.PropTypes = window.parent.PropTypes;\n window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__;\n \n // \u9884\u5B9A\u4E49 getFormRenderMaterial \u51FD\u6570\n (function() {\n // \u5B58\u50A8\u5B9E\u9645\u7684\u7269\u6599\u6570\u636E\n window.__FR_MATERIAL_DATA__ = {};\n window.__FR_MATERIAL_FUNCTION = null;\n \n // \u5B9A\u4E49 getFormRenderMaterial \u51FD\u6570\n window.getFormRenderMaterial = function(name, packageName) {\n // \u5982\u679C\u5DF2\u7ECF\u8BBE\u7F6E\u4E86\u5B9E\u9645\u7684\u51FD\u6570\uFF0C\u5C31\u8C03\u7528\u5B83\n if (window.__FR_MATERIAL_FUNCTION) {\n return window.__FR_MATERIAL_FUNCTION(name, packageName);\n }\n \n // \u5426\u5219\u8FD4\u56DE\u4E00\u4E2A\u5DE5\u5382\u51FD\u6570\uFF0C\u8FD9\u4E2A\u5DE5\u5382\u51FD\u6570\u8FD4\u56DE\u5B9E\u9645\u7684\u7269\u6599\u6570\u636E\n return function() {\n // \u68C0\u67E5\u662F\u5426\u5DF2\u7ECF\u6709\u7269\u6599\u6570\u636E\n var materialKey = name + '_' + packageName;\n if (window.__FR_MATERIAL_DATA__[materialKey]) {\n return window.__FR_MATERIAL_DATA__[materialKey];\n }\n \n // \u8FD4\u56DE\u4E00\u4E2A\u7A7A\u5BF9\u8C61\uFF0C\u907F\u514D\u62A5\u9519\n console.warn('FormRender material not ready yet for:', name, packageName);\n return {};\n };\n };\n \n // \u63D0\u4F9B\u4E00\u4E2A\u65B9\u6CD5\u8BA9\u5916\u90E8\u8BBE\u7F6E\u7269\u6599\u6570\u636E\n window.__setFormRenderMaterial = function(data) {\n if (typeof data === 'function') {\n window.__FR_MATERIAL_FUNCTION = data;\n } else if (typeof data === 'object') {\n window.__FR_MATERIAL_DATA__ = Object.assign({}, window.__FR_MATERIAL_DATA__, data);\n }\n };\n \n // \u76D1\u542C\u6765\u81EA\u7236\u7A97\u53E3\u7684\u6D88\u606F\uFF0C\u8BBE\u7F6E\u7269\u6599\u6570\u636E\n window.addEventListener('message', function(event) {\n if (event.data && event.data.type === 'SET_FORM_RENDER_MATERIAL') {\n window.__setFormRenderMaterial(event.data.materialData);\n }\n });\n })();\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 ";
|
|
9
9
|
return html;
|
|
10
10
|
};
|
|
11
11
|
var _default = exports.default = function _default() {
|
package/lib/main.js
CHANGED
|
@@ -8,7 +8,6 @@ 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 _console = require("console");
|
|
12
11
|
var _excluded = ["widgets", "settings"];
|
|
13
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
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); }
|
|
@@ -20,6 +19,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
20
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; }
|
|
21
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; }
|
|
22
21
|
var iframe;
|
|
22
|
+
var materialData = null;
|
|
23
23
|
var Design = function Design(props, ref) {
|
|
24
24
|
var widgets = props.widgets,
|
|
25
25
|
settings = props.settings,
|
|
@@ -46,18 +46,74 @@ var Design = function Design(props, ref) {
|
|
|
46
46
|
}, []);
|
|
47
47
|
var initIframe = function initIframe() {
|
|
48
48
|
iframe = (0, _createIframe.default)();
|
|
49
|
-
|
|
49
|
+
|
|
50
|
+
// 监听 iframe 加载完成
|
|
51
|
+
iframe.onload = function () {
|
|
52
|
+
// 立即设置 getFormRenderMaterial 函数,防止 create-simulator 调用时报错
|
|
53
|
+
if (iframe.contentWindow) {
|
|
54
|
+
// 创建一个临时的 getFormRenderMaterial 函数
|
|
55
|
+
iframe.contentWindow.getFormRenderMaterial = function (name, packageName) {
|
|
56
|
+
console.log('getFormRenderMaterial called with:', name, packageName);
|
|
57
|
+
|
|
58
|
+
// 返回一个工厂函数
|
|
59
|
+
return function () {
|
|
60
|
+
console.log('Material factory called for:', name, packageName);
|
|
61
|
+
|
|
62
|
+
// 检查是否有缓存的物料
|
|
63
|
+
if (materialData) {
|
|
64
|
+
return materialData;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 返回一个模拟的物料,包含必要的属性
|
|
68
|
+
return {
|
|
69
|
+
__esModule: true,
|
|
70
|
+
// 添加一些默认的组件配置
|
|
71
|
+
components: {},
|
|
72
|
+
snippets: [],
|
|
73
|
+
componentList: []
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// 发送物料数据到 iframe
|
|
79
|
+
if (widgets) {
|
|
80
|
+
materialData = widgets;
|
|
81
|
+
iframe.contentWindow.postMessage({
|
|
82
|
+
type: 'SET_FORM_RENDER_MATERIAL',
|
|
83
|
+
materialData: widgets
|
|
84
|
+
}, '*');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
setTimeout(function () {
|
|
89
|
+
// 延迟设置物料
|
|
90
|
+
iframe.contentWindow.AliFormRenderMaterial = materialData;
|
|
91
|
+
}, 100);
|
|
50
92
|
containerRef.current.appendChild(iframe);
|
|
51
93
|
};
|
|
52
94
|
var engineOnLoad = function engineOnLoad(event) {
|
|
53
|
-
var _iframe3,
|
|
95
|
+
var _iframe3, _iframe4, _iframe4$contentWindo, _iframe4$contentWindo2;
|
|
54
96
|
if (event.data.type !== 'engine-load') {
|
|
55
97
|
return;
|
|
56
98
|
}
|
|
57
|
-
|
|
99
|
+
|
|
100
|
+
// 确保物料数据已经准备好
|
|
101
|
+
if (!materialData && widgets) {
|
|
102
|
+
materialData = widgets;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 再次发送物料数据,确保 fr-generator 能够收到
|
|
106
|
+
if (((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow) && materialData) {
|
|
107
|
+
iframe.contentWindow.postMessage({
|
|
108
|
+
type: 'SET_FORM_RENDER_MATERIAL',
|
|
109
|
+
materialData: materialData
|
|
110
|
+
}, '*');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 初始化引擎
|
|
114
|
+
(_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$contentWindo2.init(_objectSpread({
|
|
58
115
|
settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
|
|
59
|
-
widgets: widgets,
|
|
60
|
-
// recordEnable: true,
|
|
116
|
+
widgets: materialData || widgets,
|
|
61
117
|
logo: {
|
|
62
118
|
title: 'XRender'
|
|
63
119
|
}
|