@lvce-editor/text-search-worker 4.5.0 → 4.7.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.
@@ -1076,7 +1076,7 @@ const FocusSearchWholeWord = 34;
1076
1076
  const FocusToggleDetails = 1010;
1077
1077
  const FocusToggleReplace = 1020;
1078
1078
 
1079
- const clearSearchResults = state => {
1079
+ const clearSearchResults$1 = state => {
1080
1080
  return {
1081
1081
  ...state,
1082
1082
  value: '',
@@ -1089,6 +1089,10 @@ const clearSearchResults = state => {
1089
1089
  };
1090
1090
  };
1091
1091
 
1092
+ const collapseAll$1 = async state => {
1093
+ return state;
1094
+ };
1095
+
1092
1096
  const PreserveCase$2 = 1 << 0; // 1
1093
1097
  const UseRegularExpression$2 = 1 << 1; // 2
1094
1098
  const ReplaceExpanded = 1 << 2; // 4
@@ -1168,13 +1172,37 @@ const create$2 = () => {
1168
1172
  return Object.keys(states).map(key => {
1169
1173
  return Number.parseInt(key);
1170
1174
  });
1175
+ },
1176
+ clear() {
1177
+ for (const key of Object.keys(states)) {
1178
+ delete states[key];
1179
+ }
1180
+ },
1181
+ wrapCommand(fn) {
1182
+ const wrapped = async (uid, ...args) => {
1183
+ const {
1184
+ newState
1185
+ } = states[uid];
1186
+ const newerState = await fn(newState, ...args);
1187
+ if (newState === newerState) {
1188
+ return;
1189
+ }
1190
+ const latest = states[uid];
1191
+ states[uid] = {
1192
+ oldState: latest.oldState,
1193
+ newState: newerState
1194
+ };
1195
+ };
1196
+ return wrapped;
1171
1197
  }
1172
1198
  };
1173
1199
  };
1174
1200
 
1175
1201
  const {
1176
1202
  get,
1177
- set} = create$2();
1203
+ set,
1204
+ wrapCommand
1205
+ } = create$2();
1178
1206
 
