From 2a859772493f3b83d0c12597b0f473e3042c04fe Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Tue, 23 Apr 2024 20:31:05 +0800 Subject: [PATCH] Remove the lock icon block content only blocks --- .../block-settings-menu-controls/index.js | 17 ++++++++++++----- .../components/list-view/block-select-button.js | 11 ++++++++++- .../src/components/list-view/block.js | 4 ++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/block-settings-menu-controls/index.js b/packages/block-editor/src/components/block-settings-menu-controls/index.js index 8b43827605c53..d043ae34aa0d2 100644 --- a/packages/block-editor/src/components/block-settings-menu-controls/index.js +++ b/packages/block-editor/src/components/block-settings-menu-controls/index.js @@ -27,15 +27,20 @@ import { BlockRenameControl, useBlockRename } from '../block-rename'; const { Fill, Slot } = createSlotFill( 'BlockSettingsMenuControls' ); const BlockSettingsMenuControlsSlot = ( { fillProps, clientIds = null } ) => { - const { selectedBlocks, selectedClientIds } = useSelect( + const { selectedBlocks, selectedClientIds, isContentOnly } = useSelect( ( select ) => { - const { getBlockNamesByClientId, getSelectedBlockClientIds } = - select( blockEditorStore ); + const { + getBlockNamesByClientId, + getSelectedBlockClientIds, + getBlockEditingMode, + } = select( blockEditorStore ); const ids = clientIds !== null ? clientIds : getSelectedBlockClientIds(); return { selectedBlocks: getBlockNamesByClientId( ids ), selectedClientIds: ids, + isContentOnly: + getBlockEditingMode( ids[ 0 ] ) === 'contentOnly', }; }, [ clientIds ] @@ -43,8 +48,10 @@ const BlockSettingsMenuControlsSlot = ( { fillProps, clientIds = null } ) => { const { canLock } = useBlockLock( selectedClientIds[ 0 ] ); const { canRename } = useBlockRename( selectedBlocks[ 0 ] ); - const showLockButton = selectedClientIds.length === 1 && canLock; - const showRenameButton = selectedClientIds.length === 1 && canRename; + const showLockButton = + selectedClientIds.length === 1 && canLock && ! isContentOnly; + const showRenameButton = + selectedClientIds.length === 1 && canRename && ! isContentOnly; // Check if current selection of blocks is Groupable or Ungroupable // and pass this props down to ConvertToGroupButton. diff --git a/packages/block-editor/src/components/list-view/block-select-button.js b/packages/block-editor/src/components/list-view/block-select-button.js index e52fc693afa79..539fd768caa3b 100644 --- a/packages/block-editor/src/components/list-view/block-select-button.js +++ b/packages/block-editor/src/components/list-view/block-select-button.js @@ -58,6 +58,15 @@ function ListViewBlockSelectButton( context: 'list-view', } ); const { isLocked } = useBlockLock( clientId ); + const { isContentOnly } = useSelect( + ( select ) => ( { + isContentOnly: + select( blockEditorStore ).getBlockEditingMode( clientId ) === + 'contentOnly', + } ), + [ clientId ] + ); + const shouldShowLockIcon = isLocked && ! isContentOnly; const { canInsertBlockType, getSelectedBlockClientIds, @@ -339,7 +348,7 @@ function ListViewBlockSelectButton( ) ) } ) : null } - { isLocked && ( + { shouldShowLockIcon && ( diff --git a/packages/block-editor/src/components/list-view/block.js b/packages/block-editor/src/components/list-view/block.js index 930d0a0f80ef6..9ae6d97d63edf 100644 --- a/packages/block-editor/src/components/list-view/block.js +++ b/packages/block-editor/src/components/list-view/block.js @@ -107,8 +107,8 @@ function ListViewBlock( { // since that menu is part of the toolbar in the editor canvas. // List View respects this by also hiding the block settings menu. hasBlockSupport( blockName, '__experimentalToolbar', true ) && - // Don't show the settings menu if block is disabled or content only. - blockEditingMode === 'default'; + // Don't show the settings menu if block is disabled. + blockEditingMode !== 'disabled'; const instanceId = useInstanceId( ListViewBlock ); const descriptionId = `list-view-block-select-button__description-${ instanceId }`;