@lvce-editor/source-control-worker 1.4.0 → 1.5.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 +144 -91
- package/package.json +1 -1
|
@@ -1062,7 +1062,9 @@ const create2 = (id, uri, x, y, width, height, workspacePath) => {
|
|
|
1062
1062
|
itemHeight: 20,
|
|
1063
1063
|
minimumSliderSize: 20,
|
|
1064
1064
|
workspacePath,
|
|
1065
|
-
headerHeight: 40
|
|
1065
|
+
headerHeight: 40,
|
|
1066
|
+
// TODO
|
|
1067
|
+
actionsCache: Object.create(null)
|
|
1066
1068
|
};
|
|
1067
1069
|
set$1(id, state, state);
|
|
1068
1070
|
};
|
|
@@ -1097,7 +1099,7 @@ const diff2 = uid => {
|
|
|
1097
1099
|
return result;
|
|
1098
1100
|
};
|
|
1099
1101
|
|
|
1100
|
-
const commandIds = ['acceptInput', '
|
|
1102
|
+
const commandIds = ['acceptInput', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'handleClick', 'handleClickAt', 'handleFocus', 'handleIconThemeChange', 'handleMouseOut', 'handleMouseOutAt', 'handleMouseOver', 'handleMouseOverAt', 'handleWheel', 'selectIndex'];
|
|
1101
1103
|
|
|
1102
1104
|
const getCommandIds = () => {
|
|
1103
1105
|
return commandIds;
|
|
@@ -1380,40 +1382,21 @@ const getListHeight = (itemsLength, itemHeight, maxHeight) => {
|
|
|
1380
1382
|
return Math.min(totalHeight, maxHeight);
|
|
1381
1383
|
};
|
|
1382
1384
|
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
// 20px fill 100px but when scrolled 6 items are needed
|
|
1386
|
-
const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
1387
|
-
return Math.ceil(listHeight / itemHeight) + 1;
|
|
1388
|
-
};
|
|
1389
|
-
|
|
1390
|
-
const Disk = 'file';
|
|
1391
|
-
|
|
1392
|
-
const RE_PROTOCOL = /^([a-z-]+):\/\//;
|
|
1393
|
-
const getProtocol = uri => {
|
|
1394
|
-
if (!uri) {
|
|
1395
|
-
return Disk;
|
|
1396
|
-
}
|
|
1397
|
-
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
1398
|
-
if (protocolMatch) {
|
|
1399
|
-
return protocolMatch[1];
|
|
1400
|
-
}
|
|
1401
|
-
return Disk;
|
|
1402
|
-
};
|
|
1403
|
-
|
|
1404
|
-
const get = key => {
|
|
1405
|
-
return false;
|
|
1385
|
+
const getExtensions = async () => {
|
|
1386
|
+
return invoke('Extensions.getExtensions');
|
|
1406
1387
|
};
|
|
1407
1388
|
|
|
1408
|
-
const
|
|
1409
|
-
|
|
1410
|
-
|
|
1389
|
+
const requestSourceActions = async () => {
|
|
1390
|
+
const extensions = await getExtensions();
|
|
1391
|
+
const newCache = Object.create(null);
|
|
1392
|
+
for (const extension of extensions) {
|
|
1393
|
+
if (extension && extension['source-control-actions']) {
|
|
1394
|
+
for (const [key, value] of Object.entries(extension['source-control-actions'])) {
|
|
1395
|
+
newCache.cache[key] = value;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1411
1398
|
}
|
|
1412
|
-
return
|
|
1413
|
-
};
|
|
1414
|
-
|
|
1415
|
-
const getExtensions = async () => {
|
|
1416
|
-
return invoke('Extensions.getExtensions');
|
|
1399
|
+
return newCache;
|
|
1417
1400
|
};
|
|
1418
1401
|
|
|
1419
1402
|
const state = {
|
|
@@ -1429,14 +1412,8 @@ const ensureActions = async () => {
|
|
|
1429
1412
|
if (Object.keys(state.cache).length > 0) {
|
|
1430
1413
|
return;
|
|
1431
1414
|
}
|
|
1432
|
-
const
|
|
1433
|
-
|
|
1434
|
-
if (extension && extension['source-control-actions']) {
|
|
1435
|
-
for (const [key, value] of Object.entries(extension['source-control-actions'])) {
|
|
1436
|
-
state.cache[key] = value;
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1415
|
+
const newCache = await requestSourceActions();
|
|
1416
|
+
state.cache = newCache;
|
|
1440
1417
|
};
|
|
1441
1418
|
const getSourceControlActions = async (providerId, groupId, type) => {
|
|
1442
1419
|
string(groupId);
|
|
@@ -1446,7 +1423,7 @@ const getSourceControlActions = async (providerId, groupId, type) => {
|
|
|
1446
1423
|
return value;
|
|
1447
1424
|
};
|
|
1448
1425
|
|
|
1449
|
-
const getNewButtons = async (displayItems, providerId, buttonIndex) => {
|
|
1426
|
+
const getNewButtons = async (displayItems, providerId, buttonIndex, actionsCache) => {
|
|
1450
1427
|
if (buttonIndex === -1) {
|
|
1451
1428
|
return [];
|
|
1452
1429
|
}
|
|
@@ -1457,14 +1434,48 @@ const getNewButtons = async (displayItems, providerId, buttonIndex) => {
|
|
|
1457
1434
|
const actions = await getSourceControlActions(providerId, item.groupId, item.type);
|
|
1458
1435
|
return actions;
|
|
1459
1436
|
};
|
|
1437
|
+
|
|
1438
|
+
// TODO optimize this function to return the minimum number
|
|
1439
|
+
// of visible items needed, e.g. when not scrolled 5 items with
|
|
1440
|
+
// 20px fill 100px but when scrolled 6 items are needed
|
|
1441
|
+
const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
1442
|
+
return Math.ceil(listHeight / itemHeight) + 1;
|
|
1443
|
+
};
|
|
1444
|
+
|
|
1445
|
+
const Disk = 'file';
|
|
1446
|
+
|
|
1447
|
+
const RE_PROTOCOL = /^([a-z-]+):\/\//;
|
|
1448
|
+
const getProtocol = uri => {
|
|
1449
|
+
if (!uri) {
|
|
1450
|
+
return Disk;
|
|
1451
|
+
}
|
|
1452
|
+
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
1453
|
+
if (protocolMatch) {
|
|
1454
|
+
return protocolMatch[1];
|
|
1455
|
+
}
|
|
1456
|
+
return Disk;
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1459
|
+
const get = key => {
|
|
1460
|
+
return false;
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
1464
|
+
if (size >= contentSize) {
|
|
1465
|
+
return 0;
|
|
1466
|
+
}
|
|
1467
|
+
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
1468
|
+
};
|
|
1469
|
+
|
|
1460
1470
|
const loadContent = async state => {
|
|
1461
1471
|
const {
|
|
1462
1472
|
itemHeight,
|
|
1463
1473
|
height,
|
|
1464
1474
|
minimumSliderSize,
|
|
1465
1475
|
workspacePath,
|
|
1466
|
-
fileIconCache
|
|
1467
|
-
|
|
1476
|
+
fileIconCache,
|
|
1477
|
+
providerId,
|
|
1478
|
+
buttonIndex} = state;
|
|
1468
1479
|
const root = workspacePath;
|
|
1469
1480
|
const scheme = getProtocol(root);
|
|
1470
1481
|
const enabledProviderIds = await getEnabledProviderIds(scheme, root);
|
|
@@ -1474,7 +1485,7 @@ const loadContent = async state => {
|
|
|
1474
1485
|
} = await getGroups(enabledProviderIds);
|
|
1475
1486
|
const isExpanded = true;
|
|
1476
1487
|
const items = getDisplayItems(allGroups, isExpanded);
|
|
1477
|
-
const buttons = await getNewButtons(items,
|
|
1488
|
+
const buttons = await getNewButtons(items, providerId, buttonIndex);
|
|
1478
1489
|
const splitButtonEnabled = get();
|
|
1479
1490
|
const total = items.length;
|
|
1480
1491
|
const contentHeight = total * itemHeight;
|
|
@@ -1628,6 +1639,25 @@ const handleFocus = async state => {
|
|
|
1628
1639
|
return state;
|
|
1629
1640
|
};
|
|
1630
1641
|
|
|
1642
|
+
const handleMouseOut = (state, index) => {
|
|
1643
|
+
const {
|
|
1644
|
+
items
|
|
1645
|
+
} = state;
|
|
1646
|
+
if (index === -1 || index > items.length) {
|
|
1647
|
+
return {
|
|
1648
|
+
...state,
|
|
1649
|
+
buttonIndex: -1,
|
|
1650
|
+
buttons: []
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
return state;
|
|
1654
|
+
};
|
|
1655
|
+
|
|
1656
|
+
const handleMouseOutAt = (state, eventX, eventY) => {
|
|
1657
|
+
const index = getIndex(state, eventX, eventY);
|
|
1658
|
+
return handleMouseOut(state, index);
|
|
1659
|
+
};
|
|
1660
|
+
|
|
1631
1661
|
const handleMouseOver = async (state, index) => {
|
|
1632
1662
|
const {
|
|
1633
1663
|
items,
|
|
@@ -1649,6 +1679,11 @@ const handleMouseOver = async (state, index) => {
|
|
|
1649
1679
|
};
|
|
1650
1680
|
};
|
|
1651
1681
|
|
|
1682
|
+
const handleMouseOverAt = async (state, eventX, eventY) => {
|
|
1683
|
+
const index = getIndex(state, eventX, eventY);
|
|
1684
|
+
return handleMouseOver(state, index);
|
|
1685
|
+
};
|
|
1686
|
+
|
|
1652
1687
|
const getPortTuple = () => {
|
|
1653
1688
|
const {
|
|
1654
1689
|
port1,
|
|
@@ -1691,6 +1726,7 @@ const initialize = async () => {
|
|
|
1691
1726
|
};
|
|
1692
1727
|
|
|
1693
1728
|
const Actions = 'Actions';
|
|
1729
|
+
const Grow = 'Grow';
|
|
1694
1730
|
const Chevron = 'Chevron';
|
|
1695
1731
|
const ChevronRight = 'ChevronRight';
|
|
1696
1732
|
const DecorationIcon = 'DecorationIcon';
|
|
@@ -1722,6 +1758,7 @@ const HandleContextMenu = 'handleContextMenu';
|
|
|
1722
1758
|
const HandleFocus = 'handleFocus';
|
|
1723
1759
|
const HandleInput = 'handleInput';
|
|
1724
1760
|
const HandleMouseOut = 'handleMouseOut';
|
|
1761
|
+
const HandleMouseOutAt = 'handleMouseOutAt';
|
|
1725
1762
|
const HandleMouseOver = 'handleMouseOver';
|
|
1726
1763
|
const HandleMouseOverAt = 'handleMouseOverAt';
|
|
1727
1764
|
const HandleWheel = 'handleWheel';
|
|
@@ -1781,37 +1818,6 @@ const ToolBar = 'toolbar';
|
|
|
1781
1818
|
const Tree = 'tree';
|
|
1782
1819
|
const TreeItem = 'treeitem';
|
|
1783
1820
|
|
|
1784
|
-
const emptySourceControlButtons = [];
|
|
1785
|
-
|
|
1786
|
-
const getIconVirtualDom = (icon, type = Div) => {
|
|
1787
|
-
return {
|
|
1788
|
-
type,
|
|
1789
|
-
className: `MaskIcon MaskIcon${icon}`,
|
|
1790
|
-
role: None,
|
|
1791
|
-
childCount: 0
|
|
1792
|
-
};
|
|
1793
|
-
};
|
|
1794
|
-
|
|
1795
|
-
const addButtons = (dom, buttons) => {
|
|
1796
|
-
if (buttons === emptySourceControlButtons) {
|
|
1797
|
-
return;
|
|
1798
|
-
}
|
|
1799
|
-
dom[0].childCount += buttons.length;
|
|
1800
|
-
for (const button of buttons) {
|
|
1801
|
-
const {
|
|
1802
|
-
icon,
|
|
1803
|
-
label
|
|
1804
|
-
} = button;
|
|
1805
|
-
dom.push({
|
|
1806
|
-
type: Button$1,
|
|
1807
|
-
className: SourceControlButton,
|
|
1808
|
-
title: label,
|
|
1809
|
-
ariaLabel: label,
|
|
1810
|
-
childCount: 1
|
|
1811
|
-
}, getIconVirtualDom(icon, Span));
|
|
1812
|
-
}
|
|
1813
|
-
};
|
|
1814
|
-
|
|
1815
1821
|
const mergeClassNames = (...classNames) => {
|
|
1816
1822
|
return classNames.filter(Boolean).join(' ');
|
|
1817
1823
|
};
|
|
@@ -1832,10 +1838,46 @@ const getBadgeVirtualDom = (className, count) => {
|
|
|
1832
1838
|
}, text(`${count}`)];
|
|
1833
1839
|
};
|
|
1834
1840
|
|
|
1841
|
+
const emptySourceControlButtons = [];
|
|
1842
|
+
|
|
1843
|
+
const getIconVirtualDom = (icon, type = Div) => {
|
|
1844
|
+
return {
|
|
1845
|
+
type,
|
|
1846
|
+
className: `MaskIcon MaskIcon${icon}`,
|
|
1847
|
+
role: None,
|
|
1848
|
+
childCount: 0
|
|
1849
|
+
};
|
|
1850
|
+
};
|
|
1851
|
+
|
|
1852
|
+
const getButtonVirtualDom = button => {
|
|
1853
|
+
const {
|
|
1854
|
+
icon,
|
|
1855
|
+
label
|
|
1856
|
+
} = button;
|
|
1857
|
+
return [{
|
|
1858
|
+
type: Button$1,
|
|
1859
|
+
className: SourceControlButton,
|
|
1860
|
+
title: label,
|
|
1861
|
+
ariaLabel: label,
|
|
1862
|
+
childCount: 1
|
|
1863
|
+
}, getIconVirtualDom(icon, Span)];
|
|
1864
|
+
};
|
|
1865
|
+
|
|
1866
|
+
const getButtonsVirtualDom = buttons => {
|
|
1867
|
+
if (buttons === emptySourceControlButtons) {
|
|
1868
|
+
return [];
|
|
1869
|
+
}
|
|
1870
|
+
return [{
|
|
1871
|
+
type: Div,
|
|
1872
|
+
className: 'SourceControlButtons',
|
|
1873
|
+
childCount: buttons.length
|
|
1874
|
+
}, ...buttons.flatMap(getButtonVirtualDom)];
|
|
1875
|
+
};
|
|
1876
|
+
|
|
1835
1877
|
const getLabelClassName = decorationStrikeThrough => {
|
|
1836
|
-
let className = Label
|
|
1878
|
+
let className = mergeClassNames(Label, Grow);
|
|
1837
1879
|
if (decorationStrikeThrough) {
|
|
1838
|
-
className
|
|
1880
|
+
className = mergeClassNames(className, StrikeThrough);
|
|
1839
1881
|
}
|
|
1840
1882
|
return className;
|
|
1841
1883
|
};
|
|
@@ -1855,28 +1897,27 @@ const createItemDirectory = item => {
|
|
|
1855
1897
|
buttons
|
|
1856
1898
|
} = item;
|
|
1857
1899
|
const labelClassName = getLabelClassName(decorationStrikeThrough);
|
|
1858
|
-
const
|
|
1900
|
+
const buttonsDom = getButtonsVirtualDom(buttons);
|
|
1901
|
+
const hasButtons = buttons.length;
|
|
1902
|
+
return [{
|
|
1859
1903
|
type: Div,
|
|
1860
1904
|
className: TreeItem$1,
|
|
1861
1905
|
role: TreeItem,
|
|
1862
1906
|
ariaExpanded: type === DirectoryExpanded,
|
|
1863
1907
|
ariaPosInSet: posInSet,
|
|
1864
1908
|
ariaSetSize: setSize,
|
|
1865
|
-
childCount: 3,
|
|
1909
|
+
childCount: 3 + (hasButtons ? 1 : 0),
|
|
1866
1910
|
paddingLeft: PaddingLeft,
|
|
1867
1911
|
paddingRight: PaddingRight
|
|
1868
1912
|
}, {
|
|
1869
1913
|
type: Div,
|
|
1870
|
-
className:
|
|
1914
|
+
className: mergeClassNames(Chevron, `MaskIcon${icon}`),
|
|
1871
1915
|
childCount: 0
|
|
1872
1916
|
}, {
|
|
1873
1917
|
type: Div,
|
|
1874
1918
|
className: labelClassName,
|
|
1875
1919
|
childCount: 1
|
|
1876
|
-
}, text(label)];
|
|
1877
|
-
addButtons(dom, buttons);
|
|
1878
|
-
dom.push(...getBadgeVirtualDom(SourceControlBadge, badgeCount));
|
|
1879
|
-
return dom;
|
|
1920
|
+
}, text(label), ...buttonsDom, ...getBadgeVirtualDom(SourceControlBadge, badgeCount)];
|
|
1880
1921
|
};
|
|
1881
1922
|
|
|
1882
1923
|
const getFileIconVirtualDom = icon => {
|
|
@@ -1916,6 +1957,8 @@ const createItemOther = item => {
|
|
|
1916
1957
|
} = item;
|
|
1917
1958
|
const labelClassName = getLabelClassName(decorationStrikeThrough);
|
|
1918
1959
|
const dom = [];
|
|
1960
|
+
const hasButtons = buttons.length;
|
|
1961
|
+
const buttonsDom = getButtonsVirtualDom(buttons);
|
|
1919
1962
|
dom.push({
|
|
1920
1963
|
type: Div,
|
|
1921
1964
|
className: TreeItem$1,
|
|
@@ -1923,7 +1966,7 @@ const createItemOther = item => {
|
|
|
1923
1966
|
ariaPosInSet: posInSet,
|
|
1924
1967
|
ariaSetSize: setSize,
|
|
1925
1968
|
title: file,
|
|
1926
|
-
childCount: 3,
|
|
1969
|
+
childCount: 3 + (hasButtons ? 1 : 0),
|
|
1927
1970
|
paddingLeft: '1rem',
|
|
1928
1971
|
paddingRight: '12px'
|
|
1929
1972
|
}, ...getIconsDom(icon, fileIcon));
|
|
@@ -1941,7 +1984,7 @@ const createItemOther = item => {
|
|
|
1941
1984
|
childCount: 1
|
|
1942
1985
|
}, text(detail));
|
|
1943
1986
|
}
|
|
1944
|
-
|
|
1987
|
+
dom.push(...buttonsDom);
|
|
1945
1988
|
dom.push({
|
|
1946
1989
|
type: Img,
|
|
1947
1990
|
className: DecorationIcon,
|
|
@@ -1968,7 +2011,9 @@ const getSourceControlListVirtualDom = items => {
|
|
|
1968
2011
|
className: SourceControlItems,
|
|
1969
2012
|
role: Tree,
|
|
1970
2013
|
childCount: items.length,
|
|
1971
|
-
onClick: HandleClickAt
|
|
2014
|
+
onClick: HandleClickAt,
|
|
2015
|
+
onPointerOver: HandleMouseOverAt,
|
|
2016
|
+
onPointerOut: HandleMouseOutAt
|
|
1972
2017
|
}, ...items.flatMap(getSourceControlItemVirtualDom)];
|
|
1973
2018
|
};
|
|
1974
2019
|
|
|
@@ -2126,6 +2171,9 @@ const renderEventListeners = () => {
|
|
|
2126
2171
|
}, {
|
|
2127
2172
|
name: HandleMouseOver,
|
|
2128
2173
|
params: ['handleMouseOver', 'event.clientX', 'event.clientY']
|
|
2174
|
+
}, {
|
|
2175
|
+
name: HandleMouseOutAt,
|
|
2176
|
+
params: ['handleMouseOutAt', 'event.clientX', 'event.clientY']
|
|
2129
2177
|
}, {
|
|
2130
2178
|
name: HandleInput,
|
|
2131
2179
|
params: ['handleInput', 'event.target.value']
|
|
@@ -2148,13 +2196,15 @@ const saveState = uid => {
|
|
|
2148
2196
|
} = value;
|
|
2149
2197
|
const {
|
|
2150
2198
|
root,
|
|
2151
|
-
maxLineY
|
|
2199
|
+
maxLineY,
|
|
2200
|
+
isExpanded
|
|
2152
2201
|
} = newState;
|
|
2153
2202
|
return {
|
|
2154
2203
|
root,
|
|
2155
2204
|
minLineY: 0,
|
|
2156
2205
|
maxLineY,
|
|
2157
|
-
deltaY: 0
|
|
2206
|
+
deltaY: 0,
|
|
2207
|
+
isExpanded
|
|
2158
2208
|
};
|
|
2159
2209
|
};
|
|
2160
2210
|
|
|
@@ -2188,9 +2238,12 @@ const commandMap = {
|
|
|
2188
2238
|
'SourceControl.handleButtonClick': wrapCommand(handleButtonClick),
|
|
2189
2239
|
'SourceControl.handleClickAt': wrapCommand(handleClickAt),
|
|
2190
2240
|
'SourceControl.handleContextMenu': wrapCommand(handleContextMenu),
|
|
2241
|
+
'SourceControl.handleFocus': wrapCommand(handleFocus),
|
|
2242
|
+
'SourceControl.handleMouseOut': wrapCommand(handleMouseOut),
|
|
2243
|
+
'SourceControl.handleMouseOutAt': wrapCommand(handleMouseOutAt),
|
|
2191
2244
|
'SourceControl.handleMouseOver': wrapCommand(handleMouseOver),
|
|
2245
|
+
'SourceControl.handleMouseOverAt': wrapCommand(handleMouseOverAt),
|
|
2192
2246
|
'SourceControl.loadContent': wrapCommand(loadContent),
|
|
2193
|
-
'SourceControl.handleFocus': wrapCommand(handleFocus),
|
|
2194
2247
|
'SourceControl.render2': render2,
|
|
2195
2248
|
'SourceControl.renderActions2': renderActions,
|
|
2196
2249
|
'SourceControl.renderEventListeners': renderEventListeners,
|