Static Functions

12 Sep 202523 minutes to read

Root static functions of Blockeditor Component

handleExistingContentElement

Handles the case where existing content element persists.

Parameter Type Description
block BlockModel The block model containing data.
blockElement HTMLElement The block container element.
contentElement HTMLElement The content element to be updated.
existingContentElement HTMLElement | Node The existing element to transform.

Returns void

getAdjacentBlock

Gets the adjacent block of the current block based on the direction.

Parameter Type Description
currentBlock HTMLElement The current block element.
direction string The direction to find the adjacent block (‘previous’ or ‘next’).

Returns HTMLElement | null

getBlockContentElement

Gets the actual content element inside the block.

Parameter Type Description
blockElement HTMLElement The block element.

Returns HTMLElement | null

getBlockIndexById

Gets the index of a specific block element within the blocks array.

Parameter Type Description
id string The id of the block element.
blocks BlockModel[] The list of blocks.

Returns number

getBlockModelById

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

getContentElementBasedOnId

Returns the content element such as span, strong, or chip element by ID or data attribute.

Parameter Type Description
contentId string The id of the content.
wrapper HTMLElement The wrapper element to search within.

Returns HTMLElement

getContentModelById

Finds a content by its ID.
Searches recursively through the list of contents in a block to find a content with the specified ID.

Parameter Type Description
contentId string The ID of the content.
contents ContentModel[] The list of contents.

Returns ContentModel | 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

isAtEndOfBlock

Returns true if the current selection is at the end of the block.

Parameter Type Description
element HTMLElement The block element to check.

Returns boolean

isAtStartOfBlock

Returns true if the current selection is at the start of the block.

Parameter Type Description
element HTMLElement The block element to check.

Returns boolean

isChildrenTypeBlock

Specifies whether the given block is a children type block.

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

Returns boolean

isCursorAtEdge

Specifies whether the cursor is at edge of the block.(start or end)

Parameter Type Description
contentElement HTMLElement The content element to check.
isStart boolean Specifies whether to check for start or end of the block.

Returns boolean

isDividerBlock

Specifies whether the given element is a divider block.

Parameter Type Description
blockElement HTMLElement The block element to check.

Returns boolean

isListTypeBlock

Specifies whether the given block is a list type block.

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

Returns boolean

isNonContentEditableBlock

Specifies whether the given block is a non content editable block.

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

Returns boolean

normalizeBlockIntoContentElement

Normalizes the block element into a content element.

Parameter Type Description
blockElement HTMLElement | Node The block element to normalize.

Returns HTMLElement | Node

removeEmptyTextNodes

Removes empty text nodes from the given element.

Parameter Type Description
element HTMLElement | Node The element to remove empty nodes from.

Returns void

createBlocksFromPlainText

Creates block model from plain clipboard text

Parameter Type Description
text string Text from clipboard

Returns BlockModel[]

generatePlainTextForExternalClipboard

Generates plain text representation of blocks for external clipboard

Parameter Type Description
blocks BlockModel[] Block models to convert to plain text

Returns string

getBlockText

Gets text content from a block model

Parameter Type Description
block BlockModel Block model to extract text from

Returns string

isBlockLevelContent

Checks if HTML content contains block-level elements

Parameter Type Description
container HTMLElement Container with HTML content

Returns boolean

unWrapContainer

Unwraps container element if needed

Parameter Type Description
container HTMLElement Container to potentially unwrap

Returns HTMLElement

cleanupElement

Cleans up an HTML element by removing it from the DOM and setting its reference to null.

Parameter Type Description
element HTMLElement | null The HTML element to clean up.

Returns void

denormalizeUrl

Denormalize URL by removing protocol if present

Parameter Type Description
url string URL to denormalize.

Returns string

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

getAccessibleTextColor

Returns the best accessible foreground color (black or white)
for a given background color to ensure good contrast.

Parameter Type Description
bgColor string The background color in any CSS-supported format (hex, rgb, etc.)

Returns string

getAutoAvatarColor

Returns the auto generated avatar color based on the seed.

Parameter Type Description
seed string The seed string to generate the color.

Returns string

getDeepestTextNode

Gets the deepest text node within an element

Parameter Type Description
element HTMLElement The container element

Returns Node

getUserInitials

