From c108c9b080b0a078e260e91393b95d8bd5b717f0 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Fri, 19 Jan 2018 15:55:36 +0100 Subject: [PATCH] Blocks: Refactor all blocks to be exported as name & settings pair --- blocks/library/block/index.js | 7 +- blocks/library/button/index.js | 7 +- blocks/library/button/test/index.js | 8 +- blocks/library/categories/index.js | 7 +- blocks/library/code/index.js | 8 +- blocks/library/code/test/index.js | 8 +- blocks/library/cover-image/index.js | 8 +- blocks/library/cover-image/test/index.js | 8 +- blocks/library/freeform/index.js | 37 ++++----- blocks/library/freeform/test/index.js | 8 +- blocks/library/gallery/index.js | 9 ++- blocks/library/gallery/test/index.js | 8 +- blocks/library/heading/index.js | 8 +- blocks/library/heading/test/index.js | 8 +- blocks/library/html/index.js | 7 +- blocks/library/html/test/index.js | 8 +- blocks/library/image/index.js | 8 +- blocks/library/index.js | 95 ++++++++++++----------- blocks/library/latest-posts/index.js | 7 +- blocks/library/list/index.js | 14 ++-- blocks/library/list/test/index.js | 8 +- blocks/library/more/index.js | 7 +- blocks/library/more/test/index.js | 8 +- blocks/library/preformatted/index.js | 8 +- blocks/library/preformatted/test/index.js | 8 +- blocks/library/pullquote/index.js | 7 +- blocks/library/pullquote/test/index.js | 8 +- blocks/library/quote/index.js | 8 +- blocks/library/quote/test/index.js | 8 +- blocks/library/separator/index.js | 8 +- blocks/library/separator/test/index.js | 8 +- blocks/library/shortcode/index.js | 7 +- blocks/library/shortcode/test/index.js | 8 +- blocks/library/table/index.js | 7 +- blocks/library/table/test/index.js | 8 +- blocks/library/text-columns/index.js | 7 +- blocks/library/text-columns/test/index.js | 8 +- blocks/library/verse/index.js | 8 +- blocks/library/verse/test/index.js | 8 +- blocks/library/video/index.js | 7 +- blocks/library/video/test/index.js | 8 +- 41 files changed, 200 insertions(+), 240 deletions(-) diff --git a/blocks/library/block/index.js b/blocks/library/block/index.js index 8525cf6ad9221..61d2c4f3111a6 100644 --- a/blocks/library/block/index.js +++ b/blocks/library/block/index.js @@ -15,7 +15,6 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import BlockEdit from '../../block-edit'; -import { registerBlockType } from '../../api'; import ReusableBlockEditPanel from './edit-panel'; class ReusableBlockEdit extends Component { @@ -156,7 +155,9 @@ const ConnectedReusableBlockEdit = connect( } ) )( ReusableBlockEdit ); -export const registerReusableBlock = () => registerBlockType( 'core/block', { +export const name = 'core/block'; + +export const settings = { title: __( 'Reusable Block' ), category: 'reusable-blocks', isPrivate: true, @@ -174,4 +175,4 @@ export const registerReusableBlock = () => registerBlockType( 'core/block', { edit: ConnectedReusableBlockEdit, save: () => null, -} ); +}; diff --git a/blocks/library/button/index.js b/blocks/library/button/index.js index 9d75df999b11d..1a781c4114ea0 100644 --- a/blocks/library/button/index.js +++ b/blocks/library/button/index.js @@ -10,7 +10,6 @@ import { Dashicon, IconButton, PanelColor, withFallbackStyles } from '@wordpress */ import './editor.scss'; import './style.scss'; -import { registerBlockType } from '../../api'; import Editable from '../../editable'; import UrlInput from '../../url-input'; import BlockControls from '../../block-controls'; @@ -173,7 +172,9 @@ const blockAttributes = { }, }; -export const registerButtonBlock = () => registerBlockType( 'core/button', { +export const name = 'core/button'; + +export const settings = { title: __( 'Button' ), description: __( 'A nice little button. Call something out with it.' ), @@ -235,4 +236,4 @@ export const registerButtonBlock = () => registerBlockType( 'core/button', { ); }, } ], -} ); +}; diff --git a/blocks/library/button/test/index.js b/blocks/library/button/test/index.js index dabf3472672a0..2b78a36bf105b 100644 --- a/blocks/library/button/test/index.js +++ b/blocks/library/button/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerButtonBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/button', () => { - beforeAll( () => { - registerButtonBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/button' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/categories/index.js b/blocks/library/categories/index.js index 2d84cd3c13d45..d180b7df245df 100644 --- a/blocks/library/categories/index.js +++ b/blocks/library/categories/index.js @@ -8,10 +8,11 @@ import { __ } from '@wordpress/i18n'; */ import './editor.scss'; import './style.scss'; -import { registerBlockType } from '../../api'; import CategoriesBlock from './block'; -export const registerCategoriesBlock = () => registerBlockType( 'core/categories', { +export const name = 'core/categories'; + +export const settings = { title: __( 'Categories' ), description: __( 'Shows a list of your site\'s categories.' ), @@ -54,4 +55,4 @@ export const registerCategoriesBlock = () => registerBlockType( 'core/categories save() { return null; }, -} ); +}; diff --git a/blocks/library/code/index.js b/blocks/library/code/index.js index 82c32a3c168e0..248618ea31f9d 100644 --- a/blocks/library/code/index.js +++ b/blocks/library/code/index.js @@ -12,9 +12,11 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import './editor.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; -export const registerCodeBlock = () => registerBlockType( 'core/code', { +export const name = 'core/code'; + +export const settings = { title: __( 'Code' ), description: __( 'The code block maintains spaces and tabs, great for showing code snippets.' ), @@ -71,4 +73,4 @@ export const registerCodeBlock = () => registerBlockType( 'core/code', { save( { attributes } ) { return
{ attributes.content }
; }, -} ); +}; diff --git a/blocks/library/code/test/index.js b/blocks/library/code/test/index.js index 368da71705f9f..938b58f6871e6 100644 --- a/blocks/library/code/test/index.js +++ b/blocks/library/code/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerCodeBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/code', () => { - beforeAll( () => { - registerCodeBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/code' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/cover-image/index.js b/blocks/library/cover-image/index.js index 591892624826e..4b77e0745c93c 100644 --- a/blocks/library/cover-image/index.js +++ b/blocks/library/cover-image/index.js @@ -15,7 +15,7 @@ import classnames from 'classnames'; */ import './editor.scss'; import './style.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; import Editable from '../../editable'; import MediaUpload from '../../media-upload'; import ImagePlaceHolder from '../../image-placeholder'; @@ -27,7 +27,9 @@ import RangeControl from '../../inspector-controls/range-control'; const validAlignments = [ 'left', 'center', 'right', 'wide', 'full' ]; -export const registerCoverImageBlock = () => registerBlockType( 'core/cover-image', { +export const name = 'core/cover-image'; + +export const settings = { title: __( 'Cover Image' ), description: __( 'Cover Image is a bold image block with an optional title.' ), @@ -215,7 +217,7 @@ export const registerCoverImageBlock = () => registerBlockType( 'core/cover-imag ); }, -} ); +}; function dimRatioToClass( ratio ) { return ( ratio === 0 || ratio === 50 ) ? diff --git a/blocks/library/cover-image/test/index.js b/blocks/library/cover-image/test/index.js index eb33d55b87320..4cd1d315f7c3d 100644 --- a/blocks/library/cover-image/test/index.js +++ b/blocks/library/cover-image/test/index.js @@ -1,18 +1,14 @@ /** * Internal dependencies */ -import { registerCoverImageBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; jest.mock( 'blocks/media-upload', () => () => '*** Mock(Media upload button) ***' ); describe( 'core/cover-image', () => { - beforeAll( () => { - registerCoverImageBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/cover-image' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/freeform/index.js b/blocks/library/freeform/index.js index 02ef1a1c907ca..fa5e63be0138e 100644 --- a/blocks/library/freeform/index.js +++ b/blocks/library/freeform/index.js @@ -7,33 +7,30 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import './editor.scss'; -import { registerBlockType, setUnknownTypeHandlerName } from '../../api'; import OldEditor from './old-editor'; -export const registerFreeformBlock = () => { - registerBlockType( 'core/freeform', { - title: __( 'Classic' ), +export const name = 'core/freeform'; - desription: __( 'The classic editor, in block form.' ), +export const settings = { + title: __( 'Classic' ), - icon: 'editor-kitchensink', + desription: __( 'The classic editor, in block form.' ), - category: 'formatting', + icon: 'editor-kitchensink', - attributes: { - content: { - type: 'string', - source: 'html', - }, - }, - - edit: OldEditor, + category: 'formatting', - save( { attributes } ) { - const { content } = attributes; - return content; + attributes: { + content: { + type: 'string', + source: 'html', }, - } ); + }, + + edit: OldEditor, - setUnknownTypeHandlerName( 'core/freeform' ); + save( { attributes } ) { + const { content } = attributes; + return content; + }, }; diff --git a/blocks/library/freeform/test/index.js b/blocks/library/freeform/test/index.js index 187ba30d358cf..aee9066d54cf5 100644 --- a/blocks/library/freeform/test/index.js +++ b/blocks/library/freeform/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerFreeformBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/freeform', () => { - beforeAll( () => { - registerFreeformBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/freeform' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/gallery/index.js b/blocks/library/gallery/index.js index 6d66c07dee5c8..f3cd92ebabb3a 100644 --- a/blocks/library/gallery/index.js +++ b/blocks/library/gallery/index.js @@ -14,7 +14,7 @@ import { createMediaFromFile, preloadImage } from '@wordpress/utils'; */ import './editor.scss'; import './style.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; import { default as GalleryBlock, defaultColumnsNumber } from './block'; const blockAttributes = { @@ -56,7 +56,9 @@ const blockAttributes = { }, }; -export const registerGalleryBlock = () => registerBlockType( 'core/gallery', { +export const name = 'core/gallery'; + +export const settings = { title: __( 'Gallery' ), description: __( 'Image galleries are a great way to share groups of pictures on your site.' ), icon: 'format-gallery', @@ -228,5 +230,4 @@ export const registerGalleryBlock = () => registerBlockType( 'core/gallery', { }, }, ], - -} ); +}; diff --git a/blocks/library/gallery/test/index.js b/blocks/library/gallery/test/index.js index 882440e099409..1256a4d6aa642 100644 --- a/blocks/library/gallery/test/index.js +++ b/blocks/library/gallery/test/index.js @@ -1,18 +1,14 @@ /** * Internal dependencies */ -import { registerGalleryBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; jest.mock( 'blocks/media-upload', () => () => '*** Mock(Media upload button) ***' ); describe( 'core/gallery', () => { - beforeAll( () => { - registerGalleryBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/gallery' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/heading/index.js b/blocks/library/heading/index.js index fe933e6b3d00b..7c60dc764a0e1 100644 --- a/blocks/library/heading/index.js +++ b/blocks/library/heading/index.js @@ -9,13 +9,15 @@ import { Toolbar } from '@wordpress/components'; * Internal dependencies */ import './editor.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; import Editable from '../../editable'; import BlockControls from '../../block-controls'; import InspectorControls from '../../inspector-controls'; import AlignmentToolbar from '../../alignment-toolbar'; -export const registerHeadingBlock = () => registerBlockType( 'core/heading', { +export const name = 'core/heading'; + +export const settings = { title: __( 'Heading' ), description: __( 'Search engines use the headings to index the structure and content of your web pages.' ), @@ -178,4 +180,4 @@ export const registerHeadingBlock = () => registerBlockType( 'core/heading', { ); }, -} ); +}; diff --git a/blocks/library/heading/test/index.js b/blocks/library/heading/test/index.js index 4a7257e44d735..c1cba07d763d8 100644 --- a/blocks/library/heading/test/index.js +++ b/blocks/library/heading/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerHeadingBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/heading', () => { - beforeAll( () => { - registerHeadingBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/heading' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/html/index.js b/blocks/library/html/index.js index ff718e2ab42d1..e36f1a3da88ee 100644 --- a/blocks/library/html/index.js +++ b/blocks/library/html/index.js @@ -13,10 +13,11 @@ import { withState } from '@wordpress/components'; * Internal dependencies */ import './editor.scss'; -import { registerBlockType } from '../../api'; import BlockControls from '../../block-controls'; -export const registerHtmlBlock = () => registerBlockType( 'core/html', { +export const name = 'core/html'; + +export const settings = { title: __( 'Custom HTML' ), description: __( 'Add custom HTML code and preview it right here in the editor.' ), @@ -75,4 +76,4 @@ export const registerHtmlBlock = () => registerBlockType( 'core/html', { save( { attributes } ) { return attributes.content; }, -} ); +}; diff --git a/blocks/library/html/test/index.js b/blocks/library/html/test/index.js index 140b2f35e3b80..dead9a7204616 100644 --- a/blocks/library/html/test/index.js +++ b/blocks/library/html/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerHtmlBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/html', () => { - beforeAll( () => { - registerHtmlBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/html' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/image/index.js b/blocks/library/image/index.js index 292daa15d4570..918fb3a26b6ec 100644 --- a/blocks/library/image/index.js +++ b/blocks/library/image/index.js @@ -9,10 +9,12 @@ import { createMediaFromFile, preloadImage } from '@wordpress/utils'; */ import './style.scss'; import './editor.scss'; -import { registerBlockType, createBlock, getBlockAttributes, getBlockType } from '../../api'; +import { createBlock, getBlockAttributes, getBlockType } from '../../api'; import ImageBlock from './block'; -export const registerImageBlock = () => registerBlockType( 'core/image', { +export const name = 'core/image'; + +export const settings = { title: __( 'Image' ), description: __( 'Worth a thousand words.' ), @@ -179,4 +181,4 @@ export const registerImageBlock = () => registerBlockType( 'core/image', { ); }, -} ); +}; diff --git a/blocks/library/index.js b/blocks/library/index.js index 862c08343499a..23482f3e14278 100644 --- a/blocks/library/index.js +++ b/blocks/library/index.js @@ -1,65 +1,70 @@ /** * Internal dependencies */ +import { + registerBlockType, + setDefaultBlockName, + setUnknownTypeHandlerName, +} from '../api'; import * as audio from './audio'; +import * as button from './button'; +import * as categories from './categories'; +import * as code from './code'; +import * as coverImage from './cover-image'; import * as embed from './embed'; +import * as freeform from './freeform'; +import * as gallery from './gallery'; +import * as heading from './heading'; +import * as html from './html'; +import * as image from './image'; +import * as latestPosts from './latest-posts'; +import * as list from './list'; +import * as more from './more'; import * as paragraph from './paragraph'; -import { registerBlockType, setDefaultBlockName } from '../api'; -import { registerShortcodeBlock } from './shortcode'; -import { registerImageBlock } from './image'; -import { registerGalleryBlock } from './gallery'; -import { registerHeadingBlock } from './heading'; -import { registerQuoteBlock } from './quote'; -import { registerListBlock } from './list'; -import { registerSeparatorBlock } from './separator'; -import { registerMoreBlock } from './more'; -import { registerButtonBlock } from './button'; -import { registerPullquoteBlock } from './pullquote'; -import { registerTableBlock } from './table'; -import { registerPreformattedBlock } from './preformatted'; -import { registerCodeBlock } from './code'; -import { registerHtmlBlock } from './html'; -import { registerFreeformBlock } from './freeform'; -import { registerLatestPostsBlock } from './latest-posts'; -import { registerCategoriesBlock } from './categories'; -import { registerCoverImageBlock } from './cover-image'; -import { registerTextColumnsBlock } from './text-columns'; -import { registerVerseBlock } from './verse'; -import { registerVideoBlock } from './video'; -import { registerReusableBlock } from './block'; +import * as preformatted from './preformatted'; +import * as pullquote from './pullquote'; +import * as quote from './quote'; +import * as reusableBlock from './block'; +import * as separator from './separator'; +import * as shortcode from './shortcode'; +import * as table from './table'; +import * as textColumns from './text-columns'; +import * as verse from './verse'; +import * as video from './video'; export const registerCoreBlocks = () => { [ audio, + button, + categories, + code, + coverImage, embed, ...embed.common, ...embed.others, + freeform, + gallery, + heading, + html, + image, + list, + latestPosts, + more, paragraph, + preformatted, + pullquote, + quote, + reusableBlock, + separator, + shortcode, + table, + textColumns, + verse, + video, ].forEach( ( { name, settings } ) => { registerBlockType( name, settings ); } ); - registerShortcodeBlock(); - registerImageBlock(); - registerGalleryBlock(); - registerHeadingBlock(); - registerQuoteBlock(); - registerListBlock(); - registerSeparatorBlock(); - registerMoreBlock(); - registerButtonBlock(); - registerPullquoteBlock(); - registerTableBlock(); - registerPreformattedBlock(); - registerCodeBlock(); - registerHtmlBlock(); - registerFreeformBlock(); - registerLatestPostsBlock(); - registerCategoriesBlock(); - registerCoverImageBlock(); - registerTextColumnsBlock(); - registerVerseBlock(); - registerVideoBlock(); - registerReusableBlock(); setDefaultBlockName( paragraph.name ); + setUnknownTypeHandlerName( freeform.name ); }; diff --git a/blocks/library/latest-posts/index.js b/blocks/library/latest-posts/index.js index 45a0f12e3187d..3762b61e2a68b 100644 --- a/blocks/library/latest-posts/index.js +++ b/blocks/library/latest-posts/index.js @@ -8,10 +8,11 @@ import { __ } from '@wordpress/i18n'; */ import './editor.scss'; import './style.scss'; -import { registerBlockType } from '../../api'; import LatestPostsBlock from './block'; -export const registerLatestPostsBlock = () => registerBlockType( 'core/latest-posts', { +export const name = 'core/latest-posts'; + +export const settings = { title: __( 'Latest Posts' ), description: __( 'Shows a list of your site\'s most recent posts.' ), @@ -38,4 +39,4 @@ export const registerLatestPostsBlock = () => registerBlockType( 'core/latest-po save() { return null; }, -} ); +}; diff --git a/blocks/library/list/index.js b/blocks/library/list/index.js index 03773fb7b9a26..03477d006739d 100644 --- a/blocks/library/list/index.js +++ b/blocks/library/list/index.js @@ -13,11 +13,13 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import './editor.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; import Editable from '../../editable'; import BlockControls from '../../block-controls'; -export const registerListBlock = () => registerBlockType( 'core/list', { +export const name = 'core/list'; + +export const settings = { title: __( 'List' ), description: __( 'List. Numbered or bulleted.' ), icon: 'editor-ul', @@ -212,10 +214,10 @@ export const registerListBlock = () => registerBlockType( 'core/list', { }; } - getEditorSettings( settings ) { + getEditorSettings( editorSettings ) { return { - ...settings, - plugins: ( settings.plugins || [] ).concat( 'lists' ), + ...editorSettings, + plugins: ( editorSettings.plugins || [] ).concat( 'lists' ), lists_indent_on_tab: false, }; } @@ -313,4 +315,4 @@ export const registerListBlock = () => registerBlockType( 'core/list', { values ); }, -} ); +}; diff --git a/blocks/library/list/test/index.js b/blocks/library/list/test/index.js index 210ca27fe7836..d138bfe821efd 100644 --- a/blocks/library/list/test/index.js +++ b/blocks/library/list/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerListBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/list', () => { - beforeAll( () => { - registerListBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/list' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/more/index.js b/blocks/library/more/index.js index 3ecd5e7136a64..719bbe650fb7d 100644 --- a/blocks/library/more/index.js +++ b/blocks/library/more/index.js @@ -7,11 +7,12 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import './editor.scss'; -import { registerBlockType } from '../../api'; import InspectorControls from '../../inspector-controls'; import ToggleControl from '../../inspector-controls/toggle-control'; -export const registerMoreBlock = () => registerBlockType( 'core/more', { +export const name = 'core/more'; + +export const settings = { title: __( 'More' ), description: __( '"More" allows you to break your post into a part shown on index pages, and the subsequent after clicking a "Read More" link.' ), @@ -71,4 +72,4 @@ export const registerMoreBlock = () => registerBlockType( 'core/more', { save() { return null; }, -} ); +}; diff --git a/blocks/library/more/test/index.js b/blocks/library/more/test/index.js index b5318b2f28b3e..c6d259bd293f9 100644 --- a/blocks/library/more/test/index.js +++ b/blocks/library/more/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerMoreBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/more', () => { - beforeAll( () => { - registerMoreBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/more' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/preformatted/index.js b/blocks/library/preformatted/index.js index 6f5f2b6de37ea..bd110d6ca095d 100644 --- a/blocks/library/preformatted/index.js +++ b/blocks/library/preformatted/index.js @@ -7,10 +7,12 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import './editor.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; import Editable from '../../editable'; -export const registerPreformattedBlock = () => registerBlockType( 'core/preformatted', { +export const name = 'core/preformatted'; + +export const settings = { title: __( 'Preformatted' ), description: __( 'Preformatted text keeps your spaces, tabs and linebreaks as they are.' ), @@ -82,4 +84,4 @@ export const registerPreformattedBlock = () => registerBlockType( 'core/preforma return
{ content }
; }, -} ); +}; diff --git a/blocks/library/preformatted/test/index.js b/blocks/library/preformatted/test/index.js index fdc12a7c853d5..f190d8b5d77f9 100644 --- a/blocks/library/preformatted/test/index.js +++ b/blocks/library/preformatted/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerPreformattedBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/preformatted', () => { - beforeAll( () => { - registerPreformattedBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/preformatted' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/pullquote/index.js b/blocks/library/pullquote/index.js index 4781030c4d1bc..2f1511b88f2a0 100644 --- a/blocks/library/pullquote/index.js +++ b/blocks/library/pullquote/index.js @@ -13,7 +13,6 @@ import { __ } from '@wordpress/i18n'; */ import './editor.scss'; import './style.scss'; -import { registerBlockType } from '../../api'; import Editable from '../../editable'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; @@ -44,7 +43,9 @@ const blockAttributes = { }, }; -export const registerPullquoteBlock = () => registerBlockType( 'core/pullquote', { +export const name = 'core/pullquote'; + +export const settings = { title: __( 'Pullquote' ), @@ -148,4 +149,4 @@ export const registerPullquoteBlock = () => registerBlockType( 'core/pullquote', ); }, } ], -} ); +}; diff --git a/blocks/library/pullquote/test/index.js b/blocks/library/pullquote/test/index.js index 46c20d9940db8..40a2e28606e33 100644 --- a/blocks/library/pullquote/test/index.js +++ b/blocks/library/pullquote/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerPullquoteBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/pullquote', () => { - beforeAll( () => { - registerPullquoteBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/pullquote' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/quote/index.js b/blocks/library/quote/index.js index 903d65a7297cf..579fc67265a71 100644 --- a/blocks/library/quote/index.js +++ b/blocks/library/quote/index.js @@ -15,7 +15,7 @@ import { Toolbar } from '@wordpress/components'; */ import './style.scss'; import './editor.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; import AlignmentToolbar from '../../alignment-toolbar'; import BlockControls from '../../block-controls'; import Editable from '../../editable'; @@ -51,7 +51,9 @@ const blockAttributes = { }, }; -export const registerQuoteBlock = () => registerBlockType( 'core/quote', { +export const name = 'core/quote'; + +export const settings = { title: __( 'Quote' ), description: __( 'Quote. In quoting others, we cite ourselves. (Julio Cortázar)' ), icon: 'format-quote', @@ -270,4 +272,4 @@ export const registerQuoteBlock = () => registerBlockType( 'core/quote', { }, }, ], -} ); +}; diff --git a/blocks/library/quote/test/index.js b/blocks/library/quote/test/index.js index 0fb1b82a160e4..08f4c5f65f86c 100644 --- a/blocks/library/quote/test/index.js +++ b/blocks/library/quote/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerQuoteBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/quote', () => { - beforeAll( () => { - registerQuoteBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/quote' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/separator/index.js b/blocks/library/separator/index.js index 121bd3b08fadc..b387cd4eec4d5 100644 --- a/blocks/library/separator/index.js +++ b/blocks/library/separator/index.js @@ -7,9 +7,11 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import './style.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; -export const registerSeparatorBlock = () => registerBlockType( 'core/separator', { +export const name = 'core/separator'; + +export const settings = { title: __( 'Separator' ), description: __( 'Use the separator to indicate a thematic change in the content.' ), @@ -42,4 +44,4 @@ export const registerSeparatorBlock = () => registerBlockType( 'core/separator', save() { return
; }, -} ); +}; diff --git a/blocks/library/separator/test/index.js b/blocks/library/separator/test/index.js index ea518c284c566..ec79dc27e47ce 100644 --- a/blocks/library/separator/test/index.js +++ b/blocks/library/separator/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerSeparatorBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/separator', () => { - beforeAll( () => { - registerSeparatorBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/separator' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/shortcode/index.js b/blocks/library/shortcode/index.js index 848144021967a..483b279a97b83 100644 --- a/blocks/library/shortcode/index.js +++ b/blocks/library/shortcode/index.js @@ -13,9 +13,10 @@ import { withInstanceId, Dashicon } from '@wordpress/components'; * Internal dependencies */ import './editor.scss'; -import { registerBlockType } from '../../api'; -export const registerShortcodeBlock = () => registerBlockType( 'core/shortcode', { +export const name = 'core/shortcode'; + +export const settings = { title: __( 'Shortcode' ), description: __( 'A shortcode is a WordPress-specific code snippet that is written between square brackets as [shortcode]. ' ), @@ -88,4 +89,4 @@ export const registerShortcodeBlock = () => registerBlockType( 'core/shortcode', save( { attributes } ) { return attributes.text; }, -} ); +}; diff --git a/blocks/library/shortcode/test/index.js b/blocks/library/shortcode/test/index.js index 1480fc8940594..5892b6e57a1ad 100644 --- a/blocks/library/shortcode/test/index.js +++ b/blocks/library/shortcode/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerShortcodeBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/shortcode', () => { - beforeAll( () => { - registerShortcodeBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/shortcode' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/table/index.js b/blocks/library/table/index.js index 866885efa54f2..b9c7636f089b3 100644 --- a/blocks/library/table/index.js +++ b/blocks/library/table/index.js @@ -8,12 +8,13 @@ import { __ } from '@wordpress/i18n'; */ import './editor.scss'; import './style.scss'; -import { registerBlockType } from '../../api'; import TableBlock from './table-block'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; -export const registerTableBlock = () => registerBlockType( 'core/table', { +export const name = 'core/table'; + +export const settings = { title: __( 'Table' ), description: __( 'Tables. Best used for tabular data.' ), icon: 'editor-table', @@ -85,4 +86,4 @@ export const registerTableBlock = () => registerBlockType( 'core/table', { ); }, -} ); +}; diff --git a/blocks/library/table/test/index.js b/blocks/library/table/test/index.js index e10c6af5a96f0..f6249d84357c8 100644 --- a/blocks/library/table/test/index.js +++ b/blocks/library/table/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerTableBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/embed', () => { - beforeAll( () => { - registerTableBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/table' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/text-columns/index.js b/blocks/library/text-columns/index.js index 89bc06be58891..5126cc653a4fb 100644 --- a/blocks/library/text-columns/index.js +++ b/blocks/library/text-columns/index.js @@ -13,14 +13,15 @@ import { __ } from '@wordpress/i18n'; */ import './style.scss'; import './editor.scss'; -import { registerBlockType } from '../../api'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; import RangeControl from '../../inspector-controls/range-control'; import Editable from '../../editable'; import InspectorControls from '../../inspector-controls'; -export const registerTextColumnsBlock = () => registerBlockType( 'core/text-columns', { +export const name = 'core/text-columns'; + +export const settings = { title: __( 'Text Columns' ), description: __( 'Add text across columns. This block is experimental' ), @@ -118,4 +119,4 @@ export const registerTextColumnsBlock = () => registerBlockType( 'core/text-colu ); }, -} ); +}; diff --git a/blocks/library/text-columns/test/index.js b/blocks/library/text-columns/test/index.js index dfb023a187783..6a94d0a8487b5 100644 --- a/blocks/library/text-columns/test/index.js +++ b/blocks/library/text-columns/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerTextColumnsBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/text-columns', () => { - beforeAll( () => { - registerTextColumnsBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/text-columns' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/verse/index.js b/blocks/library/verse/index.js index 4b2d090981e51..1cec91dde4827 100644 --- a/blocks/library/verse/index.js +++ b/blocks/library/verse/index.js @@ -7,10 +7,12 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import './editor.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; import Editable from '../../editable'; -export const registerVerseBlock = () => registerBlockType( 'core/verse', { +export const name = 'core/verse'; + +export const settings = { title: __( 'Verse' ), description: __( 'Write poetry and other literary expressions honoring all spaces and line-breaks.' ), @@ -72,4 +74,4 @@ export const registerVerseBlock = () => registerBlockType( 'core/verse', { save( { attributes, className } ) { return
{ attributes.content }
; }, -} ); +}; diff --git a/blocks/library/verse/test/index.js b/blocks/library/verse/test/index.js index 66eacba41c259..f5df7557f9ad5 100644 --- a/blocks/library/verse/test/index.js +++ b/blocks/library/verse/test/index.js @@ -1,16 +1,12 @@ /** * Internal dependencies */ -import { registerVerseBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/verse', () => { - beforeAll( () => { - registerVerseBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/verse' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/video/index.js b/blocks/library/video/index.js index d63b3514fe8f1..d0da1dc4a16e0 100644 --- a/blocks/library/video/index.js +++ b/blocks/library/video/index.js @@ -14,13 +14,14 @@ import { Component } from '@wordpress/element'; */ import './style.scss'; import './editor.scss'; -import { registerBlockType } from '../../api'; import MediaUpload from '../../media-upload'; import Editable from '../../editable'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; -export const registerVideoBlock = () => registerBlockType( 'core/video', { +export const name = 'core/video'; + +export const settings = { title: __( 'Video' ), description: __( 'The Video block allows you to embed video files and play them back using a simple player.' ), @@ -180,4 +181,4 @@ export const registerVideoBlock = () => registerBlockType( 'core/video', { ); }, -} ); +}; diff --git a/blocks/library/video/test/index.js b/blocks/library/video/test/index.js index 42b1b3b8fb4e0..d3e53da762534 100644 --- a/blocks/library/video/test/index.js +++ b/blocks/library/video/test/index.js @@ -1,18 +1,14 @@ /** * Internal dependencies */ -import { registerVideoBlock } from '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; jest.mock( 'blocks/media-upload', () => () => '*** Mock(Media upload button) ***' ); describe( 'core/video', () => { - beforeAll( () => { - registerVideoBlock(); - } ); - test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/video' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } );