WordPress.org

The Block Editor’s Data Edit

Selectors Selectors

getBlockDependantsCacheBust getBlockDependantsCacheBust

Returns a new reference when the inner blocks of a given block client ID
change. This is used exclusively as a memoized selector dependant, relying
on this selector’s shared return value and recursively those of its inner
blocks defined as dependencies. This abuses mechanics of the selector
memoization to return from the original selector function only when
dependants change.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Top ↑

getBlockName getBlockName

Returns a block’s name given its client ID, or null if no block exists with
the client ID.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Block name.

Top ↑

isBlockValid isBlockValid

Returns whether a block is valid or not.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Is Valid.

Top ↑

getBlockAttributes getBlockAttributes

Returns a block’s attributes given its client ID, or null if no block exists with
the client ID.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Block attributes.

Top ↑

getBlock getBlock

Returns a block given its client ID. This is a parsed copy of the block,
containing its blockName, clientId, and current attributes state. This
is not the block’s registration settings, which must be retrieved from the
blocks module registration store.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Parsed block object.

Top ↑

getBlocks getBlocks

Returns all block objects for the current post being edited as an array in
the order they appear in the post.

Note: It’s important to memoize this selector to avoid return a new instance
on each call

Parameters

  • state: Editor state.
  • rootClientId: Optional root client ID of block list.

Returns

Post blocks.

Top ↑

getClientIdsOfDescendants getClientIdsOfDescendants

Returns an array containing the clientIds of all descendants
of the blocks given.

Parameters

  • state: Global application state.
  • clientIds: Array of blocks to inspect.

Returns

ids of descendants.

Top ↑

getClientIdsWithDescendants getClientIdsWithDescendants

Returns an array containing the clientIds of the top-level blocks
and their descendants of any depth (for nested blocks).

Parameters

  • state: Global application state.

Returns

ids of top-level and descendant blocks.

Top ↑

getGlobalBlockCount getGlobalBlockCount

Returns the total number of blocks, or the total number of blocks with a specific name in a post.
The number returned includes nested blocks.

Parameters

  • state: Global application state.
  • blockName: Optional block name, if specified only blocks of that type will be counted.

Returns

Number of blocks in the post, or number of blocks with name equal to blockName.

Top ↑

getBlocksByClientId getBlocksByClientId

Given an array of block client IDs, returns the corresponding array of block
objects.

Parameters

  • state: Editor state.
  • clientIds: Client IDs for which blocks are to be returned.

Returns

Block objects.

Top ↑

getBlockCount getBlockCount

Returns the number of blocks currently present in the post.

Parameters

  • state: Editor state.
  • rootClientId: Optional root client ID of block list.

Returns

Number of blocks in the post.

Top ↑

getSelectionStart getSelectionStart

Returns the current selection start block client ID, attribute key and text
offset.

Parameters

  • state: Block editor state.

Returns

Selection start information.

Top ↑

getSelectionEnd getSelectionEnd

Returns the current selection end block client ID, attribute key and text
offset.

Parameters

  • state: Block editor state.

Returns

Selection end information.

Top ↑

getBlockSelectionStart getBlockSelectionStart

Returns the current block selection start. This value may be null, and it
may represent either a singular block selection or multi-selection start.
A selection is singular if its start and end match.

Parameters

  • state: Global application state.

Returns

Client ID of block selection start.

Top ↑

getBlockSelectionEnd getBlockSelectionEnd

Returns the current block selection end. This value may be null, and it
may represent either a singular block selection or multi-selection end.
A selection is singular if its start and end match.

Parameters

  • state: Global application state.

Returns

Client ID of block selection end.

Top ↑

getSelectedBlockCount getSelectedBlockCount

Returns the number of blocks currently selected in the post.

Parameters

  • state: Global application state.

Returns

Number of blocks selected in the post.

Top ↑

hasSelectedBlock hasSelectedBlock

Returns true if there is a single selected block, or false otherwise.

Parameters

  • state: Editor state.

Returns

Whether a single block is selected.

Top ↑

getSelectedBlockClientId getSelectedBlockClientId

Returns the currently selected block client ID, or null if there is no
selected block.

Parameters

  • state: Editor state.

Returns

Selected block client ID.

Top ↑

getSelectedBlock getSelectedBlock

Returns the currently selected block, or null if there is no selected block.

Parameters

  • state: Global application state.

Returns

Selected block.

Top ↑

getBlockRootClientId getBlockRootClientId

Given a block client ID, returns the root block from which the block is
nested, an empty string for top-level blocks, or null if the block does not
exist.

