@lvce-editor/source-control-worker 1.7.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.
@@ -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;
@@ -1097,43 +1097,68 @@ 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;
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
  };
@@ -1505,6 +1531,65 @@ const getIndex = (state, eventX, eventY) => {
1505
1531
  return index;
1506
1532
  };
1507
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
+
1508
1593
  const updateVisibleItems = async (state, isExpanded) => {
1509
1594
  const {
1510
1595
  allGroups,
@@ -1592,8 +1677,11 @@ const selectIndex = async (state, index) => {
1592
1677
  }
1593
1678
  };
1594
1679
 
1595
- const handleClickAt = async (state, eventX, eventY) => {
1680
+ const handleClickAt = async (state, eventX, eventY, name) => {
1596
1681
  const index = getIndex(state, eventX, eventY);
1682
+ if (name) {
1683
+ return handleClickSourceControlButtons(state, index, name);
1684
+ }
1597
1685
  return selectIndex(state, index);
1598
1686
  };
1599
1687
 
@@ -1687,8 +1775,10 @@ const getPortTuple = () => {
1687
1775
  };
1688
1776
  };
1689
1777
 
1778
+ const DebugWorker = 55;
1779
+
1690
1780
  const sendMessagePortToExtensionHostWorker = async port => {
1691
- const command = 'HandleMessagePort.handleMessagePort';
1781
+ const command = 'HandleMessagePort.handleMessagePort2';
1692
1782
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, DebugWorker);
1693
1783
  };
1694
1784
 
@@ -1699,13 +1789,10 @@ const createExtensionHostRpc = async () => {
1699
1789
  port2
1700
1790
  } = getPortTuple();
1701
1791
  await sendMessagePortToExtensionHostWorker(port2);
1702
- port1.start();
1703
- const rpc = await MessagePortRpcParent.create({
1792
+ const rpc = await PlainMessagePortRpcParent.create({
1704
1793
  commandMap: {},
1705
- messagePort: port1,
1706
- isMessagePortOpen: false
1794
+ messagePort: port1
1707
1795
  });
1708
- // TODO createMessageportRpcParent should call port start
1709
1796
  return rpc;
1710
1797
  } catch (error) {
1711
1798
  throw new VError(error, `Failed to create extension host rpc`);
@@ -1714,10 +1801,11 @@ const createExtensionHostRpc = async () => {
1714
1801
 
1715
1802
  const initialize = async () => {
1716
1803
  const extensionHostRpc = await createExtensionHostRpc();
1717
- set(ExtensionHostWorker, extensionHostRpc);
1804
+ set(extensionHostRpc);
1718
1805
  };
1719
1806
 
1720
1807
  const Actions = 'Actions';
1808
+ const SourceControlButtons = 'SourceControlButtons';
1721
1809
  const Grow = 'Grow';
1722
1810
  const Chevron = 'Chevron';
1723
1811
  const ChevronRight = 'ChevronRight';
@@ -1849,7 +1937,8 @@ const getButtonVirtualDom = button => {
1849
1937
  className: SourceControlButton,
1850
1938
  title: label,
1851
1939
  ariaLabel: label,
1852
- childCount: 1
1940
+ childCount: 1,
1941
+ name: label
1853
1942
  }, getIconVirtualDom(icon, Span)];
1854
1943
  };
1855
1944
 
@@ -1859,7 +1948,7 @@ const getButtonsVirtualDom = buttons => {
1859
1948
  }
1860
1949
  return [{
1861
1950
  type: Div,
1862
- className: 'SourceControlButtons',
1951
+ className: SourceControlButtons,
1863
1952
  childCount: buttons.length
1864
1953
  }, ...buttons.flatMap(getButtonVirtualDom)];
1865
1954
  };
@@ -2083,7 +2172,7 @@ const render2 = (uid, diffResult) => {
2083
2172
  oldState,
2084
2173
  newState
2085
2174
  } = get$2(uid);
2086
- set$1(uid, newState, newState);
2175
+ set$4(uid, newState, newState);
2087
2176
  const commands = applyRender(oldState, newState, diffResult);
2088
2177
  return commands;
2089
2178
  };
@@ -2139,7 +2228,7 @@ const renderEventListeners = () => {
2139
2228
  params: ['handleFocus']
2140
2229
  }, {
2141
2230
  name: HandleClickAt,
2142
- params: ['handleClickAt', 'event.clientX', 'event.clientY']
2231
+ params: ['handleClickAt', 'event.clientX', 'event.clientY', 'event.target.name']
2143
2232
  }, {
2144
2233
  name: HandleMouseOverAt,
2145
2234
  params: ['handleMouseOverAt', 'event.clientX', 'event.clientY']
@@ -2212,6 +2301,7 @@ const commandMap = {
2212
2301
  'SourceControl.handleContextMenu': wrapCommand(handleContextMenu),
2213
2302
  'SourceControl.handleFocus': wrapCommand(handleFocus),
2214
2303
  'SourceControl.handleMouseOut': wrapCommand(handleMouseOut),
2304
+ 'SourceControl.refresh': wrapCommand(refresh),
2215
2305
  'SourceControl.handleMouseOutAt': wrapCommand(handleMouseOutAt),
2216
2306
  'SourceControl.handleMouseOver': wrapCommand(handleMouseOver),
2217
2307
  'SourceControl.handleMouseOverAt': wrapCommand(handleMouseOverAt),
@@ -2224,14 +2314,15 @@ const commandMap = {
2224
2314
  'SourceControl.saveState': saveState,
2225
2315
  'SourceControl.selectIndex': wrapCommand(selectIndex),
2226
2316
  'SourceControl.terminate': terminate,
2227
- 'SourceControl.updateIcons': wrapCommand(updateIcons)
2317
+ 'SourceControl.updateIcons': wrapCommand(updateIcons),
2318
+ 'SourceControl.handleClickSourceControlButtons': wrapCommand(handleClickSourceControlButtons)
2228
2319
  };
2229
2320
 
2230
2321
  const listen = async () => {
2231
2322
  const rpc = await WebWorkerRpcClient.create({
2232
2323
  commandMap: commandMap
2233
2324
  });
2234
- set(RendererWorker, rpc);
2325
+ set$1(rpc);
2235
2326
  };
2236
2327
 
2237
2328
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/source-control-worker",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Source Control Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"