From e901c30d42d9b28777a545d17f9fa235183a9c22 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 30 Aug 2024 12:33:16 +1000 Subject: [PATCH 1/6] Initial commit - just mucking around --- .../src/components/block-switcher/index.js | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/components/block-switcher/index.js b/packages/block-editor/src/components/block-switcher/index.js index c8ee422091ad1f..da394a9bee767e 100644 --- a/packages/block-editor/src/components/block-switcher/index.js +++ b/packages/block-editor/src/components/block-switcher/index.js @@ -107,9 +107,10 @@ function BlockSwitcherDropdownMenuContents( { const hasPossibleBlockVariationTransformations = !! blockVariationTransformations?.length; const hasPatternTransformation = !! patterns?.length && canRemove; - const hasBlockOrBlockVariationTransforms = + /* const hasBlockOrBlockVariationTransforms = hasPossibleBlockTransformations || - hasPossibleBlockVariationTransformations; + hasPossibleBlockVariationTransformations;*/ + const hasBlockOrBlockVariationTransforms = false; const hasContents = hasBlockStyles || hasBlockOrBlockVariationTransforms || @@ -198,6 +199,7 @@ const BlockIndicator = ( { icon, showTitle, blockTitle } ) => ( export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { const { + selectedHasTemplateLock, canRemove, hasBlockStyles, icon, @@ -206,8 +208,12 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { isTemplate, } = useSelect( ( select ) => { - const { getBlocksByClientId, getBlockAttributes, canRemoveBlocks } = - select( blockEditorStore ); + const { + getTemplateLock, + getBlocksByClientId, + getBlockAttributes, + canRemoveBlocks, + } = select( blockEditorStore ); const { getBlockStyles, getBlockType, getActiveBlockVariation } = select( blocksStore ); const _blocks = getBlocksByClientId( clientIds ); @@ -219,6 +225,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { const blockType = getBlockType( firstBlockName ); let _icon; + let _hasTemplateLock; if ( _isSingleBlockSelected ) { const match = getActiveBlockVariation( firstBlockName, @@ -226,6 +233,8 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { ); // Take into account active block variations. _icon = match?.icon || blockType.icon; + _hasTemplateLock = + getTemplateLock( clientIds[ 0 ] ) === 'contentOnly'; } else { const isSelectionOfSameType = new Set( _blocks.map( ( { name } ) => name ) ).size === 1; @@ -244,6 +253,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { _isSingleBlockSelected && isReusableBlock( _blocks[ 0 ] ), isTemplate: _isSingleBlockSelected && isTemplatePart( _blocks[ 0 ] ), + selectedHasTemplateLock: _hasTemplateLock, }; }, [ clientIds ] @@ -252,7 +262,8 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { clientId: clientIds?.[ 0 ], maximumLength: 35, } ); - if ( invalidBlocks ) { + + if ( invalidBlocks || selectedHasTemplateLock ) { return null; } From 68c05cf9b5164ef760513340d1543f9713c4d5b2 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 30 Aug 2024 15:00:15 +1000 Subject: [PATCH 2/6] Removing variations from block inspector panel if template is locked --- .../block-editor/src/components/block-inspector/index.js | 1 - packages/block-editor/src/components/block-switcher/index.js | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/block-inspector/index.js b/packages/block-editor/src/components/block-inspector/index.js index 1986ad8730c121..a18556f2fa5bd9 100644 --- a/packages/block-editor/src/components/block-inspector/index.js +++ b/packages/block-editor/src/components/block-inspector/index.js @@ -72,7 +72,6 @@ function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) { { ...blockInformation } className={ blockInformation.isSynced && 'is-synced' } /> - { hasBlockStyles && ( diff --git a/packages/block-editor/src/components/block-switcher/index.js b/packages/block-editor/src/components/block-switcher/index.js index da394a9bee767e..982b6e80792d7b 100644 --- a/packages/block-editor/src/components/block-switcher/index.js +++ b/packages/block-editor/src/components/block-switcher/index.js @@ -107,10 +107,9 @@ function BlockSwitcherDropdownMenuContents( { const hasPossibleBlockVariationTransformations = !! blockVariationTransformations?.length; const hasPatternTransformation = !! patterns?.length && canRemove; - /* const hasBlockOrBlockVariationTransforms = + const hasBlockOrBlockVariationTransforms = hasPossibleBlockTransformations || - hasPossibleBlockVariationTransformations;*/ - const hasBlockOrBlockVariationTransforms = false; + hasPossibleBlockVariationTransformations; const hasContents = hasBlockStyles || hasBlockOrBlockVariationTransforms || From 80a6026970853f726756fbc8c5b4eca79a1c31f6 Mon Sep 17 00:00:00 2001 From: ramon Date: Tue, 3 Sep 2024 09:56:50 +1000 Subject: [PATCH 3/6] Simplify condition --- packages/block-editor/src/components/block-switcher/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/block-editor/src/components/block-switcher/index.js b/packages/block-editor/src/components/block-switcher/index.js index 982b6e80792d7b..610f2c0580b5b7 100644 --- a/packages/block-editor/src/components/block-switcher/index.js +++ b/packages/block-editor/src/components/block-switcher/index.js @@ -237,6 +237,9 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { } else { const isSelectionOfSameType = new Set( _blocks.map( ( { name } ) => name ) ).size === 1; + _hasTemplateLock = clientIds.some( + ( id ) => getTemplateLock( id ) === 'contentOnly' + ); // When selection consists of blocks of multiple types, display an // appropriate icon to communicate the non-uniformity. _icon = isSelectionOfSameType ? blockType.icon : copy; From 1b67d9e43b12c03dbfcecd509a4aefee5fc2f5d4 Mon Sep 17 00:00:00 2001 From: ramon Date: Tue, 3 Sep 2024 12:58:06 +1000 Subject: [PATCH 4/6] Don't show group toolbar if one or more selected blocks are content locked. --- .../src/components/block-toolbar/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js index b14ceb50590495..aa1d00b79fb1d3 100644 --- a/packages/block-editor/src/components/block-toolbar/index.js +++ b/packages/block-editor/src/components/block-toolbar/index.js @@ -66,6 +66,7 @@ export function PrivateBlockToolbar( { showParentSelector, isUsingBindings, hasParentPattern, + selectedHasTemplateLock, } = useSelect( ( select ) => { const { getBlockName, @@ -76,6 +77,7 @@ export function PrivateBlockToolbar( { getBlockEditingMode, getBlockAttributes, getBlockParentsByBlockName, + getTemplateLock, } = select( blockEditorStore ); const selectedBlockClientIds = getSelectedBlockClientIds(); const selectedBlockClientId = selectedBlockClientIds[ 0 ]; @@ -103,6 +105,10 @@ export function PrivateBlockToolbar( { .length > 0 ); + // If one or more selected blocks re locked, do not show the BlockGroupToolbar. + const _hasTemplateLock = selectedBlockClientIds.some( + ( id ) => getTemplateLock( id ) === 'contentOnly' + ); return { blockClientId: selectedBlockClientId, blockClientIds: selectedBlockClientIds, @@ -123,6 +129,7 @@ export function PrivateBlockToolbar( { _isDefaultEditingMode, isUsingBindings: _isUsingBindings, hasParentPattern: _hasParentPattern, + selectedHasTemplateLock: _hasTemplateLock, }; }, [] ); @@ -205,9 +212,9 @@ export function PrivateBlockToolbar( { ) } - { shouldShowVisualToolbar && isMultiToolbar && ( - - ) } + { ! selectedHasTemplateLock && + shouldShowVisualToolbar && + isMultiToolbar && } { shouldShowVisualToolbar && ( <> Date: Wed, 4 Sep 2024 15:05:18 +1000 Subject: [PATCH 5/6] Rename selectedHasTemplateLock to hasContentOnlyLocking. In the block-switcher, only hide the drop down if a selected block is content locked. --- .../src/components/block-switcher/index.js | 11 +++++++---- .../src/components/block-toolbar/index.js | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/block-switcher/index.js b/packages/block-editor/src/components/block-switcher/index.js index 610f2c0580b5b7..98e7f7b2d21420 100644 --- a/packages/block-editor/src/components/block-switcher/index.js +++ b/packages/block-editor/src/components/block-switcher/index.js @@ -198,7 +198,7 @@ const BlockIndicator = ( { icon, showTitle, blockTitle } ) => ( export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { const { - selectedHasTemplateLock, + hasContentOnlyLocking, canRemove, hasBlockStyles, icon, @@ -255,7 +255,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { _isSingleBlockSelected && isReusableBlock( _blocks[ 0 ] ), isTemplate: _isSingleBlockSelected && isTemplatePart( _blocks[ 0 ] ), - selectedHasTemplateLock: _hasTemplateLock, + hasContentOnlyLocking: _hasTemplateLock, }; }, [ clientIds ] @@ -265,7 +265,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { maximumLength: 35, } ); - if ( invalidBlocks || selectedHasTemplateLock ) { + if ( invalidBlocks ) { return null; } @@ -274,7 +274,10 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { ? blockTitle : __( 'Multiple blocks selected' ); - const hideDropdown = disabled || ( ! hasBlockStyles && ! canRemove ); + const hideDropdown = + disabled || + ( ! hasBlockStyles && ! canRemove ) || + hasContentOnlyLocking; if ( hideDropdown ) { return ( diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js index aa1d00b79fb1d3..95be157c6bb713 100644 --- a/packages/block-editor/src/components/block-toolbar/index.js +++ b/packages/block-editor/src/components/block-toolbar/index.js @@ -66,7 +66,7 @@ export function PrivateBlockToolbar( { showParentSelector, isUsingBindings, hasParentPattern, - selectedHasTemplateLock, + hasContentOnlyLocking, } = useSelect( ( select ) => { const { getBlockName, @@ -129,7 +129,7 @@ export function PrivateBlockToolbar( { _isDefaultEditingMode, isUsingBindings: _isUsingBindings, hasParentPattern: _hasParentPattern, - selectedHasTemplateLock: _hasTemplateLock, + hasContentOnlyLocking: _hasTemplateLock, }; }, [] ); @@ -212,7 +212,7 @@ export function PrivateBlockToolbar( { ) } - { ! selectedHasTemplateLock && + { ! hasContentOnlyLocking && shouldShowVisualToolbar && isMultiToolbar && } { shouldShowVisualToolbar && ( From e63dfe021f25e5a05ef7dfd02c5e53fbeaa10937 Mon Sep 17 00:00:00 2001 From: Ramon Date: Sat, 7 Sep 2024 11:17:39 +1000 Subject: [PATCH 6/6] Correct misspelling Co-authored-by: Dave Smith --- packages/block-editor/src/components/block-toolbar/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js index 95be157c6bb713..6c4789cb2924f2 100644 --- a/packages/block-editor/src/components/block-toolbar/index.js +++ b/packages/block-editor/src/components/block-toolbar/index.js @@ -105,7 +105,7 @@ export function PrivateBlockToolbar( { .length > 0 ); - // If one or more selected blocks re locked, do not show the BlockGroupToolbar. + // If one or more selected blocks are locked, do not show the BlockGroupToolbar. const _hasTemplateLock = selectedBlockClientIds.some( ( id ) => getTemplateLock( id ) === 'contentOnly' );