@lvce-editor/editor-worker 2.5.0 → 2.6.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/editorWorkerMain.js +125 -32
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -1256,7 +1256,6 @@ const getErrorConstructor = (message, type) => {
|
|
|
1256
1256
|
if (type) {
|
|
1257
1257
|
switch (type) {
|
|
1258
1258
|
case DomException:
|
|
1259
|
-
// @ts-ignore
|
|
1260
1259
|
return DOMException;
|
|
1261
1260
|
case TypeError$1:
|
|
1262
1261
|
return TypeError;
|
|
@@ -1281,7 +1280,6 @@ const getErrorConstructor = (message, type) => {
|
|
|
1281
1280
|
};
|
|
1282
1281
|
const constructError = (message, type, name) => {
|
|
1283
1282
|
const ErrorConstructor = getErrorConstructor(message, type);
|
|
1284
|
-
// @ts-ignore
|
|
1285
1283
|
if (ErrorConstructor === DOMException && name) {
|
|
1286
1284
|
return new ErrorConstructor(message, name);
|
|
1287
1285
|
}
|
|
@@ -1297,6 +1295,13 @@ const constructError = (message, type, name) => {
|
|
|
1297
1295
|
const getNewLineIndex$2 = (string, startIndex = undefined) => {
|
|
1298
1296
|
return string.indexOf(NewLine$3, startIndex);
|
|
1299
1297
|
};
|
|
1298
|
+
const getParentStack = error => {
|
|
1299
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
1300
|
+
if (parentStack.startsWith(' at')) {
|
|
1301
|
+
parentStack = error.message + NewLine$3 + parentStack;
|
|
1302
|
+
}
|
|
1303
|
+
return parentStack;
|
|
1304
|
+
};
|
|
1300
1305
|
const joinLines$1 = lines => {
|
|
1301
1306
|
return lines.join(NewLine$3);
|
|
1302
1307
|
};
|
|
@@ -1305,18 +1310,11 @@ const Custom = -32001;
|
|
|
1305
1310
|
const splitLines$1 = lines => {
|
|
1306
1311
|
return lines.split(NewLine$3);
|
|
1307
1312
|
};
|
|
1308
|
-
const getParentStack = error => {
|
|
1309
|
-
let parentStack = error.stack || error.data || error.message || '';
|
|
1310
|
-
if (parentStack.startsWith(' at')) {
|
|
1311
|
-
parentStack = error.message + NewLine$3 + parentStack;
|
|
1312
|
-
}
|
|
1313
|
-
return parentStack;
|
|
1314
|
-
};
|
|
1315
1313
|
const restoreJsonRpcError = error => {
|
|
1316
1314
|
if (error && error instanceof Error) {
|
|
1317
1315
|
return error;
|
|
1318
1316
|
}
|
|
1319
|
-
const currentStack = joinLines$1(splitLines$1(new Error().stack).slice(1));
|
|
1317
|
+
const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(1));
|
|
1320
1318
|
if (error && error.code && error.code === MethodNotFound) {
|
|
1321
1319
|
const restoredError = new JsonRpcError(error.message);
|
|
1322
1320
|
const parentStack = getParentStack(error);
|
|
@@ -1345,7 +1343,6 @@ const restoreJsonRpcError = error => {
|
|
|
1345
1343
|
}
|
|
1346
1344
|
} else {
|
|
1347
1345
|
if (error.stack) {
|
|
1348
|
-
// TODO accessing stack might be slow
|
|
1349
1346
|
const lowerStack = restoredError.stack || '';
|
|
1350
1347
|
// @ts-ignore
|
|
1351
1348
|
const indexNewLine = getNewLineIndex$2(lowerStack);
|
|
@@ -1375,6 +1372,67 @@ const unwrapJsonRpcResult = responseMessage => {
|
|
|
1375
1372
|
}
|
|
1376
1373
|
throw new JsonRpcError('unexpected response message');
|
|
1377
1374
|
};
|
|
1375
|
+
const isMessagePort = value => {
|
|
1376
|
+
return typeof MessagePort !== 'undefined' && value instanceof MessagePort;
|
|
1377
|
+
};
|
|
1378
|
+
const isInstanceOf = (value, constructorName) => {
|
|
1379
|
+
return value?.constructor?.name === constructorName;
|
|
1380
|
+
};
|
|
1381
|
+
const isMessagePortMain = value => {
|
|
1382
|
+
return isInstanceOf(value, 'MessagePortMain');
|
|
1383
|
+
};
|
|
1384
|
+
const isOffscreenCanvas = value => {
|
|
1385
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
1386
|
+
};
|
|
1387
|
+
const isSocket = value => {
|
|
1388
|
+
return isInstanceOf(value, 'Socket');
|
|
1389
|
+
};
|
|
1390
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
1391
|
+
const isTransferrable = value => {
|
|
1392
|
+
for (const fn of transferrables) {
|
|
1393
|
+
if (fn(value)) {
|
|
1394
|
+
return true;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
return false;
|
|
1398
|
+
};
|
|
1399
|
+
const walkValue = (value, transferrables) => {
|
|
1400
|
+
if (!value) {
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
if (isTransferrable(value)) {
|
|
1404
|
+
transferrables.push(value);
|
|
1405
|
+
}
|
|
1406
|
+
if (Array.isArray(value)) {
|
|
1407
|
+
for (const item of value) {
|
|
1408
|
+
walkValue(item, transferrables);
|
|
1409
|
+
}
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
if (typeof value === 'object') {
|
|
1413
|
+
for (const property of Object.values(value)) {
|
|
1414
|
+
walkValue(property, transferrables);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
const getTransferrables = value => {
|
|
1419
|
+
const transferrables = [];
|
|
1420
|
+
walkValue(value, transferrables);
|
|
1421
|
+
return transferrables;
|
|
1422
|
+
};
|
|
1423
|
+
const isSingleTransferrable = value => {
|
|
1424
|
+
return isSocket(value);
|
|
1425
|
+
};
|
|
1426
|
+
const getTransferrableParams = value => {
|
|
1427
|
+
const transferrables = getTransferrables(value);
|
|
1428
|
+
if (transferrables.length === 0) {
|
|
1429
|
+
return undefined;
|
|
1430
|
+
}
|
|
1431
|
+
if (isSingleTransferrable(transferrables[0])) {
|
|
1432
|
+
return transferrables[0];
|
|
1433
|
+
}
|
|
1434
|
+
return transferrables;
|
|
1435
|
+
};
|
|
1378
1436
|
const create$1$1 = (message, error) => {
|
|
1379
1437
|
return {
|
|
1380
1438
|
jsonrpc: Two,
|
|
@@ -1427,7 +1485,42 @@ const getResponse = async (message, ipc, execute, preparePrettyError, logError,
|
|
|
1427
1485
|
return getErrorResponse(message, error, preparePrettyError, logError);
|
|
1428
1486
|
}
|
|
1429
1487
|
};
|
|
1430
|
-
const
|
|
1488
|
+
const defaultPreparePrettyError = error => {
|
|
1489
|
+
return error;
|
|
1490
|
+
};
|
|
1491
|
+
const defaultLogError = () => {
|
|
1492
|
+
// ignore
|
|
1493
|
+
};
|
|
1494
|
+
const defaultRequiresSocket = () => {
|
|
1495
|
+
return false;
|
|
1496
|
+
};
|
|
1497
|
+
const defaultResolve = resolve;
|
|
1498
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
1499
|
+
let message;
|
|
1500
|
+
let ipc;
|
|
1501
|
+
let execute;
|
|
1502
|
+
let preparePrettyError;
|
|
1503
|
+
let logError;
|
|
1504
|
+
let resolve;
|
|
1505
|
+
let requiresSocket;
|
|
1506
|
+
if (args.length === 1) {
|
|
1507
|
+
const arg = args[0];
|
|
1508
|
+
message = arg.message;
|
|
1509
|
+
ipc = arg.ipc;
|
|
1510
|
+
execute = arg.execute;
|
|
1511
|
+
preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
|
|
1512
|
+
logError = arg.logError || defaultLogError;
|
|
1513
|
+
requiresSocket = arg.requiresSocket || defaultRequiresSocket;
|
|
1514
|
+
resolve = arg.resolve || defaultResolve;
|
|
1515
|
+
} else {
|
|
1516
|
+
ipc = args[0];
|
|
1517
|
+
message = args[1];
|
|
1518
|
+
execute = args[2];
|
|
1519
|
+
resolve = args[3];
|
|
1520
|
+
preparePrettyError = args[4];
|
|
1521
|
+
logError = args[5];
|
|
1522
|
+
requiresSocket = args[6];
|
|
1523
|
+
}
|
|
1431
1524
|
if ('id' in message) {
|
|
1432
1525
|
if ('method' in message) {
|
|
1433
1526
|
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
@@ -1458,12 +1551,21 @@ const invoke$5 = async (ipc, method, ...params) => {
|
|
|
1458
1551
|
const result = unwrapJsonRpcResult(responseMessage);
|
|
1459
1552
|
return result;
|
|
1460
1553
|
};
|
|
1554
|
+
|
|
1555
|
+
// TODO deprecated old typings,
|
|
1556
|
+
// always use automatic transferrable detection
|
|
1461
1557
|
const invokeAndTransfer$2 = async (ipc, handle, method, ...params) => {
|
|
1558
|
+
let transfer = handle;
|
|
1559
|
+
if (typeof handle === 'string') {
|
|
1560
|
+
params = [method, ...params];
|
|
1561
|
+
method = handle;
|
|
1562
|
+
transfer = getTransferrableParams(params);
|
|
1563
|
+
}
|
|
1462
1564
|
const {
|
|
1463
1565
|
message,
|
|
1464
1566
|
promise
|
|
1465
1567
|
} = create$2$1(method, params);
|
|
1466
|
-
ipc.sendAndTransfer(message,
|
|
1568
|
+
ipc.sendAndTransfer(message, transfer);
|
|
1467
1569
|
const responseMessage = await promise;
|
|
1468
1570
|
const result = unwrapJsonRpcResult(responseMessage);
|
|
1469
1571
|
return result;
|
|
@@ -1567,9 +1669,9 @@ const invoke$4 = (method, ...params) => {
|
|
|
1567
1669
|
const ipc = get$4();
|
|
1568
1670
|
return invoke$5(ipc, method, ...params);
|
|
1569
1671
|
};
|
|
1570
|
-
const invokeAndTransfer$1 = async (
|
|
1672
|
+
const invokeAndTransfer$1 = async (method, ...params) => {
|
|
1571
1673
|
const ipc = get$4();
|
|
1572
|
-
return invokeAndTransfer$2(ipc,
|
|
1674
|
+
return invokeAndTransfer$2(ipc, method, ...params);
|
|
1573
1675
|
};
|
|
1574
1676
|
const listen$8 = ipc => {
|
|
1575
1677
|
set$4(ipc);
|
|
@@ -1578,12 +1680,12 @@ const listen$8 = ipc => {
|
|
|
1578
1680
|
const invoke$3 = async (method, ...params) => {
|
|
1579
1681
|
return invoke$4(method, ...params);
|
|
1580
1682
|
};
|
|
1581
|
-
const invokeAndTransfer = async (
|
|
1582
|
-
return invokeAndTransfer$1(
|
|
1683
|
+
const invokeAndTransfer = async (method, ...params) => {
|
|
1684
|
+
return invokeAndTransfer$1(method, ...params);
|
|
1583
1685
|
};
|
|
1584
1686
|
|
|
1585
1687
|
const sendMessagePortToExtensionHostWorker = async port => {
|
|
1586
|
-
await invokeAndTransfer(
|
|
1688
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, 'HandleMessagePort.handleMessagePort');
|
|
1587
1689
|
};
|
|
1588
1690
|
|
|
1589
1691
|
const withResolvers$1 = () => {
|
|
@@ -1664,7 +1766,7 @@ const IpcParentWithExtensionHostWorker = {
|
|
|
1664
1766
|
};
|
|
1665
1767
|
|
|
1666
1768
|
const sendMessagePortToSyntaxHighlightingWorker = async port => {
|
|
1667
|
-
await invokeAndTransfer(
|
|
1769
|
+
await invokeAndTransfer('SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort');
|
|
1668
1770
|
};
|
|
1669
1771
|
|
|
1670
1772
|
const create$3 = async () => {
|
|
@@ -1717,7 +1819,7 @@ const IpcParentWithSyntaxHighlightingWorker = {
|
|
|
1717
1819
|
};
|
|
1718
1820
|
|
|
1719
1821
|
const sendMessagePortToRendererProcess = async port => {
|
|
1720
|
-
await invokeAndTransfer(
|
|
1822
|
+
await invokeAndTransfer('SendMessagePortToRendererProcess.sendMessagePortToRendererProcess', port, 'HandleMessagePort.handleMessagePort');
|
|
1721
1823
|
};
|
|
1722
1824
|
|
|
1723
1825
|
const create$2 = async () => {
|
|
@@ -2364,19 +2466,14 @@ const closeCompletion = editor => {
|
|
|
2364
2466
|
};
|
|
2365
2467
|
};
|
|
2366
2468
|
|
|
2367
|
-
// @ts-ignore
|
|
2368
2469
|
const state$6 = {
|
|
2369
2470
|
isComposing: false,
|
|
2370
2471
|
compositionText: ''
|
|
2371
2472
|
};
|
|
2372
|
-
|
|
2373
|
-
// @ts-ignore
|
|
2374
2473
|
const compositionStart = (editor, event) => {
|
|
2375
2474
|
state$6.isComposing = true;
|
|
2376
2475
|
return editor;
|
|
2377
2476
|
};
|
|
2378
|
-
|
|
2379
|
-
// @ts-ignore
|
|
2380
2477
|
const getCompositionChanges = (selections, data) => {
|
|
2381
2478
|
const changes = [];
|
|
2382
2479
|
for (let i = 0; i < selections.length; i += 4) {
|
|
@@ -2401,16 +2498,12 @@ const getCompositionChanges = (selections, data) => {
|
|
|
2401
2498
|
}
|
|
2402
2499
|
return changes;
|
|
2403
2500
|
};
|
|
2404
|
-
|
|
2405
|
-
// @ts-ignore
|
|
2406
2501
|
const compositionUpdate = (editor, data) => {
|
|
2407
2502
|
const selections = editor.selections;
|
|
2408
2503
|
const changes = getCompositionChanges(selections, data);
|
|
2409
2504
|
state$6.compositionText = data;
|
|
2410
2505
|
return scheduleDocumentAndCursorsSelections(editor, changes);
|
|
2411
2506
|
};
|
|
2412
|
-
|
|
2413
|
-
// @ts-ignore
|
|
2414
2507
|
const compositionEnd = (editor, data) => {
|
|
2415
2508
|
const selections = editor.selections;
|
|
2416
2509
|
const changes = getCompositionChanges(selections, data);
|
|
@@ -8782,14 +8875,14 @@ const commandMap = {
|
|
|
8782
8875
|
};
|
|
8783
8876
|
wrapCommands(commandMap);
|
|
8784
8877
|
|
|
8785
|
-
const MessagePort = 1;
|
|
8878
|
+
const MessagePort$1 = 1;
|
|
8786
8879
|
const ModuleWorker = 2;
|
|
8787
8880
|
const ReferencePort = 3;
|
|
8788
8881
|
const ModuleWorkerAndMessagePort = 8;
|
|
8789
8882
|
const Auto = () => {
|
|
8790
8883
|
// @ts-ignore
|
|
8791
8884
|
if (globalThis.acceptPort) {
|
|
8792
|
-
return MessagePort;
|
|
8885
|
+
return MessagePort$1;
|
|
8793
8886
|
}
|
|
8794
8887
|
// @ts-ignore
|
|
8795
8888
|
if (globalThis.acceptReferencePort) {
|
|
@@ -9177,7 +9270,7 @@ const getModule = method => {
|
|
|
9177
9270
|
return IpcChildWithModuleWorker$1;
|
|
9178
9271
|
case ModuleWorkerAndMessagePort:
|
|
9179
9272
|
return IpcChildWithModuleWorkerAndMessagePort$1;
|
|
9180
|
-
case MessagePort:
|
|
9273
|
+
case MessagePort$1:
|
|
9181
9274
|
return IpcChildWithMessagePort$1;
|
|
9182
9275
|
default:
|
|
9183
9276
|
throw new Error('unexpected ipc type');
|