From e7ea7b4c89b650e48da1ba28f222f47aea86c590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Ventura?= Date: Fri, 19 May 2017 13:36:58 +0200 Subject: [PATCH 01/12] Change api/registration `getBlocks` to `getRegisteredBlocks`. --- blocks/api/registration.js | 4 ++-- blocks/api/test/factory.js | 4 ++-- blocks/api/test/parser.js | 4 ++-- blocks/api/test/registration.js | 14 +++++++------- blocks/api/test/serializer.js | 4 ++-- blocks/editable/index.js | 16 ++++++++-------- editor/block-switcher/index.js | 2 +- editor/inserter/menu.js | 6 +++--- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/blocks/api/registration.js b/blocks/api/registration.js index 3dcd1f86b356c6..db3c404005c91f 100644 --- a/blocks/api/registration.js +++ b/blocks/api/registration.js @@ -87,7 +87,7 @@ export function getUnknownTypeHandler() { } /** - * Returns settings associated with a registered block. + * Returns a registered block and its settings. * * @param {string} slug Block slug * @return {?Object} Block settings @@ -101,6 +101,6 @@ export function getBlockSettings( slug ) { * * @return {Array} Block settings */ -export function getBlocks() { +export function getRegisteredBlocks() { return Object.values( blocks ); } diff --git a/blocks/api/test/factory.js b/blocks/api/test/factory.js index 94be4006bad47b..42d0294aa38b51 100644 --- a/blocks/api/test/factory.js +++ b/blocks/api/test/factory.js @@ -7,12 +7,12 @@ import { expect } from 'chai'; * Internal dependencies */ import { createBlock, switchToBlockType } from '../factory'; -import { getBlocks, unregisterBlock, setUnknownTypeHandler, registerBlock } from '../registration'; +import { getRegisteredBlocks, unregisterBlock, setUnknownTypeHandler, registerBlock } from '../registration'; describe( 'block factory', () => { afterEach( () => { setUnknownTypeHandler( undefined ); - getBlocks().forEach( ( block ) => { + getRegisteredBlocks().forEach( ( block ) => { unregisterBlock( block.slug ); } ); } ); diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index 889a347d10e9f2..ab80c3cc440c8c 100644 --- a/blocks/api/test/parser.js +++ b/blocks/api/test/parser.js @@ -17,14 +17,14 @@ import { import { registerBlock, unregisterBlock, - getBlocks, + getRegisteredBlocks, setUnknownTypeHandler, } from '../registration'; describe( 'block parser', () => { afterEach( () => { setUnknownTypeHandler( undefined ); - getBlocks().forEach( ( block ) => { + getRegisteredBlocks().forEach( ( block ) => { unregisterBlock( block.slug ); } ); } ); diff --git a/blocks/api/test/registration.js b/blocks/api/test/registration.js index 4299d900d66eaa..32f153c8a03b03 100644 --- a/blocks/api/test/registration.js +++ b/blocks/api/test/registration.js @@ -15,7 +15,7 @@ import { setUnknownTypeHandler, getUnknownTypeHandler, getBlockSettings, - getBlocks, + getRegisteredBlocks, } from '../registration'; describe( 'blocks', () => { @@ -25,7 +25,7 @@ describe( 'blocks', () => { } ); afterEach( () => { - getBlocks().forEach( block => { + getRegisteredBlocks().forEach( block => { unregisterBlock( block.slug ); } ); setUnknownTypeHandler( undefined ); @@ -84,13 +84,13 @@ describe( 'blocks', () => { it( 'should unregister existing blocks', () => { registerBlock( 'core/test-block' ); - expect( getBlocks() ).to.eql( [ + expect( getRegisteredBlocks() ).to.eql( [ { slug: 'core/test-block' }, ] ); const oldBlock = unregisterBlock( 'core/test-block' ); expect( console.error ).to.not.have.been.called(); expect( oldBlock ).to.eql( { slug: 'core/test-block' } ); - expect( getBlocks() ).to.eql( [] ); + expect( getRegisteredBlocks() ).to.eql( [] ); } ); } ); @@ -126,16 +126,16 @@ describe( 'blocks', () => { } ); } ); - describe( 'getBlocks()', () => { + describe( 'getRegisteredBlocks()', () => { it( 'should return an empty array at first', () => { - expect( getBlocks() ).to.eql( [] ); + expect( getRegisteredBlocks() ).to.eql( [] ); } ); it( 'should return all registered blocks', () => { registerBlock( 'core/test-block' ); const blockSettings = { settingName: 'settingValue' }; registerBlock( 'core/test-block-with-settings', blockSettings ); - expect( getBlocks() ).to.eql( [ + expect( getRegisteredBlocks() ).to.eql( [ { slug: 'core/test-block' }, { slug: 'core/test-block-with-settings', settingName: 'settingValue' }, ] ); diff --git a/blocks/api/test/serializer.js b/blocks/api/test/serializer.js index 493cddeec2bb00..73da8aa8729a4b 100644 --- a/blocks/api/test/serializer.js +++ b/blocks/api/test/serializer.js @@ -7,11 +7,11 @@ import { expect } from 'chai'; * Internal dependencies */ import serialize, { getCommentAttributes, getSaveContent } from '../serializer'; -import { getBlocks, registerBlock, unregisterBlock } from '../registration'; +import { getRegisteredBlocks, registerBlock, unregisterBlock } from '../registration'; describe( 'block serializer', () => { afterEach( () => { - getBlocks().forEach( block => { + getRegisteredBlocks().forEach( block => { unregisterBlock( block.slug ); } ); } ); diff --git a/blocks/editable/index.js b/blocks/editable/index.js index 6d2a16af6f16d8..b0645495cec1fb 100644 --- a/blocks/editable/index.js +++ b/blocks/editable/index.js @@ -306,9 +306,9 @@ export default class Editable extends wp.element.Component { this.savedContent = this.props.value; this.setContent( this.savedContent ); this.editor.selection.moveToBookmark( bookmark ); + // Saving the editor on updates avoid unecessary onChanges calls // These calls can make the focus jump - this.editor.save(); } @@ -348,7 +348,7 @@ export default class Editable extends wp.element.Component { this.updateFocus(); } - // The savedContent var allows us to avoid updating the content right after an onChange call + // The `savedContent` var allows us to avoid updating the content right after an `onChange` call if ( this.props.tagName === prevProps.tagName && this.props.value !== prevProps.value && @@ -425,8 +425,8 @@ export default class Editable extends wp.element.Component { } = this.props; // Generating a key that includes `tagName` ensures that if the tag - // changes, we unmount (+ destroy) the previous TinyMCE element, then - // mount (+ initialize) a new child element in its place. + // changes, we unmount and destroy the previous TinyMCE element, then + // mount and initialize a new child element in its place. const key = [ 'editor', tagName ].join(); const classes = classnames( className, 'blocks-editable' ); @@ -449,18 +449,17 @@ export default class Editable extends wp.element.Component { ...control, onClick: () => this.toggleAlignment( control.align ), isActive: this.isAlignmentActive( control.align ), - } ) ) } /> + } ) ) } + /> } { ! inlineToolbar && formatToolbar } } - { focus && inlineToolbar &&
{ formatToolbar }
} - + key={ key } + /> ); } diff --git a/editor/block-switcher/index.js b/editor/block-switcher/index.js index 9f35c455ef4aed..8176584a002972 100644 --- a/editor/block-switcher/index.js +++ b/editor/block-switcher/index.js @@ -51,7 +51,7 @@ class BlockSwitcher extends wp.element.Component { render() { const blockSettings = wp.blocks.getBlockSettings( this.props.block.blockType ); - const blocksToBeTransformedFrom = reduce( wp.blocks.getBlocks(), ( memo, block ) => { + const blocksToBeTransformedFrom = reduce( wp.blocks.getRegisteredBlocks(), ( memo, block ) => { const transformFrom = get( block, 'transforms.from', [] ); const transformation = find( transformFrom, t => t.blocks.indexOf( this.props.block.blockType ) !== -1 ); return transformation ? memo.concat( [ block.slug ] ) : memo; diff --git a/editor/inserter/menu.js b/editor/inserter/menu.js index add96a3f4d57cb..a88f14e5bc23e1 100644 --- a/editor/inserter/menu.js +++ b/editor/inserter/menu.js @@ -150,7 +150,7 @@ class InserterMenu extends wp.element.Component { const sortedByCategory = flow( this.getVisibleBlocks, this.sortBlocksByCategory, - )( wp.blocks.getBlocks() ); + )( wp.blocks.getRegisteredBlocks() ); // If the block list is empty return early. if ( ! sortedByCategory.length ) { @@ -165,7 +165,7 @@ class InserterMenu extends wp.element.Component { const sortedByCategory = flow( this.getVisibleBlocks, this.sortBlocksByCategory, - )( wp.blocks.getBlocks() ); + )( wp.blocks.getRegisteredBlocks() ); // If the block list is empty return early. if ( ! sortedByCategory.length ) { @@ -238,7 +238,7 @@ class InserterMenu extends wp.element.Component { render() { const { position = 'top' } = this.props; - const visibleBlocksByCategory = this.getVisibleBlocksByCategory( wp.blocks.getBlocks() ); + const visibleBlocksByCategory = this.getVisibleBlocksByCategory( wp.blocks.getRegisteredBlocks() ); const positionClasses = position.split( ' ' ).map( ( pos ) => `is-${ pos }` ); const className = classnames( 'editor-inserter__menu', positionClasses ); From c86eebccd7d4f9b6b88d5ec8bb969bf4730657f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Ventura?= Date: Fri, 19 May 2017 15:03:36 +0200 Subject: [PATCH 02/12] Update inline documentation in blocks/api. --- blocks/api/factory.js | 10 +++++++--- blocks/api/parser.js | 34 +++++++++++++++++++--------------- blocks/api/serializer.js | 4 ++-- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/blocks/api/factory.js b/blocks/api/factory.js index 0e76f452f5fe3d..1294f3072466f6 100644 --- a/blocks/api/factory.js +++ b/blocks/api/factory.js @@ -10,20 +10,24 @@ import { get, castArray, findIndex, isObjectLike, find } from 'lodash'; import { getBlockSettings } from './registration'; /** - * Returns a block object given its type and attributes + * Returns a block object given its type and attributes. * * @param {String} blockType BlockType * @param {Object} attributes Block attributes * @return {Object} Block object */ export function createBlock( blockType, attributes = {} ) { + // Get the type definition associated with a registered block. const blockSettings = getBlockSettings( blockType ); + // Do we need this? What purpose does it have? let defaultAttributes; if ( blockSettings ) { defaultAttributes = blockSettings.defaultAttributes; } + // Blocks are stored with a unique ID, the assigned type name, + // and the block attributes. return { uid: uuid(), blockType, @@ -35,7 +39,7 @@ export function createBlock( blockType, attributes = {} ) { } /** - * Switch a block into one or more blocks of the new block type + * Switch a block into one or more blocks of the new block type. * * @param {Object} block Block object * @param {string} blockType BlockType @@ -52,7 +56,7 @@ export function switchToBlockType( block, blockType ) { find( transformationsTo, t => t.blocks.indexOf( blockType ) !== -1 ) || find( transformationsFrom, t => t.blocks.indexOf( block.blockType ) !== -1 ); - // If no valid transformation, stop. (How did we get here?) + // Stop if there is no valid transformation. (How did we get here?) if ( ! transformation ) { return null; } diff --git a/blocks/api/parser.js b/blocks/api/parser.js index 4bda5ecf86efbe..b0d8e610076401 100644 --- a/blocks/api/parser.js +++ b/blocks/api/parser.js @@ -47,7 +47,8 @@ export function parseBlockAttributes( rawContent, blockSettings ) { * @return {Object} All block attributes */ export function getBlockAttributes( blockSettings, rawContent, attributes ) { - // Merge any attributes from comment delimiters with block implementation + // Merge any attributes present in comment delimiters with those + // that are specified in the block implementation. attributes = attributes || {}; if ( blockSettings ) { attributes = { @@ -69,10 +70,10 @@ export function getBlockAttributes( blockSettings, rawContent, attributes ) { * @return {?Object} An initialized block object (if possible) */ export function createBlockWithFallback( blockType, rawContent, attributes ) { - // Use type from block content, otherwise find unknown handler + // Use type from block content, otherwise find unknown handler. blockType = blockType || getUnknownTypeHandler(); - // Try finding settings for known block type, else again fall back + // Try finding settings for known block type, else fall back again. let blockSettings = getBlockSettings( blockType ); const fallbackBlockType = getUnknownTypeHandler(); if ( ! blockSettings ) { @@ -80,7 +81,7 @@ export function createBlockWithFallback( blockType, rawContent, attributes ) { blockSettings = getBlockSettings( blockType ); } - // Include in set only if settings were determined + // Include in set only if settings were determined. // TODO do we ever expect there to not be an unknown type handler? if ( blockSettings && ( rawContent.trim() || blockType !== fallbackBlockType ) ) { // TODO allow blocks to opt-in to receiving a tree instead of a string. @@ -123,16 +124,19 @@ export function parseWithTinyMCE( content ) { } ); - // Create a custom HTML schema + // Create a custom HTML schema. const schema = new tinymce.html.Schema(); - // Add "tags" to our schema + + // Add "tags" to our schema. schema.addCustomElements( 'wp-block' ); - // Add valid "attributes" also + + // Add valid "attributes" also. schema.addValidElements( 'wp-block[slug|attributes]' ); - // Initialize the parser with our custom schema + + // Initialize the parser with our custom schema. const parser = new tinymce.html.DomParser( { validate: true }, schema ); - // Parse the content into an object tree + // Parse the content into an object tree. const tree = parser.parse( content ); // Create a serializer that we will use to pass strings to blocks. @@ -140,10 +144,10 @@ export function parseWithTinyMCE( content ) { // shapes that each block can accept. const serializer = new tinymce.html.Serializer( { validate: true }, schema ); - // Walk the tree and initialize blocks + // Walk the tree and initialize blocks. const blocks = []; - // Store markup we found in between blocks + // Store markup we found in between blocks. let contentBetweenBlocks = null; function flushContentBetweenBlocks() { if ( contentBetweenBlocks && contentBetweenBlocks.firstChild ) { @@ -164,19 +168,19 @@ export function parseWithTinyMCE( content ) { while ( currentNode ) { if ( currentNode.name === 'wp-block' ) { // Set node type to document fragment so that the TinyMCE - // serializer doesn't output its markup + // serializer doesn't output its markup. currentNode.type = 11; // Serialize the content const rawContent = serializer.serialize( currentNode ); - // Retrieve the attributes from the tag + // Retrieve the attributes from the tag. const nodeAttributes = currentNode.attributes.reduce( ( memo, attr ) => { memo[ attr.name ] = attr.value; return memo; }, {} ); - // Retrieve the block attributes from the original delimiters + // Retrieve the block attributes from the original delimiters. const attributesMatcher = /([a-z0-9_-]+)(="([^"]*)")?/g; const blockAttributes = {}; let match; @@ -187,7 +191,7 @@ export function parseWithTinyMCE( content ) { } } while ( !! match ); - // Try to create the block + // Try to create the block. const block = createBlockWithFallback( nodeAttributes.slug, rawContent, diff --git a/blocks/api/serializer.js b/blocks/api/serializer.js index 88b07a63072c02..3c3dac8f500e01 100644 --- a/blocks/api/serializer.js +++ b/blocks/api/serializer.js @@ -52,7 +52,7 @@ export function getCommentAttributes( realAttributes, expectedAttributes ) { Object.keys( expectedAttributes ) ); - // Serialize the comment attributes + // Serialize the comment attributes as `key="value"`. return keys.reduce( ( memo, key ) => { const value = realAttributes[ key ]; if ( undefined === value ) { @@ -64,7 +64,7 @@ export function getCommentAttributes( realAttributes, expectedAttributes ) { } /** - * Takes a block list and returns the serialized post content + * Takes a block list and returns the serialized post content. * * @param {Array} blocks Block list * @return {String} The post content From 41cb88990e415596bd9282852dc7166e18bb97e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Ventura?= Date: Fri, 19 May 2017 15:51:06 +0200 Subject: [PATCH 03/12] Expose getBlocks as getRegisteredBlocks. --- blocks/api/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/api/index.js b/blocks/api/index.js index dff1c5456ab3e3..2f9df2150f4225 100644 --- a/blocks/api/index.js +++ b/blocks/api/index.js @@ -14,5 +14,5 @@ export { setUnknownTypeHandler, getUnknownTypeHandler, getBlockSettings, - getBlocks, + getRegisteredBlocks, } from './registration'; From 9c81157f129121ecafe4e39ec7317a29a6ca2943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Ventura?= Date: Tue, 30 May 2017 19:39:07 +0200 Subject: [PATCH 04/12] Use getBlockTypes. --- blocks/api/index.js | 2 +- blocks/api/registration.js | 2 +- blocks/api/test/factory.js | 4 ++-- blocks/api/test/parser.js | 4 ++-- blocks/api/test/registration.js | 14 +++++++------- blocks/api/test/serializer.js | 4 ++-- editor/block-switcher/index.js | 2 +- editor/inserter/menu.js | 6 +++--- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/blocks/api/index.js b/blocks/api/index.js index 2f9df2150f4225..ea3dc7d7fc1948 100644 --- a/blocks/api/index.js +++ b/blocks/api/index.js @@ -14,5 +14,5 @@ export { setUnknownTypeHandler, getUnknownTypeHandler, getBlockSettings, - getRegisteredBlocks, + getBlockTypes, } from './registration'; diff --git a/blocks/api/registration.js b/blocks/api/registration.js index db3c404005c91f..601d96ac43afe3 100644 --- a/blocks/api/registration.js +++ b/blocks/api/registration.js @@ -101,6 +101,6 @@ export function getBlockSettings( slug ) { * * @return {Array} Block settings */ -export function getRegisteredBlocks() { +export function getBlockTypes() { return Object.values( blocks ); } diff --git a/blocks/api/test/factory.js b/blocks/api/test/factory.js index 42d0294aa38b51..638b1b85538708 100644 --- a/blocks/api/test/factory.js +++ b/blocks/api/test/factory.js @@ -7,12 +7,12 @@ import { expect } from 'chai'; * Internal dependencies */ import { createBlock, switchToBlockType } from '../factory'; -import { getRegisteredBlocks, unregisterBlock, setUnknownTypeHandler, registerBlock } from '../registration'; +import { getBlockTypes, unregisterBlock, setUnknownTypeHandler, registerBlock } from '../registration'; describe( 'block factory', () => { afterEach( () => { setUnknownTypeHandler( undefined ); - getRegisteredBlocks().forEach( ( block ) => { + getBlockTypes().forEach( ( block ) => { unregisterBlock( block.slug ); } ); } ); diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index ab80c3cc440c8c..36e088f1974fd6 100644 --- a/blocks/api/test/parser.js +++ b/blocks/api/test/parser.js @@ -17,14 +17,14 @@ import { import { registerBlock, unregisterBlock, - getRegisteredBlocks, + getBlockTypes, setUnknownTypeHandler, } from '../registration'; describe( 'block parser', () => { afterEach( () => { setUnknownTypeHandler( undefined ); - getRegisteredBlocks().forEach( ( block ) => { + getBlockTypes().forEach( ( block ) => { unregisterBlock( block.slug ); } ); } ); diff --git a/blocks/api/test/registration.js b/blocks/api/test/registration.js index 32f153c8a03b03..0740b7550339c3 100644 --- a/blocks/api/test/registration.js +++ b/blocks/api/test/registration.js @@ -15,7 +15,7 @@ import { setUnknownTypeHandler, getUnknownTypeHandler, getBlockSettings, - getRegisteredBlocks, + getBlockTypes, } from '../registration'; describe( 'blocks', () => { @@ -25,7 +25,7 @@ describe( 'blocks', () => { } ); afterEach( () => { - getRegisteredBlocks().forEach( block => { + getBlockTypes().forEach( block => { unregisterBlock( block.slug ); } ); setUnknownTypeHandler( undefined ); @@ -84,13 +84,13 @@ describe( 'blocks', () => { it( 'should unregister existing blocks', () => { registerBlock( 'core/test-block' ); - expect( getRegisteredBlocks() ).to.eql( [ + expect( getBlockTypes() ).to.eql( [ { slug: 'core/test-block' }, ] ); const oldBlock = unregisterBlock( 'core/test-block' ); expect( console.error ).to.not.have.been.called(); expect( oldBlock ).to.eql( { slug: 'core/test-block' } ); - expect( getRegisteredBlocks() ).to.eql( [] ); + expect( getBlockTypes() ).to.eql( [] ); } ); } ); @@ -126,16 +126,16 @@ describe( 'blocks', () => { } ); } ); - describe( 'getRegisteredBlocks()', () => { + describe( 'getBlockTypes()', () => { it( 'should return an empty array at first', () => { - expect( getRegisteredBlocks() ).to.eql( [] ); + expect( getBlockTypes() ).to.eql( [] ); } ); it( 'should return all registered blocks', () => { registerBlock( 'core/test-block' ); const blockSettings = { settingName: 'settingValue' }; registerBlock( 'core/test-block-with-settings', blockSettings ); - expect( getRegisteredBlocks() ).to.eql( [ + expect( getBlockTypes() ).to.eql( [ { slug: 'core/test-block' }, { slug: 'core/test-block-with-settings', settingName: 'settingValue' }, ] ); diff --git a/blocks/api/test/serializer.js b/blocks/api/test/serializer.js index 73da8aa8729a4b..3d576be6570a9a 100644 --- a/blocks/api/test/serializer.js +++ b/blocks/api/test/serializer.js @@ -7,11 +7,11 @@ import { expect } from 'chai'; * Internal dependencies */ import serialize, { getCommentAttributes, getSaveContent } from '../serializer'; -import { getRegisteredBlocks, registerBlock, unregisterBlock } from '../registration'; +import { getBlockTypes, registerBlock, unregisterBlock } from '../registration'; describe( 'block serializer', () => { afterEach( () => { - getRegisteredBlocks().forEach( block => { + getBlockTypes().forEach( block => { unregisterBlock( block.slug ); } ); } ); diff --git a/editor/block-switcher/index.js b/editor/block-switcher/index.js index 8176584a002972..1743db3a74b3fc 100644 --- a/editor/block-switcher/index.js +++ b/editor/block-switcher/index.js @@ -51,7 +51,7 @@ class BlockSwitcher extends wp.element.Component { render() { const blockSettings = wp.blocks.getBlockSettings( this.props.block.blockType ); - const blocksToBeTransformedFrom = reduce( wp.blocks.getRegisteredBlocks(), ( memo, block ) => { + const blocksToBeTransformedFrom = reduce( wp.blocks.getBlockTypes(), ( memo, block ) => { const transformFrom = get( block, 'transforms.from', [] ); const transformation = find( transformFrom, t => t.blocks.indexOf( this.props.block.blockType ) !== -1 ); return transformation ? memo.concat( [ block.slug ] ) : memo; diff --git a/editor/inserter/menu.js b/editor/inserter/menu.js index a88f14e5bc23e1..d34ccd16b6d292 100644 --- a/editor/inserter/menu.js +++ b/editor/inserter/menu.js @@ -150,7 +150,7 @@ class InserterMenu extends wp.element.Component { const sortedByCategory = flow( this.getVisibleBlocks, this.sortBlocksByCategory, - )( wp.blocks.getRegisteredBlocks() ); + )( wp.blocks.getBlockTypes() ); // If the block list is empty return early. if ( ! sortedByCategory.length ) { @@ -165,7 +165,7 @@ class InserterMenu extends wp.element.Component { const sortedByCategory = flow( this.getVisibleBlocks, this.sortBlocksByCategory, - )( wp.blocks.getRegisteredBlocks() ); + )( wp.blocks.getBlockTypes() ); // If the block list is empty return early. if ( ! sortedByCategory.length ) { @@ -238,7 +238,7 @@ class InserterMenu extends wp.element.Component { render() { const { position = 'top' } = this.props; - const visibleBlocksByCategory = this.getVisibleBlocksByCategory( wp.blocks.getRegisteredBlocks() ); + const visibleBlocksByCategory = this.getVisibleBlocksByCategory( wp.blocks.getBlockTypes() ); const positionClasses = position.split( ' ' ).map( ( pos ) => `is-${ pos }` ); const className = classnames( 'editor-inserter__menu', positionClasses ); From 9ef4372919b7c2b4b322cd376ed47c36bdeb4866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Ventura?= Date: Tue, 30 May 2017 19:57:56 +0200 Subject: [PATCH 05/12] Switch to getBlockType / blockName pair. --- blocks/README.md | 2 +- blocks/api/factory.js | 22 +++++++-------- blocks/api/index.js | 2 +- blocks/api/parser.js | 44 ++++++++++++++--------------- blocks/api/registration.js | 6 ++-- blocks/api/serializer.js | 14 ++++----- blocks/api/test/registration.js | 28 +++++++++--------- editor/block-switcher/index.js | 18 ++++++------ editor/effects.js | 8 +++--- editor/modes/visual-editor/block.js | 14 ++++----- 10 files changed, 79 insertions(+), 79 deletions(-) diff --git a/blocks/README.md b/blocks/README.md index b2bdcc85db12bd..30ba31903bb109 100644 --- a/blocks/README.md +++ b/blocks/README.md @@ -146,7 +146,7 @@ Registers a new block-level control. Controls appear in a block's toolbar when i Inline controls for [`Editable`](#editable) elements are identical for every block and cannot be modified. -### `wp.blocks.getBlockSettings( slug: string )` +### `wp.blocks.getBlockType( slug: string )` Returns settings associated with a registered block. diff --git a/blocks/api/factory.js b/blocks/api/factory.js index 1294f3072466f6..b374c7414e0ada 100644 --- a/blocks/api/factory.js +++ b/blocks/api/factory.js @@ -7,30 +7,30 @@ import { get, castArray, findIndex, isObjectLike, find } from 'lodash'; /** * Internal dependencies */ -import { getBlockSettings } from './registration'; +import { getBlockType } from './registration'; /** * Returns a block object given its type and attributes. * - * @param {String} blockType BlockType + * @param {String} blockName Block name * @param {Object} attributes Block attributes * @return {Object} Block object */ -export function createBlock( blockType, attributes = {} ) { +export function createBlock( blockName, attributes = {} ) { // Get the type definition associated with a registered block. - const blockSettings = getBlockSettings( blockType ); + const blockType = getBlockType( blockName ); // Do we need this? What purpose does it have? let defaultAttributes; - if ( blockSettings ) { - defaultAttributes = blockSettings.defaultAttributes; + if ( blockType ) { + defaultAttributes = blockType.defaultAttributes; } // Blocks are stored with a unique ID, the assigned type name, // and the block attributes. return { uid: uuid(), - blockType, + blockName, attributes: { ...defaultAttributes, ...attributes, @@ -48,13 +48,13 @@ export function createBlock( blockType, attributes = {} ) { export function switchToBlockType( block, blockType ) { // Find the right transformation by giving priority to the "to" // transformation. - const destinationSettings = getBlockSettings( blockType ); - const sourceSettings = getBlockSettings( block.blockType ); + const destinationSettings = getBlockType( blockType ); + const sourceSettings = getBlockType( block.blockName ); const transformationsFrom = get( destinationSettings, 'transforms.from', [] ); const transformationsTo = get( sourceSettings, 'transforms.to', [] ); const transformation = find( transformationsTo, t => t.blocks.indexOf( blockType ) !== -1 ) || - find( transformationsFrom, t => t.blocks.indexOf( block.blockType ) !== -1 ); + find( transformationsFrom, t => t.blocks.indexOf( block.blockName ) !== -1 ); // Stop if there is no valid transformation. (How did we get here?) if ( ! transformation ) { @@ -75,7 +75,7 @@ export function switchToBlockType( block, blockType ) { // Ensure that every block object returned by the transformation has a // valid block type. - if ( transformationResults.some( ( result ) => ! getBlockSettings( result.blockType ) ) ) { + if ( transformationResults.some( ( result ) => ! getBlockType( result.blockType ) ) ) { return null; } diff --git a/blocks/api/index.js b/blocks/api/index.js index ea3dc7d7fc1948..62fea244958bbe 100644 --- a/blocks/api/index.js +++ b/blocks/api/index.js @@ -13,6 +13,6 @@ export { unregisterBlock, setUnknownTypeHandler, getUnknownTypeHandler, - getBlockSettings, + getBlockType, getBlockTypes, } from './registration'; diff --git a/blocks/api/parser.js b/blocks/api/parser.js index b0d8e610076401..dceb42d74c43dc 100644 --- a/blocks/api/parser.js +++ b/blocks/api/parser.js @@ -9,18 +9,18 @@ import { escape, unescape, pickBy } from 'lodash'; * Internal dependencies */ import { parse as grammarParse } from './post.pegjs'; -import { getBlockSettings, getUnknownTypeHandler } from './registration'; +import { getBlockType, getUnknownTypeHandler } from './registration'; import { createBlock } from './factory'; /** * Returns the block attributes parsed from raw content. * * @param {String} rawContent Raw block content - * @param {Object} blockSettings Block settings + * @param {Object} blockType Block type * @return {Object} Block attributes */ -export function parseBlockAttributes( rawContent, blockSettings ) { - const { attributes } = blockSettings; +export function parseBlockAttributes( rawContent, blockType ) { + const { attributes } = blockType; if ( 'function' === typeof attributes ) { return attributes( rawContent ); } else if ( attributes ) { @@ -41,20 +41,20 @@ export function parseBlockAttributes( rawContent, blockSettings ) { /** * Returns the block attributes of a registered block node given its settings. * - * @param {?Object} blockSettings Block settings + * @param {?Object} blockType Block type * @param {string} rawContent Raw block content * @param {?Object} attributes Known block attributes (from delimiters) * @return {Object} All block attributes */ -export function getBlockAttributes( blockSettings, rawContent, attributes ) { +export function getBlockAttributes( blockType, rawContent, attributes ) { // Merge any attributes present in comment delimiters with those // that are specified in the block implementation. attributes = attributes || {}; - if ( blockSettings ) { + if ( blockType ) { attributes = { ...attributes, - ...blockSettings.defaultAttributes, - ...parseBlockAttributes( rawContent, blockSettings ), + ...blockType.defaultAttributes, + ...parseBlockAttributes( rawContent, blockType ), }; } @@ -64,32 +64,32 @@ export function getBlockAttributes( blockSettings, rawContent, attributes ) { /** * Creates a block with fallback to the unknown type handler. * - * @param {?String} blockType Block type slug + * @param {?String} name Block type slug * @param {String} rawContent Raw block content * @param {?Object} attributes Attributes obtained from block delimiters * @return {?Object} An initialized block object (if possible) */ -export function createBlockWithFallback( blockType, rawContent, attributes ) { +export function createBlockWithFallback( name, rawContent, attributes ) { // Use type from block content, otherwise find unknown handler. - blockType = blockType || getUnknownTypeHandler(); - - // Try finding settings for known block type, else fall back again. - let blockSettings = getBlockSettings( blockType ); - const fallbackBlockType = getUnknownTypeHandler(); - if ( ! blockSettings ) { - blockType = fallbackBlockType; - blockSettings = getBlockSettings( blockType ); + name = name || getUnknownTypeHandler(); + + // Try finding settings for known block name, else fall back again. + let blockType = getBlockType( name ); + const fallbackBlock = getUnknownTypeHandler(); + if ( ! blockType ) { + name = fallbackBlock; + blockType = getBlockType( name ); } // Include in set only if settings were determined. // TODO do we ever expect there to not be an unknown type handler? - if ( blockSettings && ( rawContent.trim() || blockType !== fallbackBlockType ) ) { + if ( blockType && ( rawContent.trim() || name !== fallbackBlock ) ) { // TODO allow blocks to opt-in to receiving a tree instead of a string. // Gradually convert all blocks to this new format, then remove the // string serialization. const block = createBlock( - blockType, - getBlockAttributes( blockSettings, rawContent.trim(), attributes ) + name, + getBlockAttributes( blockType, rawContent.trim(), attributes ) ); return block; } diff --git a/blocks/api/registration.js b/blocks/api/registration.js index 601d96ac43afe3..77fc7217f64e90 100644 --- a/blocks/api/registration.js +++ b/blocks/api/registration.js @@ -87,12 +87,12 @@ export function getUnknownTypeHandler() { } /** - * Returns a registered block and its settings. + * Returns a registered block type. * * @param {string} slug Block slug - * @return {?Object} Block settings + * @return {?Object} Block type */ -export function getBlockSettings( slug ) { +export function getBlockType( slug ) { return blocks[ slug ]; } diff --git a/blocks/api/serializer.js b/blocks/api/serializer.js index 3c3dac8f500e01..8ae83b463c80d9 100644 --- a/blocks/api/serializer.js +++ b/blocks/api/serializer.js @@ -7,7 +7,7 @@ import { html as beautifyHtml } from 'js-beautify'; /** * Internal dependencies */ -import { getBlockSettings } from './registration'; +import { getBlockType } from './registration'; import { parseBlockAttributes } from './parser'; /** @@ -71,9 +71,9 @@ export function getCommentAttributes( realAttributes, expectedAttributes ) { */ export default function serialize( blocks ) { return blocks.reduce( ( memo, block ) => { - const blockType = block.blockType; - const settings = getBlockSettings( blockType ); - const saveContent = getSaveContent( settings.save, block.attributes ); + const blockName = block.blockName; + const blockType = getBlockType( blockName ); + const saveContent = getSaveContent( blockType.save, block.attributes ); const beautifyOptions = { indent_inner_html: true, wrap_line_length: 0, @@ -81,16 +81,16 @@ export default function serialize( blocks ) { return memo + ( '' + ( saveContent ? '\n' + beautifyHtml( saveContent, beautifyOptions ) + '\n' : '' ) + '' ) + '\n\n'; }, '' ); diff --git a/blocks/api/test/registration.js b/blocks/api/test/registration.js index 0740b7550339c3..aa1af55146b845 100644 --- a/blocks/api/test/registration.js +++ b/blocks/api/test/registration.js @@ -14,7 +14,7 @@ import { unregisterBlock, setUnknownTypeHandler, getUnknownTypeHandler, - getBlockSettings, + getBlockType, getBlockTypes, } from '../registration'; @@ -64,11 +64,11 @@ describe( 'blocks', () => { expect( block ).to.be.undefined(); } ); - it( 'should store a copy of block settings', () => { - const blockSettings = { settingName: 'settingValue' }; - registerBlock( 'core/test-block-with-settings', blockSettings ); - blockSettings.mutated = true; - expect( getBlockSettings( 'core/test-block-with-settings' ) ).to.eql( { + it( 'should store a copy of block type', () => { + const blockType = { settingName: 'settingValue' }; + registerBlock( 'core/test-block-with-settings', blockType ); + blockType.mutated = true; + expect( getBlockType( 'core/test-block-with-settings' ) ).to.eql( { slug: 'core/test-block-with-settings', settingName: 'settingValue', } ); @@ -108,18 +108,18 @@ describe( 'blocks', () => { } ); } ); - describe( 'getBlockSettings()', () => { + describe( 'getBlockType()', () => { it( 'should return { slug } for blocks with no settings', () => { registerBlock( 'core/test-block' ); - expect( getBlockSettings( 'core/test-block' ) ).to.eql( { + expect( getBlockType( 'core/test-block' ) ).to.eql( { slug: 'core/test-block', } ); } ); - it( 'should return all block settings', () => { - const blockSettings = { settingName: 'settingValue' }; - registerBlock( 'core/test-block-with-settings', blockSettings ); - expect( getBlockSettings( 'core/test-block-with-settings' ) ).to.eql( { + it( 'should return all block type elements', () => { + const blockType = { settingName: 'settingValue' }; + registerBlock( 'core/test-block-with-settings', blockType ); + expect( getBlockType( 'core/test-block-with-settings' ) ).to.eql( { slug: 'core/test-block-with-settings', settingName: 'settingValue', } ); @@ -133,8 +133,8 @@ describe( 'blocks', () => { it( 'should return all registered blocks', () => { registerBlock( 'core/test-block' ); - const blockSettings = { settingName: 'settingValue' }; - registerBlock( 'core/test-block-with-settings', blockSettings ); + const blockType = { settingName: 'settingValue' }; + registerBlock( 'core/test-block-with-settings', blockType ); expect( getBlockTypes() ).to.eql( [ { slug: 'core/test-block' }, { slug: 'core/test-block-with-settings', settingName: 'settingValue' }, diff --git a/editor/block-switcher/index.js b/editor/block-switcher/index.js index 1743db3a74b3fc..f2f9067bb61e39 100644 --- a/editor/block-switcher/index.js +++ b/editor/block-switcher/index.js @@ -40,27 +40,27 @@ class BlockSwitcher extends wp.element.Component { } ); } - switchBlockType( blockType ) { + switchBlockType( name ) { return () => { this.setState( { open: false, } ); - this.props.onTransform( this.props.block, blockType ); + this.props.onTransform( this.props.block, name ); }; } render() { - const blockSettings = wp.blocks.getBlockSettings( this.props.block.blockType ); + const blockType = wp.blocks.getBlockType( this.props.block.blockType ); const blocksToBeTransformedFrom = reduce( wp.blocks.getBlockTypes(), ( memo, block ) => { const transformFrom = get( block, 'transforms.from', [] ); const transformation = find( transformFrom, t => t.blocks.indexOf( this.props.block.blockType ) !== -1 ); return transformation ? memo.concat( [ block.slug ] ) : memo; }, [] ); - const blocksToBeTransformedTo = get( blockSettings, 'transforms.to', [] ) + const blocksToBeTransformedTo = get( blockType, 'transforms.to', [] ) .reduce( ( memo, transformation ) => memo.concat( transformation.blocks ), [] ); const allowedBlocks = uniq( blocksToBeTransformedFrom.concat( blocksToBeTransformedTo ) ) - .reduce( ( memo, blockType ) => { - const block = wp.blocks.getBlockSettings( blockType ); + .reduce( ( memo, name ) => { + const block = wp.blocks.getBlockType( name ); return !! block ? memo.concat( block ) : memo; }, [] ); @@ -72,7 +72,7 @@ class BlockSwitcher extends wp.element.Component {
( { - onTransform( block, blockType ) { + onTransform( block, name ) { dispatch( replaceBlocks( [ ownProps.uid ], - wp.blocks.switchToBlockType( block, blockType ) + wp.blocks.switchToBlockType( block, name ) ) ); }, } ) diff --git a/editor/effects.js b/editor/effects.js index 4cfe18fb7d84cc..237c4ed328a73f 100644 --- a/editor/effects.js +++ b/editor/effects.js @@ -6,7 +6,7 @@ import { get } from 'lodash'; /** * WordPress dependencies */ -import { getBlockSettings, switchToBlockType } from 'blocks'; +import { getBlockType, switchToBlockType } from 'blocks'; import { __ } from 'i18n'; /** @@ -71,10 +71,10 @@ export default { MERGE_BLOCKS( action, store ) { const { dispatch } = store; const [ blockA, blockB ] = action.blocks; - const blockASettings = getBlockSettings( blockA.blockType ); + const blockType = getBlockType( blockA.blockType ); // Only focus the previous block if it's not mergeable - if ( ! blockASettings.merge ) { + if ( ! blockType.merge ) { dispatch( focusBlock( blockA.uid ) ); return; } @@ -91,7 +91,7 @@ export default { } // Calling the merge to update the attributes and remove the block to be merged - const updatedAttributes = blockASettings.merge( + const updatedAttributes = blockType.merge( blockA.attributes, blocksWithTheSameType[ 0 ].attributes ); diff --git a/editor/modes/visual-editor/block.js b/editor/modes/visual-editor/block.js index cc93ddf663d919..efdd6e74eafbca 100644 --- a/editor/modes/visual-editor/block.js +++ b/editor/modes/visual-editor/block.js @@ -182,11 +182,11 @@ class VisualEditorBlock extends wp.element.Component { render() { const { block, selectedBlocks } = this.props; - const settings = wp.blocks.getBlockSettings( block.blockType ); + const blockType = wp.blocks.getBlockType( block.blockType ); let BlockEdit; - if ( settings ) { - BlockEdit = settings.edit || settings.save; + if ( blockType ) { + BlockEdit = blockType.edit || blockType.save; } if ( ! BlockEdit ) { @@ -205,8 +205,8 @@ class VisualEditorBlock extends wp.element.Component { // Determine whether the block has props to apply to the wrapper let wrapperProps; - if ( settings.getEditWrapperProps ) { - wrapperProps = settings.getEditWrapperProps( block.attributes ); + if ( blockType.getEditWrapperProps ) { + wrapperProps = blockType.getEditWrapperProps( block.attributes ); } // Disable reason: Each block can be selected by clicking on it @@ -244,9 +244,9 @@ class VisualEditorBlock extends wp.element.Component { >
- { !! settings.controls && ( + { !! blockType.controls && ( ( { + controls={ blockType.controls.map( ( control ) => ( { ...control, onClick: () => control.onClick( block.attributes, this.setAttributes ), isActive: control.isActive ? control.isActive( block.attributes ) : false, From a2fe4633d24da3dd5b8f10015d538c9a0a115119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Ventura?= Date: Tue, 30 May 2017 20:34:21 +0200 Subject: [PATCH 06/12] Fix tests. --- blocks/api/factory.js | 14 ++-- blocks/api/test/factory.js | 30 ++++---- blocks/api/test/parser.js | 16 ++--- blocks/api/test/serializer.js | 2 +- blocks/test/fixtures/core-button-center.json | 2 +- blocks/test/fixtures/core-code.json | 2 +- .../fixtures/core-embed-youtube-caption.json | 2 +- blocks/test/fixtures/core-freeform.json | 2 +- blocks/test/fixtures/core-heading-h2-em.json | 2 +- blocks/test/fixtures/core-heading-h2.json | 2 +- .../fixtures/core-image-center-caption.json | 2 +- blocks/test/fixtures/core-image.json | 2 +- blocks/test/fixtures/core-list-ul.json | 2 +- blocks/test/fixtures/core-preformatted.json | 2 +- blocks/test/fixtures/core-pullquote.json | 2 +- blocks/test/fixtures/core-quote-style-1.json | 2 +- blocks/test/fixtures/core-quote-style-2.json | 2 +- blocks/test/fixtures/core-separator.json | 2 +- blocks/test/fixtures/core-table.json | 2 +- .../test/fixtures/core-text-align-right.json | 2 +- .../fixtures/core-text-multi-paragraph.json | 2 +- blocks/test/full-content.js | 4 +- editor/block-switcher/index.js | 4 +- editor/modes/visual-editor/block.js | 4 +- editor/sidebar/block-inspector/index.js | 2 +- editor/test/effects.js | 24 +++---- editor/test/selectors.js | 44 ++++++------ editor/test/state.js | 68 +++++++++---------- 28 files changed, 123 insertions(+), 123 deletions(-) diff --git a/blocks/api/factory.js b/blocks/api/factory.js index b374c7414e0ada..b6985026c8723b 100644 --- a/blocks/api/factory.js +++ b/blocks/api/factory.js @@ -42,18 +42,18 @@ export function createBlock( blockName, attributes = {} ) { * Switch a block into one or more blocks of the new block type. * * @param {Object} block Block object - * @param {string} blockType BlockType + * @param {string} blockName Block name * @return {Array} Block object */ -export function switchToBlockType( block, blockType ) { +export function switchToBlockType( block, blockName ) { // Find the right transformation by giving priority to the "to" // transformation. - const destinationSettings = getBlockType( blockType ); + const destinationSettings = getBlockType( blockName ); const sourceSettings = getBlockType( block.blockName ); const transformationsFrom = get( destinationSettings, 'transforms.from', [] ); const transformationsTo = get( sourceSettings, 'transforms.to', [] ); const transformation = - find( transformationsTo, t => t.blocks.indexOf( blockType ) !== -1 ) || + find( transformationsTo, t => t.blocks.indexOf( blockName ) !== -1 ) || find( transformationsFrom, t => t.blocks.indexOf( block.blockName ) !== -1 ); // Stop if there is no valid transformation. (How did we get here?) @@ -75,11 +75,11 @@ export function switchToBlockType( block, blockType ) { // Ensure that every block object returned by the transformation has a // valid block type. - if ( transformationResults.some( ( result ) => ! getBlockType( result.blockType ) ) ) { + if ( transformationResults.some( ( result ) => ! getBlockType( result.blockName ) ) ) { return null; } - const firstSwitchedBlock = findIndex( transformationResults, ( result ) => result.blockType === blockType ); + const firstSwitchedBlock = findIndex( transformationResults, ( result ) => result.blockName === blockName ); // Ensure that at least one block object returned by the transformation has // the expected "destination" block type. @@ -92,7 +92,7 @@ export function switchToBlockType( block, blockType ) { // The first transformed block whose type matches the "destination" // type gets to keep the existing block's UID. uid: index === firstSwitchedBlock ? block.uid : result.uid, - blockType: result.blockType, + blockName: result.blockName, attributes: result.attributes, }; } ); diff --git a/blocks/api/test/factory.js b/blocks/api/test/factory.js index 638b1b85538708..124ebf19f49307 100644 --- a/blocks/api/test/factory.js +++ b/blocks/api/test/factory.js @@ -28,7 +28,7 @@ describe( 'block factory', () => { align: 'left', } ); - expect( block.blockType ).to.eql( 'core/test-block' ); + expect( block.blockName ).to.eql( 'core/test-block' ); expect( block.attributes ).to.eql( { includesDefault: true, align: 'left', @@ -55,7 +55,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'ribs', }, @@ -65,7 +65,7 @@ describe( 'block factory', () => { expect( updatedBlock ).to.eql( [ { uid: 1, - blockType: 'core/updated-text-block', + blockName: 'core/updated-text-block', attributes: { value: 'chicken ribs', }, @@ -89,7 +89,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'ribs', }, @@ -99,7 +99,7 @@ describe( 'block factory', () => { expect( updatedBlock ).to.eql( [ { uid: 1, - blockType: 'core/updated-text-block', + blockName: 'core/updated-text-block', attributes: { value: 'chicken ribs', }, @@ -112,7 +112,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'ribs', }, @@ -136,7 +136,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'ribs', }, @@ -160,7 +160,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'ribs', }, @@ -190,7 +190,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'ribs', }, @@ -225,7 +225,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'ribs', }, @@ -253,7 +253,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'ribs', }, @@ -286,7 +286,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'ribs', }, @@ -319,7 +319,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'ribs', }, @@ -337,13 +337,13 @@ describe( 'block factory', () => { expect( updatedBlock ).to.eql( [ { uid: 2, - blockType: 'core/text-block', + blockName: 'core/text-block', attributes: { value: 'chicken ribs', }, }, { uid: 1, - blockType: 'core/updated-text-block', + blockName: 'core/updated-text-block', attributes: { value: 'smoked ribs', }, diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index 36e088f1974fd6..e38030545a3470 100644 --- a/blocks/api/test/parser.js +++ b/blocks/api/test/parser.js @@ -100,7 +100,7 @@ describe( 'block parser', () => { 'content', { attr: 'value' } ); - expect( block.blockType ).to.eql( 'core/test-block' ); + expect( block.blockName ).to.eql( 'core/test-block' ); expect( block.attributes ).to.eql( { attr: 'value' } ); } ); @@ -108,7 +108,7 @@ describe( 'block parser', () => { registerBlock( 'core/test-block', {} ); const block = createBlockWithFallback( 'core/test-block', 'content' ); - expect( block.blockType ).to.eql( 'core/test-block' ); + expect( block.blockName ).to.eql( 'core/test-block' ); expect( block.attributes ).to.eql( {} ); } ); @@ -121,7 +121,7 @@ describe( 'block parser', () => { 'content', { attr: 'value' } ); - expect( block.blockType ).to.eql( 'core/unknown-block' ); + expect( block.blockName ).to.eql( 'core/unknown-block' ); expect( block.attributes ).to.eql( { attr: 'value' } ); } ); @@ -130,7 +130,7 @@ describe( 'block parser', () => { setUnknownTypeHandler( 'core/unknown-block' ); const block = createBlockWithFallback( null, 'content' ); - expect( block.blockType ).to.eql( 'core/unknown-block' ); + expect( block.blockName ).to.eql( 'core/unknown-block' ); expect( block.attributes ).to.eql( {} ); } ); @@ -162,7 +162,7 @@ describe( 'block parser', () => { ); expect( parsed ).to.have.lengthOf( 1 ); - expect( parsed[ 0 ].blockType ).to.equal( 'core/test-block' ); + expect( parsed[ 0 ].blockName ).to.equal( 'core/test-block' ); expect( parsed[ 0 ].attributes ).to.eql( { content: 'Brisket', smoked: 'yes', @@ -195,7 +195,7 @@ describe( 'block parser', () => { ); expect( parsed ).to.have.lengthOf( 1 ); - expect( parsed[ 0 ].blockType ).to.equal( 'core/test-block' ); + expect( parsed[ 0 ].blockName ).to.equal( 'core/test-block' ); expect( parsed[ 0 ].attributes ).to.eql( { content: 'Ribs & Chicken', } ); @@ -215,7 +215,7 @@ describe( 'block parser', () => { ); expect( parsed ).to.have.lengthOf( 3 ); - expect( parsed.map( ( { blockType } ) => blockType ) ).to.eql( [ + expect( parsed.map( ( { blockName } ) => blockName ) ).to.eql( [ 'core/test-block', 'core/unknown-block', 'core/unknown-block', @@ -244,7 +244,7 @@ describe( 'block parser', () => { ); expect( parsed ).to.have.lengthOf( 5 ); - expect( parsed.map( ( { blockType } ) => blockType ) ).to.eql( [ + expect( parsed.map( ( { blockName } ) => blockName ) ).to.eql( [ 'core/unknown-block', 'core/test-block', 'core/unknown-block', diff --git a/blocks/api/test/serializer.js b/blocks/api/test/serializer.js index 3d576be6570a9a..4503db188131a5 100644 --- a/blocks/api/test/serializer.js +++ b/blocks/api/test/serializer.js @@ -102,7 +102,7 @@ describe( 'block serializer', () => { registerBlock( 'core/test-block', blockSettings ); const blockList = [ { - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: { content: 'Ribs & Chicken', align: 'left', diff --git a/blocks/test/fixtures/core-button-center.json b/blocks/test/fixtures/core-button-center.json index 9cc92bc17c4b8a..570c6649201b67 100644 --- a/blocks/test/fixtures/core-button-center.json +++ b/blocks/test/fixtures/core-button-center.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/button", + "blockName": "core/button", "attributes": { "align": "center", "url": "https://github.com/WordPress/gutenberg", diff --git a/blocks/test/fixtures/core-code.json b/blocks/test/fixtures/core-code.json index 6b47db4f880606..e208865e3dca80 100644 --- a/blocks/test/fixtures/core-code.json +++ b/blocks/test/fixtures/core-code.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/code", + "blockName": "core/code", "attributes": { "content": "export default function MyButton() {\n\treturn ;\n}" } diff --git a/blocks/test/fixtures/core-embed-youtube-caption.json b/blocks/test/fixtures/core-embed-youtube-caption.json index aff60b23db6c1e..2f6102f5e253db 100644 --- a/blocks/test/fixtures/core-embed-youtube-caption.json +++ b/blocks/test/fixtures/core-embed-youtube-caption.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/embed", + "blockName": "core/embed", "attributes": { "url": "//www.youtube.com/embed/Nl6U7UotA-M", "caption": [ diff --git a/blocks/test/fixtures/core-freeform.json b/blocks/test/fixtures/core-freeform.json index cf8daa0bf85abf..e5e0813e3331c3 100644 --- a/blocks/test/fixtures/core-freeform.json +++ b/blocks/test/fixtures/core-freeform.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/freeform", + "blockName": "core/freeform", "attributes": { "html": "Testing freeform block with some
HTML content
" } diff --git a/blocks/test/fixtures/core-heading-h2-em.json b/blocks/test/fixtures/core-heading-h2-em.json index d42b8a4d12b6d0..774fa988237adf 100644 --- a/blocks/test/fixtures/core-heading-h2-em.json +++ b/blocks/test/fixtures/core-heading-h2-em.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/heading", + "blockName": "core/heading", "attributes": { "content": [ "The ", diff --git a/blocks/test/fixtures/core-heading-h2.json b/blocks/test/fixtures/core-heading-h2.json index 19aaeb48ea60d1..98cdbc59bc9c94 100644 --- a/blocks/test/fixtures/core-heading-h2.json +++ b/blocks/test/fixtures/core-heading-h2.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/heading", + "blockName": "core/heading", "attributes": { "content": [ "A picture is worth a thousand words, or so the saying goes" diff --git a/blocks/test/fixtures/core-image-center-caption.json b/blocks/test/fixtures/core-image-center-caption.json index 3550e2bf7ae666..a883bf143af80a 100644 --- a/blocks/test/fixtures/core-image-center-caption.json +++ b/blocks/test/fixtures/core-image-center-caption.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/image", + "blockName": "core/image", "attributes": { "align": "center", "url": "https://cldup.com/YLYhpou2oq.jpg", diff --git a/blocks/test/fixtures/core-image.json b/blocks/test/fixtures/core-image.json index 34818e9a60ea08..fc982f7513ba76 100644 --- a/blocks/test/fixtures/core-image.json +++ b/blocks/test/fixtures/core-image.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/image", + "blockName": "core/image", "attributes": { "url": "https://cldup.com/uuUqE_dXzy.jpg", "caption": [] diff --git a/blocks/test/fixtures/core-list-ul.json b/blocks/test/fixtures/core-list-ul.json index 5c39a4b34faa25..15717a69fecbd8 100644 --- a/blocks/test/fixtures/core-list-ul.json +++ b/blocks/test/fixtures/core-list-ul.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/list", + "blockName": "core/list", "attributes": { "nodeName": "UL", "values": [ diff --git a/blocks/test/fixtures/core-preformatted.json b/blocks/test/fixtures/core-preformatted.json index 083a138132eb07..a573ddab5324e5 100644 --- a/blocks/test/fixtures/core-preformatted.json +++ b/blocks/test/fixtures/core-preformatted.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/preformatted", + "blockName": "core/preformatted", "attributes": { "content": [ "Some ", diff --git a/blocks/test/fixtures/core-pullquote.json b/blocks/test/fixtures/core-pullquote.json index be58e7d4167f1f..2a271301e4a573 100644 --- a/blocks/test/fixtures/core-pullquote.json +++ b/blocks/test/fixtures/core-pullquote.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/pullquote", + "blockName": "core/pullquote", "attributes": { "value": [ [ diff --git a/blocks/test/fixtures/core-quote-style-1.json b/blocks/test/fixtures/core-quote-style-1.json index b109c2c5deeb99..b0187fe4d74812 100644 --- a/blocks/test/fixtures/core-quote-style-1.json +++ b/blocks/test/fixtures/core-quote-style-1.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/quote", + "blockName": "core/quote", "attributes": { "style": "1", "value": [ diff --git a/blocks/test/fixtures/core-quote-style-2.json b/blocks/test/fixtures/core-quote-style-2.json index daf838c3e648d0..1e3b87982a9d65 100644 --- a/blocks/test/fixtures/core-quote-style-2.json +++ b/blocks/test/fixtures/core-quote-style-2.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/quote", + "blockName": "core/quote", "attributes": { "style": "2", "value": [ diff --git a/blocks/test/fixtures/core-separator.json b/blocks/test/fixtures/core-separator.json index f38860c394e769..83bf90d5c8972c 100644 --- a/blocks/test/fixtures/core-separator.json +++ b/blocks/test/fixtures/core-separator.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/separator", + "blockName": "core/separator", "attributes": {} } ] diff --git a/blocks/test/fixtures/core-table.json b/blocks/test/fixtures/core-table.json index a41df6d2aa49eb..1e43a30ec56db6 100644 --- a/blocks/test/fixtures/core-table.json +++ b/blocks/test/fixtures/core-table.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/table", + "blockName": "core/table", "attributes": { "body": [ [ diff --git a/blocks/test/fixtures/core-text-align-right.json b/blocks/test/fixtures/core-text-align-right.json index c7fd3846c45857..486b1afc5123df 100644 --- a/blocks/test/fixtures/core-text-align-right.json +++ b/blocks/test/fixtures/core-text-align-right.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/text", + "blockName": "core/text", "attributes": { "content": [ { diff --git a/blocks/test/fixtures/core-text-multi-paragraph.json b/blocks/test/fixtures/core-text-multi-paragraph.json index e1afda57342e00..8b019be283f3ae 100644 --- a/blocks/test/fixtures/core-text-multi-paragraph.json +++ b/blocks/test/fixtures/core-text-multi-paragraph.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockType": "core/text", + "blockName": "core/text", "attributes": { "content": [ { diff --git a/blocks/test/full-content.js b/blocks/test/full-content.js index 747d04a1d952c1..0798782fb5e3db 100644 --- a/blocks/test/full-content.js +++ b/blocks/test/full-content.js @@ -15,7 +15,7 @@ import { parseWithTinyMCE, } from '../api/parser'; import serialize from '../api/serializer'; -import { getBlocks } from '../api/registration'; +import { getBlockTypes } from '../api/registration'; const fixturesDir = path.join( __dirname, 'fixtures' ); @@ -134,7 +134,7 @@ describe( 'full post content fixture', () => { it( 'should be present for each block', () => { const errors = []; - getBlocks().map( block => block.slug ).forEach( slug => { + getBlockTypes().map( block => block.slug ).forEach( slug => { const slugToFilename = slug.replace( /\//g, '-' ); const foundFixtures = fileBasenames .filter( basename => ( diff --git a/editor/block-switcher/index.js b/editor/block-switcher/index.js index f2f9067bb61e39..c76820feccdba0 100644 --- a/editor/block-switcher/index.js +++ b/editor/block-switcher/index.js @@ -50,10 +50,10 @@ class BlockSwitcher extends wp.element.Component { } render() { - const blockType = wp.blocks.getBlockType( this.props.block.blockType ); + const blockType = wp.blocks.getBlockType( this.props.block.blockName ); const blocksToBeTransformedFrom = reduce( wp.blocks.getBlockTypes(), ( memo, block ) => { const transformFrom = get( block, 'transforms.from', [] ); - const transformation = find( transformFrom, t => t.blocks.indexOf( this.props.block.blockType ) !== -1 ); + const transformation = find( transformFrom, t => t.blocks.indexOf( this.props.block.blockName ) !== -1 ); return transformation ? memo.concat( [ block.slug ] ) : memo; }, [] ); const blocksToBeTransformedTo = get( blockType, 'transforms.to', [] ) diff --git a/editor/modes/visual-editor/block.js b/editor/modes/visual-editor/block.js index efdd6e74eafbca..dc808a318f14e0 100644 --- a/editor/modes/visual-editor/block.js +++ b/editor/modes/visual-editor/block.js @@ -182,7 +182,7 @@ class VisualEditorBlock extends wp.element.Component { render() { const { block, selectedBlocks } = this.props; - const blockType = wp.blocks.getBlockType( block.blockType ); + const blockType = wp.blocks.getBlockType( block.blockName ); let BlockEdit; if ( blockType ) { @@ -228,7 +228,7 @@ class VisualEditorBlock extends wp.element.Component { onMouseEnter={ this.maybeHover } onMouseLeave={ onMouseLeave } className={ className } - data-type={ block.blockType } + data-type={ block.blockName } tabIndex="0" { ...wrapperProps } > diff --git a/editor/sidebar/block-inspector/index.js b/editor/sidebar/block-inspector/index.js index 9a55f2756abe83..0e773a0d9e239e 100644 --- a/editor/sidebar/block-inspector/index.js +++ b/editor/sidebar/block-inspector/index.js @@ -35,7 +35,7 @@ const BlockInspector = ( { selectedBlock, ...props } ) => { -
{ selectedBlock.blockType } settings...
+
{ selectedBlock.blockName } settings...
    { Object.keys( selectedBlock.attributes ).map( ( attribute, index ) => (
  • { attribute }: { selectedBlock.attributes[ attribute ] }
  • diff --git a/editor/test/effects.js b/editor/test/effects.js index 9d3c8deef8849d..5b3a6b91df8ea8 100644 --- a/editor/test/effects.js +++ b/editor/test/effects.js @@ -7,7 +7,7 @@ import sinon from 'sinon'; /** * WordPress dependencies */ -import { getBlocks, unregisterBlock, registerBlock, createBlock } from 'blocks'; +import { getBlockTypes, unregisterBlock, registerBlock, createBlock } from 'blocks'; /** * Internal dependencies @@ -20,7 +20,7 @@ describe( 'effects', () => { const handler = effects.MERGE_BLOCKS; afterEach( () => { - getBlocks().forEach( ( block ) => { + getBlockTypes().forEach( ( block ) => { unregisterBlock( block.slug ); } ); } ); @@ -29,11 +29,11 @@ describe( 'effects', () => { registerBlock( 'core/test-block', {} ); const blockA = { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', }; const blockB = { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', }; const dispatch = sinon.spy(); handler( mergeBlocks( blockA, blockB ), { dispatch } ); @@ -52,12 +52,12 @@ describe( 'effects', () => { } ); const blockA = { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: { content: 'chicken' }, }; const blockB = { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: { content: 'ribs' }, }; const dispatch = sinon.spy(); @@ -67,7 +67,7 @@ describe( 'effects', () => { expect( dispatch ).to.have.been.calledWith( focusBlock( 'chicken', { offset: -1 } ) ); expect( dispatch ).to.have.been.calledWith( replaceBlocks( [ 'chicken', 'ribs' ], [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: { content: 'chicken ribs' }, } ] ) ); } ); @@ -83,12 +83,12 @@ describe( 'effects', () => { registerBlock( 'core/test-block-2', {} ); const blockA = { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: { content: 'chicken' }, }; const blockB = { uid: 'ribs', - blockType: 'core/test-block2', + blockName: 'core/test-block2', attributes: { content: 'ribs' }, }; const dispatch = sinon.spy(); @@ -120,12 +120,12 @@ describe( 'effects', () => { } ); const blockA = { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: { content: 'chicken' }, }; const blockB = { uid: 'ribs', - blockType: 'core/test-block-2', + blockName: 'core/test-block-2', attributes: { content2: 'ribs' }, }; const dispatch = sinon.spy(); @@ -135,7 +135,7 @@ describe( 'effects', () => { expect( dispatch ).to.have.been.calledWith( focusBlock( 'chicken', { offset: -1 } ) ); expect( dispatch ).to.have.been.calledWith( replaceBlocks( [ 'chicken', 'ribs' ], [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: { content: 'chicken ribs' }, } ] ) ); } ); diff --git a/editor/test/selectors.js b/editor/test/selectors.js index de6427a00cf600..d644bfe47f1fe4 100644 --- a/editor/test/selectors.js +++ b/editor/test/selectors.js @@ -360,12 +360,12 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 123: { uid: 123, blockType: 'core/text' }, + 123: { uid: 123, blockName: 'core/text' }, }, }, }; - expect( getBlock( state, 123 ) ).to.eql( { uid: 123, blockType: 'core/text' } ); + expect( getBlock( state, 123 ) ).to.eql( { uid: 123, blockName: 'core/text' } ); } ); } ); @@ -374,16 +374,16 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockType: 'core/heading' }, - 123: { uid: 123, blockType: 'core/text' }, + 23: { uid: 23, blockName: 'core/heading' }, + 123: { uid: 123, blockName: 'core/text' }, }, blockOrder: [ 123, 23 ], }, }; expect( getBlocks( state ) ).to.eql( [ - { uid: 123, blockType: 'core/text' }, - { uid: 23, blockType: 'core/heading' }, + { uid: 123, blockName: 'core/text' }, + { uid: 23, blockName: 'core/heading' }, ] ); } ); } ); @@ -393,8 +393,8 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockType: 'core/heading' }, - 123: { uid: 123, blockType: 'core/text' }, + 23: { uid: 23, blockName: 'core/heading' }, + 123: { uid: 123, blockName: 'core/text' }, }, }, selectedBlock: { uid: null }, @@ -408,8 +408,8 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockType: 'core/heading' }, - 123: { uid: 123, blockType: 'core/text' }, + 23: { uid: 23, blockName: 'core/heading' }, + 123: { uid: 123, blockName: 'core/text' }, }, }, selectedBlock: { uid: 23 }, @@ -423,8 +423,8 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockType: 'core/heading' }, - 123: { uid: 123, blockType: 'core/text' }, + 23: { uid: 23, blockName: 'core/heading' }, + 123: { uid: 123, blockName: 'core/text' }, }, }, selectedBlock: { uid: 23 }, @@ -532,15 +532,15 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockType: 'core/heading' }, - 123: { uid: 123, blockType: 'core/text' }, + 23: { uid: 23, blockName: 'core/heading' }, + 123: { uid: 123, blockName: 'core/text' }, }, blockOrder: [ 123, 23 ], }, }; expect( getPreviousBlock( state, 23 ) ).to.eql( - { uid: 123, blockType: 'core/text' }, + { uid: 123, blockName: 'core/text' }, ); } ); @@ -548,8 +548,8 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockType: 'core/heading' }, - 123: { uid: 123, blockType: 'core/text' }, + 23: { uid: 23, blockName: 'core/heading' }, + 123: { uid: 123, blockName: 'core/text' }, }, blockOrder: [ 123, 23 ], }, @@ -564,15 +564,15 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockType: 'core/heading' }, - 123: { uid: 123, blockType: 'core/text' }, + 23: { uid: 23, blockName: 'core/heading' }, + 123: { uid: 123, blockName: 'core/text' }, }, blockOrder: [ 123, 23 ], }, }; expect( getNextBlock( state, 123 ) ).to.eql( - { uid: 23, blockType: 'core/heading' }, + { uid: 23, blockName: 'core/heading' }, ); } ); @@ -580,8 +580,8 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockType: 'core/heading' }, - 123: { uid: 123, blockType: 'core/text' }, + 23: { uid: 23, blockName: 'core/heading' }, + 123: { uid: 123, blockName: 'core/text' }, }, blockOrder: [ 123, 23 ], }, diff --git a/editor/test/state.js b/editor/test/state.js index 77c9671459c6f7..e2205bcbe377da 100644 --- a/editor/test/state.js +++ b/editor/test/state.js @@ -77,7 +77,7 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -85,7 +85,7 @@ describe( 'state', () => { type: 'INSERT_BLOCK', block: { uid: 'ribs', - blockType: 'core/freeform', + blockName: 'core/freeform', }, } ); @@ -99,7 +99,7 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -108,12 +108,12 @@ describe( 'state', () => { uids: [ 'chicken' ], blocks: [ { uid: 'wings', - blockType: 'core/freeform', + blockName: 'core/freeform', } ], } ); expect( Object.keys( state.blocksByUid ) ).to.have.lengthOf( 1 ); - expect( values( state.blocksByUid )[ 0 ].blockType ).to.equal( 'core/freeform' ); + expect( values( state.blocksByUid )[ 0 ].blockName ).to.equal( 'core/freeform' ); expect( values( state.blocksByUid )[ 0 ].uid ).to.equal( 'wings' ); expect( state.blockOrder ).to.eql( [ 'wings' ] ); } ); @@ -123,11 +123,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -144,15 +144,15 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'veggies', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -169,11 +169,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -190,11 +190,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -211,15 +211,15 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'veggies', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -236,11 +236,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -257,11 +257,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -274,7 +274,7 @@ describe( 'state', () => { expect( state.blocksByUid ).to.eql( { ribs: { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, } ); @@ -285,15 +285,15 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'veggies', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -306,7 +306,7 @@ describe( 'state', () => { expect( state.blocksByUid ).to.eql( { ribs: { uid: 'ribs', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, } ); @@ -317,11 +317,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'kumquat', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, }, { uid: 'loquat', - blockType: 'core/test-block', + blockName: 'core/test-block', attributes: {}, } ], } ); @@ -331,7 +331,7 @@ describe( 'state', () => { after: 'kumquat', block: { uid: 'persimmon', - blockType: 'core/freeform', + blockName: 'core/freeform', }, } ); @@ -539,7 +539,7 @@ describe( 'state', () => { uids: [ 'chicken' ], blocks: [ { uid: 'wings', - blockType: 'core/freeform', + blockName: 'core/freeform', } ], } ); @@ -552,7 +552,7 @@ describe( 'state', () => { uids: [ 'ribs' ], blocks: [ { uid: 'wings', - blockType: 'core/freeform', + blockName: 'core/freeform', } ], } ); @@ -657,7 +657,7 @@ describe( 'state', () => { type: 'INSERT_BLOCK', block: { uid: 'ribs', - blockType: 'core/freeform', + blockName: 'core/freeform', }, } ); @@ -739,7 +739,7 @@ describe( 'state', () => { uids: [ 'chicken' ], blocks: [ { uid: 'wings', - blockType: 'core/freeform', + blockName: 'core/freeform', } ], } ); @@ -753,7 +753,7 @@ describe( 'state', () => { uids: [ 'ribs' ], blocks: [ { uid: 'wings', - blockType: 'core/freeform', + blockName: 'core/freeform', } ], } ); From 788743b2166debe6ac4897228cc3a4588db3f97c Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 30 May 2017 21:41:51 -0400 Subject: [PATCH 07/12] Rename (un)registerBlock as (un)registerBlockType --- blocks/README.md | 4 +-- blocks/api/index.js | 4 +-- blocks/api/registration.js | 4 +-- blocks/api/test/factory.js | 46 ++++++++++++++-------------- blocks/api/test/parser.js | 26 ++++++++-------- blocks/api/test/registration.js | 38 +++++++++++------------ blocks/api/test/serializer.js | 6 ++-- blocks/index.js | 2 +- blocks/library/button/index.js | 4 +-- blocks/library/code/index.js | 4 +-- blocks/library/embed/index.js | 4 +-- blocks/library/freeform/index.js | 4 +-- blocks/library/heading/index.js | 4 +-- blocks/library/image/index.js | 4 +-- blocks/library/list/index.js | 4 +-- blocks/library/preformatted/index.js | 4 +-- blocks/library/pullquote/index.js | 4 +-- blocks/library/quote/index.js | 4 +-- blocks/library/separator/index.js | 4 +-- blocks/library/table/index.js | 4 +-- blocks/library/text/index.js | 4 +-- editor/test/effects.js | 16 +++++----- editor/test/state.js | 4 +-- 23 files changed, 101 insertions(+), 101 deletions(-) diff --git a/blocks/README.md b/blocks/README.md index 30ba31903bb109..89d3529a8747ea 100644 --- a/blocks/README.md +++ b/blocks/README.md @@ -58,7 +58,7 @@ function RandomImage( props ) { } ); } -wp.blocks.registerBlock( 'myplugin/random-image', { +wp.blocks.registerBlockType( 'myplugin/random-image', { title: 'Random Image', icon: 'format-image', @@ -121,7 +121,7 @@ In the random image block above, we've given the `alt` attribute of the image a ## API -### `wp.blocks.registerBlock( slug: string, settings: Object )` +### `wp.blocks.registerBlockType( slug: string, settings: Object )` Registers a new block provided a unique slug and an object defining its behavior. Once registered, the block is made available as an option to any editor interface where blocks are implemented. diff --git a/blocks/api/index.js b/blocks/api/index.js index 62fea244958bbe..d6a5dae4f004a0 100644 --- a/blocks/api/index.js +++ b/blocks/api/index.js @@ -9,8 +9,8 @@ export { default as parse } from './parser'; export { default as serialize } from './serializer'; export { getCategories } from './categories'; export { - registerBlock, - unregisterBlock, + registerBlockType, + unregisterBlockType, setUnknownTypeHandler, getUnknownTypeHandler, getBlockType, diff --git a/blocks/api/registration.js b/blocks/api/registration.js index 77fc7217f64e90..275bcb872a9546 100644 --- a/blocks/api/registration.js +++ b/blocks/api/registration.js @@ -24,7 +24,7 @@ let unknownTypeHandler; * @return {?WPBlock} The block, if it has been successfully * registered; otherwise `undefined`. */ -export function registerBlock( slug, settings ) { +export function registerBlockType( slug, settings ) { if ( typeof slug !== 'string' ) { console.error( 'Block slugs must be strings.' @@ -55,7 +55,7 @@ export function registerBlock( slug, settings ) { * @return {?WPBlock} The previous block value, if it has been * successfully unregistered; otherwise `undefined`. */ -export function unregisterBlock( slug ) { +export function unregisterBlockType( slug ) { if ( ! blocks[ slug ] ) { console.error( 'Block "' + slug + '" is not registered.' diff --git a/blocks/api/test/factory.js b/blocks/api/test/factory.js index 124ebf19f49307..f2aa4971e68ce0 100644 --- a/blocks/api/test/factory.js +++ b/blocks/api/test/factory.js @@ -7,19 +7,19 @@ import { expect } from 'chai'; * Internal dependencies */ import { createBlock, switchToBlockType } from '../factory'; -import { getBlockTypes, unregisterBlock, setUnknownTypeHandler, registerBlock } from '../registration'; +import { getBlockTypes, unregisterBlockType, setUnknownTypeHandler, registerBlockType } from '../registration'; describe( 'block factory', () => { afterEach( () => { setUnknownTypeHandler( undefined ); getBlockTypes().forEach( ( block ) => { - unregisterBlock( block.slug ); + unregisterBlockType( block.slug ); } ); } ); describe( 'createBlock()', () => { it( 'should create a block given its blockType and attributes', () => { - registerBlock( 'core/test-block', { + registerBlockType( 'core/test-block', { defaultAttributes: { includesDefault: true, }, @@ -39,7 +39,7 @@ describe( 'block factory', () => { describe( 'switchToBlockType()', () => { it( 'should switch the blockType of a block using the "transform form"', () => { - registerBlock( 'core/updated-text-block', { + registerBlockType( 'core/updated-text-block', { transforms: { from: [ { blocks: [ 'core/text-block' ], @@ -51,7 +51,7 @@ describe( 'block factory', () => { } ], }, } ); - registerBlock( 'core/text-block', {} ); + registerBlockType( 'core/text-block', {} ); const block = { uid: 1, @@ -73,8 +73,8 @@ describe( 'block factory', () => { } ); it( 'should switch the blockType of a block using the "transform to"', () => { - registerBlock( 'core/updated-text-block', {} ); - registerBlock( 'core/text-block', { + registerBlockType( 'core/updated-text-block', {} ); + registerBlockType( 'core/text-block', { transforms: { to: [ { blocks: [ 'core/updated-text-block' ], @@ -107,8 +107,8 @@ describe( 'block factory', () => { } ); it( 'should return null if no transformation is found', () => { - registerBlock( 'core/updated-text-block', {} ); - registerBlock( 'core/text-block', {} ); + registerBlockType( 'core/updated-text-block', {} ); + registerBlockType( 'core/text-block', {} ); const block = { uid: 1, @@ -124,7 +124,7 @@ describe( 'block factory', () => { } ); it( 'should reject transformations that return null', () => { - registerBlock( 'core/updated-text-block', { + registerBlockType( 'core/updated-text-block', { transforms: { from: [ { blocks: [ 'core/text-block' ], @@ -132,7 +132,7 @@ describe( 'block factory', () => { } ], }, } ); - registerBlock( 'core/text-block', {} ); + registerBlockType( 'core/text-block', {} ); const block = { uid: 1, @@ -148,7 +148,7 @@ describe( 'block factory', () => { } ); it( 'should reject transformations that return an empty array', () => { - registerBlock( 'core/updated-text-block', { + registerBlockType( 'core/updated-text-block', { transforms: { from: [ { blocks: [ 'core/text-block' ], @@ -156,7 +156,7 @@ describe( 'block factory', () => { } ], }, } ); - registerBlock( 'core/text-block', {} ); + registerBlockType( 'core/text-block', {} ); const block = { uid: 1, @@ -172,7 +172,7 @@ describe( 'block factory', () => { } ); it( 'should reject single transformations that do not include block types', () => { - registerBlock( 'core/updated-text-block', { + registerBlockType( 'core/updated-text-block', { transforms: { from: [ { blocks: [ 'core/text-block' ], @@ -186,7 +186,7 @@ describe( 'block factory', () => { } ], }, } ); - registerBlock( 'core/text-block', {} ); + registerBlockType( 'core/text-block', {} ); const block = { uid: 1, @@ -202,7 +202,7 @@ describe( 'block factory', () => { } ); it( 'should reject array transformations that do not include block types', () => { - registerBlock( 'core/updated-text-block', { + registerBlockType( 'core/updated-text-block', { transforms: { from: [ { blocks: [ 'core/text-block' ], @@ -221,7 +221,7 @@ describe( 'block factory', () => { } ], }, } ); - registerBlock( 'core/text-block', {} ); + registerBlockType( 'core/text-block', {} ); const block = { uid: 1, @@ -237,8 +237,8 @@ describe( 'block factory', () => { } ); it( 'should reject single transformations with unexpected block types', () => { - registerBlock( 'core/updated-text-block', {} ); - registerBlock( 'core/text-block', { + registerBlockType( 'core/updated-text-block', {} ); + registerBlockType( 'core/text-block', { transforms: { to: [ { blocks: [ 'core/updated-text-block' ], @@ -265,8 +265,8 @@ describe( 'block factory', () => { } ); it( 'should reject array transformations with unexpected block types', () => { - registerBlock( 'core/updated-text-block', {} ); - registerBlock( 'core/text-block', { + registerBlockType( 'core/updated-text-block', {} ); + registerBlockType( 'core/text-block', { transforms: { to: [ { blocks: [ 'core/updated-text-block' ], @@ -298,8 +298,8 @@ describe( 'block factory', () => { } ); it( 'should accept valid array transformations', () => { - registerBlock( 'core/updated-text-block', {} ); - registerBlock( 'core/text-block', { + registerBlockType( 'core/updated-text-block', {} ); + registerBlockType( 'core/text-block', { transforms: { to: [ { blocks: [ 'core/updated-text-block' ], diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index e38030545a3470..d94bac7cfd91af 100644 --- a/blocks/api/test/parser.js +++ b/blocks/api/test/parser.js @@ -15,8 +15,8 @@ import { parseWithTinyMCE, } from '../parser'; import { - registerBlock, - unregisterBlock, + registerBlockType, + unregisterBlockType, getBlockTypes, setUnknownTypeHandler, } from '../registration'; @@ -25,7 +25,7 @@ describe( 'block parser', () => { afterEach( () => { setUnknownTypeHandler( undefined ); getBlockTypes().forEach( ( block ) => { - unregisterBlock( block.slug ); + unregisterBlockType( block.slug ); } ); } ); @@ -93,7 +93,7 @@ describe( 'block parser', () => { describe( 'createBlockWithFallback', () => { it( 'should create the requested block if it exists', () => { - registerBlock( 'core/test-block', {} ); + registerBlockType( 'core/test-block', {} ); const block = createBlockWithFallback( 'core/test-block', @@ -105,7 +105,7 @@ describe( 'block parser', () => { } ); it( 'should create the requested block with no attributes if it exists', () => { - registerBlock( 'core/test-block', {} ); + registerBlockType( 'core/test-block', {} ); const block = createBlockWithFallback( 'core/test-block', 'content' ); expect( block.blockName ).to.eql( 'core/test-block' ); @@ -113,7 +113,7 @@ describe( 'block parser', () => { } ); it( 'should fall back to the unknown type handler for unknown blocks if present', () => { - registerBlock( 'core/unknown-block', {} ); + registerBlockType( 'core/unknown-block', {} ); setUnknownTypeHandler( 'core/unknown-block' ); const block = createBlockWithFallback( @@ -126,7 +126,7 @@ describe( 'block parser', () => { } ); it( 'should fall back to the unknown type handler if block type not specified', () => { - registerBlock( 'core/unknown-block', {} ); + registerBlockType( 'core/unknown-block', {} ); setUnknownTypeHandler( 'core/unknown-block' ); const block = createBlockWithFallback( null, 'content' ); @@ -146,7 +146,7 @@ describe( 'block parser', () => { const parse = parsers[ parser ]; describe( parser, () => { it( 'should parse the post content, including block attributes', () => { - registerBlock( 'core/test-block', { + registerBlockType( 'core/test-block', { // Currently this is the only way to test block content parsing? attributes: function( rawContent ) { return { @@ -180,7 +180,7 @@ describe( 'block parser', () => { } ); it( 'should parse the post content, ignoring unknown blocks', () => { - registerBlock( 'core/test-block', { + registerBlockType( 'core/test-block', { attributes: function( rawContent ) { return { content: rawContent + ' & Chicken', @@ -203,8 +203,8 @@ describe( 'block parser', () => { } ); it( 'should parse the post content, using unknown block handler', () => { - registerBlock( 'core/test-block', {} ); - registerBlock( 'core/unknown-block', {} ); + registerBlockType( 'core/test-block', {} ); + registerBlockType( 'core/unknown-block', {} ); setUnknownTypeHandler( 'core/unknown-block' ); @@ -223,8 +223,8 @@ describe( 'block parser', () => { } ); it( 'should parse the post content, including raw HTML at each end', () => { - registerBlock( 'core/test-block', {} ); - registerBlock( 'core/unknown-block', { + registerBlockType( 'core/test-block', {} ); + registerBlockType( 'core/unknown-block', { // Currently this is the only way to test block content parsing? attributes: function( rawContent ) { return { diff --git a/blocks/api/test/registration.js b/blocks/api/test/registration.js index aa1af55146b845..b7aaf1a07226ce 100644 --- a/blocks/api/test/registration.js +++ b/blocks/api/test/registration.js @@ -10,8 +10,8 @@ import sinon from 'sinon'; * Internal dependencies */ import { - registerBlock, - unregisterBlock, + registerBlockType, + unregisterBlockType, setUnknownTypeHandler, getUnknownTypeHandler, getBlockType, @@ -26,47 +26,47 @@ describe( 'blocks', () => { afterEach( () => { getBlockTypes().forEach( block => { - unregisterBlock( block.slug ); + unregisterBlockType( block.slug ); } ); setUnknownTypeHandler( undefined ); console.error.restore(); } ); - describe( 'registerBlock()', () => { + describe( 'registerBlockType()', () => { it( 'should reject numbers', () => { - const block = registerBlock( 999 ); + const block = registerBlockType( 999 ); expect( console.error ).to.have.been.calledWith( 'Block slugs must be strings.' ); expect( block ).to.be.undefined(); } ); it( 'should reject blocks without a namespace', () => { - const block = registerBlock( 'doing-it-wrong' ); + const block = registerBlockType( 'doing-it-wrong' ); expect( console.error ).to.have.been.calledWith( 'Block slugs must contain a namespace prefix. Example: my-plugin/my-custom-block' ); expect( block ).to.be.undefined(); } ); it( 'should reject blocks with invalid characters', () => { - const block = registerBlock( 'still/_doing_it_wrong' ); + const block = registerBlockType( 'still/_doing_it_wrong' ); expect( console.error ).to.have.been.calledWith( 'Block slugs must contain a namespace prefix. Example: my-plugin/my-custom-block' ); expect( block ).to.be.undefined(); } ); it( 'should accept valid block names', () => { - const block = registerBlock( 'my-plugin/fancy-block-4' ); + const block = registerBlockType( 'my-plugin/fancy-block-4' ); expect( console.error ).to.not.have.been.called(); expect( block ).to.eql( { slug: 'my-plugin/fancy-block-4' } ); } ); it( 'should prohibit registering the same block twice', () => { - registerBlock( 'core/test-block' ); - const block = registerBlock( 'core/test-block' ); + registerBlockType( 'core/test-block' ); + const block = registerBlockType( 'core/test-block' ); expect( console.error ).to.have.been.calledWith( 'Block "core/test-block" is already registered.' ); expect( block ).to.be.undefined(); } ); it( 'should store a copy of block type', () => { const blockType = { settingName: 'settingValue' }; - registerBlock( 'core/test-block-with-settings', blockType ); + registerBlockType( 'core/test-block-with-settings', blockType ); blockType.mutated = true; expect( getBlockType( 'core/test-block-with-settings' ) ).to.eql( { slug: 'core/test-block-with-settings', @@ -75,19 +75,19 @@ describe( 'blocks', () => { } ); } ); - describe( 'unregisterBlock()', () => { + describe( 'unregisterBlockType()', () => { it( 'should fail if a block is not registered', () => { - const oldBlock = unregisterBlock( 'core/test-block' ); + const oldBlock = unregisterBlockType( 'core/test-block' ); expect( console.error ).to.have.been.calledWith( 'Block "core/test-block" is not registered.' ); expect( oldBlock ).to.be.undefined(); } ); it( 'should unregister existing blocks', () => { - registerBlock( 'core/test-block' ); + registerBlockType( 'core/test-block' ); expect( getBlockTypes() ).to.eql( [ { slug: 'core/test-block' }, ] ); - const oldBlock = unregisterBlock( 'core/test-block' ); + const oldBlock = unregisterBlockType( 'core/test-block' ); expect( console.error ).to.not.have.been.called(); expect( oldBlock ).to.eql( { slug: 'core/test-block' } ); expect( getBlockTypes() ).to.eql( [] ); @@ -110,7 +110,7 @@ describe( 'blocks', () => { describe( 'getBlockType()', () => { it( 'should return { slug } for blocks with no settings', () => { - registerBlock( 'core/test-block' ); + registerBlockType( 'core/test-block' ); expect( getBlockType( 'core/test-block' ) ).to.eql( { slug: 'core/test-block', } ); @@ -118,7 +118,7 @@ describe( 'blocks', () => { it( 'should return all block type elements', () => { const blockType = { settingName: 'settingValue' }; - registerBlock( 'core/test-block-with-settings', blockType ); + registerBlockType( 'core/test-block-with-settings', blockType ); expect( getBlockType( 'core/test-block-with-settings' ) ).to.eql( { slug: 'core/test-block-with-settings', settingName: 'settingValue', @@ -132,9 +132,9 @@ describe( 'blocks', () => { } ); it( 'should return all registered blocks', () => { - registerBlock( 'core/test-block' ); + registerBlockType( 'core/test-block' ); const blockType = { settingName: 'settingValue' }; - registerBlock( 'core/test-block-with-settings', blockType ); + registerBlockType( 'core/test-block-with-settings', blockType ); expect( getBlockTypes() ).to.eql( [ { slug: 'core/test-block' }, { slug: 'core/test-block-with-settings', settingName: 'settingValue' }, diff --git a/blocks/api/test/serializer.js b/blocks/api/test/serializer.js index 4503db188131a5..0e0d8b4d658147 100644 --- a/blocks/api/test/serializer.js +++ b/blocks/api/test/serializer.js @@ -7,12 +7,12 @@ import { expect } from 'chai'; * Internal dependencies */ import serialize, { getCommentAttributes, getSaveContent } from '../serializer'; -import { getBlockTypes, registerBlock, unregisterBlock } from '../registration'; +import { getBlockTypes, registerBlockType, unregisterBlockType } from '../registration'; describe( 'block serializer', () => { afterEach( () => { getBlockTypes().forEach( block => { - unregisterBlock( block.slug ); + unregisterBlockType( block.slug ); } ); } ); @@ -99,7 +99,7 @@ describe( 'block serializer', () => { return

    ; }, }; - registerBlock( 'core/test-block', blockSettings ); + registerBlockType( 'core/test-block', blockSettings ); const blockList = [ { blockName: 'core/test-block', diff --git a/blocks/index.js b/blocks/index.js index ebfb61ffa0a6b4..5b40f139bc29b9 100644 --- a/blocks/index.js +++ b/blocks/index.js @@ -7,7 +7,7 @@ import './library'; // when composed together, form the content or layout of a page. // The API for blocks is exposed via `wp.blocks`. // -// Supported blocks are registered by calling `registerBlock`. Once registered, +// Supported blocks are registered by calling `registerBlockType`. Once registered, // the block is made available as an option to the editor interface. // // Blocks are inferred from the HTML source of a post through a parsing mechanism diff --git a/blocks/library/button/index.js b/blocks/library/button/index.js index 8b94c237701e4b..f391e6d9634512 100644 --- a/blocks/library/button/index.js +++ b/blocks/library/button/index.js @@ -7,7 +7,7 @@ import { IconButton } from 'components'; * Internal dependencies */ import './style.scss'; -import { registerBlock, query } from '../../api'; +import { registerBlockType, query } from '../../api'; import Editable from '../../editable'; const { attr, children } = query; @@ -26,7 +26,7 @@ function applyOrUnset( align ) { }; } -registerBlock( 'core/button', { +registerBlockType( 'core/button', { title: wp.i18n.__( 'Button' ), icon: 'button', diff --git a/blocks/library/code/index.js b/blocks/library/code/index.js index 1f7f60e049f72e..6b513072d5f34b 100644 --- a/blocks/library/code/index.js +++ b/blocks/library/code/index.js @@ -7,11 +7,11 @@ import TextareaAutosize from 'react-autosize-textarea'; * Internal dependencies */ import './style.scss'; -import { registerBlock, query } from '../../api'; +import { registerBlockType, query } from '../../api'; const { prop } = query; -registerBlock( 'core/code', { +registerBlockType( 'core/code', { title: wp.i18n.__( 'Code' ), icon: 'editor-code', diff --git a/blocks/library/embed/index.js b/blocks/library/embed/index.js index 8fcbb551151bef..53f1a49c5de1b3 100644 --- a/blocks/library/embed/index.js +++ b/blocks/library/embed/index.js @@ -7,7 +7,7 @@ import { Button, Placeholder } from 'components'; * Internal dependencies */ import './style.scss'; -import { registerBlock, query } from '../../api'; +import { registerBlockType, query } from '../../api'; import Editable from '../../editable'; const { attr, children } = query; @@ -26,7 +26,7 @@ function toggleAlignment( align ) { }; } -registerBlock( 'core/embed', { +registerBlockType( 'core/embed', { title: wp.i18n.__( 'Embed' ), icon: 'video-alt3', diff --git a/blocks/library/freeform/index.js b/blocks/library/freeform/index.js index ade728732b96f7..16d9da5abde913 100644 --- a/blocks/library/freeform/index.js +++ b/blocks/library/freeform/index.js @@ -1,11 +1,11 @@ /** * Internal dependencies */ -import { registerBlock, query, setUnknownTypeHandler } from '../../api'; +import { registerBlockType, query, setUnknownTypeHandler } from '../../api'; const { html } = query; -registerBlock( 'core/freeform', { +registerBlockType( 'core/freeform', { title: wp.i18n.__( 'Freeform' ), icon: 'text', diff --git a/blocks/library/heading/index.js b/blocks/library/heading/index.js index 069e273c63bf6a..1b114e5de65fda 100644 --- a/blocks/library/heading/index.js +++ b/blocks/library/heading/index.js @@ -7,13 +7,13 @@ import { isString } from 'lodash'; * Internal dependencies */ import './style.scss'; -import { registerBlock, createBlock, query } from '../../api'; +import { registerBlockType, createBlock, query } from '../../api'; import Editable from '../../editable'; import BlockControls from '../../block-controls'; const { children, prop } = query; -registerBlock( 'core/heading', { +registerBlockType( 'core/heading', { title: wp.i18n.__( 'Heading' ), icon: 'heading', diff --git a/blocks/library/image/index.js b/blocks/library/image/index.js index 36a49e169eb5f7..2b7d06ab90810a 100644 --- a/blocks/library/image/index.js +++ b/blocks/library/image/index.js @@ -7,7 +7,7 @@ import { Placeholder } from 'components'; * Internal dependencies */ import './style.scss'; -import { registerBlock, query } from '../../api'; +import { registerBlockType, query } from '../../api'; import Editable from '../../editable'; import MediaUploadButton from '../../media-upload-button'; @@ -27,7 +27,7 @@ function toggleAlignment( align ) { }; } -registerBlock( 'core/image', { +registerBlockType( 'core/image', { title: wp.i18n.__( 'Image' ), icon: 'format-image', diff --git a/blocks/library/list/index.js b/blocks/library/list/index.js index 46b0acf18d812e..80bec7d99f42c5 100644 --- a/blocks/library/list/index.js +++ b/blocks/library/list/index.js @@ -8,7 +8,7 @@ import { find } from 'lodash'; * Internal dependencies */ import './style.scss'; -import { registerBlock, query as hpq, createBlock } from '../../api'; +import { registerBlockType, query as hpq, createBlock } from '../../api'; import Editable from '../../editable'; const { children, prop } = hpq; @@ -47,7 +47,7 @@ function findInternalListType( { parents } ) { return list ? list.nodeName : null; } -registerBlock( 'core/list', { +registerBlockType( 'core/list', { title: wp.i18n.__( 'List' ), icon: 'editor-ul', category: 'common', diff --git a/blocks/library/preformatted/index.js b/blocks/library/preformatted/index.js index 2514d3c1604383..354ec63e683b61 100644 --- a/blocks/library/preformatted/index.js +++ b/blocks/library/preformatted/index.js @@ -2,12 +2,12 @@ * Internal dependencies */ import './style.scss'; -import { registerBlock, createBlock, query } from '../../api'; +import { registerBlockType, createBlock, query } from '../../api'; import Editable from '../../editable'; const { children } = query; -registerBlock( 'core/preformatted', { +registerBlockType( 'core/preformatted', { title: wp.i18n.__( 'Preformatted' ), icon: 'text', diff --git a/blocks/library/pullquote/index.js b/blocks/library/pullquote/index.js index f958dedce9865e..f87efe2764a4fb 100644 --- a/blocks/library/pullquote/index.js +++ b/blocks/library/pullquote/index.js @@ -2,12 +2,12 @@ * Internal dependencies */ import './style.scss'; -import { registerBlock, query as hpq } from '../../api'; +import { registerBlockType, query as hpq } from '../../api'; import Editable from '../../editable'; const { children, query } = hpq; -registerBlock( 'core/pullquote', { +registerBlockType( 'core/pullquote', { title: wp.i18n.__( 'Pullquote' ), diff --git a/blocks/library/quote/index.js b/blocks/library/quote/index.js index dd589ac3e69ee8..e75a009503d7f2 100644 --- a/blocks/library/quote/index.js +++ b/blocks/library/quote/index.js @@ -7,12 +7,12 @@ import { switchChildrenNodeName } from 'element'; * Internal dependencies */ import './style.scss'; -import { registerBlock, createBlock, query as hpq } from '../../api'; +import { registerBlockType, createBlock, query as hpq } from '../../api'; import Editable from '../../editable'; const { children, query } = hpq; -registerBlock( 'core/quote', { +registerBlockType( 'core/quote', { title: wp.i18n.__( 'Quote' ), icon: 'format-quote', category: 'common', diff --git a/blocks/library/separator/index.js b/blocks/library/separator/index.js index 55c88d81c32b9d..aa54c61eac3d3d 100644 --- a/blocks/library/separator/index.js +++ b/blocks/library/separator/index.js @@ -2,9 +2,9 @@ * Internal dependencies */ import './style.scss'; -import { registerBlock } from '../../api'; +import { registerBlockType } from '../../api'; -registerBlock( 'core/separator', { +registerBlockType( 'core/separator', { title: wp.i18n.__( 'Separator' ), icon: 'minus', diff --git a/blocks/library/table/index.js b/blocks/library/table/index.js index c24604676a91c3..b14e101eeb47dd 100644 --- a/blocks/library/table/index.js +++ b/blocks/library/table/index.js @@ -2,7 +2,7 @@ * Internal dependencies */ import './style.scss'; -import { registerBlock, query as hpq } from '../../api'; +import { registerBlockType, query as hpq } from '../../api'; import Editable from '../../editable'; const { children, query } = hpq; @@ -21,7 +21,7 @@ function toggleAlignment( align ) { }; } -registerBlock( 'core/table', { +registerBlockType( 'core/table', { title: wp.i18n.__( 'Table' ), icon: 'editor-table', category: 'formatting', diff --git a/blocks/library/text/index.js b/blocks/library/text/index.js index af23cb5df122f1..e98587fabb174c 100644 --- a/blocks/library/text/index.js +++ b/blocks/library/text/index.js @@ -1,12 +1,12 @@ /** * Internal dependencies */ -import { registerBlock, createBlock, query } from '../../api'; +import { registerBlockType, createBlock, query } from '../../api'; import Editable from '../../editable'; const { children } = query; -registerBlock( 'core/text', { +registerBlockType( 'core/text', { title: wp.i18n.__( 'Text' ), icon: 'text', diff --git a/editor/test/effects.js b/editor/test/effects.js index 5b3a6b91df8ea8..5493a3a7bd5bdd 100644 --- a/editor/test/effects.js +++ b/editor/test/effects.js @@ -7,7 +7,7 @@ import sinon from 'sinon'; /** * WordPress dependencies */ -import { getBlockTypes, unregisterBlock, registerBlock, createBlock } from 'blocks'; +import { getBlockTypes, unregisterBlockType, registerBlockType, createBlock } from 'blocks'; /** * Internal dependencies @@ -21,12 +21,12 @@ describe( 'effects', () => { afterEach( () => { getBlockTypes().forEach( ( block ) => { - unregisterBlock( block.slug ); + unregisterBlockType( block.slug ); } ); } ); it( 'should only focus the blockA if the blockA has no merge function', () => { - registerBlock( 'core/test-block', {} ); + registerBlockType( 'core/test-block', {} ); const blockA = { uid: 'chicken', blockName: 'core/test-block', @@ -43,7 +43,7 @@ describe( 'effects', () => { } ); it( 'should merge the blocks if blocks of the same type', () => { - registerBlock( 'core/test-block', { + registerBlockType( 'core/test-block', { merge( attributes, attributesToMerge ) { return { content: attributes.content + ' ' + attributesToMerge.content, @@ -73,14 +73,14 @@ describe( 'effects', () => { } ); it( 'should not merge the blocks have different types without transformation', () => { - registerBlock( 'core/test-block', { + registerBlockType( 'core/test-block', { merge( attributes, attributesToMerge ) { return { content: attributes.content + ' ' + attributesToMerge.content, }; }, } ); - registerBlock( 'core/test-block-2', {} ); + registerBlockType( 'core/test-block-2', {} ); const blockA = { uid: 'chicken', blockName: 'core/test-block', @@ -98,14 +98,14 @@ describe( 'effects', () => { } ); it( 'should transform and merge the blocks', () => { - registerBlock( 'core/test-block', { + registerBlockType( 'core/test-block', { merge( attributes, attributesToMerge ) { return { content: attributes.content + ' ' + attributesToMerge.content, }; }, } ); - registerBlock( 'core/test-block-2', { + registerBlockType( 'core/test-block-2', { transforms: { to: [ { type: 'blocks', diff --git a/editor/test/state.js b/editor/test/state.js index e2205bcbe377da..bf1a0623c7f6cb 100644 --- a/editor/test/state.js +++ b/editor/test/state.js @@ -24,11 +24,11 @@ import { describe( 'state', () => { describe( 'editor()', () => { before( () => { - wp.blocks.registerBlock( 'core/test-block', {} ); + wp.blocks.registerBlockType( 'core/test-block', {} ); } ); after( () => { - wp.blocks.unregisterBlock( 'core/test-block' ); + wp.blocks.unregisterBlockType( 'core/test-block' ); } ); it( 'should return empty blocksByUid, blockOrder, history by default', () => { From 905ebaa5e8a71792a59cc19c84125b11b453b9dc Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 30 May 2017 21:52:41 -0400 Subject: [PATCH 08/12] Convert more blockSettings to blockType --- blocks/api/factory.js | 8 ++++---- blocks/api/parser.js | 6 +++--- blocks/api/test/parser.js | 16 ++++++++-------- blocks/api/test/serializer.js | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/blocks/api/factory.js b/blocks/api/factory.js index b6985026c8723b..22d5e60d89f8f2 100644 --- a/blocks/api/factory.js +++ b/blocks/api/factory.js @@ -48,10 +48,10 @@ export function createBlock( blockName, attributes = {} ) { export function switchToBlockType( block, blockName ) { // Find the right transformation by giving priority to the "to" // transformation. - const destinationSettings = getBlockType( blockName ); - const sourceSettings = getBlockType( block.blockName ); - const transformationsFrom = get( destinationSettings, 'transforms.from', [] ); - const transformationsTo = get( sourceSettings, 'transforms.to', [] ); + const destinationType = getBlockType( blockName ); + const sourceType = getBlockType( block.blockName ); + const transformationsFrom = get( destinationType, 'transforms.from', [] ); + const transformationsTo = get( sourceType, 'transforms.to', [] ); const transformation = find( transformationsTo, t => t.blocks.indexOf( blockName ) !== -1 ) || find( transformationsFrom, t => t.blocks.indexOf( block.blockName ) !== -1 ); diff --git a/blocks/api/parser.js b/blocks/api/parser.js index dceb42d74c43dc..5457754a096567 100644 --- a/blocks/api/parser.js +++ b/blocks/api/parser.js @@ -39,7 +39,7 @@ export function parseBlockAttributes( rawContent, blockType ) { } /** - * Returns the block attributes of a registered block node given its settings. + * Returns the block attributes of a registered block node given its type. * * @param {?Object} blockType Block type * @param {string} rawContent Raw block content @@ -73,7 +73,7 @@ export function createBlockWithFallback( name, rawContent, attributes ) { // Use type from block content, otherwise find unknown handler. name = name || getUnknownTypeHandler(); - // Try finding settings for known block name, else fall back again. + // Try finding type for known block name, else fall back again. let blockType = getBlockType( name ); const fallbackBlock = getUnknownTypeHandler(); if ( ! blockType ) { @@ -81,7 +81,7 @@ export function createBlockWithFallback( name, rawContent, attributes ) { blockType = getBlockType( name ); } - // Include in set only if settings were determined. + // Include in set only if type were determined. // TODO do we ever expect there to not be an unknown type handler? if ( blockType && ( rawContent.trim() || name !== fallbackBlock ) ) { // TODO allow blocks to opt-in to receiving a tree instead of a string. diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index d94bac7cfd91af..2ca9a0747276a5 100644 --- a/blocks/api/test/parser.js +++ b/blocks/api/test/parser.js @@ -31,7 +31,7 @@ describe( 'block parser', () => { describe( 'parseBlockAttributes()', () => { it( 'should use the function implementation', () => { - const blockSettings = { + const blockType = { attributes: function( rawContent ) { return { content: rawContent + ' & Chicken', @@ -39,13 +39,13 @@ describe( 'block parser', () => { }, }; - expect( parseBlockAttributes( 'Ribs', blockSettings ) ).to.eql( { + expect( parseBlockAttributes( 'Ribs', blockType ) ).to.eql( { content: 'Ribs & Chicken', } ); } ); it( 'should use the query object implementation', () => { - const blockSettings = { + const blockType = { attributes: { emphasis: text( 'strong' ), ignoredDomMatcher: ( node ) => node.innerHTML, @@ -54,22 +54,22 @@ describe( 'block parser', () => { const rawContent = 'Ribs & Chicken'; - expect( parseBlockAttributes( rawContent, blockSettings ) ).to.eql( { + expect( parseBlockAttributes( rawContent, blockType ) ).to.eql( { emphasis: '& Chicken', } ); } ); it( 'should return an empty object if no attributes defined', () => { - const blockSettings = {}; + const blockType = {}; const rawContent = 'Ribs & Chicken'; - expect( parseBlockAttributes( rawContent, blockSettings ) ).to.eql( {} ); + expect( parseBlockAttributes( rawContent, blockType ) ).to.eql( {} ); } ); } ); describe( 'getBlockAttributes()', () => { it( 'should merge attributes with the parsed and default attributes', () => { - const blockSettings = { + const blockType = { attributes: function( rawContent ) { return { content: rawContent + ' & Chicken', @@ -83,7 +83,7 @@ describe( 'block parser', () => { const rawContent = 'Ribs'; const attrs = { align: 'left' }; - expect( getBlockAttributes( blockSettings, rawContent, attrs ) ).to.eql( { + expect( getBlockAttributes( blockType, rawContent, attrs ) ).to.eql( { align: 'left', topic: 'none', content: 'Ribs & Chicken', diff --git a/blocks/api/test/serializer.js b/blocks/api/test/serializer.js index 0e0d8b4d658147..bb66c7f43d8d56 100644 --- a/blocks/api/test/serializer.js +++ b/blocks/api/test/serializer.js @@ -89,7 +89,7 @@ describe( 'block serializer', () => { describe( 'serialize()', () => { it( 'should serialize the post content properly', () => { - const blockSettings = { + const blockType = { attributes: ( rawContent ) => { return { content: rawContent, @@ -99,7 +99,7 @@ describe( 'block serializer', () => { return

    ; }, }; - registerBlockType( 'core/test-block', blockSettings ); + registerBlockType( 'core/test-block', blockType ); const blockList = [ { blockName: 'core/test-block', From b2ad98bab63fb8d2ca26d2738d24f93b0a140558 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 30 May 2017 21:53:51 -0400 Subject: [PATCH 09/12] Rename PHP register_block to register_block_type --- index.php | 4 +-- phpunit/class-dynamic-blocks-render-test.php | 4 +-- phpunit/class-registration-test.php | 36 ++++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/index.php b/index.php index fcca4adf570a3b..d52795dc9cb464 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ function gutenberg_menu() { * @return array The block, if it has been successfully registered. */ -function register_block( $slug, $settings ) { +function register_block_type( $slug, $settings ) { global $wp_registered_blocks; if ( ! is_string( $slug ) ) { @@ -74,7 +74,7 @@ function register_block( $slug, $settings ) { * @return array The previous block value, if it has been * successfully unregistered; otherwise `null`. */ -function unregister_block( $slug ) { +function unregister_block_type( $slug ) { global $wp_registered_blocks; if ( ! isset( $wp_registered_blocks[ $slug ] ) ) { /* translators: 1: block slug */ diff --git a/phpunit/class-dynamic-blocks-render-test.php b/phpunit/class-dynamic-blocks-render-test.php index f04c5fbe9c81d2..60b6de3d729e61 100644 --- a/phpunit/class-dynamic-blocks-render-test.php +++ b/phpunit/class-dynamic-blocks-render-test.php @@ -31,7 +31,7 @@ function test_dynamic_block_rendering() { 'render_dummy_block', ), ); - register_block( 'core/dummy', $settings ); + register_block_type( 'core/dummy', $settings ); $post_content = 'before' . '' . @@ -56,7 +56,7 @@ function test_dynamic_block_rendering_with_content() { 'render_dummy_block', ), ); - register_block( 'core/dummy', $settings ); + register_block_type( 'core/dummy', $settings ); $post_content = 'before' . 'this should be ignored' . diff --git a/phpunit/class-registration-test.php b/phpunit/class-registration-test.php index f99b06375ec3e3..8aa98a50e1384e 100644 --- a/phpunit/class-registration-test.php +++ b/phpunit/class-registration-test.php @@ -6,7 +6,7 @@ */ /** - * Test register_block + * Test register_block_type */ class Registration_Test extends WP_UnitTestCase { function tearDown() { @@ -16,42 +16,42 @@ function tearDown() { /** * Should reject numbers * - * @expectedIncorrectUsage register_block + * @expectedIncorrectUsage register_block_type */ function test_invalid_non_string_slugs() { - $result = register_block( 1, array() ); + $result = register_block_type( 1, array() ); $this->assertFalse( $result ); } /** * Should reject blocks without a namespace * - * @expectedIncorrectUsage register_block + * @expectedIncorrectUsage register_block_type */ function test_invalid_slugs_without_namespace() { - $result = register_block( 'text', array() ); + $result = register_block_type( 'text', array() ); $this->assertFalse( $result ); } /** * Should reject blocks with invalid characters * - * @expectedIncorrectUsage register_block + * @expectedIncorrectUsage register_block_type */ function test_invlalid_characters() { - $result = register_block( 'still/_doing_it_wrong', array() ); + $result = register_block_type( 'still/_doing_it_wrong', array() ); $this->assertFalse( $result ); } /** * Should accept valid block names */ - function test_register_block() { + function test_register_block_type() { global $wp_registered_blocks; $settings = array( 'icon' => 'text', ); - $updated_settings = register_block( 'core/text', $settings ); + $updated_settings = register_block_type( 'core/text', $settings ); $this->assertEquals( $updated_settings, array( 'icon' => 'text', 'slug' => 'core/text', @@ -62,38 +62,38 @@ function test_register_block() { /** * Should fail to re-register the same block * - * @expectedIncorrectUsage register_block + * @expectedIncorrectUsage register_block_type */ - function test_register_block_twice() { + function test_register_block_type_twice() { $settings = array( 'icon' => 'text', ); - $result = register_block( 'core/text', $settings ); + $result = register_block_type( 'core/text', $settings ); $this->assertNotFalse( $result ); - $result = register_block( 'core/text', $settings ); + $result = register_block_type( 'core/text', $settings ); $this->assertFalse( $result ); } /** * Unregistering should fail if a block is not registered * - * @expectedIncorrectUsage unregister_block + * @expectedIncorrectUsage unregister_block_type */ function test_unregister_not_registered_block() { - $result = unregister_block( 'core/unregistered' ); + $result = unregister_block_type( 'core/unregistered' ); $this->assertFalse( $result ); } /** * Should unregister existing blocks */ - function test_unregister_block() { + function test_unregister_block_type() { global $wp_registered_blocks; $settings = array( 'icon' => 'text', ); - register_block( 'core/text', $settings ); - $unregistered_block = unregister_block( 'core/text' ); + register_block_type( 'core/text', $settings ); + $unregistered_block = unregister_block_type( 'core/text' ); $this->assertEquals( $unregistered_block, array( 'icon' => 'text', 'slug' => 'core/text', From ae96acc258eb658de886e2ec0656f6daefedf694 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 30 May 2017 22:08:08 -0400 Subject: [PATCH 10/12] Correct blockType to blockName --- editor/effects.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/editor/effects.js b/editor/effects.js index 237c4ed328a73f..b2cc3a2825104b 100644 --- a/editor/effects.js +++ b/editor/effects.js @@ -71,7 +71,7 @@ export default { MERGE_BLOCKS( action, store ) { const { dispatch } = store; const [ blockA, blockB ] = action.blocks; - const blockType = getBlockType( blockA.blockType ); + const blockType = getBlockType( blockA.blockName ); // Only focus the previous block if it's not mergeable if ( ! blockType.merge ) { @@ -81,9 +81,9 @@ export default { // We can only merge blocks with similar types // thus, we transform the block to merge first - const blocksWithTheSameType = blockA.blockType === blockB.blockType + const blocksWithTheSameType = blockA.blockName === blockB.blockName ? [ blockB ] - : switchToBlockType( blockB, blockA.blockType ); + : switchToBlockType( blockB, blockA.blockName ); // If the block types can not match, do nothing if ( ! blocksWithTheSameType || ! blocksWithTheSameType.length ) { From f62098390628f009e99bbffff003253344728aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Ventura?= Date: Wed, 31 May 2017 11:26:37 +0200 Subject: [PATCH 11/12] Update block Readme to refer to type. --- blocks/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/README.md b/blocks/README.md index 89d3529a8747ea..0415bf7252fdab 100644 --- a/blocks/README.md +++ b/blocks/README.md @@ -121,7 +121,7 @@ In the random image block above, we've given the `alt` attribute of the image a ## API -### `wp.blocks.registerBlockType( slug: string, settings: Object )` +### `wp.blocks.registerBlockType( name: string, typeDefinition: Object )` Registers a new block provided a unique slug and an object defining its behavior. Once registered, the block is made available as an option to any editor interface where blocks are implemented. @@ -148,7 +148,7 @@ Inline controls for [`Editable`](#editable) elements are identical for every blo ### `wp.blocks.getBlockType( slug: string )` -Returns settings associated with a registered block. +Returns type definitions associated with a registered block. ### `wp.blocks.getControlSettings( slug: string )` From 11ac2a2ca3d171be19da275162fa2355529fb632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Ventura?= Date: Thu, 1 Jun 2017 13:09:39 +0200 Subject: [PATCH 12/12] Simplify blockName attribute. --- blocks/api/factory.js | 26 +++---- blocks/api/serializer.js | 2 +- blocks/api/test/factory.js | 30 ++++---- blocks/api/test/parser.js | 16 ++--- blocks/api/test/serializer.js | 4 +- blocks/test/fixtures/core-button-center.json | 2 +- blocks/test/fixtures/core-code.json | 2 +- .../fixtures/core-embed-youtube-caption.json | 2 +- blocks/test/fixtures/core-freeform.json | 2 +- blocks/test/fixtures/core-heading-h2-em.json | 2 +- blocks/test/fixtures/core-heading-h2.json | 2 +- .../fixtures/core-image-center-caption.json | 2 +- blocks/test/fixtures/core-image.json | 2 +- blocks/test/fixtures/core-list-ul.json | 2 +- blocks/test/fixtures/core-preformatted.json | 2 +- blocks/test/fixtures/core-pullquote.json | 2 +- blocks/test/fixtures/core-quote-style-1.json | 2 +- blocks/test/fixtures/core-quote-style-2.json | 2 +- blocks/test/fixtures/core-separator.json | 2 +- blocks/test/fixtures/core-table.json | 2 +- .../test/fixtures/core-text-align-right.json | 2 +- .../fixtures/core-text-multi-paragraph.json | 2 +- editor/block-switcher/index.js | 4 +- editor/effects.js | 6 +- editor/modes/visual-editor/block.js | 4 +- editor/sidebar/block-inspector/index.js | 2 +- editor/test/effects.js | 20 +++--- editor/test/selectors.js | 44 ++++++------ editor/test/state.js | 68 +++++++++---------- 29 files changed, 130 insertions(+), 130 deletions(-) diff --git a/blocks/api/factory.js b/blocks/api/factory.js index 22d5e60d89f8f2..000468224adbbe 100644 --- a/blocks/api/factory.js +++ b/blocks/api/factory.js @@ -12,13 +12,13 @@ import { getBlockType } from './registration'; /** * Returns a block object given its type and attributes. * - * @param {String} blockName Block name + * @param {String} name Block name * @param {Object} attributes Block attributes * @return {Object} Block object */ -export function createBlock( blockName, attributes = {} ) { +export function createBlock( name, attributes = {} ) { // Get the type definition associated with a registered block. - const blockType = getBlockType( blockName ); + const blockType = getBlockType( name ); // Do we need this? What purpose does it have? let defaultAttributes; @@ -30,7 +30,7 @@ export function createBlock( blockName, attributes = {} ) { // and the block attributes. return { uid: uuid(), - blockName, + name, attributes: { ...defaultAttributes, ...attributes, @@ -42,19 +42,19 @@ export function createBlock( blockName, attributes = {} ) { * Switch a block into one or more blocks of the new block type. * * @param {Object} block Block object - * @param {string} blockName Block name + * @param {string} name Block name * @return {Array} Block object */ -export function switchToBlockType( block, blockName ) { +export function switchToBlockType( block, name ) { // Find the right transformation by giving priority to the "to" // transformation. - const destinationType = getBlockType( blockName ); - const sourceType = getBlockType( block.blockName ); + const destinationType = getBlockType( name ); + const sourceType = getBlockType( block.name ); const transformationsFrom = get( destinationType, 'transforms.from', [] ); const transformationsTo = get( sourceType, 'transforms.to', [] ); const transformation = - find( transformationsTo, t => t.blocks.indexOf( blockName ) !== -1 ) || - find( transformationsFrom, t => t.blocks.indexOf( block.blockName ) !== -1 ); + find( transformationsTo, t => t.blocks.indexOf( name ) !== -1 ) || + find( transformationsFrom, t => t.blocks.indexOf( block.name ) !== -1 ); // Stop if there is no valid transformation. (How did we get here?) if ( ! transformation ) { @@ -75,11 +75,11 @@ export function switchToBlockType( block, blockName ) { // Ensure that every block object returned by the transformation has a // valid block type. - if ( transformationResults.some( ( result ) => ! getBlockType( result.blockName ) ) ) { + if ( transformationResults.some( ( result ) => ! getBlockType( result.name ) ) ) { return null; } - const firstSwitchedBlock = findIndex( transformationResults, ( result ) => result.blockName === blockName ); + const firstSwitchedBlock = findIndex( transformationResults, ( result ) => result.name === name ); // Ensure that at least one block object returned by the transformation has // the expected "destination" block type. @@ -92,7 +92,7 @@ export function switchToBlockType( block, blockName ) { // The first transformed block whose type matches the "destination" // type gets to keep the existing block's UID. uid: index === firstSwitchedBlock ? block.uid : result.uid, - blockName: result.blockName, + name: result.name, attributes: result.attributes, }; } ); diff --git a/blocks/api/serializer.js b/blocks/api/serializer.js index 8ae83b463c80d9..3d114e4aa31835 100644 --- a/blocks/api/serializer.js +++ b/blocks/api/serializer.js @@ -71,7 +71,7 @@ export function getCommentAttributes( realAttributes, expectedAttributes ) { */ export default function serialize( blocks ) { return blocks.reduce( ( memo, block ) => { - const blockName = block.blockName; + const blockName = block.name; const blockType = getBlockType( blockName ); const saveContent = getSaveContent( blockType.save, block.attributes ); const beautifyOptions = { diff --git a/blocks/api/test/factory.js b/blocks/api/test/factory.js index f2aa4971e68ce0..c3f8b3fa7c2d41 100644 --- a/blocks/api/test/factory.js +++ b/blocks/api/test/factory.js @@ -28,7 +28,7 @@ describe( 'block factory', () => { align: 'left', } ); - expect( block.blockName ).to.eql( 'core/test-block' ); + expect( block.name ).to.eql( 'core/test-block' ); expect( block.attributes ).to.eql( { includesDefault: true, align: 'left', @@ -55,7 +55,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'ribs', }, @@ -65,7 +65,7 @@ describe( 'block factory', () => { expect( updatedBlock ).to.eql( [ { uid: 1, - blockName: 'core/updated-text-block', + name: 'core/updated-text-block', attributes: { value: 'chicken ribs', }, @@ -89,7 +89,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'ribs', }, @@ -99,7 +99,7 @@ describe( 'block factory', () => { expect( updatedBlock ).to.eql( [ { uid: 1, - blockName: 'core/updated-text-block', + name: 'core/updated-text-block', attributes: { value: 'chicken ribs', }, @@ -112,7 +112,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'ribs', }, @@ -136,7 +136,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'ribs', }, @@ -160,7 +160,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'ribs', }, @@ -190,7 +190,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'ribs', }, @@ -225,7 +225,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'ribs', }, @@ -253,7 +253,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'ribs', }, @@ -286,7 +286,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'ribs', }, @@ -319,7 +319,7 @@ describe( 'block factory', () => { const block = { uid: 1, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'ribs', }, @@ -337,13 +337,13 @@ describe( 'block factory', () => { expect( updatedBlock ).to.eql( [ { uid: 2, - blockName: 'core/text-block', + name: 'core/text-block', attributes: { value: 'chicken ribs', }, }, { uid: 1, - blockName: 'core/updated-text-block', + name: 'core/updated-text-block', attributes: { value: 'smoked ribs', }, diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index 2ca9a0747276a5..af8401c578c997 100644 --- a/blocks/api/test/parser.js +++ b/blocks/api/test/parser.js @@ -100,7 +100,7 @@ describe( 'block parser', () => { 'content', { attr: 'value' } ); - expect( block.blockName ).to.eql( 'core/test-block' ); + expect( block.name ).to.eql( 'core/test-block' ); expect( block.attributes ).to.eql( { attr: 'value' } ); } ); @@ -108,7 +108,7 @@ describe( 'block parser', () => { registerBlockType( 'core/test-block', {} ); const block = createBlockWithFallback( 'core/test-block', 'content' ); - expect( block.blockName ).to.eql( 'core/test-block' ); + expect( block.name ).to.eql( 'core/test-block' ); expect( block.attributes ).to.eql( {} ); } ); @@ -121,7 +121,7 @@ describe( 'block parser', () => { 'content', { attr: 'value' } ); - expect( block.blockName ).to.eql( 'core/unknown-block' ); + expect( block.name ).to.eql( 'core/unknown-block' ); expect( block.attributes ).to.eql( { attr: 'value' } ); } ); @@ -130,7 +130,7 @@ describe( 'block parser', () => { setUnknownTypeHandler( 'core/unknown-block' ); const block = createBlockWithFallback( null, 'content' ); - expect( block.blockName ).to.eql( 'core/unknown-block' ); + expect( block.name ).to.eql( 'core/unknown-block' ); expect( block.attributes ).to.eql( {} ); } ); @@ -162,7 +162,7 @@ describe( 'block parser', () => { ); expect( parsed ).to.have.lengthOf( 1 ); - expect( parsed[ 0 ].blockName ).to.equal( 'core/test-block' ); + expect( parsed[ 0 ].name ).to.equal( 'core/test-block' ); expect( parsed[ 0 ].attributes ).to.eql( { content: 'Brisket', smoked: 'yes', @@ -195,7 +195,7 @@ describe( 'block parser', () => { ); expect( parsed ).to.have.lengthOf( 1 ); - expect( parsed[ 0 ].blockName ).to.equal( 'core/test-block' ); + expect( parsed[ 0 ].name ).to.equal( 'core/test-block' ); expect( parsed[ 0 ].attributes ).to.eql( { content: 'Ribs & Chicken', } ); @@ -215,7 +215,7 @@ describe( 'block parser', () => { ); expect( parsed ).to.have.lengthOf( 3 ); - expect( parsed.map( ( { blockName } ) => blockName ) ).to.eql( [ + expect( parsed.map( ( { name } ) => name ) ).to.eql( [ 'core/test-block', 'core/unknown-block', 'core/unknown-block', @@ -244,7 +244,7 @@ describe( 'block parser', () => { ); expect( parsed ).to.have.lengthOf( 5 ); - expect( parsed.map( ( { blockName } ) => blockName ) ).to.eql( [ + expect( parsed.map( ( { name } ) => name ) ).to.eql( [ 'core/unknown-block', 'core/test-block', 'core/unknown-block', diff --git a/blocks/api/test/serializer.js b/blocks/api/test/serializer.js index bb66c7f43d8d56..75621e39e31a0e 100644 --- a/blocks/api/test/serializer.js +++ b/blocks/api/test/serializer.js @@ -12,7 +12,7 @@ import { getBlockTypes, registerBlockType, unregisterBlockType } from '../regist describe( 'block serializer', () => { afterEach( () => { getBlockTypes().forEach( block => { - unregisterBlockType( block.slug ); + unregisterBlockType( block.name ); } ); } ); @@ -102,7 +102,7 @@ describe( 'block serializer', () => { registerBlockType( 'core/test-block', blockType ); const blockList = [ { - blockName: 'core/test-block', + name: 'core/test-block', attributes: { content: 'Ribs & Chicken', align: 'left', diff --git a/blocks/test/fixtures/core-button-center.json b/blocks/test/fixtures/core-button-center.json index 570c6649201b67..6a257c42322e77 100644 --- a/blocks/test/fixtures/core-button-center.json +++ b/blocks/test/fixtures/core-button-center.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/button", + "name": "core/button", "attributes": { "align": "center", "url": "https://github.com/WordPress/gutenberg", diff --git a/blocks/test/fixtures/core-code.json b/blocks/test/fixtures/core-code.json index e208865e3dca80..4d2fc33c743b73 100644 --- a/blocks/test/fixtures/core-code.json +++ b/blocks/test/fixtures/core-code.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/code", + "name": "core/code", "attributes": { "content": "export default function MyButton() {\n\treturn ;\n}" } diff --git a/blocks/test/fixtures/core-embed-youtube-caption.json b/blocks/test/fixtures/core-embed-youtube-caption.json index 2f6102f5e253db..81689a7432fd07 100644 --- a/blocks/test/fixtures/core-embed-youtube-caption.json +++ b/blocks/test/fixtures/core-embed-youtube-caption.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/embed", + "name": "core/embed", "attributes": { "url": "//www.youtube.com/embed/Nl6U7UotA-M", "caption": [ diff --git a/blocks/test/fixtures/core-freeform.json b/blocks/test/fixtures/core-freeform.json index e5e0813e3331c3..d78ea4ed6181f0 100644 --- a/blocks/test/fixtures/core-freeform.json +++ b/blocks/test/fixtures/core-freeform.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/freeform", + "name": "core/freeform", "attributes": { "html": "Testing freeform block with some

    HTML content
    " } diff --git a/blocks/test/fixtures/core-heading-h2-em.json b/blocks/test/fixtures/core-heading-h2-em.json index 774fa988237adf..16513a34cfa3cc 100644 --- a/blocks/test/fixtures/core-heading-h2-em.json +++ b/blocks/test/fixtures/core-heading-h2-em.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/heading", + "name": "core/heading", "attributes": { "content": [ "The ", diff --git a/blocks/test/fixtures/core-heading-h2.json b/blocks/test/fixtures/core-heading-h2.json index 98cdbc59bc9c94..915407fa11b90d 100644 --- a/blocks/test/fixtures/core-heading-h2.json +++ b/blocks/test/fixtures/core-heading-h2.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/heading", + "name": "core/heading", "attributes": { "content": [ "A picture is worth a thousand words, or so the saying goes" diff --git a/blocks/test/fixtures/core-image-center-caption.json b/blocks/test/fixtures/core-image-center-caption.json index a883bf143af80a..4630b4bb896828 100644 --- a/blocks/test/fixtures/core-image-center-caption.json +++ b/blocks/test/fixtures/core-image-center-caption.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/image", + "name": "core/image", "attributes": { "align": "center", "url": "https://cldup.com/YLYhpou2oq.jpg", diff --git a/blocks/test/fixtures/core-image.json b/blocks/test/fixtures/core-image.json index fc982f7513ba76..e04ca6120b14a6 100644 --- a/blocks/test/fixtures/core-image.json +++ b/blocks/test/fixtures/core-image.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/image", + "name": "core/image", "attributes": { "url": "https://cldup.com/uuUqE_dXzy.jpg", "caption": [] diff --git a/blocks/test/fixtures/core-list-ul.json b/blocks/test/fixtures/core-list-ul.json index 15717a69fecbd8..1ebd8c3f7fd287 100644 --- a/blocks/test/fixtures/core-list-ul.json +++ b/blocks/test/fixtures/core-list-ul.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/list", + "name": "core/list", "attributes": { "nodeName": "UL", "values": [ diff --git a/blocks/test/fixtures/core-preformatted.json b/blocks/test/fixtures/core-preformatted.json index a573ddab5324e5..3b77060722d570 100644 --- a/blocks/test/fixtures/core-preformatted.json +++ b/blocks/test/fixtures/core-preformatted.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/preformatted", + "name": "core/preformatted", "attributes": { "content": [ "Some ", diff --git a/blocks/test/fixtures/core-pullquote.json b/blocks/test/fixtures/core-pullquote.json index 2a271301e4a573..088e26a2d92f0a 100644 --- a/blocks/test/fixtures/core-pullquote.json +++ b/blocks/test/fixtures/core-pullquote.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/pullquote", + "name": "core/pullquote", "attributes": { "value": [ [ diff --git a/blocks/test/fixtures/core-quote-style-1.json b/blocks/test/fixtures/core-quote-style-1.json index b0187fe4d74812..37815136063030 100644 --- a/blocks/test/fixtures/core-quote-style-1.json +++ b/blocks/test/fixtures/core-quote-style-1.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/quote", + "name": "core/quote", "attributes": { "style": "1", "value": [ diff --git a/blocks/test/fixtures/core-quote-style-2.json b/blocks/test/fixtures/core-quote-style-2.json index 1e3b87982a9d65..ba3c1bd9241327 100644 --- a/blocks/test/fixtures/core-quote-style-2.json +++ b/blocks/test/fixtures/core-quote-style-2.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/quote", + "name": "core/quote", "attributes": { "style": "2", "value": [ diff --git a/blocks/test/fixtures/core-separator.json b/blocks/test/fixtures/core-separator.json index 83bf90d5c8972c..c068dfcf2de5a3 100644 --- a/blocks/test/fixtures/core-separator.json +++ b/blocks/test/fixtures/core-separator.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/separator", + "name": "core/separator", "attributes": {} } ] diff --git a/blocks/test/fixtures/core-table.json b/blocks/test/fixtures/core-table.json index 1e43a30ec56db6..eb57ab634f0010 100644 --- a/blocks/test/fixtures/core-table.json +++ b/blocks/test/fixtures/core-table.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/table", + "name": "core/table", "attributes": { "body": [ [ diff --git a/blocks/test/fixtures/core-text-align-right.json b/blocks/test/fixtures/core-text-align-right.json index 486b1afc5123df..c4854077e88866 100644 --- a/blocks/test/fixtures/core-text-align-right.json +++ b/blocks/test/fixtures/core-text-align-right.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/text", + "name": "core/text", "attributes": { "content": [ { diff --git a/blocks/test/fixtures/core-text-multi-paragraph.json b/blocks/test/fixtures/core-text-multi-paragraph.json index 8b019be283f3ae..4760696210f6b2 100644 --- a/blocks/test/fixtures/core-text-multi-paragraph.json +++ b/blocks/test/fixtures/core-text-multi-paragraph.json @@ -1,7 +1,7 @@ [ { "uid": "_uid_0", - "blockName": "core/text", + "name": "core/text", "attributes": { "content": [ { diff --git a/editor/block-switcher/index.js b/editor/block-switcher/index.js index c76820feccdba0..e563b6e40a748f 100644 --- a/editor/block-switcher/index.js +++ b/editor/block-switcher/index.js @@ -50,10 +50,10 @@ class BlockSwitcher extends wp.element.Component { } render() { - const blockType = wp.blocks.getBlockType( this.props.block.blockName ); + const blockType = wp.blocks.getBlockType( this.props.block.name ); const blocksToBeTransformedFrom = reduce( wp.blocks.getBlockTypes(), ( memo, block ) => { const transformFrom = get( block, 'transforms.from', [] ); - const transformation = find( transformFrom, t => t.blocks.indexOf( this.props.block.blockName ) !== -1 ); + const transformation = find( transformFrom, t => t.blocks.indexOf( this.props.block.name ) !== -1 ); return transformation ? memo.concat( [ block.slug ] ) : memo; }, [] ); const blocksToBeTransformedTo = get( blockType, 'transforms.to', [] ) diff --git a/editor/effects.js b/editor/effects.js index b2cc3a2825104b..153bc11ffca5d7 100644 --- a/editor/effects.js +++ b/editor/effects.js @@ -71,7 +71,7 @@ export default { MERGE_BLOCKS( action, store ) { const { dispatch } = store; const [ blockA, blockB ] = action.blocks; - const blockType = getBlockType( blockA.blockName ); + const blockType = getBlockType( blockA.name ); // Only focus the previous block if it's not mergeable if ( ! blockType.merge ) { @@ -81,9 +81,9 @@ export default { // We can only merge blocks with similar types // thus, we transform the block to merge first - const blocksWithTheSameType = blockA.blockName === blockB.blockName + const blocksWithTheSameType = blockA.name === blockB.name ? [ blockB ] - : switchToBlockType( blockB, blockA.blockName ); + : switchToBlockType( blockB, blockA.name ); // If the block types can not match, do nothing if ( ! blocksWithTheSameType || ! blocksWithTheSameType.length ) { diff --git a/editor/modes/visual-editor/block.js b/editor/modes/visual-editor/block.js index dc808a318f14e0..1e43e9182e0006 100644 --- a/editor/modes/visual-editor/block.js +++ b/editor/modes/visual-editor/block.js @@ -182,7 +182,7 @@ class VisualEditorBlock extends wp.element.Component { render() { const { block, selectedBlocks } = this.props; - const blockType = wp.blocks.getBlockType( block.blockName ); + const blockType = wp.blocks.getBlockType( block.name ); let BlockEdit; if ( blockType ) { @@ -228,7 +228,7 @@ class VisualEditorBlock extends wp.element.Component { onMouseEnter={ this.maybeHover } onMouseLeave={ onMouseLeave } className={ className } - data-type={ block.blockName } + data-type={ block.name } tabIndex="0" { ...wrapperProps } > diff --git a/editor/sidebar/block-inspector/index.js b/editor/sidebar/block-inspector/index.js index 0e773a0d9e239e..1fb510f529ca3d 100644 --- a/editor/sidebar/block-inspector/index.js +++ b/editor/sidebar/block-inspector/index.js @@ -35,7 +35,7 @@ const BlockInspector = ( { selectedBlock, ...props } ) => { -
    { selectedBlock.blockName } settings...
    +
    { selectedBlock.name } settings...
      { Object.keys( selectedBlock.attributes ).map( ( attribute, index ) => (
    • { attribute }: { selectedBlock.attributes[ attribute ] }
    • diff --git a/editor/test/effects.js b/editor/test/effects.js index 5493a3a7bd5bdd..83364d229a0392 100644 --- a/editor/test/effects.js +++ b/editor/test/effects.js @@ -29,11 +29,11 @@ describe( 'effects', () => { registerBlockType( 'core/test-block', {} ); const blockA = { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', }; const blockB = { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', }; const dispatch = sinon.spy(); handler( mergeBlocks( blockA, blockB ), { dispatch } ); @@ -52,12 +52,12 @@ describe( 'effects', () => { } ); const blockA = { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: { content: 'chicken' }, }; const blockB = { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: { content: 'ribs' }, }; const dispatch = sinon.spy(); @@ -67,7 +67,7 @@ describe( 'effects', () => { expect( dispatch ).to.have.been.calledWith( focusBlock( 'chicken', { offset: -1 } ) ); expect( dispatch ).to.have.been.calledWith( replaceBlocks( [ 'chicken', 'ribs' ], [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: { content: 'chicken ribs' }, } ] ) ); } ); @@ -83,12 +83,12 @@ describe( 'effects', () => { registerBlockType( 'core/test-block-2', {} ); const blockA = { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: { content: 'chicken' }, }; const blockB = { uid: 'ribs', - blockName: 'core/test-block2', + name: 'core/test-block2', attributes: { content: 'ribs' }, }; const dispatch = sinon.spy(); @@ -120,12 +120,12 @@ describe( 'effects', () => { } ); const blockA = { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: { content: 'chicken' }, }; const blockB = { uid: 'ribs', - blockName: 'core/test-block-2', + name: 'core/test-block-2', attributes: { content2: 'ribs' }, }; const dispatch = sinon.spy(); @@ -135,7 +135,7 @@ describe( 'effects', () => { expect( dispatch ).to.have.been.calledWith( focusBlock( 'chicken', { offset: -1 } ) ); expect( dispatch ).to.have.been.calledWith( replaceBlocks( [ 'chicken', 'ribs' ], [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: { content: 'chicken ribs' }, } ] ) ); } ); diff --git a/editor/test/selectors.js b/editor/test/selectors.js index d644bfe47f1fe4..a7f1bae80e4cbf 100644 --- a/editor/test/selectors.js +++ b/editor/test/selectors.js @@ -360,12 +360,12 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 123: { uid: 123, blockName: 'core/text' }, + 123: { uid: 123, name: 'core/text' }, }, }, }; - expect( getBlock( state, 123 ) ).to.eql( { uid: 123, blockName: 'core/text' } ); + expect( getBlock( state, 123 ) ).to.eql( { uid: 123, name: 'core/text' } ); } ); } ); @@ -374,16 +374,16 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockName: 'core/heading' }, - 123: { uid: 123, blockName: 'core/text' }, + 23: { uid: 23, name: 'core/heading' }, + 123: { uid: 123, name: 'core/text' }, }, blockOrder: [ 123, 23 ], }, }; expect( getBlocks( state ) ).to.eql( [ - { uid: 123, blockName: 'core/text' }, - { uid: 23, blockName: 'core/heading' }, + { uid: 123, name: 'core/text' }, + { uid: 23, name: 'core/heading' }, ] ); } ); } ); @@ -393,8 +393,8 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockName: 'core/heading' }, - 123: { uid: 123, blockName: 'core/text' }, + 23: { uid: 23, name: 'core/heading' }, + 123: { uid: 123, name: 'core/text' }, }, }, selectedBlock: { uid: null }, @@ -408,8 +408,8 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockName: 'core/heading' }, - 123: { uid: 123, blockName: 'core/text' }, + 23: { uid: 23, name: 'core/heading' }, + 123: { uid: 123, name: 'core/text' }, }, }, selectedBlock: { uid: 23 }, @@ -423,8 +423,8 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockName: 'core/heading' }, - 123: { uid: 123, blockName: 'core/text' }, + 23: { uid: 23, name: 'core/heading' }, + 123: { uid: 123, name: 'core/text' }, }, }, selectedBlock: { uid: 23 }, @@ -532,15 +532,15 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockName: 'core/heading' }, - 123: { uid: 123, blockName: 'core/text' }, + 23: { uid: 23, name: 'core/heading' }, + 123: { uid: 123, name: 'core/text' }, }, blockOrder: [ 123, 23 ], }, }; expect( getPreviousBlock( state, 23 ) ).to.eql( - { uid: 123, blockName: 'core/text' }, + { uid: 123, name: 'core/text' }, ); } ); @@ -548,8 +548,8 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockName: 'core/heading' }, - 123: { uid: 123, blockName: 'core/text' }, + 23: { uid: 23, name: 'core/heading' }, + 123: { uid: 123, name: 'core/text' }, }, blockOrder: [ 123, 23 ], }, @@ -564,15 +564,15 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockName: 'core/heading' }, - 123: { uid: 123, blockName: 'core/text' }, + 23: { uid: 23, name: 'core/heading' }, + 123: { uid: 123, name: 'core/text' }, }, blockOrder: [ 123, 23 ], }, }; expect( getNextBlock( state, 123 ) ).to.eql( - { uid: 23, blockName: 'core/heading' }, + { uid: 23, name: 'core/heading' }, ); } ); @@ -580,8 +580,8 @@ describe( 'selectors', () => { const state = { editor: { blocksByUid: { - 23: { uid: 23, blockName: 'core/heading' }, - 123: { uid: 123, blockName: 'core/text' }, + 23: { uid: 23, name: 'core/heading' }, + 123: { uid: 123, name: 'core/text' }, }, blockOrder: [ 123, 23 ], }, diff --git a/editor/test/state.js b/editor/test/state.js index bf1a0623c7f6cb..7c38718836abdd 100644 --- a/editor/test/state.js +++ b/editor/test/state.js @@ -77,7 +77,7 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -85,7 +85,7 @@ describe( 'state', () => { type: 'INSERT_BLOCK', block: { uid: 'ribs', - blockName: 'core/freeform', + name: 'core/freeform', }, } ); @@ -99,7 +99,7 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -108,12 +108,12 @@ describe( 'state', () => { uids: [ 'chicken' ], blocks: [ { uid: 'wings', - blockName: 'core/freeform', + name: 'core/freeform', } ], } ); expect( Object.keys( state.blocksByUid ) ).to.have.lengthOf( 1 ); - expect( values( state.blocksByUid )[ 0 ].blockName ).to.equal( 'core/freeform' ); + expect( values( state.blocksByUid )[ 0 ].name ).to.equal( 'core/freeform' ); expect( values( state.blocksByUid )[ 0 ].uid ).to.equal( 'wings' ); expect( state.blockOrder ).to.eql( [ 'wings' ] ); } ); @@ -123,11 +123,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -144,15 +144,15 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'veggies', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -169,11 +169,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -190,11 +190,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -211,15 +211,15 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'veggies', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -236,11 +236,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -257,11 +257,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -274,7 +274,7 @@ describe( 'state', () => { expect( state.blocksByUid ).to.eql( { ribs: { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, } ); @@ -285,15 +285,15 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'chicken', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'veggies', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -306,7 +306,7 @@ describe( 'state', () => { expect( state.blocksByUid ).to.eql( { ribs: { uid: 'ribs', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, } ); @@ -317,11 +317,11 @@ describe( 'state', () => { type: 'RESET_BLOCKS', blocks: [ { uid: 'kumquat', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, }, { uid: 'loquat', - blockName: 'core/test-block', + name: 'core/test-block', attributes: {}, } ], } ); @@ -331,7 +331,7 @@ describe( 'state', () => { after: 'kumquat', block: { uid: 'persimmon', - blockName: 'core/freeform', + name: 'core/freeform', }, } ); @@ -539,7 +539,7 @@ describe( 'state', () => { uids: [ 'chicken' ], blocks: [ { uid: 'wings', - blockName: 'core/freeform', + name: 'core/freeform', } ], } ); @@ -552,7 +552,7 @@ describe( 'state', () => { uids: [ 'ribs' ], blocks: [ { uid: 'wings', - blockName: 'core/freeform', + name: 'core/freeform', } ], } ); @@ -657,7 +657,7 @@ describe( 'state', () => { type: 'INSERT_BLOCK', block: { uid: 'ribs', - blockName: 'core/freeform', + name: 'core/freeform', }, } ); @@ -739,7 +739,7 @@ describe( 'state', () => { uids: [ 'chicken' ], blocks: [ { uid: 'wings', - blockName: 'core/freeform', + name: 'core/freeform', } ], } ); @@ -753,7 +753,7 @@ describe( 'state', () => { uids: [ 'ribs' ], blocks: [ { uid: 'wings', - blockName: 'core/freeform', + name: 'core/freeform', } ], } );