-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Per Block Prototype: Use an inline tinymce for small blocks (paragrap…
…hs, quotes, headings) (#148)
- Loading branch information
1 parent
01f2c86
commit efc7d11
Showing
14 changed files
with
198 additions
and
260 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
.heading-block__form { | ||
textarea, .textarea-mirror { | ||
width: 100%; | ||
border: none; | ||
font-family: Merriweather, Georgia, "Times New Roman", Times, serif; | ||
resize: none; | ||
color: inherit; | ||
font-size: inherit; | ||
font-weight: bold; | ||
overflow: hidden; | ||
|
||
&:focus { | ||
outline: 0; | ||
} | ||
width: 100%; | ||
border: none; | ||
font-family: Merriweather, Georgia, "Times New Roman", Times, serif; | ||
color: inherit; | ||
font-size: inherit; | ||
font-weight: bold; | ||
overflow: hidden; | ||
p { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
&.h1 textarea, &.h1 .textarea-mirror { | ||
&.h1 { | ||
font-size: 34px; | ||
} | ||
|
||
&.h2 textarea, &.h2 .textarea-mirror { | ||
&.h2 { | ||
font-size: 28px; | ||
} | ||
|
||
&.h3 textarea, &.h3 .textarea-mirror { | ||
&.h3 { | ||
font-size: 20px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement, Component } from 'wp-elements'; | ||
import { EditableComponent } from 'wp-blocks'; | ||
|
||
import { serialize } from 'serializers/block'; | ||
|
||
export default class InlineTextBlockForm extends Component { | ||
focus( position ) { | ||
this.editable.focus( position ); | ||
} | ||
|
||
merge = ( block, index ) => { | ||
const acceptedBlockTypes = [ 'quote', 'paragraph', 'heading' ]; | ||
if ( acceptedBlockTypes.indexOf( block.blockType ) === -1 ) { | ||
return; | ||
} | ||
|
||
const getLeaves = children => { | ||
if ( children.length === 1 && children[ 0 ].name === 'p' ) { | ||
return getLeaves( children[ 0 ].children ); | ||
} | ||
|
||
return children; | ||
}; | ||
|
||
const { block: { children }, remove, setChildren } = this.props; | ||
remove( index ); | ||
setTimeout( () => setChildren( getLeaves( children ).concat( getLeaves( block.children ) ) ) ); | ||
} | ||
|
||
bindEditable = ( ref ) => { | ||
this.editable = ref; | ||
} | ||
|
||
render() { | ||
const { block, setChildren, moveUp, moveDown, appendBlock, mergeWithPrevious, remove } = this.props; | ||
const { children } = block; | ||
|
||
const splitValue = ( left, right ) => { | ||
setChildren( left ); | ||
if ( right ) { | ||
appendBlock( { | ||
...block, | ||
children: right | ||
} ); | ||
} else { | ||
appendBlock(); | ||
} | ||
}; | ||
|
||
return ( | ||
<EditableComponent | ||
ref={ this.bindEditable } | ||
content={ serialize( children ) } | ||
moveUp={ moveUp } | ||
moveDown={ moveDown } | ||
splitValue={ splitValue } | ||
mergeWithPrevious={ mergeWithPrevious } | ||
remove={ remove } | ||
onChange={ ( value ) => setChildren( value ) } | ||
inline /> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
.paragraph-block__form textarea, .paragraph-block__form .textarea-mirror { | ||
.paragraph-block__form { | ||
width: 100%; | ||
border: none; | ||
font: inherit; | ||
font-family: "Merriweather", serif; | ||
font-size: 16px; | ||
color: inherit; | ||
font-weight: 300; | ||
resize: none; | ||
|
||
&:focus { | ||
outline: 0; | ||
p { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
.quote-block__form textarea, .quote-block__form .textarea-mirror { | ||
.quote-block__form { | ||
width: 100%; | ||
border: none; | ||
font: inherit; | ||
font-family: "Merriweather", serif; | ||
color: inherit; | ||
font-weight: 300; | ||
resize: none; | ||
font-size: 20px; | ||
border-left: 4px solid black; | ||
margin-left: -20px; | ||
padding-left: 20px; | ||
font-style: italic; | ||
|
||
&:focus { | ||
outline: 0; | ||
p { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
} |
Oops, something went wrong.