Skip to content
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

Try read only navigation sidebar in browse mode #48971

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { store as blockEditorStore } from '../../store';
import { updateAttributes } from './update-attributes';
import { LinkUI } from './link-ui';
import { useInsertedBlock } from './use-inserted-block';
import { useListViewContext } from './context';

const BLOCKS_WITH_LINK_UI_SUPPORT = [
'core/navigation-link',
Expand All @@ -43,6 +44,7 @@ const ListViewBlockContents = forwardRef(
) => {
const { clientId } = block;
const [ isLinkUIOpen, setIsLinkUIOpen ] = useState();
const { enableDragAndDrop } = useListViewContext();
const {
blockMovingClientId,
selectedBlockInBlockEditor,
Expand Down Expand Up @@ -124,26 +126,44 @@ const ListViewBlockContents = forwardRef(
onCancel={ () => setIsLinkUIOpen( false ) }
/>
) }
<BlockDraggable clientIds={ draggableClientIds }>
{ ( { draggable, onDragStart, onDragEnd } ) => (
<ListViewBlockSelectButton
ref={ ref }
className={ className }
block={ block }
onClick={ onClick }
onToggleExpanded={ onToggleExpanded }
isSelected={ isSelected }
position={ position }
siblingBlockCount={ siblingBlockCount }
level={ level }
draggable={ draggable }
onDragStart={ onDragStart }
onDragEnd={ onDragEnd }
isExpanded={ isExpanded }
{ ...props }
/>
) }
</BlockDraggable>
{ enableDragAndDrop && (
<BlockDraggable clientIds={ draggableClientIds }>
{ ( { draggable, onDragStart, onDragEnd } ) => (
<ListViewBlockSelectButton
ref={ ref }
className={ className }
block={ block }
onClick={ onClick }
onToggleExpanded={ onToggleExpanded }
isSelected={ isSelected }
position={ position }
siblingBlockCount={ siblingBlockCount }
level={ level }
draggable={ draggable }
onDragStart={ onDragStart }
onDragEnd={ onDragEnd }
isExpanded={ isExpanded }
{ ...props }
/>
) }
</BlockDraggable>
) }
{ ! enableDragAndDrop && (
<ListViewBlockSelectButton
ref={ ref }
className={ className }
block={ block }
onClick={ onClick }
onToggleExpanded={ onToggleExpanded }
isSelected={ isSelected }
position={ position }
siblingBlockCount={ siblingBlockCount }
level={ level }
isExpanded={ isExpanded }
draggable={ false }
{ ...props }
/>
) }
</>
);
}
Expand Down
67 changes: 34 additions & 33 deletions packages/block-editor/src/components/off-canvas-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,39 +307,40 @@ function ListViewBlock( {
</>
) }

