@lvce-editor/text-search-worker 3.10.0 → 3.11.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.
@@ -808,6 +808,8 @@ const FocusSearchWholeWord = 34;
808
808
  const FocusSearchReplaceAll = 35;
809
809
  const FocusSearchPreserveCase = 36;
810
810
  const FocusSearchIncludeInput = 1007;
811
+ const FocusSearchExcludeInput = 1008;
812
+ const FocusSearchResults = 22;
811
813
 
812
814
  const User = 1;
813
815
  const Script = 2;
@@ -965,59 +967,6 @@ const fromAsync = async asyncIterable => {
965
967
  return children;
966
968
  };
967
969
 
968
- class AssertionError extends Error {
969
- constructor(message) {
970
- super(message);
971
- this.name = 'AssertionError';
972
- }
973
- }
974
- const getType = value => {
975
- switch (typeof value) {
976
- case 'number':
977
- return 'number';
978
- case 'function':
979
- return 'function';
980
- case 'string':
981
- return 'string';
982
- case 'object':
983
- if (value === null) {
984
- return 'null';
985
- }
986
- if (Array.isArray(value)) {
987
- return 'array';
988
- }
989
- return 'object';
990
- case 'boolean':
991
- return 'boolean';
992
- default:
993
- return 'unknown';
994
- }
995
- };
996
- const object = value => {
997
- const type = getType(value);
998
- if (type !== 'object') {
999
- throw new AssertionError('expected value to be of type object');
1000
- }
1001
- };
1002
- const number = value => {
1003
- const type = getType(value);
1004
- if (type !== 'number') {
1005
- throw new AssertionError('expected value to be of type number');
1006
- }
1007
- };
1008
- const array = value => {
1009
- const type = getType(value);
1010
- if (type !== 'array') {
1011
- throw new AssertionError('expected value to be of type array');
1012
- }
1013
- };
1014
- const string = value => {
1015
- const type = getType(value);
1016
- if (type !== 'string') {
1017
- throw new AssertionError('expected value to be of type string');
1018
- }
1019
- };
1020
-
1021
970
  const emptyObject = {};
1022
971
  const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1023
972
  const i18nString = (key, placeholders = emptyObject) => {
@@ -1124,9 +1073,6 @@ const confirmReplaceManyOccurrencesInOneFileNoValue = matchCount => {
1124
1073
  });
1125
1074
  };
