From e6e84d086e3a6e31df3d2118b61c5bcdcc44cf5c Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 2 Dec 2018 12:54:52 +0100 Subject: [PATCH 1/2] Add default block style if missing --- .../editor/src/components/block-styles/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/editor/src/components/block-styles/index.js b/packages/editor/src/components/block-styles/index.js index 6892df08c6d0..2c59a614f870 100644 --- a/packages/editor/src/components/block-styles/index.js +++ b/packages/editor/src/components/block-styles/index.js @@ -11,6 +11,8 @@ import { compose } from '@wordpress/compose'; import { withSelect, withDispatch } from '@wordpress/data'; import TokenList from '@wordpress/token-list'; import { ENTER, SPACE } from '@wordpress/keycodes'; +import { __ } from '@wordpress/i18n'; +import { getBlockType } from '@wordpress/blocks'; /** * Internal dependencies @@ -68,6 +70,7 @@ function BlockStyles( { onChangeClassName, name, attributes, + type, onSwitch = noop, onHoverClassName = noop, } ) { @@ -75,6 +78,17 @@ function BlockStyles( { return null; } + if ( ! type.styles && ! find( styles, 'isDefault' ) ) { + styles = [ + { + name: 'default', + label: __( 'Default' ), + isDefault: true, + }, + ...styles, + ]; + } + const activeStyle = getActiveStyle( styles, className ); function updateClassName( style ) { const updatedClassName = replaceActiveStyle( className, activeStyle, style ); @@ -131,12 +145,14 @@ export default compose( [ const { getBlock } = select( 'core/editor' ); const { getBlockStyles } = select( 'core/blocks' ); const block = getBlock( clientId ); + const blockType = getBlockType( block.name ); return { name: block.name, attributes: block.attributes, className: block.attributes.className || '', styles: getBlockStyles( block.name ), + type: blockType, }; } ), withDispatch( ( dispatch, { clientId } ) => { From 45e42b7be850d3b0fa9e997e4e88f7d97ecb26cc Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 3 Dec 2018 13:25:30 +0100 Subject: [PATCH 2/2] Add 'block style' context --- packages/editor/src/components/block-styles/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/components/block-styles/index.js b/packages/editor/src/components/block-styles/index.js index 2c59a614f870..a6ab103805de 100644 --- a/packages/editor/src/components/block-styles/index.js +++ b/packages/editor/src/components/block-styles/index.js @@ -11,7 +11,7 @@ import { compose } from '@wordpress/compose'; import { withSelect, withDispatch } from '@wordpress/data'; import TokenList from '@wordpress/token-list'; import { ENTER, SPACE } from '@wordpress/keycodes'; -import { __ } from '@wordpress/i18n'; +import { _x } from '@wordpress/i18n'; import { getBlockType } from '@wordpress/blocks'; /** @@ -82,7 +82,7 @@ function BlockStyles( { styles = [ { name: 'default', - label: __( 'Default' ), + label: _x( 'Default', 'block style' ), isDefault: true, }, ...styles,