Skip to content

Commit

Permalink
Fix previews for blocks using InnerBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 10, 2019
1 parent 94d48e0 commit 9946176
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
31 changes: 16 additions & 15 deletions packages/block-editor/src/components/block-preview/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/**
* External dependencies
*/
import { noop } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { createBlock } from '@wordpress/blocks';
import { Disabled } from '@wordpress/components';
import { withSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import BlockEdit from '../block-edit';
import BlockEditorProvider from '../provider';
import BlockList from '../block-list';

/**
* Block Preview Component: It renders a preview given a block name and attributes.
Expand All @@ -31,18 +28,22 @@ function BlockPreview( props ) {
);
}

export function BlockPreviewContent( { name, attributes } ) {
const block = createBlock( name, attributes );
export function BlockPreviewContent( { name, attributes, innerBlocks, settings } ) {
const block = createBlock( name, attributes, innerBlocks );
return (
<Disabled className="editor-block-preview__content block-editor-block-preview__content editor-styles-wrapper" aria-hidden>
<BlockEdit
name={ name }
focus={ false }
attributes={ block.attributes }
setAttributes={ noop }
/>
<BlockEditorProvider
value={ [ block ] }
settings={ settings }
>
<BlockList />
</BlockEditorProvider>
</Disabled>
);
}

export default BlockPreview;
export default withSelect( ( select ) => {
return {
settings: select( 'core/block-editor' ).getSettings(),
};
} )( BlockPreview );
3 changes: 3 additions & 0 deletions packages/block-editor/src/components/block-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function BlockStyles( {
name,
attributes,
type,
block,
onSwitch = noop,
onHoverClassName = noop,
} ) {
Expand Down Expand Up @@ -129,6 +130,7 @@ function BlockStyles( {
...attributes,
className: styleClassName,
} }
innerBlocks={ block.innerBlocks }
/>
</div>
<div className="editor-block-styles__item-label block-editor-block-styles__item-label">
Expand All @@ -149,6 +151,7 @@ export default compose( [
const blockType = getBlockType( block.name );

return {
block,
name: block.name,
attributes: block.attributes,
className: block.attributes.className || '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export class BlockSwitcher extends Component {
<BlockPreview
name={ blocks[ 0 ].name }
attributes={ { ...blocks[ 0 ].attributes, className: hoveredClassName } }
innerBlocks={ blocks[ 0 ].innerBlocks }
/>
}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export default compose(
} ),
withViewportMatch( { isLargeViewport: 'medium' } ),
withSelect( ( select, { clientId, isLargeViewport, isCollapsed } ) => {
const { getBlockRootClientId, getEditorSettings } = select( 'core/editor' );
const { getBlockRootClientId, getSettings } = select( 'core/block-editor' );
return {
isCollapsed: isCollapsed || ! isLargeViewport || (
! getEditorSettings().hasFixedToolbar &&
! getSettings().hasFixedToolbar &&
getBlockRootClientId( clientId )
),
};
Expand Down

0 comments on commit 9946176

Please sign in to comment.