@lvce-editor/main-area-worker 7.1.0 → 7.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/mainAreaWorkerMain.js +217 -6
- 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);
|
|
@@ -1678,9 +1824,14 @@ const closeOtherTabs = (state, groupId) => {
|
|
|
1678
1824
|
layout
|
|
1679
1825
|
} = state;
|
|
1680
1826
|
const {
|
|
1827
|
+
activeGroupId,
|
|
1681
1828
|
groups
|
|
1682
1829
|
} = layout;
|
|
1683
|
-
const
|
|
1830
|
+
const targetGroupId = groupId ?? activeGroupId;
|
|
1831
|
+
if (targetGroupId === undefined) {
|
|
1832
|
+
return state;
|
|
1833
|
+
}
|
|
1834
|
+
const group = groups.find(g => g.id === targetGroupId);
|
|
1684
1835
|
if (!group) {
|
|
1685
1836
|
return state;
|
|
1686
1837
|
}
|
|
@@ -1691,7 +1842,7 @@ const closeOtherTabs = (state, groupId) => {
|
|
|
1691
1842
|
return state;
|
|
1692
1843
|
}
|
|
1693
1844
|
const newGroups = groups.map(g => {
|
|
1694
|
-
if (g.id ===
|
|
1845
|
+
if (g.id === targetGroupId) {
|
|
1695
1846
|
const newTabs = g.tabs.filter(tab => tab.id === activeTabId);
|
|
1696
1847
|
return {
|
|
1697
1848
|
...g,
|
|
@@ -1711,6 +1862,51 @@ const closeOtherTabs = (state, groupId) => {
|
|
|
1711
1862
|
};
|
|
1712
1863
|
};
|
|
1713
1864
|
|
|
1865
|
+
const closeTabsRight = (state, groupId) => {
|
|
1866
|
+
const {
|
|
1867
|
+
layout
|
|
1868
|
+
} = state;
|
|
1869
|
+
const {
|
|
1870
|
+
groups
|
|
1871
|
+
} = layout;
|
|
1872
|
+
const group = groups.find(g => g.id === groupId);
|
|
1873
|
+
if (!group) {
|
|
1874
|
+
return state;
|
|
1875
|
+
}
|
|
1876
|
+
const {
|
|
1877
|
+
activeTabId,
|
|
1878
|
+
tabs
|
|
1879
|
+
} = group;
|
|
1880
|
+
if (activeTabId === undefined) {
|
|
1881
|
+
return state;
|
|
1882
|
+
}
|
|
1883
|
+
const activeTabIndex = tabs.findIndex(tab => tab.id === activeTabId);
|
|
1884
|
+
if (activeTabIndex === -1) {
|
|
1885
|
+
return state;
|
|
1886
|
+
}
|
|
1887
|
+
const newTabs = tabs.slice(0, activeTabIndex + 1);
|
|
1888
|
+
if (newTabs.length === tabs.length) {
|
|
1889
|
+
return state;
|
|
1890
|
+
}
|
|
1891
|
+
const newGroups = groups.map(g => {
|
|
1892
|
+
if (g.id === groupId) {
|
|
1893
|
+
return {
|
|
1894
|
+
...g,
|
|
1895
|
+
isEmpty: newTabs.length === 0,
|
|
1896
|
+
tabs: newTabs
|
|
1897
|
+
};
|
|
1898
|
+
}
|
|
1899
|
+
return g;
|
|
1900
|
+
});
|
|
1901
|
+
return {
|
|
1902
|
+
...state,
|
|
1903
|
+
layout: {
|
|
1904
|
+
...layout,
|
|
1905
|
+
groups: newGroups
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
};
|
|
1909
|
+
|
|
1714
1910
|
const copyPath$1 = async (state, path) => {
|
|
1715
1911
|
string(path);
|
|
1716
1912
|
await invoke('ClipBoard.writeText', path);
|
|
@@ -1741,6 +1937,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir, tabHeight = 3
|
|
|
1741
1937
|
tabHeight,
|
|
1742
1938
|
uid,
|
|
1743
1939
|
width,
|
|
1940
|
+
workspaceuri: uri,
|
|
1744
1941
|
x,
|
|
1745
1942
|
y
|
|
1746
1943
|
};
|
|
@@ -4049,6 +4246,7 @@ const commandMap = {
|
|
|
4049
4246
|
'MainArea.closeAllEditors': wrapCommand(closeAll$1),
|
|
4050
4247
|
'MainArea.closeFocusedTab': wrapCommand(closeFocusedTab),
|
|
4051
4248
|
'MainArea.closeOthers': wrapCommand(closeOtherTabs),
|
|
4249
|
+
'MainArea.closeTabsRight': wrapCommand(closeTabsRight),
|
|
4052
4250
|
'MainArea.copyPath': wrapCommand(copyPath$1),
|
|
4053
4251
|
'MainArea.copyRelativePath': wrapCommand(copyRelativePath$1),
|
|
4054
4252
|
'MainArea.create': create,
|
|
@@ -4087,6 +4285,19 @@ const commandMap = {
|
|
|
4087
4285
|
'MainArea.terminate': terminate
|
|
4088
4286
|
};
|
|
4089
4287
|
|
|
4288
|
+
const sendMessagePortToClipBoardWorker = async port => {
|
|
4289
|
+
// @ts-ignore
|
|
4290
|
+
await undefined(port, 0);
|
|
4291
|
+
};
|
|
4292
|
+
|
|
4293
|
+
const initializeClipBoardWorker = async () => {
|
|
4294
|
+
const rpc = await LazyTransferElectronMessagePortRpc.create({
|
|
4295
|
+
commandMap: {},
|
|
4296
|
+
send: sendMessagePortToClipBoardWorker
|
|
4297
|
+
});
|
|
4298
|
+
set$4(rpc);
|
|
4299
|
+
};
|
|
4300
|
+
|
|
4090
4301
|
const send = port => {
|
|
4091
4302
|
return sendMessagePortToIconThemeWorker(port, 0);
|
|
4092
4303
|
};
|
|
@@ -4116,7 +4327,7 @@ const initializeRendererWorker = async () => {
|
|
|
4116
4327
|
|
|
4117
4328
|
const listen = async () => {
|
|
4118
4329
|
registerCommands(commandMap);
|
|
4119
|
-
await Promise.all([initializeRendererWorker(), initializeIconThemeWorker()]);
|
|
4330
|
+
await Promise.all([initializeRendererWorker(), initializeIconThemeWorker(), initializeClipBoardWorker()]);
|
|
4120
4331
|
};
|
|
4121
4332
|
|
|
4122
4333
|
const main$2 = async () => {
|