Commands

Add the Compare extension to the editor before using these commands.

compareDocuments

Compares two Tiptap JSON documents and displays the changes.

This command is equivalent to calling compareDocuments and displayChangeset immediately after.

Parameters (CompareDocumentsOptions)

  • docA (JSONContent): The original document.
  • docB (JSONContent): The changed document.
  • diffOptions? (DiffOptions): Options that control the comparison.
  • displayOptions? (DisplayOptions): Options that control the rendered diff.

Returns (boolean)

  • boolean: true after comparing the documents and creating the diff suggestions.

compareFragments

Compares two Tiptap JSON fragments and displays the changes.

This command is equivalent to calling compareFragments and displayChangeset immediately after.

Parameters (CompareFragmentsOptions)

  • fragmentA (JSONContent[] | null): The original fragment.
  • fragmentB (JSONContent[] | null): The changed fragment.
  • diffOptions? (DiffOptions): Options that control the comparison.
  • displayOptions? (DisplayOptions): Options that control the rendered diff.

Returns (boolean)

  • boolean: true after comparing the fragments and creating the diff suggestions.

compareSteps

Compares a sequence of document steps and displays the changes.

This command is equivalent to calling compareSteps and displayChangeset immediately after.

Parameters (CompareStepsOptions)

  • stepSequence (StepSequence): The sequence of steps to compare. Each step can have associated metadata, such as the user who completed that step.
  • compareMetadata? ((a: ChangeMetadata, b: ChangeMetadata) => boolean): Decides whether adjacent steps can be grouped.
  • diffOptions? (DiffOptions): Options that control the comparison.
  • displayOptions? (DisplayOptions): Options that control the rendered diff.

Returns (boolean)

  • boolean: true after comparing the steps and creating the diff suggestions.

compareVersions

Compares two Yjs version updates and displays the changes.

This command is equivalent to calling compareVersions and displayChangeset immediately after.

Parameters (CompareVersionsOptions)

  • versionA (Uint8Array): The older Yjs v2 update.
  • versionB (Uint8Array): The newer Yjs v2 update.
  • diffOptions? (DiffOptions): Options that control the comparison.
  • compareMetadata? ((a: ChangeMetadata, b: ChangeMetadata) => boolean): Decides whether adjacent changes can be grouped.
  • field? (string): The Yjs document field. Default: 'default'.
  • permanentUserDataMapField? (string): The shared user-data map field. Default: '__tiptapcollab__users'.
  • enableDebugging? (boolean): Enables extraction logging. Default: false.
  • displayOptions? (DisplayOptions): Options that control the rendered diff.

Returns (boolean)

  • boolean: true after comparing the versions and creating the diff suggestions.

displayChangeset

Displays a changeset as review suggestions in the editor. The editor displays the current document (Changeset.docB), with each suggestion offering the corresponding content from the original document (Changeset.docA).

Parameters (DisplayChangesetOptions)

  • changeset (Changeset): The comparison result to display.
  • displayOptions? (DisplayOptions): Options that control the rendered diff.

Returns (boolean)

  • boolean: true after loading the changeset and creating the diff suggestions.

displayChangesetAsTrackedChanges

Loads a changeset as Tracked Changes suggestions. The editor displays the changed document (Changeset.docB) with additions, deletions, replacements, and formatting changes encoded as tracked changes. Any displayed diff suggestions are cleared.

Parameters (DisplayChangesetAsTrackedChangesOptions)

  • changeset (Changeset): The comparison result to display.

Returns (boolean)

  • boolean: true after loading the document and creating the tracked changes.

setDiffSuggestions

Sets the list of displayed diff suggestions.

Parameters

  • diffSuggestions (DiffSuggestion[]): The suggestions to display. Pass an empty array to clear them.

Returns (boolean)

  • boolean: true after replacing the active suggestions.

acceptDiffSuggestion

Accepts a diff suggestion. Stops displaying the suggestion and leaves the document as it is.

Parameters

  • diffSuggestionId (string): The ID of the suggestion to accept.

Returns (boolean)

  • boolean: true when the suggestion was found and accepted; otherwise false.

rejectDiffSuggestion

Rejects a diff suggestion. Applies the suggestion's replacement content to the document to restore the previous version.

Parameters

  • diffSuggestionId (string): The ID of the suggestion to reject.

Returns (boolean)

  • boolean: true when the suggestion was found and rejected; otherwise false.

acceptAllDiffSuggestions

Accepts all active suggestions, or a filtered set of them.

Parameters (AllDiffSuggestionsOptions)

  • filter? ((diffSuggestion: DiffSuggestion) => boolean): Selects which suggestions to accept. By default, all suggestions are accepted.

Returns (boolean)

  • boolean: true after processing the selected suggestions.

rejectAllDiffSuggestions

Rejects all active suggestions, or a filtered set of them.

Parameters (AllDiffSuggestionsOptions)

  • filter? ((diffSuggestion: DiffSuggestion) => boolean): Selects which suggestions to reject. By default, all suggestions are rejected.

Returns (boolean)

  • boolean: true after processing the selected suggestions.