Module: @lexical/selection
Functions
$addNodeStyle
▸ $addNodeStyle(node
): void
Gets the TextNode's style object and adds the styles to the CSS.
Parameters
Name | Type | Description |
---|---|---|
node | TextNode | The TextNode to add styles to. |
Returns
void
Defined in
lexical-selection/src/lexical-node.ts:287
$cloneWithProperties
▸ $cloneWithProperties<T
>(node
): T
Returns a copy of a node, but generates a new key for the copy.
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Parameters
Name | Type | Description |
---|---|---|
node | T | The node to be cloned. |
Returns
T
The clone of the node.
Defined in
lexical-selection/src/lexical-node.ts:68
$getSelectionStyleValueForProperty
▸ $getSelectionStyleValueForProperty(selection
, styleProperty
, defaultValue?
): string
Returns the current value of a CSS property for TextNodes in the Selection, if set. If not set, it returns the defaultValue. If all TextNodes do not have the same value, it returns an empty string.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
selection | RangeSelection | undefined | The selection of TextNodes whose value to find. |
styleProperty | string | undefined | The CSS style property. |
defaultValue | string | '' | The default value for the property, defaults to an empty string. |
Returns
string
The value of the property for the selected TextNodes.
Defined in
lexical-selection/src/range-selection.ts:514
$isAtNodeEnd
▸ $isAtNodeEnd(point
): boolean
Determines if the current selection is at the end of the node.
Parameters
Name | Type | Description |
---|---|---|
point | Point | The point of the selection to test. |
Returns
boolean
true if the provided point offset is in the last possible position, false otherwise.
Defined in
lexical-selection/src/lexical-node.ts:143
$isParentElementRTL
▸ $isParentElementRTL(selection
): boolean
Tests a parent element for right to left direction.
Parameters
Name | Type | Description |
---|---|---|
selection | RangeSelection | The selection whose parent is to be tested. |
Returns
boolean
true if the selections' parent element has a direction of 'rtl' (right to left), false otherwise.
Defined in
lexical-selection/src/range-selection.ts:420
$moveCaretSelection
▸ $moveCaretSelection(selection
, isHoldingShift
, isBackward
, granularity
): void
Moves the selection according to the arguments.
Parameters
Name | Type | Description |
---|---|---|
selection | RangeSelection | The selected text or nodes. |
isHoldingShift | boolean | Is the shift key being held down during the operation. |
isBackward | boolean | Is the selection selected backwards (the focus comes before the anchor)? |
granularity | "character" | "word" | "lineboundary" | The distance to adjust the current selection. |
Returns
void
Defined in
lexical-selection/src/range-selection.ts:406
$moveCharacter
▸ $moveCharacter(selection
, isHoldingShift
, isBackward
): void
Moves selection by character according to arguments.
Parameters
Name | Type | Description |
---|---|---|
selection | RangeSelection | The selection of the characters to move. |
isHoldingShift | boolean | Is the shift key being held down during the operation. |
isBackward | boolean | Is the selection backward (the focus comes before the anchor)? |
Returns
void
Defined in
lexical-selection/src/range-selection.ts:435
$patchStyleText
▸ $patchStyleText(selection
, patch
): void
Applies the provided styles to the TextNodes in the provided Selection. Will update partially selected TextNodes by splitting the TextNode and applying the styles to the appropriate one.
Parameters
Name | Type | Description |
---|---|---|
selection | INTERNAL_PointSelection | The selected node(s) to update. |
patch | Record <string , null | string > | The patch to apply, which can include multiple styles. { CSSProperty: value } |
Returns
void
Defined in
lexical-selection/src/lexical-node.ts:323
$selectAll
▸ $selectAll(selection
): void
Expands the current Selection to cover all of the content in the editor.
Parameters
Name | Type | Description |
---|---|---|
selection | RangeSelection | The current selection. |
Returns
void
Defined in
lexical-selection/src/range-selection.ts:453
$setBlocksType
▸ $setBlocksType(selection
, createElement
): void
Converts all nodes in the selection that are of one block type to another.
Parameters
Name | Type | Description |
---|---|---|
selection | INTERNAL_PointSelection | The selected blocks to be converted. |
createElement | () => ElementNode | The function that creates the node. eg. $createParagraphNode. |
Returns
void
Defined in
lexical-selection/src/range-selection.ts:44
$shouldOverrideDefaultCharacterSelection
▸ $shouldOverrideDefaultCharacterSelection(selection
, isBackward
): boolean
Determines if the default character selection should be overridden. Used with DecoratorNodes
Parameters
Name | Type | Description |
---|---|---|
selection | RangeSelection | The selection whose default character selection may need to be overridden. |
isBackward | boolean | Is the selection backwards (the focus comes before the anchor)? |
Returns
boolean
true if it should be overridden, false if not.
Defined in
lexical-selection/src/range-selection.ts:385
$sliceSelectedTextNodeContent
▸ $sliceSelectedTextNodeContent(selection
, textNode
): LexicalNode
Generally used to append text content to HTML and JSON. Grabs the text content and "slices" it to be generated into the new TextNode.
Parameters
Name | Type | Description |
---|---|---|
selection | BaseSelection | The selection containing the node whose TextNode is to be edited. |
textNode | TextNode | The TextNode to be edited. |
Returns
The updated TextNode.
Defined in
lexical-selection/src/lexical-node.ts:94
$wrapNodes
▸ $wrapNodes(selection
, createElement
, wrappingElement?
): void
Deprecated
Wraps all nodes in the selection into another node of the type returned by createElement.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
selection | INTERNAL_PointSelection | undefined | The selection of nodes to be wrapped. |
createElement | () => ElementNode | undefined | A function that creates the wrapping ElementNode. eg. $createParagraphNode. |
wrappingElement | null | ElementNode | null | An element to append the wrapped selection and its children to. |
Returns
void
Defined in
lexical-selection/src/range-selection.ts:112
createDOMRange
▸ createDOMRange(editor
, anchorNode
, _anchorOffset
, focusNode
, _focusOffset
): Range
| null
Creates a selection range for the DOM.
Parameters
Name | Type | Description |
---|---|---|
editor | LexicalEditor | The lexical editor. |
anchorNode | LexicalNode | The anchor node of a selection. |
_anchorOffset | number | The amount of space offset from the anchor to the focus. |
focusNode | LexicalNode | The current focus. |
_focusOffset | number | The amount of space offset from the focus to the anchor. |
Returns
Range
| null
The range of selection for the DOM that was created.
Defined in
lexical-selection/src/utils.ts:47
createRectsFromDOMRange
▸ createRectsFromDOMRange(editor
, range
): ClientRect
[]
Creates DOMRects, generally used to help the editor find a specific location on the screen.
Parameters
Name | Type | Description |
---|---|---|
editor | LexicalEditor | The lexical editor |
range | Range | A fragment of a document that can contain nodes and parts of text nodes. |
Returns
ClientRect
[]
The selectionRects as an array.
Defined in
lexical-selection/src/utils.ts:124
getStyleObjectFromCSS
▸ getStyleObjectFromCSS(css
): Record
<string
, string
>
Given a CSS string, returns an object from the style cache.
Parameters
Name | Type | Description |
---|---|---|
css | string | The CSS property as a string. |
Returns
Record
<string
, string
>
The value of the given CSS property.
Defined in
lexical-selection/src/utils.ts:198
trimTextContentFromAnchor
▸ trimTextContentFromAnchor(editor
, anchor
, delCount
): void
Trims text from a node in order to shorten it, eg. to enforce a text's max length. If it deletes text that is an ancestor of the anchor then it will leave 2 indents, otherwise, if no text content exists, it deletes the TextNode. It will move the focus to either the end of any left over text or beginning of a new TextNode.
Parameters
Name | Type | Description |
---|---|---|
editor | LexicalEditor | The lexical editor. |
anchor | Point | The anchor of the current selection, where the selection should be pointing. |
delCount | number | The amount of characters to delete. Useful as a dynamic variable eg. textContentSize - maxLength; |
Returns
void
Defined in
lexical-selection/src/lexical-node.ts:164