Skip to content

Commit

Permalink
Show inserter at block mover slot for empty text block
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Apr 28, 2017
1 parent 92be486 commit 9728eeb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
38 changes: 33 additions & 5 deletions blocks/library/text/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/**
* External dependencies
*/
import { Fill } from 'react-slot-fill';

/**
* Internal dependencies
*/
import { registerBlock, query } from 'api';
import Editable from 'components/editable';
import Inserter from '../../../editor/components/inserter';

const { children } = query;

const DEFAULT_CONTENT = <p />;

registerBlock( 'core/text', {
title: wp.i18n.__( 'Text' ),

Expand All @@ -18,7 +26,7 @@ registerBlock( 'core/text', {
},

defaultAttributes: {
content: <p />
content: DEFAULT_CONTENT
},

controls: [
Expand Down Expand Up @@ -56,9 +64,11 @@ registerBlock( 'core/text', {

edit( { attributes, setAttributes, insertBlockAfter, focus, setFocus, mergeWithPrevious } ) {
const { content, align } = attributes;
const isEmpty = ( ! content || content === DEFAULT_CONTENT );

return (
const editable = (
<Editable
key="editable"
value={ content }
onChange={ ( nextContent ) => {
setAttributes( {
Expand All @@ -70,13 +80,31 @@ registerBlock( 'core/text', {
style={ align ? { textAlign: align } : null }
onSplit={ ( before, after ) => {
setAttributes( { content: before } );
insertBlockAfter( wp.blocks.createBlock( 'core/text', {
content: after
} ) );

let afterBlockAttributes;
if ( after ) {
afterBlockAttributes = { content: after };
}

insertBlockAfter( wp.blocks.createBlock(
'core/text',
afterBlockAttributes
) );
} }
onMerge={ mergeWithPrevious }
/>
);

if ( focus && isEmpty ) {
return [
<Fill key="inserter" name="Mover">
<Inserter />
</Fill>,
editable
];
}

return editable;
},

save( { attributes } ) {
Expand Down
2 changes: 2 additions & 0 deletions editor/components/block-mover/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import { Slot } from 'react-slot-fill';
import { connect } from 'react-redux';
import classnames from 'classnames';
import { first, last } from 'lodash';
Expand All @@ -14,6 +15,7 @@ import IconButton from 'components/icon-button';
function BlockMover( { onMoveUp, onMoveDown, isFirst, isLast } ) {
return (
<div className="editor-block-mover">
<Slot name="Mover" />
<IconButton
className={ classnames( 'editor-block-mover__control', { 'is-disabled': isFirst } ) }
onClick={ onMoveUp }
Expand Down
8 changes: 4 additions & 4 deletions languages/gutenberg.pot
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ msgstr ""

#: blocks/library/image/index.js:41
#: blocks/library/list/index.js:25
#: blocks/library/text/index.js:27
#: blocks/library/text/index.js:35
msgid "Align left"
msgstr ""

#: blocks/library/image/index.js:47
#: blocks/library/list/index.js:33
#: blocks/library/text/index.js:35
#: blocks/library/text/index.js:43
msgid "Align center"
msgstr ""

#: blocks/library/image/index.js:53
#: blocks/library/list/index.js:41
#: blocks/library/text/index.js:43
#: blocks/library/text/index.js:51
msgid "Align right"
msgstr ""

Expand All @@ -78,7 +78,7 @@ msgstr ""
msgid "Quote style %d"
msgstr ""

#: blocks/library/text/index.js:10
#: blocks/library/text/index.js:18
msgid "Text"
msgstr ""

Expand Down

0 comments on commit 9728eeb

Please sign in to comment.