@lvce-editor/iframe-worker 5.7.0 → 5.9.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 +22 -15
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -893,6 +893,16 @@ const createLocalHostUrl = (locationProtocol, locationHost, isGitpod, webViewPor
|
|
|
893
893
|
return `http://localhost:${webViewPort}`;
|
|
894
894
|
};
|
|
895
895
|
|
|
896
|
+
const getIframeSrcRemoteBaseUrl = (webViewRoot, locationOrigin) => {
|
|
897
|
+
if (webViewRoot && (webViewRoot.startsWith('http:') || webViewRoot.startsWith('https:'))) {
|
|
898
|
+
if (webViewRoot.startsWith(locationOrigin)) {
|
|
899
|
+
return webViewRoot.slice(locationOrigin.length);
|
|
900
|
+
}
|
|
901
|
+
return webViewRoot;
|
|
902
|
+
}
|
|
903
|
+
return '';
|
|
904
|
+
};
|
|
905
|
+
|
|
896
906
|
const getWebView = (webViews, webViewId) => {
|
|
897
907
|
for (const webView of webViews) {
|
|
898
908
|
if (webView.id === webViewId) {
|
|
@@ -948,7 +958,7 @@ const getWebViewUri = (webViews, webViewId) => {
|
|
|
948
958
|
return webViewPath;
|
|
949
959
|
};
|
|
950
960
|
|
|
951
|
-
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform$1 = platform, assetDir, webViewScheme) => {
|
|
961
|
+
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationOrigin, locationHost, isGitpod, root, platform$1 = platform, assetDir, webViewScheme) => {
|
|
952
962
|
const webView = getWebView(webViews, webViewId);
|
|
953
963
|
const webViewUri = getWebViewUri(webViews, webViewId);
|
|
954
964
|
if (!webViewUri) {
|
|
@@ -965,12 +975,12 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
|
|
|
965
975
|
webViewRoot = webView.uri;
|
|
966
976
|
iframeSrc = createLocalHostUrl(locationProtocol, locationHost, isGitpod, webViewPort);
|
|
967
977
|
}
|
|
968
|
-
const
|
|
978
|
+
const baseUrl = getIframeSrcRemoteBaseUrl(webViewRoot, locationOrigin);
|
|
979
|
+
const iframeContent = getWebViewHtml(baseUrl, '', webView.elements, assetDir);
|
|
969
980
|
// TODO either
|
|
970
981
|
// - load webviews the same as in web using blob urls
|
|
971
982
|
// - load webviews from a pattern like /webviews/:id/:fileName
|
|
972
983
|
return {
|
|
973
|
-
srcDoc: '',
|
|
974
984
|
iframeSrc,
|
|
975
985
|
webViewRoot,
|
|
976
986
|
iframeContent
|
|
@@ -1019,7 +1029,6 @@ const getIframeSrc$1 = (webView, locationOrigin, assetDir) => {
|
|
|
1019
1029
|
if (srcHtml) {
|
|
1020
1030
|
const blobUrl = getBlobUrl(srcHtml, 'text/html');
|
|
1021
1031
|
return {
|
|
1022
|
-
srcDoc: '',
|
|
1023
1032
|
iframeSrc: blobUrl,
|
|
1024
1033
|
webViewRoot: '',
|
|
1025
1034
|
iframeContent: ''
|
|
@@ -1034,7 +1043,7 @@ const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, location
|
|
|
1034
1043
|
if (platform === Web) {
|
|
1035
1044
|
return getIframeSrc$1(webView, locationOrigin, assetDir);
|
|
1036
1045
|
}
|
|
1037
|
-
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform, assetDir, webViewScheme);
|
|
1046
|
+
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationOrigin, locationHost, isGitpod, root, platform, assetDir, webViewScheme);
|
|
1038
1047
|
} catch (error) {
|
|
1039
1048
|
throw new VError(error, `Failed to construct webview iframe src`);
|
|
1040
1049
|
}
|
|
@@ -1195,7 +1204,7 @@ const start = async (previewServerId, webViewPort) => {
|
|
|
1195
1204
|
const setInfo = async (previewServerId, webViewId, webViewRoot, contentSecurityPolicy, iframeContent) => {
|
|
1196
1205
|
await invoke('WebViewServer.setInfo', previewServerId, webViewId, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1197
1206
|
};
|
|
1198
|
-
const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent) => {
|
|
1207
|
+
const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent, remotePathPrefix) => {
|
|
1199
1208
|
await invoke('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1200
1209
|
};
|
|
1201
1210
|
|
|
@@ -1212,7 +1221,7 @@ const register$3 = async (previewServerId, webViewPort, frameAncestors, webViewR
|
|
|
1212
1221
|
await setInfo(previewServerId, webViewId, webViewRoot, csp, iframeContent);
|
|
1213
1222
|
};
|
|
1214
1223
|
|
|
1215
|
-
const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
|
|
1224
|
+
const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, remotePathPrefix) => {
|
|
1216
1225
|
// TODO apply something similar for electron
|
|
1217
1226
|
// TODO pass webview root, so that only these resources can be accessed
|
|
1218
1227
|
// TODO pass csp configuration to server
|
|
@@ -1239,9 +1248,9 @@ const getModule = platform => {
|
|
|
1239
1248
|
}
|
|
1240
1249
|
};
|
|
1241
1250
|
|
|
1242
|
-
const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId) => {
|
|
1251
|
+
const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix) => {
|
|
1243
1252
|
const fn = getModule(platform);
|
|
1244
|
-
return fn(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId);
|
|
1253
|
+
return fn(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId, remotePathPrefix);
|
|
1245
1254
|
};
|
|
1246
1255
|
|
|
1247
1256
|
const create2 = async ({
|
|
@@ -1273,7 +1282,6 @@ const create2 = async ({
|
|
|
1273
1282
|
const {
|
|
1274
1283
|
iframeSrc,
|
|
1275
1284
|
webViewRoot,
|
|
1276
|
-
srcDoc,
|
|
1277
1285
|
iframeContent
|
|
1278
1286
|
} = iframeResult;
|
|
1279
1287
|
const frameAncestors = getWebViewFrameAncestors(locationProtocol, locationHost);
|
|
@@ -1296,7 +1304,8 @@ const create2 = async ({
|
|
|
1296
1304
|
port2
|
|
1297
1305
|
} = getPortTuple();
|
|
1298
1306
|
const portId = create$1();
|
|
1299
|
-
|
|
1307
|
+
const remotePathPrefix = '/remote';
|
|
1308
|
+
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix);
|
|
1300
1309
|
await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
|
|
1301
1310
|
|
|
1302
1311
|
// TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
|
|
@@ -1310,7 +1319,6 @@ const create2 = async ({
|
|
|
1310
1319
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1311
1320
|
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1312
1321
|
return {
|
|
1313
|
-
srcDoc,
|
|
1314
1322
|
iframeSrc,
|
|
1315
1323
|
sandbox,
|
|
1316
1324
|
portId,
|
|
@@ -1377,7 +1385,6 @@ const create3 = async ({
|
|
|
1377
1385
|
const {
|
|
1378
1386
|
iframeSrc,
|
|
1379
1387
|
webViewRoot,
|
|
1380
|
-
srcDoc,
|
|
1381
1388
|
iframeContent
|
|
1382
1389
|
} = iframeResult;
|
|
1383
1390
|
const frameAncestors = getWebViewFrameAncestors(locationProtocol, locationHost);
|
|
@@ -1400,7 +1407,8 @@ const create3 = async ({
|
|
|
1400
1407
|
port2
|
|
1401
1408
|
} = getPortTuple();
|
|
1402
1409
|
const portId = create$1();
|
|
1403
|
-
|
|
1410
|
+
const remotePathPrefix = '/remote';
|
|
1411
|
+
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix);
|
|
1404
1412
|
await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
|
|
1405
1413
|
|
|
1406
1414
|
// TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
|
|
@@ -1414,7 +1422,6 @@ const create3 = async ({
|
|
|
1414
1422
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1415
1423
|
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1416
1424
|
return {
|
|
1417
|
-
srcDoc,
|
|
1418
1425
|
iframeSrc,
|
|
1419
1426
|
sandbox,
|
|
1420
1427
|
portId,
|