Skip to content

Vizel API / svelte/src / createVizelVersionHistory

Function: createVizelVersionHistory()

ts
function createVizelVersionHistory(getEditor, options?): CreateVizelVersionHistoryResult;

Defined in: packages/svelte/src/runes/createVizelVersionHistory.svelte.ts:56

Svelte 5 rune for managing document version history.

Parameters

ParameterTypeDescription
getEditor() => Editor | null | undefinedFunction that returns the editor instance
optionsVizelVersionHistoryOptionsVersion history configuration options

Returns

CreateVizelVersionHistoryResult

Version history state and controls

Example

svelte
<script lang="ts">
import { createVizelEditor, createVizelVersionHistory } from '@vizel/svelte';

const editor = createVizelEditor({ ... });
const history = createVizelVersionHistory(() => editor.current, {
  maxVersions: 20,
});
</script>

<button onclick={() => history.saveVersion("Manual save")}>Save Version</button>
{#each history.snapshots as snapshot}
  <div>{snapshot.description} - {new Date(snapshot.timestamp).toLocaleString()}</div>
{/each}

Released under the MIT License.