Returns the user initials based on the name.

Parameter Type Description
name string The name to generate initials from.

Returns string

isNodeAroundSpecialElements

Checks whether the given node is around special elements.
Some special elements are ‘a’, etc.

Parameter Type Description
node Node | null The node to check.

Returns boolean

isolateModel

Creates an isolated copy of a model with independent references for all nested objects.
This function creates a new instance of a model where all nested objects (including props,
styles, and other references) are also copied, preventing unintended modifications to the
original model or shared references. Use this function when you need to manipulate a model
without affecting other parts of the application that may reference the same object.

Parameter Type Description
item T The original model to create an isolated copy from

Returns T

normalizeRange

Normalizes the range to handle edge cases where selection spans element boundaries

Parameter Type Description
range Range The range to normalize.

Returns Range

normalizeUrl

Normalize URL by adding protocol if missing

Parameter Type Description
url string URL to normalize.

Returns string

getBlockActionsMenuItems

Returns the block action menu items.

Returns BlockActionItemModel[]

getCommandMenuItems

Returns the command menu items.

Returns CommandItemModel[]

getContextMenuItems

Returns the context menu items.

Returns ContextMenuItemModel[]

getInlineToolbarItems

Returns the inline toolbar items.

Returns ToolbarItemModel[]

getLabelMentionDisplayTemplate

Returns the display template content for label mention

Returns string

getLabelMenuItems

Returns the label menu items.

Returns LabelItemModel[]

getLanguageItems

Returns the language items of the code block.

Returns CodeLanguageModel[]

getModifierKey

Returns the modifier key based on the platform (Ctrl for non-macOS, Cmd for macOS).

Returns string

getUserMentionDisplayTemplate

Returns the display template content for user mention

Returns string

isMacOS

Checks if the current operating system is macOS.

Returns boolean

clearBreakTags

Removes all break tags from an HTML element.

Parameter Type Description
element HTMLElement The element to clean

Returns void

createFormattingElement

Creates formatting element based on the content model.

Parameter Type Description
content ContentModel Content model.
value (optional) string | LinkData Value to be set for the content.

Returns HTMLElement

findClosestParent

Finds the closest parent element that matches the specified selector.

Parameter Type Description
element Node | HTMLElement The starting element
selector string The CSS selector to match

Returns HTMLElement | null

getElementRect

Gets the computed absolute position of an element relative to the document.

Parameter Type Description
element HTMLElement The element to get the position for

Returns DOMRect

isElementEmpty

Checks if an element is empty (contains only whitespace or a single
tag).

Parameter Type Description
element HTMLElement The element to check

Returns boolean

isNodeInsideElement

Checks if a node is contained within a container element.

Parameter Type Description
node Node The node to check
container HTMLElement The container element

Returns boolean

wrapNodeWithSpan

Wraps a node with a span and applies the specified style.

Parameter Type Description
node Node The node to wrap
styleType string The type of style to apply
value string | boolean The style value

Returns HTMLElement

wrapNodeWithTag

Wraps a node with a specified HTML tag.

Parameter Type Description
node Node The node to wrap
tagName string The HTML tag to wrap with

Returns HTMLElement

decode

Decodes HTML entities in a string

Parameter Type Description
value string specifies the string value

Returns string

encode

Encodes HTML entities in a string

Parameter Type Description
value string specifies the string value

Returns string

sanitizeHelper

Sanitizes HTML content if enabled

Parameter Type Description
html string The HTML content to sanitize.
enableSanitizer boolean Whether to enable HTML sanitization.

Returns string

captureSelectionState

Captures the current selection state, including the start and end blocks and offsets.

Returns IUndoRedoSelectionState | null

getNodeFromPath

Retrieves a node from a block element using a path.

Parameter Type Description
blockElement HTMLElement The block element to start from.
path number[] The path as an array of indices.

Returns Node | null

getPathFromBlock

Retrieves the path from a block element to a target node.

Parameter Type Description
blockElement HTMLElement The block element to start from.
targetNode Node The target node to find the path to.

Returns number[]

getSelectedRange

Returns the current text selection range.

Returns Range | null

setCursorPosition

Moves the cursor to a specific position considering formatted content

Parameter Type Description
element HTMLElement The container element
position number Character position within entire content (not just text nodes)

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

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[]