@lvce-editor/iframe-worker 5.20.0 → 5.22.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.
@@ -1094,6 +1094,9 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
1094
1094
  if (!webViewUri) {
1095
1095
  return undefined;
1096
1096
  }
1097
+ if (!webView) {
1098
+ return undefined;
1099
+ }
1097
1100
  let iframeSrc = webViewUri;
1098
1101
  let webViewRoot = webViewUri;
1099
1102
 
@@ -1469,6 +1472,15 @@ const create2 = async ({
1469
1472
  };
1470
1473
  };
1471
1474
 
1475
+ const createAndLoadWebView = async (id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle) => {
1476
+ await invoke$2('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
1477
+
1478
+ // TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
1479
+ // and causes flash of unstyled content, maybe a better way would be to just send the
1480
+ // port and wait for the first port message
1481
+ await invoke$2('WebView.load', id);
1482
+ };
1483
+
1472
1484
  const invoke = async (method, ...params) => {
1473
1485
  return invoke$4('WebView.compatRendererWorkerInvoke', method, ...params);
1474
1486
  };
@@ -1566,10 +1578,7 @@ const commandMap$1 = {
1566
1578
  'WebView.readFile': readFile
1567
1579
  };
1568
1580
 
1569
- /**
1570
- * @deprecated use getWebViewWorkerRpc2 instead
1571
- */
1572
- const getWebViewWorkerRpc = async rpcInfo => {
1581
+ const getWebViewWorkerRpc2 = async rpcInfo => {
1573
1582
  const {
1574
1583
  port1,
1575
1584
  port2
@@ -1579,15 +1588,32 @@ const getWebViewWorkerRpc = async rpcInfo => {
1579
1588
  messagePort: port2,
1580
1589
  isMessagePortOpen: true
1581
1590
  });
1582
- await invokeAndTransfer$2('WebView.createWebViewWorkerRpc', rpcInfo, port1);
1591
+ // TODO
1592
+ // 1. ask extension host worker to ask renderer worker to ask renderer process to create a worker with given url
1593
+ // 2. send the port through renderer worker to renderer process to the worker for a direct connection
1594
+ await invokeAndTransfer$2('WebView.createWebViewWorkerRpc2', rpcInfo, port1);
1583
1595
  const rpc = await rpcPromise;
1584
1596
  // TODO rpc module should start the port
1585
1597
  port2.start();
1586
1598
  return rpc;
1587
1599
  };
1588
1600
 
1601
+ // TODO not part of this function but, for the webview webworker connection,
1602
+ // send two ports to the iframe
1603
+ // one port for builtin events like ctrl+shift+p keydown event for quickpick
1604
+ // second port for the webview webworker connection
1605
+
1606
+ // this creates in total
1607
+ // 1 iframe
1608
+ // 1 worker
1609
+ // 6 messageports
1610
+
1611
+ // one way to reduce the number of messageports could be to route the worker events
1612
+ // through the iframe worker. However that could introduce some overhead / latency
1613
+ // compared to direct connections
1614
+
1589
1615
  const createWebWorkerRpc2 = async (rpcInfo, webView, savedState, uri, portId, webViewUid, origin) => {
1590
- const rpc = await getWebViewWorkerRpc(rpcInfo);
1616
+ const rpc = await getWebViewWorkerRpc2(rpcInfo);
1591
1617
  const webViewInfo = {
1592
1618
  rpc,
1593
1619
  webViewId: webView.id,
@@ -1613,6 +1639,26 @@ const createWebWorkerRpc2 = async (rpcInfo, webView, savedState, uri, portId, we
1613
1639
  });
1614
1640
  };
1615
1641
 
1642
+ /**
1643
+ * @deprecated use getWebViewWorkerRpc2 instead
1644
+ */
1645
+ const getWebViewWorkerRpc = async rpcInfo => {
1646
+ const {
1647
+ port1,
1648
+ port2
1649
+ } = getPortTuple();
1650
+ const rpcPromise = MessagePortRpcParent.create({
1651
+ commandMap: commandMap$1,
1652
+ messagePort: port2,
1653
+ isMessagePortOpen: true
1654
+ });
1655
+ await invokeAndTransfer$2('WebView.createWebViewWorkerRpc', rpcInfo, port1);
1656
+ const rpc = await rpcPromise;
1657
+ // TODO rpc module should start the port
1658
+ port2.start();
1659
+ return rpc;
1660
+ };
1661
+
1616
1662
  const createWebViewRpc$1 = async (rpcInfo, webView, savedState, uri, portId, webViewUid, origin) => {
1617
1663
  // deprecated below
1618
1664
  const rpc = await getWebViewWorkerRpc(rpcInfo);
@@ -1650,6 +1696,7 @@ const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, or
1650
1696
  if (rpcInfo && rpcInfo.type === 'web-worker-2') {
1651
1697
  return createWebWorkerRpc2(rpcInfo, webView, savedState, uri, portId, webViewUid, origin);
1652
1698
  }
1699
+ // legacy
1653
1700
  if (rpcInfo.type !== 'web-worker') {
1654
1701
  throw new Error(`only web worker rpc is supported for webviews`);
1655
1702
  }
@@ -1710,8 +1757,6 @@ const create3 = async ({
1710
1757
  return undefined;
1711
1758
  }
1712
1759
  const webView = getWebView(webViews, webViewId);
1713
-
1714
- // TODO move all of this to iframe worker
1715
1760
  const {
1716
1761
  iframeSrc,
1717
1762
  webViewRoot,
@@ -1735,12 +1780,7 @@ const create3 = async ({
1735
1780
  const portId = create$1();
1736
1781
  const remotePathPrefix = '/remote';
1737
1782
  await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix, useNewWebViewHandler);
1738
- await invoke$2('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
1739
-
1740
- // TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
1741
- // and causes flash of unstyled content, maybe a better way would be to just send the
1742
- // port and wait for the first port message
1743
- await invoke$2('WebView.load', id);
1783
+ await createAndLoadWebView(id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
1744
1784
  const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
1745
1785
  const hasOldRpc = !webView || !webView.rpc || typeof webView.rpc !== 'string';
1746
1786
  if (hasOldRpc) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "5.20.0",
3
+ "version": "5.22.0",
4
4
  "description": "Web Worker to manage creation and lifecycle of iframes in Lvce Editor",
5
5
  "keywords": [
6
6
  "iframe"