Parameters

  • state: Editor state.
  • clientId: Block from which to find root client ID.

Returns

Root client ID, if exists

Top ↑

getBlockHierarchyRootClientId getBlockHierarchyRootClientId

Given a block client ID, returns the root of the hierarchy from which the block is nested, return the block itself for root level blocks.

Parameters

  • state: Editor state.
  • clientId: Block from which to find root client ID.

Returns

Root client ID

Top ↑

getAdjacentBlockClientId getAdjacentBlockClientId

Returns the client ID of the block adjacent one at the given reference
startClientId and modifier directionality. Defaults start startClientId to
the selected block, and direction as next block. Returns null if there is no
adjacent block.

Parameters

  • state: Editor state.
  • startClientId: Optional client ID of block from which to
    search.
  • modifier: Directionality multiplier (1 next, -1
    previous).

Returns

Return the client ID of the block, or null if none exists.

Top ↑

getPreviousBlockClientId getPreviousBlockClientId

Returns the previous block’s client ID from the given reference start ID.
Defaults start to the selected block. Returns null if there is no previous
block.

Parameters

  • state: Editor state.
  • startClientId: Optional client ID of block from which to
    search.

Returns

Adjacent block’s client ID, or null if none exists.

Top ↑

getNextBlockClientId getNextBlockClientId

Returns the next block’s client ID from the given reference start ID.
Defaults start to the selected block. Returns null if there is no next
block.

Parameters

  • state: Editor state.
  • startClientId: Optional client ID of block from which to
    search.

Returns

Adjacent block’s client ID, or null if none exists.

Top ↑

getSelectedBlocksInitialCaretPosition getSelectedBlocksInitialCaretPosition

Returns the initial caret position for the selected block.
This position is to used to position the caret properly when the selected block changes.

Parameters

  • state: Global application state.

Returns

Selected block.

Top ↑

getSelectedBlockClientIds getSelectedBlockClientIds

Returns the current selection set of block client IDs (multiselection or single selection).

Parameters

  • state: Editor state.

Returns

Multi-selected block client IDs.

Top ↑

getMultiSelectedBlockClientIds getMultiSelectedBlockClientIds

Returns the current multi-selection set of block client IDs, or an empty
array if there is no multi-selection.

Parameters

  • state: Editor state.

Returns

Multi-selected block client IDs.

Top ↑

getMultiSelectedBlocks getMultiSelectedBlocks

Returns the current multi-selection set of blocks, or an empty array if
there is no multi-selection.

Parameters

  • state: Editor state.

Returns

Multi-selected block objects.

Top ↑

getFirstMultiSelectedBlockClientId getFirstMultiSelectedBlockClientId

Returns the client ID of the first block in the multi-selection set, or null
if there is no multi-selection.

Parameters

  • state: Editor state.

Returns

First block client ID in the multi-selection set.

Top ↑

getLastMultiSelectedBlockClientId getLastMultiSelectedBlockClientId

Returns the client ID of the last block in the multi-selection set, or null
if there is no multi-selection.

Parameters

  • state: Editor state.

Returns

Last block client ID in the multi-selection set.

Top ↑

isFirstMultiSelectedBlock isFirstMultiSelectedBlock

Returns true if a multi-selection exists, and the block corresponding to the
specified client ID is the first block of the multi-selection set, or false
otherwise.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Whether block is first in multi-selection.

Top ↑

isBlockMultiSelected isBlockMultiSelected

Returns true if the client ID occurs within the block multi-selection, or
false otherwise.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Whether block is in multi-selection set.

Top ↑

isAncestorMultiSelected isAncestorMultiSelected

Returns true if an ancestor of the block is multi-selected, or false
otherwise.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Whether an ancestor of the block is in multi-selection
set.

Top ↑

getMultiSelectedBlocksStartClientId getMultiSelectedBlocksStartClientId

Returns the client ID of the block which begins the multi-selection set, or
null if there is no multi-selection.

This is not necessarily the first client ID in the selection.

Parameters

  • state: Editor state.

Returns

Client ID of block beginning multi-selection.

Top ↑

getMultiSelectedBlocksEndClientId getMultiSelectedBlocksEndClientId

Returns the client ID of the block which ends the multi-selection set, or
null if there is no multi-selection.

This is not necessarily the last client ID in the selection.

Parameters

  • state: Editor state.

Returns

Client ID of block ending multi-selection.

Top ↑

getBlockOrder getBlockOrder

Returns an array containing all block client IDs in the editor in the order
they appear. Optionally accepts a root client ID of the block list for which
the order should be returned, defaulting to the top-level block order.

