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: move new props to hook #22212

Merged
merged 2 commits into from
May 8, 2020
Merged
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
20 changes: 12 additions & 8 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function BlockListBlock( {
isLocked,
clientId,
rootClientId,
isHighlighted,
isSelected,
isMultiSelected,
isPartOfMultiSelection,
Expand All @@ -66,9 +65,13 @@ function BlockListBlock( {
// In addition to withSelect, we should favor using useSelect in this
// component going forward to avoid leaking new props to the public API
// (editor.BlockListBlock filter)
const { isDraggingBlocks } = useSelect( ( select ) => {
const { isDragging, isHighlighted } = useSelect( ( select ) => {
const { isDraggingBlocks, isBlockHighlighted } = select(
'core/block-editor'
);
return {
isDraggingBlocks: select( 'core/block-editor' ).isDraggingBlocks(),
isDragging: isDraggingBlocks(),
isHighlighted: isBlockHighlighted( clientId ),
};
}, [] );

Expand All @@ -83,8 +86,6 @@ function BlockListBlock( {
false
);
const isUnregisteredBlock = name === getUnregisteredTypeHandlerName();
const isDragging =
isDraggingBlocks && ( isSelected || isPartOfMultiSelection );

// Determine whether the block has props to apply to the wrapper.
if ( blockType.getEditWrapperProps ) {
Expand Down Expand Up @@ -113,7 +114,8 @@ function BlockListBlock( {
'is-highlighted': isHighlighted,
'is-multi-selected': isMultiSelected,
'is-reusable': isReusableBlock( blockType ),
'is-dragging': isDragging,
'is-dragging':
isDragging && ( isSelected || isPartOfMultiSelection ),
'is-typing': isTypingWithinBlock,
'is-focused':
isFocusMode && ( isSelected || isAncestorOfSelectedBlock ),
Expand Down Expand Up @@ -219,7 +221,6 @@ const applyWithSelect = withSelect(
getTemplateLock,
__unstableGetBlockWithoutInnerBlocks,
isNavigationMode,
isBlockHighlighted,
} = select( 'core/block-editor' );
const block = __unstableGetBlockWithoutInnerBlocks( clientId );
const isSelected = isBlockSelected( clientId );
Expand All @@ -239,8 +240,9 @@ const applyWithSelect = withSelect(
// is not correct.
const { name, attributes, isValid } = block || {};

// Do not add new properties here, use `useSelect` instead to avoid
// leaking new props to the public API (editor.BlockListBlock filter).
return {
isHighlighted: isBlockHighlighted( clientId ),
isMultiSelected: isBlockMultiSelected( clientId ),
isPartOfMultiSelection:
isBlockMultiSelected( clientId ) ||
Expand Down Expand Up @@ -287,6 +289,8 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, { select } ) => {
__unstableMarkLastChangeAsPersistent,
} = dispatch( 'core/block-editor' );

// Do not add new properties here, use `useDispatch` instead to avoid
// leaking new props to the public API (editor.BlockListBlock filter).
return {
setAttributes( newAttributes ) {
const { clientId } = ownProps;
Expand Down