1179
1207
  const create$1 = ({
1180
1208
  itemHeight,
@@ -1328,33 +1356,40 @@ const i18nString = (key, placeholders = emptyObject) => {
1328
1356
  return key.replaceAll(RE_PLACEHOLDER, replacer);
1329
1357
  };
1330
1358
 
1359
+ const ClearSearchResults = 'Clear Search Results';
1360
+ const CollapseAll$1 = 'Collapse All';
1331
1361
  const ConfirmReplaceManyOccurrencesInManyFiles = "Replace {PH1} occurrences across {PH2} files with '{PH3}'";
1332
1362
  const ConfirmReplaceManyOccurrencesInManyFilesNoValue = 'Replace {PH1} occurrences across {PH2} files';
1333
1363
  const ConfirmReplaceManyOccurrencesInOneFile = "Replace {PH1} occurrences across 1 file with '{PH2}'";
1334
1364
  const ConfirmReplaceManyOccurrencesInOneFileNoValue = 'Replace {PH1} occurrences across 1 file';
1335
1365
  const ConfirmReplaceOneOccurrenceInOneFile = "Replace 1 occurrence across 1 file with '{PH1}'";
1336
1366
  const ConfirmReplaceOneOccurrenceInOneFileNoValue = 'Replace 1 occurrence across 1 file';
1367
+ const Exclude = 'Exclude';
1337
1368
  const FilesToExclude$1 = 'Files to Exclude';
1338
1369
  const FilesToInclude$1 = 'Files to Include';
1370
+ const Include = 'Include';
1339
1371
  const ManyResultsInManyFiles = '{PH1} results in {PH2} files';
1340
1372
  const ManyResultsInOneFile = '{PH1} results in 1 file';
1341
1373
  const MatchCase$1 = 'Match Case';
1342
1374
  const MatchWholeWord$1 = 'Match Whole Word';
1343
1375
  const NoResults = 'No results found';
1344
1376
  const Oneresult = '1 result in 1 file';
1377
+ const OpenNewSearchEditor = 'Open New Search Editor';
1345
1378
  const PreserveCase$1 = 'Preserve Case';
1379
+ const Refresh$1 = 'Refresh';
1346
1380
  const Replace = 'Replace';
1347
1381
  const ReplaceAll$1 = 'Replace All';
1348
1382
  const ReplacedManyOccurrencesInManyFiles = "Replaced {PH1} occurrences across {PH2} files with '{PH3}'";
1349
1383
  const ReplacedOneOccurrenceInOneFile = "Replaced 1 occurrence across 1 file with '{PH1}'";
1384
+ const ReplaceForHistory = 'Replace (⇅ for history)';
1350
1385
  const Search$2 = 'Search';
1351
1386
  const SearchForHistory = 'Search (⇅ for history)';
1352
- const ReplaceForHistory = 'Replace (⇅ for history)';
1353
1387
  const SearchOnlyOpenEditors$1 = 'Search Only Open Editors';
1354
1388
  const ToggleReplace$1 = 'Toggle Replace';
1355
1389
  const ToggleSearchDetails$1 = 'Toggle Search Details';
1356
1390
  const UseExcludeSettings$1 = 'Use Exclude Settings';
1357
1391
  const UseRegularExpression$1 = 'Use Regular Expression';
1392
+ const ViewAsTree = 'View as Tree';
1358
1393
 
1359
1394
  const noResults = () => {
1360
1395
  return i18nString(NoResults);
@@ -1447,9 +1482,30 @@ const replaceAll$1 = () => {
1447
1482
  const replace = () => {
1448
1483
  return i18nString(Replace);
1449
1484
  };
1485
+ const refresh$1 = () => {
1486
+ return i18nString(Refresh$1);
1487
+ };
1488
+ const clearSearchResults = () => {
1489
+ return i18nString(ClearSearchResults);
1490
+ };
1491
+ const openNewSearchEditor = () => {
1492
+ return i18nString(OpenNewSearchEditor);
1493
+ };
1494
+ const viewAsTree$1 = () => {
1495
+ return i18nString(ViewAsTree);
1496
+ };
1497
+ const collapseAll = () => {
1498
+ return i18nString(CollapseAll$1);
1499
+ };
1450
1500
  const filesToInclude = () => {
1451
1501
  return i18nString(FilesToInclude$1);
1452
1502
  };
1503
+ const include = () => {
1504
+ return i18nString(Include);
1505
+ };
1506
+ const exclude = () => {
1507
+ return i18nString(Exclude);
1508
+ };
1453
1509
  const filesToExclude = () => {
1454
1510
  return i18nString(FilesToExclude$1);
1455
1511
  };
@@ -1750,7 +1806,7 @@ const focusSearchValueNext = state => {
1750
1806
  return focusMatchCase$1(state);
1751
1807
  };
1752
1808
 
1753
- const commandIds = ['clearSearchResults', 'collapseDetails', 'copy', 'dismissItem', 'expandDetails', 'focusFirst', 'focusIndex', 'focusLast', 'focusMatchCase', 'focusMatchCasePrevious', 'focusMatchWholeWord', 'focusNext', 'focusNextInput', 'focusNextPage', 'focusPreserveCasePrevious', 'focusPrevious', 'focusPreviousInput', 'focusPreviousPage', 'focusRegex', 'focusRegexNext', 'focusReplaceAll', 'focusReplaceValue', 'focusReplaceValueNext', 'focusReplaceValuePrevious', 'focusSearchValue', 'focusSearchValueNext', 'handleClick', 'handleClickAt', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleContextMenuMouseAt', 'handleExcludeInput', 'handleFocusIn', 'handleHeaderClick', 'handleHeaderFocusIn', 'handleHeaderFocusOut', 'handleIconThemeChange', 'handleIconThemeChange', 'handleIncludeInput', 'handleInput', 'handleInput2', 'handleListBlur', 'handleListFocus', 'handleReplaceInput', 'handleScrollBarCaptureLost', 'handleScrollBarClick', 'handleScrollBarMove', 'handleScrollBarThumbPointerMove', 'handleTouchEnd', 'handleTouchMove', 'handleTouchStart', 'handleUpdate', 'handleWheel', 'nextHistoryResult', 'previousHistoryResult', 'refresh', 'replaceAll', 'scrollDown', 'selectIndex', 'submit', 'toggleMatchCase', 'toggleMatchWholeWord', 'togglePreserveCase', 'toggleReplace', 'toggleSearchDetails', 'toggleUseRegularExpression'];
1809
+ const commandIds = ['clearSearchResults', 'collapseAll', 'collapseDetails', 'copy', 'dismissItem', 'dispose', 'expandDetails', 'focusFirst', 'focusIndex', 'focusLast', 'focusMatchCase', 'focusMatchCasePrevious', 'focusMatchWholeWord', 'focusNext', 'focusNextInput', 'focusNextPage', 'focusPreserveCasePrevious', 'focusPrevious', 'focusPreviousInput', 'focusPreviousPage', 'focusRegex', 'focusRegexNext', 'focusReplaceAll', 'focusReplaceValue', 'focusReplaceValueNext', 'focusReplaceValuePrevious', 'focusSearchValue', 'focusSearchValueNext', 'handleClick', 'handleClickAt', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleContextMenuMouseAt', 'handleExcludeInput', 'handleFocusIn', 'handleHeaderClick', 'handleHeaderFocusIn', 'handleHeaderFocusOut', 'handleIconThemeChange', 'handleIconThemeChange', 'handleIncludeInput', 'handleInput', 'handleInput2', 'handleListBlur', 'handleListFocus', 'handleReplaceInput', 'handleScrollBarCaptureLost', 'handleScrollBarClick', 'handleScrollBarMove', 'handleScrollBarThumbPointerMove', 'handleTouchEnd', 'handleTouchMove', 'handleTouchStart', 'handleUpdate', 'handleWheel', 'nextHistoryResult', 'previousHistoryResult', 'refresh', 'replaceAll', 'scrollDown', 'selectIndex', 'submit', 'toggleMatchCase', 'toggleMatchWholeWord', 'togglePreserveCase', 'toggleReplace', 'toggleSearchDetails', 'toggleUseRegularExpression', 'viewAsTree'];
1754
1810
 
1755
1811
  const getCommandIds = () => {
1756
1812
  return commandIds;
@@ -2865,13 +2921,17 @@ const selectIndexPreview = async (state, searchResult, index) => {
2865
2921
  const fileResult = items[fileIndex];
2866
2922
  const relativePath = getRelativePath(fileResult.text);
2867
2923
  const absolutePath = `${workspacePath}${relativePath}`;
2924
+ if (state.focus !== FocusSearchResults) {
2925
+ await setFocus(FocusSearchResults);
2926
+ }
2868
2927
  await openUri(absolutePath, true, {
2869
2928
  selections: new Uint32Array([lineNumber, 0, lineNumber, 0])
2870
2929
  });
2871
2930
  return {
2872
2931
  ...state,
2873
2932
  listFocusedIndex: index,
2874
- listFocused: false
2933
+ listFocused: false,
2934
+ focus: FocusSearchResults
2875
2935
  };
2876
2936
  };
2877
2937
 
@@ -3737,6 +3797,8 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
3737
3797
  const getSearchHeaderDetailsExpandedVirtualDom = (flags, message) => {
3738
3798
  const includeButtons = getInputActionsInclude(flags);
3739
3799
  const excludeButtons = getInputActionsExclude(flags);
3800
+ const includePlaceholder = include();
3801
+ const excludePlaceholder = exclude();
3740
3802
  return [{
3741
3803
  type: Div,
3742
3804
  className: SearchHeaderDetailsExpanded,
@@ -3749,11 +3811,11 @@ const getSearchHeaderDetailsExpandedVirtualDom = (flags, message) => {
3749
3811
  type: H4,
3750
3812
  className: SearchHeaderDetailsHeading,
3751
3813
  childCount: 1
3752
- }, text(filesToInclude()), ...getSearchFieldVirtualDom(FilesToInclude, 'Include', HandleInput2, includeButtons.inside, includeButtons.outside), {
3814
+ }, text(filesToInclude()), ...getSearchFieldVirtualDom(FilesToInclude, includePlaceholder, HandleInput2, includeButtons.inside, includeButtons.outside), {
3753
3815
  type: H4,
3754
3816
  className: SearchHeaderDetailsHeading,
3755
3817
  childCount: 1
3756
- }, text(filesToExclude()), ...getSearchFieldVirtualDom(FilesToExclude, 'Exclude', HandleInput2, excludeButtons.inside, excludeButtons.outside), ...getSearchMessageVirtualDom(message, false)];
3818
+ }, text(filesToExclude()), ...getSearchFieldVirtualDom(FilesToExclude, excludePlaceholder, HandleInput2, excludeButtons.inside, excludeButtons.outside), ...getSearchMessageVirtualDom(message, false)];
3757
3819
  };
3758
3820
 
3759
3821
  const getSearchHeaderDetailsVirtualDom = (flags, message) => {
@@ -3820,19 +3882,19 @@ const getSearchPlaceholder = focus => {
3820
3882
  return search();
3821
3883
  };
3822
3884
 
3823
- const getSearchToggleVirtualDom = flags => {
3885
+ const getSearchToggleVirtualDom = replaceExpanded => {
3824
3886
  return [{
3825
3887
  type: Button$1,
3826
- className: mergeClassNames(IconButton, SearchToggleButton, flags & ReplaceExpanded ? SearchToggleButtonExpanded : ''),
3888
+ className: mergeClassNames(IconButton, SearchToggleButton, replaceExpanded ? SearchToggleButtonExpanded : ''),
3827
3889
  title: toggleReplace$1(),
3828
3890
  ariaLabel: toggleReplace$1(),
3829
- ariaExpanded: Boolean(flags & ReplaceExpanded),
3891
+ ariaExpanded: Boolean(replaceExpanded),
3830
3892
  childCount: 1,
3831
3893
  'data-command': 'toggleReplace',
3832
3894
  name: ToggleReplace
3833
3895
  }, {
3834
3896
  type: Div,
3835
- className: mergeClassNames(MaskIcon, flags & ReplaceExpanded ? MaskIconChevronDown : MaskIconChevronRight),
3897
+ className: mergeClassNames(MaskIcon, replaceExpanded ? MaskIconChevronDown : MaskIconChevronRight),
3836
3898
  childCount: 0
3837
3899
  }];
3838
3900
  };
@@ -3842,16 +3904,17 @@ const getSearchHeaderTopVirtualDom = (flags, searchInputErrorMessage, matchCount
3842
3904
  const replaceActions = getInputActionsReplace(flags, matchCount);
3843
3905
  const searchPlaceholder = getSearchPlaceholder(focus);
3844
3906
  const replacePlaceholder = getReplacePlaceholder(focus);
3907
+ const replaceExpanded = flags & ReplaceExpanded;
3845
3908
  const dom = [{
3846
3909
  type: Div,
3847
3910
  className: SearchHeaderTop,
3848
3911
  role: None,
3849
3912
  childCount: 2
3850
- }, ...getSearchToggleVirtualDom(flags), {
3913
+ }, ...getSearchToggleVirtualDom(replaceExpanded), {
3851
3914
  type: Div,
3852
3915
  className: SearchHeaderTopRight,
3853
3916
  role: None,
3854
- childCount: flags & ReplaceExpanded ? 2 : 1
3917
+ childCount: replaceExpanded ? 2 : 1
3855
3918
  }, ...getSearchFieldVirtualDom(SearchValue, searchPlaceholder, HandleInput2, inputActions.inside, inputActions.outside, '', Boolean(searchInputErrorMessage))];
3856
3919
  if (flags & ReplaceExpanded) {
3857
3920
  dom.push(...getSearchFieldVirtualDom(ReplaceValue, replacePlaceholder, HandleInput2, replaceActions.inside, replaceActions.outside));
@@ -4069,6 +4132,7 @@ const getTreeItemsVirtualDom = (visibleItems, deltaY, itemHeight) => {
4069
4132
  onClick: HandleClick,
4070
4133
  onBlur: HandleListBlur,
4071
4134
  onWheel: HandleWheel,
4135
+ onContextMenu: HandleContextMenu,
4072
4136
  id: TreeItems,
4073
4137
  top: `${-pixelOffset}px`
4074
4138
  }, ...visibleItems.flatMap(getSearchResultVirtualDom)];
@@ -4198,15 +4262,43 @@ const getActionsVirtualDom = actions => {
4198
4262
  }, ...actions.flatMap(getActionVirtualDom)];
4199
4263
  };
4200
4264
 
4265
+ const ClearAll = 'ClearAll';
4266
+ const CollapseAll = 'CollapseAll';
4267
+ const ListFlat = 'ListFlat';
4268
+ const NewFile = 'NewFile';
4269
+ const Refresh = 'Refresh';
4270
+
4271
+ const getActions = () => {
4272
+ return [{
4273
+ type: Button,
4274
+ id: refresh$1(),
4275
+ icon: Refresh,
4276
+ command: 'refresh'
4277
+ }, {
4278
+ type: Button,
4279
+ id: clearSearchResults(),
4280
+ icon: ClearAll,
4281
+ command: 'clearSearchResults'
4282
+ }, {
4283
+ type: Button,
4284
+ id: openNewSearchEditor(),
4285
+ icon: NewFile,
4286
+ command: ''
4287
+ }, {
4288
+ type: Button,
4289
+ id: viewAsTree$1(),
4290
+ icon: ListFlat,
4291
+ command: ''
4292
+ }, {
4293
+ type: Button,
4294
+ id: collapseAll(),
4295
+ icon: CollapseAll,
4296
+ command: ''
4297
+ }];
4298
+ };
4299
+
4201
4300
  const renderActions = uid => {
4202
- const {
4203
- oldState,
4204
- newState
4205
- } = get(uid);
4206
- if (oldState === newState) {
4207
- return [];
4208
- }
4209
- const actions = [];
4301
+ const actions = getActions();
4210
4302
  const dom = getActionsVirtualDom(actions);
4211
4303
  return dom;
4212
4304
  };
@@ -4462,6 +4554,10 @@ const terminate = () => {
4462
4554
  globalThis.close();
4463
4555
  };
4464
4556
 
4557
+ const viewAsTree = async state => {
4558
+ return state;
4559
+ };
4560
+
4465
4561
  const Keyboard = -1;
4466
4562
 
4467
4563
  const show = async (x, y, id, ...args) => {
@@ -4506,24 +4602,10 @@ const handleContextMenu = async (state, button, x, y) => {
4506
4602
  return newState;
4507
4603
  };
4508
4604
 
4509
- const wrapCommand = fn => {
4510
- const wrapped = async (uid, ...args) => {
4511
- const {
4512
- newState
4513
- } = get(uid);
4514
- const newerState = await fn(newState, ...args);
4515
- if (newState === newerState) {
4516
- return;
4517
- }
4518
- const latest = get(uid);
4519
- set(uid, latest.oldState, newerState);
4520
- };
4521
- return wrapped;
4522
- };
4523
-
4524
4605
  const commandMap = {
4525
- 'TextSearch.clearSearchResults': wrapCommand(clearSearchResults),
4606
+ 'TextSearch.clearSearchResults': wrapCommand(clearSearchResults$1),
4526
4607
  'TextSearch.collapseDetails': wrapCommand(collapseDetails),
4608
+ 'TextSearch.collapseAll': wrapCommand(collapseAll$1),
4527
4609
  'TextSearch.copy': wrapCommand(copy),
4528
4610
  'TextSearch.diff2': diff2,
4529
4611
  'TextSearch.dismissItem': wrapCommand(dismissItem),
@@ -4550,8 +4632,8 @@ const commandMap = {
4550
4632
  'TextSearch.focusReplaceValuePrevious': wrapCommand(focusReplaceValuePrevious),
4551
4633
  'TextSearch.focusSearchValue': wrapCommand(focusSearchValue$1),
4552
4634
  'TextSearch.focusSearchValueNext': wrapCommand(focusSearchValueNext),
4553
- 'TextSearch.getCommandIds': getCommandIds,
4554
4635
  'TextSearch.handleClickAt': wrapCommand(handleClickAt),
4636
+ 'TextSearch.viewAsTree': wrapCommand(viewAsTree),
4555
4637
  'TextSearch.handleContextMenu': wrapCommand(handleContextMenu),
4556
4638
  'TextSearch.handleExcludeInput': wrapCommand(handleExcludeInput),
4557
4639
  'TextSearch.handleFocusIn': wrapCommand(handleFocusIn),
@@ -4574,7 +4656,6 @@ const commandMap = {
4574
4656
  'TextSearch.nextHistoryResult': wrapCommand(nextHistoryResult),
4575
4657
  'TextSearch.previousHistoryResult': wrapCommand(previousHistoryResult),
4576
4658
  'TextSearch.refresh': wrapCommand(refresh),
4577
- 'TextSearch.renderActions': renderActions,
4578
4659
  'TextSearch.replaceAll': wrapCommand(replaceAll),
4579
4660
  'TextSearch.selectIndex': wrapCommand(selectIndex),
4580
4661
  'TextSearch.submit': wrapCommand(submit),
@@ -4588,6 +4669,7 @@ const commandMap = {
4588
4669
  'TextSearch.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression),
4589
4670
  // not wrapped
4590
4671
  'TextSearch.create': create,
4672
+ 'TextSearch.getCommandIds': getCommandIds,
4591
4673
  'TextSearch.getKeyBindings': getKeyBindings,
4592
4674
  'TextSearch.render2': render2,
4593
4675
  'TextSearch.renderEventListeners': renderEventListeners,
@@ -4595,6 +4677,7 @@ const commandMap = {
4595
4677
  'TextSearch.restoreState': restoreState,
4596
4678
  'TextSearch.saveState': saveState,
4597
4679
  'TextSearch.terminate': terminate,
4680
+ 'TextSearch.renderActions': renderActions,
4598
4681
  // TODO needed?
4599
4682
  'TextSearch.replaceAllAndPrompt': replaceAllAndPrompt,
4600
4683
  'TextSearch.textSearch': textSearch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "4.5.0",
3
+ "version": "4.7.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"