Skip to content

Commit

Permalink
Pass block context differently
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Sep 25, 2020
1 parent f27f81e commit 3f6715a
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 27 deletions.
3 changes: 2 additions & 1 deletion packages/block-library/src/audio/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const { autoplay, caption, loop, preload, src } = attributes;

return (
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/button/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import getColorAndStyleProps from './color-props';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const { borderRadius, linkTarget, rel, text, title, url } = attributes;
const colorProps = getColorAndStyleProps( attributes );
const buttonClasses = classnames(
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/buttons/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { getBlockProps } ) {
export default function save() {
return (
<div { ...getBlockProps() }>
<InnerBlocks.Content />
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/code/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { escape } from './utils';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
return (
<pre { ...getBlockProps() }>
<RichText.Content
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/column/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const { verticalAlignment, width } = attributes;

const wrapperClasses = classnames( {
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/columns/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const { verticalAlignment } = attributes;

const className = classnames( {
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/cover/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getColorClassName,
__experimentalGetGradientClass,
} from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -24,7 +25,7 @@ import {
getPositionClassName,
} from './shared';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const {
backgroundType,
gradient,
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/group/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

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

return (
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/heading/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const { align, content, level } = attributes;
const TagName = 'h' + level;

Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/image/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { isEmpty } from 'lodash';
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const {
url,
alt,
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/list/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const { ordered, values, type, reversed, start } = attributes;
const TagName = ordered ? 'ol' : 'ul';

Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/media-text/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { noop, isEmpty } from 'lodash';
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -17,7 +18,7 @@ import { DEFAULT_MEDIA_SIZE_SLUG } from './constants';

const DEFAULT_MEDIA_WIDTH = 50;

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const {
isStackedOnMobile,
mediaAlt,
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/paragraph/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const { align, content, dropCap, direction } = attributes;
const className = classnames( {
'has-drop-cap': dropCap,
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/preformatted/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const { content } = attributes;

return (
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/quote/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const { align, value, citation } = attributes;

const className = classnames( {
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/social-links/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { getBlockProps } ) {
export default function save() {
return (
<ul { ...getBlockProps() }>
<InnerBlocks.Content />
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/verse/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const { textAlign, content } = attributes;

const className = classnames( {
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/video/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

export default function save( { attributes, getBlockProps } ) {
export default function save( { attributes } ) {
const {
autoplay,
caption,
Expand Down
4 changes: 4 additions & 0 deletions packages/blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ _Returns_

- `string`: The block's default menu item class.

<a name="getBlockProps" href="#getBlockProps">#</a> **getBlockProps**

Undocumented declaration.

<a name="getBlockSupport" href="#getBlockSupport">#</a> **getBlockSupport**

Returns the block support value for a feature, if defined.
Expand Down
1 change: 1 addition & 0 deletions packages/blocks/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export {
getBlockMenuDefaultClassName,
getSaveElement,
getSaveContent,
getBlockProps,
} from './serializer';
export { isValidBlockContent } from './validation';
export { getCategories, setCategories, updateCategory } from './categories';
Expand Down
24 changes: 15 additions & 9 deletions packages/blocks/src/api/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ export function getBlockMenuDefaultClassName( blockName ) {
);
}

const blockPropsProvider = {};

export function getBlockProps( props ) {
const { blockType, attributes } = blockPropsProvider;
return applyFilters(
'blocks.getSaveContent.extraProps',
{ ...props },
blockType,
attributes
);
}

/**
* Given a block type containing a save render implementation and attributes, returns the
* enhanced element to be saved or string when raw HTML expected.
Expand All @@ -95,16 +107,10 @@ export function getSaveElement(
save = instance.render.bind( instance );
}

function getBlockProps( props ) {
return applyFilters(
'blocks.getSaveContent.extraProps',
{ ...props },
blockType,
attributes
);
}
blockPropsProvider.blockType = blockType;
blockPropsProvider.attributes = attributes;

let element = save( { attributes, innerBlocks, getBlockProps } );
let element = save( { attributes, innerBlocks } );

if (
isObject( element ) &&
Expand Down

0 comments on commit 3f6715a

Please sign in to comment.