@lvce-editor/activity-bar-worker 3.1.0 → 3.2.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.
@@ -933,9 +933,13 @@ const Web = 1;
933
933
 
934
934
  const RendererWorker = 1;
935
935
 
936
+ const Left = 1;
937
+ const Right = 2;
938
+
936
939
  const SetCss = 'Viewlet.setCss';
937
940
  const SetDom2 = 'Viewlet.setDom2';
938
941
  const SetFocusContext = 'Viewlet.setFocusContext';
942
+ const SetPatches = 'Viewlet.setPatches';
939
943
 
940
944
  const FocusActivityBar = 5;
941
945
  const FocusExplorer = 13;
@@ -1009,42 +1013,68 @@ const create$1 = () => {
1009
1013
  const states = Object.create(null);
1010
1014
  const commandMapRef = {};
1011
1015
  return {
1012
- get(uid) {
1013
- return states[uid];
1016
+ clear() {
1017
+ for (const key of Object.keys(states)) {
1018
+ delete states[key];
1019
+ }
1014
1020
  },
1015
- set(uid, oldState, newState) {
1016
- states[uid] = {
1017
- oldState,
1018
- newState
1019
- };
1021
+ diff(uid, modules, numbers) {
1022
+ const {
1023
+ newState,
1024
+ oldState
1025
+ } = states[uid];
1026
+ const diffResult = [];
1027
+ for (let i = 0; i < modules.length; i++) {
1028
+ const fn = modules[i];
1029
+ if (!fn(oldState, newState)) {
1030
+ diffResult.push(numbers[i]);
1031
+ }
1032
+ }
1033
+ return diffResult;
1020
1034
  },
1021
1035
  dispose(uid) {
1022
1036
  delete states[uid];
1023
1037
  },
1038
+ get(uid) {
1039
+ return states[uid];
1040
+ },
1041
+ getCommandIds() {
1042
+ const keys = Object.keys(commandMapRef);
1043
+ const ids = keys.map(toCommandId);
1044
+ return ids;
1045
+ },
1024
1046
  getKeys() {
1025
1047
  return Object.keys(states).map(key => {
1026
1048
  return Number.parseInt(key);
1027
1049
  });
1028
1050
  },
1029
- clear() {
1030
- for (const key of Object.keys(states)) {
1031
- delete states[key];
1032
- }
1051
+ registerCommands(commandMap) {
1052
+ Object.assign(commandMapRef, commandMap);
1053
+ },
1054
+ set(uid, oldState, newState) {
1055
+ states[uid] = {
1056
+ newState,
1057
+ oldState
1058
+ };
1033
1059
  },
1034
1060
  wrapCommand(fn) {
1035
1061
  const wrapped = async (uid, ...args) => {
1036
1062
  const {
1037
- oldState,
1038
- newState
1063
+ newState,
1064
+ oldState
1039
1065
  } = states[uid];
1040
1066
  const newerState = await fn(newState, ...args);
1041
1067
  if (oldState === newerState || newState === newerState) {
1042
1068
  return;
1043
1069
  }
1044
- const latest = states[uid];
1070
+ const latestOld = states[uid];
1071
+ const latestNew = {
1072
+ ...latestOld.newState,
1073
+ ...newerState
1074
+ };
1045
1075
  states[uid] = {
1046
- oldState: latest.oldState,
1047
- newState: newerState
1076
+ newState: latestNew,
1077
+ oldState: latestOld.oldState
1048
1078
  };
1049
1079
  };
1050
1080
  return wrapped;
@@ -1057,28 +1087,6 @@ const create$1 = () => {
1057
1087
  return fn(newState, ...args);
1058
1088
  };
1059
1089
  return wrapped;
1060
- },
1061
- diff(uid, modules, numbers) {
1062
- const {
1063
- oldState,
1064
- newState
1065
- } = states[uid];
1066
- const diffResult = [];
1067
- for (let i = 0; i < modules.length; i++) {
1068
- const fn = modules[i];
1069
- if (!fn(oldState, newState)) {
1070
- diffResult.push(numbers[i]);
1071
- }
1072
- }
1073
- return diffResult;
1074
- },
1075
- getCommandIds() {
1076
- const keys = Object.keys(commandMapRef);
1077
- const ids = keys.map(toCommandId);
1078
- return ids;
1079
- },
1080
- registerCommands(commandMap) {
1081
- Object.assign(commandMapRef, commandMap);
1082
1090
  }
1083
1091
  };
1084
1092
  };
@@ -1107,6 +1115,7 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) =>
1107
1115
  focused: false,
1108
1116
  focusedIndex: -1,
1109
1117
  height,
1118
+ initial: true,
1110
1119
  itemHeight: 48,
1111
1120
  numberOfVisibleItems: 0,
1112
1121
  platform,
@@ -1141,9 +1150,10 @@ const RenderItems = 4;
1141
1150
  const RenderFocus = 6;
1142
1151
  const RenderFocusContext = 7;
1143
1152
  const RenderCss = 11;
1153
+ const RenderIncremental = 12;
1144
1154
 
1145
1155
  const modules = [isEqual, isEqual$1, isEqual$1, isEqual$2];
1146
- const numbers = [RenderItems, RenderFocus, RenderFocusContext, RenderCss];
1156
+ const numbers = [RenderIncremental, RenderFocus, RenderFocusContext, RenderCss];
1147
1157
 
1148
1158
  const diff2 = uid => {
1149
1159
  return diff(uid, modules, numbers);
@@ -1244,14 +1254,6 @@ const getMenuEntriesAccount = state => {
1244
1254
  }];
1245
1255
  };
1246
1256
 
1247
- const Tab = 1;
1248
- const Button = 1 << 1;
1249
- const Progress = 1 << 2;
1250
- const Enabled = 1 << 3;
1251
- const Selected = 1 << 4;
1252
- const Focused = 1 << 5;
1253
- const MarginTop = 1 << 6;
1254
-
1255
1257
  const emptyObject = {};
1256
1258
  const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1257
1259
  const i18nString = (key, placeholders = emptyObject) => {
@@ -1330,9 +1332,6 @@ const colorTheme = () => {
1330
1332
  return i18nString(ColorTheme);
1331
1333
  };
1332
1334
 
1333
- const Left = 1;
1334
- const Right = 2;
1335
-
1336
1335
  const menuEntryMoveSideBar = sideBarLocation => {
1337
1336
  switch (sideBarLocation) {
1338
1337
  case Left:
@@ -1361,16 +1360,25 @@ const menuEntrySeparator = {
1361
1360
  label: ''
1362
1361
  };
1363
1362
 
1363
+ const Tab = 1;
1364
+ const Button = 1 << 1;
1365
+ const Progress = 1 << 2;
1366
+ const Enabled = 1 << 3;
1367
+ const Selected = 1 << 4;
1368
+ const Focused = 1 << 5;
1369
+ const MarginTop = 1 << 6;
1370
+
1364
1371
  const toContextMenuItem$1 = activityBarItem => {
1365
1372
  const isEnabled = activityBarItem.flags & Enabled;
1366
1373
  return {
1367
- command: '',
1374
+ args: [activityBarItem.id],
1375
+ command: 'ActivityBar.toggleActivityBarItem',
1368
1376
  flags: isEnabled ? Checked : Unchecked,
1369
- id: '',
1370
- // TODO
1377
+ id: `toggle-${activityBarItem.id}`,
1371
1378
  label: activityBarItem.id
1372
1379
  };
1373
1380
  };
1381
+
1374
1382
  const getMenuEntriesActivityBar = state => {
1375
1383
  const {
1376
1384
  activityBarItems,
@@ -1702,6 +1710,78 @@ const handleResize = (state, dimensions) => {
1702
1710
  };
1703
1711
  };
1704
1712
 
1713
+ const Explorer = 'Explorer';
1714
+ const Extensions = 'Extensions';
1715
+ const RunAndDebug = 'Run And Debug';
1716
+ const Search = 'Search';
1717
+ const SourceControl = 'Source Control';
1718
+
1719
+ const getActivityBarItems = state => {
1720
+ const {
1721
+ accountEnabled
1722
+ } = state;
1723
+ const items = [
1724
+ // Top
1725
+ {
1726
+ flags: Tab | Enabled,
1727
+ icon: Files,
1728
+ id: Explorer,
1729
+ keyShortcuts: 'Control+Shift+E',
1730
+ title: explorer()
1731
+ }, {
1732
+ flags: Tab | Enabled,
1733
+ icon: Search$1,
1734
+ id: Search,
1735
+ keyShortcuts: 'Control+Shift+F',
1736
+ title: search()
1737
+ }, {
1738
+ flags: Tab | Enabled,
1739
+ icon: SourceControl$1,
1740
+ id: SourceControl,
1741
+ keyShortcuts: 'Control+Shift+G',
1742
+ title: sourceControl()
1743
+ }, {
1744
+ flags: Tab | Enabled,
1745
+ icon: DebugAlt2,
1746
+ id: RunAndDebug,
1747
+ keyShortcuts: 'Control+Shift+D',
1748
+ title: runAndDebug()
1749
+ }, {
1750
+ flags: Tab | Enabled,
1751
+ icon: Extensions$1,
1752
+ id: Extensions,
1753
+ keyShortcuts: 'Control+Shift+X',
1754
+ title: extensions()
1755
+ }
1756
+ // Bottom
1757
+ ];
1758
+ if (accountEnabled) {
1759
+ items.push({
1760
+ flags: Button | Enabled | MarginTop,
1761
+ icon: Account,
1762
+ id: 'Account',
1763
+ keyShortcuts: '',
1764
+ title: account()
1765
+ });
1766
+ }
1767
+ items.push({
1768
+ flags: Button | Enabled | MarginTop,
1769
+ icon: SettingsGear,
1770
+ id: 'Settings',
1771
+ keyShortcuts: '',
1772
+ title: settings()
1773
+ });
1774
+ return items;
1775
+ };
1776
+
1777
+ const getSideBarPosition = async () => {
1778
+ try {
1779
+ return await invoke('Layout.getSideBarPosition');
1780
+ } catch {
1781
+ return Left;
1782
+ }
1783
+ };
1784
+
1705
1785
  const setFlag = (item, flag, enabled) => {
1706
1786
  return {
1707
1787
  ...item,
@@ -1709,6 +1789,32 @@ const setFlag = (item, flag, enabled) => {
1709
1789
  };
1710
1790
  };
1711
1791
 
1792
+ const markSelected = (items, selectedIndex) => {
1793
+ return items.map((item, index) => {
1794
+ const isSelected = index === selectedIndex;
1795
+ return setFlag(item, Selected, isSelected);
1796
+ });
1797
+ };
1798
+
1799
+ const handleSettingsChanged = async state => {
1800
+ const {
1801
+ height,
1802
+ itemHeight,
1803
+ selectedIndex
1804
+ } = state;
1805
+ const items = getActivityBarItems(state);
1806
+ const itemsWithSelected = markSelected(items, selectedIndex);
1807
+ const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
1808
+ const newItems = await updateItemsWithBadgeCount(filteredItems);
1809
+ const sidebarLocation = await getSideBarPosition();
1810
+ return {
1811
+ ...state,
1812
+ activityBarItems: itemsWithSelected,
1813
+ filteredItems: newItems,
1814
+ sideBarLocation: sidebarLocation
1815
+ };
1816
+ };
1817
+
1712
1818
  const handleSideBarHidden = state => {
1713
1819
  const itemsCleared = state.activityBarItems.map(item => {
1714
1820
  const withoutSelected = setFlag(item, Selected, false);
@@ -1732,13 +1838,6 @@ const findIndex = (activityBarItems, id) => {
1732
1838
  return -1;
1733
1839
  };
1734
1840
 
1735
- const markSelected = (items, selectedIndex) => {
1736
- return items.map((item, index) => {
1737
- const isSelected = index === selectedIndex;
1738
- return setFlag(item, Selected, isSelected);
1739
- });
1740
- };
1741
-
1742
1841
  const handleSideBarViewletChange = (state, id, ...args) => {
1743
1842
  const {
1744
1843
  activityBarItems,
@@ -1796,12 +1895,6 @@ const handleUpdateStateChange = async (state, config) => {
1796
1895
  };
1797
1896
  };
1798
1897
 
1799
- const Explorer = 'Explorer';
1800
- const Extensions = 'Extensions';
1801
- const RunAndDebug = 'Run And Debug';
1802
- const Search = 'Search';
1803
- const SourceControl = 'Source Control';
1804
-
1805
1898
  const getActiveView = async () => {
1806
1899
  try {
1807
1900
  const activeView = await invoke('Layout.getActiveSideBarView');
@@ -1811,65 +1904,7 @@ const getActiveView = async () => {
1811
1904
  }
1812
1905
  };
1813
1906
 
1814
- const getActivityBarItems = state => {
1815
- const {
1816
- accountEnabled
1817
- } = state;
1818
- const items = [
1819
- // Top
1820
- {
1821
- flags: Tab | Enabled,
1822
- icon: Files,
1823
- id: Explorer,
1824
- keyShortcuts: 'Control+Shift+E',
1825
- title: explorer()
1826
- }, {
1827
- flags: Tab | Enabled,
1828
- icon: Search$1,
1829
- id: Search,
1830
- keyShortcuts: 'Control+Shift+F',
1831
- title: search()
1832
- }, {
1833
- flags: Tab | Enabled,
1834
- icon: SourceControl$1,
1835
- id: SourceControl,
1836
- keyShortcuts: 'Control+Shift+G',
1837
- title: sourceControl()
1838
- }, {
1839
- flags: Tab | Enabled,
1840
- icon: DebugAlt2,
1841
- id: RunAndDebug,
1842
- keyShortcuts: 'Control+Shift+D',
1843
- title: runAndDebug()
1844
- }, {
1845
- flags: Tab | Enabled,
1846
- icon: Extensions$1,
1847
- id: Extensions,
1848
- keyShortcuts: 'Control+Shift+X',
1849
- title: extensions()
1850
- }
1851
- // Bottom
1852
- ];
1853
- if (accountEnabled) {
1854
- items.push({
1855
- flags: Button | Enabled | MarginTop,
1856
- icon: Account,
1857
- id: 'Account',
1858
- keyShortcuts: '',
1859
- title: account()
1860
- });
1861
- }
1862
- items.push({
1863
- flags: Button | Enabled | MarginTop,
1864
- icon: SettingsGear,
1865
- id: 'Settings',
1866
- keyShortcuts: '',
1867
- title: settings()
1868
- });
1869
- return items;
1870
- };
1871
-
1872
- const loadContent = async (state, savedState) => {
1907
+ const loadContent = async state => {
1873
1908
  const {
1874
1909
  height,
1875
1910
  itemHeight
@@ -1880,13 +1915,15 @@ const loadContent = async (state, savedState) => {
1880
1915
  const itemsWithSelected = markSelected(items, index);
1881
1916
  const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
1882
1917
  const newItems = await updateItemsWithBadgeCount(filteredItems);
1918
+ const sidebarLocation = await getSideBarPosition();
1883
1919
  return {
1884
1920
  ...state,
1885
1921
  activityBarItems: itemsWithSelected,
1886
1922
  currentViewletId: Explorer,
1887
1923
  filteredItems: newItems,
1924
+ initial: false,
1888
1925
  selectedIndex: index,
1889
- sideBarLocation: Left,
1926
+ sideBarLocation: sidebarLocation,
1890
1927
  sideBarVisible: true
1891
1928
  };
1892
1929
  };
@@ -1926,6 +1963,283 @@ const text = data => {
1926
1963
  };
1927
1964
  };
1928
1965
 
1966
+ const SetText = 1;
1967
+ const Replace = 2;
1968
+ const SetAttribute = 3;
1969
+ const RemoveAttribute = 4;
1970
+ const Add = 6;
1971
+ const NavigateChild = 7;
1972
+ const NavigateParent = 8;
1973
+ const RemoveChild = 9;
1974
+ const NavigateSibling = 10;
1975
+
1976
+ const isKey = key => {
1977
+ return key !== 'type' && key !== 'childCount';
1978
+ };
1979
+
1980
+ const getKeys = node => {
1981
+ const keys = Object.keys(node).filter(isKey);
1982
+ return keys;
1983
+ };
1984
+
1985
+ const arrayToTree = nodes => {
1986
+ const result = [];
1987
+ let i = 0;
1988
+ while (i < nodes.length) {
1989
+ const node = nodes[i];
1990
+ const {
1991
+ children,
1992
+ nodesConsumed
1993
+ } = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
1994
+ result.push({
1995
+ node,
1996
+ children
1997
+ });
1998
+ i += 1 + nodesConsumed;
1999
+ }
2000
+ return result;
2001
+ };
2002
+ const getChildrenWithCount = (nodes, startIndex, childCount) => {
2003
+ if (childCount === 0) {
2004
+ return {
2005
+ children: [],
2006
+ nodesConsumed: 0
2007
+ };
2008
+ }
2009
+ const children = [];
2010
+ let i = startIndex;
2011
+ let remaining = childCount;
2012
+ let totalConsumed = 0;
2013
+ while (remaining > 0 && i < nodes.length) {
2014
+ const node = nodes[i];
2015
+ const nodeChildCount = node.childCount || 0;
2016
+ const {
2017
+ children: nodeChildren,
2018
+ nodesConsumed
2019
+ } = getChildrenWithCount(nodes, i + 1, nodeChildCount);
2020
+ children.push({
2021
+ node,
2022
+ children: nodeChildren
2023
+ });
2024
+ const nodeSize = 1 + nodesConsumed;
2025
+ i += nodeSize;
2026
+ totalConsumed += nodeSize;
2027
+ remaining--;
2028
+ }
2029
+ return {
2030
+ children,
2031
+ nodesConsumed: totalConsumed
2032
+ };
2033
+ };
2034
+
2035
+ const compareNodes = (oldNode, newNode) => {
2036
+ const patches = [];
2037
+ // Check if node type changed - return null to signal incompatible nodes
2038
+ // (caller should handle this with a Replace operation)
2039
+ if (oldNode.type !== newNode.type) {
2040
+ return null;
2041
+ }
2042
+ // Handle text nodes
2043
+ if (oldNode.type === Text && newNode.type === Text) {
2044
+ if (oldNode.text !== newNode.text) {
2045
+ patches.push({
2046
+ type: SetText,
2047
+ value: newNode.text
2048
+ });
2049
+ }
2050
+ return patches;
2051
+ }
2052
+ // Compare attributes
2053
+ const oldKeys = getKeys(oldNode);
2054
+ const newKeys = getKeys(newNode);
2055
+ // Check for attribute changes
2056
+ for (const key of newKeys) {
2057
+ if (oldNode[key] !== newNode[key]) {
2058
+ patches.push({
2059
+ type: SetAttribute,
2060
+ key,
2061
+ value: newNode[key]
2062
+ });
2063
+ }
2064
+ }
2065
+ // Check for removed attributes
2066
+ for (const key of oldKeys) {
2067
+ if (!(key in newNode)) {
2068
+ patches.push({
2069
+ type: RemoveAttribute,
2070
+ key
2071
+ });
2072
+ }
2073
+ }
2074
+ return patches;
2075
+ };
2076
+
2077
+ const treeToArray = node => {
2078
+ const result = [node.node];
2079
+ for (const child of node.children) {
2080
+ result.push(...treeToArray(child));
2081
+ }
2082
+ return result;
2083
+ };
2084
+
2085
+ const diffChildren = (oldChildren, newChildren, patches) => {
2086
+ const maxLength = Math.max(oldChildren.length, newChildren.length);
2087
+ // Track where we are: -1 means at parent, >= 0 means at child index
2088
+ let currentChildIndex = -1;
2089
+ // Collect indices of children to remove (we'll add these patches at the end in reverse order)
2090
+ const indicesToRemove = [];
2091
+ for (let i = 0; i < maxLength; i++) {
2092
+ const oldNode = oldChildren[i];
2093
+ const newNode = newChildren[i];
2094
+ if (!oldNode && !newNode) {
2095
+ continue;
2096
+ }
2097
+ if (!oldNode) {
2098
+ // Add new node - we should be at the parent
2099
+ if (currentChildIndex >= 0) {
2100
+ // Navigate back to parent
2101
+ patches.push({
2102
+ type: NavigateParent
2103
+ });
2104
+ currentChildIndex = -1;
2105
+ }
2106
+ // Flatten the entire subtree so renderInternal can handle it
2107
+ const flatNodes = treeToArray(newNode);
2108
+ patches.push({
2109
+ type: Add,
2110
+ nodes: flatNodes
2111
+ });
2112
+ } else if (newNode) {
2113
+ // Compare nodes to see if we need any patches
2114
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2115
+ // If nodePatches is null, the node types are incompatible - need to replace
2116
+ if (nodePatches === null) {
2117
+ // Navigate to this child
2118
+ if (currentChildIndex === -1) {
2119
+ patches.push({
2120
+ type: NavigateChild,
2121
+ index: i
2122
+ });
2123
+ currentChildIndex = i;
2124
+ } else if (currentChildIndex !== i) {
2125
+ patches.push({
2126
+ type: NavigateSibling,
2127
+ index: i
2128
+ });
2129
+ currentChildIndex = i;
2130
+ }
2131
+ // Replace the entire subtree
2132
+ const flatNodes = treeToArray(newNode);
2133
+ patches.push({
2134
+ type: Replace,
2135
+ nodes: flatNodes
2136
+ });
2137
+ // After replace, we're at the new element (same position)
2138
+ continue;
2139
+ }
2140
+ // Check if we need to recurse into children
2141
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2142
+ // Only navigate to this element if we need to do something
2143
+ if (nodePatches.length > 0 || hasChildrenToCompare) {
2144
+ // Navigate to this child if not already there
2145
+ if (currentChildIndex === -1) {
2146
+ patches.push({
2147
+ type: NavigateChild,
2148
+ index: i
2149
+ });
2150
+ currentChildIndex = i;
2151
+ } else if (currentChildIndex !== i) {
2152
+ patches.push({
2153
+ type: NavigateSibling,
2154
+ index: i
2155
+ });
2156
+ currentChildIndex = i;
2157
+ }
2158
+ // Apply node patches (these apply to the current element, not children)
2159
+ if (nodePatches.length > 0) {
2160
+ patches.push(...nodePatches);
2161
+ }
2162
+ // Compare children recursively
2163
+ if (hasChildrenToCompare) {
2164
+ diffChildren(oldNode.children, newNode.children, patches);
2165
+ }
2166
+ }
2167
+ } else {
2168
+ // Remove old node - collect the index for later removal
2169
+ indicesToRemove.push(i);
2170
+ }
2171
+ }
2172
+ // Navigate back to parent if we ended at a child
2173
+ if (currentChildIndex >= 0) {
2174
+ patches.push({
2175
+ type: NavigateParent
2176
+ });
2177
+ currentChildIndex = -1;
2178
+ }
2179
+ // Add remove patches in reverse order (highest index first)
2180
+ // This ensures indices remain valid as we remove
2181
+ for (let j = indicesToRemove.length - 1; j >= 0; j--) {
2182
+ patches.push({
2183
+ type: RemoveChild,
2184
+ index: indicesToRemove[j]
2185
+ });
2186
+ }
2187
+ };
2188
+ const diffTrees = (oldTree, newTree, patches, path) => {
2189
+ // At the root level (path.length === 0), we're already AT the element
2190
+ // So we compare the root node directly, then compare its children
2191
+ if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
2192
+ const oldNode = oldTree[0];
2193
+ const newNode = newTree[0];
2194
+ // Compare root nodes
2195
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2196
+ // If nodePatches is null, the root node types are incompatible - need to replace
2197
+ if (nodePatches === null) {
2198
+ const flatNodes = treeToArray(newNode);
2199
+ patches.push({
2200
+ type: Replace,
2201
+ nodes: flatNodes
2202
+ });
2203
+ return;
2204
+ }
2205
+ if (nodePatches.length > 0) {
2206
+ patches.push(...nodePatches);
2207
+ }
2208
+ // Compare children
2209
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
2210
+ diffChildren(oldNode.children, newNode.children, patches);
2211
+ }
2212
+ } else {
2213
+ // Non-root level or multiple root elements - use the regular comparison
2214
+ diffChildren(oldTree, newTree, patches);
2215
+ }
2216
+ };
2217
+
2218
+ const removeTrailingNavigationPatches = patches => {
2219
+ // Find the last non-navigation patch
2220
+ let lastNonNavigationIndex = -1;
2221
+ for (let i = patches.length - 1; i >= 0; i--) {
2222
+ const patch = patches[i];
2223
+ if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
2224
+ lastNonNavigationIndex = i;
2225
+ break;
2226
+ }
2227
+ }
2228
+ // Return patches up to and including the last non-navigation patch
2229
+ return lastNonNavigationIndex === -1 ? [] : patches.slice(0, lastNonNavigationIndex + 1);
2230
+ };
2231
+
2232
+ const diffTree = (oldNodes, newNodes) => {
2233
+ // Step 1: Convert flat arrays to tree structures
2234
+ const oldTree = arrayToTree(oldNodes);
2235
+ const newTree = arrayToTree(newNodes);
2236
+ // Step 3: Compare the trees
2237
+ const patches = [];
2238
+ diffTrees(oldTree, newTree, patches, []);
2239
+ // Remove trailing navigation patches since they serve no purpose
2240
+ return removeTrailingNavigationPatches(patches);
2241
+ };
2242
+
1929
2243
  const Vertical = 'vertical';
1930
2244
 
1931
2245
  const ActivityBar$1 = 'ActivityBar';
@@ -2134,12 +2448,23 @@ const getActivityBarVirtualDom = visibleItems => {
2134
2448
  const renderItems = (oldState, newState) => {
2135
2449
  const {
2136
2450
  filteredItems,
2451
+ initial,
2137
2452
  uid
2138
2453
  } = newState;
2454
+ if (initial) {
2455
+ return [SetDom2, uid, []];
2456
+ }
2139
2457
  const dom = getActivityBarVirtualDom(filteredItems);
2140
2458
  return [SetDom2, uid, dom];
2141
2459
  };
2142
2460
 
2461
+ const renderIncremental = (oldState, newState) => {
2462
+ const oldDom = renderItems(oldState, oldState)[2];
2463
+ const newDom = renderItems(newState, newState)[2];
2464
+ const patches = diffTree(oldDom, newDom);
2465
+ return [SetPatches, newState.uid, patches];
2466
+ };
2467
+
2143
2468
  const getRenderer = diffType => {
2144
2469
  switch (diffType) {
2145
2470
  case RenderCss:
@@ -2148,6 +2473,8 @@ const getRenderer = diffType => {
2148
2473
  return renderFocusContext;
2149
2474
  case RenderFocusContext:
2150
2475
  return renderFocusContext;
2476
+ case RenderIncremental:
2477
+ return renderIncremental;
2151
2478
  case RenderItems:
2152
2479
  return renderItems;
2153
2480
  default:
@@ -2198,25 +2525,50 @@ const renderEventListeners = () => {
2198
2525
 
2199
2526
  const saveState = state => {
2200
2527
  const {
2201
- currentViewletId,
2202
- uid
2528
+ currentViewletId
2203
2529
  } = state;
2204
2530
  return {
2205
- currentViewletId,
2206
- uid
2531
+ currentViewletId
2207
2532
  };
2208
2533
  };
2209
2534
 
2210
- const isEnabled = activityBarItem => {
2211
- return activityBarItem.enabled;
2535
+ const setAccountEnabled = (state, enabled) => {
2536
+ const {
2537
+ height,
2538
+ itemHeight,
2539
+ selectedIndex
2540
+ } = state;
2541
+ const newState = {
2542
+ ...state,
2543
+ accountEnabled: enabled
2544
+ };
2545
+ const newActivityBarItems = getActivityBarItems(newState);
2546
+ const markedItems = markSelected(newActivityBarItems, selectedIndex);
2547
+ const filteredItems = getFilteredActivityBarItems(markedItems, height, itemHeight);
2548
+ return {
2549
+ ...newState,
2550
+ activityBarItems: markedItems,
2551
+ filteredItems: filteredItems
2552
+ };
2212
2553
  };
2213
- const toggleActivityBarItem = async (state, item) => {
2214
- const activityBarItem = state.activityBarItems.find(activityBarItem => activityBarItem.id === item.label);
2215
- // @ts-ignore
2216
- activityBarItem.enabled = !activityBarItem.enabled;
2554
+
2555
+ const toggleActivityBarItem = async (state, itemId) => {
2556
+ const {
2557
+ activityBarItems
2558
+ } = state;
2559
+ const updatedItems = activityBarItems.map(item => {
2560
+ if (item.id === itemId) {
2561
+ const isCurrentlyEnabled = item.flags & Enabled;
2562
+ return {
2563
+ ...item,
2564
+ flags: isCurrentlyEnabled ? item.flags & -9 : item.flags | Enabled
2565
+ };
2566
+ }
2567
+ return item;
2568
+ });
2217
2569
  return {
2218
2570
  ...state,
2219
- activityBarItems: state.activityBarItems.filter(isEnabled)
2571
+ activityBarItems: updatedItems
2220
2572
  };
2221
2573
  };
2222
2574
 
@@ -2238,6 +2590,7 @@ const commandMap = {
2238
2590
  'ActivityBar.handleClick': wrapCommand(handleClick),
2239
2591
  'ActivityBar.handleClickIndex': wrapCommand(handleClickIndex),
2240
2592
  'ActivityBar.handleContextMenu': wrapCommand(handleContextMenu),
2593
+ 'ActivityBar.handleSettingsChanged': wrapCommand(handleSettingsChanged),
2241
2594
  'ActivityBar.handleSideBarHidden': wrapCommand(handleSideBarHidden),
2242
2595
  'ActivityBar.handleSideBarViewletChange': wrapCommand(handleSideBarViewletChange),
2243
2596
  'ActivityBar.handleUpdateStateChange': wrapCommand(handleUpdateStateChange),
@@ -2246,6 +2599,7 @@ const commandMap = {
2246
2599
  'ActivityBar.renderEventListeners': renderEventListeners,
2247
2600
  'ActivityBar.resize': wrapCommand(handleResize),
2248
2601
  'ActivityBar.saveState': wrapGetter(saveState),
2602
+ 'ActivityBar.setAccountEnabled': wrapCommand(setAccountEnabled),
2249
2603
  'ActivityBar.terminate': terminate,
2250
2604
  'ActivityBar.toggleActivityBarItem': wrapCommand(toggleActivityBarItem)
2251
2605
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",