@lvce-editor/activity-bar-worker 6.1.0 → 7.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.
@@ -1070,7 +1070,7 @@ const createMockRpc = ({
1070
1070
  };
1071
1071
 
1072
1072
  const rpcs = Object.create(null);
1073
- const set$3 = (id, rpc) => {
1073
+ const set$4 = (id, rpc) => {
1074
1074
  rpcs[id] = rpc;
1075
1075
  };
1076
1076
  const get$1 = id => {
@@ -1103,7 +1103,7 @@ const create$2 = rpcId => {
1103
1103
  const mockRpc = createMockRpc({
1104
1104
  commandMap
1105
1105
  });
1106
- set$3(rpcId, mockRpc);
1106
+ set$4(rpcId, mockRpc);
1107
1107
  // @ts-ignore
1108
1108
  mockRpc[Symbol.dispose] = () => {
1109
1109
  remove(rpcId);
@@ -1112,13 +1112,13 @@ const create$2 = rpcId => {
1112
1112
  return mockRpc;
1113
1113
  },
1114
1114
  set(rpc) {
1115
- set$3(rpcId, rpc);
1115
+ set$4(rpcId, rpc);
1116
1116
  }
1117
1117
  };
1118
1118
  };
1119
1119
 
1120
1120
  const {
1121
- set: set$2
1121
+ set: set$3
1122
1122
  } = create$2(6010);
1123
1123
 
1124
1124
  const Button$2 = 'button';
@@ -1156,6 +1156,7 @@ const LeftClick = 0;
1156
1156
 
1157
1157
  const Web = 1;
1158
1158
 
1159
+ const ExtensionManagementWorker = 9006;
1159
1160
  const RendererWorker = 1;
1160
1161
 
1161
1162
  const Left = 1;
@@ -1169,6 +1170,11 @@ const SetPatches = 'Viewlet.setPatches';
1169
1170
  const FocusActivityBar = 5;
1170
1171
  const FocusExplorer = 13;
1171
1172
 
1173
+ const {
1174
+ invoke: invoke$1,
1175
+ set: set$2
1176
+ } = create$2(ExtensionManagementWorker);
1177
+
1172
1178
  const {
1173
1179
  invoke,
1174
1180
  invokeAndTransfer,
@@ -1642,11 +1648,11 @@ const getNumberOfVisibleItems = state => {
1642
1648
  };
1643
1649
  const getHiddenItems = state => {
1644
1650
  const numberOfVisibleItems = getNumberOfVisibleItems(state);
1645
- const items = state.activityBarItems;
1651
+ const items = state.activityBarItems.filter(item => item.flags & Enabled);
1646
1652
  if (numberOfVisibleItems >= items.length) {
1647
1653
  return [];
1648
1654
  }
1649
- return state.activityBarItems.slice(numberOfVisibleItems - 2, -1);
1655
+ return items.slice(numberOfVisibleItems - 2, -1);
1650
1656
  };
1651
1657
 
1652
1658
  const toContextMenuItem = activityBarItem => {
@@ -1849,12 +1855,13 @@ const SourceControl$1 = 'SourceControl';
1849
1855
  const Ellipsis = 'Ellipsis';
1850
1856
 
1851
1857
  const getFilteredActivityBarItems = (items, height, itemHeight) => {
1858
+ const enabledItems = items.filter(item => item.flags & Enabled);
1852
1859
  const numberOfVisibleItems = getNumberOfVisibleItems({
1853
1860
  height,
1854
1861
  itemHeight
1855
1862
  });
1856
- if (numberOfVisibleItems >= items.length) {
1857
- return items;
1863
+ if (numberOfVisibleItems >= enabledItems.length) {
1864
+ return enabledItems;
1858
1865
  }
1859
1866
  const showMoreItem = {
1860
1867
  flags: Button,
@@ -1863,7 +1870,7 @@ const getFilteredActivityBarItems = (items, height, itemHeight) => {
1863
1870
  keyShortcuts: '',
1864
1871
  title: additionalViews()
1865
1872
  };
1866
- return [...items.slice(0, numberOfVisibleItems - 2), showMoreItem, items.at(-1)];
1873
+ return [...enabledItems.slice(0, numberOfVisibleItems - 2), showMoreItem, enabledItems.at(-1)];
1867
1874
  };
1868
1875
 
1869
1876
  const setFlag = (item, flag, enabled) => {
@@ -2001,42 +2008,14 @@ const handleContextMenu = async (state, button, eventX, eventY) => {
2001
2008
  return state;
2002
2009
  };
2003
2010
 
2004
- const handleFocus = state => {
2005
- return {
2006
- ...state,
2007
- focused: true
2008
- };
2009
- };
2010
-
2011
- const handleResize = (state, dimensions) => {
2012
- const {
2013
- activityBarItems,
2014
- itemHeight
2015
- } = state;
2016
- const {
2017
- height,
2018
- width,
2019
- x,
2020
- y
2021
- } = dimensions;
2022
- const filteredItems = getFilteredActivityBarItems(activityBarItems, height, itemHeight);
2023
- return {
2024
- ...state,
2025
- filteredItems,
2026
- height,
2027
- width,
2028
- x,
2029
- y
2030
- };
2031
- };
2011
+ const commandMap$1 = {};
2032
2012
 
2033
- const getAccountEnabled = async defaultValue => {
2034
- try {
2035
- const value = await invoke('Preferences.get', 'activityBar.accountEnabled');
2036
- return typeof value === 'boolean' ? value : defaultValue;
2037
- } catch {
2038
- return defaultValue;
2039
- }
2013
+ const handleExtensionManagementMessagePort = async port => {
2014
+ const rpc = await create$6({
2015
+ commandMap: commandMap$1,
2016
+ messagePort: port
2017
+ });
2018
+ set$2(rpc);
2040
2019
  };
2041
2020
 
2042
2021
  const Explorer = 'Explorer';
@@ -2045,7 +2024,16 @@ const RunAndDebug = 'Run And Debug';
2045
2024
  const Search = 'Search';
2046
2025
  const SourceControl = 'Source Control';
2047
2026
 
2048
- const getActivityBarItems = state => {
2027
+ const toActivityBarItem = view => {
2028
+ return {
2029
+ flags: Tab | Enabled,
2030
+ icon: view.icon || Extensions$1,
2031
+ id: view.id,
2032
+ keyShortcuts: '',
2033
+ title: view.title || view.id
2034
+ };
2035
+ };
2036
+ const getActivityBarItems = (state, contributedViews = []) => {
2049
2037
  const {
2050
2038
  accountEnabled
2051
2039
  } = state;
@@ -2082,7 +2070,7 @@ const getActivityBarItems = state => {
2082
2070
  id: Extensions,
2083
2071
  keyShortcuts: 'Control+Shift+X',
2084
2072
  title: extensions()
2085
- }
2073
+ }, ...contributedViews.map(toActivityBarItem)
2086
2074
  // Bottom
2087
2075
  ];
2088
2076
  if (accountEnabled) {
@@ -2104,6 +2092,70 @@ const getActivityBarItems = state => {
2104
2092
  return items;
2105
2093
  };
2106
2094
 
2095
+ const getContributedViews = async platform => {
2096
+ try {
2097
+ return await invoke$1('Extensions.getViews', '', platform);
2098
+ } catch {
2099
+ return [];
2100
+ }
2101
+ };
2102
+
2103
+ const handleExtensionsChanged = async state => {
2104
+ const {
2105
+ height,
2106
+ itemHeight,
2107
+ selectedIndex
2108
+ } = state;
2109
+ const contributedViews = await getContributedViews(state.platform);
2110
+ const items = getActivityBarItems(state, contributedViews);
2111
+ const itemsWithSelected = markSelected(items, selectedIndex);
2112
+ const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
2113
+ const newItems = await updateItemsWithBadgeCount(filteredItems);
2114
+ return {
2115
+ ...state,
2116
+ activityBarItems: itemsWithSelected,
2117
+ filteredItems: newItems
2118
+ };
2119
+ };
2120
+
2121
+ const handleFocus = state => {
2122
+ return {
2123
+ ...state,
2124
+ focused: true
2125
+ };
2126
+ };
2127
+
2128
+ const handleResize = (state, dimensions) => {
2129
+ const {
2130
+ activityBarItems,
2131
+ itemHeight
2132
+ } = state;
2133
+ const {
2134
+ height,
2135
+ width,
2136
+ x,
2137
+ y
2138
+ } = dimensions;
2139
+ const filteredItems = getFilteredActivityBarItems(activityBarItems, height, itemHeight);
2140
+ return {
2141
+ ...state,
2142
+ filteredItems,
2143
+ height,
2144
+ width,
2145
+ x,
2146
+ y
2147
+ };
2148
+ };
2149
+
2150
+ const getAccountEnabled = async defaultValue => {
2151
+ try {
2152
+ const value = await invoke('Preferences.get', 'activityBar.accountEnabled');
2153
+ return typeof value === 'boolean' ? value : defaultValue;
2154
+ } catch {
2155
+ return defaultValue;
2156
+ }
2157
+ };
2158
+
2107
2159
  const getSideBarPosition = async () => {
2108
2160
  try {
2109
2161
  return await invoke('Layout.getSideBarPosition');
@@ -2118,12 +2170,12 @@ const handleSettingsChanged = async state => {
2118
2170
  itemHeight,
2119
2171
  selectedIndex
2120
2172
  } = state;
2121
- const [accountEnabled, sidebarLocation] = await Promise.all([getAccountEnabled(state.accountEnabled), getSideBarPosition()]);
2173
+ const [accountEnabled, contributedViews, sidebarLocation] = await Promise.all([getAccountEnabled(state.accountEnabled), getContributedViews(state.platform), getSideBarPosition()]);
2122
2174
  const newState = {
2123
2175
  ...state,
2124
2176
  accountEnabled
2125
2177
  };
2126
- const items = getActivityBarItems(newState);
2178
+ const items = getActivityBarItems(newState, contributedViews);
2127
2179
  const itemsWithSelected = markSelected(items, selectedIndex);
2128
2180
  const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
2129
2181
  const newItems = await updateItemsWithBadgeCount(filteredItems);
@@ -2262,15 +2314,16 @@ const loadContent = async state => {
2262
2314
  const {
2263
2315
  accountEnabled,
2264
2316
  height,
2265
- itemHeight
2317
+ itemHeight,
2318
+ platform
2266
2319
  } = state;
2267
- const [accountEnabledNew, activeView, sideBarVisible, sidebarLocation, userInfo] = await Promise.all([getAccountEnabled(accountEnabled), getActiveView(), getSideBarVisible(), getSideBarPosition(), getUserInfo()]);
2320
+ const [accountEnabledNew, activeView, contributedViews, sideBarVisible, sidebarLocation, userInfo] = await Promise.all([getAccountEnabled(accountEnabled), getActiveView(), getContributedViews(platform), getSideBarVisible(), getSideBarPosition(), getUserInfo()]);
2268
2321
  const newState = {
2269
2322
  ...state,
2270
2323
  accountEnabled: accountEnabledNew,
2271
2324
  userLoginState: toUserLoginState(getUserState(userInfo))
2272
2325
  };
2273
- const items = getActivityBarItems(newState);
2326
+ const items = getActivityBarItems(newState, contributedViews);
2274
2327
  const index = items.findIndex(item => item.id === activeView);
2275
2328
  const selectedIndex = sideBarVisible ? index : -1;
2276
2329
  const itemsWithSelected = markSelected(items, selectedIndex);
@@ -2453,11 +2506,78 @@ const treeToArray = node => {
2453
2506
  return result;
2454
2507
  };
2455
2508
 
2509
+ const navigateToChild = (patches, currentChildIndex, index) => {
2510
+ if (currentChildIndex === -1) {
2511
+ patches.push({
2512
+ type: NavigateChild,
2513
+ index
2514
+ });
2515
+ return index;
2516
+ }
2517
+ if (currentChildIndex !== index) {
2518
+ patches.push({
2519
+ type: NavigateSibling,
2520
+ index
2521
+ });
2522
+ }
2523
+ return index;
2524
+ };
2525
+ const navigateToParent = (patches, currentChildIndex) => {
2526
+ if (currentChildIndex >= 0) {
2527
+ patches.push({
2528
+ type: NavigateParent
2529
+ });
2530
+ }
2531
+ return -1;
2532
+ };
2533
+ const addTree = (newNode, patches) => {
2534
+ patches.push({
2535
+ type: Add,
2536
+ nodes: treeToArray(newNode)
2537
+ });
2538
+ };
2539
+ const replaceTree = (newNode, patches) => {
2540
+ patches.push({
2541
+ type: Replace,
2542
+ nodes: treeToArray(newNode)
2543
+ });
2544
+ };
2545
+ const diffExistingChild = (oldNode, newNode, patches, currentChildIndex, index) => {
2546
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2547
+ if (nodePatches === null) {
2548
+ const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
2549
+ replaceTree(newNode, patches);
2550
+ return nextChildIndex;
2551
+ }
2552
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2553
+ if (nodePatches.length === 0 && !hasChildrenToCompare) {
2554
+ return currentChildIndex;
2555
+ }
2556
+ const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
2557
+ if (nodePatches.length > 0) {
2558
+ patches.push(...nodePatches);
2559
+ }
2560
+ if (hasChildrenToCompare) {
2561
+ diffChildren(oldNode.children, newNode.children, patches);
2562
+ }
2563
+ return nextChildIndex;
2564
+ };
2565
+ const diffRootNode = (oldNode, newNode, patches) => {
2566
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2567
+ if (nodePatches === null) {
2568
+ replaceTree(newNode, patches);
2569
+ return;
2570
+ }
2571
+ if (nodePatches.length > 0) {
2572
+ patches.push(...nodePatches);
2573
+ }
2574
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
2575
+ diffChildren(oldNode.children, newNode.children, patches);
2576
+ }
2577
+ };
2456
2578
  const diffChildren = (oldChildren, newChildren, patches) => {
2457
2579
  const maxLength = Math.max(oldChildren.length, newChildren.length);
2458
- // Track where we are: -1 means at parent, >= 0 means at child index
2459
2580
  let currentChildIndex = -1;
2460
- // Collect indices of children to remove (we'll add these patches at the end in reverse order)
2461
2581
  const indicesToRemove = [];
2462
2582
  for (let i = 0; i < maxLength; i++) {
2463
2583
  const oldNode = oldChildren[i];
@@ -2466,88 +2586,17 @@ const diffChildren = (oldChildren, newChildren, patches) => {
2466
2586
  continue;
2467
2587
  }
2468
2588
  if (!oldNode) {
2469
- // Add new node - we should be at the parent
2470
- if (currentChildIndex >= 0) {
2471
- // Navigate back to parent
2472
- patches.push({
2473
- type: NavigateParent
2474
- });
2475
- currentChildIndex = -1;
2476
- }
2477
- // Flatten the entire subtree so renderInternal can handle it
2478
- const flatNodes = treeToArray(newNode);
2479
- patches.push({
2480
- type: Add,
2481
- nodes: flatNodes
2482
- });
2483
- } else if (newNode) {
2484
- // Compare nodes to see if we need any patches
2485
- const nodePatches = compareNodes(oldNode.node, newNode.node);
2486
- // If nodePatches is null, the node types are incompatible - need to replace
2487
- if (nodePatches === null) {
2488
- // Navigate to this child
2489
- if (currentChildIndex === -1) {
2490
- patches.push({
2491
- type: NavigateChild,
2492
- index: i
2493
- });
2494
- currentChildIndex = i;
2495
- } else if (currentChildIndex !== i) {
2496
- patches.push({
2497
- type: NavigateSibling,
2498
- index: i
2499
- });
2500
- currentChildIndex = i;
2501
- }
2502
- // Replace the entire subtree
2503
- const flatNodes = treeToArray(newNode);
2504
- patches.push({
2505
- type: Replace,
2506
- nodes: flatNodes
2507
- });
2508
- // After replace, we're at the new element (same position)
2509
- continue;
2510
- }
2511
- // Check if we need to recurse into children
2512
- const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2513
- // Only navigate to this element if we need to do something
2514
- if (nodePatches.length > 0 || hasChildrenToCompare) {
2515
- // Navigate to this child if not already there
2516
- if (currentChildIndex === -1) {
2517
- patches.push({
2518
- type: NavigateChild,
2519
- index: i
2520
- });
2521
- currentChildIndex = i;
2522
- } else if (currentChildIndex !== i) {
2523
- patches.push({
2524
- type: NavigateSibling,
2525
- index: i
2526
- });
2527
- currentChildIndex = i;
2528
- }
2529
- // Apply node patches (these apply to the current element, not children)
2530
- if (nodePatches.length > 0) {
2531
- patches.push(...nodePatches);
2532
- }
2533
- // Compare children recursively
2534
- if (hasChildrenToCompare) {
2535
- diffChildren(oldNode.children, newNode.children, patches);
2536
- }
2537
- }
2538
- } else {
2539
- // Remove old node - collect the index for later removal
2589
+ currentChildIndex = navigateToParent(patches, currentChildIndex);
2590
+ addTree(newNode, patches);
2591
+ continue;
2592
+ }
2593
+ if (!newNode) {
2540
2594
  indicesToRemove.push(i);
2595
+ continue;
2541
2596
  }
2597
+ currentChildIndex = diffExistingChild(oldNode, newNode, patches, currentChildIndex, i);
2542
2598
  }
2543
- // Navigate back to parent if we ended at a child
2544
- if (currentChildIndex >= 0) {
2545
- patches.push({
2546
- type: NavigateParent
2547
- });
2548
- }
2549
- // Add remove patches in reverse order (highest index first)
2550
- // This ensures indices remain valid as we remove
2599
+ navigateToParent(patches, currentChildIndex);
2551
2600
  for (let j = indicesToRemove.length - 1; j >= 0; j--) {
2552
2601
  patches.push({
2553
2602
  type: RemoveChild,
@@ -2556,33 +2605,11 @@ const diffChildren = (oldChildren, newChildren, patches) => {
2556
2605
  }
2557
2606
  };
2558
2607
  const diffTrees = (oldTree, newTree, patches, path) => {
2559
- // At the root level (path.length === 0), we're already AT the element
2560
- // So we compare the root node directly, then compare its children
2561
2608
  if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
2562
- const oldNode = oldTree[0];
2563
- const newNode = newTree[0];
2564
- // Compare root nodes
2565
- const nodePatches = compareNodes(oldNode.node, newNode.node);
2566
- // If nodePatches is null, the root node types are incompatible - need to replace
2567
- if (nodePatches === null) {
2568
- const flatNodes = treeToArray(newNode);
2569
- patches.push({
2570
- type: Replace,
2571
- nodes: flatNodes
2572
- });
2573
- return;
2574
- }
2575
- if (nodePatches.length > 0) {
2576
- patches.push(...nodePatches);
2577
- }
2578
- // Compare children
2579
- if (oldNode.children.length > 0 || newNode.children.length > 0) {
2580
- diffChildren(oldNode.children, newNode.children, patches);
2581
- }
2582
- } else {
2583
- // Non-root level or multiple root elements - use the regular comparison
2584
- diffChildren(oldTree, newTree, patches);
2609
+ diffRootNode(oldTree[0], newTree[0], patches);
2610
+ return;
2585
2611
  }
2612
+ diffChildren(oldTree, newTree, patches);
2586
2613
  };
2587
2614
 
2588
2615
  const removeTrailingNavigationPatches = patches => {
@@ -2985,6 +3012,8 @@ const commandMap = {
2985
3012
  'ActivityBar.handleClickSignIn': wrapCommand(handleClickSignIn),
2986
3013
  'ActivityBar.handleClickSignOut': wrapCommand(handleClickSignOut),
2987
3014
  'ActivityBar.handleContextMenu': wrapCommand(handleContextMenu),
3015
+ 'ActivityBar.handleExtensionManagementMessagePort': handleExtensionManagementMessagePort,
3016
+ 'ActivityBar.handleExtensionsChanged': wrapCommand(handleExtensionsChanged),
2988
3017
  'ActivityBar.handleFocus': wrapCommand(handleFocus),
2989
3018
  'ActivityBar.handleSettingsChanged': wrapCommand(handleSettingsChanged),
2990
3019
  'ActivityBar.handleSideBarStateChange': wrapCommand(handleSideBarStateChange),
@@ -3009,7 +3038,7 @@ const initializeAuthWorker = async () => {
3009
3038
  commandMap: {},
3010
3039
  send
3011
3040
  });
3012
- set$2(rpc);
3041
+ set$3(rpc);
3013
3042
  };
3014
3043
 
3015
3044
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "6.1.0",
3
+ "version": "7.0.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",