@zzdadelu/schema-builder 1.0.0-alpha.7 → 1.0.0-alpha.71

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
@@ -8,9 +8,11 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
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
10
  import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
11
- import createIframe from './createIframe';
12
11
  import * as defaultSetting from './settings';
12
+ import createIframe from './createIframe';
13
13
  var iframe;
14
+
15
+ // 修改 main.ts,在父窗口中直接注入 getFormRenderMaterial
14
16
  var Design = function Design(props, ref) {
15
17
  var widgets = props.widgets,
16
18
  settings = props.settings,
@@ -19,38 +21,87 @@ var Design = function Design(props, ref) {
19
21
  useImperativeHandle(ref, function () {
20
22
  return {
21
23
  getValue: function getValue() {
22
- var _iframe, _iframe2, _iframe2$contentWindo, _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2, _iframe3$contentWindo3;
23
- console.log("contentWindow", (_iframe = iframe) === null || _iframe === void 0 ? void 0 : _iframe.contentWindow);
24
- console.log("__FR_ENGINE__", (_iframe2 = iframe) === null || _iframe2 === void 0 ? void 0 : (_iframe2$contentWindo = _iframe2.contentWindow) === null || _iframe2$contentWindo === void 0 ? void 0 : _iframe2$contentWindo.__FR_ENGINE__);
25
- return (_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$contentWindo3 = _iframe3$contentWindo2.exportSchema) === null || _iframe3$contentWindo3 === void 0 ? void 0 : _iframe3$contentWindo3.call(_iframe3$contentWindo2);
24
+ var _iframe, _iframe$contentWindow, _iframe$contentWindow2, _iframe$contentWindow3;
25
+ return (_iframe = iframe) === null || _iframe === void 0 ? void 0 : (_iframe$contentWindow = _iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : (_iframe$contentWindow2 = _iframe$contentWindow.__FR_ENGINE__) === null || _iframe$contentWindow2 === void 0 ? void 0 : (_iframe$contentWindow3 = _iframe$contentWindow2.exportSchema) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.call(_iframe$contentWindow2);
26
26
  },
27
27
  setValue: function setValue(schema) {
28
- var _iframe4, _iframe4$contentWindo, _iframe4$contentWindo2, _iframe4$contentWindo3;
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);
28
+ var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
29
+ return (_iframe2 = iframe) === null || _iframe2 === void 0 ? void 0 : (_iframe2$contentWindo = _iframe2.contentWindow) === null || _iframe2$contentWindo === void 0 ? void 0 : (_iframe2$contentWindo2 = _iframe2$contentWindo.__FR_ENGINE__) === null || _iframe2$contentWindo2 === void 0 ? void 0 : (_iframe2$contentWindo3 = _iframe2$contentWindo2.importSchema) === null || _iframe2$contentWindo3 === void 0 ? void 0 : _iframe2$contentWindo3.call(_iframe2$contentWindo2, schema);
30
30
  }
31
31
  };
32
32
  });
33
33
  useEffect(function () {
34
34
  initIframe();
35
35
  window.addEventListener('message', engineOnLoad);
36
+
37
+ // 添加一个定时器,确保 getFormRenderMaterial 被正确注入
38
+ var checkInterval = setInterval(function () {
39
+ var _iframe3;
40
+ if (((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow) && !iframe.contentWindow.getFormRenderMaterial) {
41
+ console.log('Manually injecting getFormRenderMaterial from parent');
42
+ iframe.contentWindow.getFormRenderMaterial = function () {
43
+ return Object.assign({
44
+ __esModule: true
45
+ }, widgets || {});
46
+ };
47
+ }
48
+ }, 100);
36
49
  return function () {
37
50
  window.removeEventListener('message', engineOnLoad);
51
+ clearInterval(checkInterval);
38
52
  };
39
53
  }, []);
40
54
  var initIframe = function initIframe() {
41
- console.log("开始创建 iframe");
42
55
  iframe = createIframe();
43
56
  containerRef.current.appendChild(iframe);
57
+
58
+ // 监听 iframe 的 load 事件
59
+ iframe.onload = function () {
60
+ console.log('iframe loaded, injecting getFormRenderMaterial');
61
+
62
+ // 立即尝试注入 getFormRenderMaterial
63
+ if (iframe.contentWindow) {
64
+ // 方法1:直接注入
65
+ iframe.contentWindow.getFormRenderMaterial = function () {
66
+ console.log('Parent-injected getFormRenderMaterial called');
67
+ return Object.assign({
68
+ __esModule: true
69
+ }, widgets || {});
70
+ };
71
+
72
+ // 方法2:模拟 polling 机制
73
+ setTimeout(function () {
74
+ if (iframe.contentWindow && !iframe.contentWindow.getFormRenderMaterial) {
75
+ console.log('Fallback injection after timeout');
76
+ iframe.contentWindow.getFormRenderMaterial = function () {
77
+ return Object.assign({
78
+ __esModule: true
79
+ }, widgets || {});
80
+ };
81
+ }
82
+ }, 500);
83
+ }
84
+ };
44
85
  };
45
86
  var engineOnLoad = function engineOnLoad(event) {
46
- var _iframe5, _iframe5$contentWindo, _iframe5$contentWindo2;
87
+ var _iframe4, _iframe5, _iframe5$contentWindo, _iframe5$contentWindo2;
47
88
  if (event.data.type !== 'engine-load') {
48
89
  return;
49
90
  }
91
+
92
+ // 在初始化前再次确保 getFormRenderMaterial 存在
93
+ var iframeWin = (_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : _iframe4.contentWindow;
94
+ if (iframeWin && !iframeWin.getFormRenderMaterial) {
95
+ console.warn('getFormRenderMaterial missing before init, injecting');
96
+ iframeWin.getFormRenderMaterial = function () {
97
+ return Object.assign({
98
+ __esModule: true
99
+ }, widgets || {});
100
+ };
101
+ }
50
102
  (_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({
51
103
  settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
52
104
  widgets: widgets,
53
- // recordEnable: true,
54
105
  logo: {
55
106
  title: 'XRender'
56
107
  }
package/lib/main.js CHANGED
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
- var _createIframe = _interopRequireDefault(require("./createIframe"));
10
9
  var defaultSetting = _interopRequireWildcard(require("./settings"));
10
+ var _createIframe = _interopRequireDefault(require("./createIframe"));
11
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); }
@@ -19,6 +19,8 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
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
21
  var iframe;
22
+
23
+ // 修改 main.ts,在父窗口中直接注入 getFormRenderMaterial
22
24
  var Design = function Design(props, ref) {
23
25
  var widgets = props.widgets,
24
26
  settings = props.settings,
@@ -27,38 +29,87 @@ var Design = function Design(props, ref) {
27
29
  (0, _react.useImperativeHandle)(ref, function () {
28
30
  return {
29
31
  getValue: function getValue() {
30
- var _iframe, _iframe2, _iframe2$contentWindo, _iframe3, _iframe3$contentWindo, _iframe3$contentWindo2, _iframe3$contentWindo3;
31
- console.log("contentWindow", (_iframe = iframe) === null || _iframe === void 0 ? void 0 : _iframe.contentWindow);
32
- console.log("__FR_ENGINE__", (_iframe2 = iframe) === null || _iframe2 === void 0 ? void 0 : (_iframe2$contentWindo = _iframe2.contentWindow) === null || _iframe2$contentWindo === void 0 ? void 0 : _iframe2$contentWindo.__FR_ENGINE__);
33
- return (_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$contentWindo3 = _iframe3$contentWindo2.exportSchema) === null || _iframe3$contentWindo3 === void 0 ? void 0 : _iframe3$contentWindo3.call(_iframe3$contentWindo2);
32
+ var _iframe, _iframe$contentWindow, _iframe$contentWindow2, _iframe$contentWindow3;
33
+ return (_iframe = iframe) === null || _iframe === void 0 ? void 0 : (_iframe$contentWindow = _iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : (_iframe$contentWindow2 = _iframe$contentWindow.__FR_ENGINE__) === null || _iframe$contentWindow2 === void 0 ? void 0 : (_iframe$contentWindow3 = _iframe$contentWindow2.exportSchema) === null || _iframe$contentWindow3 === void 0 ? void 0 : _iframe$contentWindow3.call(_iframe$contentWindow2);
34
34
  },
35
35
  setValue: function setValue(schema) {
36
- var _iframe4, _iframe4$contentWindo, _iframe4$contentWindo2, _iframe4$contentWindo3;
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);
36
+ var _iframe2, _iframe2$contentWindo, _iframe2$contentWindo2, _iframe2$contentWindo3;
37
+ return (_iframe2 = iframe) === null || _iframe2 === void 0 ? void 0 : (_iframe2$contentWindo = _iframe2.contentWindow) === null || _iframe2$contentWindo === void 0 ? void 0 : (_iframe2$contentWindo2 = _iframe2$contentWindo.__FR_ENGINE__) === null || _iframe2$contentWindo2 === void 0 ? void 0 : (_iframe2$contentWindo3 = _iframe2$contentWindo2.importSchema) === null || _iframe2$contentWindo3 === void 0 ? void 0 : _iframe2$contentWindo3.call(_iframe2$contentWindo2, schema);
38
38
  }
39
39
  };
40
40
  });
41
41
  (0, _react.useEffect)(function () {
42
42
  initIframe();
43
43
  window.addEventListener('message', engineOnLoad);
44
+
45
+ // 添加一个定时器,确保 getFormRenderMaterial 被正确注入
46
+ var checkInterval = setInterval(function () {
47
+ var _iframe3;
48
+ if (((_iframe3 = iframe) === null || _iframe3 === void 0 ? void 0 : _iframe3.contentWindow) && !iframe.contentWindow.getFormRenderMaterial) {
49
+ console.log('Manually injecting getFormRenderMaterial from parent');
50
+ iframe.contentWindow.getFormRenderMaterial = function () {
51
+ return Object.assign({
52
+ __esModule: true
53
+ }, widgets || {});
54
+ };
55
+ }
56
+ }, 100);
44
57
  return function () {
45
58
  window.removeEventListener('message', engineOnLoad);
59
+ clearInterval(checkInterval);
46
60
  };
47
61
  }, []);
48
62
  var initIframe = function initIframe() {
49
- console.log("开始创建 iframe");
50
63
  iframe = (0, _createIframe.default)();
51
64
  containerRef.current.appendChild(iframe);
65
+
66
+ // 监听 iframe 的 load 事件
67
+ iframe.onload = function () {
68
+ console.log('iframe loaded, injecting getFormRenderMaterial');
69
+
70
+ // 立即尝试注入 getFormRenderMaterial
71
+ if (iframe.contentWindow) {
72
+ // 方法1:直接注入
73
+ iframe.contentWindow.getFormRenderMaterial = function () {
74
+ console.log('Parent-injected getFormRenderMaterial called');
75
+ return Object.assign({
76
+ __esModule: true
77
+ }, widgets || {});
78
+ };
79
+
80
+ // 方法2:模拟 polling 机制
81
+ setTimeout(function () {
82
+ if (iframe.contentWindow && !iframe.contentWindow.getFormRenderMaterial) {
83
+ console.log('Fallback injection after timeout');
84
+ iframe.contentWindow.getFormRenderMaterial = function () {
85
+ return Object.assign({
86
+ __esModule: true
87
+ }, widgets || {});
88
+ };
89
+ }
90
+ }, 500);
91
+ }
92
+ };
52
93
  };
53
94
  var engineOnLoad = function engineOnLoad(event) {
54
- var _iframe5, _iframe5$contentWindo, _iframe5$contentWindo2;
95
+ var _iframe4, _iframe5, _iframe5$contentWindo, _iframe5$contentWindo2;
55
96
  if (event.data.type !== 'engine-load') {
56
97
  return;
57
98
  }
99
+
100
+ // 在初始化前再次确保 getFormRenderMaterial 存在
101
+ var iframeWin = (_iframe4 = iframe) === null || _iframe4 === void 0 ? void 0 : _iframe4.contentWindow;
102
+ if (iframeWin && !iframeWin.getFormRenderMaterial) {
103
+ console.warn('getFormRenderMaterial missing before init, injecting');
104
+ iframeWin.getFormRenderMaterial = function () {
105
+ return Object.assign({
106
+ __esModule: true
107
+ }, widgets || {});
108
+ };
109
+ }
58
110
  (_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({
59
111
  settings: _objectSpread(_objectSpread({}, defaultSetting), settings),
60
112
  widgets: widgets,
61
- // recordEnable: true,
62
113
  logo: {
63
114
  title: 'XRender'
64
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzdadelu/schema-builder",
3
- "version": "1.0.0-alpha.7",
3
+ "version": "1.0.0-alpha.71",
4
4
  "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
5
5
  "keywords": [
6
6
  "Form",
package/es/example.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/lib/example.js DELETED
@@ -1 +0,0 @@
1
- "use strict";