Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title as a block #2089

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions blocks/library/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './text';
import './image';
import './gallery';
import './title';
import './heading';
import './quote';
import './embed';
Expand Down
99 changes: 99 additions & 0 deletions blocks/library/title/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* WordPress dependencies
*/
import { __ } from 'i18n';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note with #2172, these need to be updated to prefix the dependencies with @wordpress/. You will need to perform a rebase against the latest version of master and apply your changes:

git fetch origin
git rebase origin/master


/**
* Internal dependencies
*/
// import './block.scss';
import { registerBlockType, createBlock, query as hpq } from '../../api';
import Editable from '../../editable';
import BlockControls from '../../block-controls';
import AlignmentToolbar from '../../alignment-toolbar';
import InspectorControls from '../../inspector-controls';
import BlockDescription from '../../block-description';

const { children } = hpq;

registerBlockType( 'core/title', {
title: __( 'Title' ),

icon: 'heading',

category: 'common',

useOnce: true,

className: false,

attributes: {
content: children( 'h1' ),
},

transforms: {
from: [
{
type: 'pattern',
regExp: /^#\s/,
transform: ( { content } ) => {
return createBlock( 'core/title', {
content,
} );
},
},
],
},

edit( { attributes, setAttributes, focus, setFocus, mergeBlocks, insertBlocksAfter } ) {
const { align, content, placeholder } = attributes;

return [
focus && (
<InspectorControls key="inspector">
<BlockDescription>
<p>{ __( 'This is the document’s title. Usually it’s placed at the very top.' ) }</p>
</BlockDescription>
</InspectorControls>
),
focus && (
<BlockControls key="controls">
<AlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
/>
</BlockControls>
),
<Editable
key="editor"
tagName="h1"
value={ content }
focus={ focus }
onFocus={ setFocus }
onChange={ ( value ) => setAttributes( { content: value } ) }
onMerge={ mergeBlocks }
onSplit={ ( before, after, ...blocks ) => {
setAttributes( { content: before } );
insertBlocksAfter( [
...blocks,
createBlock( 'core/text', { content: after } ),
] );
} }
style={ { textAlign: align } }
placeholder={ placeholder || __( 'Write title…' ) }
/>,
];
},

save( { attributes } ) {
const { align, content } = attributes;

return (
<h1 style={ { textAlign: align } }>
{ content }
</h1>
);
},
} );
3 changes: 3 additions & 0 deletions blocks/test/fixtures/core__title.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:core/title -->
<h1>A <em>big</em> title</h1>
<!-- /wp:core/title -->
17 changes: 17 additions & 0 deletions blocks/test/fixtures/core__title.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"uid": "_uid_0",
"name": "core/title",
"isValid": true,
"attributes": {
"content": [
"A ",
{
"type": "em",
"children": "big"
},
" title"
]
}
}
]
11 changes: 11 additions & 0 deletions blocks/test/fixtures/core__title.parsed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"blockName": "core/title",
"attrs": null,
"rawContent": "\n<h1>A <em>big</em> title</h1>\n"
},
{
"attrs": {},
"rawContent": "\n"
}
]
3 changes: 3 additions & 0 deletions blocks/test/fixtures/core__title.serialized.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:core/title -->
<h1>A <em>big</em> title</h1>
<!-- /wp:core/title -->
2 changes: 0 additions & 2 deletions editor/modes/text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { serialize, parse } from 'blocks';
* Internal dependencies
*/
import './style.scss';
import PostTitle from '../../post-title';
import { getBlocks } from '../../selectors';

class TextEditor extends Component {
Expand Down Expand Up @@ -83,7 +82,6 @@ class TextEditor extends Component {
</div>
</header>
<div className="editor-text-editor__body">
<PostTitle />
<Textarea
autoComplete="off"
value={ value }
Expand Down
2 changes: 0 additions & 2 deletions editor/modes/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { KeyboardShortcuts } from 'components';
*/
import './style.scss';
import VisualEditorBlockList from './block-list';
import PostTitle from '../../post-title';
import { getBlockUids } from '../../selectors';
import { clearSelectedBlock, multiSelect, redo, undo } from '../../actions';

Expand Down Expand Up @@ -87,7 +86,6 @@ class VisualEditor extends Component {
'mod+z': this.undoOrRedo,
'mod+shift+z': this.undoOrRedo,
} } />
<PostTitle />
<VisualEditorBlockList ref={ this.bindBlocksContainer } />
</div>
);
Expand Down
74 changes: 0 additions & 74 deletions editor/post-permalink/index.js

This file was deleted.

37 changes: 0 additions & 37 deletions editor/post-permalink/style.scss

This file was deleted.

Loading