@lvce-editor/source-control-worker 1.6.0 → 1.7.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.
@@ -1162,7 +1162,7 @@ const Directory = 3;
1162
1162
  const DirectoryExpanded = 4;
1163
1163
  const File = 7;
1164
1164
 
1165
- const getFileIcon$1 = ({
1165
+ const getFileIcon = ({
1166
1166
  name
1167
1167
  }) => {
1168
1168
  return '';
@@ -1219,7 +1219,7 @@ const getDisplayItemsGroup = (group, isExpanded) => {
1219
1219
  detail: folderName,
1220
1220
  posInSet: i + 1,
1221
1221
  setSize: length,
1222
- icon: getFileIcon$1({
1222
+ icon: getFileIcon({
1223
1223
  name: file
1224
1224
  }),
1225
1225
  decorationIcon: icon,
@@ -1243,35 +1243,31 @@ const getDisplayItems = (allGroups, isExpanded) => {
1243
1243
  return displayItems;
1244
1244
  };
1245
1245
 
1246
+ const getIconType = direntType => {
1247
+ switch (direntType) {
1248
+ case Directory:
1249
+ case DirectoryExpanded:
1250
+ return 2;
1251
+ default:
1252
+ return 1;
1253
+ }
1254
+ };
1246
1255
  const getMissingIconRequests = (dirents, fileIconCache) => {
1247
1256
  const missingRequests = [];
1248
1257
  for (const dirent of dirents) {
1249
1258
  if (!(dirent.file in fileIconCache)) {
1250
1259
  missingRequests.push({
1251
- type: dirent.type,
1252
- name: dirent.label,
1253
- path: dirent.file
1260
+ type: getIconType(dirent.type),
1261
+ name: dirent.label
1254
1262
  });
1255
1263
  }
1256
1264
  }
1257
1265
  return missingRequests;
1258
1266
  };
1259
1267
 
1260
- const getFileIcon = async name => {
1261
- return invoke$1('IconTheme.getFileIcon', {
1262
- name
1263
- });
1264
- };
1265
-
1266
- const getFolderIcon = async name => {
1267
- return invoke$1('IconTheme.getFolderIcon', {
1268
- name
1269
- });
1270
- };
1271
-
1272
1268
  const requestFileIcons = async requests => {
1273
- const promises = requests.map(request => request.type === File ? getFileIcon(request.name) : getFolderIcon(request.name));
1274
- return Promise.all(promises);
1269
+ const results = await invoke$1('IconTheme.getIcons', requests);
1270
+ return results;
1275
1271
  };
1276
1272
 
1277
1273
  const updateIconCache = (iconCache, missingRequests, newIcons) => {
@@ -1284,7 +1280,7 @@ const updateIconCache = (iconCache, missingRequests, newIcons) => {
1284
1280
  for (let i = 0; i < missingRequests.length; i++) {
1285
1281
  const request = missingRequests[i];
1286
1282
  const icon = newIcons[i];
1287
- newFileIconCache[request.path] = icon;
1283
+ newFileIconCache[request.name] = icon;
1288
1284
  }
1289
1285
  return newFileIconCache;
1290
1286
  };
@@ -1399,7 +1395,7 @@ const getVisibleSourceControlItems = (items, minLineY, maxLineY, actionsCache, f
1399
1395
  const item = items[i];
1400
1396
  const contextId = getContextId(item.groupId, item.type);
1401
1397
  const buttons = actionsCache[contextId] || emptySourceControlButtons;
1402
- const fileIcon = fileIconCache[item.file] || '';
1398
+ const fileIcon = fileIconCache[item.label] || '';
1403
1399
  visible.push({
1404
1400
  ...item,
1405
1401
  buttons,
@@ -1454,7 +1450,7 @@ const loadContent = async state => {
1454
1450
  } = await getGroups(enabledProviderIds);
1455
1451
  const isExpanded = true;
1456
1452
  const displayItems = getDisplayItems(allGroups, isExpanded);
1457
- const cache = await requestSourceActions();
1453
+ const actionsCache = await requestSourceActions();
1458
1454
  const splitButtonEnabled = get();
1459
1455
  const total = displayItems.length;
1460
1456
  const contentHeight = total * itemHeight;
@@ -1463,9 +1459,8 @@ const loadContent = async state => {
1463
1459
  const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
1464
1460
  const minLineY = 0;
1465
1461
  const maxLineY = Math.min(numberOfVisible, total);
1466
- const slicedItems = displayItems.slice(minLineY, maxLineY);
1467
- const newFileIconCache = await getFileIcons(slicedItems, fileIconCache);
1468
- const visibleItems = getVisibleSourceControlItems(displayItems, minLineY, maxLineY, cache, newFileIconCache);
1462
+ const newFileIconCache = await getFileIcons(displayItems, fileIconCache);
1463
+ const visibleItems = getVisibleSourceControlItems(displayItems, minLineY, maxLineY, actionsCache, newFileIconCache);
1469
1464
  const finalDeltaY = getFinalDeltaY(listHeight, itemHeight, total);
1470
1465
  return {
1471
1466
  ...state,
@@ -1480,7 +1475,8 @@ const loadContent = async state => {
1480
1475
  maxLineY,
1481
1476
  scrollBarHeight,
1482
1477
  finalDeltaY,
1483
- fileIconCache: newFileIconCache
1478
+ fileIconCache: newFileIconCache,
1479
+ actionsCache
1484
1480
  };
1485
1481
  };
1486
1482
 
@@ -1509,35 +1505,46 @@ const getIndex = (state, eventX, eventY) => {
1509
1505
  return index;
1510
1506
  };
1511
1507
 
1512
- const handleClickDirectory = async (state, item) => {
1508
+ const updateVisibleItems = async (state, isExpanded) => {
1513
1509
  const {
1514
- allGroups
1510
+ allGroups,
1511
+ itemHeight,
1512
+ height,
1513
+ minimumSliderSize,
1514
+ fileIconCache,
1515
+ actionsCache
1515
1516
  } = state;
1516
- const isExpanded = true;
1517
1517
  const displayItems = getDisplayItems(allGroups, isExpanded);
1518
1518
  const newMaxLineY = displayItems.length;
1519
+ const total = displayItems.length;
1520
+ const contentHeight = total * itemHeight;
1521
+ const listHeight = getListHeight(total, itemHeight, height);
1522
+ const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
1523
+ const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
1524
+ const minLineY = 0;
1525
+ const maxLineY = Math.min(numberOfVisible, total);
1526
+ const slicedItems = displayItems.slice(minLineY, maxLineY);
1527
+ const newFileIconCache = await getFileIcons(slicedItems, fileIconCache);
1528
+ const visibleItems = getVisibleSourceControlItems(displayItems, minLineY, maxLineY, actionsCache, newFileIconCache);
1519
1529
  return {
1520
1530
  ...state,
1521
1531
  items: displayItems,
1522
1532
  isExpanded,
1523
- maxLineY: newMaxLineY
1533
+ maxLineY: newMaxLineY,
1534
+ fileIconCache: newFileIconCache,
1535
+ visibleItems,
1536
+ scrollBarHeight
1524
1537
  };
1525
1538
  };
1526
1539
 
1540
+ const handleClickDirectory = async (state, item) => {
1541
+ const isExpanded = true;
1542
+ return updateVisibleItems(state, isExpanded);
1543
+ };
1544
+
1527
1545
  const handleClickDirectoryExpanded = async (state, item) => {
1528
- const {
1529
- allGroups,
1530
- maxLineY
1531
- } = state;
1532
1546
  const isExpanded = false;
1533
- const displayItems = getDisplayItems(allGroups, isExpanded);
1534
- const newMaxLineY = Math.min(displayItems.length, maxLineY);
1535
- return {
1536
- ...state,
1537
- items: displayItems,
1538
- isExpanded,
1539
- maxLineY: newMaxLineY
1540
- };
1547
+ return updateVisibleItems(state, isExpanded);
1541
1548
  };
1542
1549
 
1543
1550
  const readFile = async (uri, encoding = 'utf8') => {
@@ -1640,6 +1647,35 @@ const handleMouseOverAt = async (state, eventX, eventY) => {
1640
1647
  return handleMouseOver(state, index);
1641
1648
  };
1642
1649
 
1650
+ const setDeltaY = async (state, newDeltaY) => {
1651
+ const {
1652
+ itemHeight,
1653
+ items,
1654
+ height,
1655
+ headerHeight,
1656
+ actionsCache,
1657
+ fileIconCache
1658
+ } = state;
1659
+ const normalizedDeltaY = Math.max(newDeltaY, 0);
1660
+ const newMinLineY = Math.floor(normalizedDeltaY / itemHeight);
1661
+ const total = items.length;
1662
+ const listHeight = height - headerHeight;
1663
+ const visibleCount = getNumberOfVisibleItems(listHeight, itemHeight);
1664
+ const maxLineY = Math.min(newMinLineY + visibleCount, total);
1665
+ const visible = getVisibleSourceControlItems(items, newMinLineY, maxLineY, actionsCache, fileIconCache);
1666
+ return {
1667
+ ...state,
1668
+ deltaY: newDeltaY,
1669
+ visibleItems: visible,
1670
+ minLineY: newMinLineY,
1671
+ maxLineY
1672
+ };
1673
+ };
1674
+
1675
+ const handleWheel = async (state, deltaMode, deltaY) => {
1676
+ return setDeltaY(state, state.deltaY + deltaY);
1677
+ };
1678
+
1643
1679
  const getPortTuple = () => {
1644
1680
  const {
1645
1681
  port1,
@@ -2179,6 +2215,8 @@ const commandMap = {
2179
2215
  'SourceControl.handleMouseOutAt': wrapCommand(handleMouseOutAt),
2180
2216
  'SourceControl.handleMouseOver': wrapCommand(handleMouseOver),
2181
2217
  'SourceControl.handleMouseOverAt': wrapCommand(handleMouseOverAt),
2218
+ 'SourceControl.setDeltaY': wrapCommand(setDeltaY),
2219
+ 'SourceControl.handleWheel': wrapCommand(handleWheel),
2182
2220
  'SourceControl.loadContent': wrapCommand(loadContent),
2183
2221
  'SourceControl.render2': render2,
2184
2222
  'SourceControl.renderActions2': renderActions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/source-control-worker",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Source Control Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"