-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Select Mode: Use the content-only behavior in select mode #65204
Changes from 20 commits
32b3ed8
fd0007a
6150855
ea2e6d9
e7d306a
8a954af
596aff7
a80d1f3
ac9f416
f3d104d
a0df8e3
0ae55fe
51c2c81
330efd3
3eaf070
7ed6c44
cf9cedf
be0afbc
96642a6
f1954d3
2084336
a783818
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,83 +40,36 @@ function BlockStylesPanel( { clientId } ) { | |
); | ||
} | ||
|
||
function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of creating a custom "inspector control" for "content only" mode (and similar), I refactored this component to reuse the same block inspector control component by passing a "isContentLockingParent" flag instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes everything easier to reason about 👍 |
||
const contentClientIds = useSelect( | ||
( select ) => { | ||
const { | ||
getClientIdsOfDescendants, | ||
getBlockName, | ||
getBlockEditingMode, | ||
} = select( blockEditorStore ); | ||
return getClientIdsOfDescendants( topLevelLockedBlock ).filter( | ||
( clientId ) => | ||
getBlockName( clientId ) !== 'core/list-item' && | ||
getBlockEditingMode( clientId ) === 'contentOnly' | ||
); | ||
}, | ||
[ topLevelLockedBlock ] | ||
); | ||
const hasBlockStyles = useSelect( | ||
( select ) => { | ||
const { getBlockName } = select( blockEditorStore ); | ||
const { getBlockStyles } = select( blocksStore ); | ||
return !! getBlockStyles( getBlockName( topLevelLockedBlock ) ) | ||
?.length; | ||
}, | ||
[ topLevelLockedBlock ] | ||
); | ||
const blockInformation = useBlockDisplayInformation( topLevelLockedBlock ); | ||
return ( | ||
<div className="block-editor-block-inspector"> | ||
<BlockCard | ||
{ ...blockInformation } | ||
className={ blockInformation.isSynced && 'is-synced' } | ||
/> | ||
<BlockInfo.Slot /> | ||
{ hasBlockStyles && ( | ||
<BlockStylesPanel clientId={ topLevelLockedBlock } /> | ||
) } | ||
{ contentClientIds.length > 0 && ( | ||
<PanelBody title={ __( 'Content' ) }> | ||
<BlockQuickNavigation clientIds={ contentClientIds } /> | ||
</PanelBody> | ||
) } | ||
</div> | ||
); | ||
} | ||
|
||
const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => { | ||
const { | ||
count, | ||
selectedBlockName, | ||
selectedBlockClientId, | ||
blockType, | ||
topLevelLockedBlock, | ||
isSectionBlock, | ||
} = useSelect( ( select ) => { | ||
const { | ||
getSelectedBlockClientId, | ||
getSelectedBlockCount, | ||
getBlockName, | ||
getContentLockingParent, | ||
getTemplateLock, | ||
getParentSectionBlock, | ||
isSectionBlock: _isSectionBlock, | ||
} = unlock( select( blockEditorStore ) ); | ||
const _selectedBlockClientId = getSelectedBlockClientId(); | ||
const renderedBlockClientId = | ||
getParentSectionBlock( _selectedBlockClientId ) || | ||
getSelectedBlockClientId(); | ||
const _selectedBlockName = | ||
_selectedBlockClientId && getBlockName( _selectedBlockClientId ); | ||
renderedBlockClientId && getBlockName( renderedBlockClientId ); | ||
const _blockType = | ||
_selectedBlockName && getBlockType( _selectedBlockName ); | ||
|
||
return { | ||
count: getSelectedBlockCount(), | ||
selectedBlockClientId: _selectedBlockClientId, | ||
selectedBlockClientId: renderedBlockClientId, | ||
selectedBlockName: _selectedBlockName, | ||
blockType: _blockType, | ||
topLevelLockedBlock: | ||
getContentLockingParent( _selectedBlockClientId ) || | ||
( getTemplateLock( _selectedBlockClientId ) === 'contentOnly' || | ||
_selectedBlockName === 'core/block' | ||
? _selectedBlockClientId | ||
: undefined ), | ||
isSectionBlock: _isSectionBlock( renderedBlockClientId ), | ||
}; | ||
}, [] ); | ||
|
||
|
@@ -136,7 +89,7 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => { | |
blockName: selectedBlockName, | ||
} ); | ||
|
||
if ( count > 1 ) { | ||
if ( count > 1 && ! isSectionBlock ) { | ||
return ( | ||
<div className="block-editor-block-inspector"> | ||
<MultiSelectionInspector /> | ||
|
@@ -194,13 +147,6 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => { | |
} | ||
return null; | ||
} | ||
if ( topLevelLockedBlock ) { | ||
return ( | ||
<BlockInspectorLockedBlocks | ||
topLevelLockedBlock={ topLevelLockedBlock } | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<BlockInspectorSingleBlockWrapper | ||
|
@@ -219,6 +165,7 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => { | |
<BlockInspectorSingleBlock | ||
clientId={ selectedBlockClientId } | ||
blockName={ blockType.name } | ||
isSectionBlock={ isSectionBlock } | ||
/> | ||
</BlockInspectorSingleBlockWrapper> | ||
); | ||
|
@@ -260,9 +207,13 @@ const AnimatedContainer = ( { | |
); | ||
}; | ||
|
||
const BlockInspectorSingleBlock = ( { clientId, blockName } ) => { | ||
const BlockInspectorSingleBlock = ( { | ||
clientId, | ||
blockName, | ||
isSectionBlock, | ||
} ) => { | ||
const availableTabs = useInspectorControlsTabs( blockName ); | ||
const showTabs = availableTabs?.length > 1; | ||
const showTabs = ! isSectionBlock && availableTabs?.length > 1; | ||
|
||
const hasBlockStyles = useSelect( | ||
( select ) => { | ||
|
@@ -274,6 +225,26 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => { | |
); | ||
const blockInformation = useBlockDisplayInformation( clientId ); | ||
const borderPanelLabel = useBorderPanelLabel( { blockName } ); | ||
const contentClientIds = useSelect( | ||
( select ) => { | ||
// Avoid unnecessary subscription. | ||
if ( ! isSectionBlock ) { | ||
return; | ||
} | ||
|
||
const { | ||
getClientIdsOfDescendants, | ||
getBlockName, | ||
getBlockEditingMode, | ||
} = select( blockEditorStore ); | ||
return getClientIdsOfDescendants( clientId ).filter( | ||
( current ) => | ||
getBlockName( current ) !== 'core/list-item' && | ||
getBlockEditingMode( current ) === 'contentOnly' | ||
); | ||
}, | ||
[ isSectionBlock, clientId ] | ||
); | ||
|
||
return ( | ||
<div className="block-editor-block-inspector"> | ||
|
@@ -296,35 +267,48 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => { | |
{ hasBlockStyles && ( | ||
<BlockStylesPanel clientId={ clientId } /> | ||
) } | ||
<InspectorControls.Slot /> | ||
<InspectorControls.Slot group="list" /> | ||
<InspectorControls.Slot | ||
group="color" | ||
label={ __( 'Color' ) } | ||
className="color-block-support-panel__inner-wrapper" | ||
/> | ||
<InspectorControls.Slot | ||
group="background" | ||
label={ __( 'Background image' ) } | ||
/> | ||
<InspectorControls.Slot | ||
group="typography" | ||
label={ __( 'Typography' ) } | ||
/> | ||
<InspectorControls.Slot | ||
group="dimensions" | ||
label={ __( 'Dimensions' ) } | ||
/> | ||
<InspectorControls.Slot | ||
group="border" | ||
label={ borderPanelLabel } | ||
/> | ||
<InspectorControls.Slot group="styles" /> | ||
<PositionControls /> | ||
<InspectorControls.Slot group="bindings" /> | ||
<div> | ||
<AdvancedControls /> | ||
</div> | ||
|
||
{ contentClientIds && contentClientIds?.length > 0 && ( | ||
<PanelBody title={ __( 'Content' ) }> | ||
<BlockQuickNavigation | ||
clientIds={ contentClientIds } | ||
/> | ||
</PanelBody> | ||
) } | ||
|
||
{ ! isSectionBlock && ( | ||
<> | ||
<InspectorControls.Slot /> | ||
<InspectorControls.Slot group="list" /> | ||
<InspectorControls.Slot | ||
group="color" | ||
label={ __( 'Color' ) } | ||
className="color-block-support-panel__inner-wrapper" | ||
/> | ||
<InspectorControls.Slot | ||
group="background" | ||
label={ __( 'Background image' ) } | ||
/> | ||
<InspectorControls.Slot | ||
group="typography" | ||
label={ __( 'Typography' ) } | ||
/> | ||
<InspectorControls.Slot | ||
group="dimensions" | ||
label={ __( 'Dimensions' ) } | ||
/> | ||
<InspectorControls.Slot | ||
group="border" | ||
label={ borderPanelLabel } | ||
/> | ||
<InspectorControls.Slot group="styles" /> | ||
<PositionControls /> | ||
<InspectorControls.Slot group="bindings" /> | ||
<div> | ||
<AdvancedControls /> | ||
</div> | ||
</> | ||
) } | ||
</> | ||
) } | ||
<SkipToSelectedBlock key="back" /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can users remove blocks in this mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know I updated this file because canMove and onMove are not used anymore by the components using BlockActions.