-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import Format API components instead of passing as props (#11545)
* Import Format API components instead of passing as props * Include button title in inserter search * Simplify isResult * RichTextInserterListItem => RichTextInserterItem
- Loading branch information
1 parent
62c4f80
commit 5338625
Showing
12 changed files
with
139 additions
and
116 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
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
38 changes: 38 additions & 0 deletions
38
packages/editor/src/components/rich-text/inserter-list-item.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,38 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { normalizeIconObject } from '@wordpress/blocks'; | ||
import { Fill } from '@wordpress/components'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import InserterListItem from '../inserter-list-item'; | ||
import { normalizeTerm } from '../inserter/menu'; | ||
|
||
function isResult( keywords, filterValue ) { | ||
return keywords.some( ( string ) => | ||
normalizeTerm( string ).indexOf( normalizeTerm( filterValue ) ) !== -1 | ||
); | ||
} | ||
|
||
export const RichTextInserterItem = withSelect( ( select, { name } ) => ( { | ||
formatType: select( 'core/rich-text' ).getFormatType( name ), | ||
} ) )( ( props ) => { | ||
return ( | ||
<Fill name="Inserter.InlineElements"> | ||
{ ( { filterValue } ) => { | ||
const { keywords = [], title } = props.formatType; | ||
|
||
keywords.push( title, props.title ); | ||
|
||
if ( filterValue && ! isResult( keywords, filterValue ) ) { | ||
return null; | ||
} | ||
|
||
return <InserterListItem { ...props } icon={ normalizeIconObject( props.icon ) } />; | ||
} } | ||
</Fill> | ||
); | ||
} ); |
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,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
import { KeyboardShortcuts } from '@wordpress/components'; | ||
import { rawShortcut } from '@wordpress/keycodes'; | ||
|
||
export class RichTextShortcut extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.onUse = this.onUse.bind( this ); | ||
} | ||
|
||
onUse() { | ||
this.props.onUse(); | ||
return false; | ||
} | ||
|
||
render() { | ||
const { character, type } = this.props; | ||
|
||
return ( | ||
<KeyboardShortcuts | ||
bindGlobal | ||
shortcuts={ { | ||
[ rawShortcut[ type ]( character ) ]: this.onUse, | ||
} } | ||
/> | ||
); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/editor/src/components/rich-text/toolbar-button.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 { Fill, ToolbarButton } from '@wordpress/components'; | ||
import { displayShortcut } from '@wordpress/keycodes'; | ||
|
||
export function RichTextToolbarButton( { name, shortcutType, shortcutCharacter, ...props } ) { | ||
let shortcut; | ||
let fillName = 'RichText.ToolbarControls'; | ||
|
||
if ( name ) { | ||
fillName += `.${ name }`; | ||
} | ||
|
||
if ( shortcutType && shortcutCharacter ) { | ||
shortcut = displayShortcut[ shortcutType ]( shortcutCharacter ); | ||
} | ||
|
||
return ( | ||
<Fill name={ fillName }> | ||
<ToolbarButton | ||
{ ...props } | ||
shortcut={ shortcut } | ||
/> | ||
</Fill> | ||
); | ||
} |
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.