Search results

Static Functions API in JavaScript (ES5) Blockeditor API control

Root static functions of Blockeditor Component

findBlockById

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

getParentBlock

Gets the parent block.

Parameter Type Description
element HTMLElement | Node The element for which you need to find the parent.

Returns HTMLElement | null

getPlaceholderValue

Gets the placeholder value for the given block element.

Parameter Type Description
blockType BlockType | string The type of the block.

Returns string

mergeSimilarStyledContentBlock

Merges adjacent content elements with the same styles to maintain structured storage.

Parameter Type Description
block BlockModel The block to be checked.

Returns void

copyToClipboard

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

cutToClipboard

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

pasteFromClipboard

Pastes text from the clipboard. Uses the Clipboard API to read text from the user’s clipboard.

Returns Promise

generateUniqueId

Generates a unique ID with an optional prefix.

Returns string

getAbsoluteOffset

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

isEmpty

Determines whether a given node is empty (contains no meaningful content).

Parameter Type Description
node Node The node to check.

Returns boolean

normalizeText

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

sanitizeHTML

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

scrollIntoView

Smoothly scrolls an element into view.

Parameter Type Description
node Node The node to scroll into view.

Returns void

getCommandMenuItems

Returns the command menu items.

Returns CommandItemModel[]

getInlineToolbarItems

Returns the inline toolbar items.

Returns ToolbarItemModel[]

collapseSelection

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

expandSelectionToWord

Expands the selection to the nearest word boundaries.

Parameter Type Description
element HTMLElement The text-containing HTML element.

Returns void

getCaretPosition

Retrieves the caret position inside an editable block.

Parameter Type Description
element HTMLElement The block element.

Returns number

getCursorPosition

Returns the current cursor position.

Returns number | null

getSelectedText

Returns the currently selected text.

Returns string

getSelectionRange

Returns the current text selection range.

Returns Range | null

isSelectionCollapsed

Checks if the selection is collapsed (no text selected).

Returns boolean

setCursorPosition

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

setSelectionRange

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

deleteText

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

getTextAfterCursor

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

getTextAtRange

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

getTextBeforeCursor

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

insertText

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

replaceText

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

wrapText

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

transformIntoToolbarItem

Transforms an array of ToolbarItemModel objects into an array of ItemModel objects.

Parameter Type Description
items ToolbarItemModel[] The toolbar items to transform.

Returns ItemModel[]