@lvce-editor/text-search-worker 3.32.0 → 3.33.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.
@@ -1695,6 +1695,7 @@ const Search$1 = 'Search';
1695
1695
  const SearchField = 'SearchField';
1696
1696
  const SearchFieldButton = 'SearchFieldButton';
1697
1697
  const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
1698
+ const SearchFieldButtonDisabled = 'SearchFieldButtonDisabled';
1698
1699
  const SearchFieldButtons = 'SearchFieldButtons';
1699
1700
  const SearchFieldContainer = 'SearchFieldContainer';
1700
1701
  const SearchFieldError = 'SearchFieldError';
@@ -1900,6 +1901,18 @@ const getMatchCount = (results, startIndex) => {
1900
1901
  return results.length - startIndex - 1;
1901
1902
  };
1902
1903
 
1904
+ const getChildCount = (expanded, matchCount) => {
1905
+ let childCount = 1;
1906
+ if (expanded === Expanded || expanded === Collapsed) {
1907
+ childCount += 2;
1908
+ }
1909
+ if (matchCount) {
1910
+ childCount++;
1911
+ }
1912
+ childCount++;
1913
+ return childCount;
1914
+ };
1915
+
1903
1916
  // TODO this should be in FileSystem module
1904
1917
  const pathBaseName = path => {
1905
1918
  return path.slice(path.lastIndexOf('/') + 1);
@@ -1911,12 +1924,55 @@ const getAbsolutePath = relativePath => {
1911
1924
  return `/${relativePath}`; // TODO support windows paths
1912
1925
  };
1913
1926
 
1914
- const getDisplayResult = (results, fileIcons, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY) => {
1927
+ const getSearchDisplayResultFile = (results, fileIcons, i, setSize, collapsedPaths, text, posInSet, relativeIndex, focused, originalResults) => {
1928
+ const path = text;
1929
+ const absolutePath = getAbsolutePath(path);
1930
+ const baseName = pathBaseName(path);
1931
+ const index = originalResults.indexOf(results[i]);
1932
+ const matchCount = getMatchCount(results, index);
1933
+ const expanded = collapsedPaths.includes(path) ? Collapsed : Expanded;
1934
+ const childCount = getChildCount(expanded, matchCount);
1935
+ const badgeText = `${matchCount}`;
1936
+ return {
1937
+ badgeText,
1938
+ childCount,
1939
+ depth: 0,
1940
+ expanded,
1941
+ focused,
1942
+ icon: fileIcons[relativeIndex],
1943
+ matchLength: 0,
1944
+ matchStart: 0,
1945
+ posInSet,
1946
+ replacement: '',
1947
+ setSize,
1948
+ text: baseName,
1949
+ title: absolutePath
1950
+ };
1951
+ };
1952
+
1953
+ const getDisplayResultMatch = (setSize, searchTermLength, replacement, text, posInSet, start, focused) => {
1954
+ return {
1955
+ badgeText: '',
1956
+ childCount: getChildCount(None, 0),
1957
+ depth: 1,
1958
+ expanded: None,
1959
+ focused,
1960
+ icon: '',
1961
+ matchLength: searchTermLength,
1962
+ matchStart: start,
1963
+ posInSet,
1964
+ replacement,
1965
+ setSize,
1966
+ text: text,
1967
+ title: text
1968
+ };
1969
+ };
1970
+
1971
+ const getDisplayResult = (results, fileIcons, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY, originalResults) => {
1915
1972
  const result = results[i];
1916
1973
  const {
1917
1974
  type,
1918
1975
  text,
1919
- lineNumber,
1920
1976
  start
1921
1977
  } = result;
1922
1978
  const posInSet = i + 1;
@@ -1924,52 +1980,20 @@ const getDisplayResult = (results, fileIcons, i, setSize, searchTermLength, repl
1924
1980
  const relativeIndex = i - minLineY;
1925
1981
  switch (type) {
1926
1982
  case File:
1927
- const path = text;
1928
- const absolutePath = getAbsolutePath(path);
1929
- const baseName = pathBaseName(path);
1930
- const matchCount = getMatchCount(results, i);
1931
- return {
1932
- title: absolutePath,
1933
- text: baseName,
1934
- icon: fileIcons[relativeIndex],
1935
- posInSet,
1936
- setSize,
1937
- lineNumber,
1938
- matchStart: 0,
1939
- matchLength: 0,
1940
- replacement: '',
1941
- depth: 0,
1942
- matchCount,
1943
- focused,
1944
- expanded: collapsedPaths.includes(path) ? Collapsed : Expanded
1945
- };
1983
+ return getSearchDisplayResultFile(results, fileIcons, i, setSize, collapsedPaths, text, posInSet, relativeIndex, focused, originalResults);
1946
1984
  case Match:
1947
- return {
1948
- title: text,
1949
- text: text,
1950
- icon: '',
1951
- posInSet,
1952
- setSize,
1953
- lineNumber,
1954
- matchStart: start,
1955
- matchLength: searchTermLength,
1956
- replacement,
1957
- depth: 1,
1958
- matchCount: 0,
1959
- focused,
1960
- expanded: None
1961
- };
1985
+ return getDisplayResultMatch(setSize, searchTermLength, replacement, text, posInSet, start, focused);
1962
1986
  default:
1963
1987
  throw new Error('unexpected search result type');
1964
1988
  }
1965
1989
  };
1966
1990
 
1967
- const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, fileIcons, focusedIndex, collapsedPaths) => {
1991
+ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, fileIcons, focusedIndex, collapsedPaths, originalResults) => {
1968
1992
  const displayResults = [];
1969
1993
  const setSize = resultCount;
1970
1994
  const searchTermLength = searchTerm.length;
1971
1995
  for (let i = minLineY; i < maxLineY; i++) {
1972
- const displayResult = getDisplayResult(results, fileIcons, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY);
1996
+ const displayResult = getDisplayResult(results, fileIcons, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY, originalResults);
1973
1997
  displayResults.push(displayResult);
1974
1998
  }
1975
1999
  return displayResults;
@@ -2073,16 +2097,20 @@ const getInputActionsInclude = flags => {
2073
2097
  };
2074
2098
  };
2075
2099
 
2100
+ const getClassName = (checked, disabled) => {
2101
+ return mergeClassNames(SearchFieldButton, checked ? SearchFieldButtonChecked : '', disabled ? SearchFieldButtonDisabled : '');
2102
+ };
2076
2103
  const getSearchFieldButtonVirtualDom = button => {
2077
2104
  const {
2078
2105
  icon,
2079
2106
  checked,
2080
2107
  title,
2081
- name
2108
+ name,
2109
+ disabled
2082
2110
  } = button;
2083
2111
  return [{
2084
2112
  type: Button,
2085
- className: mergeClassNames(SearchFieldButton, checked ? SearchFieldButtonChecked : ''),
2113
+ className: getClassName(checked, disabled),
2086
2114
  name,
2087
2115
  title,
2088
2116
  role: CheckBox,
@@ -2197,7 +2225,7 @@ const getInputActionsInput = flags => {
2197
2225
  };
2198
2226
  };
2199
2227
 
2200
- const getInputActionsReplace = flags => {
2228
+ const getInputActionsReplace = (flags, matchCount) => {
2201
2229
  const inside = [{
2202
2230
  icon: MaskIconPreserveCase,
2203
2231
  checked: Boolean(flags & PreserveCase$1),
@@ -2208,7 +2236,8 @@ const getInputActionsReplace = flags => {
2208
2236
  icon: MaskIconReplaceAll,
2209
2237
  checked: false,
2210
2238
  title: replaceAll$1(),
2211
- name: ReplaceAll
2239
+ name: ReplaceAll,
2240
+ disabled: matchCount === 0
2212
2241
  }];
2213
2242
  return {
2214
2243
  inside,
@@ -2233,9 +2262,9 @@ const getSearchToggleVirtualDom = flags => {
2233
2262
  }];
2234
2263
  };
2235
2264
 
2236
- const getSearchHeaderTopVirtualDom = (flags, searchInputErrorMessage = '') => {
2265
+ const getSearchHeaderTopVirtualDom = (flags, searchInputErrorMessage, matchCount) => {
2237
2266
  const inputActions = getInputActionsInput(flags);
2238
- const replaceActions = getInputActionsReplace(flags);
2267
+ const replaceActions = getInputActionsReplace(flags, matchCount);
2239
2268
  const dom = [{
2240
2269
  type: Div,
2241
2270
  className: SearchHeaderTop,
@@ -2253,7 +2282,7 @@ const getSearchHeaderTopVirtualDom = (flags, searchInputErrorMessage = '') => {
2253
2282
  return dom;
2254
2283
  };
2255
2284
 
2256
- const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage) => {
2285
+ const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage, matchCount) => {
2257
2286
  const dom = [{
2258
2287
  type: Div,
2259
2288
  className: SearchHeader,
@@ -2261,7 +2290,7 @@ const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage) => {
2261
2290
  childCount: 2,
2262
2291
  onClick: HandleHeaderClick2,
2263
2292
  onFocusIn: HandleHeaderFocusIn
2264
- }, ...getSearchHeaderTopVirtualDom(flags, searchInputErrorMessage), ...getSearchHeaderDetailsVirtualDom(flags, message)];
2293
+ }, ...getSearchHeaderTopVirtualDom(flags, searchInputErrorMessage, matchCount), ...getSearchHeaderDetailsVirtualDom(flags, message)];
2265
2294
  return dom;
2266
2295
  };
2267
2296
 
@@ -2313,12 +2342,15 @@ const getAriaExpanded = expanded => {
2313
2342
  }
2314
2343
  };
2315
2344
 
2316
- const getBadgeVirtualDom = (className, count) => {
2345
+ const getBadgeVirtualDom = (className, badgeText) => {
2346
+ if (!badgeText) {
2347
+ return [];
2348
+ }
2317
2349
  return [{
2318
2350
  type: Div,
2319
2351
  className: mergeClassNames(Badge, className),
2320
2352
  childCount: 1
2321
- }, text(`${count}`)];
2353
+ }, text(badgeText)];
2322
2354
  };
2323
2355
 
2324
2356
  const chevronDownVirtualDom = {
@@ -2396,6 +2428,16 @@ const getSearchResultClassName = focused => {
2396
2428
 
2397
2429
  const PaddingRight = '12px';
2398
2430
 
2431
+ const getIconsVirtualDom = (expanded, icon) => {
2432
+ switch (expanded) {
2433
+ case Expanded:
2434
+ return [chevronDownVirtualDom, getFileIconVirtualDom(icon)];
2435
+ case Collapsed:
2436
+ return [chevronRightVirtualDom, getFileIconVirtualDom(icon)];
2437
+ default:
2438
+ return [];
2439
+ }
2440
+ };
2399
2441
  const getSearchResultVirtualDom = rowInfo => {
2400
2442
  const {
2401
2443
  matchStart,
@@ -2407,11 +2449,12 @@ const getSearchResultVirtualDom = rowInfo => {
2407
2449
  posInSet,
2408
2450
  depth,
2409
2451
  replacement,
2410
- matchCount,
2411
2452
  focused,
2412
- expanded
2453
+ expanded,
2454
+ childCount,
2455
+ badgeText
2413
2456
  } = rowInfo;
2414
- const treeItem = {
2457
+ const dom = [{
2415
2458
  type: Div,
2416
2459
  role: TreeItem$1,
2417
2460
  className: getSearchResultClassName(focused),
@@ -2421,29 +2464,11 @@ const getSearchResultVirtualDom = rowInfo => {
2421
2464
  ariaPosInSet: posInSet,
2422
2465
  ariaLabel: title,
2423
2466
  ariaDescription: '',
2424
- childCount: 1,
2467
+ childCount,
2425
2468
  paddingLeft: getPaddingLeft(depth),
2426
2469
  paddingRight: PaddingRight,
2427
2470
  ariaExpanded: getAriaExpanded(expanded)
2428
- };
2429
- const dom = [];
2430
- dom.push(treeItem);
2431
- if (expanded === Expanded) {
2432
- // TODO move childcount computation to getDisplaySearchresults
2433
- // TODO add chevronIcon and fileIcon properties to getDisplaySearchResults
2434
- treeItem.childCount += 2;
2435
- dom.push(chevronDownVirtualDom, getFileIconVirtualDom(icon));
2436
- } else if (expanded === Collapsed) {
2437
- treeItem.childCount += 2;
2438
- dom.push(chevronRightVirtualDom, getFileIconVirtualDom(icon));
2439
- }
2440
- dom.push(...getLabelVirtualDom(displayText, matchLength, matchStart, replacement));
2441
- if (matchCount) {
2442
- treeItem.childCount++;
2443
- dom.push(...getBadgeVirtualDom(SourceControlBadge, matchCount));
2444
- }
2445
- treeItem.childCount++;
2446
- dom.push({
2471
+ }, ...getIconsVirtualDom(expanded, icon), ...getLabelVirtualDom(displayText, matchLength, matchStart, replacement), ...getBadgeVirtualDom(SourceControlBadge, badgeText), {
2447
2472
  type: Div,
2448
2473
  className: SearchRemove,
2449
2474
  childCount: 1
@@ -2451,7 +2476,7 @@ const getSearchResultVirtualDom = rowInfo => {
2451
2476
  type: Div,
2452
2477
  className: CloseMaskIcon,
2453
2478
  childCount: 0
2454
- });
2479
+ }];
2455
2480
  return dom;
2456
2481
  };
2457
2482
 
@@ -2480,14 +2505,14 @@ const getSearchResultsVirtualDom = (visibleItems, focusOutline, scrollbarHeight,
2480
2505
  }, ...getTreeItemsVirtualDom(visibleItems, deltaY, itemHeight), ...getScrollBarVirtualDom(scrollbarHeight, scrollBarY, scrollBarValue)];
2481
2506
  };
2482
2507
 
2483
- const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchInputErrorMessage, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight) => {
2508
+ const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchInputErrorMessage, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight, matchCount) => {
2484
2509
  const errorDom = getSearchInputErrorVirtualDom(searchInputErrorMessage);
2485
2510
  const childCount = 2 + (errorDom.length > 0 ? 1 : 0);
2486
2511
  return [{
2487
2512
  type: Div,
2488
2513
  className: mergeClassNames(Viewlet, Search$1),
2489
2514
  childCount
2490
- }, ...getSearchHeaderVirtualDom(flags, message, searchInputErrorMessage), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight)];
2515
+ }, ...getSearchHeaderVirtualDom(flags, message, searchInputErrorMessage, matchCount), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight)];
2491
2516
  };
2492
2517
 
2493
2518
  const handleError = error => {
@@ -3347,6 +3372,7 @@ const selectIndexFile = async (state, searchResult, index) => {
3347
3372
  const path = searchResult.text;
3348
3373
  const newCollapsedPaths = toggleCollapsedPath(collapsedPaths, path);
3349
3374
  const filteredResults = getFilteredResults(items, newCollapsedPaths);
3375
+ const icons = await getFileIcons(filteredResults);
3350
3376
  const total = filteredResults.length;
3351
3377
  const listHeight = height - headerHeight;
3352
3378
  const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
@@ -3357,7 +3383,8 @@ const selectIndexFile = async (state, searchResult, index) => {
3357
3383
  listFocusedIndex: index,
3358
3384
  listFocused: true,
3359
3385
  listItems: filteredResults,
3360
- maxLineY
3386
+ maxLineY,
3387
+ icons
3361
3388
  };
3362
3389
  };
3363
3390
 
@@ -3458,7 +3485,8 @@ const setDeltaY = (state, value) => {
3458
3485
  finalDeltaY,
3459
3486
  deltaY,
3460
3487
  height,
3461
- headerHeight
3488
+ headerHeight,
3489
+ listItems
3462
3490
  } = state;
3463
3491
  const listHeight = height - headerHeight;
3464
3492
  const newDeltaY = clamp(value, 0, finalDeltaY);
@@ -3467,7 +3495,7 @@ const setDeltaY = (state, value) => {
3467
3495
  }
3468
3496
  // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
3469
3497
  const minLineY = Math.floor(newDeltaY / itemHeight);
3470
- const maxLineY = minLineY + getNumberOfVisibleItems(listHeight, itemHeight);
3498
+ const maxLineY = Math.min(minLineY + getNumberOfVisibleItems(listHeight, itemHeight), listItems.length);
3471
3499
 
3472
3500
  // TODO update icons
3473
3501
  return {
@@ -3654,11 +3682,11 @@ const renderItems = {
3654
3682
  return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.replacement === newState.replacement && oldState.flags === newState.flags && oldState.message === newState.message && oldState.loaded === newState.loaded && oldState.collapsedPaths === newState.collapsedPaths && oldState.listFocusedIndex === newState.listFocusedIndex && oldState.listFocused === newState.listFocused && oldState.icons === newState.icons && oldState.searchInputErrorMessage === newState.searchInputErrorMessage && oldState.deltaY === newState.deltaY;
3655
3683
  },
3656
3684
  apply(oldState, newState) {
3657
- const displayResults = getDisplayResults(newState.listItems, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.icons, newState.listFocusedIndex, newState.collapsedPaths);
3685
+ const displayResults = getDisplayResults(newState.listItems, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.icons, newState.listFocusedIndex, newState.collapsedPaths, newState.items);
3658
3686
  const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
3659
3687
  const scrollBarValue = newState.deltaY / newState.finalDeltaY * 100;
3660
3688
  const scrollBarY = getScrollBarY(newState.deltaY, newState.finalDeltaY, newState.height - newState.headerHeight, newState.scrollBarHeight);
3661
- const dom = getSearchVirtualDom(displayResults, newState.flags, newState.message, focusOutline, newState.searchInputErrorMessage, newState.scrollBarHeight, scrollBarY, scrollBarValue, newState.deltaY, newState.itemHeight);
3689
+ const dom = getSearchVirtualDom(displayResults, newState.flags, newState.message, focusOutline, newState.searchInputErrorMessage, newState.scrollBarHeight, scrollBarY, scrollBarValue, newState.deltaY, newState.itemHeight, newState.matchCount);
3662
3690
  return ['Viewlet.setDom2', newState.uid, dom];
3663
3691
  }
3664
3692
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "3.32.0",
3
+ "version": "3.33.0",
4
4
  "description": "Text Search Worker",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",