@lvce-editor/quick-pick-worker 4.21.1 → 4.22.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.
@@ -1804,6 +1804,87 @@ const getListHeight$1 = (itemsLength, itemHeight, maxHeight) => {
1804
1804
  return Math.min(totalHeight, maxHeight);
1805
1805
  };
1806
1806
 
1807
+ const getIconsCached = (paths, fileIconCache) => {
1808
+ return paths.map(path => fileIconCache[path]);
1809
+ };
1810
+
1811
+ const getMissingIconRequests = (dirents, fileIconCache) => {
1812
+ const missingRequests = [];
1813
+ for (const dirent of dirents) {
1814
+ if (!dirent.path) {
1815
+ continue;
1816
+ }
1817
+ if (!(dirent.path in fileIconCache)) {
1818
+ missingRequests.push({
1819
+ name: dirent.name,
1820
+ path: dirent.path,
1821
+ type: dirent.type
1822
+ });
1823
+ }
1824
+ }
1825
+ return missingRequests;
1826
+ };
1827
+
1828
+ const getPath$1 = dirent => {
1829
+ return dirent.path;
1830
+ };
1831
+
1832
+ const None$2 = 0;
1833
+ const Directory = 3;
1834
+ const File = 7;
1835
+
1836
+ const requestFileIcon = async request => {
1837
+ if (!request.name) {
1838
+ return '';
1839
+ }
1840
+ return request.type === File ? getFileIcon({
1841
+ name: request.name
1842
+ }) : getFolderIcon({
1843
+ name: request.name
1844
+ });
1845
+ };
1846
+ const requestFileIcons = async requests => {
1847
+ const promises = requests.map(requestFileIcon);
1848
+ return Promise.all(promises);
1849
+ };
1850
+
1851
+ const toDirent = pick => {
1852
+ const dirent = {
1853
+ name: pick.iconName || pick.label,
1854
+ path: pick.uri,
1855
+ type: pick.direntType
1856
+ };
1857
+ return dirent;
1858
+ };
1859
+
1860
+ const updateIconCache = (iconCache, missingRequests, newIcons) => {
1861
+ if (missingRequests.length === 0) {
1862
+ return iconCache;
1863
+ }
1864
+ const newFileIconCache = {
1865
+ ...iconCache
1866
+ };
1867
+ for (let i = 0; i < missingRequests.length; i++) {
1868
+ const request = missingRequests[i];
1869
+ const icon = newIcons[i];
1870
+ newFileIconCache[request.path] = icon;
1871
+ }
1872
+ return newFileIconCache;
1873
+ };
1874
+
1875
+ const getQuickPickFileIcons = async (items, fileIconCache) => {
1876
+ const dirents = items.map(toDirent);
1877
+ const missingRequests = getMissingIconRequests(dirents, fileIconCache);
1878
+ const newIcons = await requestFileIcons(missingRequests);
1879
+ const newFileIconCache = updateIconCache(fileIconCache, missingRequests, newIcons);
1880
+ const paths = dirents.map(getPath$1);
1881
+ const icons = getIconsCached(paths, newFileIconCache);
1882
+ return {
1883
+ icons,
1884
+ newFileIconCache
1885
+ };
1886
+ };
1887
+
1807
1888
  const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
