@lvce-editor/main-area-worker 1.5.0 → 1.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/mainAreaWorkerMain.js +33 -277
- package/package.json +1 -1
|
@@ -102,12 +102,6 @@ const number = value => {
|
|
|
102
102
|
throw new AssertionError('expected value to be of type number');
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
-
const string = value => {
|
|
106
|
-
const type = getType(value);
|
|
107
|
-
if (type !== String) {
|
|
108
|
-
throw new AssertionError('expected value to be of type string');
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
105
|
|
|
112
106
|
const isMessagePort = value => {
|
|
113
107
|
return value && value instanceof MessagePort;
|
|
@@ -462,7 +456,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
|
|
|
462
456
|
return promise;
|
|
463
457
|
};
|
|
464
458
|
const Message$1 = 3;
|
|
465
|
-
const create$5
|
|
459
|
+
const create$5 = async ({
|
|
466
460
|
isMessagePortOpen,
|
|
467
461
|
messagePort
|
|
468
462
|
}) => {
|
|
@@ -513,7 +507,7 @@ const wrap$5 = messagePort => {
|
|
|
513
507
|
};
|
|
514
508
|
const IpcParentWithMessagePort$1 = {
|
|
515
509
|
__proto__: null,
|
|
516
|
-
create: create$5
|
|
510
|
+
create: create$5,
|
|
517
511
|
signal: signal$1,
|
|
518
512
|
wrap: wrap$5
|
|
519
513
|
};
|
|
@@ -732,7 +726,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
732
726
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
733
727
|
return create$1$2(id, errorProperty);
|
|
734
728
|
};
|
|
735
|
-
const create$
|
|
729
|
+
const create$3 = (message, result) => {
|
|
736
730
|
return {
|
|
737
731
|
jsonrpc: Two$1,
|
|
738
732
|
id: message.id,
|
|
@@ -741,7 +735,7 @@ const create$5 = (message, result) => {
|
|
|
741
735
|
};
|
|
742
736
|
const getSuccessResponse = (message, result) => {
|
|
743
737
|
const resultProperty = result ?? null;
|
|
744
|
-
return create$
|
|
738
|
+
return create$3(message, resultProperty);
|
|
745
739
|
};
|
|
746
740
|
const getErrorResponseSimple = (id, error) => {
|
|
747
741
|
return {
|
|
@@ -1065,7 +1059,7 @@ const remove = id => {
|
|
|
1065
1059
|
};
|
|
1066
1060
|
|
|
1067
1061
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1068
|
-
const create$
|
|
1062
|
+
const create$2 = rpcId => {
|
|
1069
1063
|
return {
|
|
1070
1064
|
async dispose() {
|
|
1071
1065
|
const rpc = get$1(rpcId);
|
|
@@ -1103,12 +1097,12 @@ const create$3 = rpcId => {
|
|
|
1103
1097
|
|
|
1104
1098
|
const {
|
|
1105
1099
|
set: set$2
|
|
1106
|
-
} = create$
|
|
1100
|
+
} = create$2(ExtensionHostWorker);
|
|
1107
1101
|
|
|
1108
1102
|
const {
|
|
1109
1103
|
invokeAndTransfer,
|
|
1110
1104
|
set: set$1
|
|
1111
|
-
} = create$
|
|
1105
|
+
} = create$2(RendererWorker);
|
|
1112
1106
|
const sendMessagePortToExtensionHostWorker$1 = async (port, rpcId = 0) => {
|
|
1113
1107
|
const command = 'HandleMessagePort.handleMessagePort2';
|
|
1114
1108
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
|
|
@@ -1118,7 +1112,7 @@ const toCommandId = key => {
|
|
|
1118
1112
|
const dotIndex = key.indexOf('.');
|
|
1119
1113
|
return key.slice(dotIndex + 1);
|
|
1120
1114
|
};
|
|
1121
|
-
const create$
|
|
1115
|
+
const create$1 = () => {
|
|
1122
1116
|
const states = Object.create(null);
|
|
1123
1117
|
const commandMapRef = {};
|
|
1124
1118
|
return {
|
|
@@ -1204,9 +1198,9 @@ const {
|
|
|
1204
1198
|
getCommandIds,
|
|
1205
1199
|
registerCommands,
|
|
1206
1200
|
set,
|
|
1207
|
-
wrapCommand} = create$
|
|
1201
|
+
wrapCommand} = create$1();
|
|
1208
1202
|
|
|
1209
|
-
const create
|
|
1203
|
+
const create = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
1210
1204
|
const state = {
|
|
1211
1205
|
assetDir,
|
|
1212
1206
|
layout: {
|
|
@@ -1261,6 +1255,11 @@ const handleClickCloseTab = (state, groupId, tabId) => {
|
|
|
1261
1255
|
return state;
|
|
1262
1256
|
};
|
|
1263
1257
|
|
|
1258
|
+
const handleClickTab = async (state, groupIndex, index) => {
|
|
1259
|
+
// TODO mark that tab as active (if it is a valid group index and index)
|
|
1260
|
+
return state;
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1264
1263
|
const id = 7201;
|
|
1265
1264
|
const sendMessagePortToExtensionHostWorker = async port => {
|
|
1266
1265
|
await sendMessagePortToExtensionHostWorker$1(port, id);
|
|
@@ -1303,7 +1302,7 @@ const loadContent = async state => {
|
|
|
1303
1302
|
activeGroupId: '0',
|
|
1304
1303
|
direction: 'horizontal',
|
|
1305
1304
|
groups: [{
|
|
1306
|
-
activeTabId:
|
|
1305
|
+
activeTabId: tabs.length > 0 ? tabs[0].id : undefined,
|
|
1307
1306
|
direction: 'horizontal',
|
|
1308
1307
|
focused: false,
|
|
1309
1308
|
id: '0',
|
|
@@ -1314,263 +1313,13 @@ const loadContent = async state => {
|
|
|
1314
1313
|
};
|
|
1315
1314
|
};
|
|
1316
1315
|
|
|
1317
|
-
|
|
1318
|
-
const create = () => {
|
|
1319
|
-
idCounter++;
|
|
1320
|
-
return idCounter;
|
|
1321
|
-
};
|
|
1322
|
-
|
|
1323
|
-
const getTitle = (uri, homeDir) => {
|
|
1324
|
-
if (!uri) {
|
|
1325
|
-
return '';
|
|
1326
|
-
}
|
|
1327
|
-
return uri;
|
|
1328
|
-
};
|
|
1329
|
-
const getLabel = uri => {
|
|
1330
|
-
if (uri.startsWith('settings://')) {
|
|
1331
|
-
return 'Settings';
|
|
1332
|
-
}
|
|
1333
|
-
if (uri.startsWith('simple-browser://')) {
|
|
1334
|
-
return 'Simple Browser';
|
|
1335
|
-
}
|
|
1336
|
-
return uri;
|
|
1337
|
-
// return Workspace.pathBaseName(uri)
|
|
1338
|
-
};
|
|
1339
|
-
|
|
1340
|
-
/**
|
|
1341
|
-
*
|
|
1342
|
-
* @param {string} uri
|
|
1343
|
-
* @returns
|
|
1344
|
-
*/
|
|
1345
|
-
const getFileIcon = uri => {
|
|
1346
|
-
if (uri === 'app://keybindings') {
|
|
1347
|
-
return `MaskIconRecordKey`;
|
|
1348
|
-
}
|
|
1349
|
-
if (uri.startsWith('extension-detail://')) {
|
|
1350
|
-
return `MaskIconExtensions`;
|
|
1351
|
-
}
|
|
1352
|
-
return '';
|
|
1353
|
-
};
|
|
1354
|
-
|
|
1355
|
-
const Preview = 1 << 4;
|
|
1356
|
-
|
|
1357
|
-
// @ts-nocheck
|
|
1358
|
-
|
|
1359
|
-
const focusIndex = async (state, index) => {
|
|
1360
|
-
const {
|
|
1361
|
-
activeGroupIndex,
|
|
1362
|
-
groups,
|
|
1363
|
-
tabHeight,
|
|
1364
|
-
uid
|
|
1365
|
-
} = state;
|
|
1366
|
-
const group = groups[activeGroupIndex];
|
|
1367
|
-
const {
|
|
1368
|
-
editors
|
|
1369
|
-
} = group;
|
|
1370
|
-
const oldActiveIndex = group.activeIndex;
|
|
1371
|
-
if (index === oldActiveIndex) {
|
|
1372
|
-
return {
|
|
1373
|
-
commands: [],
|
|
1374
|
-
newState: state
|
|
1375
|
-
};
|
|
1376
|
-
}
|
|
1377
|
-
const newGroup = {
|
|
1378
|
-
...group,
|
|
1379
|
-
activeIndex: index
|
|
1380
|
-
};
|
|
1381
|
-
const newGroups = [...groups.slice(0, activeGroupIndex), newGroup, ...groups.slice(activeGroupIndex + 1)];
|
|
1382
|
-
const newState = {
|
|
1383
|
-
...state,
|
|
1384
|
-
groups: newGroups
|
|
1385
|
-
};
|
|
1386
|
-
const editor = editors[index];
|
|
1387
|
-
const {
|
|
1388
|
-
x
|
|
1389
|
-
} = group;
|
|
1390
|
-
const y = group.y + tabHeight;
|
|
1391
|
-
const {
|
|
1392
|
-
width
|
|
1393
|
-
} = group;
|
|
1394
|
-
const contentHeight = group.height - tabHeight;
|
|
1395
|
-
const id = await ViewletMap.getModuleId(editor.uri);
|
|
1396
|
-
const oldEditor = editors[oldActiveIndex];
|
|
1397
|
-
const oldId = await ViewletMap.getModuleId(oldEditor.uri);
|
|
1398
|
-
// @ts-ignore
|
|
1399
|
-
ViewletStates.getInstance(oldId);
|
|
1400
|
-
const previousUid = oldEditor.uid;
|
|
1401
|
-
number(previousUid);
|
|
1402
|
-
const disposeCommands = Viewlet.disposeFunctional(previousUid);
|
|
1403
|
-
const maybeHiddenEditorInstance = ViewletStates.getInstance(editor.uid);
|
|
1404
|
-
if (maybeHiddenEditorInstance) {
|
|
1405
|
-
const commands = Viewlet.showFunctional(editor.uid);
|
|
1406
|
-
const allCommands = [...disposeCommands, ...commands];
|
|
1407
|
-
return {
|
|
1408
|
-
commands: allCommands,
|
|
1409
|
-
newState
|
|
1410
|
-
};
|
|
1411
|
-
}
|
|
1412
|
-
const instanceUid = create();
|
|
1413
|
-
const instance = ViewletManager.create(ViewletModule.load, id, uid, editor.uri, x, y, width, contentHeight);
|
|
1414
|
-
instance.show = false;
|
|
1415
|
-
instance.setBounds = false;
|
|
1416
|
-
instance.uid = instanceUid;
|
|
1417
|
-
editor.uid = instanceUid;
|
|
1418
|
-
const resizeCommands = ['Viewlet.setBounds', instanceUid, x, tabHeight, width, contentHeight];
|
|
1419
|
-
|
|
1420
|
-
// @ts-ignore
|
|
1421
|
-
const commands = await ViewletManager.load(instance);
|
|
1422
|
-
// @ts-ignore
|
|
1423
|
-
commands.unshift(...disposeCommands);
|
|
1424
|
-
// @ts-ignore
|
|
1425
|
-
commands.push(resizeCommands);
|
|
1426
|
-
// @ts-ignore
|
|
1427
|
-
commands.push(['Viewlet.append', uid, instanceUid]);
|
|
1428
|
-
return {
|
|
1429
|
-
commands,
|
|
1430
|
-
newState
|
|
1431
|
-
};
|
|
1432
|
-
};
|
|
1433
|
-
|
|
1434
|
-
// @ts-nocheck
|
|
1435
|
-
const openUri = async (state, uri, focus = true, {
|
|
1436
|
-
preview = false,
|
|
1437
|
-
...context
|
|
1438
|
-
} = {}) => {
|
|
1316
|
+
const openUri = async (state, options) => {
|
|
1439
1317
|
object(state);
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
groups,
|
|
1444
|
-
tabFontFamily,
|
|
1445
|
-
tabFontSize,
|
|
1446
|
-
tabFontWeight,
|
|
1447
|
-
tabHeight,
|
|
1448
|
-
tabLetterSpacing
|
|
1449
|
-
} = state;
|
|
1450
|
-
const {
|
|
1451
|
-
x
|
|
1452
|
-
} = state;
|
|
1453
|
-
const y = state.y + tabHeight;
|
|
1454
|
-
const {
|
|
1455
|
-
width
|
|
1456
|
-
} = state;
|
|
1457
|
-
const contentHeight = state.height - tabHeight;
|
|
1458
|
-
// @ts-ignore
|
|
1459
|
-
const moduleId = await ViewletMap.getModuleId(uri, context.opener);
|
|
1460
|
-
let activeGroup = groups[activeGroupIndex];
|
|
1461
|
-
activeGroup ||= {
|
|
1462
|
-
activeIndex: -1,
|
|
1463
|
-
editors: [],
|
|
1464
|
-
focusedIndex: -1,
|
|
1465
|
-
height: state.height,
|
|
1466
|
-
tabsUid: create(),
|
|
1467
|
-
uid: create(),
|
|
1468
|
-
width,
|
|
1469
|
-
x,
|
|
1470
|
-
y: 0
|
|
1471
|
-
};
|
|
1472
|
-
const {
|
|
1473
|
-
activeIndex,
|
|
1474
|
-
editors
|
|
1475
|
-
} = activeGroup;
|
|
1476
|
-
const previousEditor = editors[activeIndex];
|
|
1477
|
-
let disposeCommands;
|
|
1478
|
-
// @ts-ignore
|
|
1479
|
-
if (previousEditor && previousEditor.uri === uri && previousEditor.opener === context.opener) {
|
|
1480
|
-
return {
|
|
1481
|
-
commands: [],
|
|
1482
|
-
newState: state
|
|
1483
|
-
};
|
|
1484
|
-
}
|
|
1485
|
-
for (let i = 0; i < editors.length; i++) {
|
|
1486
|
-
const editor = editors[i];
|
|
1487
|
-
if (editor.uri === uri &&
|
|
1488
|
-
// @ts-ignore
|
|
1489
|
-
editor.opener === context.opener) {
|
|
1490
|
-
return focusIndex(state, i);
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
// TODO editor needs to be disposed when closing
|
|
1494
|
-
// other tabs and closing all tabs
|
|
1495
|
-
if (previousEditor) {
|
|
1496
|
-
const previousUid = previousEditor.uid;
|
|
1497
|
-
disposeCommands = Viewlet.hideFunctional(previousUid);
|
|
1498
|
-
}
|
|
1499
|
-
const instanceUid = create();
|
|
1500
|
-
const instance = ViewletManager.create(ViewletModule.load, moduleId, state.uid, uri, activeGroup.x, y, activeGroup.width, contentHeight);
|
|
1501
|
-
instance.uid = instanceUid;
|
|
1502
|
-
// const oldActiveIndex = state.activeIndex
|
|
1503
|
-
const tabLabel = getLabel(uri);
|
|
1504
|
-
const tabWidth = MeasureTabWidth.measureTabWidth(tabLabel, tabFontWeight, tabFontSize, tabFontFamily, tabLetterSpacing);
|
|
1505
|
-
const tabTitle = getTitle(uri);
|
|
1506
|
-
const icon = getFileIcon(uri);
|
|
1507
|
-
const newEditor = {
|
|
1508
|
-
flags: Preview,
|
|
1509
|
-
icon,
|
|
1510
|
-
label: tabLabel,
|
|
1511
|
-
moduleId,
|
|
1512
|
-
tabWidth,
|
|
1513
|
-
title: tabTitle,
|
|
1514
|
-
uid: instanceUid,
|
|
1515
|
-
uri
|
|
1516
|
-
};
|
|
1517
|
-
const newEditors = [...activeGroup.editors, newEditor];
|
|
1518
|
-
const newActiveIndex = newEditors.length - 1;
|
|
1519
|
-
const newGroup = {
|
|
1520
|
-
...activeGroup,
|
|
1521
|
-
activeIndex: newActiveIndex,
|
|
1522
|
-
editors: newEditors
|
|
1523
|
-
};
|
|
1524
|
-
const newGroups = [...groups.slice(0, activeGroupIndex), newGroup, ...groups.slice(activeGroupIndex + 1)];
|
|
1525
|
-
// @ts-ignore
|
|
1526
|
-
instance.show = false;
|
|
1527
|
-
instance.setBounds = false;
|
|
1528
|
-
ViewletStates.setState(state.uid, {
|
|
1529
|
-
...state,
|
|
1530
|
-
activeGroupIndex: 0,
|
|
1531
|
-
groups: newGroups,
|
|
1532
|
-
pendingUid: instanceUid
|
|
1533
|
-
});
|
|
1534
|
-
if (context) {
|
|
1535
|
-
instance.args = [context];
|
|
1536
|
-
}
|
|
1537
|
-
// @ts-ignore
|
|
1538
|
-
const commands = await ViewletManager.load(instance, focus);
|
|
1539
|
-
commands.push(['Viewlet.setBounds', instanceUid, activeGroup.x, tabHeight, activeGroup.width, contentHeight]);
|
|
1540
|
-
let {
|
|
1541
|
-
tabsUid
|
|
1542
|
-
} = state;
|
|
1543
|
-
if (tabsUid === -1) {
|
|
1544
|
-
tabsUid = create();
|
|
1545
|
-
}
|
|
1546
|
-
if (disposeCommands) {
|
|
1547
|
-
commands.push(...disposeCommands);
|
|
1548
|
-
}
|
|
1549
|
-
commands.push(['Viewlet.append', state.uid, instanceUid]);
|
|
1550
|
-
if (focus) {
|
|
1551
|
-
commands.push(['Viewlet.focus', instanceUid]);
|
|
1552
|
-
}
|
|
1553
|
-
const latestState = ViewletStates.getState(state.uid);
|
|
1554
|
-
const latestPendingUid = latestState.pendingUid;
|
|
1555
|
-
if (latestPendingUid !== instanceUid) {
|
|
1556
|
-
return {
|
|
1557
|
-
commands: [],
|
|
1558
|
-
newState: state
|
|
1559
|
-
};
|
|
1560
|
-
}
|
|
1561
|
-
if (!ViewletStates.hasInstance(instanceUid)) {
|
|
1562
|
-
return {
|
|
1563
|
-
commands,
|
|
1564
|
-
newState: state
|
|
1565
|
-
};
|
|
1566
|
-
}
|
|
1318
|
+
object(options);
|
|
1319
|
+
|
|
1320
|
+
// TODO
|
|
1567
1321
|
return {
|
|
1568
|
-
|
|
1569
|
-
newState: {
|
|
1570
|
-
...state,
|
|
1571
|
-
groups: newGroups,
|
|
1572
|
-
tabsUid
|
|
1573
|
-
}
|
|
1322
|
+
...state
|
|
1574
1323
|
};
|
|
1575
1324
|
};
|
|
1576
1325
|
|
|
@@ -1607,10 +1356,15 @@ const renderEditor = tab => {
|
|
|
1607
1356
|
}, text(tab.content || '')];
|
|
1608
1357
|
};
|
|
1609
1358
|
|
|
1359
|
+
const HandleClick = 11;
|
|
1360
|
+
const HandleClickClose = 12;
|
|
1361
|
+
const HandleClickTab = 13;
|
|
1362
|
+
|
|
1610
1363
|
const renderTab = (tab, isActive) => {
|
|
1611
1364
|
return [{
|
|
1612
1365
|
childCount: 2,
|
|
1613
1366
|
className: isActive ? 'MainTab MainTabActive' : 'MainTab',
|
|
1367
|
+
onClick: HandleClickTab,
|
|
1614
1368
|
type: Div
|
|
1615
1369
|
}, {
|
|
1616
1370
|
childCount: 1,
|
|
@@ -1619,6 +1373,7 @@ const renderTab = (tab, isActive) => {
|
|
|
1619
1373
|
}, text(tab.isDirty ? `*${tab.title}` : tab.title), {
|
|
1620
1374
|
childCount: 1,
|
|
1621
1375
|
className: 'EditorTabCloseButton',
|
|
1376
|
+
onClick: HandleClickClose,
|
|
1622
1377
|
type: Button
|
|
1623
1378
|
}, text('×')];
|
|
1624
1379
|
};
|
|
@@ -1696,16 +1451,16 @@ const render2 = (uid, diffResult) => {
|
|
|
1696
1451
|
return commands;
|
|
1697
1452
|
};
|
|
1698
1453
|
|
|
1699
|
-
const HandleClick = 11;
|
|
1700
|
-
const HandleClickClose = 12;
|
|
1701
|
-
|
|
1702
1454
|
const renderEventListeners = () => {
|
|
1703
1455
|
return [{
|
|
1704
1456
|
name: HandleClick,
|
|
1705
1457
|
params: ['handleClick', TargetName]
|
|
1706
1458
|
}, {
|
|
1707
1459
|
name: HandleClickClose,
|
|
1708
|
-
params: ['
|
|
1460
|
+
params: ['handleClickCloseTab', 'event.target.dataset.groupIndex', 'event.target.dataset.index']
|
|
1461
|
+
}, {
|
|
1462
|
+
name: HandleClickClose,
|
|
1463
|
+
params: ['handleClickTab', 'event.target.dataset.groupIndex', 'event.target.dataset.index']
|
|
1709
1464
|
}];
|
|
1710
1465
|
};
|
|
1711
1466
|
|
|
@@ -1733,11 +1488,12 @@ const saveState = uid => {
|
|
|
1733
1488
|
};
|
|
1734
1489
|
|
|
1735
1490
|
const commandMap = {
|
|
1736
|
-
'MainArea.create': create
|
|
1491
|
+
'MainArea.create': create,
|
|
1737
1492
|
'MainArea.diff2': diff2,
|
|
1738
1493
|
'MainArea.getCommandIds': getCommandIds,
|
|
1739
1494
|
'MainArea.handleClick': wrapCommand(handleClick),
|
|
1740
1495
|
'MainArea.handleClickCloseTab': wrapCommand(handleClickCloseTab),
|
|
1496
|
+
'MainArea.handleClickTab': wrapCommand(handleClickTab),
|
|
1741
1497
|
'MainArea.initialize': initialize,
|
|
1742
1498
|
'MainArea.loadContent': wrapCommand(loadContent),
|
|
1743
1499
|
'MainArea.openUri': wrapCommand(openUri),
|