Skip to content

Commit

Permalink
Allow setting mode with specific clientId
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jun 6, 2023
1 parent 95336bf commit eb61716
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/block-editor/src/components/block-editing-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -66,6 +73,6 @@ export function useBlockEditingMode( mode ) {
unsetBlockEditingMode( clientId );
}
};
}, [ clientId, mode ] );
}, [ clientId, mode, setBlockEditingMode, unsetBlockEditingMode ] );
return blockEditingMode;
}

0 comments on commit eb61716

Please sign in to comment.