@lvce-editor/text-search-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.
@@ -958,11 +958,15 @@ const isLastIndex = (array, index) => {
958
958
  const lastIndex = array => {
959
959
  return array.length - 1;
960
960
  };
961
- const toSpliced = (array, index, deleteCount, ...inserted) => {
962
- return [...array.slice(0, index), ...inserted, ...array.slice(index + deleteCount)];
963
- };
964
961
  const remove = (array, index, deleteCount) => {
965
- return toSpliced(array, index, deleteCount);
962
+ return array.toSpliced(index, deleteCount);
963
+ };
964
+ const fromAsync = async asyncIterable => {
965
+ const children = [];
966
+ for await (const value of asyncIterable) {
967
+ children.push(value);
968
+ }
969
+ return children;
966
970
  };
967
971
 
968
972
  class AssertionError extends Error {
@@ -1035,23 +1039,34 @@ const i18nString = (key, placeholders = emptyObject) => {
1035
1039
  * @enum {string}
1036
1040
  */
1037
1041
  const UiStrings = {
1038
- NoResults: 'No results found',
1039
- Oneresult: '1 result in 1 file',
1040
- ManyResultsInOneFile: '{PH1} results in 1 file',
1041
- ManyResultsInManyFiles: '{PH1} results in {PH2} files',
1042
- ReplaceAll: 'Replace All',
1043
- Replace: 'Replace',
1044
- ConfirmReplaceOneOccurrenceInOneFile: "Replace 1 occurrence across 1 file with '{PH1}'",
1045
- ConfirmReplaceOneOccurrenceInOneFileNoValue: 'Replace 1 occurrence across 1 file',
1046
- ConfirmReplaceManyOccurrencesInOneFile: "Replace {PH1} occurrences across 1 file with '{PH2}'",
1047
- ConfirmReplaceManyOccurrencesInOneFileNoValue: 'Replace {PH1} occurrences across 1 file',
1042
+ ClearSearchResults: 'Clear Search Results',
1043
+ CollapseAll: 'Collapse All',
1044
+ ConfirmReplaceAll: 'Replace All?',
1048
1045
  ConfirmReplaceManyOccurrencesInManyFiles: "Replace {PH1} occurrences across {PH2} files with '{PH3}'",
1049
1046
  ConfirmReplaceManyOccurrencesInManyFilesNoValue: 'Replace {PH1} occurrences across {PH2} files',
1050
- Refresh: 'Refresh',
1051
- ClearSearchResults: 'Clear Search Results',
1047
+ ConfirmReplaceManyOccurrencesInOneFile: "Replace {PH1} occurrences across 1 file with '{PH2}'",
1048
+ ConfirmReplaceManyOccurrencesInOneFileNoValue: 'Replace {PH1} occurrences across 1 file',
1049
+ ConfirmReplaceOneOccurrenceInOneFile: "Replace 1 occurrence across 1 file with '{PH1}'",
1050
+ ConfirmReplaceOneOccurrenceInOneFileNoValue: 'Replace 1 occurrence across 1 file',
1051
+ CopyPath: 'Copy Path',
1052
+ Dismiss: 'Dismiss',
1053
+ ManyResultsInManyFiles: '{PH1} results in {PH2} files',
1054
+ ManyResultsInOneFile: '{PH1} results in 1 file',
1055
+ MatchCase: 'Match Case',
1056
+ MatchWholeWord: 'Match Whole Word',
1057
+ NoResults: 'No results found',
1058
+ Oneresult: '1 result in 1 file',
1052
1059
  OpenNewSearchEditor: 'Open New Search Editor',
1053
- ViewAsTree: 'View as Tree',
1054
- CollapseAll: 'Collapse All'
1060
+ PreserveCase: 'Preserve Case',
1061
+ Refresh: 'Refresh',
1062
+ Replace: 'Replace',
1063
+ ReplaceAll: 'Replace All',
1064
+ ReplacedManyOccurrencesInManyFiles: "Replaced {PH1} occurrences across {PH2} files with '{PH3}'",
1065
+ ReplacedManyOccurrencesInOneFile: "Replaced {PH1} occurrences across 1 file with '{PH2}'",
1066
+ ReplacedOneOccurrenceInOneFile: "Replaced 1 occurrence across 1 file with '{PH1}'",
1067
+ ToggleReplace: 'Toggle Replace',
1068
+ UseRegularExpression: 'Use Regular Expression',
1069
+ ViewAsTree: 'View as Tree'
1055
1070
  };
1056
1071
  const noResults = () => {
1057
1072
  return i18nString(UiStrings.NoResults);
@@ -1059,6 +1074,21 @@ const noResults = () => {
1059
1074
  const oneResult = () => {
1060
1075
  return i18nString(UiStrings.Oneresult);
1061
1076
  };
1077
+ const toggleReplace$1 = () => {
1078
+ return i18nString(UiStrings.ToggleReplace);
1079
+ };
1080
+ const matchCase = () => {
1081
+ return i18nString(UiStrings.MatchCase);
1082
+ };
1083
+ const preserveCase = () => {
1084
+ return i18nString(UiStrings.PreserveCase);
1085
+ };
1086
+ const matchWholeWord = () => {
1087
+ return i18nString(UiStrings.MatchWholeWord);
1088
+ };
1089
+ const useRegularExpression = () => {
1090
+ return i18nString(UiStrings.UseRegularExpression);
1091
+ };
1062
1092
  const manyResultsInOneFile = resultCount => {
1063
1093
  return i18nString(UiStrings.ManyResultsInOneFile, {
1064
1094
  PH1: resultCount
@@ -1327,8 +1357,13 @@ const IconButton = 'IconButton';
1327
1357
  const Label = 'Label';
1328
1358
  const List = 'List';
1329
1359
  const MaskIcon = 'MaskIcon';
1360
+ const MaskIconCaseSensitive = 'MaskIconCaseSensitive';
1330
1361
  const MaskIconChevronDown = 'MaskIconChevronDown';
1331
1362
  const MaskIconChevronRight = 'MaskIconChevronRight';
1363
+ const MaskIconPreserveCase = 'MaskIconPreserveCase';
1364
+ const MaskIconRegex = 'MaskIconRegex';
1365
+ const MaskIconReplaceAll = 'MaskIconReplaceAll';
1366
+ const MaskIconWholeWord = 'MaskIconWholeWord';
1332
1367
  const MultilineInputBox = 'MultilineInputBox';
1333
1368
  const Search$1 = 'Search';
1334
1369
  const SearchField = 'SearchField';
@@ -1572,8 +1607,29 @@ const getSearchFieldButtonVirtualDom = button => {
1572
1607
  }];
1573
1608
  };
1574
1609
 
1610
+ const getOutSideButtonsDom = outsideButtons => {
1611
+ if (outsideButtons.length === 0) {
1612
+ return {
1613
+ preNodes: [],
1614
+ postNodes: []
1615
+ };
1616
+ }
1617
+ return {
1618
+ preNodes: [{
1619
+ type: Div,
1620
+ className: SearchFieldContainer,
1621
+ role: None,
1622
+ childCount: 1 + outsideButtons.length
1623
+ }],
1624
+ postNodes: outsideButtons.flatMap(getSearchFieldButtonVirtualDom)
1625
+ };
1626
+ };
1575
1627
  const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '') => {
1576
- const dom = [{
1628
+ const {
1629
+ preNodes,
1630
+ postNodes
1631
+ } = getOutSideButtonsDom(outsideButtons);
1632
+ const dom = [...preNodes, {
1577
1633
  type: Div,
1578
1634
  className: SearchField,
1579
1635
  role: None,
@@ -1593,16 +1649,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
1593
1649
  type: Div,
1594
1650
  className: SearchFieldButtons,
1595
1651
  childCount: insideButtons.length
1596
- }, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom)];
1597
- if (outsideButtons.length > 0) {
1598
- dom.unshift({
1599
- type: Div,
1600
- className: SearchFieldContainer,
1601
- role: None,
1602
- childCount: 1 + outsideButtons.length
1603
- });
1604
- dom.push(...outsideButtons.flatMap(getSearchFieldButtonVirtualDom));
1605
- }
1652
+ }, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom), ...postNodes];
1606
1653
  return dom;
1607
1654
  };
1608
1655
 
@@ -1614,7 +1661,7 @@ const text = data => {
1614
1661
  };
1615
1662
  };
1616
1663
 
1617
- const getSearchHeaderVirtualDom = (replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded) => {
1664
+ const getSearchHeaderVirtualDom = (replaceExpanded, matchCase$1, matchWholeWord$1, useRegularExpression$1, detailsExpanded) => {
1618
1665
  const dom = [{
1619
1666
  type: Div,
1620
1667
  className: SearchHeader,
@@ -1630,8 +1677,8 @@ const getSearchHeaderVirtualDom = (replaceExpanded, matchCase, matchWholeWord, u
1630
1677
  }, {
1631
1678
  type: Button,
1632
1679
  className: mergeClassNames(IconButton, SearchToggleButton, replaceExpanded ? SearchToggleButtonExpanded : ''),
1633
- title: 'Toggle Replace',
1634
- ariaLabel: 'Toggle Replace',
1680
+ title: toggleReplace$1(),
1681
+ ariaLabel: toggleReplace$1(),
1635
1682
  ariaExpanded: replaceExpanded,
1636
1683
  childCount: 1,
1637
1684
  'data-command': 'toggleReplace'
@@ -1645,27 +1692,27 @@ const getSearchHeaderVirtualDom = (replaceExpanded, matchCase, matchWholeWord, u
1645
1692
  role: None,
1646
1693
  childCount: replaceExpanded ? 2 : 1
1647
1694
  }, ...getSearchFieldVirtualDom('search-value', 'Search', 'handleInput', [{
1648
- icon: 'MaskIconCaseSensitive',
1649
- checked: matchCase,
1650
- title: 'Match Case'
1695
+ icon: MaskIconCaseSensitive,
1696
+ checked: matchCase$1,
1697
+ title: matchCase()
1651
1698
  }, {
1652
- icon: 'MaskIconWholeWord',
1653
- checked: matchWholeWord,
1654
- title: 'Match Whole Word'
1699
+ icon: MaskIconWholeWord,
1700
+ checked: matchWholeWord$1,
1701
+ title: matchWholeWord()
1655
1702
  }, {
1656
- icon: 'MaskIconRegex',
1657
- checked: useRegularExpression,
1658
- title: 'Use Regular Expression'
1703
+ icon: MaskIconRegex,
1704
+ checked: useRegularExpression$1,
1705
+ title: useRegularExpression()
1659
1706
  }], [])];
1660
1707
  if (replaceExpanded) {
1661
1708
  dom.push(...getSearchFieldVirtualDom('search-replace-value', 'Replace', 'handleReplaceInput', [{
1662
- icon: 'MaskIconPreserveCase',
1709
+ icon: MaskIconPreserveCase,
1663
1710
  checked: false,
1664
- title: 'Preserve Case'
1711
+ title: preserveCase()
1665
1712
  }], [{
1666
- icon: 'MaskIconReplaceAll',
1713
+ icon: MaskIconReplaceAll,
1667
1714
  checked: false,
1668
- title: 'Replace All'
1715
+ title: replaceAll$1()
1669
1716
  }]));
1670
1717
  }
1671
1718
  if (detailsExpanded) {
@@ -1697,12 +1744,18 @@ const getBadgeVirtualDom = (className, count) => {
1697
1744
  }, text(`${count}`)];
1698
1745
  };
1699
1746
 
1700
- const getChevronDownVirtualDom = (extraClassName = '') => {
1701
- return {
1702
- type: Div,
1703
- className: mergeClassNames(Chevron, MaskIconChevronDown, extraClassName),
1704
- childCount: 0
1705
- };
1747
+ const chevronDownVirtualDom = {
1748
+ type: Div,
1749
+ className: mergeClassNames(Chevron, MaskIconChevronDown),
1750
+ childCount: 0
1751
+ };
1752
+ ({
1753
+ type: Div,
1754
+ className: mergeClassNames(Chevron, MaskIconChevronRight),
1755
+ childCount: 0
1756
+ });
1757
+ const getChevronDownVirtualDom = () => {
1758
+ return chevronDownVirtualDom;
1706
1759
  };
1707
1760
 
1708
1761
  const getFileIconVirtualDom = icon => {
@@ -1825,21 +1878,17 @@ const getSearchResultsVirtualDom = visibleItems => {
1825
1878
  };
1826
1879
 
1827
1880
  const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWholeWord, useRegularExpression, message, detailsExpanded, focusOutline) => {
1828
- const dom = [];
1829
- dom.push({
1881
+ const dom = [{
1830
1882
  type: Div,
1831
1883
  className: mergeClassNames(Viewlet, Search$1),
1832
1884
  childCount: 2
1833
- });
1834
- dom.push(...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded));
1835
- dom.push({
1885
+ }, ...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded), {
1836
1886
  type: Div,
1837
1887
  className: ViewletSearchMessage,
1838
1888
  role: Status,
1839
1889
  tabIndex: 0,
1840
1890
  childCount: 1
1841
- }, text(message));
1842
- dom.push({
1891
+ }, text(message), {
1843
1892
  type: Div,
1844
1893
  className: mergeClassNames(Viewlet, List, focusOutline ? FocusOutline : Empty),
1845
1894
  role: Tree,
@@ -1847,8 +1896,7 @@ const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWhol
1847
1896
  childCount: visibleItems.length,
1848
1897
  onClick: HandleClick,
1849
1898
  onBlur: HandleListBlur
1850
- });
1851
- dom.push(...getSearchResultsVirtualDom(visibleItems));
1899
+ }, ...getSearchResultsVirtualDom(visibleItems)];
1852
1900
  return dom;
1853
1901
  };
1854
1902
 
@@ -2050,7 +2098,7 @@ const splitLines = lines => {
2050
2098
  return lines.split('\n');
2051
2099
  };
2052
2100
 
2053
- const textSearchInFile$1 = (file, content, query) => {
2101
+ const textSearchInText = (file, content, query) => {
2054
2102
  const results = [];
2055
2103
  const lines = splitLines(content);
2056
2104
  for (let i = 0; i < lines.length; i++) {
@@ -2077,6 +2125,7 @@ const textSearchInFile$1 = (file, content, query) => {
2077
2125
  }
2078
2126
  return results;
2079
2127
  };
2128
+
2080
2129
  const textSearch$4 = async (scheme, root, query, options, assetDir) => {
2081
2130
  string(scheme);
2082
2131
  string(root);
@@ -2089,15 +2138,38 @@ const textSearch$4 = async (scheme, root, query, options, assetDir) => {
2089
2138
  const fetchUri = `${assetDir}${uri}`;
2090
2139
  const content = await getText(fetchUri);
2091
2140
  const relativeUri = uri.slice(relativeRoot.length + 1);
2092
- const results = textSearchInFile$1(relativeUri, content, query);
2141
+ const results = textSearchInText(relativeUri, content, query);
2093
2142
  allResults.push(...results);
2094
2143
  }
2095
2144
  return allResults;
2096
2145
  };
2097
2146
 
2147
+ class FileNotFoundError extends Error {
2148
+ constructor(message) {
2149
+ super(message);
2150
+ this.name = 'FileNotFoundError';
2151
+ }
2152
+ }
2153
+
2098
2154
  const Directory = 'directory';
2099
2155
  const File = 'file';
2100
2156
 
2157
+ const getChildHandles$1 = async handle => {
2158
+ object(handle);
2159
+ // @ts-ignore
2160
+ const childHandles = handle.values();
2161
+ const handles = await fromAsync(childHandles);
2162
+ return handles;
2163
+ };
2164
+
2165
+ const getChildHandles = async handle => {
2166
+ try {
2167
+ return await getChildHandles$1(handle);
2168
+ } catch (error) {
2169
+ throw new VError(error, 'failed to get child handles');
2170
+ }
2171
+ };
2172
+
2101
2173
  const dirname = (pathSeparator, path) => {
2102
2174
  const index = path.lastIndexOf(pathSeparator);
2103
2175
  if (index === -1) {
@@ -2361,7 +2433,11 @@ replaceTraps(oldTraps => ({
2361
2433
  }));
2362
2434
 
2363
2435
  const state = {
2364
- dbVersion: 1};
2436
+ databases: Object.create(null),
2437
+ eventId: 0,
2438
+ dbVersion: 1,
2439
+ cachedDb: undefined
2440
+ };
2365
2441
 
2366
2442
  // TODO high memory usage in idb because of transactionDoneMap
2367
2443
 
@@ -2415,34 +2491,6 @@ const getFile = handle => {
2415
2491
  return handle.getFile();
2416
2492
  };
2417
2493
 
2418
- const textSearchInText = (file, content, query) => {
2419
- const results = [];
2420
- const lines = splitLines(content);
2421
- for (let i = 0; i < lines.length; i++) {
2422
- const line = lines[i];
2423
- const index = line.indexOf(query);
2424
- if (index !== -1) {
2425
- results.push({
2426
- type: Match,
2427
- text: line,
2428
- start: index,
2429
- end: index + query.length,
2430
- lineNumber: i
2431
- });
2432
- }
2433
- }
2434
- if (results.length > 0) {
2435
- results.unshift({
2436
- type: File$1,
2437
- text: file,
2438
- start: 0,
2439
- end: 0,
2440
- lineNumber: 0
2441
- });
2442
- }
2443
- return results;
2444
- };
2445
-
2446
2494
  const textSearchInFile = async (all, handle, absolutePath, query) => {
2447
2495
  try {
2448
2496
  const file = await getFile(handle);
@@ -2459,9 +2507,7 @@ const textSearchInFile = async (all, handle, absolutePath, query) => {
2459
2507
  };
2460
2508
 
2461
2509
  const textSearchRecursively = async (all, parent, handle, query) => {
2462
- const childHandles = [];
2463
- // TODO
2464
- // await FileSystemHtml.getChildHandles(handle)
2510
+ const childHandles = await getChildHandles(handle);
2465
2511
  const promises = [];
2466
2512
  for (const childHandle of childHandles) {
2467
2513
  const absolutePath = parent + '/' + childHandle.name;
@@ -2470,6 +2516,7 @@ const textSearchRecursively = async (all, parent, handle, query) => {
2470
2516
  promises.push(textSearchRecursively(all, absolutePath, childHandle, query));
2471
2517
  break;
2472
2518
  case File:
2519
+ // @ts-ignore
2473
2520
  promises.push(textSearchInFile(all, childHandle, absolutePath, query));
2474
2521
  break;
2475
2522
  }
@@ -2483,7 +2530,7 @@ const textSearch$3 = async (scheme, root, query) => {
2483
2530
  const relativeRoot = root.slice('html://'.length);
2484
2531
  const handle = await getDirectoryHandle(relativeRoot);
2485
2532
  if (!handle) {
2486
- throw new VError(`Folder not found ${relativeRoot}`);
2533
+ throw new FileNotFoundError(`Folder not found: ${relativeRoot}`);
2487
2534
  }
2488
2535
  const all = [];
2489
2536
  await textSearchRecursively(all, '', handle, query);
@@ -3110,7 +3157,7 @@ const getBulkReplacementEdits = (workspacePath, matches) => {
3110
3157
  ranges.push(currentRanges.length);
3111
3158
  push(ranges, currentRanges);
3112
3159
  const absolutePath = `${workspacePath}/${text.slice(2)}`;
3113
- files.push(absolutePath); // TODO
3160
+ files.push(absolutePath);
3114
3161
  currentRanges = [];
3115
3162
  break;
3116
3163
  case Match:
@@ -3126,12 +3173,18 @@ const getBulkReplacementEdits = (workspacePath, matches) => {
3126
3173
  };
3127
3174
  };
3128
3175
 
3129
- const replaceAll = async (workspacePath, items, replacement) => {
3176
+ const replaceAll = async state => {
3177
+ const {
3178
+ workspacePath,
3179
+ items,
3180
+ replacement
3181
+ } = state;
3130
3182
  const {
3131
3183
  files,
3132
3184
  ranges
3133
3185
  } = getBulkReplacementEdits(workspacePath, items);
3134
3186
  await invoke$1('BulkReplacement.applyBulkReplacement', files, ranges, replacement);
3187
+ return state;
3135
3188
  };
3136
3189
 
3137
3190
  const getReplaceAllConfirmText = (matchCount, fileCount, replacement) => {
@@ -3188,6 +3241,14 @@ const saveState = uid => {
3188
3241
  };
3189
3242
  };
3190
3243
 
3244
+ const focusElement = (state, focusKey) => {
3245
+ return {
3246
+ ...state,
3247
+ focus: focusKey,
3248
+ focusSource: Script
3249
+ };
3250
+ };
3251
+
3191
3252
  const setFocus = async focusKey => {
3192
3253
  await invoke$1('Focus.setFocus', focusKey);
3193
3254
  };
@@ -3214,11 +3275,7 @@ const getSearchFocusKey = key => {
3214
3275
  };
3215
3276
 
3216
3277
  const focusSearchValue = state => {
3217
- return {
3218
- ...state,
3219
- focus: FocusSearchInput,
3220
- focusSource: Script
3221
- };
3278
+ return focusElement(state, FocusSearchInput);
3222
3279
  };
3223
3280
  const focusMatchCasePrevious = state => {
3224
3281
  const {
@@ -3236,46 +3293,22 @@ const focusRegexNext = state => {
3236
3293
  return focusPreserveCase(state);
3237
3294
  };
3238
3295
  const focusReplaceValue = state => {
3239
- return {
3240
- ...state,
3241
- focus: FocusSearchReplaceInput,
3242
- focusSource: Script
3243
- };
3296
+ return focusElement(state, FocusSearchReplaceInput);
3244
3297
  };
3245
3298
  const focusMatchCase = state => {
3246
- return {
3247
- ...state,
3248
- focus: FocusSearchMatchCase,
3249
- focusSource: Script
3250
- };
3299
+ return focusElement(state, FocusSearchMatchCase);
3251
3300
  };
3252
3301
  const focusPreserveCase = state => {
3253
- return {
3254
- ...state,
3255
- focus: FocusSearchPreserveCase,
3256
- focusSource: Script
3257
- };
3302
+ return focusElement(state, FocusSearchPreserveCase);
3258
3303
  };
3259
3304
  const focusMatchWholeWord = state => {
3260
- return {
3261
- ...state,
3262
- focus: FocusSearchWholeWord,
3263
- focusSource: Script
3264
- };
3305
+ return focusElement(state, FocusSearchWholeWord);
3265
3306
  };
3266
3307
  const focusRegex = state => {
3267
- return {
3268
- ...state,
3269
- focus: FocusSearchRegex,
3270
- focusSource: Script
3271
- };
3308
+ return focusElement(state, FocusSearchRegex);
3272
3309
  };
3273
3310
  const focusReplaceAll = state => {
3274
- return {
3275
- ...state,
3276
- focus: FocusSearchReplaceAll,
3277
- focusSource: Script
3278
- };
3311
+ return focusElement(state, FocusSearchReplaceAll);
3279
3312
  };
3280
3313
  const handleFocusIn = (state, key) => {
3281
3314
  const focusKey = getSearchFocusKey(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "description": "Text Search Worker",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",