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

Widgets editor: Add basic options for extensibility #25758

Merged
merged 2 commits into from
Oct 5, 2020
Merged
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
51 changes: 23 additions & 28 deletions packages/edit-widgets/src/components/sidebar/block-areas.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,25 @@ import { BlockIcon } from '@wordpress/block-editor';
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

function BlockArea( { clientId } ) {
const { name, selectedBlock } = useSelect(
( select ) => {
const { getBlockAttributes, getBlockSelectionStart } = select(
'core/block-editor'
);
return {
name: getBlockAttributes( clientId ).name,
selectedBlock: getBlockSelectionStart(),
};
},
[ clientId ]
function BlockArea( { block } ) {
const selectedBlock = useSelect(
( select ) => select( 'core/block-editor' ).getBlockSelectionStart(),
[]
);

const { selectBlock } = useDispatch( 'core/block-editor' );
const isSelected = selectedBlock === clientId;

if ( block.name !== 'core/widget-area' ) {
return null;
}

return (
<li>
<Button
aria-expanded={ isSelected }
onClick={
isSelected
? undefined
: () => {
selectBlock( clientId );
}
}
aria-expanded={ selectedBlock === block.clientId }
onClick={ () => selectBlock( block.clientId ) }
>
{ name }
{ block.attributes.name }
<span className="edit-widgets-block-areas__edit">
{ __( 'Edit' ) }
</span>
Expand All @@ -44,10 +35,13 @@ function BlockArea( { clientId } ) {
}

export default function BlockAreas() {
const blockOrder = useSelect( ( select ) => {
return select( 'core/block-editor' ).getBlockOrder();
} );
const hasBlockAreas = blockOrder.length > 0;
const blocks = useSelect(
( select ) => select( 'core/block-editor' ).getBlocks(),
[]
);

const hasBlockAreas = blocks.length > 0;

return (
<>
<div className="edit-widgets-block-areas">
Expand All @@ -68,10 +62,11 @@ export default function BlockAreas() {
) }
</div>
</div>

{ hasBlockAreas && (
<ul>
{ blockOrder.map( ( clientId ) => (
<BlockArea key={ clientId } clientId={ clientId } />
{ blocks.map( ( block ) => (
<BlockArea key={ block.clientId } block={ block } />
) ) }
</ul>
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default function WidgetAreasBlockEditorProvider( {
onInput={ onInput }
onChange={ onChange }
settings={ settings }
useSubRegistry={ false }
{ ...props }
/>
</FocusReturnProvider>
Expand Down