@lvce-editor/activity-bar-worker 4.4.0 → 5.0.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.
@@ -411,6 +411,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
411
411
  listen: listen$6,
412
412
  wrap: wrap$e
413
413
  };
414
+ const addListener = (emitter, type, callback) => {
415
+ if ('addEventListener' in emitter) {
416
+ emitter.addEventListener(type, callback);
417
+ } else {
418
+ emitter.on(type, callback);
419
+ }
420
+ };
421
+ const removeListener = (emitter, type, callback) => {
422
+ if ('removeEventListener' in emitter) {
423
+ emitter.removeEventListener(type, callback);
424
+ } else {
425
+ emitter.off(type, callback);
426
+ }
427
+ };
428
+ const getFirstEvent = (eventEmitter, eventMap) => {
429
+ const {
430
+ promise,
431
+ resolve
432
+ } = Promise.withResolvers();
433
+ const listenerMap = Object.create(null);
434
+ const cleanup = value => {
435
+ for (const event of Object.keys(eventMap)) {
436
+ removeListener(eventEmitter, event, listenerMap[event]);
437
+ }
438
+ resolve(value);
439
+ };
440
+ for (const [event, type] of Object.entries(eventMap)) {
441
+ const listener = event => {
442
+ cleanup({
443
+ event,
444
+ type
445
+ });
446
+ };
447
+ addListener(eventEmitter, event, listener);
448
+ listenerMap[event] = listener;
449
+ }
450
+ return promise;
451
+ };
452
+ const Message$1 = 3;
453
+ const create$5$1 = async ({
454
+ isMessagePortOpen,
455
+ messagePort
456
+ }) => {
457
+ if (!isMessagePort(messagePort)) {
458
+ throw new IpcError('port must be of type MessagePort');
459
+ }
460
+ if (isMessagePortOpen) {
461
+ return messagePort;
462
+ }
463
+ const eventPromise = getFirstEvent(messagePort, {
464
+ message: Message$1
465
+ });
466
+ messagePort.start();
467
+ const {
468
+ event,
469
+ type
470
+ } = await eventPromise;
471
+ if (type !== Message$1) {
472
+ throw new IpcError('Failed to wait for ipc message');
473
+ }
474
+ if (event.data !== readyMessage) {
475
+ throw new IpcError('unexpected first message');
476
+ }
477
+ return messagePort;
478
+ };
479
+ const signal$1 = messagePort => {
480
+ messagePort.start();
481
+ };
482
+ class IpcParentWithMessagePort extends Ipc {
483
+ getData = getData$2;
484
+ send(message) {
485
+ this._rawIpc.postMessage(message);
486
+ }
487
+ sendAndTransfer(message) {
488
+ const transfer = getTransferrables(message);
489
+ this._rawIpc.postMessage(message, transfer);
490
+ }
491
+ dispose() {
492
+ this._rawIpc.close();
493
+ }
494
+ onMessage(callback) {
495
+ this._rawIpc.addEventListener('message', callback);
496
+ }
497
+ onClose(callback) {}
498
+ }
499
+ const wrap$5 = messagePort => {
500
+ return new IpcParentWithMessagePort(messagePort);
501
+ };
502
+ const IpcParentWithMessagePort$1 = {
503
+ __proto__: null,
504
+ create: create$5$1,
505
+ signal: signal$1,
506
+ wrap: wrap$5
507
+ };
414
508
 
