@viveeditor/ext-track-changes
v1.1.0
Published
Track changes for viveEditor: suggestion mode that records insertions, deletions and paragraph breaks by author, with accept and reject.
Maintainers
Readme
@viveeditor/ext-track-changes
Track changes for viveEditor: suggestion mode that records insertions, deletions and paragraph breaks by author, with accept and reject.
Part of viveEditor, a free, open-source rich text editor.
Install
npm install @viveeditor/ext-track-changes @viveeditor/coreUsage
import { Editor } from '@viveeditor/core'
import '@viveeditor/core/style.css'
import { TrackChanges } from '@viveeditor/ext-track-changes'
import '@viveeditor/ext-track-changes/style.css'
const editor = await Editor.create(document.querySelector('#editor'), {
extensions: [TrackChanges.configure({ user: { id: 'u1', name: 'Ada' } })],
})
editor.commands.setSuggesting(true)
for (const change of editor.query.changes()) {
console.log(change.kind, change.name, change.inserted, change.deleted)
}
editor.commands.acceptChange(editor.query.changes()[0].id)
editor.commands.rejectAllChanges()While suggesting, typed text is marked as an insertion, deleted text stays visible as a deletion, and Enter or Backspace at the start of a paragraph records an inserted or deleted paragraph break. Deleting your own pending insertion removes it for real. Formatting and structural edits (lists, tables, images) are refused while suggesting; editor.query.suggestionRefusals() counts them so the UI can explain. Code blocks cannot hold suggestions. Text typed with an input method (Chinese, Japanese, Korean, many Android keyboards) is marked when the composition ends or the editor loses focus; call editor.commands.commitSuggestions() before reading the HTML yourself in the middle of typing. If tracking an edit fails for any reason, the edit is refused rather than applied untracked.
Options: user ({ id, name }, required to suggest), suggesting (start in suggestion mode), locked (suggestion mode cannot be turned off and accept/reject are refused — for reviewers), types (textblocks that can carry a paragraph-break change, default paragraph and heading).
Suggestions are stored in the HTML as <ins> and <del> with data-vive-change, data-author, data-name and data-time, and paragraph breaks as data-vive-break on the paragraph. An insertion with invalid change attributes is dropped together with its text, so it can never turn into approved text. Pasted content loses pending suggestions; text moved by drag and drop while suggesting is recorded as a deletion plus an insertion. Published HTML shows only approved text unless the sanitizer runs with suggestions: 'keep' or 'accept'.
License
MIT
