@lvce-editor/iframe-worker 3.1.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 +51 -54
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -834,6 +834,33 @@ const createLocalHostUrl = (locationProtocol, locationHost, isGitpod, webViewPor
|
|
|
834
834
|
return `http://localhost:${webViewPort}`;
|
|
835
835
|
};
|
|
836
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
|
+
|
|
837
864
|
const Web = 1;
|
|
838
865
|
const Electron = 2;
|
|
839
866
|
const Remote = 3;
|
|
@@ -869,46 +896,6 @@ const getPlatform = () => {
|
|
|
869
896
|
};
|
|
870
897
|
const platform = getPlatform();
|
|
871
898
|
|
|
872
|
-
const getAssetDir = () => {
|
|
873
|
-
// @ts-ignore
|
|
874
|
-
if (typeof ASSET_DIR !== 'undefined') {
|
|
875
|
-
// @ts-ignore
|
|
876
|
-
return ASSET_DIR;
|
|
877
|
-
}
|
|
878
|
-
if (platform === Electron) {
|
|
879
|
-
return '';
|
|
880
|
-
}
|
|
881
|
-
return '';
|
|
882
|
-
};
|
|
883
|
-
const assetDir = getAssetDir();
|
|
884
|
-
|
|
885
|
-
const getWebViewHtml = (baseUrl, locationOrigin, elements) => {
|
|
886
|
-
if (!elements) {
|
|
887
|
-
return '';
|
|
888
|
-
}
|
|
889
|
-
const middle = [];
|
|
890
|
-
middle.push('<meta charset="utf-8">');
|
|
891
|
-
for (const element of elements) {
|
|
892
|
-
if (element.type === 'title') {
|
|
893
|
-
middle.push(`<title>${element.value}</title>`);
|
|
894
|
-
} else if (element.type === 'script') {
|
|
895
|
-
middle.push(`<script type="module" src="${locationOrigin}${assetDir}/js/preview-injected.js"></script>`);
|
|
896
|
-
middle.push(`<script type="module" src="${locationOrigin}${baseUrl}/${element.path}"></script>`);
|
|
897
|
-
} else if (element.type === 'css') {
|
|
898
|
-
middle.push(`<link rel="stylesheet" href="${locationOrigin}${baseUrl}/${element.path}" />`);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
const middleHtml = middle.join('\n ');
|
|
902
|
-
const html = `<!DOCTYPE html>
|
|
903
|
-
<html>
|
|
904
|
-
<head>
|
|
905
|
-
${middleHtml}
|
|
906
|
-
</head>
|
|
907
|
-
</html>
|
|
908
|
-
`;
|
|
909
|
-
return html;
|
|
910
|
-
};
|
|
911
|
-
|
|
912
899
|
const WebView = 'lvce-oss-webview';
|
|
913
900
|
|
|
914
901
|
const getWebView$1 = (webViews, webViewId) => {
|
|
@@ -937,13 +924,9 @@ const getWebViewUri = (webViews, webViewId) => {
|
|
|
937
924
|
}
|
|
938
925
|
return webViewPath;
|
|
939
926
|
};
|
|
940
|
-
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) => {
|
|
941
928
|
const webView = getWebView$1(webViews, webViewId);
|
|
942
929
|
const webViewUri = getWebViewUri(webViews, webViewId);
|
|
943
|
-
console.log({
|
|
944
|
-
webViews,
|
|
945
|
-
webViewId
|
|
946
|
-
});
|
|
947
930
|
if (!webViewUri) {
|
|
948
931
|
return undefined;
|
|
949
932
|
}
|
|
@@ -963,7 +946,7 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
|
|
|
963
946
|
}
|
|
964
947
|
iframeSrc = createLocalHostUrl(locationProtocol, locationHost, isGitpod, webViewPort);
|
|
965
948
|
}
|
|
966
|
-
let iframeContent = getWebViewHtml('', '', webView.elements);
|
|
949
|
+
let iframeContent = getWebViewHtml('', '', webView.elements, assetDir);
|
|
967
950
|
// TODO either
|
|
968
951
|
// - load webviews the same as in web using blob urls
|
|
969
952
|
// - load webviews from a pattern like /webviews/:id/:fileName
|
|
@@ -1008,9 +991,9 @@ const getWebViewBaseUrl = webView => {
|
|
|
1008
991
|
return defaultBaseUrl;
|
|
1009
992
|
};
|
|
1010
993
|
|
|
1011
|
-
const getIframeSrc$1 = (webView, locationOrigin) => {
|
|
994
|
+
const getIframeSrc$1 = (webView, locationOrigin, assetDir) => {
|
|
1012
995
|
const baseUrl = getWebViewBaseUrl(webView);
|
|
1013
|
-
const srcHtml = getWebViewHtml(baseUrl, locationOrigin, webView.elements);
|
|
996
|
+
const srcHtml = getWebViewHtml(baseUrl, locationOrigin, webView.elements, assetDir);
|
|
1014
997
|
if (srcHtml) {
|
|
1015
998
|
const blobUrl = getBlobUrl(srcHtml, 'text/html');
|
|
1016
999
|
return {
|
|
@@ -1088,13 +1071,13 @@ class VError extends Error {
|
|
|
1088
1071
|
}
|
|
1089
1072
|
}
|
|
1090
1073
|
|
|
1091
|
-
const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform
|
|
1074
|
+
const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir) => {
|
|
1092
1075
|
try {
|
|
1093
1076
|
const webView = getWebView(webViews, webViewId);
|
|
1094
|
-
if (platform
|
|
1095
|
-
return getIframeSrc$1(webView, locationOrigin);
|
|
1077
|
+
if (platform === Web) {
|
|
1078
|
+
return getIframeSrc$1(webView, locationOrigin, assetDir);
|
|
1096
1079
|
}
|
|
1097
|
-
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root);
|
|
1080
|
+
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform, assetDir);
|
|
1098
1081
|
} catch (error) {
|
|
1099
1082
|
throw new VError(error, `Failed to construct webview iframe src`);
|
|
1100
1083
|
}
|
|
@@ -1218,6 +1201,19 @@ const invoke = async (method, ...params) => {
|
|
|
1218
1201
|
return invoke$3('WebView.compatSharedProcessInvoke', method, ...params);
|
|
1219
1202
|
};
|
|
1220
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
|
+
|
|
1221
1217
|
const registerProtocol = async () => {
|
|
1222
1218
|
await invoke('WebViewServer.registerProtocol');
|
|
1223
1219
|
};
|
|
@@ -1274,7 +1270,8 @@ const create2 = async ({
|
|
|
1274
1270
|
previewServerId,
|
|
1275
1271
|
uri,
|
|
1276
1272
|
platform,
|
|
1277
|
-
isGitpod
|
|
1273
|
+
isGitpod,
|
|
1274
|
+
assetDir: assetDir$1 = assetDir
|
|
1278
1275
|
}) => {
|
|
1279
1276
|
let root = '';
|
|
1280
1277
|
if (platform === Remote) {
|
|
@@ -1284,7 +1281,7 @@ const create2 = async ({
|
|
|
1284
1281
|
const locationProtocol = getProtocol();
|
|
1285
1282
|
const locationHost = getHost();
|
|
1286
1283
|
const locationOrigin = getOrigin();
|
|
1287
|
-
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);
|
|
1288
1285
|
if (!iframeResult) {
|
|
1289
1286
|
return undefined;
|
|
1290
1287
|
}
|