@lvce-editor/iframe-worker 2.2.0 → 2.3.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 +63 -70
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const Two = '2.0';
|
|
2
|
-
const state$
|
|
2
|
+
const state$2 = {
|
|
3
3
|
callbacks: Object.create(null)
|
|
4
4
|
};
|
|
5
5
|
const set = (id, fn) => {
|
|
6
|
-
state$
|
|
6
|
+
state$2.callbacks[id] = fn;
|
|
7
7
|
};
|
|
8
8
|
const get = id => {
|
|
9
|
-
return state$
|
|
9
|
+
return state$2.callbacks[id];
|
|
10
10
|
};
|
|
11
11
|
const remove = id => {
|
|
12
|
-
delete state$
|
|
12
|
+
delete state$2.callbacks[id];
|
|
13
13
|
};
|
|
14
14
|
let id = 0;
|
|
15
15
|
const create$3 = () => {
|
|
@@ -328,10 +328,10 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
328
328
|
const responseMessage = await promise;
|
|
329
329
|
return unwrapJsonRpcResult(responseMessage);
|
|
330
330
|
};
|
|
331
|
-
const invoke$
|
|
331
|
+
const invoke$4 = (ipc, method, ...params) => {
|
|
332
332
|
return invokeHelper(ipc, method, params, false);
|
|
333
333
|
};
|
|
334
|
-
const invokeAndTransfer$
|
|
334
|
+
const invokeAndTransfer$3 = (ipc, method, ...params) => {
|
|
335
335
|
return invokeHelper(ipc, method, params, true);
|
|
336
336
|
};
|
|
337
337
|
|
|
@@ -736,10 +736,10 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
736
736
|
const createRpc = ipc => {
|
|
737
737
|
const rpc = {
|
|
738
738
|
invoke(method, ...params) {
|
|
739
|
-
return invoke$
|
|
739
|
+
return invoke$4(ipc, method, ...params);
|
|
740
740
|
},
|
|
741
741
|
invokeAndTransfer(method, ...params) {
|
|
742
|
-
return invokeAndTransfer$
|
|
742
|
+
return invokeAndTransfer$3(ipc, method, ...params);
|
|
743
743
|
}
|
|
744
744
|
};
|
|
745
745
|
return rpc;
|
|
@@ -782,8 +782,28 @@ const WebWorkerRpcClient = {
|
|
|
782
782
|
create: create$1$1
|
|
783
783
|
};
|
|
784
784
|
|
|
785
|
+
const state$1 = {
|
|
786
|
+
rpc: undefined
|
|
787
|
+
};
|
|
788
|
+
const invoke$3 = (method, ...params) => {
|
|
789
|
+
const rpc = state$1.rpc;
|
|
790
|
+
// @ts-ignore
|
|
791
|
+
return rpc.invoke(method, ...params);
|
|
792
|
+
};
|
|
793
|
+
const invokeAndTransfer$2 = (method, ...params) => {
|
|
794
|
+
const rpc = state$1.rpc;
|
|
795
|
+
// @ts-ignore
|
|
796
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
797
|
+
};
|
|
798
|
+
const setRpc = rpc => {
|
|
799
|
+
state$1.rpc = rpc;
|
|
800
|
+
};
|
|
801
|
+
|
|
785
802
|
const invoke$2 = async (method, ...params) => {
|
|
786
|
-
|
|
803
|
+
return invoke$3('WebView.compatExtensionHostWorkerInvoke', method, ...params);
|
|
804
|
+
};
|
|
805
|
+
const invokeAndTransfer$1 = async (method, ...params) => {
|
|
806
|
+
return invokeAndTransfer$2('WebView.compatExtensionHostWorkerInvokeAndTransfer', method, ...params);
|
|
787
807
|
};
|
|
788
808
|
|
|
789
809
|
const createUrl = (protocol, host) => {
|
|
@@ -900,19 +920,23 @@ const getWebViewUri = (webViews, webViewId) => {
|
|
|
900
920
|
}
|
|
901
921
|
return webViewPath;
|
|
902
922
|
};
|
|
903
|
-
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root) => {
|
|
923
|
+
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform$1 = platform) => {
|
|
904
924
|
const webView = getWebView$1(webViews, webViewId);
|
|
905
925
|
const webViewUri = getWebViewUri(webViews, webViewId);
|
|
926
|
+
console.log({
|
|
927
|
+
webViews,
|
|
928
|
+
webViewId
|
|
929
|
+
});
|
|
906
930
|
if (!webViewUri) {
|
|
907
931
|
return undefined;
|
|
908
932
|
}
|
|
909
933
|
let iframeSrc = webViewUri;
|
|
910
934
|
let webViewRoot = webViewUri;
|
|
911
|
-
if (platform === Electron) {
|
|
935
|
+
if (platform$1 === Electron) {
|
|
912
936
|
const relativePath = new URL(webViewUri).pathname.replace('/index.html', '');
|
|
913
937
|
iframeSrc = `${WebView}://-${relativePath}/`;
|
|
914
938
|
// TODO
|
|
915
|
-
} else if (platform === Remote) {
|
|
939
|
+
} else if (platform$1 === Remote) {
|
|
916
940
|
const relativePath = new URL(webViewUri).pathname.replace('/index.html', '');
|
|
917
941
|
if (webViewUri.startsWith('file://')) {
|
|
918
942
|
// ignore
|
|
@@ -1047,10 +1071,10 @@ class VError extends Error {
|
|
|
1047
1071
|
}
|
|
1048
1072
|
}
|
|
1049
1073
|
|
|
1050
|
-
const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin) => {
|
|
1074
|
+
const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform$1 = platform) => {
|
|
1051
1075
|
try {
|
|
1052
1076
|
const webView = getWebView(webViews, webViewId);
|
|
1053
|
-
if (platform === Web) {
|
|
1077
|
+
if (platform$1 === Web) {
|
|
1054
1078
|
return getIframeSrc$1(webView, locationOrigin);
|
|
1055
1079
|
}
|
|
1056
1080
|
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root);
|
|
@@ -1130,40 +1154,8 @@ const getWebViewOrigin = webViewPort => {
|
|
|
1130
1154
|
return origin;
|
|
1131
1155
|
};
|
|
1132
1156
|
|
|
1133
|
-
const invoke$1 = async (method, ...params) => {
|
|
1134
|
-
// TODO
|
|
1135
|
-
};
|
|
1136
|
-
|
|
1137
|
-
const getWebViewsNode = async () => {
|
|
1138
|
-
const webViews = await invoke$1();
|
|
1139
|
-
return webViews;
|
|
1140
|
-
};
|
|
1141
|
-
|
|
1142
|
-
const getWebViewsWeb = async () => {
|
|
1143
|
-
// const url = `${AssetDir.assetDir}/config/webViews.json`
|
|
1144
|
-
// TODO move this to shared-process-web / network-process-web
|
|
1145
|
-
// TODO handle error ?
|
|
1146
|
-
// TODO use parent rpc invoke
|
|
1147
|
-
// return Command.execute(/* Ajax.getJson */ 'Ajax.getJson', /* url */ url)
|
|
1148
|
-
return [];
|
|
1149
|
-
};
|
|
1150
|
-
|
|
1151
|
-
const getWebViewsDefault = async () => {
|
|
1152
|
-
switch (platform) {
|
|
1153
|
-
case Web:
|
|
1154
|
-
return getWebViewsWeb();
|
|
1155
|
-
case Test:
|
|
1156
|
-
return [];
|
|
1157
|
-
default:
|
|
1158
|
-
return getWebViewsNode();
|
|
1159
|
-
}
|
|
1160
|
-
};
|
|
1161
1157
|
const getWebViews = async () => {
|
|
1162
|
-
|
|
1163
|
-
// TODO ask renderer worker for webviews
|
|
1164
|
-
// const registeredWebViews = WebViews.get()
|
|
1165
|
-
const allWebViews = [...nodeWebViews];
|
|
1166
|
-
return allWebViews;
|
|
1158
|
+
return invoke$3('WebView.getWebViews');
|
|
1167
1159
|
};
|
|
1168
1160
|
|
|
1169
1161
|
const AllowScripts = 'allow-scripts';
|
|
@@ -1197,28 +1189,32 @@ const getProtocol = () => {
|
|
|
1197
1189
|
return location.protocol;
|
|
1198
1190
|
};
|
|
1199
1191
|
|
|
1200
|
-
const invoke = async (method, ...params) => {
|
|
1201
|
-
|
|
1192
|
+
const invoke$1 = async (method, ...params) => {
|
|
1193
|
+
return invoke$3('WebView.compatRendererProcessInvoke', method, ...params);
|
|
1202
1194
|
};
|
|
1203
1195
|
const invokeAndTransfer = async (method, ...params) => {
|
|
1204
|
-
|
|
1196
|
+
return invokeAndTransfer$2('WebView.compatRendererProcessInvokeAndTransfer', method, ...params);
|
|
1205
1197
|
};
|
|
1206
1198
|
|
|
1207
1199
|
const setPort = async (uid, port, origin, portType) => {
|
|
1208
1200
|
await invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
|
|
1209
1201
|
};
|
|
1210
1202
|
|
|
1203
|
+
const invoke = async (method, ...params) => {
|
|
1204
|
+
return invoke$3('WebView.compatSharedProcessInvoke', method, ...params);
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1211
1207
|
const registerProtocol = async () => {
|
|
1212
|
-
await invoke
|
|
1208
|
+
await invoke('WebViewServer.registerProtocol');
|
|
1213
1209
|
};
|
|
1214
1210
|
const create = async previewServerId => {
|
|
1215
|
-
await invoke
|
|
1211
|
+
await invoke('WebViewServer.create', previewServerId);
|
|
1216
1212
|
};
|
|
1217
1213
|
const start = async (previewServerId, webViewPort) => {
|
|
1218
|
-
await invoke
|
|
1214
|
+
await invoke('WebViewServer.start', previewServerId, webViewPort);
|
|
1219
1215
|
};
|
|
1220
1216
|
const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent) => {
|
|
1221
|
-
await invoke
|
|
1217
|
+
await invoke('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1222
1218
|
};
|
|
1223
1219
|
|
|
1224
1220
|
const register$3 = async previewServerId => {
|
|
@@ -1278,18 +1274,18 @@ const create2 = async ({
|
|
|
1278
1274
|
webViewId,
|
|
1279
1275
|
previewServerId,
|
|
1280
1276
|
uri,
|
|
1281
|
-
platform
|
|
1277
|
+
platform,
|
|
1282
1278
|
isGitpod
|
|
1283
1279
|
}) => {
|
|
1284
1280
|
let root = '';
|
|
1285
1281
|
if (platform === Remote) {
|
|
1286
|
-
root = await invoke
|
|
1282
|
+
root = await invoke('Platform.getRoot');
|
|
1287
1283
|
}
|
|
1288
1284
|
const webViews = await getWebViews();
|
|
1289
1285
|
const locationProtocol = getProtocol();
|
|
1290
1286
|
const locationHost = getHost();
|
|
1291
1287
|
const locationOrigin = getOrigin();
|
|
1292
|
-
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin);
|
|
1288
|
+
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform);
|
|
1293
1289
|
if (!iframeResult) {
|
|
1294
1290
|
return undefined;
|
|
1295
1291
|
}
|
|
@@ -1311,26 +1307,22 @@ const create2 = async ({
|
|
|
1311
1307
|
// 4. create webview in extension host worker and load content
|
|
1312
1308
|
|
|
1313
1309
|
const csp = getWebViewCsp(webView);
|
|
1314
|
-
const sandbox = getIframeSandbox(webView, platform
|
|
1315
|
-
const iframeCsp = platform
|
|
1310
|
+
const sandbox = getIframeSandbox(webView, platform);
|
|
1311
|
+
const iframeCsp = platform === Web ? csp : '';
|
|
1316
1312
|
const credentialless = true;
|
|
1317
|
-
|
|
1318
|
-
// TODO ask renderer worker to activate
|
|
1319
|
-
// await ExtensionHostManagement.activateByEvent(`onWebView:${webViewId}`)
|
|
1313
|
+
await invoke$3('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
|
|
1320
1314
|
const {
|
|
1321
|
-
port1
|
|
1315
|
+
port1,
|
|
1316
|
+
port2
|
|
1322
1317
|
} = getPortTuple();
|
|
1323
1318
|
const portId = create$1();
|
|
1324
1319
|
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
|
|
1325
|
-
await invoke('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless);
|
|
1326
|
-
await invoke('WebView.load', id);
|
|
1320
|
+
await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless);
|
|
1321
|
+
await invoke$1('WebView.load', id);
|
|
1327
1322
|
const origin = getWebViewOrigin(webViewPort);
|
|
1328
1323
|
const portType = '';
|
|
1329
1324
|
await setPort(id, port1, origin, portType);
|
|
1330
|
-
|
|
1331
|
-
// TODO
|
|
1332
|
-
// await ExtensionHostWorker.invokeAndTransfer('ExtensionHostWebView.create', webViewId, port2, uri, id, origin)
|
|
1333
|
-
|
|
1325
|
+
await invokeAndTransfer$1('ExtensionHostWebView.create', webViewId, port2, uri, id, origin);
|
|
1334
1326
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1335
1327
|
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1336
1328
|
return {
|
|
@@ -1360,9 +1352,10 @@ const commandMap = {
|
|
|
1360
1352
|
};
|
|
1361
1353
|
|
|
1362
1354
|
const listen = async () => {
|
|
1363
|
-
await WebWorkerRpcClient.create({
|
|
1355
|
+
const rpc = await WebWorkerRpcClient.create({
|
|
1364
1356
|
commandMap: commandMap
|
|
1365
1357
|
});
|
|
1358
|
+
setRpc(rpc);
|
|
1366
1359
|
};
|
|
1367
1360
|
|
|
1368
1361
|
const main = async () => {
|