@lvce-editor/source-control-worker 1.6.0 → 1.8.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.
@@ -524,7 +524,7 @@ const create$4 = (method, params) => {
524
524
  };
525
525
  };
526
526
  const callbacks = Object.create(null);
527
- const set$2 = (id, fn) => {
527
+ const set$5 = (id, fn) => {
528
528
  callbacks[id] = fn;
529
529
  };
530
530
  const get$3 = id => {
@@ -543,13 +543,13 @@ const registerPromise = () => {
543
543
  resolve,
544
544
  promise
545
545
  } = Promise.withResolvers();
546
- set$2(id, resolve);
546
+ set$5(id, resolve);
547
547
  return {
548
548
  id,
549
549
  promise
550
550
  };
551
551
  };
552
- const create$2 = (method, params) => {
552
+ const create$2$1 = (method, params) => {
553
553
  const {
554
554
  id,
555
555
  promise
@@ -841,7 +841,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
841
841
  const {
842
842
  message,
843
843
  promise
844
- } = create$2(method, params);
844
+ } = create$2$1(method, params);
845
845
  if (useSendAndTransfer && ipc.sendAndTransfer) {
846
846
  ipc.sendAndTransfer(message);
847
847
  } else {
@@ -854,10 +854,10 @@ const send = (transport, method, ...params) => {
854
854
  const message = create$4(method, params);
855
855
  transport.send(message);
856
856
  };
857
- const invoke$2 = (ipc, method, ...params) => {
857
+ const invoke$3 = (ipc, method, ...params) => {
858
858
  return invokeHelper(ipc, method, params, false);
859
859
  };
860
- const invokeAndTransfer$1 = (ipc, method, ...params) => {
860
+ const invokeAndTransfer$2 = (ipc, method, ...params) => {
861
861
  return invokeHelper(ipc, method, params, true);
862
862
  };
863
863
 
@@ -887,10 +887,10 @@ const createRpc = ipc => {
887
887
  send(ipc, method, ...params);
888
888
  },
889
889
  invoke(method, ...params) {
890
- return invoke$2(ipc, method, ...params);
890
+ return invoke$3(ipc, method, ...params);
891
891
  },
892
892
  invokeAndTransfer(method, ...params) {
893
- return invokeAndTransfer$1(ipc, method, ...params);
893
+ return invokeAndTransfer$2(ipc, method, ...params);
894
894
  },
895
895
  async dispose() {
896
896
  await ipc?.dispose();
@@ -928,25 +928,25 @@ const listen$1 = async (module, options) => {
928
928
  const ipc = module.wrap(rawIpc);
929
929
  return ipc;
930
930
  };
931
- const create$8 = async ({
931
+ const create$2 = async ({
932
932
  commandMap,
933
- messagePort,
934
- isMessagePortOpen
933
+ messagePort
935
934
  }) => {
936
935
  // TODO create a commandMap per rpc instance
937
936
  register(commandMap);
938
937
  const rawIpc = await IpcParentWithMessagePort$1.create({
939
938
  messagePort,
940
- isMessagePortOpen
939
+ isMessagePortOpen: true
941
940
  });
942
941
  const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
943
942
  handleIpc(ipc);
944
943
  const rpc = createRpc(ipc);
944
+ messagePort.start();
945
945
  return rpc;
946
946
  };
947
- const MessagePortRpcParent = {
947
+ const PlainMessagePortRpcParent = {
948
948
  __proto__: null,
949
- create: create$8
949
+ create: create$2
950
950
  };
951
951
  const create$1 = async ({
952
952
  commandMap
@@ -1024,7 +1024,7 @@ const create = () => {
1024
1024
 
1025
1025
  const {
1026
1026
  get: get$2,
1027
- set: set$1,
1027
+ set: set$4,
1028
1028
  wrapCommand
1029
1029
  } = create();
1030
1030
 
@@ -1064,7 +1064,7 @@ const create2 = (id, uri, x, y, width, height, workspacePath) => {
1064
1064
  x,
1065
1065
  y
1066
1066
  };
1067
- set$1(id, state, state);
1067
+ set$4(id, state, state);
1068
1068
  };
1069
1069
 
1070
1070
  const RenderItems = 4;
@@ -1103,37 +1103,62 @@ const getCommandIds = () => {
1103
1103
  return commandIds;
1104
1104
  };
1105
1105
 
1106
- const RendererWorker = 1;
1107
- const ExtensionHostWorker = 44;
1108
- const DebugWorker = 55;
1109
-
1110
1106
  const rpcs = Object.create(null);
1111
- const set = (id, rpc) => {
1107
+ const set$2 = (id, rpc) => {
1112
1108
  rpcs[id] = rpc;
1113
1109
  };
1114
1110
  const get$1 = id => {
1115
1111
  return rpcs[id];
1116
1112
  };
1117
-
1118
- const invoke$1 = (method, ...params) => {
1119
- const rpc = get$1(RendererWorker);
1113
+ const RendererWorker$1 = 1;
1114
+ const ExtensionHostWorker = 44;
1115
+ const invoke$1$1 = (method, ...params) => {
1116
+ const rpc = get$1(RendererWorker$1);
1120
1117
  // @ts-ignore
1121
1118
  return rpc.invoke(method, ...params);
1122
1119
  };
1123
- const invokeAndTransfer = (method, ...params) => {
1124
- const rpc = get$1(RendererWorker);
1120
+ const invokeAndTransfer$1 = (method, ...params) => {
1121
+ const rpc = get$1(RendererWorker$1);
1125
1122
  // @ts-ignore
1126
1123
  return rpc.invokeAndTransfer(method, ...params);
1127
1124
  };
1125
+ const set$1$1 = rpc => {
1126
+ set$2(RendererWorker$1, rpc);
1127
+ };
1128
+ const RendererWorker = {
1129
+ __proto__: null,
1130
+ invoke: invoke$1$1,
1131
+ invokeAndTransfer: invokeAndTransfer$1,
1132
+ set: set$1$1
1133
+ };
1134
+ const invoke$2 = (method, ...params) => {
1135
+ const rpc = get$1(ExtensionHostWorker);
1136
+ // @ts-ignore
1137
+ return rpc.invoke(method, ...params);
1138
+ };
1139
+ const set$3 = rpc => {
1140
+ set$2(ExtensionHostWorker, rpc);
1141
+ };
1142
+ const ExtensionHost = {
1143
+ __proto__: null,
1144
+ invoke: invoke$2,
1145
+ set: set$3
1146
+ };
1147
+
1148
+ const {
1149
+ invoke: invoke$1,
1150
+ invokeAndTransfer,
1151
+ set: set$1
1152
+ } = RendererWorker;
1128
1153
 
1129
1154
  const activateByEvent = event => {
1130
1155
  return invoke$1('ExtensionHostManagement.activateByEvent', event);
1131
1156
  };
1132
1157
 
1133
- const invoke = async (method, ...params) => {
1134
- const rpc = get$1(ExtensionHostWorker);
1135
- return rpc.invoke(method, ...params);
1136
- };
1158
+ const {
1159
+ invoke,
1160
+ set
1161
+ } = ExtensionHost;
1137
1162
 
1138
1163
  const executeProvider = async ({
1139
1164
  event,
@@ -1141,6 +1166,7 @@ const executeProvider = async ({
1141
1166
  params
1142
1167
  }) => {
1143
1168
  await activateByEvent(event);
1169
+ // @ts-ignore
1144
1170
  const result = await invoke(method, ...params);
1145
1171
  return result;
1146
1172
  };
@@ -1162,7 +1188,7 @@ const Directory = 3;
1162
1188
  const DirectoryExpanded = 4;
1163
1189
  const File = 7;
1164
1190
 
1165
- const getFileIcon$1 = ({
1191
+ const getFileIcon = ({
1166
1192
  name
1167
1193
  }) => {
1168
1194
  return '';
@@ -1219,7 +1245,7 @@ const getDisplayItemsGroup = (group, isExpanded) => {
1219
1245
  detail: folderName,
1220
1246
  posInSet: i + 1,
1221
1247
  setSize: length,
1222
- icon: getFileIcon$1({
1248
+ icon: getFileIcon({
1223
1249
  name: file
1224
1250
  }),
1225
1251
  decorationIcon: icon,
@@ -1243,35 +1269,31 @@ const getDisplayItems = (allGroups, isExpanded) => {
1243
1269
  return displayItems;
1244
1270
  };
1245
1271
 
1272
+ const getIconType = direntType => {
1273
+ switch (direntType) {
1274
+ case Directory:
1275
+ case DirectoryExpanded:
1276
+ return 2;
1277
+ default:
1278
+ return 1;
1279
+ }
1280
+ };
1246
1281
  const getMissingIconRequests = (dirents, fileIconCache) => {
1247
1282
  const missingRequests = [];
1248
1283
  for (const dirent of dirents) {
1249
1284
  if (!(dirent.file in fileIconCache)) {
1250
1285
  missingRequests.push({
1251
- type: dirent.type,
1252
- name: dirent.label,
1253
- path: dirent.file
1286
+ type: getIconType(dirent.type),
1287
+ name: dirent.label
1254
1288
  });
1255
1289
  }
1256
1290
  }
1257
1291
  return missingRequests;
1258
1292
  };
1259
1293
 
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
1294
  const requestFileIcons = async requests => {
1273
- const promises = requests.map(request => request.type === File ? getFileIcon(request.name) : getFolderIcon(request.name));
1274
- return Promise.all(promises);
1295
+ const results = await invoke$1('IconTheme.getIcons', requests);
1296
+ return results;
1275
1297
  };
1276
1298
 
1277
1299
  const updateIconCache = (iconCache, missingRequests, newIcons) => {
@@ -1284,7 +1306,7 @@ const updateIconCache = (iconCache, missingRequests, newIcons) => {
1284
1306
  for (let i = 0; i < missingRequests.length; i++) {
1285
1307
  const request = missingRequests[i];
1286
1308
  const icon = newIcons[i];
1287
- newFileIconCache[request.path] = icon;
1309
+ newFileIconCache[request.name] = icon;
1288
1310
  }
1289
1311
  return newFileIconCache;
1290
1312
  };
@@ -1399,7 +1421,7 @@ const getVisibleSourceControlItems = (items, minLineY, maxLineY, actionsCache, f
1399
1421
  const item = items[i];
1400
1422
  const contextId = getContextId(item.groupId, item.type);
1401
1423
  const buttons = actionsCache[contextId] || emptySourceControlButtons;
1402
- const fileIcon = fileIconCache[item.file] || '';
1424
+ const fileIcon = fileIconCache[item.label] || '';
1403
1425
  visible.push({
1404
1426
  ...item,
1405
1427
  buttons,
@@ -1454,7 +1476,7 @@ const loadContent = async state => {
1454
1476
  } = await getGroups(enabledProviderIds);
1455
1477
  const isExpanded = true;
1456
1478
  const displayItems = getDisplayItems(allGroups, isExpanded);
1457
- const cache = await requestSourceActions();
1479
+ const actionsCache = await requestSourceActions();
1458
1480
  const splitButtonEnabled = get();
1459
1481
  const total = displayItems.length;
1460
1482
  const contentHeight = total * itemHeight;
@@ -1463,9 +1485,8 @@ const loadContent = async state => {
1463
1485
  const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
1464
1486
  const minLineY = 0;
1465
1487
  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);
1488
+ const newFileIconCache = await getFileIcons(displayItems, fileIconCache);
1489
+ const visibleItems = getVisibleSourceControlItems(displayItems, minLineY, maxLineY, actionsCache, newFileIconCache);
1469
1490
  const finalDeltaY = getFinalDeltaY(listHeight, itemHeight, total);
1470
1491
  return {
1471
1492
  ...state,
@@ -1480,7 +1501,8 @@ const loadContent = async state => {
1480
1501
  maxLineY,
1481
1502
  scrollBarHeight,
1482
1503
  finalDeltaY,
1483
- fileIconCache: newFileIconCache
1504
+ fileIconCache: newFileIconCache,
1505
+ actionsCache
1484
1506
  };
1485
1507
  };
1486
1508
 
@@ -1509,35 +1531,46 @@ const getIndex = (state, eventX, eventY) => {
1509
1531
  return index;
1510
1532
  };
1511
1533
 
1512
- const handleClickDirectory = async (state, item) => {
1534
+ const updateVisibleItems = async (state, isExpanded) => {
1513
1535
  const {
1514
- allGroups
1536
+ allGroups,
1537
+ itemHeight,
1538
+ height,
1539
+ minimumSliderSize,
1540
+ fileIconCache,
1541
+ actionsCache
1515
1542
  } = state;
1516
- const isExpanded = true;
1517
1543
  const displayItems = getDisplayItems(allGroups, isExpanded);
1518
1544
  const newMaxLineY = displayItems.length;
1545
+ const total = displayItems.length;
1546
+ const contentHeight = total * itemHeight;
1547
+ const listHeight = getListHeight(total, itemHeight, height);
1548
+ const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
1549
+ const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
1550
+ const minLineY = 0;
1551
+ const maxLineY = Math.min(numberOfVisible, total);
1552
+ const slicedItems = displayItems.slice(minLineY, maxLineY);
1553
+ const newFileIconCache = await getFileIcons(slicedItems, fileIconCache);
1554
+ const visibleItems = getVisibleSourceControlItems(displayItems, minLineY, maxLineY, actionsCache, newFileIconCache);
1519
1555
  return {
1520
1556
  ...state,
1521
1557
  items: displayItems,
1522
1558
  isExpanded,
1523
- maxLineY: newMaxLineY
1559
+ maxLineY: newMaxLineY,
1560
+ fileIconCache: newFileIconCache,
1561
+ visibleItems,
1562
+ scrollBarHeight
1524
1563
  };
1525
1564
  };
1526
1565
 
1566
+ const handleClickDirectory = async (state, item) => {
1567
+ const isExpanded = true;
1568
+ return updateVisibleItems(state, isExpanded);
1569
+ };
1570
+
1527
1571
  const handleClickDirectoryExpanded = async (state, item) => {
1528
- const {
1529
- allGroups,
1530
- maxLineY
1531
- } = state;
1532
1572
  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
- };
1573
+ return updateVisibleItems(state, isExpanded);
1541
1574
  };
1542
1575
 
1543
1576
  const readFile = async (uri, encoding = 'utf8') => {
@@ -1640,6 +1673,35 @@ const handleMouseOverAt = async (state, eventX, eventY) => {
1640
1673
  return handleMouseOver(state, index);
1641
1674
  };
1642
1675
 
1676
+ const setDeltaY = async (state, newDeltaY) => {
1677
+ const {
1678
+ itemHeight,
1679
+ items,
1680
+ height,
1681
+ headerHeight,
1682
+ actionsCache,
1683
+ fileIconCache
1684
+ } = state;
1685
+ const normalizedDeltaY = Math.max(newDeltaY, 0);
1686
+ const newMinLineY = Math.floor(normalizedDeltaY / itemHeight);
1687
+ const total = items.length;
1688
+ const listHeight = height - headerHeight;
1689
+ const visibleCount = getNumberOfVisibleItems(listHeight, itemHeight);
1690
+ const maxLineY = Math.min(newMinLineY + visibleCount, total);
1691
+ const visible = getVisibleSourceControlItems(items, newMinLineY, maxLineY, actionsCache, fileIconCache);
1692
+ return {
1693
+ ...state,
1694
+ deltaY: newDeltaY,
1695
+ visibleItems: visible,
1696
+ minLineY: newMinLineY,
1697
+ maxLineY
1698
+ };
1699
+ };
1700
+
1701
+ const handleWheel = async (state, deltaMode, deltaY) => {
1702
+ return setDeltaY(state, state.deltaY + deltaY);
1703
+ };
1704
+
1643
1705
  const getPortTuple = () => {
1644
1706
  const {
1645
1707
  port1,
@@ -1651,8 +1713,10 @@ const getPortTuple = () => {
1651
1713
  };
1652
1714
  };
1653
1715
 
1716
+ const DebugWorker = 55;
1717
+
1654
1718
  const sendMessagePortToExtensionHostWorker = async port => {
1655
- const command = 'HandleMessagePort.handleMessagePort';
1719
+ const command = 'HandleMessagePort.handleMessagePort2';
1656
1720
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, DebugWorker);
1657
1721
  };
1658
1722
 
@@ -1663,13 +1727,10 @@ const createExtensionHostRpc = async () => {
1663
1727
  port2
1664
1728
  } = getPortTuple();
1665
1729
  await sendMessagePortToExtensionHostWorker(port2);
1666
- port1.start();
1667
- const rpc = await MessagePortRpcParent.create({
1730
+ const rpc = await PlainMessagePortRpcParent.create({
1668
1731
  commandMap: {},
1669
- messagePort: port1,
1670
- isMessagePortOpen: false
1732
+ messagePort: port1
1671
1733
  });
1672
- // TODO createMessageportRpcParent should call port start
1673
1734
  return rpc;
1674
1735
  } catch (error) {
1675
1736
  throw new VError(error, `Failed to create extension host rpc`);
@@ -1678,7 +1739,7 @@ const createExtensionHostRpc = async () => {
1678
1739
 
1679
1740
  const initialize = async () => {
1680
1741
  const extensionHostRpc = await createExtensionHostRpc();
1681
- set(ExtensionHostWorker, extensionHostRpc);
1742
+ set(extensionHostRpc);
1682
1743
  };
1683
1744
 
1684
1745
  const Actions = 'Actions';
@@ -2047,7 +2108,7 @@ const render2 = (uid, diffResult) => {
2047
2108
  oldState,
2048
2109
  newState
2049
2110
  } = get$2(uid);
2050
- set$1(uid, newState, newState);
2111
+ set$4(uid, newState, newState);
2051
2112
  const commands = applyRender(oldState, newState, diffResult);
2052
2113
  return commands;
2053
2114
  };
@@ -2179,6 +2240,8 @@ const commandMap = {
2179
2240
  'SourceControl.handleMouseOutAt': wrapCommand(handleMouseOutAt),
2180
2241
  'SourceControl.handleMouseOver': wrapCommand(handleMouseOver),
2181
2242
  'SourceControl.handleMouseOverAt': wrapCommand(handleMouseOverAt),
2243
+ 'SourceControl.setDeltaY': wrapCommand(setDeltaY),
2244
+ 'SourceControl.handleWheel': wrapCommand(handleWheel),
2182
2245
  'SourceControl.loadContent': wrapCommand(loadContent),
2183
2246
  'SourceControl.render2': render2,
2184
2247
  'SourceControl.renderActions2': renderActions,
@@ -2193,7 +2256,7 @@ const listen = async () => {
2193
2256
  const rpc = await WebWorkerRpcClient.create({
2194
2257
  commandMap: commandMap
2195
2258
  });
2196
- set(RendererWorker, rpc);
2259
+ set$1(rpc);
2197
2260
  };
2198
2261
 
2199
2262
  const main = async () => {
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.8.0",
4
4
  "description": "Source Control Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"