Skip to main content

@lexical/y/headless

Classes​

YHeadlessError​

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:103

Experimental

The error the headless helpers throw when they refuse.

Extends​

Constructors​

Constructor​

new YHeadlessError(code, message): YHeadlessError

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:105

Experimental

Parameters​
code​

YHeadlessErrorCode

message​

string

Returns​

YHeadlessError

Overrides​

Error.constructor

Properties​

cause?​

optional cause?: unknown

Defined in: typescript/lib/lib.es2022.error.d.ts:24

Experimental

Inherited from​

Error.cause

code​

readonly code: YHeadlessErrorCode

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:104

Experimental

message​

message: string

Defined in: typescript/lib/lib.es5.d.ts:1075

Experimental

Inherited from​

Error.message

name​

name: string

Defined in: typescript/lib/lib.es5.d.ts:1074

Experimental

Inherited from​

Error.name

stack?​

optional stack?: string

Defined in: typescript/lib/lib.es5.d.ts:1076

Experimental

Inherited from​

Error.stack

stackTraceLimit​

static stackTraceLimit: number

Defined in: @types/node/globals.d.ts:67

Experimental

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Inherited from​

Error.stackTraceLimit

Methods​

captureStackTrace()​

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: @types/node/globals.d.ts:51

Experimental

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
b();
}

function b() {
c();
}

function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;

// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}

a();
Parameters​
targetObject​

object

constructorOpt?​

Function

Returns​

void

Inherited from​

Error.captureStackTrace

isError()​

static isError(error): error is Error

Defined in: typescript/lib/lib.esnext.error.d.ts:21

Experimental

Indicates whether the argument provided is a built-in Error instance or not.

Parameters​
error​

unknown

Returns​

error is Error

Inherited from​

Error.isError

prepareStackTrace()​

static prepareStackTrace(err, stackTraces): any

Defined in: @types/node/globals.d.ts:55

Experimental

Parameters​
err​

Error

stackTraces​

CallSite[]

Returns​

any

See​

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from​

Error.prepareStackTrace

Interfaces​

EditYStateOptions​

Defined in: packages/lexical-y/src/headless.ts:49

Experimental

Properties​

allowedRoots?​

optional allowedRoots?: Iterable<string, any, any>

Defined in: packages/lexical-y/src/headless.ts:54

Experimental

The shared roots the update may write to; anything else refuses the edit. Default: the layout root only.

tag?​

optional tag?: string | string[]

Defined in: packages/lexical-y/src/headless.ts:62

Experimental

Update tag(s) of the edit's editor update.

transact?​

optional transact?: (doc) => void

Defined in: packages/lexical-y/src/headless.ts:60

Experimental

Writes to other shared types of the document (for example an activity log), run in one Yjs transaction after the edit. Their roots must be in allowedRoots.

Parameters​
doc​

Doc

Returns​

void


EditYStateResult​

Defined in: packages/lexical-y/src/headless.ts:35

Experimental

The result of editYState.

Properties​

state​

state: Uint8Array

Defined in: packages/lexical-y/src/headless.ts:43

Experimental

state with update merged in.

update​

update: Uint8Array<ArrayBufferLike> | null

Defined in: packages/lexical-y/src/headless.ts:41

Experimental

Everything the edit wrote, as one merged update, or null when it changed nothing. Includes what opening the document wrote (repairs and refreshes a client would also write), which the edit may depend on.

warnings​

warnings: YHeadlessWarning[]

Defined in: packages/lexical-y/src/headless.ts:45

Experimental

Warnings reported while opening and editing, oldest first.


HeadlessYConfig​

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:63

Experimental

The editor a headless helper binds: the same extensions (or nodes) as the clients' editors, so that the server reads and writes the document the way a client would.

Properties​

clientIDRange?​

optional clientIDRange?: ClientIDRange

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:74

Experimental

The range of the client ids the server writes with (default 'uint53'). Use 'uint32' when updates pass through yrs before 0.28.

extensions?​

