Skip to content

Commit

Permalink
Try using the @wordpress/embed-block library.
Browse files Browse the repository at this point in the history
  • Loading branch information
pento committed Feb 12, 2020
1 parent 1d185ab commit b4a7f2d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 336 deletions.
217 changes: 0 additions & 217 deletions extensions/blocks/pinterest/edit.js

This file was deleted.

75 changes: 11 additions & 64 deletions extensions/blocks/pinterest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@
*/
import { __ } from '@wordpress/i18n';
import { G, Path, Rect, SVG } from '@wordpress/components';
import { createBlock } from '@wordpress/blocks';

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

export const URL_REGEX = /^\s*https?:\/\/(?:www\.)?(?:[a-z]{2}\.)?(?:pinterest\.[a-z.]+|pin\.it)\/([^/]+)(\/[^/]+)?/i;

export const name = 'pinterest';
export const title = __( 'Pinterest', 'jetpack' );

export const icon = (
const icon = (
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<Rect x="0" fill="none" width="24" height="24" />
<G>
Expand All @@ -26,60 +16,17 @@ export const icon = (
);

export const settings = {
title,

description: __( 'Embed a Pinterest pin, board, or user.', 'jetpack' ),

icon,

category: 'jetpack',

supports: {
align: false,
html: false,
},

attributes: {
url: {
type: 'string',
},
},

edit,

save: ( { attributes, className } ) => {
const { url } = attributes;

const type = pinType( url );

if ( ! type ) {
return null;
}

return (
<div className={ className }>
<a data-pin-do={ pinType( url ) } href={ url } />
</div>
);
},

transforms: {
from: [
{
type: 'raw',
isMatch: node => node.nodeName === 'P' && URL_REGEX.test( node.textContent ),
transform: node => {
return createBlock( 'jetpack/pinterest', {
url: node.textContent.trim(),
} );
},
settings: {
title: __( 'Pinterest', 'jetpack' ),
icon,
description: __( 'Embed a Pinterest pin, board, or user.', 'jetpack' ),
example: {
attributes: {
url: 'https://pinterest.com/anapinskywalker/',
},
],
},

example: {
attributes: {
url: 'https://pinterest.com/anapinskywalker/',
},
},
patterns: [
/^\s*https?:\/\/(?:www\.)?(?:[a-z]{2}\.)?(?:pinterest\.[a-z.]+|pin\.it)\/([^/]+)(\/[^/]+)?/i,
],
};
55 changes: 0 additions & 55 deletions extensions/blocks/pinterest/utils.js

This file was deleted.

14 changes: 14 additions & 0 deletions extensions/shared/register-jetpack-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { addFilter } from '@wordpress/hooks';
import { registerBlockType } from '@wordpress/blocks';
import { getEmbedBlockSettings } from '@wordpress/embed-block';

/**
* Internal dependencies
Expand Down Expand Up @@ -44,6 +45,19 @@ export default function registerJetpackBlock( name, settings, childBlocks = [] )
return false;
}

if ( settings.settings ) {
settings = {
name: `jetpack/${ name }`,
...getEmbedBlockSettings( {
title: betaExtensions.includes( name )
? `${ settings.settings.title } (beta)`
: settings.settings.title,
example: requiredPlan ? undefined : settings.settings.example,
...settings.settings,
} ),
};
}

const result = registerBlockType( `jetpack/${ name }`, {
...settings,
title: betaExtensions.includes( name ) ? `${ settings.title } (beta)` : settings.title,
Expand Down

0 comments on commit b4a7f2d

Please sign in to comment.