Skip to content

Commit

Permalink
Inner Blocks: Respecting locking in display of default block appender (
Browse files Browse the repository at this point in the history
…#7732)

* Block List: Avoid rendering default appender if locked

* Inner Blocks: Prepare locking for initial InnerBlocks render

* Inner Blocks: Avoid synchronizing template on mismatch update
  • Loading branch information
aduth authored Jul 5, 2018
1 parent 622bbfb commit dd6d2c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
23 changes: 15 additions & 8 deletions editor/components/block-list/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'element-closest';
*/
import { Component, compose } from '@wordpress/element';
import { withSelect, withDispatch } from '@wordpress/data';
import { getDefaultBlockName } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -193,6 +194,7 @@ class BlockListLayout extends Component {
layout,
isGroupedByLayout,
rootUID,
canInsertDefaultBlock,
} = this.props;

let defaultLayout;
Expand Down Expand Up @@ -220,34 +222,39 @@ class BlockListLayout extends Component {
isLast={ blockIndex === blockUIDs.length - 1 }
/>
) ) }
<IgnoreNestedEvents childHandledEvents={ [ 'onFocus', 'onClick', 'onKeyDown' ] }>
<DefaultBlockAppender
rootUID={ rootUID }
lastBlockUID={ last( blockUIDs ) }
layout={ defaultLayout }
/>
</IgnoreNestedEvents>
{ canInsertDefaultBlock && (
<IgnoreNestedEvents childHandledEvents={ [ 'onFocus', 'onClick', 'onKeyDown' ] }>
<DefaultBlockAppender
rootUID={ rootUID }
lastBlockUID={ last( blockUIDs ) }
layout={ defaultLayout }
/>
</IgnoreNestedEvents>
) }
</div>
);
}
}

export default compose( [
withSelect( ( select ) => {
withSelect( ( select, ownProps ) => {
const {
isSelectionEnabled,
isMultiSelecting,
getMultiSelectedBlocksStartUid,
getMultiSelectedBlocksEndUid,
getBlockSelectionStart,
canInsertBlockType,
} = select( 'core/editor' );
const { rootUID } = ownProps;

return {
selectionStart: getMultiSelectedBlocksStartUid(),
selectionEnd: getMultiSelectedBlocksEndUid(),
selectionStartUID: getBlockSelectionStart(),
isSelectionEnabled: isSelectionEnabled(),
isMultiSelecting: isMultiSelecting(),
canInsertDefaultBlock: canInsertBlockType( getDefaultBlockName(), rootUID ),
};
} ),
withDispatch( ( dispatch ) => {
Expand Down
16 changes: 8 additions & 8 deletions editor/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ import BlockList from '../block-list';
import { withBlockEditContext } from '../block-edit/context';

class InnerBlocks extends Component {
componentDidMount() {
constructor() {
super( ...arguments );

this.updateNestedSettings();
}

componentDidMount() {
this.synchronizeBlocksWithTemplate();
}

componentDidUpdate( prevProps ) {
const { template, block } = this.props;
const { template } = this.props;

this.updateNestedSettings();

const hasTemplateChanged = ! isEqual( template, prevProps.template );
const isTemplateInnerBlockMismatch = (
template &&
block.innerBlocks.length !== template.length
);

if ( hasTemplateChanged || isTemplateInnerBlockMismatch ) {
if ( hasTemplateChanged ) {
this.synchronizeBlocksWithTemplate();
}
}
Expand Down

0 comments on commit dd6d2c2

Please sign in to comment.