-
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
Replace the side inserter by an inserter with shortcuts on empty paragraphs #4953
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
99a6e16
Replace the side inserter by an inserter with shortcuts on empty para…
youknowriad efd3fa3
Use Block insert frequency to fill the quick inserter
youknowriad a611508
Fix showing/hiding the inserter on type
youknowriad 5bffc9b
Fix border radius
youknowriad 9c6459b
Some tweaks per review
youknowriad f2fa42f
Hide insertion point when replacing a block
youknowriad e723bad
Restore removed onChange callback
youknowriad dbad796
Empty paragraph blocks should always appear unselected
youknowriad 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
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,76 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import { filter, isEmpty } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BlockIcon, createBlock, getDefaultBlockName } from '@wordpress/blocks'; | ||
import { compose } from '@wordpress/element'; | ||
import { IconButton, withContext } from '@wordpress/components'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import Inserter from '../inserter'; | ||
import { getFrequentInserterItems } from '../../store/selectors'; | ||
import { replaceBlocks } from '../../store/actions'; | ||
|
||
function InserterWithShortcuts( { items, isLocked, onToggle, onInsert } ) { | ||
if ( isLocked ) { | ||
return null; | ||
} | ||
|
||
const itemsWithoutDefaultBlock = filter( items, ( item ) => | ||
item.name !== getDefaultBlockName() || ! isEmpty( item.initialAttributes ) | ||
).slice( 0, 2 ); | ||
|
||
return ( | ||
<div className="editor-inserter-with-shortcuts"> | ||
<Inserter | ||
position="top left" | ||
onToggle={ onToggle } | ||
/> | ||
|
||
{ itemsWithoutDefaultBlock.map( ( item ) => ( | ||
<IconButton | ||
key={ item.id } | ||
className="editor-inserter-with-shortcuts__block" | ||
onClick={ () => onInsert( item ) } | ||
label={ sprintf( __( 'Add %s' ), item.title ) } | ||
icon={ ( | ||
<span className="editor-inserter-with-shortcuts__block-icon"> | ||
<BlockIcon icon={ item.icon } /> | ||
</span> | ||
) } | ||
/> | ||
) ) } | ||
</div> | ||
); | ||
} | ||
|
||
export default compose( | ||
withContext( 'editor' )( ( settings ) => { | ||
const { templateLock, blockTypes } = settings; | ||
|
||
return { | ||
isLocked: !! templateLock, | ||
enabledBlockTypes: blockTypes, | ||
}; | ||
} ), | ||
connect( | ||
( state, { enabledBlockTypes } ) => ( { | ||
items: getFrequentInserterItems( state, enabledBlockTypes, 3 ), | ||
} ), | ||
( dispatch, { uid, layout } ) => ( { | ||
onInsert( { name, initialAttributes } ) { | ||
const block = createBlock( name, { ...initialAttributes, layout } ); | ||
return dispatch( replaceBlocks( uid, block ) ); | ||
}, | ||
} ) | ||
), | ||
)( InserterWithShortcuts ); |
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,16 @@ | ||
.editor-inserter-with-shortcuts { | ||
display: flex; | ||
align-items: center; | ||
flex-direction: row-reverse; | ||
|
||
.components-icon-button { | ||
border-radius: $button-style__radius-roundrect; | ||
} | ||
} | ||
|
||
.editor-inserter-with-shortcuts__block { | ||
margin-right: 5px; | ||
width: 36px; | ||
height: 36px; | ||
padding-top: 8px; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const PREFERENCES_DEFAULTS = { | ||
recentInserts: [], | ||
insertUsage: {}, | ||
}; |
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.
Why
! isEmpty( item.initialAttributes )
?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.
It's so that shared paragraph blocks don't get filtered out.
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.
As a casual observer, I'd have no hints from the context available to reach this conclusion. Even now, I'm not clear what it is about shared blocks that causes us to filter them.
I'd suggest some combination of code comment and/or explaining variable.