Skip to contentSheetwrite

Collaboration

Save, compare and restore versions

Edit a shared budget with a teammate, save a version, compare it with the approved budget and restore part of it.

Entry point @sheetwrite/core/history

Authors
You, Sam Lee
Starts from
Budget approved
Try it
  1. Your edit to Q2, sent to the server
  2. Document version 0
  3. Lists each changed cell and its author
  4. One undoable change, for both clients

How versions are kept

  • The server records each committed change in the archive, with its author. Edits that are not committed yet never reach a version.
  • Versions store each block of cells once and share the blocks that did not change, so a new version costs only what changed.
  • A restore is one undoable change and one synced transaction, so Sam's client receives it like any other edit.
How versions are keptThe document authority journals each committed change in the archive with its author; edits that are not committed never reach a version. Versions are stored in content-addressed chunks, so unchanged cells are shared between versions. A restore is one undoable change and one synced transaction, so a collaborator's client receives it like any other edit.Committed editsEach with its authorNot committedNever reaches a versionAuthorityJournals each changein the archiveChunksContent-addressed;unchanged cells sharedRestoreOne undoable change,one synced transaction

The first compare loads a small WebAssembly module.

The code behind it

version-history.ts
import "@sheetwrite/core/styles.css";
import {
} from "@sheetwrite/core";
import { historyAddon, HistoryArchive, MemoryHistoryStorage } from "@sheetwrite/core/history";
// The document to edit; a snapshot with a "budget" sheet and this documentId
declare const snapshot: WorkbookSnapshot;
const documentId = "budget-2027";
// The server records every committed change, with its author, in the archive.
// MemoryPersistenceAdapter stands in for your server here.
await archive.initialize(snapshot, Date.now());
// Review › Version History and Save Version in the ribbon
// The grid fills its host, so the host needs a height
const host = document.querySelector<HTMLElement>("#grid");
if (host === null) throw new Error("Missing #grid host");
host.style.height = "480px";
config: { ribbon: true },
addons: { history: { archive, authorId: "you", sync: () => sync } },
});
authorId: "you",
});
await sync.ready();
// Name the committed head, compare it with the current document, restore a range
const approved = await archive.saveVersion("Budget approved", "sam", Date.now());
const changes = await archive.diffVersions({ from: approved.id, to: "head" });
console.info(changes);
{ kind: "range", range: { sheet: "budget", start: { row: 1, col: 4 }, end: { row: 8, col: 5 } } },
{ sync },
);
// When the page removes the host: sync.destroy(); grid.destroy();
Show all 50 linesShow the first lines