@lvce-editor/source-control-worker 1.8.0 → 1.9.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.
@@ -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', 'handleFocus', 'handleIconThemeChange', 'handleMouseOut', 'handleMouseOutAt', 'handleMouseOver', 'handleMouseOverAt', 'handleWheel', 'selectIndex'];
1100
+ const commandIds = ['acceptInput', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'refresh', 'handleClickSourceControlButtons', 'handleClick', 'handleClickAt', 'handleFocus', 'handleIconThemeChange', 'handleMouseOut', 'handleMouseOutAt', 'handleMouseOver', 'handleMouseOverAt', 'handleWheel', 'selectIndex'];
1101
1101
 
1102
1102
  const getCommandIds = () => {
1103
1103
  return commandIds;
@@ -1531,6 +1531,65 @@ const getIndex = (state, eventX, eventY) => {
1531
1531
  return index;
1532
1532
  };
1533
1533
 
1534
+ const refresh = async state => {
1535
+ const {
1536
+ itemHeight,
1537
+ height,
1538
+ minimumSliderSize,
1539
+ fileIconCache,
1540
+ enabledProviderIds,
1541
+ splitButtonEnabled,
1542
+ actionsCache
1543
+ } = state;
1544
+ const {
1545
+ allGroups,
1546
+ gitRoot
1547
+ } = await getGroups(enabledProviderIds);
1548
+ const isExpanded = true;
1549
+ const displayItems = getDisplayItems(allGroups, isExpanded);
1550
+ const total = displayItems.length;
1551
+ const contentHeight = total * itemHeight;
1552
+ const listHeight = getListHeight(total, itemHeight, height);
1553
+ const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
1554
+ const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
1555
+ const minLineY = 0;
1556
+ const maxLineY = Math.min(numberOfVisible, total);
1557
+ const visibleItems = getVisibleSourceControlItems(displayItems, minLineY, maxLineY, actionsCache, fileIconCache);
1558
+ const finalDeltaY = getFinalDeltaY(listHeight, itemHeight, total);
1559
+ return {
1560
+ ...state,
1561
+ allGroups,
1562
+ gitRoot,
1563
+ items: displayItems,
1564
+ visibleItems,
1565
+ enabledProviderIds,
1566
+ isExpanded,
1567
+ splitButtonEnabled,
1568
+ maxLineY,
1569
+ scrollBarHeight,
1570
+ finalDeltaY,
1571
+ actionsCache
1572
+ };
1573
+ };
1574
+
1575
+ const handleClickSourceControlButtons = async (state, index, name) => {
1576
+ const {
1577
+ visibleItems
1578
+ } = state;
1579
+ const item = visibleItems[index];
1580
+ if (!item) {
1581
+ return state;
1582
+ }
1583
+ const button = item.buttons.find(button => button.label === name);
1584
+ if (!button) {
1585
+ return state;
1586
+ }
1587
+ const file = item.file;
1588
+ await executeCommand(button.command, file);
1589
+ const newState = await refresh(state);
1590
+ return newState;
1591
+ };
1592
+
1534
1593
  const updateVisibleItems = async (state, isExpanded) => {
1535
1594
  const {
1536
1595
  allGroups,
@@ -1618,8 +1677,11 @@ const selectIndex = async (state, index) => {
1618
1677
  }
1619
1678
  };
1620
1679
 
1621
- const handleClickAt = async (state, eventX, eventY) => {
1680
+ const handleClickAt = async (state, eventX, eventY, name) => {
1622
1681
  const index = getIndex(state, eventX, eventY);
1682
+ if (name) {
1683
+ return handleClickSourceControlButtons(state, index, name);
1684
+ }
1623
1685
  return selectIndex(state, index);
1624
1686
  };
1625
1687
 
@@ -1743,6 +1805,7 @@ const initialize = async () => {
1743
1805
  };
1744
1806
 
1745
1807
  const Actions = 'Actions';
1808
+ const SourceControlButtons = 'SourceControlButtons';
1746
1809
  const Grow = 'Grow';
1747
1810
  const Chevron = 'Chevron';
1748
1811
  const ChevronRight = 'ChevronRight';
@@ -1874,7 +1937,8 @@ const getButtonVirtualDom = button => {
1874
1937
  className: SourceControlButton,
1875
1938
  title: label,
1876
1939
  ariaLabel: label,
1877
- childCount: 1
1940
+ childCount: 1,
1941
+ name: label
1878
1942
  }, getIconVirtualDom(icon, Span)];
1879
1943
  };
1880
1944
 
@@ -1884,7 +1948,7 @@ const getButtonsVirtualDom = buttons => {
1884
1948
  }
1885
1949
  return [{
1886
1950
  type: Div,
1887
- className: 'SourceControlButtons',
1951
+ className: SourceControlButtons,
1888
1952
  childCount: buttons.length
1889
1953
  }, ...buttons.flatMap(getButtonVirtualDom)];
1890
1954
  };
@@ -2164,7 +2228,7 @@ const renderEventListeners = () => {
2164
2228
  params: ['handleFocus']
2165
2229
  }, {
2166
2230
  name: HandleClickAt,
2167
- params: ['handleClickAt', 'event.clientX', 'event.clientY']
2231
+ params: ['handleClickAt', 'event.clientX', 'event.clientY', 'event.target.name']
2168
2232
  }, {
2169
2233
  name: HandleMouseOverAt,
2170
2234
  params: ['handleMouseOverAt', 'event.clientX', 'event.clientY']
@@ -2237,6 +2301,7 @@ const commandMap = {
2237
2301
  'SourceControl.handleContextMenu': wrapCommand(handleContextMenu),
2238
2302
  'SourceControl.handleFocus': wrapCommand(handleFocus),
2239
2303
  'SourceControl.handleMouseOut': wrapCommand(handleMouseOut),
2304
+ 'SourceControl.refresh': wrapCommand(refresh),
2240
2305
  'SourceControl.handleMouseOutAt': wrapCommand(handleMouseOutAt),
2241
2306
  'SourceControl.handleMouseOver': wrapCommand(handleMouseOver),
2242
2307
  'SourceControl.handleMouseOverAt': wrapCommand(handleMouseOverAt),
@@ -2249,7 +2314,8 @@ const commandMap = {
2249
2314
  'SourceControl.saveState': saveState,
2250
2315
  'SourceControl.selectIndex': wrapCommand(selectIndex),
2251
2316
  'SourceControl.terminate': terminate,
2252
- 'SourceControl.updateIcons': wrapCommand(updateIcons)
2317
+ 'SourceControl.updateIcons': wrapCommand(updateIcons),
2318
+ 'SourceControl.handleClickSourceControlButtons': wrapCommand(handleClickSourceControlButtons)
2253
2319
  };
2254
2320
 
2255
2321
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/source-control-worker",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Source Control Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"