optional extensions?: readonly AnyLexicalExtensionArgument[]

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:65

Experimental

Extensions that define the editor: nodes, transforms, NodeState.

nodes?​

optional nodes?: readonly LexicalNodeConfig[]

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:67

Experimental

Node classes, for an editor that is not defined by extensions.

onWarn?​

optional onWarn?: (warning) => void

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:82

Experimental

Called with every warning (see YHeadlessWarningCode): the binding's, the editor's (it replaces an onWarn of the extensions), and follow-up updates left uncommitted. Warnings never refuse an edit, in any environment. Default: console.warn outside production, nothing in production.

Parameters​
warning​

YHeadlessWarning

Returns​

void

root?​

optional root?: string

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:69

Experimental

The name of the shared root (default 'lexical-y').

selfCheck?​

optional selfCheck?: boolean

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:87

Experimental

The binding's self-check of its own writes (see YBindingOptions). Default: on in development, off in production.


YHeadlessWarning​

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:53

Experimental

A warning of the headless helpers, passed to config.onWarn and returned in warnings.

Properties​

code​

readonly code: YHeadlessWarningCode

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:54

Experimental

message​

readonly message: string

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:55

Experimental

Type Aliases​

YHeadlessErrorCode​

YHeadlessErrorCode = "not-initialized" | "read-only" | "foreign-roots"

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:91

Experimental

Error codes of YHeadlessError.


YHeadlessWarningCode​

YHeadlessWarningCode = YWarningCode | "editor-warning" | "follow-ups-exhausted"

Defined in: packages/lexical-y/src/internal/HeadlessEditor.ts:35

Experimental

What a YHeadlessWarning reports: the binding's codes (see YWarningCode in @lexical/y) and two of the headless helpers' own. Codes are stable: new ones may be added, existing ones keep their meaning.

Functions​

editYState()​

editYState(state, config, $edit, options?): EditYStateResult

Defined in: packages/lexical-y/src/headless.ts:118

Experimental

Run $edit (one discrete editor update, plus the updates it makes listeners schedule) on the document at state and return the update it makes. The update is checked to write only to allowedRoots. Throws a YHeadlessError when the document is not initialized or is read only, or when the update writes elsewhere; an error thrown by $edit is rethrown and nothing is written. Warnings (see YHeadlessWarningCode) are reported to config.onWarn and returned in warnings; they do not refuse the edit.

With $edit a no-op, the update is what opening the document writes (ids an extension gives blocks that have none, repairs): store it once before relying on readYState for such values.

Parameters​

state​

Uint8Array

config​

HeadlessYConfig

$edit​

() => void

options?​

EditYStateOptions = {}

Returns​

EditYStateResult


readYState()​

readYState<T>(state, config, $read): T

Defined in: packages/lexical-y/src/headless.ts:175

Experimental

The value $read returns from the document at state (for example its Markdown or $getEditor().getEditorState().toJSON()). Nothing is written. Throws a YHeadlessError when the document is not initialized or is read only.

What opening the document writes is discarded: a value an extension assigns on open (an id for a block stored without one) is read here but never stored, so two reads can disagree. Store the update of a no-op editYState first.

Type Parameters​

T​

T

Parameters​

state​

Uint8Array

config​

HeadlessYConfig

$read​

() => T

Returns​

T


seedYState()​

seedYState(config, $build): Uint8Array

Defined in: packages/lexical-y/src/headless.ts:86

Experimental

The state of a new document whose content $build writes into an empty root: the documented way to seed a document (from a template, an import, or a converter's editor). The content is written the way a client's initialize() writes it: with a client id derived from the content (53 bits under 'uint53', 32 under 'uint32') and outside any undo history. Seeding identical content twice gives the same bytes, and the two seeds merge into one copy; content with random parts (such as ids an extension draws for new blocks) is not identical. The state only holds the layout root, so a converter merges it into the stored document next to an older layout's root.

Parameters​

config​

HeadlessYConfig

$build​

() => void

Returns​

Uint8Array