@lvce-editor/iframe-worker 5.8.0 → 5.10.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.
@@ -886,20 +886,27 @@ const createUrl = (protocol, host) => {
886
886
  return protocol + '//' + host;
887
887
  };
888
888
 
889
- const createLocalHostUrl = (locationProtocol, locationHost, isGitpod, webViewPort) => {
889
+ const createLocalHostUrl = (locationProtocol, locationHost, isGitpod, webViewPort, webViewId, useNewWebViewHandler) => {
890
890
  if (isGitpod) {
891
891
  return createUrl(locationProtocol, locationHost.replace('3000', `${webViewPort}`));
892
892
  }
893
+ if (useNewWebViewHandler) {
894
+ return `http://localhost:${webViewPort}/${webViewId}`;
895
+ }
893
896
  return `http://localhost:${webViewPort}`;
894
897
  };
895
898
 
896
- const getIframeSrcRemoteBaseUrl = (webViewRoot, locationOrigin) => {
899
+ const getIframeSrcRemoteBaseUrl = (webViewRoot, locationOrigin, platform, webViewId, useNewWebViewHandler) => {
897
900
  if (webViewRoot && (webViewRoot.startsWith('http:') || webViewRoot.startsWith('https:'))) {
898
901
  if (webViewRoot.startsWith(locationOrigin)) {
899
- return webViewRoot.slice(locationOrigin.length);
902
+ const baseUrl = webViewRoot.slice(locationOrigin.length);
903
+ return baseUrl;
900
904
  }
901
905
  return webViewRoot;
902
906
  }
907
+ if (platform === Remote && useNewWebViewHandler && webViewId) {
908
+ return `/${webViewId}`;
909
+ }
903
910
  return '';
904
911
  };
905
912
 
@@ -958,7 +965,7 @@ const getWebViewUri = (webViews, webViewId) => {
958
965
  return webViewPath;
959
966
  };
960
967
 
961
- const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationOrigin, locationHost, isGitpod, root, platform$1 = platform, assetDir, webViewScheme) => {
968
+ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationOrigin, locationHost, isGitpod, root, platform$1 = platform, assetDir, webViewScheme, useNewWebViewHandler) => {
962
969
  const webView = getWebView(webViews, webViewId);
963
970
  const webViewUri = getWebViewUri(webViews, webViewId);
964
971
  if (!webViewUri) {
@@ -973,9 +980,9 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
973
980
  iframeSrc = `${webViewScheme}://${webViewId}`;
974
981
  } else if (platform$1 === Remote) {
975
982
  webViewRoot = webView.uri;
976
- iframeSrc = createLocalHostUrl(locationProtocol, locationHost, isGitpod, webViewPort);
983
+ iframeSrc = createLocalHostUrl(locationProtocol, locationHost, isGitpod, webViewPort, webViewId, useNewWebViewHandler);
977
984
  }
978
- const baseUrl = getIframeSrcRemoteBaseUrl(webViewRoot, locationOrigin);
985
+ const baseUrl = getIframeSrcRemoteBaseUrl(webViewRoot, locationOrigin, platform$1, webViewId, useNewWebViewHandler);
979
986
  const iframeContent = getWebViewHtml(baseUrl, '', webView.elements, assetDir);
980
987
  // TODO either
981
988
  // - load webviews the same as in web using blob urls
@@ -1037,13 +1044,13 @@ const getIframeSrc$1 = (webView, locationOrigin, assetDir) => {
1037
1044
  return undefined;
1038
1045
  };
1039
1046
 
1040
- const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir, webViewScheme) => {
1047
+ const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir, webViewScheme, useNewWebViewHandler) => {
1041
1048
  try {
1042
1049
  const webView = getWebView(webViews, webViewId);
1043
1050
  if (platform === Web) {
1044
1051
  return getIframeSrc$1(webView, locationOrigin, assetDir);
1045
1052
  }
1046
- return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationOrigin, locationHost, isGitpod, root, platform, assetDir, webViewScheme);
1053
+ return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationOrigin, locationHost, isGitpod, root, platform, assetDir, webViewScheme, useNewWebViewHandler);
1047
1054
  } catch (error) {
1048
1055
  throw new VError(error, `Failed to construct webview iframe src`);
1049
1056
  }
