@lvce-editor/iframe-worker 5.18.0 → 5.20.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.
@@ -711,7 +711,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
711
711
  const errorProperty = getErrorProperty(error, prettyError);
712
712
  return create$1$1(message, errorProperty);
713
713
  };
714
- const create$6 = (message, result) => {
714
+ const create$5 = (message, result) => {
715
715
  return {
716
716
  jsonrpc: Two,
717
717
  id: message.id,
@@ -720,7 +720,7 @@ const create$6 = (message, result) => {
720
720
  };
721
721
  const getSuccessResponse = (message, result) => {
722
722
  const resultProperty = result ?? null;
723
- return create$6(message, resultProperty);
723
+ return create$5(message, resultProperty);
724
724
  };
725
725
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
726
726
  try {
@@ -884,7 +884,7 @@ const listen$1 = async (module, options) => {
884
884
  const ipc = module.wrap(rawIpc);
885
885
  return ipc;
886
886
  };
887
- const create$5 = async ({
887
+ const create$6 = async ({
888
888
  commandMap,
889
889
  messagePort,
890
890
  isMessagePortOpen
@@ -902,7 +902,7 @@ const create$5 = async ({
902
902
  };
903
903
  const MessagePortRpcParent = {
904
904
  __proto__: null,
905
- create: create$5
905
+ create: create$6
906
906
  };
907
907
  const create$2 = async ({
908
908
  commandMap
@@ -1566,6 +1566,9 @@ const commandMap$1 = {
1566
1566
  'WebView.readFile': readFile
1567
1567
  };
1568
1568
 
1569
+ /**
1570
+ * @deprecated use getWebViewWorkerRpc2 instead
1571
+ */
1569
1572
  const getWebViewWorkerRpc = async rpcInfo => {
1570
1573
  const {
1571
1574
  port1,
@@ -1583,14 +1586,35 @@ const getWebViewWorkerRpc = async rpcInfo => {
1583
1586
  return rpc;
1584
1587
  };
1585
1588
 
1586
- const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, origin) => {
1587
- if (!webView || !webView.rpc || typeof webView.rpc !== 'string') {
1588
- return;
1589
- }
1590
- const rpcInfo = await invoke$3('WebView.getRpcInfo', webView.rpc);
1591
- if (rpcInfo.type !== 'web-worker') {
1592
- throw new Error(`only web worker rpc is supported for webviews`);
1593
- }
1589
+ const createWebWorkerRpc2 = async (rpcInfo, webView, savedState, uri, portId, webViewUid, origin) => {
1590
+ const rpc = await getWebViewWorkerRpc(rpcInfo);
1591
+ const webViewInfo = {
1592
+ rpc,
1593
+ webViewId: webView.id,
1594
+ portId: portId,
1595
+ webViewUid,
1596
+ origin
1597
+ };
1598
+ set(portId, webViewInfo);
1599
+
1600
+ // TODO this connection might not be needed
1601
+ await createWebViewConnection(webViewUid, origin);
1602
+ const {
1603
+ port1,
1604
+ port2
1605
+ } = getPortTuple();
1606
+ await createSecondaryWebViewConnection(webViewUid, origin, port1);
1607
+ await rpc.invokeAndTransfer('_WebView.setPort', portId, port2);
1608
+ await rpc.invoke('_WebView.create', {
1609
+ id: portId,
1610
+ savedState,
1611
+ webViewId: webView.id,
1612
+ uri
1613
+ });
1614
+ };
1615
+
1616
+ const createWebViewRpc$1 = async (rpcInfo, webView, savedState, uri, portId, webViewUid, origin) => {
1617
+ // deprecated below
1594
1618
  const rpc = await getWebViewWorkerRpc(rpcInfo);
1595
1619
  const webViewInfo = {
1596
1620
  rpc,
@@ -1618,6 +1642,20 @@ const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, or
1618
1642
  });
1619
1643
  };
1620
1644
 
1645
+ const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, origin) => {
1646
+ if (!webView || !webView.rpc || typeof webView.rpc !== 'string') {
1647
+ return;
1648
+ }
1649
+ const rpcInfo = await invoke$3('WebView.getRpcInfo', webView.rpc);
1650
+ if (rpcInfo && rpcInfo.type === 'web-worker-2') {
1651
+ return createWebWorkerRpc2(rpcInfo, webView, savedState, uri, portId, webViewUid, origin);
1652
+ }
1653
+ if (rpcInfo.type !== 'web-worker') {
1654
+ throw new Error(`only web worker rpc is supported for webviews`);
1655
+ }
1656
+ return createWebViewRpc$1(rpcInfo, webView, savedState, uri, portId, webViewUid, origin);
1657
+ };
1658
+
1621
1659
  const getPreviewServerId = () => {
1622
1660
  // TODO
1623
1661
  return 1;
@@ -1728,6 +1766,10 @@ const create3 = async ({
1728
1766
  };
1729
1767
  };
1730
1768
 
1769
+ const getSecret = async key => {
1770
+ return invoke('WebView.getSecret', key);
1771
+ };
1772
+
1731
1773
  const saveState = async () => {
1732
1774
  const all = getAll();
1733
1775
  const serialized = [];
@@ -1750,7 +1792,8 @@ const saveState = async () => {
1750
1792
  const commandMap = {
1751
1793
  'WebView.create2': create2,
1752
1794
  'WebView.create3': create3,
1753
- 'WebView.saveState': saveState
1795
+ 'WebView.saveState': saveState,
1796
+ 'WebView.getSecret': getSecret
1754
1797
  };
1755
1798
 
1756
1799
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "5.18.0",
3
+ "version": "5.20.0",
4
4
  "description": "Web Worker to manage creation and lifecycle of iframes in Lvce Editor",
5
5
  "keywords": [
6
6
  "iframe"