Skip to content

Commit

Permalink
Initial commit - just mucking around
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Aug 30, 2024
1 parent 520fa41 commit 2033b2f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -198,6 +199,7 @@ const BlockIndicator = ( { icon, showTitle, blockTitle } ) => (

export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
const {
selectedHasTemplateLock,
canRemove,
hasBlockStyles,
icon,
Expand All @@ -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 );
Expand All @@ -219,13 +225,16 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
const blockType = getBlockType( firstBlockName );

let _icon;
let _hasTemplateLock;
if ( _isSingleBlockSelected ) {
const match = getActiveBlockVariation(
firstBlockName,
getBlockAttributes( clientIds[ 0 ] )
);
// 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;
Expand All @@ -244,6 +253,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
_isSingleBlockSelected && isReusableBlock( _blocks[ 0 ] ),
isTemplate:
_isSingleBlockSelected && isTemplatePart( _blocks[ 0 ] ),
selectedHasTemplateLock: _hasTemplateLock,
};
},
[ clientIds ]
Expand All @@ -252,7 +262,8 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
clientId: clientIds?.[ 0 ],
maximumLength: 35,
} );
if ( invalidBlocks ) {

if ( invalidBlocks || selectedHasTemplateLock ) {
return null;
}

Expand Down

0 comments on commit 2033b2f

Please sign in to comment.