Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

createTimeline

Bounded undo/redo history built on createRegistry with a configurable size limit.


AdvancedApr 5, 2026

Usage

The createTimeline composable extends createRegistry to provide undo/redo functionality with a bounded history. When the timeline reaches its size limit, older items are moved to an overflow buffer, allowing you to undo back to them while maintaining a fixed active timeline size.

ts
import { createTimeline } from '@vuetify/v0'

const timeline = createTimeline({ size: 10 })

// Register actions
timeline.register({ id: 'action-1', value: 'Created document' })
timeline.register({ id: 'action-2', value: 'Added title' })
timeline.register({ id: 'action-3', value: 'Added paragraph' })

console.log(timeline.size) // 3

// Undo the last action
timeline.undo()
console.log(timeline.size) // 2

// Redo the undone action
timeline.redo()
console.log(timeline.size) // 3

Context / DI

Use createTimelineContext to share a timeline instance across a component tree:

ts
import { createTimelineContext } from '@vuetify/v0'

export const [useHistory, provideHistory, history] =
  createTimelineContext({ namespace: 'my:history', size: 50 })

// In parent component
provideHistory()

// In child component
const timeline = useHistory()
timeline.register({ id: 'action-1', value: 'Created item' })
timeline.undo()

Options

OptionTypeDefaultNotes
sizenumber10Maximum number of entries in the active timeline. When exceeded, the oldest entry moves to an internal overflow buffer — it remains accessible via undo() but no longer counts against the limit

Architecture

createTimeline extends createRegistry with bounded history and overflow management:

Timeline Hierarchy

Use controls to zoom and pan. Click outside or press Escape to close.

Timeline Hierarchy

Reactivity

createTimeline uses minimal reactivity like its parent createRegistry. History state is managed internally without reactive primitives.

Tip

Need reactive history? Wrap with useProxyRegistry(timeline) for full template reactivity on the active timeline.

Examples

Drawing Canvas

A freehand drawing canvas split into four files demonstrating timeline-powered undo/redo:

FileRole
context.tsDefines Point, Stroke, CanvasContext types and the DI pair
CanvasProvider.vueCreates the timeline, tracks redo state, exposes add/undo/redo/clear
CanvasConsumer.vueOwns the <canvas> element, mouse/touch handlers, and render loop
canvas.vueEntry point — wraps Provider around Consumer
Provider/Consumer Data Flow

Use controls to zoom and pan. Click outside or press Escape to close.

Provider/Consumer Data Flow

Key patterns:

  • Provider owns createTimeline + useProxyRegistry — consumer never touches the timeline directly

  • strokes computed maps proxy.values to raw Stroke[] — consumer only sees domain data

  • redoStackSize tracked manually via shallowRef since redo stack is internal to the timeline

  • watchEffect in consumer reads strokes.value for reactive canvas re-rendering

  • History bar visualizes the 20-slot bounded timeline capacity

Draw on the canvas, then use Undo/Redo to time-travel through your strokes.

0 strokes

API Reference

The following API details are for the createTimeline composable.

Functions

createTimeline

(_options?: TimelineOptions) => E

Creates a new timeline instance.

createTimelineContext

(_options?: TimelineContextOptions) => ContextTrinity<E>

Creates a new timeline context.

useTimeline

(namespace?: string) => E

Returns the current timeline instance.

Options

events

boolean | undefined

Enable event emission for registry operations

Default: false

reactive

boolean | undefined

Enable reactive behavior for registry operations

Default: false

size

number | undefined

The maximum size of the timeline.

Default: 10

Properties

collection

ReadonlyMap<ID, E>

The collection of tickets in the registry

size

number

The number of tickets in the registry

Methods

clear

() => void

Clear the entire registry

has

(id: ID) => boolean

Check if a ticket exists by ID

keys

() => readonly ID[]

Get all registered IDs

browse

(value: E["value"]) => ID[] | undefined

Browse for an ID(s) by value

lookup

(index: number) => ID | undefined

lookup a ticket by index number

get

(id: ID) => E | undefined

Get a ticket by ID

upsert

(id: ID, ticket?: Partial<Z>, event?: string) => E

Update or insert a ticket by ID

values

() => readonly E[]

Get all values of registered tickets

entries

() => readonly [ID, E][]

Get all entries of registered tickets

register

(ticket?: Partial<Z & RegistryTicket>) => E

Register a new ticket

unregister

(id: ID) => void

Unregister a ticket by ID

reindex

() => void

Reset the index directory and update all tickets

move

(id: ID, toIndex: number) => E | undefined

Seek for a ticket based on direction and optional predicate

seek

(direction?: "first" | "last", from?: number, predicate?: (ticket) => boolean) => E | undefined

on

<K extends Extensible<RegistryEventName>>(event: K, cb: EventHandler<E, K>) => void

Listen for registry events

off

<K extends Extensible<RegistryEventName>>(event: K, cb: EventHandler<E, K>) => void

Stop listening for registry events

emit

<K extends Extensible<RegistryEventName>>(event: K, data: EventPayload<E, K>) => void

Emit an event with data

dispose

() => void

Clears the registry and removes all listeners

onboard

(registrations: Partial<Z & RegistryTicket>[]) => E[]

Onboard multiple tickets at once

offboard

(ids: ID[]) => void

Offboard multiple tickets at once

batch

<R>(fn: () => R) => R

Execute operations in a batch, deferring cache invalidation and event emission until complete

undo

() => Z | undefined

Removes the last registered ticket and stores it for redo

redo

() => Z | undefined

Restores the last undone ticket

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/