@lvce-editor/source-control-worker 1.11.0 → 1.13.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.
@@ -696,14 +696,14 @@ const unwrapJsonRpcResult = responseMessage => {
696
696
  }
697
697
  throw new JsonRpcError('unexpected response message');
698
698
  };
699
- const warn = (...args) => {
699
+ const warn$1 = (...args) => {
700
700
  console.warn(...args);
701
701
  };
702
702
  const resolve = (id, response) => {
703
703
  const fn = get$3(id);
704
704
  if (!fn) {
705
705
  console.log(response);
706
- warn(`callback ${id} may already be disposed`);
706
+ warn$1(`callback ${id} may already be disposed`);
707
707
  return;
708
708
  }
709
709
  fn(response);
@@ -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,
@@ -1531,6 +1541,10 @@ const getIndex = (state, eventX, eventY) => {
1531
1541
  return index;
1532
1542
  };
1533
1543
 
1544
+ const warn = (...args) => {
1545
+ console.warn(...args);
1546
+ };
1547
+
1534
1548
  const refresh = async state => {
1535
1549
  const {
1536
1550
  itemHeight,
@@ -1545,8 +1559,8 @@ const refresh = async state => {
1545
1559
  allGroups,
1546
1560
  gitRoot
1547
1561
  } = await getGroups(enabledProviderIds);
1548
- const isExpanded = true;
1549
- const displayItems = getDisplayItems(allGroups, isExpanded);
1562
+ const expandedGroups = restoreExpandedGroups(allGroups);
1563
+ const displayItems = getDisplayItems(allGroups, expandedGroups);
1550
1564
  const total = displayItems.length;
1551
1565
  const contentHeight = total * itemHeight;
1552
1566
  const listHeight = getListHeight(total, itemHeight, height);
@@ -1563,7 +1577,6 @@ const refresh = async state => {
1563
1577
  items: displayItems,
1564
1578
  visibleItems,
1565
1579
  enabledProviderIds,
1566
- isExpanded,
1567
1580
  splitButtonEnabled,
1568
1581
  maxLineY,
1569
1582
  scrollBarHeight,
@@ -1580,8 +1593,12 @@ const handleClickSourceControlButtons = async (state, index, name) => {
1580
1593
  if (!item) {
1581
1594
  return state;
1582
1595
  }
1583
- const button = item.buttons.find(button => button.label === name);
1596
+ const {
1597
+ buttons
1598
+ } = item;
1599
+ const button = buttons.find(button => button.label === name);
1584
1600
  if (!button) {
1601
+ warn(`[source-control-worker] Button not found ${name}`);
1585
1602
  return state;
1586
1603
  }
1587
1604
  const file = item.file;
@@ -1590,46 +1607,51 @@ const handleClickSourceControlButtons = async (state, index, name) => {
1590
1607
  return newState;
1591
1608
  };
1592
1609
 
1593
- const updateVisibleItems = async (state, isExpanded) => {
1610
+ const updateVisibleItems = async (state, expandedGroups) => {
1594
1611
  const {
1595
- allGroups,
1596
1612
  itemHeight,
1597
1613
  height,
1598
- minimumSliderSize,
1614
+ actionsCache,
1599
1615
  fileIconCache,
1600
- actionsCache
1616
+ allGroups
1601
1617
  } = state;
1602
- const displayItems = getDisplayItems(allGroups, isExpanded);
1603
- const newMaxLineY = displayItems.length;
1618
+ const displayItems = getDisplayItems(allGroups, expandedGroups);
1604
1619
  const total = displayItems.length;
1605
- const contentHeight = total * itemHeight;
1606
1620
  const listHeight = getListHeight(total, itemHeight, height);
1607
- const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
1608
1621
  const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
1609
1622
  const minLineY = 0;
1610
1623
  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);
1624
+ const visibleItems = getVisibleSourceControlItems(displayItems, minLineY, maxLineY, actionsCache, fileIconCache);
1614
1625
  return {
1615
1626
  ...state,
1616
1627
  items: displayItems,
1617
- isExpanded,
1618
- maxLineY: newMaxLineY,
1619
- fileIconCache: newFileIconCache,
1620
1628
  visibleItems,
1621
- scrollBarHeight
1629
+ expandedGroups,
1630
+ minLineY,
1631
+ maxLineY
1622
1632
  };
1623
1633
  };
1624
1634
 
1625
1635
  const handleClickDirectory = async (state, item) => {
1626
- const isExpanded = true;
1627
- return updateVisibleItems(state, isExpanded);
1636
+ const {
1637
+ expandedGroups
1638
+ } = state;
1639
+ const newExpandedGroups = {
1640
+ ...expandedGroups,
1641
+ [item.groupId]: true
1642
+ };
1643
+ return updateVisibleItems(state, newExpandedGroups);
1628
1644
  };
1629
1645
 
1630
1646
  const handleClickDirectoryExpanded = async (state, item) => {
1631
- const isExpanded = false;
1632
- return updateVisibleItems(state, isExpanded);
1647
+ const {
1648
+ expandedGroups
1649
+ } = state;
1650
+ const newExpandedGroups = {
1651
+ ...expandedGroups,
1652
+ [item.groupId]: false
1653
+ };
1654
+ return updateVisibleItems(state, newExpandedGroups);
1633
1655
  };
1634
1656
 
1635
1657
  const readFile = async (uri, encoding = 'utf8') => {
@@ -1666,9 +1688,9 @@ const selectIndex = async (state, index) => {
1666
1688
  const item = items[index];
1667
1689
  switch (item.type) {
1668
1690
  case Directory:
1669
- return handleClickDirectory(state);
1691
+ return handleClickDirectory(state, item);
1670
1692
  case DirectoryExpanded:
1671
- return handleClickDirectoryExpanded(state);
1693
+ return handleClickDirectoryExpanded(state, item);
1672
1694
  case File:
1673
1695
  return handleClickFile(state, item);
1674
1696
  default:
@@ -2261,14 +2283,14 @@ const saveState = uid => {
2261
2283
  const {
2262
2284
  root,
2263
2285
  maxLineY,
2264
- isExpanded
2286
+ expandedGroups
2265
2287
  } = newState;
2266
2288
  return {
2267
2289
  root,
2268
2290
  minLineY: 0,
2269
2291
  maxLineY,
2270
2292
  deltaY: 0,
2271
- isExpanded
2293
+ expandedGroups
2272
2294
  };
2273
2295
  };
2274
2296
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/source-control-worker",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "Source Control Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"