{ showBlockActions && (
<>
<TreeGridCell
className={ listViewBlockSettingsClassName }
aria-selected={
!! isSelected || forceSelectionContentLock
}
>
{ ( { ref, tabIndex, onFocus } ) => (
<>
<MoreMenuComponent
clientIds={ dropdownClientIds }
block={ block }
clientId={ clientId }
icon={ moreVertical }
label={ settingsAriaLabel }
toggleProps={ {
ref,
className:
'block-editor-list-view-block__menu',
tabIndex,
onFocus,
} }
disableOpenOnArrowDown
__experimentalSelectBlock={
updateSelection
}
/>
</>
) }
</TreeGridCell>
</>
) }
{ showBlockActions ||
( MoreMenuComponent === false && (
<>
<TreeGridCell
className={ listViewBlockSettingsClassName }
aria-selected={
!! isSelected || forceSelectionContentLock
}
>
{ ( { ref, tabIndex, onFocus } ) => (
<>
<MoreMenuComponent
clientIds={ dropdownClientIds }
block={ block }
clientId={ clientId }
icon={ moreVertical }
label={ settingsAriaLabel }
toggleProps={ {
ref,
className:
'block-editor-list-view-block__menu',
tabIndex,
onFocus,
} }
disableOpenOnArrowDown
__experimentalSelectBlock={
updateSelection
}
/>
</>
) }
</TreeGridCell>
</>
) ) }
</ListViewLeaf>
);
}
Expand Down
25 changes: 14 additions & 11 deletions packages/block-editor/src/components/off-canvas-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@ export const BLOCK_LIST_ITEM_HEIGHT = 36;
/**
* Show a hierarchical list of blocks.
*
* @param {Object} props Components props.
* @param {string} props.id An HTML element id for the root element of ListView.
* @param {string} props.parentClientId The client id of the parent block.
* @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.
* @param {boolean} props.showBlockMovers Flag to enable block movers
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.
* @param {Object} props.LeafMoreMenu Optional more menu substitution.
* @param {string} props.description Optional accessible description for the tree grid component.
* @param {string} props.onSelect Optional callback to be invoked when a block is selected.
* @param {string} props.showAppender Flag to show or hide the block appender.
* @param {Object} ref Forwarded ref
* @param {Object} props Components props.
* @param {string} props.id An HTML element id for the root element of ListView.
* @param {string} props.parentClientId The client id of the parent block.
* @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.
* @param {boolean} props.showBlockMovers Flag to enable block movers
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.
* @param {Object} props.LeafMoreMenu Optional more menu substitution.
* @param {boolean} props.enableDragAndDrop Flag to enable drag and drop.
* @param {string} props.description Optional accessible description for the tree grid component.
* @param {string} props.onSelect Optional callback to be invoked when a block is selected.
* @param {string} props.showAppender Flag to show or hide the block appender.
* @param {Object} ref Forwarded ref
*/
function OffCanvasEditor(
{
Expand All @@ -75,6 +76,7 @@ function OffCanvasEditor(
isExpanded = false,
showAppender = true,
LeafMoreMenu,
enableDragAndDrop = true,
description = __( 'Block navigation structure' ),
onSelect,
},
Expand Down Expand Up @@ -200,6 +202,7 @@ function OffCanvasEditor(
expand,
collapse,
LeafMoreMenu,
enableDragAndDrop,
} ),
[
isMounted.current,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
}

.edit-site-sidebar-navigation-screen__content .block-editor-list-view-block-select-button {
cursor: grab;
cursor: pointer;
padding: $grid-unit-10;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,32 @@ import { NavigationMenuLoader } from './loader';
export default function NavigationMenuContent( { rootClientId, onSelect } ) {
const { clientIdsTree, isLoading } = useSelect(
( select ) => {
const { __unstableGetClientIdsTree, areInnerBlocksControlled } =
select( blockEditorStore );
const {
__unstableGetClientIdsTree,
areInnerBlocksControlled,
getBlocksByClientId,
} = select( blockEditorStore );

const filterLinksOnly = ( tree ) => {
if ( tree.innerBlocks && tree.innerBlocks.length > 0 ) {
tree.innerBlocks = filterLinksOnly( tree.innerBlocks );
}
tree = tree.filter( ( item ) => {
const block = getBlocksByClientId( item.clientId )[ 0 ];
return (
block.name === 'core/navigation-link' ||
block.name === 'core/navigation-submenu' ||
block.name === 'core/page-list' ||
block.name === 'core/page-list-item'
);
} );
return tree;
};
const _clientIdsTree = filterLinksOnly(
__unstableGetClientIdsTree( rootClientId )
);
return {
clientIdsTree: __unstableGetClientIdsTree( rootClientId ),
clientIdsTree: _clientIdsTree,

// This is a small hack to wait for the navigation block
// to actually load its inner blocks.
Expand All @@ -35,7 +57,7 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
const { replaceBlock, __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );

const { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorPrivateApis );
const { OffCanvasEditor } = unlock( blockEditorPrivateApis );

const offCanvasOnselect = useCallback(
( block ) => {
Expand Down Expand Up @@ -64,8 +86,9 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
<OffCanvasEditor
blocks={ clientIdsTree }
onSelect={ offCanvasOnselect }
LeafMoreMenu={ LeafMoreMenu }
LeafMoreMenu={ false }
showAppender={ false }
enableDragAndDrop={ false }
/>
) }
<div style={ { visibility: 'hidden' } }>
Expand Down