Skip to content

Commit 7cf8417

Browse files
draganescucbravobernal
authored andcommitted
bring over two private selectors from trunk the fix depends on
1 parent 53fd74c commit 7cf8417

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

packages/block-editor/src/store/private-selectors.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
getBlockName,
1616
getTemplateLock,
1717
getClientIdsWithDescendants,
18+
isNavigationMode,
1819
} from './selectors';
1920
import {
2021
checkAllowListRecursive,
@@ -580,3 +581,40 @@ export function getZoomLevel( state ) {
580581
export function isZoomOut( state ) {
581582
return getZoomLevel( state ) < 100;
582583
}
584+
585+
/**
586+
* Retrieves the client ID of the parent section block.
587+
*
588+
* @param {Object} state Global application state.
589+
* @param {string} clientId Client Id of the block.
590+
*
591+
* @return {?string} Client ID of the ancestor block that is content locking the block.
592+
*/
593+
export const getParentSectionBlock = ( state, clientId ) => {
594+
let current = clientId;
595+
let result;
596+
while ( ! result && ( current = state.blocks.parents.get( current ) ) ) {
597+
if ( isSectionBlock( state, current ) ) {
598+
result = current;
599+
}
600+
}
601+
return result;
602+
};
603+
604+
/**
605+
* Retrieves the client ID is a content locking parent
606+
*
607+
* @param {Object} state Global application state.
608+
* @param {string} clientId Client Id of the block.
609+
*
610+
* @return {boolean} Whether the block is a content locking parent.
611+
*/
612+
export function isSectionBlock( state, clientId ) {
613+
const sectionRootClientId = getSectionRootClientId( state );
614+
const sectionClientIds = getBlockOrder( state, sectionRootClientId );
615+
return (
616+
getBlockName( state, clientId ) === 'core/block' ||
617+
getTemplateLock( state, clientId ) === 'contentOnly' ||
618+
( isNavigationMode( state ) && sectionClientIds.includes( clientId ) )
619+
);
620+
}

0 commit comments

Comments
 (0)