@lvce-editor/main-area-worker 1.9.0 → 1.11.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 +455 -29
- package/package.json +2 -2
|
@@ -96,6 +96,12 @@ const object = value => {
|
|
|
96
96
|
throw new AssertionError('expected value to be of type object');
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
|
+
const number = value => {
|
|
100
|
+
const type = getType(value);
|
|
101
|
+
if (type !== Number$1) {
|
|
102
|
+
throw new AssertionError('expected value to be of type number');
|
|
103
|
+
}
|
|
104
|
+
};
|
|
99
105
|
|
|
100
106
|
const isMessagePort = value => {
|
|
101
107
|
return value && value instanceof MessagePort;
|
|
@@ -450,7 +456,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
|
|
|
450
456
|
return promise;
|
|
451
457
|
};
|
|
452
458
|
const Message$1 = 3;
|
|
453
|
-
const create$5 = async ({
|
|
459
|
+
const create$5$1 = async ({
|
|
454
460
|
isMessagePortOpen,
|
|
455
461
|
messagePort
|
|
456
462
|
}) => {
|
|
@@ -501,7 +507,7 @@ const wrap$5 = messagePort => {
|
|
|
501
507
|
};
|
|
502
508
|
const IpcParentWithMessagePort$1 = {
|
|
503
509
|
__proto__: null,
|
|
504
|
-
create: create$5,
|
|
510
|
+
create: create$5$1,
|
|
505
511
|
signal: signal$1,
|
|
506
512
|
wrap: wrap$5
|
|
507
513
|
};
|
|
@@ -720,7 +726,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
720
726
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
721
727
|
return create$1$2(id, errorProperty);
|
|
722
728
|
};
|
|
723
|
-
const create$
|
|
729
|
+
const create$5 = (message, result) => {
|
|
724
730
|
return {
|
|
725
731
|
jsonrpc: Two$1,
|
|
726
732
|
id: message.id,
|
|
@@ -729,7 +735,7 @@ const create$3 = (message, result) => {
|
|
|
729
735
|
};
|
|
730
736
|
const getSuccessResponse = (message, result) => {
|
|
731
737
|
const resultProperty = result ?? null;
|
|
732
|
-
return create$
|
|
738
|
+
return create$5(message, resultProperty);
|
|
733
739
|
};
|
|
734
740
|
const getErrorResponseSimple = (id, error) => {
|
|
735
741
|
return {
|
|
@@ -1028,14 +1034,22 @@ const createMockRpc = ({
|
|
|
1028
1034
|
return mockRpc;
|
|
1029
1035
|
};
|
|
1030
1036
|
|
|
1031
|
-
const Button = 1;
|
|
1037
|
+
const Button$1 = 1;
|
|
1032
1038
|
const Div = 4;
|
|
1033
1039
|
const Span = 8;
|
|
1034
1040
|
const Text = 12;
|
|
1035
1041
|
const Pre = 51;
|
|
1036
1042
|
|
|
1043
|
+
const Button = 'event.button';
|
|
1044
|
+
const ClientX = 'event.clientX';
|
|
1045
|
+
const ClientY = 'event.clientY';
|
|
1037
1046
|
const TargetName = 'event.target.name';
|
|
1038
1047
|
|
|
1048
|
+
const Tab = 13;
|
|
1049
|
+
|
|
1050
|
+
const Separator = 1;
|
|
1051
|
+
const None = 0;
|
|
1052
|
+
|
|
1039
1053
|
const ExtensionHostWorker = 44;
|
|
1040
1054
|
const RendererWorker = 1;
|
|
1041
1055
|
|
|
@@ -1053,7 +1067,7 @@ const remove = id => {
|
|
|
1053
1067
|
};
|
|
1054
1068
|
|
|
1055
1069
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1056
|
-
const create$
|
|
1070
|
+
const create$3 = rpcId => {
|
|
1057
1071
|
return {
|
|
1058
1072
|
async dispose() {
|
|
1059
1073
|
const rpc = get$1(rpcId);
|
|
@@ -1091,12 +1105,21 @@ const create$2 = rpcId => {
|
|
|
1091
1105
|
|
|
1092
1106
|
const {
|
|
1093
1107
|
set: set$2
|
|
1094
|
-
} = create$
|
|
1108
|
+
} = create$3(ExtensionHostWorker);
|
|
1095
1109
|
|
|
1096
1110
|
const {
|
|
1111
|
+
invoke,
|
|
1097
1112
|
invokeAndTransfer,
|
|
1098
1113
|
set: set$1
|
|
1099
|
-
} = create$
|
|
1114
|
+
} = create$3(RendererWorker);
|
|
1115
|
+
const showContextMenu2 = async (uid, menuId, x, y, args) => {
|
|
1116
|
+
number(uid);
|
|
1117
|
+
number(menuId);
|
|
1118
|
+
number(x);
|
|
1119
|
+
number(y);
|
|
1120
|
+
// @ts-ignore
|
|
1121
|
+
await invoke('ContextMenu.show2', uid, menuId, x, y, args);
|
|
1122
|
+
};
|
|
1100
1123
|
const sendMessagePortToExtensionHostWorker$1 = async (port, rpcId = 0) => {
|
|
1101
1124
|
const command = 'HandleMessagePort.handleMessagePort2';
|
|
1102
1125
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
|
|
@@ -1106,7 +1129,7 @@ const toCommandId = key => {
|
|
|
1106
1129
|
const dotIndex = key.indexOf('.');
|
|
1107
1130
|
return key.slice(dotIndex + 1);
|
|
1108
1131
|
};
|
|
1109
|
-
const create$
|
|
1132
|
+
const create$2 = () => {
|
|
1110
1133
|
const states = Object.create(null);
|
|
1111
1134
|
const commandMapRef = {};
|
|
1112
1135
|
return {
|
|
@@ -1192,13 +1215,15 @@ const {
|
|
|
1192
1215
|
getCommandIds,
|
|
1193
1216
|
registerCommands,
|
|
1194
1217
|
set,
|
|
1195
|
-
wrapCommand
|
|
1218
|
+
wrapCommand,
|
|
1219
|
+
wrapGetter
|
|
1220
|
+
} = create$2();
|
|
1196
1221
|
|
|
1197
|
-
const create = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
1222
|
+
const create$1 = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
1198
1223
|
const state = {
|
|
1199
1224
|
assetDir,
|
|
1200
1225
|
layout: {
|
|
1201
|
-
activeGroupId:
|
|
1226
|
+
activeGroupId: undefined,
|
|
1202
1227
|
direction: 'horizontal',
|
|
1203
1228
|
groups: []
|
|
1204
1229
|
},
|
|
@@ -1237,6 +1262,10 @@ const diff2 = uid => {
|
|
|
1237
1262
|
return result;
|
|
1238
1263
|
};
|
|
1239
1264
|
|
|
1265
|
+
const getMenuIds = () => {
|
|
1266
|
+
return [Tab];
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1240
1269
|
const handleClick = async (state, name) => {
|
|
1241
1270
|
if (!name) {
|
|
1242
1271
|
return state;
|
|
@@ -1245,7 +1274,14 @@ const handleClick = async (state, name) => {
|
|
|
1245
1274
|
};
|
|
1246
1275
|
|
|
1247
1276
|
const closeTab = (state, groupId, tabId) => {
|
|
1248
|
-
const
|
|
1277
|
+
const {
|
|
1278
|
+
layout
|
|
1279
|
+
} = state;
|
|
1280
|
+
const {
|
|
1281
|
+
activeGroupId,
|
|
1282
|
+
groups
|
|
1283
|
+
} = layout;
|
|
1284
|
+
const newGroups = groups.map(group => {
|
|
1249
1285
|
if (group.id === groupId) {
|
|
1250
1286
|
const newTabs = group.tabs.filter(tab => tab.id !== tabId);
|
|
1251
1287
|
let newActiveTabId = group.activeTabId;
|
|
@@ -1265,18 +1301,58 @@ const closeTab = (state, groupId, tabId) => {
|
|
|
1265
1301
|
}
|
|
1266
1302
|
return group;
|
|
1267
1303
|
});
|
|
1304
|
+
|
|
1305
|
+
// If the group has no tabs left and there are other groups, remove the group
|
|
1306
|
+
const groupWithNoTabs = newGroups.find(group => group.id === groupId && group.tabs.length === 0);
|
|
1307
|
+
if (groupWithNoTabs && newGroups.length > 1) {
|
|
1308
|
+
const remainingGroups = newGroups.filter(group => group.id !== groupId);
|
|
1309
|
+
const redistributedGroups = remainingGroups.map(group => ({
|
|
1310
|
+
...group,
|
|
1311
|
+
size: Math.round(100 / remainingGroups.length)
|
|
1312
|
+
}));
|
|
1313
|
+
const newActiveGroupId = activeGroupId === groupId ? remainingGroups[0]?.id : activeGroupId;
|
|
1314
|
+
return {
|
|
1315
|
+
...state,
|
|
1316
|
+
layout: {
|
|
1317
|
+
...layout,
|
|
1318
|
+
activeGroupId: newActiveGroupId,
|
|
1319
|
+
groups: redistributedGroups
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1268
1323
|
return {
|
|
1269
1324
|
...state,
|
|
1270
1325
|
layout: {
|
|
1271
|
-
...
|
|
1272
|
-
groups
|
|
1326
|
+
...layout,
|
|
1327
|
+
groups: newGroups
|
|
1273
1328
|
}
|
|
1274
1329
|
};
|
|
1275
1330
|
};
|
|
1276
1331
|
|
|
1277
|
-
const handleClickCloseTab = (state,
|
|
1278
|
-
|
|
1279
|
-
|
|
1332
|
+
const handleClickCloseTab = (state, rawGroupIndex, rawIndex) => {
|
|
1333
|
+
if (!rawGroupIndex || !rawIndex) {
|
|
1334
|
+
return state;
|
|
1335
|
+
}
|
|
1336
|
+
const groupIndex = Number.parseInt(rawGroupIndex);
|
|
1337
|
+
const index = Number.parseInt(rawIndex);
|
|
1338
|
+
const {
|
|
1339
|
+
layout
|
|
1340
|
+
} = state;
|
|
1341
|
+
const {
|
|
1342
|
+
groups
|
|
1343
|
+
} = layout;
|
|
1344
|
+
|
|
1345
|
+
// Validate indexes
|
|
1346
|
+
if (groupIndex < 0 || groupIndex >= groups.length) {
|
|
1347
|
+
return state;
|
|
1348
|
+
}
|
|
1349
|
+
const group = groups[groupIndex];
|
|
1350
|
+
if (index < 0 || index >= group.tabs.length) {
|
|
1351
|
+
return state;
|
|
1352
|
+
}
|
|
1353
|
+
const tab = group.tabs[index];
|
|
1354
|
+
const groupId = group.id;
|
|
1355
|
+
const tabId = tab.id;
|
|
1280
1356
|
return closeTab(state, groupId, tabId);
|
|
1281
1357
|
};
|
|
1282
1358
|
|
|
@@ -1330,6 +1406,22 @@ const handleClickTab = async (state, groupIndexRaw, indexRaw) => {
|
|
|
1330
1406
|
return selectTab(state, groupIndex, index);
|
|
1331
1407
|
};
|
|
1332
1408
|
|
|
1409
|
+
const show2 = async (uid, menuId, x, y, args) => {
|
|
1410
|
+
await showContextMenu2(uid, menuId, x, y, args);
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
const handleTabContextMenu = async (state, x, y) => {
|
|
1414
|
+
number(x);
|
|
1415
|
+
number(y);
|
|
1416
|
+
const {
|
|
1417
|
+
uid
|
|
1418
|
+
} = state;
|
|
1419
|
+
await show2(uid, Tab, x, y, {
|
|
1420
|
+
menuId: Tab
|
|
1421
|
+
});
|
|
1422
|
+
return state;
|
|
1423
|
+
};
|
|
1424
|
+
|
|
1333
1425
|
const id = 7201;
|
|
1334
1426
|
const sendMessagePortToExtensionHostWorker = async port => {
|
|
1335
1427
|
await sendMessagePortToExtensionHostWorker$1(port, id);
|
|
@@ -1356,15 +1448,39 @@ const getTabs = async () => {
|
|
|
1356
1448
|
const tabs = [{
|
|
1357
1449
|
content: '',
|
|
1358
1450
|
editorType: 'text',
|
|
1359
|
-
id:
|
|
1451
|
+
id: 1,
|
|
1360
1452
|
isDirty: false,
|
|
1361
1453
|
title: 'tab 1'
|
|
1362
1454
|
}, {
|
|
1363
1455
|
content: '',
|
|
1364
1456
|
editorType: 'text',
|
|
1365
|
-
id:
|
|
1457
|
+
id: 2,
|
|
1366
1458
|
isDirty: false,
|
|
1367
1459
|
title: 'tab 2'
|
|
1460
|
+
}, {
|
|
1461
|
+
content: '',
|
|
1462
|
+
editorType: 'text',
|
|
1463
|
+
id: 3,
|
|
1464
|
+
isDirty: false,
|
|
1465
|
+
title: 'tab 3'
|
|
1466
|
+
}, {
|
|
1467
|
+
content: '',
|
|
1468
|
+
editorType: 'text',
|
|
1469
|
+
id: 4,
|
|
1470
|
+
isDirty: false,
|
|
1471
|
+
title: 'tab 4'
|
|
1472
|
+
}, {
|
|
1473
|
+
content: '',
|
|
1474
|
+
editorType: 'text',
|
|
1475
|
+
id: 5,
|
|
1476
|
+
isDirty: false,
|
|
1477
|
+
title: 'tab 5'
|
|
1478
|
+
}, {
|
|
1479
|
+
content: '',
|
|
1480
|
+
editorType: 'text',
|
|
1481
|
+
id: 6,
|
|
1482
|
+
isDirty: false,
|
|
1483
|
+
title: 'tab 6'
|
|
1368
1484
|
}];
|
|
1369
1485
|
return tabs;
|
|
1370
1486
|
};
|
|
@@ -1374,13 +1490,13 @@ const loadContent = async state => {
|
|
|
1374
1490
|
return {
|
|
1375
1491
|
...state,
|
|
1376
1492
|
layout: {
|
|
1377
|
-
activeGroupId:
|
|
1493
|
+
activeGroupId: 0,
|
|
1378
1494
|
direction: 'horizontal',
|
|
1379
1495
|
groups: [{
|
|
1380
1496
|
activeTabId: tabs.length > 0 ? tabs[0].id : undefined,
|
|
1381
1497
|
direction: 'horizontal',
|
|
1382
1498
|
focused: false,
|
|
1383
|
-
id:
|
|
1499
|
+
id: 0,
|
|
1384
1500
|
size: 300,
|
|
1385
1501
|
tabs
|
|
1386
1502
|
}]
|
|
@@ -1388,14 +1504,306 @@ const loadContent = async state => {
|
|
|
1388
1504
|
};
|
|
1389
1505
|
};
|
|
1390
1506
|
|
|
1507
|
+
const emptyObject = {};
|
|
1508
|
+
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
1509
|
+
const i18nString = (key, placeholders = emptyObject) => {
|
|
1510
|
+
if (placeholders === emptyObject) {
|
|
1511
|
+
return key;
|
|
1512
|
+
}
|
|
1513
|
+
const replacer = (match, rest) => {
|
|
1514
|
+
return placeholders[rest];
|
|
1515
|
+
};
|
|
1516
|
+
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
/**
|
|
1520
|
+
* @enum {string}
|
|
1521
|
+
*/
|
|
1522
|
+
const UiStrings = {
|
|
1523
|
+
Close: 'Close',
|
|
1524
|
+
CloseAll: 'Close All',
|
|
1525
|
+
CloseOthers: 'Close Others',
|
|
1526
|
+
CloseToTheRight: 'Close To The Right',
|
|
1527
|
+
FindFileReferences: 'Find File References',
|
|
1528
|
+
RevealInExplorer: 'Reveal in Explorer'};
|
|
1529
|
+
const close = () => {
|
|
1530
|
+
return i18nString(UiStrings.Close);
|
|
1531
|
+
};
|
|
1532
|
+
const closeOthers = () => {
|
|
1533
|
+
return i18nString(UiStrings.CloseOthers);
|
|
1534
|
+
};
|
|
1535
|
+
const closeAll = () => {
|
|
1536
|
+
return i18nString(UiStrings.CloseAll);
|
|
1537
|
+
};
|
|
1538
|
+
const revealInExplorer = () => {
|
|
1539
|
+
return i18nString(UiStrings.RevealInExplorer);
|
|
1540
|
+
};
|
|
1541
|
+
const closeToTheRight = () => {
|
|
1542
|
+
return i18nString(UiStrings.CloseToTheRight);
|
|
1543
|
+
};
|
|
1544
|
+
const findFileReferences = () => {
|
|
1545
|
+
return i18nString(UiStrings.FindFileReferences);
|
|
1546
|
+
};
|
|
1547
|
+
|
|
1548
|
+
const menuEntrySeparator = {
|
|
1549
|
+
command: '',
|
|
1550
|
+
flags: Separator,
|
|
1551
|
+
id: 'separator',
|
|
1552
|
+
label: ''
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
// TODO should pass tab uri as argument or tab index
|
|
1556
|
+
const getMenuEntries$1 = state => {
|
|
1557
|
+
const {
|
|
1558
|
+
layout
|
|
1559
|
+
} = state;
|
|
1560
|
+
const {
|
|
1561
|
+
activeGroupId,
|
|
1562
|
+
groups
|
|
1563
|
+
} = layout;
|
|
1564
|
+
const group = groups[activeGroupId || 0];
|
|
1565
|
+
const {
|
|
1566
|
+
activeTabId,
|
|
1567
|
+
tabs
|
|
1568
|
+
} = group;
|
|
1569
|
+
const tab = tabs[activeTabId || 0];
|
|
1570
|
+
object(tab);
|
|
1571
|
+
const {
|
|
1572
|
+
path
|
|
1573
|
+
} = tab;
|
|
1574
|
+
return [{
|
|
1575
|
+
command: 'Main.closeFocusedTab',
|
|
1576
|
+
flags: None,
|
|
1577
|
+
id: 'tabClose',
|
|
1578
|
+
label: close()
|
|
1579
|
+
}, {
|
|
1580
|
+
command: 'Main.closeOthers',
|
|
1581
|
+
flags: None,
|
|
1582
|
+
id: 'tabCloseOthers',
|
|
1583
|
+
label: closeOthers()
|
|
1584
|
+
}, {
|
|
1585
|
+
command: 'Main.closeTabsRight',
|
|
1586
|
+
flags: None,
|
|
1587
|
+
id: 'tabCloseToTheRight',
|
|
1588
|
+
label: closeToTheRight()
|
|
1589
|
+
}, {
|
|
1590
|
+
command: 'Main.closeAllEditors',
|
|
1591
|
+
flags: None,
|
|
1592
|
+
id: 'tabCloseAll',
|
|
1593
|
+
label: closeAll()
|
|
1594
|
+
}, menuEntrySeparator, {
|
|
1595
|
+
args: [path],
|
|
1596
|
+
command: 'Explorer.revealItem',
|
|
1597
|
+
flags: None,
|
|
1598
|
+
id: 'revealInExplorer',
|
|
1599
|
+
label: revealInExplorer()
|
|
1600
|
+
}, menuEntrySeparator, {
|
|
1601
|
+
args: [/* id */'References', /* focus */true, path],
|
|
1602
|
+
command: 'SideBar.show',
|
|
1603
|
+
flags: None,
|
|
1604
|
+
id: 'findFileReferences',
|
|
1605
|
+
label: findFileReferences()
|
|
1606
|
+
}];
|
|
1607
|
+
};
|
|
1608
|
+
|
|
1609
|
+
const getMenuEntries = async (state, props) => {
|
|
1610
|
+
switch (props.menuId) {
|
|
1611
|
+
case Tab:
|
|
1612
|
+
return getMenuEntries$1(state);
|
|
1613
|
+
default:
|
|
1614
|
+
return [];
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
|
|
1618
|
+
const findTabByUri = (state, uri) => {
|
|
1619
|
+
const {
|
|
1620
|
+
layout
|
|
1621
|
+
} = state;
|
|
1622
|
+
const {
|
|
1623
|
+
groups
|
|
1624
|
+
} = layout;
|
|
1625
|
+
for (const group of groups) {
|
|
1626
|
+
const tab = group.tabs.find(t => t.path === uri);
|
|
1627
|
+
if (tab) {
|
|
1628
|
+
return {
|
|
1629
|
+
groupId: group.id,
|
|
1630
|
+
tab
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
return undefined;
|
|
1635
|
+
};
|
|
1636
|
+
|
|
1637
|
+
const focusEditorGroup = (state, groupId) => {
|
|
1638
|
+
const {
|
|
1639
|
+
layout
|
|
1640
|
+
} = state;
|
|
1641
|
+
const {
|
|
1642
|
+
groups
|
|
1643
|
+
} = layout;
|
|
1644
|
+
const updatedGroups = groups.map(group => ({
|
|
1645
|
+
...group,
|
|
1646
|
+
focused: group.id === groupId
|
|
1647
|
+
}));
|
|
1648
|
+
return {
|
|
1649
|
+
...state,
|
|
1650
|
+
layout: {
|
|
1651
|
+
...layout,
|
|
1652
|
+
activeGroupId: groupId,
|
|
1653
|
+
groups: updatedGroups
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
let idCounter = 0;
|
|
1659
|
+
const create = () => {
|
|
1660
|
+
idCounter++;
|
|
1661
|
+
return idCounter;
|
|
1662
|
+
};
|
|
1663
|
+
|
|
1664
|
+
const openTab = (state, groupId, tab) => {
|
|
1665
|
+
const newTab = {
|
|
1666
|
+
...tab,
|
|
1667
|
+
id: create()
|
|
1668
|
+
};
|
|
1669
|
+
const {
|
|
1670
|
+
layout
|
|
1671
|
+
} = state;
|
|
1672
|
+
const {
|
|
1673
|
+
groups
|
|
1674
|
+
} = layout;
|
|
1675
|
+
const updatedGroups = groups.map(group => {
|
|
1676
|
+
if (group.id === groupId) {
|
|
1677
|
+
return {
|
|
1678
|
+
...group,
|
|
1679
|
+
activeTabId: newTab.id,
|
|
1680
|
+
tabs: [...group.tabs, newTab]
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
return group;
|
|
1684
|
+
});
|
|
1685
|
+
return {
|
|
1686
|
+
...state,
|
|
1687
|
+
layout: {
|
|
1688
|
+
...layout,
|
|
1689
|
+
groups: updatedGroups
|
|
1690
|
+
}
|
|
1691
|
+
};
|
|
1692
|
+
};
|
|
1693
|
+
|
|
1694
|
+
const getBasename = uri => {
|
|
1695
|
+
const lastSlashIndex = uri.lastIndexOf('/');
|
|
1696
|
+
if (lastSlashIndex === -1) {
|
|
1697
|
+
return uri;
|
|
1698
|
+
}
|
|
1699
|
+
return uri.slice(lastSlashIndex + 1);
|
|
1700
|
+
};
|
|
1701
|
+
const getLabel = uri => {
|
|
1702
|
+
if (uri.startsWith('settings://')) {
|
|
1703
|
+
return 'Settings';
|
|
1704
|
+
}
|
|
1705
|
+
if (uri.startsWith('simple-browser://')) {
|
|
1706
|
+
return 'Simple Browser';
|
|
1707
|
+
}
|
|
1708
|
+
return getBasename(uri);
|
|
1709
|
+
};
|
|
1710
|
+
|
|
1711
|
+
const switchTab = (state, groupId, tabId) => {
|
|
1712
|
+
const {
|
|
1713
|
+
layout
|
|
1714
|
+
} = state;
|
|
1715
|
+
const {
|
|
1716
|
+
groups
|
|
1717
|
+
} = layout;
|
|
1718
|
+
const updatedGroups = groups.map(group => {
|
|
1719
|
+
if (group.id === groupId) {
|
|
1720
|
+
const tabExists = group.tabs.some(tab => tab.id === tabId);
|
|
1721
|
+
if (tabExists) {
|
|
1722
|
+
return {
|
|
1723
|
+
...group,
|
|
1724
|
+
activeTabId: tabId
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
return group;
|
|
1729
|
+
});
|
|
1730
|
+
return {
|
|
1731
|
+
...state,
|
|
1732
|
+
layout: {
|
|
1733
|
+
...layout,
|
|
1734
|
+
groups: updatedGroups
|
|
1735
|
+
}
|
|
1736
|
+
};
|
|
1737
|
+
};
|
|
1738
|
+
|
|
1739
|
+
/* eslint-disable prefer-destructuring */
|
|
1740
|
+
|
|
1391
1741
|
const openUri = async (state, options) => {
|
|
1392
1742
|
object(state);
|
|
1393
|
-
|
|
1743
|
+
let uri = '';
|
|
1744
|
+
if (typeof options === 'string') {
|
|
1745
|
+
uri = options;
|
|
1746
|
+
} else {
|
|
1747
|
+
uri = options.uri;
|
|
1748
|
+
}
|
|
1394
1749
|
|
|
1395
|
-
//
|
|
1396
|
-
|
|
1397
|
-
|
|
1750
|
+
// Check if a tab with this URI already exists
|
|
1751
|
+
const existingTab = findTabByUri(state, uri);
|
|
1752
|
+
if (existingTab) {
|
|
1753
|
+
// Tab exists, switch to it and focus its group
|
|
1754
|
+
const focusedState = focusEditorGroup(state, existingTab.groupId);
|
|
1755
|
+
return switchTab(focusedState, existingTab.groupId, existingTab.tab.id);
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
// Find the active group (by activeGroupId or focused flag)
|
|
1759
|
+
const {
|
|
1760
|
+
layout
|
|
1761
|
+
} = state;
|
|
1762
|
+
const {
|
|
1763
|
+
activeGroupId,
|
|
1764
|
+
groups
|
|
1765
|
+
} = layout;
|
|
1766
|
+
const activeGroup = activeGroupId === undefined ? groups.find(group => group.focused) : groups.find(group => group.id === activeGroupId);
|
|
1767
|
+
|
|
1768
|
+
// If no active group exists, create one
|
|
1769
|
+
if (!activeGroup) {
|
|
1770
|
+
const groupId = create();
|
|
1771
|
+
const title = getLabel(uri);
|
|
1772
|
+
const newTab = {
|
|
1773
|
+
content: '',
|
|
1774
|
+
editorType: 'text',
|
|
1775
|
+
id: create(),
|
|
1776
|
+
isDirty: false,
|
|
1777
|
+
path: uri,
|
|
1778
|
+
title
|
|
1779
|
+
};
|
|
1780
|
+
const newGroup = {
|
|
1781
|
+
activeTabId: newTab.id,
|
|
1782
|
+
focused: true,
|
|
1783
|
+
id: groupId,
|
|
1784
|
+
size: 100,
|
|
1785
|
+
tabs: [newTab]
|
|
1786
|
+
};
|
|
1787
|
+
return {
|
|
1788
|
+
...state,
|
|
1789
|
+
layout: {
|
|
1790
|
+
...layout,
|
|
1791
|
+
activeGroupId: groupId,
|
|
1792
|
+
groups: [...groups, newGroup]
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
// Create a new tab with the URI in the active group
|
|
1798
|
+
const title = getLabel(uri);
|
|
1799
|
+
const newTab = {
|
|
1800
|
+
content: '',
|
|
1801
|
+
editorType: 'text',
|
|
1802
|
+
isDirty: false,
|
|
1803
|
+
path: uri,
|
|
1804
|
+
title
|
|
1398
1805
|
};
|
|
1806
|
+
return openTab(state, activeGroup.id, newTab);
|
|
1399
1807
|
};
|
|
1400
1808
|
|
|
1401
1809
|
const text = data => {
|
|
@@ -1411,7 +1819,15 @@ const CSS_CLASSES = {
|
|
|
1411
1819
|
|
|
1412
1820
|
const renderEditor = tab => {
|
|
1413
1821
|
if (!tab) {
|
|
1414
|
-
return [
|
|
1822
|
+
return [{
|
|
1823
|
+
childCount: 1,
|
|
1824
|
+
className: 'TextEditor',
|
|
1825
|
+
type: Div
|
|
1826
|
+
}, {
|
|
1827
|
+
childCount: 1,
|
|
1828
|
+
className: 'EditorContent',
|
|
1829
|
+
type: Pre
|
|
1830
|
+
}, text('')];
|
|
1415
1831
|
}
|
|
1416
1832
|
if (tab.editorType === 'custom') {
|
|
1417
1833
|
return [{
|
|
@@ -1434,6 +1850,7 @@ const renderEditor = tab => {
|
|
|
1434
1850
|
const HandleClick = 11;
|
|
1435
1851
|
const HandleClickClose = 12;
|
|
1436
1852
|
const HandleClickTab = 13;
|
|
1853
|
+
const HandleTabContextMenu = 14;
|
|
1437
1854
|
|
|
1438
1855
|
const renderTab = (tab, isActive, tabIndex, groupIndex) => {
|
|
1439
1856
|
return [{
|
|
@@ -1442,7 +1859,9 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
|
|
|
1442
1859
|
'data-groupIndex': groupIndex,
|
|
1443
1860
|
'data-index': tabIndex,
|
|
1444
1861
|
onClick: HandleClickTab,
|
|
1862
|
+
onContextMenu: HandleTabContextMenu,
|
|
1445
1863
|
role: 'tab',
|
|
1864
|
+
title: tab.path || tab.title,
|
|
1446
1865
|
type: Div
|
|
1447
1866
|
}, {
|
|
1448
1867
|
childCount: 1,
|
|
@@ -1454,7 +1873,7 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
|
|
|
1454
1873
|
'data-groupIndex': groupIndex,
|
|
1455
1874
|
'data-index': tabIndex,
|
|
1456
1875
|
onClick: HandleClickClose,
|
|
1457
|
-
type: Button
|
|
1876
|
+
type: Button$1
|
|
1458
1877
|
}, text('×')];
|
|
1459
1878
|
};
|
|
1460
1879
|
|
|
@@ -1541,6 +1960,10 @@ const renderEventListeners = () => {
|
|
|
1541
1960
|
}, {
|
|
1542
1961
|
name: HandleClickTab,
|
|
1543
1962
|
params: ['handleClickTab', 'event.target.dataset.groupIndex', 'event.target.dataset.index']
|
|
1963
|
+
}, {
|
|
1964
|
+
name: HandleTabContextMenu,
|
|
1965
|
+
params: ['handleTabContextMenu', Button, ClientX, ClientY],
|
|
1966
|
+
preventDefault: true
|
|
1544
1967
|
}];
|
|
1545
1968
|
};
|
|
1546
1969
|
|
|
@@ -1561,12 +1984,15 @@ const saveState = state => {
|
|
|
1561
1984
|
};
|
|
1562
1985
|
|
|
1563
1986
|
const commandMap = {
|
|
1564
|
-
'MainArea.create': create,
|
|
1987
|
+
'MainArea.create': create$1,
|
|
1565
1988
|
'MainArea.diff2': diff2,
|
|
1566
1989
|
'MainArea.getCommandIds': getCommandIds,
|
|
1990
|
+
'MainArea.getMenuEntries': wrapGetter(getMenuEntries),
|
|
1991
|
+
'MainArea.getMenuIds': getMenuIds,
|
|
1567
1992
|
'MainArea.handleClick': wrapCommand(handleClick),
|
|
1568
1993
|
'MainArea.handleClickCloseTab': wrapCommand(handleClickCloseTab),
|
|
1569
1994
|
'MainArea.handleClickTab': wrapCommand(handleClickTab),
|
|
1995
|
+
'MainArea.handleTabContextMenu': wrapCommand(handleTabContextMenu),
|
|
1570
1996
|
'MainArea.initialize': initialize,
|
|
1571
1997
|
'MainArea.loadContent': wrapCommand(loadContent),
|
|
1572
1998
|
'MainArea.openUri': wrapCommand(openUri),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/main-area-worker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Main Area Worker",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "dist/mainAreaWorkerMain.js",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@lvce-editor/virtual-dom-worker": "^
|
|
14
|
+
"@lvce-editor/virtual-dom-worker": "^6.2.0"
|
|
15
15
|
}
|
|
16
16
|
}
|