@lvce-editor/activity-bar-worker 7.5.0 → 7.7.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.
@@ -151,7 +151,9 @@ const create$9 = (id, uri, x, y, width, height, args, parentUid, platform = 0) =
151
151
  uid: id,
152
152
  updateProgress: 0,
153
153
  updateState: '',
154
+ userLoginProvider: 'GitHub',
154
155
  userLoginState: 'logged out',
156
+ userName: '',
155
157
  width,
156
158
  x,
157
159
  y
@@ -251,6 +253,7 @@ const Reference = 100;
251
253
  const Button$1 = 'event.button';
252
254
  const ClientX = 'event.clientX';
253
255
  const ClientY = 'event.clientY';
256
+ const TargetName = 'event.target.name';
254
257
 
255
258
  const Enter = 3;
256
259
  const Space = 9;
@@ -267,6 +270,7 @@ const ActivityBarAdditionalViews = 17;
267
270
 
268
271
  const Separator = 1;
269
272
  const None = 0;
273
+ const SubMenu = 4;
270
274
  const Checked = 2;
271
275
  const Unchecked = 3;
272
276
 
@@ -324,7 +328,24 @@ const getKeyBindings = () => {
324
328
  }];
325
329
  };
326
330
 
331
+ const ACCOUNT_SUBMENU_ID = 32_123;
332
+ const getAccountLabel = state => {
333
+ const name = state.userName || 'Account';
334
+ const provider = state.userLoginProvider || 'GitHub';
335
+ return `${name} (${provider})`;
336
+ };
327
337
  const getMenuEntriesAccountLoggedIn = state => {
338
+ return [{
339
+ args: [{
340
+ menuId: ACCOUNT_SUBMENU_ID
341
+ }],
342
+ command: '',
343
+ flags: SubMenu,
344
+ id: ACCOUNT_SUBMENU_ID,
345
+ label: getAccountLabel(state)
346
+ }];
347
+ };
348
+ const getMenuEntriesAccountSubMenu = state => {
328
349
  const {
329
350
  userLoginState
330
351
  } = state;
@@ -1768,6 +1789,8 @@ const getMenuEntries = (state, options) => {
1768
1789
  switch (menuId) {
1769
1790
  case ACCOUNT_MENU_ID:
1770
1791
  return getMenuEntriesAccount(state);
1792
+ case ACCOUNT_SUBMENU_ID:
1793
+ return getMenuEntriesAccountSubMenu(state);
1771
1794
  case ActivityBar$3:
1772
1795
  return getMenuEntriesActivityBar(state);
1773
1796
  case ActivityBarAdditionalViews:
@@ -1780,7 +1803,7 @@ const getMenuEntries = (state, options) => {
1780
1803
  };
1781
1804
 
1782
1805
  const getMenuEntryIds = () => {
1783
- return [ActivityBar$3, ActivityBarAdditionalViews, Settings$1, ACCOUNT_MENU_ID];
1806
+ return [ActivityBar$3, ActivityBarAdditionalViews, Settings$1, ACCOUNT_MENU_ID, ACCOUNT_SUBMENU_ID];
1784
1807
  };
1785
1808
 
1786
1809
  const updateItemsWithBadgeCount = async items => {
@@ -1800,16 +1823,38 @@ const updateItemsWithBadgeCount = async items => {
1800
1823
  }
1801
1824
  };
1802
1825
 
1803
- const handleBadgeCountChange = async state => {
1804
- const {
1805
- filteredItems
1806
- } = state;
1807
- const newItems = await updateItemsWithBadgeCount(filteredItems);
1826
+ const updateStateItems = (state, activityBarItems) => {
1827
+ const itemById = new Map(activityBarItems.map(item => [item.id, item]));
1828
+ const filteredItems = state.filteredItems.map(item => itemById.get(item.id) || item);
1808
1829
  return {
1809
1830
  ...state,
1810
- filteredItems: newItems
1831
+ activityBarItems,
1832
+ filteredItems
1811
1833
  };
1812
1834
  };
1835
+ const applyBadgeCountChanges = (state, badgeCounts) => {
1836
+ const activityBarItems = state.activityBarItems.map(item => {
1837
+ if (!Object.hasOwn(badgeCounts, item.id)) {
1838
+ return item;
1839
+ }
1840
+ const badgeCount = badgeCounts[item.id];
1841
+ return {
1842
+ ...item,
1843
+ badgeText: badgeCount ? String(badgeCount) : ''
1844
+ };
1845
+ });
1846
+ return updateStateItems(state, activityBarItems);
1847
+ };
1848
+ const handleBadgeCountChange = async (state, badgeCounts) => {
1849
+ if (badgeCounts) {
1850
+ return applyBadgeCountChanges(state, badgeCounts);
1851
+ }
1852
+ const newActivityBarItems = await updateItemsWithBadgeCount(state.activityBarItems);
1853
+ if (newActivityBarItems === state.activityBarItems) {
1854
+ return state;
1855
+ }
1856
+ return updateStateItems(state, newActivityBarItems);
1857
+ };
1813
1858
 
1814
1859
  const handleBlur = state => {
1815
1860
  return {
@@ -2015,14 +2060,21 @@ const handleClickIndex = async (state, button, index, x, y) => {
2015
2060
  }
2016
2061
  };
2017
2062
 
2018
- const handleClick = async (state, button, eventX, eventY) => {
2063
+ const getIndexFromTarget = (state, targetName) => {
2064
+ if (!targetName) {
2065
+ return -1;
2066
+ }
2067
+ return state.filteredItems.findIndex(item => item.id === targetName);
2068
+ };
2069
+ const handleClick = async (state, button, eventX, eventY, targetName = '') => {
2019
2070
  const {
2020
2071
  filteredItems,
2021
2072
  height,
2022
2073
  itemHeight,
2023
2074
  y
2024
2075
  } = state;
2025
- const index = getIndexFromPosition(y, eventX, eventY, itemHeight, filteredItems, height);
2076
+ const targetIndex = getIndexFromTarget(state, targetName);
2077
+ const index = targetIndex === -1 ? getIndexFromPosition(y, eventX, eventY, itemHeight, filteredItems, height) : targetIndex;
2026
2078
  return handleClickIndex(state, button, index, eventX, eventY);
2027
2079
  };
2028
2080
 
@@ -2175,12 +2227,12 @@ const handleExtensionsChanged = async state => {
2175
2227
  const contributedViews = await getContributedViews(state.platform);
2176
2228
  const items = getActivityBarItems(state, contributedViews);
2177
2229
  const itemsWithSelected = markSelected(items, selectedIndex);
2178
- const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
2179
- const newItems = await updateItemsWithBadgeCount(filteredItems);
2230
+ const activityBarItems = await updateItemsWithBadgeCount(itemsWithSelected);
2231
+ const filteredItems = getFilteredActivityBarItems(activityBarItems, height, itemHeight);
2180
2232
  return {
2181
2233
  ...state,
2182
- activityBarItems: itemsWithSelected,
2183
- filteredItems: newItems
2234
+ activityBarItems,
2235
+ filteredItems
2184
2236
  };
2185
2237
  };
2186
2238
 
@@ -2243,12 +2295,12 @@ const handleSettingsChanged = async state => {
2243
2295
  };
2244
2296
  const items = getActivityBarItems(newState, contributedViews);
2245
2297
  const itemsWithSelected = markSelected(items, selectedIndex);
2246
- const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
2247
- const newItems = await updateItemsWithBadgeCount(filteredItems);
2298
+ const activityBarItems = await updateItemsWithBadgeCount(itemsWithSelected);
2299
+ const filteredItems = getFilteredActivityBarItems(activityBarItems, height, itemHeight);
2248
2300
  return {
2249
2301
  ...newState,
2250
- activityBarItems: itemsWithSelected,
2251
- filteredItems: newItems,
2302
+ activityBarItems,
2303
+ filteredItems,
2252
2304
  sideBarLocation: sidebarLocation
2253
2305
  };
2254
2306
  };
@@ -2336,6 +2388,30 @@ const handleUpdateStateChange = async (state, config) => {
2336
2388
  };
2337
2389
  };
2338
2390
 
2391
+ const providerKeys = ['userLoginProvider', 'loginProvider', 'authProvider', 'provider'];
2392
+ const getUserLoginProvider = userInfo => {
2393
+ if (!userInfo || typeof userInfo !== 'object') {
2394
+ return 'GitHub';
2395
+ }
2396
+ const record = userInfo;
2397
+ for (const key of providerKeys) {
2398
+ if (typeof record[key] === 'string' && record[key]) {
2399
+ return record[key];
2400
+ }
2401
+ }
2402
+ return 'GitHub';
2403
+ };
2404
+
2405
+ const getUserName = userInfo => {
2406
+ if (!userInfo || typeof userInfo !== 'object') {
2407
+ return '';
2408
+ }
2409
+ if (!('userName' in userInfo) || typeof userInfo.userName !== 'string') {
2410
+ return '';
2411
+ }
2412
+ return userInfo.userName;
2413
+ };
2414
+
2339
2415
  const getUserState = userInfo => {
2340
2416
  if (!userInfo || typeof userInfo !== 'object') {
2341
2417
  return undefined;
@@ -2406,19 +2482,21 @@ const loadContent = async state => {
2406
2482
  const newState = {
2407
2483
  ...state,
2408
2484
  accountEnabled: accountEnabledNew,
2409
- userLoginState: toUserLoginState(getUserState(userInfo))
2485
+ userLoginProvider: getUserLoginProvider(userInfo),
2486
+ userLoginState: toUserLoginState(getUserState(userInfo)),
2487
+ userName: getUserName(userInfo)
2410
2488
  };
2411
2489
  const items = getActivityBarItems(newState, contributedViews);
2412
2490
  const index = items.findIndex(item => item.id === activeView);
2413
2491
  const selectedIndex = sideBarVisible ? index : -1;
2414
2492
  const itemsWithSelected = markSelected(items, selectedIndex);
2415
- const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
2416
- const newItems = await updateItemsWithBadgeCount(filteredItems);
2493
+ const activityBarItems = await updateItemsWithBadgeCount(itemsWithSelected);
2494
+ const filteredItems = getFilteredActivityBarItems(activityBarItems, height, itemHeight);
2417
2495
  return {
2418
2496
  ...newState,
2419
- activityBarItems: itemsWithSelected,
2497
+ activityBarItems,
2420
2498
  currentViewletId: Explorer,
2421
- filteredItems: newItems,
2499
+ filteredItems,
2422
2500
  initial: false,
2423
2501
  selectedIndex,
2424
2502
  sideBarLocation: sidebarLocation,
@@ -2852,6 +2930,7 @@ const getActivityBarItemWithBadgeDom = item => {
2852
2930
  const {
2853
2931
  badgeText,
2854
2932
  flags,
2933
+ id,
2855
2934
  title
2856
2935
  } = item;
2857
2936
  if (!badgeText) {
@@ -2873,17 +2952,20 @@ const getActivityBarItemWithBadgeDom = item => {
2873
2952
  ariaSelected,
2874
2953
  childCount: 2,
2875
2954
  className,
2955
+ name: id,
2876
2956
  role,
2877
2957
  title,
2878
2958
  type: Div
2879
2959
  }, {
2880
2960
  childCount: 0,
2881
2961
  className: mergeClassNames(Icon, getIconClass(item, 'MaskIcon')),
2962
+ name: id,
2882
2963
  role: None$1,
2883
2964
  type: Div
2884
2965
  }, {
2885
2966
  childCount: 1,
2886
2967
  className: ActivityBarItemBadge,
2968
+ name: id,
2887
2969
  type: Div
2888
2970
  }, text(badgeText)];
2889
2971
  };
@@ -2902,6 +2984,7 @@ const getActivityBarItemVirtualDom = item => {
2902
2984
  badgeText,
2903
2985
  flags,
2904
2986
  icon,
2987
+ id,
2905
2988
  title
2906
2989
  } = item;
2907
2990
  const ariaHasPopup = getActivityBarItemHasPopup(item) || undefined;
@@ -2920,10 +3003,14 @@ const getActivityBarItemVirtualDom = item => {
2920
3003
  ariaSelected,
2921
3004
  childCount: 1,
2922
3005
  className,
3006
+ name: id,
2923
3007
  role,
2924
3008
  title,
2925
3009
  type: Div
2926
- }, getIconVirtualDom(icon, Div, item.customIconClass)];
3010
+ }, {
3011
+ ...getIconVirtualDom(icon, Div, item.customIconClass),
3012
+ name: id
3013
+ }];
2927
3014
  }
2928
3015
 
2929
3016
  // TODO support progress on selected activity bar item
@@ -2939,6 +3026,7 @@ const getActivityBarItemVirtualDom = item => {
2939
3026
  ariaSelected,
2940
3027
  childCount: 0,
2941
3028
  className: mergeClassNames(className, getIconClass(item, 'Icon')),
3029
+ name: id,
2942
3030
  role,
2943
3031
  title,
2944
3032
  type: Div
@@ -3043,7 +3131,7 @@ const renderEventListeners = () => {
3043
3131
  preventDefault: true
3044
3132
  }, {
3045
3133
  name: HandleMouseDown,
3046
- params: ['handleClick', Button$1, ClientX, ClientY],
3134
+ params: ['handleClick', Button$1, ClientX, ClientY, TargetName],
3047
3135
  preventDefault: false,
3048
3136
  stopPropagation: false
3049
3137
  }];
@@ -3073,10 +3161,12 @@ const setAccountEnabled = (state, enabled) => {
3073
3161
  };
3074
3162
  };
3075
3163
 
3076
- const setUserLoginState = (state, userLoginState) => {
3164
+ const setUserLoginState = (state, userLoginState, userInfo) => {
3077
3165
  return {
3078
3166
  ...state,
3079
- userLoginState
3167
+ userLoginProvider: getUserLoginProvider(userInfo),
3168
+ userLoginState,
3169
+ userName: getUserName(userInfo)
3080
3170
  };
3081
3171
  };
3082
3172
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "7.5.0",
3
+ "version": "7.7.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",