Skip to main content

@lexical/y/headless

Classes​

YHeadlessError​

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

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:117

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:116

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:59

Experimental

Properties​

allowedRoots?​

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

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

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:76

Experimental

Update tag(s) of the edit's editor update. COLLABORATION_TAG and SKIP_COLLAB_TAG are refused ('ignored-tag'): the binding does not write an update that carries them, so the edit would be lost.

transact?​

optional transact?: (doc) => void

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

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:37

Experimental

The result of editYState.

Properties​

state​

state: Uint8Array

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

Experimental

state with update applied, garbage collected as clients and Yjs servers store a document (deleted content keeps only its tombstones). When update is null, state garbage collected the same way.

update​

update: Uint8Array<ArrayBufferLike> | null

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

Experimental

Everything the edit wrote, as one merged update, or null when it changed nothing. Includes what opening the document wrote (block ids an extension gives blocks that have none, which a client would also write), which the edit may depend on.

warnings​

warnings: LexicalWarning[]

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

Experimental

Warnings reported while opening and editing, oldest first (also passed to config.onWarn).


HeadlessYConfig​

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

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:78

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:69

Experimental

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

nodes?​

optional nodes?: readonly LexicalNodeConfig[]

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

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:88

Experimental

Called with every warning, as a LexicalWarning (the same ones the result's warnings lists): the binding's (@lexical/y/... codes), the editor's (it replaces an onWarn of the extensions; other errors come as EDITOR_WARNING), and FOLLOW_UPS_EXHAUSTED_WARNING. Warnings never refuse an edit, in any environment, and a throwing handler does not either. Default: console.warn outside production, nothing in production.

Parameters​
warning​

LexicalWarning

Returns​

void

root?​

optional root?: string

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

Experimental

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

selfCheck?​

optional selfCheck?: boolean

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

Experimental

The binding's self-check of its own writes (see YBindingOptions). Default: off.

Type Aliases​

YHeadlessErrorCode​

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

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

Experimental

Error codes of YHeadlessError.


YHeadlessWarningCode​

YHeadlessWarningCode = YWarningCode | typeof EDITOR_WARNING | typeof FOLLOW_UPS_EXHAUSTED_WARNING

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

Experimental

The codes of the warnings the headless helpers report (the code of each LexicalWarning they return or pass to onWarn): the binding's, and EDITOR_WARNING and FOLLOW_UPS_EXHAUSTED_WARNING. Codes are never renamed or reused; new ones may be added, so a switch over them needs a default.

Variables​

EDITOR_WARNING​

const EDITOR_WARNING: "@lexical/y/editor-warning" = '@lexical/y/editor-warning'

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

Experimental

A warning the editor reported through its onWarn that is not a LexicalWarning (Lexical's own, or an extension's), passed on as one with its message. data: {error: Error} (the warning as reported).


FOLLOW_UPS_EXHAUSTED_WARNING​

const FOLLOW_UPS_EXHAUSTED_WARNING: "@lexical/y/follow-ups-exhausted" = '@lexical/y/follow-ups-exhausted'

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

Experimental

The edit's listeners kept scheduling updates: after the last follow-up update the helpers commit, the rest were not committed and are not part of the result. data: {limit: number} (the follow-up updates committed). Once the binding writes, an update that changes content and is made after a commit in the same task (as a listener's is) commits at once, so Lexical's own guard stops such listeners instead (EDITOR_WARNING).

Functions​

editYState()​

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

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

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, when the update writes elsewhere, or when options.tag names a tag with which the binding writes nothing (COLLABORATION_TAG, SKIP_COLLAB_TAG). Whatever $edit throws (any value, an Error or not) is rethrown as it is, and nothing is written: transact does not run. Warnings (LexicalWarnings) are returned in warnings and passed to config.onWarn; they never refuse the edit.

With $edit a no-op, the update is what opening the document writes (ids an extension gives blocks that have none): 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:255

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:153

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. The state is garbage collected, as clients store a document.

Parameters​

config​

HeadlessYConfig

$build​

() => void

Returns​

Uint8Array