Root static functions of Blockeditor Component
Finds a block by its ID. Searches recursively through the list of blocks to find a block with the specified ID.
Parameter | Type | Description |
---|---|---|
blockId | string |
The ID of the block. |
blocks | BlockModel[] |
The list of blocks. |
Returns BlockModel | null
Gets the parent block.
Parameter | Type | Description |
---|---|---|
element | HTMLElement | Node |
The element for which you need to find the parent. |
Returns HTMLElement | null
Gets the placeholder value for the given block element.
Parameter | Type | Description |
---|---|---|
blockType | BlockType | string |
The type of the block. |
Returns string
Merges adjacent content elements with the same styles to maintain structured storage.
Parameter | Type | Description |
---|---|---|
block | BlockModel |
The block to be checked. |
Returns void
Copies text to the clipboard. Uses the Clipboard API to write the given text to the user’s clipboard.
Parameter | Type | Description |
---|---|---|
text | string |
The text to copy to the clipboard. |
Returns Promise
Cuts a selected portion of text to the clipboard. This function removes the selected portion from the text content and copies it to the clipboard.
Parameter | Type | Description |
---|---|---|
start | number |
The start index of the text selection. |
end | number |
The end index of the text selection. |
Returns Promise
Pastes text from the clipboard. Uses the Clipboard API to read text from the user’s clipboard.
Returns Promise
Generates a unique ID with an optional prefix.
Returns string
Calculates the absolute offset of a given node within its parent element.
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The parent element. |
node | Node |
The node to calculate the offset for. |
relativeOffset | number |
The offset relative to the node. |
Returns number
Determines whether a given node is empty (contains no meaningful content).
Parameter | Type | Description |
---|---|---|
node | Node |
The node to check. |
Returns boolean
Normalizes a text string by trimming and replacing multiple spaces with a single space.
Parameter | Type | Description |
---|---|---|
text | string |
The text to normalize. |
Returns string
Sanitizes an HTML string to prevent XSS attacks by escaping potentially harmful characters.
Parameter | Type | Description |
---|---|---|
html | string |
The HTML string to sanitize. |
Returns string
Smoothly scrolls an element into view.
Parameter | Type | Description |
---|---|---|
node | Node |
The node to scroll into view. |
Returns void
Returns the command menu items.
Returns CommandItemModel[]
Returns the inline toolbar items.
Returns ToolbarItemModel[]
Collapses the selection to the start or end.
Parameter | Type | Description |
---|---|---|
toStart | boolean |
Whether to collapse to the start (true) or the end (false). |
Returns void
Expands the selection to the nearest word boundaries.
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The text-containing HTML element. |
Returns void
Retrieves the caret position inside an editable block.
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The block element. |
Returns number
Returns the current cursor position.
Returns number | null
Returns the currently selected text.
Returns string
Returns the current text selection range.
Returns Range | null
Checks if the selection is collapsed (no text selected).
Returns boolean
Moves the cursor to a specific position.
Parameter | Type | Description |
---|---|---|
element | Element | HTMLElement |
The HTML element to apply the cursor position to. |
position | number |
The position to move the cursor to. |
Returns void
Sets the selection range in the editor.
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The HTML element to apply the selection range to. |
start | number |
The start index of the selection. |
end | number |
The end index of the selection. |
Returns void
Deletes text within a specific range.
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The HTML element to delete text from. |
start | number |
The start index of the range. |
end | number |
The end index of the range. |
Returns void
Returns text after the cursor.
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The HTML element to get text from. |
length | number |
The number of characters to retrieve after the cursor. |
Returns string
Returns text within a specific range.
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The HTML element to get range. |
start | number |
The start index of the range. |
end | number |
The end index of the range. |
Returns string
Returns text before the cursor.
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The HTML element to get text from. |
length | number |
The number of characters to retrieve before the cursor. |
Returns string
Inserts text at the current cursor position.
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The HTML element where the text will be inserted. |
text | string |
The text to insert. |
Returns void
Replaces text within a range.
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The HTML element to replace text in. |
start | number |
The start index of the range. |
end | number |
The end index of the range. |
newText | string |
The text to insert. |
Returns void
Wraps selected text with a wrapper (e.g., ** for bold).
Parameter | Type | Description |
---|---|---|
element | HTMLElement |
The HTML element containing the text. |
start | number |
The start index of the range. |
end | number |
The end index of the range. |
wrapper | string |
The wrapper string to apply. |
Returns void
Transforms an array of ToolbarItemModel objects into an array of ItemModel objects.
Parameter | Type | Description |
---|---|---|
items | ToolbarItemModel[] |
The toolbar items to transform. |
Returns ItemModel[]