@lvce-editor/main-area-worker 1.10.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 +185 -9
- 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;
|
|
@@ -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
|
|
|
@@ -1094,9 +1108,18 @@ const {
|
|
|
1094
1108
|
} = create$3(ExtensionHostWorker);
|
|
1095
1109
|
|
|
1096
1110
|
const {
|
|
1111
|
+
invoke,
|
|
1097
1112
|
invokeAndTransfer,
|
|
1098
1113
|
set: set$1
|
|
1099
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);
|
|
@@ -1192,7 +1215,9 @@ const {
|
|
|
1192
1215
|
getCommandIds,
|
|
1193
1216
|
registerCommands,
|
|
1194
1217
|
set,
|
|
1195
|
-
wrapCommand
|
|
1218
|
+
wrapCommand,
|
|
1219
|
+
wrapGetter
|
|
1220
|
+
} = create$2();
|
|
1196
1221
|
|
|
1197
1222
|
const create$1 = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
1198
1223
|
const state = {
|
|
@@ -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;
|
|
@@ -1377,6 +1406,22 @@ const handleClickTab = async (state, groupIndexRaw, indexRaw) => {
|
|
|
1377
1406
|
return selectTab(state, groupIndex, index);
|
|
1378
1407
|
};
|
|
1379
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
|
+
|
|
1380
1425
|
const id = 7201;
|
|
1381
1426
|
const sendMessagePortToExtensionHostWorker = async port => {
|
|
1382
1427
|
await sendMessagePortToExtensionHostWorker$1(port, id);
|
|
@@ -1459,6 +1504,117 @@ const loadContent = async state => {
|
|
|
1459
1504
|
};
|
|
1460
1505
|
};
|
|
1461
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
|
+
|
|
1462
1618
|
const findTabByUri = (state, uri) => {
|
|
1463
1619
|
const {
|
|
1464
1620
|
layout
|
|
@@ -1535,6 +1691,13 @@ const openTab = (state, groupId, tab) => {
|
|
|
1535
1691
|
};
|
|
1536
1692
|
};
|
|
1537
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
|
+
};
|
|
1538
1701
|
const getLabel = uri => {
|
|
1539
1702
|
if (uri.startsWith('settings://')) {
|
|
1540
1703
|
return 'Settings';
|
|
@@ -1542,8 +1705,7 @@ const getLabel = uri => {
|
|
|
1542
1705
|
if (uri.startsWith('simple-browser://')) {
|
|
1543
1706
|
return 'Simple Browser';
|
|
1544
1707
|
}
|
|
1545
|
-
return uri;
|
|
1546
|
-
// return Workspace.pathBaseName(uri)
|
|
1708
|
+
return getBasename(uri);
|
|
1547
1709
|
};
|
|
1548
1710
|
|
|
1549
1711
|
const switchTab = (state, groupId, tabId) => {
|
|
@@ -1574,12 +1736,16 @@ const switchTab = (state, groupId, tabId) => {
|
|
|
1574
1736
|
};
|
|
1575
1737
|
};
|
|
1576
1738
|
|
|
1739
|
+
/* eslint-disable prefer-destructuring */
|
|
1740
|
+
|
|
1577
1741
|
const openUri = async (state, options) => {
|
|
1578
1742
|
object(state);
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
uri
|
|
1582
|
-
}
|
|
1743
|
+
let uri = '';
|
|
1744
|
+
if (typeof options === 'string') {
|
|
1745
|
+
uri = options;
|
|
1746
|
+
} else {
|
|
1747
|
+
uri = options.uri;
|
|
1748
|
+
}
|
|
1583
1749
|
|
|
1584
1750
|
// Check if a tab with this URI already exists
|
|
1585
1751
|
const existingTab = findTabByUri(state, uri);
|
|
@@ -1684,6 +1850,7 @@ const renderEditor = tab => {
|
|
|
1684
1850
|
const HandleClick = 11;
|
|
1685
1851
|
const HandleClickClose = 12;
|
|
1686
1852
|
const HandleClickTab = 13;
|
|
1853
|
+
const HandleTabContextMenu = 14;
|
|
1687
1854
|
|
|
1688
1855
|
const renderTab = (tab, isActive, tabIndex, groupIndex) => {
|
|
1689
1856
|
return [{
|
|
@@ -1692,7 +1859,9 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
|
|
|
1692
1859
|
'data-groupIndex': groupIndex,
|
|
1693
1860
|
'data-index': tabIndex,
|
|
1694
1861
|
onClick: HandleClickTab,
|
|
1862
|
+
onContextMenu: HandleTabContextMenu,
|
|
1695
1863
|
role: 'tab',
|
|
1864
|
+
title: tab.path || tab.title,
|
|
1696
1865
|
type: Div
|
|
1697
1866
|
}, {
|
|
1698
1867
|
childCount: 1,
|
|
@@ -1704,7 +1873,7 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
|
|
|
1704
1873
|
'data-groupIndex': groupIndex,
|
|
1705
1874
|
'data-index': tabIndex,
|
|
1706
1875
|
onClick: HandleClickClose,
|
|
1707
|
-
type: Button
|
|
1876
|
+
type: Button$1
|
|
1708
1877
|
}, text('×')];
|
|
1709
1878
|
};
|
|
1710
1879
|
|
|
@@ -1791,6 +1960,10 @@ const renderEventListeners = () => {
|
|
|
1791
1960
|
}, {
|
|
1792
1961
|
name: HandleClickTab,
|
|
1793
1962
|
params: ['handleClickTab', 'event.target.dataset.groupIndex', 'event.target.dataset.index']
|
|
1963
|
+
}, {
|
|
1964
|
+
name: HandleTabContextMenu,
|
|
1965
|
+
params: ['handleTabContextMenu', Button, ClientX, ClientY],
|
|
1966
|
+
preventDefault: true
|
|
1794
1967
|
}];
|
|
1795
1968
|
};
|
|
1796
1969
|
|
|
@@ -1814,9 +1987,12 @@ const commandMap = {
|
|
|
1814
1987
|
'MainArea.create': create$1,
|
|
1815
1988
|
'MainArea.diff2': diff2,
|
|
1816
1989
|
'MainArea.getCommandIds': getCommandIds,
|
|
1990
|
+
'MainArea.getMenuEntries': wrapGetter(getMenuEntries),
|
|
1991
|
+
'MainArea.getMenuIds': getMenuIds,
|
|
1817
1992
|
'MainArea.handleClick': wrapCommand(handleClick),
|
|
1818
1993
|
'MainArea.handleClickCloseTab': wrapCommand(handleClickCloseTab),
|
|
1819
1994
|
'MainArea.handleClickTab': wrapCommand(handleClickTab),
|
|
1995
|
+
'MainArea.handleTabContextMenu': wrapCommand(handleTabContextMenu),
|
|
1820
1996
|
'MainArea.initialize': initialize,
|
|
1821
1997
|
'MainArea.loadContent': wrapCommand(loadContent),
|
|
1822
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
|
}
|