Skip to content

Commit

Permalink
Block Edit: Remove legacy context API child context (#7869)
Browse files Browse the repository at this point in the history
* Block Edit: Remove legacy context API child context

* Testing: Fix BlockEdit import
  • Loading branch information
aduth authored and gziolo committed Jul 11, 2018
1 parent 88d133d commit 5e59893
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
6 changes: 1 addition & 5 deletions core-blocks/test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down
31 changes: 5 additions & 26 deletions editor/components/block-edit/index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
/**
* 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
*/
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 ) {
Expand Down Expand Up @@ -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;
6 changes: 4 additions & 2 deletions editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) {
Expand Down Expand Up @@ -934,7 +934,6 @@ export class RichText extends Component {
RichText.contextTypes = {
onUndo: noop,
onRedo: noop,
canUserUseUnfilteredHTML: noop,
onCreateUndoLevel: noop,
};

Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 5e59893

Please sign in to comment.