Built-in Undo and Redo
Standalone sessions (those without anoverrides option) automatically attach a history module. You call undo() and redo() directly on the composition, and guard UI state with canUndo() and canRedo().
Opting out of the built-in history
Passhistory: false when the host application owns the undo stack and you want the SDK to emit patches without building a parallel internal stack:
history: false only disables the SDK undo stack. Persistence (auto-save) is independent — passing history: false does not suppress disk writes.Coalescing rapid edits
The history module coalesces patch events into one undo entry when two conditions are met: the same op types and same element paths are touched within a configurable window. This prevents a slider drag from flooding the stack with hundreds of individual entries. The default coalesce window is 300 ms. Override it inopenComposition:
HistoryOptions type, see Utilities.
Patch Events
Every committed change emits apatch event. Subscribe to mirror SDK edits into your host state, audit log, or collaboration channel.
PatchEvent fields
Always
1 in the current SDK. Check this and reject unknown versions — a bump means a breaking change.Forward patches that were applied: the add/remove/replace ops describing how the document changed.
Inverse patches that undo this change. Store these alongside
patches to support host-owned undo.The origin tag that was passed to
dispatch() or batch(). Use it to route or filter events.Semantic names of the operations that produced this event (e.g.
["setStyle"]). Useful for analytics and history labels. Not versioned — treat as informational.JsonPatchOp
The SDK emits and accepts only the add/remove/replace subset of RFC 6902:move, copy, or test ops, and applyPatches() ignores them if passed.
Origin Model
Every mutation is tagged with an origin string. The SDK defines two built-in origins:| Constant | Value | When used |
|---|---|---|
ORIGIN_LOCAL | "local" | Default for all dispatch() and batch() calls |
ORIGIN_APPLY_PATCHES | "@hyperframes/sdk:applyPatches" | Automatically applied by applyPatches() |
@hyperframes/sdk.
Setting a custom origin
Passorigin in the options to dispatch() or batch() to tag the event for downstream routing:
Host-Owned History with applyPatches
Whenhistory: false, the host maintains its own undo stack from the patch events the SDK emits. To replay an undo step back into the SDK, call applyPatches() with the inverse patches from that stack entry:
Preventing undo loops
applyPatches() auto-tags its patch event with ORIGIN_APPLY_PATCHES. Your listener must skip that origin or you create an infinite loop:
ORIGIN_APPLY_PATCHES is a namespaced string ("@hyperframes/sdk:applyPatches") rather than a Symbol so it survives postMessage, structured clone, and JSON round-trips — important when the host forwards patch events across frames or workers.
applyPatches with a custom origin
If you want downstream listeners to receive an explicit marker different from the default:ORIGIN_APPLY_PATCHES will enter the history module if history is still attached. Use history: false or a trackedOrigins filter when running host-owned history to avoid double-stacking.
Embedded Override Mode Integration
In embedded (T3) mode, the host stores only the sparse override delta for each user. Pairhistory: false with applyPatches() to let the host drive undo while the SDK updates the composition state:
Composition API
Full method signatures for
undo, redo, canUndo, canRedo, on, applyPatches, dispatch, and batch.Types
PatchEvent, JsonPatchOp, ORIGIN_APPLY_PATCHES, ORIGIN_LOCAL, and related types.Utilities
HistoryOptions, coalesceMs, trackedOrigins, and createHistory internals.Embedded Override Mode
Full T3 embedded integration with host-owned history.