@tiptap/extension-find-and-replace 3.30.2 → 3.30.3
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/dist/index.cjs +699 -831
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +177 -169
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +177 -169
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +686 -796
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { Extension } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { DecorationSet } from
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
3
|
+
import { RE2JS } from "re2js";
|
|
4
|
+
import { DecorationSet } from "@tiptap/pm/view";
|
|
5
|
+
import { Node } from "@tiptap/pm/model";
|
|
6
|
+
//#region src/search/types.d.ts
|
|
7
7
|
interface SearchResult {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
from: number;
|
|
9
|
+
to: number;
|
|
10
10
|
}
|
|
11
11
|
interface TextblockSearchTarget {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
node: Node;
|
|
13
|
+
pos: number;
|
|
14
14
|
}
|
|
15
15
|
interface SearchOptions {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
caseSensitive: boolean;
|
|
17
|
+
useRegex: boolean;
|
|
18
|
+
wholeWord: boolean;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/search/regex.d.ts
|
|
21
22
|
type SearchRegex = RegExp | RE2JS;
|
|
22
23
|
/**
|
|
23
24
|
* Creates a search matcher for a term.
|
|
@@ -27,7 +28,8 @@ type SearchRegex = RegExp | RE2JS;
|
|
|
27
28
|
* @returns A compiled matcher, or `null` when the term is invalid or unsupported.
|
|
28
29
|
*/
|
|
29
30
|
declare function createSearchRegex(term: string, options: SearchOptions): SearchRegex | null;
|
|
30
|
-
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/search/search.d.ts
|
|
31
33
|
/**
|
|
32
34
|
* Searches textblocks for a term and returns their matched ranges.
|
|
33
35
|
* @param textblocks The textblocks and their document positions.
|
|
@@ -53,178 +55,184 @@ declare function searchDocument(doc: Node, term: string, options: SearchOptions)
|
|
|
53
55
|
* @returns The result index, or `null` when there are no results.
|
|
54
56
|
*/
|
|
55
57
|
declare function findNextIndex(results: SearchResult[], from: number): number | null;
|
|
56
|
-
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/types.d.ts
|
|
57
60
|
interface FindAndReplaceOptions {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
61
|
+
/**
|
|
62
|
+
* The initial search term.
|
|
63
|
+
* @default ''
|
|
64
|
+
*/
|
|
65
|
+
searchTerm: string;
|
|
66
|
+
/**
|
|
67
|
+
* The initial replace term.
|
|
68
|
+
* @default ''
|
|
69
|
+
*/
|
|
70
|
+
replaceTerm: string;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the search is case sensitive.
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
caseSensitive: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Whether the search term is treated as an RE2-compatible regular expression.
|
|
78
|
+
* Lookarounds and backreferences are not supported.
|
|
79
|
+
* @default false
|
|
80
|
+
*/
|
|
81
|
+
useRegex: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Whether to match whole words only. Ignored when `useRegex` is enabled.
|
|
84
|
+
* @default false
|
|
85
|
+
*/
|
|
86
|
+
wholeWord: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Debounce delay in milliseconds applied to `setSearchTerm`.
|
|
89
|
+
* Set to `0` to disable debouncing.
|
|
90
|
+
* @default 250
|
|
91
|
+
*/
|
|
92
|
+
searchDebounceMs: number;
|
|
93
|
+
/**
|
|
94
|
+
* Whether the default result highlight styles are injected.
|
|
95
|
+
* @default true
|
|
96
|
+
*/
|
|
97
|
+
injectCSS: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* A nonce for the injected style tag, needed for strict CSP setups.
|
|
100
|
+
* @default undefined
|
|
101
|
+
*/
|
|
102
|
+
injectNonce: string | undefined;
|
|
100
103
|
}
|
|
101
104
|
interface FindAndReplaceStorage {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
105
|
+
/**
|
|
106
|
+
* The current search term.
|
|
107
|
+
*/
|
|
108
|
+
searchTerm: string;
|
|
109
|
+
/**
|
|
110
|
+
* The current replace term.
|
|
111
|
+
*/
|
|
112
|
+
replaceTerm: string;
|
|
113
|
+
/**
|
|
114
|
+
* Whether the search is case sensitive.
|
|
115
|
+
*/
|
|
116
|
+
caseSensitive: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Whether the search term is treated as an RE2-compatible regular expression.
|
|
119
|
+
*/
|
|
120
|
+
useRegex: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Whether to match whole words only. Ignored when `useRegex` is enabled.
|
|
123
|
+
*/
|
|
124
|
+
wholeWord: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* The current search results in document order.
|
|
127
|
+
*/
|
|
128
|
+
results: SearchResult[];
|
|
129
|
+
/**
|
|
130
|
+
* The index of the current result, or `null` when no result is selected.
|
|
131
|
+
*/
|
|
132
|
+
currentIndex: number | null;
|
|
130
133
|
}
|
|
131
134
|
declare module '@tiptap/core' {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
interface Storage {
|
|
136
|
+
findAndReplace: FindAndReplaceStorage;
|
|
137
|
+
}
|
|
135
138
|
}
|
|
136
|
-
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/find-and-replace.d.ts
|
|
137
141
|
declare module '@tiptap/core' {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
142
|
+
interface Commands<ReturnType> {
|
|
143
|
+
findAndReplace: {
|
|
144
|
+
/**
|
|
145
|
+
* Set the search term and highlight all matches in the document.
|
|
146
|
+
* @param term The search term, treated as regex source when regex mode is enabled.
|
|
147
|
+
* @example editor.commands.setSearchTerm('Hello')
|
|
148
|
+
*/
|
|
149
|
+
setSearchTerm: (term: string) => ReturnType;
|
|
150
|
+
/**
|
|
151
|
+
* Set the replace term used by the replace commands.
|
|
152
|
+
* @param term The replacement text.
|
|
153
|
+
* @example editor.commands.setReplaceTerm('World')
|
|
154
|
+
*/
|
|
155
|
+
setReplaceTerm: (term: string) => ReturnType;
|
|
156
|
+
/**
|
|
157
|
+
* Set whether the search is case sensitive.
|
|
158
|
+
* @param caseSensitive The new case sensitivity.
|
|
159
|
+
* @example editor.commands.setCaseSensitive(true)
|
|
160
|
+
*/
|
|
161
|
+
setCaseSensitive: (caseSensitive: boolean) => ReturnType;
|
|
162
|
+
/**
|
|
163
|
+
* Set whether the search term is treated as an RE2-compatible regular expression.
|
|
164
|
+
* Lookarounds and backreferences are not supported.
|
|
165
|
+
* @param useRegex The new regex mode.
|
|
166
|
+
* @example editor.commands.setUseRegex(true)
|
|
167
|
+
*/
|
|
168
|
+
setUseRegex: (useRegex: boolean) => ReturnType;
|
|
169
|
+
/**
|
|
170
|
+
* Set whether to match whole words only. Ignored when regex mode is enabled.
|
|
171
|
+
* @param wholeWord The new whole word mode.
|
|
172
|
+
* @example editor.commands.setWholeWord(true)
|
|
173
|
+
*/
|
|
174
|
+
setWholeWord: (wholeWord: boolean) => ReturnType;
|
|
175
|
+
/**
|
|
176
|
+
* Replace the current search result and jump to the next one.
|
|
177
|
+
* @example editor.commands.replace()
|
|
178
|
+
*/
|
|
179
|
+
replace: () => ReturnType;
|
|
180
|
+
/**
|
|
181
|
+
* Replace all search results at once.
|
|
182
|
+
* @example editor.commands.replaceAll()
|
|
183
|
+
*/
|
|
184
|
+
replaceAll: () => ReturnType;
|
|
185
|
+
/**
|
|
186
|
+
* Jump to the next search result, wrapping around at the end.
|
|
187
|
+
* @example editor.commands.goToNextResult()
|
|
188
|
+
*/
|
|
189
|
+
goToNextResult: () => ReturnType;
|
|
190
|
+
/**
|
|
191
|
+
* Jump to the previous search result, wrapping around at the start.
|
|
192
|
+
* @example editor.commands.goToPreviousResult()
|
|
193
|
+
*/
|
|
194
|
+
goToPreviousResult: () => ReturnType;
|
|
195
|
+
/**
|
|
196
|
+
* Clear the search term and remove all search result highlights.
|
|
197
|
+
* @example editor.commands.clearSearch()
|
|
198
|
+
*/
|
|
199
|
+
clearSearch: () => ReturnType;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
198
202
|
}
|
|
199
203
|
declare const FindAndReplace: Extension<FindAndReplaceOptions, FindAndReplaceStorage>;
|
|
200
|
-
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/constants/constants.d.ts
|
|
201
206
|
declare const resultClass = "find-and-replace-result";
|
|
202
207
|
declare const currentResultClass = "find-and-replace-result-current";
|
|
203
|
-
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/plugin/plugin-state.d.ts
|
|
204
210
|
interface FindAndReplacePluginState {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
searchTerm: string;
|
|
212
|
+
replaceTerm: string;
|
|
213
|
+
caseSensitive: boolean;
|
|
214
|
+
useRegex: boolean;
|
|
215
|
+
wholeWord: boolean;
|
|
216
|
+
results: SearchResult[];
|
|
217
|
+
currentIndex: number | null;
|
|
218
|
+
decorations: DecorationSet;
|
|
213
219
|
}
|
|
214
220
|
/**
|
|
215
221
|
* Transaction meta to patch the plugin state. Setting `searchTerm`,
|
|
216
222
|
* `caseSensitive`, `useRegex` or `wholeWord` re-runs the search.
|
|
217
223
|
*/
|
|
218
224
|
interface FindAndReplaceMeta {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
+
searchTerm?: string;
|
|
226
|
+
replaceTerm?: string;
|
|
227
|
+
caseSensitive?: boolean;
|
|
228
|
+
useRegex?: boolean;
|
|
229
|
+
wholeWord?: boolean;
|
|
230
|
+
currentIndex?: number | null;
|
|
225
231
|
}
|
|
226
|
-
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/plugin/plugin.d.ts
|
|
227
234
|
declare const FindAndReplacePluginKey: PluginKey<FindAndReplacePluginState>;
|
|
228
235
|
declare const FindAndReplacePlugin: (options: FindAndReplaceOptions, onCreate: (pluginState: FindAndReplacePluginState) => void) => Plugin<FindAndReplacePluginState>;
|
|
229
|
-
|
|
230
|
-
export { FindAndReplace, type FindAndReplaceMeta,
|
|
236
|
+
//#endregion
|
|
237
|
+
export { FindAndReplace, FindAndReplace as default, type FindAndReplaceMeta, FindAndReplaceOptions, FindAndReplacePlugin, FindAndReplacePluginKey, type FindAndReplacePluginState, FindAndReplaceStorage, type SearchOptions, type SearchResult, type TextblockSearchTarget, createSearchRegex, currentResultClass, findNextIndex, resultClass, searchDocument, searchTextblocks };
|
|
238
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/search/types.ts","../src/search/regex.ts","../src/search/search.ts","../src/types.ts","../src/find-and-replace.ts","../src/constants/constants.ts","../src/plugin/plugin-state.ts","../src/plugin/plugin.ts"],"mappings":";;;;;;UAEiB;EACf;EACA;;UAGe;EACf,MAAM;EACN;;UAGe;EACf;EACA;EACA;;;;KCXU,cAAc,SAAS;;;;;;;;iBA2CnB,kBAAkB,cAAc,SAAS,gBAAgB;;;;;;;;;;iBC/BzD,iBACd,qBAAqB,yBACrB,cACA,SAAS,gBACR;;;;;;;;;iBAkBa,eAAe,KAAK,MAAM,cAAc,SAAS,gBAAgB;;;;;;;;iBAuBjE,cAAc,SAAS,gBAAgB;;;UC3DtC;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;;;EAOA;;;;;EAMA;;;;;;EAOA;;;;;EAMA;;;;;EAMA;;UAGe;;;;EAIf;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA,SAAS;;;;EAKT;;;YAIU;IACR,gBAAgB;;;;;;YC5ER,SAAS;IACjB;;;;;;MAME,gBAAgB,iBAAiB;;;;;;MAOjC,iBAAiB,iBAAiB;;;;;;MAOlC,mBAAmB,2BAA2B;;;;;;;MAQ9C,cAAc,sBAAsB;;;;;;MAOpC,eAAe,uBAAuB;;;;;MAMtC,eAAe;;;;;MAMf,kBAAkB;;;;;MAMlB,sBAAsB;;;;;MAMtB,0BAA0B;;;;;MAM1B,mBAAmB;;;;cAuHZ,gBAAc,UAAA,uBAAA;;;cC1Md;cACA;;;UCGI;EACf;EACA;EACA;EACA;EACA;EACA,SAAS;EACT;EACA,aAAa;;;;;;UAOE;EACf;EACA;EACA;EACA;EACA;EACA;;;;cCbW,yBAAuB,UAAA;cAEvB,uBACX,SAAS,uBACT,WAAW,aAAa,uCAAkC,OAAA"}
|