-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix/1390 Make "title" a block #2714
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ import './text-columns'; | |
import './verse'; | ||
import './video'; | ||
import './audio'; | ||
import './post-title'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.editor-post-permalink { | ||
display: inline-flex; | ||
align-items: center; | ||
position: absolute; | ||
top: -34px; | ||
box-shadow: $shadow-popover; | ||
border: 1px solid $light-gray-500; | ||
background: $white; | ||
padding: 5px; | ||
font-family: $default-font; | ||
font-size: $default-font-size; | ||
left: 0; | ||
right: 0; | ||
|
||
@include break-small() { | ||
left: $block-padding + $block-mover-padding-visible - 2px; | ||
right: $block-padding + $block-mover-padding-visible - 2px; | ||
} | ||
} | ||
|
||
.editor-post-permalink__label { | ||
margin: 0 10px; | ||
} | ||
|
||
.editor-post-permalink__link { | ||
color: $dark-gray-200; | ||
text-decoration: underline; | ||
margin-right: 10px; | ||
width: 100%; | ||
overflow: hidden; | ||
position: relative; | ||
white-space: nowrap; | ||
|
||
&:after { | ||
@include long-content-fade( $size: 20% ); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { registerBlockType, source } from '../../api'; | ||
import PostTitleEdit from './post-title-edit'; | ||
|
||
registerBlockType( 'core/post-title', { | ||
title: __( 'Post Title' ), | ||
|
||
keywords: [ __( 'title' ) ], | ||
|
||
className: false, | ||
|
||
category: 'common', | ||
|
||
attributes: { | ||
content: { | ||
type: 'string', | ||
source: source.text(), | ||
}, | ||
}, | ||
|
||
isFixed: true, | ||
|
||
edit( { attributes, setAttributes, focus, setFocus } ) { | ||
return <PostTitleEdit | ||
title={ attributes.content } | ||
focus={ focus } | ||
setFocus={ setFocus } | ||
onChange={ value => setAttributes( { content: value } ) } | ||
/>; | ||
}, | ||
|
||
save( { attributes } ) { | ||
return <h1> { attributes.content } </h1>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Dashicon, ClipboardButton, Button } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import './editor.scss'; | ||
import { isEditedPostNew, getEditedPostAttribute } from '../../../editor/selectors'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to be reaching out into the editor top-level directory. This could tie into #2473 |
||
|
||
class PostPermalink extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
this.state = { | ||
showCopyConfirmation: false, | ||
}; | ||
this.onCopy = this.onCopy.bind( this ); | ||
} | ||
|
||
componentWillUnmout() { | ||
clearTimeout( this.dismissCopyConfirmation ); | ||
} | ||
|
||
onCopy() { | ||
this.setState( { | ||
showCopyConfirmation: true, | ||
} ); | ||
|
||
clearTimeout( this.dismissCopyConfirmation ); | ||
this.dismissCopyConfirmation = setTimeout( () => { | ||
this.setState( { | ||
showCopyConfirmation: false, | ||
} ); | ||
}, 4000 ); | ||
} | ||
|
||
render() { | ||
const { isNew, link } = this.props; | ||
if ( isNew || ! link ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="editor-post-permalink"> | ||
<Dashicon icon="admin-links" /> | ||
<span className="editor-post-permalink__label">{ __( 'Permalink:' ) }</span> | ||
<Button className="editor-post-permalink__link" href={ link } target="_blank"> | ||
{ link } | ||
</Button> | ||
<ClipboardButton className="button" text={ link } onCopy={ this.onCopy }> | ||
{ this.state.showCopyConfirmation ? __( 'Copied!' ) : __( 'Copy' ) } | ||
</ClipboardButton> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
( state ) => { | ||
return { | ||
isNew: isEditedPostNew( state ), | ||
link: getEditedPostAttribute( state, 'link' ), | ||
}; | ||
} | ||
)( PostPermalink ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { connect } from 'react-redux'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import Editable from '../../editable'; | ||
import PostPermaLink from './post-permalink'; | ||
import { editPost } from '../../../editor/actions'; | ||
|
||
const PostTitleEdit = ( { title, focus, setFocus, onChange } ) => [ | ||
focus && <PostPermaLink />, | ||
<Editable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this needs to be editable, just a plain |
||
key="editable" | ||
tagName="h1" | ||
value={ [ title ] } | ||
focus={ focus } | ||
onFocus={ setFocus } | ||
onChange={ onChange } | ||
style={ { textAlign: 'left' } } | ||
formattingControls={ [] } /> ]; | ||
|
||
export default connect( null, dispatch => ( { onChange: title => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is a bit difficult to understand given the many levels of function nesting and differing implicit return / explicit arrow function blocks it creates. |
||
dispatch( editPost( { title: title[ 0 ] } ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the value of title here? If we were to consider |
||
} } ) )( PostTitleEdit ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { get, uniqueId } from 'lodash'; | |
/** | ||
* WordPress dependencies | ||
*/ | ||
import { parse, getBlockType, switchToBlockType } from '@wordpress/blocks'; | ||
import { parse, getBlockType, switchToBlockType, createBlock } from '@wordpress/blocks'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
|
@@ -254,12 +254,15 @@ export default { | |
SET_INITIAL_POST( action ) { | ||
const { post } = action; | ||
const effects = []; | ||
let blocks = []; | ||
|
||
// Parse content as blocks | ||
if ( post.content.raw ) { | ||
effects.push( resetBlocks( parse( post.content.raw ) ) ); | ||
blocks = blocks.concat( parse( post.content.raw ) ); | ||
} | ||
|
||
effects.push( resetBlocks( blocks ) ); | ||
|
||
// Resetting post should occur after blocks have been reset, since it's | ||
// the post reset that restarts history (used in dirty detection). | ||
effects.push( resetPost( post ) ); | ||
|
@@ -273,4 +276,8 @@ export default { | |
|
||
return effects; | ||
}, | ||
RESET_BLOCKS( action, store ) { | ||
const blocks = [ createBlock( 'core/post-title' ) ].concat( action.blocks ); | ||
store.dispatch( { type: 'ACTUALLY_RESET_BLOCKS', blocks } ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we need to better distinguish between effects triggered by |
||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be redundant, given that searching "title" would also match the "Post Title" title property, unless it was localized significantly different between "title" and "Post Title".