Class

RevisionTracker (revision-history)

@ckeditor/ckeditor5-revision-history/src/revisiontracker

class

Creates and updates revisions based on changes of the editor content.

There are always at least two revisions available for the document: the initial revision and the current revision. If those revisions have not been created for the document yet, they are created when the editor data is loaded.

The initial revision contains the initial document data from when the document was loaded for the first time.

The current revision contains all the unsaved document changes, that is changes which have not been saved yet as a specific revision. The current revision is always available and it is always the "top" revision (most recent).

Filtering

Properties

  • adapter : RevisionHistoryAdapter

    An adapter object that should communicate with the data source to fetch or save the revisions data.

    This property is also set through adapter.

Methods

  • addRevisionData( revisionData ) → Revision

    Creates a revision basing on given revision data and adds it to the revision tracker and revision repository.

    Parameters

    revisionData : Object

    Revision data.

    Returns

    Revision

    The created revision.

  • saveRevision( [ revisionData ] = { [revisionData.name], [revisionData.id], [revisionData.attributes] }, [ version ] ) → Promise

    Creates and saves a new revision.

    // Saves all the unsaved changes as a revision without a name.
    const myRevision = await revisionTracker.saveRevision();
    
    // Saves all the unsaved changes as a revision named 'My revision'.
    const myRevision = await revisionTracker.saveRevision( { name: 'My revision' } );
    
    // Saves a revision named 'My revision'.
    // It will include document data with all the changes up to document version `30`.
    // The revision will be on "top" of the closest revision with a lower document version.
    // The revision diff will include all the changes since the previous revision up to document version `30`.
    const myRevision = await revisionTracker.saveRevision( { name: 'My revision' }, 30 );
    

    A new revision can be created in the middle of the revision history. In such case, already existing revisions will be appropriately updated.

    Parameters

    [ revisionData ] : Object

    Revision data to set on the created revision.

    Properties
    [ revisionData.name ] : String

    Revision name.

    [ revisionData.id ] : String

    Revision id.

    [ revisionData.attributes ] : Object

    Revision attributes.

    [ version ] : Number

    Document version on which the revision is saved. If not set, the revision will be saved for the current (most recent) document state.

    Returns

    Promise

    Promise that resolves with the created revision after it is saved locally (the promise does not wait for the adapter update).

  • update() → Promise

    Adds the new document changes to the current revision.

    This method should be called before document data and revision data is saved (for example, in the autosave callback).

    Returns

    Promise

    Promise that is resolved after the revision is updated locally (the promise does not wait for the adapter update).