@@ -1195,22 +1202,25 @@ const invoke = async (method, ...params) => {
1195
1202
  const registerProtocol = async () => {
1196
1203
  await invoke('WebViewServer.registerProtocol');
1197
1204
  };
1198
- const create = async previewServerId => {
1199
- await invoke('WebViewServer.create', previewServerId);
1205
+ const create = async (previewServerId, useNewWebViewHandler) => {
1206
+ await invoke('WebViewServer.create', previewServerId, useNewWebViewHandler);
1200
1207
  };
1201
1208
  const start = async (previewServerId, webViewPort) => {
1202
1209
  await invoke('WebViewServer.start', previewServerId, webViewPort);
1203
1210
  };
1211
+ const setInfo2 = async info => {
1212
+ await invoke('WebViewServer.setInfo2', info);
1213
+ };
1204
1214
  const setInfo = async (previewServerId, webViewId, webViewRoot, contentSecurityPolicy, iframeContent) => {
1205
1215
  await invoke('WebViewServer.setInfo', previewServerId, webViewId, webViewRoot, contentSecurityPolicy, iframeContent);
1206
1216
  };
1207
- const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent) => {
1217
+ const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent, remotePathPrefix) => {
1208
1218
  await invoke('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
1209
1219
  };
1210
1220
 
1211
- const register$3 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId) => {
1221
+ const register$3 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId, remotePathPrefix, useNewWebViewHandler) => {
1212
1222
  await registerProtocol();
1213
- await create(previewServerId); // TODO move this up
1223
+ await create(previewServerId, useNewWebViewHandler); // TODO move this up
1214
1224
 
1215
1225
  // TODO send info to electron which domain maps to which webview root.
1216
1226
  // for example, video-preview maps to domain lvce-oss-webview://video-preview
@@ -1221,14 +1231,24 @@ const register$3 = async (previewServerId, webViewPort, frameAncestors, webViewR
1221
1231
  await setInfo(previewServerId, webViewId, webViewRoot, csp, iframeContent);
1222
1232
  };
1223
1233
 
1224
- const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
1234
+ const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId, remotePathPrefix, useNewWebViewHandler) => {
1225
1235
  // TODO apply something similar for electron
1226
1236
  // TODO pass webview root, so that only these resources can be accessed
1227
1237
  // TODO pass csp configuration to server
1228
1238
  // TODO pass coop / coep configuration to server
1229
- await create(previewServerId); // TODO move this up
1239
+ await create(previewServerId, useNewWebViewHandler); // TODO move this up
1230
1240
  await start(previewServerId, webViewPort); // TODO move this up
1231
- await setHandler(previewServerId, frameAncestors, webViewRoot, csp, iframeContent);
1241
+ if (useNewWebViewHandler) {
1242
+ await setInfo2({
1243
+ webViewRoot,
1244
+ webViewId,
1245
+ contentSecurityPolicy: csp,
1246
+ iframeContent,
1247
+ remotePathPrefix
1248
+ });
1249
+ } else {
1250
+ await setHandler(previewServerId, frameAncestors, webViewRoot, csp, iframeContent);
1251
+ }
1232
1252
  // TODO make this work in gitpod also
1233
1253
  };
1234
1254
 
@@ -1248,9 +1268,9 @@ const getModule = platform => {
1248
1268
  }
1249
1269
  };
1250
1270
 
1251
- const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId) => {
1271
+ const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix, useNewWebViewHandler) => {
1252
1272
  const fn = getModule(platform);
1253
- return fn(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId);
1273
+ return fn(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId, remotePathPrefix, useNewWebViewHandler);
1254
1274
  };
1255
1275
 
1256
1276
  const create2 = async ({
@@ -1272,7 +1292,7 @@ const create2 = async ({
1272
1292
  const locationProtocol = getProtocol();
1273
1293
  const locationHost = getHost();
1274
1294
  const locationOrigin = getOrigin();
1275
- const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir$1, webViewScheme);
1295
+ const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir$1, webViewScheme, false);
1276
1296
  if (!iframeResult) {
1277
1297
  return undefined;
1278
1298
  }
@@ -1304,7 +1324,8 @@ const create2 = async ({
1304
1324
  port2
1305
1325
  } = getPortTuple();
1306
1326
  const portId = create$1();
1307
- await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId);
1327
+ const remotePathPrefix = '/remote';
1328
+ await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix);
1308
1329
  await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
1309
1330
 
1310
1331
  // TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
@@ -1360,7 +1381,8 @@ const create3 = async ({
1360
1381
  isGitpod,
1361
1382
  platform,
1362
1383
  assetDir,
1363
- webViewScheme
1384
+ webViewScheme,
1385
+ useNewWebViewHandler
1364
1386
  }) => {
1365
1387
  let root = '';
1366
1388
  if (platform === Remote) {
@@ -1374,7 +1396,7 @@ const create3 = async ({
1374
1396
  const locationPort = getPort();
1375
1397
  const webViewPort = getWebViewPort(platform, locationPort);
1376
1398
  const previewServerId = getPreviewServerId();
1377
- const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir, webViewScheme);
1399
+ const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir, webViewScheme, useNewWebViewHandler || false);
1378
1400
  if (!iframeResult) {
1379
1401
  return undefined;
1380
1402
  }
@@ -1406,7 +1428,8 @@ const create3 = async ({
1406
1428
  port2
1407
1429
  } = getPortTuple();
1408
1430
  const portId = create$1();
1409
- await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId);
1431
+ const remotePathPrefix = '/remote';
1432
+ await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix, useNewWebViewHandler);
1410
1433
  await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
1411
1434
 
1412
1435
  // TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "5.8.0",
3
+ "version": "5.10.0",
4
4
  "description": "Web Worker to manage creation and lifecycle of iframes in Lvce Editor",
5
5
  "main": "dist/iframeWorkerMain.js",
6
6
  "type": "module",