Skip to content
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

Block Edit: Remove legacy context API child context #7869

Merged
merged 2 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Member

@gziolo gziolo Jul 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more hacks 😄


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 @@ -357,7 +357,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 @@ -986,7 +986,6 @@ export class RichText extends Component {
RichText.contextTypes = {
onUndo: noop,
onRedo: noop,
canUserUseUnfilteredHTML: noop,
onCreateUndoLevel: noop,
};

Expand All @@ -1009,6 +1008,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 @@ -1017,9 +1017,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