@lvce-editor/source-control-worker 1.10.0 → 1.12.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.
@@ -857,7 +857,7 @@ const send = (transport, method, ...params) => {
857
857
  const invoke$3 = (ipc, method, ...params) => {
858
858
  return invokeHelper(ipc, method, params, false);
859
859
  };
860
- const invokeAndTransfer$2 = (ipc, method, ...params) => {
860
+ const invokeAndTransfer$1 = (ipc, method, ...params) => {
861
861
  return invokeHelper(ipc, method, params, true);
862
862
  };
863
863
 
@@ -890,7 +890,7 @@ const createRpc = ipc => {
890
890
  return invoke$3(ipc, method, ...params);
891
891
  },
892
892
  invokeAndTransfer(method, ...params) {
893
- return invokeAndTransfer$2(ipc, method, ...params);
893
+ return invokeAndTransfer$1(ipc, method, ...params);
894
894
  },
895
895
  async dispose() {
896
896
  await ipc?.dispose();
@@ -1044,7 +1044,7 @@ const create2 = (id, uri, x, y, width, height, workspacePath) => {
1044
1044
  id,
1045
1045
  index: [],
1046
1046
  inputValue: '',
1047
- isExpanded: true,
1047
+ expandedGroups: Object.create(null),
1048
1048
  itemHeight: 20,
1049
1049
  items: [],
1050
1050
  maxLineY: 0,
@@ -1104,7 +1104,7 @@ const getCommandIds = () => {
1104
1104
  };
1105
1105
 
1106
1106
  const rpcs = Object.create(null);
1107
- const set$2 = (id, rpc) => {
1107
+ const set$3 = (id, rpc) => {
1108
1108
  rpcs[id] = rpc;
1109
1109
  };
1110
1110
  const get$1 = id => {
@@ -1112,37 +1112,37 @@ const get$1 = id => {
1112
1112
  };
1113
1113
  const RendererWorker$1 = 1;
1114
1114
  const ExtensionHostWorker = 44;
1115
- const invoke$1$1 = (method, ...params) => {
1115
+ const invoke$2 = (method, ...params) => {
1116
1116
  const rpc = get$1(RendererWorker$1);
1117
1117
  // @ts-ignore
1118
1118
  return rpc.invoke(method, ...params);
1119
1119
  };
1120
- const invokeAndTransfer$1 = (method, ...params) => {
1120
+ const invokeAndTransfer$2 = (method, ...params) => {
1121
1121
  const rpc = get$1(RendererWorker$1);
1122
1122
  // @ts-ignore
1123
1123
  return rpc.invokeAndTransfer(method, ...params);
1124
1124
  };
1125
- const set$1$1 = rpc => {
1126
- set$2(RendererWorker$1, rpc);
1125
+ const set$2 = rpc => {
1126
+ set$3(RendererWorker$1, rpc);
1127
1127
  };
1128
1128
  const RendererWorker = {
1129
1129
  __proto__: null,
1130
- invoke: invoke$1$1,
1131
- invokeAndTransfer: invokeAndTransfer$1,
1132
- set: set$1$1
1130
+ invoke: invoke$2,
1131
+ invokeAndTransfer: invokeAndTransfer$2,
1132
+ set: set$2
1133
1133
  };
1134
- const invoke$2 = (method, ...params) => {
1134
+ const invoke$1$1 = (method, ...params) => {
1135
1135
  const rpc = get$1(ExtensionHostWorker);
1136
1136
  // @ts-ignore
1137
1137
  return rpc.invoke(method, ...params);
1138
1138
  };
1139
- const set$3 = rpc => {
1140
- set$2(ExtensionHostWorker, rpc);
1139
+ const set$1$1 = rpc => {
1140
+ set$3(ExtensionHostWorker, rpc);
1141
1141
  };
1142
1142
  const ExtensionHost = {
1143
1143
  __proto__: null,
1144
- invoke: invoke$2,
1145
- set: set$3
1144
+ invoke: invoke$1$1,
1145
+ set: set$1$1
1146
1146
  };
1147
1147
 
1148
1148
  const {
@@ -1199,7 +1199,7 @@ const pathBaseName = path => {
1199
1199
  return path.slice(path.lastIndexOf('/') + 1);
1200
1200
  };
1201
1201
 
1202
- const getDisplayItemsGroup = (group, isExpanded) => {
1202
+ const getDisplayItemsGroup = (group, expandedGroups) => {
1203
1203
  const displayItems = [];
1204
1204
  const {
1205
1205
  id,
@@ -1210,6 +1210,7 @@ const getDisplayItemsGroup = (group, isExpanded) => {
1210
1210
  throw new Error('Source control group is missing an items property');
1211
1211
  }
1212
1212
  const length = items.length;
1213
+ const isExpanded = expandedGroups[id] || false;
1213
1214
  const type = isExpanded ? DirectoryExpanded : Directory;
1214
1215
  const icon = isExpanded ? 'ChevronDown' : 'ChevronRight';
1215
1216
  if (length > 0) {
@@ -1260,10 +1261,10 @@ const getDisplayItemsGroup = (group, isExpanded) => {
1260
1261
  return displayItems;
1261
1262
  };
1262
1263
 
1263
- const getDisplayItems = (allGroups, isExpanded) => {
1264
+ const getDisplayItems = (allGroups, expandedGroups) => {
1264
1265
  const displayItems = [];
1265
1266
  for (const group of allGroups) {
1266
- const groupDisplayItems = getDisplayItemsGroup(group, isExpanded);
1267
+ const groupDisplayItems = getDisplayItemsGroup(group, expandedGroups);
1267
1268
  displayItems.push(...groupDisplayItems);
1268
1269
  }
1269
1270
  return displayItems;
@@ -1452,6 +1453,16 @@ const requestSourceActions = async () => {
1452
1453
  return newCache;
1453
1454
  };
1454
1455
 
1456
+ /* eslint-disable unicorn/no-array-reduce */
1457
+ const restoreExpandedGroups = groups => {
1458
+ return groups.map(group => group.id).reduce((total, current) => {
1459
+ return {
1460
+ ...total,
1461
+ [current]: true
1462
+ };
1463
+ }, Object.create(null));
1464
+ };
1465
+
1455
1466
  const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
1456
1467
  if (size >= contentSize) {
1457
1468
  return 0;
@@ -1474,8 +1485,8 @@ const loadContent = async state => {
1474
1485
  allGroups,
1475
1486
  gitRoot
1476
1487
  } = await getGroups(enabledProviderIds);
1477
- const isExpanded = true;
1478
- const displayItems = getDisplayItems(allGroups, isExpanded);
1488
+ const expandedGroups = restoreExpandedGroups(allGroups);
1489
+ const displayItems = getDisplayItems(allGroups, expandedGroups);
1479
1490
  const actionsCache = await requestSourceActions();
1480
1491
  const splitButtonEnabled = get();
1481
1492
  const total = displayItems.length;
@@ -1495,7 +1506,6 @@ const loadContent = async state => {
1495
1506
  items: displayItems,
1496
1507
  visibleItems,
1497
1508
  enabledProviderIds,
1498
- isExpanded,
1499
1509
  root,
1500
1510
  splitButtonEnabled,
1501
1511
  maxLineY,
@@ -1539,14 +1549,14 @@ const refresh = async state => {
1539
1549
  fileIconCache,
1540
1550
  enabledProviderIds,
1541
1551
  splitButtonEnabled,
1542
- actionsCache
1552
+ actionsCache,
1553
+ expandedGroups
1543
1554
  } = state;
1544
1555
  const {
1545
1556
  allGroups,
1546
1557
  gitRoot
1547
1558
  } = await getGroups(enabledProviderIds);
1548
- const isExpanded = true;
1549
- const displayItems = getDisplayItems(allGroups, isExpanded);
1559
+ const displayItems = getDisplayItems(allGroups, expandedGroups);
1550
1560
  const total = displayItems.length;
1551
1561
  const contentHeight = total * itemHeight;
1552
1562
  const listHeight = getListHeight(total, itemHeight, height);
@@ -1563,7 +1573,6 @@ const refresh = async state => {
1563
1573
  items: displayItems,
1564
1574
  visibleItems,
1565
1575
  enabledProviderIds,
1566
- isExpanded,
1567
1576
  splitButtonEnabled,
1568
1577
  maxLineY,
1569
1578
  scrollBarHeight,
@@ -1590,46 +1599,51 @@ const handleClickSourceControlButtons = async (state, index, name) => {
1590
1599
  return newState;
1591
1600
  };
1592
1601
 
1593
- const updateVisibleItems = async (state, isExpanded) => {
1602
+ const updateVisibleItems = async (state, expandedGroups) => {
1594
1603
  const {
1595
- allGroups,
1596
1604
  itemHeight,
1597
1605
  height,
1598
- minimumSliderSize,
1606
+ actionsCache,
1599
1607
  fileIconCache,
1600
- actionsCache
1608
+ allGroups
1601
1609
  } = state;
1602
- const displayItems = getDisplayItems(allGroups, isExpanded);
1603
- const newMaxLineY = displayItems.length;
1610
+ const displayItems = getDisplayItems(allGroups, expandedGroups);
1604
1611
  const total = displayItems.length;
1605
- const contentHeight = total * itemHeight;
1606
1612
  const listHeight = getListHeight(total, itemHeight, height);
1607
- const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
1608
1613
  const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
1609
1614
  const minLineY = 0;
1610
1615
  const maxLineY = Math.min(numberOfVisible, total);
1611
- const slicedItems = displayItems.slice(minLineY, maxLineY);
1612
- const newFileIconCache = await getFileIcons(slicedItems, fileIconCache);
1613
- const visibleItems = getVisibleSourceControlItems(displayItems, minLineY, maxLineY, actionsCache, newFileIconCache);
1616
+ const visibleItems = getVisibleSourceControlItems(displayItems, minLineY, maxLineY, actionsCache, fileIconCache);
1614
1617
  return {
1615
1618
  ...state,
1616
1619
  items: displayItems,
1617
- isExpanded,
1618
- maxLineY: newMaxLineY,
1619
- fileIconCache: newFileIconCache,
1620
1620
  visibleItems,
1621
- scrollBarHeight
1621
+ expandedGroups,
1622
+ minLineY,
1623
+ maxLineY
1622
1624
  };
1623
1625
  };
1624
1626
 
1625
1627
  const handleClickDirectory = async (state, item) => {
1626
- const isExpanded = true;
1627
- return updateVisibleItems(state, isExpanded);
1628
+ const {
1629
+ expandedGroups
1630
+ } = state;
1631
+ const newExpandedGroups = {
1632
+ ...expandedGroups,
1633
+ [item.groupId]: true
1634
+ };
1635
+ return updateVisibleItems(state, newExpandedGroups);
1628
1636
  };
1629
1637
 
1630
1638
  const handleClickDirectoryExpanded = async (state, item) => {
1631
- const isExpanded = false;
1632
- return updateVisibleItems(state, isExpanded);
1639
+ const {
1640
+ expandedGroups
1641
+ } = state;
1642
+ const newExpandedGroups = {
1643
+ ...expandedGroups,
1644
+ [item.groupId]: false
1645
+ };
1646
+ return updateVisibleItems(state, newExpandedGroups);
1633
1647
  };
1634
1648
 
1635
1649
  const readFile = async (uri, encoding = 'utf8') => {
@@ -1666,9 +1680,9 @@ const selectIndex = async (state, index) => {
1666
1680
  const item = items[index];
1667
1681
  switch (item.type) {
1668
1682
  case Directory:
1669
- return handleClickDirectory(state);
1683
+ return handleClickDirectory(state, item);
1670
1684
  case DirectoryExpanded:
1671
- return handleClickDirectoryExpanded(state);
1685
+ return handleClickDirectoryExpanded(state, item);
1672
1686
  case File:
1673
1687
  return handleClickFile(state, item);
1674
1688
  default:
@@ -2261,14 +2275,14 @@ const saveState = uid => {
2261
2275
  const {
2262
2276
  root,
2263
2277
  maxLineY,
2264
- isExpanded
2278
+ expandedGroups
2265
2279
  } = newState;
2266
2280
  return {
2267
2281
  root,
2268
2282
  minLineY: 0,
2269
2283
  maxLineY,
2270
2284
  deltaY: 0,
2271
- isExpanded
2285
+ expandedGroups
2272
2286
  };
2273
2287
  };
2274
2288
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/source-control-worker",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "Source Control Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"