-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 List: Use default Inserter for sibling insertion #11018
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d073055
Block List: Use default Inserter for sibling insertion
aduth 4d2688c
Editor: Refactor insertion point to support assignment
aduth 32a2aa6
Block List: Render BlockInsertionPoint with explicit inserter values
aduth 50fdd4e
Testing: Update sibling inserter E2E test
aduth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -6,12 +6,14 @@ import classnames from 'classnames'; | |
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { isUnmodifiedDefaultBlock } from '@wordpress/blocks'; | ||
import { Component } from '@wordpress/element'; | ||
import { IconButton } from '@wordpress/components'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { ifCondition, compose } from '@wordpress/compose'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Inserter from '../inserter'; | ||
|
||
class BlockInsertionPoint extends Component { | ||
constructor() { | ||
|
@@ -22,12 +24,12 @@ class BlockInsertionPoint extends Component { | |
|
||
this.onBlurInserter = this.onBlurInserter.bind( this ); | ||
this.onFocusInserter = this.onFocusInserter.bind( this ); | ||
this.onClick = this.onClick.bind( this ); | ||
} | ||
|
||
onFocusInserter( event ) { | ||
// We stop propagation of the focus event to avoid selecting the current block | ||
// While we're trying to insert a new block | ||
// Stop propagation of the focus event to avoid selecting the current | ||
// block while inserting a new block, as it is not relevant to sibling | ||
// insertion and conflicts with contextual toolbar placement. | ||
event.stopPropagation(); | ||
|
||
this.setState( { | ||
|
@@ -41,77 +43,57 @@ class BlockInsertionPoint extends Component { | |
} ); | ||
} | ||
|
||
onClick() { | ||
const { rootClientId, index, ...props } = this.props; | ||
props.insertDefaultBlock( undefined, rootClientId, index ); | ||
props.startTyping(); | ||
this.onBlurInserter(); | ||
if ( props.onInsert ) { | ||
this.props.onInsert(); | ||
} | ||
} | ||
|
||
render() { | ||
const { isInserterFocused } = this.state; | ||
const { showInsertionPoint, showInserter } = this.props; | ||
const { | ||
showInsertionPoint, | ||
canShowInserter, | ||
rootClientId, | ||
insertIndex, | ||
} = this.props; | ||
|
||
return ( | ||
<div className="editor-block-list__insertion-point"> | ||
{ showInsertionPoint && <div className="editor-block-list__insertion-point-indicator" /> } | ||
{ showInserter && ( | ||
<div className={ classnames( 'editor-block-list__insertion-point-inserter', { 'is-visible': isInserterFocused } ) }> | ||
<IconButton | ||
icon="insert" | ||
className="editor-block-list__insertion-point-button" | ||
onClick={ this.onClick } | ||
label={ __( 'Insert block' ) } | ||
onFocus={ this.onFocusInserter } | ||
onBlur={ this.onBlurInserter } | ||
{ showInsertionPoint && ( | ||
<div className="editor-block-list__insertion-point-indicator" /> | ||
) } | ||
{ canShowInserter && ( | ||
<div | ||
onFocus={ this.onFocusInserter } | ||
onBlur={ this.onBlurInserter } | ||
className={ | ||
classnames( 'editor-block-list__insertion-point-inserter', { | ||
'is-visible': isInserterFocused, | ||
} ) | ||
} | ||
> | ||
<Inserter | ||
rootClientId={ rootClientId } | ||
index={ insertIndex } | ||
/> | ||
</div> | ||
) } | ||
</div> | ||
); | ||
} | ||
} | ||
export default compose( | ||
withSelect( ( select, { clientId, rootClientId, canShowInserter } ) => { | ||
const { | ||
canInsertBlockType, | ||
getBlockIndex, | ||
getBlockInsertionPoint, | ||
getBlock, | ||
isBlockInsertionPointVisible, | ||
isTyping, | ||
} = select( 'core/editor' ); | ||
const { | ||
getDefaultBlockName, | ||
} = select( 'core/blocks' ); | ||
const blockIndex = clientId ? getBlockIndex( clientId, rootClientId ) : -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
const insertIndex = blockIndex; | ||
const insertionPoint = getBlockInsertionPoint(); | ||
const block = clientId ? getBlock( clientId ) : null; | ||
const showInsertionPoint = ( | ||
isBlockInsertionPointVisible() && | ||
insertionPoint.index === insertIndex && | ||
insertionPoint.rootClientId === rootClientId && | ||
( ! block || ! isUnmodifiedDefaultBlock( block ) ) | ||
); | ||
export default withSelect( ( select, { clientId, rootClientId } ) => { | ||
const { | ||
getBlockIndex, | ||
getBlockInsertionPoint, | ||
getBlock, | ||
isBlockInsertionPointVisible, | ||
} = select( 'core/editor' ); | ||
const blockIndex = getBlockIndex( clientId, rootClientId ); | ||
const insertIndex = blockIndex; | ||
const insertionPoint = getBlockInsertionPoint(); | ||
const block = getBlock( clientId ); | ||
const showInsertionPoint = ( | ||
isBlockInsertionPointVisible() && | ||
insertionPoint.index === insertIndex && | ||
insertionPoint.rootClientId === rootClientId && | ||
! isUnmodifiedDefaultBlock( block ) | ||
); | ||
|
||
const defaultBlockName = getDefaultBlockName(); | ||
return { | ||
canInsertDefaultBlock: canInsertBlockType( defaultBlockName, rootClientId ), | ||
showInserter: ! isTyping() && canShowInserter, | ||
index: insertIndex, | ||
showInsertionPoint, | ||
}; | ||
} ), | ||
ifCondition( ( { canInsertDefaultBlock } ) => canInsertDefaultBlock ), | ||
withDispatch( ( dispatch ) => { | ||
const { insertDefaultBlock, startTyping } = dispatch( 'core/editor' ); | ||
return { | ||
insertDefaultBlock, | ||
startTyping, | ||
}; | ||
} ) | ||
)( BlockInsertionPoint ); | ||
return { showInsertionPoint, insertIndex }; | ||
} )( BlockInsertionPoint ); |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was wrong before;
isFirst
means first of an entirerootClientId
context, not first in a multi-selection.gutenberg/packages/editor/src/components/block-list/index.js
Line 218 in b022ad2