@zzdadelu/schema-builder 1.0.1-alpha.2 → 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 +42 -21
- package/lib/main.js +42 -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);
|
|
@@ -66,47 +65,49 @@ var Design = function Design(props, ref) {
|
|
|
66
65
|
var widgets = props.widgets,
|
|
67
66
|
settings = props.settings,
|
|
68
67
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
69
|
-
var containerRef = useRef();
|
|
68
|
+
var containerRef = useRef(null);
|
|
69
|
+
var iframeRef = useRef(null);
|
|
70
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
|
+
};
|
|
71
76
|
useImperativeHandle(ref, function () {
|
|
72
77
|
return {
|
|
73
78
|
getValue: function getValue() {
|
|
74
|
-
var
|
|
75
|
-
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);
|
|
76
81
|
},
|
|
77
82
|
setValue: function setValue(schema) {
|
|
78
|
-
var
|
|
79
|
-
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);
|
|
80
85
|
}
|
|
81
86
|
};
|
|
82
87
|
});
|
|
83
|
-
useEffect(function () {
|
|
84
|
-
initIframe();
|
|
85
|
-
window.addEventListener('message', engineOnLoad);
|
|
86
|
-
return function () {
|
|
87
|
-
window.removeEventListener('message', engineOnLoad);
|
|
88
|
-
hasInitializedRef.current = false;
|
|
89
|
-
};
|
|
90
|
-
}, []);
|
|
91
88
|
var initIframe = function initIframe() {
|
|
92
|
-
|
|
89
|
+
var _containerRef$current;
|
|
90
|
+
var nextIframe = createIframe();
|
|
93
91
|
hasInitializedRef.current = false;
|
|
94
|
-
|
|
92
|
+
isInitializingRef.current = false;
|
|
93
|
+
iframeRef.current = nextIframe;
|
|
94
|
+
(_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.appendChild(nextIframe);
|
|
95
95
|
};
|
|
96
96
|
var engineOnLoad = /*#__PURE__*/function () {
|
|
97
97
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(event) {
|
|
98
|
-
var
|
|
99
|
-
var iframeWindow, engine, initConfig, _t2;
|
|
98
|
+
var _event$data;
|
|
99
|
+
var currentIframe, iframeWindow, engine, initConfig, _t2;
|
|
100
100
|
return _regenerator().w(function (_context2) {
|
|
101
101
|
while (1) switch (_context2.p = _context2.n) {
|
|
102
102
|
case 0:
|
|
103
|
-
|
|
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)) {
|
|
104
105
|
_context2.n = 1;
|
|
105
106
|
break;
|
|
106
107
|
}
|
|
107
108
|
return _context2.a(2);
|
|
108
109
|
case 1:
|
|
109
|
-
iframeWindow = (
|
|
110
|
+
iframeWindow = getIframeWindow();
|
|
110
111
|
engine = iframeWindow === null || iframeWindow === void 0 ? void 0 : iframeWindow.__FR_ENGINE__;
|
|
111
112
|
if (!(!iframeWindow || !engine)) {
|
|
112
113
|
_context2.n = 2;
|
|
@@ -122,6 +123,7 @@ var Design = function Design(props, ref) {
|
|
|
122
123
|
title: 'XRender'
|
|
123
124
|
}
|
|
124
125
|
}, restProps);
|
|
126
|
+
isInitializingRef.current = true;
|
|
125
127
|
_context2.p = 3;
|
|
126
128
|
_context2.n = 4;
|
|
127
129
|
return tryInitEngine(engine, initConfig);
|
|
@@ -135,14 +137,33 @@ var Design = function Design(props, ref) {
|
|
|
135
137
|
hasInitializedRef.current = false;
|
|
136
138
|
console.error('[schema-builder] engine init failed after retries', _t2);
|
|
137
139
|
case 6:
|
|
140
|
+
_context2.p = 6;
|
|
141
|
+
isInitializingRef.current = false;
|
|
142
|
+
return _context2.f(6);
|
|
143
|
+
case 7:
|
|
138
144
|
return _context2.a(2);
|
|
139
145
|
}
|
|
140
|
-
}, _callee2, null, [[3, 5]]);
|
|
146
|
+
}, _callee2, null, [[3, 5, 6, 7]]);
|
|
141
147
|
}));
|
|
142
148
|
return function engineOnLoad(_x3) {
|
|
143
149
|
return _ref2.apply(this, arguments);
|
|
144
150
|
};
|
|
145
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
|
+
}, []);
|
|
146
167
|
return /*#__PURE__*/React.createElement("div", {
|
|
147
168
|
ref: containerRef,
|
|
148
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);
|
|
@@ -74,47 +73,49 @@ var Design = function Design(props, ref) {
|
|
|
74
73
|
var widgets = props.widgets,
|
|
75
74
|
settings = props.settings,
|
|
76
75
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
77
|
-
var containerRef = (0, _react.useRef)();
|
|
76
|
+
var containerRef = (0, _react.useRef)(null);
|
|
77
|
+
var iframeRef = (0, _react.useRef)(null);
|
|
78
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
|
+
};
|
|
79
84
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
80
85
|
return {
|
|
81
86
|
getValue: function getValue() {
|
|
82
|
-
var
|
|
83
|
-
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);
|
|
84
89
|
},
|
|
85
90
|
setValue: function setValue(schema) {
|
|
86
|
-
var
|
|
87
|
-
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);
|
|
88
93
|
}
|
|
89
94
|
};
|
|
90
95
|
});
|
|
91
|
-
(0, _react.useEffect)(function () {
|
|
92
|
-
initIframe();
|
|
93
|
-
window.addEventListener('message', engineOnLoad);
|
|
94
|
-
return function () {
|
|
95
|
-
window.removeEventListener('message', engineOnLoad);
|
|
96
|
-
hasInitializedRef.current = false;
|
|
97
|
-
};
|
|
98
|
-
}, []);
|
|
99
96
|
var initIframe = function initIframe() {
|
|
100
|
-
|
|
97
|
+
var _containerRef$current;
|
|
98
|
+
var nextIframe = (0, _createIframe.default)();
|
|
101
99
|
hasInitializedRef.current = false;
|
|
102
|
-
|
|
100
|
+
isInitializingRef.current = false;
|
|
101
|
+
iframeRef.current = nextIframe;
|
|
102
|
+
(_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.appendChild(nextIframe);
|
|
103
103
|
};
|
|
104
104
|
var engineOnLoad = /*#__PURE__*/function () {
|
|
105
105
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(event) {
|
|
106
|
-
var
|
|
107
|
-
var iframeWindow, engine, initConfig, _t2;
|
|
106
|
+
var _event$data;
|
|
107
|
+
var currentIframe, iframeWindow, engine, initConfig, _t2;
|
|
108
108
|
return _regenerator().w(function (_context2) {
|
|
109
109
|
while (1) switch (_context2.p = _context2.n) {
|
|
110
110
|
case 0:
|
|
111
|
-
|
|
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)) {
|
|
112
113
|
_context2.n = 1;
|
|
113
114
|
break;
|
|
114
115
|
}
|
|
115
116
|
return _context2.a(2);
|
|
116
117
|
case 1:
|
|
117
|
-
iframeWindow = (
|
|
118
|
+
iframeWindow = getIframeWindow();
|
|
118
119
|
engine = iframeWindow === null || iframeWindow === void 0 ? void 0 : iframeWindow.__FR_ENGINE__;
|
|
119
120
|
if (!(!iframeWindow || !engine)) {
|
|
120
121
|
_context2.n = 2;
|
|
@@ -130,6 +131,7 @@ var Design = function Design(props, ref) {
|
|
|
130
131
|
title: 'XRender'
|
|
131
132
|
}
|
|
132
133
|
}, restProps);
|
|
134
|
+
isInitializingRef.current = true;
|
|
133
135
|
_context2.p = 3;
|
|
134
136
|
_context2.n = 4;
|
|
135
137
|
return tryInitEngine(engine, initConfig);
|
|
@@ -143,14 +145,33 @@ var Design = function Design(props, ref) {
|
|
|
143
145
|
hasInitializedRef.current = false;
|
|
144
146
|
console.error('[schema-builder] engine init failed after retries', _t2);
|
|
145
147
|
case 6:
|
|
148
|
+
_context2.p = 6;
|
|
149
|
+
isInitializingRef.current = false;
|
|
150
|
+
return _context2.f(6);
|
|
151
|
+
case 7:
|
|
146
152
|
return _context2.a(2);
|
|
147
153
|
}
|
|
148
|
-
}, _callee2, null, [[3, 5]]);
|
|
154
|
+
}, _callee2, null, [[3, 5, 6, 7]]);
|
|
149
155
|
}));
|
|
150
156
|
return function engineOnLoad(_x3) {
|
|
151
157
|
return _ref2.apply(this, arguments);
|
|
152
158
|
};
|
|
153
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
|
+
}, []);
|
|
154
175
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
155
176
|
ref: containerRef,
|
|
156
177
|
style: {
|