@lvce-editor/text-search-worker 3.4.0 → 3.6.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.
@@ -883,13 +883,13 @@ const FocusSearchWholeWord = 34;
883
883
  const FocusSearchReplaceAll = 35;
884
884
  const FocusSearchPreserveCase = 36;
885
885
 
886
- const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight) => {
886
+ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, value = '', replacement = '') => {
887
887
  const state = {
888
888
  uid,
889
889
  searchResults: [],
890
890
  stats: {},
891
891
  searchId: -1,
892
- value: '',
892
+ value,
893
893
  disposed: false,
894
894
  fileCount: 0,
895
895
  x,
@@ -902,11 +902,7 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight) =
902
902
  headerHeight: 61 // TODO
903
903
  }),
904
904
  threads: 0,
905
- replaceExpanded: false,
906
- useRegularExpression: false,
907
- matchCase: false,
908
- matchWholeWord: false,
909
- replacement: '',
905
+ replacement,
910
906
  matchCount: 0,
911
907
  listFocused: false,
912
908
  listFocusedIndex: -1,
@@ -914,7 +910,6 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight) =
914
910
  workspacePath: workspacePath,
915
911
  includeValue: '',
916
912
  excludeValue: '',
917
- detailsExpanded: false,
918
913
  focus: Empty$1,
919
914
  loaded: false,
920
915
  message: '',
@@ -927,7 +922,7 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight) =
927
922
  focusedIndex: -1,
928
923
  handleOffset: 0,
929
924
  focusSource: User,
930
- preserveCase: false
925
+ flags: 0
931
926
  };
932
927
  set(uid, state, state);
933
928
  return state;
@@ -1323,11 +1318,34 @@ const focusSearchValue$1 = state => {
1323
1318
  };
1324
1319
  };
1325
1320
 
