/** * The suggestion ProseMirror plugin: plugin state, the edit lock on committed suggestions, the * rewrite that turns an edit into pending suggestion marks, and paste cleaning. * * Pure ProseMirror — no editor instance, no Velt. */ import { Slice } from '@tiptap/pm/model'; import { Plugin, PluginKey } from '@tiptap/pm/state'; import type { EditorState, Transaction } from '@tiptap/pm/state'; import type { SuggestionAuthor } from './types'; export interface SuggestionPluginState { /** Suggesting mode (mirrors Velt's suggestion mode). */ enabled: boolean; /** The signed-in user; nothing is tracked without one. */ author: SuggestionAuthor | null; /** Tracked format marks; empty = format tracking off. */ trackedFormats: ReadonlySet; /** Pending clusters being committed: new edits never join them. */ frozen: ReadonlySet; } /** Meta stored under the plugin key. */ export interface SuggestionMeta { /** Plugin-state update. */ setState?: Partial; /** A transaction made by this package (commands, sync) — never tracked, never locked. */ internal?: boolean; /** The user transaction was already rewritten into suggestion marks. */ rewritten?: boolean; } export declare const suggestionsPluginKey: PluginKey; /** * True when the user's transaction would change a committed suggestion while suggesting: a text * change over it, or a tracked format change over it. Other mark changes (comments, links) pass. * Checked against each step's own document, before the rewrite adds anything. */ export declare const isBlockedByLock: (tr: Transaction, state: EditorState, ps: SuggestionPluginState | undefined) => boolean; /** * False when `[from, to)` is in a block that allows no marks (a code block), or it (or, for an insertion * point, the marks there) includes a mark that cannot carry the suggestion marks (Tiptap's inline code) — * a suggestion cannot be recorded there. */ export declare const acceptsSuggestionMarks: (state: EditorState, from: number, to: number) => boolean; /** * Appends to `tr` (which already carries the user's steps) the marking steps that record the edit * as a pending suggestion, so the edit and its marks are ONE transaction (one undo step). * Returns true when anything was added. * * - Inserted text → wrapper + insertion marks (joining the author's adjacent, non-frozen cluster). * - Deleted text → put back as a pending deletion; the author's own pending insertion in it is * really deleted. A deletion spanning a block boundary is applied untracked. * - A transaction of only tracked format changes → a format suggestion (formatting the author's own * pending insertion is not a separate suggestion). */ export declare const rewriteAsSuggestion: (tr: Transaction, oldState: EditorState, ps: SuggestionPluginState | undefined) => boolean; /** The pasted content without suggestion marks — a paste never carries another suggestion's identity. */ export declare const stripSuggestionMarks: (slice: Slice) => Slice; export declare const createSuggestionsPlugin: (trackedFormats: readonly string[] | false) => Plugin; /** A plugin-state update transaction meta. */ export declare const setStateMeta: (update: Partial) => SuggestionMeta;