Parameters

  • state: Editor state.
  • rootClientId: Optional root client ID of block list.

Returns

Ordered client IDs of editor blocks.

Top ↑

getBlockIndex getBlockIndex

Returns the index at which the block corresponding to the specified client
ID occurs within the block order, or -1 if the block does not exist.

Parameters

  • state: Editor state.
  • clientId: Block client ID.
  • rootClientId: Optional root client ID of block list.

Returns

Index at which block exists in order.

Top ↑

isBlockSelected isBlockSelected

Returns true if the block corresponding to the specified client ID is
currently selected and no multi-selection exists, or false otherwise.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Whether block is selected and multi-selection exists.

Top ↑

hasSelectedInnerBlock hasSelectedInnerBlock

Returns true if one of the block’s inner blocks is selected.

Parameters

  • state: Editor state.
  • clientId: Block client ID.
  • deep: Perform a deep check.

Returns

Whether the block as an inner block selected

Top ↑

isBlockWithinSelection isBlockWithinSelection

Returns true if the block corresponding to the specified client ID is
currently selected but isn’t the last of the selected blocks. Here “last”
refers to the block sequence in the document, not the sequence of
multi-selection, which is why state.blockSelection.end isn’t used.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Whether block is selected and not the last in the
selection.

Top ↑

hasMultiSelection hasMultiSelection

Returns true if a multi-selection has been made, or false otherwise.

Parameters

  • state: Editor state.

Returns

Whether multi-selection has been made.

Top ↑

isMultiSelecting isMultiSelecting

Whether in the process of multi-selecting or not. This flag is only true
while the multi-selection is being selected (by mouse move), and is false
once the multi-selection has been settled.

Parameters

  • state: Global application state.

Returns

True if multi-selecting, false if not.

Top ↑

isSelectionEnabled isSelectionEnabled

Selector that returns if multi-selection is enabled or not.

Parameters

  • state: Global application state.

Returns

True if it should be possible to multi-select blocks, false if multi-selection is disabled.

Top ↑

getBlockMode getBlockMode

Returns the block’s editing mode, defaulting to “visual” if not explicitly
assigned.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Block editing mode.

Top ↑

isTyping isTyping

Returns true if the user is typing, or false otherwise.

Parameters

  • state: Global application state.

Returns

Whether user is typing.

Top ↑

isCaretWithinFormattedText isCaretWithinFormattedText

Returns true if the caret is within formatted text, or false otherwise.

Parameters

  • state: Global application state.

Returns

Whether the caret is within formatted text.

Top ↑

getBlockInsertionPoint getBlockInsertionPoint

Returns the insertion point, the index at which the new inserted block would
be placed. Defaults to the last index.

Parameters

  • state: Editor state.

Returns

Insertion point object with rootClientId, index.

Top ↑

isBlockInsertionPointVisible isBlockInsertionPointVisible

Returns true if we should show the block insertion point.

Parameters

  • state: Global application state.

Returns

Whether the insertion point is visible or not.

Top ↑

isValidTemplate isValidTemplate

Returns whether the blocks matches the template or not.

Parameters

  • state: null

Returns

Whether the template is valid or not.

Top ↑

getTemplate getTemplate

Returns the defined block template

Parameters

  • state: null

Returns

Block Template

Top ↑

getTemplateLock getTemplateLock

Returns the defined block template lock. Optionally accepts a root block
client ID as context, otherwise defaulting to the global context.

Parameters

  • state: Editor state.
  • rootClientId: Optional block root client ID.

Returns

Block Template Lock

Top ↑

canInsertBlockType canInsertBlockType

Determines if the given block type is allowed to be inserted into the block list.

Parameters

  • state: Editor state.
  • blockName: The name of the block type, e.g.’ core/paragraph’.
  • rootClientId: Optional root client ID of block list.

Returns

Whether the given block type is allowed to be inserted.

Top ↑

getInserterItems getInserterItems

Determines the items that appear in the inserter. Includes both static
items (e.g. a regular block type) and dynamic items (e.g. a reusable block).

Each item object contains what’s necessary to display a button in the
inserter and handle its selection.

The ‘utility’ property indicates how useful we think an item will be to the
user. There are 4 levels of utility:

  1. Blocks that are contextually useful (utility = 3)
  2. Blocks that have been previously inserted (utility = 2)
  3. Blocks that are in the common category (utility = 1)
  4. All other blocks (utility = 0)