1808
1889
  if (size >= contentSize) {
1809
1890
  return 0;
@@ -1878,7 +1959,7 @@ const getScrollBarTop = (state, scrollBarHeight) => {
1878
1959
  const getRelativePointerY = (state, clientY) => {
1879
1960
  return clientY - state.top - state.headerHeight;
1880
1961
  };
1881
- const setDeltaY = (state, deltaY) => {
1962
+ const setDeltaY = async (state, deltaY) => {
1882
1963
  object(state);
1883
1964
  number(deltaY);
1884
1965
  const {
@@ -1902,20 +1983,26 @@ const setDeltaY = (state, deltaY) => {
1902
1983
  const maxLineY = minLineY + Math.round(listHeight / itemHeight);
1903
1984
  number(minLineY);
1904
1985
  number(maxLineY);
1986
+ const {
1987
+ icons,
1988
+ newFileIconCache
1989
+ } = await getQuickPickFileIcons(items.slice(minLineY, maxLineY), state.fileIconCache);
1905
1990
  return {
1906
1991
  ...state,
1907
1992
  deltaY,
1993
+ fileIconCache: newFileIconCache,
1994
+ icons,
1908
1995
  maxLineY,
1909
1996
  minLineY
1910
1997
  };
1911
1998
  };
1912
- const handleWheel = (state, deltaMode, deltaY) => {
1999
+ const handleWheel = async (state, deltaMode, deltaY) => {
1913
2000
  object(state);
1914
2001
  number(deltaMode);
1915
2002
  number(deltaY);
1916
2003
  return setDeltaY(state, state.deltaY + deltaY);
1917
2004
  };
1918
- const handleScrollBarPointerDown = (state, clientY, pointerId) => {
2005
+ const handleScrollBarPointerDown = async (state, clientY, pointerId) => {
1919
2006
  object(state);
1920
2007
  number(clientY);
1921
2008
  number(pointerId);
@@ -1934,7 +2021,7 @@ const handleScrollBarPointerDown = (state, clientY, pointerId) => {
1934
2021
  };
1935
2022
  return handleScrollBarPointerMove(newState, clientY, pointerId);
1936
2023
  };
1937
- const handleScrollBarPointerMove = (state, clientY, pointerId) => {
2024
+ const handleScrollBarPointerMove = async (state, clientY, pointerId) => {
1938
2025
  object(state);
1939
2026
  number(clientY);
1940
2027
  number(pointerId);
@@ -2081,87 +2168,6 @@ const focusPick = (id, pick) => {
2081
2168
  return fn(pick);
2082
2169
  };
2083
2170
 
2084
- const getIconsCached = (paths, fileIconCache) => {
2085
- return paths.map(path => fileIconCache[path]);
2086
- };
2087
-
2088
- const getMissingIconRequests = (dirents, fileIconCache) => {
2089
- const missingRequests = [];
2090
- for (const dirent of dirents) {
2091
- if (!dirent.path) {
2092
- continue;
2093
- }
2094
- if (!(dirent.path in fileIconCache)) {
2095
- missingRequests.push({
2096
- name: dirent.name,
2097
- path: dirent.path,
2098
- type: dirent.type
2099
- });
2100
- }
2101
- }
2102
- return missingRequests;
2103
- };
2104
-
2105
- const getPath$1 = dirent => {
2106
- return dirent.path;
2107
- };
2108
-
2109
- const None$2 = 0;
2110
- const Directory = 3;
2111
- const File = 7;
2112
-
2113
- const requestFileIcon = async request => {
2114
- if (!request.name) {
2115
- return '';
2116
- }
2117
- return request.type === File ? getFileIcon({
2118
- name: request.name
2119
- }) : getFolderIcon({
2120
- name: request.name
2121
- });
2122
- };
2123
- const requestFileIcons = async requests => {
2124
- const promises = requests.map(requestFileIcon);
2125
- return Promise.all(promises);
2126
- };
2127
-
2128
- const toDirent = pick => {
2129
- const dirent = {
2130
- name: pick.iconName || pick.label,
2131
- path: pick.uri,
2132
- type: pick.direntType
2133
- };
2134
- return dirent;
2135
- };
2136
-
2137
- const updateIconCache = (iconCache, missingRequests, newIcons) => {
2138
- if (missingRequests.length === 0) {
2139
- return iconCache;
2140
- }
2141
- const newFileIconCache = {
2142
- ...iconCache
2143
- };
2144
- for (let i = 0; i < missingRequests.length; i++) {
2145
- const request = missingRequests[i];
2146
- const icon = newIcons[i];
2147
- newFileIconCache[request.path] = icon;
2148
- }
2149
- return newFileIconCache;
2150
- };
2151
-
2152
- const getQuickPickFileIcons = async (items, fileIconCache) => {
2153
- const dirents = items.map(toDirent);
2154
- const missingRequests = getMissingIconRequests(dirents, fileIconCache);
2155
- const newIcons = await requestFileIcons(missingRequests);
2156
- const newFileIconCache = updateIconCache(fileIconCache, missingRequests, newIcons);
2157
- const paths = dirents.map(getPath$1);
2158
- const icons = getIconsCached(paths, newFileIconCache);
2159
- return {
2160
- icons,
2161
- newFileIconCache
2162
- };
2163
- };
2164
-
2165
2171
  const focusIndex = async (state, index) => {
2166
2172
  const {
2167
2173
  fileIconCache,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/quick-pick-worker",
3
- "version": "4.21.1",
3
+ "version": "4.22.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lvce-editor/quick-pick-worker.git"