@lvce-editor/iframe-worker 3.0.0 → 3.2.0
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/dist/iframeWorkerMain.js +70 -56
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
const Two = '2.0';
|
|
2
|
+
const create$4 = (method, params) => {
|
|
3
|
+
return {
|
|
4
|
+
jsonrpc: Two,
|
|
5
|
+
method,
|
|
6
|
+
params
|
|
7
|
+
};
|
|
8
|
+
};
|
|
2
9
|
const state$2 = {
|
|
3
10
|
callbacks: Object.create(null)
|
|
4
11
|
};
|
|
@@ -230,7 +237,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
|
230
237
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
231
238
|
return create$1$2(message, errorProperty);
|
|
232
239
|
};
|
|
233
|
-
const create$
|
|
240
|
+
const create$5 = (message, result) => {
|
|
234
241
|
return {
|
|
235
242
|
jsonrpc: Two,
|
|
236
243
|
id: message.id,
|
|
@@ -239,7 +246,7 @@ const create$4 = (message, result) => {
|
|
|
239
246
|
};
|
|
240
247
|
const getSuccessResponse = (message, result) => {
|
|
241
248
|
const resultProperty = result ?? null;
|
|
242
|
-
return create$
|
|
249
|
+
return create$5(message, resultProperty);
|
|
243
250
|
};
|
|
244
251
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
245
252
|
try {
|
|
@@ -328,6 +335,10 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
328
335
|
const responseMessage = await promise;
|
|
329
336
|
return unwrapJsonRpcResult(responseMessage);
|
|
330
337
|
};
|
|
338
|
+
const send = (transport, method, ...params) => {
|
|
339
|
+
const message = create$4(method, params);
|
|
340
|
+
transport.send(message);
|
|
341
|
+
};
|
|
331
342
|
const invoke$4 = (ipc, method, ...params) => {
|
|
332
343
|
return invokeHelper(ipc, method, params, false);
|
|
333
344
|
};
|
|
@@ -735,6 +746,12 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
735
746
|
|
|
736
747
|
const createRpc = ipc => {
|
|
737
748
|
const rpc = {
|
|
749
|
+
/**
|
|
750
|
+
* @deprecated
|
|
751
|
+
*/
|
|
752
|
+
send(method, ...params) {
|
|
753
|
+
send(ipc, method, ...params);
|
|
754
|
+
},
|
|
738
755
|
invoke(method, ...params) {
|
|
739
756
|
return invoke$4(ipc, method, ...params);
|
|
740
757
|
},
|
|
@@ -817,6 +834,33 @@ const createLocalHostUrl = (locationProtocol, locationHost, isGitpod, webViewPor
|
|
|
817
834
|
return `http://localhost:${webViewPort}`;
|
|
818
835
|
};
|
|
819
836
|
|
|
837
|
+
const getWebViewHtml = (baseUrl, locationOrigin, elements, assetDir) => {
|
|
838
|
+
if (!elements) {
|
|
839
|
+
return '';
|
|
840
|
+
}
|
|
841
|
+
const middle = [];
|
|
842
|
+
middle.push('<meta charset="utf-8">');
|
|
843
|
+
for (const element of elements) {
|
|
844
|
+
if (element.type === 'title') {
|
|
845
|
+
middle.push(`<title>${element.value}</title>`);
|
|
846
|
+
} else if (element.type === 'script') {
|
|
847
|
+
middle.push(`<script type="module" src="${locationOrigin}${assetDir}/js/preview-injected.js"></script>`);
|
|
848
|
+
middle.push(`<script type="module" src="${locationOrigin}${baseUrl}/${element.path}"></script>`);
|
|
849
|
+
} else if (element.type === 'css') {
|
|
850
|
+
middle.push(`<link rel="stylesheet" href="${locationOrigin}${baseUrl}/${element.path}" />`);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
const middleHtml = middle.join('\n ');
|
|
854
|
+
const html = `<!DOCTYPE html>
|
|
855
|
+
<html>
|
|
856
|
+
<head>
|
|
857
|
+
${middleHtml}
|
|
858
|
+
</head>
|
|
859
|
+
</html>
|
|
860
|
+
`;
|
|
861
|
+
return html;
|
|
862
|
+
};
|
|
863
|
+
|
|
820
864
|
const Web = 1;
|
|
821
865
|
const Electron = 2;
|
|
822
866
|
const Remote = 3;
|
|
@@ -852,46 +896,6 @@ const getPlatform = () => {
|
|
|
852
896
|
};
|
|
853
897
|
const platform = getPlatform();
|
|
854
898
|
|
|
855
|
-
const getAssetDir = () => {
|
|
856
|
-
// @ts-ignore
|
|
857
|
-
if (typeof ASSET_DIR !== 'undefined') {
|
|
858
|
-
// @ts-ignore
|
|
859
|
-
return ASSET_DIR;
|
|
860
|
-
}
|
|
861
|
-
if (platform === Electron) {
|
|
862
|
-
return '';
|
|
863
|
-
}
|
|
864
|
-
return '';
|
|
865
|
-
};
|
|
866
|
-
const assetDir = getAssetDir();
|
|
867
|
-
|
|
868
|
-
const getWebViewHtml = (baseUrl, locationOrigin, elements) => {
|
|
869
|
-
if (!elements) {
|
|
870
|
-
return '';
|
|
871
|
-
}
|
|
872
|
-
const middle = [];
|
|
873
|
-
middle.push('<meta charset="utf-8">');
|
|
874
|
-
for (const element of elements) {
|
|
875
|
-
if (element.type === 'title') {
|
|
876
|
-
middle.push(`<title>${element.value}</title>`);
|
|
877
|
-
} else if (element.type === 'script') {
|
|
878
|
-
middle.push(`<script type="module" src="${locationOrigin}${assetDir}/js/preview-injected.js"></script>`);
|
|
879
|
-
middle.push(`<script type="module" src="${locationOrigin}${baseUrl}/${element.path}"></script>`);
|
|
880
|
-
} else if (element.type === 'css') {
|
|
881
|
-
middle.push(`<link rel="stylesheet" href="${locationOrigin}${baseUrl}/${element.path}" />`);
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
const middleHtml = middle.join('\n ');
|
|
885
|
-
const html = `<!DOCTYPE html>
|
|
886
|
-
<html>
|
|
887
|
-
<head>
|
|
888
|
-
${middleHtml}
|
|
889
|
-
</head>
|
|
890
|
-
</html>
|
|
891
|
-
`;
|
|
892
|
-
return html;
|
|
893
|
-
};
|
|
894
|
-
|
|
895
899
|
const WebView = 'lvce-oss-webview';
|
|
896
900
|
|
|
897
901
|
const getWebView$1 = (webViews, webViewId) => {
|
|
@@ -920,13 +924,9 @@ const getWebViewUri = (webViews, webViewId) => {
|
|
|
920
924
|
}
|
|
921
925
|
return webViewPath;
|
|
922
926
|
};
|
|
923
|
-
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform$1 = platform) => {
|
|
927
|
+
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform$1 = platform, assetDir) => {
|
|
924
928
|
const webView = getWebView$1(webViews, webViewId);
|
|
925
929
|
const webViewUri = getWebViewUri(webViews, webViewId);
|
|
926
|
-
console.log({
|
|
927
|
-
webViews,
|
|
928
|
-
webViewId
|
|
929
|
-
});
|
|
930
930
|
if (!webViewUri) {
|
|
931
931
|
return undefined;
|
|
932
932
|
}
|
|
@@ -946,7 +946,7 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
|
|
|
946
946
|
}
|
|
947
947
|
iframeSrc = createLocalHostUrl(locationProtocol, locationHost, isGitpod, webViewPort);
|
|
948
948
|
}
|
|
949
|
-
let iframeContent = getWebViewHtml('', '', webView.elements);
|
|
949
|
+
let iframeContent = getWebViewHtml('', '', webView.elements, assetDir);
|
|
950
950
|
// TODO either
|
|
951
951
|
// - load webviews the same as in web using blob urls
|
|
952
952
|
// - load webviews from a pattern like /webviews/:id/:fileName
|
|
@@ -991,9 +991,9 @@ const getWebViewBaseUrl = webView => {
|
|
|
991
991
|
return defaultBaseUrl;
|
|
992
992
|
};
|
|
993
993
|
|
|
994
|
-
const getIframeSrc$1 = (webView, locationOrigin) => {
|
|
994
|
+
const getIframeSrc$1 = (webView, locationOrigin, assetDir) => {
|
|
995
995
|
const baseUrl = getWebViewBaseUrl(webView);
|
|
996
|
-
const srcHtml = getWebViewHtml(baseUrl, locationOrigin, webView.elements);
|
|
996
|
+
const srcHtml = getWebViewHtml(baseUrl, locationOrigin, webView.elements, assetDir);
|
|
997
997
|
if (srcHtml) {
|
|
998
998
|
const blobUrl = getBlobUrl(srcHtml, 'text/html');
|
|
999
999
|
return {
|
|
@@ -1071,13 +1071,13 @@ class VError extends Error {
|
|
|
1071
1071
|
}
|
|
1072
1072
|
}
|
|
1073
1073
|
|
|
1074
|
-
const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform
|
|
1074
|
+
const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir) => {
|
|
1075
1075
|
try {
|
|
1076
1076
|
const webView = getWebView(webViews, webViewId);
|
|
1077
|
-
if (platform
|
|
1078
|
-
return getIframeSrc$1(webView, locationOrigin);
|
|
1077
|
+
if (platform === Web) {
|
|
1078
|
+
return getIframeSrc$1(webView, locationOrigin, assetDir);
|
|
1079
1079
|
}
|
|
1080
|
-
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root);
|
|
1080
|
+
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform, assetDir);
|
|
1081
1081
|
} catch (error) {
|
|
1082
1082
|
throw new VError(error, `Failed to construct webview iframe src`);
|
|
1083
1083
|
}
|
|
@@ -1201,6 +1201,19 @@ const invoke = async (method, ...params) => {
|
|
|
1201
1201
|
return invoke$3('WebView.compatSharedProcessInvoke', method, ...params);
|
|
1202
1202
|
};
|
|
1203
1203
|
|
|
1204
|
+
const getAssetDir = () => {
|
|
1205
|
+
// @ts-ignore
|
|
1206
|
+
if (typeof ASSET_DIR !== 'undefined') {
|
|
1207
|
+
// @ts-ignore
|
|
1208
|
+
return ASSET_DIR;
|
|
1209
|
+
}
|
|
1210
|
+
if (platform === Electron) {
|
|
1211
|
+
return '';
|
|
1212
|
+
}
|
|
1213
|
+
return '';
|
|
1214
|
+
};
|
|
1215
|
+
const assetDir = getAssetDir();
|
|
1216
|
+
|
|
1204
1217
|
const registerProtocol = async () => {
|
|
1205
1218
|
await invoke('WebViewServer.registerProtocol');
|
|
1206
1219
|
};
|
|
@@ -1257,7 +1270,8 @@ const create2 = async ({
|
|
|
1257
1270
|
previewServerId,
|
|
1258
1271
|
uri,
|
|
1259
1272
|
platform,
|
|
1260
|
-
isGitpod
|
|
1273
|
+
isGitpod,
|
|
1274
|
+
assetDir: assetDir$1 = assetDir
|
|
1261
1275
|
}) => {
|
|
1262
1276
|
let root = '';
|
|
1263
1277
|
if (platform === Remote) {
|
|
@@ -1267,7 +1281,7 @@ const create2 = async ({
|
|
|
1267
1281
|
const locationProtocol = getProtocol();
|
|
1268
1282
|
const locationHost = getHost();
|
|
1269
1283
|
const locationOrigin = getOrigin();
|
|
1270
|
-
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform);
|
|
1284
|
+
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir$1);
|
|
1271
1285
|
if (!iframeResult) {
|
|
1272
1286
|
return undefined;
|
|
1273
1287
|
}
|