@lvce-editor/main-area-worker 7.2.0 → 7.4.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/mainAreaWorkerMain.js +180 -5
- package/package.json +1 -1
|
@@ -105,6 +105,7 @@ const Tab = 13;
|
|
|
105
105
|
const Separator = 1;
|
|
106
106
|
const None = 0;
|
|
107
107
|
|
|
108
|
+
const ClipBoardWorker = 3400;
|
|
108
109
|
const ExtensionHostWorker = 44;
|
|
109
110
|
const IconThemeWorker = 7009;
|
|
110
111
|
const RendererWorker = 1;
|
|
@@ -273,6 +274,55 @@ const getTransferrables = value => {
|
|
|
273
274
|
walkValue(value, transferrables, isTransferrable);
|
|
274
275
|
return transferrables;
|
|
275
276
|
};
|
|
277
|
+
const removeValues = (value, toRemove) => {
|
|
278
|
+
if (!value) {
|
|
279
|
+
return value;
|
|
280
|
+
}
|
|
281
|
+
if (Array.isArray(value)) {
|
|
282
|
+
const newItems = [];
|
|
283
|
+
for (const item of value) {
|
|
284
|
+
if (!toRemove.includes(item)) {
|
|
285
|
+
newItems.push(removeValues(item, toRemove));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return newItems;
|
|
289
|
+
}
|
|
290
|
+
if (typeof value === 'object') {
|
|
291
|
+
const newObject = Object.create(null);
|
|
292
|
+
for (const [key, property] of Object.entries(value)) {
|
|
293
|
+
if (!toRemove.includes(property)) {
|
|
294
|
+
newObject[key] = removeValues(property, toRemove);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return newObject;
|
|
298
|
+
}
|
|
299
|
+
return value;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// workaround for electron not supporting transferrable objects
|
|
303
|
+
// as parameters. If the transferrable object is a parameter, in electron
|
|
304
|
+
// only an empty objected is received in the main process
|
|
305
|
+
const fixElectronParameters = value => {
|
|
306
|
+
const transfer = getTransferrables(value);
|
|
307
|
+
const newValue = removeValues(value, transfer);
|
|
308
|
+
return {
|
|
309
|
+
newValue,
|
|
310
|
+
transfer
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
const getActualDataElectron = event => {
|
|
314
|
+
const {
|
|
315
|
+
data,
|
|
316
|
+
ports
|
|
317
|
+
} = event;
|
|
318
|
+
if (ports.length === 0) {
|
|
319
|
+
return data;
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
...data,
|
|
323
|
+
params: [...ports, ...data.params]
|
|
324
|
+
};
|
|
325
|
+
};
|
|
276
326
|
const attachEvents = that => {
|
|
277
327
|
const handleMessage = (...args) => {
|
|
278
328
|
const data = that.getData(...args);
|
|
@@ -432,6 +482,48 @@ class IpcError extends VError {
|
|
|
432
482
|
this.stderr = stderr;
|
|
433
483
|
}
|
|
434
484
|
}
|
|
485
|
+
const listen$b = ({
|
|
486
|
+
messagePort
|
|
487
|
+
}) => {
|
|
488
|
+
if (!isMessagePortMain(messagePort)) {
|
|
489
|
+
throw new IpcError('port must be of type MessagePortMain');
|
|
490
|
+
}
|
|
491
|
+
return messagePort;
|
|
492
|
+
};
|
|
493
|
+
const signal$c = messagePort => {
|
|
494
|
+
messagePort.start();
|
|
495
|
+
};
|
|
496
|
+
class IpcChildWithElectronMessagePort extends Ipc {
|
|
497
|
+
getData = getActualDataElectron;
|
|
498
|
+
send(message) {
|
|
499
|
+
this._rawIpc.postMessage(message);
|
|
500
|
+
}
|
|
501
|
+
sendAndTransfer(message) {
|
|
502
|
+
const {
|
|
503
|
+
newValue,
|
|
504
|
+
transfer
|
|
505
|
+
} = fixElectronParameters(message);
|
|
506
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
507
|
+
}
|
|
508
|
+
dispose() {
|
|
509
|
+
this._rawIpc.close();
|
|
510
|
+
}
|
|
511
|
+
onMessage(callback) {
|
|
512
|
+
this._rawIpc.on('message', callback);
|
|
513
|
+
}
|
|
514
|
+
onClose(callback) {
|
|
515
|
+
this._rawIpc.on('close', callback);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
const wrap$j = messagePort => {
|
|
519
|
+
return new IpcChildWithElectronMessagePort(messagePort);
|
|
520
|
+
};
|
|
521
|
+
const IpcChildWithElectronMessagePort$1 = {
|
|
522
|
+
__proto__: null,
|
|
523
|
+
listen: listen$b,
|
|
524
|
+
signal: signal$c,
|
|
525
|
+
wrap: wrap$j
|
|
526
|
+
};
|
|
435
527
|
const readyMessage = 'ready';
|
|
436
528
|
const getData$2 = event => {
|
|
437
529
|
return event.data;
|
|
@@ -1083,6 +1175,23 @@ const listen$1 = async (module, options) => {
|
|
|
1083
1175
|
const ipc = module.wrap(rawIpc);
|
|
1084
1176
|
return ipc;
|
|
1085
1177
|
};
|
|
1178
|
+
const create$q = async ({
|
|
1179
|
+
commandMap,
|
|
1180
|
+
messagePort,
|
|
1181
|
+
requiresSocket
|
|
1182
|
+
}) => {
|
|
1183
|
+
// TODO create a commandMap per rpc instance
|
|
1184
|
+
register(commandMap);
|
|
1185
|
+
const ipc = await listen$1(IpcChildWithElectronMessagePort$1, {
|
|
1186
|
+
messagePort
|
|
1187
|
+
});
|
|
1188
|
+
if (requiresSocket) {
|
|
1189
|
+
ipc.requiresSocket = requiresSocket;
|
|
1190
|
+
}
|
|
1191
|
+
handleIpc(ipc);
|
|
1192
|
+
const rpc = createRpc(ipc);
|
|
1193
|
+
return rpc;
|
|
1194
|
+
};
|
|
1086
1195
|
|
|
1087
1196
|
/* eslint-disable @typescript-eslint/no-misused-promises */
|
|
1088
1197
|
|
|
@@ -1113,6 +1222,39 @@ const createSharedLazyRpc = factory => {
|
|
|
1113
1222
|
}
|
|
1114
1223
|
};
|
|
1115
1224
|
};
|
|
1225
|
+
const create$l = async ({
|
|
1226
|
+
commandMap,
|
|
1227
|
+
getPortTuple,
|
|
1228
|
+
send
|
|
1229
|
+
}) => {
|
|
1230
|
+
const {
|
|
1231
|
+
port1,
|
|
1232
|
+
port2
|
|
1233
|
+
} = await getPortTuple();
|
|
1234
|
+
await send(port1);
|
|
1235
|
+
const rpc = create$q({
|
|
1236
|
+
commandMap,
|
|
1237
|
+
messagePort: port2
|
|
1238
|
+
});
|
|
1239
|
+
return rpc;
|
|
1240
|
+
};
|
|
1241
|
+
const create$k = async ({
|
|
1242
|
+
commandMap,
|
|
1243
|
+
getPortTuple,
|
|
1244
|
+
send
|
|
1245
|
+
}) => {
|
|
1246
|
+
return createSharedLazyRpc(() => {
|
|
1247
|
+
return create$l({
|
|
1248
|
+
commandMap,
|
|
1249
|
+
getPortTuple,
|
|
1250
|
+
send
|
|
1251
|
+
});
|
|
1252
|
+
});
|
|
1253
|
+
};
|
|
1254
|
+
const LazyTransferElectronMessagePortRpc = {
|
|
1255
|
+
__proto__: null,
|
|
1256
|
+
create: create$k
|
|
1257
|
+
};
|
|
1116
1258
|
const create$j = async ({
|
|
1117
1259
|
commandMap,
|
|
1118
1260
|
isMessagePortOpen,
|
|
@@ -1202,7 +1344,7 @@ const createMockRpc = ({
|
|
|
1202
1344
|
};
|
|
1203
1345
|
|
|
1204
1346
|
const rpcs = Object.create(null);
|
|
1205
|
-
const set$
|
|
1347
|
+
const set$5 = (id, rpc) => {
|
|
1206
1348
|
rpcs[id] = rpc;
|
|
1207
1349
|
};
|
|
1208
1350
|
const get$1 = id => {
|
|
@@ -1235,7 +1377,7 @@ const create$2 = rpcId => {
|
|
|
1235
1377
|
const mockRpc = createMockRpc({
|
|
1236
1378
|
commandMap
|
|
1237
1379
|
});
|
|
1238
|
-
set$
|
|
1380
|
+
set$5(rpcId, mockRpc);
|
|
1239
1381
|
// @ts-ignore
|
|
1240
1382
|
mockRpc[Symbol.dispose] = () => {
|
|
1241
1383
|
remove(rpcId);
|
|
@@ -1244,11 +1386,15 @@ const create$2 = rpcId => {
|
|
|
1244
1386
|
return mockRpc;
|
|
1245
1387
|
},
|
|
1246
1388
|
set(rpc) {
|
|
1247
|
-
set$
|
|
1389
|
+
set$5(rpcId, rpc);
|
|
1248
1390
|
}
|
|
1249
1391
|
};
|
|
1250
1392
|
};
|
|
1251
1393
|
|
|
1394
|
+
const {
|
|
1395
|
+
set: set$4
|
|
1396
|
+
} = create$2(ClipBoardWorker);
|
|
1397
|
+
|
|
1252
1398
|
const {
|
|
1253
1399
|
set: set$3
|
|
1254
1400
|
} = create$2(ExtensionHostWorker);
|
|
@@ -1274,6 +1420,10 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
|
|
|
1274
1420
|
number(y);
|
|
1275
1421
|
await invoke('ContextMenu.show2', uid, menuId, x, y, args);
|
|
1276
1422
|
};
|
|
1423
|
+
const sendMessagePortToClipBoardWorker$1 = async (port, rpcId) => {
|
|
1424
|
+
const command = 'ClipBoard.handleMessagePort';
|
|
1425
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToClipBoardWorker', port, command, rpcId);
|
|
1426
|
+
};
|
|
1277
1427
|
const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
|
|
1278
1428
|
const command = 'IconTheme.handleMessagePort';
|
|
1279
1429
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
|
|
@@ -2811,7 +2961,19 @@ const tryRestoreLayout = savedState => {
|
|
|
2811
2961
|
if (!isValidMainAreaLayout(layout)) {
|
|
2812
2962
|
return undefined;
|
|
2813
2963
|
}
|
|
2814
|
-
|
|
2964
|
+
|
|
2965
|
+
// Normalize all tabs to have editorUid: -1 so SelectTab will create viewlets
|
|
2966
|
+
const normalizedLayout = {
|
|
2967
|
+
...layout,
|
|
2968
|
+
groups: layout.groups.map(group => ({
|
|
2969
|
+
...group,
|
|
2970
|
+
tabs: group.tabs.map(tab => ({
|
|
2971
|
+
...tab,
|
|
2972
|
+
editorUid: -1
|
|
2973
|
+
}))
|
|
2974
|
+
}))
|
|
2975
|
+
};
|
|
2976
|
+
return normalizedLayout;
|
|
2815
2977
|
};
|
|
2816
2978
|
|
|
2817
2979
|
const createViewlets = async (layout, viewletModuleIds, bounds) => {
|
|
@@ -4139,6 +4301,19 @@ const commandMap = {
|
|
|
4139
4301
|
'MainArea.terminate': terminate
|
|
4140
4302
|
};
|
|
4141
4303
|
|
|
4304
|
+
const sendMessagePortToClipBoardWorker = async port => {
|
|
4305
|
+
// @ts-ignore
|
|
4306
|
+
await sendMessagePortToClipBoardWorker$1(port, 0);
|
|
4307
|
+
};
|
|
4308
|
+
|
|
4309
|
+
const initializeClipBoardWorker = async () => {
|
|
4310
|
+
const rpc = await LazyTransferElectronMessagePortRpc.create({
|
|
4311
|
+
commandMap: {},
|
|
4312
|
+
send: sendMessagePortToClipBoardWorker
|
|
4313
|
+
});
|
|
4314
|
+
set$4(rpc);
|
|
4315
|
+
};
|
|
4316
|
+
|
|
4142
4317
|
const send = port => {
|
|
4143
4318
|
return sendMessagePortToIconThemeWorker(port, 0);
|
|
4144
4319
|
};
|
|
@@ -4168,7 +4343,7 @@ const initializeRendererWorker = async () => {
|
|
|
4168
4343
|
|
|
4169
4344
|
const listen = async () => {
|
|
4170
4345
|
registerCommands(commandMap);
|
|
4171
|
-
await Promise.all([initializeRendererWorker(), initializeIconThemeWorker()]);
|
|
4346
|
+
await Promise.all([initializeRendererWorker(), initializeIconThemeWorker(), initializeClipBoardWorker()]);
|
|
4172
4347
|
};
|
|
4173
4348
|
|
|
4174
4349
|
const main$2 = async () => {
|