@wordpress/block-editor
Version:
4 lines • 138 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/store/selectors.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tgetBlockType,\n\tgetBlockTypes,\n\tgetBlockVariations,\n\thasBlockSupport,\n\tgetPossibleBlockTransformations,\n\tswitchToBlockType,\n\tstore as blocksStore,\n\tprivateApis as blocksPrivateApis,\n} from '@wordpress/blocks';\nimport { Platform } from '@wordpress/element';\nimport { applyFilters } from '@wordpress/hooks';\nimport { symbol } from '@wordpress/icons';\nimport { create, remove, toHTMLString } from '@wordpress/rich-text';\nimport deprecated from '@wordpress/deprecated';\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tisFiltered,\n\tcheckAllowListRecursive,\n\tcheckAllowList,\n\tgetAllPatternsDependants,\n\tgetInsertBlockTypeDependants,\n\tgetParsedPattern,\n\tgetGrammar,\n\tmapUserPattern,\n} from './utils';\nimport { orderBy } from '../utils/sorting';\nimport { STORE_NAME } from './constants';\nimport { unlock } from '../lock-unlock';\n\nimport {\n\tgetContentLockingParent,\n\tgetEditedContentOnlySection,\n\tgetSectionRootClientId,\n\tisSectionBlock,\n\tgetParentSectionBlock,\n\tisZoomOut,\n\tisContainerInsertableToInContentOnlyMode,\n} from './private-selectors';\n\nconst { isContentBlock } = unlock( blocksPrivateApis );\n\n/**\n * A block selection object.\n *\n * @typedef {Object} WPBlockSelection\n *\n * @property {string} clientId A block client ID.\n * @property {string} attributeKey A block attribute key.\n * @property {number} offset An attribute value offset, based on the rich\n * text value. See `wp.richText.create`.\n */\n\n// Module constants.\nconst MILLISECONDS_PER_HOUR = 3600 * 1000;\nconst MILLISECONDS_PER_DAY = 24 * 3600 * 1000;\nconst MILLISECONDS_PER_WEEK = 7 * 24 * 3600 * 1000;\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation, as in a connected or\n * other pure component which performs `shouldComponentUpdate` check on props.\n * This should be used as a last resort, since the normalized data should be\n * maintained by the reducer result in state.\n *\n * @type {Array}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Shared reference to an empty Set for cases where it is important to avoid\n * returning a new Set reference on every invocation, as in a connected or\n * other pure component which performs `shouldComponentUpdate` check on props.\n * This should be used as a last resort, since the normalized data should be\n * maintained by the reducer result in state.\n *\n * @type {Set}\n */\nconst EMPTY_SET = new Set();\n\nconst DEFAULT_INSERTER_OPTIONS = {\n\t[ isFiltered ]: true,\n};\n\n/**\n * Returns a block's name given its client ID, or null if no block exists with\n * the client ID.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {string} Block name.\n */\nexport function getBlockName( state, clientId ) {\n\tconst block = state.blocks.byClientId.get( clientId );\n\tconst socialLinkName = 'core/social-link';\n\n\tif ( Platform.OS !== 'web' && block?.name === socialLinkName ) {\n\t\tconst attributes = state.blocks.attributes.get( clientId );\n\t\tconst { service } = attributes ?? {};\n\n\t\treturn service ? `${ socialLinkName }-${ service }` : socialLinkName;\n\t}\n\treturn block ? block.name : null;\n}\n\n/**\n * Returns whether a block is valid or not.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {boolean} Is Valid.\n */\nexport function isBlockValid( state, clientId ) {\n\tconst block = state.blocks.byClientId.get( clientId );\n\treturn !! block && block.isValid;\n}\n\n/**\n * Returns a block's attributes given its client ID, or null if no block exists with\n * the client ID.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {?Object} Block attributes.\n */\nexport function getBlockAttributes( state, clientId ) {\n\tconst block = state.blocks.byClientId.get( clientId );\n\tif ( ! block ) {\n\t\treturn null;\n\t}\n\n\treturn state.blocks.attributes.get( clientId );\n}\n\n/**\n * Returns a block given its client ID. This is a parsed copy of the block,\n * containing its `blockName`, `clientId`, and current `attributes` state. This\n * is not the block's registration settings, which must be retrieved from the\n * blocks module registration store.\n *\n * getBlock recurses through its inner blocks until all its children blocks have\n * been retrieved. Note that getBlock will not return the child inner blocks of\n * an inner block controller. This is because an inner block controller syncs\n * itself with its own entity, and should therefore not be included with the\n * blocks of a different entity. For example, say you call `getBlocks( TP )` to\n * get the blocks of a template part. If another template part is a child of TP,\n * then the nested template part's child blocks will not be returned. This way,\n * the template block itself is considered part of the parent, but the children\n * are not.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {Object} Parsed block object.\n */\nexport function getBlock( state, clientId ) {\n\tif ( ! state.blocks.byClientId.has( clientId ) ) {\n\t\treturn null;\n\t}\n\n\treturn state.blocks.tree.get( clientId );\n}\n\nexport const __unstableGetBlockWithoutInnerBlocks = createSelector(\n\t( state, clientId ) => {\n\t\tconst block = state.blocks.byClientId.get( clientId );\n\t\tif ( ! block ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn {\n\t\t\t...block,\n\t\t\tattributes: getBlockAttributes( state, clientId ),\n\t\t};\n\t},\n\t( state, clientId ) => [\n\t\tstate.blocks.byClientId.get( clientId ),\n\t\tstate.blocks.attributes.get( clientId ),\n\t]\n);\n\n/**\n * Returns all block objects for the current post being edited as an array in\n * the order they appear in the post. Note that this will exclude child blocks\n * of nested inner block controllers.\n *\n * @param {Object} state Editor state.\n * @param {?string} rootClientId Optional root client ID of block list.\n *\n * @return {Object[]} Post blocks.\n */\nexport function getBlocks( state, rootClientId ) {\n\tconst treeKey =\n\t\t! rootClientId || ! areInnerBlocksControlled( state, rootClientId )\n\t\t\t? rootClientId || ''\n\t\t\t: 'controlled||' + rootClientId;\n\treturn state.blocks.tree.get( treeKey )?.innerBlocks || EMPTY_ARRAY;\n}\n\n/**\n * Returns a stripped down block object containing only its client ID,\n * and its inner blocks' client IDs.\n *\n * @deprecated\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Client ID of the block to get.\n *\n * @return {Object} Client IDs of the post blocks.\n */\nexport const __unstableGetClientIdWithClientIdsTree = createSelector(\n\t( state, clientId ) => {\n\t\tdeprecated(\n\t\t\t\"wp.data.select( 'core/block-editor' ).__unstableGetClientIdWithClientIdsTree\",\n\t\t\t{\n\t\t\t\tsince: '6.3',\n\t\t\t\tversion: '6.5',\n\t\t\t}\n\t\t);\n\t\treturn {\n\t\t\tclientId,\n\t\t\tinnerBlocks: __unstableGetClientIdsTree( state, clientId ),\n\t\t};\n\t},\n\t( state ) => [ state.blocks.order ]\n);\n\n/**\n * Returns the block tree represented in the block-editor store from the\n * given root, consisting of stripped down block objects containing only\n * their client IDs, and their inner blocks' client IDs.\n *\n * @deprecated\n *\n * @param {Object} state Editor state.\n * @param {?string} rootClientId Optional root client ID of block list.\n *\n * @return {Object[]} Client IDs of the post blocks.\n */\nexport const __unstableGetClientIdsTree = createSelector(\n\t( state, rootClientId = '' ) => {\n\t\tdeprecated(\n\t\t\t\"wp.data.select( 'core/block-editor' ).__unstableGetClientIdsTree\",\n\t\t\t{\n\t\t\t\tsince: '6.3',\n\t\t\t\tversion: '6.5',\n\t\t\t}\n\t\t);\n\t\treturn getBlockOrder( state, rootClientId ).map( ( clientId ) =>\n\t\t\t__unstableGetClientIdWithClientIdsTree( state, clientId )\n\t\t);\n\t},\n\t( state ) => [ state.blocks.order ]\n);\n\n/**\n * Returns an array containing the clientIds of all descendants of the blocks\n * given. Returned ids are ordered first by the order of the ids given, then\n * by the order that they appear in the editor.\n *\n * @param {Object} state Global application state.\n * @param {string|string[]} rootIds Client ID(s) for which descendant blocks are to be returned.\n *\n * @return {Array} Client IDs of descendants.\n */\nexport const getClientIdsOfDescendants = createSelector(\n\t( state, rootIds ) => {\n\t\trootIds = Array.isArray( rootIds ) ? [ ...rootIds ] : [ rootIds ];\n\t\tconst ids = [];\n\n\t\t// Add the descendants of the root blocks first.\n\t\tfor ( const rootId of rootIds ) {\n\t\t\tconst order = state.blocks.order.get( rootId );\n\t\t\tif ( order ) {\n\t\t\t\tids.push( ...order );\n\t\t\t}\n\t\t}\n\n\t\tlet index = 0;\n\n\t\t// Add the descendants of the descendants, recursively.\n\t\twhile ( index < ids.length ) {\n\t\t\tconst id = ids[ index ];\n\t\t\tconst order = state.blocks.order.get( id );\n\t\t\tif ( order ) {\n\t\t\t\tids.splice( index + 1, 0, ...order );\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\n\t\treturn ids;\n\t},\n\t( state ) => [ state.blocks.order ]\n);\n\n/**\n * Returns an array containing the clientIds of the top-level blocks and\n * their descendants of any depth (for nested blocks). Ids are returned\n * in the same order that they appear in the editor.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} ids of top-level and descendant blocks.\n */\nexport const getClientIdsWithDescendants = ( state ) =>\n\tgetClientIdsOfDescendants( state, '' );\n\n/**\n * Returns the total number of blocks, or the total number of blocks with a specific name in a post.\n * The number returned includes nested blocks.\n *\n * @param {Object} state Global application state.\n * @param {?string} blockName Optional block name, if specified only blocks of that type will be counted.\n *\n * @return {number} Number of blocks in the post, or number of blocks with name equal to blockName.\n */\nexport const getGlobalBlockCount = createSelector(\n\t( state, blockName ) => {\n\t\tconst clientIds = getClientIdsWithDescendants( state );\n\t\tif ( ! blockName ) {\n\t\t\treturn clientIds.length;\n\t\t}\n\t\tlet count = 0;\n\t\tfor ( const clientId of clientIds ) {\n\t\t\tconst block = state.blocks.byClientId.get( clientId );\n\t\t\tif ( block.name === blockName ) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t},\n\t( state ) => [ state.blocks.order, state.blocks.byClientId ]\n);\n\n/**\n * Returns all blocks that match a blockName. Results include nested blocks.\n *\n * @param {Object} state Global application state.\n * @param {string[]} blockName Block name(s) for which clientIds are to be returned.\n *\n * @return {Array} Array of clientIds of blocks with name equal to blockName.\n */\nexport const getBlocksByName = createSelector(\n\t( state, blockName ) => {\n\t\tif ( ! blockName ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\t\tconst blockNames = Array.isArray( blockName )\n\t\t\t? blockName\n\t\t\t: [ blockName ];\n\t\tconst clientIds = getClientIdsWithDescendants( state );\n\t\tconst foundBlocks = clientIds.filter( ( clientId ) => {\n\t\t\tconst block = state.blocks.byClientId.get( clientId );\n\t\t\treturn blockNames.includes( block.name );\n\t\t} );\n\t\treturn foundBlocks.length > 0 ? foundBlocks : EMPTY_ARRAY;\n\t},\n\t( state ) => [ state.blocks.order, state.blocks.byClientId ]\n);\n\n/**\n * Returns all global blocks that match a blockName. Results include nested blocks.\n *\n * @deprecated\n *\n * @param {Object} state Global application state.\n * @param {string[]} blockName Block name(s) for which clientIds are to be returned.\n *\n * @return {Array} Array of clientIds of blocks with name equal to blockName.\n */\nexport function __experimentalGetGlobalBlocksByName( state, blockName ) {\n\tdeprecated(\n\t\t\"wp.data.select( 'core/block-editor' ).__experimentalGetGlobalBlocksByName\",\n\t\t{\n\t\t\tsince: '6.5',\n\t\t\talternative: `wp.data.select( 'core/block-editor' ).getBlocksByName`,\n\t\t}\n\t);\n\treturn getBlocksByName( state, blockName );\n}\n\n/**\n * Given an array of block client IDs, returns the corresponding array of block\n * objects.\n *\n * @param {Object} state Editor state.\n * @param {string[]} clientIds Client IDs for which blocks are to be returned.\n *\n * @return {WPBlock[]} Block objects.\n */\nexport const getBlocksByClientId = createSelector(\n\t( state, clientIds ) =>\n\t\t( Array.isArray( clientIds ) ? clientIds : [ clientIds ] ).map(\n\t\t\t( clientId ) => getBlock( state, clientId )\n\t\t),\n\t( state, clientIds ) =>\n\t\t( Array.isArray( clientIds ) ? clientIds : [ clientIds ] ).map(\n\t\t\t( clientId ) => state.blocks.tree.get( clientId )\n\t\t)\n);\n\n/**\n * Given an array of block client IDs, returns the corresponding array of block\n * names.\n *\n * @param {Object} state Editor state.\n * @param {string[]} clientIds Client IDs for which block names are to be returned.\n *\n * @return {string[]} Block names.\n */\nexport const getBlockNamesByClientId = createSelector(\n\t( state, clientIds ) =>\n\t\tgetBlocksByClientId( state, clientIds )\n\t\t\t.filter( Boolean )\n\t\t\t.map( ( block ) => block.name ),\n\t( state, clientIds ) => getBlocksByClientId( state, clientIds )\n);\n\n/**\n * Returns the number of blocks currently present in the post.\n *\n * @param {Object} state Editor state.\n * @param {?string} rootClientId Optional root client ID of block list.\n *\n * @return {number} Number of blocks in the post.\n */\nexport function getBlockCount( state, rootClientId ) {\n\treturn getBlockOrder( state, rootClientId ).length;\n}\n\n/**\n * Returns the current selection start block client ID, attribute key and text\n * offset.\n *\n * @param {Object} state Block editor state.\n *\n * @return {WPBlockSelection} Selection start information.\n */\nexport function getSelectionStart( state ) {\n\treturn state.selection.selectionStart;\n}\n\n/**\n * Returns the current selection end block client ID, attribute key and text\n * offset.\n *\n * @param {Object} state Block editor state.\n *\n * @return {WPBlockSelection} Selection end information.\n */\nexport function getSelectionEnd( state ) {\n\treturn state.selection.selectionEnd;\n}\n\n/**\n * Returns the current block selection start. This value may be null, and it\n * may represent either a singular block selection or multi-selection start.\n * A selection is singular if its start and end match.\n *\n * @param {Object} state Global application state.\n *\n * @return {?string} Client ID of block selection start.\n */\nexport function getBlockSelectionStart( state ) {\n\treturn state.selection.selectionStart.clientId;\n}\n\n/**\n * Returns the current block selection end. This value may be null, and it\n * may represent either a singular block selection or multi-selection end.\n * A selection is singular if its start and end match.\n *\n * @param {Object} state Global application state.\n *\n * @return {?string} Client ID of block selection end.\n */\nexport function getBlockSelectionEnd( state ) {\n\treturn state.selection.selectionEnd.clientId;\n}\n\n/**\n * Returns the number of blocks currently selected in the post.\n *\n * @param {Object} state Global application state.\n *\n * @return {number} Number of blocks selected in the post.\n */\nexport function getSelectedBlockCount( state ) {\n\tconst multiSelectedBlockCount =\n\t\tgetMultiSelectedBlockClientIds( state ).length;\n\n\tif ( multiSelectedBlockCount ) {\n\t\treturn multiSelectedBlockCount;\n\t}\n\n\treturn state.selection.selectionStart.clientId ? 1 : 0;\n}\n\n/**\n * Returns true if there is a single selected block, or false otherwise.\n *\n * @param {Object} state Editor state.\n *\n * @return {boolean} Whether a single block is selected.\n */\nexport function hasSelectedBlock( state ) {\n\tconst { selectionStart, selectionEnd } = state.selection;\n\treturn (\n\t\t!! selectionStart.clientId &&\n\t\tselectionStart.clientId === selectionEnd.clientId\n\t);\n}\n\n/**\n * Returns the currently selected block client ID, or null if there is no\n * selected block.\n *\n * @param {Object} state Editor state.\n *\n * @return {?string} Selected block client ID.\n */\nexport function getSelectedBlockClientId( state ) {\n\tconst { selectionStart, selectionEnd } = state.selection;\n\tconst { clientId } = selectionStart;\n\n\tif ( ! clientId || clientId !== selectionEnd.clientId ) {\n\t\treturn null;\n\t}\n\n\treturn clientId;\n}\n\n/**\n * Returns the currently selected block, or null if there is no selected block.\n *\n * @param {Object} state Global application state.\n *\n * @example\n *\n *```js\n * import { select } from '@wordpress/data'\n * import { store as blockEditorStore } from '@wordpress/block-editor'\n *\n * // Set initial active block client ID\n * let activeBlockClientId = null\n *\n * const getActiveBlockData = () => {\n * \tconst activeBlock = select(blockEditorStore).getSelectedBlock()\n *\n * \tif (activeBlock && activeBlock.clientId !== activeBlockClientId) {\n * \t\tactiveBlockClientId = activeBlock.clientId\n *\n * \t\t// Get active block name and attributes\n * \t\tconst activeBlockName = activeBlock.name\n * \t\tconst activeBlockAttributes = activeBlock.attributes\n *\n * \t\t// Log active block name and attributes\n * \t\tconsole.log(activeBlockName, activeBlockAttributes)\n * \t\t}\n * \t}\n *\n * \t// Subscribe to changes in the editor\n * \t// wp.data.subscribe(() => {\n * \t\t// getActiveBlockData()\n * \t// })\n *\n * \t// Update active block data on click\n * \t// onclick=\"getActiveBlockData()\"\n *```\n *\n * @return {?Object} Selected block.\n */\nexport function getSelectedBlock( state ) {\n\tconst clientId = getSelectedBlockClientId( state );\n\treturn clientId ? getBlock( state, clientId ) : null;\n}\n\n/**\n * Given a block client ID, returns the root block from which the block is\n * nested, an empty string for top-level blocks, or null if the block does not\n * exist.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block from which to find root client ID.\n *\n * @return {?string} Root client ID, if exists\n */\nexport function getBlockRootClientId( state, clientId ) {\n\treturn state.blocks.parents.get( clientId ) ?? null;\n}\n\n/**\n * Given a block client ID, returns the list of all its parents from top to bottom.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block from which to find root client ID.\n * @param {boolean} ascending Order results from bottom to top (true) or top to bottom (false).\n *\n * @return {Array} ClientIDs of the parent blocks.\n */\nexport const getBlockParents = createSelector(\n\t( state, clientId, ascending = false ) => {\n\t\tconst parents = [];\n\t\tlet current = clientId;\n\t\twhile ( ( current = state.blocks.parents.get( current ) ) ) {\n\t\t\tparents.push( current );\n\t\t}\n\n\t\tif ( ! parents.length ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\n\t\treturn ascending ? parents : parents.reverse();\n\t},\n\t( state ) => [ state.blocks.parents ]\n);\n\n/**\n * Given a block client ID and a block name, returns the list of all its parents\n * from top to bottom, filtered by the given name(s). For example, if passed\n * 'core/group' as the blockName, it will only return parents which are group\n * blocks. If passed `[ 'core/group', 'core/cover']`, as the blockName, it will\n * return parents which are group blocks and parents which are cover blocks.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block from which to find root client ID.\n * @param {string|string[]} blockName Block name(s) to filter.\n * @param {boolean} ascending Order results from bottom to top (true) or top to bottom (false).\n *\n * @return {Array} ClientIDs of the parent blocks.\n */\nexport const getBlockParentsByBlockName = createSelector(\n\t( state, clientId, blockName, ascending = false ) => {\n\t\tconst parents = getBlockParents( state, clientId, ascending );\n\t\tconst hasName = Array.isArray( blockName )\n\t\t\t? ( name ) => blockName.includes( name )\n\t\t\t: ( name ) => blockName === name;\n\t\treturn parents.filter( ( id ) => hasName( getBlockName( state, id ) ) );\n\t},\n\t( state ) => [ state.blocks.parents ]\n);\n/**\n * 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.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block from which to find root client ID.\n *\n * @return {string} Root client ID\n */\nexport function getBlockHierarchyRootClientId( state, clientId ) {\n\tlet current = clientId;\n\tlet parent;\n\tdo {\n\t\tparent = current;\n\t\tcurrent = state.blocks.parents.get( current );\n\t} while ( current );\n\treturn parent;\n}\n\n/**\n * Given a block client ID, returns the lowest common ancestor with selected client ID.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block from which to find common ancestor client ID.\n *\n * @return {string} Common ancestor client ID or undefined\n */\nexport function getLowestCommonAncestorWithSelectedBlock( state, clientId ) {\n\tconst selectedId = getSelectedBlockClientId( state );\n\tconst clientParents = [ ...getBlockParents( state, clientId ), clientId ];\n\tconst selectedParents = [\n\t\t...getBlockParents( state, selectedId ),\n\t\tselectedId,\n\t];\n\n\tlet lowestCommonAncestor;\n\n\tconst maxDepth = Math.min( clientParents.length, selectedParents.length );\n\tfor ( let index = 0; index < maxDepth; index++ ) {\n\t\tif ( clientParents[ index ] === selectedParents[ index ] ) {\n\t\t\tlowestCommonAncestor = clientParents[ index ];\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn lowestCommonAncestor;\n}\n\n/**\n * Returns the client ID of the block adjacent one at the given reference\n * startClientId and modifier directionality. Defaults start startClientId to\n * the selected block, and direction as next block. Returns null if there is no\n * adjacent block.\n *\n * @param {Object} state Editor state.\n * @param {?string} startClientId Optional client ID of block from which to\n * search.\n * @param {?number} modifier Directionality multiplier (1 next, -1\n * previous).\n *\n * @return {?string} Return the client ID of the block, or null if none exists.\n */\nexport function getAdjacentBlockClientId( state, startClientId, modifier = 1 ) {\n\t// Default to selected block.\n\tif ( startClientId === undefined ) {\n\t\tstartClientId = getSelectedBlockClientId( state );\n\t}\n\n\t// Try multi-selection starting at extent based on modifier.\n\tif ( startClientId === undefined ) {\n\t\tif ( modifier < 0 ) {\n\t\t\tstartClientId = getFirstMultiSelectedBlockClientId( state );\n\t\t} else {\n\t\t\tstartClientId = getLastMultiSelectedBlockClientId( state );\n\t\t}\n\t}\n\n\t// Validate working start client ID.\n\tif ( ! startClientId ) {\n\t\treturn null;\n\t}\n\n\t// Retrieve start block root client ID, being careful to allow the falsey\n\t// empty string top-level root by explicitly testing against null.\n\tconst rootClientId = getBlockRootClientId( state, startClientId );\n\tif ( rootClientId === null ) {\n\t\treturn null;\n\t}\n\n\tconst { order } = state.blocks;\n\tconst orderSet = order.get( rootClientId );\n\tconst index = orderSet.indexOf( startClientId );\n\tconst nextIndex = index + 1 * modifier;\n\n\t// Block was first in set and we're attempting to get previous.\n\tif ( nextIndex < 0 ) {\n\t\treturn null;\n\t}\n\n\t// Block was last in set and we're attempting to get next.\n\tif ( nextIndex === orderSet.length ) {\n\t\treturn null;\n\t}\n\n\t// Assume incremented index is within the set.\n\treturn orderSet[ nextIndex ];\n}\n\n/**\n * Returns the previous block's client ID from the given reference start ID.\n * Defaults start to the selected block. Returns null if there is no previous\n * block.\n *\n * @param {Object} state Editor state.\n * @param {?string} startClientId Optional client ID of block from which to\n * search.\n *\n * @return {?string} Adjacent block's client ID, or null if none exists.\n */\nexport function getPreviousBlockClientId( state, startClientId ) {\n\treturn getAdjacentBlockClientId( state, startClientId, -1 );\n}\n\n/**\n * Returns the next block's client ID from the given reference start ID.\n * Defaults start to the selected block. Returns null if there is no next\n * block.\n *\n * @param {Object} state Editor state.\n * @param {?string} startClientId Optional client ID of block from which to\n * search.\n *\n * @return {?string} Adjacent block's client ID, or null if none exists.\n */\nexport function getNextBlockClientId( state, startClientId ) {\n\treturn getAdjacentBlockClientId( state, startClientId, 1 );\n}\n\n/**\n * Returns the initial caret position for the selected block.\n * This position is to used to position the caret properly when the selected block changes.\n * If the current block is not a RichText, having initial position set to 0 means \"focus block\"\n *\n * @param {Object} state Global application state.\n *\n * @return {0|-1|null} Initial position.\n */\nexport function getSelectedBlocksInitialCaretPosition( state ) {\n\treturn state.initialPosition;\n}\n\n/**\n * Returns the current selection set of block client IDs (multiselection or single selection).\n *\n * @param {Object} state Editor state.\n *\n * @return {Array} Multi-selected block client IDs.\n */\nexport const getSelectedBlockClientIds = createSelector(\n\t( state ) => {\n\t\tconst { selectionStart, selectionEnd } = state.selection;\n\n\t\tif ( ! selectionStart.clientId || ! selectionEnd.clientId ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\n\t\tif ( selectionStart.clientId === selectionEnd.clientId ) {\n\t\t\treturn [ selectionStart.clientId ];\n\t\t}\n\n\t\t// Retrieve root client ID to aid in retrieving relevant nested block\n\t\t// order, being careful to allow the falsey empty string top-level root\n\t\t// by explicitly testing against null.\n\t\tconst rootClientId = getBlockRootClientId(\n\t\t\tstate,\n\t\t\tselectionStart.clientId\n\t\t);\n\n\t\tif ( rootClientId === null ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\n\t\tconst blockOrder = getBlockOrder( state, rootClientId );\n\t\tconst startIndex = blockOrder.indexOf( selectionStart.clientId );\n\t\tconst endIndex = blockOrder.indexOf( selectionEnd.clientId );\n\n\t\tif ( startIndex > endIndex ) {\n\t\t\treturn blockOrder.slice( endIndex, startIndex + 1 );\n\t\t}\n\n\t\treturn blockOrder.slice( startIndex, endIndex + 1 );\n\t},\n\t( state ) => [\n\t\tstate.blocks.order,\n\t\tstate.selection.selectionStart.clientId,\n\t\tstate.selection.selectionEnd.clientId,\n\t]\n);\n\n/**\n * Returns the current multi-selection set of block client IDs, or an empty\n * array if there is no multi-selection.\n *\n * @param {Object} state Editor state.\n *\n * @return {Array} Multi-selected block client IDs.\n */\nexport function getMultiSelectedBlockClientIds( state ) {\n\tconst { selectionStart, selectionEnd } = state.selection;\n\n\tif ( selectionStart.clientId === selectionEnd.clientId ) {\n\t\treturn EMPTY_ARRAY;\n\t}\n\n\treturn getSelectedBlockClientIds( state );\n}\n\n/**\n * Returns the current multi-selection set of blocks, or an empty array if\n * there is no multi-selection.\n *\n * @param {Object} state Editor state.\n *\n * @return {Array} Multi-selected block objects.\n */\nexport const getMultiSelectedBlocks = createSelector(\n\t( state ) => {\n\t\tconst multiSelectedBlockClientIds =\n\t\t\tgetMultiSelectedBlockClientIds( state );\n\t\tif ( ! multiSelectedBlockClientIds.length ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\n\t\treturn multiSelectedBlockClientIds.map( ( clientId ) =>\n\t\t\tgetBlock( state, clientId )\n\t\t);\n\t},\n\t( state ) => [\n\t\t...getSelectedBlockClientIds.getDependants( state ),\n\t\tstate.blocks.byClientId,\n\t\tstate.blocks.order,\n\t\tstate.blocks.attributes,\n\t]\n);\n\n/**\n * Returns the client ID of the first block in the multi-selection set, or null\n * if there is no multi-selection.\n *\n * @param {Object} state Editor state.\n *\n * @return {?string} First block client ID in the multi-selection set.\n */\nexport function getFirstMultiSelectedBlockClientId( state ) {\n\treturn getMultiSelectedBlockClientIds( state )[ 0 ] || null;\n}\n\n/**\n * Returns the client ID of the last block in the multi-selection set, or null\n * if there is no multi-selection.\n *\n * @param {Object} state Editor state.\n *\n * @return {?string} Last block client ID in the multi-selection set.\n */\nexport function getLastMultiSelectedBlockClientId( state ) {\n\tconst selectedClientIds = getMultiSelectedBlockClientIds( state );\n\treturn selectedClientIds[ selectedClientIds.length - 1 ] || null;\n}\n\n/**\n * Returns true if a multi-selection exists, and the block corresponding to the\n * specified client ID is the first block of the multi-selection set, or false\n * otherwise.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {boolean} Whether block is first in multi-selection.\n */\nexport function isFirstMultiSelectedBlock( state, clientId ) {\n\treturn getFirstMultiSelectedBlockClientId( state ) === clientId;\n}\n\n/**\n * Returns true if the client ID occurs within the block multi-selection, or\n * false otherwise.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {boolean} Whether block is in multi-selection set.\n */\nexport function isBlockMultiSelected( state, clientId ) {\n\treturn getMultiSelectedBlockClientIds( state ).indexOf( clientId ) !== -1;\n}\n\n/**\n * Returns true if an ancestor of the block is multi-selected, or false\n * otherwise.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {boolean} Whether an ancestor of the block is in multi-selection\n * set.\n */\nexport const isAncestorMultiSelected = createSelector(\n\t( state, clientId ) => {\n\t\tlet ancestorClientId = clientId;\n\t\tlet isMultiSelected = false;\n\t\twhile ( ancestorClientId && ! isMultiSelected ) {\n\t\t\tancestorClientId = getBlockRootClientId( state, ancestorClientId );\n\t\t\tisMultiSelected = isBlockMultiSelected( state, ancestorClientId );\n\t\t}\n\t\treturn isMultiSelected;\n\t},\n\t( state ) => [\n\t\tstate.blocks.order,\n\t\tstate.selection.selectionStart.clientId,\n\t\tstate.selection.selectionEnd.clientId,\n\t]\n);\n\n/**\n * Returns the client ID of the block which begins the multi-selection set, or\n * null if there is no multi-selection.\n *\n * This is not necessarily the first client ID in the selection.\n *\n * @see getFirstMultiSelectedBlockClientId\n *\n * @param {Object} state Editor state.\n *\n * @return {?string} Client ID of block beginning multi-selection.\n */\nexport function getMultiSelectedBlocksStartClientId( state ) {\n\tconst { selectionStart, selectionEnd } = state.selection;\n\n\tif ( selectionStart.clientId === selectionEnd.clientId ) {\n\t\treturn null;\n\t}\n\n\treturn selectionStart.clientId || null;\n}\n\n/**\n * Returns the client ID of the block which ends the multi-selection set, or\n * null if there is no multi-selection.\n *\n * This is not necessarily the last client ID in the selection.\n *\n * @see getLastMultiSelectedBlockClientId\n *\n * @param {Object} state Editor state.\n *\n * @return {?string} Client ID of block ending multi-selection.\n */\nexport function getMultiSelectedBlocksEndClientId( state ) {\n\tconst { selectionStart, selectionEnd } = state.selection;\n\n\tif ( selectionStart.clientId === selectionEnd.clientId ) {\n\t\treturn null;\n\t}\n\n\treturn selectionEnd.clientId || null;\n}\n\n/**\n * Returns true if the selection is not partial.\n *\n * @param {Object} state Editor state.\n *\n * @return {boolean} Whether the selection is mergeable.\n */\nexport function __unstableIsFullySelected( state ) {\n\tconst selectionAnchor = getSelectionStart( state );\n\tconst selectionFocus = getSelectionEnd( state );\n\treturn (\n\t\t! selectionAnchor.attributeKey &&\n\t\t! selectionFocus.attributeKey &&\n\t\ttypeof selectionAnchor.offset === 'undefined' &&\n\t\ttypeof selectionFocus.offset === 'undefined'\n\t);\n}\n\n/**\n * Returns true if the selection is collapsed.\n *\n * @param {Object} state Editor state.\n *\n * @return {boolean} Whether the selection is collapsed.\n */\nexport function __unstableIsSelectionCollapsed( state ) {\n\tconst selectionAnchor = getSelectionStart( state );\n\tconst selectionFocus = getSelectionEnd( state );\n\treturn (\n\t\t!! selectionAnchor &&\n\t\t!! selectionFocus &&\n\t\tselectionAnchor.clientId === selectionFocus.clientId &&\n\t\tselectionAnchor.attributeKey === selectionFocus.attributeKey &&\n\t\tselectionAnchor.offset === selectionFocus.offset\n\t);\n}\n\nexport function __unstableSelectionHasUnmergeableBlock( state ) {\n\treturn getSelectedBlockClientIds( state ).some( ( clientId ) => {\n\t\tconst blockName = getBlockName( state, clientId );\n\t\tconst blockType = getBlockType( blockName );\n\t\treturn ! blockType.merge;\n\t} );\n}\n\n/**\n * Check whether the selection is mergeable.\n *\n * @param {Object} state Editor state.\n * @param {boolean} isForward Whether to merge forwards.\n *\n * @return {boolean} Whether the selection is mergeable.\n */\nexport function __unstableIsSelectionMergeable( state, isForward ) {\n\tconst selectionAnchor = getSelectionStart( state );\n\tconst selectionFocus = getSelectionEnd( state );\n\n\t// It's not mergeable if the start and end are within the same block.\n\tif ( selectionAnchor.clientId === selectionFocus.clientId ) {\n\t\treturn false;\n\t}\n\n\t// It's not mergeable if there's no rich text selection.\n\tif (\n\t\t! selectionAnchor.attributeKey ||\n\t\t! selectionFocus.attributeKey ||\n\t\ttypeof selectionAnchor.offset === 'undefined' ||\n\t\ttypeof selectionFocus.offset === 'undefined'\n\t) {\n\t\treturn false;\n\t}\n\n\tconst anchorRootClientId = getBlockRootClientId(\n\t\tstate,\n\t\tselectionAnchor.clientId\n\t);\n\tconst focusRootClientId = getBlockRootClientId(\n\t\tstate,\n\t\tselectionFocus.clientId\n\t);\n\n\t// It's not mergeable if the selection doesn't start and end in the same\n\t// block list. Maybe in the future it should be allowed.\n\tif ( anchorRootClientId !== focusRootClientId ) {\n\t\treturn false;\n\t}\n\n\tconst blockOrder = getBlockOrder( state, anchorRootClientId );\n\tconst anchorIndex = blockOrder.indexOf( selectionAnchor.clientId );\n\tconst focusIndex = blockOrder.indexOf( selectionFocus.clientId );\n\n\t// Reassign selection start and end based on order.\n\tlet selectionStart, selectionEnd;\n\n\tif ( anchorIndex > focusIndex ) {\n\t\tselectionStart = selectionFocus;\n\t\tselectionEnd = selectionAnchor;\n\t} else {\n\t\tselectionStart = selectionAnchor;\n\t\tselectionEnd = selectionFocus;\n\t}\n\n\tconst targetBlockClientId = isForward\n\t\t? selectionEnd.clientId\n\t\t: selectionStart.clientId;\n\tconst blockToMergeClientId = isForward\n\t\t? selectionStart.clientId\n\t\t: selectionEnd.clientId;\n\n\tconst targetBlockName = getBlockName( state, targetBlockClientId );\n\tconst targetBlockType = getBlockType( targetBlockName );\n\n\tif ( ! targetBlockType.merge ) {\n\t\treturn false;\n\t}\n\n\tconst blockToMerge = getBlock( state, blockToMergeClientId );\n\n\t// It's mergeable if the blocks are of the same type.\n\tif ( blockToMerge.name === targetBlockName ) {\n\t\treturn true;\n\t}\n\n\t// If the blocks are of a different type, try to transform the block being\n\t// merged into the same type of block.\n\tconst blocksToMerge = switchToBlockType( blockToMerge, targetBlockName );\n\n\treturn blocksToMerge && blocksToMerge.length;\n}\n\n/**\n * Get partial selected blocks with their content updated\n * based on the selection.\n *\n * @param {Object} state Editor state.\n *\n * @return {Object[]} Updated partial selected blocks.\n */\nexport const __unstableGetSelectedBlocksWithPartialSelection = ( state ) => {\n\tconst selectionAnchor = getSelectionStart( state );\n\tconst selectionFocus = getSelectionEnd( state );\n\n\tif ( selectionAnchor.clientId === selectionFocus.clientId ) {\n\t\treturn EMPTY_ARRAY;\n\t}\n\n\t// Can't split if the selection is not set.\n\tif (\n\t\t! selectionAnchor.attributeKey ||\n\t\t! selectionFocus.attributeKey ||\n\t\ttypeof selectionAnchor.offset === 'undefined' ||\n\t\ttypeof selectionFocus.offset === 'undefined'\n\t) {\n\t\treturn EMPTY_ARRAY;\n\t}\n\n\tconst anchorRootClientId = getBlockRootClientId(\n\t\tstate,\n\t\tselectionAnchor.clientId\n\t);\n\tconst focusRootClientId = getBlockRootClientId(\n\t\tstate,\n\t\tselectionFocus.clientId\n\t);\n\n\t// It's not splittable if the selection doesn't start and end in the same\n\t// block list. Maybe in the future it should be allowed.\n\tif ( anchorRootClientId !== focusRootClientId ) {\n\t\treturn EMPTY_ARRAY;\n\t}\n\n\tconst blockOrder = getBlockOrder( state, anchorRootClientId );\n\tconst anchorIndex = blockOrder.indexOf( selectionAnchor.clientId );\n\tconst focusIndex = blockOrder.indexOf( selectionFocus.clientId );\n\n\t// Reassign selection start and end based on order.\n\tconst [ selectionStart, selectionEnd ] =\n\t\tanchorIndex > focusIndex\n\t\t\t? [ selectionFocus, selectionAnchor ]\n\t\t\t: [ selectionAnchor, selectionFocus ];\n\n\tconst blockA = getBlock( state, selectionStart.clientId );\n\tconst blockB = getBlock( state, selectionEnd.clientId );\n\n\tconst htmlA = blockA.attributes[ selectionStart.attributeKey ];\n\tconst htmlB = blockB.attributes[ selectionEnd.attributeKey ];\n\n\tlet valueA = create( { html: htmlA } );\n\tlet valueB = create( { html: htmlB } );\n\n\tvalueA = remove( valueA, 0, selectionStart.offset );\n\tvalueB = remove( valueB, selectionEnd.offset, valueB.text.length );\n\n\treturn [\n\t\t{\n\t\t\t...blockA,\n\t\t\tattributes: {\n\t\t\t\t...blockA.attributes,\n\t\t\t\t[ selectionStart.attributeKey ]: toHTMLString( {\n\t\t\t\t\tvalue: valueA,\n\t\t\t\t} ),\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\t...blockB,\n\t\t\tattributes: {\n\t\t\t\t...blockB.attributes,\n\t\t\t\t[ selectionEnd.attributeKey ]: toHTMLString( {\n\t\t\t\t\tvalue: valueB,\n\t\t\t\t} ),\n\t\t\t},\n\t\t},\n\t];\n};\n\n/**\n * Returns an array containing all block client IDs in the editor in the order\n * they appear. Optionally accepts a root client ID of the block list for which\n * the order should be returned, defaulting to the top-level block order.\n *\n * @param {Object} state Editor state.\n * @param {?string} rootClientId Optional root client ID of block list.\n *\n * @return {Array} Ordered client IDs of editor blocks.\n */\nexport function getBlockOrder( state, rootClientId ) {\n\treturn state.blocks.order.get( rootClientId || '' ) || EMPTY_ARRAY;\n}\n\n/**\n * Returns the index at which the block corresponding to the specified client\n * ID occurs within the block order, or `-1` if the block does not exist.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {number} Index at which block exists in order.\n */\nexport function getBlockIndex( state, clientId ) {\n\tconst rootClientId = getBlockRootClientId( state, clientId );\n\treturn getBlockOrder( state, rootClientId ).indexOf( clientId );\n}\n\n/**\n * Returns true if the block corresponding to the specified client ID is\n * currently selected and no multi-selection exists, or false otherwise.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {boolean} Whether block is selected and multi-selection exists.\n */\nexport function isBlockSelected( state, clientId ) {\n\tconst { selectionStart, selectionEnd } = state.selection;\n\n\tif ( selectionStart.clientId !== selectionEnd.clientId ) {\n\t\treturn false;\n\t}\n\n\treturn selectionStart.clientId === clientId;\n}\n\n/**\n * Returns true if one of the block's inner blocks is selected.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n * @param {boolean} deep Perform a deep check.\n *\n * @return {boolean} Whether the block has an inner block selected\n */\nexport function hasSelectedInnerBlock( state, clientId, deep = false ) {\n\tconst selectedBlockClientIds = getSelectedBlockClientIds( state );\n\n\tif ( ! selectedBlockClientIds.length ) {\n\t\treturn false;\n\t}\n\n\tif ( deep ) {\n\t\treturn selectedBlockClientIds.some( ( id ) =>\n\t\t\t// Pass true because we don't care about order and it's more\n\t\t\t// performant.\n\t\t\tgetBlockParents( state, id, true ).includes( clientId )\n\t\t);\n\t}\n\n\treturn selectedBlockClientIds.some(\n\t\t( id ) => getBlockRootClientId( state, id ) === clientId\n\t);\n}\n\n/**\n * Returns true if one of the block's inner blocks is dragged.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n * @param {boolean} deep Perform a deep check.\n *\n * @return {boolean} Whether the block has an inner block dragged\n */\nexport function hasDraggedInnerBlock( state, clientId, deep = false ) {\n\treturn getBlockOrder( state, clientId ).some(\n\t\t( innerClientId ) =>\n\t\t\tisBlockBeingDragged( state, innerClientId ) ||\n\t\t\t( deep && hasDraggedInnerBlock( state, innerClientId, deep ) )\n\t);\n}\n\n/**\n * Returns true if the block corresponding to the specified client ID is\n * currently selected but isn't the last of the selected blocks. Here \"last\"\n * refers to the block sequence in the document, _not_ the sequence of\n * multi-selection, which is why `state.selectionEnd` isn't used.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {boolean} Whether block is selected and not the last in the\n * selection.\n */\nexport function isBlockWithinSelection( state, clientId ) {\n\tif ( ! clientId ) {\n\t\treturn false;\n\t}\n\n\tconst clientIds = getMultiSelectedBlockClientIds( state );\n\tconst index = clientIds.indexOf( clientId );\n\treturn index > -1 && index < clientIds.length - 1;\n}\n\n/**\n * Returns true if a multi-selection has been made, or false otherwise.\n *\n * @param {Object} state Editor state.\n *\n * @return {boolean} Whether multi-selection has been made.\n */\nexport function hasMultiSelection( state ) {\n\tconst { selectionStart, selectionEnd } = state.selection;\n\treturn selectionStart.clientId !== selectionEnd.clientId;\n}\n\n/**\n * Whether in the process of multi-selecting or not. This flag is only true\n * while the multi-selection is being selected (by mouse move), and is false\n * once the multi-selection has been settled.\n *\n * @see hasMultiSelection\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} True if multi-selecting, false if not.\n */\nexport function isMultiSelecting( state ) {\n\treturn state.isMultiSelecting;\n}\n\n/**\n * Selector that returns if multi-selection is enabled or not.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} True if it should be possible to multi-select blocks, false if multi-selection is disabled.\n */\nexport function isSelectionEnabled( state ) {\n\treturn state.isSelectionEnabled;\n}\n\n/**\n * Returns the block's editing mode, defaulting to \"visual\" if not explicitly\n * assigned.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId Block client ID.\n *\n * @return {Object} Block editing mode.\n */\nexport function getBlockMode( state, clientId ) {\n\treturn state.blocksMode[ clientId ] || 'visual';\n}\n\n/**\n * Returns true if the user is typing, or false otherwise.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether user is typing.\n */\nexport function isTyping( state ) {\n\treturn state.isTyping;\n}\n\n/**\n * Returns true if the user is dragging blocks, or false otherwise.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether user is dragging blocks.\n */\nexport function isDraggingBlocks( state ) {\n\treturn !! state.draggedBlocks.length;\n}\n\n/**\n * Returns the client ids of any blocks being directly dragged.\n *\n * This does not include children of a parent being dragged.\n *\n * @param {Object} state Global application state.\n *\n * @return {string[]} Array of dragged block client ids.\n */\nexport function getDraggedBlockClientIds( state ) {\n\treturn state.draggedBlocks;\n}\n\n/**\n * Returns whether the block is being dragged.\n *\n * Only returns true if the block is being directly dragged,\n * not if the block is a child of a parent being dragged.\n * See `isAncestorBeingDragged` for child blocks.\n *\n * @param {Object} state Global application state.\n * @param {string} clientId Client id for block to check.\n *\n * @return {boolean} Whether the block is being dragged.\n */\nexport function isBlockBeingDragged( state, clientId ) {\n\treturn state.draggedBlocks.includes( clientId );\n}\n\n/**\n * Returns whether a parent/ancestor of the block is being dragged.\n *\n * @param {Object} state Global application state.\n * @param {string} clientId Client id for block to check.\n *\n * @return {boolean} Whether the block's ancestor is being dragged.\n */\nexport function isAncestorBeingDragged( state, clientId ) {\n\t// Return early if no blocks are being dragged rather than\n\t// the more expensive check for parents.\n\tif ( ! isDraggingBlocks( state ) ) {\n\t\treturn false;\n\t}\n\n\tconst parents = getBlockParents( state, clientId );\n\treturn parents.some( ( parentClientId ) =>\n\t\tisBlockBeingDragged( state, parentClientId )\n\t);\n}\n\n/**\n * Returns true if the caret is within formatted text, or false otherwise.\n *\n * @deprecated\n *\n * @return {boolean} Whether the caret is within formatted text.\n */\nexport function isCaretWithinFormattedText() {\n\tdeprecated(\n\t\t'wp.data.select( \"core/block-editor\" ).isCaretWithinFormattedText',\n\t\t{\n\t\t\tsince: '6.1',\n\t\t\tversion: '6.3',\n\t\t}\n\t);\n\n\treturn false;\n}\n\n/**\n * Returns the location of the insertion cue. Defaults to the last index.\n *\n * @param {Object} state Editor state.\n *\n * @return {Object} Insertion point object with `rootClientId`, `index`.\n */\nexport const getBlockInsertionPoint = createSelector(\n\t( state ) => {\n\t\tlet rootClientId, index;\n\n\t\tconst {\n\t\t\tinsertionCue,\n\t\t\tselection: { selectionEnd },\n\t\t} = state;\n\t\tif ( insertionCue !== null ) {\n\t\t\treturn insertionCue;\n\t\t}\n\n\t\tconst { clientId } = selectionEnd;\n\n\t\tif ( clientId ) {\n\t\t\trootClientId = getBlockRootClientId( state, clientId ) || undefined;\n\t\t\tindex = getBlockIndex( state, selectionEnd.clientId ) + 1;\n\t\t} else {\n\t\t\tindex = getBlockOrder( state ).length;\n\t\t}\n\n\t\treturn { rootClientId, index };\n\t},\n\t( state ) => [\n\t\tstate.insertionCue,\n\t\tstate.selection.selectionEnd.clientId,\n\t\tstate.blocks.parents,\n\t\tstate.blocks.order,\n\t]\n);\n\n/**\n * Returns true if the block insertion point is visible.\n *\n * @param {Object} state Global application state.\n *\n * @return {?boolean} Whether the insertion point is visible or not.\n */\nexport function isBlockInsertionPointVisible( state ) {\n\treturn state.insertionCue !== null;\n}\n\n/**\n * Returns whether the blocks matches the template or not.\n *\n * @param {boolean} state\n * @return {?boolean} Whether the template is valid or not.\n */\nexport function isValidTemplate( state ) {\n\treturn state.template.isValid;\n}\n\n/**\n * Returns the defined block template\n *\n * @param {boolean} state\n *\n * @return {?Array} Block Template.\n */\nexport function getTemplate( state ) {\n\treturn state.settings.template;\n}\n\n/**\n * Returns the defined block template lock. Optionally accepts a root block\n * client ID as context, otherwise defaulting to the global context.\n *\n * @param {Object} state Editor state.\n * @param {?string} rootClientId Optional block root client ID.\n *\n * @return {string|false} Block Template Lock\n */\nexport function getTemplateLock( state, rootClientId ) {\n\tif ( ! rootClientId ) {\n\t\treturn state.settings.templateLock ?? false;\n\t}\n\n\tconst blockListTemplateLock = getBlockListSettings(\n\t\tstate,\n\t\trootClientId\n\t)?.templateLock;\n\n\t// If this is a contentOnly template locked block that's in the process\n\t// of being edited, consider the template lock as temporarily inactive.\n\tif (\n\t\tblockListTemplateLock === 'contentOnly' &&\n\t\tstate.editedContentOnlySection === rootClientId\n\t) {\n\t\treturn false;\n\t}\n\n\treturn blockListTemplateLock ?? false;\n}\n\n/**\n * Determines if the given block type is visible in the inserter.\n * Note that this is different than whether a block is allowed to be inserted.\n * In some cases, the block is not allowed in a given position but\n * it should still be visible in the inserter to be able to add it\n * to a different position.\n *\n * @param {Object} state Editor state.\n * @param {string|Object} blockNameOrType The block type object, e.g., the response\n * from the block directory; or a string name of\n * an installed block type, e.g.' core/paragraph'.\n * @p