@prose-reader/enhancer-search 1.164.0 → 1.165.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/package.json +3 -5
- package/src/index.test.ts +0 -2
- package/src/index.ts +13 -7
- package/src/search.ts +11 -5
- package/vite.config.ts +1 -1
- package/.eslintrc.cjs +0 -1
- package/.prettierrc.cjs +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prose-reader/enhancer-search",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.165.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.umd.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -14,15 +14,13 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"start": "vite build --watch --mode development",
|
|
16
16
|
"build": "tsc && vite build",
|
|
17
|
-
"lint:read": "prettier --check . && eslint . --ext .ts,.tsx,.js,.jsx",
|
|
18
|
-
"lint:write": "prettier --write . && eslint --fix . --ext .ts,.tsx,.js,.jsx",
|
|
19
17
|
"test": "vitest run --coverage"
|
|
20
18
|
},
|
|
21
19
|
"dependencies": {
|
|
22
|
-
"@prose-reader/core": "^1.
|
|
20
|
+
"@prose-reader/core": "^1.165.0"
|
|
23
21
|
},
|
|
24
22
|
"peerDependencies": {
|
|
25
23
|
"rxjs": "*"
|
|
26
24
|
},
|
|
27
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "59799628bd1974e31ae4bb40104f441b517db554"
|
|
28
26
|
}
|
package/src/index.test.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { defer, forkJoin, Observable, of } from "rxjs"
|
|
1
|
+
import { deferIdle, type Reader } from "@prose-reader/core"
|
|
2
|
+
import { defer, forkJoin, type Observable, of } from "rxjs"
|
|
4
3
|
import { catchError, finalize, map, switchMap } from "rxjs/operators"
|
|
5
|
-
import { searchInDocument, SearchResult } from "./search"
|
|
4
|
+
import { searchInDocument, type SearchResult } from "./search"
|
|
6
5
|
import { report } from "./report"
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -14,7 +13,9 @@ import { report } from "./report"
|
|
|
14
13
|
* enhancer is agnostic and can only search into documents.
|
|
15
14
|
*/
|
|
16
15
|
export const searchEnhancer =
|
|
17
|
-
<InheritOptions, InheritOutput extends Reader>(
|
|
16
|
+
<InheritOptions, InheritOutput extends Reader>(
|
|
17
|
+
next: (options: InheritOptions) => InheritOutput,
|
|
18
|
+
) =>
|
|
18
19
|
(
|
|
19
20
|
options: InheritOptions,
|
|
20
21
|
): InheritOutput & {
|
|
@@ -37,7 +38,9 @@ export const searchEnhancer =
|
|
|
37
38
|
|
|
38
39
|
if (!doc) return of([])
|
|
39
40
|
|
|
40
|
-
return deferIdle(() =>
|
|
41
|
+
return deferIdle(() =>
|
|
42
|
+
searchInDocument(reader, item, doc, text),
|
|
43
|
+
).pipe(
|
|
41
44
|
finalize(() => {
|
|
42
45
|
release?.()
|
|
43
46
|
}),
|
|
@@ -57,7 +60,10 @@ export const searchEnhancer =
|
|
|
57
60
|
return of([])
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
const searches$ =
|
|
63
|
+
const searches$ =
|
|
64
|
+
reader.context.manifest?.spineItems.map((_, index) =>
|
|
65
|
+
searchForItem(index, text),
|
|
66
|
+
) || []
|
|
61
67
|
|
|
62
68
|
return forkJoin([...searches$, of([])])
|
|
63
69
|
}).pipe(
|
package/src/search.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Reader, SpineItem } from "@prose-reader/core"
|
|
2
|
-
import { Observable, of } from "rxjs"
|
|
3
|
-
import { ResultItem } from "./types"
|
|
1
|
+
import type { Reader, SpineItem } from "@prose-reader/core"
|
|
2
|
+
import { type Observable, of } from "rxjs"
|
|
3
|
+
import type { ResultItem } from "./types"
|
|
4
4
|
|
|
5
5
|
export type SearchResult = ResultItem[]
|
|
6
6
|
|
|
@@ -25,9 +25,10 @@ const searchNodeContainingText = (node: Node, text: string) => {
|
|
|
25
25
|
if (subNode.nodeType === 3) {
|
|
26
26
|
const content = (subNode as Text).data.toLowerCase()
|
|
27
27
|
if (content) {
|
|
28
|
-
let match
|
|
28
|
+
let match: RegExpExecArray | null = null
|
|
29
29
|
const regexp = RegExp(`(${text})`, `gi`)
|
|
30
30
|
|
|
31
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
|
|
31
32
|
while ((match = regexp.exec(content)) !== null) {
|
|
32
33
|
if (match.index >= 0 && subNode.ownerDocument) {
|
|
33
34
|
const range = subNode.ownerDocument.createRange()
|
|
@@ -44,7 +45,12 @@ const searchNodeContainingText = (node: Node, text: string) => {
|
|
|
44
45
|
return rangeList
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
export const searchInDocument = (
|
|
48
|
+
export const searchInDocument = (
|
|
49
|
+
reader: Reader,
|
|
50
|
+
item: SpineItem,
|
|
51
|
+
doc: Document,
|
|
52
|
+
text: string,
|
|
53
|
+
): Observable<SearchResult> => {
|
|
48
54
|
const ranges = searchNodeContainingText(doc, text)
|
|
49
55
|
|
|
50
56
|
const newResults = ranges.map((range) => {
|
package/vite.config.ts
CHANGED
package/.eslintrc.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require(`../../.eslintrc.cjs`)
|
package/.prettierrc.cjs
DELETED