Files
CHIEFSOFT\ameye e9e5c0546c first commit
2023-11-30 13:20:54 -05:00

20 lines
709 B
React

const { findIndex } = window.lodash;
/**
* Returns the considered adjacent to that of the specified `clientId` for
* resizing consideration. Adjacent blocks are those occurring after, except
* when the given block is the last block in the set. For the last block, the
* behavior is reversed.
*
* @param {WPBlock[]} blocks Block objects.
* @param {string} clientId Client ID to consider for adjacent blocks.
*
* @return {WPBlock[]} Adjacent block objects.
*/
export function getAdjacentBlocks( blocks, clientId ) {
const index = findIndex( blocks, { clientId } );
const isLastBlock = index === blocks.length - 1;
return isLastBlock ? blocks.slice( 0, index ) : blocks.slice( index + 1 );
}