Skip to content

Commit

Permalink
Do not change the API
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 3, 2018
1 parent 47c682c commit eb7b0b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 5 additions & 7 deletions blocks/api/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import { getBlockType, getBlockTypes } from './registration';
import { getBlockAttributes } from './parser';

/**
* Returns a block object given its type and attributes.
*
* @param {String} name Block name
* @param {Object} blockAttributes Block attributes
* @param {?String} innerHTML Block HTML
* @return {Object} Block object
* @param {String} name Block name
* @param {Object} blockAttributes Block attributes
* @return {Object} Block object
*/
export function createBlock( name, blockAttributes = {}, innerHTML ) {
export function createBlock( name, blockAttributes = {} ) {
// Get the type definition associated with a registered block.
const blockType = getBlockType( name );

Expand All @@ -59,7 +57,7 @@ export function createBlock( name, blockAttributes = {}, innerHTML ) {
uid: uuid(),
name,
isValid: true,
attributes: innerHTML ? getBlockAttributes( blockType, innerHTML, attributes ) : attributes,
attributes,
};
}

Expand Down
6 changes: 4 additions & 2 deletions blocks/library/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createMediaFromFile } from '@wordpress/utils';
*/
import './style.scss';
import './editor.scss';
import { registerBlockType, createBlock } from '../../api';
import { registerBlockType, createBlock, getBlockAttributes, getBlockType } from '../../api';
import ImageBlock from './block';

registerBlockType( 'core/image', {
Expand Down Expand Up @@ -76,8 +76,10 @@ registerBlockType( 'core/image', {
const targetNode = node.parentNode.querySelector( 'figure,img' );
const matches = /align(left|center|right)/.exec( targetNode.className );
const align = matches ? matches[ 1 ] : undefined;
const blockType = getBlockType( 'core/image' );
const attributes = getBlockAttributes( blockType, targetNode.outerHTML, { align } );

return createBlock( 'core/image', { align }, targetNode.outerHTML );
return createBlock( 'core/image', attributes );
},
},
{
Expand Down

0 comments on commit eb7b0b7

Please sign in to comment.