@tiptap/extension-find-and-replace 3.30.2 → 3.30.4

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.d.cts CHANGED
@@ -1,23 +1,24 @@
1
- import { Extension } from '@tiptap/core';
2
- import { Node } from '@tiptap/pm/model';
3
- import { Plugin, PluginKey } from '@tiptap/pm/state';
4
- import { DecorationSet } from '@tiptap/pm/view';
5
- import { RE2JS } from 're2js';
6
-
1
+ import { Extension } from "@tiptap/core";
2
+ import { Node } from "@tiptap/pm/model";
3
+ import { RE2JS } from "re2js";
4
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
5
+ import { DecorationSet } from "@tiptap/pm/view";
6
+ //#region src/search/types.d.ts
7
7
  interface SearchResult {
8
- from: number;
9
- to: number;
8
+ from: number;
9
+ to: number;
10
10
  }
11
11
  interface TextblockSearchTarget {
12
- node: Node;
13
- pos: number;
12
+ node: Node;
13
+ pos: number;
14
14
  }
15
15
  interface SearchOptions {
16
- caseSensitive: boolean;
17
- useRegex: boolean;
18
- wholeWord: boolean;
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
- * The initial search term.
60
- * @default ''
61
- */
62
- searchTerm: string;
63
- /**
64
- * The initial replace term.
65
- * @default ''
66
- */
67
- replaceTerm: string;
68
- /**
69
- * Whether the search is case sensitive.
70
- * @default false
71
- */
72
- caseSensitive: boolean;
73
- /**
74
- * Whether the search term is treated as an RE2-compatible regular expression.
75
- * Lookarounds and backreferences are not supported.
76
- * @default false
77
- */
78
- useRegex: boolean;
79
- /**
80
- * Whether to match whole words only. Ignored when `useRegex` is enabled.
81
- * @default false
82
- */
83
- wholeWord: boolean;
84
- /**
85
- * Debounce delay in milliseconds applied to `setSearchTerm`.
86
- * Set to `0` to disable debouncing.
87
- * @default 250
88
- */
89
- searchDebounceMs: number;
90
- /**
91
- * Whether the default result highlight styles are injected.
92
- * @default true
93
- */
94
- injectCSS: boolean;
95
- /**
96
- * A nonce for the injected style tag, needed for strict CSP setups.
97
- * @default undefined
98
- */
99
- injectNonce: string | undefined;
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
- * The current search term.
104
- */
105
- searchTerm: string;
106
- /**
107
- * The current replace term.
108
- */
109
- replaceTerm: string;
110
- /**
111
- * Whether the search is case sensitive.
112
- */
113
- caseSensitive: boolean;
114
- /**
115
- * Whether the search term is treated as an RE2-compatible regular expression.
116
- */
117
- useRegex: boolean;
118
- /**
119
- * Whether to match whole words only. Ignored when `useRegex` is enabled.
120
- */
121
- wholeWord: boolean;
122
- /**
123
- * The current search results in document order.
124
- */
125
- results: SearchResult[];
126
- /**
127
- * The index of the current result, or `null` when no result is selected.
128
- */
129
- currentIndex: number | null;
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
- interface Storage {
133
- findAndReplace: FindAndReplaceStorage;
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
- interface Commands<ReturnType> {
139
- findAndReplace: {
140
- /**
141
- * Set the search term and highlight all matches in the document.
142
- * @param term The search term, treated as regex source when regex mode is enabled.
143
- * @example editor.commands.setSearchTerm('Hello')
144
- */
145
- setSearchTerm: (term: string) => ReturnType;
146
- /**
147
- * Set the replace term used by the replace commands.
148
- * @param term The replacement text.
149
- * @example editor.commands.setReplaceTerm('World')
150
- */
151
- setReplaceTerm: (term: string) => ReturnType;
152
- /**
153
- * Set whether the search is case sensitive.
154
- * @param caseSensitive The new case sensitivity.
155
- * @example editor.commands.setCaseSensitive(true)
156
- */
157
- setCaseSensitive: (caseSensitive: boolean) => ReturnType;
158
- /**
159
- * Set whether the search term is treated as an RE2-compatible regular expression.
160
- * Lookarounds and backreferences are not supported.
161
- * @param useRegex The new regex mode.
162
- * @example editor.commands.setUseRegex(true)
163
- */
164
- setUseRegex: (useRegex: boolean) => ReturnType;
165
- /**
166
- * Set whether to match whole words only. Ignored when regex mode is enabled.
167
- * @param wholeWord The new whole word mode.
168
- * @example editor.commands.setWholeWord(true)
169
- */
170
- setWholeWord: (wholeWord: boolean) => ReturnType;
171
- /**
172
- * Replace the current search result and jump to the next one.
173
- * @example editor.commands.replace()
174
- */
175
- replace: () => ReturnType;
176
- /**
177
- * Replace all search results at once.
178
- * @example editor.commands.replaceAll()
179
- */
180
- replaceAll: () => ReturnType;
181
- /**
182
- * Jump to the next search result, wrapping around at the end.
183
- * @example editor.commands.goToNextResult()
184
- */
185
- goToNextResult: () => ReturnType;
186
- /**
187
- * Jump to the previous search result, wrapping around at the start.
188
- * @example editor.commands.goToPreviousResult()
189
- */
190
- goToPreviousResult: () => ReturnType;
191
- /**
192
- * Clear the search term and remove all search result highlights.
193
- * @example editor.commands.clearSearch()
194
- */
195
- clearSearch: () => ReturnType;
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
- searchTerm: string;
206
- replaceTerm: string;
207
- caseSensitive: boolean;
208
- useRegex: boolean;
209
- wholeWord: boolean;
210
- results: SearchResult[];
211
- currentIndex: number | null;
212
- decorations: DecorationSet;
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
- searchTerm?: string;
220
- replaceTerm?: string;
221
- caseSensitive?: boolean;
222
- useRegex?: boolean;
223
- wholeWord?: boolean;
224
- currentIndex?: number | null;
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, type FindAndReplaceOptions, FindAndReplacePlugin, FindAndReplacePluginKey, type FindAndReplacePluginState, type FindAndReplaceStorage, type SearchOptions, type SearchResult, type TextblockSearchTarget, createSearchRegex, currentResultClass, FindAndReplace as default, findNextIndex, resultClass, searchDocument, searchTextblocks };
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.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","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"}