415
509
  class CommandNotFoundError extends Error {
416
510
  constructor(command) {
@@ -647,7 +741,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
647
741
  const errorProperty = getErrorProperty(error, prettyError);
648
742
  return create$1$1(id, errorProperty);
649
743
  };
650
- const create$7 = (message, result) => {
744
+ const create$a = (message, result) => {
651
745
  return {
652
746
  id: message.id,
653
747
  jsonrpc: Two$1,
@@ -656,7 +750,7 @@ const create$7 = (message, result) => {
656
750
  };
657
751
  const getSuccessResponse = (message, result) => {
658
752
  const resultProperty = result ?? null;
659
- return create$7(message, resultProperty);
753
+ return create$a(message, resultProperty);
660
754
  };
661
755
  const getErrorResponseSimple = (id, error) => {
662
756
  return {
@@ -750,7 +844,7 @@ const handleJsonRpcMessage = async (...args) => {
750
844
 
751
845
  const Two = '2.0';
752
846
 
753
- const create$6 = (method, params) => {
847
+ const create$9 = (method, params) => {
754
848
  return {
755
849
  jsonrpc: Two,
756
850
  method,
@@ -758,7 +852,7 @@ const create$6 = (method, params) => {
758
852
  };
759
853
  };
760
854
 
761
- const create$5 = (id, method, params) => {
855
+ const create$8 = (id, method, params) => {
762
856
  const message = {
763
857
  id,
764
858
  jsonrpc: Two,
@@ -769,12 +863,12 @@ const create$5 = (id, method, params) => {
769
863
  };
770
864
 
771
865
  let id = 0;
772
- const create$4 = () => {
866
+ const create$7 = () => {
773
867
  return ++id;
774
868
  };
775
869
 
776
870
  const registerPromise = map => {
777
- const id = create$4();
871
+ const id = create$7();
778
872
  const {
779
873
  promise,
780
874
  resolve
@@ -791,7 +885,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
791
885
  id,
792
886
  promise
793
887
  } = registerPromise(callbacks);
794
- const message = create$5(id, method, params);
888
+ const message = create$8(id, method, params);
795
889
  if (useSendAndTransfer && ipc.sendAndTransfer) {
796
890
  ipc.sendAndTransfer(message);
797
891
  } else {
@@ -827,7 +921,7 @@ const createRpc = ipc => {
827
921
  * @deprecated
828
922
  */
829
923
  send(method, ...params) {
830
- const message = create$6(method, params);
924
+ const message = create$9(method, params);
831
925
  ipc.send(message);
832
926
  }
833
927
  };
@@ -867,6 +961,83 @@ const listen$1 = async (module, options) => {
867
961
  return ipc;
868
962
  };
869
963
 
964
+ const create$6 = async ({
965
+ commandMap,
966
+ isMessagePortOpen = true,
967
+ messagePort
968
+ }) => {
969
+ // TODO create a commandMap per rpc instance
970
+ register(commandMap);
971
+ const rawIpc = await IpcParentWithMessagePort$1.create({
972
+ isMessagePortOpen,
973
+ messagePort
974
+ });
975
+ const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
976
+ handleIpc(ipc);
977
+ const rpc = createRpc(ipc);
978
+ messagePort.start();
979
+ return rpc;
980
+ };
981
+
982
+ const create$5 = async ({
983
+ commandMap,
984
+ isMessagePortOpen,
985
+ send
986
+ }) => {
987
+ const {
988
+ port1,
989
+ port2
990
+ } = new MessageChannel();
991
+ await send(port1);
992
+ return create$6({
993
+ commandMap,
994
+ isMessagePortOpen,
995
+ messagePort: port2
996
+ });
997
+ };
998
+
999
+ const createSharedLazyRpc = factory => {
1000
+ let rpcPromise;
1001
+ const getOrCreate = () => {
1002
+ if (!rpcPromise) {
1003
+ rpcPromise = factory();
1004
+ }
1005
+ return rpcPromise;
1006
+ };
1007
+ return {
1008
+ async dispose() {
1009
+ const rpc = await getOrCreate();
1010
+ await rpc.dispose();
1011
+ },
1012
+ async invoke(method, ...params) {
1013
+ const rpc = await getOrCreate();
1014
+ return rpc.invoke(method, ...params);
1015
+ },
1016
+ async invokeAndTransfer(method, ...params) {
1017
+ const rpc = await getOrCreate();
1018
+ return rpc.invokeAndTransfer(method, ...params);
1019
+ },
1020
+ async send(method, ...params) {
1021
+ const rpc = await getOrCreate();
1022
+ rpc.send(method, ...params);
1023
+ }
1024
+ };
1025
+ };
1026
+
1027
+ const create$4 = async ({
1028
+ commandMap,
1029
+ isMessagePortOpen,
1030
+ send
1031
+ }) => {
1032
+ return createSharedLazyRpc(() => {
1033
+ return create$5({
1034
+ commandMap,
1035
+ isMessagePortOpen,
1036
+ send
1037
+ });
1038
+ });
1039
+ };
1040
+
870
1041
  const create$3 = async ({
871
1042
  commandMap
872
1043
  }) => {
@@ -899,7 +1070,7 @@ const createMockRpc = ({
899
1070
  };
900
1071
 
901
1072
  const rpcs = Object.create(null);
902
- const set$2 = (id, rpc) => {
1073
+ const set$3 = (id, rpc) => {
903
1074
  rpcs[id] = rpc;
904
1075
  };
905
1076
  const get$1 = id => {
@@ -932,7 +1103,7 @@ const create$2 = rpcId => {
932
1103
  const mockRpc = createMockRpc({
933
1104
  commandMap
934
1105
  });
935
- set$2(rpcId, mockRpc);
1106
+ set$3(rpcId, mockRpc);
936
1107
  // @ts-ignore
937
1108
  mockRpc[Symbol.dispose] = () => {
938
1109
  remove(rpcId);
@@ -941,11 +1112,16 @@ const create$2 = rpcId => {
941
1112
  return mockRpc;
942
1113
  },
943
1114
  set(rpc) {
944
- set$2(rpcId, rpc);
1115
+ set$3(rpcId, rpc);
945
1116
  }
946
1117
  };
947
1118
  };
948
1119
 
1120
+ const {
1121
+ invoke: invoke$1,
1122
+ set: set$2
1123
+ } = create$2(6010);
1124
+
949
1125
  const Button$2 = 'button';
950
1126
  const None$1 = 'none';
951
1127
  const Tab$1 = 'tab';
@@ -996,6 +1172,7 @@ const FocusExplorer = 13;
996
1172
 
997
1173
  const {
998
1174
  invoke,
1175
+ invokeAndTransfer,
999
1176
  set: set$1
1000
1177
  } = create$2(RendererWorker);
1001
1178
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
@@ -1005,6 +1182,10 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1005
1182
  number(y);
1006
1183
  await invoke('ContextMenu.show2', uid, menuId, x, y, args);
1007
1184
  };
1185
+ const sendMessagePortToAuthWorker = async (port, rpcId) => {
1186
+ const command = 'HandleMessagePort.handleMessagePort';
1187
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToAuthWorker', port, command, rpcId);
1188
+ };
1008
1189
 
1009
1190
  const toCommandId = key => {
1010
1191
  const dotIndex = key.indexOf('.');
@@ -1274,16 +1455,21 @@ const getKeyBindings = () => {
1274
1455
  };
1275
1456
 
1276
1457
  const getMenuEntriesAccount = state => {
1458
+ const signInLabel = state.userLoginState === 'logging in' ? 'Signing In...' : 'Sign In';
1459
+ const signOutLabel = state.userLoginState === 'logging out' ? 'Signing Out...' : 'Sign Out';
1460
+ if (state.userLoginState === 'logged in' || state.userLoginState === 'logging out') {
1461
+ return [{
1462
+ command: 'ActivityBar.handleClickSignOut',
1463
+ flags: None,
1464
+ id: 'signOut',
1465
+ label: signOutLabel
1466
+ }];
1467
+ }
1277
1468
  return [{
1278
- command: 'Account.signIn',
1469
+ command: 'ActivityBar.handleClickSignIn',
1279
1470
  flags: None,
1280
1471
  id: 'signIn',
1281
- label: 'Sign In'
1282
- }, {
1283
- command: 'Account.signOut',
1284
- flags: None,
1285
- id: 'signOut',
1286
- label: 'Sign Out'
1472
+ label: signInLabel
1287
1473
  }];
1288
1474
  };
1289
1475
 
@@ -1495,15 +1681,28 @@ const getMenuEntriesSettings = state => {
1495
1681
  return items;
1496
1682
  };
1497
1683
 
1498
- // Use a unique number for the Account menu ID
1499
- const ACCOUNT_MENU_ID$1 = 1000;
1684
+ const show2 = async (uid, menuId, x, y, args) => {
1685
+ await showContextMenu2(uid, menuId, x, y, args);
1686
+ };
1687
+
1688
+ const ACCOUNT_MENU_ID = 32_122;
1689
+ const handleClickAccount = async (state, eventX, eventY, viewletId) => {
1690
+ const {
1691
+ uid
1692
+ } = state;
1693
+ await show2(uid, ACCOUNT_MENU_ID, eventX, eventY, {
1694
+ menuId: ACCOUNT_MENU_ID
1695
+ });
1696
+ return state;
1697
+ };
1698
+
1500
1699
  const getMenuEntries = (state, options) => {
1501
1700
  const {
1502
1701
  menuId
1503
1702
  } = options;
1504
1703
  switch (menuId) {
1505
- case ACCOUNT_MENU_ID$1:
1506
- return getMenuEntriesAccount();
1704
+ case ACCOUNT_MENU_ID:
1705
+ return getMenuEntriesAccount(state);
1507
1706
  case ActivityBar$3:
1508
1707
  return getMenuEntriesActivityBar(state);
1509
1708
  case ActivityBarAdditionalViews:
@@ -1516,7 +1715,7 @@ const getMenuEntries = (state, options) => {
1516
1715
  };
1517
1716
 
1518
1717
  const getMenuEntryIds = () => {
1519
- return [ActivityBar$3, ActivityBarAdditionalViews, Settings$1];
1718
+ return [ActivityBar$3, ActivityBarAdditionalViews, Settings$1, ACCOUNT_MENU_ID];
1520
1719
  };
1521
1720
 
1522
1721
  const updateItemsWithBadgeCount = async items => {
@@ -1554,7 +1753,23 @@ const handleBlur = state => {
1554
1753
  };
1555
1754
  };
1556
1755
 
1557
- const getIndexFromPosition = (y, eventX, eventY, itemHeight, itemCount, height) => {
1756
+ const isBottomItem = item => {
1757
+ return item.id === 'Account' || item.id === 'Settings';
1758
+ };
1759
+ const getBottomItemCount = items => {
1760
+ if (typeof items === 'number') {
1761
+ return items > 1 ? 1 : 0;
1762
+ }
1763
+ return items.filter(isBottomItem).length;
1764
+ };
1765
+ const getItemCount = items => {
1766
+ if (typeof items === 'number') {
1767
+ return items;
1768
+ }
1769
+ return items.length;
1770
+ };
1771
+ const getIndexFromPosition = (y, eventX, eventY, itemHeight, items, height) => {
1772
+ const itemCount = getItemCount(items);
1558
1773
  if (itemCount === 0) {
1559
1774
  return -1;
1560
1775
  }
@@ -1567,38 +1782,22 @@ const getIndexFromPosition = (y, eventX, eventY, itemHeight, itemCount, height)
1567
1782
  }
1568
1783
  return index;
1569
1784
  }
1570
- // Settings is always at the bottom (last item) when there are multiple items
1571
- const settingsBottomY = y + height;
1572
- const settingsTopY = settingsBottomY - itemHeight;
1573
- // Check if click is in the Settings area (bottom)
1574
- if (eventY >= settingsTopY && eventY < settingsBottomY) {
1575
- return itemCount - 1;
1785
+ const bottomItemCount = getBottomItemCount(items);
1786
+ const bottomItemsHeight = bottomItemCount * itemHeight;
1787
+ const bottomItemsTopY = y + height - bottomItemsHeight;
1788
+ if (bottomItemCount > 0 && eventY >= bottomItemsTopY && eventY < y + height) {
1789
+ const relativeBottomY = eventY - bottomItemsTopY;
1790
+ return itemCount - bottomItemCount + Math.floor(relativeBottomY / itemHeight);
1576
1791
  }
1577
- // Otherwise, calculate index from top items
1792
+ const topItemCount = itemCount - bottomItemCount;
1578
1793
  const relativeY = eventY - y;
1579
1794
  const index = Math.floor(relativeY / itemHeight);
1580
- if (index < 0 || index >= itemCount - 1) {
1795
+ if (index < 0 || index >= topItemCount) {
1581
1796
  return -1;
1582
1797
  }
1583
1798
  return index;
1584
1799
  };
1585
1800
 
1586
- const show2 = async (uid, menuId, x, y, args) => {
1587
- await showContextMenu2(uid, menuId, x, y, args);
1588
- };
1589
-
1590
- // Use a unique number for the Account menu ID
1591
- const ACCOUNT_MENU_ID = 1000;
1592
- const handleClickAccount = async (state, eventX, eventY, viewletId) => {
1593
- const {
1594
- uid
1595
- } = state;
1596
- await show2(uid, ACCOUNT_MENU_ID, eventX, eventY, {
1597
- menuId: ACCOUNT_MENU_ID
1598
- });
1599
- return state;
1600
- };
1601
-
1602
1801
  const handleClickAdditionalViews = async (state, eventX, eventY, viewletId) => {
1603
1802
  const {
1604
1803
  uid
@@ -1610,33 +1809,110 @@ const handleClickAdditionalViews = async (state, eventX, eventY, viewletId) => {
1610
1809
  return state;
1611
1810
  };
1612
1811
 
1613
- const show = async (sideBarVisible, id) => {
1614
- if (sideBarVisible) {
1615
- await invoke('SideBar.show', id);
1616
- } else {
1617
- // @ts-ignore
1618
- await invoke('Layout.showSideBar', /* id */id);
1812
+ const findIndex = (activityBarItems, id) => {
1813
+ for (let i = 0; i < activityBarItems.length; i++) {
1814
+ if (activityBarItems[i].id === id) {
1815
+ return i;
1816
+ }
1619
1817
  }
1818
+ return -1;
1819
+ };
1820
+
1821
+ const Account = 'Account';
1822
+ const DebugAlt2 = 'DebugAlt2';
1823
+ const Extensions$1 = 'Extensions';
1824
+ const Files = 'Files';
1825
+ const Search$1 = 'Search';
1826
+ const SettingsGear = 'SettingsGear';
1827
+ const SourceControl$1 = 'SourceControl';
1828
+ const Ellipsis = 'Ellipsis';
1829
+
1830
+ const getFilteredActivityBarItems = (items, height, itemHeight) => {
1831
+ const numberOfVisibleItems = getNumberOfVisibleItems({
1832
+ height,
1833
+ itemHeight
1834
+ });
1835
+ if (numberOfVisibleItems >= items.length) {
1836
+ return items;
1837
+ }
1838
+ const showMoreItem = {
1839
+ flags: Button,
1840
+ icon: Ellipsis,
1841
+ id: 'Additional Views',
1842
+ keyShortcuts: '',
1843
+ title: additionalViews()
1844
+ };
1845
+ return [...items.slice(0, numberOfVisibleItems - 2), showMoreItem, items.at(-1)];
1846
+ };
1847
+
1848
+ const setFlag = (item, flag, enabled) => {
1849
+ return {
1850
+ ...item,
1851
+ flags: enabled ? item.flags | flag : item.flags & ~flag
1852
+ };
1853
+ };
1854
+
1855
+ const markSelected = (items, selectedIndex) => {
1856
+ return items.map((item, index) => {
1857
+ const isSelected = index === selectedIndex;
1858
+ return setFlag(item, Selected, isSelected);
1859
+ });
1620
1860
  };
1621
- const hide = async () => {
1622
- await invoke('Layout.hideSideBar');
1861
+
1862
+ const toggle = async id => {
1863
+ await invoke('SideBar.toggle', id);
1623
1864
  };
1624
1865
 
1866
+ const getSideBarChange = (sideBarVisible, currentViewletId, viewletId) => {
1867
+ if (sideBarVisible) {
1868
+ if (currentViewletId === viewletId) {
1869
+ return {
1870
+ type: 'hide',
1871
+ viewletId
1872
+ };
1873
+ }
1874
+ return {
1875
+ type: 'switch',
1876
+ viewletId
1877
+ };
1878
+ }
1879
+ return {
1880
+ type: 'show',
1881
+ viewletId
1882
+ };
1883
+ };
1625
1884
  const handleClickOther = async (state, viewletId) => {
1626
1885
  const {
1886
+ activityBarItems,
1627
1887
  currentViewletId,
1888
+ height,
1889
+ itemHeight,
1628
1890
  sideBarVisible
1629
1891
  } = state;
1630
- if (sideBarVisible) {
1631
- if (currentViewletId === viewletId) {
1632
- await hide();
1633
- return state;
1634
- }
1635
- await show(sideBarVisible, viewletId);
1636
- return state;
1892
+ const sideBarChange = getSideBarChange(sideBarVisible, currentViewletId, viewletId);
1893
+ await toggle(viewletId);
1894
+ if (sideBarChange.type === 'hide') {
1895
+ const newActivityBarItems = markSelected(activityBarItems, -1);
1896
+ const filteredItems = getFilteredActivityBarItems(newActivityBarItems, height, itemHeight);
1897
+ return {
1898
+ ...state,
1899
+ activityBarItems: newActivityBarItems,
1900
+ filteredItems,
1901
+ selectedIndex: -1,
1902
+ sideBarVisible: false
1903
+ };
1637
1904
  }
1638
- await show(sideBarVisible, currentViewletId);
1639
- return state;
1905
+ const selectedIndex = findIndex(activityBarItems, viewletId);
1906
+ const newActivityBarItems = markSelected(activityBarItems, selectedIndex);
1907
+ const filteredItems = getFilteredActivityBarItems(newActivityBarItems, height, itemHeight);
1908
+ return {
1909
+ ...state,
1910
+ activityBarItems: newActivityBarItems,
1911
+ currentViewletId: viewletId,
1912
+ filteredItems,
1913
+ selectedIndex,
1914
+ sideBarVisible: true
1915
+ };
1640
1916
  };
1641
1917
 
1642
1918
  const handleClickSettings = async (state, eventX, eventY, viewletId) => {
@@ -1680,10 +1956,26 @@ const handleClick = async (state, button, eventX, eventY) => {
1680
1956
  itemHeight,
1681
1957
  y
1682
1958
  } = state;
1683
- const index = getIndexFromPosition(y, eventX, eventY, itemHeight, filteredItems.length, height);
1959
+ const index = getIndexFromPosition(y, eventX, eventY, itemHeight, filteredItems, height);
1684
1960
  return handleClickIndex(state, button, index, eventX, eventY);
1685
1961
  };
1686
1962
 
1963
+ const handleClickSignIn = async state => {
1964
+ const {
1965
+ platform
1966
+ } = state;
1967
+ const backendUrl = await invoke('Layout.getBackendUrl');
1968
+ await invoke$1('Auth.login', {
1969
+ backendUrl,
1970
+ platform
1971
+ });
1972
+ return state;
1973
+ };
1974
+
1975
+ const handleClickSignOut = async state => {
1976
+ return state;
1977
+ };
1978
+
1687
1979
  const handleContextMenu = async (state, button, eventX, eventY) => {
1688
1980
  const {
1689
1981
  uid
@@ -1701,33 +1993,6 @@ const handleFocus = state => {
1701
1993
  };
1702
1994
  };
1703
1995
 
1704
- const Account = 'Account';
1705
- const DebugAlt2 = 'DebugAlt2';
1706
- const Extensions$1 = 'Extensions';
1707
- const Files = 'Files';
1708
- const Search$1 = 'Search';
1709
- const SettingsGear = 'SettingsGear';
1710
- const SourceControl$1 = 'SourceControl';
1711
- const Ellipsis = 'Ellipsis';
1712
-
1713
- const getFilteredActivityBarItems = (items, height, itemHeight) => {
1714
- const numberOfVisibleItems = getNumberOfVisibleItems({
1715
- height,
1716
- itemHeight
1717
- });
1718
- if (numberOfVisibleItems >= items.length) {
1719
- return items;
1720
- }
1721
- const showMoreItem = {
1722
- flags: Button,
1723
- icon: Ellipsis,
1724
- id: 'Additional Views',
1725
- keyShortcuts: '',
1726
- title: additionalViews()
1727
- };
1728
- return [...items.slice(0, numberOfVisibleItems - 2), showMoreItem, items.at(-1)];
1729
- };
1730
-
1731
1996
  const handleResize = (state, dimensions) => {
1732
1997
  const {
1733
1998
  activityBarItems,
@@ -1750,6 +2015,15 @@ const handleResize = (state, dimensions) => {
1750
2015
  };
1751
2016
  };
1752
2017
 
2018
+ const getAccountEnabled = async defaultValue => {
2019
+ try {
2020
+ const value = await invoke('Preferences.get', 'activityBar.accountEnabled');
2021
+ return typeof value === 'boolean' ? value : defaultValue;
2022
+ } catch {
2023
+ return defaultValue;
2024
+ }
2025
+ };
2026
+
1753
2027
  const Explorer = 'Explorer';
1754
2028
  const Extensions = 'Extensions';
1755
2029
  const RunAndDebug = 'Run And Debug';
@@ -1760,6 +2034,7 @@ const getActivityBarItems = state => {
1760
2034
  const {
1761
2035
  accountEnabled
1762
2036
  } = state;
2037
+ const settingsFlags = Button | Enabled | (accountEnabled ? 0 : MarginTop);
1763
2038
  const items = [
1764
2039
  // Top
1765
2040
  {
@@ -1805,7 +2080,7 @@ const getActivityBarItems = state => {
1805
2080
  });
1806
2081
  }
1807
2082
  items.push({
1808
- flags: Button | Enabled | MarginTop,
2083
+ flags: settingsFlags,
1809
2084
  icon: SettingsGear,
1810
2085
  id: 'Settings',
1811
2086
  keyShortcuts: '',
@@ -1822,70 +2097,29 @@ const getSideBarPosition = async () => {
1822
2097
  }
1823
2098
  };
1824
2099
 
1825
- const setFlag = (item, flag, enabled) => {
1826
- return {
1827
- ...item,
1828
- flags: enabled ? item.flags | flag : item.flags & ~flag
1829
- };
1830
- };
1831
-
1832
- const markSelected = (items, selectedIndex) => {
1833
- return items.map((item, index) => {
1834
- const isSelected = index === selectedIndex;
1835
- return setFlag(item, Selected, isSelected);
1836
- });
1837
- };
1838
-
1839
2100
  const handleSettingsChanged = async state => {
1840
2101
  const {
1841
2102
  height,
1842
2103
  itemHeight,
1843
2104
  selectedIndex
1844
2105
  } = state;
1845
- const items = getActivityBarItems(state);
2106
+ const [accountEnabled, sidebarLocation] = await Promise.all([getAccountEnabled(state.accountEnabled), getSideBarPosition()]);
2107
+ const newState = {
2108
+ ...state,
2109
+ accountEnabled
2110
+ };
2111
+ const items = getActivityBarItems(newState);
1846
2112
  const itemsWithSelected = markSelected(items, selectedIndex);
1847
2113
  const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
1848
2114
  const newItems = await updateItemsWithBadgeCount(filteredItems);
1849
- const sidebarLocation = await getSideBarPosition();
1850
2115
  return {
1851
- ...state,
2116
+ ...newState,
1852
2117
  activityBarItems: itemsWithSelected,
1853
2118
  filteredItems: newItems,
1854
2119
  sideBarLocation: sidebarLocation
1855
2120
  };
1856
2121
  };
1857
2122
 
1858
- const clearItem = item => {
1859
- const withoutSelected = setFlag(item, Selected, false);
1860
- return setFlag(withoutSelected, Focused, false);
1861
- };
1862
- const handleSideBarHidden = state => {
1863
- const {
1864
- activityBarItems,
1865
- height,
1866
- itemHeight
1867
- } = state;
1868
- const itemsCleared = activityBarItems.map(clearItem);
1869
- const filteredItems = getFilteredActivityBarItems(itemsCleared, height, itemHeight);
1870
- return {
1871
- ...state,
1872
- activityBarItems: itemsCleared,
1873
- filteredItems,
1874
- focusedIndex: -1,
1875
- selectedIndex: -1,
1876
- sideBarVisible: false
1877
- };
1878
- };
1879
-
1880
- const findIndex = (activityBarItems, id) => {
1881
- for (let i = 0; i < activityBarItems.length; i++) {
1882
- if (activityBarItems[i].id === id) {
1883
- return i;
1884
- }
1885
- }
1886
- return -1;
1887
- };
1888
-
1889
2123
  const getSideBarVisible = async () => {
1890
2124
  try {
1891
2125
  const visible = await invoke('Layout.getSideBarVisible');
@@ -1895,22 +2129,38 @@ const getSideBarVisible = async () => {
1895
2129
  }
1896
2130
  };
1897
2131
 
1898
- const handleSideBarViewletChange = async (state, id, ...args) => {
2132
+ const clearItem = item => {
2133
+ const withoutSelected = setFlag(item, Selected, false);
2134
+ return setFlag(withoutSelected, Focused, false);
2135
+ };
2136
+ const handleSideBarStateChange = async (state, id = state.currentViewletId, sideBarVisibleOverride) => {
1899
2137
  const {
1900
2138
  activityBarItems,
1901
2139
  height,
1902
2140
  itemHeight
1903
2141
  } = state;
1904
- const sideBarVisible = await getSideBarVisible();
1905
- const index = findIndex(activityBarItems, id);
1906
- const newActivityBarItems = markSelected(activityBarItems, index);
2142
+ const sideBarVisible = typeof sideBarVisibleOverride === 'boolean' ? sideBarVisibleOverride : await getSideBarVisible();
2143
+ if (!sideBarVisible) {
2144
+ const itemsCleared = activityBarItems.map(clearItem);
2145
+ const filteredItems = getFilteredActivityBarItems(itemsCleared, height, itemHeight);
2146
+ return {
2147
+ ...state,
2148
+ activityBarItems: itemsCleared,
2149
+ filteredItems,
2150
+ focusedIndex: -1,
2151
+ selectedIndex: -1,
2152
+ sideBarVisible: false
2153
+ };
2154
+ }
2155
+ const selectedIndex = findIndex(activityBarItems, id);
2156
+ const newActivityBarItems = markSelected(activityBarItems, selectedIndex);
1907
2157
  const filteredItems = getFilteredActivityBarItems(newActivityBarItems, height, itemHeight);
1908
2158
  return {
1909
2159
  ...state,
1910
2160
  activityBarItems: newActivityBarItems,
1911
2161
  currentViewletId: id,
1912
2162
  filteredItems,
1913
- selectedIndex: index,
2163
+ selectedIndex,
1914
2164
  sideBarVisible
1915
2165
  };
1916
2166
  };
@@ -1964,18 +2214,23 @@ const getActiveView = async () => {
1964
2214
 
1965
2215
  const loadContent = async state => {
1966
2216
  const {
2217
+ accountEnabled,
1967
2218
  height,
1968
2219
  itemHeight
1969
2220
  } = state;
1970
- const items = getActivityBarItems(state);
1971
- const [activeView, sideBarVisible, sidebarLocation] = await Promise.all([getActiveView(), getSideBarVisible(), getSideBarPosition()]);
2221
+ const [accountEnabledNew, activeView, sideBarVisible, sidebarLocation] = await Promise.all([getAccountEnabled(accountEnabled), getActiveView(), getSideBarVisible(), getSideBarPosition()]);
2222
+ const newState = {
2223
+ ...state,
2224
+ accountEnabled: accountEnabledNew
2225
+ };
2226
+ const items = getActivityBarItems(newState);
1972
2227
  const index = items.findIndex(item => item.id === activeView);
1973
2228
  const selectedIndex = sideBarVisible ? index : -1;
1974
2229
  const itemsWithSelected = markSelected(items, selectedIndex);
1975
2230
  const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
1976
2231
  const newItems = await updateItemsWithBadgeCount(filteredItems);
1977
2232
  return {
1978
- ...state,
2233
+ ...newState,
1979
2234
  activityBarItems: itemsWithSelected,
1980
2235
  currentViewletId: Explorer,
1981
2236
  filteredItems: newItems,
@@ -2331,6 +2586,10 @@ const HandleMouseDown = 4;
2331
2586
 
2332
2587
  const ActivityBar = 'ActivityBar';
2333
2588
 
2589
+ const getActivityBarItemHasPopup = item => {
2590
+ return item.id === 'Account' || item.id === 'Settings';
2591
+ };
2592
+
2334
2593
  const getAriaSelected = (isTab, isSelected) => {
2335
2594
  if (!isTab) {
2336
2595
  return undefined;
@@ -2379,10 +2638,12 @@ const getActivityBarItemInProgressDom = item => {
2379
2638
  const isFocused = flags & Focused;
2380
2639
  const role = isTab ? Tab$1 : Button$2;
2381
2640
  const ariaSelected = getAriaSelected(isTab, isSelected);
2641
+ const ariaHasPopup = getActivityBarItemHasPopup(item) || undefined;
2382
2642
  const marginTop = flags & MarginTop;
2383
2643
  let className = getClassName(isFocused, marginTop, isSelected);
2384
2644
  className += ' ' + ActivityBarItemNested;
2385
2645
  return [{
2646
+ ariaHasPopup,
2386
2647
  ariaLabel: '',
2387
2648
  ariaSelected,
2388
2649
  childCount: 2,
@@ -2414,10 +2675,12 @@ const getActivityBarItemWithBadgeDom = item => {
2414
2675
  const isFocused = flags & Focused;
2415
2676
  const role = isTab ? Tab$1 : Button$2;
2416
2677
  const ariaSelected = getAriaSelected(isTab, isSelected);
2678
+ const ariaHasPopup = getActivityBarItemHasPopup(item) || undefined;
2417
2679
  const marginTop = flags & MarginTop;
2418
2680
  let className = getClassName(isFocused, marginTop, isSelected);
2419
2681
  className += ' ' + ActivityBarItemNested;
2420
2682
  return [{
2683
+ ariaHasPopup,
2421
2684
  ariaLabel: '',
2422
2685
  ariaSelected,
2423
2686
  childCount: 2,
@@ -2453,6 +2716,7 @@ const getActivityBarItemVirtualDom = item => {
2453
2716
  icon,
2454
2717
  title
2455
2718
  } = item;
2719
+ const ariaHasPopup = getActivityBarItemHasPopup(item) || undefined;
2456
2720
  const isTab = flags & Tab;
2457
2721
  const isSelected = flags & Selected;
2458
2722
  const isFocused = flags & Focused;
@@ -2463,6 +2727,7 @@ const getActivityBarItemVirtualDom = item => {
2463
2727
  const className = getClassName(isFocused, marginTop, isSelected);
2464
2728
  if (isSelected) {
2465
2729
  return [{
2730
+ ariaHasPopup,
2466
2731
  ariaLabel: '',
2467
2732
  ariaSelected,
2468
2733
  childCount: 1,
@@ -2481,6 +2746,7 @@ const getActivityBarItemVirtualDom = item => {
2481
2746
  return getActivityBarItemWithBadgeDom(item);
2482
2747
  }
2483
2748
  return [{
2749
+ ariaHasPopup,
2484
2750
  ariaLabel: '',
2485
2751
  ariaSelected,
2486
2752
  childCount: 0,
@@ -2596,12 +2862,7 @@ const renderEventListeners = () => {
2596
2862
  };
2597
2863
 
2598
2864
  const saveState = state => {
2599
- const {
2600
- currentViewletId
2601
- } = state;
2602
- return {
2603
- currentViewletId
2604
- };
2865
+ return {};
2605
2866
  };
2606
2867
 
2607
2868
  const setAccountEnabled = (state, enabled) => {
@@ -2624,6 +2885,13 @@ const setAccountEnabled = (state, enabled) => {
2624
2885
  };
2625
2886
  };
2626
2887
 
2888
+ const setUserLoginState = (state, userLoginState) => {
2889
+ return {
2890
+ ...state,
2891
+ userLoginState
2892
+ };
2893
+ };
2894
+
2627
2895
  const toggleActivityBarItem = async (state, itemId) => {
2628
2896
  const {
2629
2897
  activityBarItems
@@ -2662,11 +2930,12 @@ const commandMap = {
2662
2930
  'ActivityBar.handleClick': wrapCommand(handleClick),
2663
2931
  'ActivityBar.handleClickIndex': wrapCommand(handleClickIndex),
2664
2932
  'ActivityBar.handleClickSettings': wrapCommand(handleClickSettings),
2933
+ 'ActivityBar.handleClickSignIn': wrapCommand(handleClickSignIn),
2934
+ 'ActivityBar.handleClickSignOut': wrapCommand(handleClickSignOut),
2665
2935
  'ActivityBar.handleContextMenu': wrapCommand(handleContextMenu),
2666
2936
  'ActivityBar.handleFocus': wrapCommand(handleFocus),
2667
2937
  'ActivityBar.handleSettingsChanged': wrapCommand(handleSettingsChanged),
2668
- 'ActivityBar.handleSideBarHidden': wrapCommand(handleSideBarHidden),
2669
- 'ActivityBar.handleSideBarViewletChange': wrapCommand(handleSideBarViewletChange),
2938
+ 'ActivityBar.handleSideBarStateChange': wrapCommand(handleSideBarStateChange),
2670
2939
  'ActivityBar.handleUpdateStateChange': wrapCommand(handleUpdateStateChange),
2671
2940
  'ActivityBar.loadContent': wrapCommand(loadContent),
2672
2941
  'ActivityBar.render2': render2,
@@ -2674,16 +2943,30 @@ const commandMap = {
2674
2943
  'ActivityBar.resize': wrapCommand(handleResize),
2675
2944
  'ActivityBar.saveState': wrapGetter(saveState),
2676
2945
  'ActivityBar.setAccountEnabled': wrapCommand(setAccountEnabled),
2946
+ 'ActivityBar.setUserLoginState': wrapCommand(setUserLoginState),
2677
2947
  'ActivityBar.terminate': terminate,
2678
2948
  'ActivityBar.toggleActivityBarItem': wrapCommand(toggleActivityBarItem)
2679
2949
  };
2680
2950
 
2951
+ const send = async port => {
2952
+ // @ts-ignore
2953
+ await sendMessagePortToAuthWorker(port);
2954
+ };
2955
+ const initializeAuthWorker = async () => {
2956
+ const rpc = await create$4({
2957
+ commandMap: {},
2958
+ send
2959
+ });
2960
+ set$2(rpc);
2961
+ };
2962
+
2681
2963
  const listen = async () => {
2682
2964
  registerCommands(commandMap);
2683
2965
  const rpc = await create$3({
2684
2966
  commandMap: commandMap
2685
2967
  });
2686
2968
  set$1(rpc);
2969
+ await initializeAuthWorker();
2687
2970
  };
2688
2971
 
2689
2972
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "4.4.0",
3
+ "version": "5.0.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",