Skip to content

Commit

Permalink
Use in InnerBlocks.Content internally
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 12, 2020
1 parent 1a0cec1 commit f3ce3f2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 32 deletions.
5 changes: 1 addition & 4 deletions packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { forwardRef, useRef } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import {
getBlockType,
withBlockContentContext,
__unstableGetInnerBlocksProps as getInnerBlocksProps,
} from '@wordpress/blocks';

Expand Down Expand Up @@ -190,9 +189,7 @@ useInnerBlocksProps.save = getInnerBlocksProps;
ForwardedInnerBlocks.DefaultBlockAppender = DefaultBlockAppender;
ForwardedInnerBlocks.ButtonBlockAppender = ButtonBlockAppender;

ForwardedInnerBlocks.Content = withBlockContentContext(
( { BlockContent } ) => <BlockContent />
);
ForwardedInnerBlocks.Content = () => useInnerBlocksProps.save().children;

/**
* @see https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/inner-blocks/README.md
Expand Down
8 changes: 2 additions & 6 deletions packages/block-library/src/buttons/save.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/**
* WordPress dependencies
*/
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';

export default function save() {
return (
<div { ...useBlockProps.save() }>
<InnerBlocks.Content />
</div>
);
return <div { ...useInnerBlocksProps.save( useBlockProps.save() ) } />;
}
10 changes: 6 additions & 4 deletions packages/block-library/src/cover/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import {
InnerBlocks,
useInnerBlocksProps,
getColorClassName,
__experimentalGetGradientClass,
useBlockProps,
Expand Down Expand Up @@ -122,9 +122,11 @@ export default function save( { attributes } ) {
style={ videoStyle }
/>
) }
<div className="wp-block-cover__inner-container">
<InnerBlocks.Content />
</div>
<div
{ ...useInnerBlocksProps.save( {
className: 'wp-block-cover__inner-container',
} ) }
/>
</div>
);
}
10 changes: 6 additions & 4 deletions packages/block-library/src/group/save.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/**
* WordPress dependencies
*/
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
import { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { tagName: Tag } = attributes;

return (
<Tag { ...useBlockProps.save() }>
<div className="wp-block-group__inner-container">
<InnerBlocks.Content />
</div>
<div
{ ...useInnerBlocksProps.save( {
className: 'wp-block-group__inner-container',
} ) }
/>
</Tag>
);
}
10 changes: 6 additions & 4 deletions packages/block-library/src/media-text/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { noop, isEmpty } from 'lodash';
/**
* WordPress dependencies
*/
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
import { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand Down Expand Up @@ -95,9 +95,11 @@ export default function save( { attributes } ) {
>
{ ( mediaTypeRenders[ mediaType ] || noop )() }
</figure>
<div className="wp-block-media-text__content">
<InnerBlocks.Content />
</div>
<div
{ ...useInnerBlocksProps.save( {
className: 'wp-block-media-text__content',
} ) }
/>
</div>
);
}
13 changes: 3 additions & 10 deletions packages/blocks/src/api/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
getUnregisteredTypeHandlerName,
} from './registration';
import { normalizeBlockType } from './utils';
import BlockContentProvider from '../block-content-provider';

/**
* @typedef {Object} WPBlockSerializationOptions Serialization Options.
Expand Down Expand Up @@ -139,9 +138,9 @@ export function getSaveElement(
let element = save( { attributes, innerBlocks } );

if (
! blockType.apiVersion &&
isObject( element ) &&
hasFilter( 'blocks.getSaveContent.extraProps' ) &&
! blockType.apiVersion
hasFilter( 'blocks.getSaveContent.extraProps' )
) {
/**
* Filters the props applied to the block save result element.
Expand Down Expand Up @@ -169,18 +168,12 @@ export function getSaveElement(
* @param {WPBlock} blockType Block type definition.
* @param {Object} attributes Block attributes.
*/
element = applyFilters(
return applyFilters(
'blocks.getSaveElement',
element,
blockType,
attributes
);

return (
<BlockContentProvider innerBlocks={ innerBlocks }>
{ element }
</BlockContentProvider>
);
}

/**
Expand Down

0 comments on commit f3ce3f2

Please sign in to comment.