diff --git a/blocks/api/raw-handling/test/integration/index.js b/blocks/api/raw-handling/test/integration/index.js index e37deddf246c45..5ac2086d3568c9 100644 --- a/blocks/api/raw-handling/test/integration/index.js +++ b/blocks/api/raw-handling/test/integration/index.js @@ -8,6 +8,7 @@ import path from 'path'; /** * Internal dependencies */ +import { registerCoreBlocks } from '../../../../library'; import rawHandler from '../../index'; import serialize from '../../../serializer'; @@ -23,8 +24,7 @@ describe( 'raw handling: integration', () => { beforeAll( () => { // Load all hooks that modify blocks require( 'blocks/hooks' ); - // Load all blocks - require( 'blocks/library' ); + registerCoreBlocks(); } ); types.forEach( ( type ) => { diff --git a/blocks/index.js b/blocks/index.js index 7c3ffb4f196ee5..0401e5be296261 100644 --- a/blocks/index.js +++ b/blocks/index.js @@ -2,7 +2,6 @@ * Internal dependencies */ import './hooks'; -import './library'; // A "block" is the abstract term used to describe units of markup that, // when composed together, form the content or layout of a page. @@ -14,6 +13,7 @@ import './library'; // Blocks are inferred from the HTML source of a post through a parsing mechanism // and then stored as objects in state, from which it is then rendered for editing. export * from './api'; +export { registerCoreBlocks } from './library'; export { default as AlignmentToolbar } from './alignment-toolbar'; export { default as BlockAlignmentToolbar } from './block-alignment-toolbar'; export { default as BlockControls } from './block-controls'; diff --git a/blocks/library/audio/index.js b/blocks/library/audio/index.js index 8858e07c414ddb..bf637d2c64d96d 100644 --- a/blocks/library/audio/index.js +++ b/blocks/library/audio/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'; -registerBlockType( 'core/audio', { +export const name = 'core/audio'; + +export const settings = { title: __( 'Audio' ), description: __( 'The Audio block allows you to embed audio files and play them back using a simple player.' ), @@ -178,4 +179,4 @@ registerBlockType( 'core/audio', { ); }, -} ); +}; diff --git a/blocks/library/audio/test/index.js b/blocks/library/audio/test/index.js index 25a087195f5056..3acc03865f117b 100644 --- a/blocks/library/audio/test/index.js +++ b/blocks/library/audio/test/index.js @@ -1,14 +1,14 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; jest.mock( 'blocks/media-upload', () => () => '*** Mock(Media upload button) ***' ); describe( 'core/audio', () => { test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/audio' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/block/index.js b/blocks/library/block/index.js index b9ac6a5c3f8526..61d2c4f3111a60 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 ); -registerBlockType( 'core/block', { +export const name = 'core/block'; + +export const settings = { title: __( 'Reusable Block' ), category: 'reusable-blocks', isPrivate: true, @@ -174,4 +175,4 @@ registerBlockType( 'core/block', { edit: ConnectedReusableBlockEdit, save: () => null, -} ); +}; diff --git a/blocks/library/button/index.js b/blocks/library/button/index.js index 170647be1d8d7f..1a781c4114ea0a 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 = { }, }; -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 @@ registerBlockType( 'core/button', { ); }, } ], -} ); +}; diff --git a/blocks/library/button/test/index.js b/blocks/library/button/test/index.js index 8e4fdf4979f539..2b78a36bf105b9 100644 --- a/blocks/library/button/test/index.js +++ b/blocks/library/button/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/button', () => { 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 a945729d8ba025..d180b7df245df7 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'; -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 @@ registerBlockType( 'core/categories', { save() { return null; }, -} ); +}; diff --git a/blocks/library/code/index.js b/blocks/library/code/index.js index da25a52707d5a4..248618ea31f9d0 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'; -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 @@ 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 0e9fdffd6675f3..938b58f6871e6d 100644 --- a/blocks/library/code/test/index.js +++ b/blocks/library/code/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/code', () => { 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 00c61c40e14990..ccf2ef4eb5b6a0 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 AlignmentToolbar from '../../alignment-toolbar'; import MediaUpload from '../../media-upload'; @@ -28,7 +28,9 @@ import RangeControl from '../../inspector-controls/range-control'; const validAlignments = [ 'left', 'center', 'right', 'wide', 'full' ]; -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.' ), @@ -234,7 +236,7 @@ registerBlockType( 'core/cover-image', { ); }, -} ); +}; 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 0f0fdf3b0f46f4..4cd1d315f7c3de 100644 --- a/blocks/library/cover-image/test/index.js +++ b/blocks/library/cover-image/test/index.js @@ -1,14 +1,14 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; jest.mock( 'blocks/media-upload', () => () => '*** Mock(Media upload button) ***' ); describe( 'core/cover-image', () => { test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/cover-image' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/embed/index.js b/blocks/library/embed/index.js index eef77e2eaa55bc..924975c7ac9eb8 100644 --- a/blocks/library/embed/index.js +++ b/blocks/library/embed/index.js @@ -17,7 +17,7 @@ import { addQueryArgs } from '@wordpress/url'; */ import './style.scss'; import './editor.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; import Editable from '../../editable'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; @@ -237,267 +237,269 @@ function getEmbedBlockSettings( { title, icon, category = 'embed', transforms, k }; } -registerBlockType( - 'core/embed', - getEmbedBlockSettings( { - title: __( 'Embed' ), - icon: 'embed-generic', - transforms: { - from: [ - { - type: 'raw', - isMatch: ( node ) => node.nodeName === 'P' && /^\s*(https?:\/\/\S+)\s*/i.test( node.textContent ), - transform: ( node ) => { - return createBlock( 'core/embed', { - url: node.textContent.trim(), - } ); - }, +export const name = 'core/embed'; + +export const settings = getEmbedBlockSettings( { + title: __( 'Embed' ), + icon: 'embed-generic', + transforms: { + from: [ + { + type: 'raw', + isMatch: ( node ) => node.nodeName === 'P' && /^\s*(https?:\/\/\S+)\s*/i.test( node.textContent ), + transform: ( node ) => { + return createBlock( 'core/embed', { + url: node.textContent.trim(), + } ); }, - ], - }, - } ) -); + }, + ], + }, +} ); -// Common -registerBlockType( - 'core-embed/twitter', - getEmbedBlockSettings( { - title: 'Twitter', - icon: 'embed-post', - keywords: [ __( 'tweet' ) ], - } ) -); -registerBlockType( - 'core-embed/youtube', - getEmbedBlockSettings( { - title: 'YouTube', - icon: 'embed-video', - keywords: [ __( 'music' ), __( 'video' ) ], - } ) -); -registerBlockType( - 'core-embed/facebook', - getEmbedBlockSettings( { - title: 'Facebook', - icon: 'embed-post', - } ) -); -registerBlockType( - 'core-embed/instagram', - getEmbedBlockSettings( { - title: 'Instagram', - icon: 'embed-photo', - keywords: [ __( 'image' ) ], - } ) -); -registerBlockType( - 'core-embed/wordpress', - getEmbedBlockSettings( { - title: 'WordPress', - icon: 'embed-post', - keywords: [ __( 'post' ), __( 'blog' ) ], - } ) -); -registerBlockType( - 'core-embed/soundcloud', - getEmbedBlockSettings( { - title: 'SoundCloud', - icon: 'embed-audio', - keywords: [ __( 'music' ), __( 'audio' ) ], - } ) -); -registerBlockType( - 'core-embed/spotify', - getEmbedBlockSettings( { - title: 'Spotify', - icon: 'embed-audio', - keywords: [ __( 'music' ), __( 'audio' ) ], - } ) -); -registerBlockType( - 'core-embed/flickr', - getEmbedBlockSettings( { - title: 'Flickr', - icon: 'embed-photo', - keywords: [ __( 'image' ) ], - } ) -); -registerBlockType( - 'core-embed/vimeo', - getEmbedBlockSettings( { - title: 'Vimeo', - icon: 'embed-video', - keywords: [ __( 'video' ) ], - } ) -); +export const common = [ + { + name: 'core-embed/twitter', + settings: getEmbedBlockSettings( { + title: 'Twitter', + icon: 'embed-post', + keywords: [ __( 'tweet' ) ], + } ), + }, + { + name: 'core-embed/youtube', + settings: getEmbedBlockSettings( { + title: 'YouTube', + icon: 'embed-video', + keywords: [ __( 'music' ), __( 'video' ) ], + } ), + }, + { + name: 'core-embed/facebook', + settings: getEmbedBlockSettings( { + title: 'Facebook', + icon: 'embed-post', + } ), + }, + { + name: 'core-embed/instagram', + settings: getEmbedBlockSettings( { + title: 'Instagram', + icon: 'embed-photo', + keywords: [ __( 'image' ) ], + } ), + }, + { + name: 'core-embed/wordpress', + settings: getEmbedBlockSettings( { + title: 'WordPress', + icon: 'embed-post', + keywords: [ __( 'post' ), __( 'blog' ) ], + } ), + }, + { + name: 'core-embed/soundcloud', + settings: getEmbedBlockSettings( { + title: 'SoundCloud', + icon: 'embed-audio', + keywords: [ __( 'music' ), __( 'audio' ) ], + } ), + }, + { + name: 'core-embed/spotify', + settings: getEmbedBlockSettings( { + title: 'Spotify', + icon: 'embed-audio', + keywords: [ __( 'music' ), __( 'audio' ) ], + } ), + }, + { + name: 'core-embed/flickr', + settings: getEmbedBlockSettings( { + title: 'Flickr', + icon: 'embed-photo', + keywords: [ __( 'image' ) ], + } ), + }, + { + name: 'core-embed/vimeo', + settings: getEmbedBlockSettings( { + title: 'Vimeo', + icon: 'embed-video', + keywords: [ __( 'video' ) ], + } ), + }, +]; -// Others -registerBlockType( - 'core-embed/animoto', - getEmbedBlockSettings( { - title: 'Animoto', - icon: 'embed-video', - } ) -); -registerBlockType( - 'core-embed/cloudup', - getEmbedBlockSettings( { - title: 'Cloudup', - icon: 'embed-post', - } ) -); -registerBlockType( - 'core-embed/collegehumor', - getEmbedBlockSettings( { - title: 'CollegeHumor', - icon: 'embed-video', - } ) -); -registerBlockType( - 'core-embed/dailymotion', - getEmbedBlockSettings( { - title: 'Dailymotion', - icon: 'embed-video', - } ) -); -registerBlockType( - 'core-embed/funnyordie', - getEmbedBlockSettings( { - title: 'Funny or Die', - icon: 'embed-video', - } ) ); -registerBlockType( - 'core-embed/hulu', - getEmbedBlockSettings( { - title: 'Hulu', - icon: 'embed-video', - } ) -); -registerBlockType( - 'core-embed/imgur', - getEmbedBlockSettings( { - title: 'Imgur', - icon: 'embed-photo', - } ) -); -registerBlockType( - 'core-embed/issuu', - getEmbedBlockSettings( { - title: 'Issuu', - icon: 'embed-post', - } ) -); -registerBlockType( - 'core-embed/kickstarter', - getEmbedBlockSettings( { - title: 'Kickstarter', - icon: 'embed-post', - } ) -); -registerBlockType( - 'core-embed/meetup-com', - getEmbedBlockSettings( { - title: 'Meetup.com', - icon: 'embed-post', - } ) -); -registerBlockType( - 'core-embed/mixcloud', - getEmbedBlockSettings( { - title: 'Mixcloud', - icon: 'embed-audio', - keywords: [ __( 'music' ), __( 'audio' ) ], - } ) -); -registerBlockType( - 'core-embed/photobucket', - getEmbedBlockSettings( { - title: 'Photobucket', - icon: 'embed-photo', - } ) -); -registerBlockType( - 'core-embed/polldaddy', - getEmbedBlockSettings( { - title: 'Polldaddy', - icon: 'embed-post', - } ) -); -registerBlockType( - 'core-embed/reddit', - getEmbedBlockSettings( { - title: 'Reddit', - icon: 'embed-post', - } ) -); -registerBlockType( - 'core-embed/reverbnation', - getEmbedBlockSettings( { - title: 'ReverbNation', - icon: 'embed-audio', - } ) -); -registerBlockType( - 'core-embed/screencast', - getEmbedBlockSettings( { - title: 'Screencast', - icon: 'embed-video', - } ) -); -registerBlockType( - 'core-embed/scribd', - getEmbedBlockSettings( { - title: 'Scribd', - icon: 'embed-post', - } ) -); -registerBlockType( - 'core-embed/slideshare', - getEmbedBlockSettings( { - title: 'Slideshare', - icon: 'embed-post', - } ) -); -registerBlockType( - 'core-embed/smugmug', - getEmbedBlockSettings( { - title: 'SmugMug', - icon: 'embed-photo', - } ) -); -registerBlockType( - 'core-embed/speaker', - getEmbedBlockSettings( { - title: 'Speaker', - icon: 'embed-audio', - } ) -); -registerBlockType( - 'core-embed/ted', - getEmbedBlockSettings( { - title: 'TED', - icon: 'embed-video', - } ) -); -registerBlockType( - 'core-embed/tumblr', - getEmbedBlockSettings( { - title: 'Tumblr', - icon: 'embed-post', - } ) -); -registerBlockType( - 'core-embed/videopress', - getEmbedBlockSettings( { - title: 'VideoPress', - icon: 'embed-video', - keywords: [ __( 'video' ) ], - } ) -); -registerBlockType( - 'core-embed/wordpress-tv', - getEmbedBlockSettings( { - title: 'WordPress.tv', - icon: 'embed-video', - } ) -); +export const others = [ + { + name: 'core-embed/animoto', + settings: getEmbedBlockSettings( { + title: 'Animoto', + icon: 'embed-video', + } ), + }, + { + name: 'core-embed/cloudup', + settings: getEmbedBlockSettings( { + title: 'Cloudup', + icon: 'embed-post', + } ), + }, + { + name: 'core-embed/collegehumor', + settings: getEmbedBlockSettings( { + title: 'CollegeHumor', + icon: 'embed-video', + } ), + }, + { + name: 'core-embed/dailymotion', + settings: getEmbedBlockSettings( { + title: 'Dailymotion', + icon: 'embed-video', + } ), + }, + { + name: 'core-embed/funnyordie', + settings: getEmbedBlockSettings( { + title: 'Funny or Die', + icon: 'embed-video', + } ), + }, + { + name: 'core-embed/hulu', + settings: getEmbedBlockSettings( { + title: 'Hulu', + icon: 'embed-video', + } ), + }, + { + name: 'core-embed/imgur', + settings: getEmbedBlockSettings( { + title: 'Imgur', + icon: 'embed-photo', + } ), + }, + { + name: 'core-embed/issuu', + settings: getEmbedBlockSettings( { + title: 'Issuu', + icon: 'embed-post', + } ), + }, + { + name: 'core-embed/kickstarter', + settings: getEmbedBlockSettings( { + title: 'Kickstarter', + icon: 'embed-post', + } ), + }, + { + name: 'core-embed/meetup-com', + settings: getEmbedBlockSettings( { + title: 'Meetup.com', + icon: 'embed-post', + } ), + }, + { + name: 'core-embed/mixcloud', + settings: getEmbedBlockSettings( { + title: 'Mixcloud', + icon: 'embed-audio', + keywords: [ __( 'music' ), __( 'audio' ) ], + } ), + }, + { + name: 'core-embed/photobucket', + settings: getEmbedBlockSettings( { + title: 'Photobucket', + icon: 'embed-photo', + } ), + }, + { + name: 'core-embed/polldaddy', + settings: getEmbedBlockSettings( { + title: 'Polldaddy', + icon: 'embed-post', + } ), + }, + { + name: 'core-embed/reddit', + settings: getEmbedBlockSettings( { + title: 'Reddit', + icon: 'embed-post', + } ), + }, + { + name: 'core-embed/reverbnation', + settings: getEmbedBlockSettings( { + title: 'ReverbNation', + icon: 'embed-audio', + } ), + }, + { + name: 'core-embed/screencast', + settings: getEmbedBlockSettings( { + title: 'Screencast', + icon: 'embed-video', + } ), + }, + { + name: 'core-embed/scribd', + settings: getEmbedBlockSettings( { + title: 'Scribd', + icon: 'embed-post', + } ), + }, + { + name: 'core-embed/slideshare', + settings: getEmbedBlockSettings( { + title: 'Slideshare', + icon: 'embed-post', + } ), + }, + { + name: 'core-embed/smugmug', + settings: getEmbedBlockSettings( { + title: 'SmugMug', + icon: 'embed-photo', + } ), + }, + { + name: 'core-embed/speaker', + settings: getEmbedBlockSettings( { + title: 'Speaker', + icon: 'embed-audio', + } ), + }, + { + name: 'core-embed/ted', + settings: getEmbedBlockSettings( { + title: 'TED', + icon: 'embed-video', + } ), + }, + { + name: 'core-embed/tumblr', + settings: getEmbedBlockSettings( { + title: 'Tumblr', + icon: 'embed-post', + } ), + }, + { + name: 'core-embed/videopress', + settings: getEmbedBlockSettings( { + title: 'VideoPress', + icon: 'embed-video', + keywords: [ __( 'video' ) ], + } ), + }, + { + name: 'core-embed/wordpress-tv', + settings: getEmbedBlockSettings( { + title: 'WordPress.tv', + icon: 'embed-video', + } ), + }, +]; diff --git a/blocks/library/embed/test/index.js b/blocks/library/embed/test/index.js index 4713de801d2f1c..f6249d84357c8e 100644 --- a/blocks/library/embed/test/index.js +++ b/blocks/library/embed/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/embed', () => { test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/embed' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/freeform/index.js b/blocks/library/freeform/index.js index b92aa4f0994a91..fa5e63be0138eb 100644 --- a/blocks/library/freeform/index.js +++ b/blocks/library/freeform/index.js @@ -7,10 +7,11 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import './editor.scss'; -import { registerBlockType, setUnknownTypeHandlerName } from '../../api'; import OldEditor from './old-editor'; -registerBlockType( 'core/freeform', { +export const name = 'core/freeform'; + +export const settings = { title: __( 'Classic' ), desription: __( 'The classic editor, in block form.' ), @@ -32,6 +33,4 @@ registerBlockType( 'core/freeform', { const { content } = attributes; return content; }, -} ); - -setUnknownTypeHandlerName( 'core/freeform' ); +}; diff --git a/blocks/library/freeform/test/index.js b/blocks/library/freeform/test/index.js index 52682119c6ea59..aee9066d54cf56 100644 --- a/blocks/library/freeform/test/index.js +++ b/blocks/library/freeform/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/freeform', () => { 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 48912f4e780fb2..f3cd92ebabb3a5 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 = { }, }; -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 @@ registerBlockType( 'core/gallery', { }, }, ], - -} ); +}; diff --git a/blocks/library/gallery/test/index.js b/blocks/library/gallery/test/index.js index 9c6aadccd31b6d..1256a4d6aa6429 100644 --- a/blocks/library/gallery/test/index.js +++ b/blocks/library/gallery/test/index.js @@ -1,14 +1,14 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; jest.mock( 'blocks/media-upload', () => () => '*** Mock(Media upload button) ***' ); describe( 'core/gallery', () => { 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 348cc2e14a2de3..7c60dc764a0e15 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'; -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 @@ registerBlockType( 'core/heading', { ); }, -} ); +}; diff --git a/blocks/library/heading/test/index.js b/blocks/library/heading/test/index.js index fa20e31292d9e0..c1cba07d763d8a 100644 --- a/blocks/library/heading/test/index.js +++ b/blocks/library/heading/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/heading', () => { 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 05ebd25338e1e8..e36f1a3da88ee0 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'; -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 @@ 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 f4ef3e2b363233..dead9a7204616f 100644 --- a/blocks/library/html/test/index.js +++ b/blocks/library/html/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/html', () => { 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 150c9c3f137509..918fb3a26b6ec7 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'; -registerBlockType( 'core/image', { +export const name = 'core/image'; + +export const settings = { title: __( 'Image' ), description: __( 'Worth a thousand words.' ), @@ -179,4 +181,4 @@ registerBlockType( 'core/image', { ); }, -} ); +}; diff --git a/blocks/library/index.js b/blocks/library/index.js index e87daedbc06731..ac6c0b2c20d20e 100644 --- a/blocks/library/index.js +++ b/blocks/library/index.js @@ -1,26 +1,72 @@ -import './shortcode'; -import './image'; -import './gallery'; -import './heading'; -import './quote'; -import './embed'; -import './list'; -import './separator'; -import './more'; -import './button'; -import './pullquote'; -import './table'; -import './preformatted'; -import './code'; -import './html'; -import './freeform'; -import './latest-posts'; -import './categories'; -import './cover-image'; -import './text-columns'; -import './verse'; -import './video'; -import './audio'; -import './block'; -import './paragraph'; -import './subhead'; +/** + * 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 * 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 subhead from './subhead'; +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, + subhead, + table, + textColumns, + verse, + video, + ].forEach( ( { name, settings } ) => { + registerBlockType( name, settings ); + } ); + + setDefaultBlockName( paragraph.name ); + setUnknownTypeHandlerName( freeform.name ); +}; diff --git a/blocks/library/latest-posts/index.js b/blocks/library/latest-posts/index.js index 36fa381bca8585..3762b61e2a68b9 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'; -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 @@ registerBlockType( 'core/latest-posts', { save() { return null; }, -} ); +}; diff --git a/blocks/library/list/index.js b/blocks/library/list/index.js index 3e538c294170d2..03477d006739d1 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'; -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 @@ 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 @@ registerBlockType( 'core/list', { values ); }, -} ); +}; diff --git a/blocks/library/list/test/index.js b/blocks/library/list/test/index.js index 1668762990b0a4..d138bfe821efd5 100644 --- a/blocks/library/list/test/index.js +++ b/blocks/library/list/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/list', () => { 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 bb7c1e0f7e0ae5..719bbe650fb7d8 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'; -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 @@ registerBlockType( 'core/more', { save() { return null; }, -} ); +}; diff --git a/blocks/library/more/test/index.js b/blocks/library/more/test/index.js index 1f13406520beaa..c6d259bd293f9d 100644 --- a/blocks/library/more/test/index.js +++ b/blocks/library/more/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/more', () => { test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/more' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/paragraph/index.js b/blocks/library/paragraph/index.js index a20452db7449c8..83cd36df71194f 100644 --- a/blocks/library/paragraph/index.js +++ b/blocks/library/paragraph/index.js @@ -15,7 +15,7 @@ import { Autocomplete, PanelBody, PanelColor, withFallbackStyles } from '@wordpr */ import './editor.scss'; import './style.scss'; -import { registerBlockType, createBlock, setDefaultBlockName } from '../../api'; +import { createBlock } from '../../api'; import { blockAutocompleter, userAutocompleter } from '../../autocompleters'; import AlignmentToolbar from '../../alignment-toolbar'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; @@ -192,7 +192,9 @@ class ParagraphBlock extends Component { } } -registerBlockType( 'core/paragraph', { +export const name = 'core/paragraph'; + +export const settings = { title: __( 'Paragraph' ), description: __( 'This is a simple text only block for adding a single paragraph of content.' ), @@ -281,6 +283,4 @@ registerBlockType( 'core/paragraph', { return

{ content }

; }, -} ); - -setDefaultBlockName( 'core/paragraph' ); +}; diff --git a/blocks/library/paragraph/test/index.js b/blocks/library/paragraph/test/index.js index f0b7cf1659f488..7eb0dcfab4c68a 100644 --- a/blocks/library/paragraph/test/index.js +++ b/blocks/library/paragraph/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/paragraph', () => { test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/paragraph' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/preformatted/index.js b/blocks/library/preformatted/index.js index 1f6e2e922be505..bd110d6ca095dc 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'; -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 @@ registerBlockType( 'core/preformatted', { return
{ content }
; }, -} ); +}; diff --git a/blocks/library/preformatted/test/index.js b/blocks/library/preformatted/test/index.js index 70413a21704266..f190d8b5d77f96 100644 --- a/blocks/library/preformatted/test/index.js +++ b/blocks/library/preformatted/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/preformatted', () => { 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 00b1d4ef2cef4d..2f1511b88f2a09 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 = { }, }; -registerBlockType( 'core/pullquote', { +export const name = 'core/pullquote'; + +export const settings = { title: __( 'Pullquote' ), @@ -148,4 +149,4 @@ registerBlockType( 'core/pullquote', { ); }, } ], -} ); +}; diff --git a/blocks/library/pullquote/test/index.js b/blocks/library/pullquote/test/index.js index 74925c679092e1..40a2e28606e339 100644 --- a/blocks/library/pullquote/test/index.js +++ b/blocks/library/pullquote/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/pullquote', () => { 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 aa4251bcd8c701..579fc67265a71c 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 = { }, }; -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 @@ registerBlockType( 'core/quote', { }, }, ], -} ); +}; diff --git a/blocks/library/quote/test/index.js b/blocks/library/quote/test/index.js index 77be56ba416bb6..08f4c5f65f86c0 100644 --- a/blocks/library/quote/test/index.js +++ b/blocks/library/quote/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/quote', () => { 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 f2f91550035027..b387cd4eec4d52 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'; -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 @@ registerBlockType( 'core/separator', { save() { return
; }, -} ); +}; diff --git a/blocks/library/separator/test/index.js b/blocks/library/separator/test/index.js index 53efab1ac71fb0..ec79dc27e47ce9 100644 --- a/blocks/library/separator/test/index.js +++ b/blocks/library/separator/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/separator', () => { 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 e208f26482138c..483b279a97b832 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'; -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 @@ 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 97e9c0b4eae7cd..5892b6e57a1ad3 100644 --- a/blocks/library/shortcode/test/index.js +++ b/blocks/library/shortcode/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/shortcode', () => { test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/shortcode' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/library/subhead/index.js b/blocks/library/subhead/index.js index af9f7878276236..aae24a211fec35 100644 --- a/blocks/library/subhead/index.js +++ b/blocks/library/subhead/index.js @@ -8,12 +8,14 @@ import { __ } from '@wordpress/i18n'; */ import './editor.scss'; import './style.scss'; -import { registerBlockType, createBlock } from '../../api'; +import { createBlock } from '../../api'; import Editable from '../../editable'; import InspectorControls from '../../inspector-controls'; import BlockDescription from '../../block-description'; -registerBlockType( 'core/subhead', { +export const name = 'core/subhead'; + +export const settings = { title: __( 'Subhead' ), icon: 'text', @@ -88,4 +90,4 @@ registerBlockType( 'core/subhead', { return

{ content }

; }, -} ); +}; diff --git a/blocks/library/table/index.js b/blocks/library/table/index.js index f3ec2e2ca52bcf..b9c7636f089b37 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'; -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 @@ registerBlockType( 'core/table', { ); }, -} ); +}; diff --git a/blocks/library/table/test/index.js b/blocks/library/table/test/index.js index 9f1456b6439a73..f6249d84357c8e 100644 --- a/blocks/library/table/test/index.js +++ b/blocks/library/table/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/embed', () => { 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 ab209b2e4c3693..5126cc653a4fbf 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'; -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 @@ registerBlockType( 'core/text-columns', { ); }, -} ); +}; diff --git a/blocks/library/text-columns/test/index.js b/blocks/library/text-columns/test/index.js index 80abaf8e5d3343..6a94d0a8487b5e 100644 --- a/blocks/library/text-columns/test/index.js +++ b/blocks/library/text-columns/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/text-columns', () => { 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 cab739ee3224b3..1cec91dde4827d 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'; -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 @@ 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 760898207c41c6..f5df7557f9ad52 100644 --- a/blocks/library/verse/test/index.js +++ b/blocks/library/verse/test/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; describe( 'core/verse', () => { 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 472042a42106ef..d0da1dc4a16e02 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'; -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 @@ registerBlockType( 'core/video', { ); }, -} ); +}; diff --git a/blocks/library/video/test/index.js b/blocks/library/video/test/index.js index 3d22f432b7e4bf..d3e53da7625341 100644 --- a/blocks/library/video/test/index.js +++ b/blocks/library/video/test/index.js @@ -1,14 +1,14 @@ /** * Internal dependencies */ -import '../'; +import { name, settings } from '../'; import { blockEditRender } from 'blocks/test/helpers'; jest.mock( 'blocks/media-upload', () => () => '*** Mock(Media upload button) ***' ); describe( 'core/video', () => { test( 'block edit matches snapshot', () => { - const wrapper = blockEditRender( 'core/video' ); + const wrapper = blockEditRender( name, settings ); expect( wrapper ).toMatchSnapshot(); } ); diff --git a/blocks/test/full-content.js b/blocks/test/full-content.js index 2f480c64380f8e..be355e6d242a37 100644 --- a/blocks/test/full-content.js +++ b/blocks/test/full-content.js @@ -9,6 +9,7 @@ import { format } from 'util'; /** * Internal dependencies */ +import { registerCoreBlocks } from '../library'; import parse from '../api/parser'; import { parse as grammarParse } from '../api/post.pegjs'; import serialize from '../api/serializer'; @@ -91,8 +92,9 @@ describe( 'full post content fixture', () => { beforeAll( () => { window._wpBlocks = require( './server-registered.json' ); - // Register all blocks. - require( 'blocks' ); + // Load all hooks that modify blocks + require( 'blocks/hooks' ); + registerCoreBlocks(); } ); fileBasenames.forEach( f => { diff --git a/blocks/test/helpers/index.js b/blocks/test/helpers/index.js index 3f6dda0bfd326b..1f34a92311c0e6 100644 --- a/blocks/test/helpers/index.js +++ b/blocks/test/helpers/index.js @@ -7,10 +7,18 @@ import { noop } from 'lodash'; /** * Internal dependencies */ -import { createBlock, BlockEdit } from '../..'; +import { + createBlock, + getBlockType, + registerBlockType, + BlockEdit, +} from '../..'; -export const blockEditRender = ( name, initialAttributes = {} ) => { - const block = createBlock( name, initialAttributes ); +export const blockEditRender = ( name, settings ) => { + if ( ! getBlockType( name ) ) { + registerBlockType( name, settings ); + } + const block = createBlock( name ); return render( { + registerCoreBlocks(); + const paragraph = createBlock( 'core/paragraph' ); const headingH1 = createBlock( 'core/heading', { content: 'Heading 1', diff --git a/editor/edit-post/modes/visual-editor/test/inserter.js b/editor/edit-post/modes/visual-editor/test/inserter.js index 893b7122b1f35c..d7d96a9bc6fccb 100644 --- a/editor/edit-post/modes/visual-editor/test/inserter.js +++ b/editor/edit-post/modes/visual-editor/test/inserter.js @@ -6,7 +6,7 @@ import { shallow } from 'enzyme'; /** * WordPress dependencies */ -import { getBlockType } from '@wordpress/blocks'; +import { getBlockType, registerCoreBlocks } from '@wordpress/blocks'; /** * Internal dependencies @@ -14,6 +14,10 @@ import { getBlockType } from '@wordpress/blocks'; import { VisualEditorInserter } from '../inserter'; describe( 'VisualEditorInserter', () => { + beforeAll( () => { + registerCoreBlocks(); + } ); + it( 'should show controls when receiving focus', () => { const clearSelectedBlock = jest.fn(); const wrapper = shallow( ); diff --git a/editor/store/test/reducer.js b/editor/store/test/reducer.js index b545dbbed087d7..2703efc42cf568 100644 --- a/editor/store/test/reducer.js +++ b/editor/store/test/reducer.js @@ -7,7 +7,12 @@ import deepFreeze from 'deep-freeze'; /** * WordPress dependencies */ -import { registerBlockType, unregisterBlockType, getBlockType } from '@wordpress/blocks'; +import { + registerCoreBlocks, + registerBlockType, + unregisterBlockType, + getBlockType, +} from '@wordpress/blocks'; /** * Internal dependencies @@ -957,6 +962,10 @@ describe( 'state', () => { } ); describe( 'preferences()', () => { + beforeAll( () => { + registerCoreBlocks(); + } ); + it( 'should apply all defaults', () => { const state = preferences( undefined, {} ); diff --git a/editor/store/test/selectors.js b/editor/store/test/selectors.js index 30396887243dd0..7f9004b33a0010 100644 --- a/editor/store/test/selectors.js +++ b/editor/store/test/selectors.js @@ -7,7 +7,7 @@ import moment from 'moment'; * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { registerBlockType, unregisterBlockType, getBlockTypes } from '@wordpress/blocks'; +import { getBlockTypes, registerBlockType, registerCoreBlocks, unregisterBlockType } from '@wordpress/blocks'; /** * Internal dependencies @@ -2119,6 +2119,10 @@ describe( 'selectors', () => { } ); describe( 'getMostFrequentlyUsedBlocks', () => { + beforeAll( () => { + registerCoreBlocks(); + } ); + it( 'should have paragraph and image to bring frequently used blocks up to three blocks', () => { const noUsage = { preferences: { blockUsage: {} } }; const someUsage = { preferences: { blockUsage: { 'core/paragraph': 1 } } }; @@ -2250,6 +2254,10 @@ describe( 'selectors', () => { } ); describe( 'getRecentInserterItems', () => { + beforeAll( () => { + registerCoreBlocks(); + } ); + it( 'should return the most recently used blocks', () => { const state = { preferences: { diff --git a/lib/client-assets.php b/lib/client-assets.php index 749320802b77d4..d4a62be7833ba6 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -905,6 +905,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) { $script .= sprintf( 'var editorSettings = %s;', wp_json_encode( $editor_settings ) ); $script .= <<