forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRY up ContentBlocksList and BlockInspectorLockedBlocks (WordPress#51281
) * DRY up ContentBlocksList and BlockInspectorLockedBlocks Extract BlockQuickNavigation out of ContentBlocksList and BlockInspectorLockedBlocks so that we're not repeating the same code that outputs a list of block navigation links. * Add back check that ensures list items don't appear in list * Remove unnecessary CSS * Reduce amount of rerendering * Update __experimentalGetGlobalBlocksByName
- Loading branch information
1 parent
a675dae
commit a5ab874
Showing
8 changed files
with
127 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/block-editor/src/components/block-quick-navigation/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { | ||
Button, | ||
__experimentalVStack as VStack, | ||
__experimentalHStack as HStack, | ||
FlexItem, | ||
} from '@wordpress/components'; | ||
import { getBlockType, __experimentalGetBlockLabel } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import BlockIcon from '../block-icon'; | ||
|
||
export default function BlockQuickNavigation( { clientIds } ) { | ||
if ( ! clientIds.length ) { | ||
return null; | ||
} | ||
return ( | ||
<VStack spacing={ 1 }> | ||
{ clientIds.map( ( clientId ) => ( | ||
<BlockQuickNavigationItem | ||
key={ clientId } | ||
clientId={ clientId } | ||
/> | ||
) ) } | ||
</VStack> | ||
); | ||
} | ||
|
||
function BlockQuickNavigationItem( { clientId } ) { | ||
const { name, attributes, isSelected } = useSelect( | ||
( select ) => { | ||
const { | ||
getBlockName, | ||
getBlockAttributes, | ||
isBlockSelected, | ||
hasSelectedInnerBlock, | ||
} = select( blockEditorStore ); | ||
return { | ||
name: getBlockName( clientId ), | ||
attributes: getBlockAttributes( clientId ), | ||
isSelected: | ||
isBlockSelected( clientId ) || | ||
hasSelectedInnerBlock( clientId, /* deep: */ true ), | ||
}; | ||
}, | ||
[ clientId ] | ||
); | ||
const { selectBlock } = useDispatch( blockEditorStore ); | ||
const blockType = getBlockType( name ); | ||
return ( | ||
<Button | ||
key={ clientId } | ||
isPressed={ isSelected } | ||
onClick={ () => selectBlock( clientId ) } | ||
> | ||
<HStack justify="flex-start"> | ||
<BlockIcon icon={ blockType.icon } /> | ||
<FlexItem> | ||
{ __experimentalGetBlockLabel( | ||
blockType, | ||
attributes, | ||
'list-view' | ||
) } | ||
</FlexItem> | ||
</HStack> | ||
</Button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
packages/edit-site/src/components/sidebar-edit-mode/page-panels/content-blocks-list.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/edit-site/src/components/sidebar-edit-mode/page-panels/page-content.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { | ||
store as blockEditorStore, | ||
privateApis as blockEditorPrivateApis, | ||
} from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PAGE_CONTENT_BLOCK_TYPES } from '../../page-content-focus/constants'; | ||
import { unlock } from '../../../private-apis'; | ||
|
||
const { BlockQuickNavigation } = unlock( blockEditorPrivateApis ); | ||
|
||
export default function PageContent() { | ||
const clientIds = useSelect( | ||
( select ) => | ||
select( blockEditorStore ).__experimentalGetGlobalBlocksByName( | ||
PAGE_CONTENT_BLOCK_TYPES | ||
), | ||
[] | ||
); | ||
return <BlockQuickNavigation clientIds={ clientIds } />; | ||
} |