@input/pen-search 0.1.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.
@@ -0,0 +1,60 @@
1
+ import { Unsubscribe, Editor, Extension, DocumentOp } from '@input/pen-types';
2
+
3
+ interface SearchOptions {
4
+ caseSensitive: boolean;
5
+ regex: boolean;
6
+ wholeWord: boolean;
7
+ locale?: string;
8
+ }
9
+ interface SearchMatch {
10
+ kind: "block" | "table-cell";
11
+ blockId: string;
12
+ from: number;
13
+ to: number;
14
+ text: string;
15
+ index: number;
16
+ row?: number;
17
+ col?: number;
18
+ cellText?: string;
19
+ }
20
+ interface SearchState {
21
+ open: boolean;
22
+ query: string;
23
+ replaceText: string;
24
+ matches: readonly SearchMatch[];
25
+ activeIndex: number;
26
+ options: SearchOptions;
27
+ }
28
+ interface SearchController {
29
+ getState(): SearchState;
30
+ subscribe(listener: () => void): Unsubscribe;
31
+ open(): void;
32
+ close(): void;
33
+ toggleOpen(): void;
34
+ setQuery(query: string): void;
35
+ setReplaceText(replaceText: string): void;
36
+ setOptions(options: Partial<SearchOptions>): void;
37
+ next(): void;
38
+ previous(): void;
39
+ replace(): void;
40
+ replaceAll(): void;
41
+ recompute(): void;
42
+ }
43
+
44
+ declare const SEARCH_EXTENSION_NAME = "search";
45
+ declare function searchExtension(): Extension;
46
+ declare function getSearchController(editor: Editor): SearchController | null;
47
+
48
+ declare const SEARCH_QUERY_MAX_LENGTH = 1024;
49
+ declare const SEARCH_EXECUTION_BUDGET_MS = 50;
50
+ declare const SEARCH_REGEX_SEGMENT_MAX_CODE_UNITS: number;
51
+ declare const SEARCH_BUDGET_EXCEEDED_CODE = "search-budget-exceeded";
52
+ declare const SEARCH_INVALID_PATTERN_CODE = "search-invalid-pattern";
53
+ declare const DEFAULT_SEARCH_LOCALE = "en";
54
+ declare const DEFAULT_SEARCH_OPTIONS: SearchOptions;
55
+ declare function findDocumentMatches(editor: Editor, query: string, options: SearchOptions): SearchMatch[];
56
+ declare function buildSearchRegex(query: string, options: SearchOptions): RegExp | null;
57
+ declare function buildReplaceOps(match: SearchMatch | null, replaceText: string): DocumentOp[];
58
+ declare function buildReplaceAllOps(matches: readonly SearchMatch[], replaceText: string): DocumentOp[];
59
+
60
+ export { DEFAULT_SEARCH_LOCALE, DEFAULT_SEARCH_OPTIONS, SEARCH_BUDGET_EXCEEDED_CODE, SEARCH_EXECUTION_BUDGET_MS, SEARCH_EXTENSION_NAME, SEARCH_INVALID_PATTERN_CODE, SEARCH_QUERY_MAX_LENGTH, SEARCH_REGEX_SEGMENT_MAX_CODE_UNITS, type SearchController, type SearchMatch, type SearchOptions, type SearchState, buildReplaceAllOps, buildReplaceOps, buildSearchRegex, findDocumentMatches, getSearchController, searchExtension };
@@ -0,0 +1,60 @@
1
+ import { Unsubscribe, Editor, Extension, DocumentOp } from '@input/pen-types';
2
+
3
+ interface SearchOptions {
4
+ caseSensitive: boolean;
5
+ regex: boolean;
6
+ wholeWord: boolean;
7
+ locale?: string;
8
+ }
9
+ interface SearchMatch {
10
+ kind: "block" | "table-cell";
11
+ blockId: string;
12
+ from: number;
13
+ to: number;
14
+ text: string;
15
+ index: number;
16
+ row?: number;
17
+ col?: number;
18
+ cellText?: string;
19
+ }
20
+ interface SearchState {
21
+ open: boolean;
22
+ query: string;
23
+ replaceText: string;
24
+ matches: readonly SearchMatch[];
25
+ activeIndex: number;
26
+ options: SearchOptions;
27
+ }
28
+ interface SearchController {
29
+ getState(): SearchState;
30
+ subscribe(listener: () => void): Unsubscribe;
31
+ open(): void;
32
+ close(): void;
33
+ toggleOpen(): void;
34
+ setQuery(query: string): void;
35
+ setReplaceText(replaceText: string): void;
36
+ setOptions(options: Partial<SearchOptions>): void;
37
+ next(): void;
38
+ previous(): void;
39
+ replace(): void;
40
+ replaceAll(): void;
41
+ recompute(): void;
42
+ }
43
+
44
+ declare const SEARCH_EXTENSION_NAME = "search";
45
+ declare function searchExtension(): Extension;
46
+ declare function getSearchController(editor: Editor): SearchController | null;
47
+
48
+ declare const SEARCH_QUERY_MAX_LENGTH = 1024;
49
+ declare const SEARCH_EXECUTION_BUDGET_MS = 50;
50
+ declare const SEARCH_REGEX_SEGMENT_MAX_CODE_UNITS: number;
51
+ declare const SEARCH_BUDGET_EXCEEDED_CODE = "search-budget-exceeded";
52
+ declare const SEARCH_INVALID_PATTERN_CODE = "search-invalid-pattern";
53
+ declare const DEFAULT_SEARCH_LOCALE = "en";
54
+ declare const DEFAULT_SEARCH_OPTIONS: SearchOptions;
55
+ declare function findDocumentMatches(editor: Editor, query: string, options: SearchOptions): SearchMatch[];
56
+ declare function buildSearchRegex(query: string, options: SearchOptions): RegExp | null;
57
+ declare function buildReplaceOps(match: SearchMatch | null, replaceText: string): DocumentOp[];
58
+ declare function buildReplaceAllOps(matches: readonly SearchMatch[], replaceText: string): DocumentOp[];
59
+
60
+ export { DEFAULT_SEARCH_LOCALE, DEFAULT_SEARCH_OPTIONS, SEARCH_BUDGET_EXCEEDED_CODE, SEARCH_EXECUTION_BUDGET_MS, SEARCH_EXTENSION_NAME, SEARCH_INVALID_PATTERN_CODE, SEARCH_QUERY_MAX_LENGTH, SEARCH_REGEX_SEGMENT_MAX_CODE_UNITS, type SearchController, type SearchMatch, type SearchOptions, type SearchState, buildReplaceAllOps, buildReplaceOps, buildSearchRegex, findDocumentMatches, getSearchController, searchExtension };