Types
Paid add-on
The extension exports TypeScript types for working with suggestions.
SuggestionType
Public-facing suggestion type returned by the query API:
type SuggestionType = 'add' | 'delete' | 'replace' | 'markChange'SuggestionMarkType
Internal mark-level type stored on suggestion marks. Replace suggestions use separate mark types for their deletion and insertion parts:
type SuggestionMarkType = 'add' | 'delete' | 'replaceDeletion' | 'replaceInsertion' | 'markChange'SuggestionMarkChangeOperation
Operation stored in a mark-change suggestion:
type SuggestionMarkChangeOperation = 'added' | 'removed'SuggestionMarkChange
Describes one mark mutation stored on a markChange suggestion:
type SuggestionMarkChange = {
operation: SuggestionMarkChangeOperation
markName: string
markAttrs: Record<string, unknown> | null
}Suggestion
Represents a suggestion found in the document:
type Suggestion = {
id: string
type: SuggestionType
userId: string
createdAt: string
userMetadata: Record<string, unknown> | null
from: number
to: number
text: string
// Only present for 'replace' suggestions:
deletionRange?: { from: number; to: number }
insertionRange?: { from: number; to: number }
replacedText?: string
// Only present for 'markChange' suggestions:
markChanges?: SuggestionMarkChange[]
}For replace suggestions:
textcontains the new (inserted) textreplacedTextcontains the old (deleted) textdeletionRangeandinsertionRangegive the exact positions of each partfromandtocover the full range of both parts
For markChange suggestions:
textcontains the affected text contentmarkChangescontains the tracked mark operations, including mark names and attrs
SuggestionMarkAttrs
Attributes stored on the suggestion mark:
type SuggestionMarkAttrs = {
id: string
type: SuggestionMarkType
userId: string
createdAt: string
userMetadata: Record<string, unknown> | null
markChanges?: SuggestionMarkChange[] | null
}TrackedChangesOptions
Configuration options for the extension:
type TrackedChangesOptions = {
enabled: boolean
userId: string
userMetadata?: Record<string, unknown> | null
suggestionGroupingTimeout: number
ignoredTrackingMarks: string[]
onSuggestionCreate?: (suggestion: Suggestion) => void
onSuggestionAccept?: (id: string) => void
onSuggestionReject?: (id: string) => void
}Type helpers
The extension exports constants and helper functions for working with suggestion types:
import {
SUGGESTION_TYPES,
isAddLikeType,
isDeleteLikeType,
isReplaceMarkType,
markTypeToSuggestionType,
} from '@tiptap-pro/extension-tracked-changes'
// Constants
SUGGESTION_TYPES.ADD // 'add'
SUGGESTION_TYPES.DELETE // 'delete'
SUGGESTION_TYPES.REPLACE_DELETION // 'replaceDeletion'
SUGGESTION_TYPES.REPLACE_INSERTION // 'replaceInsertion'
SUGGESTION_TYPES.MARK_CHANGE // 'markChange'
// Check if a mark type represents added content (matches 'add' and 'replaceInsertion')
isAddLikeType('add') // true
isAddLikeType('replaceInsertion') // true
// Check if a mark type represents deleted content (matches 'delete' and 'replaceDeletion')
isDeleteLikeType('delete') // true
isDeleteLikeType('replaceDeletion') // true
// Check if a mark type is one of the replace sub-types
isReplaceMarkType('replaceDeletion') // true
// Convert a mark-level type to the public-facing suggestion type
markTypeToSuggestionType('replaceDeletion') // 'replace'
markTypeToSuggestionType('add') // 'add'