import { Extension } from "@tiptap/core"; import { Node } from "@tiptap/pm/model"; import { RE2JS } from "re2js"; import { Plugin, PluginKey } from "@tiptap/pm/state"; import { DecorationSet } from "@tiptap/pm/view"; //#region src/search/types.d.ts interface SearchResult { from: number; to: number; } interface TextblockSearchTarget { node: Node; pos: number; } interface SearchOptions { caseSensitive: boolean; useRegex: boolean; wholeWord: boolean; } //#endregion //#region src/search/regex.d.ts type SearchRegex = RegExp | RE2JS; /** * Creates a search matcher for a term. * Regex mode uses RE2-compatible syntax to avoid catastrophic backtracking. * @param term The search term, treated as regex source when `useRegex` is enabled. * @param options Case sensitivity, regex mode, and whole word matching. * @returns A compiled matcher, or `null` when the term is invalid or unsupported. */ declare function createSearchRegex(term: string, options: SearchOptions): SearchRegex | null; //#endregion //#region src/search/search.d.ts /** * Searches textblocks for a term and returns their matched ranges. * @param textblocks The textblocks and their document positions. * @param term The search term, treated as regex source when `useRegex` is enabled. * @param options Case sensitivity, regex mode, and whole word matching. * @returns The list of matched ranges in textblock order. */ declare function searchTextblocks(textblocks: readonly TextblockSearchTarget[], term: string, options: SearchOptions): SearchResult[]; /** * Searches all textblocks of a document for a term and returns the matched ranges. * Matches may span multiple text nodes (e.g. across marks), but never leave a textblock. * @param doc The document to search in. * @param term The search term, treated as regex source when `useRegex` is enabled. * @param options Case sensitivity, regex mode, and whole word matching. * @returns The list of matched ranges in document order. */ declare function searchDocument(doc: Node, term: string, options: SearchOptions): SearchResult[]; /** * Finds the index of the first result at or after a position, wrapping around * to the first result when the position is behind the last result. * @param results The current search results. * @param from The position to search from. * @returns The result index, or `null` when there are no results. */ declare function findNextIndex(results: SearchResult[], from: number): number | null; //#endregion //#region src/types.d.ts interface FindAndReplaceOptions { /** * The initial search term. * @default '' */ searchTerm: string; /** * The initial replace term. * @default '' */ replaceTerm: string; /** * Whether the search is case sensitive. * @default false */ caseSensitive: boolean; /** * Whether the search term is treated as an RE2-compatible regular expression. * Lookarounds and backreferences are not supported. * @default false */ useRegex: boolean; /** * Whether to match whole words only. Ignored when `useRegex` is enabled. * @default false */ wholeWord: boolean; /** * Debounce delay in milliseconds applied to `setSearchTerm`. * Set to `0` to disable debouncing. * @default 250 */ searchDebounceMs: number; /** * Whether the default result highlight styles are injected. * @default true */ injectCSS: boolean; /** * A nonce for the injected style tag, needed for strict CSP setups. * @default undefined */ injectNonce: string | undefined; } interface FindAndReplaceStorage { /** * The current search term. */ searchTerm: string; /** * The current replace term. */ replaceTerm: string; /** * Whether the search is case sensitive. */ caseSensitive: boolean; /** * Whether the search term is treated as an RE2-compatible regular expression. */ useRegex: boolean; /** * Whether to match whole words only. Ignored when `useRegex` is enabled. */ wholeWord: boolean; /** * The current search results in document order. */ results: SearchResult[]; /** * The index of the current result, or `null` when no result is selected. */ currentIndex: number | null; } declare module '@tiptap/core' { interface Storage { findAndReplace: FindAndReplaceStorage; } } //#endregion //#region src/find-and-replace.d.ts declare module '@tiptap/core' { interface Commands { findAndReplace: { /** * Set the search term and highlight all matches in the document. * @param term The search term, treated as regex source when regex mode is enabled. * @example editor.commands.setSearchTerm('Hello') */ setSearchTerm: (term: string) => ReturnType; /** * Set the replace term used by the replace commands. * @param term The replacement text. * @example editor.commands.setReplaceTerm('World') */ setReplaceTerm: (term: string) => ReturnType; /** * Set whether the search is case sensitive. * @param caseSensitive The new case sensitivity. * @example editor.commands.setCaseSensitive(true) */ setCaseSensitive: (caseSensitive: boolean) => ReturnType; /** * Set whether the search term is treated as an RE2-compatible regular expression. * Lookarounds and backreferences are not supported. * @param useRegex The new regex mode. * @example editor.commands.setUseRegex(true) */ setUseRegex: (useRegex: boolean) => ReturnType; /** * Set whether to match whole words only. Ignored when regex mode is enabled. * @param wholeWord The new whole word mode. * @example editor.commands.setWholeWord(true) */ setWholeWord: (wholeWord: boolean) => ReturnType; /** * Replace the current search result and jump to the next one. * @example editor.commands.replace() */ replace: () => ReturnType; /** * Replace all search results at once. * @example editor.commands.replaceAll() */ replaceAll: () => ReturnType; /** * Jump to the next search result, wrapping around at the end. * @example editor.commands.goToNextResult() */ goToNextResult: () => ReturnType; /** * Jump to the previous search result, wrapping around at the start. * @example editor.commands.goToPreviousResult() */ goToPreviousResult: () => ReturnType; /** * Clear the search term and remove all search result highlights. * @example editor.commands.clearSearch() */ clearSearch: () => ReturnType; }; } } declare const FindAndReplace: Extension; //#endregion //#region src/constants/constants.d.ts declare const resultClass = "find-and-replace-result"; declare const currentResultClass = "find-and-replace-result-current"; //#endregion //#region src/plugin/plugin-state.d.ts interface FindAndReplacePluginState { searchTerm: string; replaceTerm: string; caseSensitive: boolean; useRegex: boolean; wholeWord: boolean; results: SearchResult[]; currentIndex: number | null; decorations: DecorationSet; } /** * Transaction meta to patch the plugin state. Setting `searchTerm`, * `caseSensitive`, `useRegex` or `wholeWord` re-runs the search. */ interface FindAndReplaceMeta { searchTerm?: string; replaceTerm?: string; caseSensitive?: boolean; useRegex?: boolean; wholeWord?: boolean; currentIndex?: number | null; } //#endregion //#region src/plugin/plugin.d.ts declare const FindAndReplacePluginKey: PluginKey; declare const FindAndReplacePlugin: (options: FindAndReplaceOptions, onCreate: (pluginState: FindAndReplacePluginState) => void) => Plugin; //#endregion 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 }; //# sourceMappingURL=index.d.cts.map