Module: lexical
Classes
- ArtificialNode__DO_NOT_USE
- DecoratorNode
- EditorState
- ElementDOMSlot
- ElementNode
- LexicalEditor
- LexicalNode
- LineBreakNode
- NodeSelection
- ParagraphNode
- Point
- RangeSelection
- RootNode
- StateConfig
- TabNode
- TextNode
Interfaces
- BaseCaret
- BaseSelection
- CaretRange
- ChildCaret
- CommonAncestorResultAncestor
- CommonAncestorResultBranch
- CommonAncestorResultDescendant
- CommonAncestorResultSame
- EditorStateReadOptions
- SerializedEditorState
- SiblingCaret
- SplitAtPointCaretNextOptions
- StateValueConfig
- StaticNodeConfigValue
- StepwiseIteratorConfig
- TextPointCaret
- TextPointCaretSlice
- UpdateListenerPayload
Type Aliases
AnyStateConfig
Ƭ AnyStateConfig: StateConfig<any, any>
For advanced use cases, using this type is not recommended unless it is required (due to TypeScript's lack of features like higher-kinded types).
A StateConfig type with any key and any value that can be used in situations where the key and value type can not be known, such as in a generic constraint when working with a collection of StateConfig.
StateConfigKey and StateConfigValue will be useful when this is used as a generic constraint.
Defined in
packages/lexical/src/LexicalNodeState.ts:288
BaseStaticNodeConfig
Ƭ BaseStaticNodeConfig: { readonly [K in string]?: StaticNodeConfigValue<LexicalNode, string> }
This is the type of LexicalNode.$config() that can be overridden by subclasses.
Defined in
packages/lexical/src/LexicalNode.ts:169
CaretDirection
Ƭ CaretDirection: "next" | "previous"
The direction of a caret, 'next' points towards the end of the document and 'previous' points towards the beginning
Defined in
packages/lexical/src/caret/LexicalCaret.ts:22
CaretType
Ƭ CaretType: "sibling" | "child"
A sibling caret type points from a LexicalNode origin to its next or previous sibling, and a child caret type points from an ElementNode origin to its first or last child.
Defined in
packages/lexical/src/caret/LexicalCaret.ts:32
CommandListener
Ƭ CommandListener<P>: (payload: P, editor: LexicalEditor) => boolean
Type parameters
| Name |
|---|
P |
Type declaration
▸ (payload, editor): boolean
Parameters
| Name | Type |
|---|---|
payload | P |
editor | LexicalEditor |
Returns
boolean
Defined in
packages/lexical/src/LexicalEditor.ts:343
CommandListenerPriority
Ƭ CommandListenerPriority: 0 | 1 | 2 | 3 | 4
Defined in
packages/lexical/src/LexicalEditor.ts:347
CommandPayloadType
Ƭ CommandPayloadType<TCommand>: TCommand extends LexicalCommand<infer TPayload> ? TPayload : never
Type helper for extracting the payload type from a command.
Example
const MY_COMMAND = createCommand<SomeType>();
// ...
editor.registerCommand(MY_COMMAND, payload => {
// Type of `payload` is inferred here. But lets say we want to extract a function to delegate to
$handleMyCommand(editor, payload);
return true;
});
function $handleMyCommand(editor: LexicalEditor, payload: CommandPayloadType<typeof MY_COMMAND>) {
// `payload` is of type `SomeType`, extracted from the command.
}
Type parameters
| Name | Type |
|---|---|
TCommand | extends LexicalCommand<unknown> |
Defined in
packages/lexical/src/LexicalEditor.ts:380
CommonAncestorResult
Ƭ CommonAncestorResult<A, B>: CommonAncestorResultSame<A> | CommonAncestorResultAncestor<A & ElementNode> | CommonAncestorResultDescendant<B & ElementNode> | CommonAncestorResultBranch<A, B>
The result of comparing two nodes that share some common ancestor
Type parameters
| Name | Type |
|---|---|
A | extends LexicalNode |
B | extends LexicalNode |
Defined in
packages/lexical/src/caret/LexicalCaret.ts:1330
CreateEditorArgs
Ƭ CreateEditorArgs: Object
Type declaration
| Name | Type |
|---|---|
disableEvents? | boolean |
editable? | boolean |
editorState? | EditorState |
html? | HTMLConfig |
namespace? | string |
nodes? | ReadonlyArray<LexicalNodeConfig> |
onError? | ErrorHandler |
parentEditor? | LexicalEditor |
theme? | EditorThemeClasses |
Defined in
packages/lexical/src/LexicalEditor.ts:217
DOMChildConversion
Ƭ DOMChildConversion: (lexicalNode: LexicalNode, parentLexicalNode: LexicalNode | null | undefined) => LexicalNode | null | undefined
Type declaration
▸ (lexicalNode, parentLexicalNode): LexicalNode | null | undefined
Parameters
| Name | Type |
|---|---|
lexicalNode | LexicalNode |
parentLexicalNode | LexicalNode | null | undefined |
Returns
LexicalNode | null | undefined
Defined in
packages/lexical/src/LexicalNode.ts:350
DOMConversion
Ƭ DOMConversion<T>: Object
Type parameters
| Name | Type |
|---|---|
T | extends HTMLElement = HTMLElement |
Type declaration
| Name | Type |
|---|---|
conversion | DOMConversionFn<T> |
priority? | 0 | 1 | 2 | 3 | 4 |
Defined in
packages/lexical/src/LexicalNode.ts:341
DOMConversionFn
Ƭ DOMConversionFn<T>: (element: T) => DOMConversionOutput | null
Type parameters
| Name | Type |
|---|---|
T | extends HTMLElement = HTMLElement |
Type declaration
▸ (element): DOMConversionOutput | null
Parameters
| Name | Type |
|---|---|
element | T |
Returns
DOMConversionOutput | null
Defined in
packages/lexical/src/LexicalNode.ts:346
DOMConversionMap
Ƭ DOMConversionMap<T>: Record<NodeName, DOMConversionProp<T>>
Type parameters
| Name | Type |
|---|---|
T | extends HTMLElement = HTMLElement |
Defined in
packages/lexical/src/LexicalNode.ts:355
DOMConversionOutput
Ƭ DOMConversionOutput: Object
Type declaration
| Name | Type |
|---|---|
after? | (childLexicalNodes: LexicalNode[]) => LexicalNode[] |
forChild? | DOMChildConversion |
node | null | LexicalNode | LexicalNode[] |
Defined in
packages/lexical/src/LexicalNode.ts:361
DOMExportOutput
Ƭ DOMExportOutput: Object
Type declaration
| Name | Type |
|---|---|
after? | (generatedElement: HTMLElement | DocumentFragment | Text | null | undefined) => HTMLElement | DocumentFragment | Text | null | undefined |
element | HTMLElement | DocumentFragment | Text | null |
Defined in
packages/lexical/src/LexicalNode.ts:372
DOMExportOutputMap
Ƭ DOMExportOutputMap: Map<Klass<LexicalNode>, (editor: LexicalEditor, target: LexicalNode) => DOMExportOutput>
Defined in
packages/lexical/src/LexicalNode.ts:367
EditableListener
Ƭ EditableListener: (editable: boolean) => void
Type declaration
▸ (editable): void
Parameters
| Name | Type |
|---|---|
editable | boolean |
Returns
void
Defined in
packages/lexical/src/LexicalEditor.ts:345
EditorConfig
Ƭ EditorConfig: Object
Type declaration
| Name | Type |
|---|---|
disableEvents? | boolean |
namespace | string |
theme | EditorThemeClasses |
Defined in
packages/lexical/src/LexicalEditor.ts:192
EditorSetOptions
Ƭ EditorSetOptions: Object
Type declaration
| Name | Type |
|---|---|
tag? | string |
Defined in
packages/lexical/src/LexicalEditor.ts:116
EditorThemeClassName
Ƭ EditorThemeClassName: string
Defined in
packages/lexical/src/LexicalEditor.ts:72
EditorThemeClasses
Ƭ EditorThemeClasses: Object
Index signature
▪ [key: string]: any
Type declaration
Defined in
packages/lexical/src/LexicalEditor.ts:128
EditorUpdateOptions
Ƭ EditorUpdateOptions: Object
Type declaration
| Name | Type | Description |
|---|---|---|
discrete? | true | If true, prevents this update from being batched, forcing it to run synchronously. |
onUpdate? | () => void | - |
skipTransforms? | true | Setting this to true will suppress all node transforms for this update cycle. Useful for synchronizing updates in some cases. |
tag? | UpdateTag | UpdateTag[] | A tag to identify this update, in an update listener, for instance. See also $addUpdateTag. |
Defined in
packages/lexical/src/LexicalEditor.ts:91
ElementFormatType
Ƭ ElementFormatType: "left" | "start" | "center" | "right" | "end" | "justify" | ""
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:68
ElementPoint
Ƭ ElementPoint: Object
Type declaration
| Name | Type |
|---|---|
_selection | BaseSelection |
getNode | () => ElementNode |
is | (point: PointType) => boolean |
isBefore | (point: PointType) => boolean |
key | NodeKey |
offset | number |
set | (key: NodeKey, offset: number, type: "text" | "element", onlyIfChanged?: boolean) => void |
type | "element" |
Defined in
packages/lexical/src/LexicalSelection.ts:111
EventHandler
Ƭ EventHandler: (event: Event, editor: LexicalEditor) => void
Type declaration
▸ (event, editor): void
Parameters
| Name | Type |
|---|---|
event | Event |
editor | LexicalEditor |
Returns
void
Defined in
packages/lexical/src/LexicalEvents.ts:1316
FlipDirection
Ƭ FlipDirection<D>: typeof FLIP_DIRECTION[D]
A type utility to flip next and previous
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Defined in
packages/lexical/src/caret/LexicalCaret.ts:26
HTMLConfig
Ƭ HTMLConfig: Object
Type declaration
| Name | Type |
|---|---|
export? | DOMExportOutputMap |
import? | DOMConversionMap |
Defined in
packages/lexical/src/LexicalEditor.ts:207
Klass
Ƭ Klass<T>: InstanceType<T["constructor"]> extends T ? T["constructor"] : GenericConstructor<T> & T["constructor"]
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
Defined in
packages/lexical/src/LexicalEditor.ts:66
KlassConstructor
Ƭ KlassConstructor<Cls>: GenericConstructor<InstanceType<Cls>> & { [k in keyof Cls]: Cls[k] }
Type parameters
| Name | Type |
|---|---|
Cls | extends GenericConstructor<any> |
Defined in
packages/lexical/src/LexicalEditor.ts:61
LexicalCommand
Ƭ LexicalCommand<TPayload>: Object
Type parameters
| Name |
|---|
TPayload |
Type declaration
| Name | Type |
|---|---|
type? | string |
Defined in
packages/lexical/src/LexicalEditor.ts:356
LexicalExportJSON
Ƭ LexicalExportJSON<T>: Prettify<Omit<ReturnType<T["exportJSON"]>, "type"> & { type: GetStaticNodeType<T> } & NodeStateJSON<T>>
The most precise type we can infer for the JSON that will be produced by T.exportJSON().
Do not use this for the return type of T.exportJSON()! It must be a more generic type to be compatible with subclassing.
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
Defined in
packages/lexical/src/LexicalNode.ts:224
LexicalNodeConfig
Ƭ LexicalNodeConfig: Klass<LexicalNode> | LexicalNodeReplacement
A LexicalNode class or LexicalNodeReplacement configuration
Defined in
packages/lexical/src/LexicalEditor.ts:215
LexicalNodeReplacement
Ƭ LexicalNodeReplacement: Object
Type declaration
| Name | Type |
|---|---|
replace | Klass<LexicalNode> |
with | <T>(node: InstanceType<T>) => LexicalNode |
withKlass? | Klass<LexicalNode> |
Defined in
packages/lexical/src/LexicalEditor.ts:198
LexicalUpdateJSON
Ƭ LexicalUpdateJSON<T>: Omit<T, "children" | "type" | "version">
Omit the children, type, and version properties from the given SerializedLexicalNode definition.
Type parameters
| Name | Type |
|---|---|
T | extends SerializedLexicalNode |
Defined in
packages/lexical/src/LexicalNode.ts:233
MutationListener
Ƭ MutationListener: (nodes: Map<NodeKey, NodeMutation>, payload: { dirtyLeaves: Set<string> ; prevEditorState: EditorState ; updateTags: Set<string> }) => void
Type declaration
▸ (nodes, payload): void
Parameters
| Name | Type |
|---|---|
nodes | Map<NodeKey, NodeMutation> |
payload | Object |
payload.dirtyLeaves | Set<string> |
payload.prevEditorState | EditorState |
payload.updateTags | Set<string> |
Returns
void
Defined in
packages/lexical/src/LexicalEditor.ts:334
NodeCaret
Ƭ NodeCaret<D>: SiblingCaret<LexicalNode, D> | ChildCaret<ElementNode, D>
A NodeCaret is the combination of an origin node and a direction that points towards where a connected node will be fetched, inserted, or replaced. A SiblingCaret points from a node to its next or previous sibling, and a ChildCaret points to its first or last child (using next or previous as direction, for symmetry with SiblingCaret).
The differences between NodeCaret and PointType are:
- NodeCaret can only be used to refer to an entire node (PointCaret is used when a full analog is needed). A PointType of text type can be used to refer to a specific location inside of a TextNode.
- NodeCaret stores an origin node, type (sibling or child), and direction (next or previous). A PointType stores a type (text or element), the key of a node, and a text or child offset within that node.
- NodeCaret is directional and always refers to a very specific node, eliminating all ambiguity. PointType can refer to the location before or at a node depending on context.
- NodeCaret is more robust to nearby mutations, as it relies only on a node's direct connections. An element Any change to the count of previous siblings in an element PointType will invalidate it.
- NodeCaret is designed to work more directly with the internal representation of the document tree, making it suitable for use in traversals without performing any redundant work.
The caret does not update in response to any mutations, you should not persist it across editor updates, and using a caret after its origin node has been removed or replaced may result in runtime errors.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection = CaretDirection |
Defined in
packages/lexical/src/caret/LexicalCaret.ts:150
NodeKey
Ƭ NodeKey: string
Defined in
packages/lexical/src/LexicalNode.ts:379
NodeMap
Ƭ NodeMap: Map<NodeKey, LexicalNode>
Defined in
packages/lexical/src/LexicalNode.ts:68
NodeMutation
Ƭ NodeMutation: "created" | "updated" | "destroyed"
Defined in
packages/lexical/src/LexicalEditor.ts:251
NodeStateJSON
Ƭ NodeStateJSON<T>: Prettify<{ $?: Prettify<CollectStateJSON<GetNodeStateConfig<T>, false>> } & CollectStateJSON<GetNodeStateConfig<T>, true>>
The NodeState JSON produced by this LexicalNode
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
Defined in
packages/lexical/src/LexicalNodeState.ts:149
PasteCommandType
Ƭ PasteCommandType: ClipboardEvent | InputEvent | KeyboardEvent
Defined in
packages/lexical/src/LexicalCommands.ts:15
PointCaret
Ƭ PointCaret<D>: TextPointCaret<TextNode, D> | SiblingCaret<LexicalNode, D> | ChildCaret<ElementNode, D>
A PointCaret is a NodeCaret that also includes a TextPointCaret type which refers to a specific offset of a TextNode. This type is separate because it is not relevant to general node traversal so it doesn't make sense to have it show up except when defining a CaretRange and in those cases there will be at most two of them only at the boundaries.
The addition of TextPointCaret allows this type to represent any location that is representable by PointType, as the TextPointCaret refers to a specific offset within a TextNode.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection = CaretDirection |
Defined in
packages/lexical/src/caret/LexicalCaret.ts:166
PointType
Ƭ PointType: TextPoint | ElementPoint
Defined in
packages/lexical/src/LexicalSelection.ts:127
RootListener
Ƭ RootListener: (rootElement: null | HTMLElement, prevRootElement: null | HTMLElement) => void
Type declaration
▸ (rootElement, prevRootElement): void
Parameters
| Name | Type |
|---|---|
rootElement | null | HTMLElement |
prevRootElement | null | HTMLElement |
Returns
void
Defined in
packages/lexical/src/LexicalEditor.ts:327
RootMode
Ƭ RootMode: "root" | "shadowRoot"
The RootMode is specified in all caret traversals where the traversal can go up towards the root. 'root' means that it will stop at the document root, and 'shadowRoot' will stop at the document root or any shadow root (per $isRootOrShadowRoot).
Defined in
packages/lexical/src/caret/LexicalCaret.ts:39
SerializedEditor
Ƭ SerializedEditor: Object
Type declaration
| Name | Type |
|---|---|
editorState | SerializedEditorState |
Defined in
packages/lexical/src/LexicalEditor.ts:418
SerializedElementNode
Ƭ SerializedElementNode<T>: Spread<{ children: T[] ; direction: "ltr" | "rtl" | null ; format: ElementFormatType ; indent: number ; textFormat?: number ; textStyle?: string }, SerializedLexicalNode>
Type parameters
| Name | Type |
|---|---|
T | extends SerializedLexicalNode = SerializedLexicalNode |
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:54
SerializedLexicalNode
Ƭ SerializedLexicalNode: Object
The base type for all serialized nodes
Type declaration
| Name | Type | Description |
|---|---|---|
$? | Record<string, unknown> | Any state persisted with the NodeState API that is not configured for flat storage |
type | string | The type string used by the Node class |
version | number | A numeric version for this schema, defaulting to 1, but not generally recommended for use |
Defined in
packages/lexical/src/LexicalNode.ts:73
SerializedLineBreakNode
Ƭ SerializedLineBreakNode: SerializedLexicalNode
Defined in
packages/lexical/src/nodes/LexicalLineBreakNode.ts:24
SerializedParagraphNode
Ƭ SerializedParagraphNode: Spread<{ textFormat: number ; textStyle: string }, SerializedElementNode>
Defined in
packages/lexical/src/nodes/LexicalParagraphNode.ts:36
SerializedRootNode
Ƭ SerializedRootNode<T>: SerializedElementNode<T>
Type parameters
| Name | Type |
|---|---|
T | extends SerializedLexicalNode = SerializedLexicalNode |
Defined in
packages/lexical/src/nodes/LexicalRootNode.ts:20
SerializedTabNode
Ƭ SerializedTabNode: SerializedTextNode
Defined in
packages/lexical/src/nodes/LexicalTabNode.ts:24
SerializedTextNode
Ƭ SerializedTextNode: Spread<{ detail: number ; format: number ; mode: TextModeType ; style: string ; text: string }, SerializedLexicalNode>
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:76
Spread
Ƭ Spread<T1, T2>: Omit<T2, keyof T1> & T1
Type parameters
| Name |
|---|
T1 |
T2 |
Defined in
packages/lexical/src/LexicalEditor.ts:57
StateConfigKey
Ƭ StateConfigKey<S>: S extends StateConfig<infer K, infer _V> ? K : never
Get the key type (K) from a StateConfig
Type parameters
| Name | Type |
|---|---|
S | extends AnyStateConfig |
Defined in
packages/lexical/src/LexicalNodeState.ts:36
StateConfigValue
Ƭ StateConfigValue<S>: S extends StateConfig<infer _K, infer V> ? V : never
Get the value type (V) from a StateConfig
Type parameters
| Name | Type |
|---|---|
S | extends AnyStateConfig |
Defined in
packages/lexical/src/LexicalNodeState.ts:27
StateValueOrUpdater
Ƭ StateValueOrUpdater<Cfg>: ValueOrUpdater<StateConfigValue<Cfg>>
A type alias to make it easier to define setter methods on your node class
Example
const fooState = createState("foo", { parse: ... });
class MyClass extends TextNode {
// ...
setFoo(valueOrUpdater: StateValueOrUpdater<typeof fooState>): this {
return $setState(this, fooState, valueOrUpdater);
}
}
Type parameters
| Name | Type |
|---|---|
Cfg | extends AnyStateConfig |
Defined in
packages/lexical/src/LexicalNodeState.ts:63
StaticNodeConfig
Ƭ StaticNodeConfig<T, Type>: BaseStaticNodeConfig & { readonly [K in Type]?: StaticNodeConfigValue<T, Type> }
Used to extract the node and type from a StaticNodeConfigRecord
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
Type | extends string |
Defined in
packages/lexical/src/LexicalNode.ts:176
TextFormatType
Ƭ TextFormatType: "bold" | "underline" | "strikethrough" | "italic" | "highlight" | "code" | "subscript" | "superscript" | "lowercase" | "uppercase" | "capitalize"
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:89
TextModeType
Ƭ TextModeType: "normal" | "token" | "segmented"
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:102
TextPoint
Ƭ TextPoint: Object
Type declaration
| Name | Type |
|---|---|
_selection | BaseSelection |
getNode | () => TextNode |
is | (point: PointType) => boolean |
isBefore | (point: PointType) => boolean |
key | NodeKey |
offset | number |
set | (key: NodeKey, offset: number, type: "text" | "element", onlyIfChanged?: boolean) => void |
type | "text" |
Defined in
packages/lexical/src/LexicalSelection.ts:95
TextPointCaretSliceTuple
Ƭ TextPointCaretSliceTuple<D>: readonly [anchorSlice: null | TextPointCaretSlice<TextNode, D>, focusSlice: null | TextPointCaretSlice<TextNode, D>]
A utility type to specify that a CaretRange may have zero, one, or two associated TextPointCaretSlice. If the anchor and focus are on the same node, the anchorSlice will contain the slice and focusSlie will be null.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Defined in
packages/lexical/src/caret/LexicalCaret.ts:371
Transform
Ƭ Transform<T>: (node: T) => void
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
Type declaration
▸ (node): void
Parameters
| Name | Type |
|---|---|
node | T |
Returns
void
Defined in
packages/lexical/src/LexicalEditor.ts:243
UpdateListener
Ƭ UpdateListener: (payload: UpdateListenerPayload) => void
A listener that gets called after the editor is updated
Type declaration
▸ (payload): void
Parameters
| Name | Type |
|---|---|
payload | UpdateListenerPayload |
Returns
void
Defined in
packages/lexical/src/LexicalEditor.ts:321
UpdateTag
Ƭ UpdateTag: typeof COLLABORATION_TAG | typeof FOCUS_TAG | typeof HISTORIC_TAG | typeof HISTORY_MERGE_TAG | typeof HISTORY_PUSH_TAG | typeof PASTE_TAG | typeof SKIP_COLLAB_TAG | typeof SKIP_DOM_SELECTION_TAG | typeof SKIP_SCROLL_INTO_VIEW_TAG | string &
The set of known update tags to help with TypeScript suggestions.
Defined in
packages/lexical/src/LexicalUpdateTags.ts:63
ValueOrUpdater
Ƭ ValueOrUpdater<V>: V | (prevValue: V) => V
A value type, or an updater for that value type. For use with $setState or any user-defined wrappers around it.
Type parameters
| Name |
|---|
V |
Defined in
packages/lexical/src/LexicalNodeState.ts:47
Variables
BLUR_COMMAND
• Const BLUR_COMMAND: LexicalCommand<FocusEvent>
Defined in
packages/lexical/src/LexicalCommands.ts:212
CAN_REDO_COMMAND
• Const CAN_REDO_COMMAND: LexicalCommand<boolean>
Defined in
packages/lexical/src/LexicalCommands.ts:206
CAN_UNDO_COMMAND
• Const CAN_UNDO_COMMAND: LexicalCommand<boolean>
Defined in
packages/lexical/src/LexicalCommands.ts:208
CLEAR_EDITOR_COMMAND
• Const CLEAR_EDITOR_COMMAND: LexicalCommand<void>
Defined in
packages/lexical/src/LexicalCommands.ts:200
CLEAR_HISTORY_COMMAND
• Const CLEAR_HISTORY_COMMAND: LexicalCommand<void>
Defined in
packages/lexical/src/LexicalCommands.ts:203
CLICK_COMMAND
• Const CLICK_COMMAND: LexicalCommand<MouseEvent>
Defined in
packages/lexical/src/LexicalCommands.ts:28
COLLABORATION_TAG
• Const COLLABORATION_TAG: "collaboration"
Indicates that the update is related to collaborative editing
Defined in
packages/lexical/src/LexicalUpdateTags.ts:37
COMMAND_PRIORITY_CRITICAL
• Const COMMAND_PRIORITY_CRITICAL: 4
Defined in
packages/lexical/src/LexicalEditor.ts:353
COMMAND_PRIORITY_EDITOR
• Const COMMAND_PRIORITY_EDITOR: 0
Defined in
packages/lexical/src/LexicalEditor.ts:349
COMMAND_PRIORITY_HIGH
• Const COMMAND_PRIORITY_HIGH: 3
Defined in
packages/lexical/src/LexicalEditor.ts:352
COMMAND_PRIORITY_LOW
• Const COMMAND_PRIORITY_LOW: 1
Defined in
packages/lexical/src/LexicalEditor.ts:350
COMMAND_PRIORITY_NORMAL
• Const COMMAND_PRIORITY_NORMAL: 2
Defined in
packages/lexical/src/LexicalEditor.ts:351
CONTROLLED_TEXT_INSERTION_COMMAND
• Const CONTROLLED_TEXT_INSERTION_COMMAND: LexicalCommand<InputEvent | string>
Defined in
packages/lexical/src/LexicalCommands.ts:49
COPY_COMMAND
• Const COPY_COMMAND: LexicalCommand<ClipboardEvent | KeyboardEvent | null>
Dispatched on a copy event, either via the clipboard or a KeyboardEvent (Cmd+C on macOS, Ctrl+C elsewhere).
Defined in
packages/lexical/src/LexicalCommands.ts:184
CUT_COMMAND
• Const CUT_COMMAND: LexicalCommand<ClipboardEvent | KeyboardEvent | null>
Dispatched on a cut event, either via the clipboard or a KeyboardEvent (Cmd+X on macOS, Ctrl+X elsewhere).
Defined in
packages/lexical/src/LexicalCommands.ts:191
DELETE_CHARACTER_COMMAND
• Const DELETE_CHARACTER_COMMAND: LexicalCommand<boolean>
Dispatched to delete a character, the payload will be true if the deletion
is backwards (backspace or delete on macOS) and false if forwards
(delete or Fn+Delete on macOS).
Defined in
packages/lexical/src/LexicalCommands.ts:35
DELETE_LINE_COMMAND
• Const DELETE_LINE_COMMAND: LexicalCommand<boolean>
Dispatched to delete a line, the payload will be true if the deletion is
backwards (Cmd+Delete on macOS), and false if forwards
(Fn+Cmd+Delete on macOS).
Defined in
packages/lexical/src/LexicalCommands.ts:69
DELETE_WORD_COMMAND
• Const DELETE_WORD_COMMAND: LexicalCommand<boolean>
Dispatched to delete a word, the payload will be true if the deletion is
backwards (Ctrl+Backspace or Opt+Delete on macOS), and false if
forwards (Ctrl+Delete or Fn+Opt+Delete on macOS).
Defined in
packages/lexical/src/LexicalCommands.ts:61
DRAGEND_COMMAND
• Const DRAGEND_COMMAND: LexicalCommand<DragEvent>
Defined in
packages/lexical/src/LexicalCommands.ts:178
DRAGOVER_COMMAND
• Const DRAGOVER_COMMAND: LexicalCommand<DragEvent>
Defined in
packages/lexical/src/LexicalCommands.ts:176
DRAGSTART_COMMAND
• Const DRAGSTART_COMMAND: LexicalCommand<DragEvent>
Defined in
packages/lexical/src/LexicalCommands.ts:174
DROP_COMMAND
• Const DROP_COMMAND: LexicalCommand<DragEvent>
Defined in
packages/lexical/src/LexicalCommands.ts:170
FOCUS_COMMAND
• Const FOCUS_COMMAND: LexicalCommand<FocusEvent>
Defined in
packages/lexical/src/LexicalCommands.ts:210
FORMAT_ELEMENT_COMMAND
• Const FORMAT_ELEMENT_COMMAND: LexicalCommand<ElementFormatType>
Defined in
packages/lexical/src/LexicalCommands.ts:172
FORMAT_TEXT_COMMAND
• Const FORMAT_TEXT_COMMAND: LexicalCommand<TextFormatType>
Dispatched to format the selected text.
Defined in
packages/lexical/src/LexicalCommands.ts:75
HISTORIC_TAG
• Const HISTORIC_TAG: "historic"
Indicates that the update is related to history operations (undo/redo)
Defined in
packages/lexical/src/LexicalUpdateTags.ts:17
HISTORY_MERGE_TAG
• Const HISTORY_MERGE_TAG: "history-merge"
Indicates that the current update should be merged with the previous history entry
Defined in
packages/lexical/src/LexicalUpdateTags.ts:27
HISTORY_PUSH_TAG
• Const HISTORY_PUSH_TAG: "history-push"
Indicates that a new history entry should be pushed to the history stack
Defined in
packages/lexical/src/LexicalUpdateTags.ts:22
INDENT_CONTENT_COMMAND
• Const INDENT_CONTENT_COMMAND: LexicalCommand<void>
Defined in
packages/lexical/src/LexicalCommands.ts:164
INSERT_LINE_BREAK_COMMAND
• Const INSERT_LINE_BREAK_COMMAND: LexicalCommand<boolean>
Dispatched to insert a line break. With a false payload the cursor moves to the new line (Shift+Enter), with a true payload the cursor does not move (Ctrl+O on macOS).
Defined in
packages/lexical/src/LexicalCommands.ts:43
INSERT_PARAGRAPH_COMMAND
• Const INSERT_PARAGRAPH_COMMAND: LexicalCommand<void>
Defined in
packages/lexical/src/LexicalCommands.ts:46
INSERT_TAB_COMMAND
• Const INSERT_TAB_COMMAND: LexicalCommand<void>
Defined in
packages/lexical/src/LexicalCommands.ts:162
IS_ALL_FORMATTING
• Const IS_ALL_FORMATTING: number
Defined in
packages/lexical/src/LexicalConstants.ts:53
IS_BOLD
• Const IS_BOLD: 1
Defined in
packages/lexical/src/LexicalConstants.ts:41
IS_CODE
• Const IS_CODE: number
Defined in
packages/lexical/src/LexicalConstants.ts:45
IS_HIGHLIGHT
• Const IS_HIGHLIGHT: number
Defined in
packages/lexical/src/LexicalConstants.ts:48
IS_ITALIC
• Const IS_ITALIC: number
Defined in
packages/lexical/src/LexicalConstants.ts:42
IS_STRIKETHROUGH
• Const IS_STRIKETHROUGH: number
Defined in
packages/lexical/src/LexicalConstants.ts:43
IS_SUBSCRIPT
• Const IS_SUBSCRIPT: number
Defined in
packages/lexical/src/LexicalConstants.ts:46
IS_SUPERSCRIPT
• Const IS_SUPERSCRIPT: number
Defined in
packages/lexical/src/LexicalConstants.ts:47
IS_UNDERLINE
• Const IS_UNDERLINE: number
Defined in
packages/lexical/src/LexicalConstants.ts:44
KEY_ARROW_DOWN_COMMAND
• Const KEY_ARROW_DOWN_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched when the 'ArrowUp' key is pressed.
The shift and/or alt (option) modifier keys may also be down.
Defined in
packages/lexical/src/LexicalCommands.ts:124
KEY_ARROW_LEFT_COMMAND
• Const KEY_ARROW_LEFT_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched when the 'ArrowLeft' key is pressed.
The shift modifier key may also be down.
Defined in
packages/lexical/src/LexicalCommands.ts:106
KEY_ARROW_RIGHT_COMMAND
• Const KEY_ARROW_RIGHT_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched when the 'ArrowRight' key is pressed.
The shift modifier key may also be down.
Defined in
packages/lexical/src/LexicalCommands.ts:94
KEY_ARROW_UP_COMMAND
• Const KEY_ARROW_UP_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched when the 'ArrowUp' key is pressed.
The shift and/or alt (option) modifier keys may also be down.
Defined in
packages/lexical/src/LexicalCommands.ts:118
KEY_BACKSPACE_COMMAND
• Const KEY_BACKSPACE_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched whenever the 'Backspace' key is pressed, the shift
modifier key may be down.
Defined in
packages/lexical/src/LexicalCommands.ts:143
KEY_DELETE_COMMAND
• Const KEY_DELETE_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched whenever the 'Delete' key is pressed (Fn+Delete on macOS).
Defined in
packages/lexical/src/LexicalCommands.ts:154
KEY_DOWN_COMMAND
• Const KEY_DOWN_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched when any key is pressed.
Defined in
packages/lexical/src/LexicalCommands.ts:88
KEY_ENTER_COMMAND
• Const KEY_ENTER_COMMAND: LexicalCommand<KeyboardEvent | null>
Dispatched when the enter key is pressed, may also be called with a null payload when the intent is to insert a newline. The shift modifier key must be down, any other modifier keys may also be down.
Defined in
packages/lexical/src/LexicalCommands.ts:131
KEY_ESCAPE_COMMAND
• Const KEY_ESCAPE_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched whenever the 'Escape' key is pressed, any modifier
keys may be down.
Defined in
packages/lexical/src/LexicalCommands.ts:149
KEY_MODIFIER_COMMAND
• Const KEY_MODIFIER_COMMAND: LexicalCommand<KeyboardEvent>
Deprecated
in v0.31.0, use KEY_DOWN_COMMAND and check for modifiers directly.
Dispatched after any KeyboardEvent when modifiers are pressed
Defined in
packages/lexical/src/LexicalCommands.ts:220
KEY_SPACE_COMMAND
• Const KEY_SPACE_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched whenever the space (' ') key is pressed, any modifier
keys may be down.
Defined in
packages/lexical/src/LexicalCommands.ts:137
KEY_TAB_COMMAND
• Const KEY_TAB_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched whenever the 'Tab' key is pressed. The shift modifier key
may be down.
Defined in
packages/lexical/src/LexicalCommands.ts:160
MOVE_TO_END
• Const MOVE_TO_END: LexicalCommand<KeyboardEvent>
Dispatched when the move to end keyboard shortcut is pressed, (Cmd+Right on macOS; Ctrl+Right elsewhere).
Defined in
packages/lexical/src/LexicalCommands.ts:100
MOVE_TO_START
• Const MOVE_TO_START: LexicalCommand<KeyboardEvent>
Dispatched when the move to start keyboard shortcut is pressed, (Cmd+Left on macOS; Ctrl+Left elsewhere).
Defined in
packages/lexical/src/LexicalCommands.ts:112
NODE_STATE_KEY
• Const NODE_STATE_KEY: "$"
Defined in
packages/lexical/src/LexicalConstants.ts:158
OUTDENT_CONTENT_COMMAND
• Const OUTDENT_CONTENT_COMMAND: LexicalCommand<void>
Defined in
packages/lexical/src/LexicalCommands.ts:167
PASTE_COMMAND
• Const PASTE_COMMAND: LexicalCommand<PasteCommandType>
Defined in
packages/lexical/src/LexicalCommands.ts:52
PASTE_TAG
• Const PASTE_TAG: "paste"
Indicates that the update is related to a paste operation
Defined in
packages/lexical/src/LexicalUpdateTags.ts:32
REDO_COMMAND
• Const REDO_COMMAND: LexicalCommand<void>
Dispatched on redo (Shift+Cmd+Z on macOS, Shift+Ctrl+Z or Ctrl+Y elsewhere).
Defined in
packages/lexical/src/LexicalCommands.ts:84
REMOVE_TEXT_COMMAND
• Const REMOVE_TEXT_COMMAND: LexicalCommand<InputEvent | null>
Defined in
packages/lexical/src/LexicalCommands.ts:54
SELECTION_CHANGE_COMMAND
• Const SELECTION_CHANGE_COMMAND: LexicalCommand<void>
Defined in
packages/lexical/src/LexicalCommands.ts:21
SELECTION_INSERT_CLIPBOARD_NODES_COMMAND
• Const SELECTION_INSERT_CLIPBOARD_NODES_COMMAND: LexicalCommand<{ nodes: LexicalNode[] ; selection: BaseSelection }>
Defined in
packages/lexical/src/LexicalCommands.ts:24
SELECT_ALL_COMMAND
• Const SELECT_ALL_COMMAND: LexicalCommand<KeyboardEvent>
Dispatched on the select all keyboard shortcut (Cmd+A on macOS, Ctrl+A elsehwere).
Defined in
packages/lexical/src/LexicalCommands.ts:198
SKIP_COLLAB_TAG
• Const SKIP_COLLAB_TAG: "skip-collab"
Indicates that the update should skip collaborative sync
Defined in
packages/lexical/src/LexicalUpdateTags.ts:42
SKIP_DOM_SELECTION_TAG
• Const SKIP_DOM_SELECTION_TAG: "skip-dom-selection"
Indicates that the update should skip updating the DOM selection This is useful when you want to make updates without changing the selection or focus
Defined in
packages/lexical/src/LexicalUpdateTags.ts:53
SKIP_SCROLL_INTO_VIEW_TAG
• Const SKIP_SCROLL_INTO_VIEW_TAG: "skip-scroll-into-view"
Indicates that the update should skip scrolling the selection into view
Defined in
packages/lexical/src/LexicalUpdateTags.ts:47
TEXT_TYPE_TO_FORMAT
• Const TEXT_TYPE_TO_FORMAT: Record<TextFormatType | string, number>
Defined in
packages/lexical/src/LexicalConstants.ts:106
UNDO_COMMAND
• Const UNDO_COMMAND: LexicalCommand<void>
Dispatched on undo (Cmd+Z on macOS, Ctrl+Z elsewhere).
Defined in
packages/lexical/src/LexicalCommands.ts:80
Functions
$addUpdateTag
▸ $addUpdateTag(tag): void
Parameters
| Name | Type |
|---|---|
tag | UpdateTag |
Returns
void
Defined in
packages/lexical/src/LexicalUtils.ts:1394
$applyNodeReplacement
▸ $applyNodeReplacement<N>(node): N
Type parameters
| Name | Type |
|---|---|
N | extends LexicalNode |
Parameters
| Name | Type |
|---|---|
node | N |
Returns
N
Defined in
packages/lexical/src/LexicalUtils.ts:1509
$caretFromPoint
▸ $caretFromPoint<D>(point, direction): PointCaret<D>
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
point | Pick<PointType, "type" | "key" | "offset"> |
direction | D |
Returns
PointCaret<D>
a PointCaret for the point
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:61
$caretRangeFromSelection
▸ $caretRangeFromSelection(selection): CaretRange
Get a pair of carets for a RangeSelection.
If the focus is before the anchor, then the direction will be 'previous', otherwise the direction will be 'next'.
Parameters
| Name | Type |
|---|---|
selection | RangeSelection |
Returns
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:156
$cloneWithProperties
▸ $cloneWithProperties<T>(latestNode): T
Returns a clone of a node using node.constructor.clone() followed by
clone.afterCloneFrom(node). The resulting clone must have the same key,
parent/next/prev pointers, and other properties that are not set by
node.constructor.clone (format, style, etc.). This is primarily used by
LexicalNode.getWritable to create a writable version of an
existing node. The clone is the same logical node as the original node,
do not try and use this function to duplicate or copy an existing node.
Does not mutate the EditorState.
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
Parameters
| Name | Type | Description |
|---|---|---|
latestNode | T | The node to be cloned. |
Returns
T
The clone of the node.
Defined in
packages/lexical/src/LexicalUtils.ts:1947
$comparePointCaretNext
▸ $comparePointCaretNext(a, b): -1 | 0 | 1
A total ordering for PointCaret<'next'>, based on
the same order that a CaretRange would iterate
them.
For a given origin node:
- ChildCaret comes before SiblingCaret
- TextPointCaret comes before SiblingCaret
An exception is thrown when a and b do not have any common ancestor.
This ordering is a sort of mix of pre-order and post-order because each ElementNode will show up as a ChildCaret on 'enter' (pre-order) and a SiblingCaret on 'leave' (post-order).
Parameters
| Name | Type |
|---|---|
a | PointCaret<"next"> |
b | PointCaret<"next"> |
Returns
-1 | 0 | 1
-1 if a comes before b, 0 if a and b are the same, or 1 if a comes after b
Defined in
packages/lexical/src/caret/LexicalCaret.ts:1227
$copyNode
▸ $copyNode<T>(node): T
Returns a shallow clone of node with a new key. All properties of the node
will be copied to the new node (by clone and then afterCloneFrom),
except those related to parent/sibling/child
relationships in the EditorState. This means that the copy must be
separately added to the document, and it will not have any children.
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
Parameters
| Name | Type | Description |
|---|---|---|
node | T | The node to be copied. |
Returns
T
The copy of the node.
Defined in
packages/lexical/src/LexicalUtils.ts:1502
$create
▸ $create<T>(klass): T
Create an node from its class.
Note that this will directly construct the final withKlass node type,
and will ignore the deprecated with functions. This allows $create to
skip any intermediate steps where the replaced node would be created and
then immediately discarded (once per configured replacement of that node).
This does not support any arguments to the constructor. Setters can be used to initialize your node, and they can be chained. You can of course write your own mutliple-argument functions to wrap that.
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
Parameters
| Name | Type |
|---|---|
klass | Klass<T> |
Returns
T
Example
function $createTokenText(text: string): TextNode {
return $create(TextNode).setTextContent(text).setMode('token');
}
Defined in
packages/lexical/src/LexicalUtils.ts:2105
$createLineBreakNode
▸ $createLineBreakNode(): LineBreakNode
Returns
Defined in
packages/lexical/src/nodes/LexicalLineBreakNode.ts:82
$createNodeSelection
▸ $createNodeSelection(): NodeSelection
Returns
Defined in
packages/lexical/src/LexicalSelection.ts:2549
$createParagraphNode
▸ $createParagraphNode(): ParagraphNode
Returns
Defined in
packages/lexical/src/nodes/LexicalParagraphNode.ts:167
$createPoint
▸ $createPoint(key, offset, type): PointType
Parameters
| Name | Type |
|---|---|
key | string |
offset | number |
type | "text" | "element" |
Returns
Defined in
packages/lexical/src/LexicalSelection.ts:217
$createRangeSelection
▸ $createRangeSelection(): RangeSelection
Returns
Defined in
packages/lexical/src/LexicalSelection.ts:2543
$createRangeSelectionFromDom
▸ $createRangeSelectionFromDom(domSelection, editor): null | RangeSelection
Parameters
| Name | Type |
|---|---|
domSelection | null | Selection |
editor | LexicalEditor |
Returns
null | RangeSelection
Defined in
packages/lexical/src/LexicalSelection.ts:2572
$createTabNode
▸ $createTabNode(): TabNode
Returns
Defined in
packages/lexical/src/nodes/LexicalTabNode.ts:101
$createTextNode
▸ $createTextNode(text?): TextNode
Parameters
| Name | Type | Default value |
|---|---|---|
text | string | '' |
Returns
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:1371
$extendCaretToRange
▸ $extendCaretToRange<D>(anchor): CaretRange<D>
Construct a CaretRange that starts at anchor and goes to the end of the document in the anchor caret's direction.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
anchor | PointCaret<D> |
Returns
CaretRange<D>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:1125
$getAdjacentChildCaret
▸ $getAdjacentChildCaret<D>(caret): null | NodeCaret<D>
Gets the adjacent caret, if not-null and if the origin of the adjacent caret is an ElementNode, then return the ChildCaret. This can be used along with the getParentAdjacentCaret method to perform a full DFS style traversal of the tree.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
caret | null | NodeCaret<D> | The caret to start at |
Returns
null | NodeCaret<D>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:975
$getAdjacentNode
▸ $getAdjacentNode(focus, isBackward): null | LexicalNode
Parameters
| Name | Type |
|---|---|
focus | PointType |
isBackward | boolean |
Returns
null | LexicalNode
Defined in
packages/lexical/src/LexicalUtils.ts:1248
$getAdjacentSiblingOrParentSiblingCaret
▸ $getAdjacentSiblingOrParentSiblingCaret<D>(startCaret, rootMode?): null | [NodeCaret<D>, number]
Returns the Node sibling when this exists, otherwise the closest parent sibling. For example R -> P -> T1, T2 -> P2 returns T2 for node T1, P2 for node T2, and null for node P2.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
startCaret | NodeCaret<D> | undefined | The initial caret |
rootMode | RootMode | 'root' | The root mode, 'root' ('default') or 'shadowRoot' |
Returns
null | [NodeCaret<D>, number]
An array (tuple) containing the found caret and the depth difference, or null, if this node doesn't exist.
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:596
$getCaretInDirection
▸ $getCaretInDirection<Caret, D>(caret, direction): NodeCaret<D> | Caret extends TextPointCaret<TextNode, CaretDirection> ? TextPointCaret<TextNode, D> : never
Return the caret if it's in the given direction, otherwise return caret.getFlipped().
Type parameters
| Name | Type |
|---|---|
Caret | extends PointCaret<CaretDirection> |
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
caret | Caret | Any PointCaret |
direction | D | The desired direction |
Returns
NodeCaret<D> | Caret extends TextPointCaret<TextNode, CaretDirection> ? TextPointCaret<TextNode, D> : never
A PointCaret in direction
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:519
$getCaretRange
▸ $getCaretRange<D>(anchor, focus): CaretRange<D>
Construct a CaretRange from anchor and focus carets pointing in the same direction. In order to get the expected behavior, the anchor must point towards the focus or be the same point.
In the 'next' direction the anchor should be at or before the focus in the document. In the 'previous' direction the anchor should be at or after the focus in the document (similar to a backwards RangeSelection).
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
anchor | PointCaret<D> |
focus | PointCaret<D> |
Returns
CaretRange<D>
a CaretRange
Defined in
packages/lexical/src/caret/LexicalCaret.ts:1154
$getCaretRangeInDirection
▸ $getCaretRangeInDirection<D>(range, direction): CaretRange<D>
Return the range if it's in the given direction, otherwise construct a new range using a flipped focus as the anchor and a flipped anchor as the focus. This transformation preserves the section of the document that it's working with, but reverses the order of iteration.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
range | CaretRange<CaretDirection> | Any CaretRange |
direction | D | The desired direction |
Returns
CaretRange<D>
A CaretRange in direction
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:548
$getCharacterOffsets
▸ $getCharacterOffsets(selection): [number, number]
Parameters
| Name | Type |
|---|---|
selection | BaseSelection |
Returns
[number, number]
Defined in
packages/lexical/src/LexicalSelection.ts:1952
$getChildCaret
▸ $getChildCaret<T, D>(origin, direction): ChildCaret<T, D>
Get a caret that points at the first or last child of the given origin node, which must be an ElementNode.
Type parameters
| Name | Type |
|---|---|
T | extends ElementNode |
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
origin | T | The origin ElementNode |
direction | D | 'next' for first child or 'previous' for last child |
Returns
ChildCaret<T, D>
null if origin is null or not an ElementNode, otherwise a ChildCaret for this origin and direction
Defined in
packages/lexical/src/caret/LexicalCaret.ts:948
$getChildCaretAtIndex
▸ $getChildCaretAtIndex<D>(parent, index, direction): NodeCaret<D>
Get a caret pointing at the child at the given index, or the last caret in that node if out of bounds.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
parent | ElementNode | An ElementNode |
index | number | The index of the origin for the caret |
direction | D | - |
Returns
NodeCaret<D>
A caret pointing towards the node at that index
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:570
$getChildCaretOrSelf
▸ $getChildCaretOrSelf<Caret>(caret): Caret | ChildCaret<ElementNode, NonNullable<Caret>["direction"]>
Gets the ChildCaret if one is possible at this caret origin, otherwise return the caret
Type parameters
| Name | Type |
|---|---|
Caret | extends null | PointCaret<CaretDirection> |
Parameters
| Name | Type |
|---|---|
caret | Caret |
Returns
Caret | ChildCaret<ElementNode, NonNullable<Caret>["direction"]>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:962
$getCollapsedCaretRange
▸ $getCollapsedCaretRange<D>(anchor): CaretRange<D>
Construct a collapsed CaretRange that starts and ends at anchor.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
anchor | PointCaret<D> |
Returns
CaretRange<D>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:1134
$getCommonAncestor
▸ $getCommonAncestor<A, B>(a, b): null | CommonAncestorResult<A, B>
Find a common ancestor of a and b and return a detailed result object, or null if there is no common ancestor between the two nodes.
The result object will have a commonAncestor property, and the other properties can be used to quickly compare these positions in the tree.
Type parameters
| Name | Type |
|---|---|
A | extends LexicalNode |
B | extends LexicalNode |
Parameters
| Name | Type | Description |
|---|---|---|
a | A | A LexicalNode |
b | B | A LexicalNode |
Returns
null | CommonAncestorResult<A, B>
A comparison result between the two nodes or null if they have no common ancestor
Defined in
packages/lexical/src/caret/LexicalCaret.ts:1365
$getCommonAncestorResultBranchOrder
▸ $getCommonAncestorResultBranchOrder<A, B>(compare): -1 | 1
Return the ordering of siblings in a CommonAncestorResultBranch
Type parameters
| Name | Type |
|---|---|
A | extends LexicalNode |
B | extends LexicalNode |
Parameters
| Name | Type |
|---|---|
compare | CommonAncestorResultBranch<A, B> |
Returns
-1 | 1
Defined in
packages/lexical/src/caret/LexicalCaret.ts:1270
$getEditor
▸ $getEditor(): LexicalEditor
Utility function for accessing current active editor instance.
Returns
Current active editor
Defined in
packages/lexical/src/LexicalUtils.ts:1884
$getNearestNodeFromDOMNode
▸ $getNearestNodeFromDOMNode(startingDOM, editorState?): LexicalNode | null
Parameters
| Name | Type |
|---|---|
startingDOM | Node |
editorState? | EditorState |
Returns
LexicalNode | null
Defined in
packages/lexical/src/LexicalUtils.ts:546
$getNearestRootOrShadowRoot
▸ $getNearestRootOrShadowRoot(node): RootNode | ElementNode
Parameters
| Name | Type |
|---|---|
node | LexicalNode |
Returns
Defined in
packages/lexical/src/LexicalUtils.ts:1466
$getNodeByKey
▸ $getNodeByKey<T>(key, _editorState?): T | null
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
Parameters
| Name | Type |
|---|---|
key | string |
_editorState? | EditorState |
Returns
T | null
Defined in
packages/lexical/src/LexicalUtils.ts:505
$getNodeByKeyOrThrow
▸ $getNodeByKeyOrThrow<N>(key): N
Type parameters
| Name | Type |
|---|---|
N | extends LexicalNode |
Parameters
| Name | Type |
|---|---|
key | string |
Returns
N
Defined in
packages/lexical/src/LexicalUtils.ts:1575
$getPreviousSelection
▸ $getPreviousSelection(): null | BaseSelection
Returns
null | BaseSelection
Defined in
packages/lexical/src/LexicalSelection.ts:2709
$getRoot
▸ $getRoot(): RootNode
Returns
Defined in
packages/lexical/src/LexicalUtils.ts:614
$getSelection
▸ $getSelection(): null | BaseSelection
Returns
null | BaseSelection
Defined in
packages/lexical/src/LexicalSelection.ts:2704
$getSiblingCaret
▸ $getSiblingCaret<T, D>(origin, direction): SiblingCaret<T, D>
Get a caret that points at the next or previous sibling of the given origin node.
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
origin | T | The origin node |
direction | D | 'next' or 'previous' |
Returns
SiblingCaret<T, D>
null if origin is null, otherwise a SiblingCaret for this origin and direction
Defined in
packages/lexical/src/caret/LexicalCaret.ts:843
▸ $getSiblingCaret<T, D>(origin, direction): null | SiblingCaret<T, D>
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
origin | null | T |
direction | D |
Returns
null | SiblingCaret<T, D>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:847
$getState
▸ $getState<K, V>(node, stateConfig, version?): V
The accessor for working with node state. This will read the value for the
state on the given node, and will return stateConfig.defaultValue if the
state has never been set on this node.
The version parameter is optional and should generally be 'latest',
consistent with the behavior of other node methods and functions,
but for certain use cases such as updateDOM you may have a need to
use 'direct' to read the state from a previous version of the node.
For very advanced use cases, you can expect that 'direct' does not
require an editor state, just like directly accessing other properties
of a node without an accessor (e.g. textNode.__text).
Type parameters
| Name | Type |
|---|---|
K | extends string |
V | V |
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
node | LexicalNode | undefined | Any LexicalNode |
stateConfig | StateConfig<K, V> | undefined | The configuration of the state to read |
version | "latest" | "direct" | 'latest' | The default value 'latest' will read the latest version of the node state, 'direct' will read the version that is stored on this LexicalNode which not reflect the version used in the current editor state |
Returns
V
The current value from the state, or the default value provided by the configuration.
Defined in
packages/lexical/src/LexicalNodeState.ts:329
$getStateChange
▸ $getStateChange<T, K, V>(node, prevNode, stateConfig): null | [value: V, prevValue: V]
Given two versions of a node and a stateConfig, compare their state values
using $getState(nodeVersion, stateConfig, 'direct').
If the values are equal according to stateConfig.isEqual, return null,
otherwise return [value, prevValue].
This is useful for implementing updateDOM. Note that the 'direct'
version argument is used for both nodes.
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
K | extends string |
V | V |
Parameters
| Name | Type | Description |
|---|---|---|
node | T | Any LexicalNode |
prevNode | T | A previous version of node |
stateConfig | StateConfig<K, V> | The configuration of the state to read |
Returns
null | [value: V, prevValue: V]
[value, prevValue] if changed, otherwise null
Defined in
packages/lexical/src/LexicalNodeState.ts:357
$getTextContent
▸ $getTextContent(): string
Returns
string
Defined in
packages/lexical/src/LexicalSelection.ts:3106
$getTextNodeOffset
▸ $getTextNodeOffset(origin, offset): number
Get a normalized offset into a TextNode given a numeric offset or a direction for which end of the string to use. Throws in dev if the offset is not in the bounds of the text content size.
Parameters
| Name | Type | Description |
|---|---|---|
origin | TextNode | a TextNode |
offset | number | CaretDirection | An absolute offset into the TextNode string, or a direction for which end to use as the offset |
Returns
number
An absolute offset into the TextNode string
Defined in
packages/lexical/src/caret/LexicalCaret.ts:901
$getTextPointCaret
▸ $getTextPointCaret<T, D>(origin, direction, offset): TextPointCaret<T, D>
Construct a TextPointCaret
Type parameters
| Name | Type |
|---|---|
T | extends TextNode |
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
origin | T | The TextNode |
direction | D | The direction (next points to the end of the text, previous points to the beginning) |
offset | number | CaretDirection | The offset into the text in absolute positive string coordinates (0 is the start) |
Returns
TextPointCaret<T, D>
a TextPointCaret
Defined in
packages/lexical/src/caret/LexicalCaret.ts:866
▸ $getTextPointCaret<T, D>(origin, direction, offset): null | TextPointCaret<T, D>
Type parameters
| Name | Type |
|---|---|
T | extends TextNode |
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
origin | null | T |
direction | D |
offset | number | CaretDirection |
Returns
null | TextPointCaret<T, D>
Defined in
packages/lexical/src/caret/LexicalCaret.ts:874
$getTextPointCaretSlice
▸ $getTextPointCaretSlice<T, D>(caret, distance): TextPointCaretSlice<T, D>
Construct a TextPointCaretSlice given a TextPointCaret and a signed distance. The distance should be negative to slice text before the caret's offset, and positive to slice text after the offset. The direction of the caret itself is not relevant to the string coordinates when working with a TextPointCaretSlice but mutation operations will preserve the direction.
Type parameters
| Name | Type |
|---|---|
T | extends TextNode |
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
caret | TextPointCaret<T, D> |
distance | number |
Returns
TextPointCaretSlice<T, D>
TextPointCaretSlice
Defined in
packages/lexical/src/caret/LexicalCaret.ts:933
$hasAncestor
▸ $hasAncestor(child, targetNode): boolean
Parameters
| Name | Type |
|---|---|
child | LexicalNode |
targetNode | LexicalNode |
Returns
boolean
Defined in
packages/lexical/src/LexicalUtils.ts:1432
$hasUpdateTag
▸ $hasUpdateTag(tag): boolean
Parameters
| Name | Type |
|---|---|
tag | UpdateTag |
Returns
boolean
Defined in
packages/lexical/src/LexicalUtils.ts:1389
$insertNodes
▸ $insertNodes(nodes): void
Parameters
| Name | Type |
|---|---|
nodes | LexicalNode[] |
Returns
void
Defined in
packages/lexical/src/LexicalSelection.ts:3097
$isBlockElementNode
▸ $isBlockElementNode(node): node is ElementNode
Parameters
| Name | Type |
|---|---|
node | undefined | null | LexicalNode |
Returns
node is ElementNode
Defined in
packages/lexical/src/LexicalSelection.ts:2513
$isChildCaret
▸ $isChildCaret<D>(caret): caret is ChildCaret<ElementNode, D>
Guard to check if the given argument is specifically a ChildCaret
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
caret | undefined | null | PointCaret<D> |
Returns
caret is ChildCaret<ElementNode, D>
true if caret is a ChildCaret
Defined in
packages/lexical/src/caret/LexicalCaret.ts:759
$isDecoratorNode
▸ $isDecoratorNode<T>(node): node is DecoratorNode<T>
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
node | undefined | null | LexicalNode |
Returns
node is DecoratorNode<T>
Defined in
packages/lexical/src/nodes/LexicalDecoratorNode.ts:48
$isElementNode
▸ $isElementNode(node): node is ElementNode
Parameters
| Name | Type |
|---|---|
node | undefined | null | LexicalNode |
Returns
node is ElementNode
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:993
$isExtendableTextPointCaret
▸ $isExtendableTextPointCaret<D>(caret): caret is TextPointCaret<TextNode, D> & Object
Determine whether the TextPointCaret's offset can be extended further without leaving the TextNode. Returns false if the given caret is not a TextPointCaret or the offset can not be moved further in direction.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
caret | PointCaret<D> | A PointCaret |
Returns
caret is TextPointCaret<TextNode, D> & Object
true if caret is a TextPointCaret with an offset that is not at the end of the text given the direction.
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:500
$isInlineElementOrDecoratorNode
▸ $isInlineElementOrDecoratorNode(node): boolean
Parameters
| Name | Type |
|---|---|
node | LexicalNode |
Returns
boolean
Defined in
packages/lexical/src/LexicalUtils.ts:1459
$isLeafNode
▸ $isLeafNode(node): node is DecoratorNode<unknown> | TextNode | LineBreakNode
Parameters
| Name | Type |
|---|---|
node | undefined | null | LexicalNode |
Returns
node is DecoratorNode<unknown> | TextNode | LineBreakNode
Defined in
packages/lexical/src/LexicalUtils.ts:294
$isLineBreakNode
▸ $isLineBreakNode(node): node is LineBreakNode
Parameters
| Name | Type |
|---|---|
node | undefined | null | LexicalNode |
Returns
node is LineBreakNode
Defined in
packages/lexical/src/nodes/LexicalLineBreakNode.ts:86
$isNodeCaret
▸ $isNodeCaret<D>(caret): caret is PointCaret<D>
Guard to check if the given argument is any type of caret
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
caret | undefined | null | PointCaret<D> |
Returns
caret is PointCaret<D>
true if caret is any type of caret
Defined in
packages/lexical/src/caret/LexicalCaret.ts:735
$isNodeSelection
▸ $isNodeSelection(x): x is NodeSelection
Parameters
| Name | Type |
|---|---|
x | unknown |
Returns
x is NodeSelection
Defined in
packages/lexical/src/LexicalSelection.ts:1936
$isParagraphNode
▸ $isParagraphNode(node): node is ParagraphNode
Parameters
| Name | Type |
|---|---|
node | undefined | null | LexicalNode |
Returns
node is ParagraphNode
Defined in
packages/lexical/src/nodes/LexicalParagraphNode.ts:171
$isRangeSelection
▸ $isRangeSelection(x): x is RangeSelection
Parameters
| Name | Type |
|---|---|
x | unknown |
Returns
x is RangeSelection
Defined in
packages/lexical/src/LexicalSelection.ts:456
$isRootNode
▸ $isRootNode(node): node is RootNode
Parameters
| Name | Type |
|---|---|
node | undefined | null | LexicalNode | RootNode |
Returns
node is RootNode
Defined in
packages/lexical/src/nodes/LexicalRootNode.ts:113
$isRootOrShadowRoot
▸ $isRootOrShadowRoot(node): node is RootNode | ShadowRootNode
Parameters
| Name | Type |
|---|---|
node | null | LexicalNode |
Returns
node is RootNode | ShadowRootNode
Defined in
packages/lexical/src/LexicalUtils.ts:1486
$isSiblingCaret
▸ $isSiblingCaret<D>(caret): caret is SiblingCaret<LexicalNode, D>
Guard to check if the given argument is specifically a SiblingCaret (or TextPointCaret)
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
caret | undefined | null | PointCaret<D> |
Returns
caret is SiblingCaret<LexicalNode, D>
true if caret is a SiblingCaret
Defined in
packages/lexical/src/caret/LexicalCaret.ts:747
$isTabNode
▸ $isTabNode(node): node is TabNode
Parameters
| Name | Type |
|---|---|
node | undefined | null | LexicalNode |
Returns
node is TabNode
Defined in
packages/lexical/src/nodes/LexicalTabNode.ts:105
$isTextNode
▸ $isTextNode(node): node is TextNode
Parameters
| Name | Type |
|---|---|
node | undefined | null | LexicalNode |
Returns
node is TextNode
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:1375
$isTextPointCaret
▸ $isTextPointCaret<D>(caret): caret is TextPointCaret<TextNode, D>
Guard to check if the given caret is specifically a TextPointCaret
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
caret | undefined | null | PointCaret<D> | Any caret |
Returns
caret is TextPointCaret<TextNode, D>
true if it is a TextPointCaret
Defined in
packages/lexical/src/caret/LexicalCaret.ts:723
$isTextPointCaretSlice
▸ $isTextPointCaretSlice<D>(caretOrSlice): caretOrSlice is TextPointCaretSlice<TextNode, D>
Guard to check for a TextPointCaretSlice
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
caretOrSlice | undefined | null | PointCaret<D> | TextPointCaretSlice<TextNode, D> | A caret or slice |
Returns
caretOrSlice is TextPointCaretSlice<TextNode, D>
true if caretOrSlice is a TextPointCaretSlice
Defined in
packages/lexical/src/caret/LexicalCaret.ts:1111
$isTokenOrSegmented
▸ $isTokenOrSegmented(node): boolean
Return true if the TextNode is a TabNode, or is in token or segmented mode.
Parameters
| Name | Type |
|---|---|
node | TextNode |
Returns
boolean
Defined in
packages/lexical/src/LexicalUtils.ts:233
$isTokenOrTab
▸ $isTokenOrTab(node): boolean
Return true if the TextNode is a TabNode or is in token mode.
Parameters
| Name | Type |
|---|---|
node | TextNode |
Returns
boolean
Defined in
packages/lexical/src/LexicalUtils.ts:226
$nodesOfType
▸ $nodesOfType<T>(klass): T[]
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
Parameters
| Name | Type |
|---|---|
klass | Klass<T> |
Returns
T[]
Deprecated
Use LexicalEditor.registerMutationListener with skipInitialization: false instead.
Defined in
packages/lexical/src/LexicalUtils.ts:1205
$normalizeCaret
▸ $normalizeCaret<D>(initialCaret): PointCaret<D>
Normalize a caret to the deepest equivalent PointCaret. This will return a TextPointCaret with the offset set according to the direction if given a caret with a TextNode origin or a caret with an ElementNode origin with the deepest ChildCaret having an adjacent TextNode.
If given a TextPointCaret, it will be returned, as no normalization is required when an offset is already present.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type |
|---|---|
initialCaret | PointCaret<D> |
Returns
PointCaret<D>
The normalized PointCaret
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:475
$normalizeSelection__EXPERIMENTAL
▸ $normalizeSelection__EXPERIMENTAL(selection): RangeSelection
Parameters
| Name | Type |
|---|---|
selection | RangeSelection |
Returns
Defined in
packages/lexical/src/LexicalNormalization.ts:95
$onUpdate
▸ $onUpdate(updateFn): void
Add a function to run after the current update. This will run after any
onUpdate function already supplied to editor.update(), as well as any
functions added with previous calls to $onUpdate.
Parameters
| Name | Type | Description |
|---|---|---|
updateFn | () => void | The function to run after the current update. |
Returns
void
Defined in
packages/lexical/src/LexicalUtils.ts:1407
$parseSerializedNode
▸ $parseSerializedNode(serializedNode): LexicalNode
Parameters
| Name | Type |
|---|---|
serializedNode | SerializedLexicalNode |
Returns
Defined in
packages/lexical/src/LexicalUpdates.ts:356
$removeTextFromCaretRange
▸ $removeTextFromCaretRange<D>(initialRange, sliceMode?): CaretRange<D>
Remove all text and nodes in the given range. If the range spans multiple blocks then the remaining contents of the later block will be merged with the earlier block.
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
initialRange | CaretRange<D> | undefined | The range to remove text and nodes from |
sliceMode | "removeEmptySlices" | "preserveEmptyTextSliceCaret" | 'removeEmptySlices' | If 'preserveEmptyTextPointCaret' it will leave an empty TextPointCaret at the anchor for insert if one exists, otherwise empty slices will be removed |
Returns
CaretRange<D>
The new collapsed range (biased towards the earlier node)
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:232
$rewindSiblingCaret
▸ $rewindSiblingCaret<T, D>(caret): NodeCaret<D>
Given a SiblingCaret we can always compute a caret that points to the origin of that caret in the same direction. The adjacent caret of the returned caret will be equivalent to the given caret.
Type parameters
| Name | Type |
|---|---|
T | extends LexicalNode |
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
caret | SiblingCaret<T, D> | The caret to "rewind" |
Returns
NodeCaret<D>
A new caret (ChildCaret or SiblingCaret) with the same direction
Example
siblingCaret.is($rewindSiblingCaret(siblingCaret).getAdjacentCaret())
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:183
$selectAll
▸ $selectAll(selection?): RangeSelection
Parameters
| Name | Type |
|---|---|
selection? | null | RangeSelection |
Returns
Defined in
packages/lexical/src/LexicalUtils.ts:1123
$setCompositionKey
▸ $setCompositionKey(compositionKey): void
Parameters
| Name | Type |
|---|---|
compositionKey | null | string |
Returns
void
Defined in
packages/lexical/src/LexicalUtils.ts:476
$setPointFromCaret
▸ $setPointFromCaret<D>(point, caret): void
Update the given point in-place from the PointCaret
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
point | PointType | the point to set |
caret | PointCaret<D> | the caret to set the point from |
Returns
void
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:91
$setSelection
▸ $setSelection(selection): void
Parameters
| Name | Type |
|---|---|
selection | null | BaseSelection |
Returns
void
Defined in
packages/lexical/src/LexicalUtils.ts:622
$setSelectionFromCaretRange
▸ $setSelectionFromCaretRange(caretRange): RangeSelection
Set a RangeSelection on the editor from the given CaretRange
Parameters
| Name | Type |
|---|---|
caretRange | CaretRange<CaretDirection> |
Returns
The new RangeSelection
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:127
$setState
▸ $setState<Node, K, V>(node, stateConfig, valueOrUpdater): Node
Set the state defined by stateConfig on node. Like with React.useState
you may directly specify the value or use an updater function that will
be called with the previous value of the state on that node (which will
be the stateConfig.defaultValue if not set).
When an updater function is used, the node will only be marked dirty if
stateConfig.isEqual(prevValue, value) is false.
Type parameters
| Name | Type |
|---|---|
Node | extends LexicalNode |
K | extends string |
V | V |
Parameters
| Name | Type | Description |
|---|---|---|
node | Node | The LexicalNode to set the state on |
stateConfig | StateConfig<K, V> | The configuration for this state |
valueOrUpdater | ValueOrUpdater<V> | The value or updater function |
Returns
Node
node
Example
const toggle = createState('toggle', {parse: Boolean});
// set it direction
$setState(node, counterState, true);
// use an updater
$setState(node, counterState, (prev) => !prev);
Defined in
packages/lexical/src/LexicalNodeState.ts:390
$splitAtPointCaretNext
▸ $splitAtPointCaretNext(pointCaret, «destructured»?): null | NodeCaret<"next">
Split a node at a PointCaret and return a NodeCaret at that point, or null if the node can't be split. This is non-recursive and will only perform at most one split.
Parameters
| Name | Type |
|---|---|
pointCaret | PointCaret<"next"> |
«destructured» | SplitAtPointCaretNextOptions |
Returns
null | NodeCaret<"next">
The NodeCaret pointing to the location of the split (or null if a split is not possible)
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:689
$splitNode
▸ $splitNode(node, offset): [ElementNode | null, ElementNode]
Parameters
| Name | Type |
|---|---|
node | ElementNode |
offset | number |
Returns
[ElementNode | null, ElementNode]
Defined in
packages/lexical/src/LexicalUtils.ts:1708
$updateRangeSelectionFromCaretRange
▸ $updateRangeSelectionFromCaretRange(selection, caretRange): void
Update the points of a RangeSelection based on the given PointCaret.
Parameters
| Name | Type |
|---|---|
selection | RangeSelection |
caretRange | CaretRange<CaretDirection> |
Returns
void
Defined in
packages/lexical/src/caret/LexicalCaretUtils.ts:142
buildImportMap
▸ buildImportMap<K>(importMap): DOMConversionMap
An identity function that will infer the type of DOM nodes based on tag names to make it easier to construct a DOMConversionMap.
Type parameters
| Name | Type |
|---|---|
K | extends string |
Parameters
| Name | Type |
|---|---|
importMap | { [NodeName in string]: DOMConversionPropByTagName<NodeName> } |
Returns
Defined in
packages/lexical/src/LexicalNode.ts:335
createCommand
▸ createCommand<T>(type?): LexicalCommand<T>
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
type? | string |
Returns
Defined in
packages/lexical/src/LexicalCommands.ts:17
createEditor
▸ createEditor(editorConfig?): LexicalEditor
Creates a new LexicalEditor attached to a single contentEditable (provided in the config). This is the lowest-level initialization API for a LexicalEditor. If you're using React or another framework, consider using the appropriate abstractions, such as LexicalComposer
Parameters
| Name | Type | Description |
|---|---|---|
editorConfig? | CreateEditorArgs | the editor configuration. |
Returns
a LexicalEditor instance
Defined in
packages/lexical/src/LexicalEditor.ts:505
createState
▸ createState<K, V>(key, valueConfig): StateConfig<K, V>
Create a StateConfig for the given string key and StateValueConfig.
The key must be locally unique. In dev you will get a key collision error when you use two separate StateConfig on the same node with the same key.
The returned StateConfig value should be used with $getState and $setState.
Type parameters
| Name | Type |
|---|---|
K | extends string |
V | V |
Parameters
| Name | Type | Description |
|---|---|---|
key | K | The key to use |
valueConfig | StateValueConfig<V> | Configuration for the value type |
Returns
StateConfig<K, V>
a StateConfig
Defined in
packages/lexical/src/LexicalNodeState.ts:303
flipDirection
▸ flipDirection<D>(direction): FlipDirection<D>
Flip a direction ('next' -> 'previous'; 'previous' -> 'next').
Note that TypeScript can't prove that FlipDirection is its own inverse (but if you have a concrete 'next' or 'previous' it will simplify accordingly).
Type parameters
| Name | Type |
|---|---|
D | extends CaretDirection |
Parameters
| Name | Type | Description |
|---|---|---|
direction | D | A direction |
Returns
The opposite direction
Defined in
packages/lexical/src/caret/LexicalCaret.ts:580
getDOMOwnerDocument
▸ getDOMOwnerDocument(target): Document | null
Parameters
| Name | Type |
|---|---|
target | null | EventTarget |
Returns
Document | null
Defined in
packages/lexical/src/LexicalUtils.ts:1326
getDOMSelection
▸ getDOMSelection(targetWindow): null | Selection
Returns the selection for the given window, or the global window if null. Will return null if CAN_USE_DOM is false.
Parameters
| Name | Type | Description |
|---|---|---|
targetWindow | null | Window | The window to get the selection from |
Returns
null | Selection
a Selection or null
Defined in
packages/lexical/src/LexicalUtils.ts:1691
getDOMSelectionFromTarget
▸ getDOMSelectionFromTarget(eventTarget): null | Selection
Returns the selection for the defaultView of the ownerDocument of given EventTarget.
Parameters
| Name | Type | Description |
|---|---|---|
eventTarget | null | EventTarget | The node to get the selection from |
Returns
null | Selection
a Selection or null
Defined in
packages/lexical/src/LexicalUtils.ts:1701
getDOMTextNode
▸ getDOMTextNode(element): Text | null
Parameters
| Name | Type |
|---|---|
element | null | Node |
Returns
Text | null
Defined in
packages/lexical/src/LexicalUtils.ts:253
getNearestEditorFromDOMNode
▸ getNearestEditorFromDOMNode(node): LexicalEditor | null
Parameters
| Name | Type |
|---|---|
node | null | Node |
Returns
LexicalEditor | null
Defined in
packages/lexical/src/LexicalUtils.ts:193
isBlockDomNode
▸ isBlockDomNode(node): boolean
Parameters
| Name | Type | Description |
|---|---|---|
node | Node | the Dom Node to check |
Returns
boolean
if the Dom Node is a block node
Defined in
packages/lexical/src/LexicalUtils.ts:1828
isCurrentlyReadOnlyMode
▸ isCurrentlyReadOnlyMode(): boolean
Returns
boolean
Defined in
packages/lexical/src/LexicalUpdates.ts:79
isDOMDocumentNode
▸ isDOMDocumentNode(node): node is Document
Parameters
| Name | Type | Description |
|---|---|---|
node | unknown | The element being tested |
Returns
node is Document
Returns true if node is an DOM Document node, false otherwise.
Defined in
packages/lexical/src/LexicalUtils.ts:249
isDOMNode
▸ isDOMNode(x): x is Node
Parameters
| Name | Type | Description |
|---|---|---|
x | unknown | The element being tested |
Returns
x is Node
Returns true if x is a DOM Node, false otherwise.
Defined in
packages/lexical/src/LexicalUtils.ts:1793
isDOMTextNode
▸ isDOMTextNode(node): node is Text
Parameters
| Name | Type | Description |
|---|---|---|
node | unknown | The element being tested |
Returns
node is Text
Returns true if node is an DOM Text node, false otherwise.
Defined in
packages/lexical/src/LexicalUtils.ts:241
isDocumentFragment
▸ isDocumentFragment(x): x is DocumentFragment
Parameters
| Name | Type | Description |
|---|---|---|
x | unknown | The element being testing |
Returns
x is DocumentFragment
Returns true if x is a document fragment, false otherwise.
Defined in
packages/lexical/src/LexicalUtils.ts:1806
isExactShortcutMatch
▸ isExactShortcutMatch(event, expectedKey, mask): boolean
Match a KeyboardEvent with its expected state
Parameters
| Name | Type | Description |
|---|---|---|
event | KeyboardEventModifiers | A KeyboardEvent, or structurally similar object |
expectedKey | string | The string to compare with event.key (case insensitive) |
mask | KeyboardEventModifierMask | An object specifying the expected state of the modifiers |
Returns
boolean
true if the event matches
Defined in
packages/lexical/src/LexicalUtils.ts:946
isHTMLAnchorElement
▸ isHTMLAnchorElement(x): x is HTMLAnchorElement
Parameters
| Name | Type | Description |
|---|---|---|
x | unknown | The element being tested |
Returns
x is HTMLAnchorElement
Returns true if x is an HTML anchor tag, false otherwise
Defined in
packages/lexical/src/LexicalUtils.ts:1777
isHTMLElement
▸ isHTMLElement(x): x is HTMLElement
Parameters
| Name | Type | Description |
|---|---|---|
x | unknown | The element being tested |
Returns
x is HTMLElement
Returns true if x is an HTML element, false otherwise.
Defined in
packages/lexical/src/LexicalUtils.ts:1785
isInlineDomNode
▸ isInlineDomNode(node): boolean
Parameters
| Name | Type | Description |
|---|---|---|
node | Node | the Dom Node to check |
Returns
boolean
if the Dom Node is an inline node
Defined in
packages/lexical/src/LexicalUtils.ts:1815
isLexicalEditor
▸ isLexicalEditor(editor): editor is LexicalEditor
Parameters
| Name | Type |
|---|---|
editor | unknown |
Returns
editor is LexicalEditor
true if the given argument is a LexicalEditor instance from this build of Lexical
Defined in
packages/lexical/src/LexicalUtils.ts:188
isModifierMatch
▸ isModifierMatch(event, mask): boolean
Match a KeyboardEvent with its expected modifier state
Parameters
| Name | Type | Description |
|---|---|---|
event | KeyboardEventModifiers | A KeyboardEvent, or structurally similar object |
mask | KeyboardEventModifierMask | An object specifying the expected state of the modifiers |
Returns
boolean
true if the event matches
Defined in
packages/lexical/src/LexicalUtils.ts:926
isSelectionCapturedInDecoratorInput
▸ isSelectionCapturedInDecoratorInput(anchorDOM): boolean
Parameters
| Name | Type |
|---|---|
anchorDOM | Node |
Returns
boolean
Defined in
packages/lexical/src/LexicalUtils.ts:147
isSelectionWithinEditor
▸ isSelectionWithinEditor(editor, anchorDOM, focusDOM): boolean
Parameters
| Name | Type |
|---|---|
editor | LexicalEditor |
anchorDOM | null | Node |
focusDOM | null | Node |
Returns
boolean
Defined in
packages/lexical/src/LexicalUtils.ts:164
makeStepwiseIterator
▸ makeStepwiseIterator<State, Stop, Value>(config): IterableIterator<Value>
A generalized utility for creating a stepwise iterator based on:
- an initial state
- a stop guard that returns true if the iteration is over, this is typically used to detect a sentinel value such as null or undefined from the state but may return true for other conditions as well
- a step function that advances the state (this will be called after map each time next() is called to prepare the next state)
- a map function that will be called that may transform the state before returning it. It will only be called once for each next() call when stop(state) === false
Type parameters
| Name |
|---|
State |
Stop |
Value |
Parameters
| Name | Type |
|---|---|
config | StepwiseIteratorConfig<State, Stop, Value> |
Returns
IterableIterator<Value>
An IterableIterator
Defined in
packages/lexical/src/caret/LexicalCaret.ts:1183
resetRandomKey
▸ resetRandomKey(): void
Returns
void
Defined in
packages/lexical/src/LexicalUtils.ts:101
setNodeIndentFromDOM
▸ setNodeIndentFromDOM(elementDom, elementNode): void
Parameters
| Name | Type |
|---|---|
elementDom | HTMLElement |
elementNode | ElementNode |
Returns
void