A file's named versions and autosaves, to preview and restore.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { type FileVersion, VersionHistory } from "./ui/uicontext/components/canvas/VersionHistory.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ panel: { inlineSize: "min(100%, 300px)", borderWidth: 1, borderStyle: "solid", borderColor: "light-dark(#ececef, #232327)", borderRadius: 12 } })const now = "2026-11-30T13:45:00.000Z"const ago = (minutes: number) => new Date(Date.parse(now) - minutes * 60_000).toISOString()const versions: ReadonlyArray<FileVersion> = [ { id: "v6", name: null, author: "Alex Kim", at: ago(2) }, { id: "v5", name: null, author: "Tom Okafor", at: ago(31) }, { id: "v4", name: null, author: "Priya Raman", at: ago(52) }, { id: "v3", name: "Handoff — sprint 14", note: "Home and onboarding ready for build.", author: "Priya Raman", at: ago(60 * 26) }, { id: "v2", name: null, author: "Leah Brandt", at: ago(60 * 50) }, { id: "v1", name: "Before crit", author: "Alex Kim", at: ago(60 * 76) },]const Message = UiSchema.TaggedEnum({ PickedVersion: { id: Schema.String }, ToggledRun: { first: Schema.String }, ClickedRestore: { id: Schema.String } })// Picking a version previews it; Restore brings it back as the newest version.export const FileHistory = Html.component({ name: "FileHistory", model: Schema.Struct({ current: Schema.NullOr(Schema.String), open: Schema.Array(Schema.String) }), message: Message,}).make({ init: () => ({ current: null, open: [] }), update: { PickedVersion: ($, { id }) => $.evolve({ current: id }), ToggledRun: ($, { first }) => $.evolve({ open: (o) => (o.includes(first) ? o.filter((x) => x !== first) : [...o, first]) }), ClickedRestore: ($) => $.evolve({ current: null }), }, view: (h, m) => h.div.attrs(sx(styles.panel)).children(VersionHistory(h, { versions, current: m.current, open: m.open, now, onPick: (id) => Message.PickedVersion({ id }), onToggleRun: (first) => Message.ToggledRun({ first }), onRestore: (id) => Message.ClickedRestore({ id }), })),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/version-historyUsage
import { type FileVersion, VersionHistory } from "./ui/uicontext/components/canvas/VersionHistory.ts"const Message = UiSchema.TaggedEnum({ PickedVersion: { id: Schema.String }, ToggledRun: { first: Schema.String } })export const History = (h: Html.H<typeof Message.Type>, versions: ReadonlyArray<FileVersion>, now: string) => VersionHistory(h, { versions, current: null, open: [], now, onPick: (id) => Message.PickedVersion({ id }), onToggleRun: (first) => Message.ToggledRun({ first }), })API reference
Options
| Name | Type | Description |
|---|---|---|
versionsrequired | FileVersion[] | — |
currentrequired | string | null | The version shown now; the newest is the live file |
openrequired | string[] | Runs of autosaves people opened, by the id of the first |
nowrequired | string | — |
onPickrequired | (id: string) => Message | — |
onToggleRunrequired | (first: string) => Message | — |
onRestore | (id: string) => Message | — |
onName | (id: string) => Message | — |