Diff utility
diffUtility
Compares two Tiptap documents and returns a list of changes between them.
Parameters (DiffUtilityOptions)
docA(Node): Original documentdocB(Node): Modified documentsimplifyChanges?(boolean): Whether to simplify the changes so that if there are multiple changes in the same word, they are merged into one change. Default:trueignoreAttributes?(string[]): The attributes to ignore. Default:['id', 'data-thread-id']ignoreMarks?(string[]): The marks to ignore. Default:['inlineThread']changeMergeDistance?(number | null): Maximum distance (in document positions) between changes to merge them. If two adjacent changes have a distance less than or equal to this value in either rangeA or rangeB, they will be merged into a single change. Set tonullorundefinedto disable merging. Default:null
Schema issue
Both documents must have the same schema. If the documents come from different editors, convert
them to a common editor schema: Node.fromJSON(editor.state.schema, otherEditor.getJSON())
Returns (Change[])
Returns a list of changes. Each Change item contains:
rangeA(Range): The range in the original document that has changedrangeB(Range): The range in the modified document that has changed
Example
// Compute changes between two documents
import { diffUtility } from '@tiptap-pro/ai-toolkit'
const changes = diffUtility({ docA, docB })