@lvce-editor/iframe-worker 5.35.0 → 5.36.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.
@@ -1397,19 +1397,18 @@ const getWebViewHtml = (baseUrl, locationOrigin, elements, assetDir) => {
1397
1397
  if (!elements) {
1398
1398
  return '';
1399
1399
  }
1400
- const middle = [];
1401
- middle.push('<meta charset="utf-8">');
1400
+ const middle = ['<meta charset="utf-8">'];
1402
1401
  for (const element of elements) {
1403
1402
  switch (element.type) {
1404
- case 'title':
1405
- middle.push(`<title>${element.value}</title>`);
1403
+ case 'css':
1404
+ middle.push(`<link rel="stylesheet" href="${locationOrigin}${baseUrl}/${element.path}" />`);
1406
1405
  break;
1407
1406
  case 'script':
1408
1407
  middle.push(`<script type="module" src="${locationOrigin}${assetDir}/js/preview-injected.js"></script>`);
1409
1408
  middle.push(`<script type="module" src="${locationOrigin}${baseUrl}/${element.path}"></script>`);
1410
1409
  break;
1411
- case 'css':
1412
- middle.push(`<link rel="stylesheet" href="${locationOrigin}${baseUrl}/${element.path}" />`);
1410
+ case 'title':
1411
+ middle.push(`<title>${element.value}</title>`);
1413
1412
  break;
1414
1413
  }
1415
1414
  }
@@ -1469,9 +1468,9 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
1469
1468
  // - load webviews the same as in web using blob urls
1470
1469
  // - load webviews from a pattern like /webviews/:id/:fileName
1471
1470
  return {
1471
+ iframeContent,
1472
1472
  iframeSrc,
1473
- webViewRoot,
1474
- iframeContent
1473
+ webViewRoot
1475
1474
  };
1476
1475
  };
1477
1476
 
