From ec59ed1acbd7a4f18d824226451767dd56152d82 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Wed, 2 Oct 2024 11:58:52 +0200 Subject: [PATCH] Combine into one selector --- .../src/store/private-selectors.js | 47 ------------------- packages/block-editor/src/store/selectors.js | 37 +++++++++++++-- 2 files changed, 34 insertions(+), 50 deletions(-) diff --git a/packages/block-editor/src/store/private-selectors.js b/packages/block-editor/src/store/private-selectors.js index b7f7951c40701..eeb987fc00f61 100644 --- a/packages/block-editor/src/store/private-selectors.js +++ b/packages/block-editor/src/store/private-selectors.js @@ -7,7 +7,6 @@ import { createSelector, createRegistrySelector } from '@wordpress/data'; * Internal dependencies */ import { - getBlockAttributes, getBlockOrder, getBlockParents, getBlockEditingMode, @@ -18,7 +17,6 @@ import { getClientIdsWithDescendants, isNavigationMode, getBlockRootClientId, - __unstableGetEditorMode, } from './selectors'; import { checkAllowListRecursive, @@ -687,51 +685,6 @@ export function getInsertionPoint( state ) { return state.insertionPoint; } -/** - * Retrieves the editing mode of a pattern block and its children. - * - * @param {Object} state Global application state. - * @param {string} clientId The block client ID. - * - * @return {string} The block editing mode. - */ -export function getPatternBlockEditingMode( state, clientId ) { - const parentPatternCount = getParentPatternCount( state, clientId ); - - // If there are no parent patterns, use the block's own editing mode. - if ( parentPatternCount === 0 ) { - return state.blockEditingModes.get( clientId ); - } - - // Disable nested patterns. - if ( parentPatternCount > 1 ) { - return 'disabled'; - } - - // Make the outer pattern block content only mode. - if ( - getBlockName( state, clientId ) === 'core/block' && - parentPatternCount === 0 - ) { - return 'contentOnly'; - } - - // Disable pattern content in zoom-out mode. - const _isZoomOut = __unstableGetEditorMode( state ) === 'zoom-out'; - if ( _isZoomOut ) { - return 'disabled'; - } - - // If the block has a binding of any kind, allow content only editing. - const attributes = getBlockAttributes( state, clientId ); - if ( Object.keys( attributes.metadata?.bindings ?? {} )?.length > 0 ) { - return 'contentOnly'; - } - - // Otherwise, the block is part of the pattern source and should not be editable. - return 'disabled'; -} - /** * Retrieves the number of parent pattern blocks. * diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index bb1973b64346b..4a246de94ccc6 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -41,7 +41,6 @@ import { isSectionBlock, getParentSectionBlock, getParentPatternCount, - getPatternBlockEditingMode, } from './private-selectors'; /** @@ -2974,8 +2973,40 @@ export const getBlockEditingMode = createRegistrySelector( clientId = ''; } - if ( getParentPatternCount( state, clientId ) > 0 ) { - return getPatternBlockEditingMode( state, clientId ); + // Handle pattern blocks (core/block) and the content of those blocks. + const parentPatternCount = getParentPatternCount( state, clientId ); + if ( parentPatternCount > 0 ) { + // Disable nested patterns. + if ( parentPatternCount > 1 ) { + return 'disabled'; + } + + // Make the outer pattern block content only mode. + if ( + getBlockName( state, clientId ) === 'core/block' && + parentPatternCount === 0 + ) { + return 'contentOnly'; + } + + // Disable pattern content editing in zoom-out mode. + const _isZoomOut = + __unstableGetEditorMode( state ) === 'zoom-out'; + if ( _isZoomOut ) { + return 'disabled'; + } + + // If the block has a binding of any kind, allow content only editing. + const attributes = getBlockAttributes( state, clientId ); + if ( + Object.keys( attributes.metadata?.bindings ?? {} )?.length > + 0 + ) { + return 'contentOnly'; + } + + // Otherwise, the block is part of the pattern source and should not be editable. + return 'disabled'; } // In zoom-out mode, override the behavior set by