@lvce-editor/iframe-worker 5.13.0 → 5.15.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.
- package/dist/iframeWorkerMain.js +66 -31
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -813,7 +813,7 @@ const send = (transport, method, ...params) => {
|
|
|
813
813
|
const message = create$4(method, params);
|
|
814
814
|
transport.send(message);
|
|
815
815
|
};
|
|
816
|
-
const invoke$
|
|
816
|
+
const invoke$5 = (ipc, method, ...params) => {
|
|
817
817
|
return invokeHelper(ipc, method, params, false);
|
|
818
818
|
};
|
|
819
819
|
const invokeAndTransfer$4 = (ipc, method, ...params) => {
|
|
@@ -846,7 +846,7 @@ const createRpc = ipc => {
|
|
|
846
846
|
send(ipc, method, ...params);
|
|
847
847
|
},
|
|
848
848
|
invoke(method, ...params) {
|
|
849
|
-
return invoke$
|
|
849
|
+
return invoke$5(ipc, method, ...params);
|
|
850
850
|
},
|
|
851
851
|
invokeAndTransfer(method, ...params) {
|
|
852
852
|
return invokeAndTransfer$4(ipc, method, ...params);
|
|
@@ -970,7 +970,7 @@ const assetDir = getAssetDir();
|
|
|
970
970
|
const state$1 = {
|
|
971
971
|
rpc: undefined
|
|
972
972
|
};
|
|
973
|
-
const invoke$
|
|
973
|
+
const invoke$4 = (method, ...params) => {
|
|
974
974
|
const rpc = state$1.rpc;
|
|
975
975
|
return rpc.invoke(method, ...params);
|
|
976
976
|
};
|
|
@@ -982,8 +982,8 @@ const setRpc = rpc => {
|
|
|
982
982
|
state$1.rpc = rpc;
|
|
983
983
|
};
|
|
984
984
|
|
|
985
|
-
const invoke$
|
|
986
|
-
return invoke$
|
|
985
|
+
const invoke$3 = async (method, ...params) => {
|
|
986
|
+
return invoke$4('WebView.compatExtensionHostWorkerInvoke', method, ...params);
|
|
987
987
|
};
|
|
988
988
|
const invokeAndTransfer$2 = async (method, ...params) => {
|
|
989
989
|
return invokeAndTransfer$3('WebView.compatExtensionHostWorkerInvokeAndTransfer', method, ...params);
|
|
@@ -1183,7 +1183,7 @@ const getPortTuple = () => {
|
|
|
1183
1183
|
};
|
|
1184
1184
|
|
|
1185
1185
|
const getSavedState = async () => {
|
|
1186
|
-
return invoke$
|
|
1186
|
+
return invoke$4('WebView.getSavedState');
|
|
1187
1187
|
};
|
|
1188
1188
|
|
|
1189
1189
|
const getSavedWebViewState = async id => {
|
|
@@ -1198,6 +1198,9 @@ const getSavedWebViewState = async id => {
|
|
|
1198
1198
|
if (item && item.key && item.key === id && item.value && item.value.state) {
|
|
1199
1199
|
return item.value.state;
|
|
1200
1200
|
}
|
|
1201
|
+
if (item && item.key && item.key === id && item.value) {
|
|
1202
|
+
return item.value;
|
|
1203
|
+
}
|
|
1201
1204
|
}
|
|
1202
1205
|
return undefined;
|
|
1203
1206
|
};
|
|
@@ -1249,7 +1252,7 @@ const getIframePermissionPolicy = webView => {
|
|
|
1249
1252
|
};
|
|
1250
1253
|
|
|
1251
1254
|
const getWebViews = async () => {
|
|
1252
|
-
return invoke$
|
|
1255
|
+
return invoke$4('WebView.getWebViews');
|
|
1253
1256
|
};
|
|
1254
1257
|
|
|
1255
1258
|
const AllowScripts = 'allow-scripts';
|
|
@@ -1297,8 +1300,8 @@ const getPort = () => {
|
|
|
1297
1300
|
return location.port;
|
|
1298
1301
|
};
|
|
1299
1302
|
|
|
1300
|
-
const invoke$
|
|
1301
|
-
return invoke$
|
|
1303
|
+
const invoke$2 = async (method, ...params) => {
|
|
1304
|
+
return invoke$4('WebView.compatRendererProcessInvoke', method, ...params);
|
|
1302
1305
|
};
|
|
1303
1306
|
const invokeAndTransfer$1 = async (method, ...params) => {
|
|
1304
1307
|
return invokeAndTransfer$3('WebView.compatRendererProcessInvokeAndTransfer', method, ...params);
|
|
@@ -1310,27 +1313,27 @@ const setPort = async (uid, port, origin, portType) => {
|
|
|
1310
1313
|
await invokeAndTransfer$1('WebView.setPort', uid, port, origin, portType);
|
|
1311
1314
|
};
|
|
1312
1315
|
|
|
1313
|
-
const invoke = async (method, ...params) => {
|
|
1314
|
-
return invoke$
|
|
1316
|
+
const invoke$1 = async (method, ...params) => {
|
|
1317
|
+
return invoke$4('WebView.compatSharedProcessInvoke', method, ...params);
|
|
1315
1318
|
};
|
|
1316
1319
|
|
|
1317
1320
|
const registerProtocol = async () => {
|
|
1318
|
-
await invoke('WebViewServer.registerProtocol');
|
|
1321
|
+
await invoke$1('WebViewServer.registerProtocol');
|
|
1319
1322
|
};
|
|
1320
1323
|
const create = async (previewServerId, useNewWebViewHandler) => {
|
|
1321
|
-
await invoke('WebViewServer.create', previewServerId, useNewWebViewHandler);
|
|
1324
|
+
await invoke$1('WebViewServer.create', previewServerId, useNewWebViewHandler);
|
|
1322
1325
|
};
|
|
1323
1326
|
const start = async (previewServerId, webViewPort) => {
|
|
1324
|
-
await invoke('WebViewServer.start', previewServerId, webViewPort);
|
|
1327
|
+
await invoke$1('WebViewServer.start', previewServerId, webViewPort);
|
|
1325
1328
|
};
|
|
1326
1329
|
const setInfo2 = async info => {
|
|
1327
|
-
await invoke('WebViewServer.setInfo2', info);
|
|
1330
|
+
await invoke$1('WebViewServer.setInfo2', info);
|
|
1328
1331
|
};
|
|
1329
1332
|
const setInfo = async (previewServerId, webViewId, webViewRoot, contentSecurityPolicy, iframeContent) => {
|
|
1330
|
-
await invoke('WebViewServer.setInfo', previewServerId, webViewId, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1333
|
+
await invoke$1('WebViewServer.setInfo', previewServerId, webViewId, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1331
1334
|
};
|
|
1332
1335
|
const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent, remotePathPrefix) => {
|
|
1333
|
-
await invoke('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1336
|
+
await invoke$1('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1334
1337
|
};
|
|
1335
1338
|
|
|
1336
1339
|
const register$3 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId, remotePathPrefix, useNewWebViewHandler) => {
|
|
@@ -1401,7 +1404,7 @@ const create2 = async ({
|
|
|
1401
1404
|
}) => {
|
|
1402
1405
|
let root = '';
|
|
1403
1406
|
if (platform === Remote) {
|
|
1404
|
-
root = await invoke('Platform.getRoot');
|
|
1407
|
+
root = await invoke$1('Platform.getRoot');
|
|
1405
1408
|
}
|
|
1406
1409
|
const webViews = await getWebViews();
|
|
1407
1410
|
const locationProtocol = getProtocol$1();
|
|
@@ -1433,7 +1436,7 @@ const create2 = async ({
|
|
|
1433
1436
|
const permissionPolicyString = permissionPolicy.join('; ');
|
|
1434
1437
|
const iframeCsp = platform === Web ? csp : '';
|
|
1435
1438
|
const credentialless = getCredentialLess(locationHost);
|
|
1436
|
-
await invoke$
|
|
1439
|
+
await invoke$4('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
|
|
1437
1440
|
const {
|
|
1438
1441
|
port1,
|
|
1439
1442
|
port2
|
|
@@ -1441,18 +1444,18 @@ const create2 = async ({
|
|
|
1441
1444
|
const portId = create$1();
|
|
1442
1445
|
const remotePathPrefix = '/remote';
|
|
1443
1446
|
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix);
|
|
1444
|
-
await invoke$
|
|
1447
|
+
await invoke$2('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
|
|
1445
1448
|
|
|
1446
1449
|
// TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
|
|
1447
1450
|
// and causes flash of unstyled content, maybe a better way would be to just send the
|
|
1448
1451
|
// port and wait for the first port message
|
|
1449
|
-
await invoke$
|
|
1452
|
+
await invoke$2('WebView.load', id);
|
|
1450
1453
|
const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
|
|
1451
1454
|
const portType = '';
|
|
1452
1455
|
await setPort(id, port1, origin, portType);
|
|
1453
1456
|
await invokeAndTransfer$2('ExtensionHostWebView.create', webViewId, port2, uri, id, origin, webView);
|
|
1454
1457
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1455
|
-
await invoke$
|
|
1458
|
+
await invoke$3('ExtensionHostWebView.load', webViewId, savedState);
|
|
1456
1459
|
return {
|
|
1457
1460
|
iframeSrc,
|
|
1458
1461
|
sandbox,
|
|
@@ -1462,6 +1465,9 @@ const create2 = async ({
|
|
|
1462
1465
|
};
|
|
1463
1466
|
};
|
|
1464
1467
|
|
|
1468
|
+
const invoke = async (method, ...params) => {
|
|
1469
|
+
return invoke$4('WebView.compatRendererWorkerInvoke', method, ...params);
|
|
1470
|
+
};
|
|
1465
1471
|
const invokeAndTransfer = async (method, ...params) => {
|
|
1466
1472
|
return invokeAndTransfer$3('WebView.compatRendererWorkerInvokeAndTransfer', method, ...params);
|
|
1467
1473
|
};
|
|
@@ -1488,6 +1494,10 @@ const createWebViewConnection = async (uid, origin) => {
|
|
|
1488
1494
|
return rpc;
|
|
1489
1495
|
};
|
|
1490
1496
|
|
|
1497
|
+
const readFile = uri => {
|
|
1498
|
+
return invoke('FileSystem.readFile', uri);
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1491
1501
|
const RE_PROTOCOL = /^([a-z-]+):\/\//;
|
|
1492
1502
|
const getProtocol = uri => {
|
|
1493
1503
|
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
@@ -1539,7 +1549,8 @@ const getRemoteUrl = async options => {
|
|
|
1539
1549
|
};
|
|
1540
1550
|
|
|
1541
1551
|
const commandMap$1 = {
|
|
1542
|
-
'WebView.getRemoteUrl': getRemoteUrl
|
|
1552
|
+
'WebView.getRemoteUrl': getRemoteUrl,
|
|
1553
|
+
'WebView.readFile': readFile
|
|
1543
1554
|
};
|
|
1544
1555
|
|
|
1545
1556
|
const getWebViewWorkerRpc = async rpcInfo => {
|
|
@@ -1563,19 +1574,23 @@ const rpcs = Object.create(null);
|
|
|
1563
1574
|
const set = (id, rpc) => {
|
|
1564
1575
|
rpcs[id] = rpc;
|
|
1565
1576
|
};
|
|
1577
|
+
const getAll = () => {
|
|
1578
|
+
return rpcs;
|
|
1579
|
+
};
|
|
1566
1580
|
|
|
1567
1581
|
const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, origin) => {
|
|
1568
1582
|
if (!webView || !webView.rpc || typeof webView.rpc !== 'string') {
|
|
1569
1583
|
return;
|
|
1570
1584
|
}
|
|
1571
|
-
const rpcInfo = await invoke$
|
|
1585
|
+
const rpcInfo = await invoke$3('WebView.getRpcInfo', webView.rpc);
|
|
1572
1586
|
if (rpcInfo.type !== 'web-worker') {
|
|
1573
1587
|
throw new Error(`only web worker rpc is supported for webviews`);
|
|
1574
1588
|
}
|
|
1575
1589
|
const rpc = await getWebViewWorkerRpc(rpcInfo);
|
|
1576
1590
|
const webViewInfo = {
|
|
1577
1591
|
rpc,
|
|
1578
|
-
webViewId: webView.id
|
|
1592
|
+
webViewId: webView.id,
|
|
1593
|
+
portId: portId
|
|
1579
1594
|
};
|
|
1580
1595
|
set(portId, webViewInfo);
|
|
1581
1596
|
await rpc.invoke('LoadFile.loadFile', rpcInfo.url);
|
|
@@ -1635,7 +1650,7 @@ const create3 = async ({
|
|
|
1635
1650
|
}) => {
|
|
1636
1651
|
let root = '';
|
|
1637
1652
|
if (platform === Remote) {
|
|
1638
|
-
root = await invoke('Platform.getRoot');
|
|
1653
|
+
root = await invoke$1('Platform.getRoot');
|
|
1639
1654
|
}
|
|
1640
1655
|
const webViews = await getWebViews();
|
|
1641
1656
|
const webViewId = getWebViewId(webViews, uri);
|
|
@@ -1671,16 +1686,16 @@ const create3 = async ({
|
|
|
1671
1686
|
const permissionPolicyString = permissionPolicy.join('; ');
|
|
1672
1687
|
const iframeCsp = platform === Web ? csp : '';
|
|
1673
1688
|
const credentialless = getCredentialLess(locationHost);
|
|
1674
|
-
await invoke$
|
|
1689
|
+
await invoke$4('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
|
|
1675
1690
|
const portId = create$1();
|
|
1676
1691
|
const remotePathPrefix = '/remote';
|
|
1677
1692
|
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix, useNewWebViewHandler);
|
|
1678
|
-
await invoke$
|
|
1693
|
+
await invoke$2('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
|
|
1679
1694
|
|
|
1680
1695
|
// TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
|
|
1681
1696
|
// and causes flash of unstyled content, maybe a better way would be to just send the
|
|
1682
1697
|
// port and wait for the first port message
|
|
1683
|
-
await invoke$
|
|
1698
|
+
await invoke$2('WebView.load', id);
|
|
1684
1699
|
const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
|
|
1685
1700
|
const hasOldRpc = !webView || !webView.rpc || typeof webView.rpc !== 'string';
|
|
1686
1701
|
if (hasOldRpc) {
|
|
@@ -1694,7 +1709,7 @@ const create3 = async ({
|
|
|
1694
1709
|
}
|
|
1695
1710
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1696
1711
|
if (hasOldRpc) {
|
|
1697
|
-
await invoke$
|
|
1712
|
+
await invoke$3('ExtensionHostWebView.load', webViewId, savedState);
|
|
1698
1713
|
}
|
|
1699
1714
|
await createWebViewRpc(webView, savedState, uri, portId, id, origin);
|
|
1700
1715
|
return {
|
|
@@ -1706,9 +1721,29 @@ const create3 = async ({
|
|
|
1706
1721
|
};
|
|
1707
1722
|
};
|
|
1708
1723
|
|
|
1724
|
+
const saveState = async () => {
|
|
1725
|
+
const all = getAll();
|
|
1726
|
+
const serialized = [];
|
|
1727
|
+
for (const value of Object.values(all)) {
|
|
1728
|
+
try {
|
|
1729
|
+
const savedState = await value.rpc.invoke('WebView.saveState', value.portId);
|
|
1730
|
+
serialized.push({
|
|
1731
|
+
key: value.webViewId,
|
|
1732
|
+
value: savedState
|
|
1733
|
+
});
|
|
1734
|
+
} catch (error) {
|
|
1735
|
+
console.log(error);
|
|
1736
|
+
// TODO maybe log the error
|
|
1737
|
+
// ignore
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
return serialized;
|
|
1741
|
+
};
|
|
1742
|
+
|
|
1709
1743
|
const commandMap = {
|
|
1710
1744
|
'WebView.create2': create2,
|
|
1711
|
-
'WebView.create3': create3
|
|
1745
|
+
'WebView.create3': create3,
|
|
1746
|
+
'WebView.saveState': saveState
|
|
1712
1747
|
};
|
|
1713
1748
|
|
|
1714
1749
|
const listen = async () => {
|