Skip to content

Commit

Permalink
Editor: Use store to always have up to date list of format types (#11483
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gziolo authored Nov 5, 2018
1 parent e7ec3b3 commit c8b4679
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
17 changes: 13 additions & 4 deletions packages/editor/src/components/rich-text/format-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* WordPress dependencies
*/
import { normalizeIconObject } from '@wordpress/blocks';
import { withSelect } from '@wordpress/data';
import { Component, Fragment } from '@wordpress/element';
import { getActiveFormat, getFormatTypes } from '@wordpress/rich-text';
import { getActiveFormat } from '@wordpress/rich-text';
import { Fill, KeyboardShortcuts, ToolbarButton } from '@wordpress/components';
import { rawShortcut, displayShortcut } from '@wordpress/keycodes';

Expand Down Expand Up @@ -81,10 +82,10 @@ class Shortcut extends Component {
}
}

const FormatEdit = ( { onChange, value } ) => {
const FormatEdit = ( { formatTypes, onChange, value } ) => {
return (
<Fragment>
{ getFormatTypes().map( ( { name, edit: Edit, keywords } ) => {
{ formatTypes.map( ( { name, edit: Edit, keywords } ) => {
if ( ! Edit ) {
return null;
}
Expand Down Expand Up @@ -115,4 +116,12 @@ const FormatEdit = ( { onChange, value } ) => {
);
};

export default FormatEdit;
export default withSelect(
( select ) => {
const { getFormatTypes } = select( 'core/rich-text' );

return {
formatTypes: getFormatTypes(),
};
}
)( FormatEdit );
1 change: 1 addition & 0 deletions packages/editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '@wordpress/blocks';
import '@wordpress/core-data';
import '@wordpress/notices';
import '@wordpress/nux';
import '@wordpress/rich-text';
import '@wordpress/viewport';

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/rich-text/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export { charAt } from './char-at';
export { concat } from './concat';
export { create } from './create';
export { getActiveFormat } from './get-active-format';
export { getFormatType } from './get-format-type';
export { getFormatTypes } from './get-format-types';
export { getSelectionEnd } from './get-selection-end';
export { getSelectionStart } from './get-selection-start';
export { getTextContent } from './get-text-content';
Expand Down

0 comments on commit c8b4679

Please sign in to comment.