Skip to content

Commit

Permalink
Adjust conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 21, 2020
1 parent 3b93437 commit e947daf
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
34 changes: 25 additions & 9 deletions packages/block-editor/src/components/block-controls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,35 @@ function BlockControlsFill( { controls, children } ) {
);
}

function BlockControls( { allowMultiple, ...props } ) {
const { isSelected, clientId } = useBlockEditContext();
const isFirstMultiSelected = useSelect( ( select ) =>
select( 'core/block-editor' ).isFirstMultiSelectedBlock( clientId )
function BlockControls( { __experimentalAllowAnyMultiple, children } ) {
const { isSelected, clientId, name } = useBlockEditContext();
const isFirstAndSameTypeMultiSelected = useSelect(
( select ) => {
const {
getBlockName,
isFirstMultiSelectedBlock,
getMultiSelectedBlockClientIds,
} = select( 'core/block-editor' );

if ( ! isFirstMultiSelectedBlock( clientId ) ) {
return false;
}

return (
__experimentalAllowAnyMultiple ||
getMultiSelectedBlockClientIds().every(
( id ) => getBlockName( id ) === name
)
);
},
[ __experimentalAllowAnyMultiple ]
);

if ( ! isSelected ) {
if ( ! allowMultiple || ! isFirstMultiSelected ) {
return null;
}
if ( ! isSelected && ! isFirstAndSameTypeMultiSelected ) {
return null;
}

return <BlockControlsFill { ...props } />;
return <BlockControlsFill>{ children }</BlockControlsFill>;
}

BlockControls.Slot = BlockControlsSlot;
Expand Down
34 changes: 25 additions & 9 deletions packages/block-editor/src/components/inspector-controls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,35 @@ import { useBlockEditContext } from '../block-edit/context';

const { Fill, Slot } = createSlotFill( 'InspectorControls' );

function InspectorControls( { allowMultiple, ...props } ) {
const { isSelected, clientId } = useBlockEditContext();
const isFirstMultiSelected = useSelect( ( select ) =>
select( 'core/block-editor' ).isFirstMultiSelectedBlock( clientId )
function InspectorControls( { __experimentalAllowAnyMultiple, children } ) {
const { isSelected, clientId, name } = useBlockEditContext();
const isFirstAndSameTypeMultiSelected = useSelect(
( select ) => {
const {
getBlockName,
isFirstMultiSelectedBlock,
getMultiSelectedBlockClientIds,
} = select( 'core/block-editor' );

if ( ! isFirstMultiSelectedBlock( clientId ) ) {
return false;
}

return (
__experimentalAllowAnyMultiple ||
getMultiSelectedBlockClientIds().every(
( id ) => getBlockName( id ) === name
)
);
},
[ __experimentalAllowAnyMultiple ]
);

if ( ! isSelected ) {
if ( ! allowMultiple || ! isFirstMultiSelected ) {
return null;
}
if ( ! isSelected && ! isFirstAndSameTypeMultiSelected ) {
return null;
}

return <Fill { ...props } />;
return <Fill>{ children }</Fill>;
}

InspectorControls.Slot = Slot;
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/color-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function ColorPanel( {
} );

return (
<InspectorControls allowMultiple>
<InspectorControls allowAnyMultiple>
<PanelColorGradientSettings
title={ __( 'Color settings' ) }
initialOpen={ false }
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const withBlockControls = createHigherOrderComponent(

return [
Platform.OS === 'web' && hasTypographySupport && (
<InspectorControls key="typography" allowMultiple>
<InspectorControls key="typography" allowAnyMultiple>
<PanelBody title={ __( 'Typography' ) }>
<FontSizeEdit { ...props } />
<LineHeightEdit { ...props } />
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function ParagraphBlock( {

return (
<>
<BlockControls allowMultiple>
<BlockControls allowAnyMultiple>
<AlignmentToolbar
value={ align }
onChange={ ( newAlign ) =>
Expand Down

0 comments on commit e947daf

Please sign in to comment.