From eb6171688f7f76e6e7506d3d35bc427a0a0eaa5c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Tue, 6 Jun 2023 15:07:42 +0100 Subject: [PATCH] Allow setting mode with specific clientId --- .../src/components/block-editing-mode/index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/components/block-editing-mode/index.js b/packages/block-editor/src/components/block-editing-mode/index.js index 0347a9b7378d0..bdd6ff971c1a4 100644 --- a/packages/block-editor/src/components/block-editing-mode/index.js +++ b/packages/block-editor/src/components/block-editing-mode/index.js @@ -40,13 +40,20 @@ import { BlockListBlockContext } from '../block-list/block-list-block-context'; * * If called outside of a block context, the mode is applied to all blocks. * - * @param {?BlockEditingMode} mode The editing mode to apply. If undefined, the - * current editing mode is not changed. + * @param {?BlockEditingMode} mode The editing mode to apply. If undefined, the + * current editing mode is not changed. + * @param {?string} clientId The block client ID. * * @return {BlockEditingMode} The current editing mode. */ -export function useBlockEditingMode( mode ) { - const { clientId = '' } = useContext( BlockListBlockContext ) ?? {}; +export function useBlockEditingMode( mode, clientId ) { + const blockContextAll = useContext( BlockListBlockContext ) ?? {}; + const { clientId: contextClientId = '' } = blockContextAll; + + if ( ! clientId ) { + clientId = contextClientId; + } + const blockEditingMode = useSelect( ( select ) => unlock( select( blockEditorStore ) ).getBlockEditingMode( @@ -66,6 +73,6 @@ export function useBlockEditingMode( mode ) { unsetBlockEditingMode( clientId ); } }; - }, [ clientId, mode ] ); + }, [ clientId, mode, setBlockEditingMode, unsetBlockEditingMode ] ); return blockEditingMode; }