diff --git a/core-blocks/test/helpers/index.js b/core-blocks/test/helpers/index.js index 7231a3fd0fe099..8e7aa54fda8ce4 100644 --- a/core-blocks/test/helpers/index.js +++ b/core-blocks/test/helpers/index.js @@ -12,11 +12,7 @@ import { getBlockType, registerBlockType, } from '@wordpress/blocks'; -// Requiredd to register the editor's store -import '@wordpress/editor'; - -// Hack to avoid the wrapping HoCs. -import { BlockEdit } from '../../../editor/components/block-edit'; +import { BlockEdit } from '@wordpress/editor'; export const blockEditRender = ( name, settings ) => { if ( ! getBlockType( name ) ) { diff --git a/editor/components/block-edit/index.js b/editor/components/block-edit/index.js index c5adb12ba5e4e4..87ddb69ca48035 100644 --- a/editor/components/block-edit/index.js +++ b/editor/components/block-edit/index.js @@ -1,13 +1,7 @@ -/** - * External dependencies - */ -import { noop } from 'lodash'; - /** * WordPress dependencies */ -import { withSelect } from '@wordpress/data'; -import { Component, compose } from '@wordpress/element'; +import { Component } from '@wordpress/element'; /** * Internal dependencies @@ -15,24 +9,18 @@ import { Component, compose } from '@wordpress/element'; import Edit from './edit'; import { BlockEditContextProvider } from './context'; -export class BlockEdit extends Component { +class BlockEdit extends Component { constructor( props ) { super( props ); + this.setFocusedElement = this.setFocusedElement.bind( this ); + this.state = { focusedElement: null, setFocusedElement: this.setFocusedElement, }; } - getChildContext() { - const { canUserUseUnfilteredHTML } = this.props; - - return { - canUserUseUnfilteredHTML, - }; - } - setFocusedElement( focusedElement ) { this.setState( ( prevState ) => { if ( prevState.focusedElement === focusedElement ) { @@ -61,13 +49,4 @@ export class BlockEdit extends Component { } } -BlockEdit.childContextTypes = { - canUserUseUnfilteredHTML: noop, -}; - -export default compose( [ - withSelect( ( select ) => ( { - postType: select( 'core/editor' ).getEditedPostAttribute( 'type' ), - canUserUseUnfilteredHTML: select( 'core/editor' ).canUserUseUnfilteredHTML(), - } ) ), -] )( BlockEdit ); +export default BlockEdit; diff --git a/editor/components/rich-text/index.js b/editor/components/rich-text/index.js index 50005fafdcd006..0d757fd3974cca 100644 --- a/editor/components/rich-text/index.js +++ b/editor/components/rich-text/index.js @@ -354,7 +354,7 @@ export class RichText extends Component { plainText: this.pastedPlainText, mode, tagName: this.props.tagName, - canUserUseUnfilteredHTML: this.context.canUserUseUnfilteredHTML, + canUserUseUnfilteredHTML: this.props.canUserUseUnfilteredHTML, } ); if ( typeof content === 'string' ) { @@ -934,7 +934,6 @@ export class RichText extends Component { RichText.contextTypes = { onUndo: noop, onRedo: noop, - canUserUseUnfilteredHTML: noop, onCreateUndoLevel: noop, }; @@ -957,6 +956,7 @@ const RichTextContainer = compose( [ isSelected: context.isSelected, }; } + // Ensures that only one RichText component can be focused. return { isSelected: context.isSelected && context.focusedElement === ownProps.instanceId, @@ -965,9 +965,11 @@ const RichTextContainer = compose( [ } ), withSelect( ( select ) => { const { isViewportMatch = identity } = select( 'core/viewport' ) || {}; + const { canUserUseUnfilteredHTML } = select( 'core/editor' ); return { isViewportSmall: isViewportMatch( '< small' ), + canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(), }; } ), withSafeTimeout,