From zbeyens. The source code is available on GitHub.

Plate
PlatePliteEditorsTemplates
GitHub16kGitHub
DiscordDiscord
UNPUBLISHED
  • Overview
  • Why This Fork
  • Examples
Walkthroughs
  • Installing Plite
  • Adding Event Handlers
  • Defining Custom Elements
  • Applying Custom Formatting
  • Executing Commands
  • Saving to a Database
  • Canonical Change Substrate
  • Improving Performance
Concepts
  • Interfaces
  • Nodes
  • Locations
  • Transforms
  • Document Changes
  • Commands
  • Editor
  • Extensions
  • Rendering
  • Serializing
  • Normalizing
  • Using TypeScript
  • Roots
  • Document State
  • Editing Behavior
  • Selection And DOM
  • Clipboard And Paste
  • Projection And Overlays
  • Schema
API
  • Anchor API
  • Location API
  • Path API
  • PointEntry API
  • Point API
  • Range API
  • Selection API
  • Location Types APIs
  • Span API
  • Editor
  • Element API
  • NodeEntry API
  • Node API
  • Node Types APIs
  • Text API
  • Debug Value Scrubbing
  • Transforms API
Libraries
  • Plite DOM
  • History Editor API
  • History Extension Setup
  • History
  • Plite History
  • Plite Hyperscript
  • Plite Layout
  • Annotations
  • DOM Coverage Boundaries
  • Editable Component
  • Plite React Event Handling
  • Virtualized Rendering
  • Plite React Hooks
  • React Editor Setup
  • React Editor
  • Plite React
  • Plite Component
  • Plite Yjs
  • Plite
General
  • Migration
  • Contributing
  • Docs Proof Map
  • FAQ
  • Resources

Anchor API

PreviousNext

Root-aware live paths, points, and ranges mapped by canonical document changes.

An anchor keeps a path, point, or range mapped through canonical DocumentChange values. Choose its API by lifetime: editor.anchor is persistent, while tx.anchor is limited to one transaction callback.

Persistent Anchors

editor.anchor(value, options) => Anchor

const selection = editor.read.selection






ExamplesLocation API

On This Page

Persistent Anchorseditor.anchor(value, options) => AnchorTransaction Anchorstx.anchor(value, options) => EditorTransactionAnchor
Build your editor
Production-ready AI template and reusable components.
Get all-access
();
if (!selection) return;
const target = editor.anchor(selection, {
association: "inward",
deletion: "drop",
});
const selection = editor.read.selection();
 
if (!selection) return;
 
const target = editor.anchor(selection, {
  association: "inward",
  deletion: "drop",
});

deletion is required:

  • "drop" resolves to null when the target is deleted.
  • "nearest" resolves to the nearest valid location.

Paths and points accept "backward" or "forward" association. Ranges also accept "inward" and "outward". Pass root for a rootless value that belongs to a named document root.

Persistent anchors remain active across commits until release() is called.

const current = target.resolve();
const finalValue = target.release();
const current = target.resolve();
const finalValue = target.release();

resolve() returns the current mapped value without ending tracking. release() returns the current value and permanently detaches the anchor. Both return null after a dropped target or release.

Use persistent anchors for application-owned runtime state such as local annotations. Release them when their owner is removed.

Transaction Anchors

tx.anchor(value, options) => EditorTransactionAnchor

Transaction anchors track a location only while the update or detached transaction builder is active.

editor.update((tx) => {
  const target = tx.anchor(range, {
    association: "inward",
    deletion: "nearest",
  });
 
  tx.text.delete({ at: range });
 
  const mapped = target.resolve();
 
  if (mapped) tx.selection.set(mapped);
});
editor.update((tx) => {
  const target = tx.anchor(range, {
    association: "inward",
    deletion: "nearest",
  });
 
  tx.text.delete({ at: range });
 
  const mapped = target.resolve();
 
  if (mapped) tx.selection.set(mapped);
});

EditorTransactionAnchor exposes only resolve(). The transaction releases its backing anchor automatically. Calling resolve() after the callback ends throws because the transaction is no longer active.

Anchors are runtime values. Persist the resolved path, point, or range only when the application owns a durable serialization policy.