The ‘frecency’ property is a heuristic (https://en.wikipedia.org/wiki/Frecency)
that combines block usage frequenty and recency.

Items are returned ordered descendingly by their ‘utility’ and ‘frecency’.

Parameters

  • state: Editor state.
  • rootClientId: Optional root client ID of block list.

Returns

Items that appear in inserter.

Top ↑

hasInserterItems hasInserterItems

Determines whether there are items to show in the inserter.

Parameters

  • state: Editor state.
  • rootClientId: Optional root client ID of block list.

Returns

Items that appear in inserter.

Top ↑

getBlockListSettings getBlockListSettings

Returns the Block List settings of a block, if any exist.

Parameters

  • state: Editor state.
  • clientId: Block client ID.

Returns

Block settings of the block if set.

Top ↑

getSettings getSettings

Returns the editor settings.

Parameters

  • state: Editor state.

Returns

The editor settings object.

Top ↑

isLastBlockChangePersistent isLastBlockChangePersistent

Returns true if the most recent block change is be considered persistent, or
false otherwise. A persistent change is one committed by BlockEditorProvider
via its onChange callback, in addition to onInput.

Parameters

  • state: Block editor state.

Returns

Whether the most recent block change was persistent.

Top ↑

__unstableIsLastBlockChangeIgnored __unstableIsLastBlockChangeIgnored

Returns true if the most recent block change is be considered ignored, or
false otherwise. An ignored change is one not to be committed by
BlockEditorProvider, neither via onChange nor onInput.

Parameters

  • state: Block editor state.

Returns

Whether the most recent block change was ignored.

Top ↑

Actions Actions

Top ↑

resetBlocks resetBlocks

Returns an action object used in signalling that blocks state should be
reset to the specified array of blocks, taking precedence over any other
content reflected as an edit in state.

Parameters

  • blocks: Array of blocks.

Top ↑

receiveBlocks receiveBlocks

Returns an action object used in signalling that blocks have been received.
Unlike resetBlocks, these should be appended to the existing known set, not
replacing.

Parameters

  • blocks: Array of block objects.

Top ↑

updateBlockAttributes updateBlockAttributes

Returns an action object used in signalling that the block attributes with
the specified client ID has been updated.

Parameters

  • clientId: Block client ID.
  • attributes: Block attributes to be merged.

Top ↑

updateBlock updateBlock

Returns an action object used in signalling that the block with the
specified client ID has been updated.

Parameters

  • clientId: Block client ID.
  • updates: Block attributes to be merged.

Top ↑

selectBlock selectBlock

Returns an action object used in signalling that the block with the
specified client ID has been selected, optionally accepting a position
value reflecting its selection directionality. An initialPosition of -1
reflects a reverse selection.

Parameters

  • clientId: Block client ID.
  • initialPosition: Optional initial position. Pass as -1 to
    reflect reverse selection.

Top ↑

selectPreviousBlock selectPreviousBlock

Yields action objects used in signalling that the block preceding the given
clientId should be selected.

Parameters

  • clientId: Block client ID.

Top ↑

selectNextBlock selectNextBlock

Yields action objects used in signalling that the block following the given
clientId should be selected.

Parameters

  • clientId: Block client ID.

Top ↑

startMultiSelect startMultiSelect

Returns an action object used in signalling that a block multi-selection has started.

Top ↑

stopMultiSelect stopMultiSelect

Returns an action object used in signalling that block multi-selection stopped.

Top ↑

multiSelect multiSelect

Returns an action object used in signalling that block multi-selection changed.

Parameters

  • start: First block of the multi selection.
  • end: Last block of the multiselection.

Top ↑

clearSelectedBlock clearSelectedBlock

Returns an action object used in signalling that the block selection is cleared.

Top ↑

toggleSelection toggleSelection

Returns an action object that enables or disables block selection.

Parameters

  • boolean: [isSelectionEnabled=true] Whether block selection should
    be enabled.

Top ↑

replaceBlocks replaceBlocks

Returns an action object signalling that a blocks should be replaced with
one or more replacement blocks.

Parameters

  • clientIds: Block client ID(s) to replace.
  • blocks: Replacement block(s).

Top ↑

replaceBlock replaceBlock

Returns an action object signalling that a single block should be replaced
with one or more replacement blocks.

Parameters

  • clientId: Block client ID to replace.
  • block: Replacement block(s).

Top ↑

moveBlockToPosition moveBlockToPosition

Returns an action object signalling that an indexed block should be moved
to a new index.

Parameters

  • clientId: The client ID of the block.
  • fromRootClientId: Root client ID source.
  • toRootClientId: Root client ID destination.
  • index: The index to move the block into.

Top ↑

insertBlock insertBlock

Returns an action object used in signalling that a single block should be
inserted, optionally at a specific index respective a root block list.

Parameters

  • block: Block object to insert.
  • index: Index at which block should be inserted.
  • rootClientId: Optional root client ID of block list on which to insert.
  • updateSelection: If true block selection will be updated. If false, block selection will not change. Defaults to true.

Top ↑

insertBlocks insertBlocks

Returns an action object used in signalling that an array of blocks should
be inserted, optionally at a specific index respective a root block list.

Parameters

  • blocks: Block objects to insert.
  • index: Index at which block should be inserted.
  • rootClientId: Optional root client ID of block list on which to insert.
  • updateSelection: If true block selection will be updated. If false, block selection will not change. Defaults to true.

Top ↑

showInsertionPoint showInsertionPoint

Returns an action object used in signalling that the insertion point should
be shown.

Parameters

  • rootClientId: Optional root client ID of block list on
    which to insert.
  • index: Index at which block should be inserted.

Top ↑

hideInsertionPoint hideInsertionPoint

Returns an action object hiding the insertion point.

Top ↑

setTemplateValidity setTemplateValidity

Returns an action object resetting the template validity.

Parameters

  • isValid: template validity flag.

Top ↑

synchronizeTemplate synchronizeTemplate

Returns an action object synchronize the template with the list of blocks

Top ↑

mergeBlocks mergeBlocks

Returns an action object used in signalling that two blocks should be merged

Parameters

  • firstBlockClientId: Client ID of the first block to merge.
  • secondBlockClientId: Client ID of the second block to merge.

Top ↑

removeBlocks removeBlocks

Yields action objects used in signalling that the blocks corresponding to
the set of specified client IDs are to be removed.

Parameters

  • clientIds: Client IDs of blocks to remove.
  • selectPrevious: True if the previous block should be
    selected when a block is removed.

Top ↑

removeBlock removeBlock

Returns an action object used in signalling that the block with the
specified client ID is to be removed.

Parameters

  • clientId: Client ID of block to remove.
  • selectPrevious: True if the previous block should be
    selected when a block is removed.

Top ↑

replaceInnerBlocks replaceInnerBlocks

Returns an action object used in signalling that the inner blocks with the
specified client ID should be replaced.

Parameters

  • rootClientId: Client ID of the block whose InnerBlocks will re replaced.
  • blocks: Block objects to insert as new InnerBlocks
  • updateSelection: If true block selection will be updated. If false, block selection will not change. Defaults to true.

Top ↑

toggleBlockMode toggleBlockMode

Returns an action object used to toggle the block editing mode between
visual and HTML modes.

Parameters

  • clientId: Block client ID.

Top ↑

startTyping startTyping

Returns an action object used in signalling that the user has begun to type.

Top ↑

stopTyping stopTyping

Returns an action object used in signalling that the user has stopped typing.

Top ↑

enterFormattedText enterFormattedText

Returns an action object used in signalling that the caret has entered formatted text.

Top ↑

exitFormattedText exitFormattedText

Returns an action object used in signalling that the user caret has exited formatted text.

Top ↑

selectionChange selectionChange

Returns an action object used in signalling that the user caret has changed
position.

Parameters

  • clientId: The selected block client ID.
  • attributeKey: The selected block attribute key.
  • startOffset: The start offset.
  • endOffset: The end offset.

Top ↑

insertDefaultBlock insertDefaultBlock

Returns an action object used in signalling that a new block of the default
type should be added to the block list.

Parameters

  • attributes: Optional attributes of the block to assign.
  • rootClientId: Optional root client ID of block list on which
    to append.
  • index: Optional index where to insert the default block

Top ↑

updateBlockListSettings updateBlockListSettings

Returns an action object that changes the nested settings of a given block.

Parameters

  • clientId: Client ID of the block whose nested setting are
    being received.
  • settings: Object with the new settings for the nested block.

Top ↑

updateSettings updateSettings

Returns an action object used in signalling that the block editor settings have been updated.

Parameters

  • settings: Updated settings

Top ↑

__unstableSaveReusableBlock __unstableSaveReusableBlock

Returns an action object used in signalling that a temporary reusable blocks have been saved
in order to switch its temporary id with the real id.

Parameters

  • id: Reusable block’s id.
  • updatedId: Updated block’s id.

Top ↑

__unstableMarkLastChangeAsPersistent __unstableMarkLastChangeAsPersistent

Returns an action object used in signalling that the last block change should be marked explicitely as persistent.

Skip to toolbar