@@ -1485,8 +1484,8 @@ const getBlobUrl = (content, contentType) => {
1485
1484
 
1486
1485
  const getDefaultBaseUrl = webView => {
1487
1486
  const {
1488
- remotePath,
1489
- path
1487
+ path,
1488
+ remotePath
1490
1489
  } = webView;
1491
1490
  if (remotePath) {
1492
1491
  if (remotePath.endsWith('/index.html')) {
@@ -1517,9 +1516,9 @@ const getIframeSrc$1 = (webView, locationOrigin, assetDir) => {
1517
1516
  if (srcHtml) {
1518
1517
  const blobUrl = getBlobUrl(srcHtml, 'text/html');
1519
1518
  return {
1519
+ iframeContent: '',
1520
1520
  iframeSrc: blobUrl,
1521
- webViewRoot: '',
1522
- iframeContent: ''
1521
+ webViewRoot: ''
1523
1522
  };
1524
1523
  }
1525
1524
  return undefined;
@@ -1728,11 +1727,11 @@ const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewR
1728
1727
  await create(previewServerId, useNewWebViewHandler); // TODO move this up
1729
1728
  await start(previewServerId, webViewPort); // TODO move this up
1730
1729
  await (useNewWebViewHandler ? setInfo2({
1731
- webViewRoot,
1732
- webViewId,
1733
1730
  contentSecurityPolicy: csp,
1734
1731
  iframeContent,
1735
- remotePathPrefix
1732
+ remotePathPrefix,
1733
+ webViewId,
1734
+ webViewRoot
1736
1735
  }) : setHandler(previewServerId, frameAncestors, webViewRoot, csp, iframeContent));
1737
1736
  // TODO make this work in gitpod also
1738
1737
  };
@@ -1743,10 +1742,10 @@ const register$1 = async () => {
1743
1742
 
1744
1743
  const getModule = platform => {
1745
1744
  switch (platform) {
1746
- case Remote:
1747
- return register$2;
1748
1745
  case Electron:
1749
1746
  return register$3;
1747
+ case Remote:
1748
+ return register$2;
1750
1749
  default:
1751
1750
  return register$1;
1752
1751
  }
@@ -1758,14 +1757,14 @@ const register = async (previewServerId, webViewPort, frameAncestors, webViewRoo
1758
1757
  };
1759
1758
 
1760
1759
  const create2 = async ({
1760
+ assetDir = '',
1761
1761
  id,
1762
- webViewPort,
1763
- webViewId,
1762
+ isGitpod,
1763
+ platform,
1764
1764
  previewServerId,
1765
1765
  uri,
1766
- platform,
1767
- isGitpod,
1768
- assetDir = '',
1766
+ webViewId,
1767
+ webViewPort,
1769
1768
  webViewScheme = WebView
1770
1769
  }) => {
1771
1770
  let root = '';
@@ -1784,9 +1783,9 @@ const create2 = async ({
1784
1783
 
1785
1784
  // TODO move all of this to iframe worker
1786
1785
  const {
1786
+ iframeContent,
1787
1787
  iframeSrc,
1788
- webViewRoot,
1789
- iframeContent
1788
+ webViewRoot
1790
1789
  } = iframeResult;
1791
1790
  const frameAncestors = getWebViewFrameAncestors(locationProtocol, locationHost);
1792
1791
  const frameTitle = getWebViewTitle(webView);
@@ -1823,11 +1822,11 @@ const create2 = async ({
1823
1822
  const savedState = await getSavedWebViewState(webViewId);
1824
1823
  await invoke$3('ExtensionHostWebView.load', webViewId, savedState);
1825
1824
  return {
1825
+ csp: iframeCsp,
1826
1826
  iframeSrc,
1827
- sandbox,
1828
- portId,
1829
1827
  origin,
1830
- csp: iframeCsp
1828
+ portId,
1829
+ sandbox
1831
1830
  };
1832
1831
  };
1833
1832
 
@@ -1860,9 +1859,9 @@ const createWebViewConnection = async (uid, origin) => {
1860
1859
  port2
1861
1860
  } = getPortTuple();
1862
1861
  const rpcPromise = MessagePortRpcParent.create({
1863
- messagePort: port2,
1862
+ commandMap: {},
1864
1863
  isMessagePortOpen: false,
1865
- commandMap: {}
1864
+ messagePort: port2
1866
1865
  });
1867
1866
  const portType = 'test';
1868
1867
  await invokeAndTransfer('WebView.setPort', uid, port1, origin, portType);
@@ -1971,8 +1970,8 @@ const getWebViewWorkerRpc2 = async rpcInfo => {
1971
1970
  } = getPortTuple();
1972
1971
  const rpcPromise = MessagePortRpcParent.create({
1973
1972
  commandMap: commandMap$1,
1974
- messagePort: port2,
1975
- isMessagePortOpen: true
1973
+ isMessagePortOpen: true,
1974
+ messagePort: port2
1976
1975
  });
1977
1976
  // TODO
1978
1977
  // 1. ask extension host worker to ask renderer worker to ask renderer process to create a worker with given url
@@ -2039,11 +2038,11 @@ const proxyPorts = (port1, port2) => {
2039
2038
  const createWebWorkerRpc2 = async (rpcInfo, webView, savedState, uri, portId, webViewUid, origin) => {
2040
2039
  const rpc = await getWebViewWorkerRpc2(rpcInfo);
2041
2040
  const webViewInfo = {
2041
+ origin,
2042
+ portId: portId,
2042
2043
  rpc,
2043
2044
  webViewId: webView.id,
2044
- portId: portId,
2045
- webViewUid,
2046
- origin
2045
+ webViewUid
2047
2046
  };
2048
2047
  set(portId, webViewInfo);
2049
2048
 
@@ -2073,8 +2072,8 @@ const createWebWorkerRpc2 = async (rpcInfo, webView, savedState, uri, portId, we
2073
2072
  await rpc.invoke('_WebView.create', {
2074
2073
  id: portId,
2075
2074
  savedState,
2076
- webViewId: webView.id,
2077
- uri
2075
+ uri,
2076
+ webViewId: webView.id
2078
2077
  });
2079
2078
  };
2080
2079
 
@@ -2088,8 +2087,8 @@ const getWebViewWorkerRpc = async rpcInfo => {
2088
2087
  } = getPortTuple();
2089
2088
  const rpcPromise = MessagePortRpcParent.create({
2090
2089
  commandMap: commandMap$1,
2091
- messagePort: port2,
2092
- isMessagePortOpen: true
2090
+ isMessagePortOpen: true,
2091
+ messagePort: port2
2093
2092
  });
2094
2093
  await invokeAndTransfer$2('WebView.createWebViewWorkerRpc', rpcInfo, port1);
2095
2094
  const rpc = await rpcPromise;
@@ -2103,11 +2102,11 @@ const createWebViewRpc$1 = async (rpcInfo, webView, savedState, uri, portId, web
2103
2102
  // eslint-disable-next-line @typescript-eslint/no-deprecated
2104
2103
  const rpc = await getWebViewWorkerRpc(rpcInfo);
2105
2104
  const webViewInfo = {
2105
+ origin,
2106
+ portId: portId,
2106
2107
  rpc,
2107
2108
  webViewId: webView.id,
2108
- portId: portId,
2109
- webViewUid,
2110
- origin
2109
+ webViewUid
2111
2110
  };
2112
2111
  set(portId, webViewInfo);
2113
2112
  await rpc.invoke('LoadFile.loadFile', rpcInfo.url);
@@ -2123,8 +2122,8 @@ const createWebViewRpc$1 = async (rpcInfo, webView, savedState, uri, portId, web
2123
2122
  await rpc.invoke('_WebView.create', {
2124
2123
  id: portId,
2125
2124
  savedState,
2126
- webViewId: webView.id,
2127
- uri
2125
+ uri,
2126
+ webViewId: webView.id
2128
2127
  });
2129
2128
  };
2130
2129
 
@@ -2172,13 +2171,13 @@ const getWebViewPort = (platform, locationPort) => {
2172
2171
  };
2173
2172
 
2174
2173
  const create3 = async ({
2174
+ assetDir,
2175
2175
  id,
2176
- uri,
2177
2176
  isGitpod,
2178
2177
  platform,
2179
- assetDir,
2180
- webViewScheme,
2181
- useNewWebViewHandler
2178
+ uri,
2179
+ useNewWebViewHandler,
2180
+ webViewScheme
2182
2181
  }) => {
2183
2182
  setPlatform(platform);
2184
2183
  let root = '';
@@ -2199,9 +2198,9 @@ const create3 = async ({
2199
2198
  }
2200
2199
  const webView = getWebView(webViews, webViewId);
2201
2200
  const {
2201
+ iframeContent,
2202
2202
  iframeSrc,
2203
- webViewRoot,
2204
- iframeContent
2203
+ webViewRoot
2205
2204
  } = iframeResult;
2206
2205
  const frameAncestors = getWebViewFrameAncestors(locationProtocol, locationHost);
2207
2206
  const frameTitle = getWebViewTitle(webView);
@@ -2241,11 +2240,11 @@ const create3 = async ({
2241
2240
  }
2242
2241
  await createWebViewRpc(webView, savedState, uri, portId, id, origin);
2243
2242
  return {
2243
+ csp: iframeCsp,
2244
2244
  iframeSrc,
2245
- sandbox,
2246
- portId,
2247
2245
  origin,
2248
- csp: iframeCsp
2246
+ portId,
2247
+ sandbox
2249
2248
  };
2250
2249
  };
2251
2250
 
@@ -2263,8 +2262,8 @@ const getWebViewInfo = webViewId => {
2263
2262
  for (const value of Object.values(rpcs)) {
2264
2263
  if (value.webViewId === webViewId) {
2265
2264
  return {
2266
- uid: value.webViewUid,
2267
- origin: value.origin
2265
+ origin: value.origin,
2266
+ uid: value.webViewUid
2268
2267
  };
2269
2268
  }
2270
2269
  }
@@ -2299,12 +2298,12 @@ const unregisterInterceptor = async id => {
2299
2298
  const commandMap = {
2300
2299
  'WebView.create2': create2,
2301
2300
  'WebView.create3': create3,
2302
- 'WebView.saveState': saveState,
2301
+ 'WebView.executeExternalCommand': executeCommand,
2303
2302
  'WebView.getSecret': getSecret,
2304
2303
  'WebView.getWebViewInfo': getWebViewInfo,
2305
2304
  'WebView.registerInterceptor': registerInterceptor,
2306
- 'WebView.unregisterInterceptor': unregisterInterceptor,
2307
- 'WebView.executeExternalCommand': executeCommand
2305
+ 'WebView.saveState': saveState,
2306
+ 'WebView.unregisterInterceptor': unregisterInterceptor
2308
2307
  };
2309
2308
 
2310
2309
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "5.35.0",
3
+ "version": "5.36.0",
4
4
  "description": "Web Worker to manage creation and lifecycle of iframes in Lvce Editor",
5
5
  "keywords": [
6
6
  "iframe"