@lvce-editor/iframe-worker 5.15.0 → 5.17.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,10 +483,10 @@ const create$4 = (method, params) => {
483
483
  };
484
484
  };
485
485
  const callbacks = Object.create(null);
486
- const set$1 = (id, fn) => {
486
+ const set$2 = (id, fn) => {
487
487
  callbacks[id] = fn;
488
488
  };
489
- const get = id => {
489
+ const get$2 = id => {
490
490
  return callbacks[id];
491
491
  };
492
492
  const remove = id => {
@@ -502,7 +502,7 @@ const registerPromise = () => {
502
502
  resolve,
503
503
  promise
504
504
  } = Promise.withResolvers();
505
- set$1(id, resolve);
505
+ set$2(id, resolve);
506
506
  return {
507
507
  id,
508
508
  promise
@@ -659,7 +659,7 @@ const warn = (...args) => {
659
659
  console.warn(...args);
660
660
  };
661
661
  const resolve = (id, response) => {
662
- const fn = get(id);
662
+ const fn = get$2(id);
663
663
  if (!fn) {
664
664
  console.log(response);
665
665
  warn(`callback ${id} may already be disposed`);
@@ -967,20 +967,24 @@ const getAssetDir = () => {
967
967
  };
968
968
  const assetDir = getAssetDir();
969
969
 
970
- const state$1 = {
971
- rpc: undefined
970
+ const RendererWorker = 1;
971
+
972
+ const rpcs$1 = Object.create(null);
973
+ const set$1 = (id, rpc) => {
974
+ rpcs$1[id] = rpc;
975
+ };
976
+ const get$1 = id => {
977
+ return rpcs$1[id];
972
978
  };
979
+
973
980
  const invoke$4 = (method, ...params) => {
974
- const rpc = state$1.rpc;
981
+ const rpc = get$1(RendererWorker);
975
982
  return rpc.invoke(method, ...params);
976
983
  };
977
984
  const invokeAndTransfer$3 = (method, ...params) => {
978
- const rpc = state$1.rpc;
985
+ const rpc = get$1(RendererWorker);
979
986
  return rpc.invokeAndTransfer(method, ...params);
980
987
  };
981
- const setRpc = rpc => {
982
- state$1.rpc = rpc;
983
- };
984
988
 
985
989
  const invoke$3 = async (method, ...params) => {
986
990
  return invoke$4('WebView.compatExtensionHostWorkerInvoke', method, ...params);
@@ -1507,6 +1511,17 @@ const getProtocol = uri => {
1507
1511
  return '';
1508
1512
  };
1509
1513
 
1514
+ const rpcs = Object.create(null);
1515
+ const set = (id, rpc) => {
1516
+ rpcs[id] = rpc;
1517
+ };
1518
+ const get = id => {
1519
+ return rpcs[id];
1520
+ };
1521
+ const getAll = () => {
1522
+ return rpcs;
1523
+ };
1524
+
1510
1525
  // TODO if webViewId is provided,
1511
1526
  // 1. read file as blob
1512
1527
  // 2. send blob to webview
@@ -1515,15 +1530,12 @@ const getProtocol = uri => {
1515
1530
  // 5. provide objectUrl to extension
1516
1531
 
1517
1532
  const getRemoteUrlForWebView = async options => {
1518
- throw new Error('not implemented');
1519
- // TODO webviews should be stored in iframe worker
1520
- // const webView = ExtensionHostWebViewState.getWebView(options.webViewId as string)
1521
- // if (!webView) {
1522
- // throw new Error(`webview ${options.webViewId} not found`)
1523
- // }
1524
- // const [rpc, blob] = await Promise.all([CreateWebViewIpc.createWebViewIpc(webView), Rpc.invoke('FileSystem.getBlob', uri)])
1525
- // const objectUrl = await rpc.invoke('createObjectUrl', blob)
1526
- // return objectUrl
1533
+ const webView = get(options.id);
1534
+ const rpcPromise = createWebViewConnection(webView.webViewUid, webView.origin);
1535
+ const blobPromise = invoke('FileSystem.getBlob', options.uri);
1536
+ const [rpc, blob] = await Promise.all([rpcPromise, blobPromise]);
1537
+ const objectUrl = await rpc.invoke('createObjectUrl', blob);
1538
+ return objectUrl;
1527
1539
  };
1528
1540
 
1529
1541
  const getRemoteUrl = async options => {
@@ -1545,7 +1557,7 @@ const getRemoteUrl = async options => {
1545
1557
  }
1546
1558
  return `/remote/${uri}`;
1547
1559
  }
1548
- return getRemoteUrlForWebView();
1560
+ return getRemoteUrlForWebView(options);
1549
1561
  };
1550
1562
 
1551
1563
  const commandMap$1 = {
@@ -1570,14 +1582,6 @@ const getWebViewWorkerRpc = async rpcInfo => {
1570
1582
  return rpc;
1571
1583
  };
1572
1584
 
1573
- const rpcs = Object.create(null);
1574
- const set = (id, rpc) => {
1575
- rpcs[id] = rpc;
1576
- };
1577
- const getAll = () => {
1578
- return rpcs;
1579
- };
1580
-
1581
1585
  const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, origin) => {
1582
1586
  if (!webView || !webView.rpc || typeof webView.rpc !== 'string') {
1583
1587
  return;
@@ -1590,7 +1594,9 @@ const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, or
1590
1594
  const webViewInfo = {
1591
1595
  rpc,
1592
1596
  webViewId: webView.id,
1593
- portId: portId
1597
+ portId: portId,
1598
+ webViewUid,
1599
+ origin
1594
1600
  };
1595
1601
  set(portId, webViewInfo);
1596
1602
  await rpc.invoke('LoadFile.loadFile', rpcInfo.url);
@@ -1750,7 +1756,7 @@ const listen = async () => {
1750
1756
  const rpc = await WebWorkerRpcClient.create({
1751
1757
  commandMap: commandMap
1752
1758
  });
1753
- setRpc(rpc);
1759
+ set$1(RendererWorker, rpc);
1754
1760
  };
1755
1761
 
1756
1762
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "5.15.0",
3
+ "version": "5.17.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",