@lvce-editor/text-search-worker 3.26.0 → 3.28.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 +101 -63
- 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)
|
|
@@ -1653,7 +1653,7 @@ const focusSearchValueNext = state => {
|
|
|
1653
1653
|
};
|
|
1654
1654
|
|
|
1655
1655
|
const CheckBox = 'checkbox';
|
|
1656
|
-
const None = 'none';
|
|
1656
|
+
const None$1 = 'none';
|
|
1657
1657
|
const Status = 'status';
|
|
1658
1658
|
const Tree = 'tree';
|
|
1659
1659
|
const TreeItem$1 = 'treeitem';
|
|
@@ -1732,7 +1732,7 @@ const getIconVirtualDom = (icon, type = Div) => {
|
|
|
1732
1732
|
return {
|
|
1733
1733
|
type,
|
|
1734
1734
|
className: mergeClassNames(MaskIcon, `MaskIcon${icon}`),
|
|
1735
|
-
role: None,
|
|
1735
|
+
role: None$1,
|
|
1736
1736
|
childCount: 0
|
|
1737
1737
|
};
|
|
1738
1738
|
};
|
|
@@ -1880,6 +1880,10 @@ const getActions = () => {
|
|
|
1880
1880
|
}];
|
|
1881
1881
|
};
|
|
1882
1882
|
|
|
1883
|
+
const None = 0;
|
|
1884
|
+
const Collapsed = 1;
|
|
1885
|
+
const Expanded = 2;
|
|
1886
|
+
|
|
1883
1887
|
// TODO this should be in FileSystem module
|
|
1884
1888
|
const pathBaseName = path => {
|
|
1885
1889
|
return path.slice(path.lastIndexOf('/') + 1);
|
|
@@ -1891,7 +1895,7 @@ const getAbsolutePath = relativePath => {
|
|
|
1891
1895
|
return `/${relativePath}`; // TODO support windows paths
|
|
1892
1896
|
};
|
|
1893
1897
|
|
|
1894
|
-
const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex) => {
|
|
1898
|
+
const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths) => {
|
|
1895
1899
|
const {
|
|
1896
1900
|
type,
|
|
1897
1901
|
text,
|
|
@@ -1908,7 +1912,6 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1908
1912
|
const baseName = pathBaseName(path);
|
|
1909
1913
|
return {
|
|
1910
1914
|
title: absolutePath,
|
|
1911
|
-
type: File,
|
|
1912
1915
|
text: baseName,
|
|
1913
1916
|
icon: fileIcons[fileIconIndex],
|
|
1914
1917
|
posInSet,
|
|
@@ -1920,12 +1923,12 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1920
1923
|
replacement: '',
|
|
1921
1924
|
depth: 0,
|
|
1922
1925
|
matchCount: 0,
|
|
1923
|
-
focused
|
|
1926
|
+
focused,
|
|
1927
|
+
expanded: collapsedPaths.includes(path) ? Collapsed : Expanded
|
|
1924
1928
|
};
|
|
1925
1929
|
case Match:
|
|
1926
1930
|
return {
|
|
1927
1931
|
title: text,
|
|
1928
|
-
type: Match,
|
|
1929
1932
|
text: text,
|
|
1930
1933
|
icon: '',
|
|
1931
1934
|
posInSet,
|
|
@@ -1937,14 +1940,15 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1937
1940
|
replacement,
|
|
1938
1941
|
depth: 1,
|
|
1939
1942
|
matchCount: 0,
|
|
1940
|
-
focused
|
|
1943
|
+
focused,
|
|
1944
|
+
expanded: None
|
|
1941
1945
|
};
|
|
1942
1946
|
default:
|
|
1943
1947
|
throw new Error('unexpected search result type');
|
|
1944
1948
|
}
|
|
1945
1949
|
};
|
|
1946
1950
|
|
|
1947
|
-
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, fileIcons, focusedIndex) => {
|
|
1951
|
+
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, fileIcons, focusedIndex, collapsedPaths) => {
|
|
1948
1952
|
const displayResults = [];
|
|
1949
1953
|
const setSize = resultCount;
|
|
1950
1954
|
const searchTermLength = searchTerm.length;
|
|
@@ -1954,7 +1958,7 @@ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLine
|
|
|
1954
1958
|
let fileIconIndex = 0;
|
|
1955
1959
|
for (let i = minLineY; i < maxLineY; i++) {
|
|
1956
1960
|
const result = results[i];
|
|
1957
|
-
const displayResult = getDisplayResult(result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
|
|
1961
|
+
const displayResult = getDisplayResult(result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths);
|
|
1958
1962
|
displayResults.push(displayResult);
|
|
1959
1963
|
if (result.type === File) {
|
|
1960
1964
|
fileResult = displayResult;
|
|
@@ -2096,7 +2100,7 @@ const getOutSideButtonsDom = outsideButtons => {
|
|
|
2096
2100
|
preNodes: [{
|
|
2097
2101
|
type: Div,
|
|
2098
2102
|
className: SearchFieldContainer,
|
|
2099
|
-
role: None,
|
|
2103
|
+
role: None$1,
|
|
2100
2104
|
childCount: 1 + outsideButtons.length
|
|
2101
2105
|
}],
|
|
2102
2106
|
postNodes: outsideButtons.flatMap(getSearchFieldButtonVirtualDom)
|
|
@@ -2112,7 +2116,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
|
|
|
2112
2116
|
const dom = [...preNodes, {
|
|
2113
2117
|
type: Div,
|
|
2114
2118
|
className: searchFieldClassName,
|
|
2115
|
-
role: None,
|
|
2119
|
+
role: None$1,
|
|
2116
2120
|
childCount: 2
|
|
2117
2121
|
}, {
|
|
2118
2122
|
type: TextArea,
|
|
@@ -2228,12 +2232,12 @@ const getSearchHeaderTopVirtualDom = (flags, searchInputErrorMessage = '') => {
|
|
|
2228
2232
|
const dom = [{
|
|
2229
2233
|
type: Div,
|
|
2230
2234
|
className: SearchHeaderTop,
|
|
2231
|
-
role: None,
|
|
2235
|
+
role: None$1,
|
|
2232
2236
|
childCount: 2
|
|
2233
2237
|
}, ...getSearchToggleVirtualDom(flags), {
|
|
2234
2238
|
type: Div,
|
|
2235
2239
|
className: SearchHeaderTopRight,
|
|
2236
|
-
role: None,
|
|
2240
|
+
role: None$1,
|
|
2237
2241
|
childCount: flags & ReplaceExpanded ? 2 : 1
|
|
2238
2242
|
}, ...getSearchFieldVirtualDom(SearchValue, 'Search', HandleInput, inputActions.inside, inputActions.outside, '', Boolean(searchInputErrorMessage))];
|
|
2239
2243
|
if (flags & ReplaceExpanded) {
|
|
@@ -2246,7 +2250,7 @@ const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage) => {
|
|
|
2246
2250
|
const dom = [{
|
|
2247
2251
|
type: Div,
|
|
2248
2252
|
className: SearchHeader,
|
|
2249
|
-
role: None,
|
|
2253
|
+
role: None$1,
|
|
2250
2254
|
childCount: 2,
|
|
2251
2255
|
onClick: HandleHeaderClick,
|
|
2252
2256
|
onFocusIn: HandleHeaderFocusIn
|
|
@@ -2279,18 +2283,18 @@ const chevronDownVirtualDom = {
|
|
|
2279
2283
|
className: mergeClassNames(Chevron, MaskIconChevronDown),
|
|
2280
2284
|
childCount: 0
|
|
2281
2285
|
};
|
|
2282
|
-
|
|
2286
|
+
const chevronRightVirtualDom = {
|
|
2283
2287
|
type: Div,
|
|
2284
2288
|
className: mergeClassNames(Chevron, MaskIconChevronRight),
|
|
2285
2289
|
childCount: 0
|
|
2286
|
-
}
|
|
2290
|
+
};
|
|
2287
2291
|
|
|
2288
2292
|
const getFileIconVirtualDom = icon => {
|
|
2289
2293
|
return {
|
|
2290
2294
|
type: Img,
|
|
2291
2295
|
className: FileIcon,
|
|
2292
2296
|
src: icon,
|
|
2293
|
-
role: None,
|
|
2297
|
+
role: None$1,
|
|
2294
2298
|
childCount: 0
|
|
2295
2299
|
};
|
|
2296
2300
|
};
|
|
@@ -2338,9 +2342,30 @@ const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) =
|
|
|
2338
2342
|
|
|
2339
2343
|
const PaddingRight = '12px';
|
|
2340
2344
|
|
|
2345
|
+
const getPaddingLeft = depth => {
|
|
2346
|
+
return `${Number(depth) + 1}rem`; // TODO use classname and dynamic css
|
|
2347
|
+
};
|
|
2348
|
+
const getClassName = focused => {
|
|
2349
|
+
if (focused) {
|
|
2350
|
+
return TreeItem + ' ' + TreeItemActive;
|
|
2351
|
+
}
|
|
2352
|
+
return TreeItem;
|
|
2353
|
+
};
|
|
2354
|
+
|
|
2355
|
+
// TODO instead of setting string, support enum in virtual dom and send enum to renderer process
|
|
2356
|
+
// which converts it to a boolean
|
|
2357
|
+
const getAriaExpanded = expanded => {
|
|
2358
|
+
switch (expanded) {
|
|
2359
|
+
case Collapsed:
|
|
2360
|
+
return 'false';
|
|
2361
|
+
case Expanded:
|
|
2362
|
+
return 'true';
|
|
2363
|
+
default:
|
|
2364
|
+
return undefined;
|
|
2365
|
+
}
|
|
2366
|
+
};
|
|
2341
2367
|
const getSearchResultVirtualDom = rowInfo => {
|
|
2342
2368
|
const {
|
|
2343
|
-
type,
|
|
2344
2369
|
matchStart,
|
|
2345
2370
|
matchLength,
|
|
2346
2371
|
text: displayText,
|
|
@@ -2351,12 +2376,13 @@ const getSearchResultVirtualDom = rowInfo => {
|
|
|
2351
2376
|
depth,
|
|
2352
2377
|
replacement,
|
|
2353
2378
|
matchCount,
|
|
2354
|
-
focused
|
|
2379
|
+
focused,
|
|
2380
|
+
expanded
|
|
2355
2381
|
} = rowInfo;
|
|
2356
2382
|
const treeItem = {
|
|
2357
2383
|
type: Div,
|
|
2358
2384
|
role: TreeItem$1,
|
|
2359
|
-
className:
|
|
2385
|
+
className: getClassName(focused),
|
|
2360
2386
|
title,
|
|
2361
2387
|
ariaSetSize: setSize,
|
|
2362
2388
|
ariaLevel: depth,
|
|
@@ -2364,23 +2390,20 @@ const getSearchResultVirtualDom = rowInfo => {
|
|
|
2364
2390
|
ariaLabel: title,
|
|
2365
2391
|
ariaDescription: '',
|
|
2366
2392
|
childCount: 1,
|
|
2367
|
-
paddingLeft:
|
|
2368
|
-
|
|
2369
|
-
|
|
2393
|
+
paddingLeft: getPaddingLeft(depth),
|
|
2394
|
+
paddingRight: PaddingRight,
|
|
2395
|
+
ariaExpanded: getAriaExpanded(expanded)
|
|
2370
2396
|
};
|
|
2371
|
-
if (focused) {
|
|
2372
|
-
treeItem.className += ' ' + TreeItemActive;
|
|
2373
|
-
}
|
|
2374
|
-
switch (type) {
|
|
2375
|
-
case File:
|
|
2376
|
-
treeItem.ariaExpanded = 'true';
|
|
2377
|
-
break;
|
|
2378
|
-
}
|
|
2379
2397
|
const dom = [];
|
|
2380
2398
|
dom.push(treeItem);
|
|
2381
|
-
if (
|
|
2399
|
+
if (expanded === Expanded) {
|
|
2400
|
+
// TODO move childcount computation to getDisplaySearchresults
|
|
2401
|
+
// TODO add chevronIcon and fileIcon properties to getDisplaySearchResults
|
|
2382
2402
|
treeItem.childCount += 2;
|
|
2383
2403
|
dom.push(chevronDownVirtualDom, getFileIconVirtualDom(icon));
|
|
2404
|
+
} else if (expanded === Collapsed) {
|
|
2405
|
+
treeItem.childCount += 2;
|
|
2406
|
+
dom.push(chevronRightVirtualDom, getFileIconVirtualDom(icon));
|
|
2384
2407
|
}
|
|
2385
2408
|
dom.push(...getLabelVirtualDom(displayText, matchLength, matchStart, replacement));
|
|
2386
2409
|
if (matchCount) {
|
|
@@ -3091,11 +3114,11 @@ const handleSharedInput = (state, name, value, inputSource = Script) => {
|
|
|
3091
3114
|
return fn(state, value, inputSource);
|
|
3092
3115
|
};
|
|
3093
3116
|
|
|
3094
|
-
const
|
|
3095
|
-
const
|
|
3117
|
+
const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
3118
|
+
const newMaxLineY = Math.min(index + 1, itemsLength);
|
|
3096
3119
|
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
3097
|
-
const
|
|
3098
|
-
const newDeltaY = newMinLineY * itemHeight;
|
|
3120
|
+
const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
|
|
3121
|
+
const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
|
|
3099
3122
|
return {
|
|
3100
3123
|
...state,
|
|
3101
3124
|
focusedIndex: index,
|
|
@@ -3105,11 +3128,12 @@ const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) =
|
|
|
3105
3128
|
deltaY: newDeltaY
|
|
3106
3129
|
};
|
|
3107
3130
|
};
|
|
3108
|
-
|
|
3109
|
-
|
|
3131
|
+
|
|
3132
|
+
const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
3133
|
+
const newMinLineY = index;
|
|
3110
3134
|
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
3111
|
-
const
|
|
3112
|
-
const newDeltaY =
|
|
3135
|
+
const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
|
|
3136
|
+
const newDeltaY = newMinLineY * itemHeight;
|
|
3113
3137
|
return {
|
|
3114
3138
|
...state,
|
|
3115
3139
|
focusedIndex: index,
|
|
@@ -3119,6 +3143,7 @@ const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength)
|
|
|
3119
3143
|
deltaY: newDeltaY
|
|
3120
3144
|
};
|
|
3121
3145
|
};
|
|
3146
|
+
|
|
3122
3147
|
const focusIndex = (state, index) => {
|
|
3123
3148
|
const {
|
|
3124
3149
|
itemHeight,
|
|
@@ -3247,12 +3272,6 @@ const getTopHeight = flags => {
|
|
|
3247
3272
|
return 61;
|
|
3248
3273
|
};
|
|
3249
3274
|
|
|
3250
|
-
const addCollapsedPath = (collapsedPaths, path) => {
|
|
3251
|
-
const pathWithDot = `.${path}`;
|
|
3252
|
-
const newCollapsedPaths = [...collapsedPaths, path, pathWithDot];
|
|
3253
|
-
return newCollapsedPaths;
|
|
3254
|
-
};
|
|
3255
|
-
|
|
3256
3275
|
const getFilteredResults = (results, collapsedPaths) => {
|
|
3257
3276
|
if (collapsedPaths.length === 0) {
|
|
3258
3277
|
return results;
|
|
@@ -3261,36 +3280,50 @@ const getFilteredResults = (results, collapsedPaths) => {
|
|
|
3261
3280
|
let isExcluded = false;
|
|
3262
3281
|
for (const result of results) {
|
|
3263
3282
|
if (result.type === File) {
|
|
3283
|
+
filteredResults.push(result);
|
|
3264
3284
|
if (collapsedPaths.includes(result.text)) {
|
|
3265
3285
|
isExcluded = true;
|
|
3266
3286
|
} else {
|
|
3267
3287
|
isExcluded = false;
|
|
3268
3288
|
}
|
|
3269
3289
|
}
|
|
3270
|
-
if (!isExcluded) {
|
|
3290
|
+
if (result.type === Match && !isExcluded) {
|
|
3271
3291
|
filteredResults.push(result);
|
|
3272
3292
|
}
|
|
3273
3293
|
}
|
|
3274
3294
|
return filteredResults;
|
|
3275
3295
|
};
|
|
3276
3296
|
|
|
3277
|
-
const
|
|
3297
|
+
const toggleCollapsedPath = (collapsedPaths, path) => {
|
|
3298
|
+
if (collapsedPaths.includes(path)) {
|
|
3299
|
+
const index = collapsedPaths.indexOf(path);
|
|
3300
|
+
return collapsedPaths.toSpliced(index, 1);
|
|
3301
|
+
}
|
|
3302
|
+
return [...collapsedPaths, path];
|
|
3303
|
+
};
|
|
3304
|
+
|
|
3305
|
+
const selectIndexFile = async (state, searchResult, index) => {
|
|
3278
3306
|
const {
|
|
3279
3307
|
collapsedPaths,
|
|
3280
3308
|
items,
|
|
3281
|
-
|
|
3309
|
+
itemHeight,
|
|
3310
|
+
headerHeight,
|
|
3311
|
+
height
|
|
3282
3312
|
} = state;
|
|
3283
|
-
const path =
|
|
3284
|
-
const newCollapsedPaths =
|
|
3285
|
-
const filteredResults = getFilteredResults(items,
|
|
3286
|
-
const
|
|
3313
|
+
const path = searchResult.text;
|
|
3314
|
+
const newCollapsedPaths = toggleCollapsedPath(collapsedPaths, path);
|
|
3315
|
+
const filteredResults = getFilteredResults(items, newCollapsedPaths);
|
|
3316
|
+
const total = filteredResults.length;
|
|
3317
|
+
const listHeight = height - headerHeight;
|
|
3318
|
+
const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
3319
|
+
const maxLineY = Math.min(numberOfVisible, total);
|
|
3287
3320
|
return {
|
|
3288
3321
|
...state,
|
|
3289
3322
|
collapsedPaths: newCollapsedPaths,
|
|
3290
3323
|
listFocusedIndex: index,
|
|
3291
3324
|
listFocused: true,
|
|
3292
3325
|
listItems: filteredResults,
|
|
3293
|
-
maxLineY
|
|
3326
|
+
maxLineY
|
|
3294
3327
|
};
|
|
3295
3328
|
};
|
|
3296
3329
|
|
|
@@ -3331,6 +3364,17 @@ const selectIndexPreview = async (state, searchResult, index) => {
|
|
|
3331
3364
|
};
|
|
3332
3365
|
};
|
|
3333
3366
|
|
|
3367
|
+
const getSelectHandler = type => {
|
|
3368
|
+
switch (type) {
|
|
3369
|
+
case File:
|
|
3370
|
+
return selectIndexFile;
|
|
3371
|
+
case Match:
|
|
3372
|
+
return selectIndexPreview;
|
|
3373
|
+
default:
|
|
3374
|
+
throw new Error(`unexpected search result type ${type}`);
|
|
3375
|
+
}
|
|
3376
|
+
};
|
|
3377
|
+
|
|
3334
3378
|
const selectIndex = async (state, index) => {
|
|
3335
3379
|
if (index === -1) {
|
|
3336
3380
|
return {
|
|
@@ -3343,14 +3387,8 @@ const selectIndex = async (state, index) => {
|
|
|
3343
3387
|
items
|
|
3344
3388
|
} = state;
|
|
3345
3389
|
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
|
-
}
|
|
3390
|
+
const fn = getSelectHandler(searchResult.type);
|
|
3391
|
+
return fn(state, searchResult, index);
|
|
3354
3392
|
};
|
|
3355
3393
|
|
|
3356
3394
|
const handleClickAt = (state, eventX, eventY) => {
|
|
@@ -3579,7 +3617,7 @@ const renderItems = {
|
|
|
3579
3617
|
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
3618
|
},
|
|
3581
3619
|
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);
|
|
3620
|
+
const displayResults = getDisplayResults(newState.listItems, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.icons, newState.listFocusedIndex, newState.collapsedPaths);
|
|
3583
3621
|
const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
|
|
3584
3622
|
const dom = getSearchVirtualDom(displayResults, newState.flags, newState.message, focusOutline, newState.searchInputErrorMessage);
|
|
3585
3623
|
return ['Viewlet.setDom2', newState.uid, dom];
|