@lvce-editor/iframe-worker 4.1.0 → 5.1.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.
@@ -957,23 +957,18 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
957
957
  let iframeSrc = webViewUri;
958
958
  let webViewRoot = webViewUri;
959
959
 
960
- // TODO simplify path handling, always use uris so that paths on windows, linux and macos are the same
961
-
960
+ // TODO when running in remote, try scope webviews by path or if possible by domain
962
961
  if (platform$1 === Electron) {
963
- const relativePath = new URL(webViewUri).pathname.replace('/index.html', '');
964
- iframeSrc = `${webViewScheme}://-${relativePath}/`;
965
- // TODO
962
+ const webViewId = webView.id;
963
+ iframeSrc = `${webViewScheme}://${webViewId}/`;
966
964
  } else if (platform$1 === Remote) {
967
965
  webViewRoot = webView.uri;
968
966
  iframeSrc = createLocalHostUrl(locationProtocol, locationHost, isGitpod, webViewPort);
969
967
  }
970
- let iframeContent = getWebViewHtml('', '', webView.elements, assetDir);
968
+ const iframeContent = getWebViewHtml('', '', webView.elements, assetDir);
971
969
  // TODO either
972
970
  // - load webviews the same as in web using blob urls
973
971
  // - load webviews from a pattern like /webviews/:id/:fileName
974
- if (!webView.path) {
975
- iframeContent = iframeContent.replaceAll('/media/', '/').replaceAll('//', '/');
976
- }
977
972
  return {
978
973
  srcDoc: '',
979
974
  iframeSrc,
@@ -1189,13 +1184,24 @@ const create = async previewServerId => {
1189
1184
  const start = async (previewServerId, webViewPort) => {
1190
1185
  await invoke('WebViewServer.start', previewServerId, webViewPort);
1191
1186
  };
1187
+ const setInfo = async (previewServerId, webViewId, webViewRoot) => {
1188
+ await invoke('WebViewServer.setInfo', previewServerId, webViewId, webViewRoot);
1189
+ };
1192
1190
  const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent) => {
1193
1191
  await invoke('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
1194
1192
  };
1195
1193
 
1196
- const register$3 = async previewServerId => {
1194
+ const register$3 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId) => {
1197
1195
  await registerProtocol();
1198
1196
  await create(previewServerId); // TODO move this up
1197
+
1198
+ // TODO send info to electron which domain maps to which webview root.
1199
+ // for example, video-preview maps to domain lvce-oss-webview://video-preview
1200
+ // and webview root /home/user/lvce/extensions/video-preview
1201
+ // Then the request handler can decide by domain which webview root to use.
1202
+ // Another option would be in electron to check what iframe (webContents)
1203
+ // responds to which webviewRoot and setting a webviewRoot per webContents instance
1204
+ await setInfo(previewServerId, webViewId, webViewRoot);
1199
1205
  };
1200
1206
 
1201
1207
  const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
@@ -1225,9 +1231,9 @@ const getModule = platform => {
1225
1231
  }
1226
1232
  };
1227
1233
 
1228
- const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
1234
+ const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId) => {
1229
1235
  const fn = getModule(platform);
1230
- return fn(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
1236
+ return fn(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId);
1231
1237
  };
1232
1238
 
1233
1239
  const create2 = async ({
@@ -1282,7 +1288,7 @@ const create2 = async ({
1282
1288
  port2
1283
1289
  } = getPortTuple();
1284
1290
  const portId = create$1();
1285
- await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
1291
+ await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId);
1286
1292
  await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
1287
1293
  await invoke$1('WebView.load', id);
1288
1294
  const origin = getWebViewOrigin(webViewPort, platform, webViewScheme);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "4.1.0",
3
+ "version": "5.1.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",