@lvce-editor/source-control-worker 1.3.0 → 1.4.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/sourceControlWorkerMain.js +169 -38
- package/package.json +1 -1
|
@@ -1051,7 +1051,6 @@ const create2 = (id, uri, x, y, width, height, workspacePath) => {
|
|
|
1051
1051
|
untracked: [],
|
|
1052
1052
|
workingTree: [],
|
|
1053
1053
|
inputValue: '',
|
|
1054
|
-
displayItems: [],
|
|
1055
1054
|
buttonIndex: -1,
|
|
1056
1055
|
enabledProviderIds: [],
|
|
1057
1056
|
isExpanded: true,
|
|
@@ -1062,7 +1061,8 @@ const create2 = (id, uri, x, y, width, height, workspacePath) => {
|
|
|
1062
1061
|
gitRoot: '',
|
|
1063
1062
|
itemHeight: 20,
|
|
1064
1063
|
minimumSliderSize: 20,
|
|
1065
|
-
workspacePath
|
|
1064
|
+
workspacePath,
|
|
1065
|
+
headerHeight: 40 // TODO
|
|
1066
1066
|
};
|
|
1067
1067
|
set$1(id, state, state);
|
|
1068
1068
|
};
|
|
@@ -1071,7 +1071,7 @@ const RenderItems = 4;
|
|
|
1071
1071
|
|
|
1072
1072
|
const diffType = RenderItems;
|
|
1073
1073
|
const isEqual = (oldState, newState) => {
|
|
1074
|
-
return oldState.allGroups === newState.allGroups && oldState.
|
|
1074
|
+
return oldState.allGroups === newState.allGroups && oldState.items === newState.items && oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.deltaY === newState.deltaY && oldState.buttonIndex === newState.buttonIndex && oldState.buttons === newState.buttons;
|
|
1075
1075
|
};
|
|
1076
1076
|
|
|
1077
1077
|
const modules = [isEqual];
|
|
@@ -1097,7 +1097,7 @@ const diff2 = uid => {
|
|
|
1097
1097
|
return result;
|
|
1098
1098
|
};
|
|
1099
1099
|
|
|
1100
|
-
const commandIds = ['acceptInput', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'handleClick', 'handleClickAt', 'handleIconThemeChange', 'handleWheel'];
|
|
1100
|
+
const commandIds = ['acceptInput', 'handleMouseOut', 'focus', 'focusFirst', 'handleFocus', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'handleClick', 'handleClickAt', 'handleIconThemeChange', 'handleMouseOver', 'handleWheel', 'selectIndex', 'handleMouseOverAt'];
|
|
1101
1101
|
|
|
1102
1102
|
const getCommandIds = () => {
|
|
1103
1103
|
return commandIds;
|
|
@@ -1147,6 +1147,7 @@ const executeProvider = async ({
|
|
|
1147
1147
|
|
|
1148
1148
|
const CommandExecute = 'ExtensionHostCommand.executeCommand';
|
|
1149
1149
|
const SourceControlGetEnabledProviderIds = 'ExtensionHostSourceControl.getEnabledProviderIds';
|
|
1150
|
+
const SourceControlGetFileBefore = 'ExtensionHostSourceControl.GetFileBefore';
|
|
1150
1151
|
const SourceControlGetGroups = 'ExtensionHostSourceControl.getGroups';
|
|
1151
1152
|
|
|
1152
1153
|
const executeCommand = (id, ...args) => {
|
|
@@ -1183,8 +1184,8 @@ const getDisplayItemsGroup = (group, isExpanded) => {
|
|
|
1183
1184
|
throw new Error('Source control group is missing an items property');
|
|
1184
1185
|
}
|
|
1185
1186
|
const length = items.length;
|
|
1186
|
-
const type = DirectoryExpanded ;
|
|
1187
|
-
const icon = 'ChevronDown' ;
|
|
1187
|
+
const type = isExpanded ? DirectoryExpanded : Directory;
|
|
1188
|
+
const icon = isExpanded ? 'ChevronDown' : 'ChevronRight';
|
|
1188
1189
|
if (length > 0) {
|
|
1189
1190
|
displayItems.push({
|
|
1190
1191
|
file: '',
|
|
@@ -1201,7 +1202,7 @@ const getDisplayItemsGroup = (group, isExpanded) => {
|
|
|
1201
1202
|
groupId: id
|
|
1202
1203
|
});
|
|
1203
1204
|
}
|
|
1204
|
-
{
|
|
1205
|
+
if (isExpanded) {
|
|
1205
1206
|
for (let i = 0; i < length; i++) {
|
|
1206
1207
|
const item = items[i];
|
|
1207
1208
|
const {
|
|
@@ -1236,7 +1237,7 @@ const getDisplayItemsGroup = (group, isExpanded) => {
|
|
|
1236
1237
|
const getDisplayItems = (allGroups, isExpanded) => {
|
|
1237
1238
|
const displayItems = [];
|
|
1238
1239
|
for (const group of allGroups) {
|
|
1239
|
-
const groupDisplayItems = getDisplayItemsGroup(group);
|
|
1240
|
+
const groupDisplayItems = getDisplayItemsGroup(group, isExpanded);
|
|
1240
1241
|
displayItems.push(...groupDisplayItems);
|
|
1241
1242
|
}
|
|
1242
1243
|
return displayItems;
|
|
@@ -1318,6 +1319,14 @@ const getFinalDeltaY = (height, itemHeight, itemsLength) => {
|
|
|
1318
1319
|
return finalDeltaY;
|
|
1319
1320
|
};
|
|
1320
1321
|
|
|
1322
|
+
const getFileBefore$1 = (providerId, path) => {
|
|
1323
|
+
return executeProvider({
|
|
1324
|
+
event: 'none',
|
|
1325
|
+
method: SourceControlGetFileBefore,
|
|
1326
|
+
params: [providerId, path]
|
|
1327
|
+
// noProviderFoundMessage: 'No source control provider found',
|
|
1328
|
+
});
|
|
1329
|
+
};
|
|
1321
1330
|
const getGroups$2 = (providerId, path) => {
|
|
1322
1331
|
return executeProvider({
|
|
1323
1332
|
event: 'none',
|
|
@@ -1335,6 +1344,9 @@ const getEnabledProviderIds$1 = (scheme, root) => {
|
|
|
1335
1344
|
});
|
|
1336
1345
|
};
|
|
1337
1346
|
|
|
1347
|
+
const getFileBefore = (providerId, file) => {
|
|
1348
|
+
return getFileBefore$1(providerId, file);
|
|
1349
|
+
};
|
|
1338
1350
|
const getEnabledProviderIds = (scheme, root) => {
|
|
1339
1351
|
string(scheme);
|
|
1340
1352
|
string(root);
|
|
@@ -1461,7 +1473,7 @@ const loadContent = async state => {
|
|
|
1461
1473
|
gitRoot
|
|
1462
1474
|
} = await getGroups(enabledProviderIds);
|
|
1463
1475
|
const isExpanded = true;
|
|
1464
|
-
const items = getDisplayItems(allGroups);
|
|
1476
|
+
const items = getDisplayItems(allGroups, isExpanded);
|
|
1465
1477
|
const buttons = await getNewButtons(items, state.providerId, state.buttonIndex);
|
|
1466
1478
|
const splitButtonEnabled = get();
|
|
1467
1479
|
const total = items.length;
|
|
@@ -1509,6 +1521,98 @@ const handleButtonClick = async (state, clickedIndex) => {
|
|
|
1509
1521
|
return newState;
|
|
1510
1522
|
};
|
|
1511
1523
|
|
|
1524
|
+
const getIndex = (state, eventX, eventY) => {
|
|
1525
|
+
const {
|
|
1526
|
+
headerHeight,
|
|
1527
|
+
y,
|
|
1528
|
+
itemHeight
|
|
1529
|
+
} = state;
|
|
1530
|
+
const relativeY = eventY - y - headerHeight;
|
|
1531
|
+
const index = Math.floor(relativeY / itemHeight);
|
|
1532
|
+
return index;
|
|
1533
|
+
};
|
|
1534
|
+
|
|
1535
|
+
const handleClickDirectory = async (state, item) => {
|
|
1536
|
+
const {
|
|
1537
|
+
allGroups
|
|
1538
|
+
} = state;
|
|
1539
|
+
const isExpanded = true;
|
|
1540
|
+
const displayItems = getDisplayItems(allGroups, isExpanded);
|
|
1541
|
+
const newMaxLineY = displayItems.length;
|
|
1542
|
+
return {
|
|
1543
|
+
...state,
|
|
1544
|
+
items: displayItems,
|
|
1545
|
+
isExpanded,
|
|
1546
|
+
maxLineY: newMaxLineY
|
|
1547
|
+
};
|
|
1548
|
+
};
|
|
1549
|
+
|
|
1550
|
+
const handleClickDirectoryExpanded = async (state, item) => {
|
|
1551
|
+
const {
|
|
1552
|
+
allGroups,
|
|
1553
|
+
maxLineY
|
|
1554
|
+
} = state;
|
|
1555
|
+
const isExpanded = false;
|
|
1556
|
+
const displayItems = getDisplayItems(allGroups, isExpanded);
|
|
1557
|
+
const newMaxLineY = Math.min(displayItems.length, maxLineY);
|
|
1558
|
+
return {
|
|
1559
|
+
...state,
|
|
1560
|
+
items: displayItems,
|
|
1561
|
+
isExpanded,
|
|
1562
|
+
maxLineY: newMaxLineY
|
|
1563
|
+
};
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1566
|
+
const readFile = async (uri, encoding = 'utf8') => {
|
|
1567
|
+
const content = await invoke$1('FileSystem.readFile', uri);
|
|
1568
|
+
return content;
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
const openUri = uri => {
|
|
1572
|
+
return invoke$1('Main.openUri', uri);
|
|
1573
|
+
};
|
|
1574
|
+
|
|
1575
|
+
const handleClickFile = async (state, item) => {
|
|
1576
|
+
const {
|
|
1577
|
+
enabledProviderIds,
|
|
1578
|
+
root
|
|
1579
|
+
} = state;
|
|
1580
|
+
const providerId = enabledProviderIds[0];
|
|
1581
|
+
const absolutePath = `${root}/${item.file}`;
|
|
1582
|
+
// TODO handle error
|
|
1583
|
+
const [fileBefore] = await Promise.all([getFileBefore(providerId, item.file), readFile(absolutePath)]);
|
|
1584
|
+
{
|
|
1585
|
+
await openUri(`inline-diff://data://${fileBefore}<->${absolutePath}`);
|
|
1586
|
+
}
|
|
1587
|
+
return state;
|
|
1588
|
+
};
|
|
1589
|
+
|
|
1590
|
+
const selectIndex = async (state, index) => {
|
|
1591
|
+
const {
|
|
1592
|
+
items
|
|
1593
|
+
} = state;
|
|
1594
|
+
if (index < 0 || index >= items.length) {
|
|
1595
|
+
return state;
|
|
1596
|
+
}
|
|
1597
|
+
const item = items[index];
|
|
1598
|
+
switch (item.type) {
|
|
1599
|
+
case Directory:
|
|
1600
|
+
return handleClickDirectory(state);
|
|
1601
|
+
case DirectoryExpanded:
|
|
1602
|
+
return handleClickDirectoryExpanded(state);
|
|
1603
|
+
case File:
|
|
1604
|
+
return handleClickFile(state, item);
|
|
1605
|
+
default:
|
|
1606
|
+
console.warn(`unknown item type: ${item.type}`);
|
|
1607
|
+
return state;
|
|
1608
|
+
}
|
|
1609
|
+
};
|
|
1610
|
+
|
|
1611
|
+
const handleClickAt = async (state, eventX, eventY) => {
|
|
1612
|
+
const index = getIndex(state, eventX, eventY);
|
|
1613
|
+
return selectIndex(state, index);
|
|
1614
|
+
};
|
|
1615
|
+
|
|
1512
1616
|
const show = async (x, y, id, ...args) => {
|
|
1513
1617
|
return invoke$1('ContextMenu.show', x, y, id, ...args);
|
|
1514
1618
|
};
|
|
@@ -1520,6 +1624,31 @@ const handleContextMenu = async (state, button, x, y) => {
|
|
|
1520
1624
|
return state;
|
|
1521
1625
|
};
|
|
1522
1626
|
|
|
1627
|
+
const handleFocus = async state => {
|
|
1628
|
+
return state;
|
|
1629
|
+
};
|
|
1630
|
+
|
|
1631
|
+
const handleMouseOver = async (state, index) => {
|
|
1632
|
+
const {
|
|
1633
|
+
items,
|
|
1634
|
+
providerId,
|
|
1635
|
+
buttonIndex
|
|
1636
|
+
} = state;
|
|
1637
|
+
if (index === buttonIndex) {
|
|
1638
|
+
return state;
|
|
1639
|
+
}
|
|
1640
|
+
const item = items[index];
|
|
1641
|
+
if (!item) {
|
|
1642
|
+
return state;
|
|
1643
|
+
}
|
|
1644
|
+
const actions = await getSourceControlActions(providerId, item.groupId, item.type);
|
|
1645
|
+
return {
|
|
1646
|
+
...state,
|
|
1647
|
+
buttonIndex: index,
|
|
1648
|
+
buttons: actions
|
|
1649
|
+
};
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1523
1652
|
const getPortTuple = () => {
|
|
1524
1653
|
const {
|
|
1525
1654
|
port1,
|
|
@@ -1588,20 +1717,15 @@ const StrikeThrough = 'StrikeThrough';
|
|
|
1588
1717
|
const TreeItem$1 = 'TreeItem';
|
|
1589
1718
|
const Viewlet = 'Viewlet';
|
|
1590
1719
|
|
|
1591
|
-
const HandleClick = 'handleClick';
|
|
1592
1720
|
const HandleClickAt = 'handleClickAt';
|
|
1593
1721
|
const HandleContextMenu = 'handleContextMenu';
|
|
1594
1722
|
const HandleFocus = 'handleFocus';
|
|
1595
1723
|
const HandleInput = 'handleInput';
|
|
1596
1724
|
const HandleMouseOut = 'handleMouseOut';
|
|
1597
1725
|
const HandleMouseOver = 'handleMouseOver';
|
|
1726
|
+
const HandleMouseOverAt = 'handleMouseOverAt';
|
|
1598
1727
|
const HandleWheel = 'handleWheel';
|
|
1599
1728
|
|
|
1600
|
-
const None = 'none';
|
|
1601
|
-
const ToolBar = 'toolbar';
|
|
1602
|
-
const Tree = 'tree';
|
|
1603
|
-
const TreeItem = 'treeitem';
|
|
1604
|
-
|
|
1605
1729
|
const SourceControlInput$1 = 'SourceControlInput';
|
|
1606
1730
|
|
|
1607
1731
|
const emptyObject = {};
|
|
@@ -1652,6 +1776,11 @@ const getSourceControlHeaderVirtualDom = () => {
|
|
|
1652
1776
|
}];
|
|
1653
1777
|
};
|
|
1654
1778
|
|
|
1779
|
+
const None = 'none';
|
|
1780
|
+
const ToolBar = 'toolbar';
|
|
1781
|
+
const Tree = 'tree';
|
|
1782
|
+
const TreeItem = 'treeitem';
|
|
1783
|
+
|
|
1655
1784
|
const emptySourceControlButtons = [];
|
|
1656
1785
|
|
|
1657
1786
|
const getIconVirtualDom = (icon, type = Div) => {
|
|
@@ -1833,9 +1962,21 @@ const getSourceControlItemVirtualDom = item => {
|
|
|
1833
1962
|
}
|
|
1834
1963
|
};
|
|
1835
1964
|
|
|
1836
|
-
const
|
|
1837
|
-
|
|
1838
|
-
|
|
1965
|
+
const getSourceControlListVirtualDom = items => {
|
|
1966
|
+
return [{
|
|
1967
|
+
type: Div,
|
|
1968
|
+
className: SourceControlItems,
|
|
1969
|
+
role: Tree,
|
|
1970
|
+
childCount: items.length,
|
|
1971
|
+
onClick: HandleClickAt
|
|
1972
|
+
}, ...items.flatMap(getSourceControlItemVirtualDom)];
|
|
1973
|
+
};
|
|
1974
|
+
|
|
1975
|
+
const getSplitButtonVirtualDom = (hasItems, splitButtonEnabled, buttonText) => {
|
|
1976
|
+
if (!splitButtonEnabled || !hasItems) {
|
|
1977
|
+
return [];
|
|
1978
|
+
}
|
|
1979
|
+
return [{
|
|
1839
1980
|
type: Div,
|
|
1840
1981
|
className: `${SplitButton} ${hasItems ? '' : SplitButtonDisabled}`,
|
|
1841
1982
|
childCount: 3
|
|
@@ -1857,38 +1998,21 @@ const getSourceControlItemsVirtualDom$1 = (hasItems, buttonText) => {
|
|
|
1857
1998
|
type: Div,
|
|
1858
1999
|
className: `${MaskIcon} ${MaskIconChevronDown}`,
|
|
1859
2000
|
childCount: 0
|
|
1860
|
-
}
|
|
1861
|
-
return dom;
|
|
1862
|
-
};
|
|
1863
|
-
|
|
1864
|
-
const getSourceControlItemsVirtualDom = (items, splitButtonEnabled) => {
|
|
1865
|
-
const dom = [];
|
|
1866
|
-
dom.push(...getSourceControlHeaderVirtualDom());
|
|
1867
|
-
if (splitButtonEnabled) {
|
|
1868
|
-
const hasItems = items.length > 0;
|
|
1869
|
-
dom.push(...getSourceControlItemsVirtualDom$1(hasItems, 'Commit'));
|
|
1870
|
-
}
|
|
1871
|
-
dom.push({
|
|
1872
|
-
type: Div,
|
|
1873
|
-
className: SourceControlItems,
|
|
1874
|
-
role: Tree,
|
|
1875
|
-
childCount: items.length
|
|
1876
|
-
}, ...items.flatMap(getSourceControlItemVirtualDom));
|
|
1877
|
-
return dom;
|
|
2001
|
+
}];
|
|
1878
2002
|
};
|
|
1879
2003
|
|
|
1880
2004
|
const getSourceControlVirtualDom = (items, splitButtonEnabled) => {
|
|
2005
|
+
const hasItems = items.length > 0;
|
|
1881
2006
|
const dom = [{
|
|
1882
2007
|
type: Div,
|
|
1883
2008
|
className: mergeClassNames(Viewlet, SourceControl),
|
|
1884
2009
|
tabIndex: 0,
|
|
1885
|
-
onClick: HandleClick,
|
|
1886
2010
|
onContextMenu: HandleContextMenu,
|
|
1887
2011
|
onMouseOver: HandleMouseOver,
|
|
1888
2012
|
onMouseOut: HandleMouseOut,
|
|
1889
2013
|
onWheel: HandleWheel,
|
|
1890
2014
|
childCount: splitButtonEnabled ? 3 : 2
|
|
1891
|
-
}, ...
|
|
2015
|
+
}, ...getSourceControlHeaderVirtualDom(), ...getSplitButtonVirtualDom(hasItems, splitButtonEnabled, 'Commit'), ...getSourceControlListVirtualDom(items)];
|
|
1892
2016
|
return dom;
|
|
1893
2017
|
};
|
|
1894
2018
|
|
|
@@ -1996,6 +2120,9 @@ const renderEventListeners = () => {
|
|
|
1996
2120
|
}, {
|
|
1997
2121
|
name: HandleClickAt,
|
|
1998
2122
|
params: ['handleClickAt', 'event.clientX', 'event.clientY']
|
|
2123
|
+
}, {
|
|
2124
|
+
name: HandleMouseOverAt,
|
|
2125
|
+
params: ['handleMouseOverAt', 'event.clientX', 'event.clientY']
|
|
1999
2126
|
}, {
|
|
2000
2127
|
name: HandleMouseOver,
|
|
2001
2128
|
params: ['handleMouseOver', 'event.clientX', 'event.clientY']
|
|
@@ -2059,12 +2186,16 @@ const commandMap = {
|
|
|
2059
2186
|
'SourceControl.diff2': diff2,
|
|
2060
2187
|
'SourceControl.getCommandIds': getCommandIds,
|
|
2061
2188
|
'SourceControl.handleButtonClick': wrapCommand(handleButtonClick),
|
|
2189
|
+
'SourceControl.handleClickAt': wrapCommand(handleClickAt),
|
|
2062
2190
|
'SourceControl.handleContextMenu': wrapCommand(handleContextMenu),
|
|
2191
|
+
'SourceControl.handleMouseOver': wrapCommand(handleMouseOver),
|
|
2063
2192
|
'SourceControl.loadContent': wrapCommand(loadContent),
|
|
2193
|
+
'SourceControl.handleFocus': wrapCommand(handleFocus),
|
|
2064
2194
|
'SourceControl.render2': render2,
|
|
2065
2195
|
'SourceControl.renderActions2': renderActions,
|
|
2066
2196
|
'SourceControl.renderEventListeners': renderEventListeners,
|
|
2067
2197
|
'SourceControl.saveState': saveState,
|
|
2198
|
+
'SourceControl.selectIndex': wrapCommand(selectIndex),
|
|
2068
2199
|
'SourceControl.terminate': terminate,
|
|
2069
2200
|
'SourceControl.updateIcons': wrapCommand(updateIcons)
|
|
2070
2201
|
};
|