diff --git a/packages/block-editor/src/components/block-list/block-wrapper.js b/packages/block-editor/src/components/block-list/block-wrapper.js index c728b2a8a01364..d81cba761357dd 100644 --- a/packages/block-editor/src/components/block-list/block-wrapper.js +++ b/packages/block-editor/src/components/block-list/block-wrapper.js @@ -19,6 +19,7 @@ import { focus, isTextField, placeCaretAtHorizontalEdge } from '@wordpress/dom'; import { BACKSPACE, DELETE, ENTER } from '@wordpress/keycodes'; import { __, sprintf } from '@wordpress/i18n'; import { useSelect, useDispatch } from '@wordpress/data'; +import { __unstableBlockPropsFilterContext as BlockPropsFilterContext } from '@wordpress/blocks'; /** * Internal dependencies @@ -235,6 +236,22 @@ const elements = [ 'nav', ]; +const BlockSaveComponent = forwardRef( + ( { children, tagName: TagName = 'div', ...props }, wrapper ) => { + return ( + + { ( filter ) => { + return ( + + { children } + + ); + } } + + ); + } +); + const ExtendedBlockComponent = elements.reduce( ( acc, element ) => { acc[ element ] = forwardRef( ( props, ref ) => { return ; @@ -242,4 +259,13 @@ const ExtendedBlockComponent = elements.reduce( ( acc, element ) => { return acc; }, BlockComponent ); +ExtendedBlockComponent.Save = elements.reduce( ( acc, element ) => { + acc[ element ] = forwardRef( ( props, ref ) => { + return ( + + ); + } ); + return acc; +}, BlockSaveComponent ); + export const Block = ExtendedBlockComponent; diff --git a/packages/block-library/src/column/save.js b/packages/block-library/src/column/save.js index d0dda9de3174b3..ea938c3417cc24 100644 --- a/packages/block-library/src/column/save.js +++ b/packages/block-library/src/column/save.js @@ -6,7 +6,10 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { InnerBlocks } from '@wordpress/block-editor'; +import { + InnerBlocks, + __experimentalBlock as Block, +} from '@wordpress/block-editor'; export default function save( { attributes } ) { const { verticalAlignment, width } = attributes; @@ -21,8 +24,8 @@ export default function save( { attributes } ) { } return ( -
+ -
+ ); } diff --git a/packages/block-library/src/columns/save.js b/packages/block-library/src/columns/save.js index 3d2249389910d2..785cdf8205af99 100644 --- a/packages/block-library/src/columns/save.js +++ b/packages/block-library/src/columns/save.js @@ -6,7 +6,11 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { InnerBlocks, getColorClassName } from '@wordpress/block-editor'; +import { + InnerBlocks, + getColorClassName, + __experimentalBlock as Block, +} from '@wordpress/block-editor'; export default function save( { attributes } ) { const { @@ -38,8 +42,11 @@ export default function save( { attributes } ) { }; return ( -
+ -
+ ); } diff --git a/packages/block-library/src/image/save.js b/packages/block-library/src/image/save.js index 4124e9c951e382..6235bd9203a3d7 100644 --- a/packages/block-library/src/image/save.js +++ b/packages/block-library/src/image/save.js @@ -7,7 +7,10 @@ import { isEmpty } from 'lodash'; /** * WordPress dependencies */ -import { RichText } from '@wordpress/block-editor'; +import { + RichText, + __experimentalBlock as Block, +} from '@wordpress/block-editor'; export default function save( { attributes } ) { const { @@ -67,11 +70,13 @@ export default function save( { attributes } ) { if ( 'left' === align || 'right' === align || 'center' === align ) { return ( -
+
{ figure }
-
+ ); } - return
{ figure }
; + return ( + { figure } + ); } diff --git a/packages/block-library/src/paragraph/save.js b/packages/block-library/src/paragraph/save.js index 2cdeeb46e60c9c..b70f810c60e174 100644 --- a/packages/block-library/src/paragraph/save.js +++ b/packages/block-library/src/paragraph/save.js @@ -10,6 +10,7 @@ import { getColorClassName, getFontSizeClass, RichText, + __experimentalBlock as Block, } from '@wordpress/block-editor'; export default function save( { attributes } ) { @@ -51,7 +52,7 @@ export default function save( { attributes } ) { return ( props; + + if ( hasFilter( 'blocks.getSaveContent.extraProps' ) ) { + if ( hasBlockSupport( blockType, 'lightBlockWrapper', false ) ) { + blockPropsFilter = ( props ) => { + /** + * Filters the props applied to the block save result element. + * + * @param {Object} props Props applied to save element. + * @param {WPBlock} blockType Block type definition. + * @param {Object} attributes Block attributes. + */ + return applyFilters( + 'blocks.getSaveContent.extraProps', + { ...props }, + blockType, + attributes + ); + }; + } else if ( isObject( element ) ) { + /** + * Filters the props applied to the block save result element. + * + * @param {Object} props Props applied to save element. + * @param {WPBlock} blockType Block type definition. + * @param {Object} attributes Block attributes. + */ + const props = applyFilters( + 'blocks.getSaveContent.extraProps', + { ...element.props }, + blockType, + attributes + ); - if ( - isObject( element ) && - hasFilter( 'blocks.getSaveContent.extraProps' ) - ) { - /** - * Filters the props applied to the block save result element. - * - * @param {Object} props Props applied to save element. - * @param {WPBlock} blockType Block type definition. - * @param {Object} attributes Block attributes. - */ - const props = applyFilters( - 'blocks.getSaveContent.extraProps', - { ...element.props }, - blockType, - attributes - ); - - if ( ! isShallowEqual( props, element.props ) ) { - element = cloneElement( element, props ); + if ( ! isShallowEqual( props, element.props ) ) { + element = cloneElement( element, props ); + } } } @@ -134,9 +158,11 @@ export function getSaveElement( ); return ( - - { element } - + + + { element } + + ); }