1321
+ const PreserveCase = 1 << 0; // 1
1322
+ const UseRegularExpression = 1 << 1; // 2
1323
+ const ReplaceExpanded = 1 << 2; // 4
1324
+ const MatchWholeWord = 1 << 3; // 8
1325
+ const MatchCase = 1 << 4; // 16
1326
+ const DetailsExpanded = 1 << 5; // 32
1327
+
1328
+ const hasPreserveCase = flags => {
1329
+ return (flags & PreserveCase) === PreserveCase;
1330
+ };
1331
+ const hasUseRegularExpression = flags => {
1332
+ return (flags & UseRegularExpression) === UseRegularExpression;
1333
+ };
1334
+ const hasReplaceExpanded = flags => {
1335
+ return (flags & ReplaceExpanded) === ReplaceExpanded;
1336
+ };
1337
+ const hasMatchWholeWord = flags => {
1338
+ return (flags & MatchWholeWord) === MatchWholeWord;
1339
+ };
1340
+ const hasMatchCase = flags => {
1341
+ return (flags & MatchCase) === MatchCase;
1342
+ };
1343
+ const hasDetailsExpanded = flags => {
1344
+ return (flags & DetailsExpanded) === DetailsExpanded;
1345
+ };
1346
+
1326
1347
  const focusSearchValueNext = state => {
1327
- const {
1328
- replaceExpanded
1329
- } = state;
1330
- if (replaceExpanded) {
1348
+ if (hasReplaceExpanded(state.flags)) {
1331
1349
  return focusReplaceValue$1(state);
1332
1350
  }
1333
1351
  return focusMatchCase$1(state);
@@ -1659,12 +1677,12 @@ const text = data => {
1659
1677
  };
1660
1678
  };
1661
1679
 
1662
- const getSearchHeaderVirtualDom = (replaceExpanded, matchCase$1, matchWholeWord$1, useRegularExpression$1, detailsExpanded) => {
1680
+ const getSearchHeaderVirtualDom = flags => {
1663
1681
  const dom = [{
1664
1682
  type: Div,
1665
1683
  className: SearchHeader,
1666
1684
  role: None,
1667
- childCount: 2,
1685
+ childCount: hasDetailsExpanded(flags) ? 3 : 2,
1668
1686
  onClick: HandleHeaderClick,
1669
1687
  onFocusIn: HandleHeaderFocusIn
1670
1688
  }, {
@@ -1674,38 +1692,38 @@ const getSearchHeaderVirtualDom = (replaceExpanded, matchCase$1, matchWholeWord$
1674
1692
  childCount: 2
1675
1693
  }, {
1676
1694
  type: Button,
1677
- className: mergeClassNames(IconButton, SearchToggleButton, replaceExpanded ? SearchToggleButtonExpanded : ''),
1695
+ className: mergeClassNames(IconButton, SearchToggleButton, hasReplaceExpanded(flags) ? SearchToggleButtonExpanded : ''),
1678
1696
  title: toggleReplace$1(),
1679
1697
  ariaLabel: toggleReplace$1(),
1680
- ariaExpanded: replaceExpanded,
1698
+ ariaExpanded: hasReplaceExpanded(flags),
1681
1699
  childCount: 1,
1682
1700
  'data-command': 'toggleReplace'
1683
1701
  }, {
1684
1702
  type: Div,
1685
- className: mergeClassNames(MaskIcon, replaceExpanded ? MaskIconChevronDown : MaskIconChevronRight),
1703
+ className: mergeClassNames(MaskIcon, hasReplaceExpanded(flags) ? MaskIconChevronDown : MaskIconChevronRight),
1686
1704
  childCount: 0
1687
1705
  }, {
1688
1706
  type: Div,
1689
1707
  className: SearchHeaderTopRight,
1690
1708
  role: None,
1691
- childCount: replaceExpanded ? 2 : 1
1709
+ childCount: hasReplaceExpanded(flags) ? 2 : 1
1692
1710
  }, ...getSearchFieldVirtualDom('search-value', 'Search', 'handleInput', [{
1693
1711
  icon: MaskIconCaseSensitive,
1694
- checked: matchCase$1,
1712
+ checked: hasMatchCase(flags),
1695
1713
  title: matchCase()
1696
1714
  }, {
1697
1715
  icon: MaskIconWholeWord,
1698
- checked: matchWholeWord$1,
1716
+ checked: hasMatchWholeWord(flags),
1699
1717
  title: matchWholeWord()
1700
1718
  }, {
1701
1719
  icon: MaskIconRegex,
1702
- checked: useRegularExpression$1,
1720
+ checked: hasUseRegularExpression(flags),
1703
1721
  title: useRegularExpression()
1704
1722
  }], [])];
1705
- if (replaceExpanded) {
1723
+ if (hasReplaceExpanded(flags)) {
1706
1724
  dom.push(...getSearchFieldVirtualDom('search-replace-value', 'Replace', 'handleReplaceInput', [{
1707
1725
  icon: MaskIconPreserveCase,
1708
- checked: false,
1726
+ checked: hasPreserveCase(flags),
1709
1727
  title: preserveCase()
1710
1728
  }], [{
1711
1729
  icon: MaskIconReplaceAll,
@@ -1713,10 +1731,7 @@ const getSearchHeaderVirtualDom = (replaceExpanded, matchCase$1, matchWholeWord$
1713
1731
  title: replaceAll$1()
1714
1732
  }]));
1715
1733
  }
1716
- if (detailsExpanded) {
1717
- console.log({
1718
- detailsExpanded
1719
- });
1734
+ if (hasDetailsExpanded(flags)) {
1720
1735
  // @ts-ignore
1721
1736
  dom[0].childCount++;
1722
1737
  dom.push({
@@ -1875,12 +1890,12 @@ const getSearchResultsVirtualDom = visibleItems => {
1875
1890
  return visibleItems.flatMap(getSearchResultVirtualDom);
1876
1891
  };
1877
1892
 
1878
- const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWholeWord, useRegularExpression, message, detailsExpanded, focusOutline) => {
1893
+ const getSearchVirtualDom = (visibleItems, flags, message, focusOutline) => {
1879
1894
  const dom = [{
1880
1895
  type: Div,
1881
1896
  className: mergeClassNames(Viewlet, Search$1),
1882
1897
  childCount: 2
1883
- }, ...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded), {
1898
+ }, ...getSearchHeaderVirtualDom(flags), {
1884
1899
  type: Div,
1885
1900
  className: ViewletSearchMessage,
1886
1901
  role: Status,
@@ -1898,21 +1913,6 @@ const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWhol
1898
1913
  return dom;
1899
1914
  };
1900
1915
 
1901
- const handleIconThemeChange = state => {
1902
- const {
1903
- items
1904
- } = state;
1905
- const newItems = [...items];
1906
- return {
1907
- ...state,
1908
- items: newItems
1909
- };
1910
- };
1911
-
1912
- const handleError = error => {
1913
- console.error(`[text-search-worker] ${error}`);
1914
- };
1915
-
1916
1916
  const getFileIcons = async files => {
1917
1917
  // TODO cache file icons
1918
1918
  const promises = [];
@@ -1928,6 +1928,24 @@ const getFileIcons = async files => {
1928
1928
  return icons;
1929
1929
  };
1930
1930
 
1931
+ const handleIconThemeChange = async state => {
1932
+ const {
1933
+ items,
1934
+ minLineY,
1935
+ maxLineY
1936
+ } = state;
1937
+ const visibleItems = items.slice(minLineY, maxLineY);
1938
+ const icons = await getFileIcons(visibleItems);
1939
+ return {
1940
+ ...state,
1941
+ icons
1942
+ };
1943
+ };
1944
+
1945
+ const handleError = error => {
1946
+ console.error(`[text-search-worker] ${error}`);
1947
+ };
1948
+
1931
1949
  // TODO optimize this function to return the minimum number
1932
1950
  // of visible items needed, e.g. when not scrolled 5 items with
1933
1951
  // 20px fill 100px but when scrolled 6 items are needed
@@ -2628,10 +2646,9 @@ const handleUpdate = async (state, update) => {
2628
2646
  itemHeight,
2629
2647
  minimumSliderSize,
2630
2648
  headerHeight,
2631
- matchCase,
2649
+ flags,
2632
2650
  value,
2633
- threads,
2634
- useRegularExpression
2651
+ threads
2635
2652
  } = partialNewState;
2636
2653
  if (isEmptyString(value)) {
2637
2654
  return {
@@ -2640,7 +2657,6 @@ const handleUpdate = async (state, update) => {
2640
2657
  maxLineY: 0,
2641
2658
  deltaY: 0,
2642
2659
  items: [],
2643
- matchIndex: 0,
2644
2660
  matchCount: 0,
2645
2661
  message: '',
2646
2662
  loaded: true
@@ -2649,8 +2665,8 @@ const handleUpdate = async (state, update) => {
2649
2665
  const root = state.workspacePath;
2650
2666
  const results = await textSearch(root, value, {
2651
2667
  threads,
2652
- isCaseSensitive: matchCase,
2653
- useRegularExpression
2668
+ isCaseSensitive: hasMatchCase(flags),
2669
+ useRegularExpression: hasUseRegularExpression(flags)
2654
2670
  }, state.assetDir);
2655
2671
  if (!Array.isArray(results)) {
2656
2672
  throw new TypeError('results must be of type array');
@@ -3047,31 +3063,25 @@ const getSavedValue = savedState => {
3047
3063
  }
3048
3064
  return '';
3049
3065
  };
3050
- const getSavedReplaceExpanded = savedState => {
3051
- if (savedState && typeof savedState === 'object' && 'replaceExpanded' in savedState && typeof savedState.replaceExpanded === 'boolean') {
3052
- return savedState.replaceExpanded;
3066
+ const getSavedReplacement = savedState => {
3067
+ if (savedState && typeof savedState === 'object' && 'replacement' in savedState && typeof savedState.replacement === 'string') {
3068
+ return savedState.replacement;
3053
3069
  }
3054
- return false;
3070
+ return '';
3055
3071
  };
3056
- const getSavedCollapsedPaths = savedState => {
3057
- if (savedState && typeof savedState === 'object' && 'collapsedPaths' in savedState && Array.isArray(savedState.collapsedPaths) && savedState.collapsedPaths.every(path => typeof path === 'string')) {
3058
- return savedState.collapsedPaths;
3072
+ const getSavedFlags = savedState => {
3073
+ if (savedState && typeof savedState === 'object' && 'flags' in savedState && typeof savedState.flags === 'number') {
3074
+ return savedState.flags;
3059
3075
  }
3060
- return [];
3061
- };
3062
- const getThreads = () => {
3063
- return 1;
3076
+ return 0;
3064
3077
  };
3065
3078
  const restoreState = savedState => {
3066
- const savedValue = getSavedValue(savedState);
3067
- const savedReplaceExpanded = getSavedReplaceExpanded(savedState);
3068
- const savedCollapsedPaths = getSavedCollapsedPaths(savedState);
3069
- const threads = getThreads();
3070
3079
  return {
3071
- savedCollapsedPaths,
3072
- savedReplaceExpanded,
3073
- savedValue,
3074
- threads
3080
+ savedValue: getSavedValue(savedState),
3081
+ replacement: getSavedReplacement(savedState),
3082
+ savedCollapsedPaths: [],
3083
+ threads: 1,
3084
+ flags: getSavedFlags(savedState)
3075
3085
  };
3076
3086
  };
3077
3087
 
@@ -3079,22 +3089,24 @@ const loadContent = async (state, savedState) => {
3079
3089
  const {
3080
3090
  savedValue,
3081
3091
  savedCollapsedPaths,
3082
- savedReplaceExpanded,
3083
- threads
3092
+ threads,
3093
+ replacement,
3094
+ flags
3084
3095
  } = restoreState(savedState);
3085
3096
  if (savedValue) {
3086
3097
  return handleUpdate(state, {
3087
3098
  value: savedValue,
3088
3099
  threads,
3089
- replaceExpanded: savedReplaceExpanded,
3090
3100
  inputSource: Script,
3091
- collapsedPaths: savedCollapsedPaths
3101
+ collapsedPaths: savedCollapsedPaths,
3102
+ replacement,
3103
+ flags
3092
3104
  });
3093
3105
  }
3094
3106
  return {
3095
3107
  ...state,
3096
3108
  threads,
3097
- replaceExpanded: savedReplaceExpanded,
3109
+ flags,
3098
3110
  loaded: true
3099
3111
  };
3100
3112
  };
@@ -3105,12 +3117,12 @@ const refresh = state => {
3105
3117
 
3106
3118
  const renderItems = {
3107
3119
  isEqual(oldState, newState) {
3108
- return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.replacement === newState.replacement && oldState.replaceExpanded === newState.replaceExpanded && oldState.matchCase === newState.matchCase && oldState.matchWholeWord === newState.matchWholeWord && oldState.useRegularExpression === newState.useRegularExpression && oldState.message === newState.message && oldState.detailsExpanded === newState.detailsExpanded && oldState.loaded === newState.loaded && oldState.collapsedPaths === newState.collapsedPaths && oldState.listFocusedIndex === newState.listFocusedIndex && oldState.listFocused === newState.listFocused;
3120
+ 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;
3109
3121
  },
3110
3122
  apply(oldState, newState) {
3111
3123
  const displayResults = getDisplayResults(newState.items, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.collapsedPaths, newState.icons, newState.focusedIndex);
3112
3124
  const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
3113
- const dom = getSearchVirtualDom(displayResults, newState.replaceExpanded, newState.matchCase, newState.matchWholeWord, newState.useRegularExpression, newState.message, newState.detailsExpanded, focusOutline);
3125
+ const dom = getSearchVirtualDom(displayResults, newState.flags, newState.message, focusOutline);
3114
3126
  return ['Viewlet.setDom2', newState.uid, dom];
3115
3127
  }
3116
3128
  };
@@ -3139,7 +3151,23 @@ const renderFocus = {
3139
3151
  return ['Viewlet.send', newState.uid, 'setFocus', selector, newState.focusSource];
3140
3152
  }
3141
3153
  };
3142
- const render = [renderItems, renderFocus];
3154
+ const renderValue = {
3155
+ isEqual(oldState, newState) {
3156
+ return oldState.value === newState.value || newState.inputSource === User;
3157
+ },
3158
+ apply(oldState, newState) {
3159
+ return ['Viewlet.send', newState.uid, 'setValue', newState.value, '[name="search-value"]'];
3160
+ }
3161
+ };
3162
+ const renderReplacement = {
3163
+ isEqual(oldState, newState) {
3164
+ return oldState.replacement === newState.replacement || newState.inputSource === User;
3165
+ },
3166
+ apply(oldState, newState) {
3167
+ return ['Viewlet.send', newState.uid, 'setValue', newState.replacement, '[name="search-replace-value"]'];
3168
+ }
3169
+ };
3170
+ const render = [renderItems, renderFocus, renderValue, renderReplacement];
3143
3171
  const doRender = uid => {
3144
3172
  const {
3145
3173
  oldState,
@@ -3246,11 +3274,13 @@ const saveState = uid => {
3246
3274
  } = get(uid);
3247
3275
  const {
3248
3276
  value,
3249
- replaceExpanded
3277
+ replacement,
3278
+ flags
3250
3279
  } = newState;
3251
3280
  return {
3252
3281
  value,
3253
- replaceExpanded
3282
+ replacement,
3283
+ flags
3254
3284
  };
3255
3285
  };
3256
3286
 
@@ -3291,10 +3321,7 @@ const focusSearchValue = state => {
3291
3321
  return focusElement(state, FocusSearchInput);
3292
3322
  };
3293
3323
  const focusMatchCasePrevious = state => {
3294
- const {
3295
- replaceExpanded
3296
- } = state;
3297
- if (replaceExpanded) {
3324
+ if (hasReplaceExpanded(state.flags)) {
3298
3325
  return focusReplaceValue(state);
3299
3326
  }
3300
3327
  return focusSearchValue(state);
@@ -3343,54 +3370,31 @@ const submit = state => {
3343
3370
  });
3344
3371
  };
3345
3372
 
3346
- const toggleMatchCase = state => {
3347
- const {
3348
- matchCase
3349
- } = state;
3373
+ const toggleSearchFlag = (state, flag) => {
3350
3374
  return {
3351
3375
  ...state,
3352
- matchCase: !matchCase
3376
+ flags: state.flags ^ flag
3353
3377
  };
3354
3378
  };
3355
3379
 
3380
+ const toggleMatchCase = state => {
3381
+ return toggleSearchFlag(state, MatchCase);
3382
+ };
3383
+
3356
3384
  const toggleMatchWholeWord = state => {
3357
- const {
3358
- matchWholeWord
3359
- } = state;
3360
- return {
3361
- ...state,
3362
- matchWholeWord: !matchWholeWord
3363
- };
3385
+ return toggleSearchFlag(state, MatchWholeWord);
3364
3386
  };
3365
3387
 
3366
3388
  const togglePreserveCase = state => {
3367
- const {
3368
- preserveCase
3369
- } = state;
3370
- return {
3371
- ...state,
3372
- preserveCase: !preserveCase
3373
- };
3389
+ return toggleSearchFlag(state, PreserveCase);
3374
3390
  };
3375
3391
 
3376
3392
  const toggleReplace = state => {
3377
- const {
3378
- replaceExpanded
3379
- } = state;
3380
- return {
3381
- ...state,
3382
- replaceExpanded: !replaceExpanded
3383
- };
3393
+ return toggleSearchFlag(state, ReplaceExpanded);
3384
3394
  };
3385
3395
 
3386
3396
  const toggleUseRegularExpression = state => {
3387
- const {
3388
- useRegularExpression
3389
- } = state;
3390
- return {
3391
- ...state,
3392
- useRegularExpression: !useRegularExpression
3393
- };
3397
+ return toggleSearchFlag(state, UseRegularExpression);
3394
3398
  };
3395
3399
 
3396
3400
  const Keyboard = -1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "description": "Text Search Worker",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",