1126
1075
  const confirmReplaceManyOccurrencesInManyFiles = (matchCount, fileCount, replacement) => {
1127
- number(matchCount);
1128
- number(fileCount);
1129
- string(replacement);
1130
1076
  return i18nString(UiStrings.ConfirmReplaceManyOccurrencesInManyFiles, {
1131
1077
  PH1: matchCount,
1132
1078
  PH2: fileCount,
@@ -1134,8 +1080,6 @@ const confirmReplaceManyOccurrencesInManyFiles = (matchCount, fileCount, replace
1134
1080
  });
1135
1081
  };
1136
1082
  const confirmReplaceManyOccurrencesInManyFilesNoValue = (matchCount, fileCount) => {
1137
- number(matchCount);
1138
- number(fileCount);
1139
1083
  return i18nString(UiStrings.ConfirmReplaceManyOccurrencesInManyFilesNoValue, {
1140
1084
  PH1: matchCount,
1141
1085
  PH2: fileCount
@@ -1176,8 +1120,6 @@ const useExcludeSettings = () => {
1176
1120
  };
1177
1121
 
1178
1122
  const getStatusMessage = (resultCount, fileResultCount) => {
1179
- number(resultCount);
1180
- number(fileResultCount);
1181
1123
  if (resultCount === 0) {
1182
1124
  return noResults();
1183
1125
  }
@@ -1330,7 +1272,8 @@ const focusMatchCase$1 = state => {
1330
1272
  const focusReplaceValue$1 = state => {
1331
1273
  return {
1332
1274
  ...state,
1333
- focus: FocusSearchReplaceInput
1275
+ focus: FocusSearchReplaceInput,
1276
+ focusSource: Script
1334
1277
  };
1335
1278
  };
1336
1279
 
@@ -1491,6 +1434,83 @@ const getActionsVirtualDom = actions => {
1491
1434
  }, ...actions.flatMap(getActionVirtualDom)];
1492
1435
  };
1493
1436
 
1437
+ const Tab = 2;
1438
+ const Enter = 3;
1439
+ const End = 255;
1440
+ const Home = 12;
1441
+ const UpArrow = 14;
1442
+ const DownArrow = 16;
1443
+ const Delete = 18;
1444
+ const KeyC = 31;
1445
+
1446
+ const CtrlCmd = 1 << 11 >>> 0;
1447
+ const Shift = 1 << 10 >>> 0;
1448
+ const Alt = 1 << 9 >>> 0;
1449
+
1450
+ const getKeyBindings = () => {
1451
+ return [{
1452
+ key: CtrlCmd | Alt | Enter,
1453
+ command: 'Search.replaceAll',
1454
+ when: FocusSearchReplaceInput
1455
+ }, {
1456
+ key: DownArrow,
1457
+ command: 'Search.focusNext',
1458
+ when: FocusSearchResults
1459
+ }, {
1460
+ key: UpArrow,
1461
+ command: 'Search.focusPrevious',
1462
+ when: FocusSearchResults
1463
+ }, {
1464
+ key: Delete,
1465
+ command: 'Search.dismissItem',
1466
+ when: FocusSearchResults
1467
+ }, {
1468
+ key: Home,
1469
+ command: 'Search.focusFirst',
1470
+ when: FocusSearchResults
1471
+ }, {
1472
+ key: End,
1473
+ command: 'Search.focusLast',
1474
+ when: FocusSearchResults
1475
+ }, {
1476
+ key: CtrlCmd | KeyC,
1477
+ command: 'Search.copy',
1478
+ when: FocusSearchResults
1479
+ }, {
1480
+ key: Tab,
1481
+ command: 'Search.focusSearchValueNext',
1482
+ when: FocusSearchInput
1483
+ }, {
1484
+ key: Shift | Tab,
1485
+ command: 'Search.focusReplaceValuePrevious',
1486
+ when: FocusSearchReplaceInput
1487
+ }, {
1488
+ key: Tab,
1489
+ command: 'Search.focusReplaceValueNext',
1490
+ when: FocusSearchReplaceInput
1491
+ }, {
1492
+ key: Shift | Tab,
1493
+ command: 'Search.focusMatchCasePrevious',
1494
+ when: FocusSearchMatchCase
1495
+ }, {
1496
+ key: Tab,
1497
+ command: 'Search.focusRegexNext',
1498
+ when: FocusSearchRegex
1499
+ }, {
1500
+ key: Shift | Tab,
1501
+ command: 'Search.focusPreserveCasePrevious',
1502
+ when: FocusSearchPreserveCase
1503
+ }, {
1504
+ key: Enter,
1505
+ command: 'Search.submit',
1506
+ when: FocusSearchInput
1507
+ }, {
1508
+ key: Enter,
1509
+ command: 'Search.submit',
1510
+ when: FocusSearchReplaceInput
1511
+ }];
1512
+ };
1513
+
1494
1514
  const ClearAll = 'ClearAll';
1495
1515
  const CollapseAll = 'CollapseAll';
1496
1516
  const ListFlat = 'ListFlat';
@@ -1867,9 +1887,6 @@ const chevronDownVirtualDom = {
1867
1887
  className: mergeClassNames(Chevron, MaskIconChevronRight),
1868
1888
  childCount: 0
1869
1889
  });
1870
- const getChevronDownVirtualDom = () => {
1871
- return chevronDownVirtualDom;
1872
- };
1873
1890
 
1874
1891
  const getFileIconVirtualDom = icon => {
1875
1892
  return {
@@ -1966,7 +1983,7 @@ const getSearchResultVirtualDom = rowInfo => {
1966
1983
  dom.push(treeItem);
1967
1984
  if (type === File$1) {
1968
1985
  treeItem.childCount += 2;
1969
- dom.push(getChevronDownVirtualDom(), getFileIconVirtualDom(icon));
1986
+ dom.push(chevronDownVirtualDom, getFileIconVirtualDom(icon));
1970
1987
  }
1971
1988
  dom.push(...getLabelVirtualDom(displayText, matchLength, matchStart, replacement));
1972
1989
  if (matchCount) {
@@ -2007,6 +2024,10 @@ const getSearchVirtualDom = (visibleItems, flags, message, focusOutline) => {
2007
2024
  return dom;
2008
2025
  };
2009
2026
 
2027
+ const handleError = error => {
2028
+ console.error(`[text-search-worker] ${error}`);
2029
+ };
2030
+
2010
2031
  const getFileIcons = async files => {
2011
2032
  // TODO cache file icons
2012
2033
  const promises = [];
@@ -2022,24 +2043,6 @@ const getFileIcons = async files => {
2022
2043
  return icons;
2023
2044
  };
2024
2045
 
2025
- const handleIconThemeChange = async state => {
2026
- const {
2027
- items,
2028
- minLineY,
2029
- maxLineY
2030
- } = state;
2031
- const visibleItems = items.slice(minLineY, maxLineY);
2032
- const icons = await getFileIcons(visibleItems);
2033
- return {
2034
- ...state,
2035
- icons
2036
- };
2037
- };
2038
-
2039
- const handleError = error => {
2040
- console.error(`[text-search-worker] ${error}`);
2041
- };
2042
-
2043
2046
  // TODO optimize this function to return the minimum number
2044
2047
  // of visible items needed, e.g. when not scrolled 5 items with
2045
2048
  // 20px fill 100px but when scrolled 6 items are needed
@@ -2106,6 +2109,59 @@ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
2106
2109
  };
2107
2110
  };
2108
2111
 
2112
+ class AssertionError extends Error {
2113
+ constructor(message) {
2114
+ super(message);
2115
+ this.name = 'AssertionError';
2116
+ }
2117
+ }
2118
+ const getType = value => {
2119
+ switch (typeof value) {
2120
+ case 'number':
2121
+ return 'number';
2122
+ case 'function':
2123
+ return 'function';
2124
+ case 'string':
2125
+ return 'string';
2126
+ case 'object':
2127
+ if (value === null) {
2128
+ return 'null';
2129
+ }
2130
+ if (Array.isArray(value)) {
2131
+ return 'array';
2132
+ }
2133
+ return 'object';
2134
+ case 'boolean':
2135
+ return 'boolean';
2136
+ default:
2137
+ return 'unknown';
2138
+ }
2139
+ };
2140
+ const object = value => {
2141
+ const type = getType(value);
2142
+ if (type !== 'object') {
2143
+ throw new AssertionError('expected value to be of type object');
2144
+ }
2145
+ };
2146
+ const number = value => {
2147
+ const type = getType(value);
2148
+ if (type !== 'number') {
2149
+ throw new AssertionError('expected value to be of type number');
2150
+ }
2151
+ };
2152
+ const array = value => {
2153
+ const type = getType(value);
2154
+ if (type !== 'array') {
2155
+ throw new AssertionError('expected value to be of type array');
2156
+ }
2157
+ };
2158
+ const string = value => {
2159
+ const type = getType(value);
2160
+ if (type !== 'string') {
2161
+ throw new AssertionError('expected value to be of type string');
2162
+ }
2163
+ };
2164
+
2109
2165
  const RE_PROTOCOL = /^([a-z-\d]+):\/\//;
2110
2166
  const getProtocol = uri => {
2111
2167
  const protocolMatch = uri.match(RE_PROTOCOL);
@@ -2809,23 +2865,45 @@ const handleUpdate = async (state, update) => {
2809
2865
  }
2810
2866
  };
2811
2867
 
2812
- const handleInput = (state, value, inputSource = Script) => {
2868
+ const handleExcludeInput = (state, value, inputSource = Script) => {
2813
2869
  return handleUpdate(state, {
2814
- value,
2870
+ excludeValue: value,
2815
2871
  inputSource
2816
2872
  });
2817
2873
  };
2818
2874
 
2819
- const handleReplaceInput = (state, value, inputSource = Script) => {
2875
+ const handleIconThemeChange = async state => {
2876
+ const {
2877
+ items,
2878
+ minLineY,
2879
+ maxLineY
2880
+ } = state;
2881
+ const visibleItems = items.slice(minLineY, maxLineY);
2882
+ const icons = await getFileIcons(visibleItems);
2883
+ return {
2884
+ ...state,
2885
+ icons
2886
+ };
2887
+ };
2888
+
2889
+ const handleIncludeInput = (state, includeValue) => {
2890
+ return {
2891
+ ...state,
2892
+ includeValue,
2893
+ focusSource: User
2894
+ };
2895
+ };
2896
+
2897
+ const handleInput = (state, value, inputSource = Script) => {
2820
2898
  return handleUpdate(state, {
2821
- replacement: value,
2899
+ value,
2822
2900
  inputSource
2823
2901
  });
2824
2902
  };
2825
2903
 
2826
- const handleExcludeInput = (state, value, inputSource = Script) => {
2904
+ const handleReplaceInput = (state, value, inputSource = Script) => {
2827
2905
  return handleUpdate(state, {
2828
- excludeValue: value,
2906
+ replacement: value,
2829
2907
  inputSource
2830
2908
  });
2831
2909
  };
@@ -2848,14 +2926,6 @@ const handleSharedInput = (state, name, value, inputSource = Script) => {
2848
2926
  return fn(state, value, inputSource);
2849
2927
  };
2850
2928
 
2851
- const handleIncludeInput = (state, includeValue) => {
2852
- return {
2853
- ...state,
2854
- includeValue,
2855
- focusSource: User
2856
- };
2857
- };
2858
-
2859
2929
  const first = () => {
2860
2930
  return 0;
2861
2931
  };
@@ -3231,7 +3301,9 @@ const loadContent = async (state, savedState) => {
3231
3301
  savedCollapsedPaths,
3232
3302
  threads,
3233
3303
  replacement,
3234
- flags
3304
+ flags,
3305
+ includeValue,
3306
+ excludeValue
3235
3307
  } = restoreState(savedState);
3236
3308
  if (savedValue) {
3237
3309
  return handleUpdate(state, {
@@ -3240,7 +3312,9 @@ const loadContent = async (state, savedState) => {
3240
3312
  inputSource: Script,
3241
3313
  collapsedPaths: savedCollapsedPaths,
3242
3314
  replacement,
3243
- flags
3315
+ flags,
3316
+ includeValue,
3317
+ excludeValue
3244
3318
  });
3245
3319
  }
3246
3320
  return {
@@ -3270,6 +3344,8 @@ const getFocusSelector = focusKey => {
3270
3344
  return '[title="Use Regular Expression"]';
3271
3345
  case FocusSearchIncludeInput:
3272
3346
  return '[name="files-to-include-value"]';
3347
+ case FocusSearchExcludeInput:
3348
+ return '[name="files-to-exclude-value"]';
3273
3349
  default:
3274
3350
  return '';
3275
3351
  }
@@ -3308,10 +3384,29 @@ const renderReplacement = {
3308
3384
  return oldState.replacement === newState.replacement || newState.inputSource === User;
3309
3385
  },
3310
3386
  apply(oldState, newState) {
3311
- return ['Viewlet.send', newState.uid, 'setValue', newState.replacement, '[name="search-replace-value"]'];
3387
+ const selector = getFocusSelector(FocusSearchReplaceInput);
3388
+ return ['Viewlet.send', newState.uid, 'setValue', newState.replacement, selector];
3389
+ }
3390
+ };
3391
+ const renderIncludeValue = {
3392
+ isEqual(oldState, newState) {
3393
+ return oldState.includeValue === newState.includeValue || newState.inputSource === User;
3394
+ },
3395
+ apply(oldState, newState) {
3396
+ const selector = getFocusSelector(FocusSearchIncludeInput);
3397
+ return ['Viewlet.send', newState.uid, 'setValue', newState.includeValue, selector];
3312
3398
  }
3313
3399
  };
3314
- const render = [renderItems, renderValue, renderReplacement, renderFocus];
3400
+ const renderExcludeValue = {
3401
+ isEqual(oldState, newState) {
3402
+ return oldState.excludeValue === newState.excludeValue || newState.inputSource === User;
3403
+ },
3404
+ apply(oldState, newState) {
3405
+ const selector = getFocusSelector(FocusSearchExcludeInput);
3406
+ return ['Viewlet.send', newState.uid, 'setValue', newState.excludeValue, selector];
3407
+ }
3408
+ };
3409
+ const render = [renderItems, renderValue, renderIncludeValue, renderExcludeValue, renderReplacement, renderFocus];
3315
3410
  const doRender = uid => {
3316
3411
  const {
3317
3412
  oldState,
@@ -3474,6 +3569,9 @@ const focusMatchCasePrevious = state => {
3474
3569
  }
3475
3570
  return focusSearchValue(state);
3476
3571
  };
3572
+ const focusReplaceValuePrevious = state => {
3573
+ return focusSearchValue(state);
3574
+ };
3477
3575
  const focusReplaceValueNext = state => {
3478
3576
  return focusMatchCase(state);
3479
3577
  };
@@ -3525,22 +3623,29 @@ const toggleSearchFlag = (state, flag) => {
3525
3623
  };
3526
3624
  };
3527
3625
 
3528
- const toggleDetailsExpanded = state => {
3529
- const newState = toggleSearchFlag(state, DetailsExpanded);
3530
- if (hasDetailsExpanded(newState.flags)) {
3531
- return {
3532
- ...newState,
3533
- focus: FocusSearchIncludeInput,
3534
- focusSource: Script
3535
- };
3536
- }
3626
+ const collapseDetails = state => {
3537
3627
  return {
3538
- ...newState,
3628
+ ...toggleSearchFlag(state, DetailsExpanded),
3539
3629
  focus: FocusSearchInput,
3540
3630
  focusSource: Script
3541
3631
  };
3542
3632
  };
3543
3633
 
3634
+ const expandDetails = state => {
3635
+ return {
3636
+ ...toggleSearchFlag(state, DetailsExpanded),
3637
+ focus: FocusSearchIncludeInput,
3638
+ focusSource: Script
3639
+ };
3640
+ };
3641
+
3642
+ const toggleDetailsExpanded = state => {
3643
+ if (hasDetailsExpanded(state.flags)) {
3644
+ return collapseDetails(state);
3645
+ }
3646
+ return expandDetails(state);
3647
+ };
3648
+
3544
3649
  const toggleMatchCase = state => {
3545
3650
  return toggleSearchFlag(state, MatchCase);
3546
3651
  };
@@ -3633,6 +3738,7 @@ const commandMap = {
3633
3738
  'TextSearch.focusRegexNext': wrapCommand(focusRegexNext),
3634
3739
  'TextSearch.focusReplaceAll': wrapCommand(focusReplaceAll),
3635
3740
  'TextSearch.focusReplaceValue': wrapCommand(focusReplaceValue$1),
3741
+ 'TextSearch.focusReplaceValuePrevious': wrapCommand(focusReplaceValuePrevious),
3636
3742
  'TextSearch.focusReplaceValueNext': wrapCommand(focusReplaceValueNext),
3637
3743
  'TextSearch.focusSearchValue': wrapCommand(focusSearchValue$1),
3638
3744
  'TextSearch.focusSearchValueNext': wrapCommand(focusSearchValueNext),
@@ -3670,6 +3776,7 @@ const commandMap = {
3670
3776
  'TextSearch.create': create,
3671
3777
  'TextSearch.render': doRender,
3672
3778
  'TextSearch.saveState': saveState,
3779
+ 'TextSearch.getKeyBindings': getKeyBindings,
3673
3780
  // TODO needed?
3674
3781
  'TextSearch.textSearch': textSearch
3675
3782
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "description": "Text Search Worker",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",