Diff utility

diffUtility

Compares two Tiptap documents and returns a list of changes between them.

Parameters (DiffUtilityOptions)

  • docA (Node): Original document
  • docB (Node): Modified document
  • simplifyChanges? (boolean): Whether to simplify the changes so that if there are multiple changes in the same word, they are merged into one change. Default: true
  • ignoreAttributes? (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 to null or undefined to 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 changed
  • rangeB (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 })