@lvce-editor/iframe-worker 5.12.0 → 5.13.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.
@@ -483,7 +483,7 @@ const create$4 = (method, params) => {
483
483
  };
484
484
  };
485
485
  const callbacks = Object.create(null);
486
- const set = (id, fn) => {
486
+ const set$1 = (id, fn) => {
487
487
  callbacks[id] = fn;
488
488
  };
489
489
  const get = id => {
@@ -502,7 +502,7 @@ const registerPromise = () => {
502
502
  resolve,
503
503
  promise
504
504
  } = Promise.withResolvers();
505
- set(id, resolve);
505
+ set$1(id, resolve);
506
506
  return {
507
507
  id,
508
508
  promise
@@ -1559,6 +1559,11 @@ const getWebViewWorkerRpc = async rpcInfo => {
1559
1559
  return rpc;
1560
1560
  };
1561
1561
 
1562
+ const rpcs = Object.create(null);
1563
+ const set = (id, rpc) => {
1564
+ rpcs[id] = rpc;
1565
+ };
1566
+
1562
1567
  const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, origin) => {
1563
1568
  if (!webView || !webView.rpc || typeof webView.rpc !== 'string') {
1564
1569
  return;
@@ -1568,6 +1573,11 @@ const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, or
1568
1573
  throw new Error(`only web worker rpc is supported for webviews`);
1569
1574
  }
1570
1575
  const rpc = await getWebViewWorkerRpc(rpcInfo);
1576
+ const webViewInfo = {
1577
+ rpc,
1578
+ webViewId: webView.id
1579
+ };
1580
+ set(portId, webViewInfo);
1571
1581
  await rpc.invoke('LoadFile.loadFile', rpcInfo.url);
1572
1582
 
1573
1583
  // TODO this connection might not be needed
@@ -1662,10 +1672,6 @@ const create3 = async ({
1662
1672
  const iframeCsp = platform === Web ? csp : '';
1663
1673
  const credentialless = getCredentialLess(locationHost);
1664
1674
  await invoke$3('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
1665
- const {
1666
- port1,
1667
- port2
1668
- } = getPortTuple();
1669
1675
  const portId = create$1();
1670
1676
  const remotePathPrefix = '/remote';
1671
1677
  await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix, useNewWebViewHandler);
@@ -1676,11 +1682,20 @@ const create3 = async ({
1676
1682
  // port and wait for the first port message
1677
1683
  await invoke$1('WebView.load', id);
1678
1684
  const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
1679
- const portType = '';
1680
- await setPort(id, port1, origin, portType);
1681
- await invokeAndTransfer$2('ExtensionHostWebView.create', webViewId, port2, uri, id, origin, webView);
1685
+ const hasOldRpc = !webView || !webView.rpc || typeof webView.rpc !== 'string';
1686
+ if (hasOldRpc) {
1687
+ const {
1688
+ port1,
1689
+ port2
1690
+ } = getPortTuple();
1691
+ const portType = '';
1692
+ await setPort(id, port1, origin, portType);
1693
+ await invokeAndTransfer$2('ExtensionHostWebView.create', webViewId, port2, uri, id, origin, webView);
1694
+ }
1682
1695
  const savedState = await getSavedWebViewState(webViewId);
1683
- await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
1696
+ if (hasOldRpc) {
1697
+ await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
1698
+ }
1684
1699
  await createWebViewRpc(webView, savedState, uri, portId, id, origin);
1685
1700
  return {
1686
1701
  iframeSrc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "5.12.0",
3
+ "version": "5.13.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",