@gotipe/versions
v0.1.1
Published
Version history for the GoTipe editor: named and automatic snapshots, block diffs and undoable restore.
Downloads
531
Maintainers
Readme
@gotipe/versions
Version history for the GoTipe editor. VersionsManager saves snapshots of the document by
name or on a timer, compares two snapshots block by block and restores one as an ordinary,
undoable edit. Snapshots live in memory; exportState() hands them to your storage.
Docs · Website · Repository
Install
npm install @gotipe/versions @gotipe/coreUsage
import { createEditor } from "@gotipe/core";
import { DefaultPreset } from "@gotipe/core/presets";
import { VersionsManager, compareDocuments } from "@gotipe/versions";
const editor = await createEditor({ extensions: [DefaultPreset] });
editor.mount(document.querySelector<HTMLElement>("#editor")!);
const versions = new VersionsManager(editor, {
autoSave: true,
autoSaveInterval: 60_000,
maxVersions: 50,
onVersionCreated: (version) => console.log(`Saved ${version.name}`),
});
const draft = versions.createVersion("First draft", "Alice");
// Later: what changed since the draft?
const diff = compareDocuments(draft.snapshot, editor.getJSON());
console.log(diff.added, diff.removed, diff.modified, diff.moved);
// Put the draft back. Undo returns to the text before the restore.
versions.restoreVersion(draft.id);- Options:
initialState,autoSave,autoSaveInterval,maxVersions,onVersionCreated,onVersionRestored. createVersion,restoreVersion,getVersions,getVersion,deleteVersion,compareVersions,subscribe.exportState()andloadState(snapshot)(orinitialState) store and restore the list;loadStatevalidates the whole snapshot before it changes anything.compareDocuments(a, b)returns the IDs of added, removed, modified and moved blocks;diffText,countWordChangesandblockTextcompare text word by word.defineVersionscreates the manager with the editor;getVersionsManager(editor)returns it.
The package has no UI; the VersionHistory panel is part of the commercial
@gotipe/block-editor.
License
MIT — see LICENSE.
