@zzdadelu/schema-builder 1.0.1-alpha.1 → 1.0.1-alpha.3
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 +43 -21
- package/lib/main.js +43 -21
- package/package.json +1 -1
package/es/main.js
CHANGED
|
@@ -16,7 +16,6 @@ import createIframe from './createIframe';
|
|
|
16
16
|
import * as defaultSetting from './settings';
|
|
17
17
|
var INIT_RETRY_COUNT = 20;
|
|
18
18
|
var INIT_RETRY_INTERVAL = 300;
|
|
19
|
-
var iframe;
|
|
20
19
|
var wait = function wait(delay) {
|
|
21
20
|
return new Promise(function (resolve) {
|
|
22
21
|
window.setTimeout(resolve, delay);
|
|
@@ -35,6 +34,7 @@ var tryInitEngine = /*#__PURE__*/function () {
|
|
|
35
34
|
_context.n = 6;
|
|
36
35
|
break;
|
|
37
36
|
}
|
|
37
|
+
console.warn('[schema-builder] try engine init failed retry', index);
|
|
38
38
|
_context.p = 2;
|
|
39
39
|
_context.n = 3;
|
|
40
40
|
return Promise.resolve(engine === null || engine === void 0 ? void 0 : (_engine$init = engine.init) === null || _engine$init === void 0 ? void 0 : _engine$init.call(engine, initConfig));
|
|
@@ -65,47 +65,49 @@ var Design = function Design(props, ref) {
|
|
|
65
65
|
var widgets = props.widgets,
|
|
66
66
|
settings = props.settings,
|
|
67
67
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
68
|
-
var containerRef = useRef();
|
|
68
|
+
var containerRef = useRef(null);
|
|
69
|
+
var iframeRef = useRef(null);
|
|
69
70
|
var hasInitializedRef = useRef(false);
|
|
71
|
+
var isInitializingRef = useRef(false);
|
|
72
|
+
var getIframeWindow = function getIframeWindow() {
|
|
73
|
+
var _iframeRef$current;
|
|
74
|
+
return (_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : _iframeRef$current.contentWindow;
|
|
75
|
+
};
|
|
70
76
|
useImperativeHandle(ref, function () {
|
|
71
77
|
return {
|
|
72
78
|
getValue: function getValue() {
|
|
73
|
-
var
|
|
74
|
-
return (
|
|
79
|
+
var _getIframeWindow, _getIframeWindow$__FR, _getIframeWindow$__FR2;
|
|
80
|
+
return (_getIframeWindow = getIframeWindow()) === null || _getIframeWindow === void 0 ? void 0 : (_getIframeWindow$__FR = _getIframeWindow.__FR_ENGINE__) === null || _getIframeWindow$__FR === void 0 ? void 0 : (_getIframeWindow$__FR2 = _getIframeWindow$__FR.exportSchema) === null || _getIframeWindow$__FR2 === void 0 ? void 0 : _getIframeWindow$__FR2.call(_getIframeWindow$__FR);
|
|
75
81
|
},
|
|
76
82
|
setValue: function setValue(schema) {
|
|
77
|
-
var
|
|
78
|
-
return (
|
|
83
|
+
var _getIframeWindow2, _getIframeWindow2$__F, _getIframeWindow2$__F2;
|
|
84
|
+
return (_getIframeWindow2 = getIframeWindow()) === null || _getIframeWindow2 === void 0 ? void 0 : (_getIframeWindow2$__F = _getIframeWindow2.__FR_ENGINE__) === null || _getIframeWindow2$__F === void 0 ? void 0 : (_getIframeWindow2$__F2 = _getIframeWindow2$__F.importSchema) === null || _getIframeWindow2$__F2 === void 0 ? void 0 : _getIframeWindow2$__F2.call(_getIframeWindow2$__F, schema);
|
|
79
85
|
}
|
|
80
86
|
};
|
|
81
87
|
});
|
|
82
|
-
useEffect(function () {
|
|
83
|
-
initIframe();
|
|
84
|
-
window.addEventListener('message', engineOnLoad);
|
|
85
|
-
return function () {
|
|
86
|
-
window.removeEventListener('message', engineOnLoad);
|
|
87
|
-
hasInitializedRef.current = false;
|
|
88
|
-
};
|
|
89
|
-
}, []);
|
|
90
88
|
var initIframe = function initIframe() {
|
|
91
|
-
|
|
89
|
+
var _containerRef$current;
|
|
90
|
+
var nextIframe = createIframe();
|
|
92
91
|
hasInitializedRef.current = false;
|
|
93
|
-
|
|
92
|
+
isInitializingRef.current = false;
|
|
93
|
+
iframeRef.current = nextIframe;
|
|
94
|
+
(_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.appendChild(nextIframe);
|
|
94
95
|
};
|
|
95
96
|
var engineOnLoad = /*#__PURE__*/function () {
|
|
96
97
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(event) {
|
|
97
|
-
var
|
|
98
|
-
var iframeWindow, engine, initConfig, _t2;
|
|
98
|
+
var _event$data;
|
|
99
|
+
var currentIframe, iframeWindow, engine, initConfig, _t2;
|
|
99
100
|
return _regenerator().w(function (_context2) {
|
|
100
101
|
while (1) switch (_context2.p = _context2.n) {
|
|
101
102
|
case 0:
|
|
102
|
-
|
|
103
|
+
currentIframe = iframeRef.current;
|
|
104
|
+
if (!(((_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.type) !== 'engine-load' || hasInitializedRef.current || isInitializingRef.current || !currentIframe || event.source !== currentIframe.contentWindow)) {
|
|
103
105
|
_context2.n = 1;
|
|
104
106
|
break;
|
|
105
107
|
}
|
|
106
108
|
return _context2.a(2);
|
|
107
109
|
case 1:
|
|
108
|
-
iframeWindow = (
|
|
110
|
+
iframeWindow = getIframeWindow();
|
|
109
111
|
engine = iframeWindow === null || iframeWindow === void 0 ? void 0 : iframeWindow.__FR_ENGINE__;
|
|
110
112
|
if (!(!iframeWindow || !engine)) {
|
|
111
113
|
_context2.n = 2;
|
|
@@ -121,6 +123,7 @@ var Design = function Design(props, ref) {
|
|
|
121
123
|
title: 'XRender'
|
|
122
124
|
}
|
|
123
125
|
}, restProps);
|
|
126
|
+
isInitializingRef.current = true;
|
|
124
127
|
_context2.p = 3;
|
|
125
128
|
_context2.n = 4;
|
|
126
129
|
return tryInitEngine(engine, initConfig);
|
|
@@ -134,14 +137,33 @@ var Design = function Design(props, ref) {
|
|
|
134
137
|
hasInitializedRef.current = false;
|
|
135
138
|
console.error('[schema-builder] engine init failed after retries', _t2);
|
|
136
139
|
case 6:
|
|
140
|
+
_context2.p = 6;
|
|
141
|
+
isInitializingRef.current = false;
|
|
142
|
+
return _context2.f(6);
|
|
143
|
+
case 7:
|
|
137
144
|
return _context2.a(2);
|
|
138
145
|
}
|
|
139
|
-
}, _callee2, null, [[3, 5]]);
|
|
146
|
+
}, _callee2, null, [[3, 5, 6, 7]]);
|
|
140
147
|
}));
|
|
141
148
|
return function engineOnLoad(_x3) {
|
|
142
149
|
return _ref2.apply(this, arguments);
|
|
143
150
|
};
|
|
144
151
|
}();
|
|
152
|
+
useEffect(function () {
|
|
153
|
+
window.addEventListener('message', engineOnLoad);
|
|
154
|
+
initIframe();
|
|
155
|
+
return function () {
|
|
156
|
+
var _containerRef$current2;
|
|
157
|
+
window.removeEventListener('message', engineOnLoad);
|
|
158
|
+
hasInitializedRef.current = false;
|
|
159
|
+
isInitializingRef.current = false;
|
|
160
|
+
var currentIframe = iframeRef.current;
|
|
161
|
+
if (currentIframe && ((_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.contains(currentIframe))) {
|
|
162
|
+
containerRef.current.removeChild(currentIframe);
|
|
163
|
+
}
|
|
164
|
+
iframeRef.current = null;
|
|
165
|
+
};
|
|
166
|
+
}, []);
|
|
145
167
|
return /*#__PURE__*/React.createElement("div", {
|
|
146
168
|
ref: containerRef,
|
|
147
169
|
style: {
|
package/lib/main.js
CHANGED
|
@@ -24,7 +24,6 @@ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.
|
|
|
24
24
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
25
25
|
var INIT_RETRY_COUNT = 20;
|
|
26
26
|
var INIT_RETRY_INTERVAL = 300;
|
|
27
|
-
var iframe;
|
|
28
27
|
var wait = function wait(delay) {
|
|
29
28
|
return new Promise(function (resolve) {
|
|
30
29
|
window.setTimeout(resolve, delay);
|
|
@@ -43,6 +42,7 @@ var tryInitEngine = /*#__PURE__*/function () {
|
|
|
43
42
|
_context.n = 6;
|
|
44
43
|
break;
|
|
45
44
|
}
|
|
45
|
+
console.warn('[schema-builder] try engine init failed retry', index);
|
|
46
46
|
_context.p = 2;
|
|
47
47
|
_context.n = 3;
|
|
48
48
|
return Promise.resolve(engine === null || engine === void 0 ? void 0 : (_engine$init = engine.init) === null || _engine$init === void 0 ? void 0 : _engine$init.call(engine, initConfig));
|
|
@@ -73,47 +73,49 @@ var Design = function Design(props, ref) {
|
|
|
73
73
|
var widgets = props.widgets,
|
|
74
74
|
settings = props.settings,
|
|
75
75
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
76
|
-
var containerRef = (0, _react.useRef)();
|
|
76
|
+
var containerRef = (0, _react.useRef)(null);
|
|
77
|
+
var iframeRef = (0, _react.useRef)(null);
|
|
77
78
|
var hasInitializedRef = (0, _react.useRef)(false);
|
|
79
|
+
var isInitializingRef = (0, _react.useRef)(false);
|
|
80
|
+
var getIframeWindow = function getIframeWindow() {
|
|
81
|
+
var _iframeRef$current;
|
|
82
|
+
return (_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : _iframeRef$current.contentWindow;
|
|
83
|
+
};
|
|
78
84
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
79
85
|
return {
|
|
80
86
|
getValue: function getValue() {
|
|
81
|
-
var
|
|
82
|
-
return (
|
|
87
|
+
var _getIframeWindow, _getIframeWindow$__FR, _getIframeWindow$__FR2;
|
|
88
|
+
return (_getIframeWindow = getIframeWindow()) === null || _getIframeWindow === void 0 ? void 0 : (_getIframeWindow$__FR = _getIframeWindow.__FR_ENGINE__) === null || _getIframeWindow$__FR === void 0 ? void 0 : (_getIframeWindow$__FR2 = _getIframeWindow$__FR.exportSchema) === null || _getIframeWindow$__FR2 === void 0 ? void 0 : _getIframeWindow$__FR2.call(_getIframeWindow$__FR);
|
|
83
89
|
},
|
|
84
90
|
setValue: function setValue(schema) {
|
|
85
|
-
var
|
|
86
|
-
return (
|
|
91
|
+
var _getIframeWindow2, _getIframeWindow2$__F, _getIframeWindow2$__F2;
|
|
92
|
+
return (_getIframeWindow2 = getIframeWindow()) === null || _getIframeWindow2 === void 0 ? void 0 : (_getIframeWindow2$__F = _getIframeWindow2.__FR_ENGINE__) === null || _getIframeWindow2$__F === void 0 ? void 0 : (_getIframeWindow2$__F2 = _getIframeWindow2$__F.importSchema) === null || _getIframeWindow2$__F2 === void 0 ? void 0 : _getIframeWindow2$__F2.call(_getIframeWindow2$__F, schema);
|
|
87
93
|
}
|
|
88
94
|
};
|
|
89
95
|
});
|
|
90
|
-
(0, _react.useEffect)(function () {
|
|
91
|
-
initIframe();
|
|
92
|
-
window.addEventListener('message', engineOnLoad);
|
|
93
|
-
return function () {
|
|
94
|
-
window.removeEventListener('message', engineOnLoad);
|
|
95
|
-
hasInitializedRef.current = false;
|
|
96
|
-
};
|
|
97
|
-
}, []);
|
|
98
96
|
var initIframe = function initIframe() {
|
|
99
|
-
|
|
97
|
+
var _containerRef$current;
|
|
98
|
+
var nextIframe = (0, _createIframe.default)();
|
|
100
99
|
hasInitializedRef.current = false;
|
|
101
|
-
|
|
100
|
+
isInitializingRef.current = false;
|
|
101
|
+
iframeRef.current = nextIframe;
|
|
102
|
+
(_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.appendChild(nextIframe);
|
|
102
103
|
};
|
|
103
104
|
var engineOnLoad = /*#__PURE__*/function () {
|
|
104
105
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(event) {
|
|
105
|
-
var
|
|
106
|
-
var iframeWindow, engine, initConfig, _t2;
|
|
106
|
+
var _event$data;
|
|
107
|
+
var currentIframe, iframeWindow, engine, initConfig, _t2;
|
|
107
108
|
return _regenerator().w(function (_context2) {
|
|
108
109
|
while (1) switch (_context2.p = _context2.n) {
|
|
109
110
|
case 0:
|
|
110
|
-
|
|
111
|
+
currentIframe = iframeRef.current;
|
|
112
|
+
if (!(((_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.type) !== 'engine-load' || hasInitializedRef.current || isInitializingRef.current || !currentIframe || event.source !== currentIframe.contentWindow)) {
|
|
111
113
|
_context2.n = 1;
|
|
112
114
|
break;
|
|
113
115
|
}
|
|
114
116
|
return _context2.a(2);
|
|
115
117
|
case 1:
|
|
116
|
-
iframeWindow = (
|
|
118
|
+
iframeWindow = getIframeWindow();
|
|
117
119
|
engine = iframeWindow === null || iframeWindow === void 0 ? void 0 : iframeWindow.__FR_ENGINE__;
|
|
118
120
|
if (!(!iframeWindow || !engine)) {
|
|
119
121
|
_context2.n = 2;
|
|
@@ -129,6 +131,7 @@ var Design = function Design(props, ref) {
|
|
|
129
131
|
title: 'XRender'
|
|
130
132
|
}
|
|
131
133
|
}, restProps);
|
|
134
|
+
isInitializingRef.current = true;
|
|
132
135
|
_context2.p = 3;
|
|
133
136
|
_context2.n = 4;
|
|
134
137
|
return tryInitEngine(engine, initConfig);
|
|
@@ -142,14 +145,33 @@ var Design = function Design(props, ref) {
|
|
|
142
145
|
hasInitializedRef.current = false;
|
|
143
146
|
console.error('[schema-builder] engine init failed after retries', _t2);
|
|
144
147
|
case 6:
|
|
148
|
+
_context2.p = 6;
|
|
149
|
+
isInitializingRef.current = false;
|
|
150
|
+
return _context2.f(6);
|
|
151
|
+
case 7:
|
|
145
152
|
return _context2.a(2);
|
|
146
153
|
}
|
|
147
|
-
}, _callee2, null, [[3, 5]]);
|
|
154
|
+
}, _callee2, null, [[3, 5, 6, 7]]);
|
|
148
155
|
}));
|
|
149
156
|
return function engineOnLoad(_x3) {
|
|
150
157
|
return _ref2.apply(this, arguments);
|
|
151
158
|
};
|
|
152
159
|
}();
|
|
160
|
+
(0, _react.useEffect)(function () {
|
|
161
|
+
window.addEventListener('message', engineOnLoad);
|
|
162
|
+
initIframe();
|
|
163
|
+
return function () {
|
|
164
|
+
var _containerRef$current2;
|
|
165
|
+
window.removeEventListener('message', engineOnLoad);
|
|
166
|
+
hasInitializedRef.current = false;
|
|
167
|
+
isInitializingRef.current = false;
|
|
168
|
+
var currentIframe = iframeRef.current;
|
|
169
|
+
if (currentIframe && ((_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.contains(currentIframe))) {
|
|
170
|
+
containerRef.current.removeChild(currentIframe);
|
|
171
|
+
}
|
|
172
|
+
iframeRef.current = null;
|
|
173
|
+
};
|
|
174
|
+
}, []);
|
|
153
175
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
154
176
|
ref: containerRef,
|
|
155
177
|
style: {
|