@lvce-editor/activity-bar-worker 3.1.0 → 3.3.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.
@@ -613,7 +613,7 @@ const getErrorProperty = (error, prettyError) => {
613
613
  }
614
614
  };
615
615
  };
616
- const create$1$2 = (id, error) => {
616
+ const create$1$1 = (id, error) => {
617
617
  return {
618
618
  jsonrpc: Two$1,
619
619
  id,
@@ -624,7 +624,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
624
624
  const prettyError = preparePrettyError(error);
625
625
  logError(error, prettyError);
626
626
  const errorProperty = getErrorProperty(error, prettyError);
627
- return create$1$2(id, errorProperty);
627
+ return create$1$1(id, errorProperty);
628
628
  };
629
629
  const create$3 = (message, result) => {
630
630
  return {
@@ -749,14 +749,14 @@ const execute = (command, ...args) => {
749
749
  };
750
750
 
751
751
  const Two = '2.0';
752
- const create$s = (method, params) => {
752
+ const create$t = (method, params) => {
753
753
  return {
754
754
  jsonrpc: Two,
755
755
  method,
756
756
  params
757
757
  };
758
758
  };
759
- const create$r = (id, method, params) => {
759
+ const create$s = (id, method, params) => {
760
760
  const message = {
761
761
  id,
762
762
  jsonrpc: Two,
@@ -766,14 +766,14 @@ const create$r = (id, method, params) => {
766
766
  return message;
767
767
  };
768
768
  let id = 0;
769
- const create$q = () => {
769
+ const create$r = () => {
770
770
  return ++id;
771
771
  };
772
772
 
773
773
  /* eslint-disable n/no-unsupported-features/es-syntax */
774
774
 
775
775
  const registerPromise = map => {
776
- const id = create$q();
776
+ const id = create$r();
777
777
  const {
778
778
  promise,
779
779
  resolve
@@ -791,7 +791,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
791
791
  id,
792
792
  promise
793
793
  } = registerPromise(callbacks);
794
- const message = create$r(id, method, params);
794
+ const message = create$s(id, method, params);
795
795
  if (useSendAndTransfer && ipc.sendAndTransfer) {
796
796
  ipc.sendAndTransfer(message);
797
797
  } else {
@@ -827,7 +827,7 @@ const createRpc = ipc => {
827
827
  * @deprecated
828
828
  */
829
829
  send(method, ...params) {
830
- const message = create$s(method, params);
830
+ const message = create$t(method, params);
831
831
  ipc.send(message);
832
832
  }
833
833
  };
@@ -863,7 +863,7 @@ const listen$1 = async (module, options) => {
863
863
  const ipc = module.wrap(rawIpc);
864
864
  return ipc;
865
865
  };
866
- const create$1$1 = async ({
866
+ const create$2$1 = async ({
867
867
  commandMap
868
868
  }) => {
869
869
  // TODO create a commandMap per rpc instance
@@ -875,7 +875,7 @@ const create$1$1 = async ({
875
875
  };
876
876
  const WebWorkerRpcClient = {
877
877
  __proto__: null,
878
- create: create$1$1
878
+ create: create$2$1
879
879
  };
880
880
  const createMockRpc = ({
881
881
  commandMap
@@ -904,6 +904,7 @@ const ToolBar = 'toolbar';
904
904
 
905
905
  const Div = 4;
906
906
  const Text = 12;
907
+ const Reference = 100;
907
908
 
908
909
  const Button$1 = 'event.button';
909
910
  const ClientX = 'event.clientX';
@@ -933,9 +934,13 @@ const Web = 1;
933
934
 
934
935
  const RendererWorker = 1;
935
936
 
937
+ const Left = 1;
938
+ const Right = 2;
939
+
936
940
  const SetCss = 'Viewlet.setCss';
937
941
  const SetDom2 = 'Viewlet.setDom2';
938
942
  const SetFocusContext = 'Viewlet.setFocusContext';
943
+ const SetPatches = 'Viewlet.setPatches';
939
944
 
940
945
  const FocusActivityBar = 5;
941
946
  const FocusExplorer = 13;
@@ -997,7 +1002,6 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
997
1002
  number(menuId);
998
1003
  number(x);
999
1004
  number(y);
1000
- // @ts-ignore
1001
1005
  await invoke('ContextMenu.show2', uid, menuId, x, y, args);
1002
1006
  };
1003
1007
 
@@ -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,294 @@ 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
+ const SetReferenceNodeUid = 11;
1976
+
1977
+ const isKey = key => {
1978
+ return key !== 'type' && key !== 'childCount';
1979
+ };
1980
+
1981
+ const getKeys = node => {
1982
+ const keys = Object.keys(node).filter(isKey);
1983
+ return keys;
1984
+ };
1985
+
1986
+ const arrayToTree = nodes => {
1987
+ const result = [];
1988
+ let i = 0;
1989
+ while (i < nodes.length) {
1990
+ const node = nodes[i];
1991
+ const {
1992
+ children,
1993
+ nodesConsumed
1994
+ } = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
1995
+ result.push({
1996
+ node,
1997
+ children
1998
+ });
1999
+ i += 1 + nodesConsumed;
2000
+ }
2001
+ return result;
2002
+ };
2003
+ const getChildrenWithCount = (nodes, startIndex, childCount) => {
2004
+ if (childCount === 0) {
2005
+ return {
2006
+ children: [],
2007
+ nodesConsumed: 0
2008
+ };
2009
+ }
2010
+ const children = [];
2011
+ let i = startIndex;
2012
+ let remaining = childCount;
2013
+ let totalConsumed = 0;
2014
+ while (remaining > 0 && i < nodes.length) {
2015
+ const node = nodes[i];
2016
+ const nodeChildCount = node.childCount || 0;
2017
+ const {
2018
+ children: nodeChildren,
2019
+ nodesConsumed
2020
+ } = getChildrenWithCount(nodes, i + 1, nodeChildCount);
2021
+ children.push({
2022
+ node,
2023
+ children: nodeChildren
2024
+ });
2025
+ const nodeSize = 1 + nodesConsumed;
2026
+ i += nodeSize;
2027
+ totalConsumed += nodeSize;
2028
+ remaining--;
2029
+ }
2030
+ return {
2031
+ children,
2032
+ nodesConsumed: totalConsumed
2033
+ };
2034
+ };
2035
+
2036
+ const compareNodes = (oldNode, newNode) => {
2037
+ const patches = [];
2038
+ // Check if node type changed - return null to signal incompatible nodes
2039
+ // (caller should handle this with a Replace operation)
2040
+ if (oldNode.type !== newNode.type) {
2041
+ return null;
2042
+ }
2043
+ // Handle reference nodes - special handling for uid changes
2044
+ if (oldNode.type === Reference) {
2045
+ if (oldNode.uid !== newNode.uid) {
2046
+ patches.push({
2047
+ type: SetReferenceNodeUid,
2048
+ uid: newNode.uid
2049
+ });
2050
+ }
2051
+ return patches;
2052
+ }
2053
+ // Handle text nodes
2054
+ if (oldNode.type === Text && newNode.type === Text) {
2055
+ if (oldNode.text !== newNode.text) {
2056
+ patches.push({
2057
+ type: SetText,
2058
+ value: newNode.text
2059
+ });
2060
+ }
2061
+ return patches;
2062
+ }
2063
+ // Compare attributes
2064
+ const oldKeys = getKeys(oldNode);
2065
+ const newKeys = getKeys(newNode);
2066
+ // Check for attribute changes
2067
+ for (const key of newKeys) {
2068
+ if (oldNode[key] !== newNode[key]) {
2069
+ patches.push({
2070
+ type: SetAttribute,
2071
+ key,
2072
+ value: newNode[key]
2073
+ });
2074
+ }
2075
+ }
2076
+ // Check for removed attributes
2077
+ for (const key of oldKeys) {
2078
+ if (!(key in newNode)) {
2079
+ patches.push({
2080
+ type: RemoveAttribute,
2081
+ key
2082
+ });
2083
+ }
2084
+ }
2085
+ return patches;
2086
+ };
2087
+
2088
+ const treeToArray = node => {
2089
+ const result = [node.node];
2090
+ for (const child of node.children) {
2091
+ result.push(...treeToArray(child));
2092
+ }
2093
+ return result;
2094
+ };
2095
+
2096
+ const diffChildren = (oldChildren, newChildren, patches) => {
2097
+ const maxLength = Math.max(oldChildren.length, newChildren.length);
2098
+ // Track where we are: -1 means at parent, >= 0 means at child index
2099
+ let currentChildIndex = -1;
2100
+ // Collect indices of children to remove (we'll add these patches at the end in reverse order)
2101
+ const indicesToRemove = [];
2102
+ for (let i = 0; i < maxLength; i++) {
2103
+ const oldNode = oldChildren[i];
2104
+ const newNode = newChildren[i];
2105
+ if (!oldNode && !newNode) {
2106
+ continue;
2107
+ }
2108
+ if (!oldNode) {
2109
+ // Add new node - we should be at the parent
2110
+ if (currentChildIndex >= 0) {
2111
+ // Navigate back to parent
2112
+ patches.push({
2113
+ type: NavigateParent
2114
+ });
2115
+ currentChildIndex = -1;
2116
+ }
2117
+ // Flatten the entire subtree so renderInternal can handle it
2118
+ const flatNodes = treeToArray(newNode);
2119
+ patches.push({
2120
+ type: Add,
2121
+ nodes: flatNodes
2122
+ });
2123
+ } else if (newNode) {
2124
+ // Compare nodes to see if we need any patches
2125
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2126
+ // If nodePatches is null, the node types are incompatible - need to replace
2127
+ if (nodePatches === null) {
2128
+ // Navigate to this child
2129
+ if (currentChildIndex === -1) {
2130
+ patches.push({
2131
+ type: NavigateChild,
2132
+ index: i
2133
+ });
2134
+ currentChildIndex = i;
2135
+ } else if (currentChildIndex !== i) {
2136
+ patches.push({
2137
+ type: NavigateSibling,
2138
+ index: i
2139
+ });
2140
+ currentChildIndex = i;
2141
+ }
2142
+ // Replace the entire subtree
2143
+ const flatNodes = treeToArray(newNode);
2144
+ patches.push({
2145
+ type: Replace,
2146
+ nodes: flatNodes
2147
+ });
2148
+ // After replace, we're at the new element (same position)
2149
+ continue;
2150
+ }
2151
+ // Check if we need to recurse into children
2152
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2153
+ // Only navigate to this element if we need to do something
2154
+ if (nodePatches.length > 0 || hasChildrenToCompare) {
2155
+ // Navigate to this child if not already there
2156
+ if (currentChildIndex === -1) {
2157
+ patches.push({
2158
+ type: NavigateChild,
2159
+ index: i
2160
+ });
2161
+ currentChildIndex = i;
2162
+ } else if (currentChildIndex !== i) {
2163
+ patches.push({
2164
+ type: NavigateSibling,
2165
+ index: i
2166
+ });
2167
+ currentChildIndex = i;
2168
+ }
2169
+ // Apply node patches (these apply to the current element, not children)
2170
+ if (nodePatches.length > 0) {
2171
+ patches.push(...nodePatches);
2172
+ }
2173
+ // Compare children recursively
2174
+ if (hasChildrenToCompare) {
2175
+ diffChildren(oldNode.children, newNode.children, patches);
2176
+ }
2177
+ }
2178
+ } else {
2179
+ // Remove old node - collect the index for later removal
2180
+ indicesToRemove.push(i);
2181
+ }
2182
+ }
2183
+ // Navigate back to parent if we ended at a child
2184
+ if (currentChildIndex >= 0) {
2185
+ patches.push({
2186
+ type: NavigateParent
2187
+ });
2188
+ currentChildIndex = -1;
2189
+ }
2190
+ // Add remove patches in reverse order (highest index first)
2191
+ // This ensures indices remain valid as we remove
2192
+ for (let j = indicesToRemove.length - 1; j >= 0; j--) {
2193
+ patches.push({
2194
+ type: RemoveChild,
2195
+ index: indicesToRemove[j]
2196
+ });
2197
+ }
2198
+ };
2199
+ const diffTrees = (oldTree, newTree, patches, path) => {
2200
+ // At the root level (path.length === 0), we're already AT the element
2201
+ // So we compare the root node directly, then compare its children
2202
+ if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
2203
+ const oldNode = oldTree[0];
2204
+ const newNode = newTree[0];
2205
+ // Compare root nodes
2206
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2207
+ // If nodePatches is null, the root node types are incompatible - need to replace
2208
+ if (nodePatches === null) {
2209
+ const flatNodes = treeToArray(newNode);
2210
+ patches.push({
2211
+ type: Replace,
2212
+ nodes: flatNodes
2213
+ });
2214
+ return;
2215
+ }
2216
+ if (nodePatches.length > 0) {
2217
+ patches.push(...nodePatches);
2218
+ }
2219
+ // Compare children
2220
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
2221
+ diffChildren(oldNode.children, newNode.children, patches);
2222
+ }
2223
+ } else {
2224
+ // Non-root level or multiple root elements - use the regular comparison
2225
+ diffChildren(oldTree, newTree, patches);
2226
+ }
2227
+ };
2228
+
2229
+ const removeTrailingNavigationPatches = patches => {
2230
+ // Find the last non-navigation patch
2231
+ let lastNonNavigationIndex = -1;
2232
+ for (let i = patches.length - 1; i >= 0; i--) {
2233
+ const patch = patches[i];
2234
+ if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
2235
+ lastNonNavigationIndex = i;
2236
+ break;
2237
+ }
2238
+ }
2239
+ // Return patches up to and including the last non-navigation patch
2240
+ return lastNonNavigationIndex === -1 ? [] : patches.slice(0, lastNonNavigationIndex + 1);
2241
+ };
2242
+
2243
+ const diffTree = (oldNodes, newNodes) => {
2244
+ // Step 1: Convert flat arrays to tree structures
2245
+ const oldTree = arrayToTree(oldNodes);
2246
+ const newTree = arrayToTree(newNodes);
2247
+ // Step 3: Compare the trees
2248
+ const patches = [];
2249
+ diffTrees(oldTree, newTree, patches, []);
2250
+ // Remove trailing navigation patches since they serve no purpose
2251
+ return removeTrailingNavigationPatches(patches);
2252
+ };
2253
+
1929
2254
  const Vertical = 'vertical';
1930
2255
 
1931
2256
  const ActivityBar$1 = 'ActivityBar';
@@ -2134,12 +2459,23 @@ const getActivityBarVirtualDom = visibleItems => {
2134
2459
  const renderItems = (oldState, newState) => {
2135
2460
  const {
2136
2461
  filteredItems,
2462
+ initial,
2137
2463
  uid
2138
2464
  } = newState;
2465
+ if (initial) {
2466
+ return [SetDom2, uid, []];
2467
+ }
2139
2468
  const dom = getActivityBarVirtualDom(filteredItems);
2140
2469
  return [SetDom2, uid, dom];
2141
2470
  };
2142
2471
 
2472
+ const renderIncremental = (oldState, newState) => {
2473
+ const oldDom = renderItems(oldState, oldState)[2];
2474
+ const newDom = renderItems(newState, newState)[2];
2475
+ const patches = diffTree(oldDom, newDom);
2476
+ return [SetPatches, newState.uid, patches];
2477
+ };
2478
+
2143
2479
  const getRenderer = diffType => {
2144
2480
  switch (diffType) {
2145
2481
  case RenderCss:
@@ -2148,6 +2484,8 @@ const getRenderer = diffType => {
2148
2484
  return renderFocusContext;
2149
2485
  case RenderFocusContext:
2150
2486
  return renderFocusContext;
2487
+ case RenderIncremental:
2488
+ return renderIncremental;
2151
2489
  case RenderItems:
2152
2490
  return renderItems;
2153
2491
  default:
@@ -2191,32 +2529,57 @@ const renderEventListeners = () => {
2191
2529
  }, {
2192
2530
  name: HandleMouseDown,
2193
2531
  params: ['handleClick', Button$1, ClientX, ClientY],
2194
- preventDefault: true,
2195
- stopPropagation: true
2532
+ preventDefault: false,
2533
+ stopPropagation: false
2196
2534
  }];
2197
2535
  };
2198
2536
 
2199
2537
  const saveState = state => {
2200
2538
  const {
2201
- currentViewletId,
2202
- uid
2539
+ currentViewletId
2203
2540
  } = state;
2204
2541
  return {
2205
- currentViewletId,
2206
- uid
2542
+ currentViewletId
2207
2543
  };
2208
2544
  };
2209
2545
 
2210
- const isEnabled = activityBarItem => {
2211
- return activityBarItem.enabled;
2546
+ const setAccountEnabled = (state, enabled) => {
2547
+ const {
2548
+ height,
2549
+ itemHeight,
2550
+ selectedIndex
2551
+ } = state;
2552
+ const newState = {
2553
+ ...state,
2554
+ accountEnabled: enabled
2555
+ };
2556
+ const newActivityBarItems = getActivityBarItems(newState);
2557
+ const markedItems = markSelected(newActivityBarItems, selectedIndex);
2558
+ const filteredItems = getFilteredActivityBarItems(markedItems, height, itemHeight);
2559
+ return {
2560
+ ...newState,
2561
+ activityBarItems: markedItems,
2562
+ filteredItems: filteredItems
2563
+ };
2212
2564
  };
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;
2565
+
2566
+ const toggleActivityBarItem = async (state, itemId) => {
2567
+ const {
2568
+ activityBarItems
2569
+ } = state;
2570
+ const updatedItems = activityBarItems.map(item => {
2571
+ if (item.id === itemId) {
2572
+ const isCurrentlyEnabled = item.flags & Enabled;
2573
+ return {
2574
+ ...item,
2575
+ flags: isCurrentlyEnabled ? item.flags & -9 : item.flags | Enabled
2576
+ };
2577
+ }
2578
+ return item;
2579
+ });
2217
2580
  return {
2218
2581
  ...state,
2219
- activityBarItems: state.activityBarItems.filter(isEnabled)
2582
+ activityBarItems: updatedItems
2220
2583
  };
2221
2584
  };
2222
2585
 
@@ -2238,6 +2601,7 @@ const commandMap = {
2238
2601
  'ActivityBar.handleClick': wrapCommand(handleClick),
2239
2602
  'ActivityBar.handleClickIndex': wrapCommand(handleClickIndex),
2240
2603
  'ActivityBar.handleContextMenu': wrapCommand(handleContextMenu),
2604
+ 'ActivityBar.handleSettingsChanged': wrapCommand(handleSettingsChanged),
2241
2605
  'ActivityBar.handleSideBarHidden': wrapCommand(handleSideBarHidden),
2242
2606
  'ActivityBar.handleSideBarViewletChange': wrapCommand(handleSideBarViewletChange),
2243
2607
  'ActivityBar.handleUpdateStateChange': wrapCommand(handleUpdateStateChange),
@@ -2246,6 +2610,7 @@ const commandMap = {
2246
2610
  'ActivityBar.renderEventListeners': renderEventListeners,
2247
2611
  'ActivityBar.resize': wrapCommand(handleResize),
2248
2612
  'ActivityBar.saveState': wrapGetter(saveState),
2613
+ 'ActivityBar.setAccountEnabled': wrapCommand(setAccountEnabled),
2249
2614
  'ActivityBar.terminate': terminate,
2250
2615
  'ActivityBar.toggleActivityBarItem': wrapCommand(toggleActivityBarItem)
2251
2616
  };
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.3.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",