@lexical/y/headless
Classes
YHeadlessError
Defined in: packages/lexical-y/src/headless.ts:88
Experimental
The error the headless helpers throw when they refuse.
Extends
Constructors
Constructor
new YHeadlessError(
code,message):YHeadlessError
Defined in: packages/lexical-y/src/headless.ts:90
Experimental
Parameters
code
message
string
Returns
Overrides
Error.constructor
Properties
cause?
optionalcause?:unknown
Defined in: typescript/lib/lib.es2022.error.d.ts:24
Experimental
Inherited from
Error.cause
code
readonlycode:YHeadlessErrorCode
Defined in: packages/lexical-y/src/headless.ts:89
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?
optionalstack?:string
Defined in: typescript/lib/lib.es5.d.ts:1076
Experimental
Inherited from
Error.stack
stackTraceLimit
staticstackTraceLimit: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()
staticcaptureStackTrace(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?
Returns
void
Inherited from
Error.captureStackTrace
isError()
staticisError(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()
staticprepareStackTrace(err,stackTraces):any
Defined in: @types/node/globals.d.ts:55
Experimental
Parameters
err
stackTraces
CallSite[]
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTrace
Interfaces
CreateHeadlessYEditorOptions
Defined in: packages/lexical-y/src/headless.ts:56
Experimental
Extends
Properties
clientIDRange?
optionalclientIDRange?:ClientIDRange
Defined in: packages/lexical-y/src/headless.ts:39
Experimental
The range of the client ids the server writes with (default
'uint53'). Use 'uint32' when updates pass through yrs before 0.28.
Inherited from
extensions?
optionalextensions?: readonlyAnyLexicalExtensionArgument[]
Defined in: packages/lexical-y/src/headless.ts:30
Experimental
Extensions that define the editor: nodes, transforms, NodeState.
Inherited from
nodes?
optionalnodes?: readonlyLexicalNodeConfig[]
Defined in: packages/lexical-y/src/headless.ts:32
Experimental
Node classes, for an editor that is not defined by extensions.
Inherited from
onWarn?
optionalonWarn?: (message) =>void
Defined in: packages/lexical-y/src/headless.ts:47
Experimental
Called with the binding's and the editor's warnings (a write that had to
be recovered, a self-check mismatch, the reason a document is read only;
it replaces an onWarn of the extensions). Warnings never refuse an
edit, in any environment. Default: console.warn outside production,
nothing in production.
Parameters
message
string
Returns
void
Inherited from
root?
optionalroot?:string
Defined in: packages/lexical-y/src/headless.ts:34
Experimental
The name of the shared root (default 'lexical-y').
Inherited from
selfCheck?
optionalselfCheck?:boolean
Defined in: packages/lexical-y/src/headless.ts:52
Experimental
The binding's self-check of its own writes (see YBindingOptions).
Default: on in development, off in production.
Inherited from
state?
optionalstate?:Uint8Array<ArrayBufferLike> |null
Defined in: packages/lexical-y/src/headless.ts:58
Experimental
A Yjs update (usually the stored state) to load before binding.
EditYStateOptions
Defined in: packages/lexical-y/src/headless.ts:112
Experimental
Properties
allowedRoots?
optionalallowedRoots?:Iterable<string,any,any>
Defined in: packages/lexical-y/src/headless.ts:117
Experimental
The shared roots the update may write to; anything else refuses the edit. Default: the layout root only.
tag?
optionaltag?:string|string[]
Defined in: packages/lexical-y/src/headless.ts:125
Experimental
Update tag(s) of the edit's editor update.
transact?
optionaltransact?: (doc) =>void
Defined in: packages/lexical-y/src/headless.ts:123
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
Returns
void
EditYStateResult
Defined in: packages/lexical-y/src/headless.ts:98
Experimental
The result of editYState.
Properties
state
state:
Uint8Array
Defined in: packages/lexical-y/src/headless.ts:106
Experimental
state with update merged in.
update
update:
Uint8Array<ArrayBufferLike> |null
Defined in: packages/lexical-y/src/headless.ts:104
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:
string[]
Defined in: packages/lexical-y/src/headless.ts:108
Experimental
Warnings the binding reported while opening and editing.
HeadlessYConfig
Defined in: packages/lexical-y/src/headless.ts:28
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.
Extended by
Properties
clientIDRange?
optionalclientIDRange?:ClientIDRange
Defined in: packages/lexical-y/src/headless.ts:39
Experimental
The range of the client ids the server writes with (default
'uint53'). Use 'uint32' when updates pass through yrs before 0.28.
extensions?
optionalextensions?: readonlyAnyLexicalExtensionArgument[]
Defined in: packages/lexical-y/src/headless.ts:30
Experimental
Extensions that define the editor: nodes, transforms, NodeState.
nodes?
optionalnodes?: readonlyLexicalNodeConfig[]
Defined in: packages/lexical-y/src/headless.ts:32
Experimental
Node classes, for an editor that is not defined by extensions.
onWarn?
optionalonWarn?: (message) =>void
Defined in: packages/lexical-y/src/headless.ts:47
Experimental
Called with the binding's and the editor's warnings (a write that had to
be recovered, a self-check mismatch, the reason a document is read only;
it replaces an onWarn of the extensions). Warnings never refuse an
edit, in any environment. Default: console.warn outside production,
nothing in production.
Parameters
message
string
Returns
void
root?
optionalroot?:string
Defined in: packages/lexical-y/src/headless.ts:34
Experimental
The name of the shared root (default 'lexical-y').
selfCheck?
optionalselfCheck?:boolean
Defined in: packages/lexical-y/src/headless.ts:52
Experimental
The binding's self-check of its own writes (see YBindingOptions).
Default: on in development, off in production.
HeadlessYEditor
Defined in: packages/lexical-y/src/headless.ts:66
Experimental
A headless editor bound to its own Yjs 14 document, with
collaborative undo off. dispose (or using) releases the binding, the
editor and the document.
Extends
Properties
binding
readonlybinding:YBinding
Defined in: packages/lexical-y/src/headless.ts:69
Experimental
doc
readonlydoc:Doc
Defined in: packages/lexical-y/src/headless.ts:68
Experimental
editor
readonlyeditor:LexicalEditor
Defined in: packages/lexical-y/src/headless.ts:67
Experimental
warnings
readonlywarnings: readonlystring[]
Defined in: packages/lexical-y/src/headless.ts:71
Experimental
Warnings the binding reported, oldest first.
Methods
[dispose]()
[dispose]():
void
Defined in: typescript/lib/lib.esnext.disposable.d.ts:34
Experimental
Returns
void
Inherited from
Disposable.[dispose]
dispose()
dispose():
void
Defined in: packages/lexical-y/src/headless.ts:72
Experimental
Returns
void
Type Aliases
YHeadlessErrorCode
YHeadlessErrorCode =
"not-initialized"|"read-only"|"foreign-roots"
Defined in: packages/lexical-y/src/headless.ts:76
Experimental
Functions
createHeadlessYEditor()
createHeadlessYEditor(
options?):HeadlessYEditor
Defined in: packages/lexical-y/src/headless.ts:274
Experimental
A headless editor bound to a new Yjs 14 document holding
state, after the layout record has been read. Throws a
YHeadlessError ('read-only') when the binding cannot write the
document (a newer layout, unknown node types). With no state (or an empty
one) the binding is 'pending': write content and call
binding.initialize() to seed it.
Parameters
options?
CreateHeadlessYEditorOptions = {}
Returns
editYState()
editYState(
state,config,$edit,options?):EditYStateResult
Defined in: packages/lexical-y/src/headless.ts:319
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. The binding's warnings are reported
(config.onWarn, and warnings in the result) and 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
config
$edit
() => void
options?
EditYStateOptions = {}
Returns
readYState()
readYState<
T>(state,config,$read):T
Defined in: packages/lexical-y/src/headless.ts:376
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
config
$read
() => T
Returns
T
seedYState()
seedYState(
config,$build):Uint8Array
Defined in: packages/lexical-y/src/headless.ts:288
Experimental
The state of a new document whose content $build writes
into an empty root. The content is written the way a client's
initialize() writes it: with a client id derived from the content 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.
Parameters
config
$build
() => void