@lvce-editor/text-search-worker 3.26.0 → 3.27.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.
- package/README.md +13 -0
- package/dist/textSearchWorkerMain.js +62 -40
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
# Text Search Worker
|
|
2
2
|
|
|
3
3
|
Web Worker for the text search functionality in LVCE Editor.
|
|
4
|
+
|
|
5
|
+
## Contributing
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
git clone git@github.com:lvce-editor/text-search-worker.git &&
|
|
9
|
+
cd text-search-worker &&
|
|
10
|
+
npm ci &&
|
|
11
|
+
npm test
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Gitpod
|
|
15
|
+
|
|
16
|
+
[](https://gitpod.io/#https://github.com/lvce-editor/text-search-worker)
|
|
@@ -1891,7 +1891,7 @@ const getAbsolutePath = relativePath => {
|
|
|
1891
1891
|
return `/${relativePath}`; // TODO support windows paths
|
|
1892
1892
|
};
|
|
1893
1893
|
|
|
1894
|
-
const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex) => {
|
|
1894
|
+
const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths) => {
|
|
1895
1895
|
const {
|
|
1896
1896
|
type,
|
|
1897
1897
|
text,
|
|
@@ -1920,7 +1920,8 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1920
1920
|
replacement: '',
|
|
1921
1921
|
depth: 0,
|
|
1922
1922
|
matchCount: 0,
|
|
1923
|
-
focused
|
|
1923
|
+
focused,
|
|
1924
|
+
expanded: !collapsedPaths.includes(path)
|
|
1924
1925
|
};
|
|
1925
1926
|
case Match:
|
|
1926
1927
|
return {
|
|
@@ -1937,14 +1938,15 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1937
1938
|
replacement,
|
|
1938
1939
|
depth: 1,
|
|
1939
1940
|
matchCount: 0,
|
|
1940
|
-
focused
|
|
1941
|
+
focused,
|
|
1942
|
+
expanded: false
|
|
1941
1943
|
};
|
|
1942
1944
|
default:
|
|
1943
1945
|
throw new Error('unexpected search result type');
|
|
1944
1946
|
}
|
|
1945
1947
|
};
|
|
1946
1948
|
|
|
1947
|
-
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, fileIcons, focusedIndex) => {
|
|
1949
|
+
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, fileIcons, focusedIndex, collapsedPaths) => {
|
|
1948
1950
|
const displayResults = [];
|
|
1949
1951
|
const setSize = resultCount;
|
|
1950
1952
|
const searchTermLength = searchTerm.length;
|
|
@@ -1954,7 +1956,7 @@ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLine
|
|
|
1954
1956
|
let fileIconIndex = 0;
|
|
1955
1957
|
for (let i = minLineY; i < maxLineY; i++) {
|
|
1956
1958
|
const result = results[i];
|
|
1957
|
-
const displayResult = getDisplayResult(result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
|
|
1959
|
+
const displayResult = getDisplayResult(result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths);
|
|
1958
1960
|
displayResults.push(displayResult);
|
|
1959
1961
|
if (result.type === File) {
|
|
1960
1962
|
fileResult = displayResult;
|
|
@@ -2279,11 +2281,11 @@ const chevronDownVirtualDom = {
|
|
|
2279
2281
|
className: mergeClassNames(Chevron, MaskIconChevronDown),
|
|
2280
2282
|
childCount: 0
|
|
2281
2283
|
};
|
|
2282
|
-
|
|
2284
|
+
const chevronRightVirtualDom = {
|
|
2283
2285
|
type: Div,
|
|
2284
2286
|
className: mergeClassNames(Chevron, MaskIconChevronRight),
|
|
2285
2287
|
childCount: 0
|
|
2286
|
-
}
|
|
2288
|
+
};
|
|
2287
2289
|
|
|
2288
2290
|
const getFileIconVirtualDom = icon => {
|
|
2289
2291
|
return {
|
|
@@ -2351,7 +2353,8 @@ const getSearchResultVirtualDom = rowInfo => {
|
|
|
2351
2353
|
depth,
|
|
2352
2354
|
replacement,
|
|
2353
2355
|
matchCount,
|
|
2354
|
-
focused
|
|
2356
|
+
focused,
|
|
2357
|
+
expanded
|
|
2355
2358
|
} = rowInfo;
|
|
2356
2359
|
const treeItem = {
|
|
2357
2360
|
type: Div,
|
|
@@ -2373,14 +2376,18 @@ const getSearchResultVirtualDom = rowInfo => {
|
|
|
2373
2376
|
}
|
|
2374
2377
|
switch (type) {
|
|
2375
2378
|
case File:
|
|
2376
|
-
treeItem.ariaExpanded =
|
|
2379
|
+
treeItem.ariaExpanded = `${expanded}`;
|
|
2377
2380
|
break;
|
|
2378
2381
|
}
|
|
2379
2382
|
const dom = [];
|
|
2380
2383
|
dom.push(treeItem);
|
|
2381
2384
|
if (type === File) {
|
|
2382
2385
|
treeItem.childCount += 2;
|
|
2383
|
-
|
|
2386
|
+
if (expanded) {
|
|
2387
|
+
dom.push(chevronDownVirtualDom, getFileIconVirtualDom(icon));
|
|
2388
|
+
} else {
|
|
2389
|
+
dom.push(chevronRightVirtualDom, getFileIconVirtualDom(icon));
|
|
2390
|
+
}
|
|
2384
2391
|
}
|
|
2385
2392
|
dom.push(...getLabelVirtualDom(displayText, matchLength, matchStart, replacement));
|
|
2386
2393
|
if (matchCount) {
|
|
@@ -3091,11 +3098,11 @@ const handleSharedInput = (state, name, value, inputSource = Script) => {
|
|
|
3091
3098
|
return fn(state, value, inputSource);
|
|
3092
3099
|
};
|
|
3093
3100
|
|
|
3094
|
-
const
|
|
3095
|
-
const
|
|
3101
|
+
const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
3102
|
+
const newMaxLineY = Math.min(index + 1, itemsLength);
|
|
3096
3103
|
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
3097
|
-
const
|
|
3098
|
-
const newDeltaY = newMinLineY * itemHeight;
|
|
3104
|
+
const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
|
|
3105
|
+
const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
|
|
3099
3106
|
return {
|
|
3100
3107
|
...state,
|
|
3101
3108
|
focusedIndex: index,
|
|
@@ -3105,11 +3112,12 @@ const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) =
|
|
|
3105
3112
|
deltaY: newDeltaY
|
|
3106
3113
|
};
|
|
3107
3114
|
};
|
|
3108
|
-
|
|
3109
|
-
|
|
3115
|
+
|
|
3116
|
+
const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
3117
|
+
const newMinLineY = index;
|
|
3110
3118
|
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
3111
|
-
const
|
|
3112
|
-
const newDeltaY =
|
|
3119
|
+
const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
|
|
3120
|
+
const newDeltaY = newMinLineY * itemHeight;
|
|
3113
3121
|
return {
|
|
3114
3122
|
...state,
|
|
3115
3123
|
focusedIndex: index,
|
|
@@ -3119,6 +3127,7 @@ const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength)
|
|
|
3119
3127
|
deltaY: newDeltaY
|
|
3120
3128
|
};
|
|
3121
3129
|
};
|
|
3130
|
+
|
|
3122
3131
|
const focusIndex = (state, index) => {
|
|
3123
3132
|
const {
|
|
3124
3133
|
itemHeight,
|
|
@@ -3247,12 +3256,6 @@ const getTopHeight = flags => {
|
|
|
3247
3256
|
return 61;
|
|
3248
3257
|
};
|
|
3249
3258
|
|
|
3250
|
-
const addCollapsedPath = (collapsedPaths, path) => {
|
|
3251
|
-
const pathWithDot = `.${path}`;
|
|
3252
|
-
const newCollapsedPaths = [...collapsedPaths, path, pathWithDot];
|
|
3253
|
-
return newCollapsedPaths;
|
|
3254
|
-
};
|
|
3255
|
-
|
|
3256
3259
|
const getFilteredResults = (results, collapsedPaths) => {
|
|
3257
3260
|
if (collapsedPaths.length === 0) {
|
|
3258
3261
|
return results;
|
|
@@ -3261,6 +3264,7 @@ const getFilteredResults = (results, collapsedPaths) => {
|
|
|
3261
3264
|
let isExcluded = false;
|
|
3262
3265
|
for (const result of results) {
|
|
3263
3266
|
if (result.type === File) {
|
|
3267
|
+
filteredResults.push(result);
|
|
3264
3268
|
if (collapsedPaths.includes(result.text)) {
|
|
3265
3269
|
isExcluded = true;
|
|
3266
3270
|
} else {
|
|
@@ -3274,23 +3278,36 @@ const getFilteredResults = (results, collapsedPaths) => {
|
|
|
3274
3278
|
return filteredResults;
|
|
3275
3279
|
};
|
|
3276
3280
|
|
|
3277
|
-
const
|
|
3281
|
+
const toggleCollapsedPath = (collapsedPaths, path) => {
|
|
3282
|
+
if (collapsedPaths.includes(path)) {
|
|
3283
|
+
const index = collapsedPaths.indexOf(path);
|
|
3284
|
+
return collapsedPaths.toSpliced(index, 1);
|
|
3285
|
+
}
|
|
3286
|
+
return [...collapsedPaths, path];
|
|
3287
|
+
};
|
|
3288
|
+
|
|
3289
|
+
const selectIndexFile = async (state, searchResult, index) => {
|
|
3278
3290
|
const {
|
|
3279
3291
|
collapsedPaths,
|
|
3280
3292
|
items,
|
|
3281
|
-
|
|
3293
|
+
itemHeight,
|
|
3294
|
+
headerHeight,
|
|
3295
|
+
height
|
|
3282
3296
|
} = state;
|
|
3283
|
-
const path =
|
|
3284
|
-
const newCollapsedPaths =
|
|
3285
|
-
const filteredResults = getFilteredResults(items,
|
|
3286
|
-
const
|
|
3297
|
+
const path = searchResult.text;
|
|
3298
|
+
const newCollapsedPaths = toggleCollapsedPath(collapsedPaths, path);
|
|
3299
|
+
const filteredResults = getFilteredResults(items, newCollapsedPaths);
|
|
3300
|
+
const total = filteredResults.length;
|
|
3301
|
+
const listHeight = height - headerHeight;
|
|
3302
|
+
const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
3303
|
+
const maxLineY = Math.min(numberOfVisible, total);
|
|
3287
3304
|
return {
|
|
3288
3305
|
...state,
|
|
3289
3306
|
collapsedPaths: newCollapsedPaths,
|
|
3290
3307
|
listFocusedIndex: index,
|
|
3291
3308
|
listFocused: true,
|
|
3292
3309
|
listItems: filteredResults,
|
|
3293
|
-
maxLineY
|
|
3310
|
+
maxLineY
|
|
3294
3311
|
};
|
|
3295
3312
|
};
|
|
3296
3313
|
|
|
@@ -3331,6 +3348,17 @@ const selectIndexPreview = async (state, searchResult, index) => {
|
|
|
3331
3348
|
};
|
|
3332
3349
|
};
|
|
3333
3350
|
|
|
3351
|
+
const getSelectHandler = type => {
|
|
3352
|
+
switch (type) {
|
|
3353
|
+
case File:
|
|
3354
|
+
return selectIndexFile;
|
|
3355
|
+
case Match:
|
|
3356
|
+
return selectIndexPreview;
|
|
3357
|
+
default:
|
|
3358
|
+
throw new Error(`unexpected search result type ${type}`);
|
|
3359
|
+
}
|
|
3360
|
+
};
|
|
3361
|
+
|
|
3334
3362
|
const selectIndex = async (state, index) => {
|
|
3335
3363
|
if (index === -1) {
|
|
3336
3364
|
return {
|
|
@@ -3343,14 +3371,8 @@ const selectIndex = async (state, index) => {
|
|
|
3343
3371
|
items
|
|
3344
3372
|
} = state;
|
|
3345
3373
|
const searchResult = items[index];
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
return selectIndexFile(state, searchResult, index);
|
|
3349
|
-
case Match:
|
|
3350
|
-
return selectIndexPreview(state, searchResult, index);
|
|
3351
|
-
default:
|
|
3352
|
-
throw new Error(`unexpected search result type ${searchResult.type}`);
|
|
3353
|
-
}
|
|
3374
|
+
const fn = getSelectHandler(searchResult.type);
|
|
3375
|
+
return fn(state, searchResult, index);
|
|
3354
3376
|
};
|
|
3355
3377
|
|
|
3356
3378
|
const handleClickAt = (state, eventX, eventY) => {
|
|
@@ -3579,7 +3601,7 @@ const renderItems = {
|
|
|
3579
3601
|
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;
|
|
3580
3602
|
},
|
|
3581
3603
|
apply(oldState, newState) {
|
|
3582
|
-
const displayResults = getDisplayResults(newState.listItems, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.icons, newState.listFocusedIndex);
|
|
3604
|
+
const displayResults = getDisplayResults(newState.listItems, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.icons, newState.listFocusedIndex, newState.collapsedPaths);
|
|
3583
3605
|
const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
|
|
3584
3606
|
const dom = getSearchVirtualDom(displayResults, newState.flags, newState.message, focusOutline, newState.searchInputErrorMessage);
|
|
3585
3607
|
return ['Viewlet.setDom2', newState.uid, dom];
|