Skip to content

Commit

Permalink
Update canMoveBlock selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jun 14, 2024
1 parent efa14f7 commit f86afbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 0 additions & 2 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ _Parameters_

- _state_ `Object`: Editor state.
- _clientId_ `string`: The block client Id.
- _rootClientId_ `?string`: Optional root client ID of block list.

_Returns_

Expand All @@ -95,7 +94,6 @@ _Parameters_

- _state_ `Object`: Editor state.
- _clientIds_ `string`: The block client IDs to be moved.
- _rootClientId_ `?string`: Optional root client ID of block list.

_Returns_

Expand Down
20 changes: 9 additions & 11 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1749,20 +1749,21 @@ export function canRemoveBlocks( state, clientIds ) {
/**
* Determines if the given block is allowed to be moved.
*
* @param {Object} state Editor state.
* @param {string} clientId The block client Id.
* @param {?string} rootClientId Optional root client ID of block list.
* @param {Object} state Editor state.
* @param {string} clientId The block client Id.
*
* @return {boolean | undefined} Whether the given block is allowed to be moved.
*/
export function canMoveBlock( state, clientId, rootClientId = null ) {
export function canMoveBlock( state, clientId ) {
const attributes = getBlockAttributes( state, clientId );
if ( attributes === null ) {
return true;
}
if ( attributes.lock?.move !== undefined ) {
return ! attributes.lock.move;
}

const rootClientId = getBlockRootClientId( state, clientId );
if ( getTemplateLock( state, rootClientId ) === 'all' ) {
return false;
}
Expand All @@ -1772,16 +1773,13 @@ export function canMoveBlock( state, clientId, rootClientId = null ) {
/**
* Determines if the given blocks are allowed to be moved.
*
* @param {Object} state Editor state.
* @param {string} clientIds The block client IDs to be moved.
* @param {?string} rootClientId Optional root client ID of block list.
* @param {Object} state Editor state.
* @param {string} clientIds The block client IDs to be moved.
*
* @return {boolean} Whether the given blocks are allowed to be moved.
*/
export function canMoveBlocks( state, clientIds, rootClientId = null ) {
return clientIds.every( ( clientId ) =>
canMoveBlock( state, clientId, rootClientId )
);
export function canMoveBlocks( state, clientIds ) {
return clientIds.every( ( clientId ) => canMoveBlock( state, clientId ) );
}

/**
Expand Down

0 comments on commit f86afbf

Please sign in to comment.