@lvce-editor/iframe-worker 4.0.0 → 4.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.
@@ -948,9 +948,7 @@ const getWebViewUri = (webViews, webViewId) => {
948
948
  return webViewPath;
949
949
  };
950
950
 
951
- const WebView = 'lvce-oss-webview';
952
-
953
- const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform$1 = platform, assetDir) => {
951
+ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform$1 = platform, assetDir, webViewScheme) => {
954
952
  const webView = getWebView(webViews, webViewId);
955
953
  const webViewUri = getWebViewUri(webViews, webViewId);
956
954
  if (!webViewUri) {
@@ -963,7 +961,7 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
963
961
 
964
962
  if (platform$1 === Electron) {
965
963
  const relativePath = new URL(webViewUri).pathname.replace('/index.html', '');
966
- iframeSrc = `${WebView}://-${relativePath}/`;
964
+ iframeSrc = `${webViewScheme}://-${relativePath}/`;
967
965
  // TODO
968
966
  } else if (platform$1 === Remote) {
969
967
  webViewRoot = webView.uri;
@@ -1034,13 +1032,13 @@ const getIframeSrc$1 = (webView, locationOrigin, assetDir) => {
1034
1032
  return undefined;
1035
1033
  };
1036
1034
 
1037
- const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir) => {
1035
+ const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir, webViewScheme) => {
1038
1036
  try {
1039
1037
  const webView = getWebView(webViews, webViewId);
1040
1038
  if (platform === Web) {
1041
1039
  return getIframeSrc$1(webView, locationOrigin, assetDir);
1042
1040
  }
1043
- return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform, assetDir);
1041
+ return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform, assetDir, webViewScheme);
1044
1042
  } catch (error) {
1045
1043
  throw new VError(error, `Failed to construct webview iframe src`);
1046
1044
  }
@@ -1101,11 +1099,11 @@ const getWebViewFrameAncestors = (locationProtocol, locationHost) => {
1101
1099
  return frameAncestors;
1102
1100
  };
1103
1101
 
1104
- const getWebViewOrigin = (webViewPort, platform) => {
1102
+ const getWebViewOrigin = (webViewPort, platform, webViewScheme) => {
1105
1103
  // TODO don't hardcode protocol
1106
1104
  let origin = '';
1107
1105
  if (platform === Electron) {
1108
- origin = `${WebView}://-/`;
1106
+ origin = `${webViewScheme}://-/`;
1109
1107
  } else if (platform === Remote) {
1110
1108
  origin = `http://localhost:${webViewPort}`;
1111
1109
  } else {
@@ -1137,6 +1135,17 @@ const getIframeSandbox = (webView, platform) => {
1137
1135
  return [AllowScripts, AllowSameOrigin, ...extensionSandbox];
1138
1136
  };
1139
1137
 
1138
+ const getWebViewTitle = webView => {
1139
+ if (webView && webView.elements && Array.isArray(webView.elements)) {
1140
+ for (const item of webView.elements) {
1141
+ if (item && item.type === 'title' && typeof item.value === 'string') {
1142
+ return item.value;
1143
+ }
1144
+ }
1145
+ }
1146
+ return 'WebView';
1147
+ };
1148
+
1140
1149
  const state = {
1141
1150
  id: 0
1142
1151
  };
@@ -1161,6 +1170,8 @@ const invokeAndTransfer = async (method, ...params) => {
1161
1170
  return invokeAndTransfer$2('WebView.compatRendererProcessInvokeAndTransfer', method, ...params);
1162
1171
  };
1163
1172
 
1173
+ const WebView = 'lvce-oss-webview';
1174
+
1164
1175
  const setPort = async (uid, port, origin, portType) => {
1165
1176
  await invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
1166
1177
  };
@@ -1227,7 +1238,8 @@ const create2 = async ({
1227
1238
  uri,
1228
1239
  platform,
1229
1240
  isGitpod,
1230
- assetDir: assetDir$1 = assetDir
1241
+ assetDir: assetDir$1 = assetDir,
1242
+ webViewScheme = WebView
1231
1243
  }) => {
1232
1244
  let root = '';
1233
1245
  if (platform === Remote) {
@@ -1237,7 +1249,7 @@ const create2 = async ({
1237
1249
  const locationProtocol = getProtocol();
1238
1250
  const locationHost = getHost();
1239
1251
  const locationOrigin = getOrigin();
1240
- const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir$1);
1252
+ const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir$1, webViewScheme);
1241
1253
  if (!iframeResult) {
1242
1254
  return undefined;
1243
1255
  }
@@ -1251,7 +1263,7 @@ const create2 = async ({
1251
1263
  iframeContent
1252
1264
  } = iframeResult;
1253
1265
  const frameAncestors = getWebViewFrameAncestors(locationProtocol, locationHost);
1254
-
1266
+ const frameTitle = getWebViewTitle(webView);
1255
1267
  // TODO figure out order for events, e.g.
1256
1268
  // 1. activate extension, create webview and ports in parallel
1257
1269
  // 2. wait for webview to load (?)
@@ -1271,9 +1283,9 @@ const create2 = async ({
1271
1283
  } = getPortTuple();
1272
1284
  const portId = create$1();
1273
1285
  await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
1274
- await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString);
1286
+ await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
1275
1287
  await invoke$1('WebView.load', id);
1276
- const origin = getWebViewOrigin(webViewPort, platform);
1288
+ const origin = getWebViewOrigin(webViewPort, platform, webViewScheme);
1277
1289
  const portType = '';
1278
1290
  await setPort(id, port1, origin, portType);
1279
1291
  await invokeAndTransfer$1('ExtensionHostWebView.create', webViewId, port2, uri, id, origin);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "4.0.0",
3
+ "version": "4.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",