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

Block: combine store subscriptions #56994

Merged
merged 10 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
debug error
  • Loading branch information
ellatrix committed Dec 13, 2023
commit 735151f94a36d4efed5610c736839e14ffcd066d
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useContext, useEffect } from '@wordpress/element';
import { useEffect } from '@wordpress/element';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import { BlockListBlockContext } from '../block-list/block-list-block-context';
import { useBlockEditContext } from '../block-edit/context';

/**
* @typedef {'disabled'|'contentOnly'|'default'} BlockEditingMode
Expand Down Expand Up @@ -45,7 +45,7 @@ import { BlockListBlockContext } from '../block-list/block-list-block-context';
* @return {BlockEditingMode} The current editing mode.
*/
export function useBlockEditingMode( mode ) {
const { clientId = '' } = useContext( BlockListBlockContext ) ?? {};
const { clientId = '' } = useBlockEditContext();
const blockEditingMode = useSelect(
( select ) =>
select( blockEditorStore ).getBlockEditingMode( clientId ),
Expand Down
18 changes: 9 additions & 9 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ function BlockListBlock( {
/>
);

const blockType = getBlockType( name );
const _blockType = getBlockType( name );

// Determine whether the block has props to apply to the wrapper.
if ( blockType?.getEditWrapperProps ) {
if ( _blockType?.getEditWrapperProps ) {
wrapperProps = mergeWrapperProps(
wrapperProps,
blockType.getEditWrapperProps( attributes )
_blockType.getEditWrapperProps( attributes )
);
}

Expand Down Expand Up @@ -205,7 +205,7 @@ function BlockListBlock( {
if ( ! isValid ) {
const saveContent = __unstableBlockSource
? serializeRawBlock( __unstableBlockSource )
: getSaveContent( blockType, attributes );
: getSaveContent( _blockType, attributes );

block = (
<Block className="has-warning">
Expand All @@ -224,7 +224,7 @@ function BlockListBlock( {
</Block>
</>
);
} else if ( blockType?.apiVersion > 1 ) {
} else if ( _blockType?.apiVersion > 1 ) {
block = blockEdit;
} else {
block = <Block>{ blockEdit }</Block>;
Expand Down Expand Up @@ -554,7 +554,7 @@ function BlockListBlockProvider( props ) {
const isPartOfMultiSelection =
isBlockMultiSelected( clientId ) ||
isAncestorMultiSelected( clientId );
const blockType = getBlockType( blockName );
const _blockType = getBlockType( blockName );
const match = getActiveBlockVariation( blockName, attributes );
const { outlineMode, supportsLayout } = getSettings();
const isMultiSelected = isBlockMultiSelected( clientId );
Expand All @@ -564,7 +564,7 @@ function BlockListBlockProvider( props ) {
checkDeep
);
const typing = isTyping();
const hasLightBlockWrapper = blockType?.apiVersion > 1;
const hasLightBlockWrapper = _blockType?.apiVersion > 1;
const movingClientId = hasBlockMovingClientId();
const _hasOverlay =
__unstableHasActiveBlockOverlayActive( clientId );
Expand Down Expand Up @@ -605,7 +605,7 @@ function BlockListBlockProvider( props ) {
) && hasSelectedInnerBlock( clientId ),

index: getBlockIndex( clientId ),
blockTitle: match?.title || blockType?.title,
blockTitle: match?.title || _blockType?.title,
isPartOfSelection: _isSelected || isPartOfMultiSelection,
adjustScrolling:
_isSelected || isFirstMultiSelectedBlock( clientId ),
Expand All @@ -629,7 +629,7 @@ function BlockListBlockProvider( props ) {
isMultiSelected &&
! __unstableIsFullySelected() &&
! __unstableSelectionHasUnmergeableBlock(),
'is-reusable': isReusableBlock( blockType ),
'is-reusable': isReusableBlock( _blockType ),
'is-dragging': isBlockBeingDragged( clientId ),
'has-child-selected': isAncestorOfSelectedBlock,
'remove-outline': _isSelected && outlineMode && typing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export function useBlockProps( props = {} ) {

// Ensures it warns only inside the `edit` implementation for the block.
if ( name ) {
const blockType = getBlockType( name );
const blockApiVersion = blockType?.apiVersion || 1;
const _blockType = getBlockType( name );
const blockApiVersion = _blockType?.apiVersion || 1;
if ( blockApiVersion < 2 ) {
warning(
`Block type "${ name }" must support API version 2 or higher to work correctly with "useBlockProps" method.`
Expand Down
Loading