Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks: update remaining child blocks to API version v3 #40685

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: compat

Blocks: ensure all child blocks use the latest version of the Blocks API.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as deprecatedV1 from './v1';

export default [ deprecatedV1 ];
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import PlaceholderSiteIcon from '../../../placeholder-site-icon.svg';

export default {
id: {
type: 'string',
},
name: {
type: 'string',
},
icon: {
type: 'string',
default: PlaceholderSiteIcon,
},
is_non_wpcom_site: {
type: 'boolean',
default: false,
},
url: {
type: 'string',
},
description: {
type: 'string',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { InnerBlocks } from '@wordpress/block-editor';
export { default as attributes } from './attributes';
export { default as supports } from './supports';

export const save = () => <InnerBlocks.Content />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
align: false,
alignWide: true,
anchor: false,
customClassName: true,
className: true,
html: false,
multiple: true,
reusable: true,
inserter: false,
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { InnerBlocks } from '@wordpress/block-editor';
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { getIconColor } from '../../../shared/block-icons';
import PlaceholderSiteIcon from '../placeholder-site-icon.svg';
import { default as deprecated } from './deprecated';
import edit from './edit';
import icon from './icon';
import './editor.scss';

export const name = 'blogroll-item';
export const title = __( 'Blogroll Item', 'jetpack' );
export const settings = {
apiVersion: 3,
title,
description: __( 'Blogroll Item', 'jetpack' ),
icon: {
Expand Down Expand Up @@ -65,10 +67,19 @@ export const settings = {
type: 'string',
},
},
save: () => <InnerBlocks.Content />,
save: () => {
const blockProps = useBlockProps.save();

return (
<div { ...blockProps }>
<InnerBlocks.Content />
</div>
);
},
example: {
attributes: {
// @TODO: Add default values for block attributes, for generating the block preview.
},
},
deprecated,
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const attributes = {
export const name = 'address';

export const settings = {
apiVersion: 3,
title: __( 'Address', 'jetpack' ),
description: __( 'Lets you add a physical address with Schema markup.', 'jetpack' ),
keywords: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useBlockProps } from '@wordpress/block-editor';
import { Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

Expand Down Expand Up @@ -56,9 +57,15 @@ export const googleMapsUrl = ( {
);
};

const save = props =>
hasAddress( props.attributes ) && (
<div className={ props.className }>
const save = props => {
if ( ! hasAddress( props.attributes ) ) {
return null;
}

const blockProps = useBlockProps.save();

return (
<div { ...blockProps }>
{ props.attributes.linkToGoogleMaps && (
<a
href={ googleMapsUrl( props ) }
Expand All @@ -72,5 +79,6 @@ const save = props =>
{ ! props.attributes.linkToGoogleMaps && <Address { ...props } /> }
</div>
);
};

export default save;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import AddressEdit from '../edit';

jest.mock( '@wordpress/block-editor', () => ( {
...jest.requireActual( '@wordpress/block-editor' ),
useBlockProps: {
save: () => ( {} ),
},
} ) );

const defaultAttributes = {
address: '',
addressLine2: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const attributes = {
export const name = 'email';

export const settings = {
apiVersion: 3,
title: __( 'Email Address', 'jetpack' ),
description: __(
'Lets you add an email address with an automatically generated click-to-email link.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useBlockProps } from '@wordpress/block-editor';
import { Fragment } from '@wordpress/element';
import emailValidator from 'email-validator';

Expand Down Expand Up @@ -27,7 +28,14 @@ const renderEmail = inputText => {
return explodedInput;
};

const save = ( { attributes: { email }, className } ) =>
email && <div className={ className }>{ renderEmail( email ) }</div>;
const save = ( { attributes: { email } } ) => {
if ( ! email ) {
return null;
}

const blockProps = useBlockProps.save();

return <div { ...blockProps }>{ renderEmail( email ) }</div>;
};

export default save;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import EmailEdit from '../edit';

jest.mock( '@wordpress/block-editor', () => ( {
...jest.requireActual( '@wordpress/block-editor' ),
useBlockProps: {
save: () => ( {} ),
},
} ) );

const setAttributes = jest.fn();

const defaultAttributes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const attributes = {
export const name = 'phone';

export const settings = {
apiVersion: 3,
title: __( 'Phone Number', 'jetpack' ),
description: __(
'Lets you add a phone number with an automatically generated click-to-call link.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useBlockProps } from '@wordpress/block-editor';

export function renderPhone( inputText ) {
const arrayOfNumbers = inputText.match( /\d+\.\d+|\d+\b|\d+(?=\w)/g );
if ( ! arrayOfNumbers ) {
Expand Down Expand Up @@ -37,7 +39,14 @@ export function renderPhone( inputText ) {
];
}

const save = ( { attributes: { phone }, className } ) =>
phone && <div className={ className }>{ renderPhone( phone ) }</div>;
const save = ( { attributes: { phone } } ) => {
if ( ! phone ) {
return null;
}

const blockProps = useBlockProps.save();

return <div { ...blockProps }>{ renderPhone( phone ) }</div>;
};

export default save;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import PhoneEdit from '../edit';

jest.mock( '@wordpress/block-editor', () => ( {
...jest.requireActual( '@wordpress/block-editor' ),
useBlockProps: {
save: () => ( {} ),
},
} ) );

const setAttributes = jest.fn();

const defaultAttributes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import save from './save';

const name = 'premium-content/logged-out-view';
const settings = {
apiVersion: 3,
title: __( 'Guest View', 'jetpack' ),
description: __(
'The container for all content shown to site visitors who are not subscribers.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { InnerBlocks } from '@wordpress/block-editor';
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

/**
* Block Save function
*
* @return {string} HTML markup.
*/
export default function Save() {
const blockProps = useBlockProps.save( {
className: 'wp-block-premium-content-logged-out-view entry-content',
} );

return (
<div className="wp-block-premium-content-logged-out-view entry-content">
<div { ...blockProps }>
<InnerBlocks.Content />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const name = 'premium-content/login-button';
* @type {BlockConfiguration}
*/
const settings = {
apiVersion: 3,
title: __( 'Premium Content login button', 'jetpack' ),
description: __(
'Prompt subscriber visitors to log in with a button-style link (only visible for logged out users).',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import save from './save';

const name = 'premium-content/subscriber-view';
const settings = {
apiVersion: 3,
title: __( 'Subscriber View', 'jetpack' ),
description: __( 'The container for all content shown to subscribers.', 'jetpack' ),
icon,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { InnerBlocks } from '@wordpress/block-editor';
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

/**
* Block Save function
*
* @return {string} HTML markup.
*/
export default function Save() {
const blockProps = useBlockProps.save( {
className: 'wp-block-premium-content-subscriber-view entry-content',
} );

return (
<div className="wp-block-premium-content-subscriber-view entry-content">
<div { ...blockProps }>
<InnerBlocks.Content />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InnerBlocks } from '@wordpress/block-editor';
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
import { TextControl, __experimentalUnitControl as UnitControl } from '@wordpress/components'; // eslint-disable-line @wordpress/no-unsafe-wp-apis
import './editor.scss';

Expand All @@ -9,8 +9,10 @@ const units = [

function RecipeDetailsEdit( { className, attributes, setAttributes } ) {
const { prepTime, prepTimeLabel, cookTime, cookTimeLabel, servings, servingsLabel } = attributes;
const blockProps = useBlockProps( { className } );

return (
<div className={ className }>
<div { ...blockProps }>
<div className="wp-container wp-recipe-block-details">
<div className="group">
<TextControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import './editor.scss';
export const name = 'recipe-details';

export const settings = {
apiVersion: 3,
title: __( 'Recipe Details', 'jetpack' ),
description: (
<Fragment>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* External dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

const RecipeSave = ( { attributes, className } ) => {
const RecipeSave = ( { attributes } ) => {
const { prepTime, prepTimeLabel, cookTime, cookTimeLabel, servings, servingsLabel } = attributes;
const blockProps = useBlockProps.save();

return (
<div className={ className }>
<div { ...blockProps }>
<div className="wp-block-jetpack-recipe-details__detail">
<p>{ prepTimeLabel }</p>
<p itemProp="prepTime" content={ `PT${ prepTime.toUpperCase() }` }>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* External dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

function RecipeHeroEdit( { className, hasInnerBlocks } ) {
const blockProps = useBlockProps( { className } );
return (
<div className={ className }>
<div { ...blockProps }>
<InnerBlocks
allowedBlocks={ [ 'core/image', 'jetpack/slideshow', 'core/cover' ] }
renderAppender={ ! hasInnerBlocks && InnerBlocks.ButtonBlockAppender }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import save from './save';
export const name = 'recipe-hero';
export const title = __( 'Recipe Hero', 'jetpack' );
export const settings = {
apiVersion: 3,
title,
description: (
<Fragment>
Expand Down
15 changes: 9 additions & 6 deletions projects/plugins/jetpack/extensions/blocks/recipe/hero/save.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/**
* External dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

const RecipeHeroSave = ( { className } ) => (
<div className={ className }>
<InnerBlocks.Content />
</div>
);
const RecipeHeroSave = () => {
const blockProps = useBlockProps.save();
return (
<div { ...blockProps }>
<InnerBlocks.Content />
</div>
);
};

export default RecipeHeroSave;
Loading
Loading