Skip to content

Commit

Permalink
enable list view inspector control for controlling blocks in content …
Browse files Browse the repository at this point in the history
…only mode
  • Loading branch information
draganescu committed Nov 6, 2024
1 parent bd11f59 commit c44ea46
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 13 deletions.
47 changes: 40 additions & 7 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import useBlockInspectorAnimationSettings from './useBlockInspectorAnimationSett
import BlockInfo from '../block-info-slot-fill';
import BlockQuickNavigation from '../block-quick-navigation';
import { useBorderPanelLabel } from '../../hooks/border';
import { privateApis as blockEditorPrivateApis } from '../../private-apis';

import { unlock } from '../../lock-unlock';
const { PrivateListView } = unlock( blockEditorPrivateApis );

function BlockStylesPanel( { clientId } ) {
return (
Expand Down Expand Up @@ -223,6 +225,7 @@ const BlockInspectorSingleBlock = ( {
},
[ blockName ]
);

const blockInformation = useBlockDisplayInformation( clientId );
const borderPanelLabel = useBorderPanelLabel( { blockName } );
const contentClientIds = useSelect(
Expand All @@ -246,6 +249,20 @@ const BlockInspectorSingleBlock = ( {
[ isSectionBlock, clientId ]
);

const { selectedContentClientId, isSelectedContentClientIdControlling } =
useSelect( ( select ) => {
const { getSelectedBlockClientId, areInnerBlocksControlled } =
select( blockEditorStore );

const _selectedBlockClientId = getSelectedBlockClientId();
return {
selectedContentClientId: _selectedBlockClientId,
isSelectedContentClientIdControlling: areInnerBlocksControlled(
_selectedBlockClientId
),
};
} );

return (
<div className="block-editor-block-inspector">
<BlockCard
Expand All @@ -268,13 +285,29 @@ const BlockInspectorSingleBlock = ( {
<BlockStylesPanel clientId={ clientId } />
) }

{ contentClientIds && contentClientIds?.length > 0 && (
<PanelBody title={ __( 'Content' ) }>
<BlockQuickNavigation
clientIds={ contentClientIds }
/>
</PanelBody>
) }
{ ! isSelectedContentClientIdControlling &&
contentClientIds &&
contentClientIds?.length > 0 && (
<PanelBody title={ __( 'Content' ) }>
<BlockQuickNavigation
clientIds={ contentClientIds }
/>
</PanelBody>
) }

{ isSelectedContentClientIdControlling &&
contentClientIds &&
contentClientIds?.length > 0 && (
<PanelBody title={ __( 'Content' ) }>
<PrivateListView
rootClientId={ selectedContentClientId }
ignoreRenderingMode
isExpanded
description={ __( 'Inner blocks' ) }
showAppender={ false }
/>
</PanelBody>
) }

{ ! isSectionBlock && (
<>
Expand Down
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const BLOCK_LIST_ITEM_HEIGHT = 32;
* @param {?HTMLElement} props.dropZoneElement Optional element to be used as the drop zone.
* @param {?boolean} props.showBlockMovers Flag to enable block movers. Defaults to `false`.
* @param {?boolean} props.isExpanded Flag to determine whether nested levels are expanded by default. Defaults to `false`.
* @param {?boolean} props.ignoreRenderingMode Flag to ignore rendering mode and always show the block. Defaults to `false`.
* @param {?boolean} props.showAppender Flag to show or hide the block appender. Defaults to `false`.
* @param {?ComponentType} props.blockSettingsMenu Optional more menu substitution. Defaults to the standard `BlockSettingsDropdown` component.
* @param {string} props.rootClientId The client id of the root block from which we determine the blocks to show in the list.
Expand All @@ -93,6 +94,7 @@ function ListViewComponent(
dropZoneElement,
showBlockMovers = false,
isExpanded = false,
ignoreRenderingMode = false,
showAppender = false,
blockSettingsMenu: BlockSettingsMenu = BlockSettingsDropdown,
rootClientId,
Expand All @@ -115,7 +117,7 @@ function ListViewComponent(

const instanceId = useInstanceId( ListViewComponent );
const { clientIdsTree, draggedClientIds, selectedClientIds } =
useListViewClientIds( { blocks, rootClientId } );
useListViewClientIds( { blocks, rootClientId, ignoreRenderingMode } );
const blockIndexes = useListViewBlockIndexes( clientIdsTree );

const { getBlock } = useSelect( blockEditorStore );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,29 @@ import { useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

export default function useListViewClientIds( { blocks, rootClientId } ) {
export default function useListViewClientIds( {
blocks,
rootClientId,
ignoreRenderingMode,
} ) {
return useSelect(
( select ) => {
const {
getDraggedBlockClientIds,
getSelectedBlockClientIds,
getEnabledClientIdsTree,
__unstableGetClientIdsTree: getClientIdsTree,
} = unlock( select( blockEditorStore ) );

return {
selectedClientIds: getSelectedBlockClientIds(),
draggedClientIds: getDraggedBlockClientIds(),
clientIdsTree:
blocks ?? getEnabledClientIdsTree( rootClientId ),
blocks ?? ignoreRenderingMode
? getClientIdsTree( rootClientId )
: getEnabledClientIdsTree( rootClientId ),
};
},
[ blocks, rootClientId ]
[ blocks, rootClientId, ignoreRenderingMode ]
);
}
1 change: 1 addition & 0 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function getEnabledClientIdsTreeUnmemoized( state, rootClientId ) {
state,
clientId
);

if ( getBlockEditingMode( state, clientId ) !== 'disabled' ) {
result.push( { clientId, innerBlocks } );
} else {
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3037,6 +3037,10 @@ export const getBlockEditingMode = createRegistrySelector(
clientId = '';
}

if ( areInnerBlocksControlled( state, clientId ) ) {
return 'contentOnly';
}

// In zoom-out mode, override the behavior set by
// __unstableSetBlockEditingMode to only allow editing the top-level
// sections.
Expand Down
10 changes: 8 additions & 2 deletions packages/block-library/src/navigation/edit/inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export default function NavigationInnerBlocks( {
const showPlaceholder =
! hasCustomPlaceholder && ! hasMenuItems && ! isSelected;

const defaultRenderingMode = useSelect( ( select ) => {
const { getBlockEditingMode } = select( blockEditorStore );
return getBlockEditingMode( clientId ) === 'default';
} );

const innerBlocksProps = useInnerBlocksProps(
{
className: 'wp-block-navigation__container',
Expand All @@ -93,13 +98,14 @@ export default function NavigationInnerBlocks( {
// the sibling inserter.
// See https://github.com/WordPress/gutenberg/issues/37572.
renderAppender:
isSelected ||
defaultRenderingMode &&
( isSelected ||
( isImmediateParentOfSelectedBlock &&
! selectedBlockHasChildren ) ||
// Show the appender while dragging to allow inserting element between item and the appender.
parentOrChildHasSelection
? InnerBlocks.ButtonBlockAppender
: false,
: false ),
placeholder: showPlaceholder ? placeholder : undefined,
__experimentalCaptureToolbars: true,
__unstableDisableLayoutClassNames: true,
Expand Down

0 comments on commit c44ea46

Please sign in to comment.